@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
103 lines (102 loc) • 2.7 kB
JavaScript
import { isDate as Nt } from "../../util/code-utils.js";
import {
convertMsToSeconds as X,
dateFromUnixTimestamp as Y,
secondsAgo as hs,
secondsInTheFuture as us,
} from "../../util/date-utils.js";
export default class hr {
constructor(t, s, e, i) {
(this.tT = t),
(this.sT = s),
(this.comparator = e),
(this.eT = i),
(this.tT = t),
(this.sT = s),
(this.comparator = e),
(this.eT = i),
this.sT === hr.lT.iT &&
this.comparator !== hr.hT.rT &&
this.comparator !== hr.hT.nT &&
this.comparator !== hr.hT.uT &&
this.comparator !== hr.hT.oT &&
(this.eT = Y(this.eT));
}
Hc(t) {
let s = null;
switch ((null != t && (s = t[this.tT]), this.comparator)) {
case hr.hT.ET:
return null != s && s.valueOf() === this.eT.valueOf();
case hr.hT.aT:
return null == s || s.valueOf() !== this.eT.valueOf();
case hr.hT.TT:
return null != s && typeof s == typeof this.eT && s > this.eT;
case hr.hT.rT:
return this.sT === hr.lT.iT
? null != s && Nt(s) && hs(s) <= this.eT.valueOf()
: null != s && typeof s == typeof this.eT && s >= this.eT;
case hr.hT.cT:
return null != s && typeof s == typeof this.eT && s < this.eT;
case hr.hT.nT:
return this.sT === hr.lT.iT
? null != s && Nt(s) && hs(s) >= this.eT.valueOf()
: null != s && typeof s == typeof this.eT && s <= this.eT;
case hr.hT.AT:
return (
null != s &&
"string" == typeof s &&
typeof s == typeof this.eT &&
null != s.match(this.eT)
);
case hr.hT._T:
return null != s;
case hr.hT.fT:
return null == s;
case hr.hT.uT:
return null != s && Nt(s) && us(s) < this.eT;
case hr.hT.oT:
return null != s && Nt(s) && us(s) > this.eT;
case hr.hT.pT:
return (
null == s ||
typeof s != typeof this.eT ||
"string" != typeof s ||
null == s.match(this.eT)
);
}
return !1;
}
static fromJson(t) {
return new hr(
t.property_key,
t.property_type,
t.comparator,
t.property_value,
);
}
qt() {
let t = this.eT;
return (
Nt(this.eT) && (t = X(t.valueOf())),
{ k: this.tT, t: this.sT, c: this.comparator, v: t }
);
}
static _u(t) {
return new hr(t.k, t.t, t.c, t.v);
}
}
(hr.lT = { yT: "boolean", ST: "number", NT: "string", iT: "date" }),
(hr.hT = {
ET: 1,
aT: 2,
TT: 3,
rT: 4,
cT: 5,
nT: 6,
AT: 10,
_T: 11,
fT: 12,
uT: 15,
oT: 16,
pT: 17,
});