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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@carlwr/fastcheck-utils

v0.3.1

Published

improved generators for fast-check

Readme

fastcheck-utils

improved generators for fast-check

Links:

Installation

npm install @carlwr/fastcheck-utils

fast-check is a peer dependency of this package. It should be picked up by the package manager also if you depend on e.g. @fast-check/vitest or @fast-check/jest rather than on fast-check directly.

to run checks and tests:

npm qa

Generators

element

function element<T>(xs: readonly [T, T]): Arbitrary<T>

Randomly choose one of the constant array values.

Shrinking is done towards the first element.

Similar to fc.constantFrom, but shrinks across all elements - fc.constantFrom only shrinks towards the first element.

example:

import * as fcu from 'fastcheck-utils'
import * as fc from 'fast-check'

const arb = fcu.element(['a', 'b', 'c'] as const)
const samples = fc.sample(arb, {seed:1, numRuns:3})
console.log(samples)  // ['b', 'c', 'b']

getNext

function getNext<T>(stream: InfiniteStream<T>): T

Get next value from an InfiniteStream object yielded by infiniteStream.

Throws if the stream is unexpectedly done (it is my understanding that this should never happen).

infiniteStream

function infiniteStream<T>(arb: Arbitrary<T>): Arbitrary<InfiniteStream<T>>

Generate an infinite stream of values.

This arbitrary is a minimal wrapper around fc.infiniteStream allowing access to the generated values in a type-safe way through the getNext helper.

features and non-features:

  • does not shrink at all unfortunately - since fc.infiniteStream doesn't
  • does print a meaningful counterexample and execution summary on failure, that includes some of the previously tried values in the stream

example:

import * as fcu from 'fastcheck-utils'
import * as fc from 'fast-check'

const arb = fcu.infiniteStream(fc.nat({max:10}))
const stream = fc.sample(arb, {seed:1})[0] ?? fail()
console.log(fcu.getNext(stream))  // 8
console.log(fcu.getNext(stream))  // 2

nonEmptyArray

function nonEmptyArray<T>(arb: Arbitrary<T>, constraints?: ArrayConstraints): Arbitrary<[T, ...T[]]>

Generate a non-empty array.

If a constraints parameter object is passed, it will be honored (function throws if {minLength: 0} is specified).

example:

import * as fcu from 'fastcheck-utils'
import * as fc from 'fast-check'

const arb = fcu.nonEmptyArray(fc.nat({max:5}))
const sample = fc.sample(arb, {seed:1})[0]
console.log(sample)  // [5, 4, 2, 2, 5, 0, 3, 1, 5, 3, 1]

nonEmptyUniqueArray

function nonEmptyUniqueArray<T, U>(arb: Arbitrary<T>, constraints?: UniqueArrayConstraints<T, U>): Arbitrary<[T, ...T[]]>

Generate a non-empty array of unique values.

example:

import * as fcu from 'fastcheck-utils'
import * as fc from 'fast-check'

const arb = fcu.nonEmptyUniqueArray(fc.nat({max:10}))
const sample = fc.sample(arb, {seed:1})[0]
console.log(sample)  // [2, 6, 5, 9, 4, 7, 10, 3, 1, 0, 8]

record

function record<T>(model: Model<T>): Arbitrary<ExactRecord<T>>

function record<T>(model: Model<T>, constr: AllKeysRequired<T>): Arbitrary<ExactRecord<T>>

function record<T, K>(model: Model<T>, constr: SomeKeysRequired<T, K>): Arbitrary<{ [K in string | number | symbol]: (Partial<T> & Pick<T, K & keyof T>)[K] }>

like fc.record, but with

  • noNullPrototype true by default
  • stronger typing

example:

import * as fcu from 'fastcheck-utils'
import * as fc from 'fast-check'

const arb = fcu.record({name: fc.string(), age: fc.nat({max: 100})})
const sample = fc.sample(arb, {seed:1})[0] ?? fail()
console.log(sample)  // {name: 'TVb~o"nP', age: 36}