Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
indent-string
Advanced tools
The indent-string npm package is a utility that allows users to add indentation to the beginning of each line in a string. This can be particularly useful for formatting multi-line strings or code snippets in a more readable manner. The package provides a simple interface to specify the number of spaces or the string to use for indentation, making it a versatile tool for text manipulation in Node.js applications.
Indenting with spaces
This feature allows you to indent each line of a given string with a specified number of spaces. In the code sample, the string 'Unicorn\nRainbow' is indented by 4 spaces.
const indentString = require('indent-string');
console.log(indentString('Unicorn\nRainbow', 4));
// Output:
// Unicorn
// Rainbow
Indenting with custom string
This feature enables indenting each line of a string with a custom string instead of spaces. In the example, the string 'Unicorn\nRainbow' is indented using the '♥' character, repeated 4 times as specified.
const indentString = require('indent-string');
console.log(indentString('Unicorn\nRainbow', 4, {indent: '♥'}));
// Output:
// ♥♥♥♥Unicorn
// ♥♥♥♥Rainbow
Similar to indent-string, left-pad adds characters to the left of a string, effectively indenting it. However, left-pad is more focused on padding a single line to a specific length, rather than indenting all lines in a multi-line string.
While not directly similar, cli-boxes is a package that deals with text formatting in the terminal, offering a variety of box styles for CLI applications. It can be used in conjunction with indent-string for more complex text formatting tasks.
Indent each line in a string
$ npm install indent-string
const indentString = require('indent-string');
indentString('Unicorns\nRainbows', 4);
//=> ' Unicorns\n Rainbows'
indentString('Unicorns\nRainbows', 4, {indent: '♥'});
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
Type: string
The string to indent.
Type: number
Default: 1
How many times you want options.indent
repeated.
Type: object
Type: string
Default: ' '
The string to use for the indent.
Type: boolean
Default: false
Also indent empty lines.
MIT © Sindre Sorhus
FAQs
Indent each line in a string
The npm package indent-string receives a total of 29,849,199 weekly downloads. As such, indent-string popularity was classified as popular.
We found that indent-string 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.