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

@wmfs/json-schema-builder

v1.27.0

Published

Generate JSON-Schema schemas via a UI-orientated DSL.

Downloads

37

Readme

json-schema-builder

Tymly Package npm (scoped) CircleCI codecov CodeFactor Dependabot badge Commitizen friendly JavaScript Style Guide license

Generate JSON-Schema schemas via a UI-orientated DSL.

Why?

If you're building some high-level, user-facing tool to produce JSON Schema objects, chances are your internal representation will be more array-like... This package is intended to take that internal DSL and turn it into a valid JSON-Schema schema.

Installation

npm install @wmfs/json-schema-builder --save

Usage


const jsonSchemaBuilder = require('@wmfs/json-schema-builder')

const jsonSchema = jsonSchemaBuilder.dslToJsonSchema(
{
  title: 'Pizza',
  description: 'A model for storing details of a pizza (recipe, price etc.)',
  propertyHints: [
    {
      key: 'code',
      typeHint: 'text',
      example: 'CHEESE_TOMATO',
      required: true,
      title: 'Unique code of the pizza',
      minLength: 3,
      maxLength: 15,
      primary: true
    },
    {
      key: 'label',
      typeHint: 'text',
      required: true,
      example: 'Cheese & Tomato',
      title: 'Customer-facing label'
    },
    {
      key: 'popularitySeq',
      typeHint: 'integer',
      required: true,
      title: 'Integer value to order lists by',
      minimum: 1
    },
    {
      key: 'imageUri',
      typeHint: 'uri',
      required: true,
      example: 'https://tinyurl.com/y8r5bbu5',
      title: 'URI to an enticing photo of the pizza'
    },
    {
      key: 'crusts',
      typeHint: 'text',
      choiceSet: {
        NORMAL: 'Normal',
        STUFFED: 'Stuffed',
        HOT_DOG: 'Hot Dog'
      },
      multiple: true,
      default: ['NORMAL', 'STUFFED'],
      title: 'Offer which crust options?',
      required: true
    },
    {
      key: 'vegetarian',
      typeHint: 'boolean',
      required: true,
      default: false,
      title: 'Is the pizza suitable for vegetarians?'
    },
    {
      key: 'allergens',
      typeHint: 'text',
      example: ['Gluten', 'Wheat', 'Milk'],
      multiple: true,
      uniqueItems: true,
      title: 'List of allergens present in pizza'
    },
    {
      key: 'availabilityEnd',
      typeHint: 'date',
      example: '2019-12-31',
      required: false,
      title: 'Date when pizza is no longer available.'
    },
    {
      key: 'reviews',
      typeHint: 'object',
      multiple: true,
      title: 'Favourable customer reviews',
      propertyHints: [
        {
          key: 'username',
          example: 'joebloggs4',
          typeHint: 'text',
          required: true,
          title: 'Who wrote the review'
        },
        {
          key: 'review',
          example: 'Lovely stuff!',
          typeHint: 'text',
          required: true,
          title: 'Something nice to say'
        },
        {
          key: 'rating',
          title: 'Star rating (0=Awful 5=Great)',
          example: 5,
          typeHint: 'integer',
          required: true,
          minimum: 0,
          maximum: 5,
          default: 5
        }
      ]
    }
  ]
})

/*

// Which returns...
// ----------------
//

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "Pizza",
  "description": "A model for storing details of a pizza (recipe, price etc.)",
  "type": "object",
  "properties": {
    "code": {
      "type": "string",
      "title": "Unique code of the pizza",
      "examples": [
        "CHEESE_TOMATO"
      ],
      "minLength": 3,
      "maxLength": 15
    },
    "label": {
      "type": "string",
      "title": "Customer-facing label",
      "examples": [
        "Cheese & Tomato"
      ]
    },
    "popularitySeq": {
      "type": "integer",
      "title": "Integer value to order lists by",
      "minimum": 1
    },
    "imageUri": {
      "type": "string",
      "format": "uri",
      "title": "URI to an enticing photo of the pizza",
      "examples": [
        "https://tinyurl.com/y8r5bbu5"
      ]
    },
    "crusts": {
      "type": "array",
      "title": "Offer which crust options?",
      "default": [
        "NORMAL",
        "STUFFED"
      ],
      "items": {
        "type": "string",
        "enum": [
          "NORMAL",
          "STUFFED",
          "HOT_DOG"
        ]
      }
    },
    "vegetarian": {
      "type": "boolean",
      "title": "Is the pizza suitable for vegetarians?",
      "default": false
    },
    "allergens": {
      "type": "array",
      "title": "List of allergens present in pizza",
      "examples": [
        [
          "Gluten",
          "Wheat",
          "Milk"
        ]
      ],
      "uniqueItems": true,
      "items": {
        "type": "string"
      }
    },
    "availabilityEnd": {
      "type": "string",
      "format": "date-time",
      "title": "Date when pizza is no longer available.",
      "examples": [
        "2019-12-31"
      ]
    },
    "reviews": {
      "type": "array",
      "title": "Favourable customer reviews",
      "items": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "title": "Who wrote the review",
            "examples": [
              "joebloggs4"
            ]
          },
          "review": {
            "type": "string",
            "title": "Something nice to say",
            "examples": [
              "Lovely stuff!"
            ]
          },
          "rating": {
            "type": "integer",
            "title": "Star rating (0=Awful 5=Great)",
            "default": 5,
            "examples": [
              5
            ],
            "minimum": 0,
            "maximum": 5
          }
        },
        "required": [
          "username",
          "review",
          "rating"
        ]
      }
    }
  },
  "required": [
    "code",
    "label",
    "popularitySeq",
    "imageUri",
    "crusts",
    "vegetarian"
  ],
  "primaryKey": [
    "code"
  ]
}

*/

Testing

npm test

License

MIT