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

jsoschema

v2.1.8

Published

A javascript object validation engine and schema language

Downloads

4

Readme

= jsoSchema Marco Baringer [email protected] v2, Winter 2014

jsoSchema is an engine, and a kind of schema language, for validating javascript objects (often, but not always, json data sent between a browser and a web server).

Note that jsoSchema is not a JSON text parser/validator. It operates on in-memory objects only, and its schema is not just data (objects with a static, and serializable, stata ala JSON Schema and XSD) actual code (functions). While a jsoSchema can be used to generate a json schema (or any other kind of schema), since it's "just" javascript objects and methods, it can not be parsed and minpulated by something other than jsoSchema.

== Synopsis ==


// load the module var s = require('jsoSchema');

// create a schema which matches either a positive integer or a string var schema = s.Or(s.GreaterThan(0), s.String());

// assuming foo holds our value, test it agains the schema var test = schema.test(foo)

// the returned object has, among other things, a boolean property // called match. this property is, surprisingly enough, true if the // object matched the schema and false otherwise. if (test.match) { console.log('foo is a positive integer or a string'); } else { console.log('foo is not a positive integer nor a string'); console.log('failed because:', test.backtrace()); }

== Reference ==

See link:doc/API.asciidoc[API].

== Installation ==

=== with npm ===


npm install jsoschema

=== without npm ===

How many ways are there to install, compile and deploy js code? too many; and I have no desire to try and keep up with them all. Considering that, the code itself is exactly one file of javascript:

link:src/jsoSchema.js?raw=true[jsoSchema.js]

It should work in nodejs/npm (that's the environment the code is developed and tested in) directly and, i would assume but haven't tested, in the browser as well.

If it doesn't, or if you're just curious: At the bottom of that file is a single function, bound to the exporter variable in the jsoSchema code itself, which takes as input the jsoSchema object and does whatever is needed to export the object. Please feel free to edit that bit of code to suite your needs.

== Compared to JSON schema ==

http://tools.ietf.org/html/draft-zyp-json-schema-04

While jsoSchema and JSON Schema server very similar purposes, they go about it in two very different ways. A JSON Schema is a bit of data which is passed to a validator, along with the actual data to validate, and the validator understands the semantics of JSON Schema and dos what the schema says it should do given the data it has.

a jsoSchema is a block of code describing how to test if something is valid or not.

This code vs data approach has two important consequences:

  1. A JSON Schema can be represented, and transmitted and stored, as JSON data; a jsoSchema can not.

  2. A jsoSchema can perfrom any computation that's needed; a JSON Schema is limited to the constraints defined in the JSON Schema specification.