mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-23 15:24:45 +08:00
Still WIP
This commit is contained in:
36
js/entity/NumberEntity.js
Executable file
36
js/entity/NumberEntity.js
Executable file
@@ -0,0 +1,36 @@
|
||||
import P from "parsernostrum"
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
export default class NumberEntity extends IEntity {
|
||||
|
||||
static grammar = P.regArray(
|
||||
new RegExp(`(${P.number.getParser().parser.regexp.source})|(\\+?inf)|(-inf)`)
|
||||
).map(([_0, n, plusInf, minusInf]) => new this(
|
||||
n ? Number(n) : plusInf ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY
|
||||
))
|
||||
|
||||
/** @type {Number} */
|
||||
#value
|
||||
get value() {
|
||||
return this.#value
|
||||
}
|
||||
set value(value) {
|
||||
if (value === -0) {
|
||||
value = 0
|
||||
}
|
||||
this.#value = value
|
||||
}
|
||||
|
||||
constructor(value = 0) {
|
||||
super()
|
||||
this.value = value
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.value.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user