UNPKG

jexl-extended

Version:

Extended grammar for Javascript Expression Language (JEXL)

1,010 lines 77.5 kB
[ { "type": "Function", "name": "string", "description": "Casts the input to a string.", "args": "input, prettify", "returns": "string", "code": "(input,prettify=false)=>{return JSON.stringify(input,null,prettify?2:0)}" }, { "type": "Function", "name": "json", "description": "Parses the string and returns a JSON object.", "args": "input", "returns": "any", "code": "input=>{return JSON.parse(input)}" }, { "type": "Function", "name": "parseJson", "description": "Parses the string and returns a JSON object.", "args": "input", "returns": "any", "code": "input=>{return JSON.parse(input)}" }, { "type": "Function", "name": "length", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Function", "name": "count", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Function", "name": "size", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Function", "name": "substring", "description": "Gets a substring of a string.", "args": "input, start, length", "returns": "string", "code": "(input,start,length2)=>{let str=input;if(typeof str!==\"string\"){str=JSON.stringify(str)}if(typeof str===\"string\"){let startNum=start;let len=length2??str.length;if(startNum<0){startNum=str.length+start;if(startNum<0){startNum=0}}if(startNum+len>str.length){len=str.length-startNum}if(len<0){len=0}return str.substring(startNum,startNum+len)}return\"\"}" }, { "type": "Function", "name": "substringBefore", "description": "Returns the substring before the first occurrence of the character sequence chars in str.", "args": "input, chars", "returns": "string", "code": "(input,chars)=>{const str=typeof input===\"string\"?input:JSON.stringify(input);const charsStr=typeof chars===\"string\"?chars:JSON.stringify(chars);const index=str.indexOf(charsStr);if(index===-1){return str}return str.substring(0,index)}" }, { "type": "Function", "name": "substringAfter", "description": "Returns the substring after the first occurrence of the character sequence chars in str.", "args": "input, chars", "returns": "string", "code": "(input,chars)=>{const str=typeof input===\"string\"?input:JSON.stringify(input);const charsStr=typeof chars===\"string\"?chars:JSON.stringify(chars);const index=str.indexOf(charsStr);if(index===-1){return\"\"}return str.substring(index+charsStr.length)}" }, { "type": "Function", "name": "uppercase", "description": "Converts the input string to uppercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toUpperCase()}" }, { "type": "Function", "name": "upper", "description": "Converts the input string to uppercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toUpperCase()}" }, { "type": "Function", "name": "lowercase", "description": "Converts the input string to lowercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toLowerCase()}" }, { "type": "Function", "name": "lower", "description": "Converts the input string to lowercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toLowerCase()}" }, { "type": "Function", "name": "camelCase", "description": "Converts the input string to camel case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map((word,index)=>{if(index===0)return word.toLowerCase();return word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()}).join(\"\")}" }, { "type": "Function", "name": "pascalCase", "description": "Converts the input string to pascal case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()).join(\"\")}" }, { "type": "Function", "name": "trim", "description": "Trims whitespace from both ends of a string.", "args": "input, trimChar", "returns": "string", "code": "(input,trimChar)=>{if(typeof input===\"string\"){if(trimChar){return input.replace(new RegExp(`^${trimChar}+|${trimChar}+$`,\"g\"),\"\")}return input.trim()}return\"\"}" }, { "type": "Function", "name": "pad", "description": "Pads the input string to the specified width.", "args": "input, width, char", "returns": "string", "code": "(input,width,char=\" \")=>{const str=typeof input!==\"string\"?JSON.stringify(input):input;if(width>0){return str.padEnd(width,char)}else{return str.padStart(-width,char)}}" }, { "type": "Function", "name": "contains", "description": "Checks if the input string or array contains the specified value.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"||Array.isArray(input)){return input.includes(search)}return false}" }, { "type": "Function", "name": "includes", "description": "Checks if the input string or array contains the specified value.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"||Array.isArray(input)){return input.includes(search)}return false}" }, { "type": "Function", "name": "startsWith", "description": "Checks if the input string starts with the specified substring.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"){return input.startsWith(search)}return false}" }, { "type": "Function", "name": "endsWith", "description": "Checks if the input string ends with the specified substring.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"){return input.endsWith(search)}return false}" }, { "type": "Function", "name": "split", "description": "Splits the input string into an array of substrings.", "args": "input, separator", "returns": "array", "code": "(input,separator)=>{if(typeof input===\"string\"){return input.split(separator)}return[]}" }, { "type": "Function", "name": "join", "description": "Joins elements of an array into a string.", "args": "input, separator", "returns": "string", "code": "(input,separator)=>{if(Array.isArray(input)){return input.join(separator)}return void 0}" }, { "type": "Function", "name": "replace", "description": "Replaces occurrences of a specified string with a replacement string.", "args": "input, search, replacement", "returns": "string", "code": "(input,search,replacement)=>{if(typeof input===\"string\"&&typeof search===\"string\"){const _replacement=replacement===void 0?\"\":replacement;return input.replace(new RegExp(search,\"g\"),_replacement)}return void 0}" }, { "type": "Function", "name": "base64Encode", "description": "Encodes a string to Base64.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){try{encodeURIComponent(input);const bytes=new TextEncoder().encode(input);const binString=String.fromCodePoint(...bytes);return btoa(binString)}catch(error){return\"\"}}return\"\"}" }, { "type": "Function", "name": "base64Decode", "description": "Decodes a Base64 encoded string.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){const binString=atob(input);const bytes=Uint8Array.from(binString,m=>m.codePointAt(0));return new TextDecoder().decode(bytes)}return\"\"}" }, { "type": "Function", "name": "formUrlEncoded", "description": "Encodes a string or object to URI component format.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){return encodeURIComponent(input)}else if(typeof input===\"object\"){return Object.keys(input).map(key=>`${encodeURIComponent(key)}=${encodeURIComponent(input[key])}`).join(\"&\")}return\"\"}" }, { "type": "Function", "name": "number", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Function", "name": "parseFloat", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Function", "name": "abs", "description": "Returns the absolute value of a number.", "args": "input", "returns": "number", "code": "input=>{const num=toNumber(input);return isNaN(num)?NaN:Math.abs(num)}" }, { "type": "Function", "name": "floor", "description": "Rounds a number down to the nearest integer.", "args": "input", "returns": "number", "code": "input=>{const num=toNumber(input);return isNaN(num)?NaN:Math.floor(num)}" }, { "type": "Function", "name": "ceil", "description": "Rounds a number up to the nearest integer.", "args": "input", "returns": "number", "code": "input=>{const num=toNumber(input);return isNaN(num)?NaN:Math.ceil(num)}" }, { "type": "Function", "name": "round", "description": "Rounds a number to the nearest integer or to specified decimal places.", "args": "input, decimals", "returns": "number", "code": "(input,decimals)=>{const num=toNumber(input);return isNaN(num)?NaN:decimals?Math.round(num*Math.pow(10,decimals))/Math.pow(10,decimals):Math.round(num)}" }, { "type": "Function", "name": "power", "description": "Returns the value of a number raised to a power.", "args": "input, exponent", "returns": "number", "code": "(input,exponent)=>{const num=toNumber(input);const exp=exponent===void 0?2:exponent;return isNaN(num)?NaN:Math.pow(num,exp)}" }, { "type": "Function", "name": "sqrt", "description": "Returns the square root of a number.", "args": "input", "returns": "number", "code": "input=>{const num=toNumber(input);return isNaN(num)?NaN:Math.sqrt(num)}" }, { "type": "Function", "name": "random", "description": "Generates a random number between 0 (inclusive) and 1 (exclusive).", "returns": "number", "code": "()=>{return Math.random()}" }, { "type": "Function", "name": "formatNumber", "description": "Formats a number to a decimal representation as specified by the format string.", "args": "input, format", "returns": "string", "code": "(input,format)=>{const num=typeof input===\"number\"?input:parseInt(toNumber(input).toString(),10);return isNaN(num)?\"\":num.toLocaleString(\"en-us\",{minimumFractionDigits:format.split(\".\")[1]?.length,maximumFractionDigits:format.split(\".\")[1]?.length,useGrouping:format.split(\".\")[0]?.includes(\",\")})}" }, { "type": "Function", "name": "formatBase", "description": "Formats a number as a string in the specified base.", "args": "input, base", "returns": "string", "code": "(input,base)=>{const num=typeof input===\"number\"?input:parseInt(toNumber(input).toString(),10);return isNaN(num)?\"\":num.toString(base)}" }, { "type": "Function", "name": "formatInteger", "description": "Formats a number as an integer with zero padding.", "args": "input, format", "returns": "string", "code": "(input,format)=>{const num=toNumber(input);return isNaN(num)?\"\":pad(Math.floor(num).toString(),-format.length,\"0\")}" }, { "type": "Function", "name": "parseInteger", "description": "Parses a string and returns an integer.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return parseInt(input,10)}else if(typeof input===\"number\"){return Math.floor(input)}return NaN}" }, { "type": "Function", "name": "parseInt", "description": "Parses a string and returns an integer.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return parseInt(input,10)}else if(typeof input===\"number\"){return Math.floor(input)}return NaN}" }, { "type": "Function", "name": "sum", "description": "Calculates the sum of an array of numbers.", "args": "input", "returns": "number", "code": "(...input)=>{if(!Array.isArray(input))return NaN;return input.flat().reduce((acc,val)=>acc+toNumber(val),0)}" }, { "type": "Function", "name": "max", "description": "Finds the maximum value in an array of numbers.", "args": "input", "returns": "number", "code": "(...input)=>{if(!Array.isArray(input))return NaN;return Math.max(...input.flat().map(toNumber))}" }, { "type": "Function", "name": "min", "description": "Finds the minimum value in an array of numbers.", "args": "input", "returns": "number", "code": "(...input)=>{if(!Array.isArray(input))return NaN;return Math.min(...input.flat().map(toNumber))}" }, { "type": "Function", "name": "average", "description": "Calculates the average of an array of numbers.", "args": "input", "returns": "number", "code": "(...input)=>{if(!Array.isArray(input))return NaN;const total=sum(...input);return total/input.flat().length}" }, { "type": "Function", "name": "avg", "description": "Calculates the average of an array of numbers.", "args": "input", "returns": "number", "code": "(...input)=>{if(!Array.isArray(input))return NaN;const total=sum(...input);return total/input.flat().length}" }, { "type": "Function", "name": "boolean", "description": "Converts the input to a boolean.", "args": "input", "returns": "boolean", "code": "input=>{if(typeof input===\"boolean\")return input;if(typeof input===\"number\")return input!==0;if(typeof input===\"string\"){if(input.trim().toLowerCase()===\"true\"||input.trim()===\"1\")return true;if(input.trim().toLowerCase()===\"false\"||input.trim()===\"0\")return false;else return void 0}return Boolean(input)}" }, { "type": "Function", "name": "bool", "description": "Converts the input to a boolean.", "args": "input", "returns": "boolean", "code": "input=>{if(typeof input===\"boolean\")return input;if(typeof input===\"number\")return input!==0;if(typeof input===\"string\"){if(input.trim().toLowerCase()===\"true\"||input.trim()===\"1\")return true;if(input.trim().toLowerCase()===\"false\"||input.trim()===\"0\")return false;else return void 0}return Boolean(input)}" }, { "type": "Function", "name": "not", "description": "Returns the logical NOT of the input.", "args": "input", "returns": "boolean", "code": "input=>{return!toBoolean(input)}" }, { "type": "Function", "name": "case", "description": "Evaluates a list of predicates and returns the first result expression whose predicate is satisfied.", "args": "args", "returns": "unknown", "code": "(...args)=>{if(args.length<3)return null;const expressionResult=args[0];for(let i=1;i<args.length-1;i+=2){const caseResult=args[i];if(JSON.stringify(expressionResult)===JSON.stringify(caseResult)){return args[i+1]}}if(args.length%2===0){const defaultResult=args[args.length-1];return defaultResult}return null}" }, { "type": "Function", "name": "switch", "description": "Evaluates a list of predicates and returns the first result expression whose predicate is satisfied.", "args": "args", "returns": "unknown", "code": "(...args)=>{if(args.length<3)return null;const expressionResult=args[0];for(let i=1;i<args.length-1;i+=2){const caseResult=args[i];if(JSON.stringify(expressionResult)===JSON.stringify(caseResult)){return args[i+1]}}if(args.length%2===0){const defaultResult=args[args.length-1];return defaultResult}return null}" }, { "type": "Function", "name": "range", "description": "Returns a sub-array from start index to end index.", "args": "array, start, end", "returns": "array", "code": "(array,start,end)=>{if(!Array.isArray(array))return[];return array.slice(start,end)}" }, { "type": "Function", "name": "append", "description": "Appends elements to an array.", "args": "input", "returns": "array", "code": "(...input)=>{if(!Array.isArray(input))return[];return[...input.flat()]}" }, { "type": "Function", "name": "concat", "description": "Appends elements to an array.", "args": "input", "returns": "array", "code": "(...input)=>{if(!Array.isArray(input))return[];return[...input.flat()]}" }, { "type": "Function", "name": "reverse", "description": "Reverses the elements of an array.", "args": "input", "returns": "array", "code": "(...input)=>{if(!Array.isArray(input))return[];return[...input.flat()].reverse()}" }, { "type": "Function", "name": "shuffle", "description": "Shuffles the elements of an array randomly.", "args": "input", "returns": "array", "code": "input=>{if(!Array.isArray(input))return[];for(let i=input.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[input[i],input[j]]=[input[j],input[i]]}return input}" }, { "type": "Function", "name": "sort", "description": "Sorts the elements of an array.", "args": "input, expression, descending", "returns": "array", "code": "(input,expression,descending)=>{if(!Array.isArray(input))return[];if(!expression)return[...input].sort();const expr=import__.default.compile(expression);const compareFunction=__name((a,b)=>{const aValue=expr.evalSync(a);const bValue=expr.evalSync(b);if(aValue<bValue)return descending?-1:1;if(aValue>bValue)return descending?1:-1;return 0},\"compareFunction\");return[...input].sort(compareFunction)}" }, { "type": "Function", "name": "order", "description": "Sorts the elements of an array.", "args": "input, expression, descending", "returns": "array", "code": "(input,expression,descending)=>{if(!Array.isArray(input))return[];if(!expression)return[...input].sort();const expr=import__.default.compile(expression);const compareFunction=__name((a,b)=>{const aValue=expr.evalSync(a);const bValue=expr.evalSync(b);if(aValue<bValue)return descending?-1:1;if(aValue>bValue)return descending?1:-1;return 0},\"compareFunction\");return[...input].sort(compareFunction)}" }, { "type": "Function", "name": "distinct", "description": "Returns a new array with duplicate elements removed.", "args": "input", "returns": "array", "code": "input=>{if(!Array.isArray(input))return[];return[...new Set(input)]}" }, { "type": "Function", "name": "toObject", "description": "Creates a new object based on key-value pairs or string keys.", "args": "input, val", "returns": "any", "code": "(input,val)=>{if(typeof input===\"string\")return{[input]:val};if(!Array.isArray(input))return{};return input.reduce((acc,kv)=>{if(Array.isArray(kv)&&kv.length===2){acc[kv[0]]=kv[1];return acc}else if(typeof kv===\"string\"){acc[kv]=val;return acc}return acc},{})}" }, { "type": "Function", "name": "fromEntries", "description": "Creates a new object based on key-value pairs or string keys.", "args": "input, val", "returns": "any", "code": "(input,val)=>{if(typeof input===\"string\")return{[input]:val};if(!Array.isArray(input))return{};return input.reduce((acc,kv)=>{if(Array.isArray(kv)&&kv.length===2){acc[kv[0]]=kv[1];return acc}else if(typeof kv===\"string\"){acc[kv]=val;return acc}return acc},{})}" }, { "type": "Function", "name": "mapField", "description": "Returns a new array with elements transformed by extracting a specific field.", "args": "input, field", "returns": "array", "code": "(input,field)=>{if(!Array.isArray(input))return[];return input.map(item=>item[field])}" }, { "type": "Function", "name": "map", "description": "Returns an array containing the results of applying the expression parameter to each value in the array parameter.\nThe expression must be a valid JEXL expression string, which is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "array", "code": "(input,expression)=>{if(!Array.isArray(input))return void 0;const expr=import__.default.compile(expression);return input.map((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "any", "description": "Checks whether the provided array has any elements that match the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "boolean", "code": "(input,expression)=>{if(!Array.isArray(input))return false;const expr=import__.default.compile(expression);return input.some((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "some", "description": "Checks whether the provided array has any elements that match the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "boolean", "code": "(input,expression)=>{if(!Array.isArray(input))return false;const expr=import__.default.compile(expression);return input.some((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "all", "description": "Checks whether the provided array has all elements that match the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "boolean", "code": "(input,expression)=>{if(!Array.isArray(input))return false;const expr=import__.default.compile(expression);return input.every((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "every", "description": "Checks whether the provided array has all elements that match the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "boolean", "code": "(input,expression)=>{if(!Array.isArray(input))return false;const expr=import__.default.compile(expression);return input.every((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "filter", "description": "Returns a new array with the elements of the input array that match the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "array", "code": "(input,expression)=>{if(!Array.isArray(input))return[];const expr=import__.default.compile(expression);return input.filter((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "find", "description": "Finds the first element in an array that matches the specified expression.\nThe expression must be a valid JEXL expression string, and is applied to each element of the array.\nThe relative context provided to the expression is an object with the properties value, index and array (the original array).", "args": "input, expression", "returns": "unknown", "code": "(input,expression)=>{if(!Array.isArray(input))return void 0;const expr=import__.default.compile(expression);return input.find((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "findIndex", "description": "Finds the index of the first element in the input array that satisfies the given Jexl expression.", "args": "input, expression", "returns": "number", "code": "(input,expression)=>{if(!Array.isArray(input))return void 0;const expr=import__.default.compile(expression);return input.findIndex((value,index,array)=>{return expr.evalSync({value,index,array})})}" }, { "type": "Function", "name": "reduce", "description": "Returns an aggregated value derived from applying the function parameter successively to each value in array in combination with the result of the previous application of the function.\nThe expression must be a valid JEXL expression string, and behaves like an infix operator between each value within the array.\nThe relative context provided to the expression is an object with the properties accumulator, value, index and array (the original array).", "args": "input, expression, initialValue", "returns": "unknown", "code": "(input,expression,initialValue)=>{if(!Array.isArray(input))return void 0;const expr=import__.default.compile(expression);return input.reduce((accumulator,value,index,array)=>{return expr.evalSync({accumulator,value,index,array})},initialValue)}" }, { "type": "Function", "name": "keys", "description": "Returns the keys of an object as an array.", "args": "input", "returns": "array", "code": "input=>{if(typeof input===\"object\"&&input!==null){return Object.keys(input)}return void 0}" }, { "type": "Function", "name": "values", "description": "Returns the values of an object as an array.", "args": "input", "returns": "array", "code": "input=>{if(typeof input===\"object\"&&input!==null){return Object.values(input)}return void 0}" }, { "type": "Function", "name": "entries", "description": "Returns an array of key-value pairs from the input object.", "args": "input", "returns": "array", "code": "input=>{if(typeof input===\"object\"&&input!==null){return Object.entries(input)}return void 0}" }, { "type": "Function", "name": "merge", "description": "Returns a new object with the properties of the input objects merged together.", "args": "args", "returns": "Record", "code": "(...args)=>{return args.reduce((acc,obj)=>{if(!Array.isArray(obj)&&typeof obj===\"object\"&&obj!==null){return{...acc,...obj}}if(Array.isArray(obj)){for(const item of obj){if(typeof item===\"object\"&&item!==null){acc={...acc,...item}}}}return acc},{})}" }, { "type": "Function", "name": "now", "description": "Returns the current date and time in the ISO 8601 format.", "returns": "string", "code": "()=>{return new Date().toISOString()}" }, { "type": "Function", "name": "millis", "description": "Returns the current date and time in milliseconds since the Unix epoch.", "returns": "number", "code": "()=>{return Date.now()}" }, { "type": "Function", "name": "millisToDateTime", "description": "Parses the number of milliseconds since the Unix epoch or parses a string (with or without specified format) and returns the date and time in the ISO 8601 format.", "args": "input, format", "returns": "string", "code": "(input,format)=>{if(typeof input===\"number\"){return new Date(input).toISOString()}if(typeof input===\"string\"){if(format){const _format=format.includes(\"x\")||format.includes(\"X\")?format:`${format} X`;const _input=format.includes(\"x\")||format.includes(\"X\")?input:`${input} Z`;return(0,import_date_fns.parse)(_input,_format,new Date).toISOString()}return new Date(input).toISOString()}if(input===void 0){return new Date().toISOString()}return void 0}" }, { "type": "Function", "name": "fromMillis", "description": "Parses the number of milliseconds since the Unix epoch or parses a string (with or without specified format) and returns the date and time in the ISO 8601 format.", "args": "input, format", "returns": "string", "code": "(input,format)=>{if(typeof input===\"number\"){return new Date(input).toISOString()}if(typeof input===\"string\"){if(format){const _format=format.includes(\"x\")||format.includes(\"X\")?format:`${format} X`;const _input=format.includes(\"x\")||format.includes(\"X\")?input:`${input} Z`;return(0,import_date_fns.parse)(_input,_format,new Date).toISOString()}return new Date(input).toISOString()}if(input===void 0){return new Date().toISOString()}return void 0}" }, { "type": "Function", "name": "toDateTime", "description": "Parses the number of milliseconds since the Unix epoch or parses a string (with or without specified format) and returns the date and time in the ISO 8601 format.", "args": "input, format", "returns": "string", "code": "(input,format)=>{if(typeof input===\"number\"){return new Date(input).toISOString()}if(typeof input===\"string\"){if(format){const _format=format.includes(\"x\")||format.includes(\"X\")?format:`${format} X`;const _input=format.includes(\"x\")||format.includes(\"X\")?input:`${input} Z`;return(0,import_date_fns.parse)(_input,_format,new Date).toISOString()}return new Date(input).toISOString()}if(input===void 0){return new Date().toISOString()}return void 0}" }, { "type": "Function", "name": "dateTimeString", "description": "Parses the number of milliseconds since the Unix epoch or parses a string (with or without specified format) and returns the date and time in the ISO 8601 format.", "args": "input, format", "returns": "string", "code": "(input,format)=>{if(typeof input===\"number\"){return new Date(input).toISOString()}if(typeof input===\"string\"){if(format){const _format=format.includes(\"x\")||format.includes(\"X\")?format:`${format} X`;const _input=format.includes(\"x\")||format.includes(\"X\")?input:`${input} Z`;return(0,import_date_fns.parse)(_input,_format,new Date).toISOString()}return new Date(input).toISOString()}if(input===void 0){return new Date().toISOString()}return void 0}" }, { "type": "Function", "name": "dateTimeToMillis", "description": "Parses the date and time in the ISO 8601 format and returns the number of milliseconds since the Unix epoch.", "args": "input", "returns": "number", "code": "input=>{return new Date(input).getTime()}" }, { "type": "Function", "name": "toMillis", "description": "Parses the date and time in the ISO 8601 format and returns the number of milliseconds since the Unix epoch.", "args": "input", "returns": "number", "code": "input=>{return new Date(input).getTime()}" }, { "type": "Function", "name": "dateTimeFormat", "description": "Converts a date and time to a provided format.", "args": "input, format", "returns": "string", "code": "(input,format)=>{let dateTime;if(typeof input===\"string\"){dateTime=new Date(input)}else if(typeof input===\"number\"){dateTime=new Date(input)}else{return null}const utcDateTime=new Date(dateTime.getTime()+dateTime.getTimezoneOffset()*6e4);return(0,import_date_fns.format)(utcDateTime,format)}" }, { "type": "Function", "name": "dateTimeAdd", "description": "Adds a time range to a date and time in the ISO 8601 format.", "args": "input, unit, value", "returns": "string", "code": "(input,unit,value)=>{const _unit=unit.toLowerCase().endsWith(\"s\")?unit.toLowerCase():`${unit.toLowerCase()}s`;const returnDate=(0,import_date_fns.add)(new Date(input),{[_unit]:value});return returnDate.toISOString()}" }, { "type": "Function", "name": "convertTimeZone", "description": "Converts an ISO datetime string to a target timezone, handling daylight savings, and returns an ISO string with the correct offset.", "args": "input, targetTimeZone", "returns": "string", "code": "(input,targetTimeZone)=>{if(typeof input!==\"string\"||typeof targetTimeZone!==\"string\")return null;try{const date=new Date(input);if(isNaN(date.getTime()))return null;const tzStr=targetTimeZone.trim();const offsetMatch=/^([+-])(\\d{2}):(\\d{2})$/.exec(tzStr);if(offsetMatch){const sign=offsetMatch[1]===\"+\"?1:-1;const hours=parseInt(offsetMatch[2],10);const minutes=parseInt(offsetMatch[3],10);const offset=sign*(hours*60+minutes);const utcMillis=date.getTime();const offsetMillis=offset*60*1e3;const converted=new Date(utcMillis+offsetMillis);const pad2=__name((n,l=2)=>n.toString().padStart(l,\"0\"),\"pad\");const offsetStr=`${offsetMatch[1]}${pad2(hours)}:${pad2(minutes)}`;let iso=converted.toISOString().replace(\"Z\",\"\");const isoMatch=iso.match(/^(.*\\.(\\d+))/);if(isoMatch){const frac=isoMatch[2].padEnd(7,\"0\").slice(0,7);iso=iso.replace(/\\.(\\d+)/,`.${frac}`)}return iso+offsetStr}let ianaTz=tzStr;if(!tzStr.includes(\"/\")&&tzStr.toLowerCase()!==\"utc\"){try{const iana=(0,import_windows_iana.findIana)(tzStr);if(iana&&iana.length>0&&typeof iana[0]===\"string\"){ianaTz=iana[0]}}catch{}}if(tzStr.toLowerCase()===\"utc\"||tzStr===\"Etc/UTC\"){ianaTz=\"UTC\"}const{formatInTimeZone:formatInTimeZone2}=require(\"date-fns-tz\");let formatted=formatInTimeZone2(date,ianaTz,\"yyyy-MM-dd'T'HH:mm:ss.SSSXXX\");formatted=formatted.replace(/\\.(\\d{3})/,(m,ms)=>`.${ms.padEnd(7,\"0\")}`);if(ianaTz===\"UTC\"&&formatted.endsWith(\"Z\")){formatted=formatted.slice(0,-1)+\"+00:00\"}return formatted}catch{return null}}" }, { "type": "Function", "name": "localTimeToIsoWithOffset", "description": "Converts a local time string in a specified timezone to an ISO datetime string with the correct offset.", "args": "localTime, timeZone", "returns": "string", "code": "(localTime,timeZone)=>{try{const utcDate=(0,import_date_fns_tz.fromZonedTime)(localTime,timeZone);let formatted=(0,import_date_fns_tz.formatInTimeZone)(utcDate,timeZone,\"yyyy-MM-dd'T'HH:mm:ss.SSSXXX\");formatted=formatted.replace(/\\.(\\d{3})/,(m,ms)=>`.${ms.padEnd(7,\"0\")}`);return formatted}catch{return null}}" }, { "type": "Function", "name": "eval", "description": "Evaluates a JEXL expression and returns the result.\nIf only one argument is provided, it is expected that the first argument is a JEXL expression.\nIf two arguments are provided, the first argument is the context (must be an object) and the second argument is the JEXL expression.\nThe expression uses the default JEXL extended grammar and can't use any custom defined functions or transforms.", "args": "input, expression", "returns": "any", "code": "(input,expression)=>{if(expression===void 0){const _input=typeof input===\"string\"?input:JSON.stringify(input);return import__.default.evalSync(_input)}if(typeof input===\"object\"){return import__.default.evalSync(expression,input)}return void 0}" }, { "type": "Function", "name": "uuid", "description": "Generates a new UUID (Universally Unique Identifier).", "returns": "string", "code": "()=>{return(0,import_uuid.v4)()}" }, { "type": "Function", "name": "uid", "description": "Generates a new UUID (Universally Unique Identifier).", "returns": "string", "code": "()=>{return(0,import_uuid.v4)()}" }, { "type": "Function", "name": "type", "description": "Returns the type of the input value as a string.\n\nSupported return values:\n- \"string\", \"number\", \"boolean\", \"undefined\", \"array\", \"object\"\n- Only for JS: \"function\", \"symbol\", \"bigint\"", "args": "input", "returns": "string", "code": "input=>{if(input===null)return\"null\";if(Array.isArray(input))return\"array\";return typeof input}" }, { "type": "Transform", "name": "string", "description": "Casts the input to a string.", "args": "input, prettify", "returns": "string", "code": "(input,prettify=false)=>{return JSON.stringify(input,null,prettify?2:0)}" }, { "type": "Transform", "name": "toJson", "description": "Parses the string and returns a JSON object.", "args": "input", "returns": "any", "code": "input=>{return JSON.parse(input)}" }, { "type": "Transform", "name": "parseJson", "description": "Parses the string and returns a JSON object.", "args": "input", "returns": "any", "code": "input=>{return JSON.parse(input)}" }, { "type": "Transform", "name": "length", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Transform", "name": "count", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Transform", "name": "size", "description": "Returns the number of characters in a string, or the length of an array.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"string\"){return input.length}if(Array.isArray(input)){return input.length}if(typeof input===\"object\"&&input!==null){return Object.keys(input).length}return 0}" }, { "type": "Transform", "name": "substring", "description": "Gets a substring of a string.", "args": "input, start, length", "returns": "string", "code": "(input,start,length2)=>{let str=input;if(typeof str!==\"string\"){str=JSON.stringify(str)}if(typeof str===\"string\"){let startNum=start;let len=length2??str.length;if(startNum<0){startNum=str.length+start;if(startNum<0){startNum=0}}if(startNum+len>str.length){len=str.length-startNum}if(len<0){len=0}return str.substring(startNum,startNum+len)}return\"\"}" }, { "type": "Transform", "name": "substringBefore", "description": "Returns the substring before the first occurrence of the character sequence chars in str.", "args": "input, chars", "returns": "string", "code": "(input,chars)=>{const str=typeof input===\"string\"?input:JSON.stringify(input);const charsStr=typeof chars===\"string\"?chars:JSON.stringify(chars);const index=str.indexOf(charsStr);if(index===-1){return str}return str.substring(0,index)}" }, { "type": "Transform", "name": "substringAfter", "description": "Returns the substring after the first occurrence of the character sequence chars in str.", "args": "input, chars", "returns": "string", "code": "(input,chars)=>{const str=typeof input===\"string\"?input:JSON.stringify(input);const charsStr=typeof chars===\"string\"?chars:JSON.stringify(chars);const index=str.indexOf(charsStr);if(index===-1){return\"\"}return str.substring(index+charsStr.length)}" }, { "type": "Transform", "name": "uppercase", "description": "Converts the input string to uppercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toUpperCase()}" }, { "type": "Transform", "name": "upper", "description": "Converts the input string to uppercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toUpperCase()}" }, { "type": "Transform", "name": "lowercase", "description": "Converts the input string to lowercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toLowerCase()}" }, { "type": "Transform", "name": "lower", "description": "Converts the input string to lowercase.", "args": "input", "returns": "string", "code": "input=>{const str=typeof input===\"string\"?input:JSON.stringify(input);return str.toLowerCase()}" }, { "type": "Transform", "name": "camelcase", "description": "Converts the input string to camel case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map((word,index)=>{if(index===0)return word.toLowerCase();return word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()}).join(\"\")}" }, { "type": "Transform", "name": "camelCase", "description": "Converts the input string to camel case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map((word,index)=>{if(index===0)return word.toLowerCase();return word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()}).join(\"\")}" }, { "type": "Transform", "name": "toCamelCase", "description": "Converts the input string to camel case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map((word,index)=>{if(index===0)return word.toLowerCase();return word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()}).join(\"\")}" }, { "type": "Transform", "name": "pascalcase", "description": "Converts the input string to pascal case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()).join(\"\")}" }, { "type": "Transform", "name": "pascalCase", "description": "Converts the input string to pascal case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()).join(\"\")}" }, { "type": "Transform", "name": "toPascalCase", "description": "Converts the input string to pascal case.", "args": "input", "returns": "string", "code": "input=>{if(typeof input!==\"string\")return\"\";return input.split(splitRegex).map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()).join(\"\")}" }, { "type": "Transform", "name": "trim", "description": "Trims whitespace from both ends of a string.", "args": "input, trimChar", "returns": "string", "code": "(input,trimChar)=>{if(typeof input===\"string\"){if(trimChar){return input.replace(new RegExp(`^${trimChar}+|${trimChar}+$`,\"g\"),\"\")}return input.trim()}return\"\"}" }, { "type": "Transform", "name": "pad", "description": "Pads the input string to the specified width.", "args": "input, width, char", "returns": "string", "code": "(input,width,char=\" \")=>{const str=typeof input!==\"string\"?JSON.stringify(input):input;if(width>0){return str.padEnd(width,char)}else{return str.padStart(-width,char)}}" }, { "type": "Transform", "name": "contains", "description": "Checks if the input string or array contains the specified value.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"||Array.isArray(input)){return input.includes(search)}return false}" }, { "type": "Transform", "name": "includes", "description": "Checks if the input string or array contains the specified value.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"||Array.isArray(input)){return input.includes(search)}return false}" }, { "type": "Transform", "name": "startsWith", "description": "Checks if the input string starts with the specified substring.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"){return input.startsWith(search)}return false}" }, { "type": "Transform", "name": "endsWith", "description": "Checks if the input string ends with the specified substring.", "args": "input, search", "returns": "boolean", "code": "(input,search)=>{if(typeof input===\"string\"){return input.endsWith(search)}return false}" }, { "type": "Transform", "name": "split", "description": "Splits the input string into an array of substrings.", "args": "input, separator", "returns": "array", "code": "(input,separator)=>{if(typeof input===\"string\"){return input.split(separator)}return[]}" }, { "type": "Transform", "name": "join", "description": "Joins elements of an array into a string.", "args": "input, separator", "returns": "string", "code": "(input,separator)=>{if(Array.isArray(input)){return input.join(separator)}return void 0}" }, { "type": "Transform", "name": "replace", "description": "Replaces occurrences of a specified string with a replacement string.", "args": "input, search, replacement", "returns": "string", "code": "(input,search,replacement)=>{if(typeof input===\"string\"&&typeof search===\"string\"){const _replacement=replacement===void 0?\"\":replacement;return input.replace(new RegExp(search,\"g\"),_replacement)}return void 0}" }, { "type": "Transform", "name": "base64Encode", "description": "Encodes a string to Base64.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){try{encodeURIComponent(input);const bytes=new TextEncoder().encode(input);const binString=String.fromCodePoint(...bytes);return btoa(binString)}catch(error){return\"\"}}return\"\"}" }, { "type": "Transform", "name": "base64Decode", "description": "Decodes a Base64 encoded string.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){const binString=atob(input);const bytes=Uint8Array.from(binString,m=>m.codePointAt(0));return new TextDecoder().decode(bytes)}return\"\"}" }, { "type": "Transform", "name": "formUrlEncoded", "description": "Encodes a string or object to URI component format.", "args": "input", "returns": "string", "code": "input=>{if(typeof input===\"string\"){return encodeURIComponent(input)}else if(typeof input===\"object\"){return Object.keys(input).map(key=>`${encodeURIComponent(key)}=${encodeURIComponent(input[key])}`).join(\"&\")}return\"\"}" }, { "type": "Transform", "name": "number", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Transform", "name": "toNumber", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Transform", "name": "float", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Transform", "name": "toFloat", "description": "Converts the input to a number.", "args": "input", "returns": "number", "code": "input=>{if(typeof input===\"number\")return input;if(typeof input===\"string\")return parseFloat(input);return NaN}" }, { "type": "Transform", "name": "abs", "description": "Returns the absolute value of a number.", "args": "input", "returns": "nu