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

schematic-js

v1.0.2

Published

A library that provides JSON schema model validation and hardening.

Downloads

5

Readme

#schematic-js An ES5 JSON-schema-based model support library.

Overview

Schematic-js adds JSON schema support to model-based javascript applications. JSON Schema (http://json-schema.org) provides declarative structure and validation to data models making their behavior in an application more predictable.

Usage

Schematic uses AMD for module support and that is its only strict dependency. The tests, which are also good examples of how to use schematic, use the requirejs loader (https://github.com/jrburke/requirejs.git), and the single-file minified versions (schematic-x.x.x-min.js) use requirejs' (https://github.com/jrburke/r.js.git) optimizer, but any AMD compliant loader should work. Below is sample code from the BackboneSchemaExample demonstrating the use of a validated model.

// Use AMD to define and load the resources we depend on.
require([
    "schematic/ModelFactory",
    "schema/ExampleSchema"
], function (
        ModelFactory,
        ExampleSchema
) {
    // Create a model factory.
    var mfact = new ModelFactory({
            // "resolver" is used by the factory to find schemas based on names.
            // Resolve schema by mapping it to the dependency where it was already loaded.
            resolver: function (name) {
                if (name === "schema/ExampleSchema") {
                    return ExampleSchema;
                }
            }
        }),
        // Create a model based on the example schema.
        model = mfact.getModel("schema/ExampleSchema"),
        msg = document.getElementsByName("message")[0],
        btn = document.getElementsByName("Increment")[0];

    model.num = 1;
    // update the model.
    // Should fail after 10, because the schema defines a maximum of 10 for the num property.
    btn.onclick = function (evt) {
        model.num = model.num + 1;
        msg.innerHTML = "Model.num equals " + model.num;
    }

 });

Integration

Validation

The current version of Schematic-js relies on third party validators to supply JSONSchema validation. The examples use a reference implementation from json-schema (https://github.com/kriszyp/json-schema.git), but other validators can easily be injected via AMD's module mapping.

Backbone

The library provides backbone (https://github.com/documentcloud/backbone.git) integration by creating a Backbone.SchematicModel that extends Backbone.Model. SchematicModel implements validation and adds property definitions defined on the schema to the model.

##License This software is licensed under the Apache 2.0 license (http://www.apache.org/licenses/LICENSE-2.0).