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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
55,100 | peerigon/alamid-sorted-array | lib/sortedArray.js | sortedIndex | function sortedIndex(element) {
/* jshint validthis:true */
var index = binarySearch(toArray(this), element, this.comparator);
if (index < 0) {
// binarySearch decreases the negative index by one because otherwise the index 0 would stand for two results
// @see https://github.com/darkskyapp/binary-search/issues/1
return Math.abs(index) - 1;
} else {
return index;
}
} | javascript | function sortedIndex(element) {
/* jshint validthis:true */
var index = binarySearch(toArray(this), element, this.comparator);
if (index < 0) {
// binarySearch decreases the negative index by one because otherwise the index 0 would stand for two results
// @see https://github.com/darkskyapp/binary-search/issues/1
return Math.abs(index) - 1;
} else {
return index;
}
} | [
"function",
"sortedIndex",
"(",
"element",
")",
"{",
"/* jshint validthis:true */",
"var",
"index",
"=",
"binarySearch",
"(",
"toArray",
"(",
"this",
")",
",",
"element",
",",
"this",
".",
"comparator",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"// binarySearch decreases the negative index by one because otherwise the index 0 would stand for two results",
"// @see https://github.com/darkskyapp/binary-search/issues/1",
"return",
"Math",
".",
"abs",
"(",
"index",
")",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"index",
";",
"}",
"}"
] | Returns the index where the given element would be inserted.
@param {*} element
@returns {Number} | [
"Returns",
"the",
"index",
"where",
"the",
"given",
"element",
"would",
"be",
"inserted",
"."
] | 59d58fd3b94d26c873c2a4ba2ecd18758309bd0b | https://github.com/peerigon/alamid-sorted-array/blob/59d58fd3b94d26c873c2a4ba2ecd18758309bd0b/lib/sortedArray.js#L188-L199 |
55,101 | peerigon/alamid-sorted-array | lib/sortedArray.js | pushSingle | function pushSingle(arr, element) {
var index = arr.sortedIndex(element),
_ = arr._sortedArray;
// original push and unshift are faster than splice
if (index === 0) {
_.unshift.call(arr, element);
} else if (index === arr.length) {
_.push.call(arr, element);
} else {
_.splice.call(arr, index, 0, element);
}
} | javascript | function pushSingle(arr, element) {
var index = arr.sortedIndex(element),
_ = arr._sortedArray;
// original push and unshift are faster than splice
if (index === 0) {
_.unshift.call(arr, element);
} else if (index === arr.length) {
_.push.call(arr, element);
} else {
_.splice.call(arr, index, 0, element);
}
} | [
"function",
"pushSingle",
"(",
"arr",
",",
"element",
")",
"{",
"var",
"index",
"=",
"arr",
".",
"sortedIndex",
"(",
"element",
")",
",",
"_",
"=",
"arr",
".",
"_sortedArray",
";",
"// original push and unshift are faster than splice",
"if",
"(",
"index",
"===",
"0",
")",
"{",
"_",
".",
"unshift",
".",
"call",
"(",
"arr",
",",
"element",
")",
";",
"}",
"else",
"if",
"(",
"index",
"===",
"arr",
".",
"length",
")",
"{",
"_",
".",
"push",
".",
"call",
"(",
"arr",
",",
"element",
")",
";",
"}",
"else",
"{",
"_",
".",
"splice",
".",
"call",
"(",
"arr",
",",
"index",
",",
"0",
",",
"element",
")",
";",
"}",
"}"
] | Performs a push of a single element. Used by push, unshift, splice.
@private
@param {Array} arr
@param {*} element | [
"Performs",
"a",
"push",
"of",
"a",
"single",
"element",
".",
"Used",
"by",
"push",
"unshift",
"splice",
"."
] | 59d58fd3b94d26c873c2a4ba2ecd18758309bd0b | https://github.com/peerigon/alamid-sorted-array/blob/59d58fd3b94d26c873c2a4ba2ecd18758309bd0b/lib/sortedArray.js#L208-L220 |
55,102 | peerigon/alamid-sorted-array | lib/sortedArray.js | getInversionOf | function getInversionOf(comparator) {
function inversion(a, b) {
return -comparator(a, b);
}
inversion.original = comparator;
return inversion;
} | javascript | function getInversionOf(comparator) {
function inversion(a, b) {
return -comparator(a, b);
}
inversion.original = comparator;
return inversion;
} | [
"function",
"getInversionOf",
"(",
"comparator",
")",
"{",
"function",
"inversion",
"(",
"a",
",",
"b",
")",
"{",
"return",
"-",
"comparator",
"(",
"a",
",",
"b",
")",
";",
"}",
"inversion",
".",
"original",
"=",
"comparator",
";",
"return",
"inversion",
";",
"}"
] | Inverts the given comparator so the array will be sorted reversed.
The original comparator is saved so it can be restored.
@private
@param {Function} comparator
@returns {Function} | [
"Inverts",
"the",
"given",
"comparator",
"so",
"the",
"array",
"will",
"be",
"sorted",
"reversed",
".",
"The",
"original",
"comparator",
"is",
"saved",
"so",
"it",
"can",
"be",
"restored",
"."
] | 59d58fd3b94d26c873c2a4ba2ecd18758309bd0b | https://github.com/peerigon/alamid-sorted-array/blob/59d58fd3b94d26c873c2a4ba2ecd18758309bd0b/lib/sortedArray.js#L230-L238 |
55,103 | peerigon/alamid-sorted-array | lib/sortedArray.js | multipleComparators | function multipleComparators(comparators) {
return function applyComparators(a, b) {
var i,
result;
for (i = 0; i < comparators.length; i++) {
result = comparators[i](a, b);
if (result !== 0) {
return result;
}
}
return defaultComparator(a, b);
};
} | javascript | function multipleComparators(comparators) {
return function applyComparators(a, b) {
var i,
result;
for (i = 0; i < comparators.length; i++) {
result = comparators[i](a, b);
if (result !== 0) {
return result;
}
}
return defaultComparator(a, b);
};
} | [
"function",
"multipleComparators",
"(",
"comparators",
")",
"{",
"return",
"function",
"applyComparators",
"(",
"a",
",",
"b",
")",
"{",
"var",
"i",
",",
"result",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"comparators",
".",
"length",
";",
"i",
"++",
")",
"{",
"result",
"=",
"comparators",
"[",
"i",
"]",
"(",
"a",
",",
"b",
")",
";",
"if",
"(",
"result",
"!==",
"0",
")",
"{",
"return",
"result",
";",
"}",
"}",
"return",
"defaultComparator",
"(",
"a",
",",
"b",
")",
";",
"}",
";",
"}"
] | Returns a single comparator which tries all given comparators one after another
and stops if one of them returned another value than 0.
If the end is reached the defaultComparator is applied.
@private
@param {Array} comparators
@returns {Function} | [
"Returns",
"a",
"single",
"comparator",
"which",
"tries",
"all",
"given",
"comparators",
"one",
"after",
"another",
"and",
"stops",
"if",
"one",
"of",
"them",
"returned",
"another",
"value",
"than",
"0",
"."
] | 59d58fd3b94d26c873c2a4ba2ecd18758309bd0b | https://github.com/peerigon/alamid-sorted-array/blob/59d58fd3b94d26c873c2a4ba2ecd18758309bd0b/lib/sortedArray.js#L299-L313 |
55,104 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inName, inValue) {
this.attributes[inName] = inValue;
if (this.hasNode()) {
this.attributeToNode(inName, inValue);
}
this.invalidateTags();
} | javascript | function(inName, inValue) {
this.attributes[inName] = inValue;
if (this.hasNode()) {
this.attributeToNode(inName, inValue);
}
this.invalidateTags();
} | [
"function",
"(",
"inName",
",",
"inValue",
")",
"{",
"this",
".",
"attributes",
"[",
"inName",
"]",
"=",
"inValue",
";",
"if",
"(",
"this",
".",
"hasNode",
"(",
")",
")",
"{",
"this",
".",
"attributeToNode",
"(",
"inName",
",",
"inValue",
")",
";",
"}",
"this",
".",
"invalidateTags",
"(",
")",
";",
"}"
] | Sets the value of an attribute on this object. Pass null _inValue_ to remove an attribute.
set the tabIndex attribute for this DomNode
this.setAttribute("tabIndex", 3);
...
remove the index attribute
this.setAttribute("index", null); | [
"Sets",
"the",
"value",
"of",
"an",
"attribute",
"on",
"this",
"object",
".",
"Pass",
"null",
"_inValue_",
"to",
"remove",
"an",
"attribute",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L177-L183 |
|
55,105 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inClass) {
if (inClass && !this.hasClass(inClass)) {
var c = this.getClassAttribute();
this.setClassAttribute(c + (c ? " " : "") + inClass);
}
} | javascript | function(inClass) {
if (inClass && !this.hasClass(inClass)) {
var c = this.getClassAttribute();
this.setClassAttribute(c + (c ? " " : "") + inClass);
}
} | [
"function",
"(",
"inClass",
")",
"{",
"if",
"(",
"inClass",
"&&",
"!",
"this",
".",
"hasClass",
"(",
"inClass",
")",
")",
"{",
"var",
"c",
"=",
"this",
".",
"getClassAttribute",
"(",
")",
";",
"this",
".",
"setClassAttribute",
"(",
"c",
"+",
"(",
"c",
"?",
"\" \"",
":",
"\"\"",
")",
"+",
"inClass",
")",
";",
"}",
"}"
] | Adds CSS class name _inClass_ to the _class_ attribute of this object.
add the highlight class to this object
this.addClass("highlight"); | [
"Adds",
"CSS",
"class",
"name",
"_inClass_",
"to",
"the",
"_class_",
"attribute",
"of",
"this",
"object",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L235-L240 |
|
55,106 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inClass) {
if (inClass && this.hasClass(inClass)) {
var c = this.getClassAttribute();
c = (" " + c + " ").replace(" " + inClass + " ", " ").slice(1, -1);
this.setClassAttribute(c);
}
} | javascript | function(inClass) {
if (inClass && this.hasClass(inClass)) {
var c = this.getClassAttribute();
c = (" " + c + " ").replace(" " + inClass + " ", " ").slice(1, -1);
this.setClassAttribute(c);
}
} | [
"function",
"(",
"inClass",
")",
"{",
"if",
"(",
"inClass",
"&&",
"this",
".",
"hasClass",
"(",
"inClass",
")",
")",
"{",
"var",
"c",
"=",
"this",
".",
"getClassAttribute",
"(",
")",
";",
"c",
"=",
"(",
"\" \"",
"+",
"c",
"+",
"\" \"",
")",
".",
"replace",
"(",
"\" \"",
"+",
"inClass",
"+",
"\" \"",
",",
"\" \"",
")",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"this",
".",
"setClassAttribute",
"(",
"c",
")",
";",
"}",
"}"
] | Removes substring _inClass_ from the _class_ attribute of this object.
_inClass_ must have no leading or trailing spaces.
Using a compound class name is supported, but the name is treated atomically.
For example, given "a b c", removeClass("a b") will produce "c", but removeClass("a c") will produce "a b c".
remove the highlight class from this object
this.removeClass("highlight"); | [
"Removes",
"substring",
"_inClass_",
"from",
"the",
"_class_",
"attribute",
"of",
"this",
"object",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L252-L258 |
|
55,107 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inParentNode) {
// clean up render flags and memoizations
this.teardownRender();
// inParentNode can be a string id or a node reference
var pn = enyo.dom.byId(inParentNode);
if (pn == document.body) {
this.setupBodyFitting();
} else if (this.fit) {
this.addClass("enyo-fit enyo-clip");
}
// generate our HTML
pn.innerHTML = this.generateHtml();
// post-rendering tasks
this.rendered();
// support method chaining
return this;
} | javascript | function(inParentNode) {
// clean up render flags and memoizations
this.teardownRender();
// inParentNode can be a string id or a node reference
var pn = enyo.dom.byId(inParentNode);
if (pn == document.body) {
this.setupBodyFitting();
} else if (this.fit) {
this.addClass("enyo-fit enyo-clip");
}
// generate our HTML
pn.innerHTML = this.generateHtml();
// post-rendering tasks
this.rendered();
// support method chaining
return this;
} | [
"function",
"(",
"inParentNode",
")",
"{",
"// clean up render flags and memoizations",
"this",
".",
"teardownRender",
"(",
")",
";",
"// inParentNode can be a string id or a node reference",
"var",
"pn",
"=",
"enyo",
".",
"dom",
".",
"byId",
"(",
"inParentNode",
")",
";",
"if",
"(",
"pn",
"==",
"document",
".",
"body",
")",
"{",
"this",
".",
"setupBodyFitting",
"(",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"fit",
")",
"{",
"this",
".",
"addClass",
"(",
"\"enyo-fit enyo-clip\"",
")",
";",
"}",
"// generate our HTML",
"pn",
".",
"innerHTML",
"=",
"this",
".",
"generateHtml",
"(",
")",
";",
"// post-rendering tasks",
"this",
".",
"rendered",
"(",
")",
";",
"// support method chaining",
"return",
"this",
";",
"}"
] | Renders this object into the DOM node referenced by _inParentNode_.
If rendering into the document body element, appropriate styles will
be used to have it expand to fill the whole window. | [
"Renders",
"this",
"object",
"into",
"the",
"DOM",
"node",
"referenced",
"by",
"_inParentNode_",
".",
"If",
"rendering",
"into",
"the",
"document",
"body",
"element",
"appropriate",
"styles",
"will",
"be",
"used",
"to",
"have",
"it",
"expand",
"to",
"fill",
"the",
"whole",
"window",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L365-L381 |
|
55,108 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inBounds, inUnit) {
var s = this.domStyles, unit = inUnit || "px";
var extents = ["width", "height", "left", "top", "right", "bottom"];
for (var i=0, b, e; e=extents[i]; i++) {
b = inBounds[e];
if (b || b === 0) {
s[e] = b + (!enyo.isString(b) ? unit : '');
}
}
this.domStylesChanged();
} | javascript | function(inBounds, inUnit) {
var s = this.domStyles, unit = inUnit || "px";
var extents = ["width", "height", "left", "top", "right", "bottom"];
for (var i=0, b, e; e=extents[i]; i++) {
b = inBounds[e];
if (b || b === 0) {
s[e] = b + (!enyo.isString(b) ? unit : '');
}
}
this.domStylesChanged();
} | [
"function",
"(",
"inBounds",
",",
"inUnit",
")",
"{",
"var",
"s",
"=",
"this",
".",
"domStyles",
",",
"unit",
"=",
"inUnit",
"||",
"\"px\"",
";",
"var",
"extents",
"=",
"[",
"\"width\"",
",",
"\"height\"",
",",
"\"left\"",
",",
"\"top\"",
",",
"\"right\"",
",",
"\"bottom\"",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"b",
",",
"e",
";",
"e",
"=",
"extents",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"b",
"=",
"inBounds",
"[",
"e",
"]",
";",
"if",
"(",
"b",
"||",
"b",
"===",
"0",
")",
"{",
"s",
"[",
"e",
"]",
"=",
"b",
"+",
"(",
"!",
"enyo",
".",
"isString",
"(",
"b",
")",
"?",
"unit",
":",
"''",
")",
";",
"}",
"}",
"this",
".",
"domStylesChanged",
"(",
")",
";",
"}"
] | Sets any or all of geometry style properties _width_, _height_, _left_, _top_, _right_ and _bottom_.
Values may be specified as strings (with units specified), or as numbers when a unit is provided in _inUnit_.
this.setBounds({width: 100, height: 100}, "px"); // adds style properties like "width: 100px; height: 100px;"
this.setBounds({width: "10em", right: "30pt"}); // adds style properties like "width: 10em; right: 30pt;" | [
"Sets",
"any",
"or",
"all",
"of",
"geometry",
"style",
"properties",
"_width_",
"_height_",
"_left_",
"_top_",
"_right_",
"and",
"_bottom_",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L452-L462 |
|
55,109 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/dom/Control.js | function(inName, inValue) {
if (inValue === null || inValue === false || inValue === "") {
this.node.removeAttribute(inName);
} else {
this.node.setAttribute(inName, inValue);
}
} | javascript | function(inName, inValue) {
if (inValue === null || inValue === false || inValue === "") {
this.node.removeAttribute(inName);
} else {
this.node.setAttribute(inName, inValue);
}
} | [
"function",
"(",
"inName",
",",
"inValue",
")",
"{",
"if",
"(",
"inValue",
"===",
"null",
"||",
"inValue",
"===",
"false",
"||",
"inValue",
"===",
"\"\"",
")",
"{",
"this",
".",
"node",
".",
"removeAttribute",
"(",
"inName",
")",
";",
"}",
"else",
"{",
"this",
".",
"node",
".",
"setAttribute",
"(",
"inName",
",",
"inValue",
")",
";",
"}",
"}"
] | DOM, aka direct-to-node, rendering | [
"DOM",
"aka",
"direct",
"-",
"to",
"-",
"node",
"rendering"
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/dom/Control.js#L566-L572 |
|
55,110 | tunnckoCore/simple-get-stream | index.js | simpleGetStream | function simpleGetStream (opts) {
var stream = through2()
stream.req = simpleGet.call(this, opts, function callback (err, res) {
stream.res = res
if (err) return stream.emit('error', err)
res.pipe(stream)
})
return stream
} | javascript | function simpleGetStream (opts) {
var stream = through2()
stream.req = simpleGet.call(this, opts, function callback (err, res) {
stream.res = res
if (err) return stream.emit('error', err)
res.pipe(stream)
})
return stream
} | [
"function",
"simpleGetStream",
"(",
"opts",
")",
"{",
"var",
"stream",
"=",
"through2",
"(",
")",
"stream",
".",
"req",
"=",
"simpleGet",
".",
"call",
"(",
"this",
",",
"opts",
",",
"function",
"callback",
"(",
"err",
",",
"res",
")",
"{",
"stream",
".",
"res",
"=",
"res",
"if",
"(",
"err",
")",
"return",
"stream",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
"res",
".",
"pipe",
"(",
"stream",
")",
"}",
")",
"return",
"stream",
"}"
] | > Request a page and return a response stream
**Example**
```js
const request = require('simple-get-stream')
const stream = request('http://www.tunnckocore.tk')
stream.once('error', console.error)
stream.pipe(process.stdout) // => html content of the page
```
@name simpleGetStream
@param {String|Object} `<opts>` Url or options object, passed to `simple-get`.
@return {Stream} Response stream instead of Request stream as `simple-get` does.
@api public | [
">",
"Request",
"a",
"page",
"and",
"return",
"a",
"response",
"stream"
] | bb68e95e1411bcf866fb202980bbf399a5899b04 | https://github.com/tunnckoCore/simple-get-stream/blob/bb68e95e1411bcf866fb202980bbf399a5899b04/index.js#L31-L39 |
55,111 | fibo/multidim-array-index | multidim-array-index.js | multiDimArrayIndex | function multiDimArrayIndex (dimensions, indices) {
// Check that indices fit inside dimensions shape.
for (var i = 0; i < dimensions.length; i++) {
if (indices[i] > dimensions[i]) {
throw new TypeError(error.outOfBoundIndex)
}
}
var order = dimensions.length
// Handle order 1
if (order === 1) return indices[0]
//* index = i_n + i_(n-1) * d_n + i_(n-2) * d_n * d_(n-1) + ... + i_2 * d_n * d_(n-1) * ... * d_3 + i_1 * d_n * ... * d_2
var n = order - 1
var factor = dimensions[n] // d_n
var index = indices[n] + factor * indices[n - 1] // i_n + i_(n-1) * d_n
for (var j = 2; j < order; j++) {
factor *= dimensions[n - j]
index += factor * indices[n - j]
}
return index
} | javascript | function multiDimArrayIndex (dimensions, indices) {
// Check that indices fit inside dimensions shape.
for (var i = 0; i < dimensions.length; i++) {
if (indices[i] > dimensions[i]) {
throw new TypeError(error.outOfBoundIndex)
}
}
var order = dimensions.length
// Handle order 1
if (order === 1) return indices[0]
//* index = i_n + i_(n-1) * d_n + i_(n-2) * d_n * d_(n-1) + ... + i_2 * d_n * d_(n-1) * ... * d_3 + i_1 * d_n * ... * d_2
var n = order - 1
var factor = dimensions[n] // d_n
var index = indices[n] + factor * indices[n - 1] // i_n + i_(n-1) * d_n
for (var j = 2; j < order; j++) {
factor *= dimensions[n - j]
index += factor * indices[n - j]
}
return index
} | [
"function",
"multiDimArrayIndex",
"(",
"dimensions",
",",
"indices",
")",
"{",
"// Check that indices fit inside dimensions shape.",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"dimensions",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"indices",
"[",
"i",
"]",
">",
"dimensions",
"[",
"i",
"]",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"error",
".",
"outOfBoundIndex",
")",
"}",
"}",
"var",
"order",
"=",
"dimensions",
".",
"length",
"// Handle order 1",
"if",
"(",
"order",
"===",
"1",
")",
"return",
"indices",
"[",
"0",
"]",
"//* index = i_n + i_(n-1) * d_n + i_(n-2) * d_n * d_(n-1) + ... + i_2 * d_n * d_(n-1) * ... * d_3 + i_1 * d_n * ... * d_2",
"var",
"n",
"=",
"order",
"-",
"1",
"var",
"factor",
"=",
"dimensions",
"[",
"n",
"]",
"// d_n",
"var",
"index",
"=",
"indices",
"[",
"n",
"]",
"+",
"factor",
"*",
"indices",
"[",
"n",
"-",
"1",
"]",
"// i_n + i_(n-1) * d_n",
"for",
"(",
"var",
"j",
"=",
"2",
";",
"j",
"<",
"order",
";",
"j",
"++",
")",
"{",
"factor",
"*=",
"dimensions",
"[",
"n",
"-",
"j",
"]",
"index",
"+=",
"factor",
"*",
"indices",
"[",
"n",
"-",
"j",
"]",
"}",
"return",
"index",
"}"
] | Maps multidimensional array indices to monodimensional array index
Given
dimensions d_1, d_2, d_3 .. d_n
and
indices i_1, i_2, i_3 .. i_n
index is computed by formula
index = i_n + i_(n-1) * d_n + i_(n-2) * d_n * d_(n-1) + ... + i_2 * d_n * d_(n-1) * ... * d_3 + i_1 * d_n * ... * d_2
@param {Array} dimensions
@param {Array} indices
@returns {Number} index | [
"Maps",
"multidimensional",
"array",
"indices",
"to",
"monodimensional",
"array",
"index"
] | d212ed0ea234311453d5187fd34c1e61726d1e6d | https://github.com/fibo/multidim-array-index/blob/d212ed0ea234311453d5187fd34c1e61726d1e6d/multidim-array-index.js#L36-L61 |
55,112 | angeloocana/joj-core | dist/Board.js | hasPositionByBoardSize | function hasPositionByBoardSize(boardSize, position) {
return position && position.x >= 0 && position.y >= 0 && boardSize.y > position.y && boardSize.x > position.x;
} | javascript | function hasPositionByBoardSize(boardSize, position) {
return position && position.x >= 0 && position.y >= 0 && boardSize.y > position.y && boardSize.x > position.x;
} | [
"function",
"hasPositionByBoardSize",
"(",
"boardSize",
",",
"position",
")",
"{",
"return",
"position",
"&&",
"position",
".",
"x",
">=",
"0",
"&&",
"position",
".",
"y",
">=",
"0",
"&&",
"boardSize",
".",
"y",
">",
"position",
".",
"y",
"&&",
"boardSize",
".",
"x",
">",
"position",
".",
"x",
";",
"}"
] | Checks if position exists in this board size | [
"Checks",
"if",
"position",
"exists",
"in",
"this",
"board",
"size"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L27-L29 |
55,113 | angeloocana/joj-core | dist/Board.js | mapBoard | function mapBoard(board, func) {
return board.map(function (col) {
return col.map(function (p) {
return func(p);
});
});
} | javascript | function mapBoard(board, func) {
return board.map(function (col) {
return col.map(function (p) {
return func(p);
});
});
} | [
"function",
"mapBoard",
"(",
"board",
",",
"func",
")",
"{",
"return",
"board",
".",
"map",
"(",
"function",
"(",
"col",
")",
"{",
"return",
"col",
".",
"map",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"func",
"(",
"p",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Map some function in all board positions and return a new board | [
"Map",
"some",
"function",
"in",
"all",
"board",
"positions",
"and",
"return",
"a",
"new",
"board"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L39-L45 |
55,114 | angeloocana/joj-core | dist/Board.js | getBoardWithPieces | function getBoardWithPieces(board, pieces) {
return mapBoard(board, function (p) {
var x = p.x,
y = p.y;
var piece = Position.getPositionFromPositions(pieces, p);
return piece ? { x: x, y: y, isBlack: piece.isBlack } : { x: x, y: y };
});
} | javascript | function getBoardWithPieces(board, pieces) {
return mapBoard(board, function (p) {
var x = p.x,
y = p.y;
var piece = Position.getPositionFromPositions(pieces, p);
return piece ? { x: x, y: y, isBlack: piece.isBlack } : { x: x, y: y };
});
} | [
"function",
"getBoardWithPieces",
"(",
"board",
",",
"pieces",
")",
"{",
"return",
"mapBoard",
"(",
"board",
",",
"function",
"(",
"p",
")",
"{",
"var",
"x",
"=",
"p",
".",
"x",
",",
"y",
"=",
"p",
".",
"y",
";",
"var",
"piece",
"=",
"Position",
".",
"getPositionFromPositions",
"(",
"pieces",
",",
"p",
")",
";",
"return",
"piece",
"?",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"isBlack",
":",
"piece",
".",
"isBlack",
"}",
":",
"{",
"x",
":",
"x",
",",
"y",
":",
"y",
"}",
";",
"}",
")",
";",
"}"
] | Takes a board and return a new board with pieces. | [
"Takes",
"a",
"board",
"and",
"return",
"a",
"new",
"board",
"with",
"pieces",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L111-L119 |
55,115 | angeloocana/joj-core | dist/Board.js | getStartWhiteBlack | function getStartWhiteBlack(x, whiteY) {
return [{ x: x, y: 0, isBlack: true }, { x: x, y: whiteY, isBlack: false }];
} | javascript | function getStartWhiteBlack(x, whiteY) {
return [{ x: x, y: 0, isBlack: true }, { x: x, y: whiteY, isBlack: false }];
} | [
"function",
"getStartWhiteBlack",
"(",
"x",
",",
"whiteY",
")",
"{",
"return",
"[",
"{",
"x",
":",
"x",
",",
"y",
":",
"0",
",",
"isBlack",
":",
"true",
"}",
",",
"{",
"x",
":",
"x",
",",
"y",
":",
"whiteY",
",",
"isBlack",
":",
"false",
"}",
"]",
";",
"}"
] | Get start white and black pieces. | [
"Get",
"start",
"white",
"and",
"black",
"pieces",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L123-L125 |
55,116 | angeloocana/joj-core | dist/Board.js | addStartPieces | function addStartPieces(x, whiteY, positions) {
return x < 0 ? positions : addStartPieces(x - 1, whiteY, positions.concat(getStartWhiteBlack(x, whiteY)));
} | javascript | function addStartPieces(x, whiteY, positions) {
return x < 0 ? positions : addStartPieces(x - 1, whiteY, positions.concat(getStartWhiteBlack(x, whiteY)));
} | [
"function",
"addStartPieces",
"(",
"x",
",",
"whiteY",
",",
"positions",
")",
"{",
"return",
"x",
"<",
"0",
"?",
"positions",
":",
"addStartPieces",
"(",
"x",
"-",
"1",
",",
"whiteY",
",",
"positions",
".",
"concat",
"(",
"getStartWhiteBlack",
"(",
"x",
",",
"whiteY",
")",
")",
")",
";",
"}"
] | Add start pieces recursively | [
"Add",
"start",
"pieces",
"recursively"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L129-L131 |
55,117 | angeloocana/joj-core | dist/Board.js | getPositionFromBoard | function getPositionFromBoard(board, position) {
try {
return board[position.y][position.x];
} catch (e) {
throw new Error('Error getting position');
}
} | javascript | function getPositionFromBoard(board, position) {
try {
return board[position.y][position.x];
} catch (e) {
throw new Error('Error getting position');
}
} | [
"function",
"getPositionFromBoard",
"(",
"board",
",",
"position",
")",
"{",
"try",
"{",
"return",
"board",
"[",
"position",
".",
"y",
"]",
"[",
"position",
".",
"x",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Error getting position'",
")",
";",
"}",
"}"
] | Gets board position from x and y coordinates.
@param board board to get the position.
@param position desired x,y position. | [
"Gets",
"board",
"position",
"from",
"x",
"and",
"y",
"coordinates",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L160-L166 |
55,118 | angeloocana/joj-core | dist/Board.js | getAllNearPositions | function getAllNearPositions(position) {
return [[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1] // Below positions
].map(function (toAdd) {
return {
x: position.x + toAdd[0],
y: position.y + toAdd[1]
};
});
} | javascript | function getAllNearPositions(position) {
return [[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1] // Below positions
].map(function (toAdd) {
return {
x: position.x + toAdd[0],
y: position.y + toAdd[1]
};
});
} | [
"function",
"getAllNearPositions",
"(",
"position",
")",
"{",
"return",
"[",
"[",
"-",
"1",
",",
"-",
"1",
"]",
",",
"[",
"0",
",",
"-",
"1",
"]",
",",
"[",
"1",
",",
"-",
"1",
"]",
",",
"[",
"-",
"1",
",",
"0",
"]",
",",
"[",
"1",
",",
"0",
"]",
",",
"[",
"-",
"1",
",",
"1",
"]",
",",
"[",
"0",
",",
"1",
"]",
",",
"[",
"1",
",",
"1",
"]",
"// Below positions",
"]",
".",
"map",
"(",
"function",
"(",
"toAdd",
")",
"{",
"return",
"{",
"x",
":",
"position",
".",
"x",
"+",
"toAdd",
"[",
"0",
"]",
",",
"y",
":",
"position",
".",
"y",
"+",
"toAdd",
"[",
"1",
"]",
"}",
";",
"}",
")",
";",
"}"
] | Get all valid and invalid near positions. | [
"Get",
"all",
"valid",
"and",
"invalid",
"near",
"positions",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L272-L280 |
55,119 | angeloocana/joj-core | dist/Board.js | getNearPositions | function getNearPositions(board, position) {
var nearPositions = _getNearPositions(getBoardSize(board), Position.getXAndY(position));
return getPositionsFromBoard(board, nearPositions);
} | javascript | function getNearPositions(board, position) {
var nearPositions = _getNearPositions(getBoardSize(board), Position.getXAndY(position));
return getPositionsFromBoard(board, nearPositions);
} | [
"function",
"getNearPositions",
"(",
"board",
",",
"position",
")",
"{",
"var",
"nearPositions",
"=",
"_getNearPositions",
"(",
"getBoardSize",
"(",
"board",
")",
",",
"Position",
".",
"getXAndY",
"(",
"position",
")",
")",
";",
"return",
"getPositionsFromBoard",
"(",
"board",
",",
"nearPositions",
")",
";",
"}"
] | Get all near positions from the given board instance. | [
"Get",
"all",
"near",
"positions",
"from",
"the",
"given",
"board",
"instance",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L293-L296 |
55,120 | angeloocana/joj-core | dist/Board.js | getEmptyNearPositions | function getEmptyNearPositions(board, position) {
return getNearPositions(board, position).filter(function (p) {
return Position.hasNoPiece(p);
});
} | javascript | function getEmptyNearPositions(board, position) {
return getNearPositions(board, position).filter(function (p) {
return Position.hasNoPiece(p);
});
} | [
"function",
"getEmptyNearPositions",
"(",
"board",
",",
"position",
")",
"{",
"return",
"getNearPositions",
"(",
"board",
",",
"position",
")",
".",
"filter",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"Position",
".",
"hasNoPiece",
"(",
"p",
")",
";",
"}",
")",
";",
"}"
] | Get empty near positions | [
"Get",
"empty",
"near",
"positions"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L300-L304 |
55,121 | angeloocana/joj-core | dist/Board.js | getNotEmptyNearPositions | function getNotEmptyNearPositions(board, position) {
return getNearPositions(board, position).filter(function (p) {
return Position.hasPiece(p);
});
} | javascript | function getNotEmptyNearPositions(board, position) {
return getNearPositions(board, position).filter(function (p) {
return Position.hasPiece(p);
});
} | [
"function",
"getNotEmptyNearPositions",
"(",
"board",
",",
"position",
")",
"{",
"return",
"getNearPositions",
"(",
"board",
",",
"position",
")",
".",
"filter",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"Position",
".",
"hasPiece",
"(",
"p",
")",
";",
"}",
")",
";",
"}"
] | Get not empty near positions | [
"Get",
"not",
"empty",
"near",
"positions"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L308-L312 |
55,122 | angeloocana/joj-core | dist/Board.js | getJumpXY | function getJumpXY(from, toJump) {
return {
x: getJump(from.x, toJump.x),
y: getJump(from.y, toJump.y)
};
} | javascript | function getJumpXY(from, toJump) {
return {
x: getJump(from.x, toJump.x),
y: getJump(from.y, toJump.y)
};
} | [
"function",
"getJumpXY",
"(",
"from",
",",
"toJump",
")",
"{",
"return",
"{",
"x",
":",
"getJump",
"(",
"from",
".",
"x",
",",
"toJump",
".",
"x",
")",
",",
"y",
":",
"getJump",
"(",
"from",
".",
"y",
",",
"toJump",
".",
"y",
")",
"}",
";",
"}"
] | Returns the target position from a jump. | [
"Returns",
"the",
"target",
"position",
"from",
"a",
"jump",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L322-L327 |
55,123 | angeloocana/joj-core | dist/Board.js | getBoardWhereCanIGo | function getBoardWhereCanIGo(board, from) {
var positions = getPositionsWhereCanIGo(board, from);
return mapBoard(board, function (position) {
return Position.setICanGoHere(positions, position);
});
} | javascript | function getBoardWhereCanIGo(board, from) {
var positions = getPositionsWhereCanIGo(board, from);
return mapBoard(board, function (position) {
return Position.setICanGoHere(positions, position);
});
} | [
"function",
"getBoardWhereCanIGo",
"(",
"board",
",",
"from",
")",
"{",
"var",
"positions",
"=",
"getPositionsWhereCanIGo",
"(",
"board",
",",
"from",
")",
";",
"return",
"mapBoard",
"(",
"board",
",",
"function",
"(",
"position",
")",
"{",
"return",
"Position",
".",
"setICanGoHere",
"(",
"positions",
",",
"position",
")",
";",
"}",
")",
";",
"}"
] | Get board with checked where can I go positions | [
"Get",
"board",
"with",
"checked",
"where",
"can",
"I",
"go",
"positions"
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L341-L346 |
55,124 | angeloocana/joj-core | dist/Board.js | getPiecesFromBoard | function getPiecesFromBoard(board) {
var initialPieces = {
white: [],
black: []
};
return board.reduce(function (piecesRow, row) {
return row.reduce(function (pieces, position) {
if (Position.hasBlackPiece(position)) pieces.black = pieces.black.concat(position);else if (Position.hasWhitePiece(position)) pieces.white = pieces.white.concat(position);
return pieces;
}, piecesRow);
}, initialPieces);
} | javascript | function getPiecesFromBoard(board) {
var initialPieces = {
white: [],
black: []
};
return board.reduce(function (piecesRow, row) {
return row.reduce(function (pieces, position) {
if (Position.hasBlackPiece(position)) pieces.black = pieces.black.concat(position);else if (Position.hasWhitePiece(position)) pieces.white = pieces.white.concat(position);
return pieces;
}, piecesRow);
}, initialPieces);
} | [
"function",
"getPiecesFromBoard",
"(",
"board",
")",
"{",
"var",
"initialPieces",
"=",
"{",
"white",
":",
"[",
"]",
",",
"black",
":",
"[",
"]",
"}",
";",
"return",
"board",
".",
"reduce",
"(",
"function",
"(",
"piecesRow",
",",
"row",
")",
"{",
"return",
"row",
".",
"reduce",
"(",
"function",
"(",
"pieces",
",",
"position",
")",
"{",
"if",
"(",
"Position",
".",
"hasBlackPiece",
"(",
"position",
")",
")",
"pieces",
".",
"black",
"=",
"pieces",
".",
"black",
".",
"concat",
"(",
"position",
")",
";",
"else",
"if",
"(",
"Position",
".",
"hasWhitePiece",
"(",
"position",
")",
")",
"pieces",
".",
"white",
"=",
"pieces",
".",
"white",
".",
"concat",
"(",
"position",
")",
";",
"return",
"pieces",
";",
"}",
",",
"piecesRow",
")",
";",
"}",
",",
"initialPieces",
")",
";",
"}"
] | Takes a board and return white and black pieces.
Used to calculate score from a board.
returns { white: [{x,y}], black: [{x,y}] } | [
"Takes",
"a",
"board",
"and",
"return",
"white",
"and",
"black",
"pieces",
".",
"Used",
"to",
"calculate",
"score",
"from",
"a",
"board",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist/Board.js#L353-L364 |
55,125 | mgesmundo/authorify-client | lib/mixin/WithPayload.js | function(sessionId) {
if (sessionId) {
if (sessionId.length < 24) {
throw new CError('sid length undersized').log();
}
if (sessionId.length > 128) {
throw new CError('sid length exceeded').log();
}
this._sid = sessionId;
}
} | javascript | function(sessionId) {
if (sessionId) {
if (sessionId.length < 24) {
throw new CError('sid length undersized').log();
}
if (sessionId.length > 128) {
throw new CError('sid length exceeded').log();
}
this._sid = sessionId;
}
} | [
"function",
"(",
"sessionId",
")",
"{",
"if",
"(",
"sessionId",
")",
"{",
"if",
"(",
"sessionId",
".",
"length",
"<",
"24",
")",
"{",
"throw",
"new",
"CError",
"(",
"'sid length undersized'",
")",
".",
"log",
"(",
")",
";",
"}",
"if",
"(",
"sessionId",
".",
"length",
">",
"128",
")",
"{",
"throw",
"new",
"CError",
"(",
"'sid length exceeded'",
")",
".",
"log",
"(",
")",
";",
"}",
"this",
".",
"_sid",
"=",
"sessionId",
";",
"}",
"}"
] | Set the session identifier
@param {String} sid The session identifier | [
"Set",
"the",
"session",
"identifier"
] | 39fb57db897eaa49b76444ff62bbc0ccedc7ee16 | https://github.com/mgesmundo/authorify-client/blob/39fb57db897eaa49b76444ff62bbc0ccedc7ee16/lib/mixin/WithPayload.js#L72-L82 |
|
55,126 | D-Mobilelab/http-francis | src/main.js | getImageRaw | function getImageRaw(options, _onProgress = () => {}){
return new Promise((resolve, reject) => {
var request = new XMLHttpRequest();
request.open('GET', options.url, true);
request.responseType = options.responseType || 'blob';
function transferComplete(){
var result;
switch (options.responseType){
case 'blob':
result = new Blob([this.response], { type: options.mimeType || 'image/jpeg' });
resolve(result);
break;
case 'arraybuffer':
result = this.response;
resolve(result);
break;
default:
result = this.response;
resolve(result);
break;
}
}
var transferCanceled = reject;
var transferFailed = reject;
request.addEventListener('progress', _onProgress, false);
request.addEventListener('load', transferComplete, false);
request.addEventListener('error', transferFailed, false);
request.addEventListener('abort', transferCanceled, false);
request.send(null);
});
} | javascript | function getImageRaw(options, _onProgress = () => {}){
return new Promise((resolve, reject) => {
var request = new XMLHttpRequest();
request.open('GET', options.url, true);
request.responseType = options.responseType || 'blob';
function transferComplete(){
var result;
switch (options.responseType){
case 'blob':
result = new Blob([this.response], { type: options.mimeType || 'image/jpeg' });
resolve(result);
break;
case 'arraybuffer':
result = this.response;
resolve(result);
break;
default:
result = this.response;
resolve(result);
break;
}
}
var transferCanceled = reject;
var transferFailed = reject;
request.addEventListener('progress', _onProgress, false);
request.addEventListener('load', transferComplete, false);
request.addEventListener('error', transferFailed, false);
request.addEventListener('abort', transferCanceled, false);
request.send(null);
});
} | [
"function",
"getImageRaw",
"(",
"options",
",",
"_onProgress",
"=",
"(",
")",
"=>",
"{",
"}",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"var",
"request",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"request",
".",
"open",
"(",
"'GET'",
",",
"options",
".",
"url",
",",
"true",
")",
";",
"request",
".",
"responseType",
"=",
"options",
".",
"responseType",
"||",
"'blob'",
";",
"function",
"transferComplete",
"(",
")",
"{",
"var",
"result",
";",
"switch",
"(",
"options",
".",
"responseType",
")",
"{",
"case",
"'blob'",
":",
"result",
"=",
"new",
"Blob",
"(",
"[",
"this",
".",
"response",
"]",
",",
"{",
"type",
":",
"options",
".",
"mimeType",
"||",
"'image/jpeg'",
"}",
")",
";",
"resolve",
"(",
"result",
")",
";",
"break",
";",
"case",
"'arraybuffer'",
":",
"result",
"=",
"this",
".",
"response",
";",
"resolve",
"(",
"result",
")",
";",
"break",
";",
"default",
":",
"result",
"=",
"this",
".",
"response",
";",
"resolve",
"(",
"result",
")",
";",
"break",
";",
"}",
"}",
"var",
"transferCanceled",
"=",
"reject",
";",
"var",
"transferFailed",
"=",
"reject",
";",
"request",
".",
"addEventListener",
"(",
"'progress'",
",",
"_onProgress",
",",
"false",
")",
";",
"request",
".",
"addEventListener",
"(",
"'load'",
",",
"transferComplete",
",",
"false",
")",
";",
"request",
".",
"addEventListener",
"(",
"'error'",
",",
"transferFailed",
",",
"false",
")",
";",
"request",
".",
"addEventListener",
"(",
"'abort'",
",",
"transferCanceled",
",",
"false",
")",
";",
"request",
".",
"send",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] | getImageRaw from a specific url
@param {Object} options - the options object
@param {String} options.url - http or whatever
@param {String} [options.responseType="blob"] - possible values arraybuffer|blob
@param {String} [options.mimeType="image/jpeg"] - possible values "image/png"|"image/jpeg" used only if "blob" is set as responseType
@param {Function} [_onProgress=function(){}]
@return {Promise<Blob|ArrayBuffer|Error>} | [
"getImageRaw",
"from",
"a",
"specific",
"url"
] | bb303b4aaad810014939d1fd237982a4dcceed4c | https://github.com/D-Mobilelab/http-francis/blob/bb303b4aaad810014939d1fd237982a4dcceed4c/src/main.js#L253-L288 |
55,127 | D-Mobilelab/http-francis | src/main.js | JSONPRequest | function JSONPRequest(url, timeout = 3000){
var self = this;
self.timeout = timeout;
self.called = false;
if (window.document) {
var ts = Date.now();
self.scriptTag = window.document.createElement('script');
// url += '&callback=window.__jsonpHandler_' + ts;
var _url = '';
if (url && url !== '') {
_url = queryfy(url, { callback: `window.__jsonpHandler_${ts}` });
}
self.scriptTag.src = _url;
self.scriptTag.type = 'text/javascript';
self.scriptTag.async = true;
self.prom = new Promise((resolve, reject) => {
var functionName = `__jsonpHandler_${ts}`;
window[functionName] = function(data){
self.called = true;
resolve(data);
self.scriptTag.parentElement.removeChild(self.scriptTag);
delete window[functionName];
};
// reject after a timeout
setTimeout(() => {
if (!self.called){
reject('Timeout jsonp request ' + ts);
self.scriptTag.parentElement.removeChild(self.scriptTag);
delete window[functionName];
}
}, self.timeout);
});
// the append start the call
window.document.getElementsByTagName('head')[0].appendChild(self.scriptTag);
}
} | javascript | function JSONPRequest(url, timeout = 3000){
var self = this;
self.timeout = timeout;
self.called = false;
if (window.document) {
var ts = Date.now();
self.scriptTag = window.document.createElement('script');
// url += '&callback=window.__jsonpHandler_' + ts;
var _url = '';
if (url && url !== '') {
_url = queryfy(url, { callback: `window.__jsonpHandler_${ts}` });
}
self.scriptTag.src = _url;
self.scriptTag.type = 'text/javascript';
self.scriptTag.async = true;
self.prom = new Promise((resolve, reject) => {
var functionName = `__jsonpHandler_${ts}`;
window[functionName] = function(data){
self.called = true;
resolve(data);
self.scriptTag.parentElement.removeChild(self.scriptTag);
delete window[functionName];
};
// reject after a timeout
setTimeout(() => {
if (!self.called){
reject('Timeout jsonp request ' + ts);
self.scriptTag.parentElement.removeChild(self.scriptTag);
delete window[functionName];
}
}, self.timeout);
});
// the append start the call
window.document.getElementsByTagName('head')[0].appendChild(self.scriptTag);
}
} | [
"function",
"JSONPRequest",
"(",
"url",
",",
"timeout",
"=",
"3000",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"timeout",
"=",
"timeout",
";",
"self",
".",
"called",
"=",
"false",
";",
"if",
"(",
"window",
".",
"document",
")",
"{",
"var",
"ts",
"=",
"Date",
".",
"now",
"(",
")",
";",
"self",
".",
"scriptTag",
"=",
"window",
".",
"document",
".",
"createElement",
"(",
"'script'",
")",
";",
"// url += '&callback=window.__jsonpHandler_' + ts;",
"var",
"_url",
"=",
"''",
";",
"if",
"(",
"url",
"&&",
"url",
"!==",
"''",
")",
"{",
"_url",
"=",
"queryfy",
"(",
"url",
",",
"{",
"callback",
":",
"`",
"${",
"ts",
"}",
"`",
"}",
")",
";",
"}",
"self",
".",
"scriptTag",
".",
"src",
"=",
"_url",
";",
"self",
".",
"scriptTag",
".",
"type",
"=",
"'text/javascript'",
";",
"self",
".",
"scriptTag",
".",
"async",
"=",
"true",
";",
"self",
".",
"prom",
"=",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"var",
"functionName",
"=",
"`",
"${",
"ts",
"}",
"`",
";",
"window",
"[",
"functionName",
"]",
"=",
"function",
"(",
"data",
")",
"{",
"self",
".",
"called",
"=",
"true",
";",
"resolve",
"(",
"data",
")",
";",
"self",
".",
"scriptTag",
".",
"parentElement",
".",
"removeChild",
"(",
"self",
".",
"scriptTag",
")",
";",
"delete",
"window",
"[",
"functionName",
"]",
";",
"}",
";",
"// reject after a timeout",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"self",
".",
"called",
")",
"{",
"reject",
"(",
"'Timeout jsonp request '",
"+",
"ts",
")",
";",
"self",
".",
"scriptTag",
".",
"parentElement",
".",
"removeChild",
"(",
"self",
".",
"scriptTag",
")",
";",
"delete",
"window",
"[",
"functionName",
"]",
";",
"}",
"}",
",",
"self",
".",
"timeout",
")",
";",
"}",
")",
";",
"// the append start the call",
"window",
".",
"document",
".",
"getElementsByTagName",
"(",
"'head'",
")",
"[",
"0",
"]",
".",
"appendChild",
"(",
"self",
".",
"scriptTag",
")",
";",
"}",
"}"
] | Make a jsonp request, remember only GET
The function create a tag script and append a callback param in querystring.
The promise will be reject after 3s if the url fail to respond
@example
<pre>
request = new JSONPRequest("http://www.someapi.com/asd?somequery=1");
request.then((data) => {});
</pre>
@param {String} url - the url with querystring but without &callback at the end or &function
@param {Number} timeout - ms range for the response
@return {Promise<Object|String>} | [
"Make",
"a",
"jsonp",
"request",
"remember",
"only",
"GET",
"The",
"function",
"create",
"a",
"tag",
"script",
"and",
"append",
"a",
"callback",
"param",
"in",
"querystring",
".",
"The",
"promise",
"will",
"be",
"reject",
"after",
"3s",
"if",
"the",
"url",
"fail",
"to",
"respond"
] | bb303b4aaad810014939d1fd237982a4dcceed4c | https://github.com/D-Mobilelab/http-francis/blob/bb303b4aaad810014939d1fd237982a4dcceed4c/src/main.js#L304-L341 |
55,128 | segmentio/clear-globals | lib/index.js | copy | function copy(source, target) {
for (var name in source) {
if (source.hasOwnProperty(name)) {
target[name] = source[name];
}
}
} | javascript | function copy(source, target) {
for (var name in source) {
if (source.hasOwnProperty(name)) {
target[name] = source[name];
}
}
} | [
"function",
"copy",
"(",
"source",
",",
"target",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"source",
")",
"{",
"if",
"(",
"source",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"target",
"[",
"name",
"]",
"=",
"source",
"[",
"name",
"]",
";",
"}",
"}",
"}"
] | Reset properties on object.
@param {Object} source
@param {Object} target
@api private | [
"Reset",
"properties",
"on",
"object",
"."
] | 2ad614b42ed3d8a6fda293b40c8e5cf42397468a | https://github.com/segmentio/clear-globals/blob/2ad614b42ed3d8a6fda293b40c8e5cf42397468a/lib/index.js#L51-L57 |
55,129 | viskan/node-hacontrol | index.js | function(localPath, globalPath)
{
if (!(this instanceof HAControl))
{
return new HAControl(localPath, globalPath);
}
this.localHa = true;
this.globalHa = true;
this.localPath = localPath;
this.globalPath = globalPath;
} | javascript | function(localPath, globalPath)
{
if (!(this instanceof HAControl))
{
return new HAControl(localPath, globalPath);
}
this.localHa = true;
this.globalHa = true;
this.localPath = localPath;
this.globalPath = globalPath;
} | [
"function",
"(",
"localPath",
",",
"globalPath",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"HAControl",
")",
")",
"{",
"return",
"new",
"HAControl",
"(",
"localPath",
",",
"globalPath",
")",
";",
"}",
"this",
".",
"localHa",
"=",
"true",
";",
"this",
".",
"globalHa",
"=",
"true",
";",
"this",
".",
"localPath",
"=",
"localPath",
";",
"this",
".",
"globalPath",
"=",
"globalPath",
";",
"}"
] | Simple service for fetching HAControl status.
@constructor
@author Ulrik Augustsson
@author Anton Johansson | [
"Simple",
"service",
"for",
"fetching",
"HAControl",
"status",
"."
] | dd409246bf8cd00ad2faa94273d71b5fcbf4515b | https://github.com/viskan/node-hacontrol/blob/dd409246bf8cd00ad2faa94273d71b5fcbf4515b/index.js#L13-L25 |
|
55,130 | ponycode/pony-config | index.js | _keySourceHintFrom | function _keySourceHintFrom( method, source, environment ){
var hints = [];
if( method ) hints.push( method );
if( source ) hints.push( source );
if( environment ) hints.push( "WHEN " + environment );
return hints.join(' ');
} | javascript | function _keySourceHintFrom( method, source, environment ){
var hints = [];
if( method ) hints.push( method );
if( source ) hints.push( source );
if( environment ) hints.push( "WHEN " + environment );
return hints.join(' ');
} | [
"function",
"_keySourceHintFrom",
"(",
"method",
",",
"source",
",",
"environment",
")",
"{",
"var",
"hints",
"=",
"[",
"]",
";",
"if",
"(",
"method",
")",
"hints",
".",
"push",
"(",
"method",
")",
";",
"if",
"(",
"source",
")",
"hints",
".",
"push",
"(",
"source",
")",
";",
"if",
"(",
"environment",
")",
"hints",
".",
"push",
"(",
"\"WHEN \"",
"+",
"environment",
")",
";",
"return",
"hints",
".",
"join",
"(",
"' '",
")",
";",
"}"
] | construct a source hint for the ConfigStore
Hints are stored in the config to indicate source of applied changes
@param method
@param source
@param environment
@return {string}
@private | [
"construct",
"a",
"source",
"hint",
"for",
"the",
"ConfigStore",
"Hints",
"are",
"stored",
"in",
"the",
"config",
"to",
"indicate",
"source",
"of",
"applied",
"changes"
] | 171d69aea32d7b60481f4523d5eac13d549a05fe | https://github.com/ponycode/pony-config/blob/171d69aea32d7b60481f4523d5eac13d549a05fe/index.js#L239-L246 |
55,131 | ngageoint/eslint-plugin-opensphere | util.js | isGoogCallExpression | function isGoogCallExpression(node, name) {
const callee = node.callee;
return callee && callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' && callee.object.name === 'goog' &&
callee.property.type === 'Identifier' && !callee.property.computed &&
callee.property.name === name;
} | javascript | function isGoogCallExpression(node, name) {
const callee = node.callee;
return callee && callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' && callee.object.name === 'goog' &&
callee.property.type === 'Identifier' && !callee.property.computed &&
callee.property.name === name;
} | [
"function",
"isGoogCallExpression",
"(",
"node",
",",
"name",
")",
"{",
"const",
"callee",
"=",
"node",
".",
"callee",
";",
"return",
"callee",
"&&",
"callee",
".",
"type",
"===",
"'MemberExpression'",
"&&",
"callee",
".",
"object",
".",
"type",
"===",
"'Identifier'",
"&&",
"callee",
".",
"object",
".",
"name",
"===",
"'goog'",
"&&",
"callee",
".",
"property",
".",
"type",
"===",
"'Identifier'",
"&&",
"!",
"callee",
".",
"property",
".",
"computed",
"&&",
"callee",
".",
"property",
".",
"name",
"===",
"name",
";",
"}"
] | If a node represents a goog call expression.
@param {!AST.Node} node The node.
@param {string} name The name.
@return {boolean} | [
"If",
"a",
"node",
"represents",
"a",
"goog",
"call",
"expression",
"."
] | 3d1804b49a0349aeba0eb694e45266fb2cb2d83b | https://github.com/ngageoint/eslint-plugin-opensphere/blob/3d1804b49a0349aeba0eb694e45266fb2cb2d83b/util.js#L9-L15 |
55,132 | ngageoint/eslint-plugin-opensphere | util.js | isGoogStatement | function isGoogStatement(node, name) {
return node.expression && node.expression.type === 'CallExpression' &&
isGoogCallExpression(node.expression, name);
} | javascript | function isGoogStatement(node, name) {
return node.expression && node.expression.type === 'CallExpression' &&
isGoogCallExpression(node.expression, name);
} | [
"function",
"isGoogStatement",
"(",
"node",
",",
"name",
")",
"{",
"return",
"node",
".",
"expression",
"&&",
"node",
".",
"expression",
".",
"type",
"===",
"'CallExpression'",
"&&",
"isGoogCallExpression",
"(",
"node",
".",
"expression",
",",
"name",
")",
";",
"}"
] | If a node represents a goog statement.
@param {!AST.Node} node The node.
@param {string} name The name.
@return {boolean} | [
"If",
"a",
"node",
"represents",
"a",
"goog",
"statement",
"."
] | 3d1804b49a0349aeba0eb694e45266fb2cb2d83b | https://github.com/ngageoint/eslint-plugin-opensphere/blob/3d1804b49a0349aeba0eb694e45266fb2cb2d83b/util.js#L23-L26 |
55,133 | ibm-watson-data-lab/--deprecated--simple-data-pipe-connector-reddit | lib/index.js | function () {
logger.info('Records sent to Tone Analyzer: ' + amaStats.processed_record_count);
// these records could be fetched using other API calls
logger.info('Records missing (no comment text available): ' + amaStats.missing_record_count);
logger.info('Maximum processed comment thread depth: ' + amaStats.max_processed_level);
if(amaStats.parser_warnings > 0) {
// Potential issue with parser logic. If a non-zero value is reported, the base tree should be reviewed.
logger.warn('Potential base tree parsing issues: ' + amaStats.parser_warnings);
}
logger.debug('AMA thread statistics: ' + util.inspect(amaStats.level_stats,3));
} | javascript | function () {
logger.info('Records sent to Tone Analyzer: ' + amaStats.processed_record_count);
// these records could be fetched using other API calls
logger.info('Records missing (no comment text available): ' + amaStats.missing_record_count);
logger.info('Maximum processed comment thread depth: ' + amaStats.max_processed_level);
if(amaStats.parser_warnings > 0) {
// Potential issue with parser logic. If a non-zero value is reported, the base tree should be reviewed.
logger.warn('Potential base tree parsing issues: ' + amaStats.parser_warnings);
}
logger.debug('AMA thread statistics: ' + util.inspect(amaStats.level_stats,3));
} | [
"function",
"(",
")",
"{",
"logger",
".",
"info",
"(",
"'Records sent to Tone Analyzer: '",
"+",
"amaStats",
".",
"processed_record_count",
")",
";",
"// these records could be fetched using other API calls",
"logger",
".",
"info",
"(",
"'Records missing (no comment text available): '",
"+",
"amaStats",
".",
"missing_record_count",
")",
";",
"logger",
".",
"info",
"(",
"'Maximum processed comment thread depth: '",
"+",
"amaStats",
".",
"max_processed_level",
")",
";",
"if",
"(",
"amaStats",
".",
"parser_warnings",
">",
"0",
")",
"{",
"// Potential issue with parser logic. If a non-zero value is reported, the base tree should be reviewed.",
"logger",
".",
"warn",
"(",
"'Potential base tree parsing issues: '",
"+",
"amaStats",
".",
"parser_warnings",
")",
";",
"}",
"logger",
".",
"debug",
"(",
"'AMA thread statistics: '",
"+",
"util",
".",
"inspect",
"(",
"amaStats",
".",
"level_stats",
",",
"3",
")",
")",
";",
"}"
] | local helper function; displays processing statistics` | [
"local",
"helper",
"function",
";",
"displays",
"processing",
"statistics"
] | df7188d9a8519f14d095ab7db5bee913e92804c2 | https://github.com/ibm-watson-data-lab/--deprecated--simple-data-pipe-connector-reddit/blob/df7188d9a8519f14d095ab7db5bee913e92804c2/lib/index.js#L337-L349 |
|
55,134 | amercier/broccoli-file-size | src/lib/index.js | listFiles | function listFiles(dir, callback) {
return new Promise((resolveThis, reject) => {
walk.walk(dir, { followLinks: true })
.on('file', (root, stats, next) => {
const destDir = relative(dir, root);
const relativePath = destDir ? join(destDir, stats.name) : stats.name;
resolve(relativePath).then(callback).then(next);
})
.on('errors', reject)
.on('end', resolveThis);
});
} | javascript | function listFiles(dir, callback) {
return new Promise((resolveThis, reject) => {
walk.walk(dir, { followLinks: true })
.on('file', (root, stats, next) => {
const destDir = relative(dir, root);
const relativePath = destDir ? join(destDir, stats.name) : stats.name;
resolve(relativePath).then(callback).then(next);
})
.on('errors', reject)
.on('end', resolveThis);
});
} | [
"function",
"listFiles",
"(",
"dir",
",",
"callback",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolveThis",
",",
"reject",
")",
"=>",
"{",
"walk",
".",
"walk",
"(",
"dir",
",",
"{",
"followLinks",
":",
"true",
"}",
")",
".",
"on",
"(",
"'file'",
",",
"(",
"root",
",",
"stats",
",",
"next",
")",
"=>",
"{",
"const",
"destDir",
"=",
"relative",
"(",
"dir",
",",
"root",
")",
";",
"const",
"relativePath",
"=",
"destDir",
"?",
"join",
"(",
"destDir",
",",
"stats",
".",
"name",
")",
":",
"stats",
".",
"name",
";",
"resolve",
"(",
"relativePath",
")",
".",
"then",
"(",
"callback",
")",
".",
"then",
"(",
"next",
")",
";",
"}",
")",
".",
"on",
"(",
"'errors'",
",",
"reject",
")",
".",
"on",
"(",
"'end'",
",",
"resolveThis",
")",
";",
"}",
")",
";",
"}"
] | Lists files of a directory recursively. Follows symbolic links.
@param {String} dir Directory to scan
@param {Function()} callback Callback executed when a file is found. Can return a Promise.
@return {Promise} A new promise that is resolved once the given directory
has been scanned entirely and all callbacks have completed. | [
"Lists",
"files",
"of",
"a",
"directory",
"recursively",
".",
"Follows",
"symbolic",
"links",
"."
] | 35785685f00629ad362b413285cf8e355369005a | https://github.com/amercier/broccoli-file-size/blob/35785685f00629ad362b413285cf8e355369005a/src/lib/index.js#L23-L34 |
55,135 | amercier/broccoli-file-size | src/lib/index.js | symlinkOrCopySync | function symlinkOrCopySync(dir, target) {
try {
symlinkOrCopy.sync(dir, target);
} catch (e) {
if (existsSync(target)) {
rimraf.sync(target);
}
symlinkOrCopy.sync(dir, target);
}
} | javascript | function symlinkOrCopySync(dir, target) {
try {
symlinkOrCopy.sync(dir, target);
} catch (e) {
if (existsSync(target)) {
rimraf.sync(target);
}
symlinkOrCopy.sync(dir, target);
}
} | [
"function",
"symlinkOrCopySync",
"(",
"dir",
",",
"target",
")",
"{",
"try",
"{",
"symlinkOrCopy",
".",
"sync",
"(",
"dir",
",",
"target",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"existsSync",
"(",
"target",
")",
")",
"{",
"rimraf",
".",
"sync",
"(",
"target",
")",
";",
"}",
"symlinkOrCopy",
".",
"sync",
"(",
"dir",
",",
"target",
")",
";",
"}",
"}"
] | Symlink or copy a directory
@param {String} dir Path to an existing
@param {String} target Path of the symlink to create | [
"Symlink",
"or",
"copy",
"a",
"directory"
] | 35785685f00629ad362b413285cf8e355369005a | https://github.com/amercier/broccoli-file-size/blob/35785685f00629ad362b413285cf8e355369005a/src/lib/index.js#L41-L50 |
55,136 | rhyolight/github-data | lib/tree.js | Tree | function Tree(source, parent, githubClient) {
this.gh = githubClient;
this.sha = source.sha;
this.parent = parent;
this.truncated = source.truncated;
this.objects = _.cloneDeep(source.tree);
this._source = source;
} | javascript | function Tree(source, parent, githubClient) {
this.gh = githubClient;
this.sha = source.sha;
this.parent = parent;
this.truncated = source.truncated;
this.objects = _.cloneDeep(source.tree);
this._source = source;
} | [
"function",
"Tree",
"(",
"source",
",",
"parent",
",",
"githubClient",
")",
"{",
"this",
".",
"gh",
"=",
"githubClient",
";",
"this",
".",
"sha",
"=",
"source",
".",
"sha",
";",
"this",
".",
"parent",
"=",
"parent",
";",
"this",
".",
"truncated",
"=",
"source",
".",
"truncated",
";",
"this",
".",
"objects",
"=",
"_",
".",
"cloneDeep",
"(",
"source",
".",
"tree",
")",
";",
"this",
".",
"_source",
"=",
"source",
";",
"}"
] | A git tree object.
@class Tree
@param source {Object} JSON response from API, used to build.
@param parent {Object} Expected to be {{#crossLink "Tree"}}{{/crossLink}} or
{{#crossLink "Commit"}}{{/crossLink}}.
@param githubClient {Object} GitHub API Client object.
@constructor | [
"A",
"git",
"tree",
"object",
"."
] | 5d6a3fc0e7ecfeaec03e4815b0940c2d9ce07d64 | https://github.com/rhyolight/github-data/blob/5d6a3fc0e7ecfeaec03e4815b0940c2d9ce07d64/lib/tree.js#L21-L28 |
55,137 | ugate/releasebot | releasebot.js | task | function task() {
// make sure the release task has been initialized
init.apply(this, arguments);
var name, desc, deps, cb;
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'string') {
if (name) {
desc = arguments[i];
} else {
name = arguments[i];
}
} else if (typeof arguments[i] === 'function') {
cb = taskCallback(arguments[i]);
} else if (Array.isArray(arguments[i])) {
deps = arguments[i];
}
}
if (rbot.env.usingGrunt) {
if (name && desc) {
return rbot.env.taskRunner.registerTask(name, desc, cb);
} else if (name && deps) {
return rbot.env.taskRunner.registerTask(name, deps);
}
throw new Error('Invalid grunt.registerTask() for: name = "' + name + '", desc = "' + desc + '", taskList = "'
+ deps + '", function = "' + cb + '"');
} else {
if (name && deps && cb) {
return rbot.env.taskRunner.task(name, deps, cb);
} else if (name && cb) {
return rbot.env.taskRunner.task(name, cb);
}
throw new Error('Invalid gulp.task() for: name = "' + name + '", deps = "' + deps + '", function = "' + cb
+ '"');
}
} | javascript | function task() {
// make sure the release task has been initialized
init.apply(this, arguments);
var name, desc, deps, cb;
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'string') {
if (name) {
desc = arguments[i];
} else {
name = arguments[i];
}
} else if (typeof arguments[i] === 'function') {
cb = taskCallback(arguments[i]);
} else if (Array.isArray(arguments[i])) {
deps = arguments[i];
}
}
if (rbot.env.usingGrunt) {
if (name && desc) {
return rbot.env.taskRunner.registerTask(name, desc, cb);
} else if (name && deps) {
return rbot.env.taskRunner.registerTask(name, deps);
}
throw new Error('Invalid grunt.registerTask() for: name = "' + name + '", desc = "' + desc + '", taskList = "'
+ deps + '", function = "' + cb + '"');
} else {
if (name && deps && cb) {
return rbot.env.taskRunner.task(name, deps, cb);
} else if (name && cb) {
return rbot.env.taskRunner.task(name, cb);
}
throw new Error('Invalid gulp.task() for: name = "' + name + '", deps = "' + deps + '", function = "' + cb
+ '"');
}
} | [
"function",
"task",
"(",
")",
"{",
"// make sure the release task has been initialized",
"init",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"name",
",",
"desc",
",",
"deps",
",",
"cb",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"arguments",
"[",
"i",
"]",
"===",
"'string'",
")",
"{",
"if",
"(",
"name",
")",
"{",
"desc",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"else",
"{",
"name",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"arguments",
"[",
"i",
"]",
"===",
"'function'",
")",
"{",
"cb",
"=",
"taskCallback",
"(",
"arguments",
"[",
"i",
"]",
")",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arguments",
"[",
"i",
"]",
")",
")",
"{",
"deps",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"}",
"if",
"(",
"rbot",
".",
"env",
".",
"usingGrunt",
")",
"{",
"if",
"(",
"name",
"&&",
"desc",
")",
"{",
"return",
"rbot",
".",
"env",
".",
"taskRunner",
".",
"registerTask",
"(",
"name",
",",
"desc",
",",
"cb",
")",
";",
"}",
"else",
"if",
"(",
"name",
"&&",
"deps",
")",
"{",
"return",
"rbot",
".",
"env",
".",
"taskRunner",
".",
"registerTask",
"(",
"name",
",",
"deps",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Invalid grunt.registerTask() for: name = \"'",
"+",
"name",
"+",
"'\", desc = \"'",
"+",
"desc",
"+",
"'\", taskList = \"'",
"+",
"deps",
"+",
"'\", function = \"'",
"+",
"cb",
"+",
"'\"'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"name",
"&&",
"deps",
"&&",
"cb",
")",
"{",
"return",
"rbot",
".",
"env",
".",
"taskRunner",
".",
"task",
"(",
"name",
",",
"deps",
",",
"cb",
")",
";",
"}",
"else",
"if",
"(",
"name",
"&&",
"cb",
")",
"{",
"return",
"rbot",
".",
"env",
".",
"taskRunner",
".",
"task",
"(",
"name",
",",
"cb",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Invalid gulp.task() for: name = \"'",
"+",
"name",
"+",
"'\", deps = \"'",
"+",
"deps",
"+",
"'\", function = \"'",
"+",
"cb",
"+",
"'\"'",
")",
";",
"}",
"}"
] | Registers a task runner neutral API for a task. If using Grunt "registerTask"
is executed. If using Gulp "task" is executed. In either case the arguments
are passed in the expected order regardless of how they are passed into this
function.
@returns the return value from the task runner API | [
"Registers",
"a",
"task",
"runner",
"neutral",
"API",
"for",
"a",
"task",
".",
"If",
"using",
"Grunt",
"registerTask",
"is",
"executed",
".",
"If",
"using",
"Gulp",
"task",
"is",
"executed",
".",
"In",
"either",
"case",
"the",
"arguments",
"are",
"passed",
"in",
"the",
"expected",
"order",
"regardless",
"of",
"how",
"they",
"are",
"passed",
"into",
"this",
"function",
"."
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/releasebot.js#L86-L120 |
55,138 | ugate/releasebot | releasebot.js | taskCallback | function taskCallback(fn) {
return fn.length ? taskAsyncCb : taskSyncCb;
function taskAsyncCb(cb) {
return taskCb(this || {}, arguments, fn, cb, true);
}
function taskSyncCb() {
return taskCb(this || {}, arguments, fn, null, false);
}
function taskCb(cxt, args, fn, done, isAsync) {
cxt.done = isAsync && typeof done === 'function' ? done : isAsync && typeof cxt.async === 'function' ? cxt
.async() : taskSyncDone;
if (!rbot.env.usingGrunt) {
// set options using either a configuration value or the passed
// default value
cxt.options = function setOptions(defOpts) {
Object.keys(defOpts).forEach(function it(k) {
this.options[k] = rbot.config(k) || defOpts[k];
}.bind(this));
return this.options;
}.bind(cxt);
}
var fna = args;
if (cxt.done !== done && cxt.done !== taskSyncDone) {
// ensure that the done function still gets passed as the 1st
// argument even when the task runner doesn't pass it
fna = args ? Array.prototype.slice.call(args, 0) : [];
fna.unshift(cxt.done);
}
return fn.apply(cxt, fna);
}
function taskSyncDone(success) {
rbot.log.verbose('Synchronous task ' + (success ? 'completed' : 'failed'));
}
} | javascript | function taskCallback(fn) {
return fn.length ? taskAsyncCb : taskSyncCb;
function taskAsyncCb(cb) {
return taskCb(this || {}, arguments, fn, cb, true);
}
function taskSyncCb() {
return taskCb(this || {}, arguments, fn, null, false);
}
function taskCb(cxt, args, fn, done, isAsync) {
cxt.done = isAsync && typeof done === 'function' ? done : isAsync && typeof cxt.async === 'function' ? cxt
.async() : taskSyncDone;
if (!rbot.env.usingGrunt) {
// set options using either a configuration value or the passed
// default value
cxt.options = function setOptions(defOpts) {
Object.keys(defOpts).forEach(function it(k) {
this.options[k] = rbot.config(k) || defOpts[k];
}.bind(this));
return this.options;
}.bind(cxt);
}
var fna = args;
if (cxt.done !== done && cxt.done !== taskSyncDone) {
// ensure that the done function still gets passed as the 1st
// argument even when the task runner doesn't pass it
fna = args ? Array.prototype.slice.call(args, 0) : [];
fna.unshift(cxt.done);
}
return fn.apply(cxt, fna);
}
function taskSyncDone(success) {
rbot.log.verbose('Synchronous task ' + (success ? 'completed' : 'failed'));
}
} | [
"function",
"taskCallback",
"(",
"fn",
")",
"{",
"return",
"fn",
".",
"length",
"?",
"taskAsyncCb",
":",
"taskSyncCb",
";",
"function",
"taskAsyncCb",
"(",
"cb",
")",
"{",
"return",
"taskCb",
"(",
"this",
"||",
"{",
"}",
",",
"arguments",
",",
"fn",
",",
"cb",
",",
"true",
")",
";",
"}",
"function",
"taskSyncCb",
"(",
")",
"{",
"return",
"taskCb",
"(",
"this",
"||",
"{",
"}",
",",
"arguments",
",",
"fn",
",",
"null",
",",
"false",
")",
";",
"}",
"function",
"taskCb",
"(",
"cxt",
",",
"args",
",",
"fn",
",",
"done",
",",
"isAsync",
")",
"{",
"cxt",
".",
"done",
"=",
"isAsync",
"&&",
"typeof",
"done",
"===",
"'function'",
"?",
"done",
":",
"isAsync",
"&&",
"typeof",
"cxt",
".",
"async",
"===",
"'function'",
"?",
"cxt",
".",
"async",
"(",
")",
":",
"taskSyncDone",
";",
"if",
"(",
"!",
"rbot",
".",
"env",
".",
"usingGrunt",
")",
"{",
"// set options using either a configuration value or the passed",
"// default value",
"cxt",
".",
"options",
"=",
"function",
"setOptions",
"(",
"defOpts",
")",
"{",
"Object",
".",
"keys",
"(",
"defOpts",
")",
".",
"forEach",
"(",
"function",
"it",
"(",
"k",
")",
"{",
"this",
".",
"options",
"[",
"k",
"]",
"=",
"rbot",
".",
"config",
"(",
"k",
")",
"||",
"defOpts",
"[",
"k",
"]",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"return",
"this",
".",
"options",
";",
"}",
".",
"bind",
"(",
"cxt",
")",
";",
"}",
"var",
"fna",
"=",
"args",
";",
"if",
"(",
"cxt",
".",
"done",
"!==",
"done",
"&&",
"cxt",
".",
"done",
"!==",
"taskSyncDone",
")",
"{",
"// ensure that the done function still gets passed as the 1st",
"// argument even when the task runner doesn't pass it",
"fna",
"=",
"args",
"?",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"args",
",",
"0",
")",
":",
"[",
"]",
";",
"fna",
".",
"unshift",
"(",
"cxt",
".",
"done",
")",
";",
"}",
"return",
"fn",
".",
"apply",
"(",
"cxt",
",",
"fna",
")",
";",
"}",
"function",
"taskSyncDone",
"(",
"success",
")",
"{",
"rbot",
".",
"log",
".",
"verbose",
"(",
"'Synchronous task '",
"+",
"(",
"success",
"?",
"'completed'",
":",
"'failed'",
")",
")",
";",
"}",
"}"
] | Creates a task callback function that will wrap the passed callback that the
task runner requires to ensure consistent option behavior between different
task runners. When the specified function contains arguments the wrapper will
assume that the associated task will be executed in an asynchronous fashion.
Relies on the number of arguments defined in the passed function to determine
synchronicity.
@param fn
the function that will be wrapped
@returns a wrapped callback function | [
"Creates",
"a",
"task",
"callback",
"function",
"that",
"will",
"wrap",
"the",
"passed",
"callback",
"that",
"the",
"task",
"runner",
"requires",
"to",
"ensure",
"consistent",
"option",
"behavior",
"between",
"different",
"task",
"runners",
".",
"When",
"the",
"specified",
"function",
"contains",
"arguments",
"the",
"wrapper",
"will",
"assume",
"that",
"the",
"associated",
"task",
"will",
"be",
"executed",
"in",
"an",
"asynchronous",
"fashion",
".",
"Relies",
"on",
"the",
"number",
"of",
"arguments",
"defined",
"in",
"the",
"passed",
"function",
"to",
"determine",
"synchronicity",
"."
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/releasebot.js#L134-L167 |
55,139 | ugate/releasebot | releasebot.js | processTemplate | function processTemplate(val, data) {
if (rbot.env.usingGrunt) {
return rbot.env.taskRunner.template.process(val, data);
}
// TODO : add gulp template processing
if (!val) {
return val;
}
return val;
} | javascript | function processTemplate(val, data) {
if (rbot.env.usingGrunt) {
return rbot.env.taskRunner.template.process(val, data);
}
// TODO : add gulp template processing
if (!val) {
return val;
}
return val;
} | [
"function",
"processTemplate",
"(",
"val",
",",
"data",
")",
"{",
"if",
"(",
"rbot",
".",
"env",
".",
"usingGrunt",
")",
"{",
"return",
"rbot",
".",
"env",
".",
"taskRunner",
".",
"template",
".",
"process",
"(",
"val",
",",
"data",
")",
";",
"}",
"// TODO : add gulp template processing",
"if",
"(",
"!",
"val",
")",
"{",
"return",
"val",
";",
"}",
"return",
"val",
";",
"}"
] | Processes a value using the passed data
@param val
the value
@param data
the object that contains the template data to use
@returns the processed value | [
"Processes",
"a",
"value",
"using",
"the",
"passed",
"data"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/releasebot.js#L193-L202 |
55,140 | AndreasMadsen/immortal | lib/executables/pump.js | function (emits, message, daemonPid) {
var monitor = new Monitor(message, options, daemonPid, shutdown, child, function () {
// emit events before starting child
Object.keys(emits).forEach(function (name) {
// skip the process event until the child spawns
if (name === 'process') return;
monitor.emit.apply(monitor, [name].concat( emits[name] ));
});
// spawn child when monitor is ready
child.spawn();
// start pumping streams to monitor
child.pump(monitor);
});
// once the child has started emit the process event
child.once('start', function () {
monitor.pid.process = child.pid;
monitor.emit.apply(monitor, ['process'].concat( emits.process ));
});
// relay stop and restart to process event on monitor
child.on('stop', function () {
monitor.pid.process = null;
// Do not emit if the deamon is in restart mode
if (daemonInRestart) return;
monitor.emit('process', 'stop');
});
child.on('restart', function () {
monitor.pid.process = child.pid;
monitor.emit('process', 'restart');
});
} | javascript | function (emits, message, daemonPid) {
var monitor = new Monitor(message, options, daemonPid, shutdown, child, function () {
// emit events before starting child
Object.keys(emits).forEach(function (name) {
// skip the process event until the child spawns
if (name === 'process') return;
monitor.emit.apply(monitor, [name].concat( emits[name] ));
});
// spawn child when monitor is ready
child.spawn();
// start pumping streams to monitor
child.pump(monitor);
});
// once the child has started emit the process event
child.once('start', function () {
monitor.pid.process = child.pid;
monitor.emit.apply(monitor, ['process'].concat( emits.process ));
});
// relay stop and restart to process event on monitor
child.on('stop', function () {
monitor.pid.process = null;
// Do not emit if the deamon is in restart mode
if (daemonInRestart) return;
monitor.emit('process', 'stop');
});
child.on('restart', function () {
monitor.pid.process = child.pid;
monitor.emit('process', 'restart');
});
} | [
"function",
"(",
"emits",
",",
"message",
",",
"daemonPid",
")",
"{",
"var",
"monitor",
"=",
"new",
"Monitor",
"(",
"message",
",",
"options",
",",
"daemonPid",
",",
"shutdown",
",",
"child",
",",
"function",
"(",
")",
"{",
"// emit events before starting child",
"Object",
".",
"keys",
"(",
"emits",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"// skip the process event until the child spawns",
"if",
"(",
"name",
"===",
"'process'",
")",
"return",
";",
"monitor",
".",
"emit",
".",
"apply",
"(",
"monitor",
",",
"[",
"name",
"]",
".",
"concat",
"(",
"emits",
"[",
"name",
"]",
")",
")",
";",
"}",
")",
";",
"// spawn child when monitor is ready",
"child",
".",
"spawn",
"(",
")",
";",
"// start pumping streams to monitor",
"child",
".",
"pump",
"(",
"monitor",
")",
";",
"}",
")",
";",
"// once the child has started emit the process event",
"child",
".",
"once",
"(",
"'start'",
",",
"function",
"(",
")",
"{",
"monitor",
".",
"pid",
".",
"process",
"=",
"child",
".",
"pid",
";",
"monitor",
".",
"emit",
".",
"apply",
"(",
"monitor",
",",
"[",
"'process'",
"]",
".",
"concat",
"(",
"emits",
".",
"process",
")",
")",
";",
"}",
")",
";",
"// relay stop and restart to process event on monitor",
"child",
".",
"on",
"(",
"'stop'",
",",
"function",
"(",
")",
"{",
"monitor",
".",
"pid",
".",
"process",
"=",
"null",
";",
"// Do not emit if the deamon is in restart mode",
"if",
"(",
"daemonInRestart",
")",
"return",
";",
"monitor",
".",
"emit",
"(",
"'process'",
",",
"'stop'",
")",
";",
"}",
")",
";",
"child",
".",
"on",
"(",
"'restart'",
",",
"function",
"(",
")",
"{",
"monitor",
".",
"pid",
".",
"process",
"=",
"child",
".",
"pid",
";",
"monitor",
".",
"emit",
"(",
"'process'",
",",
"'restart'",
")",
";",
"}",
")",
";",
"}"
] | first create monitor object, the callback is executed when the monitor constructor call this.ready | [
"first",
"create",
"monitor",
"object",
"the",
"callback",
"is",
"executed",
"when",
"the",
"monitor",
"constructor",
"call",
"this",
".",
"ready"
] | c1ab5a4287a543fdfd980604a9e9927d663a9ef2 | https://github.com/AndreasMadsen/immortal/blob/c1ab5a4287a543fdfd980604a9e9927d663a9ef2/lib/executables/pump.js#L54-L90 |
|
55,141 | RnbWd/parse-browserify | lib/user.js | function(other) {
if (other.getSessionToken()) {
this._sessionToken = other.getSessionToken();
}
Parse.User.__super__._mergeFromObject.call(this, other);
} | javascript | function(other) {
if (other.getSessionToken()) {
this._sessionToken = other.getSessionToken();
}
Parse.User.__super__._mergeFromObject.call(this, other);
} | [
"function",
"(",
"other",
")",
"{",
"if",
"(",
"other",
".",
"getSessionToken",
"(",
")",
")",
"{",
"this",
".",
"_sessionToken",
"=",
"other",
".",
"getSessionToken",
"(",
")",
";",
"}",
"Parse",
".",
"User",
".",
"__super__",
".",
"_mergeFromObject",
".",
"call",
"(",
"this",
",",
"other",
")",
";",
"}"
] | Instance Methods
Merges another object's attributes into this object. | [
"Instance",
"Methods",
"Merges",
"another",
"object",
"s",
"attributes",
"into",
"this",
"object",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/user.js#L24-L29 |
|
55,142 | RnbWd/parse-browserify | lib/user.js | function(attrs) {
if (attrs.sessionToken) {
this._sessionToken = attrs.sessionToken;
delete attrs.sessionToken;
}
Parse.User.__super__._mergeMagicFields.call(this, attrs);
} | javascript | function(attrs) {
if (attrs.sessionToken) {
this._sessionToken = attrs.sessionToken;
delete attrs.sessionToken;
}
Parse.User.__super__._mergeMagicFields.call(this, attrs);
} | [
"function",
"(",
"attrs",
")",
"{",
"if",
"(",
"attrs",
".",
"sessionToken",
")",
"{",
"this",
".",
"_sessionToken",
"=",
"attrs",
".",
"sessionToken",
";",
"delete",
"attrs",
".",
"sessionToken",
";",
"}",
"Parse",
".",
"User",
".",
"__super__",
".",
"_mergeMagicFields",
".",
"call",
"(",
"this",
",",
"attrs",
")",
";",
"}"
] | Internal method to handle special fields in a _User response. | [
"Internal",
"method",
"to",
"handle",
"special",
"fields",
"in",
"a",
"_User",
"response",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/user.js#L34-L40 |
|
55,143 | RnbWd/parse-browserify | lib/user.js | function(provider, options) {
var authType;
if (_.isString(provider)) {
authType = provider;
provider = Parse.User._authProviders[provider];
} else {
authType = provider.getAuthType();
}
var newOptions = _.clone(options);
var self = this;
newOptions.authData = null;
newOptions.success = function(model) {
self._synchronizeAuthData(provider);
if (options.success) {
options.success.apply(this, arguments);
}
};
return this._linkWith(provider, newOptions);
} | javascript | function(provider, options) {
var authType;
if (_.isString(provider)) {
authType = provider;
provider = Parse.User._authProviders[provider];
} else {
authType = provider.getAuthType();
}
var newOptions = _.clone(options);
var self = this;
newOptions.authData = null;
newOptions.success = function(model) {
self._synchronizeAuthData(provider);
if (options.success) {
options.success.apply(this, arguments);
}
};
return this._linkWith(provider, newOptions);
} | [
"function",
"(",
"provider",
",",
"options",
")",
"{",
"var",
"authType",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"provider",
")",
")",
"{",
"authType",
"=",
"provider",
";",
"provider",
"=",
"Parse",
".",
"User",
".",
"_authProviders",
"[",
"provider",
"]",
";",
"}",
"else",
"{",
"authType",
"=",
"provider",
".",
"getAuthType",
"(",
")",
";",
"}",
"var",
"newOptions",
"=",
"_",
".",
"clone",
"(",
"options",
")",
";",
"var",
"self",
"=",
"this",
";",
"newOptions",
".",
"authData",
"=",
"null",
";",
"newOptions",
".",
"success",
"=",
"function",
"(",
"model",
")",
"{",
"self",
".",
"_synchronizeAuthData",
"(",
"provider",
")",
";",
"if",
"(",
"options",
".",
"success",
")",
"{",
"options",
".",
"success",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"return",
"this",
".",
"_linkWith",
"(",
"provider",
",",
"newOptions",
")",
";",
"}"
] | Unlinks a user from a service. | [
"Unlinks",
"a",
"user",
"from",
"a",
"service",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/user.js#L170-L188 |
|
55,144 | RnbWd/parse-browserify | lib/user.js | function(email, options) {
options = options || {};
var request = Parse._request({
route: "requestPasswordReset",
method: "POST",
useMasterKey: options.useMasterKey,
data: { email: email }
});
return request._thenRunCallbacks(options);
} | javascript | function(email, options) {
options = options || {};
var request = Parse._request({
route: "requestPasswordReset",
method: "POST",
useMasterKey: options.useMasterKey,
data: { email: email }
});
return request._thenRunCallbacks(options);
} | [
"function",
"(",
"email",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"request",
"=",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"\"requestPasswordReset\"",
",",
"method",
":",
"\"POST\"",
",",
"useMasterKey",
":",
"options",
".",
"useMasterKey",
",",
"data",
":",
"{",
"email",
":",
"email",
"}",
"}",
")",
";",
"return",
"request",
".",
"_thenRunCallbacks",
"(",
"options",
")",
";",
"}"
] | Requests a password reset email to be sent to the specified email address
associated with the user account. This email allows the user to securely
reset their password on the Parse site.
<p>Calls options.success or options.error on completion.</p>
@param {String} email The email address associated with the user that
forgot their password.
@param {Object} options A Backbone-style options object. | [
"Requests",
"a",
"password",
"reset",
"email",
"to",
"be",
"sent",
"to",
"the",
"specified",
"email",
"address",
"associated",
"with",
"the",
"user",
"account",
".",
"This",
"email",
"allows",
"the",
"user",
"to",
"securely",
"reset",
"their",
"password",
"on",
"the",
"Parse",
"site",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/user.js#L560-L569 |
|
55,145 | RnbWd/parse-browserify | lib/user.js | function() {
if (Parse.User._currentUser) {
return Parse.User._currentUser;
}
if (Parse.User._currentUserMatchesDisk) {
return Parse.User._currentUser;
}
// Load the user from local storage.
Parse.User._currentUserMatchesDisk = true;
var userData = Parse.localStorage.getItem(Parse._getParsePath(
Parse.User._CURRENT_USER_KEY));
if (!userData) {
return null;
}
Parse.User._currentUser = Parse.Object._create("_User");
Parse.User._currentUser._isCurrentUser = true;
var json = JSON.parse(userData);
Parse.User._currentUser.id = json._id;
delete json._id;
Parse.User._currentUser._sessionToken = json._sessionToken;
delete json._sessionToken;
Parse.User._currentUser._finishFetch(json);
Parse.User._currentUser._synchronizeAllAuthData();
Parse.User._currentUser._refreshCache();
Parse.User._currentUser._opSetQueue = [{}];
return Parse.User._currentUser;
} | javascript | function() {
if (Parse.User._currentUser) {
return Parse.User._currentUser;
}
if (Parse.User._currentUserMatchesDisk) {
return Parse.User._currentUser;
}
// Load the user from local storage.
Parse.User._currentUserMatchesDisk = true;
var userData = Parse.localStorage.getItem(Parse._getParsePath(
Parse.User._CURRENT_USER_KEY));
if (!userData) {
return null;
}
Parse.User._currentUser = Parse.Object._create("_User");
Parse.User._currentUser._isCurrentUser = true;
var json = JSON.parse(userData);
Parse.User._currentUser.id = json._id;
delete json._id;
Parse.User._currentUser._sessionToken = json._sessionToken;
delete json._sessionToken;
Parse.User._currentUser._finishFetch(json);
Parse.User._currentUser._synchronizeAllAuthData();
Parse.User._currentUser._refreshCache();
Parse.User._currentUser._opSetQueue = [{}];
return Parse.User._currentUser;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"Parse",
".",
"User",
".",
"_currentUser",
")",
"{",
"return",
"Parse",
".",
"User",
".",
"_currentUser",
";",
"}",
"if",
"(",
"Parse",
".",
"User",
".",
"_currentUserMatchesDisk",
")",
"{",
"return",
"Parse",
".",
"User",
".",
"_currentUser",
";",
"}",
"// Load the user from local storage.",
"Parse",
".",
"User",
".",
"_currentUserMatchesDisk",
"=",
"true",
";",
"var",
"userData",
"=",
"Parse",
".",
"localStorage",
".",
"getItem",
"(",
"Parse",
".",
"_getParsePath",
"(",
"Parse",
".",
"User",
".",
"_CURRENT_USER_KEY",
")",
")",
";",
"if",
"(",
"!",
"userData",
")",
"{",
"return",
"null",
";",
"}",
"Parse",
".",
"User",
".",
"_currentUser",
"=",
"Parse",
".",
"Object",
".",
"_create",
"(",
"\"_User\"",
")",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_isCurrentUser",
"=",
"true",
";",
"var",
"json",
"=",
"JSON",
".",
"parse",
"(",
"userData",
")",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"id",
"=",
"json",
".",
"_id",
";",
"delete",
"json",
".",
"_id",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_sessionToken",
"=",
"json",
".",
"_sessionToken",
";",
"delete",
"json",
".",
"_sessionToken",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_finishFetch",
"(",
"json",
")",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_synchronizeAllAuthData",
"(",
")",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_refreshCache",
"(",
")",
";",
"Parse",
".",
"User",
".",
"_currentUser",
".",
"_opSetQueue",
"=",
"[",
"{",
"}",
"]",
";",
"return",
"Parse",
".",
"User",
".",
"_currentUser",
";",
"}"
] | Retrieves the currently logged in ParseUser with a valid session,
either from memory or localStorage, if necessary.
@return {Parse.Object} The currently logged in Parse.User. | [
"Retrieves",
"the",
"currently",
"logged",
"in",
"ParseUser",
"with",
"a",
"valid",
"session",
"either",
"from",
"memory",
"or",
"localStorage",
"if",
"necessary",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/user.js#L576-L609 |
|
55,146 | codenothing/munit | lib/spy.js | function(){
spy.history = [];
spy.args = [];
spy.count = 0;
spy.scope = null;
spy.trace = null;
return spy;
} | javascript | function(){
spy.history = [];
spy.args = [];
spy.count = 0;
spy.scope = null;
spy.trace = null;
return spy;
} | [
"function",
"(",
")",
"{",
"spy",
".",
"history",
"=",
"[",
"]",
";",
"spy",
".",
"args",
"=",
"[",
"]",
";",
"spy",
".",
"count",
"=",
"0",
";",
"spy",
".",
"scope",
"=",
"null",
";",
"spy",
".",
"trace",
"=",
"null",
";",
"return",
"spy",
";",
"}"
] | Resets history and counters | [
"Resets",
"history",
"and",
"counters"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/spy.js#L115-L123 |
|
55,147 | codenothing/munit | lib/spy.js | function(){
if ( spy.wrapped ) {
spy._module[ spy._method ] = spy.original;
spy.wrapped = false;
}
return spy;
} | javascript | function(){
if ( spy.wrapped ) {
spy._module[ spy._method ] = spy.original;
spy.wrapped = false;
}
return spy;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"spy",
".",
"wrapped",
")",
"{",
"spy",
".",
"_module",
"[",
"spy",
".",
"_method",
"]",
"=",
"spy",
".",
"original",
";",
"spy",
".",
"wrapped",
"=",
"false",
";",
"}",
"return",
"spy",
";",
"}"
] | Restores the original method back | [
"Restores",
"the",
"original",
"method",
"back"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/spy.js#L126-L133 |
|
55,148 | codenothing/munit | lib/spy.js | SpyCall | function SpyCall( scope, args, spy ) {
var self = this;
if ( ! ( self instanceof SpyCall ) ) {
return new SpyCall( args );
}
self.scope = scope;
self.args = args;
self.time = new Date();
self.order = spy.assert._spyOrder++;
self.overall = Spy.overall++;
self.trace = ( new Error( "" ) ).stack;
} | javascript | function SpyCall( scope, args, spy ) {
var self = this;
if ( ! ( self instanceof SpyCall ) ) {
return new SpyCall( args );
}
self.scope = scope;
self.args = args;
self.time = new Date();
self.order = spy.assert._spyOrder++;
self.overall = Spy.overall++;
self.trace = ( new Error( "" ) ).stack;
} | [
"function",
"SpyCall",
"(",
"scope",
",",
"args",
",",
"spy",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"(",
"self",
"instanceof",
"SpyCall",
")",
")",
"{",
"return",
"new",
"SpyCall",
"(",
"args",
")",
";",
"}",
"self",
".",
"scope",
"=",
"scope",
";",
"self",
".",
"args",
"=",
"args",
";",
"self",
".",
"time",
"=",
"new",
"Date",
"(",
")",
";",
"self",
".",
"order",
"=",
"spy",
".",
"assert",
".",
"_spyOrder",
"++",
";",
"self",
".",
"overall",
"=",
"Spy",
".",
"overall",
"++",
";",
"self",
".",
"trace",
"=",
"(",
"new",
"Error",
"(",
"\"\"",
")",
")",
".",
"stack",
";",
"}"
] | Call History Object | [
"Call",
"History",
"Object"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/spy.js#L139-L152 |
55,149 | pinyin/outline | vendor/transformation-matrix/translate.js | translate | function translate(tx) {
var ty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return {
a: 1, c: 0, e: tx,
b: 0, d: 1, f: ty
};
} | javascript | function translate(tx) {
var ty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return {
a: 1, c: 0, e: tx,
b: 0, d: 1, f: ty
};
} | [
"function",
"translate",
"(",
"tx",
")",
"{",
"var",
"ty",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"0",
";",
"return",
"{",
"a",
":",
"1",
",",
"c",
":",
"0",
",",
"e",
":",
"tx",
",",
"b",
":",
"0",
",",
"d",
":",
"1",
",",
"f",
":",
"ty",
"}",
";",
"}"
] | Calculate a translate matrix
@param tx Translation on axis x
@param [ty = 0] Translation on axis y
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"translate",
"matrix"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/translate.js#L14-L21 |
55,150 | amandeepmittal/rainbow-log | index.js | log | function log(msg) {
process.stdout.write(time + ' ');
console.log(colors.log(msg));
} | javascript | function log(msg) {
process.stdout.write(time + ' ');
console.log(colors.log(msg));
} | [
"function",
"log",
"(",
"msg",
")",
"{",
"process",
".",
"stdout",
".",
"write",
"(",
"time",
"+",
"' '",
")",
";",
"console",
".",
"log",
"(",
"colors",
".",
"log",
"(",
"msg",
")",
")",
";",
"}"
] | console functions nodejs supports | [
"console",
"functions",
"nodejs",
"supports"
] | fb7153c36c1a27addf564512f68f2b67ec62e8f6 | https://github.com/amandeepmittal/rainbow-log/blob/fb7153c36c1a27addf564512f68f2b67ec62e8f6/index.js#L24-L27 |
55,151 | joneit/overrider | index.js | mixInTo | function mixInTo(target) {
var descriptor;
for (var key in this) {
if ((descriptor = Object.getOwnPropertyDescriptor(this, key))) {
Object.defineProperty(target, key, descriptor);
}
}
return target;
} | javascript | function mixInTo(target) {
var descriptor;
for (var key in this) {
if ((descriptor = Object.getOwnPropertyDescriptor(this, key))) {
Object.defineProperty(target, key, descriptor);
}
}
return target;
} | [
"function",
"mixInTo",
"(",
"target",
")",
"{",
"var",
"descriptor",
";",
"for",
"(",
"var",
"key",
"in",
"this",
")",
"{",
"if",
"(",
"(",
"descriptor",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"this",
",",
"key",
")",
")",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"target",
",",
"key",
",",
"descriptor",
")",
";",
"}",
"}",
"return",
"target",
";",
"}"
] | Mix `this` members into `target`.
@example
// A. Simple usage (using .call):
var mixInTo = require('overrider').mixInTo;
var target = { a: 1 }, source = { b: 2 };
target === overrider.mixInTo.call(source, target); // true
// target object now has both a and b; source object untouched
@example
// B. Semantic usage (when the source hosts the method):
var mixInTo = require('overrider').mixInTo;
var target = { a: 1 }, source = { b: 2, mixInTo: mixInTo };
target === source.mixInTo(target); // true
// target object now has both a and b; source object untouched
@this {object} Target.
@param target
@returns {object} The target object (`target`)
@memberOf module:overrider | [
"Mix",
"this",
"members",
"into",
"target",
"."
] | 57c406d3c9e62c2cf4d4231b029bd868f8fe0c47 | https://github.com/joneit/overrider/blob/57c406d3c9e62c2cf4d4231b029bd868f8fe0c47/index.js#L50-L58 |
55,152 | joneit/overrider | index.js | mixIn | function mixIn(source) {
var descriptor;
for (var key in source) {
if ((descriptor = Object.getOwnPropertyDescriptor(source, key))) {
Object.defineProperty(this, key, descriptor);
}
}
return this;
} | javascript | function mixIn(source) {
var descriptor;
for (var key in source) {
if ((descriptor = Object.getOwnPropertyDescriptor(source, key))) {
Object.defineProperty(this, key, descriptor);
}
}
return this;
} | [
"function",
"mixIn",
"(",
"source",
")",
"{",
"var",
"descriptor",
";",
"for",
"(",
"var",
"key",
"in",
"source",
")",
"{",
"if",
"(",
"(",
"descriptor",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"source",
",",
"key",
")",
")",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"key",
",",
"descriptor",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Mix `source` members into `this`.
@example
// A. Simple usage (using .call):
var mixIn = require('overrider').mixIn;
var target = { a: 1 }, source = { b: 2 };
target === overrider.mixIn.call(target, source) // true
// target object now has both a and b; source object untouched
@example
// B. Semantic usage (when the target hosts the method):
var mixIn = require('overrider').mixIn;
var target = { a: 1, mixIn: mixIn }, source = { b: 2 };
target === target.mixIn(source) // true
// target now has both a and b (and mixIn); source untouched
@param source
@returns {object} The target object (`this`)
@memberOf overrider
@memberOf module:overrider | [
"Mix",
"source",
"members",
"into",
"this",
"."
] | 57c406d3c9e62c2cf4d4231b029bd868f8fe0c47 | https://github.com/joneit/overrider/blob/57c406d3c9e62c2cf4d4231b029bd868f8fe0c47/index.js#L82-L90 |
55,153 | mallocator/docker-cli-proxy | lib/index.js | cleanObject | function cleanObject(obj) {
if (obj instanceof Object) {
Object.keys(obj).forEach((key) => (obj[key] == null) && delete obj[key]);
}
return obj;
} | javascript | function cleanObject(obj) {
if (obj instanceof Object) {
Object.keys(obj).forEach((key) => (obj[key] == null) && delete obj[key]);
}
return obj;
} | [
"function",
"cleanObject",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
"instanceof",
"Object",
")",
"{",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"(",
"obj",
"[",
"key",
"]",
"==",
"null",
")",
"&&",
"delete",
"obj",
"[",
"key",
"]",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Removes any properties from an object that resolve to null.
@param {Object} obj | [
"Removes",
"any",
"properties",
"from",
"an",
"object",
"that",
"resolve",
"to",
"null",
"."
] | 6dcd85e3eaaccac9318feab797eeec272d790b97 | https://github.com/mallocator/docker-cli-proxy/blob/6dcd85e3eaaccac9318feab797eeec272d790b97/lib/index.js#L29-L34 |
55,154 | mallocator/docker-cli-proxy | lib/index.js | getDockerfileContext | function getDockerfileContext(context) {
const fs = require('fs');
let files = [];
let dockerfile = exports.resolveDockerfile(context);
let file = fs.readFileSync(dockerfile, {encoding: 'utf8'});
for (let line of file.split('\n')) {
if (line.match(/^\s*(ADD|COPY).*$/)) {
let entries = line.split(' ')
.splice(1)
.map(val => val.trim())
.filter(val => val !== '')
.filter(val => !val.startsWith('http'));
if (entries[0].startsWith('--chown')) {
entries = entries.splice(1);
}
// Array mode
if (line.indexOf('[') !== -1 && line.indexOf(']') !== -1) {
let args = JSON.parse(entries.join(' '));
args.splice(-1);
files = args
}
// Default mode
else {
entries.splice(-1);
files = entries;
}
}
}
let resolvedFiles = [];
for (let file of files) {
resolvedFiles = resolvedFiles.concat(glob.sync(path.join(path.dirname(context), file)));
}
return { context, src: ['Dockerfile', ...resolvedFiles] };
} | javascript | function getDockerfileContext(context) {
const fs = require('fs');
let files = [];
let dockerfile = exports.resolveDockerfile(context);
let file = fs.readFileSync(dockerfile, {encoding: 'utf8'});
for (let line of file.split('\n')) {
if (line.match(/^\s*(ADD|COPY).*$/)) {
let entries = line.split(' ')
.splice(1)
.map(val => val.trim())
.filter(val => val !== '')
.filter(val => !val.startsWith('http'));
if (entries[0].startsWith('--chown')) {
entries = entries.splice(1);
}
// Array mode
if (line.indexOf('[') !== -1 && line.indexOf(']') !== -1) {
let args = JSON.parse(entries.join(' '));
args.splice(-1);
files = args
}
// Default mode
else {
entries.splice(-1);
files = entries;
}
}
}
let resolvedFiles = [];
for (let file of files) {
resolvedFiles = resolvedFiles.concat(glob.sync(path.join(path.dirname(context), file)));
}
return { context, src: ['Dockerfile', ...resolvedFiles] };
} | [
"function",
"getDockerfileContext",
"(",
"context",
")",
"{",
"const",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"let",
"files",
"=",
"[",
"]",
";",
"let",
"dockerfile",
"=",
"exports",
".",
"resolveDockerfile",
"(",
"context",
")",
";",
"let",
"file",
"=",
"fs",
".",
"readFileSync",
"(",
"dockerfile",
",",
"{",
"encoding",
":",
"'utf8'",
"}",
")",
";",
"for",
"(",
"let",
"line",
"of",
"file",
".",
"split",
"(",
"'\\n'",
")",
")",
"{",
"if",
"(",
"line",
".",
"match",
"(",
"/",
"^\\s*(ADD|COPY).*$",
"/",
")",
")",
"{",
"let",
"entries",
"=",
"line",
".",
"split",
"(",
"' '",
")",
".",
"splice",
"(",
"1",
")",
".",
"map",
"(",
"val",
"=>",
"val",
".",
"trim",
"(",
")",
")",
".",
"filter",
"(",
"val",
"=>",
"val",
"!==",
"''",
")",
".",
"filter",
"(",
"val",
"=>",
"!",
"val",
".",
"startsWith",
"(",
"'http'",
")",
")",
";",
"if",
"(",
"entries",
"[",
"0",
"]",
".",
"startsWith",
"(",
"'--chown'",
")",
")",
"{",
"entries",
"=",
"entries",
".",
"splice",
"(",
"1",
")",
";",
"}",
"// Array mode",
"if",
"(",
"line",
".",
"indexOf",
"(",
"'['",
")",
"!==",
"-",
"1",
"&&",
"line",
".",
"indexOf",
"(",
"']'",
")",
"!==",
"-",
"1",
")",
"{",
"let",
"args",
"=",
"JSON",
".",
"parse",
"(",
"entries",
".",
"join",
"(",
"' '",
")",
")",
";",
"args",
".",
"splice",
"(",
"-",
"1",
")",
";",
"files",
"=",
"args",
"}",
"// Default mode",
"else",
"{",
"entries",
".",
"splice",
"(",
"-",
"1",
")",
";",
"files",
"=",
"entries",
";",
"}",
"}",
"}",
"let",
"resolvedFiles",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"file",
"of",
"files",
")",
"{",
"resolvedFiles",
"=",
"resolvedFiles",
".",
"concat",
"(",
"glob",
".",
"sync",
"(",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"context",
")",
",",
"file",
")",
")",
")",
";",
"}",
"return",
"{",
"context",
",",
"src",
":",
"[",
"'Dockerfile'",
",",
"...",
"resolvedFiles",
"]",
"}",
";",
"}"
] | Parses a Dockerfile and looks for sources that may be needed to build this image.
@param context
@returns {{context: *, src: *[]}} | [
"Parses",
"a",
"Dockerfile",
"and",
"looks",
"for",
"sources",
"that",
"may",
"be",
"needed",
"to",
"build",
"this",
"image",
"."
] | 6dcd85e3eaaccac9318feab797eeec272d790b97 | https://github.com/mallocator/docker-cli-proxy/blob/6dcd85e3eaaccac9318feab797eeec272d790b97/lib/index.js#L58-L94 |
55,155 | nomocas/yamvish | lib/output-engine/string.js | tagOutput | function tagOutput(descriptor, innerDescriptor, name) {
var out = '<' + name + innerDescriptor.attributes;
if (innerDescriptor.style)
out += ' style="' + innerDescriptor.style + '"';
if (innerDescriptor.classes)
out += ' class="' + innerDescriptor.classes + '"';
if (innerDescriptor.children)
descriptor.children += out + '>' + innerDescriptor.children + '</' + name + '>';
else if (openTags.test(name))
descriptor.children += out + '>';
else if (strictTags.test(name))
descriptor.children += out + '></' + name + '>';
else
descriptor.children += out + '/>';
} | javascript | function tagOutput(descriptor, innerDescriptor, name) {
var out = '<' + name + innerDescriptor.attributes;
if (innerDescriptor.style)
out += ' style="' + innerDescriptor.style + '"';
if (innerDescriptor.classes)
out += ' class="' + innerDescriptor.classes + '"';
if (innerDescriptor.children)
descriptor.children += out + '>' + innerDescriptor.children + '</' + name + '>';
else if (openTags.test(name))
descriptor.children += out + '>';
else if (strictTags.test(name))
descriptor.children += out + '></' + name + '>';
else
descriptor.children += out + '/>';
} | [
"function",
"tagOutput",
"(",
"descriptor",
",",
"innerDescriptor",
",",
"name",
")",
"{",
"var",
"out",
"=",
"'<'",
"+",
"name",
"+",
"innerDescriptor",
".",
"attributes",
";",
"if",
"(",
"innerDescriptor",
".",
"style",
")",
"out",
"+=",
"' style=\"'",
"+",
"innerDescriptor",
".",
"style",
"+",
"'\"'",
";",
"if",
"(",
"innerDescriptor",
".",
"classes",
")",
"out",
"+=",
"' class=\"'",
"+",
"innerDescriptor",
".",
"classes",
"+",
"'\"'",
";",
"if",
"(",
"innerDescriptor",
".",
"children",
")",
"descriptor",
".",
"children",
"+=",
"out",
"+",
"'>'",
"+",
"innerDescriptor",
".",
"children",
"+",
"'</'",
"+",
"name",
"+",
"'>'",
";",
"else",
"if",
"(",
"openTags",
".",
"test",
"(",
"name",
")",
")",
"descriptor",
".",
"children",
"+=",
"out",
"+",
"'>'",
";",
"else",
"if",
"(",
"strictTags",
".",
"test",
"(",
"name",
")",
")",
"descriptor",
".",
"children",
"+=",
"out",
"+",
"'></'",
"+",
"name",
"+",
"'>'",
";",
"else",
"descriptor",
".",
"children",
"+=",
"out",
"+",
"'/>'",
";",
"}"
] | produce final html tag representation | [
"produce",
"final",
"html",
"tag",
"representation"
] | 017a536bb6bafddf1b31c0c7af6f723be58e9f0e | https://github.com/nomocas/yamvish/blob/017a536bb6bafddf1b31c0c7af6f723be58e9f0e/lib/output-engine/string.js#L38-L52 |
55,156 | MaiaVictor/dattata | canvasImage.js | function(width, height){
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext("2d");
var imageData = context.getImageData(0, 0, width, height);
var buffer = new ArrayBuffer(width*height*4);
var buffer8 = new Uint8ClampedArray(buffer);
var buffer32 = new Uint32Array(buffer);
return {
canvas: canvas,
context: context,
width: width,
height: height,
imageData: imageData,
buffer8: buffer8,
buffer32: buffer32};
} | javascript | function(width, height){
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext("2d");
var imageData = context.getImageData(0, 0, width, height);
var buffer = new ArrayBuffer(width*height*4);
var buffer8 = new Uint8ClampedArray(buffer);
var buffer32 = new Uint32Array(buffer);
return {
canvas: canvas,
context: context,
width: width,
height: height,
imageData: imageData,
buffer8: buffer8,
buffer32: buffer32};
} | [
"function",
"(",
"width",
",",
"height",
")",
"{",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"\"canvas\"",
")",
";",
"canvas",
".",
"width",
"=",
"width",
";",
"canvas",
".",
"height",
"=",
"height",
";",
"var",
"context",
"=",
"canvas",
".",
"getContext",
"(",
"\"2d\"",
")",
";",
"var",
"imageData",
"=",
"context",
".",
"getImageData",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
";",
"var",
"buffer",
"=",
"new",
"ArrayBuffer",
"(",
"width",
"*",
"height",
"*",
"4",
")",
";",
"var",
"buffer8",
"=",
"new",
"Uint8ClampedArray",
"(",
"buffer",
")",
";",
"var",
"buffer32",
"=",
"new",
"Uint32Array",
"(",
"buffer",
")",
";",
"return",
"{",
"canvas",
":",
"canvas",
",",
"context",
":",
"context",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
",",
"imageData",
":",
"imageData",
",",
"buffer8",
":",
"buffer8",
",",
"buffer32",
":",
"buffer32",
"}",
";",
"}"
] | Uint, Uint -> CanvasImage | [
"Uint",
"Uint",
"-",
">",
"CanvasImage"
] | 890d83b89b7193ce8863bb9ac9b296b3510e8db9 | https://github.com/MaiaVictor/dattata/blob/890d83b89b7193ce8863bb9ac9b296b3510e8db9/canvasImage.js#L3-L20 |
|
55,157 | skenqbx/file-emitter | lib/file-emitter.js | FileEmitter | function FileEmitter(folder, opt_options) {
if (!(this instanceof FileEmitter)) {
return new FileEmitter(folder, opt_options);
}
events.EventEmitter.call(this);
opt_options = opt_options || {};
this.root = path.resolve(process.cwd(), folder);
// flags & options
this.buffer = opt_options.buffer || false;
this.incremental = opt_options.incremental || false;
this.followSymLinks = opt_options.followSymLinks || false;
this.recursive = opt_options.recursive === false ? false : true;
this.maxBufferSize = opt_options.maxBufferSize || 10485760; // 10 MiB
// file constructor
this.File = opt_options.File || File;
// filters
this.include = opt_options.include || false;
this.exclude = opt_options.exclude || false;
this._minimatchOptions = opt_options.minimatchOptions || {matchBase: true};
// read, stat & readdir queues
this._queues = [[], [], ['']];
// max number of open file descriptors (used for incremental EMFILE back-off)
this._maxFDs = opt_options.maxFDs || Infinity; // UNDOCUMENTED OPTION
// currently open file descriptors
this._numFDs = 0;
// incremental lock
this._locked = false;
this._hadError = false;
var self = this;
if (opt_options.autorun !== false) {
setImmediate(function() {
self.run();
});
}
} | javascript | function FileEmitter(folder, opt_options) {
if (!(this instanceof FileEmitter)) {
return new FileEmitter(folder, opt_options);
}
events.EventEmitter.call(this);
opt_options = opt_options || {};
this.root = path.resolve(process.cwd(), folder);
// flags & options
this.buffer = opt_options.buffer || false;
this.incremental = opt_options.incremental || false;
this.followSymLinks = opt_options.followSymLinks || false;
this.recursive = opt_options.recursive === false ? false : true;
this.maxBufferSize = opt_options.maxBufferSize || 10485760; // 10 MiB
// file constructor
this.File = opt_options.File || File;
// filters
this.include = opt_options.include || false;
this.exclude = opt_options.exclude || false;
this._minimatchOptions = opt_options.minimatchOptions || {matchBase: true};
// read, stat & readdir queues
this._queues = [[], [], ['']];
// max number of open file descriptors (used for incremental EMFILE back-off)
this._maxFDs = opt_options.maxFDs || Infinity; // UNDOCUMENTED OPTION
// currently open file descriptors
this._numFDs = 0;
// incremental lock
this._locked = false;
this._hadError = false;
var self = this;
if (opt_options.autorun !== false) {
setImmediate(function() {
self.run();
});
}
} | [
"function",
"FileEmitter",
"(",
"folder",
",",
"opt_options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"FileEmitter",
")",
")",
"{",
"return",
"new",
"FileEmitter",
"(",
"folder",
",",
"opt_options",
")",
";",
"}",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"opt_options",
"=",
"opt_options",
"||",
"{",
"}",
";",
"this",
".",
"root",
"=",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"folder",
")",
";",
"// flags & options",
"this",
".",
"buffer",
"=",
"opt_options",
".",
"buffer",
"||",
"false",
";",
"this",
".",
"incremental",
"=",
"opt_options",
".",
"incremental",
"||",
"false",
";",
"this",
".",
"followSymLinks",
"=",
"opt_options",
".",
"followSymLinks",
"||",
"false",
";",
"this",
".",
"recursive",
"=",
"opt_options",
".",
"recursive",
"===",
"false",
"?",
"false",
":",
"true",
";",
"this",
".",
"maxBufferSize",
"=",
"opt_options",
".",
"maxBufferSize",
"||",
"10485760",
";",
"// 10 MiB",
"// file constructor",
"this",
".",
"File",
"=",
"opt_options",
".",
"File",
"||",
"File",
";",
"// filters",
"this",
".",
"include",
"=",
"opt_options",
".",
"include",
"||",
"false",
";",
"this",
".",
"exclude",
"=",
"opt_options",
".",
"exclude",
"||",
"false",
";",
"this",
".",
"_minimatchOptions",
"=",
"opt_options",
".",
"minimatchOptions",
"||",
"{",
"matchBase",
":",
"true",
"}",
";",
"// read, stat & readdir queues",
"this",
".",
"_queues",
"=",
"[",
"[",
"]",
",",
"[",
"]",
",",
"[",
"''",
"]",
"]",
";",
"// max number of open file descriptors (used for incremental EMFILE back-off)",
"this",
".",
"_maxFDs",
"=",
"opt_options",
".",
"maxFDs",
"||",
"Infinity",
";",
"// UNDOCUMENTED OPTION",
"// currently open file descriptors",
"this",
".",
"_numFDs",
"=",
"0",
";",
"// incremental lock",
"this",
".",
"_locked",
"=",
"false",
";",
"this",
".",
"_hadError",
"=",
"false",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"opt_options",
".",
"autorun",
"!==",
"false",
")",
"{",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"self",
".",
"run",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | file-emitter
**opt_options**
- `{boolean} buffer` Load each file into a buffer before emitting, defaults to `false`
- `{number} maxBufferSize` The max size of a file buffer, defaults to `10485760` (=10MiB)
- `{boolean} incremental` When `true` each `file` event has to be acknowledged by calling `fe.next()`
- `{boolean} followSymLinks` ..., defaults to `false`
- `{boolean} recursive` ..., defaults to `true`
- `{boolean} autorun` ..., defaults to `true`
- `{Array<string>} exclude` glob patterns applied after `readir`
- `{Array<string>} include` glob patterns applied after `stat`
- `{Object} minimatchOptions` See `minimatch` README, defaults to `{matchBase: true}`
- `{Function} File` A custom constructor for file objects, has to extend `File`
@param {string} folder
@param {?Object} opt_options
@constructor | [
"file",
"-",
"emitter"
] | a17e03dbb251bd79772101a94a1e6b116b01f1f7 | https://github.com/skenqbx/file-emitter/blob/a17e03dbb251bd79772101a94a1e6b116b01f1f7/lib/file-emitter.js#L31-L73 |
55,158 | gmalysa/flux-link | coverage.js | reportCoverage | function reportCoverage(cov) {
// Stats
print('\n [bold]{Test Coverage}\n');
var sep = ' +------------------------------------------+----------+------+------+--------+',
lastSep = ' +----------+------+------+--------+';
result = sep+'\n';
result += ' | filename | coverage | LOC | SLOC | missed |\n';
result += sep+'\n';
for (var name in cov) {
var file = cov[name];
if (Array.isArray(file)) {
result += ' | ' + rpad(name, 40);
result += ' | ' + lpad(file.coverage.toFixed(2), 8);
result += ' | ' + lpad(file.LOC, 4);
result += ' | ' + lpad(file.SLOC, 4);
result += ' | ' + lpad(file.totalMisses, 6);
result += ' |\n';
}
}
result += sep+'\n';
result += ' ' + rpad('', 40);
result += ' | ' + lpad(cov.coverage.toFixed(2), 8);
result += ' | ' + lpad(cov.LOC, 4);
result += ' | ' + lpad(cov.SLOC, 4);
result += ' | ' + lpad(cov.totalMisses, 6);
result += ' |\n';
result += lastSep;
console.log(result);
for (var name in cov) {
if (name.match(file_matcher)) {
var file = cov[name];
var annotated = '';
annotated += colorize('\n [bold]{' + name + '}:');
annotated += colorize(file.source);
annotated += '\n';
fs.writeFileSync('annotated/'+name, annotated);
}
}
} | javascript | function reportCoverage(cov) {
// Stats
print('\n [bold]{Test Coverage}\n');
var sep = ' +------------------------------------------+----------+------+------+--------+',
lastSep = ' +----------+------+------+--------+';
result = sep+'\n';
result += ' | filename | coverage | LOC | SLOC | missed |\n';
result += sep+'\n';
for (var name in cov) {
var file = cov[name];
if (Array.isArray(file)) {
result += ' | ' + rpad(name, 40);
result += ' | ' + lpad(file.coverage.toFixed(2), 8);
result += ' | ' + lpad(file.LOC, 4);
result += ' | ' + lpad(file.SLOC, 4);
result += ' | ' + lpad(file.totalMisses, 6);
result += ' |\n';
}
}
result += sep+'\n';
result += ' ' + rpad('', 40);
result += ' | ' + lpad(cov.coverage.toFixed(2), 8);
result += ' | ' + lpad(cov.LOC, 4);
result += ' | ' + lpad(cov.SLOC, 4);
result += ' | ' + lpad(cov.totalMisses, 6);
result += ' |\n';
result += lastSep;
console.log(result);
for (var name in cov) {
if (name.match(file_matcher)) {
var file = cov[name];
var annotated = '';
annotated += colorize('\n [bold]{' + name + '}:');
annotated += colorize(file.source);
annotated += '\n';
fs.writeFileSync('annotated/'+name, annotated);
}
}
} | [
"function",
"reportCoverage",
"(",
"cov",
")",
"{",
"// Stats",
"print",
"(",
"'\\n [bold]{Test Coverage}\\n'",
")",
";",
"var",
"sep",
"=",
"' +------------------------------------------+----------+------+------+--------+'",
",",
"lastSep",
"=",
"' +----------+------+------+--------+'",
";",
"result",
"=",
"sep",
"+",
"'\\n'",
";",
"result",
"+=",
"' | filename | coverage | LOC | SLOC | missed |\\n'",
";",
"result",
"+=",
"sep",
"+",
"'\\n'",
";",
"for",
"(",
"var",
"name",
"in",
"cov",
")",
"{",
"var",
"file",
"=",
"cov",
"[",
"name",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"file",
")",
")",
"{",
"result",
"+=",
"' | '",
"+",
"rpad",
"(",
"name",
",",
"40",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"file",
".",
"coverage",
".",
"toFixed",
"(",
"2",
")",
",",
"8",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"file",
".",
"LOC",
",",
"4",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"file",
".",
"SLOC",
",",
"4",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"file",
".",
"totalMisses",
",",
"6",
")",
";",
"result",
"+=",
"' |\\n'",
";",
"}",
"}",
"result",
"+=",
"sep",
"+",
"'\\n'",
";",
"result",
"+=",
"' '",
"+",
"rpad",
"(",
"''",
",",
"40",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"cov",
".",
"coverage",
".",
"toFixed",
"(",
"2",
")",
",",
"8",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"cov",
".",
"LOC",
",",
"4",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"cov",
".",
"SLOC",
",",
"4",
")",
";",
"result",
"+=",
"' | '",
"+",
"lpad",
"(",
"cov",
".",
"totalMisses",
",",
"6",
")",
";",
"result",
"+=",
"' |\\n'",
";",
"result",
"+=",
"lastSep",
";",
"console",
".",
"log",
"(",
"result",
")",
";",
"for",
"(",
"var",
"name",
"in",
"cov",
")",
"{",
"if",
"(",
"name",
".",
"match",
"(",
"file_matcher",
")",
")",
"{",
"var",
"file",
"=",
"cov",
"[",
"name",
"]",
";",
"var",
"annotated",
"=",
"''",
";",
"annotated",
"+=",
"colorize",
"(",
"'\\n [bold]{'",
"+",
"name",
"+",
"'}:'",
")",
";",
"annotated",
"+=",
"colorize",
"(",
"file",
".",
"source",
")",
";",
"annotated",
"+=",
"'\\n'",
";",
"fs",
".",
"writeFileSync",
"(",
"'annotated/'",
"+",
"name",
",",
"annotated",
")",
";",
"}",
"}",
"}"
] | Report test coverage.
@param {Object} cov | [
"Report",
"test",
"coverage",
"."
] | 567ac39a1f4a74f85465a58fb6fd96d64b1b765f | https://github.com/gmalysa/flux-link/blob/567ac39a1f4a74f85465a58fb6fd96d64b1b765f/coverage.js#L154-L193 |
55,159 | gmalysa/flux-link | coverage.js | populateCoverage | function populateCoverage(cov) {
cov.LOC =
cov.SLOC =
cov.totalFiles =
cov.totalHits =
cov.totalMisses =
cov.coverage = 0;
for (var name in cov) {
var file = cov[name];
if (Array.isArray(file)) {
// Stats
++cov.totalFiles;
cov.totalHits += file.totalHits = coverage(file, true);
cov.totalMisses += file.totalMisses = coverage(file, false);
file.totalLines = file.totalHits + file.totalMisses;
cov.SLOC += file.SLOC = file.totalLines;
if (!file.source) file.source = [];
cov.LOC += file.LOC = file.source.length;
file.coverage = (file.totalHits / file.totalLines) * 100;
// Source
var width = file.source.length.toString().length;
file.source = file.source.map(function(line, i){
++i;
var hits = file[i] === 0 ? 0 : (file[i] || ' ');
if (hits === 0) {
hits = '\x1b[31m' + hits + '\x1b[0m';
line = '\x1b[41m' + line + '\x1b[0m';
} else {
hits = '\x1b[32m' + hits + '\x1b[0m';
}
return '\n ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
}).join('');
}
}
cov.coverage = (cov.totalHits / cov.SLOC) * 100;
} | javascript | function populateCoverage(cov) {
cov.LOC =
cov.SLOC =
cov.totalFiles =
cov.totalHits =
cov.totalMisses =
cov.coverage = 0;
for (var name in cov) {
var file = cov[name];
if (Array.isArray(file)) {
// Stats
++cov.totalFiles;
cov.totalHits += file.totalHits = coverage(file, true);
cov.totalMisses += file.totalMisses = coverage(file, false);
file.totalLines = file.totalHits + file.totalMisses;
cov.SLOC += file.SLOC = file.totalLines;
if (!file.source) file.source = [];
cov.LOC += file.LOC = file.source.length;
file.coverage = (file.totalHits / file.totalLines) * 100;
// Source
var width = file.source.length.toString().length;
file.source = file.source.map(function(line, i){
++i;
var hits = file[i] === 0 ? 0 : (file[i] || ' ');
if (hits === 0) {
hits = '\x1b[31m' + hits + '\x1b[0m';
line = '\x1b[41m' + line + '\x1b[0m';
} else {
hits = '\x1b[32m' + hits + '\x1b[0m';
}
return '\n ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
}).join('');
}
}
cov.coverage = (cov.totalHits / cov.SLOC) * 100;
} | [
"function",
"populateCoverage",
"(",
"cov",
")",
"{",
"cov",
".",
"LOC",
"=",
"cov",
".",
"SLOC",
"=",
"cov",
".",
"totalFiles",
"=",
"cov",
".",
"totalHits",
"=",
"cov",
".",
"totalMisses",
"=",
"cov",
".",
"coverage",
"=",
"0",
";",
"for",
"(",
"var",
"name",
"in",
"cov",
")",
"{",
"var",
"file",
"=",
"cov",
"[",
"name",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"file",
")",
")",
"{",
"// Stats",
"++",
"cov",
".",
"totalFiles",
";",
"cov",
".",
"totalHits",
"+=",
"file",
".",
"totalHits",
"=",
"coverage",
"(",
"file",
",",
"true",
")",
";",
"cov",
".",
"totalMisses",
"+=",
"file",
".",
"totalMisses",
"=",
"coverage",
"(",
"file",
",",
"false",
")",
";",
"file",
".",
"totalLines",
"=",
"file",
".",
"totalHits",
"+",
"file",
".",
"totalMisses",
";",
"cov",
".",
"SLOC",
"+=",
"file",
".",
"SLOC",
"=",
"file",
".",
"totalLines",
";",
"if",
"(",
"!",
"file",
".",
"source",
")",
"file",
".",
"source",
"=",
"[",
"]",
";",
"cov",
".",
"LOC",
"+=",
"file",
".",
"LOC",
"=",
"file",
".",
"source",
".",
"length",
";",
"file",
".",
"coverage",
"=",
"(",
"file",
".",
"totalHits",
"/",
"file",
".",
"totalLines",
")",
"*",
"100",
";",
"// Source",
"var",
"width",
"=",
"file",
".",
"source",
".",
"length",
".",
"toString",
"(",
")",
".",
"length",
";",
"file",
".",
"source",
"=",
"file",
".",
"source",
".",
"map",
"(",
"function",
"(",
"line",
",",
"i",
")",
"{",
"++",
"i",
";",
"var",
"hits",
"=",
"file",
"[",
"i",
"]",
"===",
"0",
"?",
"0",
":",
"(",
"file",
"[",
"i",
"]",
"||",
"' '",
")",
";",
"if",
"(",
"hits",
"===",
"0",
")",
"{",
"hits",
"=",
"'\\x1b[31m'",
"+",
"hits",
"+",
"'\\x1b[0m'",
";",
"line",
"=",
"'\\x1b[41m'",
"+",
"line",
"+",
"'\\x1b[0m'",
";",
"}",
"else",
"{",
"hits",
"=",
"'\\x1b[32m'",
"+",
"hits",
"+",
"'\\x1b[0m'",
";",
"}",
"return",
"'\\n '",
"+",
"lpad",
"(",
"i",
",",
"width",
")",
"+",
"' | '",
"+",
"hits",
"+",
"' | '",
"+",
"line",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"}",
"}",
"cov",
".",
"coverage",
"=",
"(",
"cov",
".",
"totalHits",
"/",
"cov",
".",
"SLOC",
")",
"*",
"100",
";",
"}"
] | Populate code coverage data.
@param {Object} cov | [
"Populate",
"code",
"coverage",
"data",
"."
] | 567ac39a1f4a74f85465a58fb6fd96d64b1b765f | https://github.com/gmalysa/flux-link/blob/567ac39a1f4a74f85465a58fb6fd96d64b1b765f/coverage.js#L200-L235 |
55,160 | gmalysa/flux-link | coverage.js | hasFullCoverage | function hasFullCoverage(cov) {
for (var name in cov) {
var file = cov[name];
if (file instanceof Array) {
if (file.coverage !== 100) {
return false;
}
}
}
return true;
} | javascript | function hasFullCoverage(cov) {
for (var name in cov) {
var file = cov[name];
if (file instanceof Array) {
if (file.coverage !== 100) {
return false;
}
}
}
return true;
} | [
"function",
"hasFullCoverage",
"(",
"cov",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"cov",
")",
"{",
"var",
"file",
"=",
"cov",
"[",
"name",
"]",
";",
"if",
"(",
"file",
"instanceof",
"Array",
")",
"{",
"if",
"(",
"file",
".",
"coverage",
"!==",
"100",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Test if all files have 100% coverage
@param {Object} cov
@return {Boolean} | [
"Test",
"if",
"all",
"files",
"have",
"100%",
"coverage"
] | 567ac39a1f4a74f85465a58fb6fd96d64b1b765f | https://github.com/gmalysa/flux-link/blob/567ac39a1f4a74f85465a58fb6fd96d64b1b765f/coverage.js#L259-L269 |
55,161 | maxleiko/wsmsgbroker | lib/actions/server/send.js | send | function send(id) {
if (msg.ack) { server._rememberAck(msg.ack, ws.broker_uuid); }
var destWs = server.id2ws[id];
if (destWs) {
if (destWs.readyState === WebSocket.OPEN) {
destWs.send(JSON.stringify({
action: 'message',
message: msg.message,
ack: msg.ack,
from: server.ws2id[ws.broker_uuid]
}));
} else {
err = new Error('Unable to send message. Client "'+id+'" disconnected');
server.emit('error', err);
}
} else {
server.emit('warn', new Error('Unable to send message. Client "'+id+'" unknown'));
}
} | javascript | function send(id) {
if (msg.ack) { server._rememberAck(msg.ack, ws.broker_uuid); }
var destWs = server.id2ws[id];
if (destWs) {
if (destWs.readyState === WebSocket.OPEN) {
destWs.send(JSON.stringify({
action: 'message',
message: msg.message,
ack: msg.ack,
from: server.ws2id[ws.broker_uuid]
}));
} else {
err = new Error('Unable to send message. Client "'+id+'" disconnected');
server.emit('error', err);
}
} else {
server.emit('warn', new Error('Unable to send message. Client "'+id+'" unknown'));
}
} | [
"function",
"send",
"(",
"id",
")",
"{",
"if",
"(",
"msg",
".",
"ack",
")",
"{",
"server",
".",
"_rememberAck",
"(",
"msg",
".",
"ack",
",",
"ws",
".",
"broker_uuid",
")",
";",
"}",
"var",
"destWs",
"=",
"server",
".",
"id2ws",
"[",
"id",
"]",
";",
"if",
"(",
"destWs",
")",
"{",
"if",
"(",
"destWs",
".",
"readyState",
"===",
"WebSocket",
".",
"OPEN",
")",
"{",
"destWs",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"action",
":",
"'message'",
",",
"message",
":",
"msg",
".",
"message",
",",
"ack",
":",
"msg",
".",
"ack",
",",
"from",
":",
"server",
".",
"ws2id",
"[",
"ws",
".",
"broker_uuid",
"]",
"}",
")",
")",
";",
"}",
"else",
"{",
"err",
"=",
"new",
"Error",
"(",
"'Unable to send message. Client \"'",
"+",
"id",
"+",
"'\" disconnected'",
")",
";",
"server",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"}",
"}",
"else",
"{",
"server",
".",
"emit",
"(",
"'warn'",
",",
"new",
"Error",
"(",
"'Unable to send message. Client \"'",
"+",
"id",
"+",
"'\" unknown'",
")",
")",
";",
"}",
"}"
] | Re-wraps incoming 'send' message into a 'message' message to the specified destination
@param id | [
"Re",
"-",
"wraps",
"incoming",
"send",
"message",
"into",
"a",
"message",
"message",
"to",
"the",
"specified",
"destination"
] | b42daba04d3e4fc33ba278244bcb81a72cdc2ce5 | https://github.com/maxleiko/wsmsgbroker/blob/b42daba04d3e4fc33ba278244bcb81a72cdc2ce5/lib/actions/server/send.js#L18-L37 |
55,162 | shinuza/captain-core | lib/db.js | load | function load(filename) {
return function(cb) {
var file = path.join(process.cwd(), filename)
, json = require(file)
, model = exports[json.table]
, rows = json.rows;
console.log('Loading', file);
run();
function run() {
var row = rows.shift();
if(row !== undefined) {
model.create(row, function(err) {
if(err) {
cb(err);
} else {
run();
}
});
} else {
cb();
}
}
};
} | javascript | function load(filename) {
return function(cb) {
var file = path.join(process.cwd(), filename)
, json = require(file)
, model = exports[json.table]
, rows = json.rows;
console.log('Loading', file);
run();
function run() {
var row = rows.shift();
if(row !== undefined) {
model.create(row, function(err) {
if(err) {
cb(err);
} else {
run();
}
});
} else {
cb();
}
}
};
} | [
"function",
"load",
"(",
"filename",
")",
"{",
"return",
"function",
"(",
"cb",
")",
"{",
"var",
"file",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"filename",
")",
",",
"json",
"=",
"require",
"(",
"file",
")",
",",
"model",
"=",
"exports",
"[",
"json",
".",
"table",
"]",
",",
"rows",
"=",
"json",
".",
"rows",
";",
"console",
".",
"log",
"(",
"'Loading'",
",",
"file",
")",
";",
"run",
"(",
")",
";",
"function",
"run",
"(",
")",
"{",
"var",
"row",
"=",
"rows",
".",
"shift",
"(",
")",
";",
"if",
"(",
"row",
"!==",
"undefined",
")",
"{",
"model",
".",
"create",
"(",
"row",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"else",
"{",
"run",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}",
"}",
";",
"}"
] | Loads `filename` in the database
@param {String} filename | [
"Loads",
"filename",
"in",
"the",
"database"
] | 02f3a404cdfca608e8726bbacc33e32fec484b21 | https://github.com/shinuza/captain-core/blob/02f3a404cdfca608e8726bbacc33e32fec484b21/lib/db.js#L86-L112 |
55,163 | shinuza/captain-core | lib/db.js | connect | function connect(uri, cb) {
pg.connect(uri, function(err, client, done) {
// Backwards compatibility with pg
if(typeof done === 'undefined') { done = noop; }
if(err) {
cb(err, null, done);
} else {
cb(null, client, done);
}
});
} | javascript | function connect(uri, cb) {
pg.connect(uri, function(err, client, done) {
// Backwards compatibility with pg
if(typeof done === 'undefined') { done = noop; }
if(err) {
cb(err, null, done);
} else {
cb(null, client, done);
}
});
} | [
"function",
"connect",
"(",
"uri",
",",
"cb",
")",
"{",
"pg",
".",
"connect",
"(",
"uri",
",",
"function",
"(",
"err",
",",
"client",
",",
"done",
")",
"{",
"// Backwards compatibility with pg",
"if",
"(",
"typeof",
"done",
"===",
"'undefined'",
")",
"{",
"done",
"=",
"noop",
";",
"}",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
",",
"null",
",",
"done",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"null",
",",
"client",
",",
"done",
")",
";",
"}",
"}",
")",
";",
"}"
] | Connects to database at `uri`
@param {String} uri
@param {Function} cb | [
"Connects",
"to",
"database",
"at",
"uri"
] | 02f3a404cdfca608e8726bbacc33e32fec484b21 | https://github.com/shinuza/captain-core/blob/02f3a404cdfca608e8726bbacc33e32fec484b21/lib/db.js#L122-L132 |
55,164 | shinuza/captain-core | lib/db.js | getClient | function getClient(uri, cb) {
if(typeof uri === 'function') {
cb = uri;
uri = conf.db;
}
connect(uri, function(err, client, done) {
if(err) {
cb(err, null, done);
} else {
cb(null, client, done);
}
});
} | javascript | function getClient(uri, cb) {
if(typeof uri === 'function') {
cb = uri;
uri = conf.db;
}
connect(uri, function(err, client, done) {
if(err) {
cb(err, null, done);
} else {
cb(null, client, done);
}
});
} | [
"function",
"getClient",
"(",
"uri",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"uri",
"===",
"'function'",
")",
"{",
"cb",
"=",
"uri",
";",
"uri",
"=",
"conf",
".",
"db",
";",
"}",
"connect",
"(",
"uri",
",",
"function",
"(",
"err",
",",
"client",
",",
"done",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
",",
"null",
",",
"done",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"null",
",",
"client",
",",
"done",
")",
";",
"}",
"}",
")",
";",
"}"
] | Returns a pg client, you can either specify a connection uri
or let the function use `conf.db`
### Example:
```js
getClient('tcp://[email protected]', function(err, client, done) {});
```
```js
getClient(function(err, client, done) {});
```
@param {*} uri
@param {Function} cb | [
"Returns",
"a",
"pg",
"client",
"you",
"can",
"either",
"specify",
"a",
"connection",
"uri",
"or",
"let",
"the",
"function",
"use",
"conf",
".",
"db"
] | 02f3a404cdfca608e8726bbacc33e32fec484b21 | https://github.com/shinuza/captain-core/blob/02f3a404cdfca608e8726bbacc33e32fec484b21/lib/db.js#L153-L165 |
55,165 | jantimon/ng-directive-parser | lib/esprima-helpers.js | getFirstReturnStatement | function getFirstReturnStatement(node) {
if (!node || !node.body) {
return;
}
if (node.body.type === 'BlockStatement') {
node = node.body;
}
for (var i = 0; i < node.body.length; i++) {
if (node.body[i].type === 'ReturnStatement') {
return node.body[i];
}
}
} | javascript | function getFirstReturnStatement(node) {
if (!node || !node.body) {
return;
}
if (node.body.type === 'BlockStatement') {
node = node.body;
}
for (var i = 0; i < node.body.length; i++) {
if (node.body[i].type === 'ReturnStatement') {
return node.body[i];
}
}
} | [
"function",
"getFirstReturnStatement",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"node",
"||",
"!",
"node",
".",
"body",
")",
"{",
"return",
";",
"}",
"if",
"(",
"node",
".",
"body",
".",
"type",
"===",
"'BlockStatement'",
")",
"{",
"node",
"=",
"node",
".",
"body",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"node",
".",
"body",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"node",
".",
"body",
"[",
"i",
"]",
".",
"type",
"===",
"'ReturnStatement'",
")",
"{",
"return",
"node",
".",
"body",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] | Pareses a FunctionExpression or BlockStatement and returns the first ReturnStatement
@param node
@returns {*} | [
"Pareses",
"a",
"FunctionExpression",
"or",
"BlockStatement",
"and",
"returns",
"the",
"first",
"ReturnStatement"
] | e7bb3b800243be7399d8af3ab2546dd3f159beda | https://github.com/jantimon/ng-directive-parser/blob/e7bb3b800243be7399d8af3ab2546dd3f159beda/lib/esprima-helpers.js#L28-L40 |
55,166 | hashkitty/ckwallet-core | providers/database/sql-client.js | get | function get(tableName, fieldNames, where, orderBy) {
if (orderBy && !checkOrderBy(orderBy)) {
throw new Error('Invalid arg: orderBy');
}
if (!db) {
throw new Error('Not connected');
}
let sql = `SELECT ${fieldNames.join(',')} FROM ${tableName}`;
if (where) {
sql += ` WHERE ${where}`;
}
if (orderBy) {
sql += ` ORDER BY ${orderBy.join(',')}`;
}
return new Promise(((resolve, reject) => {
db.get(sql, [], (error, row) => {
if (error) {
reject(error);
} else {
resolve(row);
}
});
}));
} | javascript | function get(tableName, fieldNames, where, orderBy) {
if (orderBy && !checkOrderBy(orderBy)) {
throw new Error('Invalid arg: orderBy');
}
if (!db) {
throw new Error('Not connected');
}
let sql = `SELECT ${fieldNames.join(',')} FROM ${tableName}`;
if (where) {
sql += ` WHERE ${where}`;
}
if (orderBy) {
sql += ` ORDER BY ${orderBy.join(',')}`;
}
return new Promise(((resolve, reject) => {
db.get(sql, [], (error, row) => {
if (error) {
reject(error);
} else {
resolve(row);
}
});
}));
} | [
"function",
"get",
"(",
"tableName",
",",
"fieldNames",
",",
"where",
",",
"orderBy",
")",
"{",
"if",
"(",
"orderBy",
"&&",
"!",
"checkOrderBy",
"(",
"orderBy",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid arg: orderBy'",
")",
";",
"}",
"if",
"(",
"!",
"db",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Not connected'",
")",
";",
"}",
"let",
"sql",
"=",
"`",
"${",
"fieldNames",
".",
"join",
"(",
"','",
")",
"}",
"${",
"tableName",
"}",
"`",
";",
"if",
"(",
"where",
")",
"{",
"sql",
"+=",
"`",
"${",
"where",
"}",
"`",
";",
"}",
"if",
"(",
"orderBy",
")",
"{",
"sql",
"+=",
"`",
"${",
"orderBy",
".",
"join",
"(",
"','",
")",
"}",
"`",
";",
"}",
"return",
"new",
"Promise",
"(",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"db",
".",
"get",
"(",
"sql",
",",
"[",
"]",
",",
"(",
"error",
",",
"row",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"row",
")",
";",
"}",
"}",
")",
";",
"}",
")",
")",
";",
"}"
] | return single row | [
"return",
"single",
"row"
] | 968d38f0e7fc443f4009f1efce54a84ef8cd1fc9 | https://github.com/hashkitty/ckwallet-core/blob/968d38f0e7fc443f4009f1efce54a84ef8cd1fc9/providers/database/sql-client.js#L72-L95 |
55,167 | hashkitty/ckwallet-core | providers/database/sql-client.js | all | function all(tableName, fieldNames, where, orderBy, limit = null, join = null) {
if (orderBy && !checkOrderBy(orderBy)) {
throw new Error('Invalid arg: orderBy');
}
if (!db) {
throw new Error('Not connected');
}
let sql = `SELECT ${fieldNames.join(',')} FROM ${tableName}`;
if (join) {
sql += ` JOIN ${join}`;
}
if (where) {
sql += ` WHERE ${where}`;
}
if (orderBy) {
sql += ` ORDER BY ${orderBy.join(',')}`;
}
if (limit) {
sql += ` LIMIT ${limit}`;
}
return new Promise(((resolve, reject) => {
db.all(sql, [], (error, rows) => {
if (error) {
reject(error);
} else {
resolve(rows);
}
});
}));
} | javascript | function all(tableName, fieldNames, where, orderBy, limit = null, join = null) {
if (orderBy && !checkOrderBy(orderBy)) {
throw new Error('Invalid arg: orderBy');
}
if (!db) {
throw new Error('Not connected');
}
let sql = `SELECT ${fieldNames.join(',')} FROM ${tableName}`;
if (join) {
sql += ` JOIN ${join}`;
}
if (where) {
sql += ` WHERE ${where}`;
}
if (orderBy) {
sql += ` ORDER BY ${orderBy.join(',')}`;
}
if (limit) {
sql += ` LIMIT ${limit}`;
}
return new Promise(((resolve, reject) => {
db.all(sql, [], (error, rows) => {
if (error) {
reject(error);
} else {
resolve(rows);
}
});
}));
} | [
"function",
"all",
"(",
"tableName",
",",
"fieldNames",
",",
"where",
",",
"orderBy",
",",
"limit",
"=",
"null",
",",
"join",
"=",
"null",
")",
"{",
"if",
"(",
"orderBy",
"&&",
"!",
"checkOrderBy",
"(",
"orderBy",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid arg: orderBy'",
")",
";",
"}",
"if",
"(",
"!",
"db",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Not connected'",
")",
";",
"}",
"let",
"sql",
"=",
"`",
"${",
"fieldNames",
".",
"join",
"(",
"','",
")",
"}",
"${",
"tableName",
"}",
"`",
";",
"if",
"(",
"join",
")",
"{",
"sql",
"+=",
"`",
"${",
"join",
"}",
"`",
";",
"}",
"if",
"(",
"where",
")",
"{",
"sql",
"+=",
"`",
"${",
"where",
"}",
"`",
";",
"}",
"if",
"(",
"orderBy",
")",
"{",
"sql",
"+=",
"`",
"${",
"orderBy",
".",
"join",
"(",
"','",
")",
"}",
"`",
";",
"}",
"if",
"(",
"limit",
")",
"{",
"sql",
"+=",
"`",
"${",
"limit",
"}",
"`",
";",
"}",
"return",
"new",
"Promise",
"(",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"db",
".",
"all",
"(",
"sql",
",",
"[",
"]",
",",
"(",
"error",
",",
"rows",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"rows",
")",
";",
"}",
"}",
")",
";",
"}",
")",
")",
";",
"}"
] | return all rows | [
"return",
"all",
"rows"
] | 968d38f0e7fc443f4009f1efce54a84ef8cd1fc9 | https://github.com/hashkitty/ckwallet-core/blob/968d38f0e7fc443f4009f1efce54a84ef8cd1fc9/providers/database/sql-client.js#L98-L128 |
55,168 | gavinhungry/rudiment | rudiment.js | function(db) {
if (!db.type) {
return defaultDbType;
}
return dbTypes.find(function(dbType) {
return dbType.name === db.type;
}) || null;
} | javascript | function(db) {
if (!db.type) {
return defaultDbType;
}
return dbTypes.find(function(dbType) {
return dbType.name === db.type;
}) || null;
} | [
"function",
"(",
"db",
")",
"{",
"if",
"(",
"!",
"db",
".",
"type",
")",
"{",
"return",
"defaultDbType",
";",
"}",
"return",
"dbTypes",
".",
"find",
"(",
"function",
"(",
"dbType",
")",
"{",
"return",
"dbType",
".",
"name",
"===",
"db",
".",
"type",
";",
"}",
")",
"||",
"null",
";",
"}"
] | Given a database object, get the database type
@param {Object} db - database object passed to Rudiment constructor
@return {Object|null} object from dbTypes | [
"Given",
"a",
"database",
"object",
"get",
"the",
"database",
"type"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L28-L36 |
|
55,169 | gavinhungry/rudiment | rudiment.js | function(obj, keys) {
return keys.reduce(function(memo, key) {
if (obj[key] !== undefined) {
memo[key] = obj[key];
}
return memo;
}, {});
} | javascript | function(obj, keys) {
return keys.reduce(function(memo, key) {
if (obj[key] !== undefined) {
memo[key] = obj[key];
}
return memo;
}, {});
} | [
"function",
"(",
"obj",
",",
"keys",
")",
"{",
"return",
"keys",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"key",
")",
"{",
"if",
"(",
"obj",
"[",
"key",
"]",
"!==",
"undefined",
")",
"{",
"memo",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"return",
"memo",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Return a copy of an object with only the picked keys
@param {Object} obj
@param {Array} keys
@return {Object} | [
"Return",
"a",
"copy",
"of",
"an",
"object",
"with",
"only",
"the",
"picked",
"keys"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L45-L53 |
|
55,170 | gavinhungry/rudiment | rudiment.js | function(doc) {
if (!this._props) {
return doc;
}
return this._props.reduce(function(obj, prop) {
if (doc.hasOwnProperty(prop)) {
obj[prop] = doc[prop];
}
return obj;
}, {});
} | javascript | function(doc) {
if (!this._props) {
return doc;
}
return this._props.reduce(function(obj, prop) {
if (doc.hasOwnProperty(prop)) {
obj[prop] = doc[prop];
}
return obj;
}, {});
} | [
"function",
"(",
"doc",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_props",
")",
"{",
"return",
"doc",
";",
"}",
"return",
"this",
".",
"_props",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"prop",
")",
"{",
"if",
"(",
"doc",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"obj",
"[",
"prop",
"]",
"=",
"doc",
"[",
"prop",
"]",
";",
"}",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Remove extraneous properties from a proposed document
@param {Object} doc - a document to clean
@return {Object} a copy of the cleaned document | [
"Remove",
"extraneous",
"properties",
"from",
"a",
"proposed",
"document"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L177-L189 |
|
55,171 | gavinhungry/rudiment | rudiment.js | function(doc) {
if (!this.isValid(doc)) {
return Promise.resolve(false);
}
var props = pick(doc, this._uniq);
if (!Object.keys(props).length) {
return Promise.resolve(true);
}
return this._dbApi.isAdmissible(doc, props);
} | javascript | function(doc) {
if (!this.isValid(doc)) {
return Promise.resolve(false);
}
var props = pick(doc, this._uniq);
if (!Object.keys(props).length) {
return Promise.resolve(true);
}
return this._dbApi.isAdmissible(doc, props);
} | [
"function",
"(",
"doc",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isValid",
"(",
"doc",
")",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"false",
")",
";",
"}",
"var",
"props",
"=",
"pick",
"(",
"doc",
",",
"this",
".",
"_uniq",
")",
";",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"props",
")",
".",
"length",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"true",
")",
";",
"}",
"return",
"this",
".",
"_dbApi",
".",
"isAdmissible",
"(",
"doc",
",",
"props",
")",
";",
"}"
] | Check if a proposed document is admissible into the database
A document is admissible if it passes the valid predicate, and no other
document in the database is already using its unique keys.
@param {Object} doc - a document to test
@return {Promise} | [
"Check",
"if",
"a",
"proposed",
"document",
"is",
"admissible",
"into",
"the",
"database"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L215-L226 |
|
55,172 | gavinhungry/rudiment | rudiment.js | function(doc) {
var that = this;
doc = that._in_map(doc);
return this._init.then(function() {
return that.isAdmissible(doc);
}).then(function(admissible) {
if (!admissible) {
throw new Error('Document not admissible');
}
doc = that.clean(doc);
if (that._index) {
delete doc[that._index];
}
return that.getNextIndex();
}).then(function(max) {
if (that._index && typeof max === 'number') {
doc[that._index] = max;
}
return that._dbApi.create(doc).then(function(doc) {
if (!doc) {
throw new Error('Document not created');
}
return doc;
});
});
} | javascript | function(doc) {
var that = this;
doc = that._in_map(doc);
return this._init.then(function() {
return that.isAdmissible(doc);
}).then(function(admissible) {
if (!admissible) {
throw new Error('Document not admissible');
}
doc = that.clean(doc);
if (that._index) {
delete doc[that._index];
}
return that.getNextIndex();
}).then(function(max) {
if (that._index && typeof max === 'number') {
doc[that._index] = max;
}
return that._dbApi.create(doc).then(function(doc) {
if (!doc) {
throw new Error('Document not created');
}
return doc;
});
});
} | [
"function",
"(",
"doc",
")",
"{",
"var",
"that",
"=",
"this",
";",
"doc",
"=",
"that",
".",
"_in_map",
"(",
"doc",
")",
";",
"return",
"this",
".",
"_init",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"that",
".",
"isAdmissible",
"(",
"doc",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"admissible",
")",
"{",
"if",
"(",
"!",
"admissible",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Document not admissible'",
")",
";",
"}",
"doc",
"=",
"that",
".",
"clean",
"(",
"doc",
")",
";",
"if",
"(",
"that",
".",
"_index",
")",
"{",
"delete",
"doc",
"[",
"that",
".",
"_index",
"]",
";",
"}",
"return",
"that",
".",
"getNextIndex",
"(",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"max",
")",
"{",
"if",
"(",
"that",
".",
"_index",
"&&",
"typeof",
"max",
"===",
"'number'",
")",
"{",
"doc",
"[",
"that",
".",
"_index",
"]",
"=",
"max",
";",
"}",
"return",
"that",
".",
"_dbApi",
".",
"create",
"(",
"doc",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"if",
"(",
"!",
"doc",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Document not created'",
")",
";",
"}",
"return",
"doc",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Create and insert a new document into the database
@param {Object} doc - a document to insert
@return {Promise} | [
"Create",
"and",
"insert",
"a",
"new",
"document",
"into",
"the",
"database"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L234-L265 |
|
55,173 | gavinhungry/rudiment | rudiment.js | function(props) {
var that = this;
return this._dbApi.find(props || {}).then(function(docs) {
return docs.map(that._out_map);
});
} | javascript | function(props) {
var that = this;
return this._dbApi.find(props || {}).then(function(docs) {
return docs.map(that._out_map);
});
} | [
"function",
"(",
"props",
")",
"{",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"_dbApi",
".",
"find",
"(",
"props",
"||",
"{",
"}",
")",
".",
"then",
"(",
"function",
"(",
"docs",
")",
"{",
"return",
"docs",
".",
"map",
"(",
"that",
".",
"_out_map",
")",
";",
"}",
")",
";",
"}"
] | Get all documents from the database with matching properties
@param {Object} props
@return {Promise} -> {Array} | [
"Get",
"all",
"documents",
"from",
"the",
"database",
"with",
"matching",
"properties"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L273-L279 |
|
55,174 | gavinhungry/rudiment | rudiment.js | function(id) {
var that = this;
return this._dbApi.read(id).then(function(doc) {
return that._readDoc(doc);
});
} | javascript | function(id) {
var that = this;
return this._dbApi.read(id).then(function(doc) {
return that._readDoc(doc);
});
} | [
"function",
"(",
"id",
")",
"{",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"_dbApi",
".",
"read",
"(",
"id",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"_readDoc",
"(",
"doc",
")",
";",
"}",
")",
";",
"}"
] | Get a document from the database by database ID
@param {String} id
@return {Promise} | [
"Get",
"a",
"document",
"from",
"the",
"database",
"by",
"database",
"ID"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L295-L301 |
|
55,175 | gavinhungry/rudiment | rudiment.js | function(key) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
var props = {};
props[this._key] = key;
return this._dbApi.find(props).then(function(docs) {
return that._readDoc(docs[0]);
});
} | javascript | function(key) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
var props = {};
props[this._key] = key;
return this._dbApi.find(props).then(function(docs) {
return that._readDoc(docs[0]);
});
} | [
"function",
"(",
"key",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_key",
"||",
"!",
"key",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'No unique key specified'",
")",
")",
";",
"}",
"var",
"props",
"=",
"{",
"}",
";",
"props",
"[",
"this",
".",
"_key",
"]",
"=",
"key",
";",
"return",
"this",
".",
"_dbApi",
".",
"find",
"(",
"props",
")",
".",
"then",
"(",
"function",
"(",
"docs",
")",
"{",
"return",
"that",
".",
"_readDoc",
"(",
"docs",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"}"
] | Get a document from the database by key
@param {String} key
@return {Promise} | [
"Get",
"a",
"document",
"from",
"the",
"database",
"by",
"key"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L309-L322 |
|
55,176 | gavinhungry/rudiment | rudiment.js | function(index) {
var that = this;
var props = this._propIndex(index);
if (!props) {
return Promise.reject(new Error('No auto-indexing key specified'));
}
return this._dbApi.find(props).then(function(docs) {
return that._readDoc(docs[0]);
});
} | javascript | function(index) {
var that = this;
var props = this._propIndex(index);
if (!props) {
return Promise.reject(new Error('No auto-indexing key specified'));
}
return this._dbApi.find(props).then(function(docs) {
return that._readDoc(docs[0]);
});
} | [
"function",
"(",
"index",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"props",
"=",
"this",
".",
"_propIndex",
"(",
"index",
")",
";",
"if",
"(",
"!",
"props",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'No auto-indexing key specified'",
")",
")",
";",
"}",
"return",
"this",
".",
"_dbApi",
".",
"find",
"(",
"props",
")",
".",
"then",
"(",
"function",
"(",
"docs",
")",
"{",
"return",
"that",
".",
"_readDoc",
"(",
"docs",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"}"
] | Get a document from the database by auto-index
@param {Number|String} index
@return {Promise} | [
"Get",
"a",
"document",
"from",
"the",
"database",
"by",
"auto",
"-",
"index"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L349-L360 |
|
55,177 | gavinhungry/rudiment | rudiment.js | function(doc, updates) {
updates = this._in_map(updates || {});
Object.keys(doc).forEach(function(prop) {
if (updates.hasOwnProperty(prop)) {
doc[prop] = updates[prop];
}
});
if (!this.isValid(doc)) {
throw new Error('Updated document is invalid');
}
var id = doc[this._dbType.id];
this._uniq.forEach(function(uniq) {
delete doc[uniq];
});
doc = this.clean(doc);
return this._dbApi.update(id, doc);
} | javascript | function(doc, updates) {
updates = this._in_map(updates || {});
Object.keys(doc).forEach(function(prop) {
if (updates.hasOwnProperty(prop)) {
doc[prop] = updates[prop];
}
});
if (!this.isValid(doc)) {
throw new Error('Updated document is invalid');
}
var id = doc[this._dbType.id];
this._uniq.forEach(function(uniq) {
delete doc[uniq];
});
doc = this.clean(doc);
return this._dbApi.update(id, doc);
} | [
"function",
"(",
"doc",
",",
"updates",
")",
"{",
"updates",
"=",
"this",
".",
"_in_map",
"(",
"updates",
"||",
"{",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"doc",
")",
".",
"forEach",
"(",
"function",
"(",
"prop",
")",
"{",
"if",
"(",
"updates",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"doc",
"[",
"prop",
"]",
"=",
"updates",
"[",
"prop",
"]",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"this",
".",
"isValid",
"(",
"doc",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Updated document is invalid'",
")",
";",
"}",
"var",
"id",
"=",
"doc",
"[",
"this",
".",
"_dbType",
".",
"id",
"]",
";",
"this",
".",
"_uniq",
".",
"forEach",
"(",
"function",
"(",
"uniq",
")",
"{",
"delete",
"doc",
"[",
"uniq",
"]",
";",
"}",
")",
";",
"doc",
"=",
"this",
".",
"clean",
"(",
"doc",
")",
";",
"return",
"this",
".",
"_dbApi",
".",
"update",
"(",
"id",
",",
"doc",
")",
";",
"}"
] | Update an existing database document
The unique values of a document cannot be updated with this method.
Delete the document and create a new document instead.
@private
@param {Document} doc
@param {Object} updates - updates to apply to document
@return {Promise} | [
"Update",
"an",
"existing",
"database",
"document"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L383-L404 |
|
55,178 | gavinhungry/rudiment | rudiment.js | function(id, updates) {
var that = this;
return this.read(id).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | javascript | function(id, updates) {
var that = this;
return this.read(id).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | [
"function",
"(",
"id",
",",
"updates",
")",
"{",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"read",
"(",
"id",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"_updateDoc",
"(",
"doc",
",",
"updates",
")",
";",
"}",
")",
";",
"}"
] | Update a document in the database by database ID
@param {String} id
@param {Object} updates - updates to apply to document
@return {Promise} | [
"Update",
"a",
"document",
"in",
"the",
"database",
"by",
"database",
"ID"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L413-L419 |
|
55,179 | gavinhungry/rudiment | rudiment.js | function(key, updates) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
return this.readByKey(key).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | javascript | function(key, updates) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
return this.readByKey(key).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | [
"function",
"(",
"key",
",",
"updates",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_key",
"||",
"!",
"key",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'No unique key specified'",
")",
")",
";",
"}",
"return",
"this",
".",
"readByKey",
"(",
"key",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"_updateDoc",
"(",
"doc",
",",
"updates",
")",
";",
"}",
")",
";",
"}"
] | Update a document in the database by key
@param {String} key
@param {Object} updates - updates to apply to document
@return {Promise} | [
"Update",
"a",
"document",
"in",
"the",
"database",
"by",
"key"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L428-L438 |
|
55,180 | gavinhungry/rudiment | rudiment.js | function(index, updates) {
var that = this;
return this.readByIndex(index).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | javascript | function(index, updates) {
var that = this;
return this.readByIndex(index).then(function(doc) {
return that._updateDoc(doc, updates);
});
} | [
"function",
"(",
"index",
",",
"updates",
")",
"{",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"readByIndex",
"(",
"index",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"_updateDoc",
"(",
"doc",
",",
"updates",
")",
";",
"}",
")",
";",
"}"
] | Update a document in the database by auto-index
@param {Number|String} index
@param {Object} updates - updates to apply to document
@return {Promise} | [
"Update",
"a",
"document",
"in",
"the",
"database",
"by",
"auto",
"-",
"index"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L447-L453 |
|
55,181 | gavinhungry/rudiment | rudiment.js | function(key) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
return this.readByKey(key).then(function(doc) {
return that.delete(doc[that._dbType.id]);
});
} | javascript | function(key) {
var that = this;
if (!this._key || !key) {
return Promise.reject(new Error('No unique key specified'));
}
return this.readByKey(key).then(function(doc) {
return that.delete(doc[that._dbType.id]);
});
} | [
"function",
"(",
"key",
")",
"{",
"var",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_key",
"||",
"!",
"key",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'No unique key specified'",
")",
")",
";",
"}",
"return",
"this",
".",
"readByKey",
"(",
"key",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"delete",
"(",
"doc",
"[",
"that",
".",
"_dbType",
".",
"id",
"]",
")",
";",
"}",
")",
";",
"}"
] | Delete a document from the database by key
@param {String} key
@return {Promise} | [
"Delete",
"a",
"document",
"from",
"the",
"database",
"by",
"key"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L475-L485 |
|
55,182 | gavinhungry/rudiment | rudiment.js | function(index) {
var that = this;
return this.readByIndex(index).then(function(doc) {
return that.delete(doc[that._dbType.id]);
});
} | javascript | function(index) {
var that = this;
return this.readByIndex(index).then(function(doc) {
return that.delete(doc[that._dbType.id]);
});
} | [
"function",
"(",
"index",
")",
"{",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"readByIndex",
"(",
"index",
")",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"return",
"that",
".",
"delete",
"(",
"doc",
"[",
"that",
".",
"_dbType",
".",
"id",
"]",
")",
";",
"}",
")",
";",
"}"
] | Delete a document from the database by auto-index
@param {Number|String} index
@return {Promise} | [
"Delete",
"a",
"document",
"from",
"the",
"database",
"by",
"auto",
"-",
"index"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L493-L499 |
|
55,183 | gavinhungry/rudiment | rudiment.js | function(operation, res) {
var that = this;
var method = res.req.method;
return operation.then(function(doc) {
if (method === 'POST') {
if (that._path && (that._key || that._index)) {
res.header('Location', '/' + that._path + '/' + doc[that._key || that._index]);
}
return res.status(201).json(doc);
}
return res.status(200).json(doc);
}, function(err) {
console.error(err.message);
if (method === 'POST' || method === 'PUT') {
return res.status(409).end();
}
if (method === 'GET') {
res.status(404).end();
}
return res.status(500).end();
});
} | javascript | function(operation, res) {
var that = this;
var method = res.req.method;
return operation.then(function(doc) {
if (method === 'POST') {
if (that._path && (that._key || that._index)) {
res.header('Location', '/' + that._path + '/' + doc[that._key || that._index]);
}
return res.status(201).json(doc);
}
return res.status(200).json(doc);
}, function(err) {
console.error(err.message);
if (method === 'POST' || method === 'PUT') {
return res.status(409).end();
}
if (method === 'GET') {
res.status(404).end();
}
return res.status(500).end();
});
} | [
"function",
"(",
"operation",
",",
"res",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"method",
"=",
"res",
".",
"req",
".",
"method",
";",
"return",
"operation",
".",
"then",
"(",
"function",
"(",
"doc",
")",
"{",
"if",
"(",
"method",
"===",
"'POST'",
")",
"{",
"if",
"(",
"that",
".",
"_path",
"&&",
"(",
"that",
".",
"_key",
"||",
"that",
".",
"_index",
")",
")",
"{",
"res",
".",
"header",
"(",
"'Location'",
",",
"'/'",
"+",
"that",
".",
"_path",
"+",
"'/'",
"+",
"doc",
"[",
"that",
".",
"_key",
"||",
"that",
".",
"_index",
"]",
")",
";",
"}",
"return",
"res",
".",
"status",
"(",
"201",
")",
".",
"json",
"(",
"doc",
")",
";",
"}",
"return",
"res",
".",
"status",
"(",
"200",
")",
".",
"json",
"(",
"doc",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"if",
"(",
"method",
"===",
"'POST'",
"||",
"method",
"===",
"'PUT'",
")",
"{",
"return",
"res",
".",
"status",
"(",
"409",
")",
".",
"end",
"(",
")",
";",
"}",
"if",
"(",
"method",
"===",
"'GET'",
")",
"{",
"res",
".",
"status",
"(",
"404",
")",
".",
"end",
"(",
")",
";",
"}",
"return",
"res",
".",
"status",
"(",
"500",
")",
".",
"end",
"(",
")",
";",
"}",
")",
";",
"}"
] | Middleware REST handler for CRUD operations
@param {Promise} operation
@param {ServerResponse} res | [
"Middleware",
"REST",
"handler",
"for",
"CRUD",
"operations"
] | b4e77deb794d11bcae5598736905bb630ee65329 | https://github.com/gavinhungry/rudiment/blob/b4e77deb794d11bcae5598736905bb630ee65329/rudiment.js#L507-L534 |
|
55,184 | thirdcoder/trit-getset | getset.js | get_trit | function get_trit(n,i) {
// convert entire number to balanced ternary string then slice
// would be nice to extract without converting everything, see extract_digit(), which
// works for unbalanced ternary, but balanced converts 2 -> 1i, so individual digit extraction
// is more difficult -- see https://en.wikipedia.org/wiki/Balanced_ternary#Conversion_from_ternary
var s = n2bts(n);
return ~~BT_DIGIT_TO_N[s.charAt(s.length - i - 1)];
} | javascript | function get_trit(n,i) {
// convert entire number to balanced ternary string then slice
// would be nice to extract without converting everything, see extract_digit(), which
// works for unbalanced ternary, but balanced converts 2 -> 1i, so individual digit extraction
// is more difficult -- see https://en.wikipedia.org/wiki/Balanced_ternary#Conversion_from_ternary
var s = n2bts(n);
return ~~BT_DIGIT_TO_N[s.charAt(s.length - i - 1)];
} | [
"function",
"get_trit",
"(",
"n",
",",
"i",
")",
"{",
"// convert entire number to balanced ternary string then slice",
"// would be nice to extract without converting everything, see extract_digit(), which",
"// works for unbalanced ternary, but balanced converts 2 -> 1i, so individual digit extraction",
"// is more difficult -- see https://en.wikipedia.org/wiki/Balanced_ternary#Conversion_from_ternary",
"var",
"s",
"=",
"n2bts",
"(",
"n",
")",
";",
"return",
"~",
"~",
"BT_DIGIT_TO_N",
"[",
"s",
".",
"charAt",
"(",
"s",
".",
"length",
"-",
"i",
"-",
"1",
")",
"]",
";",
"}"
] | get trit value at ith index of n, i of 0=least significant | [
"get",
"trit",
"value",
"at",
"ith",
"index",
"of",
"n",
"i",
"of",
"0",
"=",
"least",
"significant"
] | bb80f19e943cf2ee7f8a0039f780e06100db6600 | https://github.com/thirdcoder/trit-getset/blob/bb80f19e943cf2ee7f8a0039f780e06100db6600/getset.js#L9-L16 |
55,185 | nodys/htmly | lib/processor.js | resolveFunctionList | function resolveFunctionList (functionList, basedir) {
if (!functionList) return []
return (Array.isArray(functionList) ? functionList : [functionList])
.map(function (proc) {
if (typeof (proc) === 'string') {
proc = require(resolve.sync(proc, { basedir: basedir }))
}
return toAsync(proc)
})
} | javascript | function resolveFunctionList (functionList, basedir) {
if (!functionList) return []
return (Array.isArray(functionList) ? functionList : [functionList])
.map(function (proc) {
if (typeof (proc) === 'string') {
proc = require(resolve.sync(proc, { basedir: basedir }))
}
return toAsync(proc)
})
} | [
"function",
"resolveFunctionList",
"(",
"functionList",
",",
"basedir",
")",
"{",
"if",
"(",
"!",
"functionList",
")",
"return",
"[",
"]",
"return",
"(",
"Array",
".",
"isArray",
"(",
"functionList",
")",
"?",
"functionList",
":",
"[",
"functionList",
"]",
")",
".",
"map",
"(",
"function",
"(",
"proc",
")",
"{",
"if",
"(",
"typeof",
"(",
"proc",
")",
"===",
"'string'",
")",
"{",
"proc",
"=",
"require",
"(",
"resolve",
".",
"sync",
"(",
"proc",
",",
"{",
"basedir",
":",
"basedir",
"}",
")",
")",
"}",
"return",
"toAsync",
"(",
"proc",
")",
"}",
")",
"}"
] | Resolve and require a list of module path that exports async function
Each path is resolved against `basedir`. `utils.toAsync()` unsure that
each function will work as async function.
@param {Array|String} functionList
Module path or array of module path
@param {String} basedir
Base path for path resolution (dirname of the package.json)
@return {Array}
An array of htmly asynchronous functions | [
"Resolve",
"and",
"require",
"a",
"list",
"of",
"module",
"path",
"that",
"exports",
"async",
"function"
] | 770560274167b7efd78cf56544ec72f52efb3fb8 | https://github.com/nodys/htmly/blob/770560274167b7efd78cf56544ec72f52efb3fb8/lib/processor.js#L143-L152 |
55,186 | chrisocast/grunt-faker | tasks/faker.js | processJson | function processJson(obj) {
for (var i in obj) {
if (typeof(obj[i]) === "object") {
processJson(obj[i]); // found an obj or array keep digging
} else if (obj[i] !== null){
obj[i] = getFunctionNameAndArgs(obj[i]);// not an obj or array, check contents
}
}
return obj;
} | javascript | function processJson(obj) {
for (var i in obj) {
if (typeof(obj[i]) === "object") {
processJson(obj[i]); // found an obj or array keep digging
} else if (obj[i] !== null){
obj[i] = getFunctionNameAndArgs(obj[i]);// not an obj or array, check contents
}
}
return obj;
} | [
"function",
"processJson",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"obj",
")",
"{",
"if",
"(",
"typeof",
"(",
"obj",
"[",
"i",
"]",
")",
"===",
"\"object\"",
")",
"{",
"processJson",
"(",
"obj",
"[",
"i",
"]",
")",
";",
"// found an obj or array keep digging",
"}",
"else",
"if",
"(",
"obj",
"[",
"i",
"]",
"!==",
"null",
")",
"{",
"obj",
"[",
"i",
"]",
"=",
"getFunctionNameAndArgs",
"(",
"obj",
"[",
"i",
"]",
")",
";",
"// not an obj or array, check contents",
"}",
"}",
"return",
"obj",
";",
"}"
] | Loop through entire json object | [
"Loop",
"through",
"entire",
"json",
"object"
] | 8fa81b0e4839ffba4089cd93e091628e39447e94 | https://github.com/chrisocast/grunt-faker/blob/8fa81b0e4839ffba4089cd93e091628e39447e94/tasks/faker.js#L17-L26 |
55,187 | chrisocast/grunt-faker | tasks/faker.js | getFunctionNameAndArgs | function getFunctionNameAndArgs(value) {
var pattern = /^(.*)\{\{([^()]+?)(\((.+)\))?\}\}(.*)$/g,
match, func, args;
var argArray = [], surroundings = [];
var retValue;
while (match = pattern.exec(value)) {
surroundings[0] = match[1];
func = match[2];
args = match[4];
surroundings[1] = match[5];
}
if (args !== undefined ){
if (args.indexOf("[") !== -1){
// is an array as string
args = JSON.parse(args);
argArray.push(args);
} else {
// one or more string/number params
args = args.replace(/, /gi, ",");
args = args.replace(/'/gi, "", "gi");
argArray = args.split(',');
}
}
// return value if no Faker method is detected
retValue = func ?
executeFunctionByName(func,argArray) :
value;
if(surroundings[0]) { // prefix
retValue = surroundings[0] + retValue;
}
if(surroundings[1]) { // postfix
retValue += surroundings[1];
}
return retValue;
} | javascript | function getFunctionNameAndArgs(value) {
var pattern = /^(.*)\{\{([^()]+?)(\((.+)\))?\}\}(.*)$/g,
match, func, args;
var argArray = [], surroundings = [];
var retValue;
while (match = pattern.exec(value)) {
surroundings[0] = match[1];
func = match[2];
args = match[4];
surroundings[1] = match[5];
}
if (args !== undefined ){
if (args.indexOf("[") !== -1){
// is an array as string
args = JSON.parse(args);
argArray.push(args);
} else {
// one or more string/number params
args = args.replace(/, /gi, ",");
args = args.replace(/'/gi, "", "gi");
argArray = args.split(',');
}
}
// return value if no Faker method is detected
retValue = func ?
executeFunctionByName(func,argArray) :
value;
if(surroundings[0]) { // prefix
retValue = surroundings[0] + retValue;
}
if(surroundings[1]) { // postfix
retValue += surroundings[1];
}
return retValue;
} | [
"function",
"getFunctionNameAndArgs",
"(",
"value",
")",
"{",
"var",
"pattern",
"=",
"/",
"^(.*)\\{\\{([^()]+?)(\\((.+)\\))?\\}\\}(.*)$",
"/",
"g",
",",
"match",
",",
"func",
",",
"args",
";",
"var",
"argArray",
"=",
"[",
"]",
",",
"surroundings",
"=",
"[",
"]",
";",
"var",
"retValue",
";",
"while",
"(",
"match",
"=",
"pattern",
".",
"exec",
"(",
"value",
")",
")",
"{",
"surroundings",
"[",
"0",
"]",
"=",
"match",
"[",
"1",
"]",
";",
"func",
"=",
"match",
"[",
"2",
"]",
";",
"args",
"=",
"match",
"[",
"4",
"]",
";",
"surroundings",
"[",
"1",
"]",
"=",
"match",
"[",
"5",
"]",
";",
"}",
"if",
"(",
"args",
"!==",
"undefined",
")",
"{",
"if",
"(",
"args",
".",
"indexOf",
"(",
"\"[\"",
")",
"!==",
"-",
"1",
")",
"{",
"// is an array as string",
"args",
"=",
"JSON",
".",
"parse",
"(",
"args",
")",
";",
"argArray",
".",
"push",
"(",
"args",
")",
";",
"}",
"else",
"{",
"// one or more string/number params",
"args",
"=",
"args",
".",
"replace",
"(",
"/",
", ",
"/",
"gi",
",",
"\",\"",
")",
";",
"args",
"=",
"args",
".",
"replace",
"(",
"/",
"'",
"/",
"gi",
",",
"\"\"",
",",
"\"gi\"",
")",
";",
"argArray",
"=",
"args",
".",
"split",
"(",
"','",
")",
";",
"}",
"}",
"// return value if no Faker method is detected",
"retValue",
"=",
"func",
"?",
"executeFunctionByName",
"(",
"func",
",",
"argArray",
")",
":",
"value",
";",
"if",
"(",
"surroundings",
"[",
"0",
"]",
")",
"{",
"// prefix",
"retValue",
"=",
"surroundings",
"[",
"0",
"]",
"+",
"retValue",
";",
"}",
"if",
"(",
"surroundings",
"[",
"1",
"]",
")",
"{",
"// postfix",
"retValue",
"+=",
"surroundings",
"[",
"1",
"]",
";",
"}",
"return",
"retValue",
";",
"}"
] | Get func name, extract args, and exec on their values | [
"Get",
"func",
"name",
"extract",
"args",
"and",
"exec",
"on",
"their",
"values"
] | 8fa81b0e4839ffba4089cd93e091628e39447e94 | https://github.com/chrisocast/grunt-faker/blob/8fa81b0e4839ffba4089cd93e091628e39447e94/tasks/faker.js#L29-L68 |
55,188 | chrisocast/grunt-faker | tasks/faker.js | executeFunctionByName | function executeFunctionByName(functionName, args) {
var namespaces = functionName.split(".");
var nsLength = namespaces.length;
var context = Faker;
var parentContext = Faker;
if (namespaces[0].toLowerCase() === 'definitions'){
grunt.log.warn('The definitions module from Faker.js is not avail in this task.');
return;
}
for(var i = 0; i < nsLength; i++) {
context = context[namespaces[i]];
}
for(var j = 0; j < nsLength - 1; j++) {
parentContext = parentContext[namespaces[j]];
}
return context.apply(parentContext, args);
} | javascript | function executeFunctionByName(functionName, args) {
var namespaces = functionName.split(".");
var nsLength = namespaces.length;
var context = Faker;
var parentContext = Faker;
if (namespaces[0].toLowerCase() === 'definitions'){
grunt.log.warn('The definitions module from Faker.js is not avail in this task.');
return;
}
for(var i = 0; i < nsLength; i++) {
context = context[namespaces[i]];
}
for(var j = 0; j < nsLength - 1; j++) {
parentContext = parentContext[namespaces[j]];
}
return context.apply(parentContext, args);
} | [
"function",
"executeFunctionByName",
"(",
"functionName",
",",
"args",
")",
"{",
"var",
"namespaces",
"=",
"functionName",
".",
"split",
"(",
"\".\"",
")",
";",
"var",
"nsLength",
"=",
"namespaces",
".",
"length",
";",
"var",
"context",
"=",
"Faker",
";",
"var",
"parentContext",
"=",
"Faker",
";",
"if",
"(",
"namespaces",
"[",
"0",
"]",
".",
"toLowerCase",
"(",
")",
"===",
"'definitions'",
")",
"{",
"grunt",
".",
"log",
".",
"warn",
"(",
"'The definitions module from Faker.js is not avail in this task.'",
")",
";",
"return",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nsLength",
";",
"i",
"++",
")",
"{",
"context",
"=",
"context",
"[",
"namespaces",
"[",
"i",
"]",
"]",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"nsLength",
"-",
"1",
";",
"j",
"++",
")",
"{",
"parentContext",
"=",
"parentContext",
"[",
"namespaces",
"[",
"j",
"]",
"]",
";",
"}",
"return",
"context",
".",
"apply",
"(",
"parentContext",
",",
"args",
")",
";",
"}"
] | Execute function as string | [
"Execute",
"function",
"as",
"string"
] | 8fa81b0e4839ffba4089cd93e091628e39447e94 | https://github.com/chrisocast/grunt-faker/blob/8fa81b0e4839ffba4089cd93e091628e39447e94/tasks/faker.js#L71-L91 |
55,189 | troygoode/node-tsa | lib/guard.js | function(){
if(errors.length) return cb(errors);
var transform = opts.transform || function(_result, _cb){
_cb(null, _result);
};
transform(result, function(err, _result){
if(err){
errors.push(formatError(err, key));
cb(errors);
}else{
cb(null, _result);
}
});
} | javascript | function(){
if(errors.length) return cb(errors);
var transform = opts.transform || function(_result, _cb){
_cb(null, _result);
};
transform(result, function(err, _result){
if(err){
errors.push(formatError(err, key));
cb(errors);
}else{
cb(null, _result);
}
});
} | [
"function",
"(",
")",
"{",
"if",
"(",
"errors",
".",
"length",
")",
"return",
"cb",
"(",
"errors",
")",
";",
"var",
"transform",
"=",
"opts",
".",
"transform",
"||",
"function",
"(",
"_result",
",",
"_cb",
")",
"{",
"_cb",
"(",
"null",
",",
"_result",
")",
";",
"}",
";",
"transform",
"(",
"result",
",",
"function",
"(",
"err",
",",
"_result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"errors",
".",
"push",
"(",
"formatError",
"(",
"err",
",",
"key",
")",
")",
";",
"cb",
"(",
"errors",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"null",
",",
"_result",
")",
";",
"}",
"}",
")",
";",
"}"
] | setup function to call once all keys have been recursed | [
"setup",
"function",
"to",
"call",
"once",
"all",
"keys",
"have",
"been",
"recursed"
] | a58d40f9b77a248504b96e7704ca6a9a48e0b4ba | https://github.com/troygoode/node-tsa/blob/a58d40f9b77a248504b96e7704ca6a9a48e0b4ba/lib/guard.js#L47-L60 |
|
55,190 | kasargeant/tinter | src/js/Tinter.js | function(text, color=[255,255,255], colorBg=[0,0,0], style="reset") {
// First check for raw RGB truecolor code... if the console scheme
// supports this then no probs... but if not - we need to degrade appropriately.
if(color.constructor === Array && colorBg.constructor === Array) {
if(config.scheme === "16M") {
return this._styleTruecolor(text, color, colorBg, style);
} else {
return this._degrade(text, color, colorBg, style);
}
} else {
throw new Error("Unrecognized or malformed RGB array values.");
}
} | javascript | function(text, color=[255,255,255], colorBg=[0,0,0], style="reset") {
// First check for raw RGB truecolor code... if the console scheme
// supports this then no probs... but if not - we need to degrade appropriately.
if(color.constructor === Array && colorBg.constructor === Array) {
if(config.scheme === "16M") {
return this._styleTruecolor(text, color, colorBg, style);
} else {
return this._degrade(text, color, colorBg, style);
}
} else {
throw new Error("Unrecognized or malformed RGB array values.");
}
} | [
"function",
"(",
"text",
",",
"color",
"=",
"[",
"255",
",",
"255",
",",
"255",
"]",
",",
"colorBg",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
",",
"style",
"=",
"\"reset\"",
")",
"{",
"// First check for raw RGB truecolor code... if the console scheme",
"// supports this then no probs... but if not - we need to degrade appropriately.",
"if",
"(",
"color",
".",
"constructor",
"===",
"Array",
"&&",
"colorBg",
".",
"constructor",
"===",
"Array",
")",
"{",
"if",
"(",
"config",
".",
"scheme",
"===",
"\"16M\"",
")",
"{",
"return",
"this",
".",
"_styleTruecolor",
"(",
"text",
",",
"color",
",",
"colorBg",
",",
"style",
")",
";",
"}",
"else",
"{",
"return",
"this",
".",
"_degrade",
"(",
"text",
",",
"color",
",",
"colorBg",
",",
"style",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Unrecognized or malformed RGB array values.\"",
")",
";",
"}",
"}"
] | Marks the text string with multiple RGB colors and ANSI named style characteristics.
@param {string} text - the text string to be colorized and/or styled.
@param {Array} color - an RGB integer array representing the foreground color.
@param {Array} colorBg - an RGB integer array representing the foreground color.
@param {string} style - the name of the ANSI text style.
@returns {string} - the colorized/styled text string.
@static | [
"Marks",
"the",
"text",
"string",
"with",
"multiple",
"RGB",
"colors",
"and",
"ANSI",
"named",
"style",
"characteristics",
"."
] | a9fbce086558ec9682e104f39324b0a00c52f98c | https://github.com/kasargeant/tinter/blob/a9fbce086558ec9682e104f39324b0a00c52f98c/src/js/Tinter.js#L533-L545 |
|
55,191 | longbill/precise-number | index.js | decimalLength | function decimalLength(n) {
let ns = cleanNumber(n).toString();
let ems = ns.match(/e([\+\-]\d+)$/);
let e = 0;
if (ems && ems[1]) e = parseInt(ems[1]);
ns = ns.replace(/e[\-\+]\d+$/, '');
let parts = ns.split('.', 2);
if (parts.length === 1) return -e;
return parts[1].length - e;
} | javascript | function decimalLength(n) {
let ns = cleanNumber(n).toString();
let ems = ns.match(/e([\+\-]\d+)$/);
let e = 0;
if (ems && ems[1]) e = parseInt(ems[1]);
ns = ns.replace(/e[\-\+]\d+$/, '');
let parts = ns.split('.', 2);
if (parts.length === 1) return -e;
return parts[1].length - e;
} | [
"function",
"decimalLength",
"(",
"n",
")",
"{",
"let",
"ns",
"=",
"cleanNumber",
"(",
"n",
")",
".",
"toString",
"(",
")",
";",
"let",
"ems",
"=",
"ns",
".",
"match",
"(",
"/",
"e([\\+\\-]\\d+)$",
"/",
")",
";",
"let",
"e",
"=",
"0",
";",
"if",
"(",
"ems",
"&&",
"ems",
"[",
"1",
"]",
")",
"e",
"=",
"parseInt",
"(",
"ems",
"[",
"1",
"]",
")",
";",
"ns",
"=",
"ns",
".",
"replace",
"(",
"/",
"e[\\-\\+]\\d+$",
"/",
",",
"''",
")",
";",
"let",
"parts",
"=",
"ns",
".",
"split",
"(",
"'.'",
",",
"2",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"1",
")",
"return",
"-",
"e",
";",
"return",
"parts",
"[",
"1",
"]",
".",
"length",
"-",
"e",
";",
"}"
] | calculate the decimal part length of a number | [
"calculate",
"the",
"decimal",
"part",
"length",
"of",
"a",
"number"
] | 690b08e745af7b6b9f82649a6e7ee06a9ca88588 | https://github.com/longbill/precise-number/blob/690b08e745af7b6b9f82649a6e7ee06a9ca88588/index.js#L167-L176 |
55,192 | meisterplayer/js-dev | gulp/clean.js | createClean | function createClean(inPath) {
if (!inPath) {
throw new Error('Input path argument is required');
}
return function cleanDir() {
return gulp.src(inPath, { read: false }).pipe(clean());
};
} | javascript | function createClean(inPath) {
if (!inPath) {
throw new Error('Input path argument is required');
}
return function cleanDir() {
return gulp.src(inPath, { read: false }).pipe(clean());
};
} | [
"function",
"createClean",
"(",
"inPath",
")",
"{",
"if",
"(",
"!",
"inPath",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Input path argument is required'",
")",
";",
"}",
"return",
"function",
"cleanDir",
"(",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"inPath",
",",
"{",
"read",
":",
"false",
"}",
")",
".",
"pipe",
"(",
"clean",
"(",
")",
")",
";",
"}",
";",
"}"
] | Higher order function to create gulp function that cleans directories.
@param {string|string[]} inPath The globs to the files/directories that need to be removed
@return {function} Function that can be used as a gulp task | [
"Higher",
"order",
"function",
"to",
"create",
"gulp",
"function",
"that",
"cleans",
"directories",
"."
] | c2646678c49dcdaa120ba3f24824da52b0c63e31 | https://github.com/meisterplayer/js-dev/blob/c2646678c49dcdaa120ba3f24824da52b0c63e31/gulp/clean.js#L9-L17 |
55,193 | byu-oit/sans-server-swagger | bin/exception.js | Exception | function Exception(code, message) {
const factory = Object.create(Exception.prototype);
factory.code = code;
factory.message = message;
factory.stack = factory.toString();
return factory;
} | javascript | function Exception(code, message) {
const factory = Object.create(Exception.prototype);
factory.code = code;
factory.message = message;
factory.stack = factory.toString();
return factory;
} | [
"function",
"Exception",
"(",
"code",
",",
"message",
")",
"{",
"const",
"factory",
"=",
"Object",
".",
"create",
"(",
"Exception",
".",
"prototype",
")",
";",
"factory",
".",
"code",
"=",
"code",
";",
"factory",
".",
"message",
"=",
"message",
";",
"factory",
".",
"stack",
"=",
"factory",
".",
"toString",
"(",
")",
";",
"return",
"factory",
";",
"}"
] | Create a swagger response instance.
@param {Number} code
@param {String} [message]
@returns {Exception}
@constructor | [
"Create",
"a",
"swagger",
"response",
"instance",
"."
] | 455e76b8d65451e606e3c7894ff08affbeb447f1 | https://github.com/byu-oit/sans-server-swagger/blob/455e76b8d65451e606e3c7894ff08affbeb447f1/bin/exception.js#L27-L33 |
55,194 | andrey-p/arg-err | index.js | someSchemasValidate | function someSchemasValidate(propName) {
return schema[propName].some(function (possibleType) {
var tempInput = {},
tempSchema = {},
tempErrs;
tempInput[propName] = input[propName];
tempSchema[propName] = possibleType;
tempErrs = getErrs({
input: tempInput,
schema: tempSchema,
optional: optional
});
return tempErrs.length === 0;
});
} | javascript | function someSchemasValidate(propName) {
return schema[propName].some(function (possibleType) {
var tempInput = {},
tempSchema = {},
tempErrs;
tempInput[propName] = input[propName];
tempSchema[propName] = possibleType;
tempErrs = getErrs({
input: tempInput,
schema: tempSchema,
optional: optional
});
return tempErrs.length === 0;
});
} | [
"function",
"someSchemasValidate",
"(",
"propName",
")",
"{",
"return",
"schema",
"[",
"propName",
"]",
".",
"some",
"(",
"function",
"(",
"possibleType",
")",
"{",
"var",
"tempInput",
"=",
"{",
"}",
",",
"tempSchema",
"=",
"{",
"}",
",",
"tempErrs",
";",
"tempInput",
"[",
"propName",
"]",
"=",
"input",
"[",
"propName",
"]",
";",
"tempSchema",
"[",
"propName",
"]",
"=",
"possibleType",
";",
"tempErrs",
"=",
"getErrs",
"(",
"{",
"input",
":",
"tempInput",
",",
"schema",
":",
"tempSchema",
",",
"optional",
":",
"optional",
"}",
")",
";",
"return",
"tempErrs",
".",
"length",
"===",
"0",
";",
"}",
")",
";",
"}"
] | used for array schema types where all we need is to pass a single array element | [
"used",
"for",
"array",
"schema",
"types",
"where",
"all",
"we",
"need",
"is",
"to",
"pass",
"a",
"single",
"array",
"element"
] | b2aeb45c17f6828821c8b12ffd41ff028a8d360b | https://github.com/andrey-p/arg-err/blob/b2aeb45c17f6828821c8b12ffd41ff028a8d360b/index.js#L83-L99 |
55,195 | intervolga/bem-utils | lib/first-exist.js | firstExist | function firstExist(fileNames) {
const head = fileNames.slice(0, 1);
if (head.length === 0) {
return new Promise((resolve, reject) => {
resolve(false);
});
}
const tail = fileNames.slice(1);
return fileExist(head[0]).then((result) => {
if (false === result) {
return firstExist(tail);
}
return result;
});
} | javascript | function firstExist(fileNames) {
const head = fileNames.slice(0, 1);
if (head.length === 0) {
return new Promise((resolve, reject) => {
resolve(false);
});
}
const tail = fileNames.slice(1);
return fileExist(head[0]).then((result) => {
if (false === result) {
return firstExist(tail);
}
return result;
});
} | [
"function",
"firstExist",
"(",
"fileNames",
")",
"{",
"const",
"head",
"=",
"fileNames",
".",
"slice",
"(",
"0",
",",
"1",
")",
";",
"if",
"(",
"head",
".",
"length",
"===",
"0",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"resolve",
"(",
"false",
")",
";",
"}",
")",
";",
"}",
"const",
"tail",
"=",
"fileNames",
".",
"slice",
"(",
"1",
")",
";",
"return",
"fileExist",
"(",
"head",
"[",
"0",
"]",
")",
".",
"then",
"(",
"(",
"result",
")",
"=>",
"{",
"if",
"(",
"false",
"===",
"result",
")",
"{",
"return",
"firstExist",
"(",
"tail",
")",
";",
"}",
"return",
"result",
";",
"}",
")",
";",
"}"
] | Search for first existing file
@param {Array} fileNames
@return {Promise} | [
"Search",
"for",
"first",
"existing",
"file"
] | 3b81bb9bc408275486175326dc7f35c563a46563 | https://github.com/intervolga/bem-utils/blob/3b81bb9bc408275486175326dc7f35c563a46563/lib/first-exist.js#L9-L25 |
55,196 | johnwebbcole/gulp-openjscad-standalone | docs/csg.js | function(csg) {
var newpolygons = this.polygons.concat(csg.polygons);
var result = CSG.fromPolygons(newpolygons);
result.properties = this.properties._merge(csg.properties);
result.isCanonicalized = this.isCanonicalized && csg.isCanonicalized;
result.isRetesselated = this.isRetesselated && csg.isRetesselated;
return result;
} | javascript | function(csg) {
var newpolygons = this.polygons.concat(csg.polygons);
var result = CSG.fromPolygons(newpolygons);
result.properties = this.properties._merge(csg.properties);
result.isCanonicalized = this.isCanonicalized && csg.isCanonicalized;
result.isRetesselated = this.isRetesselated && csg.isRetesselated;
return result;
} | [
"function",
"(",
"csg",
")",
"{",
"var",
"newpolygons",
"=",
"this",
".",
"polygons",
".",
"concat",
"(",
"csg",
".",
"polygons",
")",
";",
"var",
"result",
"=",
"CSG",
".",
"fromPolygons",
"(",
"newpolygons",
")",
";",
"result",
".",
"properties",
"=",
"this",
".",
"properties",
".",
"_merge",
"(",
"csg",
".",
"properties",
")",
";",
"result",
".",
"isCanonicalized",
"=",
"this",
".",
"isCanonicalized",
"&&",
"csg",
".",
"isCanonicalized",
";",
"result",
".",
"isRetesselated",
"=",
"this",
".",
"isRetesselated",
"&&",
"csg",
".",
"isRetesselated",
";",
"return",
"result",
";",
"}"
] | Like union, but when we know that the two solids are not intersecting Do not use if you are not completely sure that the solids do not intersect! | [
"Like",
"union",
"but",
"when",
"we",
"know",
"that",
"the",
"two",
"solids",
"are",
"not",
"intersecting",
"Do",
"not",
"use",
"if",
"you",
"are",
"not",
"completely",
"sure",
"that",
"the",
"solids",
"do",
"not",
"intersect!"
] | 0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c | https://github.com/johnwebbcole/gulp-openjscad-standalone/blob/0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c/docs/csg.js#L269-L276 |
|
55,197 | johnwebbcole/gulp-openjscad-standalone | docs/csg.js | function(matrix4x4) {
var newpolygons = this.polygons.map(function(p) {
return p.transform(matrix4x4);
});
var result = CSG.fromPolygons(newpolygons);
result.properties = this.properties._transform(matrix4x4);
result.isRetesselated = this.isRetesselated;
return result;
} | javascript | function(matrix4x4) {
var newpolygons = this.polygons.map(function(p) {
return p.transform(matrix4x4);
});
var result = CSG.fromPolygons(newpolygons);
result.properties = this.properties._transform(matrix4x4);
result.isRetesselated = this.isRetesselated;
return result;
} | [
"function",
"(",
"matrix4x4",
")",
"{",
"var",
"newpolygons",
"=",
"this",
".",
"polygons",
".",
"map",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
".",
"transform",
"(",
"matrix4x4",
")",
";",
"}",
")",
";",
"var",
"result",
"=",
"CSG",
".",
"fromPolygons",
"(",
"newpolygons",
")",
";",
"result",
".",
"properties",
"=",
"this",
".",
"properties",
".",
"_transform",
"(",
"matrix4x4",
")",
";",
"result",
".",
"isRetesselated",
"=",
"this",
".",
"isRetesselated",
";",
"return",
"result",
";",
"}"
] | Affine transformation of CSG object. Returns a new CSG object | [
"Affine",
"transformation",
"of",
"CSG",
"object",
".",
"Returns",
"a",
"new",
"CSG",
"object"
] | 0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c | https://github.com/johnwebbcole/gulp-openjscad-standalone/blob/0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c/docs/csg.js#L379-L387 |
|
55,198 | johnwebbcole/gulp-openjscad-standalone | docs/csg.js | function(normal, point, length) {
var plane = CSG.Plane.fromNormalAndPoint(normal, point);
var onb = new CSG.OrthoNormalBasis(plane);
var crosssect = this.sectionCut(onb);
var midpiece = crosssect.extrudeInOrthonormalBasis(onb, length);
var piece1 = this.cutByPlane(plane);
var piece2 = this.cutByPlane(plane.flipped());
var result = piece1.union([midpiece, piece2.translate(plane.normal.times(length))]);
return result;
} | javascript | function(normal, point, length) {
var plane = CSG.Plane.fromNormalAndPoint(normal, point);
var onb = new CSG.OrthoNormalBasis(plane);
var crosssect = this.sectionCut(onb);
var midpiece = crosssect.extrudeInOrthonormalBasis(onb, length);
var piece1 = this.cutByPlane(plane);
var piece2 = this.cutByPlane(plane.flipped());
var result = piece1.union([midpiece, piece2.translate(plane.normal.times(length))]);
return result;
} | [
"function",
"(",
"normal",
",",
"point",
",",
"length",
")",
"{",
"var",
"plane",
"=",
"CSG",
".",
"Plane",
".",
"fromNormalAndPoint",
"(",
"normal",
",",
"point",
")",
";",
"var",
"onb",
"=",
"new",
"CSG",
".",
"OrthoNormalBasis",
"(",
"plane",
")",
";",
"var",
"crosssect",
"=",
"this",
".",
"sectionCut",
"(",
"onb",
")",
";",
"var",
"midpiece",
"=",
"crosssect",
".",
"extrudeInOrthonormalBasis",
"(",
"onb",
",",
"length",
")",
";",
"var",
"piece1",
"=",
"this",
".",
"cutByPlane",
"(",
"plane",
")",
";",
"var",
"piece2",
"=",
"this",
".",
"cutByPlane",
"(",
"plane",
".",
"flipped",
"(",
")",
")",
";",
"var",
"result",
"=",
"piece1",
".",
"union",
"(",
"[",
"midpiece",
",",
"piece2",
".",
"translate",
"(",
"plane",
".",
"normal",
".",
"times",
"(",
"length",
")",
")",
"]",
")",
";",
"return",
"result",
";",
"}"
] | cut the solid at a plane, and stretch the cross-section found along plane normal | [
"cut",
"the",
"solid",
"at",
"a",
"plane",
"and",
"stretch",
"the",
"cross",
"-",
"section",
"found",
"along",
"plane",
"normal"
] | 0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c | https://github.com/johnwebbcole/gulp-openjscad-standalone/blob/0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c/docs/csg.js#L452-L461 |
|
55,199 | johnwebbcole/gulp-openjscad-standalone | docs/csg.js | function(csg) {
if ((this.polygons.length === 0) || (csg.polygons.length === 0)) {
return false;
} else {
var mybounds = this.getBounds();
var otherbounds = csg.getBounds();
if (mybounds[1].x < otherbounds[0].x) return false;
if (mybounds[0].x > otherbounds[1].x) return false;
if (mybounds[1].y < otherbounds[0].y) return false;
if (mybounds[0].y > otherbounds[1].y) return false;
if (mybounds[1].z < otherbounds[0].z) return false;
if (mybounds[0].z > otherbounds[1].z) return false;
return true;
}
} | javascript | function(csg) {
if ((this.polygons.length === 0) || (csg.polygons.length === 0)) {
return false;
} else {
var mybounds = this.getBounds();
var otherbounds = csg.getBounds();
if (mybounds[1].x < otherbounds[0].x) return false;
if (mybounds[0].x > otherbounds[1].x) return false;
if (mybounds[1].y < otherbounds[0].y) return false;
if (mybounds[0].y > otherbounds[1].y) return false;
if (mybounds[1].z < otherbounds[0].z) return false;
if (mybounds[0].z > otherbounds[1].z) return false;
return true;
}
} | [
"function",
"(",
"csg",
")",
"{",
"if",
"(",
"(",
"this",
".",
"polygons",
".",
"length",
"===",
"0",
")",
"||",
"(",
"csg",
".",
"polygons",
".",
"length",
"===",
"0",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"var",
"mybounds",
"=",
"this",
".",
"getBounds",
"(",
")",
";",
"var",
"otherbounds",
"=",
"csg",
".",
"getBounds",
"(",
")",
";",
"if",
"(",
"mybounds",
"[",
"1",
"]",
".",
"x",
"<",
"otherbounds",
"[",
"0",
"]",
".",
"x",
")",
"return",
"false",
";",
"if",
"(",
"mybounds",
"[",
"0",
"]",
".",
"x",
">",
"otherbounds",
"[",
"1",
"]",
".",
"x",
")",
"return",
"false",
";",
"if",
"(",
"mybounds",
"[",
"1",
"]",
".",
"y",
"<",
"otherbounds",
"[",
"0",
"]",
".",
"y",
")",
"return",
"false",
";",
"if",
"(",
"mybounds",
"[",
"0",
"]",
".",
"y",
">",
"otherbounds",
"[",
"1",
"]",
".",
"y",
")",
"return",
"false",
";",
"if",
"(",
"mybounds",
"[",
"1",
"]",
".",
"z",
"<",
"otherbounds",
"[",
"0",
"]",
".",
"z",
")",
"return",
"false",
";",
"if",
"(",
"mybounds",
"[",
"0",
"]",
".",
"z",
">",
"otherbounds",
"[",
"1",
"]",
".",
"z",
")",
"return",
"false",
";",
"return",
"true",
";",
"}",
"}"
] | returns true if there is a possibility that the two solids overlap returns false if we can be sure that they do not overlap | [
"returns",
"true",
"if",
"there",
"is",
"a",
"possibility",
"that",
"the",
"two",
"solids",
"overlap",
"returns",
"false",
"if",
"we",
"can",
"be",
"sure",
"that",
"they",
"do",
"not",
"overlap"
] | 0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c | https://github.com/johnwebbcole/gulp-openjscad-standalone/blob/0727d09fc2b6b20a0e7dac4d2bb44e706c1b442c/docs/csg.js#L748-L762 |
Subsets and Splits