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,105 +0,0 @@
|
|
|
1
|
-
# sbo
|
|
2
|
-
|
|
3
|
-
SBO stands for Support the [Bind Operator](https://github.com/tc39/proposal-bind-operator).
|
|
4
|
-
|
|
5
|
-
Converts `value::yourFunction(arg)` to `yourFunction(value, arg)`—but lets your function support either.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i sbo
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## API
|
|
16
|
-
|
|
17
|
-
The module exports a single function.
|
|
18
|
-
|
|
19
|
-
### Parameters
|
|
20
|
-
|
|
21
|
-
1. Optional: Object argument:
|
|
22
|
-
* Optional: `arg` (integer): The argument index at which `this` should be inserted. Defaults to `0`.
|
|
23
|
-
* Optional: `path` (string): The dot-separated key path of an options object argument located at index `arg` into which `this` should be inserted.
|
|
24
|
-
* Optional: `ignoreThis` (object, array, or function): `this` is ignored if `ignoreThis` strictly equals `this`, or if `ignoreThis` is an array containing `this`, or if `ignoreThis` is a function which returns `true` when given `this`.
|
|
25
|
-
2. `fn` (Function): The function which should receive bind operator support.
|
|
26
|
-
|
|
27
|
-
### Return Value
|
|
28
|
-
|
|
29
|
-
A wrapper function with bind operator support that calls `fn`.
|
|
30
|
-
|
|
31
|
-
## Tutorial
|
|
32
|
-
|
|
33
|
-
Let’s say, for the sake of example, that you have a function called `addSuffix`:
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
const addSuffix = (str, suffix) => str + suffix
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
You use the `sbo` module to add support for the bind operator:
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
const supportBindOperator = require('sbo')
|
|
43
|
-
const addSuffix = supportBindOperator((str, suffix) => str + suffix)
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Now your function can be called either the normal way or with the bind operator:
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
addSuffix('Hello, world', '!') // 'Hello, world!'
|
|
50
|
-
'Hello, world'::addSuffix('!') // 'Hello, world!'
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Specifying a Parameter Index
|
|
54
|
-
|
|
55
|
-
Now let’s swap the order of the parameters:
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
const addSuffix = (suffix, str) => str + suffix
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
A bound `this` would now need to become the argument with an index of 1. To do this, pass an extra argument to `sbo`:
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
const supportBindOperator = require('sbo')
|
|
65
|
-
const addSuffix = supportBindOperator({arg: 1}, (suffix, str) => str + suffix)
|
|
66
|
-
|
|
67
|
-
addSuffix('!', 'Hello, world') // 'Hello, world!'
|
|
68
|
-
'Hello, world'::addSuffix('!') // 'Hello, world!'
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Specifying an Object Argument Key
|
|
72
|
-
|
|
73
|
-
Let’s try using a deconstructed object parameter:
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
const addSuffix = ({str, suffix}) => str + suffix
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Do the following to direct a bound `this` to the `str` key of the object argument at index zero (i.e. the first, and in this case the only, argument):
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
const supportBindOperator = require('sbo')
|
|
83
|
-
const addSuffix = supportBindOperator({path: 'str'}, ({str, suffix}) => str + suffix)
|
|
84
|
-
|
|
85
|
-
addSuffix({str: 'Hello, world', suffix: '!'}) // 'Hello, world!'
|
|
86
|
-
'Hello, world'::addSuffix({suffix: '!'}) // 'Hello, world!'
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
If you have a nested object parameter, you can use a dot-separated key path.
|
|
90
|
-
|
|
91
|
-
## Related
|
|
92
|
-
|
|
93
|
-
Check out these other function utility packages.
|
|
94
|
-
|
|
95
|
-
* [efn](https://github.com/lamansky/efn): Extracted Function
|
|
96
|
-
* [ffn](https://github.com/lamansky/ffn): Filtering Function
|
|
97
|
-
* [jfn](https://github.com/lamansky/jfn): Joined Function
|
|
98
|
-
* [mfn](https://github.com/lamansky/mfn): Memoized Function
|
|
99
|
-
* [ofn](https://github.com/lamansky/ofn): Overloaded Function
|
|
100
|
-
* [pfn](https://github.com/lamansky/pfn): Possible Function
|
|
101
|
-
* [qfn](https://github.com/lamansky/qfn): Qualified Function
|
|
102
|
-
* [vfn](https://github.com/lamansky/vfn): Variadic Function
|
|
103
|
-
* [wfn](https://github.com/lamansky/wfn): Wrapper Function
|
|
104
|
-
* [xfn](https://github.com/lamansky/xfn): Extended Function
|
|
105
|
-
* [3fn](https://github.com/lamansky/3fn): Three-Way Comparison Function
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2018 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,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sorp",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Returns a singular or plural form depending on a given number.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"singular",
|
|
7
|
-
"plural",
|
|
8
|
-
"string",
|
|
9
|
-
"number"
|
|
10
|
-
],
|
|
11
|
-
"author": "John Lamansky",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"homepage": "https://github.com/lamansky/sorp",
|
|
14
|
-
"repository": "lamansky/sorp",
|
|
15
|
-
"main": "index.js",
|
|
16
|
-
"files": [],
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=4.0.0"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"eslint-config-lamansky": "^1.0.0",
|
|
23
|
-
"mocha": "^5.0.0"
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"test": "mocha"
|
|
27
|
-
},
|
|
28
|
-
"eslintConfig": {
|
|
29
|
-
"extends": "lamansky",
|
|
30
|
-
"env": {
|
|
31
|
-
"mocha": true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# sorp
|
|
2
|
-
|
|
3
|
-
Returns a singular or plural form depending on a given number.
|
|
4
|
-
|
|
5
|
-
Does not generate plural forms for you. There are plenty of other modules that do that. This module omits that overhead deliberately.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
Requires [Node.js](https://nodejs.org/) 4.0.0 or above.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i sorp
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
The module exports a single function.
|
|
16
|
-
|
|
17
|
-
## Usage Example
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
const sorp = require('sorp')
|
|
21
|
-
|
|
22
|
-
sorp(0, 'thing', 'things') // 'things'
|
|
23
|
-
sorp(1, 'thing', 'things') // 'thing'
|
|
24
|
-
sorp(2, 'thing', 'things') // 'things'
|
|
25
|
-
```
|
|
@@ -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,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "trim-call",
|
|
3
|
-
"version": "1.1.0",
|
|
4
|
-
"description": "Drops undefined arguments from the end of a function call.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"trim",
|
|
7
|
-
"undefined",
|
|
8
|
-
"arguments",
|
|
9
|
-
"function",
|
|
10
|
-
"call"
|
|
11
|
-
],
|
|
12
|
-
"author": {
|
|
13
|
-
"name": "Fr. John Lamansky",
|
|
14
|
-
"url": "lamansky.com"
|
|
15
|
-
},
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"homepage": "https://github.com/lamansky/trim-call",
|
|
18
|
-
"repository": "lamansky/trim-call",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"files": [],
|
|
21
|
-
"engines": {
|
|
22
|
-
"node": ">=6.0.0"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"rtrim-array": "^1.0.0"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"eslint-config-lamansky": "^2.0.0",
|
|
29
|
-
"mocha": "^6.2.1"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"test": "mocha"
|
|
33
|
-
},
|
|
34
|
-
"eslintConfig": {
|
|
35
|
-
"extends": "lamansky",
|
|
36
|
-
"env": {
|
|
37
|
-
"mocha": true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# trim-call
|
|
2
|
-
|
|
3
|
-
Drops undefined arguments from the end of a function call.
|
|
4
|
-
|
|
5
|
-
Useful if you’re forwarding arguments from one function to another, but the second function has behavior which is affected by the presence of an explicit `undefined` argument.
|
|
6
|
-
|
|
7
|
-
Accepts an arguments list, just like [`Function.prototype.call()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call). If you want to provide an argument array instead, use the [`trim-apply`](https://github.com/lamansky/trim-apply) module.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm i trim-call
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## API
|
|
18
|
-
|
|
19
|
-
The module exports a function (`trimCall()`) that has one other function attached to it as a method (`trimCall.new()`).
|
|
20
|
-
|
|
21
|
-
### `trimCall()`
|
|
22
|
-
|
|
23
|
-
#### Parameters
|
|
24
|
-
|
|
25
|
-
1. `fn` (function): The function to call.
|
|
26
|
-
2. `thisArg` (any): The value of `this` while the function is being called.
|
|
27
|
-
3. Variadic: `...args` (one or more of: any): The arguments for the function call. Any `undefined` arguments at the end will be dropped.
|
|
28
|
-
|
|
29
|
-
#### Return Value
|
|
30
|
-
|
|
31
|
-
The return value of `fn` when called with `thisArg` and `args`.
|
|
32
|
-
|
|
33
|
-
### `trimCall.new()`
|
|
34
|
-
|
|
35
|
-
#### Parameters
|
|
36
|
-
|
|
37
|
-
1. `Cls` (class): The class whose constructor you want to call.
|
|
38
|
-
2. Variadic: `...args` (one or more of: any): The arguments for the constructor call. Any `undefined` arguments at the end will be dropped.
|
|
39
|
-
|
|
40
|
-
#### Return Value
|
|
41
|
-
|
|
42
|
-
A new instance of `Cls` constructed with `args`.
|
|
43
|
-
|
|
44
|
-
## Examples
|
|
45
|
-
|
|
46
|
-
```javascript
|
|
47
|
-
const trimCall = require('trim-call')
|
|
48
|
-
|
|
49
|
-
f1('test')
|
|
50
|
-
|
|
51
|
-
function f1 (a, b) {
|
|
52
|
-
trimCall(f2, this, a, b)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function f2 () {
|
|
56
|
-
arguments.length // 1
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Because of `trimCall()`, the `f2()` function only receives one argument.
|
|
61
|
-
|
|
62
|
-
Here is the above example repeated _without_ `trimCall()`:
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
f1('test')
|
|
66
|
-
|
|
67
|
-
function f1 (a, b) {
|
|
68
|
-
f2.call(this, a, b)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function f2 () {
|
|
72
|
-
arguments.length // 2
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Without `trimCall()`, the undefined `b` argument of `f1()` becomes an explicit second argument for `f2()`.
|
|
77
|
-
|
|
78
|
-
## Related
|
|
79
|
-
|
|
80
|
-
* [trim-apply](https://github.com/lamansky/trim-apply)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018-present Alec Larson
|
|
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,24 +0,0 @@
|
|
|
1
|
-
# type-error v1.0.3
|
|
2
|
-
|
|
3
|
-
Create a native `TypeError` object by passing the expected type and the actual value.
|
|
4
|
-
|
|
5
|
-
*Note:* No validation is done; only type & value formatting.
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
const TypeError = require('type-error');
|
|
9
|
-
|
|
10
|
-
const foo = new Foo();
|
|
11
|
-
if (!(foo instanceof Bar)) {
|
|
12
|
-
throw TypeError(Bar, foo); // 'Expected a Bar instance, got a Foo instance'
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The first argument should be the constructor of the expected type, or a string
|
|
17
|
-
describing the expected value. The second argument can be anything.
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
TypeError(Function, 1) // 'Expected a function, got a number'
|
|
21
|
-
TypeError(Array, true) // 'Expected an array, got true'
|
|
22
|
-
TypeError(Number, NaN) // 'Expected a number, got NaN'
|
|
23
|
-
TypeError('null', {}) // 'Expected null, got an object'
|
|
24
|
-
```
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const {toString} = Object.prototype;
|
|
2
|
-
const vowels = /^[aeiou]/i;
|
|
3
|
-
|
|
4
|
-
const builtin = [Array, Boolean, Date, Error, Function, Number, Object, Promise, RegExp, String, Symbol];
|
|
5
|
-
if (typeof Buffer == 'function') builtin.push(Buffer);
|
|
6
|
-
|
|
7
|
-
const _TypeError = TypeError;
|
|
8
|
-
module.exports = function() {
|
|
9
|
-
const cst = Error.captureStackTrace;
|
|
10
|
-
return function TypeError(type, val) {
|
|
11
|
-
if (type === undefined) throw Error('Type cannot be undefined');
|
|
12
|
-
if (typeof type != 'string') type = ofType(type);
|
|
13
|
-
const err = _TypeError('Expected ' + type + ', got ' + typeOf(val));
|
|
14
|
-
if (cst) cst(err, TypeError);
|
|
15
|
-
return err;
|
|
16
|
-
};
|
|
17
|
-
}();
|
|
18
|
-
|
|
19
|
-
function typeOf(val) {
|
|
20
|
-
if (val !== val) return 'NaN';
|
|
21
|
-
return val == null || typeof val == 'boolean' ?
|
|
22
|
-
String(val) : ofType(val.constructor);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function ofType(type) {
|
|
26
|
-
if (type == null) type = Object;
|
|
27
|
-
return article(type.name) +
|
|
28
|
-
(builtin.indexOf(type) == -1 ?
|
|
29
|
-
type.name + ' instance' :
|
|
30
|
-
type.name.toLowerCase());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function article(str) {
|
|
34
|
-
return vowels.test(str) ? 'an ' : 'a ';
|
|
35
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "type-error",
|
|
3
|
-
"version": "1.0.3",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"repository": "aleclarson/type-error",
|
|
6
|
-
"description": "Create native TypeError objects from an expected type and actual value",
|
|
7
|
-
"devDependencies": {
|
|
8
|
-
"lodge": "^0.1.0",
|
|
9
|
-
"testpass": "^0.9.4"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const arrayPad = require('array-pad')
|
|
4
|
-
const isPlainObject = require('is-plain-object')
|
|
5
|
-
const plainify = require('plainify')
|
|
6
|
-
const wfn = require('wfn')
|
|
7
|
-
|
|
8
|
-
module.exports = (o, fn) => wfn(fn, function vfn () {
|
|
9
|
-
const {arg: i = 0, oo} = plainify('arg', o)
|
|
10
|
-
const origArgs = Array.from(arguments)
|
|
11
|
-
|
|
12
|
-
let options
|
|
13
|
-
if (oo && origArgs.length && isPlainObject(origArgs[origArgs.length - 1])) options = origArgs.pop()
|
|
14
|
-
|
|
15
|
-
const newArgs = arrayPad(origArgs, i)
|
|
16
|
-
newArgs.splice(i, 0, origArgs.length < fn.length ? [] : newArgs.splice(i, origArgs.length - fn.length + 1))
|
|
17
|
-
|
|
18
|
-
if (options) newArgs.push(options)
|
|
19
|
-
|
|
20
|
-
return fn.apply(this, newArgs) // eslint-disable-line no-invalid-this
|
|
21
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2018 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,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vfn",
|
|
3
|
-
"version": "1.1.0",
|
|
4
|
-
"description": "Creates a variadic function, with a “rest parameter” that’s NOT at the end.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"variadic",
|
|
7
|
-
"function",
|
|
8
|
-
"rest parameter",
|
|
9
|
-
"parameters",
|
|
10
|
-
"arguments"
|
|
11
|
-
],
|
|
12
|
-
"author": "John Lamansky",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"homepage": "https://github.com/lamansky/vfn",
|
|
15
|
-
"repository": "lamansky/vfn",
|
|
16
|
-
"main": "index.js",
|
|
17
|
-
"files": [],
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=6.0.0"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"array-pad": "0.0.1",
|
|
23
|
-
"is-plain-object": "^2.0.4",
|
|
24
|
-
"plainify": "^1.0.0",
|
|
25
|
-
"wfn": "^1.0.0"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"eslint-config-lamansky": "^1.0.0",
|
|
29
|
-
"mocha": "^5.1.0"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"test": "mocha"
|
|
33
|
-
},
|
|
34
|
-
"eslintConfig": {
|
|
35
|
-
"extends": "lamansky",
|
|
36
|
-
"env": {
|
|
37
|
-
"mocha": true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# Variadic Function (vfn)
|
|
2
|
-
|
|
3
|
-
Lets you specify a “[rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)” that’s _not_ at the end.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Requires [Node.js](https://nodejs.org/) 6.0.0 or above.
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm i vfn
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## API
|
|
14
|
-
|
|
15
|
-
The module exports a single function.
|
|
16
|
-
|
|
17
|
-
### Parameters
|
|
18
|
-
|
|
19
|
-
1. Object argument (_or_ a value for `arg`):
|
|
20
|
-
* Optional: `arg` (positive integer): The zero-based index of which parameter in `fn`’s parameters list should be the “rest parameter.” Defaults to `0`.
|
|
21
|
-
* Optional: `oo` (boolean): If `true`, an optional options argument at the end of the parameter list will be ignored. (This will only work if you can be sure that none of your other arguments will be plain objects.) Defaults to `false`.
|
|
22
|
-
2. `fn` (function): The function that has a parameter you want to convert into a “rest parameter.”
|
|
23
|
-
|
|
24
|
-
### Return Value
|
|
25
|
-
|
|
26
|
-
A wrapper function that turns all excess arguments into an array which is passed to `fn` at parameter index `arg`.
|
|
27
|
-
|
|
28
|
-
## Example
|
|
29
|
-
|
|
30
|
-
JavaScript supports “rest parameters,” but only at the end. Anything else will throw an error:
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
function func (...a, b, c) {} // Uncaught SyntaxError: Rest parameter must be last formal parameter
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
The `vfn` module lets you accomplish this. The index of `a` in the parameters list is `0`, so we pass `0` as the first argument to `vfn()`:
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
const vfn = require('vfn')
|
|
40
|
-
|
|
41
|
-
const func = vfn(0, function (a, b, c) {})
|
|
42
|
-
|
|
43
|
-
func(1, 2, 3, 4, 5) // a = [1, 2, 3]; b = 4; c = 5
|
|
44
|
-
func(1, 2, 3) // a = [1]; b = 2; c = 3
|
|
45
|
-
func('test', 'example') // a = []; b = 'test'; c = 'example'
|
|
46
|
-
func('hello world') // a = []; b = 'hello world'; c = undefined
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### With Optional Options Argument
|
|
50
|
-
|
|
51
|
-
Normally, `vfn` does not support optional parameters, because there’s no way to tell which arguments go to the optional parameter and which go to the variadic parameter. Therefore, `vfn` ignores optional parameters altogether. Take for example the common design pattern of including an optional options parameter at the end of the parameter list:
|
|
52
|
-
|
|
53
|
-
```javascript
|
|
54
|
-
const vfn = require('vfn')
|
|
55
|
-
|
|
56
|
-
const func = vfn(0, function (a, b, c, {option} = {}) {})
|
|
57
|
-
|
|
58
|
-
func(1, 2, 3, 4, 5) // a = [1, 2, 3]; b = 4; c = 5; option = undefined
|
|
59
|
-
func(1, 2, 3, 4, 5, {option: 123}) // a = [1, 2, 3, 4]; b = 5; c = {option: 123}; option = undefined
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
As you can see, the first call works as expected, because the optional options parameter is ignored completely. But it continues to be ignored when we introduce the options object in the second call. `vfn` collapses one too many arguments into `a` and puts the options object into `c`.
|
|
63
|
-
|
|
64
|
-
To make use of an optional options argument, set the `oo` flag when calling `vfn`:
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
const vfn = require('vfn')
|
|
68
|
-
|
|
69
|
-
const func = vfn({arg: 0, oo: true}, function (a, b, c, {option} = {}) {})
|
|
70
|
-
|
|
71
|
-
func(1, 2, 3, 4, 5) // a = [1, 2, 3]; b = 4; c = 5; option = undefined
|
|
72
|
-
func(1, 2, 3, 4, 5, {option: 123}) // a = [1, 2, 3]; b = 4; c = 5; option = 123
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
With `oo` set, `vfn` will recognize that a plain object at the end belongs to an optional ending parameter.
|
|
76
|
-
|
|
77
|
-
This _only_ works if your options parameter is optional and is at the end, and if you can be sure that none of your other arguments will be plain objects.
|
|
78
|
-
|
|
79
|
-
## Related
|
|
80
|
-
|
|
81
|
-
For more projects like this, check out [@lamansky/fn](https://github.com/lamansky/fn).
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const copyOwn = require('copy-own')
|
|
4
|
-
const list = require('english-list')
|
|
5
|
-
const sorp = require('sorp')
|
|
6
|
-
|
|
7
|
-
const wrapperNames = new WeakMap()
|
|
8
|
-
const innerFnStrs = new WeakMap()
|
|
9
|
-
|
|
10
|
-
const multiLineFunction = /([^\n]+(?:\r?\n)?{\r?\n)([ \t]*)([\s\S]+)/
|
|
11
|
-
|
|
12
|
-
module.exports = function wrapFunction (fn, wrapper) {
|
|
13
|
-
if (typeof fn !== 'function') throw new TypeError('wfn argument 1 must be a function')
|
|
14
|
-
if (typeof wrapper !== 'function') throw new TypeError('wfn argument 2 must be a function')
|
|
15
|
-
|
|
16
|
-
const innerFnStr = innerFnStrs.has(fn) ? innerFnStrs.get(fn) : String(fn)
|
|
17
|
-
innerFnStrs.set(wrapper, innerFnStr)
|
|
18
|
-
const names = (wrapperNames.has(fn) ? wrapperNames.get(fn) : []).concat([wrapper.name])
|
|
19
|
-
wrapperNames.set(wrapper, names)
|
|
20
|
-
|
|
21
|
-
copyOwn(fn, wrapper)
|
|
22
|
-
|
|
23
|
-
const actualNames = names.filter(Boolean)
|
|
24
|
-
let namesList
|
|
25
|
-
if (actualNames.length) {
|
|
26
|
-
const diff = names.length - actualNames.length
|
|
27
|
-
namesList = list('and', actualNames.map(n => n + '()').concat(diff > 0 ? [diff + ' other unnamed function' + sorp(diff, '', 's')] : []))
|
|
28
|
-
} else {
|
|
29
|
-
namesList = names.length + ' unnamed function' + sorp(names.length, '', 's')
|
|
30
|
-
}
|
|
31
|
-
const comment = `/* [wfn] Wrapped with ${namesList} */`
|
|
32
|
-
let fnStr
|
|
33
|
-
const matches = innerFnStr.match(multiLineFunction)
|
|
34
|
-
if (matches) {
|
|
35
|
-
const [, before, space, after] = matches
|
|
36
|
-
fnStr = before + space + comment + '\n' + space + after
|
|
37
|
-
} else {
|
|
38
|
-
fnStr = innerFnStr.trim() + '\n' + comment
|
|
39
|
-
}
|
|
40
|
-
wrapper.toString = () => fnStr
|
|
41
|
-
|
|
42
|
-
return wrapper
|
|
43
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright ©2018 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.
|