pubchem
Version:
pubchem simplifies the data retrieval from the PubChem API.
22 lines • 798 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cache = cache;
const fs_1 = require("fs");
const path_1 = require("path");
const md5_1 = __importDefault(require("md5"));
function cache(query, value) {
const filename = (0, path_1.join)(__dirname, `../../cache/${(0, md5_1.default)(query)}.json`);
if (!value) {
if (!(0, fs_1.existsSync)(filename))
return undefined;
return JSON.parse((0, fs_1.readFileSync)(filename, 'utf8'));
}
else {
// we save to cache
(0, fs_1.writeFileSync)(filename, JSON.stringify(value), 'utf8');
}
}
//# sourceMappingURL=cache.js.map