commonform-docx 9.3.0 → 10.1.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/README.md CHANGED
@@ -24,4 +24,6 @@ It may contain:
24
24
 
25
25
  4. a `markFilled` property whose value is `true` or `false`
26
26
 
27
+ 5. other properties you can find in function exported from `index.js`
28
+
27
29
  The function returns a [JSZip](https://npmjs.com/packages/jszip) Object primed with `.docx` document data.
package/bin.js CHANGED
@@ -20,6 +20,8 @@ const usage = [
20
20
  ' --component-style STYLE Change component style [default: both]',
21
21
  ' -d JSON --directions JSON Use directions to fill in blanks',
22
22
  ' -e VERSION, --form-version VERSION Form version to be rendered',
23
+ ' --font NAME Default font family name',
24
+ ' --font-size POINTS Default font size in points',
23
25
  ' -i, --indent-margins Indent margins, commonwealth style',
24
26
  ' --incorporate-component-text TEXT Verb for component references [default: Incorporate]',
25
27
  ' --quote-component-text TEXT Text for introducing quoted components',
@@ -105,6 +107,9 @@ if (parsed['--blank-text']) options.blanks = parsed['--blank-text']
105
107
 
106
108
  if (parsed['--mark-filled']) options.markFilled = true
107
109
 
110
+ if (parsed['--font']) options.font = parsed['--font']
111
+ if (parsed['--font-size']) options.fontSize = parsed['--font-size']
112
+
108
113
  options.loadedComponentStyle = parsed['--component-style']
109
114
  if (parsed['--quote-component-text']) options.quoteComponentText = parsed['--quote-component-text']
110
115
  options.incorporateComponentText = parsed['--incorporate-component-text']
package/index.js CHANGED
@@ -25,10 +25,8 @@ function defaultStyles (smart) {
25
25
  }
26
26
  }
27
27
 
28
- module.exports = (
29
- form,
30
- values = [],
31
- {
28
+ module.exports = (form, values = [], options = {}) => {
29
+ let {
32
30
  a4 = false,
33
31
  after = '',
34
32
  blanks = { text: '[•]', highlight: 'yellow' },
@@ -39,15 +37,21 @@ module.exports = (
39
37
  leftAlignTitle = false,
40
38
  loadedComponentStyle = 'inline',
41
39
  markFilled = false,
40
+ fontSize = 12,
41
+ font = 'Times New Roman',
42
42
  complete = false,
43
43
  numberStyle = decimalNumbering,
44
44
  quoteComponentText = 'Quoting for convenience, with any conflicts resolved in favor of the standard:',
45
45
  smart,
46
46
  styles,
47
47
  title,
48
- version
48
+ version,
49
+ ...rest
50
+ } = options
51
+ const extraKeys = Object.keys(rest)
52
+ if (extraKeys.length !== 0) {
53
+ throw new Error(`Unsupported Options: ${extraKeys.join(', ')}`)
49
54
  }
50
- ) => {
51
55
  styles = styles
52
56
  ? Object.assign({}, defaultStyles(smart), styles)
53
57
  : defaultStyles(smart)
@@ -80,6 +84,26 @@ module.exports = (
80
84
  const clone = Object.assign({}, scaffold)
81
85
  clone.word['document.xml'] = result.xml
82
86
  clone.word._rels['document.xml.rels'] = docRels(result.hrefs)
87
+ // Set default font size. We need to replace <w:sz> and <w:szCs>
88
+ // elements both in <w:docDefaults> and in the default style.
89
+ const fontSizeInHalfPoints = Math.floor(fontSize * 2)
90
+ clone.word['styles.xml'] = clone.word['styles.xml']
91
+ .replaceAll(
92
+ /<w:sz w:val="[0-9]+"\/>/g,
93
+ `<w:sz w:val="${fontSizeInHalfPoints}"/>`
94
+ )
95
+ .replaceAll(
96
+ /<w:szCs w:val="[0-9]+"\/>/g,
97
+ `<w:szCs w:val="${fontSizeInHalfPoints}"/>`
98
+ )
99
+ // Set font family the same way.
100
+ if (font !== 'Times New Roman') {
101
+ clone.word['styles.xml'] = clone.word['styles.xml']
102
+ .replaceAll(
103
+ '<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>',
104
+ `<w:rFonts w:ascii="${font}" w:hAnsi="${font}"/>`
105
+ )
106
+ }
83
107
  const zip = new JSZip()
84
108
  zipObject(zip, clone)
85
109
  return zip
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "commonform-docx",
3
3
  "description": "render Common Forms in Office Open XML (Microsoft Word .docx format)",
4
- "version": "9.3.0",
4
+ "version": "10.1.0",
5
5
  "author": "Kyle E. Mitchell <kyle@kemitchell.com> (http://kemitchell.com)",
6
6
  "bin": "bin.js",
7
+ "files": [
8
+ "bin.js",
9
+ "data/scaffold.json",
10
+ "escape.js",
11
+ "index.js",
12
+ "LICENSE.md",
13
+ "README.md",
14
+ "templates"
15
+ ],
7
16
  "dependencies": {
8
17
  "@kemitchell/docopt": "^1.0.0",
9
18
  "agreement-schedules-exhibits-numbering": "^3.0.0",
@@ -1,4 +1,3 @@
1
- const escape = require('../escape')
2
1
  const has = require('has')
3
2
  const hyperlink = require('./hyperlink')
4
3
  const numberToWords = require('number-to-words-en')
package/lint.log DELETED
@@ -1,4 +0,0 @@
1
-
2
- > commonform-docx@9.1.1 lint
3
- > standard
4
-
package/outdated.log DELETED
File without changes
package/test.log DELETED
@@ -1,98 +0,0 @@
1
-
2
- > commonform-docx@9.2.0 pretest
3
- > npm run prepublishOnly
4
-
5
-
6
- > commonform-docx@9.2.0 prepublishOnly
7
- > node build/scaffold.js data/scaffold.docx > data/scaffold.json
8
-
9
-
10
- > commonform-docx@9.2.0 test
11
- > tape test.js
12
-
13
- TAP version 13
14
- # renders text
15
- ok 1 no render error
16
- ok 2 no textract error
17
- ok 3 text appears in output
18
- # renders definitions
19
- ok 4 no render error
20
- ok 5 no textract error
21
- ok 6 defined term appears in output
22
- # renders uses
23
- ok 7 no render error
24
- ok 8 no textract error
25
- ok 9 term appears in output
26
- # renders references
27
- ok 10 no render error
28
- ok 11 no textract error
29
- ok 12 reference appears in output
30
- # handles components without headings
31
- ok 13 no render error
32
- # handles components with substitutions
33
- ok 14 no render error
34
- # omits period after heading ending w/ period
35
- ok 15 no render error
36
- ok 16 no textract error
37
- ok 17 double period does not appear in output
38
- # adds space between heading and defined term
39
- ok 18 no render error
40
- ok 19 no textract error
41
- ok 20 space between heading and term
42
- # adds space between heading and text
43
- ok 21 no render error
44
- ok 22 no textract error
45
- ok 23 space between heading and text
46
- # renders broken references
47
- ok 24 no render error
48
- ok 25 no textract error
49
- ok 26 reference appears in output
50
- # fills blanks
51
- ok 27 no render error
52
- ok 28 no textract error
53
- ok 29 value appears in output
54
- # custom blank text
55
- ok 30 no render error
56
- ok 31 no textract error
57
- ok 32 value appears in output
58
- # renders empty blank placeholders
59
- ok 33 no render error
60
- ok 34 no textract error
61
- ok 35 placeholder appears in output
62
- # renders custom empty blank placeholders
63
- ok 36 no render error
64
- ok 37 no textract error
65
- ok 38 placeholder appears in output
66
- # renders custom empty blank placeholders
67
- ok 39 no render error
68
- ok 40 no textract error
69
- ok 41 placeholder appears in output
70
- # renders conspicuous text
71
- ok 42 no render error
72
- ok 43 no textract error
73
- ok 44 conspicuous text appears in output
74
- # renders titles
75
- ok 45 no render error
76
- ok 46 no textract error
77
- ok 47 title appears in output
78
- # renders centered titles
79
- ok 48 no render error
80
- ok 49 no textract error
81
- ok 50 title appears in output
82
- # renders versions
83
- ok 51 no render error
84
- ok 52 no textract error
85
- ok 53 version appears in output
86
- # renders hashes
87
- ok 54 no render error
88
- ok 55 no textract error
89
- ok 56 hash symbol appears in output
90
- # throws for invalid content
91
- ok 57 throw an error
92
-
93
- 1..57
94
- # tests 57
95
- # pass 57
96
-
97
- # ok
98
-