dev: update objutil

This commit is contained in:
KernelDeimos
2025-08-29 18:41:28 -04:00
parent d05696f1a7
commit e4262201d8
+25 -1
View File
@@ -1,10 +1,16 @@
const { config } = require("yargs");
const { whatis } = require("./langutil");
const DO_NOT_DEFINE = Symbol('DO_NOT_DEFINE');
const createTransformedValues = (input, options = {}, state = {}) => {
// initialize state
if ( ! state.keys ) state.keys = [];
if ( whatis(input) === 'array' ) {
if ( options.doNotProcessArrays ) {
return DO_NOT_DEFINE;
}
const output = [];
for ( let i=0 ; i < input.length; i++ ) {
const value = input[i];
@@ -19,7 +25,10 @@ const createTransformedValues = (input, options = {}, state = {}) => {
Object.setPrototypeOf(output, input);
for ( const k in input ) {
state.keys.push(k);
output[k] = createTransformedValues(input[k], options);
const new_value = createTransformedValues(input[k], options);
if ( new_value !== DO_NOT_DEFINE ) {
output[k] = new_value;
}
state.keys.pop();
}
return output;
@@ -31,6 +40,21 @@ const createTransformedValues = (input, options = {}, state = {}) => {
return value;
};
config.__set_config_object__(createTransformedValues(config, {
mutateValue: (input, { state }) => {
const path = state.keys.join('.'); // or jq
// ....
if ( should_replace ) {
return 'replacement';
} else {
return DO_NOT_DEFINE;
}
}
}))
module.exports = {
createTransformedValues,
DO_NOT_DEFINE,
};