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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isAncestorContainer | function isAncestorContainer(ancestor, descendant) {
return (ancestor || descendant)
&& (ancestor == descendant || isAncestor(ancestor, descendant));
} | javascript | function isAncestorContainer(ancestor, descendant) {
return (ancestor || descendant)
&& (ancestor == descendant || isAncestor(ancestor, descendant));
} | [
"function",
"isAncestorContainer",
"(",
"ancestor",
",",
"descendant",
")",
"{",
"return",
"(",
"ancestor",
"||",
"descendant",
")",
"&&",
"(",
"ancestor",
"==",
"descendant",
"||",
"isAncestor",
"(",
"ancestor",
",",
"descendant",
")",
")",
";",
"}"
] | Returns true if ancestor is an ancestor of or equal to descendant, false
otherwise. | [
"Returns",
"true",
"if",
"ancestor",
"is",
"an",
"ancestor",
"of",
"or",
"equal",
"to",
"descendant",
"false",
"otherwise",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L65-L68 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isDescendant | function isDescendant(descendant, ancestor) {
return ancestor
&& descendant
&& Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);
} | javascript | function isDescendant(descendant, ancestor) {
return ancestor
&& descendant
&& Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);
} | [
"function",
"isDescendant",
"(",
"descendant",
",",
"ancestor",
")",
"{",
"return",
"ancestor",
"&&",
"descendant",
"&&",
"Boolean",
"(",
"ancestor",
".",
"compareDocumentPosition",
"(",
"descendant",
")",
"&",
"Node",
".",
"DOCUMENT_POSITION_CONTAINED_BY",
")",
"... | Returns true if descendant is a descendant of ancestor, false otherwise. | [
"Returns",
"true",
"if",
"descendant",
"is",
"a",
"descendant",
"of",
"ancestor",
"false",
"otherwise",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L73-L77 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | getPosition | function getPosition(nodeA, offsetA, nodeB, offsetB) {
// "If node A is the same as node B, return equal if offset A equals offset
// B, before if offset A is less than offset B, and after if offset A is
// greater than offset B."
if (nodeA == nodeB) {
if (offsetA == offsetB) {
return "equal";
}
if (offset... | javascript | function getPosition(nodeA, offsetA, nodeB, offsetB) {
// "If node A is the same as node B, return equal if offset A equals offset
// B, before if offset A is less than offset B, and after if offset A is
// greater than offset B."
if (nodeA == nodeB) {
if (offsetA == offsetB) {
return "equal";
}
if (offset... | [
"function",
"getPosition",
"(",
"nodeA",
",",
"offsetA",
",",
"nodeB",
",",
"offsetB",
")",
"{",
"// \"If node A is the same as node B, return equal if offset A equals offset",
"// B, before if offset A is less than offset B, and after if offset A is",
"// greater than offset B.\"",
"i... | The position of two boundary points relative to one another, as defined by
DOM Range. | [
"The",
"position",
"of",
"two",
"boundary",
"points",
"relative",
"to",
"one",
"another",
"as",
"defined",
"by",
"DOM",
"Range",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L254-L301 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | getContainedNodes | function getContainedNodes(range, condition) {
if (typeof condition == "undefined") {
condition = function() { return true };
}
var node = range.startContainer;
if (node.hasChildNodes()
&& range.startOffset < node.childNodes.length) {
// A child is contained
node = node.childNodes[range.startOffset];
} else... | javascript | function getContainedNodes(range, condition) {
if (typeof condition == "undefined") {
condition = function() { return true };
}
var node = range.startContainer;
if (node.hasChildNodes()
&& range.startOffset < node.childNodes.length) {
// A child is contained
node = node.childNodes[range.startOffset];
} else... | [
"function",
"getContainedNodes",
"(",
"range",
",",
"condition",
")",
"{",
"if",
"(",
"typeof",
"condition",
"==",
"\"undefined\"",
")",
"{",
"condition",
"=",
"function",
"(",
")",
"{",
"return",
"true",
"}",
";",
"}",
"var",
"node",
"=",
"range",
".",
... | Return all nodes contained in range that the provided function returns true
for, omitting any with an ancestor already being returned. | [
"Return",
"all",
"nodes",
"contained",
"in",
"range",
"that",
"the",
"provided",
"function",
"returns",
"true",
"for",
"omitting",
"any",
"with",
"an",
"ancestor",
"already",
"being",
"returned",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L332-L370 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | editCommandMethod | function editCommandMethod(command, range, callback) {
// Set up our global range magic, but only if we're the outermost function
if (executionStackDepth == 0 && typeof range != "undefined") {
globalRange = range;
} else if (executionStackDepth == 0) {
globalRange = null;
globalRange = getActiveRange();
}
/... | javascript | function editCommandMethod(command, range, callback) {
// Set up our global range magic, but only if we're the outermost function
if (executionStackDepth == 0 && typeof range != "undefined") {
globalRange = range;
} else if (executionStackDepth == 0) {
globalRange = null;
globalRange = getActiveRange();
}
/... | [
"function",
"editCommandMethod",
"(",
"command",
",",
"range",
",",
"callback",
")",
"{",
"// Set up our global range magic, but only if we're the outermost function",
"if",
"(",
"executionStackDepth",
"==",
"0",
"&&",
"typeof",
"range",
"!=",
"\"undefined\"",
")",
"{",
... | Helper function for common behavior. | [
"Helper",
"function",
"for",
"common",
"behavior",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L497-L522 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isEditingHost | function isEditingHost(node) {
return node
&& isHtmlElement(node)
&& (node.contentEditable == "true"
|| (node.parentNode
&& node.parentNode.nodeType == Node.DOCUMENT_NODE
&& node.parentNode.designMode == "on"));
} | javascript | function isEditingHost(node) {
return node
&& isHtmlElement(node)
&& (node.contentEditable == "true"
|| (node.parentNode
&& node.parentNode.nodeType == Node.DOCUMENT_NODE
&& node.parentNode.designMode == "on"));
} | [
"function",
"isEditingHost",
"(",
"node",
")",
"{",
"return",
"node",
"&&",
"isHtmlElement",
"(",
"node",
")",
"&&",
"(",
"node",
".",
"contentEditable",
"==",
"\"true\"",
"||",
"(",
"node",
".",
"parentNode",
"&&",
"node",
".",
"parentNode",
".",
"nodeTyp... | "An editing host is a node that is either an HTML element with a contenteditable attribute set to the true state, or the HTML element child of a Document whose designMode is enabled." | [
"An",
"editing",
"host",
"is",
"a",
"node",
"that",
"is",
"either",
"an",
"HTML",
"element",
"with",
"a",
"contenteditable",
"attribute",
"set",
"to",
"the",
"true",
"state",
"or",
"the",
"HTML",
"element",
"child",
"of",
"a",
"Document",
"whose",
"designM... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L729-L736 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isEditable | function isEditable(node) {
return node
&& !isEditingHost(node)
&& (node.nodeType != Node.ELEMENT_NODE || node.contentEditable != "false")
&& (isEditingHost(node.parentNode) || isEditable(node.parentNode))
&& (isHtmlElement(node)
|| (node.nodeType == Node.ELEMENT_NODE && node.namespaceURI == "http://www.w3.o... | javascript | function isEditable(node) {
return node
&& !isEditingHost(node)
&& (node.nodeType != Node.ELEMENT_NODE || node.contentEditable != "false")
&& (isEditingHost(node.parentNode) || isEditable(node.parentNode))
&& (isHtmlElement(node)
|| (node.nodeType == Node.ELEMENT_NODE && node.namespaceURI == "http://www.w3.o... | [
"function",
"isEditable",
"(",
"node",
")",
"{",
"return",
"node",
"&&",
"!",
"isEditingHost",
"(",
"node",
")",
"&&",
"(",
"node",
".",
"nodeType",
"!=",
"Node",
".",
"ELEMENT_NODE",
"||",
"node",
".",
"contentEditable",
"!=",
"\"false\"",
")",
"&&",
"(... | "Something is editable if it is a node; it is not an editing host; it does not have a contenteditable attribute set to the false state; its parent is an editing host or editable; and either it is an HTML element, or it is an svg or math element, or it is not an Element and its parent is an HTML element." | [
"Something",
"is",
"editable",
"if",
"it",
"is",
"a",
"node",
";",
"it",
"is",
"not",
"an",
"editing",
"host",
";",
"it",
"does",
"not",
"have",
"a",
"contenteditable",
"attribute",
"set",
"to",
"the",
"false",
"state",
";",
"its",
"parent",
"is",
"an"... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L743-L752 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | hasEditableDescendants | function hasEditableDescendants(node) {
for (var i = 0; i < node.childNodes.length; i++) {
if (isEditable(node.childNodes[i])
|| hasEditableDescendants(node.childNodes[i])) {
return true;
}
}
return false;
} | javascript | function hasEditableDescendants(node) {
for (var i = 0; i < node.childNodes.length; i++) {
if (isEditable(node.childNodes[i])
|| hasEditableDescendants(node.childNodes[i])) {
return true;
}
}
return false;
} | [
"function",
"hasEditableDescendants",
"(",
"node",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"node",
".",
"childNodes",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"isEditable",
"(",
"node",
".",
"childNodes",
"[",
"i",
"]"... | Helper function, not defined in the spec | [
"Helper",
"function",
"not",
"defined",
"in",
"the",
"spec"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L755-L763 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | getEditingHostOf | function getEditingHostOf(node) {
if (isEditingHost(node)) {
return node;
} else if (isEditable(node)) {
var ancestor = node.parentNode;
while (!isEditingHost(ancestor)) {
ancestor = ancestor.parentNode;
}
return ancestor;
} else {
return null;
}
} | javascript | function getEditingHostOf(node) {
if (isEditingHost(node)) {
return node;
} else if (isEditable(node)) {
var ancestor = node.parentNode;
while (!isEditingHost(ancestor)) {
ancestor = ancestor.parentNode;
}
return ancestor;
} else {
return null;
}
} | [
"function",
"getEditingHostOf",
"(",
"node",
")",
"{",
"if",
"(",
"isEditingHost",
"(",
"node",
")",
")",
"{",
"return",
"node",
";",
"}",
"else",
"if",
"(",
"isEditable",
"(",
"node",
")",
")",
"{",
"var",
"ancestor",
"=",
"node",
".",
"parentNode",
... | "The editing host of node is null if node is neither editable nor an editing host; node itself, if node is an editing host; or the nearest ancestor of node that is an editing host, if node is editable." | [
"The",
"editing",
"host",
"of",
"node",
"is",
"null",
"if",
"node",
"is",
"neither",
"editable",
"nor",
"an",
"editing",
"host",
";",
"node",
"itself",
"if",
"node",
"is",
"an",
"editing",
"host",
";",
"or",
"the",
"nearest",
"ancestor",
"of",
"node",
... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L768-L780 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isCollapsedBlockProp | function isCollapsedBlockProp(node) {
if (isCollapsedLineBreak(node)
&& !isExtraneousLineBreak(node)) {
return true;
}
if (!isInlineNode(node)
|| node.nodeType != Node.ELEMENT_NODE) {
return false;
}
var hasCollapsedBlockPropChild = false;
for (var i = 0; i < node.childNodes.length; i++) {
if (!isInvisi... | javascript | function isCollapsedBlockProp(node) {
if (isCollapsedLineBreak(node)
&& !isExtraneousLineBreak(node)) {
return true;
}
if (!isInlineNode(node)
|| node.nodeType != Node.ELEMENT_NODE) {
return false;
}
var hasCollapsedBlockPropChild = false;
for (var i = 0; i < node.childNodes.length; i++) {
if (!isInvisi... | [
"function",
"isCollapsedBlockProp",
"(",
"node",
")",
"{",
"if",
"(",
"isCollapsedLineBreak",
"(",
"node",
")",
"&&",
"!",
"isExtraneousLineBreak",
"(",
"node",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"isInlineNode",
"(",
"node",
")",
... | "A collapsed block prop is either a collapsed line break that is not an extraneous line break, or an Element that is an inline node and whose children are all either invisible or collapsed block props and that has at least one child that is a collapsed block prop." | [
"A",
"collapsed",
"block",
"prop",
"is",
"either",
"a",
"collapsed",
"line",
"break",
"that",
"is",
"not",
"an",
"extraneous",
"line",
"break",
"or",
"an",
"Element",
"that",
"is",
"an",
"inline",
"node",
"and",
"whose",
"children",
"are",
"all",
"either",... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L1034-L1057 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isFormattableNode | function isFormattableNode(node) {
return isEditable(node)
&& isVisible(node)
&& (node.nodeType == Node.TEXT_NODE
|| isHtmlElement(node, ["img", "br"]));
} | javascript | function isFormattableNode(node) {
return isEditable(node)
&& isVisible(node)
&& (node.nodeType == Node.TEXT_NODE
|| isHtmlElement(node, ["img", "br"]));
} | [
"function",
"isFormattableNode",
"(",
"node",
")",
"{",
"return",
"isEditable",
"(",
"node",
")",
"&&",
"isVisible",
"(",
"node",
")",
"&&",
"(",
"node",
".",
"nodeType",
"==",
"Node",
".",
"TEXT_NODE",
"||",
"isHtmlElement",
"(",
"node",
",",
"[",
"\"im... | "A formattable node is an editable visible node that is either a Text node, an img, or a br." | [
"A",
"formattable",
"node",
"is",
"an",
"editable",
"visible",
"node",
"that",
"is",
"either",
"a",
"Text",
"node",
"an",
"img",
"or",
"a",
"br",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L1988-L1993 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | areEquivalentValues | function areEquivalentValues(command, val1, val2) {
if (val1 === null && val2 === null) {
return true;
}
if (typeof val1 == "string"
&& typeof val2 == "string"
&& val1 == val2
&& !("equivalentValues" in commands[command])) {
return true;
}
if (typeof val1 == "string"
&& typeof val2 == "string"
&& "equiv... | javascript | function areEquivalentValues(command, val1, val2) {
if (val1 === null && val2 === null) {
return true;
}
if (typeof val1 == "string"
&& typeof val2 == "string"
&& val1 == val2
&& !("equivalentValues" in commands[command])) {
return true;
}
if (typeof val1 == "string"
&& typeof val2 == "string"
&& "equiv... | [
"function",
"areEquivalentValues",
"(",
"command",
",",
"val1",
",",
"val2",
")",
"{",
"if",
"(",
"val1",
"===",
"null",
"&&",
"val2",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"typeof",
"val1",
"==",
"\"string\"",
"&&",
"typeof",... | "Two quantities are equivalent values for a command if either both are null, or both are strings and they're equal and the command does not define any equivalent values, or both are strings and the command defines equivalent values and they match the definition." | [
"Two",
"quantities",
"are",
"equivalent",
"values",
"for",
"a",
"command",
"if",
"either",
"both",
"are",
"null",
"or",
"both",
"are",
"strings",
"and",
"they",
"re",
"equal",
"and",
"the",
"command",
"does",
"not",
"define",
"any",
"equivalent",
"values",
... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L1999-L2019 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | normalizeFontSize | function normalizeFontSize(value) {
// "Strip leading and trailing whitespace from value."
//
// Cheap hack, not following the actual algorithm.
value = value.trim();
// "If value is not a valid floating point number, and would not be a valid
// floating point number if a single leading "+" character were stripp... | javascript | function normalizeFontSize(value) {
// "Strip leading and trailing whitespace from value."
//
// Cheap hack, not following the actual algorithm.
value = value.trim();
// "If value is not a valid floating point number, and would not be a valid
// floating point number if a single leading "+" character were stripp... | [
"function",
"normalizeFontSize",
"(",
"value",
")",
"{",
"// \"Strip leading and trailing whitespace from value.\"",
"//",
"// Cheap hack, not following the actual algorithm.",
"value",
"=",
"value",
".",
"trim",
"(",
")",
";",
"// \"If value is not a valid floating point number, a... | Helper function for fontSize's action plus queryOutputHelper. It's just the middle of fontSize's action, ripped out into its own function. Returns null if the size is invalid. | [
"Helper",
"function",
"for",
"fontSize",
"s",
"action",
"plus",
"queryOutputHelper",
".",
"It",
"s",
"just",
"the",
"middle",
"of",
"fontSize",
"s",
"action",
"ripped",
"out",
"into",
"its",
"own",
"function",
".",
"Returns",
"null",
"if",
"the",
"size",
"... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L3177-L3245 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | function(value) {
// Action is further copy-pasted, same as foreColor
// "If value is not a valid CSS color, prepend "#" to it."
//
// "If value is still not a valid CSS color, or if it is currentColor,
// abort these steps and do nothing."
//
// Cheap hack for testing, no attempt to be comprehensive.
... | javascript | function(value) {
// Action is further copy-pasted, same as foreColor
// "If value is not a valid CSS color, prepend "#" to it."
//
// "If value is still not a valid CSS color, or if it is currentColor,
// abort these steps and do nothing."
//
// Cheap hack for testing, no attempt to be comprehensive.
... | [
"function",
"(",
"value",
")",
"{",
"// Action is further copy-pasted, same as foreColor",
"// \"If value is not a valid CSS color, prepend \"#\" to it.\"",
"//",
"// \"If value is still not a valid CSS color, or if it is currentColor,",
"// abort these steps and do nothing.\"",
"//",
"// Chea... | Copy-pasted, same as backColor | [
"Copy",
"-",
"pasted",
"same",
"as",
"backColor"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L3394-L3414 | train | |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | isIndentationElement | function isIndentationElement(node) {
if (!isHtmlElement(node)) {
return false;
}
if (node.tagName == "BLOCKQUOTE") {
return true;
}
if (node.tagName != "DIV") {
return false;
}
for (var i = 0; i < node.style.length; i++) {
// Approximate check
if (/^(-[a-z]+-)?margin/.test(node.style[i])) {
retu... | javascript | function isIndentationElement(node) {
if (!isHtmlElement(node)) {
return false;
}
if (node.tagName == "BLOCKQUOTE") {
return true;
}
if (node.tagName != "DIV") {
return false;
}
for (var i = 0; i < node.style.length; i++) {
// Approximate check
if (/^(-[a-z]+-)?margin/.test(node.style[i])) {
retu... | [
"function",
"isIndentationElement",
"(",
"node",
")",
"{",
"if",
"(",
"!",
"isHtmlElement",
"(",
"node",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"node",
".",
"tagName",
"==",
"\"BLOCKQUOTE\"",
")",
"{",
"return",
"true",
";",
"}",
"if",
... | "An indentation element is either a blockquote, or a div that has a style attribute that sets "margin" or some subproperty of it." | [
"An",
"indentation",
"element",
"is",
"either",
"a",
"blockquote",
"or",
"a",
"div",
"that",
"has",
"a",
"style",
"attribute",
"that",
"sets",
"margin",
"or",
"some",
"subproperty",
"of",
"it",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L3702-L3723 | train |
timdown/rangy | src/modules/inactive/commands/aryeh_implementation.js | removePreservingDescendants | function removePreservingDescendants(node) {
if (node.hasChildNodes()) {
splitParent([].slice.call(node.childNodes));
} else {
node.parentNode.removeChild(node);
}
} | javascript | function removePreservingDescendants(node) {
if (node.hasChildNodes()) {
splitParent([].slice.call(node.childNodes));
} else {
node.parentNode.removeChild(node);
}
} | [
"function",
"removePreservingDescendants",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"hasChildNodes",
"(",
")",
")",
"{",
"splitParent",
"(",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"node",
".",
"childNodes",
")",
")",
";",
"}",
"else",
"{",
"... | "To remove a node node while preserving its descendants, split the parent of node's children if it has any. If it has no children, instead remove it from its parent." | [
"To",
"remove",
"a",
"node",
"node",
"while",
"preserving",
"its",
"descendants",
"split",
"the",
"parent",
"of",
"node",
"s",
"children",
"if",
"it",
"has",
"any",
".",
"If",
"it",
"has",
"no",
"children",
"instead",
"remove",
"it",
"from",
"its",
"pare... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/commands/aryeh_implementation.js#L5146-L5152 | train |
timdown/rangy | src/modules/rangy-classapplier.js | hasClass | function hasClass(el, className) {
if (typeof el.classList == "object") {
return el.classList.contains(className);
} else {
var classNameSupported = (typeof el.className == "string");
var elClass = classNameSupported ? el.className : el.getAttribute("class");
... | javascript | function hasClass(el, className) {
if (typeof el.classList == "object") {
return el.classList.contains(className);
} else {
var classNameSupported = (typeof el.className == "string");
var elClass = classNameSupported ? el.className : el.getAttribute("class");
... | [
"function",
"hasClass",
"(",
"el",
",",
"className",
")",
"{",
"if",
"(",
"typeof",
"el",
".",
"classList",
"==",
"\"object\"",
")",
"{",
"return",
"el",
".",
"classList",
".",
"contains",
"(",
"className",
")",
";",
"}",
"else",
"{",
"var",
"className... | Inefficient, inelegant nonsense for IE's svg element, which has no classList and non-HTML className implementation | [
"Inefficient",
"inelegant",
"nonsense",
"for",
"IE",
"s",
"svg",
"element",
"which",
"has",
"no",
"classList",
"and",
"non",
"-",
"HTML",
"className",
"implementation"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-classapplier.js#L48-L56 | train |
timdown/rangy | src/modules/rangy-classapplier.js | function(textNodes, range, positionsToPreserve, isUndo) {
log.group("postApply " + range.toHtml());
var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
var merges = [], currentMerge;
var rangeStartNode = firstNode, rangeEndNode = lastNode;
... | javascript | function(textNodes, range, positionsToPreserve, isUndo) {
log.group("postApply " + range.toHtml());
var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
var merges = [], currentMerge;
var rangeStartNode = firstNode, rangeEndNode = lastNode;
... | [
"function",
"(",
"textNodes",
",",
"range",
",",
"positionsToPreserve",
",",
"isUndo",
")",
"{",
"log",
".",
"group",
"(",
"\"postApply \"",
"+",
"range",
".",
"toHtml",
"(",
")",
")",
";",
"var",
"firstNode",
"=",
"textNodes",
"[",
"0",
"]",
",",
"las... | Normalizes nodes after applying a class to a Range. | [
"Normalizes",
"nodes",
"after",
"applying",
"a",
"class",
"to",
"a",
"Range",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-classapplier.js#L696-L751 | train | |
timdown/rangy | src/modules/rangy-textrange.js | getComputedDisplay | function getComputedDisplay(el, win) {
var display = getComputedStyleProperty(el, "display", win);
var tagName = el.tagName.toLowerCase();
return (display == "block" &&
tableCssDisplayBlock &&
defaultDisplayValueForTag.hasOwnProperty(tagName)) ?
defaul... | javascript | function getComputedDisplay(el, win) {
var display = getComputedStyleProperty(el, "display", win);
var tagName = el.tagName.toLowerCase();
return (display == "block" &&
tableCssDisplayBlock &&
defaultDisplayValueForTag.hasOwnProperty(tagName)) ?
defaul... | [
"function",
"getComputedDisplay",
"(",
"el",
",",
"win",
")",
"{",
"var",
"display",
"=",
"getComputedStyleProperty",
"(",
"el",
",",
"\"display\"",
",",
"win",
")",
";",
"var",
"tagName",
"=",
"el",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
";",
"re... | Corrects IE's "block" value for table-related elements | [
"Corrects",
"IE",
"s",
"block",
"value",
"for",
"table",
"-",
"related",
"elements"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-textrange.js#L300-L307 | train |
timdown/rangy | src/modules/rangy-textrange.js | function() {
if (!this.prepopulatedChar) {
this.prepopulateChar();
}
if (this.checkForTrailingSpace) {
var trailingSpace = this.session.getNodeWrapper(this.node.childNodes[this.offset - 1]).getTrailingSpace();
log.debug("resolveLeadingA... | javascript | function() {
if (!this.prepopulatedChar) {
this.prepopulateChar();
}
if (this.checkForTrailingSpace) {
var trailingSpace = this.session.getNodeWrapper(this.node.childNodes[this.offset - 1]).getTrailingSpace();
log.debug("resolveLeadingA... | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"prepopulatedChar",
")",
"{",
"this",
".",
"prepopulateChar",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"checkForTrailingSpace",
")",
"{",
"var",
"trailingSpace",
"=",
"this",
".",
"session",
".... | Resolve leading and trailing spaces, which may involve prepopulating other positions | [
"Resolve",
"leading",
"and",
"trailing",
"spaces",
"which",
"may",
"involve",
"prepopulating",
"other",
"positions"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-textrange.js#L791-L815 | train | |
timdown/rangy | src/modules/rangy-textrange.js | consumeWord | function consumeWord(forward) {
log.debug("consumeWord called, forward is " + forward);
var pos, textChar;
var newChars = [], it = forward ? forwardIterator : backwardIterator;
var passedWordBoundary = false, insideWord = false;
while ( (pos = it.next()) ) {... | javascript | function consumeWord(forward) {
log.debug("consumeWord called, forward is " + forward);
var pos, textChar;
var newChars = [], it = forward ? forwardIterator : backwardIterator;
var passedWordBoundary = false, insideWord = false;
while ( (pos = it.next()) ) {... | [
"function",
"consumeWord",
"(",
"forward",
")",
"{",
"log",
".",
"debug",
"(",
"\"consumeWord called, forward is \"",
"+",
"forward",
")",
";",
"var",
"pos",
",",
"textChar",
";",
"var",
"newChars",
"=",
"[",
"]",
",",
"it",
"=",
"forward",
"?",
"forwardIt... | Consumes a word and the whitespace beyond it | [
"Consumes",
"a",
"word",
"and",
"the",
"whitespace",
"beyond",
"it"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-textrange.js#L1306-L1339 | train |
timdown/rangy | src/modules/inactive/rangy-commands.js | isEditingHost | function isEditingHost(node) {
return node &&
((node.nodeType == 9 && node.designMode == "on") ||
(isEditableElement(node) && !isEditableElement(node.parentNode)));
} | javascript | function isEditingHost(node) {
return node &&
((node.nodeType == 9 && node.designMode == "on") ||
(isEditableElement(node) && !isEditableElement(node.parentNode)));
} | [
"function",
"isEditingHost",
"(",
"node",
")",
"{",
"return",
"node",
"&&",
"(",
"(",
"node",
".",
"nodeType",
"==",
"9",
"&&",
"node",
".",
"designMode",
"==",
"\"on\"",
")",
"||",
"(",
"isEditableElement",
"(",
"node",
")",
"&&",
"!",
"isEditableElemen... | "An editing host is a node that is either an Element whose isContentEditable property returns true but whose parent node is not an element or whose isContentEditable property returns false, or a Document whose designMode is enabled." | [
"An",
"editing",
"host",
"is",
"a",
"node",
"that",
"is",
"either",
"an",
"Element",
"whose",
"isContentEditable",
"property",
"returns",
"true",
"but",
"whose",
"parent",
"node",
"is",
"not",
"an",
"element",
"or",
"whose",
"isContentEditable",
"property",
"r... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands.js#L85-L89 | train |
timdown/rangy | src/modules/inactive/rangy-commands.js | isEditable | function isEditable(node, options) {
// This is slightly a lie, because we're excluding non-HTML elements with
// contentEditable attributes.
return !options || !options.applyToEditableOnly
|| ( (isEditableElement(node) || isEditableElement(node.parentNode)) && !isEditingHost(node) )... | javascript | function isEditable(node, options) {
// This is slightly a lie, because we're excluding non-HTML elements with
// contentEditable attributes.
return !options || !options.applyToEditableOnly
|| ( (isEditableElement(node) || isEditableElement(node.parentNode)) && !isEditingHost(node) )... | [
"function",
"isEditable",
"(",
"node",
",",
"options",
")",
"{",
"// This is slightly a lie, because we're excluding non-HTML elements with",
"// contentEditable attributes.",
"return",
"!",
"options",
"||",
"!",
"options",
".",
"applyToEditableOnly",
"||",
"(",
"(",
"isEdi... | "A node is editable if it is not an editing host and is or is the child of an Element whose isContentEditable property returns true." | [
"A",
"node",
"is",
"editable",
"if",
"it",
"is",
"not",
"an",
"editing",
"host",
"and",
"is",
"or",
"is",
"the",
"child",
"of",
"an",
"Element",
"whose",
"isContentEditable",
"property",
"returns",
"true",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands.js#L100-L105 | train |
timdown/rangy | src/modules/inactive/rangy-commands.js | isEffectivelyContained | function isEffectivelyContained(node, range) {
if (isContained(node, range)) {
return true;
}
var isCharData = dom.isCharacterDataNode(node);
if (node == range.startContainer && isCharData && dom.getNodeLength(node) != range.startOffset) {
return true;
}
... | javascript | function isEffectivelyContained(node, range) {
if (isContained(node, range)) {
return true;
}
var isCharData = dom.isCharacterDataNode(node);
if (node == range.startContainer && isCharData && dom.getNodeLength(node) != range.startOffset) {
return true;
}
... | [
"function",
"isEffectivelyContained",
"(",
"node",
",",
"range",
")",
"{",
"if",
"(",
"isContained",
"(",
"node",
",",
"range",
")",
")",
"{",
"return",
"true",
";",
"}",
"var",
"isCharData",
"=",
"dom",
".",
"isCharacterDataNode",
"(",
"node",
")",
";",... | "A Node is effectively contained in a Range if either it is contained in the
Range; or it is the Range's start node, it is a Text node, and its length is
different from the Range's start offset; or it is the Range's end node, it
is a Text node, and the Range's end offset is not 0; or it has at least one
child, and all ... | [
"A",
"Node",
"is",
"effectively",
"contained",
"in",
"a",
"Range",
"if",
"either",
"it",
"is",
"contained",
"in",
"the",
"Range",
";",
"or",
"it",
"is",
"the",
"Range",
"s",
"start",
"node",
"it",
"is",
"a",
"Text",
"node",
"and",
"its",
"length",
"i... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands.js#L128-L149 | train |
timdown/rangy | src/modules/inactive/rangy-commands.js | isInlineNode | function isInlineNode(node) {
return dom.isCharacterDataNode(node) ||
(node.nodeType == 1 && inlineDisplayRegex.test(getComputedStyleProperty(node, "display")));
} | javascript | function isInlineNode(node) {
return dom.isCharacterDataNode(node) ||
(node.nodeType == 1 && inlineDisplayRegex.test(getComputedStyleProperty(node, "display")));
} | [
"function",
"isInlineNode",
"(",
"node",
")",
"{",
"return",
"dom",
".",
"isCharacterDataNode",
"(",
"node",
")",
"||",
"(",
"node",
".",
"nodeType",
"==",
"1",
"&&",
"inlineDisplayRegex",
".",
"test",
"(",
"getComputedStyleProperty",
"(",
"node",
",",
"\"di... | "An inline node is either a Text node, or an Element whose 'display'
property computes to 'inline', 'inline-block', or 'inline-table'." | [
"An",
"inline",
"node",
"is",
"either",
"a",
"Text",
"node",
"or",
"an",
"Element",
"whose",
"display",
"property",
"computes",
"to",
"inline",
"inline",
"-",
"block",
"or",
"inline",
"-",
"table",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands.js#L165-L168 | train |
timdown/rangy | src/modules/inactive/rangy-commands.js | valuesEqual | function valuesEqual(command, val1, val2) {
if (val1 === null || val2 === null) {
return val1 === val2;
}
return command.valuesEqual(val1, val2);
} | javascript | function valuesEqual(command, val1, val2) {
if (val1 === null || val2 === null) {
return val1 === val2;
}
return command.valuesEqual(val1, val2);
} | [
"function",
"valuesEqual",
"(",
"command",
",",
"val1",
",",
"val2",
")",
"{",
"if",
"(",
"val1",
"===",
"null",
"||",
"val2",
"===",
"null",
")",
"{",
"return",
"val1",
"===",
"val2",
";",
"}",
"return",
"command",
".",
"valuesEqual",
"(",
"val1",
"... | This entire function is a massive hack to work around browser incompatibility. It wouldn't work in real life, but it's good enough for a test implementation. It's not clear how all this should actually be specced in practice, since CSS defines no notion of equality, does it? | [
"This",
"entire",
"function",
"is",
"a",
"massive",
"hack",
"to",
"work",
"around",
"browser",
"incompatibility",
".",
"It",
"wouldn",
"t",
"work",
"in",
"real",
"life",
"but",
"it",
"s",
"good",
"enough",
"for",
"a",
"test",
"implementation",
".",
"It",
... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-commands.js#L701-L707 | train |
timdown/rangy | src/modules/inactive/rangy-textcommands.js | function(textNodes, range) {
log.group("postApply");
var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
var merges = [], currentMerge;
var rangeStartNode = firstNode, rangeEndNode = lastNode;
var rangeStartOffset = 0, rangeEndOffset = ... | javascript | function(textNodes, range) {
log.group("postApply");
var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
var merges = [], currentMerge;
var rangeStartNode = firstNode, rangeEndNode = lastNode;
var rangeStartOffset = 0, rangeEndOffset = ... | [
"function",
"(",
"textNodes",
",",
"range",
")",
"{",
"log",
".",
"group",
"(",
"\"postApply\"",
")",
";",
"var",
"firstNode",
"=",
"textNodes",
"[",
"0",
"]",
",",
"lastNode",
"=",
"textNodes",
"[",
"textNodes",
".",
"length",
"-",
"1",
"]",
";",
"v... | Normalizes nodes after applying a CSS class to a Range. | [
"Normalizes",
"nodes",
"after",
"applying",
"a",
"CSS",
"class",
"to",
"a",
"Range",
"."
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-textcommands.js#L238-L296 | train | |
timdown/rangy | src/modules/inactive/rangy-position.js | getScrollPosition | function getScrollPosition(win) {
var x = 0, y = 0;
if (typeof win.pageXOffset == NUMBER && typeof win.pageYOffset == NUMBER) {
x = win.pageXOffset;
y = win.pageYOffset;
} else {
var doc = win.document;
var docEl = doc.documentElement;
... | javascript | function getScrollPosition(win) {
var x = 0, y = 0;
if (typeof win.pageXOffset == NUMBER && typeof win.pageYOffset == NUMBER) {
x = win.pageXOffset;
y = win.pageYOffset;
} else {
var doc = win.document;
var docEl = doc.documentElement;
... | [
"function",
"getScrollPosition",
"(",
"win",
")",
"{",
"var",
"x",
"=",
"0",
",",
"y",
"=",
"0",
";",
"if",
"(",
"typeof",
"win",
".",
"pageXOffset",
"==",
"NUMBER",
"&&",
"typeof",
"win",
".",
"pageYOffset",
"==",
"NUMBER",
")",
"{",
"x",
"=",
"wi... | Since Rangy can deal with multiple documents which could be in different modes, we have to do the checks every time, unless we cache a getScrollPosition function in each document. This would necessarily pollute the document's global namespace, which I'm choosing to view as a greater evil than a slight performance hit. | [
"Since",
"Rangy",
"can",
"deal",
"with",
"multiple",
"documents",
"which",
"could",
"be",
"in",
"different",
"modes",
"we",
"have",
"to",
"do",
"the",
"checks",
"every",
"time",
"unless",
"we",
"cache",
"a",
"getScrollPosition",
"function",
"in",
"each",
"do... | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-position.js#L30-L50 | train |
timdown/rangy | src/modules/inactive/rangy-position.js | function(el) {
var x = 0, y = 0, offsetEl = el, width = el.offsetWidth, height = el.offsetHeight;
while (offsetEl) {
x += offsetEl.offsetLeft;
y += offsetEl.offsetTop;
offsetEl = offsetEl.offsetParent;
... | javascript | function(el) {
var x = 0, y = 0, offsetEl = el, width = el.offsetWidth, height = el.offsetHeight;
while (offsetEl) {
x += offsetEl.offsetLeft;
y += offsetEl.offsetTop;
offsetEl = offsetEl.offsetParent;
... | [
"function",
"(",
"el",
")",
"{",
"var",
"x",
"=",
"0",
",",
"y",
"=",
"0",
",",
"offsetEl",
"=",
"el",
",",
"width",
"=",
"el",
".",
"offsetWidth",
",",
"height",
"=",
"el",
".",
"offsetHeight",
";",
"while",
"(",
"offsetEl",
")",
"{",
"x",
"+=... | This implementation is very naive. There are many browser quirks that make it extremely difficult to get accurate element coordinates in all situations | [
"This",
"implementation",
"is",
"very",
"naive",
".",
"There",
"are",
"many",
"browser",
"quirks",
"that",
"make",
"it",
"extremely",
"difficult",
"to",
"get",
"accurate",
"element",
"coordinates",
"in",
"all",
"situations"
] | 1e55169d2e4d1d9458c2a87119addf47a8265276 | https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/inactive/rangy-position.js#L400-L409 | train | |
artilleryio/artillery | core/lib/engine_util.js | templateObjectOrArray | function templateObjectOrArray(o, context) {
deepForEach(o, (value, key, subj, path) => {
const newPath = template(path, context, true);
let newValue;
if (value && (value.constructor !== Object && value.constructor !== Array)) {
newValue = template(value, context, true);
} else {
newValue... | javascript | function templateObjectOrArray(o, context) {
deepForEach(o, (value, key, subj, path) => {
const newPath = template(path, context, true);
let newValue;
if (value && (value.constructor !== Object && value.constructor !== Array)) {
newValue = template(value, context, true);
} else {
newValue... | [
"function",
"templateObjectOrArray",
"(",
"o",
",",
"context",
")",
"{",
"deepForEach",
"(",
"o",
",",
"(",
"value",
",",
"key",
",",
"subj",
",",
"path",
")",
"=>",
"{",
"const",
"newPath",
"=",
"template",
"(",
"path",
",",
"context",
",",
"true",
... | Mutates the object in place | [
"Mutates",
"the",
"object",
"in",
"place"
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/engine_util.js#L240-L262 | train |
artilleryio/artillery | core/lib/engine_util.js | extractJSONPath | function extractJSONPath(doc, expr) {
// typeof null is 'object' hence the explicit check here
if (typeof doc !== 'object' || doc === null) {
return '';
}
let results;
try {
results = jsonpath.query(doc, expr);
} catch (queryErr) {
debug(queryErr);
}
if (!results) {
return '';
}
... | javascript | function extractJSONPath(doc, expr) {
// typeof null is 'object' hence the explicit check here
if (typeof doc !== 'object' || doc === null) {
return '';
}
let results;
try {
results = jsonpath.query(doc, expr);
} catch (queryErr) {
debug(queryErr);
}
if (!results) {
return '';
}
... | [
"function",
"extractJSONPath",
"(",
"doc",
",",
"expr",
")",
"{",
"// typeof null is 'object' hence the explicit check here",
"if",
"(",
"typeof",
"doc",
"!==",
"'object'",
"||",
"doc",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"let",
"results",
";",
... | doc is a JSON object | [
"doc",
"is",
"a",
"JSON",
"object"
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/engine_util.js#L499-L522 | train |
artilleryio/artillery | lib/dist.js | divideWork | function divideWork(script, numWorkers) {
let newPhases = [];
for (let i = 0; i < numWorkers; i++) {
newPhases.push(L.cloneDeep(script.config.phases));
}
//
// Adjust phase definitions:
//
L.each(script.config.phases, function(phase, phaseSpecIndex) {
if (phase.arrivalRate && phase.rampTo) {
... | javascript | function divideWork(script, numWorkers) {
let newPhases = [];
for (let i = 0; i < numWorkers; i++) {
newPhases.push(L.cloneDeep(script.config.phases));
}
//
// Adjust phase definitions:
//
L.each(script.config.phases, function(phase, phaseSpecIndex) {
if (phase.arrivalRate && phase.rampTo) {
... | [
"function",
"divideWork",
"(",
"script",
",",
"numWorkers",
")",
"{",
"let",
"newPhases",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"numWorkers",
";",
"i",
"++",
")",
"{",
"newPhases",
".",
"push",
"(",
"L",
".",
"clone... | Create a number of scripts for workers from the script given to use by user. | [
"Create",
"a",
"number",
"of",
"scripts",
"for",
"workers",
"from",
"the",
"script",
"given",
"to",
"use",
"by",
"user",
"."
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/lib/dist.js#L15-L82 | train |
artilleryio/artillery | lib/dist.js | distribute | function distribute(m, n) {
m = Number(m);
n = Number(n);
let result = [];
if (m < n) {
for (let i = 0; i < n; i++) {
result.push(i < m ? 1 : 0);
}
} else {
let baseCount = Math.floor(m / n);
let extraItems = m % n;
for(let i = 0; i < n; i++) {
result.push(baseCount);
i... | javascript | function distribute(m, n) {
m = Number(m);
n = Number(n);
let result = [];
if (m < n) {
for (let i = 0; i < n; i++) {
result.push(i < m ? 1 : 0);
}
} else {
let baseCount = Math.floor(m / n);
let extraItems = m % n;
for(let i = 0; i < n; i++) {
result.push(baseCount);
i... | [
"function",
"distribute",
"(",
"m",
",",
"n",
")",
"{",
"m",
"=",
"Number",
"(",
"m",
")",
";",
"n",
"=",
"Number",
"(",
"n",
")",
";",
"let",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"m",
"<",
"n",
")",
"{",
"for",
"(",
"let",
"i",
"=",
... | Given M "things", distribute them between N peers as equally as possible | [
"Given",
"M",
"things",
"distribute",
"them",
"between",
"N",
"peers",
"as",
"equally",
"as",
"possible"
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/lib/dist.js#L88-L111 | train |
artilleryio/artillery | core/lib/weighted-pick.js | create | function create(list) {
let dist = l.reduce(list, function(acc, el, i) {
for(let j = 0; j < el.weight * 100; j++) {
acc.push(i);
}
return acc;
}, []);
return function() {
let i = dist[l.random(0, dist.length - 1)];
return [i, list[i]];
};
} | javascript | function create(list) {
let dist = l.reduce(list, function(acc, el, i) {
for(let j = 0; j < el.weight * 100; j++) {
acc.push(i);
}
return acc;
}, []);
return function() {
let i = dist[l.random(0, dist.length - 1)];
return [i, list[i]];
};
} | [
"function",
"create",
"(",
"list",
")",
"{",
"let",
"dist",
"=",
"l",
".",
"reduce",
"(",
"list",
",",
"function",
"(",
"acc",
",",
"el",
",",
"i",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"el",
".",
"weight",
"*",
"100",
... | naive implementation of selection with replacement | [
"naive",
"implementation",
"of",
"selection",
"with",
"replacement"
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/weighted-pick.js#L12-L24 | train |
artilleryio/artillery | core/lib/runner.js | createContext | function createContext(script) {
const INITIAL_CONTEXT = {
vars: {
target: script.config.target,
$environment: script._environment,
$processEnvironment: process.env
},
funcs: {
$randomNumber: $randomNumber,
$randomString: $randomString,
$template: input => engineUtil.te... | javascript | function createContext(script) {
const INITIAL_CONTEXT = {
vars: {
target: script.config.target,
$environment: script._environment,
$processEnvironment: process.env
},
funcs: {
$randomNumber: $randomNumber,
$randomString: $randomString,
$template: input => engineUtil.te... | [
"function",
"createContext",
"(",
"script",
")",
"{",
"const",
"INITIAL_CONTEXT",
"=",
"{",
"vars",
":",
"{",
"target",
":",
"script",
".",
"config",
".",
"target",
",",
"$environment",
":",
"script",
".",
"_environment",
",",
"$processEnvironment",
":",
"pr... | Create initial context for a scenario. | [
"Create",
"initial",
"context",
"for",
"a",
"scenario",
"."
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/runner.js#L450-L476 | train |
artilleryio/artillery | core/lib/stats2.js | combine | function combine(statsObjects) {
let result = create();
L.each(statsObjects, function(stats) {
L.each(stats._latencies, function(latency) {
result._latencies.push(latency);
});
result._generatedScenarios += stats._generatedScenarios;
L.each(stats._scenarioCounter, function(count, name) {
... | javascript | function combine(statsObjects) {
let result = create();
L.each(statsObjects, function(stats) {
L.each(stats._latencies, function(latency) {
result._latencies.push(latency);
});
result._generatedScenarios += stats._generatedScenarios;
L.each(stats._scenarioCounter, function(count, name) {
... | [
"function",
"combine",
"(",
"statsObjects",
")",
"{",
"let",
"result",
"=",
"create",
"(",
")",
";",
"L",
".",
"each",
"(",
"statsObjects",
",",
"function",
"(",
"stats",
")",
"{",
"L",
".",
"each",
"(",
"stats",
".",
"_latencies",
",",
"function",
"... | Combine several stats objects from different workers into one | [
"Combine",
"several",
"stats",
"objects",
"from",
"different",
"workers",
"into",
"one"
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/stats2.js#L26-L86 | train |
artilleryio/artillery | core/lib/engine_http.js | ensurePropertyIsAList | function ensurePropertyIsAList(obj, prop) {
obj[prop] = [].concat(
typeof obj[prop] === 'undefined' ?
[] : obj[prop]);
return obj;
} | javascript | function ensurePropertyIsAList(obj, prop) {
obj[prop] = [].concat(
typeof obj[prop] === 'undefined' ?
[] : obj[prop]);
return obj;
} | [
"function",
"ensurePropertyIsAList",
"(",
"obj",
",",
"prop",
")",
"{",
"obj",
"[",
"prop",
"]",
"=",
"[",
"]",
".",
"concat",
"(",
"typeof",
"obj",
"[",
"prop",
"]",
"===",
"'undefined'",
"?",
"[",
"]",
":",
"obj",
"[",
"prop",
"]",
")",
";",
"r... | Helper function to wrap an object's property in a list if it's defined, or set it to an empty list if not. | [
"Helper",
"function",
"to",
"wrap",
"an",
"object",
"s",
"property",
"in",
"a",
"list",
"if",
"it",
"s",
"defined",
"or",
"set",
"it",
"to",
"an",
"empty",
"list",
"if",
"not",
"."
] | e8023099e7b05a712dba6d627ce5ea221f75d142 | https://github.com/artilleryio/artillery/blob/e8023099e7b05a712dba6d627ce5ea221f75d142/core/lib/engine_http.js#L57-L62 | train |
apache/cordova-node-xcode | lib/pbxProject.js | propReplace | function propReplace(obj, prop, value) {
var o = {};
for (var p in obj) {
if (o.hasOwnProperty.call(obj, p)) {
if (typeof obj[p] == 'object' && !Array.isArray(obj[p])) {
propReplace(obj[p], prop, value);
} else if (p == prop) {
obj[p] = value;
... | javascript | function propReplace(obj, prop, value) {
var o = {};
for (var p in obj) {
if (o.hasOwnProperty.call(obj, p)) {
if (typeof obj[p] == 'object' && !Array.isArray(obj[p])) {
propReplace(obj[p], prop, value);
} else if (p == prop) {
obj[p] = value;
... | [
"function",
"propReplace",
"(",
"obj",
",",
"prop",
",",
"value",
")",
"{",
"var",
"o",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"p",
"in",
"obj",
")",
"{",
"if",
"(",
"o",
".",
"hasOwnProperty",
".",
"call",
"(",
"obj",
",",
"p",
")",
")",
"{"... | helper recursive prop search+replace | [
"helper",
"recursive",
"prop",
"search",
"+",
"replace"
] | a65e1943ed8c71d93e4c673d0a7aabf4ebca7623 | https://github.com/apache/cordova-node-xcode/blob/a65e1943ed8c71d93e4c673d0a7aabf4ebca7623/lib/pbxProject.js#L1495-L1506 | train |
apache/cordova-node-xcode | lib/pbxProject.js | pbxBuildFileObj | function pbxBuildFileObj(file) {
var obj = Object.create(null);
obj.isa = 'PBXBuildFile';
obj.fileRef = file.fileRef;
obj.fileRef_comment = file.basename;
if (file.settings) obj.settings = file.settings;
return obj;
} | javascript | function pbxBuildFileObj(file) {
var obj = Object.create(null);
obj.isa = 'PBXBuildFile';
obj.fileRef = file.fileRef;
obj.fileRef_comment = file.basename;
if (file.settings) obj.settings = file.settings;
return obj;
} | [
"function",
"pbxBuildFileObj",
"(",
"file",
")",
"{",
"var",
"obj",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"obj",
".",
"isa",
"=",
"'PBXBuildFile'",
";",
"obj",
".",
"fileRef",
"=",
"file",
".",
"fileRef",
";",
"obj",
".",
"fileRef_commen... | helper object creation functions | [
"helper",
"object",
"creation",
"functions"
] | a65e1943ed8c71d93e4c673d0a7aabf4ebca7623 | https://github.com/apache/cordova-node-xcode/blob/a65e1943ed8c71d93e4c673d0a7aabf4ebca7623/lib/pbxProject.js#L1509-L1518 | train |
johnculviner/jquery.fileDownload | src/Scripts/jquery.fileDownload.js | getiframeDocument | function getiframeDocument($iframe) {
var iframeDoc = $iframe[0].contentWindow || $iframe[0].contentDocument;
if (iframeDoc.document) {
iframeDoc = iframeDoc.document;
}
return iframeDoc;
} | javascript | function getiframeDocument($iframe) {
var iframeDoc = $iframe[0].contentWindow || $iframe[0].contentDocument;
if (iframeDoc.document) {
iframeDoc = iframeDoc.document;
}
return iframeDoc;
} | [
"function",
"getiframeDocument",
"(",
"$iframe",
")",
"{",
"var",
"iframeDoc",
"=",
"$iframe",
"[",
"0",
"]",
".",
"contentWindow",
"||",
"$iframe",
"[",
"0",
"]",
".",
"contentDocument",
";",
"if",
"(",
"iframeDoc",
".",
"document",
")",
"{",
"iframeDoc",... | gets an iframes document in a cross browser compatible manner | [
"gets",
"an",
"iframes",
"document",
"in",
"a",
"cross",
"browser",
"compatible",
"manner"
] | 67859ca512d8ab35a44b2ff26473e18350172fac | https://github.com/johnculviner/jquery.fileDownload/blob/67859ca512d8ab35a44b2ff26473e18350172fac/src/Scripts/jquery.fileDownload.js#L437-L443 | train |
skanaar/nomnoml | src/renderer.js | quadrant | function quadrant(point, node, fallback) {
if (point.x < node.x && point.y < node.y) return 1;
if (point.x > node.x && point.y < node.y) return 2;
if (point.x > node.x && point.y > node.y) return 3;
if (point.x < node.x && point.y > node.y) return 4;
return fallback;
} | javascript | function quadrant(point, node, fallback) {
if (point.x < node.x && point.y < node.y) return 1;
if (point.x > node.x && point.y < node.y) return 2;
if (point.x > node.x && point.y > node.y) return 3;
if (point.x < node.x && point.y > node.y) return 4;
return fallback;
} | [
"function",
"quadrant",
"(",
"point",
",",
"node",
",",
"fallback",
")",
"{",
"if",
"(",
"point",
".",
"x",
"<",
"node",
".",
"x",
"&&",
"point",
".",
"y",
"<",
"node",
".",
"y",
")",
"return",
"1",
";",
"if",
"(",
"point",
".",
"x",
">",
"no... | find basic quadrant using relative position of endpoint and block rectangle | [
"find",
"basic",
"quadrant",
"using",
"relative",
"position",
"of",
"endpoint",
"and",
"block",
"rectangle"
] | 188b359e9cd3cc56b9a7b3d4e897bf1191b9910c | https://github.com/skanaar/nomnoml/blob/188b359e9cd3cc56b9a7b3d4e897bf1191b9910c/src/renderer.js#L108-L114 | train |
skanaar/nomnoml | src/renderer.js | adjustQuadrant | function adjustQuadrant(quadrant, point, opposite) {
if ((opposite.x == point.x) || (opposite.y == point.y)) return quadrant;
var flipHorizontally = [4, 3, 2, 1]
var flipVertically = [2, 1, 4, 3]
var oppositeQuadrant = (opposite.y < point.y) ?
((opposite.x < point.x) ? 2 : 1) :
((opposite.x < poin... | javascript | function adjustQuadrant(quadrant, point, opposite) {
if ((opposite.x == point.x) || (opposite.y == point.y)) return quadrant;
var flipHorizontally = [4, 3, 2, 1]
var flipVertically = [2, 1, 4, 3]
var oppositeQuadrant = (opposite.y < point.y) ?
((opposite.x < point.x) ? 2 : 1) :
((opposite.x < poin... | [
"function",
"adjustQuadrant",
"(",
"quadrant",
",",
"point",
",",
"opposite",
")",
"{",
"if",
"(",
"(",
"opposite",
".",
"x",
"==",
"point",
".",
"x",
")",
"||",
"(",
"opposite",
".",
"y",
"==",
"point",
".",
"y",
")",
")",
"return",
"quadrant",
";... | Flip basic label quadrant if needed, to avoid crossing a bent relationship line | [
"Flip",
"basic",
"label",
"quadrant",
"if",
"needed",
"to",
"avoid",
"crossing",
"a",
"bent",
"relationship",
"line"
] | 188b359e9cd3cc56b9a7b3d4e897bf1191b9910c | https://github.com/skanaar/nomnoml/blob/188b359e9cd3cc56b9a7b3d4e897bf1191b9910c/src/renderer.js#L117-L130 | train |
jscottsmith/react-scroll-parallax | src/classes/ParallaxController.js | _updateAllElements | function _updateAllElements({ updateCache } = {}) {
elements.forEach(element => {
_updateElementPosition(element);
if (updateCache) {
element.setCachedAttributes(view, scroll);
}
});
// reset ticking so more animations can be called
tic... | javascript | function _updateAllElements({ updateCache } = {}) {
elements.forEach(element => {
_updateElementPosition(element);
if (updateCache) {
element.setCachedAttributes(view, scroll);
}
});
// reset ticking so more animations can be called
tic... | [
"function",
"_updateAllElements",
"(",
"{",
"updateCache",
"}",
"=",
"{",
"}",
")",
"{",
"elements",
".",
"forEach",
"(",
"element",
"=>",
"{",
"_updateElementPosition",
"(",
"element",
")",
";",
"if",
"(",
"updateCache",
")",
"{",
"element",
".",
"setCach... | Update element positions.
Determines if the element is in view based on the cached
attributes, if so set the elements parallax styles. | [
"Update",
"element",
"positions",
".",
"Determines",
"if",
"the",
"element",
"is",
"in",
"view",
"based",
"on",
"the",
"cached",
"attributes",
"if",
"so",
"set",
"the",
"elements",
"parallax",
"styles",
"."
] | 6404cf1cef94734bf1bc179e951d7d1dafc4d309 | https://github.com/jscottsmith/react-scroll-parallax/blob/6404cf1cef94734bf1bc179e951d7d1dafc4d309/src/classes/ParallaxController.js#L93-L102 | train |
jscottsmith/react-scroll-parallax | src/classes/ParallaxController.js | _setViewSize | function _setViewSize() {
if (hasScrollContainer) {
const width = viewEl.offsetWidth;
const height = viewEl.offsetHeight;
return view.setSize(width, height);
}
const html = document.documentElement;
const width = window.innerWidth || html.clientWidth;... | javascript | function _setViewSize() {
if (hasScrollContainer) {
const width = viewEl.offsetWidth;
const height = viewEl.offsetHeight;
return view.setSize(width, height);
}
const html = document.documentElement;
const width = window.innerWidth || html.clientWidth;... | [
"function",
"_setViewSize",
"(",
")",
"{",
"if",
"(",
"hasScrollContainer",
")",
"{",
"const",
"width",
"=",
"viewEl",
".",
"offsetWidth",
";",
"const",
"height",
"=",
"viewEl",
".",
"offsetHeight",
";",
"return",
"view",
".",
"setSize",
"(",
"width",
",",... | Cache the window height. | [
"Cache",
"the",
"window",
"height",
"."
] | 6404cf1cef94734bf1bc179e951d7d1dafc4d309 | https://github.com/jscottsmith/react-scroll-parallax/blob/6404cf1cef94734bf1bc179e951d7d1dafc4d309/src/classes/ParallaxController.js#L117-L129 | train |
nx-js/observer-util | src/handlers.js | get | function get (target, key, receiver) {
const result = Reflect.get(target, key, receiver)
// do not register (observable.prop -> reaction) pairs for well known symbols
// these symbols are frequently retrieved in low level JavaScript under the hood
if (typeof key === 'symbol' && wellKnownSymbols.has(key)) {
... | javascript | function get (target, key, receiver) {
const result = Reflect.get(target, key, receiver)
// do not register (observable.prop -> reaction) pairs for well known symbols
// these symbols are frequently retrieved in low level JavaScript under the hood
if (typeof key === 'symbol' && wellKnownSymbols.has(key)) {
... | [
"function",
"get",
"(",
"target",
",",
"key",
",",
"receiver",
")",
"{",
"const",
"result",
"=",
"Reflect",
".",
"get",
"(",
"target",
",",
"key",
",",
"receiver",
")",
"// do not register (observable.prop -> reaction) pairs for well known symbols",
"// these symbols ... | intercept get operations on observables to know which reaction uses their properties | [
"intercept",
"get",
"operations",
"on",
"observables",
"to",
"know",
"which",
"reaction",
"uses",
"their",
"properties"
] | 62aebe1bb8c92572a1dbbd236600f20cba0f6ae9 | https://github.com/nx-js/observer-util/blob/62aebe1bb8c92572a1dbbd236600f20cba0f6ae9/src/handlers.js#L17-L45 | train |
nx-js/observer-util | src/handlers.js | set | function set (target, key, value, receiver) {
// make sure to do not pollute the raw object with observables
if (typeof value === 'object' && value !== null) {
value = proxyToRaw.get(value) || value
}
// save if the object had a descriptor for this key
const hadKey = hasOwnProperty.call(target, key)
// ... | javascript | function set (target, key, value, receiver) {
// make sure to do not pollute the raw object with observables
if (typeof value === 'object' && value !== null) {
value = proxyToRaw.get(value) || value
}
// save if the object had a descriptor for this key
const hadKey = hasOwnProperty.call(target, key)
// ... | [
"function",
"set",
"(",
"target",
",",
"key",
",",
"value",
",",
"receiver",
")",
"{",
"// make sure to do not pollute the raw object with observables",
"if",
"(",
"typeof",
"value",
"===",
"'object'",
"&&",
"value",
"!==",
"null",
")",
"{",
"value",
"=",
"proxy... | intercept set operations on observables to know when to trigger reactions | [
"intercept",
"set",
"operations",
"on",
"observables",
"to",
"know",
"when",
"to",
"trigger",
"reactions"
] | 62aebe1bb8c92572a1dbbd236600f20cba0f6ae9 | https://github.com/nx-js/observer-util/blob/62aebe1bb8c92572a1dbbd236600f20cba0f6ae9/src/handlers.js#L60-L90 | train |
s-yadav/react-number-format | lib/utils.js | splitDecimal | function splitDecimal(numStr) {
var allowNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var hasNagation = numStr[0] === '-';
var addNegation = hasNagation && allowNegative;
numStr = numStr.replace('-', '');
var parts = numStr.split('.');
var beforeDecimal = parts[0];
... | javascript | function splitDecimal(numStr) {
var allowNegative = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var hasNagation = numStr[0] === '-';
var addNegation = hasNagation && allowNegative;
numStr = numStr.replace('-', '');
var parts = numStr.split('.');
var beforeDecimal = parts[0];
... | [
"function",
"splitDecimal",
"(",
"numStr",
")",
"{",
"var",
"allowNegative",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"true",
";",
"var",
"hasNagation",
"=",
... | spilt a float number into different parts beforeDecimal, afterDecimal, and negation | [
"spilt",
"a",
"float",
"number",
"into",
"different",
"parts",
"beforeDecimal",
"afterDecimal",
"and",
"negation"
] | 6a1113ff90ba69e479ec2b9902799f1ab2e69082 | https://github.com/s-yadav/react-number-format/blob/6a1113ff90ba69e479ec2b9902799f1ab2e69082/lib/utils.js#L58-L72 | train |
s-yadav/react-number-format | lib/utils.js | limitToScale | function limitToScale(numStr, scale, fixedDecimalScale) {
var str = '';
var filler = fixedDecimalScale ? '0' : '';
for (var i = 0; i <= scale - 1; i++) {
str += numStr[i] || filler;
}
return str;
} | javascript | function limitToScale(numStr, scale, fixedDecimalScale) {
var str = '';
var filler = fixedDecimalScale ? '0' : '';
for (var i = 0; i <= scale - 1; i++) {
str += numStr[i] || filler;
}
return str;
} | [
"function",
"limitToScale",
"(",
"numStr",
",",
"scale",
",",
"fixedDecimalScale",
")",
"{",
"var",
"str",
"=",
"''",
";",
"var",
"filler",
"=",
"fixedDecimalScale",
"?",
"'0'",
":",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<=",
"scale... | limit decimal numbers to given scale
Not used .fixedTo because that will break with big numbers | [
"limit",
"decimal",
"numbers",
"to",
"given",
"scale",
"Not",
"used",
".",
"fixedTo",
"because",
"that",
"will",
"break",
"with",
"big",
"numbers"
] | 6a1113ff90ba69e479ec2b9902799f1ab2e69082 | https://github.com/s-yadav/react-number-format/blob/6a1113ff90ba69e479ec2b9902799f1ab2e69082/lib/utils.js#L89-L98 | train |
s-yadav/react-number-format | lib/utils.js | roundToPrecision | function roundToPrecision(numStr, scale, fixedDecimalScale) {
//if number is empty don't do anything return empty string
if (['', '-'].indexOf(numStr) !== -1) return numStr;
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
var _splitDecimal = splitDecimal(numStr),
beforeDecimal = _spl... | javascript | function roundToPrecision(numStr, scale, fixedDecimalScale) {
//if number is empty don't do anything return empty string
if (['', '-'].indexOf(numStr) !== -1) return numStr;
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
var _splitDecimal = splitDecimal(numStr),
beforeDecimal = _spl... | [
"function",
"roundToPrecision",
"(",
"numStr",
",",
"scale",
",",
"fixedDecimalScale",
")",
"{",
"//if number is empty don't do anything return empty string",
"if",
"(",
"[",
"''",
",",
"'-'",
"]",
".",
"indexOf",
"(",
"numStr",
")",
"!==",
"-",
"1",
")",
"retur... | This method is required to round prop value to given scale.
Not used .round or .fixedTo because that will break with big numbers | [
"This",
"method",
"is",
"required",
"to",
"round",
"prop",
"value",
"to",
"given",
"scale",
".",
"Not",
"used",
".",
"round",
"or",
".",
"fixedTo",
"because",
"that",
"will",
"break",
"with",
"big",
"numbers"
] | 6a1113ff90ba69e479ec2b9902799f1ab2e69082 | https://github.com/s-yadav/react-number-format/blob/6a1113ff90ba69e479ec2b9902799f1ab2e69082/lib/utils.js#L105-L127 | train |
s-yadav/react-number-format | lib/utils.js | findChangedIndex | function findChangedIndex(prevValue, newValue) {
var i = 0,
j = 0;
var prevLength = prevValue.length;
var newLength = newValue.length;
while (prevValue[i] === newValue[i] && i < prevLength) {
i++;
} //check what has been changed from last
while (prevValue[prevLength - 1 - j] === newValue[newLen... | javascript | function findChangedIndex(prevValue, newValue) {
var i = 0,
j = 0;
var prevLength = prevValue.length;
var newLength = newValue.length;
while (prevValue[i] === newValue[i] && i < prevLength) {
i++;
} //check what has been changed from last
while (prevValue[prevLength - 1 - j] === newValue[newLen... | [
"function",
"findChangedIndex",
"(",
"prevValue",
",",
"newValue",
")",
"{",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"0",
";",
"var",
"prevLength",
"=",
"prevValue",
".",
"length",
";",
"var",
"newLength",
"=",
"newValue",
".",
"length",
";",
"while",
"("... | Given previous value and newValue it returns the index
start - end to which values have changed.
This function makes assumption about only consecutive
characters are changed which is correct assumption for caret input. | [
"Given",
"previous",
"value",
"and",
"newValue",
"it",
"returns",
"the",
"index",
"start",
"-",
"end",
"to",
"which",
"values",
"have",
"changed",
".",
"This",
"function",
"makes",
"assumption",
"about",
"only",
"consecutive",
"characters",
"are",
"changed",
"... | 6a1113ff90ba69e479ec2b9902799f1ab2e69082 | https://github.com/s-yadav/react-number-format/blob/6a1113ff90ba69e479ec2b9902799f1ab2e69082/lib/utils.js#L172-L191 | train |
s-yadav/react-number-format | custom_formatters/card_expiry.js | limit | function limit(val, max) {
if (val.length === 1 && val[0] > max[0]) {
val = '0' + val;
}
if (val.length === 2) {
if (Number(val) === 0) {
val = '01';
//this can happen when user paste number
} else if (val > max) {
val = max;
}
}
return val;
} | javascript | function limit(val, max) {
if (val.length === 1 && val[0] > max[0]) {
val = '0' + val;
}
if (val.length === 2) {
if (Number(val) === 0) {
val = '01';
//this can happen when user paste number
} else if (val > max) {
val = max;
}
}
return val;
} | [
"function",
"limit",
"(",
"val",
",",
"max",
")",
"{",
"if",
"(",
"val",
".",
"length",
"===",
"1",
"&&",
"val",
"[",
"0",
"]",
">",
"max",
"[",
"0",
"]",
")",
"{",
"val",
"=",
"'0'",
"+",
"val",
";",
"}",
"if",
"(",
"val",
".",
"length",
... | This method limit val between 1 to max
val and max both are passed as string | [
"This",
"method",
"limit",
"val",
"between",
"1",
"to",
"max",
"val",
"and",
"max",
"both",
"are",
"passed",
"as",
"string"
] | 6a1113ff90ba69e479ec2b9902799f1ab2e69082 | https://github.com/s-yadav/react-number-format/blob/6a1113ff90ba69e479ec2b9902799f1ab2e69082/custom_formatters/card_expiry.js#L5-L21 | train |
wework/speccy | lib/loader.js | readSpecFile | function readSpecFile(file, options) {
if (options.verbose > 1) {
file ? console.error('GET ' + file) : console.error('GET <stdin>');
}
if (!file) {
// standard input
return readFileStdinAsync();
} else if (file && file.startsWith('http')) {
// remote file
return ... | javascript | function readSpecFile(file, options) {
if (options.verbose > 1) {
file ? console.error('GET ' + file) : console.error('GET <stdin>');
}
if (!file) {
// standard input
return readFileStdinAsync();
} else if (file && file.startsWith('http')) {
// remote file
return ... | [
"function",
"readSpecFile",
"(",
"file",
",",
"options",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
">",
"1",
")",
"{",
"file",
"?",
"console",
".",
"error",
"(",
"'GET '",
"+",
"file",
")",
":",
"console",
".",
"error",
"(",
"'GET <stdin>'",
")... | file can be null, meaning stdin | [
"file",
"can",
"be",
"null",
"meaning",
"stdin"
] | 740d19d88935db7735250c16abc2ad09256b5854 | https://github.com/wework/speccy/blob/740d19d88935db7735250c16abc2ad09256b5854/lib/loader.js#L65-L85 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | cleanPath | function cleanPath( txt ) {
var ch;
var j;
if ( txt.charCodeAt( 0 ) === 34 ) {
j = 1;
for ( j = 1; j < txt.length; j++ ) {
ch = txt.charCodeAt( j );
if ( ch === 34 ) {
txt = txt.slice( 1, j );
break;
}
}
}
j = txt.indexOf( '/docs/types/' );
if ( j >= 0 ) {
txt = txt.slice( ... | javascript | function cleanPath( txt ) {
var ch;
var j;
if ( txt.charCodeAt( 0 ) === 34 ) {
j = 1;
for ( j = 1; j < txt.length; j++ ) {
ch = txt.charCodeAt( j );
if ( ch === 34 ) {
txt = txt.slice( 1, j );
break;
}
}
}
j = txt.indexOf( '/docs/types/' );
if ( j >= 0 ) {
txt = txt.slice( ... | [
"function",
"cleanPath",
"(",
"txt",
")",
"{",
"var",
"ch",
";",
"var",
"j",
";",
"if",
"(",
"txt",
".",
"charCodeAt",
"(",
"0",
")",
"===",
"34",
")",
"{",
"j",
"=",
"1",
";",
"for",
"(",
"j",
"=",
"1",
";",
"j",
"<",
"txt",
".",
"length",... | eslint-disable-line func-names, no-restricted-syntax
Removes extraneous information from a path.
@private
@param {string} txt - text 1
@returns {string} cleaned text | [
"eslint",
"-",
"disable",
"-",
"line",
"func",
"-",
"names",
"no",
"-",
"restricted",
"-",
"syntax",
"Removes",
"extraneous",
"information",
"from",
"a",
"path",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L29-L52 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | cleanTitle | function cleanTitle( el ) {
var txt = cleanPath( el.innerHTML );
var idx = txt.indexOf( 'stdlib' );
if ( idx === -1 || idx === 1 ) { // e.g., '@stdlib/types/iter'
txt = 'stdlib | ' + txt;
} else if ( txt.indexOf( ' | stdlib' ) === txt.length-9 ) { // e.g., 'foo/bar | stdlib'
txt = 'stdlib | ' + txt.slice(... | javascript | function cleanTitle( el ) {
var txt = cleanPath( el.innerHTML );
var idx = txt.indexOf( 'stdlib' );
if ( idx === -1 || idx === 1 ) { // e.g., '@stdlib/types/iter'
txt = 'stdlib | ' + txt;
} else if ( txt.indexOf( ' | stdlib' ) === txt.length-9 ) { // e.g., 'foo/bar | stdlib'
txt = 'stdlib | ' + txt.slice(... | [
"function",
"cleanTitle",
"(",
"el",
")",
"{",
"var",
"txt",
"=",
"cleanPath",
"(",
"el",
".",
"innerHTML",
")",
";",
"var",
"idx",
"=",
"txt",
".",
"indexOf",
"(",
"'stdlib'",
")",
";",
"if",
"(",
"idx",
"===",
"-",
"1",
"||",
"idx",
"===",
"1",... | Cleans up the document title.
@private
@param {DOMElement} el - title element | [
"Cleans",
"up",
"the",
"document",
"title",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L60-L69 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | cleanLinks | function cleanLinks( el ) {
var i;
for ( i = 0; i < el.length; i++ ) {
el[ i ].innerHTML = cleanPath( el[ i ].innerHTML );
}
} | javascript | function cleanLinks( el ) {
var i;
for ( i = 0; i < el.length; i++ ) {
el[ i ].innerHTML = cleanPath( el[ i ].innerHTML );
}
} | [
"function",
"cleanLinks",
"(",
"el",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"el",
".",
"length",
";",
"i",
"++",
")",
"{",
"el",
"[",
"i",
"]",
".",
"innerHTML",
"=",
"cleanPath",
"(",
"el",
"[",
"i",
"]",
".",... | Cleans up link text.
@private
@param {Array<DOMElement>} el - list of anchor elements to clean | [
"Cleans",
"up",
"link",
"text",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L77-L82 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | cleanHeadings | function cleanHeadings( el ) {
var i;
for ( i = 0; i < el.length; i++ ) {
el[ i ].innerHTML = cleanHeading( el[ i ].innerHTML );
}
} | javascript | function cleanHeadings( el ) {
var i;
for ( i = 0; i < el.length; i++ ) {
el[ i ].innerHTML = cleanHeading( el[ i ].innerHTML );
}
} | [
"function",
"cleanHeadings",
"(",
"el",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"el",
".",
"length",
";",
"i",
"++",
")",
"{",
"el",
"[",
"i",
"]",
".",
"innerHTML",
"=",
"cleanHeading",
"(",
"el",
"[",
"i",
"]",
... | Cleans up heading text.
@private
@param {Array<DOMElement>} el - list of heading elements to clean | [
"Cleans",
"up",
"heading",
"text",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L104-L109 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | updateDescription | function updateDescription( txt ) {
var ch;
if ( txt.length === 0 ) {
return txt;
}
ch = txt[ 0 ].toUpperCase();
if ( ch !== txt[ 0 ] ) {
txt = ch + txt.slice( 1 );
}
if ( txt.charCodeAt( txt.length-1 ) !== 46 ) { // .
txt += '.';
}
return txt;
} | javascript | function updateDescription( txt ) {
var ch;
if ( txt.length === 0 ) {
return txt;
}
ch = txt[ 0 ].toUpperCase();
if ( ch !== txt[ 0 ] ) {
txt = ch + txt.slice( 1 );
}
if ( txt.charCodeAt( txt.length-1 ) !== 46 ) { // .
txt += '.';
}
return txt;
} | [
"function",
"updateDescription",
"(",
"txt",
")",
"{",
"var",
"ch",
";",
"if",
"(",
"txt",
".",
"length",
"===",
"0",
")",
"{",
"return",
"txt",
";",
"}",
"ch",
"=",
"txt",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
";",
"if",
"(",
"ch",
"!==... | Updates a description.
@private
@param {string} txt - description
@returns {string} updated description | [
"Updates",
"a",
"description",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L118-L131 | train |
stdlib-js/stdlib | etc/typedoc/theme/assets/js/theme.js | main | function main() {
var el;
el = document.querySelector( 'title' );
cleanTitle( el );
el = document.querySelectorAll( '.tsd-kind-external-module a' );
cleanLinks( el );
el = document.querySelectorAll( '.tsd-is-not-exported a' );
cleanLinks( el );
el = document.querySelectorAll( '.tsd-breadcrumb a' );
... | javascript | function main() {
var el;
el = document.querySelector( 'title' );
cleanTitle( el );
el = document.querySelectorAll( '.tsd-kind-external-module a' );
cleanLinks( el );
el = document.querySelectorAll( '.tsd-is-not-exported a' );
cleanLinks( el );
el = document.querySelectorAll( '.tsd-breadcrumb a' );
... | [
"function",
"main",
"(",
")",
"{",
"var",
"el",
";",
"el",
"=",
"document",
".",
"querySelector",
"(",
"'title'",
")",
";",
"cleanTitle",
"(",
"el",
")",
";",
"el",
"=",
"document",
".",
"querySelectorAll",
"(",
"'.tsd-kind-external-module a'",
")",
";",
... | Main execution sequence.
@private | [
"Main",
"execution",
"sequence",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/etc/typedoc/theme/assets/js/theme.js#L151-L174 | train |
stdlib-js/stdlib | tools/docs/jsdoc/templates/json/transforms/mixin/index.js | transform | function transform( node ) {
return {
'name': node.name,
'description': node.description || '',
'access': node.access || '',
'virtual': !!node.virtual
};
} | javascript | function transform( node ) {
return {
'name': node.name,
'description': node.description || '',
'access': node.access || '',
'virtual': !!node.virtual
};
} | [
"function",
"transform",
"(",
"node",
")",
"{",
"return",
"{",
"'name'",
":",
"node",
".",
"name",
",",
"'description'",
":",
"node",
".",
"description",
"||",
"''",
",",
"'access'",
":",
"node",
".",
"access",
"||",
"''",
",",
"'virtual'",
":",
"!",
... | Transforms a `mixin` doclet element.
@param {Object} node - doclet element
@returns {Object} filtered object | [
"Transforms",
"a",
"mixin",
"doclet",
"element",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/tools/docs/jsdoc/templates/json/transforms/mixin/index.js#L9-L16 | train |
stdlib-js/stdlib | tools/docs/jsdoc/templates/json/transforms/member/index.js | transform | function transform( node ) {
var type;
if ( node.type ) {
if ( node.type.length === 1 ) {
type = node.type[ 0 ];
} else {
type = node.type;
}
} else {
type = '';
}
return {
'name': node.name,
'description': node.description || '',
'type': type,
'access': node.access || '',
'virtual': !!node... | javascript | function transform( node ) {
var type;
if ( node.type ) {
if ( node.type.length === 1 ) {
type = node.type[ 0 ];
} else {
type = node.type;
}
} else {
type = '';
}
return {
'name': node.name,
'description': node.description || '',
'type': type,
'access': node.access || '',
'virtual': !!node... | [
"function",
"transform",
"(",
"node",
")",
"{",
"var",
"type",
";",
"if",
"(",
"node",
".",
"type",
")",
"{",
"if",
"(",
"node",
".",
"type",
".",
"length",
"===",
"1",
")",
"{",
"type",
"=",
"node",
".",
"type",
"[",
"0",
"]",
";",
"}",
"els... | Transforms a `member` doclet element.
@param {Object} node - doclet element
@returns {Object} filtered object | [
"Transforms",
"a",
"member",
"doclet",
"element",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/tools/docs/jsdoc/templates/json/transforms/member/index.js#L9-L27 | train |
stdlib-js/stdlib | tools/snippets/benchmark/benchmark.length.js | benchmark | function benchmark( b ) {
var i;
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// TODO: synchronous task
if ( TODO/* TODO: condition */ ) {
b.fail( 'something went wrong' );
}
}
b.toc();
if ( TODO/* TODO: condition */ ) {
b.fail( 'something went wrong' );
}
b.pass( 'benchmark finished... | javascript | function benchmark( b ) {
var i;
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// TODO: synchronous task
if ( TODO/* TODO: condition */ ) {
b.fail( 'something went wrong' );
}
}
b.toc();
if ( TODO/* TODO: condition */ ) {
b.fail( 'something went wrong' );
}
b.pass( 'benchmark finished... | [
"function",
"benchmark",
"(",
"b",
")",
"{",
"var",
"i",
";",
"b",
".",
"tic",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"b",
".",
"iterations",
";",
"i",
"++",
")",
"{",
"// TODO: synchronous task",
"if",
"(",
"TODO",
"/* TODO: co... | Benchmark function.
@private
@param {Benchmark} b - benchmark instance | [
"Benchmark",
"function",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/tools/snippets/benchmark/benchmark.length.js#L54-L70 | train |
stdlib-js/stdlib | tools/docs/jsdoc/templates/json/transforms/function/returns.js | transform | function transform( nodes ) {
var type;
var desc;
if ( nodes[ 0 ].type ) {
if ( nodes[ 0 ].type.names.length === 1 ) {
type = nodes[ 0 ].type.names[ 0 ];
} else {
type = nodes[ 0 ].type.names;
}
} else {
type = '';
}
desc = nodes[ 0 ].description || '';
return {
'type': type,
'description': des... | javascript | function transform( nodes ) {
var type;
var desc;
if ( nodes[ 0 ].type ) {
if ( nodes[ 0 ].type.names.length === 1 ) {
type = nodes[ 0 ].type.names[ 0 ];
} else {
type = nodes[ 0 ].type.names;
}
} else {
type = '';
}
desc = nodes[ 0 ].description || '';
return {
'type': type,
'description': des... | [
"function",
"transform",
"(",
"nodes",
")",
"{",
"var",
"type",
";",
"var",
"desc",
";",
"if",
"(",
"nodes",
"[",
"0",
"]",
".",
"type",
")",
"{",
"if",
"(",
"nodes",
"[",
"0",
"]",
".",
"type",
".",
"names",
".",
"length",
"===",
"1",
")",
"... | Transforms `returns` doclet elements.
@param {Object[]} nodes - doclet elements
@returns {Object} filtered object | [
"Transforms",
"returns",
"doclet",
"elements",
"."
] | 1026b15f47f0b4d2c0db8617f22a35873c514919 | https://github.com/stdlib-js/stdlib/blob/1026b15f47f0b4d2c0db8617f22a35873c514919/tools/docs/jsdoc/templates/json/transforms/function/returns.js#L9-L26 | train |
reactjs/react-docgen | src/utils/getMethodDocumentation.js | getMethodReturnDoc | function getMethodReturnDoc(methodPath) {
const functionExpression = methodPath.get('value');
if (functionExpression.node.returnType) {
const returnType = getTypeAnnotation(functionExpression.get('returnType'));
if (returnType && t.Flow.check(returnType.node)) {
return { type: getFlowType(returnType)... | javascript | function getMethodReturnDoc(methodPath) {
const functionExpression = methodPath.get('value');
if (functionExpression.node.returnType) {
const returnType = getTypeAnnotation(functionExpression.get('returnType'));
if (returnType && t.Flow.check(returnType.node)) {
return { type: getFlowType(returnType)... | [
"function",
"getMethodReturnDoc",
"(",
"methodPath",
")",
"{",
"const",
"functionExpression",
"=",
"methodPath",
".",
"get",
"(",
"'value'",
")",
";",
"if",
"(",
"functionExpression",
".",
"node",
".",
"returnType",
")",
"{",
"const",
"returnType",
"=",
"getTy... | Extract flow return type. | [
"Extract",
"flow",
"return",
"type",
"."
] | f78450432c6b1cad788327a2f97f782091958b7a | https://github.com/reactjs/react-docgen/blob/f78450432c6b1cad788327a2f97f782091958b7a/src/utils/getMethodDocumentation.js#L72-L85 | train |
reactjs/react-docgen | src/handlers/propTypeCompositionHandler.js | amendComposes | function amendComposes(documentation, path) {
const moduleName = resolveToModule(path);
if (moduleName) {
documentation.addComposes(moduleName);
}
} | javascript | function amendComposes(documentation, path) {
const moduleName = resolveToModule(path);
if (moduleName) {
documentation.addComposes(moduleName);
}
} | [
"function",
"amendComposes",
"(",
"documentation",
",",
"path",
")",
"{",
"const",
"moduleName",
"=",
"resolveToModule",
"(",
"path",
")",
";",
"if",
"(",
"moduleName",
")",
"{",
"documentation",
".",
"addComposes",
"(",
"moduleName",
")",
";",
"}",
"}"
] | It resolves the path to its module name and adds it to the "composes" entry
in the documentation. | [
"It",
"resolves",
"the",
"path",
"to",
"its",
"module",
"name",
"and",
"adds",
"it",
"to",
"the",
"composes",
"entry",
"in",
"the",
"documentation",
"."
] | f78450432c6b1cad788327a2f97f782091958b7a | https://github.com/reactjs/react-docgen/blob/f78450432c6b1cad788327a2f97f782091958b7a/src/handlers/propTypeCompositionHandler.js#L22-L27 | train |
aws/aws-iot-device-sdk-js | device/lib/tls.js | buildBuilder | function buildBuilder(mqttClient, opts) {
var connection;
connection = tls.connect(opts);
function handleTLSerrors(err) {
mqttClient.emit('error', err);
connection.end();
}
connection.on('secureConnect', function() {
if (!connection.authorized) {
connection.emit('error', new... | javascript | function buildBuilder(mqttClient, opts) {
var connection;
connection = tls.connect(opts);
function handleTLSerrors(err) {
mqttClient.emit('error', err);
connection.end();
}
connection.on('secureConnect', function() {
if (!connection.authorized) {
connection.emit('error', new... | [
"function",
"buildBuilder",
"(",
"mqttClient",
",",
"opts",
")",
"{",
"var",
"connection",
";",
"connection",
"=",
"tls",
".",
"connect",
"(",
"opts",
")",
";",
"function",
"handleTLSerrors",
"(",
"err",
")",
"{",
"mqttClient",
".",
"emit",
"(",
"'error'",... | npm deps app deps | [
"npm",
"deps",
"app",
"deps"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/device/lib/tls.js#L23-L43 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | errorToString | function errorToString(err) {
if (isUndefined(err)) {
return undefined;
} else if (err.toString().length > maxStatusDetailLength) {
return err.toString().substring(0, maxStatusDetailLength - 3) + '...';
} else {
return err.toString();
}
} | javascript | function errorToString(err) {
if (isUndefined(err)) {
return undefined;
} else if (err.toString().length > maxStatusDetailLength) {
return err.toString().substring(0, maxStatusDetailLength - 3) + '...';
} else {
return err.toString();
}
} | [
"function",
"errorToString",
"(",
"err",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"err",
")",
")",
"{",
"return",
"undefined",
";",
"}",
"else",
"if",
"(",
"err",
".",
"toString",
"(",
")",
".",
"length",
">",
"maxStatusDetailLength",
")",
"{",
"return... | Private function to safely convert errors to strings | [
"Private",
"function",
"to",
"safely",
"convert",
"errors",
"to",
"strings"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L102-L110 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | validateChecksum | function validateChecksum(fileName, checksum, cb) {
if (isUndefined(checksum) || isUndefined(checksum.hashAlgorithm)) {
cb();
return;
}
if (isUndefined(checksum.inline) || isUndefined(checksum.inline.value)) {
cb(new Error('Installed jobs agent only supports inline checksum value provided in... | javascript | function validateChecksum(fileName, checksum, cb) {
if (isUndefined(checksum) || isUndefined(checksum.hashAlgorithm)) {
cb();
return;
}
if (isUndefined(checksum.inline) || isUndefined(checksum.inline.value)) {
cb(new Error('Installed jobs agent only supports inline checksum value provided in... | [
"function",
"validateChecksum",
"(",
"fileName",
",",
"checksum",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"checksum",
")",
"||",
"isUndefined",
"(",
"checksum",
".",
"hashAlgorithm",
")",
")",
"{",
"cb",
"(",
")",
";",
"return",
";",
"}",
"... | Private function to validate checksum | [
"Private",
"function",
"to",
"validate",
"checksum"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L115-L150 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | validateSignature | function validateSignature(fileName, signature, cb) {
if (isUndefined(signature) || isUndefined(signature.codesign)) {
cb();
return;
}
if (isUndefined(codeSignCertFileName)) {
cb(new Error('No code sign certificate file specified'));
return;
}
var codeSignCert;
try {
c... | javascript | function validateSignature(fileName, signature, cb) {
if (isUndefined(signature) || isUndefined(signature.codesign)) {
cb();
return;
}
if (isUndefined(codeSignCertFileName)) {
cb(new Error('No code sign certificate file specified'));
return;
}
var codeSignCert;
try {
c... | [
"function",
"validateSignature",
"(",
"fileName",
",",
"signature",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"signature",
")",
"||",
"isUndefined",
"(",
"signature",
".",
"codesign",
")",
")",
"{",
"cb",
"(",
")",
";",
"return",
";",
"}",
"i... | Private function to validate signature | [
"Private",
"function",
"to",
"validate",
"signature"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L156-L213 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | backupFiles | function backupFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
if (isUndefined(file)) {
cb(new Error('empty file specification'));
return;
... | javascript | function backupFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
if (isUndefined(file)) {
cb(new Error('empty file specification'));
return;
... | [
"function",
"backupFiles",
"(",
"job",
",",
"iFile",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"cb",
")",
")",
"{",
"cb",
"=",
"iFile",
";",
"iFile",
"=",
"0",
";",
"}",
"if",
"(",
"iFile",
"===",
"job",
".",
"document",
".",
"files",
... | Private function to backup existing files before downloading | [
"Private",
"function",
"to",
"backup",
"existing",
"files",
"before",
"downloading"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L219-L257 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | rollbackFiles | function rollbackFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
var filePath = path.resolve(job.document.workingDirectory || '', file.fileName);
if (!... | javascript | function rollbackFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
var filePath = path.resolve(job.document.workingDirectory || '', file.fileName);
if (!... | [
"function",
"rollbackFiles",
"(",
"job",
",",
"iFile",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"cb",
")",
")",
"{",
"cb",
"=",
"iFile",
";",
"iFile",
"=",
"0",
";",
"}",
"if",
"(",
"iFile",
"===",
"job",
".",
"document",
".",
"files",... | Private function to rollback files after a failed install operation | [
"Private",
"function",
"to",
"rollback",
"files",
"after",
"a",
"failed",
"install",
"operation"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L263-L289 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | downloadFiles | function downloadFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
var filePath = path.resolve(job.document.workingDirectory || '', file.fileName);
if (... | javascript | function downloadFiles(job, iFile, cb) {
if (isUndefined(cb)) {
cb = iFile;
iFile = 0;
}
if (iFile === job.document.files.length) {
cb();
return;
}
var file = job.document.files[iFile];
var filePath = path.resolve(job.document.workingDirectory || '', file.fileName);
if (... | [
"function",
"downloadFiles",
"(",
"job",
",",
"iFile",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"cb",
")",
")",
"{",
"cb",
"=",
"iFile",
";",
"iFile",
"=",
"0",
";",
"}",
"if",
"(",
"iFile",
"===",
"job",
".",
"document",
".",
"files",... | Private function to download specified files in sequence to temporary locations | [
"Private",
"function",
"to",
"download",
"specified",
"files",
"in",
"sequence",
"to",
"temporary",
"locations"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L295-L339 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | updateInstalledPackage | function updateInstalledPackage(updatedPackage) {
var packageIndex = installedPackages.findIndex(function(element) {
return (element.packageName === updatedPackage.packageName);
});
if (packageIndex < 0) {
packageIndex = installedPackages.length;
installedPackages.push(updatedPackage);
... | javascript | function updateInstalledPackage(updatedPackage) {
var packageIndex = installedPackages.findIndex(function(element) {
return (element.packageName === updatedPackage.packageName);
});
if (packageIndex < 0) {
packageIndex = installedPackages.length;
installedPackages.push(updatedPackage);
... | [
"function",
"updateInstalledPackage",
"(",
"updatedPackage",
")",
"{",
"var",
"packageIndex",
"=",
"installedPackages",
".",
"findIndex",
"(",
"function",
"(",
"element",
")",
"{",
"return",
"(",
"element",
".",
"packageName",
"===",
"updatedPackage",
".",
"packag... | Private function to update installed package | [
"Private",
"function",
"to",
"update",
"installed",
"package"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L345-L358 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | startPackage | function startPackage(package, cb) {
if (isUndefined(packageRuntimes[package.packageName])) {
packageRuntimes[package.packageName] = {};
}
var packageRuntime = packageRuntimes[package.packageName];
if (!isUndefined(packageRuntime.process)) {
cb(new Error('package already running'));
retu... | javascript | function startPackage(package, cb) {
if (isUndefined(packageRuntimes[package.packageName])) {
packageRuntimes[package.packageName] = {};
}
var packageRuntime = packageRuntimes[package.packageName];
if (!isUndefined(packageRuntime.process)) {
cb(new Error('package already running'));
retu... | [
"function",
"startPackage",
"(",
"package",
",",
"cb",
")",
"{",
"if",
"(",
"isUndefined",
"(",
"packageRuntimes",
"[",
"package",
".",
"packageName",
"]",
")",
")",
"{",
"packageRuntimes",
"[",
"package",
".",
"packageName",
"]",
"=",
"{",
"}",
";",
"}"... | Private function to start installed package | [
"Private",
"function",
"to",
"start",
"installed",
"package"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L414-L444 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | shutdownHandler | function shutdownHandler(job) {
// Change status to IN_PROGRESS
job.inProgress({ operation: job.operation, step: 'attempting' }, function(err) {
showJobsError(err);
var delay = (isUndefined(job.document.delay) ? '0' : job.document.delay.toString());
// Check for adequate permissions to perfor... | javascript | function shutdownHandler(job) {
// Change status to IN_PROGRESS
job.inProgress({ operation: job.operation, step: 'attempting' }, function(err) {
showJobsError(err);
var delay = (isUndefined(job.document.delay) ? '0' : job.document.delay.toString());
// Check for adequate permissions to perfor... | [
"function",
"shutdownHandler",
"(",
"job",
")",
"{",
"// Change status to IN_PROGRESS",
"job",
".",
"inProgress",
"(",
"{",
"operation",
":",
"job",
".",
"operation",
",",
"step",
":",
"'attempting'",
"}",
",",
"function",
"(",
"err",
")",
"{",
"showJobsError"... | Private function to handle gracefull shutdown operation | [
"Private",
"function",
"to",
"handle",
"gracefull",
"shutdown",
"operation"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L580-L603 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | rebootHandler | function rebootHandler(job) {
// Check if the reboot job has not yet been initiated
if (job.status.status === 'QUEUED' ||
isUndefined(job.status.statusDetails) ||
isUndefined(job.status.statusDetails.step)) {
// Change status to IN_PROGRESS
job.inProgress({ operation: job.operation, s... | javascript | function rebootHandler(job) {
// Check if the reboot job has not yet been initiated
if (job.status.status === 'QUEUED' ||
isUndefined(job.status.statusDetails) ||
isUndefined(job.status.statusDetails.step)) {
// Change status to IN_PROGRESS
job.inProgress({ operation: job.operation, s... | [
"function",
"rebootHandler",
"(",
"job",
")",
"{",
"// Check if the reboot job has not yet been initiated",
"if",
"(",
"job",
".",
"status",
".",
"status",
"===",
"'QUEUED'",
"||",
"isUndefined",
"(",
"job",
".",
"status",
".",
"statusDetails",
")",
"||",
"isUndef... | Private function to handle reboot operation | [
"Private",
"function",
"to",
"handle",
"reboot",
"operation"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L609-L637 | train |
aws/aws-iot-device-sdk-js | examples/jobs-agent.js | systemStatusHandler | function systemStatusHandler(job) {
var packageNames = '[';
for (var i = 0; i < installedPackages.length; i++) {
packageNames += installedPackages[i].packageName + ((i !== installedPackages.length - 1) ? ', ' : '');
}
packageNames += ']';
job.succeeded({
operation: job.operation,
inst... | javascript | function systemStatusHandler(job) {
var packageNames = '[';
for (var i = 0; i < installedPackages.length; i++) {
packageNames += installedPackages[i].packageName + ((i !== installedPackages.length - 1) ? ', ' : '');
}
packageNames += ']';
job.succeeded({
operation: job.operation,
inst... | [
"function",
"systemStatusHandler",
"(",
"job",
")",
"{",
"var",
"packageNames",
"=",
"'['",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"installedPackages",
".",
"length",
";",
"i",
"++",
")",
"{",
"packageNames",
"+=",
"installedPackages",
"["... | Private function to handle systemStatus operation | [
"Private",
"function",
"to",
"handle",
"systemStatus",
"operation"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/examples/jobs-agent.js#L643-L661 | train |
aws/aws-iot-device-sdk-js | device/index.js | _markConnectionStable | function _markConnectionStable() {
currentReconnectTimeMs = baseReconnectTimeMs;
device.options.reconnectPeriod = currentReconnectTimeMs;
//
// Mark this timeout as expired
//
connectionTimer = null;
connectionState = 'stable';
} | javascript | function _markConnectionStable() {
currentReconnectTimeMs = baseReconnectTimeMs;
device.options.reconnectPeriod = currentReconnectTimeMs;
//
// Mark this timeout as expired
//
connectionTimer = null;
connectionState = 'stable';
} | [
"function",
"_markConnectionStable",
"(",
")",
"{",
"currentReconnectTimeMs",
"=",
"baseReconnectTimeMs",
";",
"device",
".",
"options",
".",
"reconnectPeriod",
"=",
"currentReconnectTimeMs",
";",
"//",
"// Mark this timeout as expired",
"//",
"connectionTimer",
"=",
"nul... | Timeout expiry function for the connection timer; once a connection is stable, reset the current reconnection time to the base value. | [
"Timeout",
"expiry",
"function",
"for",
"the",
"connection",
"timer",
";",
"once",
"a",
"connection",
"is",
"stable",
"reset",
"the",
"current",
"reconnection",
"time",
"to",
"the",
"base",
"value",
"."
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/device/index.js#L647-L655 | train |
aws/aws-iot-device-sdk-js | device/index.js | _trimOfflinePublishQueueIfNecessary | function _trimOfflinePublishQueueIfNecessary() {
var rc = true;
if ((offlineQueueMaxSize > 0) &&
(offlinePublishQueue.length >= offlineQueueMaxSize)) {
//
// The queue has reached its maximum size, trim it
// according to the defined drop behavior.
//
i... | javascript | function _trimOfflinePublishQueueIfNecessary() {
var rc = true;
if ((offlineQueueMaxSize > 0) &&
(offlinePublishQueue.length >= offlineQueueMaxSize)) {
//
// The queue has reached its maximum size, trim it
// according to the defined drop behavior.
//
i... | [
"function",
"_trimOfflinePublishQueueIfNecessary",
"(",
")",
"{",
"var",
"rc",
"=",
"true",
";",
"if",
"(",
"(",
"offlineQueueMaxSize",
">",
"0",
")",
"&&",
"(",
"offlinePublishQueue",
".",
"length",
">=",
"offlineQueueMaxSize",
")",
")",
"{",
"//",
"// The qu... | Trim the offline queue if required; returns true if another element can be placed in the queue | [
"Trim",
"the",
"offline",
"queue",
"if",
"required",
";",
"returns",
"true",
"if",
"another",
"element",
"can",
"be",
"placed",
"in",
"the",
"queue"
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/device/index.js#L660-L676 | train |
aws/aws-iot-device-sdk-js | device/index.js | _drainOperationQueue | function _drainOperationQueue() {
//
// Handle our active subscriptions first, using a cloned
// copy of the array. We shift them out one-by-one until
// all have been processed, leaving the official record
// of active subscriptions untouched.
//
var subscription = clonedSu... | javascript | function _drainOperationQueue() {
//
// Handle our active subscriptions first, using a cloned
// copy of the array. We shift them out one-by-one until
// all have been processed, leaving the official record
// of active subscriptions untouched.
//
var subscription = clonedSu... | [
"function",
"_drainOperationQueue",
"(",
")",
"{",
"//",
"// Handle our active subscriptions first, using a cloned",
"// copy of the array. We shift them out one-by-one until",
"// all have been processed, leaving the official record",
"// of active subscriptions untouched.",
"// ",
"var",
... | Timeout expiry function for the drain timer; once a connection has been established, begin draining cached transactions. | [
"Timeout",
"expiry",
"function",
"for",
"the",
"drain",
"timer",
";",
"once",
"a",
"connection",
"has",
"been",
"established",
"begin",
"draining",
"cached",
"transactions",
"."
] | 481445639ff6bb92586c63d3c9ee85dd37728453 | https://github.com/aws/aws-iot-device-sdk-js/blob/481445639ff6bb92586c63d3c9ee85dd37728453/device/index.js#L682-L744 | train |
siimon/prom-client | lib/metricAggregators.js | AggregatorFactory | function AggregatorFactory(aggregatorFn) {
return metrics => {
if (metrics.length === 0) return;
const result = {
help: metrics[0].help,
name: metrics[0].name,
type: metrics[0].type,
values: [],
aggregator: metrics[0].aggregator
};
// Gather metrics by metricName and labels.
const byLabels = n... | javascript | function AggregatorFactory(aggregatorFn) {
return metrics => {
if (metrics.length === 0) return;
const result = {
help: metrics[0].help,
name: metrics[0].name,
type: metrics[0].type,
values: [],
aggregator: metrics[0].aggregator
};
// Gather metrics by metricName and labels.
const byLabels = n... | [
"function",
"AggregatorFactory",
"(",
"aggregatorFn",
")",
"{",
"return",
"metrics",
"=>",
"{",
"if",
"(",
"metrics",
".",
"length",
"===",
"0",
")",
"return",
";",
"const",
"result",
"=",
"{",
"help",
":",
"metrics",
"[",
"0",
"]",
".",
"help",
",",
... | Returns a new function that applies the `aggregatorFn` to the values.
@param {Function} aggregatorFn function to apply to values.
@return {Function} aggregator function | [
"Returns",
"a",
"new",
"function",
"that",
"applies",
"the",
"aggregatorFn",
"to",
"the",
"values",
"."
] | b66755a6f79c7483dc899360eaf9759f330cd420 | https://github.com/siimon/prom-client/blob/b66755a6f79c7483dc899360eaf9759f330cd420/lib/metricAggregators.js#L10-L43 | train |
amireh/happypack | lib/HappyForegroundThreadPool.js | HappyForegroundThreadPool | function HappyForegroundThreadPool(config) {
var rpcHandler, worker;
return {
size: config.size,
start: function(compilerId, compiler, compilerOptions, done) {
var fakeCompiler = new HappyFakeCompiler({
id: 'foreground',
compilerId: compilerId,
send: function executeCompilerR... | javascript | function HappyForegroundThreadPool(config) {
var rpcHandler, worker;
return {
size: config.size,
start: function(compilerId, compiler, compilerOptions, done) {
var fakeCompiler = new HappyFakeCompiler({
id: 'foreground',
compilerId: compilerId,
send: function executeCompilerR... | [
"function",
"HappyForegroundThreadPool",
"(",
"config",
")",
"{",
"var",
"rpcHandler",
",",
"worker",
";",
"return",
"{",
"size",
":",
"config",
".",
"size",
",",
"start",
":",
"function",
"(",
"compilerId",
",",
"compiler",
",",
"compilerOptions",
",",
"don... | Create a thread pool that can be shared between multiple plugin instances.
@param {Object} config
@param {Array.<String>} config.loaders
The loaders to configure the (foreground) worker with. | [
"Create",
"a",
"thread",
"pool",
"that",
"can",
"be",
"shared",
"between",
"multiple",
"plugin",
"instances",
"."
] | e45926e9754f42098d882ff129269b15907ef00e | https://github.com/amireh/happypack/blob/e45926e9754f42098d882ff129269b15907ef00e/lib/HappyForegroundThreadPool.js#L13-L68 | train |
assaf/zombie | src/reroute.js | enableRerouting | function enableRerouting() {
if (enabled)
return;
enabled = true;
const connect = Net.Socket.prototype.connect;
Net.Socket.prototype.connect = function(options, callback) {
const hasNormalizedArgs = Object.getOwnPropertySymbols && Object.getOwnPropertySymbols(options).length > 0;
const isNode8 ... | javascript | function enableRerouting() {
if (enabled)
return;
enabled = true;
const connect = Net.Socket.prototype.connect;
Net.Socket.prototype.connect = function(options, callback) {
const hasNormalizedArgs = Object.getOwnPropertySymbols && Object.getOwnPropertySymbols(options).length > 0;
const isNode8 ... | [
"function",
"enableRerouting",
"(",
")",
"{",
"if",
"(",
"enabled",
")",
"return",
";",
"enabled",
"=",
"true",
";",
"const",
"connect",
"=",
"Net",
".",
"Socket",
".",
"prototype",
".",
"connect",
";",
"Net",
".",
"Socket",
".",
"prototype",
".",
"con... | Called once to hack Socket.connect | [
"Called",
"once",
"to",
"hack",
"Socket",
".",
"connect"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/reroute.js#L51-L70 | train |
assaf/zombie | src/assert.js | assertMatch | function assertMatch(actual, expected, message) {
if (isRegExp(expected))
assert(expected.test(actual), message || `Expected "${actual}" to match "${expected}"`);
else if (typeof expected === 'function')
assert(expected(actual), message);
else
assert.deepEqual(actual, expected, message);
} | javascript | function assertMatch(actual, expected, message) {
if (isRegExp(expected))
assert(expected.test(actual), message || `Expected "${actual}" to match "${expected}"`);
else if (typeof expected === 'function')
assert(expected(actual), message);
else
assert.deepEqual(actual, expected, message);
} | [
"function",
"assertMatch",
"(",
"actual",
",",
"expected",
",",
"message",
")",
"{",
"if",
"(",
"isRegExp",
"(",
"expected",
")",
")",
"assert",
"(",
"expected",
".",
"test",
"(",
"actual",
")",
",",
"message",
"||",
"`",
"${",
"actual",
"}",
"${",
"... | Used to assert that actual matches expected value, where expected may be a function or a string. | [
"Used",
"to",
"assert",
"that",
"actual",
"matches",
"expected",
"value",
"where",
"expected",
"may",
"be",
"a",
"function",
"or",
"a",
"string",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/assert.js#L10-L17 | train |
assaf/zombie | src/eventloop.js | ontick | function ontick(next) {
// No point in waiting that long
if (next >= timeoutOn) {
timeout();
return;
}
const activeWindow = eventLoop.active;
if (completionFunction && activeWindow.document.documentElement)
try {
const waitFor = Math.max(next - Date.now... | javascript | function ontick(next) {
// No point in waiting that long
if (next >= timeoutOn) {
timeout();
return;
}
const activeWindow = eventLoop.active;
if (completionFunction && activeWindow.document.documentElement)
try {
const waitFor = Math.max(next - Date.now... | [
"function",
"ontick",
"(",
"next",
")",
"{",
"// No point in waiting that long",
"if",
"(",
"next",
">=",
"timeoutOn",
")",
"{",
"timeout",
"(",
")",
";",
"return",
";",
"}",
"const",
"activeWindow",
"=",
"eventLoop",
".",
"active",
";",
"if",
"(",
"comple... | Fired after every event, decide if we want to stop waiting | [
"Fired",
"after",
"every",
"event",
"decide",
"if",
"we",
"want",
"to",
"stop",
"waiting"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/eventloop.js#L414-L433 | train |
assaf/zombie | src/eventloop.js | done | function done(error) {
global.clearTimeout(timer);
eventLoop.removeListener('tick', ontick);
eventLoop.removeListener('idle', done);
eventLoop.browser.removeListener('error', done);
--eventLoop.waiting;
try {
callback(error);
} catch (error) {
// If callback ma... | javascript | function done(error) {
global.clearTimeout(timer);
eventLoop.removeListener('tick', ontick);
eventLoop.removeListener('idle', done);
eventLoop.browser.removeListener('error', done);
--eventLoop.waiting;
try {
callback(error);
} catch (error) {
// If callback ma... | [
"function",
"done",
"(",
"error",
")",
"{",
"global",
".",
"clearTimeout",
"(",
"timer",
")",
";",
"eventLoop",
".",
"removeListener",
"(",
"'tick'",
",",
"ontick",
")",
";",
"eventLoop",
".",
"removeListener",
"(",
"'idle'",
",",
"done",
")",
";",
"even... | The wait is over ... | [
"The",
"wait",
"is",
"over",
"..."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/eventloop.js#L436-L452 | train |
assaf/zombie | Gulpfile.js | changes | function changes() {
const version = require('./package.json').version;
const changelog = File.readFileSync('CHANGELOG.md', 'utf-8');
const match = changelog.match(/^## Version (.*) .*\n([\S\s]+?)\n##/m);
assert(match, 'CHANGELOG.md missing entry: ## Version ' + version);
assert.equal(match[1], version... | javascript | function changes() {
const version = require('./package.json').version;
const changelog = File.readFileSync('CHANGELOG.md', 'utf-8');
const match = changelog.match(/^## Version (.*) .*\n([\S\s]+?)\n##/m);
assert(match, 'CHANGELOG.md missing entry: ## Version ' + version);
assert.equal(match[1], version... | [
"function",
"changes",
"(",
")",
"{",
"const",
"version",
"=",
"require",
"(",
"'./package.json'",
")",
".",
"version",
";",
"const",
"changelog",
"=",
"File",
".",
"readFileSync",
"(",
"'CHANGELOG.md'",
",",
"'utf-8'",
")",
";",
"const",
"match",
"=",
"ch... | Generate a change log summary for this release git tag uses the generated .changes file | [
"Generate",
"a",
"change",
"log",
"summary",
"for",
"this",
"release",
"git",
"tag",
"uses",
"the",
"generated",
".",
"changes",
"file"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/Gulpfile.js#L46-L57 | train |
assaf/zombie | src/fetch.js | decompressStream | function decompressStream(stream, headers) {
const transferEncoding = headers.get('Transfer-Encoding');
const contentEncoding = headers.get('Content-Encoding');
if (contentEncoding === 'deflate' || transferEncoding === 'deflate')
return stream.pipe( Zlib.createInflate() );
if (contentEncoding === 'gzip' ... | javascript | function decompressStream(stream, headers) {
const transferEncoding = headers.get('Transfer-Encoding');
const contentEncoding = headers.get('Content-Encoding');
if (contentEncoding === 'deflate' || transferEncoding === 'deflate')
return stream.pipe( Zlib.createInflate() );
if (contentEncoding === 'gzip' ... | [
"function",
"decompressStream",
"(",
"stream",
",",
"headers",
")",
"{",
"const",
"transferEncoding",
"=",
"headers",
".",
"get",
"(",
"'Transfer-Encoding'",
")",
";",
"const",
"contentEncoding",
"=",
"headers",
".",
"get",
"(",
"'Content-Encoding'",
")",
";",
... | Decompress stream based on content and transfer encoding headers. | [
"Decompress",
"stream",
"based",
"on",
"content",
"and",
"transfer",
"encoding",
"headers",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/fetch.js#L9-L17 | train |
assaf/zombie | src/dom/forms.js | click | function click() {
const clickEvent = input.ownerDocument.createEvent('HTMLEvents');
clickEvent.initEvent('click', true, true);
const labelElementImpl = domSymbolTree.parent(idlUtils.implForWrapper(input));
const dispatchResult = input.dispatchEvent(clickEvent);
input._click && input._click(clickEve... | javascript | function click() {
const clickEvent = input.ownerDocument.createEvent('HTMLEvents');
clickEvent.initEvent('click', true, true);
const labelElementImpl = domSymbolTree.parent(idlUtils.implForWrapper(input));
const dispatchResult = input.dispatchEvent(clickEvent);
input._click && input._click(clickEve... | [
"function",
"click",
"(",
")",
"{",
"const",
"clickEvent",
"=",
"input",
".",
"ownerDocument",
".",
"createEvent",
"(",
"'HTMLEvents'",
")",
";",
"clickEvent",
".",
"initEvent",
"(",
"'click'",
",",
"true",
",",
"true",
")",
";",
"const",
"labelElementImpl",... | First event we fire is click event | [
"First",
"event",
"we",
"fire",
"is",
"click",
"event"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/dom/forms.js#L182-L189 | train |
assaf/zombie | src/document.js | windowLoaded | function windowLoaded(event) {
document.removeEventListener('DOMContentLoaded', windowLoaded);
// JSDom > 7.1 does not allow re-dispatching the same event, so
// a copy of the event needs to be created for the new dispatch
const windowContentLoaded = document.createEvent('HTMLEvents');
windowConten... | javascript | function windowLoaded(event) {
document.removeEventListener('DOMContentLoaded', windowLoaded);
// JSDom > 7.1 does not allow re-dispatching the same event, so
// a copy of the event needs to be created for the new dispatch
const windowContentLoaded = document.createEvent('HTMLEvents');
windowConten... | [
"function",
"windowLoaded",
"(",
"event",
")",
"{",
"document",
".",
"removeEventListener",
"(",
"'DOMContentLoaded'",
",",
"windowLoaded",
")",
";",
"// JSDom > 7.1 does not allow re-dispatching the same event, so",
"// a copy of the event needs to be created for the new dispatch",
... | JSDOM fires DCL event on document but not on window | [
"JSDOM",
"fires",
"DCL",
"event",
"on",
"document",
"but",
"not",
"on",
"window"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L468-L476 | train |
assaf/zombie | src/document.js | createDocument | function createDocument(args) {
const { browser } = args;
const features = {
FetchExternalResources: [],
ProcessExternalResources: [],
MutationEvents: '2.0'
};
const window = new Window({
parsingMode: 'html',
contentType: 'text/html',
url: args.url,
referrer... | javascript | function createDocument(args) {
const { browser } = args;
const features = {
FetchExternalResources: [],
ProcessExternalResources: [],
MutationEvents: '2.0'
};
const window = new Window({
parsingMode: 'html',
contentType: 'text/html',
url: args.url,
referrer... | [
"function",
"createDocument",
"(",
"args",
")",
"{",
"const",
"{",
"browser",
"}",
"=",
"args",
";",
"const",
"features",
"=",
"{",
"FetchExternalResources",
":",
"[",
"]",
",",
"ProcessExternalResources",
":",
"[",
"]",
",",
"MutationEvents",
":",
"'2.0'",
... | Creates an returns a new document attached to the window. | [
"Creates",
"an",
"returns",
"a",
"new",
"document",
"attached",
"to",
"the",
"window",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L491-L531 | train |
assaf/zombie | src/document.js | parseResponse | function parseResponse({ browser, history, document, response }) {
const window = document.defaultView;
window._request = response.request;
window._response = response;
history.updateLocation(window, response._url);
const done = window._eventQueue.waitForCompletion();
response
._consume()
.... | javascript | function parseResponse({ browser, history, document, response }) {
const window = document.defaultView;
window._request = response.request;
window._response = response;
history.updateLocation(window, response._url);
const done = window._eventQueue.waitForCompletion();
response
._consume()
.... | [
"function",
"parseResponse",
"(",
"{",
"browser",
",",
"history",
",",
"document",
",",
"response",
"}",
")",
"{",
"const",
"window",
"=",
"document",
".",
"defaultView",
";",
"window",
".",
"_request",
"=",
"response",
".",
"request",
";",
"window",
".",
... | Parse HTML response and setup document | [
"Parse",
"HTML",
"response",
"and",
"setup",
"document"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L630-L692 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | expandQNames | function expandQNames(xpath) {
var namespaces = constants.XmlNamespaces;
var pathParts = xpath.split('/');
for (var i=0; i < pathParts.length; i++) {
if (pathParts[i].indexOf(':') !== -1) {
var QNameParts = pathParts[i].split(':');
if (QNameParts.length !== 2) {
throw new Error('Unable to ... | javascript | function expandQNames(xpath) {
var namespaces = constants.XmlNamespaces;
var pathParts = xpath.split('/');
for (var i=0; i < pathParts.length; i++) {
if (pathParts[i].indexOf(':') !== -1) {
var QNameParts = pathParts[i].split(':');
if (QNameParts.length !== 2) {
throw new Error('Unable to ... | [
"function",
"expandQNames",
"(",
"xpath",
")",
"{",
"var",
"namespaces",
"=",
"constants",
".",
"XmlNamespaces",
";",
"var",
"pathParts",
"=",
"xpath",
".",
"split",
"(",
"'/'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pathParts",
... | The xpath implementation being used does not have a way of matching expanded namespace.
This method takes an xpath query and expands all of the namespaces involved. It then
re-writes the query in to a longer form that directory matches the correct namespaces.
@private
@static
@memberOf XmlUtil
@param {string} xpath ... | [
"The",
"xpath",
"implementation",
"being",
"used",
"does",
"not",
"have",
"a",
"way",
"of",
"matching",
"expanded",
"namespace",
".",
"This",
"method",
"takes",
"an",
"xpath",
"query",
"and",
"expands",
"all",
"of",
"the",
"namespaces",
"involved",
".",
"It"... | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L45-L60 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | function(node) {
var doc = '';
var sibling = node.firstChild;
var serializer = new XMLSerializer();
while (sibling) {
if (this.isElementNode(sibling)) {
doc += serializer.serializeToString(sibling);
}
sibling = sibling.nextSibling;
}
return doc !== '' ? doc : null;
... | javascript | function(node) {
var doc = '';
var sibling = node.firstChild;
var serializer = new XMLSerializer();
while (sibling) {
if (this.isElementNode(sibling)) {
doc += serializer.serializeToString(sibling);
}
sibling = sibling.nextSibling;
}
return doc !== '' ? doc : null;
... | [
"function",
"(",
"node",
")",
"{",
"var",
"doc",
"=",
"''",
";",
"var",
"sibling",
"=",
"node",
".",
"firstChild",
";",
"var",
"serializer",
"=",
"new",
"XMLSerializer",
"(",
")",
";",
"while",
"(",
"sibling",
")",
"{",
"if",
"(",
"this",
".",
"isE... | Given a dom node serializes all immediate children that are xml elements.
@static
@memberOf XmlUtil
@param {object} node An xml dom node.
@return {string} Serialized xml. | [
"Given",
"a",
"dom",
"node",
"serializes",
"all",
"immediate",
"children",
"that",
"are",
"xml",
"elements",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L84-L97 | train | |
AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | function(node) {
var sibling = node.firstChild;
while (sibling && !sibling.data) {
sibling = sibling.nextSibling;
}
return sibling.data ? sibling.data : null;
} | javascript | function(node) {
var sibling = node.firstChild;
while (sibling && !sibling.data) {
sibling = sibling.nextSibling;
}
return sibling.data ? sibling.data : null;
} | [
"function",
"(",
"node",
")",
"{",
"var",
"sibling",
"=",
"node",
".",
"firstChild",
";",
"while",
"(",
"sibling",
"&&",
"!",
"sibling",
".",
"data",
")",
"{",
"sibling",
"=",
"sibling",
".",
"nextSibling",
";",
"}",
"return",
"sibling",
".",
"data",
... | Given an xmldom node this function returns any text data contained within.
@static
@memberOf XmlUtil
@param {object} node An xmldom node from which the data should be extracted.
@return {string} Any data found within the element or null if none is found. | [
"Given",
"an",
"xmldom",
"node",
"this",
"function",
"returns",
"any",
"text",
"data",
"contained",
"within",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L117-L124 | train | |
AzureAD/azure-activedirectory-library-for-nodejs | lib/authority.js | Authority | function Authority(authorityUrl, validateAuthority) {
this._log = null;
this._url = url.parse(authorityUrl);
this._validateAuthorityUrl();
this._validated = !validateAuthority;
this._host = null;
this._tenant = null;
this._parseAuthority();
this._authorizationEndpoint = null;
this._tokenEndpoint = n... | javascript | function Authority(authorityUrl, validateAuthority) {
this._log = null;
this._url = url.parse(authorityUrl);
this._validateAuthorityUrl();
this._validated = !validateAuthority;
this._host = null;
this._tenant = null;
this._parseAuthority();
this._authorizationEndpoint = null;
this._tokenEndpoint = n... | [
"function",
"Authority",
"(",
"authorityUrl",
",",
"validateAuthority",
")",
"{",
"this",
".",
"_log",
"=",
"null",
";",
"this",
".",
"_url",
"=",
"url",
".",
"parse",
"(",
"authorityUrl",
")",
";",
"this",
".",
"_validateAuthorityUrl",
"(",
")",
";",
"t... | Constructs an Authority object with a specific authority URL.
@private
@constructor
@param {string} authorityUrl A URL that identifies a token authority.
@param {bool} validateAuthority Indicates whether the Authority url should be validated as an actual AAD
authority. The default is true. | [
"Constructs",
"an",
"Authority",
"object",
"with",
"a",
"specific",
"authority",
"URL",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/authority.js#L39-L53 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/log.js | function(options) {
if (!options) {
options = {};
}
if (options.log) {
if (!_.isFunction(options.log)) {
throw new Error('setLogOptions expects the log key in the options parameter to be a function');
}
} else {
// if no log function was passed set it to a default no op ... | javascript | function(options) {
if (!options) {
options = {};
}
if (options.log) {
if (!_.isFunction(options.log)) {
throw new Error('setLogOptions expects the log key in the options parameter to be a function');
}
} else {
// if no log function was passed set it to a default no op ... | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"options",
".",
"log",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"options",
".",
"log",
")",
")",
"{",
"thr... | Sets global logging options for ADAL.
@param {LoggingOptions} options | [
"Sets",
"global",
"logging",
"options",
"for",
"ADAL",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/log.js#L72-L100 | train | |
AzureAD/azure-activedirectory-library-for-nodejs | lib/self-signed-jwt.js | SelfSignedJwt | function SelfSignedJwt(callContext, authority, clientId) {
this._log = new Logger('SelfSignedJwt', callContext._logContext);
this._callContext = callContext;
this._authority = authority;
this._tokenEndpoint = authority.tokenEndpoint;
this._clientId = clientId;
} | javascript | function SelfSignedJwt(callContext, authority, clientId) {
this._log = new Logger('SelfSignedJwt', callContext._logContext);
this._callContext = callContext;
this._authority = authority;
this._tokenEndpoint = authority.tokenEndpoint;
this._clientId = clientId;
} | [
"function",
"SelfSignedJwt",
"(",
"callContext",
",",
"authority",
",",
"clientId",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'SelfSignedJwt'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
... | Constructs a new SelfSignedJwt object.
@param {object} callContext Context specific to this token request.
@param {Authority} authority The authority to be used as the JWT audience.
@param {string} clientId The client id of the calling app. | [
"Constructs",
"a",
"new",
"SelfSignedJwt",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/self-signed-jwt.js#L47-L54 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/cache-driver.js | CacheDriver | function CacheDriver(callContext, authority, resource, clientId, cache, refreshFunction) {
this._callContext = callContext;
this._log = new Logger('CacheDriver', callContext._logContext);
this._authority = authority;
this._resource = resource;
this._clientId = clientId;
this._cache = cache || nopCache;
th... | javascript | function CacheDriver(callContext, authority, resource, clientId, cache, refreshFunction) {
this._callContext = callContext;
this._log = new Logger('CacheDriver', callContext._logContext);
this._authority = authority;
this._resource = resource;
this._clientId = clientId;
this._cache = cache || nopCache;
th... | [
"function",
"CacheDriver",
"(",
"callContext",
",",
"authority",
",",
"resource",
",",
"clientId",
",",
"cache",
",",
"refreshFunction",
")",
"{",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'CacheDr... | This is the callback that is passed to all acquireToken variants below.
@callback RefreshEntryFunction
@memberOf CacheDriver
@param {object} tokenResponse A token response to refresh.
@param {string} [resource] The resource for which to obtain the token if it is different from the original token.
@param {Acq... | [
"This",
"is",
"the",
"callback",
"that",
"is",
"passed",
"to",
"all",
"acquireToken",
"variants",
"below",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/cache-driver.js#L116-L124 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/oauth2client.js | OAuth2Client | function OAuth2Client(callContext, authority) {
this._tokenEndpoint = authority.tokenEndpoint;
this._deviceCodeEndpoint = authority.deviceCodeEndpoint;
this._log = new Logger('OAuth2Client', callContext._logContext);
this._callContext = callContext;
this._cancelPollingRequest = false;
} | javascript | function OAuth2Client(callContext, authority) {
this._tokenEndpoint = authority.tokenEndpoint;
this._deviceCodeEndpoint = authority.deviceCodeEndpoint;
this._log = new Logger('OAuth2Client', callContext._logContext);
this._callContext = callContext;
this._cancelPollingRequest = false;
} | [
"function",
"OAuth2Client",
"(",
"callContext",
",",
"authority",
")",
"{",
"this",
".",
"_tokenEndpoint",
"=",
"authority",
".",
"tokenEndpoint",
";",
"this",
".",
"_deviceCodeEndpoint",
"=",
"authority",
".",
"deviceCodeEndpoint",
";",
"this",
".",
"_log",
"="... | Constructs an instances of OAuth2Client
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {string|url} authority An url that points to an authority. | [
"Constructs",
"an",
"instances",
"of",
"OAuth2Client"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/oauth2client.js#L72-L79 | train |
AzureAD/azure-activedirectory-library-for-nodejs | lib/oauth2client.js | function (response, body) {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(body);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
... | javascript | function (response, body) {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(body);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
... | [
"function",
"(",
"response",
",",
"body",
")",
"{",
"var",
"tokenResponse",
";",
"try",
"{",
"tokenResponse",
"=",
"self",
".",
"_handlePollingResponse",
"(",
"body",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"self",
".",
"_log",
".",
"error",
"(",
... | success response callback | [
"success",
"response",
"callback"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/oauth2client.js#L420-L431 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.