Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, add TypeScript definition (#6)
- Loading branch information
1 parent
767c465
commit 578f3a7
Showing
8 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
Strip leading whitespace from each line in a string. | ||
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove. | ||
@example | ||
``` | ||
import stripIndent = require('strip-indent'); | ||
const string = '\tunicorn\n\t\tcake'; | ||
// unicorn | ||
// cake | ||
stripIndent(string); | ||
//unicorn | ||
// cake | ||
``` | ||
*/ | ||
declare function stripIndent(string: string): string; | ||
|
||
export = stripIndent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
'use strict'; | ||
const minIndent = require('min-indent'); | ||
|
||
module.exports = str => { | ||
const indent = minIndent(str); | ||
module.exports = string => { | ||
const indent = minIndent(string); | ||
|
||
if (indent === 0) { | ||
return str; | ||
return string; | ||
} | ||
|
||
const re = new RegExp(`^[ \\t]{${indent}}`, 'gm'); | ||
const regExp = new RegExp(`^[ \\t]{${indent}}`, 'gm'); | ||
|
||
return str.replace(re, ''); | ||
return string.replace(regExp, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {expectType} from 'tsd'; | ||
import stripIndent = require('.'); | ||
|
||
expectType<string>(stripIndent('\tunicorn\n\t\tcake')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import stripIndent from '.'; | ||
|
||
test(t => { | ||
t.is(m('\nunicorn\n'), '\nunicorn\n'); | ||
t.is(m('\n unicorn\n'), '\nunicorn\n'); | ||
t.is(m('\t\t<!doctype html>\n\t\t<html>\n\t\t\t<body>\n\n\n\n\t\t\t\t<h1>Hello world!</h1>\n\t\t\t</body>\n\t\t</html>'), '<!doctype html>\n<html>\n\t<body>\n\n\n\n\t\t<h1>Hello world!</h1>\n\t</body>\n</html>'); | ||
t.is(m('\n\t\n\t\tunicorn\n\n\n\n\t\t\tunicorn'), '\n\t\nunicorn\n\n\n\n\tunicorn', 'ignore whitespace only lines'); | ||
test('main', t => { | ||
t.is(stripIndent('\nunicorn\n'), '\nunicorn\n'); | ||
t.is(stripIndent('\n unicorn\n'), '\nunicorn\n'); | ||
t.is(stripIndent('\t\t<!doctype html>\n\t\t<html>\n\t\t\t<body>\n\n\n\n\t\t\t\t<h1>Hello world!</h1>\n\t\t\t</body>\n\t\t</html>'), '<!doctype html>\n<html>\n\t<body>\n\n\n\n\t\t<h1>Hello world!</h1>\n\t</body>\n</html>'); | ||
t.is(stripIndent('\n\t\n\t\tunicorn\n\n\n\n\t\t\tunicorn'), '\n\t\nunicorn\n\n\n\n\tunicorn', 'ignore whitespace only lines'); | ||
}); |