Socket
Socket
Sign inDemoInstall

jsonata

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonata - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

26

CHANGELOG.md

@@ -0,1 +1,27 @@

#### 1.2.0 Milestone Release
- New syntax to specify order of query results
- Support for asynchronous extension functions - callbacks and promises
- New functions
- $floor - numeric rounding down
- $ceil - numeric rounding up
- $round - numeric round half to even
- $abs - numeric absolute value
- $power - numeric power function
- $sqrt - square root
- $random - generate random number
- $now - current timestamp
- $filter - filter array with predicate function
- $sort - sort array with comparator function
- $reverse - reverse contents of array
- $shuffle - shuffle contents of array into random order
- $zip - convolves (zips) multiple arrays into an array of tuples (nested arrays)
- $each - generate array from object by applying function to key/value pairs
- $sift - sift contents of object with predicate function
- The following (previously undocumented) functions have been modified to align them with other functions
- $map - apply a function to all values in an array
- $reduce - apply a function to aggregate (fold) all values in an array
#### 1.1.1 Maintenance Release

@@ -2,0 +28,0 @@

2

jsonata.min.js

@@ -1,1 +0,1 @@

var jsonata=function(){"use strict";function e(e){for(var n=1,t=[],r={},a=r;n<e.length;){var o=e.charAt(n);if(":"===o)break;var i=function(){t.push(r),a=r,r={}},s=function(e,n,t,r){for(var a=1,i=n;i<e.length;)if(i++,o=e.charAt(i),o===r){if(a--,0===a)break}else o===t&&a++;return i};switch(o){case"s":case"n":case"b":case"l":case"o":r.regex="["+o+"m]",r.type=o,i();break;case"a":r.regex="[asnblfom]",r.type=o,r.array=!0,i();break;case"f":r.regex="f",r.type=o,i();break;case"j":r.regex="[asnblom]",r.type=o,i();break;case"x":r.regex="[asnblfom]",r.type=o,i();break;case"-":a.context=!0,a.contextRegex=new RegExp(a.regex),a.regex+="?";break;case"?":case"+":a.regex+=o;break;case"(":var u=s(e,n,"(",")"),f=e.substring(n+1,u);if(f.indexOf("<")!==-1)throw{code:"S0402",stack:(new Error).stack,value:f,offset:n};r.regex="["+f+"m]",r.type="("+f+")",n=u,i();break;case"<":if("a"!==a.type&&"f"!==a.type)throw{code:"S0401",stack:(new Error).stack,value:a.type,offset:n};var c=s(e,n,"<",">");a.subtype=e.substring(n+1,c),n=c}n++}var p="^"+t.map(function(e){return"("+e.regex+")"}).join("")+"$",l=new RegExp(p),d=function(e){var n;if(T(e))n="f";else{var t=typeof e;switch(t){case"string":n="s";break;case"number":n="n";break;case"boolean":n="b";break;case"object":n=null===e?"l":Array.isArray(e)?"a":"o";break;case"undefined":n="m"}}return n},h=function(e,n){for(var r="^",a=0,o=0;o<t.length;o++){r+=t[o].regex;var i=n.match(r);if(null===i)throw{code:"T0410",stack:(new Error).stack,value:e[a],index:a+1};a=i[0].length}throw{code:"T0410",stack:(new Error).stack,value:e[a],index:a+1}};return{definition:e,validate:function(e,n){var r="";e.forEach(function(e){r+=d(e)});var a=l.exec(r);if(a){var o=[],i=0;return t.forEach(function(t,r){var s=e[i],u=a[r+1];if(""===u)if(t.context){var f=d(n);if(!t.contextRegex.test(f))throw{code:"T0411",stack:(new Error).stack,value:n,index:i+1};o.push(n)}else o.push(s),i++;else u.split("").forEach(function(n){if("a"===t.type){if("m"===n)s=void 0;else{s=e[i];var r=!0;if("undefined"!=typeof t.subtype)if("a"!==n&&u!==t.subtype)r=!1;else if("a"===n&&s.length>0){var a=d(s[0]);if(a!==t.subtype.charAt(0))r=!1;else{var f=s.filter(function(e){return d(e)!==a});r=0===f.length}}if(!r)throw{code:"T0412",stack:(new Error).stack,value:s,index:i+1,type:t.subtype};"a"!==n&&(s=[s])}o.push(s),i++}else o.push(s),i++})}),o}h(e,r)}}}function n(e){var n=!1;if("number"==typeof e){var t=parseFloat(e);if(n=!isNaN(t),n&&!isFinite(t))throw{code:"D1001",value:e,stack:(new Error).stack}}return n}function t(e){var t=!1;return Array.isArray(e)&&(t=0===e.filter(function(e){return!n(e)}).length),t}function r(e,n,t){var r,p=t.lookup("__evaluate_entry");switch(p&&p(e,n,t),e.type){case"path":r=a(e,n,t);break;case"binary":r=i(e,n,t);break;case"unary":r=s(e,n,t);break;case"name":r=u(e,n,t);break;case"literal":r=f(e,n,t);break;case"wildcard":r=c(e,n,t);break;case"descendant":r=l(e,n,t);break;case"condition":r=x(e,n,t);break;case"block":r=E(e,n,t);break;case"regex":r=A(e,n,t);break;case"function":r=O(e,n,t);break;case"variable":r=S(e,n,t);break;case"lambda":r=$(e,n,t);break;case"partial":r=I(e,n,t)}e.hasOwnProperty("predicate")&&(r=o(e.predicate,r,t)),e.hasOwnProperty("group")&&(r=k(e.group,r,t));var d=t.lookup("__evaluate_exit");return d&&d(e,n,t,r),r}function a(e,n,t){var a,o,i=!1;"variable"===e[0].type?e[0].absolute=!0:"unary"===e[0].type&&"["===e[0].value&&(n=[null]);for(var s=0;s<e.length;s++){var u=e[s];u.keepArray===!0&&(i=!0);var f=[];if(a=void 0,o=u.absolute===!0?[n]:Array.isArray(n)?n:[n],e.length>1&&"literal"===u.type&&(u.type="name"),o.forEach(function(e){var n=r(u,e,t);"undefined"!=typeof n&&(Array.isArray(n)&&"["!==u.value?n.forEach(function(e){"undefined"!=typeof e&&f.push(e)}):f.push(n))}),1===f.length?a=i?f:f[0]:f.length>1&&(a=f),"undefined"==typeof a)break;n=a}return a}function o(e,a,o){var i,s=a,u=[];return e.forEach(function(e){if(Array.isArray(s)||(s=[s]),u=[],i=void 0,"literal"===e.type&&n(e.value)){var a=e.value;Number.isInteger(a)||(a=Math.floor(a)),a<0&&(a=s.length+a),i=s[a]}else s.forEach(function(a,i){var f=r(e,a,o);n(f)&&(f=[f]),t(f)?f.forEach(function(e){Number.isInteger(e)||(e=Math.floor(e)),e<0&&(e=s.length+e),e===i&&u.push(a)}):ie(f)&&u.push(a)});1===u.length?i=u[0]:u.length>1&&(i=u),s=i}),i}function i(e,n,t){var r;switch(e.value){case"+":case"-":case"*":case"/":case"%":r=h(e,n,t);break;case"=":case"!=":case"<":case"<=":case">":case">=":r=v(e,n,t);break;case"&":r=g(e,n,t);break;case"and":case"or":r=b(e,n,t);break;case"..":r=m(e,n,t);break;case":=":r=w(e,n,t);break;case"in":r=y(e,n,t);break;case"~>":r=j(e,n,t)}return r}function s(e,t,a){var o;switch(e.value){case"-":if(o=r(e.expression,t,a),!n(o))throw{code:"D1002",stack:(new Error).stack,position:e.position,token:e.value,value:o};o=-o;break;case"[":o=[],e.lhs.forEach(function(e){var n=r(e,t,a);"undefined"!=typeof n&&("["===e.value?o.push(n):o=le(o,n))});break;case"{":o=k(e,t,a)}return o}function u(e,n,t){var r;if(Array.isArray(n)){var a=[];n.forEach(function(n){var r=u(e,n,t);"undefined"!=typeof r&&a.push(r)}),1===a.length?r=a[0]:a.length>1&&(r=a)}else null!==n&&"object"==typeof n&&(r=n[e.value]);return r}function f(e){return e.value}function c(e,n){var t,r=[];return null!==n&&"object"==typeof n&&Object.keys(n).forEach(function(e){var t=n[e];Array.isArray(t)?(t=p(t),r=le(r,t)):r.push(t)}),1===r.length?t=r[0]:r.length>1&&(t=r),t}function p(e,n){return"undefined"==typeof n&&(n=[]),Array.isArray(e)?e.forEach(function(e){p(e,n)}):n.push(e),n}function l(e,n){var t,r=[];return"undefined"!=typeof n&&(d(n,r),t=1===r.length?r[0]:r),t}function d(e,n){Array.isArray(e)||n.push(e),Array.isArray(e)?e.forEach(function(e){d(e,n)}):null!==e&&"object"==typeof e&&Object.keys(e).forEach(function(t){d(e[t],n)})}function h(e,t,a){var o,i=r(e.lhs,t,a),s=r(e.rhs,t,a);if("undefined"==typeof i||"undefined"==typeof s)return o;if(!n(i))throw{code:"T2001",stack:(new Error).stack,position:e.position,token:e.value,value:i};if(!n(s))throw{code:"T2002",stack:(new Error).stack,position:e.position,token:e.value,value:s};switch(e.value){case"+":o=i+s;break;case"-":o=i-s;break;case"*":o=i*s;break;case"/":o=i/s;break;case"%":o=i%s}return o}function v(e,n,t){var a,o=r(e.lhs,n,t),i=r(e.rhs,n,t);if("undefined"==typeof o||"undefined"==typeof i)return!1;switch(e.value){case"=":a=o===i;break;case"!=":a=o!==i;break;case"<":a=o<i;break;case"<=":a=o<=i;break;case">":a=o>i;break;case">=":a=o>=i}return a}function y(e,n,t){var a=!1,o=r(e.lhs,n,t),i=r(e.rhs,n,t);if("undefined"==typeof o||"undefined"==typeof i)return!1;Array.isArray(i)||(i=[i]);for(var s=0;s<i.length;s++)if(i[s]===o){a=!0;break}return a}function b(e,n,t){var a;switch(e.value){case"and":a=ie(r(e.lhs,n,t))&&ie(r(e.rhs,n,t));break;case"or":a=ie(r(e.lhs,n,t))||ie(r(e.rhs,n,t))}return a}function g(e,n,t){var a,o=r(e.lhs,n,t),i=r(e.rhs,n,t),s="",u="";return"undefined"!=typeof o&&(s=J(o)),"undefined"!=typeof i&&(u=J(i)),a=s.concat(u)}function k(e,n,t){var a={},o={};Array.isArray(n)||(n=[n]),n.forEach(function(n){e.lhs.forEach(function(a){var i=r(a[0],n,t);if("string"!=typeof i)throw{code:"T1003",stack:(new Error).stack,position:e.position,value:i};var s={data:n,expr:a[1]};o.hasOwnProperty(i)?o[i].data=le(o[i].data,n):o[i]=s})});for(var i in o){var s=o[i],u=r(s.expr,s.data,t);a[i]=u}return a}function m(e,n,t){var a,o=r(e.lhs,n,t),i=r(e.rhs,n,t);if("undefined"==typeof o||"undefined"==typeof i)return a;if(o>i)return a;if(!Number.isInteger(o))throw{code:"T2003",stack:(new Error).stack,position:e.position,token:e.value,value:o};if(!Number.isInteger(i))throw{code:"T2004",stack:(new Error).stack,position:e.position,token:e.value,value:i};a=new Array(i-o+1);for(var s=o,u=0;s<=i;s++,u++)a[u]=s;return a}function w(e,n,t){var a=r(e.rhs,n,t);if("variable"!==e.lhs.type)throw{code:"D2005",stack:(new Error).stack,position:e.position,token:e.value,value:"path"===e.lhs.type?e.lhs[0].value:e.lhs.value};return t.bind(e.lhs.value,a),a}function x(e,n,t){var a,o=r(e.condition,n,t);return ie(o)?a=r(e.then,n,t):"undefined"!=typeof e.else&&(a=r(e.else,n,t)),a}function E(e,n,t){var a,o=ve(t);return e.expressions.forEach(function(e){a=r(e,n,o)}),a}function A(e){e.value.lastIndex=0;var n=function(t){var r,a=e.value,o=a.exec(t);if(null!==o){if(r={match:o[0],start:o.index,end:o.index+o[0].length,groups:[]},o.length>1)for(var i=1;i<o.length;i++)r.groups.push(o[i]);r.next=function(){if(!(a.lastIndex>=t.length)){var r=n(t);if(r&&""===r.match&&a.lastIndex===e.value.lastIndex)throw{code:"D1004",stack:(new Error).stack,position:e.position,value:e.value.source};return r}}}return r};return n}function S(e,n,t){var r;return r=""===e.value?n:t.lookup(e.value)}function j(e,n,t){var a,o=r(e.lhs,n,t);if("function"===e.rhs.type)a=O(e.rhs,n,t,{context:o});else{var i=r(e.rhs,n,t);if(!T(i))throw{code:"T2006",stack:(new Error).stack,position:e.position,value:i};a=T(o)?D(Ee,[o,i],t,null):D(i,[o],t,null)}return a}function T(e){return e&&(e._jsonata_function===!0||e._jsonata_lambda===!0)||"function"==typeof e}function _(e){return e&&e._jsonata_lambda===!0}function O(e,n,t,a){var o,i=[];e.arguments.forEach(function(e){i.push(r(e,n,t))}),a&&i.unshift(a.context);var s=r(e.procedure,n,t);if("undefined"==typeof s&&"path"===e.procedure.type&&t.lookup(e.procedure[0].value))throw{code:"T1005",stack:(new Error).stack,position:e.position,token:e.procedure[0].value};try{var u=i;s&&(u=F(s.signature,i,n)),o=D(s,u,n)}catch(n){throw n.position=e.position,n.token="path"===e.procedure.type?e.procedure[0].value:e.procedure.value,n}return o}function D(e,n,t){var a;for(a=N(e,n,t);_(a)&&a.thunk===!0;){var o=r(a.body.procedure,a.input,a.environment),i=[];a.body.arguments.forEach(function(e){i.push(r(e,a.input,a.environment))}),a=N(o,i,t)}return a}function N(e,n,t){var r;if(_(e))r=M(e,n);else if(e&&e._jsonata_function===!0)r=e.implementation.apply(t,n);else{if("function"!=typeof e)throw{code:"T1006",stack:(new Error).stack};r=e.apply(t,n)}return r}function $(e,n,t){var r={_jsonata_lambda:!0,input:n,environment:t,arguments:e.arguments,signature:e.signature,body:e.body};return e.thunk===!0&&(r.thunk=!0),r}function I(e,n,t){var a,o=[];e.arguments.forEach(function(e){"operator"===e.type&&"?"===e.value?o.push(e):o.push(r(e,n,t))});var i=r(e.procedure,n,t);if("undefined"==typeof i&&"path"===e.procedure.type&&t.lookup(e.procedure[0].value))throw{code:"T1007",stack:(new Error).stack,position:e.position,token:e.procedure[0].value};if(_(i))a=P(i,o);else if(i&&i._jsonata_function===!0)a=R(i.implementation,o);else{if("function"!=typeof i)throw{code:"T1008",stack:(new Error).stack,position:e.position,token:"path"===e.procedure.type?e.procedure[0].value:e.procedure.value};a=R(i,o)}return a}function F(e,n,t){if("undefined"==typeof e)return n;var r=e.validate(n,t);return r}function M(e,n){var t,a=ve(e.environment);return e.arguments.forEach(function(e,t){a.bind(e.value,n[t])}),t="function"==typeof e.body?C(e.body,a):r(e.body,e.input,a)}function P(e,n){var t=ve(e.environment),r=[];e.arguments.forEach(function(e,a){var o=n[a];o&&"operator"===o.type&&"?"===o.value?r.push(e):t.bind(e.value,o)});var a={_jsonata_lambda:!0,input:e.input,environment:t,arguments:r,body:e.body};return a}function R(e,n){var t=U(e);t=t.map(function(e){return"$"+e.trim()});var r="function("+t.join(", ")+"){ _ }",a=we(r);a.body=e;var o=P(a,n);return o}function C(e,n){var t=U(e),r=t.map(function(e){return n.lookup(e.trim())}),a=e.apply(null,r);return a}function U(e){var n=e.toString(),t=/\(([^\)]*)\)/.exec(n)[1],r=t.split(",");return r}function H(n,t){var r={_jsonata_function:!0,implementation:n};return"undefined"!=typeof t&&(r.signature=e(t)),r}function L(e){if("undefined"!=typeof e){var n=0;return e.forEach(function(e){n+=e}),n}}function q(e){return"undefined"==typeof e?0:e.length}function z(e){if("undefined"!=typeof e&&0!==e.length)return Math.max.apply(Math,e)}function G(e){if("undefined"!=typeof e&&0!==e.length)return Math.min.apply(Math,e)}function B(e){if("undefined"!=typeof e&&0!==e.length){var n=0;return e.forEach(function(e){n+=e}),n/e.length}}function J(e){if("undefined"!=typeof e){var t;if("string"==typeof e)t=e;else if(T(e))t="";else{if("number"==typeof e&&!isFinite(e))throw{code:"D3001",value:e,stack:(new Error).stack};t=JSON.stringify(e,function(e,t){return"undefined"!=typeof t&&null!==t&&t.toPrecision&&n(t)?Number(t.toPrecision(13)):t&&T(t)?"":t})}return t}}function K(e,n,t){if("undefined"!=typeof e)return e.substr(n,t)}function Q(e,n){if("undefined"!=typeof e){var t=e.indexOf(n);return t>-1?e.substr(0,t):e}}function V(e,n){if("undefined"!=typeof e){var t=e.indexOf(n);return t>-1?e.substr(t+n.length):e}}function W(e){if("undefined"!=typeof e)return e.toLowerCase()}function X(e){if("undefined"!=typeof e)return e.toUpperCase()}function Y(e){if("undefined"!=typeof e)return e.length}function Z(e){if("undefined"!=typeof e){var n=e.replace(/[ \t\n\r]+/gm," ");return" "===n.charAt(0)&&(n=n.substring(1))," "===n.charAt(n.length-1)&&(n=n.substring(0,n.length-1)),n}}function ee(e,n){if("undefined"!=typeof e){var t;if("string"==typeof n)t=e.indexOf(n)!==-1;else{var r=n(e);t="undefined"!=typeof r}return t}}function ne(e,n,t){if("undefined"!=typeof e){if(t<0)throw{stack:(new Error).stack,value:t,code:"D3040",index:3};var r=[];if("undefined"==typeof t||t>0){var a=0,o=n(e);if("undefined"!=typeof o)for(;"undefined"!=typeof o&&("undefined"==typeof t||a<t);)r.push({match:o.match,index:o.start,groups:o.groups}),o=o.next(),a++}return r}}function te(e,n,t,r){if("undefined"!=typeof e){if(""===n)throw{code:"D3010",stack:(new Error).stack,value:n,index:2};if(r<0)throw{code:"D3011",stack:(new Error).stack,value:r,index:4};var a;a="string"==typeof t?function(e){for(var n="",r=0,a=t.indexOf("$",r);a!==-1&&r<t.length;){n+=t.substring(r,a),r=a+1;var o=t.charAt(r);if("$"===o)n+="$",r++;else if("0"===o)n+=e.match,r++;else{var i;if(i=0===e.groups.length?1:Math.floor(Math.log(e.groups.length)*Math.LOG10E)+1,a=parseInt(t.substring(r,r+i),10),i>1&&a>e.groups.length&&(a=parseInt(t.substring(r,r+i-1),10)),isNaN(a))n+="$";else{if(e.groups.length>0){var s=e.groups[a-1];"undefined"!=typeof s&&(n+=s)}r+=a.toString().length}}a=t.indexOf("$",r)}return n+=t.substring(r)}:t;var o="",i=0;if("undefined"==typeof r||r>0){var s=0;if("string"==typeof n){for(var u=e.indexOf(n,i);u!==-1&&("undefined"==typeof r||s<r);)o+=e.substring(i,u),o+=t,i=u+n.length,s++,u=e.indexOf(n,i);o+=e.substring(i)}else{var f=n(e);if("undefined"!=typeof f){for(;"undefined"!=typeof f&&("undefined"==typeof r||s<r);){o+=e.substring(i,f.start);var c=D(a,[f],null);if("string"!=typeof c)throw{code:"D3012",stack:(new Error).stack,value:c};o+=c,i=f.start+f.match.length,s++,f=f.next()}o+=e.substring(i)}else o=e}}else o=e;return o}}function re(e,n,t){if("undefined"!=typeof e){if(t<0)throw{code:"D3020",stack:(new Error).stack,value:t,index:3};var r=[];if("undefined"==typeof t||t>0)if("string"==typeof n)r=e.split(n,t);else{var a=0,o=n(e);if("undefined"!=typeof o){for(var i=0;"undefined"!=typeof o&&("undefined"==typeof t||a<t);)r.push(e.substring(i,o.start)),i=o.end,o=o.next(),a++;("undefined"==typeof t||a<t)&&r.push(e.substring(i))}else r=[e]}return r}}function ae(e,n){if("undefined"!=typeof e)return"undefined"==typeof n&&(n=""),e.join(n)}function oe(e){var n;if("undefined"!=typeof e){if("number"==typeof e)n=e;else{if("string"!=typeof e||!/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(e)||isNaN(parseFloat(e))||!isFinite(e))throw{code:"D3030",value:e,stack:(new Error).stack,index:1};n=parseFloat(e)}return n}}function ie(e){if("undefined"!=typeof e){var t=!1;if(Array.isArray(e)){if(1===e.length)t=ie(e[0]);else if(e.length>1){var r=e.filter(function(e){return ie(e)});t=r.length>0}}else"string"==typeof e?e.length>0&&(t=!0):n(e)?0!==e&&(t=!0):null!==e&&"object"==typeof e?Object.keys(e).length>0&&(_(e)||e._jsonata_function||(t=!0)):"boolean"==typeof e&&e===!0&&(t=!0);return t}}function se(e){return!ie(e)}function ue(e,n){var t=arguments,r=[],a=n;a=[];for(var o=1;o<t.length;o++)a.push(t[o]);for(var i=0;i<a[0].length;i++){for(var s=[],u="function"==typeof e?e.length:e._jsonata_function===!0?e.implementation.length:e.arguments.length,f=0;f<u;f++)s.push(a[f][i]);r.push(D(e,s,null))}return r}function fe(e,n,t){var r;if(2!==e.length&&(e._jsonata_function!==!0||2!==e.implementation.length)&&2!==e.arguments.length)throw{stack:(new Error).stack,code:"D3050",index:1};var a;for("undefined"==typeof t&&n.length>0?(r=n[0],a=1):(r=t,a=0);a<n.length;)r=D(e,[r,n[a]],null),a++;return r}function ce(e){var n=[];if(Array.isArray(e)){var t={};e.forEach(function(e){var n=ce(e);Array.isArray(n)&&n.forEach(function(e){t[e]=!0})}),n=ce(t)}else null===e||"object"!=typeof e||_(e)?n=void 0:(n=Object.keys(e),0===n.length&&(n=void 0));return n}function pe(e,n){var t=u({value:n},e);return t}function le(e,n){return"undefined"==typeof e?n:"undefined"==typeof n?e:(Array.isArray(e)||(e=[e]),Array.isArray(n)||(n=[n]),Array.prototype.push.apply(e,n),e)}function de(e){return"undefined"!=typeof e}function he(e){var n=[];if(Array.isArray(e))e.forEach(function(e){n=le(n,he(e))});else if(null===e||"object"!=typeof e||_(e))n=e;else for(var t in e){var r={};r[t]=e[t],n.push(r)}return n}function ve(e){var n={};return{bind:function(e,t){n[e]=t},lookup:function(t){var r;return n.hasOwnProperty(t)?r=n[t]:e&&(r=e.lookup(t)),r}}}function ye(e){var n="Unknown error";"undefined"!=typeof e.message&&(n=e.message);var t=Ae[e.code];return"undefined"!=typeof t&&(n=t.replace(/\{\{([^}]+)}}/g,function(){return e[arguments[1]]})),n}function be(e){var n;try{n=we(e)}catch(e){throw e.message=ye(e),e}var t=ve(xe);return{evaluate:function(e,a){if("undefined"!=typeof a){var o;o=ve(t);for(var i in a)o.bind(i,a[i])}else o=t;o.bind("$",e);var s;try{s=r(n,e,o)}catch(e){throw e.message=ye(e),e}return s},assign:function(e,n){t.bind(e,n)},registerFunction:function(e,n,r){var a=H(n,r);t.bind(e,a)}}}var ge={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":75,"#":70,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"`":80,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},ke={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},me=function(e){var n=0,t=e.length,r=function(e,t){var r={type:e,value:t,position:n};return r},a=function(){for(var r,a,o=n,i=0;n<t;){var s=e.charAt(n);if("/"===s&&"\\"!==e.charAt(n-1)&&0===i){if(r=e.substring(o,n),""===r)throw{code:"S0301",stack:(new Error).stack,position:n};for(n++,s=e.charAt(n),o=n;"i"===s||"m"===s;)n++,s=e.charAt(n);return a=e.substring(o,n)+"g",new RegExp(r,a)}"("!==s&&"["!==s&&"{"!==s||"\\"===e.charAt(n-1)||i++,")"!==s&&"]"!==s&&"}"!==s||"\\"===e.charAt(n-1)||i--,n++}throw{code:"S0302",stack:(new Error).stack,position:n}},o=function(o){if(n>=t)return null;for(var i=e.charAt(n);n<t&&" \t\n\r\v".indexOf(i)>-1;)n++,i=e.charAt(n);if(o!==!0&&"/"===i)return n++,r("regex",a());if("."===i&&"."===e.charAt(n+1))return n+=2,r("operator","..");if(":"===i&&"="===e.charAt(n+1))return n+=2,r("operator",":=");if("!"===i&&"="===e.charAt(n+1))return n+=2,r("operator","!=");if(">"===i&&"="===e.charAt(n+1))return n+=2,r("operator",">=");if("<"===i&&"="===e.charAt(n+1))return n+=2,r("operator","<=");if("*"===i&&"*"===e.charAt(n+1))return n+=2,r("operator","**");if("~"===i&&">"===e.charAt(n+1))return n+=2,r("operator","~>");if(ge.hasOwnProperty(i))return n++,r("operator",i);if('"'===i||"'"===i){var s=i;n++;for(var u="";n<t;){if(i=e.charAt(n),"\\"===i)if(n++,i=e.charAt(n),ke.hasOwnProperty(i))u+=ke[i];else{if("u"!==i)throw{code:"S0103",stack:(new Error).stack,position:n,token:i};var f=e.substr(n+1,4);if(!/^[0-9a-fA-F]+$/.test(f))throw{code:"S0104",stack:(new Error).stack,position:n};var c=parseInt(f,16);u+=String.fromCharCode(c),n+=4}else{if(i===s)return n++,r("string",u);u+=i}n++}throw{code:"S0101",stack:(new Error).stack,position:n}}var p=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/,l=p.exec(e.substring(n));if(null!==l){var d=parseFloat(l[0]);if(!isNaN(d)&&isFinite(d))return n+=l[0].length,r("number",d);throw{code:"S0102",stack:(new Error).stack,position:n,token:l[0]}}for(var h,v,y=n;;)if(h=e.charAt(y),y===t||" \t\n\r\v".indexOf(h)>-1||ge.hasOwnProperty(h)){if("$"===e.charAt(n))return v=e.substring(n+1,y),n=y,r("variable",v);switch(v=e.substring(n,y),n=y,v){case"or":case"in":case"and":return r("operator",v);case"true":return r("value",!0);case"false":return r("value",!1);case"null":return r("value",null);default:return n===t&&""===v?null:r("name",v)}}else y++};return o},we=function(t){var r,a,o={},i={nud:function(){return this}},s=function(e,n){var t=o[e];return n=n||0,t?n>=t.lbp&&(t.lbp=n):(t=Object.create(i),t.id=t.value=e,t.lbp=n,o[e]=t),t},u=function(e,n){if(e&&r.id!==e){var i;throw i="(end)"===r.id?"S0203":"S0202",{code:i,stack:(new Error).stack,position:r.position,token:r.id,value:e}}var s=a(n);if(null===s)return r=o["(end)"],r.position=t.length,r;var u,f=s.value,c=s.type;switch(c){case"name":case"variable":u=o["(name)"];break;case"operator":if(u=o[f],!u)throw{code:"S0204",stack:(new Error).stack,position:s.position,token:f};break;case"string":case"number":case"value":c="literal",u=o["(literal)"];break;case"regex":c="regex",u=o["(regex)"];break;default:throw{code:"S0205",stack:(new Error).stack,position:s.position,token:f}}return r=Object.create(u),r.value=f,r.type=c,r.position=s.position,r},f=function(e){var n,t=r;for(u(null,!0),n=t.nud();e<r.lbp;)t=r,u(),n=t.led(n);return n},c=function(e,n,t){var r=n||ge[e],a=s(e,r);return a.led=t||function(e){return this.lhs=e,this.rhs=f(r),this.type="binary",this},a},p=function(e,n,t){var r=n||ge[e],a=s(e,r);return a.led=t||function(e){return this.lhs=e,this.rhs=f(r-1),this.type="binary",this},a},l=function(e,n){var t=s(e);return t.nud=n||function(){return this.expression=f(70),this.type="unary",this},t};s("(end)"),s("(name)"),s("(literal)"),s("(regex)"),s(":"),s(";"),s(","),s(")"),s("]"),s("}"),s(".."),c("."),c("+"),c("-"),c("*"),c("/"),c("%"),c("="),c("<"),c(">"),c("!="),c("<="),c(">="),c("&"),c("and"),c("or"),c("in"),p(":="),l("-"),c("~>"),l("*",function(){return this.type="wildcard",this}),l("**",function(){return this.type="descendant",this}),c("(",ge["("],function(n){if(this.procedure=n,this.type="function",this.arguments=[],")"!==r.id)for(;"operator"===r.type&&"?"===r.id?(this.type="partial",this.arguments.push(r),u("?")):this.arguments.push(f(0)),","===r.id;)u(",");if(u(")",!0),"name"===n.type&&("function"===n.value||"λ"===n.value)){if(this.arguments.forEach(function(e,n){if("variable"!==e.type)throw{code:"S0208",stack:(new Error).stack,position:e.position,token:e.value,value:n+1}}),this.type="lambda","<"===r.id){for(var t=r.position,a=1,o="<";a>0&&"{"!==r.id&&"(end)"!==r.id;){var i=u();">"===i.id?a--:"<"===i.id&&a++,o+=i.value}u(">");try{this.signature=e(o)}catch(e){throw e.position=t+e.offset,e}}u("{"),this.body=f(0),u("}")}return this}),l("(",function(){for(var e=[];")"!==r.id&&(e.push(f(0)),";"===r.id);)u(";");return u(")",!0),this.type="block",this.expressions=e,this}),l("[",function(){var e=[];if("]"!==r.id)for(;;){var n=f(0);if(".."===r.id){var t={type:"binary",value:"..",position:r.position,lhs:n};u(".."),t.rhs=f(0),n=t}if(e.push(n),","!==r.id)break;u(",")}return u("]",!0),this.lhs=e,this.type="unary",this}),c("[",ge["["],function(e){if("]"===r.id){for(var n=e;n&&"binary"===n.type&&"["===n.value;)n=n.lhs;return n.keepArray=!0,u("]"),e}return this.lhs=e,this.rhs=f(ge["]"]),this.type="binary",u("]",!0),this});var d=function(e){var n=[];if("}"!==r.id)for(;;){var t=f(0);u(":");var a=f(0);if(n.push([t,a]),","!==r.id)break;u(",")}return u("}",!0),"undefined"==typeof e?(this.lhs=n,this.type="unary"):(this.lhs=e,this.rhs=n,this.type="binary"),this};l("{",d),c("{",ge["{"],d),c("?",ge["?"],function(e){return this.type="condition",this.condition=e,this.then=f(0),":"===r.id&&(u(":"),this.else=f(0)),this});var h=function(e){var n;if("function"===e.type){var t={type:"lambda",thunk:!0,arguments:[],position:e.position};t.body=e,n=t}else if("condition"===e.type)e.then=h(e.then),e.else=h(e.else),n=e;else if("block"===e.type){var r=e.expressions.length;r>0&&(e.expressions[r-1]=h(e.expressions[r-1])),n=e}else n=e;return n},v=function(e){var t=[];switch(e.type){case"binary":switch(e.value){case".":var r=v(e.lhs);"path"===r.type?Array.prototype.push.apply(t,r):t.push(r);var a=v(e.rhs);"path"!==a.type&&(a=[a]),Array.prototype.push.apply(t,a),t.type="path";break;case"[":t=v(e.lhs);var o=t;if("path"===t.type&&(o=t[t.length-1]),"undefined"!=typeof o.group)throw{code:"S0209",stack:(new Error).stack,position:e.position};"undefined"==typeof o.predicate&&(o.predicate=[]),o.predicate.push(v(e.rhs));break;case"{":if(t=v(e.lhs),"undefined"!=typeof t.group)throw{code:"S0210",stack:(new Error).stack,position:e.position};t.group={lhs:e.rhs.map(function(e){return[v(e[0]),v(e[1])]}),position:e.position};break;default:t={type:e.type,value:e.value,position:e.position},t.lhs=v(e.lhs),t.rhs=v(e.rhs)}break;case"unary":t={type:e.type,value:e.value,position:e.position},"["===e.value?t.lhs=e.lhs.map(function(e){return v(e)}):"{"===e.value?t.lhs=e.lhs.map(function(e){return[v(e[0]),v(e[1])]}):(t.expression=v(e.expression),"-"===e.value&&"literal"===t.expression.type&&n(t.expression.value)&&(t=t.expression,t.value=-t.value));break;case"function":case"partial":t={type:e.type,name:e.name,value:e.value,position:e.position},t.arguments=e.arguments.map(function(e){return v(e)}),t.procedure=v(e.procedure);break;case"lambda":t={type:e.type,arguments:e.arguments,signature:e.signature,position:e.position};var i=v(e.body);t.body=h(i);break;case"condition":t={type:e.type,position:e.position},t.condition=v(e.condition),t.then=v(e.then),"undefined"!=typeof e.else&&(t.else=v(e.else));break;case"block":t={type:e.type,position:e.position},t.expressions=e.expressions.map(function(e){return v(e)});break;case"name":t=[e],t.type="path";break;case"literal":case"wildcard":case"descendant":case"variable":case"regex":t=e;break;case"operator":if("and"===e.value||"or"===e.value||"in"===e.value)e.type="name",t=v(e);else{if("?"!==e.value)throw{code:"S0201",stack:(new Error).stack,position:e.position,token:e.value};t=e}break;default:var s="S0206";throw"(end)"===e.id&&(s="S0207"),{code:s,stack:(new Error).stack,position:e.position,token:e.value}}return t};a=me(t),u();var y=f(0);if("(end)"!==r.id)throw{code:"S0201",stack:(new Error).stack,position:r.position,token:r.value};return y=v(y)},xe=ve(null);Number.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e};var Ee=r(we("function($f, $g) { function($x){ $g($f($x)) } }"),null,xe);xe.bind("sum",H(L,"<a<n>:n>")),xe.bind("count",H(q,"<a:n>")),xe.bind("max",H(z,"<a<n>:n>")),xe.bind("min",H(G,"<a<n>:n>")),xe.bind("average",H(B,"<a<n>:n>")),xe.bind("string",H(J,"<x-:s>")),xe.bind("substring",H(K,"<s-nn?:s>")),xe.bind("substringBefore",H(Q,"<s-s:s>")),xe.bind("substringAfter",H(V,"<s-s:s>")),xe.bind("lowercase",H(W,"<s-:s>")),xe.bind("uppercase",H(X,"<s-:s>")),xe.bind("length",H(Y,"<s-:n>")),xe.bind("trim",H(Z,"<s-:s>")),xe.bind("match",H(ne,"<s-f<s:o>n?:a<o>>")),xe.bind("contains",H(ee,"<s-(sf):b>")),xe.bind("replace",H(te,"<s-(sf)(sf)n?:s>")),xe.bind("split",H(re,"<s-(sf)n?:a<s>>")),xe.bind("join",H(ae,"<a<s>s?:s>")),xe.bind("number",H(oe,"<(ns)-:n>")),xe.bind("boolean",H(ie,"<x-:b>")),xe.bind("not",H(se,"<x-:b>")),xe.bind("map",H(ue,"<fa+>")),xe.bind("reduce",H(fe,"<faj?:j>")),xe.bind("keys",H(ce,"<x-:a<s>>")),xe.bind("lookup",H(pe,"<x-s:x>")),xe.bind("append",H(le,"<xx:a>")),xe.bind("exists",H(de,"<x:b>")),xe.bind("spread",H(he,"<x-:a<o>>"));var Ae={S0101:"No terminating quote found in string literal",S0102:"Number out of range: {{token}}",S0103:"unsupported escape sequence: \\{{token}}",S0104:"The escape sequence \\u must be followed by 4 hex digits",S0203:"Syntax error: expected '{{value}}' before end of expression",S0202:"Syntax error: expected '{{value}}', got '{{token}}'",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",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.",S0201:"Syntax error: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Syntax error: unexpected end of expression",S0301:"Empty regular expressions are not allowed",S0302:"No terminating / in regular expression",S0402:"Choice groups containing parameterized types not supported",S0401:"Type parameters can only be applied to functions and arrays",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}}",T2001:"LHS of {{token}} operator must evaluate to a number",T2002:"RHS of {{token}} operator must evaluate to a number",T1003:"Key in object structure must evaluate to a string. Got: {{value}}",T2003:"LHS of range operator (..) must evaluate to an integer",T2004:"RHS of range operator (..) must evaluate to an integer",D2005:"Left hand side of := must be a variable name (start with $)",D1004:"Regular expression matches zero length string",T2006:"RHS of function application operator ~> is not a function",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",D3001:"Attempting to invoke string function on Infinity or NaN",D3010:"Second argument of replace function cannot be an empty string",D3011:"Forth argument of replace function must evaluate to a positive number",D3012:"Attempted to replace a matched string with a non-string value",D3020:"Third argument of split function must evaluate to a positive number",D3030:"Unable to cast value to a number: {{value}}"};return be.parser=we,be}();"undefined"!=typeof module&&(module.exports=jsonata);
var jsonata=function(){"use strict";function e(e){for(var r=1,t=[],n={},a=n;r<e.length;){var i=e.charAt(r);if(":"===i)break;var o=function(){t.push(n),a=n,n={}},s=function(e,r,t,n){for(var a=1,o=r;o<e.length;)if(o++,(i=e.charAt(o))===n){if(0===--a)break}else i===t&&a++;return o};switch(i){case"s":case"n":case"b":case"l":case"o":n.regex="["+i+"m]",n.type=i,o();break;case"a":n.regex="[asnblfom]",n.type=i,n.array=!0,o();break;case"f":n.regex="f",n.type=i,o();break;case"j":n.regex="[asnblom]",n.type=i,o();break;case"x":n.regex="[asnblfom]",n.type=i,o();break;case"-":a.context=!0,a.contextRegex=new RegExp(a.regex),a.regex+="?";break;case"?":case"+":a.regex+=i;break;case"(":var u=s(e,r,"(",")"),c=e.substring(r+1,u);if(-1!==c.indexOf("<"))throw{code:"S0402",stack:(new Error).stack,value:c,offset:r};n.regex="["+c+"m]",n.type="("+c+")",r=u,o();break;case"<":if("a"!==a.type&&"f"!==a.type)throw{code:"S0401",stack:(new Error).stack,value:a.type,offset:r};var l=s(e,r,"<",">");a.subtype=e.substring(r+1,l),r=l}r++}var f="^"+t.map(function(e){return"("+e.regex+")"}).join("")+"$",p=new RegExp(f),d=function(e){var r;if($(e))r="f";else switch(typeof e){case"string":r="s";break;case"number":r="n";break;case"boolean":r="b";break;case"object":r=null===e?"l":Array.isArray(e)?"a":"o";break;case"undefined":r="m"}return r},v=function(e,r){for(var n="^",a=0,i=0;i<t.length;i++){n+=t[i].regex;var o=r.match(n);if(null===o)throw{code:"T0410",stack:(new Error).stack,value:e[a],index:a+1};a=o[0].length}throw{code:"T0410",stack:(new Error).stack,value:e[a],index:a+1}};return{definition:e,validate:function(e,r){var n="";e.forEach(function(e){n+=d(e)});var a=p.exec(n);if(a){var i=[],o=0;return t.forEach(function(t,n){var s=e[o],u=a[n+1];if(""===u)if(t.context){var c=d(r);if(!t.contextRegex.test(c))throw{code:"T0411",stack:(new Error).stack,value:r,index:o+1};i.push(r)}else i.push(s),o++;else u.split("").forEach(function(r){if("a"===t.type){if("m"===r)s=void 0;else{s=e[o];var n=!0;if(void 0!==t.subtype)if("a"!==r&&u!==t.subtype)n=!1;else if("a"===r&&s.length>0){var a=d(s[0]);n=a===t.subtype.charAt(0)&&0===s.filter(function(e){return d(e)!==a}).length}if(!n)throw{code:"T0412",stack:(new Error).stack,value:s,index:o+1,type:t.subtype};"a"!==r&&(s=[s])}i.push(s),o++}else i.push(s),o++})}),i}v(e,n)}}}function r(e){var r=!1;if("number"==typeof e){var t=parseFloat(e);if((r=!isNaN(t))&&!isFinite(t))throw{code:"D1001",value:e,stack:(new Error).stack}}return r}function t(e){var r=!1;return Array.isArray(e)&&(r=0===e.filter(function(e){return"string"!=typeof e}).length),r}function n(e){var t=!1;return Array.isArray(e)&&(t=0===e.filter(function(e){return!r(e)}).length),t}function*a(e,r,t){var n,a=t.lookup("__evaluate_entry");switch(a&&a(e,r,t),e.type){case"path":n=o(n=yield*i(e.steps,r,t),e.keepSingletonArray);break;case"binary":n=yield*l(e,r,t);break;case"unary":n=yield*f(e,r,t);break;case"name":n=p(e,r,t);break;case"literal":n=d(e);break;case"wildcard":n=v(e,r);break;case"descendant":n=y(e,r);break;case"condition":n=yield*T(e,r,t);break;case"block":n=yield*j(e,r,t);break;case"bind":n=yield*S(e,r,t);break;case"regex":n=_(e);break;case"function":n=yield*P(e,r,t);break;case"variable":n=D(e,r,t);break;case"lambda":n=q(e,r,t);break;case"partial":n=yield*R(e,r,t);break;case"apply":n=yield*N(e,r,t);break;case"sort":n=yield*O(e,r,t)}!t.lookup("__jsonata_async")||void 0!==n&&"function"==typeof n.then||(n=Promise.resolve(n)),n=yield n,e.hasOwnProperty("predicate")&&(n=o(n=yield*u(e.predicate,n,t))),e.hasOwnProperty("group")&&(n=yield*A(e.group,n,t));var s=t.lookup("__evaluate_exit");return s&&s(e,r,t,n),n}function*i(e,r,t){var n;n="variable"===e[0].type?[r]:e[0].consarray?[null]:Array.isArray(r)?r:[r];for(var a,i=0;i<e.length&&(void 0!==(a=yield*s(e[i],n,t))&&0!==a.length);i++)n=a;return a}function o(e,r){var t;return void 0===e?t=void 0:Array.isArray(e)?1===e.length?t=r?e:e[0]:e.length>1&&(t=e):t=e,t}function*s(e,r,t){for(var n=[],i=0;i<r.length;i++){var o=yield*a(e,r[i],t);Array.isArray(o)&&"["!==e.value||e.consarray||(o=[o]),o.forEach(function(e){void 0!==e&&n.push(e)})}return n}function*u(e,t,n){for(var a=t,i=[],o=0;o<e.length;o++){var s=e[o];if(Array.isArray(a)||(a=[a]),i=[],"literal"===s.type&&r(s.value)){var u=s.value;Number.isInteger(u)||(u=Math.floor(u)),u<0&&(u=a.length+u),i=a[u]}else i=yield*c(s,a,n);a=i}return i}function*c(e,t,i){for(var o=[],s=0;s<t.length;s++){var u=t[s],c=yield*a(e,u,i);r(c)&&(c=[c]),n(c)?c.forEach(function(e){Number.isInteger(e)||(e=Math.floor(e)),e<0&&(e=t.length+e),e===s&&o.push(u)}):me(c)&&o.push(u)}return o}function*l(e,r,t){var n,i=yield*a(e.lhs,r,t),o=yield*a(e.rhs,r,t),s=e.value;try{switch(s){case"+":case"-":case"*":case"/":case"%":n=g(i,o,s);break;case"=":case"!=":case"<":case"<=":case">":case">=":n=k(i,o,s);break;case"&":n=x(i,o);break;case"and":case"or":n=w(i,o,s);break;case"..":n=E(i,o);break;case"in":n=m(i,o)}}catch(r){throw r.position=e.position,r.token=s,r}return n}function*f(e,t,n){var i;switch(e.value){case"-":if(i=yield*a(e.expression,t,n),!r(i))throw{code:"D1002",stack:(new Error).stack,position:e.position,token:e.value,value:i};i=-i;break;case"[":i=[];for(var o=0;o<e.lhs.length;o++){var s=e.lhs[o],u=yield*a(s,t,n);void 0!==u&&("["===s.value?i.push(u):i=_e(i,u))}break;case"{":i=yield*A(e,t,n)}return i}function p(e,r,t){var n;if(Array.isArray(r)){n=[];for(var a=0;a<r.length;a++){var i=p(e,r[a],t);void 0!==i&&n.push(i)}}else null!==r&&"object"==typeof r&&(n=r[e.value]);return n=o(n)}function d(e){return e.value}function v(e,r){var t=[];return null!==r&&"object"==typeof r&&Object.keys(r).forEach(function(e){var n=r[e];Array.isArray(n)?(n=h(n),t=_e(t,n)):t.push(n)}),o(t)}function h(e,r){return void 0===r&&(r=[]),Array.isArray(e)?e.forEach(function(e){h(e,r)}):r.push(e),r}function y(e,r){var t,n=[];return void 0!==r&&(b(r,n),t=1===n.length?n[0]:n),t}function b(e,r){Array.isArray(e)||r.push(e),Array.isArray(e)?e.forEach(function(e){b(e,r)}):null!==e&&"object"==typeof e&&Object.keys(e).forEach(function(t){b(e[t],r)})}function g(e,t,n){var a;if(void 0===e||void 0===t)return a;if(!r(e))throw{code:"T2001",stack:(new Error).stack,value:e};if(!r(t))throw{code:"T2002",stack:(new Error).stack,value:t};switch(n){case"+":a=e+t;break;case"-":a=e-t;break;case"*":a=e*t;break;case"/":a=e/t;break;case"%":a=e%t}return a}function k(e,r,t){var n,a=typeof e,i=typeof r;if("undefined"===a||"undefined"===i)return!1;var o=function(){if("string"!==a&&"number"!==a||"string"!==i&&"number"!==i)throw{code:"T2010",stack:(new Error).stack,value:"string"!==a&&"number"!==a?e:r};if(a!==i)throw{code:"T2009",stack:(new Error).stack,value:e,value2:r}};switch(t){case"=":n=e===r;break;case"!=":n=e!==r;break;case"<":o(),n=e<r;break;case"<=":o(),n=e<=r;break;case">":o(),n=e>r;break;case">=":o(),n=e>=r}return n}function m(e,r){var t=!1;if(void 0===e||void 0===r)return!1;Array.isArray(r)||(r=[r]);for(var n=0;n<r.length;n++)if(r[n]===e){t=!0;break}return t}function w(e,r,t){var n;switch(t){case"and":n=me(e)&&me(r);break;case"or":n=me(e)||me(r)}return n}function x(e,r){var t="",n="";return void 0!==e&&(t=Z(e)),void 0!==r&&(n=Z(r)),t.concat(n)}function*A(e,r,t){var n={},i={};Array.isArray(r)||(r=[r]);for(var o=[],s=0;s<r.length;s++)for(var u=0;u<e.lhs.length;u++)o.push(yield*a(e.lhs[u][0],r[s],t));var c=o.entries();r.forEach(function(r){e.lhs.forEach(function(t){var n=c.next().value[1];if("string"!=typeof n)throw{code:"T1003",stack:(new Error).stack,position:e.position,value:n};var a={data:r,expr:t[1]};i.hasOwnProperty(n)?i[n].data=_e(i[n].data,r):i[n]=a})}),o=[];var l;for(l in i){var f=i[l];o.push(yield*a(f.expr,f.data,t))}c=o.entries();for(l in i){var p=c.next().value[1];n[l]=p}return n}function E(e,r){var t;if(void 0===e||void 0===r)return t;if(e>r)return t;if(!Number.isInteger(e))throw{code:"T2003",stack:(new Error).stack,value:e};if(!Number.isInteger(r))throw{code:"T2004",stack:(new Error).stack,value:r};t=new Array(r-e+1);for(var n=e,a=0;n<=r;n++,a++)t[a]=n;return t}function*S(e,r,t){var n=yield*a(e.rhs,r,t);if("variable"!==e.lhs.type)throw{code:"D2005",stack:(new Error).stack,position:e.position,token:e.value,value:"path"===e.lhs.type?e.lhs.steps[0].value:e.lhs.value};return t.bind(e.lhs.value,n),n}function*T(e,r,t){var n;return me(yield*a(e.condition,r,t))?n=yield*a(e.then,r,t):void 0!==e.else&&(n=yield*a(e.else,r,t)),n}function*j(e,r,t){for(var n,i=Pe(t),o=0;o<e.expressions.length;o++)n=yield*a(e.expressions[o],r,i);return n}function _(e){e.value.lastIndex=0;var r=function(t){var n,a=e.value,i=a.exec(t);if(null!==i){if(n={match:i[0],start:i.index,end:i.index+i[0].length,groups:[]},i.length>1)for(var o=1;o<i.length;o++)n.groups.push(i[o]);n.next=function(){if(!(a.lastIndex>=t.length)){var n=r(t);if(n&&""===n.match&&a.lastIndex===e.value.lastIndex)throw{code:"D1004",stack:(new Error).stack,position:e.position,value:e.value.source};return n}}}return n};return r}function D(e,r,t){return""===e.value?r:t.lookup(e.value)}function*O(e,r,t){return $e(yield*a(e.lhs,r,t),function(r,n){for(var a=0,i=0;0===a&&i<e.rhs.length;i++){var o=e.rhs[i],s=M(o.expression,r,t),u=M(o.expression,n,t),c=typeof s,l=typeof u;if("undefined"!==c)if("undefined"!==l){if("string"!==c&&"number"!==c||"string"!==l&&"number"!==l)throw{code:"T2008",stack:(new Error).stack,position:e.position,value:"string"!==c&&"number"!==c?s:u};if(c!==l)throw{code:"T2007",stack:(new Error).stack,position:e.position,value:s,value2:u};s!==u&&(a=s<u?-1:1,!0===o.descending&&(a=-a))}else a=-1;else a="undefined"===l?0:1}return 1===a})}function M(e,r,t){for(var n=a(e,r,t),i=n.next();!i.done;)i=n.next(i.value);return i.value}function*N(e,r,t){var n,i=yield*a(e.lhs,r,t);if("function"===e.rhs.type)n=yield*P(e.rhs,r,t,{context:i});else{var o=yield*a(e.rhs,r,t);if(!$(o))throw{code:"T2006",stack:(new Error).stack,position:e.position,value:o};n=$(i)?yield*U(Le,[i,o],t,null):yield*U(o,[i],t,null)}return n}function $(e){return e&&(!0===e._jsonata_function||!0===e._jsonata_lambda)||"function"==typeof e}function F(e){return e&&!0===e._jsonata_lambda}function I(e){return"GeneratorFunction"===e.constructor.name}function*P(e,r,t,n){for(var i,o=[],s=0;s<e.arguments.length;s++)o.push(yield*a(e.arguments[s],r,t));n&&o.unshift(n.context);var u=yield*a(e.procedure,r,t);if(void 0===u&&"path"===e.procedure.type&&t.lookup(e.procedure.steps[0].value))throw{code:"T1005",stack:(new Error).stack,position:e.position,token:e.procedure.steps[0].value};try{i=yield*U(u,o,r)}catch(r){throw r.position=e.position,r.token="path"===e.procedure.type?e.procedure.steps[0].value:e.procedure.value,r}return i}function*U(e,r,t){var n;for(n=yield*C(e,r,t);F(n)&&!0===n.thunk;){for(var i=yield*a(n.body.procedure,n.input,n.environment),o=[],s=0;s<n.body.arguments.length;s++)o.push(yield*a(n.body.arguments[s],n.input,n.environment));n=yield*C(i,o,t)}return n}function*C(e,r,t){var n,a=r;if(e&&(a=J(e.signature,r,t)),F(e))n=yield*z(e,a);else if(e&&!0===e._jsonata_function)n=e.implementation.apply(t,a),I(e.implementation)&&(n=yield*n);else{if("function"!=typeof e)throw{code:"T1006",stack:(new Error).stack};n=e.apply(t,a)}return n}function q(e,r,t){var n={_jsonata_lambda:!0,input:r,environment:t,arguments:e.arguments,signature:e.signature,body:e.body};return!0===e.thunk&&(n.thunk=!0),n}function*R(e,r,t){for(var n,i=[],o=0;o<e.arguments.length;o++){var s=e.arguments[o];"operator"===s.type&&"?"===s.value?i.push(s):i.push(yield*a(s,r,t))}var u=yield*a(e.procedure,r,t);if(void 0===u&&"path"===e.procedure.type&&t.lookup(e.procedure.steps[0].value))throw{code:"T1007",stack:(new Error).stack,position:e.position,token:e.procedure.steps[0].value};if(F(u))n=G(u,i);else if(u&&!0===u._jsonata_function)n=L(u.implementation,i);else{if("function"!=typeof u)throw{code:"T1008",stack:(new Error).stack,position:e.position,token:"path"===e.procedure.type?e.procedure.steps[0].value:e.procedure.value};n=L(u,i)}return n}function J(e,r,t){return void 0===e?r:e.validate(r,t)}function*z(e,r){var t=Pe(e.environment);return e.arguments.forEach(function(e,n){t.bind(e.value,r[n])}),"function"==typeof e.body?yield*B(e.body,t):yield*a(e.body,e.input,t)}function G(e,r){var t=Pe(e.environment),n=[];return e.arguments.forEach(function(e,a){var i=r[a];i&&"operator"===i.type&&"?"===i.value?n.push(e):t.bind(e.value,i)}),{_jsonata_lambda:!0,input:e.input,environment:t,arguments:n,body:e.body}}function L(e,r){var t=K(e),n="function("+(t=t.map(function(e){return"$"+e.trim()})).join(", ")+"){ _ }",a=ze(n);return a.body=e,G(a,r)}function*B(e,r){var t=K(e).map(function(e){return r.lookup(e.trim())}),n=e.apply(null,t);return I(e)&&(n=yield*n),n}function K(e){var r=e.toString();return/\(([^\)]*)\)/.exec(r)[1].split(",")}function H(r,t){var n={_jsonata_function:!0,implementation:r};return void 0!==t&&(n.signature=e(t)),n}function Q(e){if(void 0!==e){var r=0;return e.forEach(function(e){r+=e}),r}}function V(e){return void 0===e?0:e.length}function W(e){if(void 0!==e&&0!==e.length)return Math.max.apply(Math,e)}function X(e){if(void 0!==e&&0!==e.length)return Math.min.apply(Math,e)}function Y(e){if(void 0!==e&&0!==e.length){var r=0;return e.forEach(function(e){r+=e}),r/e.length}}function Z(e){if(void 0!==e){var t;if("string"==typeof e)t=e;else if($(e))t="";else{if("number"==typeof e&&!isFinite(e))throw{code:"D3001",value:e,stack:(new Error).stack};t=JSON.stringify(e,function(e,t){return void 0!==t&&null!==t&&t.toPrecision&&r(t)?Number(t.toPrecision(13)):t&&$(t)?"":t})}return t}}function ee(e,r,t){if(void 0!==e)return e.substr(r,t)}function re(e,r){if(void 0!==e){var t=e.indexOf(r);return t>-1?e.substr(0,t):e}}function te(e,r){if(void 0!==e){var t=e.indexOf(r);return t>-1?e.substr(t+r.length):e}}function ne(e){if(void 0!==e)return e.toLowerCase()}function ae(e){if(void 0!==e)return e.toUpperCase()}function ie(e){if(void 0!==e)return e.length}function oe(e){if(void 0!==e){var r=e.replace(/[ \t\n\r]+/gm," ");return" "===r.charAt(0)&&(r=r.substring(1))," "===r.charAt(r.length-1)&&(r=r.substring(0,r.length-1)),r}}function se(e,r){if(void 0!==e){return"string"==typeof r?-1!==e.indexOf(r):void 0!==r(e)}}function ue(e,r,t){if(void 0!==e){if(t<0)throw{stack:(new Error).stack,value:t,code:"D3040",index:3};var n=[];if(void 0===t||t>0){var a=0,i=r(e);if(void 0!==i)for(;void 0!==i&&(void 0===t||a<t);)n.push({match:i.match,index:i.start,groups:i.groups}),i=i.next(),a++}return n}}function*ce(e,r,t,n){if(void 0!==e){if(""===r)throw{code:"D3010",stack:(new Error).stack,value:r,index:2};if(n<0)throw{code:"D3011",stack:(new Error).stack,value:n,index:4};var a;a="string"==typeof t?function(e){for(var r="",n=0,a=t.indexOf("$",n);-1!==a&&n<t.length;){r+=t.substring(n,a),n=a+1;var i=t.charAt(n);if("$"===i)r+="$",n++;else if("0"===i)r+=e.match,n++;else{var o;if(o=0===e.groups.length?1:Math.floor(Math.log(e.groups.length)*Math.LOG10E)+1,a=parseInt(t.substring(n,n+o),10),o>1&&a>e.groups.length&&(a=parseInt(t.substring(n,n+o-1),10)),isNaN(a))r+="$";else{if(e.groups.length>0){var s=e.groups[a-1];void 0!==s&&(r+=s)}n+=a.toString().length}}a=t.indexOf("$",n)}return r+=t.substring(n)}:t;var i="",o=0;if(void 0===n||n>0){var s=0;if("string"==typeof r){for(var u=e.indexOf(r,o);-1!==u&&(void 0===n||s<n);)i+=e.substring(o,u),i+=t,o=u+r.length,s++,u=e.indexOf(r,o);i+=e.substring(o)}else{var c=r(e);if(void 0!==c){for(;void 0!==c&&(void 0===n||s<n);){i+=e.substring(o,c.start);var l=yield*U(a,[c],null);if("string"!=typeof l)throw{code:"D3012",stack:(new Error).stack,value:l};i+=l,o=c.start+c.match.length,s++,c=c.next()}i+=e.substring(o)}else i=e}}else i=e;return i}}function le(e,r,t){if(void 0!==e){if(t<0)throw{code:"D3020",stack:(new Error).stack,value:t,index:3};var n=[];if(void 0===t||t>0)if("string"==typeof r)n=e.split(r,t);else{var a=0,i=r(e);if(void 0!==i){for(var o=0;void 0!==i&&(void 0===t||a<t);)n.push(e.substring(o,i.start)),o=i.end,i=i.next(),a++;(void 0===t||a<t)&&n.push(e.substring(o))}else n=[e]}return n}}function fe(e,r){if(void 0!==e)return void 0===r&&(r=""),e.join(r)}function pe(e){var r;if(void 0!==e){if("number"==typeof e)r=e;else{if("string"!=typeof e||!/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(e)||isNaN(parseFloat(e))||!isFinite(e))throw{code:"D3030",value:e,stack:(new Error).stack,index:1};r=parseFloat(e)}return r}}function de(e){if(void 0!==e)return Math.abs(e)}function ve(e){if(void 0!==e)return Math.floor(e)}function he(e){if(void 0!==e)return Math.ceil(e)}function ye(e,r){var t;if(void 0!==e){if(r){var n=e.toString().split("e");e=+(n[0]+"e"+(n[1]?+n[1]+r:r))}var a=(t=Math.round(e))-e;return.5===Math.abs(a)&&1===Math.abs(t%2)&&(t-=1),r&&(t=+((n=t.toString().split("e"))[0]+"e"+(n[1]?+n[1]-r:-r))),-0===t&&(t=0),t}}function be(e){if(void 0!==e){if(e<0)throw{stack:(new Error).stack,code:"D3060",index:1,value:e};return Math.sqrt(e)}}function ge(e,r){var t;if(void 0!==e){if(t=Math.pow(e,r),!isFinite(t))throw{stack:(new Error).stack,code:"D3061",index:1,value:e,exp:r};return t}}function ke(){return Math.random()}function me(e){if(void 0!==e){var t=!1;return Array.isArray(e)?1===e.length?t=me(e[0]):e.length>1&&(t=e.filter(function(e){return me(e)}).length>0):"string"==typeof e?e.length>0&&(t=!0):r(e)?0!==e&&(t=!0):null!==e&&"object"==typeof e?Object.keys(e).length>0&&(F(e)||e._jsonata_function||(t=!0)):"boolean"==typeof e&&!0===e&&(t=!0),t}}function we(e){return!me(e)}function*xe(e,r){if(void 0!==e){for(var t=[],n=0;n<e.length;n++){var a=[e[n]],i="function"==typeof r?r.length:!0===r._jsonata_function?r.implementation.length:r.arguments.length;i>=2&&a.push(n),i>=3&&a.push(e);var o=yield*U(r,a,null);void 0!==o&&t.push(o)}return t}}function*Ae(e,r){if(void 0!==e){for(var t=[],n=0;n<e.length;n++){var a=e[n];me(function(e,t,n){for(var a=U(r,[e,t,n],null),i=a.next();!i.done;)i=a.next(i.value);return i.value}(a,n,e))&&t.push(a)}return t}}function Ee(){for(var e=[],r=Array.prototype.slice.call(arguments),t=Math.min.apply(Math,r.map(function(e){return Array.isArray(e)?e.length:0})),n=0;n<t;n++){var a=r.map(e=>e[n]);e.push(a)}return e}function*Se(e,r,t){if(void 0!==e){var n;if(2!==r.length&&(!0!==r._jsonata_function||2!==r.implementation.length)&&2!==r.arguments.length)throw{stack:(new Error).stack,code:"D3050",index:1};var a;for(void 0===t&&e.length>0?(n=e[0],a=1):(n=t,a=0);a<e.length;)n=yield*U(r,[n,e[a]],null),a++;return n}}function Te(e){var r=[];if(Array.isArray(e)){var t={};e.forEach(function(e){var r=Te(e);Array.isArray(r)&&r.forEach(function(e){t[e]=!0})}),r=Te(t)}else null===e||"object"!=typeof e||F(e)?r=void 0:0===(r=Object.keys(e)).length&&(r=void 0);return r}function je(e,r){return p({value:r},e)}function _e(e,r){return void 0===e?r:void 0===r?e:(Array.isArray(e)||(e=[e]),Array.isArray(r)||(r=[r]),Array.prototype.push.apply(e,r),e)}function De(e){return void 0!==e}function Oe(e){var r=[];if(Array.isArray(e))e.forEach(function(e){r=_e(r,Oe(e))});else if(null===e||"object"!=typeof e||F(e))r=e;else for(var t in e){var n={};n[t]=e[t],r.push(n)}return r}function Me(e){if(void 0!==e){if(e.length<=1)return e;for(var r=e.length,t=new Array(r),n=0;n<r;n++)t[r-n-1]=e[n];return t}}function*Ne(e,r){var t=[];for(var n in e){var a=[e[n],n];t.push(yield*U(r,a,null))}return t}function $e(e,r){if(void 0!==e){if(e.length<=1)return e;var a;if(void 0===r){if(!n(e)&&!t(e))throw{stack:(new Error).stack,code:"D3070",index:1};a=function(e,r){return e>r}}else a="function"==typeof r?r:function(e,t){for(var n=U(r,[e,t],null),a=n.next();!a.done;)a=n.next(a.value);return a.value};var i=function(e,r){var t=function(e,r,n){0===r.length?Array.prototype.push.apply(e,n):0===n.length?Array.prototype.push.apply(e,r):a(r[0],n[0])?(e.push(n[0]),t(e,r,n.slice(1))):(e.push(r[0]),t(e,r.slice(1),n))},n=[];return t(n,e,r),n},o=function(e){if(e.length<=1)return e;var r=Math.floor(e.length/2),t=e.slice(0,r),n=e.slice(r);return t=o(t),n=o(n),i(t,n)};return o(e)}}function Fe(e){if(void 0!==e){if(e.length<=1)return e;for(var r=new Array(e.length),t=0;t<e.length;t++){var n=Math.floor(Math.random()*(t+1));t!==n&&(r[t]=r[n]),r[n]=e[t]}return r}}function Ie(e,r){var t={};for(var n in e){var a=e[n];me(function(e,t,n){for(var a=U(r,[e,t,n],null),i=a.next();!i.done;)i=a.next(i.value);return i.value}(a,n,e))&&(t[n]=a)}return 0===Object.keys(t).length&&(t=void 0),t}function Pe(e){var r={};return{bind:function(e,t){r[e]=t},lookup:function(t){var n;return r.hasOwnProperty(t)?n=r[t]:e&&(n=e.lookup(t)),n}}}function Ue(e){var r="Unknown error";void 0!==e.message&&(r=e.message);var t=Be[e.code];return void 0!==t&&(r=t.replace(/\{\{([^}]+)}}/g,function(){return JSON.stringify(e[arguments[1]])})),r}function Ce(e){var r;try{r=ze(e)}catch(e){throw e.message=Ue(e),e}var t=Pe(Ge);return{evaluate:function(e,n,i){if(void 0!==n){var o;o=Pe(t);for(var s in n)o.bind(s,n[s])}else o=t;o.bind("$",e);var u=(new Date).toJSON();o.bind("now",H(function(){return u},"<:s>"));var c,l;if("function"==typeof i){o.bind("__jsonata_async",!0);var f=function(e){(c=l.next(e)).done?i(null,c.value):c.value.then(f).catch(function(e){e.message=Ue(e),i(e,null)})};l=a(r,e,o),(c=l.next()).value.then(f)}else try{for(l=a(r,e,o),c=l.next();!c.done;)c=l.next(c.value);return c.value}catch(e){throw e.message=Ue(e),e}},assign:function(e,r){t.bind(e,r)},registerFunction:function(e,r,n){var a=H(r,n);t.bind(e,a)}}}var qe={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":75,"#":70,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"`":80,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},Re={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},Je=function(e){var r=0,t=e.length,n=function(e,t){return{type:e,value:t,position:r}},a=function(){for(var n,a,i=r,o=0;r<t;){var s=e.charAt(r);if("/"===s&&"\\"!==e.charAt(r-1)&&0===o){if(""===(n=e.substring(i,r)))throw{code:"S0301",stack:(new Error).stack,position:r};for(r++,s=e.charAt(r),i=r;"i"===s||"m"===s;)r++,s=e.charAt(r);return a=e.substring(i,r)+"g",new RegExp(n,a)}"("!==s&&"["!==s&&"{"!==s||"\\"===e.charAt(r-1)||o++,")"!==s&&"]"!==s&&"}"!==s||"\\"===e.charAt(r-1)||o--,r++}throw{code:"S0302",stack:(new Error).stack,position:r}};return function(i){if(r>=t)return null;for(var o=e.charAt(r);r<t&&" \t\n\r\v".indexOf(o)>-1;)r++,o=e.charAt(r);if(!0!==i&&"/"===o)return r++,n("regex",a());if("."===o&&"."===e.charAt(r+1))return r+=2,n("operator","..");if(":"===o&&"="===e.charAt(r+1))return r+=2,n("operator",":=");if("!"===o&&"="===e.charAt(r+1))return r+=2,n("operator","!=");if(">"===o&&"="===e.charAt(r+1))return r+=2,n("operator",">=");if("<"===o&&"="===e.charAt(r+1))return r+=2,n("operator","<=");if("*"===o&&"*"===e.charAt(r+1))return r+=2,n("operator","**");if("~"===o&&">"===e.charAt(r+1))return r+=2,n("operator","~>");if(qe.hasOwnProperty(o))return r++,n("operator",o);if('"'===o||"'"===o){var s=o;r++;for(var u="";r<t;){if("\\"===(o=e.charAt(r)))if(r++,o=e.charAt(r),Re.hasOwnProperty(o))u+=Re[o];else{if("u"!==o)throw{code:"S0103",stack:(new Error).stack,position:r,token:o};var c=e.substr(r+1,4);if(!/^[0-9a-fA-F]+$/.test(c))throw{code:"S0104",stack:(new Error).stack,position:r};var l=parseInt(c,16);u+=String.fromCharCode(l),r+=4}else{if(o===s)return r++,n("string",u);u+=o}r++}throw{code:"S0101",stack:(new Error).stack,position:r}}var f=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/.exec(e.substring(r));if(null!==f){var p=parseFloat(f[0]);if(!isNaN(p)&&isFinite(p))return r+=f[0].length,n("number",p);throw{code:"S0102",stack:(new Error).stack,position:r,token:f[0]}}for(var d,v,h=r;;)if(d=e.charAt(h),h===t||" \t\n\r\v".indexOf(d)>-1||qe.hasOwnProperty(d)){if("$"===e.charAt(r))return v=e.substring(r+1,h),r=h,n("variable",v);switch(v=e.substring(r,h),r=h,v){case"or":case"in":case"and":return n("operator",v);case"true":return n("value",!0);case"false":return n("value",!1);case"null":return n("value",null);default:return r===t&&""===v?null:n("name",v)}}else h++}},ze=function(t){var n,a,i={},o={nud:function(){return this}},s=function(e,r){var t=i[e];return r=r||0,t?r>=t.lbp&&(t.lbp=r):((t=Object.create(o)).id=t.value=e,t.lbp=r,i[e]=t),t},u=function(e,r){if(e&&n.id!==e){var o;throw o="(end)"===n.id?"S0203":"S0202",{code:o,stack:(new Error).stack,position:n.position,token:n.id,value:e}}var s=a(r);if(null===s)return n=i["(end)"],n.position=t.length,n;var u,c=s.value,l=s.type;switch(l){case"name":case"variable":u=i["(name)"];break;case"operator":if(!(u=i[c]))throw{code:"S0204",stack:(new Error).stack,position:s.position,token:c};break;case"string":case"number":case"value":l="literal",u=i["(literal)"];break;case"regex":l="regex",u=i["(regex)"];break;default:throw{code:"S0205",stack:(new Error).stack,position:s.position,token:c}}return n=Object.create(u),n.value=c,n.type=l,n.position=s.position,n},c=function(e){var r,t=n;for(u(null,!0),r=t.nud();e<n.lbp;)t=n,u(),r=t.led(r);return r},l=function(e,r,t){var n=r||qe[e],a=s(e,n);return a.led=t||function(e){return this.lhs=e,this.rhs=c(n),this.type="binary",this},a},f=function(e,r){var t=s(e);return t.nud=r||function(){return this.expression=c(70),this.type="unary",this},t};s("(end)"),s("(name)"),s("(literal)"),s("(regex)"),s(":"),s(";"),s(","),s(")"),s("]"),s("}"),s(".."),l("."),l("+"),l("-"),l("*"),l("/"),l("%"),l("="),l("<"),l(">"),l("!="),l("<="),l(">="),l("&"),l("and"),l("or"),l("in"),function(e,r,t){var n=r||qe[e],a=s(e,n);a.led=t||function(e){return this.lhs=e,this.rhs=c(n-1),this.type="binary",this}}(":="),f("-"),l("~>"),f("*",function(){return this.type="wildcard",this}),f("**",function(){return this.type="descendant",this}),l("(",qe["("],function(r){if(this.procedure=r,this.type="function",this.arguments=[],")"!==n.id)for(;"operator"===n.type&&"?"===n.id?(this.type="partial",this.arguments.push(n),u("?")):this.arguments.push(c(0)),","===n.id;)u(",");if(u(")",!0),"name"===r.type&&("function"===r.value||"λ"===r.value)){if(this.arguments.forEach(function(e,r){if("variable"!==e.type)throw{code:"S0208",stack:(new Error).stack,position:e.position,token:e.value,value:r+1}}),this.type="lambda","<"===n.id){for(var t=n.position,a=1,i="<";a>0&&"{"!==n.id&&"(end)"!==n.id;){var o=u();">"===o.id?a--:"<"===o.id&&a++,i+=o.value}u(">");try{this.signature=e(i)}catch(e){throw e.position=t+e.offset,e}}u("{"),this.body=c(0),u("}")}return this}),f("(",function(){for(var e=[];")"!==n.id&&(e.push(c(0)),";"===n.id);)u(";");return u(")",!0),this.type="block",this.expressions=e,this}),f("[",function(){var e=[];if("]"!==n.id)for(;;){var r=c(0);if(".."===n.id){var t={type:"binary",value:"..",position:n.position,lhs:r};u(".."),t.rhs=c(0),r=t}if(e.push(r),","!==n.id)break;u(",")}return u("]",!0),this.lhs=e,this.type="unary",this}),l("[",qe["["],function(e){if("]"===n.id){for(var r=e;r&&"binary"===r.type&&"["===r.value;)r=r.lhs;return r.keepArray=!0,u("]"),e}return this.lhs=e,this.rhs=c(qe["]"]),this.type="binary",u("]",!0),this}),l("^",qe["^"],function(e){u("(");for(var r=[];;){var t={descending:!1};if("<"===n.id?u("<"):">"===n.id&&(t.descending=!0,u(">")),t.expression=c(0),r.push(t),","!==n.id)break;u(",")}return u(")"),this.lhs=e,this.rhs=r,this.type="binary",this});var p=function(e){var r=[];if("}"!==n.id)for(;;){var t=c(0);u(":");var a=c(0);if(r.push([t,a]),","!==n.id)break;u(",")}return u("}",!0),void 0===e?(this.lhs=r,this.type="unary"):(this.lhs=e,this.rhs=r,this.type="binary"),this};f("{",p),l("{",qe["{"],p),l("?",qe["?"],function(e){return this.type="condition",this.condition=e,this.then=c(0),":"===n.id&&(u(":"),this.else=c(0)),this});var d=function(e){var r;if("function"===e.type){var t={type:"lambda",thunk:!0,arguments:[],position:e.position};t.body=e,r=t}else if("condition"===e.type)e.then=d(e.then),void 0!==e.else&&(e.else=d(e.else)),r=e;else if("block"===e.type){var n=e.expressions.length;n>0&&(e.expressions[n-1]=d(e.expressions[n-1])),r=e}else r=e;return r},v=function(e){var t;switch(e.type){case"binary":switch(e.value){case".":var n=v(e.lhs);t={type:"path",steps:[]},"path"===n.type?Array.prototype.push.apply(t.steps,n.steps):t.steps=[n];var a=v(e.rhs);"path"!==a.type&&(a={type:"path",steps:[a]}),Array.prototype.push.apply(t.steps,a.steps),t.steps.filter(function(e){return"literal"===e.type}).forEach(function(e){e.type="name"}),t.steps.filter(function(e){return!0===e.keepArray}).length>0&&(t.keepSingletonArray=!0),"unary"===t.steps[0].type&&"["===t.steps[0].value&&(t.steps[0].consarray=!0);break;case"[":var i=t=v(e.lhs);if("path"===t.type&&(i=t.steps[t.steps.length-1]),void 0!==i.group)throw{code:"S0209",stack:(new Error).stack,position:e.position};void 0===i.predicate&&(i.predicate=[]),i.predicate.push(v(e.rhs));break;case"{":if(void 0!==(t=v(e.lhs)).group)throw{code:"S0210",stack:(new Error).stack,position:e.position};t.group={lhs:e.rhs.map(function(e){return[v(e[0]),v(e[1])]}),position:e.position};break;case"^":(t={type:"sort",value:e.value,position:e.position}).lhs=v(e.lhs),t.rhs=e.rhs.map(function(e){return{descending:e.descending,expression:v(e.expression)}});break;case":=":(t={type:"bind",value:e.value,position:e.position}).lhs=v(e.lhs),t.rhs=v(e.rhs);break;case"~>":(t={type:"apply",value:e.value,position:e.position}).lhs=v(e.lhs),t.rhs=v(e.rhs);break;default:(t={type:e.type,value:e.value,position:e.position}).lhs=v(e.lhs),t.rhs=v(e.rhs)}break;case"unary":t={type:e.type,value:e.value,position:e.position},"["===e.value?t.lhs=e.lhs.map(function(e){return v(e)}):"{"===e.value?t.lhs=e.lhs.map(function(e){return[v(e[0]),v(e[1])]}):(t.expression=v(e.expression),"-"===e.value&&"literal"===t.expression.type&&r(t.expression.value)&&((t=t.expression).value=-t.value));break;case"function":case"partial":(t={type:e.type,name:e.name,value:e.value,position:e.position}).arguments=e.arguments.map(function(e){return v(e)}),t.procedure=v(e.procedure);break;case"lambda":t={type:e.type,arguments:e.arguments,signature:e.signature,position:e.position};var o=v(e.body);t.body=d(o);break;case"condition":(t={type:e.type,position:e.position}).condition=v(e.condition),t.then=v(e.then),void 0!==e.else&&(t.else=v(e.else));break;case"block":(t={type:e.type,position:e.position}).expressions=e.expressions.map(function(e){return v(e)});break;case"name":t={type:"path",steps:[e]},e.keepArray&&(t.keepSingletonArray=!0);break;case"literal":case"wildcard":case"descendant":case"variable":case"regex":t=e;break;case"operator":if("and"===e.value||"or"===e.value||"in"===e.value)e.type="name",t=v(e);else{if("?"!==e.value)throw{code:"S0201",stack:(new Error).stack,position:e.position,token:e.value};t=e}break;default:var s="S0206";throw"(end)"===e.id&&(s="S0207"),{code:s,stack:(new Error).stack,position:e.position,token:e.value}}return t};a=Je(t),u();var h=c(0);if("(end)"!==n.id)throw{code:"S0201",stack:(new Error).stack,position:n.position,token:n.value};return h=v(h)},Ge=Pe(null);Number.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e};var Le=M(ze("function($f, $g) { function($x){ $g($f($x)) } }"),null,Ge);Ge.bind("sum",H(Q,"<a<n>:n>")),Ge.bind("count",H(V,"<a:n>")),Ge.bind("max",H(W,"<a<n>:n>")),Ge.bind("min",H(X,"<a<n>:n>")),Ge.bind("average",H(Y,"<a<n>:n>")),Ge.bind("string",H(Z,"<x-:s>")),Ge.bind("substring",H(ee,"<s-nn?:s>")),Ge.bind("substringBefore",H(re,"<s-s:s>")),Ge.bind("substringAfter",H(te,"<s-s:s>")),Ge.bind("lowercase",H(ne,"<s-:s>")),Ge.bind("uppercase",H(ae,"<s-:s>")),Ge.bind("length",H(ie,"<s-:n>")),Ge.bind("trim",H(oe,"<s-:s>")),Ge.bind("match",H(ue,"<s-f<s:o>n?:a<o>>")),Ge.bind("contains",H(se,"<s-(sf):b>")),Ge.bind("replace",H(ce,"<s-(sf)(sf)n?:s>")),Ge.bind("split",H(le,"<s-(sf)n?:a<s>>")),Ge.bind("join",H(fe,"<a<s>s?:s>")),Ge.bind("number",H(pe,"<(ns)-:n>")),Ge.bind("floor",H(ve,"<n-:n>")),Ge.bind("ceil",H(he,"<n-:n>")),Ge.bind("round",H(ye,"<n-n?:n>")),Ge.bind("abs",H(de,"<n-:n>")),Ge.bind("sqrt",H(be,"<n-:n>")),Ge.bind("power",H(ge,"<n-n:n>")),Ge.bind("random",H(ke,"<:n>")),Ge.bind("boolean",H(me,"<x-:b>")),Ge.bind("not",H(we,"<x-:b>")),Ge.bind("map",H(xe,"<af>")),Ge.bind("zip",H(Ee,"<a+>")),Ge.bind("filter",H(Ae,"<af>")),Ge.bind("reduce",H(Se,"<afj?:j>")),Ge.bind("sift",H(Ie,"<o-f?:o>")),Ge.bind("keys",H(Te,"<x-:a<s>>")),Ge.bind("lookup",H(je,"<x-s:x>")),Ge.bind("append",H(_e,"<xx:a>")),Ge.bind("exists",H(De,"<x:b>")),Ge.bind("spread",H(Oe,"<x-:a<o>>")),Ge.bind("reverse",H(Me,"<a:a>")),Ge.bind("each",H(Ne,"<o-f:a>")),Ge.bind("sort",H($e,"<af?:a>")),Ge.bind("shuffle",H(Fe,"<a:a>"));var Be={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",S0203:"Expected '{{value}}' before end of expression",S0202:"Expected '{{value}}', got '{{token}}'",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",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",S0201:"Syntax error: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Unexpected end of 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",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}}",T2001:"The left side of the {{token}} operator must evaluate to a number",T2002:"The right side of the {{token}} operator must evaluate to a number",T1003:"Key in object structure must evaluate to a string; got: {{value}}",T2003:"The left side of the range operator (..) must evaluate to an integer",T2004:"The right side of the range operator (..) must evaluate to an integer",D2005:"The left side of := must be a variable name (start with $)",D1004:"Regular expression matches zero length string",T2006:"The right side of the function application operator ~> must be a function",T2007:"Type mismatch when comparing values {{value}} and {{value2}} in order-by clause",T2008:"The expressions within an order-by clause must evaluate to numeric or string values",T2009:"The values {{value}} and {{value2}} either side of operator {{token}} must be of the same data type",T2010:"The expressions either side of operator {{token}} must evaluate to numeric or string values",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",D3001:"Attempting to invoke string function on Infinity or NaN",D3010:"Second argument of replace function cannot be an empty string",D3011:"Fourth argument of replace function must evaluate to a positive number",D3012:"Attempted to replace a matched string with a non-string value",D3020:"Third argument of split function must evaluate to a positive number",D3030:"Unable to cast value to a number: {{value}}",D3040:"Third argument of match function must evaluate to a positive number",D3050:"First argument of reduce function must be a function with two arguments",D3060:"The sqrt function cannot be applied to a negative number: {{value}}",D3061:"The power function has resulted in a value that cannot be represented as a JSON number: base={{value}}, exponent={{exp}}",D3070:"The single argument form of the sort function can only be applied to an array of strings or an array of numbers. Use the second argument to specify a comparison function"};return Ce.parser=ze,Ce}();"undefined"!=typeof module&&(module.exports=jsonata);
{
"name": "jsonata",
"version": "1.1.1",
"version": "1.2.0",
"description": "JSON query and transformation language",

@@ -34,2 +34,3 @@ "main": "jsonata.js",

"chai": "^3.4.1",
"chai-as-promised": "^6.0.0",
"coveralls": "^2.11.14",

@@ -42,7 +43,8 @@ "eslint": "^2.0.0",

"mocha-lcov-reporter": "^1.2.0",
"uglify-js": "^2.7.5"
"request": "^2.81.0",
"uglify-es": "^3.0.4"
},
"engines": {
"node": ">= 0.10"
"node": ">= 4.4"
}
}
# JSONata
<div>
<a href="https://nodei.co/npm/jsonata/"><img src="https://nodei.co/npm/jsonata.png?downloads=true&downloadRank=true"></a>
</div>
[![Build Status](https://travis-ci.org/jsonata-js/jsonata.svg)](https://travis-ci.org/jsonata-js/jsonata)

@@ -82,3 +86,3 @@ [![Coverage Status](https://coveralls.io/repos/github/jsonata-js/jsonata/badge.svg?branch=master)](https://coveralls.io/github/jsonata-js/jsonata?branch=master)

If an expression throws an error, e.g. syntax error or a runtime error (type error), then the object thrown
has a consistent structure containing the column number of the error, the token that caused the error,
has a consistent structure containing the error code, column number of the error, the token that caused the error,
and any other relevant information, including a meaningful message string.

@@ -88,3 +92,11 @@

`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}'" }`
```
{
"code": "S0202",
"position": 16,
"token": "}",
"value": "]",
"message": "Syntax error: expected ']' got '}'"
}
```

@@ -91,0 +103,0 @@ ## More Information

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc