From 986aace78dfb9c8878dbb19c24451c649a48c204 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Sun, 3 Nov 2024 19:49:53 -0600 Subject: [PATCH] 0.6.0 --- dist/uDSV.cjs.js | 2 +- dist/uDSV.iife.js | 2 +- dist/uDSV.iife.min.js | 2 +- dist/uDSV.mjs | 2 +- package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/uDSV.cjs.js b/dist/uDSV.cjs.js index 274a18b..305d2fa 100644 --- a/dist/uDSV.cjs.js +++ b/dist/uDSV.cjs.js @@ -4,7 +4,7 @@ * * uDSV.js * A small, fast CSV parser -* https://github.com/leeoniya/uDSV (v0.5.3) +* https://github.com/leeoniya/uDSV (v0.6.0) */ 'use strict'; diff --git a/dist/uDSV.iife.js b/dist/uDSV.iife.js index 59f2ee7..eedeb94 100644 --- a/dist/uDSV.iife.js +++ b/dist/uDSV.iife.js @@ -4,7 +4,7 @@ * * uDSV.js * A small, fast CSV parser -* https://github.com/leeoniya/uDSV (v0.5.3) +* https://github.com/leeoniya/uDSV (v0.6.0) */ var uDSV = (function (exports) { diff --git a/dist/uDSV.iife.min.js b/dist/uDSV.iife.min.js index bcc15b7..e33a674 100644 --- a/dist/uDSV.iife.min.js +++ b/dist/uDSV.iife.min.js @@ -1,2 +1,2 @@ -/*! https://github.com/leeoniya/uDSV (v0.5.3) */ +/*! https://github.com/leeoniya/uDSV (v0.6.0) */ var uDSV=function(e){"use strict";const l=/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3,})?(?:Z|[-+]\d{2}:?\d{2}))?$/,t=/^(?:t(?:rue)?|f(?:alse)?|y(?:es)?|n(?:o)?|0|1)$/i,n=["\t","|",";",","],r="d",i="n",s="j",c="b";const o=JSON.stringify,f=e=>"string"==typeof e?o(e):e;function u(e,l){let{type:t}=l,n=`r[${e}]`,u=t===r?`new Date(${n})`:t===s?`JSON.parse(${n})`:t===i?"+"+n:t[0]===c?`${n} === ${o(t.slice(2))} ? true : false`:n,{repl:a}=l,h=void 0!==a.NaN&&t===i?`${n} === 'NaN' ? ${f(a.NaN)} : `:"",d=void 0!==a.null?`${n} === 'null' || ${n} === 'NULL' ? ${f(a.null)} : `:"";return`${void 0!==a.empty?`${n} === '' ? ${f(a.empty)} : `:""} ${d} ${h} ${u}`}const a=/\w+(?:\[|\]?[\.\[]?|$)/gm;function h(e,l=!1,t=!1){let n="";if(l&&t){let l={},t=0,r=e.map((e=>e.name.replace(/\.(\d+)\.?/gi,"[$1]")));do{let e=r.shift(),n=/\s/.test(e)?[e]:[...e.matchAll(a)].flatMap((e=>e.map((e=>e.replace("]",""))))),i=l;do{let e=n.shift(),l=e,r=e.at(-1);"."==r||"["==r?(l=e.slice(0,-1),i=i[l]=i[l]??("."==r?{}:[])):i[l]=`¦${t}¦`}while(n.length>0);t++}while(r.length>0);n=o(l).replace(/"¦(\d+)¦"/g,((l,t)=>u(+t,e[+t])))}else!l&&e.every((e=>"s"===e.type))?n="r":(n=l?"{":"[",e.forEach(((e,t)=>{n+=l?o(e.name)+":":"";let r=u(t,e);n+=r+","})),n+=l?"}":"]");return Function("rows",` let arr = Array(rows.length); for (let i = 0; i < rows.length; i++) { let r = rows[i]; arr[i] = ${n}; } return arr; `)}function d(e,l,t,n=0,r=!0,i=1e3,s=null,c=null){let{row:o,col:f,encl:u,esc:a,trim:h}=l;u??=e.indexOf('"')>-1?'"':"",a??=u;let d=`${a}${u}`,p=c||l.cols.length,g=null!=s,$=null!=c&&g,y=o.length,m=f.length,A=u.charCodeAt(0),N=a.charCodeAt(0),k=o.charCodeAt(0),w=f.charCodeAt(0),b=0,C=0,O=e.length-1,x=0,v=[],E=Array(p).fill(""),S=E.slice(),j=0,L=p-1,T=-1;if(""===u){for(;O>=C;)if(j===L){let l=e.indexOf(o,C);if(-1===l){if(!r)break;l=O+1}let c=e.slice(C,l);if(S[j]=h?c.trim():c,0>--n&&v.push(S),v.length===i){let e=!1===t(v,"");if(v=[],e||g&&++b===s)return}S=E.slice(),j=0,T=-1,C=l+y,x=C}else if(0===j&&e.charCodeAt(C)===k)C+=y;else{let l=e.indexOf(f,C);if(-1===l&&!r)break;let t=e.slice(C,l);S[j]=h?t.trim():t,C=l+m,T=j++}return r&&j===L&&T>-1&&0>--n&&v.push(S),void(r&&0>=v.length||t(v,r?"":e.slice(x)))}const R=$?RegExp(`[^${f}${o}]+`,"my"):null;let Y=0,D="",F=0,J=C;for(;O>=C;){if(F=e.charCodeAt(C),0===Y)if(F===A){if(Y=2,C+=1,J=C,C>O)break;F=e.charCodeAt(C)}else if(F===w||F===k){if(F===k&&0===j){C+=y;continue}if(S[j]=D,T=j,j+=1,C+=1,D="",F===k){if($&&L>T&&0===v.length&&(S.length=E.length=T+1,L=T),0>--n&&v.push(S),v.length===i){let e=!1===t(v,"");if(v=[],e||g&&++b===s)return}S=E.slice(),j=0,T=-1,C+=y-1,x=C}if(C>O)break}else if(h&&32===F)for(;32===F;)F=e.charCodeAt(++C);else Y=1;if(2===Y){let l=!1,t=0;for(;;)if(F===A)if(A===N){if(C+1>O){t=C,C=O+1;break}if(e.charCodeAt(C+1)!==A){Y=0,t=C,C+=1;break}if(C+=2,l=!0,C>O)break;F=e.charCodeAt(C)}else{if(e.charCodeAt(C-1)!==N){Y=0,t=C,C+=1;break}if(C+=1,l=!0,C>O)break;F=e.charCodeAt(C)}else{let l=e.indexOf(u,C);if(-1===l){C=O+1;break}C=l,F=A}(0===Y||C>O)&&(D=l?e.slice(J,t).replaceAll(d,u):e.slice(J,t))}else if(1===Y)if(F===w||F===k){if(F===k&&0===j){C+=y;continue}if(S[j]=D,T=j,j+=1,C+=1,D="",F===k){if($&&L>T&&0===v.length&&(S.length=E.length=T+1,L=T),0>--n&&v.push(S),v.length===i){let e=!1===t(v,"");if(v=[],e||g&&++b===s)return}S=E.slice(),j=0,T=-1,C+=y-1,x=C}Y=0}else if($){R.lastIndex=C;let l=R.exec(e)[0];D=l,C+=l.length}else{let l=e.indexOf(j===L?o:f,C);-1===l&&(l=O+1);let t=e.slice(C,l);D=h?t.trim():t,C=l}}r&&j===L&&(S[j]=D,0>--n&&v.push(S),Y=0),t(v,r||0===Y&&!(-1===T?""!==D:L>T)?"":e.slice(x))}return e.inferSchema=function(e,o,f){let{header:u,col:a,row:h,encl:p,esc:g,trim:$=!1}=o??{};u??=e=>[e[0]],f??=10;const y=RegExp(`(.*)(${h??"\r\n|\r|\n"})`),m=e.match(y),A=m[1];h??=m[2],a??=n.find((e=>A.indexOf(e)>-1))??",";const N={skip:1,col:a,row:h,encl:p,esc:g,trim:$,cols:[]},k=A.split(a).length,w=[];d(e,N,(e=>{w.push(...e)}),0,!0,f,1,k);let b=u(w)??[],C=N.skip=b.length,O=b.find((e=>null!=e))??[...Array(w[0].length).keys()];return w.splice(0,C),O.forEach(((e,n)=>{let o=function(e,n){let o=n.findLast((l=>""!==l[e]&&"null"!==l[e]&&"NULL"!==l[e]&&"NaN"!==l[e])),f="s";if(null!=o){let n=o[e];f=l.test(n)?r:+n==+n?i:t.test(n)?c+":"+function(e){let[l,t=""]=e;return"1"==l||"0"==l?"1":"t"==l||"f"==l?""==t?"t":"true":"T"==l||"F"==l?""==t?"T":"R"==t||"A"===t?"TRUE":"True":"y"==l||"n"==l?""==t?"y":"yes":"Y"==l||"N"==l?""==t?"Y":"E"==t||"O"===t?"YES":"Yes":""}(n):function(e){if("["===e[0]||"{"===e[0])try{return JSON.parse(e),!0}catch{}return!1}(n)?s:f}return f}(n,w);N.cols.push({name:e,type:o,repl:{empty:null,NaN:void 0,null:void 0}})})),N},e.initParser=function(e,l){let{skip:t,cols:n}=e,r=null,i=null,s=null,c=null,o=null,f=null,u=0,a=0,p=null,g=null,$="",y="",m=null;function A(){a=u=0,y=$="",p=g=m=null}let N=(e,l)=>{l(e)},k=()=>[],w=e=>{m.push(...e)};function b(n,r,i){let s=null;return(c,o=N)=>{s??=i(),m??=n();let f=m,h=0===a||2===a;return d(c,e,((e,l)=>{y=l;let t=o(s(e),r);return!1===t&&0!==a&&A(),t}),0===u?t:0,h,l),h&&(m=null),f}}const C=b(k,w,(()=>(r??=e=>e,r))),O=b(k,w,(()=>(o??=h(n.map((e=>({...e,type:"s",repl:{...e.repl,empty:void 0}}))),!0,!1),o))),x=b(k,w,(()=>(i??=h(n,!1,!1),i))),v=b(k,w,(()=>(s??=h(n,!0,!1),s))),E=b(k,w,(()=>(c??=h(n,!0,!0),c))),S=b((()=>n.map((()=>[]))),(e=>{e.forEach(((e,l)=>{m[l].push(...e)}))}),(()=>(i??=h(n,!1,!1),f??=function(e){return Function("rows",` let cols = [${e.map((()=>"Array(rows.length)")).join(",")}]; for (let i = 0; i < rows.length; i++) { let r = rows[i]; ${e.map(((e,l)=>`cols[${l}][i] = r[${l}]`)).join(";")}; } return cols; `)}(n),e=>f(i(e)))));return{schema:e,stringArrs:C,stringObjs:O,typedArrs:x,typedObjs:v,typedDeep:E,typedCols:S,chunk(e,l=C,t=N){p??=l,g??=t,1===a&&(p(y+$,g),u++),$=e,a=1},end(){a=2;let e=p(y+$,g);return A(),e}}},e}({}); diff --git a/dist/uDSV.mjs b/dist/uDSV.mjs index f67bbca..03fb0b8 100644 --- a/dist/uDSV.mjs +++ b/dist/uDSV.mjs @@ -4,7 +4,7 @@ * * uDSV.js * A small, fast CSV parser -* https://github.com/leeoniya/uDSV (v0.5.3) +* https://github.com/leeoniya/uDSV (v0.6.0) */ const comma = ','; diff --git a/package.json b/package.json index f01abbc..a060b1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "udsv", - "version": "0.5.3", + "version": "0.6.0", "description": "A small, fast CSV parser", "main": "./dist/uDSV.cjs.js", "module": "./dist/uDSV.mjs",