Skip to content

Instantly share code, notes, and snippets.

View rbonestell's full-sized avatar
🤔
Cleverly arranging ones and zeros.

Bobby Bonestell rbonestell

🤔
Cleverly arranging ones and zeros.
View GitHub Profile
@rbonestell
rbonestell / redact.ts
Last active February 7, 2024 18:13
JS/TS Redact Specific Fields From Object: Prototype Pollution?
/* eslint-disable @typescript-eslint/no-explicit-any */
export function redactSpecifiedProperties(target: any, fields: string[], redactedMessage = 'REDACTED'): any {
// Return if target is not a redactable datatype or no redactable fields were provided
if (!target || typeof target !== 'object' || fields?.length === 0) {
return target;
}
// Iterate through all items in an array
if (Array.isArray(target)) {
return target.map(item => redactSpecifiedProperties(item, fields, redactedMessage));