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
addRow(position) { const rng = this.getLastRange(this.$editable); if (rng.isCollapsed() && rng.isOnCell()) { this.beforeCommand(); this.table.addRow(rng, position); this.afterCommand(); } }
returns link info @return {Object} @return {WrappedRange} return.range @return {String} return.text @return {Boolean} [return.isNewWindow=true] @return {String} [return.url=""]
addRow
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
addCol(position) { const rng = this.getLastRange(this.$editable); if (rng.isCollapsed() && rng.isOnCell()) { this.beforeCommand(); this.table.addCol(rng, position); this.afterCommand(); } }
returns link info @return {Object} @return {WrappedRange} return.range @return {String} return.text @return {Boolean} [return.isNewWindow=true] @return {String} [return.url=""]
addCol
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
deleteRow() { const rng = this.getLastRange(this.$editable); if (rng.isCollapsed() && rng.isOnCell()) { this.beforeCommand(); this.table.deleteRow(rng); this.afterCommand(); } }
returns link info @return {Object} @return {WrappedRange} return.range @return {String} return.text @return {Boolean} [return.isNewWindow=true] @return {String} [return.url=""]
deleteRow
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
deleteCol() { const rng = this.getLastRange(this.$editable); if (rng.isCollapsed() && rng.isOnCell()) { this.beforeCommand(); this.table.deleteCol(rng); this.afterCommand(); } }
returns link info @return {Object} @return {WrappedRange} return.range @return {String} return.text @return {Boolean} [return.isNewWindow=true] @return {String} [return.url=""]
deleteCol
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
deleteTable() { const rng = this.getLastRange(this.$editable); if (rng.isCollapsed() && rng.isOnCell()) { this.beforeCommand(); this.table.deleteTable(rng); this.afterCommand(); } }
returns link info @return {Object} @return {WrappedRange} return.range @return {String} return.text @return {Boolean} [return.isNewWindow=true] @return {String} [return.url=""]
deleteTable
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
resizeTo(pos, $target, bKeepRatio) { let imageSize; if (bKeepRatio) { const newRatio = pos.y / pos.x; const ratio = $target.data('ratio'); imageSize = { width: ratio > newRatio ? pos.x : pos.y / ratio, height: ratio > newRatio ? pos.x * ratio : pos.y, }; } else { ...
@param {Position} pos @param {jQuery} $target - target element @param {Boolean} [bKeepRatio] - keep ratio
resizeTo
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
hasFocus() { return this.$editable.is(':focus'); }
returns whether editable area has focus or not.
hasFocus
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
isEmpty() { return dom.isEmpty(this.$editable[0]) || dom.emptyPara === this.$editable.html(); }
returns whether contents is empty or not. @return {Boolean}
isEmpty
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
empty() { this.context.invoke('code', dom.emptyPara); }
Removes all contents and restores the editable instance to an _emptyPara_.
empty
javascript
summernote/summernote
src/js/module/Editor.js
https://github.com/summernote/summernote/blob/master/src/js/module/Editor.js
MIT
showImageDialog() { return $.Deferred((deferred) => { const $imageInput = this.$dialog.find('.note-image-input'); const $imageUrl = this.$dialog.find('.note-image-url'); const $imageBtn = this.$dialog.find('.note-image-btn'); this.ui.onDialogShown(this.$dialog, () => { this.context....
show image dialog @param {jQuery} $dialog @return {Promise}
showImageDialog
javascript
summernote/summernote
src/js/module/ImageDialog.js
https://github.com/summernote/summernote/blob/master/src/js/module/ImageDialog.js
MIT
constructor(context) { this.context = context; this.ui = $.summernote.ui; this.editable = context.layoutInfo.editable[0]; this.options = context.options; this.events = { 'summernote.disable summernote.dialog.shown': () => { this.hide(); }, 'summernote.blur': (we, event) =...
Image popover module mouse events that show/hide popover will be handled by Handle.js. Handle.js will receive the events and invoke 'imagePopover.update'.
constructor
javascript
summernote/summernote
src/js/module/ImagePopover.js
https://github.com/summernote/summernote/blob/master/src/js/module/ImagePopover.js
MIT
shouldInitialize() { return !lists.isEmpty(this.options.popover.image); }
Image popover module mouse events that show/hide popover will be handled by Handle.js. Handle.js will receive the events and invoke 'imagePopover.update'.
shouldInitialize
javascript
summernote/summernote
src/js/module/ImagePopover.js
https://github.com/summernote/summernote/blob/master/src/js/module/ImagePopover.js
MIT
initialize() { this.$popover = this.ui.popover({ className: 'note-image-popover', }).render().appendTo(this.options.container); const $content = this.$popover.find('.popover-content,.note-popover-content'); this.context.invoke('buttons.build', $content, this.options.popover.image); this.$popo...
Image popover module mouse events that show/hide popover will be handled by Handle.js. Handle.js will receive the events and invoke 'imagePopover.update'.
initialize
javascript
summernote/summernote
src/js/module/ImagePopover.js
https://github.com/summernote/summernote/blob/master/src/js/module/ImagePopover.js
MIT
update(target, event) { if (dom.isImg(target)) { const position = $(target).offset(); const containerOffset = $(this.options.container).offset(); let pos = {}; if (this.options.popatmouse) { pos.left = event.pageX - 20; pos.top = event.pageY; } else { pos = posi...
Image popover module mouse events that show/hide popover will be handled by Handle.js. Handle.js will receive the events and invoke 'imagePopover.update'.
update
javascript
summernote/summernote
src/js/module/ImagePopover.js
https://github.com/summernote/summernote/blob/master/src/js/module/ImagePopover.js
MIT
showLinkDialog(linkInfo) { return $.Deferred((deferred) => { const $linkText = this.$dialog.find('.note-link-text'); const $linkUrl = this.$dialog.find('.note-link-url'); const $linkBtn = this.$dialog.find('.note-link-btn'); const $openInNewWindow = this.$dialog .find('.sn-checkbox-o...
Show link dialog and set event handlers on dialog controls. @param {Object} linkInfo @return {Promise}
showLinkDialog
javascript
summernote/summernote
src/js/module/LinkDialog.js
https://github.com/summernote/summernote/blob/master/src/js/module/LinkDialog.js
MIT
showVideoDialog(/* text */) { return $.Deferred((deferred) => { const $videoUrl = this.$dialog.find('.note-video-url'); const $videoBtn = this.$dialog.find('.note-video-btn'); this.ui.onDialogShown(this.$dialog, () => { this.context.triggerEvent('dialog.shown'); $videoUrl.on('inp...
show video dialog @param {jQuery} $dialog @return {Promise}
showVideoDialog
javascript
summernote/summernote
src/js/module/VideoDialog.js
https://github.com/summernote/summernote/blob/master/src/js/module/VideoDialog.js
MIT
function initSwitchStyle(swEl, options, sw) { classList(swEl). add( 'switch', 'switch-' + (legalSize.includes(options.size) ? options.size : 'default'), options.checked ? SWITCH_ON_CLASS : SWITCH_OFF_CLASS ); setJackText.call(sw); setSwitchColor.call(sw); setJackPosition....
remove switch form DOM and show the checkbox @public
initSwitchStyle
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function initSwitchAttr(swEl, options) { swEl.setAttribute('tabindex', 0); swEl.setAttribute('role', 'checkbox'); swEl.setAttribute('aria-checked', options.checked); swEl.setAttribute('aria-disabled', options.disabled); }
remove switch form DOM and show the checkbox @public
initSwitchAttr
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function insertSwitch(source, target) { target.parentNode.insertBefore(source, target.nextSibling); }
remove switch form DOM and show the checkbox @public
insertSwitch
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function setSwitchColor() { if(this._el.checked){ this._switch.style.boxShadow = 'inset 0 0 0 ' + this._switch.clientHeight/1.8 + 'px ' + this._options.onSwitchColor; this._switch.style.border = '1px solid ' + this._options.onSwitchColor; this._switch.style.transition = 'border 0.4s, box-s...
remove switch form DOM and show the checkbox @public
setSwitchColor
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function setSwitchDisabled(disabled) { this._el.disabled = disabled; classList(this._switch)[disabled? 'add' : 'remove']('switch-disabled'); this._switch.setAttribute('aria-disabled', disabled); }
remove switch form DOM and show the checkbox @public
setSwitchDisabled
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function setJackPosition() { let offset = parseInt(window.getComputedStyle(this._switch).width) - parseInt(window.getComputedStyle(this._jack).width); this._jack.style.left = this._el.checked ? offset+'px' : 0; }
remove switch form DOM and show the checkbox @public
setJackPosition
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function setJackText() { if(!this._options.showText)return; this._jack.innerHTML = this._el.checked ? this._options.onText : this._options.offText; }
remove switch form DOM and show the checkbox @public
setJackText
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function mergeOptions(a, b) { if(!b)return a; Object.keys(b).forEach(key => { a[key] = b[key]; }); return a; }
remove switch form DOM and show the checkbox @public
mergeOptions
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function bindEvents(events, sw) { for(let[value, el] of events){ value = value.split(' '); (function (event, func) { el.addEventListener(event, switchEventsHandles[func]) })(value[0], value[1]); } }
remove switch form DOM and show the checkbox @public
bindEvents
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
function unbindEvents(events,sw) { for(let[value, el] of events){ value = value.split(' '); (function (event, func) { console.log(); el.removeEventListener(event, switchEventsHandles[func]); })(value[0], value[1]); } }
remove switch form DOM and show the checkbox @public
unbindEvents
javascript
weatherstar/switch
src/switch.js
https://github.com/weatherstar/switch/blob/master/src/switch.js
MIT
async function start() { // Make sure the database tables are up to date await models.sequelize.sync({ force: true }); // Create sample data const foo = await models.User.create({ name: 'Foo' }); const bar = await models.User.create({ name: 'Bar' }); await foo.createPet({ name: 'Bat' }); await bar.create...
DISCLAIMER: using sequelize#sync is not recommended for production use. Please, please use migrations. This method of creating a database is used in this demo for simplicity's sake.
start
javascript
mickhansen/graphql-sequelize
examples/graphql-yoga/src/index.js
https://github.com/mickhansen/graphql-sequelize/blob/master/examples/graphql-yoga/src/index.js
MIT
toCursor = function (item, index) { const model = getModelOfInstance(item); const id = model ? typeof model.primaryKeyAttribute === 'string' ? item[model.primaryKeyAttribute] : null : item[Object.keys(item)[0]]; return base64(JSON.stringify([id, index])); }
Creates a cursor given a item returned from the Database @param {Object} item sequelize row @param {Integer} index the index of this item within the results, 0 indexed @return {String} The Base64 encoded cursor string
toCursor
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
toCursor = function (item, index) { const model = getModelOfInstance(item); const id = model ? typeof model.primaryKeyAttribute === 'string' ? item[model.primaryKeyAttribute] : null : item[Object.keys(item)[0]]; return base64(JSON.stringify([id, index])); }
Creates a cursor given a item returned from the Database @param {Object} item sequelize row @param {Integer} index the index of this item within the results, 0 indexed @return {String} The Base64 encoded cursor string
toCursor
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
fromCursor = function (cursor) { let [id, index] = JSON.parse(unbase64(cursor)); return { id, index }; }
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
fromCursor
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
fromCursor = function (cursor) { let [id, index] = JSON.parse(unbase64(cursor)); return { id, index }; }
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
fromCursor
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
argsToWhere = function (args) { let result = {}; if (where === undefined) return result; _.each(args, (value, key) => { if (ignoreArgs && key in ignoreArgs) return; Object.assign(result, where(key, value, result)); }); return replaceWhereOperators(result); }
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
argsToWhere
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
argsToWhere = function (args) { let result = {}; if (where === undefined) return result; _.each(args, (value, key) => { if (ignoreArgs && key in ignoreArgs) return; Object.assign(result, where(key, value, result)); }); return replaceWhereOperators(result); }
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
argsToWhere
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
resolveEdge = function (item, index, queriedCursor, sourceArgs = {}, source) { let startIndex = null; if (queriedCursor) startIndex = Number(queriedCursor.index); if (startIndex !== null) { startIndex++; } else { startIndex = 0; } return { cursor: toCursor(item, index + startI...
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
resolveEdge
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
resolveEdge = function (item, index, queriedCursor, sourceArgs = {}, source) { let startIndex = null; if (queriedCursor) startIndex = Number(queriedCursor.index); if (startIndex !== null) { startIndex++; } else { startIndex = 0; } return { cursor: toCursor(item, index + startI...
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
resolveEdge
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
resolveConnection = (source, args, context, info) => { var fieldNodes = info.fieldASTs || info.fieldNodes; if (simplifyAST(fieldNodes[0], info).fields.edges) { return $resolver(source, args, context, info); } return after({ source, args, where: argsToWhere(args) }, args, con...
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
resolveConnection
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
resolveConnection = (source, args, context, info) => { var fieldNodes = info.fieldASTs || info.fieldNodes; if (simplifyAST(fieldNodes[0], info).fields.edges) { return $resolver(source, args, context, info); } return after({ source, args, where: argsToWhere(args) }, args, con...
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
resolveConnection
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
function createConnection({ name, nodeType, target: targetMaybeThunk, orderBy: orderByEnum, before, after, connectionFields, edgeFields, where }) { const { edgeType, connectionType } = connectionDefinitions({ name, nodeType, connectionFields, edgeFields }); let $connec...
Decode a cursor into its component parts @param {String} cursor Base64 encoded cursor @return {Object} Object containing ID and index
createConnection
javascript
mickhansen/graphql-sequelize
src/relay.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/relay.js
MIT
function replaceKeyDeep(obj, keyMap) { return Object.getOwnPropertySymbols(obj).concat(Object.keys(obj)).reduce((memo, key)=> { // determine which key we are going to use let targetKey = keyMap[key] ? keyMap[key] : key; if (Array.isArray(obj[key])) { // recurse if an array memo[targetKey] = ...
Replace a key deeply in an object @param obj @param keyMap @returns {Object}
replaceKeyDeep
javascript
mickhansen/graphql-sequelize
src/replaceWhereOperators.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/replaceWhereOperators.js
MIT
function replaceWhereOperators(where) { return replaceKeyDeep(where, sequelizeOps); }
Replace the where arguments object and return the sequelize compatible version. @param where arguments object in GraphQL Safe format meaning no leading "$" chars. @returns {Object}
replaceWhereOperators
javascript
mickhansen/graphql-sequelize
src/replaceWhereOperators.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/replaceWhereOperators.js
MIT
function mapType(mapFunc) { customTypeMapper = mapFunc; }
A function to set a custom mapping of types @param {Function} mapFunc
mapType
javascript
mickhansen/graphql-sequelize
src/typeMapper.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/typeMapper.js
MIT
function sanitizeEnumValue(value) { return value .trim() .replace(/([^_a-zA-Z0-9])/g, (_, p) => specialCharsMap.get(p) || ' ') .split(' ') .map((v, i) => i ? _.upperFirst(v) : v) .join('') .replace(/(^\d)/, '_$1'); }
Checks the type of the sequelize data type and returns the corresponding type in GraphQL @param {Object} sequelizeType @param {Object} sequelizeTypes @return {Function} GraphQL type declaration
sanitizeEnumValue
javascript
mickhansen/graphql-sequelize
src/typeMapper.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/typeMapper.js
MIT
serialize(d) { if (!d) { return null; } if (d instanceof Date) { return d.toISOString(); } return d; }
serialize @param {Date} d Date obj @return {String} Serialised date object
serialize
javascript
mickhansen/graphql-sequelize
src/types/dateType.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/types/dateType.js
MIT
parseValue(value) { try { if (!value) { return null; } return new Date(value); } catch (e) { return null; } }
parseValue @param {String} value date string @return {Date} Date object
parseValue
javascript
mickhansen/graphql-sequelize
src/types/dateType.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/types/dateType.js
MIT
parseLiteral(ast) { return new Date(ast.value); }
parseValue @param {String} value date string @return {Date} Date object
parseLiteral
javascript
mickhansen/graphql-sequelize
src/types/dateType.js
https://github.com/mickhansen/graphql-sequelize/blob/master/src/types/dateType.js
MIT
function strip(start, end) { return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng - end); }
/) { var $0 = $$.length - 1; switch (yystate) { case 1: return $$[$0 - 1]; break; case 2: this.$ = yy.prepareProgram($$[$0]); break; case 3: ...
strip
javascript
goofychris/art-template
example/web-test-speed/js/handlebars.js
https://github.com/goofychris/art-template/blob/master/example/web-test-speed/js/handlebars.js
MIT
function Parser() { this.yy = {}; }
/) { var $0 = $$.length - 1; switch (yystate) { case 1: return $$[$0 - 1]; break; case 2: this.$ = yy.prepareProgram($$[$0]); break; case 3: ...
Parser
javascript
goofychris/art-template
example/web-test-speed/js/handlebars.js
https://github.com/goofychris/art-template/blob/master/example/web-test-speed/js/handlebars.js
MIT
function r(e,t){var n={absolute:t.options.explicitRoot,relative:!t.options.explicitRoot&&t.options.explicitTarget, fromBase:t.options.relativeTo};return n.absolute||n.relative?(n.absolute&&t.options.explicitTarget&&t.warnings.push("Both 'root' and output file given so rebasing URLs as absolute paths"),n.absolute&&(n.to...
/",SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',TEMPLATE_QUOTE:"`",REGEXP:"//g"},f=n.BRACKETS={"(":")","{":"}","[":"]"},d={")":"(","}":"{","]":"["};n.parse=r,n.parseUntil=i,n.parseChar=o,n.defaultState=function(){return new s},s.prototype.current=function(){return this.stack[this.stack.length-1]},s.prototype.isString=function(){r...
r
javascript
goofychris/art-template
example/web-test-speed/js/pug.min.js
https://github.com/goofychris/art-template/blob/master/example/web-test-speed/js/pug.min.js
MIT
function r(e,t){for(var n=[],r=0;r<t;r++)n.push("a"+r) ;var i=["return function ("+n.join(",")+") {","var self = this;","return new Promise(function (rs, rj) {","var res = fn.call(",["self"].concat(n).concat([a]).join(","),");","if (res &&",'(typeof res === "object" || typeof res === "function") &&','typeof res.then ==...
/",SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',TEMPLATE_QUOTE:"`",REGEXP:"//g"},f=n.BRACKETS={"(":")","{":"}","[":"]"},d={")":"(","}":"{","]":"["};n.parse=r,n.parseUntil=i,n.parseChar=o,n.defaultState=function(){return new s},s.prototype.current=function(){return this.stack[this.stack.length-1]},s.prototype.isString=function(){r...
r
javascript
goofychris/art-template
example/web-test-speed/js/pug.min.js
https://github.com/goofychris/art-template/blob/master/example/web-test-speed/js/pug.min.js
MIT
function parse(str) { str = String(str); if (str.length > 100) { return; } var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { return; } var n = parseFloat(match[1]); var t...
Parse the given `str` and return milliseconds. @param {String} str @return {Number} @api private
parse
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function fmtShort(ms) { var msAbs = Math.abs(ms); if (msAbs >= d) { return Math.round(ms / d) + 'd'; } if (msAbs >= h) { return Math.round(ms / h) + 'h'; } if (msAbs >= m) { return Math.round(ms / m) + 'm'; } if (msAbs >= s) { return Math.round(ms / s) + 's'; } return ms + 'ms'; }
Short format for `ms`. @param {Number} ms @return {String} @api private
fmtShort
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function fmtLong(ms) { var msAbs = Math.abs(ms); if (msAbs >= d) { return plural(ms, msAbs, d, 'day'); } if (msAbs >= h) { return plural(ms, msAbs, h, 'hour'); } if (msAbs >= m) { return plural(ms, msAbs, m, 'minute'); } if (msAbs >= s) { return plural(ms, msAbs, s, 'second'); } retu...
Long format for `ms`. @param {Number} ms @return {String} @api private
fmtLong
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function useColors() { // NB: In an Electron preload script, document will be defined but not fully // initialized. Since we know we're in Chrome, we'll just detect this case // explicitly if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { retur...
Currently only WebKit-based Web Inspectors, Firefox >= v31, and the Firebug extension (any Firefox version) are known to support "%c" CSS customizations. TODO: add a `localStorage` variable to explicitly enable/disable colors
useColors
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function formatArgs(args) { args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff); if (!this.useColors) { return; } const c = 'color: ' + this.color; args.splice(1, 0, c, 'color: i...
Colorize log arguments if enabled. @api public
formatArgs
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function save(namespaces) { try { if (namespaces) { exports.storage.setItem('debug', namespaces); } else { exports.storage.removeItem('debug'); } } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } }
Save `namespaces`. @param {String} namespaces @api private
save
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function load() { let r; try { r = exports.storage.getItem('debug'); } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } // If debug isn't set in LS, and we're in Electron, try to load $DEBUG if (!r && typeof process !== 'undefined' && 'env' in process) { r = process.env.DEBUG; } ...
Load `namespaces`. @return {String} returns the previously persisted debug modes @api private
load
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function localstorage() { try { // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context // The Browser also has localStorage in the global context. return localStorage; } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } }
Localstorage attempts to return the localstorage. This is necessary because safari throws when a user disables cookies/localstorage and you attempt to access it. @return {LocalStorage} @api private
localstorage
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function setup(env) { createDebug.debug = createDebug; createDebug.default = createDebug; createDebug.coerce = coerce; createDebug.disable = disable; createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = require('ms'); createDebug.destroy = destroy; Object.keys(env).forEach(key =>...
This is the common logic for both the Node.js and web browser implementations of `debug()`.
setup
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function selectColor(namespace) { let hash = 0; for (let i = 0; i < namespace.length; i++) { hash = ((hash << 5) - hash) + namespace.charCodeAt(i); hash |= 0; // Convert to 32bit integer } return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; }
Selects a color for a debug namespace @param {String} namespace The namespace string for the debug instance to be colored @return {Number|String} An ANSI color code for the given namespace @api private
selectColor
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function createDebug(namespace) { let prevTime; let enableOverride = null; let namespacesCache; let enabledCache; function debug(...args) { // Disabled? if (!debug.enabled) { return; } const self = debug; // Set `diff` timestamp const curr = Number(new Date()); const ms = curr - (p...
Create a debugger with the given `namespace`. @param {String} namespace @return {Function} @api public
createDebug
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function debug(...args) { // Disabled? if (!debug.enabled) { return; } const self = debug; // Set `diff` timestamp const curr = Number(new Date()); const ms = curr - (prevTime || curr); self.diff = ms; self.prev = prevTime; self.curr = curr; prevTime = curr; args[0] = createDe...
Create a debugger with the given `namespace`. @param {String} namespace @return {Function} @api public
debug
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; return newDebug; }
Create a debugger with the given `namespace`. @param {String} namespace @return {Function} @api public
extend
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function enable(namespaces) { createDebug.save(namespaces); createDebug.namespaces = namespaces; createDebug.names = []; createDebug.skips = []; let i; const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); const len = split.length; for (i = 0; i < len; i++) { if (!split...
Enables a debug mode by namespaces. This can include modes separated by a colon and wildcards. @param {String} namespaces @api public
enable
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function disable() { const namespaces = [ ...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) ].join(','); createDebug.enable(''); return namespaces; }
Disable debug output. @return {String} namespaces @api public
disable
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function enabled(name) { if (name[name.length - 1] === '*') { return true; } let i; let len; for (i = 0, len = createDebug.skips.length; i < len; i++) { if (createDebug.skips[i].test(name)) { return false; } } for (i = 0, len = createDebug.names.length; i < len; i++) { if (createDebug.n...
Returns true if the given mode name is enabled, false otherwise. @param {String} name @return {Boolean} @api public
enabled
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function toNamespace(regexp) { return regexp.toString() .substring(2, regexp.toString().length - 2) .replace(/\.\*\?$/, '*'); }
Convert regexp to namespace @param {RegExp} regxep @return {String} namespace @api private
toNamespace
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function coerce(val) { if (val instanceof Error) { return val.stack || val.message; } return val; }
Coerce `val`. @param {Mixed} val @return {Mixed} @api private
coerce
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function destroy() { console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); }
XXX DO NOT USE. This is a temporary stub function. XXX It WILL be removed in the next major release.
destroy
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function decode(input) { try { return decodeURIComponent(input.replace(/\+/g, ' ')); } catch (e) { return null; } }
Decode a URI encoded string. @param {String} input The URI encoded string. @returns {String|Null} The decoded string. @api private
decode
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function encode(input) { try { return encodeURIComponent(input); } catch (e) { return null; } }
Attempts to encode a given input. @param {String} input The string that needs to be encoded. @returns {String|Null} The encoded string. @api private
encode
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function querystring(query) { var parser = /([^=?&]+)=?([^&]*)/g , result = {} , part; while (part = parser.exec(query)) { var key = decode(part[1]) , value = decode(part[2]); // // Prevent overriding of existing properties. This ensures that build-in // methods like `toString` or __...
Simple query string parser. @param {String} query The query string that needs to be parsed. @returns {Object} @api public
querystring
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function querystringify(obj, prefix) { prefix = prefix || ''; var pairs = [] , value , key; // // Optionally prefix with a '?' if needed // if ('string' !== typeof prefix) prefix = '?'; for (key in obj) { if (has.call(obj, key)) { value = obj[key]; // // Edge cases where ...
Transform a query string to an object. @param {Object} obj Object that should be transformed. @param {String} prefix Optional prefix. @returns {String} @api public
querystringify
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function trimLeft(str) { return (str ? str : '').toString().replace(controlOrWhitespace, ''); }
Remove control characters and whitespace from the beginning of a string. @param {Object|String} str String to trim. @returns {String} A new string representing `str` stripped of control characters and whitespace from its beginning. @public
trimLeft
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function lolcation(loc) { var globalVar; if (typeof window !== 'undefined') globalVar = window; else if (typeof global !== 'undefined') globalVar = global; else if (typeof self !== 'undefined') globalVar = self; else globalVar = {}; var location = globalVar.location || {}; loc = loc || location; var ...
The location object differs when your code is loaded through a normal page, Worker or through a worker using a blob. And with the blobble begins the trouble as the location object will contain the URL of the blob, not the location of the page where our code is loaded in. The actual origin is encoded in the `pathname` s...
lolcation
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function isSpecial(scheme) { return ( scheme === 'file:' || scheme === 'ftp:' || scheme === 'http:' || scheme === 'https:' || scheme === 'ws:' || scheme === 'wss:' ); }
Check whether a protocol scheme is special. @param {String} The protocol scheme of the URL @return {Boolean} `true` if the protocol scheme is special, else `false` @private
isSpecial
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function extractProtocol(address, location) { address = trimLeft(address); address = address.replace(CRHTLF, ''); location = location || {}; var match = protocolre.exec(address); var protocol = match[1] ? match[1].toLowerCase() : ''; var forwardSlashes = !!match[2]; var otherSlashes = !!match[3]; var s...
Extract protocol information from a URL with/without double slash ("//"). @param {String} address URL we want to extract from. @param {Object} location @return {ProtocolExtract} Extracted information. @private
extractProtocol
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function resolve(relative, base) { if (relative === '') return base; var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/')) , i = path.length , last = path[i - 1] , unshift = false , up = 0; while (i--) { if (path[i] === '.') { path.splice(i, 1); } else if (pa...
Resolve a relative URL pathname against a base URL pathname. @param {String} relative Pathname of the relative URL. @param {String} base Pathname of the base URL. @return {String} Resolved pathname. @private
resolve
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function Url(address, location, parser) { address = trimLeft(address); address = address.replace(CRHTLF, ''); if (!(this instanceof Url)) { return new Url(address, location, parser); } var relative, extracted, parse, instruction, index, key , instructions = rules.slice() , type = typeof location...
The actual URL instance. Instead of returning an object we've opted-in to create an actual constructor as it's much more memory efficient and faster and it pleases my OCD. It is worth noting that we should not use `URL` as class name to prevent clashes with the global URL instance that got introduced in browsers. @co...
Url
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function set(part, value, fn) { var url = this; switch (part) { case 'query': if ('string' === typeof value && value.length) { value = (fn || qs.parse)(value); } url[part] = value; break; case 'port': url[part] = value; if (!required(value, url.protocol)) { ...
This is convenience method for changing properties in the URL instance to insure that they all propagate correctly. @param {String} part Property we need to adjust. @param {Mixed} value The newly assigned value. @param {Boolean|Function} fn When setting the query, it will be the function ...
set
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function toString(stringify) { if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify; var query , url = this , host = url.host , protocol = url.protocol; if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':'; var result = protocol + ((url.prot...
Transform the properties back in to a valid and full URL string. @param {Function} stringify Optional query stringify function. @returns {String} Compiled version of the URL. @public
toString
javascript
sockjs/sockjs-client
dist/sockjs.js
https://github.com/sockjs/sockjs-client/blob/master/dist/sockjs.js
MIT
function require(name){ if (cache[name]) return cache[name].exports; if (modules[name]) return call(name, require); throw new Error('cannot find module "' + name + '"'); }
Require `name`. @param {String} name @api public
require
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function call(id, require){ var m = cache[id] = { exports: {} }; var mod = modules[id]; var name = mod[2]; var fn = mod[0]; var threw = true; try { fn.call(m.exports, function(req){ var dep = modules[id][1][req]; return require(dep || req); }, m, m.exports, outer, mo...
Call module `id` and cache it. @param {Number} id @param {Function} require @return {Function} @api private
call
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function Facade (obj) { obj = clone(obj); if (!obj.hasOwnProperty('timestamp')) obj.timestamp = new Date(); else obj.timestamp = newDate(obj.timestamp); traverse(obj); this.obj = obj; }
Initialize a new `Facade` with an `obj` of arguments. @param {Object} obj
Facade
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function transform(obj){ var cloned = clone(obj); return cloned; }
Return the cloned and traversed object @param {Mixed} obj @return {Mixed}
transform
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function traverse (input, strict) { if (strict === undefined) strict = true; if (is.object(input)) return object(input, strict); if (is.array(input)) return array(input, strict); return input; }
Traverse an object or array, and return a clone with all ISO strings parsed into Date objects. @param {Object} obj @return {Object}
traverse
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function object (obj, strict) { each(obj, function (key, val) { if (isodate.is(val, strict)) { obj[key] = isodate.parse(val); } else if (is.object(val) || is.array(val)) { traverse(val, strict); } }); return obj; }
Object traverser. @param {Object} obj @param {Boolean} strict @return {Object}
object
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function array (arr, strict) { each(arr, function (val, x) { if (is.object(val)) { traverse(val, strict); } else if (isodate.is(val, strict)) { arr[x] = isodate.parse(val); } }); return arr; }
Array traverser. @param {Array} arr @param {Boolean} strict @return {Array}
array
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 isEmpty (val) { if (null == val) return true; if ('number' == typeof val) return 0 === val; if (undefined !== val.length) return 0 === val.length; for (var key in val) if (has.call(val, key)) return false; return true; }
Test whether a value is "empty". @param {Mixed} val @return {Boolean}
isEmpty
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function string(obj, fn) { for (var i = 0; i < obj.length; ++i) { fn(obj.charAt(i), i); } }
Iterate string chars. @param {String} obj @param {Function} fn @api private
string
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function object(obj, fn) { for (var key in obj) { if (has.call(obj, key)) { fn(key, obj[key]); } } }
Iterate object keys. @param {Object} obj @param {Function} fn @api private
object
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function array(obj, fn) { for (var i = 0; i < obj.length; ++i) { fn(obj[i], i); } }
Iterate array-ish. @param {Array|Object} obj @param {Function} fn @api private
array
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function trait(a, b){ return function(){ var traits = this.traits(); var props = this.properties ? this.properties() : {}; return get(traits, 'address.' + a) || get(traits, a) || (b ? get(traits, 'address.' + b) : null) || (b ? get(traits, b) : null) || get(props, ...
Add address getters to `proto`. @param {Function} proto
trait
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function multiple (fn) { return function (obj, path, val, options) { var normalize = options && isFunction(options.normalizer) ? options.normalizer : defaultNormalize; path = normalize(path); var key; var finished = false; while (!finished) loop(); function loop() { for (key in obj) {...
Compose applying the function to a nested key
multiple
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function loop() { for (key in obj) { var normalizedKey = normalize(key); if (0 === path.indexOf(normalizedKey)) { var temp = path.substr(normalizedKey.length); if (temp.charAt(0) === '.' || temp.length === 0) { path = temp.substr(1); var child = obj[key]...
Compose applying the function to a nested key
loop
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function find (obj, key) { if (obj.hasOwnProperty(key)) return obj[key]; }
Find an object by its key find({ first_name : 'Calvin' }, 'firstName')
find
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function del (obj, key) { if (obj.hasOwnProperty(key)) delete obj[key]; return obj; }
Delete a value for a given key del({ a : 'b', x : 'y' }, 'X' }) -> { a : 'b' }
del
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function replace (obj, key, val) { if (obj.hasOwnProperty(key)) obj[key] = val; return obj; }
Replace an objects existing value with a new one replace({ a : 'b' }, 'a', 'c') -> { a : 'c' }
replace
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function defaultNormalize(path) { return path.replace(/[^a-zA-Z0-9\.]+/g, '').toLowerCase(); }
Normalize a `dot.separated.path`. A.HELL(!*&#(!)O_WOR LD.bar => ahelloworldbar @param {String} path @return {String}
defaultNormalize
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT
function isFunction(val) { return typeof val === 'function'; }
Check if a value is a function. @param {*} val @return {boolean} Returns `true` if `val` is a function, otherwise `false`.
isFunction
javascript
segmentio/analytics.js
analytics.js
https://github.com/segmentio/analytics.js/blob/master/analytics.js
MIT