2023-07-12 17:40:41 +00:00
|
|
|
import * as plugins from '../smartobject.plugins.js';
|
2022-03-07 14:28:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* runs a function for all properties of an object whose key matches a regex expression
|
|
|
|
* @param parentObjectArg the parent object
|
|
|
|
* @param wildcardArg the rege expression to match the property keys against
|
|
|
|
* @param callbackArg the function to run with those properties
|
|
|
|
*/
|
2023-07-12 17:40:41 +00:00
|
|
|
export let forEachMinimatch = async (
|
|
|
|
parentObjectArg: any,
|
|
|
|
wildcardArg: string,
|
|
|
|
callbackArg: (matchedArg: string) => void
|
|
|
|
) => {
|
2022-03-07 14:28:32 +00:00
|
|
|
let propertyNames = Object.getOwnPropertyNames(parentObjectArg);
|
2023-07-12 17:40:41 +00:00
|
|
|
let propertyNamesMatched = propertyNames.filter((propertyNameArg) => {
|
2023-07-12 17:59:28 +00:00
|
|
|
return plugins.minimatch.minimatch(propertyNameArg, wildcardArg);
|
2022-03-07 14:28:32 +00:00
|
|
|
});
|
|
|
|
for (let propertyNameArg of propertyNamesMatched) {
|
|
|
|
await callbackArg(parentObjectArg[propertyNameArg]);
|
|
|
|
}
|
2023-07-12 17:40:41 +00:00
|
|
|
};
|