Codebase list node-strip-indent / 1d8dbb4
New upstream release. Debian Janitor 4 years ago
13 changed file(s) with 98 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
66 trim_trailing_whitespace = true
77 insert_final_newline = true
88
9 [{package.json,*.yml}]
9 [*.yml]
1010 indent_style = space
1111 indent_size = 2
0 * text=auto
0 * text=auto eol=lf
00 node_modules
1 yarn.lock
0 package-lock=false
0 sudo: false
10 language: node_js
21 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
06 node-strip-indent (2.0.0-1) unstable; urgency=low
17
28 * 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;
00 'use strict';
1 module.exports = str => {
2 const match = str.match(/^[ \t]*(?=\S)/gm);
1 const minIndent = require('min-indent');
32
4 if (!match) {
5 return str;
3 module.exports = string => {
4 const indent = minIndent(string);
5
6 if (indent === 0) {
7 return string;
68 }
79
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');
1111
12 return indent > 0 ? str.replace(re, '') : str;
12 return string.replace(regex, '');
1313 };
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
11
22 Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
33
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:
105
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.
137
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.
00 {
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 }
4041 }
99 ## Install
1010
1111 ```
12 $ npm install --save strip-indent
12 $ npm install strip-indent
1313 ```
1414
1515
1818 ```js
1919 const stripIndent = require('strip-indent');
2020
21 const str = '\tunicorn\n\t\tcake';
21 const string = '\tunicorn\n\t\tcake';
2222 /*
2323 unicorn
2424 cake
2525 */
2626
27 stripIndent('\tunicorn\n\t\tcake');
27 stripIndent(string);
2828 /*
2929 unicorn
3030 cake
00 import test from 'ava';
1 import m from './';
1 import stripIndent from '.';
22
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');
88 });