UNPKG

pubchem

Version:

pubchem simplifies the data retrieval from the PubChem API.

23 lines 883 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.compoundFromName = compoundFromName; const Compound_1 = require("../Compound"); const handleError_1 = require("./handleError"); async function compoundFromName(smiles, options = {}) { const { cache } = options; let compounds; if (cache?.(smiles)) { compounds = cache(smiles); } else { const encodedName = encodeURIComponent(smiles); const moleculeResponse = await fetch(`https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/${encodedName}/json`); compounds = (await moleculeResponse.json()).PC_Compounds; if (cache) { cache(smiles, compounds); } } (0, handleError_1.checkCompoundsResult)(compounds); return new Compound_1.Compound(compounds[0], { cache }); } //# sourceMappingURL=compoundFromName.js.map