UNPKG

967 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getStringFromStrOrFunc = exports.escapeChar = exports.escapeForWithinString = void 0;
4const newlineRegex = /(\r?\n)/g;
5/** @internal */
6function escapeForWithinString(str, quoteKind) {
7 return escapeChar(str, quoteKind).replace(newlineRegex, "\\$1");
8}
9exports.escapeForWithinString = escapeForWithinString;
10/** @internal */
11function escapeChar(str, char) {
12 if (char.length !== 1)
13 throw new Error(`Specified char must be one character long.`);
14 let result = "";
15 for (let i = 0; i < str.length; i++) {
16 if (str[i] === char)
17 result += "\\";
18 result += str[i];
19 }
20 return result;
21}
22exports.escapeChar = escapeChar;
23/** @internal */
24function getStringFromStrOrFunc(strOrFunc) {
25 return strOrFunc instanceof Function ? strOrFunc() : strOrFunc;
26}
27exports.getStringFromStrOrFunc = getStringFromStrOrFunc;