UNPKG

1.23 kBJavaScriptView Raw
1import { hasKey } from "./has-key.js";
2export 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}
17export 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}
26export class Term {
27 constructor(termType, value) {
28 this.termType = termType;
29 this.value = value;
30 }
31 // This is here as a default, if the class has more than these
32 // two properties, it MUST follow its own path equality
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//# sourceMappingURL=term.js.map
\No newline at end of file