| "use strict"; |
|
|
| Object.defineProperty(exports, "__esModule", { |
| value: true |
| }); |
| exports.default = void 0; |
| const dedent = createDedent({}); |
| var _default = exports.default = dedent; |
| function createDedent(options) { |
| dedent.withOptions = newOptions => createDedent({ |
| ...options, |
| ...newOptions |
| }); |
| return dedent; |
| function dedent(strings, ...values) { |
| const raw = typeof strings === "string" ? [strings] : strings.raw; |
| const { |
| alignValues = false, |
| escapeSpecialCharacters = Array.isArray(strings), |
| trimWhitespace = true |
| } = options; |
|
|
| |
| let result = ""; |
| for (let i = 0; i < raw.length; i++) { |
| let next = raw[i]; |
| if (escapeSpecialCharacters) { |
| |
| next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{"); |
| } |
| result += next; |
| if (i < values.length) { |
| const value = alignValues ? alignValue(values[i], result) : values[i]; |
|
|
| |
| result += value; |
| } |
| } |
|
|
| |
| const lines = result.split("\n"); |
| let mindent = null; |
| for (const l of lines) { |
| const m = l.match(/^(\s+)\S+/); |
| if (m) { |
| const indent = m[1].length; |
| if (!mindent) { |
| |
| mindent = indent; |
| } else { |
| mindent = Math.min(mindent, indent); |
| } |
| } |
| } |
| if (mindent !== null) { |
| const m = mindent; |
| result = lines |
| |
| |
| .map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n"); |
| } |
|
|
| |
| if (trimWhitespace) { |
| result = result.trim(); |
| } |
|
|
| |
| |
| if (escapeSpecialCharacters) { |
| result = result.replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/\\r/g, "\r").replace(/\\v/g, "\v").replace(/\\b/g, "\b").replace(/\\f/g, "\f").replace(/\\0/g, "\0").replace(/\\x([\da-fA-F]{2})/g, (_, h) => String.fromCharCode(parseInt(h, 16))).replace(/\\u\{([\da-fA-F]{1,6})\}/g, (_, h) => String.fromCodePoint(parseInt(h, 16))).replace(/\\u([\da-fA-F]{4})/g, (_, h) => String.fromCharCode(parseInt(h, 16))); |
| } |
|
|
| |
| |
| if (typeof Bun !== "undefined") { |
| result = result.replace( |
| |
| /\\u(?:\{([\da-fA-F]{1,6})\}|([\da-fA-F]{4}))/g, (_, braced, unbraced) => { |
| var _ref; |
| const hex = (_ref = braced !== null && braced !== void 0 ? braced : unbraced) !== null && _ref !== void 0 ? _ref : ""; |
| return String.fromCodePoint(parseInt(hex, 16)); |
| }); |
| } |
| return result; |
| } |
| } |
|
|
| |
| |
| |
| function alignValue(value, precedingText) { |
| if (typeof value !== "string" || !value.includes("\n")) { |
| return value; |
| } |
| const currentLine = precedingText.slice(precedingText.lastIndexOf("\n") + 1); |
| const indentMatch = currentLine.match(/^(\s+)/); |
| if (indentMatch) { |
| const indent = indentMatch[1]; |
| return value.replace(/\n/g, `\n${indent}`); |
| } |
| return value; |
| } |
| module.exports = exports.default; |
| module.exports.default = exports.default; |
|
|