Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
😍
Stage 3 decorators, meet Deno 🦖

Nicholas Berlette nberlette

😍
Stage 3 decorators, meet Deno 🦖
View GitHub Profile
@nberlette
nberlette / temporal-proxy.ts
Created April 10, 2024 22:00
TemporalProxy
// deno-lint-ignore-file ban-types
import { is } from "jsr:@type/is@0.1.0";
/**
* Simple abstraction using the native `Proxy` and `Proxy.revocable` APIs to
* create temporary, "restorable" proxies of a given target object. This is
* particularly well-suited for testing and mocking purposes, allowing one to
* create a virtually indistinguishable proxy of an object or function that is
* to be tested, apply custom spying / mocking logic, and still be capable of
@nberlette
nberlette / extract-workers-ai-models.ts
Last active February 27, 2024 10:35
WorkersAI: utility to extract LLM model data from Cloudflare Workers AI docs
/*!
* Run this script with Deno to extract all models from the Workers AI
* documentation site (https://developers.cloudflare.com/workers-ai/models).
*
* @example
* ```sh
* # install Deno if you do not have it already
* curl -fsSL https://deno.land/install.sh | sh -
*
* # run the script
@nberlette
nberlette / LICENSE
Last active February 24, 2024 09:11
Outdent: highly configurable, modern re-implementation of the popular outdent module
The MIT License (MIT)
Copyright © 2023-2024 Nicholas Berlette (https://github.com/nberlette)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@nberlette
nberlette / dataurl.ts
Last active February 17, 2024 07:50
`DataURL`: a custom subclass of `URL` to handle data-uri strings
/**
* User-extensible type for encoding types that can be used with the `DataURL`
* class. This interface can be extended using TypeSript's declaration merging,
* to supplement the built-in encoding types. */
// deno-lint-ignore no-empty-interface
export interface EncodingTypeMap {
"uri": "uri";
"url": "uri";
"uri-component": "uri";
"percent": "uri";
@nberlette
nberlette / chainable.ts
Last active January 18, 2024 21:38
Chainable Stage 3 Decorators (experimental)
/*~----------------------------------------~*\
* CHAINABLE DECORATORS UTILITY CLASS *
* FOR TYPESCRIPT 5.0 *
*~----------------------------------------~*
* © 2023-2024 NICHOLAS BERLETTE • MIT *
\*~----------------------------------------~*/
// deno-lint-ignore-file no-explicit-any ban-types
import type {
@nberlette
nberlette / expect.ts
Last active February 9, 2024 23:53
Hard fork of the Deno stdlib 'expect' module + BDD testing tools (from https://deno.land/std/expect/mod.ts)
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright 2019 Allain Lalonde. All rights reserved. ISC License.
import {
type AnyConstructor,
type Matcher,
matchers,
type TypeNames,
} from "./matchers.ts";
import { AssertionError, type Async, type Fn, isPromiseLike } from "./utils.ts";
@nberlette
nberlette / example.ts
Last active January 17, 2024 06:56
Polyfill for the Iterator Helpers TC39 Proposal
import { Iterator } from "./iterator.ts";
/** Simple numeric iterator that returns the numbers passed to the constructor. Extremely useless. */
export class NumericIterator extends Iterator<number> {
#index = 0;
#numbers: number[] = [];
constructor(...numbers: number[]) {
super();
this.#numbers = numbers;
@nberlette
nberlette / hook.ts
Last active February 5, 2024 06:42
`Hook`: git hooks integration with Deno's task runner
const TASK_NAME_REGEXP = /^[a-z\^\$][a-z0-9\-_$:.\^]*$/i;
type TaskConfig = { [key: string]: string };
type HooksConfig<K extends MaybeHookNames = Hook.Name> = {
readonly [P in K]: string | string[];
};
type HookNames = typeof Hook.names[number];
type strings = string & { __strings__?: never };
@nberlette
nberlette / xml-formatter.ts
Last active March 24, 2024 13:53
XMLFormatter
export enum EOL {
CRLF = "\r\n",
CR = "\r",
LF = "\n",
}
export interface Options {
newLine?: EOL | `${EOL}`;
lineWidth?: number;
tabSize?: number;
@nberlette
nberlette / char.ts
Last active November 26, 2023 23:37
`Char`: TypeScript Enum of Unicode Character Code Points
export enum CharacterCodes {
Null = 0,
/**
* The `\b` character.
*/
Backspace = 8,
/**
* The `\t` character.
*/
Tab = 9,