UNPKG

@backtrace/sourcemap-tools

Version:
21 lines 751 B
"use strict"; 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