Config Utils
ConfigUtil provides helpers for managing configuration objects by resolving nested values, cloning data safely, and merging overrides without mutating original objects.
extractConfigValue
Returns a property from a partial configuration when it is defined, falling back to the default configuration otherwise. The helper keeps optional feature toggles readable without manual guards.
static extractConfigValue<Type>(partialConfig:Optional<Type>, defaultConfig:Type, property:keyof Type):any;
interface ReelConfig {
reelCount:number;
symbolsPerReel:number;
}
const defaultConfig:ReelConfig = {
reelCount: 5,
symbolsPerReel: 3
};
const partialConfig:Optional<ReelConfig> = {
reelCount: 6
};
const reelCount = ConfigUtil.extractConfigValue(
partialConfig,
defaultConfig,
'reelCount'
);
const symbolsPerReel = ConfigUtil.extractConfigValue(
partialConfig,
defaultConfig,
'symbolsPerReel'
);
console.log(reelCount, symbolsPerReel);
// Output: 6 3
overrideConfig
Creates a new configuration by merging a partial object into an existing configuration. Nested objects are merged recursively so overrides can target specific branches.
static overrideConfig<Type>(sourceConfig:Type, partialConfig:Optional<Type>):Type;
const baseConfig = {
paylines: 20,
autoplay: {
step: 10,
limit: 100
}
};
const gameOverrides = {
autoplay: {
limit: 50
}
};
const mergedConfig = ConfigUtil.overrideConfig(
baseConfig,
gameOverrides
);
console.log(mergedConfig);
// Output: {
// paylines: 20,
// autoplay: {
// step: 10,
// limit: 50
// }
// }
normalizeConfig
Recursively merges a partial configuration with defaults and returns a new object. When the partial input is missing or matches the defaults, the defaults are returned as-is.
static normalizeConfig<Type>(partialConfig:Optional<Type>, defaultConfig:Type):Type;
const defaultReelset = {
symbols: [ 'A', 'K', 'Q' ],
weights: {
A: 1,
K: 1,
Q: 1
}
};
const specialReelset = {
weights: {
A: 3
}
};
const normalizedReelset = ConfigUtil.normalizeConfig(
specialReelset,
defaultReelset
);
console.log(normalizedReelset);
// Output: {
// symbols: [ 'A', 'K', 'Q' ],
// weights: {
// A: 3,
// K: 1,
// Q: 1
// }
// }
removeEmptyValue
Deletes null and undefined properties from the provided configuration object in place. Run it before serializing to external storage to avoid persisting empty fields.
static removeEmptyValue<Type>(currentConfig:Type):Type;
const sourceConfig = { wildMultiplier: null, scatterMultiplier: 2 };
const resultConfig = ConfigUtil.removeEmptyValue(sourceConfig);
console.log(resultConfig);
// Output: { scatterMultiplier: 2 }