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

data-document-creator

v1.0.1

Published

Creates JSON and XML documents

Downloads

3

Readme

Data Document Creator

This package can be used to generate JSON and XML documents.

A document is generated with the help of a document description.

document description

A document description is a JSON or YAML file containing configuration used to generate a document.

It should contain the following structure:

{
  "config": Config;
  "document": object;
}

It is also possible to define an array with document descriptions to generate multiple documents.

config

The config property contains configuration data used when generating the document. Like the filename of the document.

config.outputDirectory

Use this property to define the directory where the generated document will be saved. For example test-data/products.

config.outputFilename

Use this property to define the generated document filename (with extension). For example product-1.json.

config.outputFormat

Use this property to define the generated document data format. For example json or xml.

config.validationSchema

Use this property to define a JSON Schema used to validate the document description. For example schemas/product-document-description.json.

If no config.validationSchema is defined it will not validate the document.

document

The document property contains the document content.

Example

schema.json

{
  "title": "Product document description",
  "type": "object",
  "properties": {
    "document": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "price": {
          "type": "integer"
        }
      }
    }
  }
}

product.json

{
  "config": {
    "outputDirectory": "products",
    "outputFilename": "product-1.json",
    "outputFormat": "json",
    "validationSchema": "schema.json"
  },
  "document": {
    "id": 1,
    "name": "Some product",
    "price": 100
  }
}

Command line

data-document-creator -i 'product.json' -o 'test-data'

test-data/products/product-1.json

{
  "id": 1,
  "name": "Some product",
  "price": 100
}

Example with multiple documents

products.json

[
  {
    "config": {
      "outputDirectory": "products",
      "outputFilename": "product-1.json",
      "outputFormat": "json"
    },
    "document": {
      "id": 1,
      "name": "Some product",
      "price": 100
    }
  },
  {
    "config": {
      "outputDirectory": "products",
      "outputFilename": "product-2.json",
      "outputFormat": "json"
    },
    "document": {
      "id": 2,
      "name": "Some other product",
      "price": 200
    }
  }
]

Command line

data-document-creator -i 'products.json' -o 'test-data'

test-data/products/product-1.json

{
  "id": 1,
  "name": "Some product",
  "price": 100
}

test-data/products/product-2.json

{
  "id": 2,
  "name": "Some other product",
  "price": 200
}

Example with merging

Input files are merged with json-merger before validating and creating the output.

Go to https://www.npmjs.com/package/json-merger for more information.

product-defaults.json

{
  "config": {
    "outputDirectory": "products",
    "outputFilename": {
      "$afterMerges": {
        "$expression": "`product-${$source.document.id}.json`"
      }
    },
    "outputFormat": "json",
    "validationSchema": "schema.json"
  }
}

product.json

{
  "$merge": {
    "source": {
      "$import": "product-defaults.json"
    },
    "with": {
      "document": {
        "id": 1,
        "name": "Some product",
        "price": 100
      }
    }
  }
}

Command line

data-document-creator -i 'product.json' -o 'test-data'

test-data/products/product-1.json

{
  "id": 1,
  "name": "Some product",
  "price": 100
}

Command line options

Usage: data-document-creator [options]

Options:

  -V, --version                                 output the version number
  -i, --input <files>                           Glob pattern to specify the documents to process
  -o, --output-directory <path>                 The directory to output the processed documents to. If this param is not set the output is sent to stdout.
  -r, --property-removal-indicator <indicator>  Remove all properties containing this value. Defaults to '__NILL__'.
  -s, --skip-schema-validation                  Skip JSON schema validation. Defaults to false.
  -v, --no-verbose                              Verbose output
  -V, --no-verbose                              No verbose output
  -h, --help                                    output usage information