JS: A working v0.9.0
This commit is contained in:
parent
f614b8db20
commit
a1b8bc4630
5 changed files with 261 additions and 216 deletions
54
assets/js/terms.js
Normal file
54
assets/js/terms.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
class Term {
|
||||
stringValue;
|
||||
|
||||
constructor(stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Term[${stringValue}]`;
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.stringValue;
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberTerm extends Term {
|
||||
value;
|
||||
|
||||
constructor(stringValue) {
|
||||
super(stringValue);
|
||||
|
||||
const parsedValue = parseInt(stringValue);
|
||||
if (isNaN(parsedValue)) {
|
||||
throw new TypeError("Number value is not a valid number");
|
||||
}
|
||||
|
||||
this.value = parsedValue;
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Number[${this.value}]`;
|
||||
}
|
||||
}
|
||||
|
||||
export class NameTerm extends Term {
|
||||
static regex = /[-\w]+/;
|
||||
|
||||
constructor(stringValue) {
|
||||
if (!NameTerm.regex.test(stringValue)) {
|
||||
throw new TypeError("Name must be string with non-zero length");
|
||||
}
|
||||
|
||||
super(stringValue);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Name[${this.stringValue}]`;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue