id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
45,700 | thorn0/tinymce.html | tinymce.html.js | addValidChildren | function addValidChildren(validChildren) {
var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
// Invalidate the schema cache if the schema is mutated
mapCache[settings.schema] = null;
validChildren && each(split(validChildren, ','), function(rule) {
var parent, prefix, matches = childRuleRegExp.exec(rule);
if (matches) {
prefix = matches[1];
// Add/remove items from default
parent = prefix ? children[matches[2]] : children[matches[2]] = {
'#comment': {}
};
parent = children[matches[2]];
each(split(matches[3], '|'), function(child) {
'-' === prefix ? delete parent[child] : parent[child] = {};
});
}
});
} | javascript | function addValidChildren(validChildren) {
var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
// Invalidate the schema cache if the schema is mutated
mapCache[settings.schema] = null;
validChildren && each(split(validChildren, ','), function(rule) {
var parent, prefix, matches = childRuleRegExp.exec(rule);
if (matches) {
prefix = matches[1];
// Add/remove items from default
parent = prefix ? children[matches[2]] : children[matches[2]] = {
'#comment': {}
};
parent = children[matches[2]];
each(split(matches[3], '|'), function(child) {
'-' === prefix ? delete parent[child] : parent[child] = {};
});
}
});
} | [
"function",
"addValidChildren",
"(",
"validChildren",
")",
"{",
"var",
"childRuleRegExp",
"=",
"/",
"^([+\\-]?)(\\w+)\\[([^\\]]+)\\]$",
"/",
";",
"// Invalidate the schema cache if the schema is mutated",
"mapCache",
"[",
"settings",
".",
"schema",
"]",
"=",
"null",
";",
"validChildren",
"&&",
"each",
"(",
"split",
"(",
"validChildren",
",",
"','",
")",
",",
"function",
"(",
"rule",
")",
"{",
"var",
"parent",
",",
"prefix",
",",
"matches",
"=",
"childRuleRegExp",
".",
"exec",
"(",
"rule",
")",
";",
"if",
"(",
"matches",
")",
"{",
"prefix",
"=",
"matches",
"[",
"1",
"]",
";",
"// Add/remove items from default",
"parent",
"=",
"prefix",
"?",
"children",
"[",
"matches",
"[",
"2",
"]",
"]",
":",
"children",
"[",
"matches",
"[",
"2",
"]",
"]",
"=",
"{",
"'#comment'",
":",
"{",
"}",
"}",
";",
"parent",
"=",
"children",
"[",
"matches",
"[",
"2",
"]",
"]",
";",
"each",
"(",
"split",
"(",
"matches",
"[",
"3",
"]",
",",
"'|'",
")",
",",
"function",
"(",
"child",
")",
"{",
"'-'",
"===",
"prefix",
"?",
"delete",
"parent",
"[",
"child",
"]",
":",
"parent",
"[",
"child",
"]",
"=",
"{",
"}",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Adds valid children to the schema object | [
"Adds",
"valid",
"children",
"to",
"the",
"schema",
"object"
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1147-L1165 |
45,701 | thorn0/tinymce.html | tinymce.html.js | function(node) {
var self = this;
node.parent && node.remove();
self.insert(node, self);
self.remove();
return self;
} | javascript | function(node) {
var self = this;
node.parent && node.remove();
self.insert(node, self);
self.remove();
return self;
} | [
"function",
"(",
"node",
")",
"{",
"var",
"self",
"=",
"this",
";",
"node",
".",
"parent",
"&&",
"node",
".",
"remove",
"(",
")",
";",
"self",
".",
"insert",
"(",
"node",
",",
"self",
")",
";",
"self",
".",
"remove",
"(",
")",
";",
"return",
"self",
";",
"}"
]
| Replaces the current node with the specified one.
@example
someNode.replace(someNewNode);
@method replace
@param {tinymce.html.Node} node Node to replace the current node with.
@return {tinymce.html.Node} The old node that got replaced. | [
"Replaces",
"the",
"current",
"node",
"with",
"the",
"specified",
"one",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1689-L1695 |
|
45,702 | thorn0/tinymce.html | tinymce.html.js | function() {
var i, l, selfAttrs, selfAttr, cloneAttrs, self = this,
clone = new Node(self.name, self.type);
// Clone element attributes
if (selfAttrs = self.attributes) {
cloneAttrs = [];
cloneAttrs.map = {};
for (i = 0, l = selfAttrs.length; i < l; i++) {
selfAttr = selfAttrs[i];
// Clone everything except id
if ('id' !== selfAttr.name) {
cloneAttrs[cloneAttrs.length] = {
name: selfAttr.name,
value: selfAttr.value
};
cloneAttrs.map[selfAttr.name] = selfAttr.value;
}
}
clone.attributes = cloneAttrs;
}
clone.value = self.value;
clone.shortEnded = self.shortEnded;
return clone;
} | javascript | function() {
var i, l, selfAttrs, selfAttr, cloneAttrs, self = this,
clone = new Node(self.name, self.type);
// Clone element attributes
if (selfAttrs = self.attributes) {
cloneAttrs = [];
cloneAttrs.map = {};
for (i = 0, l = selfAttrs.length; i < l; i++) {
selfAttr = selfAttrs[i];
// Clone everything except id
if ('id' !== selfAttr.name) {
cloneAttrs[cloneAttrs.length] = {
name: selfAttr.name,
value: selfAttr.value
};
cloneAttrs.map[selfAttr.name] = selfAttr.value;
}
}
clone.attributes = cloneAttrs;
}
clone.value = self.value;
clone.shortEnded = self.shortEnded;
return clone;
} | [
"function",
"(",
")",
"{",
"var",
"i",
",",
"l",
",",
"selfAttrs",
",",
"selfAttr",
",",
"cloneAttrs",
",",
"self",
"=",
"this",
",",
"clone",
"=",
"new",
"Node",
"(",
"self",
".",
"name",
",",
"self",
".",
"type",
")",
";",
"// Clone element attributes",
"if",
"(",
"selfAttrs",
"=",
"self",
".",
"attributes",
")",
"{",
"cloneAttrs",
"=",
"[",
"]",
";",
"cloneAttrs",
".",
"map",
"=",
"{",
"}",
";",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"selfAttrs",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"selfAttr",
"=",
"selfAttrs",
"[",
"i",
"]",
";",
"// Clone everything except id",
"if",
"(",
"'id'",
"!==",
"selfAttr",
".",
"name",
")",
"{",
"cloneAttrs",
"[",
"cloneAttrs",
".",
"length",
"]",
"=",
"{",
"name",
":",
"selfAttr",
".",
"name",
",",
"value",
":",
"selfAttr",
".",
"value",
"}",
";",
"cloneAttrs",
".",
"map",
"[",
"selfAttr",
".",
"name",
"]",
"=",
"selfAttr",
".",
"value",
";",
"}",
"}",
"clone",
".",
"attributes",
"=",
"cloneAttrs",
";",
"}",
"clone",
".",
"value",
"=",
"self",
".",
"value",
";",
"clone",
".",
"shortEnded",
"=",
"self",
".",
"shortEnded",
";",
"return",
"clone",
";",
"}"
]
| Does a shallow clones the node into a new node. It will also exclude id attributes since
there should only be one id per document.
@example
var clonedNode = node.clone();
@method clone
@return {tinymce.html.Node} New copy of the original node. | [
"Does",
"a",
"shallow",
"clones",
"the",
"node",
"into",
"a",
"new",
"node",
".",
"It",
"will",
"also",
"exclude",
"id",
"attributes",
"since",
"there",
"should",
"only",
"be",
"one",
"id",
"per",
"document",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1765-L1788 |
|
45,703 | thorn0/tinymce.html | tinymce.html.js | function(wrapper) {
var self = this;
self.parent.insert(wrapper, self);
wrapper.append(self);
return self;
} | javascript | function(wrapper) {
var self = this;
self.parent.insert(wrapper, self);
wrapper.append(self);
return self;
} | [
"function",
"(",
"wrapper",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"parent",
".",
"insert",
"(",
"wrapper",
",",
"self",
")",
";",
"wrapper",
".",
"append",
"(",
"self",
")",
";",
"return",
"self",
";",
"}"
]
| Wraps the node in in another node.
@example
node.wrap(wrapperNode);
@method wrap | [
"Wraps",
"the",
"node",
"in",
"in",
"another",
"node",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1797-L1802 |
|
45,704 | thorn0/tinymce.html | tinymce.html.js | function() {
var node, next, self = this;
for (node = self.firstChild; node;) {
next = node.next;
self.insert(node, self, true);
node = next;
}
self.remove();
} | javascript | function() {
var node, next, self = this;
for (node = self.firstChild; node;) {
next = node.next;
self.insert(node, self, true);
node = next;
}
self.remove();
} | [
"function",
"(",
")",
"{",
"var",
"node",
",",
"next",
",",
"self",
"=",
"this",
";",
"for",
"(",
"node",
"=",
"self",
".",
"firstChild",
";",
"node",
";",
")",
"{",
"next",
"=",
"node",
".",
"next",
";",
"self",
".",
"insert",
"(",
"node",
",",
"self",
",",
"true",
")",
";",
"node",
"=",
"next",
";",
"}",
"self",
".",
"remove",
"(",
")",
";",
"}"
]
| Unwraps the node in other words it removes the node but keeps the children.
@example
node.unwrap();
@method unwrap | [
"Unwraps",
"the",
"node",
"in",
"other",
"words",
"it",
"removes",
"the",
"node",
"but",
"keeps",
"the",
"children",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1811-L1819 |
|
45,705 | thorn0/tinymce.html | tinymce.html.js | function(name) {
var node, self = this,
collection = [];
for (node = self.firstChild; node; node = walk(node, self)) {
node.name === name && collection.push(node);
}
return collection;
} | javascript | function(name) {
var node, self = this,
collection = [];
for (node = self.firstChild; node; node = walk(node, self)) {
node.name === name && collection.push(node);
}
return collection;
} | [
"function",
"(",
"name",
")",
"{",
"var",
"node",
",",
"self",
"=",
"this",
",",
"collection",
"=",
"[",
"]",
";",
"for",
"(",
"node",
"=",
"self",
".",
"firstChild",
";",
"node",
";",
"node",
"=",
"walk",
"(",
"node",
",",
"self",
")",
")",
"{",
"node",
".",
"name",
"===",
"name",
"&&",
"collection",
".",
"push",
"(",
"node",
")",
";",
"}",
"return",
"collection",
";",
"}"
]
| Get all children by name.
@method getAll
@param {String} name Name of the child nodes to collect.
@return {Array} Array with child nodes matchin the specified name. | [
"Get",
"all",
"children",
"by",
"name",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1912-L1919 |
|
45,706 | thorn0/tinymce.html | tinymce.html.js | function() {
var nodes, i, node, self = this;
// Remove all children
if (self.firstChild) {
nodes = [];
// Collect the children
for (node = self.firstChild; node; node = walk(node, self)) {
nodes.push(node);
}
// Remove the children
i = nodes.length;
while (i--) {
node = nodes[i];
node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
}
}
self.firstChild = self.lastChild = null;
return self;
} | javascript | function() {
var nodes, i, node, self = this;
// Remove all children
if (self.firstChild) {
nodes = [];
// Collect the children
for (node = self.firstChild; node; node = walk(node, self)) {
nodes.push(node);
}
// Remove the children
i = nodes.length;
while (i--) {
node = nodes[i];
node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
}
}
self.firstChild = self.lastChild = null;
return self;
} | [
"function",
"(",
")",
"{",
"var",
"nodes",
",",
"i",
",",
"node",
",",
"self",
"=",
"this",
";",
"// Remove all children",
"if",
"(",
"self",
".",
"firstChild",
")",
"{",
"nodes",
"=",
"[",
"]",
";",
"// Collect the children",
"for",
"(",
"node",
"=",
"self",
".",
"firstChild",
";",
"node",
";",
"node",
"=",
"walk",
"(",
"node",
",",
"self",
")",
")",
"{",
"nodes",
".",
"push",
"(",
"node",
")",
";",
"}",
"// Remove the children",
"i",
"=",
"nodes",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"node",
"=",
"nodes",
"[",
"i",
"]",
";",
"node",
".",
"parent",
"=",
"node",
".",
"firstChild",
"=",
"node",
".",
"lastChild",
"=",
"node",
".",
"next",
"=",
"node",
".",
"prev",
"=",
"null",
";",
"}",
"}",
"self",
".",
"firstChild",
"=",
"self",
".",
"lastChild",
"=",
"null",
";",
"return",
"self",
";",
"}"
]
| Removes all children of the current node.
@method empty
@return {tinymce.html.Node} The current node that got cleared. | [
"Removes",
"all",
"children",
"of",
"the",
"current",
"node",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L1926-L1944 |
|
45,707 | thorn0/tinymce.html | tinymce.html.js | compress2 | function compress2(target, a, b, c) {
if (!canCompress(a)) {
return;
}
if (!canCompress(b)) {
return;
}
if (!canCompress(c)) {
return;
}
// Compress
styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
delete styles[a];
delete styles[b];
delete styles[c];
} | javascript | function compress2(target, a, b, c) {
if (!canCompress(a)) {
return;
}
if (!canCompress(b)) {
return;
}
if (!canCompress(c)) {
return;
}
// Compress
styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
delete styles[a];
delete styles[b];
delete styles[c];
} | [
"function",
"compress2",
"(",
"target",
",",
"a",
",",
"b",
",",
"c",
")",
"{",
"if",
"(",
"!",
"canCompress",
"(",
"a",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"canCompress",
"(",
"b",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"canCompress",
"(",
"c",
")",
")",
"{",
"return",
";",
"}",
"// Compress",
"styles",
"[",
"target",
"]",
"=",
"styles",
"[",
"a",
"]",
"+",
"' '",
"+",
"styles",
"[",
"b",
"]",
"+",
"' '",
"+",
"styles",
"[",
"c",
"]",
";",
"delete",
"styles",
"[",
"a",
"]",
";",
"delete",
"styles",
"[",
"b",
"]",
";",
"delete",
"styles",
"[",
"c",
"]",
";",
"}"
]
| Compresses multiple styles into one style. | [
"Compresses",
"multiple",
"styles",
"into",
"one",
"style",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L3150-L3165 |
45,708 | thorn0/tinymce.html | tinymce.html.js | function(styles, elementName) {
var name, value, css = '';
function serializeStyles(name) {
var styleList, i, l, value;
styleList = validStyles[name];
if (styleList) {
for (i = 0, l = styleList.length; i < l; i++) {
name = styleList[i];
value = styles[name];
value && (css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';');
}
}
}
function isValid(name, elementName) {
var styleMap;
styleMap = invalidStyles['*'];
if (styleMap && styleMap[name]) {
return false;
}
styleMap = invalidStyles[elementName];
if (styleMap && styleMap[name]) {
return false;
}
return true;
}
// Serialize styles according to schema
if (elementName && validStyles) {
// Serialize global styles and element specific styles
serializeStyles('*');
serializeStyles(elementName);
} else {
// Output the styles in the order they are inside the object
for (name in styles) {
value = styles[name];
!value || invalidStyles && !isValid(name, elementName) || (css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';');
}
}
return css;
} | javascript | function(styles, elementName) {
var name, value, css = '';
function serializeStyles(name) {
var styleList, i, l, value;
styleList = validStyles[name];
if (styleList) {
for (i = 0, l = styleList.length; i < l; i++) {
name = styleList[i];
value = styles[name];
value && (css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';');
}
}
}
function isValid(name, elementName) {
var styleMap;
styleMap = invalidStyles['*'];
if (styleMap && styleMap[name]) {
return false;
}
styleMap = invalidStyles[elementName];
if (styleMap && styleMap[name]) {
return false;
}
return true;
}
// Serialize styles according to schema
if (elementName && validStyles) {
// Serialize global styles and element specific styles
serializeStyles('*');
serializeStyles(elementName);
} else {
// Output the styles in the order they are inside the object
for (name in styles) {
value = styles[name];
!value || invalidStyles && !isValid(name, elementName) || (css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';');
}
}
return css;
} | [
"function",
"(",
"styles",
",",
"elementName",
")",
"{",
"var",
"name",
",",
"value",
",",
"css",
"=",
"''",
";",
"function",
"serializeStyles",
"(",
"name",
")",
"{",
"var",
"styleList",
",",
"i",
",",
"l",
",",
"value",
";",
"styleList",
"=",
"validStyles",
"[",
"name",
"]",
";",
"if",
"(",
"styleList",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"l",
"=",
"styleList",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"name",
"=",
"styleList",
"[",
"i",
"]",
";",
"value",
"=",
"styles",
"[",
"name",
"]",
";",
"value",
"&&",
"(",
"css",
"+=",
"(",
"css",
".",
"length",
">",
"0",
"?",
"' '",
":",
"''",
")",
"+",
"name",
"+",
"': '",
"+",
"value",
"+",
"';'",
")",
";",
"}",
"}",
"}",
"function",
"isValid",
"(",
"name",
",",
"elementName",
")",
"{",
"var",
"styleMap",
";",
"styleMap",
"=",
"invalidStyles",
"[",
"'*'",
"]",
";",
"if",
"(",
"styleMap",
"&&",
"styleMap",
"[",
"name",
"]",
")",
"{",
"return",
"false",
";",
"}",
"styleMap",
"=",
"invalidStyles",
"[",
"elementName",
"]",
";",
"if",
"(",
"styleMap",
"&&",
"styleMap",
"[",
"name",
"]",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"// Serialize styles according to schema",
"if",
"(",
"elementName",
"&&",
"validStyles",
")",
"{",
"// Serialize global styles and element specific styles",
"serializeStyles",
"(",
"'*'",
")",
";",
"serializeStyles",
"(",
"elementName",
")",
";",
"}",
"else",
"{",
"// Output the styles in the order they are inside the object",
"for",
"(",
"name",
"in",
"styles",
")",
"{",
"value",
"=",
"styles",
"[",
"name",
"]",
";",
"!",
"value",
"||",
"invalidStyles",
"&&",
"!",
"isValid",
"(",
"name",
",",
"elementName",
")",
"||",
"(",
"css",
"+=",
"(",
"css",
".",
"length",
">",
"0",
"?",
"' '",
":",
"''",
")",
"+",
"name",
"+",
"': '",
"+",
"value",
"+",
"';'",
")",
";",
"}",
"}",
"return",
"css",
";",
"}"
]
| Serializes the specified style object into a string.
@method serialize
@param {Object} styles Object to serialize as string for example: {border: '1px solid red'}
@param {String} elementName Optional element name, if specified only the styles that matches the schema will be serialized.
@return {String} String representation of the style object for example: border: 1px solid red. | [
"Serializes",
"the",
"specified",
"style",
"object",
"into",
"a",
"string",
"."
]
| 0bf3faa50368b68b5a4f5a436169295535778ead | https://github.com/thorn0/tinymce.html/blob/0bf3faa50368b68b5a4f5a436169295535778ead/tinymce.html.js#L3270-L3310 |
|
45,709 | socialally/air | lib/air/find.js | find | function find(selector) {
var arr = [], $ = this.air, slice = this.slice;
this.each(function(el) {
arr = arr.concat(slice.call($(selector, el).dom));
});
return $(arr);
} | javascript | function find(selector) {
var arr = [], $ = this.air, slice = this.slice;
this.each(function(el) {
arr = arr.concat(slice.call($(selector, el).dom));
});
return $(arr);
} | [
"function",
"find",
"(",
"selector",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
",",
"$",
"=",
"this",
".",
"air",
",",
"slice",
"=",
"this",
".",
"slice",
";",
"this",
".",
"each",
"(",
"function",
"(",
"el",
")",
"{",
"arr",
"=",
"arr",
".",
"concat",
"(",
"slice",
".",
"call",
"(",
"$",
"(",
"selector",
",",
"el",
")",
".",
"dom",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"(",
"arr",
")",
";",
"}"
]
| Get the descendants of each element in the current set
of matched elements, filtered by a selector. | [
"Get",
"the",
"descendants",
"of",
"each",
"element",
"in",
"the",
"current",
"set",
"of",
"matched",
"elements",
"filtered",
"by",
"a",
"selector",
"."
]
| a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/find.js#L5-L11 |
45,710 | vid/SenseBase | util/importItemAnnotations.js | fv | function fv(vals, key) {
if (!vals) return;
vals.forEach(function(v) {
if (v.key === key && vals[key] !== 'Not available') {
return vals[key];
}
});
} | javascript | function fv(vals, key) {
if (!vals) return;
vals.forEach(function(v) {
if (v.key === key && vals[key] !== 'Not available') {
return vals[key];
}
});
} | [
"function",
"fv",
"(",
"vals",
",",
"key",
")",
"{",
"if",
"(",
"!",
"vals",
")",
"return",
";",
"vals",
".",
"forEach",
"(",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
".",
"key",
"===",
"key",
"&&",
"vals",
"[",
"key",
"]",
"!==",
"'Not available'",
")",
"{",
"return",
"vals",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"}"
]
| utility assigns field value | [
"utility",
"assigns",
"field",
"value"
]
| d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/util/importItemAnnotations.js#L99-L106 |
45,711 | theworkers/W.js | node/jade-middleware.js | hasMatchingJadeFileInPages | function hasMatchingJadeFileInPages(srcDir, url, pages, jadeOptions, callback) {
if (typeof pages[url] === 'undefined') {
// get the possible jade file path
var extension = path.extname(url);
var jadeFilePath;
var htmlFilePath;
if (extension === ".html" /* || extension === ".htm" */) {
jadeFilePath = path.join(srcDir, url.substring(0, url.length - extension.length) + ".jade");
htmlFilePath = path.join(srcDir, url);
} else {
jadeFilePath = path.join(srcDir, url + "/index.jade");
htmlFilePath = path.join(srcDir, url + "/index.html");
}
// see if the jadefile exsists
fs.exists(jadeFilePath, function (exsits) {
// store the result in a new HTML page
pages[url] = new HTMLPage({
matchingJadeFilePath: (exsits)?jadeFilePath:null,
htmlFilePath: htmlFilePath,
jadeOptions: jadeOptions
});
callback(!!pages[url].matchingJadeFilePath, pages[url]);
});
} else {
callback(!!pages[url].matchingJadeFilePath, pages[url]);
}
} | javascript | function hasMatchingJadeFileInPages(srcDir, url, pages, jadeOptions, callback) {
if (typeof pages[url] === 'undefined') {
// get the possible jade file path
var extension = path.extname(url);
var jadeFilePath;
var htmlFilePath;
if (extension === ".html" /* || extension === ".htm" */) {
jadeFilePath = path.join(srcDir, url.substring(0, url.length - extension.length) + ".jade");
htmlFilePath = path.join(srcDir, url);
} else {
jadeFilePath = path.join(srcDir, url + "/index.jade");
htmlFilePath = path.join(srcDir, url + "/index.html");
}
// see if the jadefile exsists
fs.exists(jadeFilePath, function (exsits) {
// store the result in a new HTML page
pages[url] = new HTMLPage({
matchingJadeFilePath: (exsits)?jadeFilePath:null,
htmlFilePath: htmlFilePath,
jadeOptions: jadeOptions
});
callback(!!pages[url].matchingJadeFilePath, pages[url]);
});
} else {
callback(!!pages[url].matchingJadeFilePath, pages[url]);
}
} | [
"function",
"hasMatchingJadeFileInPages",
"(",
"srcDir",
",",
"url",
",",
"pages",
",",
"jadeOptions",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"pages",
"[",
"url",
"]",
"===",
"'undefined'",
")",
"{",
"// get the possible jade file path",
"var",
"extension",
"=",
"path",
".",
"extname",
"(",
"url",
")",
";",
"var",
"jadeFilePath",
";",
"var",
"htmlFilePath",
";",
"if",
"(",
"extension",
"===",
"\".html\"",
"/* || extension === \".htm\" */",
")",
"{",
"jadeFilePath",
"=",
"path",
".",
"join",
"(",
"srcDir",
",",
"url",
".",
"substring",
"(",
"0",
",",
"url",
".",
"length",
"-",
"extension",
".",
"length",
")",
"+",
"\".jade\"",
")",
";",
"htmlFilePath",
"=",
"path",
".",
"join",
"(",
"srcDir",
",",
"url",
")",
";",
"}",
"else",
"{",
"jadeFilePath",
"=",
"path",
".",
"join",
"(",
"srcDir",
",",
"url",
"+",
"\"/index.jade\"",
")",
";",
"htmlFilePath",
"=",
"path",
".",
"join",
"(",
"srcDir",
",",
"url",
"+",
"\"/index.html\"",
")",
";",
"}",
"// see if the jadefile exsists",
"fs",
".",
"exists",
"(",
"jadeFilePath",
",",
"function",
"(",
"exsits",
")",
"{",
"// store the result in a new HTML page",
"pages",
"[",
"url",
"]",
"=",
"new",
"HTMLPage",
"(",
"{",
"matchingJadeFilePath",
":",
"(",
"exsits",
")",
"?",
"jadeFilePath",
":",
"null",
",",
"htmlFilePath",
":",
"htmlFilePath",
",",
"jadeOptions",
":",
"jadeOptions",
"}",
")",
";",
"callback",
"(",
"!",
"!",
"pages",
"[",
"url",
"]",
".",
"matchingJadeFilePath",
",",
"pages",
"[",
"url",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"!",
"!",
"pages",
"[",
"url",
"]",
".",
"matchingJadeFilePath",
",",
"pages",
"[",
"url",
"]",
")",
";",
"}",
"}"
]
| creates a jade page if it doesn't exist in cache | [
"creates",
"a",
"jade",
"page",
"if",
"it",
"doesn",
"t",
"exist",
"in",
"cache"
]
| 25a11baf8edb27c306f2baf6438bed2faf935bc6 | https://github.com/theworkers/W.js/blob/25a11baf8edb27c306f2baf6438bed2faf935bc6/node/jade-middleware.js#L56-L82 |
45,712 | mattinsler/caboose | lib/view/helpers/view_helper.js | function( input, null_text ) {
if ( input == null || input === undefined ) return null_text || '';
if ( typeof input === 'object' && Object.prototype.toString.call(input) === '[object Date]' ) return input.toDateString();
if ( input.toString ) return input.toString().replace(/\n/g, '<br />').replace(/''/g, "'");
return '';
} | javascript | function( input, null_text ) {
if ( input == null || input === undefined ) return null_text || '';
if ( typeof input === 'object' && Object.prototype.toString.call(input) === '[object Date]' ) return input.toDateString();
if ( input.toString ) return input.toString().replace(/\n/g, '<br />').replace(/''/g, "'");
return '';
} | [
"function",
"(",
"input",
",",
"null_text",
")",
"{",
"if",
"(",
"input",
"==",
"null",
"||",
"input",
"===",
"undefined",
")",
"return",
"null_text",
"||",
"''",
";",
"if",
"(",
"typeof",
"input",
"===",
"'object'",
"&&",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"input",
")",
"===",
"'[object Date]'",
")",
"return",
"input",
".",
"toDateString",
"(",
")",
";",
"if",
"(",
"input",
".",
"toString",
")",
"return",
"input",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"'<br />'",
")",
".",
"replace",
"(",
"/",
"''",
"/",
"g",
",",
"\"'\"",
")",
";",
"return",
"''",
";",
"}"
]
| Converts response to text. | [
"Converts",
"response",
"to",
"text",
"."
]
| b0e1d0d7962050a2f72e918197488011cfb8ba57 | https://github.com/mattinsler/caboose/blob/b0e1d0d7962050a2f72e918197488011cfb8ba57/lib/view/helpers/view_helper.js#L5-L10 |
|
45,713 | mattinsler/caboose | lib/view/helpers/view_helper.js | function( name, value, options, checked ) {
options = options || {};
if(checked) options.checked = "checked";
return this.input_field_tag(name, value, 'checkbox', options);
} | javascript | function( name, value, options, checked ) {
options = options || {};
if(checked) options.checked = "checked";
return this.input_field_tag(name, value, 'checkbox', options);
} | [
"function",
"(",
"name",
",",
"value",
",",
"options",
",",
"checked",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"checked",
")",
"options",
".",
"checked",
"=",
"\"checked\"",
";",
"return",
"this",
".",
"input_field_tag",
"(",
"name",
",",
"value",
",",
"'checkbox'",
",",
"options",
")",
";",
"}"
]
| Creates a check box tag
@plugin view/helpers
@param {Object} name
@param {Object} value
@param {Object} options
@param {Object} checked | [
"Creates",
"a",
"check",
"box",
"tag"
]
| b0e1d0d7962050a2f72e918197488011cfb8ba57 | https://github.com/mattinsler/caboose/blob/b0e1d0d7962050a2f72e918197488011cfb8ba57/lib/view/helpers/view_helper.js#L23-L27 |
|
45,714 | colleenjoyce/react-paginator | index.js | range | function range(start, stop) {
if (arguments.length <= 1) {
stop = start || 0;
start = 0;
}
var length = Math.max(stop - start, 0);
var idx = 0;
var arr = new Array(length);
while(idx < length) {
arr[idx++] = start;
start += 1;
}
return arr;
} | javascript | function range(start, stop) {
if (arguments.length <= 1) {
stop = start || 0;
start = 0;
}
var length = Math.max(stop - start, 0);
var idx = 0;
var arr = new Array(length);
while(idx < length) {
arr[idx++] = start;
start += 1;
}
return arr;
} | [
"function",
"range",
"(",
"start",
",",
"stop",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"<=",
"1",
")",
"{",
"stop",
"=",
"start",
"||",
"0",
";",
"start",
"=",
"0",
";",
"}",
"var",
"length",
"=",
"Math",
".",
"max",
"(",
"stop",
"-",
"start",
",",
"0",
")",
";",
"var",
"idx",
"=",
"0",
";",
"var",
"arr",
"=",
"new",
"Array",
"(",
"length",
")",
";",
"while",
"(",
"idx",
"<",
"length",
")",
"{",
"arr",
"[",
"idx",
"++",
"]",
"=",
"start",
";",
"start",
"+=",
"1",
";",
"}",
"return",
"arr",
";",
"}"
]
| Slighlty modified from underscore source | [
"Slighlty",
"modified",
"from",
"underscore",
"source"
]
| 13fe5de76a9b20e55d7e2e382e7744623a965e9f | https://github.com/colleenjoyce/react-paginator/blob/13fe5de76a9b20e55d7e2e382e7744623a965e9f/index.js#L7-L23 |
45,715 | colleenjoyce/react-paginator | index.js | function(n) {
// n is out of range, don't do anything
if (n > this.props.numPages || n < 1) return;
if (this.props.onClick) this.props.onClick(n);
this.setState({ page: n });
} | javascript | function(n) {
// n is out of range, don't do anything
if (n > this.props.numPages || n < 1) return;
if (this.props.onClick) this.props.onClick(n);
this.setState({ page: n });
} | [
"function",
"(",
"n",
")",
"{",
"// n is out of range, don't do anything",
"if",
"(",
"n",
">",
"this",
".",
"props",
".",
"numPages",
"||",
"n",
"<",
"1",
")",
"return",
";",
"if",
"(",
"this",
".",
"props",
".",
"onClick",
")",
"this",
".",
"props",
".",
"onClick",
"(",
"n",
")",
";",
"this",
".",
"setState",
"(",
"{",
"page",
":",
"n",
"}",
")",
";",
"}"
]
| Triggered by any button click within the paginator.
@param {number} n - Page number | [
"Triggered",
"by",
"any",
"button",
"click",
"within",
"the",
"paginator",
"."
]
| 13fe5de76a9b20e55d7e2e382e7744623a965e9f | https://github.com/colleenjoyce/react-paginator/blob/13fe5de76a9b20e55d7e2e382e7744623a965e9f/index.js#L56-L61 |
|
45,716 | byteclubfr/npm-scripts-tree | index.js | archify | function archify (scripts, alpha) {
let names = Object.keys(scripts)
if (alpha) {
names = names.sort()
}
return {
label: `${names.length} scripts`,
nodes: names.map(n => scripts[n])
}
} | javascript | function archify (scripts, alpha) {
let names = Object.keys(scripts)
if (alpha) {
names = names.sort()
}
return {
label: `${names.length} scripts`,
nodes: names.map(n => scripts[n])
}
} | [
"function",
"archify",
"(",
"scripts",
",",
"alpha",
")",
"{",
"let",
"names",
"=",
"Object",
".",
"keys",
"(",
"scripts",
")",
"if",
"(",
"alpha",
")",
"{",
"names",
"=",
"names",
".",
"sort",
"(",
")",
"}",
"return",
"{",
"label",
":",
"`",
"${",
"names",
".",
"length",
"}",
"`",
",",
"nodes",
":",
"names",
".",
"map",
"(",
"n",
"=>",
"scripts",
"[",
"n",
"]",
")",
"}",
"}"
]
| label and nodes | [
"label",
"and",
"nodes"
]
| fee33c1a00b9aae01801afe5e6951af9a596670b | https://github.com/byteclubfr/npm-scripts-tree/blob/fee33c1a00b9aae01801afe5e6951af9a596670b/index.js#L53-L62 |
45,717 | byteclubfr/npm-scripts-tree | index.js | isLifeCycleScript | function isLifeCycleScript (prefix, name, scripts) {
const re = new RegExp("^" + prefix)
const root = name.slice(prefix.length)
return Boolean(name.match(re) && (scripts[root] || BUILTINS.includes(root)))
} | javascript | function isLifeCycleScript (prefix, name, scripts) {
const re = new RegExp("^" + prefix)
const root = name.slice(prefix.length)
return Boolean(name.match(re) && (scripts[root] || BUILTINS.includes(root)))
} | [
"function",
"isLifeCycleScript",
"(",
"prefix",
",",
"name",
",",
"scripts",
")",
"{",
"const",
"re",
"=",
"new",
"RegExp",
"(",
"\"^\"",
"+",
"prefix",
")",
"const",
"root",
"=",
"name",
".",
"slice",
"(",
"prefix",
".",
"length",
")",
"return",
"Boolean",
"(",
"name",
".",
"match",
"(",
"re",
")",
"&&",
"(",
"scripts",
"[",
"root",
"]",
"||",
"BUILTINS",
".",
"includes",
"(",
"root",
")",
")",
")",
"}"
]
| pre, post or builtins | [
"pre",
"post",
"or",
"builtins"
]
| fee33c1a00b9aae01801afe5e6951af9a596670b | https://github.com/byteclubfr/npm-scripts-tree/blob/fee33c1a00b9aae01801afe5e6951af9a596670b/index.js#L77-L81 |
45,718 | byteclubfr/npm-scripts-tree | index.js | getRunAllScripts | function getRunAllScripts (cmd) {
const re = RegExp("(?:npm-run-all" + RE_FLAGS + RE_NAMES + ")+", "gi")
const cmds = getMatches(re, cmd).map(m =>
// clean spaces
m.match.trim().split(" ").filter(x => x))
return unique(flatten(cmds))
} | javascript | function getRunAllScripts (cmd) {
const re = RegExp("(?:npm-run-all" + RE_FLAGS + RE_NAMES + ")+", "gi")
const cmds = getMatches(re, cmd).map(m =>
// clean spaces
m.match.trim().split(" ").filter(x => x))
return unique(flatten(cmds))
} | [
"function",
"getRunAllScripts",
"(",
"cmd",
")",
"{",
"const",
"re",
"=",
"RegExp",
"(",
"\"(?:npm-run-all\"",
"+",
"RE_FLAGS",
"+",
"RE_NAMES",
"+",
"\")+\"",
",",
"\"gi\"",
")",
"const",
"cmds",
"=",
"getMatches",
"(",
"re",
",",
"cmd",
")",
".",
"map",
"(",
"m",
"=>",
"// clean spaces",
"m",
".",
"match",
".",
"trim",
"(",
")",
".",
"split",
"(",
"\" \"",
")",
".",
"filter",
"(",
"x",
"=>",
"x",
")",
")",
"return",
"unique",
"(",
"flatten",
"(",
"cmds",
")",
")",
"}"
]
| handled by npm-run-all module | [
"handled",
"by",
"npm",
"-",
"run",
"-",
"all",
"module"
]
| fee33c1a00b9aae01801afe5e6951af9a596670b | https://github.com/byteclubfr/npm-scripts-tree/blob/fee33c1a00b9aae01801afe5e6951af9a596670b/index.js#L119-L126 |
45,719 | KAIT-HEMS/node-picogw-plugin-admin | index.js | onProcCallGet | function onProcCallGet(method, path, args) {
// log('onProcCallGet('+JSON.stringify(arguments));
let pathSplit = path.split('/');
const serviceid = pathSplit.shift();
const propname = pathSplit.join('/');
const bInfo = (args.info === 'true');
if (serviceid == '') { // access 'admin/' => service list
let re = {net: {}, server_status: {}};
if (bInfo) {
re._info = {leaf: false};
}
re.net = ipv4.getMACs();
re.id = {};
if (bInfo) {
re.net._info = {
leaf: false,
doc: {short: 'Mac address of recognized network peers'},
};
re.server_status._info={
leaf: true,
doc: {short: 'Check server memory/swap status'},
};
re.id._info = {leaf: true, doc:{short: 'Get unique ID of this PicoGW'}};
}
return re;
}
if (propname == '') { // access 'admin/serviceid/' => property list
let ret;
switch (serviceid) {
case 'net':
const macs = ipv4.getMACs();
// log(JSON.stringify(macs));
ret = macs;
for (const [mac, macinfo] of Object.entries(macs)) {
if (bInfo) {
ret[mac]._info = {
leaf: true,
doc: {short: (macinfo.ip || 'IP:null')},
};
}
}
return ret;
case 'server_status':
return new Promise((ac, rj)=>{
exec('vmstat', (err, stdout, stderr) => {
if (err) {
ac({error: 'Command execution failed.',
result: err});
} else if (stdout !== null) {
ac({success: true, result: stdout.split('\n')});
} else {
ac({error: 'Command execution failed.',
result: stderr});
}
});
});
case 'id':
return {id:exports.getMyID()};
}
return {error: 'No such service:'+serviceid};
}
switch (serviceid) {
case 'net':
const m = ipv4.getMACs()[propname];
if (m == undefined) {
return {error: 'No such mac address:'+propname};
}
return m;
}
return {error: 'No such service:'+serviceid};
} | javascript | function onProcCallGet(method, path, args) {
// log('onProcCallGet('+JSON.stringify(arguments));
let pathSplit = path.split('/');
const serviceid = pathSplit.shift();
const propname = pathSplit.join('/');
const bInfo = (args.info === 'true');
if (serviceid == '') { // access 'admin/' => service list
let re = {net: {}, server_status: {}};
if (bInfo) {
re._info = {leaf: false};
}
re.net = ipv4.getMACs();
re.id = {};
if (bInfo) {
re.net._info = {
leaf: false,
doc: {short: 'Mac address of recognized network peers'},
};
re.server_status._info={
leaf: true,
doc: {short: 'Check server memory/swap status'},
};
re.id._info = {leaf: true, doc:{short: 'Get unique ID of this PicoGW'}};
}
return re;
}
if (propname == '') { // access 'admin/serviceid/' => property list
let ret;
switch (serviceid) {
case 'net':
const macs = ipv4.getMACs();
// log(JSON.stringify(macs));
ret = macs;
for (const [mac, macinfo] of Object.entries(macs)) {
if (bInfo) {
ret[mac]._info = {
leaf: true,
doc: {short: (macinfo.ip || 'IP:null')},
};
}
}
return ret;
case 'server_status':
return new Promise((ac, rj)=>{
exec('vmstat', (err, stdout, stderr) => {
if (err) {
ac({error: 'Command execution failed.',
result: err});
} else if (stdout !== null) {
ac({success: true, result: stdout.split('\n')});
} else {
ac({error: 'Command execution failed.',
result: stderr});
}
});
});
case 'id':
return {id:exports.getMyID()};
}
return {error: 'No such service:'+serviceid};
}
switch (serviceid) {
case 'net':
const m = ipv4.getMACs()[propname];
if (m == undefined) {
return {error: 'No such mac address:'+propname};
}
return m;
}
return {error: 'No such service:'+serviceid};
} | [
"function",
"onProcCallGet",
"(",
"method",
",",
"path",
",",
"args",
")",
"{",
"// log('onProcCallGet('+JSON.stringify(arguments));",
"let",
"pathSplit",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
";",
"const",
"serviceid",
"=",
"pathSplit",
".",
"shift",
"(",
")",
";",
"const",
"propname",
"=",
"pathSplit",
".",
"join",
"(",
"'/'",
")",
";",
"const",
"bInfo",
"=",
"(",
"args",
".",
"info",
"===",
"'true'",
")",
";",
"if",
"(",
"serviceid",
"==",
"''",
")",
"{",
"// access 'admin/' => service list",
"let",
"re",
"=",
"{",
"net",
":",
"{",
"}",
",",
"server_status",
":",
"{",
"}",
"}",
";",
"if",
"(",
"bInfo",
")",
"{",
"re",
".",
"_info",
"=",
"{",
"leaf",
":",
"false",
"}",
";",
"}",
"re",
".",
"net",
"=",
"ipv4",
".",
"getMACs",
"(",
")",
";",
"re",
".",
"id",
"=",
"{",
"}",
";",
"if",
"(",
"bInfo",
")",
"{",
"re",
".",
"net",
".",
"_info",
"=",
"{",
"leaf",
":",
"false",
",",
"doc",
":",
"{",
"short",
":",
"'Mac address of recognized network peers'",
"}",
",",
"}",
";",
"re",
".",
"server_status",
".",
"_info",
"=",
"{",
"leaf",
":",
"true",
",",
"doc",
":",
"{",
"short",
":",
"'Check server memory/swap status'",
"}",
",",
"}",
";",
"re",
".",
"id",
".",
"_info",
"=",
"{",
"leaf",
":",
"true",
",",
"doc",
":",
"{",
"short",
":",
"'Get unique ID of this PicoGW'",
"}",
"}",
";",
"}",
"return",
"re",
";",
"}",
"if",
"(",
"propname",
"==",
"''",
")",
"{",
"// access 'admin/serviceid/' => property list",
"let",
"ret",
";",
"switch",
"(",
"serviceid",
")",
"{",
"case",
"'net'",
":",
"const",
"macs",
"=",
"ipv4",
".",
"getMACs",
"(",
")",
";",
"// log(JSON.stringify(macs));",
"ret",
"=",
"macs",
";",
"for",
"(",
"const",
"[",
"mac",
",",
"macinfo",
"]",
"of",
"Object",
".",
"entries",
"(",
"macs",
")",
")",
"{",
"if",
"(",
"bInfo",
")",
"{",
"ret",
"[",
"mac",
"]",
".",
"_info",
"=",
"{",
"leaf",
":",
"true",
",",
"doc",
":",
"{",
"short",
":",
"(",
"macinfo",
".",
"ip",
"||",
"'IP:null'",
")",
"}",
",",
"}",
";",
"}",
"}",
"return",
"ret",
";",
"case",
"'server_status'",
":",
"return",
"new",
"Promise",
"(",
"(",
"ac",
",",
"rj",
")",
"=>",
"{",
"exec",
"(",
"'vmstat'",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"ac",
"(",
"{",
"error",
":",
"'Command execution failed.'",
",",
"result",
":",
"err",
"}",
")",
";",
"}",
"else",
"if",
"(",
"stdout",
"!==",
"null",
")",
"{",
"ac",
"(",
"{",
"success",
":",
"true",
",",
"result",
":",
"stdout",
".",
"split",
"(",
"'\\n'",
")",
"}",
")",
";",
"}",
"else",
"{",
"ac",
"(",
"{",
"error",
":",
"'Command execution failed.'",
",",
"result",
":",
"stderr",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"case",
"'id'",
":",
"return",
"{",
"id",
":",
"exports",
".",
"getMyID",
"(",
")",
"}",
";",
"}",
"return",
"{",
"error",
":",
"'No such service:'",
"+",
"serviceid",
"}",
";",
"}",
"switch",
"(",
"serviceid",
")",
"{",
"case",
"'net'",
":",
"const",
"m",
"=",
"ipv4",
".",
"getMACs",
"(",
")",
"[",
"propname",
"]",
";",
"if",
"(",
"m",
"==",
"undefined",
")",
"{",
"return",
"{",
"error",
":",
"'No such mac address:'",
"+",
"propname",
"}",
";",
"}",
"return",
"m",
";",
"}",
"return",
"{",
"error",
":",
"'No such service:'",
"+",
"serviceid",
"}",
";",
"}"
]
| onCall handler of plugin for GET method
@param {string} method Caller method, accept GET only.
@param {string} path Plugin URL path
@param {object} args parameters of this call
@return {object} Returns a Promise object or object containing the result | [
"onCall",
"handler",
"of",
"plugin",
"for",
"GET",
"method"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L121-L197 |
45,720 | KAIT-HEMS/node-picogw-plugin-admin | index.js | listNetInterfaces | function listNetInterfaces() {
return new Promise((ac, rj) => {
exec('nmcli d', (err, stdout, stderr) => {
const lines = stdout.split('\n');
if (err || lines.length<2) {
rj({error: 'No network available.'});
return;
}
lines.shift();
// Correct visible APs should be listed
let bWlanExist = false;
const interfaces = [];
lines.forEach((line)=>{
let sp = line.trim().split(/\s+/);
if (sp.length < 4 || sp[0]=='lo') return; // Illegally formatted line
if (sp[0].indexOf('wlan')==0) bWlanExist = true;
interfaces.push(sp[0]);
});
ac([interfaces, bWlanExist]);
});
});
} | javascript | function listNetInterfaces() {
return new Promise((ac, rj) => {
exec('nmcli d', (err, stdout, stderr) => {
const lines = stdout.split('\n');
if (err || lines.length<2) {
rj({error: 'No network available.'});
return;
}
lines.shift();
// Correct visible APs should be listed
let bWlanExist = false;
const interfaces = [];
lines.forEach((line)=>{
let sp = line.trim().split(/\s+/);
if (sp.length < 4 || sp[0]=='lo') return; // Illegally formatted line
if (sp[0].indexOf('wlan')==0) bWlanExist = true;
interfaces.push(sp[0]);
});
ac([interfaces, bWlanExist]);
});
});
} | [
"function",
"listNetInterfaces",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"ac",
",",
"rj",
")",
"=>",
"{",
"exec",
"(",
"'nmcli d'",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"const",
"lines",
"=",
"stdout",
".",
"split",
"(",
"'\\n'",
")",
";",
"if",
"(",
"err",
"||",
"lines",
".",
"length",
"<",
"2",
")",
"{",
"rj",
"(",
"{",
"error",
":",
"'No network available.'",
"}",
")",
";",
"return",
";",
"}",
"lines",
".",
"shift",
"(",
")",
";",
"// Correct visible APs should be listed",
"let",
"bWlanExist",
"=",
"false",
";",
"const",
"interfaces",
"=",
"[",
"]",
";",
"lines",
".",
"forEach",
"(",
"(",
"line",
")",
"=>",
"{",
"let",
"sp",
"=",
"line",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"if",
"(",
"sp",
".",
"length",
"<",
"4",
"||",
"sp",
"[",
"0",
"]",
"==",
"'lo'",
")",
"return",
";",
"// Illegally formatted line",
"if",
"(",
"sp",
"[",
"0",
"]",
".",
"indexOf",
"(",
"'wlan'",
")",
"==",
"0",
")",
"bWlanExist",
"=",
"true",
";",
"interfaces",
".",
"push",
"(",
"sp",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"ac",
"(",
"[",
"interfaces",
",",
"bWlanExist",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| List Network Interfaces
@return {Promise} Return a list of network interfaces and whether you are using WiFi | [
"List",
"Network",
"Interfaces"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L466-L489 |
45,721 | KAIT-HEMS/node-picogw-plugin-admin | index.js | routeSet | async function routeSet(target, netInterface, rootPwd) {
const connName = await searchConnNameFromNetworkInterface(netInterface);
const prevRoutes = await searchPrevRoutes(target);
if (prevRoutes.length == 1) {
if (prevRoutes[0].connName === connName &&
prevRoutes[0].target === target &&
prevRoutes[0].gatewayIP === '0.0.0.0') {
return; // no need to do anything
}
}
await routeDelete(target, rootPwd);
const cmds = [
['nmcli', 'connection', 'modify', connName,
'+ipv4.routes', `${target} 0.0.0.0`],
['nmcli', 'connection', 'down', connName],
['nmcli', 'connection', 'up', connName],
];
return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
} | javascript | async function routeSet(target, netInterface, rootPwd) {
const connName = await searchConnNameFromNetworkInterface(netInterface);
const prevRoutes = await searchPrevRoutes(target);
if (prevRoutes.length == 1) {
if (prevRoutes[0].connName === connName &&
prevRoutes[0].target === target &&
prevRoutes[0].gatewayIP === '0.0.0.0') {
return; // no need to do anything
}
}
await routeDelete(target, rootPwd);
const cmds = [
['nmcli', 'connection', 'modify', connName,
'+ipv4.routes', `${target} 0.0.0.0`],
['nmcli', 'connection', 'down', connName],
['nmcli', 'connection', 'up', connName],
];
return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
} | [
"async",
"function",
"routeSet",
"(",
"target",
",",
"netInterface",
",",
"rootPwd",
")",
"{",
"const",
"connName",
"=",
"await",
"searchConnNameFromNetworkInterface",
"(",
"netInterface",
")",
";",
"const",
"prevRoutes",
"=",
"await",
"searchPrevRoutes",
"(",
"target",
")",
";",
"if",
"(",
"prevRoutes",
".",
"length",
"==",
"1",
")",
"{",
"if",
"(",
"prevRoutes",
"[",
"0",
"]",
".",
"connName",
"===",
"connName",
"&&",
"prevRoutes",
"[",
"0",
"]",
".",
"target",
"===",
"target",
"&&",
"prevRoutes",
"[",
"0",
"]",
".",
"gatewayIP",
"===",
"'0.0.0.0'",
")",
"{",
"return",
";",
"// no need to do anything",
"}",
"}",
"await",
"routeDelete",
"(",
"target",
",",
"rootPwd",
")",
";",
"const",
"cmds",
"=",
"[",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'modify'",
",",
"connName",
",",
"'+ipv4.routes'",
",",
"`",
"${",
"target",
"}",
"`",
"]",
",",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'down'",
",",
"connName",
"]",
",",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'up'",
",",
"connName",
"]",
",",
"]",
";",
"return",
"await",
"executeCommands",
"(",
"cmds",
",",
"null",
",",
"{",
"sudo",
":",
"true",
",",
"password",
":",
"rootPwd",
"}",
")",
";",
"}"
]
| Set static route to ipv4 network
@param {string} target : the destination network or host. e.g. 224.0.23.0/32
@param {string} netInterface : network interface to set route
@param {string} rootPwd : root password for executing sudo
@return {Promise} Return last command output | [
"Set",
"static",
"route",
"to",
"ipv4",
"network"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L527-L546 |
45,722 | KAIT-HEMS/node-picogw-plugin-admin | index.js | routeDelete | async function routeDelete(target, rootPwd) {
const prevRoutes = await searchPrevRoutes(target);
if (prevRoutes.length == 0) {
return; // no need to do anything
}
const cmds = [];
for (const prevRoute of prevRoutes) {
cmds.push([
'nmcli', 'connection', 'modify', prevRoute.connName,
'-ipv4.routes', `${prevRoute.target} ${prevRoute.gatewayIP}`]);
cmds.push(['nmcli', 'connection', 'down', prevRoute.connName]);
cmds.push(['nmcli', 'connection', 'up', prevRoute.connName]);
}
return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
} | javascript | async function routeDelete(target, rootPwd) {
const prevRoutes = await searchPrevRoutes(target);
if (prevRoutes.length == 0) {
return; // no need to do anything
}
const cmds = [];
for (const prevRoute of prevRoutes) {
cmds.push([
'nmcli', 'connection', 'modify', prevRoute.connName,
'-ipv4.routes', `${prevRoute.target} ${prevRoute.gatewayIP}`]);
cmds.push(['nmcli', 'connection', 'down', prevRoute.connName]);
cmds.push(['nmcli', 'connection', 'up', prevRoute.connName]);
}
return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
} | [
"async",
"function",
"routeDelete",
"(",
"target",
",",
"rootPwd",
")",
"{",
"const",
"prevRoutes",
"=",
"await",
"searchPrevRoutes",
"(",
"target",
")",
";",
"if",
"(",
"prevRoutes",
".",
"length",
"==",
"0",
")",
"{",
"return",
";",
"// no need to do anything",
"}",
"const",
"cmds",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"prevRoute",
"of",
"prevRoutes",
")",
"{",
"cmds",
".",
"push",
"(",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'modify'",
",",
"prevRoute",
".",
"connName",
",",
"'-ipv4.routes'",
",",
"`",
"${",
"prevRoute",
".",
"target",
"}",
"${",
"prevRoute",
".",
"gatewayIP",
"}",
"`",
"]",
")",
";",
"cmds",
".",
"push",
"(",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'down'",
",",
"prevRoute",
".",
"connName",
"]",
")",
";",
"cmds",
".",
"push",
"(",
"[",
"'nmcli'",
",",
"'connection'",
",",
"'up'",
",",
"prevRoute",
".",
"connName",
"]",
")",
";",
"}",
"return",
"await",
"executeCommands",
"(",
"cmds",
",",
"null",
",",
"{",
"sudo",
":",
"true",
",",
"password",
":",
"rootPwd",
"}",
")",
";",
"}"
]
| Delete static route from ipv4 network
@param {string} target : the destination network or host. e.g. 224.0.23.0/32
@param {string} rootPwd : root password for executing sudo
@return {Promise} Return standard output of each command as an array | [
"Delete",
"static",
"route",
"from",
"ipv4",
"network"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L555-L569 |
45,723 | KAIT-HEMS/node-picogw-plugin-admin | index.js | listConnections | async function listConnections() {
const connList = await executeCommand(
['nmcli', '-f', 'NAME,DEVICE', '-t', 'connection', 'show']);
const ret = {};
connList.split('\n').map((l) => {
return l.split(/:/);
}).filter((ary) => {
return ary[0] && ary[1];
}).forEach((ary) => {
ret[ary[0]] = ary[1];
});
return ret;
} | javascript | async function listConnections() {
const connList = await executeCommand(
['nmcli', '-f', 'NAME,DEVICE', '-t', 'connection', 'show']);
const ret = {};
connList.split('\n').map((l) => {
return l.split(/:/);
}).filter((ary) => {
return ary[0] && ary[1];
}).forEach((ary) => {
ret[ary[0]] = ary[1];
});
return ret;
} | [
"async",
"function",
"listConnections",
"(",
")",
"{",
"const",
"connList",
"=",
"await",
"executeCommand",
"(",
"[",
"'nmcli'",
",",
"'-f'",
",",
"'NAME,DEVICE'",
",",
"'-t'",
",",
"'connection'",
",",
"'show'",
"]",
")",
";",
"const",
"ret",
"=",
"{",
"}",
";",
"connList",
".",
"split",
"(",
"'\\n'",
")",
".",
"map",
"(",
"(",
"l",
")",
"=>",
"{",
"return",
"l",
".",
"split",
"(",
"/",
":",
"/",
")",
";",
"}",
")",
".",
"filter",
"(",
"(",
"ary",
")",
"=>",
"{",
"return",
"ary",
"[",
"0",
"]",
"&&",
"ary",
"[",
"1",
"]",
";",
"}",
")",
".",
"forEach",
"(",
"(",
"ary",
")",
"=>",
"{",
"ret",
"[",
"ary",
"[",
"0",
"]",
"]",
"=",
"ary",
"[",
"1",
"]",
";",
"}",
")",
";",
"return",
"ret",
";",
"}"
]
| List connection names with device name
@return {Array.<object>} Return list of connection name and device name | [
"List",
"connection",
"names",
"with",
"device",
"name"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L576-L588 |
45,724 | KAIT-HEMS/node-picogw-plugin-admin | index.js | searchPrevRoutes | async function searchPrevRoutes(target) {
const connNames = await listConnectionNames();
const ret = [];
for (const connName of connNames) {
const cmd = [
'nmcli', '-f', 'IP4.ROUTE', 'connection', 'show', connName,
];
const output = await executeCommand(cmd);
for (const line of output.split('\n')) {
const exs = `dst\\s*=\\s*${target},\\snh\\s*=\\s*([\\d\.]+)`;
const re = line.match(new RegExp(exs));
if (!re) {
continue;
}
ret.push({
connName: connName,
target: target,
gatewayIP: re[1],
});
}
}
return ret;
} | javascript | async function searchPrevRoutes(target) {
const connNames = await listConnectionNames();
const ret = [];
for (const connName of connNames) {
const cmd = [
'nmcli', '-f', 'IP4.ROUTE', 'connection', 'show', connName,
];
const output = await executeCommand(cmd);
for (const line of output.split('\n')) {
const exs = `dst\\s*=\\s*${target},\\snh\\s*=\\s*([\\d\.]+)`;
const re = line.match(new RegExp(exs));
if (!re) {
continue;
}
ret.push({
connName: connName,
target: target,
gatewayIP: re[1],
});
}
}
return ret;
} | [
"async",
"function",
"searchPrevRoutes",
"(",
"target",
")",
"{",
"const",
"connNames",
"=",
"await",
"listConnectionNames",
"(",
")",
";",
"const",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"connName",
"of",
"connNames",
")",
"{",
"const",
"cmd",
"=",
"[",
"'nmcli'",
",",
"'-f'",
",",
"'IP4.ROUTE'",
",",
"'connection'",
",",
"'show'",
",",
"connName",
",",
"]",
";",
"const",
"output",
"=",
"await",
"executeCommand",
"(",
"cmd",
")",
";",
"for",
"(",
"const",
"line",
"of",
"output",
".",
"split",
"(",
"'\\n'",
")",
")",
"{",
"const",
"exs",
"=",
"`",
"\\\\",
"\\\\",
"${",
"target",
"}",
"\\\\",
"\\\\",
"\\\\",
"\\\\",
"\\.",
"`",
";",
"const",
"re",
"=",
"line",
".",
"match",
"(",
"new",
"RegExp",
"(",
"exs",
")",
")",
";",
"if",
"(",
"!",
"re",
")",
"{",
"continue",
";",
"}",
"ret",
".",
"push",
"(",
"{",
"connName",
":",
"connName",
",",
"target",
":",
"target",
",",
"gatewayIP",
":",
"re",
"[",
"1",
"]",
",",
"}",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
]
| Search previous route from NetworkManager
@param {string} target : the destination network or host. e.g. 224.0.23.0/32
@return {Array.<object>} Return list of previous route setting | [
"Search",
"previous",
"route",
"from",
"NetworkManager"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L603-L625 |
45,725 | KAIT-HEMS/node-picogw-plugin-admin | index.js | searchConnNameFromIP | async function searchConnNameFromIP(ip) { // eslint-disable-line no-unused-vars
const connNames = await listConnectionNames();
const gipnum = ipv4.convToNum(ip);
for (const connName of connNames) {
const cmd = [
'nmcli', '-f', 'IP4.ADDRESS', 'connection', 'show', connName,
];
const output = await executeCommand(cmd);
for (const line of output.split('\n')) {
const re = line.match(/\s+([\d\.]+)\/([\d]+)/);
if (!re) {
continue;
}
const ip = ipv4.convToNum(re[1]);
const mask = parseInt(re[2]);
if ((ip & mask) == (gipnum & mask)) {
return connName;
}
}
}
return null;
} | javascript | async function searchConnNameFromIP(ip) { // eslint-disable-line no-unused-vars
const connNames = await listConnectionNames();
const gipnum = ipv4.convToNum(ip);
for (const connName of connNames) {
const cmd = [
'nmcli', '-f', 'IP4.ADDRESS', 'connection', 'show', connName,
];
const output = await executeCommand(cmd);
for (const line of output.split('\n')) {
const re = line.match(/\s+([\d\.]+)\/([\d]+)/);
if (!re) {
continue;
}
const ip = ipv4.convToNum(re[1]);
const mask = parseInt(re[2]);
if ((ip & mask) == (gipnum & mask)) {
return connName;
}
}
}
return null;
} | [
"async",
"function",
"searchConnNameFromIP",
"(",
"ip",
")",
"{",
"// eslint-disable-line no-unused-vars",
"const",
"connNames",
"=",
"await",
"listConnectionNames",
"(",
")",
";",
"const",
"gipnum",
"=",
"ipv4",
".",
"convToNum",
"(",
"ip",
")",
";",
"for",
"(",
"const",
"connName",
"of",
"connNames",
")",
"{",
"const",
"cmd",
"=",
"[",
"'nmcli'",
",",
"'-f'",
",",
"'IP4.ADDRESS'",
",",
"'connection'",
",",
"'show'",
",",
"connName",
",",
"]",
";",
"const",
"output",
"=",
"await",
"executeCommand",
"(",
"cmd",
")",
";",
"for",
"(",
"const",
"line",
"of",
"output",
".",
"split",
"(",
"'\\n'",
")",
")",
"{",
"const",
"re",
"=",
"line",
".",
"match",
"(",
"/",
"\\s+([\\d\\.]+)\\/([\\d]+)",
"/",
")",
";",
"if",
"(",
"!",
"re",
")",
"{",
"continue",
";",
"}",
"const",
"ip",
"=",
"ipv4",
".",
"convToNum",
"(",
"re",
"[",
"1",
"]",
")",
";",
"const",
"mask",
"=",
"parseInt",
"(",
"re",
"[",
"2",
"]",
")",
";",
"if",
"(",
"(",
"ip",
"&",
"mask",
")",
"==",
"(",
"gipnum",
"&",
"mask",
")",
")",
"{",
"return",
"connName",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
]
| Search the connection name of the same network from the ip address
@param {string} ip : ip address
@return {string} connection name for NetworkManager | [
"Search",
"the",
"connection",
"name",
"of",
"the",
"same",
"network",
"from",
"the",
"ip",
"address"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L632-L653 |
45,726 | KAIT-HEMS/node-picogw-plugin-admin | index.js | searchConnNameFromNetworkInterface | async function searchConnNameFromNetworkInterface(netInterface) { // eslint-disable-line no-unused-vars
const conns = await listConnections();
for (const [connName, nif] of Object.entries(conns)) {
if (nif === netInterface) {
return connName;
}
}
return null;
} | javascript | async function searchConnNameFromNetworkInterface(netInterface) { // eslint-disable-line no-unused-vars
const conns = await listConnections();
for (const [connName, nif] of Object.entries(conns)) {
if (nif === netInterface) {
return connName;
}
}
return null;
} | [
"async",
"function",
"searchConnNameFromNetworkInterface",
"(",
"netInterface",
")",
"{",
"// eslint-disable-line no-unused-vars",
"const",
"conns",
"=",
"await",
"listConnections",
"(",
")",
";",
"for",
"(",
"const",
"[",
"connName",
",",
"nif",
"]",
"of",
"Object",
".",
"entries",
"(",
"conns",
")",
")",
"{",
"if",
"(",
"nif",
"===",
"netInterface",
")",
"{",
"return",
"connName",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Search the connection name from the network interface
@param {string} netInterface : network interface
@return {string} connection name for NetworkManager | [
"Search",
"the",
"connection",
"name",
"from",
"the",
"network",
"interface"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L660-L668 |
45,727 | KAIT-HEMS/node-picogw-plugin-admin | index.js | executeCommand | function executeCommand(cmd, option) {
option = option || {};
return new Promise((ac, rj)=>{
let okMsg = '';
let erMsg='';
log('Exec:'+cmd.join(' '));
let child;
if (option.sudo) {
child = sudo(cmd, {password: option.password});
} else {
child = spawn(cmd[0], cmd.slice(1));
}
child.stdout.on('data', (dat)=>{
okMsg += dat.toString();
});
child.stderr.on('data', (dat)=>{
erMsg += dat.toString();
});
child.on('close', (code)=>{
if (code == 0) {
ac(okMsg);
} else {
rj('Error in executing\n'
+'$ '+cmd.join(' ')+'\n\n'
+ erMsg);
}
});
child.on('error', (err)=>{
rj(err);
});
});
} | javascript | function executeCommand(cmd, option) {
option = option || {};
return new Promise((ac, rj)=>{
let okMsg = '';
let erMsg='';
log('Exec:'+cmd.join(' '));
let child;
if (option.sudo) {
child = sudo(cmd, {password: option.password});
} else {
child = spawn(cmd[0], cmd.slice(1));
}
child.stdout.on('data', (dat)=>{
okMsg += dat.toString();
});
child.stderr.on('data', (dat)=>{
erMsg += dat.toString();
});
child.on('close', (code)=>{
if (code == 0) {
ac(okMsg);
} else {
rj('Error in executing\n'
+'$ '+cmd.join(' ')+'\n\n'
+ erMsg);
}
});
child.on('error', (err)=>{
rj(err);
});
});
} | [
"function",
"executeCommand",
"(",
"cmd",
",",
"option",
")",
"{",
"option",
"=",
"option",
"||",
"{",
"}",
";",
"return",
"new",
"Promise",
"(",
"(",
"ac",
",",
"rj",
")",
"=>",
"{",
"let",
"okMsg",
"=",
"''",
";",
"let",
"erMsg",
"=",
"''",
";",
"log",
"(",
"'Exec:'",
"+",
"cmd",
".",
"join",
"(",
"' '",
")",
")",
";",
"let",
"child",
";",
"if",
"(",
"option",
".",
"sudo",
")",
"{",
"child",
"=",
"sudo",
"(",
"cmd",
",",
"{",
"password",
":",
"option",
".",
"password",
"}",
")",
";",
"}",
"else",
"{",
"child",
"=",
"spawn",
"(",
"cmd",
"[",
"0",
"]",
",",
"cmd",
".",
"slice",
"(",
"1",
")",
")",
";",
"}",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"dat",
")",
"=>",
"{",
"okMsg",
"+=",
"dat",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"dat",
")",
"=>",
"{",
"erMsg",
"+=",
"dat",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"child",
".",
"on",
"(",
"'close'",
",",
"(",
"code",
")",
"=>",
"{",
"if",
"(",
"code",
"==",
"0",
")",
"{",
"ac",
"(",
"okMsg",
")",
";",
"}",
"else",
"{",
"rj",
"(",
"'Error in executing\\n'",
"+",
"'$ '",
"+",
"cmd",
".",
"join",
"(",
"' '",
")",
"+",
"'\\n\\n'",
"+",
"erMsg",
")",
";",
"}",
"}",
")",
";",
"child",
".",
"on",
"(",
"'error'",
",",
"(",
"err",
")",
"=>",
"{",
"rj",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Execute command with sudo
@param {Array.<string>} cmd : Array of command
@param {object} [option] : option parameter
@return {Promise} Return stdout strings | [
"Execute",
"command",
"with",
"sudo"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L676-L707 |
45,728 | KAIT-HEMS/node-picogw-plugin-admin | index.js | executeCommands | async function executeCommands(commands, ignoreErrorFunc, option) {
const ret = [];
for (const cmd of commands) {
const r = await executeCommand(cmd, option).catch((e) => {
if (ignoreErrorFunc && ignoreErrorFunc(cmd)) {
// ignore error
return '';
}
throw e;
});
ret.push(r);
}
return ret;
} | javascript | async function executeCommands(commands, ignoreErrorFunc, option) {
const ret = [];
for (const cmd of commands) {
const r = await executeCommand(cmd, option).catch((e) => {
if (ignoreErrorFunc && ignoreErrorFunc(cmd)) {
// ignore error
return '';
}
throw e;
});
ret.push(r);
}
return ret;
} | [
"async",
"function",
"executeCommands",
"(",
"commands",
",",
"ignoreErrorFunc",
",",
"option",
")",
"{",
"const",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"cmd",
"of",
"commands",
")",
"{",
"const",
"r",
"=",
"await",
"executeCommand",
"(",
"cmd",
",",
"option",
")",
".",
"catch",
"(",
"(",
"e",
")",
"=>",
"{",
"if",
"(",
"ignoreErrorFunc",
"&&",
"ignoreErrorFunc",
"(",
"cmd",
")",
")",
"{",
"// ignore error",
"return",
"''",
";",
"}",
"throw",
"e",
";",
"}",
")",
";",
"ret",
".",
"push",
"(",
"r",
")",
";",
"}",
"return",
"ret",
";",
"}"
]
| Execute commands with sudo
@param {Array.<Array.<string>>} commands : Array of command list
@param {function} ignoreErrorFunc : Handler for determining whether to ignore when command fails
@param {object} [option] : option parameter
@return {Promise} Return standard output of each command as an array | [
"Execute",
"commands",
"with",
"sudo"
]
| 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/index.js#L716-L729 |
45,729 | DScheglov/merest | lib/controllers/search.js | search | function search(req, res, next) {
res.__apiMethod = 'search';
buildQuery.call(this, req).exec(function (err, obj) {
if (err) {
var isCastError =
(err.name === 'CastError') ||
(err.message && err.message[0] === '$') ||
(err.message === 'and needs an array')
;
if (isCastError) return next(
new ModelAPIError(400, err.message)
);
return next(err);
}
res.json(obj);
});
} | javascript | function search(req, res, next) {
res.__apiMethod = 'search';
buildQuery.call(this, req).exec(function (err, obj) {
if (err) {
var isCastError =
(err.name === 'CastError') ||
(err.message && err.message[0] === '$') ||
(err.message === 'and needs an array')
;
if (isCastError) return next(
new ModelAPIError(400, err.message)
);
return next(err);
}
res.json(obj);
});
} | [
"function",
"search",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"__apiMethod",
"=",
"'search'",
";",
"buildQuery",
".",
"call",
"(",
"this",
",",
"req",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"obj",
")",
"{",
"if",
"(",
"err",
")",
"{",
"var",
"isCastError",
"=",
"(",
"err",
".",
"name",
"===",
"'CastError'",
")",
"||",
"(",
"err",
".",
"message",
"&&",
"err",
".",
"message",
"[",
"0",
"]",
"===",
"'$'",
")",
"||",
"(",
"err",
".",
"message",
"===",
"'and needs an array'",
")",
";",
"if",
"(",
"isCastError",
")",
"return",
"next",
"(",
"new",
"ModelAPIError",
"(",
"400",
",",
"err",
".",
"message",
")",
")",
";",
"return",
"next",
"(",
"err",
")",
";",
"}",
"res",
".",
"json",
"(",
"obj",
")",
";",
"}",
")",
";",
"}"
]
| search - Searches the objects in attached model collection
@param {express.Request} req the http(s) request
@param {express.Response} res the http(s) response
@param {Function} next the callback should be called if controller fails
@memberof ModelAPIRouter | [
"search",
"-",
"Searches",
"the",
"objects",
"in",
"attached",
"model",
"collection"
]
| d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/search.js#L16-L36 |
45,730 | jillix/flow-registry | lib/dev.js | installModule | function installModule (module, modulesDir, callback) {
let details = module.split('/');
let devModulePath = resolve(modulesDir, module);
fs.access(resolve(modulesDir, module), err => {
// skip next steps if module already exists
if (!err || err.code !== 'ENOENT') {
return callback();
}
exec('git clone [email protected]:' + details[0] + '/' + details[1] + '.git ' + devModulePath, err => {
if (err) {
return callback(err);
}
exec('cd ' + devModulePath + '; npm i', err => {
if (err) {
return callback(err);
}
// create a symlink to the babelify presets
// it is required in order for babelify to work
fs.symlink(resolve(__dirname, '../../', 'babel-preset-es2015'), resolve(devModulePath, 'node_modules/babel-preset-es2015'), err => {
if (err) {
return callback(err);
}
callback();
});
});
});
});
} | javascript | function installModule (module, modulesDir, callback) {
let details = module.split('/');
let devModulePath = resolve(modulesDir, module);
fs.access(resolve(modulesDir, module), err => {
// skip next steps if module already exists
if (!err || err.code !== 'ENOENT') {
return callback();
}
exec('git clone [email protected]:' + details[0] + '/' + details[1] + '.git ' + devModulePath, err => {
if (err) {
return callback(err);
}
exec('cd ' + devModulePath + '; npm i', err => {
if (err) {
return callback(err);
}
// create a symlink to the babelify presets
// it is required in order for babelify to work
fs.symlink(resolve(__dirname, '../../', 'babel-preset-es2015'), resolve(devModulePath, 'node_modules/babel-preset-es2015'), err => {
if (err) {
return callback(err);
}
callback();
});
});
});
});
} | [
"function",
"installModule",
"(",
"module",
",",
"modulesDir",
",",
"callback",
")",
"{",
"let",
"details",
"=",
"module",
".",
"split",
"(",
"'/'",
")",
";",
"let",
"devModulePath",
"=",
"resolve",
"(",
"modulesDir",
",",
"module",
")",
";",
"fs",
".",
"access",
"(",
"resolve",
"(",
"modulesDir",
",",
"module",
")",
",",
"err",
"=>",
"{",
"// skip next steps if module already exists",
"if",
"(",
"!",
"err",
"||",
"err",
".",
"code",
"!==",
"'ENOENT'",
")",
"{",
"return",
"callback",
"(",
")",
";",
"}",
"exec",
"(",
"'git clone [email protected]:'",
"+",
"details",
"[",
"0",
"]",
"+",
"'/'",
"+",
"details",
"[",
"1",
"]",
"+",
"'.git '",
"+",
"devModulePath",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"exec",
"(",
"'cd '",
"+",
"devModulePath",
"+",
"'; npm i'",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"// create a symlink to the babelify presets",
"// it is required in order for babelify to work",
"fs",
".",
"symlink",
"(",
"resolve",
"(",
"__dirname",
",",
"'../../'",
",",
"'babel-preset-es2015'",
")",
",",
"resolve",
"(",
"devModulePath",
",",
"'node_modules/babel-preset-es2015'",
")",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| this will clone and install all the required dependencies of a module | [
"this",
"will",
"clone",
"and",
"install",
"all",
"the",
"required",
"dependencies",
"of",
"a",
"module"
]
| 4a2b8c462269098fe76551f5adf1acef5ceb1b1c | https://github.com/jillix/flow-registry/blob/4a2b8c462269098fe76551f5adf1acef5ceb1b1c/lib/dev.js#L76-L113 |
45,731 | jillix/flow-registry | lib/dev.js | setupSymlinks | function setupSymlinks (module, modulesDir, callback) {
let details = module.split('/');
let modulePath = resolve(NODE_MODULES, details[1]);
let devModulePath = resolve(modulesDir, module);
rimraf(modulePath, err => {
if (err) {
return callback(err);
}
fs.symlink(devModulePath, modulePath, err => {
if (err) {
return callback(err);
}
callback();
});
});
} | javascript | function setupSymlinks (module, modulesDir, callback) {
let details = module.split('/');
let modulePath = resolve(NODE_MODULES, details[1]);
let devModulePath = resolve(modulesDir, module);
rimraf(modulePath, err => {
if (err) {
return callback(err);
}
fs.symlink(devModulePath, modulePath, err => {
if (err) {
return callback(err);
}
callback();
});
});
} | [
"function",
"setupSymlinks",
"(",
"module",
",",
"modulesDir",
",",
"callback",
")",
"{",
"let",
"details",
"=",
"module",
".",
"split",
"(",
"'/'",
")",
";",
"let",
"modulePath",
"=",
"resolve",
"(",
"NODE_MODULES",
",",
"details",
"[",
"1",
"]",
")",
";",
"let",
"devModulePath",
"=",
"resolve",
"(",
"modulesDir",
",",
"module",
")",
";",
"rimraf",
"(",
"modulePath",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"fs",
".",
"symlink",
"(",
"devModulePath",
",",
"modulePath",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| this will remove the module from the registry and create all the required links | [
"this",
"will",
"remove",
"the",
"module",
"from",
"the",
"registry",
"and",
"create",
"all",
"the",
"required",
"links"
]
| 4a2b8c462269098fe76551f5adf1acef5ceb1b1c | https://github.com/jillix/flow-registry/blob/4a2b8c462269098fe76551f5adf1acef5ceb1b1c/lib/dev.js#L116-L137 |
45,732 | jillix/flow-registry | lib/dev.js | watchModule | function watchModule (module, modulesDir) {
const pathToModule = resolve(modulesDir, module);
const pathToHandlers = resolve(HANDLER_BASE, module);
modules[module] = {
handlers: []
};
fs.readdir(pathToHandlers, (err, files) => {
if (err) {
return console.log(new Error('Failed to get handler files for module: ' + module));
}
files.forEach(file => {
if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
return;
}
modules[module].handlers.push(pathToHandlers + '/' + file);
});
let watchList = modules[module].handlers.concat([pathToModule]);
let watcher = chokidar.watch(watchList, {
ignored: /(^|[\/\\])\../,
persistent: true
});
watcher.on('change', (path, stats) => {
// rebundle based on the type of the file
if (modules[module].handlers.indexOf(path) < 0) {
modules[module].handlers.forEach(handler => bundleHandler(pathToHandlers, module, handler.substr(handler.lastIndexOf('/') + 1)));
} else {
bundleHandler(pathToHandlers, module, path.substr(path.lastIndexOf('/') + 1));
}
});
});
} | javascript | function watchModule (module, modulesDir) {
const pathToModule = resolve(modulesDir, module);
const pathToHandlers = resolve(HANDLER_BASE, module);
modules[module] = {
handlers: []
};
fs.readdir(pathToHandlers, (err, files) => {
if (err) {
return console.log(new Error('Failed to get handler files for module: ' + module));
}
files.forEach(file => {
if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
return;
}
modules[module].handlers.push(pathToHandlers + '/' + file);
});
let watchList = modules[module].handlers.concat([pathToModule]);
let watcher = chokidar.watch(watchList, {
ignored: /(^|[\/\\])\../,
persistent: true
});
watcher.on('change', (path, stats) => {
// rebundle based on the type of the file
if (modules[module].handlers.indexOf(path) < 0) {
modules[module].handlers.forEach(handler => bundleHandler(pathToHandlers, module, handler.substr(handler.lastIndexOf('/') + 1)));
} else {
bundleHandler(pathToHandlers, module, path.substr(path.lastIndexOf('/') + 1));
}
});
});
} | [
"function",
"watchModule",
"(",
"module",
",",
"modulesDir",
")",
"{",
"const",
"pathToModule",
"=",
"resolve",
"(",
"modulesDir",
",",
"module",
")",
";",
"const",
"pathToHandlers",
"=",
"resolve",
"(",
"HANDLER_BASE",
",",
"module",
")",
";",
"modules",
"[",
"module",
"]",
"=",
"{",
"handlers",
":",
"[",
"]",
"}",
";",
"fs",
".",
"readdir",
"(",
"pathToHandlers",
",",
"(",
"err",
",",
"files",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"console",
".",
"log",
"(",
"new",
"Error",
"(",
"'Failed to get handler files for module: '",
"+",
"module",
")",
")",
";",
"}",
"files",
".",
"forEach",
"(",
"file",
"=>",
"{",
"if",
"(",
"file",
".",
"length",
"<",
"3",
"||",
"file",
".",
"indexOf",
"(",
"'bundle.'",
")",
"===",
"0",
"||",
"file",
".",
"substr",
"(",
"file",
".",
"length",
"-",
"3",
")",
"!==",
"'.js'",
")",
"{",
"return",
";",
"}",
"modules",
"[",
"module",
"]",
".",
"handlers",
".",
"push",
"(",
"pathToHandlers",
"+",
"'/'",
"+",
"file",
")",
";",
"}",
")",
";",
"let",
"watchList",
"=",
"modules",
"[",
"module",
"]",
".",
"handlers",
".",
"concat",
"(",
"[",
"pathToModule",
"]",
")",
";",
"let",
"watcher",
"=",
"chokidar",
".",
"watch",
"(",
"watchList",
",",
"{",
"ignored",
":",
"/",
"(^|[\\/\\\\])\\..",
"/",
",",
"persistent",
":",
"true",
"}",
")",
";",
"watcher",
".",
"on",
"(",
"'change'",
",",
"(",
"path",
",",
"stats",
")",
"=>",
"{",
"// rebundle based on the type of the file",
"if",
"(",
"modules",
"[",
"module",
"]",
".",
"handlers",
".",
"indexOf",
"(",
"path",
")",
"<",
"0",
")",
"{",
"modules",
"[",
"module",
"]",
".",
"handlers",
".",
"forEach",
"(",
"handler",
"=>",
"bundleHandler",
"(",
"pathToHandlers",
",",
"module",
",",
"handler",
".",
"substr",
"(",
"handler",
".",
"lastIndexOf",
"(",
"'/'",
")",
"+",
"1",
")",
")",
")",
";",
"}",
"else",
"{",
"bundleHandler",
"(",
"pathToHandlers",
",",
"module",
",",
"path",
".",
"substr",
"(",
"path",
".",
"lastIndexOf",
"(",
"'/'",
")",
"+",
"1",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
]
| this will watch for changes in a module or its handlers | [
"this",
"will",
"watch",
"for",
"changes",
"in",
"a",
"module",
"or",
"its",
"handlers"
]
| 4a2b8c462269098fe76551f5adf1acef5ceb1b1c | https://github.com/jillix/flow-registry/blob/4a2b8c462269098fe76551f5adf1acef5ceb1b1c/lib/dev.js#L140-L179 |
45,733 | jillix/flow-registry | lib/dev.js | bundleHandler | function bundleHandler (pathToHandlers, module, file) {
// only rebundle if js file changed
if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
return;
}
// only rebundle if handler was already bundled before
fs.access(pathToHandlers + '/bundle.' + file, err => {
if (err && err.code === 'ENOENT') {
return ;
}
let fnIri = module + '/' + file.slice(0, -3);
// remove the old bundle
fs.unlink(pathToHandlers + '/bundle.' + file, err => {
if (err) {
console.log('Failed to delete old bundle for handler: ' + fnIri);
return console.log(err);
}
// build the new bundle
console.log('Bundle handler: ' + fnIri);
runtime.bundle(fnIri, {}, (err) => {
if (err) {
console.log('Failed to bundle handler: ' + fnIri);
return console.log(err);
}
console.log('Bundle done for handler: ' + fnIri);
});
});
});
} | javascript | function bundleHandler (pathToHandlers, module, file) {
// only rebundle if js file changed
if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
return;
}
// only rebundle if handler was already bundled before
fs.access(pathToHandlers + '/bundle.' + file, err => {
if (err && err.code === 'ENOENT') {
return ;
}
let fnIri = module + '/' + file.slice(0, -3);
// remove the old bundle
fs.unlink(pathToHandlers + '/bundle.' + file, err => {
if (err) {
console.log('Failed to delete old bundle for handler: ' + fnIri);
return console.log(err);
}
// build the new bundle
console.log('Bundle handler: ' + fnIri);
runtime.bundle(fnIri, {}, (err) => {
if (err) {
console.log('Failed to bundle handler: ' + fnIri);
return console.log(err);
}
console.log('Bundle done for handler: ' + fnIri);
});
});
});
} | [
"function",
"bundleHandler",
"(",
"pathToHandlers",
",",
"module",
",",
"file",
")",
"{",
"// only rebundle if js file changed",
"if",
"(",
"file",
".",
"length",
"<",
"3",
"||",
"file",
".",
"indexOf",
"(",
"'bundle.'",
")",
"===",
"0",
"||",
"file",
".",
"substr",
"(",
"file",
".",
"length",
"-",
"3",
")",
"!==",
"'.js'",
")",
"{",
"return",
";",
"}",
"// only rebundle if handler was already bundled before",
"fs",
".",
"access",
"(",
"pathToHandlers",
"+",
"'/bundle.'",
"+",
"file",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"return",
";",
"}",
"let",
"fnIri",
"=",
"module",
"+",
"'/'",
"+",
"file",
".",
"slice",
"(",
"0",
",",
"-",
"3",
")",
";",
"// remove the old bundle",
"fs",
".",
"unlink",
"(",
"pathToHandlers",
"+",
"'/bundle.'",
"+",
"file",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'Failed to delete old bundle for handler: '",
"+",
"fnIri",
")",
";",
"return",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"// build the new bundle",
"console",
".",
"log",
"(",
"'Bundle handler: '",
"+",
"fnIri",
")",
";",
"runtime",
".",
"bundle",
"(",
"fnIri",
",",
"{",
"}",
",",
"(",
"err",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'Failed to bundle handler: '",
"+",
"fnIri",
")",
";",
"return",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"console",
".",
"log",
"(",
"'Bundle done for handler: '",
"+",
"fnIri",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| this will rebundle a handler | [
"this",
"will",
"rebundle",
"a",
"handler"
]
| 4a2b8c462269098fe76551f5adf1acef5ceb1b1c | https://github.com/jillix/flow-registry/blob/4a2b8c462269098fe76551f5adf1acef5ceb1b1c/lib/dev.js#L182-L219 |
45,734 | MikeShi42/rrequire | client/src/index.js | remoteRequest | function remoteRequest(moduleName, methodName, argsArr) {
// TODO: Handle moduleName properly
// TODO: Better ID generation
const id = Math.floor(Math.random() * 10000000);
const serializedRequest = serializer.request(id, methodName, argsArr);
return sendRequest(serializedRequest).then((res) => {
const response = serializer.deserialize(res.text);
if (response.type === 'success') {
return response.payload.result;
} else if (response.type === 'error') {
throw response.payload.error;
} else {
// TODO: Better error handling
throw response;
}
});
} | javascript | function remoteRequest(moduleName, methodName, argsArr) {
// TODO: Handle moduleName properly
// TODO: Better ID generation
const id = Math.floor(Math.random() * 10000000);
const serializedRequest = serializer.request(id, methodName, argsArr);
return sendRequest(serializedRequest).then((res) => {
const response = serializer.deserialize(res.text);
if (response.type === 'success') {
return response.payload.result;
} else if (response.type === 'error') {
throw response.payload.error;
} else {
// TODO: Better error handling
throw response;
}
});
} | [
"function",
"remoteRequest",
"(",
"moduleName",
",",
"methodName",
",",
"argsArr",
")",
"{",
"// TODO: Handle moduleName properly",
"// TODO: Better ID generation",
"const",
"id",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"10000000",
")",
";",
"const",
"serializedRequest",
"=",
"serializer",
".",
"request",
"(",
"id",
",",
"methodName",
",",
"argsArr",
")",
";",
"return",
"sendRequest",
"(",
"serializedRequest",
")",
".",
"then",
"(",
"(",
"res",
")",
"=>",
"{",
"const",
"response",
"=",
"serializer",
".",
"deserialize",
"(",
"res",
".",
"text",
")",
";",
"if",
"(",
"response",
".",
"type",
"===",
"'success'",
")",
"{",
"return",
"response",
".",
"payload",
".",
"result",
";",
"}",
"else",
"if",
"(",
"response",
".",
"type",
"===",
"'error'",
")",
"{",
"throw",
"response",
".",
"payload",
".",
"error",
";",
"}",
"else",
"{",
"// TODO: Better error handling",
"throw",
"response",
";",
"}",
"}",
")",
";",
"}"
]
| Executes a RPC and returns a Promise resolving to the returned value or
rejecting on a client or remote exception.
@param {String} moduleName Full module path to resolve on remote
@param {String} methodName Method name to invoke on remote
@param {Array} argsArr Array of arguments to invoke the remote
method with
@return {Promise} Promise resolving to the return value of the
remote function or rejecting due to
a client or remote exception | [
"Executes",
"a",
"RPC",
"and",
"returns",
"a",
"Promise",
"resolving",
"to",
"the",
"returned",
"value",
"or",
"rejecting",
"on",
"a",
"client",
"or",
"remote",
"exception",
"."
]
| a03ccf84ec0187497d2aa8bd564d5f612e3dc38c | https://github.com/MikeShi42/rrequire/blob/a03ccf84ec0187497d2aa8bd564d5f612e3dc38c/client/src/index.js#L39-L56 |
45,735 | YazgelderRp/abp-electron-resources | Abp/Framework/scripts/libs/abp.jtable.js | function () {
var self = this;
base._create.apply(self, arguments);
if (self.options.actions.listAction) {
self._adaptListActionforAbp();
}
if (self.options.actions.createAction) {
self._adaptCreateActionforAbp();
}
if (self.options.actions.updateAction) {
self._adaptUpdateActionforAbp();
}
if (self.options.actions.deleteAction) {
self._adaptDeleteActionforAbp();
}
} | javascript | function () {
var self = this;
base._create.apply(self, arguments);
if (self.options.actions.listAction) {
self._adaptListActionforAbp();
}
if (self.options.actions.createAction) {
self._adaptCreateActionforAbp();
}
if (self.options.actions.updateAction) {
self._adaptUpdateActionforAbp();
}
if (self.options.actions.deleteAction) {
self._adaptDeleteActionforAbp();
}
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"base",
".",
"_create",
".",
"apply",
"(",
"self",
",",
"arguments",
")",
";",
"if",
"(",
"self",
".",
"options",
".",
"actions",
".",
"listAction",
")",
"{",
"self",
".",
"_adaptListActionforAbp",
"(",
")",
";",
"}",
"if",
"(",
"self",
".",
"options",
".",
"actions",
".",
"createAction",
")",
"{",
"self",
".",
"_adaptCreateActionforAbp",
"(",
")",
";",
"}",
"if",
"(",
"self",
".",
"options",
".",
"actions",
".",
"updateAction",
")",
"{",
"self",
".",
"_adaptUpdateActionforAbp",
"(",
")",
";",
"}",
"if",
"(",
"self",
".",
"options",
".",
"actions",
".",
"deleteAction",
")",
"{",
"self",
".",
"_adaptDeleteActionforAbp",
"(",
")",
";",
"}",
"}"
]
| Override _create function to change actions according to Abp system | [
"Override",
"_create",
"function",
"to",
"change",
"actions",
"according",
"to",
"Abp",
"system"
]
| 0272277a83d71fe1c8821292dd44909d78bd54ec | https://github.com/YazgelderRp/abp-electron-resources/blob/0272277a83d71fe1c8821292dd44909d78bd54ec/Abp/Framework/scripts/libs/abp.jtable.js#L19-L38 |
|
45,736 | YazgelderRp/abp-electron-resources | Abp/Framework/scripts/libs/abp.jtable.js | function () {
var self = this;
var originalListAction = self.options.actions.listAction;
self.options.actions.listAction = function (postData, jtParams) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData, {
skipCount: jtParams.jtStartIndex,
maxResultCount: jtParams.jtPageSize,
sorting: jtParams.jtSorting
});
originalListAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
"Records": result.items || result[originalListAction.recordsField],
"TotalRecordCount": result.totalCount,
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | javascript | function () {
var self = this;
var originalListAction = self.options.actions.listAction;
self.options.actions.listAction = function (postData, jtParams) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData, {
skipCount: jtParams.jtStartIndex,
maxResultCount: jtParams.jtPageSize,
sorting: jtParams.jtSorting
});
originalListAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
"Records": result.items || result[originalListAction.recordsField],
"TotalRecordCount": result.totalCount,
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"originalListAction",
"=",
"self",
".",
"options",
".",
"actions",
".",
"listAction",
";",
"self",
".",
"options",
".",
"actions",
".",
"listAction",
"=",
"function",
"(",
"postData",
",",
"jtParams",
")",
"{",
"return",
"$",
".",
"Deferred",
"(",
"function",
"(",
"$dfd",
")",
"{",
"var",
"input",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"postData",
",",
"{",
"skipCount",
":",
"jtParams",
".",
"jtStartIndex",
",",
"maxResultCount",
":",
"jtParams",
".",
"jtPageSize",
",",
"sorting",
":",
"jtParams",
".",
"jtSorting",
"}",
")",
";",
"originalListAction",
".",
"method",
"(",
"input",
")",
".",
"done",
"(",
"function",
"(",
"result",
")",
"{",
"$dfd",
".",
"resolve",
"(",
"{",
"\"Result\"",
":",
"\"OK\"",
",",
"\"Records\"",
":",
"result",
".",
"items",
"||",
"result",
"[",
"originalListAction",
".",
"recordsField",
"]",
",",
"\"TotalRecordCount\"",
":",
"result",
".",
"totalCount",
",",
"originalResult",
":",
"result",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"self",
".",
"_handlerForFailOnAbpRequest",
"(",
"$dfd",
",",
"error",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"}"
]
| LIST ACTION ADAPTER | [
"LIST",
"ACTION",
"ADAPTER"
]
| 0272277a83d71fe1c8821292dd44909d78bd54ec | https://github.com/YazgelderRp/abp-electron-resources/blob/0272277a83d71fe1c8821292dd44909d78bd54ec/Abp/Framework/scripts/libs/abp.jtable.js#L41-L67 |
|
45,737 | YazgelderRp/abp-electron-resources | Abp/Framework/scripts/libs/abp.jtable.js | function () {
var self = this;
var originalCreateAction = self.options.actions.createAction;
self.options.actions.createAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalCreateAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
"Record": originalCreateAction.recordField ? result[originalCreateAction.recordField] : result,
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | javascript | function () {
var self = this;
var originalCreateAction = self.options.actions.createAction;
self.options.actions.createAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalCreateAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
"Record": originalCreateAction.recordField ? result[originalCreateAction.recordField] : result,
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"originalCreateAction",
"=",
"self",
".",
"options",
".",
"actions",
".",
"createAction",
";",
"self",
".",
"options",
".",
"actions",
".",
"createAction",
"=",
"function",
"(",
"postData",
")",
"{",
"return",
"$",
".",
"Deferred",
"(",
"function",
"(",
"$dfd",
")",
"{",
"var",
"input",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"postData",
")",
";",
"originalCreateAction",
".",
"method",
"(",
"input",
")",
".",
"done",
"(",
"function",
"(",
"result",
")",
"{",
"$dfd",
".",
"resolve",
"(",
"{",
"\"Result\"",
":",
"\"OK\"",
",",
"\"Record\"",
":",
"originalCreateAction",
".",
"recordField",
"?",
"result",
"[",
"originalCreateAction",
".",
"recordField",
"]",
":",
"result",
",",
"originalResult",
":",
"result",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"self",
".",
"_handlerForFailOnAbpRequest",
"(",
"$dfd",
",",
"error",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"}"
]
| CREATE ACTION ADAPTER | [
"CREATE",
"ACTION",
"ADAPTER"
]
| 0272277a83d71fe1c8821292dd44909d78bd54ec | https://github.com/YazgelderRp/abp-electron-resources/blob/0272277a83d71fe1c8821292dd44909d78bd54ec/Abp/Framework/scripts/libs/abp.jtable.js#L70-L91 |
|
45,738 | YazgelderRp/abp-electron-resources | Abp/Framework/scripts/libs/abp.jtable.js | function () {
var self = this;
var originalUpdateAction = self.options.actions.updateAction;
self.options.actions.updateAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalUpdateAction.method(input)
.done(function (result) {
var jtableResult = {
"Result": "OK",
originalResult: result
};
if (originalUpdateAction.returnsRecord) {
if (originalUpdateAction.recordField) {
jtableResult.Record = result[originalUpdateAction.recordField];
} else {
jtableResult.Record = result;
}
}
$dfd.resolve(jtableResult);
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | javascript | function () {
var self = this;
var originalUpdateAction = self.options.actions.updateAction;
self.options.actions.updateAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalUpdateAction.method(input)
.done(function (result) {
var jtableResult = {
"Result": "OK",
originalResult: result
};
if (originalUpdateAction.returnsRecord) {
if (originalUpdateAction.recordField) {
jtableResult.Record = result[originalUpdateAction.recordField];
} else {
jtableResult.Record = result;
}
}
$dfd.resolve(jtableResult);
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"originalUpdateAction",
"=",
"self",
".",
"options",
".",
"actions",
".",
"updateAction",
";",
"self",
".",
"options",
".",
"actions",
".",
"updateAction",
"=",
"function",
"(",
"postData",
")",
"{",
"return",
"$",
".",
"Deferred",
"(",
"function",
"(",
"$dfd",
")",
"{",
"var",
"input",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"postData",
")",
";",
"originalUpdateAction",
".",
"method",
"(",
"input",
")",
".",
"done",
"(",
"function",
"(",
"result",
")",
"{",
"var",
"jtableResult",
"=",
"{",
"\"Result\"",
":",
"\"OK\"",
",",
"originalResult",
":",
"result",
"}",
";",
"if",
"(",
"originalUpdateAction",
".",
"returnsRecord",
")",
"{",
"if",
"(",
"originalUpdateAction",
".",
"recordField",
")",
"{",
"jtableResult",
".",
"Record",
"=",
"result",
"[",
"originalUpdateAction",
".",
"recordField",
"]",
";",
"}",
"else",
"{",
"jtableResult",
".",
"Record",
"=",
"result",
";",
"}",
"}",
"$dfd",
".",
"resolve",
"(",
"jtableResult",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"self",
".",
"_handlerForFailOnAbpRequest",
"(",
"$dfd",
",",
"error",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"}"
]
| UPDATE ACTION ADAPTER | [
"UPDATE",
"ACTION",
"ADAPTER"
]
| 0272277a83d71fe1c8821292dd44909d78bd54ec | https://github.com/YazgelderRp/abp-electron-resources/blob/0272277a83d71fe1c8821292dd44909d78bd54ec/Abp/Framework/scripts/libs/abp.jtable.js#L94-L124 |
|
45,739 | YazgelderRp/abp-electron-resources | Abp/Framework/scripts/libs/abp.jtable.js | function () {
var self = this;
var originalDeleteAction = self.options.actions.deleteAction;
self.options.actions.deleteAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalDeleteAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | javascript | function () {
var self = this;
var originalDeleteAction = self.options.actions.deleteAction;
self.options.actions.deleteAction = function (postData) {
return $.Deferred(function ($dfd) {
var input = $.extend({}, postData);
originalDeleteAction.method(input)
.done(function (result) {
$dfd.resolve({
"Result": "OK",
originalResult: result
});
})
.fail(function (error) {
self._handlerForFailOnAbpRequest($dfd, error);
});
});
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"originalDeleteAction",
"=",
"self",
".",
"options",
".",
"actions",
".",
"deleteAction",
";",
"self",
".",
"options",
".",
"actions",
".",
"deleteAction",
"=",
"function",
"(",
"postData",
")",
"{",
"return",
"$",
".",
"Deferred",
"(",
"function",
"(",
"$dfd",
")",
"{",
"var",
"input",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"postData",
")",
";",
"originalDeleteAction",
".",
"method",
"(",
"input",
")",
".",
"done",
"(",
"function",
"(",
"result",
")",
"{",
"$dfd",
".",
"resolve",
"(",
"{",
"\"Result\"",
":",
"\"OK\"",
",",
"originalResult",
":",
"result",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"self",
".",
"_handlerForFailOnAbpRequest",
"(",
"$dfd",
",",
"error",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"}"
]
| DELETE ACTION ADAPTER | [
"DELETE",
"ACTION",
"ADAPTER"
]
| 0272277a83d71fe1c8821292dd44909d78bd54ec | https://github.com/YazgelderRp/abp-electron-resources/blob/0272277a83d71fe1c8821292dd44909d78bd54ec/Abp/Framework/scripts/libs/abp.jtable.js#L127-L147 |
|
45,740 | DScheglov/merest | lib/controllers/options.js | options | function options(req, res) {
res.__apiMethod = 'options';
res.status(200);
res.json(this.urls());
} | javascript | function options(req, res) {
res.__apiMethod = 'options';
res.status(200);
res.json(this.urls());
} | [
"function",
"options",
"(",
"req",
",",
"res",
")",
"{",
"res",
".",
"__apiMethod",
"=",
"'options'",
";",
"res",
".",
"status",
"(",
"200",
")",
";",
"res",
".",
"json",
"(",
"this",
".",
"urls",
"(",
")",
")",
";",
"}"
]
| options - controller that returns urls
@param {express.Request} req the http(s) request
@param {express.Response} res the http(s) response
@param {Function} next the callback should be called if controller fails
@memberof ModelAPIRouter | [
"options",
"-",
"controller",
"that",
"returns",
"urls"
]
| d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/options.js#L12-L16 |
45,741 | ForgeRock/node-openam-agent-cache-mongodb | lib/mongodb-cache.js | MongoCache | function MongoCache(options) {
options = options || {};
var url = options.url || 'http://localhost/openam-agent',
expireAfterSeconds = options.expireAfterSeconds || 60,
collectionName = options.collectionName || 'agentcache';
this.collection = mongodb.MongoClient.connectAsync(url).then(function (db) {
var collection = db.collection(collectionName);
return collection.createIndex('timestamp', {expireAfterSeconds: expireAfterSeconds}).then(function () {
return collection;
});
});
} | javascript | function MongoCache(options) {
options = options || {};
var url = options.url || 'http://localhost/openam-agent',
expireAfterSeconds = options.expireAfterSeconds || 60,
collectionName = options.collectionName || 'agentcache';
this.collection = mongodb.MongoClient.connectAsync(url).then(function (db) {
var collection = db.collection(collectionName);
return collection.createIndex('timestamp', {expireAfterSeconds: expireAfterSeconds}).then(function () {
return collection;
});
});
} | [
"function",
"MongoCache",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"url",
"=",
"options",
".",
"url",
"||",
"'http://localhost/openam-agent'",
",",
"expireAfterSeconds",
"=",
"options",
".",
"expireAfterSeconds",
"||",
"60",
",",
"collectionName",
"=",
"options",
".",
"collectionName",
"||",
"'agentcache'",
";",
"this",
".",
"collection",
"=",
"mongodb",
".",
"MongoClient",
".",
"connectAsync",
"(",
"url",
")",
".",
"then",
"(",
"function",
"(",
"db",
")",
"{",
"var",
"collection",
"=",
"db",
".",
"collection",
"(",
"collectionName",
")",
";",
"return",
"collection",
".",
"createIndex",
"(",
"'timestamp'",
",",
"{",
"expireAfterSeconds",
":",
"expireAfterSeconds",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"collection",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Cache implementation for MongoDB
@extends Cache
@param {object} [options] Options
@param {string} [options.url=http://localhost/openam-agent] MongoDB URL
@param {number} [options.expireAfterSeconds=60] Expiration time in seconds
@param {string} [options.collectionName=agentcache] MongoDB collection name
@example
var mongoCache = new MongoCache({
url: 'mongodb://db.example.com/mydb',
expireAfterSeconds: 600,
collectionName: 'sessions'
});
@constructor | [
"Cache",
"implementation",
"for",
"MongoDB"
]
| 07352fe7c846559b5362c403dc0b444159cae017 | https://github.com/ForgeRock/node-openam-agent-cache-mongodb/blob/07352fe7c846559b5362c403dc0b444159cae017/lib/mongodb-cache.js#L28-L41 |
45,742 | socialally/air | lib/air/append.js | append | function append() {
var i, l = this.length, el, args = this.slice.call(arguments);
function it(node, index) {
// content elements to insert
el.each(function(ins) {
ins = (index < (l - 1)) ? ins.cloneNode(true) : ins;
node.appendChild(ins);
});
}
for(i = 0;i < args.length;i++) {
// wrap content
el = this.air(args[i]);
// matched parent elements (targets)
this.each(it);
}
return this;
} | javascript | function append() {
var i, l = this.length, el, args = this.slice.call(arguments);
function it(node, index) {
// content elements to insert
el.each(function(ins) {
ins = (index < (l - 1)) ? ins.cloneNode(true) : ins;
node.appendChild(ins);
});
}
for(i = 0;i < args.length;i++) {
// wrap content
el = this.air(args[i]);
// matched parent elements (targets)
this.each(it);
}
return this;
} | [
"function",
"append",
"(",
")",
"{",
"var",
"i",
",",
"l",
"=",
"this",
".",
"length",
",",
"el",
",",
"args",
"=",
"this",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"function",
"it",
"(",
"node",
",",
"index",
")",
"{",
"// content elements to insert",
"el",
".",
"each",
"(",
"function",
"(",
"ins",
")",
"{",
"ins",
"=",
"(",
"index",
"<",
"(",
"l",
"-",
"1",
")",
")",
"?",
"ins",
".",
"cloneNode",
"(",
"true",
")",
":",
"ins",
";",
"node",
".",
"appendChild",
"(",
"ins",
")",
";",
"}",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"// wrap content",
"el",
"=",
"this",
".",
"air",
"(",
"args",
"[",
"i",
"]",
")",
";",
"// matched parent elements (targets)",
"this",
".",
"each",
"(",
"it",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Insert content, specified by the parameter, to the end of each
element in the set of matched elements. | [
"Insert",
"content",
"specified",
"by",
"the",
"parameter",
"to",
"the",
"end",
"of",
"each",
"element",
"in",
"the",
"set",
"of",
"matched",
"elements",
"."
]
| a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/append.js#L5-L21 |
45,743 | haraldrudell/nodegod | lib/rotatedstream.js | rotate | function rotate(cb) {
var retryCount
var newName
if (self.writable && didWrite && !rotating) { // we wrote something to the log, and are not in process of rotating
rotating = true
retryCount = 0
newName = getRotatedName()
fs.stat(newName, doesNewNameExist) // see if the new filename already exist
} else end()
function doesNewNameExist(err, stat) {
if (err instanceof Error && err.code === 'ENOENT') { // we can use newName!
buffer = [] // start logging to memory instead of the stream
closeStream('Log rotated to: ' + path.basename(newName) + '\n', renameLog)
} else {
if (!err) { // newFile already exists
if (++retryCount < maxRetry) setTimeout(retry, rotateAttemptWait)
else end(new Error('Renamed logfile exists'))
} else end(err) // some other error
}
}
function retry() {
//** stream.write('retry')
if (self.writable) {
newName = getRotatedName()
fs.stat(newName, doesNewNameExist) // see if the new filename already exist
} else end()
}
function renameLog(err) { // we are in buffer mode, closed stream
if (self.writable && !err) fs.rename(self.filename, newName, createWriteStream)
else flushBuffer(err)
}
function createWriteStream(err) {
if (self.writable && !err)
if (!(err = openStream()))
while (buffer.length && self.writable) {
stream.write(buffer.shift())
}
flushBuffer(err)
}
function flushBuffer(err) {
//** stream.write('flushBuffer')
buffer = null
rotating = false
end(err)
}
function end(err) {
if (!err) {
if (cb) cb()
} else {
emitError(err)
if (cb) cb(err)
}
}
} | javascript | function rotate(cb) {
var retryCount
var newName
if (self.writable && didWrite && !rotating) { // we wrote something to the log, and are not in process of rotating
rotating = true
retryCount = 0
newName = getRotatedName()
fs.stat(newName, doesNewNameExist) // see if the new filename already exist
} else end()
function doesNewNameExist(err, stat) {
if (err instanceof Error && err.code === 'ENOENT') { // we can use newName!
buffer = [] // start logging to memory instead of the stream
closeStream('Log rotated to: ' + path.basename(newName) + '\n', renameLog)
} else {
if (!err) { // newFile already exists
if (++retryCount < maxRetry) setTimeout(retry, rotateAttemptWait)
else end(new Error('Renamed logfile exists'))
} else end(err) // some other error
}
}
function retry() {
//** stream.write('retry')
if (self.writable) {
newName = getRotatedName()
fs.stat(newName, doesNewNameExist) // see if the new filename already exist
} else end()
}
function renameLog(err) { // we are in buffer mode, closed stream
if (self.writable && !err) fs.rename(self.filename, newName, createWriteStream)
else flushBuffer(err)
}
function createWriteStream(err) {
if (self.writable && !err)
if (!(err = openStream()))
while (buffer.length && self.writable) {
stream.write(buffer.shift())
}
flushBuffer(err)
}
function flushBuffer(err) {
//** stream.write('flushBuffer')
buffer = null
rotating = false
end(err)
}
function end(err) {
if (!err) {
if (cb) cb()
} else {
emitError(err)
if (cb) cb(err)
}
}
} | [
"function",
"rotate",
"(",
"cb",
")",
"{",
"var",
"retryCount",
"var",
"newName",
"if",
"(",
"self",
".",
"writable",
"&&",
"didWrite",
"&&",
"!",
"rotating",
")",
"{",
"// we wrote something to the log, and are not in process of rotating",
"rotating",
"=",
"true",
"retryCount",
"=",
"0",
"newName",
"=",
"getRotatedName",
"(",
")",
"fs",
".",
"stat",
"(",
"newName",
",",
"doesNewNameExist",
")",
"// see if the new filename already exist",
"}",
"else",
"end",
"(",
")",
"function",
"doesNewNameExist",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
"&&",
"err",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"// we can use newName!",
"buffer",
"=",
"[",
"]",
"// start logging to memory instead of the stream",
"closeStream",
"(",
"'Log rotated to: '",
"+",
"path",
".",
"basename",
"(",
"newName",
")",
"+",
"'\\n'",
",",
"renameLog",
")",
"}",
"else",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"// newFile already exists",
"if",
"(",
"++",
"retryCount",
"<",
"maxRetry",
")",
"setTimeout",
"(",
"retry",
",",
"rotateAttemptWait",
")",
"else",
"end",
"(",
"new",
"Error",
"(",
"'Renamed logfile exists'",
")",
")",
"}",
"else",
"end",
"(",
"err",
")",
"// some other error",
"}",
"}",
"function",
"retry",
"(",
")",
"{",
"//** stream.write('retry')",
"if",
"(",
"self",
".",
"writable",
")",
"{",
"newName",
"=",
"getRotatedName",
"(",
")",
"fs",
".",
"stat",
"(",
"newName",
",",
"doesNewNameExist",
")",
"// see if the new filename already exist",
"}",
"else",
"end",
"(",
")",
"}",
"function",
"renameLog",
"(",
"err",
")",
"{",
"// we are in buffer mode, closed stream",
"if",
"(",
"self",
".",
"writable",
"&&",
"!",
"err",
")",
"fs",
".",
"rename",
"(",
"self",
".",
"filename",
",",
"newName",
",",
"createWriteStream",
")",
"else",
"flushBuffer",
"(",
"err",
")",
"}",
"function",
"createWriteStream",
"(",
"err",
")",
"{",
"if",
"(",
"self",
".",
"writable",
"&&",
"!",
"err",
")",
"if",
"(",
"!",
"(",
"err",
"=",
"openStream",
"(",
")",
")",
")",
"while",
"(",
"buffer",
".",
"length",
"&&",
"self",
".",
"writable",
")",
"{",
"stream",
".",
"write",
"(",
"buffer",
".",
"shift",
"(",
")",
")",
"}",
"flushBuffer",
"(",
"err",
")",
"}",
"function",
"flushBuffer",
"(",
"err",
")",
"{",
"//** stream.write('flushBuffer')",
"buffer",
"=",
"null",
"rotating",
"=",
"false",
"end",
"(",
"err",
")",
"}",
"function",
"end",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"if",
"(",
"cb",
")",
"cb",
"(",
")",
"}",
"else",
"{",
"emitError",
"(",
"err",
")",
"if",
"(",
"cb",
")",
"cb",
"(",
"err",
")",
"}",
"}",
"}"
]
| rotate the log | [
"rotate",
"the",
"log"
]
| 3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21 | https://github.com/haraldrudell/nodegod/blob/3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21/lib/rotatedstream.js#L114-L174 |
45,744 | onecommons/base | lib/dataForm.js | resolve | function resolve(obj, propstr, default_val){
// special case, no test and assignment needed for optional default_val; we don't mind if default_val is undefined!
// note: eval called on propstr!
var rv;
if(obj === undefined){
rv = default_val;
} else if(obj.hasOwnProperty(propstr)) {
rv = obj[propstr];
} else {
//treat [] as index 0
propstr = propstr.replace(/\[\]/g,'[0]');
// try drilling down complex propstr like 'foo.bar.quux' or array.
try {
//eval like this to enable "with {}" in strict mode (for babel compatibility)
rv = (new Function( "with(this) { return " + propstr + "}")).call(obj);
} catch(e) {
rv = undefined;
}
}
return (rv === undefined ) ? default_val : rv;
} | javascript | function resolve(obj, propstr, default_val){
// special case, no test and assignment needed for optional default_val; we don't mind if default_val is undefined!
// note: eval called on propstr!
var rv;
if(obj === undefined){
rv = default_val;
} else if(obj.hasOwnProperty(propstr)) {
rv = obj[propstr];
} else {
//treat [] as index 0
propstr = propstr.replace(/\[\]/g,'[0]');
// try drilling down complex propstr like 'foo.bar.quux' or array.
try {
//eval like this to enable "with {}" in strict mode (for babel compatibility)
rv = (new Function( "with(this) { return " + propstr + "}")).call(obj);
} catch(e) {
rv = undefined;
}
}
return (rv === undefined ) ? default_val : rv;
} | [
"function",
"resolve",
"(",
"obj",
",",
"propstr",
",",
"default_val",
")",
"{",
"// special case, no test and assignment needed for optional default_val; we don't mind if default_val is undefined!",
"// note: eval called on propstr!",
"var",
"rv",
";",
"if",
"(",
"obj",
"===",
"undefined",
")",
"{",
"rv",
"=",
"default_val",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"propstr",
")",
")",
"{",
"rv",
"=",
"obj",
"[",
"propstr",
"]",
";",
"}",
"else",
"{",
"//treat [] as index 0",
"propstr",
"=",
"propstr",
".",
"replace",
"(",
"/",
"\\[\\]",
"/",
"g",
",",
"'[0]'",
")",
";",
"// try drilling down complex propstr like 'foo.bar.quux' or array.",
"try",
"{",
"//eval like this to enable \"with {}\" in strict mode (for babel compatibility)",
"rv",
"=",
"(",
"new",
"Function",
"(",
"\"with(this) { return \"",
"+",
"propstr",
"+",
"\"}\"",
")",
")",
".",
"call",
"(",
"obj",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"rv",
"=",
"undefined",
";",
"}",
"}",
"return",
"(",
"rv",
"===",
"undefined",
")",
"?",
"default_val",
":",
"rv",
";",
"}"
]
| return value of property in object. | [
"return",
"value",
"of",
"property",
"in",
"object",
"."
]
| 4f35d9f714d0367b0622a3504802363404290246 | https://github.com/onecommons/base/blob/4f35d9f714d0367b0622a3504802363404290246/lib/dataForm.js#L107-L128 |
45,745 | charto/charto-loader | src/extra.js | loadMonaco | function loadMonaco(monaco) {
var deps = [
'vs/editor/editor.main.nls',
'vs/editor/editor.main'
];
charto.monaco = monaco;
// Monaco loader sets exports, then gets confused by them.
exports = void 0;
return(new Promise(function(resolve, reject) {
monaco.require(deps, resolve);
}));
} | javascript | function loadMonaco(monaco) {
var deps = [
'vs/editor/editor.main.nls',
'vs/editor/editor.main'
];
charto.monaco = monaco;
// Monaco loader sets exports, then gets confused by them.
exports = void 0;
return(new Promise(function(resolve, reject) {
monaco.require(deps, resolve);
}));
} | [
"function",
"loadMonaco",
"(",
"monaco",
")",
"{",
"var",
"deps",
"=",
"[",
"'vs/editor/editor.main.nls'",
",",
"'vs/editor/editor.main'",
"]",
";",
"charto",
".",
"monaco",
"=",
"monaco",
";",
"// Monaco loader sets exports, then gets confused by them.",
"exports",
"=",
"void",
"0",
";",
"return",
"(",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"monaco",
".",
"require",
"(",
"deps",
",",
"resolve",
")",
";",
"}",
")",
")",
";",
"}"
]
| Fetch main Monaco bundles. | [
"Fetch",
"main",
"Monaco",
"bundles",
"."
]
| 640ebb383bbda2be388c7c04ba627cb7d4263a0b | https://github.com/charto/charto-loader/blob/640ebb383bbda2be388c7c04ba627cb7d4263a0b/src/extra.js#L61-L75 |
45,746 | zxqfox/pym | lib/pym.js | updateCollected | function updateCollected(err, result) {
if (typeof result !== 'object') {
collection.err = collection.err || new Error('Invalid acrhitect plugin format');
return;
}
collection.err = collection.err || err;
if (!collection.loaded) {
collection.result = result;
collection.loaded = true;
return;
}
for (var i in result) {
if (result.hasOwnProperty(i)) {
if (collection.result.hasOwnProperty(i)) {
collection.err = collection.err || new Error('Service overloading not supported: ' + i);
return;
}
collection.result[i] = result[i];
}
}
} | javascript | function updateCollected(err, result) {
if (typeof result !== 'object') {
collection.err = collection.err || new Error('Invalid acrhitect plugin format');
return;
}
collection.err = collection.err || err;
if (!collection.loaded) {
collection.result = result;
collection.loaded = true;
return;
}
for (var i in result) {
if (result.hasOwnProperty(i)) {
if (collection.result.hasOwnProperty(i)) {
collection.err = collection.err || new Error('Service overloading not supported: ' + i);
return;
}
collection.result[i] = result[i];
}
}
} | [
"function",
"updateCollected",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"typeof",
"result",
"!==",
"'object'",
")",
"{",
"collection",
".",
"err",
"=",
"collection",
".",
"err",
"||",
"new",
"Error",
"(",
"'Invalid acrhitect plugin format'",
")",
";",
"return",
";",
"}",
"collection",
".",
"err",
"=",
"collection",
".",
"err",
"||",
"err",
";",
"if",
"(",
"!",
"collection",
".",
"loaded",
")",
"{",
"collection",
".",
"result",
"=",
"result",
";",
"collection",
".",
"loaded",
"=",
"true",
";",
"return",
";",
"}",
"for",
"(",
"var",
"i",
"in",
"result",
")",
"{",
"if",
"(",
"result",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"if",
"(",
"collection",
".",
"result",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"collection",
".",
"err",
"=",
"collection",
".",
"err",
"||",
"new",
"Error",
"(",
"'Service overloading not supported: '",
"+",
"i",
")",
";",
"return",
";",
"}",
"collection",
".",
"result",
"[",
"i",
"]",
"=",
"result",
"[",
"i",
"]",
";",
"}",
"}",
"}"
]
| update `collection` hash
@param {Error} err
@param {Object} result | [
"update",
"collection",
"hash"
]
| 5a8f62d4b447e17565334baf43127c731fd53dc7 | https://github.com/zxqfox/pym/blob/5a8f62d4b447e17565334baf43127c731fd53dc7/lib/pym.js#L117-L140 |
45,747 | zxqfox/pym | lib/pym.js | _resolvePackageSync | function _resolvePackageSync(base, relativePath) {
var packageJsonPath;
var packagePath;
// try to fetch node package
try {
packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
packagePath = dirname(packageJsonPath);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
// try to resolve package itself
packagePath = _resolvePackagePathSync(base, relativePath);
}
// compiling resolved metadata
var packageJson = packageJsonPath && require(packageJsonPath) || {};
var metadata = packageJson.pym || {};
metadata.interface =
metadata.interface ||
packageJson.pym ? 'pym' :
packageJson.plugin ? 'architect' :
// what 'bout amd?
'commonjs';
// load package itself
var packageMainPath;
var nodeModule;
switch (metadata.interface) {
case 'pym':
packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
nodeModule = require(packageMainPath);
metadata.provides = metadata.provides || nodeModule.provides || [];
metadata.consumes = metadata.consumes || nodeModule.consumes || [];
metadata.packagePath = packagePath;
metadata.exports = nodeModule;
break;
case 'architect':
var pluginData = packageJson.plugin || {};
nodeModule = require(packagePath);
metadata.provides = pluginData.provides || nodeModule.provides || [];
metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
metadata.packagePath = packagePath;
metadata.exports = _wrapToArchitect(nodeModule, metadata);
break;
default:
throw new Error('Unsupported package format ' + relativePath);
}
return metadata;
} | javascript | function _resolvePackageSync(base, relativePath) {
var packageJsonPath;
var packagePath;
// try to fetch node package
try {
packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
packagePath = dirname(packageJsonPath);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
// try to resolve package itself
packagePath = _resolvePackagePathSync(base, relativePath);
}
// compiling resolved metadata
var packageJson = packageJsonPath && require(packageJsonPath) || {};
var metadata = packageJson.pym || {};
metadata.interface =
metadata.interface ||
packageJson.pym ? 'pym' :
packageJson.plugin ? 'architect' :
// what 'bout amd?
'commonjs';
// load package itself
var packageMainPath;
var nodeModule;
switch (metadata.interface) {
case 'pym':
packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
nodeModule = require(packageMainPath);
metadata.provides = metadata.provides || nodeModule.provides || [];
metadata.consumes = metadata.consumes || nodeModule.consumes || [];
metadata.packagePath = packagePath;
metadata.exports = nodeModule;
break;
case 'architect':
var pluginData = packageJson.plugin || {};
nodeModule = require(packagePath);
metadata.provides = pluginData.provides || nodeModule.provides || [];
metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
metadata.packagePath = packagePath;
metadata.exports = _wrapToArchitect(nodeModule, metadata);
break;
default:
throw new Error('Unsupported package format ' + relativePath);
}
return metadata;
} | [
"function",
"_resolvePackageSync",
"(",
"base",
",",
"relativePath",
")",
"{",
"var",
"packageJsonPath",
";",
"var",
"packagePath",
";",
"// try to fetch node package",
"try",
"{",
"packageJsonPath",
"=",
"_resolvePackagePathSync",
"(",
"base",
",",
"PATH",
".",
"join",
"(",
"relativePath",
",",
"'package.json'",
")",
")",
";",
"packagePath",
"=",
"dirname",
"(",
"packageJsonPath",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"!==",
"'ENOENT'",
")",
"{",
"throw",
"err",
";",
"}",
"// try to resolve package itself",
"packagePath",
"=",
"_resolvePackagePathSync",
"(",
"base",
",",
"relativePath",
")",
";",
"}",
"// compiling resolved metadata",
"var",
"packageJson",
"=",
"packageJsonPath",
"&&",
"require",
"(",
"packageJsonPath",
")",
"||",
"{",
"}",
";",
"var",
"metadata",
"=",
"packageJson",
".",
"pym",
"||",
"{",
"}",
";",
"metadata",
".",
"interface",
"=",
"metadata",
".",
"interface",
"||",
"packageJson",
".",
"pym",
"?",
"'pym'",
":",
"packageJson",
".",
"plugin",
"?",
"'architect'",
":",
"// what 'bout amd?",
"'commonjs'",
";",
"// load package itself",
"var",
"packageMainPath",
";",
"var",
"nodeModule",
";",
"switch",
"(",
"metadata",
".",
"interface",
")",
"{",
"case",
"'pym'",
":",
"packageMainPath",
"=",
"PATH",
".",
"join",
"(",
"packagePath",
",",
"metadata",
".",
"main",
"||",
"packageJson",
".",
"main",
")",
";",
"nodeModule",
"=",
"require",
"(",
"packageMainPath",
")",
";",
"metadata",
".",
"provides",
"=",
"metadata",
".",
"provides",
"||",
"nodeModule",
".",
"provides",
"||",
"[",
"]",
";",
"metadata",
".",
"consumes",
"=",
"metadata",
".",
"consumes",
"||",
"nodeModule",
".",
"consumes",
"||",
"[",
"]",
";",
"metadata",
".",
"packagePath",
"=",
"packagePath",
";",
"metadata",
".",
"exports",
"=",
"nodeModule",
";",
"break",
";",
"case",
"'architect'",
":",
"var",
"pluginData",
"=",
"packageJson",
".",
"plugin",
"||",
"{",
"}",
";",
"nodeModule",
"=",
"require",
"(",
"packagePath",
")",
";",
"metadata",
".",
"provides",
"=",
"pluginData",
".",
"provides",
"||",
"nodeModule",
".",
"provides",
"||",
"[",
"]",
";",
"metadata",
".",
"consumes",
"=",
"pluginData",
".",
"consumes",
"||",
"nodeModule",
".",
"consumes",
"||",
"[",
"]",
";",
"metadata",
".",
"packagePath",
"=",
"packagePath",
";",
"metadata",
".",
"exports",
"=",
"_wrapToArchitect",
"(",
"nodeModule",
",",
"metadata",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'Unsupported package format '",
"+",
"relativePath",
")",
";",
"}",
"return",
"metadata",
";",
"}"
]
| Loads a module, getting metadata from either it's package.json
or export object.
@private
@param {string} base
@param {string} relativePath
@returns {Object}
- {string[]} provides
- {string[]} consumes
- {string} packagePath
- {string} | [
"Loads",
"a",
"module",
"getting",
"metadata",
"from",
"either",
"it",
"s",
"package",
".",
"json",
"or",
"export",
"object",
"."
]
| 5a8f62d4b447e17565334baf43127c731fd53dc7 | https://github.com/zxqfox/pym/blob/5a8f62d4b447e17565334baf43127c731fd53dc7/lib/pym.js#L191-L244 |
45,748 | zxqfox/pym | lib/pym.js | _resolvePackagePathSync | function _resolvePackagePathSync(base, relativePath) {
var originalBase = base;
if (!(base in packagePathCache)) {
packagePathCache[base] = {};
}
var cache = packagePathCache[base];
if (relativePath in cache) {
return cache[relativePath];
}
var packagePath;
if (relativePath[0] === '.' || relativePath[0] === '/') {
packagePath = resolve(base, relativePath);
if (existsSync(packagePath)) {
packagePath = realpathSync(packagePath);
cache[relativePath] = packagePath;
return packagePath;
}
} else {
var newBase;
while (base) {
packagePath = resolve(base, 'node_modules', relativePath);
if (existsSync(packagePath)) {
packagePath = realpathSync(packagePath);
cache[relativePath] = packagePath;
return packagePath;
}
newBase = resolve(base, '..');
if (base === newBase) {
break;
}
base = newBase;
}
}
var err = new Error('Can\'t find "' + relativePath + '" relative to "' + originalBase + '"');
err.code = 'ENOENT';
throw err;
} | javascript | function _resolvePackagePathSync(base, relativePath) {
var originalBase = base;
if (!(base in packagePathCache)) {
packagePathCache[base] = {};
}
var cache = packagePathCache[base];
if (relativePath in cache) {
return cache[relativePath];
}
var packagePath;
if (relativePath[0] === '.' || relativePath[0] === '/') {
packagePath = resolve(base, relativePath);
if (existsSync(packagePath)) {
packagePath = realpathSync(packagePath);
cache[relativePath] = packagePath;
return packagePath;
}
} else {
var newBase;
while (base) {
packagePath = resolve(base, 'node_modules', relativePath);
if (existsSync(packagePath)) {
packagePath = realpathSync(packagePath);
cache[relativePath] = packagePath;
return packagePath;
}
newBase = resolve(base, '..');
if (base === newBase) {
break;
}
base = newBase;
}
}
var err = new Error('Can\'t find "' + relativePath + '" relative to "' + originalBase + '"');
err.code = 'ENOENT';
throw err;
} | [
"function",
"_resolvePackagePathSync",
"(",
"base",
",",
"relativePath",
")",
"{",
"var",
"originalBase",
"=",
"base",
";",
"if",
"(",
"!",
"(",
"base",
"in",
"packagePathCache",
")",
")",
"{",
"packagePathCache",
"[",
"base",
"]",
"=",
"{",
"}",
";",
"}",
"var",
"cache",
"=",
"packagePathCache",
"[",
"base",
"]",
";",
"if",
"(",
"relativePath",
"in",
"cache",
")",
"{",
"return",
"cache",
"[",
"relativePath",
"]",
";",
"}",
"var",
"packagePath",
";",
"if",
"(",
"relativePath",
"[",
"0",
"]",
"===",
"'.'",
"||",
"relativePath",
"[",
"0",
"]",
"===",
"'/'",
")",
"{",
"packagePath",
"=",
"resolve",
"(",
"base",
",",
"relativePath",
")",
";",
"if",
"(",
"existsSync",
"(",
"packagePath",
")",
")",
"{",
"packagePath",
"=",
"realpathSync",
"(",
"packagePath",
")",
";",
"cache",
"[",
"relativePath",
"]",
"=",
"packagePath",
";",
"return",
"packagePath",
";",
"}",
"}",
"else",
"{",
"var",
"newBase",
";",
"while",
"(",
"base",
")",
"{",
"packagePath",
"=",
"resolve",
"(",
"base",
",",
"'node_modules'",
",",
"relativePath",
")",
";",
"if",
"(",
"existsSync",
"(",
"packagePath",
")",
")",
"{",
"packagePath",
"=",
"realpathSync",
"(",
"packagePath",
")",
";",
"cache",
"[",
"relativePath",
"]",
"=",
"packagePath",
";",
"return",
"packagePath",
";",
"}",
"newBase",
"=",
"resolve",
"(",
"base",
",",
"'..'",
")",
";",
"if",
"(",
"base",
"===",
"newBase",
")",
"{",
"break",
";",
"}",
"base",
"=",
"newBase",
";",
"}",
"}",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Can\\'t find \"'",
"+",
"relativePath",
"+",
"'\" relative to \"'",
"+",
"originalBase",
"+",
"'\"'",
")",
";",
"err",
".",
"code",
"=",
"'ENOENT'",
";",
"throw",
"err",
";",
"}"
]
| Node style package resolving so that plugins' package.json can be found relative to the config file
It's not the full node require system algorithm, but it's the 99% case
This throws, make sure to wrap in try..catch
@private
@param {string} base - base path
@param {string} relativePath | [
"Node",
"style",
"package",
"resolving",
"so",
"that",
"plugins",
"package",
".",
"json",
"can",
"be",
"found",
"relative",
"to",
"the",
"config",
"file",
"It",
"s",
"not",
"the",
"full",
"node",
"require",
"system",
"algorithm",
"but",
"it",
"s",
"the",
"99%",
"case",
"This",
"throws",
"make",
"sure",
"to",
"wrap",
"in",
"try",
"..",
"catch"
]
| 5a8f62d4b447e17565334baf43127c731fd53dc7 | https://github.com/zxqfox/pym/blob/5a8f62d4b447e17565334baf43127c731fd53dc7/lib/pym.js#L259-L298 |
45,749 | whitelizard/extended-ds-client | src/index.js | _$updateRecord | function _$updateRecord(name, obj, mode = 'shallow', lockedKeys = [], protectedKeys = []) {
if (!Object.keys(updateModes).includes(mode)) throw new TypeError('Unsupported mode');
lockedKeys.push(this.datasetRecordIdKey);
if (mode === 'shallow') return this.record._$updateRecordShallowP(name, obj, lockedKeys);
if (mode === 'overwrite') {
return this.record._$updateRecordOverwriteP(name, obj, lockedKeys, protectedKeys);
}
if (mode === 'removeKeys') {
return this.record._$updateRecordRemoveKeysP(name, obj, lockedKeys, protectedKeys);
}
return this.record._$updateRecordDeepP(name, obj, mode, lockedKeys);
} | javascript | function _$updateRecord(name, obj, mode = 'shallow', lockedKeys = [], protectedKeys = []) {
if (!Object.keys(updateModes).includes(mode)) throw new TypeError('Unsupported mode');
lockedKeys.push(this.datasetRecordIdKey);
if (mode === 'shallow') return this.record._$updateRecordShallowP(name, obj, lockedKeys);
if (mode === 'overwrite') {
return this.record._$updateRecordOverwriteP(name, obj, lockedKeys, protectedKeys);
}
if (mode === 'removeKeys') {
return this.record._$updateRecordRemoveKeysP(name, obj, lockedKeys, protectedKeys);
}
return this.record._$updateRecordDeepP(name, obj, mode, lockedKeys);
} | [
"function",
"_$updateRecord",
"(",
"name",
",",
"obj",
",",
"mode",
"=",
"'shallow'",
",",
"lockedKeys",
"=",
"[",
"]",
",",
"protectedKeys",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"updateModes",
")",
".",
"includes",
"(",
"mode",
")",
")",
"throw",
"new",
"TypeError",
"(",
"'Unsupported mode'",
")",
";",
"lockedKeys",
".",
"push",
"(",
"this",
".",
"datasetRecordIdKey",
")",
";",
"if",
"(",
"mode",
"===",
"'shallow'",
")",
"return",
"this",
".",
"record",
".",
"_$updateRecordShallowP",
"(",
"name",
",",
"obj",
",",
"lockedKeys",
")",
";",
"if",
"(",
"mode",
"===",
"'overwrite'",
")",
"{",
"return",
"this",
".",
"record",
".",
"_$updateRecordOverwriteP",
"(",
"name",
",",
"obj",
",",
"lockedKeys",
",",
"protectedKeys",
")",
";",
"}",
"if",
"(",
"mode",
"===",
"'removeKeys'",
")",
"{",
"return",
"this",
".",
"record",
".",
"_$updateRecordRemoveKeysP",
"(",
"name",
",",
"obj",
",",
"lockedKeys",
",",
"protectedKeys",
")",
";",
"}",
"return",
"this",
".",
"record",
".",
"_$updateRecordDeepP",
"(",
"name",
",",
"obj",
",",
"mode",
",",
"lockedKeys",
")",
";",
"}"
]
| should never be called externally since it is undefined what happens if record does not exist | [
"should",
"never",
"be",
"called",
"externally",
"since",
"it",
"is",
"undefined",
"what",
"happens",
"if",
"record",
"does",
"not",
"exist"
]
| b8a2a79c6c6e45c06bf19fed107d1a251716048c | https://github.com/whitelizard/extended-ds-client/blob/b8a2a79c6c6e45c06bf19fed107d1a251716048c/src/index.js#L227-L238 |
45,750 | chapmanu/hb | lib/services/core/service.js | function(stream, post) {
this._credentials = [];
this._status = {};
this._modules = {
stream: stream || Stream,
post: post || Post
};
} | javascript | function(stream, post) {
this._credentials = [];
this._status = {};
this._modules = {
stream: stream || Stream,
post: post || Post
};
} | [
"function",
"(",
"stream",
",",
"post",
")",
"{",
"this",
".",
"_credentials",
"=",
"[",
"]",
";",
"this",
".",
"_status",
"=",
"{",
"}",
";",
"this",
".",
"_modules",
"=",
"{",
"stream",
":",
"stream",
"||",
"Stream",
",",
"post",
":",
"post",
"||",
"Post",
"}",
";",
"}"
]
| Service
Manages all interactions with a social media service API, including streams, tracking info, etc.
This is a parent class template, meant to be inherited.
@constructor | [
"Service",
"Manages",
"all",
"interactions",
"with",
"a",
"social",
"media",
"service",
"API",
"including",
"streams",
"tracking",
"info",
"etc",
".",
"This",
"is",
"a",
"parent",
"class",
"template",
"meant",
"to",
"be",
"inherited",
"."
]
| 5edd8de89c7c5fdffc3df0c627513889220f7d51 | https://github.com/chapmanu/hb/blob/5edd8de89c7c5fdffc3df0c627513889220f7d51/lib/services/core/service.js#L16-L23 |
|
45,751 | prathamesh7pute/coral | lib/queryConfig.js | QueryConfig | function QueryConfig (req, res, config) {
var sort = req.query.sort
var order = req.query.order
var select = req.query.select
var skip = req.query.skip
var limit = req.query.limit
var page = req.query.page
var perPage = config.perPage || 10
var idAttribute = config.idParam ? req.params[config.idParam] : req.params.idAttribute
var query = config.query || {}
var updateRef = config.updateRef
var conditions = query.conditions || {}
var options = query.options || {}
var fields = query.fields || ''
var subDoc = config.subDoc
var data = req.body
// sort order
if (sort && (order === 'desc' || order === 'descending' || order === '-1')) {
options.sort = '-' + sort
}
if (sort && (order === 'asc' || order === 'ascending' || order === '1')) {
options.sort = sort
}
if (skip) {
options.skip = skip
}
if (limit) {
options.limit = limit
}
// pagination
if (page) {
options.skip = page * perPage
options.limit = perPage
}
// to find unique record for update, remove and findOne
if (idAttribute) {
conditions[config.idAttribute || '_id'] = idAttribute
}
while (subDoc) {
idAttribute = subDoc.idParam ? req.params[subDoc.idParam] : req.params.idAttribute
if (idAttribute) {
subDoc.conditions = {}
subDoc.conditions[subDoc.idAttribute] = idAttribute
}
subDoc = subDoc.subDoc
}
if (select) {
fields = select.replace(/,/g, ' ')
}
return {
conditions: conditions,
subDoc: config.subDoc,
fields: fields,
options: options,
data: data,
callback: callback(req, res, updateRef)
}
} | javascript | function QueryConfig (req, res, config) {
var sort = req.query.sort
var order = req.query.order
var select = req.query.select
var skip = req.query.skip
var limit = req.query.limit
var page = req.query.page
var perPage = config.perPage || 10
var idAttribute = config.idParam ? req.params[config.idParam] : req.params.idAttribute
var query = config.query || {}
var updateRef = config.updateRef
var conditions = query.conditions || {}
var options = query.options || {}
var fields = query.fields || ''
var subDoc = config.subDoc
var data = req.body
// sort order
if (sort && (order === 'desc' || order === 'descending' || order === '-1')) {
options.sort = '-' + sort
}
if (sort && (order === 'asc' || order === 'ascending' || order === '1')) {
options.sort = sort
}
if (skip) {
options.skip = skip
}
if (limit) {
options.limit = limit
}
// pagination
if (page) {
options.skip = page * perPage
options.limit = perPage
}
// to find unique record for update, remove and findOne
if (idAttribute) {
conditions[config.idAttribute || '_id'] = idAttribute
}
while (subDoc) {
idAttribute = subDoc.idParam ? req.params[subDoc.idParam] : req.params.idAttribute
if (idAttribute) {
subDoc.conditions = {}
subDoc.conditions[subDoc.idAttribute] = idAttribute
}
subDoc = subDoc.subDoc
}
if (select) {
fields = select.replace(/,/g, ' ')
}
return {
conditions: conditions,
subDoc: config.subDoc,
fields: fields,
options: options,
data: data,
callback: callback(req, res, updateRef)
}
} | [
"function",
"QueryConfig",
"(",
"req",
",",
"res",
",",
"config",
")",
"{",
"var",
"sort",
"=",
"req",
".",
"query",
".",
"sort",
"var",
"order",
"=",
"req",
".",
"query",
".",
"order",
"var",
"select",
"=",
"req",
".",
"query",
".",
"select",
"var",
"skip",
"=",
"req",
".",
"query",
".",
"skip",
"var",
"limit",
"=",
"req",
".",
"query",
".",
"limit",
"var",
"page",
"=",
"req",
".",
"query",
".",
"page",
"var",
"perPage",
"=",
"config",
".",
"perPage",
"||",
"10",
"var",
"idAttribute",
"=",
"config",
".",
"idParam",
"?",
"req",
".",
"params",
"[",
"config",
".",
"idParam",
"]",
":",
"req",
".",
"params",
".",
"idAttribute",
"var",
"query",
"=",
"config",
".",
"query",
"||",
"{",
"}",
"var",
"updateRef",
"=",
"config",
".",
"updateRef",
"var",
"conditions",
"=",
"query",
".",
"conditions",
"||",
"{",
"}",
"var",
"options",
"=",
"query",
".",
"options",
"||",
"{",
"}",
"var",
"fields",
"=",
"query",
".",
"fields",
"||",
"''",
"var",
"subDoc",
"=",
"config",
".",
"subDoc",
"var",
"data",
"=",
"req",
".",
"body",
"// sort order",
"if",
"(",
"sort",
"&&",
"(",
"order",
"===",
"'desc'",
"||",
"order",
"===",
"'descending'",
"||",
"order",
"===",
"'-1'",
")",
")",
"{",
"options",
".",
"sort",
"=",
"'-'",
"+",
"sort",
"}",
"if",
"(",
"sort",
"&&",
"(",
"order",
"===",
"'asc'",
"||",
"order",
"===",
"'ascending'",
"||",
"order",
"===",
"'1'",
")",
")",
"{",
"options",
".",
"sort",
"=",
"sort",
"}",
"if",
"(",
"skip",
")",
"{",
"options",
".",
"skip",
"=",
"skip",
"}",
"if",
"(",
"limit",
")",
"{",
"options",
".",
"limit",
"=",
"limit",
"}",
"// pagination",
"if",
"(",
"page",
")",
"{",
"options",
".",
"skip",
"=",
"page",
"*",
"perPage",
"options",
".",
"limit",
"=",
"perPage",
"}",
"// to find unique record for update, remove and findOne",
"if",
"(",
"idAttribute",
")",
"{",
"conditions",
"[",
"config",
".",
"idAttribute",
"||",
"'_id'",
"]",
"=",
"idAttribute",
"}",
"while",
"(",
"subDoc",
")",
"{",
"idAttribute",
"=",
"subDoc",
".",
"idParam",
"?",
"req",
".",
"params",
"[",
"subDoc",
".",
"idParam",
"]",
":",
"req",
".",
"params",
".",
"idAttribute",
"if",
"(",
"idAttribute",
")",
"{",
"subDoc",
".",
"conditions",
"=",
"{",
"}",
"subDoc",
".",
"conditions",
"[",
"subDoc",
".",
"idAttribute",
"]",
"=",
"idAttribute",
"}",
"subDoc",
"=",
"subDoc",
".",
"subDoc",
"}",
"if",
"(",
"select",
")",
"{",
"fields",
"=",
"select",
".",
"replace",
"(",
"/",
",",
"/",
"g",
",",
"' '",
")",
"}",
"return",
"{",
"conditions",
":",
"conditions",
",",
"subDoc",
":",
"config",
".",
"subDoc",
",",
"fields",
":",
"fields",
",",
"options",
":",
"options",
",",
"data",
":",
"data",
",",
"callback",
":",
"callback",
"(",
"req",
",",
"res",
",",
"updateRef",
")",
"}",
"}"
]
| returns the process object with the passed data for pagination and sorting | [
"returns",
"the",
"process",
"object",
"with",
"the",
"passed",
"data",
"for",
"pagination",
"and",
"sorting"
]
| 9036255bb67df53a94df0d7d6998f67692cb8c73 | https://github.com/prathamesh7pute/coral/blob/9036255bb67df53a94df0d7d6998f67692cb8c73/lib/queryConfig.js#L48-L114 |
45,752 | Krinkle/node-colorfactory | src/ColorFactory.js | function (color, angle) {
var hsl, color0, color2;
if (!angle) {
angle = 30;
}
hsl = ColorHelper.rgbToHSL(color);
hsl[0] = (hsl[0] + angle) % 360;
color0 = ColorHelper.hslToHexColor(hsl);
color0 = ColorHelper.darken(color0, 8);
color0 = ColorHelper.saturate(color0, -6);
hsl = ColorHelper.rgbToHSL(color);
hsl[0] = (hsl[0] - angle + 360) % 360;
color2 = ColorHelper.hslToHexColor(hsl);
return [color0, color, color2];
} | javascript | function (color, angle) {
var hsl, color0, color2;
if (!angle) {
angle = 30;
}
hsl = ColorHelper.rgbToHSL(color);
hsl[0] = (hsl[0] + angle) % 360;
color0 = ColorHelper.hslToHexColor(hsl);
color0 = ColorHelper.darken(color0, 8);
color0 = ColorHelper.saturate(color0, -6);
hsl = ColorHelper.rgbToHSL(color);
hsl[0] = (hsl[0] - angle + 360) % 360;
color2 = ColorHelper.hslToHexColor(hsl);
return [color0, color, color2];
} | [
"function",
"(",
"color",
",",
"angle",
")",
"{",
"var",
"hsl",
",",
"color0",
",",
"color2",
";",
"if",
"(",
"!",
"angle",
")",
"{",
"angle",
"=",
"30",
";",
"}",
"hsl",
"=",
"ColorHelper",
".",
"rgbToHSL",
"(",
"color",
")",
";",
"hsl",
"[",
"0",
"]",
"=",
"(",
"hsl",
"[",
"0",
"]",
"+",
"angle",
")",
"%",
"360",
";",
"color0",
"=",
"ColorHelper",
".",
"hslToHexColor",
"(",
"hsl",
")",
";",
"color0",
"=",
"ColorHelper",
".",
"darken",
"(",
"color0",
",",
"8",
")",
";",
"color0",
"=",
"ColorHelper",
".",
"saturate",
"(",
"color0",
",",
"-",
"6",
")",
";",
"hsl",
"=",
"ColorHelper",
".",
"rgbToHSL",
"(",
"color",
")",
";",
"hsl",
"[",
"0",
"]",
"=",
"(",
"hsl",
"[",
"0",
"]",
"-",
"angle",
"+",
"360",
")",
"%",
"360",
";",
"color2",
"=",
"ColorHelper",
".",
"hslToHexColor",
"(",
"hsl",
")",
";",
"return",
"[",
"color0",
",",
"color",
",",
"color2",
"]",
";",
"}"
]
| Two adjacent colors on 12-part color wheel | [
"Two",
"adjacent",
"colors",
"on",
"12",
"-",
"part",
"color",
"wheel"
]
| 4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0 | https://github.com/Krinkle/node-colorfactory/blob/4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0/src/ColorFactory.js#L29-L43 |
|
45,753 | Krinkle/node-colorfactory | src/ColorFactory.js | function (startColor, endColor, count) {
var lightness,
hsl = ColorHelper.rgbToHSL(startColor);
if (count === undefined) {
count = endColor;
lightness = hsl[2] - 20 * count;
if (lightness < 0) {
lightness = 100 - hsl[2];
}
endColor = ColorHelper.hslToHexColor([hsl[0], hsl[1], lightness]);
}
return ColorFactory.interpolate(startColor, endColor, count);
} | javascript | function (startColor, endColor, count) {
var lightness,
hsl = ColorHelper.rgbToHSL(startColor);
if (count === undefined) {
count = endColor;
lightness = hsl[2] - 20 * count;
if (lightness < 0) {
lightness = 100 - hsl[2];
}
endColor = ColorHelper.hslToHexColor([hsl[0], hsl[1], lightness]);
}
return ColorFactory.interpolate(startColor, endColor, count);
} | [
"function",
"(",
"startColor",
",",
"endColor",
",",
"count",
")",
"{",
"var",
"lightness",
",",
"hsl",
"=",
"ColorHelper",
".",
"rgbToHSL",
"(",
"startColor",
")",
";",
"if",
"(",
"count",
"===",
"undefined",
")",
"{",
"count",
"=",
"endColor",
";",
"lightness",
"=",
"hsl",
"[",
"2",
"]",
"-",
"20",
"*",
"count",
";",
"if",
"(",
"lightness",
"<",
"0",
")",
"{",
"lightness",
"=",
"100",
"-",
"hsl",
"[",
"2",
"]",
";",
"}",
"endColor",
"=",
"ColorHelper",
".",
"hslToHexColor",
"(",
"[",
"hsl",
"[",
"0",
"]",
",",
"hsl",
"[",
"1",
"]",
",",
"lightness",
"]",
")",
";",
"}",
"return",
"ColorFactory",
".",
"interpolate",
"(",
"startColor",
",",
"endColor",
",",
"count",
")",
";",
"}"
]
| Sequential schemes are suited to ordered data that progress from low to high.
Lightness steps dominate the look of these schemes, with light colors
for low data values to dark colors for high data values.
@param startColor
@param endColor (optional)
@param count | [
"Sequential",
"schemes",
"are",
"suited",
"to",
"ordered",
"data",
"that",
"progress",
"from",
"low",
"to",
"high",
".",
"Lightness",
"steps",
"dominate",
"the",
"look",
"of",
"these",
"schemes",
"with",
"light",
"colors",
"for",
"low",
"data",
"values",
"to",
"dark",
"colors",
"for",
"high",
"data",
"values",
"."
]
| 4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0 | https://github.com/Krinkle/node-colorfactory/blob/4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0/src/ColorFactory.js#L118-L131 |
|
45,754 | wunderbyte/grunt-spiritual-build | tasks/super.js | oncurlyclose | function oncurlyclose(state, curly, suber) {
curly.count--;
if (suber.protostring && curly.count === curly.protocount) {
suber.protostring = null;
}
} | javascript | function oncurlyclose(state, curly, suber) {
curly.count--;
if (suber.protostring && curly.count === curly.protocount) {
suber.protostring = null;
}
} | [
"function",
"oncurlyclose",
"(",
"state",
",",
"curly",
",",
"suber",
")",
"{",
"curly",
".",
"count",
"--",
";",
"if",
"(",
"suber",
".",
"protostring",
"&&",
"curly",
".",
"count",
"===",
"curly",
".",
"protocount",
")",
"{",
"suber",
".",
"protostring",
"=",
"null",
";",
"}",
"}"
]
| Curly brace ends.
@param {State} state
@param {Curly} curly
@param {Super} suber | [
"Curly",
"brace",
"ends",
"."
]
| 6676b699904fe72f899fe7b88871de5ef23a23c3 | https://github.com/wunderbyte/grunt-spiritual-build/blob/6676b699904fe72f899fe7b88871de5ef23a23c3/tasks/super.js#L332-L337 |
45,755 | elliottsj/memoize-id | src/index.js | get | function get(cache, keys) {
if (keys.length === 0) {
return cache.get(sentinel);
}
const [key, ...restKeys] = keys;
const nestedCache = cache.get(key);
if (!nestedCache) {
return undefined;
}
return get(nestedCache, restKeys);
} | javascript | function get(cache, keys) {
if (keys.length === 0) {
return cache.get(sentinel);
}
const [key, ...restKeys] = keys;
const nestedCache = cache.get(key);
if (!nestedCache) {
return undefined;
}
return get(nestedCache, restKeys);
} | [
"function",
"get",
"(",
"cache",
",",
"keys",
")",
"{",
"if",
"(",
"keys",
".",
"length",
"===",
"0",
")",
"{",
"return",
"cache",
".",
"get",
"(",
"sentinel",
")",
";",
"}",
"const",
"[",
"key",
",",
"...",
"restKeys",
"]",
"=",
"keys",
";",
"const",
"nestedCache",
"=",
"cache",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"!",
"nestedCache",
")",
"{",
"return",
"undefined",
";",
"}",
"return",
"get",
"(",
"nestedCache",
",",
"restKeys",
")",
";",
"}"
]
| Get a value from the given cache Map, accessing an inner Map for each value in `keys`.
If a value does not exist, return undefined.
@param {Map} cache The base Map from which to get a value
@param {Array<Any>} keys An array of keys for which nested Maps will be accessed
@return {Any} The value itself | [
"Get",
"a",
"value",
"from",
"the",
"given",
"cache",
"Map",
"accessing",
"an",
"inner",
"Map",
"for",
"each",
"value",
"in",
"keys",
".",
"If",
"a",
"value",
"does",
"not",
"exist",
"return",
"undefined",
"."
]
| 68b8771ada2b678509db31b403d406317003f7ea | https://github.com/elliottsj/memoize-id/blob/68b8771ada2b678509db31b403d406317003f7ea/src/index.js#L12-L22 |
45,756 | hoist/hoist-js | src/hoist.js | DataManager | function DataManager(hoist, type, bucket) {
this.type = type;
this.hoist = hoist;
this.url = hoist._configs.data + "/" + type;
this.bucket = bucket;
} | javascript | function DataManager(hoist, type, bucket) {
this.type = type;
this.hoist = hoist;
this.url = hoist._configs.data + "/" + type;
this.bucket = bucket;
} | [
"function",
"DataManager",
"(",
"hoist",
",",
"type",
",",
"bucket",
")",
"{",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"hoist",
"=",
"hoist",
";",
"this",
".",
"url",
"=",
"hoist",
".",
"_configs",
".",
"data",
"+",
"\"/\"",
"+",
"type",
";",
"this",
".",
"bucket",
"=",
"bucket",
";",
"}"
]
| simple data manager | [
"simple",
"data",
"manager"
]
| 999a2d3cde5e3e6cd70b4d8cf640c1623a002c2b | https://github.com/hoist/hoist-js/blob/999a2d3cde5e3e6cd70b4d8cf640c1623a002c2b/src/hoist.js#L170-L175 |
45,757 | pkgcloud/pkgcloud-bootstrapper | lib/pkgcloud-bootstrapper.js | iterateKeys | function iterateKeys(keys) {
async.forEach(keys, readKey, function (err) {
return err ? callback(err) : callback(null, keyinfo);
});
} | javascript | function iterateKeys(keys) {
async.forEach(keys, readKey, function (err) {
return err ? callback(err) : callback(null, keyinfo);
});
} | [
"function",
"iterateKeys",
"(",
"keys",
")",
"{",
"async",
".",
"forEach",
"(",
"keys",
",",
"readKey",
",",
"function",
"(",
"err",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"null",
",",
"keyinfo",
")",
";",
"}",
")",
";",
"}"
]
| Helper function to iterate the array of keys | [
"Helper",
"function",
"to",
"iterate",
"the",
"array",
"of",
"keys"
]
| 773d75b8ac3744408a9626c9c6161aafea0a33b4 | https://github.com/pkgcloud/pkgcloud-bootstrapper/blob/773d75b8ac3744408a9626c9c6161aafea0a33b4/lib/pkgcloud-bootstrapper.js#L94-L98 |
45,758 | pkgcloud/pkgcloud-bootstrapper | lib/pkgcloud-bootstrapper.js | createDirs | function createDirs(next) {
if (!options.files || !options.files.length) {
return next();
}
self.ssh({
keys: options.keys,
server: options.server,
tunnel: options.tunnel,
remoteUser: options.remoteUser,
commands: ['mkdir -p ' + options.files.map(function (file) {
return path.dirname(file.target);
}).join(' ')]
}).on('error', function (err) {
if (!hasErr) {
hasErr = true;
next(err);
}
}).on('complete', function () {
if (!hasErr) {
next();
}
});
} | javascript | function createDirs(next) {
if (!options.files || !options.files.length) {
return next();
}
self.ssh({
keys: options.keys,
server: options.server,
tunnel: options.tunnel,
remoteUser: options.remoteUser,
commands: ['mkdir -p ' + options.files.map(function (file) {
return path.dirname(file.target);
}).join(' ')]
}).on('error', function (err) {
if (!hasErr) {
hasErr = true;
next(err);
}
}).on('complete', function () {
if (!hasErr) {
next();
}
});
} | [
"function",
"createDirs",
"(",
"next",
")",
"{",
"if",
"(",
"!",
"options",
".",
"files",
"||",
"!",
"options",
".",
"files",
".",
"length",
")",
"{",
"return",
"next",
"(",
")",
";",
"}",
"self",
".",
"ssh",
"(",
"{",
"keys",
":",
"options",
".",
"keys",
",",
"server",
":",
"options",
".",
"server",
",",
"tunnel",
":",
"options",
".",
"tunnel",
",",
"remoteUser",
":",
"options",
".",
"remoteUser",
",",
"commands",
":",
"[",
"'mkdir -p '",
"+",
"options",
".",
"files",
".",
"map",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"path",
".",
"dirname",
"(",
"file",
".",
"target",
")",
";",
"}",
")",
".",
"join",
"(",
"' '",
")",
"]",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"hasErr",
")",
"{",
"hasErr",
"=",
"true",
";",
"next",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"'complete'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"hasErr",
")",
"{",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
]
| 1. Create any remote directories for files that will be uploaded. | [
"1",
".",
"Create",
"any",
"remote",
"directories",
"for",
"files",
"that",
"will",
"be",
"uploaded",
"."
]
| 773d75b8ac3744408a9626c9c6161aafea0a33b4 | https://github.com/pkgcloud/pkgcloud-bootstrapper/blob/773d75b8ac3744408a9626c9c6161aafea0a33b4/lib/pkgcloud-bootstrapper.js#L271-L294 |
45,759 | pkgcloud/pkgcloud-bootstrapper | lib/pkgcloud-bootstrapper.js | uploadFiles | function uploadFiles(next) {
return options.files && options.files.length
? async.forEachSeries(options.files, uploadFile, next)
: next();
} | javascript | function uploadFiles(next) {
return options.files && options.files.length
? async.forEachSeries(options.files, uploadFile, next)
: next();
} | [
"function",
"uploadFiles",
"(",
"next",
")",
"{",
"return",
"options",
".",
"files",
"&&",
"options",
".",
"files",
".",
"length",
"?",
"async",
".",
"forEachSeries",
"(",
"options",
".",
"files",
",",
"uploadFile",
",",
"next",
")",
":",
"next",
"(",
")",
";",
"}"
]
| 2. Upload any required files. | [
"2",
".",
"Upload",
"any",
"required",
"files",
"."
]
| 773d75b8ac3744408a9626c9c6161aafea0a33b4 | https://github.com/pkgcloud/pkgcloud-bootstrapper/blob/773d75b8ac3744408a9626c9c6161aafea0a33b4/lib/pkgcloud-bootstrapper.js#L297-L301 |
45,760 | pkgcloud/pkgcloud-bootstrapper | lib/pkgcloud-bootstrapper.js | bootstrap | function bootstrap(next) {
if (!options.commands || !options.commands.length) {
return next();
}
var hasErr;
self.ssh({
keys: options.keys,
server: options.server,
commands: options.commands,
remoteUser: options.remoteUser,
tunnel: options.tunnel
}).on('error', function (err) {
if (!hasErr) {
hasErr = true;
next(err);
}
}).on('complete', function (server, stdout) {
if (!hasErr) {
next(null, stdout);
}
});
} | javascript | function bootstrap(next) {
if (!options.commands || !options.commands.length) {
return next();
}
var hasErr;
self.ssh({
keys: options.keys,
server: options.server,
commands: options.commands,
remoteUser: options.remoteUser,
tunnel: options.tunnel
}).on('error', function (err) {
if (!hasErr) {
hasErr = true;
next(err);
}
}).on('complete', function (server, stdout) {
if (!hasErr) {
next(null, stdout);
}
});
} | [
"function",
"bootstrap",
"(",
"next",
")",
"{",
"if",
"(",
"!",
"options",
".",
"commands",
"||",
"!",
"options",
".",
"commands",
".",
"length",
")",
"{",
"return",
"next",
"(",
")",
";",
"}",
"var",
"hasErr",
";",
"self",
".",
"ssh",
"(",
"{",
"keys",
":",
"options",
".",
"keys",
",",
"server",
":",
"options",
".",
"server",
",",
"commands",
":",
"options",
".",
"commands",
",",
"remoteUser",
":",
"options",
".",
"remoteUser",
",",
"tunnel",
":",
"options",
".",
"tunnel",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"hasErr",
")",
"{",
"hasErr",
"=",
"true",
";",
"next",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"'complete'",
",",
"function",
"(",
"server",
",",
"stdout",
")",
"{",
"if",
"(",
"!",
"hasErr",
")",
"{",
"next",
"(",
"null",
",",
"stdout",
")",
";",
"}",
"}",
")",
";",
"}"
]
| 3. Bootstrap the server with the appropriate commands. | [
"3",
".",
"Bootstrap",
"the",
"server",
"with",
"the",
"appropriate",
"commands",
"."
]
| 773d75b8ac3744408a9626c9c6161aafea0a33b4 | https://github.com/pkgcloud/pkgcloud-bootstrapper/blob/773d75b8ac3744408a9626c9c6161aafea0a33b4/lib/pkgcloud-bootstrapper.js#L303-L326 |
45,761 | jldec/pub-generator | output.js | fixOutputPaths | function fixOutputPaths(output, files) {
// map directories to use for index files
var dirMap = {};
u.each(files, function(file) {
dirMap[ppath.dirname(file.path)] = true;
// edge case - treat /foo/ as directory too
if (/\/$/.test(file.path) && ppath.dirname(file.path) !== file.path) {
dirMap[file.path] = true;
}
});
// default output file extension is .html
var extension = 'extension' in output ? (output.extension || '') : '.html';
var indexFile = output.indexFile || 'index';
u.each(files, function(file) {
if (dirMap[file.path]) {
debug('index file for %s', file.path);
file.path = ppath.join(file.path, indexFile);
}
if (!/\.[^/]*$/.test(file.path)) {
file.path = file.path + extension;
}
});
} | javascript | function fixOutputPaths(output, files) {
// map directories to use for index files
var dirMap = {};
u.each(files, function(file) {
dirMap[ppath.dirname(file.path)] = true;
// edge case - treat /foo/ as directory too
if (/\/$/.test(file.path) && ppath.dirname(file.path) !== file.path) {
dirMap[file.path] = true;
}
});
// default output file extension is .html
var extension = 'extension' in output ? (output.extension || '') : '.html';
var indexFile = output.indexFile || 'index';
u.each(files, function(file) {
if (dirMap[file.path]) {
debug('index file for %s', file.path);
file.path = ppath.join(file.path, indexFile);
}
if (!/\.[^/]*$/.test(file.path)) {
file.path = file.path + extension;
}
});
} | [
"function",
"fixOutputPaths",
"(",
"output",
",",
"files",
")",
"{",
"// map directories to use for index files",
"var",
"dirMap",
"=",
"{",
"}",
";",
"u",
".",
"each",
"(",
"files",
",",
"function",
"(",
"file",
")",
"{",
"dirMap",
"[",
"ppath",
".",
"dirname",
"(",
"file",
".",
"path",
")",
"]",
"=",
"true",
";",
"// edge case - treat /foo/ as directory too",
"if",
"(",
"/",
"\\/$",
"/",
".",
"test",
"(",
"file",
".",
"path",
")",
"&&",
"ppath",
".",
"dirname",
"(",
"file",
".",
"path",
")",
"!==",
"file",
".",
"path",
")",
"{",
"dirMap",
"[",
"file",
".",
"path",
"]",
"=",
"true",
";",
"}",
"}",
")",
";",
"// default output file extension is .html",
"var",
"extension",
"=",
"'extension'",
"in",
"output",
"?",
"(",
"output",
".",
"extension",
"||",
"''",
")",
":",
"'.html'",
";",
"var",
"indexFile",
"=",
"output",
".",
"indexFile",
"||",
"'index'",
";",
"u",
".",
"each",
"(",
"files",
",",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"dirMap",
"[",
"file",
".",
"path",
"]",
")",
"{",
"debug",
"(",
"'index file for %s'",
",",
"file",
".",
"path",
")",
";",
"file",
".",
"path",
"=",
"ppath",
".",
"join",
"(",
"file",
".",
"path",
",",
"indexFile",
")",
";",
"}",
"if",
"(",
"!",
"/",
"\\.[^/]*$",
"/",
".",
"test",
"(",
"file",
".",
"path",
")",
")",
"{",
"file",
".",
"path",
"=",
"file",
".",
"path",
"+",
"extension",
";",
"}",
"}",
")",
";",
"}"
]
| convert file-paths to 'index' files where necessary | [
"convert",
"file",
"-",
"paths",
"to",
"index",
"files",
"where",
"necessary"
]
| 524081509921ac8cb897753142324d61e10afdf3 | https://github.com/jldec/pub-generator/blob/524081509921ac8cb897753142324d61e10afdf3/output.js#L110-L136 |
45,762 | binduwavell/generator-alfresco-common | lib/maven-archetype-generate.js | addModuleToParentPom | function addModuleToParentPom (parentPomPath, properties, yoFs) {
var pomStr = yoFs.read(parentPomPath);
var pomEditor = mavenPomModule(pomStr);
pomEditor.addModule(properties.artifactId);
yoFs.write(parentPomPath, pomEditor.getPOMString());
} | javascript | function addModuleToParentPom (parentPomPath, properties, yoFs) {
var pomStr = yoFs.read(parentPomPath);
var pomEditor = mavenPomModule(pomStr);
pomEditor.addModule(properties.artifactId);
yoFs.write(parentPomPath, pomEditor.getPOMString());
} | [
"function",
"addModuleToParentPom",
"(",
"parentPomPath",
",",
"properties",
",",
"yoFs",
")",
"{",
"var",
"pomStr",
"=",
"yoFs",
".",
"read",
"(",
"parentPomPath",
")",
";",
"var",
"pomEditor",
"=",
"mavenPomModule",
"(",
"pomStr",
")",
";",
"pomEditor",
".",
"addModule",
"(",
"properties",
".",
"artifactId",
")",
";",
"yoFs",
".",
"write",
"(",
"parentPomPath",
",",
"pomEditor",
".",
"getPOMString",
"(",
")",
")",
";",
"}"
]
| When a child module is instantiated we need to make sure the parent pom references
the child.
@param {!string} parentPomPath
@param {!Object} properties
@param {!Object} yoFs | [
"When",
"a",
"child",
"module",
"is",
"instantiated",
"we",
"need",
"to",
"make",
"sure",
"the",
"parent",
"pom",
"references",
"the",
"child",
"."
]
| d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4 | https://github.com/binduwavell/generator-alfresco-common/blob/d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4/lib/maven-archetype-generate.js#L92-L97 |
45,763 | binduwavell/generator-alfresco-common | lib/maven-archetype-generate.js | processModules | function processModules (resourcesPath, targetPath, directory, modules, parentPomPath, properties, yoFs) {
modules.forEach(module => {
debug('Processing module', module);
var modulePath = path.join(directory, module.dir);
properties.artifactId = pathFiltering.filter(module.dir, properties);
addModuleToParentPom(parentPomPath, properties, yoFs);
var pomPath = copyPom(resourcesPath, targetPath, modulePath, properties, yoFs);
processFileSets(resourcesPath, targetPath, modulePath, module.fileSets, properties, yoFs);
processModules(resourcesPath, targetPath, modulePath, module.modules, pomPath, properties, yoFs);
});
} | javascript | function processModules (resourcesPath, targetPath, directory, modules, parentPomPath, properties, yoFs) {
modules.forEach(module => {
debug('Processing module', module);
var modulePath = path.join(directory, module.dir);
properties.artifactId = pathFiltering.filter(module.dir, properties);
addModuleToParentPom(parentPomPath, properties, yoFs);
var pomPath = copyPom(resourcesPath, targetPath, modulePath, properties, yoFs);
processFileSets(resourcesPath, targetPath, modulePath, module.fileSets, properties, yoFs);
processModules(resourcesPath, targetPath, modulePath, module.modules, pomPath, properties, yoFs);
});
} | [
"function",
"processModules",
"(",
"resourcesPath",
",",
"targetPath",
",",
"directory",
",",
"modules",
",",
"parentPomPath",
",",
"properties",
",",
"yoFs",
")",
"{",
"modules",
".",
"forEach",
"(",
"module",
"=>",
"{",
"debug",
"(",
"'Processing module'",
",",
"module",
")",
";",
"var",
"modulePath",
"=",
"path",
".",
"join",
"(",
"directory",
",",
"module",
".",
"dir",
")",
";",
"properties",
".",
"artifactId",
"=",
"pathFiltering",
".",
"filter",
"(",
"module",
".",
"dir",
",",
"properties",
")",
";",
"addModuleToParentPom",
"(",
"parentPomPath",
",",
"properties",
",",
"yoFs",
")",
";",
"var",
"pomPath",
"=",
"copyPom",
"(",
"resourcesPath",
",",
"targetPath",
",",
"modulePath",
",",
"properties",
",",
"yoFs",
")",
";",
"processFileSets",
"(",
"resourcesPath",
",",
"targetPath",
",",
"modulePath",
",",
"module",
".",
"fileSets",
",",
"properties",
",",
"yoFs",
")",
";",
"processModules",
"(",
"resourcesPath",
",",
"targetPath",
",",
"modulePath",
",",
"module",
".",
"modules",
",",
"pomPath",
",",
"properties",
",",
"yoFs",
")",
";",
"}",
")",
";",
"}"
]
| Given a list of modules, this accounts for the module directory and updates the artifactId
property. Then it copies the module pom.xml, any filesets defined in the module and finally
recuses on any sub-modules.
@param {!string} resourcesPath
@param {!string} targetPath
@param {!string} directory
@param {!Array<{dir: !string, id: !string}>} modules
@param {!string} parentPomPath
@param {!Object} properties
@param {!Object} yoFs | [
"Given",
"a",
"list",
"of",
"modules",
"this",
"accounts",
"for",
"the",
"module",
"directory",
"and",
"updates",
"the",
"artifactId",
"property",
".",
"Then",
"it",
"copies",
"the",
"module",
"pom",
".",
"xml",
"any",
"filesets",
"defined",
"in",
"the",
"module",
"and",
"finally",
"recuses",
"on",
"any",
"sub",
"-",
"modules",
"."
]
| d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4 | https://github.com/binduwavell/generator-alfresco-common/blob/d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4/lib/maven-archetype-generate.js#L214-L224 |
45,764 | binduwavell/generator-alfresco-common | lib/maven-archetype-generate.js | filesFromFileSet | function filesFromFileSet (dirname, fileset) {
if (!fileset.includes || !fileset.includes.length) {
return [];
}
return fileset.includes
.filter(include => !glob.hasMagic(include))
.map(include => path.join(dirname, include));
} | javascript | function filesFromFileSet (dirname, fileset) {
if (!fileset.includes || !fileset.includes.length) {
return [];
}
return fileset.includes
.filter(include => !glob.hasMagic(include))
.map(include => path.join(dirname, include));
} | [
"function",
"filesFromFileSet",
"(",
"dirname",
",",
"fileset",
")",
"{",
"if",
"(",
"!",
"fileset",
".",
"includes",
"||",
"!",
"fileset",
".",
"includes",
".",
"length",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"fileset",
".",
"includes",
".",
"filter",
"(",
"include",
"=>",
"!",
"glob",
".",
"hasMagic",
"(",
"include",
")",
")",
".",
"map",
"(",
"include",
"=>",
"path",
".",
"join",
"(",
"dirname",
",",
"include",
")",
")",
";",
"}"
]
| The includes in a fileset may be globs or they may be individual files.
This extracts all of the individual files and makes them absolute.
@param {!string} dirname
@param {!Array<{includes: Array<string>}>} fileset
@returns {!Array<string>} | [
"The",
"includes",
"in",
"a",
"fileset",
"may",
"be",
"globs",
"or",
"they",
"may",
"be",
"individual",
"files",
".",
"This",
"extracts",
"all",
"of",
"the",
"individual",
"files",
"and",
"makes",
"them",
"absolute",
"."
]
| d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4 | https://github.com/binduwavell/generator-alfresco-common/blob/d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4/lib/maven-archetype-generate.js#L307-L314 |
45,765 | binduwavell/generator-alfresco-common | lib/maven-archetype-generate.js | globsToExcludeFromFileSet | function globsToExcludeFromFileSet (dirname, fileset) {
if (fileset.excludes && fileset.excludes.length) {
return fileset.excludes.map(exclude => '!' + path.join(dirname, exclude));
} else {
return [];
}
} | javascript | function globsToExcludeFromFileSet (dirname, fileset) {
if (fileset.excludes && fileset.excludes.length) {
return fileset.excludes.map(exclude => '!' + path.join(dirname, exclude));
} else {
return [];
}
} | [
"function",
"globsToExcludeFromFileSet",
"(",
"dirname",
",",
"fileset",
")",
"{",
"if",
"(",
"fileset",
".",
"excludes",
"&&",
"fileset",
".",
"excludes",
".",
"length",
")",
"{",
"return",
"fileset",
".",
"excludes",
".",
"map",
"(",
"exclude",
"=>",
"'!'",
"+",
"path",
".",
"join",
"(",
"dirname",
",",
"exclude",
")",
")",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
]
| The excludes in a fileset are all treated as globs. This extracts all of
them and makes them absolute.
@param {!string} dirname
@param {Array<{excludes: Array<string>}>} fileset
@returns {Array<string>} | [
"The",
"excludes",
"in",
"a",
"fileset",
"are",
"all",
"treated",
"as",
"globs",
".",
"This",
"extracts",
"all",
"of",
"them",
"and",
"makes",
"them",
"absolute",
"."
]
| d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4 | https://github.com/binduwavell/generator-alfresco-common/blob/d9ba309a1b1d26a97268a07a49ac9e5d86b31dc4/lib/maven-archetype-generate.js#L341-L347 |
45,766 | socialally/air | lib/air/filter.js | filter | function filter(selector) {
var arr = [], $ = this.air;
this.each(function(el) {
var selections;
if(typeof selector === 'function') {
if(selector.call(el)) {
arr.push(el);
}
}else{
selections = $(selector);
if(~selections.dom.indexOf(el)) {
arr.push(el);
}
}
});
return $(arr);
} | javascript | function filter(selector) {
var arr = [], $ = this.air;
this.each(function(el) {
var selections;
if(typeof selector === 'function') {
if(selector.call(el)) {
arr.push(el);
}
}else{
selections = $(selector);
if(~selections.dom.indexOf(el)) {
arr.push(el);
}
}
});
return $(arr);
} | [
"function",
"filter",
"(",
"selector",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
",",
"$",
"=",
"this",
".",
"air",
";",
"this",
".",
"each",
"(",
"function",
"(",
"el",
")",
"{",
"var",
"selections",
";",
"if",
"(",
"typeof",
"selector",
"===",
"'function'",
")",
"{",
"if",
"(",
"selector",
".",
"call",
"(",
"el",
")",
")",
"{",
"arr",
".",
"push",
"(",
"el",
")",
";",
"}",
"}",
"else",
"{",
"selections",
"=",
"$",
"(",
"selector",
")",
";",
"if",
"(",
"~",
"selections",
".",
"dom",
".",
"indexOf",
"(",
"el",
")",
")",
"{",
"arr",
".",
"push",
"(",
"el",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"$",
"(",
"arr",
")",
";",
"}"
]
| Reduce the set of matched elements to those that match the selector
or pass the function's test. | [
"Reduce",
"the",
"set",
"of",
"matched",
"elements",
"to",
"those",
"that",
"match",
"the",
"selector",
"or",
"pass",
"the",
"function",
"s",
"test",
"."
]
| a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/filter.js#L5-L21 |
45,767 | charto/charto-loader | src/loader.js | exec | function exec() {
var result;
while(scripts.length) {
var script = scripts.shift();
if(typeof(script) == 'function') {
result = script();
if(result && typeof(result) == 'object' && typeof(result.then) == 'function') {
result.then(exec);
break;
}
} else {
eval(script);
}
}
} | javascript | function exec() {
var result;
while(scripts.length) {
var script = scripts.shift();
if(typeof(script) == 'function') {
result = script();
if(result && typeof(result) == 'object' && typeof(result.then) == 'function') {
result.then(exec);
break;
}
} else {
eval(script);
}
}
} | [
"function",
"exec",
"(",
")",
"{",
"var",
"result",
";",
"while",
"(",
"scripts",
".",
"length",
")",
"{",
"var",
"script",
"=",
"scripts",
".",
"shift",
"(",
")",
";",
"if",
"(",
"typeof",
"(",
"script",
")",
"==",
"'function'",
")",
"{",
"result",
"=",
"script",
"(",
")",
";",
"if",
"(",
"result",
"&&",
"typeof",
"(",
"result",
")",
"==",
"'object'",
"&&",
"typeof",
"(",
"result",
".",
"then",
")",
"==",
"'function'",
")",
"{",
"result",
".",
"then",
"(",
"exec",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"eval",
"(",
"script",
")",
";",
"}",
"}",
"}"
]
| Try to load a single module from multiple possible addresses.
@param { number } num - Index of module in deps to maintain order.
@param { string } key - Key for successfully resolved address cache.
@param { string[] } urls - Addresses in order of decreasing preference. | [
"Try",
"to",
"load",
"a",
"single",
"module",
"from",
"multiple",
"possible",
"addresses",
"."
]
| 640ebb383bbda2be388c7c04ba627cb7d4263a0b | https://github.com/charto/charto-loader/blob/640ebb383bbda2be388c7c04ba627cb7d4263a0b/src/loader.js#L190-L205 |
45,768 | owstack/btc-wallet-service | lib/server.js | WalletService | function WalletService() {
if (!initialized)
throw new Error('Server not initialized');
this.lock = lock;
this.storage = storage;
this.blockchainExplorer = blockchainExplorer;
this.blockchainExplorerOpts = blockchainExplorerOpts;
this.messageBroker = messageBroker;
this.fiatRateService = fiatRateService;
this.notifyTicker = 0;
} | javascript | function WalletService() {
if (!initialized)
throw new Error('Server not initialized');
this.lock = lock;
this.storage = storage;
this.blockchainExplorer = blockchainExplorer;
this.blockchainExplorerOpts = blockchainExplorerOpts;
this.messageBroker = messageBroker;
this.fiatRateService = fiatRateService;
this.notifyTicker = 0;
} | [
"function",
"WalletService",
"(",
")",
"{",
"if",
"(",
"!",
"initialized",
")",
"throw",
"new",
"Error",
"(",
"'Server not initialized'",
")",
";",
"this",
".",
"lock",
"=",
"lock",
";",
"this",
".",
"storage",
"=",
"storage",
";",
"this",
".",
"blockchainExplorer",
"=",
"blockchainExplorer",
";",
"this",
".",
"blockchainExplorerOpts",
"=",
"blockchainExplorerOpts",
";",
"this",
".",
"messageBroker",
"=",
"messageBroker",
";",
"this",
".",
"fiatRateService",
"=",
"fiatRateService",
";",
"this",
".",
"notifyTicker",
"=",
"0",
";",
"}"
]
| Creates an instance of the Btc Wallet Service.
@constructor | [
"Creates",
"an",
"instance",
"of",
"the",
"Btc",
"Wallet",
"Service",
"."
]
| 1c5f30621fd18794a7795bdc56f027cdaf593616 | https://github.com/owstack/btc-wallet-service/blob/1c5f30621fd18794a7795bdc56f027cdaf593616/lib/server.js#L49-L60 |
45,769 | nodejitsu/contour | pagelets/nodejitsu/analytics/base.js | initialize | function initialize() {
switch (this.type) {
case 'ga':
ga('create', this.key, this.domain);
ga('send', 'pageview');
break;
case 'segment':
default:
window.analytics.load(this.key);
window.analytics.page();
break;
}
} | javascript | function initialize() {
switch (this.type) {
case 'ga':
ga('create', this.key, this.domain);
ga('send', 'pageview');
break;
case 'segment':
default:
window.analytics.load(this.key);
window.analytics.page();
break;
}
} | [
"function",
"initialize",
"(",
")",
"{",
"switch",
"(",
"this",
".",
"type",
")",
"{",
"case",
"'ga'",
":",
"ga",
"(",
"'create'",
",",
"this",
".",
"key",
",",
"this",
".",
"domain",
")",
";",
"ga",
"(",
"'send'",
",",
"'pageview'",
")",
";",
"break",
";",
"case",
"'segment'",
":",
"default",
":",
"window",
".",
"analytics",
".",
"load",
"(",
"this",
".",
"key",
")",
";",
"window",
".",
"analytics",
".",
"page",
"(",
")",
";",
"break",
";",
"}",
"}"
]
| After initialization, load the required analytics stack.
@api private | [
"After",
"initialization",
"load",
"the",
"required",
"analytics",
"stack",
"."
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/nodejitsu/analytics/base.js#L33-L46 |
45,770 | nodejitsu/contour | pagelets/nodejitsu/analytics/base.js | map | function map(data) {
var result = {}
, i = this.properties.length;
while (i--) result[this.properties[i]] = data[i];
return result;
} | javascript | function map(data) {
var result = {}
, i = this.properties.length;
while (i--) result[this.properties[i]] = data[i];
return result;
} | [
"function",
"map",
"(",
"data",
")",
"{",
"var",
"result",
"=",
"{",
"}",
",",
"i",
"=",
"this",
".",
"properties",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"result",
"[",
"this",
".",
"properties",
"[",
"i",
"]",
"]",
"=",
"data",
"[",
"i",
"]",
";",
"return",
"result",
";",
"}"
]
| Map data to properties in consequtive order.
@param {Array} data collection
@api private | [
"Map",
"data",
"to",
"properties",
"in",
"consequtive",
"order",
"."
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/nodejitsu/analytics/base.js#L65-L71 |
45,771 | nodejitsu/contour | pagelets/nodejitsu/analytics/base.js | log | function log(e) {
var data = $(e.element).get('track').split(';');
// Revenue only allows numbers remove it if it is not a number.
if ('number' !== typeof data[3]) data.splice(3);
analytics.track(data.splice(0, 1), this.map(data));
} | javascript | function log(e) {
var data = $(e.element).get('track').split(';');
// Revenue only allows numbers remove it if it is not a number.
if ('number' !== typeof data[3]) data.splice(3);
analytics.track(data.splice(0, 1), this.map(data));
} | [
"function",
"log",
"(",
"e",
")",
"{",
"var",
"data",
"=",
"$",
"(",
"e",
".",
"element",
")",
".",
"get",
"(",
"'track'",
")",
".",
"split",
"(",
"';'",
")",
";",
"// Revenue only allows numbers remove it if it is not a number.",
"if",
"(",
"'number'",
"!==",
"typeof",
"data",
"[",
"3",
"]",
")",
"data",
".",
"splice",
"(",
"3",
")",
";",
"analytics",
".",
"track",
"(",
"data",
".",
"splice",
"(",
"0",
",",
"1",
")",
",",
"this",
".",
"map",
"(",
"data",
")",
")",
";",
"}"
]
| Track event and send it to segment.io, mapping data to properties.
@param {Event} e
@api private | [
"Track",
"event",
"and",
"send",
"it",
"to",
"segment",
".",
"io",
"mapping",
"data",
"to",
"properties",
"."
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/nodejitsu/analytics/base.js#L79-L85 |
45,772 | nodejitsu/contour | pagelets/nodejitsu/analytics/base.js | google | function google(e) {
var tracker = this.tracking.ga;
if (!tracker) return;
ga(function done() {
ga.getByName(tracker).send.apply(
tracker,
[ 'event' ].concat($(e.element).get('track').split(';'))
);
});
} | javascript | function google(e) {
var tracker = this.tracking.ga;
if (!tracker) return;
ga(function done() {
ga.getByName(tracker).send.apply(
tracker,
[ 'event' ].concat($(e.element).get('track').split(';'))
);
});
} | [
"function",
"google",
"(",
"e",
")",
"{",
"var",
"tracker",
"=",
"this",
".",
"tracking",
".",
"ga",
";",
"if",
"(",
"!",
"tracker",
")",
"return",
";",
"ga",
"(",
"function",
"done",
"(",
")",
"{",
"ga",
".",
"getByName",
"(",
"tracker",
")",
".",
"send",
".",
"apply",
"(",
"tracker",
",",
"[",
"'event'",
"]",
".",
"concat",
"(",
"$",
"(",
"e",
".",
"element",
")",
".",
"get",
"(",
"'track'",
")",
".",
"split",
"(",
"';'",
")",
")",
")",
";",
"}",
")",
";",
"}"
]
| Track the event and send beacon to all remaining trackers.
@param {Event} e
@api private | [
"Track",
"the",
"event",
"and",
"send",
"beacon",
"to",
"all",
"remaining",
"trackers",
"."
]
| 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/nodejitsu/analytics/base.js#L93-L103 |
45,773 | moqada/github-contribution-stats | src/index.js | fetchGitHub | function fetchGitHub(url) {
return fetch(url).then(res => {
if (res.status === STATUS_NOT_FOUND) {
throw new Error('USER_NOT_FOUND');
} else if (res.status !== STATUS_OK) {
throw new Error('CANNOT_FETCH_DATA');
}
return res.text();
});
} | javascript | function fetchGitHub(url) {
return fetch(url).then(res => {
if (res.status === STATUS_NOT_FOUND) {
throw new Error('USER_NOT_FOUND');
} else if (res.status !== STATUS_OK) {
throw new Error('CANNOT_FETCH_DATA');
}
return res.text();
});
} | [
"function",
"fetchGitHub",
"(",
"url",
")",
"{",
"return",
"fetch",
"(",
"url",
")",
".",
"then",
"(",
"res",
"=>",
"{",
"if",
"(",
"res",
".",
"status",
"===",
"STATUS_NOT_FOUND",
")",
"{",
"throw",
"new",
"Error",
"(",
"'USER_NOT_FOUND'",
")",
";",
"}",
"else",
"if",
"(",
"res",
".",
"status",
"!==",
"STATUS_OK",
")",
"{",
"throw",
"new",
"Error",
"(",
"'CANNOT_FETCH_DATA'",
")",
";",
"}",
"return",
"res",
".",
"text",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Fetch HTML from GitHub
@param {string} url - URL
@return {Promise<string, Error>} | [
"Fetch",
"HTML",
"from",
"GitHub"
]
| 0c5d07889c030ed699527e4c61a9763e794a9be0 | https://github.com/moqada/github-contribution-stats/blob/0c5d07889c030ed699527e4c61a9763e794a9be0/src/index.js#L91-L100 |
45,774 | moqada/github-contribution-stats | src/index.js | getStreaks | function getStreaks(contributions) {
const start = contributions[0].date;
const end = contributions.slice(-1)[0].date;
const streak = {days: 0, start: null, end: null, unmeasurable: false};
let currentStreak = Object.assign({}, streak);
let longestStreak = Object.assign({}, streak);
contributions.forEach(ret => {
if (ret.count > 0) {
currentStreak.days += 1;
currentStreak.end = ret.date;
if (!currentStreak.start) {
currentStreak.start = ret.date;
}
if (currentStreak.days >= longestStreak.days) {
longestStreak = Object.assign({}, currentStreak);
}
} else if (ret.date !== end) {
currentStreak = Object.assign({}, streak);
}
});
if (currentStreak.start === start && currentStreak.end === end) {
currentStreak.unmeasurable = true;
longestStreak.unmeasurable = true;
}
return {currentStreak, longestStreak};
} | javascript | function getStreaks(contributions) {
const start = contributions[0].date;
const end = contributions.slice(-1)[0].date;
const streak = {days: 0, start: null, end: null, unmeasurable: false};
let currentStreak = Object.assign({}, streak);
let longestStreak = Object.assign({}, streak);
contributions.forEach(ret => {
if (ret.count > 0) {
currentStreak.days += 1;
currentStreak.end = ret.date;
if (!currentStreak.start) {
currentStreak.start = ret.date;
}
if (currentStreak.days >= longestStreak.days) {
longestStreak = Object.assign({}, currentStreak);
}
} else if (ret.date !== end) {
currentStreak = Object.assign({}, streak);
}
});
if (currentStreak.start === start && currentStreak.end === end) {
currentStreak.unmeasurable = true;
longestStreak.unmeasurable = true;
}
return {currentStreak, longestStreak};
} | [
"function",
"getStreaks",
"(",
"contributions",
")",
"{",
"const",
"start",
"=",
"contributions",
"[",
"0",
"]",
".",
"date",
";",
"const",
"end",
"=",
"contributions",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
".",
"date",
";",
"const",
"streak",
"=",
"{",
"days",
":",
"0",
",",
"start",
":",
"null",
",",
"end",
":",
"null",
",",
"unmeasurable",
":",
"false",
"}",
";",
"let",
"currentStreak",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"streak",
")",
";",
"let",
"longestStreak",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"streak",
")",
";",
"contributions",
".",
"forEach",
"(",
"ret",
"=>",
"{",
"if",
"(",
"ret",
".",
"count",
">",
"0",
")",
"{",
"currentStreak",
".",
"days",
"+=",
"1",
";",
"currentStreak",
".",
"end",
"=",
"ret",
".",
"date",
";",
"if",
"(",
"!",
"currentStreak",
".",
"start",
")",
"{",
"currentStreak",
".",
"start",
"=",
"ret",
".",
"date",
";",
"}",
"if",
"(",
"currentStreak",
".",
"days",
">=",
"longestStreak",
".",
"days",
")",
"{",
"longestStreak",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"currentStreak",
")",
";",
"}",
"}",
"else",
"if",
"(",
"ret",
".",
"date",
"!==",
"end",
")",
"{",
"currentStreak",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"streak",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"currentStreak",
".",
"start",
"===",
"start",
"&&",
"currentStreak",
".",
"end",
"===",
"end",
")",
"{",
"currentStreak",
".",
"unmeasurable",
"=",
"true",
";",
"longestStreak",
".",
"unmeasurable",
"=",
"true",
";",
"}",
"return",
"{",
"currentStreak",
",",
"longestStreak",
"}",
";",
"}"
]
| Parse data to streak
@param {Array<{date: string, count: number}>} contributions - List of contributions
@return {{currentStreak: Streak, longestStreak: Streak}} | [
"Parse",
"data",
"to",
"streak"
]
| 0c5d07889c030ed699527e4c61a9763e794a9be0 | https://github.com/moqada/github-contribution-stats/blob/0c5d07889c030ed699527e4c61a9763e794a9be0/src/index.js#L109-L134 |
45,775 | moqada/github-contribution-stats | src/index.js | parseCalendar | function parseCalendar($calendar) {
const data = [];
$calendar.find('rect').each((i, elm) => {
const $rect = cheerio(elm);
const date = $rect.attr('data-date');
if (!date) {
return;
}
data.push({
date,
count: parseInt($rect.attr('data-count'), 10)
});
});
return data;
} | javascript | function parseCalendar($calendar) {
const data = [];
$calendar.find('rect').each((i, elm) => {
const $rect = cheerio(elm);
const date = $rect.attr('data-date');
if (!date) {
return;
}
data.push({
date,
count: parseInt($rect.attr('data-count'), 10)
});
});
return data;
} | [
"function",
"parseCalendar",
"(",
"$calendar",
")",
"{",
"const",
"data",
"=",
"[",
"]",
";",
"$calendar",
".",
"find",
"(",
"'rect'",
")",
".",
"each",
"(",
"(",
"i",
",",
"elm",
")",
"=>",
"{",
"const",
"$rect",
"=",
"cheerio",
"(",
"elm",
")",
";",
"const",
"date",
"=",
"$rect",
".",
"attr",
"(",
"'data-date'",
")",
";",
"if",
"(",
"!",
"date",
")",
"{",
"return",
";",
"}",
"data",
".",
"push",
"(",
"{",
"date",
",",
"count",
":",
"parseInt",
"(",
"$rect",
".",
"attr",
"(",
"'data-count'",
")",
",",
"10",
")",
"}",
")",
";",
"}",
")",
";",
"return",
"data",
";",
"}"
]
| Parse HTML to list of contribution
@param {Object} $calendar - cheerio object
@return {Array<{date: string, count: number}>} | [
"Parse",
"HTML",
"to",
"list",
"of",
"contribution"
]
| 0c5d07889c030ed699527e4c61a9763e794a9be0 | https://github.com/moqada/github-contribution-stats/blob/0c5d07889c030ed699527e4c61a9763e794a9be0/src/index.js#L143-L157 |
45,776 | moqada/github-contribution-stats | src/index.js | summarizeContributions | function summarizeContributions(contributions) {
let busiestDay = null;
let total = 0;
contributions.forEach(d => {
if (d.count > 0 && (!busiestDay || d.count > busiestDay.count)) {
busiestDay = d;
}
total += d.count;
});
return {
busiestDay,
end: contributions.slice(-1)[0].date,
start: contributions[0].date,
total
};
} | javascript | function summarizeContributions(contributions) {
let busiestDay = null;
let total = 0;
contributions.forEach(d => {
if (d.count > 0 && (!busiestDay || d.count > busiestDay.count)) {
busiestDay = d;
}
total += d.count;
});
return {
busiestDay,
end: contributions.slice(-1)[0].date,
start: contributions[0].date,
total
};
} | [
"function",
"summarizeContributions",
"(",
"contributions",
")",
"{",
"let",
"busiestDay",
"=",
"null",
";",
"let",
"total",
"=",
"0",
";",
"contributions",
".",
"forEach",
"(",
"d",
"=>",
"{",
"if",
"(",
"d",
".",
"count",
">",
"0",
"&&",
"(",
"!",
"busiestDay",
"||",
"d",
".",
"count",
">",
"busiestDay",
".",
"count",
")",
")",
"{",
"busiestDay",
"=",
"d",
";",
"}",
"total",
"+=",
"d",
".",
"count",
";",
"}",
")",
";",
"return",
"{",
"busiestDay",
",",
"end",
":",
"contributions",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
".",
"date",
",",
"start",
":",
"contributions",
"[",
"0",
"]",
".",
"date",
",",
"total",
"}",
";",
"}"
]
| Summarize list of contribution
@param {Array<{date: string, count: number}>} contributions - List of contribution
@return {{end: string, start: string, total: number, busiestDay: {date: string, count: number}}} | [
"Summarize",
"list",
"of",
"contribution"
]
| 0c5d07889c030ed699527e4c61a9763e794a9be0 | https://github.com/moqada/github-contribution-stats/blob/0c5d07889c030ed699527e4c61a9763e794a9be0/src/index.js#L166-L181 |
45,777 | lucbories/devapt-core-server | src/js/start_node.js | reload_file | function reload_file(arg_file_path)
{
const file_name = path.basename(arg_file_path)
const this_file_name = path.basename(__filename)
if (file_name == this_file_name)
{
console.info('Need to reload after change on ' + this_file_name)
return
}
const exts = ['.js', '.json']
const ext = path.extname(arg_file_path)
const full_path = path.resolve(arg_file_path)
if ((exts.indexOf(ext) > -1) && (full_path in require.cache))
{
console.info('Reloading: ' + full_path)
// console.log(require.cache[full_path].parent.children[0])
delete require.cache[full_path]
require(full_path)
}
} | javascript | function reload_file(arg_file_path)
{
const file_name = path.basename(arg_file_path)
const this_file_name = path.basename(__filename)
if (file_name == this_file_name)
{
console.info('Need to reload after change on ' + this_file_name)
return
}
const exts = ['.js', '.json']
const ext = path.extname(arg_file_path)
const full_path = path.resolve(arg_file_path)
if ((exts.indexOf(ext) > -1) && (full_path in require.cache))
{
console.info('Reloading: ' + full_path)
// console.log(require.cache[full_path].parent.children[0])
delete require.cache[full_path]
require(full_path)
}
} | [
"function",
"reload_file",
"(",
"arg_file_path",
")",
"{",
"const",
"file_name",
"=",
"path",
".",
"basename",
"(",
"arg_file_path",
")",
"const",
"this_file_name",
"=",
"path",
".",
"basename",
"(",
"__filename",
")",
"if",
"(",
"file_name",
"==",
"this_file_name",
")",
"{",
"console",
".",
"info",
"(",
"'Need to reload after change on '",
"+",
"this_file_name",
")",
"return",
"}",
"const",
"exts",
"=",
"[",
"'.js'",
",",
"'.json'",
"]",
"const",
"ext",
"=",
"path",
".",
"extname",
"(",
"arg_file_path",
")",
"const",
"full_path",
"=",
"path",
".",
"resolve",
"(",
"arg_file_path",
")",
"if",
"(",
"(",
"exts",
".",
"indexOf",
"(",
"ext",
")",
">",
"-",
"1",
")",
"&&",
"(",
"full_path",
"in",
"require",
".",
"cache",
")",
")",
"{",
"console",
".",
"info",
"(",
"'Reloading: '",
"+",
"full_path",
")",
"// console.log(require.cache[full_path].parent.children[0])",
"delete",
"require",
".",
"cache",
"[",
"full_path",
"]",
"require",
"(",
"full_path",
")",
"}",
"}"
]
| Reload a file.
@param {string} arg_file_path - file path name.
@returns {nothing} | [
"Reload",
"a",
"file",
"."
]
| 3f11b62e1d967202111b5f54536bbeddfe3443c9 | https://github.com/lucbories/devapt-core-server/blob/3f11b62e1d967202111b5f54536bbeddfe3443c9/src/js/start_node.js#L146-L168 |
45,778 | lucbories/devapt-core-server | src/js/start_node.js | watch | function watch(arg_src_dir)
{
console.info('Watching for change on: ' + arg_src_dir)
const watch_settings = { ignored: /[\/\\]\./, persistent: true }
var watcher = chokidar.watch(arg_src_dir, watch_settings)
watcher.on('change', reload_file)
return watcher
} | javascript | function watch(arg_src_dir)
{
console.info('Watching for change on: ' + arg_src_dir)
const watch_settings = { ignored: /[\/\\]\./, persistent: true }
var watcher = chokidar.watch(arg_src_dir, watch_settings)
watcher.on('change', reload_file)
return watcher
} | [
"function",
"watch",
"(",
"arg_src_dir",
")",
"{",
"console",
".",
"info",
"(",
"'Watching for change on: '",
"+",
"arg_src_dir",
")",
"const",
"watch_settings",
"=",
"{",
"ignored",
":",
"/",
"[\\/\\\\]\\.",
"/",
",",
"persistent",
":",
"true",
"}",
"var",
"watcher",
"=",
"chokidar",
".",
"watch",
"(",
"arg_src_dir",
",",
"watch_settings",
")",
"watcher",
".",
"on",
"(",
"'change'",
",",
"reload_file",
")",
"return",
"watcher",
"}"
]
| Watch directory files.
@param {string} arg_src_dir - source directory.
@returns {object} - watcher object. | [
"Watch",
"directory",
"files",
"."
]
| 3f11b62e1d967202111b5f54536bbeddfe3443c9 | https://github.com/lucbories/devapt-core-server/blob/3f11b62e1d967202111b5f54536bbeddfe3443c9/src/js/start_node.js#L179-L188 |
45,779 | OpenSmartEnvironment/ose | lib/peer/remote.js | rxServer | function rxServer(val) { // {{{2
/**
* Called, when received "server" message as a client.
*/
if (! (
val.space === this.peer.space.name &&
val.peer === this.peer.name
)) {
O.log.error(this, 'This is not the right peer');
this.close();
return;
}
this.rx = rxConfirm;
this.tx({
space: O.here.space.name,
peer: O.here.name,
});
return;
} | javascript | function rxServer(val) { // {{{2
/**
* Called, when received "server" message as a client.
*/
if (! (
val.space === this.peer.space.name &&
val.peer === this.peer.name
)) {
O.log.error(this, 'This is not the right peer');
this.close();
return;
}
this.rx = rxConfirm;
this.tx({
space: O.here.space.name,
peer: O.here.name,
});
return;
} | [
"function",
"rxServer",
"(",
"val",
")",
"{",
"// {{{2",
"/**\n * Called, when received \"server\" message as a client.\n */",
"if",
"(",
"!",
"(",
"val",
".",
"space",
"===",
"this",
".",
"peer",
".",
"space",
".",
"name",
"&&",
"val",
".",
"peer",
"===",
"this",
".",
"peer",
".",
"name",
")",
")",
"{",
"O",
".",
"log",
".",
"error",
"(",
"this",
",",
"'This is not the right peer'",
")",
";",
"this",
".",
"close",
"(",
")",
";",
"return",
";",
"}",
"this",
".",
"rx",
"=",
"rxConfirm",
";",
"this",
".",
"tx",
"(",
"{",
"space",
":",
"O",
".",
"here",
".",
"space",
".",
"name",
",",
"peer",
":",
"O",
".",
"here",
".",
"name",
",",
"}",
")",
";",
"return",
";",
"}"
]
| WS {{{1 All methods are bound to "ws" | [
"WS",
"{{{",
"1",
"All",
"methods",
"are",
"bound",
"to",
"ws"
]
| 2ab051d9db6e77341c40abb9cbdae6ce586917e0 | https://github.com/OpenSmartEnvironment/ose/blob/2ab051d9db6e77341c40abb9cbdae6ce586917e0/lib/peer/remote.js#L419-L440 |
45,780 | vadr-vr/VR-Analytics-JSCore | js/deviceData.js | _setVadrDeviceCookie | function _setVadrDeviceCookie(){
// setting cookie valid for years set in constants
const cookieValidFor = constants.cookieValidForYears;
const deviceCookieName = constants.deviceCookieName;
const currentDate = new Date();
const laterDate = new Date();
laterDate.setFullYear(currentDate.getFullYear() + cookieValidFor);
const deviceId = utils.getToken();
utils.setCookie(deviceCookieName, deviceId, laterDate, false);
return deviceId;
} | javascript | function _setVadrDeviceCookie(){
// setting cookie valid for years set in constants
const cookieValidFor = constants.cookieValidForYears;
const deviceCookieName = constants.deviceCookieName;
const currentDate = new Date();
const laterDate = new Date();
laterDate.setFullYear(currentDate.getFullYear() + cookieValidFor);
const deviceId = utils.getToken();
utils.setCookie(deviceCookieName, deviceId, laterDate, false);
return deviceId;
} | [
"function",
"_setVadrDeviceCookie",
"(",
")",
"{",
"// setting cookie valid for years set in constants",
"const",
"cookieValidFor",
"=",
"constants",
".",
"cookieValidForYears",
";",
"const",
"deviceCookieName",
"=",
"constants",
".",
"deviceCookieName",
";",
"const",
"currentDate",
"=",
"new",
"Date",
"(",
")",
";",
"const",
"laterDate",
"=",
"new",
"Date",
"(",
")",
";",
"laterDate",
".",
"setFullYear",
"(",
"currentDate",
".",
"getFullYear",
"(",
")",
"+",
"cookieValidFor",
")",
";",
"const",
"deviceId",
"=",
"utils",
".",
"getToken",
"(",
")",
";",
"utils",
".",
"setCookie",
"(",
"deviceCookieName",
",",
"deviceId",
",",
"laterDate",
",",
"false",
")",
";",
"return",
"deviceId",
";",
"}"
]
| sets the deviceId to Cookie | [
"sets",
"the",
"deviceId",
"to",
"Cookie"
]
| 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/deviceData.js#L73-L89 |
45,781 | socialally/air | lib/air/remove.js | remove | function remove() {
var i, el;
for(i = 0;i < this.length;i++) {
el = this.dom[i];
// if for some reason this point to the document element
// an exception will occur, pretty hard to reproduce so
// going to let it slide
if(el.parentNode) {
el.parentNode.removeChild(el);
this.dom.splice(i, 1);
i--;
}
}
return this;
} | javascript | function remove() {
var i, el;
for(i = 0;i < this.length;i++) {
el = this.dom[i];
// if for some reason this point to the document element
// an exception will occur, pretty hard to reproduce so
// going to let it slide
if(el.parentNode) {
el.parentNode.removeChild(el);
this.dom.splice(i, 1);
i--;
}
}
return this;
} | [
"function",
"remove",
"(",
")",
"{",
"var",
"i",
",",
"el",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"el",
"=",
"this",
".",
"dom",
"[",
"i",
"]",
";",
"// if for some reason this point to the document element",
"// an exception will occur, pretty hard to reproduce so",
"// going to let it slide",
"if",
"(",
"el",
".",
"parentNode",
")",
"{",
"el",
".",
"parentNode",
".",
"removeChild",
"(",
"el",
")",
";",
"this",
".",
"dom",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"i",
"--",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Remove all matched elements. | [
"Remove",
"all",
"matched",
"elements",
"."
]
| a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/remove.js#L4-L18 |
45,782 | feedhenry/fh-reportingclient | lib/mbaas-reporting.js | getEnvNumericalValue | function getEnvNumericalValue(envValue, defaultVal) {
var limit = defaultVal;
if (envValue) {
limit = parseInt(envValue,10);
if (isNaN(limit)) {
limit = defaultVal;
}
}
return limit;
} | javascript | function getEnvNumericalValue(envValue, defaultVal) {
var limit = defaultVal;
if (envValue) {
limit = parseInt(envValue,10);
if (isNaN(limit)) {
limit = defaultVal;
}
}
return limit;
} | [
"function",
"getEnvNumericalValue",
"(",
"envValue",
",",
"defaultVal",
")",
"{",
"var",
"limit",
"=",
"defaultVal",
";",
"if",
"(",
"envValue",
")",
"{",
"limit",
"=",
"parseInt",
"(",
"envValue",
",",
"10",
")",
";",
"if",
"(",
"isNaN",
"(",
"limit",
")",
")",
"{",
"limit",
"=",
"defaultVal",
";",
"}",
"}",
"return",
"limit",
";",
"}"
]
| parse the value if it is present and if it is not NaN return that else return the default | [
"parse",
"the",
"value",
"if",
"it",
"is",
"present",
"and",
"if",
"it",
"is",
"not",
"NaN",
"return",
"that",
"else",
"return",
"the",
"default"
]
| a0e2c959ce73addbf138d48f3ed46ef87229ae1a | https://github.com/feedhenry/fh-reportingclient/blob/a0e2c959ce73addbf138d48f3ed46ef87229ae1a/lib/mbaas-reporting.js#L10-L19 |
45,783 | vadr-vr/VR-Analytics-JSCore | js/config.js | setApplication | function setApplication(appId, token, version){
appConfig['appId'] = appId;
appConfig['appToken'] = token;
appConfig['version'] = version;
} | javascript | function setApplication(appId, token, version){
appConfig['appId'] = appId;
appConfig['appToken'] = token;
appConfig['version'] = version;
} | [
"function",
"setApplication",
"(",
"appId",
",",
"token",
",",
"version",
")",
"{",
"appConfig",
"[",
"'appId'",
"]",
"=",
"appId",
";",
"appConfig",
"[",
"'appToken'",
"]",
"=",
"token",
";",
"appConfig",
"[",
"'version'",
"]",
"=",
"version",
";",
"}"
]
| Sets the application details such as appId, appToken, version
@memberof ApplicationConfig
@param {string} appId application id provided by vadr
@param {token} token application token provided by vadr
@param {version} version version of application set by developer | [
"Sets",
"the",
"application",
"details",
"such",
"as",
"appId",
"appToken",
"version"
]
| 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/config.js#L27-L33 |
45,784 | mchalapuk/hyper-text-slider | lib/utils/detect-features.js | featureNameFromProperty | function featureNameFromProperty(instance, defaultName, candidateMap) {
for (var key in candidateMap) {
if (typeof instance[key] !== 'undefined') {
return candidateMap[key];
}
}
console.warn('no feature name detected for '+ defaultName +' using default');
return defaultName;
} | javascript | function featureNameFromProperty(instance, defaultName, candidateMap) {
for (var key in candidateMap) {
if (typeof instance[key] !== 'undefined') {
return candidateMap[key];
}
}
console.warn('no feature name detected for '+ defaultName +' using default');
return defaultName;
} | [
"function",
"featureNameFromProperty",
"(",
"instance",
",",
"defaultName",
",",
"candidateMap",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"candidateMap",
")",
"{",
"if",
"(",
"typeof",
"instance",
"[",
"key",
"]",
"!==",
"'undefined'",
")",
"{",
"return",
"candidateMap",
"[",
"key",
"]",
";",
"}",
"}",
"console",
".",
"warn",
"(",
"'no feature name detected for '",
"+",
"defaultName",
"+",
"' using default'",
")",
";",
"return",
"defaultName",
";",
"}"
]
| Detects browser-specific names of browser features by checking availability
of browser-specific properties in given object instance.
@param {Object} instance object that will be checked for existence of properties
@param {String} defaultName name used if nothing else detected (standard-compliant name)
@param {Object} candidateMap browser-specific properties (keys) mapped to feature names (values)
@return {String} value from candidateMap or defaultName | [
"Detects",
"browser",
"-",
"specific",
"names",
"of",
"browser",
"features",
"by",
"checking",
"availability",
"of",
"browser",
"-",
"specific",
"properties",
"in",
"given",
"object",
"instance",
"."
]
| 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/utils/detect-features.js#L54-L63 |
45,785 | stevenvelozo/tidings | source/Tidings-CommonServices.js | function(pDefaultMessage, pError, pRequest, pResponse, fNext)
{
var tmpErrorMessage = pDefaultMessage;
var tmpErrorCode = 1;
var tmpScope = null;
var tmpParams = null;
var tmpSessionID = null;
if (typeof(pError) === 'object')
{
tmpErrorMessage = pError.Message;
if (pError.Code)
tmpErrorCode = pError.Code;
}
else if (typeof(pError) === 'string')
{
tmpErrorMessage += ' ' + pError;
}
if (pRequest.DAL)
{
tmpScope = pRequest.DAL.scope;
}
if (pRequest.params)
{
tmpParams = pRequest.params;
}
if (pRequest.UserSession)
{
tmpSessionID = pRequest.UserSession.SessionID;
}
_Log.warn('API Error: '+tmpErrorMessage, {SessionID: tmpSessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Scope: tmpScope, Parameters: tmpParams, Action:'APIError'}, pRequest);
pResponse.send({Error:tmpErrorMessage, ErrorCode: tmpErrorCode});
return fNext();
} | javascript | function(pDefaultMessage, pError, pRequest, pResponse, fNext)
{
var tmpErrorMessage = pDefaultMessage;
var tmpErrorCode = 1;
var tmpScope = null;
var tmpParams = null;
var tmpSessionID = null;
if (typeof(pError) === 'object')
{
tmpErrorMessage = pError.Message;
if (pError.Code)
tmpErrorCode = pError.Code;
}
else if (typeof(pError) === 'string')
{
tmpErrorMessage += ' ' + pError;
}
if (pRequest.DAL)
{
tmpScope = pRequest.DAL.scope;
}
if (pRequest.params)
{
tmpParams = pRequest.params;
}
if (pRequest.UserSession)
{
tmpSessionID = pRequest.UserSession.SessionID;
}
_Log.warn('API Error: '+tmpErrorMessage, {SessionID: tmpSessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Scope: tmpScope, Parameters: tmpParams, Action:'APIError'}, pRequest);
pResponse.send({Error:tmpErrorMessage, ErrorCode: tmpErrorCode});
return fNext();
} | [
"function",
"(",
"pDefaultMessage",
",",
"pError",
",",
"pRequest",
",",
"pResponse",
",",
"fNext",
")",
"{",
"var",
"tmpErrorMessage",
"=",
"pDefaultMessage",
";",
"var",
"tmpErrorCode",
"=",
"1",
";",
"var",
"tmpScope",
"=",
"null",
";",
"var",
"tmpParams",
"=",
"null",
";",
"var",
"tmpSessionID",
"=",
"null",
";",
"if",
"(",
"typeof",
"(",
"pError",
")",
"===",
"'object'",
")",
"{",
"tmpErrorMessage",
"=",
"pError",
".",
"Message",
";",
"if",
"(",
"pError",
".",
"Code",
")",
"tmpErrorCode",
"=",
"pError",
".",
"Code",
";",
"}",
"else",
"if",
"(",
"typeof",
"(",
"pError",
")",
"===",
"'string'",
")",
"{",
"tmpErrorMessage",
"+=",
"' '",
"+",
"pError",
";",
"}",
"if",
"(",
"pRequest",
".",
"DAL",
")",
"{",
"tmpScope",
"=",
"pRequest",
".",
"DAL",
".",
"scope",
";",
"}",
"if",
"(",
"pRequest",
".",
"params",
")",
"{",
"tmpParams",
"=",
"pRequest",
".",
"params",
";",
"}",
"if",
"(",
"pRequest",
".",
"UserSession",
")",
"{",
"tmpSessionID",
"=",
"pRequest",
".",
"UserSession",
".",
"SessionID",
";",
"}",
"_Log",
".",
"warn",
"(",
"'API Error: '",
"+",
"tmpErrorMessage",
",",
"{",
"SessionID",
":",
"tmpSessionID",
",",
"RequestID",
":",
"pRequest",
".",
"RequestUUID",
",",
"RequestURL",
":",
"pRequest",
".",
"url",
",",
"Scope",
":",
"tmpScope",
",",
"Parameters",
":",
"tmpParams",
",",
"Action",
":",
"'APIError'",
"}",
",",
"pRequest",
")",
";",
"pResponse",
".",
"send",
"(",
"{",
"Error",
":",
"tmpErrorMessage",
",",
"ErrorCode",
":",
"tmpErrorCode",
"}",
")",
";",
"return",
"fNext",
"(",
")",
";",
"}"
]
| Send an Error Code and Error Message to the client, and log it as an error in the log files.
@method sendCodedError | [
"Send",
"an",
"Error",
"Code",
"and",
"Error",
"Message",
"to",
"the",
"client",
"and",
"log",
"it",
"as",
"an",
"error",
"in",
"the",
"log",
"files",
"."
]
| 761c7b4d746c874f43cfecfa1cf3f192fa8f5755 | https://github.com/stevenvelozo/tidings/blob/761c7b4d746c874f43cfecfa1cf3f192fa8f5755/source/Tidings-CommonServices.js#L39-L74 |
|
45,786 | stevenvelozo/tidings | source/Tidings-CommonServices.js | function(pMessage, pRequest, pResponse, fNext)
{
var tmpSessionID = null;
if (pRequest.UserSession)
{
tmpSessionID = pRequest.UserSession.SessionID;
}
_Log.warn('API Error: '+pMessage, {SessionID: tmpSessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:'APIError'}, pRequest);
pResponse.send({Error:pMessage});
return fNext();
} | javascript | function(pMessage, pRequest, pResponse, fNext)
{
var tmpSessionID = null;
if (pRequest.UserSession)
{
tmpSessionID = pRequest.UserSession.SessionID;
}
_Log.warn('API Error: '+pMessage, {SessionID: tmpSessionID, RequestID:pRequest.RequestUUID, RequestURL:pRequest.url, Action:'APIError'}, pRequest);
pResponse.send({Error:pMessage});
return fNext();
} | [
"function",
"(",
"pMessage",
",",
"pRequest",
",",
"pResponse",
",",
"fNext",
")",
"{",
"var",
"tmpSessionID",
"=",
"null",
";",
"if",
"(",
"pRequest",
".",
"UserSession",
")",
"{",
"tmpSessionID",
"=",
"pRequest",
".",
"UserSession",
".",
"SessionID",
";",
"}",
"_Log",
".",
"warn",
"(",
"'API Error: '",
"+",
"pMessage",
",",
"{",
"SessionID",
":",
"tmpSessionID",
",",
"RequestID",
":",
"pRequest",
".",
"RequestUUID",
",",
"RequestURL",
":",
"pRequest",
".",
"url",
",",
"Action",
":",
"'APIError'",
"}",
",",
"pRequest",
")",
";",
"pResponse",
".",
"send",
"(",
"{",
"Error",
":",
"pMessage",
"}",
")",
";",
"return",
"fNext",
"(",
")",
";",
"}"
]
| Send an Error to the client, and log it as an error in the log files.
@method sendError | [
"Send",
"an",
"Error",
"to",
"the",
"client",
"and",
"log",
"it",
"as",
"an",
"error",
"in",
"the",
"log",
"files",
"."
]
| 761c7b4d746c874f43cfecfa1cf3f192fa8f5755 | https://github.com/stevenvelozo/tidings/blob/761c7b4d746c874f43cfecfa1cf3f192fa8f5755/source/Tidings-CommonServices.js#L82-L94 |
|
45,787 | rolandliwag/serverrunner | index.js | startWorkers | function startWorkers() {
_.range(0, numWorkers).forEach(function (index) {
workers.push(startWorker(startPort + index));
});
} | javascript | function startWorkers() {
_.range(0, numWorkers).forEach(function (index) {
workers.push(startWorker(startPort + index));
});
} | [
"function",
"startWorkers",
"(",
")",
"{",
"_",
".",
"range",
"(",
"0",
",",
"numWorkers",
")",
".",
"forEach",
"(",
"function",
"(",
"index",
")",
"{",
"workers",
".",
"push",
"(",
"startWorker",
"(",
"startPort",
"+",
"index",
")",
")",
";",
"}",
")",
";",
"}"
]
| Start the workers | [
"Start",
"the",
"workers"
]
| 8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7 | https://github.com/rolandliwag/serverrunner/blob/8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7/index.js#L48-L52 |
45,788 | rolandliwag/serverrunner | index.js | startWorker | function startWorker(port) {
var worker = child.fork(serverWorker, [
'--port', port,
'--server', serverFile,
'--allowForcedExit', allowForcedExit,
'--config', JSON.stringify(config.app || {}),
'--title', workerTitle
]);
worker.on('exit', createWorkerExitHandler(port));
return worker;
} | javascript | function startWorker(port) {
var worker = child.fork(serverWorker, [
'--port', port,
'--server', serverFile,
'--allowForcedExit', allowForcedExit,
'--config', JSON.stringify(config.app || {}),
'--title', workerTitle
]);
worker.on('exit', createWorkerExitHandler(port));
return worker;
} | [
"function",
"startWorker",
"(",
"port",
")",
"{",
"var",
"worker",
"=",
"child",
".",
"fork",
"(",
"serverWorker",
",",
"[",
"'--port'",
",",
"port",
",",
"'--server'",
",",
"serverFile",
",",
"'--allowForcedExit'",
",",
"allowForcedExit",
",",
"'--config'",
",",
"JSON",
".",
"stringify",
"(",
"config",
".",
"app",
"||",
"{",
"}",
")",
",",
"'--title'",
",",
"workerTitle",
"]",
")",
";",
"worker",
".",
"on",
"(",
"'exit'",
",",
"createWorkerExitHandler",
"(",
"port",
")",
")",
";",
"return",
"worker",
";",
"}"
]
| Start a worker on a specific port
@private | [
"Start",
"a",
"worker",
"on",
"a",
"specific",
"port"
]
| 8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7 | https://github.com/rolandliwag/serverrunner/blob/8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7/index.js#L58-L69 |
45,789 | rolandliwag/serverrunner | index.js | createWorkerExitHandler | function createWorkerExitHandler(port) {
return function (code, signal) {
var workerIndex = port - startPort;
workers[workerIndex] = null;
if (code !== 0 || code === null) {
console.log('Worker exited with code: ' + code);
if (!shuttingDown) {
// Start worker again after 1 sec
setTimeout(function () {
if (!workers[workerIndex]) {
workers[workerIndex] = startWorker(port);
}
}, 1000);
}
}
};
} | javascript | function createWorkerExitHandler(port) {
return function (code, signal) {
var workerIndex = port - startPort;
workers[workerIndex] = null;
if (code !== 0 || code === null) {
console.log('Worker exited with code: ' + code);
if (!shuttingDown) {
// Start worker again after 1 sec
setTimeout(function () {
if (!workers[workerIndex]) {
workers[workerIndex] = startWorker(port);
}
}, 1000);
}
}
};
} | [
"function",
"createWorkerExitHandler",
"(",
"port",
")",
"{",
"return",
"function",
"(",
"code",
",",
"signal",
")",
"{",
"var",
"workerIndex",
"=",
"port",
"-",
"startPort",
";",
"workers",
"[",
"workerIndex",
"]",
"=",
"null",
";",
"if",
"(",
"code",
"!==",
"0",
"||",
"code",
"===",
"null",
")",
"{",
"console",
".",
"log",
"(",
"'Worker exited with code: '",
"+",
"code",
")",
";",
"if",
"(",
"!",
"shuttingDown",
")",
"{",
"// Start worker again after 1 sec",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"workers",
"[",
"workerIndex",
"]",
")",
"{",
"workers",
"[",
"workerIndex",
"]",
"=",
"startWorker",
"(",
"port",
")",
";",
"}",
"}",
",",
"1000",
")",
";",
"}",
"}",
"}",
";",
"}"
]
| Create a listener function to handle a premature exit event from a worker
@private
@param {Number} port The port number of the worker.
@returns {Function} | [
"Create",
"a",
"listener",
"function",
"to",
"handle",
"a",
"premature",
"exit",
"event",
"from",
"a",
"worker"
]
| 8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7 | https://github.com/rolandliwag/serverrunner/blob/8a85f2d5af82c6a9d1d6c3b7eff68ab06e238aa7/index.js#L145-L164 |
45,790 | soichih/node-htcondor | index.js | condor_simple | function condor_simple(cmd, opts) {
var deferred = Q.defer();
var p = spawn(cmd, opts, {env: get_condor_env()});//, {cwd: __dirname});
//load event
var stdout = "";
p.stdout.on('data', function (data) {
stdout += data;
});
var stderr = "";
p.stderr.on('data', function (data) {
stderr += data;
});
p.on('error', deferred.reject);
p.on('close', function (code, signal) {
if (signal) {
deferred.reject(cmd+ " was killed by signal "+ signal);
} else if (code !== 0) {
deferred.reject(cmd+ " failed with exit code "+ code+ "\nSTDERR:"+ stderr + "\nSTDOUT:"+ stdout);
} else {
deferred.resolve(stdout, stderr);
}
});
return deferred.promise;
} | javascript | function condor_simple(cmd, opts) {
var deferred = Q.defer();
var p = spawn(cmd, opts, {env: get_condor_env()});//, {cwd: __dirname});
//load event
var stdout = "";
p.stdout.on('data', function (data) {
stdout += data;
});
var stderr = "";
p.stderr.on('data', function (data) {
stderr += data;
});
p.on('error', deferred.reject);
p.on('close', function (code, signal) {
if (signal) {
deferred.reject(cmd+ " was killed by signal "+ signal);
} else if (code !== 0) {
deferred.reject(cmd+ " failed with exit code "+ code+ "\nSTDERR:"+ stderr + "\nSTDOUT:"+ stdout);
} else {
deferred.resolve(stdout, stderr);
}
});
return deferred.promise;
} | [
"function",
"condor_simple",
"(",
"cmd",
",",
"opts",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"p",
"=",
"spawn",
"(",
"cmd",
",",
"opts",
",",
"{",
"env",
":",
"get_condor_env",
"(",
")",
"}",
")",
";",
"//, {cwd: __dirname});",
"//load event",
"var",
"stdout",
"=",
"\"\"",
";",
"p",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"stdout",
"+=",
"data",
";",
"}",
")",
";",
"var",
"stderr",
"=",
"\"\"",
";",
"p",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"stderr",
"+=",
"data",
";",
"}",
")",
";",
"p",
".",
"on",
"(",
"'error'",
",",
"deferred",
".",
"reject",
")",
";",
"p",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
",",
"signal",
")",
"{",
"if",
"(",
"signal",
")",
"{",
"deferred",
".",
"reject",
"(",
"cmd",
"+",
"\" was killed by signal \"",
"+",
"signal",
")",
";",
"}",
"else",
"if",
"(",
"code",
"!==",
"0",
")",
"{",
"deferred",
".",
"reject",
"(",
"cmd",
"+",
"\" failed with exit code \"",
"+",
"code",
"+",
"\"\\nSTDERR:\"",
"+",
"stderr",
"+",
"\"\\nSTDOUT:\"",
"+",
"stdout",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
"stdout",
",",
"stderr",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
]
| run simple condor command that takes job id as an argument | [
"run",
"simple",
"condor",
"command",
"that",
"takes",
"job",
"id",
"as",
"an",
"argument"
]
| 8800d84356d7235a6a19587464b0a3201bf4f9fc | https://github.com/soichih/node-htcondor/blob/8800d84356d7235a6a19587464b0a3201bf4f9fc/index.js#L218-L242 |
45,791 | jquense/cobble | lib/descriptors.js | describe | function describe(composer, trailing) {
return function (method) {
return new Descriptor(function (key, previousValues) {
if ( method !== undefined)
previousValues[trailing ? 'push' : 'unshift' ](method)
//console.log(previousValues)
return reduce(previousValues, function(merged, next, idx){
return trailing
? composer(next, merged)
: composer(merged, next)
})
})
}
} | javascript | function describe(composer, trailing) {
return function (method) {
return new Descriptor(function (key, previousValues) {
if ( method !== undefined)
previousValues[trailing ? 'push' : 'unshift' ](method)
//console.log(previousValues)
return reduce(previousValues, function(merged, next, idx){
return trailing
? composer(next, merged)
: composer(merged, next)
})
})
}
} | [
"function",
"describe",
"(",
"composer",
",",
"trailing",
")",
"{",
"return",
"function",
"(",
"method",
")",
"{",
"return",
"new",
"Descriptor",
"(",
"function",
"(",
"key",
",",
"previousValues",
")",
"{",
"if",
"(",
"method",
"!==",
"undefined",
")",
"previousValues",
"[",
"trailing",
"?",
"'push'",
":",
"'unshift'",
"]",
"(",
"method",
")",
"//console.log(previousValues)",
"return",
"reduce",
"(",
"previousValues",
",",
"function",
"(",
"merged",
",",
"next",
",",
"idx",
")",
"{",
"return",
"trailing",
"?",
"composer",
"(",
"next",
",",
"merged",
")",
":",
"composer",
"(",
"merged",
",",
"next",
")",
"}",
")",
"}",
")",
"}",
"}"
]
| turns a normal decorator into a 'descriptor'
@param {function} composer
@return {function} | [
"turns",
"a",
"normal",
"decorator",
"into",
"a",
"descriptor"
]
| 25889b99309cdd6d690fa8efdb6f86e99c41c466 | https://github.com/jquense/cobble/blob/25889b99309cdd6d690fa8efdb6f86e99c41c466/lib/descriptors.js#L89-L106 |
45,792 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | parseTaskObject | function parseTaskObject(task, options) {
if (Array.isArray(task)) {
return task;
} else {
return task.bind(null, gulp, ...options.params);
}
} | javascript | function parseTaskObject(task, options) {
if (Array.isArray(task)) {
return task;
} else {
return task.bind(null, gulp, ...options.params);
}
} | [
"function",
"parseTaskObject",
"(",
"task",
",",
"options",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"task",
")",
")",
"{",
"return",
"task",
";",
"}",
"else",
"{",
"return",
"task",
".",
"bind",
"(",
"null",
",",
"gulp",
",",
"...",
"options",
".",
"params",
")",
";",
"}",
"}"
]
| This builds the task object. A gulp task may be either an array or a
function, so we must handle both. If it is an array, we return it
immediately, otherwise we create a new function with the correctly-bounded
parameters.
@param {Array|Function} task
@param {Object} options
@returns {Array|Function} | [
"This",
"builds",
"the",
"task",
"object",
".",
"A",
"gulp",
"task",
"may",
"be",
"either",
"an",
"array",
"or",
"a",
"function",
"so",
"we",
"must",
"handle",
"both",
".",
"If",
"it",
"is",
"an",
"array",
"we",
"return",
"it",
"immediately",
"otherwise",
"we",
"create",
"a",
"new",
"function",
"with",
"the",
"correctly",
"-",
"bounded",
"parameters",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L49-L55 |
45,793 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | registerTask | function registerTask(file, options) {
const task = require(file.path);
const taskName = path.basename(file.path, file.ext);
const taskObject = parseTaskObject(task, options);
// Register this task with Gulp.
gulp.task.call(gulp, taskName, taskObject);
debug(`registered "${taskName}" task`);
} | javascript | function registerTask(file, options) {
const task = require(file.path);
const taskName = path.basename(file.path, file.ext);
const taskObject = parseTaskObject(task, options);
// Register this task with Gulp.
gulp.task.call(gulp, taskName, taskObject);
debug(`registered "${taskName}" task`);
} | [
"function",
"registerTask",
"(",
"file",
",",
"options",
")",
"{",
"const",
"task",
"=",
"require",
"(",
"file",
".",
"path",
")",
";",
"const",
"taskName",
"=",
"path",
".",
"basename",
"(",
"file",
".",
"path",
",",
"file",
".",
"ext",
")",
";",
"const",
"taskObject",
"=",
"parseTaskObject",
"(",
"task",
",",
"options",
")",
";",
"// Register this task with Gulp.",
"gulp",
".",
"task",
".",
"call",
"(",
"gulp",
",",
"taskName",
",",
"taskObject",
")",
";",
"debug",
"(",
"`",
"${",
"taskName",
"}",
"`",
")",
";",
"}"
]
| Registers a Gulp task given a file and a set of options.
@param {Object} file
@param {Object} options | [
"Registers",
"a",
"Gulp",
"task",
"given",
"a",
"file",
"and",
"a",
"set",
"of",
"options",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L63-L72 |
45,794 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | parseFile | function parseFile(dir, filename) {
const filePath = path.join(dir, filename);
const fileStat = fs.statSync(filePath);
const fileExt = path.extname(filename);
return {
path: filePath,
stat: fileStat,
ext: fileExt
};
} | javascript | function parseFile(dir, filename) {
const filePath = path.join(dir, filename);
const fileStat = fs.statSync(filePath);
const fileExt = path.extname(filename);
return {
path: filePath,
stat: fileStat,
ext: fileExt
};
} | [
"function",
"parseFile",
"(",
"dir",
",",
"filename",
")",
"{",
"const",
"filePath",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"filename",
")",
";",
"const",
"fileStat",
"=",
"fs",
".",
"statSync",
"(",
"filePath",
")",
";",
"const",
"fileExt",
"=",
"path",
".",
"extname",
"(",
"filename",
")",
";",
"return",
"{",
"path",
":",
"filePath",
",",
"stat",
":",
"fileStat",
",",
"ext",
":",
"fileExt",
"}",
";",
"}"
]
| Parses relevant file properties into a single object.
@param {string} dir
@param {string} filename
@returns {Object} | [
"Parses",
"relevant",
"file",
"properties",
"into",
"a",
"single",
"object",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L81-L91 |
45,795 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | handleFile | function handleFile(dir, options) {
return filename => {
const file = parseFile(dir, filename);
debug(`found "${filename}"`);
// Exit early if this item is not a file.
if (!file.stat.isFile()) {
debug(`skipped "${filename}" (not a file)`);
return;
}
// Exit early if this item is not the right file type.
if (!options.extensions.includes(file.ext)) {
debug(`skipped "${filename}" (incorrect file type)`);
return;
}
registerTask(file, options);
};
} | javascript | function handleFile(dir, options) {
return filename => {
const file = parseFile(dir, filename);
debug(`found "${filename}"`);
// Exit early if this item is not a file.
if (!file.stat.isFile()) {
debug(`skipped "${filename}" (not a file)`);
return;
}
// Exit early if this item is not the right file type.
if (!options.extensions.includes(file.ext)) {
debug(`skipped "${filename}" (incorrect file type)`);
return;
}
registerTask(file, options);
};
} | [
"function",
"handleFile",
"(",
"dir",
",",
"options",
")",
"{",
"return",
"filename",
"=>",
"{",
"const",
"file",
"=",
"parseFile",
"(",
"dir",
",",
"filename",
")",
";",
"debug",
"(",
"`",
"${",
"filename",
"}",
"`",
")",
";",
"// Exit early if this item is not a file.",
"if",
"(",
"!",
"file",
".",
"stat",
".",
"isFile",
"(",
")",
")",
"{",
"debug",
"(",
"`",
"${",
"filename",
"}",
"`",
")",
";",
"return",
";",
"}",
"// Exit early if this item is not the right file type.",
"if",
"(",
"!",
"options",
".",
"extensions",
".",
"includes",
"(",
"file",
".",
"ext",
")",
")",
"{",
"debug",
"(",
"`",
"${",
"filename",
"}",
"`",
")",
";",
"return",
";",
"}",
"registerTask",
"(",
"file",
",",
"options",
")",
";",
"}",
";",
"}"
]
| Creates a closure that is invoked for each item in the chosen directory.
Verifies that the item is a file and of the correct type, then registers
the task.
@param {string} dir
@param {Object} options
@returns {Function} | [
"Creates",
"a",
"closure",
"that",
"is",
"invoked",
"for",
"each",
"item",
"in",
"the",
"chosen",
"directory",
".",
"Verifies",
"that",
"the",
"item",
"is",
"a",
"file",
"and",
"of",
"the",
"correct",
"type",
"then",
"registers",
"the",
"task",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L102-L122 |
45,796 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | extendDefaultOptions | function extendDefaultOptions(options) {
return Object.assign({
dir: DEFAULT_DIRECTORY,
extensions: DEFAULT_EXTENSIONS,
params: DEFAULT_PARAMS
}, options);
} | javascript | function extendDefaultOptions(options) {
return Object.assign({
dir: DEFAULT_DIRECTORY,
extensions: DEFAULT_EXTENSIONS,
params: DEFAULT_PARAMS
}, options);
} | [
"function",
"extendDefaultOptions",
"(",
"options",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"dir",
":",
"DEFAULT_DIRECTORY",
",",
"extensions",
":",
"DEFAULT_EXTENSIONS",
",",
"params",
":",
"DEFAULT_PARAMS",
"}",
",",
"options",
")",
";",
"}"
]
| Extends default options with user options.
@param {Object} options
@returns {Object} | [
"Extends",
"default",
"options",
"with",
"user",
"options",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L130-L136 |
45,797 | nathanbuchar/gulp-import-tasks | lib/gulp-import-tasks.js | importTasks | function importTasks(options) {
const opts = parseOptions(options);
const cwd = process.cwd();
const dir = path.join(cwd, opts.dir);
debug(`importing tasks from "${dir}"...`);
// This synchronously reads the contents within the chosen directory then
// loops through each item, verifies that it is in fact a file of the correct
// file type, then creates the tasks object and registers it with gulp.
fs.readdirSync(dir).forEach(
handleFile(dir, opts)
);
debug(`finished importing tasks`);
} | javascript | function importTasks(options) {
const opts = parseOptions(options);
const cwd = process.cwd();
const dir = path.join(cwd, opts.dir);
debug(`importing tasks from "${dir}"...`);
// This synchronously reads the contents within the chosen directory then
// loops through each item, verifies that it is in fact a file of the correct
// file type, then creates the tasks object and registers it with gulp.
fs.readdirSync(dir).forEach(
handleFile(dir, opts)
);
debug(`finished importing tasks`);
} | [
"function",
"importTasks",
"(",
"options",
")",
"{",
"const",
"opts",
"=",
"parseOptions",
"(",
"options",
")",
";",
"const",
"cwd",
"=",
"process",
".",
"cwd",
"(",
")",
";",
"const",
"dir",
"=",
"path",
".",
"join",
"(",
"cwd",
",",
"opts",
".",
"dir",
")",
";",
"debug",
"(",
"`",
"${",
"dir",
"}",
"`",
")",
";",
"// This synchronously reads the contents within the chosen directory then",
"// loops through each item, verifies that it is in fact a file of the correct",
"// file type, then creates the tasks object and registers it with gulp.",
"fs",
".",
"readdirSync",
"(",
"dir",
")",
".",
"forEach",
"(",
"handleFile",
"(",
"dir",
",",
"opts",
")",
")",
";",
"debug",
"(",
"`",
"`",
")",
";",
"}"
]
| Registers all gulp tasks within the given directory.
@param {Object|string} [options]
@param {string} [options.dir='tasks']
@param {Array.<string>} [options.extensions=['.js']]
@param {Array.<*>} [options.params=[]] | [
"Registers",
"all",
"gulp",
"tasks",
"within",
"the",
"given",
"directory",
"."
]
| 2d65e761e2100f68a422a2e63d24725e31247bb7 | https://github.com/nathanbuchar/gulp-import-tasks/blob/2d65e761e2100f68a422a2e63d24725e31247bb7/lib/gulp-import-tasks.js#L162-L177 |
45,798 | cettia/cettia-protocol | lib/transport-http-stream-transport.js | onmessage | function onmessage(data) {
if (!handshaked) {
handshaked = true;
// The handshake output is in the form of URI.
var result = url.parse(data, true).query;
// A newly issued id for HTTP transport. It is used to identify which HTTP transport
// is associated with which HTTP exchange. Don't confuse it with an id for socket,
// `cettia-id`.
self.id = result["cettia-transport-id"];
// And then fire `open` event.
self.emit("open");
} else {
// `code` is a first character of a message and used to recognize that delivered
// message is text message or binary message.
var code = data.substring(0, 1);
data = data.substring(1);
switch (code) {
// If the `code` is `1`, the remainder of message is a plain text message. Fires
// `text` event.
case "1":
self.emit("text", data);
break;
// If the `code` is `2`, the remainder of message is a Base64-encoded binary
// message. Decodes it in Base64 and fires `binary` event.
case "2":
self.emit("binary", new Buffer(data, "base64"));
break;
// Otherwise, it is invalid. Fires an error and closes the connection.
default:
self.emit("error", new Error("protocol"));
self.close();
break;
}
}
} | javascript | function onmessage(data) {
if (!handshaked) {
handshaked = true;
// The handshake output is in the form of URI.
var result = url.parse(data, true).query;
// A newly issued id for HTTP transport. It is used to identify which HTTP transport
// is associated with which HTTP exchange. Don't confuse it with an id for socket,
// `cettia-id`.
self.id = result["cettia-transport-id"];
// And then fire `open` event.
self.emit("open");
} else {
// `code` is a first character of a message and used to recognize that delivered
// message is text message or binary message.
var code = data.substring(0, 1);
data = data.substring(1);
switch (code) {
// If the `code` is `1`, the remainder of message is a plain text message. Fires
// `text` event.
case "1":
self.emit("text", data);
break;
// If the `code` is `2`, the remainder of message is a Base64-encoded binary
// message. Decodes it in Base64 and fires `binary` event.
case "2":
self.emit("binary", new Buffer(data, "base64"));
break;
// Otherwise, it is invalid. Fires an error and closes the connection.
default:
self.emit("error", new Error("protocol"));
self.close();
break;
}
}
} | [
"function",
"onmessage",
"(",
"data",
")",
"{",
"if",
"(",
"!",
"handshaked",
")",
"{",
"handshaked",
"=",
"true",
";",
"// The handshake output is in the form of URI.",
"var",
"result",
"=",
"url",
".",
"parse",
"(",
"data",
",",
"true",
")",
".",
"query",
";",
"// A newly issued id for HTTP transport. It is used to identify which HTTP transport",
"// is associated with which HTTP exchange. Don't confuse it with an id for socket,",
"// `cettia-id`.",
"self",
".",
"id",
"=",
"result",
"[",
"\"cettia-transport-id\"",
"]",
";",
"// And then fire `open` event.",
"self",
".",
"emit",
"(",
"\"open\"",
")",
";",
"}",
"else",
"{",
"// `code` is a first character of a message and used to recognize that delivered",
"// message is text message or binary message.",
"var",
"code",
"=",
"data",
".",
"substring",
"(",
"0",
",",
"1",
")",
";",
"data",
"=",
"data",
".",
"substring",
"(",
"1",
")",
";",
"switch",
"(",
"code",
")",
"{",
"// If the `code` is `1`, the remainder of message is a plain text message. Fires",
"// `text` event.",
"case",
"\"1\"",
":",
"self",
".",
"emit",
"(",
"\"text\"",
",",
"data",
")",
";",
"break",
";",
"// If the `code` is `2`, the remainder of message is a Base64-encoded binary",
"// message. Decodes it in Base64 and fires `binary` event.",
"case",
"\"2\"",
":",
"self",
".",
"emit",
"(",
"\"binary\"",
",",
"new",
"Buffer",
"(",
"data",
",",
"\"base64\"",
")",
")",
";",
"break",
";",
"// Otherwise, it is invalid. Fires an error and closes the connection.",
"default",
":",
"self",
".",
"emit",
"(",
"\"error\"",
",",
"new",
"Error",
"(",
"\"protocol\"",
")",
")",
";",
"self",
".",
"close",
"(",
")",
";",
"break",
";",
"}",
"}",
"}"
]
| On a message of the event stream format of Server-Sent Events, | [
"On",
"a",
"message",
"of",
"the",
"event",
"stream",
"format",
"of",
"Server",
"-",
"Sent",
"Events"
]
| 9af3b578a9ae7b33099932903b52faeb2ca92528 | https://github.com/cettia/cettia-protocol/blob/9af3b578a9ae7b33099932903b52faeb2ca92528/lib/transport-http-stream-transport.js#L64-L98 |
45,799 | solid/solid-auth-tls | src/auth.js | loginTo | function loginTo (endpoint, config) {
return global.IS_BROWSER
? loginFromBrowser(endpoint, config)
: loginFromNode(endpoint, config)
} | javascript | function loginTo (endpoint, config) {
return global.IS_BROWSER
? loginFromBrowser(endpoint, config)
: loginFromNode(endpoint, config)
} | [
"function",
"loginTo",
"(",
"endpoint",
",",
"config",
")",
"{",
"return",
"global",
".",
"IS_BROWSER",
"?",
"loginFromBrowser",
"(",
"endpoint",
",",
"config",
")",
":",
"loginFromNode",
"(",
"endpoint",
",",
"config",
")",
"}"
]
| Logs in to the specified endpoint with the given configuration
@param {AUTH_ENDPOINTS} endpoint - the endpoint type
@param {@link module:config-default} config - the config object
@returns {(Promise<String>|Promise<null>)} the WebID as a string if the
client cert is recognized, otherwise null. | [
"Logs",
"in",
"to",
"the",
"specified",
"endpoint",
"with",
"the",
"given",
"configuration"
]
| a27dea9c29778db936adf48be8042895af3a8f43 | https://github.com/solid/solid-auth-tls/blob/a27dea9c29778db936adf48be8042895af3a8f43/src/auth.js#L60-L64 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.