Fix links on pasted nodes

This commit is contained in:
barsdeveloper
2022-04-11 21:07:53 +02:00
parent 295e1d3120
commit 4b045b4c70
13 changed files with 334 additions and 235 deletions

View File

@@ -5,12 +5,19 @@
*/
export default class TypeInitialization {
static sanitize(value) {
if (!(value instanceof Object)) {
return value // Is already primitive
static sanitize(value, targetType) {
if (targetType === undefined) {
targetType = value?.constructor
}
let wrongType = false
if (targetType && value?.constructor !== targetType && !(value instanceof targetType)) {
wrongType = true
}
if (value instanceof Boolean || value instanceof Number || value instanceof String) {
return value.valueOf()
value = value.valueOf() // Get the relative primitive value
}
if (wrongType) {
return new targetType(value)
}
return value
}