Files
NapCatQQ/.pnpm-store/v3/files/6b/7f3d650d147ca4cd54c94eec3699c938ddd4f3c96d250212c12abb55c58de7639392d914476b6e6fb6fc046ae7b83e566e10b8eb0f6a07c12035bbc5580c68
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

29 lines
842 B
Plaintext

import { Transform } from './index.js';
import { Block, Line } from '../primitives.js';
import { rewireSource } from '../util.js';
const pull = (offset: number) => (str) => str.slice(offset);
const push = (offset: number) => {
const space = ''.padStart(offset, ' ');
return (str) => str + space;
};
export default function indent(pos: number): Transform {
let shift: (string: string) => string;
const pad = (start: string) => {
if (shift === undefined) {
const offset = pos - start.length;
shift = offset > 0 ? push(offset) : pull(-offset);
}
return shift(start);
};
const update = (line: Line): Line => ({
...line,
tokens: { ...line.tokens, start: pad(line.tokens.start) },
});
return ({ source, ...fields }: Block): Block =>
rewireSource({ ...fields, source: source.map(update) });
}