Skip to content

Instantly share code, notes, and snippets.

@Veenap
Last active May 22, 2020 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Veenap/7bca65b131e525353f30bdee8e1d6b08 to your computer and use it in GitHub Desktop.
Save Veenap/7bca65b131e525353f30bdee8e1d6b08 to your computer and use it in GitHub Desktop.
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