UNPKG

meta-og-scrape

Version:

Scrape meta, link & open graph tags from the head of document as a JavaScript object (JSON)

31 lines (27 loc) 842 B
/** * Source https://github.com/strongloop/loopback-connector-rest/blob/master/lib/utils.js#L3 */ exports.createPromiseCallback = createPromiseCallback; function createPromiseCallback() { var cb; if (!global.Promise) { cb = function(){}; cb.promise = {}; Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined }); Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined }); return cb; } var promise = new Promise(function (resolve, reject) { cb = function (err, data) { if (err) return reject(err); return resolve(data); }; }); cb.promise = promise; return cb; } function throwPromiseNotDefined() { throw new Error( 'Your Node runtime does support ES6 Promises. ' + 'Set "global.Promise" to your preferred implementation of promises.'); }