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

flow-dynamic

v0.0.14

Published

A helper library link runtime type check to static flow check.

Downloads

6

Readme

Flow-Dynamic

Dynamic type check library which will generate corresponding static Flow Type.

For quick start

goto flow-dynamic/wiki.

Why need dynamic check?

  1. Data go though typed and untyped packages.(this case should be resolved by flow typed all packages)
  2. Data are in a complex code stream between packages,too complex for flow type between those packages. (Like graphql's resolver,which be used in graphql-relay,and the params are narrowed to a custom type).
  3. Data from remote,out of your control.(In this case,flow-dynamic could be used at both client and server,with single type valid logic).

Recommend Validate Style

if the params need to check is short.I prefer write them inline. like:

const wrappedFn = check1(
(v) => ({
  mail:pro.isString.isEmail(v.mail) // check src.mail.
}), (v) => { // Now, the input data is validated and have a Flow type {mail:string}
  // .... doing something
});

if things gets longer,should write a separated caster:

const userValid = (src) => ({
  id:pro.isString(src.id),
  name:pro.isString(src.name),
  age:pro.isNumber(src.age),
  friend:pro.isArray.isNumArr.inLength(src.friend, {max:5}),
});

In your real project,there also should be an explicitly Flow type wrote by you.

type USER = {
  id:string,
  name:string,
  age:number,
  friend:number[]
};
const userValid = (src) => ({
  id:pro.isString(src.id),
  name:pro.isString(src.name),
  age:pro.isNumber(src.age),
  friend:pro.isArray.isNumArr.inLength(src.friend, {max:5}),
});

const resolver = check1(userValid, (src:USER) => {
  // .... doing something
});

Note: explicitly declare (src:USER) to your hand-writing Flow type is helpful, will avoid wrong typo in writing userValid. If the userValid you writing is not corresponding with USER , flow will notice you.

Functions

  1. validate functions are group by the corresponding Flow type.Like pro.isArray.isNumArr.inLength.
  2. There are three top namespace for validator. dev pro cvt.
  3. pro(product) contain all validator which do not modify the input be checked.
  4. dev(develop) is just a copy from pro. but when NODE_ENV != 'dev',all function in dev will do nothing,and just return the passed in value back. (So dev is used for those type check you think should not be checked in production environment).
  5. cvt(convert). This namespace contain all validators which will mutate the been checked value. (Like setdefault for passin value,or clip them. or more complex usage. Like Graphql's connection cursor can be narrowed to offset when you using an array-like data model).
  6. checker: The common checker is in normal.js. And i hand-writed some custom checker for graphql(in graphql-ck.js have more clearly Error notice,its in namespacegraph ).
  7. Code demonstration could be find in __tests__ folds in src, and my pr to graphql-relay.