@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
1 lines • 3.77 kB
Source Map (JSON)
{"version":3,"file":"getChunk.cjs","names":["splitTextByLines"],"sources":["../../../src/utils/getChunk.ts"],"sourcesContent":["import { splitTextByLines } from './splitTextByLine';\n\ntype TrunkOptions = {\n lineStart?: number;\n lineLength?: number;\n charStart?: number;\n charLength?: number;\n};\n\nexport const getChunk = (text: string, options: TrunkOptions = {}): string => {\n const { lineStart, lineLength, charStart, charLength } = options;\n\n // Fast-path: if no filters were provided, return the whole text\n if (\n lineStart === undefined &&\n lineLength === undefined &&\n charStart === undefined &&\n charLength === undefined\n ) {\n return text;\n }\n\n // ---------------------------------------------------------------------------\n // Utility helpers to convert between line numbers and absolute char indices\n // ---------------------------------------------------------------------------\n const lines = splitTextByLines(text);\n\n const getCharIndexOfLineStart = (lineNumber: number): number => {\n if (lineNumber <= 0) return 0;\n // Sum the length of every previous line\n let idx = 0;\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n idx += lines[i].length;\n }\n return idx;\n };\n\n const getCharIndexOfLineEnd = (lineNumber: number): number => {\n // If the requested line number exceeds the number of lines, clamp to the last character\n if (lineNumber >= lines.length) {\n return text.length;\n }\n const line = lines[lineNumber];\n const lineEnd = getCharIndexOfLineStart(lineNumber) + line.length;\n\n return lineEnd;\n };\n\n // ---------------------------------------------------------------------------\n // Compute the effective (inclusive) charStart/charEnd for the requested slice\n // ---------------------------------------------------------------------------\n let effectiveStart = 0; // inclusive\n let effectiveEnd = text.length; // exclusive\n\n // Apply line boundaries if provided\n if (lineStart !== undefined) {\n effectiveStart = Math.max(\n effectiveStart,\n getCharIndexOfLineStart(lineStart)\n );\n }\n\n // Apply character boundaries if provided\n if (charStart !== undefined) {\n effectiveStart = Math.max(effectiveStart, charStart);\n }\n\n // Apply line length boundary from lineStart (or 0)\n if (lineLength !== undefined) {\n const endLine = (lineStart ?? 0) + lineLength - 1;\n effectiveEnd = Math.min(effectiveEnd, getCharIndexOfLineEnd(endLine));\n }\n\n // Apply character length boundary from effectiveStart\n if (charLength !== undefined) {\n effectiveEnd = Math.min(\n effectiveEnd,\n (charStart ?? effectiveStart) + charLength\n );\n }\n\n // If bounds do not overlap, return empty string\n if (effectiveStart >= effectiveEnd) {\n return '';\n }\n\n return text.slice(effectiveStart, effectiveEnd);\n};\n"],"mappings":";;;;AASA,MAAa,YAAY,MAAc,UAAwB,CAAC,MAAc;CAC5E,MAAM,EAAE,WAAW,YAAY,WAAW,eAAe;CAGzD,IACE,cAAc,UACd,eAAe,UACf,cAAc,UACd,eAAe,QAEf,OAAO;CAMT,MAAM,QAAQA,+CAAiB,IAAI;CAEnC,MAAM,2BAA2B,eAA+B;EAC9D,IAAI,cAAc,GAAG,OAAO;EAE5B,IAAI,MAAM;EACV,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,YAAY,MAAM,MAAM,GAAG,KACtD,OAAO,MAAM,GAAG;EAElB,OAAO;CACT;CAEA,MAAM,yBAAyB,eAA+B;EAE5D,IAAI,cAAc,MAAM,QACtB,OAAO,KAAK;EAEd,MAAM,OAAO,MAAM;EAGnB,OAFgB,wBAAwB,UAAU,IAAI,KAAK;CAG7D;CAKA,IAAI,iBAAiB;CACrB,IAAI,eAAe,KAAK;CAGxB,IAAI,cAAc,QAChB,iBAAiB,KAAK,IACpB,gBACA,wBAAwB,SAAS,CACnC;CAIF,IAAI,cAAc,QAChB,iBAAiB,KAAK,IAAI,gBAAgB,SAAS;CAIrD,IAAI,eAAe,QAAW;EAC5B,MAAM,WAAW,aAAa,KAAK,aAAa;EAChD,eAAe,KAAK,IAAI,cAAc,sBAAsB,OAAO,CAAC;CACtE;CAGA,IAAI,eAAe,QACjB,eAAe,KAAK,IAClB,eACC,aAAa,kBAAkB,UAClC;CAIF,IAAI,kBAAkB,cACpB,OAAO;CAGT,OAAO,KAAK,MAAM,gBAAgB,YAAY;AAChD"}