Files
ueblueprint/js/entity/TypeInitialization.js
2022-03-10 21:13:55 +01:00

27 lines
744 B
JavaScript
Executable File

export default class TypeInitialization {
static sanitize(value) {
if (!(value instanceof Object)) {
return value // Is already primitive
}
if (value instanceof Boolean || value instanceof Number || value instanceof String) {
return value.valueOf()
}
return value
}
/**
* @param {typeof Object} type
* @param {boolean} showDefault
* @param {*} value
*/
constructor(type, showDefault = true, value = undefined) {
if (value === undefined) {
value = TypeInitialization.sanitize(new type())
}
this.value = value
this.showDefault = showDefault
this.type = type
}
}