npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zgeoff/std

v0.4.3

Published

Small, dependency-free TypeScript helpers shared across the zgeoff repos

Readme

@zgeoff/std

Small, dependency-free TypeScript helpers that more than one zgeoff repo needs. Each helper is one file with its test beside it, exported from the package root unless it needs Bun, and named by the shared function-naming rules.

Install

bun add @zgeoff/std

Helpers

toExactOptional

Returns a copy of an object without the keys whose value is undefined, typed so the copy fits a type with optional properties under exactOptionalPropertyTypes. It replaces the conditional spread, ...(x === undefined ? {} : { x }), that such code otherwise writes per key.

import { toExactOptional } from '@zgeoff/std';

const label: string | undefined = readLabel();

// { label: string | undefined; retries: number } does not fit the type, but
// toExactOptional's { label?: string; retries: number } does.
const options: { label?: string; retries: number } = toExactOptional({ label, retries: 3 });

Own enumerable keys are copied, symbols included, as an object spread would. null values stay, falsy values such as 0 and '' stay, and the input object is left untouched. A union input maps member by member, so each member keeps its own keys.

isRecord

Tells whether a value is a plain keyed object, and narrows it to Record<string, unknown>, so code that reads parsed JSON can index it. An array or null is not a record.

import { isRecord } from '@zgeoff/std';

const parsed: unknown = JSON.parse(text);
const name = isRecord(parsed) ? parsed['name'] : undefined;

isOneOf

Tells whether a value is one of a list of values, and narrows it to the list's element type, so a string read from outside the program becomes a literal union without a cast. It compares with Array.prototype.includes, so NaN matches NaN.

import { isOneOf } from '@zgeoff/std';

const sizes = ['small', 'large'] as const;

const size = isOneOf(input, sizes) ? input : 'small';

readOptionalText

Reads a file's text, or returns undefined when the file or a folder on its path does not exist. It reads to the end of the file, so a procfs or cgroupfs file that reports a size of 0 still reads in full. Any other failure, such as a path that names a folder, throws.

import { readOptionalText } from '@zgeoff/std';

const lefthook = await readOptionalText('lefthook.yml');

writeStdout

Writes a text to stdout as it is, with no newline added. Pass it as the writeOutput of a command's options at its entry point, so a test hands in its own writer.

import { writeStdout } from '@zgeoff/std';

process.exitCode = runCheck({ cwd: process.cwd(), writeOutput: writeStdout });

withFileLock

Runs a callback under an exclusive lock on a file that other processes share. It needs Bun, so import it from @zgeoff/std/with-file-lock; its doc covers the rest.

Typed helpers

Each typed helper holds the one type assertion that its job needs, because TypeScript cannot prove the type it returns. toExactOptional holds one for the same reason. The assertion carries an approved disable comment, so code that calls the helper needs no assertion of its own.

The typed helpers are machineTypes, pick, mergeDeep, toTagged and toReadonlyDeep. The std typed helpers doc describes each one, with an example.