Skip to content

Improve README #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 43 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand All @@ -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.
Expand All @@ -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;
/**
Expand Down Expand Up @@ -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[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely sure if declare is needed here; the README does not seem to use it consistently.

export interface Location {
/**
* The previous property key or literal value (string, number, boolean or null) or undefined.
Expand All @@ -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.
*/
Expand All @@ -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
Expand Down Expand Up @@ -255,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;
}

```
Expand Down