UNPKG

749 BMarkdownView Raw
1# @mischnic/json-sourcemap
2
3Generate positions for values in JSON and JSON5 strings.
4
5Inspired by and mostly API-compatible with https://github.com/epoberezkin/json-source-map.
6
7## Usage
8
9```ts
10type Position = {
11 line: number;
12 column: number;
13 pos: number;
14};
15
16type Mapping =
17 | {
18 value: Position;
19 valueEnd: Position;
20 }
21 | {
22 value: Position;
23 valueEnd: Position;
24 key?: Position;
25 keyEnd?: Position;
26 };
27
28export function parse(
29 json: string,
30 reviver?: (key: any, value: any) => any,
31 options?: {
32 tabWidth?: number;
33 useJSON5?: boolean;
34 }
35): {
36 data: any;
37 pointers: Record<string, Mapping>;
38};
39```
40
41The default `tabWidth` is 4.
42
43The `valueEnd` and `keyEnd` positions are exclusive. `line`, `column` and `pos` are 0-based.