aneka 0.7.2 → 0.7.4

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
@@ -12,6 +12,8 @@
12
12
  - [0.7.0] Add ```parseObject()```
13
13
  - [0.7.1] Bug fix in ```parseObject()```
14
14
  - [0.7.2] Bug fix in ```parseArgsArgv()```
15
+ - [0.7.3] Rewrite options in ```parseObject()```
16
+ - [0.7.4] Bug fix in ```parseObject()```
15
17
 
16
18
  ## 2025-12-11
17
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,12 +14,13 @@ 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 {function(string): string} [options.translator] - If provided, translate string value with this function
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, translate } = options
22
+ const { silent = true, parseValue = false, translator = {} } = options
23
+ const { prefix, lang, handler } = translator
23
24
  const statics = ['*']
24
25
  if (isString(input)) {
25
26
  try {
@@ -43,12 +44,12 @@ function parseObject (input, options = {}) {
43
44
  if (isArray(obj[k][idx])) obj[k][idx] = obj[k][idx].map(item => typeof item === 'string' ? item.trim() : item)
44
45
  })
45
46
  } else if (isSet(v)) {
46
- if (isString(v) && translate) v = translate(v.slice(2))
47
+ if (isString(v) && prefix && lang && handler && v.startsWith(prefix)) v = handler(v.slice(prefix.length))
47
48
  try {
48
49
  if (statics.includes(v)) obj[k] = v
49
- else if (k.startsWith('t:') && isString(v)) {
50
- const newK = k.slice(2)
51
- if (translate) obj[newK] = translate(v)
50
+ else if (isString(v) && prefix && handler && k.startsWith(prefix)) {
51
+ const newK = k.slice(prefix.length)
52
+ if (lang) obj[newK] = handler(v)
52
53
  else obj[newK] = v
53
54
  mutated.push(k)
54
55
  } else if (parseValue) {
@@ -0,0 +1,10 @@
1
+ import { expect } from 'chai'
2
+ import fn from '../src/parse-object.js'
3
+
4
+ describe('parseObjecy', function () {
5
+ it('Should return the expected result', function () {
6
+ const items = { _: { log: { pretty: true, level: 'trace' }, lang: 'id' } }
7
+ const result = fn(items, { parseValue: true })
8
+ expect(result).to.eql(items)
9
+ })
10
+ })