commonform-docx 10.1.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.js CHANGED
@@ -1,8 +1,16 @@
1
1
  #!/usr/bin/env node
2
- const docopt = require('@kemitchell/docopt').docopt
3
- const fs = require('fs')
4
- const has = require('has')
5
- const path = require('path')
2
+ import meta from './package.json' with { type: 'json' }
3
+ import { docopt } from '@kemitchell/docopt'
4
+ import { readFileSync } from 'fs'
5
+ import ooxmlSignaturePages from 'ooxml-signature-pages'
6
+ import { resolve } from 'path'
7
+ import docx from './index.js'
8
+
9
+ import rse from 'resolutions-schedules-exhibits-numbering',
10
+ import ase from 'agreement-schedules-exhibits-numbering',
11
+ import pae from 'plan-addenda-exhibits-numbering',
12
+ import decimal from 'decimal-numbering',
13
+ import outline from 'outline-numbering'
6
14
 
7
15
  // Parse arguments and options.
8
16
 
@@ -14,7 +22,7 @@ const usage = [
14
22
  ' -h, --help Show this screen.',
15
23
  ' -v, --version Show version.',
16
24
  ' -H, --hash Render form hash',
17
- ' -a, --a4-paper A4 paper',
25
+ ' -a, --a4-paper Set paper size to A4',
18
26
  ' -b TEXT, --blank-text TEXT Render blanks with custom text',
19
27
  ' --complete Throw an error if any blank does not have a value.',
20
28
  ' --component-style STYLE Change component style [default: both]',
@@ -32,11 +40,11 @@ const usage = [
32
40
  ' -r --left-align-body Left-align body paragraphs.',
33
41
  ' -s PAGES, --signatures PAGES Signature page data',
34
42
  ' -t TITLE, --title TITLE Render title as <h1>',
35
- ' -v JSON --values JSON Use values to fill in blanks',
43
+ ' --values JSON Use values to fill in blanks',
36
44
  ' -y JSON, --styles JSON Render with custom styles'
37
45
  ].join('\n')
38
46
 
39
- const parsed = docopt(usage, { version: require('./package.json').version })
47
+ const parsed = docopt(usage, { version: meta.version })
40
48
 
41
49
  // Parse arguments and options.
42
50
 
@@ -53,13 +61,13 @@ if (parsed['--title']) options.title = parsed['--title']
53
61
  if (parsed['--number']) {
54
62
  const numberStyle = parsed['--number']
55
63
  const supportedNumberingStyles = {
56
- rse: 'resolutions-schedules-exhibits-numbering',
57
- ase: 'agreement-schedules-exhibits-numbering',
58
- pae: 'plan-addenda-exhibits-numbering',
59
- decimal: 'decimal-numbering',
60
- outline: 'outline-numbering'
64
+ rse,
65
+ ase,
66
+ pae,
67
+ decimal,
68
+ outline,
61
69
  }
62
- if (!has(supportedNumberingStyles, numberStyle)) {
70
+ if (!Object.hasOwn(supportedNumberingStyles, numberStyle)) {
63
71
  process.stderr.write([
64
72
  `"${numberStyle}" is not a valid numbering style.`,
65
73
  'Valid styles are ' +
@@ -69,20 +77,20 @@ if (parsed['--number']) {
69
77
  ].join('\n') + '\n')
70
78
  process.exit(1)
71
79
  } else {
72
- options.numberStyle = require(supportedNumberingStyles[numberStyle])
80
+ options.numberStyle = supportedNumberingStyles[numberStyle]
73
81
  }
74
82
  } else {
75
- options.numberStyle = require('decimal-numbering')
83
+ options.numberStyle = decimal
76
84
  }
77
85
 
78
86
  if (parsed['--signatures']) {
79
- options.after = require('ooxml-signature-pages')(
80
- JSON.parse(fs.readFileSync(parsed['--signatures']))
87
+ options.after = ooxmlSignaturePages(
88
+ JSON.parse(readFileSync(parsed['--signatures']))
81
89
  )
82
90
  }
83
91
 
84
92
  if (parsed['--styles']) {
85
- options.styles = JSON.parse(fs.readFileSync(parsed['--styles']))
93
+ options.styles = JSON.parse(readFileSync(parsed['--styles']))
86
94
  }
87
95
 
88
96
  if (parsed['--title']) options.title = parsed['--title']
@@ -115,10 +123,10 @@ if (parsed['--quote-component-text']) options.quoteComponentText = parsed['--quo
115
123
  options.incorporateComponentText = parsed['--incorporate-component-text']
116
124
 
117
125
  function readJSON (file) {
118
- return JSON.parse(fs.readFileSync(path.resolve(file)))
126
+ return JSON.parse(readFileSync(resolve(file)))
119
127
  }
120
128
 
121
129
  // Render and print.
122
- const rendered = require('./')(form, blanks, options)
130
+ const rendered = docs(form, blanks, options)
123
131
 
124
132
  rendered.generateNodeStream().pipe(process.stdout)
package/escape.js CHANGED
@@ -1,4 +1,4 @@
1
- module.exports = string => {
1
+ export default string => {
2
2
  const special = {
3
3
  '&amp;': /&/g,
4
4
  '&apos;': /'/g,
package/index.js CHANGED
@@ -1,10 +1,11 @@
1
- const JSZip = require('jszip')
2
- const commonformHash = require('commonform-hash')
3
- const decimalNumbering = require('decimal-numbering')
4
- const smartify = require('commonform-smartify')
1
+ import JSZip from 'jszip'
2
+ import commonformHash from 'commonform-hash'
3
+ import decimalNumbering from 'decimal-numbering'
4
+ import smartify from 'commonform-smartify'
5
+ import scaffold from './data/scaffold.json' with { type: 'json' }
5
6
 
6
- const doc = require('./templates/document')
7
- const docRels = require('./templates/document-relationships')
7
+ import doc from './templates/document.js'
8
+ import docRels from './templates/document-relationships.js'
8
9
 
9
10
  function defaultStyles (smart) {
10
11
  return {
@@ -25,7 +26,7 @@ function defaultStyles (smart) {
25
26
  }
26
27
  }
27
28
 
28
- module.exports = (form, values = [], options = {}) => {
29
+ export default (form, values = [], options = {}) => {
29
30
  let {
30
31
  a4 = false,
31
32
  after = '',
@@ -80,7 +81,6 @@ module.exports = (form, values = [], options = {}) => {
80
81
  version
81
82
  }
82
83
  )
83
- const scaffold = require('./data/scaffold.json')
84
84
  const clone = structuredClone(scaffold)
85
85
  clone.word['document.xml'] = result.xml
86
86
  clone.word._rels['document.xml.rels'] = docRels(result.hrefs)
package/package.json CHANGED
@@ -1,27 +1,24 @@
1
1
  {
2
2
  "name": "commonform-docx",
3
3
  "description": "render Common Forms in Office Open XML (Microsoft Word .docx format)",
4
- "version": "10.1.1",
4
+ "version": "11.0.0",
5
5
  "author": "Kyle E. Mitchell <kyle@kemitchell.com> (http://kemitchell.com)",
6
6
  "bin": "bin.js",
7
+ "type": "module",
8
+ "main": "index.js",
7
9
  "files": [
8
- "bin.js",
9
10
  "data/scaffold.json",
10
11
  "escape.js",
11
- "index.js",
12
- "LICENSE.md",
13
- "README.md",
14
12
  "templates"
15
13
  ],
16
14
  "dependencies": {
17
15
  "@kemitchell/docopt": "^1.0.0",
18
16
  "agreement-schedules-exhibits-numbering": "^3.0.0",
19
- "commonform-flatten": "^3.0.0",
20
- "commonform-hash": "^1.0.0",
21
- "commonform-prepare-blanks": "^1.0.1",
22
- "commonform-smartify": "^1.0.1",
17
+ "commonform-flatten": "^4.0.0",
18
+ "commonform-hash": "^2.0.0",
19
+ "commonform-prepare-blanks": "^2.0.0",
20
+ "commonform-smartify": "^2.0.0",
23
21
  "decimal-numbering": "^4.0.0",
24
- "has": "^1.0.3",
25
22
  "jszip": "^3.2.1",
26
23
  "number-to-words-en": "^1.2.5",
27
24
  "ooxml-signature-pages": "^3.0.2",
@@ -30,9 +27,7 @@
30
27
  "resolutions-schedules-exhibits-numbering": "^2.0.0"
31
28
  },
32
29
  "devDependencies": {
33
- "istanbul": "^0.4.0",
34
30
  "run-series": "^1.1.8",
35
- "standard": "^17.0.0",
36
31
  "tape": "^5.0.1",
37
32
  "textract": "^2.5.0"
38
33
  },
@@ -49,11 +44,11 @@
49
44
  "license": "BlueOak-1.0.0",
50
45
  "repository": "commonform/commonform-docx",
51
46
  "scripts": {
52
- "lint": "standard",
53
- "precoverage": "npm run pretest && istanbul cover -- tape test.js",
54
- "coverage": "FORCE_COLOR=true istanbul check-coverage coverage/coverage.json",
55
- "prepublishOnly": "node build/scaffold.js data/scaffold.docx > data/scaffold.json",
56
- "pretest": "npm run prepublishOnly",
57
- "test": "tape test.js"
47
+ "precoverage": "npm run build",
48
+ "coverage": "node --experimental-test-coverage --test --test-concurrency=1 test.js",
49
+ "build": "node build/scaffold.js data/scaffold.docx > data/scaffold.json",
50
+ "prepublishOnly": "npm run build",
51
+ "pretest": "npm run build",
52
+ "test": "node --test --test-concurrency=1 test.js"
58
53
  }
59
54
  }
@@ -1,7 +1,8 @@
1
- const escape = require('../escape')
1
+ import escape from '../escape.js'
2
+ import scaffold from '../data/scaffold.json' with { type: 'json' }
2
3
 
3
- module.exports = array => {
4
- const scaffolded = require('../data/scaffold.json').word._rels['document.xml.rels']
4
+ export default array => {
5
+ const scaffolded = scaffold.word._rels['document.xml.rels']
5
6
  if (array.length === 0) return scaffolded
6
7
  const appended = []
7
8
  for (let index = 0; index < array.length; index++) {
@@ -1,7 +1,7 @@
1
- const flatten = require('commonform-flatten')
2
- const hashRun = require('./hash')
3
- const titleRun = require('./title')
4
- const paragraph = require('./paragraph')
1
+ import flatten from 'commonform-flatten'
2
+ import hashRun from './hash.js'
3
+ import titleRun from './title.js'
4
+ import paragraph from './paragraph.js'
5
5
 
6
6
  const DOCUMENT_XMLNS = (
7
7
  /* jscs:disable maximumLineLength */
@@ -40,7 +40,7 @@ function section (a4) {
40
40
  return returned
41
41
  }
42
42
 
43
- module.exports = (form, values, options) => {
43
+ export default (form, values, options) => {
44
44
  // Hyperlinks in documents must refer to Relationships by rId.
45
45
  // Set up a running list of HREFs to turn into Relationships,
46
46
  // then pass a helper function that assigns rIds to HREFs.
package/templates/hash.js CHANGED
@@ -1,6 +1,6 @@
1
- const paragraph = require('./paragraph')
1
+ import paragraph from './paragraph.js'
2
2
 
3
- module.exports = (string, options) => {
3
+ export default (string, options) => {
4
4
  return paragraph({
5
5
  title: true,
6
6
  alignment: options.leftAlignTitle ? 'left' : 'center',
@@ -1,6 +1,6 @@
1
- const escape = require('../escape')
1
+ import escape from '../escape.js'
2
2
 
3
- module.exports = (options, url) => {
3
+ export default (options, url) => {
4
4
  const rId = options.rIdForHREF(url)
5
5
  return `<w:hyperlink r:id="${rId}"><w:r><w:rPr><w:color w:val="0000EE"/><w:u w:val="single"/></w:rPr><w:t>${escape(url)}</w:t></w:r></w:hyperlink>`
6
6
  }
@@ -1,8 +1,7 @@
1
- const has = require('has')
2
- const hyperlink = require('./hyperlink')
3
- const numberToWords = require('number-to-words-en')
4
- const run = require('./run')
5
- const tag = require('./tag')
1
+ import hyperlink from './hyperlink.js'
2
+ import numberToWords from 'number-to-words-en'
3
+ import run from './run.js'
4
+ import tag from './tag.js'
6
5
 
7
6
  // Half an inch in twentieths of a point
8
7
  const HALF_INCH = 720
@@ -46,20 +45,20 @@ function properties (o, number, indentMargins) {
46
45
 
47
46
  const TAB = '<w:r><w:tab/></w:r>'
48
47
 
49
- module.exports = (element, options) => {
50
- if (!has(element, 'alignment')) {
48
+ export default (element, options) => {
49
+ if (!Object.hasOwn(element, 'alignment')) {
51
50
  element.alignment = options.styles.alignment || 'justify'
52
51
  }
53
- const number = has(element, 'numbering')
52
+ const number = Object.hasOwn(element, 'numbering')
54
53
  ? options.numberStyle(element.numbering, true)
55
54
  : ''
56
- const conspicuous = has(element, 'conspicuous')
57
- const hasComponent = has(element, 'component')
58
- const hasContent = has(element, 'content')
55
+ const conspicuous = Object.hasOwn(element, 'conspicuous')
56
+ const hasComponent = Object.hasOwn(element, 'component')
57
+ const hasContent = Object.hasOwn(element, 'content')
59
58
  let returned = '<w:p>'
60
59
  returned += properties(element, number, options.indentMargins)
61
60
  returned += number ? makeRun(number, false) + TAB : ''
62
- if (has(element, 'heading')) {
61
+ if (Object.hasOwn(element, 'heading')) {
63
62
  returned += makeRun({ caption: element.heading }, conspicuous)
64
63
  if (!/\.$/.test(element.heading)) {
65
64
  returned += makeRun('.', false)
@@ -100,7 +99,7 @@ module.exports = (element, options) => {
100
99
  return returned
101
100
 
102
101
  function childContent (element) {
103
- const conspicuous = has(element, 'conspicuous')
102
+ const conspicuous = Object.hasOwn(element, 'conspicuous')
104
103
  return element.content
105
104
  .map(element => makeRun(element, conspicuous, options))
106
105
  .join('')
package/templates/run.js CHANGED
@@ -1,7 +1,6 @@
1
- const escape = require('../escape')
2
- const has = require('has')
3
- const hyperlink = require('./hyperlink')
4
- const tag = require('./tag')
1
+ import escape from '../escape.js'
2
+ import hyperlink from './hyperlink.js'
3
+ import tag from './tag.js'
5
4
 
6
5
  const defaults = {
7
6
  highlight: false,
@@ -10,7 +9,7 @@ const defaults = {
10
9
  underline: false
11
10
  }
12
11
 
13
- module.exports = function run (element, conspicuous, options) {
12
+ export default function run (element, conspicuous, options) {
14
13
  const { styles } = options
15
14
  const properties = Object.assign({}, defaults)
16
15
  if (conspicuous === true) {
@@ -21,16 +20,16 @@ module.exports = function run (element, conspicuous, options) {
21
20
  if (typeof element === 'string') {
22
21
  Object.assign(properties, styles.text)
23
22
  text = element
24
- } else if (has(element, 'caption')) {
23
+ } else if (Object.hasOwn(element, 'caption')) {
25
24
  Object.assign(properties, styles.heading)
26
25
  text = element.caption
27
- } else if (has(element, 'title')) {
26
+ } else if (Object.hasOwn(element, 'title')) {
28
27
  Object.assign(properties, styles.title)
29
28
  text = element.title
30
- } else if (has(element, 'monospaced')) {
29
+ } else if (Object.hasOwn(element, 'monospaced')) {
31
30
  Object.assign(properties, styles.monospaced)
32
31
  text = element.monospaced
33
- } else if (has(element, 'definition')) {
32
+ } else if (Object.hasOwn(element, 'definition')) {
34
33
  const term = element.definition
35
34
  return (
36
35
  (
@@ -45,7 +44,7 @@ module.exports = function run (element, conspicuous, options) {
45
44
  : ''
46
45
  )
47
46
  )
48
- } else if (has(element, 'blank')) {
47
+ } else if (Object.hasOwn(element, 'blank')) {
49
48
  Object.assign(properties, styles.text)
50
49
  if (element.blank !== undefined) {
51
50
  text = element.blank
@@ -55,15 +54,15 @@ module.exports = function run (element, conspicuous, options) {
55
54
  text = options.blanks.text
56
55
  if (options.blanks.highlight) Object.assign(properties, styles.highlighted)
57
56
  }
58
- } else if (has(element, 'use')) {
57
+ } else if (Object.hasOwn(element, 'use')) {
59
58
  Object.assign(properties, styles.use)
60
59
  text = element.use
61
- } else if (has(element, 'heading')) {
60
+ } else if (Object.hasOwn(element, 'heading')) {
62
61
  const numbering = element.numbering
63
62
  const heading = element.heading
64
63
  if (
65
- has(element, 'broken') ||
66
- has(element, 'ambiguous')
64
+ Object.hasOwn(element, 'broken') ||
65
+ Object.hasOwn(element, 'ambiguous')
67
66
  ) {
68
67
  Object.assign(properties, styles.broken)
69
68
  text = '[Broken Cross-Reference to "' + heading + '"]'
@@ -84,7 +83,7 @@ module.exports = function run (element, conspicuous, options) {
84
83
  )
85
84
  )
86
85
  }
87
- } else if (has(element, 'link')) {
86
+ } else if (Object.hasOwn(element, 'link')) {
88
87
  return hyperlink(options, element.link)
89
88
  } else {
90
89
  throw new Error('Invalid type: ' + JSON.stringify(element, null, 2))
package/templates/tag.js CHANGED
@@ -1,3 +1,3 @@
1
- module.exports = (name, content) => {
1
+ export default (name, content) => {
2
2
  return `<${name}>${content}</${name}>`
3
3
  }
@@ -1,6 +1,6 @@
1
- const paragraph = require('./paragraph')
1
+ import paragraph from './paragraph.js'
2
2
 
3
- module.exports = (string, options) => {
3
+ export default (string, options) => {
4
4
  const argument = {
5
5
  title: true,
6
6
  alignment: 'center',