UNPKG

react-querybuilder

Version:

React Query Builder component for constructing queries and filters, with utilities for executing them in various database and evaluation contexts

1,225 lines (1,223 loc) 258 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // ../../node_modules/jsonata/jsonata.js var require_jsonata = __commonJS({ "../../node_modules/jsonata/jsonata.js"(exports2, module2) { "use strict"; (function(f) { if (typeof exports2 === "object" && typeof module2 !== "undefined") { module2.exports = f(); } else if (typeof define === "function" && define.amd) { define([], f); } else { var g; if (typeof window !== "undefined") { g = window; } else if (typeof global !== "undefined") { g = global; } else if (typeof self !== "undefined") { g = self; } else { g = this; } g.jsonata = f(); } })(function() { var define2, module3, exports3; return (/* @__PURE__ */ function() { function r(e, n, t) { function o(i2, f) { if (!n[i2]) { if (!e[i2]) { var c = "function" == typeof require && require; if (!f && c) return c(i2, true); if (u) return u(i2, true); var a = new Error("Cannot find module '" + i2 + "'"); throw a.code = "MODULE_NOT_FOUND", a; } var p = n[i2] = { exports: {} }; e[i2][0].call(p.exports, function(r2) { var n2 = e[i2][1][r2]; return o(n2 || r2); }, p, p.exports, r, e, n, t); } return n[i2].exports; } for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]); return o; } return r; }())({ 1: [function(require2, module4, exports4) { const utils = require2("./utils"); const dateTime = function() { "use strict"; const stringToArray = utils.stringToArray; const few = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" ]; const ordinals = [ "Zeroth", "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelfth", "Thirteenth", "Fourteenth", "Fifteenth", "Sixteenth", "Seventeenth", "Eighteenth", "Nineteenth" ]; const decades = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety", "Hundred"]; const magnitudes = ["Thousand", "Million", "Billion", "Trillion"]; function numberToWords(value, ordinal) { var lookup = function(num, prev, ord) { var words2 = ""; if (num <= 19) { words2 = (prev ? " and " : "") + (ord ? ordinals[num] : few[num]); } else if (num < 100) { const tens = Math.floor(num / 10); const remainder = num % 10; words2 = (prev ? " and " : "") + decades[tens - 2]; if (remainder > 0) { words2 += "-" + lookup(remainder, false, ord); } else if (ord) { words2 = words2.substring(0, words2.length - 1) + "ieth"; } } else if (num < 1e3) { const hundreds = Math.floor(num / 100); const remainder = num % 100; words2 = (prev ? ", " : "") + few[hundreds] + " Hundred"; if (remainder > 0) { words2 += lookup(remainder, true, ord); } else if (ord) { words2 += "th"; } } else { var mag = Math.floor(Math.log10(num) / 3); if (mag > magnitudes.length) { mag = magnitudes.length; } const factor = Math.pow(10, mag * 3); const mant = Math.floor(num / factor); const remainder = num - mant * factor; words2 = (prev ? ", " : "") + lookup(mant, false, false) + " " + magnitudes[mag - 1]; if (remainder > 0) { words2 += lookup(remainder, true, ord); } else if (ord) { words2 += "th"; } } return words2; }; var words = lookup(value, false, ordinal); return words; } const wordValues = {}; few.forEach(function(word, index) { wordValues[word.toLowerCase()] = index; }); ordinals.forEach(function(word, index) { wordValues[word.toLowerCase()] = index; }); decades.forEach(function(word, index) { const lword = word.toLowerCase(); wordValues[lword] = (index + 2) * 10; wordValues[lword.substring(0, word.length - 1) + "ieth"] = wordValues[lword]; }); wordValues.hundredth = 100; magnitudes.forEach(function(word, index) { const lword = word.toLowerCase(); const val = Math.pow(10, (index + 1) * 3); wordValues[lword] = val; wordValues[lword + "th"] = val; }); function wordsToNumber(text) { const parts = text.split(/,\s|\sand\s|[\s\\-]/); const values = parts.map((part) => wordValues[part]); let segs = [0]; values.forEach((value) => { if (value < 100) { let top = segs.pop(); if (top >= 1e3) { segs.push(top); top = 0; } segs.push(top + value); } else { segs.push(segs.pop() * value); } }); const result = segs.reduce((a, b) => a + b, 0); return result; } const romanNumerals = [ [1e3, "m"], [900, "cm"], [500, "d"], [400, "cd"], [100, "c"], [90, "xc"], [50, "l"], [40, "xl"], [10, "x"], [9, "ix"], [5, "v"], [4, "iv"], [1, "i"] ]; const romanValues = { "M": 1e3, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1 }; function decimalToRoman(value) { for (var index = 0; index < romanNumerals.length; index++) { const numeral = romanNumerals[index]; if (value >= numeral[0]) { return numeral[1] + decimalToRoman(value - numeral[0]); } } return ""; } function romanToDecimal(roman) { var decimal = 0; var max = 1; for (var i = roman.length - 1; i >= 0; i--) { const digit = roman[i]; const value = romanValues[digit]; if (value < max) { decimal -= value; } else { max = value; decimal += value; } } return decimal; } function decimalToLetters(value, aChar) { var letters = []; var aCode = aChar.charCodeAt(0); while (value > 0) { letters.unshift(String.fromCharCode((value - 1) % 26 + aCode)); value = Math.floor((value - 1) / 26); } return letters.join(""); } function lettersToDecimal(letters, aChar) { var aCode = aChar.charCodeAt(0); var decimal = 0; for (var i = 0; i < letters.length; i++) { decimal += (letters.charCodeAt(letters.length - i - 1) - aCode + 1) * Math.pow(26, i); } return decimal; } function formatInteger(value, picture) { if (typeof value === "undefined") { return void 0; } value = Math.floor(value); const format = analyseIntegerPicture(picture); return _formatInteger(value, format); } const formats = { DECIMAL: "decimal", LETTERS: "letters", ROMAN: "roman", WORDS: "words", SEQUENCE: "sequence" }; const tcase = { UPPER: "upper", LOWER: "lower", TITLE: "title" }; function _formatInteger(value, format) { let formattedInteger; const negative = value < 0; value = Math.abs(value); switch (format.primary) { case formats.LETTERS: formattedInteger = decimalToLetters(value, format.case === tcase.UPPER ? "A" : "a"); break; case formats.ROMAN: formattedInteger = decimalToRoman(value); if (format.case === tcase.UPPER) { formattedInteger = formattedInteger.toUpperCase(); } break; case formats.WORDS: formattedInteger = numberToWords(value, format.ordinal); if (format.case === tcase.UPPER) { formattedInteger = formattedInteger.toUpperCase(); } else if (format.case === tcase.LOWER) { formattedInteger = formattedInteger.toLowerCase(); } break; case formats.DECIMAL: formattedInteger = "" + value; var padLength = format.mandatoryDigits - formattedInteger.length; if (padLength > 0) { var padding = new Array(padLength + 1).join("0"); formattedInteger = padding + formattedInteger; } if (format.zeroCode !== 48) { formattedInteger = stringToArray(formattedInteger).map((code) => { return String.fromCodePoint(code.codePointAt(0) + format.zeroCode - 48); }).join(""); } if (format.regular) { const n = Math.floor((formattedInteger.length - 1) / format.groupingSeparators.position); for (let ii = n; ii > 0; ii--) { const pos = formattedInteger.length - ii * format.groupingSeparators.position; formattedInteger = formattedInteger.substr(0, pos) + format.groupingSeparators.character + formattedInteger.substr(pos); } } else { format.groupingSeparators.reverse().forEach((separator) => { const pos = formattedInteger.length - separator.position; formattedInteger = formattedInteger.substr(0, pos) + separator.character + formattedInteger.substr(pos); }); } if (format.ordinal) { var suffix123 = { "1": "st", "2": "nd", "3": "rd" }; var lastDigit = formattedInteger[formattedInteger.length - 1]; var suffix = suffix123[lastDigit]; if (!suffix || formattedInteger.length > 1 && formattedInteger[formattedInteger.length - 2] === "1") { suffix = "th"; } formattedInteger = formattedInteger + suffix; } break; case formats.SEQUENCE: throw { code: "D3130", value: format.token }; } if (negative) { formattedInteger = "-" + formattedInteger; } return formattedInteger; } const decimalGroups = [48, 1632, 1776, 1984, 2406, 2534, 2662, 2790, 2918, 3046, 3174, 3302, 3430, 3558, 3664, 3792, 3872, 4160, 4240, 6112, 6160, 6470, 6608, 6784, 6800, 6992, 7088, 7232, 7248, 42528, 43216, 43264, 43472, 43504, 43600, 44016, 65296]; function analyseIntegerPicture(picture) { const format = { type: "integer", primary: formats.DECIMAL, case: tcase.LOWER, ordinal: false }; let primaryFormat, formatModifier; const semicolon = picture.lastIndexOf(";"); if (semicolon === -1) { primaryFormat = picture; } else { primaryFormat = picture.substring(0, semicolon); formatModifier = picture.substring(semicolon + 1); if (formatModifier[0] === "o") { format.ordinal = true; } } switch (primaryFormat) { case "A": format.case = tcase.UPPER; /* eslnt-disable-next-line no-fallthrough */ case "a": format.primary = formats.LETTERS; break; case "I": format.case = tcase.UPPER; /* eslnt-disable-next-line no-fallthrough */ case "i": format.primary = formats.ROMAN; break; case "W": format.case = tcase.UPPER; format.primary = formats.WORDS; break; case "Ww": format.case = tcase.TITLE; format.primary = formats.WORDS; break; case "w": format.primary = formats.WORDS; break; default: { let zeroCode = null; let mandatoryDigits = 0; let optionalDigits = 0; let groupingSeparators = []; let separatorPosition = 0; const formatCodepoints = stringToArray(primaryFormat).map((c) => c.codePointAt(0)).reverse(); formatCodepoints.forEach((codePoint) => { let digit = false; for (let ii = 0; ii < decimalGroups.length; ii++) { const group = decimalGroups[ii]; if (codePoint >= group && codePoint <= group + 9) { digit = true; mandatoryDigits++; separatorPosition++; if (zeroCode === null) { zeroCode = group; } else if (group !== zeroCode) { throw { code: "D3131" }; } break; } } if (!digit) { if (codePoint === 35) { separatorPosition++; optionalDigits++; } else { groupingSeparators.push({ position: separatorPosition, character: String.fromCodePoint(codePoint) }); } } }); if (mandatoryDigits > 0) { format.primary = formats.DECIMAL; format.zeroCode = zeroCode; format.mandatoryDigits = mandatoryDigits; format.optionalDigits = optionalDigits; const regularRepeat = function(separators) { if (separators.length === 0) { return 0; } const sepChar = separators[0].character; for (let ii = 1; ii < separators.length; ii++) { if (separators[ii].character !== sepChar) { return 0; } } const indexes = separators.map((separator) => separator.position); const gcd = function(a, b) { return b === 0 ? a : gcd(b, a % b); }; const factor = indexes.reduce(gcd); for (let index = 1; index <= indexes.length; index++) { if (indexes.indexOf(index * factor) === -1) { return 0; } } return factor; }; const regular = regularRepeat(groupingSeparators); if (regular > 0) { format.regular = true; format.groupingSeparators = { position: regular, character: groupingSeparators[0].character }; } else { format.regular = false; format.groupingSeparators = groupingSeparators; } } else { format.primary = formats.SEQUENCE; format.token = primaryFormat; } } } return format; } const defaultPresentationModifiers = { Y: "1", M: "1", D: "1", d: "1", F: "n", W: "1", w: "1", X: "1", x: "1", H: "1", h: "1", P: "n", m: "01", s: "01", f: "1", Z: "01:01", z: "01:01", C: "n", E: "n" }; function analyseDateTimePicture(picture) { var spec = []; const format = { type: "datetime", parts: spec }; const addLiteral = function(start2, end) { if (end > start2) { let literal = picture.substring(start2, end); literal = literal.split("]]").join("]"); spec.push({ type: "literal", value: literal }); } }; var start = 0, pos = 0; while (pos < picture.length) { if (picture.charAt(pos) === "[") { if (picture.charAt(pos + 1) === "[") { addLiteral(start, pos); spec.push({ type: "literal", value: "[" }); pos += 2; start = pos; continue; } addLiteral(start, pos); start = pos; pos = picture.indexOf("]", start); if (pos === -1) { throw { code: "D3135" }; } let marker = picture.substring(start + 1, pos); marker = marker.split(/\s+/).join(""); var def = { type: "marker", component: marker.charAt(0) // 1. The component specifier is always present and is always a single letter. }; var comma = marker.lastIndexOf(","); var presMod; if (comma !== -1) { const widthMod = marker.substring(comma + 1); const dash = widthMod.indexOf("-"); let min, max; const parseWidth = function(wm) { if (typeof wm === "undefined" || wm === "*") { return void 0; } else { return parseInt(wm); } }; if (dash === -1) { min = widthMod; } else { min = widthMod.substring(0, dash); max = widthMod.substring(dash + 1); } const widthDef = { min: parseWidth(min), max: parseWidth(max) }; def.width = widthDef; presMod = marker.substring(1, comma); } else { presMod = marker.substring(1); } if (presMod.length === 1) { def.presentation1 = presMod; } else if (presMod.length > 1) { var lastChar = presMod.charAt(presMod.length - 1); if ("atco".indexOf(lastChar) !== -1) { def.presentation2 = lastChar; if (lastChar === "o") { def.ordinal = true; } def.presentation1 = presMod.substring(0, presMod.length - 1); } else { def.presentation1 = presMod; } } else { def.presentation1 = defaultPresentationModifiers[def.component]; } if (typeof def.presentation1 === "undefined") { throw { code: "D3132", value: def.component }; } if (def.presentation1[0] === "n") { def.names = tcase.LOWER; } else if (def.presentation1[0] === "N") { if (def.presentation1[1] === "n") { def.names = tcase.TITLE; } else { def.names = tcase.UPPER; } } else if ("YMDdFWwXxHhmsf".indexOf(def.component) !== -1) { var integerPattern = def.presentation1; if (def.presentation2) { integerPattern += ";" + def.presentation2; } def.integerFormat = analyseIntegerPicture(integerPattern); if (def.width && def.width.min !== void 0) { if (def.integerFormat.mandatoryDigits < def.width.min) { def.integerFormat.mandatoryDigits = def.width.min; } } if ("YMD".indexOf(def.component) !== -1) { def.n = -1; if (def.width && def.width.max !== void 0) { def.n = def.width.max; def.integerFormat.mandatoryDigits = def.n; } else { var w = def.integerFormat.mandatoryDigits + def.integerFormat.optionalDigits; if (w >= 2) { def.n = w; } } } } if (def.component === "Z" || def.component === "z") { def.integerFormat = analyseIntegerPicture(def.presentation1); } spec.push(def); start = pos + 1; } pos++; } addLiteral(start, pos); return format; } const days = ["", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; const millisInADay = 1e3 * 60 * 60 * 24; const startOfFirstWeek = function(ym) { const jan1 = Date.UTC(ym.year, ym.month); var dayOfJan1 = new Date(jan1).getUTCDay(); if (dayOfJan1 === 0) { dayOfJan1 = 7; } return dayOfJan1 > 4 ? jan1 + (8 - dayOfJan1) * millisInADay : jan1 - (dayOfJan1 - 1) * millisInADay; }; const yearMonth = function(year, month) { return { year, month, nextMonth: function() { return month === 11 ? yearMonth(year + 1, 0) : yearMonth(year, month + 1); }, previousMonth: function() { return month === 0 ? yearMonth(year - 1, 11) : yearMonth(year, month - 1); }, nextYear: function() { return yearMonth(year + 1, month); }, previousYear: function() { return yearMonth(year - 1, month); } }; }; const deltaWeeks = function(start, end) { return (end - start) / (millisInADay * 7) + 1; }; const getDateTimeFragment = (date, component) => { let componentValue; switch (component) { case "Y": componentValue = date.getUTCFullYear(); break; case "M": componentValue = date.getUTCMonth() + 1; break; case "D": componentValue = date.getUTCDate(); break; case "d": { const today = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); const firstJan = Date.UTC(date.getUTCFullYear(), 0); componentValue = (today - firstJan) / millisInADay + 1; break; } case "F": componentValue = date.getUTCDay(); if (componentValue === 0) { componentValue = 7; } break; case "W": { const thisYear = yearMonth(date.getUTCFullYear(), 0); const startOfWeek1 = startOfFirstWeek(thisYear); const today = Date.UTC(thisYear.year, date.getUTCMonth(), date.getUTCDate()); let week = deltaWeeks(startOfWeek1, today); if (week > 52) { const startOfFollowingYear = startOfFirstWeek(thisYear.nextYear()); if (today >= startOfFollowingYear) { week = 1; } } else if (week < 1) { const startOfPreviousYear = startOfFirstWeek(thisYear.previousYear()); week = deltaWeeks(startOfPreviousYear, today); } componentValue = Math.floor(week); break; } case "w": { const thisMonth = yearMonth(date.getUTCFullYear(), date.getUTCMonth()); const startOfWeek1 = startOfFirstWeek(thisMonth); const today = Date.UTC(thisMonth.year, thisMonth.month, date.getUTCDate()); let week = deltaWeeks(startOfWeek1, today); if (week > 4) { const startOfFollowingMonth = startOfFirstWeek(thisMonth.nextMonth()); if (today >= startOfFollowingMonth) { week = 1; } } else if (week < 1) { const startOfPreviousMonth = startOfFirstWeek(thisMonth.previousMonth()); week = deltaWeeks(startOfPreviousMonth, today); } componentValue = Math.floor(week); break; } case "X": { const thisYear = yearMonth(date.getUTCFullYear(), 0); const startOfISOYear = startOfFirstWeek(thisYear); const endOfISOYear = startOfFirstWeek(thisYear.nextYear()); const now = date.getTime(); if (now < startOfISOYear) { componentValue = thisYear.year - 1; } else if (now >= endOfISOYear) { componentValue = thisYear.year + 1; } else { componentValue = thisYear.year; } break; } case "x": { const thisMonth = yearMonth(date.getUTCFullYear(), date.getUTCMonth()); const startOfISOMonth = startOfFirstWeek(thisMonth); const nextMonth = thisMonth.nextMonth(); const endOfISOMonth = startOfFirstWeek(nextMonth); const now = date.getTime(); if (now < startOfISOMonth) { componentValue = thisMonth.previousMonth().month + 1; } else if (now >= endOfISOMonth) { componentValue = nextMonth.month + 1; } else { componentValue = thisMonth.month + 1; } break; } case "H": componentValue = date.getUTCHours(); break; case "h": componentValue = date.getUTCHours(); componentValue = componentValue % 12; if (componentValue === 0) { componentValue = 12; } break; case "P": componentValue = date.getUTCHours() >= 12 ? "pm" : "am"; break; case "m": componentValue = date.getUTCMinutes(); break; case "s": componentValue = date.getUTCSeconds(); break; case "f": componentValue = date.getUTCMilliseconds(); break; case "Z": // timezone case "z": break; case "C": componentValue = "ISO"; break; case "E": componentValue = "ISO"; break; } return componentValue; }; let iso8601Spec = null; function formatDateTime(millis, picture, timezone) { var offsetHours = 0; var offsetMinutes = 0; if (typeof timezone !== "undefined") { const offset = parseInt(timezone); offsetHours = Math.floor(offset / 100); offsetMinutes = offset % 100; } var formatComponent = function(date, markerSpec) { var componentValue = getDateTimeFragment(date, markerSpec.component); if ("YMDdFWwXxHhms".indexOf(markerSpec.component) !== -1) { if (markerSpec.component === "Y") { if (markerSpec.n !== -1) { componentValue = componentValue % Math.pow(10, markerSpec.n); } } if (markerSpec.names) { if (markerSpec.component === "M" || markerSpec.component === "x") { componentValue = months[componentValue - 1]; } else if (markerSpec.component === "F") { componentValue = days[componentValue]; } else { throw { code: "D3133", value: markerSpec.component }; } if (markerSpec.names === tcase.UPPER) { componentValue = componentValue.toUpperCase(); } else if (markerSpec.names === tcase.LOWER) { componentValue = componentValue.toLowerCase(); } if (markerSpec.width && componentValue.length > markerSpec.width.max) { componentValue = componentValue.substring(0, markerSpec.width.max); } } else { componentValue = _formatInteger(componentValue, markerSpec.integerFormat); } } else if (markerSpec.component === "f") { componentValue = _formatInteger(componentValue, markerSpec.integerFormat); } else if (markerSpec.component === "Z" || markerSpec.component === "z") { const offset = offsetHours * 100 + offsetMinutes; if (markerSpec.integerFormat.regular) { componentValue = _formatInteger(offset, markerSpec.integerFormat); } else { const numDigits = markerSpec.integerFormat.mandatoryDigits; if (numDigits === 1 || numDigits === 2) { componentValue = _formatInteger(offsetHours, markerSpec.integerFormat); if (offsetMinutes !== 0) { componentValue += ":" + formatInteger(offsetMinutes, "00"); } } else if (numDigits === 3 || numDigits === 4) { componentValue = _formatInteger(offset, markerSpec.integerFormat); } else { throw { code: "D3134", value: numDigits }; } } if (offset >= 0) { componentValue = "+" + componentValue; } if (markerSpec.component === "z") { componentValue = "GMT" + componentValue; } if (offset === 0 && markerSpec.presentation2 === "t") { componentValue = "Z"; } } else if (markerSpec.component === "P") { if (markerSpec.names === tcase.UPPER) { componentValue = componentValue.toUpperCase(); } } return componentValue; }; let formatSpec; if (typeof picture === "undefined") { if (iso8601Spec === null) { iso8601Spec = analyseDateTimePicture("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]"); } formatSpec = iso8601Spec; } else { formatSpec = analyseDateTimePicture(picture); } const offsetMillis = (60 * offsetHours + offsetMinutes) * 60 * 1e3; const dateTime2 = new Date(millis + offsetMillis); let result = ""; formatSpec.parts.forEach(function(part) { if (part.type === "literal") { result += part.value; } else { result += formatComponent(dateTime2, part); } }); return result; } function generateRegex(formatSpec) { var matcher = {}; if (formatSpec.type === "datetime") { matcher.type = "datetime"; matcher.parts = formatSpec.parts.map(function(part) { var res = {}; if (part.type === "literal") { res.regex = part.value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } else if (part.component === "Z" || part.component === "z") { let separator; if (!Array.isArray(part.integerFormat.groupingSeparators)) { separator = part.integerFormat.groupingSeparators; } res.regex = ""; if (part.component === "z") { res.regex = "GMT"; } res.regex += "[-+][0-9]+"; if (separator) { res.regex += separator.character + "[0-9]+"; } res.parse = function(value) { if (part.component === "z") { value = value.substring(3); } let offsetHours = 0, offsetMinutes = 0; if (separator) { offsetHours = Number.parseInt(value.substring(0, value.indexOf(separator.character))); offsetMinutes = Number.parseInt(value.substring(value.indexOf(separator.character) + 1)); } else { const numdigits = value.length - 1; if (numdigits <= 2) { offsetHours = Number.parseInt(value); } else { offsetHours = Number.parseInt(value.substring(0, 3)); offsetMinutes = Number.parseInt(value.substring(3)); } } return offsetHours * 60 + offsetMinutes; }; } else if (part.integerFormat) { part.integerFormat.n = part.n; res = generateRegex(part.integerFormat); } else { res.regex = "[a-zA-Z]+"; var lookup = {}; if (part.component === "M" || part.component === "x") { months.forEach(function(name, index) { if (part.width && part.width.max) { lookup[name.substring(0, part.width.max)] = index + 1; } else { lookup[name] = index + 1; } }); } else if (part.component === "F") { days.forEach(function(name, index) { if (index > 0) { if (part.width && part.width.max) { lookup[name.substring(0, part.width.max)] = index; } else { lookup[name] = index; } } }); } else if (part.component === "P") { lookup = { "am": 0, "AM": 0, "pm": 1, "PM": 1 }; } else { throw { code: "D3133", value: part.component }; } res.parse = function(value) { return lookup[value]; }; } res.component = part.component; return res; }); } else { matcher.type = "integer"; const isUpper = formatSpec.case === tcase.UPPER; let occurrences; if (formatSpec.n && formatSpec.n > 0) { if (formatSpec.optionalDigits === 0) { occurrences = `{${formatSpec.n}}`; } else { occurrences = `{${formatSpec.n - formatSpec.optionalDigits},${formatSpec.n}}`; } } else { occurrences = "+"; } switch (formatSpec.primary) { case formats.LETTERS: matcher.regex = isUpper ? "[A-Z]+" : "[a-z]+"; matcher.parse = function(value) { return lettersToDecimal(value, isUpper ? "A" : "a"); }; break; case formats.ROMAN: matcher.regex = isUpper ? "[MDCLXVI]+" : "[mdclxvi]+"; matcher.parse = function(value) { return romanToDecimal(isUpper ? value : value.toUpperCase()); }; break; case formats.WORDS: matcher.regex = "(?:" + Object.keys(wordValues).concat("and", "[\\-, ]").join("|") + ")+"; matcher.parse = function(value) { return wordsToNumber(value.toLowerCase()); }; break; case formats.DECIMAL: matcher.regex = `[0-9]${occurrences}`; if (formatSpec.ordinal) { matcher.regex += "(?:th|st|nd|rd)"; } matcher.parse = function(value) { let digits = value; if (formatSpec.ordinal) { digits = value.substring(0, value.length - 2); } if (formatSpec.regular) { digits = digits.split(",").join(""); } else { formatSpec.groupingSeparators.forEach((sep) => { digits = digits.split(sep.character).join(""); }); } if (formatSpec.zeroCode !== 48) { digits = digits.split("").map((char) => String.fromCodePoint(char.codePointAt(0) - formatSpec.zeroCode + 48)).join(""); } return parseInt(digits); }; break; case formats.SEQUENCE: throw { code: "D3130", value: formatSpec.token }; } } return matcher; } function parseInteger(value, picture) { if (typeof value === "undefined") { return void 0; } const formatSpec = analyseIntegerPicture(picture); const matchSpec = generateRegex(formatSpec); const result = matchSpec.parse(value); return result; } function parseDateTime(timestamp, picture) { const formatSpec = analyseDateTimePicture(picture); const matchSpec = generateRegex(formatSpec); const fullRegex = "^" + matchSpec.parts.map((part) => "(" + part.regex + ")").join("") + "$"; const matcher = new RegExp(fullRegex, "i"); var info = matcher.exec(timestamp); if (info !== null) { const dmA = 161; const dmB = 130; const dmC = 84; const dmD = 72; const tmA = 23; const tmB = 47; const components = {}; for (let i = 1; i < info.length; i++) { const mpart = matchSpec.parts[i - 1]; if (mpart.parse) { components[mpart.component] = mpart.parse(info[i]); } } if (Object.getOwnPropertyNames(components).length === 0) { return void 0; } let mask = 0; const shift = (bit) => { mask <<= 1; mask += bit ? 1 : 0; }; const isType = (type) => { return !(~type & mask) && !!(type & mask); }; "YXMxWwdD".split("").forEach((part) => shift(components[part])); const dateA = isType(dmA); const dateB = !dateA && isType(dmB); const dateC = isType(dmC); const dateD = !dateC && isType(dmD); mask = 0; "PHhmsf".split("").forEach((part) => shift(components[part])); const timeA = isType(tmA); const timeB = !timeA && isType(tmB); const dateComps = dateB ? "YD" : dateC ? "XxwF" : dateD ? "XWF" : "YMD"; const timeComps = timeB ? "Phmsf" : "Hmsf"; const comps = dateComps + timeComps; const now = this.environment.timestamp; let startSpecified = false; let endSpecified = false; comps.split("").forEach((part) => { if (typeof components[part] === "undefined") { if (startSpecified) { components[part] = "MDd".indexOf(part) !== -1 ? 1 : 0; endSpecified = true; } else { components[part] = getDateTimeFragment(now, part); } } else { startSpecified = true; if (endSpecified) { throw { code: "D3136" }; } } }); if (components.M > 0) { components.M -= 1; } else { components.M = 0; } if (dateB) { const firstJan = Date.UTC(components.Y, 0); const offsetMillis = (components.d - 1) * 1e3 * 60 * 60 * 24; const derivedDate = new Date(firstJan + offsetMillis); components.M = derivedDate.getUTCMonth(); components.D = derivedDate.getUTCDate(); } if (dateC) { throw { code: "D3136" }; } if (dateD) { throw { code: "D3136" }; } if (timeB) { components.H = components.h === 12 ? 0 : components.h; if (components.P === 1) { components.H += 12; } } var millis = Date.UTC(components.Y, components.M, components.D, components.H, components.m, components.s, components.f); if (components.Z || components.z) { millis -= (components.Z || components.z) * 60 * 1e3; } return millis; } } var iso8601regex = new RegExp("^\\d{4}(-[01]\\d)*(-[0-3]\\d)*(T[0-2]\\d:[0-5]\\d:[0-5]\\d)*(\\.\\d+)?([+-][0-2]\\d:?[0-5]\\d|Z)?$"); function toMillis(timestamp, picture) { if (typeof timestamp === "undefined") { return void 0; } if (typeof picture === "undefined") { if (!iso8601regex.test(timestamp)) { throw { stack: new Error().stack, code: "D3110", value: timestamp }; } return Date.parse(timestamp); } else { return parseDateTime.call(this, timestamp, picture); } } function fromMillis(millis, picture, timezone) { if (typeof millis === "undefined") { return void 0; } return formatDateTime.call(this, millis, picture, timezone); } return { formatInteger, parseInteger, fromMillis, toMillis }; }(); module4.exports = dateTime; }, { "./utils": 6 }], 2: [function(require2, module4, exports4) { (function(global2) { (function() { var utils = require2("./utils"); const functions = (() => { "use strict"; var isNumeric = utils.isNumeric; var isArrayOfStrings = utils.isArrayOfStrings; var isArrayOfNumbers = utils.isArrayOfNumbers; var createSequence = utils.createSequence; var isSequence = utils.isSequence; var isFunction = utils.isFunction; var isLambda = utils.isLambda; var isPromise = utils.isPromise; var getFunctionArity = utils.getFunctionArity; var deepEquals = utils.isDeepEqual; var stringToArray = utils.stringToArray; function sum(args) { if (typeof args === "undefined") { return void 0; } var total = 0; args.forEach(function(num) { total += num; }); return total; } function count(args) { if (typeof args === "undefined") { return 0; } return args.length; } function max(args) { if (typeof args === "undefined" || args.length === 0) { return void 0; } return Math.max.apply(Math, args); } function min(args) { if (typeof args === "undefined" || args.length === 0) { return void 0; } return Math.min.apply(Math, args); } function average(args) { if (typeof args === "undefined" || args.length === 0) { return void 0; } var total = 0; args.forEach(function(num) { total += num; }); return total / args.length; } function string(arg, prettify = false) { if (typeof arg === "undefined") {