UNPKG

pubchem

Version:

pubchem simplifies the data retrieval from the PubChem API.

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