Writing
I write short notes on tools and habits that help with day-to-day engineering.
2026
- Connect with Node’s built-in WebSocket clientOpen a WebSocket from Node, send a text message after the connection opens, and close the client after the reply.
- Truncate visible characters with Intl.SegmenterUse Intl.Segmenter to shorten JavaScript strings at grapheme boundaries so accents and joined emoji stay intact.
- Migrate to ESLint 9 flat configConvert a browser project’s .eslintrc.json to ESLint 9 flat config, then check the effective globals, rule settings, and ignored files.
- Write shell scripts in JavaScript with zxMove a shell check to JavaScript with zx, keep paths with spaces intact, and handle grep’s no-match status without swallowing errors.
- Colour terminal output with util.styleTextUse Node’s util.styleText for CLI status colours and pass the destination stream so redirected diagnostics stay plain.
- Trace slow clicks with long animation framesUse Chrome’s Long Animation Frames API to locate the script behind a slow click and separate script time from rendering work.
- Combine fetch cancellation with AbortSignal.anyGive fetch a Cancel button and a timeout with AbortSignal.any, then distinguish a user cancellation from an expired deadline.
- Keep defaults from widening types with NoInferUse TypeScript’s NoInfer to check a default against the choices in a list without letting the default widen the inferred union.
- Parse .env files in code with loadEnvFileprocess.loadEnvFile() loads a .env file into process.env with no dotenv dependency, and util.parseEnv() returns the values as an object instead.
2025
- Narrowing survives closures after last assignmentTypeScript 5.4 preserves some narrowings inside callbacks after the last assignment. Check when you can remove the non-null assertion.
- Group array items with Object.groupByGroup orders by status with Object.groupBy, read its null-prototype result, or use Map.groupBy to group by object identity.
- Use Promise.withResolvers to wrap callbacksUse Promise.withResolvers to await the result of a callback-driven operation and handle success or cancellation with the same promise.
- Make fixup commits squash automaticallySet rebase.autoSquash so interactive rebase moves fixup commits beside their targets, then inspect the order before saving.
- Fetch every remote with fetch.allMake plain git fetch update your fork and upstream, then check the remote tracking branches before you integrate changes.
- Render components with declarative shadow DOMShip a shadow root in the initial HTML so a web component can render its styled content before its JavaScript loads.
- Set up Husky 9 in two linesInstall Husky 9, initialize a pre-commit test hook, and check that Git runs it in the next checkout.
- Prerender next pages with speculation rulesUse a moderate speculation rule on a likely next link, then check whether Chrome activated the prerendered page.
- Collect async iterables with Array.fromAsyncCollect an async generator into an array, map pages as they arrive, and keep a loop when you need partial results.
- Replace nvm with misePin Node in mise.toml, let interactive zsh switch versions by directory, and run the same version from a script or CI.
- Style parents with :has()Use a CSS :has() selector with :user-invalid to highlight a field group after a failed validation attempt.