Files
NapCatQQ/.pnpm-store/v3/files/f2/937e1854367e2f787d65e7e10f0c79817a21dc51b9d311ea0c5a39ebb06e02bb8823b947ca871159c4fb553bf29e5dbd36ac1fc53b00b5d88755c7b181319b
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

25 lines
620 B
Plaintext

export default function stripIndent(string) {
const match = string.match(/^[ \t]*(?=\S)/gm);
if (!match) {
return string;
}
let minIndent = Number.POSITIVE_INFINITY;
for (const indent of match) {
minIndent = Math.min(minIndent, indent.length);
}
if (minIndent === 0 || minIndent === Number.POSITIVE_INFINITY) {
return string;
}
return string.replace(new RegExp(`^[ \\t]{${minIndent}}`, 'gm'), '');
}
export function dedent(string) {
// Remove all leading and trailing whitespace-only lines
const trimmed = string.replace(/^(?:[ \t]*\r?\n)+|(?:\r?\n[ \t]*)+$/g, '');
return stripIndent(trimmed);
}