Created
January 3, 2020 05:01
-
-
Save anibal21/7d9631cf98f4b926b4e7967c271968c6 to your computer and use it in GitHub Desktop.
EC6 functions to handle json data
This file contains hidden or 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
/* Method to exclude items in a json, filtering by key index */ | |
const excludeItemsInJson = | |
(jsonObject: any, filterParams: ReadonlyArray<string>) = | |
Object.keys(jsonObject) | |
.filter((key: string) => filterParams.includes(key) ? false : true) | |
.reduce((obj, item) => ({...obj, [item]: test[item]}) ,{}) | |
/* Method to allow items in a json, filtering by key index. | |
Then a json will be returned with all the allowed items | |
*/ | |
const allowItemsInJson = | |
(jsonObject: any, filterParams: ReadonlyArray<string>) = | |
Object.keys(jsonObject) | |
.filter((key: string) => filterParams.includes(key) ? true : false) | |
.reduce((obj, item) => ({...obj, [item]: test[item]}) ,{}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment