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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
9,100
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function(type, base_class) {
if (!base_class.prototype) {
throw "Cannot register a simple object, it must be a class with a prototype";
}
base_class.type = type;
if (LiteGraph.debug) {
console.log("Node registered: " + type);
}
var categories = type.split("/");
var classname = base_class.name;
var pos = type.lastIndexOf("/");
base_class.category = type.substr(0, pos);
if (!base_class.title) {
base_class.title = classname;
}
//info.name = name.substr(pos+1,name.length - pos);
//extend class
if (base_class.prototype) {
//is a class
for (var i in LGraphNode.prototype) {
if (!base_class.prototype[i]) {
base_class.prototype[i] = LGraphNode.prototype[i];
}
}
}
Object.defineProperty(base_class.prototype, "shape", {
set: function(v) {
switch (v) {
case "default":
delete this._shape;
break;
case "box":
this._shape = LiteGraph.BOX_SHAPE;
break;
case "round":
this._shape = LiteGraph.ROUND_SHAPE;
break;
case "circle":
this._shape = LiteGraph.CIRCLE_SHAPE;
break;
case "card":
this._shape = LiteGraph.CARD_SHAPE;
break;
default:
this._shape = v;
}
},
get: function(v) {
return this._shape;
},
enumerable: true
});
var prev = this.registered_node_types[type];
this.registered_node_types[type] = base_class;
if (base_class.constructor.name) {
this.Nodes[classname] = base_class;
}
if (LiteGraph.onNodeTypeRegistered) {
LiteGraph.onNodeTypeRegistered(type, base_class);
}
if (prev && LiteGraph.onNodeTypeReplaced) {
LiteGraph.onNodeTypeReplaced(type, base_class, prev);
}
//warnings
if (base_class.prototype.onPropertyChange) {
console.warn(
"LiteGraph node class " +
type +
" has onPropertyChange method, it must be called onPropertyChanged with d at the end"
);
}
if (base_class.supported_extensions) {
for (var i in base_class.supported_extensions) {
this.node_types_by_file_extension[
base_class.supported_extensions[i].toLowerCase()
] = base_class;
}
}
}
|
javascript
|
function(type, base_class) {
if (!base_class.prototype) {
throw "Cannot register a simple object, it must be a class with a prototype";
}
base_class.type = type;
if (LiteGraph.debug) {
console.log("Node registered: " + type);
}
var categories = type.split("/");
var classname = base_class.name;
var pos = type.lastIndexOf("/");
base_class.category = type.substr(0, pos);
if (!base_class.title) {
base_class.title = classname;
}
//info.name = name.substr(pos+1,name.length - pos);
//extend class
if (base_class.prototype) {
//is a class
for (var i in LGraphNode.prototype) {
if (!base_class.prototype[i]) {
base_class.prototype[i] = LGraphNode.prototype[i];
}
}
}
Object.defineProperty(base_class.prototype, "shape", {
set: function(v) {
switch (v) {
case "default":
delete this._shape;
break;
case "box":
this._shape = LiteGraph.BOX_SHAPE;
break;
case "round":
this._shape = LiteGraph.ROUND_SHAPE;
break;
case "circle":
this._shape = LiteGraph.CIRCLE_SHAPE;
break;
case "card":
this._shape = LiteGraph.CARD_SHAPE;
break;
default:
this._shape = v;
}
},
get: function(v) {
return this._shape;
},
enumerable: true
});
var prev = this.registered_node_types[type];
this.registered_node_types[type] = base_class;
if (base_class.constructor.name) {
this.Nodes[classname] = base_class;
}
if (LiteGraph.onNodeTypeRegistered) {
LiteGraph.onNodeTypeRegistered(type, base_class);
}
if (prev && LiteGraph.onNodeTypeReplaced) {
LiteGraph.onNodeTypeReplaced(type, base_class, prev);
}
//warnings
if (base_class.prototype.onPropertyChange) {
console.warn(
"LiteGraph node class " +
type +
" has onPropertyChange method, it must be called onPropertyChanged with d at the end"
);
}
if (base_class.supported_extensions) {
for (var i in base_class.supported_extensions) {
this.node_types_by_file_extension[
base_class.supported_extensions[i].toLowerCase()
] = base_class;
}
}
}
|
[
"function",
"(",
"type",
",",
"base_class",
")",
"{",
"if",
"(",
"!",
"base_class",
".",
"prototype",
")",
"{",
"throw",
"\"Cannot register a simple object, it must be a class with a prototype\"",
";",
"}",
"base_class",
".",
"type",
"=",
"type",
";",
"if",
"(",
"LiteGraph",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"\"Node registered: \"",
"+",
"type",
")",
";",
"}",
"var",
"categories",
"=",
"type",
".",
"split",
"(",
"\"/\"",
")",
";",
"var",
"classname",
"=",
"base_class",
".",
"name",
";",
"var",
"pos",
"=",
"type",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
";",
"base_class",
".",
"category",
"=",
"type",
".",
"substr",
"(",
"0",
",",
"pos",
")",
";",
"if",
"(",
"!",
"base_class",
".",
"title",
")",
"{",
"base_class",
".",
"title",
"=",
"classname",
";",
"}",
"//info.name = name.substr(pos+1,name.length - pos);",
"//extend class",
"if",
"(",
"base_class",
".",
"prototype",
")",
"{",
"//is a class",
"for",
"(",
"var",
"i",
"in",
"LGraphNode",
".",
"prototype",
")",
"{",
"if",
"(",
"!",
"base_class",
".",
"prototype",
"[",
"i",
"]",
")",
"{",
"base_class",
".",
"prototype",
"[",
"i",
"]",
"=",
"LGraphNode",
".",
"prototype",
"[",
"i",
"]",
";",
"}",
"}",
"}",
"Object",
".",
"defineProperty",
"(",
"base_class",
".",
"prototype",
",",
"\"shape\"",
",",
"{",
"set",
":",
"function",
"(",
"v",
")",
"{",
"switch",
"(",
"v",
")",
"{",
"case",
"\"default\"",
":",
"delete",
"this",
".",
"_shape",
";",
"break",
";",
"case",
"\"box\"",
":",
"this",
".",
"_shape",
"=",
"LiteGraph",
".",
"BOX_SHAPE",
";",
"break",
";",
"case",
"\"round\"",
":",
"this",
".",
"_shape",
"=",
"LiteGraph",
".",
"ROUND_SHAPE",
";",
"break",
";",
"case",
"\"circle\"",
":",
"this",
".",
"_shape",
"=",
"LiteGraph",
".",
"CIRCLE_SHAPE",
";",
"break",
";",
"case",
"\"card\"",
":",
"this",
".",
"_shape",
"=",
"LiteGraph",
".",
"CARD_SHAPE",
";",
"break",
";",
"default",
":",
"this",
".",
"_shape",
"=",
"v",
";",
"}",
"}",
",",
"get",
":",
"function",
"(",
"v",
")",
"{",
"return",
"this",
".",
"_shape",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"var",
"prev",
"=",
"this",
".",
"registered_node_types",
"[",
"type",
"]",
";",
"this",
".",
"registered_node_types",
"[",
"type",
"]",
"=",
"base_class",
";",
"if",
"(",
"base_class",
".",
"constructor",
".",
"name",
")",
"{",
"this",
".",
"Nodes",
"[",
"classname",
"]",
"=",
"base_class",
";",
"}",
"if",
"(",
"LiteGraph",
".",
"onNodeTypeRegistered",
")",
"{",
"LiteGraph",
".",
"onNodeTypeRegistered",
"(",
"type",
",",
"base_class",
")",
";",
"}",
"if",
"(",
"prev",
"&&",
"LiteGraph",
".",
"onNodeTypeReplaced",
")",
"{",
"LiteGraph",
".",
"onNodeTypeReplaced",
"(",
"type",
",",
"base_class",
",",
"prev",
")",
";",
"}",
"//warnings",
"if",
"(",
"base_class",
".",
"prototype",
".",
"onPropertyChange",
")",
"{",
"console",
".",
"warn",
"(",
"\"LiteGraph node class \"",
"+",
"type",
"+",
"\" has onPropertyChange method, it must be called onPropertyChanged with d at the end\"",
")",
";",
"}",
"if",
"(",
"base_class",
".",
"supported_extensions",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"base_class",
".",
"supported_extensions",
")",
"{",
"this",
".",
"node_types_by_file_extension",
"[",
"base_class",
".",
"supported_extensions",
"[",
"i",
"]",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"base_class",
";",
"}",
"}",
"}"
] |
used to add extra features to the search box
Register a node class so it can be listed when the user wants to create a new one
@method registerNodeType
@param {String} type name of the node and path
@param {Class} base_class class containing the structure of a node
|
[
"used",
"to",
"add",
"extra",
"features",
"to",
"the",
"search",
"box",
"Register",
"a",
"node",
"class",
"so",
"it",
"can",
"be",
"listed",
"when",
"the",
"user",
"wants",
"to",
"create",
"a",
"new",
"one"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L101-L188
|
|
9,101
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function(
name,
func,
param_types,
return_type,
properties
) {
var params = Array(func.length);
var code = "";
var names = LiteGraph.getParameterNames(func);
for (var i = 0; i < names.length; ++i) {
code +=
"this.addInput('" +
names[i] +
"'," +
(param_types && param_types[i]
? "'" + param_types[i] + "'"
: "0") +
");\n";
}
code +=
"this.addOutput('out'," +
(return_type ? "'" + return_type + "'" : 0) +
");\n";
if (properties) {
code +=
"this.properties = " + JSON.stringify(properties) + ";\n";
}
var classobj = Function(code);
classobj.title = name.split("/").pop();
classobj.desc = "Generated from " + func.name;
classobj.prototype.onExecute = function onExecute() {
for (var i = 0; i < params.length; ++i) {
params[i] = this.getInputData(i);
}
var r = func.apply(this, params);
this.setOutputData(0, r);
};
this.registerNodeType(name, classobj);
}
|
javascript
|
function(
name,
func,
param_types,
return_type,
properties
) {
var params = Array(func.length);
var code = "";
var names = LiteGraph.getParameterNames(func);
for (var i = 0; i < names.length; ++i) {
code +=
"this.addInput('" +
names[i] +
"'," +
(param_types && param_types[i]
? "'" + param_types[i] + "'"
: "0") +
");\n";
}
code +=
"this.addOutput('out'," +
(return_type ? "'" + return_type + "'" : 0) +
");\n";
if (properties) {
code +=
"this.properties = " + JSON.stringify(properties) + ";\n";
}
var classobj = Function(code);
classobj.title = name.split("/").pop();
classobj.desc = "Generated from " + func.name;
classobj.prototype.onExecute = function onExecute() {
for (var i = 0; i < params.length; ++i) {
params[i] = this.getInputData(i);
}
var r = func.apply(this, params);
this.setOutputData(0, r);
};
this.registerNodeType(name, classobj);
}
|
[
"function",
"(",
"name",
",",
"func",
",",
"param_types",
",",
"return_type",
",",
"properties",
")",
"{",
"var",
"params",
"=",
"Array",
"(",
"func",
".",
"length",
")",
";",
"var",
"code",
"=",
"\"\"",
";",
"var",
"names",
"=",
"LiteGraph",
".",
"getParameterNames",
"(",
"func",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"names",
".",
"length",
";",
"++",
"i",
")",
"{",
"code",
"+=",
"\"this.addInput('\"",
"+",
"names",
"[",
"i",
"]",
"+",
"\"',\"",
"+",
"(",
"param_types",
"&&",
"param_types",
"[",
"i",
"]",
"?",
"\"'\"",
"+",
"param_types",
"[",
"i",
"]",
"+",
"\"'\"",
":",
"\"0\"",
")",
"+",
"\");\\n\"",
";",
"}",
"code",
"+=",
"\"this.addOutput('out',\"",
"+",
"(",
"return_type",
"?",
"\"'\"",
"+",
"return_type",
"+",
"\"'\"",
":",
"0",
")",
"+",
"\");\\n\"",
";",
"if",
"(",
"properties",
")",
"{",
"code",
"+=",
"\"this.properties = \"",
"+",
"JSON",
".",
"stringify",
"(",
"properties",
")",
"+",
"\";\\n\"",
";",
"}",
"var",
"classobj",
"=",
"Function",
"(",
"code",
")",
";",
"classobj",
".",
"title",
"=",
"name",
".",
"split",
"(",
"\"/\"",
")",
".",
"pop",
"(",
")",
";",
"classobj",
".",
"desc",
"=",
"\"Generated from \"",
"+",
"func",
".",
"name",
";",
"classobj",
".",
"prototype",
".",
"onExecute",
"=",
"function",
"onExecute",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"params",
".",
"length",
";",
"++",
"i",
")",
"{",
"params",
"[",
"i",
"]",
"=",
"this",
".",
"getInputData",
"(",
"i",
")",
";",
"}",
"var",
"r",
"=",
"func",
".",
"apply",
"(",
"this",
",",
"params",
")",
";",
"this",
".",
"setOutputData",
"(",
"0",
",",
"r",
")",
";",
"}",
";",
"this",
".",
"registerNodeType",
"(",
"name",
",",
"classobj",
")",
";",
"}"
] |
Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function.
Useful to wrap simple methods that do not require properties, and that only process some input to generate an output.
@method wrapFunctionAsNode
@param {String} name node name with namespace (p.e.: 'math/sum')
@param {Function} func
@param {Array} param_types [optional] an array containing the type of every parameter, otherwise parameters will accept any type
@param {String} return_type [optional] string with the return type, otherwise it will be generic
@param {Object} properties [optional] properties to be configurable
|
[
"Create",
"a",
"new",
"nodetype",
"by",
"passing",
"a",
"function",
"it",
"wraps",
"it",
"with",
"a",
"proper",
"class",
"and",
"generates",
"inputs",
"according",
"to",
"the",
"parameters",
"of",
"the",
"function",
".",
"Useful",
"to",
"wrap",
"simple",
"methods",
"that",
"do",
"not",
"require",
"properties",
"and",
"that",
"only",
"process",
"some",
"input",
"to",
"generate",
"an",
"output",
"."
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L200-L239
|
|
9,102
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function(type, title, options) {
var base_class = this.registered_node_types[type];
if (!base_class) {
if (LiteGraph.debug) {
console.log(
'GraphNode type "' + type + '" not registered.'
);
}
return null;
}
var prototype = base_class.prototype || base_class;
title = title || base_class.title || type;
var node = null;
if (LiteGraph.catch_exceptions) {
try {
node = new base_class(title);
} catch (err) {
console.error(err);
return null;
}
} else {
node = new base_class(title);
}
node.type = type;
if (!node.title && title) {
node.title = title;
}
if (!node.properties) {
node.properties = {};
}
if (!node.properties_info) {
node.properties_info = [];
}
if (!node.flags) {
node.flags = {};
}
if (!node.size) {
node.size = node.computeSize();
}
if (!node.pos) {
node.pos = LiteGraph.DEFAULT_POSITION.concat();
}
if (!node.mode) {
node.mode = LiteGraph.ALWAYS;
}
//extra options
if (options) {
for (var i in options) {
node[i] = options[i];
}
}
return node;
}
|
javascript
|
function(type, title, options) {
var base_class = this.registered_node_types[type];
if (!base_class) {
if (LiteGraph.debug) {
console.log(
'GraphNode type "' + type + '" not registered.'
);
}
return null;
}
var prototype = base_class.prototype || base_class;
title = title || base_class.title || type;
var node = null;
if (LiteGraph.catch_exceptions) {
try {
node = new base_class(title);
} catch (err) {
console.error(err);
return null;
}
} else {
node = new base_class(title);
}
node.type = type;
if (!node.title && title) {
node.title = title;
}
if (!node.properties) {
node.properties = {};
}
if (!node.properties_info) {
node.properties_info = [];
}
if (!node.flags) {
node.flags = {};
}
if (!node.size) {
node.size = node.computeSize();
}
if (!node.pos) {
node.pos = LiteGraph.DEFAULT_POSITION.concat();
}
if (!node.mode) {
node.mode = LiteGraph.ALWAYS;
}
//extra options
if (options) {
for (var i in options) {
node[i] = options[i];
}
}
return node;
}
|
[
"function",
"(",
"type",
",",
"title",
",",
"options",
")",
"{",
"var",
"base_class",
"=",
"this",
".",
"registered_node_types",
"[",
"type",
"]",
";",
"if",
"(",
"!",
"base_class",
")",
"{",
"if",
"(",
"LiteGraph",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"'GraphNode type \"'",
"+",
"type",
"+",
"'\" not registered.'",
")",
";",
"}",
"return",
"null",
";",
"}",
"var",
"prototype",
"=",
"base_class",
".",
"prototype",
"||",
"base_class",
";",
"title",
"=",
"title",
"||",
"base_class",
".",
"title",
"||",
"type",
";",
"var",
"node",
"=",
"null",
";",
"if",
"(",
"LiteGraph",
".",
"catch_exceptions",
")",
"{",
"try",
"{",
"node",
"=",
"new",
"base_class",
"(",
"title",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"node",
"=",
"new",
"base_class",
"(",
"title",
")",
";",
"}",
"node",
".",
"type",
"=",
"type",
";",
"if",
"(",
"!",
"node",
".",
"title",
"&&",
"title",
")",
"{",
"node",
".",
"title",
"=",
"title",
";",
"}",
"if",
"(",
"!",
"node",
".",
"properties",
")",
"{",
"node",
".",
"properties",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"node",
".",
"properties_info",
")",
"{",
"node",
".",
"properties_info",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"node",
".",
"flags",
")",
"{",
"node",
".",
"flags",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"node",
".",
"size",
")",
"{",
"node",
".",
"size",
"=",
"node",
".",
"computeSize",
"(",
")",
";",
"}",
"if",
"(",
"!",
"node",
".",
"pos",
")",
"{",
"node",
".",
"pos",
"=",
"LiteGraph",
".",
"DEFAULT_POSITION",
".",
"concat",
"(",
")",
";",
"}",
"if",
"(",
"!",
"node",
".",
"mode",
")",
"{",
"node",
".",
"mode",
"=",
"LiteGraph",
".",
"ALWAYS",
";",
"}",
"//extra options",
"if",
"(",
"options",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"options",
")",
"{",
"node",
"[",
"i",
"]",
"=",
"options",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"node",
";",
"}"
] |
Create a node of a given type with a name. The node is not attached to any graph yet.
@method createNode
@param {String} type full name of the node class. p.e. "math/sin"
@param {String} name a name to distinguish from other nodes
@param {Object} options to set options
|
[
"Create",
"a",
"node",
"of",
"a",
"given",
"type",
"with",
"a",
"name",
".",
"The",
"node",
"is",
"not",
"attached",
"to",
"any",
"graph",
"yet",
"."
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L266-L326
|
|
9,103
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function(category, filter) {
var r = [];
for (var i in this.registered_node_types) {
var type = this.registered_node_types[i];
if (filter && type.filter && type.filter != filter) {
continue;
}
if (category == "") {
if (type.category == null) {
r.push(type);
}
} else if (type.category == category) {
r.push(type);
}
}
return r;
}
|
javascript
|
function(category, filter) {
var r = [];
for (var i in this.registered_node_types) {
var type = this.registered_node_types[i];
if (filter && type.filter && type.filter != filter) {
continue;
}
if (category == "") {
if (type.category == null) {
r.push(type);
}
} else if (type.category == category) {
r.push(type);
}
}
return r;
}
|
[
"function",
"(",
"category",
",",
"filter",
")",
"{",
"var",
"r",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"in",
"this",
".",
"registered_node_types",
")",
"{",
"var",
"type",
"=",
"this",
".",
"registered_node_types",
"[",
"i",
"]",
";",
"if",
"(",
"filter",
"&&",
"type",
".",
"filter",
"&&",
"type",
".",
"filter",
"!=",
"filter",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"category",
"==",
"\"\"",
")",
"{",
"if",
"(",
"type",
".",
"category",
"==",
"null",
")",
"{",
"r",
".",
"push",
"(",
"type",
")",
";",
"}",
"}",
"else",
"if",
"(",
"type",
".",
"category",
"==",
"category",
")",
"{",
"r",
".",
"push",
"(",
"type",
")",
";",
"}",
"}",
"return",
"r",
";",
"}"
] |
Returns a list of node types matching one category
@method getNodeType
@param {String} category category name
@return {Array} array with all the node classes
|
[
"Returns",
"a",
"list",
"of",
"node",
"types",
"matching",
"one",
"category"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L345-L363
|
|
9,104
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function() {
var categories = { "": 1 };
for (var i in this.registered_node_types) {
if (
this.registered_node_types[i].category &&
!this.registered_node_types[i].skip_list
) {
categories[this.registered_node_types[i].category] = 1;
}
}
var result = [];
for (var i in categories) {
result.push(i);
}
return result;
}
|
javascript
|
function() {
var categories = { "": 1 };
for (var i in this.registered_node_types) {
if (
this.registered_node_types[i].category &&
!this.registered_node_types[i].skip_list
) {
categories[this.registered_node_types[i].category] = 1;
}
}
var result = [];
for (var i in categories) {
result.push(i);
}
return result;
}
|
[
"function",
"(",
")",
"{",
"var",
"categories",
"=",
"{",
"\"\"",
":",
"1",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"this",
".",
"registered_node_types",
")",
"{",
"if",
"(",
"this",
".",
"registered_node_types",
"[",
"i",
"]",
".",
"category",
"&&",
"!",
"this",
".",
"registered_node_types",
"[",
"i",
"]",
".",
"skip_list",
")",
"{",
"categories",
"[",
"this",
".",
"registered_node_types",
"[",
"i",
"]",
".",
"category",
"]",
"=",
"1",
";",
"}",
"}",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"in",
"categories",
")",
"{",
"result",
".",
"push",
"(",
"i",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Returns a list with all the node type categories
@method getNodeTypesCategories
@return {Array} array with all the names of the categories
|
[
"Returns",
"a",
"list",
"with",
"all",
"the",
"node",
"type",
"categories"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L371-L386
|
|
9,105
|
jagenjo/litegraph.js
|
build/litegraph.js
|
function(obj, target) {
if (obj == null) {
return null;
}
var r = JSON.parse(JSON.stringify(obj));
if (!target) {
return r;
}
for (var i in r) {
target[i] = r[i];
}
return target;
}
|
javascript
|
function(obj, target) {
if (obj == null) {
return null;
}
var r = JSON.parse(JSON.stringify(obj));
if (!target) {
return r;
}
for (var i in r) {
target[i] = r[i];
}
return target;
}
|
[
"function",
"(",
"obj",
",",
"target",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"var",
"r",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"obj",
")",
")",
";",
"if",
"(",
"!",
"target",
")",
"{",
"return",
"r",
";",
"}",
"for",
"(",
"var",
"i",
"in",
"r",
")",
"{",
"target",
"[",
"i",
"]",
"=",
"r",
"[",
"i",
"]",
";",
"}",
"return",
"target",
";",
"}"
] |
separated just to improve if it doesn't work
|
[
"separated",
"just",
"to",
"improve",
"if",
"it",
"doesn",
"t",
"work"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L434-L447
|
|
9,106
|
jagenjo/litegraph.js
|
build/litegraph.js
|
LLink
|
function LLink(id, type, origin_id, origin_slot, target_id, target_slot) {
this.id = id;
this.type = type;
this.origin_id = origin_id;
this.origin_slot = origin_slot;
this.target_id = target_id;
this.target_slot = target_slot;
this._data = null;
this._pos = new Float32Array(2); //center
}
|
javascript
|
function LLink(id, type, origin_id, origin_slot, target_id, target_slot) {
this.id = id;
this.type = type;
this.origin_id = origin_id;
this.origin_slot = origin_slot;
this.target_id = target_id;
this.target_slot = target_slot;
this._data = null;
this._pos = new Float32Array(2); //center
}
|
[
"function",
"LLink",
"(",
"id",
",",
"type",
",",
"origin_id",
",",
"origin_slot",
",",
"target_id",
",",
"target_slot",
")",
"{",
"this",
".",
"id",
"=",
"id",
";",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"origin_id",
"=",
"origin_id",
";",
"this",
".",
"origin_slot",
"=",
"origin_slot",
";",
"this",
".",
"target_id",
"=",
"target_id",
";",
"this",
".",
"target_slot",
"=",
"target_slot",
";",
"this",
".",
"_data",
"=",
"null",
";",
"this",
".",
"_pos",
"=",
"new",
"Float32Array",
"(",
"2",
")",
";",
"//center",
"}"
] |
this is the class in charge of storing link information
|
[
"this",
"is",
"the",
"class",
"in",
"charge",
"of",
"storing",
"link",
"information"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L1954-L1964
|
9,107
|
jagenjo/litegraph.js
|
build/litegraph.js
|
isInsideBounding
|
function isInsideBounding(p, bb) {
if (
p[0] < bb[0][0] ||
p[1] < bb[0][1] ||
p[0] > bb[1][0] ||
p[1] > bb[1][1]
) {
return false;
}
return true;
}
|
javascript
|
function isInsideBounding(p, bb) {
if (
p[0] < bb[0][0] ||
p[1] < bb[0][1] ||
p[0] > bb[1][0] ||
p[1] > bb[1][1]
) {
return false;
}
return true;
}
|
[
"function",
"isInsideBounding",
"(",
"p",
",",
"bb",
")",
"{",
"if",
"(",
"p",
"[",
"0",
"]",
"<",
"bb",
"[",
"0",
"]",
"[",
"0",
"]",
"||",
"p",
"[",
"1",
"]",
"<",
"bb",
"[",
"0",
"]",
"[",
"1",
"]",
"||",
"p",
"[",
"0",
"]",
">",
"bb",
"[",
"1",
"]",
"[",
"0",
"]",
"||",
"p",
"[",
"1",
"]",
">",
"bb",
"[",
"1",
"]",
"[",
"1",
"]",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
point inside bounding box
|
[
"point",
"inside",
"bounding",
"box"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L9994-L10004
|
9,108
|
jagenjo/litegraph.js
|
build/litegraph.js
|
hex2num
|
function hex2num(hex) {
if (hex.charAt(0) == "#") {
hex = hex.slice(1);
} //Remove the '#' char - if there is one.
hex = hex.toUpperCase();
var hex_alphabets = "0123456789ABCDEF";
var value = new Array(3);
var k = 0;
var int1, int2;
for (var i = 0; i < 6; i += 2) {
int1 = hex_alphabets.indexOf(hex.charAt(i));
int2 = hex_alphabets.indexOf(hex.charAt(i + 1));
value[k] = int1 * 16 + int2;
k++;
}
return value;
}
|
javascript
|
function hex2num(hex) {
if (hex.charAt(0) == "#") {
hex = hex.slice(1);
} //Remove the '#' char - if there is one.
hex = hex.toUpperCase();
var hex_alphabets = "0123456789ABCDEF";
var value = new Array(3);
var k = 0;
var int1, int2;
for (var i = 0; i < 6; i += 2) {
int1 = hex_alphabets.indexOf(hex.charAt(i));
int2 = hex_alphabets.indexOf(hex.charAt(i + 1));
value[k] = int1 * 16 + int2;
k++;
}
return value;
}
|
[
"function",
"hex2num",
"(",
"hex",
")",
"{",
"if",
"(",
"hex",
".",
"charAt",
"(",
"0",
")",
"==",
"\"#\"",
")",
"{",
"hex",
"=",
"hex",
".",
"slice",
"(",
"1",
")",
";",
"}",
"//Remove the '#' char - if there is one.",
"hex",
"=",
"hex",
".",
"toUpperCase",
"(",
")",
";",
"var",
"hex_alphabets",
"=",
"\"0123456789ABCDEF\"",
";",
"var",
"value",
"=",
"new",
"Array",
"(",
"3",
")",
";",
"var",
"k",
"=",
"0",
";",
"var",
"int1",
",",
"int2",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"6",
";",
"i",
"+=",
"2",
")",
"{",
"int1",
"=",
"hex_alphabets",
".",
"indexOf",
"(",
"hex",
".",
"charAt",
"(",
"i",
")",
")",
";",
"int2",
"=",
"hex_alphabets",
".",
"indexOf",
"(",
"hex",
".",
"charAt",
"(",
"i",
"+",
"1",
")",
")",
";",
"value",
"[",
"k",
"]",
"=",
"int1",
"*",
"16",
"+",
"int2",
";",
"k",
"++",
";",
"}",
"return",
"value",
";",
"}"
] |
Convert a hex value to its decimal value - the inputted hex must be in the format of a hex triplet - the kind we use for HTML colours. The function will return an array with three values.
|
[
"Convert",
"a",
"hex",
"value",
"to",
"its",
"decimal",
"value",
"-",
"the",
"inputted",
"hex",
"must",
"be",
"in",
"the",
"format",
"of",
"a",
"hex",
"triplet",
"-",
"the",
"kind",
"we",
"use",
"for",
"HTML",
"colours",
".",
"The",
"function",
"will",
"return",
"an",
"array",
"with",
"three",
"values",
"."
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L10029-L10045
|
9,109
|
jagenjo/litegraph.js
|
build/litegraph.js
|
num2hex
|
function num2hex(triplet) {
var hex_alphabets = "0123456789ABCDEF";
var hex = "#";
var int1, int2;
for (var i = 0; i < 3; i++) {
int1 = triplet[i] / 16;
int2 = triplet[i] % 16;
hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2);
}
return hex;
}
|
javascript
|
function num2hex(triplet) {
var hex_alphabets = "0123456789ABCDEF";
var hex = "#";
var int1, int2;
for (var i = 0; i < 3; i++) {
int1 = triplet[i] / 16;
int2 = triplet[i] % 16;
hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2);
}
return hex;
}
|
[
"function",
"num2hex",
"(",
"triplet",
")",
"{",
"var",
"hex_alphabets",
"=",
"\"0123456789ABCDEF\"",
";",
"var",
"hex",
"=",
"\"#\"",
";",
"var",
"int1",
",",
"int2",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"int1",
"=",
"triplet",
"[",
"i",
"]",
"/",
"16",
";",
"int2",
"=",
"triplet",
"[",
"i",
"]",
"%",
"16",
";",
"hex",
"+=",
"hex_alphabets",
".",
"charAt",
"(",
"int1",
")",
"+",
"hex_alphabets",
".",
"charAt",
"(",
"int2",
")",
";",
"}",
"return",
"hex",
";",
"}"
] |
Give a array with three values as the argument and the function will return the corresponding hex triplet.
|
[
"Give",
"a",
"array",
"with",
"three",
"values",
"as",
"the",
"argument",
"and",
"the",
"function",
"will",
"return",
"the",
"corresponding",
"hex",
"triplet",
"."
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L10051-L10062
|
9,110
|
jagenjo/litegraph.js
|
build/litegraph.js
|
inner_onclick
|
function inner_onclick(e) {
var value = this.value;
var close_parent = true;
if (that.current_submenu) {
that.current_submenu.close(e);
}
//global callback
if (options.callback) {
var r = options.callback.call(
this,
value,
options,
e,
that,
options.node
);
if (r === true) {
close_parent = false;
}
}
//special cases
if (value) {
if (
value.callback &&
!options.ignore_item_callbacks &&
value.disabled !== true
) {
//item callback
var r = value.callback.call(
this,
value,
options,
e,
that,
options.extra
);
if (r === true) {
close_parent = false;
}
}
if (value.submenu) {
if (!value.submenu.options) {
throw "ContextMenu submenu needs options";
}
var submenu = new that.constructor(value.submenu.options, {
callback: value.submenu.callback,
event: e,
parentMenu: that,
ignore_item_callbacks:
value.submenu.ignore_item_callbacks,
title: value.submenu.title,
extra: value.submenu.extra,
autoopen: options.autoopen
});
close_parent = false;
}
}
if (close_parent && !that.lock) {
that.close();
}
}
|
javascript
|
function inner_onclick(e) {
var value = this.value;
var close_parent = true;
if (that.current_submenu) {
that.current_submenu.close(e);
}
//global callback
if (options.callback) {
var r = options.callback.call(
this,
value,
options,
e,
that,
options.node
);
if (r === true) {
close_parent = false;
}
}
//special cases
if (value) {
if (
value.callback &&
!options.ignore_item_callbacks &&
value.disabled !== true
) {
//item callback
var r = value.callback.call(
this,
value,
options,
e,
that,
options.extra
);
if (r === true) {
close_parent = false;
}
}
if (value.submenu) {
if (!value.submenu.options) {
throw "ContextMenu submenu needs options";
}
var submenu = new that.constructor(value.submenu.options, {
callback: value.submenu.callback,
event: e,
parentMenu: that,
ignore_item_callbacks:
value.submenu.ignore_item_callbacks,
title: value.submenu.title,
extra: value.submenu.extra,
autoopen: options.autoopen
});
close_parent = false;
}
}
if (close_parent && !that.lock) {
that.close();
}
}
|
[
"function",
"inner_onclick",
"(",
"e",
")",
"{",
"var",
"value",
"=",
"this",
".",
"value",
";",
"var",
"close_parent",
"=",
"true",
";",
"if",
"(",
"that",
".",
"current_submenu",
")",
"{",
"that",
".",
"current_submenu",
".",
"close",
"(",
"e",
")",
";",
"}",
"//global callback",
"if",
"(",
"options",
".",
"callback",
")",
"{",
"var",
"r",
"=",
"options",
".",
"callback",
".",
"call",
"(",
"this",
",",
"value",
",",
"options",
",",
"e",
",",
"that",
",",
"options",
".",
"node",
")",
";",
"if",
"(",
"r",
"===",
"true",
")",
"{",
"close_parent",
"=",
"false",
";",
"}",
"}",
"//special cases",
"if",
"(",
"value",
")",
"{",
"if",
"(",
"value",
".",
"callback",
"&&",
"!",
"options",
".",
"ignore_item_callbacks",
"&&",
"value",
".",
"disabled",
"!==",
"true",
")",
"{",
"//item callback",
"var",
"r",
"=",
"value",
".",
"callback",
".",
"call",
"(",
"this",
",",
"value",
",",
"options",
",",
"e",
",",
"that",
",",
"options",
".",
"extra",
")",
";",
"if",
"(",
"r",
"===",
"true",
")",
"{",
"close_parent",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"value",
".",
"submenu",
")",
"{",
"if",
"(",
"!",
"value",
".",
"submenu",
".",
"options",
")",
"{",
"throw",
"\"ContextMenu submenu needs options\"",
";",
"}",
"var",
"submenu",
"=",
"new",
"that",
".",
"constructor",
"(",
"value",
".",
"submenu",
".",
"options",
",",
"{",
"callback",
":",
"value",
".",
"submenu",
".",
"callback",
",",
"event",
":",
"e",
",",
"parentMenu",
":",
"that",
",",
"ignore_item_callbacks",
":",
"value",
".",
"submenu",
".",
"ignore_item_callbacks",
",",
"title",
":",
"value",
".",
"submenu",
".",
"title",
",",
"extra",
":",
"value",
".",
"submenu",
".",
"extra",
",",
"autoopen",
":",
"options",
".",
"autoopen",
"}",
")",
";",
"close_parent",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"close_parent",
"&&",
"!",
"that",
".",
"lock",
")",
"{",
"that",
".",
"close",
"(",
")",
";",
"}",
"}"
] |
menu option clicked
|
[
"menu",
"option",
"clicked"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L10313-L10377
|
9,111
|
jagenjo/litegraph.js
|
build/litegraph.js
|
GraphInput
|
function GraphInput() {
this.addOutput("", "");
this.name_in_graph = "";
this.properties = {};
var that = this;
Object.defineProperty(this.properties, "name", {
get: function() {
return that.name_in_graph;
},
set: function(v) {
if (v == "" || v == that.name_in_graph || v == "enabled") {
return;
}
if (that.name_in_graph) {
//already added
that.graph.renameInput(that.name_in_graph, v);
} else {
that.graph.addInput(v, that.properties.type);
}
that.name_widget.value = v;
that.name_in_graph = v;
},
enumerable: true
});
Object.defineProperty(this.properties, "type", {
get: function() {
return that.outputs[0].type;
},
set: function(v) {
if (v == "event") {
v = LiteGraph.EVENT;
}
that.outputs[0].type = v;
if (that.name_in_graph) {
//already added
that.graph.changeInputType(
that.name_in_graph,
that.outputs[0].type
);
}
that.type_widget.value = v;
},
enumerable: true
});
this.name_widget = this.addWidget(
"text",
"Name",
this.properties.name,
function(v) {
if (!v) {
return;
}
that.properties.name = v;
}
);
this.type_widget = this.addWidget(
"text",
"Type",
this.properties.type,
function(v) {
v = v || "";
that.properties.type = v;
}
);
this.widgets_up = true;
this.size = [180, 60];
}
|
javascript
|
function GraphInput() {
this.addOutput("", "");
this.name_in_graph = "";
this.properties = {};
var that = this;
Object.defineProperty(this.properties, "name", {
get: function() {
return that.name_in_graph;
},
set: function(v) {
if (v == "" || v == that.name_in_graph || v == "enabled") {
return;
}
if (that.name_in_graph) {
//already added
that.graph.renameInput(that.name_in_graph, v);
} else {
that.graph.addInput(v, that.properties.type);
}
that.name_widget.value = v;
that.name_in_graph = v;
},
enumerable: true
});
Object.defineProperty(this.properties, "type", {
get: function() {
return that.outputs[0].type;
},
set: function(v) {
if (v == "event") {
v = LiteGraph.EVENT;
}
that.outputs[0].type = v;
if (that.name_in_graph) {
//already added
that.graph.changeInputType(
that.name_in_graph,
that.outputs[0].type
);
}
that.type_widget.value = v;
},
enumerable: true
});
this.name_widget = this.addWidget(
"text",
"Name",
this.properties.name,
function(v) {
if (!v) {
return;
}
that.properties.name = v;
}
);
this.type_widget = this.addWidget(
"text",
"Type",
this.properties.type,
function(v) {
v = v || "";
that.properties.type = v;
}
);
this.widgets_up = true;
this.size = [180, 60];
}
|
[
"function",
"GraphInput",
"(",
")",
"{",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"\"\"",
")",
";",
"this",
".",
"name_in_graph",
"=",
"\"\"",
";",
"this",
".",
"properties",
"=",
"{",
"}",
";",
"var",
"that",
"=",
"this",
";",
"Object",
".",
"defineProperty",
"(",
"this",
".",
"properties",
",",
"\"name\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"that",
".",
"name_in_graph",
";",
"}",
",",
"set",
":",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
"==",
"\"\"",
"||",
"v",
"==",
"that",
".",
"name_in_graph",
"||",
"v",
"==",
"\"enabled\"",
")",
"{",
"return",
";",
"}",
"if",
"(",
"that",
".",
"name_in_graph",
")",
"{",
"//already added",
"that",
".",
"graph",
".",
"renameInput",
"(",
"that",
".",
"name_in_graph",
",",
"v",
")",
";",
"}",
"else",
"{",
"that",
".",
"graph",
".",
"addInput",
"(",
"v",
",",
"that",
".",
"properties",
".",
"type",
")",
";",
"}",
"that",
".",
"name_widget",
".",
"value",
"=",
"v",
";",
"that",
".",
"name_in_graph",
"=",
"v",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
".",
"properties",
",",
"\"type\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"that",
".",
"outputs",
"[",
"0",
"]",
".",
"type",
";",
"}",
",",
"set",
":",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
"==",
"\"event\"",
")",
"{",
"v",
"=",
"LiteGraph",
".",
"EVENT",
";",
"}",
"that",
".",
"outputs",
"[",
"0",
"]",
".",
"type",
"=",
"v",
";",
"if",
"(",
"that",
".",
"name_in_graph",
")",
"{",
"//already added",
"that",
".",
"graph",
".",
"changeInputType",
"(",
"that",
".",
"name_in_graph",
",",
"that",
".",
"outputs",
"[",
"0",
"]",
".",
"type",
")",
";",
"}",
"that",
".",
"type_widget",
".",
"value",
"=",
"v",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"this",
".",
"name_widget",
"=",
"this",
".",
"addWidget",
"(",
"\"text\"",
",",
"\"Name\"",
",",
"this",
".",
"properties",
".",
"name",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"!",
"v",
")",
"{",
"return",
";",
"}",
"that",
".",
"properties",
".",
"name",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"type_widget",
"=",
"this",
".",
"addWidget",
"(",
"\"text\"",
",",
"\"Type\"",
",",
"this",
".",
"properties",
".",
"type",
",",
"function",
"(",
"v",
")",
"{",
"v",
"=",
"v",
"||",
"\"\"",
";",
"that",
".",
"properties",
".",
"type",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"widgets_up",
"=",
"true",
";",
"this",
".",
"size",
"=",
"[",
"180",
",",
"60",
"]",
";",
"}"
] |
Input for a subgraph
|
[
"Input",
"for",
"a",
"subgraph"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L10798-L10869
|
9,112
|
jagenjo/litegraph.js
|
build/litegraph.js
|
GraphOutput
|
function GraphOutput() {
this.addInput("", "");
this.name_in_graph = "";
this.properties = {};
var that = this;
Object.defineProperty(this.properties, "name", {
get: function() {
return that.name_in_graph;
},
set: function(v) {
if (v == "" || v == that.name_in_graph) {
return;
}
if (that.name_in_graph) {
//already added
that.graph.renameOutput(that.name_in_graph, v);
} else {
that.graph.addOutput(v, that.properties.type);
}
that.name_widget.value = v;
that.name_in_graph = v;
},
enumerable: true
});
Object.defineProperty(this.properties, "type", {
get: function() {
return that.inputs[0].type;
},
set: function(v) {
if (v == "action" || v == "event") {
v = LiteGraph.ACTION;
}
that.inputs[0].type = v;
if (that.name_in_graph) {
//already added
that.graph.changeOutputType(
that.name_in_graph,
that.inputs[0].type
);
}
that.type_widget.value = v || "";
},
enumerable: true
});
this.name_widget = this.addWidget(
"text",
"Name",
this.properties.name,
function(v) {
if (!v) {
return;
}
that.properties.name = v;
}
);
this.type_widget = this.addWidget(
"text",
"Type",
this.properties.type,
function(v) {
v = v || "";
that.properties.type = v;
}
);
this.widgets_up = true;
this.size = [180, 60];
}
|
javascript
|
function GraphOutput() {
this.addInput("", "");
this.name_in_graph = "";
this.properties = {};
var that = this;
Object.defineProperty(this.properties, "name", {
get: function() {
return that.name_in_graph;
},
set: function(v) {
if (v == "" || v == that.name_in_graph) {
return;
}
if (that.name_in_graph) {
//already added
that.graph.renameOutput(that.name_in_graph, v);
} else {
that.graph.addOutput(v, that.properties.type);
}
that.name_widget.value = v;
that.name_in_graph = v;
},
enumerable: true
});
Object.defineProperty(this.properties, "type", {
get: function() {
return that.inputs[0].type;
},
set: function(v) {
if (v == "action" || v == "event") {
v = LiteGraph.ACTION;
}
that.inputs[0].type = v;
if (that.name_in_graph) {
//already added
that.graph.changeOutputType(
that.name_in_graph,
that.inputs[0].type
);
}
that.type_widget.value = v || "";
},
enumerable: true
});
this.name_widget = this.addWidget(
"text",
"Name",
this.properties.name,
function(v) {
if (!v) {
return;
}
that.properties.name = v;
}
);
this.type_widget = this.addWidget(
"text",
"Type",
this.properties.type,
function(v) {
v = v || "";
that.properties.type = v;
}
);
this.widgets_up = true;
this.size = [180, 60];
}
|
[
"function",
"GraphOutput",
"(",
")",
"{",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"\"\"",
")",
";",
"this",
".",
"name_in_graph",
"=",
"\"\"",
";",
"this",
".",
"properties",
"=",
"{",
"}",
";",
"var",
"that",
"=",
"this",
";",
"Object",
".",
"defineProperty",
"(",
"this",
".",
"properties",
",",
"\"name\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"that",
".",
"name_in_graph",
";",
"}",
",",
"set",
":",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
"==",
"\"\"",
"||",
"v",
"==",
"that",
".",
"name_in_graph",
")",
"{",
"return",
";",
"}",
"if",
"(",
"that",
".",
"name_in_graph",
")",
"{",
"//already added",
"that",
".",
"graph",
".",
"renameOutput",
"(",
"that",
".",
"name_in_graph",
",",
"v",
")",
";",
"}",
"else",
"{",
"that",
".",
"graph",
".",
"addOutput",
"(",
"v",
",",
"that",
".",
"properties",
".",
"type",
")",
";",
"}",
"that",
".",
"name_widget",
".",
"value",
"=",
"v",
";",
"that",
".",
"name_in_graph",
"=",
"v",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
".",
"properties",
",",
"\"type\"",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"that",
".",
"inputs",
"[",
"0",
"]",
".",
"type",
";",
"}",
",",
"set",
":",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
"==",
"\"action\"",
"||",
"v",
"==",
"\"event\"",
")",
"{",
"v",
"=",
"LiteGraph",
".",
"ACTION",
";",
"}",
"that",
".",
"inputs",
"[",
"0",
"]",
".",
"type",
"=",
"v",
";",
"if",
"(",
"that",
".",
"name_in_graph",
")",
"{",
"//already added",
"that",
".",
"graph",
".",
"changeOutputType",
"(",
"that",
".",
"name_in_graph",
",",
"that",
".",
"inputs",
"[",
"0",
"]",
".",
"type",
")",
";",
"}",
"that",
".",
"type_widget",
".",
"value",
"=",
"v",
"||",
"\"\"",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"this",
".",
"name_widget",
"=",
"this",
".",
"addWidget",
"(",
"\"text\"",
",",
"\"Name\"",
",",
"this",
".",
"properties",
".",
"name",
",",
"function",
"(",
"v",
")",
"{",
"if",
"(",
"!",
"v",
")",
"{",
"return",
";",
"}",
"that",
".",
"properties",
".",
"name",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"type_widget",
"=",
"this",
".",
"addWidget",
"(",
"\"text\"",
",",
"\"Type\"",
",",
"this",
".",
"properties",
".",
"type",
",",
"function",
"(",
"v",
")",
"{",
"v",
"=",
"v",
"||",
"\"\"",
";",
"that",
".",
"properties",
".",
"type",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"widgets_up",
"=",
"true",
";",
"this",
".",
"size",
"=",
"[",
"180",
",",
"60",
"]",
";",
"}"
] |
Output for a subgraph
|
[
"Output",
"for",
"a",
"subgraph"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L10910-L10981
|
9,113
|
jagenjo/litegraph.js
|
build/litegraph.js
|
Sequencer
|
function Sequencer() {
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.size = [120, 30];
this.flags = { horizontal: true, render_box: false };
}
|
javascript
|
function Sequencer() {
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addInput("", LiteGraph.ACTION);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.addOutput("", LiteGraph.EVENT);
this.size = [120, 30];
this.flags = { horizontal: true, render_box: false };
}
|
[
"function",
"Sequencer",
"(",
")",
"{",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addInput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"ACTION",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"LiteGraph",
".",
"EVENT",
")",
";",
"this",
".",
"size",
"=",
"[",
"120",
",",
"30",
"]",
";",
"this",
".",
"flags",
"=",
"{",
"horizontal",
":",
"true",
",",
"render_box",
":",
"false",
"}",
";",
"}"
] |
Sequencer for events
|
[
"Sequencer",
"for",
"events"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L11397-L11412
|
9,114
|
jagenjo/litegraph.js
|
build/litegraph.js
|
MathFormula
|
function MathFormula() {
this.addInput("x", "number");
this.addInput("y", "number");
this.addOutput("", "number");
this.properties = { x: 1.0, y: 1.0, formula: "x+y" };
this.code_widget = this.addWidget(
"text",
"F(x,y)",
this.properties.formula,
function(v, canvas, node) {
node.properties.formula = v;
}
);
this.addWidget("toggle", "allow", LiteGraph.allow_scripts, function(v) {
LiteGraph.allow_scripts = v;
});
this._func = null;
}
|
javascript
|
function MathFormula() {
this.addInput("x", "number");
this.addInput("y", "number");
this.addOutput("", "number");
this.properties = { x: 1.0, y: 1.0, formula: "x+y" };
this.code_widget = this.addWidget(
"text",
"F(x,y)",
this.properties.formula,
function(v, canvas, node) {
node.properties.formula = v;
}
);
this.addWidget("toggle", "allow", LiteGraph.allow_scripts, function(v) {
LiteGraph.allow_scripts = v;
});
this._func = null;
}
|
[
"function",
"MathFormula",
"(",
")",
"{",
"this",
".",
"addInput",
"(",
"\"x\"",
",",
"\"number\"",
")",
";",
"this",
".",
"addInput",
"(",
"\"y\"",
",",
"\"number\"",
")",
";",
"this",
".",
"addOutput",
"(",
"\"\"",
",",
"\"number\"",
")",
";",
"this",
".",
"properties",
"=",
"{",
"x",
":",
"1.0",
",",
"y",
":",
"1.0",
",",
"formula",
":",
"\"x+y\"",
"}",
";",
"this",
".",
"code_widget",
"=",
"this",
".",
"addWidget",
"(",
"\"text\"",
",",
"\"F(x,y)\"",
",",
"this",
".",
"properties",
".",
"formula",
",",
"function",
"(",
"v",
",",
"canvas",
",",
"node",
")",
"{",
"node",
".",
"properties",
".",
"formula",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"addWidget",
"(",
"\"toggle\"",
",",
"\"allow\"",
",",
"LiteGraph",
".",
"allow_scripts",
",",
"function",
"(",
"v",
")",
"{",
"LiteGraph",
".",
"allow_scripts",
"=",
"v",
";",
"}",
")",
";",
"this",
".",
"_func",
"=",
"null",
";",
"}"
] |
math library for safe math operations without eval
|
[
"math",
"library",
"for",
"safe",
"math",
"operations",
"without",
"eval"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L13717-L13734
|
9,115
|
jagenjo/litegraph.js
|
build/litegraph.js
|
LGraphTextureScaleOffset
|
function LGraphTextureScaleOffset() {
this.addInput("in", "Texture");
this.addInput("scale", "vec2");
this.addInput("offset", "vec2");
this.addOutput("out", "Texture");
this.properties = {
offset: vec2.fromValues(0, 0),
scale: vec2.fromValues(1, 1),
precision: LGraphTexture.DEFAULT
};
}
|
javascript
|
function LGraphTextureScaleOffset() {
this.addInput("in", "Texture");
this.addInput("scale", "vec2");
this.addInput("offset", "vec2");
this.addOutput("out", "Texture");
this.properties = {
offset: vec2.fromValues(0, 0),
scale: vec2.fromValues(1, 1),
precision: LGraphTexture.DEFAULT
};
}
|
[
"function",
"LGraphTextureScaleOffset",
"(",
")",
"{",
"this",
".",
"addInput",
"(",
"\"in\"",
",",
"\"Texture\"",
")",
";",
"this",
".",
"addInput",
"(",
"\"scale\"",
",",
"\"vec2\"",
")",
";",
"this",
".",
"addInput",
"(",
"\"offset\"",
",",
"\"vec2\"",
")",
";",
"this",
".",
"addOutput",
"(",
"\"out\"",
",",
"\"Texture\"",
")",
";",
"this",
".",
"properties",
"=",
"{",
"offset",
":",
"vec2",
".",
"fromValues",
"(",
"0",
",",
"0",
")",
",",
"scale",
":",
"vec2",
".",
"fromValues",
"(",
"1",
",",
"1",
")",
",",
"precision",
":",
"LGraphTexture",
".",
"DEFAULT",
"}",
";",
"}"
] |
Texture Scale Offset
|
[
"Texture",
"Scale",
"Offset"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L16540-L16550
|
9,116
|
jagenjo/litegraph.js
|
build/litegraph.js
|
LGraphExposition
|
function LGraphExposition() {
this.addInput("in", "Texture");
this.addInput("exp", "number");
this.addOutput("out", "Texture");
this.properties = { exposition: 1, precision: LGraphTexture.LOW };
this._uniforms = { u_texture: 0, u_exposition: 1 };
}
|
javascript
|
function LGraphExposition() {
this.addInput("in", "Texture");
this.addInput("exp", "number");
this.addOutput("out", "Texture");
this.properties = { exposition: 1, precision: LGraphTexture.LOW };
this._uniforms = { u_texture: 0, u_exposition: 1 };
}
|
[
"function",
"LGraphExposition",
"(",
")",
"{",
"this",
".",
"addInput",
"(",
"\"in\"",
",",
"\"Texture\"",
")",
";",
"this",
".",
"addInput",
"(",
"\"exp\"",
",",
"\"number\"",
")",
";",
"this",
".",
"addOutput",
"(",
"\"out\"",
",",
"\"Texture\"",
")",
";",
"this",
".",
"properties",
"=",
"{",
"exposition",
":",
"1",
",",
"precision",
":",
"LGraphTexture",
".",
"LOW",
"}",
";",
"this",
".",
"_uniforms",
"=",
"{",
"u_texture",
":",
"0",
",",
"u_exposition",
":",
"1",
"}",
";",
"}"
] |
simple exposition, but plan to expand it to support different gamma curves
|
[
"simple",
"exposition",
"but",
"plan",
"to",
"expand",
"it",
"to",
"support",
"different",
"gamma",
"curves"
] |
b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2
|
https://github.com/jagenjo/litegraph.js/blob/b6ca97f2b1f6c3ec0be919070850a2f0df81f0b2/build/litegraph.js#L19476-L19482
|
9,117
|
rstudio/shiny-server
|
lib/router/directory-router.js
|
onDirectory
|
function onDirectory() {
var this_SendStream = this;
if (!/\/$/.test(reqUrl.pathname)) {
// No trailing slash? Redirect to add one
res.writeHead(301, {
'Location': reqUrl.pathname + '/' + (reqUrl.search || '')
});
res.end();
deferred.resolve(true);
return;
}
var indexPath = path.normalize(path.join(
self.$root, unescape(this.path), 'index.html'));
fs.exists(indexPath, function(exists) {
if (exists) {
// index.html exists, just serve that. This is the same as
// the below call except without onDirectory and without
// .index(false)
send(req, suffix, {root: self.$root})
.on('error', onError)
.on('stream', onStream)
.pipe(res);
deferred.resolve(true);
} else {
// Either serve up 404, or the directory auto-index
if (!self.$dirIndex) {
deferred.resolve(null);
} else {
deferred.resolve(
self.$autoindex_p(req, res, this_SendStream.path, self.$blacklist)
);
}
}
});
}
|
javascript
|
function onDirectory() {
var this_SendStream = this;
if (!/\/$/.test(reqUrl.pathname)) {
// No trailing slash? Redirect to add one
res.writeHead(301, {
'Location': reqUrl.pathname + '/' + (reqUrl.search || '')
});
res.end();
deferred.resolve(true);
return;
}
var indexPath = path.normalize(path.join(
self.$root, unescape(this.path), 'index.html'));
fs.exists(indexPath, function(exists) {
if (exists) {
// index.html exists, just serve that. This is the same as
// the below call except without onDirectory and without
// .index(false)
send(req, suffix, {root: self.$root})
.on('error', onError)
.on('stream', onStream)
.pipe(res);
deferred.resolve(true);
} else {
// Either serve up 404, or the directory auto-index
if (!self.$dirIndex) {
deferred.resolve(null);
} else {
deferred.resolve(
self.$autoindex_p(req, res, this_SendStream.path, self.$blacklist)
);
}
}
});
}
|
[
"function",
"onDirectory",
"(",
")",
"{",
"var",
"this_SendStream",
"=",
"this",
";",
"if",
"(",
"!",
"/",
"\\/$",
"/",
".",
"test",
"(",
"reqUrl",
".",
"pathname",
")",
")",
"{",
"// No trailing slash? Redirect to add one",
"res",
".",
"writeHead",
"(",
"301",
",",
"{",
"'Location'",
":",
"reqUrl",
".",
"pathname",
"+",
"'/'",
"+",
"(",
"reqUrl",
".",
"search",
"||",
"''",
")",
"}",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"deferred",
".",
"resolve",
"(",
"true",
")",
";",
"return",
";",
"}",
"var",
"indexPath",
"=",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"self",
".",
"$root",
",",
"unescape",
"(",
"this",
".",
"path",
")",
",",
"'index.html'",
")",
")",
";",
"fs",
".",
"exists",
"(",
"indexPath",
",",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"exists",
")",
"{",
"// index.html exists, just serve that. This is the same as",
"// the below call except without onDirectory and without",
"// .index(false)",
"send",
"(",
"req",
",",
"suffix",
",",
"{",
"root",
":",
"self",
".",
"$root",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
".",
"on",
"(",
"'stream'",
",",
"onStream",
")",
".",
"pipe",
"(",
"res",
")",
";",
"deferred",
".",
"resolve",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// Either serve up 404, or the directory auto-index",
"if",
"(",
"!",
"self",
".",
"$dirIndex",
")",
"{",
"deferred",
".",
"resolve",
"(",
"null",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
"self",
".",
"$autoindex_p",
"(",
"req",
",",
"res",
",",
"this_SendStream",
".",
"path",
",",
"self",
".",
"$blacklist",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Called when the URL requested is a directory
|
[
"Called",
"when",
"the",
"URL",
"requested",
"is",
"a",
"directory"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/router/directory-router.js#L152-L188
|
9,118
|
rstudio/shiny-server
|
lib/proxy/http.js
|
error500
|
function error500(req, res, errorText, detail, templateDir, consoleLogFile, appSpec) {
fsutil.safeTail_p(consoleLogFile, 8192)
.fail(function(consoleLog) {
return;
})
.then(function(consoleLog) {
render.sendPage(res, 500, 'An error has occurred', {
template: 'error-500',
templateDir: templateDir,
vars: {
message: errorText,
detail: detail,
console: (appSpec && appSpec.settings.appDefaults.sanitizeErrors) ? null : consoleLog
}
});
})
.fail(function(err) {
logger.error('Failed to render error 500 page: ' + err.message);
})
.fin(function() {
try {
res.end();
} catch(err) {
logger.error('Error while cleaning up response: ' + err);
}
})
.done();
}
|
javascript
|
function error500(req, res, errorText, detail, templateDir, consoleLogFile, appSpec) {
fsutil.safeTail_p(consoleLogFile, 8192)
.fail(function(consoleLog) {
return;
})
.then(function(consoleLog) {
render.sendPage(res, 500, 'An error has occurred', {
template: 'error-500',
templateDir: templateDir,
vars: {
message: errorText,
detail: detail,
console: (appSpec && appSpec.settings.appDefaults.sanitizeErrors) ? null : consoleLog
}
});
})
.fail(function(err) {
logger.error('Failed to render error 500 page: ' + err.message);
})
.fin(function() {
try {
res.end();
} catch(err) {
logger.error('Error while cleaning up response: ' + err);
}
})
.done();
}
|
[
"function",
"error500",
"(",
"req",
",",
"res",
",",
"errorText",
",",
"detail",
",",
"templateDir",
",",
"consoleLogFile",
",",
"appSpec",
")",
"{",
"fsutil",
".",
"safeTail_p",
"(",
"consoleLogFile",
",",
"8192",
")",
".",
"fail",
"(",
"function",
"(",
"consoleLog",
")",
"{",
"return",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"consoleLog",
")",
"{",
"render",
".",
"sendPage",
"(",
"res",
",",
"500",
",",
"'An error has occurred'",
",",
"{",
"template",
":",
"'error-500'",
",",
"templateDir",
":",
"templateDir",
",",
"vars",
":",
"{",
"message",
":",
"errorText",
",",
"detail",
":",
"detail",
",",
"console",
":",
"(",
"appSpec",
"&&",
"appSpec",
".",
"settings",
".",
"appDefaults",
".",
"sanitizeErrors",
")",
"?",
"null",
":",
"consoleLog",
"}",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"'Failed to render error 500 page: '",
"+",
"err",
".",
"message",
")",
";",
"}",
")",
".",
"fin",
"(",
"function",
"(",
")",
"{",
"try",
"{",
"res",
".",
"end",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"'Error while cleaning up response: '",
"+",
"err",
")",
";",
"}",
"}",
")",
".",
"done",
"(",
")",
";",
"}"
] |
Send a 500 error response
|
[
"Send",
"a",
"500",
"error",
"response"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/proxy/http.js#L30-L57
|
9,119
|
rstudio/shiny-server
|
lib/proxy/http.js
|
isKeepalive
|
function isKeepalive(req) {
var conn = req.headers.connection;
if (typeof(conn) === 'undefined' || conn === null)
conn = '';
conn = conn.trim().toLowerCase();
if (/\bclose\b/i.test(conn))
return false;
if (/\bkeep-alive\b/i.test(conn))
return true;
// No Connection header. Default to keepalive for 1.1, non for 1.0.
if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
return false;
} else {
return true;
}
}
|
javascript
|
function isKeepalive(req) {
var conn = req.headers.connection;
if (typeof(conn) === 'undefined' || conn === null)
conn = '';
conn = conn.trim().toLowerCase();
if (/\bclose\b/i.test(conn))
return false;
if (/\bkeep-alive\b/i.test(conn))
return true;
// No Connection header. Default to keepalive for 1.1, non for 1.0.
if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
return false;
} else {
return true;
}
}
|
[
"function",
"isKeepalive",
"(",
"req",
")",
"{",
"var",
"conn",
"=",
"req",
".",
"headers",
".",
"connection",
";",
"if",
"(",
"typeof",
"(",
"conn",
")",
"===",
"'undefined'",
"||",
"conn",
"===",
"null",
")",
"conn",
"=",
"''",
";",
"conn",
"=",
"conn",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"/",
"\\bclose\\b",
"/",
"i",
".",
"test",
"(",
"conn",
")",
")",
"return",
"false",
";",
"if",
"(",
"/",
"\\bkeep-alive\\b",
"/",
"i",
".",
"test",
"(",
"conn",
")",
")",
"return",
"true",
";",
"// No Connection header. Default to keepalive for 1.1, non for 1.0.",
"if",
"(",
"req",
".",
"httpVersionMajor",
"<",
"1",
"||",
"req",
".",
"httpVersionMinor",
"<",
"1",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
Determine if keepalive is desired by the client that generated this request
|
[
"Determine",
"if",
"keepalive",
"is",
"desired",
"by",
"the",
"client",
"that",
"generated",
"this",
"request"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/proxy/http.js#L287-L304
|
9,120
|
rstudio/shiny-server
|
lib/config/config.js
|
read_p
|
function read_p(path, schemaPath) {
return Q.nfcall(fs.readFile, path, 'utf8')
.then(function(cdata) {
return Q.nfcall(fs.readFile, schemaPath, 'utf8')
.then(function(sdata) {
return schema.applySchema(parse(cdata, path), parse(sdata, schemaPath));
});
});
}
|
javascript
|
function read_p(path, schemaPath) {
return Q.nfcall(fs.readFile, path, 'utf8')
.then(function(cdata) {
return Q.nfcall(fs.readFile, schemaPath, 'utf8')
.then(function(sdata) {
return schema.applySchema(parse(cdata, path), parse(sdata, schemaPath));
});
});
}
|
[
"function",
"read_p",
"(",
"path",
",",
"schemaPath",
")",
"{",
"return",
"Q",
".",
"nfcall",
"(",
"fs",
".",
"readFile",
",",
"path",
",",
"'utf8'",
")",
".",
"then",
"(",
"function",
"(",
"cdata",
")",
"{",
"return",
"Q",
".",
"nfcall",
"(",
"fs",
".",
"readFile",
",",
"schemaPath",
",",
"'utf8'",
")",
".",
"then",
"(",
"function",
"(",
"sdata",
")",
"{",
"return",
"schema",
".",
"applySchema",
"(",
"parse",
"(",
"cdata",
",",
"path",
")",
",",
"parse",
"(",
"sdata",
",",
"schemaPath",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Reads the given config file. The returned promise resolves to the ConfigNode
object at the root of the config file.
@param {String} path File path for the config file.
@returns {Promise} Promise that resolves to ConfigNode.
|
[
"Reads",
"the",
"given",
"config",
"file",
".",
"The",
"returned",
"promise",
"resolves",
"to",
"the",
"ConfigNode",
"object",
"at",
"the",
"root",
"of",
"the",
"config",
"file",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/config/config.js#L29-L37
|
9,121
|
rstudio/shiny-server
|
lib/proxy/multiplex.js
|
MultiplexChannel
|
function MultiplexChannel(id, conn, properties) {
events.EventEmitter.call(this);
this.$id = id; // The channel id
this.$conn = conn; // The underlying SockJS connection
_.extend(this, properties); // Apply extra properties to this object
this.readyState = this.$conn.readyState;
assert(this.readyState === 1); // copied from the (definitely active) conn
}
|
javascript
|
function MultiplexChannel(id, conn, properties) {
events.EventEmitter.call(this);
this.$id = id; // The channel id
this.$conn = conn; // The underlying SockJS connection
_.extend(this, properties); // Apply extra properties to this object
this.readyState = this.$conn.readyState;
assert(this.readyState === 1); // copied from the (definitely active) conn
}
|
[
"function",
"MultiplexChannel",
"(",
"id",
",",
"conn",
",",
"properties",
")",
"{",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"$id",
"=",
"id",
";",
"// The channel id",
"this",
".",
"$conn",
"=",
"conn",
";",
"// The underlying SockJS connection",
"_",
".",
"extend",
"(",
"this",
",",
"properties",
")",
";",
"// Apply extra properties to this object",
"this",
".",
"readyState",
"=",
"this",
".",
"$conn",
".",
"readyState",
";",
"assert",
"(",
"this",
".",
"readyState",
"===",
"1",
")",
";",
"// copied from the (definitely active) conn",
"}"
] |
Fake SockJS connection that can be multiplexed over a real SockJS connection.
|
[
"Fake",
"SockJS",
"connection",
"that",
"can",
"be",
"multiplexed",
"over",
"a",
"real",
"SockJS",
"connection",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/proxy/multiplex.js#L115-L122
|
9,122
|
rstudio/shiny-server
|
lib/router/config-router.js
|
createServers
|
function createServers(conf) {
var seenKeys = map.create();
var servers = _.map(conf.search('server'), function(serverNode) {
var listenNode = serverNode.getOne('listen');
if (!listenNode)
throwForNode(serverNode,
new Error('Required "listen" directive is missing'));
var port = serverNode.getValues('listen').port;
if (typeof port === 'undefined')
port = 80;
if (port <= 0)
throwForNode(listenNode, new Error('Invalid port number'));
var host = serverNode.getValues('listen').host || '::';
if (host === '*')
host = '::';
if (!iputil.isValid(host)) {
throwForNode(listenNode,
new Error('Invalid IP address "' + host + '"'));
}
if (iputil.hasZone(host)) {
throwForNode(listenNode,
new Error(`Invalid IP address "${host}"--zone IDs are not currently supported`))
}
var serverNames = serverNode.getValues('server_name').names;
// Read all locations. Use post-order traversal so that nested locs
// get priority over their parents.
var locations = _.chain(serverNode.search('location', false, true))
.map(createLocation)
.compact()
.value();
// We get the templateDir at the server level so that a global or server-
// wide templateDir can be attached to the request directly. We may need
// this if a page gets returns without a matching AppSpec (like a 404).
var templateDir = serverNode.getValues('template_dir').dir;
_.each(serverNames || [''], function(serverName) {
var key = host + ':' + port;
if (serverName !== '')
key += '(' + serverName + ')';
if (seenKeys[key])
throwForNode(listenNode,
new Error(key + ' combination conflicts with earlier server definition'));
seenKeys[key] = true;
});
return new ServerRouter(port, host, serverNames, locations, templateDir);
});
return servers;
}
|
javascript
|
function createServers(conf) {
var seenKeys = map.create();
var servers = _.map(conf.search('server'), function(serverNode) {
var listenNode = serverNode.getOne('listen');
if (!listenNode)
throwForNode(serverNode,
new Error('Required "listen" directive is missing'));
var port = serverNode.getValues('listen').port;
if (typeof port === 'undefined')
port = 80;
if (port <= 0)
throwForNode(listenNode, new Error('Invalid port number'));
var host = serverNode.getValues('listen').host || '::';
if (host === '*')
host = '::';
if (!iputil.isValid(host)) {
throwForNode(listenNode,
new Error('Invalid IP address "' + host + '"'));
}
if (iputil.hasZone(host)) {
throwForNode(listenNode,
new Error(`Invalid IP address "${host}"--zone IDs are not currently supported`))
}
var serverNames = serverNode.getValues('server_name').names;
// Read all locations. Use post-order traversal so that nested locs
// get priority over their parents.
var locations = _.chain(serverNode.search('location', false, true))
.map(createLocation)
.compact()
.value();
// We get the templateDir at the server level so that a global or server-
// wide templateDir can be attached to the request directly. We may need
// this if a page gets returns without a matching AppSpec (like a 404).
var templateDir = serverNode.getValues('template_dir').dir;
_.each(serverNames || [''], function(serverName) {
var key = host + ':' + port;
if (serverName !== '')
key += '(' + serverName + ')';
if (seenKeys[key])
throwForNode(listenNode,
new Error(key + ' combination conflicts with earlier server definition'));
seenKeys[key] = true;
});
return new ServerRouter(port, host, serverNames, locations, templateDir);
});
return servers;
}
|
[
"function",
"createServers",
"(",
"conf",
")",
"{",
"var",
"seenKeys",
"=",
"map",
".",
"create",
"(",
")",
";",
"var",
"servers",
"=",
"_",
".",
"map",
"(",
"conf",
".",
"search",
"(",
"'server'",
")",
",",
"function",
"(",
"serverNode",
")",
"{",
"var",
"listenNode",
"=",
"serverNode",
".",
"getOne",
"(",
"'listen'",
")",
";",
"if",
"(",
"!",
"listenNode",
")",
"throwForNode",
"(",
"serverNode",
",",
"new",
"Error",
"(",
"'Required \"listen\" directive is missing'",
")",
")",
";",
"var",
"port",
"=",
"serverNode",
".",
"getValues",
"(",
"'listen'",
")",
".",
"port",
";",
"if",
"(",
"typeof",
"port",
"===",
"'undefined'",
")",
"port",
"=",
"80",
";",
"if",
"(",
"port",
"<=",
"0",
")",
"throwForNode",
"(",
"listenNode",
",",
"new",
"Error",
"(",
"'Invalid port number'",
")",
")",
";",
"var",
"host",
"=",
"serverNode",
".",
"getValues",
"(",
"'listen'",
")",
".",
"host",
"||",
"'::'",
";",
"if",
"(",
"host",
"===",
"'*'",
")",
"host",
"=",
"'::'",
";",
"if",
"(",
"!",
"iputil",
".",
"isValid",
"(",
"host",
")",
")",
"{",
"throwForNode",
"(",
"listenNode",
",",
"new",
"Error",
"(",
"'Invalid IP address \"'",
"+",
"host",
"+",
"'\"'",
")",
")",
";",
"}",
"if",
"(",
"iputil",
".",
"hasZone",
"(",
"host",
")",
")",
"{",
"throwForNode",
"(",
"listenNode",
",",
"new",
"Error",
"(",
"`",
"${",
"host",
"}",
"`",
")",
")",
"}",
"var",
"serverNames",
"=",
"serverNode",
".",
"getValues",
"(",
"'server_name'",
")",
".",
"names",
";",
"// Read all locations. Use post-order traversal so that nested locs",
"// get priority over their parents.",
"var",
"locations",
"=",
"_",
".",
"chain",
"(",
"serverNode",
".",
"search",
"(",
"'location'",
",",
"false",
",",
"true",
")",
")",
".",
"map",
"(",
"createLocation",
")",
".",
"compact",
"(",
")",
".",
"value",
"(",
")",
";",
"// We get the templateDir at the server level so that a global or server-",
"// wide templateDir can be attached to the request directly. We may need",
"// this if a page gets returns without a matching AppSpec (like a 404).",
"var",
"templateDir",
"=",
"serverNode",
".",
"getValues",
"(",
"'template_dir'",
")",
".",
"dir",
";",
"_",
".",
"each",
"(",
"serverNames",
"||",
"[",
"''",
"]",
",",
"function",
"(",
"serverName",
")",
"{",
"var",
"key",
"=",
"host",
"+",
"':'",
"+",
"port",
";",
"if",
"(",
"serverName",
"!==",
"''",
")",
"key",
"+=",
"'('",
"+",
"serverName",
"+",
"')'",
";",
"if",
"(",
"seenKeys",
"[",
"key",
"]",
")",
"throwForNode",
"(",
"listenNode",
",",
"new",
"Error",
"(",
"key",
"+",
"' combination conflicts with earlier server definition'",
")",
")",
";",
"seenKeys",
"[",
"key",
"]",
"=",
"true",
";",
"}",
")",
";",
"return",
"new",
"ServerRouter",
"(",
"port",
",",
"host",
",",
"serverNames",
",",
"locations",
",",
"templateDir",
")",
";",
"}",
")",
";",
"return",
"servers",
";",
"}"
] |
Crawl the parsed and validated config file data to create an array of
ServerRouters.
|
[
"Crawl",
"the",
"parsed",
"and",
"validated",
"config",
"file",
"data",
"to",
"create",
"an",
"array",
"of",
"ServerRouters",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/router/config-router.js#L191-L248
|
9,123
|
rstudio/shiny-server
|
lib/router/config-router.js
|
createLocation
|
function createLocation(locNode) {
// TODO: Include ancestor locations in path
var path = locNode.values.path;
var terminalLocation = !locNode.getOne('location', false);
var node = locNode.getOne(/^site_dir|user_dirs|app_dir|user_apps|redirect$/);
if (!node) {
// No directives. Only allow this if child locations exist.
if (terminalLocation)
throwForNode(locNode, new Error('location directive must contain (or inherit) one of site_dir, user_apps, app_dir, or redirect'));
else
return null;
}
var settings = map.create();
var gaid = locNode.getValues('google_analytics_id').gaid;
if (gaid)
settings.gaTrackingId = gaid;
var logAsUser = locNode.getValues('log_as_user').enabled;
settings.logAsUser = logAsUser;
// Add the templateDir to the AppSpec, if we have one.
var templateDir = locNode.getValues('template_dir').dir;
if (templateDir){
settings.templateDir = templateDir;
}
settings = configRouterUtil.parseApplication(settings,
locNode, true);
switch (node.name) {
case 'site_dir':
return createSiteDir(locNode, node, settings);
case 'app_dir':
return createAppDir(locNode, node, settings);
case 'user_apps':
return createUserApps(locNode, node, settings);
case 'user_dirs':
return createUserApps(locNode, node, settings, true);
case 'redirect':
return createRedirect(locNode, node, settings);
default:
throwForNode(locNode, new Error('Node name ' + node.name + ' was not expected here'));
}
}
|
javascript
|
function createLocation(locNode) {
// TODO: Include ancestor locations in path
var path = locNode.values.path;
var terminalLocation = !locNode.getOne('location', false);
var node = locNode.getOne(/^site_dir|user_dirs|app_dir|user_apps|redirect$/);
if (!node) {
// No directives. Only allow this if child locations exist.
if (terminalLocation)
throwForNode(locNode, new Error('location directive must contain (or inherit) one of site_dir, user_apps, app_dir, or redirect'));
else
return null;
}
var settings = map.create();
var gaid = locNode.getValues('google_analytics_id').gaid;
if (gaid)
settings.gaTrackingId = gaid;
var logAsUser = locNode.getValues('log_as_user').enabled;
settings.logAsUser = logAsUser;
// Add the templateDir to the AppSpec, if we have one.
var templateDir = locNode.getValues('template_dir').dir;
if (templateDir){
settings.templateDir = templateDir;
}
settings = configRouterUtil.parseApplication(settings,
locNode, true);
switch (node.name) {
case 'site_dir':
return createSiteDir(locNode, node, settings);
case 'app_dir':
return createAppDir(locNode, node, settings);
case 'user_apps':
return createUserApps(locNode, node, settings);
case 'user_dirs':
return createUserApps(locNode, node, settings, true);
case 'redirect':
return createRedirect(locNode, node, settings);
default:
throwForNode(locNode, new Error('Node name ' + node.name + ' was not expected here'));
}
}
|
[
"function",
"createLocation",
"(",
"locNode",
")",
"{",
"// TODO: Include ancestor locations in path",
"var",
"path",
"=",
"locNode",
".",
"values",
".",
"path",
";",
"var",
"terminalLocation",
"=",
"!",
"locNode",
".",
"getOne",
"(",
"'location'",
",",
"false",
")",
";",
"var",
"node",
"=",
"locNode",
".",
"getOne",
"(",
"/",
"^site_dir|user_dirs|app_dir|user_apps|redirect$",
"/",
")",
";",
"if",
"(",
"!",
"node",
")",
"{",
"// No directives. Only allow this if child locations exist.",
"if",
"(",
"terminalLocation",
")",
"throwForNode",
"(",
"locNode",
",",
"new",
"Error",
"(",
"'location directive must contain (or inherit) one of site_dir, user_apps, app_dir, or redirect'",
")",
")",
";",
"else",
"return",
"null",
";",
"}",
"var",
"settings",
"=",
"map",
".",
"create",
"(",
")",
";",
"var",
"gaid",
"=",
"locNode",
".",
"getValues",
"(",
"'google_analytics_id'",
")",
".",
"gaid",
";",
"if",
"(",
"gaid",
")",
"settings",
".",
"gaTrackingId",
"=",
"gaid",
";",
"var",
"logAsUser",
"=",
"locNode",
".",
"getValues",
"(",
"'log_as_user'",
")",
".",
"enabled",
";",
"settings",
".",
"logAsUser",
"=",
"logAsUser",
";",
"// Add the templateDir to the AppSpec, if we have one.",
"var",
"templateDir",
"=",
"locNode",
".",
"getValues",
"(",
"'template_dir'",
")",
".",
"dir",
";",
"if",
"(",
"templateDir",
")",
"{",
"settings",
".",
"templateDir",
"=",
"templateDir",
";",
"}",
"settings",
"=",
"configRouterUtil",
".",
"parseApplication",
"(",
"settings",
",",
"locNode",
",",
"true",
")",
";",
"switch",
"(",
"node",
".",
"name",
")",
"{",
"case",
"'site_dir'",
":",
"return",
"createSiteDir",
"(",
"locNode",
",",
"node",
",",
"settings",
")",
";",
"case",
"'app_dir'",
":",
"return",
"createAppDir",
"(",
"locNode",
",",
"node",
",",
"settings",
")",
";",
"case",
"'user_apps'",
":",
"return",
"createUserApps",
"(",
"locNode",
",",
"node",
",",
"settings",
")",
";",
"case",
"'user_dirs'",
":",
"return",
"createUserApps",
"(",
"locNode",
",",
"node",
",",
"settings",
",",
"true",
")",
";",
"case",
"'redirect'",
":",
"return",
"createRedirect",
"(",
"locNode",
",",
"node",
",",
"settings",
")",
";",
"default",
":",
"throwForNode",
"(",
"locNode",
",",
"new",
"Error",
"(",
"'Node name '",
"+",
"node",
".",
"name",
"+",
"' was not expected here'",
")",
")",
";",
"}",
"}"
] |
Validates the location node, and returns the appropriate type of router
it represents.
|
[
"Validates",
"the",
"location",
"node",
"and",
"returns",
"the",
"appropriate",
"type",
"of",
"router",
"it",
"represents",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/router/config-router.js#L482-L527
|
9,124
|
rstudio/shiny-server
|
lib/core/qutil.js
|
forEachPromise_p
|
function forEachPromise_p(array, iterator, accept, defaultValue) {
var deferred = Q.defer();
var i = 0;
function tryNext() {
if (i >= array.length) {
// We've reached the end of the list--give up
deferred.resolve(defaultValue);
}
else {
try {
// Try the next item in the list
iterator(array[i++])
.then(
function(result) {
// If the promise returns a result, see if it is acceptable; if
// so, we're done, otherwise move on to the next item in the list
if (accept(result)) {
deferred.resolve(result);
} else {
tryNext();
}
},
function(err) {
deferred.reject(err);
}
);
} catch(ex) {
deferred.reject(ex);
}
}
}
tryNext();
return deferred.promise;
}
|
javascript
|
function forEachPromise_p(array, iterator, accept, defaultValue) {
var deferred = Q.defer();
var i = 0;
function tryNext() {
if (i >= array.length) {
// We've reached the end of the list--give up
deferred.resolve(defaultValue);
}
else {
try {
// Try the next item in the list
iterator(array[i++])
.then(
function(result) {
// If the promise returns a result, see if it is acceptable; if
// so, we're done, otherwise move on to the next item in the list
if (accept(result)) {
deferred.resolve(result);
} else {
tryNext();
}
},
function(err) {
deferred.reject(err);
}
);
} catch(ex) {
deferred.reject(ex);
}
}
}
tryNext();
return deferred.promise;
}
|
[
"function",
"forEachPromise_p",
"(",
"array",
",",
"iterator",
",",
"accept",
",",
"defaultValue",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"i",
"=",
"0",
";",
"function",
"tryNext",
"(",
")",
"{",
"if",
"(",
"i",
">=",
"array",
".",
"length",
")",
"{",
"// We've reached the end of the list--give up",
"deferred",
".",
"resolve",
"(",
"defaultValue",
")",
";",
"}",
"else",
"{",
"try",
"{",
"// Try the next item in the list",
"iterator",
"(",
"array",
"[",
"i",
"++",
"]",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"// If the promise returns a result, see if it is acceptable; if",
"// so, we're done, otherwise move on to the next item in the list",
"if",
"(",
"accept",
"(",
"result",
")",
")",
"{",
"deferred",
".",
"resolve",
"(",
"result",
")",
";",
"}",
"else",
"{",
"tryNext",
"(",
")",
";",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"deferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"deferred",
".",
"reject",
"(",
"ex",
")",
";",
"}",
"}",
"}",
"tryNext",
"(",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Starting at the beginning of the array, pass an element to the iterator,
which should return a promise. If the promise resolves, test the value
using the accept function. If accepted, that value is the result. If not
accepted, move on to the next array element.
If any of the iterator-produced promises fails, then reject the overall
promise with that error.
If the end of the array is reached without any values being accepted,
defaultValue is the result.
|
[
"Starting",
"at",
"the",
"beginning",
"of",
"the",
"array",
"pass",
"an",
"element",
"to",
"the",
"iterator",
"which",
"should",
"return",
"a",
"promise",
".",
"If",
"the",
"promise",
"resolves",
"test",
"the",
"value",
"using",
"the",
"accept",
"function",
".",
"If",
"accepted",
"that",
"value",
"is",
"the",
"result",
".",
"If",
"not",
"accepted",
"move",
"on",
"to",
"the",
"next",
"array",
"element",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/qutil.js#L91-L124
|
9,125
|
rstudio/shiny-server
|
lib/core/qutil.js
|
fapply
|
function fapply(func, object, args) {
try {
return Q.resolve(func.apply(object, args));
} catch(err) {
return Q.reject(err);
}
}
|
javascript
|
function fapply(func, object, args) {
try {
return Q.resolve(func.apply(object, args));
} catch(err) {
return Q.reject(err);
}
}
|
[
"function",
"fapply",
"(",
"func",
",",
"object",
",",
"args",
")",
"{",
"try",
"{",
"return",
"Q",
".",
"resolve",
"(",
"func",
".",
"apply",
"(",
"object",
",",
"args",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}"
] |
Apply a synchronous function but wrap the result or exception in a promise.
Why doesn't Q.apply work this way??
|
[
"Apply",
"a",
"synchronous",
"function",
"but",
"wrap",
"the",
"result",
"or",
"exception",
"in",
"a",
"promise",
".",
"Why",
"doesn",
"t",
"Q",
".",
"apply",
"work",
"this",
"way??"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/qutil.js#L131-L137
|
9,126
|
rstudio/shiny-server
|
lib/core/qutil.js
|
map_p
|
function map_p(collection, func_p) {
if (collection.length === 0)
return Q.resolve([]);
var results = [];
var lastFunc = Q.resolve(true);
_.each(collection, function(el, index) {
lastFunc = lastFunc.then(function() {
return func_p(collection[index])
.then(function(result) {
results[index] = result;
return results;
});
});
});
return lastFunc;
}
|
javascript
|
function map_p(collection, func_p) {
if (collection.length === 0)
return Q.resolve([]);
var results = [];
var lastFunc = Q.resolve(true);
_.each(collection, function(el, index) {
lastFunc = lastFunc.then(function() {
return func_p(collection[index])
.then(function(result) {
results[index] = result;
return results;
});
});
});
return lastFunc;
}
|
[
"function",
"map_p",
"(",
"collection",
",",
"func_p",
")",
"{",
"if",
"(",
"collection",
".",
"length",
"===",
"0",
")",
"return",
"Q",
".",
"resolve",
"(",
"[",
"]",
")",
";",
"var",
"results",
"=",
"[",
"]",
";",
"var",
"lastFunc",
"=",
"Q",
".",
"resolve",
"(",
"true",
")",
";",
"_",
".",
"each",
"(",
"collection",
",",
"function",
"(",
"el",
",",
"index",
")",
"{",
"lastFunc",
"=",
"lastFunc",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"func_p",
"(",
"collection",
"[",
"index",
"]",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"results",
"[",
"index",
"]",
"=",
"result",
";",
"return",
"results",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"lastFunc",
";",
"}"
] |
Pass in a collection and a promise-returning function, and map_p will
do a sequential map operation and resolve to the results.
|
[
"Pass",
"in",
"a",
"collection",
"and",
"a",
"promise",
"-",
"returning",
"function",
"and",
"map_p",
"will",
"do",
"a",
"sequential",
"map",
"operation",
"and",
"resolve",
"to",
"the",
"results",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/qutil.js#L158-L177
|
9,127
|
rstudio/shiny-server
|
lib/config/app-config.js
|
findConfig_p
|
function findConfig_p(appDir){
var filePath = path.join(appDir, ".shiny_app.conf");
return fsutil.safeStat_p(filePath)
.then(function(stat){
if (stat && stat.isFile()){
return (filePath);
}
throw new Error('Invalid app configuration file.');
});
}
|
javascript
|
function findConfig_p(appDir){
var filePath = path.join(appDir, ".shiny_app.conf");
return fsutil.safeStat_p(filePath)
.then(function(stat){
if (stat && stat.isFile()){
return (filePath);
}
throw new Error('Invalid app configuration file.');
});
}
|
[
"function",
"findConfig_p",
"(",
"appDir",
")",
"{",
"var",
"filePath",
"=",
"path",
".",
"join",
"(",
"appDir",
",",
"\".shiny_app.conf\"",
")",
";",
"return",
"fsutil",
".",
"safeStat_p",
"(",
"filePath",
")",
".",
"then",
"(",
"function",
"(",
"stat",
")",
"{",
"if",
"(",
"stat",
"&&",
"stat",
".",
"isFile",
"(",
")",
")",
"{",
"return",
"(",
"filePath",
")",
";",
"}",
"throw",
"new",
"Error",
"(",
"'Invalid app configuration file.'",
")",
";",
"}",
")",
";",
"}"
] |
Check to see if there's a configuration file in the given app directory,
if so, parse it.
@param appDir The base directory in which the application is hosted.
@return A promise resolving to the path of the application-specific
configuration file
|
[
"Check",
"to",
"see",
"if",
"there",
"s",
"a",
"configuration",
"file",
"in",
"the",
"given",
"app",
"directory",
"if",
"so",
"parse",
"it",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/config/app-config.js#L92-L101
|
9,128
|
rstudio/shiny-server
|
lib/core/render.js
|
sendClientAlertMessage
|
function sendClientAlertMessage(ws, alert) {
var msg = JSON.stringify({
custom: {
alert: alert
}
});
ws.write(msg);
}
|
javascript
|
function sendClientAlertMessage(ws, alert) {
var msg = JSON.stringify({
custom: {
alert: alert
}
});
ws.write(msg);
}
|
[
"function",
"sendClientAlertMessage",
"(",
"ws",
",",
"alert",
")",
"{",
"var",
"msg",
"=",
"JSON",
".",
"stringify",
"(",
"{",
"custom",
":",
"{",
"alert",
":",
"alert",
"}",
"}",
")",
";",
"ws",
".",
"write",
"(",
"msg",
")",
";",
"}"
] |
Sends the given string to the client, where it will be displayed as a
JavaScript alert message.
|
[
"Sends",
"the",
"given",
"string",
"to",
"the",
"client",
"where",
"it",
"will",
"be",
"displayed",
"as",
"a",
"JavaScript",
"alert",
"message",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/render.js#L110-L117
|
9,129
|
rstudio/shiny-server
|
lib/core/render.js
|
error404
|
function error404(req, res, templateDir) {
sendPage(res, 404, 'Page not found', {
template: 'error-404',
templateDir: templateDir,
vars: {
message: "Sorry, but the page you requested doesn't exist."
}
});
}
|
javascript
|
function error404(req, res, templateDir) {
sendPage(res, 404, 'Page not found', {
template: 'error-404',
templateDir: templateDir,
vars: {
message: "Sorry, but the page you requested doesn't exist."
}
});
}
|
[
"function",
"error404",
"(",
"req",
",",
"res",
",",
"templateDir",
")",
"{",
"sendPage",
"(",
"res",
",",
"404",
",",
"'Page not found'",
",",
"{",
"template",
":",
"'error-404'",
",",
"templateDir",
":",
"templateDir",
",",
"vars",
":",
"{",
"message",
":",
"\"Sorry, but the page you requested doesn't exist.\"",
"}",
"}",
")",
";",
"}"
] |
Send a 404 error response
|
[
"Send",
"a",
"404",
"error",
"response"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/render.js#L121-L129
|
9,130
|
rstudio/shiny-server
|
lib/core/render.js
|
errorAppOverloaded
|
function errorAppOverloaded(req, res, templateDir) {
sendPage(res, 503, 'Too Many Users', {
template: 'error-503-users',
templateDir: templateDir,
vars: {
message: "Sorry, but this application has exceeded its quota of concurrent users. Please try again later."
}
});
}
|
javascript
|
function errorAppOverloaded(req, res, templateDir) {
sendPage(res, 503, 'Too Many Users', {
template: 'error-503-users',
templateDir: templateDir,
vars: {
message: "Sorry, but this application has exceeded its quota of concurrent users. Please try again later."
}
});
}
|
[
"function",
"errorAppOverloaded",
"(",
"req",
",",
"res",
",",
"templateDir",
")",
"{",
"sendPage",
"(",
"res",
",",
"503",
",",
"'Too Many Users'",
",",
"{",
"template",
":",
"'error-503-users'",
",",
"templateDir",
":",
"templateDir",
",",
"vars",
":",
"{",
"message",
":",
"\"Sorry, but this application has exceeded its quota of concurrent users. Please try again later.\"",
"}",
"}",
")",
";",
"}"
] |
Send a 503 error response
|
[
"Send",
"a",
"503",
"error",
"response"
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/render.js#L133-L141
|
9,131
|
rstudio/shiny-server
|
lib/main.js
|
ping
|
function ping(req, res) {
if (url.parse(req.url).pathname == '/ping') {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('OK');
return true;
}
return false;
}
|
javascript
|
function ping(req, res) {
if (url.parse(req.url).pathname == '/ping') {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('OK');
return true;
}
return false;
}
|
[
"function",
"ping",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"url",
".",
"parse",
"(",
"req",
".",
"url",
")",
".",
"pathname",
"==",
"'/ping'",
")",
"{",
"res",
".",
"writeHead",
"(",
"200",
",",
"{",
"'Content-Type'",
":",
"'text/plain'",
"}",
")",
";",
"res",
".",
"end",
"(",
"'OK'",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
A simple router function that does nothing but respond "OK". Can be used for load balancer health checks, for example.
|
[
"A",
"simple",
"router",
"function",
"that",
"does",
"nothing",
"but",
"respond",
"OK",
".",
"Can",
"be",
"used",
"for",
"load",
"balancer",
"health",
"checks",
"for",
"example",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/main.js#L111-L118
|
9,132
|
rstudio/shiny-server
|
lib/core/map.js
|
compact
|
function compact(x) {
function shouldDrop(key) {
return typeof(x[key]) === 'undefined' || x[key] === null;
}
return _.omit(x, _.filter(_.keys(x), shouldDrop))
}
|
javascript
|
function compact(x) {
function shouldDrop(key) {
return typeof(x[key]) === 'undefined' || x[key] === null;
}
return _.omit(x, _.filter(_.keys(x), shouldDrop))
}
|
[
"function",
"compact",
"(",
"x",
")",
"{",
"function",
"shouldDrop",
"(",
"key",
")",
"{",
"return",
"typeof",
"(",
"x",
"[",
"key",
"]",
")",
"===",
"'undefined'",
"||",
"x",
"[",
"key",
"]",
"===",
"null",
";",
"}",
"return",
"_",
".",
"omit",
"(",
"x",
",",
"_",
".",
"filter",
"(",
"_",
".",
"keys",
"(",
"x",
")",
",",
"shouldDrop",
")",
")",
"}"
] |
Return a copy of object x with null or undefined "own" properties removed.
|
[
"Return",
"a",
"copy",
"of",
"object",
"x",
"with",
"null",
"or",
"undefined",
"own",
"properties",
"removed",
"."
] |
0227ff5e5ce0182921446e45295873932507b36f
|
https://github.com/rstudio/shiny-server/blob/0227ff5e5ce0182921446e45295873932507b36f/lib/core/map.js#L28-L33
|
9,133
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
AnonymousObserver
|
function AnonymousObserver(onNext, onError, onCompleted) {
__super__.call(this);
this._onNext = onNext;
this._onError = onError;
this._onCompleted = onCompleted;
}
|
javascript
|
function AnonymousObserver(onNext, onError, onCompleted) {
__super__.call(this);
this._onNext = onNext;
this._onError = onError;
this._onCompleted = onCompleted;
}
|
[
"function",
"AnonymousObserver",
"(",
"onNext",
",",
"onError",
",",
"onCompleted",
")",
"{",
"__super__",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_onNext",
"=",
"onNext",
";",
"this",
".",
"_onError",
"=",
"onError",
";",
"this",
".",
"_onCompleted",
"=",
"onCompleted",
";",
"}"
] |
Creates an observer from the specified OnNext, OnError, and OnCompleted actions.
@param {Any} onNext Observer's OnNext action implementation.
@param {Any} onError Observer's OnError action implementation.
@param {Any} onCompleted Observer's OnCompleted action implementation.
|
[
"Creates",
"an",
"observer",
"from",
"the",
"specified",
"OnNext",
"OnError",
"and",
"OnCompleted",
"actions",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L1806-L1811
|
9,134
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
arrayIndexOfComparer
|
function arrayIndexOfComparer(array, item, comparer) {
for (var i = 0, len = array.length; i < len; i++) {
if (comparer(array[i], item)) { return i; }
}
return -1;
}
|
javascript
|
function arrayIndexOfComparer(array, item, comparer) {
for (var i = 0, len = array.length; i < len; i++) {
if (comparer(array[i], item)) { return i; }
}
return -1;
}
|
[
"function",
"arrayIndexOfComparer",
"(",
"array",
",",
"item",
",",
"comparer",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"array",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"comparer",
"(",
"array",
"[",
"i",
"]",
",",
"item",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
Swap out for Array.findIndex
|
[
"Swap",
"out",
"for",
"Array",
".",
"findIndex"
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L5256-L5261
|
9,135
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
VirtualTimeScheduler
|
function VirtualTimeScheduler(initialClock, comparer) {
this.clock = initialClock;
this.comparer = comparer;
this.isEnabled = false;
this.queue = new PriorityQueue(1024);
__super__.call(this);
}
|
javascript
|
function VirtualTimeScheduler(initialClock, comparer) {
this.clock = initialClock;
this.comparer = comparer;
this.isEnabled = false;
this.queue = new PriorityQueue(1024);
__super__.call(this);
}
|
[
"function",
"VirtualTimeScheduler",
"(",
"initialClock",
",",
"comparer",
")",
"{",
"this",
".",
"clock",
"=",
"initialClock",
";",
"this",
".",
"comparer",
"=",
"comparer",
";",
"this",
".",
"isEnabled",
"=",
"false",
";",
"this",
".",
"queue",
"=",
"new",
"PriorityQueue",
"(",
"1024",
")",
";",
"__super__",
".",
"call",
"(",
"this",
")",
";",
"}"
] |
Creates a new virtual time scheduler with the specified initial clock value and absolute time comparer.
@constructor
@param {Number} initialClock Initial value for the clock.
@param {Function} comparer Comparer to determine causality of events based on absolute time.
|
[
"Creates",
"a",
"new",
"virtual",
"time",
"scheduler",
"with",
"the",
"specified",
"initial",
"clock",
"value",
"and",
"absolute",
"time",
"comparer",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L10873-L10879
|
9,136
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
HistoricalScheduler
|
function HistoricalScheduler(initialClock, comparer) {
var clock = initialClock == null ? 0 : initialClock;
var cmp = comparer || defaultSubComparer;
__super__.call(this, clock, cmp);
}
|
javascript
|
function HistoricalScheduler(initialClock, comparer) {
var clock = initialClock == null ? 0 : initialClock;
var cmp = comparer || defaultSubComparer;
__super__.call(this, clock, cmp);
}
|
[
"function",
"HistoricalScheduler",
"(",
"initialClock",
",",
"comparer",
")",
"{",
"var",
"clock",
"=",
"initialClock",
"==",
"null",
"?",
"0",
":",
"initialClock",
";",
"var",
"cmp",
"=",
"comparer",
"||",
"defaultSubComparer",
";",
"__super__",
".",
"call",
"(",
"this",
",",
"clock",
",",
"cmp",
")",
";",
"}"
] |
Creates a new historical scheduler with the specified initial clock value.
@constructor
@param {Number} initialClock Initial value for the clock.
@param {Function} comparer Comparer to determine causality of events based on absolute time.
|
[
"Creates",
"a",
"new",
"historical",
"scheduler",
"with",
"the",
"specified",
"initial",
"clock",
"value",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L11067-L11071
|
9,137
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
function (ticks, value) {
return typeof value === 'function' ?
new Recorded(ticks, new OnNextPredicate(value)) :
new Recorded(ticks, Notification.createOnNext(value));
}
|
javascript
|
function (ticks, value) {
return typeof value === 'function' ?
new Recorded(ticks, new OnNextPredicate(value)) :
new Recorded(ticks, Notification.createOnNext(value));
}
|
[
"function",
"(",
"ticks",
",",
"value",
")",
"{",
"return",
"typeof",
"value",
"===",
"'function'",
"?",
"new",
"Recorded",
"(",
"ticks",
",",
"new",
"OnNextPredicate",
"(",
"value",
")",
")",
":",
"new",
"Recorded",
"(",
"ticks",
",",
"Notification",
".",
"createOnNext",
"(",
"value",
")",
")",
";",
"}"
] |
Factory method for an OnNext notification record at a given time with a given value or a predicate function.
1 - ReactiveTest.onNext(200, 42);
2 - ReactiveTest.onNext(200, function (x) { return x.length == 2; });
@param ticks Recorded virtual time the OnNext notification occurs.
@param value Recorded value stored in the OnNext notification or a predicate.
@return Recorded OnNext notification.
|
[
"Factory",
"method",
"for",
"an",
"OnNext",
"notification",
"record",
"at",
"a",
"given",
"time",
"with",
"a",
"given",
"value",
"or",
"a",
"predicate",
"function",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L11142-L11146
|
|
9,138
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
function (ticks, error) {
return typeof error === 'function' ?
new Recorded(ticks, new OnErrorPredicate(error)) :
new Recorded(ticks, Notification.createOnError(error));
}
|
javascript
|
function (ticks, error) {
return typeof error === 'function' ?
new Recorded(ticks, new OnErrorPredicate(error)) :
new Recorded(ticks, Notification.createOnError(error));
}
|
[
"function",
"(",
"ticks",
",",
"error",
")",
"{",
"return",
"typeof",
"error",
"===",
"'function'",
"?",
"new",
"Recorded",
"(",
"ticks",
",",
"new",
"OnErrorPredicate",
"(",
"error",
")",
")",
":",
"new",
"Recorded",
"(",
"ticks",
",",
"Notification",
".",
"createOnError",
"(",
"error",
")",
")",
";",
"}"
] |
Factory method for an OnError notification record at a given time with a given error.
1 - ReactiveTest.onNext(200, new Error('error'));
2 - ReactiveTest.onNext(200, function (e) { return e.message === 'error'; });
@param ticks Recorded virtual time the OnError notification occurs.
@param exception Recorded exception stored in the OnError notification.
@return Recorded OnError notification.
|
[
"Factory",
"method",
"for",
"an",
"OnError",
"notification",
"record",
"at",
"a",
"given",
"time",
"with",
"a",
"given",
"error",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L11157-L11161
|
|
9,139
|
machty/ember-concurrency
|
vendor/dummy-deps/rx.js
|
AsyncSubject
|
function AsyncSubject() {
__super__.call(this);
this.isDisposed = false;
this.isStopped = false;
this.hasValue = false;
this.observers = [];
this.hasError = false;
}
|
javascript
|
function AsyncSubject() {
__super__.call(this);
this.isDisposed = false;
this.isStopped = false;
this.hasValue = false;
this.observers = [];
this.hasError = false;
}
|
[
"function",
"AsyncSubject",
"(",
")",
"{",
"__super__",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"isDisposed",
"=",
"false",
";",
"this",
".",
"isStopped",
"=",
"false",
";",
"this",
".",
"hasValue",
"=",
"false",
";",
"this",
".",
"observers",
"=",
"[",
"]",
";",
"this",
".",
"hasError",
"=",
"false",
";",
"}"
] |
Creates a subject that can only receive one value and that value is cached for all future observations.
@constructor
|
[
"Creates",
"a",
"subject",
"that",
"can",
"only",
"receive",
"one",
"value",
"and",
"that",
"value",
"is",
"cached",
"for",
"all",
"future",
"observations",
"."
] |
6b1a46e5ccd5495412409a29d82b5fcc6dae2272
|
https://github.com/machty/ember-concurrency/blob/6b1a46e5ccd5495412409a29d82b5fcc6dae2272/vendor/dummy-deps/rx.js#L11783-L11790
|
9,140
|
intel-iot-devkit/upm
|
examples/javascript/zfm20-register.js
|
exit
|
function exit()
{
myFingerprintSensor = null;
fingerprint_lib.cleanUp();
fingerprint_lib = null;
console.log("Exiting");
process.exit(0);
}
|
javascript
|
function exit()
{
myFingerprintSensor = null;
fingerprint_lib.cleanUp();
fingerprint_lib = null;
console.log("Exiting");
process.exit(0);
}
|
[
"function",
"exit",
"(",
")",
"{",
"myFingerprintSensor",
"=",
"null",
";",
"fingerprint_lib",
".",
"cleanUp",
"(",
")",
";",
"fingerprint_lib",
"=",
"null",
";",
"console",
".",
"log",
"(",
"\"Exiting\"",
")",
";",
"process",
".",
"exit",
"(",
"0",
")",
";",
"}"
] |
Print message when exiting
|
[
"Print",
"message",
"when",
"exiting"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/zfm20-register.js#L126-L133
|
9,141
|
intel-iot-devkit/upm
|
examples/javascript/md-stepper.js
|
start
|
function start()
{
if (motor)
{
// configure it, for this example, we'll assume 200 steps per rev
motor.configStepper(200);
motor.setStepperSteps(100);
// start it going at 10 RPM
motor.enableStepper(mdObj.MD.STEP_DIR_CW, 10);
}
}
|
javascript
|
function start()
{
if (motor)
{
// configure it, for this example, we'll assume 200 steps per rev
motor.configStepper(200);
motor.setStepperSteps(100);
// start it going at 10 RPM
motor.enableStepper(mdObj.MD.STEP_DIR_CW, 10);
}
}
|
[
"function",
"start",
"(",
")",
"{",
"if",
"(",
"motor",
")",
"{",
"// configure it, for this example, we'll assume 200 steps per rev",
"motor",
".",
"configStepper",
"(",
"200",
")",
";",
"motor",
".",
"setStepperSteps",
"(",
"100",
")",
";",
"// start it going at 10 RPM",
"motor",
".",
"enableStepper",
"(",
"mdObj",
".",
"MD",
".",
"STEP_DIR_CW",
",",
"10",
")",
";",
"}",
"}"
] |
This example demonstrates using the MD to drive a stepper motor
|
[
"This",
"example",
"demonstrates",
"using",
"the",
"MD",
"to",
"drive",
"a",
"stepper",
"motor"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/md-stepper.js#L29-L39
|
9,142
|
intel-iot-devkit/upm
|
examples/javascript/adis16448.js
|
periodicActivity
|
function periodicActivity()
{
//Read & Scale Gyro/Accel Data
var xgyro = imu.gyroScale(imu.regRead(0x04));
var ygyro = imu.gyroScale(imu.regRead(0x06));
var zgyro = imu.gyroScale(imu.regRead(0x08));
var xaccl = imu.accelScale(imu.regRead(0x0A));
var yaccl = imu.accelScale(imu.regRead(0x0C));
var zaccl = imu.accelScale(imu.regRead(0x0E));
//Display Scaled Data on the Console Log
console.log('XGYRO: ' + xgyro);
console.log('YGYRO: ' + ygyro);
console.log('ZGYRO: ' + zgyro);
console.log('XACCL: ' + xaccl);
console.log('YACCL: ' + yaccl);
console.log('ZACCL: ' + zaccl);
console.log(' ');
setTimeout(periodicActivity,200); //call the indicated function after 0.2 seconds (200 milliseconds)
}
|
javascript
|
function periodicActivity()
{
//Read & Scale Gyro/Accel Data
var xgyro = imu.gyroScale(imu.regRead(0x04));
var ygyro = imu.gyroScale(imu.regRead(0x06));
var zgyro = imu.gyroScale(imu.regRead(0x08));
var xaccl = imu.accelScale(imu.regRead(0x0A));
var yaccl = imu.accelScale(imu.regRead(0x0C));
var zaccl = imu.accelScale(imu.regRead(0x0E));
//Display Scaled Data on the Console Log
console.log('XGYRO: ' + xgyro);
console.log('YGYRO: ' + ygyro);
console.log('ZGYRO: ' + zgyro);
console.log('XACCL: ' + xaccl);
console.log('YACCL: ' + yaccl);
console.log('ZACCL: ' + zaccl);
console.log(' ');
setTimeout(periodicActivity,200); //call the indicated function after 0.2 seconds (200 milliseconds)
}
|
[
"function",
"periodicActivity",
"(",
")",
"{",
"//Read & Scale Gyro/Accel Data",
"var",
"xgyro",
"=",
"imu",
".",
"gyroScale",
"(",
"imu",
".",
"regRead",
"(",
"0x04",
")",
")",
";",
"var",
"ygyro",
"=",
"imu",
".",
"gyroScale",
"(",
"imu",
".",
"regRead",
"(",
"0x06",
")",
")",
";",
"var",
"zgyro",
"=",
"imu",
".",
"gyroScale",
"(",
"imu",
".",
"regRead",
"(",
"0x08",
")",
")",
";",
"var",
"xaccl",
"=",
"imu",
".",
"accelScale",
"(",
"imu",
".",
"regRead",
"(",
"0x0A",
")",
")",
";",
"var",
"yaccl",
"=",
"imu",
".",
"accelScale",
"(",
"imu",
".",
"regRead",
"(",
"0x0C",
")",
")",
";",
"var",
"zaccl",
"=",
"imu",
".",
"accelScale",
"(",
"imu",
".",
"regRead",
"(",
"0x0E",
")",
")",
";",
"//Display Scaled Data on the Console Log",
"console",
".",
"log",
"(",
"'XGYRO: '",
"+",
"xgyro",
")",
";",
"console",
".",
"log",
"(",
"'YGYRO: '",
"+",
"ygyro",
")",
";",
"console",
".",
"log",
"(",
"'ZGYRO: '",
"+",
"zgyro",
")",
";",
"console",
".",
"log",
"(",
"'XACCL: '",
"+",
"xaccl",
")",
";",
"console",
".",
"log",
"(",
"'YACCL: '",
"+",
"yaccl",
")",
";",
"console",
".",
"log",
"(",
"'ZACCL: '",
"+",
"zaccl",
")",
";",
"console",
".",
"log",
"(",
"' '",
")",
";",
"setTimeout",
"(",
"periodicActivity",
",",
"200",
")",
";",
"//call the indicated function after 0.2 seconds (200 milliseconds)",
"}"
] |
Call the periodicActivity function
|
[
"Call",
"the",
"periodicActivity",
"function"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/adis16448.js#L48-L67
|
9,143
|
intel-iot-devkit/upm
|
examples/javascript/ttp223.js
|
readSensorValue
|
function readSensorValue() {
if ( touch.isPressed() ) {
console.log(touch.name() + " is pressed");
} else {
console.log(touch.name() + " is not pressed");
}
}
|
javascript
|
function readSensorValue() {
if ( touch.isPressed() ) {
console.log(touch.name() + " is pressed");
} else {
console.log(touch.name() + " is not pressed");
}
}
|
[
"function",
"readSensorValue",
"(",
")",
"{",
"if",
"(",
"touch",
".",
"isPressed",
"(",
")",
")",
"{",
"console",
".",
"log",
"(",
"touch",
".",
"name",
"(",
")",
"+",
"\" is pressed\"",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"touch",
".",
"name",
"(",
")",
"+",
"\" is not pressed\"",
")",
";",
"}",
"}"
] |
Check whether or not a finger is near the touch sensor and print accordingly, waiting one second between readings
|
[
"Check",
"whether",
"or",
"not",
"a",
"finger",
"is",
"near",
"the",
"touch",
"sensor",
"and",
"print",
"accordingly",
"waiting",
"one",
"second",
"between",
"readings"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/ttp223.js#L33-L39
|
9,144
|
intel-iot-devkit/upm
|
examples/javascript/bno055.js
|
outputData
|
function outputData()
{
sensor.update();
var floatData = sensor.getEulerAngles();
console.log("Euler: Heading: " + floatData.get(0)
+ " Roll: " + floatData.get(1)
+ " Pitch: " + floatData.get(2)
+ " degrees");
floatData = sensor.getQuaternions();
console.log("Quaternion: W: " + floatData.get(0)
+ " X:" + floatData.get(1)
+ " Y: " + floatData.get(2)
+ " Z: " + floatData.get(3));
floatData = sensor.getLinearAcceleration();
console.log("Linear Acceleration: X: " + floatData.get(0)
+ " Y: " + floatData.get(1)
+ " Z: " + floatData.get(2)
+ " m/s^2");
floatData = sensor.getGravityVectors();
console.log("Gravity Vector: X: " + floatData.get(0)
+ " Y: " + floatData.get(1)
+ " Z: " + floatData.get(2)
+ " m/s^2");
console.log("");
}
|
javascript
|
function outputData()
{
sensor.update();
var floatData = sensor.getEulerAngles();
console.log("Euler: Heading: " + floatData.get(0)
+ " Roll: " + floatData.get(1)
+ " Pitch: " + floatData.get(2)
+ " degrees");
floatData = sensor.getQuaternions();
console.log("Quaternion: W: " + floatData.get(0)
+ " X:" + floatData.get(1)
+ " Y: " + floatData.get(2)
+ " Z: " + floatData.get(3));
floatData = sensor.getLinearAcceleration();
console.log("Linear Acceleration: X: " + floatData.get(0)
+ " Y: " + floatData.get(1)
+ " Z: " + floatData.get(2)
+ " m/s^2");
floatData = sensor.getGravityVectors();
console.log("Gravity Vector: X: " + floatData.get(0)
+ " Y: " + floatData.get(1)
+ " Z: " + floatData.get(2)
+ " m/s^2");
console.log("");
}
|
[
"function",
"outputData",
"(",
")",
"{",
"sensor",
".",
"update",
"(",
")",
";",
"var",
"floatData",
"=",
"sensor",
".",
"getEulerAngles",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"Euler: Heading: \"",
"+",
"floatData",
".",
"get",
"(",
"0",
")",
"+",
"\" Roll: \"",
"+",
"floatData",
".",
"get",
"(",
"1",
")",
"+",
"\" Pitch: \"",
"+",
"floatData",
".",
"get",
"(",
"2",
")",
"+",
"\" degrees\"",
")",
";",
"floatData",
"=",
"sensor",
".",
"getQuaternions",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"Quaternion: W: \"",
"+",
"floatData",
".",
"get",
"(",
"0",
")",
"+",
"\" X:\"",
"+",
"floatData",
".",
"get",
"(",
"1",
")",
"+",
"\" Y: \"",
"+",
"floatData",
".",
"get",
"(",
"2",
")",
"+",
"\" Z: \"",
"+",
"floatData",
".",
"get",
"(",
"3",
")",
")",
";",
"floatData",
"=",
"sensor",
".",
"getLinearAcceleration",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"Linear Acceleration: X: \"",
"+",
"floatData",
".",
"get",
"(",
"0",
")",
"+",
"\" Y: \"",
"+",
"floatData",
".",
"get",
"(",
"1",
")",
"+",
"\" Z: \"",
"+",
"floatData",
".",
"get",
"(",
"2",
")",
"+",
"\" m/s^2\"",
")",
";",
"floatData",
"=",
"sensor",
".",
"getGravityVectors",
"(",
")",
";",
"console",
".",
"log",
"(",
"\"Gravity Vector: X: \"",
"+",
"floatData",
".",
"get",
"(",
"0",
")",
"+",
"\" Y: \"",
"+",
"floatData",
".",
"get",
"(",
"1",
")",
"+",
"\" Z: \"",
"+",
"floatData",
".",
"get",
"(",
"2",
")",
"+",
"\" m/s^2\"",
")",
";",
"console",
".",
"log",
"(",
"\"\"",
")",
";",
"}"
] |
now output various fusion data every 250 milliseconds
|
[
"now",
"output",
"various",
"fusion",
"data",
"every",
"250",
"milliseconds"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/bno055.js#L67-L96
|
9,145
|
intel-iot-devkit/upm
|
examples/javascript/tm1637.js
|
update
|
function update(){
now = new Date();
var time = now.getHours().toString() + ("0" + now.getMinutes().toString()).slice(-2);
display.writeString(time);
display.setColon(colon = !colon);
}
|
javascript
|
function update(){
now = new Date();
var time = now.getHours().toString() + ("0" + now.getMinutes().toString()).slice(-2);
display.writeString(time);
display.setColon(colon = !colon);
}
|
[
"function",
"update",
"(",
")",
"{",
"now",
"=",
"new",
"Date",
"(",
")",
";",
"var",
"time",
"=",
"now",
".",
"getHours",
"(",
")",
".",
"toString",
"(",
")",
"+",
"(",
"\"0\"",
"+",
"now",
".",
"getMinutes",
"(",
")",
".",
"toString",
"(",
")",
")",
".",
"slice",
"(",
"-",
"2",
")",
";",
"display",
".",
"writeString",
"(",
"time",
")",
";",
"display",
".",
"setColon",
"(",
"colon",
"=",
"!",
"colon",
")",
";",
"}"
] |
Display and time update function
|
[
"Display",
"and",
"time",
"update",
"function"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/tm1637.js#L41-L46
|
9,146
|
intel-iot-devkit/upm
|
examples/javascript/ili9341.js
|
rotateScreen
|
function rotateScreen(r) {
lcd.setRotation(r);
lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE);
if (r < 4) {
r++;
setTimeout(function() { rotateScreen(r); }, 1000);
}
}
|
javascript
|
function rotateScreen(r) {
lcd.setRotation(r);
lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE);
if (r < 4) {
r++;
setTimeout(function() { rotateScreen(r); }, 1000);
}
}
|
[
"function",
"rotateScreen",
"(",
"r",
")",
"{",
"lcd",
".",
"setRotation",
"(",
"r",
")",
";",
"lcd",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"5",
",",
"5",
",",
"ili9341",
".",
"ILI9341_WHITE",
")",
";",
"if",
"(",
"r",
"<",
"4",
")",
"{",
"r",
"++",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"rotateScreen",
"(",
"r",
")",
";",
"}",
",",
"1000",
")",
";",
"}",
"}"
] |
Test screen rotation
|
[
"Test",
"screen",
"rotation"
] |
5cf20df96c6b35c19d5b871ba4e319e96b4df72d
|
https://github.com/intel-iot-devkit/upm/blob/5cf20df96c6b35c19d5b871ba4e319e96b4df72d/examples/javascript/ili9341.js#L65-L72
|
9,147
|
pkgcloud/pkgcloud
|
lib/pkgcloud/openstack/compute/client/extensions/networks-base.js
|
function (callback) {
return this._request({
path: this._extension
}, function (err, body, res) {
return err
? callback(err)
: callback(null, body.networks, res);
});
}
|
javascript
|
function (callback) {
return this._request({
path: this._extension
}, function (err, body, res) {
return err
? callback(err)
: callback(null, body.networks, res);
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"return",
"this",
".",
"_request",
"(",
"{",
"path",
":",
"this",
".",
"_extension",
"}",
",",
"function",
"(",
"err",
",",
"body",
",",
"res",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"null",
",",
"body",
".",
"networks",
",",
"res",
")",
";",
"}",
")",
";",
"}"
] |
client.getNetworks
@description Display the currently available networks
@param {Function} callback f(err, networks) where networks is an array of networks
@returns {*}
|
[
"client",
".",
"getNetworks"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/openstack/compute/client/extensions/networks-base.js#L26-L34
|
|
9,148
|
pkgcloud/pkgcloud
|
lib/pkgcloud/openstack/compute/client/extensions/networks-base.js
|
function (network, callback) {
var networkId = (typeof network === 'object') ? network.id : network;
return this._request({
path: urlJoin(this._extension, networkId)
}, function (err, body) {
return err
? callback(err)
: callback(null, body.network);
});
}
|
javascript
|
function (network, callback) {
var networkId = (typeof network === 'object') ? network.id : network;
return this._request({
path: urlJoin(this._extension, networkId)
}, function (err, body) {
return err
? callback(err)
: callback(null, body.network);
});
}
|
[
"function",
"(",
"network",
",",
"callback",
")",
"{",
"var",
"networkId",
"=",
"(",
"typeof",
"network",
"===",
"'object'",
")",
"?",
"network",
".",
"id",
":",
"network",
";",
"return",
"this",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"this",
".",
"_extension",
",",
"networkId",
")",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"null",
",",
"body",
".",
"network",
")",
";",
"}",
")",
";",
"}"
] |
client.getNetwork
@description Get the details for a specific network
@param {String|object} network The network or networkId to get
@param {Function} callback
@returns {*}
|
[
"client",
".",
"getNetwork"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/openstack/compute/client/extensions/networks-base.js#L45-L55
|
|
9,149
|
pkgcloud/pkgcloud
|
lib/pkgcloud/openstack/compute/client/extensions/networks-base.js
|
function (options, properties, callback) {
return this._request({
method: 'POST',
path: this._extension,
body: {
network: _.pick(options, properties)
}
}, function (err, body) {
return err
? callback(err)
: callback(null, body.network);
});
}
|
javascript
|
function (options, properties, callback) {
return this._request({
method: 'POST',
path: this._extension,
body: {
network: _.pick(options, properties)
}
}, function (err, body) {
return err
? callback(err)
: callback(null, body.network);
});
}
|
[
"function",
"(",
"options",
",",
"properties",
",",
"callback",
")",
"{",
"return",
"this",
".",
"_request",
"(",
"{",
"method",
":",
"'POST'",
",",
"path",
":",
"this",
".",
"_extension",
",",
"body",
":",
"{",
"network",
":",
"_",
".",
"pick",
"(",
"options",
",",
"properties",
")",
"}",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"null",
",",
"body",
".",
"network",
")",
";",
"}",
")",
";",
"}"
] |
client._createNetwork
@description helper function for allowing a different set of options to be passed to the
remote API.
@param options
@param {Array} properties Array of properties to be used when building the payload
@param callback
@returns {*}
@private
|
[
"client",
".",
"_createNetwork"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/openstack/compute/client/extensions/networks-base.js#L95-L107
|
|
9,150
|
pkgcloud/pkgcloud
|
lib/pkgcloud/openstack/compute/client/extensions/networks-base.js
|
function (network, callback) {
var networkId = (typeof network === 'object') ? network.id : network;
return this._request({
path: urlJoin(this._extension, 'add'),
method: 'POST',
body: {
id: networkId
}
}, function (err) {
return callback(err);
});
}
|
javascript
|
function (network, callback) {
var networkId = (typeof network === 'object') ? network.id : network;
return this._request({
path: urlJoin(this._extension, 'add'),
method: 'POST',
body: {
id: networkId
}
}, function (err) {
return callback(err);
});
}
|
[
"function",
"(",
"network",
",",
"callback",
")",
"{",
"var",
"networkId",
"=",
"(",
"typeof",
"network",
"===",
"'object'",
")",
"?",
"network",
".",
"id",
":",
"network",
";",
"return",
"this",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"this",
".",
"_extension",
",",
"'add'",
")",
",",
"method",
":",
"'POST'",
",",
"body",
":",
"{",
"id",
":",
"networkId",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.addNetwork
@description Add an existing network to a project
@param {String|object} network The network or networkId to add
@param {Function} callback
|
[
"client",
".",
"addNetwork"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/openstack/compute/client/extensions/networks-base.js#L117-L129
|
|
9,151
|
pkgcloud/pkgcloud
|
examples/compute/oneandone.js
|
handleServerResponse
|
function handleServerResponse(err, server) {
if (err) {
console.dir(err);
return;
}
console.log('SERVER CREATED: ' + server.name + ', waiting for active status');
// Wait for status: ACTIVE on our server, and then callback
server.setWait({ status: server.STATUS.running }, 5000, function (err) {
if (err) {
console.dir(err);
return;
}
console.log('SERVER INFO');
console.log(server.name);
console.log(server.status);
console.log(server.id);
console.log('Make sure you DELETE server: ' + server.id +
' in order to not accrue billing charges');
});
}
|
javascript
|
function handleServerResponse(err, server) {
if (err) {
console.dir(err);
return;
}
console.log('SERVER CREATED: ' + server.name + ', waiting for active status');
// Wait for status: ACTIVE on our server, and then callback
server.setWait({ status: server.STATUS.running }, 5000, function (err) {
if (err) {
console.dir(err);
return;
}
console.log('SERVER INFO');
console.log(server.name);
console.log(server.status);
console.log(server.id);
console.log('Make sure you DELETE server: ' + server.id +
' in order to not accrue billing charges');
});
}
|
[
"function",
"handleServerResponse",
"(",
"err",
",",
"server",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"dir",
"(",
"err",
")",
";",
"return",
";",
"}",
"console",
".",
"log",
"(",
"'SERVER CREATED: '",
"+",
"server",
".",
"name",
"+",
"', waiting for active status'",
")",
";",
"// Wait for status: ACTIVE on our server, and then callback\r",
"server",
".",
"setWait",
"(",
"{",
"status",
":",
"server",
".",
"STATUS",
".",
"running",
"}",
",",
"5000",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"dir",
"(",
"err",
")",
";",
"return",
";",
"}",
"console",
".",
"log",
"(",
"'SERVER INFO'",
")",
";",
"console",
".",
"log",
"(",
"server",
".",
"name",
")",
";",
"console",
".",
"log",
"(",
"server",
".",
"status",
")",
";",
"console",
".",
"log",
"(",
"server",
".",
"id",
")",
";",
"console",
".",
"log",
"(",
"'Make sure you DELETE server: '",
"+",
"server",
".",
"id",
"+",
"' in order to not accrue billing charges'",
")",
";",
"}",
")",
";",
"}"
] |
This function will handle our server creation, as well as waiting for the server to come online after we've created it.
|
[
"This",
"function",
"will",
"handle",
"our",
"server",
"creation",
"as",
"well",
"as",
"waiting",
"for",
"the",
"server",
"to",
"come",
"online",
"after",
"we",
"ve",
"created",
"it",
"."
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/examples/compute/oneandone.js#L15-L38
|
9,152
|
pkgcloud/pkgcloud
|
lib/pkgcloud/azure/utils/sharedkeytable.js
|
SharedKeyTable
|
function SharedKeyTable(storageAccount, storageAccessKey) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.signer = new HmacSha256Sign(storageAccessKey);
}
|
javascript
|
function SharedKeyTable(storageAccount, storageAccessKey) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.signer = new HmacSha256Sign(storageAccessKey);
}
|
[
"function",
"SharedKeyTable",
"(",
"storageAccount",
",",
"storageAccessKey",
")",
"{",
"this",
".",
"storageAccount",
"=",
"storageAccount",
";",
"this",
".",
"storageAccessKey",
"=",
"storageAccessKey",
";",
"this",
".",
"signer",
"=",
"new",
"HmacSha256Sign",
"(",
"storageAccessKey",
")",
";",
"}"
] |
Creates a new SharedKeyTable object.
@constructor
@param {string} storageAccount The storage account.
@param {string} storageAccessKey The storage account's access key.
|
[
"Creates",
"a",
"new",
"SharedKeyTable",
"object",
"."
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/azure/utils/sharedkeytable.js#L29-L33
|
9,153
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function(loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId)
}, function (err, body) {
if (err) {
return callback(err);
}
else if (!body || !body.loadBalancer) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, new lb.LoadBalancer(self, body.loadBalancer));
}
});
}
|
javascript
|
function(loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId)
}, function (err, body) {
if (err) {
return callback(err);
}
else if (!body || !body.loadBalancer) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, new lb.LoadBalancer(self, body.loadBalancer));
}
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
")",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"!",
"body",
"||",
"!",
"body",
".",
"loadBalancer",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Unexpected empty response'",
")",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
",",
"new",
"lb",
".",
"LoadBalancer",
"(",
"self",
",",
"body",
".",
"loadBalancer",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
client.getLoadBalancer
@description Get the details for the provided load balancer Id
@param {object|String} loadBalancer The loadBalancer or loadBalancer id for the query
@param {function} callback
@returns {*}
|
[
"client",
".",
"getLoadBalancer"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L120-L140
|
|
9,154
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function(details, callback) {
var self = this,
createOptions = {
path: _urlPrefix,
method: 'POST',
body: {
name: details.name,
nodes: details.nodes || [],
protocol: details.protocol ? details.protocol.name : '',
port: details.protocol ? details.protocol.port : '',
virtualIps: details.virtualIps
}
};
createOptions.body = _.extend(createOptions.body,
_.pick(details, ['accessList', 'algorithm', 'connectionLogging',
'connectionThrottle', 'healthMonitor', 'metadata', 'timeout',
'sessionPersistence']));
var validationErrors = validateLbInputs(createOptions.body);
if (validationErrors) {
return callback(new Error('Errors validating inputs for createLoadBalancer', validationErrors));
}
self._request(createOptions, function(err, body) {
return err
? callback(err)
: callback(err, new lb.LoadBalancer(self, body.loadBalancer));
});
}
|
javascript
|
function(details, callback) {
var self = this,
createOptions = {
path: _urlPrefix,
method: 'POST',
body: {
name: details.name,
nodes: details.nodes || [],
protocol: details.protocol ? details.protocol.name : '',
port: details.protocol ? details.protocol.port : '',
virtualIps: details.virtualIps
}
};
createOptions.body = _.extend(createOptions.body,
_.pick(details, ['accessList', 'algorithm', 'connectionLogging',
'connectionThrottle', 'healthMonitor', 'metadata', 'timeout',
'sessionPersistence']));
var validationErrors = validateLbInputs(createOptions.body);
if (validationErrors) {
return callback(new Error('Errors validating inputs for createLoadBalancer', validationErrors));
}
self._request(createOptions, function(err, body) {
return err
? callback(err)
: callback(err, new lb.LoadBalancer(self, body.loadBalancer));
});
}
|
[
"function",
"(",
"details",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"createOptions",
"=",
"{",
"path",
":",
"_urlPrefix",
",",
"method",
":",
"'POST'",
",",
"body",
":",
"{",
"name",
":",
"details",
".",
"name",
",",
"nodes",
":",
"details",
".",
"nodes",
"||",
"[",
"]",
",",
"protocol",
":",
"details",
".",
"protocol",
"?",
"details",
".",
"protocol",
".",
"name",
":",
"''",
",",
"port",
":",
"details",
".",
"protocol",
"?",
"details",
".",
"protocol",
".",
"port",
":",
"''",
",",
"virtualIps",
":",
"details",
".",
"virtualIps",
"}",
"}",
";",
"createOptions",
".",
"body",
"=",
"_",
".",
"extend",
"(",
"createOptions",
".",
"body",
",",
"_",
".",
"pick",
"(",
"details",
",",
"[",
"'accessList'",
",",
"'algorithm'",
",",
"'connectionLogging'",
",",
"'connectionThrottle'",
",",
"'healthMonitor'",
",",
"'metadata'",
",",
"'timeout'",
",",
"'sessionPersistence'",
"]",
")",
")",
";",
"var",
"validationErrors",
"=",
"validateLbInputs",
"(",
"createOptions",
".",
"body",
")",
";",
"if",
"(",
"validationErrors",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Errors validating inputs for createLoadBalancer'",
",",
"validationErrors",
")",
")",
";",
"}",
"self",
".",
"_request",
"(",
"createOptions",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"err",
",",
"new",
"lb",
".",
"LoadBalancer",
"(",
"self",
",",
"body",
".",
"loadBalancer",
")",
")",
";",
"}",
")",
";",
"}"
] |
client.createLoadBalancer
@description Create a new cloud LoadBalancer. There are a number of options for
cloud load balancers; please reference the Rackspace API documentation for more
insight into the specific parameter values:
http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Create_Load_Balancer-d1e1635.html
@param {object} details details object for the new load balancer
@param {String} details.name the name of your load balancer
@param {Object} details.protocol
@param {String} details.protocol.name protocol name
@param {Number} details.protocol.port port number
@param {Array} details.virtualIps array of virtualIps for new LB
@param {Array} [details.nodes] array of nodes to add
For extended option support please see the API documentation
@param {function} callback
@returns {*}
|
[
"client",
".",
"createLoadBalancer"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L164-L194
|
|
9,155
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (loadBalancer, callback) {
if (!(loadBalancer instanceof lb.LoadBalancer)) {
throw new Error('Missing required argument: loadBalancer');
}
var self = this,
updateOptions = {
path: urlJoin(_urlPrefix, loadBalancer.id),
method: 'PUT',
body: {}
};
updateOptions.body.loadBalancer = _.pick(loadBalancer, ['name', 'protocol',
'port', 'timeout', 'algorithm', 'httpsRedirect', 'halfClosed']);
self._request(updateOptions, function (err) {
callback(err);
});
}
|
javascript
|
function (loadBalancer, callback) {
if (!(loadBalancer instanceof lb.LoadBalancer)) {
throw new Error('Missing required argument: loadBalancer');
}
var self = this,
updateOptions = {
path: urlJoin(_urlPrefix, loadBalancer.id),
method: 'PUT',
body: {}
};
updateOptions.body.loadBalancer = _.pick(loadBalancer, ['name', 'protocol',
'port', 'timeout', 'algorithm', 'httpsRedirect', 'halfClosed']);
self._request(updateOptions, function (err) {
callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"(",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Missing required argument: loadBalancer'",
")",
";",
"}",
"var",
"self",
"=",
"this",
",",
"updateOptions",
"=",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancer",
".",
"id",
")",
",",
"method",
":",
"'PUT'",
",",
"body",
":",
"{",
"}",
"}",
";",
"updateOptions",
".",
"body",
".",
"loadBalancer",
"=",
"_",
".",
"pick",
"(",
"loadBalancer",
",",
"[",
"'name'",
",",
"'protocol'",
",",
"'port'",
",",
"'timeout'",
",",
"'algorithm'",
",",
"'httpsRedirect'",
",",
"'halfClosed'",
"]",
")",
";",
"self",
".",
"_request",
"(",
"updateOptions",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.updateLoadBalancer
@description updates specific parameters of the load balancer
Specific properties updated: name, protocol, port, timeout,
algorithm, httpsRedirect and halfClosed
@param {Object} loadBalancer
@param {function} callback
|
[
"client",
".",
"updateLoadBalancer"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L207-L226
|
|
9,156
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function(loadBalancer, details, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!details || !details.type) {
throw new Error('Details is a required option for loadBalancer health monitors');
}
var requestOptions = {
path: urlJoin(_urlPrefix, loadBalancerId, 'healthmonitor'),
method: 'PUT'
};
if (details.type === 'CONNECT') {
requestOptions.body = {
attemptsBeforeDeactivation: details.attemptsBeforeDeactivation,
type: details.type,
delay: details.delay,
timeout: details.timeout
};
}
else if (details.type === 'HTTP' || details.type === 'HTTPS') {
requestOptions.body = {
attemptsBeforeDeactivation: details.attemptsBeforeDeactivation,
type: details.type,
delay: details.delay,
timeout: details.timeout,
bodyRegex: details.bodyRegex,
path: details.path,
statusRegex: details.statusRegex
};
if (details.hostHeader) {
requestOptions.body.hostHeader = details.hostHeader;
}
}
else {
throw new Error('Unsupported health monitor type');
}
self._request(requestOptions, function (err) {
return callback(err);
});
}
|
javascript
|
function(loadBalancer, details, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!details || !details.type) {
throw new Error('Details is a required option for loadBalancer health monitors');
}
var requestOptions = {
path: urlJoin(_urlPrefix, loadBalancerId, 'healthmonitor'),
method: 'PUT'
};
if (details.type === 'CONNECT') {
requestOptions.body = {
attemptsBeforeDeactivation: details.attemptsBeforeDeactivation,
type: details.type,
delay: details.delay,
timeout: details.timeout
};
}
else if (details.type === 'HTTP' || details.type === 'HTTPS') {
requestOptions.body = {
attemptsBeforeDeactivation: details.attemptsBeforeDeactivation,
type: details.type,
delay: details.delay,
timeout: details.timeout,
bodyRegex: details.bodyRegex,
path: details.path,
statusRegex: details.statusRegex
};
if (details.hostHeader) {
requestOptions.body.hostHeader = details.hostHeader;
}
}
else {
throw new Error('Unsupported health monitor type');
}
self._request(requestOptions, function (err) {
return callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"details",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"if",
"(",
"!",
"details",
"||",
"!",
"details",
".",
"type",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Details is a required option for loadBalancer health monitors'",
")",
";",
"}",
"var",
"requestOptions",
"=",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'healthmonitor'",
")",
",",
"method",
":",
"'PUT'",
"}",
";",
"if",
"(",
"details",
".",
"type",
"===",
"'CONNECT'",
")",
"{",
"requestOptions",
".",
"body",
"=",
"{",
"attemptsBeforeDeactivation",
":",
"details",
".",
"attemptsBeforeDeactivation",
",",
"type",
":",
"details",
".",
"type",
",",
"delay",
":",
"details",
".",
"delay",
",",
"timeout",
":",
"details",
".",
"timeout",
"}",
";",
"}",
"else",
"if",
"(",
"details",
".",
"type",
"===",
"'HTTP'",
"||",
"details",
".",
"type",
"===",
"'HTTPS'",
")",
"{",
"requestOptions",
".",
"body",
"=",
"{",
"attemptsBeforeDeactivation",
":",
"details",
".",
"attemptsBeforeDeactivation",
",",
"type",
":",
"details",
".",
"type",
",",
"delay",
":",
"details",
".",
"delay",
",",
"timeout",
":",
"details",
".",
"timeout",
",",
"bodyRegex",
":",
"details",
".",
"bodyRegex",
",",
"path",
":",
"details",
".",
"path",
",",
"statusRegex",
":",
"details",
".",
"statusRegex",
"}",
";",
"if",
"(",
"details",
".",
"hostHeader",
")",
"{",
"requestOptions",
".",
"body",
".",
"hostHeader",
"=",
"details",
".",
"hostHeader",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Unsupported health monitor type'",
")",
";",
"}",
"self",
".",
"_request",
"(",
"requestOptions",
",",
"function",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.updateHealthMonitor
@description get the current health monitor configuration for a loadBalancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Object} details
@param {function} callback
There are two kinds of connection monitors you can enable, CONNECT and HTTP/HTTPS.
CONNECT monitors are basically a ping check. HTTP/HTTPS checks
are used to validate a HTTP request body/status for specific information.
Sample CONNECT details:
{
type: 'CONNECT',
delay: 10,
timeout: 10,
attemptsBeforeDeactivation: 3
}
Sample HTTP details:
{
type: 'HTTP',
delay: 10,
timeout: 10,
attemptsBeforeDeactivation: 3,
path: '/',
statusRegex: '^[234][0-9][0-9]$',
bodyRegex: '^[234][0-9][0-9]$',
hostHeader: 'myrack.com'
}
|
[
"client",
".",
"updateHealthMonitor"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L589-L633
|
|
9,157
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (loadBalancer, type, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!type || (type !== 'HTTP_COOKIE' && type !== 'SOURCE_IP')) {
throw new Error('Please provide a valid session persistence type');
}
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'sessionpersistence'),
method: 'PUT',
body: {
sessionPersistence: {
persistenceType: type
}
}
}, function (err) {
return callback(err);
});
}
|
javascript
|
function (loadBalancer, type, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!type || (type !== 'HTTP_COOKIE' && type !== 'SOURCE_IP')) {
throw new Error('Please provide a valid session persistence type');
}
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'sessionpersistence'),
method: 'PUT',
body: {
sessionPersistence: {
persistenceType: type
}
}
}, function (err) {
return callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"type",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"if",
"(",
"!",
"type",
"||",
"(",
"type",
"!==",
"'HTTP_COOKIE'",
"&&",
"type",
"!==",
"'SOURCE_IP'",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please provide a valid session persistence type'",
")",
";",
"}",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'sessionpersistence'",
")",
",",
"method",
":",
"'PUT'",
",",
"body",
":",
"{",
"sessionPersistence",
":",
"{",
"persistenceType",
":",
"type",
"}",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.enableSessionPersistence
@description Enable session persistence of the requested type
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {String} type HTTP_COOKIE or SOURCE_IP
@param {function} callback
|
[
"client",
".",
"enableSessionPersistence"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L687-L707
|
|
9,158
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (loadBalancer, details, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
var options = _.pick(details, ['maxConnectionRate', 'maxConnections',
'minConnections', 'rateInterval']);
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'connectionthrottle'),
method: 'PUT',
body: {
connectionThrottle: options
}
}, function (err) {
return callback(err);
});
}
|
javascript
|
function (loadBalancer, details, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
var options = _.pick(details, ['maxConnectionRate', 'maxConnections',
'minConnections', 'rateInterval']);
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'connectionthrottle'),
method: 'PUT',
body: {
connectionThrottle: options
}
}, function (err) {
return callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"details",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"var",
"options",
"=",
"_",
".",
"pick",
"(",
"details",
",",
"[",
"'maxConnectionRate'",
",",
"'maxConnections'",
",",
"'minConnections'",
",",
"'rateInterval'",
"]",
")",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'connectionthrottle'",
")",
",",
"method",
":",
"'PUT'",
",",
"body",
":",
"{",
"connectionThrottle",
":",
"options",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.updateConnectionThrottle
@description update or add a connection throttle for the provided load balancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Object} details the connection throttle details
@param {function} callback
Sample Access List Entry:
{
maxConnectionRate: 0, // 0 for unlimited, 1-100000
maxConnections: 10, // 0 for unlimited, 1-100000
minConnections: 5, // 0 for unlimited, 1-1000 otherwise
rateInterval: 3600 // frequency in seconds at which maxConnectionRate
// is assessed
}
|
[
"client",
".",
"updateConnectionThrottle"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L827-L844
|
|
9,159
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (startTime, endTime, options, callback) {
var self = this;
if (typeof options === 'function') {
callback = options;
options = {};
}
var requestOpts = {
path: urlJoin(_urlPrefix, 'billable'),
qs: {
startTime: typeof startTime === 'Date' ? startTime.toISOString() : startTime,
endTime: typeof endTime === 'Date' ? endTime.toISOString() : endTime
}
};
requestOpts.qs = _.extend(requestOpts.qs, _.pick(options, ['offset', 'limit']));
self._request(requestOpts, function (err, body, res) {
return callback(err, body.loadBalancers.map(function (loadBalancer) {
return new lb.LoadBalancer(self, loadBalancer);
}), res);
});
}
|
javascript
|
function (startTime, endTime, options, callback) {
var self = this;
if (typeof options === 'function') {
callback = options;
options = {};
}
var requestOpts = {
path: urlJoin(_urlPrefix, 'billable'),
qs: {
startTime: typeof startTime === 'Date' ? startTime.toISOString() : startTime,
endTime: typeof endTime === 'Date' ? endTime.toISOString() : endTime
}
};
requestOpts.qs = _.extend(requestOpts.qs, _.pick(options, ['offset', 'limit']));
self._request(requestOpts, function (err, body, res) {
return callback(err, body.loadBalancers.map(function (loadBalancer) {
return new lb.LoadBalancer(self, loadBalancer);
}), res);
});
}
|
[
"function",
"(",
"startTime",
",",
"endTime",
",",
"options",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"var",
"requestOpts",
"=",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"'billable'",
")",
",",
"qs",
":",
"{",
"startTime",
":",
"typeof",
"startTime",
"===",
"'Date'",
"?",
"startTime",
".",
"toISOString",
"(",
")",
":",
"startTime",
",",
"endTime",
":",
"typeof",
"endTime",
"===",
"'Date'",
"?",
"endTime",
".",
"toISOString",
"(",
")",
":",
"endTime",
"}",
"}",
";",
"requestOpts",
".",
"qs",
"=",
"_",
".",
"extend",
"(",
"requestOpts",
".",
"qs",
",",
"_",
".",
"pick",
"(",
"options",
",",
"[",
"'offset'",
",",
"'limit'",
"]",
")",
")",
";",
"self",
".",
"_request",
"(",
"requestOpts",
",",
"function",
"(",
"err",
",",
"body",
",",
"res",
")",
"{",
"return",
"callback",
"(",
"err",
",",
"body",
".",
"loadBalancers",
".",
"map",
"(",
"function",
"(",
"loadBalancer",
")",
"{",
"return",
"new",
"lb",
".",
"LoadBalancer",
"(",
"self",
",",
"loadBalancer",
")",
";",
"}",
")",
",",
"res",
")",
";",
"}",
")",
";",
"}"
] |
client.getBillableLoadBalancers
@description gets the billable load balancer within the query limits provided
@param {Date|String} startTime the start time for the query
@param {Date|String} endTime the end time for the query
@param {object} [options]
@param {object} [options.limit]
@param {object} [options.offset]
@param {function} callback
|
[
"client",
".",
"getBillableLoadBalancers"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L1033-L1056
|
|
9,160
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (startTime, endTime, callback) {
var self = this;
self._request({
path: urlJoin(_urlPrefix, 'usage'),
qs: {
startTime: typeof startTime === 'Date' ? startTime.toISOString() : startTime,
endTime: typeof endTime === 'Date' ? endTime.toISOString() : endTime
}
}, function (err, body) {
return callback(err, body);
});
}
|
javascript
|
function (startTime, endTime, callback) {
var self = this;
self._request({
path: urlJoin(_urlPrefix, 'usage'),
qs: {
startTime: typeof startTime === 'Date' ? startTime.toISOString() : startTime,
endTime: typeof endTime === 'Date' ? endTime.toISOString() : endTime
}
}, function (err, body) {
return callback(err, body);
});
}
|
[
"function",
"(",
"startTime",
",",
"endTime",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"'usage'",
")",
",",
"qs",
":",
"{",
"startTime",
":",
"typeof",
"startTime",
"===",
"'Date'",
"?",
"startTime",
".",
"toISOString",
"(",
")",
":",
"startTime",
",",
"endTime",
":",
"typeof",
"endTime",
"===",
"'Date'",
"?",
"endTime",
".",
"toISOString",
"(",
")",
":",
"endTime",
"}",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"callback",
"(",
"err",
",",
"body",
")",
";",
"}",
")",
";",
"}"
] |
client.getAccountUsage
@description lists account level usage
@param {Date|String} startTime the start time for the query
@param {Date|String} endTime the end time for the query
@param {function} callback
|
[
"client",
".",
"getAccountUsage"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L1067-L1079
|
|
9,161
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js
|
function (callback) {
var self = this;
self._request({
path: urlJoin(_urlPrefix, 'alloweddomains')
}, function (err, body) {
return callback(err, body.allowedDomains);
});
}
|
javascript
|
function (callback) {
var self = this;
self._request({
path: urlJoin(_urlPrefix, 'alloweddomains')
}, function (err, body) {
return callback(err, body.allowedDomains);
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"'alloweddomains'",
")",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"callback",
"(",
"err",
",",
"body",
".",
"allowedDomains",
")",
";",
"}",
")",
";",
"}"
] |
client.getAllowedDomains
@description gets a list of domains that are available in lieu of IP addresses
when adding nodes to a load balancer
@param {function} callback
|
[
"client",
".",
"getAllowedDomains"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/loadbalancers.js#L1135-L1143
|
|
9,162
|
pkgcloud/pkgcloud
|
lib/pkgcloud/azure/utils/sharedkey.js
|
SharedKey
|
function SharedKey(storageAccount, storageAccessKey) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.signer = new HmacSha256Sign(storageAccessKey);
}
|
javascript
|
function SharedKey(storageAccount, storageAccessKey) {
this.storageAccount = storageAccount;
this.storageAccessKey = storageAccessKey;
this.signer = new HmacSha256Sign(storageAccessKey);
}
|
[
"function",
"SharedKey",
"(",
"storageAccount",
",",
"storageAccessKey",
")",
"{",
"this",
".",
"storageAccount",
"=",
"storageAccount",
";",
"this",
".",
"storageAccessKey",
"=",
"storageAccessKey",
";",
"this",
".",
"signer",
"=",
"new",
"HmacSha256Sign",
"(",
"storageAccessKey",
")",
";",
"}"
] |
Creates a new SharedKey object.
@constructor
@param {string} storageAccount The storage account.
@param {string} storageAccessKey The storage account's access key.
|
[
"Creates",
"a",
"new",
"SharedKey",
"object",
"."
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/azure/utils/sharedkey.js#L31-L35
|
9,163
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function (loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes')
}, function (err, body, res) {
if (err) {
return callback(err);
}
else if (!body || !body.nodes) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, body.nodes.map(function (node) {
return new lb.Node(self,
_.extend(node, { loadBalancerId: loadBalancerId }));
}), res);
}
});
}
|
javascript
|
function (loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes')
}, function (err, body, res) {
if (err) {
return callback(err);
}
else if (!body || !body.nodes) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, body.nodes.map(function (node) {
return new lb.Node(self,
_.extend(node, { loadBalancerId: loadBalancerId }));
}), res);
}
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
")",
"}",
",",
"function",
"(",
"err",
",",
"body",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"!",
"body",
"||",
"!",
"body",
".",
"nodes",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Unexpected empty response'",
")",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
",",
"body",
".",
"nodes",
".",
"map",
"(",
"function",
"(",
"node",
")",
"{",
"return",
"new",
"lb",
".",
"Node",
"(",
"self",
",",
"_",
".",
"extend",
"(",
"node",
",",
"{",
"loadBalancerId",
":",
"loadBalancerId",
"}",
")",
")",
";",
"}",
")",
",",
"res",
")",
";",
"}",
"}",
")",
";",
"}"
] |
client.getNodes
@description get an array of nodes for the provided load balancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {function} callback
|
[
"client",
".",
"getNodes"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L27-L50
|
|
9,164
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function(loadBalancer, nodes, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!Array.isArray(nodes)) {
nodes = [ nodes ];
}
var postOptions = {
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes'),
method: 'POST',
body: { nodes: [] }
};
postOptions.body.nodes = _.map(nodes, function(node) {
return _.pick(node, ['address', 'port', 'condition', 'type', 'weight']);
});
self._request(postOptions, function (err, body, res) {
if (err) {
return callback(err);
}
else if (!body || !body.nodes) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, body.nodes.map(function (node) {
return new lb.Node(self,
_.extend(node, { loadBalancerId: loadBalancerId }));
}), res);
}
});
}
|
javascript
|
function(loadBalancer, nodes, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!Array.isArray(nodes)) {
nodes = [ nodes ];
}
var postOptions = {
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes'),
method: 'POST',
body: { nodes: [] }
};
postOptions.body.nodes = _.map(nodes, function(node) {
return _.pick(node, ['address', 'port', 'condition', 'type', 'weight']);
});
self._request(postOptions, function (err, body, res) {
if (err) {
return callback(err);
}
else if (!body || !body.nodes) {
return callback(new Error('Unexpected empty response'));
}
else {
return callback(null, body.nodes.map(function (node) {
return new lb.Node(self,
_.extend(node, { loadBalancerId: loadBalancerId }));
}), res);
}
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"nodes",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"nodes",
")",
")",
"{",
"nodes",
"=",
"[",
"nodes",
"]",
";",
"}",
"var",
"postOptions",
"=",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
")",
",",
"method",
":",
"'POST'",
",",
"body",
":",
"{",
"nodes",
":",
"[",
"]",
"}",
"}",
";",
"postOptions",
".",
"body",
".",
"nodes",
"=",
"_",
".",
"map",
"(",
"nodes",
",",
"function",
"(",
"node",
")",
"{",
"return",
"_",
".",
"pick",
"(",
"node",
",",
"[",
"'address'",
",",
"'port'",
",",
"'condition'",
",",
"'type'",
",",
"'weight'",
"]",
")",
";",
"}",
")",
";",
"self",
".",
"_request",
"(",
"postOptions",
",",
"function",
"(",
"err",
",",
"body",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"!",
"body",
"||",
"!",
"body",
".",
"nodes",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Unexpected empty response'",
")",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
",",
"body",
".",
"nodes",
".",
"map",
"(",
"function",
"(",
"node",
")",
"{",
"return",
"new",
"lb",
".",
"Node",
"(",
"self",
",",
"_",
".",
"extend",
"(",
"node",
",",
"{",
"loadBalancerId",
":",
"loadBalancerId",
"}",
")",
")",
";",
"}",
")",
",",
"res",
")",
";",
"}",
"}",
")",
";",
"}"
] |
client.addNodes
@description add a node or array of nodes to the provided load balancer. Each of the addresses must be unique to this load balancer.
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Object|Array} nodes list of nodes to add
@param {function} callback
Sample node
{
address: '192.168.10.1',
port: 80,
condition: 'ENABLED', // also supports 'DISABLED' & 'DRAINING'
type: 'PRIMARY' // use 'SECONDARY' as a fail over node
}
|
[
"client",
".",
"addNodes"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L71-L106
|
|
9,165
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function(loadBalancer, node, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!(node instanceof lb.Node) && (typeof node !== 'object')) {
throw new Error('node is a required argument and must be an object');
}
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', node.id),
method: 'PUT',
body: {
node: _.pick(node, ['condition', 'type', 'weight'])
}
}, function (err) {
callback(err);
});
}
|
javascript
|
function(loadBalancer, node, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
if (!(node instanceof lb.Node) && (typeof node !== 'object')) {
throw new Error('node is a required argument and must be an object');
}
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', node.id),
method: 'PUT',
body: {
node: _.pick(node, ['condition', 'type', 'weight'])
}
}, function (err) {
callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"node",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"if",
"(",
"!",
"(",
"node",
"instanceof",
"lb",
".",
"Node",
")",
"&&",
"(",
"typeof",
"node",
"!==",
"'object'",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'node is a required argument and must be an object'",
")",
";",
"}",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
",",
"node",
".",
"id",
")",
",",
"method",
":",
"'PUT'",
",",
"body",
":",
"{",
"node",
":",
"_",
".",
"pick",
"(",
"node",
",",
"[",
"'condition'",
",",
"'type'",
",",
"'weight'",
"]",
")",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.updateNode
@description update a node condition, type, or weight
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Object} node the node to update
@param {function} callback
|
[
"client",
".",
"updateNode"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L117-L135
|
|
9,166
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function (loadBalancer, node, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer,
nodeId =
node instanceof lb.Node ? node.id : node;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', nodeId),
method: 'DELETE'
}, function (err) {
callback(err);
});
}
|
javascript
|
function (loadBalancer, node, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer,
nodeId =
node instanceof lb.Node ? node.id : node;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', nodeId),
method: 'DELETE'
}, function (err) {
callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"node",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
",",
"nodeId",
"=",
"node",
"instanceof",
"lb",
".",
"Node",
"?",
"node",
".",
"id",
":",
"node",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
",",
"nodeId",
")",
",",
"method",
":",
"'DELETE'",
"}",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.removeNode
@description remove a node from a load balancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Object} node the node or nodeId to remove
@param {function} callback
|
[
"client",
".",
"removeNode"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L146-L159
|
|
9,167
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function (loadBalancer, nodes, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
// check for valid inputs
if (!nodes || nodes.length === 0 || !Array.isArray(nodes)) {
throw new Error('nodes must be an array of Node or nodeId');
}
// support passing either the javascript object or an array of ids
var list = nodes.map(function (item) {
return (typeof item === 'object') ? item.id : item;
});
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', '?id=' + list.join('&id=')),
method: 'DELETE'
}, function (err) {
callback(err);
});
}
|
javascript
|
function (loadBalancer, nodes, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
// check for valid inputs
if (!nodes || nodes.length === 0 || !Array.isArray(nodes)) {
throw new Error('nodes must be an array of Node or nodeId');
}
// support passing either the javascript object or an array of ids
var list = nodes.map(function (item) {
return (typeof item === 'object') ? item.id : item;
});
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', '?id=' + list.join('&id=')),
method: 'DELETE'
}, function (err) {
callback(err);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"nodes",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"// check for valid inputs",
"if",
"(",
"!",
"nodes",
"||",
"nodes",
".",
"length",
"===",
"0",
"||",
"!",
"Array",
".",
"isArray",
"(",
"nodes",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'nodes must be an array of Node or nodeId'",
")",
";",
"}",
"// support passing either the javascript object or an array of ids",
"var",
"list",
"=",
"nodes",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"(",
"typeof",
"item",
"===",
"'object'",
")",
"?",
"item",
".",
"id",
":",
"item",
";",
"}",
")",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
",",
"'?id='",
"+",
"list",
".",
"join",
"(",
"'&id='",
")",
")",
",",
"method",
":",
"'DELETE'",
"}",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] |
client.removeNodes
@description remove an array of nodes or nodeIds from a load balancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {Array} nodes the nodes or nodeIds to remove
@param {function} callback
|
[
"client",
".",
"removeNodes"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L170-L191
|
|
9,168
|
pkgcloud/pkgcloud
|
lib/pkgcloud/rackspace/loadbalancer/client/nodes.js
|
function (loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', 'events')
}, function (err, body) {
return err
? callback(err)
: callback(err, body.nodeServiceEvents);
});
}
|
javascript
|
function (loadBalancer, callback) {
var self = this,
loadBalancerId =
loadBalancer instanceof lb.LoadBalancer ? loadBalancer.id : loadBalancer;
self._request({
path: urlJoin(_urlPrefix, loadBalancerId, 'nodes', 'events')
}, function (err, body) {
return err
? callback(err)
: callback(err, body.nodeServiceEvents);
});
}
|
[
"function",
"(",
"loadBalancer",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"loadBalancerId",
"=",
"loadBalancer",
"instanceof",
"lb",
".",
"LoadBalancer",
"?",
"loadBalancer",
".",
"id",
":",
"loadBalancer",
";",
"self",
".",
"_request",
"(",
"{",
"path",
":",
"urlJoin",
"(",
"_urlPrefix",
",",
"loadBalancerId",
",",
"'nodes'",
",",
"'events'",
")",
"}",
",",
"function",
"(",
"err",
",",
"body",
")",
"{",
"return",
"err",
"?",
"callback",
"(",
"err",
")",
":",
"callback",
"(",
"err",
",",
"body",
".",
"nodeServiceEvents",
")",
";",
"}",
")",
";",
"}"
] |
client.getNodeServiceEvents
@description retrieve a list of events associated with the activity
between the node and the load balancer
@param {Object} loadBalancer the loadBalancer or loadBalancerId
@param {function} callback
|
[
"client",
".",
"getNodeServiceEvents"
] |
44e08a0063252829cdb5e9a8b430c2f4c08b91ad
|
https://github.com/pkgcloud/pkgcloud/blob/44e08a0063252829cdb5e9a8b430c2f4c08b91ad/lib/pkgcloud/rackspace/loadbalancer/client/nodes.js#L202-L214
|
|
9,169
|
emailjs/emailjs-imap-client
|
dist/command-parser.js
|
encodeAddressName
|
function encodeAddressName(name) {
if (!/^[\w ']*$/.test(name)) {
if (/^[\x20-\x7e]*$/.test(name)) {
return JSON.stringify(name);
} else {
return (0, _emailjsMimeCodec.mimeWordEncode)(name, 'Q', 52);
}
}
return name;
}
|
javascript
|
function encodeAddressName(name) {
if (!/^[\w ']*$/.test(name)) {
if (/^[\x20-\x7e]*$/.test(name)) {
return JSON.stringify(name);
} else {
return (0, _emailjsMimeCodec.mimeWordEncode)(name, 'Q', 52);
}
}
return name;
}
|
[
"function",
"encodeAddressName",
"(",
"name",
")",
"{",
"if",
"(",
"!",
"/",
"^[\\w ']*$",
"/",
".",
"test",
"(",
"name",
")",
")",
"{",
"if",
"(",
"/",
"^[\\x20-\\x7e]*$",
"/",
".",
"test",
"(",
"name",
")",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"name",
")",
";",
"}",
"else",
"{",
"return",
"(",
"0",
",",
"_emailjsMimeCodec",
".",
"mimeWordEncode",
")",
"(",
"name",
",",
"'Q'",
",",
"52",
")",
";",
"}",
"}",
"return",
"name",
";",
"}"
] |
If needed, encloses with quotes or mime encodes the name part of an e-mail address
@param {String} name Name part of an address
@returns {String} Mime word encoded or quoted string
|
[
"If",
"needed",
"encloses",
"with",
"quotes",
"or",
"mime",
"encodes",
"the",
"name",
"part",
"of",
"an",
"e",
"-",
"mail",
"address"
] |
32e768c83afe7a75433e1617b16e48eff318a957
|
https://github.com/emailjs/emailjs-imap-client/blob/32e768c83afe7a75433e1617b16e48eff318a957/dist/command-parser.js#L201-L210
|
9,170
|
emailjs/emailjs-imap-client
|
src/command-parser.js
|
parseFetchValue
|
function parseFetchValue (key, value) {
if (!value) {
return null
}
if (!Array.isArray(value)) {
switch (key) {
case 'uid':
case 'rfc822.size':
return Number(value.value) || 0
case 'modseq': // do not cast 64 bit uint to a number
return value.value || '0'
}
return value.value
}
switch (key) {
case 'flags':
case 'x-gm-labels':
value = [].concat(value).map((flag) => (flag.value || ''))
break
case 'envelope':
value = parseENVELOPE([].concat(value || []))
break
case 'bodystructure':
value = parseBODYSTRUCTURE([].concat(value || []))
break
case 'modseq':
value = (value.shift() || {}).value || '0'
break
}
return value
}
|
javascript
|
function parseFetchValue (key, value) {
if (!value) {
return null
}
if (!Array.isArray(value)) {
switch (key) {
case 'uid':
case 'rfc822.size':
return Number(value.value) || 0
case 'modseq': // do not cast 64 bit uint to a number
return value.value || '0'
}
return value.value
}
switch (key) {
case 'flags':
case 'x-gm-labels':
value = [].concat(value).map((flag) => (flag.value || ''))
break
case 'envelope':
value = parseENVELOPE([].concat(value || []))
break
case 'bodystructure':
value = parseBODYSTRUCTURE([].concat(value || []))
break
case 'modseq':
value = (value.shift() || {}).value || '0'
break
}
return value
}
|
[
"function",
"parseFetchValue",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"!",
"value",
")",
"{",
"return",
"null",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"switch",
"(",
"key",
")",
"{",
"case",
"'uid'",
":",
"case",
"'rfc822.size'",
":",
"return",
"Number",
"(",
"value",
".",
"value",
")",
"||",
"0",
"case",
"'modseq'",
":",
"// do not cast 64 bit uint to a number",
"return",
"value",
".",
"value",
"||",
"'0'",
"}",
"return",
"value",
".",
"value",
"}",
"switch",
"(",
"key",
")",
"{",
"case",
"'flags'",
":",
"case",
"'x-gm-labels'",
":",
"value",
"=",
"[",
"]",
".",
"concat",
"(",
"value",
")",
".",
"map",
"(",
"(",
"flag",
")",
"=>",
"(",
"flag",
".",
"value",
"||",
"''",
")",
")",
"break",
"case",
"'envelope'",
":",
"value",
"=",
"parseENVELOPE",
"(",
"[",
"]",
".",
"concat",
"(",
"value",
"||",
"[",
"]",
")",
")",
"break",
"case",
"'bodystructure'",
":",
"value",
"=",
"parseBODYSTRUCTURE",
"(",
"[",
"]",
".",
"concat",
"(",
"value",
"||",
"[",
"]",
")",
")",
"break",
"case",
"'modseq'",
":",
"value",
"=",
"(",
"value",
".",
"shift",
"(",
")",
"||",
"{",
"}",
")",
".",
"value",
"||",
"'0'",
"break",
"}",
"return",
"value",
"}"
] |
Parses a single value from the FETCH response object
@param {String} key Key name (uppercase)
@param {Mized} value Value for the key
@return {Mixed} Processed value
|
[
"Parses",
"a",
"single",
"value",
"from",
"the",
"FETCH",
"response",
"object"
] |
32e768c83afe7a75433e1617b16e48eff318a957
|
https://github.com/emailjs/emailjs-imap-client/blob/32e768c83afe7a75433e1617b16e48eff318a957/src/command-parser.js#L400-L433
|
9,171
|
emailjs/emailjs-imap-client
|
dist/command-builder.js
|
buildFETCHCommand
|
function buildFETCHCommand(sequence, items, options) {
let command = {
command: options.byUid ? 'UID FETCH' : 'FETCH',
attributes: [{
type: 'SEQUENCE',
value: sequence
}]
};
if (options.valueAsString !== undefined) {
command.valueAsString = options.valueAsString;
}
let query = [];
items.forEach(item => {
item = item.toUpperCase().trim();
if (/^\w+$/.test(item)) {
// alphanum strings can be used directly
query.push({
type: 'ATOM',
value: item
});
} else if (item) {
try {
// parse the value as a fake command, use only the attributes block
const cmd = (0, _emailjsImapHandler.parser)((0, _common.toTypedArray)('* Z ' + item));
query = query.concat(cmd.attributes || []);
} catch (e) {
// if parse failed, use the original string as one entity
query.push({
type: 'ATOM',
value: item
});
}
}
});
if (query.length === 1) {
query = query.pop();
}
command.attributes.push(query);
if (options.changedSince) {
command.attributes.push([{
type: 'ATOM',
value: 'CHANGEDSINCE'
}, {
type: 'ATOM',
value: options.changedSince
}]);
}
return command;
}
|
javascript
|
function buildFETCHCommand(sequence, items, options) {
let command = {
command: options.byUid ? 'UID FETCH' : 'FETCH',
attributes: [{
type: 'SEQUENCE',
value: sequence
}]
};
if (options.valueAsString !== undefined) {
command.valueAsString = options.valueAsString;
}
let query = [];
items.forEach(item => {
item = item.toUpperCase().trim();
if (/^\w+$/.test(item)) {
// alphanum strings can be used directly
query.push({
type: 'ATOM',
value: item
});
} else if (item) {
try {
// parse the value as a fake command, use only the attributes block
const cmd = (0, _emailjsImapHandler.parser)((0, _common.toTypedArray)('* Z ' + item));
query = query.concat(cmd.attributes || []);
} catch (e) {
// if parse failed, use the original string as one entity
query.push({
type: 'ATOM',
value: item
});
}
}
});
if (query.length === 1) {
query = query.pop();
}
command.attributes.push(query);
if (options.changedSince) {
command.attributes.push([{
type: 'ATOM',
value: 'CHANGEDSINCE'
}, {
type: 'ATOM',
value: options.changedSince
}]);
}
return command;
}
|
[
"function",
"buildFETCHCommand",
"(",
"sequence",
",",
"items",
",",
"options",
")",
"{",
"let",
"command",
"=",
"{",
"command",
":",
"options",
".",
"byUid",
"?",
"'UID FETCH'",
":",
"'FETCH'",
",",
"attributes",
":",
"[",
"{",
"type",
":",
"'SEQUENCE'",
",",
"value",
":",
"sequence",
"}",
"]",
"}",
";",
"if",
"(",
"options",
".",
"valueAsString",
"!==",
"undefined",
")",
"{",
"command",
".",
"valueAsString",
"=",
"options",
".",
"valueAsString",
";",
"}",
"let",
"query",
"=",
"[",
"]",
";",
"items",
".",
"forEach",
"(",
"item",
"=>",
"{",
"item",
"=",
"item",
".",
"toUpperCase",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"/",
"^\\w+$",
"/",
".",
"test",
"(",
"item",
")",
")",
"{",
"// alphanum strings can be used directly",
"query",
".",
"push",
"(",
"{",
"type",
":",
"'ATOM'",
",",
"value",
":",
"item",
"}",
")",
";",
"}",
"else",
"if",
"(",
"item",
")",
"{",
"try",
"{",
"// parse the value as a fake command, use only the attributes block",
"const",
"cmd",
"=",
"(",
"0",
",",
"_emailjsImapHandler",
".",
"parser",
")",
"(",
"(",
"0",
",",
"_common",
".",
"toTypedArray",
")",
"(",
"'* Z '",
"+",
"item",
")",
")",
";",
"query",
"=",
"query",
".",
"concat",
"(",
"cmd",
".",
"attributes",
"||",
"[",
"]",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// if parse failed, use the original string as one entity",
"query",
".",
"push",
"(",
"{",
"type",
":",
"'ATOM'",
",",
"value",
":",
"item",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"if",
"(",
"query",
".",
"length",
"===",
"1",
")",
"{",
"query",
"=",
"query",
".",
"pop",
"(",
")",
";",
"}",
"command",
".",
"attributes",
".",
"push",
"(",
"query",
")",
";",
"if",
"(",
"options",
".",
"changedSince",
")",
"{",
"command",
".",
"attributes",
".",
"push",
"(",
"[",
"{",
"type",
":",
"'ATOM'",
",",
"value",
":",
"'CHANGEDSINCE'",
"}",
",",
"{",
"type",
":",
"'ATOM'",
",",
"value",
":",
"options",
".",
"changedSince",
"}",
"]",
")",
";",
"}",
"return",
"command",
";",
"}"
] |
Builds a FETCH command
@param {String} sequence Message range selector
@param {Array} items List of elements to fetch (eg. `['uid', 'envelope']`).
@param {Object} [options] Optional options object. Use `{byUid:true}` for `UID FETCH`
@returns {Object} Structured IMAP command
|
[
"Builds",
"a",
"FETCH",
"command"
] |
32e768c83afe7a75433e1617b16e48eff318a957
|
https://github.com/emailjs/emailjs-imap-client/blob/32e768c83afe7a75433e1617b16e48eff318a957/dist/command-builder.js#L27-L83
|
9,172
|
emailjs/emailjs-imap-client
|
dist/command-builder.js
|
buildXOAuth2Token
|
function buildXOAuth2Token(user = '', token) {
let authData = [`user=${user}`, `auth=Bearer ${token}`, '', ''];
return (0, _emailjsBase.encode)(authData.join('\x01'));
}
|
javascript
|
function buildXOAuth2Token(user = '', token) {
let authData = [`user=${user}`, `auth=Bearer ${token}`, '', ''];
return (0, _emailjsBase.encode)(authData.join('\x01'));
}
|
[
"function",
"buildXOAuth2Token",
"(",
"user",
"=",
"''",
",",
"token",
")",
"{",
"let",
"authData",
"=",
"[",
"`",
"${",
"user",
"}",
"`",
",",
"`",
"${",
"token",
"}",
"`",
",",
"''",
",",
"''",
"]",
";",
"return",
"(",
"0",
",",
"_emailjsBase",
".",
"encode",
")",
"(",
"authData",
".",
"join",
"(",
"'\\x01'",
")",
")",
";",
"}"
] |
Builds a login token for XOAUTH2 authentication command
@param {String} user E-mail address of the user
@param {String} token Valid access token for the user
@return {String} Base64 formatted login token
|
[
"Builds",
"a",
"login",
"token",
"for",
"XOAUTH2",
"authentication",
"command"
] |
32e768c83afe7a75433e1617b16e48eff318a957
|
https://github.com/emailjs/emailjs-imap-client/blob/32e768c83afe7a75433e1617b16e48eff318a957/dist/command-builder.js#L92-L95
|
9,173
|
emailjs/emailjs-imap-client
|
dist/command-builder.js
|
buildSTORECommand
|
function buildSTORECommand(sequence, action = '', flags = [], options = {}) {
let command = {
command: options.byUid ? 'UID STORE' : 'STORE',
attributes: [{
type: 'sequence',
value: sequence
}]
};
command.attributes.push({
type: 'atom',
value: action.toUpperCase() + (options.silent ? '.SILENT' : '')
});
command.attributes.push(flags.map(flag => {
return {
type: 'atom',
value: flag
};
}));
return command;
}
|
javascript
|
function buildSTORECommand(sequence, action = '', flags = [], options = {}) {
let command = {
command: options.byUid ? 'UID STORE' : 'STORE',
attributes: [{
type: 'sequence',
value: sequence
}]
};
command.attributes.push({
type: 'atom',
value: action.toUpperCase() + (options.silent ? '.SILENT' : '')
});
command.attributes.push(flags.map(flag => {
return {
type: 'atom',
value: flag
};
}));
return command;
}
|
[
"function",
"buildSTORECommand",
"(",
"sequence",
",",
"action",
"=",
"''",
",",
"flags",
"=",
"[",
"]",
",",
"options",
"=",
"{",
"}",
")",
"{",
"let",
"command",
"=",
"{",
"command",
":",
"options",
".",
"byUid",
"?",
"'UID STORE'",
":",
"'STORE'",
",",
"attributes",
":",
"[",
"{",
"type",
":",
"'sequence'",
",",
"value",
":",
"sequence",
"}",
"]",
"}",
";",
"command",
".",
"attributes",
".",
"push",
"(",
"{",
"type",
":",
"'atom'",
",",
"value",
":",
"action",
".",
"toUpperCase",
"(",
")",
"+",
"(",
"options",
".",
"silent",
"?",
"'.SILENT'",
":",
"''",
")",
"}",
")",
";",
"command",
".",
"attributes",
".",
"push",
"(",
"flags",
".",
"map",
"(",
"flag",
"=>",
"{",
"return",
"{",
"type",
":",
"'atom'",
",",
"value",
":",
"flag",
"}",
";",
"}",
")",
")",
";",
"return",
"command",
";",
"}"
] |
Creates an IMAP STORE command from the selected arguments
|
[
"Creates",
"an",
"IMAP",
"STORE",
"command",
"from",
"the",
"selected",
"arguments"
] |
32e768c83afe7a75433e1617b16e48eff318a957
|
https://github.com/emailjs/emailjs-imap-client/blob/32e768c83afe7a75433e1617b16e48eff318a957/dist/command-builder.js#L217-L239
|
9,174
|
davidkpiano/react-redux-form
|
src/utils/shallow-equal.js
|
shallowEqual
|
function shallowEqual(objA, objB, options = {}) {
if (is(objA, objB)) {
return true;
}
if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
return false;
}
if(objA instanceof Date && objB instanceof Date) {
return objA === objB;
}
const keysA = Object.keys(objA);
const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
const {
omitKeys,
deepKeys,
} = options;
// Test for A's keys different from B.
for (let i = 0; i < keysA.length; i++) {
// if key is an omitted key, skip comparison
if (omitKeys && omitKeys.length && ~omitKeys.indexOf(keysA[i])) continue;
if (deepKeys && deepKeys.length && ~deepKeys.indexOf(keysA[i])) {
const result = shallowEqual(objA[keysA[i]], objB[keysA[i]]);
if (!result) return false;
} else if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
|
javascript
|
function shallowEqual(objA, objB, options = {}) {
if (is(objA, objB)) {
return true;
}
if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
return false;
}
if(objA instanceof Date && objB instanceof Date) {
return objA === objB;
}
const keysA = Object.keys(objA);
const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
const {
omitKeys,
deepKeys,
} = options;
// Test for A's keys different from B.
for (let i = 0; i < keysA.length; i++) {
// if key is an omitted key, skip comparison
if (omitKeys && omitKeys.length && ~omitKeys.indexOf(keysA[i])) continue;
if (deepKeys && deepKeys.length && ~deepKeys.indexOf(keysA[i])) {
const result = shallowEqual(objA[keysA[i]], objB[keysA[i]]);
if (!result) return false;
} else if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
|
[
"function",
"shallowEqual",
"(",
"objA",
",",
"objB",
",",
"options",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"is",
"(",
"objA",
",",
"objB",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"(",
"typeof",
"objA",
"===",
"'undefined'",
"?",
"'undefined'",
":",
"_typeof",
"(",
"objA",
")",
")",
"!==",
"'object'",
"||",
"objA",
"===",
"null",
"||",
"(",
"typeof",
"objB",
"===",
"'undefined'",
"?",
"'undefined'",
":",
"_typeof",
"(",
"objB",
")",
")",
"!==",
"'object'",
"||",
"objB",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"objA",
"instanceof",
"Date",
"&&",
"objB",
"instanceof",
"Date",
")",
"{",
"return",
"objA",
"===",
"objB",
";",
"}",
"const",
"keysA",
"=",
"Object",
".",
"keys",
"(",
"objA",
")",
";",
"const",
"keysB",
"=",
"Object",
".",
"keys",
"(",
"objB",
")",
";",
"if",
"(",
"keysA",
".",
"length",
"!==",
"keysB",
".",
"length",
")",
"{",
"return",
"false",
";",
"}",
"const",
"{",
"omitKeys",
",",
"deepKeys",
",",
"}",
"=",
"options",
";",
"// Test for A's keys different from B.",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"keysA",
".",
"length",
";",
"i",
"++",
")",
"{",
"// if key is an omitted key, skip comparison",
"if",
"(",
"omitKeys",
"&&",
"omitKeys",
".",
"length",
"&&",
"~",
"omitKeys",
".",
"indexOf",
"(",
"keysA",
"[",
"i",
"]",
")",
")",
"continue",
";",
"if",
"(",
"deepKeys",
"&&",
"deepKeys",
".",
"length",
"&&",
"~",
"deepKeys",
".",
"indexOf",
"(",
"keysA",
"[",
"i",
"]",
")",
")",
"{",
"const",
"result",
"=",
"shallowEqual",
"(",
"objA",
"[",
"keysA",
"[",
"i",
"]",
"]",
",",
"objB",
"[",
"keysA",
"[",
"i",
"]",
"]",
")",
";",
"if",
"(",
"!",
"result",
")",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"!",
"hasOwnProperty",
".",
"call",
"(",
"objB",
",",
"keysA",
"[",
"i",
"]",
")",
"||",
"!",
"is",
"(",
"objA",
"[",
"keysA",
"[",
"i",
"]",
"]",
",",
"objB",
"[",
"keysA",
"[",
"i",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Performs equality by iterating through keys on an object and returning false
when any key has values which are not strictly equal between the arguments.
Returns true when the values of all keys are strictly equal.
|
[
"Performs",
"equality",
"by",
"iterating",
"through",
"keys",
"on",
"an",
"object",
"and",
"returning",
"false",
"when",
"any",
"key",
"has",
"values",
"which",
"are",
"not",
"strictly",
"equal",
"between",
"the",
"arguments",
".",
"Returns",
"true",
"when",
"the",
"values",
"of",
"all",
"keys",
"are",
"strictly",
"equal",
"."
] |
57028979c87e6f377104bf4069ff951e1a9faa19
|
https://github.com/davidkpiano/react-redux-form/blob/57028979c87e6f377104bf4069ff951e1a9faa19/src/utils/shallow-equal.js#L32-L73
|
9,175
|
node-influx/node-influx
|
examples/esdoc-plugin.js
|
rewriteFonts
|
function rewriteFonts () {
const style = path.join(target, 'css', 'style.css')
const css = fs.readFileSync(style)
.toString()
.replace(/@import url\(.*?Roboto.*?\);/, `@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600|Source+Code+Pro:400,600');`)
.replace(/Roboto/g, 'Open Sans')
fs.writeFileSync(style, `
${css}
code {
font-family: 'Source Code Pro', monospace;
}
pre > code {
padding: 0.75em 1em;
line-height: 1.5em;
}
ul, ol {
margin-bottom: 15px;
}
hr {
border: 0;
height: 2px;
background: #f5f5f5;
margin: 15px 0;
}
blockquote {
border-left: 3px solid #eee;
padding-left: 0.75em;
margin-bottom: 15px;
color: #999;
font-size: 0.9em;
}
`)
}
|
javascript
|
function rewriteFonts () {
const style = path.join(target, 'css', 'style.css')
const css = fs.readFileSync(style)
.toString()
.replace(/@import url\(.*?Roboto.*?\);/, `@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600|Source+Code+Pro:400,600');`)
.replace(/Roboto/g, 'Open Sans')
fs.writeFileSync(style, `
${css}
code {
font-family: 'Source Code Pro', monospace;
}
pre > code {
padding: 0.75em 1em;
line-height: 1.5em;
}
ul, ol {
margin-bottom: 15px;
}
hr {
border: 0;
height: 2px;
background: #f5f5f5;
margin: 15px 0;
}
blockquote {
border-left: 3px solid #eee;
padding-left: 0.75em;
margin-bottom: 15px;
color: #999;
font-size: 0.9em;
}
`)
}
|
[
"function",
"rewriteFonts",
"(",
")",
"{",
"const",
"style",
"=",
"path",
".",
"join",
"(",
"target",
",",
"'css'",
",",
"'style.css'",
")",
"const",
"css",
"=",
"fs",
".",
"readFileSync",
"(",
"style",
")",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"@import url\\(.*?Roboto.*?\\);",
"/",
",",
"`",
"`",
")",
".",
"replace",
"(",
"/",
"Roboto",
"/",
"g",
",",
"'Open Sans'",
")",
"fs",
".",
"writeFileSync",
"(",
"style",
",",
"`",
"${",
"css",
"}",
"`",
")",
"}"
] |
Rewrites the fonts in the output CSS to replace them with our own.
Do this instead of overriding for load times and reduction in hackery.
|
[
"Rewrites",
"the",
"fonts",
"in",
"the",
"output",
"CSS",
"to",
"replace",
"them",
"with",
"our",
"own",
".",
"Do",
"this",
"instead",
"of",
"overriding",
"for",
"load",
"times",
"and",
"reduction",
"in",
"hackery",
"."
] |
54c6ddf19da033334c526da9416bbc7a0cd71859
|
https://github.com/node-influx/node-influx/blob/54c6ddf19da033334c526da9416bbc7a0cd71859/examples/esdoc-plugin.js#L10-L48
|
9,176
|
apocas/dockerode
|
examples/exec_running_container.js
|
runExec
|
function runExec(container) {
var options = {
Cmd: ['bash', '-c', 'echo test $VAR'],
Env: ['VAR=ttslkfjsdalkfj'],
AttachStdout: true,
AttachStderr: true
};
container.exec(options, function(err, exec) {
if (err) return;
exec.start(function(err, stream) {
if (err) return;
container.modem.demuxStream(stream, process.stdout, process.stderr);
exec.inspect(function(err, data) {
if (err) return;
console.log(data);
});
});
});
}
|
javascript
|
function runExec(container) {
var options = {
Cmd: ['bash', '-c', 'echo test $VAR'],
Env: ['VAR=ttslkfjsdalkfj'],
AttachStdout: true,
AttachStderr: true
};
container.exec(options, function(err, exec) {
if (err) return;
exec.start(function(err, stream) {
if (err) return;
container.modem.demuxStream(stream, process.stdout, process.stderr);
exec.inspect(function(err, data) {
if (err) return;
console.log(data);
});
});
});
}
|
[
"function",
"runExec",
"(",
"container",
")",
"{",
"var",
"options",
"=",
"{",
"Cmd",
":",
"[",
"'bash'",
",",
"'-c'",
",",
"'echo test $VAR'",
"]",
",",
"Env",
":",
"[",
"'VAR=ttslkfjsdalkfj'",
"]",
",",
"AttachStdout",
":",
"true",
",",
"AttachStderr",
":",
"true",
"}",
";",
"container",
".",
"exec",
"(",
"options",
",",
"function",
"(",
"err",
",",
"exec",
")",
"{",
"if",
"(",
"err",
")",
"return",
";",
"exec",
".",
"start",
"(",
"function",
"(",
"err",
",",
"stream",
")",
"{",
"if",
"(",
"err",
")",
"return",
";",
"container",
".",
"modem",
".",
"demuxStream",
"(",
"stream",
",",
"process",
".",
"stdout",
",",
"process",
".",
"stderr",
")",
";",
"exec",
".",
"inspect",
"(",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"return",
";",
"console",
".",
"log",
"(",
"data",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Get env list from running container
@param container
|
[
"Get",
"env",
"list",
"from",
"running",
"container"
] |
5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1
|
https://github.com/apocas/dockerode/blob/5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1/examples/exec_running_container.js#L11-L33
|
9,177
|
apocas/dockerode
|
lib/plugin.js
|
function(modem, name, remote) {
this.modem = modem;
this.name = name;
this.remote = remote || name;
}
|
javascript
|
function(modem, name, remote) {
this.modem = modem;
this.name = name;
this.remote = remote || name;
}
|
[
"function",
"(",
"modem",
",",
"name",
",",
"remote",
")",
"{",
"this",
".",
"modem",
"=",
"modem",
";",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"remote",
"=",
"remote",
"||",
"name",
";",
"}"
] |
Represents a plugin
@param {Object} modem docker-modem
@param {String} name Plugin's name
|
[
"Represents",
"a",
"plugin"
] |
5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1
|
https://github.com/apocas/dockerode/blob/5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1/lib/plugin.js#L8-L12
|
|
9,178
|
apocas/dockerode
|
examples/logs.js
|
containerLogs
|
function containerLogs(container) {
// create a single stream for stdin and stdout
var logStream = new stream.PassThrough();
logStream.on('data', function(chunk){
console.log(chunk.toString('utf8'));
});
container.logs({
follow: true,
stdout: true,
stderr: true
}, function(err, stream){
if(err) {
return logger.error(err.message);
}
container.modem.demuxStream(stream, logStream, logStream);
stream.on('end', function(){
logStream.end('!stop!');
});
setTimeout(function() {
stream.destroy();
}, 2000);
});
}
|
javascript
|
function containerLogs(container) {
// create a single stream for stdin and stdout
var logStream = new stream.PassThrough();
logStream.on('data', function(chunk){
console.log(chunk.toString('utf8'));
});
container.logs({
follow: true,
stdout: true,
stderr: true
}, function(err, stream){
if(err) {
return logger.error(err.message);
}
container.modem.demuxStream(stream, logStream, logStream);
stream.on('end', function(){
logStream.end('!stop!');
});
setTimeout(function() {
stream.destroy();
}, 2000);
});
}
|
[
"function",
"containerLogs",
"(",
"container",
")",
"{",
"// create a single stream for stdin and stdout",
"var",
"logStream",
"=",
"new",
"stream",
".",
"PassThrough",
"(",
")",
";",
"logStream",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"console",
".",
"log",
"(",
"chunk",
".",
"toString",
"(",
"'utf8'",
")",
")",
";",
"}",
")",
";",
"container",
".",
"logs",
"(",
"{",
"follow",
":",
"true",
",",
"stdout",
":",
"true",
",",
"stderr",
":",
"true",
"}",
",",
"function",
"(",
"err",
",",
"stream",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"logger",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"}",
"container",
".",
"modem",
".",
"demuxStream",
"(",
"stream",
",",
"logStream",
",",
"logStream",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"logStream",
".",
"end",
"(",
"'!stop!'",
")",
";",
"}",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"stream",
".",
"destroy",
"(",
")",
";",
"}",
",",
"2000",
")",
";",
"}",
")",
";",
"}"
] |
Get logs from running container
|
[
"Get",
"logs",
"from",
"running",
"container"
] |
5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1
|
https://github.com/apocas/dockerode/blob/5ac15d82be325173c6f42c3e7b1d13a61a6d4bf1/examples/logs.js#L11-L36
|
9,179
|
felixrieseberg/npm-windows-upgrade
|
src/find-npm.js
|
_getPathFromPowerShell
|
function _getPathFromPowerShell () {
return new Promise(resolve => {
const psArgs = 'Get-Command npm | Select-Object -ExpandProperty Definition'
const args = [ '-NoProfile', '-NoLogo', psArgs ]
const child = spawn('powershell.exe', args)
let stdout = []
let stderr = []
child.stdout.on('data', (data) => {
debug(`PowerShell: Stdout received: ${data.toString()}`)
stdout.push(data.toString())
})
child.stderr.on('data', (data) => {
debug(`PowerShell: Stderr received: ${data.toString()}`)
stderr.push(data.toString())
})
child.on('exit', () => {
const cmdPath = (stdout[0] && stdout[0].trim) ? stdout[0].trim() : null
if (stderr.length === 0 && cmdPath && cmdPath.slice(cmdPath.length - 7) === 'npm.cmd') {
// We're probably installed in a location like C:\Program Files\nodejs\npm.cmd,
// meaning that we should not use the global prefix installation location
const npmPath = cmdPath.slice(0, cmdPath.length - 8)
debug(`PowerShell: _getPathFromPowerShell() resolving with: ${npmPath}`)
resolve(npmPath)
} else {
resolve(null)
}
})
child.stdin.end()
})
}
|
javascript
|
function _getPathFromPowerShell () {
return new Promise(resolve => {
const psArgs = 'Get-Command npm | Select-Object -ExpandProperty Definition'
const args = [ '-NoProfile', '-NoLogo', psArgs ]
const child = spawn('powershell.exe', args)
let stdout = []
let stderr = []
child.stdout.on('data', (data) => {
debug(`PowerShell: Stdout received: ${data.toString()}`)
stdout.push(data.toString())
})
child.stderr.on('data', (data) => {
debug(`PowerShell: Stderr received: ${data.toString()}`)
stderr.push(data.toString())
})
child.on('exit', () => {
const cmdPath = (stdout[0] && stdout[0].trim) ? stdout[0].trim() : null
if (stderr.length === 0 && cmdPath && cmdPath.slice(cmdPath.length - 7) === 'npm.cmd') {
// We're probably installed in a location like C:\Program Files\nodejs\npm.cmd,
// meaning that we should not use the global prefix installation location
const npmPath = cmdPath.slice(0, cmdPath.length - 8)
debug(`PowerShell: _getPathFromPowerShell() resolving with: ${npmPath}`)
resolve(npmPath)
} else {
resolve(null)
}
})
child.stdin.end()
})
}
|
[
"function",
"_getPathFromPowerShell",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"resolve",
"=>",
"{",
"const",
"psArgs",
"=",
"'Get-Command npm | Select-Object -ExpandProperty Definition'",
"const",
"args",
"=",
"[",
"'-NoProfile'",
",",
"'-NoLogo'",
",",
"psArgs",
"]",
"const",
"child",
"=",
"spawn",
"(",
"'powershell.exe'",
",",
"args",
")",
"let",
"stdout",
"=",
"[",
"]",
"let",
"stderr",
"=",
"[",
"]",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"`",
"${",
"data",
".",
"toString",
"(",
")",
"}",
"`",
")",
"stdout",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"`",
"${",
"data",
".",
"toString",
"(",
")",
"}",
"`",
")",
"stderr",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"{",
"const",
"cmdPath",
"=",
"(",
"stdout",
"[",
"0",
"]",
"&&",
"stdout",
"[",
"0",
"]",
".",
"trim",
")",
"?",
"stdout",
"[",
"0",
"]",
".",
"trim",
"(",
")",
":",
"null",
"if",
"(",
"stderr",
".",
"length",
"===",
"0",
"&&",
"cmdPath",
"&&",
"cmdPath",
".",
"slice",
"(",
"cmdPath",
".",
"length",
"-",
"7",
")",
"===",
"'npm.cmd'",
")",
"{",
"// We're probably installed in a location like C:\\Program Files\\nodejs\\npm.cmd,",
"// meaning that we should not use the global prefix installation location",
"const",
"npmPath",
"=",
"cmdPath",
".",
"slice",
"(",
"0",
",",
"cmdPath",
".",
"length",
"-",
"8",
")",
"debug",
"(",
"`",
"${",
"npmPath",
"}",
"`",
")",
"resolve",
"(",
"npmPath",
")",
"}",
"else",
"{",
"resolve",
"(",
"null",
")",
"}",
"}",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Attempts to get npm's path by calling out to "Get-Command npm"
@returns {Promise.<string>} - Promise that resolves with the found path (or null if not found)
|
[
"Attempts",
"to",
"get",
"npm",
"s",
"path",
"by",
"calling",
"out",
"to",
"Get",
"-",
"Command",
"npm"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/find-npm.js#L33-L68
|
9,180
|
felixrieseberg/npm-windows-upgrade
|
src/find-npm.js
|
_getPath
|
function _getPath () {
return Promise.all([_getPathFromPowerShell(), _getPathFromNpm()])
.then((results) => {
const fromNpm = results[1] || ''
const fromPowershell = results[0] || ''
// Quickly check if there's an npm folder in there
const fromPowershellPath = path.join(fromPowershell, 'node_modules', 'npm')
const fromNpmPath = path.join(fromNpm, 'node_modules', 'npm')
const isFromPowershell = utils.isPathAccessible(fromPowershellPath)
const isFromNpm = utils.isPathAccessible(fromNpmPath)
// Found in...
// Powershell: -> return powershell path
// npm: -> return npm path
// nowhere: -> return powershell path
if (isFromPowershell) {
return {
path: fromPowershell,
message: strings.npmFoundIn(fromPowershell, fromNpm, fromPowershell)
}
} else if (isFromNpm) {
return {
path: fromNpm,
message: strings.npmFoundIn(fromPowershell, fromNpm, fromNpm)
}
} else {
return {
path: fromPowershell,
message: strings.npmNotFoundGuessing(fromPowershell, fromNpm, fromPowershell)
}
}
})
}
|
javascript
|
function _getPath () {
return Promise.all([_getPathFromPowerShell(), _getPathFromNpm()])
.then((results) => {
const fromNpm = results[1] || ''
const fromPowershell = results[0] || ''
// Quickly check if there's an npm folder in there
const fromPowershellPath = path.join(fromPowershell, 'node_modules', 'npm')
const fromNpmPath = path.join(fromNpm, 'node_modules', 'npm')
const isFromPowershell = utils.isPathAccessible(fromPowershellPath)
const isFromNpm = utils.isPathAccessible(fromNpmPath)
// Found in...
// Powershell: -> return powershell path
// npm: -> return npm path
// nowhere: -> return powershell path
if (isFromPowershell) {
return {
path: fromPowershell,
message: strings.npmFoundIn(fromPowershell, fromNpm, fromPowershell)
}
} else if (isFromNpm) {
return {
path: fromNpm,
message: strings.npmFoundIn(fromPowershell, fromNpm, fromNpm)
}
} else {
return {
path: fromPowershell,
message: strings.npmNotFoundGuessing(fromPowershell, fromNpm, fromPowershell)
}
}
})
}
|
[
"function",
"_getPath",
"(",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"[",
"_getPathFromPowerShell",
"(",
")",
",",
"_getPathFromNpm",
"(",
")",
"]",
")",
".",
"then",
"(",
"(",
"results",
")",
"=>",
"{",
"const",
"fromNpm",
"=",
"results",
"[",
"1",
"]",
"||",
"''",
"const",
"fromPowershell",
"=",
"results",
"[",
"0",
"]",
"||",
"''",
"// Quickly check if there's an npm folder in there",
"const",
"fromPowershellPath",
"=",
"path",
".",
"join",
"(",
"fromPowershell",
",",
"'node_modules'",
",",
"'npm'",
")",
"const",
"fromNpmPath",
"=",
"path",
".",
"join",
"(",
"fromNpm",
",",
"'node_modules'",
",",
"'npm'",
")",
"const",
"isFromPowershell",
"=",
"utils",
".",
"isPathAccessible",
"(",
"fromPowershellPath",
")",
"const",
"isFromNpm",
"=",
"utils",
".",
"isPathAccessible",
"(",
"fromNpmPath",
")",
"// Found in...",
"// Powershell: -> return powershell path",
"// npm: -> return npm path",
"// nowhere: -> return powershell path",
"if",
"(",
"isFromPowershell",
")",
"{",
"return",
"{",
"path",
":",
"fromPowershell",
",",
"message",
":",
"strings",
".",
"npmFoundIn",
"(",
"fromPowershell",
",",
"fromNpm",
",",
"fromPowershell",
")",
"}",
"}",
"else",
"if",
"(",
"isFromNpm",
")",
"{",
"return",
"{",
"path",
":",
"fromNpm",
",",
"message",
":",
"strings",
".",
"npmFoundIn",
"(",
"fromPowershell",
",",
"fromNpm",
",",
"fromNpm",
")",
"}",
"}",
"else",
"{",
"return",
"{",
"path",
":",
"fromPowershell",
",",
"message",
":",
"strings",
".",
"npmNotFoundGuessing",
"(",
"fromPowershell",
",",
"fromNpm",
",",
"fromPowershell",
")",
"}",
"}",
"}",
")",
"}"
] |
Attempts to get the current installation location of npm by looking up the global prefix.
Prefer PowerShell, be falls back to npm's opinion
@return {Promise.<string>} - NodeJS installation path
|
[
"Attempts",
"to",
"get",
"the",
"current",
"installation",
"location",
"of",
"npm",
"by",
"looking",
"up",
"the",
"global",
"prefix",
".",
"Prefer",
"PowerShell",
"be",
"falls",
"back",
"to",
"npm",
"s",
"opinion"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/find-npm.js#L76-L109
|
9,181
|
felixrieseberg/npm-windows-upgrade
|
src/powershell.js
|
runUpgrade
|
function runUpgrade (version, npmPath) {
return new Promise((resolve, reject) => {
const scriptPath = path.resolve(__dirname, '../powershell/upgrade-npm.ps1')
const psArgs = npmPath === null
? `& {& '${scriptPath}' -version '${version}' }`
: `& {& '${scriptPath}' -version '${version}' -NodePath '${npmPath}' }`
const args = [ '-ExecutionPolicy', 'Bypass', '-NoProfile', '-NoLogo', psArgs ]
if (process.env.DEBUG) {
args.push('-debug')
}
let stdout = []
let stderr = []
let child
try {
child = spawn('powershell.exe', args)
} catch (error) {
return reject(error)
}
child.stdout.on('data', (data) => {
debug('PowerShell: Stdout received: ' + data.toString())
stdout.push(data.toString())
})
child.stderr.on('data', (data) => {
debug('PowerShell: Stderr received: ' + data.toString())
stderr.push(data.toString())
})
child.on('exit', () => resolve({ stderr, stdout }))
child.stdin.end()
})
}
|
javascript
|
function runUpgrade (version, npmPath) {
return new Promise((resolve, reject) => {
const scriptPath = path.resolve(__dirname, '../powershell/upgrade-npm.ps1')
const psArgs = npmPath === null
? `& {& '${scriptPath}' -version '${version}' }`
: `& {& '${scriptPath}' -version '${version}' -NodePath '${npmPath}' }`
const args = [ '-ExecutionPolicy', 'Bypass', '-NoProfile', '-NoLogo', psArgs ]
if (process.env.DEBUG) {
args.push('-debug')
}
let stdout = []
let stderr = []
let child
try {
child = spawn('powershell.exe', args)
} catch (error) {
return reject(error)
}
child.stdout.on('data', (data) => {
debug('PowerShell: Stdout received: ' + data.toString())
stdout.push(data.toString())
})
child.stderr.on('data', (data) => {
debug('PowerShell: Stderr received: ' + data.toString())
stderr.push(data.toString())
})
child.on('exit', () => resolve({ stderr, stdout }))
child.stdin.end()
})
}
|
[
"function",
"runUpgrade",
"(",
"version",
",",
"npmPath",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"scriptPath",
"=",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'../powershell/upgrade-npm.ps1'",
")",
"const",
"psArgs",
"=",
"npmPath",
"===",
"null",
"?",
"`",
"${",
"scriptPath",
"}",
"${",
"version",
"}",
"`",
":",
"`",
"${",
"scriptPath",
"}",
"${",
"version",
"}",
"${",
"npmPath",
"}",
"`",
"const",
"args",
"=",
"[",
"'-ExecutionPolicy'",
",",
"'Bypass'",
",",
"'-NoProfile'",
",",
"'-NoLogo'",
",",
"psArgs",
"]",
"if",
"(",
"process",
".",
"env",
".",
"DEBUG",
")",
"{",
"args",
".",
"push",
"(",
"'-debug'",
")",
"}",
"let",
"stdout",
"=",
"[",
"]",
"let",
"stderr",
"=",
"[",
"]",
"let",
"child",
"try",
"{",
"child",
"=",
"spawn",
"(",
"'powershell.exe'",
",",
"args",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"return",
"reject",
"(",
"error",
")",
"}",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"'PowerShell: Stdout received: '",
"+",
"data",
".",
"toString",
"(",
")",
")",
"stdout",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"'PowerShell: Stderr received: '",
"+",
"data",
".",
"toString",
"(",
")",
")",
"stderr",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"resolve",
"(",
"{",
"stderr",
",",
"stdout",
"}",
")",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Executes the PS1 script upgrading npm
@param {string} version - The version to be installed (npm install npm@{version})
@param {string} npmPath - Path to Node installation (optional)
@return {Promise.<stderr[], stdout[]>} - stderr and stdout received from the PS1 process
|
[
"Executes",
"the",
"PS1",
"script",
"upgrading",
"npm"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/powershell.js#L12-L47
|
9,182
|
felixrieseberg/npm-windows-upgrade
|
src/powershell.js
|
runSimpleUpgrade
|
function runSimpleUpgrade (version) {
return new Promise((resolve) => {
let npmCommand = (version) ? `npm install -g npm@${version}` : 'npm install -g npm'
let stdout = []
let stderr = []
let child
try {
child = spawn('powershell.exe', [ '-NoProfile', '-NoLogo', npmCommand ])
} catch (error) {
// This is dirty, but the best way for us to try/catch right now
resolve({ error })
}
child.stdout.on('data', (data) => stdout.push(data.toString()))
child.stderr.on('data', (data) => stderr.push(data.toString()))
child.on('exit', () => resolve({ stderr, stdout }))
child.stdin.end()
})
}
|
javascript
|
function runSimpleUpgrade (version) {
return new Promise((resolve) => {
let npmCommand = (version) ? `npm install -g npm@${version}` : 'npm install -g npm'
let stdout = []
let stderr = []
let child
try {
child = spawn('powershell.exe', [ '-NoProfile', '-NoLogo', npmCommand ])
} catch (error) {
// This is dirty, but the best way for us to try/catch right now
resolve({ error })
}
child.stdout.on('data', (data) => stdout.push(data.toString()))
child.stderr.on('data', (data) => stderr.push(data.toString()))
child.on('exit', () => resolve({ stderr, stdout }))
child.stdin.end()
})
}
|
[
"function",
"runSimpleUpgrade",
"(",
"version",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
")",
"=>",
"{",
"let",
"npmCommand",
"=",
"(",
"version",
")",
"?",
"`",
"${",
"version",
"}",
"`",
":",
"'npm install -g npm'",
"let",
"stdout",
"=",
"[",
"]",
"let",
"stderr",
"=",
"[",
"]",
"let",
"child",
"try",
"{",
"child",
"=",
"spawn",
"(",
"'powershell.exe'",
",",
"[",
"'-NoProfile'",
",",
"'-NoLogo'",
",",
"npmCommand",
"]",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"// This is dirty, but the best way for us to try/catch right now",
"resolve",
"(",
"{",
"error",
"}",
")",
"}",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"stdout",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"stderr",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"resolve",
"(",
"{",
"stderr",
",",
"stdout",
"}",
")",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Executes 'npm install -g npm' upgrading npm
@param {string} version - The version to be installed (npm install npm@{version})
@return {Promise.<stderr[], stdout[]>} - stderr and stdout received from the PS1 process
|
[
"Executes",
"npm",
"install",
"-",
"g",
"npm",
"upgrading",
"npm"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/powershell.js#L54-L75
|
9,183
|
felixrieseberg/npm-windows-upgrade
|
src/utils.js
|
exit
|
function exit (status, ...messages) {
if (messages) {
messages.forEach(message => console.log(message))
}
process.exit(status)
}
|
javascript
|
function exit (status, ...messages) {
if (messages) {
messages.forEach(message => console.log(message))
}
process.exit(status)
}
|
[
"function",
"exit",
"(",
"status",
",",
"...",
"messages",
")",
"{",
"if",
"(",
"messages",
")",
"{",
"messages",
".",
"forEach",
"(",
"message",
"=>",
"console",
".",
"log",
"(",
"message",
")",
")",
"}",
"process",
".",
"exit",
"(",
"status",
")",
"}"
] |
Exits the process with a given status,
logging a given message before exiting.
@param {number} status - exit status
@param {string} messages - message to log
|
[
"Exits",
"the",
"process",
"with",
"a",
"given",
"status",
"logging",
"a",
"given",
"message",
"before",
"exiting",
"."
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/utils.js#L14-L20
|
9,184
|
felixrieseberg/npm-windows-upgrade
|
src/utils.js
|
checkExecutionPolicy
|
function checkExecutionPolicy () {
return new Promise((resolve, reject) => {
let output = []
let child
try {
debug('Powershell: Attempting to spawn PowerShell child')
child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', 'Get-ExecutionPolicy'])
} catch (error) {
debug('Powershell: Could not spawn PowerShell child')
reject(error)
}
child.stdout.on('data', (data) => {
debug('PowerShell: Stdout received: ' + data.toString())
output.push(data.toString())
})
child.stderr.on('data', (data) => {
debug('PowerShell: Stderr received: ' + data.toString())
output.push(data.toString())
})
child.on('exit', () => {
const linesHit = output.filter((line) => line.includes('Unrestricted') || line.includes('RemoteSigned') || line.includes('Bypass'))
const unrestricted = (linesHit.length > 0)
if (!unrestricted) {
debug('PowerShell: Resolving restricted (false)')
resolve(false)
} else {
debug('PowerShell: Resolving unrestricted (true)')
resolve(true)
}
})
child.stdin.end()
})
}
|
javascript
|
function checkExecutionPolicy () {
return new Promise((resolve, reject) => {
let output = []
let child
try {
debug('Powershell: Attempting to spawn PowerShell child')
child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', 'Get-ExecutionPolicy'])
} catch (error) {
debug('Powershell: Could not spawn PowerShell child')
reject(error)
}
child.stdout.on('data', (data) => {
debug('PowerShell: Stdout received: ' + data.toString())
output.push(data.toString())
})
child.stderr.on('data', (data) => {
debug('PowerShell: Stderr received: ' + data.toString())
output.push(data.toString())
})
child.on('exit', () => {
const linesHit = output.filter((line) => line.includes('Unrestricted') || line.includes('RemoteSigned') || line.includes('Bypass'))
const unrestricted = (linesHit.length > 0)
if (!unrestricted) {
debug('PowerShell: Resolving restricted (false)')
resolve(false)
} else {
debug('PowerShell: Resolving unrestricted (true)')
resolve(true)
}
})
child.stdin.end()
})
}
|
[
"function",
"checkExecutionPolicy",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"output",
"=",
"[",
"]",
"let",
"child",
"try",
"{",
"debug",
"(",
"'Powershell: Attempting to spawn PowerShell child'",
")",
"child",
"=",
"spawn",
"(",
"'powershell.exe'",
",",
"[",
"'-NoProfile'",
",",
"'-NoLogo'",
",",
"'Get-ExecutionPolicy'",
"]",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"debug",
"(",
"'Powershell: Could not spawn PowerShell child'",
")",
"reject",
"(",
"error",
")",
"}",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"'PowerShell: Stdout received: '",
"+",
"data",
".",
"toString",
"(",
")",
")",
"output",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"{",
"debug",
"(",
"'PowerShell: Stderr received: '",
"+",
"data",
".",
"toString",
"(",
")",
")",
"output",
".",
"push",
"(",
"data",
".",
"toString",
"(",
")",
")",
"}",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"{",
"const",
"linesHit",
"=",
"output",
".",
"filter",
"(",
"(",
"line",
")",
"=>",
"line",
".",
"includes",
"(",
"'Unrestricted'",
")",
"||",
"line",
".",
"includes",
"(",
"'RemoteSigned'",
")",
"||",
"line",
".",
"includes",
"(",
"'Bypass'",
")",
")",
"const",
"unrestricted",
"=",
"(",
"linesHit",
".",
"length",
">",
"0",
")",
"if",
"(",
"!",
"unrestricted",
")",
"{",
"debug",
"(",
"'PowerShell: Resolving restricted (false)'",
")",
"resolve",
"(",
"false",
")",
"}",
"else",
"{",
"debug",
"(",
"'PowerShell: Resolving unrestricted (true)'",
")",
"resolve",
"(",
"true",
")",
"}",
"}",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Checks the current Windows PS1 execution policy. The upgrader requires an unrestricted policy.
@return {Promise.<boolean>} - True if unrestricted, false if it isn't
|
[
"Checks",
"the",
"current",
"Windows",
"PS1",
"execution",
"policy",
".",
"The",
"upgrader",
"requires",
"an",
"unrestricted",
"policy",
"."
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/utils.js#L44-L82
|
9,185
|
felixrieseberg/npm-windows-upgrade
|
src/utils.js
|
isPathAccessible
|
function isPathAccessible (filePath) {
try {
fs.accessSync(filePath)
debug(`Utils: isPathAccessible(): ${filePath} exists`)
return true
} catch (err) {
debug(`Utils: isPathAccessible(): ${filePath} does not exist`)
return false
}
}
|
javascript
|
function isPathAccessible (filePath) {
try {
fs.accessSync(filePath)
debug(`Utils: isPathAccessible(): ${filePath} exists`)
return true
} catch (err) {
debug(`Utils: isPathAccessible(): ${filePath} does not exist`)
return false
}
}
|
[
"function",
"isPathAccessible",
"(",
"filePath",
")",
"{",
"try",
"{",
"fs",
".",
"accessSync",
"(",
"filePath",
")",
"debug",
"(",
"`",
"${",
"filePath",
"}",
"`",
")",
"return",
"true",
"}",
"catch",
"(",
"err",
")",
"{",
"debug",
"(",
"`",
"${",
"filePath",
"}",
"`",
")",
"return",
"false",
"}",
"}"
] |
Checks if a path exists
@param filePath - file path to check
@returns {boolean} - does the file path exist?
|
[
"Checks",
"if",
"a",
"path",
"exists"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/utils.js#L90-L99
|
9,186
|
felixrieseberg/npm-windows-upgrade
|
src/versions.js
|
getAvailableNPMVersions
|
function getAvailableNPMVersions () {
return new Promise((resolve, reject) => {
exec('npm view npm versions --json', (err, stdout) => {
if (err) {
let error = 'We could not show latest available versions. Try running this script again '
error += 'with the version you want to install (npm-windows-upgrade --npm-version 3.0.0)'
return reject(error)
}
resolve(JSON.parse(stdout))
})
})
}
|
javascript
|
function getAvailableNPMVersions () {
return new Promise((resolve, reject) => {
exec('npm view npm versions --json', (err, stdout) => {
if (err) {
let error = 'We could not show latest available versions. Try running this script again '
error += 'with the version you want to install (npm-windows-upgrade --npm-version 3.0.0)'
return reject(error)
}
resolve(JSON.parse(stdout))
})
})
}
|
[
"function",
"getAvailableNPMVersions",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"exec",
"(",
"'npm view npm versions --json'",
",",
"(",
"err",
",",
"stdout",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"let",
"error",
"=",
"'We could not show latest available versions. Try running this script again '",
"error",
"+=",
"'with the version you want to install (npm-windows-upgrade --npm-version 3.0.0)'",
"return",
"reject",
"(",
"error",
")",
"}",
"resolve",
"(",
"JSON",
".",
"parse",
"(",
"stdout",
")",
")",
"}",
")",
"}",
")",
"}"
] |
Fetches the published versions of npm from the npm registry
@return {Promise.<versions[]>} - Array of the available versions
|
[
"Fetches",
"the",
"published",
"versions",
"of",
"npm",
"from",
"the",
"npm",
"registry"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/versions.js#L27-L39
|
9,187
|
felixrieseberg/npm-windows-upgrade
|
src/versions.js
|
_getWindowsVersion
|
function _getWindowsVersion () {
return new Promise((resolve, reject) => {
const command = 'systeminfo | findstr /B /C:"OS Name" /C:"OS Version"'
exec(command, (error, stdout) => {
if (error) {
reject(error)
} else {
resolve(stdout)
}
})
})
}
|
javascript
|
function _getWindowsVersion () {
return new Promise((resolve, reject) => {
const command = 'systeminfo | findstr /B /C:"OS Name" /C:"OS Version"'
exec(command, (error, stdout) => {
if (error) {
reject(error)
} else {
resolve(stdout)
}
})
})
}
|
[
"function",
"_getWindowsVersion",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"command",
"=",
"'systeminfo | findstr /B /C:\"OS Name\" /C:\"OS Version\"'",
"exec",
"(",
"command",
",",
"(",
"error",
",",
"stdout",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
"}",
"else",
"{",
"resolve",
"(",
"stdout",
")",
"}",
"}",
")",
"}",
")",
"}"
] |
Get the current name and version of Windows
|
[
"Get",
"the",
"current",
"name",
"and",
"version",
"of",
"Windows"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/versions.js#L64-L75
|
9,188
|
felixrieseberg/npm-windows-upgrade
|
src/versions.js
|
getVersions
|
async function getVersions () {
let versions = process.versions
let prettyVersions = []
versions.os = process.platform + ' ' + process.arch
for (let variable in versions) {
if (versions.hasOwnProperty(variable)) {
prettyVersions.push(`${variable}: ${versions[variable]}`)
}
}
try {
const windowsVersion = await _getWindowsVersion()
prettyVersions.push(windowsVersion.replace(/ +/g, ' '))
} catch (error) {
// Do nothing, we're okay with this failing.
// Most common reason is we're not on an english
// Windows.
}
return prettyVersions.join(' | ')
}
|
javascript
|
async function getVersions () {
let versions = process.versions
let prettyVersions = []
versions.os = process.platform + ' ' + process.arch
for (let variable in versions) {
if (versions.hasOwnProperty(variable)) {
prettyVersions.push(`${variable}: ${versions[variable]}`)
}
}
try {
const windowsVersion = await _getWindowsVersion()
prettyVersions.push(windowsVersion.replace(/ +/g, ' '))
} catch (error) {
// Do nothing, we're okay with this failing.
// Most common reason is we're not on an english
// Windows.
}
return prettyVersions.join(' | ')
}
|
[
"async",
"function",
"getVersions",
"(",
")",
"{",
"let",
"versions",
"=",
"process",
".",
"versions",
"let",
"prettyVersions",
"=",
"[",
"]",
"versions",
".",
"os",
"=",
"process",
".",
"platform",
"+",
"' '",
"+",
"process",
".",
"arch",
"for",
"(",
"let",
"variable",
"in",
"versions",
")",
"{",
"if",
"(",
"versions",
".",
"hasOwnProperty",
"(",
"variable",
")",
")",
"{",
"prettyVersions",
".",
"push",
"(",
"`",
"${",
"variable",
"}",
"${",
"versions",
"[",
"variable",
"]",
"}",
"`",
")",
"}",
"}",
"try",
"{",
"const",
"windowsVersion",
"=",
"await",
"_getWindowsVersion",
"(",
")",
"prettyVersions",
".",
"push",
"(",
"windowsVersion",
".",
"replace",
"(",
"/",
" +",
"/",
"g",
",",
"' '",
")",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"// Do nothing, we're okay with this failing.",
"// Most common reason is we're not on an english",
"// Windows.",
"}",
"return",
"prettyVersions",
".",
"join",
"(",
"' | '",
")",
"}"
] |
Get installed versions of virtually everything important
|
[
"Get",
"installed",
"versions",
"of",
"virtually",
"everything",
"important"
] |
763c2ff750f65dfbef5dbc48b131a6af897f1a35
|
https://github.com/felixrieseberg/npm-windows-upgrade/blob/763c2ff750f65dfbef5dbc48b131a6af897f1a35/src/versions.js#L80-L101
|
9,189
|
wix/angular-tree-control
|
demo/ui-bootstrap-tpls.0.11.2.js
|
function (hostEl, targetEl, positionStr, appendToBody) {
var positionStrParts = positionStr.split('-');
var pos0 = positionStrParts[0], pos1 = positionStrParts[1] || 'center';
var hostElPos,
targetElWidth,
targetElHeight,
targetElPos;
hostElPos = appendToBody ? this.offset(hostEl) : this.position(hostEl);
targetElWidth = targetEl.prop('offsetWidth');
targetElHeight = targetEl.prop('offsetHeight');
var shiftWidth = {
center: function () {
return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2;
},
left: function () {
return hostElPos.left;
},
right: function () {
return hostElPos.left + hostElPos.width;
}
};
var shiftHeight = {
center: function () {
return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2;
},
top: function () {
return hostElPos.top;
},
bottom: function () {
return hostElPos.top + hostElPos.height;
}
};
switch (pos0) {
case 'right':
targetElPos = {
top: shiftHeight[pos1](),
left: shiftWidth[pos0]()
};
break;
case 'left':
targetElPos = {
top: shiftHeight[pos1](),
left: hostElPos.left - targetElWidth
};
break;
case 'bottom':
targetElPos = {
top: shiftHeight[pos0](),
left: shiftWidth[pos1]()
};
break;
default:
targetElPos = {
top: hostElPos.top - targetElHeight,
left: shiftWidth[pos1]()
};
break;
}
return targetElPos;
}
|
javascript
|
function (hostEl, targetEl, positionStr, appendToBody) {
var positionStrParts = positionStr.split('-');
var pos0 = positionStrParts[0], pos1 = positionStrParts[1] || 'center';
var hostElPos,
targetElWidth,
targetElHeight,
targetElPos;
hostElPos = appendToBody ? this.offset(hostEl) : this.position(hostEl);
targetElWidth = targetEl.prop('offsetWidth');
targetElHeight = targetEl.prop('offsetHeight');
var shiftWidth = {
center: function () {
return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2;
},
left: function () {
return hostElPos.left;
},
right: function () {
return hostElPos.left + hostElPos.width;
}
};
var shiftHeight = {
center: function () {
return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2;
},
top: function () {
return hostElPos.top;
},
bottom: function () {
return hostElPos.top + hostElPos.height;
}
};
switch (pos0) {
case 'right':
targetElPos = {
top: shiftHeight[pos1](),
left: shiftWidth[pos0]()
};
break;
case 'left':
targetElPos = {
top: shiftHeight[pos1](),
left: hostElPos.left - targetElWidth
};
break;
case 'bottom':
targetElPos = {
top: shiftHeight[pos0](),
left: shiftWidth[pos1]()
};
break;
default:
targetElPos = {
top: hostElPos.top - targetElHeight,
left: shiftWidth[pos1]()
};
break;
}
return targetElPos;
}
|
[
"function",
"(",
"hostEl",
",",
"targetEl",
",",
"positionStr",
",",
"appendToBody",
")",
"{",
"var",
"positionStrParts",
"=",
"positionStr",
".",
"split",
"(",
"'-'",
")",
";",
"var",
"pos0",
"=",
"positionStrParts",
"[",
"0",
"]",
",",
"pos1",
"=",
"positionStrParts",
"[",
"1",
"]",
"||",
"'center'",
";",
"var",
"hostElPos",
",",
"targetElWidth",
",",
"targetElHeight",
",",
"targetElPos",
";",
"hostElPos",
"=",
"appendToBody",
"?",
"this",
".",
"offset",
"(",
"hostEl",
")",
":",
"this",
".",
"position",
"(",
"hostEl",
")",
";",
"targetElWidth",
"=",
"targetEl",
".",
"prop",
"(",
"'offsetWidth'",
")",
";",
"targetElHeight",
"=",
"targetEl",
".",
"prop",
"(",
"'offsetHeight'",
")",
";",
"var",
"shiftWidth",
"=",
"{",
"center",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"left",
"+",
"hostElPos",
".",
"width",
"/",
"2",
"-",
"targetElWidth",
"/",
"2",
";",
"}",
",",
"left",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"left",
";",
"}",
",",
"right",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"left",
"+",
"hostElPos",
".",
"width",
";",
"}",
"}",
";",
"var",
"shiftHeight",
"=",
"{",
"center",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"top",
"+",
"hostElPos",
".",
"height",
"/",
"2",
"-",
"targetElHeight",
"/",
"2",
";",
"}",
",",
"top",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"top",
";",
"}",
",",
"bottom",
":",
"function",
"(",
")",
"{",
"return",
"hostElPos",
".",
"top",
"+",
"hostElPos",
".",
"height",
";",
"}",
"}",
";",
"switch",
"(",
"pos0",
")",
"{",
"case",
"'right'",
":",
"targetElPos",
"=",
"{",
"top",
":",
"shiftHeight",
"[",
"pos1",
"]",
"(",
")",
",",
"left",
":",
"shiftWidth",
"[",
"pos0",
"]",
"(",
")",
"}",
";",
"break",
";",
"case",
"'left'",
":",
"targetElPos",
"=",
"{",
"top",
":",
"shiftHeight",
"[",
"pos1",
"]",
"(",
")",
",",
"left",
":",
"hostElPos",
".",
"left",
"-",
"targetElWidth",
"}",
";",
"break",
";",
"case",
"'bottom'",
":",
"targetElPos",
"=",
"{",
"top",
":",
"shiftHeight",
"[",
"pos0",
"]",
"(",
")",
",",
"left",
":",
"shiftWidth",
"[",
"pos1",
"]",
"(",
")",
"}",
";",
"break",
";",
"default",
":",
"targetElPos",
"=",
"{",
"top",
":",
"hostElPos",
".",
"top",
"-",
"targetElHeight",
",",
"left",
":",
"shiftWidth",
"[",
"pos1",
"]",
"(",
")",
"}",
";",
"break",
";",
"}",
"return",
"targetElPos",
";",
"}"
] |
Provides coordinates for the targetEl in relation to hostEl
|
[
"Provides",
"coordinates",
"for",
"the",
"targetEl",
"in",
"relation",
"to",
"hostEl"
] |
5bcedace8bcf135ec47d06a6549c802185318196
|
https://github.com/wix/angular-tree-control/blob/5bcedace8bcf135ec47d06a6549c802185318196/demo/ui-bootstrap-tpls.0.11.2.js#L908-L975
|
|
9,190
|
wix/angular-tree-control
|
demo/ui-bootstrap-tpls.0.11.2.js
|
snake_case
|
function snake_case(name){
var regexp = /[A-Z]/g;
var separator = '-';
return name.replace(regexp, function(letter, pos) {
return (pos ? separator : '') + letter.toLowerCase();
});
}
|
javascript
|
function snake_case(name){
var regexp = /[A-Z]/g;
var separator = '-';
return name.replace(regexp, function(letter, pos) {
return (pos ? separator : '') + letter.toLowerCase();
});
}
|
[
"function",
"snake_case",
"(",
"name",
")",
"{",
"var",
"regexp",
"=",
"/",
"[A-Z]",
"/",
"g",
";",
"var",
"separator",
"=",
"'-'",
";",
"return",
"name",
".",
"replace",
"(",
"regexp",
",",
"function",
"(",
"letter",
",",
"pos",
")",
"{",
"return",
"(",
"pos",
"?",
"separator",
":",
"''",
")",
"+",
"letter",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
";",
"}"
] |
This is a helper function for translating camel-case to snake-case.
|
[
"This",
"is",
"a",
"helper",
"function",
"for",
"translating",
"camel",
"-",
"case",
"to",
"snake",
"-",
"case",
"."
] |
5bcedace8bcf135ec47d06a6549c802185318196
|
https://github.com/wix/angular-tree-control/blob/5bcedace8bcf135ec47d06a6549c802185318196/demo/ui-bootstrap-tpls.0.11.2.js#L2464-L2470
|
9,191
|
csstree/csstree
|
lib/tokenizer/Tokenizer.js
|
computeLinesAndColumns
|
function computeLinesAndColumns(tokenizer, source) {
var sourceLength = source.length;
var start = firstCharOffset(source);
var lines = tokenizer.lines;
var line = tokenizer.startLine;
var columns = tokenizer.columns;
var column = tokenizer.startColumn;
if (lines === null || lines.length < sourceLength + 1) {
lines = new SafeUint32Array(Math.max(sourceLength + 1024, MIN_BUFFER_SIZE));
columns = new SafeUint32Array(lines.length);
}
for (var i = start; i < sourceLength; i++) {
var code = source.charCodeAt(i);
lines[i] = line;
columns[i] = column++;
if (code === N || code === R || code === F) {
if (code === R && i + 1 < sourceLength && source.charCodeAt(i + 1) === N) {
i++;
lines[i] = line;
columns[i] = column;
}
line++;
column = 1;
}
}
lines[i] = line;
columns[i] = column;
tokenizer.linesAnsColumnsComputed = true;
tokenizer.lines = lines;
tokenizer.columns = columns;
}
|
javascript
|
function computeLinesAndColumns(tokenizer, source) {
var sourceLength = source.length;
var start = firstCharOffset(source);
var lines = tokenizer.lines;
var line = tokenizer.startLine;
var columns = tokenizer.columns;
var column = tokenizer.startColumn;
if (lines === null || lines.length < sourceLength + 1) {
lines = new SafeUint32Array(Math.max(sourceLength + 1024, MIN_BUFFER_SIZE));
columns = new SafeUint32Array(lines.length);
}
for (var i = start; i < sourceLength; i++) {
var code = source.charCodeAt(i);
lines[i] = line;
columns[i] = column++;
if (code === N || code === R || code === F) {
if (code === R && i + 1 < sourceLength && source.charCodeAt(i + 1) === N) {
i++;
lines[i] = line;
columns[i] = column;
}
line++;
column = 1;
}
}
lines[i] = line;
columns[i] = column;
tokenizer.linesAnsColumnsComputed = true;
tokenizer.lines = lines;
tokenizer.columns = columns;
}
|
[
"function",
"computeLinesAndColumns",
"(",
"tokenizer",
",",
"source",
")",
"{",
"var",
"sourceLength",
"=",
"source",
".",
"length",
";",
"var",
"start",
"=",
"firstCharOffset",
"(",
"source",
")",
";",
"var",
"lines",
"=",
"tokenizer",
".",
"lines",
";",
"var",
"line",
"=",
"tokenizer",
".",
"startLine",
";",
"var",
"columns",
"=",
"tokenizer",
".",
"columns",
";",
"var",
"column",
"=",
"tokenizer",
".",
"startColumn",
";",
"if",
"(",
"lines",
"===",
"null",
"||",
"lines",
".",
"length",
"<",
"sourceLength",
"+",
"1",
")",
"{",
"lines",
"=",
"new",
"SafeUint32Array",
"(",
"Math",
".",
"max",
"(",
"sourceLength",
"+",
"1024",
",",
"MIN_BUFFER_SIZE",
")",
")",
";",
"columns",
"=",
"new",
"SafeUint32Array",
"(",
"lines",
".",
"length",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"start",
";",
"i",
"<",
"sourceLength",
";",
"i",
"++",
")",
"{",
"var",
"code",
"=",
"source",
".",
"charCodeAt",
"(",
"i",
")",
";",
"lines",
"[",
"i",
"]",
"=",
"line",
";",
"columns",
"[",
"i",
"]",
"=",
"column",
"++",
";",
"if",
"(",
"code",
"===",
"N",
"||",
"code",
"===",
"R",
"||",
"code",
"===",
"F",
")",
"{",
"if",
"(",
"code",
"===",
"R",
"&&",
"i",
"+",
"1",
"<",
"sourceLength",
"&&",
"source",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"===",
"N",
")",
"{",
"i",
"++",
";",
"lines",
"[",
"i",
"]",
"=",
"line",
";",
"columns",
"[",
"i",
"]",
"=",
"column",
";",
"}",
"line",
"++",
";",
"column",
"=",
"1",
";",
"}",
"}",
"lines",
"[",
"i",
"]",
"=",
"line",
";",
"columns",
"[",
"i",
"]",
"=",
"column",
";",
"tokenizer",
".",
"linesAnsColumnsComputed",
"=",
"true",
";",
"tokenizer",
".",
"lines",
"=",
"lines",
";",
"tokenizer",
".",
"columns",
"=",
"columns",
";",
"}"
] |
fallback on Array when TypedArray is not supported
|
[
"fallback",
"on",
"Array",
"when",
"TypedArray",
"is",
"not",
"supported"
] |
5835eabde1d789e8a5a030a0946f2b4a1698c350
|
https://github.com/csstree/csstree/blob/5835eabde1d789e8a5a030a0946f2b4a1698c350/lib/tokenizer/Tokenizer.js#L60-L97
|
9,192
|
apache/cordova-plugin-splashscreen
|
src/browser/SplashScreenProxy.js
|
readPreferencesFromCfg
|
function readPreferencesFromCfg(cfg) {
try {
var value = cfg.getPreferenceValue('ShowSplashScreen');
if(typeof value != 'undefined') {
showSplashScreen = value === 'true';
}
splashScreenDelay = cfg.getPreferenceValue('SplashScreenDelay') || splashScreenDelay;
splashScreenDelay = parseInt(splashScreenDelay, 10);
imageSrc = cfg.getPreferenceValue('SplashScreen') || imageSrc;
bgColor = cfg.getPreferenceValue('SplashScreenBackgroundColor') || bgColor;
splashImageWidth = cfg.getPreferenceValue('SplashScreenWidth') || splashImageWidth;
splashImageHeight = cfg.getPreferenceValue('SplashScreenHeight') || splashImageHeight;
autoHideSplashScreen = cfg.getPreferenceValue('AutoHideSplashScreen') || autoHideSplashScreen;
autoHideSplashScreen = (autoHideSplashScreen === true || autoHideSplashScreen.toLowerCase() === 'true');
} catch(e) {
var msg = '[Browser][SplashScreen] Error occurred on loading preferences from config.xml: ' + JSON.stringify(e);
console.error(msg);
}
}
|
javascript
|
function readPreferencesFromCfg(cfg) {
try {
var value = cfg.getPreferenceValue('ShowSplashScreen');
if(typeof value != 'undefined') {
showSplashScreen = value === 'true';
}
splashScreenDelay = cfg.getPreferenceValue('SplashScreenDelay') || splashScreenDelay;
splashScreenDelay = parseInt(splashScreenDelay, 10);
imageSrc = cfg.getPreferenceValue('SplashScreen') || imageSrc;
bgColor = cfg.getPreferenceValue('SplashScreenBackgroundColor') || bgColor;
splashImageWidth = cfg.getPreferenceValue('SplashScreenWidth') || splashImageWidth;
splashImageHeight = cfg.getPreferenceValue('SplashScreenHeight') || splashImageHeight;
autoHideSplashScreen = cfg.getPreferenceValue('AutoHideSplashScreen') || autoHideSplashScreen;
autoHideSplashScreen = (autoHideSplashScreen === true || autoHideSplashScreen.toLowerCase() === 'true');
} catch(e) {
var msg = '[Browser][SplashScreen] Error occurred on loading preferences from config.xml: ' + JSON.stringify(e);
console.error(msg);
}
}
|
[
"function",
"readPreferencesFromCfg",
"(",
"cfg",
")",
"{",
"try",
"{",
"var",
"value",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'ShowSplashScreen'",
")",
";",
"if",
"(",
"typeof",
"value",
"!=",
"'undefined'",
")",
"{",
"showSplashScreen",
"=",
"value",
"===",
"'true'",
";",
"}",
"splashScreenDelay",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'SplashScreenDelay'",
")",
"||",
"splashScreenDelay",
";",
"splashScreenDelay",
"=",
"parseInt",
"(",
"splashScreenDelay",
",",
"10",
")",
";",
"imageSrc",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'SplashScreen'",
")",
"||",
"imageSrc",
";",
"bgColor",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'SplashScreenBackgroundColor'",
")",
"||",
"bgColor",
";",
"splashImageWidth",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'SplashScreenWidth'",
")",
"||",
"splashImageWidth",
";",
"splashImageHeight",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'SplashScreenHeight'",
")",
"||",
"splashImageHeight",
";",
"autoHideSplashScreen",
"=",
"cfg",
".",
"getPreferenceValue",
"(",
"'AutoHideSplashScreen'",
")",
"||",
"autoHideSplashScreen",
";",
"autoHideSplashScreen",
"=",
"(",
"autoHideSplashScreen",
"===",
"true",
"||",
"autoHideSplashScreen",
".",
"toLowerCase",
"(",
")",
"===",
"'true'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"var",
"msg",
"=",
"'[Browser][SplashScreen] Error occurred on loading preferences from config.xml: '",
"+",
"JSON",
".",
"stringify",
"(",
"e",
")",
";",
"console",
".",
"error",
"(",
"msg",
")",
";",
"}",
"}"
] |
Reads preferences via ConfigHelper and substitutes default parameters.
|
[
"Reads",
"preferences",
"via",
"ConfigHelper",
"and",
"substitutes",
"default",
"parameters",
"."
] |
6800de23b168b3de143ee3f91c1efcaba9309de8
|
https://github.com/apache/cordova-plugin-splashscreen/blob/6800de23b168b3de143ee3f91c1efcaba9309de8/src/browser/SplashScreenProxy.js#L115-L135
|
9,193
|
samselikoff/ember-cli-mirage
|
addon/start-mirage.js
|
resolveRegistration
|
function resolveRegistration(owner, ...args) {
if (owner.resolveRegistration) {
return owner.resolveRegistration(...args);
} else if (owner.__container__) {
return owner.__container__.lookupFactory(...args);
} else {
return owner.container.lookupFactory(...args);
}
}
|
javascript
|
function resolveRegistration(owner, ...args) {
if (owner.resolveRegistration) {
return owner.resolveRegistration(...args);
} else if (owner.__container__) {
return owner.__container__.lookupFactory(...args);
} else {
return owner.container.lookupFactory(...args);
}
}
|
[
"function",
"resolveRegistration",
"(",
"owner",
",",
"...",
"args",
")",
"{",
"if",
"(",
"owner",
".",
"resolveRegistration",
")",
"{",
"return",
"owner",
".",
"resolveRegistration",
"(",
"...",
"args",
")",
";",
"}",
"else",
"if",
"(",
"owner",
".",
"__container__",
")",
"{",
"return",
"owner",
".",
"__container__",
".",
"lookupFactory",
"(",
"...",
"args",
")",
";",
"}",
"else",
"{",
"return",
"owner",
".",
"container",
".",
"lookupFactory",
"(",
"...",
"args",
")",
";",
"}",
"}"
] |
Support Ember 1.13
|
[
"Support",
"Ember",
"1",
".",
"13"
] |
41422055dc884410a0b468ef9e336446d193c8cf
|
https://github.com/samselikoff/ember-cli-mirage/blob/41422055dc884410a0b468ef9e336446d193c8cf/addon/start-mirage.js#L42-L50
|
9,194
|
samselikoff/ember-cli-mirage
|
addon/server.js
|
createPretender
|
function createPretender(server) {
return new Pretender(function() {
this.passthroughRequest = function(verb, path, request) {
if (server.shouldLog()) {
console.log(`Passthrough request: ${verb.toUpperCase()} ${request.url}`);
}
};
this.handledRequest = function(verb, path, request) {
if (server.shouldLog()) {
console.groupCollapsed(
`Mirage: [${request.status}] ${verb.toUpperCase()} ${request.url}`
);
let { requestBody, responseText } = request;
let loggedRequest, loggedResponse;
try {
loggedRequest = JSON.parse(requestBody);
} catch(e) {
loggedRequest = requestBody;
}
try {
loggedResponse = JSON.parse(responseText);
} catch(e) {
loggedResponse = responseText;
}
console.log({
request: loggedRequest,
response: loggedResponse,
raw: request
});
console.groupEnd();
}
};
this.unhandledRequest = function(verb, path) {
path = decodeURI(path);
assert(
`Your Ember app tried to ${verb} '${path}', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?`
);
};
}, { trackRequests: server.shouldTrackRequests() });
}
|
javascript
|
function createPretender(server) {
return new Pretender(function() {
this.passthroughRequest = function(verb, path, request) {
if (server.shouldLog()) {
console.log(`Passthrough request: ${verb.toUpperCase()} ${request.url}`);
}
};
this.handledRequest = function(verb, path, request) {
if (server.shouldLog()) {
console.groupCollapsed(
`Mirage: [${request.status}] ${verb.toUpperCase()} ${request.url}`
);
let { requestBody, responseText } = request;
let loggedRequest, loggedResponse;
try {
loggedRequest = JSON.parse(requestBody);
} catch(e) {
loggedRequest = requestBody;
}
try {
loggedResponse = JSON.parse(responseText);
} catch(e) {
loggedResponse = responseText;
}
console.log({
request: loggedRequest,
response: loggedResponse,
raw: request
});
console.groupEnd();
}
};
this.unhandledRequest = function(verb, path) {
path = decodeURI(path);
assert(
`Your Ember app tried to ${verb} '${path}', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?`
);
};
}, { trackRequests: server.shouldTrackRequests() });
}
|
[
"function",
"createPretender",
"(",
"server",
")",
"{",
"return",
"new",
"Pretender",
"(",
"function",
"(",
")",
"{",
"this",
".",
"passthroughRequest",
"=",
"function",
"(",
"verb",
",",
"path",
",",
"request",
")",
"{",
"if",
"(",
"server",
".",
"shouldLog",
"(",
")",
")",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"verb",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"request",
".",
"url",
"}",
"`",
")",
";",
"}",
"}",
";",
"this",
".",
"handledRequest",
"=",
"function",
"(",
"verb",
",",
"path",
",",
"request",
")",
"{",
"if",
"(",
"server",
".",
"shouldLog",
"(",
")",
")",
"{",
"console",
".",
"groupCollapsed",
"(",
"`",
"${",
"request",
".",
"status",
"}",
"${",
"verb",
".",
"toUpperCase",
"(",
")",
"}",
"${",
"request",
".",
"url",
"}",
"`",
")",
";",
"let",
"{",
"requestBody",
",",
"responseText",
"}",
"=",
"request",
";",
"let",
"loggedRequest",
",",
"loggedResponse",
";",
"try",
"{",
"loggedRequest",
"=",
"JSON",
".",
"parse",
"(",
"requestBody",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"loggedRequest",
"=",
"requestBody",
";",
"}",
"try",
"{",
"loggedResponse",
"=",
"JSON",
".",
"parse",
"(",
"responseText",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"loggedResponse",
"=",
"responseText",
";",
"}",
"console",
".",
"log",
"(",
"{",
"request",
":",
"loggedRequest",
",",
"response",
":",
"loggedResponse",
",",
"raw",
":",
"request",
"}",
")",
";",
"console",
".",
"groupEnd",
"(",
")",
";",
"}",
"}",
";",
"this",
".",
"unhandledRequest",
"=",
"function",
"(",
"verb",
",",
"path",
")",
"{",
"path",
"=",
"decodeURI",
"(",
"path",
")",
";",
"assert",
"(",
"`",
"${",
"verb",
"}",
"${",
"path",
"}",
"`",
")",
";",
"}",
";",
"}",
",",
"{",
"trackRequests",
":",
"server",
".",
"shouldTrackRequests",
"(",
")",
"}",
")",
";",
"}"
] |
Creates a new Pretender instance.
@method createPretender
@param {Server} server
@return {Object} A new Pretender instance.
@public
|
[
"Creates",
"a",
"new",
"Pretender",
"instance",
"."
] |
41422055dc884410a0b468ef9e336446d193c8cf
|
https://github.com/samselikoff/ember-cli-mirage/blob/41422055dc884410a0b468ef9e336446d193c8cf/addon/server.js#L30-L74
|
9,195
|
samselikoff/ember-cli-mirage
|
addon/server.js
|
isOption
|
function isOption(option) {
if (!option || typeof option !== 'object') {
return false;
}
let allOptions = Object.keys(defaultRouteOptions);
let optionKeys = Object.keys(option);
for (let i = 0; i < optionKeys.length; i++) {
let key = optionKeys[i];
if (allOptions.indexOf(key) > -1) {
return true;
}
}
return false;
}
|
javascript
|
function isOption(option) {
if (!option || typeof option !== 'object') {
return false;
}
let allOptions = Object.keys(defaultRouteOptions);
let optionKeys = Object.keys(option);
for (let i = 0; i < optionKeys.length; i++) {
let key = optionKeys[i];
if (allOptions.indexOf(key) > -1) {
return true;
}
}
return false;
}
|
[
"function",
"isOption",
"(",
"option",
")",
"{",
"if",
"(",
"!",
"option",
"||",
"typeof",
"option",
"!==",
"'object'",
")",
"{",
"return",
"false",
";",
"}",
"let",
"allOptions",
"=",
"Object",
".",
"keys",
"(",
"defaultRouteOptions",
")",
";",
"let",
"optionKeys",
"=",
"Object",
".",
"keys",
"(",
"option",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"optionKeys",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"key",
"=",
"optionKeys",
"[",
"i",
"]",
";",
"if",
"(",
"allOptions",
".",
"indexOf",
"(",
"key",
")",
">",
"-",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Determine if the object contains a valid option.
@method isOption
@param {Object} option An object with one option value pair.
@return {Boolean} True if option is a valid option, false otherwise.
@private
|
[
"Determine",
"if",
"the",
"object",
"contains",
"a",
"valid",
"option",
"."
] |
41422055dc884410a0b468ef9e336446d193c8cf
|
https://github.com/samselikoff/ember-cli-mirage/blob/41422055dc884410a0b468ef9e336446d193c8cf/addon/server.js#L102-L116
|
9,196
|
samselikoff/ember-cli-mirage
|
addon/server.js
|
extractRouteArguments
|
function extractRouteArguments(args) {
let [ lastArg ] = args.splice(-1);
if (isOption(lastArg)) {
lastArg = _assign({}, defaultRouteOptions, lastArg);
} else {
args.push(lastArg);
lastArg = defaultRouteOptions;
}
let t = 2 - args.length;
while (t-- > 0) {
args.push(undefined);
}
args.push(lastArg);
return args;
}
|
javascript
|
function extractRouteArguments(args) {
let [ lastArg ] = args.splice(-1);
if (isOption(lastArg)) {
lastArg = _assign({}, defaultRouteOptions, lastArg);
} else {
args.push(lastArg);
lastArg = defaultRouteOptions;
}
let t = 2 - args.length;
while (t-- > 0) {
args.push(undefined);
}
args.push(lastArg);
return args;
}
|
[
"function",
"extractRouteArguments",
"(",
"args",
")",
"{",
"let",
"[",
"lastArg",
"]",
"=",
"args",
".",
"splice",
"(",
"-",
"1",
")",
";",
"if",
"(",
"isOption",
"(",
"lastArg",
")",
")",
"{",
"lastArg",
"=",
"_assign",
"(",
"{",
"}",
",",
"defaultRouteOptions",
",",
"lastArg",
")",
";",
"}",
"else",
"{",
"args",
".",
"push",
"(",
"lastArg",
")",
";",
"lastArg",
"=",
"defaultRouteOptions",
";",
"}",
"let",
"t",
"=",
"2",
"-",
"args",
".",
"length",
";",
"while",
"(",
"t",
"--",
">",
"0",
")",
"{",
"args",
".",
"push",
"(",
"undefined",
")",
";",
"}",
"args",
".",
"push",
"(",
"lastArg",
")",
";",
"return",
"args",
";",
"}"
] |
Extract arguments for a route.
@method extractRouteArguments
@param {Array} args Of the form [options], [object, code], [function, code]
[shorthand, options], [shorthand, code, options]
@return {Array} [handler (i.e. the function, object or shorthand), code,
options].
@private
|
[
"Extract",
"arguments",
"for",
"a",
"route",
"."
] |
41422055dc884410a0b468ef9e336446d193c8cf
|
https://github.com/samselikoff/ember-cli-mirage/blob/41422055dc884410a0b468ef9e336446d193c8cf/addon/server.js#L128-L142
|
9,197
|
ianstormtaylor/superstruct
|
src/superstruct.js
|
superstruct
|
function superstruct(config = {}) {
const types = {
...Types,
...(config.types || {}),
}
/**
* Create a `kind` struct with `schema`, `defaults` and `options`.
*
* @param {Any} schema
* @param {Any} defaults
* @param {Object} options
* @return {Function}
*/
function struct(schema, defaults, options = {}) {
if (isStruct(schema)) {
schema = schema.schema
}
const kind = Kinds.any(schema, defaults, { ...options, types })
function Struct(data) {
if (this instanceof Struct) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
'The `Struct` creation function should not be used with the `new` keyword.'
)
} else {
throw new Error('Invalid `new` keyword!')
}
}
return Struct.assert(data)
}
Object.defineProperty(Struct, IS_STRUCT, { value: true })
Object.defineProperty(Struct, KIND, { value: kind })
Struct.kind = kind.name
Struct.type = kind.type
Struct.schema = schema
Struct.defaults = defaults
Struct.options = options
Struct.assert = value => {
const [error, result] = kind.validate(value)
if (error) {
throw new StructError(error)
}
return result
}
Struct.test = value => {
const [error] = kind.validate(value)
return !error
}
Struct.validate = value => {
const [error, result] = kind.validate(value)
if (error) {
return [new StructError(error)]
}
return [undefined, result]
}
return Struct
}
/**
* Mix in a factory for each specific kind of struct.
*/
Object.keys(Kinds).forEach(name => {
const kind = Kinds[name]
struct[name] = (schema, defaults, options) => {
const type = kind(schema, defaults, { ...options, types })
const s = struct(type, defaults, options)
return s
}
})
/**
* Return the struct factory.
*/
return struct
}
|
javascript
|
function superstruct(config = {}) {
const types = {
...Types,
...(config.types || {}),
}
/**
* Create a `kind` struct with `schema`, `defaults` and `options`.
*
* @param {Any} schema
* @param {Any} defaults
* @param {Object} options
* @return {Function}
*/
function struct(schema, defaults, options = {}) {
if (isStruct(schema)) {
schema = schema.schema
}
const kind = Kinds.any(schema, defaults, { ...options, types })
function Struct(data) {
if (this instanceof Struct) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
'The `Struct` creation function should not be used with the `new` keyword.'
)
} else {
throw new Error('Invalid `new` keyword!')
}
}
return Struct.assert(data)
}
Object.defineProperty(Struct, IS_STRUCT, { value: true })
Object.defineProperty(Struct, KIND, { value: kind })
Struct.kind = kind.name
Struct.type = kind.type
Struct.schema = schema
Struct.defaults = defaults
Struct.options = options
Struct.assert = value => {
const [error, result] = kind.validate(value)
if (error) {
throw new StructError(error)
}
return result
}
Struct.test = value => {
const [error] = kind.validate(value)
return !error
}
Struct.validate = value => {
const [error, result] = kind.validate(value)
if (error) {
return [new StructError(error)]
}
return [undefined, result]
}
return Struct
}
/**
* Mix in a factory for each specific kind of struct.
*/
Object.keys(Kinds).forEach(name => {
const kind = Kinds[name]
struct[name] = (schema, defaults, options) => {
const type = kind(schema, defaults, { ...options, types })
const s = struct(type, defaults, options)
return s
}
})
/**
* Return the struct factory.
*/
return struct
}
|
[
"function",
"superstruct",
"(",
"config",
"=",
"{",
"}",
")",
"{",
"const",
"types",
"=",
"{",
"...",
"Types",
",",
"...",
"(",
"config",
".",
"types",
"||",
"{",
"}",
")",
",",
"}",
"/**\n * Create a `kind` struct with `schema`, `defaults` and `options`.\n *\n * @param {Any} schema\n * @param {Any} defaults\n * @param {Object} options\n * @return {Function}\n */",
"function",
"struct",
"(",
"schema",
",",
"defaults",
",",
"options",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"isStruct",
"(",
"schema",
")",
")",
"{",
"schema",
"=",
"schema",
".",
"schema",
"}",
"const",
"kind",
"=",
"Kinds",
".",
"any",
"(",
"schema",
",",
"defaults",
",",
"{",
"...",
"options",
",",
"types",
"}",
")",
"function",
"Struct",
"(",
"data",
")",
"{",
"if",
"(",
"this",
"instanceof",
"Struct",
")",
"{",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The `Struct` creation function should not be used with the `new` keyword.'",
")",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid `new` keyword!'",
")",
"}",
"}",
"return",
"Struct",
".",
"assert",
"(",
"data",
")",
"}",
"Object",
".",
"defineProperty",
"(",
"Struct",
",",
"IS_STRUCT",
",",
"{",
"value",
":",
"true",
"}",
")",
"Object",
".",
"defineProperty",
"(",
"Struct",
",",
"KIND",
",",
"{",
"value",
":",
"kind",
"}",
")",
"Struct",
".",
"kind",
"=",
"kind",
".",
"name",
"Struct",
".",
"type",
"=",
"kind",
".",
"type",
"Struct",
".",
"schema",
"=",
"schema",
"Struct",
".",
"defaults",
"=",
"defaults",
"Struct",
".",
"options",
"=",
"options",
"Struct",
".",
"assert",
"=",
"value",
"=>",
"{",
"const",
"[",
"error",
",",
"result",
"]",
"=",
"kind",
".",
"validate",
"(",
"value",
")",
"if",
"(",
"error",
")",
"{",
"throw",
"new",
"StructError",
"(",
"error",
")",
"}",
"return",
"result",
"}",
"Struct",
".",
"test",
"=",
"value",
"=>",
"{",
"const",
"[",
"error",
"]",
"=",
"kind",
".",
"validate",
"(",
"value",
")",
"return",
"!",
"error",
"}",
"Struct",
".",
"validate",
"=",
"value",
"=>",
"{",
"const",
"[",
"error",
",",
"result",
"]",
"=",
"kind",
".",
"validate",
"(",
"value",
")",
"if",
"(",
"error",
")",
"{",
"return",
"[",
"new",
"StructError",
"(",
"error",
")",
"]",
"}",
"return",
"[",
"undefined",
",",
"result",
"]",
"}",
"return",
"Struct",
"}",
"/**\n * Mix in a factory for each specific kind of struct.\n */",
"Object",
".",
"keys",
"(",
"Kinds",
")",
".",
"forEach",
"(",
"name",
"=>",
"{",
"const",
"kind",
"=",
"Kinds",
"[",
"name",
"]",
"struct",
"[",
"name",
"]",
"=",
"(",
"schema",
",",
"defaults",
",",
"options",
")",
"=>",
"{",
"const",
"type",
"=",
"kind",
"(",
"schema",
",",
"defaults",
",",
"{",
"...",
"options",
",",
"types",
"}",
")",
"const",
"s",
"=",
"struct",
"(",
"type",
",",
"defaults",
",",
"options",
")",
"return",
"s",
"}",
"}",
")",
"/**\n * Return the struct factory.\n */",
"return",
"struct",
"}"
] |
Create a struct factory with a `config`.
@param {Object} config
@return {Function}
|
[
"Create",
"a",
"struct",
"factory",
"with",
"a",
"config",
"."
] |
5d72235a1ec84b06315e5c87b63787b9cfa2be4c
|
https://github.com/ianstormtaylor/superstruct/blob/5d72235a1ec84b06315e5c87b63787b9cfa2be4c/src/superstruct.js#L14-L106
|
9,198
|
Microsoft/BotBuilder-CognitiveServices
|
CSharp/Samples/LuisActions/LuisActions.Samples.Web/Scripts/jquery.validate.js
|
function( element, method ) {
return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase()));
}
|
javascript
|
function( element, method ) {
return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase()));
}
|
[
"function",
"(",
"element",
",",
"method",
")",
"{",
"return",
"$",
"(",
"element",
")",
".",
"data",
"(",
"\"msg-\"",
"+",
"method",
".",
"toLowerCase",
"(",
")",
")",
"||",
"(",
"element",
".",
"attributes",
"&&",
"$",
"(",
"element",
")",
".",
"attr",
"(",
"\"data-msg-\"",
"+",
"method",
".",
"toLowerCase",
"(",
")",
")",
")",
";",
"}"
] |
return the custom message for the given element and validation method specified in the element's HTML5 data attribute
|
[
"return",
"the",
"custom",
"message",
"for",
"the",
"given",
"element",
"and",
"validation",
"method",
"specified",
"in",
"the",
"element",
"s",
"HTML5",
"data",
"attribute"
] |
f74a54bd7ccc74ef08a3a1d5682dc0198e8869cd
|
https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/f74a54bd7ccc74ef08a3a1d5682dc0198e8869cd/CSharp/Samples/LuisActions/LuisActions.Samples.Web/Scripts/jquery.validate.js#L600-L602
|
|
9,199
|
Microsoft/BotBuilder-CognitiveServices
|
CSharp/Samples/LuisActions/LuisActions.Samples.Web/Scripts/jquery.validate-vsdoc.js
|
function(element, method) {
if (!$.metadata)
return;
var meta = this.settings.meta
? $(element).metadata()[this.settings.meta]
: $(element).metadata();
return meta && meta.messages && meta.messages[method];
}
|
javascript
|
function(element, method) {
if (!$.metadata)
return;
var meta = this.settings.meta
? $(element).metadata()[this.settings.meta]
: $(element).metadata();
return meta && meta.messages && meta.messages[method];
}
|
[
"function",
"(",
"element",
",",
"method",
")",
"{",
"if",
"(",
"!",
"$",
".",
"metadata",
")",
"return",
";",
"var",
"meta",
"=",
"this",
".",
"settings",
".",
"meta",
"?",
"$",
"(",
"element",
")",
".",
"metadata",
"(",
")",
"[",
"this",
".",
"settings",
".",
"meta",
"]",
":",
"$",
"(",
"element",
")",
".",
"metadata",
"(",
")",
";",
"return",
"meta",
"&&",
"meta",
".",
"messages",
"&&",
"meta",
".",
"messages",
"[",
"method",
"]",
";",
"}"
] |
return the custom message for the given element and validation method specified in the element's "messages" metadata
|
[
"return",
"the",
"custom",
"message",
"for",
"the",
"given",
"element",
"and",
"validation",
"method",
"specified",
"in",
"the",
"element",
"s",
"messages",
"metadata"
] |
f74a54bd7ccc74ef08a3a1d5682dc0198e8869cd
|
https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/f74a54bd7ccc74ef08a3a1d5682dc0198e8869cd/CSharp/Samples/LuisActions/LuisActions.Samples.Web/Scripts/jquery.validate-vsdoc.js#L639-L648
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.