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

extended-proptypes

v1.3.0

Published

Useful proptypes for react components

Downloads

67,133

Readme

Build Status Coverage Status

Extended Prop Types

Useful proptypes for React components. Developed for and tested on ClassDojo's web app.

Usage

This module exports a set of proptype validators.

import ExtendedPropTypes from "extended-proptypes";

class MyComponent extends Component {

  static propTypes = {
    myDate: ExtendedPropTypes.date.isRequired,
    mySatanicString: ExtendedPropTypes.stringMatching(/^6+$/).isRequired,
  };
}

If you only need a few of the provided functions, individual validators can be imported under /lib/validators.

import keyedObject from "extended-proptypes/lib/validators/keyedObject";

class MyComponent extends Component {

  static propTypes = {
    mySpecialObject: keyedObject(/keyregex/).isRequired,
  };
}

It may be convenient to not have to reference both the original proptypes object and also this one. To resolve this, you can use one of two methods:

  • extended-proptypes/lib/extend-from-react imports {PropTypes} from react and adds all of its methods to this module's export.
  • extended-proptypes/lib/extend-from-standalone imports PropTypes from prop-types and adds all of its methods to this module's export.
import `extended-proptypes/lib/extend-from-react`;
import PropTypes from "extended-proptypes";

class MyComponent extends Component {

  static propTypes = {
    myEmailAddress: PropTypes.emailAddress.isRequired,
    myArrayOrObject: PropTypes.collectionOf(PropTypes.bool),
  };
}

When NODE_ENV === "production", since React will not validate PropTypes, this method exports stubbed versions of each validator.

New Prop Types

All validators expose basic and isRequired versions.

React:

  • elementWithType(Type): A react element matching the provided type, which may be a class or a function.

Collections

  • collection: An array or a plain object.
  • collectionOf(validator): An array or a plain object whose values match the provided validator.
  • keyedObject(regex): An object whose keys match the provided regex.
  • keyedObjectOf(regex, validator): An object whose keys match the provided regex and whose values match the provided validator.
  • iterable: An iterable. Errors if enviroment does not support symbols.

General Primatives

  • constant(val): The provided val, only.
  • primative: a number, a string, or a boolean.
  • stringMatching(regex): A string that matches the provided regex.
  • stringWithLength(min, max=Infinity): A string with length between min and max, inclusive. If only one argument is provided, requires exactly that length.
  • hex: A string consisting of hex characters, with an optional 0x at the beginning.
  • date: A date object.
  • dateBetween(min, max=Infinity): A date object which is within the provided interval.
  • time: A value parsable by new Date().
  • timeBetween(min, max=Infinity): A value parsable by new Date() which is within the provided interval.
  • uuid: A uuid string (e.g. 123e4567-e89b-12d3-a456-426655440000).
  • locale: A locale string, like en-US or jp.
  • emailAddress: An email address (regex taken from the highest-upvoted SO answer).

CSS

  • percent: A percentage.
  • cssLength: A single css length, like 24px, 43% or 4rem.
  • cssSize: Between 1 and 4 css lengths.
  • color: A hex or rgb(a) string

MongoDB-specific

  • mongoId: A 24-character hex string.
  • mongoIdKeyedObject: An object whose keys are mongo ids.
  • mongoIdKeyedObjectOf(validator): An object whose keys are mongo ids and whose values match the provided validator.