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 🙏

© 2024 – Pkg Stats / Ryan Hefner

kuvio

v1.4.0

Published

Create string patterns and derive things from them, such as regexes

Downloads

1,768

Readme

kuvio

build Codacy
Badge codecov dependencies size downloads version

kuvio is a tool to construct composable string patterns, from which you can derive things like regular expressions or fast-check Arbitrarys. As of v1.4.0, it requires no dependencies.

kuvio is specifically for string-like patterns. If you want to extend this concept to more complicated data types, check out schemata-ts! kuvio was originally developed as part of schemata-ts but was extracted as it seems useful independently.

Usage

kuvio comes with several useful patterns built-in, but you can also create your own.

import * as k from 'kuvio';

// Use built-in patterns
const creditCardRegex = k.regexFromPattern(k.patterns.creditCard);

// Create your own patterns.
const areaCode = k.exactly(3)(k.digit)
const exchangeCode = k.exactly(3)(k.digit)
const lineNumber = k.exactly(4)(k.digit)

// Create pattern functions
const parenthesize = (p: k.Pattern) => k.subgroup(
  k.sequence(k.char('('), p, k.char(')'))
)

// Compose patterns to make more complex patterns
const phoneNumberPattern = k.sequence(
  parenthesize(areaCode),
  k.char(' '),
  k.subgroup(exchangeCode),
  k.char('-'),
  k.subgroup(lineNumber),
)

See the patterns directory for the built-in patterns, which can also be useful examples for creating your own.

Note regarding fast-check usage

Arbitraries are intended primarily for use in test code; in order to help keep fast-check out of your production code, kuvio does not include fast-check in the main export. If you want to use the Arbitrary functions, you'll need to import them separately from kuvio/arbitrary.

kuvio also exports a version of the Arbitrary functions that take the fast-check library as an argument, to prevent any possible accidental inclusion of fast-check in production code. This shouldn't be an issue, but there are many bundlers and we cannot test them all. You can import these from kuvio/arbitrary-deferred.