Socket
Socket
Sign inDemoInstall

@mischnic/json-sourcemap

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mischnic/json-sourcemap

Generate positions for values in JSON and JSON5 strings


Version published
Weekly downloads
382K
decreased by-23.17%
Maintainers
1
Install size
526 kB
Created
Weekly downloads
 

Readme

Source

@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;
		useJSON5?: boolean;
	}
): {
	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.

FAQs

Last updated on 10 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc