aneka 0.10.0 → 0.11.1

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/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-01-18
4
+
5
+ - [0.11.1] ```parseArgsArgv()``` now accepts an object as its parameter
6
+
7
+
3
8
  ## 2025-12-25
4
9
 
5
10
  - [0.10.0] Add ```parseKvString()```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- function mergeObjectsByKey(inputs, key) {
1
+ function mergeObjectsByKey (inputs, key) {
2
2
  const uniqueMap = new Map()
3
3
 
4
4
  for (const item of inputs) {
@@ -25,8 +25,8 @@ async function parseWithParser () {
25
25
  })
26
26
  }
27
27
 
28
- async function parseWithYargs () {
29
- const pkgFile = `${process.cwd()}/package.json`
28
+ async function parseWithYargs (cwd) {
29
+ const pkgFile = `${cwd ?? process.cwd()}/package.json`
30
30
  const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'))
31
31
  let name = `node ${pkg.main}`
32
32
  if (pkg.bin) name = path.basename(pkg.bin, '.js')
@@ -50,15 +50,18 @@ async function parseWithYargs () {
50
50
  * Parse program arguments (args) & options (argv)
51
51
  *
52
52
  * @async
53
- * @param {function(Object): Object} [sanitizer] - If provided, result will be sanitized with this function
54
- * @param {boolean} [useParser] - If ```true```, skip {@link https://github.com/yargs/yargs|yargs}
53
+ * @param {Object} [options={}] - Options object
54
+ * @param {function(Object): Object} [options.sanitizer] - If provided, result will be sanitized with this function
55
+ * @param {boolean} [options.useParser] - If ```true```, skip {@link https://github.com/yargs/yargs|yargs}
56
+ * @param {string} [options.cwd] - If provided, current working directory is set to this
55
57
  * @returns {{args: Array, argv: Object}} An object containing ```args``` and ```argv```
56
58
  * @see App#args
57
59
  * @see App#argv
58
60
  */
59
- async function parseArgsArgv (sanitizer, useParser) {
61
+ async function parseArgsArgv (options = {}) {
62
+ let { sanitizer, useParser, cwd } = options
60
63
  if (!useParser) useParser = find(process.argv, a => a.startsWith('--spawn'))
61
- let argv = useParser ? await parseWithParser.call() : await parseWithYargs.call()
64
+ let argv = useParser ? await parseWithParser() : await parseWithYargs(cwd)
62
65
  const args = argv._
63
66
  delete argv._
64
67
  delete argv.$0
@@ -6,7 +6,7 @@
6
6
  * @param {boolean} alpha - Set ```true``` to return alphanumeric characters
7
7
  * @returns
8
8
  */
9
- function randomRange(min = 0, max = 65439, alpha = false) {
9
+ function randomRange (min = 0, max = 65439, alpha = false) {
10
10
  const num = Math.floor(Math.random() * (max - min + 1) + min)
11
11
  if (!alpha) return num
12
12
  return String.fromCharCode(96 + num)
@@ -4,9 +4,9 @@ import fn from '../src/filter-duplicate.js'
4
4
  describe('filterDuplicate', function () {
5
5
  it('No duplication', function () {
6
6
  const items = [
7
- { id: 1, name: "one" },
8
- { id: 2, name: "two" },
9
- { id: 3, name: "three" }
7
+ { id: 1, name: 'one' },
8
+ { id: 2, name: 'two' },
9
+ { id: 3, name: 'three' }
10
10
  ]
11
11
  const dups = fn(items, 'name')
12
12
  expect(dups).to.have.lengthOf(0)
@@ -14,11 +14,11 @@ describe('filterDuplicate', function () {
14
14
 
15
15
  it('Two duplications', function () {
16
16
  const items = [
17
- { id: 1, name: "one" },
18
- { id: 2, name: "one" },
19
- { id: 3, name: "three" }
17
+ { id: 1, name: 'one' },
18
+ { id: 2, name: 'one' },
19
+ { id: 3, name: 'three' }
20
20
  ]
21
21
  const dups = fn(items, 'name')
22
22
  expect(dups).to.have.lengthOf(2)
23
23
  })
24
- })
24
+ })
@@ -4,9 +4,9 @@ import fn from '../src/filter-index.js'
4
4
  describe('filterIndex', function () {
5
5
  it('Nothing found', function () {
6
6
  const items = [
7
- { id: 1, name: "one" },
8
- { id: 2, name: "two" },
9
- { id: 3, name: "three" }
7
+ { id: 1, name: 'one' },
8
+ { id: 2, name: 'two' },
9
+ { id: 3, name: 'three' }
10
10
  ]
11
11
  const dups = fn(items, item => item.name === 'zero')
12
12
  expect(dups).to.have.lengthOf(0)
@@ -14,12 +14,11 @@ describe('filterIndex', function () {
14
14
 
15
15
  it('Found 2 items', function () {
16
16
  const items = [
17
- { id: 1, name: "one" },
18
- { id: 2, name: "two" },
19
- { id: 3, name: "three" }
17
+ { id: 1, name: 'one' },
18
+ { id: 2, name: 'two' },
19
+ { id: 3, name: 'three' }
20
20
  ]
21
21
  const dups = fn(items, item => ['one', 'two'].includes(item.name))
22
22
  expect(dups).to.eql([0, 1])
23
23
  })
24
-
25
- })
24
+ })
@@ -18,4 +18,4 @@ describe('mergeObjectsByKey', function () {
18
18
  const result = fn(items, 'id')
19
19
  expect(result).to.eql(expected)
20
20
  })
21
- })
21
+ })
@@ -8,4 +8,4 @@ describe('parseKvString', function () {
8
8
  const result = fn(input)
9
9
  expect(result).to.eql(items)
10
10
  })
11
- })
11
+ })