UNPKG

test-jsonata

Version:

JSON query and transformation language

1 lines 75.4 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).jsonata=e()}}(function(){return function(){return function e(t,r,n){function i(o,s){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[o]={exports:{}};t[o][0].call(l.exports,function(e){return i(t[o][1][e]||e)},l,l.exports,e,t,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}}()({1:[function(e,t,r){const n=e("./utils"),i=function(){"use strict";const e=n.stringToArray,t=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],r=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],i=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],a=["Thousand","Million","Billion","Trillion"];const o={};t.forEach(function(e,t){o[e.toLowerCase()]=t}),r.forEach(function(e,t){o[e.toLowerCase()]=t}),i.forEach(function(e,t){const r=e.toLowerCase();o[r]=10*(t+2),o[r.substring(0,e.length-1)+"ieth"]=o[r]}),o.hundredth=100,a.forEach(function(e,t){const r=e.toLowerCase(),n=Math.pow(10,3*(t+1));o[r]=n,o[r+"th"]=n});const s=[[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"]],u={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function c(e,t){if(void 0===e)return;return f(e=Math.floor(e),h(t))}const l={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},p={UPPER:"upper",LOWER:"lower",TITLE:"title"};function f(n,o){let u;const c=n<0;switch(n=Math.abs(n),o.primary){case l.LETTERS:u=function(e,t){for(var r=[],n=t.charCodeAt(0);e>0;)r.unshift(String.fromCharCode((e-1)%26+n)),e=Math.floor((e-1)/26);return r.join("")}(n,o.case===p.UPPER?"A":"a");break;case l.ROMAN:u=function e(t){for(var r=0;r<s.length;r++){const n=s[r];if(t>=n[0])return n[1]+e(t-n[0])}return""}(n),o.case===p.UPPER&&(u=u.toUpperCase());break;case l.WORDS:u=function(e,n){var o=function(e,n,s){var u="";if(e<=19)u=(n?" and ":"")+(s?r[e]:t[e]);else if(e<100){const t=Math.floor(e/10),r=e%10;u=(n?" and ":"")+i[t-2],r>0?u+="-"+o(r,!1,s):s&&(u=u.substring(0,u.length-1)+"ieth")}else if(e<1e3){const r=Math.floor(e/100),i=e%100;u=(n?", ":"")+t[r]+" Hundred",i>0?u+=o(i,!0,s):s&&(u+="th")}else{var c=Math.floor(Math.log10(e)/3);c>a.length&&(c=a.length);const t=Math.pow(10,3*c),r=Math.floor(e/t),i=e-r*t;u=(n?", ":"")+o(r,!1,!1)+" "+a[c-1],i>0?u+=o(i,!0,s):s&&(u+="th")}return u};return o(e,!1,n)}(n,o.ordinal),o.case===p.UPPER?u=u.toUpperCase():o.case===p.LOWER&&(u=u.toLowerCase());break;case l.DECIMAL:u=""+n;var f=o.mandatoryDigits-u.length;if(f>0){var d=new Array(f+1).join("0");u=d+u}if(48!==o.zeroCode&&(u=e(u).map(e=>String.fromCodePoint(e.codePointAt(0)+o.zeroCode-48)).join("")),o.regular){for(let e=Math.floor((u.length-1)/o.groupingSeparators.position);e>0;e--){const t=u.length-e*o.groupingSeparators.position;u=u.substr(0,t)+o.groupingSeparators.character+u.substr(t)}}else o.groupingSeparators.reverse().forEach(e=>{const t=u.length-e.position;u=u.substr(0,t)+e.character+u.substr(t)});if(o.ordinal){var h={1:"st",2:"nd",3:"rd"}[u[u.length-1]];(!h||u.length>1&&"1"===u[u.length-2])&&(h="th"),u+=h}break;case l.SEQUENCE:throw{code:"D3130",value:o.token}}return c&&(u="-"+u),u}const d=[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 h(t){const r={type:"integer",primary:l.DECIMAL,case:p.LOWER,ordinal:!1};let n,i;const a=t.lastIndexOf(";");switch(-1===a?n=t:(n=t.substring(0,a),"o"===(i=t.substring(a+1))[0]&&(r.ordinal=!0)),n){case"A":r.case=p.UPPER;case"a":r.primary=l.LETTERS;break;case"I":r.case=p.UPPER;case"i":r.primary=l.ROMAN;break;case"W":r.case=p.UPPER,r.primary=l.WORDS;break;case"Ww":r.case=p.TITLE,r.primary=l.WORDS;break;case"w":r.primary=l.WORDS;break;default:{let t=null,i=0,a=0,o=[],s=0;if(e(n).map(e=>e.codePointAt(0)).reverse().forEach(e=>{let r=!1;for(let n=0;n<d.length;n++){const a=d[n];if(e>=a&&e<=a+9){if(r=!0,i++,s++,null===t)t=a;else if(a!==t)throw{code:"D3131"};break}}r||(35===e?(s++,a++):o.push({position:s,character:String.fromCodePoint(e)}))}),i>0){r.primary=l.DECIMAL,r.zeroCode=t,r.mandatoryDigits=i,r.optionalDigits=a;const e=function(e){if(0===e.length)return 0;const t=e[0].character;for(let r=1;r<e.length;r++)if(e[r].character!==t)return 0;const r=e.map(e=>e.position),n=function(e,t){return 0===t?e:n(t,e%t)},i=r.reduce(n);for(let e=1;e<=r.length;e++)if(-1===r.indexOf(e*i))return 0;return i}(o);e>0?(r.regular=!0,r.groupingSeparators={position:e,character:o[0].character}):(r.regular=!1,r.groupingSeparators=o)}else r.primary=l.SEQUENCE,r.token=n}}return r}const v={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 g(e){var t=[];const r={type:"datetime",parts:t},n=function(r,n){if(n>r){let i=e.substring(r,n);i=i.split("]]").join("]"),t.push({type:"literal",value:i})}};for(var i=0,a=0;a<e.length;){if("["===e.charAt(a)){if("["===e.charAt(a+1)){n(i,a),t.push({type:"literal",value:"["}),i=a+=2;continue}if(n(i,a),i=a,-1===(a=e.indexOf("]",i)))throw{code:"D3135"};let r=e.substring(i+1,a);var o,s={type:"marker",component:(r=r.split(/\s+/).join("")).charAt(0)},u=r.lastIndexOf(",");if(-1!==u){const e=r.substring(u+1),t=e.indexOf("-");let n,i;const a=function(e){return void 0===e||"*"===e?void 0:parseInt(e)};-1===t?n=e:(n=e.substring(0,t),i=e.substring(t+1));const c={min:a(n),max:a(i)};s.width=c,o=r.substring(1,u)}else o=r.substring(1);if(1===o.length)s.presentation1=o;else if(o.length>1){var c=o.charAt(o.length-1);-1!=="atco".indexOf(c)?(s.presentation2=c,"o"===c&&(s.ordinal=!0),s.presentation1=o.substring(0,o.length-1)):s.presentation1=o}else s.presentation1=v[s.component];if(void 0===s.presentation1)throw{code:"D3132",value:s.component};if("n"===s.presentation1[0])s.names=p.LOWER;else if("N"===s.presentation1[0])"n"===s.presentation1[1]?s.names=p.TITLE:s.names=p.UPPER;else if(-1!=="YMDdFWwXxHhmsf".indexOf(s.component)){var l=s.presentation1;if(s.presentation2&&(l+=";"+s.presentation2),s.integerFormat=h(l),s.width&&void 0!==s.width.min&&s.integerFormat.mandatoryDigits<s.width.min&&(s.integerFormat.mandatoryDigits=s.width.min),"Y"===s.component)if(s.n=-1,s.width&&void 0!==s.width.max)s.n=s.width.max,s.integerFormat.mandatoryDigits=s.n;else{var f=s.integerFormat.mandatoryDigits+s.integerFormat.optionalDigits;f>=2&&(s.n=f)}}"Z"!==s.component&&"z"!==s.component||(s.integerFormat=h(s.presentation1)),t.push(s),i=a+1}a++}return n(i,a),r}const y=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],m=["January","February","March","April","May","June","July","August","September","October","November","December"],b=function(e){const t=Date.UTC(e.year,e.month);var r=new Date(t).getUTCDay();return 0===r&&(r=7),r>4?t+864e5*(8-r):t-864e5*(r-1)},k=function(e,t){return{year:e,month:t,nextMonth:function(){return 11===t?k(e+1,0):k(e,t+1)},previousMonth:function(){return 0===t?k(e-1,11):k(e,t-1)},nextYear:function(){return k(e+1,t)},previousYear:function(){return k(e-1,t)}}},x=function(e,t){return(t-e)/6048e5+1},w=(e,t)=>{let r;switch(t){case"Y":r=e.getUTCFullYear();break;case"M":r=e.getUTCMonth()+1;break;case"D":r=e.getUTCDate();break;case"d":r=(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())-Date.UTC(e.getUTCFullYear(),0))/864e5+1;break;case"F":0===(r=e.getUTCDay())&&(r=7);break;case"W":{const t=k(e.getUTCFullYear(),0),n=b(t),i=Date.UTC(t.year,e.getUTCMonth(),e.getUTCDate());let a=x(n,i);if(a>52){i>=b(t.nextYear())&&(a=1)}else if(a<1){const e=b(t.previousYear());a=x(e,i)}r=Math.floor(a);break}case"w":{const t=k(e.getUTCFullYear(),e.getUTCMonth()),n=b(t),i=Date.UTC(t.year,t.month,e.getUTCDate());let a=x(n,i);if(a>4){i>=b(t.nextMonth())&&(a=1)}else if(a<1){const e=b(t.previousMonth());a=x(e,i)}r=Math.floor(a);break}case"X":{const t=k(e.getUTCFullYear(),0),n=b(t),i=b(t.nextYear()),a=e.getTime();r=a<n?t.year-1:a>=i?t.year+1:t.year;break}case"x":{const t=k(e.getUTCFullYear(),e.getUTCMonth()),n=b(t),i=t.nextMonth(),a=b(i),o=e.getTime();r=o<n?t.previousMonth().month+1:o>=a?i.month+1:t.month+1;break}case"H":r=e.getUTCHours();break;case"h":r=e.getUTCHours(),0===(r%=12)&&(r=12);break;case"P":r=e.getUTCHours()>=12?"pm":"am";break;case"m":r=e.getUTCMinutes();break;case"s":r=e.getUTCSeconds();break;case"f":r=e.getUTCMilliseconds();break;case"Z":case"z":break;case"C":case"E":r="ISO"}return r};let A=null;function E(e,t,r){var n=0,i=0;if(void 0!==r){const e=parseInt(r);n=Math.floor(e/100),i=e%100}let a;void 0===t?(null===A&&(A=g("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),a=A):a=g(t);const o=new Date(e+60*(60*n+i)*1e3);let s="";return a.parts.forEach(function(e){"literal"===e.type?s+=e.value:s+=function(e,t){var r=w(e,t.component);if(-1!=="YMDdFWwXxHhms".indexOf(t.component))if("Y"===t.component&&-1!==t.n&&(r%=Math.pow(10,t.n)),t.names){if("M"===t.component||"x"===t.component)r=m[r-1];else{if("F"!==t.component)throw{code:"D3133",value:t.component};r=y[r]}t.names===p.UPPER?r=r.toUpperCase():t.names===p.LOWER&&(r=r.toLowerCase()),t.width&&r.length>t.width.max&&(r=r.substring(0,t.width.max))}else r=f(r,t.integerFormat);else if("f"===t.component)r=f(r,t.integerFormat);else if("Z"===t.component||"z"===t.component){const e=100*n+i;if(t.integerFormat.regular)r=f(e,t.integerFormat);else{const a=t.integerFormat.mandatoryDigits;if(1===a||2===a)r=f(n,t.integerFormat),0!==i&&(r+=":"+c(i,"00"));else{if(3!==a&&4!==a)throw{code:"D3134",value:a};r=f(e,t.integerFormat)}}e>=0&&(r="+"+r),"z"===t.component&&(r="GMT"+r),0===e&&"t"===t.presentation2&&(r="Z")}return r}(o,e)}),s}function T(e){var t={};if("datetime"===e.type)t.type="datetime",t.parts=e.parts.map(function(e){var t={};if("literal"===e.type)t.regex=e.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if("Z"===e.component||"z"===e.component){let r;Array.isArray(e.integerFormat.groupingSeparators)||(r=e.integerFormat.groupingSeparators),t.regex="","z"===e.component&&(t.regex="GMT"),t.regex+="[-+][0-9]+",r&&(t.regex+=r.character+"[0-9]+"),t.parse=function(t){"z"===e.component&&(t=t.substring(3));let n=0,i=0;if(r)n=Number.parseInt(t.substring(0,t.indexOf(r.character))),i=Number.parseInt(t.substring(t.indexOf(r.character)+1));else{t.length-1<=2?n=Number.parseInt(t):(n=Number.parseInt(t.substring(0,3)),i=Number.parseInt(t.substring(3)))}return 60*n+i}}else if(e.integerFormat)t=T(e.integerFormat);else{t.regex="[a-zA-Z]+";var r={};if("M"===e.component||"x"===e.component)m.forEach(function(t,n){e.width&&e.width.max?r[t.substring(0,e.width.max)]=n+1:r[t]=n+1});else if("F"===e.component)y.forEach(function(t,n){n>0&&(e.width&&e.width.max?r[t.substring(0,e.width.max)]=n:r[t]=n)});else{if("P"!==e.component)throw{code:"D3133",value:e.component};r={am:0,AM:0,pm:1,PM:1}}t.parse=function(e){return r[e]}}return t.component=e.component,t});else{t.type="integer";const r=e.case===p.UPPER;switch(e.primary){case l.LETTERS:t.regex=r?"[A-Z]+":"[a-z]+",t.parse=function(e){return function(e,t){for(var r=t.charCodeAt(0),n=0,i=0;i<e.length;i++)n+=(e.charCodeAt(e.length-i-1)-r+1)*Math.pow(26,i);return n}(e,r?"A":"a")};break;case l.ROMAN:t.regex=r?"[MDCLXVI]+":"[mdclxvi]+",t.parse=function(e){return function(e){for(var t=0,r=1,n=e.length-1;n>=0;n--){const i=e[n],a=u[i];a<r?t-=a:(r=a,t+=a)}return t}(r?e:e.toUpperCase())};break;case l.WORDS:t.regex="(?:"+Object.keys(o).concat("and","[\\-, ]").join("|")+")+",t.parse=function(e){return function(e){const t=e.split(/,\s|\sand\s|[\s\\-]/).map(e=>o[e]);let r=[0];return t.forEach(e=>{if(e<100){let t=r.pop();t>=1e3&&(r.push(t),t=0),r.push(t+e)}else r.push(r.pop()*e)}),r.reduce((e,t)=>e+t,0)}(e.toLowerCase())};break;case l.DECIMAL:t.regex="[0-9]+",e.ordinal&&(t.regex+="(?:th|st|nd|rd)"),t.parse=function(t){let r=t;return e.ordinal&&(r=t.substring(0,t.length-2)),e.regular?r=r.split(",").join(""):e.groupingSeparators.forEach(e=>{r=r.split(e.character).join("")}),48!==e.zeroCode&&(r=r.split("").map(t=>String.fromCodePoint(t.codePointAt(0)-e.zeroCode+48)).join("")),parseInt(r)};break;case l.SEQUENCE:throw{code:"D3130",value:e.token}}}return t}var D=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)?$");return{formatInteger:c,parseInteger:function(e,t){if(void 0===e)return;return T(h(t)).parse(e)},fromMillis:function(e,t,r){if(void 0!==e)return E.call(this,e,t,r)},toMillis:function(e,t){if(void 0!==e){if(void 0===t){if(!D.test(e))throw{stack:(new Error).stack,code:"D3110",value:e};return Date.parse(e)}return function(e,t){const r=T(g(t)),n="^"+r.parts.map(e=>"("+e.regex+")").join("")+"$";var i=new RegExp(n,"i").exec(e);if(null!==i){const e=161,t=130,n=84,o=72,s=23,u=47,c={};for(let e=1;e<i.length;e++){const t=r.parts[e-1];t.parse&&(c[t.component]=t.parse(i[e]))}if(0===Object.getOwnPropertyNames(c).length)return;let l=0;const p=e=>{l<<=1,l+=e?1:0},f=e=>!(~e&l||!(e&l));"YXMxWwdD".split("").forEach(e=>p(c[e]));const d=!f(e)&&f(t),h=f(n),v=!h&&f(o);l=0,"PHhmsf".split("").forEach(e=>p(c[e]));const g=!f(s)&&f(u),y=(d?"YD":h?"XxwF":v?"XWF":"YMD")+(g?"Phmsf":"Hmsf"),m=this.environment.timestamp;let b=!1,k=!1;if(y.split("").forEach(e=>{if(void 0===c[e])b?(c[e]=-1!=="MDd".indexOf(e)?1:0,k=!0):c[e]=w(m,e);else if(b=!0,k)throw{code:"D3136"}}),c.M>0?c.M-=1:c.M=0,d){const e=Date.UTC(c.Y,0),t=1e3*(c.d-1)*60*60*24,r=new Date(e+t);c.M=r.getUTCMonth(),c.D=r.getUTCDate()}if(h)throw{code:"D3136"};if(v)throw{code:"D3136"};g&&(c.H=12===c.h?0:c.h,1===c.P&&(c.H+=12));var a=Date.UTC(c.Y,c.M,c.D,c.H,c.m,c.s,c.f);return(c.Z||c.z)&&(a-=60*(c.Z||c.z)*1e3),a}}.call(this,e,t)}}}}();t.exports=i},{"./utils":6}],2:[function(e,t,r){(function(r){(function(){var n=e("./utils");const i=(()=>{"use strict";var e=n.isNumeric,t=n.isArrayOfStrings,i=n.isArrayOfNumbers,a=n.createSequence,o=n.isSequence,s=n.isFunction,u=n.isLambda,c=n.isIterable,l=n.getFunctionArity,p=n.isDeepEqual,f=n.stringToArray;function d(e,t,r){if(void 0!==e){var n=f(e),i=n.length;if(i+t<0&&(t=0),void 0!==r){if(r<=0)return"";var a=t>=0?t+r:i+t+r;return n.slice(t,a).join("")}return n.slice(t).join("")}}function h(e){if(void 0!==e)return f(e).length}function*v(e,t){var r=e.apply(this,[t]);if(c(r)&&(r=yield*r),r&&"number"!=typeof r.start&&"number"!==r.end&&!Array.isArray(r.groups)&&!s(r.next))throw{code:"T1010",stack:(new Error).stack};return r}function g(e,t){var r;if(void 0!==e){if(t){var n=e.toString().split("e");e=+(n[0]+"e"+(n[1]?+n[1]+t:t))}var i=(r=Math.round(e))-e;return.5===Math.abs(i)&&1===Math.abs(r%2)&&(r-=1),t&&(r=+((n=r.toString().split("e"))[0]+"e"+(n[1]?+n[1]-t:-t))),Object.is(r,-0)&&(r=0),r}}function y(t){if(void 0!==t){var r=!1;if(Array.isArray(t)){if(1===t.length)r=y(t[0]);else if(t.length>1){r=t.filter(function(e){return y(e)}).length>0}}else"string"==typeof t?t.length>0&&(r=!0):e(t)?0!==t&&(r=!0):null!==t&&"object"==typeof t?Object.keys(t).length>0&&(r=!0):"boolean"==typeof t&&!0===t&&(r=!0);return r}}function m(e,t,r,n){var i=[t],a=l(e);return a>=2&&i.push(r),a>=3&&i.push(n),i}function b(e,t){return void 0===e?t:void 0===t?e:(Array.isArray(e)||(e=a(e)),Array.isArray(t)||(t=[t]),e.concat(t))}return{sum:function(e){if(void 0!==e){var t=0;return e.forEach(function(e){t+=e}),t}},count:function(e){return void 0===e?0:e.length},max:function(e){if(void 0!==e&&0!==e.length)return Math.max.apply(Math,e)},min:function(e){if(void 0!==e&&0!==e.length)return Math.min.apply(Math,e)},average:function(e){if(void 0!==e&&0!==e.length){var t=0;return e.forEach(function(e){t+=e}),t/e.length}},string:function(t,r=!1){if(void 0!==t){var n;if("string"==typeof t)n=t;else if(s(t))n="";else{if("number"==typeof t&&!isFinite(t))throw{code:"D3001",value:t,stack:(new Error).stack};var i=r?2:0;Array.isArray(t)&&t.outerWrapper&&(t=t[0]),n=JSON.stringify(t,function(t,r){return null!=r&&r.toPrecision&&e(r)?Number(r.toPrecision(15)):r&&s(r)?"":r},i)}return n}},substring:d,substringBefore:function(e,t){if(void 0!==e){var r=e.indexOf(t);return r>-1?e.substr(0,r):e}},substringAfter:function(e,t){if(void 0!==e){var r=e.indexOf(t);return r>-1?e.substr(r+t.length):e}},lowercase:function(e){if(void 0!==e)return e.toLowerCase()},uppercase:function(e){if(void 0!==e)return e.toUpperCase()},length:h,trim:function(e){if(void 0!==e){var t=e.replace(/[ \t\n\r]+/gm," ");return" "===t.charAt(0)&&(t=t.substring(1))," "===t.charAt(t.length-1)&&(t=t.substring(0,t.length-1)),t}},pad:function(e,t,r){if(void 0!==e){var n;void 0!==r&&0!==r.length||(r=" ");var i=Math.abs(t)-h(e);if(i>0){var a=new Array(i+1).join(r);r.length>1&&(a=d(a,0,i)),n=t>0?e+a:a+e}else n=e;return n}},match:function*(e,t,r){if(void 0!==e){if(r<0)throw{stack:(new Error).stack,value:r,code:"D3040",index:3};var n=a();if(void 0===r||r>0){var i=0,o=yield*v(t,e);if(void 0!==o)for(;void 0!==o&&(void 0===r||i<r);)n.push({match:o.match,index:o.start,groups:o.groups}),o=yield*v(o.next),i++}return n}},contains:function*(e,t){if(void 0!==e){return"string"==typeof t?-1!==e.indexOf(t):void 0!==(yield*v(t,e))}},replace:function*(e,t,r,n){if(void 0!==e){var i;if(""===t)throw{code:"D3010",stack:(new Error).stack,value:t,index:2};if(n<0)throw{code:"D3011",stack:(new Error).stack,value:n,index:4};i="string"==typeof r?function(e){for(var t="",n=0,i=r.indexOf("$",n);-1!==i&&n<r.length;){t+=r.substring(n,i),n=i+1;var a=r.charAt(n);if("$"===a)t+="$",n++;else if("0"===a)t+=e.match,n++;else{var o;if(o=0===e.groups.length?1:Math.floor(Math.log(e.groups.length)*Math.LOG10E)+1,i=parseInt(r.substring(n,n+o),10),o>1&&i>e.groups.length&&(i=parseInt(r.substring(n,n+o-1),10)),isNaN(i))t+="$";else{if(e.groups.length>0){var s=e.groups[i-1];void 0!==s&&(t+=s)}n+=i.toString().length}}i=r.indexOf("$",n)}return t+=r.substring(n)}:r;var a="",o=0;if(void 0===n||n>0){var s=0;if("string"==typeof t){for(var u=e.indexOf(t,o);-1!==u&&(void 0===n||s<n);)a+=e.substring(o,u),a+=r,o=u+t.length,s++,u=e.indexOf(t,o);a+=e.substring(o)}else{var l=yield*v(t,e);if(void 0!==l){for(;void 0!==l&&(void 0===n||s<n);){a+=e.substring(o,l.start);var p=i.apply(this,[l]);if(c(p)&&(p=yield*p),"string"!=typeof p)throw{code:"D3012",stack:(new Error).stack,value:p};a+=p,o=l.start+l.match.length,s++,l=yield*v(l.next)}a+=e.substring(o)}else a=e}}else a=e;return a}},split:function*(e,t,r){if(void 0!==e){if(r<0)throw{code:"D3020",stack:(new Error).stack,value:r,index:3};var n=[];if(void 0===r||r>0)if("string"==typeof t)n=e.split(t,r);else{var i=0,a=yield*v(t,e);if(void 0!==a){for(var o=0;void 0!==a&&(void 0===r||i<r);)n.push(e.substring(o,a.start)),o=a.end,a=yield*v(a.next),i++;(void 0===r||i<r)&&n.push(e.substring(o))}else n.push(e)}return n}},join:function(e,t){if(void 0!==e)return void 0===t&&(t=""),e.join(t)},formatNumber:function(e,t,r){if(void 0!==e){var n={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"‰","zero-digit":"0",digit:"#","pattern-separator":";"};void 0!==r&&Object.keys(r).forEach(function(e){n[e]=r[e]});for(var i=[],a=n["zero-digit"].charCodeAt(0),o=a;o<a+10;o++)i.push(String.fromCharCode(o));var s=i.concat([n["decimal-separator"],n["exponent-separator"],n["grouping-separator"],n.digit,n["pattern-separator"]]),u=t.split(n["pattern-separator"]);if(u.length>2)throw{code:"D3080",stack:(new Error).stack};var c=u.map(function(e){var t,r,i,a,o=function(){for(var t,r=0;r<e.length;r++)if(t=e.charAt(r),-1!==s.indexOf(t)&&t!==n["exponent-separator"])return e.substring(0,r)}(),u=function(){for(var t,r=e.length-1;r>=0;r--)if(t=e.charAt(r),-1!==s.indexOf(t)&&t!==n["exponent-separator"])return e.substring(r+1)}(),c=e.substring(o.length,e.length-u.length),l=e.indexOf(n["exponent-separator"],o.length);-1===l||l>e.length-u.length?(t=c,r=void 0):(t=c.substring(0,l),r=c.substring(l+1));var p=t.indexOf(n["decimal-separator"]);return-1===p?(i=t,a=u):(i=t.substring(0,p),a=t.substring(p+1)),{prefix:o,suffix:u,activePart:c,mantissaPart:t,exponentPart:r,integerPart:i,fractionalPart:a,subpicture:e}});c.forEach(function(e){var t,r,a=e.subpicture,o=a.indexOf(n["decimal-separator"]);o!==a.lastIndexOf(n["decimal-separator"])&&(t="D3081"),a.indexOf(n.percent)!==a.lastIndexOf(n.percent)&&(t="D3082"),a.indexOf(n["per-mille"])!==a.lastIndexOf(n["per-mille"])&&(t="D3083"),-1!==a.indexOf(n.percent)&&-1!==a.indexOf(n["per-mille"])&&(t="D3084");var u=!1;for(r=0;r<e.mantissaPart.length;r++){var c=e.mantissaPart.charAt(r);if(-1!==i.indexOf(c)||c===n.digit){u=!0;break}}u||(t="D3085"),-1!==e.activePart.split("").map(function(e){return-1===s.indexOf(e)?"p":"a"}).join("").indexOf("p")&&(t="D3086"),-1!==o?a.charAt(o-1)!==n["grouping-separator"]&&a.charAt(o+1)!==n["grouping-separator"]||(t="D3087"):e.integerPart.charAt(e.integerPart.length-1)===n["grouping-separator"]&&(t="D3088"),-1!==a.indexOf(n["grouping-separator"]+n["grouping-separator"])&&(t="D3089");var l=e.integerPart.indexOf(n.digit);-1!==l&&e.integerPart.substring(0,l).split("").filter(function(e){return i.indexOf(e)>-1}).length>0&&(t="D3090"),-1!==(l=e.fractionalPart.lastIndexOf(n.digit))&&e.fractionalPart.substring(l).split("").filter(function(e){return i.indexOf(e)>-1}).length>0&&(t="D3091");var p="string"==typeof e.exponentPart;if(p&&e.exponentPart.length>0&&(-1!==a.indexOf(n.percent)||-1!==a.indexOf(n["per-mille"]))&&(t="D3092"),p&&(0===e.exponentPart.length||e.exponentPart.split("").filter(function(e){return-1===i.indexOf(e)}).length>0)&&(t="D3093"),t)throw{code:t,stack:(new Error).stack}});var l,p,f,d,h=c.map(function(e){var t=function(t,r){for(var a=[],o=t.indexOf(n["grouping-separator"]);-1!==o;){var s=(r?t.substring(0,o):t.substring(o)).split("").filter(function(e){return-1!==i.indexOf(e)||e===n.digit}).length;a.push(s),o=e.integerPart.indexOf(n["grouping-separator"],o+1)}return a},r=t(e.integerPart),a=function(e){if(0===e.length)return 0;for(var t=function(e,r){return 0===r?e:t(r,e%r)},r=e.reduce(t),n=1;n<=e.length;n++)if(-1===e.indexOf(n*r))return 0;return r}(r),o=t(e.fractionalPart,!0),s=e.integerPart.split("").filter(function(e){return-1!==i.indexOf(e)}).length,u=s,c=e.fractionalPart.split(""),l=c.filter(function(e){return-1!==i.indexOf(e)}).length,p=c.filter(function(e){return-1!==i.indexOf(e)||e===n.digit}).length,f="string"==typeof e.exponentPart;0===s&&0===p&&(f?(l=1,p=1):s=1),f&&0===s&&-1!==e.integerPart.indexOf(n.digit)&&(s=1),0===s&&0===l&&(l=1);var d=0;return f&&(d=e.exponentPart.split("").filter(function(e){return-1!==i.indexOf(e)}).length),{integerPartGroupingPositions:r,regularGrouping:a,minimumIntegerPartSize:s,scalingFactor:u,prefix:e.prefix,fractionalPartGroupingPositions:o,minimumFactionalPartSize:l,maximumFactionalPartSize:p,minimumExponentSize:d,suffix:e.suffix,picture:e.subpicture}}),v=n["minus-sign"],y=n["zero-digit"],m=n["decimal-separator"],b=n["grouping-separator"];if(1===h.length&&(h.push(JSON.parse(JSON.stringify(h[0]))),h[1].prefix=v+h[1].prefix),p=-1!==(l=e>=0?h[0]:h[1]).picture.indexOf(n.percent)?100*e:-1!==l.picture.indexOf(n["per-mille"])?1e3*e:e,0===l.minimumExponentSize)f=p;else{var k=Math.pow(10,l.scalingFactor),x=Math.pow(10,l.scalingFactor-1);for(f=p,d=0;f<x;)f*=10,d-=1;for(;f>k;)f/=10,d+=1}var w=function(e,t){var r=Math.abs(e).toFixed(t);return"0"!==y&&(r=r.split("").map(function(e){return e>="0"&&e<="9"?i[e.charCodeAt(0)-48]:e}).join("")),r},A=w(g(f,l.maximumFactionalPartSize),l.maximumFactionalPartSize),E=A.indexOf(".");for(-1===E?A+=m:A=A.replace(".",m);A.charAt(0)===y;)A=A.substring(1);for(;A.charAt(A.length-1)===y;)A=A.substring(0,A.length-1);E=A.indexOf(m);var T=l.minimumIntegerPartSize-E,D=l.minimumFactionalPartSize-(A.length-E-1);if(A=(T>0?new Array(T+1).join(y):"")+A,A+=D>0?new Array(D+1).join(y):"",E=A.indexOf(m),l.regularGrouping>0)for(var S=Math.floor((E-1)/l.regularGrouping),O=1;O<=S;O++)A=[A.slice(0,E-O*l.regularGrouping),b,A.slice(E-O*l.regularGrouping)].join("");else l.integerPartGroupingPositions.forEach(function(e){A=[A.slice(0,E-e),b,A.slice(E-e)].join(""),E++});if(E=A.indexOf(m),l.fractionalPartGroupingPositions.forEach(function(e){A=[A.slice(0,e+E+1),b,A.slice(e+E+1)].join("")}),E=A.indexOf(m),-1!==l.picture.indexOf(m)&&E!==A.length-1||(A=A.substring(0,A.length-1)),void 0!==d){var P=w(d,0);(T=l.minimumExponentSize-P.length)>0&&(P=new Array(T+1).join(y)+P),A=A+n["exponent-separator"]+(d<0?v:"")+P}return A=l.prefix+A+l.suffix}},formatBase:function(e,t){if(void 0!==e){if(e=g(e),(t=void 0===t?10:g(t))<2||t>36)throw{code:"D3100",stack:(new Error).stack,value:t};return e.toString(t)}},number:function(e){var t;if(void 0!==e){if("number"==typeof e)t=e;else if("string"==typeof e&&/^-?[0-9]+(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(e)&&!isNaN(parseFloat(e))&&isFinite(e))t=parseFloat(e);else if(!0===e)t=1;else{if(!1!==e)throw{code:"D3030",value:e,stack:(new Error).stack,index:1};t=0}return t}},floor:function(e){if(void 0!==e)return Math.floor(e)},ceil:function(e){if(void 0!==e)return Math.ceil(e)},round:g,abs:function(e){if(void 0!==e)return Math.abs(e)},sqrt:function(e){if(void 0!==e){if(e<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:e};return Math.sqrt(e)}},power:function(e,t){var r;if(void 0!==e){if(r=Math.pow(e,t),!isFinite(r))throw{stack:(new Error).stack,code:"D3061",index:1,value:e,exp:t};return r}},random:function(){return Math.random()},boolean:y,not:function(e){if(void 0!==e)return!y(e)},map:function*(e,t){if(void 0!==e){for(var r=a(),n=0;n<e.length;n++){var i=m(t,e[n],n,e),o=yield*t.apply(this,i);void 0!==o&&r.push(o)}return r}},zip:function(){for(var e=[],t=Array.prototype.slice.call(arguments),r=Math.min.apply(Math,t.map(function(e){return Array.isArray(e)?e.length:0})),n=0;n<r;n++){var i=t.map(e=>e[n]);e.push(i)}return e},filter:function*(e,t){if(void 0!==e){for(var r=a(),n=0;n<e.length;n++){var i=e[n],o=m(t,i,n,e);y(yield*t.apply(this,o))&&r.push(i)}return r}},single:function*(e,t){if(void 0!==e){for(var r,n=!1,i=0;i<e.length;i++){var a=e[i],o=!0;if(void 0!==t){var s=m(t,a,i,e);o=y(yield*t.apply(this,s))}if(o){if(n)throw{stack:(new Error).stack,code:"D3138",index:i};r=a,n=!0}}if(!n)throw{stack:(new Error).stack,code:"D3139"};return r}},foldLeft:function*(e,t,r){if(void 0!==e){var n,i,a=l(t);if(a<2)throw{stack:(new Error).stack,code:"D3050",index:1};for(void 0===r&&e.length>0?(n=e[0],i=1):(n=r,i=0);i<e.length;){var o=[n,e[i]];a>=3&&o.push(i),a>=4&&o.push(e),n=yield*t.apply(this,o),i++}return n}},sift:function*(e,t){var r={};for(var n in e){var i=e[n],a=m(t,i,n,e);y(yield*t.apply(this,a))&&(r[n]=i)}return 0===Object.keys(r).length&&(r=void 0),r},keys:function e(t){var r=a();if(Array.isArray(t)){var n={};t.forEach(function(t){e(t).forEach(function(e){n[e]=!0})}),r=e(n)}else null===t||"object"!=typeof t||u(t)||Object.keys(t).forEach(e=>r.push(e));return r},lookup:function e(t,r){var n;if(Array.isArray(t)){n=a();for(var i=0;i<t.length;i++){var o=e(t[i],r);void 0!==o&&(Array.isArray(o)?o.forEach(e=>n.push(e)):n.push(o))}}else null!==t&&"object"==typeof t&&(n=t[r]);return n},append:b,exists:function(e){return void 0!==e},spread:function e(t){var r=a();if(Array.isArray(t))t.forEach(function(t){r=b(r,e(t))});else if(null===t||"object"!=typeof t||u(t))r=t;else for(var n in t){var i={};i[n]=t[n],r.push(i)}return r},merge:function(e){if(void 0!==e){var t={};return e.forEach(function(e){for(var r in e)t[r]=e[r]}),t}},reverse:function(e){if(void 0!==e){if(e.length<=1)return e;for(var t=e.length,r=new Array(t),n=0;n<t;n++)r[t-n-1]=e[n];return r}},each:function*(e,t){var r=a();for(var n in e){var i=m(t,e[n],n,e),o=yield*t.apply(this,i);void 0!==o&&r.push(o)}return r},error:function(e){throw{code:"D3137",stack:(new Error).stack,message:e||"$error() function evaluated"}},assert:function(e,t){if(!e)throw{code:"D3141",stack:(new Error).stack,message:t||"$assert() statement failed"}},type:function(t){if(void 0!==t)return null===t?"null":e(t)?"number":"string"==typeof t?"string":"boolean"==typeof t?"boolean":Array.isArray(t)?"array":s(t)?"function":"object"},sort:function*(e,r){if(void 0!==e){if(e.length<=1)return e;var n;if(void 0===r){if(!i(e)&&!t(e))throw{stack:(new Error).stack,code:"D3070",index:1};n=function*(e,t){return e>t}}else n=r;var a=function*(e){if(!Array.isArray(e)||e.length<=1)return e;var t=Math.floor(e.length/2),r=e.slice(0,t),i=e.slice(t);return yield*function*(e,t){var r=function*(e,t,i){0===t.length?Array.prototype.push.apply(e,i):0===i.length?Array.prototype.push.apply(e,t):(yield*n(t[0],i[0]))?(e.push(i[0]),yield*r(e,t,i.slice(1))):(e.push(t[0]),yield*r(e,t.slice(1),i))},i=[];return yield*r(i,e,t),i}(r=yield*a(r),i=yield*a(i))};return yield*a(e)}},shuffle:function(e){if(void 0!==e){if(e.length<=1)return e;for(var t=new Array(e.length),r=0;r<e.length;r++){var n=Math.floor(Math.random()*(r+1));r!==n&&(t[r]=t[n]),t[n]=e[r]}return t}},distinct:function(e){if(void 0!==e){if(!Array.isArray(e)||e.length<=1)return e;for(var t=o(e)?a():[],r=0;r<e.length;r++){for(var n=e[r],i=!1,s=0;s<t.length;s++)if(p(n,t[s])){i=!0;break}i||t.push(n)}return t}},base64encode:function(e){if(void 0!==e)return("undefined"!=typeof window?window.btoa:function(e){return new r.Buffer.from(e,"binary").toString("base64")})(e)},base64decode:function(e){if(void 0!==e)return("undefined"!=typeof window?window.atob:function(e){return new r.Buffer(e,"base64").toString("binary")})(e)},encodeUrlComponent:function(e){if(void 0!==e){var t;try{t=encodeURIComponent(e)}catch(t){throw{code:"D3140",stack:(new Error).stack,value:e,functionName:"encodeUrlComponent"}}return t}},encodeUrl:function(e){if(void 0!==e){var t;try{t=encodeURI(e)}catch(t){throw{code:"D3140",stack:(new Error).stack,value:e,functionName:"encodeUrl"}}return t}},decodeUrlComponent:function(e){if(void 0!==e){var t;try{t=decodeURIComponent(e)}catch(t){throw{code:"D3140",stack:(new Error).stack,value:e,functionName:"decodeUrlComponent"}}return t}},decodeUrl:function(e){if(void 0!==e){var t;try{t=decodeURI(e)}catch(t){throw{code:"D3140",stack:(new Error).stack,value:e,functionName:"decodeUrl"}}return t}}}})();t.exports=i}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils":6}],3:[function(e,t,r){var n=e("./datetime"),i=e("./functions"),a=e("./utils"),o=e("./parser"),s=e("./signature"),u=function(){"use strict";var e=a.isNumeric,t=a.isArrayOfStrings,r=a.isArrayOfNumbers,u=a.createSequence,c=a.isSequence,l=a.isFunction,p=a.isLambda,f=a.isIterable,d=a.getFunctionArity,h=a.isDeepEqual,v=U(null);function*g(r,n,a){var o,s=a.lookup("__evaluate_entry");switch(s&&s(r,n,a),r.type){case"path":o=yield*function*(e,t,r){var n,i;n=Array.isArray(t)&&"variable"!==e.steps[0].type?t:u(t);for(var a=!1,o=void 0,s=0;s<e.steps.length;s++){var l=e.steps[s];if(l.tuple&&(a=!0),0===s&&l.consarray?i=yield*g(l,n,r):a?o=yield*k(l,n,o,r):i=yield*m(l,n,r,s===e.steps.length-1),!a&&(void 0===i||0===i.length))break;void 0===l.focus&&(n=i)}if(a)if(e.tuple)i=o;else for(i=u(),s=0;s<o.length;s++)i.push(o[s]["@"]);e.keepSingletonArray&&(c(i)||(i=u(i)),i.keepSingleton=!0);e.hasOwnProperty("group")&&(i=yield*w(e.group,a?o:i,r));return i}(r,n,a);break;case"binary":o=yield*function*(t,r,n){var a,o=yield*g(t.lhs,r,n),s=yield*g(t.rhs,r,n),u=t.value;try{switch(u){case"+":case"-":case"*":case"/":case"%":a=function(t,r,n){var i;if(void 0!==t&&!e(t))throw{code:"T2001",stack:(new Error).stack,value:t};if(void 0!==r&&!e(r))throw{code:"T2002",stack:(new Error).stack,value:r};if(void 0===t||void 0===r)return i;switch(n){case"+":i=t+r;break;case"-":i=t-r;break;case"*":i=t*r;break;case"/":i=t/r;break;case"%":i=t%r}return i}(o,s,u);break;case"=":case"!=":a=function(e,t,r){var n;if(void 0===e||void 0===t)return!1;switch(r){case"=":n=h(e,t);break;case"!=":n=!h(e,t)}return n}(o,s,u);break;case"<":case"<=":case">":case">=":a=function(e,t,r){var n,i=typeof e,a=typeof t;if("undefined"!==i&&"string"!==i&&"number"!==i||"undefined"!==a&&"string"!==a&&"number"!==a)throw{code:"T2010",stack:(new Error).stack,value:"string"!==i&&"number"!==i?e:t};if("undefined"===i||"undefined"===a)return;if(i!==a)throw{code:"T2009",stack:(new Error).stack,value:e,value2:t};switch(r){case"<":n=e<t;break;case"<=":n=e<=t;break;case">":n=e>t;break;case">=":n=e>=t}return n}(o,s,u);break;case"&":a=function(e,t){var r="",n="";void 0!==e&&(r=i.string(e));void 0!==t&&(n=i.string(t));return r.concat(n)}(o,s);break;case"and":case"or":a=function(e,t,r){var n,a=i.boolean(e),o=i.boolean(t);void 0===a&&(a=!1);void 0===o&&(o=!1);switch(r){case"and":n=a&&o;break;case"or":n=a||o}return n}(o,s,u);break;case"..":a=function(e,t){var r;if(void 0!==e&&!Number.isInteger(e))throw{code:"T2003",stack:(new Error).stack,value:e};if(void 0!==t&&!Number.isInteger(t))throw{code:"T2004",stack:(new Error).stack,value:t};if(void 0===e||void 0===t)return r;if(e>t)return r;var n=t-e+1;if(n>1e7)throw{code:"D2014",stack:(new Error).stack,value:n};r=new Array(n);for(var i=e,a=0;i<=t;i++,a++)r[a]=i;return r.sequence=!0,r}(o,s);break;case"in":a=function(e,t){var r=!1;if(void 0===e||void 0===t)return!1;Array.isArray(t)||(t=[t]);for(var n=0;n<t.length;n++)if(t[n]===e){r=!0;break}return r}(o,s)}}catch(e){throw e.position=t.position,e.token=u,e}return a}(r,n,a);break;case"unary":o=yield*function*(t,r,n){var a;switch(t.value){case"-":if(void 0===(a=yield*g(t.expression,r,n)))a=void 0;else{if(!e(a))throw{code:"D1002",stack:(new Error).stack,position:t.position,token:t.value,value:a};a=-a}break;case"[":a=[];for(var o=0;o<t.expressions.length;o++){var s=t.expressions[o],u=yield*g(s,r,n);void 0!==u&&("["===s.value?a.push(u):a=i.append(a,u))}t.consarray&&Object.defineProperty(a,"cons",{enumerable:!1,configurable:!1,value:!0});break;case"{":a=yield*w(t,r,n)}return a}(r,n,a);break;case"name":o=function(e,t,r){return i.lookup(t,e.value)}(r,n);break;case"string":case"number":case"value":o=function(e){return e.value}(r);break;case"wildcard":o=function(e,t){var r=u();null!==t&&"object"==typeof t&&Object.keys(t).forEach(function(e){var n=t[e];Array.isArray(n)?(n=function e(t,r){void 0===r&&(r=[]);Array.isArray(t)?t.forEach(function(t){e(t,r)}):r.push(t);return r}(n),r=i.append(r,n)):r.push(n)});return r}(0,n);break;case"descendant":o=function(e,t){var r,n=u();void 0!==t&&(!function e(t,r){Array.isArray(t)||r.push(t);Array.isArray(t)?t.forEach(function(t){e(t,r)}):null!==t&&"object"==typeof t&&Object.keys(t).forEach(function(n){e(t[n],r)})}(t,n),r=1===n.length?n[0]:n);return r}(0,n);break;case"parent":o=a.lookup(r.slot.label);break;case"condition":o=yield*function*(e,t,r){var n,a=yield*g(e.condition,t,r);i.boolean(a)?n=yield*g(e.then,t,r):void 0!==e.else&&(n=yield*g(e.else,t,r));return n}(r,n,a);break;case"block":o=yield*function*(e,t,r){for(var n,i=U(r),a=0;a<e.expressions.length;a++)n=yield*g(e.expressions[a],t,i);return n}(r,n,a);break;case"bind":o=yield*function*(e,t,r){var n=yield*g(e.rhs,t,r);return r.bind(e.lhs.value,n),n}(r,n,a);break;case"regex":o=function(e){var t=new I.RegexEngine(e.value),r=function(n,i){var a;t.lastIndex=i||0;var o=t.exec(n);if(null!==o){if(a={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var s=1;s<o.length;s++)a.groups.push(o[s]);a.next=function(){if(!(t.lastIndex>=n.length)){var i=r(n,t.lastIndex);if(i&&""===i.match)throw{code:"D1004",stack:(new Error).stack,position:e.position,value:e.value.source};return i}}}return a};return r}(r);break;case"function":o=yield*D(r,n,a);break;case"variable":o=function(e,t,r){var n;n=""===e.value?t&&t.outerWrapper?t[0]:t:r.lookup(e.value);return n}(r,n,a);break;case"lambda":o=function(e,t,r){var n={_jsonata_lambda:!0,input:t,environment:r,arguments:e.arguments,signature:e.signature,body:e.body};!0===e.thunk&&(n.thunk=!0);return n.apply=function*(e,r){return yield*S(n,r,t,e.environment)},n}(r,n,a);break;case"partial":o=yield*function*(e,t,r){for(var n,i=[],a=0;a<e.arguments.length;a++){var o=e.arguments[a];"operator"===o.type&&"?"===o.value?i.push(o):i.push(yield*g(o,t,r))}var s=yield*g(e.procedure,t,r);if(void 0===s&&"path"===e.procedure.type&&r.lookup(e.procedure.steps[0].value))throw{code:"T1007",stack:(new Error).stack,position:e.position,token:e.procedure.steps[0].value};if(p(s))n=P(s,i);else if(s&&!0===s._jsonata_function)n=M(s.implementation,i);else{if("function"!=typeof s)throw{code:"T1008",stack:(new Error).stack,position:e.position,token:"path"===e.procedure.type?e.procedure.steps[0].value:e.procedure.value};n=M(s,i)}return n}(r,n,a);break;case"apply":o=yield*function*(e,t,r){var n,i=yield*g(e.lhs,t,r);if("function"===e.rhs.type)n=yield*D(e.rhs,t,r,{context:i});else{var a=yield*g(e.rhs,t,r);if(!l(a))throw{code:"T2006",stack:(new Error).stack,position:e.position,value:a};if(l(i)){var o=yield*g(T,null,r);n=yield*S(o,[i,a],null,r)}else n=yield*S(a,[i],null,r)}return n}(r,n,a);break;case"transform":o=function(e,r,n){return j(function*(r){if(void 0!==r){var i=n.lookup("clone");if(!l(i))throw{code:"T2013",stack:(new Error).stack,position:e.position};var a=yield*S(i,[r],null,n),o=yield*g(e.pattern,a,n);if(void 0!==o){Array.isArray(o)||(o=[o]);for(var s=0;s<o.length;s++){var u=o[s],c=yield*g(e.update,u,n),p=typeof c;if("undefined"!==p){if("object"!==p||null===c||Array.isArray(c))throw{code:"T2011",stack:(new Error).stack,position:e.update.position,value:c};for(var f in c)u[f]=c[f]}if(void 0!==e.delete){var d=yield*g(e.delete,u,n);if(void 0!==d){var h=d;if(Array.isArray(d)||(d=[d]),!t(d))throw{code:"T2012",stack:(new Error).stack,position:e.delete.position,value:h};for(var v=0;v<d.length;v++)"object"==typeof u&&null!==u&&delete u[d[v]]}}}}return a}},"<(oa):o>")}(r,0,a)}if(!a.async||null!=o&&"function"==typeof o.then||(o=Promise.resolve(o)),a.async&&"function"==typeof o.then&&r.nextFunction&&"function"==typeof o[r.nextFunction]||(o=yield o),Object.prototype.hasOwnProperty.call(r,"predicate"))for(var f=0;f<r.predicate.length;f++)o=yield*x(r.predicate[f].expr,o,a);"path"!==r.type&&Object.prototype.hasOwnProperty.call(r,"group")&&(o=yield*w(r.group,o,a));var d=a.lookup("__evaluate_exit");return d&&d(r,n,a,o),o&&c(o)&&!o.tupleStream&&(r.keepArray&&(o.keepSingleton=!0),0===o.length?o=void 0:1===o.length&&(o=o.keepSingleton?o:o[0])),o}function y(e,t){var r=U(e);for(const e in t)r.bind(e,t[e]);return r}function*m(e,t,r,n){var i;if("sort"===e.type)return i=yield*E(e,t,r),e.stages&&(i=yield*b(e.stages,i,r)),i;i=u();for(var a=0;a<t.length;a++){var o=yield*g(e,t[a],r);if(e.stages)for(var s=0;s<e.stages.length;s++)o=yield*x(e.stages[s].expr,o,r);void 0!==o&&i.push(o)}var l=u();return n&&1===i.length&&Array.isArray(i[0])&&!c(i[0])?l=i[0]:i.forEach(function(e){!Array.isArray(e)||e.cons?l.push(e):e.forEach(e=>l.push(e))}),l}function*b(e,t,r){for(var n=t,i=0;i<e.length;i++){var a=e[i];switch(a.type){case"filter":n=yield*x(a.expr,n,r);break;case"index":for(var o=0;o<n.length;o++){n[o][a.value]=o}}}return n}function*k(e,t,r,n){var i;if("sort"===e.type){if(r)i=yield*E(e,r,n);else{var a=yield*E(e,t,n);(i=u()).tupleStream=!0;for(var o=0;o<a.length;o++){var s={"@":a[o]};s[e.index]=o,i.push(s)}}return e.stages&&(i=yield*b(e.stages,i,n)),i}(i=u()).tupleStream=!0;var c=n;void 0===r&&(r=t.map(e=>({"@":e})));for(var l=0;l<r.length;l++){c=y(n,r[l]);var p=yield*g(e,r[l]["@"],c);if(void 0!==p){Array.isArray(p)||(p=[p]);for(var f=0;f<p.length;f++)s={},Object.assign(s,r[l]),p.tupleStream?Object.assign(s,p[f]):(e.focus?(s[e.focus]=p[f],s["@"]=r[l]["@"]):s["@"]=p[f],e.index&&(s[e.index]=f),e.ancestor&&(s[e.ancestor.label]=r[l]["@"])),i.push(s)}}return e.stages&&(i=yield*b(e.stages,i,n)),i}function*x(t,n,a){var o=u();if(n&&n.tupleStream&&(o.tupleStream=!0),Array.isArray(n)||(n=u(n)),"number"===t.type){var s=Math.floor(t.value);s<0&&(s=n.length+s),void 0!==(c=n[s])&&(Array.isArray(c)?o=c:o.push(c))}else for(s=0;s<n.length;s++){var c,l=c=n[s],p=a;n.tupleStream&&(l=c["@"],p=y(a,c));var f=yield*g(t,l,p);e(f)&&(f=[f]),r(f)?f.forEach(function(e){var t=Math.floor(e);t<0&&(t=n.length+t),t===s&&o.push(c)}):i.boolean(f)&&o.push(c)}return o}function*w(e,t,r){var n={},a={},o=!(!t||!t.tupleStream);Array.isArray(t)||(t=u(t));for(var s=0;s<t.length;s++)for(var c=t[s],l=o?y(r,c):r,p=0;p<e.lhs.length;p++){var f=yield*g(e.lhs[p][0],o?c["@"]:c,l);if("string"!=typeof f)throw{code:"T1003",stack:(new Error).stack,position:e.position,value:f};var d={data:c,exprIndex:p};if(a.hasOwnProperty(f)){if(a[f].exprIndex!==p)throw{code:"D1009",stack:(new Error).stack,position:e.position,value:f};a[f].data=i.append(a[f].data,c)}else a[f]=d}for(f in a){var h=(d=a[f]).data;l=r;if(o){var v=A(d.data);h=v["@"],delete v["@"],l=y(r,v)}var m=yield*g(e.lhs[d.exprIndex][1],h,l);void 0!==m&&(n[f]=m)}return n}function A(e){if(!Array.isArray(e))return e;var t={};Object.assign(t,e[0]);for(var r=1;r<e.length;r++)for(const n in e[r])t[n]=i.append(t[n],e[r][n]);return t}function*E(e,t,r){var n=t,a=!!t.tupleStream,o={environment:r,input:t};return yield*i.sort.apply(o,[n,function*(t,n){for(var i=0,o=0;0===i&&o<e.terms.length;o++){var s=e.terms[o],u=t,c=r;a&&(u=t["@"],c=y(r,t));var l=yield*g(s.expression,u,c);u=n,c=r,a&&(u=n["@"],c=y(r,n));var p=yield*g(s.expression,u,c),f=typeof l,d=typeof p;if("undefined"!==f)if("undefined"!==d){if("string"!==f&&"number"!==f||"string"!==d&&"number"!==d)throw{code:"T2008",stack:(new Error).stack,position:e.position,value:"string"!==f&&"number"!==f?l:p};if(f!==d)throw{code:"T2007",stack:(new Error).stack,position:e.position,value:l,value2:p};l!==p&&(i=l<p?-1:1,!0===s.descending&&(i=-i))}else i=-1;else i="undefined"===d?0:1}return 1===i}])}var T=o("function($f, $g) { function($x){ $g($f($x)) } }");function*D(e,t,r,n){var i,a=yield*g(e.procedure,t,r);if(void 0===a&&"path"===e.procedure.type&&r.lookup(e.procedure.steps[0].value))throw{code:"T1005",stack:(new Error).stack,position:e.position,token:e.procedure.steps[0].value};var o=[];void 0!==n&&o.push(n.context);for(var s=0;s<e.arguments.length;s++){const n=yield*g(e.arguments[s],t,r);if(l(n)){const e=function*(...e){return yield*S(n,e,null,r)};e.arity=d(n),o.push(e)}else o.push(n)}var u="path"===e.procedure.type?e.procedure.steps[0].value:e.procedure.value;try{"object"==typeof a&&(a.token=u,a.position=e.position),i=yield*S(a,o,t,r)}catch(t){throw t.position||(t.position=e.position),t.token||(t.token=u),t}return i}function*S(e,t,r,n){var i;for(i=yield*O(e,t,r,n);p(i)&&!0===i.thunk;){var a=yield*g(i.body.procedure,i.input,i.environment);"variable"===i.body.procedure.type&&(a.token=i.body.procedure.value),a.position=i.body.procedure.position;for(var o=[],s=0;s<i.body.arguments.length;s++)o.push(yield*g(i.body.arguments[s],i.input,i.environment));i=yield*O(a,o,r,n)}return i}function*O(e,t,r,n){var i;try{var a=t;if(e&&(a=function(e,t,r){if(void 0===e)return t;return e.validate(t,r)}(e.signature,t,r)),p(e))i=yield*function*(e,t){var r,n=U(e.environment);e.arguments.forEach(function(e,r){n.bind(e.value,t[r])}),r="function"==typeof e.body?yield*function*(e,t){var r=C(e).map(function(e){return t.lookup(e.trim())}),n={environment:t},i=e.apply(n,r);f(i)&&(i=yield*i);return i}(e.body,n):yield*g(e.body,e.input,n);return r}(e,a);else if(e&&!0===e._jsonata_function){var o={environment:n,input:r};i=e.implementation.apply(o,a),f(i)&&(i=yield*i)}else{if("function"!=typeof e)throw{code:"T1006",stack:(new Error).stack};i=e.apply(r,a),f(i)&&(i=yield*i)}}catch(t){throw e&&(void 0===t.token&&void 0!==e.token&&(t.token=e.token),t.position=e.position),t}return i}function P(e,t){var r=U(e.environment),n=[];return e.arguments.forEach(function(e,i){var a=t[i];a&&"operator"===a.type&&"?"===a.value?n.push(e):r.bind(e.value,a)}),{_jsonata_lambda:!0,input:e.input,environment:r,arguments:n,body:e.body}}function M(e,t){var r=C(e),n="function("+(r=r.map(function(e){return"$"+e.trim()})).join(", ")+"){ _ }",i=o(n);return i.body=e,P(i,t)}function C(e){var t=e.toString();return/\(([^)]*)\)/.exec(t)[1].split(",")}function j(e,t){var r={_jsonata_function:!0,implementation:e};return void 0!==t&&(r.signature=s(t)),r}function U(e){var t={};return{bind:function(e,r){t[e]=r},lookup:function(r){var n;return t.hasOwnProperty(r)?n=t[r]:e&&(n=e.lookup(r)),n},timestamp:e?e.timestamp:null,async:!!e&&e.async,global:e?e.global:{ancestry:[null]}}}v.bind("sum",j(i.sum,"<a<n>:n>")),v.bind("count",j(i.count,"<a:n>")),v.bind("max",j(i.max,"<a<n>:n>")),v.bind("min",j(i.min,"<a<n>:n>")),v.bind("average",j(i.average,"<a<n>:n>")),v.bind("string",j(i.string,"<x-b?:s>")),v.bind("substring",j(i.substring,"<s-nn?:s>")),v.bind("substringBefore",j(i.substringBefore,"<s-s:s>")),v.bind("substringAfter",j(i.substringAfter,"<s-s:s>")),v.bind("lowercase",j(i.lowercase,"<s-:s>")),v.bind("uppercase",j(i.uppercase,"<s-:s>")),v.bind("length",j(i.length,"<s-:n>")),v.bind("trim",j(i.trim,"<s-:s>")),v.bind("pad",j(i.pad,"<s-ns?:s>")),v.bind("match",j(i.match,"<s-f<s:o>n?:a<o>>")),v.bind("contains",j(i.contains,"<s-(sf):b>")),v.bind("replace",j(i.replace,"<s-(sf)(sf)n?:s>")),v.bind("split",j(i.split,"<s-(sf)n?:a<s>>")),v.bind("join",j(i.join,"<a<s>s?:s>")),v.bind("formatNumber",j(i.formatNumber,"<n-so?:s>")),v.bind("formatBase",j(i.formatBase,"<n-n?:s>")),v.bind("formatInteger",j(n.formatInteger,"<n-s:s>")),v.bind("parseInteger",j(n.parseInteger,"<s-s:n>")),v.bind("number",j(i.number,"<(nsb)-:n>")),v.bind("floor",j(i.floor,"<n-:n>")),v.bind("ceil",j(i.ceil,"<n-:n>")),v.bind("round",j(i.round,"<n-n?:n>")),v.bind("abs",j(i.abs,"<n-:n>")),v.bind("sqrt",j(i.sqrt,"<n-:n>")),v.bind("power",j(i.power,"<n-n:n>")),v.bind("random",j(i.random,"<:n>")),v.bind("boolean",j(i.boolean,"<x-:b>")),v.bind("not",j(i.not,"<x-:b>")),v.bind("map",j(i.map,"<af>")),v.bind("zip",j(i.zip,"<a+>")),v.bind("filter",j(i.filter,"<af>")),v.bind("single",j(i.single,"<af?>")),v.bind("reduce",j(i.foldLeft,"<afj?:j>")),v.bind("sift",j(i.sift,"<o-f?:o>")),v.bind("keys",j(i.keys,"<x-:a<s>>")),v.bind("lookup",j(i.lookup,"<x-s:x>")),v.bind("append",j(i.append,"<xx:a>")),v.bind("exists",j(i.exists,"<x:b>")),v.bind("spread",j(i.spread,"<x-:a<o>>")),v.bind("merge",j(i.merge,"<a<o>:o>")),v.bind("reverse",j(i.reverse,"<a:a>")),v.bind("each",j(i.each,"<o-f:a>")),v.bind("error",j(i.error,"<s?:x>")),v.bind("assert",j(i.assert,"<bs?:x>")),v.bind("type",j(i.type,"<x:s>")),v.bind("sort",j(i.sort,"<af?:a>")),v.bind("shuffle",j(i.shuffle,"<a:a>")),v.bind("distinct",j(i.distinct,"<x:x>")),v.bind("base64encode",j(i.base64encode,"<s-:s>")),v.bind("base64decode",j(i.base64decode,"<s-:s>")),v.bind("encodeUrlComponent",j(i.encodeUrlComponent,"<s-:s>")),v.bind("encodeUrl",j(i.encodeUrl,"<s-:s>")),v.bind("decodeUrlComponent",j(i.decodeUrlComponent,"<s-:s>")),v.bind("decodeUrl",j(i.decodeUrl,"<s-:s>")),v.bind("eval",j(function*(e,t){if(void 0!==e){var r=this.input;void 0!==t&&(r=t,Array.isArray(r)&&!c(r)&&((r=u(r)).outerWrapper=!0));try{var n=o(e,!1)}catch(e){throw N(e),{stack:(new Error).stack,code:"D3120",value:e.message,error:e}}try{var i=yield*g(n,r,this.environment)}catch(e){throw N(e),{stack:(new Error).stack,code:"D3121",value:e.message,error:e}}return i}},"<sx?:x>")),v.bind("toMillis",j(n.toMillis,"<s-s?:n>")),v.bind("fromMillis",j(n.fromMillis,"<n-s?s?:s>")),v.bind("clone",j(function(e){if(void 0!==e)return JSON.parse(i.string(e))},"<(oa)-:o>"));var F={S0101:"String literal must be terminated by a matching quote",S0102:"Number out of range: {{token}}",S0103:"Unsupported escape sequence: \\{{token}}",S0104:"The escape sequence \\u must be followed by 4 hex digits",S0105:"Quoted property name must be terminated with a backquote (`)",S0106:"Comment has no closing tag",S0201:"Syntax error: {{token}}",S0202:"Expected {{value}}, got {{token}}",S0203:"Expected {{value}} before end of expression",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Unexpected end of expression",S0208:"Parameter {{value}} of function definition must be a variable name (start with $)",S0209:"A predicate cannot follow a grouping expression in a step",S0210:"Each step can only have one grouping expression",S0211:"The symbol {{token}} cannot be used as a unary operator",S0212:"The left side of := must be a variable name (start with $)",S0213:"The literal value {{value}} cannot be used as a step within a path expression",S0214:"The right side of {{token}} must be a variable name (start with $)",S0215:"A context variable binding must precede any predicates on a step",S0216:"A context variable binding must precede the 'order-by' clause on a step",S0217:"The object representing the 'parent' cannot be derived from this expression",S0301:"Empty regular expressions are not allowed",S0302:"No terminating / in regular expression",S0402:"Choice groups containing parameterized types are not supported",S0401:"Type parameters can only be applied to functions and arrays",S0500:"Attempted to evaluate an expression containing syntax error(s)",T0410:"Argument {{index}} of function {{token}} does not match function signature",T0411:"Context value is not a compatible type with argument {{index}} of function {{token}}",T0412:"Argument {{index}} of function {{token}} must be an array of {{type}}",D1001:"Number out of range: {{value}}",D1002:"Cannot negate a non-numeric value: {{value}}",T1003:"Key in object structure must evaluate to a string; got: {{value}}",D1004:"Regular expression matches zero length string",T1005:"Attempted to invoke a non-function. Did you mean ${{{token}}}?",T1006:"Attempted to invoke a non-function",T1007:"Attempted to partially apply a non-function. Did you mean ${{{token}}}?",T1008:"Attempted to partially apply a non-function",D1009:"Multiple key definitions evaluate to sam