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

chkr

v8.0.0

Published

js type check

Downloads

17

Readme

chkr

npm Build Status Coverage Status

js type check

Installation

npm install chkr

Example

const {Num, Optional, Arr, Str, Bool} = require('chkr');

//simple type check
Num(1) //==> 1
Num('1') //throws error
Num('a') //throws error

//type combination
Optional(Num)(undefined) //===> undefined
Arr(Num)([1,2,3]) //===> [1,2,3]

console.log(Obj({
  user: Str,
  age: Num,
  isAdmin: Bool,
  pages: Arr(Str)
}).sample())

API

Type

a type is a js function with sample as it's method. it's inspect symbol is customized to show the infomation of itself.

Type()

type function checks and parse the input value and returns then transformed value or throw an error if the input value is not the required type

.sample

sample method returns a sample data of a type

Concrete Type

  • Id any type
  • Null null or undefined
  • Any any thing but not Null
  • Num input a number or a string consist of only digits will output a exact number
  • Str any thing will transfer to string
  • Bool true or 'true' to true, false or 'false' to false, number, object... throws
  • Time Date or any thing can be transfered into Date by new Date

Type Combinator

  • Const a type with only one value (1)
  • Or accept some types returns a type which can be all the given types (+)
  • Obj accept an object indicate an object has some key with some type (*)
  • Optional make type optional (Null + Type)
  • Kv accept a type called value type to generate a key value paire object type
  • Arr Array of a type

Recursive Type Def

recursive type is supported using a fn withSelf. you can use this to define an List

const List = ValueType => withSelf(Self => Or(Const(Empty), Obj({head: ValueType, tail: Self})))
const NumList = List(Num)

Test

$ npm test
$ npm run test-cov