JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q45985F
  • License Apache-2.0

normalize Common Forms

Package Exports

  • commonform-normalize

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (commonform-normalize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Produces a digest-to-object map with an extra .root property containing the digest of the root of the Common Form.

var hash = require('commonform-hash')
var normalize = require('commonform-normalize')

var formA = {content: [ 'A' ]}
var formADigest = hash(formA)

var formB = {
  content: ['B'],
  conspicuous: 'yes'
}
var formBDigest = hash(formB)

var formC = {content: ['C']}
var formCDigest = hash(formC)

var formD = {content: ['D']}
var formDDigest = hash(formD)

var result = {}
result[formADigest] = formA
result[formBDigest] = formB
result[formCDigest] = formC
result[formDDigest] = formD

var first = {
  content: [
    {digest: formADigest},
    {digest: formBDigest}
  ]
}
var firstDigest = hash(first)
result[firstDigest] = first

var second = {
  content: [
    {digest: formCDigest},
    {digest: formDDigest}
  ]
}
var secondDigest = hash(second)
result[secondDigest] = second

var rootForm = {
  content: [
    {heading: 'First', digest: firstDigest},
    {digest: secondDigest}
  ]
}
var rootHash = hash(rootForm)
result[hash(rootForm)] = rootForm
result.root = rootHash

require('assert').deepEqual(
  normalize({
    content: [
      {
        heading: 'First',
        form: {
          content: [
            {form: formA},
            {form: formB}
          ]
        }
      },
      {
        form: {
          content: [
            {form: formC},
            {form: formD}
          ]
        }
      }
    ]
  }),
  result
)