Last active
May 22, 2020 12:54
-
-
Save Veenap/7bca65b131e525353f30bdee8e1d6b08 to your computer and use it in GitHub Desktop.
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
function transform(events) { | |
//traverse the JSON structure and replace PII fields with obfuscations for fuzzy matched keys | |
for( var i = 0; i < events.length; i++) { | |
event = events[i]; | |
walk(event,['SSN','Social Security Number', 'social security no.','social sec num', 'ssnum'],'XXX-XX-XXXX'); | |
} | |
return events; | |
} | |
function walk(obj,targetKeyArray,newValue) { | |
for (var key in obj) { | |
value = obj[key] | |
if (value && (typeof value == 'object')){ //recurse till leaf is reached | |
walk(value,targetKeyArray,newValue) | |
} | |
fs = fuzzysortNew() | |
matches = fs.go(key,targetKeyArray,{allowTypo: true}) | |
if ((typeof matches != "undefined") && Array.isArray(matches)) { | |
if (matches.length > 0) { | |
obj[key] = newValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment