indent-string
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The npm package "indent-string" is a nifty tool designed to help developers add indentation to each line in a string conveniently. It can significantly simplify your code and improve readability when working with multiline strings. The primary function of this solution is to repeat a predetermined character (or group of characters) at the beginning of each line in a string. As its name suggests, it's mainly used to add indentation, but it can serve any purpose that requires repeating characters at the start of each line.
Using the "indent-string" npm package is a straightforward process. After installing it, you can import it into your script and use it with both single and multiline strings. Here's a simple JavaScript usage example:
import indentString from 'indent-string';
// Basic usage
console.log(indentString('Unicorns\nRainbows', 4));
// Output: ' Unicorns\n Rainbows'
// Custom indentation string
console.log(indentString('Unicorns\nRainbows', 4, {indent: '♥'}));
// Output: '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
In these examples, the first argument is the string you want to indent. The second argument is the number of times you want the indentation string (a space by default) to be repeated. The third argument is an optional object with additional settings, with 'indent' being the indentation string to repeat.
The "indent-string" documentation is contained within its README file, which you can find on the npm package's GitHub repository at https://github.com/sindresorhus/indent-string.git
. The readme includes the complete API explanation and all the necessary usage examples, letting developers quickly get the hang of using the package effectively. If you ever need custom support for the usage of this package, there is also an option to get a professional subscription via Tidelift from the same README.