@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 V,
secondsAgo as es,
secondsInTheFuture as hs,
} from "../../util/date-utils.js";
export default class fr {
constructor(t, s, e, i) {
(this.yE = t),
(this.HE = s),
(this.comparator = e),
(this.LE = i),
(this.yE = t),
(this.HE = s),
(this.comparator = e),
(this.LE = i),
this.HE === fr.XE.QE &&
this.comparator !== fr.BE.wE &&
this.comparator !== fr.BE.jE &&
this.comparator !== fr.BE.zE &&
this.comparator !== fr.BE.FE &&
(this.LE = V(this.LE));
}
xc(t) {
let s = null;
switch ((null != t && (s = t[this.yE]), this.comparator)) {
case fr.BE.kE:
return null != s && s.valueOf() === this.LE.valueOf();
case fr.BE.xE:
return null == s || s.valueOf() !== this.LE.valueOf();
case fr.BE.JE:
return null != s && typeof s == typeof this.LE && s > this.LE;
case fr.BE.wE:
return this.HE === fr.XE.QE
? null != s && Nt(s) && es(s) <= this.LE.valueOf()
: null != s && typeof s == typeof this.LE && s >= this.LE;
case fr.BE.VE:
return null != s && typeof s == typeof this.LE && s < this.LE;
case fr.BE.jE:
return this.HE === fr.XE.QE
? null != s && Nt(s) && es(s) >= this.LE.valueOf()
: null != s && typeof s == typeof this.LE && s <= this.LE;
case fr.BE.qE:
return (
null != s &&
"string" == typeof s &&
typeof s == typeof this.LE &&
null != s.match(this.LE)
);
case fr.BE.PE:
return null != s;
case fr.BE.WE:
return null == s;
case fr.BE.zE:
return null != s && Nt(s) && hs(s) < this.LE;
case fr.BE.FE:
return null != s && Nt(s) && hs(s) > this.LE;
case fr.BE.ZE:
return (
null == s ||
typeof s != typeof this.LE ||
"string" != typeof s ||
null == s.match(this.LE)
);
}
return !1;
}
static fromJson(t) {
return new fr(
t.property_key,
t.property_type,
t.comparator,
t.property_value,
);
}
dt() {
let t = this.LE;
return (
Nt(this.LE) && (t = X(t.valueOf())),
{ k: this.yE, t: this.HE, c: this.comparator, v: t }
);
}
static qn(t) {
return new fr(t.k, t.t, t.c, t.v);
}
}
(fr.XE = { $E: "boolean", tT: "number", sT: "string", QE: "date" }),
(fr.BE = {
kE: 1,
xE: 2,
JE: 3,
wE: 4,
VE: 5,
jE: 6,
qE: 10,
PE: 11,
WE: 12,
zE: 15,
FE: 16,
ZE: 17,
});