pax_global_header00006660000000000000000000000064127063353510014517gustar00rootroot0000000000000052 comment=459f98737dd57252ea63268c4686b939d40579ae strip-indent-2.0.0/000077500000000000000000000000001270633535100141365ustar00rootroot00000000000000strip-indent-2.0.0/.editorconfig000066400000000000000000000002761270633535100166200ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 strip-indent-2.0.0/.gitattributes000066400000000000000000000000141270633535100170240ustar00rootroot00000000000000* text=auto strip-indent-2.0.0/.gitignore000066400000000000000000000000151270633535100161220ustar00rootroot00000000000000node_modules strip-indent-2.0.0/.travis.yml000066400000000000000000000001151270633535100162440ustar00rootroot00000000000000sudo: false language: node_js node_js: - '5' - '4' - '0.12' - '0.10' strip-indent-2.0.0/index.js000066400000000000000000000005551270633535100156100ustar00rootroot00000000000000'use strict'; module.exports = str => { const match = str.match(/^[ \t]*(?=\S)/gm); if (!match) { return str; } // TODO: use spread operator when targeting Node.js 6 const indent = Math.min.apply(Math, match.map(x => x.length)); // eslint-disable-line const re = new RegExp(`^[ \\t]{${indent}}`, 'gm'); return indent > 0 ? str.replace(re, '') : str; }; strip-indent-2.0.0/license000066400000000000000000000021371270633535100155060ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. strip-indent-2.0.0/package.json000066400000000000000000000012621270633535100164250ustar00rootroot00000000000000{ "name": "strip-indent", "version": "2.0.0", "description": "Strip leading whitespace from each line in a string", "license": "MIT", "repository": "sindresorhus/strip-indent", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "strip", "indent", "indentation", "normalize", "remove", "delete", "whitespace", "space", "tab", "string", "str" ], "devDependencies": { "ava": "*", "xo": "*" }, "xo": { "esnext": true } } strip-indent-2.0.0/readme.md000066400000000000000000000015361270633535100157220ustar00rootroot00000000000000# strip-indent [![Build Status](https://travis-ci.org/sindresorhus/strip-indent.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-indent) > 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. Useful for removing redundant indentation. ## Install ``` $ npm install --save strip-indent ``` ## Usage ```js const stripIndent = require('strip-indent'); const str = '\tunicorn\n\t\tcake'; /* unicorn cake */ stripIndent('\tunicorn\n\t\tcake'); /* unicorn cake */ ``` ## Related - [strip-indent-cli](https://github.com/sindresorhus/strip-indent-cli) - CLI for this module - [indent-string](https://github.com/sindresorhus/indent-string) - Indent each line in a string ## License MIT © [Sindre Sorhus](https://sindresorhus.com) strip-indent-2.0.0/test.js000066400000000000000000000007331270633535100154560ustar00rootroot00000000000000import test from 'ava'; import m from './'; test(t => { t.is(m('\nunicorn\n'), '\nunicorn\n'); t.is(m('\n unicorn\n'), '\nunicorn\n'); t.is(m('\t\t\n\t\t\n\t\t\t\n\n\n\n\t\t\t\t

Hello world!

\n\t\t\t\n\t\t'), '\n\n\t\n\n\n\n\t\t

Hello world!

\n\t\n'); 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'); });