@technobuddha/library
Version:
A large library of useful functions
17 lines (16 loc) • 513 B
JavaScript
import escapeRegExp from 'lodash/escapeRegExp';
import { empty, space } from '../constants';
import getIndent from '../getIndent';
/**
* Remove indentation from text
*
* @param input The indented text
* @param pattern (space)
*/
export function unindent(input, { indenter = space } = {}) {
const indent = getIndent(input, { indenter });
if (indent === 0)
return input;
return input.replace(new RegExp(`^(${escapeRegExp(indenter)}){${indent}}`, 'gmu'), empty);
}
export default unindent;