Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
strip-indent
Advanced tools
The strip-indent npm package is used to remove the leading whitespace from every line in a given text block. This is particularly useful when working with multi-line strings that need to be displayed without indentation or when processing template literals in JavaScript that should not retain the formatting of the source code.
Strip indentation from a multi-line string
This feature allows you to remove the common leading whitespace from all lines in a text block, making it easier to handle formatted multi-line strings without unwanted indentation.
const stripIndent = require('strip-indent');
const text = ` line one
line two
line three`;
console.log(stripIndent(text));
Dedent is similar to strip-indent but also trims the trailing newline. It is often used in template literals to avoid first-line indentation and to ensure that the output does not end with a newline, making it slightly different in its approach compared to strip-indent.
While strip-indent removes indentation, indent-string adds indentation to each line in a string. This package can be considered the opposite of strip-indent. It allows specifying the number of spaces or the type of indentation (spaces or tabs), offering more flexibility depending on the user's needs.
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.
$ npm install strip-indent
import stripIndent from 'strip-indent';
const string = '\tunicorn\n\t\tcake';
/*
unicorn
cake
*/
stripIndent(string);
/*
unicorn
cake
*/
FAQs
Strip leading whitespace from each line in a string
We found that strip-indent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.