Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!Object.keys(metadata).length){
return BBPromise.reject(Error('No COinS in provided string'));
}
if (metadata.rft && metadata.rft.genre){
metadata.rft.genre = metadata.rft.genre.toLowerCase(); // Genre should be case insensitive as this field may be used programmatically
}
return metadata;
});
/**
* Scrapes Dublin Core data given Cheerio loaded html object
* @param {Object} chtml html Cheerio object
* @return {Object} BBPromise for DC metadata
*/
exports.parseDublinCore = BBPromise.method(function(chtml){
return exports.parseBase(
chtml,
['meta', 'link'],
'No Dublin Core metadata found in page',
function(element) {
var isLink = element[0].name === 'link';
var nameAttr = element.attr(isLink ? 'rel' : 'name');
var value = element.attr(isLink ? 'href' : 'content');
// If the element isn't a Dublin Core property or if value is missing, skip it
if (!nameAttr || !value
|| (nameAttr.substring(0, 3).toUpperCase() !== 'DC.'
&& nameAttr.substring(0, 8).toUpperCase() !== 'DCTERMS.')) {
return;
}
// Reject promise if meta is empty
if (Object.keys(meta).length === 0){
throw new Error('No general metadata found in page');
}
// Resolve on meta
return meta;
});
/**
* Scrapes Highwire Press metadata given html object
* @param {Object} chtml html Cheerio object
* @return {Object} promise of highwire press metadata object
*/
exports.parseHighwirePress = BBPromise.method(function(chtml){
return exports.parseBase(
chtml,
['meta'],
'No Highwire Press metadata found in page',
function(element) {
var nameAttr = element.attr('name');
var content = element.attr('content');
// If the element isn't a Highwire Press property, skip it
if (!nameAttr || !content || (nameAttr.substring(0, 9).toLowerCase() !== 'citation_')) {
return;
}
return nameAttr.substring(nameAttr.indexOf('_') + 1).toLowerCase();
},
debug('Server TCP at port %s has stopped', number);
def.resolve();
});
server.listen(number, iface, function(err) {
if (err)
def.reject(err);
def.resolve(server);
});
return def.promise;
});
});
exports.stopTcp = bluebird.method(function(arr) {
return bluebird.resolve([].concat(arr))
.each(function(server) {
var def = bluebird.defer();
server.close(def.callback);
return def.promise;
});
});
exports.autoClose = bluebird.method(function(ports, iface, promise) {
if (!promise || typeof iface !== 'string') {
promise = iface;
iface = null;
}
if (err) return callback(err);
self.bayeuxServer.stop(function(err) {
if (err) return callback(err);
callback();
});
});
},
networkOutage: Promise.method(function(timeout) {
this.proxyServer.disableTraffic(timeout);
}),
stopWebsockets: Promise.method(function(timeout) {
this.bayeuxServer.crush(timeout);
}),
deleteSocket: Promise.method(function(clientId) {
return Promise.fromCallback(this.bayeuxServer.deleteClient.bind(this.bayeuxServer, clientId));
}),
restart: Promise.method(function() {
var proxy = this.proxyServer;
return Promise.fromCallback(proxy.stop.bind(proxy))
.delay(500)
.then(function() {
return Promise.fromCallback(proxy.start.bind(proxy));
});
}),
function mockClient(client) {
client.driverName = 'mocked';
client.acquireConnection = Promise.method(function() {
return connection;
});
client.releaseConnection = Promise.method(_.noop);
client.acquireRawConnection = Promise.method(function() {
return {};
});
client.destroyRawConnection = function destroyRawConnection(connection, cb) {
cb();
};
client.constructor.prototype._query = client._query = function(connection, obj) {
return new Promise(function(resolver, rejecter) {
tracker.queries.track(obj, resolver);
});
};
client.constructor.prototype.processResponse = client.processResponse = function(obj) {
headers: this.headers,
_token: options.token
});
});
/**
* @method revokeTokenSelf
* @desc Revokes the current client token and all child tokens.
*
* @param {string} [options.token] - the authentication token
* @param {string} [mountName=token] - path name the token auth backend is mounted on
* @resolve success
* @reject {Error} An error indicating what went wrong
* @return {Promise}
*/
Vaulted.revokeTokenSelf = Promise.method(function revokeTokenSelf(options, mountName) {
options = options || {};
return this.getTokenRevokeSelfEndpoint(mountName)
.post({
headers: this.headers,
_token: options.token
});
});
return null;
});
/**
* Returns all examples
* @returns {object}
*/
Model.prototype.examples = Promise.method(function examples() {
return _.clone(this._examples);
});
/**
* Returns schema
* @returns {object}
*/
Model.prototype.schema = Promise.method(function schema() {
return _.clone(this._schema);
});
return new Promise(function (resolve, reject) {
return iam.createPolicy({
PolicyDocument: document
, PolicyName: name
, Description: description
}, function (err, data) {
if (err) {
return reject(err);
} else {
return resolve(data);
}
});
});
});
var putUserPolicy = Promise.method(function (iam, user, document, name) {
return new Promise(function (resolve, reject) {
return iam.putUserPolicy({
PolicyDocument: document
, PolicyName: name
, UserName: user
}, function (err, data) {
if (err) {
return reject(err);
} else {
return resolve(data);
}
});
});
});
var putRolePolicy = Promise.method(function (iam, role, document, name) {
register(callback, events = '*') {
const id = _prefix + _lastID;
events = _.isString(events) ? [ events ] : events;
if (! _.size(events)) {
throw new Error('Fluxapp: Dispatcher requires a list of events or "*" to receive all events');
}
this._callbacks[id] = Promise.method(callback);
_.each(events, (event) => {
event = event === '*' ? event : namespaceTransform(event);
this._events[event] = this._events[event] || [];
this._events[event].push(id);
});
_lastID += 1;
return id;
}
const flushNext = (ret) => {
if (!this._queue.length) return Bluebird.resolve(ret);
const { method, args, dfd } = this._queue.shift();
const invocation = Bluebird.method(this.component[method]);
const promise = invocation.apply(this.component, args);
dfd.resolve(promise);
return promise
.then(flushNext);
};