3.0.0 • Published 2 years ago

commonform-flatten v3.0.0

Weekly downloads
441
License
BlueOak-1.0.0
Repository
github
Last release
2 years ago

commonform-flatten

Produces a useful intermediary representation for rendering in linear document formats, like Office Open XML and terminal listings.

var flatten = require('commonform-flatten')
var assert = require('assert')

assert.deepStrictEqual(
  flatten(
    {
      content: [
        'some text ',
        { blank: '' },
        {
          heading: 'A',
          form: {
            conspicuous: 'yes',
            content: [
              'before',
              { form: { content: ['B'] } },
              { form: { content: ['C'] } },
              'between',
              { form: { content: ['D'] } },
              { form: { content: ['E'] } },
              'after'
            ]
          }
        },
        'after',
        { use: 'A Defined Term' },
        {
          heading: 'Some Component',
          component: 'https://example.com/component',
          version: '1.0.0',
          substitutions: {
            terms: {},
            headings: {}
          }
        }
      ]
    },
    [{ blank: ['content', 1], value: 'NewCo' }]
  ),
  [
    {
      depth: 1,
      content: [
        'some text ',
        { blank: 'NewCo' }
      ]
    },
    {
      depth: 2,
      heading: 'A',
      content: ['before'],
      numbering: [
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 1 }
        }
      ],
      conspicuous: 'yes'
    },
    {
      depth: 3,
      content: ['B'],
      numbering: [
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 1 }
        },
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 2 }
        }
      ]
    },
    {
      depth: 3,
      content: ['C'],
      numbering: [
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 1 }
        },
        {
          series: { number: 1, of: 2 },
          element: { number: 2, of: 2 }
        }
      ]
    },
    {
      depth: 2,
      content: ['between'],
      conspicuous: 'yes'
    },
    {
      depth: 3,
      content: ['D'],
      numbering: [
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 1 }
        },
        {
          series: { number: 2, of: 2 },
          element: { number: 1, of: 2 }
        }
      ]
    },
    {
      depth: 3,
      content: ['E'],
      numbering: [
        {
          series: { number: 1, of: 2 },
          element: { number: 1, of: 1 }
        },
        {
          series: { number: 2, of: 2 },
          element: { number: 2, of: 2 }
        }
      ]
    },
    {
      depth: 2,
      content: ['after'],
      conspicuous: 'yes'
    },
    {
      depth: 1,
      content: [
        'after',
        { use: 'A Defined Term' }
      ]
    },
    {
      depth: 2,
      heading: 'Some Component',
      component: 'https://example.com/component',
      version: '1.0.0',
      substitutions: { terms: {}, headings: {} },
      numbering: [
        {
          series: { number: 2, of: 2 },
          element: { number: 1, of: 1 }
        }
      ]
    }
  ]
)

Preserves loaded component attributes:

var form = { content: ['This is a test.'] }

var reference = {
  component: 'https://example.com/component',
  version: '1.0.0',
  substitutions: { terms: {}, headings: {} }
}

var component = {
  publisher: 'Example Publisher',
  name: 'Example Component',
  version: '1.0.0'
}

assert.deepStrictEqual(
  flatten(
    {
      content: [
        {
          heading: 'Example Component',
          form: form,
          component: component,
          reference: reference
        }
      ]
    },
    [/* no blanks */]
  ),
  [
    {
      depth: 2,
      heading: 'Example Component',
      content: ['This is a test.'],
      reference: reference,
      component: component,
      numbering: [
        {
          element: { number: 1, of: 1 },
          series: { number: 1, of: 1 }
        }
      ]
    }
  ]
)
3.0.0

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.8.1

9 years ago

0.8.0

10 years ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago