var unifyType = function (value) { if (_.isArray (value)) { return _.nonempty ([_.reduce (value.slice (1), function (a, b) { return _.undiff (a, b) }, _.first (value) || undefined)]) } else if (_.isStrictlyObject (value)) { var pairs = _.pairs (value) var unite = _.map ( _.reduce (pairs.slice (1), function (a, b) { return _.undiff (a, b) }, _.first (pairs) || [undefined, undefined]), _.nonempty) return (_.isEmpty (unite) || _.isEmpty (unite[1])) ? value : _.fromPairs ([[unite[0] || '*', unite[1]]]) } else { return value } }
var zip = function (type, value, pred) { var required = Meta.unwrapAll (_.filter2 (type, $required.is)) var match = _.nonempty (_.zip2 (Meta.unwrapAll (type), value, pred)) if (_.isEmpty (required)) { return match } else { var requiredMatch = _.nonempty (_.zip2 (required, value, pred)) var allSatisfied = _.values2 (required).length === _.values2 (requiredMatch).length return allSatisfied ? match : _.coerceToEmpty (value) } }
//Gets a property from the config object getProp(propName){ if(_.isUndefined(propName)) throw new Error('invalid-prop', 'Property name cannot be undefined'); if(!_.isString(propName)) throw new Error('invalid-prop', 'Property name must be a string'); if(_.isEmpty(propName)) throw new Error('invalid-prop', 'Property name cannot be empty'); return this.config[propName]; }
function uncheckedReadJSON(bytebuf) { var str = uncheckedReadString(bytebuf)(); logger.tracef("Read object as string: '%s'", str); var obj = _.isEmpty(str) ? {} : JSON.parse(str); logger.tracef('Returning JSON object: %s', JSON.stringify(obj)); return obj; }
Backbone.Collection.extend({ url: function() { return app.serverConfigs.getActive().getServerBaseUrl() + '/get_ratings'; }, model: RatingMd, parse: function(response) { if (!response || __.isEmpty(response)) { return []; } return response.reverse(); } })
// Return the user from the ID. async function getUserById(id) { let user = await $r.hgetall(`user:${id}`); return _.isEmpty(user) ? null : user; }
function decodePrev(header, bytebuf, decoder) { var decodeActions = decodeSingle(decoder); var prev = decodeActions(bytebuf); if (f.existy(prev)) return {result: _.isEmpty(prev) ? undefined : prev, continue: true}; else return {continue: false}; }
/** * Creates new logger with configuration from given configuration file (or files). Changes in * configuration file(s) are applied immediately on the run. * * @param {String|String[]} path Path (or paths) to logger configuration file(s). * @param {String} [category='Default'] Logger category. * @returns {Logger} Logger instance. */ static fromConfigurationFile(path = [], category = 'Default') { let configuration; if (!_.isEmpty(path)) { configuration = LoggerConfiguration.fromFiles(_.isArray(path) ? path : [path], new Logger()); } return new Logger(undefined, category, configuration); }
/* Abstract _.values ======================================================================== */ _.withTest (['stdlib', 'values2'], function () { $assert (_.values2 (undefined), []) $assert (_.values2 (_.identity), [_.identity]) $assert (_.values2 ('foo'), ['foo']) $assert (_.values2 (['foo', 'bar']), ['foo', 'bar']) $assert (_.values2 ({ f: 'foo', b: 'bar' }), ['foo', 'bar']) }, function () { _.mixin ({ values2: function (x) { if (_.isArrayLike (x)) { return x } else if (_.isStrictlyObject (x)) { return _.values (x) } else if (_.isEmpty (x)) { return [] } else { return [x] } } }) })
reload(propName){ if(_.isUndefined(propName)) for (let key in this.propsCache) { if (this.propsCache.hasOwnProperty(key)) { this.setProp(key, this.propsCache[key]); } } if(_.isArray(propName)) for (let item of propName) { if(this.propsCache[item]) this.setProp(item, this.propsCache[item]); } if(_.isString(propName) && !_.isEmpty(propName)) this.setProp(propName, this.propsCache[propName]); return this; }
function Model(data) { var nonNullDefaults = _.omit(this.defaults, _.isEmpty); _.extend(this, nonNullDefaults, data); this.initialize(data); }
var getBTCPrices = function(){ $.ajax({ url: app.serverConfigs.getActive().getServerBaseUrl() + '/btc_price', dataType: 'json', cache: false //just in case }) .done(function(data){ if (!__.isEmpty(data.currencyCodes)){ btPrices.push(data.currencyCodes); } }) .fail(function (jqXHR, textStatus, errorThrown) { logAPIErrorInfo("Call to btc_price", jqXHR, textStatus, errorThrown); }) .always(function () { makeAveragePrice(); }); }
objectFromData(hbaseRowData) { if (_.isEmpty(this.columnTypes)) { return hbaseRowData; } const obj = {}; obj.rowkey = hbaseRowData.row ? hbaseRowData.row.toString() : null; _.each(hbaseRowData.columnValues, colVal => { const family = colVal.family.toString(); const qualName = colVal.qualifier.toString(); const columnFullName = family + qualName; const columnType = this.columnTypes[columnFullName]; obj[family] = obj[family] || {}; obj[family][qualName] = serde.deserialize(colVal.value, columnType); }); return obj; }
test("isEmpty", function() { ok(!_([1]).isEmpty(), '[1] is not empty'); ok(_.isEmpty([]), '[] is empty'); ok(!_.isEmpty({one : 1}), '{one : 1} is not empty'); ok(_.isEmpty({}), '{} is empty'); ok(_.isEmpty(new RegExp('')), 'objects with prototype properties are empty'); ok(_.isEmpty(null), 'null is empty'); ok(_.isEmpty(), 'undefined is empty'); ok(_.isEmpty(''), 'the empty string is empty'); ok(!_.isEmpty('moe'), 'but other strings are not'); var obj = {one : 1}; delete obj.one; ok(_.isEmpty(obj), 'deleting all the keys from an object empties it'); });
function trySwitchCluster(noClustersF, clusterFailF, transport) { var failedClusterName = router.getClusterName(); logger.debugf('Try to failover away from cluster=%s', failedClusterName); if (_.isEmpty(clientOpts.clusters)) { logger.tracef('No alternative clusters configured'); return new Promise(function() { noClustersF(); }); } else { return aroundClusterSwitch(function() { var clusters = getCandidateClusters(failedClusterName); var allLazyConns = _.flatten(f.cat(_.map(clusters, function(cluster) { return toLazyAltConnections(cluster, transport); }))); return findFirstConnection(allLazyConns, getFailoverMainRouter(failedClusterName)) }, clusterFailF); } }