Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-utilities

@5f83e6c
Run it yourself

Small built-ins added since Node.js 24 that replace common npm packages. Use for debounce/throttle, temp files and directories with automatic cleanup, URL pattern matching or routing, an in-process mutex (Web Locks), Web Workers, partial deep-equality checks, UTF-8 byte length or fs.glob depth limits, or when about to install lodash.debounce, p-throttle, tmp or urlpattern-polyfill. Covers util.debounce/throttle, isPartialDeepStrictEqual, markPromiseAsHandled, Buffer.stringLength, fs.mkdtempDisposable, fs.mkstemp, openAsBlobSync, Utf8Stream, URLPattern, navigator.locks, the global Worker, addUncaughtExceptionCaptureCallback and tty raw modes. Node.js 24+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-utilities

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulesbuffer-and-streams.md

≈922 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Buffer and stream additions

Buffer.stringLength(input[, encoding]) (v26.11.0; not on v24)

Returns the .length (in UTF-16 code units) of the string that buf.toString(encoding) would produce, without decoding. It is the inverse of Buffer.byteLength. Input can be a Buffer, TypedArray or ArrayBuffer.

Verified:

  • Buffer.from('€ 100'): 7 bytes, stringLength 5, and 'hex' gives 14.
  • '😀' gives 2 (a surrogate pair).
  • [0xff, 0xfe, 0x41] in utf8 gives 3, because each maximal invalid subsequence becomes one U+FFFD.

Use it as a guard: if (Buffer.stringLength(buf) > constants.MAX_STRING_LENGTH) then stream instead of calling toString(). A detached ArrayBuffer counts as empty.

buffer.isLatin1(string) (v26.11.0; not on v24)

Validates a string: it returns true when every code unit is ≤ U+00FF, so the string round-trips through Node 'latin1' and is a valid WebIDL ByteString. Example use: validating HTTP header values. Verified: 'café' → true, '\u0080' → true, '€' → false, '' → true. Passing a Buffer throws ERR_INVALID_ARG_TYPE. Node's latin1 is not WHATWG windows-1252. This is the string counterpart of buffer.isAscii and buffer.isUtf8, which take bytes.

Aligned allocation (v26.8.0)

Buffer.allocUnsafe(size, alignment) and Buffer.allocUnsafeSlow(size, alignment) return memory whose start address is a multiple of alignment, which must be a power of two ≤ 2³⁰. This is for O_DIRECT-style I/O: Buffer.allocUnsafeSlow(4096, 4096).

  • A non-power-of-two throws ERR_INVALID_ARG_VALUE (verified).
  • v24.19.0 ignores the argument silently. allocUnsafe(16, 3) does not throw, and the buffer is not aligned. Feature-detect with try { Buffer.allocUnsafe(1, 3); /* unsupported */ } catch { /* supported */ }.
  • The address cannot be checked from JS. The alignment guarantee comes from the docs.

Buffer.poolSize defaults to 65536 since v26.3.0 and v24.18.0 (verified on v24.19.0). It was 8192 before.

blob.textStream() (v26.5.0, v24.19.0)

Returns a ReadableStream<string> of UTF-8-decoded chunks. It is the same as blob.stream().pipeThrough(new TextDecoderStream()). Verified: the chunks are strings and multi-byte characters survive.

ReadableStreamTee(stream[, cloneForBranch2]) (v26.5.0, v24.19.0; Stability 1)

import { ReadableStreamTee } from 'node:stream/web'. With true, branch 2 receives structured clones of the chunks. Verified: the two branches get different Uint8Array objects with equal contents. readable.tee() gives both branches the same object, so a consumer that mutates a chunk corrupts the other branch. This matches Fetch's response.clone() semantics.

streamConsumers.bytes(stream) (v25.6.0, v24.14.0)

import { bytes } from 'node:stream/consumers'. Resolves to a Uint8Array (not a Buffer, verified) holding the full contents of a Node Readable, a web ReadableStream or an async iterable. Use buffer() when you need a Buffer.

stream.compose(...streams) is Stable (v26.2.0, v24.19.0)

Combines streams, async generator functions, web streams and iterables into a single Duplex. It writes to the first stage and reads from the last. Verified: compose(new Transform(...), async function* (src) {...}) piped from Readable.from(['a', 'b']) yields '[A][B]'. Use it to build reusable pipeline segments instead of pumpify/duplexify.

Changed default to remember

readable.read() with no size returns one buffered chunk per call since v26.0.0. Before that it drained the whole buffer. Verified: after push('a') and push('b'), read() returns 'a' on main and 'ab' on v24.19.0.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides comprehensive documentation and verified code examples for new Node.js v24+ features. No security risks were identified.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-utilities