@dwp/govuk-casa 9.0.0 → 9.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.
Files changed (199) hide show
  1. package/README.md +9 -9
  2. package/dist/assets/css/casa.css +1 -1
  3. package/dist/assets/css/casa.css.map +1 -1
  4. package/dist/casa.d.ts +122 -95
  5. package/dist/casa.js +119 -86
  6. package/dist/casa.js.map +1 -1
  7. package/dist/lib/CasaTemplateLoader.d.ts +4 -4
  8. package/dist/lib/CasaTemplateLoader.js +16 -16
  9. package/dist/lib/CasaTemplateLoader.js.map +1 -1
  10. package/dist/lib/JourneyContext.d.ts +38 -40
  11. package/dist/lib/JourneyContext.js +81 -75
  12. package/dist/lib/JourneyContext.js.map +1 -1
  13. package/dist/lib/MutableRouter.d.ts +40 -41
  14. package/dist/lib/MutableRouter.js +64 -71
  15. package/dist/lib/MutableRouter.js.map +1 -1
  16. package/dist/lib/Plan.d.ts +29 -26
  17. package/dist/lib/Plan.js +85 -71
  18. package/dist/lib/Plan.js.map +1 -1
  19. package/dist/lib/ValidationError.d.ts +16 -15
  20. package/dist/lib/ValidationError.js +21 -20
  21. package/dist/lib/ValidationError.js.map +1 -1
  22. package/dist/lib/ValidatorFactory.d.ts +15 -13
  23. package/dist/lib/ValidatorFactory.js +14 -12
  24. package/dist/lib/ValidatorFactory.js.map +1 -1
  25. package/dist/lib/configuration-ingestor.d.ts +37 -40
  26. package/dist/lib/configuration-ingestor.js +93 -93
  27. package/dist/lib/configuration-ingestor.js.map +1 -1
  28. package/dist/lib/configure.d.ts +6 -6
  29. package/dist/lib/configure.js +14 -12
  30. package/dist/lib/configure.js.map +1 -1
  31. package/dist/lib/constants.d.ts +1 -3
  32. package/dist/lib/constants.js +9 -11
  33. package/dist/lib/constants.js.map +1 -1
  34. package/dist/lib/context-id-generators.d.ts +3 -5
  35. package/dist/lib/context-id-generators.js +7 -6
  36. package/dist/lib/context-id-generators.js.map +1 -1
  37. package/dist/lib/end-session.d.ts +4 -4
  38. package/dist/lib/end-session.js +5 -5
  39. package/dist/lib/field.d.ts +20 -18
  40. package/dist/lib/field.js +35 -48
  41. package/dist/lib/field.js.map +1 -1
  42. package/dist/lib/index.d.ts +13 -13
  43. package/dist/lib/logger.d.ts +7 -6
  44. package/dist/lib/logger.js +7 -7
  45. package/dist/lib/logger.js.map +1 -1
  46. package/dist/lib/mount.d.ts +5 -5
  47. package/dist/lib/mount.js +11 -10
  48. package/dist/lib/mount.js.map +1 -1
  49. package/dist/lib/nunjucks-filters.d.ts +10 -12
  50. package/dist/lib/nunjucks-filters.js +35 -35
  51. package/dist/lib/nunjucks-filters.js.map +1 -1
  52. package/dist/lib/nunjucks.d.ts +7 -5
  53. package/dist/lib/nunjucks.js +10 -8
  54. package/dist/lib/nunjucks.js.map +1 -1
  55. package/dist/lib/utils.d.ts +19 -19
  56. package/dist/lib/utils.js +62 -55
  57. package/dist/lib/utils.js.map +1 -1
  58. package/dist/lib/validators/dateObject.d.ts +29 -22
  59. package/dist/lib/validators/dateObject.js +58 -49
  60. package/dist/lib/validators/dateObject.js.map +1 -1
  61. package/dist/lib/validators/email.d.ts +4 -4
  62. package/dist/lib/validators/email.js +4 -4
  63. package/dist/lib/validators/inArray.d.ts +4 -4
  64. package/dist/lib/validators/inArray.js +7 -8
  65. package/dist/lib/validators/inArray.js.map +1 -1
  66. package/dist/lib/validators/index.d.ts +10 -10
  67. package/dist/lib/validators/index.js +1 -3
  68. package/dist/lib/validators/index.js.map +1 -1
  69. package/dist/lib/validators/nino.d.ts +9 -8
  70. package/dist/lib/validators/nino.js +14 -10
  71. package/dist/lib/validators/nino.js.map +1 -1
  72. package/dist/lib/validators/postalAddressObject.d.ts +37 -24
  73. package/dist/lib/validators/postalAddressObject.js +65 -46
  74. package/dist/lib/validators/postalAddressObject.js.map +1 -1
  75. package/dist/lib/validators/range.d.ts +12 -8
  76. package/dist/lib/validators/range.js +11 -9
  77. package/dist/lib/validators/range.js.map +1 -1
  78. package/dist/lib/validators/regex.d.ts +4 -4
  79. package/dist/lib/validators/regex.js +5 -5
  80. package/dist/lib/validators/required.d.ts +6 -6
  81. package/dist/lib/validators/required.js +9 -11
  82. package/dist/lib/validators/required.js.map +1 -1
  83. package/dist/lib/validators/strlen.d.ts +12 -8
  84. package/dist/lib/validators/strlen.js +13 -11
  85. package/dist/lib/validators/strlen.js.map +1 -1
  86. package/dist/lib/validators/wordCount.d.ts +12 -8
  87. package/dist/lib/validators/wordCount.js +15 -11
  88. package/dist/lib/validators/wordCount.js.map +1 -1
  89. package/dist/lib/waypoint-url.d.ts +16 -13
  90. package/dist/lib/waypoint-url.js +39 -36
  91. package/dist/lib/waypoint-url.js.map +1 -1
  92. package/dist/middleware/body-parser.d.ts +1 -1
  93. package/dist/middleware/body-parser.js +6 -6
  94. package/dist/middleware/body-parser.js.map +1 -1
  95. package/dist/middleware/data.d.ts +1 -1
  96. package/dist/middleware/data.js +8 -7
  97. package/dist/middleware/data.js.map +1 -1
  98. package/dist/middleware/gather-fields.d.ts +2 -2
  99. package/dist/middleware/gather-fields.js +6 -4
  100. package/dist/middleware/gather-fields.js.map +1 -1
  101. package/dist/middleware/i18n.js +13 -15
  102. package/dist/middleware/i18n.js.map +1 -1
  103. package/dist/middleware/post.js +30 -18
  104. package/dist/middleware/post.js.map +1 -1
  105. package/dist/middleware/pre.d.ts +2 -2
  106. package/dist/middleware/pre.js +46 -27
  107. package/dist/middleware/pre.js.map +1 -1
  108. package/dist/middleware/progress-journey.d.ts +1 -1
  109. package/dist/middleware/progress-journey.js +5 -5
  110. package/dist/middleware/progress-journey.js.map +1 -1
  111. package/dist/middleware/sanitise-fields.d.ts +1 -1
  112. package/dist/middleware/sanitise-fields.js +13 -11
  113. package/dist/middleware/sanitise-fields.js.map +1 -1
  114. package/dist/middleware/serve-first-waypoint.d.ts +3 -3
  115. package/dist/middleware/serve-first-waypoint.js +8 -6
  116. package/dist/middleware/serve-first-waypoint.js.map +1 -1
  117. package/dist/middleware/session.js +14 -11
  118. package/dist/middleware/session.js.map +1 -1
  119. package/dist/middleware/skip-waypoint.d.ts +1 -1
  120. package/dist/middleware/skip-waypoint.js +3 -3
  121. package/dist/middleware/skip-waypoint.js.map +1 -1
  122. package/dist/middleware/steer-journey.d.ts +1 -1
  123. package/dist/middleware/steer-journey.js +16 -14
  124. package/dist/middleware/steer-journey.js.map +1 -1
  125. package/dist/middleware/strip-proxy-path.d.ts +1 -1
  126. package/dist/middleware/strip-proxy-path.js +3 -3
  127. package/dist/middleware/strip-proxy-path.js.map +1 -1
  128. package/dist/middleware/validate-fields.d.ts +1 -1
  129. package/dist/middleware/validate-fields.js +2 -5
  130. package/dist/middleware/validate-fields.js.map +1 -1
  131. package/dist/routes/ancillary.d.ts +3 -3
  132. package/dist/routes/ancillary.js +4 -4
  133. package/dist/routes/ancillary.js.map +1 -1
  134. package/dist/routes/journey.d.ts +2 -2
  135. package/dist/routes/journey.js +91 -39
  136. package/dist/routes/journey.js.map +1 -1
  137. package/dist/routes/static.d.ts +7 -5
  138. package/dist/routes/static.js +20 -19
  139. package/dist/routes/static.js.map +1 -1
  140. package/package.json +19 -18
  141. package/src/casa.js +133 -100
  142. package/src/lib/CasaTemplateLoader.js +24 -19
  143. package/src/lib/JourneyContext.js +138 -107
  144. package/src/lib/MutableRouter.js +72 -74
  145. package/src/lib/Plan.js +145 -97
  146. package/src/lib/ValidationError.js +25 -21
  147. package/src/lib/ValidatorFactory.js +17 -13
  148. package/src/lib/configuration-ingestor.js +147 -110
  149. package/src/lib/configure.js +34 -32
  150. package/src/lib/constants.js +9 -11
  151. package/src/lib/context-id-generators.js +40 -43
  152. package/src/lib/end-session.js +6 -6
  153. package/src/lib/field.js +69 -58
  154. package/src/lib/index.js +12 -12
  155. package/src/lib/logger.js +9 -9
  156. package/src/lib/mount.js +70 -74
  157. package/src/lib/nunjucks-filters.js +56 -59
  158. package/src/lib/nunjucks.js +23 -18
  159. package/src/lib/utils.js +78 -57
  160. package/src/lib/validators/dateObject.js +71 -60
  161. package/src/lib/validators/email.js +8 -8
  162. package/src/lib/validators/inArray.js +10 -11
  163. package/src/lib/validators/index.js +12 -14
  164. package/src/lib/validators/nino.js +29 -15
  165. package/src/lib/validators/postalAddressObject.js +87 -63
  166. package/src/lib/validators/range.js +14 -12
  167. package/src/lib/validators/regex.js +8 -8
  168. package/src/lib/validators/required.js +16 -16
  169. package/src/lib/validators/strlen.js +16 -14
  170. package/src/lib/validators/wordCount.js +22 -14
  171. package/src/lib/waypoint-url.js +64 -46
  172. package/src/middleware/body-parser.js +10 -10
  173. package/src/middleware/csrf.js +1 -1
  174. package/src/middleware/data.js +28 -24
  175. package/src/middleware/gather-fields.js +10 -9
  176. package/src/middleware/i18n.js +35 -37
  177. package/src/middleware/post.js +41 -21
  178. package/src/middleware/pre.js +62 -41
  179. package/src/middleware/progress-journey.js +32 -18
  180. package/src/middleware/sanitise-fields.js +43 -20
  181. package/src/middleware/serve-first-waypoint.js +14 -12
  182. package/src/middleware/session.js +74 -61
  183. package/src/middleware/skip-waypoint.js +7 -9
  184. package/src/middleware/steer-journey.js +40 -28
  185. package/src/middleware/strip-proxy-path.js +8 -7
  186. package/src/middleware/validate-fields.js +5 -12
  187. package/src/routes/ancillary.js +5 -7
  188. package/src/routes/journey.js +159 -85
  189. package/src/routes/static.js +62 -29
  190. package/views/casa/components/character-count/README.md +2 -2
  191. package/views/casa/components/checkboxes/README.md +6 -6
  192. package/views/casa/components/date-input/README.md +7 -7
  193. package/views/casa/components/input/README.md +2 -2
  194. package/views/casa/components/journey-form/README.md +33 -14
  195. package/views/casa/components/postal-address-object/README.md +4 -4
  196. package/views/casa/components/radios/README.md +6 -6
  197. package/views/casa/components/select/README.md +6 -6
  198. package/views/casa/components/textarea/README.md +2 -2
  199. package/views/casa/layouts/main.njk +2 -1
@@ -1,24 +1,24 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import ValidationError from '../ValidationError.js';
3
- import ValidatorFactory from '../ValidatorFactory.js';
4
- import { stringifyInput } from '../utils.js';
2
+ import ValidationError from "../ValidationError.js";
3
+ import ValidatorFactory from "../ValidatorFactory.js";
4
+ import { stringifyInput } from "../utils.js";
5
5
 
6
6
  /**
7
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
7
8
  * @access private
8
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
9
9
  */
10
10
 
11
11
  /**
12
12
  * @typedef {object} NinoConfigOptions
13
13
  * @property {ErrorMessageConfig} errorMsg Error message config
14
- * @property {boolean} allowWhitespace Will permit input values that contain spaces.
14
+ * @property {boolean} allowWhitespace Will permit input values that contain
15
+ * spaces.
15
16
  */
16
17
 
17
18
  /**
18
19
  * UK National Insurance number.
19
20
  *
20
- * Ref:
21
- * https://en.wikipedia.org/wiki/National_Insurance_number#Format
21
+ * Ref: https://en.wikipedia.org/wiki/National_Insurance_number#Format
22
22
  * https://design-system.service.gov.uk/patterns/national-insurance-numbers/
23
23
  *
24
24
  * See {@link NinoConfigOptions} for `make()` options.
@@ -27,23 +27,37 @@ import { stringifyInput } from '../utils.js';
27
27
  * @augments ValidatorFactory
28
28
  */
29
29
  export default class Nino extends ValidatorFactory {
30
- name = 'nino';
30
+ name = "nino";
31
31
 
32
32
  validate(value, dataContext = {}) {
33
33
  const {
34
34
  allowWhitespace,
35
35
  errorMsg = {
36
- inline: 'validation:rule.nino.inline',
37
- summary: 'validation:rule.nino.summary',
36
+ inline: "validation:rule.nino.inline",
37
+ summary: "validation:rule.nino.summary",
38
38
  },
39
39
  } = this.config;
40
40
 
41
- if (typeof allowWhitespace !== 'undefined' && typeof allowWhitespace !== 'boolean') {
42
- throw new TypeError(`NINO validation rule option "allowWhitespace" must been a boolean. received ${typeof allowWhitespace}`);
41
+ if (
42
+ typeof allowWhitespace !== "undefined" &&
43
+ typeof allowWhitespace !== "boolean"
44
+ ) {
45
+ throw new TypeError(
46
+ `NINO validation rule option "allowWhitespace" must been a boolean. received ${typeof allowWhitespace}`,
47
+ );
43
48
  }
44
- const valid = typeof value === 'string'
45
- && value.replace((typeof allowWhitespace !== 'undefined' && allowWhitespace) ? /\u0020/g : '', '')
46
- .match(/^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$/i);
49
+ const valid =
50
+ typeof value === "string" &&
51
+ value
52
+ .replace(
53
+ typeof allowWhitespace !== "undefined" && allowWhitespace
54
+ ? /\u0020/g
55
+ : "",
56
+ "",
57
+ )
58
+ .match(
59
+ /^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$/i,
60
+ );
47
61
 
48
62
  return valid ? [] : [ValidationError.make({ errorMsg, dataContext })];
49
63
  }
@@ -1,32 +1,38 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import lodash from 'lodash';
3
- import ValidationError from '../ValidationError.js';
4
- import ValidatorFactory from '../ValidatorFactory.js';
5
- import { stringifyInput } from '../utils.js';
2
+ import lodash from "lodash";
3
+ import ValidationError from "../ValidationError.js";
4
+ import ValidatorFactory from "../ValidatorFactory.js";
5
+ import { stringifyInput } from "../utils.js";
6
6
 
7
7
  const { isPlainObject } = lodash; // CommonjS
8
8
 
9
9
  /**
10
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
10
11
  * @access private
11
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
12
12
  */
13
13
 
14
14
  /**
15
15
  * @typedef {object} PostalAddressObjectConfigOptions
16
- * @property {ErrorMessageConfig} [errorMsg] General error message for the entire address block
17
- * @property {string|object} [errorMsgAddress1] Error message for address1 part
18
- * @property {string|object} [errorMsgAddress2] Error message for address2 part
19
- * @property {string|object} [errorMsgAddress3] Error message for address3 part
20
- * @property {string|object} [errorMsgAddress4] Error message for address4 part
21
- * @property {string|object} [errorMsgPostcode] Error message for postcode part
22
- * @property {number} [strlenmax] Max. String length for each of the inputs address[1-4]
23
- * @property {string[]} [requiredFields] Field parts required (others become optional). One of
24
- * 'address1'|'address2'|'address3'|'address4'|'postcode'
16
+ * @property {ErrorMessageConfig} [errorMsg] General error message for the
17
+ * entire address block
18
+ * @property {string | object} [errorMsgAddress1] Error message for address1
19
+ * part
20
+ * @property {string | object} [errorMsgAddress2] Error message for address2
21
+ * part
22
+ * @property {string | object} [errorMsgAddress3] Error message for address3
23
+ * part
24
+ * @property {string | object} [errorMsgAddress4] Error message for address4
25
+ * part
26
+ * @property {string | object} [errorMsgPostcode] Error message for postcode
27
+ * part
28
+ * @property {number} [strlenmax] Max. String length for each of the inputs
29
+ * address[1-4]
30
+ * @property {string[]} [requiredFields] Field parts required (others become
31
+ * optional). One of 'address1'|'address2'|'address3'|'address4'|'postcode'
25
32
  */
26
33
 
27
34
  /**
28
- * Works hand in hand with the core CASA `postalAddressObject` form
29
- * macro.
35
+ * Works hand in hand with the core CASA `postalAddressObject` form macro.
30
36
  *
31
37
  * The errors sent back from this validator are specific to each subfield. For
32
38
  * example, if the field name being tested is "address", any errors related to
@@ -38,73 +44,84 @@ const { isPlainObject } = lodash; // CommonjS
38
44
  * @augments ValidatorFactory
39
45
  */
40
46
  export default class PostalAddressObject extends ValidatorFactory {
41
- name = 'postalAddressObject';
47
+ name = "postalAddressObject";
42
48
 
43
49
  validate(value, dataContext = {}) {
44
50
  const cfg = {
45
- requiredFields: ['address1', 'address3', 'postcode'],
51
+ requiredFields: ["address1", "address3", "postcode"],
46
52
  strlenmax: undefined,
47
53
  errorMsgAddress1: {
48
- inline: 'validation:rule.postalAddressObject.address1.inline',
49
- summary: 'validation:rule.postalAddressObject.address1.summary',
50
- focusSuffix: '[address1]',
54
+ inline: "validation:rule.postalAddressObject.address1.inline",
55
+ summary: "validation:rule.postalAddressObject.address1.summary",
56
+ focusSuffix: "[address1]",
51
57
  },
52
58
  errorMsgAddress2: {
53
- inline: 'validation:rule.postalAddressObject.address2.inline',
54
- summary: 'validation:rule.postalAddressObject.address2.summary',
55
- focusSuffix: '[address2]',
59
+ inline: "validation:rule.postalAddressObject.address2.inline",
60
+ summary: "validation:rule.postalAddressObject.address2.summary",
61
+ focusSuffix: "[address2]",
56
62
  },
57
63
  errorMsgAddress3: {
58
- inline: 'validation:rule.postalAddressObject.address3.inline',
59
- summary: 'validation:rule.postalAddressObject.address3.summary',
60
- focusSuffix: '[address3]',
64
+ inline: "validation:rule.postalAddressObject.address3.inline",
65
+ summary: "validation:rule.postalAddressObject.address3.summary",
66
+ focusSuffix: "[address3]",
61
67
  },
62
68
  errorMsgAddress4: {
63
- inline: 'validation:rule.postalAddressObject.address4.inline',
64
- summary: 'validation:rule.postalAddressObject.address4.summary',
65
- focusSuffix: '[address4]',
69
+ inline: "validation:rule.postalAddressObject.address4.inline",
70
+ summary: "validation:rule.postalAddressObject.address4.summary",
71
+ focusSuffix: "[address4]",
66
72
  },
67
73
  errorMsgPostcode: {
68
- inline: 'validation:rule.postalAddressObject.postcode.inline',
69
- summary: 'validation:rule.postalAddressObject.postcode.summary',
70
- focusSuffix: '[postcode]',
74
+ inline: "validation:rule.postalAddressObject.postcode.inline",
75
+ summary: "validation:rule.postalAddressObject.postcode.summary",
76
+ focusSuffix: "[postcode]",
71
77
  },
72
78
  errorMsg: {
73
- inline: 'validation:rule.postalAddressObject.group.inline',
74
- summary: 'validation:rule.postalAddressObject.group.summary',
75
- focusSuffix: '[address1]',
79
+ inline: "validation:rule.postalAddressObject.group.inline",
80
+ summary: "validation:rule.postalAddressObject.group.summary",
81
+ focusSuffix: "[address1]",
76
82
  },
77
83
  ...this.config,
78
84
  };
79
85
 
80
86
  /* eslint-disable-next-line require-jsdoc */
81
- const objectifyError = (err) => (typeof err === 'string' ? {
82
- inline: err,
83
- summary: err,
84
- } : err);
87
+ const objectifyError = (err) =>
88
+ typeof err === "string"
89
+ ? {
90
+ inline: err,
91
+ summary: err,
92
+ }
93
+ : err;
85
94
 
86
95
  // Work out required/optional parts based on config
87
96
  const reqF = Object.create(null);
88
97
  const reqC = cfg.requiredFields;
89
- ['address1', 'address2', 'address3', 'address4', 'postcode'].forEach((k) => {
90
- // ESLint disabled as `k` is a known value from a constant list
91
- /* eslint-disable-next-line security/detect-object-injection */
92
- reqF[k] = reqC.indexOf(k) > -1;
93
- });
98
+ ["address1", "address2", "address3", "address4", "postcode"].forEach(
99
+ (k) => {
100
+ // ESLint disabled as `k` is a known value from a constant list
101
+ /* eslint-disable-next-line security/detect-object-injection */
102
+ reqF[k] = reqC.indexOf(k) > -1;
103
+ },
104
+ );
94
105
 
95
106
  let valid = true;
96
107
  const errorMsgs = [];
97
108
 
98
- if (typeof value === 'object') {
109
+ if (typeof value === "object") {
99
110
  const reAddr = /^[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
100
111
  const reAddrLine1 = /^\d+|[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
101
112
  // UK Postcode regex taken from the dwp java pc checker
102
113
  // https://github.com/dwp/postcode-format-validation
103
- const rePostcode = /^(?![QVX])[A-Z]((?![IJZ])[A-Z][0-9](([0-9]?)|([ABEHMNPRVWXY]?))|([0-9]([0-9]?|[ABCDEFGHJKPSTUW]?))) ?[0-9]((?![CIKMOV])[A-Z]){2}$|^(BFPO)[ ]?[0-9]{1,4}$/i;
114
+ const rePostcode =
115
+ /^(?![QVX])[A-Z]((?![IJZ])[A-Z][0-9](([0-9]?)|([ABEHMNPRVWXY]?))|([0-9]([0-9]?|[ABCDEFGHJKPSTUW]?))) ?[0-9]((?![CIKMOV])[A-Z]){2}$|^(BFPO)[ ]?[0-9]{1,4}$/i;
104
116
 
105
117
  // [required, regex, strlenmax, error message]
106
118
  const attributes = {
107
- address1: [reqF.address1, reAddrLine1, cfg.strlenmax, cfg.errorMsgAddress1],
119
+ address1: [
120
+ reqF.address1,
121
+ reAddrLine1,
122
+ cfg.strlenmax,
123
+ cfg.errorMsgAddress1,
124
+ ],
108
125
  address2: [reqF.address2, reAddr, cfg.strlenmax, cfg.errorMsgAddress2],
109
126
  address3: [reqF.address3, reAddr, cfg.strlenmax, cfg.errorMsgAddress3],
110
127
  address4: [reqF.address4, reAddr, cfg.strlenmax, cfg.errorMsgAddress4],
@@ -117,16 +134,18 @@ export default class PostalAddressObject extends ValidatorFactory {
117
134
  const hasProperty = Object.prototype.hasOwnProperty.call(value, k);
118
135
  const hasContent = hasProperty && value[k].length > 0;
119
136
 
120
- const condMissingOrRegexMismatch = (attr[0] || hasContent)
121
- && (!hasProperty || !value[k].match(attr[1]));
122
- const condExceedStrlen = attr[2] > 0 && hasContent
123
- && String(value[k]).length > attr[2];
137
+ const condMissingOrRegexMismatch =
138
+ (attr[0] || hasContent) && (!hasProperty || !value[k].match(attr[1]));
139
+ const condExceedStrlen =
140
+ attr[2] > 0 && hasContent && String(value[k]).length > attr[2];
124
141
 
125
142
  if (condMissingOrRegexMismatch || condExceedStrlen) {
126
143
  valid = false;
127
- errorMsgs.push(Object.assign(Object.create(null), objectifyError(attr[3]), {
128
- fieldKeySuffix: `[${k}]`,
129
- }));
144
+ errorMsgs.push(
145
+ Object.assign(Object.create(null), objectifyError(attr[3]), {
146
+ fieldKeySuffix: `[${k}]`,
147
+ }),
148
+ );
130
149
  }
131
150
  });
132
151
  /* eslint-enable security/detect-object-injection */
@@ -136,8 +155,9 @@ export default class PostalAddressObject extends ValidatorFactory {
136
155
  }
137
156
 
138
157
  // Build ValidationErrorGroup
139
- const errorGroup = errorMsgs.map((err) => (
140
- ValidationError.make({ errorMsg: err, dataContext })));
158
+ const errorGroup = errorMsgs.map((err) =>
159
+ ValidationError.make({ errorMsg: err, dataContext }),
160
+ );
141
161
 
142
162
  return valid ? [] : [...errorGroup];
143
163
  }
@@ -149,13 +169,17 @@ export default class PostalAddressObject extends ValidatorFactory {
149
169
  }
150
170
 
151
171
  // Prune unrecognised attributes, and coerce to Strings
152
- const validKeys = ['address1', 'address2', 'address3', 'address4', 'postcode'];
172
+ const validKeys = [
173
+ "address1",
174
+ "address2",
175
+ "address3",
176
+ "address4",
177
+ "postcode",
178
+ ];
153
179
  const pruned = Object.fromEntries(
154
- Object.entries(value).filter(
155
- ([k]) => (validKeys.includes(k)),
156
- ).map(
157
- ([k, v]) => ([k, stringifyInput(v)]),
158
- ),
180
+ Object.entries(value)
181
+ .filter(([k]) => validKeys.includes(k))
182
+ .map(([k, v]) => [k, stringifyInput(v)]),
159
183
  );
160
184
  return Object.assign(Object.create(null), pruned);
161
185
  }
@@ -1,18 +1,20 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
 
3
- import ValidatorFactory from '../ValidatorFactory.js';
4
- import ValidationError from '../ValidationError.js';
5
- import { coerceInputToInteger } from '../utils.js';
3
+ import ValidatorFactory from "../ValidatorFactory.js";
4
+ import ValidationError from "../ValidationError.js";
5
+ import { coerceInputToInteger } from "../utils.js";
6
6
 
7
7
  /**
8
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
8
9
  * @access private
9
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
10
10
  */
11
11
 
12
12
  /**
13
13
  * @typedef {object} RangeConfigOptions
14
- * @property {ErrorMessageConfig} errorMsgMax Error message to use on max failure
15
- * @property {ErrorMessageConfig} errorMsgMin Error message to use on min failure
14
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max
15
+ * failure
16
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min
17
+ * failure
16
18
  * @property {number} max Maximum integer value
17
19
  * @property {number} min Minimum integer value
18
20
  */
@@ -26,17 +28,17 @@ import { coerceInputToInteger } from '../utils.js';
26
28
  * @augments ValidatorFactory
27
29
  */
28
30
  export default class Range extends ValidatorFactory {
29
- name = 'range';
31
+ name = "range";
30
32
 
31
33
  validate(inputValue, dataContext = {}) {
32
34
  const {
33
35
  errorMsgMax = {
34
- inline: 'validation:rule.range.max.inline',
35
- summary: 'validation:rule.range.max.summary',
36
+ inline: "validation:rule.range.max.inline",
37
+ summary: "validation:rule.range.max.summary",
36
38
  },
37
39
  errorMsgMin = {
38
- inline: 'validation:rule.range.min.inline',
39
- summary: 'validation:rule.range.min.summary',
40
+ inline: "validation:rule.range.min.inline",
41
+ summary: "validation:rule.range.min.summary",
40
42
  },
41
43
  min = Number.MIN_VALUE,
42
44
  max = Number.MAX_VALUE,
@@ -61,7 +63,7 @@ export default class Range extends ValidatorFactory {
61
63
  sanitise(value) {
62
64
  // treat an empty string as undefined
63
65
  // when user submits empty form, it stores an empty string
64
- if (value !== '' && value !== undefined) {
66
+ if (value !== "" && value !== undefined) {
65
67
  // add to custom validator docs to ensure not to return a falsy value as
66
68
  // it doesn't show on screen
67
69
  return coerceInputToInteger(value)?.toString();
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
2
+ import ValidatorFactory from "../ValidatorFactory.js";
3
+ import ValidationError from "../ValidationError.js";
4
+ import { stringifyInput } from "../utils.js";
5
5
 
6
6
  /**
7
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
7
8
  * @access private
8
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
9
9
  */
10
10
 
11
11
  /**
@@ -24,16 +24,16 @@ import { stringifyInput } from '../utils.js';
24
24
  * @augments ValidatorFactory
25
25
  */
26
26
  export default class Regex extends ValidatorFactory {
27
- name = 'regex';
27
+ name = "regex";
28
28
 
29
- validate(value = '', dataContext = {}) {
29
+ validate(value = "", dataContext = {}) {
30
30
  const invert = this.config.invert || false;
31
31
  const match = value.match(this.config.pattern || /.*/);
32
32
  const valid = invert ? !match : match;
33
33
 
34
34
  const errorMsg = this.config.errorMsg || {
35
- inline: 'validation:rule.regex.inline',
36
- summary: 'validation:rule.regex.summary',
35
+ inline: "validation:rule.regex.inline",
36
+ summary: "validation:rule.regex.summary",
37
37
  };
38
38
 
39
39
  return valid ? [] : [ValidationError.make({ errorMsg, dataContext })];
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import lodash from 'lodash';
3
- import { isEmpty, isStringable, stringifyInput } from '../utils.js';
4
- import ValidatorFactory from '../ValidatorFactory.js';
5
- import ValidationError from '../ValidationError.js';
2
+ import lodash from "lodash";
3
+ import { isEmpty, isStringable, stringifyInput } from "../utils.js";
4
+ import ValidatorFactory from "../ValidatorFactory.js";
5
+ import ValidationError from "../ValidationError.js";
6
6
 
7
7
  const { isPlainObject } = lodash; // CommonJS
8
8
 
9
9
  /**
10
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
10
11
  * @access private
11
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
12
12
  */
13
13
 
14
14
  /**
@@ -19,8 +19,8 @@ const { isPlainObject } = lodash; // CommonJS
19
19
  /**
20
20
  * Test if value is present.
21
21
  *
22
- * Value is required. The following values will fail this rule:
23
- * (all values that satisfy `isEmpty()`) plus '\s'
22
+ * Value is required. The following values will fail this rule: (all values that
23
+ * satisfy `isEmpty()`) plus '\s'
24
24
  *
25
25
  * See {@link RequiredConfigOptions} for `make()` options.
26
26
  *
@@ -28,29 +28,27 @@ const { isPlainObject } = lodash; // CommonJS
28
28
  * @augments ValidatorFactory
29
29
  */
30
30
  export default class Required extends ValidatorFactory {
31
- name = 'required';
31
+ name = "required";
32
32
 
33
33
  validate(value, dataContext = {}) {
34
34
  const {
35
35
  errorMsg = {
36
- inline: 'validation:rule.required.inline',
37
- summary: 'validation:rule.required.summary',
36
+ inline: "validation:rule.required.inline",
37
+ summary: "validation:rule.required.summary",
38
38
  },
39
39
  } = this.config;
40
40
 
41
41
  if (!isEmpty(value)) {
42
- return []
42
+ return [];
43
43
  }
44
44
 
45
- return [
46
- ValidationError.make({ errorMsg, dataContext }),
47
- ];
45
+ return [ValidationError.make({ errorMsg, dataContext })];
48
46
  }
49
47
 
50
48
  sanitise(value) {
51
49
  const coerce = (val) => {
52
50
  const s = stringifyInput(val, undefined);
53
- return s === undefined ? undefined : s.replace(/^\s+$/, '');
51
+ return s === undefined ? undefined : s.replace(/^\s+$/, "");
54
52
  };
55
53
 
56
54
  if (isStringable(value)) {
@@ -66,7 +64,9 @@ export default class Required extends ValidatorFactory {
66
64
  // Coerce all elements to Strings.
67
65
  // This only supports a one dimensional object, with stringable elements.
68
66
  if (isPlainObject(value)) {
69
- return Object.fromEntries(Object.entries(value).map(([k, v]) => ([k, coerce(v)])));
67
+ return Object.fromEntries(
68
+ Object.entries(value).map(([k, v]) => [k, coerce(v)]),
69
+ );
70
70
  }
71
71
 
72
72
  return undefined;
@@ -1,17 +1,19 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
2
+ import ValidatorFactory from "../ValidatorFactory.js";
3
+ import ValidationError from "../ValidationError.js";
4
+ import { stringifyInput } from "../utils.js";
5
5
 
6
6
  /**
7
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
7
8
  * @access private
8
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
9
9
  */
10
10
 
11
11
  /**
12
12
  * @typedef {object} StrlenConfigOptions
13
- * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
14
- * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
13
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
14
+ * failure
15
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
16
+ * failure
15
17
  * @property {number} max Maximum string length allowed
16
18
  * @property {number} min Minimum string length required
17
19
  */
@@ -25,17 +27,17 @@ import { stringifyInput } from '../utils.js';
25
27
  * @augments ValidatorFactory
26
28
  */
27
29
  export default class Strlen extends ValidatorFactory {
28
- name = 'strlen';
30
+ name = "strlen";
29
31
 
30
- validate(inputValue = '', dataContext = {}) {
32
+ validate(inputValue = "", dataContext = {}) {
31
33
  const {
32
34
  errorMsgMax = {
33
- inline: 'validation:rule.strlen.max.inline',
34
- summary: 'validation:rule.strlen.max.summary',
35
+ inline: "validation:rule.strlen.max.inline",
36
+ summary: "validation:rule.strlen.max.summary",
35
37
  },
36
38
  errorMsgMin = {
37
- inline: 'validation:rule.strlen.min.inline',
38
- summary: 'validation:rule.strlen.min.summary',
39
+ inline: "validation:rule.strlen.min.inline",
40
+ summary: "validation:rule.strlen.min.summary",
39
41
  },
40
42
  min,
41
43
  max,
@@ -44,12 +46,12 @@ export default class Strlen extends ValidatorFactory {
44
46
  let errorMsg;
45
47
  let valid = true;
46
48
 
47
- if (typeof max !== 'undefined' && inputValue.length > max) {
49
+ if (typeof max !== "undefined" && inputValue.length > max) {
48
50
  valid = false;
49
51
  errorMsg = errorMsgMax;
50
52
  }
51
53
 
52
- if (typeof min !== 'undefined' && inputValue.length < min) {
54
+ if (typeof min !== "undefined" && inputValue.length < min) {
53
55
  valid = false;
54
56
  errorMsg = errorMsgMin;
55
57
  }
@@ -1,17 +1,19 @@
1
1
  /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
2
+ import ValidatorFactory from "../ValidatorFactory.js";
3
+ import ValidationError from "../ValidationError.js";
4
+ import { stringifyInput } from "../utils.js";
5
5
 
6
6
  /**
7
+ * @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
7
8
  * @access private
8
- * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
9
9
  */
10
10
 
11
11
  /**
12
12
  * @typedef {object} WordcountConfigOptions
13
- * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
14
- * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
13
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length
14
+ * failure
15
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length
16
+ * failure
15
17
  * @property {number} max Maximum string length allowed
16
18
  * @property {number} min Minimum string length required
17
19
  */
@@ -25,21 +27,21 @@ import { stringifyInput } from '../utils.js';
25
27
  * @augments ValidatorFactory
26
28
  */
27
29
  export default class WordCount extends ValidatorFactory {
28
- name = 'wordCount';
30
+ name = "wordCount";
29
31
 
30
32
  count(input) {
31
33
  return (input.match(/\S+/g) || []).length;
32
34
  }
33
35
 
34
- validate(inputValue = '', dataContext = {}) {
36
+ validate(inputValue = "", dataContext = {}) {
35
37
  const {
36
38
  errorMsgMax = {
37
- inline: 'validation:rule.wordCount.max.inline',
38
- summary: 'validation:rule.wordCount.max.summary',
39
+ inline: "validation:rule.wordCount.max.inline",
40
+ summary: "validation:rule.wordCount.max.summary",
39
41
  },
40
42
  errorMsgMin = {
41
- inline: 'validation:rule.wordCount.min.inline',
42
- summary: 'validation:rule.wordCount.min.summary',
43
+ inline: "validation:rule.wordCount.min.inline",
44
+ summary: "validation:rule.wordCount.min.summary",
43
45
  },
44
46
  min,
45
47
  max,
@@ -48,12 +50,18 @@ export default class WordCount extends ValidatorFactory {
48
50
  let errorMsg;
49
51
  let valid = true;
50
52
 
51
- if (typeof max !== 'undefined' && (inputValue.match(/\S+/g) || []).length > max) {
53
+ if (
54
+ typeof max !== "undefined" &&
55
+ (inputValue.match(/\S+/g) || []).length > max
56
+ ) {
52
57
  valid = false;
53
58
  errorMsg = errorMsgMax;
54
59
  }
55
60
 
56
- if (typeof min !== 'undefined' && (inputValue.match(/\S+/g) || []).length < min) {
61
+ if (
62
+ typeof min !== "undefined" &&
63
+ (inputValue.match(/\S+/g) || []).length < min
64
+ ) {
57
65
  valid = false;
58
66
  errorMsg = errorMsgMin;
59
67
  }