blob: 5ca14866db85258969bdebe5c015dd7409823df3 [file] [edit]
/**
* A replacer function for `JSON.stringify()` that omits properties whose keys start with an underscore (`_`).
*
* @example
* const object = { name: 'Alice', _password: 'secret' };
* JSON.stringify(object, omitPrivateProperties);
* //=> '{"name":"Alice"}'
*
* @param {string} key
* @param {unknown} value
* @returns {unknown}
*/
export default function omitPrivateProperties(key, value) {
return key.startsWith('_') ? undefined : value;
}