UNPKG

@technobuddha/library

Version:
17 lines (16 loc) 513 B
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;