New upstream release.
Debian Janitor
4 years ago
6 | 6 | trim_trailing_whitespace = true |
7 | 7 | insert_final_newline = true |
8 | 8 | |
9 | [{package.json,*.yml}] | |
9 | [*.yml] | |
10 | 10 | indent_style = space |
11 | 11 | indent_size = 2 |
0 | sudo: false | |
1 | 0 | language: node_js |
2 | 1 | node_js: |
3 | - '5' | |
4 | - '4' | |
5 | - '0.12' | |
6 | - '0.10' | |
2 | - '10' | |
3 | - '8' |
0 | node-strip-indent (3.0.0-1) UNRELEASED; urgency=medium | |
1 | ||
2 | * New upstream release. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Thu, 28 Nov 2019 08:22:46 +0000 | |
5 | ||
0 | 6 | node-strip-indent (2.0.0-1) unstable; urgency=low |
1 | 7 | |
2 | 8 | * Initial release (Closes: #841998) |
0 | /** | |
1 | Strip leading whitespace from each line in a string. | |
2 | ||
3 | The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove. | |
4 | ||
5 | @example | |
6 | ``` | |
7 | import stripIndent = require('strip-indent'); | |
8 | ||
9 | const string = '\tunicorn\n\t\tcake'; | |
10 | // unicorn | |
11 | // cake | |
12 | ||
13 | stripIndent(string); | |
14 | //unicorn | |
15 | // cake | |
16 | ``` | |
17 | */ | |
18 | declare function stripIndent(string: string): string; | |
19 | ||
20 | export = stripIndent; |
0 | 0 | 'use strict'; |
1 | module.exports = str => { | |
2 | const match = str.match(/^[ \t]*(?=\S)/gm); | |
1 | const minIndent = require('min-indent'); | |
3 | 2 | |
4 | if (!match) { | |
5 | return str; | |
3 | module.exports = string => { | |
4 | const indent = minIndent(string); | |
5 | ||
6 | if (indent === 0) { | |
7 | return string; | |
6 | 8 | } |
7 | 9 | |
8 | // TODO: use spread operator when targeting Node.js 6 | |
9 | const indent = Math.min.apply(Math, match.map(x => x.length)); // eslint-disable-line | |
10 | const re = new RegExp(`^[ \\t]{${indent}}`, 'gm'); | |
10 | const regex = new RegExp(`^[ \\t]{${indent}}`, 'gm'); | |
11 | 11 | |
12 | return indent > 0 ? str.replace(re, '') : str; | |
12 | return string.replace(regex, ''); | |
13 | 13 | }; |
0 | import {expectType} from 'tsd'; | |
1 | import stripIndent = require('.'); | |
2 | ||
3 | expectType<string>(stripIndent('\tunicorn\n\t\tcake')); |
0 | The MIT License (MIT) | |
0 | MIT License | |
1 | 1 | |
2 | 2 | Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) |
3 | 3 | |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
10 | 5 | |
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
13 | 7 | |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | THE SOFTWARE. | |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 | 0 | { |
1 | "name": "strip-indent", | |
2 | "version": "2.0.0", | |
3 | "description": "Strip leading whitespace from each line in a string", | |
4 | "license": "MIT", | |
5 | "repository": "sindresorhus/strip-indent", | |
6 | "author": { | |
7 | "name": "Sindre Sorhus", | |
8 | "email": "sindresorhus@gmail.com", | |
9 | "url": "sindresorhus.com" | |
10 | }, | |
11 | "engines": { | |
12 | "node": ">=4" | |
13 | }, | |
14 | "scripts": { | |
15 | "test": "xo && ava" | |
16 | }, | |
17 | "files": [ | |
18 | "index.js" | |
19 | ], | |
20 | "keywords": [ | |
21 | "strip", | |
22 | "indent", | |
23 | "indentation", | |
24 | "normalize", | |
25 | "remove", | |
26 | "delete", | |
27 | "whitespace", | |
28 | "space", | |
29 | "tab", | |
30 | "string", | |
31 | "str" | |
32 | ], | |
33 | "devDependencies": { | |
34 | "ava": "*", | |
35 | "xo": "*" | |
36 | }, | |
37 | "xo": { | |
38 | "esnext": true | |
39 | } | |
1 | "name": "strip-indent", | |
2 | "version": "3.0.0", | |
3 | "description": "Strip leading whitespace from each line in a string", | |
4 | "license": "MIT", | |
5 | "repository": "sindresorhus/strip-indent", | |
6 | "author": { | |
7 | "name": "Sindre Sorhus", | |
8 | "email": "sindresorhus@gmail.com", | |
9 | "url": "sindresorhus.com" | |
10 | }, | |
11 | "engines": { | |
12 | "node": ">=8" | |
13 | }, | |
14 | "scripts": { | |
15 | "test": "xo && ava && tsd" | |
16 | }, | |
17 | "files": [ | |
18 | "index.js", | |
19 | "index.d.ts" | |
20 | ], | |
21 | "keywords": [ | |
22 | "strip", | |
23 | "indent", | |
24 | "indentation", | |
25 | "normalize", | |
26 | "remove", | |
27 | "delete", | |
28 | "whitespace", | |
29 | "space", | |
30 | "tab", | |
31 | "string" | |
32 | ], | |
33 | "dependencies": { | |
34 | "min-indent": "^1.0.0" | |
35 | }, | |
36 | "devDependencies": { | |
37 | "ava": "^1.4.1", | |
38 | "tsd": "^0.7.2", | |
39 | "xo": "^0.24.0" | |
40 | } | |
40 | 41 | } |
9 | 9 | ## Install |
10 | 10 | |
11 | 11 | ``` |
12 | $ npm install --save strip-indent | |
12 | $ npm install strip-indent | |
13 | 13 | ``` |
14 | 14 | |
15 | 15 | |
18 | 18 | ```js |
19 | 19 | const stripIndent = require('strip-indent'); |
20 | 20 | |
21 | const str = '\tunicorn\n\t\tcake'; | |
21 | const string = '\tunicorn\n\t\tcake'; | |
22 | 22 | /* |
23 | 23 | unicorn |
24 | 24 | cake |
25 | 25 | */ |
26 | 26 | |
27 | stripIndent('\tunicorn\n\t\tcake'); | |
27 | stripIndent(string); | |
28 | 28 | /* |
29 | 29 | unicorn |
30 | 30 | cake |
0 | 0 | import test from 'ava'; |
1 | import m from './'; | |
1 | import stripIndent from '.'; | |
2 | 2 | |
3 | test(t => { | |
4 | t.is(m('\nunicorn\n'), '\nunicorn\n'); | |
5 | t.is(m('\n unicorn\n'), '\nunicorn\n'); | |
6 | 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>'); | |
7 | 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'); | |
3 | test('main', t => { | |
4 | t.is(stripIndent('\nunicorn\n'), '\nunicorn\n'); | |
5 | t.is(stripIndent('\n unicorn\n'), '\nunicorn\n'); | |
6 | 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>'); | |
7 | 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'); | |
8 | 8 | }); |