pubchem
Version:
pubchem simplifies the data retrieval from the PubChem API.
32 lines • 1.14 kB
JavaScript
import { compoundDataFromCID } from '../compoundData/from/compoundDataFromCID';
import { compoundFromInchiKey } from './from/compoundFromInchiKey';
import { compoundFromName } from './from/compoundFromName';
import { compoundFromSmiles } from './from/compoundFromSmiles';
export class Compound {
constructor(data, options = {}) {
this.data = data;
this.cache = options.cache;
}
getCID() {
return this.data?.id?.id?.cid;
}
getData() {
const cid = this.getCID();
const cd = compoundDataFromCID(cid, { cache: this.cache });
return cd;
}
toJSON() {
const methods = Object.entries(Object.getOwnPropertyDescriptors(Compound.prototype))
.filter(([, descriptor]) => typeof descriptor.get === 'function')
.map(([key]) => key);
const result = {};
for (const method of methods) {
result[method] = this[method];
}
return result;
}
}
Compound.fromSmiles = compoundFromSmiles;
Compound.fromName = compoundFromName;
Compound.fromInchiKey = compoundFromInchiKey;
//# sourceMappingURL=Compound.js.map