├── .npmrc ├── .gitattributes ├── .gitignore ├── .github ├── funding.yml ├── security.md └── workflows │ └── main.yml ├── index.js ├── .editorconfig ├── index.test-d.ts ├── test.js ├── index.d.ts ├── package.json ├── license └── readme.md /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: sindresorhus 2 | open_collective: sindresorhus 3 | tidelift: npm/redent 4 | custom: https://sindresorhus.com/donate 5 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import stripIndent from 'strip-indent'; 2 | import indentString from 'indent-string'; 3 | 4 | export default function redent(string, count = 0, options = {}) { 5 | return indentString(stripIndent(string), count, options); 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType} from 'tsd'; 2 | import redent from './index.js'; 3 | 4 | expectType(redent('\n foo\n bar\n')); 5 | expectType(redent('\n foo\n bar\n', 1)); 6 | expectType(redent('\n foo\n bar\n', 1, {indent: ' '})); 7 | expectType(redent('\n foo\n bar\n', 1, {includeEmptyLines: true})); 8 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import redent from './index.js'; 3 | 4 | test('main', t => { 5 | t.is(redent('\n foo\n bar\n', 1), '\n foo\n bar\n'); 6 | t.is(redent('\n foo\n bar\n', 5, {indent: '-'}), '\n-----foo\n----- bar\n'); 7 | t.is(redent('\n foo\n bar\n', 5, {indent: '-', includeEmptyLines: true}), '-----\n-----foo\n----- bar\n-----'); 8 | }); 9 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | - 14 15 | - 12 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions/setup-node@v2 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import {Options} from 'indent-string'; 2 | 3 | /** 4 | [Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string). 5 | 6 | @param string - The string to normalize indentation. 7 | @param count - How many times you want `options.indent` repeated. Default: `0`. 8 | 9 | @example 10 | ``` 11 | import redent from 'redent'; 12 | 13 | redent('\n foo\n bar\n', 1); 14 | //=> '\n foo\n bar\n' 15 | ``` 16 | */ 17 | export default function redent( 18 | string: string, 19 | count?: number, 20 | options?: Options 21 | ): string; 22 | 23 | export {Options}; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "redent", 3 | "version": "4.0.0", 4 | "description": "Strip redundant indentation and indent the string", 5 | "license": "MIT", 6 | "repository": "sindresorhus/redent", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": ">=12" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava && tsd" 20 | }, 21 | "files": [ 22 | "index.js", 23 | "index.d.ts" 24 | ], 25 | "keywords": [ 26 | "string", 27 | "strip", 28 | "trim", 29 | "indent", 30 | "indentation", 31 | "add", 32 | "reindent", 33 | "normalize", 34 | "remove", 35 | "whitespace", 36 | "space" 37 | ], 38 | "dependencies": { 39 | "indent-string": "^5.0.0", 40 | "strip-indent": "^4.0.0" 41 | }, 42 | "devDependencies": { 43 | "ava": "^3.15.0", 44 | "tsd": "^0.14.0", 45 | "xo": "^0.39.1" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # redent 2 | 3 | > [Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string) 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install redent 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import redent from 'redent'; 15 | 16 | redent('\n foo\n bar\n', 1); 17 | //=> '\n foo\n bar\n' 18 | ``` 19 | 20 | ## API 21 | 22 | ### redent(string, count?, options?) 23 | 24 | #### string 25 | 26 | Type: `string` 27 | 28 | The string to normalize indentation. 29 | 30 | #### count 31 | 32 | Type: `number`\ 33 | Default: `0` 34 | 35 | How many times you want `options.indent` repeated. 36 | 37 | #### options 38 | 39 | Type: `object` 40 | 41 | ##### indent 42 | 43 | Type: `string`\ 44 | Default: `' '` 45 | 46 | The string to use for the indent. 47 | 48 | ##### includeEmptyLines 49 | 50 | Type: `boolean`\ 51 | Default: `false` 52 | 53 | Also indent empty lines. 54 | 55 | --- 56 | 57 |
58 | 59 | Get professional support for this package with a Tidelift subscription 60 | 61 |
62 | 63 | Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. 64 |
65 |
66 | --------------------------------------------------------------------------------