Skip to content

Instantly share code, notes, and snippets.

@anibal21
Created January 3, 2020 05:01
Show Gist options
  • Save anibal21/7d9631cf98f4b926b4e7967c271968c6 to your computer and use it in GitHub Desktop.
Save anibal21/7d9631cf98f4b926b4e7967c271968c6 to your computer and use it in GitHub Desktop.
EC6 functions to handle json data
/* 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