diff --git a/.gitpod.yml b/.gitpod.yml index c0915d2..95a0513 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -10,15 +10,16 @@ tasks: vscode: extensions: - - "denoland.vscode-deno" - - "editorconfig.editorconfig" - - "vsls-contrib.gistfs" - - "sdras.night-owl" - - "redhat.vscode-yaml" - - "antfu.browse-lite" - - "bierner.markdown-preview-github-styles" - - "gitpod.gitpod-desktop" - - "gitpod.gitpod-remote-ssh" + - denoland.vscode-deno + - editorconfig.editorconfig + - vsls-contrib.gistfs + - sdras.night-owl + - redhat.vscode-yaml + - antfu.browse-lite + - bierner.markdown-preview-github-styles + - gitpod.gitpod-desktop + - gitpod.gitpod-remote-ssh + - yzhang.markdown-all-in-one github: prebuilds: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 58d429c..4b228db 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,7 +2,7 @@ "recommendations": [ "denoland.vscode-deno", "editorconfig.editorconfig", - "GitHub.codespaces", + "github.codespaces", "gitpod.gitpod-desktop", "gitpod.gitpod-remote-ssh", "vsls-contrib.gistfs", @@ -10,6 +10,7 @@ "redhat.vscode-yaml", "antfu.iconify", "antfu.browse-lite", - "bierner.markdown-preview-github-styles" + "bierner.markdown-preview-github-styles", + "yzhang.markdown-all-in-one" ] } diff --git a/README.md b/README.md index 0962b43..bad9074 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,20 @@ -# [![deno911/this](https://migo.deno.dev/img.png?titleFontFamily=monospace&titleFontSize=100&titleFontWeight=100&&titleTextAnchor=left&titleX=60&titleY=150&subtitleFontSize=27&subtitleFontWeight=100&subtitleFontFamily=monospace&subtitleTextAnchor=middle&subtitleX=500&subtitleY=260&width=1000&height=300&bgColor=111827&titleColor=c0ff3e&subtitleColor=fff&iconW=150&iconH=150&iconX=820&iconY=30&borderRadius=20&icon=fluent-emoji:sauropod&pxRatio=1.5&title=this&subtitle=extends+globalThis+with+std%2ftesting+%26+std%2fencoding+tools "deno911/this - extend globalThis with std/testing and std/encoding tools")](https://deno.land/x/this "deno911/this - extend globalThis with std/testing and std/encoding tools") +# [![deno911/this][banner-img]][this] -`this` uses **side-effect imports**: by simply importing the filename, all methods are immediately available to your project. **Please be mindful - this is experimental!** - -# Usage +## **Usage** ```ts -import "https://deno.land/x/this@0.160.0/mod.ts"; +import "https://deno.land/x/this@0.160.1/mod.ts"; ``` -> **Warning**: this exposes **everything** globally. **Not recommended**. -> Instead, import only the section/subsection that fits your needs. - ---- - -
Table of Contents
+
Table of Contents
+- [**Usage**](#usage) - [**encoding**](#encoding) - [**`CSV`**](#csv) - [**`JSONC`**](#jsonc) - [**`JSON5`**](#json5) - - [**`JSONStream`**](#jsonstream) + - [**`JsonStream`**](#jsonstream) - [**`TOML`**](#toml) - [**`YAML`**](#yaml) - [**`FrontMatter`**](#frontmatter) @@ -29,47 +23,46 @@ import "https://deno.land/x/this@0.160.0/mod.ts"; - [**`binary`**](#binary) - [**`Hex`**](#hex) - [**testing**](#testing) + - [**`all`**](#all) - [**`asserts`**](#asserts) - [**`bdd`**](#bdd) - [**`mock`**](#mock) - [**`snapshot`**](#snapshot) - - [Third Party](#third-party) -- [**examples**](#examples) - - [`JSONC`, `JSON5`, `YAML`, `TOML`, ...](#jsonc-json5-yaml-toml-) - - [`FrontMatter.extract`](#frontmatterextract) - - [`describe` + `it`](#describe--it) - - [`assertEquals` + `AssertionError`](#assertequals--assertionerror) - - [**`chai`** (chai.js)](#chai-chaijs) - - [**`fc`** (fastcheck)](#fc-fastcheck) -- [Contributing](#contributing) - - [⚠️ Fixing a bug? Create an Issue first](#️-fixing-a-bug-create-an-issue-first) - - [Fork + clone the repository](#fork--clone-the-repository) - - [Create a new branch for your changes](#create-a-new-branch-for-your-changes) - - [Make small changes and concise commits](#make-small-changes-and-concise-commits) - - [Open a Pull Request](#open-a-pull-request) - - [🅓🅔🅝🅞⑨①①](#) - -
+ - [**`chai`**](#chai) + - [**`fc`**](#fc-fastcheck) +- [**Examples**](#examples) +- [**Contributing**](#contributing) + +

+ +This project uses side-effect imports to extend the global namespace of the Deno runtime. It adds various tools from Deno Standard Library's `encoding` and `testing` suites. + +For example, by importing `./encoding.ts`, your project will have access to `CSV`, `JSON5`, `YAML`, and `TOML` modules (to name a few) **at the global level**. See all available API's below. + +--- ## **encoding** -`this/encoding` exposes all the [`std/encoding`](https://deno.land/std/encoding) modules from the +`this/encoding` exposes all the [`std/encoding`](https://deno.land/std@0.160.0/encoding) modules from the Deno Standard Library, along with a few extra goodies too. ```ts -import "https://deno.land/x/this@0.160.0/encoding.ts"; +import "https://deno.land/x/this@0.160.1/encoding.ts"; ``` -### **`CSV`** +### **CSV** ```ts -import "https://deno.land/x/this@0.160.0/encoding/csv.ts"; +import "https://deno.land/x/this@0.160.1/encoding/csv.ts"; ``` #### `.parse` ```ts CSV.parse(text: string, options?: CSV.ParseOptions): string[][]; +``` + +```ts CSV.parse(text: string, { columns?: CSV.Column[]; }): Record; ``` @@ -79,12 +72,12 @@ CSV.parse(text: string, { columns?: CSV.Column[]; }): Record; CSV.stringify(data: CSV.DataItem[], options?: CSV.StringifyOptions): string; ``` -> **Source**: [std@0.160.0/encoding/csv.ts](https://deno.land/std@0.160.0/encoding/csv.ts) +> **Source**: [**`std@0.160.0/encoding/csv.ts`**](https://deno.land/std@0.160.0/encoding/csv.ts) -### **`JSONC`** +### **JSONC** ```ts -import "https://deno.land/x/this@0.160.0/encoding/jsonc.ts"; +import "https://deno.land/x/this@0.160.1/encoding/jsonc.ts"; ``` #### `.parse` @@ -97,17 +90,18 @@ JSONC.parse(data: string, { allowTrailingComma?: boolean }): JsonValue; ```ts JSONC.stringify(data: JsonValue, replacer?: (key: string, value: any) => any, space?: string | number): string; +``` -// overload #1: +```ts JSONC.stringify(data: JsonValue, replacer?: (string | number)[], space?: string | number): string; ``` -> **Source**: [std@0.160.0/encoding/jsonc.ts](https://deno.land/std@0.160.0/encoding/jsonc.ts) +> **Source**: [**`std@0.160.0/encoding/jsonc.ts`**](https://deno.land/std@0.160.0/encoding/jsonc.ts) -### **`JSON5`** +### **JSON5** ```ts -import "https://deno.land/x/this@0.160.0/encoding/json5.ts"; +import "https://deno.land/x/this@0.160.1/encoding/json5.ts"; ``` #### `.parse` @@ -134,29 +128,80 @@ JSON5.require(path: string | URL, reviver?: JSONReviverFn): T; JSON5.require(path: string | URL, reviver?: JSONReviverFn): Promise; ``` -### **`JSONStream`** +### **JsonStream** + +```ts +import "https://deno.land/x/this@0.160.1/encoding/jsonstream.ts"; +``` + +This is a custom implementation of the Deno Standard Library's JsonStream classes. + +Importing `jsonstream.ts` creates a global named **`JsonStream`** with these properties: + +#### `.Parse` + +Shorthand alias for the **`JsonParseStream`** class. + +Must be called with the **`new`** keyword before its constructor, like so: ```ts -import "https://deno.land/x/this@0.160.0/encoding/jsonstream.ts"; +const stream = new JsonStream.Parse(...options); ``` +[**`JsonParseStream Documentation`**](https://doc.deno.land/https://deno.land/std@0.160.0/encoding/json/stream.ts/~/JsonParseStream) + +#### `.Stringify` + +Shorthand alias for the **`JsonStringifyStream`** class. + +Must be called with the **`new`** keyword before its constructor, like so: + ```ts -interface JSONStream { - Parse: typeof JsonParseStream; - Stringify: typeof JsonStringifyStream; - Concatenated: typeof ConcatenatedJsonParseStream; - useParse({ writableStrategy, readableStrategy }: ParseStreamOptions): JsonParseStream; - useStringify({ writableStrategy, readableStrategy, prefix, suffix, }: StringifyStreamOptions): JsonStringifyStream; - useConcat({ writableStrategy, readableStrategy }: ParseStreamOptions): ConcatenatedJsonParseStream; -} +const stream = new JsonStream.Stringify(...options); ``` -> **Note**: see [**std/encoding/json/stream.ts**](https://deno.land/std@0.160.0/encoding/json/stream.ts) for more info on JSONStream classes. +[**`JsonStringifyStream Documentation`**](https://doc.deno.land/https://deno.land/std@0.160.0/encoding/json/stream.ts/~/JsonStringifyStream) + +#### `.Concatenated` -### **`TOML`** +Shorthand alias for the **`ConcatenatedJsonParseStream`** class. + +Must be called with the **`new`** keyword before its constructor, like so: ```ts -import "https://deno.land/x/this@0.160.0/encoding/toml.ts"; +const stream = new JsonStream.Concatenated(...options); +``` + +[**`ConcatenatedJsonParseStream Documentation`**](https://doc.deno.land/https://deno.land/std@0.160.0/encoding/json/stream.ts/~/ConcatenatedJsonParseStream) + +#### `.useParse` + +Shorthand equivalent to calling **`new JsonStream.Parse()`**, this creates a new instance of the `JsonParseStream` class. + +```ts +const stream = JsonStream.useParse(...options); +``` + +#### `.useStringify` + +Shorthand equivalent to calling **`new JsonStream.Stringify()`**, this creates a new instance of the **`JsonStringifyStream`** class. + +```ts +const stream = JsonStream.useStringify(...options); +``` + +#### `.useConcat` + +Shorthand equivalent to calling **`new JsonStream.Concatenated()`**, this creates a new instance of the **`ConcatenatedJsonParseStream`** class. + +```ts +const stream = JsonStream.useConcat(...options); +``` + +### **TOML** + +```ts +import "https://deno.land/x/this@0.160.1/encoding/toml.ts"; ``` #### `.parse` @@ -171,39 +216,43 @@ TOML.parse(text: string): Record; TOML.stringify(data: Record, options: TOML.FormatOptions): string; ``` -> **Source**: [std@0.160.0/encoding/toml.ts](https://deno.land/std@0.160.0/encoding/toml.ts) +> **Source**: [**`std@0.160.0/encoding/toml.ts`**](https://deno.land/std@0.160.0/encoding/toml.ts) -### **`YAML`** +### **YAML** ```ts -import "https://deno.land/x/this@0.160.0/encoding/yaml.ts"; +import "https://deno.land/x/this@0.160.1/encoding/yaml.ts"; ``` #### `.parse` ```ts -YAML.parse() // TODO +YAML.parse(content: string, options?: LoaderStateOptions): unknown; ``` #### `.parseAll` ```ts -YAML.parseAll() // TODO +YAML.parseAll(content: string, options?: LoaderStateOptions): unknown; +``` + +```ts +YAML.parseAll(content: string, iterator: CbFunction, options?: LoaderStateOptions); ``` #### `.stringify` ```ts -YAML.stringify() // TODO +YAML.stringify(obj: Record, options?: DumperStateOptions): string; ``` -> **Source**: [std@0.160.0/encoding/yaml.ts](https://deno.land/std@0.160.0/encoding/yaml.ts) +> **Source**: [**`std@0.160.0/encoding/yaml.ts`**](https://deno.land/std@0.160.0/encoding/yaml.ts) -### **`FrontMatter`** +### **FrontMatter** ```ts -import "https://deno.land/x/this@0.160.0/encoding/front_matter.ts"; +import "https://deno.land/x/this@0.160.1/encoding/front_matter.ts"; ``` #### `.extract` @@ -226,14 +275,14 @@ type Extract = { FrontMatter.test(markdown: string): boolean; ``` -> **Source**: [std@0.160.0/encoding/front_matter.ts](https://deno.land/std@0.160.0/encoding/front_matter.ts) +> **Source**: [**`std@0.160.0/encoding/front_matter.ts`**](https://deno.land/std@0.160.0/encoding/front_matter.ts) --- -### **`base64`** +### **base64** ```ts -import "https://deno.land/x/this@0.160.0/encoding/base64.ts"; +import "https://deno.land/x/this@0.160.1/encoding/base64.ts"; ``` #### `.encode` @@ -254,14 +303,14 @@ base64.decode(b64: string): string; base64.decodeBytes(b64: string): Uint8Array; ``` -> **Source**: [`std@0.160.0/encoding/base64.ts`](https://deno.land/std@0.160.0/encoding/base64.ts) +> **Source**: [**``std@0.160.0/encoding/base64.ts``**](https://deno.land/std@0.160.0/encoding/base64.ts) --- -### **`base64url`** +### **base64url** ```ts -import "https://deno.land/x/this@0.160.0/encoding/base64url.ts"; +import "https://deno.land/x/this@0.160.1/encoding/base64url.ts"; ``` #### `.encode` @@ -282,23 +331,21 @@ base64.decode(b64url: string): string; base64.decodeBytes(b64url: string): Uint8Array; ``` -> **Source**: [std@0.160.0/encoding/base64url.ts](https://deno.land/std@0.160.0/encoding/base64url.ts) +> **Source**: [**`std@0.160.0/encoding/base64url.ts`**](https://deno.land/std@0.160.0/encoding/base64url.ts) -### **`binary`** +### **binary** ```ts -import "https://deno.land/x/this@0.160.0/encoding/binary.ts"; +import "https://deno.land/x/this@0.160.1/encoding/binary.ts"; ``` -#### `binary.*` +> **Source**: [**`std@0.160.0/encoding/binary.ts`**](https://deno.land/std@0.160.0/encoding/binary.ts) -> `TODO`: see [std@0.160.0/encoding/binary.ts](https://deno.land/std/encoding/binary.ts) for available methods - -### **`Hex`** +### **Hex** ```ts -import "https://deno.land/x/this@0.160.0/encoding/hex.ts"; +import "https://deno.land/x/this@0.160.1/encoding/hex.ts"; ``` #### `.encode` @@ -313,30 +360,43 @@ Hex.encode(); // TODO Hex.decode(); // TODO ``` -> **Source**: [std@0.160.0/encoding/hex.ts](https://deno.land/std@0.160.0/encoding/hex.ts) +> **Source**: [**`std@0.160.0/encoding/hex.ts`**](https://deno.land/std@0.160.0/encoding/hex.ts) --- ## **testing** ```ts -import "https://deno.land/x/this@0.160.0/testing.ts"; +import "https://deno.land/x/this@0.160.1/testing.ts"; ``` -### **`asserts`** +> **Note**: due to the size of [`chai`](#chai) and [`fc`](#fc-fastcheck), they +> have been excluded from the imports in the `./testing.ts` file. To use them, +> please import their respective files instead. Or, if you **really** want to +> YOLO, you can import ***all of the testing tools at once***. See below. + +### **all** ```ts -import "https://deno.land/x/this@0.160.0/testing/asserts.ts"; +import "https://deno.land/x/this@0.160.1/testing/all.ts"; ``` -> **Source**: [std/testing/asserts.ts](https://deno.land/std/testing/asserts.ts) +> **Warning**: this Imports everything below add quite a bit of weight to your project. + +### **asserts** + +```ts +import "https://deno.land/x/this@0.160.1/testing/asserts.ts"; +``` + +> **Source**: [**`std@0.160.0/testing/asserts.ts`**](https://deno.land/std@0.160.0/testing/asserts.ts) --- -### **`bdd`** +### **bdd** ```ts -import "https://deno.land/x/this@0.160.0/testing/bdd.ts"; +import "https://deno.land/x/this@0.160.1/testing/bdd.ts"; ``` #### `beforeAll` @@ -382,46 +442,36 @@ afterEach(() => { #### `it` -> **Source**: [std/testing/bdd.ts](https://deno.land/std/testing/bdd.ts) +> **Source**: [**`std@0.160.0/testing/bdd.ts`**](https://deno.land/std@0.160.0/testing/bdd.ts) -### **`mock`** +### **mock** ```ts -import "https://deno.land/x/this@0.160.0/testing/mock.ts"; +import "https://deno.land/x/this@0.160.1/testing/mock.ts"; ``` -> **Source**: [std/testing/mock.ts](https://deno.land/std/testing/mock.ts) +> **Source**: [**`std@0.160.0/testing/mock.ts`**](https://deno.land/std@0.160.0/testing/mock.ts) -### **`snapshot`** +### **snapshot** ```ts -import "https://deno.land/x/this@0.160.0/testing/snapshot.ts"; +import "https://deno.land/x/this@0.160.1/testing/snapshot.ts"; ``` -> **Source**: [std/testing/snapshot.ts](https://deno.land/std/testing/snapshot.ts) - ---- - -### Third Party - -> **Note**: starting in `0.160.0`, **chai** and **fastcheck** have been -> excluded from the `./testing.ts` file due to their large file size. -> Please import them from their respective files instead. If you **really** -> want to import ***all*** of the testing tools at once, you can use the -> newly created file at `./testing/all.ts` instead. +> **Source**: [**`std@0.160.0/testing/snapshot.ts`**](https://deno.land/std@0.160.0/testing/snapshot.ts) -#### **`chai`** +### **chai** ```ts -import "https://deno.land/x/this@0.160.0/testing/chai.ts"; +import "https://deno.land/x/this@0.160.1/testing/chai.ts"; ``` > **Source**: [**`chai@4.3.4`**]() -#### **`fc`** (fastcheck) +### **fc** (fastcheck) ```ts -import "https://deno.land/x/this@0.160.0/testing/fc.ts"; +import "https://deno.land/x/this@0.160.1/testing/fc.ts"; ``` > **Source**: [**`fast-check@3.2.0`**](https://github.com/dubzzz/fast-check#readme) @@ -430,12 +480,12 @@ import "https://deno.land/x/this@0.160.0/testing/fc.ts"; ## **examples** -### `JSONC`, `JSON5`, `YAML`, `TOML`, ... +### `JSONC`, `JSON5`, `YAML`, `TOML` Now you can use `CSV`, `JSON5`, `JSONC`, `YAML`, `TOML` (and more), just as easily as you would use JavaScript's builtin `JSON` object. Check it out below. ```ts -import "https://deno.land/x/this@0.160.0/encoding.ts"; +import "https://deno.land/x/this@0.160.1/encoding.ts"; // deno.jsonc => { "compilerOptions": { "lib": ["deno.ns", "deno.window"] }, ... } const deno_jsonc = JSONC.parse(await Deno.readTextFile("./deno.jsonc")); @@ -455,8 +505,8 @@ const deno_yml = YAML.stringify(deno_jsonc); ### `FrontMatter.extract` ```ts -import "https://deno.land/x/this@0.160.0/testing/asserts.ts"; -import "https://deno.land/x/this@0.160.0/encoding/front_matter.ts"; +import "https://deno.land/x/this@0.160.1/testing/asserts.ts"; +import "https://deno.land/x/this@0.160.1/encoding/front_matter.ts"; const { attrs, body, frontMatter } = FrontMatter.extract<{ title: string }>( "---\ntitle: Three dashes marks the spot\n---\n"); @@ -469,7 +519,7 @@ assertEquals(frontMatter, "title: Three dashes marks the spot"); ### `describe` + `it` ```ts -import "https://deno.land/x/this@0.160.0/testing/bdd.ts"; +import "https://deno.land/x/this@0.160.1/testing/bdd.ts"; let users: Map; @@ -498,7 +548,7 @@ describe("Users Map", () => { ### `assertEquals` + `AssertionError` ```ts -import "https://deno.land/x/this@0.160.0/testing/asserts.ts"; +import "https://deno.land/x/this@0.160.1/testing/asserts.ts"; Deno.test("Global Assertions", async ({ step }) => { @@ -516,44 +566,44 @@ Deno.test("Global Assertions", async ({ step }) => { ### **`chai`** (chai.js) ```ts -import "https://deno.land/x/this@0.160.0/testing/chai.ts"; +import "https://deno.land/x/this@0.160.1/testing/chai.ts"; ``` -### **`fc`** (fastcheck) +### **`fc`** ```ts -import "https://deno.land/x/this@0.160.0/testing/fc.ts"; +import "https://deno.land/x/this@0.160.1/testing/fc.ts"; ``` --- ## Contributing -### ⚠️ Fixing a bug? Create an Issue first +### ⚠️ Fixing a bug? Create an Issue first > Unless you're fixing a bug for which an issue already exists! -This allows the issue to be connected to your Pull Request, creating a permanent record of your contribution to the project. It also makes it easier for maintainers to track project progression. +This allows the issue to be connected to your Pull Request, creating a permanent record of your contribution to the project. It also helps maintainers with tracking project progression. Creating an issue also ensures you're given credit for fixing that bug. 😁 --- -### Fork + clone the repository +### Fork + clone the repository -> This section assumes you have [**the GitHub CLI**][gh] (you ***really* should**). +> **Note**: This section assumes you have [**the GitHub CLI**][gh]. You should get it. ```sh gh repo fork deno911/this --clone ``` -### Create a new branch for your changes +### Create a new branch for your changes ```sh git checkout -b fix/typo-in-readme ``` -### Make small changes and concise commits +### Make small changes and concise commits ```sh # hack hack hack... @@ -563,7 +613,7 @@ git commit README.md -m "fix: typos in README.md" && git push > **Note**: keep the scope of your changes relevant and concise. -### Open a Pull Request +### Open a Pull Request ```sh gh pr create --title "fix: typos in README.md" @@ -579,14 +629,14 @@ gh pr create --title "fix: typos in README.md"
-The foundation of this module was inspired by [ije/global](https://github.com/ije/global). +## [🅓🅔🅝🅞⑨①①][deno911] -### [🅓🅔🅝🅞⑨①①][deno911] +###### The foundation of this module was inspired by [ije/global][ije].
-[deno.land]: https://deno.land "Deno.land - Official Module Registry" -[nest.land]: https://nest.land "Nest.land - Immutable Module Registry" -[Arweave blockchain]: https://arweave.org "Arweave Blockchain" +[ije]: https://github.com/ije/global "The foundation of this module was inspired by ije/global" [deno911]: https://github.com/deno911 "Projects by deno911 on GitHub" [gh]: https://cli.github.com +[this]: https://deno.land/x/this "View deno911/this on deno.land/x" +[banner-img]: https://raw.githubusercontent.com/deno911/.github/main/static/this/banner.png "deno911/this - Extend Deno's globals with std/encoding & std/testing tools" \ No newline at end of file diff --git a/deps.ts b/deps.ts index d589d52..17c37c3 100644 --- a/deps.ts +++ b/deps.ts @@ -28,11 +28,11 @@ export * as snapshot from "https://deno.land/std@0.160.0/testing/snapshot.ts"; /* ./testing/mock.ts */ export * as mock from "https://deno.land/std@0.160.0/testing/mock.ts"; -/* third-party testing tools */ +/* ./testing/chai.ts - chai@4.3.4 */ export { default as chai } from "https://cdn.skypack.dev/chai@4.3.4?dts"; -export { default as fc } from "https://cdn.skypack.dev/fast-check@v3.1.1?dts"; -/* encoding */ +/* ./testing/fc.ts - fast-check@v3.2.0 */ +export { default as fc } from "https://cdn.skypack.dev/fast-check@v3.2.0?dts"; /* ./encoding/ascii.ts */ export * as ascii85 from "https://deno.land/std@0.160.0/encoding/ascii85.ts"; @@ -64,15 +64,16 @@ export * as FrontMatter from "https://deno.land/std@0.160.0/encoding/front_matte /* ./encoding/jsonc.ts */ export * as JSONC from "https://deno.land/std@0.160.0/encoding/jsonc.ts"; -/* ./encoding/json5.ts */ +/* ./encoding/json5.ts - json5@1.0.0 */ export { default as JSON5 } from "https://deno.land/x/json5@v1.0.0/mod.ts"; /* ./encoding/jsonstream.ts */ export { - ConcatenatedJsonParseStream as ConcatenatedJSONParseStream, - JsonParseStream as JSONParseStream, - JsonStringifyStream as JSONStringifyStream, + ConcatenatedJsonParseStream, + JsonParseStream, + JsonStringifyStream, type JsonValue as JSONValue, + type JsonValue, type ParseStreamOptions, type StringifyStreamOptions, } from "https://deno.land/std@0.160.0/encoding/json/stream.ts"; diff --git a/encoding/jsonstream.ts b/encoding/jsonstream.ts index f78e181..be8ada7 100644 --- a/encoding/jsonstream.ts +++ b/encoding/jsonstream.ts @@ -3,48 +3,48 @@ /// import { - ConcatenatedJSONParseStream, - JSONParseStream, - JSONStringifyStream, + ConcatenatedJsonParseStream, + JsonParseStream, + JsonStringifyStream, type ParseStreamOptions, type StringifyStreamOptions, } from "../deps.ts"; -type JSONStream = { - Parse: typeof JSONParseStream; - Stringify: typeof JSONStringifyStream; - Concatenated: typeof ConcatenatedJSONParseStream; +type JsonStream = { + Parse: typeof JsonParseStream; + Stringify: typeof JsonStringifyStream; + Concatenated: typeof ConcatenatedJsonParseStream; useParse( { writableStrategy, readableStrategy }: ParseStreamOptions, - ): JSONParseStream; + ): JsonParseStream; useStringify({ writableStrategy, readableStrategy, prefix, suffix, - }: StringifyStreamOptions): JSONStringifyStream; + }: StringifyStreamOptions): JsonStringifyStream; useConcat( { writableStrategy, readableStrategy }: ParseStreamOptions, - ): ConcatenatedJSONParseStream; + ): ConcatenatedJsonParseStream; }; -const JSONStream: JSONStream = { - Parse: JSONParseStream, - Stringify: JSONStringifyStream, - Concatenated: ConcatenatedJSONParseStream, +const JsonStream: JsonStream = { + Parse: JsonParseStream, + Stringify: JsonStringifyStream, + Concatenated: ConcatenatedJsonParseStream, useParse({ writableStrategy, readableStrategy, - }: ParseStreamOptions = {}): JSONParseStream { - return new JSONParseStream({ writableStrategy, readableStrategy }); + }: ParseStreamOptions = {}): JsonParseStream { + return new JsonParseStream({ writableStrategy, readableStrategy }); }, useStringify({ writableStrategy, readableStrategy, prefix, suffix, - }: StringifyStreamOptions = {}): JSONStringifyStream { - return new JSONStringifyStream({ + }: StringifyStreamOptions = {}): JsonStringifyStream { + return new JsonStringifyStream({ writableStrategy, readableStrategy, prefix, @@ -54,23 +54,20 @@ const JSONStream: JSONStream = { useConcat({ writableStrategy, readableStrategy, - }: ParseStreamOptions = {}): ConcatenatedJSONParseStream { - return new ConcatenatedJSONParseStream({ + }: ParseStreamOptions = {}): ConcatenatedJsonParseStream { + return new ConcatenatedJsonParseStream({ writableStrategy, readableStrategy, }); }, }; +Object.defineProperty(JsonStream, Symbol.toStringTag, { value: "JsonStream" }); + declare global { - const JSONStream: JSONStream; + const JsonStream: JsonStream; + /** @deprecated use {@linkcode JsonStream} instead */ + const JSONStream: JsonStream; } -Object.assign(globalThis, { - JSONStream: Object.defineProperty(JSONStream, Symbol.toStringTag, { - value: "JSONStream", - writable: false, - enumerable: false, - configurable: false, - }), -}); +Object.assign(globalThis, { JsonStream, JSONStream: JsonStream });