-
Notifications
You must be signed in to change notification settings - Fork 0
Library: cleanRegExp()
Eugene Lazutkin edited this page Jul 3, 2018
·
1 revision
cleanRegExp() module is a function, which recursively removes properties fitting a regular expression.
cleanRegExp() works slower than clean() but more flexible. If you want to remove just one property consider clean().
In a module-enabled environment (like Babel) it can be accessed like that:
import cleanRegExp from '@researchnow/reno/src/utils/cleanRegExp';In global-based environments (like a browser) it is frequently mapped to Reno.utils.cleanRegExp.
The function takes the following arguments:
-
objectis an object, which will be recursively traversed and checked for fitting properties. If found, that properties will be deleted. -
patternis a regular expression to look for. The default:/^_/.
It returns object.
Using the default:
const object = [
{_id: 1, _meta: {account: 42}, value: 'x'},
{_id: 2, _meta: {account: 66}, value: 'y'}
];
cleanRegExp(object);
assert(isEqual(object,
[
{value: 'x'},
{value: 'y'}
]
));Custom removal:
const object = {
'@audit': 'mnvkbvoiqwe',
name: {
'@audit': 'sdspodpsdnn',
first: 'Jill',
last: 'Smith',
meta$: 'db56'
},
meta$: 'db42'
};
cleanRegExp(object, /^@|\$$/);
assert(isEqual(object,
{
name: {
first: 'Jill',
last: 'Smith'
}
}
));