aneka 0.7.2 → 0.7.3
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 +1 -0
- package/package.json +1 -1
- package/src/parse-object.js +5 -5
package/CHANGES.md
CHANGED
package/package.json
CHANGED
package/src/parse-object.js
CHANGED
|
@@ -14,12 +14,12 @@ import { set, isString, cloneDeep, isPlainObject, isArray, omit } from 'lodash-e
|
|
|
14
14
|
* @param {Object} [options={}] - Options
|
|
15
15
|
* @param {boolean} [options.silent=true] - If ```true``` (default), exception are not thrown and silently ignored
|
|
16
16
|
* @param {boolean} [options.parseValue=false] - If ```true```, values will be parsed & normalized
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {Object} [options.translator] - If provided, translate string value
|
|
18
18
|
* @returns {Object}
|
|
19
19
|
* @see {@link https://github.com/ladjs/dotenv-parse-variables}
|
|
20
20
|
*/
|
|
21
21
|
function parseObject (input, options = {}) {
|
|
22
|
-
const { silent = true, parseValue = false,
|
|
22
|
+
const { silent = true, parseValue = false, translator = {} } = options
|
|
23
23
|
const statics = ['*']
|
|
24
24
|
if (isString(input)) {
|
|
25
25
|
try {
|
|
@@ -43,12 +43,12 @@ function parseObject (input, options = {}) {
|
|
|
43
43
|
if (isArray(obj[k][idx])) obj[k][idx] = obj[k][idx].map(item => typeof item === 'string' ? item.trim() : item)
|
|
44
44
|
})
|
|
45
45
|
} else if (isSet(v)) {
|
|
46
|
-
if (isString(v) &&
|
|
46
|
+
if (isString(v) && translator.handler && translator.matcher && translator.matcher(v)) v = translator.handler(v.slice(2))
|
|
47
47
|
try {
|
|
48
48
|
if (statics.includes(v)) obj[k] = v
|
|
49
|
-
else if (
|
|
49
|
+
else if (isString(v)) {
|
|
50
50
|
const newK = k.slice(2)
|
|
51
|
-
if (
|
|
51
|
+
if (translator.handler && translator.matcher && translator.matcher(k)) obj[newK] = translator.handler(v)
|
|
52
52
|
else obj[newK] = v
|
|
53
53
|
mutated.push(k)
|
|
54
54
|
} else if (parseValue) {
|