/** Parse params object to search string @param {Object} params @returns {String} search */ function parseParam(data) { var stack = [], query; each(data, function (value, key) { stack.push(key + '=' + value); }); query = stack.join('!!').replace(/\s/g, '+'); return query; }
Model.on('construct', function (model, attrs) { each(Model.attrs, function (key, options) { var value = undefined != options.default ? options.default : defaults[key]; if (value !== undefined) apply(model, key, value); }); });
it('should handle changes in opacity', function() { each([ "0", "0.25", "0.5", "0.75", "1" ], function(opacity) { css(div, 'opacity', opacity); assert(parseFloat(opacity) == css(div, 'opacity'), 'opacity can be a string'); opacity = parseFloat(opacity); css(div, 'opacity', opacity); assert(opacity == css(div, 'opacity'), 'opacity can be a number'); }); });
function make_road_for_every_creep(room){ var creeps = creeps_for_roads(room); each( creeps, function(creep){ if( should_build_roads(creep.room) ){ creep.pos.createConstructionSite(STRUCTURE_ROAD); } } ); }
it('should configure all defaults', function(){ window._gs = sinon.spy(); var assert = test(gosquared).initialize(); each(gosquared.options, function(name, value){ if ('siteToken' == name) return; if (null == value) return; assert.called(window._gs).args('set', name, value); }); })
return req.end(utils.easy(function (err, data) { if (err) return callback(err); each(data.results, function (row) { traverse(row); translate(row, "vertex_types", "vertex_type_id", "type"); translate(row, row.type.toLowerCase() + "_types", "subtype_id"); }); callback(null, data.results); }));
function filter(arr, fn) { var result = []; each(arr, function(el, i) { if (fn(el)) { result.push(el); } }); return result; }
it('Recurly.configured remains false', function () { each(examples, function (opts) { try { recurly.configure(opts); } catch (e) { assert(recurly.configured === false); } }); });
LabelEdgeGroup.prototype.getRenderLength = function(display) { if (!this.renderLength) { this.renderLength = 0; each(this.renderedEdges, function(rEdge) { this.renderLength += rEdge.graphEdge.getRenderLength(display); }, this); } return this.renderLength; };
it('sets Recurly.config to the options given', function () { each(examples, function (opts) { var recurly = new Recurly(); recurly.configure(opts); each(opts, function (opt, val) { assert(recurly.config[opt] === val); }); }); });
exports = module.exports = function(key, val){ switch (arguments.length) { case 2: return set(key, val); case 0: return all(); case 1: return 'object' == type(key) ? each(key, set) : get(key); } };
each(this.config, function(cfg) { each(self.targets, function(target) { var handler = function(e) { self.handle.call(self, handler, cfg, target, cb); }; events.bind(target, cfg.event, handler); }); });
function processPage(body, callback, next) { var rows = [] var body = $.load(body) var body_rows = [] each(body('table[cellpadding=3] tr').toArray()) .on('item', function(next_row, body_row, i) { if (i % 3 == 0) { var row = {} var link = $(body_row).find('td.right a').attr('href').split('=') row.id = link[link.length - 1] + '-0' row.date = moment($(body_row).find('td[width=85]').text().trim(), 'DD.MM.YYYY').format('YYYY-MM-DDTHH:mm:ssZ'); row.type = $(body_row).find('td.teateliik').text().trim(); row.description = $(body_row).next().find('td[colspan=4]').text().trim().replace("'", "''"); row.priority = types.filter(function(item) { return item.name === row.type })[0].priority processRow(row, function(p_row) { if (p_row.childs.length < 2) { p_row.childs.push(p_row) } each(p_row.childs) .on('item', function(next, p_row, i) { p_row.description = encodeURIComponent(p_row.description) p_row.description_short = encodeURIComponent(p_row.description_short) var url = "http://" + CONFIG.cartoUser + ".cartodb.com/api/v2/sql?q=INSERT INTO " + CONFIG.cartoTable + " (id, priority, date, type, description, description_short" + (p_row.the_geom ? ", the_geom" : "") + ") VALUES ('" + p_row.id + "', '" + p_row.priority + "', '" + p_row.date + "', '" + p_row.type + "', '" + p_row.description + "', '" + p_row.description_short + "'" + (p_row.the_geom ? ", " + p_row.the_geom : "") + ")&api_key=" + CONFIG.cartoKey request.post({url: url, json: true}, function (err, res, body) { if (body && body.error) console.log(body) setTimeout(next, 0) }) }) .on('end', function() { setTimeout(next_row, (CONFIG.scrapeDelay || 0)) }) }) } else { setTimeout(next_row, (CONFIG.scrapeDelay || 0)) } }) .on('end', function() { return callback(null) }) }
identify : function (userId, traits, context, callback) { if (!this.initialized) return; // Allow for not passing context, but passing a callback. if (type(context) === 'function') { callback = context; context = null; } // Allow for not passing traits, but passing a callback. if (type(traits) === 'function') { callback = traits; traits = null; } // Allow for identifying traits without setting a `userId`, for // anonymous users whose traits you learn. if (type(userId) === 'object') { if (traits && type(traits) === 'function') callback = traits; traits = userId; userId = null; } // Use the saved userId. if (userId === null) userId = user.id(); // Update the cookie with new userId and traits. var alias = user.update(userId, traits); // Before we manipulate traits, clone it so we don't do anything uncouth. traits = clone(traits); // Test for a `created` that's a valid date string and convert it. if (traits && traits.created && type (traits.created) === 'string' && Date.parse(traits.created)) { traits.created = new Date(traits.created); } // Call `identify` on all of our enabled providers that support it. each(this.providers, function (provider) { if (provider.identify && utils.isEnabled(provider, context)) { var args = [userId, clone(traits), clone(context)]; if (provider.ready) provider.identify.apply(provider, args); else provider.enqueue('identify', args); } }); // TODO: auto-alias once mixpanel API doesn't error // If we should alias, go ahead and do it. // if (alias) this.alias(userId); if (callback && type(callback) === 'function') { setTimeout(callback, this.timeout); } },
function Tween(config) { if(!(this instanceof Tween)) return new Tween(config); this.config = config = extend({}, config); // merge the defaults with self each(defaults, function(val, key) { this[key] = isValue(config[key]) ? config[key] : val; }, this); }
function extend(obj) { each(slice.call(arguments, 1), function(source) { for(var prop in source) { if(has.call(source, prop)) { obj[prop] = source[prop]; } } }); return obj; }
function flatten(input, shallow, output) { each(input, function(value) { if (isArray(value)) { shallow ? [].push.apply(output, value) : flatten(value, shallow, output); } else { output.push(value); } }); return output; }
step: function() { var t = this; var grid = this.grid; var gol = this.gol; if (!this.init) { each(gol.unchanged, function(pos) { t.cubify(pos.x, pos.y); }); this.init = true; } var pool = []; each(gol.removed, function(pos) { var faces = filter(grid.faces, function(f) { return f.getAttribute('x:y:z') === [pos.x, pos.y, 0].join(':') }); pool = pool.concat(faces); }); each(gol.added, function(pos) { if (pool.length > 0) { var faces = grid.closest(pos.x, pos.y, pool); each(['front', 'left', 'top'], function(o, i) { var f = faces[faces.length - 1 - i]; grid.move(f, { x: pos.x, y: pos.y, dir: o }); pool = without(pool, f); }); } else { t.cubify(pos.x, pos.y); } }); this.ephemerize(pool); gol.step(); }
Styler.prototype.compute = function(rules, display, data, index) { var computed, self = this; each(rules, function(rule) { var val = isFunction(rule) ? rule.call(self, display, data, index, styles.utils) : rule; if (val !== undefined && val !== null) computed = val; }); return computed; };
each(this.places, function(placeId) { var place = this.places[placeId]; if (!place.graphVertex) return; each(place.graphVertex.incidentEdges(), function(edge) { var oppVertex = edge.oppositeVertex(place.graphVertex); if (oppVertex.point) { oppVertex.point.adjacentPlace = place; } }); }, this);
var dequeue = function () { each(self.queue, function (call) { var method = call.method , args = call.args; self[method].apply(self, args); }); self.ready = true; self.queue = []; ready(); };
function fValue(form) { if(!(this instanceof fValue)) return new fValue(form); this.form = form; this.fields = {}; // inputs each(query.all('input[name]', form), function(el) { this.fields[el.getAttribute('name')] = el; }.bind(this)); // selects each(query.all('select[name]', form), function(el) { this.fields[el.getAttribute('name')] = el; }.bind(this)); return this; }
window._kmq.push(function(){ var km = window.KM; each(products, function(product, i){ var temp = new Track({ event: event, properties: product }); var item = prefix(event, product); item._t = km.ts() + i; item._d = 1; km.set(item); }); });
return linker.scanDefinitions(baseDir).then(function (packages) { console.info('TSD link packages:', _.map(packages, function (pack) { return pack.name; })); each(packages) .on('item', function (packaged, next) { return manager .addToBundle(bundlePath, packaged.definitions, true) .then(next); }) .on('end', done); });
Styler.prototype.load = function(styles) { var self = this; each(types, function(type) { if (styles[type]) { each(styles[type], function (key, val) { self[type][key] = (self[type][key] || []).concat(val); }); } }); };
module.exports = function(numbers, breakpoint) { var arr = []; each(numbers, function(val) { if (val < breakpoint) val = Number('0' + val); arr.push(val); }); return arr; };
function encode(obj) { if (!obj) return obj; var str = ''; each(obj, function(key, value) { str += (typeof value === 'boolean' ? (value ? '*' : '!') : ('*' + value + '|')) + key; }); return str; }
Indexed.prototype.all = async(function() { var result = []; var values = store.getAll(); var name = this._name(); each(values, function(key, val) { if (key.indexOf(name) === 0) result.push(val); }); return result; });
enqueue(function(){ var data = {}; var ids = window._vwo_exp_ids; if (!ids) return fn(); each(ids, function(id){ var name = variation(id); if (name) data['Experiment: ' + id] = name; }); fn(null, data); });
enqueue(function() { var data = {}; var experimentIds = window._vwo_exp_ids; if (!experimentIds) return fn(); each(experimentIds, function(experimentId) { var variationName = variation(experimentId); if (variationName) data[experimentId] = variationName; }); fn(null, data); });