From 477a55aea072c0d22f4f960b3fb6d40e000fa166 Mon Sep 17 00:00:00 2001 From: Rick Wilson Date: Sat, 24 Feb 2024 18:02:00 -0500 Subject: [PATCH 1/3] added types --- index.d.ts | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..1fe79a0 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,79 @@ +declare module 'json-source-map' { + // Options for parsing JSON, allowing for custom behavior such as bigint support and jsonc (JSON with comments). + export interface ParseOptions { + bigint?: boolean; // Specifies if BigInt values should be parsed as native BigInt types. + jsonc?: boolean; // Specifies if JSON with comments (jsonc) should be correctly parsed. + } + + // Options for stringifying values into JSON, allowing for customization of the output. + export interface StringifyOptions { + space?: string | number; // Specifies the indentation for beautifying the output JSON. + es6?: boolean; // Specifies if ES6 features (e.g., Set, Map) are allowed in the output. + } + + // The result of parsing JSON, including the data and pointers to various elements within the JSON string. + export interface ParseResult { + data: any; // The parsed data as a JavaScript object. + pointers: { + [key: string]: { + value: any; // The value of the property or element. + valuePos: { // The starting position of the value in the original JSON string. + line: number; + column: number; + pos: number; + }; + valueEnd: { // The ending position of the value in the original JSON string. + line: number; + column: number; + pos: number; + }; + key?: { // The starting position of the key in the original JSON string (for object properties). + line: number; + column: number; + pos: number; + }; + keyEnd?: { // The ending position of the key in the original JSON string (for object properties). + line: number; + column: number; + pos: number; + }; + }; + }; + } + + // The result of stringifying a JavaScript value into JSON, including the JSON string and pointers to elements. + export interface StringifyResult { + json: string; // The generated JSON string. + pointers: { + [key: string]: { + value: any; // The value of the property or element. + valuePos: { // The starting position of the value in the resulting JSON string. + line: number; + column: number; + pos: number; + }; + valueEnd: { // The ending position of the value in the resulting JSON string. + line: number; + column: number; + pos: number; + }; + key?: { // The starting position of the key in the resulting JSON string (for object properties). + line: number; + column: number; + pos: number; + }; + keyEnd?: { // The ending position of the key in the resulting JSON string (for object properties). + line: number; + column: number; + pos: number; + }; + }; + }; + } + + // Parses a JSON string into a JavaScript object, with options for handling BigInt and comments (jsonc). + export function parse(json: string, _?: any, options?: ParseOptions): ParseResult; + + // Converts a JavaScript value to a JSON string, with options for output formatting and ES6 feature inclusion. + export function stringify(value: any, _?: any, options?: string | number | StringifyOptions): StringifyResult; +} From 9921605df6eedebec267bf62adcb38413bd01dc6 Mon Sep 17 00:00:00 2001 From: Rick Wilson Date: Sat, 24 Feb 2024 18:07:06 -0500 Subject: [PATCH 2/3] update to include types in package --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8ba2a8e..a5234dd 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.6.1", "description": "Parse/stringify JSON and provide source-map for JSON-pointers to all nodes", "main": "index.js", + "types": "index.d.ts", "scripts": { "eslint": "eslint index.js spec", "test-spec": "mocha spec -R spec", From 54aa9e9dd3908c365b629148451b15add73cff6e Mon Sep 17 00:00:00 2001 From: Rick Wilson Date: Sat, 24 Feb 2024 21:53:38 -0500 Subject: [PATCH 3/3] updates --- index.d.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1fe79a0..76b8da8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -15,9 +15,8 @@ declare module 'json-source-map' { export interface ParseResult { data: any; // The parsed data as a JavaScript object. pointers: { - [key: string]: { - value: any; // The value of the property or element. - valuePos: { // The starting position of the value in the original JSON string. + [key: string]: { + value: { // The starting position of the value in the original JSON string. line: number; column: number; pos: number; @@ -46,8 +45,7 @@ declare module 'json-source-map' { json: string; // The generated JSON string. pointers: { [key: string]: { - value: any; // The value of the property or element. - valuePos: { // The starting position of the value in the resulting JSON string. + value: { // The starting position of the value in the resulting JSON string. line: number; column: number; pos: number;