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

tsdoc-defaults

v1.0.2

Published

Generate typed runtime defaults from @default/@defaultValue TSDoc tags

Readme

Single source of truth for defaults - turn TSDoc @default tags into a typed runtime DEFAULTS constant.

// types.ts
export interface Options {
  /** @default `10_000` */
  timeoutMs?: number;
}

// client.ts
const timeoutMs = opts.timeoutMs
  ?? 5_000; // drifted
// types.ts
export interface Options {
  /** @default `10_000` */
  timeoutMs?: number;
}

// client.ts
import { DEFAULTS } from './types.defaults';

const timeoutMs = opts.timeoutMs
  ?? DEFAULTS.Options.timeoutMs;

types.defaults.ts is generated from the tags. Mistakes fail the build:

| Mistake | Caught by | | --- | --- | | @default `'10s'` on a number | tsc: Type 'string' is not assignable to type 'number'. | | Tag removed, code still reads it | tsc: Property 'timeoutMs' does not exist on type … | | Tag edited, file not regenerated | --check: src/types.defaults.ts is stale: run tsdoc-defaults |

Demo: a source, its generated file and the rendered docs

Install

npm install --save-dev tsdoc-defaults

ESM only, Node 22 or later. Uses its own typescript dependency; your project's version does not matter.

Usage

  1. Tag a member with @default (which tags count).

  2. Generate <name>.defaults.ts next to each source with tags, and commit it:

    tsdoc-defaults
  3. Read the default where it applies:

    const timeoutMs = opts.timeoutMs ?? DEFAULTS.Options.timeoutMs;

    Each default has its member's declared type: number, not 10_000. Keep DEFAULTS internal to your package: its shape follows your declaration names and changes with them.

  4. In CI, fail when a tag was edited but its file wasn't regenerated:

    tsdoc-defaults --check

CLI

tsdoc-defaults [files or globs...] [--check] [--project <tsconfig>]

| Argument | What it does | | --- | --- | | files or globs | The sources to read. Default: the TypeScript files the tsconfig includes. Quote globs. | | --check | Writes nothing; exits 1 and names each stale generated file. Formatting and comments don't count, so Prettier may run on generated files. | | -p, --project <tsconfig> | The tsconfig to use. Default: ./tsconfig.json; without one, pass files or globs. It sets the default sources and the extension of the generated file's import. | | -h, --help | Prints the usage line. |

  • Output: <name>.defaults.ts next to each source with tags (.defaults.mts/.defaults.cts for .mts/.cts). A generated file whose source was deleted or no longer has a code default is removed; a file there without the generated header is never overwritten or removed: it is an error if its source has tags.
  • Exit codes:
    • 0: done
    • 1: tag errors, printed as file:line:col with nothing written; or stale files with --check
    • 2: usage error, an unreadable tsconfig, or no files to read

API

import { extractDefaults, generate, check } from 'tsdoc-defaults';

extractDefaults reads one source's tags, generate renders the modules for a set of sources without writing them, and check compares them with disk. Their TSDoc has the details.

Tags

@default or @defaultValue, on a direct member of an exported, non-generic, top-level interface or object type alias.

A code span is content in backticks; bare text is anything else.

| Tag | Generated | Note | | --- | --- | --- | | @default 10_000 or @default `10_000` | 10_000 | backticks are optional | | @default `os.tmpdir()` | os.tmpdir() | the file's os import is copied | | // tsdoc-defaults: import os from 'node:os'@default `os.tmpdir()` | os.tmpdir() | if only the tag uses os, or the file imports it with import type, add this comment anywhere in the file | | @default `process.env.PORT` | process.env.PORT | | | @default process.env.PORT | nothing | skipped: bare text can't be told from prose, so it may read only the file's imports and undefined, NaN, Infinity, globalThis; use a code span | | @default the temp directory | nothing | skipped: prose | | @default undefined | nothing | skipped: no default | | @default `{ a:` | nothing | error: a code span must be one expression | | @default `{ a: 1 | nothing | error: a code span or fence must be closed; a word starting with @ ends the tag, even inside a fence |

TypeDoc

{ "plugin": ["tsdoc-defaults/typedoc"] }

Requires typedoc@^0.28 (optional peer dependency).

  • A default that is one expression renders in the signature: timeoutMs?: number = 10_000.
  • Prose stays a "Default" block.
  • So does bare text that reads an imported name (@default DEFAULT_TIMEOUT). Write it as a code span to get it in the signature.

Limits

  • Nothing stops code from bypassing DEFAULTS with its own literal.
  • Bare text that isn't an expression is prose, so @default ten seconds on a number is skipped without an error. Only a code span is checked.
  • The alternative, a const that the tag {@link}s, shows the constant's name in hovers and generated docs instead of its value.

Changelog

CHANGELOG.md lists the changes in each release.

License

MIT