1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getStringFromStrOrFunc = exports.escapeChar = exports.escapeForWithinString = void 0;
|
4 | const newlineRegex = /(\r?\n)/g;
|
5 |
|
6 | function escapeForWithinString(str, quoteKind) {
|
7 | return escapeChar(str, quoteKind).replace(newlineRegex, "\\$1");
|
8 | }
|
9 | exports.escapeForWithinString = escapeForWithinString;
|
10 |
|
11 | function 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 | }
|
22 | exports.escapeChar = escapeChar;
|
23 |
|
24 | function getStringFromStrOrFunc(strOrFunc) {
|
25 | return strOrFunc instanceof Function ? strOrFunc() : strOrFunc;
|
26 | }
|
27 | exports.getStringFromStrOrFunc = getStringFromStrOrFunc;
|