aneka 0.9.0 → 0.11.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/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-01-18
4
+
5
+ - [0.11.0] ```parseArgsArgv()``` now accepts a third parameter to set the current working directory
6
+
7
+ ## 2025-12-25
8
+
9
+ - [0.10.0] Add ```parseKvString()```
10
+
3
11
  ## 2025-12-19
4
12
 
5
13
  - [0.9.0] Add ```fillObject()```
package/index.js CHANGED
@@ -28,6 +28,7 @@ import parseObject from './src/parse-object.js'
28
28
  import randomRange from './src/random-range.js'
29
29
  import generateId from './src/generate-id.js'
30
30
  import fillObject from './src/fill-object.js'
31
+ import parseKvString from './src/parse-kv-string.js'
31
32
 
32
33
  export {
33
34
  arrangeArray,
@@ -52,6 +53,7 @@ export {
52
53
  parseArgsArgv,
53
54
  parseDuration,
54
55
  parseEnv,
56
+ parseKvString,
55
57
  parseObject,
56
58
  pascalCase,
57
59
  randomRange,
@@ -86,6 +88,7 @@ export default {
86
88
  parseArgsArgv,
87
89
  parseDuration,
88
90
  parseEnv,
91
+ parseKvString,
89
92
  parseObject,
90
93
  pascalCase,
91
94
  randomRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,6 +21,9 @@
21
21
  "bugs": {
22
22
  "url": "https://github.com/ardhi/aneka/issues"
23
23
  },
24
+ "standard": {
25
+ "env": [ "mocha" ]
26
+ },
24
27
  "homepage": "https://github.com/ardhi/aneka#readme",
25
28
  "dependencies": {
26
29
  "dotenv": "^17.2.3",
@@ -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')
@@ -52,13 +52,14 @@ async function parseWithYargs () {
52
52
  * @async
53
53
  * @param {function(Object): Object} [sanitizer] - If provided, result will be sanitized with this function
54
54
  * @param {boolean} [useParser] - If ```true```, skip {@link https://github.com/yargs/yargs|yargs}
55
+ * @param {string} [cwd] - If provided, current working directory is set to this
55
56
  * @returns {{args: Array, argv: Object}} An object containing ```args``` and ```argv```
56
57
  * @see App#args
57
58
  * @see App#argv
58
59
  */
59
- async function parseArgsArgv (sanitizer, useParser) {
60
+ async function parseArgsArgv (sanitizer, useParser, cwd) {
60
61
  if (!useParser) useParser = find(process.argv, a => a.startsWith('--spawn'))
61
- let argv = useParser ? await parseWithParser.call() : await parseWithYargs.call()
62
+ let argv = useParser ? await parseWithParser() : await parseWithYargs(cwd)
62
63
  const args = argv._
63
64
  delete argv._
64
65
  delete argv.$0
@@ -0,0 +1,13 @@
1
+ import dotenvParseVariables from 'dotenv-parse-variables'
2
+
3
+ function parseKvString (text, trimValue = true, lineDelimiter = '|') {
4
+ const lines = text.split(lineDelimiter).join('\n').split('\n')
5
+ const item = {}
6
+ for (const line of lines) {
7
+ const [k, v] = line.split('=')
8
+ item[k.trim()] = trimValue ? v.trim() : v
9
+ }
10
+ return dotenvParseVariables(item, { assignToProcessEnv: false })
11
+ }
12
+
13
+ export default parseKvString
@@ -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
+ })
@@ -0,0 +1,11 @@
1
+ import { expect } from 'chai'
2
+ import fn from '../src/parse-kv-string.js'
3
+
4
+ describe('parseKvString', function () {
5
+ it('Should return the expected result', function () {
6
+ const items = { ONE: 1, TWO: ['one', 'two'] }
7
+ const input = 'ONE=1\nTWO=one,two'
8
+ const result = fn(input)
9
+ expect(result).to.eql(items)
10
+ })
11
+ })
@@ -1,10 +1,10 @@
1
1
  import { expect } from 'chai'
2
2
  import fn from '../src/parse-object.js'
3
3
 
4
- describe('parseObjecy', function () {
4
+ describe('parseObject', function () {
5
5
  it('Should return the expected result', function () {
6
6
  const items = { _: { log: { pretty: true, level: 'trace' }, lang: 'id' } }
7
7
  const result = fn(items, { parseValue: true })
8
8
  expect(result).to.eql(items)
9
9
  })
10
- })
10
+ })