Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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
import indentString from '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.
FAQs
Indent each line in a string
The npm package indent-string receives a total of 38,941,167 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.