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
|
---|---|---|---|---|---|---|---|---|---|---|---|
35,600 |
Dan503/gutter-grid
|
gulp/helpers/navMap-helpers.js
|
getSpecificMap
|
function getSpecificMap(map, array){
var returnMap;
var arrayCopy = array.splice(0);
//if first item in array is "current" or "subnav" it makes the function a bit more efficient
//it restricts any title searches to just offspring of the current page
if (array[0] === 'current' || array[0] === 'subnav'){
arrayCopy.shift();
arrayCopy = pageMap.location.concat(link);
}
for (var i = 0; i < arrayCopy.length; i++){
var searchTerm = arrayCopy[i];
var searchMap = typeof returnMap !== 'undefined' ? returnMap : map;
//Output an error if neither a string or an interval provided
if (checkSearchTerm(searchTerm)){
if (is_string(searchTerm)){
//if item is a string, do a getTitleMap function on the search term using the last map
returnMap = getTitleMap(searchMap, searchTerm);
} else if(is_numeric(searchTerm) && isset(searchMap.subnav)) {
//if item is a number, return the map at the specified index of the last map in array
returnMap = searchMap.subnav[parseInt(searchTerm)];
} else {
returnMap = false;
break;
}
} else {
break;
}
}
if (returnMap){
return returnMap;
} else {
return false;
}
}
|
javascript
|
function getSpecificMap(map, array){
var returnMap;
var arrayCopy = array.splice(0);
//if first item in array is "current" or "subnav" it makes the function a bit more efficient
//it restricts any title searches to just offspring of the current page
if (array[0] === 'current' || array[0] === 'subnav'){
arrayCopy.shift();
arrayCopy = pageMap.location.concat(link);
}
for (var i = 0; i < arrayCopy.length; i++){
var searchTerm = arrayCopy[i];
var searchMap = typeof returnMap !== 'undefined' ? returnMap : map;
//Output an error if neither a string or an interval provided
if (checkSearchTerm(searchTerm)){
if (is_string(searchTerm)){
//if item is a string, do a getTitleMap function on the search term using the last map
returnMap = getTitleMap(searchMap, searchTerm);
} else if(is_numeric(searchTerm) && isset(searchMap.subnav)) {
//if item is a number, return the map at the specified index of the last map in array
returnMap = searchMap.subnav[parseInt(searchTerm)];
} else {
returnMap = false;
break;
}
} else {
break;
}
}
if (returnMap){
return returnMap;
} else {
return false;
}
}
|
[
"function",
"getSpecificMap",
"(",
"map",
",",
"array",
")",
"{",
"var",
"returnMap",
";",
"var",
"arrayCopy",
"=",
"array",
".",
"splice",
"(",
"0",
")",
";",
"//if first item in array is \"current\" or \"subnav\" it makes the function a bit more efficient",
"//it restricts any title searches to just offspring of the current page",
"if",
"(",
"array",
"[",
"0",
"]",
"===",
"'current'",
"||",
"array",
"[",
"0",
"]",
"===",
"'subnav'",
")",
"{",
"arrayCopy",
".",
"shift",
"(",
")",
";",
"arrayCopy",
"=",
"pageMap",
".",
"location",
".",
"concat",
"(",
"link",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arrayCopy",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"searchTerm",
"=",
"arrayCopy",
"[",
"i",
"]",
";",
"var",
"searchMap",
"=",
"typeof",
"returnMap",
"!==",
"'undefined'",
"?",
"returnMap",
":",
"map",
";",
"//Output an error if neither a string or an interval provided",
"if",
"(",
"checkSearchTerm",
"(",
"searchTerm",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"searchTerm",
")",
")",
"{",
"//if item is a string, do a getTitleMap function on the search term using the last map",
"returnMap",
"=",
"getTitleMap",
"(",
"searchMap",
",",
"searchTerm",
")",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"searchTerm",
")",
"&&",
"isset",
"(",
"searchMap",
".",
"subnav",
")",
")",
"{",
"//if item is a number, return the map at the specified index of the last map in array",
"returnMap",
"=",
"searchMap",
".",
"subnav",
"[",
"parseInt",
"(",
"searchTerm",
")",
"]",
";",
"}",
"else",
"{",
"returnMap",
"=",
"false",
";",
"break",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"returnMap",
")",
"{",
"return",
"returnMap",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
function that accepts an array to search for specific sections of the nav map array accepts both numbers and titles function not to be used in regular code
|
[
"function",
"that",
"accepts",
"an",
"array",
"to",
"search",
"for",
"specific",
"sections",
"of",
"the",
"nav",
"map",
"array",
"accepts",
"both",
"numbers",
"and",
"titles",
"function",
"not",
"to",
"be",
"used",
"in",
"regular",
"code"
] |
b31084da606396577474cad592998a57a63725ba
|
https://github.com/Dan503/gutter-grid/blob/b31084da606396577474cad592998a57a63725ba/gulp/helpers/navMap-helpers.js#L68-L108
|
35,601 |
Dan503/gutter-grid
|
gulp/helpers/navMap-helpers.js
|
getNavMap
|
function getNavMap(navMap, searchTerm, portion){
let returnMap = navMap;
if (!isset(searchTerm) || is_array(searchTerm) && searchTerm.length === 0){
//if the search term is an empty array, it will return the full nav map (excluding ROOT)
return returnMap;
}
//code for when an array is given (filters results based on numbers and titles provided in array)
if (is_array(searchTerm)){
returnMap = getSpecificMap(returnMap, searchTerm);
//code for when a string is given (searches full nav map for Title that matches)
} else if (is_string(searchTerm)) {
returnMap = getTitleMap(returnMap, searchTerm);
//code for when a single number is given (treats it as a single level location variable)
} else if (is_int(searchTerm)) {
returnMap = returnMap[searchTerm];
//throws error if searchTerm variable doesn't make sense
} else {
console.log('\nThe search term must be either a string, interval or an array. \nSearch term =\n', searchTerm);
}
if (isset(portion)) {
return returnMap[portion];
} else {
return returnMap;
}
}
|
javascript
|
function getNavMap(navMap, searchTerm, portion){
let returnMap = navMap;
if (!isset(searchTerm) || is_array(searchTerm) && searchTerm.length === 0){
//if the search term is an empty array, it will return the full nav map (excluding ROOT)
return returnMap;
}
//code for when an array is given (filters results based on numbers and titles provided in array)
if (is_array(searchTerm)){
returnMap = getSpecificMap(returnMap, searchTerm);
//code for when a string is given (searches full nav map for Title that matches)
} else if (is_string(searchTerm)) {
returnMap = getTitleMap(returnMap, searchTerm);
//code for when a single number is given (treats it as a single level location variable)
} else if (is_int(searchTerm)) {
returnMap = returnMap[searchTerm];
//throws error if searchTerm variable doesn't make sense
} else {
console.log('\nThe search term must be either a string, interval or an array. \nSearch term =\n', searchTerm);
}
if (isset(portion)) {
return returnMap[portion];
} else {
return returnMap;
}
}
|
[
"function",
"getNavMap",
"(",
"navMap",
",",
"searchTerm",
",",
"portion",
")",
"{",
"let",
"returnMap",
"=",
"navMap",
";",
"if",
"(",
"!",
"isset",
"(",
"searchTerm",
")",
"||",
"is_array",
"(",
"searchTerm",
")",
"&&",
"searchTerm",
".",
"length",
"===",
"0",
")",
"{",
"//if the search term is an empty array, it will return the full nav map (excluding ROOT)",
"return",
"returnMap",
";",
"}",
"//code for when an array is given (filters results based on numbers and titles provided in array)",
"if",
"(",
"is_array",
"(",
"searchTerm",
")",
")",
"{",
"returnMap",
"=",
"getSpecificMap",
"(",
"returnMap",
",",
"searchTerm",
")",
";",
"//code for when a string is given (searches full nav map for Title that matches)",
"}",
"else",
"if",
"(",
"is_string",
"(",
"searchTerm",
")",
")",
"{",
"returnMap",
"=",
"getTitleMap",
"(",
"returnMap",
",",
"searchTerm",
")",
";",
"//code for when a single number is given (treats it as a single level location variable)",
"}",
"else",
"if",
"(",
"is_int",
"(",
"searchTerm",
")",
")",
"{",
"returnMap",
"=",
"returnMap",
"[",
"searchTerm",
"]",
";",
"//throws error if searchTerm variable doesn't make sense",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'\\nThe search term must be either a string, interval or an array. \\nSearch term =\\n'",
",",
"searchTerm",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"portion",
")",
")",
"{",
"return",
"returnMap",
"[",
"portion",
"]",
";",
"}",
"else",
"{",
"return",
"returnMap",
";",
"}",
"}"
] |
function for looking up a specific portion of the navMap using a location array or a title
|
[
"function",
"for",
"looking",
"up",
"a",
"specific",
"portion",
"of",
"the",
"navMap",
"using",
"a",
"location",
"array",
"or",
"a",
"title"
] |
b31084da606396577474cad592998a57a63725ba
|
https://github.com/Dan503/gutter-grid/blob/b31084da606396577474cad592998a57a63725ba/gulp/helpers/navMap-helpers.js#L137-L169
|
35,602 |
IndigoUnited/automaton
|
lib/string/castInterpolate.js
|
castInterpolate
|
function castInterpolate(template, replacements, options) {
var matches = template.match(regExp);
var placeholder;
var not;
if (matches) {
placeholder = matches[1];
// Check if exists first
if (mout.object.has(replacements, placeholder)) {
return mout.object.get(replacements, placeholder);
}
// Handle not (!) (note that !foo! is ignored but !foo isn't)
if (/^!+?[^!]+$/.test(placeholder)) {
placeholder = placeholder.replace(/!!+/, '');
not = placeholder.charAt(0) === '!';
placeholder = not ? placeholder.substr(1) : placeholder;
if (mout.object.has(replacements, placeholder)) {
placeholder = mout.object.get(replacements, placeholder);
return not ? !placeholder : !!placeholder;
}
}
}
return interpolate(template, replacements, options);
}
|
javascript
|
function castInterpolate(template, replacements, options) {
var matches = template.match(regExp);
var placeholder;
var not;
if (matches) {
placeholder = matches[1];
// Check if exists first
if (mout.object.has(replacements, placeholder)) {
return mout.object.get(replacements, placeholder);
}
// Handle not (!) (note that !foo! is ignored but !foo isn't)
if (/^!+?[^!]+$/.test(placeholder)) {
placeholder = placeholder.replace(/!!+/, '');
not = placeholder.charAt(0) === '!';
placeholder = not ? placeholder.substr(1) : placeholder;
if (mout.object.has(replacements, placeholder)) {
placeholder = mout.object.get(replacements, placeholder);
return not ? !placeholder : !!placeholder;
}
}
}
return interpolate(template, replacements, options);
}
|
[
"function",
"castInterpolate",
"(",
"template",
",",
"replacements",
",",
"options",
")",
"{",
"var",
"matches",
"=",
"template",
".",
"match",
"(",
"regExp",
")",
";",
"var",
"placeholder",
";",
"var",
"not",
";",
"if",
"(",
"matches",
")",
"{",
"placeholder",
"=",
"matches",
"[",
"1",
"]",
";",
"// Check if exists first",
"if",
"(",
"mout",
".",
"object",
".",
"has",
"(",
"replacements",
",",
"placeholder",
")",
")",
"{",
"return",
"mout",
".",
"object",
".",
"get",
"(",
"replacements",
",",
"placeholder",
")",
";",
"}",
"// Handle not (!) (note that !foo! is ignored but !foo isn't)",
"if",
"(",
"/",
"^!+?[^!]+$",
"/",
".",
"test",
"(",
"placeholder",
")",
")",
"{",
"placeholder",
"=",
"placeholder",
".",
"replace",
"(",
"/",
"!!+",
"/",
",",
"''",
")",
";",
"not",
"=",
"placeholder",
".",
"charAt",
"(",
"0",
")",
"===",
"'!'",
";",
"placeholder",
"=",
"not",
"?",
"placeholder",
".",
"substr",
"(",
"1",
")",
":",
"placeholder",
";",
"if",
"(",
"mout",
".",
"object",
".",
"has",
"(",
"replacements",
",",
"placeholder",
")",
")",
"{",
"placeholder",
"=",
"mout",
".",
"object",
".",
"get",
"(",
"replacements",
",",
"placeholder",
")",
";",
"return",
"not",
"?",
"!",
"placeholder",
":",
"!",
"!",
"placeholder",
";",
"}",
"}",
"}",
"return",
"interpolate",
"(",
"template",
",",
"replacements",
",",
"options",
")",
";",
"}"
] |
String interpolation with casting.
Similar to the normal interpolation but if the template contains only
a token and the value is available, the value will be returned.
This way tokens that have values other than strings will be returned instead.
@param {String} template The template
@param {Object} replacements The replacements
@param {Object} [options] The options
@return {Mixed} The interpolated string or the real token value
|
[
"String",
"interpolation",
"with",
"casting",
".",
"Similar",
"to",
"the",
"normal",
"interpolation",
"but",
"if",
"the",
"template",
"contains",
"only",
"a",
"token",
"and",
"the",
"value",
"is",
"available",
"the",
"value",
"will",
"be",
"returned",
".",
"This",
"way",
"tokens",
"that",
"have",
"values",
"other",
"than",
"strings",
"will",
"be",
"returned",
"instead",
"."
] |
3e86a76374a288e4f125b3e4994c9738f79c7028
|
https://github.com/IndigoUnited/automaton/blob/3e86a76374a288e4f125b3e4994c9738f79c7028/lib/string/castInterpolate.js#L25-L52
|
35,603 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/reduceMultiplicationByZero.js
|
reduceMultiplicationByZero
|
function reduceMultiplicationByZero(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const zeroIndex = node.args.findIndex(arg => {
if (Node.Type.isConstant(arg) && arg.value === '0') {
return true;
}
if (Node.PolynomialTerm.isPolynomialTerm(arg)) {
const polyTerm = new Node.PolynomialTerm(arg);
return polyTerm.getCoeffValue() === 0;
}
return false;
});
if (zeroIndex >= 0) {
// reduce to just the 0 node
const newNode = Node.Creator.constant(0);
return Node.Status.nodeChanged(
ChangeTypes.MULTIPLY_BY_ZERO, node, newNode);
}
else {
return Node.Status.noChange(node);
}
}
|
javascript
|
function reduceMultiplicationByZero(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const zeroIndex = node.args.findIndex(arg => {
if (Node.Type.isConstant(arg) && arg.value === '0') {
return true;
}
if (Node.PolynomialTerm.isPolynomialTerm(arg)) {
const polyTerm = new Node.PolynomialTerm(arg);
return polyTerm.getCoeffValue() === 0;
}
return false;
});
if (zeroIndex >= 0) {
// reduce to just the 0 node
const newNode = Node.Creator.constant(0);
return Node.Status.nodeChanged(
ChangeTypes.MULTIPLY_BY_ZERO, node, newNode);
}
else {
return Node.Status.noChange(node);
}
}
|
[
"function",
"reduceMultiplicationByZero",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'*'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"const",
"zeroIndex",
"=",
"node",
".",
"args",
".",
"findIndex",
"(",
"arg",
"=>",
"{",
"if",
"(",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"arg",
")",
"&&",
"arg",
".",
"value",
"===",
"'0'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"Node",
".",
"PolynomialTerm",
".",
"isPolynomialTerm",
"(",
"arg",
")",
")",
"{",
"const",
"polyTerm",
"=",
"new",
"Node",
".",
"PolynomialTerm",
"(",
"arg",
")",
";",
"return",
"polyTerm",
".",
"getCoeffValue",
"(",
")",
"===",
"0",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"if",
"(",
"zeroIndex",
">=",
"0",
")",
"{",
"// reduce to just the 0 node",
"const",
"newNode",
"=",
"Node",
".",
"Creator",
".",
"constant",
"(",
"0",
")",
";",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"MULTIPLY_BY_ZERO",
",",
"node",
",",
"newNode",
")",
";",
"}",
"else",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"}"
] |
If `node` is a multiplication node with 0 as one of its operands, reduce the node to 0. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"a",
"multiplication",
"node",
"with",
"0",
"as",
"one",
"of",
"its",
"operands",
"reduce",
"the",
"node",
"to",
"0",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/reduceMultiplicationByZero.js#L8-L31
|
35,604 |
deanius/antares
|
demos/02-speak-up.js
|
speakIt
|
function speakIt({ action }) {
const { toSpeak } = action.payload
// Remember: unlike Promises, which share a similar construction,
// the observable function is not run until the Observable recieves
// a subscribe() call.
return new Observable(observer => {
try {
const say = require("say")
say.speak(toSpeak, null, null, () => {
observer.complete()
})
// An Observable allows for cancellation by returning a
// cancellation function
return () => {
say.stop()
}
} catch (error) {
log("-- speech synthesis not available --")
observer.error()
}
})
}
|
javascript
|
function speakIt({ action }) {
const { toSpeak } = action.payload
// Remember: unlike Promises, which share a similar construction,
// the observable function is not run until the Observable recieves
// a subscribe() call.
return new Observable(observer => {
try {
const say = require("say")
say.speak(toSpeak, null, null, () => {
observer.complete()
})
// An Observable allows for cancellation by returning a
// cancellation function
return () => {
say.stop()
}
} catch (error) {
log("-- speech synthesis not available --")
observer.error()
}
})
}
|
[
"function",
"speakIt",
"(",
"{",
"action",
"}",
")",
"{",
"const",
"{",
"toSpeak",
"}",
"=",
"action",
".",
"payload",
"// Remember: unlike Promises, which share a similar construction,",
"// the observable function is not run until the Observable recieves",
"// a subscribe() call.",
"return",
"new",
"Observable",
"(",
"observer",
"=>",
"{",
"try",
"{",
"const",
"say",
"=",
"require",
"(",
"\"say\"",
")",
"say",
".",
"speak",
"(",
"toSpeak",
",",
"null",
",",
"null",
",",
"(",
")",
"=>",
"{",
"observer",
".",
"complete",
"(",
")",
"}",
")",
"// An Observable allows for cancellation by returning a",
"// cancellation function",
"return",
"(",
")",
"=>",
"{",
"say",
".",
"stop",
"(",
")",
"}",
"}",
"catch",
"(",
"error",
")",
"{",
"log",
"(",
"\"-- speech synthesis not available --\"",
")",
"observer",
".",
"error",
"(",
")",
"}",
"}",
")",
"}"
] |
Return an observable that begins when subscribe is called, and completes when say.speak ends
|
[
"Return",
"an",
"observable",
"that",
"begins",
"when",
"subscribe",
"is",
"called",
"and",
"completes",
"when",
"say",
".",
"speak",
"ends"
] |
e876afbfa3b56356c9b0a9d24a82cbf603b0a8f5
|
https://github.com/deanius/antares/blob/e876afbfa3b56356c9b0a9d24a82cbf603b0a8f5/demos/02-speak-up.js#L134-L157
|
35,605 |
metadelta/metadelta
|
packages/solver/lib/util/removeUnnecessaryParens.js
|
removeUnnecessaryParens
|
function removeUnnecessaryParens(node, rootNode=false) {
// Parens that wrap everything are redundant.
// NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't
// needed, while this step only applies to the very top level expression.
// e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3) as a top level
// expression can become 2 + 3
if (rootNode) {
while (Node.Type.isParenthesis(node)) {
node = node.content;
}
}
return removeUnnecessaryParensSearch(node);
}
|
javascript
|
function removeUnnecessaryParens(node, rootNode=false) {
// Parens that wrap everything are redundant.
// NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't
// needed, while this step only applies to the very top level expression.
// e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3) as a top level
// expression can become 2 + 3
if (rootNode) {
while (Node.Type.isParenthesis(node)) {
node = node.content;
}
}
return removeUnnecessaryParensSearch(node);
}
|
[
"function",
"removeUnnecessaryParens",
"(",
"node",
",",
"rootNode",
"=",
"false",
")",
"{",
"// Parens that wrap everything are redundant.",
"// NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't",
"// needed, while this step only applies to the very top level expression.",
"// e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3) as a top level",
"// expression can become 2 + 3",
"if",
"(",
"rootNode",
")",
"{",
"while",
"(",
"Node",
".",
"Type",
".",
"isParenthesis",
"(",
"node",
")",
")",
"{",
"node",
"=",
"node",
".",
"content",
";",
"}",
"}",
"return",
"removeUnnecessaryParensSearch",
"(",
"node",
")",
";",
"}"
] |
Removes any parenthesis around nodes that can't be resolved further. Input must be a top level expression. Returns a node.
|
[
"Removes",
"any",
"parenthesis",
"around",
"nodes",
"that",
"can",
"t",
"be",
"resolved",
"further",
".",
"Input",
"must",
"be",
"a",
"top",
"level",
"expression",
".",
"Returns",
"a",
"node",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/removeUnnecessaryParens.js#L10-L22
|
35,606 |
metadelta/metadelta
|
packages/solver/lib/util/removeUnnecessaryParens.js
|
removeUnnecessaryParensInOperatorNode
|
function removeUnnecessaryParensInOperatorNode(node) {
node.args.forEach((child, i) => {
node.args[i] = removeUnnecessaryParensSearch(child);
});
// Sometimes, parens are around expressions that have been simplified
// all they can be. If that expression is part of an addition or subtraction
// operation, we can remove the parenthesis.
// e.g. (x+4) + 12 -> x+4 + 12
if (node.op === '+') {
node.args.forEach((child, i) => {
if (Node.Type.isParenthesis(child) &&
!canCollectOrCombine(child.content)) {
// remove the parens by replacing the child node (in its args list)
// with its content
node.args[i] = child.content;
}
});
}
// This is different from addition because when subtracting a group of terms
//in parenthesis, we want to distribute the subtraction.
// e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x`
else if (node.op === '-') {
if (Node.Type.isParenthesis(node.args[0]) &&
!canCollectOrCombine(node.args[0].content)) {
node.args[0] = node.args[0].content;
}
}
return node;
}
|
javascript
|
function removeUnnecessaryParensInOperatorNode(node) {
node.args.forEach((child, i) => {
node.args[i] = removeUnnecessaryParensSearch(child);
});
// Sometimes, parens are around expressions that have been simplified
// all they can be. If that expression is part of an addition or subtraction
// operation, we can remove the parenthesis.
// e.g. (x+4) + 12 -> x+4 + 12
if (node.op === '+') {
node.args.forEach((child, i) => {
if (Node.Type.isParenthesis(child) &&
!canCollectOrCombine(child.content)) {
// remove the parens by replacing the child node (in its args list)
// with its content
node.args[i] = child.content;
}
});
}
// This is different from addition because when subtracting a group of terms
//in parenthesis, we want to distribute the subtraction.
// e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x`
else if (node.op === '-') {
if (Node.Type.isParenthesis(node.args[0]) &&
!canCollectOrCombine(node.args[0].content)) {
node.args[0] = node.args[0].content;
}
}
return node;
}
|
[
"function",
"removeUnnecessaryParensInOperatorNode",
"(",
"node",
")",
"{",
"node",
".",
"args",
".",
"forEach",
"(",
"(",
"child",
",",
"i",
")",
"=>",
"{",
"node",
".",
"args",
"[",
"i",
"]",
"=",
"removeUnnecessaryParensSearch",
"(",
"child",
")",
";",
"}",
")",
";",
"// Sometimes, parens are around expressions that have been simplified",
"// all they can be. If that expression is part of an addition or subtraction",
"// operation, we can remove the parenthesis.",
"// e.g. (x+4) + 12 -> x+4 + 12",
"if",
"(",
"node",
".",
"op",
"===",
"'+'",
")",
"{",
"node",
".",
"args",
".",
"forEach",
"(",
"(",
"child",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"Node",
".",
"Type",
".",
"isParenthesis",
"(",
"child",
")",
"&&",
"!",
"canCollectOrCombine",
"(",
"child",
".",
"content",
")",
")",
"{",
"// remove the parens by replacing the child node (in its args list)",
"// with its content",
"node",
".",
"args",
"[",
"i",
"]",
"=",
"child",
".",
"content",
";",
"}",
"}",
")",
";",
"}",
"// This is different from addition because when subtracting a group of terms",
"//in parenthesis, we want to distribute the subtraction.",
"// e.g. `(2 + x) - (1 + x)` => `2 + x - (1 + x)` not `2 + x - 1 + x`",
"else",
"if",
"(",
"node",
".",
"op",
"===",
"'-'",
")",
"{",
"if",
"(",
"Node",
".",
"Type",
".",
"isParenthesis",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
"&&",
"!",
"canCollectOrCombine",
"(",
"node",
".",
"args",
"[",
"0",
"]",
".",
"content",
")",
")",
"{",
"node",
".",
"args",
"[",
"0",
"]",
"=",
"node",
".",
"args",
"[",
"0",
"]",
".",
"content",
";",
"}",
"}",
"return",
"node",
";",
"}"
] |
Removes unncessary parens for each operator in an operator node, and removes unncessary parens around operators that can't be simplified further. Returns a node.
|
[
"Removes",
"unncessary",
"parens",
"for",
"each",
"operator",
"in",
"an",
"operator",
"node",
"and",
"removes",
"unncessary",
"parens",
"around",
"operators",
"that",
"can",
"t",
"be",
"simplified",
"further",
".",
"Returns",
"a",
"node",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/removeUnnecessaryParens.js#L54-L84
|
35,607 |
metadelta/metadelta
|
packages/solver/lib/util/removeUnnecessaryParens.js
|
removeUnnecessaryParensInFunctionNode
|
function removeUnnecessaryParensInFunctionNode(node) {
node.args.forEach((child, i) => {
if (Node.Type.isParenthesis(child)) {
child = child.content;
}
node.args[i] = removeUnnecessaryParensSearch(child);
});
return node;
}
|
javascript
|
function removeUnnecessaryParensInFunctionNode(node) {
node.args.forEach((child, i) => {
if (Node.Type.isParenthesis(child)) {
child = child.content;
}
node.args[i] = removeUnnecessaryParensSearch(child);
});
return node;
}
|
[
"function",
"removeUnnecessaryParensInFunctionNode",
"(",
"node",
")",
"{",
"node",
".",
"args",
".",
"forEach",
"(",
"(",
"child",
",",
"i",
")",
"=>",
"{",
"if",
"(",
"Node",
".",
"Type",
".",
"isParenthesis",
"(",
"child",
")",
")",
"{",
"child",
"=",
"child",
".",
"content",
";",
"}",
"node",
".",
"args",
"[",
"i",
"]",
"=",
"removeUnnecessaryParensSearch",
"(",
"child",
")",
";",
"}",
")",
";",
"return",
"node",
";",
"}"
] |
Removes unncessary parens for each argument in a function node. Returns a node.
|
[
"Removes",
"unncessary",
"parens",
"for",
"each",
"argument",
"in",
"a",
"function",
"node",
".",
"Returns",
"a",
"node",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/removeUnnecessaryParens.js#L88-L97
|
35,608 |
metadelta/metadelta
|
packages/solver/lib/util/removeUnnecessaryParens.js
|
canCollectOrCombine
|
function canCollectOrCombine(node) {
return LikeTermCollector.canCollectLikeTerms(node) ||
checks.resolvesToConstant(node) ||
checks.canSimplifyPolynomialTerms(node);
}
|
javascript
|
function canCollectOrCombine(node) {
return LikeTermCollector.canCollectLikeTerms(node) ||
checks.resolvesToConstant(node) ||
checks.canSimplifyPolynomialTerms(node);
}
|
[
"function",
"canCollectOrCombine",
"(",
"node",
")",
"{",
"return",
"LikeTermCollector",
".",
"canCollectLikeTerms",
"(",
"node",
")",
"||",
"checks",
".",
"resolvesToConstant",
"(",
"node",
")",
"||",
"checks",
".",
"canSimplifyPolynomialTerms",
"(",
"node",
")",
";",
"}"
] |
Returns true if any of the collect or combine steps can be applied to the expression tree `node`.
|
[
"Returns",
"true",
"if",
"any",
"of",
"the",
"collect",
"or",
"combine",
"steps",
"can",
"be",
"applied",
"to",
"the",
"expression",
"tree",
"node",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/removeUnnecessaryParens.js#L157-L161
|
35,609 |
Corey600/zoodubbo
|
lib/invoker.js
|
Invoker
|
function Invoker(zk, opt) {
if (!(this instanceof Invoker)) return new Invoker(zk, opt);
var option = opt || {};
this._path = option.path;
this._dubbo = option.dubbo;
this._version = option.version;
this._timeout = option.timeout;
this._poolMax = option.poolMax;
this._poolMin = option.poolMin;
this._providers = null; // Array
this._configurators = null; // Object
this._loadBalance = new RandomLoadBalance();
this._parseProviders = this._parseProviders.bind(this);
this._parseConfigurators = this._parseConfigurators.bind(this);
if ('string' === typeof zk) {
this._uris = [zk];
} else if (Array.isArray(zk)) {
this._uris = zk;
} else if (zk) {
this._registerProviders = new Register(zk, '/dubbo/' + this._path + '/providers');
this._registerConfigurators = new Register(zk, '/dubbo/' + this._path + '/configurators');
this._registerProviders.on('change', this._parseProviders);
this._registerConfigurators.on('change', this._parseConfigurators);
}
}
|
javascript
|
function Invoker(zk, opt) {
if (!(this instanceof Invoker)) return new Invoker(zk, opt);
var option = opt || {};
this._path = option.path;
this._dubbo = option.dubbo;
this._version = option.version;
this._timeout = option.timeout;
this._poolMax = option.poolMax;
this._poolMin = option.poolMin;
this._providers = null; // Array
this._configurators = null; // Object
this._loadBalance = new RandomLoadBalance();
this._parseProviders = this._parseProviders.bind(this);
this._parseConfigurators = this._parseConfigurators.bind(this);
if ('string' === typeof zk) {
this._uris = [zk];
} else if (Array.isArray(zk)) {
this._uris = zk;
} else if (zk) {
this._registerProviders = new Register(zk, '/dubbo/' + this._path + '/providers');
this._registerConfigurators = new Register(zk, '/dubbo/' + this._path + '/configurators');
this._registerProviders.on('change', this._parseProviders);
this._registerConfigurators.on('change', this._parseConfigurators);
}
}
|
[
"function",
"Invoker",
"(",
"zk",
",",
"opt",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Invoker",
")",
")",
"return",
"new",
"Invoker",
"(",
"zk",
",",
"opt",
")",
";",
"var",
"option",
"=",
"opt",
"||",
"{",
"}",
";",
"this",
".",
"_path",
"=",
"option",
".",
"path",
";",
"this",
".",
"_dubbo",
"=",
"option",
".",
"dubbo",
";",
"this",
".",
"_version",
"=",
"option",
".",
"version",
";",
"this",
".",
"_timeout",
"=",
"option",
".",
"timeout",
";",
"this",
".",
"_poolMax",
"=",
"option",
".",
"poolMax",
";",
"this",
".",
"_poolMin",
"=",
"option",
".",
"poolMin",
";",
"this",
".",
"_providers",
"=",
"null",
";",
"// Array",
"this",
".",
"_configurators",
"=",
"null",
";",
"// Object",
"this",
".",
"_loadBalance",
"=",
"new",
"RandomLoadBalance",
"(",
")",
";",
"this",
".",
"_parseProviders",
"=",
"this",
".",
"_parseProviders",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_parseConfigurators",
"=",
"this",
".",
"_parseConfigurators",
".",
"bind",
"(",
"this",
")",
";",
"if",
"(",
"'string'",
"===",
"typeof",
"zk",
")",
"{",
"this",
".",
"_uris",
"=",
"[",
"zk",
"]",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"zk",
")",
")",
"{",
"this",
".",
"_uris",
"=",
"zk",
";",
"}",
"else",
"if",
"(",
"zk",
")",
"{",
"this",
".",
"_registerProviders",
"=",
"new",
"Register",
"(",
"zk",
",",
"'/dubbo/'",
"+",
"this",
".",
"_path",
"+",
"'/providers'",
")",
";",
"this",
".",
"_registerConfigurators",
"=",
"new",
"Register",
"(",
"zk",
",",
"'/dubbo/'",
"+",
"this",
".",
"_path",
"+",
"'/configurators'",
")",
";",
"this",
".",
"_registerProviders",
".",
"on",
"(",
"'change'",
",",
"this",
".",
"_parseProviders",
")",
";",
"this",
".",
"_registerConfigurators",
".",
"on",
"(",
"'change'",
",",
"this",
".",
"_parseConfigurators",
")",
";",
"}",
"}"
] |
Constructor of Invoker.
@param {Client|String|Array} zk // The ZD instance or the uri of providers.
@param {Object} opt
{
path: String // The path of service node.
version: String, // The version of service.
timeout: Number, // Timeout in milliseconds, defaults to 60 seconds.
}
@returns {Invoker}
@constructor
|
[
"Constructor",
"of",
"Invoker",
"."
] |
c5700687898c82c18d1326ecaccc33fa20269b72
|
https://github.com/Corey600/zoodubbo/blob/c5700687898c82c18d1326ecaccc33fa20269b72/lib/invoker.js#L37-L65
|
35,610 |
vlucas/toystore
|
es5/index.js
|
_expandNestedPaths
|
function _expandNestedPaths(paths) {
var expandedPaths = [];
_pathsArray(paths).forEach(function (p) {
if (p.indexOf('.') !== -1) {
var pathsWithRoots = p.split('.').map(function (value, index, array) {
return array.slice(0, index + 1).join('.');
});
expandedPaths = expandedPaths.concat(pathsWithRoots);
} else {
expandedPaths.push(p);
}
});
return expandedPaths;
}
|
javascript
|
function _expandNestedPaths(paths) {
var expandedPaths = [];
_pathsArray(paths).forEach(function (p) {
if (p.indexOf('.') !== -1) {
var pathsWithRoots = p.split('.').map(function (value, index, array) {
return array.slice(0, index + 1).join('.');
});
expandedPaths = expandedPaths.concat(pathsWithRoots);
} else {
expandedPaths.push(p);
}
});
return expandedPaths;
}
|
[
"function",
"_expandNestedPaths",
"(",
"paths",
")",
"{",
"var",
"expandedPaths",
"=",
"[",
"]",
";",
"_pathsArray",
"(",
"paths",
")",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"p",
".",
"indexOf",
"(",
"'.'",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"pathsWithRoots",
"=",
"p",
".",
"split",
"(",
"'.'",
")",
".",
"map",
"(",
"function",
"(",
"value",
",",
"index",
",",
"array",
")",
"{",
"return",
"array",
".",
"slice",
"(",
"0",
",",
"index",
"+",
"1",
")",
".",
"join",
"(",
"'.'",
")",
";",
"}",
")",
";",
"expandedPaths",
"=",
"expandedPaths",
".",
"concat",
"(",
"pathsWithRoots",
")",
";",
"}",
"else",
"{",
"expandedPaths",
".",
"push",
"(",
"p",
")",
";",
"}",
"}",
")",
";",
"return",
"expandedPaths",
";",
"}"
] |
Expand nested path syntax to include root paths as well. Mainly used for
notifications on key updates, so updates on nested keys will notify root
key, and vice-versa.
Ex: 'user.email' => ['user', 'user.email']
@param {String|String[]} paths
|
[
"Expand",
"nested",
"path",
"syntax",
"to",
"include",
"root",
"paths",
"as",
"well",
".",
"Mainly",
"used",
"for",
"notifications",
"on",
"key",
"updates",
"so",
"updates",
"on",
"nested",
"keys",
"will",
"notify",
"root",
"key",
"and",
"vice",
"-",
"versa",
"."
] |
0c1794e6cfc9d54b79dd843696a3f00360733034
|
https://github.com/vlucas/toystore/blob/0c1794e6cfc9d54b79dd843696a3f00360733034/es5/index.js#L374-L390
|
35,611 |
codedealer/livolo
|
index.js
|
function(remoteID, keycode) {
if (!config.opened && config.pinNumber !== null) this.open(config.pinNumber);
if (!config.opened) throw new Error('Trying to write with no pins opened');
debugMsg("sendButton: remoteID: " + remoteID + " keycode: " + keycode);
// how many times to transmit a command
for (pulse= 0; pulse <= config.repeats; pulse++) {
sendPulse(1); // Start
config.high = true; // first pulse is always high
// transmit remoteID
for (i = 15; i >= 0; i--) {
var txPulse = remoteID & (1 << i); // read bits from remote ID
if (txPulse > 0) {
selectPulse(1);
} else {
selectPulse(0);
}
}
// transmit keycode
for (i = 6; i >= 0; i--)
{
var txPulse = keycode & (1 << i); // read bits from keycode
if (txPulse > 0) {
selectPulse(1);
} else {
selectPulse(0);
}
}
}
rpio.write(config.pinNumber, rpio.LOW);
}
|
javascript
|
function(remoteID, keycode) {
if (!config.opened && config.pinNumber !== null) this.open(config.pinNumber);
if (!config.opened) throw new Error('Trying to write with no pins opened');
debugMsg("sendButton: remoteID: " + remoteID + " keycode: " + keycode);
// how many times to transmit a command
for (pulse= 0; pulse <= config.repeats; pulse++) {
sendPulse(1); // Start
config.high = true; // first pulse is always high
// transmit remoteID
for (i = 15; i >= 0; i--) {
var txPulse = remoteID & (1 << i); // read bits from remote ID
if (txPulse > 0) {
selectPulse(1);
} else {
selectPulse(0);
}
}
// transmit keycode
for (i = 6; i >= 0; i--)
{
var txPulse = keycode & (1 << i); // read bits from keycode
if (txPulse > 0) {
selectPulse(1);
} else {
selectPulse(0);
}
}
}
rpio.write(config.pinNumber, rpio.LOW);
}
|
[
"function",
"(",
"remoteID",
",",
"keycode",
")",
"{",
"if",
"(",
"!",
"config",
".",
"opened",
"&&",
"config",
".",
"pinNumber",
"!==",
"null",
")",
"this",
".",
"open",
"(",
"config",
".",
"pinNumber",
")",
";",
"if",
"(",
"!",
"config",
".",
"opened",
")",
"throw",
"new",
"Error",
"(",
"'Trying to write with no pins opened'",
")",
";",
"debugMsg",
"(",
"\"sendButton: remoteID: \"",
"+",
"remoteID",
"+",
"\" keycode: \"",
"+",
"keycode",
")",
";",
"// how many times to transmit a command",
"for",
"(",
"pulse",
"=",
"0",
";",
"pulse",
"<=",
"config",
".",
"repeats",
";",
"pulse",
"++",
")",
"{",
"sendPulse",
"(",
"1",
")",
";",
"// Start",
"config",
".",
"high",
"=",
"true",
";",
"// first pulse is always high",
"// transmit remoteID",
"for",
"(",
"i",
"=",
"15",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"txPulse",
"=",
"remoteID",
"&",
"(",
"1",
"<<",
"i",
")",
";",
"// read bits from remote ID",
"if",
"(",
"txPulse",
">",
"0",
")",
"{",
"selectPulse",
"(",
"1",
")",
";",
"}",
"else",
"{",
"selectPulse",
"(",
"0",
")",
";",
"}",
"}",
"// transmit keycode",
"for",
"(",
"i",
"=",
"6",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"txPulse",
"=",
"keycode",
"&",
"(",
"1",
"<<",
"i",
")",
";",
"// read bits from keycode",
"if",
"(",
"txPulse",
">",
"0",
")",
"{",
"selectPulse",
"(",
"1",
")",
";",
"}",
"else",
"{",
"selectPulse",
"(",
"0",
")",
";",
"}",
"}",
"}",
"rpio",
".",
"write",
"(",
"config",
".",
"pinNumber",
",",
"rpio",
".",
"LOW",
")",
";",
"}"
] |
emulate key signal
|
[
"emulate",
"key",
"signal"
] |
3e00d5a2414979adc3458b8ff3d5003913635023
|
https://github.com/codedealer/livolo/blob/3e00d5a2414979adc3458b8ff3d5003913635023/index.js#L75-L110
|
|
35,612 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/removeMultiplicationByOne.js
|
removeMultiplicationByOne
|
function removeMultiplicationByOne(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const oneIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '1';
});
if (oneIndex >= 0) {
let newNode = clone(node);
// remove the 1 node
newNode.args.splice(oneIndex, 1);
// if there's only one operand left, there's nothing left to multiply it
// to, so move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_MULTIPLYING_BY_ONE, node, newNode);
}
return Node.Status.noChange(node);
}
|
javascript
|
function removeMultiplicationByOne(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const oneIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '1';
});
if (oneIndex >= 0) {
let newNode = clone(node);
// remove the 1 node
newNode.args.splice(oneIndex, 1);
// if there's only one operand left, there's nothing left to multiply it
// to, so move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_MULTIPLYING_BY_ONE, node, newNode);
}
return Node.Status.noChange(node);
}
|
[
"function",
"removeMultiplicationByOne",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'*'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"const",
"oneIndex",
"=",
"node",
".",
"args",
".",
"findIndex",
"(",
"arg",
"=>",
"{",
"return",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"arg",
")",
"&&",
"arg",
".",
"value",
"===",
"'1'",
";",
"}",
")",
";",
"if",
"(",
"oneIndex",
">=",
"0",
")",
"{",
"let",
"newNode",
"=",
"clone",
"(",
"node",
")",
";",
"// remove the 1 node",
"newNode",
".",
"args",
".",
"splice",
"(",
"oneIndex",
",",
"1",
")",
";",
"// if there's only one operand left, there's nothing left to multiply it",
"// to, so move it up the tree",
"if",
"(",
"newNode",
".",
"args",
".",
"length",
"===",
"1",
")",
"{",
"newNode",
"=",
"newNode",
".",
"args",
"[",
"0",
"]",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"REMOVE_MULTIPLYING_BY_ONE",
",",
"node",
",",
"newNode",
")",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
If `node` is a multiplication node with 1 as one of its operands, remove 1 from the operands list. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"a",
"multiplication",
"node",
"with",
"1",
"as",
"one",
"of",
"its",
"operands",
"remove",
"1",
"from",
"the",
"operands",
"list",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/removeMultiplicationByOne.js#L9-L29
|
35,613 |
metadelta/metadelta
|
packages/solver/lib/util/flattenOperands.js
|
maybeFlattenPolynomialTerm
|
function maybeFlattenPolynomialTerm(node) {
// We recurse on the left side of the tree to find operands so far
const operands = getOperands(node.args[0], '*');
// If the last operand (so far) under * was a constant, then it's a
// polynomial term.
// e.g. 2*5*6x creates a tree where the top node is implicit multiplcation
// and the left branch goes to the tree with 2*5*6, and the right operand
// is the symbol x. We want to check that the last argument on the left (in
// this example 6) is a constant.
const lastOperand = operands.pop();
// in the above example, node.args[1] would be the symbol x
const nextOperand = flattenOperands(node.args[1]);
// a coefficient can be constant or a fraction of constants
if (Node.Type.isConstantOrConstantFraction(lastOperand)) {
// we replace the constant (which we popped) with constant*symbol
operands.push(
Node.Creator.operator('*', [lastOperand, nextOperand], true));
}
// Now we know it isn't a polynomial term, it's just another seperate operand
else {
operands.push(lastOperand);
operands.push(nextOperand);
}
return operands;
}
|
javascript
|
function maybeFlattenPolynomialTerm(node) {
// We recurse on the left side of the tree to find operands so far
const operands = getOperands(node.args[0], '*');
// If the last operand (so far) under * was a constant, then it's a
// polynomial term.
// e.g. 2*5*6x creates a tree where the top node is implicit multiplcation
// and the left branch goes to the tree with 2*5*6, and the right operand
// is the symbol x. We want to check that the last argument on the left (in
// this example 6) is a constant.
const lastOperand = operands.pop();
// in the above example, node.args[1] would be the symbol x
const nextOperand = flattenOperands(node.args[1]);
// a coefficient can be constant or a fraction of constants
if (Node.Type.isConstantOrConstantFraction(lastOperand)) {
// we replace the constant (which we popped) with constant*symbol
operands.push(
Node.Creator.operator('*', [lastOperand, nextOperand], true));
}
// Now we know it isn't a polynomial term, it's just another seperate operand
else {
operands.push(lastOperand);
operands.push(nextOperand);
}
return operands;
}
|
[
"function",
"maybeFlattenPolynomialTerm",
"(",
"node",
")",
"{",
"// We recurse on the left side of the tree to find operands so far",
"const",
"operands",
"=",
"getOperands",
"(",
"node",
".",
"args",
"[",
"0",
"]",
",",
"'*'",
")",
";",
"// If the last operand (so far) under * was a constant, then it's a",
"// polynomial term.",
"// e.g. 2*5*6x creates a tree where the top node is implicit multiplcation",
"// and the left branch goes to the tree with 2*5*6, and the right operand",
"// is the symbol x. We want to check that the last argument on the left (in",
"// this example 6) is a constant.",
"const",
"lastOperand",
"=",
"operands",
".",
"pop",
"(",
")",
";",
"// in the above example, node.args[1] would be the symbol x",
"const",
"nextOperand",
"=",
"flattenOperands",
"(",
"node",
".",
"args",
"[",
"1",
"]",
")",
";",
"// a coefficient can be constant or a fraction of constants",
"if",
"(",
"Node",
".",
"Type",
".",
"isConstantOrConstantFraction",
"(",
"lastOperand",
")",
")",
"{",
"// we replace the constant (which we popped) with constant*symbol",
"operands",
".",
"push",
"(",
"Node",
".",
"Creator",
".",
"operator",
"(",
"'*'",
",",
"[",
"lastOperand",
",",
"nextOperand",
"]",
",",
"true",
")",
")",
";",
"}",
"// Now we know it isn't a polynomial term, it's just another seperate operand",
"else",
"{",
"operands",
".",
"push",
"(",
"lastOperand",
")",
";",
"operands",
".",
"push",
"(",
"nextOperand",
")",
";",
"}",
"return",
"operands",
";",
"}"
] |
Takes a node that might represent a multiplication with a polynomial term and flattens it appropriately so the coefficient and symbol are grouped together. Returns a new list of operands from this node that should be multiplied together.
|
[
"Takes",
"a",
"node",
"that",
"might",
"represent",
"a",
"multiplication",
"with",
"a",
"polynomial",
"term",
"and",
"flattens",
"it",
"appropriately",
"so",
"the",
"coefficient",
"and",
"symbol",
"are",
"grouped",
"together",
".",
"Returns",
"a",
"new",
"list",
"of",
"operands",
"from",
"this",
"node",
"that",
"should",
"be",
"multiplied",
"together",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/flattenOperands.js#L250-L277
|
35,614 |
metadelta/metadelta
|
packages/solver/lib/util/flattenOperands.js
|
flattenDivision
|
function flattenDivision(node) {
// We recurse on the left side of the tree to find operands so far
// Flattening division is always considered part of a bigger picture
// of multiplication, so we get operands with '*'
let operands = getOperands(node.args[0], '*');
if (operands.length === 1) {
node.args[0] = operands.pop();
node.args[1] = flattenOperands(node.args[1]);
operands = [node];
}
else {
// This is the last operand, the term we'll want to add our division to
const numerator = operands.pop();
// This is the denominator of the current division node we're recursing on
const denominator = flattenOperands(node.args[1]);
// Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6
// as an operand - in simplifyDivision.js this is changed to 4/(5*6)
const divisionNode = Node.Creator.operator('/', [numerator, denominator]);
operands.push(divisionNode);
}
return operands;
}
|
javascript
|
function flattenDivision(node) {
// We recurse on the left side of the tree to find operands so far
// Flattening division is always considered part of a bigger picture
// of multiplication, so we get operands with '*'
let operands = getOperands(node.args[0], '*');
if (operands.length === 1) {
node.args[0] = operands.pop();
node.args[1] = flattenOperands(node.args[1]);
operands = [node];
}
else {
// This is the last operand, the term we'll want to add our division to
const numerator = operands.pop();
// This is the denominator of the current division node we're recursing on
const denominator = flattenOperands(node.args[1]);
// Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6
// as an operand - in simplifyDivision.js this is changed to 4/(5*6)
const divisionNode = Node.Creator.operator('/', [numerator, denominator]);
operands.push(divisionNode);
}
return operands;
}
|
[
"function",
"flattenDivision",
"(",
"node",
")",
"{",
"// We recurse on the left side of the tree to find operands so far",
"// Flattening division is always considered part of a bigger picture",
"// of multiplication, so we get operands with '*'",
"let",
"operands",
"=",
"getOperands",
"(",
"node",
".",
"args",
"[",
"0",
"]",
",",
"'*'",
")",
";",
"if",
"(",
"operands",
".",
"length",
"===",
"1",
")",
"{",
"node",
".",
"args",
"[",
"0",
"]",
"=",
"operands",
".",
"pop",
"(",
")",
";",
"node",
".",
"args",
"[",
"1",
"]",
"=",
"flattenOperands",
"(",
"node",
".",
"args",
"[",
"1",
"]",
")",
";",
"operands",
"=",
"[",
"node",
"]",
";",
"}",
"else",
"{",
"// This is the last operand, the term we'll want to add our division to",
"const",
"numerator",
"=",
"operands",
".",
"pop",
"(",
")",
";",
"// This is the denominator of the current division node we're recursing on",
"const",
"denominator",
"=",
"flattenOperands",
"(",
"node",
".",
"args",
"[",
"1",
"]",
")",
";",
"// Note that this means 2 * 3 * 4 / 5 / 6 * 7 will flatten but keep the 4/5/6",
"// as an operand - in simplifyDivision.js this is changed to 4/(5*6)",
"const",
"divisionNode",
"=",
"Node",
".",
"Creator",
".",
"operator",
"(",
"'/'",
",",
"[",
"numerator",
",",
"denominator",
"]",
")",
";",
"operands",
".",
"push",
"(",
"divisionNode",
")",
";",
"}",
"return",
"operands",
";",
"}"
] |
Takes a division node and returns a list of operands If there is multiplication in the numerator, the operands returned are to be multiplied together. Otherwise, a list of length one with just the division node is returned. getOperands might change the operator accordingly.
|
[
"Takes",
"a",
"division",
"node",
"and",
"returns",
"a",
"list",
"of",
"operands",
"If",
"there",
"is",
"multiplication",
"in",
"the",
"numerator",
"the",
"operands",
"returned",
"are",
"to",
"be",
"multiplied",
"together",
".",
"Otherwise",
"a",
"list",
"of",
"length",
"one",
"with",
"just",
"the",
"division",
"node",
"is",
"returned",
".",
"getOperands",
"might",
"change",
"the",
"operator",
"accordingly",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/util/flattenOperands.js#L284-L307
|
35,615 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/removeAdditionOfZero.js
|
removeAdditionOfZero
|
function removeAdditionOfZero(node) {
if (node.op !== '+') {
return Node.Status.noChange(node);
}
const zeroIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '0';
});
let newNode = clone(node);
if (zeroIndex >= 0) {
// remove the 0 node
newNode.args.splice(zeroIndex, 1);
// if there's only one operand left, there's nothing left to add it to,
// so move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_ADDING_ZERO, node, newNode);
}
return Node.Status.noChange(node);
}
|
javascript
|
function removeAdditionOfZero(node) {
if (node.op !== '+') {
return Node.Status.noChange(node);
}
const zeroIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '0';
});
let newNode = clone(node);
if (zeroIndex >= 0) {
// remove the 0 node
newNode.args.splice(zeroIndex, 1);
// if there's only one operand left, there's nothing left to add it to,
// so move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_ADDING_ZERO, node, newNode);
}
return Node.Status.noChange(node);
}
|
[
"function",
"removeAdditionOfZero",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'+'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"const",
"zeroIndex",
"=",
"node",
".",
"args",
".",
"findIndex",
"(",
"arg",
"=>",
"{",
"return",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"arg",
")",
"&&",
"arg",
".",
"value",
"===",
"'0'",
";",
"}",
")",
";",
"let",
"newNode",
"=",
"clone",
"(",
"node",
")",
";",
"if",
"(",
"zeroIndex",
">=",
"0",
")",
"{",
"// remove the 0 node",
"newNode",
".",
"args",
".",
"splice",
"(",
"zeroIndex",
",",
"1",
")",
";",
"// if there's only one operand left, there's nothing left to add it to,",
"// so move it up the tree",
"if",
"(",
"newNode",
".",
"args",
".",
"length",
"===",
"1",
")",
"{",
"newNode",
"=",
"newNode",
".",
"args",
"[",
"0",
"]",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"REMOVE_ADDING_ZERO",
",",
"node",
",",
"newNode",
")",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
If `node` is an addition node with 0 as one of its operands, remove 0 from the operands list. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"an",
"addition",
"node",
"with",
"0",
"as",
"one",
"of",
"its",
"operands",
"remove",
"0",
"from",
"the",
"operands",
"list",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/removeAdditionOfZero.js#L9-L29
|
35,616 |
metadelta/metadelta
|
packages/solver/lib/solveEquation/stepThrough.js
|
step
|
function step(equation, symbolName) {
const solveFunctions = [
// ensure the symbol is always on the left node
EquationOperations.ensureSymbolInLeftNode,
// get rid of denominators that have the symbol
EquationOperations.removeSymbolFromDenominator,
// remove the symbol from the right side
EquationOperations.removeSymbolFromRightSide,
// isolate the symbol on the left side
EquationOperations.isolateSymbolOnLeftSide,
];
for (let i = 0; i < solveFunctions.length; i++) {
const equationStatus = solveFunctions[i](equation, symbolName);
if (equationStatus.hasChanged()) {
return equationStatus;
}
}
return EquationStatus.noChange(equation);
}
|
javascript
|
function step(equation, symbolName) {
const solveFunctions = [
// ensure the symbol is always on the left node
EquationOperations.ensureSymbolInLeftNode,
// get rid of denominators that have the symbol
EquationOperations.removeSymbolFromDenominator,
// remove the symbol from the right side
EquationOperations.removeSymbolFromRightSide,
// isolate the symbol on the left side
EquationOperations.isolateSymbolOnLeftSide,
];
for (let i = 0; i < solveFunctions.length; i++) {
const equationStatus = solveFunctions[i](equation, symbolName);
if (equationStatus.hasChanged()) {
return equationStatus;
}
}
return EquationStatus.noChange(equation);
}
|
[
"function",
"step",
"(",
"equation",
",",
"symbolName",
")",
"{",
"const",
"solveFunctions",
"=",
"[",
"// ensure the symbol is always on the left node",
"EquationOperations",
".",
"ensureSymbolInLeftNode",
",",
"// get rid of denominators that have the symbol",
"EquationOperations",
".",
"removeSymbolFromDenominator",
",",
"// remove the symbol from the right side",
"EquationOperations",
".",
"removeSymbolFromRightSide",
",",
"// isolate the symbol on the left side",
"EquationOperations",
".",
"isolateSymbolOnLeftSide",
",",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"solveFunctions",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"equationStatus",
"=",
"solveFunctions",
"[",
"i",
"]",
"(",
"equation",
",",
"symbolName",
")",
";",
"if",
"(",
"equationStatus",
".",
"hasChanged",
"(",
")",
")",
"{",
"return",
"equationStatus",
";",
"}",
"}",
"return",
"EquationStatus",
".",
"noChange",
"(",
"equation",
")",
";",
"}"
] |
Given a symbol and an equation, performs a single step to solve for the symbol. Returns an Status object.
|
[
"Given",
"a",
"symbol",
"and",
"an",
"equation",
"performs",
"a",
"single",
"step",
"to",
"solve",
"for",
"the",
"symbol",
".",
"Returns",
"an",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/solveEquation/stepThrough.js#L160-L180
|
35,617 |
metadelta/metadelta
|
packages/solver/lib/solveEquation/stepThrough.js
|
addSimplificationSteps
|
function addSimplificationSteps(steps, equation, debug=false) {
let oldEquation = equation.clone();
const leftSteps = simplifyExpressionNode(equation.leftNode, false);
const leftSubSteps = [];
for (let i = 0; i < leftSteps.length; i++) {
const step = leftSteps[i];
leftSubSteps.push(EquationStatus.addLeftStep(equation, step));
}
if (leftSubSteps.length === 1) {
const step = leftSubSteps[0];
step.changeType = ChangeTypes.SIMPLIFY_LEFT_SIDE;
if (debug) {
logSteps(step);
}
steps.push(step);
}
else if (leftSubSteps.length > 1) {
const lastStep = leftSubSteps[leftSubSteps.length - 1];
const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
// no change groups are set here - too much is changing for it to be useful
const simplifyStatus = new EquationStatus(
ChangeTypes.SIMPLIFY_LEFT_SIDE,
oldEquation, finalEquation, leftSubSteps);
if (debug) {
logSteps(step);
}
steps.push(simplifyStatus);
}
// update `equation` to have the new simplified left node
if (steps.length > 0) {
equation = EquationStatus.resetChangeGroups(
steps[steps.length - 1 ].newEquation);
}
// the updated equation from simplifing the left side is the old equation
// (ie the "before" of the before and after) for simplifying the right side.
oldEquation = equation.clone();
const rightSteps = simplifyExpressionNode(equation.rightNode, false);
const rightSubSteps = [];
for (let i = 0; i < rightSteps.length; i++) {
const step = rightSteps[i];
rightSubSteps.push(EquationStatus.addRightStep(equation, step));
}
if (rightSubSteps.length === 1) {
const step = rightSubSteps[0];
step.changeType = ChangeTypes.SIMPLIFY_RIGHT_SIDE;
if (debug) {
logSteps(step);
}
steps.push(step);
}
else if (rightSubSteps.length > 1) {
const lastStep = rightSubSteps[rightSubSteps.length - 1];
const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
// no change groups are set here - too much is changing for it to be useful
const simplifyStatus = new EquationStatus(
ChangeTypes.SIMPLIFY_RIGHT_SIDE,
oldEquation, finalEquation, rightSubSteps);
if (debug) {
logSteps(simplifyStatus);
}
steps.push(simplifyStatus);
}
return steps;
}
|
javascript
|
function addSimplificationSteps(steps, equation, debug=false) {
let oldEquation = equation.clone();
const leftSteps = simplifyExpressionNode(equation.leftNode, false);
const leftSubSteps = [];
for (let i = 0; i < leftSteps.length; i++) {
const step = leftSteps[i];
leftSubSteps.push(EquationStatus.addLeftStep(equation, step));
}
if (leftSubSteps.length === 1) {
const step = leftSubSteps[0];
step.changeType = ChangeTypes.SIMPLIFY_LEFT_SIDE;
if (debug) {
logSteps(step);
}
steps.push(step);
}
else if (leftSubSteps.length > 1) {
const lastStep = leftSubSteps[leftSubSteps.length - 1];
const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
// no change groups are set here - too much is changing for it to be useful
const simplifyStatus = new EquationStatus(
ChangeTypes.SIMPLIFY_LEFT_SIDE,
oldEquation, finalEquation, leftSubSteps);
if (debug) {
logSteps(step);
}
steps.push(simplifyStatus);
}
// update `equation` to have the new simplified left node
if (steps.length > 0) {
equation = EquationStatus.resetChangeGroups(
steps[steps.length - 1 ].newEquation);
}
// the updated equation from simplifing the left side is the old equation
// (ie the "before" of the before and after) for simplifying the right side.
oldEquation = equation.clone();
const rightSteps = simplifyExpressionNode(equation.rightNode, false);
const rightSubSteps = [];
for (let i = 0; i < rightSteps.length; i++) {
const step = rightSteps[i];
rightSubSteps.push(EquationStatus.addRightStep(equation, step));
}
if (rightSubSteps.length === 1) {
const step = rightSubSteps[0];
step.changeType = ChangeTypes.SIMPLIFY_RIGHT_SIDE;
if (debug) {
logSteps(step);
}
steps.push(step);
}
else if (rightSubSteps.length > 1) {
const lastStep = rightSubSteps[rightSubSteps.length - 1];
const finalEquation = EquationStatus.resetChangeGroups(lastStep.newEquation);
// no change groups are set here - too much is changing for it to be useful
const simplifyStatus = new EquationStatus(
ChangeTypes.SIMPLIFY_RIGHT_SIDE,
oldEquation, finalEquation, rightSubSteps);
if (debug) {
logSteps(simplifyStatus);
}
steps.push(simplifyStatus);
}
return steps;
}
|
[
"function",
"addSimplificationSteps",
"(",
"steps",
",",
"equation",
",",
"debug",
"=",
"false",
")",
"{",
"let",
"oldEquation",
"=",
"equation",
".",
"clone",
"(",
")",
";",
"const",
"leftSteps",
"=",
"simplifyExpressionNode",
"(",
"equation",
".",
"leftNode",
",",
"false",
")",
";",
"const",
"leftSubSteps",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"leftSteps",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"step",
"=",
"leftSteps",
"[",
"i",
"]",
";",
"leftSubSteps",
".",
"push",
"(",
"EquationStatus",
".",
"addLeftStep",
"(",
"equation",
",",
"step",
")",
")",
";",
"}",
"if",
"(",
"leftSubSteps",
".",
"length",
"===",
"1",
")",
"{",
"const",
"step",
"=",
"leftSubSteps",
"[",
"0",
"]",
";",
"step",
".",
"changeType",
"=",
"ChangeTypes",
".",
"SIMPLIFY_LEFT_SIDE",
";",
"if",
"(",
"debug",
")",
"{",
"logSteps",
"(",
"step",
")",
";",
"}",
"steps",
".",
"push",
"(",
"step",
")",
";",
"}",
"else",
"if",
"(",
"leftSubSteps",
".",
"length",
">",
"1",
")",
"{",
"const",
"lastStep",
"=",
"leftSubSteps",
"[",
"leftSubSteps",
".",
"length",
"-",
"1",
"]",
";",
"const",
"finalEquation",
"=",
"EquationStatus",
".",
"resetChangeGroups",
"(",
"lastStep",
".",
"newEquation",
")",
";",
"// no change groups are set here - too much is changing for it to be useful",
"const",
"simplifyStatus",
"=",
"new",
"EquationStatus",
"(",
"ChangeTypes",
".",
"SIMPLIFY_LEFT_SIDE",
",",
"oldEquation",
",",
"finalEquation",
",",
"leftSubSteps",
")",
";",
"if",
"(",
"debug",
")",
"{",
"logSteps",
"(",
"step",
")",
";",
"}",
"steps",
".",
"push",
"(",
"simplifyStatus",
")",
";",
"}",
"// update `equation` to have the new simplified left node",
"if",
"(",
"steps",
".",
"length",
">",
"0",
")",
"{",
"equation",
"=",
"EquationStatus",
".",
"resetChangeGroups",
"(",
"steps",
"[",
"steps",
".",
"length",
"-",
"1",
"]",
".",
"newEquation",
")",
";",
"}",
"// the updated equation from simplifing the left side is the old equation",
"// (ie the \"before\" of the before and after) for simplifying the right side.",
"oldEquation",
"=",
"equation",
".",
"clone",
"(",
")",
";",
"const",
"rightSteps",
"=",
"simplifyExpressionNode",
"(",
"equation",
".",
"rightNode",
",",
"false",
")",
";",
"const",
"rightSubSteps",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"rightSteps",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"step",
"=",
"rightSteps",
"[",
"i",
"]",
";",
"rightSubSteps",
".",
"push",
"(",
"EquationStatus",
".",
"addRightStep",
"(",
"equation",
",",
"step",
")",
")",
";",
"}",
"if",
"(",
"rightSubSteps",
".",
"length",
"===",
"1",
")",
"{",
"const",
"step",
"=",
"rightSubSteps",
"[",
"0",
"]",
";",
"step",
".",
"changeType",
"=",
"ChangeTypes",
".",
"SIMPLIFY_RIGHT_SIDE",
";",
"if",
"(",
"debug",
")",
"{",
"logSteps",
"(",
"step",
")",
";",
"}",
"steps",
".",
"push",
"(",
"step",
")",
";",
"}",
"else",
"if",
"(",
"rightSubSteps",
".",
"length",
">",
"1",
")",
"{",
"const",
"lastStep",
"=",
"rightSubSteps",
"[",
"rightSubSteps",
".",
"length",
"-",
"1",
"]",
";",
"const",
"finalEquation",
"=",
"EquationStatus",
".",
"resetChangeGroups",
"(",
"lastStep",
".",
"newEquation",
")",
";",
"// no change groups are set here - too much is changing for it to be useful",
"const",
"simplifyStatus",
"=",
"new",
"EquationStatus",
"(",
"ChangeTypes",
".",
"SIMPLIFY_RIGHT_SIDE",
",",
"oldEquation",
",",
"finalEquation",
",",
"rightSubSteps",
")",
";",
"if",
"(",
"debug",
")",
"{",
"logSteps",
"(",
"simplifyStatus",
")",
";",
"}",
"steps",
".",
"push",
"(",
"simplifyStatus",
")",
";",
"}",
"return",
"steps",
";",
"}"
] |
Simplifies the equation and returns the simplification steps
|
[
"Simplifies",
"the",
"equation",
"and",
"returns",
"the",
"simplification",
"steps"
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/solveEquation/stepThrough.js#L183-L251
|
35,618 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/reduceZeroDividedByAnything.js
|
reduceZeroDividedByAnything
|
function reduceZeroDividedByAnything(node) {
if (node.op !== '/') {
return Node.Status.noChange(node);
}
if (node.args[0].value === '0') {
const newNode = Node.Creator.constant(0);
return Node.Status.nodeChanged(
ChangeTypes.REDUCE_ZERO_NUMERATOR, node, newNode);
}
else {
return Node.Status.noChange(node);
}
}
|
javascript
|
function reduceZeroDividedByAnything(node) {
if (node.op !== '/') {
return Node.Status.noChange(node);
}
if (node.args[0].value === '0') {
const newNode = Node.Creator.constant(0);
return Node.Status.nodeChanged(
ChangeTypes.REDUCE_ZERO_NUMERATOR, node, newNode);
}
else {
return Node.Status.noChange(node);
}
}
|
[
"function",
"reduceZeroDividedByAnything",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'/'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"if",
"(",
"node",
".",
"args",
"[",
"0",
"]",
".",
"value",
"===",
"'0'",
")",
"{",
"const",
"newNode",
"=",
"Node",
".",
"Creator",
".",
"constant",
"(",
"0",
")",
";",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"REDUCE_ZERO_NUMERATOR",
",",
"node",
",",
"newNode",
")",
";",
"}",
"else",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"}"
] |
If `node` is a fraction with 0 as the numerator, reduce the node to 0. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"a",
"fraction",
"with",
"0",
"as",
"the",
"numerator",
"reduce",
"the",
"node",
"to",
"0",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/reduceZeroDividedByAnything.js#L8-L20
|
35,619 |
Corey600/zoodubbo
|
lib/register.js
|
Register
|
function Register(client, path) {
if (!(this instanceof Register)) return new Register(client);
EventEmitter.call(this);
this._client = client;
this._path = path;
// Register status. Supported 'unwatched' / 'pending' / 'watched'.
this._status = 'unwatched';
this._watcher = this._watcher.bind(this);
}
|
javascript
|
function Register(client, path) {
if (!(this instanceof Register)) return new Register(client);
EventEmitter.call(this);
this._client = client;
this._path = path;
// Register status. Supported 'unwatched' / 'pending' / 'watched'.
this._status = 'unwatched';
this._watcher = this._watcher.bind(this);
}
|
[
"function",
"Register",
"(",
"client",
",",
"path",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Register",
")",
")",
"return",
"new",
"Register",
"(",
"client",
")",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_client",
"=",
"client",
";",
"this",
".",
"_path",
"=",
"path",
";",
"// Register status. Supported 'unwatched' / 'pending' / 'watched'.",
"this",
".",
"_status",
"=",
"'unwatched'",
";",
"this",
".",
"_watcher",
"=",
"this",
".",
"_watcher",
".",
"bind",
"(",
"this",
")",
";",
"}"
] |
Constructor of Register.
@param client // The Client instance of zookeeper.
@param path // The path of zookeeper node.
@returns {Register}
@constructor
|
[
"Constructor",
"of",
"Register",
"."
] |
c5700687898c82c18d1326ecaccc33fa20269b72
|
https://github.com/Corey600/zoodubbo/blob/c5700687898c82c18d1326ecaccc33fa20269b72/lib/register.js#L19-L28
|
35,620 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/removeDivisionByOne.js
|
removeDivisionByOne
|
function removeDivisionByOne(node) {
if (node.op !== '/') {
return Node.Status.noChange(node);
}
const denominator = node.args[1];
if (!Node.Type.isConstant(denominator)) {
return Node.Status.noChange(node);
}
let numerator = clone(node.args[0]);
// if denominator is -1, we make the numerator negative
if (parseFloat(denominator.value) === -1) {
// If the numerator was an operation, wrap it in parens before adding -
// to the front.
// e.g. 2+3 / -1 ---> -(2+3)
if (Node.Type.isOperator(numerator)) {
numerator = Node.Creator.parenthesis(numerator);
}
const changeType = Negative.isNegative(numerator) ?
ChangeTypes.RESOLVE_DOUBLE_MINUS :
ChangeTypes.DIVISION_BY_NEGATIVE_ONE;
numerator = Negative.negate(numerator);
return Node.Status.nodeChanged(changeType, node, numerator);
}
else if (parseFloat(denominator.value) === 1) {
return Node.Status.nodeChanged(
ChangeTypes.DIVISION_BY_ONE, node, numerator);
}
else {
return Node.Status.noChange(node);
}
}
|
javascript
|
function removeDivisionByOne(node) {
if (node.op !== '/') {
return Node.Status.noChange(node);
}
const denominator = node.args[1];
if (!Node.Type.isConstant(denominator)) {
return Node.Status.noChange(node);
}
let numerator = clone(node.args[0]);
// if denominator is -1, we make the numerator negative
if (parseFloat(denominator.value) === -1) {
// If the numerator was an operation, wrap it in parens before adding -
// to the front.
// e.g. 2+3 / -1 ---> -(2+3)
if (Node.Type.isOperator(numerator)) {
numerator = Node.Creator.parenthesis(numerator);
}
const changeType = Negative.isNegative(numerator) ?
ChangeTypes.RESOLVE_DOUBLE_MINUS :
ChangeTypes.DIVISION_BY_NEGATIVE_ONE;
numerator = Negative.negate(numerator);
return Node.Status.nodeChanged(changeType, node, numerator);
}
else if (parseFloat(denominator.value) === 1) {
return Node.Status.nodeChanged(
ChangeTypes.DIVISION_BY_ONE, node, numerator);
}
else {
return Node.Status.noChange(node);
}
}
|
[
"function",
"removeDivisionByOne",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'/'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"const",
"denominator",
"=",
"node",
".",
"args",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"denominator",
")",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"let",
"numerator",
"=",
"clone",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
";",
"// if denominator is -1, we make the numerator negative",
"if",
"(",
"parseFloat",
"(",
"denominator",
".",
"value",
")",
"===",
"-",
"1",
")",
"{",
"// If the numerator was an operation, wrap it in parens before adding -",
"// to the front.",
"// e.g. 2+3 / -1 ---> -(2+3)",
"if",
"(",
"Node",
".",
"Type",
".",
"isOperator",
"(",
"numerator",
")",
")",
"{",
"numerator",
"=",
"Node",
".",
"Creator",
".",
"parenthesis",
"(",
"numerator",
")",
";",
"}",
"const",
"changeType",
"=",
"Negative",
".",
"isNegative",
"(",
"numerator",
")",
"?",
"ChangeTypes",
".",
"RESOLVE_DOUBLE_MINUS",
":",
"ChangeTypes",
".",
"DIVISION_BY_NEGATIVE_ONE",
";",
"numerator",
"=",
"Negative",
".",
"negate",
"(",
"numerator",
")",
";",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"changeType",
",",
"node",
",",
"numerator",
")",
";",
"}",
"else",
"if",
"(",
"parseFloat",
"(",
"denominator",
".",
"value",
")",
"===",
"1",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"DIVISION_BY_ONE",
",",
"node",
",",
"numerator",
")",
";",
"}",
"else",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"}"
] |
If `node` is a division operation of something by 1 or -1, we can remove the denominator. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"a",
"division",
"operation",
"of",
"something",
"by",
"1",
"or",
"-",
"1",
"we",
"can",
"remove",
"the",
"denominator",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/removeDivisionByOne.js#L10-L41
|
35,621 |
gunjandatta/sprest-react
|
build/webparts/wp.js
|
function (wp) {
var element = props.onRenderDisplayElement ? props.onRenderDisplayElement(wp) : null;
if (element == null) {
// Default the element
element = props.displayElement ? React.createElement(props.displayElement, { cfg: wp.cfg }) : null;
}
// See if the element exists
if (element) {
// Render the element
react_dom_1.render(React.createElement(Fabric_1.Fabric, null, element), wp.el);
}
}
|
javascript
|
function (wp) {
var element = props.onRenderDisplayElement ? props.onRenderDisplayElement(wp) : null;
if (element == null) {
// Default the element
element = props.displayElement ? React.createElement(props.displayElement, { cfg: wp.cfg }) : null;
}
// See if the element exists
if (element) {
// Render the element
react_dom_1.render(React.createElement(Fabric_1.Fabric, null, element), wp.el);
}
}
|
[
"function",
"(",
"wp",
")",
"{",
"var",
"element",
"=",
"props",
".",
"onRenderDisplayElement",
"?",
"props",
".",
"onRenderDisplayElement",
"(",
"wp",
")",
":",
"null",
";",
"if",
"(",
"element",
"==",
"null",
")",
"{",
"// Default the element",
"element",
"=",
"props",
".",
"displayElement",
"?",
"React",
".",
"createElement",
"(",
"props",
".",
"displayElement",
",",
"{",
"cfg",
":",
"wp",
".",
"cfg",
"}",
")",
":",
"null",
";",
"}",
"// See if the element exists",
"if",
"(",
"element",
")",
"{",
"// Render the element",
"react_dom_1",
".",
"render",
"(",
"React",
".",
"createElement",
"(",
"Fabric_1",
".",
"Fabric",
",",
"null",
",",
"element",
")",
",",
"wp",
".",
"el",
")",
";",
"}",
"}"
] |
The render display component
|
[
"The",
"render",
"display",
"component"
] |
df7c1d7353ec3ad2c66db90f94b5c0054eb13229
|
https://github.com/gunjandatta/sprest-react/blob/df7c1d7353ec3ad2c66db90f94b5c0054eb13229/build/webparts/wp.js#L12-L23
|
|
35,622 |
gunjandatta/sprest-react
|
build/webparts/wp.js
|
function (wp) {
var element = props.onRenderEditElement ? props.onRenderEditElement(wp) : null;
if (element == null) {
// Default the element
element = props.editElement ? React.createElement(props.editElement, { cfg: wp.cfg, cfgElementId: props.cfgElementId }) : null;
}
// See if the element exists
if (element) {
// Render the element
react_dom_1.render(React.createElement(Fabric_1.Fabric, null, element), wp.el);
}
}
|
javascript
|
function (wp) {
var element = props.onRenderEditElement ? props.onRenderEditElement(wp) : null;
if (element == null) {
// Default the element
element = props.editElement ? React.createElement(props.editElement, { cfg: wp.cfg, cfgElementId: props.cfgElementId }) : null;
}
// See if the element exists
if (element) {
// Render the element
react_dom_1.render(React.createElement(Fabric_1.Fabric, null, element), wp.el);
}
}
|
[
"function",
"(",
"wp",
")",
"{",
"var",
"element",
"=",
"props",
".",
"onRenderEditElement",
"?",
"props",
".",
"onRenderEditElement",
"(",
"wp",
")",
":",
"null",
";",
"if",
"(",
"element",
"==",
"null",
")",
"{",
"// Default the element",
"element",
"=",
"props",
".",
"editElement",
"?",
"React",
".",
"createElement",
"(",
"props",
".",
"editElement",
",",
"{",
"cfg",
":",
"wp",
".",
"cfg",
",",
"cfgElementId",
":",
"props",
".",
"cfgElementId",
"}",
")",
":",
"null",
";",
"}",
"// See if the element exists",
"if",
"(",
"element",
")",
"{",
"// Render the element",
"react_dom_1",
".",
"render",
"(",
"React",
".",
"createElement",
"(",
"Fabric_1",
".",
"Fabric",
",",
"null",
",",
"element",
")",
",",
"wp",
".",
"el",
")",
";",
"}",
"}"
] |
The render edit component
|
[
"The",
"render",
"edit",
"component"
] |
df7c1d7353ec3ad2c66db90f94b5c0054eb13229
|
https://github.com/gunjandatta/sprest-react/blob/df7c1d7353ec3ad2c66db90f94b5c0054eb13229/build/webparts/wp.js#L25-L36
|
|
35,623 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/stepThrough.js
|
stepThrough
|
function stepThrough(node, debug=false) {
if (debug) {
// eslint-disable-next-line
console.log('\n\nSimplifying: ' + print(node, false, true));
}
if(checks.hasUnsupportedNodes(node)) {
return [];
}
let nodeStatus;
const steps = [];
const originalExpressionStr = print(node);
const MAX_STEP_COUNT = 20;
let iters = 0;
// Now, step through the math expression until nothing changes
nodeStatus = step(node);
while (nodeStatus.hasChanged()) {
if (debug) {
logSteps(nodeStatus);
}
steps.push(removeUnnecessaryParensInStep(nodeStatus));
const nextNode = Status.resetChangeGroups(nodeStatus.newNode);
nodeStatus = step(nextNode);
if (iters++ === MAX_STEP_COUNT) {
// eslint-disable-next-line
console.error('Math error: Potential infinite loop for expression: ' +
originalExpressionStr + ', returning no steps');
return [];
}
}
return steps;
}
|
javascript
|
function stepThrough(node, debug=false) {
if (debug) {
// eslint-disable-next-line
console.log('\n\nSimplifying: ' + print(node, false, true));
}
if(checks.hasUnsupportedNodes(node)) {
return [];
}
let nodeStatus;
const steps = [];
const originalExpressionStr = print(node);
const MAX_STEP_COUNT = 20;
let iters = 0;
// Now, step through the math expression until nothing changes
nodeStatus = step(node);
while (nodeStatus.hasChanged()) {
if (debug) {
logSteps(nodeStatus);
}
steps.push(removeUnnecessaryParensInStep(nodeStatus));
const nextNode = Status.resetChangeGroups(nodeStatus.newNode);
nodeStatus = step(nextNode);
if (iters++ === MAX_STEP_COUNT) {
// eslint-disable-next-line
console.error('Math error: Potential infinite loop for expression: ' +
originalExpressionStr + ', returning no steps');
return [];
}
}
return steps;
}
|
[
"function",
"stepThrough",
"(",
"node",
",",
"debug",
"=",
"false",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"// eslint-disable-next-line",
"console",
".",
"log",
"(",
"'\\n\\nSimplifying: '",
"+",
"print",
"(",
"node",
",",
"false",
",",
"true",
")",
")",
";",
"}",
"if",
"(",
"checks",
".",
"hasUnsupportedNodes",
"(",
"node",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"let",
"nodeStatus",
";",
"const",
"steps",
"=",
"[",
"]",
";",
"const",
"originalExpressionStr",
"=",
"print",
"(",
"node",
")",
";",
"const",
"MAX_STEP_COUNT",
"=",
"20",
";",
"let",
"iters",
"=",
"0",
";",
"// Now, step through the math expression until nothing changes",
"nodeStatus",
"=",
"step",
"(",
"node",
")",
";",
"while",
"(",
"nodeStatus",
".",
"hasChanged",
"(",
")",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"logSteps",
"(",
"nodeStatus",
")",
";",
"}",
"steps",
".",
"push",
"(",
"removeUnnecessaryParensInStep",
"(",
"nodeStatus",
")",
")",
";",
"const",
"nextNode",
"=",
"Status",
".",
"resetChangeGroups",
"(",
"nodeStatus",
".",
"newNode",
")",
";",
"nodeStatus",
"=",
"step",
"(",
"nextNode",
")",
";",
"if",
"(",
"iters",
"++",
"===",
"MAX_STEP_COUNT",
")",
"{",
"// eslint-disable-next-line",
"console",
".",
"error",
"(",
"'Math error: Potential infinite loop for expression: '",
"+",
"originalExpressionStr",
"+",
"', returning no steps'",
")",
";",
"return",
"[",
"]",
";",
"}",
"}",
"return",
"steps",
";",
"}"
] |
Given a mathjs expression node, steps through simplifying the expression. Returns a list of details about each step.
|
[
"Given",
"a",
"mathjs",
"expression",
"node",
"steps",
"through",
"simplifying",
"the",
"expression",
".",
"Returns",
"a",
"list",
"of",
"details",
"about",
"each",
"step",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/stepThrough.js#L24-L59
|
35,624 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/stepThrough.js
|
step
|
function step(node) {
let nodeStatus;
node = flattenOperands(node);
node = removeUnnecessaryParens(node, true);
const simplificationTreeSearches = [
// Basic simplifications that we always try first e.g. (...)^0 => 1
basicsSearch,
// Simplify any division chains so there's at most one division operation.
// e.g. 2/x/6 -> 2/(x*6) e.g. 2/(x/6) => 2 * 6/x
divisionSearch,
// Adding fractions, cancelling out things in fractions
fractionsSearch,
// e.g. 2 + 2 => 4
arithmeticSearch,
// e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x
// e.g. multiplication: 2x * x * x^2 => 2x^3
collectAndCombineSearch,
// e.g. (2 + x) / 4 => 2/4 + x/4
breakUpNumeratorSearch,
// e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5)
multiplyFractionsSearch,
// e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12
distributeSearch,
// e.g. abs(-4) => 4
functionsSearch,
];
for (let i = 0; i < simplificationTreeSearches.length; i++) {
nodeStatus = simplificationTreeSearches[i](node);
// Always update node, since there might be changes that didn't count as
// a step. Remove unnecessary parens, in case one a step results in more
// parens than needed.
node = removeUnnecessaryParens(nodeStatus.newNode, true);
if (nodeStatus.hasChanged()) {
node = flattenOperands(node);
nodeStatus.newNode = clone(node);
return nodeStatus;
}
else {
node = flattenOperands(node);
}
}
return Node.Status.noChange(node);
}
|
javascript
|
function step(node) {
let nodeStatus;
node = flattenOperands(node);
node = removeUnnecessaryParens(node, true);
const simplificationTreeSearches = [
// Basic simplifications that we always try first e.g. (...)^0 => 1
basicsSearch,
// Simplify any division chains so there's at most one division operation.
// e.g. 2/x/6 -> 2/(x*6) e.g. 2/(x/6) => 2 * 6/x
divisionSearch,
// Adding fractions, cancelling out things in fractions
fractionsSearch,
// e.g. 2 + 2 => 4
arithmeticSearch,
// e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x
// e.g. multiplication: 2x * x * x^2 => 2x^3
collectAndCombineSearch,
// e.g. (2 + x) / 4 => 2/4 + x/4
breakUpNumeratorSearch,
// e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5)
multiplyFractionsSearch,
// e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12
distributeSearch,
// e.g. abs(-4) => 4
functionsSearch,
];
for (let i = 0; i < simplificationTreeSearches.length; i++) {
nodeStatus = simplificationTreeSearches[i](node);
// Always update node, since there might be changes that didn't count as
// a step. Remove unnecessary parens, in case one a step results in more
// parens than needed.
node = removeUnnecessaryParens(nodeStatus.newNode, true);
if (nodeStatus.hasChanged()) {
node = flattenOperands(node);
nodeStatus.newNode = clone(node);
return nodeStatus;
}
else {
node = flattenOperands(node);
}
}
return Node.Status.noChange(node);
}
|
[
"function",
"step",
"(",
"node",
")",
"{",
"let",
"nodeStatus",
";",
"node",
"=",
"flattenOperands",
"(",
"node",
")",
";",
"node",
"=",
"removeUnnecessaryParens",
"(",
"node",
",",
"true",
")",
";",
"const",
"simplificationTreeSearches",
"=",
"[",
"// Basic simplifications that we always try first e.g. (...)^0 => 1",
"basicsSearch",
",",
"// Simplify any division chains so there's at most one division operation.",
"// e.g. 2/x/6 -> 2/(x*6) e.g. 2/(x/6) => 2 * 6/x",
"divisionSearch",
",",
"// Adding fractions, cancelling out things in fractions",
"fractionsSearch",
",",
"// e.g. 2 + 2 => 4",
"arithmeticSearch",
",",
"// e.g. addition: 2x + 4x^2 + x => 4x^2 + 3x",
"// e.g. multiplication: 2x * x * x^2 => 2x^3",
"collectAndCombineSearch",
",",
"// e.g. (2 + x) / 4 => 2/4 + x/4",
"breakUpNumeratorSearch",
",",
"// e.g. 3/x * 2x/5 => (3 * 2x) / (x * 5)",
"multiplyFractionsSearch",
",",
"// e.g. (2x + 3)(x + 4) => 2x^2 + 11x + 12",
"distributeSearch",
",",
"// e.g. abs(-4) => 4",
"functionsSearch",
",",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"simplificationTreeSearches",
".",
"length",
";",
"i",
"++",
")",
"{",
"nodeStatus",
"=",
"simplificationTreeSearches",
"[",
"i",
"]",
"(",
"node",
")",
";",
"// Always update node, since there might be changes that didn't count as",
"// a step. Remove unnecessary parens, in case one a step results in more",
"// parens than needed.",
"node",
"=",
"removeUnnecessaryParens",
"(",
"nodeStatus",
".",
"newNode",
",",
"true",
")",
";",
"if",
"(",
"nodeStatus",
".",
"hasChanged",
"(",
")",
")",
"{",
"node",
"=",
"flattenOperands",
"(",
"node",
")",
";",
"nodeStatus",
".",
"newNode",
"=",
"clone",
"(",
"node",
")",
";",
"return",
"nodeStatus",
";",
"}",
"else",
"{",
"node",
"=",
"flattenOperands",
"(",
"node",
")",
";",
"}",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
Given a mathjs expression node, performs a single step to simplify the expression. Returns a Node.Status object.
|
[
"Given",
"a",
"mathjs",
"expression",
"node",
"performs",
"a",
"single",
"step",
"to",
"simplify",
"the",
"expression",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/stepThrough.js#L63-L108
|
35,625 |
dylansmith/node-exif-renamer
|
lib/exif-renamer.js
|
function(errOrMessage, result) {
var err = (errOrMessage instanceof Error) ? errOrMessage : new Error(errOrMessage);
result = result || {};
result.error = err;
result.status = 'error';
err.result = result;
return err;
}
|
javascript
|
function(errOrMessage, result) {
var err = (errOrMessage instanceof Error) ? errOrMessage : new Error(errOrMessage);
result = result || {};
result.error = err;
result.status = 'error';
err.result = result;
return err;
}
|
[
"function",
"(",
"errOrMessage",
",",
"result",
")",
"{",
"var",
"err",
"=",
"(",
"errOrMessage",
"instanceof",
"Error",
")",
"?",
"errOrMessage",
":",
"new",
"Error",
"(",
"errOrMessage",
")",
";",
"result",
"=",
"result",
"||",
"{",
"}",
";",
"result",
".",
"error",
"=",
"err",
";",
"result",
".",
"status",
"=",
"'error'",
";",
"err",
".",
"result",
"=",
"result",
";",
"return",
"err",
";",
"}"
] |
Generates a standardised Error object
@param {Error|String} errOrMessage
@param {Object} result
@return {Error}
|
[
"Generates",
"a",
"standardised",
"Error",
"object"
] |
47da224c84dc5d28d74877d6ef07c1c995ffc03c
|
https://github.com/dylansmith/node-exif-renamer/blob/47da224c84dc5d28d74877d6ef07c1c995ffc03c/lib/exif-renamer.js#L57-L64
|
|
35,626 |
dylansmith/node-exif-renamer
|
lib/exif-renamer.js
|
function(filepath, index) {
index = index || 1;
var params = this.get_path_info(filepath);
params.index = index;
var newpath = Handlebars.compile(this.config.sequential_template)(params);
return (fs.existsSync(newpath)) ? this.get_sequential_filepath(filepath, index + 1) : newpath;
}
|
javascript
|
function(filepath, index) {
index = index || 1;
var params = this.get_path_info(filepath);
params.index = index;
var newpath = Handlebars.compile(this.config.sequential_template)(params);
return (fs.existsSync(newpath)) ? this.get_sequential_filepath(filepath, index + 1) : newpath;
}
|
[
"function",
"(",
"filepath",
",",
"index",
")",
"{",
"index",
"=",
"index",
"||",
"1",
";",
"var",
"params",
"=",
"this",
".",
"get_path_info",
"(",
"filepath",
")",
";",
"params",
".",
"index",
"=",
"index",
";",
"var",
"newpath",
"=",
"Handlebars",
".",
"compile",
"(",
"this",
".",
"config",
".",
"sequential_template",
")",
"(",
"params",
")",
";",
"return",
"(",
"fs",
".",
"existsSync",
"(",
"newpath",
")",
")",
"?",
"this",
".",
"get_sequential_filepath",
"(",
"filepath",
",",
"index",
"+",
"1",
")",
":",
"newpath",
";",
"}"
] |
Returns the next available sequential filename for a given conflicting filepath
@param {String} filepath
@return {String}
|
[
"Returns",
"the",
"next",
"available",
"sequential",
"filename",
"for",
"a",
"given",
"conflicting",
"filepath"
] |
47da224c84dc5d28d74877d6ef07c1c995ffc03c
|
https://github.com/dylansmith/node-exif-renamer/blob/47da224c84dc5d28d74877d6ef07c1c995ffc03c/lib/exif-renamer.js#L199-L205
|
|
35,627 |
YR/express-client
|
src/lib/history.js
|
sameOrigin
|
function sameOrigin(url) {
let origin = `${location.protocol}//${location.hostname}`;
if (location.port) {
origin += `:${location.port}`;
}
return url && url.indexOf(origin) === 0;
}
|
javascript
|
function sameOrigin(url) {
let origin = `${location.protocol}//${location.hostname}`;
if (location.port) {
origin += `:${location.port}`;
}
return url && url.indexOf(origin) === 0;
}
|
[
"function",
"sameOrigin",
"(",
"url",
")",
"{",
"let",
"origin",
"=",
"`",
"${",
"location",
".",
"protocol",
"}",
"${",
"location",
".",
"hostname",
"}",
"`",
";",
"if",
"(",
"location",
".",
"port",
")",
"{",
"origin",
"+=",
"`",
"${",
"location",
".",
"port",
"}",
"`",
";",
"}",
"return",
"url",
"&&",
"url",
".",
"indexOf",
"(",
"origin",
")",
"===",
"0",
";",
"}"
] |
Check if 'url' is from same origin
@param {String} url
@returns {Boolean}
|
[
"Check",
"if",
"url",
"is",
"from",
"same",
"origin"
] |
784fb68453dd57dc24a42ce4ae439c4e77886115
|
https://github.com/YR/express-client/blob/784fb68453dd57dc24a42ce4ae439c4e77886115/src/lib/history.js#L301-L308
|
35,628 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/collectAndCombineSearch/addLikeTerms.js
|
addLikeTerms
|
function addLikeTerms(node, polynomialOnly=false) {
if (!Node.Type.isOperator(node)) {
return Node.Status.noChange(node);
}
let status;
if (!polynomialOnly) {
status = evaluateConstantSum(node);
if (status.hasChanged()) {
return status;
}
}
status = addLikePolynomialTerms(node);
if (status.hasChanged()) {
return status;
}
return Node.Status.noChange(node);
}
|
javascript
|
function addLikeTerms(node, polynomialOnly=false) {
if (!Node.Type.isOperator(node)) {
return Node.Status.noChange(node);
}
let status;
if (!polynomialOnly) {
status = evaluateConstantSum(node);
if (status.hasChanged()) {
return status;
}
}
status = addLikePolynomialTerms(node);
if (status.hasChanged()) {
return status;
}
return Node.Status.noChange(node);
}
|
[
"function",
"addLikeTerms",
"(",
"node",
",",
"polynomialOnly",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"Node",
".",
"Type",
".",
"isOperator",
"(",
"node",
")",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"let",
"status",
";",
"if",
"(",
"!",
"polynomialOnly",
")",
"{",
"status",
"=",
"evaluateConstantSum",
"(",
"node",
")",
";",
"if",
"(",
"status",
".",
"hasChanged",
"(",
")",
")",
"{",
"return",
"status",
";",
"}",
"}",
"status",
"=",
"addLikePolynomialTerms",
"(",
"node",
")",
";",
"if",
"(",
"status",
".",
"hasChanged",
"(",
")",
")",
"{",
"return",
"status",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
Adds a list of nodes that are polynomial terms. Returns a Node.Status object.
|
[
"Adds",
"a",
"list",
"of",
"nodes",
"that",
"are",
"polynomial",
"terms",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/collectAndCombineSearch/addLikeTerms.js#L10-L29
|
35,629 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/simplify.js
|
simplify
|
function simplify(node, debug=false) {
if(checks.hasUnsupportedNodes(node)) {
return node;
}
const steps = stepThrough(node, debug);
let simplifiedNode;
if (steps.length > 0) {
simplifiedNode = steps.pop().newNode;
}
else {
// removing parens isn't counted as a step, so try it here
simplifiedNode = removeUnnecessaryParens(flattenOperands(node), true);
}
// unflatten the node.
return unflatten(simplifiedNode);
}
|
javascript
|
function simplify(node, debug=false) {
if(checks.hasUnsupportedNodes(node)) {
return node;
}
const steps = stepThrough(node, debug);
let simplifiedNode;
if (steps.length > 0) {
simplifiedNode = steps.pop().newNode;
}
else {
// removing parens isn't counted as a step, so try it here
simplifiedNode = removeUnnecessaryParens(flattenOperands(node), true);
}
// unflatten the node.
return unflatten(simplifiedNode);
}
|
[
"function",
"simplify",
"(",
"node",
",",
"debug",
"=",
"false",
")",
"{",
"if",
"(",
"checks",
".",
"hasUnsupportedNodes",
"(",
"node",
")",
")",
"{",
"return",
"node",
";",
"}",
"const",
"steps",
"=",
"stepThrough",
"(",
"node",
",",
"debug",
")",
";",
"let",
"simplifiedNode",
";",
"if",
"(",
"steps",
".",
"length",
">",
"0",
")",
"{",
"simplifiedNode",
"=",
"steps",
".",
"pop",
"(",
")",
".",
"newNode",
";",
"}",
"else",
"{",
"// removing parens isn't counted as a step, so try it here",
"simplifiedNode",
"=",
"removeUnnecessaryParens",
"(",
"flattenOperands",
"(",
"node",
")",
",",
"true",
")",
";",
"}",
"// unflatten the node.",
"return",
"unflatten",
"(",
"simplifiedNode",
")",
";",
"}"
] |
Given a mathjs expression node, steps through simplifying the expression. Returns the simplified expression node.
|
[
"Given",
"a",
"mathjs",
"expression",
"node",
"steps",
"through",
"simplifying",
"the",
"expression",
".",
"Returns",
"the",
"simplified",
"expression",
"node",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/simplify.js#L14-L30
|
35,630 |
solderjs/osx-wifi-volume-remote
|
lib/osascript-vol-ctrl.js
|
get
|
function get(cb) {
getRaw(function (err, num, muted) {
timeouts.push(setTimeout(function () {
cb(err, num, muted);
}), 0);
});
}
|
javascript
|
function get(cb) {
getRaw(function (err, num, muted) {
timeouts.push(setTimeout(function () {
cb(err, num, muted);
}), 0);
});
}
|
[
"function",
"get",
"(",
"cb",
")",
"{",
"getRaw",
"(",
"function",
"(",
"err",
",",
"num",
",",
"muted",
")",
"{",
"timeouts",
".",
"push",
"(",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"cb",
"(",
"err",
",",
"num",
",",
"muted",
")",
";",
"}",
")",
",",
"0",
")",
";",
"}",
")",
";",
"}"
] |
get pushes a timeout, which makes it get cancelled
|
[
"get",
"pushes",
"a",
"timeout",
"which",
"makes",
"it",
"get",
"cancelled"
] |
a0d1fabb3e76d5fbc1b8fc41ee7b3fb68f2a7899
|
https://github.com/solderjs/osx-wifi-volume-remote/blob/a0d1fabb3e76d5fbc1b8fc41ee7b3fb68f2a7899/lib/osascript-vol-ctrl.js#L112-L118
|
35,631 |
mikolalysenko/dynamic-forest
|
dgraph.js
|
raiseLevel
|
function raiseLevel(edge) {
var s = edge.s
var t = edge.t
//Update position in edge lists
removeEdge(s, edge)
removeEdge(t, edge)
edge.level += 1
elist.insert(s.adjacent, edge)
elist.insert(t.adjacent, edge)
//Update flags for s
if(s.euler.length <= edge.level) {
s.euler.push(createEulerVertex(s))
}
var es = s.euler[edge.level]
es.setFlag(true)
//Update flags for t
if(t.euler.length <= edge.level) {
t.euler.push(createEulerVertex(t))
}
var et = t.euler[edge.level]
et.setFlag(true)
//Relink if necessary
if(edge.euler) {
edge.euler.push(es.link(et, edge))
}
}
|
javascript
|
function raiseLevel(edge) {
var s = edge.s
var t = edge.t
//Update position in edge lists
removeEdge(s, edge)
removeEdge(t, edge)
edge.level += 1
elist.insert(s.adjacent, edge)
elist.insert(t.adjacent, edge)
//Update flags for s
if(s.euler.length <= edge.level) {
s.euler.push(createEulerVertex(s))
}
var es = s.euler[edge.level]
es.setFlag(true)
//Update flags for t
if(t.euler.length <= edge.level) {
t.euler.push(createEulerVertex(t))
}
var et = t.euler[edge.level]
et.setFlag(true)
//Relink if necessary
if(edge.euler) {
edge.euler.push(es.link(et, edge))
}
}
|
[
"function",
"raiseLevel",
"(",
"edge",
")",
"{",
"var",
"s",
"=",
"edge",
".",
"s",
"var",
"t",
"=",
"edge",
".",
"t",
"//Update position in edge lists",
"removeEdge",
"(",
"s",
",",
"edge",
")",
"removeEdge",
"(",
"t",
",",
"edge",
")",
"edge",
".",
"level",
"+=",
"1",
"elist",
".",
"insert",
"(",
"s",
".",
"adjacent",
",",
"edge",
")",
"elist",
".",
"insert",
"(",
"t",
".",
"adjacent",
",",
"edge",
")",
"//Update flags for s",
"if",
"(",
"s",
".",
"euler",
".",
"length",
"<=",
"edge",
".",
"level",
")",
"{",
"s",
".",
"euler",
".",
"push",
"(",
"createEulerVertex",
"(",
"s",
")",
")",
"}",
"var",
"es",
"=",
"s",
".",
"euler",
"[",
"edge",
".",
"level",
"]",
"es",
".",
"setFlag",
"(",
"true",
")",
"//Update flags for t",
"if",
"(",
"t",
".",
"euler",
".",
"length",
"<=",
"edge",
".",
"level",
")",
"{",
"t",
".",
"euler",
".",
"push",
"(",
"createEulerVertex",
"(",
"t",
")",
")",
"}",
"var",
"et",
"=",
"t",
".",
"euler",
"[",
"edge",
".",
"level",
"]",
"et",
".",
"setFlag",
"(",
"true",
")",
"//Relink if necessary",
"if",
"(",
"edge",
".",
"euler",
")",
"{",
"edge",
".",
"euler",
".",
"push",
"(",
"es",
".",
"link",
"(",
"et",
",",
"edge",
")",
")",
"}",
"}"
] |
Raise the level of an edge, optionally inserting into higher level trees
|
[
"Raise",
"the",
"level",
"of",
"an",
"edge",
"optionally",
"inserting",
"into",
"higher",
"level",
"trees"
] |
321072cb8372961c0485bd86f6b5823325d7463b
|
https://github.com/mikolalysenko/dynamic-forest/blob/321072cb8372961c0485bd86f6b5823325d7463b/dgraph.js#L13-L42
|
35,632 |
mikolalysenko/dynamic-forest
|
dgraph.js
|
removeEdge
|
function removeEdge(vertex, edge) {
var adj = vertex.adjacent
var idx = elist.index(adj, edge)
adj.splice(idx, 1)
//Check if flag needs to be updated
if(!((idx < adj.length && adj[idx].level === edge.level) ||
(idx > 0 && adj[idx-1].level === edge.level))) {
vertex.euler[edge.level].setFlag(false)
}
}
|
javascript
|
function removeEdge(vertex, edge) {
var adj = vertex.adjacent
var idx = elist.index(adj, edge)
adj.splice(idx, 1)
//Check if flag needs to be updated
if(!((idx < adj.length && adj[idx].level === edge.level) ||
(idx > 0 && adj[idx-1].level === edge.level))) {
vertex.euler[edge.level].setFlag(false)
}
}
|
[
"function",
"removeEdge",
"(",
"vertex",
",",
"edge",
")",
"{",
"var",
"adj",
"=",
"vertex",
".",
"adjacent",
"var",
"idx",
"=",
"elist",
".",
"index",
"(",
"adj",
",",
"edge",
")",
"adj",
".",
"splice",
"(",
"idx",
",",
"1",
")",
"//Check if flag needs to be updated",
"if",
"(",
"!",
"(",
"(",
"idx",
"<",
"adj",
".",
"length",
"&&",
"adj",
"[",
"idx",
"]",
".",
"level",
"===",
"edge",
".",
"level",
")",
"||",
"(",
"idx",
">",
"0",
"&&",
"adj",
"[",
"idx",
"-",
"1",
"]",
".",
"level",
"===",
"edge",
".",
"level",
")",
")",
")",
"{",
"vertex",
".",
"euler",
"[",
"edge",
".",
"level",
"]",
".",
"setFlag",
"(",
"false",
")",
"}",
"}"
] |
Remove edge from list and update flags
|
[
"Remove",
"edge",
"from",
"list",
"and",
"update",
"flags"
] |
321072cb8372961c0485bd86f6b5823325d7463b
|
https://github.com/mikolalysenko/dynamic-forest/blob/321072cb8372961c0485bd86f6b5823325d7463b/dgraph.js#L45-L54
|
35,633 |
mikolalysenko/dynamic-forest
|
dgraph.js
|
link
|
function link(edge) {
var es = edge.s.euler
var et = edge.t.euler
var euler = new Array(edge.level+1)
for(var i=0; i<euler.length; ++i) {
if(es.length <= i) {
es.push(createEulerVertex(edge.s))
}
if(et.length <= i) {
et.push(createEulerVertex(edge.t))
}
euler[i] = es[i].link(et[i], edge)
}
edge.euler = euler
}
|
javascript
|
function link(edge) {
var es = edge.s.euler
var et = edge.t.euler
var euler = new Array(edge.level+1)
for(var i=0; i<euler.length; ++i) {
if(es.length <= i) {
es.push(createEulerVertex(edge.s))
}
if(et.length <= i) {
et.push(createEulerVertex(edge.t))
}
euler[i] = es[i].link(et[i], edge)
}
edge.euler = euler
}
|
[
"function",
"link",
"(",
"edge",
")",
"{",
"var",
"es",
"=",
"edge",
".",
"s",
".",
"euler",
"var",
"et",
"=",
"edge",
".",
"t",
".",
"euler",
"var",
"euler",
"=",
"new",
"Array",
"(",
"edge",
".",
"level",
"+",
"1",
")",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"euler",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"es",
".",
"length",
"<=",
"i",
")",
"{",
"es",
".",
"push",
"(",
"createEulerVertex",
"(",
"edge",
".",
"s",
")",
")",
"}",
"if",
"(",
"et",
".",
"length",
"<=",
"i",
")",
"{",
"et",
".",
"push",
"(",
"createEulerVertex",
"(",
"edge",
".",
"t",
")",
")",
"}",
"euler",
"[",
"i",
"]",
"=",
"es",
"[",
"i",
"]",
".",
"link",
"(",
"et",
"[",
"i",
"]",
",",
"edge",
")",
"}",
"edge",
".",
"euler",
"=",
"euler",
"}"
] |
Add an edge to all spanning forests with level <= edge.level
|
[
"Add",
"an",
"edge",
"to",
"all",
"spanning",
"forests",
"with",
"level",
"<",
"=",
"edge",
".",
"level"
] |
321072cb8372961c0485bd86f6b5823325d7463b
|
https://github.com/mikolalysenko/dynamic-forest/blob/321072cb8372961c0485bd86f6b5823325d7463b/dgraph.js#L57-L71
|
35,634 |
mikolalysenko/dynamic-forest
|
dgraph.js
|
visit
|
function visit(node) {
if(node.flag) {
var v = node.value.value
var adj = v.adjacent
for(var ptr=elist.level(adj, level); ptr<adj.length && adj[ptr].level === level; ++ptr) {
var e = adj[ptr]
var es = e.s
var et = e.t
if(es.euler[level].path(et.euler[level])) {
raiseLevel(e)
ptr -= 1
} else {
//Found the edge, relink components
link(e)
return true
}
}
}
if(node.left && node.left.flagAggregate) {
if(visit(node.left)) {
return true
}
}
if(node.right && node.right.flagAggregate) {
if(visit(node.right)) {
return true
}
}
return false
}
|
javascript
|
function visit(node) {
if(node.flag) {
var v = node.value.value
var adj = v.adjacent
for(var ptr=elist.level(adj, level); ptr<adj.length && adj[ptr].level === level; ++ptr) {
var e = adj[ptr]
var es = e.s
var et = e.t
if(es.euler[level].path(et.euler[level])) {
raiseLevel(e)
ptr -= 1
} else {
//Found the edge, relink components
link(e)
return true
}
}
}
if(node.left && node.left.flagAggregate) {
if(visit(node.left)) {
return true
}
}
if(node.right && node.right.flagAggregate) {
if(visit(node.right)) {
return true
}
}
return false
}
|
[
"function",
"visit",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"flag",
")",
"{",
"var",
"v",
"=",
"node",
".",
"value",
".",
"value",
"var",
"adj",
"=",
"v",
".",
"adjacent",
"for",
"(",
"var",
"ptr",
"=",
"elist",
".",
"level",
"(",
"adj",
",",
"level",
")",
";",
"ptr",
"<",
"adj",
".",
"length",
"&&",
"adj",
"[",
"ptr",
"]",
".",
"level",
"===",
"level",
";",
"++",
"ptr",
")",
"{",
"var",
"e",
"=",
"adj",
"[",
"ptr",
"]",
"var",
"es",
"=",
"e",
".",
"s",
"var",
"et",
"=",
"e",
".",
"t",
"if",
"(",
"es",
".",
"euler",
"[",
"level",
"]",
".",
"path",
"(",
"et",
".",
"euler",
"[",
"level",
"]",
")",
")",
"{",
"raiseLevel",
"(",
"e",
")",
"ptr",
"-=",
"1",
"}",
"else",
"{",
"//Found the edge, relink components",
"link",
"(",
"e",
")",
"return",
"true",
"}",
"}",
"}",
"if",
"(",
"node",
".",
"left",
"&&",
"node",
".",
"left",
".",
"flagAggregate",
")",
"{",
"if",
"(",
"visit",
"(",
"node",
".",
"left",
")",
")",
"{",
"return",
"true",
"}",
"}",
"if",
"(",
"node",
".",
"right",
"&&",
"node",
".",
"right",
".",
"flagAggregate",
")",
"{",
"if",
"(",
"visit",
"(",
"node",
".",
"right",
")",
")",
"{",
"return",
"true",
"}",
"}",
"return",
"false",
"}"
] |
Search over tv for edge connecting to tw
|
[
"Search",
"over",
"tv",
"for",
"edge",
"connecting",
"to",
"tw"
] |
321072cb8372961c0485bd86f6b5823325d7463b
|
https://github.com/mikolalysenko/dynamic-forest/blob/321072cb8372961c0485bd86f6b5823325d7463b/dgraph.js#L97-L126
|
35,635 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/removeMultiplicationByNegativeOne.js
|
removeMultiplicationByNegativeOne
|
function removeMultiplicationByNegativeOne(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const minusOneIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '-1';
});
if (minusOneIndex < 0) {
return Node.Status.noChange(node);
}
// We might merge/combine the negative one into another node. This stores
// the index of that other node in the arg list.
let nodeToCombineIndex;
// If minus one is the last term, maybe combine with the term before
if (minusOneIndex + 1 === node.args.length) {
nodeToCombineIndex = minusOneIndex - 1;
}
else {
nodeToCombineIndex = minusOneIndex + 1;
}
let nodeToCombine = node.args[nodeToCombineIndex];
// If it's a constant, the combining of those terms is handled elsewhere.
if (Node.Type.isConstant(nodeToCombine)) {
return Node.Status.noChange(node);
}
let newNode = clone(node);
// Get rid of the -1
nodeToCombine = Negative.negate(clone(nodeToCombine));
// replace the node next to -1 and remove -1
newNode.args[nodeToCombineIndex] = nodeToCombine;
newNode.args.splice(minusOneIndex, 1);
// if there's only one operand left, move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_MULTIPLYING_BY_NEGATIVE_ONE, node, newNode);
}
|
javascript
|
function removeMultiplicationByNegativeOne(node) {
if (node.op !== '*') {
return Node.Status.noChange(node);
}
const minusOneIndex = node.args.findIndex(arg => {
return Node.Type.isConstant(arg) && arg.value === '-1';
});
if (minusOneIndex < 0) {
return Node.Status.noChange(node);
}
// We might merge/combine the negative one into another node. This stores
// the index of that other node in the arg list.
let nodeToCombineIndex;
// If minus one is the last term, maybe combine with the term before
if (minusOneIndex + 1 === node.args.length) {
nodeToCombineIndex = minusOneIndex - 1;
}
else {
nodeToCombineIndex = minusOneIndex + 1;
}
let nodeToCombine = node.args[nodeToCombineIndex];
// If it's a constant, the combining of those terms is handled elsewhere.
if (Node.Type.isConstant(nodeToCombine)) {
return Node.Status.noChange(node);
}
let newNode = clone(node);
// Get rid of the -1
nodeToCombine = Negative.negate(clone(nodeToCombine));
// replace the node next to -1 and remove -1
newNode.args[nodeToCombineIndex] = nodeToCombine;
newNode.args.splice(minusOneIndex, 1);
// if there's only one operand left, move it up the tree
if (newNode.args.length === 1) {
newNode = newNode.args[0];
}
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_MULTIPLYING_BY_NEGATIVE_ONE, node, newNode);
}
|
[
"function",
"removeMultiplicationByNegativeOne",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"!==",
"'*'",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"const",
"minusOneIndex",
"=",
"node",
".",
"args",
".",
"findIndex",
"(",
"arg",
"=>",
"{",
"return",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"arg",
")",
"&&",
"arg",
".",
"value",
"===",
"'-1'",
";",
"}",
")",
";",
"if",
"(",
"minusOneIndex",
"<",
"0",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"// We might merge/combine the negative one into another node. This stores",
"// the index of that other node in the arg list.",
"let",
"nodeToCombineIndex",
";",
"// If minus one is the last term, maybe combine with the term before",
"if",
"(",
"minusOneIndex",
"+",
"1",
"===",
"node",
".",
"args",
".",
"length",
")",
"{",
"nodeToCombineIndex",
"=",
"minusOneIndex",
"-",
"1",
";",
"}",
"else",
"{",
"nodeToCombineIndex",
"=",
"minusOneIndex",
"+",
"1",
";",
"}",
"let",
"nodeToCombine",
"=",
"node",
".",
"args",
"[",
"nodeToCombineIndex",
"]",
";",
"// If it's a constant, the combining of those terms is handled elsewhere.",
"if",
"(",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"nodeToCombine",
")",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"let",
"newNode",
"=",
"clone",
"(",
"node",
")",
";",
"// Get rid of the -1",
"nodeToCombine",
"=",
"Negative",
".",
"negate",
"(",
"clone",
"(",
"nodeToCombine",
")",
")",
";",
"// replace the node next to -1 and remove -1",
"newNode",
".",
"args",
"[",
"nodeToCombineIndex",
"]",
"=",
"nodeToCombine",
";",
"newNode",
".",
"args",
".",
"splice",
"(",
"minusOneIndex",
",",
"1",
")",
";",
"// if there's only one operand left, move it up the tree",
"if",
"(",
"newNode",
".",
"args",
".",
"length",
"===",
"1",
")",
"{",
"newNode",
"=",
"newNode",
".",
"args",
"[",
"0",
"]",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"REMOVE_MULTIPLYING_BY_NEGATIVE_ONE",
",",
"node",
",",
"newNode",
")",
";",
"}"
] |
If `node` is a multiplication node with -1 as one of its operands, and a non constant as the next operand, remove -1 from the operands list and make the next term have a unary minus. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"a",
"multiplication",
"node",
"with",
"-",
"1",
"as",
"one",
"of",
"its",
"operands",
"and",
"a",
"non",
"constant",
"as",
"the",
"next",
"operand",
"remove",
"-",
"1",
"from",
"the",
"operands",
"list",
"and",
"make",
"the",
"next",
"term",
"have",
"a",
"unary",
"minus",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/removeMultiplicationByNegativeOne.js#L12-L55
|
35,636 |
metadelta/metadelta
|
packages/solver/lib/Symbols.js
|
isSymbolTerm
|
function isSymbolTerm(node, symbolName) {
if (Node.PolynomialTerm.isPolynomialTerm(node)) {
const polyTerm = new Node.PolynomialTerm(node);
if (polyTerm.getSymbolName() === symbolName) {
return true;
}
}
return false;
}
|
javascript
|
function isSymbolTerm(node, symbolName) {
if (Node.PolynomialTerm.isPolynomialTerm(node)) {
const polyTerm = new Node.PolynomialTerm(node);
if (polyTerm.getSymbolName() === symbolName) {
return true;
}
}
return false;
}
|
[
"function",
"isSymbolTerm",
"(",
"node",
",",
"symbolName",
")",
"{",
"if",
"(",
"Node",
".",
"PolynomialTerm",
".",
"isPolynomialTerm",
"(",
"node",
")",
")",
"{",
"const",
"polyTerm",
"=",
"new",
"Node",
".",
"PolynomialTerm",
"(",
"node",
")",
";",
"if",
"(",
"polyTerm",
".",
"getSymbolName",
"(",
")",
"===",
"symbolName",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns if `node` is a polynomial term with symbol `symbolName`
|
[
"Returns",
"if",
"node",
"is",
"a",
"polynomial",
"term",
"with",
"symbol",
"symbolName"
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/Symbols.js#L67-L75
|
35,637 |
Corey600/zoodubbo
|
index.js
|
ZD
|
function ZD(conf) {
if (!(this instanceof ZD)) return new ZD(conf);
var config = ('string' === typeof conf) ? { conn: conf } : (conf || {});
this.dubbo = config.dubbo;
this.client = zookeeper.createClient(config.conn, {
sessionTimeout: config.sessionTimeout,
spinDelay: config.spinDelay,
retries: config.retries
});
}
|
javascript
|
function ZD(conf) {
if (!(this instanceof ZD)) return new ZD(conf);
var config = ('string' === typeof conf) ? { conn: conf } : (conf || {});
this.dubbo = config.dubbo;
this.client = zookeeper.createClient(config.conn, {
sessionTimeout: config.sessionTimeout,
spinDelay: config.spinDelay,
retries: config.retries
});
}
|
[
"function",
"ZD",
"(",
"conf",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ZD",
")",
")",
"return",
"new",
"ZD",
"(",
"conf",
")",
";",
"var",
"config",
"=",
"(",
"'string'",
"===",
"typeof",
"conf",
")",
"?",
"{",
"conn",
":",
"conf",
"}",
":",
"(",
"conf",
"||",
"{",
"}",
")",
";",
"this",
".",
"dubbo",
"=",
"config",
".",
"dubbo",
";",
"this",
".",
"client",
"=",
"zookeeper",
".",
"createClient",
"(",
"config",
".",
"conn",
",",
"{",
"sessionTimeout",
":",
"config",
".",
"sessionTimeout",
",",
"spinDelay",
":",
"config",
".",
"spinDelay",
",",
"retries",
":",
"config",
".",
"retries",
"}",
")",
";",
"}"
] |
Constructor of ZD.
@param {String|Object} conf // A String of host:port pairs or an object to set options.
{
dubbo: String // Dubbo version information.
// The following content could reference:
// https://github.com/alexguan/node-zookeeper-client#client-createclientconnectionstring-options
conn: String, // Comma separated host:port pairs, each represents a ZooKeeper server
sessionTimeout: Number, // Session timeout in milliseconds, defaults to 30 seconds.
spinDelay: Number, // The delay (in milliseconds) between each connection attempts.
retries: Number // The number of retry attempts for connection loss exception.
}
@returns {ZD}
@constructor
|
[
"Constructor",
"of",
"ZD",
"."
] |
c5700687898c82c18d1326ecaccc33fa20269b72
|
https://github.com/Corey600/zoodubbo/blob/c5700687898c82c18d1326ecaccc33fa20269b72/index.js#L31-L40
|
35,638 |
telegraph/trello-client
|
lib/trello.js
|
validateConfig
|
function validateConfig(config){
let errors = [];
if( !config.key ){
errors.push('Missing config \'config.key\' - Undefined Trello Key');
}
if( !config.token ){
errors.push('Missing config \'config.token\' - Undefined Trello Token');
}
return errors;
}
|
javascript
|
function validateConfig(config){
let errors = [];
if( !config.key ){
errors.push('Missing config \'config.key\' - Undefined Trello Key');
}
if( !config.token ){
errors.push('Missing config \'config.token\' - Undefined Trello Token');
}
return errors;
}
|
[
"function",
"validateConfig",
"(",
"config",
")",
"{",
"let",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"config",
".",
"key",
")",
"{",
"errors",
".",
"push",
"(",
"'Missing config \\'config.key\\' - Undefined Trello Key'",
")",
";",
"}",
"if",
"(",
"!",
"config",
".",
"token",
")",
"{",
"errors",
".",
"push",
"(",
"'Missing config \\'config.token\\' - Undefined Trello Token'",
")",
";",
"}",
"return",
"errors",
";",
"}"
] |
Validates the configuration object.
@param {Object} config
@param {String} config.key
@param {String} config.token
@return {Array<String>}
|
[
"Validates",
"the",
"configuration",
"object",
"."
] |
949c0bc4b5b2717bda3d8d83ebcb9be65aa40b0b
|
https://github.com/telegraph/trello-client/blob/949c0bc4b5b2717bda3d8d83ebcb9be65aa40b0b/lib/trello.js#L20-L30
|
35,639 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
downloadFile
|
function downloadFile(url, outputPath) {
const dir = path.dirname(outputPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(outputPath);
const sendReq = request.get(url);
sendReq.pipe(file);
sendReq
.on("response", (response) => {
if (response.statusCode !== 200) {
fs.unlink(outputPath);
const error = new Error("Response status code was " + response.statusCode + ".");
console.trace(error);
reject(error);
}
})
.on("error", (error) => {
fs.unlink(outputPath);
console.trace(error);
reject(error);
});
file
.on("finish", () => {
file.close(() => {
resolve();
});
})
.on("error", (error) => {
fs.unlink(outputPath);
console.trace(error);
reject(error);
});
});
}
|
javascript
|
function downloadFile(url, outputPath) {
const dir = path.dirname(outputPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(outputPath);
const sendReq = request.get(url);
sendReq.pipe(file);
sendReq
.on("response", (response) => {
if (response.statusCode !== 200) {
fs.unlink(outputPath);
const error = new Error("Response status code was " + response.statusCode + ".");
console.trace(error);
reject(error);
}
})
.on("error", (error) => {
fs.unlink(outputPath);
console.trace(error);
reject(error);
});
file
.on("finish", () => {
file.close(() => {
resolve();
});
})
.on("error", (error) => {
fs.unlink(outputPath);
console.trace(error);
reject(error);
});
});
}
|
[
"function",
"downloadFile",
"(",
"url",
",",
"outputPath",
")",
"{",
"const",
"dir",
"=",
"path",
".",
"dirname",
"(",
"outputPath",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"dir",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"dir",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"file",
"=",
"fs",
".",
"createWriteStream",
"(",
"outputPath",
")",
";",
"const",
"sendReq",
"=",
"request",
".",
"get",
"(",
"url",
")",
";",
"sendReq",
".",
"pipe",
"(",
"file",
")",
";",
"sendReq",
".",
"on",
"(",
"\"response\"",
",",
"(",
"response",
")",
"=>",
"{",
"if",
"(",
"response",
".",
"statusCode",
"!==",
"200",
")",
"{",
"fs",
".",
"unlink",
"(",
"outputPath",
")",
";",
"const",
"error",
"=",
"new",
"Error",
"(",
"\"Response status code was \"",
"+",
"response",
".",
"statusCode",
"+",
"\".\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"reject",
"(",
"error",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"\"error\"",
",",
"(",
"error",
")",
"=>",
"{",
"fs",
".",
"unlink",
"(",
"outputPath",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"reject",
"(",
"error",
")",
";",
"}",
")",
";",
"file",
".",
"on",
"(",
"\"finish\"",
",",
"(",
")",
"=>",
"{",
"file",
".",
"close",
"(",
"(",
")",
"=>",
"{",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"\"error\"",
",",
"(",
"error",
")",
"=>",
"{",
"fs",
".",
"unlink",
"(",
"outputPath",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"reject",
"(",
"error",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Downloads the URL as a file
@param {string} url
@param {string} outputPath
@return {Promise<void>}
|
[
"Downloads",
"the",
"URL",
"as",
"a",
"file"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L49-L86
|
35,640 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
createProject
|
function createProject(zipFile) {
return cocoonSDK.ProjectAPI.createFromZipUpload(zipFile)
.catch((error) => {
console.error("Project couldn't be created.");
console.trace(error);
throw error;
});
}
|
javascript
|
function createProject(zipFile) {
return cocoonSDK.ProjectAPI.createFromZipUpload(zipFile)
.catch((error) => {
console.error("Project couldn't be created.");
console.trace(error);
throw error;
});
}
|
[
"function",
"createProject",
"(",
"zipFile",
")",
"{",
"return",
"cocoonSDK",
".",
"ProjectAPI",
".",
"createFromZipUpload",
"(",
"zipFile",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Project couldn't be created.\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Creates a new Cocoon Project from a zip file
@param {File} zipFile
@return {Promise<Project>}
|
[
"Creates",
"a",
"new",
"Cocoon",
"Project",
"from",
"a",
"zip",
"file"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L108-L115
|
35,641 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
updateConfig
|
function updateConfig(configXml, project) {
return project.updateConfigXml(configXml)
.catch((error) => {
console.error("Project config with ID: " + project.id + " couldn't be updated.");
console.trace(error);
throw error;
});
}
|
javascript
|
function updateConfig(configXml, project) {
return project.updateConfigXml(configXml)
.catch((error) => {
console.error("Project config with ID: " + project.id + " couldn't be updated.");
console.trace(error);
throw error;
});
}
|
[
"function",
"updateConfig",
"(",
"configXml",
",",
"project",
")",
"{",
"return",
"project",
".",
"updateConfigXml",
"(",
"configXml",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Project config with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" couldn't be updated.\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Updates the config.xml of the project with the one provided
@param {string} configXml
@param {Project} project
@return {Promise<void>}
|
[
"Updates",
"the",
"config",
".",
"xml",
"of",
"the",
"project",
"with",
"the",
"one",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L123-L130
|
35,642 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
updateConfigWithId
|
function updateConfigWithId(configXml, projectId) {
return fetchProject(projectId)
.then((project) => {
return updateConfig(configXml, project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function updateConfigWithId(configXml, projectId) {
return fetchProject(projectId)
.then((project) => {
return updateConfig(configXml, project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"updateConfigWithId",
"(",
"configXml",
",",
"projectId",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"updateConfig",
"(",
"configXml",
",",
"project",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Updates the config.xml of the project with the same ID with the XML provided
@param {string} configXml
@param {string} projectId
@return {Promise<void>}
|
[
"Updates",
"the",
"config",
".",
"xml",
"of",
"the",
"project",
"with",
"the",
"same",
"ID",
"with",
"the",
"XML",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L138-L147
|
35,643 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
deleteProject
|
function deleteProject(project) {
return project.delete()
.catch((error) => {
console.error("Project with ID: " + project.id + " couldn't be deleted.");
console.trace(error);
throw error;
});
}
|
javascript
|
function deleteProject(project) {
return project.delete()
.catch((error) => {
console.error("Project with ID: " + project.id + " couldn't be deleted.");
console.trace(error);
throw error;
});
}
|
[
"function",
"deleteProject",
"(",
"project",
")",
"{",
"return",
"project",
".",
"delete",
"(",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Project with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" couldn't be deleted.\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Deletes the project
@param {Project} project
@return {Promise<void>}
|
[
"Deletes",
"the",
"project"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L154-L161
|
35,644 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
deleteProjectWithId
|
function deleteProjectWithId(projectId) {
return fetchProject(projectId)
.then(deleteProject)
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function deleteProjectWithId(projectId) {
return fetchProject(projectId)
.then(deleteProject)
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"deleteProjectWithId",
"(",
"projectId",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"deleteProject",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Deletes the project associated with the ID
@param {string} projectId
@return {Promise<void>}
|
[
"Deletes",
"the",
"project",
"associated",
"with",
"the",
"ID"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L168-L175
|
35,645 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
createProjectWithConfig
|
function createProjectWithConfig(zipFile, configXml) {
return createProject(zipFile)
.then((project) => {
return updateConfig(configXml, project)
.then(() => {
return project;
})
.catch((errorFromUpdate) => {
deleteProject(project)
.then(() => {
console.error("The project with ID: " + project.id + " was not created because it wasn't possible to upload the custom XML.");
throw errorFromUpdate;
})
.catch((errorFromDelete) => {
console.error("The project with ID: " + project.id + " was created but it wasn't possible to upload the custom XML.");
console.trace(errorFromDelete);
throw errorFromDelete;
});
});
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function createProjectWithConfig(zipFile, configXml) {
return createProject(zipFile)
.then((project) => {
return updateConfig(configXml, project)
.then(() => {
return project;
})
.catch((errorFromUpdate) => {
deleteProject(project)
.then(() => {
console.error("The project with ID: " + project.id + " was not created because it wasn't possible to upload the custom XML.");
throw errorFromUpdate;
})
.catch((errorFromDelete) => {
console.error("The project with ID: " + project.id + " was created but it wasn't possible to upload the custom XML.");
console.trace(errorFromDelete);
throw errorFromDelete;
});
});
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"createProjectWithConfig",
"(",
"zipFile",
",",
"configXml",
")",
"{",
"return",
"createProject",
"(",
"zipFile",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"updateConfig",
"(",
"configXml",
",",
"project",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"return",
"project",
";",
"}",
")",
".",
"catch",
"(",
"(",
"errorFromUpdate",
")",
"=>",
"{",
"deleteProject",
"(",
"project",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"The project with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" was not created because it wasn't possible to upload the custom XML.\"",
")",
";",
"throw",
"errorFromUpdate",
";",
"}",
")",
".",
"catch",
"(",
"(",
"errorFromDelete",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"The project with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" was created but it wasn't possible to upload the custom XML.\"",
")",
";",
"console",
".",
"trace",
"(",
"errorFromDelete",
")",
";",
"throw",
"errorFromDelete",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Creates a new Cocoon Project from a zip file and a config XML
@param {File} zipFile
@param {string} configXml
@return {Promise<Project>}
|
[
"Creates",
"a",
"new",
"Cocoon",
"Project",
"from",
"a",
"zip",
"file",
"and",
"a",
"config",
"XML"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L183-L207
|
35,646 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
updateSource
|
function updateSource(zipFile, project) {
return project.updateZip(zipFile)
.catch((error) => {
console.error("Project source with ID: " + project.id + " couldn't be updated.");
console.trace(error);
throw error;
});
}
|
javascript
|
function updateSource(zipFile, project) {
return project.updateZip(zipFile)
.catch((error) => {
console.error("Project source with ID: " + project.id + " couldn't be updated.");
console.trace(error);
throw error;
});
}
|
[
"function",
"updateSource",
"(",
"zipFile",
",",
"project",
")",
"{",
"return",
"project",
".",
"updateZip",
"(",
"zipFile",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Project source with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" couldn't be updated.\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Uploads the zip file as the new source code of the project
@param {File} zipFile
@param {Project} project
@return {Promise<void>}
|
[
"Uploads",
"the",
"zip",
"file",
"as",
"the",
"new",
"source",
"code",
"of",
"the",
"project"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L215-L222
|
35,647 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
updateSourceWithId
|
function updateSourceWithId(zipFile, projectId) {
return fetchProject(projectId)
.then((project) => {
return updateSource(zipFile, project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function updateSourceWithId(zipFile, projectId) {
return fetchProject(projectId)
.then((project) => {
return updateSource(zipFile, project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"updateSourceWithId",
"(",
"zipFile",
",",
"projectId",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"updateSource",
"(",
"zipFile",
",",
"project",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Uploads the zip file as the new source code of the project with the same ID
@param {File} zipFile
@param {string} projectId
@return {Promise<void>}
|
[
"Uploads",
"the",
"zip",
"file",
"as",
"the",
"new",
"source",
"code",
"of",
"the",
"project",
"with",
"the",
"same",
"ID"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L230-L239
|
35,648 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
compileProject
|
function compileProject(project) {
return project.compile()
.catch((error) => {
console.error("Project " + project.name + " with ID: " + project.id + " couldn't be compiled.");
console.trace(error);
throw error;
});
}
|
javascript
|
function compileProject(project) {
return project.compile()
.catch((error) => {
console.error("Project " + project.name + " with ID: " + project.id + " couldn't be compiled.");
console.trace(error);
throw error;
});
}
|
[
"function",
"compileProject",
"(",
"project",
")",
"{",
"return",
"project",
".",
"compile",
"(",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Project \"",
"+",
"project",
".",
"name",
"+",
"\" with ID: \"",
"+",
"project",
".",
"id",
"+",
"\" couldn't be compiled.\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Places the project in the compilation queue
@param {Project} project
@return {Promise<void>}
|
[
"Places",
"the",
"project",
"in",
"the",
"compilation",
"queue"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L246-L253
|
35,649 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
compileProjectWithId
|
function compileProjectWithId(projectId) {
return fetchProject(projectId)
.then(compileProject)
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function compileProjectWithId(projectId) {
return fetchProject(projectId)
.then(compileProject)
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"compileProjectWithId",
"(",
"projectId",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"compileProject",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Places the project associated with the ID in the compilation queue
@param {string} projectId
@return {Promise<void>}
|
[
"Places",
"the",
"project",
"associated",
"with",
"the",
"ID",
"in",
"the",
"compilation",
"queue"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L260-L267
|
35,650 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
waitForCompletion
|
function waitForCompletion(project) {
return new Promise((resolve, reject) => {
let warned = false;
project.refreshUntilCompleted((completed, error) => {
if (!error) {
if (completed) {
if (warned) {
readLine.clearLine(process.stdout); // clear "Waiting" line
readLine.cursorTo(process.stdout, 0); // move cursor to beginning of line
}
resolve();
} else {
if (!warned) {
process.stdout.write("Waiting for " + project.name + " compilation to end ");
warned = true;
}
process.stdout.write(".");
}
} else {
reject(error);
}
});
});
}
|
javascript
|
function waitForCompletion(project) {
return new Promise((resolve, reject) => {
let warned = false;
project.refreshUntilCompleted((completed, error) => {
if (!error) {
if (completed) {
if (warned) {
readLine.clearLine(process.stdout); // clear "Waiting" line
readLine.cursorTo(process.stdout, 0); // move cursor to beginning of line
}
resolve();
} else {
if (!warned) {
process.stdout.write("Waiting for " + project.name + " compilation to end ");
warned = true;
}
process.stdout.write(".");
}
} else {
reject(error);
}
});
});
}
|
[
"function",
"waitForCompletion",
"(",
"project",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"warned",
"=",
"false",
";",
"project",
".",
"refreshUntilCompleted",
"(",
"(",
"completed",
",",
"error",
")",
"=>",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"if",
"(",
"completed",
")",
"{",
"if",
"(",
"warned",
")",
"{",
"readLine",
".",
"clearLine",
"(",
"process",
".",
"stdout",
")",
";",
"// clear \"Waiting\" line",
"readLine",
".",
"cursorTo",
"(",
"process",
".",
"stdout",
",",
"0",
")",
";",
"// move cursor to beginning of line",
"}",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"warned",
")",
"{",
"process",
".",
"stdout",
".",
"write",
"(",
"\"Waiting for \"",
"+",
"project",
".",
"name",
"+",
"\" compilation to end \"",
")",
";",
"warned",
"=",
"true",
";",
"}",
"process",
".",
"stdout",
".",
"write",
"(",
"\".\"",
")",
";",
"}",
"}",
"else",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Waits for the project to finish compiling. Then calls the callback
@param {Project} project
@return {Promise<void>}
|
[
"Waits",
"for",
"the",
"project",
"to",
"finish",
"compiling",
".",
"Then",
"calls",
"the",
"callback"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L274-L297
|
35,651 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
downloadProjectCompilation
|
function downloadProjectCompilation(project, platform, outputDir) {
return waitForCompletion(project)
.then(() => {
if (project.compilations[platform]) {
if (project.compilations[platform].isReady()) {
return downloadFile(project.compilations[platform].downloadLink,
outputDir + "/" + project.name + "-" + platform + ".zip")
.catch((error) => {
console.error("Couldn't download " + platform + " compilation from project " + project.id + ".");
console.trace(error);
throw error;
});
} else if (project.compilations[platform].isErred()) {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". The compilation failed.");
throw new Error("Compilation failed");
} else {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". Status: " + project.compilations[platform].status + ".");
throw new Error("Platform ignored");
}
} else {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". There was not a compilation issued for the platform.");
throw new Error("No compilation available");
}
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function downloadProjectCompilation(project, platform, outputDir) {
return waitForCompletion(project)
.then(() => {
if (project.compilations[platform]) {
if (project.compilations[platform].isReady()) {
return downloadFile(project.compilations[platform].downloadLink,
outputDir + "/" + project.name + "-" + platform + ".zip")
.catch((error) => {
console.error("Couldn't download " + platform + " compilation from project " + project.id + ".");
console.trace(error);
throw error;
});
} else if (project.compilations[platform].isErred()) {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". The compilation failed.");
throw new Error("Compilation failed");
} else {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". Status: " + project.compilations[platform].status + ".");
throw new Error("Platform ignored");
}
} else {
console.error("Couldn't download " + platform + " compilation from " + project.name + " project: " + project.id +
". There was not a compilation issued for the platform.");
throw new Error("No compilation available");
}
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"downloadProjectCompilation",
"(",
"project",
",",
"platform",
",",
"outputDir",
")",
"{",
"return",
"waitForCompletion",
"(",
"project",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"project",
".",
"compilations",
"[",
"platform",
"]",
")",
"{",
"if",
"(",
"project",
".",
"compilations",
"[",
"platform",
"]",
".",
"isReady",
"(",
")",
")",
"{",
"return",
"downloadFile",
"(",
"project",
".",
"compilations",
"[",
"platform",
"]",
".",
"downloadLink",
",",
"outputDir",
"+",
"\"/\"",
"+",
"project",
".",
"name",
"+",
"\"-\"",
"+",
"platform",
"+",
"\".zip\"",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"error",
"(",
"\"Couldn't download \"",
"+",
"platform",
"+",
"\" compilation from project \"",
"+",
"project",
".",
"id",
"+",
"\".\"",
")",
";",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"project",
".",
"compilations",
"[",
"platform",
"]",
".",
"isErred",
"(",
")",
")",
"{",
"console",
".",
"error",
"(",
"\"Couldn't download \"",
"+",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\". The compilation failed.\"",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Compilation failed\"",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"Couldn't download \"",
"+",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\". Status: \"",
"+",
"project",
".",
"compilations",
"[",
"platform",
"]",
".",
"status",
"+",
"\".\"",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Platform ignored\"",
")",
";",
"}",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"Couldn't download \"",
"+",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\". There was not a compilation issued for the platform.\"",
")",
";",
"throw",
"new",
"Error",
"(",
"\"No compilation available\"",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Downloads the result of the latest platform compilation of the project
@param {Project} project
@param {string} platform
@param {string} outputDir
@return {Promise<void>}
|
[
"Downloads",
"the",
"result",
"of",
"the",
"latest",
"platform",
"compilation",
"of",
"the",
"project"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L306-L337
|
35,652 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
downloadProjectCompilationWithId
|
function downloadProjectCompilationWithId(projectId, platform, outputDir) {
return fetchProject(projectId)
.then((project) => {
return downloadProjectCompilation(project, platform, outputDir);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function downloadProjectCompilationWithId(projectId, platform, outputDir) {
return fetchProject(projectId)
.then((project) => {
return downloadProjectCompilation(project, platform, outputDir);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"downloadProjectCompilationWithId",
"(",
"projectId",
",",
"platform",
",",
"outputDir",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"downloadProjectCompilation",
"(",
"project",
",",
"platform",
",",
"outputDir",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Downloads the result of the latest platform compilation of the project with the ID provided
@param {string} projectId
@param {string} platform
@param {string} outputDir
@return {Promise<void>}
|
[
"Downloads",
"the",
"result",
"of",
"the",
"latest",
"platform",
"compilation",
"of",
"the",
"project",
"with",
"the",
"ID",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L346-L355
|
35,653 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
downloadProjectCompilations
|
function downloadProjectCompilations(project, outputDir) {
const promises = [];
for (const platform in project.compilations) {
if (!project.compilations.hasOwnProperty(platform)) {
continue;
}
promises.push(downloadProjectCompilation(project, platform, outputDir).catch(() => {
return undefined;
}));
}
return Promise.all(promises);
}
|
javascript
|
function downloadProjectCompilations(project, outputDir) {
const promises = [];
for (const platform in project.compilations) {
if (!project.compilations.hasOwnProperty(platform)) {
continue;
}
promises.push(downloadProjectCompilation(project, platform, outputDir).catch(() => {
return undefined;
}));
}
return Promise.all(promises);
}
|
[
"function",
"downloadProjectCompilations",
"(",
"project",
",",
"outputDir",
")",
"{",
"const",
"promises",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"platform",
"in",
"project",
".",
"compilations",
")",
"{",
"if",
"(",
"!",
"project",
".",
"compilations",
".",
"hasOwnProperty",
"(",
"platform",
")",
")",
"{",
"continue",
";",
"}",
"promises",
".",
"push",
"(",
"downloadProjectCompilation",
"(",
"project",
",",
"platform",
",",
"outputDir",
")",
".",
"catch",
"(",
"(",
")",
"=>",
"{",
"return",
"undefined",
";",
"}",
")",
")",
";",
"}",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
";",
"}"
] |
Downloads the results of the latest compilation of the project
@param {Project} project
@param {string} outputDir
@return {Promise<void>}
|
[
"Downloads",
"the",
"results",
"of",
"the",
"latest",
"compilation",
"of",
"the",
"project"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L363-L374
|
35,654 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
downloadProjectCompilationsWithId
|
function downloadProjectCompilationsWithId(projectId, outputDir) {
return fetchProject(projectId)
.then((project) => {
return downloadProjectCompilations(project, outputDir);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function downloadProjectCompilationsWithId(projectId, outputDir) {
return fetchProject(projectId)
.then((project) => {
return downloadProjectCompilations(project, outputDir);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"downloadProjectCompilationsWithId",
"(",
"projectId",
",",
"outputDir",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"downloadProjectCompilations",
"(",
"project",
",",
"outputDir",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Downloads the results of the latest compilation of the project with the ID provided
@param {string} projectId
@param {string} outputDir
@return {Promise<void>}
|
[
"Downloads",
"the",
"results",
"of",
"the",
"latest",
"compilation",
"of",
"the",
"project",
"with",
"the",
"ID",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L382-L391
|
35,655 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
checkProjectCompilationWithId
|
function checkProjectCompilationWithId(projectId, platform) {
return fetchProject(projectId)
.then((project) => {
return checkProjectCompilation(project, platform);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function checkProjectCompilationWithId(projectId, platform) {
return fetchProject(projectId)
.then((project) => {
return checkProjectCompilation(project, platform);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"checkProjectCompilationWithId",
"(",
"projectId",
",",
"platform",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"checkProjectCompilation",
"(",
"project",
",",
"platform",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Logs the result of the latest platform compilation of the project with the ID provided
@param {string} projectId
@param {string} platform
@return {Promise<void>}
|
[
"Logs",
"the",
"result",
"of",
"the",
"latest",
"platform",
"compilation",
"of",
"the",
"project",
"with",
"the",
"ID",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L432-L441
|
35,656 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
checkProjectCompilations
|
function checkProjectCompilations(project) {
return waitForCompletion(project)
.then(() => {
for (const platform in project.compilations) {
if (!project.compilations.hasOwnProperty(platform)) {
continue;
}
const compilation = project.compilations[platform];
if (compilation.isReady()) {
console.info(compilation.platform + " compilation from " + project.name + " project: " + project.id + " is completed.");
} else if (compilation.isErred()) {
console.error(compilation.platform + " compilation from " + project.name + " project: " + project.id + " is erred.");
console.error("ERROR LOG of the " + compilation.platform + " platform:");
console.error(compilation.error);
} else {
console.error(compilation.platform + " compilation from " + project.name + " project: " + project.id +
" was ignored. Status: " + compilation.status + ".");
}
}
return undefined;
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function checkProjectCompilations(project) {
return waitForCompletion(project)
.then(() => {
for (const platform in project.compilations) {
if (!project.compilations.hasOwnProperty(platform)) {
continue;
}
const compilation = project.compilations[platform];
if (compilation.isReady()) {
console.info(compilation.platform + " compilation from " + project.name + " project: " + project.id + " is completed.");
} else if (compilation.isErred()) {
console.error(compilation.platform + " compilation from " + project.name + " project: " + project.id + " is erred.");
console.error("ERROR LOG of the " + compilation.platform + " platform:");
console.error(compilation.error);
} else {
console.error(compilation.platform + " compilation from " + project.name + " project: " + project.id +
" was ignored. Status: " + compilation.status + ".");
}
}
return undefined;
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"checkProjectCompilations",
"(",
"project",
")",
"{",
"return",
"waitForCompletion",
"(",
"project",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"for",
"(",
"const",
"platform",
"in",
"project",
".",
"compilations",
")",
"{",
"if",
"(",
"!",
"project",
".",
"compilations",
".",
"hasOwnProperty",
"(",
"platform",
")",
")",
"{",
"continue",
";",
"}",
"const",
"compilation",
"=",
"project",
".",
"compilations",
"[",
"platform",
"]",
";",
"if",
"(",
"compilation",
".",
"isReady",
"(",
")",
")",
"{",
"console",
".",
"info",
"(",
"compilation",
".",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\" is completed.\"",
")",
";",
"}",
"else",
"if",
"(",
"compilation",
".",
"isErred",
"(",
")",
")",
"{",
"console",
".",
"error",
"(",
"compilation",
".",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\" is erred.\"",
")",
";",
"console",
".",
"error",
"(",
"\"ERROR LOG of the \"",
"+",
"compilation",
".",
"platform",
"+",
"\" platform:\"",
")",
";",
"console",
".",
"error",
"(",
"compilation",
".",
"error",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"compilation",
".",
"platform",
"+",
"\" compilation from \"",
"+",
"project",
".",
"name",
"+",
"\" project: \"",
"+",
"project",
".",
"id",
"+",
"\" was ignored. Status: \"",
"+",
"compilation",
".",
"status",
"+",
"\".\"",
")",
";",
"}",
"}",
"return",
"undefined",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Logs the results of the latest compilation of the project
@param {Project} project
@return {Promise<void>}
|
[
"Logs",
"the",
"results",
"of",
"the",
"latest",
"compilation",
"of",
"the",
"project"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L448-L473
|
35,657 |
CocoonIO/cocoon-cloud-sdk
|
sample/gulp/gulpfile.js
|
checkProjectCompilationsWithId
|
function checkProjectCompilationsWithId(projectId) {
return fetchProject(projectId)
.then((project) => {
return checkProjectCompilations(project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
javascript
|
function checkProjectCompilationsWithId(projectId) {
return fetchProject(projectId)
.then((project) => {
return checkProjectCompilations(project);
})
.catch((error) => {
console.trace(error);
throw error;
});
}
|
[
"function",
"checkProjectCompilationsWithId",
"(",
"projectId",
")",
"{",
"return",
"fetchProject",
"(",
"projectId",
")",
".",
"then",
"(",
"(",
"project",
")",
"=>",
"{",
"return",
"checkProjectCompilations",
"(",
"project",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"console",
".",
"trace",
"(",
"error",
")",
";",
"throw",
"error",
";",
"}",
")",
";",
"}"
] |
Logs the results of the latest compilation of the project with the ID provided
@param {string} projectId
@return {Promise<void>}
|
[
"Logs",
"the",
"results",
"of",
"the",
"latest",
"compilation",
"of",
"the",
"project",
"with",
"the",
"ID",
"provided"
] |
b583faf2f3e21c3317358953494930af0cae0a3e
|
https://github.com/CocoonIO/cocoon-cloud-sdk/blob/b583faf2f3e21c3317358953494930af0cae0a3e/sample/gulp/gulpfile.js#L480-L489
|
35,658 |
roemhildtg/spectre-canjs
|
sp-form/demo/full/fixtures.js
|
getBase64
|
function getBase64 (file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onerror = function (error) {
console.log('Error: ', error);
};
return reader;
}
|
javascript
|
function getBase64 (file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onerror = function (error) {
console.log('Error: ', error);
};
return reader;
}
|
[
"function",
"getBase64",
"(",
"file",
")",
"{",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"reader",
".",
"onerror",
"=",
"function",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"'Error: '",
",",
"error",
")",
";",
"}",
";",
"return",
"reader",
";",
"}"
] |
this example uses fixtures to catch requests and simulate file upload server
|
[
"this",
"example",
"uses",
"fixtures",
"to",
"catch",
"requests",
"and",
"simulate",
"file",
"upload",
"server"
] |
5ae3b9a8454ba279c1e04dc3ca7943a72edbeb12
|
https://github.com/roemhildtg/spectre-canjs/blob/5ae3b9a8454ba279c1e04dc3ca7943a72edbeb12/sp-form/demo/full/fixtures.js#L4-L11
|
35,659 |
mphasize/sails-generate-ember-blueprints
|
templates/basic/api/blueprints/_util/actionUtil.js
|
function ( model, records, associations, sideload ) {
sideload = sideload || false;
var plural = Array.isArray( records ) ? true : false;
var documentIdentifier = plural ? pluralize( model.globalId ) : model.globalId;
//turn id into camelCase for ember
documentIdentifier = camelCase(documentIdentifier);
var json = {};
json[ documentIdentifier ] = plural ? [] : {};
if ( sideload ) {
// prepare for sideloading
forEach( associations, function ( assoc ) {
var assocName;
if (assoc.type === 'collection') {
assocName = pluralize(camelCase(sails.models[assoc.collection].globalId));
} else {
assocName = pluralize(camelCase(sails.models[assoc.model].globalId));
}
// initialize jsoning object
if ( !json.hasOwnProperty( assoc.alias ) ) {
json[ assocName ] = [];
}
} );
}
var prepareOneRecord = function ( record ) {
// get rid of the record's prototype ( otherwise the .toJSON called in res.send would re-insert embedded records)
record = create( {}, record.toJSON() );
forEach( associations, function ( assoc ) {
var assocName;
if (assoc.type === 'collection') {
assocName = pluralize(camelCase(sails.models[assoc.collection].globalId));
} else {
assocName = pluralize(camelCase(sails.models[assoc.model].globalId));
}
if ( assoc.type === "collection" && record[ assoc.alias ] && record[ assoc.alias ].length > 0 ) {
if ( sideload ) json[ assocName ] = json[ assocName ].concat( record[ assoc.alias ] );
record[ assoc.alias ] = pluck( record[ assoc.alias ], 'id' );
}
if ( assoc.type === "model" && record[ assoc.alias ] ) {
if ( sideload ) json[ assocName ] = json[ assocName ].concat( record[ assoc.alias ] );
record[ assoc.alias ] = record[ assoc.alias ].id;
}
} );
return record;
};
// many or just one?
if ( plural ) {
forEach( records, function ( record ) {
json[ documentIdentifier ] = json[ documentIdentifier ].concat( prepareOneRecord( record ) );
} );
} else {
json[ documentIdentifier ] = prepareOneRecord( records );
}
if ( sideload ) {
// filter duplicates in sideloaded records
forEach( json, function ( array, key ) {
if ( !plural && key === documentIdentifier ) return;
json[ key ] = uniq( array, function ( record ) {
return record.id;
} );
} );
}
return json;
}
|
javascript
|
function ( model, records, associations, sideload ) {
sideload = sideload || false;
var plural = Array.isArray( records ) ? true : false;
var documentIdentifier = plural ? pluralize( model.globalId ) : model.globalId;
//turn id into camelCase for ember
documentIdentifier = camelCase(documentIdentifier);
var json = {};
json[ documentIdentifier ] = plural ? [] : {};
if ( sideload ) {
// prepare for sideloading
forEach( associations, function ( assoc ) {
var assocName;
if (assoc.type === 'collection') {
assocName = pluralize(camelCase(sails.models[assoc.collection].globalId));
} else {
assocName = pluralize(camelCase(sails.models[assoc.model].globalId));
}
// initialize jsoning object
if ( !json.hasOwnProperty( assoc.alias ) ) {
json[ assocName ] = [];
}
} );
}
var prepareOneRecord = function ( record ) {
// get rid of the record's prototype ( otherwise the .toJSON called in res.send would re-insert embedded records)
record = create( {}, record.toJSON() );
forEach( associations, function ( assoc ) {
var assocName;
if (assoc.type === 'collection') {
assocName = pluralize(camelCase(sails.models[assoc.collection].globalId));
} else {
assocName = pluralize(camelCase(sails.models[assoc.model].globalId));
}
if ( assoc.type === "collection" && record[ assoc.alias ] && record[ assoc.alias ].length > 0 ) {
if ( sideload ) json[ assocName ] = json[ assocName ].concat( record[ assoc.alias ] );
record[ assoc.alias ] = pluck( record[ assoc.alias ], 'id' );
}
if ( assoc.type === "model" && record[ assoc.alias ] ) {
if ( sideload ) json[ assocName ] = json[ assocName ].concat( record[ assoc.alias ] );
record[ assoc.alias ] = record[ assoc.alias ].id;
}
} );
return record;
};
// many or just one?
if ( plural ) {
forEach( records, function ( record ) {
json[ documentIdentifier ] = json[ documentIdentifier ].concat( prepareOneRecord( record ) );
} );
} else {
json[ documentIdentifier ] = prepareOneRecord( records );
}
if ( sideload ) {
// filter duplicates in sideloaded records
forEach( json, function ( array, key ) {
if ( !plural && key === documentIdentifier ) return;
json[ key ] = uniq( array, function ( record ) {
return record.id;
} );
} );
}
return json;
}
|
[
"function",
"(",
"model",
",",
"records",
",",
"associations",
",",
"sideload",
")",
"{",
"sideload",
"=",
"sideload",
"||",
"false",
";",
"var",
"plural",
"=",
"Array",
".",
"isArray",
"(",
"records",
")",
"?",
"true",
":",
"false",
";",
"var",
"documentIdentifier",
"=",
"plural",
"?",
"pluralize",
"(",
"model",
".",
"globalId",
")",
":",
"model",
".",
"globalId",
";",
"//turn id into camelCase for ember",
"documentIdentifier",
"=",
"camelCase",
"(",
"documentIdentifier",
")",
";",
"var",
"json",
"=",
"{",
"}",
";",
"json",
"[",
"documentIdentifier",
"]",
"=",
"plural",
"?",
"[",
"]",
":",
"{",
"}",
";",
"if",
"(",
"sideload",
")",
"{",
"// prepare for sideloading",
"forEach",
"(",
"associations",
",",
"function",
"(",
"assoc",
")",
"{",
"var",
"assocName",
";",
"if",
"(",
"assoc",
".",
"type",
"===",
"'collection'",
")",
"{",
"assocName",
"=",
"pluralize",
"(",
"camelCase",
"(",
"sails",
".",
"models",
"[",
"assoc",
".",
"collection",
"]",
".",
"globalId",
")",
")",
";",
"}",
"else",
"{",
"assocName",
"=",
"pluralize",
"(",
"camelCase",
"(",
"sails",
".",
"models",
"[",
"assoc",
".",
"model",
"]",
".",
"globalId",
")",
")",
";",
"}",
"// initialize jsoning object",
"if",
"(",
"!",
"json",
".",
"hasOwnProperty",
"(",
"assoc",
".",
"alias",
")",
")",
"{",
"json",
"[",
"assocName",
"]",
"=",
"[",
"]",
";",
"}",
"}",
")",
";",
"}",
"var",
"prepareOneRecord",
"=",
"function",
"(",
"record",
")",
"{",
"// get rid of the record's prototype ( otherwise the .toJSON called in res.send would re-insert embedded records)",
"record",
"=",
"create",
"(",
"{",
"}",
",",
"record",
".",
"toJSON",
"(",
")",
")",
";",
"forEach",
"(",
"associations",
",",
"function",
"(",
"assoc",
")",
"{",
"var",
"assocName",
";",
"if",
"(",
"assoc",
".",
"type",
"===",
"'collection'",
")",
"{",
"assocName",
"=",
"pluralize",
"(",
"camelCase",
"(",
"sails",
".",
"models",
"[",
"assoc",
".",
"collection",
"]",
".",
"globalId",
")",
")",
";",
"}",
"else",
"{",
"assocName",
"=",
"pluralize",
"(",
"camelCase",
"(",
"sails",
".",
"models",
"[",
"assoc",
".",
"model",
"]",
".",
"globalId",
")",
")",
";",
"}",
"if",
"(",
"assoc",
".",
"type",
"===",
"\"collection\"",
"&&",
"record",
"[",
"assoc",
".",
"alias",
"]",
"&&",
"record",
"[",
"assoc",
".",
"alias",
"]",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"sideload",
")",
"json",
"[",
"assocName",
"]",
"=",
"json",
"[",
"assocName",
"]",
".",
"concat",
"(",
"record",
"[",
"assoc",
".",
"alias",
"]",
")",
";",
"record",
"[",
"assoc",
".",
"alias",
"]",
"=",
"pluck",
"(",
"record",
"[",
"assoc",
".",
"alias",
"]",
",",
"'id'",
")",
";",
"}",
"if",
"(",
"assoc",
".",
"type",
"===",
"\"model\"",
"&&",
"record",
"[",
"assoc",
".",
"alias",
"]",
")",
"{",
"if",
"(",
"sideload",
")",
"json",
"[",
"assocName",
"]",
"=",
"json",
"[",
"assocName",
"]",
".",
"concat",
"(",
"record",
"[",
"assoc",
".",
"alias",
"]",
")",
";",
"record",
"[",
"assoc",
".",
"alias",
"]",
"=",
"record",
"[",
"assoc",
".",
"alias",
"]",
".",
"id",
";",
"}",
"}",
")",
";",
"return",
"record",
";",
"}",
";",
"// many or just one?",
"if",
"(",
"plural",
")",
"{",
"forEach",
"(",
"records",
",",
"function",
"(",
"record",
")",
"{",
"json",
"[",
"documentIdentifier",
"]",
"=",
"json",
"[",
"documentIdentifier",
"]",
".",
"concat",
"(",
"prepareOneRecord",
"(",
"record",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"json",
"[",
"documentIdentifier",
"]",
"=",
"prepareOneRecord",
"(",
"records",
")",
";",
"}",
"if",
"(",
"sideload",
")",
"{",
"// filter duplicates in sideloaded records",
"forEach",
"(",
"json",
",",
"function",
"(",
"array",
",",
"key",
")",
"{",
"if",
"(",
"!",
"plural",
"&&",
"key",
"===",
"documentIdentifier",
")",
"return",
";",
"json",
"[",
"key",
"]",
"=",
"uniq",
"(",
"array",
",",
"function",
"(",
"record",
")",
"{",
"return",
"record",
".",
"id",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"json",
";",
"}"
] |
Prepare records and populated associations to be consumed by Ember's DS.RESTAdapter
@param {Collection} model Waterline collection object (returned from parseModel)
@param {Array|Object} records A record or an array of records returned from a Waterline query
@param {Associations} associations Definition of the associations, from `req.option.associations`
@param {Boolean} sideload Sideload embedded records or reduce them to primary keys?
@return {Object} The returned structure can be consumed by DS.RESTAdapter when passed to res.json()
|
[
"Prepare",
"records",
"and",
"populated",
"associations",
"to",
"be",
"consumed",
"by",
"Ember",
"s",
"DS",
".",
"RESTAdapter"
] |
c85211c58e806b538f000d6f4f1a2b0cbe72d8c9
|
https://github.com/mphasize/sails-generate-ember-blueprints/blob/c85211c58e806b538f000d6f4f1a2b0cbe72d8c9/templates/basic/api/blueprints/_util/actionUtil.js#L42-L116
|
|
35,660 |
IndigoUnited/automaton
|
lib/grunt/worker.js
|
resetKeepAlive
|
function resetKeepAlive() {
if (keepAliveTimeoutId) {
clearTimeout(keepAliveTimeoutId);
}
keepAliveTimeoutId = setTimeout(function () {
exit.call(process, 1);
}, keepAliveTimeout);
}
|
javascript
|
function resetKeepAlive() {
if (keepAliveTimeoutId) {
clearTimeout(keepAliveTimeoutId);
}
keepAliveTimeoutId = setTimeout(function () {
exit.call(process, 1);
}, keepAliveTimeout);
}
|
[
"function",
"resetKeepAlive",
"(",
")",
"{",
"if",
"(",
"keepAliveTimeoutId",
")",
"{",
"clearTimeout",
"(",
"keepAliveTimeoutId",
")",
";",
"}",
"keepAliveTimeoutId",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"exit",
".",
"call",
"(",
"process",
",",
"1",
")",
";",
"}",
",",
"keepAliveTimeout",
")",
";",
"}"
] |
function to reset the keep alive timeout once a keep alive message from the parent is received
|
[
"function",
"to",
"reset",
"the",
"keep",
"alive",
"timeout",
"once",
"a",
"keep",
"alive",
"message",
"from",
"the",
"parent",
"is",
"received"
] |
3e86a76374a288e4f125b3e4994c9738f79c7028
|
https://github.com/IndigoUnited/automaton/blob/3e86a76374a288e4f125b3e4994c9738f79c7028/lib/grunt/worker.js#L27-L35
|
35,661 |
SAP/yaas-nodejs-client-sdk
|
yaas-pubsub.js
|
fixEventPayload
|
function fixEventPayload(events) {
return new Promise(function (resolve, reject) {
events.forEach(function(event) {
try {
event.payload = JSON.parse(event.payload);
} catch (e) {
console.log('Could not parse payload');
return reject(new Error('Could not parse payload: ' + e.message));
}
});
resolve();
});
}
|
javascript
|
function fixEventPayload(events) {
return new Promise(function (resolve, reject) {
events.forEach(function(event) {
try {
event.payload = JSON.parse(event.payload);
} catch (e) {
console.log('Could not parse payload');
return reject(new Error('Could not parse payload: ' + e.message));
}
});
resolve();
});
}
|
[
"function",
"fixEventPayload",
"(",
"events",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"events",
".",
"forEach",
"(",
"function",
"(",
"event",
")",
"{",
"try",
"{",
"event",
".",
"payload",
"=",
"JSON",
".",
"parse",
"(",
"event",
".",
"payload",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'Could not parse payload'",
")",
";",
"return",
"reject",
"(",
"new",
"Error",
"(",
"'Could not parse payload: '",
"+",
"e",
".",
"message",
")",
")",
";",
"}",
"}",
")",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Convert PubSub event payloads into proper nested JSON
|
[
"Convert",
"PubSub",
"event",
"payloads",
"into",
"proper",
"nested",
"JSON"
] |
cb4de0048492f51b2fd1488c4d115f373f6cd98f
|
https://github.com/SAP/yaas-nodejs-client-sdk/blob/cb4de0048492f51b2fd1488c4d115f373f6cd98f/yaas-pubsub.js#L8-L20
|
35,662 |
SAP/yaas-nodejs-client-sdk
|
examples/checkout.js
|
getToken
|
function getToken(stripeCredentials) {
return new Promise(function (resolve, reject) {
var required = [
"stripe_secret",
"credit_card_number",
"credit_card_cvc",
"credit_card_expiry_month",
"credit_card_expiry_year"
];
if (stripeCredentials.stripe_api_key.indexOf("sk") === 0) {
console.log("*** WARNING: using a secret stripe api key. ***");
}
var stripe = require('stripe')(stripeCredentials.stripe_api_key);
var card = {
number: stripeCredentials.credit_card_number,
exp_month: stripeCredentials.credit_card_expiry_month,
exp_year: stripeCredentials.credit_card_expiry_year,
cvc: stripeCredentials.credit_card_cvc
};
stripe.tokens.create({ card: card },
(err, token) => {
if (err) {
reject(err);
} else {
resolve(token.id);
}
}
);
});
}
|
javascript
|
function getToken(stripeCredentials) {
return new Promise(function (resolve, reject) {
var required = [
"stripe_secret",
"credit_card_number",
"credit_card_cvc",
"credit_card_expiry_month",
"credit_card_expiry_year"
];
if (stripeCredentials.stripe_api_key.indexOf("sk") === 0) {
console.log("*** WARNING: using a secret stripe api key. ***");
}
var stripe = require('stripe')(stripeCredentials.stripe_api_key);
var card = {
number: stripeCredentials.credit_card_number,
exp_month: stripeCredentials.credit_card_expiry_month,
exp_year: stripeCredentials.credit_card_expiry_year,
cvc: stripeCredentials.credit_card_cvc
};
stripe.tokens.create({ card: card },
(err, token) => {
if (err) {
reject(err);
} else {
resolve(token.id);
}
}
);
});
}
|
[
"function",
"getToken",
"(",
"stripeCredentials",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"required",
"=",
"[",
"\"stripe_secret\"",
",",
"\"credit_card_number\"",
",",
"\"credit_card_cvc\"",
",",
"\"credit_card_expiry_month\"",
",",
"\"credit_card_expiry_year\"",
"]",
";",
"if",
"(",
"stripeCredentials",
".",
"stripe_api_key",
".",
"indexOf",
"(",
"\"sk\"",
")",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"\"*** WARNING: using a secret stripe api key. ***\"",
")",
";",
"}",
"var",
"stripe",
"=",
"require",
"(",
"'stripe'",
")",
"(",
"stripeCredentials",
".",
"stripe_api_key",
")",
";",
"var",
"card",
"=",
"{",
"number",
":",
"stripeCredentials",
".",
"credit_card_number",
",",
"exp_month",
":",
"stripeCredentials",
".",
"credit_card_expiry_month",
",",
"exp_year",
":",
"stripeCredentials",
".",
"credit_card_expiry_year",
",",
"cvc",
":",
"stripeCredentials",
".",
"credit_card_cvc",
"}",
";",
"stripe",
".",
"tokens",
".",
"create",
"(",
"{",
"card",
":",
"card",
"}",
",",
"(",
"err",
",",
"token",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"token",
".",
"id",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
helper function to get a stripe token
|
[
"helper",
"function",
"to",
"get",
"a",
"stripe",
"token"
] |
cb4de0048492f51b2fd1488c4d115f373f6cd98f
|
https://github.com/SAP/yaas-nodejs-client-sdk/blob/cb4de0048492f51b2fd1488c4d115f373f6cd98f/examples/checkout.js#L141-L175
|
35,663 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/functionsSearch/index.js
|
functions
|
function functions(node) {
if (!Node.Type.isFunction(node)) {
return Node.Status.noChange(node);
}
for (let i = 0; i < FUNCTIONS.length; i++) {
const nodeStatus = FUNCTIONS[i](node);
if (nodeStatus.hasChanged()) {
return nodeStatus;
}
}
return Node.Status.noChange(node);
}
|
javascript
|
function functions(node) {
if (!Node.Type.isFunction(node)) {
return Node.Status.noChange(node);
}
for (let i = 0; i < FUNCTIONS.length; i++) {
const nodeStatus = FUNCTIONS[i](node);
if (nodeStatus.hasChanged()) {
return nodeStatus;
}
}
return Node.Status.noChange(node);
}
|
[
"function",
"functions",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"Node",
".",
"Type",
".",
"isFunction",
"(",
"node",
")",
")",
"{",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"FUNCTIONS",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"nodeStatus",
"=",
"FUNCTIONS",
"[",
"i",
"]",
"(",
"node",
")",
";",
"if",
"(",
"nodeStatus",
".",
"hasChanged",
"(",
")",
")",
"{",
"return",
"nodeStatus",
";",
"}",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
Evaluates a function call if possible. Returns a Node.Status object.
|
[
"Evaluates",
"a",
"function",
"call",
"if",
"possible",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/functionsSearch/index.js#L20-L32
|
35,664 |
metadelta/metadelta
|
packages/solver/lib/simplifyExpression/basicsSearch/removeExponentBaseOne.js
|
removeExponentBaseOne
|
function removeExponentBaseOne(node) {
if (node.op === '^' && // an exponent with
checks.resolvesToConstant(node.args[1]) && // a power not a symbol and
Node.Type.isConstant(node.args[0]) && // a constant base
node.args[0].value === '1') { // of value 1
const newNode = clone(node.args[0]);
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_EXPONENT_BASE_ONE, node, newNode);
}
return Node.Status.noChange(node);
}
|
javascript
|
function removeExponentBaseOne(node) {
if (node.op === '^' && // an exponent with
checks.resolvesToConstant(node.args[1]) && // a power not a symbol and
Node.Type.isConstant(node.args[0]) && // a constant base
node.args[0].value === '1') { // of value 1
const newNode = clone(node.args[0]);
return Node.Status.nodeChanged(
ChangeTypes.REMOVE_EXPONENT_BASE_ONE, node, newNode);
}
return Node.Status.noChange(node);
}
|
[
"function",
"removeExponentBaseOne",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"op",
"===",
"'^'",
"&&",
"// an exponent with",
"checks",
".",
"resolvesToConstant",
"(",
"node",
".",
"args",
"[",
"1",
"]",
")",
"&&",
"// a power not a symbol and",
"Node",
".",
"Type",
".",
"isConstant",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
"&&",
"// a constant base",
"node",
".",
"args",
"[",
"0",
"]",
".",
"value",
"===",
"'1'",
")",
"{",
"// of value 1",
"const",
"newNode",
"=",
"clone",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
";",
"return",
"Node",
".",
"Status",
".",
"nodeChanged",
"(",
"ChangeTypes",
".",
"REMOVE_EXPONENT_BASE_ONE",
",",
"node",
",",
"newNode",
")",
";",
"}",
"return",
"Node",
".",
"Status",
".",
"noChange",
"(",
"node",
")",
";",
"}"
] |
If `node` is of the form 1^x, reduces it to a node of the form 1. Returns a Node.Status object.
|
[
"If",
"node",
"is",
"of",
"the",
"form",
"1^x",
"reduces",
"it",
"to",
"a",
"node",
"of",
"the",
"form",
"1",
".",
"Returns",
"a",
"Node",
".",
"Status",
"object",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/simplifyExpression/basicsSearch/removeExponentBaseOne.js#L10-L20
|
35,665 |
metadelta/metadelta
|
packages/solver/lib/checks/canRearrangeCoefficient.js
|
canRearrangeCoefficient
|
function canRearrangeCoefficient(node) {
// implicit multiplication doesn't count as multiplication here, since it
// represents a single term.
if (node.op !== '*' || node.implicit) {
return false;
}
if (node.args.length !== 2) {
return false;
}
if (!Node.Type.isConstantOrConstantFraction(node.args[1])) {
return false;
}
if (!Node.PolynomialTerm.isPolynomialTerm(node.args[0])) {
return false;
}
const polyNode = new Node.PolynomialTerm(node.args[0]);
return !polyNode.hasCoeff();
}
|
javascript
|
function canRearrangeCoefficient(node) {
// implicit multiplication doesn't count as multiplication here, since it
// represents a single term.
if (node.op !== '*' || node.implicit) {
return false;
}
if (node.args.length !== 2) {
return false;
}
if (!Node.Type.isConstantOrConstantFraction(node.args[1])) {
return false;
}
if (!Node.PolynomialTerm.isPolynomialTerm(node.args[0])) {
return false;
}
const polyNode = new Node.PolynomialTerm(node.args[0]);
return !polyNode.hasCoeff();
}
|
[
"function",
"canRearrangeCoefficient",
"(",
"node",
")",
"{",
"// implicit multiplication doesn't count as multiplication here, since it",
"// represents a single term.",
"if",
"(",
"node",
".",
"op",
"!==",
"'*'",
"||",
"node",
".",
"implicit",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"node",
".",
"args",
".",
"length",
"!==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"Node",
".",
"Type",
".",
"isConstantOrConstantFraction",
"(",
"node",
".",
"args",
"[",
"1",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"Node",
".",
"PolynomialTerm",
".",
"isPolynomialTerm",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"const",
"polyNode",
"=",
"new",
"Node",
".",
"PolynomialTerm",
"(",
"node",
".",
"args",
"[",
"0",
"]",
")",
";",
"return",
"!",
"polyNode",
".",
"hasCoeff",
"(",
")",
";",
"}"
] |
Returns true if the expression is a multiplication between a constant and polynomial without a coefficient.
|
[
"Returns",
"true",
"if",
"the",
"expression",
"is",
"a",
"multiplication",
"between",
"a",
"constant",
"and",
"polynomial",
"without",
"a",
"coefficient",
"."
] |
ce0de09f5ab9b82da62f09f7807320a6989b9070
|
https://github.com/metadelta/metadelta/blob/ce0de09f5ab9b82da62f09f7807320a6989b9070/packages/solver/lib/checks/canRearrangeCoefficient.js#L7-L25
|
35,666 |
Wildhoney/EmberSockets
|
package/EmberSockets.js
|
connect
|
function connect(params) {
/**
* @property server
* @type {String}
*/
var server = '';
(function determineHost(controller) {
var host = $ember.get(controller, 'host'),
port = $ember.get(controller, 'port'),
scheme = $ember.get(controller, 'secure') === true ? 'https' : 'http',
path = $ember.get(controller, 'path') || '';
if (!host && !port) {
return;
}
// Use the host to compile the connect string.
server = !port ? `${scheme}://${host}/${path}`
: `${scheme}://${host}:${port}/${path}`;
})(this);
// Create the host:port string for connecting, and then attempt to establish
// a connection.
var options = $ember.get(this, 'options') || {},
socket = $io(params ? params.namespace: server, $jq.extend(options, params || {}));
socket.on('error', this.error);
// Store a reference to the socket.
this.set('socket', socket);
/**
* @on connect
*/
socket.on('connect', Ember.run.bind(this, this._listen));
}
|
javascript
|
function connect(params) {
/**
* @property server
* @type {String}
*/
var server = '';
(function determineHost(controller) {
var host = $ember.get(controller, 'host'),
port = $ember.get(controller, 'port'),
scheme = $ember.get(controller, 'secure') === true ? 'https' : 'http',
path = $ember.get(controller, 'path') || '';
if (!host && !port) {
return;
}
// Use the host to compile the connect string.
server = !port ? `${scheme}://${host}/${path}`
: `${scheme}://${host}:${port}/${path}`;
})(this);
// Create the host:port string for connecting, and then attempt to establish
// a connection.
var options = $ember.get(this, 'options') || {},
socket = $io(params ? params.namespace: server, $jq.extend(options, params || {}));
socket.on('error', this.error);
// Store a reference to the socket.
this.set('socket', socket);
/**
* @on connect
*/
socket.on('connect', Ember.run.bind(this, this._listen));
}
|
[
"function",
"connect",
"(",
"params",
")",
"{",
"/**\n * @property server\n * @type {String}\n */",
"var",
"server",
"=",
"''",
";",
"(",
"function",
"determineHost",
"(",
"controller",
")",
"{",
"var",
"host",
"=",
"$ember",
".",
"get",
"(",
"controller",
",",
"'host'",
")",
",",
"port",
"=",
"$ember",
".",
"get",
"(",
"controller",
",",
"'port'",
")",
",",
"scheme",
"=",
"$ember",
".",
"get",
"(",
"controller",
",",
"'secure'",
")",
"===",
"true",
"?",
"'https'",
":",
"'http'",
",",
"path",
"=",
"$ember",
".",
"get",
"(",
"controller",
",",
"'path'",
")",
"||",
"''",
";",
"if",
"(",
"!",
"host",
"&&",
"!",
"port",
")",
"{",
"return",
";",
"}",
"// Use the host to compile the connect string.",
"server",
"=",
"!",
"port",
"?",
"`",
"${",
"scheme",
"}",
"${",
"host",
"}",
"${",
"path",
"}",
"`",
":",
"`",
"${",
"scheme",
"}",
"${",
"host",
"}",
"${",
"port",
"}",
"${",
"path",
"}",
"`",
";",
"}",
")",
"(",
"this",
")",
";",
"// Create the host:port string for connecting, and then attempt to establish",
"// a connection.",
"var",
"options",
"=",
"$ember",
".",
"get",
"(",
"this",
",",
"'options'",
")",
"||",
"{",
"}",
",",
"socket",
"=",
"$io",
"(",
"params",
"?",
"params",
".",
"namespace",
":",
"server",
",",
"$jq",
".",
"extend",
"(",
"options",
",",
"params",
"||",
"{",
"}",
")",
")",
";",
"socket",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"error",
")",
";",
"// Store a reference to the socket.",
"this",
".",
"set",
"(",
"'socket'",
",",
"socket",
")",
";",
"/**\n * @on connect\n */",
"socket",
".",
"on",
"(",
"'connect'",
",",
"Ember",
".",
"run",
".",
"bind",
"(",
"this",
",",
"this",
".",
"_listen",
")",
")",
";",
"}"
] |
Responsible for establishing a connect to the Socket.io server.
@method connect
@param [params={}] {Object}
@return {void}
|
[
"Responsible",
"for",
"establishing",
"a",
"connect",
"to",
"the",
"Socket",
".",
"io",
"server",
"."
] |
ce005e4c75a983592054d6dda0249b5297f9fc64
|
https://github.com/Wildhoney/EmberSockets/blob/ce005e4c75a983592054d6dda0249b5297f9fc64/package/EmberSockets.js#L76-L116
|
35,667 |
Wildhoney/EmberSockets
|
package/EmberSockets.js
|
emit
|
function emit(eventName, params) {
//jshint unused:false
var args = Array.prototype.slice.call(arguments),
scope = $ember.get(this, 'socket');
scope.emit.apply(scope, args);
}
|
javascript
|
function emit(eventName, params) {
//jshint unused:false
var args = Array.prototype.slice.call(arguments),
scope = $ember.get(this, 'socket');
scope.emit.apply(scope, args);
}
|
[
"function",
"emit",
"(",
"eventName",
",",
"params",
")",
"{",
"//jshint unused:false",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
",",
"scope",
"=",
"$ember",
".",
"get",
"(",
"this",
",",
"'socket'",
")",
";",
"scope",
".",
"emit",
".",
"apply",
"(",
"scope",
",",
"args",
")",
";",
"}"
] |
Responsible for emitting an event to the waiting Socket.io server.
@method emit
@param eventName {String}
@param params {Array}
@return {void}
|
[
"Responsible",
"for",
"emitting",
"an",
"event",
"to",
"the",
"waiting",
"Socket",
".",
"io",
"server",
"."
] |
ce005e4c75a983592054d6dda0249b5297f9fc64
|
https://github.com/Wildhoney/EmberSockets/blob/ce005e4c75a983592054d6dda0249b5297f9fc64/package/EmberSockets.js#L139-L147
|
35,668 |
Wildhoney/EmberSockets
|
package/EmberSockets.js
|
_listen
|
function _listen() {
var controllers = $ember.get(this, 'controllers'),
getController = Ember.run.bind(this, this._getController),
events = [],
module = this,
respond = function respond() {
var eventData = Array.prototype.slice.call(arguments);
module._update.call(module, this, eventData);
};
controllers.forEach(function controllerIteration(controllerName) {
// Fetch the controller if it's valid.
var controller = getController(controllerName),
eventNames = controller[this.NAMESPACE];
if (controller) {
// Invoke the `connect` method if it has been defined on this controller.
if (typeof controller[this.NAMESPACE] === 'object' && typeof controller[this.NAMESPACE].connect === 'function') {
controller[this.NAMESPACE].connect.apply(controller);
}
// Iterate over each event defined in the controller's `sockets` hash, so that we can
// keep an eye open for them.
for (var eventName in eventNames) {
if (eventNames.hasOwnProperty(eventName)) {
if (events.indexOf(eventName) !== -1) {
// Don't observe this event if we're already observing it.
continue;
}
// Push the event so we don't listen for it twice.
events.push(eventName);
// Check to ensure the event was not previously registered due to a reconnect
if (!(eventName in $ember.get(module, 'socket')._callbacks)) {
// ...And finally we can register the event to listen for it.
$ember.get(module, 'socket').on(eventName, respond.bind(eventName));
}
}
}
}
}, this);
}
|
javascript
|
function _listen() {
var controllers = $ember.get(this, 'controllers'),
getController = Ember.run.bind(this, this._getController),
events = [],
module = this,
respond = function respond() {
var eventData = Array.prototype.slice.call(arguments);
module._update.call(module, this, eventData);
};
controllers.forEach(function controllerIteration(controllerName) {
// Fetch the controller if it's valid.
var controller = getController(controllerName),
eventNames = controller[this.NAMESPACE];
if (controller) {
// Invoke the `connect` method if it has been defined on this controller.
if (typeof controller[this.NAMESPACE] === 'object' && typeof controller[this.NAMESPACE].connect === 'function') {
controller[this.NAMESPACE].connect.apply(controller);
}
// Iterate over each event defined in the controller's `sockets` hash, so that we can
// keep an eye open for them.
for (var eventName in eventNames) {
if (eventNames.hasOwnProperty(eventName)) {
if (events.indexOf(eventName) !== -1) {
// Don't observe this event if we're already observing it.
continue;
}
// Push the event so we don't listen for it twice.
events.push(eventName);
// Check to ensure the event was not previously registered due to a reconnect
if (!(eventName in $ember.get(module, 'socket')._callbacks)) {
// ...And finally we can register the event to listen for it.
$ember.get(module, 'socket').on(eventName, respond.bind(eventName));
}
}
}
}
}, this);
}
|
[
"function",
"_listen",
"(",
")",
"{",
"var",
"controllers",
"=",
"$ember",
".",
"get",
"(",
"this",
",",
"'controllers'",
")",
",",
"getController",
"=",
"Ember",
".",
"run",
".",
"bind",
"(",
"this",
",",
"this",
".",
"_getController",
")",
",",
"events",
"=",
"[",
"]",
",",
"module",
"=",
"this",
",",
"respond",
"=",
"function",
"respond",
"(",
")",
"{",
"var",
"eventData",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"module",
".",
"_update",
".",
"call",
"(",
"module",
",",
"this",
",",
"eventData",
")",
";",
"}",
";",
"controllers",
".",
"forEach",
"(",
"function",
"controllerIteration",
"(",
"controllerName",
")",
"{",
"// Fetch the controller if it's valid.",
"var",
"controller",
"=",
"getController",
"(",
"controllerName",
")",
",",
"eventNames",
"=",
"controller",
"[",
"this",
".",
"NAMESPACE",
"]",
";",
"if",
"(",
"controller",
")",
"{",
"// Invoke the `connect` method if it has been defined on this controller.",
"if",
"(",
"typeof",
"controller",
"[",
"this",
".",
"NAMESPACE",
"]",
"===",
"'object'",
"&&",
"typeof",
"controller",
"[",
"this",
".",
"NAMESPACE",
"]",
".",
"connect",
"===",
"'function'",
")",
"{",
"controller",
"[",
"this",
".",
"NAMESPACE",
"]",
".",
"connect",
".",
"apply",
"(",
"controller",
")",
";",
"}",
"// Iterate over each event defined in the controller's `sockets` hash, so that we can",
"// keep an eye open for them.",
"for",
"(",
"var",
"eventName",
"in",
"eventNames",
")",
"{",
"if",
"(",
"eventNames",
".",
"hasOwnProperty",
"(",
"eventName",
")",
")",
"{",
"if",
"(",
"events",
".",
"indexOf",
"(",
"eventName",
")",
"!==",
"-",
"1",
")",
"{",
"// Don't observe this event if we're already observing it.",
"continue",
";",
"}",
"// Push the event so we don't listen for it twice.",
"events",
".",
"push",
"(",
"eventName",
")",
";",
"// Check to ensure the event was not previously registered due to a reconnect",
"if",
"(",
"!",
"(",
"eventName",
"in",
"$ember",
".",
"get",
"(",
"module",
",",
"'socket'",
")",
".",
"_callbacks",
")",
")",
"{",
"// ...And finally we can register the event to listen for it.",
"$ember",
".",
"get",
"(",
"module",
",",
"'socket'",
")",
".",
"on",
"(",
"eventName",
",",
"respond",
".",
"bind",
"(",
"eventName",
")",
")",
";",
"}",
"}",
"}",
"}",
"}",
",",
"this",
")",
";",
"}"
] |
Responsible for listening to events from Socket.io, and updating controller properties that
subscribe to those events.
@method _listen
@return {void}
@private
|
[
"Responsible",
"for",
"listening",
"to",
"events",
"from",
"Socket",
".",
"io",
"and",
"updating",
"controller",
"properties",
"that",
"subscribe",
"to",
"those",
"events",
"."
] |
ce005e4c75a983592054d6dda0249b5297f9fc64
|
https://github.com/Wildhoney/EmberSockets/blob/ce005e4c75a983592054d6dda0249b5297f9fc64/package/EmberSockets.js#L157-L211
|
35,669 |
Wildhoney/EmberSockets
|
package/EmberSockets.js
|
_getController
|
function _getController(name) {
// Format the `name` to match what the lookup container is expecting, and then
// we'll locate the controller from the `container`.
name = `controller:${name}`;
var controller = Ember.getOwner(this).lookup(name);
if (!controller || (this.NAMESPACE in controller === false)) {
// Don't do anything with this controller if it hasn't defined a `sockets` hash.
return false;
}
return controller;
}
|
javascript
|
function _getController(name) {
// Format the `name` to match what the lookup container is expecting, and then
// we'll locate the controller from the `container`.
name = `controller:${name}`;
var controller = Ember.getOwner(this).lookup(name);
if (!controller || (this.NAMESPACE in controller === false)) {
// Don't do anything with this controller if it hasn't defined a `sockets` hash.
return false;
}
return controller;
}
|
[
"function",
"_getController",
"(",
"name",
")",
"{",
"// Format the `name` to match what the lookup container is expecting, and then",
"// we'll locate the controller from the `container`.",
"name",
"=",
"`",
"${",
"name",
"}",
"`",
";",
"var",
"controller",
"=",
"Ember",
".",
"getOwner",
"(",
"this",
")",
".",
"lookup",
"(",
"name",
")",
";",
"if",
"(",
"!",
"controller",
"||",
"(",
"this",
".",
"NAMESPACE",
"in",
"controller",
"===",
"false",
")",
")",
"{",
"// Don't do anything with this controller if it hasn't defined a `sockets` hash.",
"return",
"false",
";",
"}",
"return",
"controller",
";",
"}"
] |
Responsible for retrieving a controller if it exists, and if it has defined a `events` hash.
@method _getController
@param name {String}
@return {Object|Boolean}
@private
|
[
"Responsible",
"for",
"retrieving",
"a",
"controller",
"if",
"it",
"exists",
"and",
"if",
"it",
"has",
"defined",
"a",
"events",
"hash",
"."
] |
ce005e4c75a983592054d6dda0249b5297f9fc64
|
https://github.com/Wildhoney/EmberSockets/blob/ce005e4c75a983592054d6dda0249b5297f9fc64/package/EmberSockets.js#L292-L306
|
35,670 |
craterdog-bali/js-bali-component-framework
|
src/composites/Parameters.js
|
Parameters
|
function Parameters(collection) {
abstractions.Composite.call(this, utilities.types.PARAMETERS);
// the parameters are immutable so the methods are included in the constructor
const duplicator = new utilities.Duplicator();
const copy = duplicator.duplicateComponent(collection);
this.getCollection = function() { return copy; };
this.toArray = function() {
const array = copy.toArray();
return array;
};
this.acceptVisitor = function(visitor) {
visitor.visitParameters(this);
};
this.getSize = function() {
const size = copy.getSize();
return size;
};
this.getParameter = function(key, index) {
var value;
index = index || 1; // default is the first parameter
if (copy.getTypeId() === utilities.types.CATALOG) {
value = copy.getValue(key);
} else {
value = copy.getItem(index);
}
return value;
};
this.setParameter = function(key, value, index) {
index = index || 1; // default is the first parameter
if (copy.getTypeId() === utilities.types.CATALOG) {
copy.setValue(key, value);
} else {
copy.setItem(index, value);
}
};
return this;
}
|
javascript
|
function Parameters(collection) {
abstractions.Composite.call(this, utilities.types.PARAMETERS);
// the parameters are immutable so the methods are included in the constructor
const duplicator = new utilities.Duplicator();
const copy = duplicator.duplicateComponent(collection);
this.getCollection = function() { return copy; };
this.toArray = function() {
const array = copy.toArray();
return array;
};
this.acceptVisitor = function(visitor) {
visitor.visitParameters(this);
};
this.getSize = function() {
const size = copy.getSize();
return size;
};
this.getParameter = function(key, index) {
var value;
index = index || 1; // default is the first parameter
if (copy.getTypeId() === utilities.types.CATALOG) {
value = copy.getValue(key);
} else {
value = copy.getItem(index);
}
return value;
};
this.setParameter = function(key, value, index) {
index = index || 1; // default is the first parameter
if (copy.getTypeId() === utilities.types.CATALOG) {
copy.setValue(key, value);
} else {
copy.setItem(index, value);
}
};
return this;
}
|
[
"function",
"Parameters",
"(",
"collection",
")",
"{",
"abstractions",
".",
"Composite",
".",
"call",
"(",
"this",
",",
"utilities",
".",
"types",
".",
"PARAMETERS",
")",
";",
"// the parameters are immutable so the methods are included in the constructor",
"const",
"duplicator",
"=",
"new",
"utilities",
".",
"Duplicator",
"(",
")",
";",
"const",
"copy",
"=",
"duplicator",
".",
"duplicateComponent",
"(",
"collection",
")",
";",
"this",
".",
"getCollection",
"=",
"function",
"(",
")",
"{",
"return",
"copy",
";",
"}",
";",
"this",
".",
"toArray",
"=",
"function",
"(",
")",
"{",
"const",
"array",
"=",
"copy",
".",
"toArray",
"(",
")",
";",
"return",
"array",
";",
"}",
";",
"this",
".",
"acceptVisitor",
"=",
"function",
"(",
"visitor",
")",
"{",
"visitor",
".",
"visitParameters",
"(",
"this",
")",
";",
"}",
";",
"this",
".",
"getSize",
"=",
"function",
"(",
")",
"{",
"const",
"size",
"=",
"copy",
".",
"getSize",
"(",
")",
";",
"return",
"size",
";",
"}",
";",
"this",
".",
"getParameter",
"=",
"function",
"(",
"key",
",",
"index",
")",
"{",
"var",
"value",
";",
"index",
"=",
"index",
"||",
"1",
";",
"// default is the first parameter",
"if",
"(",
"copy",
".",
"getTypeId",
"(",
")",
"===",
"utilities",
".",
"types",
".",
"CATALOG",
")",
"{",
"value",
"=",
"copy",
".",
"getValue",
"(",
"key",
")",
";",
"}",
"else",
"{",
"value",
"=",
"copy",
".",
"getItem",
"(",
"index",
")",
";",
"}",
"return",
"value",
";",
"}",
";",
"this",
".",
"setParameter",
"=",
"function",
"(",
"key",
",",
"value",
",",
"index",
")",
"{",
"index",
"=",
"index",
"||",
"1",
";",
"// default is the first parameter",
"if",
"(",
"copy",
".",
"getTypeId",
"(",
")",
"===",
"utilities",
".",
"types",
".",
"CATALOG",
")",
"{",
"copy",
".",
"setValue",
"(",
"key",
",",
"value",
")",
";",
"}",
"else",
"{",
"copy",
".",
"setItem",
"(",
"index",
",",
"value",
")",
";",
"}",
"}",
";",
"return",
"this",
";",
"}"
] |
PUBLIC CONSTRUCTORS
This constructor creates a new parameter catalog or list.
@constructor
@param {Collection} collection The collection of parameters.
@returns {Parameters} The new parameter list.
|
[
"PUBLIC",
"CONSTRUCTORS",
"This",
"constructor",
"creates",
"a",
"new",
"parameter",
"catalog",
"or",
"list",
"."
] |
57279245e44d6ceef4debdb1d6132f48e464dcb8
|
https://github.com/craterdog-bali/js-bali-component-framework/blob/57279245e44d6ceef4debdb1d6132f48e464dcb8/src/composites/Parameters.js#L29-L73
|
35,671 |
craterdog-bali/js-bali-component-framework
|
src/elements/Duration.js
|
Duration
|
function Duration(value, parameters) {
abstractions.Element.call(this, utilities.types.DURATION, parameters);
value = value || 0; // the default value
value = moment.duration(value);
// since this element is immutable the value must be read-only
this.getValue = function() { return value; };
return this;
}
|
javascript
|
function Duration(value, parameters) {
abstractions.Element.call(this, utilities.types.DURATION, parameters);
value = value || 0; // the default value
value = moment.duration(value);
// since this element is immutable the value must be read-only
this.getValue = function() { return value; };
return this;
}
|
[
"function",
"Duration",
"(",
"value",
",",
"parameters",
")",
"{",
"abstractions",
".",
"Element",
".",
"call",
"(",
"this",
",",
"utilities",
".",
"types",
".",
"DURATION",
",",
"parameters",
")",
";",
"value",
"=",
"value",
"||",
"0",
";",
"// the default value",
"value",
"=",
"moment",
".",
"duration",
"(",
"value",
")",
";",
"// since this element is immutable the value must be read-only",
"this",
".",
"getValue",
"=",
"function",
"(",
")",
"{",
"return",
"value",
";",
"}",
";",
"return",
"this",
";",
"}"
] |
PUBLIC CONSTRUCTOR
This constructor creates a new duration element using the specified value.
@param {String|Number} value The source string the duration.
@param {Parameters} parameters Optional parameters used to parameterize this element.
@returns {Duration} The new duration element.
|
[
"PUBLIC",
"CONSTRUCTOR",
"This",
"constructor",
"creates",
"a",
"new",
"duration",
"element",
"using",
"the",
"specified",
"value",
"."
] |
57279245e44d6ceef4debdb1d6132f48e464dcb8
|
https://github.com/craterdog-bali/js-bali-component-framework/blob/57279245e44d6ceef4debdb1d6132f48e464dcb8/src/elements/Duration.js#L31-L40
|
35,672 |
KleeGroup/focus-notifications
|
src/component/notification-center.js
|
select
|
function select(state) {
const {notificationList, visibilityFilter, ...otherStateProperties} = state;
return {
//select the notification list from the state
notificationList: selectNotifications(notificationList, visibilityFilter),
visibilityFilter,
...otherStateProperties
};
}
|
javascript
|
function select(state) {
const {notificationList, visibilityFilter, ...otherStateProperties} = state;
return {
//select the notification list from the state
notificationList: selectNotifications(notificationList, visibilityFilter),
visibilityFilter,
...otherStateProperties
};
}
|
[
"function",
"select",
"(",
"state",
")",
"{",
"const",
"{",
"notificationList",
",",
"visibilityFilter",
",",
"...",
"otherStateProperties",
"}",
"=",
"state",
";",
"return",
"{",
"//select the notification list from the state",
"notificationList",
":",
"selectNotifications",
"(",
"notificationList",
",",
"visibilityFilter",
")",
",",
"visibilityFilter",
",",
"...",
"otherStateProperties",
"}",
";",
"}"
] |
Select the part of the state.
|
[
"Select",
"the",
"part",
"of",
"the",
"state",
"."
] |
b9a529264b625a12c3d8d479f839f36f77b674f6
|
https://github.com/KleeGroup/focus-notifications/blob/b9a529264b625a12c3d8d479f839f36f77b674f6/src/component/notification-center.js#L98-L106
|
35,673 |
kissyteam/kissy-xtemplate
|
lib/kissy/5.0.0-alpha.3/build/tree-debug.js
|
function () {
var self = this;
self.renderChildren.apply(self, arguments); // only sync child sub tree at root node
// only sync child sub tree at root node
if (self === self.get('tree')) {
updateSubTreeStatus(self, self, -1, 0);
}
}
|
javascript
|
function () {
var self = this;
self.renderChildren.apply(self, arguments); // only sync child sub tree at root node
// only sync child sub tree at root node
if (self === self.get('tree')) {
updateSubTreeStatus(self, self, -1, 0);
}
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"renderChildren",
".",
"apply",
"(",
"self",
",",
"arguments",
")",
";",
"// only sync child sub tree at root node",
"// only sync child sub tree at root node",
"if",
"(",
"self",
"===",
"self",
".",
"get",
"(",
"'tree'",
")",
")",
"{",
"updateSubTreeStatus",
"(",
"self",
",",
"self",
",",
"-",
"1",
",",
"0",
")",
";",
"}",
"}"
] |
override root 's renderChildren to apply depth and css recursively
|
[
"override",
"root",
"s",
"renderChildren",
"to",
"apply",
"depth",
"and",
"css",
"recursively"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/5.0.0-alpha.3/build/tree-debug.js#L276-L283
|
|
35,674 |
kissyteam/kissy-xtemplate
|
lib/kissy/5.0.0-alpha.3/build/tree-debug.js
|
function () {
var self = this;
self.set('expanded', true);
util.each(self.get('children'), function (c) {
c.expandAll();
});
}
|
javascript
|
function () {
var self = this;
self.set('expanded', true);
util.each(self.get('children'), function (c) {
c.expandAll();
});
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"set",
"(",
"'expanded'",
",",
"true",
")",
";",
"util",
".",
"each",
"(",
"self",
".",
"get",
"(",
"'children'",
")",
",",
"function",
"(",
"c",
")",
"{",
"c",
".",
"expandAll",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Expand all descend nodes of current node
|
[
"Expand",
"all",
"descend",
"nodes",
"of",
"current",
"node"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/5.0.0-alpha.3/build/tree-debug.js#L331-L337
|
|
35,675 |
kissyteam/kissy-xtemplate
|
lib/kissy/5.0.0-alpha.3/build/tree-debug.js
|
function () {
var self = this;
self.set('expanded', false);
util.each(self.get('children'), function (c) {
c.collapseAll();
});
}
|
javascript
|
function () {
var self = this;
self.set('expanded', false);
util.each(self.get('children'), function (c) {
c.collapseAll();
});
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"set",
"(",
"'expanded'",
",",
"false",
")",
";",
"util",
".",
"each",
"(",
"self",
".",
"get",
"(",
"'children'",
")",
",",
"function",
"(",
"c",
")",
"{",
"c",
".",
"collapseAll",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Collapse all descend nodes of current node
|
[
"Collapse",
"all",
"descend",
"nodes",
"of",
"current",
"node"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/5.0.0-alpha.3/build/tree-debug.js#L341-L347
|
|
35,676 |
kissyteam/kissy-xtemplate
|
lib/kissy/5.0.0-alpha.3/build/tree-debug.js
|
getPreviousVisibleNode
|
function getPreviousVisibleNode(self) {
var prev = self.prev();
if (!prev) {
prev = self.get('parent');
} else {
prev = getLastVisibleDescendant(prev);
}
return prev;
}
|
javascript
|
function getPreviousVisibleNode(self) {
var prev = self.prev();
if (!prev) {
prev = self.get('parent');
} else {
prev = getLastVisibleDescendant(prev);
}
return prev;
}
|
[
"function",
"getPreviousVisibleNode",
"(",
"self",
")",
"{",
"var",
"prev",
"=",
"self",
".",
"prev",
"(",
")",
";",
"if",
"(",
"!",
"prev",
")",
"{",
"prev",
"=",
"self",
".",
"get",
"(",
"'parent'",
")",
";",
"}",
"else",
"{",
"prev",
"=",
"getLastVisibleDescendant",
"(",
"prev",
")",
";",
"}",
"return",
"prev",
";",
"}"
] |
not same with _4ePreviousSourceNode in editor ! not same with _4ePreviousSourceNode in editor !
|
[
"not",
"same",
"with",
"_4ePreviousSourceNode",
"in",
"editor",
"!",
"not",
"same",
"with",
"_4ePreviousSourceNode",
"in",
"editor",
"!"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/5.0.0-alpha.3/build/tree-debug.js#L504-L512
|
35,677 |
kissyteam/kissy-xtemplate
|
lib/kissy/5.0.0-alpha.3/build/tree-debug.js
|
getNextVisibleNode
|
function getNextVisibleNode(self) {
var children = self.get('children'), n, parent;
if (self.get('expanded') && children.length) {
return children[0];
} // 没有展开或者根本没有儿子节点
// 深度遍历的下一个
// 没有展开或者根本没有儿子节点
// 深度遍历的下一个
n = self.next();
parent = self;
while (!n && (parent = parent.get('parent'))) {
n = parent.next();
}
return n;
}
|
javascript
|
function getNextVisibleNode(self) {
var children = self.get('children'), n, parent;
if (self.get('expanded') && children.length) {
return children[0];
} // 没有展开或者根本没有儿子节点
// 深度遍历的下一个
// 没有展开或者根本没有儿子节点
// 深度遍历的下一个
n = self.next();
parent = self;
while (!n && (parent = parent.get('parent'))) {
n = parent.next();
}
return n;
}
|
[
"function",
"getNextVisibleNode",
"(",
"self",
")",
"{",
"var",
"children",
"=",
"self",
".",
"get",
"(",
"'children'",
")",
",",
"n",
",",
"parent",
";",
"if",
"(",
"self",
".",
"get",
"(",
"'expanded'",
")",
"&&",
"children",
".",
"length",
")",
"{",
"return",
"children",
"[",
"0",
"]",
";",
"}",
"// 没有展开或者根本没有儿子节点",
"// 深度遍历的下一个",
"// 没有展开或者根本没有儿子节点",
"// 深度遍历的下一个",
"n",
"=",
"self",
".",
"next",
"(",
")",
";",
"parent",
"=",
"self",
";",
"while",
"(",
"!",
"n",
"&&",
"(",
"parent",
"=",
"parent",
".",
"get",
"(",
"'parent'",
")",
")",
")",
"{",
"n",
"=",
"parent",
".",
"next",
"(",
")",
";",
"}",
"return",
"n",
";",
"}"
] |
similar to _4eNextSourceNode in editor similar to _4eNextSourceNode in editor
|
[
"similar",
"to",
"_4eNextSourceNode",
"in",
"editor",
"similar",
"to",
"_4eNextSourceNode",
"in",
"editor"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/5.0.0-alpha.3/build/tree-debug.js#L514-L528
|
35,678 |
taskcluster/taskcluster-lib-validate
|
src/publish.js
|
writeFile
|
function writeFile(filename, content) {
fs.writeFileSync(filename, JSON.stringify(content, null, 2));
}
|
javascript
|
function writeFile(filename, content) {
fs.writeFileSync(filename, JSON.stringify(content, null, 2));
}
|
[
"function",
"writeFile",
"(",
"filename",
",",
"content",
")",
"{",
"fs",
".",
"writeFileSync",
"(",
"filename",
",",
"JSON",
".",
"stringify",
"(",
"content",
",",
"null",
",",
"2",
")",
")",
";",
"}"
] |
Write the schema to a local file. This is useful for debugging purposes
mainly.
|
[
"Write",
"the",
"schema",
"to",
"a",
"local",
"file",
".",
"This",
"is",
"useful",
"for",
"debugging",
"purposes",
"mainly",
"."
] |
825a80d37834f8c722ca256671ee0d2713fbecbc
|
https://github.com/taskcluster/taskcluster-lib-validate/blob/825a80d37834f8c722ca256671ee0d2713fbecbc/src/publish.js#L81-L83
|
35,679 |
taskcluster/taskcluster-lib-validate
|
src/publish.js
|
preview
|
function preview(name, content) {
console.log('=======');
console.log('JSON SCHEMA PREVIEW BEGIN: ' + name);
console.log('=======');
console.log(JSON.stringify(content, null, 2));
console.log('=======');
console.log('JSON SCHEMA PREVIEW END: ' + name);
return Promise.resolve();
}
|
javascript
|
function preview(name, content) {
console.log('=======');
console.log('JSON SCHEMA PREVIEW BEGIN: ' + name);
console.log('=======');
console.log(JSON.stringify(content, null, 2));
console.log('=======');
console.log('JSON SCHEMA PREVIEW END: ' + name);
return Promise.resolve();
}
|
[
"function",
"preview",
"(",
"name",
",",
"content",
")",
"{",
"console",
".",
"log",
"(",
"'======='",
")",
";",
"console",
".",
"log",
"(",
"'JSON SCHEMA PREVIEW BEGIN: '",
"+",
"name",
")",
";",
"console",
".",
"log",
"(",
"'======='",
")",
";",
"console",
".",
"log",
"(",
"JSON",
".",
"stringify",
"(",
"content",
",",
"null",
",",
"2",
")",
")",
";",
"console",
".",
"log",
"(",
"'======='",
")",
";",
"console",
".",
"log",
"(",
"'JSON SCHEMA PREVIEW END: '",
"+",
"name",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}"
] |
Write the generated schema to the console as pretty-json output. This is
useful for debugging purposes
|
[
"Write",
"the",
"generated",
"schema",
"to",
"the",
"console",
"as",
"pretty",
"-",
"json",
"output",
".",
"This",
"is",
"useful",
"for",
"debugging",
"purposes"
] |
825a80d37834f8c722ca256671ee0d2713fbecbc
|
https://github.com/taskcluster/taskcluster-lib-validate/blob/825a80d37834f8c722ca256671ee0d2713fbecbc/src/publish.js#L89-L97
|
35,680 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
normalizeArray
|
function normalizeArray(parts, allowAboveRoot) {
// level above root
var up = 0,
i = parts.length - 1,
// splice costs a lot in ie
// use new array instead
newParts = [],
last;
for (; i >= 0; i--) {
last = parts[i];
if (last !== '.') {
if (last === '..') {
up++;
} else if (up) {
up--;
} else {
newParts[newParts.length] = last;
}
}
}
// if allow above root, has to add ..
if (allowAboveRoot) {
for (; up--; up) {
newParts[newParts.length] = '..';
}
}
newParts = newParts.reverse();
return newParts;
}
|
javascript
|
function normalizeArray(parts, allowAboveRoot) {
// level above root
var up = 0,
i = parts.length - 1,
// splice costs a lot in ie
// use new array instead
newParts = [],
last;
for (; i >= 0; i--) {
last = parts[i];
if (last !== '.') {
if (last === '..') {
up++;
} else if (up) {
up--;
} else {
newParts[newParts.length] = last;
}
}
}
// if allow above root, has to add ..
if (allowAboveRoot) {
for (; up--; up) {
newParts[newParts.length] = '..';
}
}
newParts = newParts.reverse();
return newParts;
}
|
[
"function",
"normalizeArray",
"(",
"parts",
",",
"allowAboveRoot",
")",
"{",
"// level above root",
"var",
"up",
"=",
"0",
",",
"i",
"=",
"parts",
".",
"length",
"-",
"1",
",",
"// splice costs a lot in ie",
"// use new array instead",
"newParts",
"=",
"[",
"]",
",",
"last",
";",
"for",
"(",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"last",
"=",
"parts",
"[",
"i",
"]",
";",
"if",
"(",
"last",
"!==",
"'.'",
")",
"{",
"if",
"(",
"last",
"===",
"'..'",
")",
"{",
"up",
"++",
";",
"}",
"else",
"if",
"(",
"up",
")",
"{",
"up",
"--",
";",
"}",
"else",
"{",
"newParts",
"[",
"newParts",
".",
"length",
"]",
"=",
"last",
";",
"}",
"}",
"}",
"// if allow above root, has to add ..",
"if",
"(",
"allowAboveRoot",
")",
"{",
"for",
"(",
";",
"up",
"--",
";",
"up",
")",
"{",
"newParts",
"[",
"newParts",
".",
"length",
"]",
"=",
"'..'",
";",
"}",
"}",
"newParts",
"=",
"newParts",
".",
"reverse",
"(",
")",
";",
"return",
"newParts",
";",
"}"
] |
Remove .. and . in path array
|
[
"Remove",
"..",
"and",
".",
"in",
"path",
"array"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L632-L664
|
35,681 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (path) {
var result = path.match(splitPathRe) || [],
root = result[1] || '',
dir = result[2] || '';
if (!root && !dir) {
// No dirname
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substring(0, dir.length - 1);
}
return root + dir;
}
|
javascript
|
function (path) {
var result = path.match(splitPathRe) || [],
root = result[1] || '',
dir = result[2] || '';
if (!root && !dir) {
// No dirname
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substring(0, dir.length - 1);
}
return root + dir;
}
|
[
"function",
"(",
"path",
")",
"{",
"var",
"result",
"=",
"path",
".",
"match",
"(",
"splitPathRe",
")",
"||",
"[",
"]",
",",
"root",
"=",
"result",
"[",
"1",
"]",
"||",
"''",
",",
"dir",
"=",
"result",
"[",
"2",
"]",
"||",
"''",
";",
"if",
"(",
"!",
"root",
"&&",
"!",
"dir",
")",
"{",
"// No dirname",
"return",
"'.'",
";",
"}",
"if",
"(",
"dir",
")",
"{",
"// It has a dirname, strip trailing slash",
"dir",
"=",
"dir",
".",
"substring",
"(",
"0",
",",
"dir",
".",
"length",
"-",
"1",
")",
";",
"}",
"return",
"root",
"+",
"dir",
";",
"}"
] |
Get dirname of path
@param {String} path
@return {String}
|
[
"Get",
"dirname",
"of",
"path"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L806-L822
|
|
35,682 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function () {
var self = this,
count = 0,
_queryMap,
k;
parseQuery(self);
_queryMap = self._queryMap;
for (k in _queryMap) {
if (S.isArray(_queryMap[k])) {
count += _queryMap[k].length;
} else {
count++;
}
}
return count;
}
|
javascript
|
function () {
var self = this,
count = 0,
_queryMap,
k;
parseQuery(self);
_queryMap = self._queryMap;
for (k in _queryMap) {
if (S.isArray(_queryMap[k])) {
count += _queryMap[k].length;
} else {
count++;
}
}
return count;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"count",
"=",
"0",
",",
"_queryMap",
",",
"k",
";",
"parseQuery",
"(",
"self",
")",
";",
"_queryMap",
"=",
"self",
".",
"_queryMap",
";",
"for",
"(",
"k",
"in",
"_queryMap",
")",
"{",
"if",
"(",
"S",
".",
"isArray",
"(",
"_queryMap",
"[",
"k",
"]",
")",
")",
"{",
"count",
"+=",
"_queryMap",
"[",
"k",
"]",
".",
"length",
";",
"}",
"else",
"{",
"count",
"++",
";",
"}",
"}",
"return",
"count",
";",
"}"
] |
Parameter count.
@return {Number}
|
[
"Parameter",
"count",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L958-L975
|
|
35,683 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (key) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (key) {
return key in _queryMap;
} else {
return !S.isEmptyObject(_queryMap);
}
}
|
javascript
|
function (key) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (key) {
return key in _queryMap;
} else {
return !S.isEmptyObject(_queryMap);
}
}
|
[
"function",
"(",
"key",
")",
"{",
"var",
"self",
"=",
"this",
",",
"_queryMap",
";",
"parseQuery",
"(",
"self",
")",
";",
"_queryMap",
"=",
"self",
".",
"_queryMap",
";",
"if",
"(",
"key",
")",
"{",
"return",
"key",
"in",
"_queryMap",
";",
"}",
"else",
"{",
"return",
"!",
"S",
".",
"isEmptyObject",
"(",
"_queryMap",
")",
";",
"}",
"}"
] |
judge whether has query parameter
@param {String} [key]
|
[
"judge",
"whether",
"has",
"query",
"parameter"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L981-L990
|
|
35,684 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (key) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (key) {
return _queryMap[key];
} else {
return _queryMap;
}
}
|
javascript
|
function (key) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (key) {
return _queryMap[key];
} else {
return _queryMap;
}
}
|
[
"function",
"(",
"key",
")",
"{",
"var",
"self",
"=",
"this",
",",
"_queryMap",
";",
"parseQuery",
"(",
"self",
")",
";",
"_queryMap",
"=",
"self",
".",
"_queryMap",
";",
"if",
"(",
"key",
")",
"{",
"return",
"_queryMap",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"_queryMap",
";",
"}",
"}"
] |
Return parameter value corresponding to current key
@param {String} [key]
|
[
"Return",
"parameter",
"value",
"corresponding",
"to",
"current",
"key"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L996-L1005
|
|
35,685 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (key, value) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (typeof key === 'string') {
self._queryMap[key] = value;
} else {
if (key instanceof Query) {
key = key.get();
}
S.each(key, function (v, k) {
_queryMap[k] = v;
});
}
return self;
}
|
javascript
|
function (key, value) {
var self = this, _queryMap;
parseQuery(self);
_queryMap = self._queryMap;
if (typeof key === 'string') {
self._queryMap[key] = value;
} else {
if (key instanceof Query) {
key = key.get();
}
S.each(key, function (v, k) {
_queryMap[k] = v;
});
}
return self;
}
|
[
"function",
"(",
"key",
",",
"value",
")",
"{",
"var",
"self",
"=",
"this",
",",
"_queryMap",
";",
"parseQuery",
"(",
"self",
")",
";",
"_queryMap",
"=",
"self",
".",
"_queryMap",
";",
"if",
"(",
"typeof",
"key",
"===",
"'string'",
")",
"{",
"self",
".",
"_queryMap",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"key",
"instanceof",
"Query",
")",
"{",
"key",
"=",
"key",
".",
"get",
"(",
")",
";",
"}",
"S",
".",
"each",
"(",
"key",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"_queryMap",
"[",
"k",
"]",
"=",
"v",
";",
"}",
")",
";",
"}",
"return",
"self",
";",
"}"
] |
Set parameter value corresponding to current key
@param {String} key
@param value
@chainable
|
[
"Set",
"parameter",
"value",
"corresponding",
"to",
"current",
"key"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L1023-L1038
|
|
35,686 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (key) {
var self = this;
parseQuery(self);
if (key) {
delete self._queryMap[key];
} else {
self._queryMap = {};
}
return self;
}
|
javascript
|
function (key) {
var self = this;
parseQuery(self);
if (key) {
delete self._queryMap[key];
} else {
self._queryMap = {};
}
return self;
}
|
[
"function",
"(",
"key",
")",
"{",
"var",
"self",
"=",
"this",
";",
"parseQuery",
"(",
"self",
")",
";",
"if",
"(",
"key",
")",
"{",
"delete",
"self",
".",
"_queryMap",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"self",
".",
"_queryMap",
"=",
"{",
"}",
";",
"}",
"return",
"self",
";",
"}"
] |
Remove parameter with specified name.
@param {String} key
@chainable
|
[
"Remove",
"parameter",
"with",
"specified",
"name",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L1045-L1055
|
|
35,687 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (serializeArray) {
var self = this;
parseQuery(self);
return S.param(self._queryMap, undefined, undefined, serializeArray);
}
|
javascript
|
function (serializeArray) {
var self = this;
parseQuery(self);
return S.param(self._queryMap, undefined, undefined, serializeArray);
}
|
[
"function",
"(",
"serializeArray",
")",
"{",
"var",
"self",
"=",
"this",
";",
"parseQuery",
"(",
"self",
")",
";",
"return",
"S",
".",
"param",
"(",
"self",
".",
"_queryMap",
",",
"undefined",
",",
"undefined",
",",
"serializeArray",
")",
";",
"}"
] |
Serialize query to string.
@param {Boolean} [serializeArray=true]
whether append [] to key name when value 's type is array
|
[
"Serialize",
"query",
"to",
"string",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L1093-L1097
|
|
35,688 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function () {
var uri = new Uri(), self = this;
S.each(REG_INFO, function (index, key) {
uri[key] = self[key];
});
uri.query = uri.query.clone();
return uri;
}
|
javascript
|
function () {
var uri = new Uri(), self = this;
S.each(REG_INFO, function (index, key) {
uri[key] = self[key];
});
uri.query = uri.query.clone();
return uri;
}
|
[
"function",
"(",
")",
"{",
"var",
"uri",
"=",
"new",
"Uri",
"(",
")",
",",
"self",
"=",
"this",
";",
"S",
".",
"each",
"(",
"REG_INFO",
",",
"function",
"(",
"index",
",",
"key",
")",
"{",
"uri",
"[",
"key",
"]",
"=",
"self",
"[",
"key",
"]",
";",
"}",
")",
";",
"uri",
".",
"query",
"=",
"uri",
".",
"query",
".",
"clone",
"(",
")",
";",
"return",
"uri",
";",
"}"
] |
Return a cloned new instance.
@return {KISSY.Uri}
|
[
"Return",
"a",
"cloned",
"new",
"instance",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L1203-L1210
|
|
35,689 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (module) {
var factory = module.factory,
exports;
if (typeof factory === 'function') {
// compatible and efficiency
// KISSY.add(function(S,undefined){})
var require;
if (module.requires && module.requires.length && module.cjs) {
require = bind(module.require, module);
}
// 需要解开 index,相对路径
// 但是需要保留 alias,防止值不对应
//noinspection JSUnresolvedFunction
exports = factory.apply(module,
// KISSY.add(function(S){module.require}) lazy initialize
(module.cjs ? [S, require, module.exports, module] :
Utils.getModules(module.getRequiresWithAlias())));
if (exports !== undefined) {
//noinspection JSUndefinedPropertyAssignment
module.exports = exports;
}
} else {
//noinspection JSUndefinedPropertyAssignment
module.exports = factory;
}
module.status = ATTACHED;
}
|
javascript
|
function (module) {
var factory = module.factory,
exports;
if (typeof factory === 'function') {
// compatible and efficiency
// KISSY.add(function(S,undefined){})
var require;
if (module.requires && module.requires.length && module.cjs) {
require = bind(module.require, module);
}
// 需要解开 index,相对路径
// 但是需要保留 alias,防止值不对应
//noinspection JSUnresolvedFunction
exports = factory.apply(module,
// KISSY.add(function(S){module.require}) lazy initialize
(module.cjs ? [S, require, module.exports, module] :
Utils.getModules(module.getRequiresWithAlias())));
if (exports !== undefined) {
//noinspection JSUndefinedPropertyAssignment
module.exports = exports;
}
} else {
//noinspection JSUndefinedPropertyAssignment
module.exports = factory;
}
module.status = ATTACHED;
}
|
[
"function",
"(",
"module",
")",
"{",
"var",
"factory",
"=",
"module",
".",
"factory",
",",
"exports",
";",
"if",
"(",
"typeof",
"factory",
"===",
"'function'",
")",
"{",
"// compatible and efficiency",
"// KISSY.add(function(S,undefined){})",
"var",
"require",
";",
"if",
"(",
"module",
".",
"requires",
"&&",
"module",
".",
"requires",
".",
"length",
"&&",
"module",
".",
"cjs",
")",
"{",
"require",
"=",
"bind",
"(",
"module",
".",
"require",
",",
"module",
")",
";",
"}",
"// 需要解开 index,相对路径",
"// 但是需要保留 alias,防止值不对应",
"//noinspection JSUnresolvedFunction",
"exports",
"=",
"factory",
".",
"apply",
"(",
"module",
",",
"// KISSY.add(function(S){module.require}) lazy initialize",
"(",
"module",
".",
"cjs",
"?",
"[",
"S",
",",
"require",
",",
"module",
".",
"exports",
",",
"module",
"]",
":",
"Utils",
".",
"getModules",
"(",
"module",
".",
"getRequiresWithAlias",
"(",
")",
")",
")",
")",
";",
"if",
"(",
"exports",
"!==",
"undefined",
")",
"{",
"//noinspection JSUndefinedPropertyAssignment",
"module",
".",
"exports",
"=",
"exports",
";",
"}",
"}",
"else",
"{",
"//noinspection JSUndefinedPropertyAssignment",
"module",
".",
"exports",
"=",
"factory",
";",
"}",
"module",
".",
"status",
"=",
"ATTACHED",
";",
"}"
] |
Attach specified module.
@param {KISSY.Loader.Module} module module instance
|
[
"Attach",
"specified",
"module",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L1865-L1893
|
|
35,690 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (relativeName, fn) {
relativeName = Utils.getModNamesAsArray(relativeName);
return KISSY.use(Utils.normalDepModuleName(this.name, relativeName), fn);
}
|
javascript
|
function (relativeName, fn) {
relativeName = Utils.getModNamesAsArray(relativeName);
return KISSY.use(Utils.normalDepModuleName(this.name, relativeName), fn);
}
|
[
"function",
"(",
"relativeName",
",",
"fn",
")",
"{",
"relativeName",
"=",
"Utils",
".",
"getModNamesAsArray",
"(",
"relativeName",
")",
";",
"return",
"KISSY",
".",
"use",
"(",
"Utils",
".",
"normalDepModuleName",
"(",
"this",
".",
"name",
",",
"relativeName",
")",
",",
"fn",
")",
";",
"}"
] |
resolve module by name.
@param {String|String[]} relativeName relative module's name
@param {Function|Object} fn KISSY.use callback
@returns {String} resolved module name
|
[
"resolve",
"module",
"by",
"name",
"."
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L2275-L2278
|
|
35,691 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function () {
var self = this, uri;
if (!self.uri) {
// path can be specified
if (self.path) {
uri = new S.Uri(self.path);
} else {
uri = S.Config.resolveModFn(self);
}
self.uri = uri;
}
return self.uri;
}
|
javascript
|
function () {
var self = this, uri;
if (!self.uri) {
// path can be specified
if (self.path) {
uri = new S.Uri(self.path);
} else {
uri = S.Config.resolveModFn(self);
}
self.uri = uri;
}
return self.uri;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"uri",
";",
"if",
"(",
"!",
"self",
".",
"uri",
")",
"{",
"// path can be specified",
"if",
"(",
"self",
".",
"path",
")",
"{",
"uri",
"=",
"new",
"S",
".",
"Uri",
"(",
"self",
".",
"path",
")",
";",
"}",
"else",
"{",
"uri",
"=",
"S",
".",
"Config",
".",
"resolveModFn",
"(",
"self",
")",
";",
"}",
"self",
".",
"uri",
"=",
"uri",
";",
"}",
"return",
"self",
".",
"uri",
";",
"}"
] |
Get the path uri of current module if load dynamically
@return {KISSY.Uri}
|
[
"Get",
"the",
"path",
"uri",
"of",
"current",
"module",
"if",
"load",
"dynamically"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L2366-L2378
|
|
35,692 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function () {
var self = this,
requiresWithAlias = self.requiresWithAlias,
requires = self.requires;
if (!requires || requires.length === 0) {
return requires || [];
} else if (!requiresWithAlias) {
self.requiresWithAlias = requiresWithAlias =
Utils.normalizeModNamesWithAlias(requires, self.name);
}
return requiresWithAlias;
}
|
javascript
|
function () {
var self = this,
requiresWithAlias = self.requiresWithAlias,
requires = self.requires;
if (!requires || requires.length === 0) {
return requires || [];
} else if (!requiresWithAlias) {
self.requiresWithAlias = requiresWithAlias =
Utils.normalizeModNamesWithAlias(requires, self.name);
}
return requiresWithAlias;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"requiresWithAlias",
"=",
"self",
".",
"requiresWithAlias",
",",
"requires",
"=",
"self",
".",
"requires",
";",
"if",
"(",
"!",
"requires",
"||",
"requires",
".",
"length",
"===",
"0",
")",
"{",
"return",
"requires",
"||",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"requiresWithAlias",
")",
"{",
"self",
".",
"requiresWithAlias",
"=",
"requiresWithAlias",
"=",
"Utils",
".",
"normalizeModNamesWithAlias",
"(",
"requires",
",",
"self",
".",
"name",
")",
";",
"}",
"return",
"requiresWithAlias",
";",
"}"
] |
get alias required module names
@returns {String[]} alias required module names
|
[
"get",
"alias",
"required",
"module",
"names"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L2430-L2441
|
|
35,693 |
kissyteam/kissy-xtemplate
|
lib/kissy/seed.js
|
function (moduleName, refName) {
if (moduleName) {
var moduleNames = Utils.unalias(Utils.normalizeModNamesWithAlias([moduleName], refName));
Utils.attachModsRecursively(moduleNames);
return Utils.getModules(moduleNames)[1];
}
}
|
javascript
|
function (moduleName, refName) {
if (moduleName) {
var moduleNames = Utils.unalias(Utils.normalizeModNamesWithAlias([moduleName], refName));
Utils.attachModsRecursively(moduleNames);
return Utils.getModules(moduleNames)[1];
}
}
|
[
"function",
"(",
"moduleName",
",",
"refName",
")",
"{",
"if",
"(",
"moduleName",
")",
"{",
"var",
"moduleNames",
"=",
"Utils",
".",
"unalias",
"(",
"Utils",
".",
"normalizeModNamesWithAlias",
"(",
"[",
"moduleName",
"]",
",",
"refName",
")",
")",
";",
"Utils",
".",
"attachModsRecursively",
"(",
"moduleNames",
")",
";",
"return",
"Utils",
".",
"getModules",
"(",
"moduleNames",
")",
"[",
"1",
"]",
";",
"}",
"}"
] |
get module exports from KISSY module cache
@param {String} moduleName module name
@param {String} refName internal usage
@member KISSY
@return {*} exports of specified module
|
[
"get",
"module",
"exports",
"from",
"KISSY",
"module",
"cache"
] |
1d454ab624c867d6a862d63dba576f8d24c6dcfc
|
https://github.com/kissyteam/kissy-xtemplate/blob/1d454ab624c867d6a862d63dba576f8d24c6dcfc/lib/kissy/seed.js#L3604-L3610
|
|
35,694 |
craterdog-bali/js-bali-component-framework
|
src/collections/Stack.js
|
Stack
|
function Stack(parameters) {
parameters = parameters || new composites.Parameters(new Catalog());
if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Stack/v1');
abstractions.Collection.call(this, utilities.types.STACK, parameters);
// the capacity and array are private attributes so methods that use it are
// defined in the constructor
var capacity = 1024; // default capacity
if (parameters) {
const value = parameters.getParameter('$capacity', 2);
if (value) capacity = value.toNumber();
}
const array = [];
this.acceptVisitor = function(visitor) {
visitor.visitStack(this);
};
this.toArray = function() {
return array.slice(); // copy the array
};
this.getSize = function() {
return array.length;
};
this.addItem = function(item) {
if (array.length < capacity) {
item = this.convert(item);
array.push(item);
return true;
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$addItem',
$exception: '$resourceLimit',
$capacity: capacity,
$text: '"The stack has reached its maximum capacity."'
});
};
this.removeItem = function() {
if (array.length > 0) {
return array.pop();
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$removeItem',
$exception: '$emptyStack',
$text: '"Attempted to remove an item from an empty stack."'
});
};
this.getTop = function() {
if (array.length > 0) {
return array.peek();
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$getTop',
$exception: '$emptyStack',
$text: '"Attempted to access an item on an empty stack."'
});
};
this.deleteAll = function() {
array.splice(0);
};
return this;
}
|
javascript
|
function Stack(parameters) {
parameters = parameters || new composites.Parameters(new Catalog());
if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Stack/v1');
abstractions.Collection.call(this, utilities.types.STACK, parameters);
// the capacity and array are private attributes so methods that use it are
// defined in the constructor
var capacity = 1024; // default capacity
if (parameters) {
const value = parameters.getParameter('$capacity', 2);
if (value) capacity = value.toNumber();
}
const array = [];
this.acceptVisitor = function(visitor) {
visitor.visitStack(this);
};
this.toArray = function() {
return array.slice(); // copy the array
};
this.getSize = function() {
return array.length;
};
this.addItem = function(item) {
if (array.length < capacity) {
item = this.convert(item);
array.push(item);
return true;
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$addItem',
$exception: '$resourceLimit',
$capacity: capacity,
$text: '"The stack has reached its maximum capacity."'
});
};
this.removeItem = function() {
if (array.length > 0) {
return array.pop();
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$removeItem',
$exception: '$emptyStack',
$text: '"Attempted to remove an item from an empty stack."'
});
};
this.getTop = function() {
if (array.length > 0) {
return array.peek();
}
throw new utilities.Exception({
$module: '/bali/collections/Stack',
$procedure: '$getTop',
$exception: '$emptyStack',
$text: '"Attempted to access an item on an empty stack."'
});
};
this.deleteAll = function() {
array.splice(0);
};
return this;
}
|
[
"function",
"Stack",
"(",
"parameters",
")",
"{",
"parameters",
"=",
"parameters",
"||",
"new",
"composites",
".",
"Parameters",
"(",
"new",
"Catalog",
"(",
")",
")",
";",
"if",
"(",
"!",
"parameters",
".",
"getParameter",
"(",
"'$type'",
")",
")",
"parameters",
".",
"setParameter",
"(",
"'$type'",
",",
"'/bali/collections/Stack/v1'",
")",
";",
"abstractions",
".",
"Collection",
".",
"call",
"(",
"this",
",",
"utilities",
".",
"types",
".",
"STACK",
",",
"parameters",
")",
";",
"// the capacity and array are private attributes so methods that use it are",
"// defined in the constructor",
"var",
"capacity",
"=",
"1024",
";",
"// default capacity",
"if",
"(",
"parameters",
")",
"{",
"const",
"value",
"=",
"parameters",
".",
"getParameter",
"(",
"'$capacity'",
",",
"2",
")",
";",
"if",
"(",
"value",
")",
"capacity",
"=",
"value",
".",
"toNumber",
"(",
")",
";",
"}",
"const",
"array",
"=",
"[",
"]",
";",
"this",
".",
"acceptVisitor",
"=",
"function",
"(",
"visitor",
")",
"{",
"visitor",
".",
"visitStack",
"(",
"this",
")",
";",
"}",
";",
"this",
".",
"toArray",
"=",
"function",
"(",
")",
"{",
"return",
"array",
".",
"slice",
"(",
")",
";",
"// copy the array",
"}",
";",
"this",
".",
"getSize",
"=",
"function",
"(",
")",
"{",
"return",
"array",
".",
"length",
";",
"}",
";",
"this",
".",
"addItem",
"=",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"array",
".",
"length",
"<",
"capacity",
")",
"{",
"item",
"=",
"this",
".",
"convert",
"(",
"item",
")",
";",
"array",
".",
"push",
"(",
"item",
")",
";",
"return",
"true",
";",
"}",
"throw",
"new",
"utilities",
".",
"Exception",
"(",
"{",
"$module",
":",
"'/bali/collections/Stack'",
",",
"$procedure",
":",
"'$addItem'",
",",
"$exception",
":",
"'$resourceLimit'",
",",
"$capacity",
":",
"capacity",
",",
"$text",
":",
"'\"The stack has reached its maximum capacity.\"'",
"}",
")",
";",
"}",
";",
"this",
".",
"removeItem",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"array",
".",
"length",
">",
"0",
")",
"{",
"return",
"array",
".",
"pop",
"(",
")",
";",
"}",
"throw",
"new",
"utilities",
".",
"Exception",
"(",
"{",
"$module",
":",
"'/bali/collections/Stack'",
",",
"$procedure",
":",
"'$removeItem'",
",",
"$exception",
":",
"'$emptyStack'",
",",
"$text",
":",
"'\"Attempted to remove an item from an empty stack.\"'",
"}",
")",
";",
"}",
";",
"this",
".",
"getTop",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"array",
".",
"length",
">",
"0",
")",
"{",
"return",
"array",
".",
"peek",
"(",
")",
";",
"}",
"throw",
"new",
"utilities",
".",
"Exception",
"(",
"{",
"$module",
":",
"'/bali/collections/Stack'",
",",
"$procedure",
":",
"'$getTop'",
",",
"$exception",
":",
"'$emptyStack'",
",",
"$text",
":",
"'\"Attempted to access an item on an empty stack.\"'",
"}",
")",
";",
"}",
";",
"this",
".",
"deleteAll",
"=",
"function",
"(",
")",
"{",
"array",
".",
"splice",
"(",
"0",
")",
";",
"}",
";",
"return",
"this",
";",
"}"
] |
PUBLIC CONSTRUCTORS
This constructor creates a new stack component with optional parameters that are
used to parameterize its type.
@param {Parameters} parameters Optional parameters used to parameterize this collection.
@returns {Stack} The new stack.
|
[
"PUBLIC",
"CONSTRUCTORS",
"This",
"constructor",
"creates",
"a",
"new",
"stack",
"component",
"with",
"optional",
"parameters",
"that",
"are",
"used",
"to",
"parameterize",
"its",
"type",
"."
] |
57279245e44d6ceef4debdb1d6132f48e464dcb8
|
https://github.com/craterdog-bali/js-bali-component-framework/blob/57279245e44d6ceef4debdb1d6132f48e464dcb8/src/collections/Stack.js#L40-L110
|
35,695 |
bq/corbel-js
|
src/assets/assets-builder.js
|
function(params) {
var options = params ? corbel.utils.clone(params) : {};
var args = corbel.utils.extend(options, {
url: this._buildUri(this.uri, this.id),
method: corbel.request.method.GET,
query: params ? corbel.utils.serializeParams(params) : null
});
return this.request(args);
}
|
javascript
|
function(params) {
var options = params ? corbel.utils.clone(params) : {};
var args = corbel.utils.extend(options, {
url: this._buildUri(this.uri, this.id),
method: corbel.request.method.GET,
query: params ? corbel.utils.serializeParams(params) : null
});
return this.request(args);
}
|
[
"function",
"(",
"params",
")",
"{",
"var",
"options",
"=",
"params",
"?",
"corbel",
".",
"utils",
".",
"clone",
"(",
"params",
")",
":",
"{",
"}",
";",
"var",
"args",
"=",
"corbel",
".",
"utils",
".",
"extend",
"(",
"options",
",",
"{",
"url",
":",
"this",
".",
"_buildUri",
"(",
"this",
".",
"uri",
",",
"this",
".",
"id",
")",
",",
"method",
":",
"corbel",
".",
"request",
".",
"method",
".",
"GET",
",",
"query",
":",
"params",
"?",
"corbel",
".",
"utils",
".",
"serializeParams",
"(",
"params",
")",
":",
"null",
"}",
")",
";",
"return",
"this",
".",
"request",
"(",
"args",
")",
";",
"}"
] |
Gets my user assets
@memberof corbel.Assets.AssetsBuilder.prototype
@param {object} [params] Params of a {@link corbel.request}
@return {Promise} Promise that resolves with an Asset or rejects with a {@link CorbelError}
|
[
"Gets",
"my",
"user",
"assets"
] |
00074882676b592d2ac16868279c58b0c4faf1e2
|
https://github.com/bq/corbel-js/blob/00074882676b592d2ac16868279c58b0c4faf1e2/src/assets/assets-builder.js#L34-L46
|
|
35,696 |
bq/corbel-js
|
src/assets/assets-builder.js
|
function(data) {
return this.request({
url: this._buildUri(this.uri),
method: corbel.request.method.POST,
data: data
}).
then(function(res) {
return corbel.Services.getLocationId(res);
});
}
|
javascript
|
function(data) {
return this.request({
url: this._buildUri(this.uri),
method: corbel.request.method.POST,
data: data
}).
then(function(res) {
return corbel.Services.getLocationId(res);
});
}
|
[
"function",
"(",
"data",
")",
"{",
"return",
"this",
".",
"request",
"(",
"{",
"url",
":",
"this",
".",
"_buildUri",
"(",
"this",
".",
"uri",
")",
",",
"method",
":",
"corbel",
".",
"request",
".",
"method",
".",
"POST",
",",
"data",
":",
"data",
"}",
")",
".",
"then",
"(",
"function",
"(",
"res",
")",
"{",
"return",
"corbel",
".",
"Services",
".",
"getLocationId",
"(",
"res",
")",
";",
"}",
")",
";",
"}"
] |
Creates a new asset
@memberof corbel.Assets.AssetsBuilder.prototype
@param {object} data Contains the data of the new asset
@param {string} data.userId The user id
@param {string} data.name The asset name
@param {date} data.expire Expire date
@param {boolean} data.active If asset is active
@param {array} data.scopes Scopes of the asset
@return {Promise} Promise that resolves in the new asset id or rejects with a {@link CorbelError}
|
[
"Creates",
"a",
"new",
"asset"
] |
00074882676b592d2ac16868279c58b0c4faf1e2
|
https://github.com/bq/corbel-js/blob/00074882676b592d2ac16868279c58b0c4faf1e2/src/assets/assets-builder.js#L89-L98
|
|
35,697 |
bq/corbel-js
|
src/assets/assets-builder.js
|
function(params) {
var args = params ? corbel.utils.clone(params) : {};
args.url = this._buildUri(this.uri + '/access');
args.method = corbel.request.method.GET;
args.noRedirect = true;
var that = this;
return this.request(args).
then(function(response) {
return that.request({
noRetry: args.noRetry,
method: corbel.request.method.POST,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data:response.data,
url: response.headers.location
});
});
}
|
javascript
|
function(params) {
var args = params ? corbel.utils.clone(params) : {};
args.url = this._buildUri(this.uri + '/access');
args.method = corbel.request.method.GET;
args.noRedirect = true;
var that = this;
return this.request(args).
then(function(response) {
return that.request({
noRetry: args.noRetry,
method: corbel.request.method.POST,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data:response.data,
url: response.headers.location
});
});
}
|
[
"function",
"(",
"params",
")",
"{",
"var",
"args",
"=",
"params",
"?",
"corbel",
".",
"utils",
".",
"clone",
"(",
"params",
")",
":",
"{",
"}",
";",
"args",
".",
"url",
"=",
"this",
".",
"_buildUri",
"(",
"this",
".",
"uri",
"+",
"'/access'",
")",
";",
"args",
".",
"method",
"=",
"corbel",
".",
"request",
".",
"method",
".",
"GET",
";",
"args",
".",
"noRedirect",
"=",
"true",
";",
"var",
"that",
"=",
"this",
";",
"return",
"this",
".",
"request",
"(",
"args",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"that",
".",
"request",
"(",
"{",
"noRetry",
":",
"args",
".",
"noRetry",
",",
"method",
":",
"corbel",
".",
"request",
".",
"method",
".",
"POST",
",",
"contentType",
":",
"'application/x-www-form-urlencoded; charset=UTF-8'",
",",
"data",
":",
"response",
".",
"data",
",",
"url",
":",
"response",
".",
"headers",
".",
"location",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Generates a JWT that contains the scopes of the actual user's assets and redirects to iam to upgrade user's token
@memberof corbel.Assets.AssetsBuilder.prototype
@return {Promise} Promise that resolves to a redirection to iam/oauth/token/upgrade or rejects with a {@link CorbelError}
|
[
"Generates",
"a",
"JWT",
"that",
"contains",
"the",
"scopes",
"of",
"the",
"actual",
"user",
"s",
"assets",
"and",
"redirects",
"to",
"iam",
"to",
"upgrade",
"user",
"s",
"token"
] |
00074882676b592d2ac16868279c58b0c4faf1e2
|
https://github.com/bq/corbel-js/blob/00074882676b592d2ac16868279c58b0c4faf1e2/src/assets/assets-builder.js#L105-L123
|
|
35,698 |
bq/corbel-js
|
dist/corbel.with-polyfills.js
|
function(data, cb) {
if (corbel.Config.isNode) {
// in node transform to stream
cb(corbel.utils.toURLEncoded(data));
} else {
// in browser transform to blob
cb(corbel.utils.dataURItoBlob(data));
}
}
|
javascript
|
function(data, cb) {
if (corbel.Config.isNode) {
// in node transform to stream
cb(corbel.utils.toURLEncoded(data));
} else {
// in browser transform to blob
cb(corbel.utils.dataURItoBlob(data));
}
}
|
[
"function",
"(",
"data",
",",
"cb",
")",
"{",
"if",
"(",
"corbel",
".",
"Config",
".",
"isNode",
")",
"{",
"// in node transform to stream",
"cb",
"(",
"corbel",
".",
"utils",
".",
"toURLEncoded",
"(",
"data",
")",
")",
";",
"}",
"else",
"{",
"// in browser transform to blob",
"cb",
"(",
"corbel",
".",
"utils",
".",
"dataURItoBlob",
"(",
"data",
")",
")",
";",
"}",
"}"
] |
dataURI serialize handler
@param {object} data
@return {string}
|
[
"dataURI",
"serialize",
"handler"
] |
00074882676b592d2ac16868279c58b0c4faf1e2
|
https://github.com/bq/corbel-js/blob/00074882676b592d2ac16868279c58b0c4faf1e2/dist/corbel.with-polyfills.js#L2384-L2392
|
|
35,699 |
bq/corbel-js
|
dist/corbel.with-polyfills.js
|
function(response, resolver, callbackSuccess, callbackError) {
//xhr = xhr.target || xhr || {};
var statusCode = xhrSuccessStatus[response.status] || response.status,
statusType = Number(response.status.toString()[0]),
promiseResponse;
var data = response.response;
var headers = corbel.utils.keysToLowerCase(response.headers);
if (statusType <= 3 && !response.error) {
if (response.response) {
data = request.parse(response.response, response.responseType, response.dataType);
}
if (callbackSuccess) {
callbackSuccess.call(this, data, statusCode, response.responseObject, headers);
}
promiseResponse = {
data: data,
status: statusCode,
headers: headers
};
promiseResponse[response.responseObjectType] = response.responseObject;
resolver.resolve(promiseResponse);
} else {
var disconnected = response.error && response.status === 0;
statusCode = disconnected ? 0 : statusCode;
if (callbackError) {
callbackError.call(this, response.error, statusCode, response.responseObject, headers);
}
if (response.response) {
data = request.parse(response.response, response.responseType, response.dataType);
}
promiseResponse = {
data: data,
status: statusCode,
error: response.error,
headers: headers
};
promiseResponse[response.responseObjectType] = response.responseObject;
resolver.reject(promiseResponse);
}
}
|
javascript
|
function(response, resolver, callbackSuccess, callbackError) {
//xhr = xhr.target || xhr || {};
var statusCode = xhrSuccessStatus[response.status] || response.status,
statusType = Number(response.status.toString()[0]),
promiseResponse;
var data = response.response;
var headers = corbel.utils.keysToLowerCase(response.headers);
if (statusType <= 3 && !response.error) {
if (response.response) {
data = request.parse(response.response, response.responseType, response.dataType);
}
if (callbackSuccess) {
callbackSuccess.call(this, data, statusCode, response.responseObject, headers);
}
promiseResponse = {
data: data,
status: statusCode,
headers: headers
};
promiseResponse[response.responseObjectType] = response.responseObject;
resolver.resolve(promiseResponse);
} else {
var disconnected = response.error && response.status === 0;
statusCode = disconnected ? 0 : statusCode;
if (callbackError) {
callbackError.call(this, response.error, statusCode, response.responseObject, headers);
}
if (response.response) {
data = request.parse(response.response, response.responseType, response.dataType);
}
promiseResponse = {
data: data,
status: statusCode,
error: response.error,
headers: headers
};
promiseResponse[response.responseObjectType] = response.responseObject;
resolver.reject(promiseResponse);
}
}
|
[
"function",
"(",
"response",
",",
"resolver",
",",
"callbackSuccess",
",",
"callbackError",
")",
"{",
"//xhr = xhr.target || xhr || {};",
"var",
"statusCode",
"=",
"xhrSuccessStatus",
"[",
"response",
".",
"status",
"]",
"||",
"response",
".",
"status",
",",
"statusType",
"=",
"Number",
"(",
"response",
".",
"status",
".",
"toString",
"(",
")",
"[",
"0",
"]",
")",
",",
"promiseResponse",
";",
"var",
"data",
"=",
"response",
".",
"response",
";",
"var",
"headers",
"=",
"corbel",
".",
"utils",
".",
"keysToLowerCase",
"(",
"response",
".",
"headers",
")",
";",
"if",
"(",
"statusType",
"<=",
"3",
"&&",
"!",
"response",
".",
"error",
")",
"{",
"if",
"(",
"response",
".",
"response",
")",
"{",
"data",
"=",
"request",
".",
"parse",
"(",
"response",
".",
"response",
",",
"response",
".",
"responseType",
",",
"response",
".",
"dataType",
")",
";",
"}",
"if",
"(",
"callbackSuccess",
")",
"{",
"callbackSuccess",
".",
"call",
"(",
"this",
",",
"data",
",",
"statusCode",
",",
"response",
".",
"responseObject",
",",
"headers",
")",
";",
"}",
"promiseResponse",
"=",
"{",
"data",
":",
"data",
",",
"status",
":",
"statusCode",
",",
"headers",
":",
"headers",
"}",
";",
"promiseResponse",
"[",
"response",
".",
"responseObjectType",
"]",
"=",
"response",
".",
"responseObject",
";",
"resolver",
".",
"resolve",
"(",
"promiseResponse",
")",
";",
"}",
"else",
"{",
"var",
"disconnected",
"=",
"response",
".",
"error",
"&&",
"response",
".",
"status",
"===",
"0",
";",
"statusCode",
"=",
"disconnected",
"?",
"0",
":",
"statusCode",
";",
"if",
"(",
"callbackError",
")",
"{",
"callbackError",
".",
"call",
"(",
"this",
",",
"response",
".",
"error",
",",
"statusCode",
",",
"response",
".",
"responseObject",
",",
"headers",
")",
";",
"}",
"if",
"(",
"response",
".",
"response",
")",
"{",
"data",
"=",
"request",
".",
"parse",
"(",
"response",
".",
"response",
",",
"response",
".",
"responseType",
",",
"response",
".",
"dataType",
")",
";",
"}",
"promiseResponse",
"=",
"{",
"data",
":",
"data",
",",
"status",
":",
"statusCode",
",",
"error",
":",
"response",
".",
"error",
",",
"headers",
":",
"headers",
"}",
";",
"promiseResponse",
"[",
"response",
".",
"responseObjectType",
"]",
"=",
"response",
".",
"responseObject",
";",
"resolver",
".",
"reject",
"(",
"promiseResponse",
")",
";",
"}",
"}"
] |
Process server response
@param {object} response
@param {object} resolver
@param {function} callbackSuccess
@param {function} callbackError
|
[
"Process",
"server",
"response"
] |
00074882676b592d2ac16868279c58b0c4faf1e2
|
https://github.com/bq/corbel-js/blob/00074882676b592d2ac16868279c58b0c4faf1e2/dist/corbel.with-polyfills.js#L2574-L2627
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.