UNPKG

@digifi/jexl-functions

Version:
97 lines (96 loc) 2.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const coerceUtils_1 = require("../utils/coerceUtils"); const module_1 = require("../utils/module"); const dayjs_1 = __importDefault(require("../dayjs")); exports.default = (0, module_1.createModule)(({ coerceToStringWithValidation }) => { const ISEVEN = (value) => { return (0, coerceUtils_1.coerceToNumber)(value) % 2 === 0; }; const ISTEXT = (value) => { return typeof value === 'string'; }; const ISNONTEXT = (value) => { return !ISTEXT(value); }; const ISODD = (value) => { return !ISEVEN(value); }; const ISNULL = (value) => { return value === null; }; const ISNOTNULL = (value) => { return !ISNULL(value); }; const ISUNDEFINED = (value) => { return value === undefined; }; const ISNOTUNDEFINED = (value) => { return !ISUNDEFINED(value); }; const ISEMPTY = (value, checkForEmptyString) => { // eslint-disable-next-line eqeqeq if (checkForEmptyString == true && value === '') { return true; } return value === null || value === undefined; }; const ISNOTEMPTY = (value, checkForEmptyString) => { return !ISEMPTY(value, checkForEmptyString); }; const ISNUMBER = (value) => { return typeof value === 'number'; }; const ISFINITE = (value) => { return Number.isFinite(value); }; const ISNAN = (value) => { return isNaN(value); }; const ISDATESTRING = (value, format) => { if (typeof value === 'string' && !isNaN(Number(value))) { return false; } return (typeof value === 'string' && (0, dayjs_1.default)(value, coerceToStringWithValidation(format) || undefined, true).isValid()); }; const ISBLANK = (value) => { return value === ''; }; const ISEMPTYORBLANK = (value) => { return value === '' || value === null || value === undefined; }; const ISNOTEMPTYORBLANK = (value) => { return !ISEMPTYORBLANK(value); }; const ISEMPTYARRAY = (value) => { return value === null || value === undefined || (Array.isArray(value) && !value.length); }; const ISNOTEMPTYARRAY = (value) => { return !ISEMPTYARRAY(value); }; return { ISEVEN, ISTEXT, ISNONTEXT, ISNULL, ISNOTNULL, ISUNDEFINED, ISNOTUNDEFINED, ISEMPTY, ISNOTEMPTY, ISODD, ISNUMBER, ISFINITE, ISNAN, ISDATESTRING, ISBLANK, ISEMPTYORBLANK, ISNOTEMPTYORBLANK, ISEMPTYARRAY, ISNOTEMPTYARRAY, }; });