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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
bradzacher/eslint-plugin-typescript | lib/rules/no-inferrable-types.js | reportInferrableType | function reportInferrableType(node, typeNode, initNode) {
if (!typeNode || !initNode || !typeNode.typeAnnotation) {
return;
}
if (!isInferrable(typeNode, initNode)) {
return;
}
const typeMap = {
TSBooleanKeywor... | javascript | function reportInferrableType(node, typeNode, initNode) {
if (!typeNode || !initNode || !typeNode.typeAnnotation) {
return;
}
if (!isInferrable(typeNode, initNode)) {
return;
}
const typeMap = {
TSBooleanKeywor... | [
"function",
"reportInferrableType",
"(",
"node",
",",
"typeNode",
",",
"initNode",
")",
"{",
"if",
"(",
"!",
"typeNode",
"||",
"!",
"initNode",
"||",
"!",
"typeNode",
".",
"typeAnnotation",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isInferrable",
"(... | Reports an inferrable type declaration, if any
@param {ASTNode} node the node being visited
@param {ASTNode} typeNode the type annotation node
@param {ASTNode} initNode the initializer node
@returns {void} | [
"Reports",
"an",
"inferrable",
"type",
"declaration",
"if",
"any"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/no-inferrable-types.js#L111-L137 | train |
bradzacher/eslint-plugin-typescript | lib/rules/member-delimiter-style.js | checkMemberSeparatorStyle | function checkMemberSeparatorStyle(node) {
const isInterface = node.type === "TSInterfaceBody";
const isSingleLine = node.loc.start.line === node.loc.end.line;
const members = isInterface ? node.body : node.members;
const typeOpts = isInterface
? interfa... | javascript | function checkMemberSeparatorStyle(node) {
const isInterface = node.type === "TSInterfaceBody";
const isSingleLine = node.loc.start.line === node.loc.end.line;
const members = isInterface ? node.body : node.members;
const typeOpts = isInterface
? interfa... | [
"function",
"checkMemberSeparatorStyle",
"(",
"node",
")",
"{",
"const",
"isInterface",
"=",
"node",
".",
"type",
"===",
"\"TSInterfaceBody\"",
";",
"const",
"isSingleLine",
"=",
"node",
".",
"loc",
".",
"start",
".",
"line",
"===",
"node",
".",
"loc",
".",
... | Check the member separator being used matches the delimiter.
@param {ASTNode} node the node to be evaluated.
@returns {void}
@private | [
"Check",
"the",
"member",
"separator",
"being",
"used",
"matches",
"the",
"delimiter",
"."
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/member-delimiter-style.js#L200-L216 | train |
bradzacher/eslint-plugin-typescript | lib/util.js | deepMerge | function deepMerge(first = {}, second = {}) {
// get the unique set of keys across both objects
const keys = new Set(Object.keys(first).concat(Object.keys(second)));
return Array.from(keys).reduce((acc, key) => {
const firstHasKey = key in first;
const secondHasKey = key in second;
... | javascript | function deepMerge(first = {}, second = {}) {
// get the unique set of keys across both objects
const keys = new Set(Object.keys(first).concat(Object.keys(second)));
return Array.from(keys).reduce((acc, key) => {
const firstHasKey = key in first;
const secondHasKey = key in second;
... | [
"function",
"deepMerge",
"(",
"first",
"=",
"{",
"}",
",",
"second",
"=",
"{",
"}",
")",
"{",
"// get the unique set of keys across both objects",
"const",
"keys",
"=",
"new",
"Set",
"(",
"Object",
".",
"keys",
"(",
"first",
")",
".",
"concat",
"(",
"Objec... | Pure function - doesn't mutate either parameter!
Merges two objects together deeply, overwriting the properties in first with the properties in second
@template TFirst,TSecond
@param {TFirst} first The first object
@param {TSecond} second The second object
@returns {Record<string, any>} a new object | [
"Pure",
"function",
"-",
"doesn",
"t",
"mutate",
"either",
"parameter!",
"Merges",
"two",
"objects",
"together",
"deeply",
"overwriting",
"the",
"properties",
"in",
"first",
"with",
"the",
"properties",
"in",
"second"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/util.js#L43-L67 | train |
bradzacher/eslint-plugin-typescript | tools/update-recommended.js | generate | function generate() {
// replace this with Object.entries when node > 8
const allRules = requireIndex(path.resolve(__dirname, "../lib/rules"));
const rules = Object.keys(allRules)
.filter(key => !!allRules[key].meta.docs.recommended)
.reduce((config, key) => {
// having this her... | javascript | function generate() {
// replace this with Object.entries when node > 8
const allRules = requireIndex(path.resolve(__dirname, "../lib/rules"));
const rules = Object.keys(allRules)
.filter(key => !!allRules[key].meta.docs.recommended)
.reduce((config, key) => {
// having this her... | [
"function",
"generate",
"(",
")",
"{",
"// replace this with Object.entries when node > 8",
"const",
"allRules",
"=",
"requireIndex",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"\"../lib/rules\"",
")",
")",
";",
"const",
"rules",
"=",
"Object",
".",
"keys... | Generate recommended configuration
@returns {void} | [
"Generate",
"recommended",
"configuration"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/tools/update-recommended.js#L20-L64 | train |
bradzacher/eslint-plugin-typescript | lib/rules/adjacent-overload-signatures.js | checkBodyForOverloadMethods | function checkBodyForOverloadMethods(node) {
const members = node.body || node.members;
if (members) {
let name;
let index;
let lastName;
const seen = [];
members.forEach(member => {
name = getM... | javascript | function checkBodyForOverloadMethods(node) {
const members = node.body || node.members;
if (members) {
let name;
let index;
let lastName;
const seen = [];
members.forEach(member => {
name = getM... | [
"function",
"checkBodyForOverloadMethods",
"(",
"node",
")",
"{",
"const",
"members",
"=",
"node",
".",
"body",
"||",
"node",
".",
"members",
";",
"if",
"(",
"members",
")",
"{",
"let",
"name",
";",
"let",
"index",
";",
"let",
"lastName",
";",
"const",
... | Check the body for overload methods.
@param {ASTNode} node the body to be inspected.
@returns {void}
@private | [
"Check",
"the",
"body",
"for",
"overload",
"methods",
"."
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/adjacent-overload-signatures.js#L86-L114 | train |
bradzacher/eslint-plugin-typescript | lib/rules/no-unused-vars.js | markThisParameterAsUsed | function markThisParameterAsUsed(node) {
if (node.name) {
const variable = context
.getScope()
.variables.find(scopeVar => scopeVar.name === node.name);
if (variable) {
variable.eslintUsed = true;
}
... | javascript | function markThisParameterAsUsed(node) {
if (node.name) {
const variable = context
.getScope()
.variables.find(scopeVar => scopeVar.name === node.name);
if (variable) {
variable.eslintUsed = true;
}
... | [
"function",
"markThisParameterAsUsed",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"name",
")",
"{",
"const",
"variable",
"=",
"context",
".",
"getScope",
"(",
")",
".",
"variables",
".",
"find",
"(",
"scopeVar",
"=>",
"scopeVar",
".",
"name",
"===",
... | Mark this function parameter as used
@param {Identifier} node The node currently being traversed
@returns {void} | [
"Mark",
"this",
"function",
"parameter",
"as",
"used"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/no-unused-vars.js#L35-L45 | train |
bradzacher/eslint-plugin-typescript | lib/rules/indent.js | TSPropertySignatureToProperty | function TSPropertySignatureToProperty(node, type = "Property") {
return {
type,
key: node.key,
value: node.value || node.typeAnnotation,
// Property flags
computed: false,
method: false,
kind: "... | javascript | function TSPropertySignatureToProperty(node, type = "Property") {
return {
type,
key: node.key,
value: node.value || node.typeAnnotation,
// Property flags
computed: false,
method: false,
kind: "... | [
"function",
"TSPropertySignatureToProperty",
"(",
"node",
",",
"type",
"=",
"\"Property\"",
")",
"{",
"return",
"{",
"type",
",",
"key",
":",
"node",
".",
"key",
",",
"value",
":",
"node",
".",
"value",
"||",
"node",
".",
"typeAnnotation",
",",
"// Propert... | Converts from a TSPropertySignature to a Property
@param {Object} node a TSPropertySignature node
@param {string} [type] the type to give the new node
@returns {Object} a Property node | [
"Converts",
"from",
"a",
"TSPropertySignature",
"to",
"a",
"Property"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/indent.js#L126-L144 | train |
bradzacher/eslint-plugin-typescript | lib/rules/explicit-member-accessibility.js | checkPropertyAccessibilityModifier | function checkPropertyAccessibilityModifier(classProperty) {
if (
!classProperty.accessibility &&
util.isTypescript(context.getFilename())
) {
context.report({
node: classProperty,
message:
... | javascript | function checkPropertyAccessibilityModifier(classProperty) {
if (
!classProperty.accessibility &&
util.isTypescript(context.getFilename())
) {
context.report({
node: classProperty,
message:
... | [
"function",
"checkPropertyAccessibilityModifier",
"(",
"classProperty",
")",
"{",
"if",
"(",
"!",
"classProperty",
".",
"accessibility",
"&&",
"util",
".",
"isTypescript",
"(",
"context",
".",
"getFilename",
"(",
")",
")",
")",
"{",
"context",
".",
"report",
"... | Checks if property has an accessibility modifier.
@param {ASTNode} classProperty The node representing a ClassProperty.
@returns {void}
@private | [
"Checks",
"if",
"property",
"has",
"an",
"accessibility",
"modifier",
"."
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/explicit-member-accessibility.js#L60-L74 | train |
bradzacher/eslint-plugin-typescript | lib/rules/array-type.js | isSimpleType | function isSimpleType(node) {
switch (node.type) {
case "Identifier":
case "TSAnyKeyword":
case "TSBooleanKeyword":
case "TSNeverKeyword":
case "TSNumberKeyword":
case "TSObjectKeyword":
case "TSStringKeyword":
case "TSSymbolKeyword":
case "TSU... | javascript | function isSimpleType(node) {
switch (node.type) {
case "Identifier":
case "TSAnyKeyword":
case "TSBooleanKeyword":
case "TSNeverKeyword":
case "TSNumberKeyword":
case "TSObjectKeyword":
case "TSStringKeyword":
case "TSSymbolKeyword":
case "TSU... | [
"function",
"isSimpleType",
"(",
"node",
")",
"{",
"switch",
"(",
"node",
".",
"type",
")",
"{",
"case",
"\"Identifier\"",
":",
"case",
"\"TSAnyKeyword\"",
":",
"case",
"\"TSBooleanKeyword\"",
":",
"case",
"\"TSNeverKeyword\"",
":",
"case",
"\"TSNumberKeyword\"",
... | Check whatever node can be considered as simple
@param {ASTNode} node the node to be evaluated.
@returns {*} true or false | [
"Check",
"whatever",
"node",
"can",
"be",
"considered",
"as",
"simple"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/array-type.js#L15-L55 | train |
bradzacher/eslint-plugin-typescript | lib/rules/array-type.js | typeNeedsParentheses | function typeNeedsParentheses(node) {
if (node.type === "TSTypeReference") {
switch (node.typeName.type) {
case "TSUnionType":
case "TSFunctionType":
case "TSIntersectionType":
case "TSTypeOperator":
return true;
default:
... | javascript | function typeNeedsParentheses(node) {
if (node.type === "TSTypeReference") {
switch (node.typeName.type) {
case "TSUnionType":
case "TSFunctionType":
case "TSIntersectionType":
case "TSTypeOperator":
return true;
default:
... | [
"function",
"typeNeedsParentheses",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"\"TSTypeReference\"",
")",
"{",
"switch",
"(",
"node",
".",
"typeName",
".",
"type",
")",
"{",
"case",
"\"TSUnionType\"",
":",
"case",
"\"TSFunctionType\"",
":... | Check if node needs parentheses
@param {ASTNode} node the node to be evaluated.
@returns {*} true or false | [
"Check",
"if",
"node",
"needs",
"parentheses"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/array-type.js#L62-L75 | train |
bradzacher/eslint-plugin-typescript | lib/rules/array-type.js | requireWhitespaceBefore | function requireWhitespaceBefore(node) {
const prevToken = sourceCode.getTokenBefore(node);
if (node.range[0] - prevToken.range[1] > 0) {
return false;
}
return prevToken.type === "Identifier";
} | javascript | function requireWhitespaceBefore(node) {
const prevToken = sourceCode.getTokenBefore(node);
if (node.range[0] - prevToken.range[1] > 0) {
return false;
}
return prevToken.type === "Identifier";
} | [
"function",
"requireWhitespaceBefore",
"(",
"node",
")",
"{",
"const",
"prevToken",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"node",
")",
";",
"if",
"(",
"node",
".",
"range",
"[",
"0",
"]",
"-",
"prevToken",
".",
"range",
"[",
"1",
"]",
">",
"0"... | Check if whitespace is needed before this node
@param {ASTNode} node the node to be evaluated.
@returns {boolean} true of false | [
"Check",
"if",
"whitespace",
"is",
"needed",
"before",
"this",
"node"
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/array-type.js#L119-L127 | train |
bradzacher/eslint-plugin-typescript | lib/rules/no-use-before-define.js | parseOptions | function parseOptions(options) {
let functions = true;
let classes = true;
let variables = true;
let typedefs = true;
if (typeof options === "string") {
functions = options !== "nofunc";
} else if (typeof options === "object" && options !== null) {
functions = options.functions ... | javascript | function parseOptions(options) {
let functions = true;
let classes = true;
let variables = true;
let typedefs = true;
if (typeof options === "string") {
functions = options !== "nofunc";
} else if (typeof options === "object" && options !== null) {
functions = options.functions ... | [
"function",
"parseOptions",
"(",
"options",
")",
"{",
"let",
"functions",
"=",
"true",
";",
"let",
"classes",
"=",
"true",
";",
"let",
"variables",
"=",
"true",
";",
"let",
"typedefs",
"=",
"true",
";",
"if",
"(",
"typeof",
"options",
"===",
"\"string\""... | Parses a given value as options.
@param {any} options - A value to parse.
@returns {Object} The parsed options. | [
"Parses",
"a",
"given",
"value",
"as",
"options",
"."
] | f689a73c171f33501aa11cd9f77bec2fc10128ae | https://github.com/bradzacher/eslint-plugin-typescript/blob/f689a73c171f33501aa11cd9f77bec2fc10128ae/lib/rules/no-use-before-define.js#L26-L42 | train |
wy-ei/vue-filter | src/string/split.js | split | function split(str, separator) {
separator = separator || '';
if (_.isString(str)) {
return str.split(separator);
} else {
return str;
}
} | javascript | function split(str, separator) {
separator = separator || '';
if (_.isString(str)) {
return str.split(separator);
} else {
return str;
}
} | [
"function",
"split",
"(",
"str",
",",
"separator",
")",
"{",
"separator",
"=",
"separator",
"||",
"''",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"str",
")",
")",
"{",
"return",
"str",
".",
"split",
"(",
"separator",
")",
";",
"}",
"else",
"{",
... | The split filter takes on a substring as a parameter.
The substring is used as a delimiter to divide a string into an array.
{{ 'a-b-c-d' | split '-' }} => [a,b,c,d] | [
"The",
"split",
"filter",
"takes",
"on",
"a",
"substring",
"as",
"a",
"parameter",
".",
"The",
"substring",
"is",
"used",
"as",
"a",
"delimiter",
"to",
"divide",
"a",
"string",
"into",
"an",
"array",
"."
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/string/split.js#L9-L16 | train |
wy-ei/vue-filter | src/string/xpad.js | padding | function padding(size,ch){
var str = '';
if(!ch && ch !== 0){
ch = ' ';
}
while(size !== 0){
if(size & 1 === 1){
str += ch;
}
ch += ch;
size >>>= 1;
}
return str;
} | javascript | function padding(size,ch){
var str = '';
if(!ch && ch !== 0){
ch = ' ';
}
while(size !== 0){
if(size & 1 === 1){
str += ch;
}
ch += ch;
size >>>= 1;
}
return str;
} | [
"function",
"padding",
"(",
"size",
",",
"ch",
")",
"{",
"var",
"str",
"=",
"''",
";",
"if",
"(",
"!",
"ch",
"&&",
"ch",
"!==",
"0",
")",
"{",
"ch",
"=",
"' '",
";",
"}",
"while",
"(",
"size",
"!==",
"0",
")",
"{",
"if",
"(",
"size",
"&",
... | return a string by repeat a char n times | [
"return",
"a",
"string",
"by",
"repeat",
"a",
"char",
"n",
"times"
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/string/xpad.js#L6-L19 | train |
wy-ei/vue-filter | src/other/debounce.js | debounce | function debounce(handler, delay) {
if (!handler){
return;
}
if (!delay) {
delay = 300;
}
return _.debounce(handler, delay);
} | javascript | function debounce(handler, delay) {
if (!handler){
return;
}
if (!delay) {
delay = 300;
}
return _.debounce(handler, delay);
} | [
"function",
"debounce",
"(",
"handler",
",",
"delay",
")",
"{",
"if",
"(",
"!",
"handler",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"delay",
")",
"{",
"delay",
"=",
"300",
";",
"}",
"return",
"_",
".",
"debounce",
"(",
"handler",
",",
"delay... | debounce a function, the default dalay is 300ms
{{ func | debounce(300) }} | [
"debounce",
"a",
"function",
"the",
"default",
"dalay",
"is",
"300ms"
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/other/debounce.js#L9-L17 | train |
wy-ei/vue-filter | src/string/append.js | append | function append(str, postfix) {
if (!str && str !== 0) {
str = '';
} else {
str = str.toString();
}
return str + postfix;
} | javascript | function append(str, postfix) {
if (!str && str !== 0) {
str = '';
} else {
str = str.toString();
}
return str + postfix;
} | [
"function",
"append",
"(",
"str",
",",
"postfix",
")",
"{",
"if",
"(",
"!",
"str",
"&&",
"str",
"!==",
"0",
")",
"{",
"str",
"=",
"''",
";",
"}",
"else",
"{",
"str",
"=",
"str",
".",
"toString",
"(",
")",
";",
"}",
"return",
"str",
"+",
"post... | Appends characters to a string.
{{ 'sky' | append '.jpg' }} => 'sky.jpg' | [
"Appends",
"characters",
"to",
"a",
"string",
"."
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/string/append.js#L7-L14 | train |
wy-ei/vue-filter | src/string/prepend.js | prepend | function prepend(str, prefix) {
if (!str && str !== 0) {
str = '';
} else {
str = str.toString();
}
return prefix + str;
} | javascript | function prepend(str, prefix) {
if (!str && str !== 0) {
str = '';
} else {
str = str.toString();
}
return prefix + str;
} | [
"function",
"prepend",
"(",
"str",
",",
"prefix",
")",
"{",
"if",
"(",
"!",
"str",
"&&",
"str",
"!==",
"0",
")",
"{",
"str",
"=",
"''",
";",
"}",
"else",
"{",
"str",
"=",
"str",
".",
"toString",
"(",
")",
";",
"}",
"return",
"prefix",
"+",
"s... | Prepends characters to a string.
{{ 'world' | prepend 'hello ' }} => 'hello world' | [
"Prepends",
"characters",
"to",
"a",
"string",
"."
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/string/prepend.js#L7-L14 | train |
wy-ei/vue-filter | src/collection/reverse.js | reverse | function reverse(collection) {
if (typeof collection === 'string') {
return collection.split('').reverse().join('');
}
if(_.isArray(collection)){
return collection.concat().reverse();
}
return collection;
} | javascript | function reverse(collection) {
if (typeof collection === 'string') {
return collection.split('').reverse().join('');
}
if(_.isArray(collection)){
return collection.concat().reverse();
}
return collection;
} | [
"function",
"reverse",
"(",
"collection",
")",
"{",
"if",
"(",
"typeof",
"collection",
"===",
"'string'",
")",
"{",
"return",
"collection",
".",
"split",
"(",
"''",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"''",
")",
";",
"}",
"if",
"(",
"_... | reverse an array or a string
{{ 'abc' | reverse }} => 'cba'
{{ [1,2,3] | reverse }} => [3,2,1] | [
"reverse",
"an",
"array",
"or",
"a",
"string"
] | 13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a | https://github.com/wy-ei/vue-filter/blob/13a40a8d47c489e73ffc0ed739ab10fb27ad1a9a/src/collection/reverse.js#L11-L19 | train |
alexk111/SVG-Morpheus | source/js/deps/helpers.js | transCalc | function transCalc(transFrom, transTo, progress) {
var res={};
for(var i in transFrom) {
switch(i) {
case 'rotate':
res[i]=[0,0,0];
for(var j=0;j<3;j++) {
res[i][j]=transFrom[i][j]+(transTo[i][j]-transFrom[i][j])*progress;
}
break;
}
}
return res;
} | javascript | function transCalc(transFrom, transTo, progress) {
var res={};
for(var i in transFrom) {
switch(i) {
case 'rotate':
res[i]=[0,0,0];
for(var j=0;j<3;j++) {
res[i][j]=transFrom[i][j]+(transTo[i][j]-transFrom[i][j])*progress;
}
break;
}
}
return res;
} | [
"function",
"transCalc",
"(",
"transFrom",
",",
"transTo",
",",
"progress",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"transFrom",
")",
"{",
"switch",
"(",
"i",
")",
"{",
"case",
"'rotate'",
":",
"res",
"[",
"i",
"... | Calculate transform progress | [
"Calculate",
"transform",
"progress"
] | b0619353a6d80f3a8cf8dfff94f6ae1bbc344b77 | https://github.com/alexk111/SVG-Morpheus/blob/b0619353a6d80f3a8cf8dfff94f6ae1bbc344b77/source/js/deps/helpers.js#L104-L117 | train |
alexk111/SVG-Morpheus | source/js/deps/helpers.js | curveCalc | function curveCalc(curveFrom, curveTo, progress) {
var curve=[];
for(var i=0,len1=curveFrom.length;i<len1;i++) {
curve.push([curveFrom[i][0]]);
for(var j=1,len2=curveFrom[i].length;j<len2;j++) {
curve[i].push(curveFrom[i][j]+(curveTo[i][j]-curveFrom[i][j])*progress);
}
}
return curve;
} | javascript | function curveCalc(curveFrom, curveTo, progress) {
var curve=[];
for(var i=0,len1=curveFrom.length;i<len1;i++) {
curve.push([curveFrom[i][0]]);
for(var j=1,len2=curveFrom[i].length;j<len2;j++) {
curve[i].push(curveFrom[i][j]+(curveTo[i][j]-curveFrom[i][j])*progress);
}
}
return curve;
} | [
"function",
"curveCalc",
"(",
"curveFrom",
",",
"curveTo",
",",
"progress",
")",
"{",
"var",
"curve",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len1",
"=",
"curveFrom",
".",
"length",
";",
"i",
"<",
"len1",
";",
"i",
"++",
")",
... | Calculate curve progress | [
"Calculate",
"curve",
"progress"
] | b0619353a6d80f3a8cf8dfff94f6ae1bbc344b77 | https://github.com/alexk111/SVG-Morpheus/blob/b0619353a6d80f3a8cf8dfff94f6ae1bbc344b77/source/js/deps/helpers.js#L128-L137 | train |
rkusa/koa-passport | lib/framework/koa.js | initialize | function initialize(passport) {
const middleware = promisify(_initialize(passport))
return function passportInitialize(ctx, next) {
// koa <-> connect compatibility:
const userProperty = passport._userProperty || 'user'
// check ctx.req has the userProperty
if (!ctx.req.hasOwnProperty(userProperty))... | javascript | function initialize(passport) {
const middleware = promisify(_initialize(passport))
return function passportInitialize(ctx, next) {
// koa <-> connect compatibility:
const userProperty = passport._userProperty || 'user'
// check ctx.req has the userProperty
if (!ctx.req.hasOwnProperty(userProperty))... | [
"function",
"initialize",
"(",
"passport",
")",
"{",
"const",
"middleware",
"=",
"promisify",
"(",
"_initialize",
"(",
"passport",
")",
")",
"return",
"function",
"passportInitialize",
"(",
"ctx",
",",
"next",
")",
"{",
"// koa <-> connect compatibility:",
"const"... | Passport's initialization middleware for Koa.
@return {GeneratorFunction}
@api private | [
"Passport",
"s",
"initialization",
"middleware",
"for",
"Koa",
"."
] | 89c131476ce8919b9c3f2ce749e84487e2caf799 | https://github.com/rkusa/koa-passport/blob/89c131476ce8919b9c3f2ce749e84487e2caf799/lib/framework/koa.js#L21-L63 | train |
rkusa/koa-passport | lib/framework/koa.js | authenticate | function authenticate(passport, name, options, callback) {
// normalize arguments
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
if (callback) {
// When the callback is set, neither `next`, `res.redirect` or `res.end`
// are called. That is, a ... | javascript | function authenticate(passport, name, options, callback) {
// normalize arguments
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
if (callback) {
// When the callback is set, neither `next`, `res.redirect` or `res.end`
// are called. That is, a ... | [
"function",
"authenticate",
"(",
"passport",
",",
"name",
",",
"options",
",",
"callback",
")",
"{",
"// normalize arguments",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
"options",
"=",
"{",
"}",
"}",
"options"... | Passport's authenticate middleware for Koa.
@param {String|Array} name
@param {Object} options
@param {GeneratorFunction} callback
@return {GeneratorFunction}
@api private | [
"Passport",
"s",
"authenticate",
"middleware",
"for",
"Koa",
"."
] | 89c131476ce8919b9c3f2ce749e84487e2caf799 | https://github.com/rkusa/koa-passport/blob/89c131476ce8919b9c3f2ce749e84487e2caf799/lib/framework/koa.js#L74-L154 | train |
rkusa/koa-passport | lib/framework/koa.js | authorize | function authorize(passport, name, options, callback) {
options = options || {}
options.assignProperty = 'account'
return authenticate(passport, name, options, callback)
} | javascript | function authorize(passport, name, options, callback) {
options = options || {}
options.assignProperty = 'account'
return authenticate(passport, name, options, callback)
} | [
"function",
"authorize",
"(",
"passport",
",",
"name",
",",
"options",
",",
"callback",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"options",
".",
"assignProperty",
"=",
"'account'",
"return",
"authenticate",
"(",
"passport",
",",
"name",
",",
"o... | Passport's authorize middleware for Koa.
@param {String|Array} name
@param {Object} options
@param {GeneratorFunction} callback
@return {GeneratorFunction}
@api private | [
"Passport",
"s",
"authorize",
"middleware",
"for",
"Koa",
"."
] | 89c131476ce8919b9c3f2ce749e84487e2caf799 | https://github.com/rkusa/koa-passport/blob/89c131476ce8919b9c3f2ce749e84487e2caf799/lib/framework/koa.js#L165-L170 | train |
rkusa/koa-passport | lib/framework/request.js | getObject | function getObject(ctx, key) {
if (ctx.state && (key in ctx.state)) {
return ctx.state
}
if (key in ctx.request) {
return ctx.request
}
if (key in ctx.req) {
return ctx.req
}
if (key in ctx) {
return ctx
}
return undefined
} | javascript | function getObject(ctx, key) {
if (ctx.state && (key in ctx.state)) {
return ctx.state
}
if (key in ctx.request) {
return ctx.request
}
if (key in ctx.req) {
return ctx.req
}
if (key in ctx) {
return ctx
}
return undefined
} | [
"function",
"getObject",
"(",
"ctx",
",",
"key",
")",
"{",
"if",
"(",
"ctx",
".",
"state",
"&&",
"(",
"key",
"in",
"ctx",
".",
"state",
")",
")",
"{",
"return",
"ctx",
".",
"state",
"}",
"if",
"(",
"key",
"in",
"ctx",
".",
"request",
")",
"{",
... | test where the key is available, either in `ctx.state`, Node's request, Koa's request or Koa's context | [
"test",
"where",
"the",
"key",
"is",
"available",
"either",
"in",
"ctx",
".",
"state",
"Node",
"s",
"request",
"Koa",
"s",
"request",
"or",
"Koa",
"s",
"context"
] | 89c131476ce8919b9c3f2ce749e84487e2caf799 | https://github.com/rkusa/koa-passport/blob/89c131476ce8919b9c3f2ce749e84487e2caf799/lib/framework/request.js#L114-L132 | train |
orthes/medium-editor-insert-plugin | dist/js/medium-editor-insert-plugin.js | Core | function Core(el, options) {
var editor;
this.el = el;
this.$el = $(el);
this.templates = window.MediumInsert.Templates;
if (options) {
// Fix #142
// Avoid deep copying editor object, because since v2.3.0 it contains circular references which causes jQu... | javascript | function Core(el, options) {
var editor;
this.el = el;
this.$el = $(el);
this.templates = window.MediumInsert.Templates;
if (options) {
// Fix #142
// Avoid deep copying editor object, because since v2.3.0 it contains circular references which causes jQu... | [
"function",
"Core",
"(",
"el",
",",
"options",
")",
"{",
"var",
"editor",
";",
"this",
".",
"el",
"=",
"el",
";",
"this",
".",
"$el",
"=",
"$",
"(",
"el",
")",
";",
"this",
".",
"templates",
"=",
"window",
".",
"MediumInsert",
".",
"Templates",
"... | Core plugin's object
Sets options, variables and calls init() function
@constructor
@param {DOM} el - DOM element to init the plugin on
@param {object} options - Options to override defaults
@return {void} | [
"Core",
"plugin",
"s",
"object"
] | 276e680e49bdd965eed50e4f6ed67d660e5ca518 | https://github.com/orthes/medium-editor-insert-plugin/blob/276e680e49bdd965eed50e4f6ed67d660e5ca518/dist/js/medium-editor-insert-plugin.js#L203-L247 | train |
orthes/medium-editor-insert-plugin | spec/helpers/util.js | placeCaret | function placeCaret(el, position) {
var range, sel;
range = document.createRange();
sel = window.getSelection();
range.setStart(el.childNodes[0], position);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
} | javascript | function placeCaret(el, position) {
var range, sel;
range = document.createRange();
sel = window.getSelection();
range.setStart(el.childNodes[0], position);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
} | [
"function",
"placeCaret",
"(",
"el",
",",
"position",
")",
"{",
"var",
"range",
",",
"sel",
";",
"range",
"=",
"document",
".",
"createRange",
"(",
")",
";",
"sel",
"=",
"window",
".",
"getSelection",
"(",
")",
";",
"range",
".",
"setStart",
"(",
"el... | Placing caret to element and selected position
@param {Element} el
@param {integer} position
@return {void} | [
"Placing",
"caret",
"to",
"element",
"and",
"selected",
"position"
] | 276e680e49bdd965eed50e4f6ed67d660e5ca518 | https://github.com/orthes/medium-editor-insert-plugin/blob/276e680e49bdd965eed50e4f6ed67d660e5ca518/spec/helpers/util.js#L9-L18 | train |
chieffancypants/angular-loading-bar | build/loading-bar.js | isCached | function isCached(config) {
var cache;
var defaultCache = $cacheFactory.get('$http');
var defaults = $httpProvider.defaults;
// Choose the proper cache source. Borrowed from angular: $http service
if ((config.cache || defaults.cache) && config.cache !== false &&
(confi... | javascript | function isCached(config) {
var cache;
var defaultCache = $cacheFactory.get('$http');
var defaults = $httpProvider.defaults;
// Choose the proper cache source. Borrowed from angular: $http service
if ((config.cache || defaults.cache) && config.cache !== false &&
(confi... | [
"function",
"isCached",
"(",
"config",
")",
"{",
"var",
"cache",
";",
"var",
"defaultCache",
"=",
"$cacheFactory",
".",
"get",
"(",
"'$http'",
")",
";",
"var",
"defaults",
"=",
"$httpProvider",
".",
"defaults",
";",
"// Choose the proper cache source. Borrowed fro... | Determine if the response has already been cached
@param {Object} config the config option from the request
@return {Boolean} retrns true if cached, otherwise false | [
"Determine",
"if",
"the",
"response",
"has",
"already",
"been",
"cached"
] | 73ff0d9b13b6baa58da28a8376d464353b0b236a | https://github.com/chieffancypants/angular-loading-bar/blob/73ff0d9b13b6baa58da28a8376d464353b0b236a/build/loading-bar.js#L74-L95 | train |
chieffancypants/angular-loading-bar | build/loading-bar.js | _start | function _start() {
if (!$animate) {
$animate = $injector.get('$animate');
}
$timeout.cancel(completeTimeout);
// do not continually broadcast the started event:
if (started) {
return;
}
var document = $document[0];
var parent = docu... | javascript | function _start() {
if (!$animate) {
$animate = $injector.get('$animate');
}
$timeout.cancel(completeTimeout);
// do not continually broadcast the started event:
if (started) {
return;
}
var document = $document[0];
var parent = docu... | [
"function",
"_start",
"(",
")",
"{",
"if",
"(",
"!",
"$animate",
")",
"{",
"$animate",
"=",
"$injector",
".",
"get",
"(",
"'$animate'",
")",
";",
"}",
"$timeout",
".",
"cancel",
"(",
"completeTimeout",
")",
";",
"// do not continually broadcast the started eve... | Inserts the loading bar element into the dom, and sets it to 2% | [
"Inserts",
"the",
"loading",
"bar",
"element",
"into",
"the",
"dom",
"and",
"sets",
"it",
"to",
"2%"
] | 73ff0d9b13b6baa58da28a8376d464353b0b236a | https://github.com/chieffancypants/angular-loading-bar/blob/73ff0d9b13b6baa58da28a8376d464353b0b236a/build/loading-bar.js#L198-L235 | train |
chieffancypants/angular-loading-bar | build/loading-bar.js | _set | function _set(n) {
if (!started) {
return;
}
var pct = (n * 100) + '%';
loadingBar.css('width', pct);
status = n;
// increment loadingbar to give the illusion that there is always
// progress but make sure to cancel the previous timeouts so we don't
... | javascript | function _set(n) {
if (!started) {
return;
}
var pct = (n * 100) + '%';
loadingBar.css('width', pct);
status = n;
// increment loadingbar to give the illusion that there is always
// progress but make sure to cancel the previous timeouts so we don't
... | [
"function",
"_set",
"(",
"n",
")",
"{",
"if",
"(",
"!",
"started",
")",
"{",
"return",
";",
"}",
"var",
"pct",
"=",
"(",
"n",
"*",
"100",
")",
"+",
"'%'",
";",
"loadingBar",
".",
"css",
"(",
"'width'",
",",
"pct",
")",
";",
"status",
"=",
"n"... | Set the loading bar's width to a certain percent.
@param n any value between 0 and 1 | [
"Set",
"the",
"loading",
"bar",
"s",
"width",
"to",
"a",
"certain",
"percent",
"."
] | 73ff0d9b13b6baa58da28a8376d464353b0b236a | https://github.com/chieffancypants/angular-loading-bar/blob/73ff0d9b13b6baa58da28a8376d464353b0b236a/build/loading-bar.js#L242-L259 | train |
chieffancypants/angular-loading-bar | build/loading-bar.js | _inc | function _inc() {
if (_status() >= 1) {
return;
}
var rnd = 0;
// TODO: do this mathmatically instead of through conditions
var stat = _status();
if (stat >= 0 && stat < 0.25) {
// Start out between 3 - 6% increments
rnd = (Math.random() *... | javascript | function _inc() {
if (_status() >= 1) {
return;
}
var rnd = 0;
// TODO: do this mathmatically instead of through conditions
var stat = _status();
if (stat >= 0 && stat < 0.25) {
// Start out between 3 - 6% increments
rnd = (Math.random() *... | [
"function",
"_inc",
"(",
")",
"{",
"if",
"(",
"_status",
"(",
")",
">=",
"1",
")",
"{",
"return",
";",
"}",
"var",
"rnd",
"=",
"0",
";",
"// TODO: do this mathmatically instead of through conditions",
"var",
"stat",
"=",
"_status",
"(",
")",
";",
"if",
"... | Increments the loading bar by a random amount
but slows down as it progresses | [
"Increments",
"the",
"loading",
"bar",
"by",
"a",
"random",
"amount",
"but",
"slows",
"down",
"as",
"it",
"progresses"
] | 73ff0d9b13b6baa58da28a8376d464353b0b236a | https://github.com/chieffancypants/angular-loading-bar/blob/73ff0d9b13b6baa58da28a8376d464353b0b236a/build/loading-bar.js#L265-L294 | train |
yargs/yargs-parser | index.js | eatNargs | function eatNargs (i, key, args) {
var ii
const toEat = checkAllAliases(key, flags.nargs)
// nargs will not consume flag arguments, e.g., -abc, --foo,
// and terminates when one is observed.
var available = 0
for (ii = i + 1; ii < args.length; ii++) {
if (!args[ii].match(/^-[^0-9]/)) avai... | javascript | function eatNargs (i, key, args) {
var ii
const toEat = checkAllAliases(key, flags.nargs)
// nargs will not consume flag arguments, e.g., -abc, --foo,
// and terminates when one is observed.
var available = 0
for (ii = i + 1; ii < args.length; ii++) {
if (!args[ii].match(/^-[^0-9]/)) avai... | [
"function",
"eatNargs",
"(",
"i",
",",
"key",
",",
"args",
")",
"{",
"var",
"ii",
"const",
"toEat",
"=",
"checkAllAliases",
"(",
"key",
",",
"flags",
".",
"nargs",
")",
"// nargs will not consume flag arguments, e.g., -abc, --foo,",
"// and terminates when one is obse... | how many arguments should we consume, based on the nargs option? | [
"how",
"many",
"arguments",
"should",
"we",
"consume",
"based",
"on",
"the",
"nargs",
"option?"
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L355-L375 | train |
yargs/yargs-parser | index.js | setConfig | function setConfig (argv) {
var configLookup = {}
// expand defaults/aliases, in-case any happen to reference
// the config.json file.
applyDefaultsAndAliases(configLookup, flags.aliases, defaults)
Object.keys(flags.configs).forEach(function (configKey) {
var configPath = argv[configKey] || ... | javascript | function setConfig (argv) {
var configLookup = {}
// expand defaults/aliases, in-case any happen to reference
// the config.json file.
applyDefaultsAndAliases(configLookup, flags.aliases, defaults)
Object.keys(flags.configs).forEach(function (configKey) {
var configPath = argv[configKey] || ... | [
"function",
"setConfig",
"(",
"argv",
")",
"{",
"var",
"configLookup",
"=",
"{",
"}",
"// expand defaults/aliases, in-case any happen to reference",
"// the config.json file.",
"applyDefaultsAndAliases",
"(",
"configLookup",
",",
"flags",
".",
"aliases",
",",
"defaults",
... | set args from config.json file, this should be applied last so that defaults can be applied. | [
"set",
"args",
"from",
"config",
".",
"json",
"file",
"this",
"should",
"be",
"applied",
"last",
"so",
"that",
"defaults",
"can",
"be",
"applied",
"."
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L511-L545 | train |
yargs/yargs-parser | index.js | setConfigObject | function setConfigObject (config, prev) {
Object.keys(config).forEach(function (key) {
var value = config[key]
var fullKey = prev ? prev + '.' + key : key
// if the value is an inner object and we have dot-notation
// enabled, treat inner objects in config the same as
// heavily neste... | javascript | function setConfigObject (config, prev) {
Object.keys(config).forEach(function (key) {
var value = config[key]
var fullKey = prev ? prev + '.' + key : key
// if the value is an inner object and we have dot-notation
// enabled, treat inner objects in config the same as
// heavily neste... | [
"function",
"setConfigObject",
"(",
"config",
",",
"prev",
")",
"{",
"Object",
".",
"keys",
"(",
"config",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"value",
"=",
"config",
"[",
"key",
"]",
"var",
"fullKey",
"=",
"prev",
"?",... | set args from config object. it recursively checks nested objects. | [
"set",
"args",
"from",
"config",
"object",
".",
"it",
"recursively",
"checks",
"nested",
"objects",
"."
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L549-L568 | train |
yargs/yargs-parser | index.js | defaultValue | function defaultValue (key) {
if (!checkAllAliases(key, flags.bools) &&
!checkAllAliases(key, flags.counts) &&
`${key}` in defaults) {
return defaults[key]
} else {
return defaultForType(guessType(key))
}
} | javascript | function defaultValue (key) {
if (!checkAllAliases(key, flags.bools) &&
!checkAllAliases(key, flags.counts) &&
`${key}` in defaults) {
return defaults[key]
} else {
return defaultForType(guessType(key))
}
} | [
"function",
"defaultValue",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"checkAllAliases",
"(",
"key",
",",
"flags",
".",
"bools",
")",
"&&",
"!",
"checkAllAliases",
"(",
"key",
",",
"flags",
".",
"counts",
")",
"&&",
"`",
"${",
"key",
"}",
"`",
"in",
"d... | make a best effor to pick a default value for an option based on name and type. | [
"make",
"a",
"best",
"effor",
"to",
"pick",
"a",
"default",
"value",
"for",
"an",
"option",
"based",
"on",
"name",
"and",
"type",
"."
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L771-L779 | train |
yargs/yargs-parser | index.js | guessType | function guessType (key) {
var type = 'boolean'
if (checkAllAliases(key, flags.strings)) type = 'string'
else if (checkAllAliases(key, flags.numbers)) type = 'number'
else if (checkAllAliases(key, flags.arrays)) type = 'array'
return type
} | javascript | function guessType (key) {
var type = 'boolean'
if (checkAllAliases(key, flags.strings)) type = 'string'
else if (checkAllAliases(key, flags.numbers)) type = 'number'
else if (checkAllAliases(key, flags.arrays)) type = 'array'
return type
} | [
"function",
"guessType",
"(",
"key",
")",
"{",
"var",
"type",
"=",
"'boolean'",
"if",
"(",
"checkAllAliases",
"(",
"key",
",",
"flags",
".",
"strings",
")",
")",
"type",
"=",
"'string'",
"else",
"if",
"(",
"checkAllAliases",
"(",
"key",
",",
"flags",
"... | given a flag, enforce a default type. | [
"given",
"a",
"flag",
"enforce",
"a",
"default",
"type",
"."
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L795-L803 | train |
yargs/yargs-parser | index.js | combineAliases | function combineAliases (aliases) {
var aliasArrays = []
var change = true
var combined = {}
// turn alias lookup hash {key: ['alias1', 'alias2']} into
// a simple array ['key', 'alias1', 'alias2']
Object.keys(aliases).forEach(function (key) {
aliasArrays.push(
[].concat(aliases[key], key)
)
... | javascript | function combineAliases (aliases) {
var aliasArrays = []
var change = true
var combined = {}
// turn alias lookup hash {key: ['alias1', 'alias2']} into
// a simple array ['key', 'alias1', 'alias2']
Object.keys(aliases).forEach(function (key) {
aliasArrays.push(
[].concat(aliases[key], key)
)
... | [
"function",
"combineAliases",
"(",
"aliases",
")",
"{",
"var",
"aliasArrays",
"=",
"[",
"]",
"var",
"change",
"=",
"true",
"var",
"combined",
"=",
"{",
"}",
"// turn alias lookup hash {key: ['alias1', 'alias2']} into",
"// a simple array ['key', 'alias1', 'alias2']",
"Obj... | if any aliases reference each other, we should merge them together. | [
"if",
"any",
"aliases",
"reference",
"each",
"other",
"we",
"should",
"merge",
"them",
"together",
"."
] | 981e1512d15a0af757a74a9cd75c448259aa8efa | https://github.com/yargs/yargs-parser/blob/981e1512d15a0af757a74a9cd75c448259aa8efa/index.js#L831-L874 | train |
jaredhanson/passport-oauth2 | lib/strategy.js | OAuth2Strategy | function OAuth2Strategy(options, verify) {
if (typeof options == 'function') {
verify = options;
options = undefined;
}
options = options || {};
if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); }
if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requ... | javascript | function OAuth2Strategy(options, verify) {
if (typeof options == 'function') {
verify = options;
options = undefined;
}
options = options || {};
if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); }
if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requ... | [
"function",
"OAuth2Strategy",
"(",
"options",
",",
"verify",
")",
"{",
"if",
"(",
"typeof",
"options",
"==",
"'function'",
")",
"{",
"verify",
"=",
"options",
";",
"options",
"=",
"undefined",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"... | Creates an instance of `OAuth2Strategy`.
The OAuth 2.0 authentication strategy authenticates requests using the OAuth
2.0 framework.
OAuth 2.0 provides a facility for delegated authentication, whereby users can
authenticate using a third-party service such as Facebook. Delegating in
this manner involves a sequence o... | [
"Creates",
"an",
"instance",
"of",
"OAuth2Strategy",
"."
] | b938a915e45832971ead5d7252f7ae51eb5d6b27 | https://github.com/jaredhanson/passport-oauth2/blob/b938a915e45832971ead5d7252f7ae51eb5d6b27/lib/strategy.js#L76-L117 | train |
moleculerjs/moleculer-web | src/utils.js | composeThen | function composeThen(req, res, ...mws) {
return new Promise((resolve, reject) => {
compose(...mws)(req, res, err => {
if (err) {
/* istanbul ignore next */
if (err instanceof MoleculerError)
return reject(err);
/* istanbul ignore next */
if (err instanceof Error)
return reject(new Molec... | javascript | function composeThen(req, res, ...mws) {
return new Promise((resolve, reject) => {
compose(...mws)(req, res, err => {
if (err) {
/* istanbul ignore next */
if (err instanceof MoleculerError)
return reject(err);
/* istanbul ignore next */
if (err instanceof Error)
return reject(new Molec... | [
"function",
"composeThen",
"(",
"req",
",",
"res",
",",
"...",
"mws",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"compose",
"(",
"...",
"mws",
")",
"(",
"req",
",",
"res",
",",
"err",
"=>",
"{",
"if"... | Compose middlewares and return Promise
@param {...Function} mws
@returns {Promise} | [
"Compose",
"middlewares",
"and",
"return",
"Promise"
] | 3843c39ee2c17625a101c5df8ab92030c4c7f86f | https://github.com/moleculerjs/moleculer-web/blob/3843c39ee2c17625a101c5df8ab92030c4c7f86f/src/utils.js#L82-L101 | train |
moleculerjs/moleculer-web | src/utils.js | generateETag | function generateETag(body, opt) {
if (_.isFunction(opt))
return opt.call(this, body);
let buf = !Buffer.isBuffer(body)
? Buffer.from(body)
: body;
return etag(buf, (opt === true || opt === "weak") ? { weak: true } : null);
} | javascript | function generateETag(body, opt) {
if (_.isFunction(opt))
return opt.call(this, body);
let buf = !Buffer.isBuffer(body)
? Buffer.from(body)
: body;
return etag(buf, (opt === true || opt === "weak") ? { weak: true } : null);
} | [
"function",
"generateETag",
"(",
"body",
",",
"opt",
")",
"{",
"if",
"(",
"_",
".",
"isFunction",
"(",
"opt",
")",
")",
"return",
"opt",
".",
"call",
"(",
"this",
",",
"body",
")",
";",
"let",
"buf",
"=",
"!",
"Buffer",
".",
"isBuffer",
"(",
"bod... | Generate ETag from content.
@param {any} body
@param {Boolean|String|Function?} opt
@returns {String} | [
"Generate",
"ETag",
"from",
"content",
"."
] | 3843c39ee2c17625a101c5df8ab92030c4c7f86f | https://github.com/moleculerjs/moleculer-web/blob/3843c39ee2c17625a101c5df8ab92030c4c7f86f/src/utils.js#L111-L120 | train |
moleculerjs/moleculer-web | src/utils.js | isFresh | function isFresh(req, res) {
if ((res.statusCode >= 200 && res.statusCode < 300) || 304 === res.statusCode) {
return fresh(req.headers, {
"etag": res.getHeader("ETag"),
"last-modified": res.getHeader("Last-Modified")
});
}
return false;
} | javascript | function isFresh(req, res) {
if ((res.statusCode >= 200 && res.statusCode < 300) || 304 === res.statusCode) {
return fresh(req.headers, {
"etag": res.getHeader("ETag"),
"last-modified": res.getHeader("Last-Modified")
});
}
return false;
} | [
"function",
"isFresh",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"(",
"res",
".",
"statusCode",
">=",
"200",
"&&",
"res",
".",
"statusCode",
"<",
"300",
")",
"||",
"304",
"===",
"res",
".",
"statusCode",
")",
"{",
"return",
"fresh",
"(",
"req",
... | Check the data freshness.
@param {*} req
@param {*} res
@returns {Boolean} | [
"Check",
"the",
"data",
"freshness",
"."
] | 3843c39ee2c17625a101c5df8ab92030c4c7f86f | https://github.com/moleculerjs/moleculer-web/blob/3843c39ee2c17625a101c5df8ab92030c4c7f86f/src/utils.js#L130-L138 | train |
biati-digital/glightbox | dist/js/glightbox.js | addClass | function addClass(node, name) {
if (hasClass(node, name)) {
return;
}
if (node.classList) {
node.classList.add(name);
} else {
node.className += " " + name;
}
} | javascript | function addClass(node, name) {
if (hasClass(node, name)) {
return;
}
if (node.classList) {
node.classList.add(name);
} else {
node.className += " " + name;
}
} | [
"function",
"addClass",
"(",
"node",
",",
"name",
")",
"{",
"if",
"(",
"hasClass",
"(",
"node",
",",
"name",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"node",
".",
"classList",
")",
"{",
"node",
".",
"classList",
".",
"add",
"(",
"name",
")",... | Add element class
@param {node} element
@param {string} class name | [
"Add",
"element",
"class"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L358-L367 | train |
biati-digital/glightbox | dist/js/glightbox.js | removeClass | function removeClass(node, name) {
var c = name.split(' ');
if (c.length > 1) {
each(c, function (cl) {
removeClass(node, cl);
});
return;
}
if (node.classList) {
node.classList.remove(name);
} else {
nod... | javascript | function removeClass(node, name) {
var c = name.split(' ');
if (c.length > 1) {
each(c, function (cl) {
removeClass(node, cl);
});
return;
}
if (node.classList) {
node.classList.remove(name);
} else {
nod... | [
"function",
"removeClass",
"(",
"node",
",",
"name",
")",
"{",
"var",
"c",
"=",
"name",
".",
"split",
"(",
"' '",
")",
";",
"if",
"(",
"c",
".",
"length",
">",
"1",
")",
"{",
"each",
"(",
"c",
",",
"function",
"(",
"cl",
")",
"{",
"removeClass"... | Remove element class
@param {node} element
@param {string} class name | [
"Remove",
"element",
"class"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L375-L388 | train |
biati-digital/glightbox | dist/js/glightbox.js | createHTML | function createHTML(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
} | javascript | function createHTML(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
} | [
"function",
"createHTML",
"(",
"htmlStr",
")",
"{",
"var",
"frag",
"=",
"document",
".",
"createDocumentFragment",
"(",
")",
",",
"temp",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"temp",
".",
"innerHTML",
"=",
"htmlStr",
";",
"while",... | Create a document fragment
@param {string} html code | [
"Create",
"a",
"document",
"fragment"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L480-L488 | train |
biati-digital/glightbox | dist/js/glightbox.js | getClosest | function getClosest(elem, selector) {
while (elem !== document.body) {
elem = elem.parentElement;
var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msMatchesSelector(selector);
if (matches) return elem;
}
} | javascript | function getClosest(elem, selector) {
while (elem !== document.body) {
elem = elem.parentElement;
var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msMatchesSelector(selector);
if (matches) return elem;
}
} | [
"function",
"getClosest",
"(",
"elem",
",",
"selector",
")",
"{",
"while",
"(",
"elem",
"!==",
"document",
".",
"body",
")",
"{",
"elem",
"=",
"elem",
".",
"parentElement",
";",
"var",
"matches",
"=",
"typeof",
"elem",
".",
"matches",
"==",
"'function'",... | Get the closestElement
@param {node} element
@param {string} class name | [
"Get",
"the",
"closestElement"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L496-L503 | train |
biati-digital/glightbox | dist/js/glightbox.js | youtubeApiHandle | function youtubeApiHandle() {
for (var i = 0; i < YTTemp.length; i++) {
var iframe = YTTemp[i];
var player = new YT.Player(iframe);
videoPlayers[iframe.id] = player;
}
} | javascript | function youtubeApiHandle() {
for (var i = 0; i < YTTemp.length; i++) {
var iframe = YTTemp[i];
var player = new YT.Player(iframe);
videoPlayers[iframe.id] = player;
}
} | [
"function",
"youtubeApiHandle",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"YTTemp",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"iframe",
"=",
"YTTemp",
"[",
"i",
"]",
";",
"var",
"player",
"=",
"new",
"YT",
".",
"Play... | Handle youtube Api
This is a simple fix, when the video
is ready sometimes the youtube api is still
loading so we can not autoplay or pause
we need to listen onYouTubeIframeAPIReady and
register the videos if required | [
"Handle",
"youtube",
"Api",
"This",
"is",
"a",
"simple",
"fix",
"when",
"the",
"video",
"is",
"ready",
"sometimes",
"the",
"youtube",
"api",
"is",
"still",
"loading",
"so",
"we",
"can",
"not",
"autoplay",
"or",
"pause",
"we",
"need",
"to",
"listen",
"onY... | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L988-L994 | train |
biati-digital/glightbox | dist/js/glightbox.js | waitUntil | function waitUntil(check, onComplete, delay, timeout) {
if (check()) {
onComplete();
return;
}
if (!delay) delay = 100;
var timeoutPointer = void 0;
var intervalPointer = setInterval(function () {
if (!check()) return;
clearInterva... | javascript | function waitUntil(check, onComplete, delay, timeout) {
if (check()) {
onComplete();
return;
}
if (!delay) delay = 100;
var timeoutPointer = void 0;
var intervalPointer = setInterval(function () {
if (!check()) return;
clearInterva... | [
"function",
"waitUntil",
"(",
"check",
",",
"onComplete",
",",
"delay",
",",
"timeout",
")",
"{",
"if",
"(",
"check",
"(",
")",
")",
"{",
"onComplete",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"delay",
")",
"delay",
"=",
"100",
";",
"va... | Wait until
wait until all the validations
are passed
@param {function} check
@param {function} onComplete
@param {numeric} delay
@param {numeric} timeout | [
"Wait",
"until",
"wait",
"until",
"all",
"the",
"validations",
"are",
"passed"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L1014-L1031 | train |
biati-digital/glightbox | dist/js/glightbox.js | setInlineContent | function setInlineContent(slide, data, callback) {
var slideMedia = slide.querySelector('.gslide-media');
var hash = data.href.split('#').pop().trim();
var div = document.getElementById(hash);
if (!div) {
return false;
}
var cloned = div.cloneNode(true);
... | javascript | function setInlineContent(slide, data, callback) {
var slideMedia = slide.querySelector('.gslide-media');
var hash = data.href.split('#').pop().trim();
var div = document.getElementById(hash);
if (!div) {
return false;
}
var cloned = div.cloneNode(true);
... | [
"function",
"setInlineContent",
"(",
"slide",
",",
"data",
",",
"callback",
")",
"{",
"var",
"slideMedia",
"=",
"slide",
".",
"querySelector",
"(",
"'.gslide-media'",
")",
";",
"var",
"hash",
"=",
"data",
".",
"href",
".",
"split",
"(",
"'#'",
")",
".",
... | Set slide inline content
we'll extend this to make http
requests using the fetch api
but for now we keep it simple
@param {node} slide
@param {object} data
@param {function} callback | [
"Set",
"slide",
"inline",
"content",
"we",
"ll",
"extend",
"this",
"to",
"make",
"http",
"requests",
"using",
"the",
"fetch",
"api",
"but",
"for",
"now",
"we",
"keep",
"it",
"simple"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L1063-L1083 | train |
biati-digital/glightbox | dist/js/glightbox.js | getSourceType | function getSourceType(url) {
var origin = url;
url = url.toLowerCase();
if (url.match(/\.(jpeg|jpg|gif|png|apn|webp|svg)$/) !== null) {
return 'image';
}
if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-z... | javascript | function getSourceType(url) {
var origin = url;
url = url.toLowerCase();
if (url.match(/\.(jpeg|jpg|gif|png|apn|webp|svg)$/) !== null) {
return 'image';
}
if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || url.match(/youtu\.be\/([a-z... | [
"function",
"getSourceType",
"(",
"url",
")",
"{",
"var",
"origin",
"=",
"url",
";",
"url",
"=",
"url",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"url",
".",
"match",
"(",
"/",
"\\.(jpeg|jpg|gif|png|apn|webp|svg)$",
"/",
")",
"!==",
"null",
")",
"{... | Get source type
gte the source type of a url
@param {string} url | [
"Get",
"source",
"type",
"gte",
"the",
"source",
"type",
"of",
"a",
"url"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L1091-L1121 | train |
biati-digital/glightbox | dist/js/glightbox.js | keyboardNavigation | function keyboardNavigation() {
var _this3 = this;
if (this.events.hasOwnProperty('keyboard')) {
return false;
}
this.events['keyboard'] = addEvent('keydown', {
onElement: window,
withCallback: function withCallback(event, target) {
ev... | javascript | function keyboardNavigation() {
var _this3 = this;
if (this.events.hasOwnProperty('keyboard')) {
return false;
}
this.events['keyboard'] = addEvent('keydown', {
onElement: window,
withCallback: function withCallback(event, target) {
ev... | [
"function",
"keyboardNavigation",
"(",
")",
"{",
"var",
"_this3",
"=",
"this",
";",
"if",
"(",
"this",
".",
"events",
".",
"hasOwnProperty",
"(",
"'keyboard'",
")",
")",
"{",
"return",
"false",
";",
"}",
"this",
".",
"events",
"[",
"'keyboard'",
"]",
"... | Desktop keyboard navigation | [
"Desktop",
"keyboard",
"navigation"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/dist/js/glightbox.js#L1126-L1142 | train |
biati-digital/glightbox | src/js/glightbox.js | getNodeEvents | function getNodeEvents(node, name = null, fn = null) {
const cache = (node[uid] = node[uid] || []);
const data = { all: cache, evt: null, found: null};
if (name && fn && utils.size(cache) > 0) {
each(cache, (cl, i) => {
if (cl.eventName == name && cl.fn.toString() == fn.toString()) {
... | javascript | function getNodeEvents(node, name = null, fn = null) {
const cache = (node[uid] = node[uid] || []);
const data = { all: cache, evt: null, found: null};
if (name && fn && utils.size(cache) > 0) {
each(cache, (cl, i) => {
if (cl.eventName == name && cl.fn.toString() == fn.toString()) {
... | [
"function",
"getNodeEvents",
"(",
"node",
",",
"name",
"=",
"null",
",",
"fn",
"=",
"null",
")",
"{",
"const",
"cache",
"=",
"(",
"node",
"[",
"uid",
"]",
"=",
"node",
"[",
"uid",
"]",
"||",
"[",
"]",
")",
";",
"const",
"data",
"=",
"{",
"all",... | Get nde events
return node events and optionally
check if the node has already a specific event
to avoid duplicated callbacks
@param {node} node
@param {string} name event name
@param {object} fn callback
@returns {object} | [
"Get",
"nde",
"events",
"return",
"node",
"events",
"and",
"optionally",
"check",
"if",
"the",
"node",
"has",
"already",
"a",
"specific",
"event",
"to",
"avoid",
"duplicated",
"callbacks"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L243-L256 | train |
biati-digital/glightbox | src/js/glightbox.js | addEvent | function addEvent(eventName, {
onElement,
withCallback,
avoidDuplicate = true,
once = false,
useCapture = false} = { }, thisArg) {
let element = onElement || []
if (utils.isString(element)) {
element = document.querySelectorAll(element)
}
function handler(event) {
if... | javascript | function addEvent(eventName, {
onElement,
withCallback,
avoidDuplicate = true,
once = false,
useCapture = false} = { }, thisArg) {
let element = onElement || []
if (utils.isString(element)) {
element = document.querySelectorAll(element)
}
function handler(event) {
if... | [
"function",
"addEvent",
"(",
"eventName",
",",
"{",
"onElement",
",",
"withCallback",
",",
"avoidDuplicate",
"=",
"true",
",",
"once",
"=",
"false",
",",
"useCapture",
"=",
"false",
"}",
"=",
"{",
"}",
",",
"thisArg",
")",
"{",
"let",
"element",
"=",
"... | Add Event
Add an event listener
@param {string} eventName
@param {object} detials | [
"Add",
"Event",
"Add",
"an",
"event",
"listener"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L266-L299 | train |
biati-digital/glightbox | src/js/glightbox.js | whichTransitionEvent | function whichTransitionEvent() {
let t,
el = document.createElement("fakeelement");
const transitions = {
transition: "transitionend",
OTransition: "oTransitionEnd",
MozTransition: "transitionend",
WebkitTransition: "webkitTransitionEnd"
};
for (t in transition... | javascript | function whichTransitionEvent() {
let t,
el = document.createElement("fakeelement");
const transitions = {
transition: "transitionend",
OTransition: "oTransitionEnd",
MozTransition: "transitionend",
WebkitTransition: "webkitTransitionEnd"
};
for (t in transition... | [
"function",
"whichTransitionEvent",
"(",
")",
"{",
"let",
"t",
",",
"el",
"=",
"document",
".",
"createElement",
"(",
"\"fakeelement\"",
")",
";",
"const",
"transitions",
"=",
"{",
"transition",
":",
"\"transitionend\"",
",",
"OTransition",
":",
"\"oTransitionEn... | Determine transition events | [
"Determine",
"transition",
"events"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L372-L388 | train |
biati-digital/glightbox | src/js/glightbox.js | getSlideData | function getSlideData(element = null, settings) {
let data = {
href: '',
title: '',
type: '',
description: '',
descPosition: 'bottom',
effect: '',
node: element
};
if (utils.isObject(element) && !utils.isNode(element)){
return extend(data, ele... | javascript | function getSlideData(element = null, settings) {
let data = {
href: '',
title: '',
type: '',
description: '',
descPosition: 'bottom',
effect: '',
node: element
};
if (utils.isObject(element) && !utils.isNode(element)){
return extend(data, ele... | [
"function",
"getSlideData",
"(",
"element",
"=",
"null",
",",
"settings",
")",
"{",
"let",
"data",
"=",
"{",
"href",
":",
"''",
",",
"title",
":",
"''",
",",
"type",
":",
"''",
",",
"description",
":",
"''",
",",
"descPosition",
":",
"'bottom'",
",",... | Get slide data
@param {node} element | [
"Get",
"slide",
"data"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L479-L561 | train |
biati-digital/glightbox | src/js/glightbox.js | createIframe | function createIframe(config) {
let { url, width, height, allow, callback, appendTo } = config;
let iframe = document.createElement('iframe');
let winWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
iframe.className = 'vimeo-video gvideo';
iframe.src = ... | javascript | function createIframe(config) {
let { url, width, height, allow, callback, appendTo } = config;
let iframe = document.createElement('iframe');
let winWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
iframe.className = 'vimeo-video gvideo';
iframe.src = ... | [
"function",
"createIframe",
"(",
"config",
")",
"{",
"let",
"{",
"url",
",",
"width",
",",
"height",
",",
"allow",
",",
"callback",
",",
"appendTo",
"}",
"=",
"config",
";",
"let",
"iframe",
"=",
"document",
".",
"createElement",
"(",
"'iframe'",
")",
... | Create an iframe element
@param {string} url
@param {numeric} width
@param {numeric} height
@param {function} callback | [
"Create",
"an",
"iframe",
"element"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L843-L874 | train |
biati-digital/glightbox | src/js/glightbox.js | getYoutubeID | function getYoutubeID(url) {
let videoID = '';
url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
if (url[2] !== undefined) {
videoID = url[2].split(/[^0-9a-z_\-]/i);
videoID = videoID[0];
} else {
videoID = url;
}
return videoID;
} | javascript | function getYoutubeID(url) {
let videoID = '';
url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
if (url[2] !== undefined) {
videoID = url[2].split(/[^0-9a-z_\-]/i);
videoID = videoID[0];
} else {
videoID = url;
}
return videoID;
} | [
"function",
"getYoutubeID",
"(",
"url",
")",
"{",
"let",
"videoID",
"=",
"''",
";",
"url",
"=",
"url",
".",
"replace",
"(",
"/",
"(>|<)",
"/",
"gi",
",",
"''",
")",
".",
"split",
"(",
"/",
"(vi\\/|v=|\\/v\\/|youtu\\.be\\/|\\/embed\\/)",
"/",
")",
";",
... | Get youtube ID
@param {string} url
@returns {string} video id | [
"Get",
"youtube",
"ID"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L886-L896 | train |
biati-digital/glightbox | src/js/glightbox.js | injectVideoApi | function injectVideoApi(url, callback) {
if (utils.isNil(url)) {
console.error('Inject videos api error');
return;
}
let found = document.querySelectorAll('script[src="' + url + '"]')
if (utils.isNil(found) || found.length == 0) {
let script = document.createElement('script');
... | javascript | function injectVideoApi(url, callback) {
if (utils.isNil(url)) {
console.error('Inject videos api error');
return;
}
let found = document.querySelectorAll('script[src="' + url + '"]')
if (utils.isNil(found) || found.length == 0) {
let script = document.createElement('script');
... | [
"function",
"injectVideoApi",
"(",
"url",
",",
"callback",
")",
"{",
"if",
"(",
"utils",
".",
"isNil",
"(",
"url",
")",
")",
"{",
"console",
".",
"error",
"(",
"'Inject videos api error'",
")",
";",
"return",
";",
"}",
"let",
"found",
"=",
"document",
... | Inject videos api
used for youtube, vimeo and jwplayer
@param {string} url
@param {function} callback | [
"Inject",
"videos",
"api",
"used",
"for",
"youtube",
"vimeo",
"and",
"jwplayer"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L906-L923 | train |
biati-digital/glightbox | src/js/glightbox.js | parseUrlParams | function parseUrlParams(params) {
let qs = '';
let i = 0;
each(params, (val, key) => {
if (i > 0) {
qs += '&';
}
qs += key + '=' + val;
i += 1;
})
return qs;
} | javascript | function parseUrlParams(params) {
let qs = '';
let i = 0;
each(params, (val, key) => {
if (i > 0) {
qs += '&';
}
qs += key + '=' + val;
i += 1;
})
return qs;
} | [
"function",
"parseUrlParams",
"(",
"params",
")",
"{",
"let",
"qs",
"=",
"''",
";",
"let",
"i",
"=",
"0",
";",
"each",
"(",
"params",
",",
"(",
"val",
",",
"key",
")",
"=>",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"qs",
"+=",
"'&'",
";",... | Parse url params
convert an object in to a
url query string parameters
@param {object} params | [
"Parse",
"url",
"params",
"convert",
"an",
"object",
"in",
"to",
"a",
"url",
"query",
"string",
"parameters"
] | 49a0136d6faef64fc2e667fa90caf3a3bd444564 | https://github.com/biati-digital/glightbox/blob/49a0136d6faef64fc2e667fa90caf3a3bd444564/src/js/glightbox.js#L988-L999 | train |
redux-orm/redux-orm | src/Model.js | getByIdQuery | function getByIdQuery(modelInstance) {
const modelClass = modelInstance.getClass();
const { idAttribute, modelName } = modelClass;
return {
table: modelName,
clauses: [
{
type: FILTER,
payload: {
[idAttribute]: modelInstance.ge... | javascript | function getByIdQuery(modelInstance) {
const modelClass = modelInstance.getClass();
const { idAttribute, modelName } = modelClass;
return {
table: modelName,
clauses: [
{
type: FILTER,
payload: {
[idAttribute]: modelInstance.ge... | [
"function",
"getByIdQuery",
"(",
"modelInstance",
")",
"{",
"const",
"modelClass",
"=",
"modelInstance",
".",
"getClass",
"(",
")",
";",
"const",
"{",
"idAttribute",
",",
"modelName",
"}",
"=",
"modelClass",
";",
"return",
"{",
"table",
":",
"modelName",
","... | Generates a query specification to get the instance's
corresponding table row using its primary key.
@private
@returns {Object} | [
"Generates",
"a",
"query",
"specification",
"to",
"get",
"the",
"instance",
"s",
"corresponding",
"table",
"row",
"using",
"its",
"primary",
"key",
"."
] | e6077dbfe7da47284ad6c22b1217967017959a7f | https://github.com/redux-orm/redux-orm/blob/e6077dbfe7da47284ad6c22b1217967017959a7f/src/Model.js#L28-L43 | train |
redux-orm/redux-orm | src/descriptors.js | attrDescriptor | function attrDescriptor(fieldName) {
return {
get() {
return this._fields[fieldName];
},
set(value) {
return this.set(fieldName, value);
},
enumerable: true,
configurable: true,
};
} | javascript | function attrDescriptor(fieldName) {
return {
get() {
return this._fields[fieldName];
},
set(value) {
return this.set(fieldName, value);
},
enumerable: true,
configurable: true,
};
} | [
"function",
"attrDescriptor",
"(",
"fieldName",
")",
"{",
"return",
"{",
"get",
"(",
")",
"{",
"return",
"this",
".",
"_fields",
"[",
"fieldName",
"]",
";",
"}",
",",
"set",
"(",
"value",
")",
"{",
"return",
"this",
".",
"set",
"(",
"fieldName",
",",... | The functions in this file return custom JS property descriptors
that are supposed to be assigned to Model fields.
Some include the logic to look up models using foreign keys and
to add or remove relationships between models.
@module descriptors
Defines a basic non-key attribute.
@param {string} fieldName - the na... | [
"The",
"functions",
"in",
"this",
"file",
"return",
"custom",
"JS",
"property",
"descriptors",
"that",
"are",
"supposed",
"to",
"be",
"assigned",
"to",
"Model",
"fields",
"."
] | e6077dbfe7da47284ad6c22b1217967017959a7f | https://github.com/redux-orm/redux-orm/blob/e6077dbfe7da47284ad6c22b1217967017959a7f/src/descriptors.js#L19-L32 | train |
redux-orm/redux-orm | src/descriptors.js | manyToManyDescriptor | function manyToManyDescriptor(
declaredFromModelName,
declaredToModelName,
throughModelName,
throughFields,
reverse
) {
return {
get() {
const {
session: {
[declaredFromModelName]: DeclaredFromModel,
[declaredToModelName... | javascript | function manyToManyDescriptor(
declaredFromModelName,
declaredToModelName,
throughModelName,
throughFields,
reverse
) {
return {
get() {
const {
session: {
[declaredFromModelName]: DeclaredFromModel,
[declaredToModelName... | [
"function",
"manyToManyDescriptor",
"(",
"declaredFromModelName",
",",
"declaredToModelName",
",",
"throughModelName",
",",
"throughFields",
",",
"reverse",
")",
"{",
"return",
"{",
"get",
"(",
")",
"{",
"const",
"{",
"session",
":",
"{",
"[",
"declaredFromModelNa... | This descriptor is assigned to both sides of a many-to-many relationship.
To indicate the backwards direction pass `true` for `reverse`. | [
"This",
"descriptor",
"is",
"assigned",
"to",
"both",
"sides",
"of",
"a",
"many",
"-",
"to",
"-",
"many",
"relationship",
".",
"To",
"indicate",
"the",
"backwards",
"direction",
"pass",
"true",
"for",
"reverse",
"."
] | e6077dbfe7da47284ad6c22b1217967017959a7f | https://github.com/redux-orm/redux-orm/blob/e6077dbfe7da47284ad6c22b1217967017959a7f/src/descriptors.js#L137-L279 | train |
redux-orm/redux-orm | src/utils.js | normalizeEntity | function normalizeEntity(entity) {
if (entity !== null &&
typeof entity !== 'undefined' &&
typeof entity.getId === 'function') {
return entity.getId();
}
return entity;
} | javascript | function normalizeEntity(entity) {
if (entity !== null &&
typeof entity !== 'undefined' &&
typeof entity.getId === 'function') {
return entity.getId();
}
return entity;
} | [
"function",
"normalizeEntity",
"(",
"entity",
")",
"{",
"if",
"(",
"entity",
"!==",
"null",
"&&",
"typeof",
"entity",
"!==",
"'undefined'",
"&&",
"typeof",
"entity",
".",
"getId",
"===",
"'function'",
")",
"{",
"return",
"entity",
".",
"getId",
"(",
")",
... | Normalizes `entity` to an id, where `entity` can be an id
or a Model instance.
@param {*} entity - either a Model instance or an id value
@return {*} the id value of `entity` | [
"Normalizes",
"entity",
"to",
"an",
"id",
"where",
"entity",
"can",
"be",
"an",
"id",
"or",
"a",
"Model",
"instance",
"."
] | e6077dbfe7da47284ad6c22b1217967017959a7f | https://github.com/redux-orm/redux-orm/blob/e6077dbfe7da47284ad6c22b1217967017959a7f/src/utils.js#L123-L130 | train |
redux-orm/redux-orm | src/db/Table.js | idSequencer | function idSequencer(_currMax, userPassedId) {
let currMax = _currMax;
let newMax;
let newId;
if (currMax === undefined) {
currMax = -1;
}
if (userPassedId === undefined) {
newMax = currMax + 1;
newId = newMax;
} else {
newMax = Math.max(currMax + 1, userPas... | javascript | function idSequencer(_currMax, userPassedId) {
let currMax = _currMax;
let newMax;
let newId;
if (currMax === undefined) {
currMax = -1;
}
if (userPassedId === undefined) {
newMax = currMax + 1;
newId = newMax;
} else {
newMax = Math.max(currMax + 1, userPas... | [
"function",
"idSequencer",
"(",
"_currMax",
",",
"userPassedId",
")",
"{",
"let",
"currMax",
"=",
"_currMax",
";",
"let",
"newMax",
";",
"let",
"newId",
";",
"if",
"(",
"currMax",
"===",
"undefined",
")",
"{",
"currMax",
"=",
"-",
"1",
";",
"}",
"if",
... | Input is the current max id and the new id passed to the create action. Both may be undefined. The current max id in the case that this is the first Model being created, and the new id if the id was not explicitly passed to the database. Return value is the new max id and the id to use to create the new row. If the id... | [
"Input",
"is",
"the",
"current",
"max",
"id",
"and",
"the",
"new",
"id",
"passed",
"to",
"the",
"create",
"action",
".",
"Both",
"may",
"be",
"undefined",
".",
"The",
"current",
"max",
"id",
"in",
"the",
"case",
"that",
"this",
"is",
"the",
"first",
... | e6077dbfe7da47284ad6c22b1217967017959a7f | https://github.com/redux-orm/redux-orm/blob/e6077dbfe7da47284ad6c22b1217967017959a7f/src/db/Table.js#L27-L48 | train |
bencevans/node-sonos | lib/services/AVTransport.js | function (host, port) {
this.name = 'AVTransport'
this.host = host
this.port = port || 1400
this.controlURL = '/MediaRenderer/AVTransport/Control'
this.eventSubURL = '/MediaRenderer/AVTransport/Event'
this.SCPDURL = '/xml/AVTransport1.xml'
} | javascript | function (host, port) {
this.name = 'AVTransport'
this.host = host
this.port = port || 1400
this.controlURL = '/MediaRenderer/AVTransport/Control'
this.eventSubURL = '/MediaRenderer/AVTransport/Event'
this.SCPDURL = '/xml/AVTransport1.xml'
} | [
"function",
"(",
"host",
",",
"port",
")",
"{",
"this",
".",
"name",
"=",
"'AVTransport'",
"this",
".",
"host",
"=",
"host",
"this",
".",
"port",
"=",
"port",
"||",
"1400",
"this",
".",
"controlURL",
"=",
"'/MediaRenderer/AVTransport/Control'",
"this",
"."... | Create a new instance of AVTransport
@class AVTransport
@param {String} host The host param of one of your sonos speakers
@param {Number} port The port of your sonos speaker, defaults to 1400 | [
"Create",
"a",
"new",
"instance",
"of",
"AVTransport"
] | f0d5c1f2aa522005b800f8f2727e0f99238aaeca | https://github.com/bencevans/node-sonos/blob/f0d5c1f2aa522005b800f8f2727e0f99238aaeca/lib/services/AVTransport.js#L18-L25 | train | |
bencevans/node-sonos | lib/services/Service.js | function (options) {
this.name = options.name
this.host = options.host
this.port = options.port || 1400
this.controlURL = options.controlURL
this.eventSubURL = options.eventSubURL
this.SCPDURL = options.SCPDURL
return this
} | javascript | function (options) {
this.name = options.name
this.host = options.host
this.port = options.port || 1400
this.controlURL = options.controlURL
this.eventSubURL = options.eventSubURL
this.SCPDURL = options.SCPDURL
return this
} | [
"function",
"(",
"options",
")",
"{",
"this",
".",
"name",
"=",
"options",
".",
"name",
"this",
".",
"host",
"=",
"options",
".",
"host",
"this",
".",
"port",
"=",
"options",
".",
"port",
"||",
"1400",
"this",
".",
"controlURL",
"=",
"options",
".",
... | Create a new instance of Service
@class Service
@param {Object} [options] All the required options to use this class
@param {String} options.host The host param of one of your sonos speakers
@param {Number} options.port The port of your sonos speaker, defaults to 1400
@param {String} options.controlURL The control url ... | [
"Create",
"a",
"new",
"instance",
"of",
"Service"
] | f0d5c1f2aa522005b800f8f2727e0f99238aaeca | https://github.com/bencevans/node-sonos/blob/f0d5c1f2aa522005b800f8f2727e0f99238aaeca/lib/services/Service.js#L26-L34 | train | |
bencevans/node-sonos | lib/sonos.js | Sonos | function Sonos (host, port, options) {
this.host = host
this.port = port || 1400
this.options = options || {}
if (!this.options.endpoints) this.options.endpoints = {}
if (!this.options.endpoints.transport) this.options.endpoints.transport = TRANSPORT_ENDPOINT
if (!this.options.endpoints.rendering) this.opti... | javascript | function Sonos (host, port, options) {
this.host = host
this.port = port || 1400
this.options = options || {}
if (!this.options.endpoints) this.options.endpoints = {}
if (!this.options.endpoints.transport) this.options.endpoints.transport = TRANSPORT_ENDPOINT
if (!this.options.endpoints.rendering) this.opti... | [
"function",
"Sonos",
"(",
"host",
",",
"port",
",",
"options",
")",
"{",
"this",
".",
"host",
"=",
"host",
"this",
".",
"port",
"=",
"port",
"||",
"1400",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
"if",
"(",
"!",
"this",
".",
"optio... | Create an instance of Sonos
@class Sonos
@param {String} host IP/DNS
@param {Number} port
@returns {Sonos} | [
"Create",
"an",
"instance",
"of",
"Sonos"
] | f0d5c1f2aa522005b800f8f2727e0f99238aaeca | https://github.com/bencevans/node-sonos/blob/f0d5c1f2aa522005b800f8f2727e0f99238aaeca/lib/sonos.js#L52-L75 | train |
webscopeio/react-textarea-autocomplete | cypress/integration/textarea.js | repeat | function repeat(string, times = 1) {
let result = "";
let round = times;
while (round--) {
result += string;
}
return result;
} | javascript | function repeat(string, times = 1) {
let result = "";
let round = times;
while (round--) {
result += string;
}
return result;
} | [
"function",
"repeat",
"(",
"string",
",",
"times",
"=",
"1",
")",
"{",
"let",
"result",
"=",
"\"\"",
";",
"let",
"round",
"=",
"times",
";",
"while",
"(",
"round",
"--",
")",
"{",
"result",
"+=",
"string",
";",
"}",
"return",
"result",
";",
"}"
] | Helper function for a repeating of commands
e.g : cy
.get('.rta__textarea')
.type(`${repeat('{backspace}', 13)} again {downarrow}{enter}`); | [
"Helper",
"function",
"for",
"a",
"repeating",
"of",
"commands"
] | a0f4d87cd7d7a49726916ee6c5f9e7468a7b1427 | https://github.com/webscopeio/react-textarea-autocomplete/blob/a0f4d87cd7d7a49726916ee6c5f9e7468a7b1427/cypress/integration/textarea.js#L8-L16 | train |
andrewplummer/Sugar | lib/object.js | toQueryStringWithOptions | function toQueryStringWithOptions(obj, opts) {
opts = opts || {};
if (isUndefined(opts.separator)) {
opts.separator = '_';
}
return toQueryString(obj, opts.deep, opts.transform, opts.prefix || '', opts.separator);
} | javascript | function toQueryStringWithOptions(obj, opts) {
opts = opts || {};
if (isUndefined(opts.separator)) {
opts.separator = '_';
}
return toQueryString(obj, opts.deep, opts.transform, opts.prefix || '', opts.separator);
} | [
"function",
"toQueryStringWithOptions",
"(",
"obj",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"isUndefined",
"(",
"opts",
".",
"separator",
")",
")",
"{",
"opts",
".",
"separator",
"=",
"'_'",
";",
"}",
"return",
"to... | Query Strings | Creating | [
"Query",
"Strings",
"|",
"Creating"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/object.js#L36-L42 | train |
andrewplummer/Sugar | lib/object.js | fromQueryStringWithOptions | function fromQueryStringWithOptions(obj, opts) {
var str = String(obj || '').replace(/^.*?\?/, ''), result = {}, auto;
opts = opts || {};
if (str) {
forEach(str.split('&'), function(p) {
var split = p.split('=');
var key = decodeURIComponent(split[0]);
var val = split.length === 2 ? decodeUR... | javascript | function fromQueryStringWithOptions(obj, opts) {
var str = String(obj || '').replace(/^.*?\?/, ''), result = {}, auto;
opts = opts || {};
if (str) {
forEach(str.split('&'), function(p) {
var split = p.split('=');
var key = decodeURIComponent(split[0]);
var val = split.length === 2 ? decodeUR... | [
"function",
"fromQueryStringWithOptions",
"(",
"obj",
",",
"opts",
")",
"{",
"var",
"str",
"=",
"String",
"(",
"obj",
"||",
"''",
")",
".",
"replace",
"(",
"/",
"^.*?\\?",
"/",
",",
"''",
")",
",",
"result",
"=",
"{",
"}",
",",
"auto",
";",
"opts",... | Query Strings | Parsing | [
"Query",
"Strings",
"|",
"Parsing"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/object.js#L111-L124 | train |
andrewplummer/Sugar | lib/object.js | iterateOverKeys | function iterateOverKeys(getFn, obj, fn, hidden) {
var keys = getFn(obj), desc;
for (var i = 0, key; key = keys[i]; i++) {
desc = getOwnPropertyDescriptor(obj, key);
if (desc.enumerable || hidden) {
fn(obj[key], key);
}
}
} | javascript | function iterateOverKeys(getFn, obj, fn, hidden) {
var keys = getFn(obj), desc;
for (var i = 0, key; key = keys[i]; i++) {
desc = getOwnPropertyDescriptor(obj, key);
if (desc.enumerable || hidden) {
fn(obj[key], key);
}
}
} | [
"function",
"iterateOverKeys",
"(",
"getFn",
",",
"obj",
",",
"fn",
",",
"hidden",
")",
"{",
"var",
"keys",
"=",
"getFn",
"(",
"obj",
")",
",",
"desc",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"key",
";",
"key",
"=",
"keys",
"[",
"i",
"]",
... | "keys" may include symbols | [
"keys",
"may",
"include",
"symbols"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/object.js#L232-L240 | train |
andrewplummer/Sugar | lib/function.js | collectArguments | function collectArguments() {
var args = arguments, i = args.length, arr = new Array(i);
while (i--) {
arr[i] = args[i];
}
return arr;
} | javascript | function collectArguments() {
var args = arguments, i = args.length, arr = new Array(i);
while (i--) {
arr[i] = args[i];
}
return arr;
} | [
"function",
"collectArguments",
"(",
")",
"{",
"var",
"args",
"=",
"arguments",
",",
"i",
"=",
"args",
".",
"length",
",",
"arr",
"=",
"new",
"Array",
"(",
"i",
")",
";",
"while",
"(",
"i",
"--",
")",
"{",
"arr",
"[",
"i",
"]",
"=",
"args",
"["... | Collecting arguments in an array instead of passing back the arguments object which will deopt this function in V8. | [
"Collecting",
"arguments",
"in",
"an",
"array",
"instead",
"of",
"passing",
"back",
"the",
"arguments",
"object",
"which",
"will",
"deopt",
"this",
"function",
"in",
"V8",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/function.js#L97-L103 | train |
andrewplummer/Sugar | gulpfile.js | getSplitModule | function getSplitModule(content, constraints) {
var src = '', lastIdx = 0, currentNamespace;
content.replace(/\/\*\*\* @namespace (\w+) \*\*\*\/\n|$/g, function(match, nextNamespace, idx) {
if (!currentNamespace || constraints[currentNamespace]) {
src += content.slice(lastIdx, idx);
}
... | javascript | function getSplitModule(content, constraints) {
var src = '', lastIdx = 0, currentNamespace;
content.replace(/\/\*\*\* @namespace (\w+) \*\*\*\/\n|$/g, function(match, nextNamespace, idx) {
if (!currentNamespace || constraints[currentNamespace]) {
src += content.slice(lastIdx, idx);
}
... | [
"function",
"getSplitModule",
"(",
"content",
",",
"constraints",
")",
"{",
"var",
"src",
"=",
"''",
",",
"lastIdx",
"=",
"0",
",",
"currentNamespace",
";",
"content",
".",
"replace",
"(",
"/",
"\\/\\*\\*\\* @namespace (\\w+) \\*\\*\\*\\/\\n|$",
"/",
"g",
",",
... | Split the module into namespaces here and match on the allowed one. | [
"Split",
"the",
"module",
"into",
"namespaces",
"here",
"and",
"match",
"on",
"the",
"allowed",
"one",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L632-L642 | train |
andrewplummer/Sugar | gulpfile.js | addFixes | function addFixes() {
var match = fnPackage.name.match(/^build(\w+)Fix$/);
if (match) {
addSugarFix(match[1], fnPackage);
fnPackage.dependencies.push(fnCallName);
fnPackage.postAssigns = findVarAssignments(fnPackage.node.body.body, true);
}
} | javascript | function addFixes() {
var match = fnPackage.name.match(/^build(\w+)Fix$/);
if (match) {
addSugarFix(match[1], fnPackage);
fnPackage.dependencies.push(fnCallName);
fnPackage.postAssigns = findVarAssignments(fnPackage.node.body.body, true);
}
} | [
"function",
"addFixes",
"(",
")",
"{",
"var",
"match",
"=",
"fnPackage",
".",
"name",
".",
"match",
"(",
"/",
"^build(\\w+)Fix$",
"/",
")",
";",
"if",
"(",
"match",
")",
"{",
"addSugarFix",
"(",
"match",
"[",
"1",
"]",
",",
"fnPackage",
")",
";",
"... | Fixes are special types of build methods that fix broken behavior but are not polyfills or attached to a specific method, so need to be handled differently. | [
"Fixes",
"are",
"special",
"types",
"of",
"build",
"methods",
"that",
"fix",
"broken",
"behavior",
"but",
"are",
"not",
"polyfills",
"or",
"attached",
"to",
"a",
"specific",
"method",
"so",
"need",
"to",
"be",
"handled",
"differently",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L1886-L1893 | train |
andrewplummer/Sugar | gulpfile.js | transposeDependencies | function transposeDependencies() {
sourcePackages.forEach(function(p) {
if (p.name === fnCallName) {
// Do not transpose the call package itself. After this loop
// there should be only one dependency on the build function anymore.
return;
}
var ... | javascript | function transposeDependencies() {
sourcePackages.forEach(function(p) {
if (p.name === fnCallName) {
// Do not transpose the call package itself. After this loop
// there should be only one dependency on the build function anymore.
return;
}
var ... | [
"function",
"transposeDependencies",
"(",
")",
"{",
"sourcePackages",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"p",
".",
"name",
"===",
"fnCallName",
")",
"{",
"// Do not transpose the call package itself. After this loop",
"// there should be o... | Step through all source packages and transpose dependencies on the build function to be dependent on the function call instead, ensuring that the function is finally called. Although we could simply push the call body into the build package, this way allows the source to be faithfully rebuilt no matter where the build ... | [
"Step",
"through",
"all",
"source",
"packages",
"and",
"transpose",
"dependencies",
"on",
"the",
"build",
"function",
"to",
"be",
"dependent",
"on",
"the",
"function",
"call",
"instead",
"ensuring",
"that",
"the",
"function",
"is",
"finally",
"called",
".",
"A... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L1900-L1912 | train |
andrewplummer/Sugar | gulpfile.js | transposeVarDependencies | function transposeVarDependencies() {
var map = {};
sourcePackages.forEach(function(p) {
if (p.vars) {
p.vars.forEach(function(v) {
map[v] = p.name;
});
}
});
sourcePackages.forEach(function(p) {
var deps = [];
var varDeps = [];
p.dependencies.forE... | javascript | function transposeVarDependencies() {
var map = {};
sourcePackages.forEach(function(p) {
if (p.vars) {
p.vars.forEach(function(v) {
map[v] = p.name;
});
}
});
sourcePackages.forEach(function(p) {
var deps = [];
var varDeps = [];
p.dependencies.forE... | [
"function",
"transposeVarDependencies",
"(",
")",
"{",
"var",
"map",
"=",
"{",
"}",
";",
"sourcePackages",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"if",
"(",
"p",
".",
"vars",
")",
"{",
"p",
".",
"vars",
".",
"forEach",
"(",
"function",
... | Find packages depending on specific vars and transpose the dependency to the bundled var package instead. However keep the references as "varDependencies" for later consumption. | [
"Find",
"packages",
"depending",
"on",
"specific",
"vars",
"and",
"transpose",
"the",
"dependency",
"to",
"the",
"bundled",
"var",
"package",
"instead",
".",
"However",
"keep",
"the",
"references",
"as",
"varDependencies",
"for",
"later",
"consumption",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L2096-L2122 | train |
andrewplummer/Sugar | gulpfile.js | getDirectRequires | function getDirectRequires(p) {
return p.dependencies.filter(function(d) {
return DIRECT_REQUIRES_REG.test(d);
}).map(function(d) {
return "require('"+ getDependencyPath(d, p) +"');";
}).join('\n');
} | javascript | function getDirectRequires(p) {
return p.dependencies.filter(function(d) {
return DIRECT_REQUIRES_REG.test(d);
}).map(function(d) {
return "require('"+ getDependencyPath(d, p) +"');";
}).join('\n');
} | [
"function",
"getDirectRequires",
"(",
"p",
")",
"{",
"return",
"p",
".",
"dependencies",
".",
"filter",
"(",
"function",
"(",
"d",
")",
"{",
"return",
"DIRECT_REQUIRES_REG",
".",
"test",
"(",
"d",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
... | Any build method calls don't require a reference and can be simply required directly, so output them here. | [
"Any",
"build",
"method",
"calls",
"don",
"t",
"require",
"a",
"reference",
"and",
"can",
"be",
"simply",
"required",
"directly",
"so",
"output",
"them",
"here",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L2544-L2550 | train |
andrewplummer/Sugar | gulpfile.js | bundleCircularDependencies | function bundleCircularDependencies() {
function findCircular(deps, chain) {
for (var i = 0, startIndex, c, p; i < deps.length; i++) {
// Only top level dependencies will be included in the chain.
p = sourcePackages.findByDependencyName(deps[i]);
if (!p) {
continue;
... | javascript | function bundleCircularDependencies() {
function findCircular(deps, chain) {
for (var i = 0, startIndex, c, p; i < deps.length; i++) {
// Only top level dependencies will be included in the chain.
p = sourcePackages.findByDependencyName(deps[i]);
if (!p) {
continue;
... | [
"function",
"bundleCircularDependencies",
"(",
")",
"{",
"function",
"findCircular",
"(",
"deps",
",",
"chain",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"startIndex",
",",
"c",
",",
"p",
";",
"i",
"<",
"deps",
".",
"length",
";",
"i",
"++",
... | Circular dependencies are not necessarily a problem for Javascript at execution time due to having different code paths, however they don't work for npm packages, so they must be bundled together. This isn't too fancy so more complicated dependencies should be refactored. First in the source will be the target package ... | [
"Circular",
"dependencies",
"are",
"not",
"necessarily",
"a",
"problem",
"for",
"Javascript",
"at",
"execution",
"time",
"due",
"to",
"having",
"different",
"code",
"paths",
"however",
"they",
"don",
"t",
"work",
"for",
"npm",
"packages",
"so",
"they",
"must",... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L2714-L2831 | train |
andrewplummer/Sugar | gulpfile.js | bundleArray | function bundleArray(target, src, name, notSelf) {
var srcValues, targetValues;
if (src[name]) {
srcValues = src[name] || [];
targetValues = target[name] || [];
target[name] = uniq(targetValues.concat(srcValues.filter(function(d) {
return !notSelf || d !== target.name;
... | javascript | function bundleArray(target, src, name, notSelf) {
var srcValues, targetValues;
if (src[name]) {
srcValues = src[name] || [];
targetValues = target[name] || [];
target[name] = uniq(targetValues.concat(srcValues.filter(function(d) {
return !notSelf || d !== target.name;
... | [
"function",
"bundleArray",
"(",
"target",
",",
"src",
",",
"name",
",",
"notSelf",
")",
"{",
"var",
"srcValues",
",",
"targetValues",
";",
"if",
"(",
"src",
"[",
"name",
"]",
")",
"{",
"srcValues",
"=",
"src",
"[",
"name",
"]",
"||",
"[",
"]",
";",... | Bundle all dependencies from the source into the target, but only after removing the circular dependency itself. | [
"Bundle",
"all",
"dependencies",
"from",
"the",
"source",
"into",
"the",
"target",
"but",
"only",
"after",
"removing",
"the",
"circular",
"dependency",
"itself",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L2780-L2789 | train |
andrewplummer/Sugar | gulpfile.js | updateExternalDependencies | function updateExternalDependencies(oldName, newName) {
sourcePackages.forEach(function(p) {
var index = p.dependencies.indexOf(oldName);
if (index !== -1) {
if (p.name === newName || p.dependencies.indexOf(newName) !== -1) {
// If the package has the same name as the one we ... | javascript | function updateExternalDependencies(oldName, newName) {
sourcePackages.forEach(function(p) {
var index = p.dependencies.indexOf(oldName);
if (index !== -1) {
if (p.name === newName || p.dependencies.indexOf(newName) !== -1) {
// If the package has the same name as the one we ... | [
"function",
"updateExternalDependencies",
"(",
"oldName",
",",
"newName",
")",
"{",
"sourcePackages",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"var",
"index",
"=",
"p",
".",
"dependencies",
".",
"indexOf",
"(",
"oldName",
")",
";",
"if",
"(",
... | Update all packages pointing to the old package. | [
"Update",
"all",
"packages",
"pointing",
"to",
"the",
"old",
"package",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L2799-L2818 | train |
andrewplummer/Sugar | gulpfile.js | unpackMethodSets | function unpackMethodSets(methods) {
var result = [];
methods.forEach(function(method) {
if (method.set) {
method.set.forEach(function(name) {
var setMethod = clone(method);
setMethod.name = name;
result.push(setMethod);
});
} else {
result.push... | javascript | function unpackMethodSets(methods) {
var result = [];
methods.forEach(function(method) {
if (method.set) {
method.set.forEach(function(name) {
var setMethod = clone(method);
setMethod.name = name;
result.push(setMethod);
});
} else {
result.push... | [
"function",
"unpackMethodSets",
"(",
"methods",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"methods",
".",
"forEach",
"(",
"function",
"(",
"method",
")",
"{",
"if",
"(",
"method",
".",
"set",
")",
"{",
"method",
".",
"set",
".",
"forEach",
"(",
... | Expands method sets and merges declaration supplements. | [
"Expands",
"method",
"sets",
"and",
"merges",
"declaration",
"supplements",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L4328-L4343 | train |
andrewplummer/Sugar | gulpfile.js | getAlternateTypes | function getAlternateTypes(method) {
var types = [];
function process(arr) {
if (arr) {
arr.forEach(function(obj) {
if (obj.type) {
var split = obj.type.split('|');
if (split.length > 1) {
types = type... | javascript | function getAlternateTypes(method) {
var types = [];
function process(arr) {
if (arr) {
arr.forEach(function(obj) {
if (obj.type) {
var split = obj.type.split('|');
if (split.length > 1) {
types = type... | [
"function",
"getAlternateTypes",
"(",
"method",
")",
"{",
"var",
"types",
"=",
"[",
"]",
";",
"function",
"process",
"(",
"arr",
")",
"{",
"if",
"(",
"arr",
")",
"{",
"arr",
".",
"forEach",
"(",
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
... | If the param has multiple types, then move callbacks into the module as named types. Only do this if there are multiple types, otherwise the callback signature can be inlined into the method declaration. | [
"If",
"the",
"param",
"has",
"multiple",
"types",
"then",
"move",
"callbacks",
"into",
"the",
"module",
"as",
"named",
"types",
".",
"Only",
"do",
"this",
"if",
"there",
"are",
"multiple",
"types",
"otherwise",
"the",
"callback",
"signature",
"can",
"be",
... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/gulpfile.js#L4447-L4467 | train |
andrewplummer/Sugar | lib/date.js | callDateSetWithWeek | function callDateSetWithWeek(d, method, value, safe) {
if (method === 'ISOWeek') {
setISOWeekNumber(d, value);
} else {
callDateSet(d, method, value, safe);
}
} | javascript | function callDateSetWithWeek(d, method, value, safe) {
if (method === 'ISOWeek') {
setISOWeekNumber(d, value);
} else {
callDateSet(d, method, value, safe);
}
} | [
"function",
"callDateSetWithWeek",
"(",
"d",
",",
"method",
",",
"value",
",",
"safe",
")",
"{",
"if",
"(",
"method",
"===",
"'ISOWeek'",
")",
"{",
"setISOWeekNumber",
"(",
"d",
",",
"value",
")",
";",
"}",
"else",
"{",
"callDateSet",
"(",
"d",
",",
... | Normal callDateSet method with ability to handle ISOWeek setting as well. | [
"Normal",
"callDateSet",
"method",
"with",
"ability",
"to",
"handle",
"ISOWeek",
"setting",
"as",
"well",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L677-L683 | train |
andrewplummer/Sugar | lib/date.js | iterateOverDateUnits | function iterateOverDateUnits(fn, startIndex, endIndex) {
endIndex = endIndex || 0;
if (isUndefined(startIndex)) {
startIndex = YEAR_INDEX;
}
for (var index = startIndex; index >= endIndex; index--) {
if (fn(DateUnits[index], index) === false) {
break;
}
}
} | javascript | function iterateOverDateUnits(fn, startIndex, endIndex) {
endIndex = endIndex || 0;
if (isUndefined(startIndex)) {
startIndex = YEAR_INDEX;
}
for (var index = startIndex; index >= endIndex; index--) {
if (fn(DateUnits[index], index) === false) {
break;
}
}
} | [
"function",
"iterateOverDateUnits",
"(",
"fn",
",",
"startIndex",
",",
"endIndex",
")",
"{",
"endIndex",
"=",
"endIndex",
"||",
"0",
";",
"if",
"(",
"isUndefined",
"(",
"startIndex",
")",
")",
"{",
"startIndex",
"=",
"YEAR_INDEX",
";",
"}",
"for",
"(",
"... | Iteration helpers Years -> Milliseconds | [
"Iteration",
"helpers",
"Years",
"-",
">",
"Milliseconds"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L746-L756 | train |
andrewplummer/Sugar | lib/date.js | iterateOverDateParams | function iterateOverDateParams(params, fn, startIndex, endIndex) {
function run(name, unit, i) {
var val = getDateParam(params, name);
if (isDefined(val)) {
fn(name, val, unit, i);
}
}
iterateOverDateUnits(function (unit, i) {
var result = run(unit.name, unit, i);
if (result !== false ... | javascript | function iterateOverDateParams(params, fn, startIndex, endIndex) {
function run(name, unit, i) {
var val = getDateParam(params, name);
if (isDefined(val)) {
fn(name, val, unit, i);
}
}
iterateOverDateUnits(function (unit, i) {
var result = run(unit.name, unit, i);
if (result !== false ... | [
"function",
"iterateOverDateParams",
"(",
"params",
",",
"fn",
",",
"startIndex",
",",
"endIndex",
")",
"{",
"function",
"run",
"(",
"name",
",",
"unit",
",",
"i",
")",
"{",
"var",
"val",
"=",
"getDateParam",
"(",
"params",
",",
"name",
")",
";",
"if",... | Years -> Milliseconds checking all date params including "weekday" | [
"Years",
"-",
">",
"Milliseconds",
"checking",
"all",
"date",
"params",
"including",
"weekday"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L784-L804 | train |
andrewplummer/Sugar | lib/date.js | setISOWeekNumber | function setISOWeekNumber(d, num) {
if (isNumber(num)) {
// Intentionally avoiding updateDate here to prevent circular dependencies.
var isoWeek = cloneDate(d), dow = getWeekday(d);
moveToFirstDayOfWeekYear(isoWeek, ISO_FIRST_DAY_OF_WEEK, ISO_FIRST_DAY_OF_WEEK_YEAR);
setDate(isoWeek, getDate(isoWeek) ... | javascript | function setISOWeekNumber(d, num) {
if (isNumber(num)) {
// Intentionally avoiding updateDate here to prevent circular dependencies.
var isoWeek = cloneDate(d), dow = getWeekday(d);
moveToFirstDayOfWeekYear(isoWeek, ISO_FIRST_DAY_OF_WEEK, ISO_FIRST_DAY_OF_WEEK_YEAR);
setDate(isoWeek, getDate(isoWeek) ... | [
"function",
"setISOWeekNumber",
"(",
"d",
",",
"num",
")",
"{",
"if",
"(",
"isNumber",
"(",
"num",
")",
")",
"{",
"// Intentionally avoiding updateDate here to prevent circular dependencies.",
"var",
"isoWeek",
"=",
"cloneDate",
"(",
"d",
")",
",",
"dow",
"=",
"... | Week number helpers | [
"Week",
"number",
"helpers"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L959-L971 | train |
andrewplummer/Sugar | lib/date.js | getWeekYear | function getWeekYear(d, localeCode, iso) {
var year, month, firstDayOfWeek, firstDayOfWeekYear, week, loc;
year = getYear(d);
month = getMonth(d);
if (month === 0 || month === 11) {
if (!iso) {
loc = localeManager.get(localeCode);
firstDayOfWeek = loc.getFirstDayOfWeek(localeCode);
firstDa... | javascript | function getWeekYear(d, localeCode, iso) {
var year, month, firstDayOfWeek, firstDayOfWeekYear, week, loc;
year = getYear(d);
month = getMonth(d);
if (month === 0 || month === 11) {
if (!iso) {
loc = localeManager.get(localeCode);
firstDayOfWeek = loc.getFirstDayOfWeek(localeCode);
firstDa... | [
"function",
"getWeekYear",
"(",
"d",
",",
"localeCode",
",",
"iso",
")",
"{",
"var",
"year",
",",
"month",
",",
"firstDayOfWeek",
",",
"firstDayOfWeekYear",
",",
"week",
",",
"loc",
";",
"year",
"=",
"getYear",
"(",
"d",
")",
";",
"month",
"=",
"getMon... | Week year helpers | [
"Week",
"year",
"helpers"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L1002-L1020 | train |
andrewplummer/Sugar | lib/date.js | getAdjustedUnit | function getAdjustedUnit(ms, fn) {
var unitIndex = 0, value = 0;
iterateOverDateUnits(function(unit, i) {
value = abs(fn(unit));
if (value >= 1) {
unitIndex = i;
return false;
}
});
return [value, unitIndex, ms];
} | javascript | function getAdjustedUnit(ms, fn) {
var unitIndex = 0, value = 0;
iterateOverDateUnits(function(unit, i) {
value = abs(fn(unit));
if (value >= 1) {
unitIndex = i;
return false;
}
});
return [value, unitIndex, ms];
} | [
"function",
"getAdjustedUnit",
"(",
"ms",
",",
"fn",
")",
"{",
"var",
"unitIndex",
"=",
"0",
",",
"value",
"=",
"0",
";",
"iterateOverDateUnits",
"(",
"function",
"(",
"unit",
",",
"i",
")",
"{",
"value",
"=",
"abs",
"(",
"fn",
"(",
"unit",
")",
")... | Gets an "adjusted date unit" which is a way of representing the largest possible meaningful unit. In other words, if passed 3600000, this will return an array which represents "1 hour". | [
"Gets",
"an",
"adjusted",
"date",
"unit",
"which",
"is",
"a",
"way",
"of",
"representing",
"the",
"largest",
"possible",
"meaningful",
"unit",
".",
"In",
"other",
"words",
"if",
"passed",
"3600000",
"this",
"will",
"return",
"an",
"array",
"which",
"represen... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L1065-L1075 | train |
andrewplummer/Sugar | lib/date.js | getAdjustedUnitForNumber | function getAdjustedUnitForNumber(ms) {
return getAdjustedUnit(ms, function(unit) {
return trunc(withPrecision(ms / unit.multiplier, 1));
});
} | javascript | function getAdjustedUnitForNumber(ms) {
return getAdjustedUnit(ms, function(unit) {
return trunc(withPrecision(ms / unit.multiplier, 1));
});
} | [
"function",
"getAdjustedUnitForNumber",
"(",
"ms",
")",
"{",
"return",
"getAdjustedUnit",
"(",
"ms",
",",
"function",
"(",
"unit",
")",
"{",
"return",
"trunc",
"(",
"withPrecision",
"(",
"ms",
"/",
"unit",
".",
"multiplier",
",",
"1",
")",
")",
";",
"}",... | Gets the adjusted unit based on simple division by date unit multiplier. | [
"Gets",
"the",
"adjusted",
"unit",
"based",
"on",
"simple",
"division",
"by",
"date",
"unit",
"multiplier",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L1079-L1083 | train |
andrewplummer/Sugar | lib/date.js | cloneDateByFlag | function cloneDateByFlag(d, clone) {
if (_utc(d) && !isDefined(optFromUTC)) {
optFromUTC = true;
}
if (_utc(d) && !isDefined(optSetUTC)) {
optSetUTC = true;
}
if (clone) {
d = new Date(d.getTime());
}
return d;
} | javascript | function cloneDateByFlag(d, clone) {
if (_utc(d) && !isDefined(optFromUTC)) {
optFromUTC = true;
}
if (_utc(d) && !isDefined(optSetUTC)) {
optSetUTC = true;
}
if (clone) {
d = new Date(d.getTime());
}
return d;
} | [
"function",
"cloneDateByFlag",
"(",
"d",
",",
"clone",
")",
"{",
"if",
"(",
"_utc",
"(",
"d",
")",
"&&",
"!",
"isDefined",
"(",
"optFromUTC",
")",
")",
"{",
"optFromUTC",
"=",
"true",
";",
"}",
"if",
"(",
"_utc",
"(",
"d",
")",
"&&",
"!",
"isDefi... | Force the UTC flags to be true if the source date date is UTC, as they will be overwritten later. | [
"Force",
"the",
"UTC",
"flags",
"to",
"be",
"true",
"if",
"the",
"source",
"date",
"date",
"is",
"UTC",
"as",
"they",
"will",
"be",
"overwritten",
"later",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/date.js#L1416-L1427 | train |
andrewplummer/Sugar | lib/array.js | arraySafeConcat | function arraySafeConcat(arr, arg) {
var result = arrayClone(arr), len = result.length, arr2;
arr2 = isArray(arg) ? arg : [arg];
result.length += arr2.length;
forEach(arr2, function(el, i) {
result[len + i] = el;
});
return result;
} | javascript | function arraySafeConcat(arr, arg) {
var result = arrayClone(arr), len = result.length, arr2;
arr2 = isArray(arg) ? arg : [arg];
result.length += arr2.length;
forEach(arr2, function(el, i) {
result[len + i] = el;
});
return result;
} | [
"function",
"arraySafeConcat",
"(",
"arr",
",",
"arg",
")",
"{",
"var",
"result",
"=",
"arrayClone",
"(",
"arr",
")",
",",
"len",
"=",
"result",
".",
"length",
",",
"arr2",
";",
"arr2",
"=",
"isArray",
"(",
"arg",
")",
"?",
"arg",
":",
"[",
"arg",
... | Avoids issues with concat in < IE8 istanbul ignore next | [
"Avoids",
"issues",
"with",
"concat",
"in",
"<",
"IE8",
"istanbul",
"ignore",
"next"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/array.js#L142-L150 | train |
andrewplummer/Sugar | lib/string.js | runGlobalMatch | function runGlobalMatch(str, reg) {
var result = [], match, lastLastIndex;
while ((match = reg.exec(str)) != null) {
if (reg.lastIndex === lastLastIndex) {
reg.lastIndex += 1;
} else {
result.push(match[0]);
}
lastLastIndex = reg.lastIndex;
}
return result;
} | javascript | function runGlobalMatch(str, reg) {
var result = [], match, lastLastIndex;
while ((match = reg.exec(str)) != null) {
if (reg.lastIndex === lastLastIndex) {
reg.lastIndex += 1;
} else {
result.push(match[0]);
}
lastLastIndex = reg.lastIndex;
}
return result;
} | [
"function",
"runGlobalMatch",
"(",
"str",
",",
"reg",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"match",
",",
"lastLastIndex",
";",
"while",
"(",
"(",
"match",
"=",
"reg",
".",
"exec",
"(",
"str",
")",
")",
"!=",
"null",
")",
"{",
"if",
"(",... | "match" in < IE9 has enumable properties that will confuse for..in loops, so ensure that the match is a normal array by manually running "exec". Note that this method is also slightly more performant. | [
"match",
"in",
"<",
"IE9",
"has",
"enumable",
"properties",
"that",
"will",
"confuse",
"for",
"..",
"in",
"loops",
"so",
"ensure",
"that",
"the",
"match",
"is",
"a",
"normal",
"array",
"by",
"manually",
"running",
"exec",
".",
"Note",
"that",
"this",
"me... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/string.js#L124-L135 | train |
andrewplummer/Sugar | lib/enumerable.js | sliceArrayFromRight | function sliceArrayFromRight(arr, startIndex, loop) {
if (!loop) {
startIndex += 1;
arr = arr.slice(0, max(0, startIndex));
}
return arr;
} | javascript | function sliceArrayFromRight(arr, startIndex, loop) {
if (!loop) {
startIndex += 1;
arr = arr.slice(0, max(0, startIndex));
}
return arr;
} | [
"function",
"sliceArrayFromRight",
"(",
"arr",
",",
"startIndex",
",",
"loop",
")",
"{",
"if",
"(",
"!",
"loop",
")",
"{",
"startIndex",
"+=",
"1",
";",
"arr",
"=",
"arr",
".",
"slice",
"(",
"0",
",",
"max",
"(",
"0",
",",
"startIndex",
")",
")",
... | When iterating from the right, indexes are effectively shifted by 1. For example, iterating from the right from index 2 in an array of 3 should also include the last element in the array. This matches the "lastIndexOf" method which also iterates from the right. | [
"When",
"iterating",
"from",
"the",
"right",
"indexes",
"are",
"effectively",
"shifted",
"by",
"1",
".",
"For",
"example",
"iterating",
"from",
"the",
"right",
"from",
"index",
"2",
"in",
"an",
"array",
"of",
"3",
"should",
"also",
"include",
"the",
"last"... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/enumerable.js#L304-L310 | train |
andrewplummer/Sugar | lib/common.js | defineOnPrototype | function defineOnPrototype(ctor, methods) {
var proto = ctor.prototype;
forEachProperty(methods, function(val, key) {
proto[key] = val;
});
} | javascript | function defineOnPrototype(ctor, methods) {
var proto = ctor.prototype;
forEachProperty(methods, function(val, key) {
proto[key] = val;
});
} | [
"function",
"defineOnPrototype",
"(",
"ctor",
",",
"methods",
")",
"{",
"var",
"proto",
"=",
"ctor",
".",
"prototype",
";",
"forEachProperty",
"(",
"methods",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"proto",
"[",
"key",
"]",
"=",
"val",
";",... | For methods defined directly on the prototype like Range | [
"For",
"methods",
"defined",
"directly",
"on",
"the",
"prototype",
"like",
"Range"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L268-L273 | train |
andrewplummer/Sugar | lib/common.js | coercePositiveInteger | function coercePositiveInteger(n) {
n = +n || 0;
if (n < 0 || !isNumber(n) || !isFinite(n)) {
throw new RangeError('Invalid number');
}
return trunc(n);
} | javascript | function coercePositiveInteger(n) {
n = +n || 0;
if (n < 0 || !isNumber(n) || !isFinite(n)) {
throw new RangeError('Invalid number');
}
return trunc(n);
} | [
"function",
"coercePositiveInteger",
"(",
"n",
")",
"{",
"n",
"=",
"+",
"n",
"||",
"0",
";",
"if",
"(",
"n",
"<",
"0",
"||",
"!",
"isNumber",
"(",
"n",
")",
"||",
"!",
"isFinite",
"(",
"n",
")",
")",
"{",
"throw",
"new",
"RangeError",
"(",
"'In... | Coerces an object to a positive integer. Does not allow Infinity. | [
"Coerces",
"an",
"object",
"to",
"a",
"positive",
"integer",
".",
"Does",
"not",
"allow",
"Infinity",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L307-L313 | train |
andrewplummer/Sugar | lib/common.js | getMatcher | function getMatcher(f) {
if (!isPrimitive(f)) {
var className = classToString(f);
if (isRegExp(f, className)) {
return regexMatcher(f);
} else if (isDate(f, className)) {
return dateMatcher(f);
} else if (isFunction(f, className)) {
return functionMatcher(f);
} else if (isPlainOb... | javascript | function getMatcher(f) {
if (!isPrimitive(f)) {
var className = classToString(f);
if (isRegExp(f, className)) {
return regexMatcher(f);
} else if (isDate(f, className)) {
return dateMatcher(f);
} else if (isFunction(f, className)) {
return functionMatcher(f);
} else if (isPlainOb... | [
"function",
"getMatcher",
"(",
"f",
")",
"{",
"if",
"(",
"!",
"isPrimitive",
"(",
"f",
")",
")",
"{",
"var",
"className",
"=",
"classToString",
"(",
"f",
")",
";",
"if",
"(",
"isRegExp",
"(",
"f",
",",
"className",
")",
")",
"{",
"return",
"regexMa... | Fuzzy matching helpers | [
"Fuzzy",
"matching",
"helpers"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L345-L360 | train |
andrewplummer/Sugar | lib/common.js | handleArrayIndexRange | function handleArrayIndexRange(obj, key, any, val) {
var match, start, end, leading, trailing, arr, set;
match = key.match(PROPERTY_RANGE_REG);
if (!match) {
return;
}
set = isDefined(val);
leading = match[1];
if (leading) {
arr = handleDeepProperty(obj, leading, any, false, set ? true : false, ... | javascript | function handleArrayIndexRange(obj, key, any, val) {
var match, start, end, leading, trailing, arr, set;
match = key.match(PROPERTY_RANGE_REG);
if (!match) {
return;
}
set = isDefined(val);
leading = match[1];
if (leading) {
arr = handleDeepProperty(obj, leading, any, false, set ? true : false, ... | [
"function",
"handleArrayIndexRange",
"(",
"obj",
",",
"key",
",",
"any",
",",
"val",
")",
"{",
"var",
"match",
",",
"start",
",",
"end",
",",
"leading",
",",
"trailing",
",",
"arr",
",",
"set",
";",
"match",
"=",
"key",
".",
"match",
"(",
"PROPERTY_R... | Get object property with support for 0..1 style range notation. | [
"Get",
"object",
"property",
"with",
"support",
"for",
"0",
"..",
"1",
"style",
"range",
"notation",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L519-L569 | train |
andrewplummer/Sugar | lib/common.js | coercePrimitiveToObject | function coercePrimitiveToObject(obj) {
if (isPrimitive(obj)) {
obj = Object(obj);
}
// istanbul ignore next
if (NO_KEYS_IN_STRING_OBJECTS && isString(obj)) {
forceStringCoercion(obj);
}
return obj;
} | javascript | function coercePrimitiveToObject(obj) {
if (isPrimitive(obj)) {
obj = Object(obj);
}
// istanbul ignore next
if (NO_KEYS_IN_STRING_OBJECTS && isString(obj)) {
forceStringCoercion(obj);
}
return obj;
} | [
"function",
"coercePrimitiveToObject",
"(",
"obj",
")",
"{",
"if",
"(",
"isPrimitive",
"(",
"obj",
")",
")",
"{",
"obj",
"=",
"Object",
"(",
"obj",
")",
";",
"}",
"// istanbul ignore next",
"if",
"(",
"NO_KEYS_IN_STRING_OBJECTS",
"&&",
"isString",
"(",
"obj"... | Make primtives types like strings into objects. | [
"Make",
"primtives",
"types",
"like",
"strings",
"into",
"objects",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L647-L656 | train |
andrewplummer/Sugar | lib/common.js | forceStringCoercion | function forceStringCoercion(obj) {
var i = 0, chr;
while (chr = obj.charAt(i)) {
obj[i++] = chr;
}
} | javascript | function forceStringCoercion(obj) {
var i = 0, chr;
while (chr = obj.charAt(i)) {
obj[i++] = chr;
}
} | [
"function",
"forceStringCoercion",
"(",
"obj",
")",
"{",
"var",
"i",
"=",
"0",
",",
"chr",
";",
"while",
"(",
"chr",
"=",
"obj",
".",
"charAt",
"(",
"i",
")",
")",
"{",
"obj",
"[",
"i",
"++",
"]",
"=",
"chr",
";",
"}",
"}"
] | Force strings to have their indexes set in environments that don't do this automatically. istanbul ignore next | [
"Force",
"strings",
"to",
"have",
"their",
"indexes",
"set",
"in",
"environments",
"that",
"don",
"t",
"do",
"this",
"automatically",
".",
"istanbul",
"ignore",
"next"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L661-L666 | train |
andrewplummer/Sugar | lib/common.js | isEqual | function isEqual(a, b, stack) {
var aClass, bClass;
if (a === b) {
// Return quickly up front when matched by reference,
// but be careful about 0 !== -0.
return a !== 0 || 1 / a === 1 / b;
}
aClass = classToString(a);
bClass = classToString(b);
if (aClass !== bClass) {
return false;
}
... | javascript | function isEqual(a, b, stack) {
var aClass, bClass;
if (a === b) {
// Return quickly up front when matched by reference,
// but be careful about 0 !== -0.
return a !== 0 || 1 / a === 1 / b;
}
aClass = classToString(a);
bClass = classToString(b);
if (aClass !== bClass) {
return false;
}
... | [
"function",
"isEqual",
"(",
"a",
",",
"b",
",",
"stack",
")",
"{",
"var",
"aClass",
",",
"bClass",
";",
"if",
"(",
"a",
"===",
"b",
")",
"{",
"// Return quickly up front when matched by reference,",
"// but be careful about 0 !== -0.",
"return",
"a",
"!==",
"0",... | Equality helpers Perf | [
"Equality",
"helpers",
"Perf"
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L671-L695 | train |
andrewplummer/Sugar | lib/common.js | serializeInternal | function serializeInternal(obj, refs, stack) {
var type = typeof obj, sign = '', className, value, ref;
// Return up front on
if (1 / obj === -Infinity) {
sign = '-';
}
// Return quickly for primitives to save cycles
if (isPrimitive(obj, type) && !isRealNaN(obj)) {
return type + sign + obj;
}
... | javascript | function serializeInternal(obj, refs, stack) {
var type = typeof obj, sign = '', className, value, ref;
// Return up front on
if (1 / obj === -Infinity) {
sign = '-';
}
// Return quickly for primitives to save cycles
if (isPrimitive(obj, type) && !isRealNaN(obj)) {
return type + sign + obj;
}
... | [
"function",
"serializeInternal",
"(",
"obj",
",",
"refs",
",",
"stack",
")",
"{",
"var",
"type",
"=",
"typeof",
"obj",
",",
"sign",
"=",
"''",
",",
"className",
",",
"value",
",",
"ref",
";",
"// Return up front on",
"if",
"(",
"1",
"/",
"obj",
"===",
... | Serializes an object in a way that will provide a token unique to the type, class, and value of an object. Host objects, class instances etc, are not serializable, and are held in an array of references that will return the index as a unique identifier for the object. This array is passed from outside so that the calli... | [
"Serializes",
"an",
"object",
"in",
"a",
"way",
"that",
"will",
"provide",
"a",
"token",
"unique",
"to",
"the",
"type",
"class",
"and",
"value",
"of",
"an",
"object",
".",
"Host",
"objects",
"class",
"instances",
"etc",
"are",
"not",
"serializable",
"and",... | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L731-L759 | train |
andrewplummer/Sugar | lib/common.js | stringToNumber | function stringToNumber(str, base) {
var sanitized, isDecimal;
sanitized = str.replace(fullWidthNumberReg, function(chr) {
var replacement = getOwn(fullWidthNumberMap, chr);
if (replacement === HALF_WIDTH_PERIOD) {
isDecimal = true;
}
return replacement;
});
return isDecimal ? parseFloat(s... | javascript | function stringToNumber(str, base) {
var sanitized, isDecimal;
sanitized = str.replace(fullWidthNumberReg, function(chr) {
var replacement = getOwn(fullWidthNumberMap, chr);
if (replacement === HALF_WIDTH_PERIOD) {
isDecimal = true;
}
return replacement;
});
return isDecimal ? parseFloat(s... | [
"function",
"stringToNumber",
"(",
"str",
",",
"base",
")",
"{",
"var",
"sanitized",
",",
"isDecimal",
";",
"sanitized",
"=",
"str",
".",
"replace",
"(",
"fullWidthNumberReg",
",",
"function",
"(",
"chr",
")",
"{",
"var",
"replacement",
"=",
"getOwn",
"(",... | Takes into account full-width characters, commas, and decimals. | [
"Takes",
"into",
"account",
"full",
"-",
"width",
"characters",
"commas",
"and",
"decimals",
"."
] | 4adba2e6ef8c8734a693af3141461dec6d674d50 | https://github.com/andrewplummer/Sugar/blob/4adba2e6ef8c8734a693af3141461dec6d674d50/lib/common.js#L1009-L1019 | 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.