aneka 0.8.0 → 0.10.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
+ ## 2025-12-25
4
+
5
+ - [0.10.0] Add ```parseKvString()```
6
+
7
+ ## 2025-12-19
8
+
9
+ - [0.9.0] Add ```fillObject()```
10
+
3
11
  ## 2025-12-13
4
12
 
5
13
  - [0.6.0] Export functions as named export as well as default export
package/index.js CHANGED
@@ -27,6 +27,8 @@ import parseDuration from './src/parse-duration.js'
27
27
  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
+ import fillObject from './src/fill-object.js'
31
+ import parseKvString from './src/parse-kv-string.js'
30
32
 
31
33
  export {
32
34
  arrangeArray,
@@ -35,6 +37,7 @@ export {
35
37
  delay,
36
38
  extractText,
37
39
  formatText,
40
+ fillObject,
38
41
  filterDuplicate,
39
42
  filterIndex,
40
43
  generateId,
@@ -50,6 +53,7 @@ export {
50
53
  parseArgsArgv,
51
54
  parseDuration,
52
55
  parseEnv,
56
+ parseKvString,
53
57
  parseObject,
54
58
  pascalCase,
55
59
  randomRange,
@@ -68,6 +72,7 @@ export default {
68
72
  delay,
69
73
  extractText,
70
74
  formatText,
75
+ fillObject,
71
76
  filterDuplicate,
72
77
  filterIndex,
73
78
  generateId,
@@ -83,6 +88,7 @@ export default {
83
88
  parseArgsArgv,
84
89
  parseDuration,
85
90
  parseEnv,
91
+ parseKvString,
86
92
  parseObject,
87
93
  pascalCase,
88
94
  randomRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.8.0",
3
+ "version": "0.10.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",
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Fill object with keys. ```defValue``` is used if the corresponding key doesn't have value
3
+ *
4
+ * @param {Object} obj - Object to fill
5
+ * @param {string[]} keys - Array of keys
6
+ * @param {any} defValue - Default value
7
+ * @returns {Object}
8
+ */
9
+ function fillObject (obj = {}, keys = [], defValue) {
10
+ const newObj = {}
11
+ for (const key of keys) {
12
+ newObj[key] = obj[key] ?? defValue
13
+ }
14
+ return newObj
15
+ }
16
+
17
+ export default fillObject
@@ -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
@@ -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
+ })