UNPKG

pragma-views2

Version:

1 lines 1.22 kB
import{dateToFormattedDate}from"../../lib/date-helpers.js";const knownFunctions=new Map([["@today",todayDate],["@todayDate",todayDate],["@todayDateTime",todayDateTime],["@null",()=>null]]);export function prefixVariables(t,e,n){return 1==isKnowFunction(n)?n:n.split(e).join(t)}function isKnowFunction(t){return knownFunctions.has(t)}export function getValueOnPath(t,e){return crsbinding.utils.getValueOnPath(t,e)}export function getValueOnPathExpression(t,e){if("true"===e)return!0;const n=crsbinding.expression.compile(e);let o=n.function(t);return crsbinding.expression.release(n),o}export function setValueOnPath(t,e,n){crsbinding.data.setProperty(t._dataId,e,n)}export async function executeFunctionOnPath(t,e,n,o){let a,i;if(-1!==e.indexOf(".")){let n=e.split(".");a=n.pop(),i=getValueOnPath(t,n.join("."))}else a=e,i=t;if(null==i[a])return console.warn(`Could not execute ${e} as the path does not fully exist on object`);await i[a].call(i,n,o)}export function todayDate(){return dateToFormattedDate(new Date,!0)}export function todayDateTime(){return dateToFormattedDate(new Date)}export function parsePath(t){if(null==t)return t;let e=t;return t.includes(".")&&!1===t.includes("?.")&&(e=t.replace(".","?.")),e}