-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
29 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
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,27 +1,35 @@ | ||
import {set, reduce, has} from 'lodash/fp'; | ||
import {get, set, reduce, has, pipe} from 'lodash/fp'; | ||
|
||
const parseNode = node => { | ||
if (!has('key', node)) | ||
node = set('key', '/', node); | ||
if (node.dir) | ||
return set('nodes', (node.nodes || []).map(parseNode), node); | ||
export const stringify = value => JSON.stringify(value, null, 2); | ||
|
||
export const parseValue = value => { | ||
try { | ||
return set('value', JSON.parse(node.value), node); | ||
return JSON.parse(value); | ||
} catch (err) { | ||
return node; | ||
return value; | ||
} | ||
}; | ||
|
||
const parseAction = action => { | ||
export const parseNode = pipe( | ||
node => { // Root node does't has 'key' key | ||
if (has('key', node)) return node; | ||
return set('key', '/', node); | ||
}, | ||
node => { // Parse children of dir node | ||
if (!node.dir) return node; | ||
return set('nodes', (node.nodes || []).map(parseNode), node); | ||
}, | ||
node => { // Parse value of file node | ||
if (!has('value', node)) return node; | ||
return set('value', parseValue(get('value', node)), node); | ||
} | ||
); | ||
|
||
export const parseAction = action => { | ||
return reduce((action, key) => { | ||
if (has(key, action)) { | ||
return set(key, parseNode(action[key]), action); | ||
return set(key, parseNode(get(key, action)), action); | ||
} | ||
return action; | ||
}, action, ['node', 'prevNode']); | ||
}; | ||
|
||
export { | ||
parseNode, | ||
parseAction | ||
}; |
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
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