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

maybe-you-meant

v0.1.2

Published

Find deceptive prop-type typeo's in your react apps

Downloads

8

Readme

maybe-you-meant

CI

Find deceptive typo's in your react projects.

Are you familiar with the following?


class Foo extends Component {
  static propTypes = {
    foobar: PropTypes.string
  }

  static defaultProps = {
    foobar: 'whatever'
  }
}

// Somewhere in the app

// Oops! We misspelled, but we won't blow up because of a default prop type.
<Foo foobbar='not whatever' />

If so, maybe-you-meant can help. Maybe you meant patches React.createElement to patch every single components componentDidMount, componentDidUpdate (wraps for functional components) to issue console warnings whenever a prop type is similar (but not equal) to one of your defined propTypes.

The preceding, albeit contrived, example would issue the following:

console

In addition, maybe-you-meant will warn when Components are passed props not defined in propTypes, only when propTypes are defined. By default, maybe-you-meant whitelists react's internal properties (events, data-attributes, aria-attributes, html, and svg). The following...

  class Foo extends Component {
    static propTypes = {}
  }
  // The following will result in a warning for the `bar` prop.
  <Foo
    bar='Bang'
    data-foo='bar'
    aria-expanded='false'
    onClick={() => {}}
  />

...will result in:

console

Installation

  yarn add -D maybe-you-meant
  # Or
  npm i -D maybe-you-meant

Usage

  // Somewhere in the top of your app
  import maybeYouMeant from 'maybe-you-meant'
  maybeYouMeant()

  // or
  maybeYouMeant({
    maxDistance: 3,
    include: [/^Include/, 'PatchMe'],
    exclude: [/^Connect/, 'DoNotPatchMe']
  })

  // Don't want warnings about undeclared props?
  maybeYouMeant({
    warnOnUndeclaredProps: false
  })

  // Want to extend the set of whitelisted props (for warning on undeclared props)?
  import maybeYouMeant, { whitelisted } from 'maybe-you-meant'
  // maybe-you-meant exports whitelisted properies from all of the following
  // `all` is a combination of the rest.
  const { all, react, events, aria, data, html, svg } = whitelisted

  maybeYouMeant({
    whitelistedProps: [
      ...whitelisted.all,
      // Don't warn when these are passed and not declared in `propTypes`
      'myProp',
      /^myProps/
    ]
  })

API

maybeYouMeant([opts])

  • opts {Object}
  • opts.maxDistance {Number} The max distance between given prop and prop-type (from Levenshtein algorithm) for warnings
  • opts.include {String|RegExp|Array<String|RegExp>} String or RegExp matching for including Components (tested on displayName)
  • opts.exclude {String|RegExp|Array<String|RegExp>} String or RegExp matching for excluding Components (tested on displayName)
  • opts.warnOnUndeclaredProps {Boolean} Warn when a Component is passed props that are not declared in propTypes (default is ture)
    • Note: warnings will only be issued if the given Component has defined propTypes
  • opts.whitlistedProps {String|RegExp|Array<String|RegExp>} Props that should be ignored when issuing warnings for undeclared props. By default this is all of the React internal properties (see reactProps.js for more info)

Inspiration

The awesome why-did-you-update module.