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

@amritk/generate-examples

v0.5.0

Published

Generate fast-check arbitraries and example values from JSON Schemas.

Readme

@amritk/generate-examples

Programmatic API for generating fast-check arbitraries and example values from JSON Schemas.

status  license  JSON Schema  node


Overview

@amritk/generate-examples turns a JSON Schema into test data. Where the other mjst generators give you code that consumes data at runtime (parsers, validators, types), this one closes the loop by giving you data to exercise that code with.

Each generated file exports:

  • A TypeScript type definition for the schema
  • A fast-check arbitrary (FooArbitrary) that produces schema-valid values — ideal for property-based testing
  • A concrete, self-contained example value (fooExample) — ideal for fixtures, seeds, and documentation

An index.ts barrel re-exports everything.

[!NOTE] The generated arbitraries import fast-check, so consumers need it installed (npm i -D fast-check). An arbitrary whose schema uses a keyword no fc.* combinator captures on its own (if/then/else, not, exclusive oneOf, and the presence-gated object keywords) also imports @amritk/runtime-validators for a post-generation validating filter; files that need no such filter don't. The static fooExample values have no runtime dependencies.


Installation

npm install @amritk/generate-examples
# or
pnpm add @amritk/generate-examples
# or
yarn add @amritk/generate-examples
# or
bun add @amritk/generate-examples

Usage

import { buildExampleSchema } from '@amritk/generate-examples'

const schema = {
  type: 'object',
  properties: {
    id: { type: 'string', format: 'uuid' },
    age: { type: 'integer', minimum: 0 },
  },
  required: ['id'],
} as const

const files = await buildExampleSchema(schema, 'User')
// → [{ filename: 'user.ts', content: '...' }, { filename: 'index.ts', content: '...' }]

The generated user.ts looks like:

import * as fc from 'fast-check'

export type User = { id: string; age?: number }

export const UserArbitrary: fc.Arbitrary<User> = fc.record(
  { "id": fc.uuid(), "age": fc.integer({ min: 0 }) },
  { requiredKeys: ["id"] },
)

export const userExample: User = { "id": "00000000-0000-0000-0000-000000000000", "age": 0 }

Use the arbitrary in a property test:

import { test, fc } from '@fast-check/vitest'
import { UserArbitrary } from './generated'
import { parseUser } from './parsers'

test.prop([UserArbitrary])('parseUser round-trips any valid User', (user) => {
  expect(parseUser(user)).toEqual(user)
})

…or grab the static example as a fixture:

import { userExample } from './generated'

const res = await fetch('/users', { method: 'POST', body: JSON.stringify(userExample) })

Lower-level API

| Export | Description | |:---|:---| | buildExampleSchema(schema, rootName, suffix?) | Walks the $ref graph and returns a GeneratedFile[] (one file per schema + an index.ts). | | generateArbitrary(schema, typeName, suffix?) | Returns the export const …Arbitrary source for a single schema node. | | generateExampleConst(schema, typeName, rootSchema?) | Returns the export const …Example source for a single schema node. | | deriveExample(schema, rootSchema?) | Returns a concrete, schema-valid JavaScript value (no code-generation). | | serializeValue(value) | Serializes a derived value to a TypeScript source expression (handles Date/bigint). |


Supported keywords

type — including multi-type unions like ['string', 'null'] — (string/number/integer/boolean/null/array/object), properties, required, items, minItems/maxItems, uniqueItems, minLength/maxLength, pattern, format (email, uuid, uri/url, date, date-time, time, hostname, ipv4, ipv6), minimum/maximum, exclusiveMinimum/exclusiveMaximum, multipleOf, enum (filtered by sibling constraints), const, minProperties/maxProperties, patternProperties, propertyNames, dependentRequired, dependentSchemas, contains, oneOf/anyOf, if/then/else, not, $ref, and the x-mjst extension (Date, bigint). if/then/else, not, and oneOf exclusivity are enforced by validating generated candidates against the schema and retrying/rejecting. Unsupported constructs degrade to fc.anything() in arbitraries and null in static examples.

[!TIP] A static example constrained only by pattern is not guaranteed to match the pattern — reach for the arbitrary when pattern fidelity matters.


License

MIT