-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: all testing + encoding submodules
- Loading branch information
Showing
17 changed files
with
484 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
import { base64 as $base64 } from "../deps.ts"; | ||
|
||
const utf8decoder = new TextDecoder(); | ||
const utf8 = new TextDecoder(); | ||
|
||
const base64: base64 = { | ||
encode: (data) => $base64.encode(data), | ||
decode: (b64) => utf8decoder.decode($base64.decode(b64)), | ||
decodeBytes: (b64) => $base64.decode(b64), | ||
declare type base64 = { | ||
/** | ||
* Encodes a string or ArrayBuffer into a base64 string. | ||
* @param data | ||
* @returns RFC4648 base64-encoded string | ||
*/ | ||
encode(data: ArrayBuffer | string): string; | ||
/** | ||
* Decodes a given RFC4648 base64-encoded string into its original value. | ||
* @param b64 | ||
* @returns original decoded value as a Uint8Array | ||
*/ | ||
decodeBytes(b64: string): Uint8Array; | ||
/** | ||
* Decodes a given RFC4648 base64-encoded string into its original value. | ||
* @param b64 | ||
* @returns original decoded value as a string | ||
*/ | ||
decode(b64: string): string; | ||
}; | ||
|
||
Object.assign(globalThis, { base64 }); | ||
|
||
declare global { | ||
interface base64 { | ||
encode(data: ArrayBuffer | string): string; | ||
/** | ||
* Decodes a given RFC4648 base64 encoded string, returning a Uint8Array. | ||
* @param b64 | ||
*/ | ||
decodeBytes(b64: string): Uint8Array; | ||
/** | ||
* Decodes a given RFC4648 base64 encoded string, returning a string. | ||
* @param b64 | ||
*/ | ||
decode(b64: string): string; | ||
} | ||
namespace globalThis { | ||
const base64: base64; | ||
} | ||
const base64: base64; | ||
} | ||
|
||
const base64 = Object.defineProperties<base64>({ | ||
encode: (data) => $base64.encode(data), | ||
decode: (b64) => utf8.decode($base64.decode(b64)), | ||
decodeBytes: (b64) => $base64.decode(b64), | ||
}, { | ||
encode: { enumerable: true }, | ||
decode: { enumerable: true }, | ||
decodeBytes: { enumerable: true }, | ||
[Symbol.toStringTag]: { value: "base64" }, | ||
}) as base64; | ||
|
||
Object.assign(globalThis, { base64 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { binary as $binary } from "../deps.ts"; | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
Object.assign(globalThis, { binary: $binary }); | ||
import { binary } from "../deps.ts"; | ||
import type { Merge } from "../_internal.ts"; | ||
|
||
type binary = Merge<typeof binary>; | ||
|
||
declare global { | ||
const binary: typeof $binary; | ||
const binary: binary; | ||
} | ||
|
||
Object.assign(globalThis, { | ||
binary: Object.defineProperty({ ...binary }, Symbol.toStringTag, { | ||
value: "binary", | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { CSV as $CSV } from "../deps.ts"; | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
Object.assign(globalThis, { CSV: $CSV }); | ||
import { CSV } from "../deps.ts"; | ||
import type { Merge } from "../_internal.ts"; | ||
|
||
type CSV = Merge<typeof CSV>; | ||
|
||
declare global { | ||
const CSV: typeof $CSV; | ||
const CSV: CSV; | ||
} | ||
|
||
Object.assign(globalThis, { | ||
CSV: Object.defineProperty<CSV>({ ...CSV }, Symbol.toStringTag, { | ||
value: "CSV", | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { front_matter as $front_matter } from "../deps.ts"; | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
Object.assign(globalThis, { front_matter: $front_matter }); | ||
import { FrontMatter } from "../deps.ts"; | ||
import type { Merge } from "../_internal.ts"; | ||
|
||
type FrontMatter = Merge<typeof FrontMatter>; | ||
|
||
declare global { | ||
const front_matter: typeof $front_matter; | ||
const FrontMatter: FrontMatter; | ||
} | ||
|
||
Object.assign(globalThis, { | ||
FrontMatter: Object.defineProperty({ ...FrontMatter }, Symbol.toStringTag, { | ||
value: "FrontMatter", | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import { hex as $hex } from "../deps.ts"; | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
import { hex as Hex } from "../deps.ts"; | ||
import type { Merge } from "../_internal.ts"; | ||
|
||
type Hex = Merge<typeof Hex>; | ||
|
||
declare global { | ||
namespace globalThis { | ||
const hex: typeof $hex; | ||
} | ||
const Hex: Hex; | ||
} | ||
|
||
Object.assign(globalThis, { hex: $hex }); | ||
Object.assign(globalThis, { | ||
Hex: Object.defineProperty({ ...Hex }, Symbol.toStringTag, { | ||
value: "Hex", | ||
writable: false, | ||
enumerable: false, | ||
configurable: false, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,97 @@ | ||
import { JSON5 as $JSON5 } from "../deps.ts"; | ||
/// <reference no-default-lib="true" /> | ||
/// <reference lib="deno.ns" /> | ||
/// <reference lib="deno.window" /> | ||
|
||
import type { | ||
JSONReplacerFn, | ||
JSONReviverFn, | ||
JSONValue, | ||
Merge, | ||
} from "../_internal.ts"; | ||
import { JSON5 as JSON5_MOD } from "../deps.ts"; | ||
|
||
/** | ||
* Converts a JSON5 string into an object. | ||
* @template T Type of return value. | ||
* @param text A valid JSON string. | ||
* @param reviver A function that transforms the results. This function is | ||
* called for each member of the object. If a member contains nested objects, | ||
* the nested objects are transformed before the parent object is. | ||
*/ | ||
function parse<T extends any = JSONValue>( | ||
text: string, | ||
reviver?: JSONReviverFn, | ||
): T { | ||
return JSON5_MOD.parse(text, reviver); | ||
} | ||
|
||
/** | ||
* Converts a JavaScript value to a JSON5 string. | ||
* @param value A JavaScript value, usually an object or array, to be converted. | ||
* @param replacer A function that transforms the results. | ||
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | ||
*/ | ||
function stringify( | ||
value: JSONValue, | ||
replacer?: JSONReplacerFn, | ||
space?: string | number, | ||
): string { | ||
return JSON5_MOD.stringify( | ||
value, | ||
replacer, | ||
space ?? 0, | ||
); | ||
} | ||
|
||
/** | ||
* Loads JSON5 from file synchronously | ||
* @param path File path or url | ||
*/ | ||
function require<T extends any = JSONValue>( | ||
path: string | URL, | ||
reviver?: JSONReviverFn, | ||
): T { | ||
const raw = Deno.readTextFileSync(path); | ||
return parse<T>(raw, reviver); | ||
} | ||
|
||
/** | ||
* Loads JSON5 from file asynchronously | ||
* @param path File path or url | ||
*/ | ||
async function requireAsync<T extends any = JSONValue>( | ||
path: string | URL, | ||
reviver?: JSONReviverFn, | ||
): Promise<T> { | ||
const raw = await Deno.readTextFile(path); | ||
return parse<T>(raw, reviver); | ||
} | ||
|
||
// defaults | ||
const JSON5 = { parse, stringify, require, requireAsync }; | ||
|
||
const descriptor = { | ||
enumerable: true, | ||
writable: false, | ||
configurable: false, | ||
}; | ||
|
||
Object.defineProperties(JSON5, { | ||
parse: descriptor, | ||
stringify: descriptor, | ||
require: descriptor, | ||
requireAsync: descriptor, | ||
[Symbol.toStringTag]: { | ||
value: "JSON5", | ||
}, | ||
}); | ||
|
||
type JSON5 = Merge<typeof JSON5>; | ||
|
||
declare global { | ||
namespace globalThis { | ||
const JSON5: typeof $JSON5; | ||
} | ||
const JSON5: JSON5; | ||
} | ||
|
||
Object.assign(globalThis, { JSON5: $JSON5 }); | ||
Object.freeze(JSON5); | ||
|
||
Object.assign(globalThis, { JSON5 }); |
Oops, something went wrong.