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
import "https://deno.land/x/this@0.160.0/mod.ts";
Warning: this exposes everything globally. Not recommended. Instead, import only the section/subsection that fits your needs.
Table of Contents
encoding
this/encoding
exposes all the std/encoding
modules from the
Deno Standard Library, along with a few extra goodies too.
import "https://deno.land/x/this@0.160.0/encoding.ts";
CSV
import "https://deno.land/x/this@0.160.0/encoding/csv.ts";
.parse
CSV.parse(text: string, options?: CSV.ParseOptions): string[][];
CSV.parse(text: string, { columns?: CSV.Column[]; }): Record<string, unknown>;
.stringify
CSV.stringify(data: CSV.DataItem[], options?: CSV.StringifyOptions): string;
Source: std@0.160.0/encoding/csv.ts
JSONC
import "https://deno.land/x/this@0.160.0/encoding/jsonc.ts";
.parse
JSONC.parse(data: string, { allowTrailingComma?: boolean }): JsonValue;
.stringify
JSONC.stringify(data: JsonValue, replacer?: (key: string, value: any) => any, space?: string | number): string;
// overload #1:
JSONC.stringify(data: JsonValue, replacer?: (string | number)[], space?: string | number): string;
Source: std@0.160.0/encoding/jsonc.ts
JSON5
import "https://deno.land/x/this@0.160.0/encoding/json5.ts";
.parse
JSON5.parse<T = JSONValue>(text: string, reviver?: JSONReviverFn): T;
.stringify
JSON5.stringify(data: JSONValue, replacer?: JSONReplacerFn, space?: string | number): string;
.require
JSON5.require<T = JSONValue>(path: string | URL, reviver?: JSONReviverFn): T;
.requireAsync
JSON5.require<T = JSONValue>(path: string | URL, reviver?: JSONReviverFn): Promise<T>;
JSONStream
import "https://deno.land/x/this@0.160.0/encoding/jsonstream.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;
}
Note: see std/encoding/json/stream.ts for more info on JSONStream classes.
TOML
import "https://deno.land/x/this@0.160.0/encoding/toml.ts";
.parse
TOML.parse(text: string): Record<string, unknown>;
.stringify
TOML.stringify(data: Record<string, unknown>, options: TOML.FormatOptions): string;
Source: std@0.160.0/encoding/toml.ts
YAML
import "https://deno.land/x/this@0.160.0/encoding/yaml.ts";
.parse
YAML.parse() // TODO
.parseAll
YAML.parseAll() // TODO
.stringify
YAML.stringify() // TODO
Source: std@0.160.0/encoding/yaml.ts
FrontMatter
import "https://deno.land/x/this@0.160.0/encoding/front_matter.ts";
.extract
FrontMatter.extract<T = unknown>(str: string): Extract<T>;
type Extract<T> = {
frontMatter: string;
body: string;
attrs: T;
}
.test
FrontMatter.test(markdown: string): boolean;
base64
import "https://deno.land/x/this@0.160.0/encoding/base64.ts";
.encode
base64.encode(data: ArrayBuffer | string): string;
.decode
base64.decode(b64: string): string;
.decodeBytes
base64.decodeBytes(b64: string): Uint8Array;
Source:
std@0.160.0/encoding/base64.ts
base64url
import "https://deno.land/x/this@0.160.0/encoding/base64url.ts";
.encode
base64.encode(data: BufferSource | string): string;
.decode
base64.decode(b64url: string): string;
.decodeBytes
base64.decodeBytes(b64url: string): Uint8Array;
binary
import "https://deno.land/x/this@0.160.0/encoding/binary.ts";
binary.*
TODO
: see std@0.160.0/encoding/binary.ts for available methods
Hex
import "https://deno.land/x/this@0.160.0/encoding/hex.ts";
.encode
Hex.encode(); // TODO
.decode
Hex.decode(); // TODO
Source: std@0.160.0/encoding/hex.ts
testing
import "https://deno.land/x/this@0.160.0/testing.ts";
asserts
import "https://deno.land/x/this@0.160.0/testing/asserts.ts";
Source: std/testing/asserts.ts
bdd
import "https://deno.land/x/this@0.160.0/testing/bdd.ts";
beforeAll
let fixture: Set<number>;
let startTime: number, endTime: number;
beforeAll(() => {
fixture = new Set([]);
startTime = Date.now();
});
afterAll
afterAll(() => {
fixture.clear();
fixture = undefined;
console.log
});
beforeEach
beforeEach(() => {
fixture.clear();
for (let i = 1; i <= 10; i++) fixture.add(i);
});
afterEach
afterEach(() => {
fixture = new Set([1, 2, 3, 4]);
});
describe
it
Source: std/testing/bdd.ts
mock
import "https://deno.land/x/this@0.160.0/testing/mock.ts";
Source: std/testing/mock.ts
snapshot
import "https://deno.land/x/this@0.160.0/testing/snapshot.ts";
Source: 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.
chai
import "https://deno.land/x/this@0.160.0/testing/chai.ts";
Source:
chai@4.3.4
fc
(fastcheck)
import "https://deno.land/x/this@0.160.0/testing/fc.ts";
Source:
fast-check@3.2.0
examples
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.
import "https://deno.land/x/this@0.160.0/encoding.ts";
// deno.jsonc => { "compilerOptions": { "lib": ["deno.ns", "deno.window"] }, ... }
const deno_jsonc = JSONC.parse(await Deno.readTextFile("./deno.jsonc"));
// { compilerOptions: { lib: ["deno.ns", "deno.window"] }, ... }
const deno_json5 = JSON5.stringify(deno_jsonc);
// {compilerOptions:{lib:['deno.ns','deno.window']}, ... }
const deno_toml = TOML.stringify(deno_jsonc);
// [compilerOptions.lib] = ["deno.ns", "deno.window"]
const deno_yml = YAML.stringify(deno_jsonc);
// compilerOptions:
// lib: [deno.ns, deno.window]
FrontMatter.extract
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";
const { attrs, body, frontMatter } = FrontMatter.extract<{ title: string }>(
"---\ntitle: Three dashes marks the spot\n---\n");
assertEquals(attrs.title, "Three dashes marks the spot");
assertEquals(body, "");
assertEquals(frontMatter, "title: Three dashes marks the spot");
describe
+ it
import "https://deno.land/x/this@0.160.0/testing/bdd.ts";
let users: Map<string, unknown>;
// globally available hooks!
// (beforeAll, afterAll, beforeEach, afterEach)
beforeEach(() => {
users = new Map<string, unknown>();
});
// behavior-driven development (bdd) testing API
describe("Users Map", () => {
it("should initially empty", () => {
assertEquals(users.size, 0);
});
it("should be readable and writable", () => {
users.set("key", "value");
assertEquals(users.size, 1);
assertArrayIncludes([...users.values()], ["value"]);
});
});
assertEquals
+ AssertionError
import "https://deno.land/x/this@0.160.0/testing/asserts.ts";
Deno.test("Global Assertions", async ({ step }) => {
await step("are they equal?", () =>
assertEquals(+new Date("1970-01-01T00:00:00.000Z"), 0);
await step("AssertionError also available", () => {
if (1 !== 1) {
throw new AssertionError("OH NO! 1 != 1?!?! BAD JUJU")
}
});
});
chai
(chai.js)
import "https://deno.land/x/this@0.160.0/testing/chai.ts";
fc
(fastcheck)
import "https://deno.land/x/this@0.160.0/testing/fc.ts";
Contributing
⚠️ 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.
Creating an issue also ensures you're given credit for fixing that bug. 😁
Fork + clone the repository
This section assumes you have the GitHub CLI (you really should).
gh repo fork deno911/this --clone
Create a new branch for your changes
git checkout -b fix/typo-in-readme
Make small changes and concise commits
# hack hack hack...
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
gh pr create --title "fix: typos in README.md"
Or just open your repo on GitHub.com and follow the prompts.
Warning: make sure you select the upstream repo for your PR!
The foundation of this module was inspired by ije/global.