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

shinkansen-transmission

v2.2.204

Published

Shinkansen Transmission

Downloads

1,800

Readme

shinkansen-transmission

Shinkansen generates JSON Schema valid documents from user submissions with <html /> forms.

Transmission

Transmission transforms HTTP POST data into JSON Schema valid JSON documents (and back again).

It can also translate JSON Schema into Zashiki description format describing <html /> forms.

Installation

npm i -P shinkansen-transmission

Your schema should be dereferenced before it is transformed with Transmission (we recommend json-schema-ref-parser).

fromHashToDocument

const document = fromHashToDocument(values, rootSchema)

For applications accepting POST data.

The transformer walks the rootSchema and maps fields in values to another structure, which it returns.

  • values is a hash of keys and values
  • rootSchema is a JSON Schema

The return value is an object valid according to the Schema.

POST data is generally represented as a hash of keys and values, where the values are all strings, or arrays containing strings. fromHashToDocument transforms that hash into a document.

rootSchema
{
  type: 'object',
  properties: {
    company: {
      type: 'object',
      properties: {
        name: {
          type: 'string'
        },
        publisher: {
          type: 'object',
          properties: {
            firstName: {
              type: 'string'
            },
            lastName: {
              type: 'string'
            },
            age: {
              type: 'number'
            }
          }
        }
      }
    },
    active: {
      type: 'boolean'
    }
  }
}
values

An object.

{
  'company-name': 'Marvel',
  'company-publisher-firstName': 'Stan',
  'company-publisher-lastName': 'Lee',
  'company-publisher-age': '96',
  active: 'true'
}
document

An object.

{
  company: {
    name: 'Marvel',
    publisher: {
      firstName: 'Stan',
      lastName: 'Lee',
      age: 96
    }
  },
  active: true
}

fromDocumentToHash

const values = fromDocumentToHash(document, rootSchema)

For applications accepting POST data.

The transformer walks the document and maps its fields to another structure, which it returns.

  • document is an object valid according to the Schema
  • rootSchema is a JSON Schema

The return value is a hash of keys and values, where the values are all strings, or arrays containing strings.

POST data is generally represented as a hash of keys and values, where the values are all strings, or arrays containing strings. fromDocumentToHash transforms a document into that hash.

document

An object.

{
  company: {
    name: 'Marvel',
    publisher: {
      firstName: 'Stan',
      lastName: 'Lee',
      age: 96
    }
  },
  active: true
}
rootSchema
{
  type: 'object',
  properties: {
    company: {
      type: 'object',
      properties: {
        name: {
          type: 'string'
        },
        publisher: {
          type: 'object',
          properties: {
            firstName: {
              type: 'string'
            },
            lastName: {
              type: 'string'
            }
            age: {
              type: 'number'
            }
          }
        }
      }
    },
    active: {
      type: 'boolean'
    }
  }
}
values

A hash.

{
  'company-name': 'Marvel',
  'company-publisher-firstName': 'Stan',
  'company-publisher-lastName': 'Lee',
  'company-publisher-age': '96',
  active: 'true'
}

toZashiki

const zashiki = toZashiki(rootSchema, values, params)

The transformer walks the rootSchema and maps fields in values and params to Zashiki description format, which it returns.

  • rootSchema is a JSON Schema
  • values is a document valid according to the Schema
  • params are any other parameters for the transformer

The return value is an object with the fields meta and elements.

As you might expect, meta contains fields about the Schema, while elements contains fields to be rendered as HTML. (Transmission doesn't express any opinion on what those elements are to be, but assumes that a field will be rendered as an HTML <form /> element or some component which behaves like one.)

Transformed structure

{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    isRequired: Boolean,
    defaultValue: /* Per `type` */,
    value: /* Per `type` */,
  },
  elements: {
    title: String,
    description: String,
    field: {
      isRequired: Boolean,
      value: /* Per `type` */,
      name: String
    }
  }
}
enum
{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    isRequired: Boolean,
    selectedItems: Array
  },
  elements: {
    title: String,
    description: String,
    enum: {
      isRequired: Boolean,
      selectedItems: Array,
      items: Array,
      name: String
    }
  }
}
anyOf
{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    isRequired: Boolean,
    selectedItems: Array,
  },
  elements: {
    title: String,
    description: String,
    anyOf: {
      isRequired: Boolean,
      selectedItems: Array,
      items: Array,
      name: String
    }
  }
}
oneOf
{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    isRequired: Boolean,
    selectedItems: Array,
  },
  elements: {
    title: String,
    description: String,
    oneOf: {
      required: Boolean,
      selectedItems: Array,
      items: Array,
      name: String
    }
  }
}
allOf
  • array or object
{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    required: Boolean,
  },
  elements: {
    title: String,
    description: String,
    fields: Array
  }
}
  • Any other
{
  meta: {
    uri: String,
    name: String,
    type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
    schema: Object,
    rootSchema: Object,
    required: Boolean,
  },
  elements: {
    title: String,
    description: String,
    field: Object
  }
}

See also