1 | import { hasKey } from "./has-key.js";
|
2 | export function isTermLike(given, termType, value) {
|
3 | if (!(hasKey(given, "termType") &&
|
4 | hasKey(given, "value") &&
|
5 | typeof given.termType === "string" &&
|
6 | typeof given.value === "string")) {
|
7 | return false;
|
8 | }
|
9 | if (typeof termType === "string" && given.termType !== termType) {
|
10 | return false;
|
11 | }
|
12 | if (typeof value === "string" && given.value !== value) {
|
13 | return false;
|
14 | }
|
15 | return true;
|
16 | }
|
17 | export function isTerm(given, termType, value) {
|
18 | if (!isTermLike(given, termType, value)) {
|
19 | return false;
|
20 | }
|
21 | function hasEquals(given) {
|
22 | return !!(given && given.equals instanceof Function);
|
23 | }
|
24 | return hasEquals(given);
|
25 | }
|
26 | export class Term {
|
27 | constructor(termType, value) {
|
28 | this.termType = termType;
|
29 | this.value = value;
|
30 | }
|
31 |
|
32 |
|
33 | equals(other) {
|
34 | return isTermLike(other, this.termType, this.value);
|
35 | }
|
36 | toJSON() {
|
37 | return {
|
38 | termType: this.termType,
|
39 | value: this.value
|
40 | };
|
41 | }
|
42 | }
|
43 |
|
\ | No newline at end of file |