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

@cloudflare/json-schema-walker

v0.1.1

Published

"Utilities for walking JSON Schemas and performing actions on them."

Downloads

214,820

Readme

JSON Schema Walker

A system that visits all schema objects in a JSON Schema document and makes callbacks before and/or after visiting all of the current schema object's subschemas.

Currently, there are several vocabularies to choose from, which must be used with the two walking functions. As the vocabulary concept is finalized in JSON Schema draft-08, this package will be reworked to support it directly.

The walkers

Both walkers accept one or two callback functions, but differ slightly in their behavior. In both cases, there are "path" or "parentPath" concepts which are arrays of the JSON property names or array indexes followed to reach the current schema.

Note that walker callbacks are expected to modify the schema structure in place, so clone a copy if you need the original as well.

schemaWalk(schema, preFunc, postFunc, vocabulary)

This simply calls the preFunc callback (if there is one), calls subschemaWalk wth an empty parent path of [], and then calls the postFunc callback.

subschemaWalk(scheam, preFunc, postFunc, parentPath, vocabulary)

Sometimes it is useful to start somewhere within a document, which subschemaWalk accomplishes by taking a parent path. This is also how the recursive calls are made once you start a walk- the parent path for each subsequent call is calculated during the walk.

In particular, handling the root schema differently is common, so calling subschemaWalk direclty on the root with an empty parent path [] allows skipping the root schema.

The callbacks

Either the preFunc or postFunc call can be null, or both can be passed for the same walk. They are expected to take the following as positional parameters:

  1. The schema object (or boolean) being processed
  2. The path to the schema from its parent
  3. The parent schema object, if any
  4. The path from the schema document root to the parent

Paths are arrays of property names (strings) and array indices (integers) that are analogous to JSON Pointers. Given ["foo", 42] as the path from the root to the parent object, and ["bar"] as the path from the parent object to the schema being processed, the equivalent JSON Pointer fragment for the parent would be "#/foo/42, while for the schema being processed it would be #/foo/42/bar.

The equivalent Relative JSON Pointer from the parent to the schema being processed would be 0/bar.

An empty path is represented as an empty array []. For a pointer from the root, this is equivalent to # as a JSON Pointer fragment.

For an empty path from the parent to the schema being processed (meaning that both are the same, which happens for the root schema), this is equivalent to 0 as a Relative JSON Pointer.

Vocabularies

getVocabulary(schema, defaultVocabulary) This returns the walker vocabulary object based on the schema's $schema keyword, or returns the default that you pass in if $schema is not present or not recognized. The current default if none is provided is Draft-07 JSON Hyper-Schema.

Once draft-08 is published with a formalized concept of a schema vocabulary, the vocabulary implementation for this package will likely be substantially reworked.