@monteway/utils
v0.4.2
Published
Common utilities for Monterail projects
Downloads
9
Maintainers
Readme
@monteway/utils
Tiny but useful utilities.
Install
npm i @monteway/utils
Usage
trimMultiline
- Trims useless spaces from the beginning of each line.
- Removes empty new lines at the beginning and end of the input.
- Keeps the identation pattern.
Example
import { trimMultiline } from '@monteway/utils/format';
const code = `
function foo() {
return bar;
}
`;
const output = trimMultiline(code);
If we do
console.log(code)
, the result will be:function foo() { return bar; }
If we do
console.log(output)
, the result will be different by trimming the trailing, useless spaces:function foo() { return bar; }
This shows, that
trimMultiline
acts a little bit like Prettier.
Options
As a second, optional arguments we might pass an object:
{
// Make sure the miniam identation is this number of spaces.
indentBy?: number;
// Keep a single new line at the beginning of the output (since by default it's removed).
startWithNewLine?: boolean;
}