Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/core/api/mapped-string.ts
6458 views
1
// src/core/api/mapped-string.ts
2
3
import { globalRegistry } from "./registry.ts";
4
import type { MappedStringNamespace } from "./types.ts";
5
6
// Import implementations
7
import {
8
asMappedString,
9
mappedIndexToLineCol,
10
mappedLines,
11
mappedNormalizeNewlines,
12
} from "../lib/mapped-text.ts";
13
import { mappedStringFromFile } from "../mapped-text.ts";
14
import type { MappedString } from "../lib/text-types.ts";
15
16
// Register mappedString namespace
17
globalRegistry.register("mappedString", (): MappedStringNamespace => {
18
return {
19
fromString: asMappedString,
20
fromFile: mappedStringFromFile,
21
normalizeNewlines: mappedNormalizeNewlines,
22
splitLines: (str: MappedString, keepNewLines?: boolean) => {
23
return mappedLines(str, keepNewLines);
24
},
25
indexToLineCol: (str: MappedString, offset: number) => {
26
const fn = mappedIndexToLineCol(str);
27
return fn(offset);
28
},
29
};
30
});
31
32