Skip to content

Commit 614c920

Browse files
committed
fix(config): get full object when key is empty string
1 parent 66d6f1d commit 614c920

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ const object = {
493493
const value = Json.get(object, 'hello.world.value.hello') // 'Hello World!'
494494
const undefinedValue = Json.get(object, 'hello.worlld.value.hello') // undefined
495495
const defaultValue = Json.get(object, 'hello.worlld.value.hello', 'Hi World!') // 'Hi World!'
496-
const fullObject = Json.get(object, '*') // Same as object { hello: { world: { value: { hello: 'Hello World!' } } } }
497-
const defaultValueInObjectNull = Json.get(undefined, '*', { hello: 'world' }) // { hello: 'world' }
496+
const fullObject = Json.get(object, '') // Same as object { hello: { world: { value: { hello: 'Hello World!' } } } }
497+
const defaultValueInObjectNull = Json.get(undefined, '', { hello: 'world' }) // { hello: 'world' }
498498
```
499499

500500
---

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.9.8",
3+
"version": "1.9.9",
44
"description": "Utils functions and classes for Node.js",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/Helpers/Json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class Json {
132132
* @return {any|undefined}
133133
*/
134134
static get(object, key, defaultValue) {
135-
if (key === '*' && object) {
135+
if (key === '' && object) {
136136
return object
137137
}
138138

tests/Unit/ConfigTest.js

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ test.group('ConfigTest', group => {
3030
await Folder.safeRemove(Path.config())
3131
})
3232

33+
test('should be able to get full configurations values from Config class', ({ assert }) => {
34+
const app = Config.get('app')
35+
36+
assert.deepEqual(app, {
37+
name: 'SecJS',
38+
env: 'test',
39+
})
40+
})
41+
3342
test('should be able to get configurations values from Config class', ({ assert }) => {
3443
const appName = Config.get('app.name')
3544

tests/Unit/JsonTest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ test.group('Json Class', () => {
108108
const value = Json.get(object, 'hello.world.value.hello')
109109
const undefinedValue = Json.get(object, 'hello.worlld.value.hello')
110110
const defaultValue = Json.get(object, 'hello.worlld.value.hello', 'Hi World!')
111-
const fullObject = Json.get(object, '*')
112-
const defaultValueInObjectNull = Json.get(undefined, '*', { hello: 'world' })
111+
const fullObject = Json.get(object, '')
112+
const defaultValueInObjectNull = Json.get(undefined, '', { hello: 'world' })
113113

114114
assert.equal(value, 'Hello World!')
115115
assert.equal(defaultValue, 'Hi World!')

0 commit comments

Comments
 (0)