id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
45,600 | mchalapuk/hyper-text-slider | lib/core/phaser.js | nextPhase | function nextPhase(priv) {
setPhase(priv, PHASE_VALUES[(PHASE_VALUES.indexOf(priv.phase) + 1) % PHASE_VALUES.length]);
} | javascript | function nextPhase(priv) {
setPhase(priv, PHASE_VALUES[(PHASE_VALUES.indexOf(priv.phase) + 1) % PHASE_VALUES.length]);
} | [
"function",
"nextPhase",
"(",
"priv",
")",
"{",
"setPhase",
"(",
"priv",
",",
"PHASE_VALUES",
"[",
"(",
"PHASE_VALUES",
".",
"indexOf",
"(",
"priv",
".",
"phase",
")",
"+",
"1",
")",
"%",
"PHASE_VALUES",
".",
"length",
"]",
")",
";",
"}"
]
| Switches phase to next one.
This method is automatically invoked each time a transition ends
on DOM element added as phase trigger.
@fqn Phaser.prototype.nextPhase | [
"Switches",
"phase",
"to",
"next",
"one",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L133-L135 |
45,601 | mchalapuk/hyper-text-slider | lib/core/phaser.js | setPhase | function setPhase(priv, phase) {
check(phase, 'phase').is.oneOf(PHASE_VALUES)();
if (priv.phase !== null) {
priv.elem.classList.remove(priv.phase);
}
priv.phase = phase;
if (phase !== null) {
priv.elem.classList.add(phase);
}
priv.listeners.forEach(function(listener) {
listener(phase);
});
maybeStart(priv);
} | javascript | function setPhase(priv, phase) {
check(phase, 'phase').is.oneOf(PHASE_VALUES)();
if (priv.phase !== null) {
priv.elem.classList.remove(priv.phase);
}
priv.phase = phase;
if (phase !== null) {
priv.elem.classList.add(phase);
}
priv.listeners.forEach(function(listener) {
listener(phase);
});
maybeStart(priv);
} | [
"function",
"setPhase",
"(",
"priv",
",",
"phase",
")",
"{",
"check",
"(",
"phase",
",",
"'phase'",
")",
".",
"is",
".",
"oneOf",
"(",
"PHASE_VALUES",
")",
"(",
")",
";",
"if",
"(",
"priv",
".",
"phase",
"!==",
"null",
")",
"{",
"priv",
".",
"elem",
".",
"classList",
".",
"remove",
"(",
"priv",
".",
"phase",
")",
";",
"}",
"priv",
".",
"phase",
"=",
"phase",
";",
"if",
"(",
"phase",
"!==",
"null",
")",
"{",
"priv",
".",
"elem",
".",
"classList",
".",
"add",
"(",
"phase",
")",
";",
"}",
"priv",
".",
"listeners",
".",
"forEach",
"(",
"function",
"(",
"listener",
")",
"{",
"listener",
"(",
"phase",
")",
";",
"}",
")",
";",
"maybeStart",
"(",
"priv",
")",
";",
"}"
]
| Changes current phase.
Invoking this method will result in setting CSS class name
of requested phase on container element.
@param {String} phase desired phase
@fqn Phaser.prototype.setPhase | [
"Changes",
"current",
"phase",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L146-L160 |
45,602 | mchalapuk/hyper-text-slider | lib/core/phaser.js | addPhaseTrigger | function addPhaseTrigger(priv, target, propertyName) {
check(target, 'target').is.anEventTarget();
var property = propertyName || 'transform';
check(property, 'property').is.aString();
if (property === 'transform') {
property = feature.transformPropertyName;
}
priv.phaseTriggers.put(property, target);
maybeStart(priv);
} | javascript | function addPhaseTrigger(priv, target, propertyName) {
check(target, 'target').is.anEventTarget();
var property = propertyName || 'transform';
check(property, 'property').is.aString();
if (property === 'transform') {
property = feature.transformPropertyName;
}
priv.phaseTriggers.put(property, target);
maybeStart(priv);
} | [
"function",
"addPhaseTrigger",
"(",
"priv",
",",
"target",
",",
"propertyName",
")",
"{",
"check",
"(",
"target",
",",
"'target'",
")",
".",
"is",
".",
"anEventTarget",
"(",
")",
";",
"var",
"property",
"=",
"propertyName",
"||",
"'transform'",
";",
"check",
"(",
"property",
",",
"'property'",
")",
".",
"is",
".",
"aString",
"(",
")",
";",
"if",
"(",
"property",
"===",
"'transform'",
")",
"{",
"property",
"=",
"feature",
".",
"transformPropertyName",
";",
"}",
"priv",
".",
"phaseTriggers",
".",
"put",
"(",
"property",
",",
"target",
")",
";",
"maybeStart",
"(",
"priv",
")",
";",
"}"
]
| Adds passed target to phase triggers.
Phase will be automatically set to next each time a `transitionend` event of matching
**target** and **propertyName** bubbles up to Phaser's container element.
@param {Node} target (typically DOM Element) that will trigger next phase when matched
@param {String} propertyName will trigger next phase when matched (optional, defaults to 'transform')
@precondition **target** has container element as ancestor (see ${link Phaser.prototype.constructor})
@precondition given pair of **target** and **propertyName** is not already a phase trigger
@fqn Phaser.prototype.addPhaseTrigger | [
"Adds",
"passed",
"target",
"to",
"phase",
"triggers",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L175-L185 |
45,603 | mchalapuk/hyper-text-slider | lib/core/phaser.js | addPhaseListener | function addPhaseListener(priv, listener) {
priv.listeners.push(check(listener, 'listener').is.aFunction());
} | javascript | function addPhaseListener(priv, listener) {
priv.listeners.push(check(listener, 'listener').is.aFunction());
} | [
"function",
"addPhaseListener",
"(",
"priv",
",",
"listener",
")",
"{",
"priv",
".",
"listeners",
".",
"push",
"(",
"check",
"(",
"listener",
",",
"'listener'",
")",
".",
"is",
".",
"aFunction",
"(",
")",
")",
";",
"}"
]
| Adds a listener that will be notified on phase changes.
It is used by the ${link Slider} to change styles of dots representing slides.
@param {Function} listener listener to be added
@fqn Phaser.prototype.addPhaseListener | [
"Adds",
"a",
"listener",
"that",
"will",
"be",
"notified",
"on",
"phase",
"changes",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L196-L198 |
45,604 | mchalapuk/hyper-text-slider | lib/core/phaser.js | removePhaseTrigger | function removePhaseTrigger(priv, target, propertyName) {
var property = propertyName || 'transform';
check(property, 'property').is.aString();
var triggerElements = priv.phaseTriggers.get(property);
check(target, 'target').is.instanceOf(EventTarget).and.is.oneOf(triggerElements, 'phase triggers')();
triggerElements.splice(triggerElements.indexOf(target), 1);
} | javascript | function removePhaseTrigger(priv, target, propertyName) {
var property = propertyName || 'transform';
check(property, 'property').is.aString();
var triggerElements = priv.phaseTriggers.get(property);
check(target, 'target').is.instanceOf(EventTarget).and.is.oneOf(triggerElements, 'phase triggers')();
triggerElements.splice(triggerElements.indexOf(target), 1);
} | [
"function",
"removePhaseTrigger",
"(",
"priv",
",",
"target",
",",
"propertyName",
")",
"{",
"var",
"property",
"=",
"propertyName",
"||",
"'transform'",
";",
"check",
"(",
"property",
",",
"'property'",
")",
".",
"is",
".",
"aString",
"(",
")",
";",
"var",
"triggerElements",
"=",
"priv",
".",
"phaseTriggers",
".",
"get",
"(",
"property",
")",
";",
"check",
"(",
"target",
",",
"'target'",
")",
".",
"is",
".",
"instanceOf",
"(",
"EventTarget",
")",
".",
"and",
".",
"is",
".",
"oneOf",
"(",
"triggerElements",
",",
"'phase triggers'",
")",
"(",
")",
";",
"triggerElements",
".",
"splice",
"(",
"triggerElements",
".",
"indexOf",
"(",
"target",
")",
",",
"1",
")",
";",
"}"
]
| Removes passed target from phase triggers.
@param {Node} target that will no longer be used as a phase trigger
@param {String} transitionProperty that will no longer be a trigger (optional, defaults to 'transform')
@precondition given pair of **target** and **propertyName** is registered as phase trigger
@fqn Phaser.prototype.removePhaseTrigger | [
"Removes",
"passed",
"target",
"from",
"phase",
"triggers",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L209-L216 |
45,605 | mchalapuk/hyper-text-slider | lib/core/phaser.js | removePhaseListener | function removePhaseListener(priv, listener) {
check(listener, 'listener').is.aFunction.and.is.oneOf(priv.listeners, 'registered listeners')();
priv.listeners.splice(priv.listeners.indexOf(listener), 1);
} | javascript | function removePhaseListener(priv, listener) {
check(listener, 'listener').is.aFunction.and.is.oneOf(priv.listeners, 'registered listeners')();
priv.listeners.splice(priv.listeners.indexOf(listener), 1);
} | [
"function",
"removePhaseListener",
"(",
"priv",
",",
"listener",
")",
"{",
"check",
"(",
"listener",
",",
"'listener'",
")",
".",
"is",
".",
"aFunction",
".",
"and",
".",
"is",
".",
"oneOf",
"(",
"priv",
".",
"listeners",
",",
"'registered listeners'",
")",
"(",
")",
";",
"priv",
".",
"listeners",
".",
"splice",
"(",
"priv",
".",
"listeners",
".",
"indexOf",
"(",
"listener",
")",
",",
"1",
")",
";",
"}"
]
| Removes passed listener from the phaser.
@param {Function} listener listener to be removed
@fqn Phaser.prototype.removePhaseListener | [
"Removes",
"passed",
"listener",
"from",
"the",
"phaser",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L224-L227 |
45,606 | mchalapuk/hyper-text-slider | lib/core/phaser.js | maybeStart | function maybeStart(priv) {
if (priv.started) {
return;
}
priv.elem.addEventListener(feature.transitionEventName, handleTransitionEnd.bind(null, priv));
priv.started = true;
} | javascript | function maybeStart(priv) {
if (priv.started) {
return;
}
priv.elem.addEventListener(feature.transitionEventName, handleTransitionEnd.bind(null, priv));
priv.started = true;
} | [
"function",
"maybeStart",
"(",
"priv",
")",
"{",
"if",
"(",
"priv",
".",
"started",
")",
"{",
"return",
";",
"}",
"priv",
".",
"elem",
".",
"addEventListener",
"(",
"feature",
".",
"transitionEventName",
",",
"handleTransitionEnd",
".",
"bind",
"(",
"null",
",",
"priv",
")",
")",
";",
"priv",
".",
"started",
"=",
"true",
";",
"}"
]
| Attaches event listener to phasers DOM element, if phaser was not previously started. | [
"Attaches",
"event",
"listener",
"to",
"phasers",
"DOM",
"element",
"if",
"phaser",
"was",
"not",
"previously",
"started",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L241-L247 |
45,607 | mchalapuk/hyper-text-slider | lib/core/phaser.js | handleTransitionEnd | function handleTransitionEnd(priv, evt) {
if (evt.propertyName in priv.phaseTriggers &&
priv.phaseTriggers[evt.propertyName].indexOf(evt.target) !== -1) {
nextPhase(priv);
}
} | javascript | function handleTransitionEnd(priv, evt) {
if (evt.propertyName in priv.phaseTriggers &&
priv.phaseTriggers[evt.propertyName].indexOf(evt.target) !== -1) {
nextPhase(priv);
}
} | [
"function",
"handleTransitionEnd",
"(",
"priv",
",",
"evt",
")",
"{",
"if",
"(",
"evt",
".",
"propertyName",
"in",
"priv",
".",
"phaseTriggers",
"&&",
"priv",
".",
"phaseTriggers",
"[",
"evt",
".",
"propertyName",
"]",
".",
"indexOf",
"(",
"evt",
".",
"target",
")",
"!==",
"-",
"1",
")",
"{",
"nextPhase",
"(",
"priv",
")",
";",
"}",
"}"
]
| Moves to next phase if transition that ended matches one of phase triggers. | [
"Moves",
"to",
"next",
"phase",
"if",
"transition",
"that",
"ended",
"matches",
"one",
"of",
"phase",
"triggers",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/core/phaser.js#L250-L255 |
45,608 | haraldrudell/nodegod | lib/master/streamlabeller.js | logChild | function logChild(child, slogan, write) {
if (child) {
logSocket(child.stdout, slogan, write)
logSocket(child.stderr, slogan, write)
}
} | javascript | function logChild(child, slogan, write) {
if (child) {
logSocket(child.stdout, slogan, write)
logSocket(child.stderr, slogan, write)
}
} | [
"function",
"logChild",
"(",
"child",
",",
"slogan",
",",
"write",
")",
"{",
"if",
"(",
"child",
")",
"{",
"logSocket",
"(",
"child",
".",
"stdout",
",",
"slogan",
",",
"write",
")",
"logSocket",
"(",
"child",
".",
"stderr",
",",
"slogan",
",",
"write",
")",
"}",
"}"
]
| log joint output for a child process | [
"log",
"joint",
"output",
"for",
"a",
"child",
"process"
]
| 3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21 | https://github.com/haraldrudell/nodegod/blob/3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21/lib/master/streamlabeller.js#L10-L15 |
45,609 | Whitebolt/require-extra | tasks/jsdoc-json.js | parseJsDoc | function parseJsDoc(filePath, jsdoc) {
return jsdoc.explain({files:[filePath]}).then(items=>{
const data = {};
items.forEach(item=>{
if (!item.undocumented && !data.hasOwnProperty(item.longname)) {
data[item.longname] = {
name: item.name,
description: item.classdesc || item.description
};
}
});
return data;
});
} | javascript | function parseJsDoc(filePath, jsdoc) {
return jsdoc.explain({files:[filePath]}).then(items=>{
const data = {};
items.forEach(item=>{
if (!item.undocumented && !data.hasOwnProperty(item.longname)) {
data[item.longname] = {
name: item.name,
description: item.classdesc || item.description
};
}
});
return data;
});
} | [
"function",
"parseJsDoc",
"(",
"filePath",
",",
"jsdoc",
")",
"{",
"return",
"jsdoc",
".",
"explain",
"(",
"{",
"files",
":",
"[",
"filePath",
"]",
"}",
")",
".",
"then",
"(",
"items",
"=>",
"{",
"const",
"data",
"=",
"{",
"}",
";",
"items",
".",
"forEach",
"(",
"item",
"=>",
"{",
"if",
"(",
"!",
"item",
".",
"undocumented",
"&&",
"!",
"data",
".",
"hasOwnProperty",
"(",
"item",
".",
"longname",
")",
")",
"{",
"data",
"[",
"item",
".",
"longname",
"]",
"=",
"{",
"name",
":",
"item",
".",
"name",
",",
"description",
":",
"item",
".",
"classdesc",
"||",
"item",
".",
"description",
"}",
";",
"}",
"}",
")",
";",
"return",
"data",
";",
"}",
")",
";",
"}"
]
| Parse an input file for jsDoc and put json results in give output file.
@param {string} filePath File path to parse jsDoc from.
@param {Object} jsdoc The jsdoc class.
@returns {Promise.<Object>} Parsed jsDoc data. | [
"Parse",
"an",
"input",
"file",
"for",
"jsDoc",
"and",
"put",
"json",
"results",
"in",
"give",
"output",
"file",
"."
]
| 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/tasks/jsdoc-json.js#L12-L26 |
45,610 | pierrec/node-ekam | lib/js-ast.js | build | function build (data, cache, scope) {
scope = scope || { var: '' }
return data
.map(function (item) {
return typeof item === 'string'
? item
: Buffer.isBuffer(item)
? item.toString()
: item.run(cache, scope)
})
.join('')
} | javascript | function build (data, cache, scope) {
scope = scope || { var: '' }
return data
.map(function (item) {
return typeof item === 'string'
? item
: Buffer.isBuffer(item)
? item.toString()
: item.run(cache, scope)
})
.join('')
} | [
"function",
"build",
"(",
"data",
",",
"cache",
",",
"scope",
")",
"{",
"scope",
"=",
"scope",
"||",
"{",
"var",
":",
"''",
"}",
"return",
"data",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"typeof",
"item",
"===",
"'string'",
"?",
"item",
":",
"Buffer",
".",
"isBuffer",
"(",
"item",
")",
"?",
"item",
".",
"toString",
"(",
")",
":",
"item",
".",
"run",
"(",
"cache",
",",
"scope",
")",
"}",
")",
".",
"join",
"(",
"''",
")",
"}"
]
| Walk the AST and evaluate the nodes | [
"Walk",
"the",
"AST",
"and",
"evaluate",
"the",
"nodes"
]
| fd36038231c4f49ecae36e25352138cba0ac11aa | https://github.com/pierrec/node-ekam/blob/fd36038231c4f49ecae36e25352138cba0ac11aa/lib/js-ast.js#L16-L28 |
45,611 | redgeoff/sporks | scripts/promise-sporks.js | function (err) {
if (err) {
reject(err);
} else if (arguments.length === 2) { // single param?
resolve(arguments[1]);
} else { // multiple params?
var cbArgsArray = self.toArgsArray(arguments);
resolve(cbArgsArray.slice(1)); // remove err arg
}
} | javascript | function (err) {
if (err) {
reject(err);
} else if (arguments.length === 2) { // single param?
resolve(arguments[1]);
} else { // multiple params?
var cbArgsArray = self.toArgsArray(arguments);
resolve(cbArgsArray.slice(1)); // remove err arg
}
} | [
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"// single param?",
"resolve",
"(",
"arguments",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"// multiple params?",
"var",
"cbArgsArray",
"=",
"self",
".",
"toArgsArray",
"(",
"arguments",
")",
";",
"resolve",
"(",
"cbArgsArray",
".",
"slice",
"(",
"1",
")",
")",
";",
"// remove err arg",
"}",
"}"
]
| Define a callback and add it to the arguments | [
"Define",
"a",
"callback",
"and",
"add",
"it",
"to",
"the",
"arguments"
]
| de1f0b603f2bc82c973d76fb662da8a0d295da90 | https://github.com/redgeoff/sporks/blob/de1f0b603f2bc82c973d76fb662da8a0d295da90/scripts/promise-sporks.js#L57-L66 |
|
45,612 | feedhenry/fh-mbaas-client | lib/admin/stats/stats.js | history | function history(params, cb) {
params.resourcePath = config.addURIParams(constants.STATS_BASE_PATH + "/history", params);
params.method = 'POST';
params.data = params.data || {};
mbaasRequest.admin(params, cb);
} | javascript | function history(params, cb) {
params.resourcePath = config.addURIParams(constants.STATS_BASE_PATH + "/history", params);
params.method = 'POST';
params.data = params.data || {};
mbaasRequest.admin(params, cb);
} | [
"function",
"history",
"(",
"params",
",",
"cb",
")",
"{",
"params",
".",
"resourcePath",
"=",
"config",
".",
"addURIParams",
"(",
"constants",
".",
"STATS_BASE_PATH",
"+",
"\"/history\"",
",",
"params",
")",
";",
"params",
".",
"method",
"=",
"'POST'",
";",
"params",
".",
"data",
"=",
"params",
".",
"data",
"||",
"{",
"}",
";",
"mbaasRequest",
".",
"admin",
"(",
"params",
",",
"cb",
")",
";",
"}"
]
| Stats history post request to an MBaaS
@param params
@param cb | [
"Stats",
"history",
"post",
"request",
"to",
"an",
"MBaaS"
]
| 2d5a9cbb32e1b2464d71ffa18513358fea388859 | https://github.com/feedhenry/fh-mbaas-client/blob/2d5a9cbb32e1b2464d71ffa18513358fea388859/lib/admin/stats/stats.js#L11-L16 |
45,613 | baskerville/ciebase | src/matrix.js | transpose | function transpose (M) {
return (
[[M[0][0], M[1][0], M[2][0]],
[M[0][1], M[1][1], M[2][1]],
[M[0][2], M[1][2], M[2][2]]]
);
} | javascript | function transpose (M) {
return (
[[M[0][0], M[1][0], M[2][0]],
[M[0][1], M[1][1], M[2][1]],
[M[0][2], M[1][2], M[2][2]]]
);
} | [
"function",
"transpose",
"(",
"M",
")",
"{",
"return",
"(",
"[",
"[",
"M",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"M",
"[",
"1",
"]",
"[",
"0",
"]",
",",
"M",
"[",
"2",
"]",
"[",
"0",
"]",
"]",
",",
"[",
"M",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"M",
"[",
"1",
"]",
"[",
"1",
"]",
",",
"M",
"[",
"2",
"]",
"[",
"1",
"]",
"]",
",",
"[",
"M",
"[",
"0",
"]",
"[",
"2",
"]",
",",
"M",
"[",
"1",
"]",
"[",
"2",
"]",
",",
"M",
"[",
"2",
"]",
"[",
"2",
"]",
"]",
"]",
")",
";",
"}"
]
| 3x3 matrices operations | [
"3x3",
"matrices",
"operations"
]
| 11508fc4857f114c91a94a12173fcdaf42db52bf | https://github.com/baskerville/ciebase/blob/11508fc4857f114c91a94a12173fcdaf42db52bf/src/matrix.js#L3-L9 |
45,614 | nodecg/bundle-manager | index.js | handleChange | function handleChange(bundleName) {
const bundle = module.exports.find(bundleName);
/* istanbul ignore if: It's rare for `bundle` to be undefined here, but it can happen when using black/whitelisting. */
if (!bundle) {
return;
}
if (backoffTimer) {
log.debug('Backoff active, delaying processing of change detected in', bundleName);
hasChanged[bundleName] = true;
resetBackoffTimer();
} else {
log.debug('Processing change event for', bundleName);
resetBackoffTimer();
let reparsedBundle;
const bundleCfgPath = path.join(root, '/cfg/', bundleName + '.json');
if (fs.existsSync(bundleCfgPath)) {
reparsedBundle = parseBundle(bundle.dir, bundleCfgPath);
} else {
reparsedBundle = parseBundle(bundle.dir);
}
module.exports.add(reparsedBundle);
emitter.emit('bundleChanged', reparsedBundle);
}
} | javascript | function handleChange(bundleName) {
const bundle = module.exports.find(bundleName);
/* istanbul ignore if: It's rare for `bundle` to be undefined here, but it can happen when using black/whitelisting. */
if (!bundle) {
return;
}
if (backoffTimer) {
log.debug('Backoff active, delaying processing of change detected in', bundleName);
hasChanged[bundleName] = true;
resetBackoffTimer();
} else {
log.debug('Processing change event for', bundleName);
resetBackoffTimer();
let reparsedBundle;
const bundleCfgPath = path.join(root, '/cfg/', bundleName + '.json');
if (fs.existsSync(bundleCfgPath)) {
reparsedBundle = parseBundle(bundle.dir, bundleCfgPath);
} else {
reparsedBundle = parseBundle(bundle.dir);
}
module.exports.add(reparsedBundle);
emitter.emit('bundleChanged', reparsedBundle);
}
} | [
"function",
"handleChange",
"(",
"bundleName",
")",
"{",
"const",
"bundle",
"=",
"module",
".",
"exports",
".",
"find",
"(",
"bundleName",
")",
";",
"/* istanbul ignore if: It's rare for `bundle` to be undefined here, but it can happen when using black/whitelisting. */",
"if",
"(",
"!",
"bundle",
")",
"{",
"return",
";",
"}",
"if",
"(",
"backoffTimer",
")",
"{",
"log",
".",
"debug",
"(",
"'Backoff active, delaying processing of change detected in'",
",",
"bundleName",
")",
";",
"hasChanged",
"[",
"bundleName",
"]",
"=",
"true",
";",
"resetBackoffTimer",
"(",
")",
";",
"}",
"else",
"{",
"log",
".",
"debug",
"(",
"'Processing change event for'",
",",
"bundleName",
")",
";",
"resetBackoffTimer",
"(",
")",
";",
"let",
"reparsedBundle",
";",
"const",
"bundleCfgPath",
"=",
"path",
".",
"join",
"(",
"root",
",",
"'/cfg/'",
",",
"bundleName",
"+",
"'.json'",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"bundleCfgPath",
")",
")",
"{",
"reparsedBundle",
"=",
"parseBundle",
"(",
"bundle",
".",
"dir",
",",
"bundleCfgPath",
")",
";",
"}",
"else",
"{",
"reparsedBundle",
"=",
"parseBundle",
"(",
"bundle",
".",
"dir",
")",
";",
"}",
"module",
".",
"exports",
".",
"add",
"(",
"reparsedBundle",
")",
";",
"emitter",
".",
"emit",
"(",
"'bundleChanged'",
",",
"reparsedBundle",
")",
";",
"}",
"}"
]
| Emits a `bundleChanged` event for the given bundle.
@param bundleName {String} | [
"Emits",
"a",
"bundleChanged",
"event",
"for",
"the",
"given",
"bundle",
"."
]
| 11eedf320480ca318da7ad455f31771fb8f44d13 | https://github.com/nodecg/bundle-manager/blob/11eedf320480ca318da7ad455f31771fb8f44d13/index.js#L257-L284 |
45,615 | nodecg/bundle-manager | index.js | extractBundleName | function extractBundleName(filePath) {
const parts = filePath.replace(bundlesPath, '').split(path.sep);
return parts[1];
} | javascript | function extractBundleName(filePath) {
const parts = filePath.replace(bundlesPath, '').split(path.sep);
return parts[1];
} | [
"function",
"extractBundleName",
"(",
"filePath",
")",
"{",
"const",
"parts",
"=",
"filePath",
".",
"replace",
"(",
"bundlesPath",
",",
"''",
")",
".",
"split",
"(",
"path",
".",
"sep",
")",
";",
"return",
"parts",
"[",
"1",
"]",
";",
"}"
]
| Returns the name of a bundle that owns a given path.
@param filePath {String} - The path of the file to extract a bundle name from.
@returns {String} - The name of the bundle that owns this path.
@private | [
"Returns",
"the",
"name",
"of",
"a",
"bundle",
"that",
"owns",
"a",
"given",
"path",
"."
]
| 11eedf320480ca318da7ad455f31771fb8f44d13 | https://github.com/nodecg/bundle-manager/blob/11eedf320480ca318da7ad455f31771fb8f44d13/index.js#L312-L315 |
45,616 | jwhitmarsh/gulp-npm-check | lib/index.js | handleMismatch | function handleMismatch(results, config) {
if (results.length) {
var message = 'Out of date packages: \n' + results.map(function (p) {
return moduleInfo(p);
}).join('\n');
if (config.throw === undefined || config.throw !== undefined && config.throw) {
throw new _gulpUtil.PluginError('gulp-npm-check', {
name: 'NpmCheckError',
message: message
});
} else {
(0, _gulpUtil.log)(_gulpUtil.colors.yellow('gulp-npm-check\n', message));
}
} else {
(0, _gulpUtil.log)('All packages are up to date :)');
}
} | javascript | function handleMismatch(results, config) {
if (results.length) {
var message = 'Out of date packages: \n' + results.map(function (p) {
return moduleInfo(p);
}).join('\n');
if (config.throw === undefined || config.throw !== undefined && config.throw) {
throw new _gulpUtil.PluginError('gulp-npm-check', {
name: 'NpmCheckError',
message: message
});
} else {
(0, _gulpUtil.log)(_gulpUtil.colors.yellow('gulp-npm-check\n', message));
}
} else {
(0, _gulpUtil.log)('All packages are up to date :)');
}
} | [
"function",
"handleMismatch",
"(",
"results",
",",
"config",
")",
"{",
"if",
"(",
"results",
".",
"length",
")",
"{",
"var",
"message",
"=",
"'Out of date packages: \\n'",
"+",
"results",
".",
"map",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"moduleInfo",
"(",
"p",
")",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
";",
"if",
"(",
"config",
".",
"throw",
"===",
"undefined",
"||",
"config",
".",
"throw",
"!==",
"undefined",
"&&",
"config",
".",
"throw",
")",
"{",
"throw",
"new",
"_gulpUtil",
".",
"PluginError",
"(",
"'gulp-npm-check'",
",",
"{",
"name",
":",
"'NpmCheckError'",
",",
"message",
":",
"message",
"}",
")",
";",
"}",
"else",
"{",
"(",
"0",
",",
"_gulpUtil",
".",
"log",
")",
"(",
"_gulpUtil",
".",
"colors",
".",
"yellow",
"(",
"'gulp-npm-check\\n'",
",",
"message",
")",
")",
";",
"}",
"}",
"else",
"{",
"(",
"0",
",",
"_gulpUtil",
".",
"log",
")",
"(",
"'All packages are up to date :)'",
")",
";",
"}",
"}"
]
| do things with results
@param {array} results results from npm-check
@param {config} config object
Default method
@param {!config} config object
@param {Function} cb callback | [
"do",
"things",
"with",
"results"
]
| be399d571c4b795fcd9aa0c1495aa1e34781557f | https://github.com/jwhitmarsh/gulp-npm-check/blob/be399d571c4b795fcd9aa0c1495aa1e34781557f/lib/index.js#L95-L111 |
45,617 | vladaspasic/ember-cli-data-validation | addon/validator.js | format | function format(str, formats) {
let cachedFormats = formats;
if (!Ember.isArray(cachedFormats) || arguments.length > 2) {
cachedFormats = new Array(arguments.length - 1);
for (let i = 1, l = arguments.length; i < l; i++) {
cachedFormats[i - 1] = arguments[i];
}
}
let idx = 0;
return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++;
s = cachedFormats[argIndex];
return (s === null) ? '(null)' : (s === undefined) ? '' : Ember.inspect(s);
});
} | javascript | function format(str, formats) {
let cachedFormats = formats;
if (!Ember.isArray(cachedFormats) || arguments.length > 2) {
cachedFormats = new Array(arguments.length - 1);
for (let i = 1, l = arguments.length; i < l; i++) {
cachedFormats[i - 1] = arguments[i];
}
}
let idx = 0;
return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++;
s = cachedFormats[argIndex];
return (s === null) ? '(null)' : (s === undefined) ? '' : Ember.inspect(s);
});
} | [
"function",
"format",
"(",
"str",
",",
"formats",
")",
"{",
"let",
"cachedFormats",
"=",
"formats",
";",
"if",
"(",
"!",
"Ember",
".",
"isArray",
"(",
"cachedFormats",
")",
"||",
"arguments",
".",
"length",
">",
"2",
")",
"{",
"cachedFormats",
"=",
"new",
"Array",
"(",
"arguments",
".",
"length",
"-",
"1",
")",
";",
"for",
"(",
"let",
"i",
"=",
"1",
",",
"l",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"cachedFormats",
"[",
"i",
"-",
"1",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"}",
"let",
"idx",
"=",
"0",
";",
"return",
"str",
".",
"replace",
"(",
"/",
"%@([0-9]+)?",
"/",
"g",
",",
"function",
"(",
"s",
",",
"argIndex",
")",
"{",
"argIndex",
"=",
"(",
"argIndex",
")",
"?",
"parseInt",
"(",
"argIndex",
",",
"10",
")",
"-",
"1",
":",
"idx",
"++",
";",
"s",
"=",
"cachedFormats",
"[",
"argIndex",
"]",
";",
"return",
"(",
"s",
"===",
"null",
")",
"?",
"'(null)'",
":",
"(",
"s",
"===",
"undefined",
")",
"?",
"''",
":",
"Ember",
".",
"inspect",
"(",
"s",
")",
";",
"}",
")",
";",
"}"
]
| Implement Ember.String.fmt function, to avoid depreciation warnings | [
"Implement",
"Ember",
".",
"String",
".",
"fmt",
"function",
"to",
"avoid",
"depreciation",
"warnings"
]
| 08ee8694b9276bf7cbb40e8bc69c52592bb512d3 | https://github.com/vladaspasic/ember-cli-data-validation/blob/08ee8694b9276bf7cbb40e8bc69c52592bb512d3/addon/validator.js#L4-L21 |
45,618 | vladaspasic/ember-cli-data-validation | addon/validator.js | function() {
const message = this.get('message');
const label = this.get('attributeLabel');
Ember.assert('Message must be defined for this Validator', Ember.isPresent(message));
const args = Array.prototype.slice.call(arguments);
args.unshift(label);
args.unshift(message);
return format.apply(null, args);
} | javascript | function() {
const message = this.get('message');
const label = this.get('attributeLabel');
Ember.assert('Message must be defined for this Validator', Ember.isPresent(message));
const args = Array.prototype.slice.call(arguments);
args.unshift(label);
args.unshift(message);
return format.apply(null, args);
} | [
"function",
"(",
")",
"{",
"const",
"message",
"=",
"this",
".",
"get",
"(",
"'message'",
")",
";",
"const",
"label",
"=",
"this",
".",
"get",
"(",
"'attributeLabel'",
")",
";",
"Ember",
".",
"assert",
"(",
"'Message must be defined for this Validator'",
",",
"Ember",
".",
"isPresent",
"(",
"message",
")",
")",
";",
"const",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"args",
".",
"unshift",
"(",
"label",
")",
";",
"args",
".",
"unshift",
"(",
"message",
")",
";",
"return",
"format",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}"
]
| Formats the validation error message.
All arguments passed to this function would be used by the
`Ember.String.fmt` method to format the message.
@method format
@return {String} | [
"Formats",
"the",
"validation",
"error",
"message",
"."
]
| 08ee8694b9276bf7cbb40e8bc69c52592bb512d3 | https://github.com/vladaspasic/ember-cli-data-validation/blob/08ee8694b9276bf7cbb40e8bc69c52592bb512d3/addon/validator.js#L94-L106 |
|
45,619 | theboyWhoCriedWoolf/transition-manager | src/utils/unique.js | unique | function unique( target, arrays )
{
target = target || [];
var combined = target.concat( arrays );
target = [];
var len = combined.length,
i = -1,
ObjRef;
while(++i < len) {
ObjRef = combined[ i ];
if( target.indexOf( ObjRef ) === -1 && ObjRef !== '' & ObjRef !== (null || undefined) ) {
target[ target.length ] = ObjRef;
}
}
return target;
} | javascript | function unique( target, arrays )
{
target = target || [];
var combined = target.concat( arrays );
target = [];
var len = combined.length,
i = -1,
ObjRef;
while(++i < len) {
ObjRef = combined[ i ];
if( target.indexOf( ObjRef ) === -1 && ObjRef !== '' & ObjRef !== (null || undefined) ) {
target[ target.length ] = ObjRef;
}
}
return target;
} | [
"function",
"unique",
"(",
"target",
",",
"arrays",
")",
"{",
"target",
"=",
"target",
"||",
"[",
"]",
";",
"var",
"combined",
"=",
"target",
".",
"concat",
"(",
"arrays",
")",
";",
"target",
"=",
"[",
"]",
";",
"var",
"len",
"=",
"combined",
".",
"length",
",",
"i",
"=",
"-",
"1",
",",
"ObjRef",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"ObjRef",
"=",
"combined",
"[",
"i",
"]",
";",
"if",
"(",
"target",
".",
"indexOf",
"(",
"ObjRef",
")",
"===",
"-",
"1",
"&&",
"ObjRef",
"!==",
"''",
"&",
"ObjRef",
"!==",
"(",
"null",
"||",
"undefined",
")",
")",
"{",
"target",
"[",
"target",
".",
"length",
"]",
"=",
"ObjRef",
";",
"}",
"}",
"return",
"target",
";",
"}"
]
| join two arrays and prevent duplication
@param {array} target
@param {array} arrays
@return {array} | [
"join",
"two",
"arrays",
"and",
"prevent",
"duplication"
]
| a20fda0bb07c0098bf709ea03770b1ee2a855655 | https://github.com/theboyWhoCriedWoolf/transition-manager/blob/a20fda0bb07c0098bf709ea03770b1ee2a855655/src/utils/unique.js#L10-L27 |
45,620 | ecliptic/webpack-blocks-html | lib/index.js | html | function html(options) {
return Object.assign(function (context) {
var defaultOpts = {
filename: 'index.html',
template: 'templates/index.html',
showErrors: false
};
// Merge the provided html config into the context
var html = context.html || defaultOpts;
/* Warning: Thar be mutation ahead! */
/* eslint-disable fp/no-mutation */
context.html = (0, _deepmerge2.default)(html, options, { clone: true });
/* eslint-enable fp/no-mutation */
// Return empty config snippet (configuration will be created by the post hook)
return {};
}, { post: postConfig });
} | javascript | function html(options) {
return Object.assign(function (context) {
var defaultOpts = {
filename: 'index.html',
template: 'templates/index.html',
showErrors: false
};
// Merge the provided html config into the context
var html = context.html || defaultOpts;
/* Warning: Thar be mutation ahead! */
/* eslint-disable fp/no-mutation */
context.html = (0, _deepmerge2.default)(html, options, { clone: true });
/* eslint-enable fp/no-mutation */
// Return empty config snippet (configuration will be created by the post hook)
return {};
}, { post: postConfig });
} | [
"function",
"html",
"(",
"options",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"function",
"(",
"context",
")",
"{",
"var",
"defaultOpts",
"=",
"{",
"filename",
":",
"'index.html'",
",",
"template",
":",
"'templates/index.html'",
",",
"showErrors",
":",
"false",
"}",
";",
"// Merge the provided html config into the context",
"var",
"html",
"=",
"context",
".",
"html",
"||",
"defaultOpts",
";",
"/* Warning: Thar be mutation ahead! */",
"/* eslint-disable fp/no-mutation */",
"context",
".",
"html",
"=",
"(",
"0",
",",
"_deepmerge2",
".",
"default",
")",
"(",
"html",
",",
"options",
",",
"{",
"clone",
":",
"true",
"}",
")",
";",
"/* eslint-enable fp/no-mutation */",
"// Return empty config snippet (configuration will be created by the post hook)",
"return",
"{",
"}",
";",
"}",
",",
"{",
"post",
":",
"postConfig",
"}",
")",
";",
"}"
]
| Webpack block for html-webpack-plugin
@see https://github.com/ampedandwired/html-webpack-plugin | [
"Webpack",
"block",
"for",
"html",
"-",
"webpack",
"-",
"plugin"
]
| 6bb540916730177c88b4cfc922eee5d446da7646 | https://github.com/ecliptic/webpack-blocks-html/blob/6bb540916730177c88b4cfc922eee5d446da7646/lib/index.js#L22-L41 |
45,621 | ZeroNetJS/zeronet-swarm | src/zero/index.js | ZNV2Swarm | function ZNV2Swarm (opt, protocol, zeronet, lp2p) {
const self = this
self.proto = self.protocol = new ZProtocol({
crypto: opt.crypto,
id: opt.id
}, zeronet)
log('creating zeronet swarm')
const tr = self.transport = {}
self.multiaddrs = (opt.listen || []).map(m => multiaddr(m));
(opt.transports || []).forEach(transport => {
tr[transport.tag || transport.constructor.name] = transport
if (!transport.listeners) {
transport.listeners = []
}
})
TRANSPORT(self)
DIAL(self, lp2p)
self.advertise = {
ip: null,
port: null,
port_open: null
}
let nat
if (opt.nat) nat = self.nat = new NAT(self, opt)
self.start = cb => series([
self.listen,
nat ? nat.doDefault : cb => cb()
], cb)
self.stop = cb => series([
self.unlisten
], cb)
} | javascript | function ZNV2Swarm (opt, protocol, zeronet, lp2p) {
const self = this
self.proto = self.protocol = new ZProtocol({
crypto: opt.crypto,
id: opt.id
}, zeronet)
log('creating zeronet swarm')
const tr = self.transport = {}
self.multiaddrs = (opt.listen || []).map(m => multiaddr(m));
(opt.transports || []).forEach(transport => {
tr[transport.tag || transport.constructor.name] = transport
if (!transport.listeners) {
transport.listeners = []
}
})
TRANSPORT(self)
DIAL(self, lp2p)
self.advertise = {
ip: null,
port: null,
port_open: null
}
let nat
if (opt.nat) nat = self.nat = new NAT(self, opt)
self.start = cb => series([
self.listen,
nat ? nat.doDefault : cb => cb()
], cb)
self.stop = cb => series([
self.unlisten
], cb)
} | [
"function",
"ZNV2Swarm",
"(",
"opt",
",",
"protocol",
",",
"zeronet",
",",
"lp2p",
")",
"{",
"const",
"self",
"=",
"this",
"self",
".",
"proto",
"=",
"self",
".",
"protocol",
"=",
"new",
"ZProtocol",
"(",
"{",
"crypto",
":",
"opt",
".",
"crypto",
",",
"id",
":",
"opt",
".",
"id",
"}",
",",
"zeronet",
")",
"log",
"(",
"'creating zeronet swarm'",
")",
"const",
"tr",
"=",
"self",
".",
"transport",
"=",
"{",
"}",
"self",
".",
"multiaddrs",
"=",
"(",
"opt",
".",
"listen",
"||",
"[",
"]",
")",
".",
"map",
"(",
"m",
"=>",
"multiaddr",
"(",
"m",
")",
")",
";",
"(",
"opt",
".",
"transports",
"||",
"[",
"]",
")",
".",
"forEach",
"(",
"transport",
"=>",
"{",
"tr",
"[",
"transport",
".",
"tag",
"||",
"transport",
".",
"constructor",
".",
"name",
"]",
"=",
"transport",
"if",
"(",
"!",
"transport",
".",
"listeners",
")",
"{",
"transport",
".",
"listeners",
"=",
"[",
"]",
"}",
"}",
")",
"TRANSPORT",
"(",
"self",
")",
"DIAL",
"(",
"self",
",",
"lp2p",
")",
"self",
".",
"advertise",
"=",
"{",
"ip",
":",
"null",
",",
"port",
":",
"null",
",",
"port_open",
":",
"null",
"}",
"let",
"nat",
"if",
"(",
"opt",
".",
"nat",
")",
"nat",
"=",
"self",
".",
"nat",
"=",
"new",
"NAT",
"(",
"self",
",",
"opt",
")",
"self",
".",
"start",
"=",
"cb",
"=>",
"series",
"(",
"[",
"self",
".",
"listen",
",",
"nat",
"?",
"nat",
".",
"doDefault",
":",
"cb",
"=>",
"cb",
"(",
")",
"]",
",",
"cb",
")",
"self",
".",
"stop",
"=",
"cb",
"=>",
"series",
"(",
"[",
"self",
".",
"unlisten",
"]",
",",
"cb",
")",
"}"
]
| ZNv2 swarm using libp2p transports | [
"ZNv2",
"swarm",
"using",
"libp2p",
"transports"
]
| 015deb84d4e8a63518eda71d0e6c986f460a28b2 | https://github.com/ZeroNetJS/zeronet-swarm/blob/015deb84d4e8a63518eda71d0e6c986f460a28b2/src/zero/index.js#L17-L56 |
45,622 | OpenSmartEnvironment/ose | lib/ws/read.js | init | function init(cb) { // {{{2
if (typeof cb !== 'function') {
throw O.log.error(this, 'Callback must be a function', cb);
}
this.stream = new Readable();
this.stream._read = O._.noop;
this.stream.on('error', onError.bind(this));
cb(null, this.stream);
} | javascript | function init(cb) { // {{{2
if (typeof cb !== 'function') {
throw O.log.error(this, 'Callback must be a function', cb);
}
this.stream = new Readable();
this.stream._read = O._.noop;
this.stream.on('error', onError.bind(this));
cb(null, this.stream);
} | [
"function",
"init",
"(",
"cb",
")",
"{",
"// {{{2",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"throw",
"O",
".",
"log",
".",
"error",
"(",
"this",
",",
"'Callback must be a function'",
",",
"cb",
")",
";",
"}",
"this",
".",
"stream",
"=",
"new",
"Readable",
"(",
")",
";",
"this",
".",
"stream",
".",
"_read",
"=",
"O",
".",
"_",
".",
"noop",
";",
"this",
".",
"stream",
".",
"on",
"(",
"'error'",
",",
"onError",
".",
"bind",
"(",
"this",
")",
")",
";",
"cb",
"(",
"null",
",",
"this",
".",
"stream",
")",
";",
"}"
]
| Public {{{1 | [
"Public",
"{{{",
"1"
]
| 2ab051d9db6e77341c40abb9cbdae6ce586917e0 | https://github.com/OpenSmartEnvironment/ose/blob/2ab051d9db6e77341c40abb9cbdae6ce586917e0/lib/ws/read.js#L10-L20 |
45,623 | IonicaBizau/node-fwatcher | lib/index.js | Watcher | function Watcher(path, handler) {
this._ = Fs.watch(path, handler);
this.a_path = Abs(path);
this.handler = handler;
} | javascript | function Watcher(path, handler) {
this._ = Fs.watch(path, handler);
this.a_path = Abs(path);
this.handler = handler;
} | [
"function",
"Watcher",
"(",
"path",
",",
"handler",
")",
"{",
"this",
".",
"_",
"=",
"Fs",
".",
"watch",
"(",
"path",
",",
"handler",
")",
";",
"this",
".",
"a_path",
"=",
"Abs",
"(",
"path",
")",
";",
"this",
".",
"handler",
"=",
"handler",
";",
"}"
]
| Watcher
Creates a new instance of the internal `Watcher`.
@name Watcher
@function
@param {String} path The path to the file.
@param {Function} handler A function called when the file changes. | [
"Watcher",
"Creates",
"a",
"new",
"instance",
"of",
"the",
"internal",
"Watcher",
"."
]
| 44487b1645215aae340df8dafb220d47a36c19ca | https://github.com/IonicaBizau/node-fwatcher/blob/44487b1645215aae340df8dafb220d47a36c19ca/lib/index.js#L17-L21 |
45,624 | IonicaBizau/node-fwatcher | lib/index.js | FileWatcher | function FileWatcher(path, options, callback) {
if (typeof options === "function") {
callback = options;
}
if (typeof options === "boolean") {
options = { once: options };
}
options = Ul.merge(options, {
once: false
});
var watcher = null
, newWatcher = false
, check = function (cb) {
var inter = setInterval(function() {
IsThere(path, function (exists) {
if (!--tries || exists) {
clearInterval(inter);
}
if (exists) {
cb();
}
});
}, 500)
, tries = 5
;
}
, handler = function (ev) {
if (options.once) {
watcher.off();
}
if (newWatcher) { return; }
// Check the rename
if (ev === "rename" && !options.once) {
newWatcher = true;
check(function () {
watcher.off();
watcher._ = FileWatcher(path, options, callback)._;
});
}
callback.call(watcher, null, ev, watcher.a_path);
}
;
try {
watcher = new Watcher(path, handler);
} catch (e) {
callback(e);
}
return watcher;
} | javascript | function FileWatcher(path, options, callback) {
if (typeof options === "function") {
callback = options;
}
if (typeof options === "boolean") {
options = { once: options };
}
options = Ul.merge(options, {
once: false
});
var watcher = null
, newWatcher = false
, check = function (cb) {
var inter = setInterval(function() {
IsThere(path, function (exists) {
if (!--tries || exists) {
clearInterval(inter);
}
if (exists) {
cb();
}
});
}, 500)
, tries = 5
;
}
, handler = function (ev) {
if (options.once) {
watcher.off();
}
if (newWatcher) { return; }
// Check the rename
if (ev === "rename" && !options.once) {
newWatcher = true;
check(function () {
watcher.off();
watcher._ = FileWatcher(path, options, callback)._;
});
}
callback.call(watcher, null, ev, watcher.a_path);
}
;
try {
watcher = new Watcher(path, handler);
} catch (e) {
callback(e);
}
return watcher;
} | [
"function",
"FileWatcher",
"(",
"path",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"\"function\"",
")",
"{",
"callback",
"=",
"options",
";",
"}",
"if",
"(",
"typeof",
"options",
"===",
"\"boolean\"",
")",
"{",
"options",
"=",
"{",
"once",
":",
"options",
"}",
";",
"}",
"options",
"=",
"Ul",
".",
"merge",
"(",
"options",
",",
"{",
"once",
":",
"false",
"}",
")",
";",
"var",
"watcher",
"=",
"null",
",",
"newWatcher",
"=",
"false",
",",
"check",
"=",
"function",
"(",
"cb",
")",
"{",
"var",
"inter",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"IsThere",
"(",
"path",
",",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"!",
"--",
"tries",
"||",
"exists",
")",
"{",
"clearInterval",
"(",
"inter",
")",
";",
"}",
"if",
"(",
"exists",
")",
"{",
"cb",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
",",
"500",
")",
",",
"tries",
"=",
"5",
";",
"}",
",",
"handler",
"=",
"function",
"(",
"ev",
")",
"{",
"if",
"(",
"options",
".",
"once",
")",
"{",
"watcher",
".",
"off",
"(",
")",
";",
"}",
"if",
"(",
"newWatcher",
")",
"{",
"return",
";",
"}",
"// Check the rename",
"if",
"(",
"ev",
"===",
"\"rename\"",
"&&",
"!",
"options",
".",
"once",
")",
"{",
"newWatcher",
"=",
"true",
";",
"check",
"(",
"function",
"(",
")",
"{",
"watcher",
".",
"off",
"(",
")",
";",
"watcher",
".",
"_",
"=",
"FileWatcher",
"(",
"path",
",",
"options",
",",
"callback",
")",
".",
"_",
";",
"}",
")",
";",
"}",
"callback",
".",
"call",
"(",
"watcher",
",",
"null",
",",
"ev",
",",
"watcher",
".",
"a_path",
")",
";",
"}",
";",
"try",
"{",
"watcher",
"=",
"new",
"Watcher",
"(",
"path",
",",
"handler",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
")",
";",
"}",
"return",
"watcher",
";",
"}"
]
| FileWatcher
Creates a new file watcher.
@name FileWatcher
@function
@param {String} path The path to the file.
@param {Boolean|Options} options A boolean value representing the `once`
value or an object containing the following fields:
- `once` (Boolean): If `true`, the handler is deleted after first event.
@param {Function} callback This function will be called when the file is
changed or renamed. The first parameter is the error, the second one is
the evenit name and the third one is the file path.
@return {Watcher} The watcher instance. | [
"FileWatcher",
"Creates",
"a",
"new",
"file",
"watcher",
"."
]
| 44487b1645215aae340df8dafb220d47a36c19ca | https://github.com/IonicaBizau/node-fwatcher/blob/44487b1645215aae340df8dafb220d47a36c19ca/lib/index.js#L51-L110 |
45,625 | thirdcoder/cpu3502 | instr_decode.js | disasm1 | function disasm1(machine_code, offset=0) {
let di = decode_instruction(machine_code[offset]);
let opcode, operand;
let consumed = 1; // 1-tryte opcode, incremented later if operands
if (di.family === 0) {
opcode = invertKv(OP)[di.operation]; // inefficient lookup, but probably doesn't matter
// note: some duplication with cpu read_alu_operand TODO: factor out
// TODO: handle reading beyond end
let decoded_operand = decode_operand(di, machine_code, offset);
operand = stringify_operand(decoded_operand);
consumed += decoded_operand.consumed;
} else if (di.family === 1) {
opcode = 'BR';
opcode += invertKv(FLAGS)[di.flag];
opcode += {'-1':'L', 0:'E', 1:'N'}[di.direction];
opcode += {'-1':'N', 0:'Z', 1:'P'}[di.compare];
if (invertKv(BRANCH_INSTRUCTION_SHORTHANDS)[opcode]) {
// prefer the shorthand if there is one (BRSEZ -> BEQ)
opcode = invertKv(BRANCH_INSTRUCTION_SHORTHANDS)[opcode];
}
let rel_address = machine_code[offset + 1];
if (rel_address === undefined) {
operand = '???'
} else {
if (rel_address > 0) {
// always add +, since makes relativity clearer
operand = '#+' + rel_address.toString();
} else {
operand = '#' + rel_address.toString();
}
}
consumed += 1;
} else if (di.family === -1) {
opcode = invertKv(XOP)[di.operation];
// TODO: undefined opcodes
let decoded_operand = decode_operand(di, machine_code, offset);
operand = stringify_operand(decoded_operand);
consumed += decoded_operand.consumed;
console.log('XOP di.operation',di.operation,XOP_TO_ADDR_MODE[di.operation]);
if (XOP_TO_ADDR_MODE[opcode] !== undefined) {
// some extended opcodes can disassemble to alu special addressing modes
opcode = xop_operation_to_assembly_opcode_string(opcode);
}
}
let asm;
if (operand !== undefined) {
asm = opcode + ' ' + operand;
} else {
asm = opcode;
}
return {asm, consumed};
} | javascript | function disasm1(machine_code, offset=0) {
let di = decode_instruction(machine_code[offset]);
let opcode, operand;
let consumed = 1; // 1-tryte opcode, incremented later if operands
if (di.family === 0) {
opcode = invertKv(OP)[di.operation]; // inefficient lookup, but probably doesn't matter
// note: some duplication with cpu read_alu_operand TODO: factor out
// TODO: handle reading beyond end
let decoded_operand = decode_operand(di, machine_code, offset);
operand = stringify_operand(decoded_operand);
consumed += decoded_operand.consumed;
} else if (di.family === 1) {
opcode = 'BR';
opcode += invertKv(FLAGS)[di.flag];
opcode += {'-1':'L', 0:'E', 1:'N'}[di.direction];
opcode += {'-1':'N', 0:'Z', 1:'P'}[di.compare];
if (invertKv(BRANCH_INSTRUCTION_SHORTHANDS)[opcode]) {
// prefer the shorthand if there is one (BRSEZ -> BEQ)
opcode = invertKv(BRANCH_INSTRUCTION_SHORTHANDS)[opcode];
}
let rel_address = machine_code[offset + 1];
if (rel_address === undefined) {
operand = '???'
} else {
if (rel_address > 0) {
// always add +, since makes relativity clearer
operand = '#+' + rel_address.toString();
} else {
operand = '#' + rel_address.toString();
}
}
consumed += 1;
} else if (di.family === -1) {
opcode = invertKv(XOP)[di.operation];
// TODO: undefined opcodes
let decoded_operand = decode_operand(di, machine_code, offset);
operand = stringify_operand(decoded_operand);
consumed += decoded_operand.consumed;
console.log('XOP di.operation',di.operation,XOP_TO_ADDR_MODE[di.operation]);
if (XOP_TO_ADDR_MODE[opcode] !== undefined) {
// some extended opcodes can disassemble to alu special addressing modes
opcode = xop_operation_to_assembly_opcode_string(opcode);
}
}
let asm;
if (operand !== undefined) {
asm = opcode + ' ' + operand;
} else {
asm = opcode;
}
return {asm, consumed};
} | [
"function",
"disasm1",
"(",
"machine_code",
",",
"offset",
"=",
"0",
")",
"{",
"let",
"di",
"=",
"decode_instruction",
"(",
"machine_code",
"[",
"offset",
"]",
")",
";",
"let",
"opcode",
",",
"operand",
";",
"let",
"consumed",
"=",
"1",
";",
"// 1-tryte opcode, incremented later if operands",
"if",
"(",
"di",
".",
"family",
"===",
"0",
")",
"{",
"opcode",
"=",
"invertKv",
"(",
"OP",
")",
"[",
"di",
".",
"operation",
"]",
";",
"// inefficient lookup, but probably doesn't matter",
"// note: some duplication with cpu read_alu_operand TODO: factor out",
"// TODO: handle reading beyond end",
"let",
"decoded_operand",
"=",
"decode_operand",
"(",
"di",
",",
"machine_code",
",",
"offset",
")",
";",
"operand",
"=",
"stringify_operand",
"(",
"decoded_operand",
")",
";",
"consumed",
"+=",
"decoded_operand",
".",
"consumed",
";",
"}",
"else",
"if",
"(",
"di",
".",
"family",
"===",
"1",
")",
"{",
"opcode",
"=",
"'BR'",
";",
"opcode",
"+=",
"invertKv",
"(",
"FLAGS",
")",
"[",
"di",
".",
"flag",
"]",
";",
"opcode",
"+=",
"{",
"'-1'",
":",
"'L'",
",",
"0",
":",
"'E'",
",",
"1",
":",
"'N'",
"}",
"[",
"di",
".",
"direction",
"]",
";",
"opcode",
"+=",
"{",
"'-1'",
":",
"'N'",
",",
"0",
":",
"'Z'",
",",
"1",
":",
"'P'",
"}",
"[",
"di",
".",
"compare",
"]",
";",
"if",
"(",
"invertKv",
"(",
"BRANCH_INSTRUCTION_SHORTHANDS",
")",
"[",
"opcode",
"]",
")",
"{",
"// prefer the shorthand if there is one (BRSEZ -> BEQ)",
"opcode",
"=",
"invertKv",
"(",
"BRANCH_INSTRUCTION_SHORTHANDS",
")",
"[",
"opcode",
"]",
";",
"}",
"let",
"rel_address",
"=",
"machine_code",
"[",
"offset",
"+",
"1",
"]",
";",
"if",
"(",
"rel_address",
"===",
"undefined",
")",
"{",
"operand",
"=",
"'???'",
"}",
"else",
"{",
"if",
"(",
"rel_address",
">",
"0",
")",
"{",
"// always add +, since makes relativity clearer",
"operand",
"=",
"'#+'",
"+",
"rel_address",
".",
"toString",
"(",
")",
";",
"}",
"else",
"{",
"operand",
"=",
"'#'",
"+",
"rel_address",
".",
"toString",
"(",
")",
";",
"}",
"}",
"consumed",
"+=",
"1",
";",
"}",
"else",
"if",
"(",
"di",
".",
"family",
"===",
"-",
"1",
")",
"{",
"opcode",
"=",
"invertKv",
"(",
"XOP",
")",
"[",
"di",
".",
"operation",
"]",
";",
"// TODO: undefined opcodes",
"let",
"decoded_operand",
"=",
"decode_operand",
"(",
"di",
",",
"machine_code",
",",
"offset",
")",
";",
"operand",
"=",
"stringify_operand",
"(",
"decoded_operand",
")",
";",
"consumed",
"+=",
"decoded_operand",
".",
"consumed",
";",
"console",
".",
"log",
"(",
"'XOP di.operation'",
",",
"di",
".",
"operation",
",",
"XOP_TO_ADDR_MODE",
"[",
"di",
".",
"operation",
"]",
")",
";",
"if",
"(",
"XOP_TO_ADDR_MODE",
"[",
"opcode",
"]",
"!==",
"undefined",
")",
"{",
"// some extended opcodes can disassemble to alu special addressing modes",
"opcode",
"=",
"xop_operation_to_assembly_opcode_string",
"(",
"opcode",
")",
";",
"}",
"}",
"let",
"asm",
";",
"if",
"(",
"operand",
"!==",
"undefined",
")",
"{",
"asm",
"=",
"opcode",
"+",
"' '",
"+",
"operand",
";",
"}",
"else",
"{",
"asm",
"=",
"opcode",
";",
"}",
"return",
"{",
"asm",
",",
"consumed",
"}",
";",
"}"
]
| Disassemble one instruction in machine_code | [
"Disassemble",
"one",
"instruction",
"in",
"machine_code"
]
| af1c0c01f75d03443af572e08f14c994585a277b | https://github.com/thirdcoder/cpu3502/blob/af1c0c01f75d03443af572e08f14c994585a277b/instr_decode.js#L140-L202 |
45,626 | DynoSRC/dynosrc | lib/sources/asset/index.js | function(files, next) {
var i = files.indexOf(id);
if (i < 0) {
return next({
error: 'NOT_FOUND',
description: 'Asset not available: ' + searchDir + id
});
}
next(null, files[i]);
} | javascript | function(files, next) {
var i = files.indexOf(id);
if (i < 0) {
return next({
error: 'NOT_FOUND',
description: 'Asset not available: ' + searchDir + id
});
}
next(null, files[i]);
} | [
"function",
"(",
"files",
",",
"next",
")",
"{",
"var",
"i",
"=",
"files",
".",
"indexOf",
"(",
"id",
")",
";",
"if",
"(",
"i",
"<",
"0",
")",
"{",
"return",
"next",
"(",
"{",
"error",
":",
"'NOT_FOUND'",
",",
"description",
":",
"'Asset not available: '",
"+",
"searchDir",
"+",
"id",
"}",
")",
";",
"}",
"next",
"(",
"null",
",",
"files",
"[",
"i",
"]",
")",
";",
"}"
]
| find Asset for id | [
"find",
"Asset",
"for",
"id"
]
| 1a763c9310b719a51b0df56387970ecd3f08c438 | https://github.com/DynoSRC/dynosrc/blob/1a763c9310b719a51b0df56387970ecd3f08c438/lib/sources/asset/index.js#L24-L35 |
|
45,627 | DynoSRC/dynosrc | lib/sources/asset/index.js | function(dirname, next) {
// could be something
searchDir += dirname + '/';
var revPath = version && (searchDir + version + '.js');
return next(null, revPath || '');
} | javascript | function(dirname, next) {
// could be something
searchDir += dirname + '/';
var revPath = version && (searchDir + version + '.js');
return next(null, revPath || '');
} | [
"function",
"(",
"dirname",
",",
"next",
")",
"{",
"// could be something",
"searchDir",
"+=",
"dirname",
"+",
"'/'",
";",
"var",
"revPath",
"=",
"version",
"&&",
"(",
"searchDir",
"+",
"version",
"+",
"'.js'",
")",
";",
"return",
"next",
"(",
"null",
",",
"revPath",
"||",
"''",
")",
";",
"}"
]
| look up requested tag | [
"look",
"up",
"requested",
"tag"
]
| 1a763c9310b719a51b0df56387970ecd3f08c438 | https://github.com/DynoSRC/dynosrc/blob/1a763c9310b719a51b0df56387970ecd3f08c438/lib/sources/asset/index.js#L37-L43 |
|
45,628 | Rafflecopter/deetoo | lib/Q.js | function(filename, msg, $done) {
var __open = _.bind(fs.open, fs, filename, 'a')
, __write = util.partial.call(fs, fs.write, undefined, msg)
, __close = util.partial.call(fs, fs.close)
async.waterfall([__open, __write, __close], $done)
} | javascript | function(filename, msg, $done) {
var __open = _.bind(fs.open, fs, filename, 'a')
, __write = util.partial.call(fs, fs.write, undefined, msg)
, __close = util.partial.call(fs, fs.close)
async.waterfall([__open, __write, __close], $done)
} | [
"function",
"(",
"filename",
",",
"msg",
",",
"$done",
")",
"{",
"var",
"__open",
"=",
"_",
".",
"bind",
"(",
"fs",
".",
"open",
",",
"fs",
",",
"filename",
",",
"'a'",
")",
",",
"__write",
"=",
"util",
".",
"partial",
".",
"call",
"(",
"fs",
",",
"fs",
".",
"write",
",",
"undefined",
",",
"msg",
")",
",",
"__close",
"=",
"util",
".",
"partial",
".",
"call",
"(",
"fs",
",",
"fs",
".",
"close",
")",
"async",
".",
"waterfall",
"(",
"[",
"__open",
",",
"__write",
",",
"__close",
"]",
",",
"$done",
")",
"}"
]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ Optional Garbage Collection | [
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
"~~",
"Optional",
"Garbage",
"Collection"
]
| 4d7932efeab35e01fa3a584b6c1253b21f0c4515 | https://github.com/Rafflecopter/deetoo/blob/4d7932efeab35e01fa3a584b6c1253b21f0c4515/lib/Q.js#L44-L49 |
|
45,629 | iainvdw/gulp-tasker | index.js | function (opts) {
var options = extend(true, defaults, opts);
requireDir(process.cwd() + options.path, {recurse: options.recurse});
} | javascript | function (opts) {
var options = extend(true, defaults, opts);
requireDir(process.cwd() + options.path, {recurse: options.recurse});
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"options",
"=",
"extend",
"(",
"true",
",",
"defaults",
",",
"opts",
")",
";",
"requireDir",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"options",
".",
"path",
",",
"{",
"recurse",
":",
"options",
".",
"recurse",
"}",
")",
";",
"}"
]
| Load all tasks from the `path` option | [
"Load",
"all",
"tasks",
"from",
"the",
"path",
"option"
]
| 42e48fa62576bd0a91e06407d11aae09053e558a | https://github.com/iainvdw/gulp-tasker/blob/42e48fa62576bd0a91e06407d11aae09053e558a/index.js#L18-L22 |
|
45,630 | iainvdw/gulp-tasker | index.js | function (type, tasks, folder) {
if ( !type ) {
throw Error('Error registering task: Please specify a task type');
}
if ( !tasks ) {
throw Error('Error registering task: Please specify at least one task.');
}
allTasks[type] = allTasks[type] || {tasks: [], requireFolders: !!folder};
if ( !folder && allTasks[type].requireFolders) {
throw Error('Error registering watch type task: Please specify (a) folder(s) to watch.');
}
if ( !!folder ) { // Folder specified, tasks is a watch task
// Convert argument to array if it's no array yet
if ( !(tasks.constructor === Array) ) {
tasks = [tasks];
}
allTasks[type].tasks = allTasks[type].tasks.concat({
tasks: tasks,
folders: folder
});
} else { // Regular tasks
allTasks[type].tasks = allTasks[type].tasks.concat(tasks);
}
} | javascript | function (type, tasks, folder) {
if ( !type ) {
throw Error('Error registering task: Please specify a task type');
}
if ( !tasks ) {
throw Error('Error registering task: Please specify at least one task.');
}
allTasks[type] = allTasks[type] || {tasks: [], requireFolders: !!folder};
if ( !folder && allTasks[type].requireFolders) {
throw Error('Error registering watch type task: Please specify (a) folder(s) to watch.');
}
if ( !!folder ) { // Folder specified, tasks is a watch task
// Convert argument to array if it's no array yet
if ( !(tasks.constructor === Array) ) {
tasks = [tasks];
}
allTasks[type].tasks = allTasks[type].tasks.concat({
tasks: tasks,
folders: folder
});
} else { // Regular tasks
allTasks[type].tasks = allTasks[type].tasks.concat(tasks);
}
} | [
"function",
"(",
"type",
",",
"tasks",
",",
"folder",
")",
"{",
"if",
"(",
"!",
"type",
")",
"{",
"throw",
"Error",
"(",
"'Error registering task: Please specify a task type'",
")",
";",
"}",
"if",
"(",
"!",
"tasks",
")",
"{",
"throw",
"Error",
"(",
"'Error registering task: Please specify at least one task.'",
")",
";",
"}",
"allTasks",
"[",
"type",
"]",
"=",
"allTasks",
"[",
"type",
"]",
"||",
"{",
"tasks",
":",
"[",
"]",
",",
"requireFolders",
":",
"!",
"!",
"folder",
"}",
";",
"if",
"(",
"!",
"folder",
"&&",
"allTasks",
"[",
"type",
"]",
".",
"requireFolders",
")",
"{",
"throw",
"Error",
"(",
"'Error registering watch type task: Please specify (a) folder(s) to watch.'",
")",
";",
"}",
"if",
"(",
"!",
"!",
"folder",
")",
"{",
"// Folder specified, tasks is a watch task",
"// Convert argument to array if it's no array yet",
"if",
"(",
"!",
"(",
"tasks",
".",
"constructor",
"===",
"Array",
")",
")",
"{",
"tasks",
"=",
"[",
"tasks",
"]",
";",
"}",
"allTasks",
"[",
"type",
"]",
".",
"tasks",
"=",
"allTasks",
"[",
"type",
"]",
".",
"tasks",
".",
"concat",
"(",
"{",
"tasks",
":",
"tasks",
",",
"folders",
":",
"folder",
"}",
")",
";",
"}",
"else",
"{",
"// Regular tasks",
"allTasks",
"[",
"type",
"]",
".",
"tasks",
"=",
"allTasks",
"[",
"type",
"]",
".",
"tasks",
".",
"concat",
"(",
"tasks",
")",
";",
"}",
"}"
]
| Register helper to let subtasks register themselves in the 'default' gulp task
@param {String} type Type of task to register
@param {String|Array} tasks Task name to register in 'default' task
@param {String|Array} folder Folder(s) to watch when registering a watch task | [
"Register",
"helper",
"to",
"let",
"subtasks",
"register",
"themselves",
"in",
"the",
"default",
"gulp",
"task"
]
| 42e48fa62576bd0a91e06407d11aae09053e558a | https://github.com/iainvdw/gulp-tasker/blob/42e48fa62576bd0a91e06407d11aae09053e558a/index.js#L31-L61 |
|
45,631 | eps1lon/poe-i18n | scripts/api/util.js | mergeMessages | async function mergeMessages(locale, messages) {
const data_path = path.join(LOCALE_DATA_DIR, `${locale}/api_messages.json`);
let old_messages = {};
try {
old_messages = require(data_path);
} catch (err) {
console.log(`creating new messages for locale ${locale}`);
}
const merged_messages = { ...old_messages, ...messages };
const sorted_messages = Object.entries(merged_messages)
.sort((a, b) => a[0].localeCompare(b[0]))
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
const json = JSON.stringify(sorted_messages, undefined, 2);
await writeFile(data_path, json);
} | javascript | async function mergeMessages(locale, messages) {
const data_path = path.join(LOCALE_DATA_DIR, `${locale}/api_messages.json`);
let old_messages = {};
try {
old_messages = require(data_path);
} catch (err) {
console.log(`creating new messages for locale ${locale}`);
}
const merged_messages = { ...old_messages, ...messages };
const sorted_messages = Object.entries(merged_messages)
.sort((a, b) => a[0].localeCompare(b[0]))
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
const json = JSON.stringify(sorted_messages, undefined, 2);
await writeFile(data_path, json);
} | [
"async",
"function",
"mergeMessages",
"(",
"locale",
",",
"messages",
")",
"{",
"const",
"data_path",
"=",
"path",
".",
"join",
"(",
"LOCALE_DATA_DIR",
",",
"`",
"${",
"locale",
"}",
"`",
")",
";",
"let",
"old_messages",
"=",
"{",
"}",
";",
"try",
"{",
"old_messages",
"=",
"require",
"(",
"data_path",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"locale",
"}",
"`",
")",
";",
"}",
"const",
"merged_messages",
"=",
"{",
"...",
"old_messages",
",",
"...",
"messages",
"}",
";",
"const",
"sorted_messages",
"=",
"Object",
".",
"entries",
"(",
"merged_messages",
")",
".",
"sort",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"a",
"[",
"0",
"]",
".",
"localeCompare",
"(",
"b",
"[",
"0",
"]",
")",
")",
".",
"reduce",
"(",
"(",
"acc",
",",
"[",
"key",
",",
"value",
"]",
")",
"=>",
"{",
"acc",
"[",
"key",
"]",
"=",
"value",
";",
"return",
"acc",
";",
"}",
",",
"{",
"}",
")",
";",
"const",
"json",
"=",
"JSON",
".",
"stringify",
"(",
"sorted_messages",
",",
"undefined",
",",
"2",
")",
";",
"await",
"writeFile",
"(",
"data_path",
",",
"json",
")",
";",
"}"
]
| merges the messages into the api_messages.json under the specified locale
while sorting the resulting json object by keys
@param {*} locale
@param {*} messages | [
"merges",
"the",
"messages",
"into",
"the",
"api_messages",
".",
"json",
"under",
"the",
"specified",
"locale",
"while",
"sorting",
"the",
"resulting",
"json",
"object",
"by",
"keys"
]
| fa92cc4a2be7f321f07a5dba28135db03dc0bc38 | https://github.com/eps1lon/poe-i18n/blob/fa92cc4a2be7f321f07a5dba28135db03dc0bc38/scripts/api/util.js#L22-L39 |
45,632 | emmetio/math-expression | lib/number.js | consumeForward | function consumeForward(stream) {
const start = stream.pos;
if (stream.eat(DOT) && stream.eatWhile(isNumber)) {
// short decimal notation: .025
return true;
}
if (stream.eatWhile(isNumber) && (!stream.eat(DOT) || stream.eatWhile(isNumber))) {
// either integer or decimal: 10, 10.25
return true;
}
stream.pos = start;
return false;
} | javascript | function consumeForward(stream) {
const start = stream.pos;
if (stream.eat(DOT) && stream.eatWhile(isNumber)) {
// short decimal notation: .025
return true;
}
if (stream.eatWhile(isNumber) && (!stream.eat(DOT) || stream.eatWhile(isNumber))) {
// either integer or decimal: 10, 10.25
return true;
}
stream.pos = start;
return false;
} | [
"function",
"consumeForward",
"(",
"stream",
")",
"{",
"const",
"start",
"=",
"stream",
".",
"pos",
";",
"if",
"(",
"stream",
".",
"eat",
"(",
"DOT",
")",
"&&",
"stream",
".",
"eatWhile",
"(",
"isNumber",
")",
")",
"{",
"// short decimal notation: .025",
"return",
"true",
";",
"}",
"if",
"(",
"stream",
".",
"eatWhile",
"(",
"isNumber",
")",
"&&",
"(",
"!",
"stream",
".",
"eat",
"(",
"DOT",
")",
"||",
"stream",
".",
"eatWhile",
"(",
"isNumber",
")",
")",
")",
"{",
"// either integer or decimal: 10, 10.25",
"return",
"true",
";",
"}",
"stream",
".",
"pos",
"=",
"start",
";",
"return",
"false",
";",
"}"
]
| Consumes number in forward stream direction
@param {StreamReader} stream
@return {Boolean} Returns true if number was consumed | [
"Consumes",
"number",
"in",
"forward",
"stream",
"direction"
]
| 31dc028f80c27b5b00be9395e35ebd07c9cd8862 | https://github.com/emmetio/math-expression/blob/31dc028f80c27b5b00be9395e35ebd07c9cd8862/lib/number.js#L22-L36 |
45,633 | emmetio/math-expression | lib/number.js | consumeBackward | function consumeBackward(stream) {
const start = stream.pos;
let ch, hadDot = false, hadNumber = false;
// NB a StreamReader insance can be editor-specific and contain objects
// as a position marker. Since we don’t know for sure how to compare editor
// position markers, use consumed length instead to detect if number was consumed
let len = 0;
while (!isSoF(stream)) {
stream.backUp(1);
ch = stream.peek();
if (ch === DOT && !hadDot && hadNumber) {
hadDot = true;
} else if (!isNumber(ch)) {
stream.next();
break;
}
hadNumber = true;
len++;
}
if (len) {
const pos = stream.pos;
stream.start = pos;
stream.pos = start;
return true;
}
stream.pos = start;
return false;
} | javascript | function consumeBackward(stream) {
const start = stream.pos;
let ch, hadDot = false, hadNumber = false;
// NB a StreamReader insance can be editor-specific and contain objects
// as a position marker. Since we don’t know for sure how to compare editor
// position markers, use consumed length instead to detect if number was consumed
let len = 0;
while (!isSoF(stream)) {
stream.backUp(1);
ch = stream.peek();
if (ch === DOT && !hadDot && hadNumber) {
hadDot = true;
} else if (!isNumber(ch)) {
stream.next();
break;
}
hadNumber = true;
len++;
}
if (len) {
const pos = stream.pos;
stream.start = pos;
stream.pos = start;
return true;
}
stream.pos = start;
return false;
} | [
"function",
"consumeBackward",
"(",
"stream",
")",
"{",
"const",
"start",
"=",
"stream",
".",
"pos",
";",
"let",
"ch",
",",
"hadDot",
"=",
"false",
",",
"hadNumber",
"=",
"false",
";",
"// NB a StreamReader insance can be editor-specific and contain objects",
"// as a position marker. Since we don’t know for sure how to compare editor",
"// position markers, use consumed length instead to detect if number was consumed",
"let",
"len",
"=",
"0",
";",
"while",
"(",
"!",
"isSoF",
"(",
"stream",
")",
")",
"{",
"stream",
".",
"backUp",
"(",
"1",
")",
";",
"ch",
"=",
"stream",
".",
"peek",
"(",
")",
";",
"if",
"(",
"ch",
"===",
"DOT",
"&&",
"!",
"hadDot",
"&&",
"hadNumber",
")",
"{",
"hadDot",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"!",
"isNumber",
"(",
"ch",
")",
")",
"{",
"stream",
".",
"next",
"(",
")",
";",
"break",
";",
"}",
"hadNumber",
"=",
"true",
";",
"len",
"++",
";",
"}",
"if",
"(",
"len",
")",
"{",
"const",
"pos",
"=",
"stream",
".",
"pos",
";",
"stream",
".",
"start",
"=",
"pos",
";",
"stream",
".",
"pos",
"=",
"start",
";",
"return",
"true",
";",
"}",
"stream",
".",
"pos",
"=",
"start",
";",
"return",
"false",
";",
"}"
]
| Consumes number in backward stream direction
@param {StreamReader} stream
@return {Boolean} Returns true if number was consumed | [
"Consumes",
"number",
"in",
"backward",
"stream",
"direction"
]
| 31dc028f80c27b5b00be9395e35ebd07c9cd8862 | https://github.com/emmetio/math-expression/blob/31dc028f80c27b5b00be9395e35ebd07c9cd8862/lib/number.js#L43-L75 |
45,634 | k3erg/marantz-denon-upnpdiscovery | index.js | MarantzDenonUPnPDiscovery | function MarantzDenonUPnPDiscovery(callback) {
var that = this;
var foundDevices = {}; // only report a device once
// create socket
var socket = dgram.createSocket({type: 'udp4', reuseAddr: true});
socket.unref();
const search = new Buffer([
'M-SEARCH * HTTP/1.1',
'HOST: 239.255.255.250:1900',
'ST: upnp:rootdevice',
'MAN: "ssdp:discover"',
'MX: 3',
'',
''
].join('\r\n'));
socket.on('error', function(err) {
console.log(`server error:\n${err.stack}`);
socket.close();
});
socket.on('message', function(message, rinfo) {
var messageString = message.toString();
console.log(messageString);
if (messageString.match(/(d|D)enon/)) {
location = messageString.match(/LOCATION: (.*?)(\d+\.\d+\.\d+\.\d+)(.*)/);
if (location) {
arp.getMAC(location[2], function(err, mac) { // lookup ip on the arp table to get the MacAddress
if (!err) {
if (foundDevices[mac]) { // only report foind devices once
return;
}
var device = {
friendlyName: '',
ip: location[2],
location: (location[1] + location[2] + location[3]).trim(),
mac: mac,
manufacturer: 'Unknown Manufacturer',
model: 'Unknown Model'
};
foundDevices[mac] = device;
that.getUPnPInfo(device, function() {
if (device.manufacturer == 'Unknown Manufacturer') { // still no info?
that.getDeviceInfo(device, function() {callback(null, device);}, 80);
} else {
callback(null, device);
}
});
}
});
}
}
});
socket.on('listening', function() {
socket.addMembership('239.255.255.250');
socket.setMulticastTTL(4);
const address = socket.address();
console.log(`server listening ${address.address}:${address.port}`);
socket.send(search, 0, search.length, 1900, '239.255.255.250');
setTimeout(function() {socket.close();}, 5000);
});
socket.bind(0);
} | javascript | function MarantzDenonUPnPDiscovery(callback) {
var that = this;
var foundDevices = {}; // only report a device once
// create socket
var socket = dgram.createSocket({type: 'udp4', reuseAddr: true});
socket.unref();
const search = new Buffer([
'M-SEARCH * HTTP/1.1',
'HOST: 239.255.255.250:1900',
'ST: upnp:rootdevice',
'MAN: "ssdp:discover"',
'MX: 3',
'',
''
].join('\r\n'));
socket.on('error', function(err) {
console.log(`server error:\n${err.stack}`);
socket.close();
});
socket.on('message', function(message, rinfo) {
var messageString = message.toString();
console.log(messageString);
if (messageString.match(/(d|D)enon/)) {
location = messageString.match(/LOCATION: (.*?)(\d+\.\d+\.\d+\.\d+)(.*)/);
if (location) {
arp.getMAC(location[2], function(err, mac) { // lookup ip on the arp table to get the MacAddress
if (!err) {
if (foundDevices[mac]) { // only report foind devices once
return;
}
var device = {
friendlyName: '',
ip: location[2],
location: (location[1] + location[2] + location[3]).trim(),
mac: mac,
manufacturer: 'Unknown Manufacturer',
model: 'Unknown Model'
};
foundDevices[mac] = device;
that.getUPnPInfo(device, function() {
if (device.manufacturer == 'Unknown Manufacturer') { // still no info?
that.getDeviceInfo(device, function() {callback(null, device);}, 80);
} else {
callback(null, device);
}
});
}
});
}
}
});
socket.on('listening', function() {
socket.addMembership('239.255.255.250');
socket.setMulticastTTL(4);
const address = socket.address();
console.log(`server listening ${address.address}:${address.port}`);
socket.send(search, 0, search.length, 1900, '239.255.255.250');
setTimeout(function() {socket.close();}, 5000);
});
socket.bind(0);
} | [
"function",
"MarantzDenonUPnPDiscovery",
"(",
"callback",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"foundDevices",
"=",
"{",
"}",
";",
"// only report a device once",
"// create socket",
"var",
"socket",
"=",
"dgram",
".",
"createSocket",
"(",
"{",
"type",
":",
"'udp4'",
",",
"reuseAddr",
":",
"true",
"}",
")",
";",
"socket",
".",
"unref",
"(",
")",
";",
"const",
"search",
"=",
"new",
"Buffer",
"(",
"[",
"'M-SEARCH * HTTP/1.1'",
",",
"'HOST: 239.255.255.250:1900'",
",",
"'ST: upnp:rootdevice'",
",",
"'MAN: \"ssdp:discover\"'",
",",
"'MX: 3'",
",",
"''",
",",
"''",
"]",
".",
"join",
"(",
"'\\r\\n'",
")",
")",
";",
"socket",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"`",
"\\n",
"${",
"err",
".",
"stack",
"}",
"`",
")",
";",
"socket",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"socket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"message",
",",
"rinfo",
")",
"{",
"var",
"messageString",
"=",
"message",
".",
"toString",
"(",
")",
";",
"console",
".",
"log",
"(",
"messageString",
")",
";",
"if",
"(",
"messageString",
".",
"match",
"(",
"/",
"(d|D)enon",
"/",
")",
")",
"{",
"location",
"=",
"messageString",
".",
"match",
"(",
"/",
"LOCATION: (.*?)(\\d+\\.\\d+\\.\\d+\\.\\d+)(.*)",
"/",
")",
";",
"if",
"(",
"location",
")",
"{",
"arp",
".",
"getMAC",
"(",
"location",
"[",
"2",
"]",
",",
"function",
"(",
"err",
",",
"mac",
")",
"{",
"// lookup ip on the arp table to get the MacAddress",
"if",
"(",
"!",
"err",
")",
"{",
"if",
"(",
"foundDevices",
"[",
"mac",
"]",
")",
"{",
"// only report foind devices once",
"return",
";",
"}",
"var",
"device",
"=",
"{",
"friendlyName",
":",
"''",
",",
"ip",
":",
"location",
"[",
"2",
"]",
",",
"location",
":",
"(",
"location",
"[",
"1",
"]",
"+",
"location",
"[",
"2",
"]",
"+",
"location",
"[",
"3",
"]",
")",
".",
"trim",
"(",
")",
",",
"mac",
":",
"mac",
",",
"manufacturer",
":",
"'Unknown Manufacturer'",
",",
"model",
":",
"'Unknown Model'",
"}",
";",
"foundDevices",
"[",
"mac",
"]",
"=",
"device",
";",
"that",
".",
"getUPnPInfo",
"(",
"device",
",",
"function",
"(",
")",
"{",
"if",
"(",
"device",
".",
"manufacturer",
"==",
"'Unknown Manufacturer'",
")",
"{",
"// still no info?",
"that",
".",
"getDeviceInfo",
"(",
"device",
",",
"function",
"(",
")",
"{",
"callback",
"(",
"null",
",",
"device",
")",
";",
"}",
",",
"80",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"device",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"socket",
".",
"on",
"(",
"'listening'",
",",
"function",
"(",
")",
"{",
"socket",
".",
"addMembership",
"(",
"'239.255.255.250'",
")",
";",
"socket",
".",
"setMulticastTTL",
"(",
"4",
")",
";",
"const",
"address",
"=",
"socket",
".",
"address",
"(",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"address",
".",
"address",
"}",
"${",
"address",
".",
"port",
"}",
"`",
")",
";",
"socket",
".",
"send",
"(",
"search",
",",
"0",
",",
"search",
".",
"length",
",",
"1900",
",",
"'239.255.255.250'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"socket",
".",
"close",
"(",
")",
";",
"}",
",",
"5000",
")",
";",
"}",
")",
";",
"socket",
".",
"bind",
"(",
"0",
")",
";",
"}"
]
| Find Denon and marantz devices advertising their services by upnp.
@param {function} callback .
@constructor | [
"Find",
"Denon",
"and",
"marantz",
"devices",
"advertising",
"their",
"services",
"by",
"upnp",
"."
]
| 5613b4d1c77deea0ec04512c29286b14e0b96676 | https://github.com/k3erg/marantz-denon-upnpdiscovery/blob/5613b4d1c77deea0ec04512c29286b14e0b96676/index.js#L22-L87 |
45,635 | jirwin/node-zither | lib/statsd.js | function(options) {
options = options || {};
this.host = options.host || 'localhost';
this.port = options.port || 8125;
if (!statsdClients[this.host + ':' + this.port]) {
statsdClients[this.host + ':' + this.port] = new StatsD(options);
}
this.client = statsdClients[this.host + ':' + this.port];
this.sampleRate = options.sampleRate || 1;
Writable.call(this, {objectMode: true});
} | javascript | function(options) {
options = options || {};
this.host = options.host || 'localhost';
this.port = options.port || 8125;
if (!statsdClients[this.host + ':' + this.port]) {
statsdClients[this.host + ':' + this.port] = new StatsD(options);
}
this.client = statsdClients[this.host + ':' + this.port];
this.sampleRate = options.sampleRate || 1;
Writable.call(this, {objectMode: true});
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"host",
"=",
"options",
".",
"host",
"||",
"'localhost'",
";",
"this",
".",
"port",
"=",
"options",
".",
"port",
"||",
"8125",
";",
"if",
"(",
"!",
"statsdClients",
"[",
"this",
".",
"host",
"+",
"':'",
"+",
"this",
".",
"port",
"]",
")",
"{",
"statsdClients",
"[",
"this",
".",
"host",
"+",
"':'",
"+",
"this",
".",
"port",
"]",
"=",
"new",
"StatsD",
"(",
"options",
")",
";",
"}",
"this",
".",
"client",
"=",
"statsdClients",
"[",
"this",
".",
"host",
"+",
"':'",
"+",
"this",
".",
"port",
"]",
";",
"this",
".",
"sampleRate",
"=",
"options",
".",
"sampleRate",
"||",
"1",
";",
"Writable",
".",
"call",
"(",
"this",
",",
"{",
"objectMode",
":",
"true",
"}",
")",
";",
"}"
]
| A writable stream that acts as a statsd sink for the zither instrument input sources.
@param {Obj} options Statsd client options. See https://github.com/sivy/node-statsd for options.
Additionally you can include sampleRate to control how Statsd samples data.
sampleRate defaults to 1. | [
"A",
"writable",
"stream",
"that",
"acts",
"as",
"a",
"statsd",
"sink",
"for",
"the",
"zither",
"instrument",
"input",
"sources",
"."
]
| c8ab7f1cdfd2fdf25bf31d7d6231f2f7977387aa | https://github.com/jirwin/node-zither/blob/c8ab7f1cdfd2fdf25bf31d7d6231f2f7977387aa/lib/statsd.js#L14-L27 |
|
45,636 | thirdcoder/cpu3502 | arithmetic.js | add | function add(a, b, carryIn=0) {
let result = a + b + carryIn;
let fullResult = result;
let carryOut = 0;
// carryOut is 6th trit, truncate result to 5 trits
if (result > MAX_TRYTE) {
carryOut = 1;
result -= MAX_TRYTE * 2 + 1;
} else if (result < MIN_TRYTE) {
carryOut = -1; // underflow
result += MAX_TRYTE * 2 + 1;
}
// overflow is set if sign is incorrect
let overflow;
if (Math.sign(fullResult) === Math.sign(result)) {
overflow = 0;
} else {
overflow = Math.sign(fullResult) || Math.sign(result);
}
// note: for 5-trit + 5-trit + 1-trit will always V = C, but the logic above is generic
if (overflow !== carryOut) throw new Error(`unexpected overflow calculation: ${overflow} !== ${carryOut}`);
return {result, carryOut, fullResult, overflow};
} | javascript | function add(a, b, carryIn=0) {
let result = a + b + carryIn;
let fullResult = result;
let carryOut = 0;
// carryOut is 6th trit, truncate result to 5 trits
if (result > MAX_TRYTE) {
carryOut = 1;
result -= MAX_TRYTE * 2 + 1;
} else if (result < MIN_TRYTE) {
carryOut = -1; // underflow
result += MAX_TRYTE * 2 + 1;
}
// overflow is set if sign is incorrect
let overflow;
if (Math.sign(fullResult) === Math.sign(result)) {
overflow = 0;
} else {
overflow = Math.sign(fullResult) || Math.sign(result);
}
// note: for 5-trit + 5-trit + 1-trit will always V = C, but the logic above is generic
if (overflow !== carryOut) throw new Error(`unexpected overflow calculation: ${overflow} !== ${carryOut}`);
return {result, carryOut, fullResult, overflow};
} | [
"function",
"add",
"(",
"a",
",",
"b",
",",
"carryIn",
"=",
"0",
")",
"{",
"let",
"result",
"=",
"a",
"+",
"b",
"+",
"carryIn",
";",
"let",
"fullResult",
"=",
"result",
";",
"let",
"carryOut",
"=",
"0",
";",
"// carryOut is 6th trit, truncate result to 5 trits",
"if",
"(",
"result",
">",
"MAX_TRYTE",
")",
"{",
"carryOut",
"=",
"1",
";",
"result",
"-=",
"MAX_TRYTE",
"*",
"2",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"result",
"<",
"MIN_TRYTE",
")",
"{",
"carryOut",
"=",
"-",
"1",
";",
"// underflow",
"result",
"+=",
"MAX_TRYTE",
"*",
"2",
"+",
"1",
";",
"}",
"// overflow is set if sign is incorrect",
"let",
"overflow",
";",
"if",
"(",
"Math",
".",
"sign",
"(",
"fullResult",
")",
"===",
"Math",
".",
"sign",
"(",
"result",
")",
")",
"{",
"overflow",
"=",
"0",
";",
"}",
"else",
"{",
"overflow",
"=",
"Math",
".",
"sign",
"(",
"fullResult",
")",
"||",
"Math",
".",
"sign",
"(",
"result",
")",
";",
"}",
"// note: for 5-trit + 5-trit + 1-trit will always V = C, but the logic above is generic",
"if",
"(",
"overflow",
"!==",
"carryOut",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"overflow",
"}",
"${",
"carryOut",
"}",
"`",
")",
";",
"return",
"{",
"result",
",",
"carryOut",
",",
"fullResult",
",",
"overflow",
"}",
";",
"}"
]
| Add two trytes with optional carry, returning result and overflow | [
"Add",
"two",
"trytes",
"with",
"optional",
"carry",
"returning",
"result",
"and",
"overflow"
]
| af1c0c01f75d03443af572e08f14c994585a277b | https://github.com/thirdcoder/cpu3502/blob/af1c0c01f75d03443af572e08f14c994585a277b/arithmetic.js#L6-L31 |
45,637 | socialally/air | lib/air/html.js | html | function html(markup, outer) {
if(!this.length) {
return this;
}
if(typeof markup === 'boolean') {
outer = markup;
markup = undefined;
}
var prop = outer ? 'outerHTML' : 'innerHTML';
if(markup === undefined) {
return this.dom[0][prop];
}
markup = markup || '';
this.each(function(el) {
el[prop] = markup;
});
// TODO: should we remove matched elements when setting outerHTML?
// TODO: the matched elements have been rewritten and do not exist
// TODO: in the DOM anymore: ie: this.dom = [];
return this;
} | javascript | function html(markup, outer) {
if(!this.length) {
return this;
}
if(typeof markup === 'boolean') {
outer = markup;
markup = undefined;
}
var prop = outer ? 'outerHTML' : 'innerHTML';
if(markup === undefined) {
return this.dom[0][prop];
}
markup = markup || '';
this.each(function(el) {
el[prop] = markup;
});
// TODO: should we remove matched elements when setting outerHTML?
// TODO: the matched elements have been rewritten and do not exist
// TODO: in the DOM anymore: ie: this.dom = [];
return this;
} | [
"function",
"html",
"(",
"markup",
",",
"outer",
")",
"{",
"if",
"(",
"!",
"this",
".",
"length",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"typeof",
"markup",
"===",
"'boolean'",
")",
"{",
"outer",
"=",
"markup",
";",
"markup",
"=",
"undefined",
";",
"}",
"var",
"prop",
"=",
"outer",
"?",
"'outerHTML'",
":",
"'innerHTML'",
";",
"if",
"(",
"markup",
"===",
"undefined",
")",
"{",
"return",
"this",
".",
"dom",
"[",
"0",
"]",
"[",
"prop",
"]",
";",
"}",
"markup",
"=",
"markup",
"||",
"''",
";",
"this",
".",
"each",
"(",
"function",
"(",
"el",
")",
"{",
"el",
"[",
"prop",
"]",
"=",
"markup",
";",
"}",
")",
";",
"// TODO: should we remove matched elements when setting outerHTML?",
"// TODO: the matched elements have been rewritten and do not exist",
"// TODO: in the DOM anymore: ie: this.dom = [];",
"return",
"this",
";",
"}"
]
| Get the HTML of the first matched element or set the HTML
content of all matched elements.
Note that when using `outer` to set `outerHTML` you will likely invalidate
the current encapsulated elements and need to re-run the selector to
update the matched elements. | [
"Get",
"the",
"HTML",
"of",
"the",
"first",
"matched",
"element",
"or",
"set",
"the",
"HTML",
"content",
"of",
"all",
"matched",
"elements",
"."
]
| a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/html.js#L9-L29 |
45,638 | feedhenry/fh-mbaas-client | lib/admin/events/events.js | createEvent | function createEvent(params, cb) {
params.resourcePath = config.addURIParams(constants.EVENTS_BASE_PATH, params);
params.method = 'POST';
params.data = params.data || {};
mbaasRequest.admin(params, cb);
} | javascript | function createEvent(params, cb) {
params.resourcePath = config.addURIParams(constants.EVENTS_BASE_PATH, params);
params.method = 'POST';
params.data = params.data || {};
mbaasRequest.admin(params, cb);
} | [
"function",
"createEvent",
"(",
"params",
",",
"cb",
")",
"{",
"params",
".",
"resourcePath",
"=",
"config",
".",
"addURIParams",
"(",
"constants",
".",
"EVENTS_BASE_PATH",
",",
"params",
")",
";",
"params",
".",
"method",
"=",
"'POST'",
";",
"params",
".",
"data",
"=",
"params",
".",
"data",
"||",
"{",
"}",
";",
"mbaasRequest",
".",
"admin",
"(",
"params",
",",
"cb",
")",
";",
"}"
]
| Creating an Event on an MBaaS
@param params
@param cb | [
"Creating",
"an",
"Event",
"on",
"an",
"MBaaS"
]
| 2d5a9cbb32e1b2464d71ffa18513358fea388859 | https://github.com/feedhenry/fh-mbaas-client/blob/2d5a9cbb32e1b2464d71ffa18513358fea388859/lib/admin/events/events.js#L10-L15 |
45,639 | vid/SenseBase | web/lib/browse-facet.js | augment | function augment(el) {
// FIXME should always have a type
el.type = el.type || 'category';
el.icon = (typesIcons[el.type] || typesIcons.default).icon;
el.data = { value: el.text, type: el.type };
// branch
if (el.children && el.children.length > 0) {
el.state = { opened: el.children.length > 50 ? false : true };
el.children.forEach(function(c) {
c = augment(c);
});
el.text = el.text + ' [' + el.children.length + ']';
// value or category
} else if (el.size && el.size > 0) {
if (curAnnos.indexOf(el.text) > -1) {
el.state = { selected: true };
}
el.text = el.text + ' (' + el.size + ')';
}
return el;
} | javascript | function augment(el) {
// FIXME should always have a type
el.type = el.type || 'category';
el.icon = (typesIcons[el.type] || typesIcons.default).icon;
el.data = { value: el.text, type: el.type };
// branch
if (el.children && el.children.length > 0) {
el.state = { opened: el.children.length > 50 ? false : true };
el.children.forEach(function(c) {
c = augment(c);
});
el.text = el.text + ' [' + el.children.length + ']';
// value or category
} else if (el.size && el.size > 0) {
if (curAnnos.indexOf(el.text) > -1) {
el.state = { selected: true };
}
el.text = el.text + ' (' + el.size + ')';
}
return el;
} | [
"function",
"augment",
"(",
"el",
")",
"{",
"// FIXME should always have a type",
"el",
".",
"type",
"=",
"el",
".",
"type",
"||",
"'category'",
";",
"el",
".",
"icon",
"=",
"(",
"typesIcons",
"[",
"el",
".",
"type",
"]",
"||",
"typesIcons",
".",
"default",
")",
".",
"icon",
";",
"el",
".",
"data",
"=",
"{",
"value",
":",
"el",
".",
"text",
",",
"type",
":",
"el",
".",
"type",
"}",
";",
"// branch",
"if",
"(",
"el",
".",
"children",
"&&",
"el",
".",
"children",
".",
"length",
">",
"0",
")",
"{",
"el",
".",
"state",
"=",
"{",
"opened",
":",
"el",
".",
"children",
".",
"length",
">",
"50",
"?",
"false",
":",
"true",
"}",
";",
"el",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"c",
")",
"{",
"c",
"=",
"augment",
"(",
"c",
")",
";",
"}",
")",
";",
"el",
".",
"text",
"=",
"el",
".",
"text",
"+",
"' ['",
"+",
"el",
".",
"children",
".",
"length",
"+",
"']'",
";",
"// value or category",
"}",
"else",
"if",
"(",
"el",
".",
"size",
"&&",
"el",
".",
"size",
">",
"0",
")",
"{",
"if",
"(",
"curAnnos",
".",
"indexOf",
"(",
"el",
".",
"text",
")",
">",
"-",
"1",
")",
"{",
"el",
".",
"state",
"=",
"{",
"selected",
":",
"true",
"}",
";",
"}",
"el",
".",
"text",
"=",
"el",
".",
"text",
"+",
"' ('",
"+",
"el",
".",
"size",
"+",
"')'",
";",
"}",
"return",
"el",
";",
"}"
]
| add facet counts &c | [
"add",
"facet",
"counts",
"&c"
]
| d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/browse-facet.js#L58-L79 |
45,640 | cfpb/objectified | index.js | _tokenize | function _tokenize( prop ) {
var tokens = [],
patterns,
src = prop.source;
src = typeof src !== 'string' ? src : src.split(' ');
patterns = {
operator: /^[+\-\*\/\%]$/, // +-*/%
// @TODO Improve this regex to cover numbers like 1,000,000
number: /^\$?\d+[\.,]?\d+$/
};
function _pushToken( val, type ) {
var token = {
value: val,
type: type
};
tokens.push( token );
}
// Return early if it's a function.
if ( typeof src === 'function' ) {
_pushToken( src, 'function' );
return tokens;
}
// @TODO DRY this up.
for ( var i = 0, len = src.length; i < len; i++ ) {
if ( patterns.operator.test(src[i]) ) {
_pushToken( src[i].match(patterns.operator)[0], 'operator' );
} else if ( patterns.number.test(src[i]) ) {
_pushToken( parseFloat( src[i].match(patterns.number)[0] ), 'number' );
} else {
_pushToken( src[i], 'name' );
}
}
return tokens;
} | javascript | function _tokenize( prop ) {
var tokens = [],
patterns,
src = prop.source;
src = typeof src !== 'string' ? src : src.split(' ');
patterns = {
operator: /^[+\-\*\/\%]$/, // +-*/%
// @TODO Improve this regex to cover numbers like 1,000,000
number: /^\$?\d+[\.,]?\d+$/
};
function _pushToken( val, type ) {
var token = {
value: val,
type: type
};
tokens.push( token );
}
// Return early if it's a function.
if ( typeof src === 'function' ) {
_pushToken( src, 'function' );
return tokens;
}
// @TODO DRY this up.
for ( var i = 0, len = src.length; i < len; i++ ) {
if ( patterns.operator.test(src[i]) ) {
_pushToken( src[i].match(patterns.operator)[0], 'operator' );
} else if ( patterns.number.test(src[i]) ) {
_pushToken( parseFloat( src[i].match(patterns.number)[0] ), 'number' );
} else {
_pushToken( src[i], 'name' );
}
}
return tokens;
} | [
"function",
"_tokenize",
"(",
"prop",
")",
"{",
"var",
"tokens",
"=",
"[",
"]",
",",
"patterns",
",",
"src",
"=",
"prop",
".",
"source",
";",
"src",
"=",
"typeof",
"src",
"!==",
"'string'",
"?",
"src",
":",
"src",
".",
"split",
"(",
"' '",
")",
";",
"patterns",
"=",
"{",
"operator",
":",
"/",
"^[+\\-\\*\\/\\%]$",
"/",
",",
"// +-*/%",
"// @TODO Improve this regex to cover numbers like 1,000,000",
"number",
":",
"/",
"^\\$?\\d+[\\.,]?\\d+$",
"/",
"}",
";",
"function",
"_pushToken",
"(",
"val",
",",
"type",
")",
"{",
"var",
"token",
"=",
"{",
"value",
":",
"val",
",",
"type",
":",
"type",
"}",
";",
"tokens",
".",
"push",
"(",
"token",
")",
";",
"}",
"// Return early if it's a function.",
"if",
"(",
"typeof",
"src",
"===",
"'function'",
")",
"{",
"_pushToken",
"(",
"src",
",",
"'function'",
")",
";",
"return",
"tokens",
";",
"}",
"// @TODO DRY this up.",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"src",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"patterns",
".",
"operator",
".",
"test",
"(",
"src",
"[",
"i",
"]",
")",
")",
"{",
"_pushToken",
"(",
"src",
"[",
"i",
"]",
".",
"match",
"(",
"patterns",
".",
"operator",
")",
"[",
"0",
"]",
",",
"'operator'",
")",
";",
"}",
"else",
"if",
"(",
"patterns",
".",
"number",
".",
"test",
"(",
"src",
"[",
"i",
"]",
")",
")",
"{",
"_pushToken",
"(",
"parseFloat",
"(",
"src",
"[",
"i",
"]",
".",
"match",
"(",
"patterns",
".",
"number",
")",
"[",
"0",
"]",
")",
",",
"'number'",
")",
";",
"}",
"else",
"{",
"_pushToken",
"(",
"src",
"[",
"i",
"]",
",",
"'name'",
")",
";",
"}",
"}",
"return",
"tokens",
";",
"}"
]
| Split source strings and taxonimize language.
@param {string|function} src String to tokenize. If it's a function, leave it.
@return {array} Array of objects, each a token. | [
"Split",
"source",
"strings",
"and",
"taxonimize",
"language",
"."
]
| 252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d | https://github.com/cfpb/objectified/blob/252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d/index.js#L19-L59 |
45,641 | cfpb/objectified | index.js | _getDOMElement | function _getDOMElement( container, str ) {
var el = container.querySelector( '[name=' + str + ']' );
return el ? el : null;
} | javascript | function _getDOMElement( container, str ) {
var el = container.querySelector( '[name=' + str + ']' );
return el ? el : null;
} | [
"function",
"_getDOMElement",
"(",
"container",
",",
"str",
")",
"{",
"var",
"el",
"=",
"container",
".",
"querySelector",
"(",
"'[name='",
"+",
"str",
"+",
"']'",
")",
";",
"return",
"el",
"?",
"el",
":",
"null",
";",
"}"
]
| Returns the first element matching the provided string.
@param {object} container DOM element node of parent container.
@param {string} str Value to be provided to the selector.
@return {object} Element object. | [
"Returns",
"the",
"first",
"element",
"matching",
"the",
"provided",
"string",
"."
]
| 252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d | https://github.com/cfpb/objectified/blob/252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d/index.js#L67-L70 |
45,642 | cfpb/objectified | index.js | _deTokenize | function _deTokenize( container, arr ) {
var val,
tokens = [];
function _parseFloat( str ) {
return parseFloat( unFormatUSD(str) );
}
for ( var i = 0, len = arr.length; i < len; i++ ) {
var token = arr[i];
// @TODO DRY this up.
if ( token.type === 'function' ) {
tokens.push( token.value );
} else if ( token.type === 'operator' || token.type === 'number' ) {
tokens.push( token.value );
} else {
try {
// @TODO accommodate radio and other elements that don't use .value
val = _getDOMElement( container, token.value );
// Grab the value or the placeholder or default to 0.
val = unFormatUSD( val.value || val.getAttribute('placeholder') || 0 );
// Make it a number if it's a number.
val = isNaN( val ) ? val : _parseFloat( val );
tokens.push( val );
} catch ( e ) {}
}
}
// @TODO This feels a little repetitive.
if ( typeof tokens[0] === 'function' ) {
return tokens[0]();
}
val = tokens.length > 1 ? eval( tokens.join(' ') ) : tokens.join(' ');
return isNaN( val ) ? val : _parseFloat( val );
} | javascript | function _deTokenize( container, arr ) {
var val,
tokens = [];
function _parseFloat( str ) {
return parseFloat( unFormatUSD(str) );
}
for ( var i = 0, len = arr.length; i < len; i++ ) {
var token = arr[i];
// @TODO DRY this up.
if ( token.type === 'function' ) {
tokens.push( token.value );
} else if ( token.type === 'operator' || token.type === 'number' ) {
tokens.push( token.value );
} else {
try {
// @TODO accommodate radio and other elements that don't use .value
val = _getDOMElement( container, token.value );
// Grab the value or the placeholder or default to 0.
val = unFormatUSD( val.value || val.getAttribute('placeholder') || 0 );
// Make it a number if it's a number.
val = isNaN( val ) ? val : _parseFloat( val );
tokens.push( val );
} catch ( e ) {}
}
}
// @TODO This feels a little repetitive.
if ( typeof tokens[0] === 'function' ) {
return tokens[0]();
}
val = tokens.length > 1 ? eval( tokens.join(' ') ) : tokens.join(' ');
return isNaN( val ) ? val : _parseFloat( val );
} | [
"function",
"_deTokenize",
"(",
"container",
",",
"arr",
")",
"{",
"var",
"val",
",",
"tokens",
"=",
"[",
"]",
";",
"function",
"_parseFloat",
"(",
"str",
")",
"{",
"return",
"parseFloat",
"(",
"unFormatUSD",
"(",
"str",
")",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"token",
"=",
"arr",
"[",
"i",
"]",
";",
"// @TODO DRY this up.",
"if",
"(",
"token",
".",
"type",
"===",
"'function'",
")",
"{",
"tokens",
".",
"push",
"(",
"token",
".",
"value",
")",
";",
"}",
"else",
"if",
"(",
"token",
".",
"type",
"===",
"'operator'",
"||",
"token",
".",
"type",
"===",
"'number'",
")",
"{",
"tokens",
".",
"push",
"(",
"token",
".",
"value",
")",
";",
"}",
"else",
"{",
"try",
"{",
"// @TODO accommodate radio and other elements that don't use .value",
"val",
"=",
"_getDOMElement",
"(",
"container",
",",
"token",
".",
"value",
")",
";",
"// Grab the value or the placeholder or default to 0.",
"val",
"=",
"unFormatUSD",
"(",
"val",
".",
"value",
"||",
"val",
".",
"getAttribute",
"(",
"'placeholder'",
")",
"||",
"0",
")",
";",
"// Make it a number if it's a number.",
"val",
"=",
"isNaN",
"(",
"val",
")",
"?",
"val",
":",
"_parseFloat",
"(",
"val",
")",
";",
"tokens",
".",
"push",
"(",
"val",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"}",
"// @TODO This feels a little repetitive.",
"if",
"(",
"typeof",
"tokens",
"[",
"0",
"]",
"===",
"'function'",
")",
"{",
"return",
"tokens",
"[",
"0",
"]",
"(",
")",
";",
"}",
"val",
"=",
"tokens",
".",
"length",
">",
"1",
"?",
"eval",
"(",
"tokens",
".",
"join",
"(",
"' '",
")",
")",
":",
"tokens",
".",
"join",
"(",
"' '",
")",
";",
"return",
"isNaN",
"(",
"val",
")",
"?",
"val",
":",
"_parseFloat",
"(",
"val",
")",
";",
"}"
]
| Process an array of tokens, returning a single value.
@param {object} container DOM element node of parent container.
@param {array} arr Array of tokens created from _tokenize.
@return {string|number} The value of the processed tokens. | [
"Process",
"an",
"array",
"of",
"tokens",
"returning",
"a",
"single",
"value",
"."
]
| 252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d | https://github.com/cfpb/objectified/blob/252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d/index.js#L78-L111 |
45,643 | cfpb/objectified | index.js | update | function update( container, src, dest ) {
for ( var key in src ) {
// @TODO Better handle safe defaults.
dest[ key ] = _deTokenize( container, src[key] );
}
} | javascript | function update( container, src, dest ) {
for ( var key in src ) {
// @TODO Better handle safe defaults.
dest[ key ] = _deTokenize( container, src[key] );
}
} | [
"function",
"update",
"(",
"container",
",",
"src",
",",
"dest",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"src",
")",
"{",
"// @TODO Better handle safe defaults.",
"dest",
"[",
"key",
"]",
"=",
"_deTokenize",
"(",
"container",
",",
"src",
"[",
"key",
"]",
")",
";",
"}",
"}"
]
| Update the exported object
@param {object} container DOM element node of parent container.
@param {object} src Tokenize source object.
@param {object} dest Object to be updated.
@return {undefined} | [
"Update",
"the",
"exported",
"object"
]
| 252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d | https://github.com/cfpb/objectified/blob/252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d/index.js#L120-L125 |
45,644 | cfpb/objectified | index.js | objectify | function objectify( id, props ) {
// Stores references to elements that will be monitored.
var objectifier = {},
// Stores final values that are sent to user.
objectified = {},
container = document.querySelector( id );
for ( var i = 0, len = props.length; i < len; i++ ) {
if ( props[i].hasOwnProperty('source') ) {
objectifier[ props[i].name ] = _tokenize( props[i] );
} else {
objectifier[ props[i].name ] = undefined;
}
}
function _update() {
update( container, objectifier, objectified );
}
setListeners( container, _update );
objectified.update = _update;
return objectified;
} | javascript | function objectify( id, props ) {
// Stores references to elements that will be monitored.
var objectifier = {},
// Stores final values that are sent to user.
objectified = {},
container = document.querySelector( id );
for ( var i = 0, len = props.length; i < len; i++ ) {
if ( props[i].hasOwnProperty('source') ) {
objectifier[ props[i].name ] = _tokenize( props[i] );
} else {
objectifier[ props[i].name ] = undefined;
}
}
function _update() {
update( container, objectifier, objectified );
}
setListeners( container, _update );
objectified.update = _update;
return objectified;
} | [
"function",
"objectify",
"(",
"id",
",",
"props",
")",
"{",
"// Stores references to elements that will be monitored.",
"var",
"objectifier",
"=",
"{",
"}",
",",
"// Stores final values that are sent to user.",
"objectified",
"=",
"{",
"}",
",",
"container",
"=",
"document",
".",
"querySelector",
"(",
"id",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"props",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"props",
"[",
"i",
"]",
".",
"hasOwnProperty",
"(",
"'source'",
")",
")",
"{",
"objectifier",
"[",
"props",
"[",
"i",
"]",
".",
"name",
"]",
"=",
"_tokenize",
"(",
"props",
"[",
"i",
"]",
")",
";",
"}",
"else",
"{",
"objectifier",
"[",
"props",
"[",
"i",
"]",
".",
"name",
"]",
"=",
"undefined",
";",
"}",
"}",
"function",
"_update",
"(",
")",
"{",
"update",
"(",
"container",
",",
"objectifier",
",",
"objectified",
")",
";",
"}",
"setListeners",
"(",
"container",
",",
"_update",
")",
";",
"objectified",
".",
"update",
"=",
"_update",
";",
"return",
"objectified",
";",
"}"
]
| Constructor that processes the provided sources.
@param {array} props Array of objects
@return {object} Returns a reference to the object that is periodically updated. | [
"Constructor",
"that",
"processes",
"the",
"provided",
"sources",
"."
]
| 252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d | https://github.com/cfpb/objectified/blob/252d811d2f4900ad35ad22ad7cb4d4b4e0f4e83d/index.js#L132-L157 |
45,645 | writetome51/array-has | dist/privy/arrayHas.js | arrayHas | function arrayHas(value, array) {
error_if_not_array_1.errorIfNotArray(array);
return (array.length > 0 && (array_get_indexes_1.getFirstIndexOf(value, array) > -1));
} | javascript | function arrayHas(value, array) {
error_if_not_array_1.errorIfNotArray(array);
return (array.length > 0 && (array_get_indexes_1.getFirstIndexOf(value, array) > -1));
} | [
"function",
"arrayHas",
"(",
"value",
",",
"array",
")",
"{",
"error_if_not_array_1",
".",
"errorIfNotArray",
"(",
"array",
")",
";",
"return",
"(",
"array",
".",
"length",
">",
"0",
"&&",
"(",
"array_get_indexes_1",
".",
"getFirstIndexOf",
"(",
"value",
",",
"array",
")",
">",
"-",
"1",
")",
")",
";",
"}"
]
| value cannot be object. | [
"value",
"cannot",
"be",
"object",
"."
]
| 8ced3fda5818940b814bbcdc37e03c65f285a965 | https://github.com/writetome51/array-has/blob/8ced3fda5818940b814bbcdc37e03c65f285a965/dist/privy/arrayHas.js#L6-L9 |
45,646 | NerdDiffer/all-your-base | index.js | local_parseInt | function local_parseInt(str, from, to) {
var fn = assignFn(from, to);
return convert[fn](str + '');
} | javascript | function local_parseInt(str, from, to) {
var fn = assignFn(from, to);
return convert[fn](str + '');
} | [
"function",
"local_parseInt",
"(",
"str",
",",
"from",
",",
"to",
")",
"{",
"var",
"fn",
"=",
"assignFn",
"(",
"from",
",",
"to",
")",
";",
"return",
"convert",
"[",
"fn",
"]",
"(",
"str",
"+",
"''",
")",
";",
"}"
]
| A buffed-up version of the standard `parseInt` function
@param str, the value to convert. Is coerced into a String.
@param from, [Number], a base to convert from
@param to, [Number] a base to convert to
@return, the result of a call to a base conversion function | [
"A",
"buffed",
"-",
"up",
"version",
"of",
"the",
"standard",
"parseInt",
"function"
]
| ce258b2ca1430dd506b2a9e326f00219e8f8673c | https://github.com/NerdDiffer/all-your-base/blob/ce258b2ca1430dd506b2a9e326f00219e8f8673c/index.js#L26-L29 |
45,647 | NerdDiffer/all-your-base | index.js | assignFn | function assignFn(from, to) {
from = setDefault(10, from);
to = setDefault(10, to);
from = numToWord(from);
to = capitalize(numToWord(to));
return from + 'To' + to;
// return a copy of a string with its first letter capitalized
function capitalize(str) {
return str[0].toUpperCase() + str.slice(1);
}
// translate a number to its correlating module-specific namespace
function numToWord(num) {
num += '';
switch(num) {
case '2':
return 'bin';
case '8':
return 'oct';
case '10':
return 'dec';
case '16':
return 'hex';
default:
throw new Error('Base "' + num + '" is not supported');
}
}
// if `arg` is not provided, return a default value
function setDefault(defaultVal, arg) {
return (typeof arg === 'undefined' ? defaultVal : arg);
}
} | javascript | function assignFn(from, to) {
from = setDefault(10, from);
to = setDefault(10, to);
from = numToWord(from);
to = capitalize(numToWord(to));
return from + 'To' + to;
// return a copy of a string with its first letter capitalized
function capitalize(str) {
return str[0].toUpperCase() + str.slice(1);
}
// translate a number to its correlating module-specific namespace
function numToWord(num) {
num += '';
switch(num) {
case '2':
return 'bin';
case '8':
return 'oct';
case '10':
return 'dec';
case '16':
return 'hex';
default:
throw new Error('Base "' + num + '" is not supported');
}
}
// if `arg` is not provided, return a default value
function setDefault(defaultVal, arg) {
return (typeof arg === 'undefined' ? defaultVal : arg);
}
} | [
"function",
"assignFn",
"(",
"from",
",",
"to",
")",
"{",
"from",
"=",
"setDefault",
"(",
"10",
",",
"from",
")",
";",
"to",
"=",
"setDefault",
"(",
"10",
",",
"to",
")",
";",
"from",
"=",
"numToWord",
"(",
"from",
")",
";",
"to",
"=",
"capitalize",
"(",
"numToWord",
"(",
"to",
")",
")",
";",
"return",
"from",
"+",
"'To'",
"+",
"to",
";",
"// return a copy of a string with its first letter capitalized",
"function",
"capitalize",
"(",
"str",
")",
"{",
"return",
"str",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"str",
".",
"slice",
"(",
"1",
")",
";",
"}",
"// translate a number to its correlating module-specific namespace",
"function",
"numToWord",
"(",
"num",
")",
"{",
"num",
"+=",
"''",
";",
"switch",
"(",
"num",
")",
"{",
"case",
"'2'",
":",
"return",
"'bin'",
";",
"case",
"'8'",
":",
"return",
"'oct'",
";",
"case",
"'10'",
":",
"return",
"'dec'",
";",
"case",
"'16'",
":",
"return",
"'hex'",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Base \"'",
"+",
"num",
"+",
"'\" is not supported'",
")",
";",
"}",
"}",
"// if `arg` is not provided, return a default value",
"function",
"setDefault",
"(",
"defaultVal",
",",
"arg",
")",
"{",
"return",
"(",
"typeof",
"arg",
"===",
"'undefined'",
"?",
"defaultVal",
":",
"arg",
")",
";",
"}",
"}"
]
| Return a property to pass to the 'convert' object
@param from, [Number], a base to convert from
@param to, [Number] a base to convert to
@return, [String] a generated property name
@throws, an error if the base is not supported by this module | [
"Return",
"a",
"property",
"to",
"pass",
"to",
"the",
"convert",
"object"
]
| ce258b2ca1430dd506b2a9e326f00219e8f8673c | https://github.com/NerdDiffer/all-your-base/blob/ce258b2ca1430dd506b2a9e326f00219e8f8673c/index.js#L38-L73 |
45,648 | vid/SenseBase | lib/site-requests.js | processXML | function processXML(name, uri, processor, resp, callback) {
var parser = new xml2js.Parser();
parser.parseString(resp, function (err, xml) {
if (err) {
GLOBAL.error(name, err);
return;
} else {
processor.getAnnotations(name, uri, xml, function(err, annoRows) {
callback(err, {name: name, uri: uri, annoRows: annoRows});
});
}
});
} | javascript | function processXML(name, uri, processor, resp, callback) {
var parser = new xml2js.Parser();
parser.parseString(resp, function (err, xml) {
if (err) {
GLOBAL.error(name, err);
return;
} else {
processor.getAnnotations(name, uri, xml, function(err, annoRows) {
callback(err, {name: name, uri: uri, annoRows: annoRows});
});
}
});
} | [
"function",
"processXML",
"(",
"name",
",",
"uri",
",",
"processor",
",",
"resp",
",",
"callback",
")",
"{",
"var",
"parser",
"=",
"new",
"xml2js",
".",
"Parser",
"(",
")",
";",
"parser",
".",
"parseString",
"(",
"resp",
",",
"function",
"(",
"err",
",",
"xml",
")",
"{",
"if",
"(",
"err",
")",
"{",
"GLOBAL",
".",
"error",
"(",
"name",
",",
"err",
")",
";",
"return",
";",
"}",
"else",
"{",
"processor",
".",
"getAnnotations",
"(",
"name",
",",
"uri",
",",
"xml",
",",
"function",
"(",
"err",
",",
"annoRows",
")",
"{",
"callback",
"(",
"err",
",",
"{",
"name",
":",
"name",
",",
"uri",
":",
"uri",
",",
"annoRows",
":",
"annoRows",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
]
| process retrieved content as XML | [
"process",
"retrieved",
"content",
"as",
"XML"
]
| d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/lib/site-requests.js#L64-L77 |
45,649 | DScheglov/merest | lib/controllers/error.js | error | function error(err, req, res, next) {
if (err instanceof ModelAPIError) {
toSend = extend({error: true}, err);
res.status(err.code);
res.json(toSend);
} else {
toSend = {
error: true,
message: err.message,
stack: err.stack
};
res.status(500);
res.json(toSend);
}
} | javascript | function error(err, req, res, next) {
if (err instanceof ModelAPIError) {
toSend = extend({error: true}, err);
res.status(err.code);
res.json(toSend);
} else {
toSend = {
error: true,
message: err.message,
stack: err.stack
};
res.status(500);
res.json(toSend);
}
} | [
"function",
"error",
"(",
"err",
",",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"err",
"instanceof",
"ModelAPIError",
")",
"{",
"toSend",
"=",
"extend",
"(",
"{",
"error",
":",
"true",
"}",
",",
"err",
")",
";",
"res",
".",
"status",
"(",
"err",
".",
"code",
")",
";",
"res",
".",
"json",
"(",
"toSend",
")",
";",
"}",
"else",
"{",
"toSend",
"=",
"{",
"error",
":",
"true",
",",
"message",
":",
"err",
".",
"message",
",",
"stack",
":",
"err",
".",
"stack",
"}",
";",
"res",
".",
"status",
"(",
"500",
")",
";",
"res",
".",
"json",
"(",
"toSend",
")",
";",
"}",
"}"
]
| error - description
@param {Error} err the error that should be processed to client side
@param {express.Request} req the http(s) request
@param {express.Response} res the http(s) response
@param {Function} next the callback should be called if controller fails
@memberof ModelAPIExpress | [
"error",
"-",
"description"
]
| d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/error.js#L14-L28 |
45,650 | nodejitsu/contour | pagelets/carousel.js | controls | function controls(data, options) {
return data.reduce(function reduce(controls, item, n) {
return controls + options.fn({
panel: 'panel' + n,
checked: !n ? ' checked' : ''
});
}, '');
} | javascript | function controls(data, options) {
return data.reduce(function reduce(controls, item, n) {
return controls + options.fn({
panel: 'panel' + n,
checked: !n ? ' checked' : ''
});
}, '');
} | [
"function",
"controls",
"(",
"data",
",",
"options",
")",
"{",
"return",
"data",
".",
"reduce",
"(",
"function",
"reduce",
"(",
"controls",
",",
"item",
",",
"n",
")",
"{",
"return",
"controls",
"+",
"options",
".",
"fn",
"(",
"{",
"panel",
":",
"'panel'",
"+",
"n",
",",
"checked",
":",
"!",
"n",
"?",
"' checked'",
":",
"''",
"}",
")",
";",
"}",
",",
"''",
")",
";",
"}"
]
| Handblebar helper to generate the panel controls,
both the radio buttons as well as the arrow labels.
@param {Object} data Provided to the iterator.
@param {Object} options Optional.
@return {String} Generated template
@api private | [
"Handblebar",
"helper",
"to",
"generate",
"the",
"panel",
"controls",
"both",
"the",
"radio",
"buttons",
"as",
"well",
"as",
"the",
"arrow",
"labels",
"."
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/carousel.js#L37-L44 |
45,651 | mkdecisiondev/reshape-component | lib/index.js | copyAttributes | function copyAttributes (templateAst, componentNode, preserveType) {
for (let attributeName in componentNode.attrs) {
if (!(attributeName in skippedAttributes)) {
templateAst[0].attrs = templateAst[0].attrs || {};
if (templateAst[0].attrs[attributeName] && attributeName === 'class') {
templateAst[0].attrs[attributeName][0].content += ' ' + componentNode.attrs[attributeName][0].content;
}
else {
templateAst[0].attrs[attributeName] = componentNode.attrs[attributeName];
}
}
if (preserveType) {
const typeAttribute = preserveType === true ? 'type' : preserveType;
const typeAttributeValue = componentNode.attrs.type;
if (typeAttributeValue) {
templateAst[0].attrs = templateAst[0].attrs || {};
templateAst[0].attrs[typeAttribute] = typeAttributeValue;
}
}
}
} | javascript | function copyAttributes (templateAst, componentNode, preserveType) {
for (let attributeName in componentNode.attrs) {
if (!(attributeName in skippedAttributes)) {
templateAst[0].attrs = templateAst[0].attrs || {};
if (templateAst[0].attrs[attributeName] && attributeName === 'class') {
templateAst[0].attrs[attributeName][0].content += ' ' + componentNode.attrs[attributeName][0].content;
}
else {
templateAst[0].attrs[attributeName] = componentNode.attrs[attributeName];
}
}
if (preserveType) {
const typeAttribute = preserveType === true ? 'type' : preserveType;
const typeAttributeValue = componentNode.attrs.type;
if (typeAttributeValue) {
templateAst[0].attrs = templateAst[0].attrs || {};
templateAst[0].attrs[typeAttribute] = typeAttributeValue;
}
}
}
} | [
"function",
"copyAttributes",
"(",
"templateAst",
",",
"componentNode",
",",
"preserveType",
")",
"{",
"for",
"(",
"let",
"attributeName",
"in",
"componentNode",
".",
"attrs",
")",
"{",
"if",
"(",
"!",
"(",
"attributeName",
"in",
"skippedAttributes",
")",
")",
"{",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"=",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"||",
"{",
"}",
";",
"if",
"(",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"[",
"attributeName",
"]",
"&&",
"attributeName",
"===",
"'class'",
")",
"{",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"[",
"attributeName",
"]",
"[",
"0",
"]",
".",
"content",
"+=",
"' '",
"+",
"componentNode",
".",
"attrs",
"[",
"attributeName",
"]",
"[",
"0",
"]",
".",
"content",
";",
"}",
"else",
"{",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"[",
"attributeName",
"]",
"=",
"componentNode",
".",
"attrs",
"[",
"attributeName",
"]",
";",
"}",
"}",
"if",
"(",
"preserveType",
")",
"{",
"const",
"typeAttribute",
"=",
"preserveType",
"===",
"true",
"?",
"'type'",
":",
"preserveType",
";",
"const",
"typeAttributeValue",
"=",
"componentNode",
".",
"attrs",
".",
"type",
";",
"if",
"(",
"typeAttributeValue",
")",
"{",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"=",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"||",
"{",
"}",
";",
"templateAst",
"[",
"0",
"]",
".",
"attrs",
"[",
"typeAttribute",
"]",
"=",
"typeAttributeValue",
";",
"}",
"}",
"}",
"}"
]
| Copy attributes from 'node' to the first node in 'componentAst'
@param {ReshapeAst} templateAst - AST from the component source template
@param {ReshapeAstNode} componentNode - '<component>' node
@param {boolean|string} preserveType - If 'true', the 'type' attributed will preserved; if a string value
the 'type' attribute will be copied to an attribute named by the value | [
"Copy",
"attributes",
"from",
"node",
"to",
"the",
"first",
"node",
"in",
"componentAst"
]
| a2e8580d6789258b0c46989d804fe5cb3aec87f2 | https://github.com/mkdecisiondev/reshape-component/blob/a2e8580d6789258b0c46989d804fe5cb3aec87f2/lib/index.js#L19-L42 |
45,652 | mkdecisiondev/reshape-component | lib/index.js | replaceTokens | function replaceTokens (templateAst, componentNode) {
let promise;
if (componentNode.content) {
const tokenDefinitions = {};
componentNode.content.forEach(function (tokenDefinition) {
if (tokenDefinition.name) {
let tokenValue = '';
if (tokenDefinition.content) {
if (tokenDefinition.content.length === 1 && tokenDefinition.content[0].type === 'text') {
tokenValue = tokenDefinition.content[0].content;
}
else {
tokenValue = tokenDefinition.content;
}
}
tokenDefinitions[tokenDefinition.name] = tokenValue;
}
});
promise = modifyNodes(templateAst,
function (node) {
return node.attrs || (node.type === 'text' && tokenRegExp.test(node.content));
},
function (node) {
if (node.attrs) {
/**
* Take a node and do attribute replacement, e.g.:
* <div class="card ${state}" ${required} ${autocomplete} ${unused}></div>
* From the following component:
* <component>
* <state>active</state>
* <required/>
* <autocomplete>postal-address</autocomplete>
* </component>
* Produces the output (note that ${unused} has been trimmed):
* <div class="card active" required autocomplete="postal-address"></div>
*/
Object.keys(node.attrs).forEach(function (attributeName) {
// This code gets confusing fast:
// attributeName: this is the name of the attribute in the template node
// It is a token, e.g. ${pattern} and we are going to remove it from the node
tokenRegExp.lastIndex = 0;
const match = tokenRegExp.exec(attributeName);
if (match) {
// newAttributeName: this is the inner part of 'attributeName' and is going to be the name
// of the new attribute we add to the node, e.g. 'pattern'
const newAttributeName = match[1];
const newAttributeValue = tokenDefinitions[newAttributeName] ||
node.attrs[attributeName][0].content;
if (newAttributeValue || newAttributeName in tokenDefinitions) {
node.attrs[newAttributeName] = [
{
type: 'text',
content: newAttributeValue,
// TODO: this is not accurate, but should new nodes have no location?
location: node.attrs[attributeName].location,
},
];
}
delete node.attrs[attributeName];
}
else {
tokenRegExp.lastIndex = 0;
const attributeNode = node.attrs[attributeName][0];
replaceToken(attributeNode, tokenDefinitions, true);
}
});
}
else if (node.type === 'text') {
node = replaceToken(node, tokenDefinitions);
}
return node;
}
);
}
return promise;
} | javascript | function replaceTokens (templateAst, componentNode) {
let promise;
if (componentNode.content) {
const tokenDefinitions = {};
componentNode.content.forEach(function (tokenDefinition) {
if (tokenDefinition.name) {
let tokenValue = '';
if (tokenDefinition.content) {
if (tokenDefinition.content.length === 1 && tokenDefinition.content[0].type === 'text') {
tokenValue = tokenDefinition.content[0].content;
}
else {
tokenValue = tokenDefinition.content;
}
}
tokenDefinitions[tokenDefinition.name] = tokenValue;
}
});
promise = modifyNodes(templateAst,
function (node) {
return node.attrs || (node.type === 'text' && tokenRegExp.test(node.content));
},
function (node) {
if (node.attrs) {
/**
* Take a node and do attribute replacement, e.g.:
* <div class="card ${state}" ${required} ${autocomplete} ${unused}></div>
* From the following component:
* <component>
* <state>active</state>
* <required/>
* <autocomplete>postal-address</autocomplete>
* </component>
* Produces the output (note that ${unused} has been trimmed):
* <div class="card active" required autocomplete="postal-address"></div>
*/
Object.keys(node.attrs).forEach(function (attributeName) {
// This code gets confusing fast:
// attributeName: this is the name of the attribute in the template node
// It is a token, e.g. ${pattern} and we are going to remove it from the node
tokenRegExp.lastIndex = 0;
const match = tokenRegExp.exec(attributeName);
if (match) {
// newAttributeName: this is the inner part of 'attributeName' and is going to be the name
// of the new attribute we add to the node, e.g. 'pattern'
const newAttributeName = match[1];
const newAttributeValue = tokenDefinitions[newAttributeName] ||
node.attrs[attributeName][0].content;
if (newAttributeValue || newAttributeName in tokenDefinitions) {
node.attrs[newAttributeName] = [
{
type: 'text',
content: newAttributeValue,
// TODO: this is not accurate, but should new nodes have no location?
location: node.attrs[attributeName].location,
},
];
}
delete node.attrs[attributeName];
}
else {
tokenRegExp.lastIndex = 0;
const attributeNode = node.attrs[attributeName][0];
replaceToken(attributeNode, tokenDefinitions, true);
}
});
}
else if (node.type === 'text') {
node = replaceToken(node, tokenDefinitions);
}
return node;
}
);
}
return promise;
} | [
"function",
"replaceTokens",
"(",
"templateAst",
",",
"componentNode",
")",
"{",
"let",
"promise",
";",
"if",
"(",
"componentNode",
".",
"content",
")",
"{",
"const",
"tokenDefinitions",
"=",
"{",
"}",
";",
"componentNode",
".",
"content",
".",
"forEach",
"(",
"function",
"(",
"tokenDefinition",
")",
"{",
"if",
"(",
"tokenDefinition",
".",
"name",
")",
"{",
"let",
"tokenValue",
"=",
"''",
";",
"if",
"(",
"tokenDefinition",
".",
"content",
")",
"{",
"if",
"(",
"tokenDefinition",
".",
"content",
".",
"length",
"===",
"1",
"&&",
"tokenDefinition",
".",
"content",
"[",
"0",
"]",
".",
"type",
"===",
"'text'",
")",
"{",
"tokenValue",
"=",
"tokenDefinition",
".",
"content",
"[",
"0",
"]",
".",
"content",
";",
"}",
"else",
"{",
"tokenValue",
"=",
"tokenDefinition",
".",
"content",
";",
"}",
"}",
"tokenDefinitions",
"[",
"tokenDefinition",
".",
"name",
"]",
"=",
"tokenValue",
";",
"}",
"}",
")",
";",
"promise",
"=",
"modifyNodes",
"(",
"templateAst",
",",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"attrs",
"||",
"(",
"node",
".",
"type",
"===",
"'text'",
"&&",
"tokenRegExp",
".",
"test",
"(",
"node",
".",
"content",
")",
")",
";",
"}",
",",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"attrs",
")",
"{",
"/**\n\t\t\t\t\t * Take a node and do attribute replacement, e.g.:\n\t\t\t\t\t * <div class=\"card ${state}\" ${required} ${autocomplete} ${unused}></div>\n\t\t\t\t\t * From the following component:\n\t\t\t\t\t * <component>\n\t\t\t\t\t *\t\t<state>active</state>\n\t\t\t\t\t *\t\t<required/>\n\t\t\t\t\t *\t\t<autocomplete>postal-address</autocomplete>\n\t\t\t\t\t * </component>\n\t\t\t\t\t * Produces the output (note that ${unused} has been trimmed):\n\t\t\t\t\t * <div class=\"card active\" required autocomplete=\"postal-address\"></div>\n\t\t\t\t\t */",
"Object",
".",
"keys",
"(",
"node",
".",
"attrs",
")",
".",
"forEach",
"(",
"function",
"(",
"attributeName",
")",
"{",
"// This code gets confusing fast:",
"// attributeName: this is the name of the attribute in the template node",
"// It is a token, e.g. ${pattern} and we are going to remove it from the node",
"tokenRegExp",
".",
"lastIndex",
"=",
"0",
";",
"const",
"match",
"=",
"tokenRegExp",
".",
"exec",
"(",
"attributeName",
")",
";",
"if",
"(",
"match",
")",
"{",
"// newAttributeName: this is the inner part of 'attributeName' and is going to be the name",
"// of the new attribute we add to the node, e.g. 'pattern'",
"const",
"newAttributeName",
"=",
"match",
"[",
"1",
"]",
";",
"const",
"newAttributeValue",
"=",
"tokenDefinitions",
"[",
"newAttributeName",
"]",
"||",
"node",
".",
"attrs",
"[",
"attributeName",
"]",
"[",
"0",
"]",
".",
"content",
";",
"if",
"(",
"newAttributeValue",
"||",
"newAttributeName",
"in",
"tokenDefinitions",
")",
"{",
"node",
".",
"attrs",
"[",
"newAttributeName",
"]",
"=",
"[",
"{",
"type",
":",
"'text'",
",",
"content",
":",
"newAttributeValue",
",",
"// TODO: this is not accurate, but should new nodes have no location?",
"location",
":",
"node",
".",
"attrs",
"[",
"attributeName",
"]",
".",
"location",
",",
"}",
",",
"]",
";",
"}",
"delete",
"node",
".",
"attrs",
"[",
"attributeName",
"]",
";",
"}",
"else",
"{",
"tokenRegExp",
".",
"lastIndex",
"=",
"0",
";",
"const",
"attributeNode",
"=",
"node",
".",
"attrs",
"[",
"attributeName",
"]",
"[",
"0",
"]",
";",
"replaceToken",
"(",
"attributeNode",
",",
"tokenDefinitions",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"node",
".",
"type",
"===",
"'text'",
")",
"{",
"node",
"=",
"replaceToken",
"(",
"node",
",",
"tokenDefinitions",
")",
";",
"}",
"return",
"node",
";",
"}",
")",
";",
"}",
"return",
"promise",
";",
"}"
]
| Replace tokens in 'componentAst' with content defined in child elements of 'node'
@param {ReshapeAst} templateAst - AST from the component source template
@param {ReshapeAstNode} componentNode - '<component>' node
@returns {Thenable|undefined} If no substitution was performed then returns undefined | [
"Replace",
"tokens",
"in",
"componentAst",
"with",
"content",
"defined",
"in",
"child",
"elements",
"of",
"node"
]
| a2e8580d6789258b0c46989d804fe5cb3aec87f2 | https://github.com/mkdecisiondev/reshape-component/blob/a2e8580d6789258b0c46989d804fe5cb3aec87f2/lib/index.js#L79-L165 |
45,653 | Whitebolt/require-extra | src/versionLoader.js | getMyVersion | function getMyVersion(buildDir) {
var builds = getBuildFiles(buildDir);
var chosen = builds[0];
for (var n=0; n<builds.length; n++) {
if (semvar.satisfies(getVersion(builds[n]), '<=' + process.versions.node)) chosen = builds[n];
}
return require(buildDir + '/' + chosen);
} | javascript | function getMyVersion(buildDir) {
var builds = getBuildFiles(buildDir);
var chosen = builds[0];
for (var n=0; n<builds.length; n++) {
if (semvar.satisfies(getVersion(builds[n]), '<=' + process.versions.node)) chosen = builds[n];
}
return require(buildDir + '/' + chosen);
} | [
"function",
"getMyVersion",
"(",
"buildDir",
")",
"{",
"var",
"builds",
"=",
"getBuildFiles",
"(",
"buildDir",
")",
";",
"var",
"chosen",
"=",
"builds",
"[",
"0",
"]",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"builds",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"semvar",
".",
"satisfies",
"(",
"getVersion",
"(",
"builds",
"[",
"n",
"]",
")",
",",
"'<='",
"+",
"process",
".",
"versions",
".",
"node",
")",
")",
"chosen",
"=",
"builds",
"[",
"n",
"]",
";",
"}",
"return",
"require",
"(",
"buildDir",
"+",
"'/'",
"+",
"chosen",
")",
";",
"}"
]
| Get current node version a retrieve built file for that version.
@param {string} buildDir Where build files are located.
@returns {string} The build file to use. | [
"Get",
"current",
"node",
"version",
"a",
"retrieve",
"built",
"file",
"for",
"that",
"version",
"."
]
| 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/src/versionLoader.js#L48-L57 |
45,654 | nodejitsu/contour | pagelets/nodejitsu/pills/base.js | swap | function swap(e, to) {
if ('preventDefault' in e) e.preventDefault();
var item = $(e.element || '[data-id="' + to + '"]');
if (!!~item.get('className').indexOf('active')) return;
var parent = item.parent()
, effect = item.get('effect').split(',')
, change = item.get('swap').split('@')
, current = $(change[0])
, show = $(change[1]);
//
// Check if the effect was actually a proper list.
//
if (effect.length < 2) effect = ['fadeOut', 'fadeIn'];
current.addClass(effect[0]).removeClass(effect[1]);
parent.find('.active').removeClass('active');
item.addClass('active');
setTimeout(function () {
current.addClass('gone');
//
// Redraw elements if they were not visible.
//
if (~show.get('className').indexOf('gone')) {
show.removeClass('gone ' + effect[0]).addClass(effect[1]);
}
//
// Append hash for correct routing, will also jump to element with id=data-id
//
location.hash = item.get('data-id');
}, 500);
} | javascript | function swap(e, to) {
if ('preventDefault' in e) e.preventDefault();
var item = $(e.element || '[data-id="' + to + '"]');
if (!!~item.get('className').indexOf('active')) return;
var parent = item.parent()
, effect = item.get('effect').split(',')
, change = item.get('swap').split('@')
, current = $(change[0])
, show = $(change[1]);
//
// Check if the effect was actually a proper list.
//
if (effect.length < 2) effect = ['fadeOut', 'fadeIn'];
current.addClass(effect[0]).removeClass(effect[1]);
parent.find('.active').removeClass('active');
item.addClass('active');
setTimeout(function () {
current.addClass('gone');
//
// Redraw elements if they were not visible.
//
if (~show.get('className').indexOf('gone')) {
show.removeClass('gone ' + effect[0]).addClass(effect[1]);
}
//
// Append hash for correct routing, will also jump to element with id=data-id
//
location.hash = item.get('data-id');
}, 500);
} | [
"function",
"swap",
"(",
"e",
",",
"to",
")",
"{",
"if",
"(",
"'preventDefault'",
"in",
"e",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"item",
"=",
"$",
"(",
"e",
".",
"element",
"||",
"'[data-id=\"'",
"+",
"to",
"+",
"'\"]'",
")",
";",
"if",
"(",
"!",
"!",
"~",
"item",
".",
"get",
"(",
"'className'",
")",
".",
"indexOf",
"(",
"'active'",
")",
")",
"return",
";",
"var",
"parent",
"=",
"item",
".",
"parent",
"(",
")",
",",
"effect",
"=",
"item",
".",
"get",
"(",
"'effect'",
")",
".",
"split",
"(",
"','",
")",
",",
"change",
"=",
"item",
".",
"get",
"(",
"'swap'",
")",
".",
"split",
"(",
"'@'",
")",
",",
"current",
"=",
"$",
"(",
"change",
"[",
"0",
"]",
")",
",",
"show",
"=",
"$",
"(",
"change",
"[",
"1",
"]",
")",
";",
"//",
"// Check if the effect was actually a proper list.",
"//",
"if",
"(",
"effect",
".",
"length",
"<",
"2",
")",
"effect",
"=",
"[",
"'fadeOut'",
",",
"'fadeIn'",
"]",
";",
"current",
".",
"addClass",
"(",
"effect",
"[",
"0",
"]",
")",
".",
"removeClass",
"(",
"effect",
"[",
"1",
"]",
")",
";",
"parent",
".",
"find",
"(",
"'.active'",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"item",
".",
"addClass",
"(",
"'active'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"current",
".",
"addClass",
"(",
"'gone'",
")",
";",
"//",
"// Redraw elements if they were not visible.",
"//",
"if",
"(",
"~",
"show",
".",
"get",
"(",
"'className'",
")",
".",
"indexOf",
"(",
"'gone'",
")",
")",
"{",
"show",
".",
"removeClass",
"(",
"'gone '",
"+",
"effect",
"[",
"0",
"]",
")",
".",
"addClass",
"(",
"effect",
"[",
"1",
"]",
")",
";",
"}",
"//",
"// Append hash for correct routing, will also jump to element with id=data-id",
"//",
"location",
".",
"hash",
"=",
"item",
".",
"get",
"(",
"'data-id'",
")",
";",
"}",
",",
"500",
")",
";",
"}"
]
| Swap the different views
@param {Event} e
@param {String} to force tab by hash
@api private | [
"Swap",
"the",
"different",
"views"
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/nodejitsu/pills/base.js#L55-L91 |
45,655 | synder/xpress | demo/body-parser/lib/types/urlencoded.js | urlencoded | function urlencoded (options) {
var opts = options || {}
// notice because option default will flip in next major
if (opts.extended === undefined) {
deprecate('undefined extended: provide extended option')
}
var extended = opts.extended !== false
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'application/x-www-form-urlencoded'
var verify = opts.verify || false
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate query parser
var queryparse = extended
? extendedparser(opts)
: simpleparser(opts)
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
? typeChecker(type)
: type
function parse (body) {
return body.length
? queryparse(body)
: {}
}
return function urlencodedParser (req, res, next) {
if (req._body) {
debug('body already parsed')
next()
return
}
req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}
// assert charset
var charset = getCharset(req) || 'utf-8'
if (charset !== 'utf-8') {
debug('invalid charset')
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
charset: charset
}))
return
}
// read
read(req, res, next, parse, debug, {
debug: debug,
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
})
}
} | javascript | function urlencoded (options) {
var opts = options || {}
// notice because option default will flip in next major
if (opts.extended === undefined) {
deprecate('undefined extended: provide extended option')
}
var extended = opts.extended !== false
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'application/x-www-form-urlencoded'
var verify = opts.verify || false
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate query parser
var queryparse = extended
? extendedparser(opts)
: simpleparser(opts)
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
? typeChecker(type)
: type
function parse (body) {
return body.length
? queryparse(body)
: {}
}
return function urlencodedParser (req, res, next) {
if (req._body) {
debug('body already parsed')
next()
return
}
req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}
// assert charset
var charset = getCharset(req) || 'utf-8'
if (charset !== 'utf-8') {
debug('invalid charset')
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
charset: charset
}))
return
}
// read
read(req, res, next, parse, debug, {
debug: debug,
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
})
}
} | [
"function",
"urlencoded",
"(",
"options",
")",
"{",
"var",
"opts",
"=",
"options",
"||",
"{",
"}",
"// notice because option default will flip in next major",
"if",
"(",
"opts",
".",
"extended",
"===",
"undefined",
")",
"{",
"deprecate",
"(",
"'undefined extended: provide extended option'",
")",
"}",
"var",
"extended",
"=",
"opts",
".",
"extended",
"!==",
"false",
"var",
"inflate",
"=",
"opts",
".",
"inflate",
"!==",
"false",
"var",
"limit",
"=",
"typeof",
"opts",
".",
"limit",
"!==",
"'number'",
"?",
"bytes",
".",
"parse",
"(",
"opts",
".",
"limit",
"||",
"'100kb'",
")",
":",
"opts",
".",
"limit",
"var",
"type",
"=",
"opts",
".",
"type",
"||",
"'application/x-www-form-urlencoded'",
"var",
"verify",
"=",
"opts",
".",
"verify",
"||",
"false",
"if",
"(",
"verify",
"!==",
"false",
"&&",
"typeof",
"verify",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'option verify must be function'",
")",
"}",
"// create the appropriate query parser",
"var",
"queryparse",
"=",
"extended",
"?",
"extendedparser",
"(",
"opts",
")",
":",
"simpleparser",
"(",
"opts",
")",
"// create the appropriate type checking function",
"var",
"shouldParse",
"=",
"typeof",
"type",
"!==",
"'function'",
"?",
"typeChecker",
"(",
"type",
")",
":",
"type",
"function",
"parse",
"(",
"body",
")",
"{",
"return",
"body",
".",
"length",
"?",
"queryparse",
"(",
"body",
")",
":",
"{",
"}",
"}",
"return",
"function",
"urlencodedParser",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"req",
".",
"_body",
")",
"{",
"debug",
"(",
"'body already parsed'",
")",
"next",
"(",
")",
"return",
"}",
"req",
".",
"body",
"=",
"req",
".",
"body",
"||",
"{",
"}",
"// skip requests without bodies",
"if",
"(",
"!",
"typeis",
".",
"hasBody",
"(",
"req",
")",
")",
"{",
"debug",
"(",
"'skip empty body'",
")",
"next",
"(",
")",
"return",
"}",
"debug",
"(",
"'content-type %j'",
",",
"req",
".",
"headers",
"[",
"'content-type'",
"]",
")",
"// determine if request should be parsed",
"if",
"(",
"!",
"shouldParse",
"(",
"req",
")",
")",
"{",
"debug",
"(",
"'skip parsing'",
")",
"next",
"(",
")",
"return",
"}",
"// assert charset",
"var",
"charset",
"=",
"getCharset",
"(",
"req",
")",
"||",
"'utf-8'",
"if",
"(",
"charset",
"!==",
"'utf-8'",
")",
"{",
"debug",
"(",
"'invalid charset'",
")",
"next",
"(",
"createError",
"(",
"415",
",",
"'unsupported charset \"'",
"+",
"charset",
".",
"toUpperCase",
"(",
")",
"+",
"'\"'",
",",
"{",
"charset",
":",
"charset",
"}",
")",
")",
"return",
"}",
"// read",
"read",
"(",
"req",
",",
"res",
",",
"next",
",",
"parse",
",",
"debug",
",",
"{",
"debug",
":",
"debug",
",",
"encoding",
":",
"charset",
",",
"inflate",
":",
"inflate",
",",
"limit",
":",
"limit",
",",
"verify",
":",
"verify",
"}",
")",
"}",
"}"
]
| Create a middleware to parse urlencoded bodies.
@param {object} [options]
@return {function}
@public | [
"Create",
"a",
"middleware",
"to",
"parse",
"urlencoded",
"bodies",
"."
]
| 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/urlencoded.js#L43-L123 |
45,656 | synder/xpress | demo/body-parser/lib/types/urlencoded.js | extendedparser | function extendedparser (options) {
var parameterLimit = options.parameterLimit !== undefined
? options.parameterLimit
: 1000
var parse = parser('qs')
if (isNaN(parameterLimit) || parameterLimit < 1) {
throw new TypeError('option parameterLimit must be a positive number')
}
if (isFinite(parameterLimit)) {
parameterLimit = parameterLimit | 0
}
return function queryparse (body) {
var paramCount = parameterCount(body, parameterLimit)
if (paramCount === undefined) {
debug('too many parameters')
throw createError(413, 'too many parameters')
}
var arrayLimit = Math.max(100, paramCount)
debug('parse extended urlencoding')
return parse(body, {
allowPrototypes: true,
arrayLimit: arrayLimit,
depth: Infinity,
parameterLimit: parameterLimit
})
}
} | javascript | function extendedparser (options) {
var parameterLimit = options.parameterLimit !== undefined
? options.parameterLimit
: 1000
var parse = parser('qs')
if (isNaN(parameterLimit) || parameterLimit < 1) {
throw new TypeError('option parameterLimit must be a positive number')
}
if (isFinite(parameterLimit)) {
parameterLimit = parameterLimit | 0
}
return function queryparse (body) {
var paramCount = parameterCount(body, parameterLimit)
if (paramCount === undefined) {
debug('too many parameters')
throw createError(413, 'too many parameters')
}
var arrayLimit = Math.max(100, paramCount)
debug('parse extended urlencoding')
return parse(body, {
allowPrototypes: true,
arrayLimit: arrayLimit,
depth: Infinity,
parameterLimit: parameterLimit
})
}
} | [
"function",
"extendedparser",
"(",
"options",
")",
"{",
"var",
"parameterLimit",
"=",
"options",
".",
"parameterLimit",
"!==",
"undefined",
"?",
"options",
".",
"parameterLimit",
":",
"1000",
"var",
"parse",
"=",
"parser",
"(",
"'qs'",
")",
"if",
"(",
"isNaN",
"(",
"parameterLimit",
")",
"||",
"parameterLimit",
"<",
"1",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'option parameterLimit must be a positive number'",
")",
"}",
"if",
"(",
"isFinite",
"(",
"parameterLimit",
")",
")",
"{",
"parameterLimit",
"=",
"parameterLimit",
"|",
"0",
"}",
"return",
"function",
"queryparse",
"(",
"body",
")",
"{",
"var",
"paramCount",
"=",
"parameterCount",
"(",
"body",
",",
"parameterLimit",
")",
"if",
"(",
"paramCount",
"===",
"undefined",
")",
"{",
"debug",
"(",
"'too many parameters'",
")",
"throw",
"createError",
"(",
"413",
",",
"'too many parameters'",
")",
"}",
"var",
"arrayLimit",
"=",
"Math",
".",
"max",
"(",
"100",
",",
"paramCount",
")",
"debug",
"(",
"'parse extended urlencoding'",
")",
"return",
"parse",
"(",
"body",
",",
"{",
"allowPrototypes",
":",
"true",
",",
"arrayLimit",
":",
"arrayLimit",
",",
"depth",
":",
"Infinity",
",",
"parameterLimit",
":",
"parameterLimit",
"}",
")",
"}",
"}"
]
| Get the extended query parser.
@param {object} options | [
"Get",
"the",
"extended",
"query",
"parser",
"."
]
| 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/urlencoded.js#L131-L163 |
45,657 | synder/xpress | demo/body-parser/lib/types/urlencoded.js | parameterCount | function parameterCount (body, limit) {
var count = 0
var index = 0
while ((index = body.indexOf('&', index)) !== -1) {
count++
index++
if (count === limit) {
return undefined
}
}
return count
} | javascript | function parameterCount (body, limit) {
var count = 0
var index = 0
while ((index = body.indexOf('&', index)) !== -1) {
count++
index++
if (count === limit) {
return undefined
}
}
return count
} | [
"function",
"parameterCount",
"(",
"body",
",",
"limit",
")",
"{",
"var",
"count",
"=",
"0",
"var",
"index",
"=",
"0",
"while",
"(",
"(",
"index",
"=",
"body",
".",
"indexOf",
"(",
"'&'",
",",
"index",
")",
")",
"!==",
"-",
"1",
")",
"{",
"count",
"++",
"index",
"++",
"if",
"(",
"count",
"===",
"limit",
")",
"{",
"return",
"undefined",
"}",
"}",
"return",
"count",
"}"
]
| Count the number of parameters, stopping once limit reached
@param {string} body
@param {number} limit
@api private | [
"Count",
"the",
"number",
"of",
"parameters",
"stopping",
"once",
"limit",
"reached"
]
| 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/urlencoded.js#L188-L202 |
45,658 | synder/xpress | demo/body-parser/lib/types/urlencoded.js | parser | function parser (name) {
var mod = parsers[name]
if (mod !== undefined) {
return mod.parse
}
// this uses a switch for static require analysis
switch (name) {
case 'qs':
mod = require('qs')
break
case 'querystring':
mod = require('querystring')
break
}
// store to prevent invoking require()
parsers[name] = mod
return mod.parse
} | javascript | function parser (name) {
var mod = parsers[name]
if (mod !== undefined) {
return mod.parse
}
// this uses a switch for static require analysis
switch (name) {
case 'qs':
mod = require('qs')
break
case 'querystring':
mod = require('querystring')
break
}
// store to prevent invoking require()
parsers[name] = mod
return mod.parse
} | [
"function",
"parser",
"(",
"name",
")",
"{",
"var",
"mod",
"=",
"parsers",
"[",
"name",
"]",
"if",
"(",
"mod",
"!==",
"undefined",
")",
"{",
"return",
"mod",
".",
"parse",
"}",
"// this uses a switch for static require analysis",
"switch",
"(",
"name",
")",
"{",
"case",
"'qs'",
":",
"mod",
"=",
"require",
"(",
"'qs'",
")",
"break",
"case",
"'querystring'",
":",
"mod",
"=",
"require",
"(",
"'querystring'",
")",
"break",
"}",
"// store to prevent invoking require()",
"parsers",
"[",
"name",
"]",
"=",
"mod",
"return",
"mod",
".",
"parse",
"}"
]
| Get parser for module name dynamically.
@param {string} name
@return {function}
@api private | [
"Get",
"parser",
"for",
"module",
"name",
"dynamically",
"."
]
| 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/urlencoded.js#L212-L233 |
45,659 | synder/xpress | demo/body-parser/lib/types/urlencoded.js | simpleparser | function simpleparser (options) {
var parameterLimit = options.parameterLimit !== undefined
? options.parameterLimit
: 1000
var parse = parser('querystring')
if (isNaN(parameterLimit) || parameterLimit < 1) {
throw new TypeError('option parameterLimit must be a positive number')
}
if (isFinite(parameterLimit)) {
parameterLimit = parameterLimit | 0
}
return function queryparse (body) {
var paramCount = parameterCount(body, parameterLimit)
if (paramCount === undefined) {
debug('too many parameters')
throw createError(413, 'too many parameters')
}
debug('parse urlencoding')
return parse(body, undefined, undefined, {maxKeys: parameterLimit})
}
} | javascript | function simpleparser (options) {
var parameterLimit = options.parameterLimit !== undefined
? options.parameterLimit
: 1000
var parse = parser('querystring')
if (isNaN(parameterLimit) || parameterLimit < 1) {
throw new TypeError('option parameterLimit must be a positive number')
}
if (isFinite(parameterLimit)) {
parameterLimit = parameterLimit | 0
}
return function queryparse (body) {
var paramCount = parameterCount(body, parameterLimit)
if (paramCount === undefined) {
debug('too many parameters')
throw createError(413, 'too many parameters')
}
debug('parse urlencoding')
return parse(body, undefined, undefined, {maxKeys: parameterLimit})
}
} | [
"function",
"simpleparser",
"(",
"options",
")",
"{",
"var",
"parameterLimit",
"=",
"options",
".",
"parameterLimit",
"!==",
"undefined",
"?",
"options",
".",
"parameterLimit",
":",
"1000",
"var",
"parse",
"=",
"parser",
"(",
"'querystring'",
")",
"if",
"(",
"isNaN",
"(",
"parameterLimit",
")",
"||",
"parameterLimit",
"<",
"1",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'option parameterLimit must be a positive number'",
")",
"}",
"if",
"(",
"isFinite",
"(",
"parameterLimit",
")",
")",
"{",
"parameterLimit",
"=",
"parameterLimit",
"|",
"0",
"}",
"return",
"function",
"queryparse",
"(",
"body",
")",
"{",
"var",
"paramCount",
"=",
"parameterCount",
"(",
"body",
",",
"parameterLimit",
")",
"if",
"(",
"paramCount",
"===",
"undefined",
")",
"{",
"debug",
"(",
"'too many parameters'",
")",
"throw",
"createError",
"(",
"413",
",",
"'too many parameters'",
")",
"}",
"debug",
"(",
"'parse urlencoding'",
")",
"return",
"parse",
"(",
"body",
",",
"undefined",
",",
"undefined",
",",
"{",
"maxKeys",
":",
"parameterLimit",
"}",
")",
"}",
"}"
]
| Get the simple query parser.
@param {object} options | [
"Get",
"the",
"simple",
"query",
"parser",
"."
]
| 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/urlencoded.js#L241-L266 |
45,660 | OpenSmartEnvironment/ose | lib/shard/index.js | init | function init() { // {{{2
/**
* Class constructor
*
* @method constructor
*/
O.inherited(this)();
this.setMaxListeners(Consts.coreListeners);
this.subjectState = this.SUBJECT_STATE.INIT;
this.homeTimeOffset = 0;
this.lastTid = 0; // {{{3
/**
* Autoincemental part of last transaction id created in this shard and peer
*
* @property lastTid
* @type Number
*/
this.lastEid = 0; // {{{3
/**
* Autoincremental part of last entry id created in this shard and peer
*
* @property lastEid
* @type Number
*/
this.cache = {}; // {{{3
/**
* Object containing entries
*
* @property cache
* @type Object
*/
// }}}3
return true;
} | javascript | function init() { // {{{2
/**
* Class constructor
*
* @method constructor
*/
O.inherited(this)();
this.setMaxListeners(Consts.coreListeners);
this.subjectState = this.SUBJECT_STATE.INIT;
this.homeTimeOffset = 0;
this.lastTid = 0; // {{{3
/**
* Autoincemental part of last transaction id created in this shard and peer
*
* @property lastTid
* @type Number
*/
this.lastEid = 0; // {{{3
/**
* Autoincremental part of last entry id created in this shard and peer
*
* @property lastEid
* @type Number
*/
this.cache = {}; // {{{3
/**
* Object containing entries
*
* @property cache
* @type Object
*/
// }}}3
return true;
} | [
"function",
"init",
"(",
")",
"{",
"// {{{2",
"/**\n * Class constructor\n *\n * @method constructor\n */",
"O",
".",
"inherited",
"(",
"this",
")",
"(",
")",
";",
"this",
".",
"setMaxListeners",
"(",
"Consts",
".",
"coreListeners",
")",
";",
"this",
".",
"subjectState",
"=",
"this",
".",
"SUBJECT_STATE",
".",
"INIT",
";",
"this",
".",
"homeTimeOffset",
"=",
"0",
";",
"this",
".",
"lastTid",
"=",
"0",
";",
"// {{{3",
"/**\n * Autoincemental part of last transaction id created in this shard and peer\n *\n * @property lastTid\n * @type Number\n */",
"this",
".",
"lastEid",
"=",
"0",
";",
"// {{{3",
"/**\n * Autoincremental part of last entry id created in this shard and peer\n *\n * @property lastEid\n * @type Number\n */",
"this",
".",
"cache",
"=",
"{",
"}",
";",
"// {{{3",
"/**\n * Object containing entries\n *\n * @property cache\n * @type Object\n */",
"// }}}3",
"return",
"true",
";",
"}"
]
| master {{{2
Client socket linked to the master shard
@property master
@type Object
Public {{{1 | [
"master",
"{{{",
"2",
"Client",
"socket",
"linked",
"to",
"the",
"master",
"shard"
]
| 2ab051d9db6e77341c40abb9cbdae6ce586917e0 | https://github.com/OpenSmartEnvironment/ose/blob/2ab051d9db6e77341c40abb9cbdae6ce586917e0/lib/shard/index.js#L94-L136 |
45,661 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | arrayIncludesWith | function arrayIncludesWith(array, value, comparator) {
var index = -1, length = array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
} | javascript | function arrayIncludesWith(array, value, comparator) {
var index = -1, length = array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
} | [
"function",
"arrayIncludesWith",
"(",
"array",
",",
"value",
",",
"comparator",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"comparator",
"(",
"value",
",",
"array",
"[",
"index",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| This function is like `arrayIncludes` except that it accepts a comparator.
@private
@param {Array} array The array to search.
@param {*} target The value to search for.
@param {Function} comparator The comparator invoked per element.
@returns {boolean} Returns `true` if `target` is found, else `false`. | [
"This",
"function",
"is",
"like",
"arrayIncludes",
"except",
"that",
"it",
"accepts",
"a",
"comparator",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L12059-L12067 |
45,662 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | arrayReduceRight | function arrayReduceRight(array, iteratee, accumulator, initAccum) {
var length = array.length;
if (initAccum && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
} | javascript | function arrayReduceRight(array, iteratee, accumulator, initAccum) {
var length = array.length;
if (initAccum && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
} | [
"function",
"arrayReduceRight",
"(",
"array",
",",
"iteratee",
",",
"accumulator",
",",
"initAccum",
")",
"{",
"var",
"length",
"=",
"array",
".",
"length",
";",
"if",
"(",
"initAccum",
"&&",
"length",
")",
"{",
"accumulator",
"=",
"array",
"[",
"--",
"length",
"]",
";",
"}",
"while",
"(",
"length",
"--",
")",
"{",
"accumulator",
"=",
"iteratee",
"(",
"accumulator",
",",
"array",
"[",
"length",
"]",
",",
"length",
",",
"array",
")",
";",
"}",
"return",
"accumulator",
";",
"}"
]
| A specialized version of `_.reduceRight` for arrays without support for
iteratee shorthands.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {*} [accumulator] The initial value.
@param {boolean} [initAccum] Specify using the last element of `array` as the initial value.
@returns {*} Returns the accumulated value. | [
"A",
"specialized",
"version",
"of",
"_",
".",
"reduceRight",
"for",
"arrays",
"without",
"support",
"for",
"iteratee",
"shorthands",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L12131-L12140 |
45,663 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | baseExtremum | function baseExtremum(array, iteratee, comparator) {
var index = -1, length = array.length;
while (++index < length) {
var value = array[index], current = iteratee(value);
if (current != null && (computed === undefined ? current === current : comparator(current, computed))) {
var computed = current, result = value;
}
}
return result;
} | javascript | function baseExtremum(array, iteratee, comparator) {
var index = -1, length = array.length;
while (++index < length) {
var value = array[index], current = iteratee(value);
if (current != null && (computed === undefined ? current === current : comparator(current, computed))) {
var computed = current, result = value;
}
}
return result;
} | [
"function",
"baseExtremum",
"(",
"array",
",",
"iteratee",
",",
"comparator",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"array",
"[",
"index",
"]",
",",
"current",
"=",
"iteratee",
"(",
"value",
")",
";",
"if",
"(",
"current",
"!=",
"null",
"&&",
"(",
"computed",
"===",
"undefined",
"?",
"current",
"===",
"current",
":",
"comparator",
"(",
"current",
",",
"computed",
")",
")",
")",
"{",
"var",
"computed",
"=",
"current",
",",
"result",
"=",
"value",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| The base implementation of methods like `_.max` and `_.min` which accepts a
`comparator` to determine the extremum value.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The iteratee invoked per iteration.
@param {Function} comparator The comparator used to compare values.
@returns {*} Returns the extremum value. | [
"The",
"base",
"implementation",
"of",
"methods",
"like",
"_",
".",
"max",
"and",
"_",
".",
"min",
"which",
"accepts",
"a",
"comparator",
"to",
"determine",
"the",
"extremum",
"value",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L12169-L12178 |
45,664 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | stringSize | function stringSize(string) {
if (!(string && reHasComplexSymbol.test(string))) {
return string.length;
}
var result = reComplexSymbol.lastIndex = 0;
while (reComplexSymbol.test(string)) {
result++;
}
return result;
} | javascript | function stringSize(string) {
if (!(string && reHasComplexSymbol.test(string))) {
return string.length;
}
var result = reComplexSymbol.lastIndex = 0;
while (reComplexSymbol.test(string)) {
result++;
}
return result;
} | [
"function",
"stringSize",
"(",
"string",
")",
"{",
"if",
"(",
"!",
"(",
"string",
"&&",
"reHasComplexSymbol",
".",
"test",
"(",
"string",
")",
")",
")",
"{",
"return",
"string",
".",
"length",
";",
"}",
"var",
"result",
"=",
"reComplexSymbol",
".",
"lastIndex",
"=",
"0",
";",
"while",
"(",
"reComplexSymbol",
".",
"test",
"(",
"string",
")",
")",
"{",
"result",
"++",
";",
"}",
"return",
"result",
";",
"}"
]
| Gets the number of symbols in `string`.
@private
@param {string} string The string to inspect.
@returns {number} Returns the string size. | [
"Gets",
"the",
"number",
"of",
"symbols",
"in",
"string",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L12640-L12649 |
45,665 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | cacheHas | function cacheHas(cache, value) {
var map = cache.__data__;
if (isKeyable(value)) {
var data = map.__data__, hash = typeof value == 'string' ? data.string : data.hash;
return hash[value] === HASH_UNDEFINED;
}
return map.has(value);
} | javascript | function cacheHas(cache, value) {
var map = cache.__data__;
if (isKeyable(value)) {
var data = map.__data__, hash = typeof value == 'string' ? data.string : data.hash;
return hash[value] === HASH_UNDEFINED;
}
return map.has(value);
} | [
"function",
"cacheHas",
"(",
"cache",
",",
"value",
")",
"{",
"var",
"map",
"=",
"cache",
".",
"__data__",
";",
"if",
"(",
"isKeyable",
"(",
"value",
")",
")",
"{",
"var",
"data",
"=",
"map",
".",
"__data__",
",",
"hash",
"=",
"typeof",
"value",
"==",
"'string'",
"?",
"data",
".",
"string",
":",
"data",
".",
"hash",
";",
"return",
"hash",
"[",
"value",
"]",
"===",
"HASH_UNDEFINED",
";",
"}",
"return",
"map",
".",
"has",
"(",
"value",
")",
";",
"}"
]
| Checks if `value` is in `cache`.
@private
@param {Object} cache The set cache to search.
@param {*} value The value to search for.
@returns {number} Returns `true` if `value` is found, else `false`. | [
"Checks",
"if",
"value",
"is",
"in",
"cache",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L13177-L13184 |
45,666 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | baseHas | function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) || typeof object == 'object' && key in object && getPrototypeOf(object) === null;
} | javascript | function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) || typeof object == 'object' && key in object && getPrototypeOf(object) === null;
} | [
"function",
"baseHas",
"(",
"object",
",",
"key",
")",
"{",
"// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,",
"// that are composed entirely of index properties, return `false` for",
"// `hasOwnProperty` checks of them.",
"return",
"hasOwnProperty",
".",
"call",
"(",
"object",
",",
"key",
")",
"||",
"typeof",
"object",
"==",
"'object'",
"&&",
"key",
"in",
"object",
"&&",
"getPrototypeOf",
"(",
"object",
")",
"===",
"null",
";",
"}"
]
| The base implementation of `_.has` without support for deep paths.
@private
@param {Object} object The object to query.
@param {Array|string} key The key to check.
@returns {boolean} Returns `true` if `key` exists, else `false`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"has",
"without",
"support",
"for",
"deep",
"paths",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L13880-L13885 |
45,667 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | basePick | function basePick(object, props) {
object = Object(object);
return arrayReduce(props, function (result, key) {
if (key in object) {
result[key] = object[key];
}
return result;
}, {});
} | javascript | function basePick(object, props) {
object = Object(object);
return arrayReduce(props, function (result, key) {
if (key in object) {
result[key] = object[key];
}
return result;
}, {});
} | [
"function",
"basePick",
"(",
"object",
",",
"props",
")",
"{",
"object",
"=",
"Object",
"(",
"object",
")",
";",
"return",
"arrayReduce",
"(",
"props",
",",
"function",
"(",
"result",
",",
"key",
")",
"{",
"if",
"(",
"key",
"in",
"object",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"object",
"[",
"key",
"]",
";",
"}",
"return",
"result",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
]
| The base implementation of `_.pick` without support for individual
property names.
@private
@param {Object} object The source object.
@param {string[]} props The property names to pick.
@returns {Object} Returns the new object. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"pick",
"without",
"support",
"for",
"individual",
"property",
"names",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L14315-L14323 |
45,668 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | basePullAll | function basePullAll(array, values, iteratee, comparator) {
var indexOf = comparator ? baseIndexOfWith : baseIndexOf, index = -1, length = values.length, seen = array;
if (iteratee) {
seen = arrayMap(array, baseUnary(iteratee));
}
while (++index < length) {
var fromIndex = 0, value = values[index], computed = iteratee ? iteratee(value) : value;
while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
if (seen !== array) {
splice.call(seen, fromIndex, 1);
}
splice.call(array, fromIndex, 1);
}
}
return array;
} | javascript | function basePullAll(array, values, iteratee, comparator) {
var indexOf = comparator ? baseIndexOfWith : baseIndexOf, index = -1, length = values.length, seen = array;
if (iteratee) {
seen = arrayMap(array, baseUnary(iteratee));
}
while (++index < length) {
var fromIndex = 0, value = values[index], computed = iteratee ? iteratee(value) : value;
while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
if (seen !== array) {
splice.call(seen, fromIndex, 1);
}
splice.call(array, fromIndex, 1);
}
}
return array;
} | [
"function",
"basePullAll",
"(",
"array",
",",
"values",
",",
"iteratee",
",",
"comparator",
")",
"{",
"var",
"indexOf",
"=",
"comparator",
"?",
"baseIndexOfWith",
":",
"baseIndexOf",
",",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"values",
".",
"length",
",",
"seen",
"=",
"array",
";",
"if",
"(",
"iteratee",
")",
"{",
"seen",
"=",
"arrayMap",
"(",
"array",
",",
"baseUnary",
"(",
"iteratee",
")",
")",
";",
"}",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"fromIndex",
"=",
"0",
",",
"value",
"=",
"values",
"[",
"index",
"]",
",",
"computed",
"=",
"iteratee",
"?",
"iteratee",
"(",
"value",
")",
":",
"value",
";",
"while",
"(",
"(",
"fromIndex",
"=",
"indexOf",
"(",
"seen",
",",
"computed",
",",
"fromIndex",
",",
"comparator",
")",
")",
">",
"-",
"1",
")",
"{",
"if",
"(",
"seen",
"!==",
"array",
")",
"{",
"splice",
".",
"call",
"(",
"seen",
",",
"fromIndex",
",",
"1",
")",
";",
"}",
"splice",
".",
"call",
"(",
"array",
",",
"fromIndex",
",",
"1",
")",
";",
"}",
"}",
"return",
"array",
";",
"}"
]
| The base implementation of `_.pullAllBy` without support for iteratee
shorthands.
@private
@param {Array} array The array to modify.
@param {Array} values The values to remove.
@param {Function} [iteratee] The iteratee invoked per element.
@param {Function} [comparator] The comparator invoked per element.
@returns {Array} Returns `array`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"pullAllBy",
"without",
"support",
"for",
"iteratee",
"shorthands",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L14376-L14391 |
45,669 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | indexKeys | function indexKeys(object) {
var length = object ? object.length : undefined;
if (isLength(length) && (isArray(object) || isString(object) || isArguments(object))) {
return baseTimes(length, String);
}
return null;
} | javascript | function indexKeys(object) {
var length = object ? object.length : undefined;
if (isLength(length) && (isArray(object) || isString(object) || isArguments(object))) {
return baseTimes(length, String);
}
return null;
} | [
"function",
"indexKeys",
"(",
"object",
")",
"{",
"var",
"length",
"=",
"object",
"?",
"object",
".",
"length",
":",
"undefined",
";",
"if",
"(",
"isLength",
"(",
"length",
")",
"&&",
"(",
"isArray",
"(",
"object",
")",
"||",
"isString",
"(",
"object",
")",
"||",
"isArguments",
"(",
"object",
")",
")",
")",
"{",
"return",
"baseTimes",
"(",
"length",
",",
"String",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Creates an array of index keys for `object` values of arrays,
`arguments` objects, and strings, otherwise `null` is returned.
@private
@param {Object} object The object to query.
@returns {Array|null} Returns index keys, else `null`. | [
"Creates",
"an",
"array",
"of",
"index",
"keys",
"for",
"object",
"values",
"of",
"arrays",
"arguments",
"objects",
"and",
"strings",
"otherwise",
"null",
"is",
"returned",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L15955-L15961 |
45,670 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | mergeDefaults | function mergeDefaults(objValue, srcValue, key, object, source, stack) {
if (isObject(objValue) && isObject(srcValue)) {
baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
}
return objValue;
} | javascript | function mergeDefaults(objValue, srcValue, key, object, source, stack) {
if (isObject(objValue) && isObject(srcValue)) {
baseMerge(objValue, srcValue, undefined, mergeDefaults, stack.set(srcValue, objValue));
}
return objValue;
} | [
"function",
"mergeDefaults",
"(",
"objValue",
",",
"srcValue",
",",
"key",
",",
"object",
",",
"source",
",",
"stack",
")",
"{",
"if",
"(",
"isObject",
"(",
"objValue",
")",
"&&",
"isObject",
"(",
"srcValue",
")",
")",
"{",
"baseMerge",
"(",
"objValue",
",",
"srcValue",
",",
"undefined",
",",
"mergeDefaults",
",",
"stack",
".",
"set",
"(",
"srcValue",
",",
"objValue",
")",
")",
";",
"}",
"return",
"objValue",
";",
"}"
]
| Used by `_.defaultsDeep` to customize its `_.merge` use.
@private
@param {*} objValue The destination value.
@param {*} srcValue The source value.
@param {string} key The key of the property to merge.
@param {Object} object The parent object of `objValue`.
@param {Object} source The parent object of `srcValue`.
@param {Object} [stack] Tracks traversed source values and their merged counterparts.
@returns {*} Returns the value to assign. | [
"Used",
"by",
"_",
".",
"defaultsDeep",
"to",
"customize",
"its",
"_",
".",
"merge",
"use",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L16118-L16123 |
45,671 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | sample | function sample(collection) {
var array = isArrayLike(collection) ? collection : values(collection), length = array.length;
return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
} | javascript | function sample(collection) {
var array = isArrayLike(collection) ? collection : values(collection), length = array.length;
return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
} | [
"function",
"sample",
"(",
"collection",
")",
"{",
"var",
"array",
"=",
"isArrayLike",
"(",
"collection",
")",
"?",
"collection",
":",
"values",
"(",
"collection",
")",
",",
"length",
"=",
"array",
".",
"length",
";",
"return",
"length",
">",
"0",
"?",
"array",
"[",
"baseRandom",
"(",
"0",
",",
"length",
"-",
"1",
")",
"]",
":",
"undefined",
";",
"}"
]
| Gets a random element from `collection`.
@static
@memberOf _
@category Collection
@param {Array|Object} collection The collection to sample.
@returns {*} Returns the random element.
@example
_.sample([1, 2, 3, 4]);
// => 2 | [
"Gets",
"a",
"random",
"element",
"from",
"collection",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L18792-L18795 |
45,672 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | size | function size(collection) {
if (collection == null) {
return 0;
}
if (isArrayLike(collection)) {
var result = collection.length;
return result && isString(collection) ? stringSize(collection) : result;
}
return keys(collection).length;
} | javascript | function size(collection) {
if (collection == null) {
return 0;
}
if (isArrayLike(collection)) {
var result = collection.length;
return result && isString(collection) ? stringSize(collection) : result;
}
return keys(collection).length;
} | [
"function",
"size",
"(",
"collection",
")",
"{",
"if",
"(",
"collection",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"isArrayLike",
"(",
"collection",
")",
")",
"{",
"var",
"result",
"=",
"collection",
".",
"length",
";",
"return",
"result",
"&&",
"isString",
"(",
"collection",
")",
"?",
"stringSize",
"(",
"collection",
")",
":",
"result",
";",
"}",
"return",
"keys",
"(",
"collection",
")",
".",
"length",
";",
"}"
]
| Gets the size of `collection` by returning its length for array-like
values or the number of own enumerable properties for objects.
@static
@memberOf _
@category Collection
@param {Array|Object} collection The collection to inspect.
@returns {number} Returns the collection size.
@example
_.size([1, 2, 3]);
// => 3
_.size({ 'a': 1, 'b': 2 });
// => 2
_.size('pebbles');
// => 7 | [
"Gets",
"the",
"size",
"of",
"collection",
"by",
"returning",
"its",
"length",
"for",
"array",
"-",
"like",
"values",
"or",
"the",
"number",
"of",
"own",
"enumerable",
"properties",
"for",
"objects",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L18862-L18871 |
45,673 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | isTypedArray | function isTypedArray(value) {
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
} | javascript | function isTypedArray(value) {
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
} | [
"function",
"isTypedArray",
"(",
"value",
")",
"{",
"return",
"isObjectLike",
"(",
"value",
")",
"&&",
"isLength",
"(",
"value",
".",
"length",
")",
"&&",
"!",
"!",
"typedArrayTags",
"[",
"objectToString",
".",
"call",
"(",
"value",
")",
"]",
";",
"}"
]
| Checks if `value` is classified as a typed array.
@static
@memberOf _
@category Lang
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
@example
_.isTypedArray(new Uint8Array);
// => true
_.isTypedArray([]);
// => false | [
"Checks",
"if",
"value",
"is",
"classified",
"as",
"a",
"typed",
"array",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L20948-L20950 |
45,674 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | keys | function keys(object) {
var isProto = isPrototype(object);
if (!(isProto || isArrayLike(object))) {
return baseKeys(object);
}
var indexes = indexKeys(object), skipIndexes = !!indexes, result = indexes || [], length = result.length;
for (var key in object) {
if (baseHas(object, key) && !(skipIndexes && (key == 'length' || isIndex(key, length))) && !(isProto && key == 'constructor')) {
result.push(key);
}
}
return result;
} | javascript | function keys(object) {
var isProto = isPrototype(object);
if (!(isProto || isArrayLike(object))) {
return baseKeys(object);
}
var indexes = indexKeys(object), skipIndexes = !!indexes, result = indexes || [], length = result.length;
for (var key in object) {
if (baseHas(object, key) && !(skipIndexes && (key == 'length' || isIndex(key, length))) && !(isProto && key == 'constructor')) {
result.push(key);
}
}
return result;
} | [
"function",
"keys",
"(",
"object",
")",
"{",
"var",
"isProto",
"=",
"isPrototype",
"(",
"object",
")",
";",
"if",
"(",
"!",
"(",
"isProto",
"||",
"isArrayLike",
"(",
"object",
")",
")",
")",
"{",
"return",
"baseKeys",
"(",
"object",
")",
";",
"}",
"var",
"indexes",
"=",
"indexKeys",
"(",
"object",
")",
",",
"skipIndexes",
"=",
"!",
"!",
"indexes",
",",
"result",
"=",
"indexes",
"||",
"[",
"]",
",",
"length",
"=",
"result",
".",
"length",
";",
"for",
"(",
"var",
"key",
"in",
"object",
")",
"{",
"if",
"(",
"baseHas",
"(",
"object",
",",
"key",
")",
"&&",
"!",
"(",
"skipIndexes",
"&&",
"(",
"key",
"==",
"'length'",
"||",
"isIndex",
"(",
"key",
",",
"length",
")",
")",
")",
"&&",
"!",
"(",
"isProto",
"&&",
"key",
"==",
"'constructor'",
")",
")",
"{",
"result",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Creates an array of the own enumerable property names of `object`.
**Note:** Non-object values are coerced to objects. See the
[ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
for more details.
@static
@memberOf _
@category Object
@param {Object} object The object to query.
@returns {Array} Returns the array of property names.
@example
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
_.keys(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)
_.keys('hi');
// => ['0', '1'] | [
"Creates",
"an",
"array",
"of",
"the",
"own",
"enumerable",
"property",
"names",
"of",
"object",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L21930-L21942 |
45,675 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | parseInt | function parseInt(string, radix, guard) {
// Chrome fails to trim leading <BOM> whitespace characters.
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
if (guard || radix == null) {
radix = 0;
} else if (radix) {
radix = +radix;
}
string = toString(string).replace(reTrim, '');
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
} | javascript | function parseInt(string, radix, guard) {
// Chrome fails to trim leading <BOM> whitespace characters.
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
if (guard || radix == null) {
radix = 0;
} else if (radix) {
radix = +radix;
}
string = toString(string).replace(reTrim, '');
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
} | [
"function",
"parseInt",
"(",
"string",
",",
"radix",
",",
"guard",
")",
"{",
"// Chrome fails to trim leading <BOM> whitespace characters.",
"// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.",
"if",
"(",
"guard",
"||",
"radix",
"==",
"null",
")",
"{",
"radix",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"radix",
")",
"{",
"radix",
"=",
"+",
"radix",
";",
"}",
"string",
"=",
"toString",
"(",
"string",
")",
".",
"replace",
"(",
"reTrim",
",",
"''",
")",
";",
"return",
"nativeParseInt",
"(",
"string",
",",
"radix",
"||",
"(",
"reHasHexPrefix",
".",
"test",
"(",
"string",
")",
"?",
"16",
":",
"10",
")",
")",
";",
"}"
]
| Converts `string` to an integer of the specified radix. If `radix` is
`undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
in which case a `radix` of `16` is used.
**Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
of `parseInt`.
@static
@memberOf _
@category String
@param {string} string The string to convert.
@param {number} [radix=10] The radix to interpret `value` by.
@param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
@returns {number} Returns the converted integer.
@example
_.parseInt('08');
// => 8
_.map(['6', '08', '10'], _.parseInt);
// => [6, 8, 10] | [
"Converts",
"string",
"to",
"an",
"integer",
"of",
"the",
"specified",
"radix",
".",
"If",
"radix",
"is",
"undefined",
"or",
"0",
"a",
"radix",
"of",
"10",
"is",
"used",
"unless",
"value",
"is",
"a",
"hexadecimal",
"in",
"which",
"case",
"a",
"radix",
"of",
"16",
"is",
"used",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L23004-L23014 |
45,676 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | words | function words(string, pattern, guard) {
string = toString(string);
pattern = guard ? undefined : pattern;
if (pattern === undefined) {
pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
}
return string.match(pattern) || [];
} | javascript | function words(string, pattern, guard) {
string = toString(string);
pattern = guard ? undefined : pattern;
if (pattern === undefined) {
pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
}
return string.match(pattern) || [];
} | [
"function",
"words",
"(",
"string",
",",
"pattern",
",",
"guard",
")",
"{",
"string",
"=",
"toString",
"(",
"string",
")",
";",
"pattern",
"=",
"guard",
"?",
"undefined",
":",
"pattern",
";",
"if",
"(",
"pattern",
"===",
"undefined",
")",
"{",
"pattern",
"=",
"reHasComplexWord",
".",
"test",
"(",
"string",
")",
"?",
"reComplexWord",
":",
"reBasicWord",
";",
"}",
"return",
"string",
".",
"match",
"(",
"pattern",
")",
"||",
"[",
"]",
";",
"}"
]
| Splits `string` into an array of its words.
@static
@memberOf _
@category String
@param {string} [string=''] The string to inspect.
@param {RegExp|string} [pattern] The pattern to match words.
@param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
@returns {Array} Returns the words of `string`.
@example
_.words('fred, barney, & pebbles');
// => ['fred', 'barney', 'pebbles']
_.words('fred, barney, & pebbles', /[^, ]+/g);
// => ['fred', 'barney', '&', 'pebbles'] | [
"Splits",
"string",
"into",
"an",
"array",
"of",
"its",
"words",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L23611-L23618 |
45,677 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | mixin | function mixin(object, source, options) {
var props = keys(source), methodNames = baseFunctions(source, props);
if (options == null && !(isObject(source) && (methodNames.length || !props.length))) {
options = source;
source = object;
object = this;
methodNames = baseFunctions(source, keys(source));
}
var chain = isObject(options) && 'chain' in options ? options.chain : true, isFunc = isFunction(object);
arrayEach(methodNames, function (methodName) {
var func = source[methodName];
object[methodName] = func;
if (isFunc) {
object.prototype[methodName] = function () {
var chainAll = this.__chain__;
if (chain || chainAll) {
var result = object(this.__wrapped__), actions = result.__actions__ = copyArray(this.__actions__);
actions.push({
'func': func,
'args': arguments,
'thisArg': object
});
result.__chain__ = chainAll;
return result;
}
return func.apply(object, arrayPush([this.value()], arguments));
};
}
});
return object;
} | javascript | function mixin(object, source, options) {
var props = keys(source), methodNames = baseFunctions(source, props);
if (options == null && !(isObject(source) && (methodNames.length || !props.length))) {
options = source;
source = object;
object = this;
methodNames = baseFunctions(source, keys(source));
}
var chain = isObject(options) && 'chain' in options ? options.chain : true, isFunc = isFunction(object);
arrayEach(methodNames, function (methodName) {
var func = source[methodName];
object[methodName] = func;
if (isFunc) {
object.prototype[methodName] = function () {
var chainAll = this.__chain__;
if (chain || chainAll) {
var result = object(this.__wrapped__), actions = result.__actions__ = copyArray(this.__actions__);
actions.push({
'func': func,
'args': arguments,
'thisArg': object
});
result.__chain__ = chainAll;
return result;
}
return func.apply(object, arrayPush([this.value()], arguments));
};
}
});
return object;
} | [
"function",
"mixin",
"(",
"object",
",",
"source",
",",
"options",
")",
"{",
"var",
"props",
"=",
"keys",
"(",
"source",
")",
",",
"methodNames",
"=",
"baseFunctions",
"(",
"source",
",",
"props",
")",
";",
"if",
"(",
"options",
"==",
"null",
"&&",
"!",
"(",
"isObject",
"(",
"source",
")",
"&&",
"(",
"methodNames",
".",
"length",
"||",
"!",
"props",
".",
"length",
")",
")",
")",
"{",
"options",
"=",
"source",
";",
"source",
"=",
"object",
";",
"object",
"=",
"this",
";",
"methodNames",
"=",
"baseFunctions",
"(",
"source",
",",
"keys",
"(",
"source",
")",
")",
";",
"}",
"var",
"chain",
"=",
"isObject",
"(",
"options",
")",
"&&",
"'chain'",
"in",
"options",
"?",
"options",
".",
"chain",
":",
"true",
",",
"isFunc",
"=",
"isFunction",
"(",
"object",
")",
";",
"arrayEach",
"(",
"methodNames",
",",
"function",
"(",
"methodName",
")",
"{",
"var",
"func",
"=",
"source",
"[",
"methodName",
"]",
";",
"object",
"[",
"methodName",
"]",
"=",
"func",
";",
"if",
"(",
"isFunc",
")",
"{",
"object",
".",
"prototype",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"chainAll",
"=",
"this",
".",
"__chain__",
";",
"if",
"(",
"chain",
"||",
"chainAll",
")",
"{",
"var",
"result",
"=",
"object",
"(",
"this",
".",
"__wrapped__",
")",
",",
"actions",
"=",
"result",
".",
"__actions__",
"=",
"copyArray",
"(",
"this",
".",
"__actions__",
")",
";",
"actions",
".",
"push",
"(",
"{",
"'func'",
":",
"func",
",",
"'args'",
":",
"arguments",
",",
"'thisArg'",
":",
"object",
"}",
")",
";",
"result",
".",
"__chain__",
"=",
"chainAll",
";",
"return",
"result",
";",
"}",
"return",
"func",
".",
"apply",
"(",
"object",
",",
"arrayPush",
"(",
"[",
"this",
".",
"value",
"(",
")",
"]",
",",
"arguments",
")",
")",
";",
"}",
";",
"}",
"}",
")",
";",
"return",
"object",
";",
"}"
]
| Adds all own enumerable function properties of a source object to the
destination object. If `object` is a function then methods are added to
its prototype as well.
**Note:** Use `_.runInContext` to create a pristine `lodash` function to
avoid conflicts caused by modifying the original.
@static
@memberOf _
@category Util
@param {Function|Object} [object=lodash] The destination object.
@param {Object} source The object of functions to add.
@param {Object} [options] The options object.
@param {boolean} [options.chain=true] Specify whether the functions added
are chainable.
@returns {Function|Object} Returns `object`.
@example
function vowels(string) {
return _.filter(string, function(v) {
return /[aeiou]/i.test(v);
});
}
_.mixin({ 'vowels': vowels });
_.vowels('fred');
// => ['e']
_('fred').vowels().value();
// => ['e']
_.mixin({ 'vowels': vowels }, { 'chain': false });
_('fred').vowels();
// => ['e'] | [
"Adds",
"all",
"own",
"enumerable",
"function",
"properties",
"of",
"a",
"source",
"object",
"to",
"the",
"destination",
"object",
".",
"If",
"object",
"is",
"a",
"function",
"then",
"methods",
"are",
"added",
"to",
"its",
"prototype",
"as",
"well",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L24007-L24037 |
45,678 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | subtract | function subtract(minuend, subtrahend) {
var result;
if (minuend === undefined && subtrahend === undefined) {
return 0;
}
if (minuend !== undefined) {
result = minuend;
}
if (subtrahend !== undefined) {
result = result === undefined ? subtrahend : result - subtrahend;
}
return result;
} | javascript | function subtract(minuend, subtrahend) {
var result;
if (minuend === undefined && subtrahend === undefined) {
return 0;
}
if (minuend !== undefined) {
result = minuend;
}
if (subtrahend !== undefined) {
result = result === undefined ? subtrahend : result - subtrahend;
}
return result;
} | [
"function",
"subtract",
"(",
"minuend",
",",
"subtrahend",
")",
"{",
"var",
"result",
";",
"if",
"(",
"minuend",
"===",
"undefined",
"&&",
"subtrahend",
"===",
"undefined",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"minuend",
"!==",
"undefined",
")",
"{",
"result",
"=",
"minuend",
";",
"}",
"if",
"(",
"subtrahend",
"!==",
"undefined",
")",
"{",
"result",
"=",
"result",
"===",
"undefined",
"?",
"subtrahend",
":",
"result",
"-",
"subtrahend",
";",
"}",
"return",
"result",
";",
"}"
]
| Subtract two numbers.
@static
@memberOf _
@category Math
@param {number} minuend The first number in a subtraction.
@param {number} subtrahend The second number in a subtraction.
@returns {number} Returns the difference.
@example
_.subtract(6, 4);
// => 2 | [
"Subtract",
"two",
"numbers",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L24571-L24583 |
45,679 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | onWindowLoad | function onWindowLoad() {
self.isLoaded = true;
onPluginStart();
if (windowLoadListenderAttached) {
window.removeEventListener('load', onWindowLoad, false);
}
} | javascript | function onWindowLoad() {
self.isLoaded = true;
onPluginStart();
if (windowLoadListenderAttached) {
window.removeEventListener('load', onWindowLoad, false);
}
} | [
"function",
"onWindowLoad",
"(",
")",
"{",
"self",
".",
"isLoaded",
"=",
"true",
";",
"onPluginStart",
"(",
")",
";",
"if",
"(",
"windowLoadListenderAttached",
")",
"{",
"window",
".",
"removeEventListener",
"(",
"'load'",
",",
"onWindowLoad",
",",
"false",
")",
";",
"}",
"}"
]
| Setup listeners to know when we're ready to go. | [
"Setup",
"listeners",
"to",
"know",
"when",
"we",
"re",
"ready",
"to",
"go",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L25415-L25423 |
45,680 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | isCordova | function isCordova() {
var isCordova = null;
var idxIsCordova = window.location.search.indexOf('isCordova=');
if (idxIsCordova >= 0) {
var isCordova = window.location.search.substring(idxIsCordova + 10);
if (isCordova.indexOf('&') >= 0) {
isCordova = isCordova.substring(0, isCordova.indexOf('&'));
}
}
return (isCordova == 'true');
} | javascript | function isCordova() {
var isCordova = null;
var idxIsCordova = window.location.search.indexOf('isCordova=');
if (idxIsCordova >= 0) {
var isCordova = window.location.search.substring(idxIsCordova + 10);
if (isCordova.indexOf('&') >= 0) {
isCordova = isCordova.substring(0, isCordova.indexOf('&'));
}
}
return (isCordova == 'true');
} | [
"function",
"isCordova",
"(",
")",
"{",
"var",
"isCordova",
"=",
"null",
";",
"var",
"idxIsCordova",
"=",
"window",
".",
"location",
".",
"search",
".",
"indexOf",
"(",
"'isCordova='",
")",
";",
"if",
"(",
"idxIsCordova",
">=",
"0",
")",
"{",
"var",
"isCordova",
"=",
"window",
".",
"location",
".",
"search",
".",
"substring",
"(",
"idxIsCordova",
"+",
"10",
")",
";",
"if",
"(",
"isCordova",
".",
"indexOf",
"(",
"'&'",
")",
">=",
"0",
")",
"{",
"isCordova",
"=",
"isCordova",
".",
"substring",
"(",
"0",
",",
"isCordova",
".",
"indexOf",
"(",
"'&'",
")",
")",
";",
"}",
"}",
"return",
"(",
"isCordova",
"==",
"'true'",
")",
";",
"}"
]
| Get the isCordova boolean from the URL. | [
"Get",
"the",
"isCordova",
"boolean",
"from",
"the",
"URL",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L25573-L25584 |
45,681 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | createAccessors | function createAccessors(keys) {
var fname;
lodash.forEach(keys, function(key) {
key.replace(/[^\w\d-]/g, '');
// get<key>
fname = createFnName('get', key);
self[fname] = function() {
return getKey(ns + key);
};
// set<key>
fname = createFnName('set', key);
self[fname] = function(value) {
return setKey(ns + key, value);
};
// remove<key>
fname = createFnName('remove', key);
self[fname] = function() {
return removeKey(ns + key);
};
});
} | javascript | function createAccessors(keys) {
var fname;
lodash.forEach(keys, function(key) {
key.replace(/[^\w\d-]/g, '');
// get<key>
fname = createFnName('get', key);
self[fname] = function() {
return getKey(ns + key);
};
// set<key>
fname = createFnName('set', key);
self[fname] = function(value) {
return setKey(ns + key, value);
};
// remove<key>
fname = createFnName('remove', key);
self[fname] = function() {
return removeKey(ns + key);
};
});
} | [
"function",
"createAccessors",
"(",
"keys",
")",
"{",
"var",
"fname",
";",
"lodash",
".",
"forEach",
"(",
"keys",
",",
"function",
"(",
"key",
")",
"{",
"key",
".",
"replace",
"(",
"/",
"[^\\w\\d-]",
"/",
"g",
",",
"''",
")",
";",
"// get<key>",
"fname",
"=",
"createFnName",
"(",
"'get'",
",",
"key",
")",
";",
"self",
"[",
"fname",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"getKey",
"(",
"ns",
"+",
"key",
")",
";",
"}",
";",
"// set<key>",
"fname",
"=",
"createFnName",
"(",
"'set'",
",",
"key",
")",
";",
"self",
"[",
"fname",
"]",
"=",
"function",
"(",
"value",
")",
"{",
"return",
"setKey",
"(",
"ns",
"+",
"key",
",",
"value",
")",
";",
"}",
";",
"// remove<key>",
"fname",
"=",
"createFnName",
"(",
"'remove'",
",",
"key",
")",
";",
"self",
"[",
"fname",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"removeKey",
"(",
"ns",
"+",
"key",
")",
";",
"}",
";",
"}",
")",
";",
"}"
]
| Private functions
Create accessor functions for each key. | [
"Private",
"functions",
"Create",
"accessor",
"functions",
"for",
"each",
"key",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L26987-L27012 |
45,682 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | timeout | function timeout(message) {
$log.warn('Plugin client request timeout: ' + serialize(message));
var promiseIndex = lodash.findIndex(promises, function(promise) {
return promise.id == message.header.id;
});
if (promiseIndex >= 0) {
var promise = lodash.pullAt(promises, promiseIndex);
message.response = {
statusCode: 408,
statusText: 'REQUEST_TIMED_OUT',
data: {
message: 'Request timed out.'
}
}
promise[0].onComplete(message);
} else {
$log.warn('Message request timed out but there is no promise to fulfill: ' + serialize(message));
}
} | javascript | function timeout(message) {
$log.warn('Plugin client request timeout: ' + serialize(message));
var promiseIndex = lodash.findIndex(promises, function(promise) {
return promise.id == message.header.id;
});
if (promiseIndex >= 0) {
var promise = lodash.pullAt(promises, promiseIndex);
message.response = {
statusCode: 408,
statusText: 'REQUEST_TIMED_OUT',
data: {
message: 'Request timed out.'
}
}
promise[0].onComplete(message);
} else {
$log.warn('Message request timed out but there is no promise to fulfill: ' + serialize(message));
}
} | [
"function",
"timeout",
"(",
"message",
")",
"{",
"$log",
".",
"warn",
"(",
"'Plugin client request timeout: '",
"+",
"serialize",
"(",
"message",
")",
")",
";",
"var",
"promiseIndex",
"=",
"lodash",
".",
"findIndex",
"(",
"promises",
",",
"function",
"(",
"promise",
")",
"{",
"return",
"promise",
".",
"id",
"==",
"message",
".",
"header",
".",
"id",
";",
"}",
")",
";",
"if",
"(",
"promiseIndex",
">=",
"0",
")",
"{",
"var",
"promise",
"=",
"lodash",
".",
"pullAt",
"(",
"promises",
",",
"promiseIndex",
")",
";",
"message",
".",
"response",
"=",
"{",
"statusCode",
":",
"408",
",",
"statusText",
":",
"'REQUEST_TIMED_OUT'",
",",
"data",
":",
"{",
"message",
":",
"'Request timed out.'",
"}",
"}",
"promise",
"[",
"0",
"]",
".",
"onComplete",
"(",
"message",
")",
";",
"}",
"else",
"{",
"$log",
".",
"warn",
"(",
"'Message request timed out but there is no promise to fulfill: '",
"+",
"serialize",
"(",
"message",
")",
")",
";",
"}",
"}"
]
| Timeout a message waiting for a response. Enables the client app to process a message delivery failure. | [
"Timeout",
"a",
"message",
"waiting",
"for",
"a",
"response",
".",
"Enables",
"the",
"client",
"app",
"to",
"process",
"a",
"message",
"delivery",
"failure",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L28037-L28058 |
45,683 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | transport | function transport(message) {
return {
header: message.header,
request: message.request,
response: message.response
}
} | javascript | function transport(message) {
return {
header: message.header,
request: message.request,
response: message.response
}
} | [
"function",
"transport",
"(",
"message",
")",
"{",
"return",
"{",
"header",
":",
"message",
".",
"header",
",",
"request",
":",
"message",
".",
"request",
",",
"response",
":",
"message",
".",
"response",
"}",
"}"
]
| Only these properties of a message are sent and received. | [
"Only",
"these",
"properties",
"of",
"a",
"message",
"are",
"sent",
"and",
"received",
"."
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L28069-L28075 |
45,684 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | match | function match(mapEntry, request, route) {
var keys = [];
var m = pathToRegexpService.pathToRegexp(mapEntry.path, keys).exec(request.url);
if (!m) {
return false;
}
if (mapEntry.method != request.method) {
return false;
}
route.params = {};
route.path = m[0];
route.handler = mapEntry.handler;
// Assign url parameters to the request.
for (var i = 1; i < m.length; i++) {
var key = keys[i - 1];
var prop = key.name;
var val = decodeParam(m[i]);
if (val !== undefined || !(hasOwnProperty.call(route.params, prop))) {
route.params[prop] = val;
}
}
request.params = route.params;
return true;
} | javascript | function match(mapEntry, request, route) {
var keys = [];
var m = pathToRegexpService.pathToRegexp(mapEntry.path, keys).exec(request.url);
if (!m) {
return false;
}
if (mapEntry.method != request.method) {
return false;
}
route.params = {};
route.path = m[0];
route.handler = mapEntry.handler;
// Assign url parameters to the request.
for (var i = 1; i < m.length; i++) {
var key = keys[i - 1];
var prop = key.name;
var val = decodeParam(m[i]);
if (val !== undefined || !(hasOwnProperty.call(route.params, prop))) {
route.params[prop] = val;
}
}
request.params = route.params;
return true;
} | [
"function",
"match",
"(",
"mapEntry",
",",
"request",
",",
"route",
")",
"{",
"var",
"keys",
"=",
"[",
"]",
";",
"var",
"m",
"=",
"pathToRegexpService",
".",
"pathToRegexp",
"(",
"mapEntry",
".",
"path",
",",
"keys",
")",
".",
"exec",
"(",
"request",
".",
"url",
")",
";",
"if",
"(",
"!",
"m",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"mapEntry",
".",
"method",
"!=",
"request",
".",
"method",
")",
"{",
"return",
"false",
";",
"}",
"route",
".",
"params",
"=",
"{",
"}",
";",
"route",
".",
"path",
"=",
"m",
"[",
"0",
"]",
";",
"route",
".",
"handler",
"=",
"mapEntry",
".",
"handler",
";",
"// Assign url parameters to the request.",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"m",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"-",
"1",
"]",
";",
"var",
"prop",
"=",
"key",
".",
"name",
";",
"var",
"val",
"=",
"decodeParam",
"(",
"m",
"[",
"i",
"]",
")",
";",
"if",
"(",
"val",
"!==",
"undefined",
"||",
"!",
"(",
"hasOwnProperty",
".",
"call",
"(",
"route",
".",
"params",
",",
"prop",
")",
")",
")",
"{",
"route",
".",
"params",
"[",
"prop",
"]",
"=",
"val",
";",
"}",
"}",
"request",
".",
"params",
"=",
"route",
".",
"params",
";",
"return",
"true",
";",
"}"
]
| Private static methods | [
"Private",
"static",
"methods"
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L28220-L28250 |
45,685 | owstack/ows-wallet-plugin-client | release/ows-wallet-client.js | setConfig | function setConfig(configs) {
configProperties = platformConfigs;
provider.platform[platformName] = {};
addConfig(configProperties, configProperties.platform[platformName]);
createConfig(configProperties.platform[platformName], provider.platform[platformName], '');
} | javascript | function setConfig(configs) {
configProperties = platformConfigs;
provider.platform[platformName] = {};
addConfig(configProperties, configProperties.platform[platformName]);
createConfig(configProperties.platform[platformName], provider.platform[platformName], '');
} | [
"function",
"setConfig",
"(",
"configs",
")",
"{",
"configProperties",
"=",
"platformConfigs",
";",
"provider",
".",
"platform",
"[",
"platformName",
"]",
"=",
"{",
"}",
";",
"addConfig",
"(",
"configProperties",
",",
"configProperties",
".",
"platform",
"[",
"platformName",
"]",
")",
";",
"createConfig",
"(",
"configProperties",
".",
"platform",
"[",
"platformName",
"]",
",",
"provider",
".",
"platform",
"[",
"platformName",
"]",
",",
"''",
")",
";",
"}"
]
| Used to set configs | [
"Used",
"to",
"set",
"configs"
]
| 431b510a0f10670a831e937a3f8a1f7e09dfca35 | https://github.com/owstack/ows-wallet-plugin-client/blob/431b510a0f10670a831e937a3f8a1f7e09dfca35/release/ows-wallet-client.js#L28644-L28651 |
45,686 | tomasbasham/ember-cli-pubnub | index.js | function(app) {
this._super(app);
const vendorTree = this.treePaths.vendor;
// Import the PubNub package and shim.
app.import(`${vendorTree}/pubnub.js`);
app.import(`${vendorTree}/shims/pubnub.js`, {
exports: {
PubNub: ['default']
}
});
} | javascript | function(app) {
this._super(app);
const vendorTree = this.treePaths.vendor;
// Import the PubNub package and shim.
app.import(`${vendorTree}/pubnub.js`);
app.import(`${vendorTree}/shims/pubnub.js`, {
exports: {
PubNub: ['default']
}
});
} | [
"function",
"(",
"app",
")",
"{",
"this",
".",
"_super",
"(",
"app",
")",
";",
"const",
"vendorTree",
"=",
"this",
".",
"treePaths",
".",
"vendor",
";",
"// Import the PubNub package and shim.",
"app",
".",
"import",
"(",
"`",
"${",
"vendorTree",
"}",
"`",
")",
";",
"app",
".",
"import",
"(",
"`",
"${",
"vendorTree",
"}",
"`",
",",
"{",
"exports",
":",
"{",
"PubNub",
":",
"[",
"'default'",
"]",
"}",
"}",
")",
";",
"}"
]
| Add the PubNub JavaScript package
to the consuming application and
expose the vendor shim enabling it
to be imported as an es6 module.
@method included
@param {Object} app
An EmberApp instance. | [
"Add",
"the",
"PubNub",
"JavaScript",
"package",
"to",
"the",
"consuming",
"application",
"and",
"expose",
"the",
"vendor",
"shim",
"enabling",
"it",
"to",
"be",
"imported",
"as",
"an",
"es6",
"module",
"."
]
| b758063df6989b0ce5ceee4f832ff4aeff08d036 | https://github.com/tomasbasham/ember-cli-pubnub/blob/b758063df6989b0ce5ceee4f832ff4aeff08d036/index.js#L21-L33 |
|
45,687 | tomasbasham/ember-cli-pubnub | index.js | function(vendorTree) {
const pubnubPath = path.dirname(require.resolve('pubnub/dist/web/pubnub.js'));
const pubnubTree = new Funnel(pubnubPath, {
src: 'pubnub.js',
dest: './',
annotation: 'Funnel (PubNub)'
});
return mergeTrees([vendorTree, pubnubTree]);
} | javascript | function(vendorTree) {
const pubnubPath = path.dirname(require.resolve('pubnub/dist/web/pubnub.js'));
const pubnubTree = new Funnel(pubnubPath, {
src: 'pubnub.js',
dest: './',
annotation: 'Funnel (PubNub)'
});
return mergeTrees([vendorTree, pubnubTree]);
} | [
"function",
"(",
"vendorTree",
")",
"{",
"const",
"pubnubPath",
"=",
"path",
".",
"dirname",
"(",
"require",
".",
"resolve",
"(",
"'pubnub/dist/web/pubnub.js'",
")",
")",
";",
"const",
"pubnubTree",
"=",
"new",
"Funnel",
"(",
"pubnubPath",
",",
"{",
"src",
":",
"'pubnub.js'",
",",
"dest",
":",
"'./'",
",",
"annotation",
":",
"'Funnel (PubNub)'",
"}",
")",
";",
"return",
"mergeTrees",
"(",
"[",
"vendorTree",
",",
"pubnubTree",
"]",
")",
";",
"}"
]
| Resolve the path to the PubNub web
bundle and transpose the files in
that path into the project's vendor
folder during build time.
@method treeForVendor
@params {Object} vendorTree
The broccoli tree representing vendor files. | [
"Resolve",
"the",
"path",
"to",
"the",
"PubNub",
"web",
"bundle",
"and",
"transpose",
"the",
"files",
"in",
"that",
"path",
"into",
"the",
"project",
"s",
"vendor",
"folder",
"during",
"build",
"time",
"."
]
| b758063df6989b0ce5ceee4f832ff4aeff08d036 | https://github.com/tomasbasham/ember-cli-pubnub/blob/b758063df6989b0ce5ceee4f832ff4aeff08d036/index.js#L46-L55 |
|
45,688 | theboyWhoCriedWoolf/transition-manager | src/utils/default.js | defaultProps | function defaultProps( target, overwrite )
{
overwrite = overwrite || {};
for( var prop in overwrite ) {
if( target.hasOwnProperty(prop) && _isValid( overwrite[ prop ] ) ) {
target[ prop ] = overwrite[ prop ];
}
}
return target;
} | javascript | function defaultProps( target, overwrite )
{
overwrite = overwrite || {};
for( var prop in overwrite ) {
if( target.hasOwnProperty(prop) && _isValid( overwrite[ prop ] ) ) {
target[ prop ] = overwrite[ prop ];
}
}
return target;
} | [
"function",
"defaultProps",
"(",
"target",
",",
"overwrite",
")",
"{",
"overwrite",
"=",
"overwrite",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"prop",
"in",
"overwrite",
")",
"{",
"if",
"(",
"target",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"_isValid",
"(",
"overwrite",
"[",
"prop",
"]",
")",
")",
"{",
"target",
"[",
"prop",
"]",
"=",
"overwrite",
"[",
"prop",
"]",
";",
"}",
"}",
"return",
"target",
";",
"}"
]
| replace target object properties with the overwrite
object properties if they have been set
@param {object} target - object to overwrite
@param {object} overwrite - object with new properies and values
@return {object} | [
"replace",
"target",
"object",
"properties",
"with",
"the",
"overwrite",
"object",
"properties",
"if",
"they",
"have",
"been",
"set"
]
| a20fda0bb07c0098bf709ea03770b1ee2a855655 | https://github.com/theboyWhoCriedWoolf/transition-manager/blob/a20fda0bb07c0098bf709ea03770b1ee2a855655/src/utils/default.js#L11-L20 |
45,689 | AlmogBaku/grunt-hook | tasks/hook.js | function(action, weight) {
if(weight===undefined) {
weight=0;
}
this.tasks.push({ name: action, weight: weight});
} | javascript | function(action, weight) {
if(weight===undefined) {
weight=0;
}
this.tasks.push({ name: action, weight: weight});
} | [
"function",
"(",
"action",
",",
"weight",
")",
"{",
"if",
"(",
"weight",
"===",
"undefined",
")",
"{",
"weight",
"=",
"0",
";",
"}",
"this",
".",
"tasks",
".",
"push",
"(",
"{",
"name",
":",
"action",
",",
"weight",
":",
"weight",
"}",
")",
";",
"}"
]
| Push new task
@param action
@param weight | [
"Push",
"new",
"task"
]
| dae10b5d12b49f2de94567545d40b6dea9830804 | https://github.com/AlmogBaku/grunt-hook/blob/dae10b5d12b49f2de94567545d40b6dea9830804/tasks/hook.js#L21-L26 |
|
45,690 | AlmogBaku/grunt-hook | tasks/hook.js | function () {
var tasks = this.tasks.sort(function(a,b) {
if (a.weight < b.weight) {
return -1;
} if (a.weight > b.weight) {
return 1;
}
return 0;
});
var queue = [];
for(var i=0;i<tasks.length; i+=1) {
queue.push(tasks[i].name);
}
return queue;
} | javascript | function () {
var tasks = this.tasks.sort(function(a,b) {
if (a.weight < b.weight) {
return -1;
} if (a.weight > b.weight) {
return 1;
}
return 0;
});
var queue = [];
for(var i=0;i<tasks.length; i+=1) {
queue.push(tasks[i].name);
}
return queue;
} | [
"function",
"(",
")",
"{",
"var",
"tasks",
"=",
"this",
".",
"tasks",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
".",
"weight",
"<",
"b",
".",
"weight",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"a",
".",
"weight",
">",
"b",
".",
"weight",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}",
")",
";",
"var",
"queue",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tasks",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"queue",
".",
"push",
"(",
"tasks",
"[",
"i",
"]",
".",
"name",
")",
";",
"}",
"return",
"queue",
";",
"}"
]
| Get all tasks ordered by weight
@returns {Array} | [
"Get",
"all",
"tasks",
"ordered",
"by",
"weight"
]
| dae10b5d12b49f2de94567545d40b6dea9830804 | https://github.com/AlmogBaku/grunt-hook/blob/dae10b5d12b49f2de94567545d40b6dea9830804/tasks/hook.js#L32-L47 |
|
45,691 | jokemmy/promisynch | src/index.js | throwWapper | function throwWapper( callback ) {
return function( resultSet ) {
callback(
resultSet.err || null,
resultSet.err ? null : resultSet.result,
...resultSet.argument
);
if ( resultSet.err ) {
throw resultSet.err;
}
return resultSet;
};
} | javascript | function throwWapper( callback ) {
return function( resultSet ) {
callback(
resultSet.err || null,
resultSet.err ? null : resultSet.result,
...resultSet.argument
);
if ( resultSet.err ) {
throw resultSet.err;
}
return resultSet;
};
} | [
"function",
"throwWapper",
"(",
"callback",
")",
"{",
"return",
"function",
"(",
"resultSet",
")",
"{",
"callback",
"(",
"resultSet",
".",
"err",
"||",
"null",
",",
"resultSet",
".",
"err",
"?",
"null",
":",
"resultSet",
".",
"result",
",",
"...",
"resultSet",
".",
"argument",
")",
";",
"if",
"(",
"resultSet",
".",
"err",
")",
"{",
"throw",
"resultSet",
".",
"err",
";",
"}",
"return",
"resultSet",
";",
"}",
";",
"}"
]
| use in finally method, catch a error and throw this error or throw the last error | [
"use",
"in",
"finally",
"method",
"catch",
"a",
"error",
"and",
"throw",
"this",
"error",
"or",
"throw",
"the",
"last",
"error"
]
| 80a239d169dfb5c74eea356da031c756d6237115 | https://github.com/jokemmy/promisynch/blob/80a239d169dfb5c74eea356da031c756d6237115/src/index.js#L72-L84 |
45,692 | OpenSmartEnvironment/ose | lib/kind.js | init | function init(schema, name) { // {{{2
/**
* Kind constructor
*
* @param schema {Object|String} Schema containing the kind
* @param name {String} Unique kind name within the schema
*
* @method constructor
*/
this.name = name; // {{{3
/**
* Kind name unique within a schema
*
* @property name
* @type String
*/
this.schema = typeof schema === 'string' ? // {{{3
O.data.schemas[schema] :
schema
;
/**
* Schema to which the kind is assigned
*
* @property schema
* @type Object
*/
if (! this.schema) {
throw O.log.error('Missing schema', schema);
}
if (this.name in this.schema.kinds) {
throw O.log.error(this.schema, 'Duplicit kind', this.name);
}
this.schema.kinds[this.name] = this;
// }}}3
// O.callChain(this, 'init')();
// console.log('KIND INIT', this.schema.name, this.name);
} | javascript | function init(schema, name) { // {{{2
/**
* Kind constructor
*
* @param schema {Object|String} Schema containing the kind
* @param name {String} Unique kind name within the schema
*
* @method constructor
*/
this.name = name; // {{{3
/**
* Kind name unique within a schema
*
* @property name
* @type String
*/
this.schema = typeof schema === 'string' ? // {{{3
O.data.schemas[schema] :
schema
;
/**
* Schema to which the kind is assigned
*
* @property schema
* @type Object
*/
if (! this.schema) {
throw O.log.error('Missing schema', schema);
}
if (this.name in this.schema.kinds) {
throw O.log.error(this.schema, 'Duplicit kind', this.name);
}
this.schema.kinds[this.name] = this;
// }}}3
// O.callChain(this, 'init')();
// console.log('KIND INIT', this.schema.name, this.name);
} | [
"function",
"init",
"(",
"schema",
",",
"name",
")",
"{",
"// {{{2",
"/**\n * Kind constructor\n *\n * @param schema {Object|String} Schema containing the kind\n * @param name {String} Unique kind name within the schema\n *\n * @method constructor\n */",
"this",
".",
"name",
"=",
"name",
";",
"// {{{3",
"/**\n * Kind name unique within a schema\n *\n * @property name\n * @type String\n */",
"this",
".",
"schema",
"=",
"typeof",
"schema",
"===",
"'string'",
"?",
"// {{{3",
"O",
".",
"data",
".",
"schemas",
"[",
"schema",
"]",
":",
"schema",
";",
"/**\n * Schema to which the kind is assigned\n *\n * @property schema\n * @type Object\n */",
"if",
"(",
"!",
"this",
".",
"schema",
")",
"{",
"throw",
"O",
".",
"log",
".",
"error",
"(",
"'Missing schema'",
",",
"schema",
")",
";",
"}",
"if",
"(",
"this",
".",
"name",
"in",
"this",
".",
"schema",
".",
"kinds",
")",
"{",
"throw",
"O",
".",
"log",
".",
"error",
"(",
"this",
".",
"schema",
",",
"'Duplicit kind'",
",",
"this",
".",
"name",
")",
";",
"}",
"this",
".",
"schema",
".",
"kinds",
"[",
"this",
".",
"name",
"]",
"=",
"this",
";",
"// }}}3",
"// O.callChain(this, 'init')();",
"// console.log('KIND INIT', this.schema.name, this.name);",
"}"
]
| `entry.dval` structure description
Contains an [ose/lib/field/object] instance
@property ddef
@type Object
Public {{{1 | [
"entry",
".",
"dval",
"structure",
"description"
]
| 2ab051d9db6e77341c40abb9cbdae6ce586917e0 | https://github.com/OpenSmartEnvironment/ose/blob/2ab051d9db6e77341c40abb9cbdae6ce586917e0/lib/kind.js#L47-L92 |
45,693 | DriveTimeInc/gangplank | lib/validator.js | isException | function isException(url, exceptions) {
if (exceptions && Array.isArray(exceptions)) {
for (let i = 0; i < exceptions.length; i++) {
if ((new RegExp(exceptions[i])).test(expressUtility.getBaseRoute(url))) {
// Found exception
return true;
}
}
}
return false;
} | javascript | function isException(url, exceptions) {
if (exceptions && Array.isArray(exceptions)) {
for (let i = 0; i < exceptions.length; i++) {
if ((new RegExp(exceptions[i])).test(expressUtility.getBaseRoute(url))) {
// Found exception
return true;
}
}
}
return false;
} | [
"function",
"isException",
"(",
"url",
",",
"exceptions",
")",
"{",
"if",
"(",
"exceptions",
"&&",
"Array",
".",
"isArray",
"(",
"exceptions",
")",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"exceptions",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"new",
"RegExp",
"(",
"exceptions",
"[",
"i",
"]",
")",
")",
".",
"test",
"(",
"expressUtility",
".",
"getBaseRoute",
"(",
"url",
")",
")",
")",
"{",
"// Found exception",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Determines if the current route is an exception and thus will not be considered missing.
@param {string} url
@param {Array<string>} exceptions | [
"Determines",
"if",
"the",
"current",
"route",
"is",
"an",
"exception",
"and",
"thus",
"will",
"not",
"be",
"considered",
"missing",
"."
]
| d7eed36d4ea9d18c537884548b59460ec8bd9b5e | https://github.com/DriveTimeInc/gangplank/blob/d7eed36d4ea9d18c537884548b59460ec8bd9b5e/lib/validator.js#L33-L43 |
45,694 | DriveTimeInc/gangplank | lib/validator.js | preCast | function preCast(value, parameterDefinition) {
switch (parameterDefinition.type) {
case 'array': {
let values;
switch (parameterDefinition.collectionFormat) {
case 'ssv':
values = value.split(' ');
break;
case 'tsv':
values = value.split('\t');
break;
case 'pipes':
values = value.split('|');
break;
case 'csv':
default:
values = value.split(',');
break;
}
const result = values.map(v => {
return preCast(v, parameterDefinition.items);
});
return result;
}
case 'boolean': {
if (typeof (value) == 'string') {
return value.toLowerCase() === 'true' || value.toLowerCase() === 'false' ?
value.toLowerCase() === 'true' :
value;
} else {
return value;
}
}
case 'integer': {
const result = Number(value);
return Number.isInteger(result) ? result : value;
}
case 'number': {
const result = Number(value);
return Number.isNaN(result) ? value : result;
}
case 'object': {
try {
return JSON.parse(value);
} catch (ex) {
return value;
}
}
default: {
return value;
}
}
} | javascript | function preCast(value, parameterDefinition) {
switch (parameterDefinition.type) {
case 'array': {
let values;
switch (parameterDefinition.collectionFormat) {
case 'ssv':
values = value.split(' ');
break;
case 'tsv':
values = value.split('\t');
break;
case 'pipes':
values = value.split('|');
break;
case 'csv':
default:
values = value.split(',');
break;
}
const result = values.map(v => {
return preCast(v, parameterDefinition.items);
});
return result;
}
case 'boolean': {
if (typeof (value) == 'string') {
return value.toLowerCase() === 'true' || value.toLowerCase() === 'false' ?
value.toLowerCase() === 'true' :
value;
} else {
return value;
}
}
case 'integer': {
const result = Number(value);
return Number.isInteger(result) ? result : value;
}
case 'number': {
const result = Number(value);
return Number.isNaN(result) ? value : result;
}
case 'object': {
try {
return JSON.parse(value);
} catch (ex) {
return value;
}
}
default: {
return value;
}
}
} | [
"function",
"preCast",
"(",
"value",
",",
"parameterDefinition",
")",
"{",
"switch",
"(",
"parameterDefinition",
".",
"type",
")",
"{",
"case",
"'array'",
":",
"{",
"let",
"values",
";",
"switch",
"(",
"parameterDefinition",
".",
"collectionFormat",
")",
"{",
"case",
"'ssv'",
":",
"values",
"=",
"value",
".",
"split",
"(",
"' '",
")",
";",
"break",
";",
"case",
"'tsv'",
":",
"values",
"=",
"value",
".",
"split",
"(",
"'\\t'",
")",
";",
"break",
";",
"case",
"'pipes'",
":",
"values",
"=",
"value",
".",
"split",
"(",
"'|'",
")",
";",
"break",
";",
"case",
"'csv'",
":",
"default",
":",
"values",
"=",
"value",
".",
"split",
"(",
"','",
")",
";",
"break",
";",
"}",
"const",
"result",
"=",
"values",
".",
"map",
"(",
"v",
"=>",
"{",
"return",
"preCast",
"(",
"v",
",",
"parameterDefinition",
".",
"items",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}",
"case",
"'boolean'",
":",
"{",
"if",
"(",
"typeof",
"(",
"value",
")",
"==",
"'string'",
")",
"{",
"return",
"value",
".",
"toLowerCase",
"(",
")",
"===",
"'true'",
"||",
"value",
".",
"toLowerCase",
"(",
")",
"===",
"'false'",
"?",
"value",
".",
"toLowerCase",
"(",
")",
"===",
"'true'",
":",
"value",
";",
"}",
"else",
"{",
"return",
"value",
";",
"}",
"}",
"case",
"'integer'",
":",
"{",
"const",
"result",
"=",
"Number",
"(",
"value",
")",
";",
"return",
"Number",
".",
"isInteger",
"(",
"result",
")",
"?",
"result",
":",
"value",
";",
"}",
"case",
"'number'",
":",
"{",
"const",
"result",
"=",
"Number",
"(",
"value",
")",
";",
"return",
"Number",
".",
"isNaN",
"(",
"result",
")",
"?",
"value",
":",
"result",
";",
"}",
"case",
"'object'",
":",
"{",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"value",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"return",
"value",
";",
"}",
"}",
"default",
":",
"{",
"return",
"value",
";",
"}",
"}",
"}"
]
| Casts raw values from the request before they are validated | [
"Casts",
"raw",
"values",
"from",
"the",
"request",
"before",
"they",
"are",
"validated"
]
| d7eed36d4ea9d18c537884548b59460ec8bd9b5e | https://github.com/DriveTimeInc/gangplank/blob/d7eed36d4ea9d18c537884548b59460ec8bd9b5e/lib/validator.js#L120-L175 |
45,695 | DriveTimeInc/gangplank | lib/validator.js | postCast | function postCast(value, parameterDefinition) {
const type = parameterDefinition.type;
const format = parameterDefinition.format;
if (type === 'string' && (format === 'date' || format === 'date-time')) {
return new Date(value);
} else {
return value;
}
} | javascript | function postCast(value, parameterDefinition) {
const type = parameterDefinition.type;
const format = parameterDefinition.format;
if (type === 'string' && (format === 'date' || format === 'date-time')) {
return new Date(value);
} else {
return value;
}
} | [
"function",
"postCast",
"(",
"value",
",",
"parameterDefinition",
")",
"{",
"const",
"type",
"=",
"parameterDefinition",
".",
"type",
";",
"const",
"format",
"=",
"parameterDefinition",
".",
"format",
";",
"if",
"(",
"type",
"===",
"'string'",
"&&",
"(",
"format",
"===",
"'date'",
"||",
"format",
"===",
"'date-time'",
")",
")",
"{",
"return",
"new",
"Date",
"(",
"value",
")",
";",
"}",
"else",
"{",
"return",
"value",
";",
"}",
"}"
]
| Casts values AFTER validated to support string formats | [
"Casts",
"values",
"AFTER",
"validated",
"to",
"support",
"string",
"formats"
]
| d7eed36d4ea9d18c537884548b59460ec8bd9b5e | https://github.com/DriveTimeInc/gangplank/blob/d7eed36d4ea9d18c537884548b59460ec8bd9b5e/lib/validator.js#L178-L186 |
45,696 | mikolalysenko/grid-mesh | grid.js | gridMesh | function gridMesh(nx, ny, origin, dx, dy) {
//Unpack default arguments
origin = origin || [0,0]
if(!dx || dx.length < origin.length) {
dx = dup(origin.length)
if(origin.length > 0) {
dx[0] = 1
}
}
if(!dy || dy.length < origin.length) {
dy = dup(origin.length)
if(origin.length > 1) {
dy[1] = 1
}
}
//Initialize cells
var cells = []
, positions = dup([(nx+1) * (ny+1), origin.length])
, i, j, k, q, d = origin.length
for(j=0; j<ny; ++j) {
for(i=0; i<nx; ++i) {
cells.push([ p(i,j,nx), p(i+1, j,nx), p(i, j+1,nx) ])
cells.push([ p(i+1,j,nx), p(i+1,j+1,nx), p(i,j+1,nx) ])
}
}
//Initialize positions
for(j=0; j<=ny; ++j) {
for(i=0; i<=nx; ++i) {
q = positions[ p(i, j, nx) ]
for(k=0; k<d; ++k) {
q[k] = origin[k] + dx[k] * i + dy[k] * j
}
}
}
return {
positions: positions,
cells: cells
}
} | javascript | function gridMesh(nx, ny, origin, dx, dy) {
//Unpack default arguments
origin = origin || [0,0]
if(!dx || dx.length < origin.length) {
dx = dup(origin.length)
if(origin.length > 0) {
dx[0] = 1
}
}
if(!dy || dy.length < origin.length) {
dy = dup(origin.length)
if(origin.length > 1) {
dy[1] = 1
}
}
//Initialize cells
var cells = []
, positions = dup([(nx+1) * (ny+1), origin.length])
, i, j, k, q, d = origin.length
for(j=0; j<ny; ++j) {
for(i=0; i<nx; ++i) {
cells.push([ p(i,j,nx), p(i+1, j,nx), p(i, j+1,nx) ])
cells.push([ p(i+1,j,nx), p(i+1,j+1,nx), p(i,j+1,nx) ])
}
}
//Initialize positions
for(j=0; j<=ny; ++j) {
for(i=0; i<=nx; ++i) {
q = positions[ p(i, j, nx) ]
for(k=0; k<d; ++k) {
q[k] = origin[k] + dx[k] * i + dy[k] * j
}
}
}
return {
positions: positions,
cells: cells
}
} | [
"function",
"gridMesh",
"(",
"nx",
",",
"ny",
",",
"origin",
",",
"dx",
",",
"dy",
")",
"{",
"//Unpack default arguments",
"origin",
"=",
"origin",
"||",
"[",
"0",
",",
"0",
"]",
"if",
"(",
"!",
"dx",
"||",
"dx",
".",
"length",
"<",
"origin",
".",
"length",
")",
"{",
"dx",
"=",
"dup",
"(",
"origin",
".",
"length",
")",
"if",
"(",
"origin",
".",
"length",
">",
"0",
")",
"{",
"dx",
"[",
"0",
"]",
"=",
"1",
"}",
"}",
"if",
"(",
"!",
"dy",
"||",
"dy",
".",
"length",
"<",
"origin",
".",
"length",
")",
"{",
"dy",
"=",
"dup",
"(",
"origin",
".",
"length",
")",
"if",
"(",
"origin",
".",
"length",
">",
"1",
")",
"{",
"dy",
"[",
"1",
"]",
"=",
"1",
"}",
"}",
"//Initialize cells",
"var",
"cells",
"=",
"[",
"]",
",",
"positions",
"=",
"dup",
"(",
"[",
"(",
"nx",
"+",
"1",
")",
"*",
"(",
"ny",
"+",
"1",
")",
",",
"origin",
".",
"length",
"]",
")",
",",
"i",
",",
"j",
",",
"k",
",",
"q",
",",
"d",
"=",
"origin",
".",
"length",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"ny",
";",
"++",
"j",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"nx",
";",
"++",
"i",
")",
"{",
"cells",
".",
"push",
"(",
"[",
"p",
"(",
"i",
",",
"j",
",",
"nx",
")",
",",
"p",
"(",
"i",
"+",
"1",
",",
"j",
",",
"nx",
")",
",",
"p",
"(",
"i",
",",
"j",
"+",
"1",
",",
"nx",
")",
"]",
")",
"cells",
".",
"push",
"(",
"[",
"p",
"(",
"i",
"+",
"1",
",",
"j",
",",
"nx",
")",
",",
"p",
"(",
"i",
"+",
"1",
",",
"j",
"+",
"1",
",",
"nx",
")",
",",
"p",
"(",
"i",
",",
"j",
"+",
"1",
",",
"nx",
")",
"]",
")",
"}",
"}",
"//Initialize positions",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<=",
"ny",
";",
"++",
"j",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<=",
"nx",
";",
"++",
"i",
")",
"{",
"q",
"=",
"positions",
"[",
"p",
"(",
"i",
",",
"j",
",",
"nx",
")",
"]",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"d",
";",
"++",
"k",
")",
"{",
"q",
"[",
"k",
"]",
"=",
"origin",
"[",
"k",
"]",
"+",
"dx",
"[",
"k",
"]",
"*",
"i",
"+",
"dy",
"[",
"k",
"]",
"*",
"j",
"}",
"}",
"}",
"return",
"{",
"positions",
":",
"positions",
",",
"cells",
":",
"cells",
"}",
"}"
]
| Creates a grid mesh | [
"Creates",
"a",
"grid",
"mesh"
]
| 885fa9fd9ef08b6db6ac94c2bbc6ea967ed2e750 | https://github.com/mikolalysenko/grid-mesh/blob/885fa9fd9ef08b6db6ac94c2bbc6ea967ed2e750/grid.js#L8-L46 |
45,697 | thorn0/tinymce.html | tinymce.html.js | buildEntitiesLookup | function buildEntitiesLookup(items, radix) {
var i, chr, entity, lookup = {};
if (items) {
items = items.split(',');
radix = radix || 10;
// Build entities lookup table
for (i = 0; i < items.length; i += 2) {
chr = String.fromCharCode(parseInt(items[i], radix));
// Only add non base entities
if (!baseEntities[chr]) {
entity = '&' + items[i + 1] + ';';
lookup[chr] = entity;
lookup[entity] = chr;
}
}
return lookup;
}
} | javascript | function buildEntitiesLookup(items, radix) {
var i, chr, entity, lookup = {};
if (items) {
items = items.split(',');
radix = radix || 10;
// Build entities lookup table
for (i = 0; i < items.length; i += 2) {
chr = String.fromCharCode(parseInt(items[i], radix));
// Only add non base entities
if (!baseEntities[chr]) {
entity = '&' + items[i + 1] + ';';
lookup[chr] = entity;
lookup[entity] = chr;
}
}
return lookup;
}
} | [
"function",
"buildEntitiesLookup",
"(",
"items",
",",
"radix",
")",
"{",
"var",
"i",
",",
"chr",
",",
"entity",
",",
"lookup",
"=",
"{",
"}",
";",
"if",
"(",
"items",
")",
"{",
"items",
"=",
"items",
".",
"split",
"(",
"','",
")",
";",
"radix",
"=",
"radix",
"||",
"10",
";",
"// Build entities lookup table",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"items",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"chr",
"=",
"String",
".",
"fromCharCode",
"(",
"parseInt",
"(",
"items",
"[",
"i",
"]",
",",
"radix",
")",
")",
";",
"// Only add non base entities",
"if",
"(",
"!",
"baseEntities",
"[",
"chr",
"]",
")",
"{",
"entity",
"=",
"'&'",
"+",
"items",
"[",
"i",
"+",
"1",
"]",
"+",
"';'",
";",
"lookup",
"[",
"chr",
"]",
"=",
"entity",
";",
"lookup",
"[",
"entity",
"]",
"=",
"chr",
";",
"}",
"}",
"return",
"lookup",
";",
"}",
"}"
]
| Build a two way lookup table for the entities | [
"Build",
"a",
"two",
"way",
"lookup",
"table",
"for",
"the",
"entities"
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L340-L357 |
45,698 | thorn0/tinymce.html | tinymce.html.js | function(text, attr) {
return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
return baseEntities[chr] || chr;
});
} | javascript | function(text, attr) {
return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
return baseEntities[chr] || chr;
});
} | [
"function",
"(",
"text",
",",
"attr",
")",
"{",
"return",
"text",
".",
"replace",
"(",
"attr",
"?",
"attrsCharsRegExp",
":",
"textCharsRegExp",
",",
"function",
"(",
"chr",
")",
"{",
"return",
"baseEntities",
"[",
"chr",
"]",
"||",
"chr",
";",
"}",
")",
";",
"}"
]
| Encodes the specified string using raw entities. This means only the required XML base entities will be encoded.
@method encodeRaw
@param {String} text Text to encode.
@param {Boolean} attr Optional flag to specify if the text is attribute contents.
@return {String} Entity encoded text. | [
"Encodes",
"the",
"specified",
"string",
"using",
"raw",
"entities",
".",
"This",
"means",
"only",
"the",
"required",
"XML",
"base",
"entities",
"will",
"be",
"encoded",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L369-L373 |
|
45,699 | thorn0/tinymce.html | tinymce.html.js | function(text, attr, entities) {
entities = entities || namedEntities;
return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
return baseEntities[chr] || entities[chr] || chr;
});
} | javascript | function(text, attr, entities) {
entities = entities || namedEntities;
return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
return baseEntities[chr] || entities[chr] || chr;
});
} | [
"function",
"(",
"text",
",",
"attr",
",",
"entities",
")",
"{",
"entities",
"=",
"entities",
"||",
"namedEntities",
";",
"return",
"text",
".",
"replace",
"(",
"attr",
"?",
"attrsCharsRegExp",
":",
"textCharsRegExp",
",",
"function",
"(",
"chr",
")",
"{",
"return",
"baseEntities",
"[",
"chr",
"]",
"||",
"entities",
"[",
"chr",
"]",
"||",
"chr",
";",
"}",
")",
";",
"}"
]
| Encodes the specified string using named entities. The core entities will be encoded
as named ones but all non lower ascii characters will be encoded into named entities.
@method encodeNamed
@param {String} text Text to encode.
@param {Boolean} attr Optional flag to specify if the text is attribute contents.
@param {Object} entities Optional parameter with entities to use.
@return {String} Entity encoded text. | [
"Encodes",
"the",
"specified",
"string",
"using",
"named",
"entities",
".",
"The",
"core",
"entities",
"will",
"be",
"encoded",
"as",
"named",
"ones",
"but",
"all",
"non",
"lower",
"ascii",
"characters",
"will",
"be",
"encoded",
"into",
"named",
"entities",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L416-L421 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.