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

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 (175) hide show
  1. package/node_modules/@aashutoshrathi/word-wrap/LICENSE +21 -0
  2. package/node_modules/@aashutoshrathi/word-wrap/README.md +182 -0
  3. package/node_modules/@aashutoshrathi/word-wrap/index.d.ts +50 -0
  4. package/node_modules/@aashutoshrathi/word-wrap/index.js +52 -0
  5. package/node_modules/@aashutoshrathi/word-wrap/package.json +81 -0
  6. package/node_modules/@angular-eslint/bundled-angular-compiler/README.md +1 -0
  7. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.d.ts +5 -0
  8. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.js +32004 -0
  9. package/node_modules/@angular-eslint/bundled-angular-compiler/package.json +19 -0
  10. package/node_modules/@angular-eslint/template-parser/LICENSE +21 -0
  11. package/node_modules/@angular-eslint/template-parser/README.md +1 -0
  12. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.d.ts +6 -0
  13. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.js +69 -0
  14. package/node_modules/@angular-eslint/template-parser/dist/index.d.ts +44 -0
  15. package/node_modules/@angular-eslint/template-parser/dist/index.js +219 -0
  16. package/node_modules/@angular-eslint/template-parser/package.json +28 -0
  17. package/node_modules/@eslint/eslintrc/LICENSE +19 -0
  18. package/node_modules/@eslint/eslintrc/README.md +115 -0
  19. package/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
  20. package/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
  21. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
  22. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
  23. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4333 -0
  24. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
  25. package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
  26. package/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +523 -0
  27. package/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +115 -0
  28. package/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
  29. package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
  30. package/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
  31. package/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
  32. package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1149 -0
  33. package/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
  34. package/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
  35. package/node_modules/@eslint/eslintrc/lib/index.js +56 -0
  36. package/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
  37. package/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
  38. package/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +325 -0
  39. package/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
  40. package/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
  41. package/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
  42. package/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
  43. package/node_modules/@eslint/eslintrc/package.json +82 -0
  44. package/node_modules/@eslint/eslintrc/universal.js +9 -0
  45. package/node_modules/@eslint/js/LICENSE +19 -0
  46. package/node_modules/@eslint/js/README.md +57 -0
  47. package/node_modules/@eslint/js/package.json +31 -0
  48. package/node_modules/@eslint/js/src/configs/eslint-all.js +211 -0
  49. package/node_modules/@eslint/js/src/configs/eslint-recommended.js +76 -0
  50. package/node_modules/@eslint/js/src/index.js +17 -0
  51. package/node_modules/@eslint-community/eslint-utils/LICENSE +21 -0
  52. package/node_modules/@eslint-community/eslint-utils/README.md +37 -0
  53. package/node_modules/@eslint-community/eslint-utils/index.js +2068 -0
  54. package/node_modules/@eslint-community/eslint-utils/index.js.map +1 -0
  55. package/node_modules/@eslint-community/eslint-utils/index.mjs +2027 -0
  56. package/node_modules/@eslint-community/eslint-utils/index.mjs.map +1 -0
  57. package/node_modules/@eslint-community/eslint-utils/package.json +73 -0
  58. package/node_modules/@eslint-community/regexpp/LICENSE +21 -0
  59. package/node_modules/@eslint-community/regexpp/README.md +177 -0
  60. package/node_modules/@eslint-community/regexpp/index.d.ts +1065 -0
  61. package/node_modules/@eslint-community/regexpp/index.js +2747 -0
  62. package/node_modules/@eslint-community/regexpp/index.js.map +1 -0
  63. package/node_modules/@eslint-community/regexpp/index.mjs +2737 -0
  64. package/node_modules/@eslint-community/regexpp/index.mjs.map +1 -0
  65. package/node_modules/@eslint-community/regexpp/package.json +93 -0
  66. package/node_modules/@humanwhocodes/config-array/LICENSE +201 -0
  67. package/node_modules/@humanwhocodes/config-array/README.md +342 -0
  68. package/node_modules/@humanwhocodes/config-array/api.js +1061 -0
  69. package/node_modules/@humanwhocodes/config-array/package.json +61 -0
  70. package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +15 -0
  71. package/node_modules/@humanwhocodes/module-importer/LICENSE +201 -0
  72. package/node_modules/@humanwhocodes/module-importer/README.md +80 -0
  73. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.cjs +22 -0
  74. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.cts +27 -0
  75. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.ts +2 -0
  76. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.js +18 -0
  77. package/node_modules/@humanwhocodes/module-importer/package.json +65 -0
  78. package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +81 -0
  79. package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +22 -0
  80. package/node_modules/@humanwhocodes/object-schema/.eslintrc.js +29 -0
  81. package/node_modules/@humanwhocodes/object-schema/.github/workflows/nodejs-test.yml +27 -0
  82. package/node_modules/@humanwhocodes/object-schema/.github/workflows/release-please.yml +39 -0
  83. package/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +26 -0
  84. package/node_modules/@humanwhocodes/object-schema/LICENSE +29 -0
  85. package/node_modules/@humanwhocodes/object-schema/README.md +234 -0
  86. package/node_modules/@humanwhocodes/object-schema/package.json +33 -0
  87. package/node_modules/@humanwhocodes/object-schema/src/index.js +7 -0
  88. package/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +53 -0
  89. package/node_modules/@humanwhocodes/object-schema/src/object-schema.js +301 -0
  90. package/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +102 -0
  91. package/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +66 -0
  92. package/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +659 -0
  93. package/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +186 -0
  94. package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
  95. package/node_modules/@nodelib/fs.scandir/README.md +171 -0
  96. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  97. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
  98. package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
  99. package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
  100. package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
  101. package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
  102. package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  103. package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
  104. package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
  105. package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
  106. package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
  107. package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
  108. package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  109. package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
  110. package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  111. package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
  112. package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
  113. package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
  114. package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
  115. package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
  116. package/node_modules/@nodelib/fs.scandir/package.json +44 -0
  117. package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
  118. package/node_modules/@nodelib/fs.stat/README.md +126 -0
  119. package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  120. package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
  121. package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
  122. package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
  123. package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  124. package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
  125. package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
  126. package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
  127. package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
  128. package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
  129. package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  130. package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
  131. package/node_modules/@nodelib/fs.stat/package.json +37 -0
  132. package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
  133. package/node_modules/@nodelib/fs.walk/README.md +215 -0
  134. package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
  135. package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
  136. package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  137. package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
  138. package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
  139. package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
  140. package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
  141. package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
  142. package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
  143. package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
  144. package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  145. package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
  146. package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
  147. package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
  148. package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  149. package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
  150. package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
  151. package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
  152. package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
  153. package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
  154. package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  155. package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
  156. package/node_modules/@nodelib/fs.walk/package.json +44 -0
  157. package/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +31 -0
  158. package/node_modules/@ungap/structured-clone/LICENSE +15 -0
  159. package/node_modules/@ungap/structured-clone/README.md +95 -0
  160. package/node_modules/@ungap/structured-clone/cjs/deserialize.js +78 -0
  161. package/node_modules/@ungap/structured-clone/cjs/index.js +27 -0
  162. package/node_modules/@ungap/structured-clone/cjs/json.js +24 -0
  163. package/node_modules/@ungap/structured-clone/cjs/package.json +1 -0
  164. package/node_modules/@ungap/structured-clone/cjs/serialize.js +160 -0
  165. package/node_modules/@ungap/structured-clone/cjs/types.js +22 -0
  166. package/node_modules/@ungap/structured-clone/esm/deserialize.js +79 -0
  167. package/node_modules/@ungap/structured-clone/esm/index.js +25 -0
  168. package/node_modules/@ungap/structured-clone/esm/json.js +21 -0
  169. package/node_modules/@ungap/structured-clone/esm/serialize.js +161 -0
  170. package/node_modules/@ungap/structured-clone/esm/types.js +11 -0
  171. package/node_modules/@ungap/structured-clone/package.json +53 -0
  172. package/node_modules/@ungap/structured-clone/structured-json.js +1 -0
  173. package/package.json +1 -1
  174. package/rules/dayjs-with-timezone.js +29 -0
  175. package/rules/reducers-should-always-return.js +20 -4
@@ -0,0 +1,39 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+ name: release-please
6
+ jobs:
7
+ release-please:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: GoogleCloudPlatform/release-please-action@v3
11
+ id: release
12
+ with:
13
+ release-type: node
14
+ package-name: object-schema
15
+ # The logic below handles the npm publication:
16
+ - uses: actions/checkout@v4
17
+ # these if statements ensure that a publication only occurs when
18
+ # a new release is created:
19
+ if: ${{ steps.release.outputs.release_created }}
20
+ - uses: actions/setup-node@v3
21
+ with:
22
+ node-version: 12
23
+ registry-url: 'https://registry.npmjs.org'
24
+ if: ${{ steps.release.outputs.release_created }}
25
+ - run: npm ci
26
+ if: ${{ steps.release.outputs.release_created }}
27
+ - run: npm publish
28
+ env:
29
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
30
+ if: ${{ steps.release.outputs.release_created }}
31
+
32
+ # Tweets out release announcement
33
+ - run: 'npx @humanwhocodes/tweet "Object Schema v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }} has been released!\n\n${{ github.event.release.html_url }}"'
34
+ if: ${{ steps.release.outputs.release_created }}
35
+ env:
36
+ TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
37
+ TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
38
+ TWITTER_ACCESS_TOKEN_KEY: ${{ secrets.TWITTER_ACCESS_TOKEN_KEY }}
39
+ TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## [2.0.1](https://github.com/humanwhocodes/object-schema/compare/v2.0.0...v2.0.1) (2023-10-20)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Custom properties should be available on thrown errors ([6ca80b0](https://github.com/humanwhocodes/object-schema/commit/6ca80b001a4ffb678b9b5544fc53322117374376))
9
+
10
+ ## [2.0.0](https://github.com/humanwhocodes/object-schema/compare/v1.2.1...v2.0.0) (2023-10-18)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * Throw custom errors instead of generics.
16
+
17
+ ### Features
18
+
19
+ * Throw custom errors instead of generics. ([c6c01d7](https://github.com/humanwhocodes/object-schema/commit/c6c01d71eb354bf7b1fb3e883c40f7bd9b61647c))
20
+
21
+ ### [1.2.1](https://www.github.com/humanwhocodes/object-schema/compare/v1.2.0...v1.2.1) (2021-11-02)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * Never return original object from individual config ([5463c5c](https://www.github.com/humanwhocodes/object-schema/commit/5463c5c6d2cb35a7b7948dffc37c899a41d1775f))
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019, Human Who Codes
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,234 @@
1
+ # JavaScript ObjectSchema Package
2
+
3
+ by [Nicholas C. Zakas](https://humanwhocodes.com)
4
+
5
+ If you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate).
6
+
7
+ ## Overview
8
+
9
+ A JavaScript object merge/validation utility where you can define a different merge and validation strategy for each key. This is helpful when you need to validate complex data structures and then merge them in a way that is more complex than `Object.assign()`.
10
+
11
+ ## Installation
12
+
13
+ You can install using either npm:
14
+
15
+ ```
16
+ npm install @humanwhocodes/object-schema
17
+ ```
18
+
19
+ Or Yarn:
20
+
21
+ ```
22
+ yarn add @humanwhocodes/object-schema
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Use CommonJS to get access to the `ObjectSchema` constructor:
28
+
29
+ ```js
30
+ const { ObjectSchema } = require("@humanwhocodes/object-schema");
31
+
32
+ const schema = new ObjectSchema({
33
+
34
+ // define a definition for the "downloads" key
35
+ downloads: {
36
+ required: true,
37
+ merge(value1, value2) {
38
+ return value1 + value2;
39
+ },
40
+ validate(value) {
41
+ if (typeof value !== "number") {
42
+ throw new Error("Expected downloads to be a number.");
43
+ }
44
+ }
45
+ },
46
+
47
+ // define a strategy for the "versions" key
48
+ version: {
49
+ required: true,
50
+ merge(value1, value2) {
51
+ return value1.concat(value2);
52
+ },
53
+ validate(value) {
54
+ if (!Array.isArray(value)) {
55
+ throw new Error("Expected versions to be an array.");
56
+ }
57
+ }
58
+ }
59
+ });
60
+
61
+ const record1 = {
62
+ downloads: 25,
63
+ versions: [
64
+ "v1.0.0",
65
+ "v1.1.0",
66
+ "v1.2.0"
67
+ ]
68
+ };
69
+
70
+ const record2 = {
71
+ downloads: 125,
72
+ versions: [
73
+ "v2.0.0",
74
+ "v2.1.0",
75
+ "v3.0.0"
76
+ ]
77
+ };
78
+
79
+ // make sure the records are valid
80
+ schema.validate(record1);
81
+ schema.validate(record2);
82
+
83
+ // merge together (schema.merge() accepts any number of objects)
84
+ const result = schema.merge(record1, record2);
85
+
86
+ // result looks like this:
87
+
88
+ const result = {
89
+ downloads: 75,
90
+ versions: [
91
+ "v1.0.0",
92
+ "v1.1.0",
93
+ "v1.2.0",
94
+ "v2.0.0",
95
+ "v2.1.0",
96
+ "v3.0.0"
97
+ ]
98
+ };
99
+ ```
100
+
101
+ ## Tips and Tricks
102
+
103
+ ### Named merge strategies
104
+
105
+ Instead of specifying a `merge()` method, you can specify one of the following strings to use a default merge strategy:
106
+
107
+ * `"assign"` - use `Object.assign()` to merge the two values into one object.
108
+ * `"overwrite"` - the second value always replaces the first.
109
+ * `"replace"` - the second value replaces the first if the second is not `undefined`.
110
+
111
+ For example:
112
+
113
+ ```js
114
+ const schema = new ObjectSchema({
115
+ name: {
116
+ merge: "replace",
117
+ validate() {}
118
+ }
119
+ });
120
+ ```
121
+
122
+ ### Named validation strategies
123
+
124
+ Instead of specifying a `validate()` method, you can specify one of the following strings to use a default validation strategy:
125
+
126
+ * `"array"` - value must be an array.
127
+ * `"boolean"` - value must be a boolean.
128
+ * `"number"` - value must be a number.
129
+ * `"object"` - value must be an object.
130
+ * `"object?"` - value must be an object or null.
131
+ * `"string"` - value must be a string.
132
+ * `"string!"` - value must be a non-empty string.
133
+
134
+ For example:
135
+
136
+ ```js
137
+ const schema = new ObjectSchema({
138
+ name: {
139
+ merge: "replace",
140
+ validate: "string"
141
+ }
142
+ });
143
+ ```
144
+
145
+ ### Subschemas
146
+
147
+ If you are defining a key that is, itself, an object, you can simplify the process by using a subschema. Instead of defining `merge()` and `validate()`, assign a `schema` key that contains a schema definition, like this:
148
+
149
+ ```js
150
+ const schema = new ObjectSchema({
151
+ name: {
152
+ schema: {
153
+ first: {
154
+ merge: "replace",
155
+ validate: "string"
156
+ },
157
+ last: {
158
+ merge: "replace",
159
+ validate: "string"
160
+ }
161
+ }
162
+ }
163
+ });
164
+
165
+ schema.validate({
166
+ name: {
167
+ first: "n",
168
+ last: "z"
169
+ }
170
+ });
171
+ ```
172
+
173
+ ### Remove Keys During Merge
174
+
175
+ If the merge strategy for a key returns `undefined`, then the key will not appear in the final object. For example:
176
+
177
+ ```js
178
+ const schema = new ObjectSchema({
179
+ date: {
180
+ merge() {
181
+ return undefined;
182
+ },
183
+ validate(value) {
184
+ Date.parse(value); // throws an error when invalid
185
+ }
186
+ }
187
+ });
188
+
189
+ const object1 = { date: "5/5/2005" };
190
+ const object2 = { date: "6/6/2006" };
191
+
192
+ const result = schema.merge(object1, object2);
193
+
194
+ console.log("date" in result); // false
195
+ ```
196
+
197
+ ### Requiring Another Key Be Present
198
+
199
+ If you'd like the presence of one key to require the presence of another key, you can use the `requires` property to specify an array of other properties that any key requires. For example:
200
+
201
+ ```js
202
+ const schema = new ObjectSchema();
203
+
204
+ const schema = new ObjectSchema({
205
+ date: {
206
+ merge() {
207
+ return undefined;
208
+ },
209
+ validate(value) {
210
+ Date.parse(value); // throws an error when invalid
211
+ }
212
+ },
213
+ time: {
214
+ requires: ["date"],
215
+ merge(first, second) {
216
+ return second;
217
+ },
218
+ validate(value) {
219
+ // ...
220
+ }
221
+ }
222
+ });
223
+
224
+ // throws error: Key "time" requires keys "date"
225
+ schema.validate({
226
+ time: "13:45"
227
+ });
228
+ ```
229
+
230
+ In this example, even though `date` is an optional key, it is required to be present whenever `time` is present.
231
+
232
+ ## License
233
+
234
+ BSD 3-Clause
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@humanwhocodes/object-schema",
3
+ "version": "2.0.1",
4
+ "description": "An object schema merger/validator",
5
+ "main": "src/index.js",
6
+ "directories": {
7
+ "test": "tests"
8
+ },
9
+ "scripts": {
10
+ "test": "mocha tests/"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/humanwhocodes/object-schema.git"
15
+ },
16
+ "keywords": [
17
+ "object",
18
+ "validation",
19
+ "schema",
20
+ "merge"
21
+ ],
22
+ "author": "Nicholas C. Zakas",
23
+ "license": "BSD-3-Clause",
24
+ "bugs": {
25
+ "url": "https://github.com/humanwhocodes/object-schema/issues"
26
+ },
27
+ "homepage": "https://github.com/humanwhocodes/object-schema#readme",
28
+ "devDependencies": {
29
+ "chai": "^4.2.0",
30
+ "eslint": "^5.13.0",
31
+ "mocha": "^5.2.0"
32
+ }
33
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @filedescription Object Schema Package
3
+ */
4
+
5
+ exports.ObjectSchema = require("./object-schema").ObjectSchema;
6
+ exports.MergeStrategy = require("./merge-strategy").MergeStrategy;
7
+ exports.ValidationStrategy = require("./validation-strategy").ValidationStrategy;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @filedescription Merge Strategy
3
+ */
4
+
5
+ "use strict";
6
+
7
+ //-----------------------------------------------------------------------------
8
+ // Class
9
+ //-----------------------------------------------------------------------------
10
+
11
+ /**
12
+ * Container class for several different merge strategies.
13
+ */
14
+ class MergeStrategy {
15
+
16
+ /**
17
+ * Merges two keys by overwriting the first with the second.
18
+ * @param {*} value1 The value from the first object key.
19
+ * @param {*} value2 The value from the second object key.
20
+ * @returns {*} The second value.
21
+ */
22
+ static overwrite(value1, value2) {
23
+ return value2;
24
+ }
25
+
26
+ /**
27
+ * Merges two keys by replacing the first with the second only if the
28
+ * second is defined.
29
+ * @param {*} value1 The value from the first object key.
30
+ * @param {*} value2 The value from the second object key.
31
+ * @returns {*} The second value if it is defined.
32
+ */
33
+ static replace(value1, value2) {
34
+ if (typeof value2 !== "undefined") {
35
+ return value2;
36
+ }
37
+
38
+ return value1;
39
+ }
40
+
41
+ /**
42
+ * Merges two properties by assigning properties from the second to the first.
43
+ * @param {*} value1 The value from the first object key.
44
+ * @param {*} value2 The value from the second object key.
45
+ * @returns {*} A new object containing properties from both value1 and
46
+ * value2.
47
+ */
48
+ static assign(value1, value2) {
49
+ return Object.assign({}, value1, value2);
50
+ }
51
+ }
52
+
53
+ exports.MergeStrategy = MergeStrategy;