aneka 0.14.0 → 0.16.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.
Files changed (129) hide show
  1. package/.jsdoc.conf.json +39 -0
  2. package/CHANGES.md +8 -0
  3. package/README.md +64 -1
  4. package/docs/arrange-array.js.html +28 -0
  5. package/docs/create-class.js.html +38 -0
  6. package/docs/current-loc.js.html +34 -0
  7. package/docs/data/search.json +1 -0
  8. package/docs/defaults-deep.js.html +23 -0
  9. package/docs/delay.js.html +19 -0
  10. package/docs/extract-text.js.html +26 -0
  11. package/docs/fill-object.js.html +20 -0
  12. package/docs/filter-duplicate.js.html +29 -0
  13. package/docs/filter-index.js.html +20 -0
  14. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  15. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  16. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  17. package/docs/format-text.js.html +91 -0
  18. package/docs/generate-id.js.html +38 -0
  19. package/docs/get-caller-filename.js.html +28 -0
  20. package/docs/get-index.js.html +18 -0
  21. package/docs/get-key-by-value.js.html +15 -0
  22. package/docs/global.html +12 -0
  23. package/docs/includes.js.html +21 -0
  24. package/docs/index.html +17 -0
  25. package/docs/is-class.js.html +16 -0
  26. package/docs/is-set.js.html +14 -0
  27. package/docs/merge-objects-by-key.js.html +27 -0
  28. package/docs/paginate.js.html +48 -0
  29. package/docs/parse-args-argv.js.html +85 -0
  30. package/docs/parse-duration.js.html +17 -0
  31. package/docs/parse-env.js.html +50 -0
  32. package/docs/parse-kv-string.js.html +24 -0
  33. package/docs/parse-object.js.html +79 -0
  34. package/docs/pascal-case.js.html +17 -0
  35. package/docs/random-range.js.html +18 -0
  36. package/docs/resolve-path.js.html +26 -0
  37. package/docs/round.js.html +16 -0
  38. package/docs/scripts/core.js +726 -0
  39. package/docs/scripts/core.min.js +23 -0
  40. package/docs/scripts/resize.js +90 -0
  41. package/docs/scripts/search.js +265 -0
  42. package/docs/scripts/search.min.js +6 -0
  43. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  44. package/docs/scripts/third-party/fuse.js +9 -0
  45. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  46. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  47. package/docs/scripts/third-party/hljs-original.js +5171 -0
  48. package/docs/scripts/third-party/hljs.js +1 -0
  49. package/docs/scripts/third-party/popper.js +5 -0
  50. package/docs/scripts/third-party/tippy.js +1 -0
  51. package/docs/scripts/third-party/tocbot.js +672 -0
  52. package/docs/scripts/third-party/tocbot.min.js +1 -0
  53. package/docs/sec-to-hms.js.html +30 -0
  54. package/docs/set-immediate.js.html +15 -0
  55. package/docs/shim.js.html +31 -0
  56. package/docs/static/bitcoin.jpeg +0 -0
  57. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  58. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  59. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  60. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  61. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  62. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  63. package/docs/text-to-array.js.html +20 -0
  64. package/docs/titleize.js.html +40 -0
  65. package/docs/without.js.html +21 -0
  66. package/index.js +3 -0
  67. package/package.json +7 -2
  68. package/src/arrange-array.js +7 -0
  69. package/src/create-class.js +8 -0
  70. package/src/defaults-deep.js +6 -0
  71. package/src/delay.js +6 -0
  72. package/src/extract-text.js +8 -0
  73. package/src/get-caller-filename.js +5 -0
  74. package/src/get-global-module-dir.js +20 -0
  75. package/src/get-index.js +7 -0
  76. package/src/get-key-by-value.js +7 -0
  77. package/src/includes.js +7 -0
  78. package/src/is-class.js +6 -0
  79. package/src/is-set.js +6 -0
  80. package/src/merge-objects-by-key.js +7 -0
  81. package/src/paginate.js +17 -1
  82. package/src/parse-kv-string.js +8 -0
  83. package/src/parse-object.js +15 -10
  84. package/src/pascal-case.js +6 -0
  85. package/src/random-range.js +5 -5
  86. package/src/resolve-path.js +2 -2
  87. package/src/round.js +7 -0
  88. package/src/sec-to-hms.js +7 -0
  89. package/src/set-immediate.js +3 -1
  90. package/src/shim.js +3 -5
  91. package/src/text-to-array.js +6 -0
  92. package/src/titleize.js +11 -1
  93. package/src/without.js +10 -0
  94. package/test/arrange-array.js +41 -0
  95. package/test/create-class.js +33 -0
  96. package/test/current-loc.js +24 -0
  97. package/test/defaults-deep.js +19 -0
  98. package/test/delay.js +17 -0
  99. package/test/extract-text.js +17 -0
  100. package/test/fill-object.js +17 -0
  101. package/test/filter-duplicate.js +11 -16
  102. package/test/filter-index.js +9 -16
  103. package/test/format-text.js +26 -0
  104. package/test/generate-id.js +28 -0
  105. package/test/get-caller-filename.js +22 -0
  106. package/test/get-global-module-dir.js +51 -0
  107. package/test/get-index.js +17 -0
  108. package/test/get-key-by-value.js +17 -0
  109. package/test/includes.js +18 -0
  110. package/test/is-class.js +19 -0
  111. package/test/is-set.js +21 -0
  112. package/test/log.js +47 -0
  113. package/test/merge-objects-by-key.js +13 -15
  114. package/test/paginate.js +24 -0
  115. package/test/parse-args-argv.js +63 -0
  116. package/test/parse-duration.js +18 -0
  117. package/test/parse-env.js +35 -0
  118. package/test/parse-kv-string.js +11 -5
  119. package/test/parse-object.js +24 -4
  120. package/test/pascal-case.js +18 -0
  121. package/test/random-range.js +21 -0
  122. package/test/resolve-path.js +22 -0
  123. package/test/round.js +19 -0
  124. package/test/sec-to-hms.js +18 -0
  125. package/test/set-immediate.js +17 -0
  126. package/test/shim.js +34 -0
  127. package/test/text-to-array.js +18 -0
  128. package/test/titleize.js +27 -0
  129. 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
+ })
@@ -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('No duplication', function () {
6
- const items = [
7
- { id: 1, name: 'one' },
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('Two duplications', function () {
16
- const items = [
17
- { id: 1, name: 'one' },
18
- { id: 2, name: 'one' },
19
- { id: 3, name: 'three' }
20
- ]
21
- const dups = fn(items, 'name')
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
  })
@@ -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('Nothing found', function () {
6
- const items = [
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('Found 2 items', function () {
16
- const items = [
17
- { id: 1, name: 'one' },
18
- { id: 2, name: 'two' },
19
- { id: 3, name: 'three' }
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,51 @@
1
+ /* eslint-env mocha */
2
+ import { expect } from 'chai'
3
+ import path from 'path'
4
+ import fn from '../src/get-global-module-dir.js'
5
+
6
+ const originalPlatformDesc = Object.getOwnPropertyDescriptor(process, 'platform')
7
+ const originalExecPathDesc = Object.getOwnPropertyDescriptor(process, 'execPath')
8
+ const originalAppData = process.env.APPDATA
9
+
10
+ function setProcessProp (name, value) {
11
+ Object.defineProperty(process, name, {
12
+ value,
13
+ configurable: true
14
+ })
15
+ }
16
+
17
+ describe('getGlobalModuleDir', function () {
18
+ afterEach(function () {
19
+ if (originalPlatformDesc) Object.defineProperty(process, 'platform', originalPlatformDesc)
20
+ if (originalExecPathDesc) Object.defineProperty(process, 'execPath', originalExecPathDesc)
21
+
22
+ if (originalAppData === undefined) delete process.env.APPDATA
23
+ else process.env.APPDATA = originalAppData
24
+ })
25
+
26
+ it('returns lib/node_modules for non-win32 platforms', function () {
27
+ setProcessProp('platform', 'linux')
28
+ setProcessProp('execPath', '/opt/node/bin/node')
29
+
30
+ const result = fn()
31
+ expect(result).to.equal(path.resolve('/opt/node/lib/node_modules'))
32
+ })
33
+
34
+ it('uses APPDATA on win32 when provided', function () {
35
+ setProcessProp('platform', 'win32')
36
+ setProcessProp('execPath', '/Program Files/nodejs/node.exe')
37
+ process.env.APPDATA = '/Users/test/AppData/Roaming'
38
+
39
+ const result = fn()
40
+ expect(result).to.equal(path.resolve('/Users/test/AppData/Roaming/npm/node_modules'))
41
+ })
42
+
43
+ it('falls back to exec directory on win32 when APPDATA is missing', function () {
44
+ setProcessProp('platform', 'win32')
45
+ setProcessProp('execPath', '/Program Files/nodejs/node.exe')
46
+ delete process.env.APPDATA
47
+
48
+ const result = fn()
49
+ expect(result).to.equal(path.resolve('/Program Files/nodejs/node_modules'))
50
+ })
51
+ })
@@ -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
+ })
@@ -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
+ })
@@ -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('Should return the expected result', function () {
6
- const items = [
7
- { id: 1, name: 'Apple', count: 1 },
8
- { id: 2, name: 'Banana', count: 2 },
9
- { id: 1, color: 'Red', price: 0.99 },
10
- { id: 3, name: 'Cherry', count: 5 },
11
- { id: 2, color: 'Yellow', weight: '100g' }
12
- ]
13
- const expected = [
14
- { id: 1, name: 'Apple', count: 1, color: 'Red', price: 0.99 },
15
- { id: 2, name: 'Banana', count: 2, color: 'Yellow', weight: '100g' },
16
- { id: 3, name: 'Cherry', count: 5 }
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
  })
@@ -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
+ })