jcampconverter 8.2.0 → 8.2.4

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.
Files changed (145) hide show
  1. package/lib/2d/add2D.d.ts +2 -0
  2. package/lib/2d/add2D.d.ts.map +1 -0
  3. package/lib/2d/add2D.js +17 -0
  4. package/lib/2d/add2D.js.map +1 -0
  5. package/lib/2d/convertTo3DZ.d.ts +11 -0
  6. package/lib/2d/convertTo3DZ.d.ts.map +1 -0
  7. package/lib/2d/convertTo3DZ.js +59 -0
  8. package/lib/2d/convertTo3DZ.js.map +1 -0
  9. package/lib/2d/generateContourLines.d.ts +8 -0
  10. package/lib/2d/generateContourLines.d.ts.map +1 -0
  11. package/lib/2d/generateContourLines.js +163 -0
  12. package/lib/2d/generateContourLines.js.map +1 -0
  13. package/lib/complexChromatogram.d.ts +4 -0
  14. package/lib/complexChromatogram.d.ts.map +1 -0
  15. package/lib/complexChromatogram.js +49 -0
  16. package/lib/complexChromatogram.js.map +1 -0
  17. package/lib/convert.d.ts +147 -0
  18. package/lib/convert.d.ts.map +1 -0
  19. package/lib/convert.js +391 -0
  20. package/lib/convert.js.map +1 -0
  21. package/lib/convertToFloatArray.d.ts +2 -0
  22. package/lib/convertToFloatArray.d.ts.map +1 -0
  23. package/lib/convertToFloatArray.js +11 -0
  24. package/lib/convertToFloatArray.js.map +1 -0
  25. package/lib/createTree.d.ts +29 -0
  26. package/lib/createTree.d.ts.map +1 -0
  27. package/lib/createTree.js +98 -0
  28. package/lib/createTree.js.map +1 -0
  29. package/lib/index.d.ts +3 -0
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +8 -1213
  32. package/lib/index.js.map +1 -0
  33. package/lib/parse/fastParseXYData.d.ts +2 -0
  34. package/lib/parse/fastParseXYData.d.ts.map +1 -0
  35. package/lib/parse/fastParseXYData.js +192 -0
  36. package/lib/parse/fastParseXYData.js.map +1 -0
  37. package/lib/parse/parsePeakTable.d.ts +2 -0
  38. package/lib/parse/parsePeakTable.d.ts.map +1 -0
  39. package/lib/parse/parsePeakTable.js +67 -0
  40. package/lib/parse/parsePeakTable.js.map +1 -0
  41. package/lib/parse/parseXYA.d.ts +2 -0
  42. package/lib/parse/parseXYA.d.ts.map +1 -0
  43. package/lib/parse/parseXYA.js +17 -0
  44. package/lib/parse/parseXYA.js.map +1 -0
  45. package/lib/postProcessing.d.ts +2 -0
  46. package/lib/postProcessing.d.ts.map +1 -0
  47. package/lib/postProcessing.js +50 -0
  48. package/lib/postProcessing.js.map +1 -0
  49. package/lib/postProcessingNMR.d.ts +2 -0
  50. package/lib/postProcessingNMR.d.ts.map +1 -0
  51. package/lib/postProcessingNMR.js +94 -0
  52. package/lib/postProcessingNMR.js.map +1 -0
  53. package/lib/prepareNtuplesDatatable.d.ts +2 -0
  54. package/lib/prepareNtuplesDatatable.d.ts.map +1 -0
  55. package/lib/prepareNtuplesDatatable.js +87 -0
  56. package/lib/prepareNtuplesDatatable.js.map +1 -0
  57. package/lib/prepareSpectrum.d.ts +2 -0
  58. package/lib/prepareSpectrum.d.ts.map +1 -0
  59. package/lib/prepareSpectrum.js +10 -0
  60. package/lib/prepareSpectrum.js.map +1 -0
  61. package/lib/profiling.d.ts +2 -0
  62. package/lib/profiling.d.ts.map +1 -0
  63. package/lib/profiling.js +12 -0
  64. package/lib/profiling.js.map +1 -0
  65. package/lib/simpleChromatogram.d.ts +2 -0
  66. package/lib/simpleChromatogram.d.ts.map +1 -0
  67. package/lib/simpleChromatogram.js +16 -0
  68. package/lib/simpleChromatogram.js.map +1 -0
  69. package/lib-esm/2d/add2D.d.ts +2 -0
  70. package/lib-esm/2d/add2D.d.ts.map +1 -0
  71. package/lib-esm/2d/add2D.js +11 -0
  72. package/lib-esm/2d/add2D.js.map +1 -0
  73. package/lib-esm/2d/convertTo3DZ.d.ts +11 -0
  74. package/lib-esm/2d/convertTo3DZ.d.ts.map +1 -0
  75. package/lib-esm/2d/convertTo3DZ.js +53 -0
  76. package/lib-esm/2d/convertTo3DZ.js.map +1 -0
  77. package/lib-esm/2d/generateContourLines.d.ts +8 -0
  78. package/lib-esm/2d/generateContourLines.d.ts.map +1 -0
  79. package/lib-esm/2d/generateContourLines.js +160 -0
  80. package/lib-esm/2d/generateContourLines.js.map +1 -0
  81. package/lib-esm/complexChromatogram.d.ts +4 -0
  82. package/lib-esm/complexChromatogram.d.ts.map +1 -0
  83. package/lib-esm/complexChromatogram.js +43 -0
  84. package/lib-esm/complexChromatogram.js.map +1 -0
  85. package/lib-esm/convert.d.ts +147 -0
  86. package/lib-esm/convert.d.ts.map +1 -0
  87. package/lib-esm/convert.js +384 -0
  88. package/lib-esm/convert.js.map +1 -0
  89. package/lib-esm/convertToFloatArray.d.ts +2 -0
  90. package/lib-esm/convertToFloatArray.d.ts.map +1 -0
  91. package/lib-esm/convertToFloatArray.js +8 -0
  92. package/lib-esm/convertToFloatArray.js.map +1 -0
  93. package/lib-esm/createTree.d.ts +29 -0
  94. package/lib-esm/createTree.d.ts.map +1 -0
  95. package/lib-esm/createTree.js +94 -0
  96. package/lib-esm/createTree.js.map +1 -0
  97. package/lib-esm/index.d.ts +3 -0
  98. package/lib-esm/index.d.ts.map +1 -0
  99. package/lib-esm/index.js +3 -0
  100. package/lib-esm/index.js.map +1 -0
  101. package/lib-esm/parse/fastParseXYData.d.ts +2 -0
  102. package/lib-esm/parse/fastParseXYData.d.ts.map +1 -0
  103. package/lib-esm/parse/fastParseXYData.js +189 -0
  104. package/lib-esm/parse/fastParseXYData.js.map +1 -0
  105. package/lib-esm/parse/parsePeakTable.d.ts +2 -0
  106. package/lib-esm/parse/parsePeakTable.d.ts.map +1 -0
  107. package/lib-esm/parse/parsePeakTable.js +64 -0
  108. package/lib-esm/parse/parsePeakTable.js.map +1 -0
  109. package/lib-esm/parse/parseXYA.d.ts +2 -0
  110. package/lib-esm/parse/parseXYA.d.ts.map +1 -0
  111. package/lib-esm/parse/parseXYA.js +14 -0
  112. package/lib-esm/parse/parseXYA.js.map +1 -0
  113. package/lib-esm/postProcessing.d.ts +2 -0
  114. package/lib-esm/postProcessing.d.ts.map +1 -0
  115. package/lib-esm/postProcessing.js +44 -0
  116. package/lib-esm/postProcessing.js.map +1 -0
  117. package/lib-esm/postProcessingNMR.d.ts +2 -0
  118. package/lib-esm/postProcessingNMR.d.ts.map +1 -0
  119. package/lib-esm/postProcessingNMR.js +91 -0
  120. package/lib-esm/postProcessingNMR.js.map +1 -0
  121. package/lib-esm/prepareNtuplesDatatable.d.ts +2 -0
  122. package/lib-esm/prepareNtuplesDatatable.d.ts.map +1 -0
  123. package/lib-esm/prepareNtuplesDatatable.js +84 -0
  124. package/lib-esm/prepareNtuplesDatatable.js.map +1 -0
  125. package/lib-esm/prepareSpectrum.d.ts +2 -0
  126. package/lib-esm/prepareSpectrum.d.ts.map +1 -0
  127. package/lib-esm/prepareSpectrum.js +7 -0
  128. package/lib-esm/prepareSpectrum.js.map +1 -0
  129. package/lib-esm/profiling.d.ts +2 -0
  130. package/lib-esm/profiling.d.ts.map +1 -0
  131. package/lib-esm/profiling.js +9 -0
  132. package/lib-esm/profiling.js.map +1 -0
  133. package/lib-esm/simpleChromatogram.d.ts +2 -0
  134. package/lib-esm/simpleChromatogram.d.ts.map +1 -0
  135. package/lib-esm/simpleChromatogram.js +13 -0
  136. package/lib-esm/simpleChromatogram.js.map +1 -0
  137. package/package.json +28 -23
  138. package/src/complexChromatogram.js +1 -1
  139. package/src/convert.js +92 -37
  140. package/src/convertToFloatArray.js +1 -1
  141. package/src/createTree.js +20 -6
  142. package/src/index.js +2 -2
  143. package/src/parse/parsePeakTable.js +4 -6
  144. package/src/parse/parseXYA.js +2 -2
  145. package/CHANGELOG.md +0 -412
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "jcampconverter",
3
- "version": "8.2.0",
3
+ "version": "8.2.4",
4
4
  "description": "Parse and convert JCAMP data",
5
5
  "main": "lib/index.js",
6
- "module": "src/index.js",
6
+ "module": "lib-esm/index.js",
7
+ "types": "lib/index.d.ts",
7
8
  "files": [
8
9
  "lib",
9
- "src"
10
+ "src",
11
+ "lib-esm"
10
12
  ],
11
13
  "prettier": {
12
14
  "arrowParens": "always",
@@ -17,13 +19,20 @@
17
19
  },
18
20
  "scripts": {
19
21
  "build": "cheminfo-build --entry src/index.js --root JcampConverter",
20
- "compile": "rollup -c",
21
- "prepack": "npm run compile",
22
+ "check-types": "tsc --noEmit",
23
+ "clean": "rimraf lib lib-esm",
22
24
  "eslint": "eslint src __tests__",
23
25
  "eslint-fix": "npm run eslint -- --fix",
24
- "test": "npm run test-coverage && npm run eslint",
26
+ "jscpd": "jscpd -l 10 -i \"**/__tests__/**\" -t 1 src",
27
+ "prepack": "npm run tsc",
28
+ "prettier": "prettier --check src",
29
+ "prettier-write": "prettier --write src",
30
+ "test": "npm run test-coverage && npm run eslint && npm run prettier && npm run check-types",
25
31
  "test-coverage": "jest --coverage",
26
32
  "test-only": "jest",
33
+ "tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
34
+ "tsc-cjs": "tsc --project tsconfig.cjs.json",
35
+ "tsc-esm": "tsc --project tsconfig.esm.json",
27
36
  "benchmark": "node benchmark/benchmark.js",
28
37
  "deopt": "node --trace-opt --trace-deopt --code-comments debug/deoptimize.js > deopt.log",
29
38
  "hydra": "node --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces --redirect-code-traces-to=code.asm debug/deoptimize.js"
@@ -42,29 +51,25 @@
42
51
  "url": "https://github.com/cheminfo/jcampconverter/issues"
43
52
  },
44
53
  "homepage": "https://github.com/cheminfo/jcampconverter#readme",
45
- "jest": {
46
- "testEnvironment": "node"
47
- },
48
54
  "devDependencies": {
49
- "@babel/plugin-transform-modules-commonjs": "^7.15.4",
50
- "@types/jest": "^27.0.1",
55
+ "@types/jest": "^27.0.3",
51
56
  "benchmark": "^2.1.4",
52
57
  "cheminfo-build": "^1.1.11",
53
- "eslint": "^7.32.0",
54
- "eslint-config-cheminfo": "^5.4.0",
55
- "eslint-plugin-import": "^2.24.2",
56
- "eslint-plugin-jest": "^24.4.0",
57
- "eslint-plugin-prettier": "^4.0.0",
58
+ "eslint": "^8.4.1",
59
+ "eslint-config-cheminfo-typescript": "^10.2.4",
58
60
  "esm": "^3.2.25",
59
- "jest": "^27.1.0",
60
- "jest-matcher-deep-close-to": "^2.0.1",
61
- "prettier": "^2.3.2",
62
- "rollup": "^2.56.3"
61
+ "jest": "^27.4.5",
62
+ "jest-matcher-deep-close-to": "^3.0.2",
63
+ "jscpd": "^3.4.2",
64
+ "prettier": "^2.5.1",
65
+ "rimraf": "^3.0.2",
66
+ "ts-jest": "^27.1.1",
67
+ "typescript": "^4.5.4"
63
68
  },
64
69
  "dependencies": {
65
- "dynamic-typing": "^0.1.2",
66
- "ensure-string": "^1.0.0",
70
+ "dynamic-typing": "^0.1.3",
71
+ "ensure-string": "^1.1.0",
67
72
  "ml-array-median": "^1.1.5",
68
- "nmr-processing": "^2.5.0"
73
+ "nmr-processing": "^6.0.2"
69
74
  }
70
75
  }
@@ -29,7 +29,7 @@ export function complexChromatogram(result) {
29
29
  let spectrum = spectra[i];
30
30
  chromatogram.times[i] = spectrum.pageValue;
31
31
  for (let j = 0; j < existingGCMSFields.length; j++) {
32
- chromatogram.series[existingGCMSFields[j]].data[i] = parseFloat(
32
+ chromatogram.series[existingGCMSFields[j]].data[i] = Number(
33
33
  spectrum[existingGCMSFields[j]],
34
34
  );
35
35
  }
package/src/convert.js CHANGED
@@ -14,8 +14,6 @@ import profiling from './profiling';
14
14
  // the following RegExp can only be used for XYdata, some peakTables have values with a "E-5" ...
15
15
  const ntuplesSeparatorRegExp = /[ \t]*,[ \t]*/;
16
16
 
17
- class Spectrum {}
18
-
19
17
  const defaultOptions = {
20
18
  keepRecordsRegExp: /^$/,
21
19
  canonicDataLabels: true,
@@ -32,22 +30,79 @@ const defaultOptions = {
32
30
 
33
31
  /**
34
32
  *
35
- * @param {string|ArrayBuffer} jcamp
36
- * @param {object} [options]
37
- * @param {number} [options.keepRecordsRegExp=/^$/] By default we don't keep meta information
38
- * @param {number} [options.canonicDataLabels=true] Canonize the Labels (uppercase without symbol)
39
- * @param {number} [options.canonicMetadataLabels=false] Canonize the metadata Labels (uppercase without symbol)
40
- * @param {number} [options.dynamicTyping=false] Convert numbers to Number
41
- * @param {number} [options.withoutXY=false] Remove the XY data
42
- * @param {number} [options.chromatogram=false] Special post-processing for GC / HPLC / MS
43
- * @param {number} [options.keepSpectra=false] Force to keep the spectra in case of 2D
44
- * @param {number} [options.noContour=false] Don't calculate countour in case of 2D
45
- * @param {number} [options.nbContourLevels=7] Number of positive / negative contour levels to calculate
46
- * @param {number} [options.noiseMultiplier=5] Define for 2D the level as 5 times the median as default
47
- * @param {number} [options.profiling=false] Add profiling information
33
+ * @typedef {object} ConvertOptions
34
+ * @property {RegExp} [options.keepRecordsRegExp=/^$/] - By default we don't keep meta information.
35
+ * @property {boolean} [options.canonicDataLabels=true] - Canonize the Labels (uppercase without symbol).
36
+ * @property {boolean} [options.canonicMetadataLabels=false] - Canonize the metadata Labels (uppercase without symbol).
37
+ * @property {boolean} [options.dynamicTyping=false] - Convert numbers to Number.
38
+ * @property {boolean} [options.withoutXY=false] - Remove the XY data.
39
+ * @property {boolean} [options.chromatogram=false] - Special post-processing for GC / HPLC / MS.
40
+ * @property {boolean} [options.keepSpectra=false] - Force to keep the spectra in case of 2D.
41
+ * @property {boolean} [options.noContour=false] - Don't calculate countour in case of 2D.
42
+ * @property {number} [options.nbContourLevels=7] - Number of positive / negative contour levels to calculate.
43
+ * @property {number} [options.noiseMultiplier=5] - Define for 2D the level as 5 times the median as default.
44
+ * @property {boolean} [options.profiling=false] - Add profiling information.
45
+ */
46
+
47
+ /**
48
+ *
49
+ * @typedef {object} Ntuples
50
+ * @property {string[]} [varname]
51
+ * @property {string[]} [symbol]
52
+ * @property {string[]} [vartype]
53
+ * @property {string[]} [varform]
54
+ * @property {number[]} [vardim]
55
+ * @property {string[]} [units]
56
+ * @property {number[]} [factor]
57
+ * @property {number[]} [first]
58
+ * @property {number[]} [last]
59
+ * @property {number[]} [min]
60
+ * @property {number[]} [max]
61
+ * @property {string[]} [nucleus]
62
+ */
63
+
64
+ /**
65
+ * @typedef { Record<string, any> } Spectrum
66
+ * @property {Record<string, number[]>} [data]
67
+ * @property {number} [firstX]
68
+ * @property {number} [lastX]
69
+ * @property {number} [deltaX]
70
+ * @property {number} [yFactor]
71
+ * @property {number} [xFactor]
72
+ * @property {number} [nbPoints]
73
+ */
74
+
75
+ /**
76
+ *
77
+ * @typedef {object} Entry
78
+ * @property {Spectrum[]} spectra
79
+ * @property {Ntuples} ntuples
80
+ * @property {object} meta
81
+ * @property {object} tmp
82
+ * @property {string} [title]
83
+ * @property {string} [dataType]
84
+ * @property {string} [dataClass]
85
+ * @property {boolean} [twoD]
86
+ */
87
+
88
+ /**
89
+ *
90
+ * @typedef { object } ConvertResult
91
+ * @property { object[] | boolean } profiling
92
+ * @property { string[] } logs
93
+ * @property { object[] } entries
94
+ * @property { Entry[] } flatten
95
+ */
96
+
97
+ /**
98
+ * Parse a jcamp.
99
+ *
100
+ * @param {string|ArrayBuffer|Uint8Array} jcamp
101
+ * @param {ConvertOptions} [options]
102
+ * @returns {ConvertResult}
48
103
  */
49
104
 
50
- export default function convert(jcamp, options = {}) {
105
+ export function convert(jcamp, options = {}) {
51
106
  jcamp = ensureString(jcamp);
52
107
  options = { ...defaultOptions, ...options };
53
108
  options.wantXY = !options.withoutXY;
@@ -65,7 +120,7 @@ export default function convert(jcamp, options = {}) {
65
120
  let currentEntry = tmpResult;
66
121
  let parentsStack = [];
67
122
 
68
- let spectrum = new Spectrum();
123
+ let spectrum = {};
69
124
 
70
125
  if (typeof jcamp !== 'string') {
71
126
  throw new TypeError('the JCAMP should be a string');
@@ -125,7 +180,7 @@ export default function convert(jcamp, options = {}) {
125
180
  parsePeakTable(spectrum, dataValue, result);
126
181
  }
127
182
  currentEntry.spectra.push(spectrum);
128
- spectrum = new Spectrum();
183
+ spectrum = {};
129
184
  }
130
185
  continue;
131
186
  } else if (canonicDataLabel === 'PEAKTABLE') {
@@ -133,7 +188,7 @@ export default function convert(jcamp, options = {}) {
133
188
  prepareSpectrum(spectrum);
134
189
  parsePeakTable(spectrum, dataValue, result);
135
190
  currentEntry.spectra.push(spectrum);
136
- spectrum = new Spectrum();
191
+ spectrum = {};
137
192
  }
138
193
  continue;
139
194
  }
@@ -144,7 +199,7 @@ export default function convert(jcamp, options = {}) {
144
199
  parseXYA(spectrum, dataValue);
145
200
  }
146
201
  currentEntry.spectra.push(spectrum);
147
- spectrum = new Spectrum();
202
+ spectrum = {};
148
203
  }
149
204
  continue;
150
205
  }
@@ -181,35 +236,35 @@ export default function convert(jcamp, options = {}) {
181
236
  } else if (canonicDataLabel === 'YUNITS') {
182
237
  spectrum.yUnits = dataValue;
183
238
  } else if (canonicDataLabel === 'FIRSTX') {
184
- spectrum.firstX = parseFloat(dataValue);
239
+ spectrum.firstX = Number(dataValue);
185
240
  } else if (canonicDataLabel === 'LASTX') {
186
- spectrum.lastX = parseFloat(dataValue);
241
+ spectrum.lastX = Number(dataValue);
187
242
  } else if (canonicDataLabel === 'FIRSTY') {
188
- spectrum.firstY = parseFloat(dataValue);
243
+ spectrum.firstY = Number(dataValue);
189
244
  } else if (canonicDataLabel === 'LASTY') {
190
- spectrum.lastY = parseFloat(dataValue);
245
+ spectrum.lastY = Number(dataValue);
191
246
  } else if (canonicDataLabel === 'NPOINTS') {
192
- spectrum.nbPoints = parseFloat(dataValue);
247
+ spectrum.nbPoints = Number(dataValue);
193
248
  } else if (canonicDataLabel === 'XFACTOR') {
194
- spectrum.xFactor = parseFloat(dataValue);
249
+ spectrum.xFactor = Number(dataValue);
195
250
  } else if (canonicDataLabel === 'YFACTOR') {
196
- spectrum.yFactor = parseFloat(dataValue);
251
+ spectrum.yFactor = Number(dataValue);
197
252
  } else if (canonicDataLabel === 'MAXX') {
198
- spectrum.maxX = parseFloat(dataValue);
253
+ spectrum.maxX = Number(dataValue);
199
254
  } else if (canonicDataLabel === 'MINX') {
200
- spectrum.minX = parseFloat(dataValue);
255
+ spectrum.minX = Number(dataValue);
201
256
  } else if (canonicDataLabel === 'MAXY') {
202
- spectrum.maxY = parseFloat(dataValue);
257
+ spectrum.maxY = Number(dataValue);
203
258
  } else if (canonicDataLabel === 'MINY') {
204
- spectrum.minY = parseFloat(dataValue);
259
+ spectrum.minY = Number(dataValue);
205
260
  } else if (canonicDataLabel === 'DELTAX') {
206
- spectrum.deltaX = parseFloat(dataValue);
261
+ spectrum.deltaX = Number(dataValue);
207
262
  } else if (
208
263
  canonicDataLabel === '.OBSERVEFREQUENCY' ||
209
264
  canonicDataLabel === '$SFO1'
210
265
  ) {
211
266
  if (!spectrum.observeFrequency) {
212
- spectrum.observeFrequency = parseFloat(dataValue);
267
+ spectrum.observeFrequency = Number(dataValue);
213
268
  }
214
269
  } else if (canonicDataLabel === '.OBSERVENUCLEUS') {
215
270
  if (!spectrum.xType) {
@@ -219,7 +274,7 @@ export default function convert(jcamp, options = {}) {
219
274
  // OFFSET for Bruker spectra
220
275
  currentEntry.shiftOffsetNum = 0;
221
276
  if (!spectrum.shiftOffsetVal) {
222
- spectrum.shiftOffsetVal = parseFloat(dataValue);
277
+ spectrum.shiftOffsetVal = Number(dataValue);
223
278
  }
224
279
  } else if (canonicDataLabel === '$REFERENCEPOINT') {
225
280
  // OFFSET for Varian spectra
@@ -227,7 +282,7 @@ export default function convert(jcamp, options = {}) {
227
282
  // } else if (canonicDataLabel=='.SHIFTREFERENCE') { // OFFSET FOR Bruker Spectra
228
283
  // var parts = dataValue.split(/ *, */);
229
284
  // currentEntry.shiftOffsetNum = parseInt(parts[2].trim());
230
- // spectrum.shiftOffsetVal = parseFloat(parts[3].trim());
285
+ // spectrum.shiftOffsetVal = Number(parts[3].trim());
231
286
  } else if (canonicDataLabel === 'VARNAME') {
232
287
  currentEntry.ntuples.varname = dataValue.split(ntuplesSeparatorRegExp);
233
288
  } else if (canonicDataLabel === 'SYMBOL') {
@@ -268,10 +323,10 @@ export default function convert(jcamp, options = {}) {
268
323
  }
269
324
  } else if (canonicDataLabel === 'PAGE') {
270
325
  spectrum.page = dataValue.trim();
271
- spectrum.pageValue = parseFloat(dataValue.replace(/^.*=/, ''));
326
+ spectrum.pageValue = Number(dataValue.replace(/^.*=/, ''));
272
327
  spectrum.pageSymbol = spectrum.page.replace(/[=].*/, '');
273
328
  } else if (canonicDataLabel === 'RETENTIONTIME') {
274
- spectrum.pageValue = parseFloat(dataValue);
329
+ spectrum.pageValue = Number(dataValue);
275
330
  } else if (isMSField(canonicDataLabel)) {
276
331
  spectrum[convertMSFieldToLabel(canonicDataLabel)] = dataValue;
277
332
  } else if (canonicDataLabel === 'SAMPLEDESCRIPTION') {
@@ -1,7 +1,7 @@
1
1
  export default function convertToFloatArray(stringArray) {
2
2
  let floatArray = [];
3
3
  for (let i = 0; i < stringArray.length; i++) {
4
- floatArray.push(parseFloat(stringArray[i]));
4
+ floatArray.push(Number(stringArray[i]));
5
5
  }
6
6
  return floatArray;
7
7
  }
package/src/createTree.js CHANGED
@@ -1,13 +1,27 @@
1
1
  import { ensureString } from 'ensure-string';
2
2
 
3
3
  /**
4
- * Parse the jcamp to extract the structure as a tree
5
- * @param {string|ArrayBuffer jcamp
6
- * @param {object} [options={}]
7
- * @param {boolean} [options.flatten=false]
8
- * @returns
4
+ *
5
+ * @typedef {object} CreateTreeOptions
6
+ * @property {boolean} [flatten=false]
9
7
  */
10
- export default function createTree(jcamp, options = {}) {
8
+
9
+ /**
10
+ *
11
+ * @typedef {object} Tree
12
+ * @property {string} title
13
+ * @property {string} jcamp
14
+ * @property {Tree[]} [children]
15
+ */
16
+
17
+ /**
18
+ * Parse the jcamp to extract the structure as a tree.
19
+ *
20
+ * @param {string|ArrayBuffer|Uint8Array} jcamp
21
+ * @param {CreateTreeOptions} [options={}]
22
+ * @returns {Tree[]}
23
+ */
24
+ export function createTree(jcamp, options = {}) {
11
25
  jcamp = ensureString(jcamp);
12
26
  const { flatten = false } = options;
13
27
  if (typeof jcamp !== 'string') {
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { default as createTree } from './createTree';
2
- export { default as convert } from './convert';
1
+ export { createTree } from './createTree';
2
+ export { convert } from './convert';
@@ -32,9 +32,9 @@ function parseXY(spectrum, value, result) {
32
32
  .split(peakTableSplitRegExp);
33
33
  if (values.length % 2 === 0) {
34
34
  for (let j = 0; j < values.length; j = j + 2) {
35
- // takes around 40% of the time to add and parse the 2 values nearly exclusively because of parseFloat
36
- currentData.x.push(parseFloat(values[j]) * spectrum.xFactor);
37
- currentData.y.push(parseFloat(values[j + 1]) * spectrum.yFactor);
35
+ // takes around 40% of the time to add and parse the 2 values nearly exclusively because of Number
36
+ currentData.x.push(Number(values[j]) * spectrum.xFactor);
37
+ currentData.y.push(Number(values[j + 1]) * spectrum.yFactor);
38
38
  }
39
39
  } else {
40
40
  result.logs.push(`Format error: ${values}`);
@@ -60,9 +60,7 @@ function parseXYZ(spectrum, value, result) {
60
60
  if (values.length % numberOfVariables === 0) {
61
61
  for (let j = 0; j < values.length; j++) {
62
62
  // todo should try to find a xFactor (y, ...)
63
- currentData[variables[j % numberOfVariables]].push(
64
- parseFloat(values[j]),
65
- );
63
+ currentData[variables[j % numberOfVariables]].push(Number(values[j]));
66
64
  }
67
65
  } else {
68
66
  result.logs.push(`Format error: ${values}`);
@@ -10,7 +10,7 @@ export default function parseXYA(spectrum, value) {
10
10
 
11
11
  for (let i = 1; i < lines.length; i++) {
12
12
  values = lines[i].trim().replace(removeSymbolRegExp, '').split(',');
13
- currentData.x.push(parseFloat(values[0]));
14
- currentData.y.push(parseFloat(values[1]));
13
+ currentData.x.push(Number(values[0]));
14
+ currentData.y.push(Number(values[1]));
15
15
  }
16
16
  }