npm

Need private packages and team management tools?Check out npm Orgs. »

commonform-resolve

2.0.1 • Public • Published

commonform-resolve

resolve definitions, uses, references, fields, and blanks

var resolve = require('commonform-resolve')

Passes strings through:

var assert = require('assert')
 
assert.deepStrictEqual(
  resolve(
    { content: [ 'A' ] },
    {}
  ),
  { content: [ 'A' ] }
)

Passes term uses through:

assert.deepStrictEqual(
  resolve(
    { content: [ { use: 'A' } ] },
    {}
  ),
  { content: [ { use: 'A' } ] }
)

Passes definitions through:

assert.deepStrictEqual(
  resolve(
    { content: [ { definition: 'A' } ] },
    {}
  ),
  { content: [ { definition: 'A' } ] }
)

Provides blank values:

assert.deepStrictEqual(
  resolve(
    { content: [ { blank: 'A' } ] },
    [ { blank: [ 'content', 0 ], value: '1' } ]
  ),
  { content: [ { blank: '1' } ] }
)
 
assert.deepStrictEqual(
  resolve(
    { content: [ { blank: '' } ] },
    []
  ),
  { content: [ { blank: undefined } ] }
)

Replaces references with the numberings of target forms:

assert.deepStrictEqual(
  resolve(
    {
      content: [
        {
          heading: 'A',
          form: { content: [ 'A' ] }
        },
        { reference: 'A' }
      ]
    },
    {}
  )
  .content[1],
  {
    heading: 'A',
    numbering: [
      {
        series: { number: 1, of: 1 },
        element: { number: 1, of: 1 }
      }
    ]
  }
)

Indicates broken references:

assert.deepStrictEqual(
  resolve(
    { content: [ { reference: 'A' } ] },
    {}
  ),
  { content: [ { heading: 'A', broken: true } ] }
)

Flags ambiguous references with the numberings of all potential target forms:

assert.deepStrictEqual(
  resolve(
    {
      content: [
        {
          heading: 'A',
          form: { content: [ 'A' ] }
        },
        {
          heading: 'A',
          form: { content: [ 'A' ] }
        },
        { reference: 'A' }
      ]
    },
    {}
  )
  .content[2],
  {
    heading: 'A',
    ambiguous: true,
    numberings: [
      [
        {
          series: { number: 1, of: 1 },
          element: { number: 1, of: 2 }
        }
      ],
      [
        {
          series: { number: 1, of: 1 },
          element: { number: 2, of: 2 }
        }
      ]
    ]
  }
)

Preserves conspicuous formatting flags:

assert.deepStrictEqual(
  resolve(
    {
      content: [
        {
          heading: 'First',
          form: {
            content: [ 'test' ],
            conspicuous: 'true'
          }
        }
      ]
    },
    {}
  )
  .content,
  [
    {
      heading: 'First',
      form: {
        content: [ 'test' ],
        conspicuous: 'true'
      },
      numbering: [
        {
          series: { number: 1, of: 1 },
          element: { number: 1, of: 1 }
        }
      ]
    }
  ]
)

Throws on invalid content:

assert.throws(
  function () {
    resolve(
      {content: [ { invalid: 'object' } ] },
      {}
    )
  },
  /Invalid content/
)

Attaches numberings to form objects:

assert.deepStrictEqual(
  resolve(
    { content: [ { form: { content: [ 'test' ] } } ] },
    {}
  )
  .content,
  [
    {
      numbering: [
        {
          series: { number: 1, of: 1 },
          element: { number: 1, of: 1 }
        }
      ],
      form: { content: [ 'test' ] }
    }
  ]
)

install

npm i commonform-resolve

Downloadsweekly downloads

47

version

2.0.1

license

BlueOak-1.0.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability