molstar
Version:
A comprehensive macromolecular library.
40 lines • 1.16 kB
JavaScript
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.guessElement = void 0;
var elm1 = ['H', 'C', 'O', 'N', 'S', 'P'];
var elm2 = ['NA', 'CL', 'FE'];
function charAtIsNumber(str, index) {
var code = str.charCodeAt(index);
return code >= 48 && code <= 57;
}
function guessElement(str) {
var at = str.trim().toUpperCase();
if (charAtIsNumber(at, 0))
at = at.substr(1);
// parse again to check for a second integer
if (charAtIsNumber(at, 0))
at = at.substr(1);
var n = at.length;
if (n === 0)
return '';
if (n === 1)
return at;
if (n === 2) {
if (elm2.indexOf(at) !== -1)
return at;
if (elm1.indexOf(at[0]) !== -1)
return at[0];
}
if (n >= 3) {
if (elm1.indexOf(at[0]) !== -1)
return at[0];
}
return '';
}
exports.guessElement = guessElement;
//# sourceMappingURL=guess-element.js.map
;