Writing
I write short notes on tools and habits that help with day-to-day engineering.
2025
- Typed JSON imports with import attributesGive TypeScript the shape of a JSON settings file and use import attributes to load it in a Node ES module.
- Run TypeScript scripts with tsxRun a TypeScript script with tsx, pass command-line arguments through pnpm, and check types with tsc.
- Find and fix lone surrogates in stringsUse isWellFormed to diagnose URIError from a split surrogate pair and toWellFormed to repair text before URL encoding.
- Mock fetch with MSW 2 in VitestTest fetch with MSW 2 in Vitest, override a handler for a 404, and fail requests that match no handler.
- Style form errors after interactionUse :user-invalid to style a required field after the user leaves it with a changed value or attempts to submit the form.
- Break request chains with modulepreloadStart fetching a JavaScript module chain in parallel with modulepreload links and check the result in the Network panel.
- RegExp v flag for subtraction and intersectionWrite character classes with the v flag to subtract a Unicode set or keep the characters that two sets share.
- Reshape JSON with jq 1.7 pipelinesUse jq’s pick(), select() and map() to filter an API response and keep specific nested fields in one output array.
- Align card rows with CSS subgridShare title, description and action tracks across grid cards so a wrapped heading leaves the content below it aligned.
- Try Biome alongside PrettierCompare Biome and Prettier output on one JavaScript file, then match quote and semicolon settings before switching a repo.
- Load .env files with --env-fileLoad local configuration with Node’s --env-file flag and see how multiple files and shell variables set the final value.
- Shard Playwright in CI, merge one reportRun Playwright in four CI jobs, keep each blob report, and turn them into one HTML report even when tests fail.
- Avoid specificity traps in native CSS nestingKeep native CSS nesting predictable by separating an ID from a grouped parent selector that needs a class-level override.
- Fake timers in node:testMove the clock by hand in node:test and prove a debounce waits until the full delay after the last call.
- Sort and edit arrays without mutationUse toSorted(), toSpliced() and with() to make a shallow copy while preserving the source array and its order.
- Getters and setters with unrelated typesAccept text on assignment, validate it in the setter, and give readers a number with an independently typed getter.
- Gzip uploads from the browserUse CompressionStream to gzip a JSON upload in the browser and tell the receiving server how to decode the request body.
- Generate hover colors with color-mix()Use color-mix() to derive a hover background and border from a single brand color, with a plain-color fallback.
- Try upcoming React features with CanaryPin matching React and React DOM Canary builds, then check the export before trying ViewTransition in an app.
- Parse CLI flags with util.parseArgsUse util.parseArgs to read long flags, short flag clusters and filenames, then validate numeric values at the command line.