@tidecloak/js
Version:
TideCloak client side JS SDK
78 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isLessThan = isLessThan;
exports.isGreaterThan = isGreaterThan;
exports.isEqualTo = isEqualTo;
exports.filterValuesEqualTo = filterValuesEqualTo;
exports.filterValuesNotEqualTo = filterValuesNotEqualTo;
exports.isTotalLessThan = isTotalLessThan;
exports.isTotalMoreThan = isTotalMoreThan;
// helperFunctions.js (ESM)
function isLessThan(value, ruleValue) {
const threshold = BigInt(ruleValue);
if (Array.isArray(value)) {
return BigInt(value.length) < threshold;
}
try {
return BigInt(value) < threshold;
}
catch (e) {
return false;
}
}
function isGreaterThan(value, ruleValue) {
const threshold = BigInt(ruleValue);
if (Array.isArray(value)) {
return BigInt(value.length) > threshold;
}
try {
return BigInt(value) > threshold;
}
catch (e) {
return false;
}
}
function isEqualTo(value, ruleValue) {
if (typeof value === "number" || typeof value === "bigint") {
try {
return BigInt(value) === BigInt(ruleValue);
}
catch (e) {
return false;
}
}
return String(value) === ruleValue;
}
function filterValuesEqualTo(value, valueToExclude) {
return String(value) === valueToExclude;
}
function filterValuesNotEqualTo(value, valueToKeep) {
return String(value) !== valueToKeep;
}
function isTotalLessThan(elements, ruleValue) {
const threshold = BigInt(ruleValue);
let total = BigInt(0);
for (const el of elements) {
try {
total += BigInt(el);
}
catch (e) {
return false;
}
}
return total < threshold;
}
function isTotalMoreThan(elements, ruleValue) {
const threshold = BigInt(ruleValue);
let total = BigInt(0);
for (const el of elements) {
try {
total += BigInt(el);
}
catch (e) {
return false;
}
}
return total > threshold;
}
//# sourceMappingURL=helperFunctions.js.map