Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mzdata

Package Overview
Dependencies
Maintainers
6
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mzdata - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

src/__tests__/mzData.test.js

5

History.md

@@ -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)

22

package.json
{
"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"
}
}

@@ -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;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc