@mischnic/json-sourcemap
Generate positions for values in JSON and JSON5 strings
Last updated 3 years ago by mischnic .
MIT · Repository · Original npm · Tarball · package.json
$ npm install @mischnic/json-sourcemap 
SYNC missed versions from official npm registry.

@mischnic/json-sourcemap

Generate positions for values in JSON and JSON5 strings.

Inspired by and mostly API-compatible with https://github.com/epoberezkin/json-source-map.

Usage

type Position = {
  line: number;
  column: number;
  pos: number;
};

type Mapping =
  | {
      value: Position;
      valueEnd: Position;
    }
  | {
      value: Position;
      valueEnd: Position;
      key?: Position;
      keyEnd?: Position;
    };

export function parse(
  json: string,
  reviver?: (key: any, value: any) => any,
  options?: {
    tabWidth?: number;
    dialect?: "JSON5" | "JSON";
  }
): {
  data: any;
  pointers: Record<string, Mapping>;
};

The default tabWidth is 4.

The valueEnd and keyEnd positions are exclusive. line, column and pos are 0-based.

Current Tags

  • 0.1.1                                ...           latest (a year ago)

2 Versions

  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (6)

© 2010 - cnpmjs.org x YWFE | Home | YWFE