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