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

@extendscript/aes.util.jaw

v1.0.0

Published

Jaw is a data controller that wraps JSON objects with JSON-schema. It provides an easy to use, chaining API for managing JSON instances in ExtendScript.

Downloads

13

Readme

jaw

version

Object Manager

Jaw is a data controller that wraps JSON objects with JSON-schema. It provides an easy to use, chaining API for managing JSON instances in ExtendScript.

Install

npm install @extendscript/aes.util.jaw

Include

#include 'node_modules/@extendscript/aes.util.jaw/jaw.js'

Use

Init Jaw with a schema generate an instance that creates all the required properties:

var schema = {
    "title": "Test",
    "type" : "object",
    "properties": {
        "a"        : {"type": "string"},
        "b"        : {"type": "object"}
    },
    "required" : ["a"]
}

var Jaw = Sky.getUtil("jaw").init( schema )

console.log( Jaw.get() )

Output: { a : "" }

You can also generate all properties by passing a boolean like so:

var Jaw = Sky.getUtil("jaw").init( schema, true )

console.log( Jaw.get() )

Output: { a : "", b : {} }

Or you can wrap Jaw arround existing objects. Keep in mind that these will be validated against the given schema. Jaw will try and generate any requirements that are missing or needed:

// schema from above

var obj = { x : 0 }
Jaw = new jaw( schema, obj )

console.log( Jaw.get() )
console.log( Jaw.get() === obj)

Output: { a : "", x : 0 }, true

Set and Get

We can set property values using simple dot notation. The set() function can generate deep structures on the fly. The get() command is used to retrieve values.

// Schema from above
Jaw.set( "b.c.0.d", 10 )  

console.log( Jaw.get('b.c.0') ) 

Output: { d : 10 }

Not specifying a path always returns the complete object:

console.log( Jaw.get() )  

Output: { a : "", b : { c : [{ d : 10 }] } }

Validate

There are two ways of validating depending on the type of return you're after. validate() returns an array of errors and isValid() returns a boolean:

var result = Jaw.wrap( obj ).isValid()

console.log( result )

Output: true (No errors, object is succesfully validated against schema.)

var result = Jaw.wrap( obj ).validate()

console.log( result )

Output: [] (No errors, object is succesfully validated against schema.)

Errors

All errors are saved into an error stack you can access with the errors() function:

console.log( Jaw.getErrors() )

Output: [] (No errors)

Advanced Use

Besides the getters and setters Jaw implements some familiar tools for easy manipulation of existing properties.

Any type

  • .delete ( path )
  • .clone ( path )

Array types

  • .push ( path )
  • .pop ( path )
  • .unshift ( path )
  • .shift ( path )
  • .splice ( path, index, clear, element, element, etc... )

Chaining

You can chain commands together:

var result = Jaw
    .set( "b.c.0.d", 10 )
    .get( "b.c.0" );

console.log( result )

Output: { d : 10 }

Validating a Schema

You can also validate Schemas:

var schemaIsValid = new jaw( schema ).isValid();

console.log( schemaIsValid )

Output: true

Generate Templates

Get the default instance of the schema by calling getTemplate:

Jaw.getTemplate()

Output: { a : "" }

var allProperties = true;
Jaw.getTemplate( allProperties )

Output: { a : "", b : {} }

Test

We can test the code against a range of targets:

npm run test myTarget

We keep a log of test results

More info

Read the docs