@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.
- package/eslint-plugin-custom-rules.js +2 -0
- package/package.json +1 -1
- package/node_modules/@aashutoshrathi/word-wrap/LICENSE +0 -21
- package/node_modules/@aashutoshrathi/word-wrap/README.md +0 -182
- package/node_modules/@aashutoshrathi/word-wrap/index.d.ts +0 -50
- package/node_modules/@aashutoshrathi/word-wrap/index.js +0 -52
- package/node_modules/@aashutoshrathi/word-wrap/package.json +0 -81
- package/node_modules/@angular-eslint/bundled-angular-compiler/README.md +0 -1
- package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.d.ts +0 -5
- package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.js +0 -32004
- package/node_modules/@angular-eslint/bundled-angular-compiler/package.json +0 -19
- package/node_modules/@angular-eslint/template-parser/LICENSE +0 -21
- package/node_modules/@angular-eslint/template-parser/README.md +0 -1
- package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.d.ts +0 -6
- package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.js +0 -69
- package/node_modules/@angular-eslint/template-parser/dist/index.d.ts +0 -44
- package/node_modules/@angular-eslint/template-parser/dist/index.js +0 -219
- package/node_modules/@angular-eslint/template-parser/package.json +0 -28
- package/node_modules/@eslint/eslintrc/LICENSE +0 -19
- package/node_modules/@eslint/eslintrc/README.md +0 -115
- package/node_modules/@eslint/eslintrc/conf/config-schema.js +0 -79
- package/node_modules/@eslint/eslintrc/conf/environments.js +0 -215
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +0 -1104
- package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +0 -1
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +0 -4333
- package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +0 -1
- package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +0 -532
- package/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +0 -523
- package/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +0 -115
- package/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +0 -145
- package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +0 -238
- package/node_modules/@eslint/eslintrc/lib/config-array/index.js +0 -19
- package/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +0 -225
- package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +0 -1149
- package/node_modules/@eslint/eslintrc/lib/flat-compat.js +0 -318
- package/node_modules/@eslint/eslintrc/lib/index-universal.js +0 -29
- package/node_modules/@eslint/eslintrc/lib/index.js +0 -56
- package/node_modules/@eslint/eslintrc/lib/shared/ajv.js +0 -191
- package/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +0 -135
- package/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +0 -325
- package/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +0 -63
- package/node_modules/@eslint/eslintrc/lib/shared/naming.js +0 -96
- package/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +0 -42
- package/node_modules/@eslint/eslintrc/lib/shared/types.js +0 -149
- package/node_modules/@eslint/eslintrc/package.json +0 -82
- package/node_modules/@eslint/eslintrc/universal.js +0 -9
- package/node_modules/@eslint/js/LICENSE +0 -19
- package/node_modules/@eslint/js/README.md +0 -57
- package/node_modules/@eslint/js/package.json +0 -31
- package/node_modules/@eslint/js/src/configs/eslint-all.js +0 -211
- package/node_modules/@eslint/js/src/configs/eslint-recommended.js +0 -76
- package/node_modules/@eslint/js/src/index.js +0 -17
- package/node_modules/@eslint-community/eslint-utils/LICENSE +0 -21
- package/node_modules/@eslint-community/eslint-utils/README.md +0 -37
- package/node_modules/@eslint-community/eslint-utils/index.js +0 -2068
- package/node_modules/@eslint-community/eslint-utils/index.js.map +0 -1
- package/node_modules/@eslint-community/eslint-utils/index.mjs +0 -2027
- package/node_modules/@eslint-community/eslint-utils/index.mjs.map +0 -1
- package/node_modules/@eslint-community/eslint-utils/package.json +0 -73
- package/node_modules/@eslint-community/regexpp/LICENSE +0 -21
- package/node_modules/@eslint-community/regexpp/README.md +0 -177
- package/node_modules/@eslint-community/regexpp/index.d.ts +0 -1065
- package/node_modules/@eslint-community/regexpp/index.js +0 -2747
- package/node_modules/@eslint-community/regexpp/index.js.map +0 -1
- package/node_modules/@eslint-community/regexpp/index.mjs +0 -2737
- package/node_modules/@eslint-community/regexpp/index.mjs.map +0 -1
- package/node_modules/@eslint-community/regexpp/package.json +0 -93
- package/node_modules/@humanwhocodes/config-array/LICENSE +0 -201
- package/node_modules/@humanwhocodes/config-array/README.md +0 -342
- package/node_modules/@humanwhocodes/config-array/api.js +0 -1061
- package/node_modules/@humanwhocodes/config-array/package.json +0 -61
- package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +0 -15
- package/node_modules/@humanwhocodes/module-importer/LICENSE +0 -201
- package/node_modules/@humanwhocodes/module-importer/README.md +0 -80
- package/node_modules/@humanwhocodes/module-importer/dist/module-importer.cjs +0 -22
- package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.cts +0 -27
- package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.ts +0 -2
- package/node_modules/@humanwhocodes/module-importer/dist/module-importer.js +0 -18
- package/node_modules/@humanwhocodes/module-importer/package.json +0 -65
- package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +0 -81
- package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +0 -22
- package/node_modules/@humanwhocodes/object-schema/.eslintrc.js +0 -29
- package/node_modules/@humanwhocodes/object-schema/.github/workflows/nodejs-test.yml +0 -27
- package/node_modules/@humanwhocodes/object-schema/.github/workflows/release-please.yml +0 -39
- package/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +0 -26
- package/node_modules/@humanwhocodes/object-schema/LICENSE +0 -29
- package/node_modules/@humanwhocodes/object-schema/README.md +0 -234
- package/node_modules/@humanwhocodes/object-schema/package.json +0 -33
- package/node_modules/@humanwhocodes/object-schema/src/index.js +0 -7
- package/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +0 -53
- package/node_modules/@humanwhocodes/object-schema/src/object-schema.js +0 -301
- package/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +0 -102
- package/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +0 -66
- package/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +0 -659
- package/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +0 -186
- package/node_modules/@nodelib/fs.scandir/LICENSE +0 -21
- package/node_modules/@nodelib/fs.scandir/README.md +0 -171
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +0 -20
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +0 -19
- package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +0 -4
- package/node_modules/@nodelib/fs.scandir/out/constants.js +0 -17
- package/node_modules/@nodelib/fs.scandir/out/index.d.ts +0 -12
- package/node_modules/@nodelib/fs.scandir/out/index.js +0 -26
- package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +0 -7
- package/node_modules/@nodelib/fs.scandir/out/providers/async.js +0 -104
- package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +0 -1
- package/node_modules/@nodelib/fs.scandir/out/providers/common.js +0 -13
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +0 -5
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +0 -54
- package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +0 -20
- package/node_modules/@nodelib/fs.scandir/out/settings.js +0 -24
- package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +0 -20
- package/node_modules/@nodelib/fs.scandir/out/types/index.js +0 -2
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +0 -2
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +0 -19
- package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +0 -2
- package/node_modules/@nodelib/fs.scandir/out/utils/index.js +0 -5
- package/node_modules/@nodelib/fs.scandir/package.json +0 -44
- package/node_modules/@nodelib/fs.stat/LICENSE +0 -21
- package/node_modules/@nodelib/fs.stat/README.md +0 -126
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +0 -13
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +0 -17
- package/node_modules/@nodelib/fs.stat/out/index.d.ts +0 -12
- package/node_modules/@nodelib/fs.stat/out/index.js +0 -26
- package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +0 -4
- package/node_modules/@nodelib/fs.stat/out/providers/async.js +0 -36
- package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +0 -3
- package/node_modules/@nodelib/fs.stat/out/providers/sync.js +0 -23
- package/node_modules/@nodelib/fs.stat/out/settings.d.ts +0 -16
- package/node_modules/@nodelib/fs.stat/out/settings.js +0 -16
- package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +0 -4
- package/node_modules/@nodelib/fs.stat/out/types/index.js +0 -2
- package/node_modules/@nodelib/fs.stat/package.json +0 -37
- package/node_modules/@nodelib/fs.walk/LICENSE +0 -21
- package/node_modules/@nodelib/fs.walk/README.md +0 -215
- package/node_modules/@nodelib/fs.walk/out/index.d.ts +0 -14
- package/node_modules/@nodelib/fs.walk/out/index.js +0 -34
- package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +0 -12
- package/node_modules/@nodelib/fs.walk/out/providers/async.js +0 -30
- package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +0 -4
- package/node_modules/@nodelib/fs.walk/out/providers/index.js +0 -9
- package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +0 -12
- package/node_modules/@nodelib/fs.walk/out/providers/stream.js +0 -34
- package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +0 -10
- package/node_modules/@nodelib/fs.walk/out/providers/sync.js +0 -14
- package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +0 -30
- package/node_modules/@nodelib/fs.walk/out/readers/async.js +0 -97
- package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +0 -7
- package/node_modules/@nodelib/fs.walk/out/readers/common.js +0 -31
- package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +0 -6
- package/node_modules/@nodelib/fs.walk/out/readers/reader.js +0 -11
- package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +0 -15
- package/node_modules/@nodelib/fs.walk/out/readers/sync.js +0 -59
- package/node_modules/@nodelib/fs.walk/out/settings.d.ts +0 -30
- package/node_modules/@nodelib/fs.walk/out/settings.js +0 -26
- package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +0 -8
- package/node_modules/@nodelib/fs.walk/out/types/index.js +0 -2
- package/node_modules/@nodelib/fs.walk/package.json +0 -44
- package/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +0 -31
- package/node_modules/@ungap/structured-clone/LICENSE +0 -15
- package/node_modules/@ungap/structured-clone/README.md +0 -95
- package/node_modules/@ungap/structured-clone/cjs/deserialize.js +0 -78
- package/node_modules/@ungap/structured-clone/cjs/index.js +0 -27
- package/node_modules/@ungap/structured-clone/cjs/json.js +0 -24
- package/node_modules/@ungap/structured-clone/cjs/package.json +0 -1
- package/node_modules/@ungap/structured-clone/cjs/serialize.js +0 -160
- package/node_modules/@ungap/structured-clone/cjs/types.js +0 -22
- package/node_modules/@ungap/structured-clone/esm/deserialize.js +0 -79
- package/node_modules/@ungap/structured-clone/esm/index.js +0 -25
- package/node_modules/@ungap/structured-clone/esm/json.js +0 -21
- package/node_modules/@ungap/structured-clone/esm/serialize.js +0 -161
- package/node_modules/@ungap/structured-clone/esm/types.js +0 -11
- package/node_modules/@ungap/structured-clone/package.json +0 -53
- package/node_modules/@ungap/structured-clone/structured-json.js +0 -1
|
@@ -1,39 +0,0 @@
|
|
|
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 }}
|
|
@@ -1,26 +0,0 @@
|
|
|
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))
|
|
@@ -1,29 +0,0 @@
|
|
|
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.
|
|
@@ -1,234 +0,0 @@
|
|
|
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
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,53 +0,0 @@
|
|
|
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;
|