@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
70 lines (69 loc) • 2.07 kB
JavaScript
import {
isValid
} from "../chunk-AVHYDITZ.mjs";
import "../chunk-EBIF6AMC.mjs";
import {
toArray
} from "../chunk-KCY4RPFR.mjs";
import "../chunk-SSROJBD5.mjs";
import "../chunk-S3NSPQ7M.mjs";
import "../chunk-NNA77YYC.mjs";
import {
ofGet
} from "../chunk-SJGQU3OG.mjs";
import "../chunk-D5IYAIMK.mjs";
import {
on
} from "../chunk-PF7HDF6B.mjs";
import "../chunk-IXK47WKF.mjs";
import "../chunk-PIRWVOO2.mjs";
import {
isDefined,
isEmpty,
isIn,
isObject,
isString,
isTrue
} from "../chunk-AAND4MKF.mjs";
import "../chunk-4N72FQFX.mjs";
// src/types/Parser.ts
var Parser = class {
constructor(value, valid = true) {
this.value = value;
this.valid = valid;
}
if = {
equals: (pred) => this.evaluate(isTrue, pred),
empty: (pred) => this.evaluate(isEmpty, pred),
defined: (pred) => this.evaluate(isDefined, pred),
valid: (pred) => this.evaluate(isValid, pred),
in: (...items) => this.evaluate(() => isIn(this.value, toArray(...items))),
is: {
object: (pred) => this.evaluate(isObject, pred),
string: (pred) => this.evaluate(isString, pred),
instance: (c, pred) => this.evaluate(() => this.value instanceof c, pred)
},
not: {
empty: (pred) => this.evaluateNot(isEmpty, pred),
defined: (pred) => this.evaluateNot(isDefined, pred),
valid: (pred) => this.evaluateNot(isValid, pred),
isObject: (pred) => this.evaluateNot(isObject, pred),
in: (...items) => this.evaluate(() => !isIn(this.value, toArray(...items))),
is: {
object: (pred) => this.evaluateNot(isObject, pred),
string: (pred) => this.evaluateNot(isString, pred),
instance: (c, pred) => this.evaluate(() => !(this.value instanceof c), pred)
}
}
};
evaluate(meta, pred) {
return on(this, (t) => t.valid = ofGet(meta, pred ? ofGet(pred, this.value) : this.value));
}
evaluateNot(meta, pred) {
return on(this, (t) => t.valid = !ofGet(meta, pred ? ofGet(pred, this.value) : this.value));
}
};
export {
Parser
};
//# sourceMappingURL=Parser.mjs.map