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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@schematizer/json-schema

v0.1.0

Published

schema for listen or alter structures

Readme

json schema

This library allows make js schemas to read and overwrite data structures

Usage

JsonSchema is the main class of this library, you can registriy listeners or alters with the following methods

  • listenValue: Listen values by path
  • listenField: Listen the field that constains the specified path
  • alterValue: Alter the specified value
  • alterField: Alter the specified field found in the path

now, you will call triggerListeners and triggerAlterators with the target value

const schema = new JsonSchema();

schema.triggerListeners({ foo: 1, bar: 1 });
const alteredValue = schema.triggerAlterators([1, 2, 3]);

Examples

The following examples will use this structure

const myStructure = {
  a: 'alpaca',
  b: 'buffalo',
  c: 'camel',
  s: 'snake',
  object: {
    foo: 1,
    bar: 2,
  },
  array: [1, 2, 3],
  products: [
    { name: 'cup', price: 4 },
    { name: 'glass jar', price: 10 },
    { name: 'spoon', price: 1 },
  ],
};

test: listen values

const schema = new JsonSchema()
  .listenValue(['a'], ({ value }) => {
    expect(value).toBe('alpaca');
  })
  .listenValue(['object', 'foo'], ({ value }) => {
    expect(value).toBe(1);
  })
  .listenValue(['array'], ({ value }) => {
    expect([1, 2, 3]).toContain(value); // each array element
  })
  .listenValue(['products', 'name'], ({ value }) => {
    expect(['cup', 'glass jar', 'spoon']).toContain(value); // name of each array element
  });

schema.triggerListeners(myStructure);

test: listen fields

const schema = new JsonSchema()
  .listenField(['array'], ({ value }) => {
    expect(value).toEqual([1, 2, 3]); // array
  })
  .listenField(['products'], ({ value }) => {
    // array
    expect(value).toEqual([
      { name: 'cup', price: 4 },
      { name: 'glass jar', price: 10 },
      { name: 'spoon', price: 1 },
    ]);
  });

schema.triggerListeners(myStructure);

test: alter fields

const schema = new JsonSchema()
  .alterField(['array'], ({ value }) => {
    return value.filter((el: number) => el > 1);
  })
  .alterField(['products'], ({ value }) => {
    return (value as any[]).map(el => ({
      name: el.name,
      price: `$${el.price}.00`,
    }));
  });

expect(schema.triggerAlterators(myStructure)).toEqual({
  a: 'alpaca',
  b: 'buffalo',
  c: 'camel',
  s: 'snake',
  object: {
    foo: 1,
    bar: 2,
  },
  array: [2, 3],
  products: [
    { name: 'cup', price: '$4.00' },
    { name: 'glass jar', price: '$10.00' },
    { name: 'spoon', price: '$1.00' },
  ],
});

Arguments

the handler of the listenValue, listenField, alterValue, alterField methods receive the followind structure

  • path: string[] path of the selection
  • value: any selection value
  • parent: any parent of the selection
  • context: <Context> second argument sended to triggerListeners or triggerAlterators

Nested schemas

a JsonSchema can be appended into other with the method append

const movementSchema = new JsonSchema();
const summarySchema = new JsonSchema();

const rootSchema = new JsonSchema();
rootSchema.append(['movements'], movementSchema);
rootSchema.append(['summary'], summarySchema);