-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get value by key, prepare for #5
- Loading branch information
1 parent
01d8808
commit 4d43a15
Showing
2 changed files
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const getValue = (object, path) => path.split('.').reduce((o, k) => (o || {})[k], object), | ||
data = { key: { subKey: 'value' } }, | ||
theString = 'key.subKey'; | ||
|
||
const args = process.argv; | ||
const file = args[2]; | ||
const key = args[3]; | ||
|
||
let rawdata = fs.readFileSync(args[2]); | ||
let data = JSON.parse(rawdata); | ||
console.log(data.extra.component.id); | ||
const raw = fs.readFileSync(file); | ||
const obj = JSON.parse(raw); | ||
console.log(getValue(obj, key)); |