@graphysdk/data-import-utils 1.3.0-beta.1778059383500 → 1.3.0-beta.1778504701741
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/dist/buffer.cjs +1 -1
- package/dist/buffer.mjs +1 -1
- package/dist/file.cjs +1 -1
- package/dist/file.mjs +1 -1
- package/dist/ods.cjs +1 -1
- package/dist/ods.mjs +1 -1
- package/dist/url.cjs +1 -1
- package/dist/url.mjs +1 -1
- package/dist/xls.cjs +1 -1
- package/dist/xls.mjs +1 -1
- package/dist/xlsx.cjs +1 -1
- package/dist/xlsx.d.ts +101 -2
- package/dist/xlsx.mjs +1 -1
- package/package.json +3 -3
package/dist/buffer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib");require("papaparse");var t=require("@graphysdk/core/node"),r=require("exceljs");const o=/[^\p{ASCII}]/u,n=/[\u2012\u2013\u2014\u2212](?=\d)/g,l=/\u00A0/g,i=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,s=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,u=new Set(["PT_PT","AR"]),a=(e,t="EN_US")=>{let r;if(r=o.test(e)?e.replace(n,"-").replace(l," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(u.has(t)){if(s.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(i.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},c=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},d=(o,n)=>e.__awaiter(void 0,void 0,void 0,function*(){var
|
|
1
|
+
"use strict";var e=require("tslib");require("papaparse");var t=require("@graphysdk/core/node"),r=require("exceljs");const o=/[^\p{ASCII}]/u,n=/[\u2012\u2013\u2014\u2212](?=\d)/g,l=/\u00A0/g,i=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,s=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,u=new Set(["PT_PT","AR"]),a=(e,t="EN_US")=>{let r;if(r=o.test(e)?e.replace(n,"-").replace(l," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(u.has(t)){if(s.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(i.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},c=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},d=["dataValidations","conditionalFormatting","sheetProtection"];const f=(o,n)=>e.__awaiter(void 0,void 0,void 0,function*(){var l,i,s,u,f;const m=1024*(null!==(l=null==n?void 0:n.maxFileSize)&&void 0!==l?l:5)*1024;if(o.byteLength>m)throw new Error(`Input size (${o.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(i=null==n?void 0:n.maxFileSize)&&void 0!==i?i:5} MB).`);const h=null!==(s=null==n?void 0:n.locale)&&void 0!==s?s:"EN_US",p=yield function(t){return e.__awaiter(this,void 0,void 0,function*(){const e=new r.Workbook;return yield e.xlsx.load(t,{ignoreNodes:d}),e})}(o),w=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const r=e.worksheets[t];if(!r)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return r}const r=e.getWorksheet(t);if(!r){const r=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${r}`)}return r})(p,null==n?void 0:n.sheet);if(!w||0===w.rowCount)return{columns:[],rows:[]};const v=w.columnCount;if(0===v)return{columns:[],rows:[]};const x=w.getRow(1),g=[];for(let e=1;e<=v;e++){const t=x.getCell(e).value;g.push(String(null!=t?t:""))}const b=((e,r)=>{var o;const n=[];for(let l=0;l<r;l++){const r=null===(o=null==e?void 0:e[l])||void 0===o?void 0:o.trim(),i={key:t.columnIndexToPropertyKey(l)};r&&(i.label=r),n.push(i)}return n})(g,v),y=null!==(u=null==n?void 0:n.maxRows)&&void 0!==u?u:1e5,S=null!==(f=null==n?void 0:n.maxCells)&&void 0!==f?f:5e6,$=[];let k=0,C=0;for(let e=2;e<=w.rowCount;e++){if(k++,k>y)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=w.getRow(e),r=[];for(let e=1;e<=v;e++)r.push(c(t.getCell(e)));$.push(r)}const _=((e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];o[l.key]=null==i||""===i?null:"number"==typeof i?i:a(String(i),r)}return o}))($,b,h);return{columns:b,rows:_}});exports.fromBuffer=(t,r,o)=>e.__awaiter(void 0,void 0,void 0,function*(){switch(r){case"xlsx":case"xls":case"ods":return((e,t)=>f(e,t))(t,o);default:throw new Error(`Unsupported binary format "${r}". Supported: xlsx, xls, ods`)}});
|
package/dist/buffer.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import"papaparse";import{columnIndexToPropertyKey as t}from"@graphysdk/core/node";import o from"exceljs";const r=/[^\p{ASCII}]/u,n=/[\u2012\u2013\u2014\u2212](?=\d)/g,l=/\u00A0/g,i=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,s=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,u=new Set(["PT_PT","AR"]),
|
|
1
|
+
import{__awaiter as e}from"tslib";import"papaparse";import{columnIndexToPropertyKey as t}from"@graphysdk/core/node";import o from"exceljs";const r=/[^\p{ASCII}]/u,n=/[\u2012\u2013\u2014\u2212](?=\d)/g,l=/\u00A0/g,i=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,s=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,u=new Set(["PT_PT","AR"]),c=(e,t="EN_US")=>{let o;if(o=r.test(e)?e.replace(n,"-").replace(l," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(u.has(t)){if(s.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(i.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},d=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},f=["dataValidations","conditionalFormatting","sheetProtection"];const a=(r,n)=>e(void 0,void 0,void 0,function*(){var l,i,s,u,a;const m=1024*(null!==(l=null==n?void 0:n.maxFileSize)&&void 0!==l?l:5)*1024;if(r.byteLength>m)throw new Error(`Input size (${r.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(i=null==n?void 0:n.maxFileSize)&&void 0!==i?i:5} MB).`);const p=null!==(s=null==n?void 0:n.locale)&&void 0!==s?s:"EN_US",h=yield function(t){return e(this,void 0,void 0,function*(){const e=new o.Workbook;return yield e.xlsx.load(t,{ignoreNodes:f}),e})}(r),w=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const o=e.worksheets[t];if(!o)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return o}const o=e.getWorksheet(t);if(!o){const o=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${o}`)}return o})(h,null==n?void 0:n.sheet);if(!w||0===w.rowCount)return{columns:[],rows:[]};const v=w.columnCount;if(0===v)return{columns:[],rows:[]};const g=w.getRow(1),x=[];for(let e=1;e<=v;e++){const t=g.getCell(e).value;x.push(String(null!=t?t:""))}const b=((e,o)=>{var r;const n=[];for(let l=0;l<o;l++){const o=null===(r=null==e?void 0:e[l])||void 0===r?void 0:r.trim(),i={key:t(l)};o&&(i.label=o),n.push(i)}return n})(x,v),y=null!==(u=null==n?void 0:n.maxRows)&&void 0!==u?u:1e5,S=null!==(a=null==n?void 0:n.maxCells)&&void 0!==a?a:5e6,$=[];let k=0,C=0;for(let e=2;e<=w.rowCount;e++){if(k++,k>y)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=w.getRow(e),o=[];for(let e=1;e<=v;e++)o.push(d(t.getCell(e)));$.push(o)}const E=((e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];r[l.key]=null==i||""===i?null:"number"==typeof i?i:c(String(i),o)}return r}))($,b,p);return{columns:b,rows:E}}),m=(t,o,r)=>e(void 0,void 0,void 0,function*(){switch(o){case"xlsx":case"xls":case"ods":return((e,t)=>a(e,t))(t,r);default:throw new Error(`Unsupported binary format "${o}". Supported: xlsx, xls, ods`)}});export{m as fromBuffer};
|
package/dist/file.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("node:fs/promises"),r=require("node:path"),o=require("papaparse"),n=require("@graphysdk/core/node"),s=require("exceljs");const i=new Set(["csv","tsv"]),l={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},u=(e,t)=>{var r;const o=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:n.columnIndexToPropertyKey(s)};t&&(i.label=t),o.push(i)}return o},a=/[^\p{ASCII}]/u,d=/[\u2012\u2013\u2014\u2212](?=\d)/g,f=/\u00A0/g,c=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,p=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,v=new Set(["PT_PT","AR"]),w=(e,t="EN_US")=>{let r;if(r=a.test(e)?e.replace(d,"-").replace(f," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(v.has(t)){if(p.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(c.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},m=(e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];o[s.key]=null==i||""===i?null:"number"==typeof i?i:w(String(i),r)}return o}),h=(e,t,r)=>{var n,s,i,l,a;const d=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>d)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=!1!==(null==r?void 0:r.hasHeader),c=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",p=o.parse(e,{header:!1,delimiter:t,skipEmptyLines:!0}),v=p.errors.filter(e=>"Quotes"===e.type);if(v.length>0){const e=v[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const w=p.data;if(0===w.length)return{columns:[],rows:[]};const h=f?w[0]:void 0,x=f?w.slice(1):w,
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("node:fs/promises"),r=require("node:path"),o=require("papaparse"),n=require("@graphysdk/core/node"),s=require("exceljs");const i=new Set(["csv","tsv"]),l={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},u=(e,t)=>{var r;const o=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:n.columnIndexToPropertyKey(s)};t&&(i.label=t),o.push(i)}return o},a=/[^\p{ASCII}]/u,d=/[\u2012\u2013\u2014\u2212](?=\d)/g,f=/\u00A0/g,c=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,p=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,v=new Set(["PT_PT","AR"]),w=(e,t="EN_US")=>{let r;if(r=a.test(e)?e.replace(d,"-").replace(f," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(v.has(t)){if(p.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(c.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},m=(e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];o[s.key]=null==i||""===i?null:"number"==typeof i?i:w(String(i),r)}return o}),h=(e,t,r)=>{var n,s,i,l,a;const d=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>d)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=!1!==(null==r?void 0:r.hasHeader),c=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",p=o.parse(e,{header:!1,delimiter:t,skipEmptyLines:!0}),v=p.errors.filter(e=>"Quotes"===e.type);if(v.length>0){const e=v[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const w=p.data;if(0===w.length)return{columns:[],rows:[]};const h=f?w[0]:void 0,x=f?w.slice(1):w,y=w.reduce((e,t)=>Math.max(e,t.length),0),g=u(h,y);return{columns:g,rows:m(x,g,c)}},x=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},y=["dataValidations","conditionalFormatting","sheetProtection"];const g=(t,r)=>e.__awaiter(void 0,void 0,void 0,function*(){var o,n,i,l,a;const d=1024*(null!==(o=null==r?void 0:r.maxFileSize)&&void 0!==o?o:5)*1024;if(t.byteLength>d)throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5} MB).`);const f=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",c=yield function(t){return e.__awaiter(this,void 0,void 0,function*(){const e=new s.Workbook;return yield e.xlsx.load(t,{ignoreNodes:y}),e})}(t),p=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const r=e.worksheets[t];if(!r)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return r}const r=e.getWorksheet(t);if(!r){const r=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${r}`)}return r})(c,null==r?void 0:r.sheet);if(!p||0===p.rowCount)return{columns:[],rows:[]};const v=p.columnCount;if(0===v)return{columns:[],rows:[]};const w=p.getRow(1),h=[];for(let e=1;e<=v;e++){const t=w.getCell(e).value;h.push(String(null!=t?t:""))}const g=u(h,v),b=null!==(l=null==r?void 0:r.maxRows)&&void 0!==l?l:1e5,$=null!==(a=null==r?void 0:r.maxCells)&&void 0!==a?a:5e6,S=[];let E=0,k=0;for(let e=2;e<=p.rowCount;e++){if(E++,E>b)throw new Error(`Row limit exceeded: processed ${E} rows (maximum: ${b}). Use the maxRows option to increase the limit.`);if(k+=v,k>$)throw new Error(`Cell limit exceeded: processed ${k} cells (maximum: ${$}). Use the maxCells option to increase the limit.`);const t=p.getRow(e),r=[];for(let e=1;e<=v;e++)r.push(x(t.getCell(e)));S.push(r)}return{columns:g,rows:m(S,g,f)}}),b=(e,t,r)=>{switch(t){case"csv":return((e,t)=>h(e,void 0,t))(e,r);case"tsv":return((e,t)=>h(e,"\t",t))(e,r);default:throw new Error(`Unsupported text format "${t}". Supported: csv, tsv`)}},$=(t,r,o)=>e.__awaiter(void 0,void 0,void 0,function*(){switch(r){case"xlsx":case"xls":case"ods":return((e,t)=>g(e,t))(t,o);default:throw new Error(`Unsupported binary format "${r}". Supported: xlsx, xls, ods`)}});exports.fromFile=(o,n)=>e.__awaiter(void 0,void 0,void 0,function*(){if("undefined"!=typeof window&&"undefined"==typeof process)throw new Error("fromFile is only available in Node.js environments. In the browser, read the file using the File API and pass the result to fromCSV (for text) or fromXLSX (for binary formats).");const s=r.extname(o).toLowerCase(),u=(e=>l[e.toLowerCase()])(s);if(!u){const e=Object.keys(l).join(", ");throw new Error(`Unsupported file extension "${s||"(none)"}". Supported: ${e}`)}const a=yield t.readFile(o);return((t,r,o)=>e.__awaiter(void 0,void 0,void 0,function*(){switch(r){case"csv":case"tsv":if("string"!=typeof t)throw new TypeError(`${r.toUpperCase()} parsing requires a string input, but received an ArrayBuffer.`);return b(t,r,o);case"xlsx":case"xls":case"ods":if("string"==typeof t)throw new TypeError(`${r.toUpperCase()} parsing requires an ArrayBuffer input, but received a string.`);return $(t,r,o);default:throw new Error(`Unsupported format "${r}". Supported formats: csv, tsv, xlsx, xls, ods`)}}))(i.has(u)?"string"==typeof a?a:a.toString("utf-8"):a instanceof Buffer?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,u,n)});
|
package/dist/file.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import{readFile as t}from"node:fs/promises";import r from"node:path";import o from"papaparse";import{columnIndexToPropertyKey as n}from"@graphysdk/core/node";import s from"exceljs";const i=new Set(["csv","tsv"]),l={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},u=(e,t)=>{var r;const o=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:n(s)};t&&(i.label=t),o.push(i)}return o},a=/[^\p{ASCII}]/u,d=/[\u2012\u2013\u2014\u2212](?=\d)/g,f=/\u00A0/g,c=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,p=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,m=new Set(["PT_PT","AR"]),v=(e,t="EN_US")=>{let r;if(r=a.test(e)?e.replace(d,"-").replace(f," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(m.has(t)){if(p.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(c.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},h=(e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];o[s.key]=null==i||""===i?null:"number"==typeof i?i:v(String(i),r)}return o}),w=(e,t,r)=>{var n,s,i,l,a;const d=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>d)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=!1!==(null==r?void 0:r.hasHeader),c=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",p=o.parse(e,{header:!1,delimiter:t,skipEmptyLines:!0}),m=p.errors.filter(e=>"Quotes"===e.type);if(m.length>0){const e=m[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const v=p.data;if(0===v.length)return{columns:[],rows:[]};const w=f?v[0]:void 0,x=f?v.slice(1):v,g=v.reduce((e,t)=>Math.max(e,t.length),0),y=u(w,g);return{columns:y,rows:h(x,y,c)}},x=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},g=(t,r)=>e(void 0,void 0,void 0,function*(){var
|
|
1
|
+
import{__awaiter as e}from"tslib";import{readFile as t}from"node:fs/promises";import r from"node:path";import o from"papaparse";import{columnIndexToPropertyKey as n}from"@graphysdk/core/node";import s from"exceljs";const i=new Set(["csv","tsv"]),l={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},u=(e,t)=>{var r;const o=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:n(s)};t&&(i.label=t),o.push(i)}return o},a=/[^\p{ASCII}]/u,d=/[\u2012\u2013\u2014\u2212](?=\d)/g,f=/\u00A0/g,c=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,p=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,m=new Set(["PT_PT","AR"]),v=(e,t="EN_US")=>{let r;if(r=a.test(e)?e.replace(d,"-").replace(f," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(m.has(t)){if(p.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(c.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},h=(e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];o[s.key]=null==i||""===i?null:"number"==typeof i?i:v(String(i),r)}return o}),w=(e,t,r)=>{var n,s,i,l,a;const d=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>d)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=!1!==(null==r?void 0:r.hasHeader),c=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",p=o.parse(e,{header:!1,delimiter:t,skipEmptyLines:!0}),m=p.errors.filter(e=>"Quotes"===e.type);if(m.length>0){const e=m[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const v=p.data;if(0===v.length)return{columns:[],rows:[]};const w=f?v[0]:void 0,x=f?v.slice(1):v,g=v.reduce((e,t)=>Math.max(e,t.length),0),y=u(w,g);return{columns:y,rows:h(x,y,c)}},x=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},g=["dataValidations","conditionalFormatting","sheetProtection"];const y=(t,r)=>e(void 0,void 0,void 0,function*(){var o,n,i,l,a;const d=1024*(null!==(o=null==r?void 0:r.maxFileSize)&&void 0!==o?o:5)*1024;if(t.byteLength>d)throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5} MB).`);const f=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",c=yield function(t){return e(this,void 0,void 0,function*(){const e=new s.Workbook;return yield e.xlsx.load(t,{ignoreNodes:g}),e})}(t),p=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const r=e.worksheets[t];if(!r)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return r}const r=e.getWorksheet(t);if(!r){const r=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${r}`)}return r})(c,null==r?void 0:r.sheet);if(!p||0===p.rowCount)return{columns:[],rows:[]};const m=p.columnCount;if(0===m)return{columns:[],rows:[]};const v=p.getRow(1),w=[];for(let e=1;e<=m;e++){const t=v.getCell(e).value;w.push(String(null!=t?t:""))}const y=u(w,m),b=null!==(l=null==r?void 0:r.maxRows)&&void 0!==l?l:1e5,$=null!==(a=null==r?void 0:r.maxCells)&&void 0!==a?a:5e6,S=[];let E=0,k=0;for(let e=2;e<=p.rowCount;e++){if(E++,E>b)throw new Error(`Row limit exceeded: processed ${E} rows (maximum: ${b}). Use the maxRows option to increase the limit.`);if(k+=m,k>$)throw new Error(`Cell limit exceeded: processed ${k} cells (maximum: ${$}). Use the maxCells option to increase the limit.`);const t=p.getRow(e),r=[];for(let e=1;e<=m;e++)r.push(x(t.getCell(e)));S.push(r)}return{columns:y,rows:h(S,y,f)}}),b=(e,t,r)=>{switch(t){case"csv":return((e,t)=>w(e,void 0,t))(e,r);case"tsv":return((e,t)=>w(e,"\t",t))(e,r);default:throw new Error(`Unsupported text format "${t}". Supported: csv, tsv`)}},$=(t,r,o)=>e(void 0,void 0,void 0,function*(){switch(r){case"xlsx":case"xls":case"ods":return((e,t)=>y(e,t))(t,o);default:throw new Error(`Unsupported binary format "${r}". Supported: xlsx, xls, ods`)}}),S=(o,n)=>e(void 0,void 0,void 0,function*(){if("undefined"!=typeof window&&"undefined"==typeof process)throw new Error("fromFile is only available in Node.js environments. In the browser, read the file using the File API and pass the result to fromCSV (for text) or fromXLSX (for binary formats).");const s=r.extname(o).toLowerCase(),u=(e=>l[e.toLowerCase()])(s);if(!u){const e=Object.keys(l).join(", ");throw new Error(`Unsupported file extension "${s||"(none)"}". Supported: ${e}`)}const a=yield t(o);return((t,r,o)=>e(void 0,void 0,void 0,function*(){switch(r){case"csv":case"tsv":if("string"!=typeof t)throw new TypeError(`${r.toUpperCase()} parsing requires a string input, but received an ArrayBuffer.`);return b(t,r,o);case"xlsx":case"xls":case"ods":if("string"==typeof t)throw new TypeError(`${r.toUpperCase()} parsing requires an ArrayBuffer input, but received a string.`);return $(t,r,o);default:throw new Error(`Unsupported format "${r}". Supported formats: csv, tsv, xlsx, xls, ods`)}}))(i.has(u)?"string"==typeof a?a:a.toString("utf-8"):a instanceof Buffer?a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength):a,u,n)});export{S as fromFile};
|
package/dist/ods.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("exceljs"),r=require("@graphysdk/core/node");const o=/[^\p{ASCII}]/u,
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("exceljs"),r=require("@graphysdk/core/node");const o=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},n=["dataValidations","conditionalFormatting","sheetProtection"];const l=/[^\p{ASCII}]/u,i=/[\u2012\u2013\u2014\u2212](?=\d)/g,u=/\u00A0/g,s=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,c=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,a=new Set(["PT_PT","AR"]),f=(e,t="EN_US")=>{let r;if(r=l.test(e)?e.replace(i,"-").replace(u," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(a.has(t)){if(c.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(s.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},d=(l,i)=>e.__awaiter(void 0,void 0,void 0,function*(){var u,s,c,a,d;const m=1024*(null!==(u=null==i?void 0:i.maxFileSize)&&void 0!==u?u:5)*1024;if(l.byteLength>m)throw new Error(`Input size (${l.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(s=null==i?void 0:i.maxFileSize)&&void 0!==s?s:5} MB).`);const h=null!==(c=null==i?void 0:i.locale)&&void 0!==c?c:"EN_US",w=yield function(r){return e.__awaiter(this,void 0,void 0,function*(){const e=new t.Workbook;return yield e.xlsx.load(r,{ignoreNodes:n}),e})}(l),p=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const r=e.worksheets[t];if(!r)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return r}const r=e.getWorksheet(t);if(!r){const r=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${r}`)}return r})(w,null==i?void 0:i.sheet);if(!p||0===p.rowCount)return{columns:[],rows:[]};const v=p.columnCount;if(0===v)return{columns:[],rows:[]};const g=p.getRow(1),b=[];for(let e=1;e<=v;e++){const t=g.getCell(e).value;b.push(String(null!=t?t:""))}const y=((e,t)=>{var o;const n=[];for(let l=0;l<t;l++){const t=null===(o=null==e?void 0:e[l])||void 0===o?void 0:o.trim(),i={key:r.columnIndexToPropertyKey(l)};t&&(i.label=t),n.push(i)}return n})(b,v),x=null!==(a=null==i?void 0:i.maxRows)&&void 0!==a?a:1e5,S=null!==(d=null==i?void 0:i.maxCells)&&void 0!==d?d:5e6,$=[];let k=0,C=0;for(let e=2;e<=p.rowCount;e++){if(k++,k>x)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${x}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=p.getRow(e),r=[];for(let e=1;e<=v;e++)r.push(o(t.getCell(e)));$.push(r)}const E=((e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];o[l.key]=null==i||""===i?null:"number"==typeof i?i:f(String(i),r)}return o}))($,y,h);return{columns:y,rows:E}});exports.fromODS=(e,t)=>d(e,t);
|
package/dist/ods.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import t from"exceljs";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";const r=/[^\p{ASCII}]/u,
|
|
1
|
+
import{__awaiter as e}from"tslib";import t from"exceljs";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";const r=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},n=["dataValidations","conditionalFormatting","sheetProtection"];const l=/[^\p{ASCII}]/u,i=/[\u2012\u2013\u2014\u2212](?=\d)/g,s=/\u00A0/g,u=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,f=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,c=new Set(["PT_PT","AR"]),d=(e,t="EN_US")=>{let o;if(o=l.test(e)?e.replace(i,"-").replace(s," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(c.has(t)){if(f.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(u.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},a=(l,i)=>e(void 0,void 0,void 0,function*(){var s,u,f,c,a;const m=1024*(null!==(s=null==i?void 0:i.maxFileSize)&&void 0!==s?s:5)*1024;if(l.byteLength>m)throw new Error(`Input size (${l.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(u=null==i?void 0:i.maxFileSize)&&void 0!==u?u:5} MB).`);const h=null!==(f=null==i?void 0:i.locale)&&void 0!==f?f:"EN_US",p=yield function(o){return e(this,void 0,void 0,function*(){const e=new t.Workbook;return yield e.xlsx.load(o,{ignoreNodes:n}),e})}(l),w=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const o=e.worksheets[t];if(!o)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return o}const o=e.getWorksheet(t);if(!o){const o=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${o}`)}return o})(p,null==i?void 0:i.sheet);if(!w||0===w.rowCount)return{columns:[],rows:[]};const v=w.columnCount;if(0===v)return{columns:[],rows:[]};const g=w.getRow(1),b=[];for(let e=1;e<=v;e++){const t=g.getCell(e).value;b.push(String(null!=t?t:""))}const x=((e,t)=>{var r;const n=[];for(let l=0;l<t;l++){const t=null===(r=null==e?void 0:e[l])||void 0===r?void 0:r.trim(),i={key:o(l)};t&&(i.label=t),n.push(i)}return n})(b,v),y=null!==(c=null==i?void 0:i.maxRows)&&void 0!==c?c:1e5,S=null!==(a=null==i?void 0:i.maxCells)&&void 0!==a?a:5e6,$=[];let k=0,C=0;for(let e=2;e<=w.rowCount;e++){if(k++,k>y)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=w.getRow(e),o=[];for(let e=1;e<=v;e++)o.push(r(t.getCell(e)));$.push(o)}const E=((e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];r[l.key]=null==i||""===i?null:"number"==typeof i?i:d(String(i),o)}return r}))($,x,h);return{columns:x,rows:E}}),m=(e,t)=>a(e,t);export{m as fromODS};
|
package/dist/url.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("papaparse"),o=require("@graphysdk/core/node"),r=require("exceljs");const n=new Set(["csv","tsv"]),s={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},i=new Set(["http:","https:"]),l=[/^127\./,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^0\.0\.0\.0$/],a=[/^::1$/,/^fc00:/i,/^fe80:/i],u=e=>{(e=>{if(!i.has(e.protocol))throw new Error(`Unsupported URL scheme: ${e.protocol}. Only http: and https: are supported.`)})(e),(e=>{const t=e.toLowerCase();if("localhost"===t)throw new Error(`Access to private network address is not allowed: ${e}`);const o=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t,r=l.some(e=>e.test(o)),n=a.some(e=>e.test(o));if(r||n)throw new Error(`Access to private network address is not allowed: ${e}`)})(e.hostname)},d=(e,t)=>{var r;const n=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:o.columnIndexToPropertyKey(s)};t&&(i.label=t),n.push(i)}return n},c=/[^\p{ASCII}]/u,f=/[\u2012\u2013\u2014\u2212](?=\d)/g,h=/\u00A0/g,p=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,w=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,m=new Set(["PT_PT","AR"]),v=(e,t="EN_US")=>{let o;if(o=c.test(e)?e.replace(f,"-").replace(h," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(m.has(t)){if(w.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(p.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},x=(e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];r[s.key]=null==i||""===i?null:"number"==typeof i?i:v(String(i),o)}return r}),y=(e,o,r)=>{var n,s,i,l,a;const u=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>u)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${u} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const c=!1!==(null==r?void 0:r.hasHeader),f=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",h=t.parse(e,{header:!1,delimiter:o,skipEmptyLines:!0}),p=h.errors.filter(e=>"Quotes"===e.type);if(p.length>0){const e=p[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const w=h.data;if(0===w.length)return{columns:[],rows:[]};const m=c?w[0]:void 0,v=c?w.slice(1):w,y=w.reduce((e,t)=>Math.max(e,t.length),0),g=d(m,y);return{columns:g,rows:x(v,g,f)}},g=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},b=(t,o)=>e.__awaiter(void 0,void 0,void 0,function*(){var
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("papaparse"),o=require("@graphysdk/core/node"),r=require("exceljs");const n=new Set(["csv","tsv"]),s={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},i=new Set(["http:","https:"]),l=[/^127\./,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^0\.0\.0\.0$/],a=[/^::1$/,/^fc00:/i,/^fe80:/i],u=e=>{(e=>{if(!i.has(e.protocol))throw new Error(`Unsupported URL scheme: ${e.protocol}. Only http: and https: are supported.`)})(e),(e=>{const t=e.toLowerCase();if("localhost"===t)throw new Error(`Access to private network address is not allowed: ${e}`);const o=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t,r=l.some(e=>e.test(o)),n=a.some(e=>e.test(o));if(r||n)throw new Error(`Access to private network address is not allowed: ${e}`)})(e.hostname)},d=(e,t)=>{var r;const n=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:o.columnIndexToPropertyKey(s)};t&&(i.label=t),n.push(i)}return n},c=/[^\p{ASCII}]/u,f=/[\u2012\u2013\u2014\u2212](?=\d)/g,h=/\u00A0/g,p=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,w=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,m=new Set(["PT_PT","AR"]),v=(e,t="EN_US")=>{let o;if(o=c.test(e)?e.replace(f,"-").replace(h," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(m.has(t)){if(w.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(p.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},x=(e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];r[s.key]=null==i||""===i?null:"number"==typeof i?i:v(String(i),o)}return r}),y=(e,o,r)=>{var n,s,i,l,a;const u=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>u)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${u} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const c=!1!==(null==r?void 0:r.hasHeader),f=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",h=t.parse(e,{header:!1,delimiter:o,skipEmptyLines:!0}),p=h.errors.filter(e=>"Quotes"===e.type);if(p.length>0){const e=p[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(a=null==e?void 0:e.message)&&void 0!==a?a:"Unknown error"}`)}const w=h.data;if(0===w.length)return{columns:[],rows:[]};const m=c?w[0]:void 0,v=c?w.slice(1):w,y=w.reduce((e,t)=>Math.max(e,t.length),0),g=d(m,y);return{columns:g,rows:x(v,g,f)}},g=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},b=["dataValidations","conditionalFormatting","sheetProtection"];const $=(t,o)=>e.__awaiter(void 0,void 0,void 0,function*(){var n,s,i,l,a;const u=1024*(null!==(n=null==o?void 0:o.maxFileSize)&&void 0!==n?n:5)*1024;if(t.byteLength>u)throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${u} bytes (${null!==(s=null==o?void 0:o.maxFileSize)&&void 0!==s?s:5} MB).`);const c=null!==(i=null==o?void 0:o.locale)&&void 0!==i?i:"EN_US",f=yield function(t){return e.__awaiter(this,void 0,void 0,function*(){const e=new r.Workbook;return yield e.xlsx.load(t,{ignoreNodes:b}),e})}(t),h=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const o=e.worksheets[t];if(!o)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return o}const o=e.getWorksheet(t);if(!o){const o=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${o}`)}return o})(f,null==o?void 0:o.sheet);if(!h||0===h.rowCount)return{columns:[],rows:[]};const p=h.columnCount;if(0===p)return{columns:[],rows:[]};const w=h.getRow(1),m=[];for(let e=1;e<=p;e++){const t=w.getCell(e).value;m.push(String(null!=t?t:""))}const v=d(m,p),y=null!==(l=null==o?void 0:o.maxRows)&&void 0!==l?l:1e5,$=null!==(a=null==o?void 0:o.maxCells)&&void 0!==a?a:5e6,E=[];let S=0,z=0;for(let e=2;e<=h.rowCount;e++){if(S++,S>y)throw new Error(`Row limit exceeded: processed ${S} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(z+=p,z>$)throw new Error(`Cell limit exceeded: processed ${z} cells (maximum: ${$}). Use the maxCells option to increase the limit.`);const t=h.getRow(e),o=[];for(let e=1;e<=p;e++)o.push(g(t.getCell(e)));E.push(o)}return{columns:v,rows:x(E,v,c)}}),E=(e,t,o)=>{switch(t){case"csv":return((e,t)=>y(e,void 0,t))(e,o);case"tsv":return((e,t)=>y(e,"\t",t))(e,o);default:throw new Error(`Unsupported text format "${t}". Supported: csv, tsv`)}},S=(t,o,r)=>e.__awaiter(void 0,void 0,void 0,function*(){switch(o){case"xlsx":case"xls":case"ods":return((e,t)=>$(e,t))(t,r);default:throw new Error(`Unsupported binary format "${o}". Supported: xlsx, xls, ods`)}}),z={"text/csv":"csv","text/tab-separated-values":"tsv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-excel":"xls","application/vnd.oasis.opendocument.spreadsheet":"ods"};exports.fromURL=(t,o)=>e.__awaiter(void 0,void 0,void 0,function*(){var r,i,l;const a=new URL(t);u(a);const{pathname:d}=a,c=d.lastIndexOf("."),f=(e=>s[e.toLowerCase()])(-1===c?"":d.slice(c)),h=AbortSignal.timeout(null!==(r=null==o?void 0:o.timeout)&&void 0!==r?r:3e4),p={signal:(null==o?void 0:o.signal)?AbortSignal.any([h,o.signal]):h};(null==o?void 0:o.headers)&&(p.headers=o.headers);const w=yield fetch(t,p);if(!w.ok)throw new Error(`Failed to fetch "${t}": ${w.status} ${w.statusText}`);const m=null!=f?f:(e=>{var t;if(!e)return;const o=null===(t=e.split(";")[0])||void 0===t?void 0:t.trim().toLowerCase();return o?z[o]:void 0})(w.headers.get("content-type"));if(!m){const e=Object.keys(s).join(", ");throw new Error(`Could not detect format for "${t}". No recognized file extension or Content-Type. Supported extensions: ${e}`)}const v=1024*(null!==(i=null==o?void 0:o.maxFileSize)&&void 0!==i?i:5)*1024,x=w.headers.get("content-length");if(x&&Number(x)>v)throw new Error(`Response size (${x} bytes) exceeds the maximum allowed size of ${v} bytes (${null!==(l=null==o?void 0:o.maxFileSize)&&void 0!==l?l:5} MB).`);const y=n.has(m),g=yield((t,o,r)=>e.__awaiter(void 0,void 0,void 0,function*(){const e=t.body;if(!e){if(r){const e=yield t.text(),r=(new TextEncoder).encode(e).byteLength;if(r>o)throw new Error(`Response body size (${r} bytes) exceeds the maximum allowed size of ${o} bytes.`);return e}const e=yield t.arrayBuffer();if(e.byteLength>o)throw new Error(`Response body size (${e.byteLength} bytes) exceeds the maximum allowed size of ${o} bytes.`);return e}const n=e.getReader(),s=[];let i=0;try{for(;;){const{done:e,value:t}=yield n.read();if(e)break;if(i+=t.byteLength,i>o)throw yield n.cancel(),new Error(`Response body size exceeds the maximum allowed size of ${o} bytes. Download aborted.`);s.push(t)}}catch(e){if(e instanceof Error&&e.message.includes("maximum allowed size"))throw e;throw yield n.cancel().catch(()=>{}),e}if(r){const e=new TextDecoder;return s.map(t=>e.decode(t,{stream:!0})).join("")+e.decode()}const l=new Uint8Array(i);let a=0;for(const e of s)l.set(e,a),a+=e.byteLength;return l.buffer}))(w,v,y);return((t,o,r)=>e.__awaiter(void 0,void 0,void 0,function*(){switch(o){case"csv":case"tsv":if("string"!=typeof t)throw new TypeError(`${o.toUpperCase()} parsing requires a string input, but received an ArrayBuffer.`);return E(t,o,r);case"xlsx":case"xls":case"ods":if("string"==typeof t)throw new TypeError(`${o.toUpperCase()} parsing requires an ArrayBuffer input, but received a string.`);return S(t,o,r);default:throw new Error(`Unsupported format "${o}". Supported formats: csv, tsv, xlsx, xls, ods`)}}))(g,m,o)});
|
package/dist/url.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import t from"papaparse";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";import r from"exceljs";const n=new Set(["csv","tsv"]),s={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},i=new Set(["http:","https:"]),l=[/^127\./,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^0\.0\.0\.0$/],u=[/^::1$/,/^fc00:/i,/^fe80:/i],a=e=>{(e=>{if(!i.has(e.protocol))throw new Error(`Unsupported URL scheme: ${e.protocol}. Only http: and https: are supported.`)})(e),(e=>{const t=e.toLowerCase();if("localhost"===t)throw new Error(`Access to private network address is not allowed: ${e}`);const o=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t,r=l.some(e=>e.test(o)),n=u.some(e=>e.test(o));if(r||n)throw new Error(`Access to private network address is not allowed: ${e}`)})(e.hostname)},d=(e,t)=>{var r;const n=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:o(s)};t&&(i.label=t),n.push(i)}return n},c=/[^\p{ASCII}]/u,f=/[\u2012\u2013\u2014\u2212](?=\d)/g,
|
|
1
|
+
import{__awaiter as e}from"tslib";import t from"papaparse";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";import r from"exceljs";const n=new Set(["csv","tsv"]),s={".csv":"csv",".tsv":"tsv",".tab":"tsv",".xlsx":"xlsx",".xls":"xls",".ods":"ods"},i=new Set(["http:","https:"]),l=[/^127\./,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^0\.0\.0\.0$/],u=[/^::1$/,/^fc00:/i,/^fe80:/i],a=e=>{(e=>{if(!i.has(e.protocol))throw new Error(`Unsupported URL scheme: ${e.protocol}. Only http: and https: are supported.`)})(e),(e=>{const t=e.toLowerCase();if("localhost"===t)throw new Error(`Access to private network address is not allowed: ${e}`);const o=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t,r=l.some(e=>e.test(o)),n=u.some(e=>e.test(o));if(r||n)throw new Error(`Access to private network address is not allowed: ${e}`)})(e.hostname)},d=(e,t)=>{var r;const n=[];for(let s=0;s<t;s++){const t=null===(r=null==e?void 0:e[s])||void 0===r?void 0:r.trim(),i={key:o(s)};t&&(i.label=t),n.push(i)}return n},c=/[^\p{ASCII}]/u,f=/[\u2012\u2013\u2014\u2212](?=\d)/g,h=/\u00A0/g,p=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,m=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,v=new Set(["PT_PT","AR"]),w=(e,t="EN_US")=>{let o;if(o=c.test(e)?e.replace(f,"-").replace(h," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(v.has(t)){if(m.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(p.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},x=(e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const s=t[n];if(!s)continue;const i=e[n];r[s.key]=null==i||""===i?null:"number"==typeof i?i:w(String(i),o)}return r}),y=(e,o,r)=>{var n,s,i,l,u;const a=1024*(null!==(n=null==r?void 0:r.maxFileSize)&&void 0!==n?n:5)*1024;if(e.length>a)throw new Error(`Input size (${e.length} bytes) exceeds the maximum allowed size of ${a} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const c=!1!==(null==r?void 0:r.hasHeader),f=null!==(i=null==r?void 0:r.locale)&&void 0!==i?i:"EN_US",h=t.parse(e,{header:!1,delimiter:o,skipEmptyLines:!0}),p=h.errors.filter(e=>"Quotes"===e.type);if(p.length>0){const e=p[0];throw new Error(`Parse error at row ${null!==(l=null==e?void 0:e.row)&&void 0!==l?l:"?"}: ${null!==(u=null==e?void 0:e.message)&&void 0!==u?u:"Unknown error"}`)}const m=h.data;if(0===m.length)return{columns:[],rows:[]};const v=c?m[0]:void 0,w=c?m.slice(1):m,y=m.reduce((e,t)=>Math.max(e,t.length),0),g=d(v,y);return{columns:g,rows:x(w,g,f)}},g=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},b=["dataValidations","conditionalFormatting","sheetProtection"];const $=(t,o)=>e(void 0,void 0,void 0,function*(){var n,s,i,l,u;const a=1024*(null!==(n=null==o?void 0:o.maxFileSize)&&void 0!==n?n:5)*1024;if(t.byteLength>a)throw new Error(`Input size (${t.byteLength} bytes) exceeds the maximum allowed size of ${a} bytes (${null!==(s=null==o?void 0:o.maxFileSize)&&void 0!==s?s:5} MB).`);const c=null!==(i=null==o?void 0:o.locale)&&void 0!==i?i:"EN_US",f=yield function(t){return e(this,void 0,void 0,function*(){const e=new r.Workbook;return yield e.xlsx.load(t,{ignoreNodes:b}),e})}(t),h=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const o=e.worksheets[t];if(!o)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return o}const o=e.getWorksheet(t);if(!o){const o=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${o}`)}return o})(f,null==o?void 0:o.sheet);if(!h||0===h.rowCount)return{columns:[],rows:[]};const p=h.columnCount;if(0===p)return{columns:[],rows:[]};const m=h.getRow(1),v=[];for(let e=1;e<=p;e++){const t=m.getCell(e).value;v.push(String(null!=t?t:""))}const w=d(v,p),y=null!==(l=null==o?void 0:o.maxRows)&&void 0!==l?l:1e5,$=null!==(u=null==o?void 0:o.maxCells)&&void 0!==u?u:5e6,E=[];let S=0,z=0;for(let e=2;e<=h.rowCount;e++){if(S++,S>y)throw new Error(`Row limit exceeded: processed ${S} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(z+=p,z>$)throw new Error(`Cell limit exceeded: processed ${z} cells (maximum: ${$}). Use the maxCells option to increase the limit.`);const t=h.getRow(e),o=[];for(let e=1;e<=p;e++)o.push(g(t.getCell(e)));E.push(o)}return{columns:w,rows:x(E,w,c)}}),E=(e,t,o)=>{switch(t){case"csv":return((e,t)=>y(e,void 0,t))(e,o);case"tsv":return((e,t)=>y(e,"\t",t))(e,o);default:throw new Error(`Unsupported text format "${t}". Supported: csv, tsv`)}},S=(t,o,r)=>e(void 0,void 0,void 0,function*(){switch(o){case"xlsx":case"xls":case"ods":return((e,t)=>$(e,t))(t,r);default:throw new Error(`Unsupported binary format "${o}". Supported: xlsx, xls, ods`)}}),z={"text/csv":"csv","text/tab-separated-values":"tsv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-excel":"xls","application/vnd.oasis.opendocument.spreadsheet":"ods"},k=(t,o)=>e(void 0,void 0,void 0,function*(){var r,i,l;const u=new URL(t);a(u);const{pathname:d}=u,c=d.lastIndexOf("."),f=(e=>s[e.toLowerCase()])(-1===c?"":d.slice(c)),h=AbortSignal.timeout(null!==(r=null==o?void 0:o.timeout)&&void 0!==r?r:3e4),p={signal:(null==o?void 0:o.signal)?AbortSignal.any([h,o.signal]):h};(null==o?void 0:o.headers)&&(p.headers=o.headers);const m=yield fetch(t,p);if(!m.ok)throw new Error(`Failed to fetch "${t}": ${m.status} ${m.statusText}`);const v=null!=f?f:(e=>{var t;if(!e)return;const o=null===(t=e.split(";")[0])||void 0===t?void 0:t.trim().toLowerCase();return o?z[o]:void 0})(m.headers.get("content-type"));if(!v){const e=Object.keys(s).join(", ");throw new Error(`Could not detect format for "${t}". No recognized file extension or Content-Type. Supported extensions: ${e}`)}const w=1024*(null!==(i=null==o?void 0:o.maxFileSize)&&void 0!==i?i:5)*1024,x=m.headers.get("content-length");if(x&&Number(x)>w)throw new Error(`Response size (${x} bytes) exceeds the maximum allowed size of ${w} bytes (${null!==(l=null==o?void 0:o.maxFileSize)&&void 0!==l?l:5} MB).`);const y=n.has(v),g=yield((t,o,r)=>e(void 0,void 0,void 0,function*(){const e=t.body;if(!e){if(r){const e=yield t.text(),r=(new TextEncoder).encode(e).byteLength;if(r>o)throw new Error(`Response body size (${r} bytes) exceeds the maximum allowed size of ${o} bytes.`);return e}const e=yield t.arrayBuffer();if(e.byteLength>o)throw new Error(`Response body size (${e.byteLength} bytes) exceeds the maximum allowed size of ${o} bytes.`);return e}const n=e.getReader(),s=[];let i=0;try{for(;;){const{done:e,value:t}=yield n.read();if(e)break;if(i+=t.byteLength,i>o)throw yield n.cancel(),new Error(`Response body size exceeds the maximum allowed size of ${o} bytes. Download aborted.`);s.push(t)}}catch(e){if(e instanceof Error&&e.message.includes("maximum allowed size"))throw e;throw yield n.cancel().catch(()=>{}),e}if(r){const e=new TextDecoder;return s.map(t=>e.decode(t,{stream:!0})).join("")+e.decode()}const l=new Uint8Array(i);let u=0;for(const e of s)l.set(e,u),u+=e.byteLength;return l.buffer}))(m,w,y);return((t,o,r)=>e(void 0,void 0,void 0,function*(){switch(o){case"csv":case"tsv":if("string"!=typeof t)throw new TypeError(`${o.toUpperCase()} parsing requires a string input, but received an ArrayBuffer.`);return E(t,o,r);case"xlsx":case"xls":case"ods":if("string"==typeof t)throw new TypeError(`${o.toUpperCase()} parsing requires an ArrayBuffer input, but received a string.`);return S(t,o,r);default:throw new Error(`Unsupported format "${o}". Supported formats: csv, tsv, xlsx, xls, ods`)}}))(g,v,o)});export{k as fromURL};
|
package/dist/xls.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("exceljs"),r=require("@graphysdk/core/node");const o=/[^\p{ASCII}]/u,
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("exceljs"),r=require("@graphysdk/core/node");const o=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const r=e.text;return""===r?null:r},n=["dataValidations","conditionalFormatting","sheetProtection"];const l=/[^\p{ASCII}]/u,i=/[\u2012\u2013\u2014\u2212](?=\d)/g,u=/\u00A0/g,s=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,c=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,a=new Set(["PT_PT","AR"]),f=(e,t="EN_US")=>{let r;if(r=l.test(e)?e.replace(i,"-").replace(u," ").trim():e.trim(),""===r)return null;if(r.length>100)return r;if(a.has(t)){if(c.test(r)){const e=r.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(s.test(r)){const e=r.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return r},d=(l,i)=>e.__awaiter(void 0,void 0,void 0,function*(){var u,s,c,a,d;const m=1024*(null!==(u=null==i?void 0:i.maxFileSize)&&void 0!==u?u:5)*1024;if(l.byteLength>m)throw new Error(`Input size (${l.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(s=null==i?void 0:i.maxFileSize)&&void 0!==s?s:5} MB).`);const h=null!==(c=null==i?void 0:i.locale)&&void 0!==c?c:"EN_US",w=yield function(r){return e.__awaiter(this,void 0,void 0,function*(){const e=new t.Workbook;return yield e.xlsx.load(r,{ignoreNodes:n}),e})}(l),p=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const r=e.worksheets[t];if(!r)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return r}const r=e.getWorksheet(t);if(!r){const r=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${r}`)}return r})(w,null==i?void 0:i.sheet);if(!p||0===p.rowCount)return{columns:[],rows:[]};const v=p.columnCount;if(0===v)return{columns:[],rows:[]};const g=p.getRow(1),b=[];for(let e=1;e<=v;e++){const t=g.getCell(e).value;b.push(String(null!=t?t:""))}const y=((e,t)=>{var o;const n=[];for(let l=0;l<t;l++){const t=null===(o=null==e?void 0:e[l])||void 0===o?void 0:o.trim(),i={key:r.columnIndexToPropertyKey(l)};t&&(i.label=t),n.push(i)}return n})(b,v),x=null!==(a=null==i?void 0:i.maxRows)&&void 0!==a?a:1e5,S=null!==(d=null==i?void 0:i.maxCells)&&void 0!==d?d:5e6,$=[];let k=0,C=0;for(let e=2;e<=p.rowCount;e++){if(k++,k>x)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${x}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=p.getRow(e),r=[];for(let e=1;e<=v;e++)r.push(o(t.getCell(e)));$.push(r)}const E=((e,t,r)=>e.map(e=>{const o={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];o[l.key]=null==i||""===i?null:"number"==typeof i?i:f(String(i),r)}return o}))($,y,h);return{columns:y,rows:E}});exports.fromXLS=(e,t)=>d(e,t);
|
package/dist/xls.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import t from"exceljs";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";const r=/[^\p{ASCII}]/u,
|
|
1
|
+
import{__awaiter as e}from"tslib";import t from"exceljs";import{columnIndexToPropertyKey as o}from"@graphysdk/core/node";const r=e=>{const{value:t}=e;if(null==t)return null;if("number"==typeof t)return t;if("string"==typeof t)return""===t?null:t;if("boolean"==typeof t)return t?1:0;if(t instanceof Date)return t.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(t)){if("number"==typeof t.result)return t.result;if("string"==typeof t.result)return""===t.result?null:t.result;if("boolean"==typeof t.result)return t.result?1:0;if(t.result instanceof Date)return t.result.toISOString()}const o=e.text;return""===o?null:o},n=["dataValidations","conditionalFormatting","sheetProtection"];const l=/[^\p{ASCII}]/u,i=/[\u2012\u2013\u2014\u2212](?=\d)/g,s=/\u00A0/g,u=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,f=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,c=new Set(["PT_PT","AR"]),d=(e,t="EN_US")=>{let o;if(o=l.test(e)?e.replace(i,"-").replace(s," ").trim():e.trim(),""===o)return null;if(o.length>100)return o;if(c.has(t)){if(f.test(o)){const e=o.replace(/\./g,"").replace(",","."),t=Number(e);if(Number.isFinite(t))return t}}else if(u.test(o)){const e=o.replace(/,/g,""),t=Number(e);if(Number.isFinite(t))return t}return o},a=(l,i)=>e(void 0,void 0,void 0,function*(){var s,u,f,c,a;const m=1024*(null!==(s=null==i?void 0:i.maxFileSize)&&void 0!==s?s:5)*1024;if(l.byteLength>m)throw new Error(`Input size (${l.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(u=null==i?void 0:i.maxFileSize)&&void 0!==u?u:5} MB).`);const h=null!==(f=null==i?void 0:i.locale)&&void 0!==f?f:"EN_US",p=yield function(o){return e(this,void 0,void 0,function*(){const e=new t.Workbook;return yield e.xlsx.load(o,{ignoreNodes:n}),e})}(l),w=((e,t)=>{if(void 0===t)return e.worksheets[0];if("number"==typeof t){const o=e.worksheets[t];if(!o)throw new Error(`Sheet index ${t} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return o}const o=e.getWorksheet(t);if(!o){const o=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${t}" not found. Available sheets: ${o}`)}return o})(p,null==i?void 0:i.sheet);if(!w||0===w.rowCount)return{columns:[],rows:[]};const v=w.columnCount;if(0===v)return{columns:[],rows:[]};const g=w.getRow(1),b=[];for(let e=1;e<=v;e++){const t=g.getCell(e).value;b.push(String(null!=t?t:""))}const x=((e,t)=>{var r;const n=[];for(let l=0;l<t;l++){const t=null===(r=null==e?void 0:e[l])||void 0===r?void 0:r.trim(),i={key:o(l)};t&&(i.label=t),n.push(i)}return n})(b,v),y=null!==(c=null==i?void 0:i.maxRows)&&void 0!==c?c:1e5,S=null!==(a=null==i?void 0:i.maxCells)&&void 0!==a?a:5e6,$=[];let k=0,C=0;for(let e=2;e<=w.rowCount;e++){if(k++,k>y)throw new Error(`Row limit exceeded: processed ${k} rows (maximum: ${y}). Use the maxRows option to increase the limit.`);if(C+=v,C>S)throw new Error(`Cell limit exceeded: processed ${C} cells (maximum: ${S}). Use the maxCells option to increase the limit.`);const t=w.getRow(e),o=[];for(let e=1;e<=v;e++)o.push(r(t.getCell(e)));$.push(o)}const E=((e,t,o)=>e.map(e=>{const r={};for(let n=0;n<t.length;n++){const l=t[n];if(!l)continue;const i=e[n];r[l.key]=null==i||""===i?null:"number"==typeof i?i:d(String(i),o)}return r}))($,x,h);return{columns:x,rows:E}}),m=(e,t)=>a(e,t);export{m as fromXLS};
|
package/dist/xlsx.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),
|
|
1
|
+
"use strict";var e=require("tslib"),o=require("exceljs"),t=require("@graphysdk/core/node");const n=e=>{const{value:o}=e;if(null==o)return null;if("number"==typeof o)return o;if("string"==typeof o)return""===o?null:o;if("boolean"==typeof o)return o?1:0;if(o instanceof Date)return o.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(o)){if("number"==typeof o.result)return o.result;if("string"==typeof o.result)return""===o.result?null:o.result;if("boolean"==typeof o.result)return o.result?1:0;if(o.result instanceof Date)return o.result.toISOString()}const t=e.text;return""===t?null:t},r=["dataValidations","conditionalFormatting","sheetProtection"];function i(t){return e.__awaiter(this,void 0,void 0,function*(){const e=new o.Workbook;return yield e.xlsx.load(t,{ignoreNodes:r}),e})}const l=5e6,s=/[^\p{ASCII}]/u,u=/[\u2012\u2013\u2014\u2212](?=\d)/g,a=/\u00A0/g,c=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,d=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,f=new Set(["PT_PT","AR"]),m=(e,o="EN_US")=>{let t;if(t=s.test(e)?e.replace(u,"-").replace(a," ").trim():e.trim(),""===t)return null;if(t.length>100)return t;if(f.has(o)){if(d.test(t)){const e=t.replace(/\./g,"").replace(",","."),o=Number(e);if(Number.isFinite(o))return o}}else if(c.test(t)){const e=t.replace(/,/g,""),o=Number(e);if(Number.isFinite(o))return o}return t},h=(o,r)=>e.__awaiter(void 0,void 0,void 0,function*(){var e,s,u,a,c;const d=1024*(null!==(e=null==r?void 0:r.maxFileSize)&&void 0!==e?e:5)*1024;if(o.byteLength>d)throw new Error(`Input size (${o.byteLength} bytes) exceeds the maximum allowed size of ${d} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=null!==(u=null==r?void 0:r.locale)&&void 0!==u?u:"EN_US",h=((e,o)=>{if(void 0===o)return e.worksheets[0];if("number"==typeof o){const t=e.worksheets[o];if(!t)throw new Error(`Sheet index ${o} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return t}const t=e.getWorksheet(o);if(!t){const t=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${o}" not found. Available sheets: ${t}`)}return t})(yield i(o),null==r?void 0:r.sheet);if(!h||0===h.rowCount)return{columns:[],rows:[]};const w=h.columnCount;if(0===w)return{columns:[],rows:[]};const x=h.getRow(1),p=[];for(let e=1;e<=w;e++){const o=x.getCell(e).value;p.push(String(null!=o?o:""))}const M=((e,o)=>{var n;const r=[];for(let i=0;i<o;i++){const o=null===(n=null==e?void 0:e[i])||void 0===n?void 0:n.trim(),l={key:t.columnIndexToPropertyKey(i)};o&&(l.label=o),r.push(l)}return r})(p,w),g=null!==(a=null==r?void 0:r.maxRows)&&void 0!==a?a:1e5,b=null!==(c=null==r?void 0:r.maxCells)&&void 0!==c?c:l,E=[];let I=0,N=0;for(let e=2;e<=h.rowCount;e++){if(I++,I>g)throw new Error(`Row limit exceeded: processed ${I} rows (maximum: ${g}). Use the maxRows option to increase the limit.`);if(N+=w,N>b)throw new Error(`Cell limit exceeded: processed ${N} cells (maximum: ${b}). Use the maxCells option to increase the limit.`);const o=h.getRow(e),t=[];for(let e=1;e<=w;e++)t.push(n(o.getCell(e)));E.push(t)}const v=((e,o,t)=>e.map(e=>{const n={};for(let r=0;r<o.length;r++){const i=o[r];if(!i)continue;const l=e[r];n[i.key]=null==l||""===l?null:"number"==typeof l?l:m(String(l),t)}return n}))(E,M,f);return{columns:M,rows:v}}),w=1048576;function x(e,o,t){if(!Number.isInteger(o)||o<1||o>t)throw new Error(`${e} must be an integer between 1 and ${t} (1-based Excel index), got ${String(o)}`)}function p(e,o,t,r){const{rowMin:i,rowMax:l,colMin:s,colMax:u}=t;if(x("rowMin",i,w),x("rowMax",l,w),x("colMin",s,16384),x("colMax",u,16384),i>l||s>u)throw new Error(`Invalid region bounds: rowMin=${i}, rowMax=${l}, colMin=${s}, colMax=${u}`);const a=function(e){var o;const t=null!==(o=null==e?void 0:e.maxCells)&&void 0!==o?o:5e4;if(!Number.isInteger(t)||!Number.isFinite(t)||t<1)throw new Error(`maxCells must be a finite integer >= 1, got ${String(null==e?void 0:e.maxCells)}`);return t}(r),c=function(e,o){const t=e.worksheets[o];if(!t)throw new Error(`Sheet index ${o} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return t}(e,o),d=c.name,f=u-s+1;if(f>a)throw new Error(`Region requires ${f} cells per row, which exceeds maxCells (${a}); cannot return complete rows.`);const m=[];let h=0,p=!1;for(let e=i;e<=l;e++){if(h+f>a){p=!0;break}const o=[],t=c.getRow(e);for(let e=s;e<=u;e++)o.push(n(t.getCell(e)));m.push(o),h+=f}return{sheetIndex:o,sheetName:d,rowMin:i,rowMax:i+m.length-1,colMin:s,colMax:u,rows:m,truncated:p,returnedCellCount:h}}const M=65536,g=(e,o)=>e*M+o,b=e=>[Math.floor(e/M),e%M],E=l;function I(e){let o=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(const i of e){const[e,l]=b(i);o=Math.min(o,e),t=Math.max(t,e),n=Math.min(n,l),r=Math.max(r,l)}return{rowMin:o,rowMax:t,colMin:n,colMax:r}}function N(e,o,t,r){const i=e.name,l=function(e,o,t){const r=new Set;return e.eachRow({includeEmpty:!1},(e,i)=>{e.eachCell({includeEmpty:!1},(e,l)=>{if(null!==n(e)){if(o.remaining<=0)throw new Error(`Workbook index exceeded maxNonEmptyCells limit (${t}). Refine the workbook or pass a higher maxNonEmptyCells.`);o.remaining-=1,r.add(g(i,l))}})}),r}(e,t,r),s=l.size;if(0===s)return{sheet:{sheetName:i,sheetIndex:o,rowMin:null,rowMax:null,colMin:null,colMax:null,nonEmptyCellCount:0},islands:[]};const{rowMin:u,rowMax:a,colMin:c,colMax:d}=I([...l]),f=function(e){const o=[...e].sort((e,o)=>{const[t,n]=b(e),[r,i]=b(o);return t!==r?t-r:n-i}),t=new Set,n=[];for(const r of o){if(t.has(r))continue;const o=[],i=[r];for(t.add(r);i.length>0;){const n=i.pop();if(void 0===n)throw new Error("Unexpected empty DFS stack");o.push(n);const[r,l]=b(n);for(const[o,n]of[[1,0],[-1,0],[0,1],[0,-1]]){const s=g(r+o,l+n);e.has(s)&&!t.has(s)&&(t.add(s),i.push(s))}}n.push(o)}return n}(l),m=f.map(e=>{const t=I(e);return Object.assign(Object.assign({sheetIndex:o,sheetName:i},t),{cellCount:e.length})}).sort((e,o)=>e.rowMin-o.rowMin||e.colMin-o.colMin||e.rowMax-o.rowMax||e.colMax-o.colMax).map((e,t)=>Object.assign(Object.assign({},e),{localId:`${o}:${t}`}));return{sheet:{sheetName:i,sheetIndex:o,rowMin:u,rowMax:a,colMin:c,colMax:d,nonEmptyCellCount:s},islands:m}}function v(e,o){var t;const n=null!==(t=null==o?void 0:o.maxNonEmptyCells)&&void 0!==t?t:E;if(!Number.isInteger(n)||!Number.isFinite(n)||n<1)throw new Error(`maxNonEmptyCells must be a finite integer >= 1, got ${String(null==o?void 0:o.maxNonEmptyCells)}`);const r=[],i=[],l={remaining:n};return e.worksheets.forEach((e,o)=>{const{sheet:t,islands:s}=N(e,o,l,n);r.push(t),i.push(...s)}),{schemaVersion:1,sheets:r,islands:i}}exports.DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS=E,exports.DEFAULT_READ_REGION_MAX_CELLS=5e4,exports.WORKBOOK_INDEX_SCHEMA_VERSION=1,exports.buildWorkbookIndex=v,exports.buildWorkbookIndexFromXlsxBuffer=function(o,t){return e.__awaiter(this,void 0,void 0,function*(){return v(yield i(o),t)})},exports.extractCellPrimitive=n,exports.fromXLSX=(e,o)=>h(e,o),exports.loadWorkbookFromXlsxBuffer=i,exports.readIslandRegion=function(e,o,t){return p(e,o.sheetIndex,{rowMin:o.rowMin,rowMax:o.rowMax,colMin:o.colMin,colMax:o.colMax},t)},exports.readSheetRegion=p;
|
package/dist/xlsx.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VizLocale, GraphConfig } from '@graphysdk/core/node';
|
|
2
|
+
import ExcelJS from 'exceljs';
|
|
2
3
|
|
|
3
4
|
/** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
|
|
4
5
|
type Data = GraphConfig['data'];
|
|
@@ -24,5 +25,103 @@ interface SpreadsheetParseOptions extends BaseParseOptions {
|
|
|
24
25
|
*/
|
|
25
26
|
declare const fromXLSX: (input: ArrayBuffer, options?: SpreadsheetParseOptions) => Promise<Data>;
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Extracts a primitive value (`string | number | null`) from an ExcelJS cell.
|
|
30
|
+
* Handles numbers, strings, booleans, dates, formulas, rich text, hyperlinks, and errors.
|
|
31
|
+
* Shared by chart-oriented parsing (`fromXLSX`) and extract-oriented region reads.
|
|
32
|
+
*/
|
|
33
|
+
declare const extractCellPrimitive: (cell: ExcelJS.Cell) => string | number | null;
|
|
34
|
+
|
|
35
|
+
/** Loads an OOXML `.xlsx` buffer into an ExcelJS workbook (single-file extract pipeline). */
|
|
36
|
+
declare function loadWorkbookFromXlsxBuffer(input: ArrayBuffer): Promise<ExcelJS.Workbook>;
|
|
37
|
+
|
|
38
|
+
/** Bump when island rules or index shape changes (extract API stability). */
|
|
39
|
+
declare const WORKBOOK_INDEX_SCHEMA_VERSION: 1;
|
|
40
|
+
/** Default cap on total non-empty cells indexed across the workbook (aligns with {@link DEFAULT_MAX_CELLS}). */
|
|
41
|
+
declare const DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS = 5000000;
|
|
42
|
+
interface BuildWorkbookIndexOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Abort if the workbook would exceed this many non-empty cells in total (memory / DoS guard).
|
|
45
|
+
* @default {@link DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS}
|
|
46
|
+
*/
|
|
47
|
+
maxNonEmptyCells?: number;
|
|
48
|
+
}
|
|
49
|
+
interface SheetIndexEntry {
|
|
50
|
+
sheetName: string;
|
|
51
|
+
/** 0-based order in the workbook. */
|
|
52
|
+
sheetIndex: number;
|
|
53
|
+
/** Inclusive 1-based Excel row/column indices; `null` when the sheet has no data cells. */
|
|
54
|
+
rowMin: number | null;
|
|
55
|
+
rowMax: number | null;
|
|
56
|
+
colMin: number | null;
|
|
57
|
+
colMax: number | null;
|
|
58
|
+
nonEmptyCellCount: number;
|
|
59
|
+
}
|
|
60
|
+
interface IslandEntry {
|
|
61
|
+
/**
|
|
62
|
+
* Stable within a single file: `${sheetIndex}:${islandOrdinalOnSheet}`.
|
|
63
|
+
* Consumers prefix with request-level `fileIndex` for multi-file UX.
|
|
64
|
+
*/
|
|
65
|
+
localId: string;
|
|
66
|
+
sheetIndex: number;
|
|
67
|
+
sheetName: string;
|
|
68
|
+
rowMin: number;
|
|
69
|
+
rowMax: number;
|
|
70
|
+
colMin: number;
|
|
71
|
+
colMax: number;
|
|
72
|
+
/** Number of non-empty cells in this island (4-connected region). */
|
|
73
|
+
cellCount: number;
|
|
74
|
+
}
|
|
75
|
+
interface WorkbookIndex {
|
|
76
|
+
schemaVersion: typeof WORKBOOK_INDEX_SCHEMA_VERSION;
|
|
77
|
+
sheets: SheetIndexEntry[];
|
|
78
|
+
islands: IslandEntry[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Deterministic structural index for one loaded workbook: per-sheet used bounds and
|
|
82
|
+
* 4-connected **islands** of non-empty cells (using the same empty rules as {@link extractCellPrimitive}).
|
|
83
|
+
*/
|
|
84
|
+
declare function buildWorkbookIndex(workbook: ExcelJS.Workbook, options?: BuildWorkbookIndexOptions): WorkbookIndex;
|
|
85
|
+
/** Loads an `.xlsx` buffer and returns its structural index (no retained workbook handle). */
|
|
86
|
+
declare function buildWorkbookIndexFromXlsxBuffer(input: ArrayBuffer, options?: BuildWorkbookIndexOptions): Promise<WorkbookIndex>;
|
|
87
|
+
|
|
88
|
+
/** Default max cells returned by {@link readSheetRegion} (row-major fill). */
|
|
89
|
+
declare const DEFAULT_READ_REGION_MAX_CELLS = 50000;
|
|
90
|
+
interface ReadSheetRegionOptions {
|
|
91
|
+
/** Stop after this many cells (complete rows only — no partial trailing row). @default {@link DEFAULT_READ_REGION_MAX_CELLS} */
|
|
92
|
+
maxCells?: number;
|
|
93
|
+
}
|
|
94
|
+
interface ReadSheetRegionResult {
|
|
95
|
+
sheetIndex: number;
|
|
96
|
+
sheetName: string;
|
|
97
|
+
/**
|
|
98
|
+
* Inclusive 1-based Excel row for the first row in {@link rows} (always the requested `rowMin`).
|
|
99
|
+
*/
|
|
100
|
+
rowMin: number;
|
|
101
|
+
/**
|
|
102
|
+
* Inclusive 1-based Excel row for the last row in {@link rows} (`rowMin + rows.length - 1`).
|
|
103
|
+
* When {@link truncated} is false, this equals the requested `rowMax`.
|
|
104
|
+
*/
|
|
105
|
+
rowMax: number;
|
|
106
|
+
colMin: number;
|
|
107
|
+
colMax: number;
|
|
108
|
+
/** Row-major grid aligned to Excel indices; `rows[i]` is Excel row `rowMin + i`. */
|
|
109
|
+
rows: Array<Array<string | number | null>>;
|
|
110
|
+
truncated: boolean;
|
|
111
|
+
returnedCellCount: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reads a rectangular region (1-based inclusive Excel row/column indices) using the same cell rules as {@link extractCellPrimitive}.
|
|
115
|
+
* Enforces {@link ReadSheetRegionOptions.maxCells}; when exceeded, returns complete rows only and sets `truncated`.
|
|
116
|
+
*/
|
|
117
|
+
declare function readSheetRegion(workbook: ExcelJS.Workbook, sheetIndex: number, bounds: {
|
|
118
|
+
rowMin: number;
|
|
119
|
+
rowMax: number;
|
|
120
|
+
colMin: number;
|
|
121
|
+
colMax: number;
|
|
122
|
+
}, options?: ReadSheetRegionOptions): ReadSheetRegionResult;
|
|
123
|
+
/** Reads exactly the bounding box of an island entry from {@link buildWorkbookIndex}. */
|
|
124
|
+
declare function readIslandRegion(workbook: ExcelJS.Workbook, island: IslandEntry, options?: ReadSheetRegionOptions): ReadSheetRegionResult;
|
|
125
|
+
|
|
126
|
+
export { DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS, DEFAULT_READ_REGION_MAX_CELLS, WORKBOOK_INDEX_SCHEMA_VERSION, buildWorkbookIndex, buildWorkbookIndexFromXlsxBuffer, extractCellPrimitive, fromXLSX, loadWorkbookFromXlsxBuffer, readIslandRegion, readSheetRegion };
|
|
127
|
+
export type { BaseParseOptions, BuildWorkbookIndexOptions, IslandEntry, ReadSheetRegionOptions, ReadSheetRegionResult, SheetIndexEntry, SpreadsheetParseOptions, WorkbookIndex };
|
package/dist/xlsx.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"tslib";import
|
|
1
|
+
import{__awaiter as e}from"tslib";import n from"exceljs";import{columnIndexToPropertyKey as t}from"@graphysdk/core/node";const o=e=>{const{value:n}=e;if(null==n)return null;if("number"==typeof n)return n;if("string"==typeof n)return""===n?null:n;if("boolean"==typeof n)return n?1:0;if(n instanceof Date)return n.toISOString();if((e=>"object"==typeof e&&null!==e&&"formula"in e)(n)){if("number"==typeof n.result)return n.result;if("string"==typeof n.result)return""===n.result?null:n.result;if("boolean"==typeof n.result)return n.result?1:0;if(n.result instanceof Date)return n.result.toISOString()}const t=e.text;return""===t?null:t},r=["dataValidations","conditionalFormatting","sheetProtection"];function i(t){return e(this,void 0,void 0,function*(){const e=new n.Workbook;return yield e.xlsx.load(t,{ignoreNodes:r}),e})}const l=5e6,s=/[^\p{ASCII}]/u,u=/[\u2012\u2013\u2014\u2212](?=\d)/g,c=/\u00A0/g,a=/^-?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/,m=/^-?(?:\d{1,3}(?:\.\d{3})*|\d+)(?:,\d+)?$/,f=new Set(["PT_PT","AR"]),h=(e,n="EN_US")=>{let t;if(t=s.test(e)?e.replace(u,"-").replace(c," ").trim():e.trim(),""===t)return null;if(t.length>100)return t;if(f.has(n)){if(m.test(t)){const e=t.replace(/\./g,"").replace(",","."),n=Number(e);if(Number.isFinite(n))return n}}else if(a.test(t)){const e=t.replace(/,/g,""),n=Number(e);if(Number.isFinite(n))return n}return t},d=(n,r)=>e(void 0,void 0,void 0,function*(){var e,s,u,c,a;const m=1024*(null!==(e=null==r?void 0:r.maxFileSize)&&void 0!==e?e:5)*1024;if(n.byteLength>m)throw new Error(`Input size (${n.byteLength} bytes) exceeds the maximum allowed size of ${m} bytes (${null!==(s=null==r?void 0:r.maxFileSize)&&void 0!==s?s:5} MB).`);const f=null!==(u=null==r?void 0:r.locale)&&void 0!==u?u:"EN_US",d=((e,n)=>{if(void 0===n)return e.worksheets[0];if("number"==typeof n){const t=e.worksheets[n];if(!t)throw new Error(`Sheet index ${n} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return t}const t=e.getWorksheet(n);if(!t){const t=e.worksheets.map(e=>`"${e.name}"`).join(", ");throw new Error(`Sheet "${n}" not found. Available sheets: ${t}`)}return t})(yield i(n),null==r?void 0:r.sheet);if(!d||0===d.rowCount)return{columns:[],rows:[]};const w=d.columnCount;if(0===w)return{columns:[],rows:[]};const x=d.getRow(1),p=[];for(let e=1;e<=w;e++){const n=x.getCell(e).value;p.push(String(null!=n?n:""))}const M=((e,n)=>{var o;const r=[];for(let i=0;i<n;i++){const n=null===(o=null==e?void 0:e[i])||void 0===o?void 0:o.trim(),l={key:t(i)};n&&(l.label=n),r.push(l)}return r})(p,w),g=null!==(c=null==r?void 0:r.maxRows)&&void 0!==c?c:1e5,b=null!==(a=null==r?void 0:r.maxCells)&&void 0!==a?a:l,v=[];let N=0,I=0;for(let e=2;e<=d.rowCount;e++){if(N++,N>g)throw new Error(`Row limit exceeded: processed ${N} rows (maximum: ${g}). Use the maxRows option to increase the limit.`);if(I+=w,I>b)throw new Error(`Cell limit exceeded: processed ${I} cells (maximum: ${b}). Use the maxCells option to increase the limit.`);const n=d.getRow(e),t=[];for(let e=1;e<=w;e++)t.push(o(n.getCell(e)));v.push(t)}const E=((e,n,t)=>e.map(e=>{const o={};for(let r=0;r<n.length;r++){const i=n[r];if(!i)continue;const l=e[r];o[i.key]=null==l||""===l?null:"number"==typeof l?l:h(String(l),t)}return o}))(v,M,f);return{columns:M,rows:E}}),w=(e,n)=>d(e,n),x=1048576,p=5e4;function M(e,n,t){if(!Number.isInteger(n)||n<1||n>t)throw new Error(`${e} must be an integer between 1 and ${t} (1-based Excel index), got ${String(n)}`)}function g(e,n,t,r){const{rowMin:i,rowMax:l,colMin:s,colMax:u}=t;if(M("rowMin",i,x),M("rowMax",l,x),M("colMin",s,16384),M("colMax",u,16384),i>l||s>u)throw new Error(`Invalid region bounds: rowMin=${i}, rowMax=${l}, colMin=${s}, colMax=${u}`);const c=function(e){var n;const t=null!==(n=null==e?void 0:e.maxCells)&&void 0!==n?n:5e4;if(!Number.isInteger(t)||!Number.isFinite(t)||t<1)throw new Error(`maxCells must be a finite integer >= 1, got ${String(null==e?void 0:e.maxCells)}`);return t}(r),a=function(e,n){const t=e.worksheets[n];if(!t)throw new Error(`Sheet index ${n} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);return t}(e,n),m=a.name,f=u-s+1;if(f>c)throw new Error(`Region requires ${f} cells per row, which exceeds maxCells (${c}); cannot return complete rows.`);const h=[];let d=0,w=!1;for(let e=i;e<=l;e++){if(d+f>c){w=!0;break}const n=[],t=a.getRow(e);for(let e=s;e<=u;e++)n.push(o(t.getCell(e)));h.push(n),d+=f}return{sheetIndex:n,sheetName:m,rowMin:i,rowMax:i+h.length-1,colMin:s,colMax:u,rows:h,truncated:w,returnedCellCount:d}}function b(e,n,t){return g(e,n.sheetIndex,{rowMin:n.rowMin,rowMax:n.rowMax,colMin:n.colMin,colMax:n.colMax},t)}const v=65536,N=(e,n)=>e*v+n,I=e=>[Math.floor(e/v),e%v],E=1,$=l;function y(e){let n=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(const i of e){const[e,l]=I(i);n=Math.min(n,e),t=Math.max(t,e),o=Math.min(o,l),r=Math.max(r,l)}return{rowMin:n,rowMax:t,colMin:o,colMax:r}}function C(e,n,t,r){const i=e.name,l=function(e,n,t){const r=new Set;return e.eachRow({includeEmpty:!1},(e,i)=>{e.eachCell({includeEmpty:!1},(e,l)=>{if(null!==o(e)){if(n.remaining<=0)throw new Error(`Workbook index exceeded maxNonEmptyCells limit (${t}). Refine the workbook or pass a higher maxNonEmptyCells.`);n.remaining-=1,r.add(N(i,l))}})}),r}(e,t,r),s=l.size;if(0===s)return{sheet:{sheetName:i,sheetIndex:n,rowMin:null,rowMax:null,colMin:null,colMax:null,nonEmptyCellCount:0},islands:[]};const{rowMin:u,rowMax:c,colMin:a,colMax:m}=y([...l]),f=function(e){const n=[...e].sort((e,n)=>{const[t,o]=I(e),[r,i]=I(n);return t!==r?t-r:o-i}),t=new Set,o=[];for(const r of n){if(t.has(r))continue;const n=[],i=[r];for(t.add(r);i.length>0;){const o=i.pop();if(void 0===o)throw new Error("Unexpected empty DFS stack");n.push(o);const[r,l]=I(o);for(const[n,o]of[[1,0],[-1,0],[0,1],[0,-1]]){const s=N(r+n,l+o);e.has(s)&&!t.has(s)&&(t.add(s),i.push(s))}}o.push(n)}return o}(l),h=f.map(e=>{const t=y(e);return Object.assign(Object.assign({sheetIndex:n,sheetName:i},t),{cellCount:e.length})}).sort((e,n)=>e.rowMin-n.rowMin||e.colMin-n.colMin||e.rowMax-n.rowMax||e.colMax-n.colMax).map((e,t)=>Object.assign(Object.assign({},e),{localId:`${n}:${t}`}));return{sheet:{sheetName:i,sheetIndex:n,rowMin:u,rowMax:c,colMin:a,colMax:m,nonEmptyCellCount:s},islands:h}}function k(e,n){var t;const o=null!==(t=null==n?void 0:n.maxNonEmptyCells)&&void 0!==t?t:$;if(!Number.isInteger(o)||!Number.isFinite(o)||o<1)throw new Error(`maxNonEmptyCells must be a finite integer >= 1, got ${String(null==n?void 0:n.maxNonEmptyCells)}`);const r=[],i=[],l={remaining:o};return e.worksheets.forEach((e,n)=>{const{sheet:t,islands:s}=C(e,n,l,o);r.push(t),i.push(...s)}),{schemaVersion:1,sheets:r,islands:i}}function S(n,t){return e(this,void 0,void 0,function*(){return k(yield i(n),t)})}export{$ as DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS,p as DEFAULT_READ_REGION_MAX_CELLS,E as WORKBOOK_INDEX_SCHEMA_VERSION,k as buildWorkbookIndex,S as buildWorkbookIndexFromXlsxBuffer,o as extractCellPrimitive,w as fromXLSX,i as loadWorkbookFromXlsxBuffer,b as readIslandRegion,g as readSheetRegion};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphysdk/data-import-utils",
|
|
3
3
|
"author": "Graphy",
|
|
4
|
-
"version": "1.3.0-beta.
|
|
4
|
+
"version": "1.3.0-beta.1778504701741",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"exceljs": "^4.4.0",
|
|
93
93
|
"papaparse": "^5.5.2",
|
|
94
|
-
"@graphysdk/core": "1.3.0-beta.
|
|
94
|
+
"@graphysdk/core": "1.3.0-beta.1778504701741"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"rollup-plugin-node-externals": "^8.1.1",
|
|
107
107
|
"tslib": "^2.8.1",
|
|
108
108
|
"vitest": "^4.1.0",
|
|
109
|
-
"@graphysdk/core": "1.3.0-beta.
|
|
109
|
+
"@graphysdk/core": "1.3.0-beta.1778504701741",
|
|
110
110
|
"@graphytools/eslint-config": "0.0.1",
|
|
111
111
|
"@graphytools/typescript-config": "0.0.1",
|
|
112
112
|
"@graphytools/vitest-config": "1.0.0"
|