6.0.1 • Published 2 years ago

commonform-analyze v6.0.1

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

commonform-analyze

analyze relationships within Common Forms

var analyze = require('commonform-analyze')

Blanks

var assert = require('assert')
assert.deepStrictEqual(
  analyze({ content: [{ blank: '' }] }).blanks,
  [['content', 0]],
  'reports blanks made'
)

assert.deepStrictEqual(
  analyze({ content: [{ form: { content: [{ blank: '' }] } }] }).blanks,
  [['content', 0, 'form', 'content', 0]],
  'reports nested blanks'
)

assert.deepStrictEqual(
  analyze({ content: [{ blank: '' }, { blank: '' }] }).blanks,
  [['content', 0], ['content', 1]],
  'reports multiple blanks'
)

Definitions

assert.deepStrictEqual(
  analyze({ content: [{ definition: 'Agreement' }] }).definitions,
  { Agreement: [['content', 0]] },
  'reports term definitions'
)

assert.deepStrictEqual(
  analyze({
    content: [
      { definition: 'Agreement' },
      { form: { content: [{ definition: 'Termination' }] } }
    ]
  }).definitions,
  {
    Agreement: [['content', 0]],
    Termination: [['content', 1, 'form', 'content', 0]]
  },
  'reports nested definitions'
)

assert.deepStrictEqual(
  analyze({
    content: [
      { definition: 'Agreement' },
      { definition: 'Agreement' }
    ]
  }).definitions,
  {
    Agreement: [
      ['content', 0],
      ['content', 1]
    ]
  },
  'reports multiple paths for >1 definitions'
)

Headings

assert.deepStrictEqual(
  analyze({
    content: [{ heading: 'Price', form: { content: ['x'] } }]
  }).headings,
  { Price: [['content', 0]] },
  'reports headings used'
)

assert.deepStrictEqual(
  analyze({
    content: [
      {
        form: {
          content: [
            {
              heading: 'Price',
              form: { content: ['test'] }
            }
          ]
        }
      }
    ]
  }).headings,
  { Price: [['content', 0, 'form', 'content', 0]] },
  'reports nested headings'
)

assert.deepStrictEqual(
  analyze({
    content: [
      { heading: 'Price', form: { content: ['test'] } },
      { heading: 'Price', form: { content: ['test'] } }
    ]
  }).headings,
  { Price: [['content', 0], ['content', 1]] },
  'reports multiple paths for >1'
)

References

assert.deepStrictEqual(
  analyze({ content: [{ reference: 'Price' }] }).references,
  { Price: [['content', 0]] },
  'reports references made'
)

assert.deepStrictEqual(
  analyze({
    content: [{ form: { content: [{ reference: 'Price' }] } }]
  }).references,
  { Price: [['content', 0, 'form', 'content', 0]] },
  'reports nested references'
)

assert.deepStrictEqual(
  analyze({
    content: [{ reference: 'Price' }, { reference: 'Price' }]
  }).references,
  { Price: [['content', 0], ['content', 1]] },
  'reports multiple references'
)

Uses

assert.deepStrictEqual(
  analyze({ content: [{ use: 'Agreement' }] }).uses,
  { Agreement: [['content', 0]] },
  'reports term uses'
)

assert.deepStrictEqual(
  analyze({
    content: [
      { use: 'Agreement' },
      { form: { content: [{ use: 'Termination' }] } }
    ]
  }).uses,
  {
    Agreement: [['content', 0]],
    Termination: [['content', 1, 'form', 'content', 0]]
  },
  'reports nested uses'
)

assert.deepStrictEqual(
  analyze({
    content: [
      { use: 'Agreement' },
      { use: 'Agreement' }
    ]
  }).uses,
  {
    Agreement: [
      ['content', 0],
      ['content', 1]
    ]
  },
  'reports multiple paths for >1 uses'
)

Components

var component = {
  component: 'https://example.com/component',
  version: '1.0.0',
  substitutions: {
    terms: {
      'Licensor': 'Vendor',
      'Licensee': 'Customer',
      'Program': 'Software'
    },
    headings: {
      'Express Warranties': 'Guarantees'
    },
    blanks: {}
  }
}

var withHeading = Object.assign(
  { heading: 'Disclaimer' },
  component
)

assert.deepStrictEqual(
  analyze({ content: [withHeading] }).components,
  [[component, ['content', 0]]],
  'reports component uses'
)

assert.deepStrictEqual(
  analyze({ content: [withHeading] }).headings['Disclaimer'],
  [['content', 0]],
  'reports component heading'
)

Ignores Links

assert.doesNotThrow(() => {
  analyze({ content: ['test'] })
}, 'no error')
6.0.1

2 years ago

6.0.0

2 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.0.0

7 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.0.0

9 years ago

0.4.4

10 years ago

0.4.3

11 years ago

0.4.2

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago