aneka 0.9.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 +4 -0
- package/index.js +3 -0
- package/package.json +4 -1
- package/src/parse-kv-string.js +13 -0
- package/test/parse-kv-string.js +11 -0
- package/test/parse-object.js +2 -2
package/CHANGES.md
CHANGED
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.
|
|
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,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
|
+
})
|
package/test/parse-object.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
2
|
import fn from '../src/parse-object.js'
|
|
3
3
|
|
|
4
|
-
describe('
|
|
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
|
+
})
|