@dineroregnskab/eslint-plugin-custom-rules 2.0.6 → 2.0.7

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 (174) hide show
  1. package/eslint-plugin-custom-rules.js +2 -0
  2. package/package.json +1 -1
  3. package/node_modules/@aashutoshrathi/word-wrap/LICENSE +0 -21
  4. package/node_modules/@aashutoshrathi/word-wrap/README.md +0 -182
  5. package/node_modules/@aashutoshrathi/word-wrap/index.d.ts +0 -50
  6. package/node_modules/@aashutoshrathi/word-wrap/index.js +0 -52
  7. package/node_modules/@aashutoshrathi/word-wrap/package.json +0 -81
  8. package/node_modules/@angular-eslint/bundled-angular-compiler/README.md +0 -1
  9. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.d.ts +0 -5
  10. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.js +0 -32004
  11. package/node_modules/@angular-eslint/bundled-angular-compiler/package.json +0 -19
  12. package/node_modules/@angular-eslint/template-parser/LICENSE +0 -21
  13. package/node_modules/@angular-eslint/template-parser/README.md +0 -1
  14. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.d.ts +0 -6
  15. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.js +0 -69
  16. package/node_modules/@angular-eslint/template-parser/dist/index.d.ts +0 -44
  17. package/node_modules/@angular-eslint/template-parser/dist/index.js +0 -219
  18. package/node_modules/@angular-eslint/template-parser/package.json +0 -28
  19. package/node_modules/@eslint/eslintrc/LICENSE +0 -19
  20. package/node_modules/@eslint/eslintrc/README.md +0 -115
  21. package/node_modules/@eslint/eslintrc/conf/config-schema.js +0 -79
  22. package/node_modules/@eslint/eslintrc/conf/environments.js +0 -215
  23. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +0 -1104
  24. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +0 -1
  25. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +0 -4333
  26. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +0 -1
  27. package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +0 -532
  28. package/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +0 -523
  29. package/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +0 -115
  30. package/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +0 -145
  31. package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +0 -238
  32. package/node_modules/@eslint/eslintrc/lib/config-array/index.js +0 -19
  33. package/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +0 -225
  34. package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +0 -1149
  35. package/node_modules/@eslint/eslintrc/lib/flat-compat.js +0 -318
  36. package/node_modules/@eslint/eslintrc/lib/index-universal.js +0 -29
  37. package/node_modules/@eslint/eslintrc/lib/index.js +0 -56
  38. package/node_modules/@eslint/eslintrc/lib/shared/ajv.js +0 -191
  39. package/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +0 -135
  40. package/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +0 -325
  41. package/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +0 -63
  42. package/node_modules/@eslint/eslintrc/lib/shared/naming.js +0 -96
  43. package/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +0 -42
  44. package/node_modules/@eslint/eslintrc/lib/shared/types.js +0 -149
  45. package/node_modules/@eslint/eslintrc/package.json +0 -82
  46. package/node_modules/@eslint/eslintrc/universal.js +0 -9
  47. package/node_modules/@eslint/js/LICENSE +0 -19
  48. package/node_modules/@eslint/js/README.md +0 -57
  49. package/node_modules/@eslint/js/package.json +0 -31
  50. package/node_modules/@eslint/js/src/configs/eslint-all.js +0 -211
  51. package/node_modules/@eslint/js/src/configs/eslint-recommended.js +0 -76
  52. package/node_modules/@eslint/js/src/index.js +0 -17
  53. package/node_modules/@eslint-community/eslint-utils/LICENSE +0 -21
  54. package/node_modules/@eslint-community/eslint-utils/README.md +0 -37
  55. package/node_modules/@eslint-community/eslint-utils/index.js +0 -2068
  56. package/node_modules/@eslint-community/eslint-utils/index.js.map +0 -1
  57. package/node_modules/@eslint-community/eslint-utils/index.mjs +0 -2027
  58. package/node_modules/@eslint-community/eslint-utils/index.mjs.map +0 -1
  59. package/node_modules/@eslint-community/eslint-utils/package.json +0 -73
  60. package/node_modules/@eslint-community/regexpp/LICENSE +0 -21
  61. package/node_modules/@eslint-community/regexpp/README.md +0 -177
  62. package/node_modules/@eslint-community/regexpp/index.d.ts +0 -1065
  63. package/node_modules/@eslint-community/regexpp/index.js +0 -2747
  64. package/node_modules/@eslint-community/regexpp/index.js.map +0 -1
  65. package/node_modules/@eslint-community/regexpp/index.mjs +0 -2737
  66. package/node_modules/@eslint-community/regexpp/index.mjs.map +0 -1
  67. package/node_modules/@eslint-community/regexpp/package.json +0 -93
  68. package/node_modules/@humanwhocodes/config-array/LICENSE +0 -201
  69. package/node_modules/@humanwhocodes/config-array/README.md +0 -342
  70. package/node_modules/@humanwhocodes/config-array/api.js +0 -1061
  71. package/node_modules/@humanwhocodes/config-array/package.json +0 -61
  72. package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +0 -15
  73. package/node_modules/@humanwhocodes/module-importer/LICENSE +0 -201
  74. package/node_modules/@humanwhocodes/module-importer/README.md +0 -80
  75. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.cjs +0 -22
  76. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.cts +0 -27
  77. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.ts +0 -2
  78. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.js +0 -18
  79. package/node_modules/@humanwhocodes/module-importer/package.json +0 -65
  80. package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +0 -81
  81. package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +0 -22
  82. package/node_modules/@humanwhocodes/object-schema/.eslintrc.js +0 -29
  83. package/node_modules/@humanwhocodes/object-schema/.github/workflows/nodejs-test.yml +0 -27
  84. package/node_modules/@humanwhocodes/object-schema/.github/workflows/release-please.yml +0 -39
  85. package/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +0 -26
  86. package/node_modules/@humanwhocodes/object-schema/LICENSE +0 -29
  87. package/node_modules/@humanwhocodes/object-schema/README.md +0 -234
  88. package/node_modules/@humanwhocodes/object-schema/package.json +0 -33
  89. package/node_modules/@humanwhocodes/object-schema/src/index.js +0 -7
  90. package/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +0 -53
  91. package/node_modules/@humanwhocodes/object-schema/src/object-schema.js +0 -301
  92. package/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +0 -102
  93. package/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +0 -66
  94. package/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +0 -659
  95. package/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +0 -186
  96. package/node_modules/@nodelib/fs.scandir/LICENSE +0 -21
  97. package/node_modules/@nodelib/fs.scandir/README.md +0 -171
  98. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +0 -20
  99. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +0 -19
  100. package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +0 -4
  101. package/node_modules/@nodelib/fs.scandir/out/constants.js +0 -17
  102. package/node_modules/@nodelib/fs.scandir/out/index.d.ts +0 -12
  103. package/node_modules/@nodelib/fs.scandir/out/index.js +0 -26
  104. package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +0 -7
  105. package/node_modules/@nodelib/fs.scandir/out/providers/async.js +0 -104
  106. package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +0 -1
  107. package/node_modules/@nodelib/fs.scandir/out/providers/common.js +0 -13
  108. package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +0 -5
  109. package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +0 -54
  110. package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +0 -20
  111. package/node_modules/@nodelib/fs.scandir/out/settings.js +0 -24
  112. package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +0 -20
  113. package/node_modules/@nodelib/fs.scandir/out/types/index.js +0 -2
  114. package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +0 -2
  115. package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +0 -19
  116. package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +0 -2
  117. package/node_modules/@nodelib/fs.scandir/out/utils/index.js +0 -5
  118. package/node_modules/@nodelib/fs.scandir/package.json +0 -44
  119. package/node_modules/@nodelib/fs.stat/LICENSE +0 -21
  120. package/node_modules/@nodelib/fs.stat/README.md +0 -126
  121. package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +0 -13
  122. package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +0 -17
  123. package/node_modules/@nodelib/fs.stat/out/index.d.ts +0 -12
  124. package/node_modules/@nodelib/fs.stat/out/index.js +0 -26
  125. package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +0 -4
  126. package/node_modules/@nodelib/fs.stat/out/providers/async.js +0 -36
  127. package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +0 -3
  128. package/node_modules/@nodelib/fs.stat/out/providers/sync.js +0 -23
  129. package/node_modules/@nodelib/fs.stat/out/settings.d.ts +0 -16
  130. package/node_modules/@nodelib/fs.stat/out/settings.js +0 -16
  131. package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +0 -4
  132. package/node_modules/@nodelib/fs.stat/out/types/index.js +0 -2
  133. package/node_modules/@nodelib/fs.stat/package.json +0 -37
  134. package/node_modules/@nodelib/fs.walk/LICENSE +0 -21
  135. package/node_modules/@nodelib/fs.walk/README.md +0 -215
  136. package/node_modules/@nodelib/fs.walk/out/index.d.ts +0 -14
  137. package/node_modules/@nodelib/fs.walk/out/index.js +0 -34
  138. package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +0 -12
  139. package/node_modules/@nodelib/fs.walk/out/providers/async.js +0 -30
  140. package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +0 -4
  141. package/node_modules/@nodelib/fs.walk/out/providers/index.js +0 -9
  142. package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +0 -12
  143. package/node_modules/@nodelib/fs.walk/out/providers/stream.js +0 -34
  144. package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +0 -10
  145. package/node_modules/@nodelib/fs.walk/out/providers/sync.js +0 -14
  146. package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +0 -30
  147. package/node_modules/@nodelib/fs.walk/out/readers/async.js +0 -97
  148. package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +0 -7
  149. package/node_modules/@nodelib/fs.walk/out/readers/common.js +0 -31
  150. package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +0 -6
  151. package/node_modules/@nodelib/fs.walk/out/readers/reader.js +0 -11
  152. package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +0 -15
  153. package/node_modules/@nodelib/fs.walk/out/readers/sync.js +0 -59
  154. package/node_modules/@nodelib/fs.walk/out/settings.d.ts +0 -30
  155. package/node_modules/@nodelib/fs.walk/out/settings.js +0 -26
  156. package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +0 -8
  157. package/node_modules/@nodelib/fs.walk/out/types/index.js +0 -2
  158. package/node_modules/@nodelib/fs.walk/package.json +0 -44
  159. package/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +0 -31
  160. package/node_modules/@ungap/structured-clone/LICENSE +0 -15
  161. package/node_modules/@ungap/structured-clone/README.md +0 -95
  162. package/node_modules/@ungap/structured-clone/cjs/deserialize.js +0 -78
  163. package/node_modules/@ungap/structured-clone/cjs/index.js +0 -27
  164. package/node_modules/@ungap/structured-clone/cjs/json.js +0 -24
  165. package/node_modules/@ungap/structured-clone/cjs/package.json +0 -1
  166. package/node_modules/@ungap/structured-clone/cjs/serialize.js +0 -160
  167. package/node_modules/@ungap/structured-clone/cjs/types.js +0 -22
  168. package/node_modules/@ungap/structured-clone/esm/deserialize.js +0 -79
  169. package/node_modules/@ungap/structured-clone/esm/index.js +0 -25
  170. package/node_modules/@ungap/structured-clone/esm/json.js +0 -21
  171. package/node_modules/@ungap/structured-clone/esm/serialize.js +0 -161
  172. package/node_modules/@ungap/structured-clone/esm/types.js +0 -11
  173. package/node_modules/@ungap/structured-clone/package.json +0 -53
  174. package/node_modules/@ungap/structured-clone/structured-json.js +0 -1
@@ -1,301 +0,0 @@
1
- /**
2
- * @filedescription Object Schema
3
- */
4
-
5
- "use strict";
6
-
7
- //-----------------------------------------------------------------------------
8
- // Requirements
9
- //-----------------------------------------------------------------------------
10
-
11
- const { MergeStrategy } = require("./merge-strategy");
12
- const { ValidationStrategy } = require("./validation-strategy");
13
-
14
- //-----------------------------------------------------------------------------
15
- // Private
16
- //-----------------------------------------------------------------------------
17
-
18
- const strategies = Symbol("strategies");
19
- const requiredKeys = Symbol("requiredKeys");
20
-
21
- /**
22
- * Validates a schema strategy.
23
- * @param {string} name The name of the key this strategy is for.
24
- * @param {Object} strategy The strategy for the object key.
25
- * @param {boolean} [strategy.required=true] Whether the key is required.
26
- * @param {string[]} [strategy.requires] Other keys that are required when
27
- * this key is present.
28
- * @param {Function} strategy.merge A method to call when merging two objects
29
- * with the same key.
30
- * @param {Function} strategy.validate A method to call when validating an
31
- * object with the key.
32
- * @returns {void}
33
- * @throws {Error} When the strategy is missing a name.
34
- * @throws {Error} When the strategy is missing a merge() method.
35
- * @throws {Error} When the strategy is missing a validate() method.
36
- */
37
- function validateDefinition(name, strategy) {
38
-
39
- let hasSchema = false;
40
- if (strategy.schema) {
41
- if (typeof strategy.schema === "object") {
42
- hasSchema = true;
43
- } else {
44
- throw new TypeError("Schema must be an object.");
45
- }
46
- }
47
-
48
- if (typeof strategy.merge === "string") {
49
- if (!(strategy.merge in MergeStrategy)) {
50
- throw new TypeError(`Definition for key "${name}" missing valid merge strategy.`);
51
- }
52
- } else if (!hasSchema && typeof strategy.merge !== "function") {
53
- throw new TypeError(`Definition for key "${name}" must have a merge property.`);
54
- }
55
-
56
- if (typeof strategy.validate === "string") {
57
- if (!(strategy.validate in ValidationStrategy)) {
58
- throw new TypeError(`Definition for key "${name}" missing valid validation strategy.`);
59
- }
60
- } else if (!hasSchema && typeof strategy.validate !== "function") {
61
- throw new TypeError(`Definition for key "${name}" must have a validate() method.`);
62
- }
63
- }
64
-
65
- //-----------------------------------------------------------------------------
66
- // Errors
67
- //-----------------------------------------------------------------------------
68
-
69
- /**
70
- * Error when an unexpected key is found.
71
- */
72
- class UnexpectedKeyError extends Error {
73
-
74
- /**
75
- * Creates a new instance.
76
- * @param {string} key The key that was unexpected.
77
- */
78
- constructor(key) {
79
- super(`Unexpected key "${key}" found.`);
80
- }
81
- }
82
-
83
- /**
84
- * Error when a required key is missing.
85
- */
86
- class MissingKeyError extends Error {
87
-
88
- /**
89
- * Creates a new instance.
90
- * @param {string} key The key that was missing.
91
- */
92
- constructor(key) {
93
- super(`Missing required key "${key}".`);
94
- }
95
- }
96
-
97
- /**
98
- * Error when a key requires other keys that are missing.
99
- */
100
- class MissingDependentKeysError extends Error {
101
-
102
- /**
103
- * Creates a new instance.
104
- * @param {string} key The key that was unexpected.
105
- * @param {Array<string>} requiredKeys The keys that are required.
106
- */
107
- constructor(key, requiredKeys) {
108
- super(`Key "${key}" requires keys "${requiredKeys.join("\", \"")}".`);
109
- }
110
- }
111
-
112
- /**
113
- * Wrapper error for errors occuring during a merge or validate operation.
114
- */
115
- class WrapperError {
116
-
117
- /**
118
- * Creates a new instance.
119
- * @param {string} key The object key causing the error.
120
- * @param {Error} source The source error.
121
- */
122
- constructor(key, source) {
123
- return Object.create(source, {
124
- message: {
125
- value: `Key "${key}": ` + source.message,
126
- configurable: true,
127
- writable: true,
128
- enumerable: true
129
- }
130
- });
131
- }
132
- }
133
-
134
- //-----------------------------------------------------------------------------
135
- // Main
136
- //-----------------------------------------------------------------------------
137
-
138
- /**
139
- * Represents an object validation/merging schema.
140
- */
141
- class ObjectSchema {
142
-
143
- /**
144
- * Creates a new instance.
145
- */
146
- constructor(definitions) {
147
-
148
- if (!definitions) {
149
- throw new Error("Schema definitions missing.");
150
- }
151
-
152
- /**
153
- * Track all strategies in the schema by key.
154
- * @type {Map}
155
- * @property strategies
156
- */
157
- this[strategies] = new Map();
158
-
159
- /**
160
- * Separately track any keys that are required for faster validation.
161
- * @type {Map}
162
- * @property requiredKeys
163
- */
164
- this[requiredKeys] = new Map();
165
-
166
- // add in all strategies
167
- for (const key of Object.keys(definitions)) {
168
- validateDefinition(key, definitions[key]);
169
-
170
- // normalize merge and validate methods if subschema is present
171
- if (typeof definitions[key].schema === "object") {
172
- const schema = new ObjectSchema(definitions[key].schema);
173
- definitions[key] = {
174
- ...definitions[key],
175
- merge(first = {}, second = {}) {
176
- return schema.merge(first, second);
177
- },
178
- validate(value) {
179
- ValidationStrategy.object(value);
180
- schema.validate(value);
181
- }
182
- };
183
- }
184
-
185
- // normalize the merge method in case there's a string
186
- if (typeof definitions[key].merge === "string") {
187
- definitions[key] = {
188
- ...definitions[key],
189
- merge: MergeStrategy[definitions[key].merge]
190
- };
191
- };
192
-
193
- // normalize the validate method in case there's a string
194
- if (typeof definitions[key].validate === "string") {
195
- definitions[key] = {
196
- ...definitions[key],
197
- validate: ValidationStrategy[definitions[key].validate]
198
- };
199
- };
200
-
201
- this[strategies].set(key, definitions[key]);
202
-
203
- if (definitions[key].required) {
204
- this[requiredKeys].set(key, definitions[key]);
205
- }
206
- }
207
- }
208
-
209
- /**
210
- * Determines if a strategy has been registered for the given object key.
211
- * @param {string} key The object key to find a strategy for.
212
- * @returns {boolean} True if the key has a strategy registered, false if not.
213
- */
214
- hasKey(key) {
215
- return this[strategies].has(key);
216
- }
217
-
218
- /**
219
- * Merges objects together to create a new object comprised of the keys
220
- * of the all objects. Keys are merged based on the each key's merge
221
- * strategy.
222
- * @param {...Object} objects The objects to merge.
223
- * @returns {Object} A new object with a mix of all objects' keys.
224
- * @throws {Error} If any object is invalid.
225
- */
226
- merge(...objects) {
227
-
228
- // double check arguments
229
- if (objects.length < 2) {
230
- throw new TypeError("merge() requires at least two arguments.");
231
- }
232
-
233
- if (objects.some(object => (object == null || typeof object !== "object"))) {
234
- throw new TypeError("All arguments must be objects.");
235
- }
236
-
237
- return objects.reduce((result, object) => {
238
-
239
- this.validate(object);
240
-
241
- for (const [key, strategy] of this[strategies]) {
242
- try {
243
- if (key in result || key in object) {
244
- const value = strategy.merge.call(this, result[key], object[key]);
245
- if (value !== undefined) {
246
- result[key] = value;
247
- }
248
- }
249
- } catch (ex) {
250
- throw new WrapperError(key, ex);
251
- }
252
- }
253
- return result;
254
- }, {});
255
- }
256
-
257
- /**
258
- * Validates an object's keys based on the validate strategy for each key.
259
- * @param {Object} object The object to validate.
260
- * @returns {void}
261
- * @throws {Error} When the object is invalid.
262
- */
263
- validate(object) {
264
-
265
- // check existing keys first
266
- for (const key of Object.keys(object)) {
267
-
268
- // check to see if the key is defined
269
- if (!this.hasKey(key)) {
270
- throw new UnexpectedKeyError(key);
271
- }
272
-
273
- // validate existing keys
274
- const strategy = this[strategies].get(key);
275
-
276
- // first check to see if any other keys are required
277
- if (Array.isArray(strategy.requires)) {
278
- if (!strategy.requires.every(otherKey => otherKey in object)) {
279
- throw new MissingDependentKeysError(key, strategy.requires);
280
- }
281
- }
282
-
283
- // now apply remaining validation strategy
284
- try {
285
- strategy.validate.call(strategy, object[key]);
286
- } catch (ex) {
287
- throw new WrapperError(key, ex);
288
- }
289
- }
290
-
291
- // ensure required keys aren't missing
292
- for (const [key] of this[requiredKeys]) {
293
- if (!(key in object)) {
294
- throw new MissingKeyError(key);
295
- }
296
- }
297
-
298
- }
299
- }
300
-
301
- exports.ObjectSchema = ObjectSchema;
@@ -1,102 +0,0 @@
1
- /**
2
- * @filedescription Validation Strategy
3
- */
4
-
5
- "use strict";
6
-
7
- //-----------------------------------------------------------------------------
8
- // Class
9
- //-----------------------------------------------------------------------------
10
-
11
- /**
12
- * Container class for several different validation strategies.
13
- */
14
- class ValidationStrategy {
15
-
16
- /**
17
- * Validates that a value is an array.
18
- * @param {*} value The value to validate.
19
- * @returns {void}
20
- * @throws {TypeError} If the value is invalid.
21
- */
22
- static array(value) {
23
- if (!Array.isArray(value)) {
24
- throw new TypeError("Expected an array.");
25
- }
26
- }
27
-
28
- /**
29
- * Validates that a value is a boolean.
30
- * @param {*} value The value to validate.
31
- * @returns {void}
32
- * @throws {TypeError} If the value is invalid.
33
- */
34
- static boolean(value) {
35
- if (typeof value !== "boolean") {
36
- throw new TypeError("Expected a Boolean.");
37
- }
38
- }
39
-
40
- /**
41
- * Validates that a value is a number.
42
- * @param {*} value The value to validate.
43
- * @returns {void}
44
- * @throws {TypeError} If the value is invalid.
45
- */
46
- static number(value) {
47
- if (typeof value !== "number") {
48
- throw new TypeError("Expected a number.");
49
- }
50
- }
51
-
52
- /**
53
- * Validates that a value is a object.
54
- * @param {*} value The value to validate.
55
- * @returns {void}
56
- * @throws {TypeError} If the value is invalid.
57
- */
58
- static object(value) {
59
- if (!value || typeof value !== "object") {
60
- throw new TypeError("Expected an object.");
61
- }
62
- }
63
-
64
- /**
65
- * Validates that a value is a object or null.
66
- * @param {*} value The value to validate.
67
- * @returns {void}
68
- * @throws {TypeError} If the value is invalid.
69
- */
70
- static "object?"(value) {
71
- if (typeof value !== "object") {
72
- throw new TypeError("Expected an object or null.");
73
- }
74
- }
75
-
76
- /**
77
- * Validates that a value is a string.
78
- * @param {*} value The value to validate.
79
- * @returns {void}
80
- * @throws {TypeError} If the value is invalid.
81
- */
82
- static string(value) {
83
- if (typeof value !== "string") {
84
- throw new TypeError("Expected a string.");
85
- }
86
- }
87
-
88
- /**
89
- * Validates that a value is a non-empty string.
90
- * @param {*} value The value to validate.
91
- * @returns {void}
92
- * @throws {TypeError} If the value is invalid.
93
- */
94
- static "string!"(value) {
95
- if (typeof value !== "string" || value.length === 0) {
96
- throw new TypeError("Expected a non-empty string.");
97
- }
98
- }
99
-
100
- }
101
-
102
- exports.ValidationStrategy = ValidationStrategy;
@@ -1,66 +0,0 @@
1
- /**
2
- * @filedescription Merge Strategy Tests
3
- */
4
- /* global it, describe, beforeEach */
5
-
6
- "use strict";
7
-
8
- //-----------------------------------------------------------------------------
9
- // Requirements
10
- //-----------------------------------------------------------------------------
11
-
12
- const assert = require("chai").assert;
13
- const { MergeStrategy } = require("../src/");
14
-
15
- //-----------------------------------------------------------------------------
16
- // Class
17
- //-----------------------------------------------------------------------------
18
-
19
- describe("MergeStrategy", () => {
20
-
21
-
22
- describe("overwrite()", () => {
23
-
24
- it("should overwrite the first value with the second when the second is defined", () => {
25
- const result = MergeStrategy.overwrite(1, 2);
26
- assert.strictEqual(result, 2);
27
- });
28
-
29
- it("should overwrite the first value with the second when the second is undefined", () => {
30
- const result = MergeStrategy.overwrite(1, undefined);
31
- assert.strictEqual(result, undefined);
32
- });
33
-
34
- });
35
-
36
- describe("replace()", () => {
37
-
38
- it("should overwrite the first value with the second when the second is defined", () => {
39
- const result = MergeStrategy.replace(1, 2);
40
- assert.strictEqual(result, 2);
41
- });
42
-
43
- it("should return the first value when the second is undefined", () => {
44
- const result = MergeStrategy.replace(1, undefined);
45
- assert.strictEqual(result, 1);
46
- });
47
-
48
- });
49
-
50
- describe("assign()", () => {
51
-
52
- it("should merge properties from two objects when called", () => {
53
-
54
- const object1 = { foo: 1, bar: 3 };
55
- const object2 = { foo: 2 };
56
-
57
- const result = MergeStrategy.assign(object1, object2);
58
- assert.deepStrictEqual(result, {
59
- foo: 2,
60
- bar: 3
61
- });
62
- });
63
-
64
- });
65
-
66
- });