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

props-check

v0.3.2

Published

Check your props and give a helpful error if you've mis-typed.

Downloads

12

Readme

Build Status codecov Coverage Status Code Climate

props-check

Check your props and give a helpful error if you've mis-typed.

Installation

npm install props-check

Requiring the module

const PropsCheck = require('props-check')

PropsCheck

PropsCheck checks props against the spec and returns a map with list of possible corrections.

// Example spec
const spec = {
  read: 'Function'
, sanitize: '[Function]'
, validate: '[Function]'
, normalize: '[Function]'
};


// Example object
const test = {
  raed: () => null
, santize: [ () => null ]
, alvidate: [ () => null ]
, normalize: [ () => null ]
, format: [ () => null ]
};


const result = PropsCheck(spec, test);

result:

  { raed: [ 'read' ]
  , santize: [ 'sanitize' ]
  , alvidate: [ 'validate' ]
  , normalize: []
  , format: []
  }

PropsCheck returns null if spec and test have the exact same props.

PropsCheck.custom

PropsCheck.custom takes a custom comparator and returns a function that is similar to PropsCheck.

const comparator = (a, b) => a < b;

const result = PropsCheck.custom(comparator)(spec, test);

PropsCheck.human

PropsCheck.human accepts the same arguments as PropsCheck but returns a more helpful error message.

const result = PropsCheck.human(spec, test);

result:

    You gave me this:

      {
        raed: …,
        santize: …,
        alvidate: …,
        normalize: …
      }

    I wasn't expecting:

      { raed: …, santize: …, alvidate: … }

    You didn't give me:

      { read: …, sanitize: …, validate: … }

    Here's how to fix it:

      raed <-> read
      santize <-> sanitize
      alvidate <-> validate

    I have no idea what this mean:

      { format: …, }

PropsCheck.customHuman

PropsCheck.customHuman takes a custom message map and returns a function that is similar to PropsCheck.human.

const customMessages = {
  given: [ "This is what I got:", … ]
, unexpected: [ "Something is not right..", … ]
, missing: [ "I'm looking for this:", … ]
, conclusion: [ "I suggest the following changes:", … ]
, clueless: [ "I have no idea what these are:", … ]
};

const result = PropsCheck.customHuman(customMessages)(spec, test);

Custom messages will be used randomly if more than 1 message is provided in the list. If a property of the customMessages is misspelled or if a list is empty, default messages will be used instead.

Misc things

  • If you use PropsCheck.custom and provide your own comparator, make sure that the comparator accepts 2 arguments and returns either 0 on equal, 1 on similar, or -1 on mismatch.
  • All functions are curried. Meaning that the following:
PropsCheck(spec)(test);
PropsCheck.custom(comparator)(spec)(test);
PropsCheck.human(spec)(test);
PropsCheck.customHuman(customMessages)(spec)(test);

are the same as:

PropsCheck(spec, test);
PropsCheck.custom(comparator)(spec, test);
PropsCheck.human(spec, test);
PropsCheck.customHuman(customMessages)(spec, test);