Gathering detailed insights and metrics for outdent
Gathering detailed insights and metrics for outdent
npm install outdent
Typescript
Module System
99.6
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
TypeScript (99.61%)
JavaScript (0.39%)
Total Downloads
163,911,719
Last Day
411,744
Last Week
1,895,267
Last Month
7,836,251
Last Year
81,521,058
168 Stars
134 Commits
5 Forks
2 Watching
5 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
0.8.0
Package Id
outdent@0.8.0
Size
9.68 kB
Publised On
16 Dec 2020
Cumulative downloads
Total Downloads
Last day
3.9%
411,744
Compared to previous day
Last week
-7.5%
1,895,267
Compared to previous week
Last month
7.6%
7,836,251
Compared to previous month
Last year
55%
81,521,058
Compared to previous year
ES6 template strings are great, but they preserve everything between the backticks, including leading spaces. Sometimes I want to indent my template literals to make my code more readable without including all those spaces in the string.
Outdent will remove those leading spaces, as well as the leading and trailing newlines.
Import outdent using your module system of choice.
CommonJS:
1const outdent = require('outdent');
ES6 Modules & TypeScript:
1import outdent from 'outdent';
1import outdent from 'outdent'; 2 3const markdown = outdent` 4 # My Markdown File 5 6 Here is some indented code: 7 8 console.log("hello world!"); 9`; 10 11console.log(markdown); 12 13fs.writeFileSync('output.md', markdown);
The contents of output.md
do not have the leading indentation:
1# My Markdown File
2
3Here is some indented code:
4
5 console.log("hello world!");
As a JavaScript string:
1var markdown = '# My Markdown File\n' + 2 '\n' + 3 'Here is some indented code:\n' + 4 '\n' + 5 ' console.log("hello world!");';
You can pass options to outdent to control its behavior. They are explained in Options.
1const output = outdent({trimLeadingNewline: false, trimTrailingNewline: false})` 2 Hello world! 3`; 4 5assert(output === '\nHello world!\n');
You can explicitly specify the indentation level by passing outdent
as the first interpolated value. Its position sets the indentation level and it is removed from the output:
1const output = outdent` 2 ${outdent} 3 Yo 4 12345 5 Hello world 6`; 7 8assert(output === ' Yo\n345\n Hello world');
Note: ${outdent}
must be alone on its own line without anything before or after it. It cannot be preceded by any non-whitespace characters.
If these conditions are not met, outdent will follow normal indentation-detection behavior.
Outdent can also remove indentation from plain strings via the string
method.
1const output = outdent.string('\n Hello world!\n'); 2 3assert(output === 'Hello world!');
trimLeadingNewline
Default: true
trimTrailingNewline
Default: true
Whether or not outdent should remove the leading and/or trailing newline from your template string. For example:
1var s = outdent({trimLeadingNewline: false})` 2 Hello 3`; 4 5assert(s === '\nHello'); 6 7s = outdent({trimTrailingNewline: false})` 8 Hello 9` 10 11assert(s === 'Hello\n'); 12 13s = outdent({trimLeadingNewline: false, trimTrailingNewline: false})` 14 15`; 16 17assert(s === '\n\n');
newline
Default: null
If set to a string, normalize all newlines in the template literal to this value.
If null
, newlines are left untouched.
For example, in the absence of a .gitattributes
file, source code
checked out on Windows will have '\r\n' newlines. This affects
template literals as well. The following example would produce
different results on Windows and Linux, but can be normalized via
newline
:
s = outdent `
first
second
`;
assert(s === 'first\r\nsecond'); // Only true for git checkout on Windows
assert(s === 'first\nsecond'); // Only true for git checkout on Linux
s = outdent({newline: '\n'}) `
first
second
`;
assert(s === 'first\nsecond'); // Always true on any platform
Newlines that get normalized are '\r\n', '\r', and '\n'.
Newlines within interpolated values are never normalized.
Although intended for normalizing to '\n' or '\r\n', you can use any string, for example a space.
1const s = outdent({newline: ' '}) ` 2 Hello 3 world! 4`; 5 6assert(s === 'Hello world!');
Start the contents of your template string on a new line after the opening backtick. Otherwise, outdent has no choice but to detect indentation from the second line, which does not work in all situations.
1// Bad 2const output = outdent `* item 1 3 * sub-item 4`; 5// output === '* item 1\n* sub-item'; Indentation of sub-item is lost 6 7// Good 8const output = outdent ` 9 * item 1 10 * sub-item 11`;
Spaces and tabs are treated identically. outdent does not verify that you are using spaces or tabs consistently; they are all treated as a single character for the purpose of removing indentation. Spaces, tabs, and smart tabs should all work correctly provided you use them consistently.
This module includes TypeScript type declarations so you will get code completion and error-checking without installing anything else.
File an issue on Github: https://github.com/cspotcode/outdent/issues
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More