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,413 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const assert = require('assert')
|
|
4
|
-
const {toArray, toIterator, toMap, toNumber, toObject, toString} = require('.')
|
|
5
|
-
|
|
6
|
-
describe('2', function () {
|
|
7
|
-
describe('#toArray()', function () {
|
|
8
|
-
it('should convert array to array', function () {
|
|
9
|
-
const array = []
|
|
10
|
-
assert.strictEqual(toArray(array), array)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('should convert arguments object to array', function () {
|
|
14
|
-
const array = ['first', 'second']
|
|
15
|
-
|
|
16
|
-
function argumentsTest () {
|
|
17
|
-
const args = toArray(arguments)
|
|
18
|
-
assert(Array.isArray(args))
|
|
19
|
-
assert.strictEqual(JSON.stringify(args), JSON.stringify(array))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
argumentsTest.apply(null, array)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should convert Map to array', function () {
|
|
26
|
-
const array = [['a', 'b']]
|
|
27
|
-
const map = new Map(array)
|
|
28
|
-
assert.strictEqual(JSON.stringify(toArray(map)), JSON.stringify(array))
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('should `detectIndexKeys` of array-like Map', function () {
|
|
32
|
-
const map = new Map([[0, 'a'], ['1', 'b']])
|
|
33
|
-
assert.strictEqual(JSON.stringify(toArray(map, {detectIndexKeys: true})), JSON.stringify(['a', 'b']))
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should convert Set to array', function () {
|
|
37
|
-
const array = [1, 2, 3]
|
|
38
|
-
const set = new Set(array)
|
|
39
|
-
assert.strictEqual(JSON.stringify(toArray(set)), JSON.stringify(array))
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('should convert object to array of key/value pairs', function () {
|
|
43
|
-
const object = {a: 1, b: 2, c: 3}
|
|
44
|
-
const array = [['a', 1], ['b', 2], ['c', 3]]
|
|
45
|
-
assert.strictEqual(JSON.stringify(toArray(object)), JSON.stringify(array))
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should `detectIndexKeys` of array-like object', function () {
|
|
49
|
-
const object = {0: 'a', 1: 'b'}
|
|
50
|
-
assert.strictEqual(JSON.stringify(toArray(object, {detectIndexKeys: true})), JSON.stringify(['a', 'b']))
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('should `detectIndexKeys` of array-like object with nonsequential keys', function () {
|
|
54
|
-
const object = {1: 'b', 0: 'a'}
|
|
55
|
-
assert.strictEqual(JSON.stringify(toArray(object, {detectIndexKeys: true})), JSON.stringify(['a', 'b']))
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should convert primitive value to single-element array', function () {
|
|
59
|
-
assert.strictEqual(JSON.stringify(toArray('test')), JSON.stringify(['test']))
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
for (const value of [undefined, null, NaN]) { // eslint-disable-line no-undefined
|
|
63
|
-
it(`should convert ${value} to empty array`, function () {
|
|
64
|
-
assert.strictEqual(JSON.stringify(toArray(value)), JSON.stringify([]))
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
describe('#toIterator()', function () {
|
|
70
|
-
it('should convert primitive value to single-run iterator', function () {
|
|
71
|
-
const iterator = toIterator('test')
|
|
72
|
-
assert.strictEqual(typeof iterator, 'object')
|
|
73
|
-
assert.strictEqual(typeof iterator.next, 'function')
|
|
74
|
-
let r = iterator.next()
|
|
75
|
-
assert.notEqual(r.done, true)
|
|
76
|
-
assert.strictEqual(r.value, 'test')
|
|
77
|
-
r = iterator.next()
|
|
78
|
-
assert.strictEqual(r.done, true)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
const valueTests = [
|
|
82
|
-
['should convert array to iterator', [1, 2]],
|
|
83
|
-
['should convert Set to iterator', new Set([1, 2])],
|
|
84
|
-
]
|
|
85
|
-
|
|
86
|
-
for (const [description, object] of valueTests) {
|
|
87
|
-
it(description, function () {
|
|
88
|
-
const iterator = toIterator(object)
|
|
89
|
-
assert.strictEqual(typeof iterator, 'object')
|
|
90
|
-
assert.strictEqual(typeof iterator.next, 'function')
|
|
91
|
-
let r = iterator.next()
|
|
92
|
-
assert.notEqual(r.done, true)
|
|
93
|
-
assert.strictEqual(r.value, 1)
|
|
94
|
-
r = iterator.next()
|
|
95
|
-
assert.notEqual(r.done, true)
|
|
96
|
-
assert.strictEqual(r.value, 2)
|
|
97
|
-
r = iterator.next()
|
|
98
|
-
assert.strictEqual(r.done, true)
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const keyValueTests = [
|
|
103
|
-
['should convert Map to iterator', new Map([['a', 1], ['b', 2]])],
|
|
104
|
-
['should convert object to iterator', {a: 1, b: 2}],
|
|
105
|
-
]
|
|
106
|
-
|
|
107
|
-
for (const [description, object] of keyValueTests) {
|
|
108
|
-
it(description, function () {
|
|
109
|
-
const iterator = toIterator(object)
|
|
110
|
-
assert.strictEqual(typeof iterator, 'object')
|
|
111
|
-
assert.strictEqual(typeof iterator.next, 'function')
|
|
112
|
-
let r = iterator.next()
|
|
113
|
-
assert.notEqual(r.done, true)
|
|
114
|
-
assert(Array.isArray(r.value))
|
|
115
|
-
assert.strictEqual(r.value.length, 2)
|
|
116
|
-
assert.strictEqual(r.value[0], 'a')
|
|
117
|
-
assert.strictEqual(r.value[1], 1)
|
|
118
|
-
r = iterator.next()
|
|
119
|
-
assert.notEqual(r.done, true)
|
|
120
|
-
assert(Array.isArray(r.value))
|
|
121
|
-
assert.strictEqual(r.value.length, 2)
|
|
122
|
-
assert.strictEqual(r.value[0], 'b')
|
|
123
|
-
assert.strictEqual(r.value[1], 2)
|
|
124
|
-
r = iterator.next()
|
|
125
|
-
assert.strictEqual(r.done, true)
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
for (const value of [undefined, null, NaN]) { // eslint-disable-line no-undefined
|
|
130
|
-
it(`should convert ${value} to empty iterator`, function () {
|
|
131
|
-
const iterator = toIterator(value)
|
|
132
|
-
assert.strictEqual(typeof iterator, 'object')
|
|
133
|
-
const r = iterator.next()
|
|
134
|
-
assert.strictEqual(r.done, true)
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
describe('#toMap()', function () {
|
|
140
|
-
it('should convert Map to Map', function () {
|
|
141
|
-
assert(toMap(new Map()) instanceof Map)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('should convert array of key/value pairs to Map', function () {
|
|
145
|
-
const map = toMap([['a', 1], ['b', 2]])
|
|
146
|
-
assert.strictEqual(map.get('a'), 1)
|
|
147
|
-
assert.strictEqual(map.get('b'), 2)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('should convert values-only array to Map', function () {
|
|
151
|
-
const a = {}
|
|
152
|
-
const b = []
|
|
153
|
-
const map = toMap([a, b])
|
|
154
|
-
assert.strictEqual(map.get(0), a)
|
|
155
|
-
assert.strictEqual(map.get(1), b)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('should `mirror` array across keys and values', function () {
|
|
159
|
-
const map = toMap(['100', 200], {mirror: true})
|
|
160
|
-
assert.strictEqual(map.get('100'), '100')
|
|
161
|
-
assert.strictEqual(map.get(200), 200)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('should convert object to Map', function () {
|
|
165
|
-
const map = toMap({a: 1, b: 2})
|
|
166
|
-
assert.strictEqual(map.get('a'), 1)
|
|
167
|
-
assert.strictEqual(map.get('b'), 2)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('should convert primitive value to empty Map', function () {
|
|
171
|
-
const map = toMap('not a map')
|
|
172
|
-
assert(map instanceof Map)
|
|
173
|
-
assert.strictEqual(map.size, 0)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('should return the provided fallback if input is unconvertible', function () {
|
|
177
|
-
const map = toMap('not a map', {fallback: new Map([['a', 1], ['b', 2]])})
|
|
178
|
-
assert.strictEqual(map.get('a'), 1)
|
|
179
|
-
assert.strictEqual(map.get('b'), 2)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('should throw error if input is unconvertible and fallback is not a Map', function () {
|
|
183
|
-
assert.throws(() => { toMap('not a map', {fallback: null}) }, TypeError)
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
describe('#toNumber()', function () {
|
|
188
|
-
it('should convert number to number', function () {
|
|
189
|
-
assert.strictEqual(toNumber(1), 1)
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('should convert Number object to number', function () {
|
|
193
|
-
assert.strictEqual(toNumber(new Number(1)), 1) // eslint-disable-line no-new-wrappers
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('should convert integer string to number', function () {
|
|
197
|
-
assert.strictEqual(toNumber('100'), 100)
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('should convert integer String object to number', function () {
|
|
201
|
-
assert.strictEqual(toNumber(new String('100')), 100) // eslint-disable-line no-new-wrappers
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
it('should convert float string to number', function () {
|
|
205
|
-
assert.strictEqual(toNumber('1.2'), 1.2)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('should round float to integer if `round` is true', function () {
|
|
209
|
-
assert.strictEqual(toNumber(4.7, {round: true}), 5)
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it('should return fallback (default 0) for Infinity', function () {
|
|
213
|
-
assert.strictEqual(toNumber(Infinity), 0)
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
it('should allow +Infinity if `finite` is false', function () {
|
|
217
|
-
assert.strictEqual(toNumber(Infinity, {finite: false}), Infinity)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it('should allow -Infinity if `finite` is false', function () {
|
|
221
|
-
assert.strictEqual(toNumber(-Infinity, {finite: false}), -Infinity)
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
it('should return fallback (default 0) for NaN', function () {
|
|
225
|
-
assert.strictEqual(toNumber(NaN), 0)
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
it('should return 0 if number is invalid and no fallback provided', function () {
|
|
229
|
-
assert.strictEqual(toNumber('not a number'), 0)
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
it('should return the provided fallback if number is invalid', function () {
|
|
233
|
-
assert.strictEqual(toNumber('not a number', {fallback: 2}), 2)
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('should round fallback if `round` is true', function () {
|
|
237
|
-
assert.strictEqual(toNumber({}, {fallback: 3.3, round: true}), 3)
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it('should convert Number object fallback to primitive number', function () {
|
|
241
|
-
assert.strictEqual(typeof toNumber({}, {fallback: new Number(1)}), 'number') // eslint-disable-line no-new-wrappers
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
it('should throw error if number is invalid and fallback is not a number', function () {
|
|
245
|
-
assert.throws(() => { toNumber('not a number', {fallback: null}) }, TypeError)
|
|
246
|
-
})
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
describe('#toObject()', function () {
|
|
250
|
-
it('should convert object to object', function () {
|
|
251
|
-
const object = {a: 1, b: 2}
|
|
252
|
-
assert.strictEqual(JSON.stringify(toObject(object)), JSON.stringify(object))
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
it('should convert array of key/value pairs to object', function () {
|
|
256
|
-
const object = toObject([['a', 1], ['b', 2]])
|
|
257
|
-
assert.strictEqual(object.a, 1)
|
|
258
|
-
assert.strictEqual(object.b, 2)
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
it('should convert array of strings to object with numerical keys', function () {
|
|
262
|
-
const object = toObject(['a', 'b'])
|
|
263
|
-
assert.strictEqual(object[0], 'a')
|
|
264
|
-
assert.strictEqual(object[1], 'b')
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
it('should `mirror` string array across keys and values', function () {
|
|
268
|
-
const object = toObject(['100', '200'], {mirror: true})
|
|
269
|
-
assert.strictEqual(object[100], '100')
|
|
270
|
-
assert.strictEqual(object[200], '200')
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
it('should only `mirror` values to keys if all values can be object keys', function () {
|
|
274
|
-
const nonKeyable = {}
|
|
275
|
-
const object = toObject(['100', nonKeyable], {mirror: true})
|
|
276
|
-
assert.strictEqual(object[0], '100')
|
|
277
|
-
assert.strictEqual(object[1], nonKeyable)
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
it('should convert Map to object', function () {
|
|
281
|
-
const object = toObject(new Map([['a', 1], ['b', 2]]))
|
|
282
|
-
assert.strictEqual(object.a, 1)
|
|
283
|
-
assert.strictEqual(object.b, 2)
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
it('should convert primitive value to empty object', function () {
|
|
287
|
-
assert.strictEqual(JSON.stringify(toObject('not an object')), JSON.stringify({}))
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
it('should return the provided fallback if input is unconvertible', function () {
|
|
291
|
-
assert.strictEqual(JSON.stringify(toObject('not an object', {fallback: {a: 1}})), JSON.stringify({a: 1}))
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
it('should throw error if input is unconvertible and fallback is not object', function () {
|
|
295
|
-
assert.throws(() => { toObject('not an object', {fallback: null}) }, TypeError)
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
it('should throw error if Map has keys that are not strings/numbers', function () {
|
|
299
|
-
assert.throws(() => { toObject(new Map([{}, 'test'])) }, TypeError)
|
|
300
|
-
})
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
describe('#toString()', function () {
|
|
304
|
-
it('should convert string to string', function () {
|
|
305
|
-
assert.strictEqual(toString('test'), 'test')
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
it('should convert String object to string', function () {
|
|
309
|
-
assert.strictEqual(typeof toString(new String('test')), typeof 'test') // eslint-disable-line no-new-wrappers
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
it('should convert number to string', function () {
|
|
313
|
-
assert.strictEqual(toString(-123), '-123')
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
it('should convert 0 to "0"', function () {
|
|
317
|
-
assert.strictEqual(toString(0), '0')
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
it('should convert -0 to "0"', function () {
|
|
321
|
-
assert.strictEqual(toString(-0), '0')
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
it('should convert NaN to empty string', function () {
|
|
325
|
-
assert.strictEqual(toString(NaN), '')
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
it('should convert Infinity to empty string', function () {
|
|
329
|
-
assert.strictEqual(toString(Infinity), '')
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
it('should convert true to empty string', function () {
|
|
333
|
-
assert.strictEqual(toString(true), '')
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
it('should convert false to empty string', function () {
|
|
337
|
-
assert.strictEqual(toString(true), '')
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
it('should convert null to empty string', function () {
|
|
341
|
-
assert.strictEqual(toString(null), '')
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
it('should convert undefined to empty string', function () {
|
|
345
|
-
assert.strictEqual(toString(undefined), '') // eslint-disable-line no-undefined
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
it('should convert function to empty string', function () {
|
|
349
|
-
assert.strictEqual(toString(function () {}), '')
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
it('should convert array to empty string', function () {
|
|
353
|
-
assert.strictEqual(toString([]), '')
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
it('should convert plain object to empty string', function () {
|
|
357
|
-
assert.strictEqual(toString({}), '')
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
it('should convert symbol to empty string', function () {
|
|
361
|
-
assert.strictEqual(toString(Symbol('test')), '')
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
it('should convert object to string using object’s custom toString() method', function () {
|
|
365
|
-
class TestClass {
|
|
366
|
-
toString () {
|
|
367
|
-
return 'string value'
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const object = new TestClass()
|
|
371
|
-
assert.strictEqual(toString(object), 'string value')
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('should return the provided fallback if input is unconvertible', function () {
|
|
375
|
-
assert.strictEqual(toString({}, {fallback: 'test'}), 'test')
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
it('should convert String object fallback to primitive string', function () {
|
|
379
|
-
assert.strictEqual(typeof toString({}, {fallback: new String('test')}), 'string') // eslint-disable-line no-new-wrappers
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
it('should throw error if input is unconvertible and fallback is not string', function () {
|
|
383
|
-
assert.throws(() => { toString({}, {fallback: null}) }, TypeError)
|
|
384
|
-
})
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
it('should result in object surviving multiple chained conversions', function () {
|
|
388
|
-
let data = {a: 1, b: 2}
|
|
389
|
-
data = toMap(data)
|
|
390
|
-
data = toArray(data)
|
|
391
|
-
data = toObject(data)
|
|
392
|
-
data = toIterator(data)
|
|
393
|
-
data = toArray(data)
|
|
394
|
-
data = toMap(data)
|
|
395
|
-
data = toObject(data)
|
|
396
|
-
assert.strictEqual(Object.keys(data).length, 2)
|
|
397
|
-
assert.strictEqual(data.a, 1)
|
|
398
|
-
assert.strictEqual(data.b, 2)
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
it('should result in array surviving multiple chained conversions', function () {
|
|
402
|
-
let data = ['first', 'second']
|
|
403
|
-
data = toMap(data)
|
|
404
|
-
data = toArray(data, {detectIndexKeys: true})
|
|
405
|
-
data = toObject(data)
|
|
406
|
-
data = toIterator(data)
|
|
407
|
-
data = toArray(data, {detectIndexKeys: true})
|
|
408
|
-
data = toMap(data)
|
|
409
|
-
data = toObject(data)
|
|
410
|
-
data = toArray(data, {detectIndexKeys: true})
|
|
411
|
-
assert.strictEqual(JSON.stringify(data), JSON.stringify(['first', 'second']))
|
|
412
|
-
})
|
|
413
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "enforce-range",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Enforce a minimum and/or maximum value for a number.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"number",
|
|
7
|
-
"range",
|
|
8
|
-
"min",
|
|
9
|
-
"minimum",
|
|
10
|
-
"max",
|
|
11
|
-
"maximum",
|
|
12
|
-
"value"
|
|
13
|
-
],
|
|
14
|
-
"author": "John Lamansky",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"homepage": "https://github.com/lamansky/enforce-range",
|
|
17
|
-
"repository": "lamansky/enforce-range",
|
|
18
|
-
"main": "index.js",
|
|
19
|
-
"files": [],
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"2": "^1.0.2"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"eslint-config-lamansky": "^1.0.0",
|
|
25
|
-
"mocha": "^4.0.1"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"test": "mocha"
|
|
29
|
-
},
|
|
30
|
-
"eslintConfig": {
|
|
31
|
-
"extends": "lamansky",
|
|
32
|
-
"env": {
|
|
33
|
-
"mocha": true
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# enforce-range
|
|
2
|
-
|
|
3
|
-
Enforce a minimum and/or maximum value for a number.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install enforce-range --save
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
const enforceRange = require('enforce-range')
|
|
15
|
-
|
|
16
|
-
// Number should be between 0 and 100
|
|
17
|
-
enforceRange(0, 100, 51) // 51
|
|
18
|
-
enforceRange(0, 100, -123) // 0
|
|
19
|
-
enforceRange(0, 100, 456) // 100
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Partial Application
|
|
23
|
-
|
|
24
|
-
If you provide only the first two arguments (a minimum and a maximum value), the module will create a partially-applied function which enforces that range. Here's the above example repeated with this usage mode:
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
const enforce0to100 = require('enforce-range')(0, 100)
|
|
28
|
-
|
|
29
|
-
// Number should be between 0 and 100
|
|
30
|
-
enforce0to100(51) // 51
|
|
31
|
-
enforce0to100(-123) // 0
|
|
32
|
-
enforce0to100(456) // 100
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Open-Ended Ranges
|
|
36
|
-
|
|
37
|
-
If, for some reason, you want this module to enforce a range that is only bound on one end, you can do so by passing `null` or ±`Infinity` as the minimum/maximum value. (However, in such a case you’re probably better off cutting the overhead of using a module and just using `Math.min()` or `Math.max()`.)
|
|
38
|
-
|
|
39
|
-
```javascript
|
|
40
|
-
const enforceRange = require('enforce-range')
|
|
41
|
-
|
|
42
|
-
// Maximum only
|
|
43
|
-
enforceRange(null, 100, 200) // 100
|
|
44
|
-
enforceRange(-Infinity, 100, 200) // 100
|
|
45
|
-
|
|
46
|
-
// Minimum only
|
|
47
|
-
enforceRange(0, null, 51) // 51
|
|
48
|
-
enforceRange(0, Infinity, 51) // 51
|
|
49
|
-
|
|
50
|
-
// No range enforcement at all (module does nothing)
|
|
51
|
-
enforceRange(null, null, 12345) // 12345
|
|
52
|
-
enforceRange(-Infinity, Infinity, 12345) // 12345
|
|
53
|
-
```
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Kyle E. Mitchell
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included
|
|
14
|
-
in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
Make "X, Y, and Z"-style lists from arrays.
|
|
2
|
-
|
|
3
|
-
```javascript
|
|
4
|
-
var list = require('english-list')
|
|
5
|
-
var assert = require('assert')
|
|
6
|
-
|
|
7
|
-
assert.equal(
|
|
8
|
-
list('and', ['John']),
|
|
9
|
-
'John'
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
assert.equal(
|
|
13
|
-
list('and', ['John', 'Paul']),
|
|
14
|
-
'John and Paul'
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
assert.equal(
|
|
18
|
-
list('and', ['John', 'Paul', 'George']),
|
|
19
|
-
'John, Paul, and George'
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
assert.equal(
|
|
23
|
-
list('and', ['John', 'Paul', 'George'], false),
|
|
24
|
-
'John, Paul and George'
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
assert.equal(
|
|
28
|
-
list('and', ['John', 'Paul', 'George'], true),
|
|
29
|
-
'John, Paul, and George'
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
assert.equal(
|
|
33
|
-
list('or', ['John', 'Paul', 'George']),
|
|
34
|
-
'John, Paul, or George'
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
assert.throws(function () {
|
|
38
|
-
list('and', null)
|
|
39
|
-
}, TypeError)
|
|
40
|
-
|
|
41
|
-
assert.throws(function () {
|
|
42
|
-
list('and', [])
|
|
43
|
-
}, Error)
|
|
44
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module.exports = function (conjunction, array, serialComma) {
|
|
2
|
-
if (!Array.isArray(array) || !conjunction.toString) {
|
|
3
|
-
throw new TypeError()
|
|
4
|
-
}
|
|
5
|
-
conjunction = conjunction.toString()
|
|
6
|
-
serialComma = serialComma === undefined ? true : !!serialComma
|
|
7
|
-
var length = array.length
|
|
8
|
-
if (length === 0) {
|
|
9
|
-
throw new Error('Cannot create an English list of an empty array')
|
|
10
|
-
} else if (length === 1) {
|
|
11
|
-
return array[0].toString()
|
|
12
|
-
} else if (length === 2) {
|
|
13
|
-
return (
|
|
14
|
-
array[0].toString() +
|
|
15
|
-
' ' +
|
|
16
|
-
conjunction +
|
|
17
|
-
' ' +
|
|
18
|
-
array[1].toString()
|
|
19
|
-
)
|
|
20
|
-
} else {
|
|
21
|
-
var strings = array.map(function (element) {
|
|
22
|
-
return element.toString()
|
|
23
|
-
})
|
|
24
|
-
var front = strings.slice(0, length - 1)
|
|
25
|
-
var last = strings[length - 1]
|
|
26
|
-
return (
|
|
27
|
-
front.join(', ') +
|
|
28
|
-
(serialComma ? ', ' : ' ') +
|
|
29
|
-
conjunction +
|
|
30
|
-
' ' +
|
|
31
|
-
last
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "english-list",
|
|
3
|
-
"description": "make \"X, Y, and Z\"-style lists from arrays",
|
|
4
|
-
"version": "1.0.0",
|
|
5
|
-
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (http://kemitchell.com)",
|
|
6
|
-
"bugs": "https://github.com/kemitchell/english-list.js/issues",
|
|
7
|
-
"devDependencies": {
|
|
8
|
-
"defence-cli": "^2.0.1",
|
|
9
|
-
"literate-assertions": "^0.1.1",
|
|
10
|
-
"replace-require-self": "^1.1.1",
|
|
11
|
-
"standard": "^10.0.3",
|
|
12
|
-
"standard-markdown": "^4.0.2"
|
|
13
|
-
},
|
|
14
|
-
"homepage": "https://github.com/kemitchell/english-list.js",
|
|
15
|
-
"keywords": [
|
|
16
|
-
"array",
|
|
17
|
-
"conjunction",
|
|
18
|
-
"English",
|
|
19
|
-
"enumeration",
|
|
20
|
-
"language",
|
|
21
|
-
"list",
|
|
22
|
-
"natural"
|
|
23
|
-
],
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"repository": "kemitchell/english-list.js",
|
|
26
|
-
"scripts": {
|
|
27
|
-
"travis-ci": "npm run test",
|
|
28
|
-
"lint": "standard && standard-markdown",
|
|
29
|
-
"test": "defence -i javascript README.md | replace-require-self | node"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const copyOwn = require('copy-own')
|
|
4
|
-
const isClassOf = require('is-class-of')
|
|
5
|
-
const is = require('is-instance-of')
|
|
6
|
-
const trimCall = require('trim-call')
|
|
7
|
-
|
|
8
|
-
module.exports = function errate (e, Cls = Error, {defaultMessage, forceClass = true} = {}) {
|
|
9
|
-
if (isClassOf(e, 'Error')) {
|
|
10
|
-
Cls = e
|
|
11
|
-
e = null
|
|
12
|
-
} else if (!isClassOf(Cls, 'Error')) {
|
|
13
|
-
throw new TypeError('Invalid error class')
|
|
14
|
-
}
|
|
15
|
-
if (!e || e === true) return trimCall.new(Cls, defaultMessage)
|
|
16
|
-
if (is(e, Cls)) return e
|
|
17
|
-
if (is(e, 'Error')) return forceClass ? copyOwn(e, new Cls()) : e
|
|
18
|
-
return new Cls(e)
|
|
19
|
-
}
|