aneka 0.17.5 → 0.17.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsdoc.conf.json +0 -0
- package/CHANGES.md +87 -79
- package/LICENSE +21 -21
- package/README.md +63 -63
- package/docs/arrange-array.js.html +0 -0
- package/docs/create-class.js.html +0 -0
- package/docs/current-loc.js.html +0 -0
- package/docs/data/search.json +0 -0
- package/docs/defaults-deep.js.html +0 -0
- package/docs/delay.js.html +0 -0
- package/docs/extract-text.js.html +0 -0
- package/docs/fill-object.js.html +0 -0
- package/docs/filter-duplicate.js.html +0 -0
- package/docs/filter-index.js.html +0 -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 +0 -0
- package/docs/generate-id.js.html +0 -0
- package/docs/get-caller-filename.js.html +0 -0
- package/docs/get-global-module-dir.js.html +0 -0
- package/docs/get-index.js.html +0 -0
- package/docs/get-key-by-value.js.html +0 -0
- package/docs/global.html +0 -0
- package/docs/includes.js.html +0 -0
- package/docs/index.html +0 -0
- package/docs/is-class.js.html +0 -0
- package/docs/is-set.js.html +0 -0
- package/docs/merge-objects-by-key.js.html +0 -0
- package/docs/paginate.js.html +0 -0
- package/docs/parse-args-argv.js.html +0 -0
- package/docs/parse-duration.js.html +0 -0
- package/docs/parse-env.js.html +0 -0
- package/docs/parse-kv-string.js.html +0 -0
- package/docs/parse-object.js.html +0 -0
- package/docs/pascal-case.js.html +0 -0
- package/docs/random-range.js.html +0 -0
- package/docs/resolve-path.js.html +0 -0
- package/docs/round.js.html +0 -0
- package/docs/scripts/core.js +0 -0
- package/docs/scripts/core.min.js +0 -0
- package/docs/scripts/resize.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/scripts/search.min.js +5 -5
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
- package/docs/scripts/third-party/fuse.js +0 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -0
- package/docs/scripts/third-party/hljs-line-num.js +0 -0
- package/docs/scripts/third-party/hljs-original.js +0 -0
- package/docs/scripts/third-party/hljs.js +0 -0
- package/docs/scripts/third-party/popper.js +0 -0
- package/docs/scripts/third-party/tippy.js +0 -0
- package/docs/scripts/third-party/tocbot.js +0 -0
- package/docs/scripts/third-party/tocbot.min.js +0 -0
- package/docs/sec-to-hms.js.html +0 -0
- package/docs/set-immediate.js.html +0 -0
- package/docs/set-interval.js.html +0 -0
- package/docs/set-timeout.js.html +0 -0
- package/docs/shim.js.html +0 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +0 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
- package/docs/styles/clean-jsdoc-theme-light.css +0 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
- package/docs/styles/clean-jsdoc-theme.min.css +0 -0
- package/docs/text-to-array.js.html +0 -0
- package/docs/titleize.js.html +0 -0
- package/docs/without.js.html +0 -0
- package/index.js +119 -119
- package/package.json +48 -48
- package/src/arrange-array.js +25 -25
- package/src/create-class.js +35 -35
- package/src/current-loc.js +0 -0
- package/src/defaults-deep.js +20 -20
- package/src/delay.js +19 -19
- package/src/extract-text.js +23 -23
- package/src/fill-object.js +17 -17
- package/src/filter-duplicate.js +26 -26
- package/src/filter-index.js +17 -17
- package/src/format-text.js +88 -88
- package/src/generate-id.js +35 -35
- package/src/get-caller-filename.js +25 -25
- package/src/get-global-module-dir.js +24 -20
- package/src/get-index.js +15 -15
- package/src/get-key-by-value.js +12 -12
- package/src/includes.js +18 -18
- package/src/is-class.js +13 -13
- package/src/is-set.js +11 -11
- package/src/log.js +19 -19
- package/src/merge-objects-by-key.js +24 -24
- package/src/paginate.js +45 -45
- package/src/parse-args-argv.js +0 -0
- package/src/parse-duration.js +14 -14
- package/src/parse-env.js +0 -0
- package/src/parse-kv-string.js +21 -21
- package/src/parse-object.js +76 -76
- package/src/pascal-case.js +14 -14
- package/src/random-range.js +15 -15
- package/src/resolve-path.js +0 -0
- package/src/round.js +13 -13
- package/src/sec-to-hms.js +27 -27
- package/src/set-immediate.js +12 -12
- package/src/set-interval.js +56 -55
- package/src/set-timeout.js +34 -34
- package/src/shim.js +28 -28
- package/src/text-to-array.js +17 -17
- package/src/titleize.js +37 -37
- package/src/without.js +18 -18
- package/test/arrange-array.js +41 -41
- package/test/create-class.js +33 -33
- package/test/current-loc.js +24 -24
- package/test/defaults-deep.js +19 -19
- package/test/delay.js +17 -17
- package/test/extract-text.js +17 -17
- package/test/fill-object.js +17 -17
- package/test/filter-duplicate.js +19 -19
- package/test/filter-index.js +17 -17
- package/test/format-text.js +26 -26
- package/test/generate-id.js +28 -28
- package/test/get-caller-filename.js +22 -22
- package/test/get-global-module-dir.js +51 -51
- package/test/get-index.js +17 -17
- package/test/get-key-by-value.js +17 -17
- package/test/includes.js +18 -18
- package/test/is-class.js +19 -19
- package/test/is-set.js +21 -21
- package/test/log.js +47 -47
- package/test/merge-objects-by-key.js +19 -19
- package/test/paginate.js +24 -24
- package/test/parse-args-argv.js +63 -63
- package/test/parse-duration.js +18 -18
- package/test/parse-env.js +35 -35
- package/test/parse-kv-string.js +17 -17
- package/test/parse-object.js +30 -30
- package/test/pascal-case.js +18 -18
- package/test/random-range.js +21 -21
- package/test/resolve-path.js +22 -22
- package/test/round.js +19 -19
- package/test/sec-to-hms.js +18 -18
- package/test/set-immediate.js +17 -17
- package/test/set-interval.js +196 -180
- package/test/set-timeout.js +120 -120
- package/test/shim.js +34 -34
- package/test/text-to-array.js +18 -18
- package/test/titleize.js +27 -27
- package/test/without.js +17 -17
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/merge-objects-by-key.js'
|
|
4
|
-
|
|
5
|
-
describe('mergeObjectsByKey', function () {
|
|
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)
|
|
18
|
-
})
|
|
19
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/merge-objects-by-key.js'
|
|
4
|
+
|
|
5
|
+
describe('mergeObjectsByKey', function () {
|
|
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)
|
|
18
|
+
})
|
|
19
|
+
})
|
package/test/paginate.js
CHANGED
|
@@ -1,24 +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
|
-
})
|
|
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
|
+
})
|
package/test/parse-args-argv.js
CHANGED
|
@@ -1,63 +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
|
-
})
|
|
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
|
+
})
|
package/test/parse-duration.js
CHANGED
|
@@ -1,18 +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
|
-
})
|
|
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
|
+
})
|
package/test/parse-env.js
CHANGED
|
@@ -1,35 +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
|
-
})
|
|
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
|
+
})
|
package/test/parse-kv-string.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/parse-kv-string.js'
|
|
4
|
-
|
|
5
|
-
describe('parseKvString', function () {
|
|
6
|
-
it('parses key-value text into typed object', function () {
|
|
7
|
-
expect(fn('A=1|B=true|C=text')).to.deep.equal({ A: 1, B: true, C: 'text' })
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('supports custom line delimiters', function () {
|
|
11
|
-
expect(fn('A=1;B=2', true, ';')).to.deep.equal({ A: 1, B: 2 })
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('respects trimValue=false', function () {
|
|
15
|
-
expect(fn('A= hello ', false)).to.deep.equal({ A: ' hello ' })
|
|
16
|
-
})
|
|
17
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/parse-kv-string.js'
|
|
4
|
+
|
|
5
|
+
describe('parseKvString', function () {
|
|
6
|
+
it('parses key-value text into typed object', function () {
|
|
7
|
+
expect(fn('A=1|B=true|C=text')).to.deep.equal({ A: 1, B: true, C: 'text' })
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('supports custom line delimiters', function () {
|
|
11
|
+
expect(fn('A=1;B=2', true, ';')).to.deep.equal({ A: 1, B: 2 })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('respects trimValue=false', function () {
|
|
15
|
+
expect(fn('A= hello ', false)).to.deep.equal({ A: ' hello ' })
|
|
16
|
+
})
|
|
17
|
+
})
|
package/test/parse-object.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/parse-object.js'
|
|
4
|
-
|
|
5
|
-
describe('parseObject', function () {
|
|
6
|
-
it('parses nested values recursively', function () {
|
|
7
|
-
const out = fn({ num: '1', nested: { ok: 'true' }, ttlDur: '2s' }, { parseValue: true })
|
|
8
|
-
expect(out.num).to.equal(1)
|
|
9
|
-
expect(out.nested.ok).to.equal(true)
|
|
10
|
-
expect(out.ttlDur).to.equal(2000)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('accepts JSON string input', function () {
|
|
14
|
-
const out = fn('{"enabled":"true","count":"2"}', { parseValue: true })
|
|
15
|
-
expect(out).to.deep.equal({ enabled: true, count: 2 })
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('throws invalid json when silent is false', function () {
|
|
19
|
-
expect(() => fn('{ bad', { silent: false })).to.throw()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('returns empty object for invalid json when silent is true', function () {
|
|
23
|
-
expect(fn('{ bad', { silent: true })).to.deep.equal({})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('keeps static wildcard values unchanged', function () {
|
|
27
|
-
const out = fn({ marker: '*', nested: { marker: '*' } }, { parseValue: true })
|
|
28
|
-
expect(out).to.deep.equal({ marker: '*', nested: { marker: '*' } })
|
|
29
|
-
})
|
|
30
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/parse-object.js'
|
|
4
|
+
|
|
5
|
+
describe('parseObject', function () {
|
|
6
|
+
it('parses nested values recursively', function () {
|
|
7
|
+
const out = fn({ num: '1', nested: { ok: 'true' }, ttlDur: '2s' }, { parseValue: true })
|
|
8
|
+
expect(out.num).to.equal(1)
|
|
9
|
+
expect(out.nested.ok).to.equal(true)
|
|
10
|
+
expect(out.ttlDur).to.equal(2000)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('accepts JSON string input', function () {
|
|
14
|
+
const out = fn('{"enabled":"true","count":"2"}', { parseValue: true })
|
|
15
|
+
expect(out).to.deep.equal({ enabled: true, count: 2 })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('throws invalid json when silent is false', function () {
|
|
19
|
+
expect(() => fn('{ bad', { silent: false })).to.throw()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('returns empty object for invalid json when silent is true', function () {
|
|
23
|
+
expect(fn('{ bad', { silent: true })).to.deep.equal({})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('keeps static wildcard values unchanged', function () {
|
|
27
|
+
const out = fn({ marker: '*', nested: { marker: '*' } }, { parseValue: true })
|
|
28
|
+
expect(out).to.deep.equal({ marker: '*', nested: { marker: '*' } })
|
|
29
|
+
})
|
|
30
|
+
})
|
package/test/pascal-case.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/pascal-case.js'
|
|
4
|
-
|
|
5
|
-
describe('pascalCase', function () {
|
|
6
|
-
it('converts text to PascalCase', function () {
|
|
7
|
-
expect(fn('hello world')).to.equal('HelloWorld')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('handles snake and kebab case input', function () {
|
|
11
|
-
expect(fn('hello_world')).to.equal('HelloWorld')
|
|
12
|
-
expect(fn('hello-world')).to.equal('HelloWorld')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('handles already-camelized input', function () {
|
|
16
|
-
expect(fn('helloWorld')).to.equal('HelloWorld')
|
|
17
|
-
})
|
|
18
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/pascal-case.js'
|
|
4
|
+
|
|
5
|
+
describe('pascalCase', function () {
|
|
6
|
+
it('converts text to PascalCase', function () {
|
|
7
|
+
expect(fn('hello world')).to.equal('HelloWorld')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('handles snake and kebab case input', function () {
|
|
11
|
+
expect(fn('hello_world')).to.equal('HelloWorld')
|
|
12
|
+
expect(fn('hello-world')).to.equal('HelloWorld')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('handles already-camelized input', function () {
|
|
16
|
+
expect(fn('helloWorld')).to.equal('HelloWorld')
|
|
17
|
+
})
|
|
18
|
+
})
|
package/test/random-range.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/random-range.js'
|
|
4
|
-
|
|
5
|
-
describe('randomRange', function () {
|
|
6
|
-
it('returns number and alpha values in expected range', function () {
|
|
7
|
-
const n = fn(1, 3)
|
|
8
|
-
expect(n).to.be.within(1, 3)
|
|
9
|
-
|
|
10
|
-
const ch = fn(1, 26, true)
|
|
11
|
-
expect(ch).to.match(/^[a-z]$/)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('returns deterministic value when min equals max', function () {
|
|
15
|
-
expect(fn(5, 5)).to.equal(5)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('returns expected alpha character when min equals max', function () {
|
|
19
|
-
expect(fn(1, 1, true)).to.equal('a')
|
|
20
|
-
})
|
|
21
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/random-range.js'
|
|
4
|
+
|
|
5
|
+
describe('randomRange', function () {
|
|
6
|
+
it('returns number and alpha values in expected range', function () {
|
|
7
|
+
const n = fn(1, 3)
|
|
8
|
+
expect(n).to.be.within(1, 3)
|
|
9
|
+
|
|
10
|
+
const ch = fn(1, 26, true)
|
|
11
|
+
expect(ch).to.match(/^[a-z]$/)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns deterministic value when min equals max', function () {
|
|
15
|
+
expect(fn(5, 5)).to.equal(5)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('returns expected alpha character when min equals max', function () {
|
|
19
|
+
expect(fn(1, 1, true)).to.equal('a')
|
|
20
|
+
})
|
|
21
|
+
})
|
package/test/resolve-path.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import fn from '../src/resolve-path.js'
|
|
5
|
-
|
|
6
|
-
describe('resolvePath', function () {
|
|
7
|
-
it('resolves paths and can return file URL', function () {
|
|
8
|
-
const resolved = fn('./src/../src/round.js')
|
|
9
|
-
expect(path.isAbsolute(resolved)).to.equal(true)
|
|
10
|
-
const asUrl = fn('./src/round.js', true)
|
|
11
|
-
expect(asUrl.startsWith('file:///')).to.equal(true)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('resolves file urls back to absolute paths', function () {
|
|
15
|
-
const pathValue = fn('file:///tmp/example.txt')
|
|
16
|
-
expect(path.isAbsolute(pathValue)).to.equal(true)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('returns absolute path for relative input', function () {
|
|
20
|
-
expect(path.isAbsolute(fn('./README.md'))).to.equal(true)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import fn from '../src/resolve-path.js'
|
|
5
|
+
|
|
6
|
+
describe('resolvePath', function () {
|
|
7
|
+
it('resolves paths and can return file URL', function () {
|
|
8
|
+
const resolved = fn('./src/../src/round.js')
|
|
9
|
+
expect(path.isAbsolute(resolved)).to.equal(true)
|
|
10
|
+
const asUrl = fn('./src/round.js', true)
|
|
11
|
+
expect(asUrl.startsWith('file:///')).to.equal(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('resolves file urls back to absolute paths', function () {
|
|
15
|
+
const pathValue = fn('file:///tmp/example.txt')
|
|
16
|
+
expect(path.isAbsolute(pathValue)).to.equal(true)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('returns absolute path for relative input', function () {
|
|
20
|
+
expect(path.isAbsolute(fn('./README.md'))).to.equal(true)
|
|
21
|
+
})
|
|
22
|
+
})
|
package/test/round.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/round.js'
|
|
4
|
-
|
|
5
|
-
describe('round', function () {
|
|
6
|
-
it('rounds numeric values with scale', function () {
|
|
7
|
-
expect(fn(1.2345, 2)).to.equal(1.23)
|
|
8
|
-
expect(fn(1.9)).to.equal(2)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('uses integer rounding when scale is zero or negative', function () {
|
|
12
|
-
expect(fn(1.49, 0)).to.equal(1)
|
|
13
|
-
expect(fn(1.51, -3)).to.equal(2)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('handles negative numbers', function () {
|
|
17
|
-
expect(fn(-1.234, 2)).to.equal(-1.23)
|
|
18
|
-
})
|
|
19
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/round.js'
|
|
4
|
+
|
|
5
|
+
describe('round', function () {
|
|
6
|
+
it('rounds numeric values with scale', function () {
|
|
7
|
+
expect(fn(1.2345, 2)).to.equal(1.23)
|
|
8
|
+
expect(fn(1.9)).to.equal(2)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('uses integer rounding when scale is zero or negative', function () {
|
|
12
|
+
expect(fn(1.49, 0)).to.equal(1)
|
|
13
|
+
expect(fn(1.51, -3)).to.equal(2)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('handles negative numbers', function () {
|
|
17
|
+
expect(fn(-1.234, 2)).to.equal(-1.23)
|
|
18
|
+
})
|
|
19
|
+
})
|
package/test/sec-to-hms.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/sec-to-hms.js'
|
|
4
|
-
|
|
5
|
-
describe('secToHms', function () {
|
|
6
|
-
it('formats seconds and milliseconds', function () {
|
|
7
|
-
expect(fn(61)).to.equal('01:01')
|
|
8
|
-
expect(fn(12345, true)).to.equal('00:12+345')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('includes hours for long durations', function () {
|
|
12
|
-
expect(fn(3661)).to.equal('01:01:01')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('formats zero as 00:00', function () {
|
|
16
|
-
expect(fn(0)).to.equal('00:00')
|
|
17
|
-
})
|
|
18
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/sec-to-hms.js'
|
|
4
|
+
|
|
5
|
+
describe('secToHms', function () {
|
|
6
|
+
it('formats seconds and milliseconds', function () {
|
|
7
|
+
expect(fn(61)).to.equal('01:01')
|
|
8
|
+
expect(fn(12345, true)).to.equal('00:12+345')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('includes hours for long durations', function () {
|
|
12
|
+
expect(fn(3661)).to.equal('01:01:01')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('formats zero as 00:00', function () {
|
|
16
|
+
expect(fn(0)).to.equal('00:00')
|
|
17
|
+
})
|
|
18
|
+
})
|
package/test/set-immediate.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import fn from '../src/set-immediate.js'
|
|
4
|
-
|
|
5
|
-
describe('setImmediate', function () {
|
|
6
|
-
it('exports a callable function', function () {
|
|
7
|
-
expect(fn).to.be.a('function')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('takes no required parameters', function () {
|
|
11
|
-
expect(fn.length).to.equal(0)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('is declared as async function', function () {
|
|
15
|
-
expect(fn.constructor.name).to.equal('AsyncFunction')
|
|
16
|
-
})
|
|
17
|
-
})
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import fn from '../src/set-immediate.js'
|
|
4
|
+
|
|
5
|
+
describe('setImmediate', function () {
|
|
6
|
+
it('exports a callable function', function () {
|
|
7
|
+
expect(fn).to.be.a('function')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('takes no required parameters', function () {
|
|
11
|
+
expect(fn.length).to.equal(0)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('is declared as async function', function () {
|
|
15
|
+
expect(fn.constructor.name).to.equal('AsyncFunction')
|
|
16
|
+
})
|
|
17
|
+
})
|