Skip to content
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

docs(jsonc): complete documentation #4169

Merged
merged 1 commit into from
Jan 12, 2024
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
19 changes: 10 additions & 9 deletions jsonc/parse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** {@linkcode parse} function for parsing
* [JSONC](https://code.visualstudio.com/docs/languages/json#_json-with-comments)
/**
* {@linkcode parse} function for parsing
* {@link https://code.visualstudio.com/docs/languages/json#_json-with-comments | JSONC}
* (JSON with Comments) strings.
*
* This module is browser compatible.
Expand All @@ -15,6 +16,7 @@ import { assert } from "../assert/assert.ts";
import type { JsonValue } from "../json/common.ts";
export type { JsonValue } from "../json/common.ts";

/** Options for {@linkcode parse}. */
export interface ParseOptions {
/** Allow trailing commas at the end of arrays and objects.
*
Expand All @@ -25,18 +27,17 @@ export interface ParseOptions {

/**
* Converts a JSON with Comments (JSONC) string into an object.
* If a syntax error is found, throw a SyntaxError.
* If a syntax error is found, throw a {@linkcode SyntaxError}.
*
* @example
*
* ```ts
* import * as JSONC from "https://deno.land/std@$STD_VERSION/jsonc/mod.ts";
* import { parse } from "https://deno.land/std@$STD_VERSION/jsonc/mod.ts";
*
* console.log(JSONC.parse('{"foo": "bar", } // comment')); //=> { foo: "bar" }
* console.log(JSONC.parse('{"foo": "bar", } /* comment *\/')); //=> { foo: "bar" }
* console.log(JSONC.parse('{"foo": "bar" } // comment', {
* console.log(parse('{"foo": "bar", } // comment')); // { foo: "bar" }
* console.log(parse('{"foo": "bar", } /* comment *\/')); // { foo: "bar" }
* console.log(parse('{"foo": "bar" } // comment', {
* allowTrailingComma: false,
* })); //=> { foo: "bar" }
* })); // { foo: "bar" }
* ```
*
* @param text A valid JSONC string.
Expand Down