jcampconverter
Advanced tools
Comparing version 2.8.0 to 2.9.1
{ | ||
"name": "jcampconverter", | ||
"version": "2.8.0", | ||
"version": "2.9.1", | ||
"description": "Parse and convert JCAMP data", | ||
@@ -41,8 +41,8 @@ "main": "./src/index.js", | ||
"codecov": "^2.3.0", | ||
"eslint": "^4.4.1", | ||
"eslint": "^4.6.1", | ||
"eslint-config-cheminfo": "^1.8.0", | ||
"eslint-plugin-no-only-tests": "^2.0.0", | ||
"jest": "^20.0.4", | ||
"npm-run-all": "^4.0.2" | ||
"jest": "^21.0.2", | ||
"npm-run-all": "^4.1.1" | ||
} | ||
} |
@@ -860,4 +860,55 @@ 'use strict'; | ||
function createTree(jcamp) { | ||
if (typeof jcamp !== 'string') { | ||
throw new TypeError('the JCAMP should be a string'); | ||
} | ||
var lines = jcamp.split(/[\r\n]+/); | ||
var stack = []; | ||
var result = []; | ||
var current; | ||
var ntupleLevel = 0; | ||
for (var i = 0; i < lines.length; i++) { | ||
var line = lines[i]; | ||
if (line.substring(0, 9) === '##NTUPLES') { | ||
ntupleLevel++; | ||
} | ||
if (line.substring(0, 7) === '##TITLE') { | ||
stack.push({ | ||
title: line.substring(8).trim(), | ||
jcamp: line + '\n', | ||
children: [] | ||
}); | ||
current = stack[stack.length - 1]; | ||
} else if (line.substring(0, 5) === '##END' && ntupleLevel === 0) { | ||
current.jcamp += line + '\n'; | ||
var finished = stack.pop(); | ||
if (stack.length !== 0) { | ||
current = stack[stack.length - 1]; | ||
current.children.push(finished); | ||
} else { | ||
current = undefined; | ||
result.push(finished); | ||
} | ||
} else if (current && current.jcamp) { | ||
current.jcamp += line + '\n'; | ||
if (line.substring(0, 10) === '##DATATYPE') { | ||
current.dataType = line.substring(11).trim(); | ||
} | ||
} | ||
if (line.substring(0, 5) === '##END' && ntupleLevel > 0) { | ||
ntupleLevel--; | ||
} | ||
} | ||
return result; | ||
} | ||
module.exports = { | ||
convert: JcampConverter | ||
convert: JcampConverter, | ||
createTree: createTree | ||
}; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
46153
5
825
1