jcampconverter 9.2.1 → 9.2.2

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.
@@ -2,7 +2,7 @@
2
2
  `),jcamp:`${b}
3
3
  `,children:[]}),i=l[l.length-1],s.push(i)}else if(n.substring(0,5)==="##END"&&f===0){i.jcamp+=`${b}
4
4
  `;let o=l.pop();l.length!==0?(i=l[l.length-1],i.children.push(o)):(i=void 0,p.push(o))}else if(i&&i.jcamp){i.jcamp+=`${b}
5
- `;let o=n.match(/^##(.*?)=(.+)/);if(o){let u=o[1].replace(/[ _-]/g,"").toUpperCase();u==="DATATYPE"&&(i.dataType=o[2].trim()),u==="DATACLASS"&&(i.dataClass=o[2].trim())}}n.substring(0,5)==="##END"&&f>0&&f--}return r?(s.forEach(c=>{c.children=void 0}),s):p}var oe=require("dynamic-typing"),pe=require("ensure-string");var $=["TIC",".RIC","SCANNUMBER"];function ae(e){let t=e.spectra,r=t.length,a={times:new Array(r),series:{ms:{dimension:2,data:new Array(r)}}},s=[];for(let l=0;l<$.length;l++){let p=U($[l]);t[0][p]&&(s.push(p),a.series[p]={dimension:1,data:new Array(r)})}for(let l=0;l<r;l++){let p=t[l];a.times[l]=p.pageValue;for(let i=0;i<s.length;i++)a.series[s[i]].data[l]=Number(p[s[i]]);p.data&&(a.series.ms.data[l]=[p.data.x,p.data.y])}e.chromatogram=a}function re(e){return $.indexOf(e)!==-1}function U(e){return e.toLowerCase().replace(/[^a-z0-9]/g,"")}function Y(e){let t=[];for(let r=0;r<e.length;r++)t.push(Number(e[r]));return t}function V(e,t){let r=e.yFactor,a=e.deltaX;e.isXYdata=!0;let s={x:[],y:[]};e.data=s;let l=e.firstX,p=e.firstY,i=!1,f,m=0;for(;m<t.length;m++)if(f=t.charCodeAt(m),f===13||f===10)i=!0;else if(i)break;let c=!0,b=!1,n=!1,o=0,u=!1,d=!1,h=0,T=0,A=!1,N=!1,y=!1,S=0;for(;m<=t.length;m++)if(m===t.length?f=13:f=t.charCodeAt(m),d)(f===13||f===10)&&(c=!0,d=!1);else if(f<=57&&f>=48)N=!0,S>0?h+=(f-48)/Math.pow(10,S++):(h*=10,h+=f-48);else if(f===44||f===46)N=!0,S++;else{if(N){if(c)c=!1,n&&(y=!0);else if(y)y=!1;else{b?(o=A?0-h:h,n=!0,b=!1):u||(T=A?0-h:h);let O=u?h-1:1;for(let F=0;F<O;F++)n?p+=o:p=T,s.x.push(l),s.y.push(p*r),l+=a}A=!1,h=0,S=0,N=!1,u=!1}if(f<74&&f>63)N=!0,n=!1,h=f-64;else if(f>96&&f<106)N=!0,n=!1,h=f-96,A=!0;else if(f===115)N=!0,u=!0,h=9;else if(f>82&&f<91)N=!0,u=!0,h=f-82;else if(f>73&&f<83)N=!0,b=!0,h=f-73;else if(f>105&&f<115)N=!0,b=!0,h=f-105,A=!0;else if(f===36&&t.charCodeAt(m+1)===36)N=!0,d=!0;else if(f===37)N=!0,b=!0,h=0,A=!1;else if(f===45){let O=t.charCodeAt(m+1);(O>=48&&O<=57||O===44||O===46)&&(N=!0,c||(n=!1),A=!0)}else(f===13||f===10)&&(c=!0,d=!1)}}var fe=/\$\$.*/,ne=/[,\t ]+/;function w(e,t,r){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables)===2?Xe(e,t,r):Ne(e,t,r),e.variables)for(let a in e.variables)e.variables[a].data=e.data[a]}function Xe(e,t,r){let a={x:[],y:[]};e.data=a;let s=t.split(/,? *,?[;\r\n]+ */);for(let l=1;l<s.length;l++){let p=s[l].trim().replace(fe,"").split(ne);if(p.length%2===0)for(let i=0;i<p.length;i=i+2)a.x.push(Number(p[i])*e.xFactor),a.y.push(Number(p[i+1])*e.yFactor);else r.logs.push(`Format error: ${p}`)}}function Ne(e,t,r){let a={},s=Object.keys(e.variables),l=s.length;s.forEach(i=>a[i]=[]),e.data=a;let p=t.split(/,? *,?[;\r\n]+ */);for(let i=1;i<p.length;i++){let f=p[i].trim().replace(fe,"").split(ne);if(f.length%l===0)for(let m=0;m<f.length;m++)a[s[m%l]].push(Number(f[m]));else r.logs.push(`Format error: ${f}`)}}function I(e,t){e.isXYAdata=!0;let r={};e.data=r;let a=t.split(/\r?\n/),s=a[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(l=>l.toLowerCase());for(let l=1;l<a.length;l++){let p=a[l].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let i=0;i<s.length;i++){let f=p[i];switch(s[i]){case"x":case"y":case"w":f=Number.parseFloat(f);break;case"a":f=f.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}r[s[i]]||(r[s[i]]=[]),r[s[i]].push(f)}}}var G=require("dynamic-typing");var E=Te(require("ml-array-median"));function k(e){let t=e[0].data.y[0],r=t,a=e.length,s=e[0].data.x.length,l=new Array(a);for(let n=0;n<a;n++){l[n]=e[n].data.y;for(let o=0;o<s;o++){let u=l[n][o];u<t&&(t=u),u>r&&(r=u)}}let p=e[0].data.x[0],i=e[0].data.x[e[0].data.x.length-1],f=e[0].pageValue,m=e[a-1].pageValue;if(p>i)for(let n of l)n.reverse();f>m&&l.reverse();let c=[];for(let n=0;n<l.length;n++){let o=Float64Array.from(l[n]);for(let u=0;u<o.length;u++)o[u]<0&&(o[u]=-o[u]);c.push((0,E.default)(o))}let b=(0,E.default)(c);return{z:l,minX:Math.min(p,i),maxX:Math.max(p,i),minY:Math.min(f,m),maxY:Math.max(f,m),minZ:t,maxZ:r,noise:b}}function Z(e,t){let r=e.noise,a=e.z,s,l,p,i,f,m,c,b,n=a.length,o=a[0].length,u,d,h,T,A=e.minX,y=(e.maxX-A)/(o-1),S=e.minY,F=(e.maxY-S)/(n-1),me=e.minZ,W=e.maxZ,z=t.nbContourLevels*2,J=new Array(z),x;for(let M=0;M<z;M++){let R={};J[M]=R;let ce=M%2,Q=(W-t.noiseMultiplier*r)*Math.exp((M>>1)-t.nbContourLevels);ce===0?x=Q+t.noiseMultiplier*r:x=0-Q-t.noiseMultiplier*r;let g=[];if(R.zValue=x,R.lines=g,!(x<=me||x>=W))for(let v=0;v<n-1;v++){let ee=a[v],te=a[v+1];for(let X=0;X<o-1;X++)s=ee[X],l=ee[X+1],p=te[X],i=te[X+1],f=s>x,m=l>x,c=p>x,b=i>x,f!==m&&f!==c&&(u=X+(x-s)/(l-s),d=v,h=X,T=v+(x-s)/(p-s),g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),b!==m&&b!==c&&(u=X+1,d=v+1-(x-i)/(l-i),h=X+1-(x-i)/(p-i),T=v+1,g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),m!==c&&(u=(X+1-(x-l)/(p-l))*y+A,d=(v+(x-l)/(p-l))*F+S,m!==f&&(h=X+1-(x-l)/(s-l),T=v,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==f&&(h=X,T=v+1-(x-p)/(s-p),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),m!==b&&(h=X+1,T=v+(x-l)/(i-l),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==b&&(h=X+(x-p)/(i-p),T=v+1,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:J}}function j(e,t){let r=k(e.spectra);t.noContour||(e.contourLines=Z(r,t),delete r.z),e.minMax=r}var B=require("gyromagnetic-ratio");function q(e){for(let t of e){let r=0,a=0;for(let s of t.spectra){if(t.ntuples&&t.ntuples.symbol?(!r&&s.observeFrequency&&(r=s.observeFrequency),!a&&s.shiftOffsetVal&&(a=s.shiftOffsetVal)):(r=s.observeFrequency,a=s.shiftOffsetVal),r&&s.xUnits&&s.xUnits.toUpperCase().includes("HZ")){s.xUnits="PPM",s.xFactor=s.xFactor/r,s.firstX=s.firstX/r,s.lastX=s.lastX/r,s.deltaX=s.deltaX/r;for(let l=0;l<s.data.x.length;l++)s.data.x[l]/=r}if(a&&s.xUnits.toLowerCase().includes("ppm")){let l=s.firstX-a;s.firstX=s.firstX-l,s.lastX=s.lastX-l;for(let p=0;p<s.data.x.length;p++)s.data.x[p]-=l}if(t.ntuples&&t.ntuples.nucleus&&t.ntuples.symbol)for(let l=0;l<t.ntuples.nucleus.length;l++){let p=t.ntuples.symbol[l],i=t.ntuples.nucleus[l];if(p.match(/^[F|T]/)&&!i){if(p.match(/[F|T]1/))if(t.tmp.$NUC2)t.ntuples.nucleus[l]=t.tmp.$NUC2;else{let f=t.ntuples.symbol.indexOf(p.replace(/^([F|T]).*/,"$12"));f&&t.ntuples.nucleus[f]&&(t.ntuples.nucleus[l]=t.ntuples.nucleus[f])}p.match(/[F|T]2/)&&(t.ntuples.nucleus[l]=t.tmp.$NUC1)}p.match(/[F|T]2/)&&(t.yType=t.ntuples.nucleus[0])}if(r&&t.ntuples&&t.ntuples.symbol&&t.ntuples.nucleus){let l="",p=t.ntuples.symbol.indexOf(s.pageSymbol);if(t.ntuples.units&&t.ntuples.units[p]&&(l=t.ntuples.units[p]),l!=="PPM"){if(p!==0)throw Error("Not sure about this ntuples format");let i=B.gyromagneticRatio[t.ntuples.nucleus[0]],f=B.gyromagneticRatio[t.ntuples.nucleus[1]];if(!i||!f)throw Error("Problem with determination of gyromagnetic ratio");let m=i/f*r;s.pageValue/=m}}}}}function L(e,t,r={}){r.logger?.trace(t),e.profiling&&e.profiling.push({action:t,time:Date.now()-r.start})}function H(e){let t=e.spectra[0].data;e.chromatogram={times:t.x.slice(),series:{intensity:{dimension:1,data:t.y.slice()}}}}function K(e,t,r){q(e),ye(e,r);for(let a of e){if(Object.keys(a.ntuples).length>0){let s=[],l=Object.keys(a.ntuples);for(let p=0;p<l.length;p++){let i=l[p],f=a.ntuples[i];for(let m=0;m<f.length;m++)s[m]||(s[m]={}),s[m][i]=f[m]}a.ntuples=s}a.twoD&&r.wantXY&&(j(a,r),L(t,"Finished countour plot calculation",r),r.keepSpectra||delete a.spectra),r.chromatogram&&(a.spectra.length>1?ae(a):H(a),L(t,"Finished chromatogram calculation",r)),delete a.tmp}}function ye(e,t){for(let r of e)for(let a in r.meta){let s=r.meta[a];if(typeof s=="string"){if(s[0]==="{"){if(s[s.length-1]==="}"){let l=s.slice(1,-1).split(/[,; ]+/).filter(p=>p);for(let p=0;p<l.length;p++)r.meta[a+String(p)]=t.dynamicTyping?(0,G.parseString)(l[p]):l[p]}}else if(s[0]==="("){let l=s.split(/\r?\n/),p=/^\((?<from>\d+)\.\.(?<to>\d+)\)$/;if(p.test(l[0])){let[i,f]=l[0].match(p).slice(1).map(Number),m=l.slice(1).join(" ").split(/[,; ]+/).filter(c=>c);for(let c=i;c<=f;c++)r.meta[a+String(c)]=t.dynamicTyping?(0,G.parseString)(m[c-i]):m[c-i]}}}}}function _(e,t,r){let a=-1,s=-1,l="",p="";if(r.indexOf("++")>0)l=r.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),p=r.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{r=r.replace(/[^a-zA-Z]/g,""),l=r.charAt(0),p=r.charAt(1),t.variables={};for(let i of r){let f=i.toLowerCase(),m=e.ntuples.symbol.indexOf(i);if(m===-1)throw Error(`Symbol undefined: ${i}`);t.variables[f]={};for(let c in e.ntuples)e.ntuples[c][m]&&(t.variables[f][c.replace(/^var/,"")]=e.ntuples[c][m])}}a=e.ntuples.symbol.indexOf(l),s=e.ntuples.symbol.indexOf(p),a===-1&&(a=0),s===-1&&(s=0),e.ntuples.first&&(e.ntuples.first.length>a&&(t.firstX=e.ntuples.first[a]),e.ntuples.first.length>s&&(t.firstY=e.ntuples.first[s])),e.ntuples.last&&(e.ntuples.last.length>a&&(t.lastX=e.ntuples.last[a]),e.ntuples.last.length>s&&(t.lastY=e.ntuples.last[s])),e.ntuples.vardim&&e.ntuples.vardim.length>a&&(t.nbPoints=e.ntuples.vardim[a]),e.ntuples.factor&&(e.ntuples.factor.length>a&&(t.xFactor=e.ntuples.factor[a]),e.ntuples.factor.length>s&&(t.yFactor=e.ntuples.factor[s])),e.ntuples.units&&(e.ntuples.units.length>a&&(e.ntuples.varname&&e.ntuples.varname[a]?t.xUnits=`${e.ntuples.varname[a]} [${e.ntuples.units[a]}]`:t.xUnits=e.ntuples.units[a]),e.ntuples.units.length>s&&(e.ntuples.varname&&e.ntuples.varname[s]?t.yUnits=`${e.ntuples.varname[s]} [${e.ntuples.units[s]}]`:t.yUnits=e.ntuples.units[s]))}function D(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var C=/[ \t]*,[ \t]*/,ve={keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5,profiling:!1};function ue(e,t={}){e=(0,pe.ensureString)(e),t={...ve,...t},t.logger?.debug("Starting jcamp conversion"),t.wantXY=!t.withoutXY,t.start=Date.now();let r=[],a={profiling:t.profiling?[]:!1,logs:[],entries:[]},s={children:[]},l=s,p=[],i={};if(typeof e!="string")throw new TypeError("the JCAMP should be a string");L(a,"Before split to LDRS",t);let f=e.replace(/[\r\n]+##/g,`
5
+ `;let o=n.match(/^##(.*?)=(.+)/);if(o){let u=o[1].replace(/[ _-]/g,"").toUpperCase();u==="DATATYPE"&&(i.dataType=o[2].trim()),u==="DATACLASS"&&(i.dataClass=o[2].trim())}}n.substring(0,5)==="##END"&&f>0&&f--}return r?(s.forEach(c=>{c.children=void 0}),s):p}var oe=require("dynamic-typing"),pe=require("ensure-string");var $=["TIC",".RIC","SCANNUMBER"];function ae(e){let t=e.spectra,r=t.length,a={times:new Array(r),series:{ms:{dimension:2,data:new Array(r)}}},s=[];for(let l=0;l<$.length;l++){let p=U($[l]);t[0][p]&&(s.push(p),a.series[p]={dimension:1,data:new Array(r)})}for(let l=0;l<r;l++){let p=t[l];a.times[l]=p.pageValue;for(let i=0;i<s.length;i++)a.series[s[i]].data[l]=Number(p[s[i]]);p.data&&(a.series.ms.data[l]=[p.data.x,p.data.y])}e.chromatogram=a}function re(e){return $.indexOf(e)!==-1}function U(e){return e.toLowerCase().replace(/[^a-z0-9]/g,"")}function Y(e){let t=[];for(let r=0;r<e.length;r++)t.push(Number(e[r]));return t}function V(e,t){let r=e.yFactor,a=e.deltaX;e.isXYdata=!0;let s={x:[],y:[]};e.data=s;let l=e.firstX,p=e.firstY,i=!1,f,m=0;for(;m<t.length;m++)if(f=t.charCodeAt(m),f===13||f===10)i=!0;else if(i)break;let c=!0,b=!1,n=!1,o=0,u=!1,d=!1,h=0,T=0,A=!1,N=!1,y=!1,S=0;for(;m<=t.length;m++)if(m===t.length?f=13:f=t.charCodeAt(m),d)(f===13||f===10)&&(c=!0,d=!1);else if(f<=57&&f>=48)N=!0,S>0?h+=(f-48)/Math.pow(10,S++):(h*=10,h+=f-48);else if(f===44||f===46)N=!0,S++;else{if(N){if(c)c=!1,n&&(y=!0);else if(y)y=!1;else{b?(o=A?0-h:h,n=!0,b=!1):u||(T=A?0-h:h);let O=u?h-1:1;for(let F=0;F<O;F++)n?p+=o:p=T,s.x.push(l),s.y.push(p*r),l+=a}A=!1,h=0,S=0,N=!1,u=!1}if(f<74&&f>63)N=!0,n=!1,h=f-64;else if(f>96&&f<106)N=!0,n=!1,h=f-96,A=!0;else if(f===115)N=!0,u=!0,h=9;else if(f>82&&f<91)N=!0,u=!0,h=f-82;else if(f>73&&f<83)N=!0,b=!0,h=f-73;else if(f>105&&f<115)N=!0,b=!0,h=f-105,A=!0;else if(f===36&&t.charCodeAt(m+1)===36)N=!0,d=!0;else if(f===37)N=!0,b=!0,h=0,A=!1;else if(f===45){let O=t.charCodeAt(m+1);(O>=48&&O<=57||O===44||O===46)&&(N=!0,c||(n=!1),A=!0)}else(f===13||f===10)&&(c=!0,d=!1)}}var fe=/\$\$.*/,ne=/[,\t ]+/;function w(e,t,r){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables)===2?Xe(e,t,r):Ne(e,t,r),e.variables)for(let a in e.variables)e.variables[a].data=e.data[a]}function Xe(e,t,r){let a={x:[],y:[]};e.data=a;let s=t.split(/,? *,?[;\r\n]+ */);for(let l=1;l<s.length;l++){let p=s[l].trim().replace(fe,"").split(ne);if(p.length%2===0)for(let i=0;i<p.length;i=i+2)a.x.push(Number(p[i])*e.xFactor),a.y.push(Number(p[i+1])*e.yFactor);else r.logs.push(`Format error: ${p}`)}}function Ne(e,t,r){let a={},s=Object.keys(e.variables),l=s.length;s.forEach(i=>a[i]=[]),e.data=a;let p=t.split(/,? *,?[;\r\n]+ */);for(let i=1;i<p.length;i++){let f=p[i].trim().replace(fe,"").split(ne);if(f.length%l===0)for(let m=0;m<f.length;m++)a[s[m%l]].push(Number(f[m]));else r.logs.push(`Format error: ${f}`)}}function I(e,t){e.isXYAdata=!0;let r={};e.data=r;let a=t.split(/\r?\n/),s=a[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(l=>l.toLowerCase());for(let l=1;l<a.length;l++){let p=a[l].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let i=0;i<s.length;i++){let f=p[i];switch(s[i]){case"x":case"y":case"w":f=Number.parseFloat(f);break;case"a":f=f.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}r[s[i]]||(r[s[i]]=[]),r[s[i]].push(f)}}}var G=require("dynamic-typing");var E=Te(require("ml-array-median"));function k(e){let t=e[0].data.y[0],r=t,a=e.length,s=e[0].data.x.length,l=new Array(a);for(let n=0;n<a;n++){l[n]=e[n].data.y;for(let o=0;o<s;o++){let u=l[n][o];u<t&&(t=u),u>r&&(r=u)}}let p=e[0].data.x[0],i=e[0].data.x[e[0].data.x.length-1],f=e[0].pageValue,m=e[a-1].pageValue;if(p>i)for(let n of l)n.reverse();f>m&&l.reverse();let c=[];for(let n=0;n<l.length;n++){let o=Float64Array.from(l[n]);for(let u=0;u<o.length;u++)o[u]<0&&(o[u]=-o[u]);c.push((0,E.default)(o))}let b=(0,E.default)(c);return{z:l,minX:Math.min(p,i),maxX:Math.max(p,i),minY:Math.min(f,m),maxY:Math.max(f,m),minZ:t,maxZ:r,noise:b}}function Z(e,t){let r=e.noise,a=e.z,s,l,p,i,f,m,c,b,n=a.length,o=a[0].length,u,d,h,T,A=e.minX,y=(e.maxX-A)/(o-1),S=e.minY,F=(e.maxY-S)/(n-1),me=e.minZ,z=e.maxZ,W=t.nbContourLevels*2,J=new Array(W),x;for(let M=0;M<W;M++){let R={};J[M]=R;let ce=M%2,Q=(z-t.noiseMultiplier*r)*Math.exp((M>>1)-t.nbContourLevels);ce===0?x=Q+t.noiseMultiplier*r:x=0-Q-t.noiseMultiplier*r;let g=[];if(R.zValue=x,R.lines=g,!(x<=me||x>=z))for(let v=0;v<n-1;v++){let ee=a[v],te=a[v+1];for(let X=0;X<o-1;X++)s=ee[X],l=ee[X+1],p=te[X],i=te[X+1],f=s>x,m=l>x,c=p>x,b=i>x,f!==m&&f!==c&&(u=X+(x-s)/(l-s),d=v,h=X,T=v+(x-s)/(p-s),g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),b!==m&&b!==c&&(u=X+1,d=v+1-(x-i)/(l-i),h=X+1-(x-i)/(p-i),T=v+1,g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),m!==c&&(u=(X+1-(x-l)/(p-l))*y+A,d=(v+(x-l)/(p-l))*F+S,m!==f&&(h=X+1-(x-l)/(s-l),T=v,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==f&&(h=X,T=v+1-(x-p)/(s-p),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),m!==b&&(h=X+1,T=v+(x-l)/(i-l),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==b&&(h=X+(x-p)/(i-p),T=v+1,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:J}}function j(e,t){let r=k(e.spectra);t.noContour||(e.contourLines=Z(r,t),delete r.z),e.minMax=r}var B=require("gyromagnetic-ratio");function q(e){for(let t of e){let r=0,a=0;for(let s of t.spectra){if(t.ntuples&&t.ntuples.symbol?(!r&&s.observeFrequency&&(r=s.observeFrequency),!a&&s.shiftOffsetVal&&(a=s.shiftOffsetVal)):(r=s.observeFrequency,a=s.shiftOffsetVal),r&&s.xUnits&&s.xUnits.toUpperCase().includes("HZ")){s.xUnits="PPM",s.xFactor=s.xFactor/r,s.firstX=s.firstX/r,s.lastX=s.lastX/r,s.deltaX=s.deltaX/r;for(let l=0;l<s.data.x.length;l++)s.data.x[l]/=r}if(a&&s.xUnits.toLowerCase().includes("ppm")){let l=s.firstX-a;s.firstX=s.firstX-l,s.lastX=s.lastX-l;for(let p=0;p<s.data.x.length;p++)s.data.x[p]-=l}if(t.ntuples&&t.ntuples.nucleus&&t.ntuples.symbol)for(let l=0;l<t.ntuples.nucleus.length;l++){let p=t.ntuples.symbol[l],i=t.ntuples.nucleus[l];if(p.match(/^[F|T]/)&&!i){if(p.match(/[F|T]1/))if(t.tmp.$NUC2)t.ntuples.nucleus[l]=t.tmp.$NUC2;else{let f=t.ntuples.symbol.indexOf(p.replace(/^([F|T]).*/,"$12"));f&&t.ntuples.nucleus[f]&&(t.ntuples.nucleus[l]=t.ntuples.nucleus[f])}p.match(/[F|T]2/)&&(t.ntuples.nucleus[l]=t.tmp.$NUC1)}p.match(/[F|T]2/)&&(t.yType=t.ntuples.nucleus[0])}if(r&&t.ntuples&&t.ntuples.symbol&&t.ntuples.nucleus){let l="",p=t.ntuples.symbol.indexOf(s.pageSymbol);if(t.ntuples.units&&t.ntuples.units[p]&&(l=t.ntuples.units[p]),l!=="PPM"){if(p!==0)throw Error("Not sure about this ntuples format");let i=B.gyromagneticRatio[t.ntuples.nucleus[0]],f=B.gyromagneticRatio[t.ntuples.nucleus[1]];if(!i||!f)throw Error("Problem with determination of gyromagnetic ratio");let m=i/f*r;s.pageValue/=m}}}}}function L(e,t,r={}){r.logger?.trace(t),e.profiling&&e.profiling.push({action:t,time:Date.now()-r.start})}function H(e){let t=e.spectra[0].data;e.chromatogram={times:t.x.slice(),series:{intensity:{dimension:1,data:t.y.slice()}}}}function K(e,t,r){q(e),ye(e,r);for(let a of e){if(Object.keys(a.ntuples).length>0){let s=[],l=Object.keys(a.ntuples);for(let p=0;p<l.length;p++){let i=l[p],f=a.ntuples[i];for(let m=0;m<f.length;m++)s[m]||(s[m]={}),s[m][i]=f[m]}a.ntuples=s}a.twoD&&r.wantXY&&(j(a,r),L(t,"Finished countour plot calculation",r),r.keepSpectra||delete a.spectra),r.chromatogram&&(a.spectra.length>1?ae(a):H(a),L(t,"Finished chromatogram calculation",r)),delete a.tmp}}function ye(e,t){for(let r of e)for(let a in r.meta){let s=r.meta[a];if(typeof s=="string"){if(s[0]==="{"){if(s[s.length-1]==="}"){let l=s.slice(1,-1).split(/[,; ]+/).filter(p=>p);for(let p=0;p<l.length;p++)r.meta[a+String(p)]=t.dynamicTyping?(0,G.parseString)(l[p]):l[p]}}else if(s[0]==="("){let l=s.split(/\r?\n/),p=/^\((?<from>\d+)\.\.(?<to>\d+)\)$/;if(p.test(l[0])){let[i,f]=l[0].match(p).slice(1).map(Number),m=l.slice(1).join(" ").split(/[,; ]+/).filter(c=>c);for(let c=i;c<=f;c++)r.meta[a+String(c)]=t.dynamicTyping?(0,G.parseString)(m[c-i]):m[c-i]}}}}}function _(e,t,r){let a=-1,s=-1,l="",p="";if(r.indexOf("++")>0)l=r.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),p=r.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{r=r.replace(/[^a-zA-Z]/g,""),l=r.charAt(0),p=r.charAt(1),t.variables={};for(let i of r){let f=i.toLowerCase(),m=e.ntuples.symbol.indexOf(i);if(m===-1)throw Error(`Symbol undefined: ${i}`);t.variables[f]={};for(let c in e.ntuples)e.ntuples[c][m]&&(t.variables[f][c.replace(/^var/,"")]=e.ntuples[c][m])}}a=e.ntuples.symbol.indexOf(l),s=e.ntuples.symbol.indexOf(p),a===-1&&(a=0),s===-1&&(s=0),e.ntuples.first&&(e.ntuples.first.length>a&&(t.firstX=e.ntuples.first[a]),e.ntuples.first.length>s&&(t.firstY=e.ntuples.first[s])),e.ntuples.last&&(e.ntuples.last.length>a&&(t.lastX=e.ntuples.last[a]),e.ntuples.last.length>s&&(t.lastY=e.ntuples.last[s])),e.ntuples.vardim&&e.ntuples.vardim.length>a&&(t.nbPoints=e.ntuples.vardim[a]),e.ntuples.factor&&(e.ntuples.factor.length>a&&(t.xFactor=e.ntuples.factor[a]),e.ntuples.factor.length>s&&(t.yFactor=e.ntuples.factor[s])),e.ntuples.units&&(e.ntuples.units.length>a&&(e.ntuples.varname&&e.ntuples.varname[a]?t.xUnits=`${e.ntuples.varname[a]} [${e.ntuples.units[a]}]`:t.xUnits=e.ntuples.units[a]),e.ntuples.units.length>s&&(e.ntuples.varname&&e.ntuples.varname[s]?t.yUnits=`${e.ntuples.varname[s]} [${e.ntuples.units[s]}]`:t.yUnits=e.ntuples.units[s]))}function D(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var C=/[ \t]*,[ \t]*/,ve={keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5,profiling:!1};function ue(e,t={}){e=(0,pe.ensureString)(e),t={...ve,...t},t.logger?.debug("Starting jcamp conversion"),t.wantXY=!t.withoutXY,t.start=Date.now();let r=[],a={profiling:t.profiling?[]:!1,logs:[],entries:[]},s={children:[]},l=s,p=[],i={};if(typeof e!="string")throw new TypeError("the JCAMP should be a string");L(a,"Before split to LDRS",t);let f=e.replace(/[\r\n]+##/g,`
6
6
  ##`).split(`
7
7
  ##`);L(a,"Split to LDRS",t),f[0]&&(f[0]=f[0].replace(/^[\r\n ]*##/,""));for(let m of f){let c=m.indexOf("="),b=c>0?m.substring(0,c):m,n=c>0?m.substring(c+1).trim():"",o=b.replace(/[_ -]/g,"").toUpperCase();if(o==="DATATABLE"){let u=n.indexOf(`
8
- `);if(u===-1&&(u=n.indexOf("\r")),u>0){let d=n.substring(0,u).split(/[ ,;\t]+/);_(l,i,d[0]),i.datatable=d[0],d[1]&&d[1].indexOf("PEAKS")>-1?o="PEAKTABLE":d[1]&&(d[1].indexOf("XYDATA")||d[0].indexOf("++")>0)&&(o="XYDATA",i.nbPoints&&(i.deltaX=(i.lastX-i.firstX)/(i.nbPoints-1)))}}if(o==="XYDATA"){t.wantXY&&(D(i),n.match(/.*\+\+.*/)?(i.nbPoints&&(i.deltaX=(i.lastX-i.firstX)/(i.nbPoints-1)),V(i,n,a)):w(i,n,a),l.spectra.push(i),i={});continue}else if(o==="PEAKTABLE"){t.wantXY&&(D(i),w(i,n,a),l.spectra.push(i),i={});continue}if(o==="PEAKASSIGNMENTS"){t.wantXY&&(n.match(/.*([^A-Z]*).*/)&&I(i,n),l.spectra.push(i),i={});continue}if(o==="TITLE"){let u=l;u.children||(u.children=[]),l={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},u.children.push(l),p.push(u),r.push(l),l.title=n}else o==="DATATYPE"?(l.dataType=n,n.match(/(^nd|\snd\s)/i)&&(l.twoD=!0)):o==="NTUPLES"?n.match(/(^nd|\snd\s)/i)&&(l.twoD=!0):o==="DATACLASS"?l.dataClass=n:o==="XUNITS"?i.xUnits=n:o==="YUNITS"?i.yUnits=n:o==="FIRSTX"?i.firstX=Number(n):o==="LASTX"?i.lastX=Number(n):o==="FIRSTY"?i.firstY=Number(n):o==="LASTY"?i.lastY=Number(n):o==="NPOINTS"?i.nbPoints=Number(n):o==="XFACTOR"?i.xFactor=Number(n):o==="YFACTOR"?i.yFactor=Number(n):o==="MAXX"?i.maxX=Number(n):o==="MINX"?i.minX=Number(n):o==="MAXY"?i.maxY=Number(n):o==="MINY"?i.minY=Number(n):o==="DELTAX"?i.deltaX=Number(n):o===".OBSERVEFREQUENCY"||o==="$SFO1"?i.observeFrequency||(i.observeFrequency=Number(n)):o===".OBSERVENUCLEUS"?i.xType||(l.xType=n.replace(/[^a-zA-Z0-9]/g,"")):o==="$OFFSET"?(l.shiftOffsetNum=0,i.shiftOffsetVal||(i.shiftOffsetVal=Number(n))):o==="$REFERENCEPOINT"||(o==="VARNAME"?l.ntuples.varname=n.split(C):o==="SYMBOL"?l.ntuples.symbol=n.split(C):o==="VARTYPE"?l.ntuples.vartype=n.split(C):o==="VARFORM"?l.ntuples.varform=n.split(C):o==="VARDIM"?l.ntuples.vardim=Y(n.split(C)):o==="UNITS"?l.ntuples.units=n.split(C):o==="FACTOR"?l.ntuples.factor=Y(n.split(C)):o==="FIRST"?l.ntuples.first=Y(n.split(C)):o==="LAST"?l.ntuples.last=Y(n.split(C)):o==="MIN"?l.ntuples.min=Y(n.split(C)):o==="MAX"?l.ntuples.max=Y(n.split(C)):o===".NUCLEUS"?l.ntuples&&(l.ntuples.nucleus=n.split(C)):o==="PAGE"?(i.page=n.trim(),i.pageValue=Number(n.replace(/^.*=/,"")),i.pageSymbol=i.page.replace(/[=].*/,"")):o==="RETENTIONTIME"?i.pageValue=Number(n):re(o)?i[U(o)]=n:o==="SAMPLEDESCRIPTION"?i.sampleDescription=n:o.startsWith("$NUC")?!l.tmp[o]&&!n.includes("off")&&(l.tmp[o]=n.replace(/[<>]/g,"")):o==="END"&&(l=p.pop()));if(l&&l.info&&l.meta&&o.match(t.keepRecordsRegExp)){let u=n.trim(),d,h;b.startsWith("$")?(h=t.canonicMetadataLabels?o.substring(1):b.substring(1),d=l.meta):(h=t.canonicDataLabels?o:b,d=l.info),t.dynamicTyping&&(u=(0,oe.parseString)(u)),d[h]?(Array.isArray(d[h])||(d[h]=[d[h]]),d[h].push(u)):d[h]=u}}return L(a,"Finished parsing",t),K(r,a,t),L(a,"Total time",t),a.entries=s.children,a.flatten=r,a}
8
+ `);if(u===-1&&(u=n.indexOf("\r")),u>0){let d=n.substring(0,u).split(/[ ,;\t]+/);_(l,i,d[0]),i.datatable=d[0],d[1]&&d[1].indexOf("PEAKS")>-1?o="PEAKTABLE":d[1]&&(d[1].indexOf("XYDATA")||d[0].indexOf("++")>0)&&(o="XYDATA",i.nbPoints&&(i.deltaX=(i.lastX-i.firstX)/(i.nbPoints-1)))}}if(o==="XYDATA"){t.wantXY&&(D(i),n.match(/.*\+\+.*/)?(i.nbPoints&&(i.deltaX=(i.lastX-i.firstX)/(i.nbPoints-1)),V(i,n,a)):w(i,n,a),l.spectra.push(i),i={});continue}else if(o==="PEAKTABLE"){t.wantXY&&(D(i),w(i,n,a),l.spectra.push(i),i={});continue}if(o==="PEAKASSIGNMENTS"){t.wantXY&&(n.match(/.*([^A-Z]*).*/)&&I(i,n),l.spectra.push(i),i={});continue}if(o==="TITLE"){let u=l;u.children||(u.children=[]),l={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},u.children.push(l),p.push(u),r.push(l),l.title=n}else o==="DATATYPE"?(l.dataType=n,n.match(/(^nd|\snd\s)/i)&&(l.twoD=!0)):o==="NTUPLES"?n.match(/(^nd|\snd\s)/i)&&(l.twoD=!0):o==="DATACLASS"?l.dataClass=n:o==="XUNITS"?i.xUnits=n:o==="YUNITS"?i.yUnits=n:o==="FIRSTX"?i.firstX=Number(n):o==="LASTX"?i.lastX=Number(n):o==="FIRSTY"?i.firstY=Number(n):o==="LASTY"?i.lastY=Number(n):o==="NPOINTS"?i.nbPoints=Number(n):o==="XFACTOR"?i.xFactor=Number(n):o==="YFACTOR"?i.yFactor=Number(n):o==="MAXX"?i.maxX=Number(n):o==="MINX"?i.minX=Number(n):o==="MAXY"?i.maxY=Number(n):o==="MINY"?i.minY=Number(n):o==="DELTAX"?i.deltaX=Number(n):o===".OBSERVEFREQUENCY"||o==="$SFO1"?i.observeFrequency||(i.observeFrequency=Number(n)):o===".OBSERVENUCLEUS"?i.xType||(l.xType=n.replace(/[^a-zA-Z0-9]/g,"")):o==="$OFFSET"?(l.shiftOffsetNum=0,i.shiftOffsetVal||(i.shiftOffsetVal=Number(n))):o==="$REFERENCEPOINT"||(o==="VARNAME"?l.ntuples.varname=n.split(C):o==="SYMBOL"?l.ntuples.symbol=n.split(C):o==="VARTYPE"?l.ntuples.vartype=n.split(C):o==="VARFORM"?l.ntuples.varform=n.split(C):o==="VARDIM"?l.ntuples.vardim=Y(n.split(C)):o==="UNITS"?l.ntuples.units=n.split(C):o==="FACTOR"?l.ntuples.factor=Y(n.split(C)):o==="FIRST"?l.ntuples.first=Y(n.split(C)):o==="LAST"?l.ntuples.last=Y(n.split(C)):o==="MIN"?l.ntuples.min=Y(n.split(C)):o==="MAX"?l.ntuples.max=Y(n.split(C)):o===".NUCLEUS"?l.ntuples&&(l.ntuples.nucleus=n.split(C).map(u=>u.replace(/[^a-zA-Z0-9]/g,""))):o==="PAGE"?(i.page=n.trim(),i.pageValue=Number(n.replace(/^.*=/,"")),i.pageSymbol=i.page.replace(/[=].*/,"")):o==="RETENTIONTIME"?i.pageValue=Number(n):re(o)?i[U(o)]=n:o==="SAMPLEDESCRIPTION"?i.sampleDescription=n:o.startsWith("$NUC")?!l.tmp[o]&&!n.includes("off")&&(l.tmp[o]=n.replace(/[<>]/g,"")):o==="END"&&(l=p.pop()));if(l&&l.info&&l.meta&&o.match(t.keepRecordsRegExp)){let u=n.trim(),d,h;b.startsWith("$")?(h=t.canonicMetadataLabels?o.substring(1):b.substring(1),d=l.meta):(h=t.canonicDataLabels?o:b,d=l.info),t.dynamicTyping&&(u=(0,oe.parseString)(u)),d[h]?(Array.isArray(d[h])||(d[h]=[d[h]]),d[h].push(u)):d[h]=u}}return L(a,"Finished parsing",t),K(r,a,t),L(a,"Total time",t),a.entries=s.children,a.flatten=r,a}
@@ -2,7 +2,7 @@ import{ensureString as fe}from"ensure-string";function ne(e,i={}){e=fe(e);let{fl
2
2
  `),jcamp:`${b}
3
3
  `,children:[]}),l=t[t.length-1],s.push(l)}else if(f.substring(0,5)==="##END"&&r===0){l.jcamp+=`${b}
4
4
  `;let n=t.pop();t.length!==0?(l=t[t.length-1],l.children.push(n)):(l=void 0,o.push(n))}else if(l&&l.jcamp){l.jcamp+=`${b}
5
- `;let n=f.match(/^##(.*?)=(.+)/);if(n){let u=n[1].replace(/[ _-]/g,"").toUpperCase();u==="DATATYPE"&&(l.dataType=n[2].trim()),u==="DATACLASS"&&(l.dataClass=n[2].trim())}}f.substring(0,5)==="##END"&&r>0&&r--}return p?(s.forEach(c=>{c.children=void 0}),s):o}import{parseString as me}from"dynamic-typing";import{ensureString as ce}from"ensure-string";var R=["TIC",".RIC","SCANNUMBER"];function J(e){let i=e.spectra,p=i.length,a={times:new Array(p),series:{ms:{dimension:2,data:new Array(p)}}},s=[];for(let t=0;t<R.length;t++){let o=$(R[t]);i[0][o]&&(s.push(o),a.series[o]={dimension:1,data:new Array(p)})}for(let t=0;t<p;t++){let o=i[t];a.times[t]=o.pageValue;for(let l=0;l<s.length;l++)a.series[s[l]].data[t]=Number(o[s[l]]);o.data&&(a.series.ms.data[t]=[o.data.x,o.data.y])}e.chromatogram=a}function Q(e){return R.indexOf(e)!==-1}function $(e){return e.toLowerCase().replace(/[^a-z0-9]/g,"")}function Y(e){let i=[];for(let p=0;p<e.length;p++)i.push(Number(e[p]));return i}function U(e,i){let p=e.yFactor,a=e.deltaX;e.isXYdata=!0;let s={x:[],y:[]};e.data=s;let t=e.firstX,o=e.firstY,l=!1,r,m=0;for(;m<i.length;m++)if(r=i.charCodeAt(m),r===13||r===10)l=!0;else if(l)break;let c=!0,b=!1,f=!1,n=0,u=!1,d=!1,h=0,T=0,A=!1,N=!1,y=!1,S=0;for(;m<=i.length;m++)if(m===i.length?r=13:r=i.charCodeAt(m),d)(r===13||r===10)&&(c=!0,d=!1);else if(r<=57&&r>=48)N=!0,S>0?h+=(r-48)/Math.pow(10,S++):(h*=10,h+=r-48);else if(r===44||r===46)N=!0,S++;else{if(N){if(c)c=!1,f&&(y=!0);else if(y)y=!1;else{b?(n=A?0-h:h,f=!0,b=!1):u||(T=A?0-h:h);let O=u?h-1:1;for(let F=0;F<O;F++)f?o+=n:o=T,s.x.push(t),s.y.push(o*p),t+=a}A=!1,h=0,S=0,N=!1,u=!1}if(r<74&&r>63)N=!0,f=!1,h=r-64;else if(r>96&&r<106)N=!0,f=!1,h=r-96,A=!0;else if(r===115)N=!0,u=!0,h=9;else if(r>82&&r<91)N=!0,u=!0,h=r-82;else if(r>73&&r<83)N=!0,b=!0,h=r-73;else if(r>105&&r<115)N=!0,b=!0,h=r-105,A=!0;else if(r===36&&i.charCodeAt(m+1)===36)N=!0,d=!0;else if(r===37)N=!0,b=!0,h=0,A=!1;else if(r===45){let O=i.charCodeAt(m+1);(O>=48&&O<=57||O===44||O===46)&&(N=!0,c||(f=!1),A=!0)}else(r===13||r===10)&&(c=!0,d=!1)}}var ee=/\$\$.*/,te=/[,\t ]+/;function P(e,i,p){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables)===2?oe(e,i,p):pe(e,i,p),e.variables)for(let a in e.variables)e.variables[a].data=e.data[a]}function oe(e,i,p){let a={x:[],y:[]};e.data=a;let s=i.split(/,? *,?[;\r\n]+ */);for(let t=1;t<s.length;t++){let o=s[t].trim().replace(ee,"").split(te);if(o.length%2===0)for(let l=0;l<o.length;l=l+2)a.x.push(Number(o[l])*e.xFactor),a.y.push(Number(o[l+1])*e.yFactor);else p.logs.push(`Format error: ${o}`)}}function pe(e,i,p){let a={},s=Object.keys(e.variables),t=s.length;s.forEach(l=>a[l]=[]),e.data=a;let o=i.split(/,? *,?[;\r\n]+ */);for(let l=1;l<o.length;l++){let r=o[l].trim().replace(ee,"").split(te);if(r.length%t===0)for(let m=0;m<r.length;m++)a[s[m%t]].push(Number(r[m]));else p.logs.push(`Format error: ${r}`)}}function V(e,i){e.isXYAdata=!0;let p={};e.data=p;let a=i.split(/\r?\n/),s=a[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(t=>t.toLowerCase());for(let t=1;t<a.length;t++){let o=a[t].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let l=0;l<s.length;l++){let r=o[l];switch(s[l]){case"x":case"y":case"w":r=Number.parseFloat(r);break;case"a":r=r.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}p[s[l]]||(p[s[l]]=[]),p[s[l]].push(r)}}}import{parseString as se}from"dynamic-typing";import le from"ml-array-median";function I(e){let i=e[0].data.y[0],p=i,a=e.length,s=e[0].data.x.length,t=new Array(a);for(let f=0;f<a;f++){t[f]=e[f].data.y;for(let n=0;n<s;n++){let u=t[f][n];u<i&&(i=u),u>p&&(p=u)}}let o=e[0].data.x[0],l=e[0].data.x[e[0].data.x.length-1],r=e[0].pageValue,m=e[a-1].pageValue;if(o>l)for(let f of t)f.reverse();r>m&&t.reverse();let c=[];for(let f=0;f<t.length;f++){let n=Float64Array.from(t[f]);for(let u=0;u<n.length;u++)n[u]<0&&(n[u]=-n[u]);c.push(le(n))}let b=le(c);return{z:t,minX:Math.min(o,l),maxX:Math.max(o,l),minY:Math.min(r,m),maxY:Math.max(r,m),minZ:i,maxZ:p,noise:b}}function E(e,i){let p=e.noise,a=e.z,s,t,o,l,r,m,c,b,f=a.length,n=a[0].length,u,d,h,T,A=e.minX,y=(e.maxX-A)/(n-1),S=e.minY,F=(e.maxY-S)/(f-1),ae=e.minZ,H=e.maxZ,G=i.nbContourLevels*2,K=new Array(G),x;for(let M=0;M<G;M++){let D={};K[M]=D;let re=M%2,_=(H-i.noiseMultiplier*p)*Math.exp((M>>1)-i.nbContourLevels);re===0?x=_+i.noiseMultiplier*p:x=0-_-i.noiseMultiplier*p;let g=[];if(D.zValue=x,D.lines=g,!(x<=ae||x>=H))for(let v=0;v<f-1;v++){let W=a[v],z=a[v+1];for(let X=0;X<n-1;X++)s=W[X],t=W[X+1],o=z[X],l=z[X+1],r=s>x,m=t>x,c=o>x,b=l>x,r!==m&&r!==c&&(u=X+(x-s)/(t-s),d=v,h=X,T=v+(x-s)/(o-s),g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),b!==m&&b!==c&&(u=X+1,d=v+1-(x-l)/(t-l),h=X+1-(x-l)/(o-l),T=v+1,g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),m!==c&&(u=(X+1-(x-t)/(o-t))*y+A,d=(v+(x-t)/(o-t))*F+S,m!==r&&(h=X+1-(x-t)/(s-t),T=v,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==r&&(h=X,T=v+1-(x-o)/(s-o),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),m!==b&&(h=X+1,T=v+(x-t)/(l-t),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==b&&(h=X+(x-o)/(l-o),T=v+1,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:K}}function k(e,i){let p=I(e.spectra);i.noContour||(e.contourLines=E(p,i),delete p.z),e.minMax=p}import{gyromagneticRatio as ie}from"gyromagnetic-ratio";function Z(e){for(let i of e){let p=0,a=0;for(let s of i.spectra){if(i.ntuples&&i.ntuples.symbol?(!p&&s.observeFrequency&&(p=s.observeFrequency),!a&&s.shiftOffsetVal&&(a=s.shiftOffsetVal)):(p=s.observeFrequency,a=s.shiftOffsetVal),p&&s.xUnits&&s.xUnits.toUpperCase().includes("HZ")){s.xUnits="PPM",s.xFactor=s.xFactor/p,s.firstX=s.firstX/p,s.lastX=s.lastX/p,s.deltaX=s.deltaX/p;for(let t=0;t<s.data.x.length;t++)s.data.x[t]/=p}if(a&&s.xUnits.toLowerCase().includes("ppm")){let t=s.firstX-a;s.firstX=s.firstX-t,s.lastX=s.lastX-t;for(let o=0;o<s.data.x.length;o++)s.data.x[o]-=t}if(i.ntuples&&i.ntuples.nucleus&&i.ntuples.symbol)for(let t=0;t<i.ntuples.nucleus.length;t++){let o=i.ntuples.symbol[t],l=i.ntuples.nucleus[t];if(o.match(/^[F|T]/)&&!l){if(o.match(/[F|T]1/))if(i.tmp.$NUC2)i.ntuples.nucleus[t]=i.tmp.$NUC2;else{let r=i.ntuples.symbol.indexOf(o.replace(/^([F|T]).*/,"$12"));r&&i.ntuples.nucleus[r]&&(i.ntuples.nucleus[t]=i.ntuples.nucleus[r])}o.match(/[F|T]2/)&&(i.ntuples.nucleus[t]=i.tmp.$NUC1)}o.match(/[F|T]2/)&&(i.yType=i.ntuples.nucleus[0])}if(p&&i.ntuples&&i.ntuples.symbol&&i.ntuples.nucleus){let t="",o=i.ntuples.symbol.indexOf(s.pageSymbol);if(i.ntuples.units&&i.ntuples.units[o]&&(t=i.ntuples.units[o]),t!=="PPM"){if(o!==0)throw Error("Not sure about this ntuples format");let l=ie[i.ntuples.nucleus[0]],r=ie[i.ntuples.nucleus[1]];if(!l||!r)throw Error("Problem with determination of gyromagnetic ratio");let m=l/r*p;s.pageValue/=m}}}}}function L(e,i,p={}){p.logger?.trace(i),e.profiling&&e.profiling.push({action:i,time:Date.now()-p.start})}function j(e){let i=e.spectra[0].data;e.chromatogram={times:i.x.slice(),series:{intensity:{dimension:1,data:i.y.slice()}}}}function B(e,i,p){Z(e),ue(e,p);for(let a of e){if(Object.keys(a.ntuples).length>0){let s=[],t=Object.keys(a.ntuples);for(let o=0;o<t.length;o++){let l=t[o],r=a.ntuples[l];for(let m=0;m<r.length;m++)s[m]||(s[m]={}),s[m][l]=r[m]}a.ntuples=s}a.twoD&&p.wantXY&&(k(a,p),L(i,"Finished countour plot calculation",p),p.keepSpectra||delete a.spectra),p.chromatogram&&(a.spectra.length>1?J(a):j(a),L(i,"Finished chromatogram calculation",p)),delete a.tmp}}function ue(e,i){for(let p of e)for(let a in p.meta){let s=p.meta[a];if(typeof s=="string"){if(s[0]==="{"){if(s[s.length-1]==="}"){let t=s.slice(1,-1).split(/[,; ]+/).filter(o=>o);for(let o=0;o<t.length;o++)p.meta[a+String(o)]=i.dynamicTyping?se(t[o]):t[o]}}else if(s[0]==="("){let t=s.split(/\r?\n/),o=/^\((?<from>\d+)\.\.(?<to>\d+)\)$/;if(o.test(t[0])){let[l,r]=t[0].match(o).slice(1).map(Number),m=t.slice(1).join(" ").split(/[,; ]+/).filter(c=>c);for(let c=l;c<=r;c++)p.meta[a+String(c)]=i.dynamicTyping?se(m[c-l]):m[c-l]}}}}}function q(e,i,p){let a=-1,s=-1,t="",o="";if(p.indexOf("++")>0)t=p.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),o=p.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{p=p.replace(/[^a-zA-Z]/g,""),t=p.charAt(0),o=p.charAt(1),i.variables={};for(let l of p){let r=l.toLowerCase(),m=e.ntuples.symbol.indexOf(l);if(m===-1)throw Error(`Symbol undefined: ${l}`);i.variables[r]={};for(let c in e.ntuples)e.ntuples[c][m]&&(i.variables[r][c.replace(/^var/,"")]=e.ntuples[c][m])}}a=e.ntuples.symbol.indexOf(t),s=e.ntuples.symbol.indexOf(o),a===-1&&(a=0),s===-1&&(s=0),e.ntuples.first&&(e.ntuples.first.length>a&&(i.firstX=e.ntuples.first[a]),e.ntuples.first.length>s&&(i.firstY=e.ntuples.first[s])),e.ntuples.last&&(e.ntuples.last.length>a&&(i.lastX=e.ntuples.last[a]),e.ntuples.last.length>s&&(i.lastY=e.ntuples.last[s])),e.ntuples.vardim&&e.ntuples.vardim.length>a&&(i.nbPoints=e.ntuples.vardim[a]),e.ntuples.factor&&(e.ntuples.factor.length>a&&(i.xFactor=e.ntuples.factor[a]),e.ntuples.factor.length>s&&(i.yFactor=e.ntuples.factor[s])),e.ntuples.units&&(e.ntuples.units.length>a&&(e.ntuples.varname&&e.ntuples.varname[a]?i.xUnits=`${e.ntuples.varname[a]} [${e.ntuples.units[a]}]`:i.xUnits=e.ntuples.units[a]),e.ntuples.units.length>s&&(e.ntuples.varname&&e.ntuples.varname[s]?i.yUnits=`${e.ntuples.varname[s]} [${e.ntuples.units[s]}]`:i.yUnits=e.ntuples.units[s]))}function w(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var C=/[ \t]*,[ \t]*/,he={keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5,profiling:!1};function de(e,i={}){e=ce(e),i={...he,...i},i.logger?.debug("Starting jcamp conversion"),i.wantXY=!i.withoutXY,i.start=Date.now();let p=[],a={profiling:i.profiling?[]:!1,logs:[],entries:[]},s={children:[]},t=s,o=[],l={};if(typeof e!="string")throw new TypeError("the JCAMP should be a string");L(a,"Before split to LDRS",i);let r=e.replace(/[\r\n]+##/g,`
5
+ `;let n=f.match(/^##(.*?)=(.+)/);if(n){let u=n[1].replace(/[ _-]/g,"").toUpperCase();u==="DATATYPE"&&(l.dataType=n[2].trim()),u==="DATACLASS"&&(l.dataClass=n[2].trim())}}f.substring(0,5)==="##END"&&r>0&&r--}return p?(s.forEach(c=>{c.children=void 0}),s):o}import{parseString as me}from"dynamic-typing";import{ensureString as ce}from"ensure-string";var R=["TIC",".RIC","SCANNUMBER"];function J(e){let i=e.spectra,p=i.length,a={times:new Array(p),series:{ms:{dimension:2,data:new Array(p)}}},s=[];for(let t=0;t<R.length;t++){let o=$(R[t]);i[0][o]&&(s.push(o),a.series[o]={dimension:1,data:new Array(p)})}for(let t=0;t<p;t++){let o=i[t];a.times[t]=o.pageValue;for(let l=0;l<s.length;l++)a.series[s[l]].data[t]=Number(o[s[l]]);o.data&&(a.series.ms.data[t]=[o.data.x,o.data.y])}e.chromatogram=a}function Q(e){return R.indexOf(e)!==-1}function $(e){return e.toLowerCase().replace(/[^a-z0-9]/g,"")}function Y(e){let i=[];for(let p=0;p<e.length;p++)i.push(Number(e[p]));return i}function U(e,i){let p=e.yFactor,a=e.deltaX;e.isXYdata=!0;let s={x:[],y:[]};e.data=s;let t=e.firstX,o=e.firstY,l=!1,r,m=0;for(;m<i.length;m++)if(r=i.charCodeAt(m),r===13||r===10)l=!0;else if(l)break;let c=!0,b=!1,f=!1,n=0,u=!1,d=!1,h=0,T=0,A=!1,N=!1,y=!1,S=0;for(;m<=i.length;m++)if(m===i.length?r=13:r=i.charCodeAt(m),d)(r===13||r===10)&&(c=!0,d=!1);else if(r<=57&&r>=48)N=!0,S>0?h+=(r-48)/Math.pow(10,S++):(h*=10,h+=r-48);else if(r===44||r===46)N=!0,S++;else{if(N){if(c)c=!1,f&&(y=!0);else if(y)y=!1;else{b?(n=A?0-h:h,f=!0,b=!1):u||(T=A?0-h:h);let O=u?h-1:1;for(let F=0;F<O;F++)f?o+=n:o=T,s.x.push(t),s.y.push(o*p),t+=a}A=!1,h=0,S=0,N=!1,u=!1}if(r<74&&r>63)N=!0,f=!1,h=r-64;else if(r>96&&r<106)N=!0,f=!1,h=r-96,A=!0;else if(r===115)N=!0,u=!0,h=9;else if(r>82&&r<91)N=!0,u=!0,h=r-82;else if(r>73&&r<83)N=!0,b=!0,h=r-73;else if(r>105&&r<115)N=!0,b=!0,h=r-105,A=!0;else if(r===36&&i.charCodeAt(m+1)===36)N=!0,d=!0;else if(r===37)N=!0,b=!0,h=0,A=!1;else if(r===45){let O=i.charCodeAt(m+1);(O>=48&&O<=57||O===44||O===46)&&(N=!0,c||(f=!1),A=!0)}else(r===13||r===10)&&(c=!0,d=!1)}}var ee=/\$\$.*/,te=/[,\t ]+/;function P(e,i,p){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables)===2?oe(e,i,p):pe(e,i,p),e.variables)for(let a in e.variables)e.variables[a].data=e.data[a]}function oe(e,i,p){let a={x:[],y:[]};e.data=a;let s=i.split(/,? *,?[;\r\n]+ */);for(let t=1;t<s.length;t++){let o=s[t].trim().replace(ee,"").split(te);if(o.length%2===0)for(let l=0;l<o.length;l=l+2)a.x.push(Number(o[l])*e.xFactor),a.y.push(Number(o[l+1])*e.yFactor);else p.logs.push(`Format error: ${o}`)}}function pe(e,i,p){let a={},s=Object.keys(e.variables),t=s.length;s.forEach(l=>a[l]=[]),e.data=a;let o=i.split(/,? *,?[;\r\n]+ */);for(let l=1;l<o.length;l++){let r=o[l].trim().replace(ee,"").split(te);if(r.length%t===0)for(let m=0;m<r.length;m++)a[s[m%t]].push(Number(r[m]));else p.logs.push(`Format error: ${r}`)}}function V(e,i){e.isXYAdata=!0;let p={};e.data=p;let a=i.split(/\r?\n/),s=a[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(t=>t.toLowerCase());for(let t=1;t<a.length;t++){let o=a[t].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let l=0;l<s.length;l++){let r=o[l];switch(s[l]){case"x":case"y":case"w":r=Number.parseFloat(r);break;case"a":r=r.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}p[s[l]]||(p[s[l]]=[]),p[s[l]].push(r)}}}import{parseString as se}from"dynamic-typing";import le from"ml-array-median";function I(e){let i=e[0].data.y[0],p=i,a=e.length,s=e[0].data.x.length,t=new Array(a);for(let f=0;f<a;f++){t[f]=e[f].data.y;for(let n=0;n<s;n++){let u=t[f][n];u<i&&(i=u),u>p&&(p=u)}}let o=e[0].data.x[0],l=e[0].data.x[e[0].data.x.length-1],r=e[0].pageValue,m=e[a-1].pageValue;if(o>l)for(let f of t)f.reverse();r>m&&t.reverse();let c=[];for(let f=0;f<t.length;f++){let n=Float64Array.from(t[f]);for(let u=0;u<n.length;u++)n[u]<0&&(n[u]=-n[u]);c.push(le(n))}let b=le(c);return{z:t,minX:Math.min(o,l),maxX:Math.max(o,l),minY:Math.min(r,m),maxY:Math.max(r,m),minZ:i,maxZ:p,noise:b}}function E(e,i){let p=e.noise,a=e.z,s,t,o,l,r,m,c,b,f=a.length,n=a[0].length,u,d,h,T,A=e.minX,y=(e.maxX-A)/(n-1),S=e.minY,F=(e.maxY-S)/(f-1),ae=e.minZ,H=e.maxZ,G=i.nbContourLevels*2,K=new Array(G),x;for(let M=0;M<G;M++){let D={};K[M]=D;let re=M%2,_=(H-i.noiseMultiplier*p)*Math.exp((M>>1)-i.nbContourLevels);re===0?x=_+i.noiseMultiplier*p:x=0-_-i.noiseMultiplier*p;let g=[];if(D.zValue=x,D.lines=g,!(x<=ae||x>=H))for(let v=0;v<f-1;v++){let z=a[v],W=a[v+1];for(let X=0;X<n-1;X++)s=z[X],t=z[X+1],o=W[X],l=W[X+1],r=s>x,m=t>x,c=o>x,b=l>x,r!==m&&r!==c&&(u=X+(x-s)/(t-s),d=v,h=X,T=v+(x-s)/(o-s),g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),b!==m&&b!==c&&(u=X+1,d=v+1-(x-l)/(t-l),h=X+1-(x-l)/(o-l),T=v+1,g.push(u*y+A),g.push(d*F+S),g.push(h*y+A),g.push(T*F+S)),m!==c&&(u=(X+1-(x-t)/(o-t))*y+A,d=(v+(x-t)/(o-t))*F+S,m!==r&&(h=X+1-(x-t)/(s-t),T=v,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==r&&(h=X,T=v+1-(x-o)/(s-o),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),m!==b&&(h=X+1,T=v+(x-t)/(l-t),g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)),c!==b&&(h=X+(x-o)/(l-o),T=v+1,g.push(u),g.push(d),g.push(h*y+A),g.push(T*F+S)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:K}}function k(e,i){let p=I(e.spectra);i.noContour||(e.contourLines=E(p,i),delete p.z),e.minMax=p}import{gyromagneticRatio as ie}from"gyromagnetic-ratio";function Z(e){for(let i of e){let p=0,a=0;for(let s of i.spectra){if(i.ntuples&&i.ntuples.symbol?(!p&&s.observeFrequency&&(p=s.observeFrequency),!a&&s.shiftOffsetVal&&(a=s.shiftOffsetVal)):(p=s.observeFrequency,a=s.shiftOffsetVal),p&&s.xUnits&&s.xUnits.toUpperCase().includes("HZ")){s.xUnits="PPM",s.xFactor=s.xFactor/p,s.firstX=s.firstX/p,s.lastX=s.lastX/p,s.deltaX=s.deltaX/p;for(let t=0;t<s.data.x.length;t++)s.data.x[t]/=p}if(a&&s.xUnits.toLowerCase().includes("ppm")){let t=s.firstX-a;s.firstX=s.firstX-t,s.lastX=s.lastX-t;for(let o=0;o<s.data.x.length;o++)s.data.x[o]-=t}if(i.ntuples&&i.ntuples.nucleus&&i.ntuples.symbol)for(let t=0;t<i.ntuples.nucleus.length;t++){let o=i.ntuples.symbol[t],l=i.ntuples.nucleus[t];if(o.match(/^[F|T]/)&&!l){if(o.match(/[F|T]1/))if(i.tmp.$NUC2)i.ntuples.nucleus[t]=i.tmp.$NUC2;else{let r=i.ntuples.symbol.indexOf(o.replace(/^([F|T]).*/,"$12"));r&&i.ntuples.nucleus[r]&&(i.ntuples.nucleus[t]=i.ntuples.nucleus[r])}o.match(/[F|T]2/)&&(i.ntuples.nucleus[t]=i.tmp.$NUC1)}o.match(/[F|T]2/)&&(i.yType=i.ntuples.nucleus[0])}if(p&&i.ntuples&&i.ntuples.symbol&&i.ntuples.nucleus){let t="",o=i.ntuples.symbol.indexOf(s.pageSymbol);if(i.ntuples.units&&i.ntuples.units[o]&&(t=i.ntuples.units[o]),t!=="PPM"){if(o!==0)throw Error("Not sure about this ntuples format");let l=ie[i.ntuples.nucleus[0]],r=ie[i.ntuples.nucleus[1]];if(!l||!r)throw Error("Problem with determination of gyromagnetic ratio");let m=l/r*p;s.pageValue/=m}}}}}function L(e,i,p={}){p.logger?.trace(i),e.profiling&&e.profiling.push({action:i,time:Date.now()-p.start})}function j(e){let i=e.spectra[0].data;e.chromatogram={times:i.x.slice(),series:{intensity:{dimension:1,data:i.y.slice()}}}}function B(e,i,p){Z(e),ue(e,p);for(let a of e){if(Object.keys(a.ntuples).length>0){let s=[],t=Object.keys(a.ntuples);for(let o=0;o<t.length;o++){let l=t[o],r=a.ntuples[l];for(let m=0;m<r.length;m++)s[m]||(s[m]={}),s[m][l]=r[m]}a.ntuples=s}a.twoD&&p.wantXY&&(k(a,p),L(i,"Finished countour plot calculation",p),p.keepSpectra||delete a.spectra),p.chromatogram&&(a.spectra.length>1?J(a):j(a),L(i,"Finished chromatogram calculation",p)),delete a.tmp}}function ue(e,i){for(let p of e)for(let a in p.meta){let s=p.meta[a];if(typeof s=="string"){if(s[0]==="{"){if(s[s.length-1]==="}"){let t=s.slice(1,-1).split(/[,; ]+/).filter(o=>o);for(let o=0;o<t.length;o++)p.meta[a+String(o)]=i.dynamicTyping?se(t[o]):t[o]}}else if(s[0]==="("){let t=s.split(/\r?\n/),o=/^\((?<from>\d+)\.\.(?<to>\d+)\)$/;if(o.test(t[0])){let[l,r]=t[0].match(o).slice(1).map(Number),m=t.slice(1).join(" ").split(/[,; ]+/).filter(c=>c);for(let c=l;c<=r;c++)p.meta[a+String(c)]=i.dynamicTyping?se(m[c-l]):m[c-l]}}}}}function q(e,i,p){let a=-1,s=-1,t="",o="";if(p.indexOf("++")>0)t=p.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),o=p.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{p=p.replace(/[^a-zA-Z]/g,""),t=p.charAt(0),o=p.charAt(1),i.variables={};for(let l of p){let r=l.toLowerCase(),m=e.ntuples.symbol.indexOf(l);if(m===-1)throw Error(`Symbol undefined: ${l}`);i.variables[r]={};for(let c in e.ntuples)e.ntuples[c][m]&&(i.variables[r][c.replace(/^var/,"")]=e.ntuples[c][m])}}a=e.ntuples.symbol.indexOf(t),s=e.ntuples.symbol.indexOf(o),a===-1&&(a=0),s===-1&&(s=0),e.ntuples.first&&(e.ntuples.first.length>a&&(i.firstX=e.ntuples.first[a]),e.ntuples.first.length>s&&(i.firstY=e.ntuples.first[s])),e.ntuples.last&&(e.ntuples.last.length>a&&(i.lastX=e.ntuples.last[a]),e.ntuples.last.length>s&&(i.lastY=e.ntuples.last[s])),e.ntuples.vardim&&e.ntuples.vardim.length>a&&(i.nbPoints=e.ntuples.vardim[a]),e.ntuples.factor&&(e.ntuples.factor.length>a&&(i.xFactor=e.ntuples.factor[a]),e.ntuples.factor.length>s&&(i.yFactor=e.ntuples.factor[s])),e.ntuples.units&&(e.ntuples.units.length>a&&(e.ntuples.varname&&e.ntuples.varname[a]?i.xUnits=`${e.ntuples.varname[a]} [${e.ntuples.units[a]}]`:i.xUnits=e.ntuples.units[a]),e.ntuples.units.length>s&&(e.ntuples.varname&&e.ntuples.varname[s]?i.yUnits=`${e.ntuples.varname[s]} [${e.ntuples.units[s]}]`:i.yUnits=e.ntuples.units[s]))}function w(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var C=/[ \t]*,[ \t]*/,he={keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5,profiling:!1};function de(e,i={}){e=ce(e),i={...he,...i},i.logger?.debug("Starting jcamp conversion"),i.wantXY=!i.withoutXY,i.start=Date.now();let p=[],a={profiling:i.profiling?[]:!1,logs:[],entries:[]},s={children:[]},t=s,o=[],l={};if(typeof e!="string")throw new TypeError("the JCAMP should be a string");L(a,"Before split to LDRS",i);let r=e.replace(/[\r\n]+##/g,`
6
6
  ##`).split(`
7
7
  ##`);L(a,"Split to LDRS",i),r[0]&&(r[0]=r[0].replace(/^[\r\n ]*##/,""));for(let m of r){let c=m.indexOf("="),b=c>0?m.substring(0,c):m,f=c>0?m.substring(c+1).trim():"",n=b.replace(/[_ -]/g,"").toUpperCase();if(n==="DATATABLE"){let u=f.indexOf(`
8
- `);if(u===-1&&(u=f.indexOf("\r")),u>0){let d=f.substring(0,u).split(/[ ,;\t]+/);q(t,l,d[0]),l.datatable=d[0],d[1]&&d[1].indexOf("PEAKS")>-1?n="PEAKTABLE":d[1]&&(d[1].indexOf("XYDATA")||d[0].indexOf("++")>0)&&(n="XYDATA",l.nbPoints&&(l.deltaX=(l.lastX-l.firstX)/(l.nbPoints-1)))}}if(n==="XYDATA"){i.wantXY&&(w(l),f.match(/.*\+\+.*/)?(l.nbPoints&&(l.deltaX=(l.lastX-l.firstX)/(l.nbPoints-1)),U(l,f,a)):P(l,f,a),t.spectra.push(l),l={});continue}else if(n==="PEAKTABLE"){i.wantXY&&(w(l),P(l,f,a),t.spectra.push(l),l={});continue}if(n==="PEAKASSIGNMENTS"){i.wantXY&&(f.match(/.*([^A-Z]*).*/)&&V(l,f),t.spectra.push(l),l={});continue}if(n==="TITLE"){let u=t;u.children||(u.children=[]),t={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},u.children.push(t),o.push(u),p.push(t),t.title=f}else n==="DATATYPE"?(t.dataType=f,f.match(/(^nd|\snd\s)/i)&&(t.twoD=!0)):n==="NTUPLES"?f.match(/(^nd|\snd\s)/i)&&(t.twoD=!0):n==="DATACLASS"?t.dataClass=f:n==="XUNITS"?l.xUnits=f:n==="YUNITS"?l.yUnits=f:n==="FIRSTX"?l.firstX=Number(f):n==="LASTX"?l.lastX=Number(f):n==="FIRSTY"?l.firstY=Number(f):n==="LASTY"?l.lastY=Number(f):n==="NPOINTS"?l.nbPoints=Number(f):n==="XFACTOR"?l.xFactor=Number(f):n==="YFACTOR"?l.yFactor=Number(f):n==="MAXX"?l.maxX=Number(f):n==="MINX"?l.minX=Number(f):n==="MAXY"?l.maxY=Number(f):n==="MINY"?l.minY=Number(f):n==="DELTAX"?l.deltaX=Number(f):n===".OBSERVEFREQUENCY"||n==="$SFO1"?l.observeFrequency||(l.observeFrequency=Number(f)):n===".OBSERVENUCLEUS"?l.xType||(t.xType=f.replace(/[^a-zA-Z0-9]/g,"")):n==="$OFFSET"?(t.shiftOffsetNum=0,l.shiftOffsetVal||(l.shiftOffsetVal=Number(f))):n==="$REFERENCEPOINT"||(n==="VARNAME"?t.ntuples.varname=f.split(C):n==="SYMBOL"?t.ntuples.symbol=f.split(C):n==="VARTYPE"?t.ntuples.vartype=f.split(C):n==="VARFORM"?t.ntuples.varform=f.split(C):n==="VARDIM"?t.ntuples.vardim=Y(f.split(C)):n==="UNITS"?t.ntuples.units=f.split(C):n==="FACTOR"?t.ntuples.factor=Y(f.split(C)):n==="FIRST"?t.ntuples.first=Y(f.split(C)):n==="LAST"?t.ntuples.last=Y(f.split(C)):n==="MIN"?t.ntuples.min=Y(f.split(C)):n==="MAX"?t.ntuples.max=Y(f.split(C)):n===".NUCLEUS"?t.ntuples&&(t.ntuples.nucleus=f.split(C)):n==="PAGE"?(l.page=f.trim(),l.pageValue=Number(f.replace(/^.*=/,"")),l.pageSymbol=l.page.replace(/[=].*/,"")):n==="RETENTIONTIME"?l.pageValue=Number(f):Q(n)?l[$(n)]=f:n==="SAMPLEDESCRIPTION"?l.sampleDescription=f:n.startsWith("$NUC")?!t.tmp[n]&&!f.includes("off")&&(t.tmp[n]=f.replace(/[<>]/g,"")):n==="END"&&(t=o.pop()));if(t&&t.info&&t.meta&&n.match(i.keepRecordsRegExp)){let u=f.trim(),d,h;b.startsWith("$")?(h=i.canonicMetadataLabels?n.substring(1):b.substring(1),d=t.meta):(h=i.canonicDataLabels?n:b,d=t.info),i.dynamicTyping&&(u=me(u)),d[h]?(Array.isArray(d[h])||(d[h]=[d[h]]),d[h].push(u)):d[h]=u}}return L(a,"Finished parsing",i),B(p,a,i),L(a,"Total time",i),a.entries=s.children,a.flatten=p,a}export{de as convert,ne as createTree};
8
+ `);if(u===-1&&(u=f.indexOf("\r")),u>0){let d=f.substring(0,u).split(/[ ,;\t]+/);q(t,l,d[0]),l.datatable=d[0],d[1]&&d[1].indexOf("PEAKS")>-1?n="PEAKTABLE":d[1]&&(d[1].indexOf("XYDATA")||d[0].indexOf("++")>0)&&(n="XYDATA",l.nbPoints&&(l.deltaX=(l.lastX-l.firstX)/(l.nbPoints-1)))}}if(n==="XYDATA"){i.wantXY&&(w(l),f.match(/.*\+\+.*/)?(l.nbPoints&&(l.deltaX=(l.lastX-l.firstX)/(l.nbPoints-1)),U(l,f,a)):P(l,f,a),t.spectra.push(l),l={});continue}else if(n==="PEAKTABLE"){i.wantXY&&(w(l),P(l,f,a),t.spectra.push(l),l={});continue}if(n==="PEAKASSIGNMENTS"){i.wantXY&&(f.match(/.*([^A-Z]*).*/)&&V(l,f),t.spectra.push(l),l={});continue}if(n==="TITLE"){let u=t;u.children||(u.children=[]),t={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},u.children.push(t),o.push(u),p.push(t),t.title=f}else n==="DATATYPE"?(t.dataType=f,f.match(/(^nd|\snd\s)/i)&&(t.twoD=!0)):n==="NTUPLES"?f.match(/(^nd|\snd\s)/i)&&(t.twoD=!0):n==="DATACLASS"?t.dataClass=f:n==="XUNITS"?l.xUnits=f:n==="YUNITS"?l.yUnits=f:n==="FIRSTX"?l.firstX=Number(f):n==="LASTX"?l.lastX=Number(f):n==="FIRSTY"?l.firstY=Number(f):n==="LASTY"?l.lastY=Number(f):n==="NPOINTS"?l.nbPoints=Number(f):n==="XFACTOR"?l.xFactor=Number(f):n==="YFACTOR"?l.yFactor=Number(f):n==="MAXX"?l.maxX=Number(f):n==="MINX"?l.minX=Number(f):n==="MAXY"?l.maxY=Number(f):n==="MINY"?l.minY=Number(f):n==="DELTAX"?l.deltaX=Number(f):n===".OBSERVEFREQUENCY"||n==="$SFO1"?l.observeFrequency||(l.observeFrequency=Number(f)):n===".OBSERVENUCLEUS"?l.xType||(t.xType=f.replace(/[^a-zA-Z0-9]/g,"")):n==="$OFFSET"?(t.shiftOffsetNum=0,l.shiftOffsetVal||(l.shiftOffsetVal=Number(f))):n==="$REFERENCEPOINT"||(n==="VARNAME"?t.ntuples.varname=f.split(C):n==="SYMBOL"?t.ntuples.symbol=f.split(C):n==="VARTYPE"?t.ntuples.vartype=f.split(C):n==="VARFORM"?t.ntuples.varform=f.split(C):n==="VARDIM"?t.ntuples.vardim=Y(f.split(C)):n==="UNITS"?t.ntuples.units=f.split(C):n==="FACTOR"?t.ntuples.factor=Y(f.split(C)):n==="FIRST"?t.ntuples.first=Y(f.split(C)):n==="LAST"?t.ntuples.last=Y(f.split(C)):n==="MIN"?t.ntuples.min=Y(f.split(C)):n==="MAX"?t.ntuples.max=Y(f.split(C)):n===".NUCLEUS"?t.ntuples&&(t.ntuples.nucleus=f.split(C).map(u=>u.replace(/[^a-zA-Z0-9]/g,""))):n==="PAGE"?(l.page=f.trim(),l.pageValue=Number(f.replace(/^.*=/,"")),l.pageSymbol=l.page.replace(/[=].*/,"")):n==="RETENTIONTIME"?l.pageValue=Number(f):Q(n)?l[$(n)]=f:n==="SAMPLEDESCRIPTION"?l.sampleDescription=f:n.startsWith("$NUC")?!t.tmp[n]&&!f.includes("off")&&(t.tmp[n]=f.replace(/[<>]/g,"")):n==="END"&&(t=o.pop()));if(t&&t.info&&t.meta&&n.match(i.keepRecordsRegExp)){let u=f.trim(),d,h;b.startsWith("$")?(h=i.canonicMetadataLabels?n.substring(1):b.substring(1),d=t.meta):(h=i.canonicDataLabels?n:b,d=t.info),i.dynamicTyping&&(u=me(u)),d[h]?(Array.isArray(d[h])||(d[h]=[d[h]]),d[h].push(u)):d[h]=u}}return L(a,"Finished parsing",i),B(p,a,i),L(a,"Total time",i),a.entries=s.children,a.flatten=p,a}export{de as convert,ne as createTree};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcampconverter",
3
- "version": "9.2.1",
3
+ "version": "9.2.2",
4
4
  "description": "Parse and convert JCAMP data",
5
5
  "types": "jcampconverter.d.ts",
6
6
  "main": "jcampconverter.cjs",