mirror of
https://github.com/HeyPuter/puter.git
synced 2026-07-15 19:46:59 +00:00
dev: update objutil
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user