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

json-inspector

v1.0.0-rc.2

Published

Json Inspector is json data validator & sanitizer. It allows you to define validation rules for complex data structures by simple and descriptive way of defining json-compliant inspector schema.

Downloads

2

Readme

JSON Inspector

Build Status Test Coverage

Json Inspector is json data validator & sanitizer. It allows you to define validation rules for complex data structures by simple and descriptive way of defining json-compliant inspector schema.

Installation

npm install json-inspector

or

bower install json-inspector

... or you can browserify your own bundle for a browser, see npm run-script build in the package.json

Features

  • Complex data structures validation & sanitization
  • Extremely simple schema definition
  • Multilanguage support for error messages
  • Filtering of data
  • Custom assertion & sanitizer implementations (extensible)
  • Conditional data validation (suitable for eg. complicated permission handling)
  • Express support
  • Referencing other schema definitions from within a schema
  • And more! (see Documentation for all available options)

Resources

Simple schema definition example

inspector.define('user', {
    username: {
        $nullable: true,
        $isAlphanumeric: 'en-US',
        $hasLengthOf: {max: 32}
    },
    email: {
        $required: true,
        $isEmail: {allow_display_name: true}
    },
    address: {
        street: {
            $is: String
        },
        zip: {
            $isInt: {min: 1}
        }
    },
    apps: {
        $forEach: {
            name: {
                $in: ['app1', 'app2']
            }
        }
    }
});

Cons

The JsonInspector can't validate object's properties which have matching names with one of the schema definition keywords (those data properties are removed by default). This intentional design decision limits universality of the library in exchange for improved schema readability and simplicity (less code). The issue is partialy solved by the keyword prefix feature which allows you to dynamically change a prefix string of keywords (which defaults to the $ character). In practice, you most probably won't ecnouter this limitation (if you were to, you would have known by now).
If this limitation is a deal breaker, consider trying out the ajv validation library.

Tests

npm run-script tests

NOTE: The most of the actual data validation is handed over to the chriso validation library.