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 / 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
@nberlette
nberlette / outdent.ts
Last active February 2, 2024 09:48
`Outdent`: remove common indentation in TypeScript (on type-level and value-level)
// Copyright (c) 2024+ Nicholas Berlette (https://github.com/nberlette)
// Published under the MIT license. All rights reserved.
/**
* Removes common leading whitespace from each line in {@linkcode S}.
* This is the type-level counterpart to the {@linkcode outdent} function.
*
* @example
* ```ts
* type S = Outdent<`
@nberlette
nberlette / README.md
Last active October 31, 2023 05:20
[TS] DisposableStack + AsyncDisposableStack Implementation (explicit resource management)

Explicit Resource Management Polyfill

This is a bare-bones implementation of the interfaces AsyncDisposableStack and DisposableStack from the [Explicit Resource Management Proposal].

Usage

Note: see the examples below for more detailed usage examples.

DisposableStack and Disposable

@nberlette
nberlette / parser.mjs
Last active October 27, 2023 04:38
Peggy.js XML Grammar
// deno-lint-ignore-file
// Generated by Peggy 3.0.2.
// https://peggyjs.org/
export default (function () {
"use strict";
function add(obj, props) {
for (const [k, v] of Object.entries(props)) if (v) obj[k] = v;
return obj;
}
@nberlette
nberlette / README.md
Last active October 6, 2023 23:20
Using SVG <foreignObject /> to render an HTML document as an image

HTML documents inside SVG with <foreignObject />

HTMLImageElement

SVG foreignObject + HTML

HTMLObjectElement

<object type="image/svg+xml;charset=utf-8"