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 🙏

© 2026 – Pkg Stats / Ryan Hefner

racoon-js

v1.6.0

Published

The easiest to use and powerful data validate and formatter library for JS.

Readme

中文

racoon-js

The easiest to use and powerful data validate and formatter library for JS.

npm version build status code coverage install size npm downloads

Table Of Contents

Features

  • 🌈 Support both browser and node.
  • ❄️ The data format can be flexibly defined, and any level of attribute nesting of object and array is supported.
  • 🔗 Support chain call without paying attention to call sequence.
  • ✨ Error message can be easily customed.

Browser Support

Chrome | Firefox | Safari | Opera | Edge | IE | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |

Installing

Using npm:

$ npm install racoon-js

Using yarn:

yarn add racoon-js

Using cdn:

<script src="https://cdn.jsdelivr.net/npm/racoon-js@latest/dist/racoon.min.js"></script>

The JS from cdn is 21kB, and it will be only 4.6kB after be compressed by gzip.

Example

import racoon from 'racoon-js';

// Define data format schema
const schema = racoon.object({
  name: racoon
    .string()
    .min(3)
    .error('name is too short') // You can add your custom error message
    .max(30)
    .error('name is too long')
    .required(), // Name can not be `undefined` or `null`
  age: racoon
    .number()
    .int()
    .default(1) // If value is `null` or `undefined`, then return default value `1`
  married: racoon.boolean(),
  favorite: racoon.object({ // You can define deep nested object format schema
    sports: racoon.array(
      racoon.string().min(1).max(100).required()
    ),
    book: racoon.object({
      title: racoon.string().required(),
      date: racoon
        .string()
        .pattern(/^\d{4}-\d{1,2}-\d{1,2}$/)
        .format((date) => { // Format the return value
          return `${date} 12:00:00`;
        })
    })
  })
});

try {
  const result = schema.validate({
    name: 'Jack',
    age: 22,
    favorite: {
      sports: ['football', 'basketball'],
      book: {
        title: 12,
        date: '2010-1-1'
      }
    }
  });
} catch (error) {
  console.error(error);
  // Error: "favorite.book.title": value should be a type of string
  // ↑↑↑ The error message can be customed
}

// If you don't like `try-catch` code style,
// you can use `validateSilent` method. When
// validate failed, the `error` will not be
// empty. Otherwise,the `error` is `undefined`.
//
// For Example:
const { error, value } = schema.validateSilent({ ... });