Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
🧱
rusting away

Nicholas Berlette nberlette

🧱
rusting away
View GitHub Profile
@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 August 2, 2024 14:19
`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];
@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,
@nberlette
nberlette / char.ts
Last active January 25, 2024 06:56
`Color`: TypeScript Color Conversion and Manipulation Tools
export enum Char {
Null = 0,
/**
* The `\b` character.
*/
Backspace = 8,
/**
* The `\t` character.
*/
Tab = 9,
@nberlette
nberlette / README.md
Last active April 7, 2024 09:13
`DenoHTML`: enhances Deno's builtin HTML documentation generator (v1.38.0+)

Deno HTML Documentation Enhancer

This is a simple tool to enhance the HTML documentation generated by the Deno CLI's builtin command, deno doc --html (Deno v1.38.0+). It improves the CSS styling, adding support for dark mode and persisted color scheme preferences, along with some other usability improvements.

Usage

@nberlette
nberlette / style.css
Last active November 25, 2023 21:39
deno doc stylesheet with custom props instead of hardcoded values
:root {
--bg-body: rgb(231 229 228);
--bg-content: white;
--bg-highlight: white;
--bg-searchbar: rgb(231 229 228);
--bg-search-results-hover: rgb(243 244 246);
--bg-code: rgb(243 244 246);
--bg-overload-label: rgb(243 244 246);
@nberlette
nberlette / dom.ts
Last active November 27, 2023 00:28
`DUM`: like a DOM implementation for Deno... but dumber.
/// <reference no-default-lib="true" />
// deno-lint-ignore-file no-unused-vars no-explicit-any
import {
inspect,
type InspectOptions,
type InspectOptionsStylized,
// highlight,
indexOf,
pop,
@nberlette
nberlette / list-all.ts
Last active April 13, 2025 03:56
Deno KV: list / search / sort huge batches of entries in database
export interface ListAllOptions<T> extends Deno.KvListOptions {
comparer?(a: Deno.KvEntry<T>, b: Deno.KvEntry<T>): number;
}
export interface ListEntry<T> extends Deno.KvEntry<T> {
readonly cursor: string;
}
export async function listAll<T>(
kv: Deno.Kv,
@nberlette
nberlette / .gitignore
Last active March 5, 2025 23:25
`PLimit`: TypeScript re-imagining of p-limit and yocto-queue. Friendly with Deno, Bun, and Node.
dist
node_module
*.env*
*.log
.*.log
*.lock*
*-lock.*
.DS_Store
Thumbs.db
.SpotlightV100