UNPKG

tiny-dedent

Version:

A Tiny module for stripping indentation from multi-line strings

25 lines (19 loc) 675 B
/*! * tiny-dedent v1.0.2 (https://github.com/victornpb/tiny-dedent) * Copyright (c) victornpb * @license MIT */ 'use strict'; /** * Removes the indentation of multiline strings * @param {string} str A template literal string * @return {string} A string without the indentation */ function dedent(str) { str = str.replace(/^[ \t]*\r?\n/, ''); // remove leading blank line var indent = /^[ \t]+/m.exec(str); // detected indent if (indent) str = str.replace(new RegExp('^' + indent[0], 'gm'), ''); // remove indent return str.replace(/(\r?\n)[ \t]+$/, '$1'); // remove trailling blank line } module.exports = dedent; //# sourceMappingURL=dedent.cjs.js.map