@ingestro/importer-react 4.0.4 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunk-6KU4IPD7.js +1 -0
- package/index.js +5 -5
- package/package.json +3 -2
- package/workers/javascript/index.js +1 -1
- package/chunk-QNASKSN5.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as v}from"./chunk-J5WOZVPO.js";var L=h=>!h||typeof h!="string"?"":h.replace(/<[^>]*>/g,""),F=(h,n,c)=>{let e=h,s=[...n,{label:"rowIndex",key:"rowIndex"}];for(let l of s){let{label:m,key:g}=l,u=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),t=[],r,d=/(['"])((?:(?!\1)[^\\]|\\.)*)(\1)/g;for(;(r=d.exec(e))!==null;)t.push({start:r.index,end:r.index+r[0].length});let a=i=>t.some(o=>i>=o.start&&i<o.end),p=[new RegExp(`@${u}\\b`,"g"),new RegExp(`@${u}(?=\\W|$)`,"g")];for(let i of p){let o,f="",b=0;for(i.lastIndex=0;(o=i.exec(e))!==null;){let y=o.index;f+=e.substring(b,y),a(y)?f+=o[0]:g==="rowIndex"?f+=`row.${g}`:f+=`row["${g.trim()}"]`,b=i.lastIndex,o.index===i.lastIndex&&i.lastIndex++}for(f+=e.substring(b),e=f,t.length=0,d.lastIndex=0;(r=d.exec(e))!==null;)t.push({start:r.index,end:r.index+r[0].length})}}if(c){let l=v.getInstance().getTruthyWords(),m=v.getInstance().getFalsyWords(),g=[],u,t=/(['"])((?:(?!\1)[^\\]|\\.)*)(\1)/g;for(;(u=t.exec(e))!==null;)g.push({start:u.index,end:u.index+u[0].length});let r=a=>g.some(p=>a>=p.start&&a<p.end),d=(a,p,i)=>{let o=a;for(let f of p){let y=String(f).replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),x=new RegExp(`\\b${y}\\b`,"gi"),w="",$=0,I;for(x.lastIndex=0;(I=x.exec(o))!==null;){let S=I.index;w+=o.substring($,S),r(S)?w+=i:w+=I[0],$=x.lastIndex,I.index===x.lastIndex&&x.lastIndex++}w+=o.substring($),o=w}return o};e=d(e,l,"true"),e=d(e,m,"false")}return e},C=h=>h.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&").replace(/@/g,"[@]");import{Interpreter as E}from"eval5";import*as W from"@babel/standalone";var k=class{constructor(){this.formula="";this.outputData=[];this.initialize=()=>Promise.resolve();this.cleanupData=()=>{this.outputData=[]};this.setFormula=n=>(this.formula=n,Promise.resolve());this.check=()=>!0;this.parse=async(n,c,e)=>{this.outputData=[];let s=F(this.formula,c,e),l=this.generateInputValues(n,c),m=l?.[0];await this.validateFunction([m],c,s);let g=this.replaceNullishCoalescingWithLogicalOr(s),u=this.transpileToES5(g);for(let t=0;t<l.length;t++)try{let r={$$inputs:{...l[t],rowIndex:t+1}},p=new E(r,{timeout:5e3}).evaluate(u)(r.$$inputs),i=p===void 0?"":p;this.outputData[t]=[JSON.parse(JSON.stringify(i))]}catch(r){throw new Error(`Error in row ${t+1}: ${r instanceof Error?r.message:"Check your formula"}`)}return this.outputData};this.validateFunction=async(n,c,e)=>{let s=[...c.map(t=>t.key.trim()),"rowIndex"],l=e||this.formula;if(l){let t=/row\.([a-zA-Z_][\w$]*)/g,r=l.matchAll(t);for(let d of r){let a=d[1];if(!s.includes(a))throw new Error(`Invalid variable: row.${a} is not a valid column reference`)}}let m=n[0],g=this.replaceNullishCoalescingWithLogicalOr(e||this.formula),u=this.transpileToES5(g);try{let t={$$inputs:{...m,rowIndex:0}},a=new E(t,{timeout:5e3}).evaluate(u)(t.$$inputs),p=a===void 0?"":a;this.outputData[0]=[JSON.parse(JSON.stringify(p))]}catch(t){let r=t instanceof Error?t.message:"Invalid Syntax";throw Error(r)}};this.generateInputValues=(n,c)=>{let e=[];for(let s=0;s<n.length;++s)e[s]={},c.forEach((l,m)=>{e[s][l.key.trim()]=n[s][m]??""}),e[s].rowIndex=s;return e};this.replaceNullishCoalescingWithLogicalOr=n=>n.replace(/\?\?/g,"||");this.transpileToES5=n=>{try{let e=W.transform(n,{presets:[["env",{targets:{ie:"11"},modules:!1}]],compact:!1,comments:!1}).code||n;return e=e.replace(/^["']use strict["'];?\s*/i,"").trim().replace(/;$/,""),e}catch{return n}}}};export{L as a,F as b,C as c,k as d};
|