# @mischnic/json-sourcemap

> Generate positions for values in JSON and JSON5 strings

Latest version **0.1.1** (published 2023-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mischnic/json-sourcemap
pnpm add @mischnic/json-sourcemap
yarn add @mischnic/json-sourcemap
bun add @mischnic/json-sourcemap
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-09-20 |
| First published | 2022-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 3 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | mischnic |

## Links

- npm: https://www.npmjs.com/package/@mischnic/json-sourcemap
- Repository: https://github.com/mischnic/json-sourcemap
- npm.io page: https://npm.io/package/@mischnic/json-sourcemap

## Dependencies (3)

- [json5](https://npm.io/package/json5.md) ^2.2.1
- [@lezer/lr](https://npm.io/package/@lezer/lr.md) ^1.0.0
- [@lezer/common](https://npm.io/package/@lezer/common.md) ^1.0.0

## Recent versions

- 0.1.1 (latest) — 2023-09-20
- 0.1.0 — 2022-04-10

## README

# @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

```ts
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.

---
_Source: https://npm.io/package/@mischnic/json-sourcemap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
