Support for skipping functions in target object
Closed this issue · 5 comments
caoilte commented
I have an object to be redacted that contains some functions. redact-object blows up when it hits those properties. For my use-case I would like it to skip them. Is that something you would be open to extending the library to support?
It would be good enough if the config object could be passed an optional parameter to make it skip over un-supported types rather than throwing an exception.
shaunburdick commented
Sounds good! I'm traveling for work this week but I will look into tossing that in soon!
shaunburdick commented
Pushed v2.2.0 with this feature added! @ 2487765
shaunburdick commented
After reading your request again (sorry) I'll update it to allow you to ignore any unsupported type
caoilte commented
No worries! Amazing turn-around, thanks.
shaunburdick commented
Alright, v2.3.0 should be all set.
export interface ConfigOptions {
// do partial matches, default false
partial?: boolean;
// do strict key matching, default true
strict?: boolean;
// ignore unknown types instead of error, default false
ignoreUnknown?: boolean;
}
export type ReplaceFunction = (value: any, key: string) => string;
/**
* Parses an object and redacts any keys listed in keywords
*
* @param {*} target The target object to scan for redactable items
* @param {string[]} keywords A list of members to redact
* @param {string|ReplaceFunction} replaceVal Optional custom replace value or function replacer
* @param {ConfigOptions} config Optional config
* @return {object} the new redacted object
*/
function redact(
target: any,
keywords: string[],
replaceVal?: string | ReplaceFunction,
config?: ConfigOptions
): any;