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 toMs (num) {
if (num < 31557600000) return num * 1000;
return num;
}
|
If the number passed val is seconds from the epoch, turn it into milliseconds.
Milliseconds would be greater than 31557600000 (December 31, 1970).
@param {Number} num
|
toMs
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function generate (type) {
return function (value) {
return type === typeOf(value);
};
}
|
Generate a type checker.
@param {String} type
@return {Function}
|
generate
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Alias (dictionary) {
Facade.call(this, dictionary);
}
|
Initialize a new `Alias` facade with a `dictionary` of arguments.
@param {Object} dictionary
@property {String} from
@property {String} to
@property {Object} options
|
Alias
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Group (dictionary) {
Facade.call(this, dictionary);
}
|
Initialize a new `Group` facade with a `dictionary` of arguments.
@param {Object} dictionary
@param {String} userId
@param {String} groupId
@param {Object} properties
@param {Object} options
|
Group
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function isEmail (string) {
return matcher.test(string);
}
|
Loosely validate an email address.
@param {String} string
@return {Boolean}
|
isEmail
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Identify (dictionary) {
Facade.call(this, dictionary);
}
|
Initialize a new `Identify` facade with a `dictionary` of arguments.
@param {Object} dictionary
@param {String} userId
@param {String} sessionId
@param {Object} traits
@param {Object} options
|
Identify
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function trim(str){
if (str.trim) return str.trim();
return str.replace(/^\s*|\s*$/g, '');
}
|
Setup sme basic "special" trait proxies.
|
trim
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Track (dictionary) {
Facade.call(this, dictionary);
}
|
Initialize a new `Track` facade with a `dictionary` of arguments.
@param {object} dictionary
@property {String} event
@property {String} userId
@property {String} sessionId
@property {Object} properties
@property {Object} options
|
Track
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function currency(val) {
if (!val) return;
if (typeof val === 'number') return val;
if (typeof val !== 'string') return;
val = val.replace(/\$/g, '');
val = parseFloat(val);
if (!isNaN(val)) return val;
}
|
Get float from currency value.
@param {Mixed} val
@return {Number}
|
currency
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Page(dictionary){
Facade.call(this, dictionary);
}
|
Initialize new `Page` facade with `dictionary`.
@param {Object} dictionary
@param {String} category
@param {String} name
@param {Object} traits
@param {Object} options
|
Page
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Screen(dictionary){
Page.call(this, dictionary);
}
|
Initialize new `Screen` facade with `dictionary`.
@param {Object} dictionary
@param {String} category
@param {String} name
@param {Object} traits
@param {Object} options
|
Screen
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function bindMethods (obj, methods) {
methods = [].slice.call(arguments, 1);
for (var i = 0, method; method = methods[i]; i++) {
obj[method] = bind(obj, obj[method]);
}
return obj;
}
|
Bind `methods` on `obj` to always be called with the `obj` as context.
@param {Object} obj
@param {String} methods...
|
bindMethods
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function callback (fn) {
if ('function' === typeof fn) fn();
}
|
Call an `fn` back synchronously if it exists.
@param {Function} fn
|
callback
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function set(name, value, options) {
options = options || {};
var str = encode(name) + '=' + encode(value);
if (null == value) options.maxage = -1;
if (options.maxage) {
options.expires = new Date(+new Date + options.maxage);
}
if (options.path) str += '; path=' + options.path;
if (options.domain) str += '; domain=' + options.domain;
if (options.expires) str += '; expires=' + options.expires.toUTCString();
if (options.secure) str += '; secure';
document.cookie = str;
}
|
Set cookie `name` to `value`.
@param {String} name
@param {String} value
@param {Object} options
@api private
|
set
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function all() {
return parse(document.cookie);
}
|
Return all cookies.
@return {Object}
@api private
|
all
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function get(name) {
return all()[name];
}
|
Get cookie `name`.
@param {String} name
@return {String}
@api private
|
get
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function parse(str) {
var obj = {};
var pairs = str.split(/ *; */);
var pair;
if ('' == pairs[0]) return obj;
for (var i = 0; i < pairs.length; ++i) {
pair = pairs[i].split('=');
obj[decode(pair[0])] = decode(pair[1]);
}
return obj;
}
|
Parse cookie `str`.
@param {String} str
@return {Object}
@api private
|
parse
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function color() {
return colors[prevColor++ % colors.length];
}
|
Select a color.
@return {Number}
@api private
|
color
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function humanize(ms) {
var sec = 1000
, min = 60 * 1000
, hour = 60 * min;
if (ms >= hour) return (ms / hour).toFixed(1) + 'h';
if (ms >= min) return (ms / min).toFixed(1) + 'm';
if (ms >= sec) return (ms / sec | 0) + 's';
return ms + 'ms';
}
|
Humanize the given `ms`.
@param {Number} m
@return {String}
@api private
|
humanize
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function debug(name) {
function disabled(){}
disabled.enabled = false;
var match = skips.some(function(re){
return re.test(name);
});
if (match) return disabled;
match = names.some(function(re){
return re.test(name);
});
if (!match) return disabled;
var c = color();
function colored(fmt) {
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (prev[name] || curr);
prev[name] = curr;
fmt = ' \u001b[9' + c + 'm' + name + ' '
+ '\u001b[3' + c + 'm\u001b[90m'
+ fmt + '\u001b[3' + c + 'm'
+ ' +' + humanize(ms) + '\u001b[0m';
console.error.apply(this, arguments);
}
function plain(fmt) {
fmt = coerce(fmt);
fmt = new Date().toUTCString()
+ ' ' + name + ' ' + fmt;
console.error.apply(this, arguments);
}
colored.enabled = plain.enabled = true;
return isatty || process.env.DEBUG_COLORS
? colored
: plain;
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
debug
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function colored(fmt) {
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (prev[name] || curr);
prev[name] = curr;
fmt = ' \u001b[9' + c + 'm' + name + ' '
+ '\u001b[3' + c + 'm\u001b[90m'
+ fmt + '\u001b[3' + c + 'm'
+ ' +' + humanize(ms) + '\u001b[0m';
console.error.apply(this, arguments);
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
colored
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function plain(fmt) {
fmt = coerce(fmt);
fmt = new Date().toUTCString()
+ ' ' + name + ' ' + fmt;
console.error.apply(this, arguments);
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
plain
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function debug(name) {
if (!debug.enabled(name)) return function(){};
return function(fmt){
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (debug[name] || curr);
debug[name] = curr;
fmt = name
+ ' '
+ fmt
+ ' +' + debug.humanize(ms);
// This hackery is required for IE8
// where `console.log` doesn't have 'apply'
window.console
&& console.log
&& Function.prototype.apply.call(console.log, console, arguments);
}
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
debug
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
defaults = function (dest, src, recursive) {
for (var prop in src) {
if (recursive && dest[prop] instanceof Object && src[prop] instanceof Object) {
dest[prop] = defaults(dest[prop], src[prop], true);
} else if (! (prop in dest)) {
dest[prop] = src[prop];
}
}
return dest;
}
|
Merge default values.
@param {Object} dest
@param {Object} defaults
@return {Object}
@api public
|
defaults
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function domain(url){
var cookie = exports.cookie;
var levels = exports.levels(url);
// Lookup the real top level one.
for (var i = 0; i < levels.length; ++i) {
var cname = '__tld__';
var domain = levels[i];
var opts = { domain: '.' + domain };
cookie(cname, 1, opts);
if (cookie(cname)) {
cookie(cname, null, opts);
return domain
}
}
return '';
}
|
Get the top domain.
The function constructs the levels of domain
and attempts to set a global cookie on each one
when it succeeds it returns the top level domain.
The method returns an empty string when the hostname
is an ip or `localhost`.
Example levels:
domain.levels('http://www.google.co.uk');
// => ["co.uk", "google.co.uk", "www.google.co.uk"]
Example:
domain('http://localhost:3000/baz');
// => ''
domain('http://dev:3000/baz');
// => ''
domain('http://127.0.0.1:3000/baz');
// => ''
domain('http://segment.io/baz');
// => 'segment.io'
@param {String} url
@return {String}
@api public
|
domain
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function port (protocol){
switch (protocol) {
case 'http:':
return 80;
case 'https:':
return 443;
default:
return location.port;
}
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
port
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function set(name, value, options) {
options = options || {};
var str = encode(name) + '=' + encode(value);
if (null == value) options.maxage = -1;
if (options.maxage) {
options.expires = new Date(+new Date + options.maxage);
}
if (options.path) str += '; path=' + options.path;
if (options.domain) str += '; domain=' + options.domain;
if (options.expires) str += '; expires=' + options.expires.toUTCString();
if (options.secure) str += '; secure';
document.cookie = str;
}
|
Set cookie `name` to `value`.
@param {String} name
@param {String} value
@param {Object} options
@api private
|
set
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function all() {
var str;
try {
str = document.cookie;
} catch (err) {
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(err.stack || err);
}
return {};
}
return parse(str);
}
|
Return all cookies.
@return {Object}
@api private
|
all
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function get(name) {
return all()[name];
}
|
Get cookie `name`.
@param {String} name
@return {String}
@api private
|
get
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function parse(str) {
var obj = {};
var pairs = str.split(/ *; */);
var pair;
if ('' == pairs[0]) return obj;
for (var i = 0; i < pairs.length; ++i) {
pair = pairs[i].split('=');
obj[decode(pair[0])] = decode(pair[1]);
}
return obj;
}
|
Parse cookie `str`.
@param {String} str
@return {Object}
@api private
|
parse
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Group(options) {
this.defaults = Group.defaults;
this.debug = debug;
Entity.call(this, options);
}
|
Initialize a new `Group` with `options`.
@param {Object} options
|
Group
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Entity(options) {
this.options(options);
this.initialize();
}
|
Initialize new `Entity` with `options`.
@param {Object} options
|
Entity
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function generate (type) {
return function (value) {
return type === typeOf(value);
};
}
|
Generate a type checker.
@param {String} type
@return {Function}
|
generate
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function normalize(msg, list){
var lower = map(list, function(s){ return s.toLowerCase(); });
var opts = msg.options || {};
var integrations = opts.integrations || {};
var providers = opts.providers || {};
var context = opts.context || {};
var ret = {};
debug('<-', msg);
// integrations.
each(opts, function(key, value){
if (!integration(key)) return;
if (!has.call(integrations, key)) integrations[key] = value;
delete opts[key];
});
// providers.
delete opts.providers;
each(providers, function(key, value){
if (!integration(key)) return;
if (is.object(integrations[key])) return;
if (has.call(integrations, key) && typeof providers[key] === 'boolean') return;
integrations[key] = value;
});
// move all toplevel options to msg
// and the rest to context.
each(opts, function(key){
if (includes(key, toplevel)) {
ret[key] = opts[key];
} else {
context[key] = opts[key];
}
});
// cleanup
delete msg.options;
ret.integrations = integrations;
ret.context = context;
ret = defaults(ret, msg);
debug('->', ret);
return ret;
function integration(name){
return !!(includes(name, list) || name.toLowerCase() === 'all' || includes(name.toLowerCase(), lower));
}
}
|
Normalize `msg` based on integrations `list`.
@param {Object} msg
@param {Array} list
@return {Function}
|
normalize
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function integration(name){
return !!(includes(name, list) || name.toLowerCase() === 'all' || includes(name.toLowerCase(), lower));
}
|
Normalize `msg` based on integrations `list`.
@param {Object} msg
@param {Array} list
@return {Function}
|
integration
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
sameValueZero = function sameValueZero(value1, value2) {
// Normal values and check for 0 / -0
if (value1 === value2) {
return value1 !== 0 || 1 / value1 === 1 / value2;
}
// NaN
return value1 !== value1 && value2 !== value2;
}
|
Object.is/sameValueZero polyfill.
@api private
@param {*} value1
@param {*} value2
@return {boolean}
|
sameValueZero
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
includes = function includes(searchElement, collection) {
var found = false;
// Delegate to String.prototype.indexOf when `collection` is a string
if (typeof collection === 'string') {
return strIndexOf.call(collection, searchElement) !== -1;
}
// Iterate through enumerable/own array elements and object properties.
each(function(value) {
if (sameValueZero(value, searchElement)) {
found = true;
// Exit iteration early when found
return false;
}
}, collection);
return found;
}
|
Searches a given `collection` for a value, returning true if the collection
contains the value and false otherwise. Can search strings, arrays, and
objects.
@name includes
@api public
@param {*} searchElement The element to search for.
@param {Object|Array|string} collection The collection to search.
@return {boolean}
@example
includes(2, [1, 2, 3]);
//=> true
includes(4, [1, 2, 3]);
//=> false
includes(2, { a: 1, b: 2, c: 3 });
//=> true
includes('a', { a: 1, b: 2, c: 3 });
//=> false
includes('abc', 'xyzabc opq');
//=> true
includes('nope', 'xyzabc opq');
//=> false
|
includes
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isNumber = function isNumber(val) {
var type = typeof val;
return type === 'number' || (type === 'object' && objToString.call(val) === '[object Number]');
}
|
Tests if a value is a number.
@name isNumber
@api private
@param {*} val The value to test.
@return {boolean} Returns `true` if `val` is a number, otherwise `false`.
|
isNumber
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isArrayLike = function isArrayLike(val) {
return val != null && (isArray(val) || (val !== 'function' && isNumber(val.length)));
}
|
Tests if a value is array-like. Array-like means the value is not a function and has a numeric
`.length` property.
@name isArrayLike
@api private
@param {*} val
@return {boolean}
|
isArrayLike
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
arrayEach = function arrayEach(iterator, array) {
for (var i = 0; i < array.length; i += 1) {
// Break iteration early if `iterator` returns `false`
if (iterator(array[i], i, array) === false) {
break;
}
}
}
|
Internal implementation of `each`. Works on arrays and array-like data structures.
@name arrayEach
@api private
@param {Function(value, key, collection)} iterator The function to invoke per iteration.
@param {Array} array The array(-like) structure to iterate over.
@return {undefined}
|
arrayEach
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
baseEach = function baseEach(iterator, object) {
var ks = keys(object);
for (var i = 0; i < ks.length; i += 1) {
// Break iteration early if `iterator` returns `false`
if (iterator(object[ks[i]], ks[i], object) === false) {
break;
}
}
}
|
Internal implementation of `each`. Works on objects.
@name baseEach
@api private
@param {Function(value, key, collection)} iterator The function to invoke per iteration.
@param {Object} object The object to iterate over.
@return {undefined}
|
baseEach
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
each = function each(iterator, collection) {
return (isArrayLike(collection) ? arrayEach : baseEach).call(this, iterator, collection);
}
|
Iterate over an input collection, invoking an `iterator` function for each element in the
collection and passing to it three arguments: `(value, index, collection)`. The `iterator`
function can end iteration early by returning `false`.
@name each
@api public
@param {Function(value, key, collection)} iterator The function to invoke per iteration.
@param {Array|Object|string} collection The collection to iterate over.
@return {undefined} Because `each` is run only for side effects, always returns `undefined`.
@example
var log = console.log.bind(console);
each(log, ['a', 'b', 'c']);
//-> 'a', 0, ['a', 'b', 'c']
//-> 'b', 1, ['a', 'b', 'c']
//-> 'c', 2, ['a', 'b', 'c']
//=> undefined
each(log, 'tim');
//-> 't', 2, 'tim'
//-> 'i', 1, 'tim'
//-> 'm', 0, 'tim'
//=> undefined
// Note: Iteration order not guaranteed across environments
each(log, { name: 'tim', occupation: 'enchanter' });
//-> 'tim', 'name', { name: 'tim', occupation: 'enchanter' }
//-> 'enchanter', 'occupation', { name: 'tim', occupation: 'enchanter' }
//=> undefined
|
each
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
charAt = function(str, index) {
return strCharAt.call(str, index);
}
|
Returns the character at a given index.
@param {string} str
@param {number} index
@return {string|undefined}
|
charAt
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
has = function has(context, prop) {
return hop.call(context, prop);
}
|
hasOwnProperty, wrapped as a function.
@name has
@api private
@param {*} context
@param {string|number} prop
@return {boolean}
|
has
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isString = function isString(val) {
return toStr.call(val) === '[object String]';
}
|
Returns true if a value is a string, otherwise false.
@name isString
@api private
@param {*} val
@return {boolean}
|
isString
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isArrayLike = function isArrayLike(val) {
return val != null && (typeof val !== 'function' && typeof val.length === 'number');
}
|
Returns true if a value is array-like, otherwise false. Array-like means a
value is not null, undefined, or a function, and has a numeric `length`
property.
@name isArrayLike
@api private
@param {*} val
@return {boolean}
|
isArrayLike
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
indexKeys = function indexKeys(target, pred) {
pred = pred || has;
var results = [];
for (var i = 0, len = target.length; i < len; i += 1) {
if (pred(target, i)) {
results.push(String(i));
}
}
return results;
}
|
indexKeys
@name indexKeys
@api private
@param {} target
@param {} pred
@return {Array}
|
indexKeys
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
objectKeys = function objectKeys(target, pred) {
pred = pred || has;
var results = [];
for (var key in target) {
if (pred(target, key)) {
results.push(String(key));
}
}
return results;
}
|
Returns an array of all the owned
@name objectKeys
@api private
@param {*} target
@param {Function} pred Predicate function used to include/exclude values from
the resulting array.
@return {Array}
|
objectKeys
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function toFunction(obj) {
switch ({}.toString.call(obj)) {
case '[object Object]':
return objectToFunction(obj);
case '[object Function]':
return obj;
case '[object String]':
return stringToFunction(obj);
case '[object RegExp]':
return regexpToFunction(obj);
default:
return defaultToFunction(obj);
}
}
|
Convert `obj` to a `Function`.
@param {Mixed} obj
@return {Function}
@api private
|
toFunction
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function defaultToFunction(val) {
return function(obj){
return val === obj;
};
}
|
Default to strict equality.
@param {Mixed} val
@return {Function}
@api private
|
defaultToFunction
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function regexpToFunction(re) {
return function(obj){
return re.test(obj);
};
}
|
Convert `re` to a function.
@param {RegExp} re
@return {Function}
@api private
|
regexpToFunction
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function stringToFunction(str) {
// immediate such as "> 20"
if (/^ *\W+/.test(str)) return new Function('_', 'return _ ' + str);
// properties such as "name.first" or "age > 18" or "age > 18 && age < 36"
return new Function('_', 'return ' + get(str));
}
|
Convert property `str` to a function.
@param {String} str
@return {Function}
@api private
|
stringToFunction
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function objectToFunction(obj) {
var match = {};
for (var key in obj) {
match[key] = typeof obj[key] === 'string'
? defaultToFunction(obj[key])
: toFunction(obj[key]);
}
return function(val){
if (typeof val !== 'object') return false;
for (var key in match) {
if (!(key in val)) return false;
if (!match[key](val[key])) return false;
}
return true;
};
}
|
Convert `object` to a function.
@param {Object} object
@return {Function}
@api private
|
objectToFunction
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function get(str) {
var props = expr(str);
if (!props.length) return '_.' + str;
var val, i, prop;
for (i = 0; i < props.length; i++) {
prop = props[i];
val = '_.' + prop;
val = "('function' == typeof " + val + " ? " + val + "() : " + val + ")";
// mimic negative lookbehind to avoid problems with nested properties
str = stripNested(prop, str, val);
}
return str;
}
|
Built the getter function. Supports getter style functions
@param {String} str
@return {String}
@api private
|
get
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function stripNested (prop, str, val) {
return str.replace(new RegExp('(\\.)?' + prop, 'g'), function($0, $1) {
return $1 ? $0 : val;
});
}
|
Mimic negative lookbehind to avoid problems with nested properties.
See: http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
@param {String} prop
@param {String} str
@param {String} val
@return {String}
@api private
|
stripNested
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function props(str) {
return str
.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g, '')
.replace(globals, '')
.match(/[$a-zA-Z_]\w*/g)
|| [];
}
|
Return immediate identifiers in `str`.
@param {String} str
@return {Array}
@api private
|
props
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function map(str, props, fn) {
var re = /\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g;
return str.replace(re, function(_){
if ('(' == _[_.length - 1]) return fn(_);
if (!~props.indexOf(_)) return _;
return fn(_);
});
}
|
Return `str` with `props` mapped with `fn`.
@param {String} str
@param {Array} props
@param {Function} fn
@return {String}
@api private
|
map
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function unique(arr) {
var ret = [];
for (var i = 0; i < arr.length; i++) {
if (~ret.indexOf(arr[i])) continue;
ret.push(arr[i]);
}
return ret;
}
|
Return unique array.
@param {Array} arr
@return {Array}
@api private
|
unique
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function pageDefaults() {
return {
path: canonicalPath(),
referrer: document.referrer,
search: location.search,
title: document.title,
url: canonicalUrl(location.search)
};
}
|
Return a default `options.context.page` object.
https://segment.com/docs/spec/page/#properties
@return {Object}
|
pageDefaults
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function canonicalPath() {
var canon = canonical();
if (!canon) return window.location.pathname;
var parsed = url.parse(canon);
return parsed.pathname;
}
|
Return the canonical path for the page.
@return {string}
|
canonicalPath
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function canonicalUrl(search) {
var canon = canonical();
if (canon) return includes('?', canon) ? canon : canon + search;
var url = window.location.href;
var i = url.indexOf('#');
return i === -1 ? url : url.slice(0, i);
}
|
Return the canonical URL for the page concat the given `search`
and strip the hash.
@param {string} search
@return {string}
|
canonicalUrl
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function port (protocol){
switch (protocol) {
case 'http:':
return 80;
case 'https:':
return 443;
default:
return location.port;
}
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
port
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
existy = function(val) {
return val != null;
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
existy
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isArray = function(val) {
return objToString.call(val) === '[object Array]';
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
isArray
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isString = function(val) {
return typeof val === 'string' || objToString.call(val) === '[object String]';
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
isString
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
isObject = function(val) {
return val != null && typeof val === 'object';
}
|
Return default port for `protocol`.
@param {String} protocol
@return {String}
@api private
|
isObject
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
encode = function(str) {
try {
return encodeURIComponent(str);
} catch (e) {
return str;
}
}
|
Safely encode the given string
@param {String} str
@return {String}
@api private
|
encode
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
decode = function(str) {
try {
return decodeURIComponent(str.replace(/\+/g, ' '));
} catch (e) {
return str;
}
}
|
Safely decode the string
@param {String} str
@return {String}
@api private
|
decode
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function User(options) {
this.defaults = User.defaults;
this.debug = debug;
Entity.call(this, options);
}
|
Initialize a new `User` with `options`.
@param {Object} options
|
User
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function createIntegration(name){
/**
* Initialize a new `Integration`.
*
* @class
* @param {Object} options
*/
function Integration(options){
if (options && options.addIntegration) {
// plugin
return options.addIntegration(Integration);
}
this.debug = debug('analytics:integration:' + slug(name));
this.options = defaults(clone(options) || {}, this.defaults);
this._queue = [];
this.once('ready', bind(this, this.flush));
Integration.emit('construct', this);
this.ready = bind(this, this.ready);
this._wrapInitialize();
this._wrapPage();
this._wrapTrack();
}
Integration.prototype.defaults = {};
Integration.prototype.globals = [];
Integration.prototype.templates = {};
Integration.prototype.name = name;
extend(Integration, statics);
extend(Integration.prototype, protos);
return Integration;
}
|
Create a new `Integration` constructor.
@constructs Integration
@param {string} name
@return {Function} Integration
|
createIntegration
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function Integration(options){
if (options && options.addIntegration) {
// plugin
return options.addIntegration(Integration);
}
this.debug = debug('analytics:integration:' + slug(name));
this.options = defaults(clone(options) || {}, this.defaults);
this._queue = [];
this.once('ready', bind(this, this.flush));
Integration.emit('construct', this);
this.ready = bind(this, this.ready);
this._wrapInitialize();
this._wrapPage();
this._wrapTrack();
}
|
Initialize a new `Integration`.
@class
@param {Object} options
|
Integration
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function bindMethods (obj, methods) {
methods = [].slice.call(arguments, 1);
for (var i = 0, method; method = methods[i]; i++) {
obj[method] = bind(obj, obj[method]);
}
return obj;
}
|
Bind `methods` on `obj` to always be called with the `obj` as context.
@param {Object} obj
@param {String} methods...
|
bindMethods
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function color() {
return colors[prevColor++ % colors.length];
}
|
Select a color.
@return {Number}
@api private
|
color
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function humanize(ms) {
var sec = 1000
, min = 60 * 1000
, hour = 60 * min;
if (ms >= hour) return (ms / hour).toFixed(1) + 'h';
if (ms >= min) return (ms / min).toFixed(1) + 'm';
if (ms >= sec) return (ms / sec | 0) + 's';
return ms + 'ms';
}
|
Humanize the given `ms`.
@param {Number} m
@return {String}
@api private
|
humanize
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function debug(name) {
function disabled(){}
disabled.enabled = false;
var match = skips.some(function(re){
return re.test(name);
});
if (match) return disabled;
match = names.some(function(re){
return re.test(name);
});
if (!match) return disabled;
var c = color();
function colored(fmt) {
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (prev[name] || curr);
prev[name] = curr;
fmt = ' \u001b[9' + c + 'm' + name + ' '
+ '\u001b[3' + c + 'm\u001b[90m'
+ fmt + '\u001b[3' + c + 'm'
+ ' +' + humanize(ms) + '\u001b[0m';
console.error.apply(this, arguments);
}
function plain(fmt) {
fmt = coerce(fmt);
fmt = new Date().toUTCString()
+ ' ' + name + ' ' + fmt;
console.error.apply(this, arguments);
}
colored.enabled = plain.enabled = true;
return isatty || process.env.DEBUG_COLORS
? colored
: plain;
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
debug
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function colored(fmt) {
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (prev[name] || curr);
prev[name] = curr;
fmt = ' \u001b[9' + c + 'm' + name + ' '
+ '\u001b[3' + c + 'm\u001b[90m'
+ fmt + '\u001b[3' + c + 'm'
+ ' +' + humanize(ms) + '\u001b[0m';
console.error.apply(this, arguments);
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
colored
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function plain(fmt) {
fmt = coerce(fmt);
fmt = new Date().toUTCString()
+ ' ' + name + ' ' + fmt;
console.error.apply(this, arguments);
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
plain
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function debug(name) {
if (!debug.enabled(name)) return function(){};
return function(fmt){
fmt = coerce(fmt);
var curr = new Date;
var ms = curr - (debug[name] || curr);
debug[name] = curr;
fmt = name
+ ' '
+ fmt
+ ' +' + debug.humanize(ms);
// This hackery is required for IE8
// where `console.log` doesn't have 'apply'
window.console
&& console.log
&& Function.prototype.apply.call(console.log, console, arguments);
}
}
|
Create a debugger with the given `name`.
@param {String} name
@return {Type}
@api public
|
debug
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function loadImage(attrs, fn){
fn = fn || function(){};
var img = new Image();
img.onerror = error(fn, 'failed to load pixel', img);
img.onload = function(){ fn(); };
img.src = attrs.src;
img.width = 1;
img.height = 1;
return img;
}
|
TODO: Document me
@api private
@param {Object} attrs
@param {Function} fn
@return {undefined}
|
loadImage
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function error(fn, message, img){
return function(e){
e = e || window.event;
var err = new Error(message);
err.event = e;
err.source = img;
fn(err);
};
}
|
TODO: Document me
@api private
@param {Function} fn
@param {string} message
@param {Element} img
@return {Function}
|
error
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function render(template, locals){
return foldl(function(attrs, val, key) {
attrs[key] = val.replace(/\{\{\ *(\w+)\ *\}\}/g, function(_, $1){
return locals[$1];
});
return attrs;
}, {}, template.attrs);
}
|
Render template + locals into an `attrs` object.
@api private
@param {Object} template
@param {Object} locals
@return {Object}
|
render
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function string(obj, fn, ctx) {
for (var i = 0; i < obj.length; ++i) {
fn.call(ctx, obj.charAt(i), i);
}
}
|
Iterate string chars.
@param {String} obj
@param {Function} fn
@param {Object} ctx
@api private
|
string
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function object(obj, fn, ctx) {
for (var key in obj) {
if (has.call(obj, key)) {
fn.call(ctx, key, obj[key]);
}
}
}
|
Iterate object keys.
@param {Object} obj
@param {Function} fn
@param {Object} ctx
@api private
|
object
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function array(obj, fn, ctx) {
for (var i = 0; i < obj.length; ++i) {
fn.call(ctx, obj[i], i);
}
}
|
Iterate array-ish.
@param {Array|Object} obj
@param {Function} fn
@param {Object} ctx
@api private
|
array
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function fmt(str){
var args = [].slice.call(arguments, 1);
var j = 0;
return str.replace(/%([a-z])/gi, function(_, f){
return fmt[f]
? fmt[f](args[j++])
: _ + f;
});
}
|
Format the given `str`.
@param {String} str
@param {...} args
@return {String}
@api public
|
fmt
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
foldl = function foldl(iterator, accumulator, collection) {
if (typeof iterator !== 'function') {
throw new TypeError('Expected a function but received a ' + typeof iterator);
}
each(function(val, i, collection) {
accumulator = iterator(accumulator, val, i, collection);
}, collection);
return accumulator;
}
|
Reduces all the values in a collection down into a single value. Does so by iterating through the
collection from left to right, repeatedly calling an `iterator` function and passing to it four
arguments: `(accumulator, value, index, collection)`.
Returns the final return value of the `iterator` function.
@name foldl
@api public
@param {Function} iterator The function to invoke per iteration.
@param {*} accumulator The initial accumulator value, passed to the first invocation of `iterator`.
@param {Array|Object} collection The collection to iterate over.
@return {*} The return value of the final call to `iterator`.
@example
foldl(function(total, n) {
return total + n;
}, 0, [1, 2, 3]);
//=> 6
var phonebook = { bob: '555-111-2345', tim: '655-222-6789', sheila: '655-333-1298' };
foldl(function(results, phoneNumber) {
if (phoneNumber[0] === '6') {
return results.concat(phoneNumber);
}
return results;
}, [], phonebook);
// => ['655-222-6789', '655-333-1298']
|
foldl
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function add(el, fn){
el.addEventListener('load', function(_, e){ fn(null, e); }, false);
el.addEventListener('error', function(e){
var err = new Error('script error "' + el.src + '"');
err.event = e;
fn(err);
}, false);
}
|
Add event listener to `el`, `fn()`.
@param {Element} el
@param {Function} fn
@api private
|
add
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function attach(el, fn){
el.attachEvent('onreadystatechange', function(e){
if (!/complete|loaded/.test(el.readyState)) return;
fn(null, e);
});
el.attachEvent('onerror', function(e){
var err = new Error('failed to load the script "' + el.src + '"');
err.event = e || window.event;
fn(err);
});
}
|
Attach event.
@param {Element} el
@param {Function} fn
@api private
|
attach
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function toNoCase (string) {
if (hasSpace.test(string)) return string.toLowerCase();
if (hasSeparator.test(string)) return unseparate(string).toLowerCase();
return uncamelize(string).toLowerCase();
}
|
Remove any starting case from a `string`, like camel or snake, but keep
spaces and punctuation that may be important otherwise.
@param {String} string
@return {String}
|
toNoCase
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function unseparate (string) {
return string.replace(separatorSplitter, function (m, next) {
return next ? ' ' + next : '';
});
}
|
Un-separate a `string`.
@param {String} string
@return {String}
|
unseparate
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function uncamelize (string) {
return string.replace(camelSplitter, function (m, previous, uppers) {
return previous + ' ' + uppers.toLowerCase().split('').join(' ');
});
}
|
Un-camelcase a `string`.
@param {String} string
@return {String}
|
uncamelize
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function objectify(str) {
// replace `src` with `data-src` to prevent image loading
str = str.replace(' src="', ' data-src="');
var el = domify(str);
var attrs = {};
each(el.attributes, function(attr){
// then replace it back
var name = attr.name === 'data-src' ? 'src' : attr.name;
if (!includes(attr.name + '=', str)) return;
attrs[name] = attr.value;
});
return {
type: el.tagName.toLowerCase(),
attrs: attrs
};
}
|
Given a string, give back DOM attributes.
Do it in a way where the browser doesn't load images or iframes. It turns
out domify will load images/iframes because whenever you construct those
DOM elements, the browser immediately loads them.
@api private
@param {string} str
@return {Object}
|
objectify
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function parse(html, doc) {
if ('string' != typeof html) throw new TypeError('String expected');
// default to the global `document` object
if (!doc) doc = document;
// tag name
var m = /<([\w:]+)/.exec(html);
if (!m) return doc.createTextNode(html);
html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
var tag = m[1];
// body support
if (tag == 'body') {
var el = doc.createElement('html');
el.innerHTML = html;
return el.removeChild(el.lastChild);
}
// wrap map
var wrap = map[tag] || map._default;
var depth = wrap[0];
var prefix = wrap[1];
var suffix = wrap[2];
var el = doc.createElement('div');
el.innerHTML = prefix + html + suffix;
while (depth--) el = el.lastChild;
// one element
if (el.firstChild == el.lastChild) {
return el.removeChild(el.firstChild);
}
// several elements
var fragment = doc.createDocumentFragment();
while (el.firstChild) {
fragment.appendChild(el.removeChild(el.firstChild));
}
return fragment;
}
|
Parse `html` and return a DOM Node instance, which could be a TextNode,
HTML DOM Node of some kind (<div> for example), or a DocumentFragment
instance, depending on the contents of the `html` string.
@param {String} html - HTML string to "domify"
@param {Document} doc - The `document` instance to create the Node for
@return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance
@api private
|
parse
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function toSnakeCase (string) {
return toSpace(string).replace(/\s/g, '_');
}
|
Convert a `string` to snake case.
@param {String} string
@return {String}
|
toSnakeCase
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function toSpaceCase (string) {
return clean(string).replace(/[\W_]+(.|$)/g, function (matches, match) {
return match ? ' ' + match : '';
});
}
|
Convert a `string` to space case.
@param {String} string
@return {String}
|
toSpaceCase
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function toNoCase (string) {
if (hasSpace.test(string)) return string.toLowerCase();
if (hasSeparator.test(string)) string = unseparate(string);
if (hasCamel.test(string)) string = uncamelize(string);
return string.toLowerCase();
}
|
Remove any starting case from a `string`, like camel or snake, but keep
spaces and punctuation that may be important otherwise.
@param {String} string
@return {String}
|
toNoCase
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function unseparate (string) {
return string.replace(separatorSplitter, function (m, next) {
return next ? ' ' + next : '';
});
}
|
Un-separate a `string`.
@param {String} string
@return {String}
|
unseparate
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function uncamelize (string) {
return string.replace(camelSplitter, function (m, previous, uppers) {
return previous + ' ' + uppers.toLowerCase().split('').join(' ');
});
}
|
Un-camelcase a `string`.
@param {String} string
@return {String}
|
uncamelize
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function transform (url) {
return check() ? 'https:' + url : 'http:' + url;
}
|
Transform a protocol-relative `url` to the use the proper protocol.
@param {String} url
@return {String}
|
transform
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
function check () {
return (
location.protocol == 'https:' ||
location.protocol == 'chrome-extension:'
);
}
|
Check whether `https:` be used for loading scripts.
@return {Boolean}
|
check
|
javascript
|
segmentio/analytics.js
|
analytics.js
|
https://github.com/segmentio/analytics.js/blob/master/analytics.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.