From f3158c7c8e0ff6c7f37cbc3b859964f980a96b5d Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Mon, 30 Aug 2021 00:22:43 +0200 Subject: [PATCH 1/2] Add missing type definition for `JSONPath` to README --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2b2148c..d7c88b7 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,10 @@ JSONC is JSON with JavaScript style comments. This node module provides a scanne Installation ------------ - npm install --save jsonc-parser - - +``` +npm install --save jsonc-parser +``` + API --- @@ -34,7 +35,7 @@ API * Creates a JSON scanner on the given text. * If ignoreTrivia is set, whitespaces or comments are ignored. */ -export function createScanner(text:string, ignoreTrivia:boolean = false):JSONScanner; +export function createScanner(text: string, ignoreTrivia: boolean = false): JSONScanner; /** * The scanner object, representing a JSON scanner at a position in the input string. @@ -57,7 +58,7 @@ export interface JSONScanner { */ getToken(): SyntaxKind; /** - * Returns the last read token value. The value for strings is the decoded string content. For numbers its of type number, for boolean it's true or false. + * Returns the last read token value. The value for strings is the decoded string content. For numbers it's of type number, for boolean it's true or false. */ getTokenValue(): string; /** @@ -172,6 +173,7 @@ export declare function stripComments(text: string, replaceCh?: string): string; export declare function getLocation(text: string, position: number): Location; export declare type Segment = string | number; +export declare type JSONPath = Segment[]; export interface Location { /** * The previous property key or literal value (string, number, boolean or null) or undefined. @@ -181,13 +183,13 @@ export interface Location { * The path describing the location in the JSON document. The path consists of a sequence strings * representing an object property or numbers for array indices. */ - path: Segment[]; + path: JSONPath; /** * Matches the locations path against a pattern consisting of strings (for properties) and numbers (for array indices). * '*' will match a single segment, of any property name or index. - * '**' will match a sequece of segments or no segment, of any property name or index. + * '**' will match a sequence of segments or no segment, of any property name or index. */ - matches: (patterns: Segment[]) => boolean; + matches: (patterns: JSONPath) => boolean; /** * If set, the location's offset is at a property key. */ @@ -207,7 +209,7 @@ export function findNodeAtOffset(root: Node, offset: number, includeRightBound?: /** * Gets the JSON path of the given JSON DOM node */ -export function getNodePath(node: Node) : JSONPath; +export function getNodePath(node: Node): JSONPath; /** * Evaluates the JavaScript object of the given JSON DOM node From 98a453fca668dbed09e6e6cb2e473474c1c98f05 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Mon, 30 Aug 2021 00:25:06 +0200 Subject: [PATCH 2/2] Consistently use 4 spaces as indentation for README code blocks --- README.md | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index d7c88b7..2822a0f 100644 --- a/README.md +++ b/README.md @@ -257,47 +257,47 @@ export function applyEdits(text: string, edits: Edit[]): string; * Represents a text modification */ export interface Edit { - /** - * The start offset of the modification. - */ - offset: number; - /** - * The length of the modification. Must not be negative. Empty length represents an *insert*. - */ - length: number; - /** - * The new content. Empty content represents a *remove*. - */ - content: string; + /** + * The start offset of the modification. + */ + offset: number; + /** + * The length of the modification. Must not be negative. Empty length represents an *insert*. + */ + length: number; + /** + * The new content. Empty content represents a *remove*. + */ + content: string; } /** * A text range in the document */ export interface Range { - /** - * The start offset of the range. - */ - offset: number; - /** - * The length of the range. Must not be negative. - */ - length: number; + /** + * The start offset of the range. + */ + offset: number; + /** + * The length of the range. Must not be negative. + */ + length: number; } export interface FormattingOptions { - /** - * If indentation is based on spaces (`insertSpaces` = true), then what is the number of spaces that make an indent? - */ - tabSize: number; - /** - * Is indentation based on spaces? - */ - insertSpaces: boolean; - /** - * The default 'end of line' character - */ - eol: string; + /** + * If indentation is based on spaces (`insertSpaces` = true), then what is the number of spaces that make an indent? + */ + tabSize: number; + /** + * Is indentation based on spaces? + */ + insertSpaces: boolean; + /** + * The default 'end of line' character + */ + eol: string; } ```