Created
April 19, 2018 19:25
-
-
Save reggi/8c907d576cf35dbd30a8ec6ab36c4e9d to your computer and use it in GitHub Desktop.
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
| const {isPlainObject, isString, mapValues, includes} = require('lodash') | |
| const piiProps = [] | |
| const blackoutBulk = (str) => str[0] + Array(str.length - 1).join('▮') + str[str.length - 1] | |
| const blackoutAll = (str) => Array(str.length + 1).join('▮') | |
| const blackout = (str) => (str.length < 5) ? blackoutAll(str) : blackoutBulk(str) | |
| const checkPropPii = (val, key) => includes(piiProps, key) ? blackout(val) : val | |
| const jsonStringify = (val) => {try { return JSON.parse(val) } catch (e) { return val }} | |
| const jsonStringifyObj = (val) => isPlainObject(jsonStringify(val)) | |
| const handlePlainObj = (val) => isPlainObject(val) ? hidePii(val) : false | |
| const handleStringObjPlain = (valParsed) => isPlainObject(valParsed) ? hidePii(valParsed) : false | |
| const handleStringObj = (val) => isString(val) && handleStringObjPlain(jsonStringify(val)) | |
| const hidePiiCb = (val, key) => handlePlainObj(val, key) || handleStringObj(val, key) || checkPropPii(val, key) | |
| const hidePii = (data) => mapValues(data, hidePiiCb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment