@backtrace/sourcemap-tools
Version:
Backtrace-JavaScript sourcemap tools
21 lines • 751 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.appendBeforeWhitespaces = appendBeforeWhitespaces;
/**
* Appends `value` to `str` before trailing whitespaces in `str`.
* @param str String to append to.
* @param value String to append.
* @example
* const str = 'abc\n\n';
* const value = 'def';
* const appended = appendBeforeWhitespaces(str, value); // 'abcdef\n\n'
*/
function appendBeforeWhitespaces(str, value) {
var _a;
const whitespaces = (_a = str.match(/\s*$/)) === null || _a === void 0 ? void 0 : _a[0];
if (!whitespaces) {
return str + value;
}
return str.substring(0, str.length - whitespaces.length) + value + whitespaces;
}
//# sourceMappingURL=stringHelpers.js.map
;