pax_global_header00006660000000000000000000000064131351573370014522gustar00rootroot0000000000000052 comment=458eca3f626b95bdcff5afe30d1568bf76889920 indent-string-3.2.0/000077500000000000000000000000001313515733700143115ustar00rootroot00000000000000indent-string-3.2.0/.editorconfig000066400000000000000000000002571313515733700167720ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 indent-string-3.2.0/.gitattributes000066400000000000000000000000351313515733700172020ustar00rootroot00000000000000* text=auto *.js text eol=lf indent-string-3.2.0/.gitignore000066400000000000000000000000271313515733700163000ustar00rootroot00000000000000node_modules yarn.lock indent-string-3.2.0/.npmrc000066400000000000000000000000231313515733700154240ustar00rootroot00000000000000package-lock=false indent-string-3.2.0/.travis.yml000066400000000000000000000000631313515733700164210ustar00rootroot00000000000000language: node_js node_js: - '8' - '6' - '4' indent-string-3.2.0/index.js000066400000000000000000000016041313515733700157570ustar00rootroot00000000000000'use strict'; module.exports = (str, count, opts) => { // Support older versions: use the third parameter as options.indent // TODO: Remove the workaround in the next major version const options = typeof opts === 'object' ? Object.assign({indent: ' '}, opts) : {indent: opts || ' '}; count = count === undefined ? 1 : count; if (typeof str !== 'string') { throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``); } if (typeof count !== 'number') { throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``); } if (typeof options.indent !== 'string') { throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``); } if (count === 0) { return str; } const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg; return str.replace(regex, options.indent.repeat(count)); } ; indent-string-3.2.0/license000066400000000000000000000021251313515733700156560ustar00rootroot00000000000000MIT License 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. indent-string-3.2.0/package.json000066400000000000000000000011151313515733700165750ustar00rootroot00000000000000{ "name": "indent-string", "version": "3.2.0", "description": "Indent each line in a string", "license": "MIT", "repository": "sindresorhus/indent-string", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "indent", "string", "str", "pad", "align", "line", "text", "each", "every" ], "devDependencies": { "ava": "*", "xo": "*" } } indent-string-3.2.0/readme.md000066400000000000000000000022441313515733700160720ustar00rootroot00000000000000# indent-string [![Build Status](https://travis-ci.org/sindresorhus/indent-string.svg?branch=master)](https://travis-ci.org/sindresorhus/indent-string) > Indent each line in a string ## Install ``` $ npm install indent-string ``` ## Usage ```js const indentString = require('indent-string'); indentString('Unicorns\nRainbows', 4); //=> ' Unicorns' //=> ' Rainbows' indentString('Unicorns\nRainbows', 4, {indent: '♥'}); //=> '♥♥♥♥Unicorns' //=> '♥♥♥♥Rainbows' ``` ## API ### indentString(input, [count], [options]) #### input Type: `string` String you want to indent. #### count Type: `number`
Default: `1` How many times you want `indent` repeated. #### options Type: `Object`
##### indent Type: `string`
Default: `' '` String to use for the indent. ##### includeEmptyLines Type: `boolean`
Default: `false` Also indent empty lines. ## Related - [indent-string-cli](https://github.com/sindresorhus/indent-string-cli) - CLI for this module - [strip-indent](https://github.com/sindresorhus/strip-indent) - Strip leading whitespace from every line in a string ## License MIT © [Sindre Sorhus](https://sindresorhus.com) indent-string-3.2.0/test.js000066400000000000000000000031471313515733700156330ustar00rootroot00000000000000import test from 'ava'; import m from '.'; test('throw if input is not a string', t => { t.throws(() => m(5), 'Expected `input` to be a `string`, got `number`'); t.throws(() => m(true), 'Expected `input` to be a `string`, got `boolean`'); }); test('throw if count is not a number', t => { t.throws(() => m('foo', 'bar'), 'Expected `count` to be a `number`, got `string`'); }); test('throw if indent is not a string', t => { t.throws(() => m('foo', 1, 1), 'Expected `options.indent` to be a `string`, got `number`'); // Old syntax t.throws(() => m('foo', 1, {indent: 1}), 'Expected `options.indent` to be a `string`, got `number`'); }); test('indent each line in a string', t => { t.is(m('foo\nbar'), ' foo\n bar'); t.is(m('foo\nbar', 1), ' foo\n bar'); t.is(m('foo\r\nbar', 1), ' foo\r\n bar'); t.is(m('foo\nbar', 4), ' foo\n bar'); }); test('not indent whitespace only lines', t => { t.is(m('foo\nbar\n', 1), ' foo\n bar\n'); t.is(m('foo\nbar\n', 1, {includeEmptyLines: false}), ' foo\n bar\n'); t.is(m('foo\nbar\n', 1, {includeEmptyLines: null}), ' foo\n bar\n'); }); test('indent every line if options.blank is true', t => { t.is(m('foo\n\nbar\n ', 1, {includeEmptyLines: true}), ' foo\n \n bar\n '); }); test('indent with leading whitespace', t => { t.is(m(' foo\n bar\n', 1), ' foo\n bar\n'); }); test('indent with custom string', t => { t.is(m('foo\nbar\n', 1, {indent: '♥'}), '♥foo\n♥bar\n'); }); test('indent with custom string and old syntax', t => { t.is(m('foo\nbar\n', 1, '#'), '#foo\n#bar\n'); }); test('not indent when count is 0', t => { t.is(m('foo\nbar\n', 0), 'foo\nbar\n'); });