code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function domain(url){
var host = parse(url).hostname;
var match = host.match(regexp);
return match ? match[0] : '';
} | Get the top domain.
Official Grammar: http://tools.ietf.org/html/rfc883#page-56
Look for tlds with up to 2-6 characters.
Example:
domain('http://localhost:3000/baz');
// => ''
domain('http://dev:3000/baz');
// => ''
domain('http://127.0.0.1:3000/baz');
// => ''
domain('http://segme... | domain | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function removeBlankAttributes(obj) {
return foldl(function(results, val, key) {
if (val !== null && val !== undefined) results[key] = val;
return results;
}, {}, obj);
} | Filters null/undefined values from an object, returning a new object.
@api private
@param {Object} obj
@return {Object} | removeBlankAttributes | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function pad (number) {
var n = number.toString();
return n.length === 1 ? '0' + n : n;
} | Pad a `number` with a ten's place zero.
@param {Number} number
@return {String} | pad | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function generate (name, options) {
options = options || {};
return function (args) {
args = [].slice.call(arguments);
window[name] || (window[name] = []);
options.wrap === false
? window[name].push.apply(window[name], args)
: window[name].push(args);
};
} | Generate a global queue pushing method with `name`.
@param {String} name
@param {Object} options
@property {Boolean} wrap
@return {Function} | generate | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function throttle (func, wait) {
var rtn; // return value
var last = 0; // last invokation timestamp
return function throttled () {
var now = new Date().getTime();
var delta = now - last;
if (delta >= wait) {
rtn = func.apply(this, arguments);
last = now;
}
return rtn;
};
} | Returns a new function that, when invoked, invokes `func` at most one time per
`wait` milliseconds.
@param {Function} func The `Function` instance to wrap.
@param {Number} wait The minimum number of milliseconds that must elapse in between `func` invokations.
@return {Function} A new function that wraps the `func` fun... | throttle | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function when (condition, fn, interval) {
if (condition()) return callback.async(fn);
var ref = setInterval(function () {
if (!condition()) return;
callback(fn);
clearInterval(ref);
}, interval || 10);
} | Loop on a short interval until `condition()` is true, then call `fn`.
@param {Function} condition
@param {Function} fn
@param {Number} interval (optional) | when | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convertDate(date) {
return Math.floor(date.getTime() / 1000);
} | Convert a date to the format Customer.io supports.
@api private
@param {Date} date
@return {number} | convertDate | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function alias (obj, method) {
switch (type(method)) {
case 'object': return aliasByDictionary(clone(obj), method);
case 'function': return aliasByFunction(clone(obj), method);
}
} | Alias an `object`.
@param {Object} obj
@param {Mixed} method | alias | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function aliasByDictionary (obj, aliases) {
for (var key in aliases) {
if (undefined === obj[key]) continue;
obj[aliases[key]] = obj[key];
delete obj[key];
}
return obj;
} | Convert the keys in an `obj` using a dictionary of `aliases`.
@param {Object} obj
@param {Object} aliases | aliasByDictionary | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function aliasByFunction (obj, convert) {
// have to create another object so that ie8 won't infinite loop on keys
var output = {};
for (var key in obj) output[convert(key)] = obj[key];
return output;
} | Convert the keys in an `obj` using a `convert` function.
@param {Object} obj
@param {Function} convert | aliasByFunction | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convertDates (obj, convert) {
obj = clone(obj);
for (var key in obj) {
var val = obj[key];
if (is.date(val)) obj[key] = convert(val);
if (is.object(val)) obj[key] = convertDates(val, convert);
}
return obj;
} | Recursively convert an `obj`'s dates to new values.
@param {Object} obj
@param {Function} convert
@return {Object} | convertDates | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function onError (fn) {
callbacks.push(fn);
if (window.onerror != handler) {
callbacks.push(window.onerror);
window.onerror = handler;
}
} | Call a `fn` on `window.onerror`.
@param {Function} fn | onError | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function ecommerce(event, track, arr) {
push.apply(null, [
'_fxm.ecommerce.' + event,
track.id() || track.sku(),
track.name(),
track.category()
].concat(arr || []));
} | Track ecommerce `event` with `track`
with optional `arr` to append.
@api private
@param {string} event
@param {Track} track
@param {Array} arr | ecommerce | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function clean(obj) {
var ret = {};
// Remove traits/properties that are already represented
// outside of the data container
// TODO: Refactor into `omit` call
var excludeKeys = ['id', 'name', 'firstName', 'lastName'];
each(excludeKeys, function(omitKey) {
clear(obj, omitKey);
});
// Flatten nest... | Clean all nested objects and arrays.
@api private
@param {Object} obj
@return {Object} | clean | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function clear(obj, key) {
if (obj.hasOwnProperty(key)) {
delete obj[key];
}
} | Remove a property from an object if set.
@api private
@param {Object} obj
@param {String} key | clear | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convert(key, value) {
key = camel(key);
if (is.string(value)) return key + '_str';
if (isInt(value)) return key + '_int';
if (isFloat(value)) return key + '_real';
if (is.date(value)) return key + '_date';
if (is.boolean(value)) return key + '_bool';
} | Convert to FullStory format.
@param {string} trait
@param {*} value | convert | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function toCamelCase (string) {
return toSpace(string).replace(/\s(\w)/g, function (matches, letter) {
return letter.toUpperCase();
});
} | Convert a `string` to camel case.
@param {String} string
@return {String} | toCamelCase | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function path(properties, options) {
if (!properties) return;
var str = properties.path;
if (options.includeSearch && properties.search) str += properties.search;
return str;
} | Return the path based on `properties` and `options`.
@param {Object} properties
@param {Object} options
@return {string|undefined} | path | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function formatValue(value) {
if (!value || value < 0) return 0;
return Math.round(value);
} | Format the value property to Google's liking.
@param {Number} value
@return {Number} | formatValue | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function metrics(obj, data) {
var dimensions = data.dimensions;
var metrics = data.metrics;
var names = keys(metrics).concat(keys(dimensions));
var ret = {};
for (var i = 0; i < names.length; ++i) {
var name = names[i];
var key = metrics[name] || dimensions[name];
var value = dot(obj, name) || ob... | Map google's custom dimensions & metrics with `obj`.
Example:
metrics({ revenue: 1.9 }, { { metrics : { revenue: 'metric8' } });
// => { metric8: 1.9 }
metrics({ revenue: 1.9 }, {});
// => {}
@param {Object} obj
@param {Object} data
@return {Object|null}
@api private | metrics | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function enhancedEcommerceTrackProduct(track) {
var props = track.properties();
window.ga('ec:addProduct', {
id: track.id() || track.sku(),
name: track.name(),
category: track.category(),
quantity: track.quantity(),
price: track.price(),
brand: props.brand,
variant: props.variant,
c... | Enhanced ecommerce track product.
Simple helper so that we don't repeat `ec:addProduct` everywhere.
@api private
@param {Track} track | enhancedEcommerceTrackProduct | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function enhancedEcommerceProductAction(track, action, data) {
enhancedEcommerceTrackProduct(track);
window.ga('ec:setAction', action, data || {});
} | Set `action` on `track` with `data`.
@api private
@param {Track} track
@param {String} action
@param {Object} data | enhancedEcommerceProductAction | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function extractCheckoutOptions(props) {
var options = [
props.paymentMethod,
props.shippingMethod
];
// Remove all nulls, empty strings, zeroes, and join with commas.
var valid = select(options, function(e) {return e; });
return valid.length > 0 ? valid.join(', ') : null;
} | Extracts checkout options.
@api private
@param {Object} props
@return {string|null} | extractCheckoutOptions | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function createProductTrack(track, properties) {
properties.currency = properties.currency || track.currency();
return new Track({ properties: properties });
} | Creates a track out of product properties.
@api private
@param {Track} track
@param {Object} properties
@return {Track} | createProductTrack | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function push() {
window._gs = window._gs || function() {
window._gs.q.push(arguments);
};
window._gs.q = window._gs.q || [];
window._gs.apply(null, arguments);
} | Push to `_gs.q`.
@api private
@param {...*} args | push | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function omit(keys, object){
var ret = {};
for (var item in object) {
ret[item] = object[item];
}
for (var i = 0; i < keys.length; i++) {
delete ret[keys[i]];
}
return ret;
} | Return a copy of the object without the specified keys.
@param {Array} keys
@param {Object} object
@return {Object} | omit | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function pick(obj){
var keys = [].slice.call(arguments, 1);
var ret = {};
for (var i = 0, key; key = keys[i]; i++) {
if (key in obj) ret[key] = obj[key];
}
return ret;
} | Pick keys from an `obj`.
@param {Object} obj
@param {Strings} keys...
@return {Object} | pick | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
methodFactory = function(type) {
return function() {
window.heap.push([type].concat(Array.prototype.slice.call(arguments, 0)));
};
} | Initialize.
https://heapanalytics.com/docs/installation#web
@api public | methodFactory | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convertDates(properties) {
return convert(properties, function(date) { return date.getTime(); });
} | Convert all the dates in the HubSpot properties to millisecond times
@api private
@param {Object} properties | convertDates | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function formatDate(date) {
return Math.floor(date / 1000);
} | Format a date to Intercom's liking.
@api private
@param {Date} date
@return {number} | formatDate | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function api() {
window.Intercom.apply(window.Intercom, arguments);
} | Push a call onto the Intercom queue.
@api private | api | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function prefix(event, properties) {
var prefixed = {};
each(properties, function(key, val) {
if (key === 'Billing Amount') {
prefixed[key] = val;
} else {
prefixed[event + ' - ' + key] = val;
}
});
return prefixed;
} | Prefix properties with the event name.
@param {String} event
@param {Object} properties
@return {Object} prefixed
@api private | prefix | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convert(traits) {
var arr = [];
each(traits, function(key, value) {
arr.push({ name: key, value: value });
});
return arr;
} | Convert a traits object into the format LiveChat requires.
@param {Object} traits
@return {Array} | convert | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function lowercase(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < arr.length; ++i) {
ret[i] = String(arr[i]).toLowerCase();
}
return ret;
} | Lowercase the given `arr`.
@api private
@param {Array} arr
@return {Array} | lowercase | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function set(obj) {
each(obj, function(key, value) {
push('setVariable', key, value);
});
} | Push each key and value in the given `obj` onto the queue.
@api private
@param {Object} obj | set | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function api(action, value) {
window.olark('api.' + action, value);
} | Helper for Olark API calls.
@api private
@param {string} action
@param {Object} value | api | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function getExperiments(options) {
return foldl(function(results, experimentId) {
var experiment = options.allExperiments[experimentId];
if (experiment) {
results.push({
variationName: options.variationNamesMap[experimentId],
variationId: options.variationIdsMap[experimentId][0],
... | Retrieves active experiments.
@api private
@param {Object} options | getExperiments | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function convertDate(date) {
return Math.floor(date / 1000);
} | Convert a `date` to a format Preact supports.
@param {Date} date
@return {number} | convertDate | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function scheme() {
return protocol() === 'http:' ? 'http:' : 'https:';
} | Get the scheme.
The function returns `http:`
if the protocol is `http:` and
`https:` for other protocols.
@api private
@return {string} | scheme | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function ads(query){
var params = parse(query);
for (var key in params) {
for (var id in QUERYIDS) {
if (key === id) {
return {
id : params[key],
type : QUERYIDS[id]
};
}
}
}
} | Get all ads info from the given `querystring`
@param {String} query
@return {Object}
@api private | ads | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function store(key, value){
var length = arguments.length;
if (0 == length) return all();
if (2 <= length) return set(key, value);
if (1 != length) return;
if (null == key) return storage.clear();
if ('string' == typeof key) return get(key);
if ('object' == typeof key) return each(key, set);
} | Store the given `key`, `val`.
@param {String|Object} key
@param {Mixed} value
@return {Mixed}
@api public | store | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function set(key, val){
return null == val
? storage.removeItem(key)
: storage.setItem(key, JSON.stringify(val));
} | Set `key` to `val`.
@param {String} key
@param {Mixed} val | set | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function get(key){
return unserialize(storage.getItem(key));
} | Get `key`.
@param {String} key
@return {Mixed} | get | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function get () {
return mockedProtocol || window.location.protocol;
} | Gets the current protocol, using the fallback and then the native protocol.
@return {String} protocol | get | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function set (protocol) {
try {
define(window.location, 'protocol', {
get: function () { return protocol; }
});
} catch (err) {
mockedProtocol = protocol;
}
} | Sets the protocol
@param {String} protocol | set | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function json(url, obj, headers, fn){
if (3 == arguments.length) fn = headers, headers = {};
var req = new XMLHttpRequest;
req.onerror = fn;
req.onreadystatechange = done;
req.open('POST', url, true);
for (var k in headers) req.setRequestHeader(k, headers[k]);
req.send(JSON.stringify(obj));
function d... | Send the given `obj` to `url` with `fn(err, req)`.
@param {String} url
@param {Object} obj
@param {Object} headers
@param {Function} fn
@api private | json | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function done(){
if (4 == req.readyState) return fn(null, req);
} | Send the given `obj` to `url` with `fn(err, req)`.
@param {String} url
@param {Object} obj
@param {Object} headers
@param {Function} fn
@api private | done | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function base64(url, obj, _, fn){
if (3 == arguments.length) fn = _;
var prefix = exports.prefix;
obj = encode(JSON.stringify(obj));
obj = encodeURIComponent(obj);
url += '?' + prefix + '=' + obj;
jsonp(url, { param: exports.callback }, function(err, obj){
if (err) return fn(err);
fn(null, {
u... | Send the given `obj` to `url` with `fn(err, req)`.
@param {String} url
@param {Object} obj
@param {Function} fn
@api private | base64 | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function encode(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = utf8Encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
... | Send the given `obj` to `url` with `fn(err, req)`.
@param {String} url
@param {Object} obj
@param {Function} fn
@api private | encode | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utfte... | Send the given `obj` to `url` with `fn(err, req)`.
@param {String} url
@param {Object} obj
@param {Function} fn
@api private | encode | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function utm(query){
if ('?' == query.charAt(0)) query = query.substring(1);
var query = query.replace(/\?/g, '&');
var params = parse(query);
var param;
var ret = {};
for (var key in params) {
if (~key.indexOf('utm_')) {
param = key.substr(4);
if ('campaign' == param) param = 'name';
... | Get all utm params from the given `querystring`
@param {String} query
@return {Object}
@api private | utm | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function formatOptions(options) {
return alias(options, {
forumId: 'forum_id',
accentColor: 'accent_color',
smartvote: 'smartvote_enabled',
triggerColor: 'trigger_color',
triggerBackgroundColor: 'trigger_background_color',
triggerPosition: 'trigger_position',
screenshotEnabled: 'screenshot... | Format the options for UserVoice.
@api private
@param {Object} options
@return {Object} | formatOptions | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function formatClassicOptions(options) {
return alias(options, {
forumId: 'forum_id',
classicMode: 'mode',
primaryColor: 'primary_color',
tabPosition: 'tab_position',
tabColor: 'tab_color',
linkColor: 'link_color',
defaultMode: 'default_mode',
tabLabel: 'tab_label',
tabInverted: 't... | Format the classic options for UserVoice.
@api private
@param {Object} options
@return {Object} | formatClassicOptions | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function showClassicWidget(type, options) {
type = type || 'showLightbox';
push(type, 'classic_widget', options);
} | Show the classic version of the UserVoice widget. This method is usually part
of UserVoice classic's public API.
@api private
@param {String} type ('showTab' or 'showLightbox')
@param {Object} options (optional) | showClassicWidget | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function toUnixTimestamp (date) {
return Math.floor(date.getTime() / 1000);
} | Convert a `date` into a Unix timestamp.
@param {Date}
@return {Number} | toUnixTimestamp | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function rootExperiments(fn) {
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;
... | Get dictionary of experiment keys and variations.
http://visualwebsiteoptimizer.com/knowledge/integration-of-vwo-with-kissmetrics/
@param {Function} fn
@return {Object} | rootExperiments | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function experiments(fn) {
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);
});
} | Get dictionary of experiment keys and variations.
http://visualwebsiteoptimizer.com/knowledge/integration-of-vwo-with-kissmetrics/
@param {Function} fn
@return {Object} | experiments | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function enqueue(fn) {
window._vis_opt_queue = window._vis_opt_queue || [];
window._vis_opt_queue.push(fn);
} | Add a `fn` to the VWO queue, creating one if it doesn't exist.
@param {Function} fn | enqueue | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function variation(id) {
var experiments = window._vwo_exp;
if (!experiments) return null;
var experiment = experiments[id];
var variationId = experiment.combination_chosen;
return variationId ? experiment.comb_n[variationId] : null;
} | Get the chosen variation's name from an experiment `id`.
http://visualwebsiteoptimizer.com/knowledge/integration-of-vwo-with-kissmetrics/
@param {String} id
@return {String} | variation | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function push(callback) {
window.yandex_metrika_callbacks = window.yandex_metrika_callbacks || [];
window.yandex_metrika_callbacks.push(callback);
} | Push a new callback on the global Yandex queue.
@api private
@param {Function} callback | push | javascript | segmentio/analytics.js | analytics.js | https://github.com/segmentio/analytics.js/blob/master/analytics.js | MIT |
function parseArgs() {
var args = {};
if (arguments.length === 1) {
if (typeof arguments[0] === 'function') {
args.fn = arguments[0];
} else {
args.options = arguments[0];
}
} else if (arguments.length === 2) {
if (typeof arguments[0] === 'function') {
args.fn... | Parse the arguments of traversal functions. These functions can take one optional
first argument which is an options object. If present, this object will be stored
in args.options. The only mandatory argument is the callback function which can
appear in the first or second position (if an options object is given). This... | parseArgs | javascript | joaonuno/tree-model-js | index.js | https://github.com/joaonuno/tree-model-js/blob/master/index.js | MIT |
function parseArgs() {
var args = {};
if (arguments.length === 1) {
if (typeof arguments[0] === 'function') {
args.fn = arguments[0];
} else {
args.options = arguments[0];
}
} else if (arguments.length === 2) {
if (typeof arguments[0] === 'function') {
args.fn... | Parse the arguments of traversal functions. These functions can take one optional
first argument which is an options object. If present, this object will be stored
in args.options. The only mandatory argument is the callback function which can
appear in the first or second position (if an options object is given). This... | parseArgs | javascript | joaonuno/tree-model-js | dist/TreeModel.js | https://github.com/joaonuno/tree-model-js/blob/master/dist/TreeModel.js | MIT |
function findInsertIndex(comparatorFn, arr, el) {
var i, len;
for (i = 0, len = arr.length; i < len; i++) {
if (comparatorFn(arr[i], el) > 0) {
break;
}
}
return i;
} | Find the index to insert an element in array keeping the sort order.
@param {function} comparatorFn The comparator function which sorted the array.
@param {array} arr The sorted array.
@param {object} el The element to insert. | findInsertIndex | javascript | joaonuno/tree-model-js | dist/TreeModel.js | https://github.com/joaonuno/tree-model-js/blob/master/dist/TreeModel.js | MIT |
function mergeSort(comparatorFn, arr) {
var len = arr.length, firstHalf, secondHalf;
if (len >= 2) {
firstHalf = arr.slice(0, len / 2);
secondHalf = arr.slice(len / 2, len);
return merge(comparatorFn, mergeSort(comparatorFn, firstHalf), mergeSort(comparatorFn, secondHalf));
} else {
... | Sort an array using the merge sort algorithm.
@param {function} comparatorFn The comparator function.
@param {array} arr The array to sort.
@returns {array} The sorted array. | mergeSort | javascript | joaonuno/tree-model-js | dist/TreeModel.js | https://github.com/joaonuno/tree-model-js/blob/master/dist/TreeModel.js | MIT |
function merge(comparatorFn, arr1, arr2) {
var result = [], left1 = arr1.length, left2 = arr2.length;
while (left1 > 0 && left2 > 0) {
if (comparatorFn(arr1[0], arr2[0]) <= 0) {
result.push(arr1.shift());
left1--;
} else {
result.push(arr2.shift());
left2--;
}
... | The merge part of the merge sort algorithm.
@param {function} comparatorFn The comparator function.
@param {array} arr1 The first sorted array.
@param {array} arr2 The second sorted array.
@returns {array} The merged and sorted array. | merge | javascript | joaonuno/tree-model-js | dist/TreeModel.js | https://github.com/joaonuno/tree-model-js/blob/master/dist/TreeModel.js | MIT |
errorString = function( error ) {
var name, message,
errorString = error.toString();
if ( errorString.substring( 0, 7 ) === "[object" ) {
name = error.name ? error.name.toString() : "Error";
message = error.message ? error.message.toString() : "";
if ( name && message ) {
return name + ": " + messag... | Provides a normalized error string, correcting an issue
with IE 7 (and prior) where Error.prototype.toString is
not properly implemented
Based on http://es5.github.com/#x15.11.4.4
@param {String|Error} error
@return {String} error message | errorString | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
objectValues = function( obj ) {
// Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392.
/*jshint newcap: false */
var key, val,
vals = QUnit.is( "array", obj ) ? [] : {};
for ( key in obj ) {
if ( hasOwn.call( obj, key ) ) {
val = obj[key];
vals[key] = val === Object(val)... | Makes a clone of an object using only Array or Object as base,
and copies over the own enumerable properties.
@param {Object} obj
@return {Object} New object with only the own properties (recursively). | objectValues | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function Test( settings ) {
extend( this, settings );
this.assertions = [];
this.testNumber = ++Test.count;
} | Makes a clone of an object using only Array or Object as base,
and copies over the own enumerable properties.
@param {Object} obj
@return {Object} New object with only the own properties (recursively). | Test | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function run() {
// each of these can by async
synchronize(function() {
test.setup();
});
synchronize(function() {
test.run();
});
synchronize(function() {
test.teardown();
});
synchronize(function() {
test.finish();
});
} | Expose the current test environment.
@deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead. | run | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function validTest( test ) {
var include,
filter = config.filter && config.filter.toLowerCase(),
module = config.module && config.module.toLowerCase(),
fullName = (test.module + ": " + test.testName).toLowerCase();
// Internally-generated tests are always valid
if ( test.callback && test.callback.validTest ==... | @return Boolean: true if this test should be ran | validTest | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function extractStacktrace( e, offset ) {
offset = offset === undefined ? 3 : offset;
var stack, include, i;
if ( e.stacktrace ) {
// Opera
return e.stacktrace.split( "\n" )[ offset + 3 ];
} else if ( e.stack ) {
// Firefox, Chrome
stack = e.stack.split( "\n" );
if (/^error$/i.test( stack[0] ) ) {
st... | @return Boolean: true if this test should be ran | extractStacktrace | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function sourceFromStacktrace( offset ) {
try {
throw new Error();
} catch ( e ) {
return extractStacktrace( e, offset );
}
} | @return Boolean: true if this test should be ran | sourceFromStacktrace | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function escapeText( s ) {
if ( !s ) {
return "";
}
s = s + "";
// Both single quotes and double quotes (for attributes)
return s.replace( /['"<>&]/g, function( s ) {
switch( s ) {
case "'":
return "'";
case "\"":
return """;
case "<":
return "<";
case ">":
return ">... | Escape text for attribute or text content. | escapeText | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function synchronize( callback, last ) {
config.queue.push( callback );
if ( config.autorun && !config.blocking ) {
process( last );
}
} | Escape text for attribute or text content. | synchronize | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function process( last ) {
function next() {
process( last );
}
var start = new Date().getTime();
config.depth = config.depth ? config.depth + 1 : 1;
while ( config.queue.length && !config.blocking ) {
if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate... | Escape text for attribute or text content. | process | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function next() {
process( last );
} | Escape text for attribute or text content. | next | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function saveGlobal() {
config.pollution = [];
if ( config.noglobals ) {
for ( var key in window ) {
if ( hasOwn.call( window, key ) ) {
// in Opera sometimes DOM element ids show up here, ignore them
if ( /^qunit-test-output/.test( key ) ) {
continue;
}
config.pollution.push( key );
}
... | Escape text for attribute or text content. | saveGlobal | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function checkPollution() {
var newGlobals,
deletedGlobals,
old = config.pollution;
saveGlobal();
newGlobals = diff( config.pollution, old );
if ( newGlobals.length > 0 ) {
QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
}
deletedGlobals = diff( old, config.pollution );
i... | Escape text for attribute or text content. | checkPollution | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function diff( a, b ) {
var i, j,
result = a.slice();
for ( i = 0; i < result.length; i++ ) {
for ( j = 0; j < b.length; j++ ) {
if ( result[i] === b[j] ) {
result.splice( i, 1 );
i--;
break;
}
}
}
return result;
} | Escape text for attribute or text content. | diff | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function extend( a, b ) {
for ( var prop in b ) {
if ( hasOwn.call( b, prop ) ) {
// Avoid "Member not found" error in IE8 caused by messing with window.constructor
if ( !( prop === "constructor" && a === window ) ) {
if ( b[ prop ] === undefined ) {
delete a[ prop ];
} else {
a[ prop ] = b[ ... | Escape text for attribute or text content. | extend | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function addEvent( elem, type, fn ) {
// Standards-based browsers
if ( elem.addEventListener ) {
elem.addEventListener( type, fn, false );
// IE
} else {
elem.attachEvent( "on" + type, fn );
}
} | @param {HTMLElement} elem
@param {string} type
@param {Function} fn | addEvent | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function addEvents( elems, type, fn ) {
var i = elems.length;
while ( i-- ) {
addEvent( elems[i], type, fn );
}
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | addEvents | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function hasClass( elem, name ) {
return (" " + elem.className + " ").indexOf(" " + name + " ") > -1;
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | hasClass | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function addClass( elem, name ) {
if ( !hasClass( elem, name ) ) {
elem.className += (elem.className ? " " : "") + name;
}
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | addClass | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function removeClass( elem, name ) {
var set = " " + elem.className + " ";
// Class name may appear multiple times
while ( set.indexOf(" " + name + " ") > -1 ) {
set = set.replace(" " + name + " " , " ");
}
// If possible, trim it for prettiness, but not necessarily
elem.className = typeof set.trim === "functio... | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | removeClass | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function id( name ) {
return !!( typeof document !== "undefined" && document && document.getElementById ) &&
document.getElementById( name );
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | id | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function registerLoggingCallback( key ) {
return function( callback ) {
config[key].push( callback );
};
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | registerLoggingCallback | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function runLoggingCallbacks( key, scope, args ) {
var i, callbacks;
if ( QUnit.hasOwnProperty( key ) ) {
QUnit[ key ].call(scope, args );
} else {
callbacks = config[ key ];
for ( i = 0; i < callbacks.length; i++ ) {
callbacks[ i ].call( scope, args );
}
}
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | runLoggingCallbacks | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function bindCallbacks( o, callbacks, args ) {
var prop = QUnit.objectType( o );
if ( prop ) {
if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
return callbacks[ prop ].apply( callbacks, args );
} else {
return callbacks[ prop ]; // or undefined
}
}
} | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | bindCallbacks | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function useStrictEquality( b, a ) {
/*jshint eqeqeq:false */
if ( b instanceof a.constructor || a instanceof b.constructor ) {
// to catch short annotation VS 'new' annotation of a
// declaration
// e.g. var i = 1;
// var j = new Number(1);
return a == b;
} else {
return a ===... | @param {Array|NodeList} elems
@param {string} type
@param {Function} fn | useStrictEquality | javascript | brandonaaron/livequery | test/unit/qunit.js | https://github.com/brandonaaron/livequery/blob/master/test/unit/qunit.js | MIT |
function rebundle() {
return bundler.bundle()
// log errors if they happen
.on('error', function (e) {
gutil.log('Browserify Error', e);
})
.pipe(source('bundle.js'))
.pipe(gulp.de... | ')
.pipe(changed('dist/app/fonts'))
.pipe(gulp.dest('dist/app/fonts'));
});
}());
(function javaScript() {
gulp.task('jshint', function () {
gulp.src('app/scripts/* | rebundle | javascript | furier/websync | gulpfile.js | https://github.com/furier/websync/blob/master/gulpfile.js | MIT |
check = function () {
if ((elLog && elLog.scrollTop !== null) && (elCover && elCover.scrollTop !== null)) return;
else check();
} | Create a dialog box
@param {String} message The message passed from the callee
@param {String} type Type of dialog to create
@param {Function} fn [Optional] Callback function
@param {String} placeholder [Optional] Default value for prompt input field
@param {String} cssClas... | check | javascript | furier/websync | app/scripts/ngAlertify.js | https://github.com/furier/websync/blob/master/app/scripts/ngAlertify.js | MIT |
check = function () {
if (elLog && elLog.scrollTop !== null) return;
else check();
} | Show a new log message box
@param {String} message The message passed from the callee
@param {String} type [Optional] Optional type of log message
@param {Number} wait [Optional] Time (in ms) to wait before auto-hiding the log
@return {Object} | check | javascript | furier/websync | app/scripts/ngAlertify.js | https://github.com/furier/websync/blob/master/app/scripts/ngAlertify.js | MIT |
alignPlatformPath = (p = '') =>
p
.replace(/^(\.?\/)/, '')
.replace(/\/$/, '')
.replace(/\//g, path.sep) | source server instance (one per source code project) | alignPlatformPath | javascript | Bogdan-Lyashenko/codecrumbs | src/server/index.js | https://github.com/Bogdan-Lyashenko/codecrumbs/blob/master/src/server/index.js | BSD-3-Clause |
alignPlatformPath = (p = '') =>
p
.replace(/^(\.?\/)/, '')
.replace(/\/$/, '')
.replace(/\//g, path.sep) | source server instance (one per source code project) | alignPlatformPath | javascript | Bogdan-Lyashenko/codecrumbs | src/server/index.js | https://github.com/Bogdan-Lyashenko/codecrumbs/blob/master/src/server/index.js | BSD-3-Clause |
validateProjectPath = (pDir, ePoint) => {
const paths = [];
if (!checkIfPathExists(pDir)) {
paths.push(pDir);
}
if (!checkIfPathExists(ePoint)) {
paths.push(ePoint);
}
if (paths.length) {
logger.error(
`Not valid paths. Please enter valid path, next path does not exist: ${paths.join(', '... | source server instance (one per source code project) | validateProjectPath | javascript | Bogdan-Lyashenko/codecrumbs | src/server/index.js | https://github.com/Bogdan-Lyashenko/codecrumbs/blob/master/src/server/index.js | BSD-3-Clause |
validateProjectPath = (pDir, ePoint) => {
const paths = [];
if (!checkIfPathExists(pDir)) {
paths.push(pDir);
}
if (!checkIfPathExists(ePoint)) {
paths.push(ePoint);
}
if (paths.length) {
logger.error(
`Not valid paths. Please enter valid path, next path does not exist: ${paths.join(', '... | source server instance (one per source code project) | validateProjectPath | javascript | Bogdan-Lyashenko/codecrumbs | src/server/index.js | https://github.com/Bogdan-Lyashenko/codecrumbs/blob/master/src/server/index.js | BSD-3-Clause |
async function addExportsToPackageJson() {
const packageJsonPath = path.join(root, 'package.json')
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
for (const destination of EXPORTS) {
packageJson.exports ??= {}
packageJson.exports[`./${destination}`] = {
import: {
ty... | addExportsToPackageJson adds all entries from EXPORTS to the exports field of package.json,
so loaders and bundlers supporting the exports field can resolve them properly to either ESM or CommonJS. | addExportsToPackageJson | javascript | tus/tus-js-client | scripts/setup-exports.js | https://github.com/tus/tus-js-client/blob/master/scripts/setup-exports.js | MIT |
async function createExportsFallbacks() {
for (const entry of EXPORTS) {
const fallbackPath = path.join(root, entry)
await mkdir(fallbackPath, { recursive: true })
const destinationMain = path.join(root, 'lib.cjs', `${entry}.js`)
const destinationTypes = path.join(root, 'lib.cjs', `${entry}.d.ts`)
... | createExportsFallbacks setups fallbacks for loaders and bundlers not supporting the exports field.
It creates subdirectories with a package.json pointing to the CommonJS file and its type definition,
as explained in https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/packag... | createExportsFallbacks | javascript | tus/tus-js-client | scripts/setup-exports.js | https://github.com/tus/tus-js-client/blob/master/scripts/setup-exports.js | MIT |
function getBlob(str) {
return new Blob(str.split(''))
} | Helper function to create a Blob from a string. | getBlob | javascript | tus/tus-js-client | test/spec/helpers/utils.js | https://github.com/tus/tus-js-client/blob/master/test/spec/helpers/utils.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.