mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
29 lines
753 B
JavaScript
Executable File
29 lines
753 B
JavaScript
Executable File
// @ts-check
|
|
|
|
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 {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
|
|
}
|
|
}
|