Comparing version 1.0.1 to 1.1.0
@@ -0,1 +1,6 @@ | ||
<a name="1.1.0"></a> | ||
# [1.1.0](https://github.com/cheminfo-js/mzData/compare/v1.0.1...v1.1.0) (2018-10-25) | ||
<a name="1.0.1"></a> | ||
@@ -2,0 +7,0 @@ ## [1.0.1](https://github.com/cheminfo-js/mzData/compare/v0.2.0...v1.0.1) (2018-10-22) |
{ | ||
"name": "mzdata", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Read and explore mzData v1.05 files", | ||
"main": "lib/index.js", | ||
"module": "src/index.js", | ||
"main": "src/index.js", | ||
"browser": { | ||
"./src/util/ensureText.js": "./src/util/ensureTextBrowser.js" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src" | ||
@@ -14,7 +15,6 @@ ], | ||
"eslint-fix": "npm run eslint -- --fix", | ||
"prepublish": "rollup -c", | ||
"test": "run-s testonly eslint", | ||
"test-travis": "eslint src && jest --coverage && codecov", | ||
"testonly": "jest", | ||
"build": "rollup -c && cheminfo build" | ||
"build": "cheminfo build" | ||
}, | ||
@@ -26,3 +26,3 @@ "repository": { | ||
"keywords": [], | ||
"author": "Miguel Asencio", | ||
"author": "Miguel Asencio, Luc Patiny", | ||
"license": "MIT", | ||
@@ -37,3 +37,2 @@ "bugs": { | ||
"devDependencies": { | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", | ||
"cheminfo-tools": "^1.17.1", | ||
@@ -43,4 +42,5 @@ "codecov": "^2.2.0", | ||
"eslint-config-cheminfo": "^1.8.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-jest": "^21.26.1", | ||
"eslint-plugin-no-only-tests": "^2.0.0", | ||
"esm": "^3.0.84", | ||
"jest": "^21.2.1", | ||
@@ -51,5 +51,5 @@ "npm-run-all": "^4.0.2", | ||
"dependencies": { | ||
"base64-js": "^1.2.1", | ||
"sax": "^1.2.4" | ||
"base64-js": "^1.3.0", | ||
"fast-xml-parser": "^3.12.5" | ||
} | ||
} |
101
src/index.js
@@ -1,79 +0,46 @@ | ||
import {parser} from 'sax'; | ||
import {decoder, mergeSeries} from './utils'; | ||
'use strict'; | ||
const FastXmlParser = require('fast-xml-parser'); | ||
const processMetadata = require('./processMetaData'); | ||
const processSpectrumList = require('./processSpectrumList'); | ||
const ensureText = require('./util/ensureText'); | ||
/** | ||
* Reads a mzData v1.05 file | ||
* @param {ArrayBuffer} data - ArrayBuffer or any Typed Array (including Node.js' Buffer from v4) with the data | ||
* @param {ArrayBuffer|string} xml - ArrayBuffer or String or any Typed Array (including Node.js' Buffer from v4) with the data | ||
* @return {{times: Array<number>, series: { ms: { data:Array<Array<number>>}}}} | ||
*/ | ||
export default function mzData(data) { | ||
const xml = parser(true, {trim: true}); | ||
function mzData(xml) { | ||
xml = ensureText(xml); | ||
var result = { | ||
times: [], | ||
series: {} | ||
}; | ||
var error = []; | ||
var binaryData = {}; | ||
var mz = []; | ||
var int = []; | ||
var kind; | ||
if (typeof xml !== 'string') throw new Error('Unknown variable type'); | ||
xml.onopentag = (node) => { | ||
// eslint-disable-next-line default-case | ||
switch (node.name) { | ||
case 'mzData': | ||
kind = 'mzData'; | ||
break; | ||
case 'cvParam': | ||
if (node.attributes.name === 'TimeInMinutes') { | ||
result.times.push(Number(node.attributes.value)); | ||
} | ||
break; | ||
case 'mzArrayBinary': | ||
binaryData = { | ||
serie: 'mz' | ||
}; | ||
break; | ||
case 'intenArrayBinary': | ||
binaryData = { | ||
serie: 'int' | ||
}; | ||
break; | ||
case 'data': | ||
if (node.isSelfClosing) { | ||
if (binaryData.serie === 'mz') { | ||
mz.push([]); | ||
} else if (binaryData.serie === 'int') { | ||
int.push([]); | ||
} | ||
binaryData = {}; | ||
} else if (binaryData.serie) { | ||
binaryData.precision = node.attributes.precision; | ||
} | ||
break; | ||
} | ||
}; | ||
let parsed = FastXmlParser.parse(xml, { | ||
textNodeName: '_data', | ||
attributeNamePrefix: '', | ||
parseAttributeValue: true, | ||
attrNodeName: '_attr', | ||
ignoreAttributes: false | ||
}); | ||
xml.ontext = (raw) => { | ||
if (binaryData.serie === 'mz') { | ||
mz.push(decoder(raw, binaryData)); | ||
} else if (binaryData.serie === 'int') { | ||
int.push(decoder(raw, binaryData)); | ||
} | ||
binaryData = {}; | ||
}; | ||
if (!parsed.mzData) throw new Error('The parent node is not mzData'); | ||
xml.onerror = (err) => error.push(err); | ||
xml.write(data).close(); | ||
if (!kind || kind !== 'mzData') { | ||
throw new TypeError('Not a mzData file'); | ||
let result = { | ||
metadata: {}, | ||
times: [], | ||
series: { | ||
ms: { | ||
data: [] | ||
} | ||
} | ||
if (error.length > 0) { | ||
throw new Error(error); | ||
} | ||
}; | ||
result.series.ms = {}; | ||
result.series.ms.data = mergeSeries(mz, int); | ||
return result; | ||
processMetadata(parsed.mzData, result.metadata); | ||
processSpectrumList(parsed.mzData, result.times, result.series.ms.data); | ||
return result; | ||
} | ||
module.exports = mzData; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
10290
184
1
+ Addedfast-xml-parser@^3.12.5
+ Addedfast-xml-parser@3.21.1(transitive)
+ Addedstrnum@1.0.5(transitive)
- Removedsax@^1.2.4
- Removedsax@1.4.1(transitive)
Updatedbase64-js@^1.3.0