pax_global_header00006660000000000000000000000064134555527660014534gustar00rootroot0000000000000052 comment=99280aa24669a3fab303bb231d6caafd7d5029d3 indent-string-4.0.0/000077500000000000000000000000001345555276600143225ustar00rootroot00000000000000indent-string-4.0.0/.editorconfig000066400000000000000000000002571345555276600170030ustar00rootroot00000000000000root = 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-4.0.0/.gitattributes000066400000000000000000000000231345555276600172100ustar00rootroot00000000000000* text=auto eol=lf indent-string-4.0.0/.gitignore000066400000000000000000000000271345555276600163110ustar00rootroot00000000000000node_modules yarn.lock indent-string-4.0.0/.npmrc000066400000000000000000000000231345555276600154350ustar00rootroot00000000000000package-lock=false indent-string-4.0.0/.travis.yml000066400000000000000000000000541345555276600164320ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' indent-string-4.0.0/index.d.ts000066400000000000000000000014171345555276600162260ustar00rootroot00000000000000declare namespace indentString { interface Options { /** The string to use for the indent. @default ' ' */ readonly indent?: string; /** Also indent empty lines. @default false */ readonly includeEmptyLines?: boolean; } } /** Indent each line in a string. @param string - The string to indent. @param count - How many times you want `options.indent` repeated. Default: `1`. @example ``` import indentString = require('indent-string'); indentString('Unicorns\nRainbows', 4); //=> ' Unicorns\n Rainbows' indentString('Unicorns\nRainbows', 4, {indent: '♥'}); //=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows' ``` */ declare function indentString( string: string, count?: number, options?: indentString.Options ): string; export = indentString; indent-string-4.0.0/index.js000066400000000000000000000013471345555276600157740ustar00rootroot00000000000000'use strict'; module.exports = (string, count = 1, options) => { options = { indent: ' ', includeEmptyLines: false, ...options }; if (typeof string !== 'string') { throw new TypeError( `Expected \`input\` to be a \`string\`, got \`${typeof string}\`` ); } 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 string; } const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm; return string.replace(regex, options.indent.repeat(count)); }; indent-string-4.0.0/index.test-d.ts000066400000000000000000000005321345555276600172000ustar00rootroot00000000000000import {expectType} from 'tsd'; import indentString = require('.'); expectType(indentString('Unicorns\nRainbows')); expectType(indentString('Unicorns\nRainbows', 4)); expectType(indentString('Unicorns\nRainbows', 4, {indent: '♥'})); expectType(indentString('Unicorns\nRainbows', 4, {includeEmptyLines: true})); indent-string-4.0.0/license000066400000000000000000000021251345555276600156670ustar00rootroot00000000000000MIT 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-4.0.0/package.json000066400000000000000000000011061345555276600166060ustar00rootroot00000000000000{ "name": "indent-string", "version": "4.0.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": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "indent", "string", "pad", "align", "line", "text", "each", "every" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } indent-string-4.0.0/readme.md000066400000000000000000000022351345555276600161030ustar00rootroot00000000000000# 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\n Rainbows' indentString('Unicorns\nRainbows', 4, {indent: '♥'}); //=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows' ``` ## API ### indentString(string, [count], [options]) #### string Type: `string` The string to indent. #### count Type: `number`
Default: `1` How many times you want `options.indent` repeated. #### options Type: `object` ##### indent Type: `string`
Default: `' '` The 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-4.0.0/test.js000066400000000000000000000031401345555276600156350ustar00rootroot00000000000000import test from 'ava'; import indentString from '.'; test('throw if input is not a string', t => { t.throws(() => { indentString(5); }, 'Expected `input` to be a `string`, got `number`'); t.throws(() => { indentString(true); }, 'Expected `input` to be a `string`, got `boolean`'); }); test('throw if count is not a number', t => { t.throws(() => { indentString('foo', 'bar'); }, 'Expected `count` to be a `number`, got `string`'); }); test('throw if indent is not a string', t => { t.throws(() => { indentString('foo', 1, {indent: 1}); }, 'Expected `options.indent` to be a `string`, got `number`'); }); test('indent each line in a string', t => { t.is(indentString('foo\nbar'), ' foo\n bar'); t.is(indentString('foo\nbar', 1), ' foo\n bar'); t.is(indentString('foo\r\nbar', 1), ' foo\r\n bar'); t.is(indentString('foo\nbar', 4), ' foo\n bar'); }); test('not indent whitespace only lines', t => { t.is(indentString('foo\nbar\n', 1), ' foo\n bar\n'); t.is(indentString('foo\nbar\n', 1, {includeEmptyLines: false}), ' foo\n bar\n'); t.is(indentString('foo\nbar\n', 1, {includeEmptyLines: null}), ' foo\n bar\n'); }); test('indent every line if options.blank is true', t => { t.is(indentString('foo\n\nbar\n ', 1, {includeEmptyLines: true}), ' foo\n \n bar\n '); }); test('indent with leading whitespace', t => { t.is(indentString(' foo\n bar\n', 1), ' foo\n bar\n'); }); test('indent with custom string', t => { t.is(indentString('foo\nbar\n', 1, {indent: '♥'}), '♥foo\n♥bar\n'); }); test('not indent when count is 0', t => { t.is(indentString('foo\nbar\n', 0), 'foo\nbar\n'); });