aurix-ai 2.7.3 → 2.7.5
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/bin/aurix.js +2 -2
- package/dist/agent/AgentLoop.d.ts.map +1 -1
- package/dist/agent/AgentLoop.js +1 -52
- package/dist/agent/AgentLoop.js.map +1 -1
- package/dist/cli/App.d.ts.map +1 -1
- package/dist/cli/App.js +6 -0
- package/dist/cli/App.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +7 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/tools/Browser.d.ts.map +1 -1
- package/dist/tools/Browser.js +44 -615
- package/dist/tools/Browser.js.map +1 -1
- package/dist/tools/captcha/CaptchaRouter.d.ts +6 -0
- package/dist/tools/captcha/CaptchaRouter.d.ts.map +1 -0
- package/dist/tools/captcha/CaptchaRouter.js +371 -0
- package/dist/tools/captcha/CaptchaRouter.js.map +1 -0
- package/dist/tools/captcha/RecaptchaSolver.d.ts +2 -0
- package/dist/tools/captcha/RecaptchaSolver.d.ts.map +1 -0
- package/dist/tools/captcha/RecaptchaSolver.js +1114 -0
- package/dist/tools/captcha/RecaptchaSolver.js.map +1 -0
- package/dist/tools/captcha/common.d.ts +35 -0
- package/dist/tools/captcha/common.d.ts.map +1 -0
- package/dist/tools/captcha/common.js +445 -0
- package/dist/tools/captcha/common.js.map +1 -0
- package/dist/tools/captcha/index.d.ts +5 -0
- package/dist/tools/captcha/index.d.ts.map +1 -0
- package/dist/tools/captcha/index.js +4 -0
- package/dist/tools/captcha/index.js.map +1 -0
- package/package.json +2 -2
- package/scripts/build.cjs +0 -15
- package/scripts/run-task.mjs +86 -0
- package/training/captcha-training.json +930 -0
- package/native/token-counter/index.d.ts +0 -7
- package/native/token-counter/index.js +0 -316
- package/native/token-counter/node_modules/.package-lock.json +0 -568
- package/native/token-counter/node_modules/2/array.js +0 -25
- package/native/token-counter/node_modules/2/index.js +0 -12
- package/native/token-counter/node_modules/2/iterator.js +0 -13
- package/native/token-counter/node_modules/2/license.txt +0 -21
- package/native/token-counter/node_modules/2/map.js +0 -27
- package/native/token-counter/node_modules/2/number.js +0 -109
- package/native/token-counter/node_modules/2/object.js +0 -23
- package/native/token-counter/node_modules/2/package.json +0 -60
- package/native/token-counter/node_modules/2/readme.md +0 -246
- package/native/token-counter/node_modules/2/string.js +0 -11
- package/native/token-counter/node_modules/2/test.js +0 -520
- package/native/token-counter/node_modules/@lamansky/every/index.js +0 -16
- package/native/token-counter/node_modules/@lamansky/every/license.txt +0 -21
- package/native/token-counter/node_modules/@lamansky/every/package.json +0 -38
- package/native/token-counter/node_modules/@lamansky/every/readme.md +0 -46
- package/native/token-counter/node_modules/@lamansky/flatten/index.js +0 -5
- package/native/token-counter/node_modules/@lamansky/flatten/license.txt +0 -21
- package/native/token-counter/node_modules/@lamansky/flatten/package.json +0 -35
- package/native/token-counter/node_modules/@lamansky/flatten/readme.md +0 -41
- package/native/token-counter/node_modules/@napi-rs/cli/LICENSE +0 -21
- package/native/token-counter/node_modules/@napi-rs/cli/README.md +0 -96
- package/native/token-counter/node_modules/@napi-rs/cli/package.json +0 -65
- package/native/token-counter/node_modules/@napi-rs/cli/scripts/index.js +0 -51371
- package/native/token-counter/node_modules/add-counter/index.js +0 -3
- package/native/token-counter/node_modules/add-counter/license.txt +0 -21
- package/native/token-counter/node_modules/add-counter/package.json +0 -34
- package/native/token-counter/node_modules/add-counter/readme.md +0 -36
- package/native/token-counter/node_modules/array-pad/LICENSE +0 -22
- package/native/token-counter/node_modules/array-pad/README.md +0 -80
- package/native/token-counter/node_modules/array-pad/index.js +0 -30
- package/native/token-counter/node_modules/array-pad/package.json +0 -28
- package/native/token-counter/node_modules/arrify/index.js +0 -8
- package/native/token-counter/node_modules/arrify/license +0 -21
- package/native/token-counter/node_modules/arrify/package.json +0 -33
- package/native/token-counter/node_modules/arrify/readme.md +0 -36
- package/native/token-counter/node_modules/case-insensitive/index.js +0 -72
- package/native/token-counter/node_modules/case-insensitive/license.txt +0 -21
- package/native/token-counter/node_modules/case-insensitive/package.json +0 -39
- package/native/token-counter/node_modules/case-insensitive/readme.md +0 -39
- package/native/token-counter/node_modules/case-insensitive/test.js +0 -114
- package/native/token-counter/node_modules/class-chain/index.js +0 -32
- package/native/token-counter/node_modules/class-chain/license.txt +0 -21
- package/native/token-counter/node_modules/class-chain/package.json +0 -39
- package/native/token-counter/node_modules/class-chain/readme.md +0 -23
- package/native/token-counter/node_modules/class-chain/test.js +0 -77
- package/native/token-counter/node_modules/copy-own/index.js +0 -10
- package/native/token-counter/node_modules/copy-own/license.txt +0 -21
- package/native/token-counter/node_modules/copy-own/package.json +0 -37
- package/native/token-counter/node_modules/copy-own/readme.md +0 -67
- package/native/token-counter/node_modules/def-props/index.js +0 -43
- package/native/token-counter/node_modules/def-props/license.txt +0 -21
- package/native/token-counter/node_modules/def-props/node_modules/is-obj/index.d.ts +0 -22
- package/native/token-counter/node_modules/def-props/node_modules/is-obj/index.js +0 -6
- package/native/token-counter/node_modules/def-props/node_modules/is-obj/license +0 -9
- package/native/token-counter/node_modules/def-props/node_modules/is-obj/package.json +0 -34
- package/native/token-counter/node_modules/def-props/node_modules/is-obj/readme.md +0 -39
- package/native/token-counter/node_modules/def-props/package.json +0 -51
- package/native/token-counter/node_modules/def-props/readme.md +0 -117
- package/native/token-counter/node_modules/empty-iterator/index.js +0 -3
- package/native/token-counter/node_modules/empty-iterator/license.txt +0 -21
- package/native/token-counter/node_modules/empty-iterator/package.json +0 -33
- package/native/token-counter/node_modules/empty-iterator/readme.md +0 -23
- package/native/token-counter/node_modules/enforce-range/index.js +0 -15
- package/native/token-counter/node_modules/enforce-range/license.txt +0 -21
- package/native/token-counter/node_modules/enforce-range/node_modules/2/array.js +0 -43
- package/native/token-counter/node_modules/enforce-range/node_modules/2/index.js +0 -10
- package/native/token-counter/node_modules/enforce-range/node_modules/2/iterator.js +0 -26
- package/native/token-counter/node_modules/enforce-range/node_modules/2/license.txt +0 -21
- package/native/token-counter/node_modules/enforce-range/node_modules/2/map.js +0 -47
- package/native/token-counter/node_modules/enforce-range/node_modules/2/number.js +0 -33
- package/native/token-counter/node_modules/enforce-range/node_modules/2/object.js +0 -61
- package/native/token-counter/node_modules/enforce-range/node_modules/2/package.json +0 -41
- package/native/token-counter/node_modules/enforce-range/node_modules/2/readme.md +0 -210
- package/native/token-counter/node_modules/enforce-range/node_modules/2/string.js +0 -37
- package/native/token-counter/node_modules/enforce-range/node_modules/2/test.js +0 -413
- package/native/token-counter/node_modules/enforce-range/package.json +0 -36
- package/native/token-counter/node_modules/enforce-range/readme.md +0 -53
- package/native/token-counter/node_modules/english-list/.travis.yml +0 -6
- package/native/token-counter/node_modules/english-list/LICENSE +0 -22
- package/native/token-counter/node_modules/english-list/README.md +0 -44
- package/native/token-counter/node_modules/english-list/index.js +0 -34
- package/native/token-counter/node_modules/english-list/package.json +0 -31
- package/native/token-counter/node_modules/english-list/test.log +0 -6
- package/native/token-counter/node_modules/errate/index.js +0 -19
- package/native/token-counter/node_modules/errate/license.txt +0 -21
- package/native/token-counter/node_modules/errate/package.json +0 -39
- package/native/token-counter/node_modules/errate/readme.md +0 -79
- package/native/token-counter/node_modules/ffn/index.js +0 -9
- package/native/token-counter/node_modules/ffn/license.txt +0 -21
- package/native/token-counter/node_modules/ffn/package.json +0 -34
- package/native/token-counter/node_modules/ffn/readme.md +0 -51
- package/native/token-counter/node_modules/get-own-property/index.js +0 -5
- package/native/token-counter/node_modules/get-own-property/license.txt +0 -21
- package/native/token-counter/node_modules/get-own-property/package.json +0 -31
- package/native/token-counter/node_modules/get-own-property/readme.md +0 -22
- package/native/token-counter/node_modules/has-duplicates/index.js +0 -11
- package/native/token-counter/node_modules/has-duplicates/license.txt +0 -21
- package/native/token-counter/node_modules/has-duplicates/package.json +0 -32
- package/native/token-counter/node_modules/has-duplicates/readme.md +0 -23
- package/native/token-counter/node_modules/has-duplicates/test.js +0 -30
- package/native/token-counter/node_modules/if-else-throw/index.js +0 -8
- package/native/token-counter/node_modules/if-else-throw/license.txt +0 -21
- package/native/token-counter/node_modules/if-else-throw/package.json +0 -37
- package/native/token-counter/node_modules/if-else-throw/readme.md +0 -32
- package/native/token-counter/node_modules/is-array-of-length/index.js +0 -7
- package/native/token-counter/node_modules/is-array-of-length/license.txt +0 -21
- package/native/token-counter/node_modules/is-array-of-length/package.json +0 -42
- package/native/token-counter/node_modules/is-array-of-length/readme.md +0 -41
- package/native/token-counter/node_modules/is-class-of/index.js +0 -7
- package/native/token-counter/node_modules/is-class-of/license.txt +0 -21
- package/native/token-counter/node_modules/is-class-of/package.json +0 -35
- package/native/token-counter/node_modules/is-class-of/readme.md +0 -57
- package/native/token-counter/node_modules/is-global-object/index.js +0 -6
- package/native/token-counter/node_modules/is-global-object/license.txt +0 -21
- package/native/token-counter/node_modules/is-global-object/package.json +0 -34
- package/native/token-counter/node_modules/is-global-object/readme.md +0 -22
- package/native/token-counter/node_modules/is-instance-of/index.js +0 -28
- package/native/token-counter/node_modules/is-instance-of/license.txt +0 -21
- package/native/token-counter/node_modules/is-instance-of/package.json +0 -44
- package/native/token-counter/node_modules/is-instance-of/readme.md +0 -55
- package/native/token-counter/node_modules/is-iterable/index.js +0 -5
- package/native/token-counter/node_modules/is-iterable/license +0 -21
- package/native/token-counter/node_modules/is-iterable/package.json +0 -30
- package/native/token-counter/node_modules/is-iterable/readme.md +0 -23
- package/native/token-counter/node_modules/is-nil/LICENSE +0 -21
- package/native/token-counter/node_modules/is-nil/README.md +0 -47
- package/native/token-counter/node_modules/is-nil/index.js +0 -6
- package/native/token-counter/node_modules/is-nil/package.json +0 -46
- package/native/token-counter/node_modules/is-obj/index.js +0 -5
- package/native/token-counter/node_modules/is-obj/license +0 -21
- package/native/token-counter/node_modules/is-obj/package.json +0 -33
- package/native/token-counter/node_modules/is-obj/readme.md +0 -34
- package/native/token-counter/node_modules/is-object/.eslintignore +0 -1
- package/native/token-counter/node_modules/is-object/.eslintrc +0 -5
- package/native/token-counter/node_modules/is-object/.nycrc +0 -13
- package/native/token-counter/node_modules/is-object/.testem.json +0 -14
- package/native/token-counter/node_modules/is-object/CHANGELOG.md +0 -121
- package/native/token-counter/node_modules/is-object/LICENSE +0 -19
- package/native/token-counter/node_modules/is-object/README.md +0 -48
- package/native/token-counter/node_modules/is-object/index.js +0 -5
- package/native/token-counter/node_modules/is-object/package.json +0 -78
- package/native/token-counter/node_modules/is-object/test/index.js +0 -44
- package/native/token-counter/node_modules/is-plain-object/LICENSE +0 -21
- package/native/token-counter/node_modules/is-plain-object/README.md +0 -104
- package/native/token-counter/node_modules/is-plain-object/index.d.ts +0 -5
- package/native/token-counter/node_modules/is-plain-object/index.js +0 -37
- package/native/token-counter/node_modules/is-plain-object/package.json +0 -79
- package/native/token-counter/node_modules/isobject/LICENSE +0 -21
- package/native/token-counter/node_modules/isobject/README.md +0 -122
- package/native/token-counter/node_modules/isobject/index.d.ts +0 -5
- package/native/token-counter/node_modules/isobject/index.js +0 -12
- package/native/token-counter/node_modules/isobject/package.json +0 -74
- package/native/token-counter/node_modules/lodash.set/LICENSE +0 -47
- package/native/token-counter/node_modules/lodash.set/README.md +0 -18
- package/native/token-counter/node_modules/lodash.set/index.js +0 -990
- package/native/token-counter/node_modules/lodash.set/package.json +0 -17
- package/native/token-counter/node_modules/longest-first/index.js +0 -3
- package/native/token-counter/node_modules/longest-first/license.txt +0 -21
- package/native/token-counter/node_modules/longest-first/package.json +0 -36
- package/native/token-counter/node_modules/longest-first/readme.md +0 -29
- package/native/token-counter/node_modules/m-o/index.js +0 -27
- package/native/token-counter/node_modules/m-o/license.txt +0 -21
- package/native/token-counter/node_modules/m-o/node_modules/new-object/index.js +0 -23
- package/native/token-counter/node_modules/m-o/node_modules/new-object/license.txt +0 -21
- package/native/token-counter/node_modules/m-o/node_modules/new-object/package.json +0 -40
- package/native/token-counter/node_modules/m-o/node_modules/new-object/readme.md +0 -55
- package/native/token-counter/node_modules/m-o/package.json +0 -45
- package/native/token-counter/node_modules/m-o/readme.md +0 -87
- package/native/token-counter/node_modules/map-iter/index.js +0 -6
- package/native/token-counter/node_modules/map-iter/license.txt +0 -21
- package/native/token-counter/node_modules/map-iter/package.json +0 -40
- package/native/token-counter/node_modules/map-iter/readme.md +0 -46
- package/native/token-counter/node_modules/new-object/index.js +0 -5
- package/native/token-counter/node_modules/new-object/license.txt +0 -21
- package/native/token-counter/node_modules/new-object/package.json +0 -49
- package/native/token-counter/node_modules/new-object/readme.md +0 -145
- package/native/token-counter/node_modules/ofn/index.js +0 -22
- package/native/token-counter/node_modules/ofn/license.txt +0 -21
- package/native/token-counter/node_modules/ofn/package.json +0 -40
- package/native/token-counter/node_modules/ofn/readme.md +0 -63
- package/native/token-counter/node_modules/otherwise/index.js +0 -11
- package/native/token-counter/node_modules/otherwise/license.txt +0 -21
- package/native/token-counter/node_modules/otherwise/package.json +0 -38
- package/native/token-counter/node_modules/otherwise/readme.md +0 -29
- package/native/token-counter/node_modules/parser-factory/index.js +0 -138
- package/native/token-counter/node_modules/parser-factory/license.txt +0 -21
- package/native/token-counter/node_modules/parser-factory/node_modules/arrify/index.d.ts +0 -38
- package/native/token-counter/node_modules/parser-factory/node_modules/arrify/index.js +0 -23
- package/native/token-counter/node_modules/parser-factory/node_modules/arrify/license +0 -9
- package/native/token-counter/node_modules/parser-factory/node_modules/arrify/package.json +0 -35
- package/native/token-counter/node_modules/parser-factory/node_modules/arrify/readme.md +0 -39
- package/native/token-counter/node_modules/parser-factory/package.json +0 -38
- package/native/token-counter/node_modules/parser-factory/readme.md +0 -15
- package/native/token-counter/node_modules/pfn/index.js +0 -5
- package/native/token-counter/node_modules/pfn/license.txt +0 -21
- package/native/token-counter/node_modules/pfn/package.json +0 -41
- package/native/token-counter/node_modules/pfn/readme.md +0 -111
- package/native/token-counter/node_modules/pfn/strict.js +0 -8
- package/native/token-counter/node_modules/plainify/index.js +0 -5
- package/native/token-counter/node_modules/plainify/license.txt +0 -21
- package/native/token-counter/node_modules/plainify/package.json +0 -36
- package/native/token-counter/node_modules/plainify/readme.md +0 -47
- package/native/token-counter/node_modules/possible-function/changelog.md +0 -7
- package/native/token-counter/node_modules/possible-function/index.js +0 -43
- package/native/token-counter/node_modules/possible-function/license.txt +0 -21
- package/native/token-counter/node_modules/possible-function/package.json +0 -34
- package/native/token-counter/node_modules/possible-function/readme.md +0 -77
- package/native/token-counter/node_modules/possible-function/test.js +0 -32
- package/native/token-counter/node_modules/qfn/index.js +0 -11
- package/native/token-counter/node_modules/qfn/license.txt +0 -21
- package/native/token-counter/node_modules/qfn/package.json +0 -40
- package/native/token-counter/node_modules/qfn/readme.md +0 -45
- package/native/token-counter/node_modules/roadblock/index.js +0 -3
- package/native/token-counter/node_modules/roadblock/license.txt +0 -21
- package/native/token-counter/node_modules/roadblock/package.json +0 -40
- package/native/token-counter/node_modules/roadblock/readme.md +0 -59
- package/native/token-counter/node_modules/round-to/index.d.ts +0 -56
- package/native/token-counter/node_modules/round-to/index.js +0 -37
- package/native/token-counter/node_modules/round-to/license +0 -9
- package/native/token-counter/node_modules/round-to/package.json +0 -38
- package/native/token-counter/node_modules/round-to/readme.md +0 -71
- package/native/token-counter/node_modules/rtrim-array/index.js +0 -10
- package/native/token-counter/node_modules/rtrim-array/license.txt +0 -21
- package/native/token-counter/node_modules/rtrim-array/package.json +0 -41
- package/native/token-counter/node_modules/rtrim-array/readme.md +0 -75
- package/native/token-counter/node_modules/sbo/index.js +0 -25
- package/native/token-counter/node_modules/sbo/license.txt +0 -21
- package/native/token-counter/node_modules/sbo/package.json +0 -50
- package/native/token-counter/node_modules/sbo/readme.md +0 -105
- package/native/token-counter/node_modules/sorp/index.js +0 -3
- package/native/token-counter/node_modules/sorp/license.txt +0 -21
- package/native/token-counter/node_modules/sorp/package.json +0 -34
- package/native/token-counter/node_modules/sorp/readme.md +0 -25
- package/native/token-counter/node_modules/trim-call/index.js +0 -6
- package/native/token-counter/node_modules/trim-call/license.txt +0 -21
- package/native/token-counter/node_modules/trim-call/package.json +0 -40
- package/native/token-counter/node_modules/trim-call/readme.md +0 -80
- package/native/token-counter/node_modules/type-error/LICENSE +0 -21
- package/native/token-counter/node_modules/type-error/README.md +0 -24
- package/native/token-counter/node_modules/type-error/index.js +0 -35
- package/native/token-counter/node_modules/type-error/package.json +0 -11
- package/native/token-counter/node_modules/vfn/index.js +0 -21
- package/native/token-counter/node_modules/vfn/license.txt +0 -21
- package/native/token-counter/node_modules/vfn/package.json +0 -40
- package/native/token-counter/node_modules/vfn/readme.md +0 -81
- package/native/token-counter/node_modules/wfn/index.js +0 -43
- package/native/token-counter/node_modules/wfn/license.txt +0 -21
- package/native/token-counter/node_modules/wfn/package.json +0 -38
- package/native/token-counter/node_modules/wfn/readme.md +0 -81
- package/native/token-counter/package-lock.json +0 -578
- package/native/token-counter/package.json +0 -21
- package/native/token-counter/token-counter.linux-x64-gnu.node +0 -0
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2017 John Lamansky
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "class-chain",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Returns an object’s class and its ancestors.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"object",
|
|
7
|
-
"class",
|
|
8
|
-
"function",
|
|
9
|
-
"prototype",
|
|
10
|
-
"constructor",
|
|
11
|
-
"chain",
|
|
12
|
-
"ancestors",
|
|
13
|
-
"extends"
|
|
14
|
-
],
|
|
15
|
-
"author": "John Lamansky",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"homepage": "https://github.com/lamansky/class-chain",
|
|
18
|
-
"repository": "lamansky/class-chain",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=4.0.0"
|
|
22
|
-
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"is-object": "^1.0.1"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"eslint-config-lamansky": "^1.0.0",
|
|
28
|
-
"mocha": "^3.2.0"
|
|
29
|
-
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"test": "mocha"
|
|
32
|
-
},
|
|
33
|
-
"eslintConfig": {
|
|
34
|
-
"extends": "lamansky",
|
|
35
|
-
"env": {
|
|
36
|
-
"mocha": true
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# class-chain
|
|
2
|
-
|
|
3
|
-
A [Node.js](https://nodejs.org/) module that returns an object’s class and its ancestors.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install class-chain --save
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
const getClassChain = require('class-chain')
|
|
15
|
-
|
|
16
|
-
class A {}
|
|
17
|
-
class B extends A {}
|
|
18
|
-
|
|
19
|
-
let b = new B()
|
|
20
|
-
|
|
21
|
-
getClassChain(b) // [B, A]
|
|
22
|
-
getClassChain.names(b) // ['B', 'A']
|
|
23
|
-
```
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const assert = require('assert')
|
|
4
|
-
const getClassChain = require('.')
|
|
5
|
-
|
|
6
|
-
class A {}
|
|
7
|
-
class B {}
|
|
8
|
-
class B1 extends B {}
|
|
9
|
-
|
|
10
|
-
describe('getClassChain()', function () {
|
|
11
|
-
it('should return an empty array for primitives', function () {
|
|
12
|
-
assert.strictEqual(getClassChain('test').length, 0)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should return an empty array for a plain object', function () {
|
|
16
|
-
assert.strictEqual(getClassChain({}).length, 0)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should return an empty array for an object with a null prototype', function () {
|
|
20
|
-
assert.strictEqual(getClassChain(Object.create(null)).length, 0)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('should return an empty array for a nameless function', function () {
|
|
24
|
-
assert.strictEqual(getClassChain(function () {}).length, 0)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should return the wrapper class for a wrapped primitive', function () {
|
|
28
|
-
const classes = getClassChain(new String('test')) // eslint-disable-line no-new-wrappers
|
|
29
|
-
assert.strictEqual(classes.length, 1)
|
|
30
|
-
assert.strictEqual(classes[0], String)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should return single class when given non-extending class', function () {
|
|
34
|
-
const classes = getClassChain(A)
|
|
35
|
-
assert.strictEqual(classes.length, 1)
|
|
36
|
-
assert.strictEqual(classes[0], A)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should return single class when given instance of non-extending class', function () {
|
|
40
|
-
const classes = getClassChain(new A())
|
|
41
|
-
assert.strictEqual(classes.length, 1)
|
|
42
|
-
assert.strictEqual(classes[0], A)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('should return multiple classes when given extending class', function () {
|
|
46
|
-
const classes = getClassChain(B1)
|
|
47
|
-
assert.strictEqual(classes.length, 2)
|
|
48
|
-
assert.strictEqual(classes[0], B1)
|
|
49
|
-
assert.strictEqual(classes[1], B)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should return multiple classes when given instance of extending class', function () {
|
|
53
|
-
const classes = getClassChain(new B1())
|
|
54
|
-
assert.strictEqual(classes.length, 2)
|
|
55
|
-
assert.strictEqual(classes[0], B1)
|
|
56
|
-
assert.strictEqual(classes[1], B)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
describe('getClassChain.names()', function () {
|
|
61
|
-
it('should return an empty array for invalid input', function () {
|
|
62
|
-
assert.strictEqual(getClassChain.names('test').length, 0)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should return the wrapper class name for a wrapped primitive', function () {
|
|
66
|
-
const classes = getClassChain.names(new String('test')) // eslint-disable-line no-new-wrappers
|
|
67
|
-
assert.strictEqual(classes.length, 1)
|
|
68
|
-
assert.strictEqual(classes[0], 'String')
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('should return multiple class names when given instance of extending class', function () {
|
|
72
|
-
const classes = getClassChain.names(new B1())
|
|
73
|
-
assert.strictEqual(classes.length, 2)
|
|
74
|
-
assert.strictEqual(classes[0], 'B1')
|
|
75
|
-
assert.strictEqual(classes[1], 'B')
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = function copyOwn (from, to = {}, {enumOnly, override = true, overwrite = true} = {}) {
|
|
4
|
-
for (const key of (enumOnly ? Object.keys : Reflect.ownKeys)(from)) {
|
|
5
|
-
if ((overwrite || !Object.prototype.hasOwnProperty.call(to, key)) && (override || !(key in to))) {
|
|
6
|
-
Object.defineProperty(to, key, Object.getOwnPropertyDescriptor(from, key))
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to
|
|
10
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2018–2019 Fr. John Lamansky
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "copy-own",
|
|
3
|
-
"version": "1.2.0",
|
|
4
|
-
"description": "Copies an object’s own properties to another object.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"copy",
|
|
7
|
-
"own",
|
|
8
|
-
"object",
|
|
9
|
-
"properties"
|
|
10
|
-
],
|
|
11
|
-
"author": {
|
|
12
|
-
"name": "Fr. John Lamansky",
|
|
13
|
-
"url": "lamansky.com"
|
|
14
|
-
},
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"homepage": "https://github.com/lamansky/copy-own",
|
|
17
|
-
"repository": "lamansky/copy-own",
|
|
18
|
-
"main": "index.js",
|
|
19
|
-
"files": [],
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=6.0.0"
|
|
22
|
-
},
|
|
23
|
-
"dependencies": {},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"eslint-config-lamansky": "^2.0.0",
|
|
26
|
-
"mocha": "^6.2.1"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"test": "mocha"
|
|
30
|
-
},
|
|
31
|
-
"eslintConfig": {
|
|
32
|
-
"extends": "lamansky",
|
|
33
|
-
"env": {
|
|
34
|
-
"mocha": true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# copy-own
|
|
2
|
-
|
|
3
|
-
Copies an object’s own properties to another object.
|
|
4
|
-
|
|
5
|
-
“Own” properties are those that are not inherited from the prototype chain.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i copy-own
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## API
|
|
16
|
-
|
|
17
|
-
The module exports a single function.
|
|
18
|
-
|
|
19
|
-
### Parameters
|
|
20
|
-
|
|
21
|
-
1. `from` (object): The source object that possesses the properties to be copied.
|
|
22
|
-
2. Optional: `to` (object): The destination object that should receive the copied properties. Defaults to a new object.
|
|
23
|
-
3. Optional: Object argument:
|
|
24
|
-
* `enumOnly` (boolean): Whether or not to limit the copy operation to only those properties that were defined with the `enumerable` flag. Defaults to `false`.
|
|
25
|
-
* `override` (boolean): If omitted or set to `true`, all properties will be copied (unless `overwrite` specifies otherwise). If set to `false`, then existing properties in `to` will be neither overwritten nor overridden; that is, the copy operation will only include properties that do not share a name with properties already existing in `to` or in its prototype chain.
|
|
26
|
-
* `overwrite` (boolean): This property is only taken into consideration if `override` (see above) is omitted or set to `true`. If this property is also omitted or set to `true`, all properties will be copied (the default behavior). If set to `false`, then existing properties in `to` will _not_ be overwritten, but properties higher up in `to`’s prototype chain could still be overridden.
|
|
27
|
-
|
|
28
|
-
### Return Value
|
|
29
|
-
|
|
30
|
-
The function modifies the second argument (`to`) and returns it. If `to` is omitted, a new object is created and returned.
|
|
31
|
-
|
|
32
|
-
## Examples
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
const copyOwn = require('copy-own')
|
|
36
|
-
|
|
37
|
-
const from = {a: 'from', b: 'from'}
|
|
38
|
-
const to = {b: 'to', c: 'to'}
|
|
39
|
-
const to = copyOwn(from, to)
|
|
40
|
-
to.a // 'from'
|
|
41
|
-
to.b // 'from'
|
|
42
|
-
to.c // 'to'
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Here is the same example repeated with `overwrite` set to `false`:
|
|
46
|
-
|
|
47
|
-
```javascript
|
|
48
|
-
const copyOwn = require('copy-own')
|
|
49
|
-
|
|
50
|
-
const from = {a: 'from', b: 'from'}
|
|
51
|
-
const to = {b: 'to', c: 'to'}
|
|
52
|
-
const to = copyOwn(from, to, {overwrite: false})
|
|
53
|
-
to.a // 'from'
|
|
54
|
-
to.b // 'to'
|
|
55
|
-
to.c // 'to'
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
When no destination object is specified, a new object is created:
|
|
59
|
-
|
|
60
|
-
```javascript
|
|
61
|
-
const copyOwn = require('copy-own')
|
|
62
|
-
|
|
63
|
-
const from = {a: 1, b: 2}
|
|
64
|
-
const to = copyOwn(from)
|
|
65
|
-
to.a // 1
|
|
66
|
-
to.b // 2
|
|
67
|
-
```
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const errate = require('errate')
|
|
4
|
-
const isIterable = require('is-iterable')
|
|
5
|
-
const isObjectBased = require('is-obj')
|
|
6
|
-
const typeError = require('type-error')
|
|
7
|
-
|
|
8
|
-
module.exports = function defProps (obj, props, {descDefaults, descs, throwIfEquivKeys: err} = {}) {
|
|
9
|
-
if (!isIterable(props)) {
|
|
10
|
-
if (isObjectBased(props)) {
|
|
11
|
-
props = Object.entries(props)
|
|
12
|
-
if (typeof descs === 'undefined') descs = true
|
|
13
|
-
} else if (props) {
|
|
14
|
-
throw typeError('an iterable or object', props)
|
|
15
|
-
} else {
|
|
16
|
-
return obj
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (const entry of props) {
|
|
21
|
-
if (!entry || typeof entry !== 'object') {
|
|
22
|
-
throw new TypeError('Iterator value ' + String(entry) + ' is not an entry object')
|
|
23
|
-
}
|
|
24
|
-
const key = entry[0]
|
|
25
|
-
const value = entry[1]
|
|
26
|
-
if (err && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
27
|
-
throw errate(err, TypeError, {forceClass: false, defaultMessage: 'Multiple keys have equivalent string representations and would overwrite each other in the generated object.'})
|
|
28
|
-
}
|
|
29
|
-
if (descs) {
|
|
30
|
-
const desc = {...descDefaults, ...(typeof value === 'function' ? {value} : value)}
|
|
31
|
-
if (typeof desc.get === 'function' || typeof desc.set === 'function') {
|
|
32
|
-
delete desc.writable
|
|
33
|
-
delete desc.value
|
|
34
|
-
}
|
|
35
|
-
Object.defineProperty(obj, key, desc)
|
|
36
|
-
} else if (descDefaults) {
|
|
37
|
-
Object.defineProperty(obj, key, {...descDefaults, value})
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return obj
|
|
43
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2019 Fr. John Lamansky
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Check if a value is an object.
|
|
3
|
-
|
|
4
|
-
Keep in mind that array, function, regexp, etc, are objects in JavaScript.
|
|
5
|
-
|
|
6
|
-
@example
|
|
7
|
-
```
|
|
8
|
-
import isObject = require('is-obj');
|
|
9
|
-
|
|
10
|
-
isObject({foo: 'bar'});
|
|
11
|
-
//=> true
|
|
12
|
-
|
|
13
|
-
isObject([1, 2, 3]);
|
|
14
|
-
//=> true
|
|
15
|
-
|
|
16
|
-
isObject('foo');
|
|
17
|
-
//=> false
|
|
18
|
-
```
|
|
19
|
-
*/
|
|
20
|
-
declare function isObject(value: unknown): value is object;
|
|
21
|
-
|
|
22
|
-
export = isObject;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "is-obj",
|
|
3
|
-
"version": "2.0.0",
|
|
4
|
-
"description": "Check if a value is an object",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "sindresorhus/is-obj",
|
|
7
|
-
"author": {
|
|
8
|
-
"name": "Sindre Sorhus",
|
|
9
|
-
"email": "sindresorhus@gmail.com",
|
|
10
|
-
"url": "sindresorhus.com"
|
|
11
|
-
},
|
|
12
|
-
"engines": {
|
|
13
|
-
"node": ">=8"
|
|
14
|
-
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "xo && ava && tsd"
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"index.js",
|
|
20
|
-
"index.d.ts"
|
|
21
|
-
],
|
|
22
|
-
"keywords": [
|
|
23
|
-
"object",
|
|
24
|
-
"is",
|
|
25
|
-
"check",
|
|
26
|
-
"test",
|
|
27
|
-
"type"
|
|
28
|
-
],
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"ava": "^1.4.1",
|
|
31
|
-
"tsd": "^0.7.2",
|
|
32
|
-
"xo": "^0.24.0"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# is-obj [](https://travis-ci.org/sindresorhus/is-obj)
|
|
2
|
-
|
|
3
|
-
> Check if a value is an object
|
|
4
|
-
|
|
5
|
-
Keep in mind that array, function, regexp, etc, are objects in JavaScript.<br>
|
|
6
|
-
See [`is-plain-obj`](https://github.com/sindresorhus/is-plain-obj) if you want to check for plain objects.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
$ npm install is-obj
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
const isObject = require('is-obj');
|
|
20
|
-
|
|
21
|
-
isObject({foo: 'bar'});
|
|
22
|
-
//=> true
|
|
23
|
-
|
|
24
|
-
isObject([1, 2, 3]);
|
|
25
|
-
//=> true
|
|
26
|
-
|
|
27
|
-
isObject('foo');
|
|
28
|
-
//=> false
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## Related
|
|
33
|
-
|
|
34
|
-
- [is](https://github.com/sindresorhus/is) - Type check values
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## License
|
|
38
|
-
|
|
39
|
-
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "def-props",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Defines multiple object properties all at once, optionally with shared settings.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"object",
|
|
7
|
-
"define",
|
|
8
|
-
"property",
|
|
9
|
-
"properties",
|
|
10
|
-
"descriptor",
|
|
11
|
-
"getter",
|
|
12
|
-
"setter",
|
|
13
|
-
"configurable",
|
|
14
|
-
"enumerable",
|
|
15
|
-
"writable",
|
|
16
|
-
"entries",
|
|
17
|
-
"key",
|
|
18
|
-
"value"
|
|
19
|
-
],
|
|
20
|
-
"author": {
|
|
21
|
-
"name": "Fr. John Lamansky",
|
|
22
|
-
"url": "lamansky.com"
|
|
23
|
-
},
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"homepage": "https://github.com/lamansky/def-props",
|
|
26
|
-
"repository": "lamansky/def-props",
|
|
27
|
-
"main": "index.js",
|
|
28
|
-
"files": [],
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=8.3.0"
|
|
31
|
-
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"errate": "^1.3.0",
|
|
34
|
-
"is-iterable": "^1.1.1",
|
|
35
|
-
"is-obj": "^2.0.0",
|
|
36
|
-
"type-error": "^1.0.3"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"eslint-config-lamansky": "^2.0.0",
|
|
40
|
-
"mocha": "^6.2.2"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"test": "mocha"
|
|
44
|
-
},
|
|
45
|
-
"eslintConfig": {
|
|
46
|
-
"extends": "lamansky",
|
|
47
|
-
"env": {
|
|
48
|
-
"mocha": true
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# def-props
|
|
2
|
-
|
|
3
|
-
Defines multiple object properties all at once, optionally with shared settings.
|
|
4
|
-
|
|
5
|
-
Read more about property descriptor settings at [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Requires [Node.js](https://nodejs.org/) 8.3.0 or above.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i def-props
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## API
|
|
16
|
-
|
|
17
|
-
The module exports a single function.
|
|
18
|
-
|
|
19
|
-
### Parameters
|
|
20
|
-
|
|
21
|
-
1. `obj` (object): The object (or function) to which you want to add properties.
|
|
22
|
-
2. `props` (object): This must be one of the following:
|
|
23
|
-
* An object whose keys are property names and whose values are property descriptors for the new object.
|
|
24
|
-
* An array (or other iterable) of key-value pairs for the object.
|
|
25
|
-
* An array (or other iterable) of key-descriptor pairs for the object’s properties (if `descs` is set to `true`).
|
|
26
|
-
2. Optional: Object argument:
|
|
27
|
-
* `descDefaults` (plain object): A collection of descriptor settings (namely, `configurable`, `enumerable`, and/or `writable`) that will be applied to every property created on the new object. If you would like all these settings to be undefined, provide an empty object. Omit this option if you have specified complete descriptors in `props` or if you want the module to use simple assignment. If you provided property descriptors in `props`, the contents of `descDefaults` will serve as default values for those descriptors. If you specify `writable` in `descDefaults`, it will be skipped automatically for descriptors that contain getters or setters, since such descriptors cannot contain `writable`.
|
|
28
|
-
* `descs` (boolean): Used to disambiguate the purpose of the values in `props`. If set to `true`, the values in `props` will be interpreted as property descriptor objects. If set to `false`, the values in `props` will be used as values for the new object. Defaults to `false` if `props` is an iterable; otherwise defaults to `true`.
|
|
29
|
-
* `throwIfEquivKeys` (Error, string, or boolean): Only applies if `props` is an array. Set this to throw an error if a `props` array contains keys that would be considered duplicates in the context of an object. For example: a Map can have keys that are objects, but those keys will all likely evaluate to `[object Object]` and overwrite each other if made property keys in an object. Similarly, whereas a Map can have distinct `1` (number) and `'1'` (string) keys, these would be considered the same in an object context. If such a conflict exists and if this option is set to an Error object, the provided Error will be thrown as-is. An error message string will be used to construct a `TypeError`. A value of `true` will throw a `TypeError` with a default error message. A value of `false` is the same as the default behavior, which is that later equivalent keys will silently overwrite the earlier ones.
|
|
30
|
-
|
|
31
|
-
### Return Value
|
|
32
|
-
|
|
33
|
-
Returns the modified `obj`.
|
|
34
|
-
|
|
35
|
-
## Examples
|
|
36
|
-
|
|
37
|
-
### Object of Key-Descriptor Pairs
|
|
38
|
-
|
|
39
|
-
In this example, we define two getters on an object.
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
const defProps = require('def-props')
|
|
43
|
-
|
|
44
|
-
const obj = {}
|
|
45
|
-
defProps(obj, {
|
|
46
|
-
a: {get: () => 1},
|
|
47
|
-
b: {get: () => 2},
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
obj.a // 1
|
|
51
|
-
obj.b // 2
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Supplementing Descriptors with Default Settings
|
|
55
|
-
|
|
56
|
-
Whenever you’re using the module in a property descriptor mode, you can specify settings to be applied to all property descriptors using `descDefaults`.
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
const defProps = require('def-props')
|
|
60
|
-
|
|
61
|
-
const obj = {}
|
|
62
|
-
defProps(obj, {
|
|
63
|
-
a: {get: () => 1}, // `writable` (below) will be ignored for this property
|
|
64
|
-
b: {value: 2},
|
|
65
|
-
}, {
|
|
66
|
-
descDefaults: {configurable: true, writable: true},
|
|
67
|
-
})
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Since trying to set `writable` in a descriptor that also specifies a getter or setter will throw an error, the module will ignore the value of `writable` in `descDefaults` when creating the descriptor for a get/set property, such as the `a` property in the example above.
|
|
71
|
-
|
|
72
|
-
### Array of Key-Value Pairs
|
|
73
|
-
|
|
74
|
-
You can also use this module together with an entries array. For example, this snippet defines key-value pairs on an object as read-only properties.
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
const defProps = require('def-props')
|
|
78
|
-
|
|
79
|
-
const obj = {}
|
|
80
|
-
defProps(
|
|
81
|
-
obj,
|
|
82
|
-
[['a', 1], ['b', 2]],
|
|
83
|
-
{descDefaults: {writable: false}}
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
obj.a // 1
|
|
87
|
-
obj.b // 2
|
|
88
|
-
|
|
89
|
-
obj.a = 123 // TypeError: Cannot set property a of #<Object> which has only a getter
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Array of Key-Descriptor Pairs
|
|
93
|
-
|
|
94
|
-
In addition to providing an array of key-value pairs as in the two examples above, you can also provide an array of keys paired with object property descriptors, if `descs` is set to `true`.
|
|
95
|
-
|
|
96
|
-
```javascript
|
|
97
|
-
const defProps = require('def-props')
|
|
98
|
-
|
|
99
|
-
const obj = {}
|
|
100
|
-
defProps(
|
|
101
|
-
obj,
|
|
102
|
-
[
|
|
103
|
-
['a', {get: () => 1}],
|
|
104
|
-
['b', {get: () => 2}],
|
|
105
|
-
],
|
|
106
|
-
{descs: true}
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
obj.a // 1
|
|
110
|
-
obj.b // 2
|
|
111
|
-
|
|
112
|
-
obj.a = 123 // TypeError: Cannot set property a of #<Object> which has only a getter
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Related
|
|
116
|
-
|
|
117
|
-
* [new-object](https://github.com/lamansky/new-object): Same as this module, but creates a new object instead of modifying an existing one.
|