aneka 0.13.1 → 0.15.0
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/.jsdoc.conf.json +39 -0
- package/CHANGES.md +8 -0
- package/README.md +64 -1
- package/docs/arrange-array.js.html +28 -0
- package/docs/create-class.js.html +38 -0
- package/docs/current-loc.js.html +34 -0
- package/docs/data/search.json +1 -0
- package/docs/defaults-deep.js.html +23 -0
- package/docs/delay.js.html +19 -0
- package/docs/extract-text.js.html +26 -0
- package/docs/fill-object.js.html +20 -0
- package/docs/filter-duplicate.js.html +29 -0
- package/docs/filter-index.js.html +20 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/format-text.js.html +91 -0
- package/docs/generate-id.js.html +38 -0
- package/docs/get-caller-filename.js.html +28 -0
- package/docs/get-index.js.html +18 -0
- package/docs/get-key-by-value.js.html +15 -0
- package/docs/global.html +12 -0
- package/docs/includes.js.html +21 -0
- package/docs/index.html +17 -0
- package/docs/is-class.js.html +16 -0
- package/docs/is-set.js.html +14 -0
- package/docs/merge-objects-by-key.js.html +27 -0
- package/docs/paginate.js.html +48 -0
- package/docs/parse-args-argv.js.html +85 -0
- package/docs/parse-duration.js.html +17 -0
- package/docs/parse-env.js.html +50 -0
- package/docs/parse-kv-string.js.html +24 -0
- package/docs/parse-object.js.html +79 -0
- package/docs/pascal-case.js.html +17 -0
- package/docs/random-range.js.html +18 -0
- package/docs/resolve-path.js.html +26 -0
- package/docs/round.js.html +16 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sec-to-hms.js.html +30 -0
- package/docs/set-immediate.js.html +15 -0
- package/docs/shim.js.html +31 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/text-to-array.js.html +20 -0
- package/docs/titleize.js.html +40 -0
- package/docs/without.js.html +21 -0
- package/index.js +3 -0
- package/package.json +7 -2
- package/src/arrange-array.js +7 -0
- package/src/create-class.js +8 -0
- package/src/defaults-deep.js +6 -0
- package/src/delay.js +6 -0
- package/src/extract-text.js +8 -0
- package/src/get-caller-filename.js +25 -0
- package/src/get-index.js +7 -0
- package/src/get-key-by-value.js +7 -0
- package/src/includes.js +7 -0
- package/src/is-class.js +6 -0
- package/src/is-set.js +6 -0
- package/src/merge-objects-by-key.js +7 -0
- package/src/paginate.js +17 -1
- package/src/parse-kv-string.js +8 -0
- package/src/parse-object.js +15 -10
- package/src/pascal-case.js +6 -0
- package/src/random-range.js +5 -5
- package/src/resolve-path.js +2 -2
- package/src/round.js +7 -0
- package/src/sec-to-hms.js +7 -0
- package/src/set-immediate.js +3 -1
- package/src/shim.js +3 -5
- package/src/text-to-array.js +6 -0
- package/src/titleize.js +11 -1
- package/src/without.js +10 -0
- package/test/arrange-array.js +41 -0
- package/test/create-class.js +33 -0
- package/test/current-loc.js +24 -0
- package/test/defaults-deep.js +19 -0
- package/test/delay.js +17 -0
- package/test/extract-text.js +17 -0
- package/test/fill-object.js +17 -0
- package/test/filter-duplicate.js +11 -16
- package/test/filter-index.js +9 -16
- package/test/format-text.js +26 -0
- package/test/generate-id.js +28 -0
- package/test/get-caller-filename.js +22 -0
- package/test/get-index.js +17 -0
- package/test/get-key-by-value.js +17 -0
- package/test/includes.js +18 -0
- package/test/is-class.js +19 -0
- package/test/is-set.js +21 -0
- package/test/log.js +47 -0
- package/test/merge-objects-by-key.js +13 -15
- package/test/paginate.js +24 -0
- package/test/parse-args-argv.js +63 -0
- package/test/parse-duration.js +18 -0
- package/test/parse-env.js +35 -0
- package/test/parse-kv-string.js +11 -5
- package/test/parse-object.js +24 -4
- package/test/pascal-case.js +18 -0
- package/test/random-range.js +21 -0
- package/test/resolve-path.js +22 -0
- package/test/round.js +19 -0
- package/test/sec-to-hms.js +18 -0
- package/test/set-immediate.js +17 -0
- package/test/shim.js +34 -0
- package/test/text-to-array.js +18 -0
- package/test/titleize.js +27 -0
- package/test/without.js +17 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/arrange-array.js'
|
|
4
|
+
|
|
5
|
+
describe('arrangeArray', function () {
|
|
6
|
+
it('returns items in original order when no prefix markers are used', function () {
|
|
7
|
+
expect(fn(['a', 'b', 'c'])).to.deep.equal(['a', 'b', 'c'])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('moves ^ prefixed items to the front', function () {
|
|
11
|
+
expect(fn(['a', '^b', 'c'])).to.deep.equal(['b', 'a', 'c'])
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('moves $ prefixed items to the end', function () {
|
|
15
|
+
expect(fn(['a', '$b', 'c'])).to.deep.equal(['a', 'c', 'b'])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('handles both ^ and $ prefixed items in the same array', function () {
|
|
19
|
+
expect(fn(['a', '^b', '$c', 'd'])).to.deep.equal(['b', 'a', 'd', 'c'])
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('preserves order of multiple ^ prefixed items', function () {
|
|
23
|
+
expect(fn(['^a', '^b', 'c'])).to.deep.equal(['a', 'b', 'c'])
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('preserves order of multiple $ prefixed items', function () {
|
|
27
|
+
expect(fn(['a', '$b', '$c'])).to.deep.equal(['a', 'b', 'c'])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('trims items to detect prefix markers but returns original values for non-prefix items', function () {
|
|
31
|
+
expect(fn([' a ', ' ^b ', ' c '])).to.deep.equal(['b', ' a ', ' c '])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('does not detect prefix when trimItem is false and item has leading whitespace', function () {
|
|
35
|
+
expect(fn([' a ', ' ^b '], false)).to.deep.equal([' a ', ' ^b '])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('returns an empty array for empty input', function () {
|
|
39
|
+
expect(fn([])).to.deep.equal([])
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/create-class.js'
|
|
4
|
+
|
|
5
|
+
describe('createClass', function () {
|
|
6
|
+
it('creates class with defaults and parent support', function () {
|
|
7
|
+
const A = fn('A', { a: 1 })
|
|
8
|
+
const a = new A({ b: 2 })
|
|
9
|
+
expect(a).to.include({ a: 1, b: 2 })
|
|
10
|
+
|
|
11
|
+
class Parent {
|
|
12
|
+
constructor (options = {}) {
|
|
13
|
+
this.p = options.p
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const B = fn('B', { x: true }, Parent)
|
|
18
|
+
const b = new B({ p: 7, y: 'ok' })
|
|
19
|
+
expect(b).to.include({ p: 7, x: true, y: 'ok' })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('applies only default properties when no options passed', function () {
|
|
23
|
+
const A = fn('A', { a: 1, b: 2 })
|
|
24
|
+
const a = new A()
|
|
25
|
+
expect(a).to.include({ a: 1, b: 2 })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('lets option values override defaults', function () {
|
|
29
|
+
const A = fn('A', { a: 1 })
|
|
30
|
+
const a = new A({ a: 9 })
|
|
31
|
+
expect(a.a).to.equal(9)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import fn from '../src/current-loc.js'
|
|
5
|
+
|
|
6
|
+
describe('currentLoc', function () {
|
|
7
|
+
it('returns directory and filename aliases', function () {
|
|
8
|
+
const info = fn(import.meta)
|
|
9
|
+
expect(info).to.have.keys(['dir', 'file', '__dirname', '__filename'])
|
|
10
|
+
expect(path.basename(info.dir)).to.equal('test')
|
|
11
|
+
expect(info.file).to.include('/test/current-loc.js')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('keeps alias values in sync', function () {
|
|
15
|
+
const info = fn(import.meta)
|
|
16
|
+
expect(info.dir).to.equal(info.__dirname)
|
|
17
|
+
expect(info.file).to.equal(info.__filename)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('returns absolute file path', function () {
|
|
21
|
+
const info = fn(import.meta)
|
|
22
|
+
expect(path.isAbsolute(info.file)).to.equal(true)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/defaults-deep.js'
|
|
4
|
+
|
|
5
|
+
describe('defaultsDeep', function () {
|
|
6
|
+
it('deep merges objects and replaces arrays by first argument priority', function () {
|
|
7
|
+
const out = fn({ a: { b: 1 }, arr: [1] }, { a: { c: 2 }, arr: [2, 3] })
|
|
8
|
+
expect(out).to.deep.equal({ a: { b: 1, c: 2 }, arr: [1] })
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('returns empty object when no args are given', function () {
|
|
12
|
+
expect(fn()).to.deep.equal({})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('merges more than two objects', function () {
|
|
16
|
+
const out = fn({ a: 1 }, { b: 2 }, { c: 3 })
|
|
17
|
+
expect(out).to.deep.equal({ a: 1, b: 2, c: 3 })
|
|
18
|
+
})
|
|
19
|
+
})
|
package/test/delay.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/delay.js'
|
|
4
|
+
|
|
5
|
+
describe('delay', function () {
|
|
6
|
+
it('resolves after timeout', async function () {
|
|
7
|
+
await fn(1)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('returns a promise', function () {
|
|
11
|
+
expect(fn(1)).to.be.an.instanceof(Promise)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('works with default timeout argument', async function () {
|
|
15
|
+
await fn()
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/extract-text.js'
|
|
4
|
+
|
|
5
|
+
describe('extractText', function () {
|
|
6
|
+
it('extracts text between markers', function () {
|
|
7
|
+
expect(fn('a [x] b', '[', ']')).to.deep.equal({ result: 'x', pattern: '[x]' })
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('returns empty result when start marker is missing', function () {
|
|
11
|
+
expect(fn('a x b', '[', ']')).to.deep.equal({ result: '', pattern: '[]' })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns empty result when end marker is missing', function () {
|
|
15
|
+
expect(fn('a [x b', '[', ']')).to.deep.equal({ result: '', pattern: '[]' })
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/fill-object.js'
|
|
4
|
+
|
|
5
|
+
describe('fillObject', function () {
|
|
6
|
+
it('fills requested keys with default values', function () {
|
|
7
|
+
expect(fn({ a: 1 }, ['a', 'b'], 0)).to.deep.equal({ a: 1, b: 0 })
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('treats null and undefined as missing values', function () {
|
|
11
|
+
expect(fn({ a: null, b: undefined }, ['a', 'b'], 'x')).to.deep.equal({ a: 'x', b: 'x' })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns empty object when key list is empty', function () {
|
|
15
|
+
expect(fn({ a: 1 }, [], 0)).to.deep.equal({})
|
|
16
|
+
})
|
|
17
|
+
})
|
package/test/filter-duplicate.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
1
2
|
import { expect } from 'chai'
|
|
2
3
|
import fn from '../src/filter-duplicate.js'
|
|
3
4
|
|
|
4
5
|
describe('filterDuplicate', function () {
|
|
5
|
-
it('
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
{ id: 2, name: 'two' },
|
|
9
|
-
{ id: 3, name: 'three' }
|
|
10
|
-
]
|
|
11
|
-
const dups = fn(items, 'name')
|
|
12
|
-
expect(dups).to.have.lengthOf(0)
|
|
6
|
+
it('returns duplicated object entries', function () {
|
|
7
|
+
const rows = [{ n: 'a' }, { n: 'b' }, { n: 'a' }]
|
|
8
|
+
expect(fn(rows, 'n')).to.deep.equal([{ n: 'a' }, { n: 'a' }])
|
|
13
9
|
})
|
|
14
10
|
|
|
15
|
-
it('
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
expect(dups).to.have.lengthOf(2)
|
|
11
|
+
it('returns empty array when no duplication exists', function () {
|
|
12
|
+
expect(fn([{ n: 'a' }, { n: 'b' }], 'n')).to.deep.equal([])
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns all entries participating in duplicated keys', function () {
|
|
16
|
+
const rows = [{ n: 'a' }, { n: 'b' }, { n: 'a' }, { n: 'b' }]
|
|
17
|
+
expect(fn(rows, 'n')).to.deep.equal(rows)
|
|
23
18
|
})
|
|
24
19
|
})
|
package/test/filter-index.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
1
2
|
import { expect } from 'chai'
|
|
2
3
|
import fn from '../src/filter-index.js'
|
|
3
4
|
|
|
4
5
|
describe('filterIndex', function () {
|
|
5
|
-
it('
|
|
6
|
-
|
|
7
|
-
{ id: 1, name: 'one' },
|
|
8
|
-
{ id: 2, name: 'two' },
|
|
9
|
-
{ id: 3, name: 'three' }
|
|
10
|
-
]
|
|
11
|
-
const dups = fn(items, item => item.name === 'zero')
|
|
12
|
-
expect(dups).to.have.lengthOf(0)
|
|
6
|
+
it('returns indexes matching predicate', function () {
|
|
7
|
+
expect(fn([1, 2, 3, 4], n => n % 2 === 0)).to.deep.equal([1, 3])
|
|
13
8
|
})
|
|
14
9
|
|
|
15
|
-
it('
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
]
|
|
21
|
-
const dups = fn(items, item => ['one', 'two'].includes(item.name))
|
|
22
|
-
expect(dups).to.eql([0, 1])
|
|
10
|
+
it('returns empty array when no items match', function () {
|
|
11
|
+
expect(fn([1, 3, 5], n => n % 2 === 0)).to.deep.equal([])
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns all indexes when all items match', function () {
|
|
15
|
+
expect(fn([2, 4], n => n % 2 === 0)).to.deep.equal([0, 1])
|
|
23
16
|
})
|
|
24
17
|
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/format-text.js'
|
|
4
|
+
|
|
5
|
+
describe('formatText', function () {
|
|
6
|
+
it('applies sprintf and modifiers', function () {
|
|
7
|
+
expect(fn('hello %s', 'world')).to.equal('hello world')
|
|
8
|
+
expect(fn('Collected %s|toLower|upperFirst', 'iTeMs')).to.equal('Collected Items')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('works as plain sprintf when no modifiers are present', function () {
|
|
12
|
+
expect(fn('Total: %d', 10)).to.equal('Total: 10')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('keeps escaped percent literals', function () {
|
|
16
|
+
expect(fn('Progress %% %d', 50)).to.equal('Progress % 50')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('supports multiple modifiers in sequence', function () {
|
|
20
|
+
expect(fn('Name: %s|trim|pascalCase', ' hello world ')).to.equal('Name: HelloWorld')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('supports secToHms modifier for duration values', function () {
|
|
24
|
+
expect(fn('Elapsed %s|secToHms', 61)).to.equal('Elapsed 01:01')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/generate-id.js'
|
|
4
|
+
|
|
5
|
+
describe('generateId', function () {
|
|
6
|
+
it('generates ids based on options', function () {
|
|
7
|
+
const id = fn()
|
|
8
|
+
expect(id).to.be.a('string')
|
|
9
|
+
expect(id).to.have.lengthOf(13)
|
|
10
|
+
|
|
11
|
+
const alpha = fn('alpha')
|
|
12
|
+
expect(alpha).to.match(/^[a-zA-Z]+$/)
|
|
13
|
+
|
|
14
|
+
const intVal = fn('int')
|
|
15
|
+
expect(intVal).to.be.a('number')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('supports lower and upper case options', function () {
|
|
19
|
+
expect(fn({ case: 'lower' })).to.match(/^[a-z0-9]+$/)
|
|
20
|
+
expect(fn({ case: 'upper' })).to.match(/^[A-Z0-9]+$/)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('returns generator instance when requested', function () {
|
|
24
|
+
const inst = fn({ returnInstance: true })
|
|
25
|
+
expect(inst).to.be.a('function')
|
|
26
|
+
expect(inst()).to.be.a('string')
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/get-caller-filename.js'
|
|
4
|
+
|
|
5
|
+
describe('getCallerFilename', function () {
|
|
6
|
+
it('returns caller path', function () {
|
|
7
|
+
const got = fn()
|
|
8
|
+
expect(got).to.be.a('string')
|
|
9
|
+
expect(got).to.include('/test/get-caller-filename.js')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('returns a stable value on repeated calls', function () {
|
|
13
|
+
const a = fn()
|
|
14
|
+
const b = fn()
|
|
15
|
+
expect(a).to.equal(b)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('returns a path ending with js extension', function () {
|
|
19
|
+
const got = fn()
|
|
20
|
+
expect(got.endsWith('.js')).to.equal(true)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/get-index.js'
|
|
4
|
+
|
|
5
|
+
describe('getIndex', function () {
|
|
6
|
+
it('returns indexes of matching values', function () {
|
|
7
|
+
expect(fn([1, 2, 3, 4], n => n > 2)).to.deep.equal([2, 3])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('returns empty array for empty input', function () {
|
|
11
|
+
expect(fn([], () => true)).to.deep.equal([])
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns all indexes when matcher always true', function () {
|
|
15
|
+
expect(fn(['a', 'b'], () => true)).to.deep.equal([0, 1])
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/get-key-by-value.js'
|
|
4
|
+
|
|
5
|
+
describe('getKeyByValue', function () {
|
|
6
|
+
it('returns key by matching value', function () {
|
|
7
|
+
expect(fn({ a: 1, b: 2 }, 2)).to.equal('b')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('returns undefined when no value is found', function () {
|
|
11
|
+
expect(fn({ a: 1 }, 9)).to.equal(undefined)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns first matching key when values are duplicated', function () {
|
|
15
|
+
expect(fn({ a: 1, b: 1 }, 1)).to.equal('a')
|
|
16
|
+
})
|
|
17
|
+
})
|
package/test/includes.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/includes.js'
|
|
4
|
+
|
|
5
|
+
describe('includes', function () {
|
|
6
|
+
it('checks if any matcher exists in array', function () {
|
|
7
|
+
expect(fn('b', ['a', 'b'])).to.equal(true)
|
|
8
|
+
expect(fn(['x', 'y'], ['a', 'b'])).to.equal(false)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('supports matcher arrays with at least one hit', function () {
|
|
12
|
+
expect(fn(['x', 'b'], ['a', 'b'])).to.equal(true)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns false for empty matcher and array', function () {
|
|
16
|
+
expect(fn([], [])).to.equal(false)
|
|
17
|
+
})
|
|
18
|
+
})
|
package/test/is-class.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/is-class.js'
|
|
4
|
+
|
|
5
|
+
describe('isClass', function () {
|
|
6
|
+
it('identifies class constructors', function () {
|
|
7
|
+
class C {}
|
|
8
|
+
expect(fn(C)).to.equal(true)
|
|
9
|
+
expect(fn(() => {})).to.equal(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('returns false for plain objects', function () {
|
|
13
|
+
expect(fn({})).to.equal(false)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('returns false for null values', function () {
|
|
17
|
+
expect(fn(null)).to.equal(false)
|
|
18
|
+
})
|
|
19
|
+
})
|
package/test/is-set.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/is-set.js'
|
|
4
|
+
|
|
5
|
+
describe('isSet', function () {
|
|
6
|
+
it('returns true for non-null and non-undefined values', function () {
|
|
7
|
+
expect(fn(0)).to.equal(true)
|
|
8
|
+
expect(fn(null)).to.equal(false)
|
|
9
|
+
expect(fn(undefined)).to.equal(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('returns true for empty strings and false booleans', function () {
|
|
13
|
+
expect(fn('')).to.equal(true)
|
|
14
|
+
expect(fn(false)).to.equal(true)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('returns true for empty arrays and objects', function () {
|
|
18
|
+
expect(fn([])).to.equal(true)
|
|
19
|
+
expect(fn({})).to.equal(true)
|
|
20
|
+
})
|
|
21
|
+
})
|
package/test/log.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import { log, logError } from '../src/log.js'
|
|
4
|
+
|
|
5
|
+
describe('log', function () {
|
|
6
|
+
it('calls console log and console error', function () {
|
|
7
|
+
const originalLog = console.log
|
|
8
|
+
const originalError = console.error
|
|
9
|
+
const logs = []
|
|
10
|
+
const errors = []
|
|
11
|
+
console.log = (...args) => logs.push(args)
|
|
12
|
+
console.error = (...args) => errors.push(args)
|
|
13
|
+
try {
|
|
14
|
+
log('Hello %s', 'world')
|
|
15
|
+
logError('Oops %s', 'x')
|
|
16
|
+
expect(logs.length).to.equal(1)
|
|
17
|
+
expect(errors.length).to.equal(1)
|
|
18
|
+
} finally {
|
|
19
|
+
console.log = originalLog
|
|
20
|
+
console.error = originalError
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('passes non-string items directly to console.log', function () {
|
|
25
|
+
const originalLog = console.log
|
|
26
|
+
const logs = []
|
|
27
|
+
console.log = (...args) => logs.push(args)
|
|
28
|
+
try {
|
|
29
|
+
log({ a: 1 })
|
|
30
|
+
expect(logs[0][0]).to.deep.equal({ a: 1 })
|
|
31
|
+
} finally {
|
|
32
|
+
console.log = originalLog
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('formats string labels with timestamp prefix', function () {
|
|
37
|
+
const originalLog = console.log
|
|
38
|
+
const logs = []
|
|
39
|
+
console.log = (...args) => logs.push(args)
|
|
40
|
+
try {
|
|
41
|
+
log('Value %d', 7)
|
|
42
|
+
expect(logs[0][0]).to.match(/^\[[^\]]+\] Value 7$/)
|
|
43
|
+
} finally {
|
|
44
|
+
console.log = originalLog
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
})
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
1
2
|
import { expect } from 'chai'
|
|
2
3
|
import fn from '../src/merge-objects-by-key.js'
|
|
3
4
|
|
|
4
5
|
describe('mergeObjectsByKey', function () {
|
|
5
|
-
it('
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]
|
|
18
|
-
const result = fn(items, 'id')
|
|
19
|
-
expect(result).to.eql(expected)
|
|
6
|
+
it('merges object entries sharing same key', function () {
|
|
7
|
+
const out = fn([{ id: 1, a: 1 }, { id: 1, b: 2 }, { id: 2, c: 3 }], 'id')
|
|
8
|
+
expect(out).to.deep.equal([{ id: 1, a: 1, b: 2 }, { id: 2, c: 3 }])
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('returns empty array for empty input', function () {
|
|
12
|
+
expect(fn([], 'id')).to.deep.equal([])
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('keeps single items unchanged', function () {
|
|
16
|
+
const input = [{ id: 7, x: true }]
|
|
17
|
+
expect(fn(input, 'id')).to.deep.equal(input)
|
|
20
18
|
})
|
|
21
19
|
})
|
package/test/paginate.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/paginate.js'
|
|
4
|
+
|
|
5
|
+
describe('paginate', function () {
|
|
6
|
+
it('returns sorted paginated result with metadata', function () {
|
|
7
|
+
const out = fn([{ n: 2 }, { n: 1 }, { n: 3 }], { page: 1, limit: 2, sort: { n: 1 } })
|
|
8
|
+
expect(out.data).to.deep.equal([{ n: 1 }, { n: 2 }])
|
|
9
|
+
expect(out.count).to.equal(3)
|
|
10
|
+
expect(out.pages).to.equal(2)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('uses default options when omitted', function () {
|
|
14
|
+
const out = fn([{ n: 1 }])
|
|
15
|
+
expect(out.page).to.equal(1)
|
|
16
|
+
expect(out.limit).to.equal(25)
|
|
17
|
+
expect(out.data).to.deep.equal([{ n: 1 }])
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('supports descending sort order', function () {
|
|
21
|
+
const out = fn([{ n: 1 }, { n: 3 }, { n: 2 }], { sort: { n: -1 } })
|
|
22
|
+
expect(out.data.map(i => i.n)).to.deep.equal([3, 2, 1])
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/parse-args-argv.js'
|
|
4
|
+
|
|
5
|
+
describe('parseArgsArgv', function () {
|
|
6
|
+
it('parses process argv using parser mode', async function () {
|
|
7
|
+
const original = process.argv
|
|
8
|
+
process.argv = ['node', 'cli.js', '--foo=bar', '--app:key=10']
|
|
9
|
+
try {
|
|
10
|
+
const out = await fn({ useParser: true })
|
|
11
|
+
expect(out.args).to.deep.equal([])
|
|
12
|
+
expect(out.argv._.foo).to.equal('bar')
|
|
13
|
+
expect(out.argv.app.key).to.equal(10)
|
|
14
|
+
} finally {
|
|
15
|
+
process.argv = original
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('returns positional args in args output', async function () {
|
|
20
|
+
const original = process.argv
|
|
21
|
+
process.argv = ['node', 'cli.js', 'first', 'second']
|
|
22
|
+
try {
|
|
23
|
+
const out = await fn({ useParser: true })
|
|
24
|
+
expect(out.args).to.deep.equal(['first', 'second'])
|
|
25
|
+
} finally {
|
|
26
|
+
process.argv = original
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('applies sanitizer when provided', async function () {
|
|
31
|
+
const original = process.argv
|
|
32
|
+
process.argv = ['node', 'cli.js', '--foo=bar']
|
|
33
|
+
try {
|
|
34
|
+
const out = await fn({ useParser: true, sanitizer: item => ({ ...item, marked: true }) })
|
|
35
|
+
expect(out.argv.marked).to.equal(true)
|
|
36
|
+
} finally {
|
|
37
|
+
process.argv = original
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('auto-enables parser mode when --spawn flag exists', async function () {
|
|
42
|
+
const original = process.argv
|
|
43
|
+
process.argv = ['node', 'cli.js', '--spawn=1', '--foo=bar']
|
|
44
|
+
try {
|
|
45
|
+
const out = await fn()
|
|
46
|
+
expect(out.argv._.spawn).to.equal(1)
|
|
47
|
+
expect(out.argv._.foo).to.equal('bar')
|
|
48
|
+
} finally {
|
|
49
|
+
process.argv = original
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('unflattens hyphenated keys in underscore group', async function () {
|
|
54
|
+
const original = process.argv
|
|
55
|
+
process.argv = ['node', 'cli.js', '--db-host=localhost']
|
|
56
|
+
try {
|
|
57
|
+
const out = await fn({ useParser: true })
|
|
58
|
+
expect(out.argv._.db.host).to.equal('localhost')
|
|
59
|
+
} finally {
|
|
60
|
+
process.argv = original
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/parse-duration.js'
|
|
4
|
+
|
|
5
|
+
describe('parseDuration', function () {
|
|
6
|
+
it('converts duration strings and keeps numbers as is', function () {
|
|
7
|
+
expect(fn('1s')).to.equal(1000)
|
|
8
|
+
expect(fn(123)).to.equal(123)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('converts minute values correctly', function () {
|
|
12
|
+
expect(fn('2m')).to.equal(120000)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns undefined for invalid duration text', function () {
|
|
16
|
+
expect(fn('not-a-duration')).to.equal(undefined)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/parse-env.js'
|
|
4
|
+
|
|
5
|
+
describe('parseEnv', function () {
|
|
6
|
+
it('parses and normalizes env keys', function () {
|
|
7
|
+
const old = process.env.ANEKA_TEST_VALUE
|
|
8
|
+
process.env.ANEKA_TEST_VALUE = '42'
|
|
9
|
+
try {
|
|
10
|
+
const out = fn()
|
|
11
|
+
expect(out._.anekaTestValue).to.equal(42)
|
|
12
|
+
} finally {
|
|
13
|
+
if (old === undefined) delete process.env.ANEKA_TEST_VALUE
|
|
14
|
+
else process.env.ANEKA_TEST_VALUE = old
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('parses nested keys using dot and double underscore separators', function () {
|
|
19
|
+
const old = process.env['ANEKA_DB.PORT']
|
|
20
|
+
process.env['ANEKA_DB.PORT'] = '5432'
|
|
21
|
+
try {
|
|
22
|
+
const out = fn()
|
|
23
|
+
expect(out.anekaDb).to.be.an('object')
|
|
24
|
+
expect(out.anekaDb.port).to.equal(5432)
|
|
25
|
+
} finally {
|
|
26
|
+
if (old === undefined) delete process.env['ANEKA_DB.PORT']
|
|
27
|
+
else process.env['ANEKA_DB.PORT'] = old
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('applies sanitizer when provided', function () {
|
|
32
|
+
const out = fn(item => ({ ...item, __sanitized: true }))
|
|
33
|
+
expect(out.__sanitized).to.equal(true)
|
|
34
|
+
})
|
|
35
|
+
})
|