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

deref

v0.7.6

Published

JSON-Schema $ref resolution

Downloads

55,735

Readme

Do you have $ref's ?

Build Status NPM version Coverage Status

A simple way for solving $ref values:

var deref = require('deref');

Schema dereferencing

$ = deref();

var a = {
  id: 'a',
  type: 'object',
  properties: {
    b: {
      $ref: 'b'
    }
  }
};

var b = {
  id: 'b',
  type: 'string'
};

var c = {
  id: 'c',
  type: 'array',
  items: {
    $ref: 'a'
  }
};

console.log($(c, [b, a]).id);
// output: http://json-schema.org/c#

console.log($(c, [b, a], true).items.properties.b.type);
// output: string

Schema normalization

var schema = {
  id: 'http://x.y.z/rootschema.json#',
  schema1: {
    id: '#foo'
  },
  schema2: {
    id: 'otherschema.json',
    nested: {
      id: '#bar'
    },
    alsonested: {
      id: 't/inner.json#a'
    }
  },
  schema3: {
    id: 'some://where.else/completely#'
  }
};

console.log(deref.util.normalizeSchema(schema).schema2.nested.id);
// output: http://x.y.z/otherschema.json#bar

Schema identity

Since 0.3.0 the schema id will always be normalized internally to # when it's not provided.

This way the passed schema can be self-referenced using $ref's which is the expected behavior.

I know the id keyword is not required but while #/ is a self-reference we can assume # as the schema-id.

deref use that id for store and find $ref's, even self-references.

Without it is complex determine what to resolve. :beers:

Basic usage

The resulting function of calling deref() can accept three arguments:

  • fakeroot (string)

    Used on missing $schema values for resolve into fully qualified URIs.

    console.log($('http://example.com', { id: '#foo' }).id);
    // output: http://example.com#foo

    If missing will use http://json-schema.org/schema.

  • schema (object)

    The JSON-Schema object for dereferencing.

  • refs (array)

    Any additional schemas used while dereferencing.

    Since 0.2.4 passing an object is not longer supported.

  • ex (boolean)

    Whether do full dereferencing or not, false by default.

    Since 0.6.0 all inner references are not dereferenced by default.

    All other references are always dereferenced regardless the value of ex.

Examples

$('http://example.com', schema, true);
$(schema, refs, true);
$(schema, true);

Utilities

Aside the basics of $, this function will include:

  • $.refs (object)

    An registry of dereferenced schemas.

  • $.util (object)

    Exposes the internal helpers used by deref.

    • isURL(path)
    • parseURI(href)
    • resolveURL(base, href)
    • getDocumentURI(path)
    • findByRef(uri, refs)
    • resolveSchema(schema, refs)
    • normalizeSchema(fakeroot, schema)

Any refs passed MUST be an object of normalized schemas.

Note that calling $(schema) will not read/download any local/remote files.

Bitdeli Badge