Data types-related fixes

This commit is contained in:
barsdeveloper
2022-03-20 22:29:53 +01:00
parent 871f76b305
commit 4dd2929a9f
15 changed files with 128 additions and 23 deletions

32
js/entity/Identifier.js Normal file
View File

@@ -0,0 +1,32 @@
import IEntity from "./IEntity"
export default class Identifier extends IEntity {
static attributes = {
value: String,
}
constructor(options = {}) {
// Not instanceof to pick also primitive string
if (options.constructor === String) {
options = {
value: options
}
}
super(options)
/** @type {String} */
this.value
if (!this.value.match(/\w+/)) {
throw new Error("The value must be an identifier (/\w+/).")
}
}
valueOf() {
return this.value
}
toString() {
return this.value
}
}