What is min-indent?
The min-indent npm package is designed to determine the smallest indentation of non-empty lines in a given string. This is particularly useful in scenarios where consistent text formatting is required, or when preparing text for further processing that is sensitive to leading whitespace.
What are min-indent's main functionalities?
Detect minimum indentation
This feature allows you to find the smallest number of leading spaces in a multi-line string. It's useful for adjusting the text indentation level or preprocessing before rendering in UI components.
const minIndent = require('min-indent');
const sampleText = ` line one
line two
line three`;
const minimumIndentation = minIndent(sampleText);
console.log(minimumIndentation); // Outputs: 2
Other packages similar to min-indent
strip-indent
Similar to min-indent, strip-indent removes the common leading whitespace from each line in a string. The main difference is that strip-indent modifies the string to normalize indentation, whereas min-indent only calculates the minimum indentation without altering the original string.
indent-string
While min-indent is used to detect indentation, indent-string is used to add or increase indentation to a string. This package can be seen as a complementary tool to min-indent, where one measures and the other modifies indentation.
min-indent
Get the shortest leading whitespace from lines in a string
The line with the least number of leading whitespace, ignoring empty lines, determines the number.
Useful for removing redundant indentation.
Install
$ npm install --save min-indent
Usage
const minIndent = require('min-indent');
const str = '\tunicorn\n\t\tcake';
minIndent(str);
Related
License
MIT © James Kyle