Files
ueblueprint/js/entity/TypeInitialization.js
2022-03-30 21:59:41 +02:00

32 lines
786 B
JavaScript
Executable File

// @ts-check
/**
* @template T
*/
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 {new () => T} type
* @param {Boolean} showDefault
* @param {any} value
*/
constructor(type, showDefault = true, value = undefined) {
if (value === undefined) {
value = TypeInitialization.sanitize(new type())
}
this.value = value
this.showDefault = showDefault
this.type = type
}
}