id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,700 | onivim/oni | extensions/oni-plugin-prettier/requirePackage.js | requireLocalPkg | function requireLocalPkg(fspath, pkgName) {
const modulePath = findPkg(fspath, pkgName)
if (modulePath) {
try {
return require(modulePath)
} catch (e) {
console.warn(`Failed to load ${pkgName} from ${modulePath}. Using bundled`)
}
}
return require(pkgName)
} | javascript | function requireLocalPkg(fspath, pkgName) {
const modulePath = findPkg(fspath, pkgName)
if (modulePath) {
try {
return require(modulePath)
} catch (e) {
console.warn(`Failed to load ${pkgName} from ${modulePath}. Using bundled`)
}
}
return require(pkgName)
} | [
"function",
"requireLocalPkg",
"(",
"fspath",
",",
"pkgName",
")",
"{",
"const",
"modulePath",
"=",
"findPkg",
"(",
"fspath",
",",
"pkgName",
")",
"if",
"(",
"modulePath",
")",
"{",
"try",
"{",
"return",
"require",
"(",
"modulePath",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"warn",
"(",
"`",
"${",
"pkgName",
"}",
"${",
"modulePath",
"}",
"`",
")",
"}",
"}",
"return",
"require",
"(",
"pkgName",
")",
"}"
] | Require package explicitely installed relative to given path.
Fallback to bundled one if no pacakge was found bottom up.
@param {string} fspath file system path starting point to resolve package
@param {string} pkgName package's name to require
@returns module | [
"Require",
"package",
"explicitely",
"installed",
"relative",
"to",
"given",
"path",
".",
"Fallback",
"to",
"bundled",
"one",
"if",
"no",
"pacakge",
"was",
"found",
"bottom",
"up",
"."
] | ebe9ffded341f111f7606c661b089931c3271057 | https://github.com/onivim/oni/blob/ebe9ffded341f111f7606c661b089931c3271057/extensions/oni-plugin-prettier/requirePackage.js#L39-L50 |
5,701 | evcohen/eslint-plugin-jsx-a11y | src/rules/label-has-for.js | validateNesting | function validateNesting(node) {
let queue = [...node.parent.children];
let child;
let opener;
while (queue.length) {
child = queue.shift();
opener = child.openingElement;
if (child.type === 'JSXElement' && opener && (opener.name.name === 'input' || opener.name.name === 'textarea')) {
return true;
}
if (child.children) {
queue = queue.concat(child.children);
}
}
return false;
} | javascript | function validateNesting(node) {
let queue = [...node.parent.children];
let child;
let opener;
while (queue.length) {
child = queue.shift();
opener = child.openingElement;
if (child.type === 'JSXElement' && opener && (opener.name.name === 'input' || opener.name.name === 'textarea')) {
return true;
}
if (child.children) {
queue = queue.concat(child.children);
}
}
return false;
} | [
"function",
"validateNesting",
"(",
"node",
")",
"{",
"let",
"queue",
"=",
"[",
"...",
"node",
".",
"parent",
".",
"children",
"]",
";",
"let",
"child",
";",
"let",
"opener",
";",
"while",
"(",
"queue",
".",
"length",
")",
"{",
"child",
"=",
"queue",
".",
"shift",
"(",
")",
";",
"opener",
"=",
"child",
".",
"openingElement",
";",
"if",
"(",
"child",
".",
"type",
"===",
"'JSXElement'",
"&&",
"opener",
"&&",
"(",
"opener",
".",
"name",
".",
"name",
"===",
"'input'",
"||",
"opener",
".",
"name",
".",
"name",
"===",
"'textarea'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"child",
".",
"children",
")",
"{",
"queue",
"=",
"queue",
".",
"concat",
"(",
"child",
".",
"children",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Breadth-first search, assuming that HTML for forms is shallow. | [
"Breadth",
"-",
"first",
"search",
"assuming",
"that",
"HTML",
"for",
"forms",
"is",
"shallow",
"."
] | b7915dc5b8272dc1db103a82d6c961e6f4ad377e | https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/b7915dc5b8272dc1db103a82d6c961e6f4ad377e/src/rules/label-has-for.js#L30-L45 |
5,702 | Vincit/objection.js | lib/utils/objectUtils.js | isPlainObject | function isPlainObject(value) {
return (
isObject(value) &&
(!value.constructor || value.constructor === Object) &&
(!value.toString || value.toString === Object.prototype.toString)
);
} | javascript | function isPlainObject(value) {
return (
isObject(value) &&
(!value.constructor || value.constructor === Object) &&
(!value.toString || value.toString === Object.prototype.toString)
);
} | [
"function",
"isPlainObject",
"(",
"value",
")",
"{",
"return",
"(",
"isObject",
"(",
"value",
")",
"&&",
"(",
"!",
"value",
".",
"constructor",
"||",
"value",
".",
"constructor",
"===",
"Object",
")",
"&&",
"(",
"!",
"value",
".",
"toString",
"||",
"value",
".",
"toString",
"===",
"Object",
".",
"prototype",
".",
"toString",
")",
")",
";",
"}"
] | Quick and dirty check if an object is a plain object and not for example an instance of some class. | [
"Quick",
"and",
"dirty",
"check",
"if",
"an",
"object",
"is",
"a",
"plain",
"object",
"and",
"not",
"for",
"example",
"an",
"instance",
"of",
"some",
"class",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/objectUtils.js#L22-L28 |
5,703 | Vincit/objection.js | lib/queryBuilder/graph/GraphUpsert.js | pruneGraphs | function pruneGraphs(graph, graphOptions) {
return currentGraph => {
pruneRelatedBranches(graph, currentGraph, graphOptions);
if (!graphOptions.isInsertOnly()) {
pruneDeletedBranches(graph, currentGraph);
}
return currentGraph;
};
} | javascript | function pruneGraphs(graph, graphOptions) {
return currentGraph => {
pruneRelatedBranches(graph, currentGraph, graphOptions);
if (!graphOptions.isInsertOnly()) {
pruneDeletedBranches(graph, currentGraph);
}
return currentGraph;
};
} | [
"function",
"pruneGraphs",
"(",
"graph",
",",
"graphOptions",
")",
"{",
"return",
"currentGraph",
"=>",
"{",
"pruneRelatedBranches",
"(",
"graph",
",",
"currentGraph",
",",
"graphOptions",
")",
";",
"if",
"(",
"!",
"graphOptions",
".",
"isInsertOnly",
"(",
")",
")",
"{",
"pruneDeletedBranches",
"(",
"graph",
",",
"currentGraph",
")",
";",
"}",
"return",
"currentGraph",
";",
"}",
";",
"}"
] | Remove branches from the graph that require no operations. For example we never want to do anything for descendant nodes of a node that is deleted or unrelated. We never delete recursively. | [
"Remove",
"branches",
"from",
"the",
"graph",
"that",
"require",
"no",
"operations",
".",
"For",
"example",
"we",
"never",
"want",
"to",
"do",
"anything",
"for",
"descendant",
"nodes",
"of",
"a",
"node",
"that",
"is",
"deleted",
"or",
"unrelated",
".",
"We",
"never",
"delete",
"recursively",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/queryBuilder/graph/GraphUpsert.js#L72-L82 |
5,704 | Vincit/objection.js | lib/utils/promiseUtils/mapAfterAllReturn.js | mapAfterAllReturn | function mapAfterAllReturn(arr, mapper, returnValue) {
const results = new Array(arr.length);
let containsPromise = false;
for (let i = 0, l = arr.length; i < l; ++i) {
results[i] = mapper(arr[i]);
if (isPromise(results[i])) {
containsPromise = true;
}
}
if (containsPromise) {
return Promise.all(results).then(() => returnValue);
} else {
return returnValue;
}
} | javascript | function mapAfterAllReturn(arr, mapper, returnValue) {
const results = new Array(arr.length);
let containsPromise = false;
for (let i = 0, l = arr.length; i < l; ++i) {
results[i] = mapper(arr[i]);
if (isPromise(results[i])) {
containsPromise = true;
}
}
if (containsPromise) {
return Promise.all(results).then(() => returnValue);
} else {
return returnValue;
}
} | [
"function",
"mapAfterAllReturn",
"(",
"arr",
",",
"mapper",
",",
"returnValue",
")",
"{",
"const",
"results",
"=",
"new",
"Array",
"(",
"arr",
".",
"length",
")",
";",
"let",
"containsPromise",
"=",
"false",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"results",
"[",
"i",
"]",
"=",
"mapper",
"(",
"arr",
"[",
"i",
"]",
")",
";",
"if",
"(",
"isPromise",
"(",
"results",
"[",
"i",
"]",
")",
")",
"{",
"containsPromise",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"containsPromise",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"results",
")",
".",
"then",
"(",
"(",
")",
"=>",
"returnValue",
")",
";",
"}",
"else",
"{",
"return",
"returnValue",
";",
"}",
"}"
] | Map `arr` with `mapper` and after that return `returnValue`. If none of the mapped values is a promise, return synchronously for performance reasons. | [
"Map",
"arr",
"with",
"mapper",
"and",
"after",
"that",
"return",
"returnValue",
".",
"If",
"none",
"of",
"the",
"mapped",
"values",
"is",
"a",
"promise",
"return",
"synchronously",
"for",
"performance",
"reasons",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/promiseUtils/mapAfterAllReturn.js#L8-L25 |
5,705 | Vincit/objection.js | lib/utils/promiseUtils/map.js | promiseMap | function promiseMap(items, mapper, opt) {
switch (items.length) {
case 0:
return mapZero();
case 1:
return mapOne(items, mapper);
default:
return mapMany(items, mapper, opt);
}
} | javascript | function promiseMap(items, mapper, opt) {
switch (items.length) {
case 0:
return mapZero();
case 1:
return mapOne(items, mapper);
default:
return mapMany(items, mapper, opt);
}
} | [
"function",
"promiseMap",
"(",
"items",
",",
"mapper",
",",
"opt",
")",
"{",
"switch",
"(",
"items",
".",
"length",
")",
"{",
"case",
"0",
":",
"return",
"mapZero",
"(",
")",
";",
"case",
"1",
":",
"return",
"mapOne",
"(",
"items",
",",
"mapper",
")",
";",
"default",
":",
"return",
"mapMany",
"(",
"items",
",",
"mapper",
",",
"opt",
")",
";",
"}",
"}"
] | Works like Bluebird.map. | [
"Works",
"like",
"Bluebird",
".",
"map",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/promiseUtils/map.js#L6-L15 |
5,706 | Vincit/objection.js | lib/utils/clone.js | initCloneArray | function initCloneArray(array) {
var length = array.length,
result = new array.constructor(length);
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
}
return result;
} | javascript | function initCloneArray(array) {
var length = array.length,
result = new array.constructor(length);
// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
}
return result;
} | [
"function",
"initCloneArray",
"(",
"array",
")",
"{",
"var",
"length",
"=",
"array",
".",
"length",
",",
"result",
"=",
"new",
"array",
".",
"constructor",
"(",
"length",
")",
";",
"// Add properties assigned by `RegExp#exec`.",
"if",
"(",
"length",
"&&",
"typeof",
"array",
"[",
"0",
"]",
"==",
"'string'",
"&&",
"hasOwnProperty",
".",
"call",
"(",
"array",
",",
"'index'",
")",
")",
"{",
"result",
".",
"index",
"=",
"array",
".",
"index",
";",
"result",
".",
"input",
"=",
"array",
".",
"input",
";",
"}",
"return",
"result",
";",
"}"
] | Initializes an array clone.
@private
@param {Array} array The array to clone.
@returns {Array} Returns the initialized clone. | [
"Initializes",
"an",
"array",
"clone",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/clone.js#L1605-L1615 |
5,707 | Vincit/objection.js | lib/queryBuilder/graph/GraphOperation.js | createInputColumnSelector | function createInputColumnSelector(nodes) {
return builder => {
const selects = new Map();
for (const node of nodes) {
const databaseJson = node.obj.$toDatabaseJson(builder);
for (const column of Object.keys(databaseJson)) {
if (!shouldSelectColumn(column, selects, node)) {
continue;
}
const selection =
createManyToManyExtraSelectionIfNeeded(builder, column, node) ||
createSelection(builder, column, node);
selects.set(column, selection);
}
}
const selectArr = Array.from(selects.values());
const idColumn = builder.fullIdColumn();
if (!selectArr.includes(idColumn)) {
// Always select the identifer.
selectArr.push(idColumn);
}
builder.select(selectArr);
};
} | javascript | function createInputColumnSelector(nodes) {
return builder => {
const selects = new Map();
for (const node of nodes) {
const databaseJson = node.obj.$toDatabaseJson(builder);
for (const column of Object.keys(databaseJson)) {
if (!shouldSelectColumn(column, selects, node)) {
continue;
}
const selection =
createManyToManyExtraSelectionIfNeeded(builder, column, node) ||
createSelection(builder, column, node);
selects.set(column, selection);
}
}
const selectArr = Array.from(selects.values());
const idColumn = builder.fullIdColumn();
if (!selectArr.includes(idColumn)) {
// Always select the identifer.
selectArr.push(idColumn);
}
builder.select(selectArr);
};
} | [
"function",
"createInputColumnSelector",
"(",
"nodes",
")",
"{",
"return",
"builder",
"=>",
"{",
"const",
"selects",
"=",
"new",
"Map",
"(",
")",
";",
"for",
"(",
"const",
"node",
"of",
"nodes",
")",
"{",
"const",
"databaseJson",
"=",
"node",
".",
"obj",
".",
"$toDatabaseJson",
"(",
"builder",
")",
";",
"for",
"(",
"const",
"column",
"of",
"Object",
".",
"keys",
"(",
"databaseJson",
")",
")",
"{",
"if",
"(",
"!",
"shouldSelectColumn",
"(",
"column",
",",
"selects",
",",
"node",
")",
")",
"{",
"continue",
";",
"}",
"const",
"selection",
"=",
"createManyToManyExtraSelectionIfNeeded",
"(",
"builder",
",",
"column",
",",
"node",
")",
"||",
"createSelection",
"(",
"builder",
",",
"column",
",",
"node",
")",
";",
"selects",
".",
"set",
"(",
"column",
",",
"selection",
")",
";",
"}",
"}",
"const",
"selectArr",
"=",
"Array",
".",
"from",
"(",
"selects",
".",
"values",
"(",
")",
")",
";",
"const",
"idColumn",
"=",
"builder",
".",
"fullIdColumn",
"(",
")",
";",
"if",
"(",
"!",
"selectArr",
".",
"includes",
"(",
"idColumn",
")",
")",
"{",
"// Always select the identifer.",
"selectArr",
".",
"push",
"(",
"idColumn",
")",
";",
"}",
"builder",
".",
"select",
"(",
"selectArr",
")",
";",
"}",
";",
"}"
] | Returns a function that only selects the columns that exist in the input. | [
"Returns",
"a",
"function",
"that",
"only",
"selects",
"the",
"columns",
"that",
"exist",
"in",
"the",
"input",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/queryBuilder/graph/GraphOperation.js#L120-L150 |
5,708 | Vincit/objection.js | lib/utils/identifierMapping.js | memoize | function memoize(func) {
const cache = new Map();
return input => {
let output = cache.get(input);
if (output === undefined) {
output = func(input);
cache.set(input, output);
}
return output;
};
} | javascript | function memoize(func) {
const cache = new Map();
return input => {
let output = cache.get(input);
if (output === undefined) {
output = func(input);
cache.set(input, output);
}
return output;
};
} | [
"function",
"memoize",
"(",
"func",
")",
"{",
"const",
"cache",
"=",
"new",
"Map",
"(",
")",
";",
"return",
"input",
"=>",
"{",
"let",
"output",
"=",
"cache",
".",
"get",
"(",
"input",
")",
";",
"if",
"(",
"output",
"===",
"undefined",
")",
"{",
"output",
"=",
"func",
"(",
"input",
")",
";",
"cache",
".",
"set",
"(",
"input",
",",
"output",
")",
";",
"}",
"return",
"output",
";",
"}",
";",
"}"
] | Super fast memoize for single argument functions. | [
"Super",
"fast",
"memoize",
"for",
"single",
"argument",
"functions",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/identifierMapping.js#L6-L19 |
5,709 | Vincit/objection.js | lib/utils/identifierMapping.js | camelCase | function camelCase(str, { upperCase = false } = {}) {
if (str.length === 0) {
return str;
}
if (upperCase && isAllUpperCaseSnakeCase(str)) {
// Only convert to lower case if the string is all upper
// case snake_case. This allowes camelCase strings to go
// through without changing.
str = str.toLowerCase();
}
let out = str[0];
for (let i = 1, l = str.length; i < l; ++i) {
const char = str[i];
const prevChar = str[i - 1];
if (char !== '_') {
if (prevChar === '_') {
out += char.toUpperCase();
} else {
out += char;
}
}
}
return out;
} | javascript | function camelCase(str, { upperCase = false } = {}) {
if (str.length === 0) {
return str;
}
if (upperCase && isAllUpperCaseSnakeCase(str)) {
// Only convert to lower case if the string is all upper
// case snake_case. This allowes camelCase strings to go
// through without changing.
str = str.toLowerCase();
}
let out = str[0];
for (let i = 1, l = str.length; i < l; ++i) {
const char = str[i];
const prevChar = str[i - 1];
if (char !== '_') {
if (prevChar === '_') {
out += char.toUpperCase();
} else {
out += char;
}
}
}
return out;
} | [
"function",
"camelCase",
"(",
"str",
",",
"{",
"upperCase",
"=",
"false",
"}",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"str",
".",
"length",
"===",
"0",
")",
"{",
"return",
"str",
";",
"}",
"if",
"(",
"upperCase",
"&&",
"isAllUpperCaseSnakeCase",
"(",
"str",
")",
")",
"{",
"// Only convert to lower case if the string is all upper",
"// case snake_case. This allowes camelCase strings to go",
"// through without changing.",
"str",
"=",
"str",
".",
"toLowerCase",
"(",
")",
";",
"}",
"let",
"out",
"=",
"str",
"[",
"0",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"1",
",",
"l",
"=",
"str",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"char",
"=",
"str",
"[",
"i",
"]",
";",
"const",
"prevChar",
"=",
"str",
"[",
"i",
"-",
"1",
"]",
";",
"if",
"(",
"char",
"!==",
"'_'",
")",
"{",
"if",
"(",
"prevChar",
"===",
"'_'",
")",
"{",
"out",
"+=",
"char",
".",
"toUpperCase",
"(",
")",
";",
"}",
"else",
"{",
"out",
"+=",
"char",
";",
"}",
"}",
"}",
"return",
"out",
";",
"}"
] | snake_case to camelCase converter that simply reverses the actions done by `snakeCase` function. | [
"snake_case",
"to",
"camelCase",
"converter",
"that",
"simply",
"reverses",
"the",
"actions",
"done",
"by",
"snakeCase",
"function",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/identifierMapping.js#L76-L104 |
5,710 | Vincit/objection.js | lib/utils/identifierMapping.js | mapLastPart | function mapLastPart(mapper, separator) {
return str => {
const idx = str.lastIndexOf(separator);
const mapped = mapper(str.slice(idx + separator.length));
return str.slice(0, idx + separator.length) + mapped;
};
} | javascript | function mapLastPart(mapper, separator) {
return str => {
const idx = str.lastIndexOf(separator);
const mapped = mapper(str.slice(idx + separator.length));
return str.slice(0, idx + separator.length) + mapped;
};
} | [
"function",
"mapLastPart",
"(",
"mapper",
",",
"separator",
")",
"{",
"return",
"str",
"=>",
"{",
"const",
"idx",
"=",
"str",
".",
"lastIndexOf",
"(",
"separator",
")",
";",
"const",
"mapped",
"=",
"mapper",
"(",
"str",
".",
"slice",
"(",
"idx",
"+",
"separator",
".",
"length",
")",
")",
";",
"return",
"str",
".",
"slice",
"(",
"0",
",",
"idx",
"+",
"separator",
".",
"length",
")",
"+",
"mapped",
";",
"}",
";",
"}"
] | Returns a function that splits the inputs string into pieces using `separator`, only calls `mapper` for the last part and concatenates the string back together. If no separators are found, `mapper` is called for the entire string. | [
"Returns",
"a",
"function",
"that",
"splits",
"the",
"inputs",
"string",
"into",
"pieces",
"using",
"separator",
"only",
"calls",
"mapper",
"for",
"the",
"last",
"part",
"and",
"concatenates",
"the",
"string",
"back",
"together",
".",
"If",
"no",
"separators",
"are",
"found",
"mapper",
"is",
"called",
"for",
"the",
"entire",
"string",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/identifierMapping.js#L125-L131 |
5,711 | Vincit/objection.js | lib/utils/identifierMapping.js | keyMapper | function keyMapper(mapper) {
return obj => {
if (!isObject(obj) || Array.isArray(obj)) {
return obj;
}
const keys = Object.keys(obj);
const out = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
out[mapper(key)] = obj[key];
}
return out;
};
} | javascript | function keyMapper(mapper) {
return obj => {
if (!isObject(obj) || Array.isArray(obj)) {
return obj;
}
const keys = Object.keys(obj);
const out = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
out[mapper(key)] = obj[key];
}
return out;
};
} | [
"function",
"keyMapper",
"(",
"mapper",
")",
"{",
"return",
"obj",
"=>",
"{",
"if",
"(",
"!",
"isObject",
"(",
"obj",
")",
"||",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"obj",
";",
"}",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"obj",
")",
";",
"const",
"out",
"=",
"{",
"}",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"out",
"[",
"mapper",
"(",
"key",
")",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"return",
"out",
";",
"}",
";",
"}"
] | Returns a function that takes an object as an input and maps the object's keys using `mapper`. If the input is not an object, the input is returned unchanged. | [
"Returns",
"a",
"function",
"that",
"takes",
"an",
"object",
"as",
"an",
"input",
"and",
"maps",
"the",
"object",
"s",
"keys",
"using",
"mapper",
".",
"If",
"the",
"input",
"is",
"not",
"an",
"object",
"the",
"input",
"is",
"returned",
"unchanged",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/identifierMapping.js#L135-L151 |
5,712 | Vincit/objection.js | lib/utils/normalizeIds.js | normalizeIds | function normalizeIds(ids, prop, opt) {
opt = opt || {};
let isComposite = prop.size > 1;
let ret;
if (isComposite) {
// For composite ids these are okay:
//
// 1. [1, 'foo', 4]
// 2. {a: 1, b: 'foo', c: 4}
// 3. [[1, 'foo', 4], [4, 'bar', 1]]
// 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
//
if (Array.isArray(ids)) {
if (Array.isArray(ids[0])) {
ret = new Array(ids.length);
// 3.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = convertIdArrayToObject(ids[i], prop);
}
} else if (isObject(ids[0])) {
ret = new Array(ids.length);
// 4.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = ensureObject(ids[i], prop);
}
} else {
// 1.
ret = [convertIdArrayToObject(ids, prop)];
}
} else if (isObject(ids)) {
// 2.
ret = [ids];
} else {
throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
}
} else {
// For non-composite ids, these are okay:
//
// 1. 1
// 2. {id: 1}
// 3. [1, 'foo', 4]
// 4. [{id: 1}, {id: 'foo'}, {id: 4}]
//
if (Array.isArray(ids)) {
if (isObject(ids[0])) {
ret = new Array(ids.length);
// 4.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = ensureObject(ids[i]);
}
} else {
ret = new Array(ids.length);
// 3.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = {};
prop.setProp(ret[i], 0, ids[i]);
}
}
} else if (isObject(ids)) {
// 2.
ret = [ids];
} else {
// 1.
const obj = {};
prop.setProp(obj, 0, ids);
ret = [obj];
}
}
checkProperties(ret, prop);
if (opt.arrayOutput) {
return normalizedToArray(ret, prop);
} else {
return ret;
}
} | javascript | function normalizeIds(ids, prop, opt) {
opt = opt || {};
let isComposite = prop.size > 1;
let ret;
if (isComposite) {
// For composite ids these are okay:
//
// 1. [1, 'foo', 4]
// 2. {a: 1, b: 'foo', c: 4}
// 3. [[1, 'foo', 4], [4, 'bar', 1]]
// 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
//
if (Array.isArray(ids)) {
if (Array.isArray(ids[0])) {
ret = new Array(ids.length);
// 3.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = convertIdArrayToObject(ids[i], prop);
}
} else if (isObject(ids[0])) {
ret = new Array(ids.length);
// 4.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = ensureObject(ids[i], prop);
}
} else {
// 1.
ret = [convertIdArrayToObject(ids, prop)];
}
} else if (isObject(ids)) {
// 2.
ret = [ids];
} else {
throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
}
} else {
// For non-composite ids, these are okay:
//
// 1. 1
// 2. {id: 1}
// 3. [1, 'foo', 4]
// 4. [{id: 1}, {id: 'foo'}, {id: 4}]
//
if (Array.isArray(ids)) {
if (isObject(ids[0])) {
ret = new Array(ids.length);
// 4.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = ensureObject(ids[i]);
}
} else {
ret = new Array(ids.length);
// 3.
for (let i = 0, l = ids.length; i < l; ++i) {
ret[i] = {};
prop.setProp(ret[i], 0, ids[i]);
}
}
} else if (isObject(ids)) {
// 2.
ret = [ids];
} else {
// 1.
const obj = {};
prop.setProp(obj, 0, ids);
ret = [obj];
}
}
checkProperties(ret, prop);
if (opt.arrayOutput) {
return normalizedToArray(ret, prop);
} else {
return ret;
}
} | [
"function",
"normalizeIds",
"(",
"ids",
",",
"prop",
",",
"opt",
")",
"{",
"opt",
"=",
"opt",
"||",
"{",
"}",
";",
"let",
"isComposite",
"=",
"prop",
".",
"size",
">",
"1",
";",
"let",
"ret",
";",
"if",
"(",
"isComposite",
")",
"{",
"// For composite ids these are okay:",
"//",
"// 1. [1, 'foo', 4]",
"// 2. {a: 1, b: 'foo', c: 4}",
"// 3. [[1, 'foo', 4], [4, 'bar', 1]]",
"// 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]",
"//",
"if",
"(",
"Array",
".",
"isArray",
"(",
"ids",
")",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"ids",
"[",
"0",
"]",
")",
")",
"{",
"ret",
"=",
"new",
"Array",
"(",
"ids",
".",
"length",
")",
";",
"// 3.",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"ids",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"convertIdArrayToObject",
"(",
"ids",
"[",
"i",
"]",
",",
"prop",
")",
";",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"ids",
"[",
"0",
"]",
")",
")",
"{",
"ret",
"=",
"new",
"Array",
"(",
"ids",
".",
"length",
")",
";",
"// 4.",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"ids",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"ensureObject",
"(",
"ids",
"[",
"i",
"]",
",",
"prop",
")",
";",
"}",
"}",
"else",
"{",
"// 1.",
"ret",
"=",
"[",
"convertIdArrayToObject",
"(",
"ids",
",",
"prop",
")",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"ids",
")",
")",
"{",
"// 2.",
"ret",
"=",
"[",
"ids",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"ids",
")",
"}",
"`",
")",
";",
"}",
"}",
"else",
"{",
"// For non-composite ids, these are okay:",
"//",
"// 1. 1",
"// 2. {id: 1}",
"// 3. [1, 'foo', 4]",
"// 4. [{id: 1}, {id: 'foo'}, {id: 4}]",
"//",
"if",
"(",
"Array",
".",
"isArray",
"(",
"ids",
")",
")",
"{",
"if",
"(",
"isObject",
"(",
"ids",
"[",
"0",
"]",
")",
")",
"{",
"ret",
"=",
"new",
"Array",
"(",
"ids",
".",
"length",
")",
";",
"// 4.",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"ids",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"ensureObject",
"(",
"ids",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"ret",
"=",
"new",
"Array",
"(",
"ids",
".",
"length",
")",
";",
"// 3.",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"ids",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"{",
"}",
";",
"prop",
".",
"setProp",
"(",
"ret",
"[",
"i",
"]",
",",
"0",
",",
"ids",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"ids",
")",
")",
"{",
"// 2.",
"ret",
"=",
"[",
"ids",
"]",
";",
"}",
"else",
"{",
"// 1.",
"const",
"obj",
"=",
"{",
"}",
";",
"prop",
".",
"setProp",
"(",
"obj",
",",
"0",
",",
"ids",
")",
";",
"ret",
"=",
"[",
"obj",
"]",
";",
"}",
"}",
"checkProperties",
"(",
"ret",
",",
"prop",
")",
";",
"if",
"(",
"opt",
".",
"arrayOutput",
")",
"{",
"return",
"normalizedToArray",
"(",
"ret",
",",
"prop",
")",
";",
"}",
"else",
"{",
"return",
"ret",
";",
"}",
"}"
] | ids is of type RelationProperty. | [
"ids",
"is",
"of",
"type",
"RelationProperty",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/normalizeIds.js#L6-L88 |
5,713 | Vincit/objection.js | lib/queryBuilder/join/utils.js | forEachChildExpression | function forEachChildExpression(expr, modelClass, callback) {
if (expr.node.$allRecursive || expr.maxRecursionDepth > RELATION_RECURSION_LIMIT) {
throw modelClass.createValidationError({
type: ValidationErrorType.RelationExpression,
message: `recursion depth of eager expression ${expr.toString()} too big for JoinEagerAlgorithm`
});
}
expr.forEachChildExpression(modelClass, callback);
} | javascript | function forEachChildExpression(expr, modelClass, callback) {
if (expr.node.$allRecursive || expr.maxRecursionDepth > RELATION_RECURSION_LIMIT) {
throw modelClass.createValidationError({
type: ValidationErrorType.RelationExpression,
message: `recursion depth of eager expression ${expr.toString()} too big for JoinEagerAlgorithm`
});
}
expr.forEachChildExpression(modelClass, callback);
} | [
"function",
"forEachChildExpression",
"(",
"expr",
",",
"modelClass",
",",
"callback",
")",
"{",
"if",
"(",
"expr",
".",
"node",
".",
"$allRecursive",
"||",
"expr",
".",
"maxRecursionDepth",
">",
"RELATION_RECURSION_LIMIT",
")",
"{",
"throw",
"modelClass",
".",
"createValidationError",
"(",
"{",
"type",
":",
"ValidationErrorType",
".",
"RelationExpression",
",",
"message",
":",
"`",
"${",
"expr",
".",
"toString",
"(",
")",
"}",
"`",
"}",
")",
";",
"}",
"expr",
".",
"forEachChildExpression",
"(",
"modelClass",
",",
"callback",
")",
";",
"}"
] | Given a relation expression, goes through all first level children. | [
"Given",
"a",
"relation",
"expression",
"goes",
"through",
"all",
"first",
"level",
"children",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/queryBuilder/join/utils.js#L9-L18 |
5,714 | Vincit/objection.js | lib/utils/promiseUtils/after.js | after | function after(obj, func) {
if (isPromise(obj)) {
return obj.then(func);
} else {
return func(obj);
}
} | javascript | function after(obj, func) {
if (isPromise(obj)) {
return obj.then(func);
} else {
return func(obj);
}
} | [
"function",
"after",
"(",
"obj",
",",
"func",
")",
"{",
"if",
"(",
"isPromise",
"(",
"obj",
")",
")",
"{",
"return",
"obj",
".",
"then",
"(",
"func",
")",
";",
"}",
"else",
"{",
"return",
"func",
"(",
"obj",
")",
";",
"}",
"}"
] | Call `func` after `obj` has been resolved. Call `func` synchronously if `obj` is not a promise for performance reasons. | [
"Call",
"func",
"after",
"obj",
"has",
"been",
"resolved",
".",
"Call",
"func",
"synchronously",
"if",
"obj",
"is",
"not",
"a",
"promise",
"for",
"performance",
"reasons",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/promiseUtils/after.js#L7-L13 |
5,715 | Vincit/objection.js | lib/utils/promiseUtils/try.js | promiseTry | function promiseTry(callback) {
try {
const maybePromise = callback();
if (isPromise(maybePromise)) {
return maybePromise;
} else {
return Promise.resolve(maybePromise);
}
} catch (err) {
return Promise.reject(err);
}
} | javascript | function promiseTry(callback) {
try {
const maybePromise = callback();
if (isPromise(maybePromise)) {
return maybePromise;
} else {
return Promise.resolve(maybePromise);
}
} catch (err) {
return Promise.reject(err);
}
} | [
"function",
"promiseTry",
"(",
"callback",
")",
"{",
"try",
"{",
"const",
"maybePromise",
"=",
"callback",
"(",
")",
";",
"if",
"(",
"isPromise",
"(",
"maybePromise",
")",
")",
"{",
"return",
"maybePromise",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"maybePromise",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}"
] | Works like Bluebird.try. | [
"Works",
"like",
"Bluebird",
".",
"try",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/utils/promiseUtils/try.js#L6-L18 |
5,716 | Vincit/objection.js | lib/model/modelQueryProps.js | splitQueryProps | function splitQueryProps(model, json) {
const keys = Object.keys(json);
if (hasQueryProps(json, keys)) {
const queryProps = {};
const modelProps = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
queryProps[key] = value;
} else {
modelProps[key] = value;
}
}
defineNonEnumerableProperty(model, QUERY_PROPS_PROPERTY, queryProps);
return modelProps;
} else {
return json;
}
} | javascript | function splitQueryProps(model, json) {
const keys = Object.keys(json);
if (hasQueryProps(json, keys)) {
const queryProps = {};
const modelProps = {};
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
queryProps[key] = value;
} else {
modelProps[key] = value;
}
}
defineNonEnumerableProperty(model, QUERY_PROPS_PROPERTY, queryProps);
return modelProps;
} else {
return json;
}
} | [
"function",
"splitQueryProps",
"(",
"model",
",",
"json",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"json",
")",
";",
"if",
"(",
"hasQueryProps",
"(",
"json",
",",
"keys",
")",
")",
"{",
"const",
"queryProps",
"=",
"{",
"}",
";",
"const",
"modelProps",
"=",
"{",
"}",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"const",
"value",
"=",
"json",
"[",
"key",
"]",
";",
"if",
"(",
"isQueryProp",
"(",
"value",
")",
")",
"{",
"queryProps",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"modelProps",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"defineNonEnumerableProperty",
"(",
"model",
",",
"QUERY_PROPS_PROPERTY",
",",
"queryProps",
")",
";",
"return",
"modelProps",
";",
"}",
"else",
"{",
"return",
"json",
";",
"}",
"}"
] | Removes query properties from `json` and stores them into a hidden property inside `model` so that they can be later merged back to `json`. | [
"Removes",
"query",
"properties",
"from",
"json",
"and",
"stores",
"them",
"into",
"a",
"hidden",
"property",
"inside",
"model",
"so",
"that",
"they",
"can",
"be",
"later",
"merged",
"back",
"to",
"json",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/model/modelQueryProps.js#L11-L35 |
5,717 | Vincit/objection.js | lib/model/modelQueryProps.js | mergeQueryProps | function mergeQueryProps(model, json, omitProps, builder) {
json = convertExistingQueryProps(json, builder);
json = convertAndMergeHiddenQueryProps(model, json, omitProps, builder);
return json;
} | javascript | function mergeQueryProps(model, json, omitProps, builder) {
json = convertExistingQueryProps(json, builder);
json = convertAndMergeHiddenQueryProps(model, json, omitProps, builder);
return json;
} | [
"function",
"mergeQueryProps",
"(",
"model",
",",
"json",
",",
"omitProps",
",",
"builder",
")",
"{",
"json",
"=",
"convertExistingQueryProps",
"(",
"json",
",",
"builder",
")",
";",
"json",
"=",
"convertAndMergeHiddenQueryProps",
"(",
"model",
",",
"json",
",",
"omitProps",
",",
"builder",
")",
";",
"return",
"json",
";",
"}"
] | Merges and converts `model`'s query properties into `json`. | [
"Merges",
"and",
"converts",
"model",
"s",
"query",
"properties",
"into",
"json",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/model/modelQueryProps.js#L61-L66 |
5,718 | Vincit/objection.js | lib/model/modelQueryProps.js | convertExistingQueryProps | function convertExistingQueryProps(json, builder) {
const keys = Object.keys(json);
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
json[key] = queryPropToKnexRaw(value, builder);
}
}
return json;
} | javascript | function convertExistingQueryProps(json, builder) {
const keys = Object.keys(json);
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
const value = json[key];
if (isQueryProp(value)) {
json[key] = queryPropToKnexRaw(value, builder);
}
}
return json;
} | [
"function",
"convertExistingQueryProps",
"(",
"json",
",",
"builder",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"json",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"const",
"value",
"=",
"json",
"[",
"key",
"]",
";",
"if",
"(",
"isQueryProp",
"(",
"value",
")",
")",
"{",
"json",
"[",
"key",
"]",
"=",
"queryPropToKnexRaw",
"(",
"value",
",",
"builder",
")",
";",
"}",
"}",
"return",
"json",
";",
"}"
] | Converts the query properties in `json` to knex raw instances. `json` may have query properties even though we removed them. For example they may have been added in lifecycle hooks. | [
"Converts",
"the",
"query",
"properties",
"in",
"json",
"to",
"knex",
"raw",
"instances",
".",
"json",
"may",
"have",
"query",
"properties",
"even",
"though",
"we",
"removed",
"them",
".",
"For",
"example",
"they",
"may",
"have",
"been",
"added",
"in",
"lifecycle",
"hooks",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/model/modelQueryProps.js#L71-L84 |
5,719 | Vincit/objection.js | lib/model/modelQueryProps.js | convertAndMergeHiddenQueryProps | function convertAndMergeHiddenQueryProps(model, json, omitProps, builder) {
const queryProps = model[QUERY_PROPS_PROPERTY];
if (!queryProps) {
// The model has no query properties.
return json;
}
const modelClass = model.constructor;
const keys = Object.keys(queryProps);
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
if (!omitProps || !omitProps.includes(key)) {
const queryProp = queryPropToKnexRaw(queryProps[key], builder);
json[modelClass.propertyNameToColumnName(key)] = queryProp;
}
}
return json;
} | javascript | function convertAndMergeHiddenQueryProps(model, json, omitProps, builder) {
const queryProps = model[QUERY_PROPS_PROPERTY];
if (!queryProps) {
// The model has no query properties.
return json;
}
const modelClass = model.constructor;
const keys = Object.keys(queryProps);
for (let i = 0, l = keys.length; i < l; ++i) {
const key = keys[i];
if (!omitProps || !omitProps.includes(key)) {
const queryProp = queryPropToKnexRaw(queryProps[key], builder);
json[modelClass.propertyNameToColumnName(key)] = queryProp;
}
}
return json;
} | [
"function",
"convertAndMergeHiddenQueryProps",
"(",
"model",
",",
"json",
",",
"omitProps",
",",
"builder",
")",
"{",
"const",
"queryProps",
"=",
"model",
"[",
"QUERY_PROPS_PROPERTY",
"]",
";",
"if",
"(",
"!",
"queryProps",
")",
"{",
"// The model has no query properties.",
"return",
"json",
";",
"}",
"const",
"modelClass",
"=",
"model",
".",
"constructor",
";",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"queryProps",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"l",
";",
"++",
"i",
")",
"{",
"const",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"omitProps",
"||",
"!",
"omitProps",
".",
"includes",
"(",
"key",
")",
")",
"{",
"const",
"queryProp",
"=",
"queryPropToKnexRaw",
"(",
"queryProps",
"[",
"key",
"]",
",",
"builder",
")",
";",
"json",
"[",
"modelClass",
".",
"propertyNameToColumnName",
"(",
"key",
")",
"]",
"=",
"queryProp",
";",
"}",
"}",
"return",
"json",
";",
"}"
] | Converts and merges the query props that were split from the model and stored into QUERY_PROPS_PROPERTY. | [
"Converts",
"and",
"merges",
"the",
"query",
"props",
"that",
"were",
"split",
"from",
"the",
"model",
"and",
"stored",
"into",
"QUERY_PROPS_PROPERTY",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/model/modelQueryProps.js#L88-L109 |
5,720 | Vincit/objection.js | lib/model/modelQueryProps.js | queryPropToKnexRaw | function queryPropToKnexRaw(queryProp, builder) {
if (!queryProp) {
return queryProp;
}
if (queryProp.isObjectionQueryBuilderBase) {
return buildObjectionQueryBuilder(queryProp, builder);
} else if (isKnexRawConvertable(queryProp)) {
return buildKnexRawConvertable(queryProp, builder);
} else {
return queryProp;
}
} | javascript | function queryPropToKnexRaw(queryProp, builder) {
if (!queryProp) {
return queryProp;
}
if (queryProp.isObjectionQueryBuilderBase) {
return buildObjectionQueryBuilder(queryProp, builder);
} else if (isKnexRawConvertable(queryProp)) {
return buildKnexRawConvertable(queryProp, builder);
} else {
return queryProp;
}
} | [
"function",
"queryPropToKnexRaw",
"(",
"queryProp",
",",
"builder",
")",
"{",
"if",
"(",
"!",
"queryProp",
")",
"{",
"return",
"queryProp",
";",
"}",
"if",
"(",
"queryProp",
".",
"isObjectionQueryBuilderBase",
")",
"{",
"return",
"buildObjectionQueryBuilder",
"(",
"queryProp",
",",
"builder",
")",
";",
"}",
"else",
"if",
"(",
"isKnexRawConvertable",
"(",
"queryProp",
")",
")",
"{",
"return",
"buildKnexRawConvertable",
"(",
"queryProp",
",",
"builder",
")",
";",
"}",
"else",
"{",
"return",
"queryProp",
";",
"}",
"}"
] | Converts a query property into a knex `raw` instance. | [
"Converts",
"a",
"query",
"property",
"into",
"a",
"knex",
"raw",
"instance",
"."
] | 868f0e13d51c03033100ac9796f165630657ad90 | https://github.com/Vincit/objection.js/blob/868f0e13d51c03033100ac9796f165630657ad90/lib/model/modelQueryProps.js#L112-L124 |
5,721 | ZijianHe/koa-router | lib/layer.js | Layer | function Layer(path, methods, middleware, opts) {
this.opts = opts || {};
this.name = this.opts.name || null;
this.methods = [];
this.paramNames = [];
this.stack = Array.isArray(middleware) ? middleware : [middleware];
methods.forEach(function(method) {
var l = this.methods.push(method.toUpperCase());
if (this.methods[l-1] === 'GET') {
this.methods.unshift('HEAD');
}
}, this);
// ensure middleware is a function
this.stack.forEach(function(fn) {
var type = (typeof fn);
if (type !== 'function') {
throw new Error(
methods.toString() + " `" + (this.opts.name || path) +"`: `middleware` "
+ "must be a function, not `" + type + "`"
);
}
}, this);
this.path = path;
this.regexp = pathToRegExp(path, this.paramNames, this.opts);
debug('defined route %s %s', this.methods, this.opts.prefix + this.path);
} | javascript | function Layer(path, methods, middleware, opts) {
this.opts = opts || {};
this.name = this.opts.name || null;
this.methods = [];
this.paramNames = [];
this.stack = Array.isArray(middleware) ? middleware : [middleware];
methods.forEach(function(method) {
var l = this.methods.push(method.toUpperCase());
if (this.methods[l-1] === 'GET') {
this.methods.unshift('HEAD');
}
}, this);
// ensure middleware is a function
this.stack.forEach(function(fn) {
var type = (typeof fn);
if (type !== 'function') {
throw new Error(
methods.toString() + " `" + (this.opts.name || path) +"`: `middleware` "
+ "must be a function, not `" + type + "`"
);
}
}, this);
this.path = path;
this.regexp = pathToRegExp(path, this.paramNames, this.opts);
debug('defined route %s %s', this.methods, this.opts.prefix + this.path);
} | [
"function",
"Layer",
"(",
"path",
",",
"methods",
",",
"middleware",
",",
"opts",
")",
"{",
"this",
".",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"name",
"=",
"this",
".",
"opts",
".",
"name",
"||",
"null",
";",
"this",
".",
"methods",
"=",
"[",
"]",
";",
"this",
".",
"paramNames",
"=",
"[",
"]",
";",
"this",
".",
"stack",
"=",
"Array",
".",
"isArray",
"(",
"middleware",
")",
"?",
"middleware",
":",
"[",
"middleware",
"]",
";",
"methods",
".",
"forEach",
"(",
"function",
"(",
"method",
")",
"{",
"var",
"l",
"=",
"this",
".",
"methods",
".",
"push",
"(",
"method",
".",
"toUpperCase",
"(",
")",
")",
";",
"if",
"(",
"this",
".",
"methods",
"[",
"l",
"-",
"1",
"]",
"===",
"'GET'",
")",
"{",
"this",
".",
"methods",
".",
"unshift",
"(",
"'HEAD'",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"// ensure middleware is a function",
"this",
".",
"stack",
".",
"forEach",
"(",
"function",
"(",
"fn",
")",
"{",
"var",
"type",
"=",
"(",
"typeof",
"fn",
")",
";",
"if",
"(",
"type",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"methods",
".",
"toString",
"(",
")",
"+",
"\" `\"",
"+",
"(",
"this",
".",
"opts",
".",
"name",
"||",
"path",
")",
"+",
"\"`: `middleware` \"",
"+",
"\"must be a function, not `\"",
"+",
"type",
"+",
"\"`\"",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"this",
".",
"path",
"=",
"path",
";",
"this",
".",
"regexp",
"=",
"pathToRegExp",
"(",
"path",
",",
"this",
".",
"paramNames",
",",
"this",
".",
"opts",
")",
";",
"debug",
"(",
"'defined route %s %s'",
",",
"this",
".",
"methods",
",",
"this",
".",
"opts",
".",
"prefix",
"+",
"this",
".",
"path",
")",
";",
"}"
] | Initialize a new routing Layer with given `method`, `path`, and `middleware`.
@param {String|RegExp} path Path string or regular expression.
@param {Array} methods Array of HTTP verbs.
@param {Array} middleware Layer callback/middleware or series of.
@param {Object=} opts
@param {String=} opts.name route name
@param {String=} opts.sensitive case sensitive (default: false)
@param {String=} opts.strict require the trailing slash (default: false)
@returns {Layer}
@private | [
"Initialize",
"a",
"new",
"routing",
"Layer",
"with",
"given",
"method",
"path",
"and",
"middleware",
"."
] | 49498ff35138edb218b90b58dd99dfe9b53ae916 | https://github.com/ZijianHe/koa-router/blob/49498ff35138edb218b90b58dd99dfe9b53ae916/lib/layer.js#L21-L50 |
5,722 | dropbox/zxcvbn | demo/mustache.js | debug | function debug(e, template, line, file) {
file = file || "<template>";
var lines = template.split("\n"),
start = Math.max(line - 3, 0),
end = Math.min(lines.length, line + 3),
context = lines.slice(start, end);
var c;
for (var i = 0, len = context.length; i < len; ++i) {
c = i + start + 1;
context[i] = (c === line ? " >> " : " ") + context[i];
}
e.template = template;
e.line = line;
e.file = file;
e.message = [file + ":" + line, context.join("\n"), "", e.message].join("\n");
return e;
} | javascript | function debug(e, template, line, file) {
file = file || "<template>";
var lines = template.split("\n"),
start = Math.max(line - 3, 0),
end = Math.min(lines.length, line + 3),
context = lines.slice(start, end);
var c;
for (var i = 0, len = context.length; i < len; ++i) {
c = i + start + 1;
context[i] = (c === line ? " >> " : " ") + context[i];
}
e.template = template;
e.line = line;
e.file = file;
e.message = [file + ":" + line, context.join("\n"), "", e.message].join("\n");
return e;
} | [
"function",
"debug",
"(",
"e",
",",
"template",
",",
"line",
",",
"file",
")",
"{",
"file",
"=",
"file",
"||",
"\"<template>\"",
";",
"var",
"lines",
"=",
"template",
".",
"split",
"(",
"\"\\n\"",
")",
",",
"start",
"=",
"Math",
".",
"max",
"(",
"line",
"-",
"3",
",",
"0",
")",
",",
"end",
"=",
"Math",
".",
"min",
"(",
"lines",
".",
"length",
",",
"line",
"+",
"3",
")",
",",
"context",
"=",
"lines",
".",
"slice",
"(",
"start",
",",
"end",
")",
";",
"var",
"c",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"context",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"c",
"=",
"i",
"+",
"start",
"+",
"1",
";",
"context",
"[",
"i",
"]",
"=",
"(",
"c",
"===",
"line",
"?",
"\" >> \"",
":",
"\" \"",
")",
"+",
"context",
"[",
"i",
"]",
";",
"}",
"e",
".",
"template",
"=",
"template",
";",
"e",
".",
"line",
"=",
"line",
";",
"e",
".",
"file",
"=",
"file",
";",
"e",
".",
"message",
"=",
"[",
"file",
"+",
"\":\"",
"+",
"line",
",",
"context",
".",
"join",
"(",
"\"\\n\"",
")",
",",
"\"\"",
",",
"e",
".",
"message",
"]",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"return",
"e",
";",
"}"
] | Adds the `template`, `line`, and `file` properties to the given error
object and alters the message to provide more useful debugging information. | [
"Adds",
"the",
"template",
"line",
"and",
"file",
"properties",
"to",
"the",
"given",
"error",
"object",
"and",
"alters",
"the",
"message",
"to",
"provide",
"more",
"useful",
"debugging",
"information",
"."
] | 67c4ece9efc40c9d0a1d7d995b2b22a91be500c2 | https://github.com/dropbox/zxcvbn/blob/67c4ece9efc40c9d0a1d7d995b2b22a91be500c2/demo/mustache.js#L102-L122 |
5,723 | dropbox/zxcvbn | demo/mustache.js | lookup | function lookup(name, stack, defaultValue) {
if (name === ".") {
return stack[stack.length - 1];
}
var names = name.split(".");
var lastIndex = names.length - 1;
var target = names[lastIndex];
var value, context, i = stack.length, j, localStack;
while (i) {
localStack = stack.slice(0);
context = stack[--i];
j = 0;
while (j < lastIndex) {
context = context[names[j++]];
if (context == null) {
break;
}
localStack.push(context);
}
if (context && typeof context === "object" && target in context) {
value = context[target];
break;
}
}
// If the value is a function, call it in the current context.
if (typeof value === "function") {
value = value.call(localStack[localStack.length - 1]);
}
if (value == null) {
return defaultValue;
}
return value;
} | javascript | function lookup(name, stack, defaultValue) {
if (name === ".") {
return stack[stack.length - 1];
}
var names = name.split(".");
var lastIndex = names.length - 1;
var target = names[lastIndex];
var value, context, i = stack.length, j, localStack;
while (i) {
localStack = stack.slice(0);
context = stack[--i];
j = 0;
while (j < lastIndex) {
context = context[names[j++]];
if (context == null) {
break;
}
localStack.push(context);
}
if (context && typeof context === "object" && target in context) {
value = context[target];
break;
}
}
// If the value is a function, call it in the current context.
if (typeof value === "function") {
value = value.call(localStack[localStack.length - 1]);
}
if (value == null) {
return defaultValue;
}
return value;
} | [
"function",
"lookup",
"(",
"name",
",",
"stack",
",",
"defaultValue",
")",
"{",
"if",
"(",
"name",
"===",
"\".\"",
")",
"{",
"return",
"stack",
"[",
"stack",
".",
"length",
"-",
"1",
"]",
";",
"}",
"var",
"names",
"=",
"name",
".",
"split",
"(",
"\".\"",
")",
";",
"var",
"lastIndex",
"=",
"names",
".",
"length",
"-",
"1",
";",
"var",
"target",
"=",
"names",
"[",
"lastIndex",
"]",
";",
"var",
"value",
",",
"context",
",",
"i",
"=",
"stack",
".",
"length",
",",
"j",
",",
"localStack",
";",
"while",
"(",
"i",
")",
"{",
"localStack",
"=",
"stack",
".",
"slice",
"(",
"0",
")",
";",
"context",
"=",
"stack",
"[",
"--",
"i",
"]",
";",
"j",
"=",
"0",
";",
"while",
"(",
"j",
"<",
"lastIndex",
")",
"{",
"context",
"=",
"context",
"[",
"names",
"[",
"j",
"++",
"]",
"]",
";",
"if",
"(",
"context",
"==",
"null",
")",
"{",
"break",
";",
"}",
"localStack",
".",
"push",
"(",
"context",
")",
";",
"}",
"if",
"(",
"context",
"&&",
"typeof",
"context",
"===",
"\"object\"",
"&&",
"target",
"in",
"context",
")",
"{",
"value",
"=",
"context",
"[",
"target",
"]",
";",
"break",
";",
"}",
"}",
"// If the value is a function, call it in the current context.",
"if",
"(",
"typeof",
"value",
"===",
"\"function\"",
")",
"{",
"value",
"=",
"value",
".",
"call",
"(",
"localStack",
"[",
"localStack",
".",
"length",
"-",
"1",
"]",
")",
";",
"}",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"return",
"defaultValue",
";",
"}",
"return",
"value",
";",
"}"
] | Looks up the value of the given `name` in the given context `stack`. | [
"Looks",
"up",
"the",
"value",
"of",
"the",
"given",
"name",
"in",
"the",
"given",
"context",
"stack",
"."
] | 67c4ece9efc40c9d0a1d7d995b2b22a91be500c2 | https://github.com/dropbox/zxcvbn/blob/67c4ece9efc40c9d0a1d7d995b2b22a91be500c2/demo/mustache.js#L127-L168 |
5,724 | dropbox/zxcvbn | demo/mustache.js | _compile | function _compile(template, options) {
var args = "view,partials,stack,lookup,escapeHTML,renderSection,render";
var body = parse(template, options);
var fn = new Function(args, body);
// This anonymous function wraps the generated function so we can do
// argument coercion, setup some variables, and handle any errors
// encountered while executing it.
return function (view, partials) {
partials = partials || {};
var stack = [view]; // context stack
try {
return fn(view, partials, stack, lookup, escapeHTML, renderSection, render);
} catch (e) {
throw debug(e.error, template, e.line, options.file);
}
};
} | javascript | function _compile(template, options) {
var args = "view,partials,stack,lookup,escapeHTML,renderSection,render";
var body = parse(template, options);
var fn = new Function(args, body);
// This anonymous function wraps the generated function so we can do
// argument coercion, setup some variables, and handle any errors
// encountered while executing it.
return function (view, partials) {
partials = partials || {};
var stack = [view]; // context stack
try {
return fn(view, partials, stack, lookup, escapeHTML, renderSection, render);
} catch (e) {
throw debug(e.error, template, e.line, options.file);
}
};
} | [
"function",
"_compile",
"(",
"template",
",",
"options",
")",
"{",
"var",
"args",
"=",
"\"view,partials,stack,lookup,escapeHTML,renderSection,render\"",
";",
"var",
"body",
"=",
"parse",
"(",
"template",
",",
"options",
")",
";",
"var",
"fn",
"=",
"new",
"Function",
"(",
"args",
",",
"body",
")",
";",
"// This anonymous function wraps the generated function so we can do",
"// argument coercion, setup some variables, and handle any errors",
"// encountered while executing it.",
"return",
"function",
"(",
"view",
",",
"partials",
")",
"{",
"partials",
"=",
"partials",
"||",
"{",
"}",
";",
"var",
"stack",
"=",
"[",
"view",
"]",
";",
"// context stack",
"try",
"{",
"return",
"fn",
"(",
"view",
",",
"partials",
",",
"stack",
",",
"lookup",
",",
"escapeHTML",
",",
"renderSection",
",",
"render",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"debug",
"(",
"e",
".",
"error",
",",
"template",
",",
"e",
".",
"line",
",",
"options",
".",
"file",
")",
";",
"}",
"}",
";",
"}"
] | Used by `compile` to generate a reusable function for the given `template`. | [
"Used",
"by",
"compile",
"to",
"generate",
"a",
"reusable",
"function",
"for",
"the",
"given",
"template",
"."
] | 67c4ece9efc40c9d0a1d7d995b2b22a91be500c2 | https://github.com/dropbox/zxcvbn/blob/67c4ece9efc40c9d0a1d7d995b2b22a91be500c2/demo/mustache.js#L471-L490 |
5,725 | AliasIO/Wappalyzer | src/wappalyzer.js | addDetected | function addDetected(app, pattern, type, value, key) {
app.detected = true;
// Set confidence level
app.confidence[`${type} ${key ? `${key} ` : ''}${pattern.regex}`] = pattern.confidence === undefined ? 100 : parseInt(pattern.confidence, 10);
// Detect version number
if (pattern.version) {
const versions = [];
const matches = pattern.regex.exec(value);
let { version } = pattern;
if (matches) {
matches.forEach((match, i) => {
// Parse ternary operator
const ternary = new RegExp(`\\\\${i}\\?([^:]+):(.*)$`).exec(version);
if (ternary && ternary.length === 3) {
version = version.replace(ternary[0], match ? ternary[1] : ternary[2]);
}
// Replace back references
version = version.trim().replace(new RegExp(`\\\\${i}`, 'g'), match || '');
});
if (version && versions.indexOf(version) === -1) {
versions.push(version);
}
if (versions.length) {
// Use the longest detected version number
app.version = versions.reduce((a, b) => (a.length > b.length ? a : b));
}
}
}
} | javascript | function addDetected(app, pattern, type, value, key) {
app.detected = true;
// Set confidence level
app.confidence[`${type} ${key ? `${key} ` : ''}${pattern.regex}`] = pattern.confidence === undefined ? 100 : parseInt(pattern.confidence, 10);
// Detect version number
if (pattern.version) {
const versions = [];
const matches = pattern.regex.exec(value);
let { version } = pattern;
if (matches) {
matches.forEach((match, i) => {
// Parse ternary operator
const ternary = new RegExp(`\\\\${i}\\?([^:]+):(.*)$`).exec(version);
if (ternary && ternary.length === 3) {
version = version.replace(ternary[0], match ? ternary[1] : ternary[2]);
}
// Replace back references
version = version.trim().replace(new RegExp(`\\\\${i}`, 'g'), match || '');
});
if (version && versions.indexOf(version) === -1) {
versions.push(version);
}
if (versions.length) {
// Use the longest detected version number
app.version = versions.reduce((a, b) => (a.length > b.length ? a : b));
}
}
}
} | [
"function",
"addDetected",
"(",
"app",
",",
"pattern",
",",
"type",
",",
"value",
",",
"key",
")",
"{",
"app",
".",
"detected",
"=",
"true",
";",
"// Set confidence level",
"app",
".",
"confidence",
"[",
"`",
"${",
"type",
"}",
"${",
"key",
"?",
"`",
"${",
"key",
"}",
"`",
":",
"''",
"}",
"${",
"pattern",
".",
"regex",
"}",
"`",
"]",
"=",
"pattern",
".",
"confidence",
"===",
"undefined",
"?",
"100",
":",
"parseInt",
"(",
"pattern",
".",
"confidence",
",",
"10",
")",
";",
"// Detect version number",
"if",
"(",
"pattern",
".",
"version",
")",
"{",
"const",
"versions",
"=",
"[",
"]",
";",
"const",
"matches",
"=",
"pattern",
".",
"regex",
".",
"exec",
"(",
"value",
")",
";",
"let",
"{",
"version",
"}",
"=",
"pattern",
";",
"if",
"(",
"matches",
")",
"{",
"matches",
".",
"forEach",
"(",
"(",
"match",
",",
"i",
")",
"=>",
"{",
"// Parse ternary operator",
"const",
"ternary",
"=",
"new",
"RegExp",
"(",
"`",
"\\\\",
"\\\\",
"${",
"i",
"}",
"\\\\",
"`",
")",
".",
"exec",
"(",
"version",
")",
";",
"if",
"(",
"ternary",
"&&",
"ternary",
".",
"length",
"===",
"3",
")",
"{",
"version",
"=",
"version",
".",
"replace",
"(",
"ternary",
"[",
"0",
"]",
",",
"match",
"?",
"ternary",
"[",
"1",
"]",
":",
"ternary",
"[",
"2",
"]",
")",
";",
"}",
"// Replace back references",
"version",
"=",
"version",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"\\\\",
"\\\\",
"${",
"i",
"}",
"`",
",",
"'g'",
")",
",",
"match",
"||",
"''",
")",
";",
"}",
")",
";",
"if",
"(",
"version",
"&&",
"versions",
".",
"indexOf",
"(",
"version",
")",
"===",
"-",
"1",
")",
"{",
"versions",
".",
"push",
"(",
"version",
")",
";",
"}",
"if",
"(",
"versions",
".",
"length",
")",
"{",
"// Use the longest detected version number",
"app",
".",
"version",
"=",
"versions",
".",
"reduce",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"(",
"a",
".",
"length",
">",
"b",
".",
"length",
"?",
"a",
":",
"b",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Mark application as detected, set confidence and version | [
"Mark",
"application",
"as",
"detected",
"set",
"confidence",
"and",
"version"
] | 47c1c22712f3108c194444f11c0ca317d5df8b9a | https://github.com/AliasIO/Wappalyzer/blob/47c1c22712f3108c194444f11c0ca317d5df8b9a/src/wappalyzer.js#L32-L68 |
5,726 | AliasIO/Wappalyzer | src/drivers/webextension/js/driver.js | getOption | function getOption(name, defaultValue = null) {
return new Promise(async (resolve, reject) => {
let value = defaultValue;
try {
const option = await browser.storage.local.get(name);
if (option[name] !== undefined) {
value = option[name];
}
} catch (error) {
wappalyzer.log(error.message, 'driver', 'error');
return reject(error.message);
}
return resolve(value);
});
} | javascript | function getOption(name, defaultValue = null) {
return new Promise(async (resolve, reject) => {
let value = defaultValue;
try {
const option = await browser.storage.local.get(name);
if (option[name] !== undefined) {
value = option[name];
}
} catch (error) {
wappalyzer.log(error.message, 'driver', 'error');
return reject(error.message);
}
return resolve(value);
});
} | [
"function",
"getOption",
"(",
"name",
",",
"defaultValue",
"=",
"null",
")",
"{",
"return",
"new",
"Promise",
"(",
"async",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"value",
"=",
"defaultValue",
";",
"try",
"{",
"const",
"option",
"=",
"await",
"browser",
".",
"storage",
".",
"local",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"option",
"[",
"name",
"]",
"!==",
"undefined",
")",
"{",
"value",
"=",
"option",
"[",
"name",
"]",
";",
"}",
"}",
"catch",
"(",
"error",
")",
"{",
"wappalyzer",
".",
"log",
"(",
"error",
".",
"message",
",",
"'driver'",
",",
"'error'",
")",
";",
"return",
"reject",
"(",
"error",
".",
"message",
")",
";",
"}",
"return",
"resolve",
"(",
"value",
")",
";",
"}",
")",
";",
"}"
] | Get a value from localStorage | [
"Get",
"a",
"value",
"from",
"localStorage"
] | 47c1c22712f3108c194444f11c0ca317d5df8b9a | https://github.com/AliasIO/Wappalyzer/blob/47c1c22712f3108c194444f11c0ca317d5df8b9a/src/drivers/webextension/js/driver.js#L43-L61 |
5,727 | AliasIO/Wappalyzer | src/drivers/webextension/js/driver.js | setOption | function setOption(name, value) {
return new Promise(async (resolve, reject) => {
try {
await browser.storage.local.set({ [name]: value });
} catch (error) {
wappalyzer.log(error.message, 'driver', 'error');
return reject(error.message);
}
return resolve();
});
} | javascript | function setOption(name, value) {
return new Promise(async (resolve, reject) => {
try {
await browser.storage.local.set({ [name]: value });
} catch (error) {
wappalyzer.log(error.message, 'driver', 'error');
return reject(error.message);
}
return resolve();
});
} | [
"function",
"setOption",
"(",
"name",
",",
"value",
")",
"{",
"return",
"new",
"Promise",
"(",
"async",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"try",
"{",
"await",
"browser",
".",
"storage",
".",
"local",
".",
"set",
"(",
"{",
"[",
"name",
"]",
":",
"value",
"}",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"wappalyzer",
".",
"log",
"(",
"error",
".",
"message",
",",
"'driver'",
",",
"'error'",
")",
";",
"return",
"reject",
"(",
"error",
".",
"message",
")",
";",
"}",
"return",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] | Set a value in localStorage | [
"Set",
"a",
"value",
"in",
"localStorage"
] | 47c1c22712f3108c194444f11c0ca317d5df8b9a | https://github.com/AliasIO/Wappalyzer/blob/47c1c22712f3108c194444f11c0ca317d5df8b9a/src/drivers/webextension/js/driver.js#L66-L78 |
5,728 | AliasIO/Wappalyzer | src/drivers/webextension/js/driver.js | openTab | function openTab(args) {
browser.tabs.create({
url: args.url,
active: args.background === undefined || !args.background,
});
} | javascript | function openTab(args) {
browser.tabs.create({
url: args.url,
active: args.background === undefined || !args.background,
});
} | [
"function",
"openTab",
"(",
"args",
")",
"{",
"browser",
".",
"tabs",
".",
"create",
"(",
"{",
"url",
":",
"args",
".",
"url",
",",
"active",
":",
"args",
".",
"background",
"===",
"undefined",
"||",
"!",
"args",
".",
"background",
",",
"}",
")",
";",
"}"
] | Open a tab | [
"Open",
"a",
"tab"
] | 47c1c22712f3108c194444f11c0ca317d5df8b9a | https://github.com/AliasIO/Wappalyzer/blob/47c1c22712f3108c194444f11c0ca317d5df8b9a/src/drivers/webextension/js/driver.js#L83-L88 |
5,729 | AliasIO/Wappalyzer | src/drivers/webextension/js/driver.js | post | async function post(url, body) {
try {
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
});
wappalyzer.log(`POST ${url}: ${response.status}`, 'driver');
} catch (error) {
wappalyzer.log(`POST ${url}: ${error}`, 'driver', 'error');
}
} | javascript | async function post(url, body) {
try {
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
});
wappalyzer.log(`POST ${url}: ${response.status}`, 'driver');
} catch (error) {
wappalyzer.log(`POST ${url}: ${error}`, 'driver', 'error');
}
} | [
"async",
"function",
"post",
"(",
"url",
",",
"body",
")",
"{",
"try",
"{",
"const",
"response",
"=",
"await",
"fetch",
"(",
"url",
",",
"{",
"method",
":",
"'POST'",
",",
"body",
":",
"JSON",
".",
"stringify",
"(",
"body",
")",
",",
"}",
")",
";",
"wappalyzer",
".",
"log",
"(",
"`",
"${",
"url",
"}",
"${",
"response",
".",
"status",
"}",
"`",
",",
"'driver'",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"wappalyzer",
".",
"log",
"(",
"`",
"${",
"url",
"}",
"${",
"error",
"}",
"`",
",",
"'driver'",
",",
"'error'",
")",
";",
"}",
"}"
] | Make a POST request | [
"Make",
"a",
"POST",
"request"
] | 47c1c22712f3108c194444f11c0ca317d5df8b9a | https://github.com/AliasIO/Wappalyzer/blob/47c1c22712f3108c194444f11c0ca317d5df8b9a/src/drivers/webextension/js/driver.js#L93-L104 |
5,730 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | function (it, S) {
if (!_isObject(it)) return it;
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
throw TypeError("Can't convert object to primitive value");
} | javascript | function (it, S) {
if (!_isObject(it)) return it;
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
throw TypeError("Can't convert object to primitive value");
} | [
"function",
"(",
"it",
",",
"S",
")",
"{",
"if",
"(",
"!",
"_isObject",
"(",
"it",
")",
")",
"return",
"it",
";",
"var",
"fn",
",",
"val",
";",
"if",
"(",
"S",
"&&",
"typeof",
"(",
"fn",
"=",
"it",
".",
"toString",
")",
"==",
"'function'",
"&&",
"!",
"_isObject",
"(",
"val",
"=",
"fn",
".",
"call",
"(",
"it",
")",
")",
")",
"return",
"val",
";",
"if",
"(",
"typeof",
"(",
"fn",
"=",
"it",
".",
"valueOf",
")",
"==",
"'function'",
"&&",
"!",
"_isObject",
"(",
"val",
"=",
"fn",
".",
"call",
"(",
"it",
")",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"S",
"&&",
"typeof",
"(",
"fn",
"=",
"it",
".",
"toString",
")",
"==",
"'function'",
"&&",
"!",
"_isObject",
"(",
"val",
"=",
"fn",
".",
"call",
"(",
"it",
")",
")",
")",
"return",
"val",
";",
"throw",
"TypeError",
"(",
"\"Can't convert object to primitive value\"",
")",
";",
"}"
] | instead of the ES6 spec version, we didn't implement @@toPrimitive case and the second argument - flag - preferred type is a string | [
"instead",
"of",
"the",
"ES6",
"spec",
"version",
"we",
"didn",
"t",
"implement"
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L57-L64 |
|
5,731 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | isEmpty | function isEmpty(data) {
if (Array.isArray(data)) {
return data.length === 0;
}
return Object.keys(data).length === 0;
} | javascript | function isEmpty(data) {
if (Array.isArray(data)) {
return data.length === 0;
}
return Object.keys(data).length === 0;
} | [
"function",
"isEmpty",
"(",
"data",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"data",
")",
")",
"{",
"return",
"data",
".",
"length",
"===",
"0",
";",
"}",
"return",
"Object",
".",
"keys",
"(",
"data",
")",
".",
"length",
"===",
"0",
";",
"}"
] | Check if the given array or object is empty. | [
"Check",
"if",
"the",
"given",
"array",
"or",
"object",
"is",
"empty",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L532-L537 |
5,732 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | forOwn | function forOwn(object, iteratee) {
Object.keys(object).forEach(function (key) { return iteratee(object[key], key, object); });
} | javascript | function forOwn(object, iteratee) {
Object.keys(object).forEach(function (key) { return iteratee(object[key], key, object); });
} | [
"function",
"forOwn",
"(",
"object",
",",
"iteratee",
")",
"{",
"Object",
".",
"keys",
"(",
"object",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"iteratee",
"(",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
";",
"}",
")",
";",
"}"
] | Iterates over own enumerable string keyed properties of an object and
invokes `iteratee` for each property. | [
"Iterates",
"over",
"own",
"enumerable",
"string",
"keyed",
"properties",
"of",
"an",
"object",
"and",
"invokes",
"iteratee",
"for",
"each",
"property",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L542-L544 |
5,733 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | map | function map(object, iteratee) {
return Object.keys(object).map(function (key) {
return iteratee(object[key], key, object);
});
} | javascript | function map(object, iteratee) {
return Object.keys(object).map(function (key) {
return iteratee(object[key], key, object);
});
} | [
"function",
"map",
"(",
"object",
",",
"iteratee",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"object",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"iteratee",
"(",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
";",
"}",
")",
";",
"}"
] | Create an array from the object. | [
"Create",
"an",
"array",
"from",
"the",
"object",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L548-L552 |
5,734 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | orderBy | function orderBy(collection, keys, directions) {
var index = -1;
var result = collection.map(function (value) {
var criteria = keys.map(function (key) { return value[key]; });
return { criteria: criteria, index: ++index, value: value };
});
return baseSortBy(result, function (object, other) {
return compareMultiple(object, other, directions);
});
} | javascript | function orderBy(collection, keys, directions) {
var index = -1;
var result = collection.map(function (value) {
var criteria = keys.map(function (key) { return value[key]; });
return { criteria: criteria, index: ++index, value: value };
});
return baseSortBy(result, function (object, other) {
return compareMultiple(object, other, directions);
});
} | [
"function",
"orderBy",
"(",
"collection",
",",
"keys",
",",
"directions",
")",
"{",
"var",
"index",
"=",
"-",
"1",
";",
"var",
"result",
"=",
"collection",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"var",
"criteria",
"=",
"keys",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"value",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"{",
"criteria",
":",
"criteria",
",",
"index",
":",
"++",
"index",
",",
"value",
":",
"value",
"}",
";",
"}",
")",
";",
"return",
"baseSortBy",
"(",
"result",
",",
"function",
"(",
"object",
",",
"other",
")",
"{",
"return",
"compareMultiple",
"(",
"object",
",",
"other",
",",
"directions",
")",
";",
"}",
")",
";",
"}"
] | Creates an array of elements, sorted in specified order by the results
of running each element in a collection thru each iteratee. | [
"Creates",
"an",
"array",
"of",
"elements",
"sorted",
"in",
"specified",
"order",
"by",
"the",
"results",
"of",
"running",
"each",
"element",
"in",
"a",
"collection",
"thru",
"each",
"iteratee",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L583-L592 |
5,735 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | groupBy | function groupBy(collection, iteratee) {
return collection.reduce(function (records, record) {
var key = iteratee(record);
if (records[key] === undefined) {
records[key] = [];
}
records[key].push(record);
return records;
}, {});
} | javascript | function groupBy(collection, iteratee) {
return collection.reduce(function (records, record) {
var key = iteratee(record);
if (records[key] === undefined) {
records[key] = [];
}
records[key].push(record);
return records;
}, {});
} | [
"function",
"groupBy",
"(",
"collection",
",",
"iteratee",
")",
"{",
"return",
"collection",
".",
"reduce",
"(",
"function",
"(",
"records",
",",
"record",
")",
"{",
"var",
"key",
"=",
"iteratee",
"(",
"record",
")",
";",
"if",
"(",
"records",
"[",
"key",
"]",
"===",
"undefined",
")",
"{",
"records",
"[",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"records",
"[",
"key",
"]",
".",
"push",
"(",
"record",
")",
";",
"return",
"records",
";",
"}",
",",
"{",
"}",
")",
";",
"}"
] | Creates an object composed of keys generated from the results of running
each element of collection thru iteratee. | [
"Creates",
"an",
"object",
"composed",
"of",
"keys",
"generated",
"from",
"the",
"results",
"of",
"running",
"each",
"element",
"of",
"collection",
"thru",
"iteratee",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L597-L606 |
5,736 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | Type | function Type(model, value, mutator) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
/**
* Whether if the attribute can accept `null` as a value.
*/
_this.isNullable = false;
_this.value = value;
_this.mutator = mutator;
return _this;
} | javascript | function Type(model, value, mutator) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
/**
* Whether if the attribute can accept `null` as a value.
*/
_this.isNullable = false;
_this.value = value;
_this.mutator = mutator;
return _this;
} | [
"function",
"Type",
"(",
"model",
",",
"value",
",",
"mutator",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"/**\n * Whether if the attribute can accept `null` as a value.\n */",
"_this",
".",
"isNullable",
"=",
"false",
";",
"_this",
".",
"value",
"=",
"value",
";",
"_this",
".",
"mutator",
"=",
"mutator",
";",
"return",
"_this",
";",
"}"
] | Create a new type instance. | [
"Create",
"a",
"new",
"type",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L685-L694 |
5,737 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | Attr | function Attr(model, value, mutator) {
var _this = _super.call(this, model, value, mutator) /* istanbul ignore next */ || this;
_this.value = value;
return _this;
} | javascript | function Attr(model, value, mutator) {
var _this = _super.call(this, model, value, mutator) /* istanbul ignore next */ || this;
_this.value = value;
return _this;
} | [
"function",
"Attr",
"(",
"model",
",",
"value",
",",
"mutator",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
",",
"value",
",",
"mutator",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"_this",
".",
"value",
"=",
"value",
";",
"return",
"_this",
";",
"}"
] | Create a new attr instance. | [
"Create",
"a",
"new",
"attr",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L717-L721 |
5,738 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | HasOne | function HasOne(model, related, foreignKey, localKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.related = _this.model.relation(related);
_this.foreignKey = foreignKey;
_this.localKey = localKey;
return _this;
} | javascript | function HasOne(model, related, foreignKey, localKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.related = _this.model.relation(related);
_this.foreignKey = foreignKey;
_this.localKey = localKey;
return _this;
} | [
"function",
"HasOne",
"(",
"model",
",",
"related",
",",
"foreignKey",
",",
"localKey",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"_this",
".",
"related",
"=",
"_this",
".",
"model",
".",
"relation",
"(",
"related",
")",
";",
"_this",
".",
"foreignKey",
"=",
"foreignKey",
";",
"_this",
".",
"localKey",
"=",
"localKey",
";",
"return",
"_this",
";",
"}"
] | Create a new has one instance. | [
"Create",
"a",
"new",
"has",
"one",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L956-L962 |
5,739 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | HasManyBy | function HasManyBy(model, parent, foreignKey, ownerKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.parent = _this.model.relation(parent);
_this.foreignKey = foreignKey;
_this.ownerKey = ownerKey;
return _this;
} | javascript | function HasManyBy(model, parent, foreignKey, ownerKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.parent = _this.model.relation(parent);
_this.foreignKey = foreignKey;
_this.ownerKey = ownerKey;
return _this;
} | [
"function",
"HasManyBy",
"(",
"model",
",",
"parent",
",",
"foreignKey",
",",
"ownerKey",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"_this",
".",
"parent",
"=",
"_this",
".",
"model",
".",
"relation",
"(",
"parent",
")",
";",
"_this",
".",
"foreignKey",
"=",
"foreignKey",
";",
"_this",
".",
"ownerKey",
"=",
"ownerKey",
";",
"return",
"_this",
";",
"}"
] | Create a new has many by instance. | [
"Create",
"a",
"new",
"has",
"many",
"by",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L1216-L1222 |
5,740 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | HasManyThrough | function HasManyThrough(model, related, through, firstKey, secondKey, localKey, secondLocalKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.related = _this.model.relation(related);
_this.through = _this.model.relation(through);
_this.firstKey = firstKey;
_this.secondKey = secondKey;
_this.localKey = localKey;
_this.secondLocalKey = secondLocalKey;
return _this;
} | javascript | function HasManyThrough(model, related, through, firstKey, secondKey, localKey, secondLocalKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.related = _this.model.relation(related);
_this.through = _this.model.relation(through);
_this.firstKey = firstKey;
_this.secondKey = secondKey;
_this.localKey = localKey;
_this.secondLocalKey = secondLocalKey;
return _this;
} | [
"function",
"HasManyThrough",
"(",
"model",
",",
"related",
",",
"through",
",",
"firstKey",
",",
"secondKey",
",",
"localKey",
",",
"secondLocalKey",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"_this",
".",
"related",
"=",
"_this",
".",
"model",
".",
"relation",
"(",
"related",
")",
";",
"_this",
".",
"through",
"=",
"_this",
".",
"model",
".",
"relation",
"(",
"through",
")",
";",
"_this",
".",
"firstKey",
"=",
"firstKey",
";",
"_this",
".",
"secondKey",
"=",
"secondKey",
";",
"_this",
".",
"localKey",
"=",
"localKey",
";",
"_this",
".",
"secondLocalKey",
"=",
"secondLocalKey",
";",
"return",
"_this",
";",
"}"
] | Create a new has many through instance. | [
"Create",
"a",
"new",
"has",
"many",
"through",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L1288-L1297 |
5,741 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | MorphTo | function MorphTo(model, id, type) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.id = id;
_this.type = type;
return _this;
} | javascript | function MorphTo(model, id, type) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
_this.id = id;
_this.type = type;
return _this;
} | [
"function",
"MorphTo",
"(",
"model",
",",
"id",
",",
"type",
")",
"{",
"var",
"_this",
"=",
"_super",
".",
"call",
"(",
"this",
",",
"model",
")",
"/* istanbul ignore next */",
"||",
"this",
";",
"_this",
".",
"id",
"=",
"id",
";",
"_this",
".",
"type",
"=",
"type",
";",
"return",
"_this",
";",
"}"
] | Create a new morph to instance. | [
"Create",
"a",
"new",
"morph",
"to",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L1480-L1485 |
5,742 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | denormalizeImmutable | function denormalizeImmutable(schema, input, unvisit) {
return Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
var stringKey = '' + key;
if (object.has(stringKey)) {
return object.set(stringKey, unvisit(object.get(stringKey), schema[stringKey]));
} else {
return object;
}
}, input);
} | javascript | function denormalizeImmutable(schema, input, unvisit) {
return Object.keys(schema).reduce(function (object, key) {
// Immutable maps cast keys to strings on write so we need to ensure
// we're accessing them using string keys.
var stringKey = '' + key;
if (object.has(stringKey)) {
return object.set(stringKey, unvisit(object.get(stringKey), schema[stringKey]));
} else {
return object;
}
}, input);
} | [
"function",
"denormalizeImmutable",
"(",
"schema",
",",
"input",
",",
"unvisit",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"schema",
")",
".",
"reduce",
"(",
"function",
"(",
"object",
",",
"key",
")",
"{",
"// Immutable maps cast keys to strings on write so we need to ensure",
"// we're accessing them using string keys.",
"var",
"stringKey",
"=",
"''",
"+",
"key",
";",
"if",
"(",
"object",
".",
"has",
"(",
"stringKey",
")",
")",
"{",
"return",
"object",
".",
"set",
"(",
"stringKey",
",",
"unvisit",
"(",
"object",
".",
"get",
"(",
"stringKey",
")",
",",
"schema",
"[",
"stringKey",
"]",
")",
")",
";",
"}",
"else",
"{",
"return",
"object",
";",
"}",
"}",
",",
"input",
")",
";",
"}"
] | Denormalize an immutable entity.
@param {Schema} schema
@param {Immutable.Map|Immutable.Record} input
@param {function} unvisit
@param {function} getDenormalizedEntity
@return {Immutable.Map|Immutable.Record} | [
"Denormalize",
"an",
"immutable",
"entity",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L2553-L2565 |
5,743 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | Query | function Query(state, entity) {
/**
* Primary key ids to filter records by. It is used for filtering records
* direct key lookup when a user is trying to fetch records by its
* primary key.
*
* It should not be used if there is a logic which prevents index usage, for
* example, an "or" condition which already requires a full scan of records.
*/
this.idFilter = null;
/**
* Whether to use `idFilter` key lookup. True if there is a logic which
* prevents index usage, for example, an "or" condition which already
* requires full scan.
*/
this.cancelIdFilter = false;
/**
* Primary key ids to filter joined records. It is used for filtering
* records direct key lookup. It should not be cancelled, because it
* is free from the effects of normal where methods.
*/
this.joinedIdFilter = null;
/**
* The where constraints for the query.
*/
this.wheres = [];
/**
* The has constraints for the query.
*/
this.have = [];
/**
* The orders of the query result.
*/
this.orders = [];
/**
* Number of results to skip.
*/
this.offsetNumber = 0;
/**
* Maximum number of records to return.
*
* We use polyfill of `Number.MAX_SAFE_INTEGER` for IE11 here.
*/
this.limitNumber = Math.pow(2, 53) - 1;
/**
* The relationships that should be eager loaded with the result.
*/
this.load = {};
this.rootState = state;
this.state = state[entity];
this.entity = entity;
this.model = this.getModel(entity);
this.module = this.getModule(entity);
this.hook = new Hook(this);
} | javascript | function Query(state, entity) {
/**
* Primary key ids to filter records by. It is used for filtering records
* direct key lookup when a user is trying to fetch records by its
* primary key.
*
* It should not be used if there is a logic which prevents index usage, for
* example, an "or" condition which already requires a full scan of records.
*/
this.idFilter = null;
/**
* Whether to use `idFilter` key lookup. True if there is a logic which
* prevents index usage, for example, an "or" condition which already
* requires full scan.
*/
this.cancelIdFilter = false;
/**
* Primary key ids to filter joined records. It is used for filtering
* records direct key lookup. It should not be cancelled, because it
* is free from the effects of normal where methods.
*/
this.joinedIdFilter = null;
/**
* The where constraints for the query.
*/
this.wheres = [];
/**
* The has constraints for the query.
*/
this.have = [];
/**
* The orders of the query result.
*/
this.orders = [];
/**
* Number of results to skip.
*/
this.offsetNumber = 0;
/**
* Maximum number of records to return.
*
* We use polyfill of `Number.MAX_SAFE_INTEGER` for IE11 here.
*/
this.limitNumber = Math.pow(2, 53) - 1;
/**
* The relationships that should be eager loaded with the result.
*/
this.load = {};
this.rootState = state;
this.state = state[entity];
this.entity = entity;
this.model = this.getModel(entity);
this.module = this.getModule(entity);
this.hook = new Hook(this);
} | [
"function",
"Query",
"(",
"state",
",",
"entity",
")",
"{",
"/**\n * Primary key ids to filter records by. It is used for filtering records\n * direct key lookup when a user is trying to fetch records by its\n * primary key.\n *\n * It should not be used if there is a logic which prevents index usage, for\n * example, an \"or\" condition which already requires a full scan of records.\n */",
"this",
".",
"idFilter",
"=",
"null",
";",
"/**\n * Whether to use `idFilter` key lookup. True if there is a logic which\n * prevents index usage, for example, an \"or\" condition which already\n * requires full scan.\n */",
"this",
".",
"cancelIdFilter",
"=",
"false",
";",
"/**\n * Primary key ids to filter joined records. It is used for filtering\n * records direct key lookup. It should not be cancelled, because it\n * is free from the effects of normal where methods.\n */",
"this",
".",
"joinedIdFilter",
"=",
"null",
";",
"/**\n * The where constraints for the query.\n */",
"this",
".",
"wheres",
"=",
"[",
"]",
";",
"/**\n * The has constraints for the query.\n */",
"this",
".",
"have",
"=",
"[",
"]",
";",
"/**\n * The orders of the query result.\n */",
"this",
".",
"orders",
"=",
"[",
"]",
";",
"/**\n * Number of results to skip.\n */",
"this",
".",
"offsetNumber",
"=",
"0",
";",
"/**\n * Maximum number of records to return.\n *\n * We use polyfill of `Number.MAX_SAFE_INTEGER` for IE11 here.\n */",
"this",
".",
"limitNumber",
"=",
"Math",
".",
"pow",
"(",
"2",
",",
"53",
")",
"-",
"1",
";",
"/**\n * The relationships that should be eager loaded with the result.\n */",
"this",
".",
"load",
"=",
"{",
"}",
";",
"this",
".",
"rootState",
"=",
"state",
";",
"this",
".",
"state",
"=",
"state",
"[",
"entity",
"]",
";",
"this",
".",
"entity",
"=",
"entity",
";",
"this",
".",
"model",
"=",
"this",
".",
"getModel",
"(",
"entity",
")",
";",
"this",
".",
"module",
"=",
"this",
".",
"getModule",
"(",
"entity",
")",
";",
"this",
".",
"hook",
"=",
"new",
"Hook",
"(",
"this",
")",
";",
"}"
] | Create a new Query instance. | [
"Create",
"a",
"new",
"Query",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L3769-L3823 |
5,744 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | function (context, payload) {
var state = context.state;
var entity = state.$name;
return context.dispatch(state.$connection + "/insertOrUpdate", __assign({ entity: entity }, payload), { root: true });
} | javascript | function (context, payload) {
var state = context.state;
var entity = state.$name;
return context.dispatch(state.$connection + "/insertOrUpdate", __assign({ entity: entity }, payload), { root: true });
} | [
"function",
"(",
"context",
",",
"payload",
")",
"{",
"var",
"state",
"=",
"context",
".",
"state",
";",
"var",
"entity",
"=",
"state",
".",
"$name",
";",
"return",
"context",
".",
"dispatch",
"(",
"state",
".",
"$connection",
"+",
"\"/insertOrUpdate\"",
",",
"__assign",
"(",
"{",
"entity",
":",
"entity",
"}",
",",
"payload",
")",
",",
"{",
"root",
":",
"true",
"}",
")",
";",
"}"
] | Insert or update given data to the state. Unlike `insert`, this method
will not replace existing data within the state, but it will update only
the submitted data with the same primary key. | [
"Insert",
"or",
"update",
"given",
"data",
"to",
"the",
"state",
".",
"Unlike",
"insert",
"this",
"method",
"will",
"not",
"replace",
"existing",
"data",
"within",
"the",
"state",
"but",
"it",
"will",
"update",
"only",
"the",
"submitted",
"data",
"with",
"the",
"same",
"primary",
"key",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L4717-L4721 |
|
5,745 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | function (state, payload) {
var entity = payload.entity;
var data = payload.data;
var options = OptionsBuilder.createPersistOptions(payload);
var result = payload.result;
result.data = (new Query(state, entity)).create(data, options);
} | javascript | function (state, payload) {
var entity = payload.entity;
var data = payload.data;
var options = OptionsBuilder.createPersistOptions(payload);
var result = payload.result;
result.data = (new Query(state, entity)).create(data, options);
} | [
"function",
"(",
"state",
",",
"payload",
")",
"{",
"var",
"entity",
"=",
"payload",
".",
"entity",
";",
"var",
"data",
"=",
"payload",
".",
"data",
";",
"var",
"options",
"=",
"OptionsBuilder",
".",
"createPersistOptions",
"(",
"payload",
")",
";",
"var",
"result",
"=",
"payload",
".",
"result",
";",
"result",
".",
"data",
"=",
"(",
"new",
"Query",
"(",
"state",
",",
"entity",
")",
")",
".",
"create",
"(",
"data",
",",
"options",
")",
";",
"}"
] | Save given data to the store by replacing all existing records in the
store. If you want to save data without replacing existing records,
use the `insert` method instead. | [
"Save",
"given",
"data",
"to",
"the",
"store",
"by",
"replacing",
"all",
"existing",
"records",
"in",
"the",
"store",
".",
"If",
"you",
"want",
"to",
"save",
"data",
"without",
"replacing",
"existing",
"records",
"use",
"the",
"insert",
"method",
"instead",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L4903-L4909 |
|
5,746 | vuex-orm/vuex-orm | dist/vuex-orm.esm.js | Schema | function Schema(model) {
var _this = this;
/**
* List of generated schemas.
*/
this.schemas = {};
this.model = model;
var models = model.database().models();
Object.keys(models).forEach(function (name) { _this.one(models[name]); });
} | javascript | function Schema(model) {
var _this = this;
/**
* List of generated schemas.
*/
this.schemas = {};
this.model = model;
var models = model.database().models();
Object.keys(models).forEach(function (name) { _this.one(models[name]); });
} | [
"function",
"Schema",
"(",
"model",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/**\n * List of generated schemas.\n */",
"this",
".",
"schemas",
"=",
"{",
"}",
";",
"this",
".",
"model",
"=",
"model",
";",
"var",
"models",
"=",
"model",
".",
"database",
"(",
")",
".",
"models",
"(",
")",
";",
"Object",
".",
"keys",
"(",
"models",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"_this",
".",
"one",
"(",
"models",
"[",
"name",
"]",
")",
";",
"}",
")",
";",
"}"
] | Create a new schema instance. | [
"Create",
"a",
"new",
"schema",
"instance",
"."
] | 36ab228a09566b1f6cdce9cec90d5795760120cb | https://github.com/vuex-orm/vuex-orm/blob/36ab228a09566b1f6cdce9cec90d5795760120cb/dist/vuex-orm.esm.js#L5041-L5050 |
5,747 | sdelements/lets-chat | media/js/util/message.js | encodeEntities | function encodeEntities(value) {
return value.
replace(/&/g, '&').
replace(surrogatePairRegexp, function(value) {
var hi = value.charCodeAt(0),
low = value.charCodeAt(1);
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
}).
replace(nonAlphanumericRegexp, function(value) {
return '&#' + value.charCodeAt(0) + ';';
}).
replace(/</g, '<').
replace(/>/g, '>');
} | javascript | function encodeEntities(value) {
return value.
replace(/&/g, '&').
replace(surrogatePairRegexp, function(value) {
var hi = value.charCodeAt(0),
low = value.charCodeAt(1);
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
}).
replace(nonAlphanumericRegexp, function(value) {
return '&#' + value.charCodeAt(0) + ';';
}).
replace(/</g, '<').
replace(/>/g, '>');
} | [
"function",
"encodeEntities",
"(",
"value",
")",
"{",
"return",
"value",
".",
"replace",
"(",
"/",
"&",
"/",
"g",
",",
"'&'",
")",
".",
"replace",
"(",
"surrogatePairRegexp",
",",
"function",
"(",
"value",
")",
"{",
"var",
"hi",
"=",
"value",
".",
"charCodeAt",
"(",
"0",
")",
",",
"low",
"=",
"value",
".",
"charCodeAt",
"(",
"1",
")",
";",
"return",
"'&#'",
"+",
"(",
"(",
"(",
"hi",
"-",
"0xD800",
")",
"*",
"0x400",
")",
"+",
"(",
"low",
"-",
"0xDC00",
")",
"+",
"0x10000",
")",
"+",
"';'",
";",
"}",
")",
".",
"replace",
"(",
"nonAlphanumericRegexp",
",",
"function",
"(",
"value",
")",
"{",
"return",
"'&#'",
"+",
"value",
".",
"charCodeAt",
"(",
"0",
")",
"+",
"';'",
";",
"}",
")",
".",
"replace",
"(",
"/",
"<",
"/",
"g",
",",
"'<'",
")",
".",
"replace",
"(",
"/",
">",
"/",
"g",
",",
"'>'",
")",
";",
"}"
] | Message Text Formatting | [
"Message",
"Text",
"Formatting"
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/util/message.js#L19-L32 |
5,748 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value, token) {
var score, pos;
if (!value) return 0;
value = String(value || '');
pos = value.search(token.regex);
if (pos === -1) return 0;
score = token.string.length / value.length;
if (pos === 0) score += 0.5;
return score;
} | javascript | function(value, token) {
var score, pos;
if (!value) return 0;
value = String(value || '');
pos = value.search(token.regex);
if (pos === -1) return 0;
score = token.string.length / value.length;
if (pos === 0) score += 0.5;
return score;
} | [
"function",
"(",
"value",
",",
"token",
")",
"{",
"var",
"score",
",",
"pos",
";",
"if",
"(",
"!",
"value",
")",
"return",
"0",
";",
"value",
"=",
"String",
"(",
"value",
"||",
"''",
")",
";",
"pos",
"=",
"value",
".",
"search",
"(",
"token",
".",
"regex",
")",
";",
"if",
"(",
"pos",
"===",
"-",
"1",
")",
"return",
"0",
";",
"score",
"=",
"token",
".",
"string",
".",
"length",
"/",
"value",
".",
"length",
";",
"if",
"(",
"pos",
"===",
"0",
")",
"score",
"+=",
"0.5",
";",
"return",
"score",
";",
"}"
] | Calculates how close of a match the
given value is against a search token.
@param {mixed} value
@param {object} token
@return {number} | [
"Calculates",
"how",
"close",
"of",
"a",
"match",
"the",
"given",
"value",
"is",
"against",
"a",
"search",
"token",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L133-L143 |
|
5,749 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(a, b) {
if (typeof a === 'number' && typeof b === 'number') {
return a > b ? 1 : (a < b ? -1 : 0);
}
a = asciifold(String(a || ''));
b = asciifold(String(b || ''));
if (a > b) return 1;
if (b > a) return -1;
return 0;
} | javascript | function(a, b) {
if (typeof a === 'number' && typeof b === 'number') {
return a > b ? 1 : (a < b ? -1 : 0);
}
a = asciifold(String(a || ''));
b = asciifold(String(b || ''));
if (a > b) return 1;
if (b > a) return -1;
return 0;
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"typeof",
"a",
"===",
"'number'",
"&&",
"typeof",
"b",
"===",
"'number'",
")",
"{",
"return",
"a",
">",
"b",
"?",
"1",
":",
"(",
"a",
"<",
"b",
"?",
"-",
"1",
":",
"0",
")",
";",
"}",
"a",
"=",
"asciifold",
"(",
"String",
"(",
"a",
"||",
"''",
")",
")",
";",
"b",
"=",
"asciifold",
"(",
"String",
"(",
"b",
"||",
"''",
")",
")",
";",
"if",
"(",
"a",
">",
"b",
")",
"return",
"1",
";",
"if",
"(",
"b",
">",
"a",
")",
"return",
"-",
"1",
";",
"return",
"0",
";",
"}"
] | utilities - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | [
"utilities",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L390-L399 |
|
5,750 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(self, types, fn) {
var type;
var trigger = self.trigger;
var event_args = {};
// override trigger method
self.trigger = function() {
var type = arguments[0];
if (types.indexOf(type) !== -1) {
event_args[type] = arguments;
} else {
return trigger.apply(self, arguments);
}
};
// invoke provided function
fn.apply(self, []);
self.trigger = trigger;
// trigger queued events
for (type in event_args) {
if (event_args.hasOwnProperty(type)) {
trigger.apply(self, event_args[type]);
}
}
} | javascript | function(self, types, fn) {
var type;
var trigger = self.trigger;
var event_args = {};
// override trigger method
self.trigger = function() {
var type = arguments[0];
if (types.indexOf(type) !== -1) {
event_args[type] = arguments;
} else {
return trigger.apply(self, arguments);
}
};
// invoke provided function
fn.apply(self, []);
self.trigger = trigger;
// trigger queued events
for (type in event_args) {
if (event_args.hasOwnProperty(type)) {
trigger.apply(self, event_args[type]);
}
}
} | [
"function",
"(",
"self",
",",
"types",
",",
"fn",
")",
"{",
"var",
"type",
";",
"var",
"trigger",
"=",
"self",
".",
"trigger",
";",
"var",
"event_args",
"=",
"{",
"}",
";",
"// override trigger method",
"self",
".",
"trigger",
"=",
"function",
"(",
")",
"{",
"var",
"type",
"=",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"types",
".",
"indexOf",
"(",
"type",
")",
"!==",
"-",
"1",
")",
"{",
"event_args",
"[",
"type",
"]",
"=",
"arguments",
";",
"}",
"else",
"{",
"return",
"trigger",
".",
"apply",
"(",
"self",
",",
"arguments",
")",
";",
"}",
"}",
";",
"// invoke provided function",
"fn",
".",
"apply",
"(",
"self",
",",
"[",
"]",
")",
";",
"self",
".",
"trigger",
"=",
"trigger",
";",
"// trigger queued events",
"for",
"(",
"type",
"in",
"event_args",
")",
"{",
"if",
"(",
"event_args",
".",
"hasOwnProperty",
"(",
"type",
")",
")",
"{",
"trigger",
".",
"apply",
"(",
"self",
",",
"event_args",
"[",
"type",
"]",
")",
";",
"}",
"}",
"}"
] | Debounce all fired events types listed in `types`
while executing the provided `fn`.
@param {object} self
@param {array} types
@param {function} fn | [
"Debounce",
"all",
"fired",
"events",
"types",
"listed",
"in",
"types",
"while",
"executing",
"the",
"provided",
"fn",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L864-L889 |
|
5,751 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function($from, $to, properties) {
var i, n, styles = {};
if (properties) {
for (i = 0, n = properties.length; i < n; i++) {
styles[properties[i]] = $from.css(properties[i]);
}
} else {
styles = $from.css();
}
$to.css(styles);
} | javascript | function($from, $to, properties) {
var i, n, styles = {};
if (properties) {
for (i = 0, n = properties.length; i < n; i++) {
styles[properties[i]] = $from.css(properties[i]);
}
} else {
styles = $from.css();
}
$to.css(styles);
} | [
"function",
"(",
"$from",
",",
"$to",
",",
"properties",
")",
"{",
"var",
"i",
",",
"n",
",",
"styles",
"=",
"{",
"}",
";",
"if",
"(",
"properties",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"n",
"=",
"properties",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"styles",
"[",
"properties",
"[",
"i",
"]",
"]",
"=",
"$from",
".",
"css",
"(",
"properties",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"styles",
"=",
"$from",
".",
"css",
"(",
")",
";",
"}",
"$to",
".",
"css",
"(",
"styles",
")",
";",
"}"
] | Copies CSS properties from one element to another.
@param {object} $from
@param {object} $to
@param {array} properties | [
"Copies",
"CSS",
"properties",
"from",
"one",
"element",
"to",
"another",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L942-L952 |
|
5,752 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
var field_label = self.settings.labelField;
var field_optgroup = self.settings.optgroupLabelField;
var templates = {
'optgroup': function(data) {
return '<div class="optgroup">' + data.html + '</div>';
},
'optgroup_header': function(data, escape) {
return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>';
},
'option': function(data, escape) {
return '<div class="option">' + escape(data[field_label]) + '</div>';
},
'item': function(data, escape) {
return '<div class="item">' + escape(data[field_label]) + '</div>';
},
'option_create': function(data, escape) {
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>';
}
};
self.settings.render = $.extend({}, templates, self.settings.render);
} | javascript | function() {
var self = this;
var field_label = self.settings.labelField;
var field_optgroup = self.settings.optgroupLabelField;
var templates = {
'optgroup': function(data) {
return '<div class="optgroup">' + data.html + '</div>';
},
'optgroup_header': function(data, escape) {
return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>';
},
'option': function(data, escape) {
return '<div class="option">' + escape(data[field_label]) + '</div>';
},
'item': function(data, escape) {
return '<div class="item">' + escape(data[field_label]) + '</div>';
},
'option_create': function(data, escape) {
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>';
}
};
self.settings.render = $.extend({}, templates, self.settings.render);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"field_label",
"=",
"self",
".",
"settings",
".",
"labelField",
";",
"var",
"field_optgroup",
"=",
"self",
".",
"settings",
".",
"optgroupLabelField",
";",
"var",
"templates",
"=",
"{",
"'optgroup'",
":",
"function",
"(",
"data",
")",
"{",
"return",
"'<div class=\"optgroup\">'",
"+",
"data",
".",
"html",
"+",
"'</div>'",
";",
"}",
",",
"'optgroup_header'",
":",
"function",
"(",
"data",
",",
"escape",
")",
"{",
"return",
"'<div class=\"optgroup-header\">'",
"+",
"escape",
"(",
"data",
"[",
"field_optgroup",
"]",
")",
"+",
"'</div>'",
";",
"}",
",",
"'option'",
":",
"function",
"(",
"data",
",",
"escape",
")",
"{",
"return",
"'<div class=\"option\">'",
"+",
"escape",
"(",
"data",
"[",
"field_label",
"]",
")",
"+",
"'</div>'",
";",
"}",
",",
"'item'",
":",
"function",
"(",
"data",
",",
"escape",
")",
"{",
"return",
"'<div class=\"item\">'",
"+",
"escape",
"(",
"data",
"[",
"field_label",
"]",
")",
"+",
"'</div>'",
";",
"}",
",",
"'option_create'",
":",
"function",
"(",
"data",
",",
"escape",
")",
"{",
"return",
"'<div class=\"create\">Add <strong>'",
"+",
"escape",
"(",
"data",
".",
"input",
")",
"+",
"'</strong>…</div>'",
";",
"}",
"}",
";",
"self",
".",
"settings",
".",
"render",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"templates",
",",
"self",
".",
"settings",
".",
"render",
")",
";",
"}"
] | Sets up default rendering functions. | [
"Sets",
"up",
"default",
"rendering",
"functions",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1330-L1354 |
|
5,753 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var key, fn, callbacks = {
'initialize' : 'onInitialize',
'change' : 'onChange',
'item_add' : 'onItemAdd',
'item_remove' : 'onItemRemove',
'clear' : 'onClear',
'option_add' : 'onOptionAdd',
'option_remove' : 'onOptionRemove',
'option_clear' : 'onOptionClear',
'optgroup_add' : 'onOptionGroupAdd',
'optgroup_remove' : 'onOptionGroupRemove',
'optgroup_clear' : 'onOptionGroupClear',
'dropdown_open' : 'onDropdownOpen',
'dropdown_close' : 'onDropdownClose',
'type' : 'onType',
'load' : 'onLoad',
'focus' : 'onFocus',
'blur' : 'onBlur'
};
for (key in callbacks) {
if (callbacks.hasOwnProperty(key)) {
fn = this.settings[callbacks[key]];
if (fn) this.on(key, fn);
}
}
} | javascript | function() {
var key, fn, callbacks = {
'initialize' : 'onInitialize',
'change' : 'onChange',
'item_add' : 'onItemAdd',
'item_remove' : 'onItemRemove',
'clear' : 'onClear',
'option_add' : 'onOptionAdd',
'option_remove' : 'onOptionRemove',
'option_clear' : 'onOptionClear',
'optgroup_add' : 'onOptionGroupAdd',
'optgroup_remove' : 'onOptionGroupRemove',
'optgroup_clear' : 'onOptionGroupClear',
'dropdown_open' : 'onDropdownOpen',
'dropdown_close' : 'onDropdownClose',
'type' : 'onType',
'load' : 'onLoad',
'focus' : 'onFocus',
'blur' : 'onBlur'
};
for (key in callbacks) {
if (callbacks.hasOwnProperty(key)) {
fn = this.settings[callbacks[key]];
if (fn) this.on(key, fn);
}
}
} | [
"function",
"(",
")",
"{",
"var",
"key",
",",
"fn",
",",
"callbacks",
"=",
"{",
"'initialize'",
":",
"'onInitialize'",
",",
"'change'",
":",
"'onChange'",
",",
"'item_add'",
":",
"'onItemAdd'",
",",
"'item_remove'",
":",
"'onItemRemove'",
",",
"'clear'",
":",
"'onClear'",
",",
"'option_add'",
":",
"'onOptionAdd'",
",",
"'option_remove'",
":",
"'onOptionRemove'",
",",
"'option_clear'",
":",
"'onOptionClear'",
",",
"'optgroup_add'",
":",
"'onOptionGroupAdd'",
",",
"'optgroup_remove'",
":",
"'onOptionGroupRemove'",
",",
"'optgroup_clear'",
":",
"'onOptionGroupClear'",
",",
"'dropdown_open'",
":",
"'onDropdownOpen'",
",",
"'dropdown_close'",
":",
"'onDropdownClose'",
",",
"'type'",
":",
"'onType'",
",",
"'load'",
":",
"'onLoad'",
",",
"'focus'",
":",
"'onFocus'",
",",
"'blur'",
":",
"'onBlur'",
"}",
";",
"for",
"(",
"key",
"in",
"callbacks",
")",
"{",
"if",
"(",
"callbacks",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"fn",
"=",
"this",
".",
"settings",
"[",
"callbacks",
"[",
"key",
"]",
"]",
";",
"if",
"(",
"fn",
")",
"this",
".",
"on",
"(",
"key",
",",
"fn",
")",
";",
"}",
"}",
"}"
] | Maps fired events to callbacks provided
in the settings used when creating the control. | [
"Maps",
"fired",
"events",
"to",
"callbacks",
"provided",
"in",
"the",
"settings",
"used",
"when",
"creating",
"the",
"control",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1360-L1387 |
|
5,754 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(e) {
var self = this;
var defaultPrevented = e.isDefaultPrevented();
var $target = $(e.target);
if (self.isFocused) {
// retain focus by preventing native handling. if the
// event target is the input it should not be modified.
// otherwise, text selection within the input won't work.
if (e.target !== self.$control_input[0]) {
if (self.settings.mode === 'single') {
// toggle dropdown
self.isOpen ? self.close() : self.open();
} else if (!defaultPrevented) {
self.setActiveItem(null);
}
return false;
}
} else {
// give control focus
if (!defaultPrevented) {
window.setTimeout(function() {
self.focus();
}, 0);
}
}
} | javascript | function(e) {
var self = this;
var defaultPrevented = e.isDefaultPrevented();
var $target = $(e.target);
if (self.isFocused) {
// retain focus by preventing native handling. if the
// event target is the input it should not be modified.
// otherwise, text selection within the input won't work.
if (e.target !== self.$control_input[0]) {
if (self.settings.mode === 'single') {
// toggle dropdown
self.isOpen ? self.close() : self.open();
} else if (!defaultPrevented) {
self.setActiveItem(null);
}
return false;
}
} else {
// give control focus
if (!defaultPrevented) {
window.setTimeout(function() {
self.focus();
}, 0);
}
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"defaultPrevented",
"=",
"e",
".",
"isDefaultPrevented",
"(",
")",
";",
"var",
"$target",
"=",
"$",
"(",
"e",
".",
"target",
")",
";",
"if",
"(",
"self",
".",
"isFocused",
")",
"{",
"// retain focus by preventing native handling. if the",
"// event target is the input it should not be modified.",
"// otherwise, text selection within the input won't work.",
"if",
"(",
"e",
".",
"target",
"!==",
"self",
".",
"$control_input",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"self",
".",
"settings",
".",
"mode",
"===",
"'single'",
")",
"{",
"// toggle dropdown",
"self",
".",
"isOpen",
"?",
"self",
".",
"close",
"(",
")",
":",
"self",
".",
"open",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"defaultPrevented",
")",
"{",
"self",
".",
"setActiveItem",
"(",
"null",
")",
";",
"}",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"// give control focus",
"if",
"(",
"!",
"defaultPrevented",
")",
"{",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"focus",
"(",
")",
";",
"}",
",",
"0",
")",
";",
"}",
"}",
"}"
] | Triggered when the main control element
has a mouse down event.
@param {object} e
@return {boolean} | [
"Triggered",
"when",
"the",
"main",
"control",
"element",
"has",
"a",
"mouse",
"down",
"event",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1414-L1440 |
|
5,755 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(e) {
var value, $target, $option, self = this;
if (e.preventDefault) {
e.preventDefault();
e.stopPropagation();
}
$target = $(e.currentTarget);
if ($target.hasClass('create')) {
self.createItem(null, function() {
if (self.settings.closeAfterSelect) {
self.close();
}
});
} else {
value = $target.attr('data-value');
if (typeof value !== 'undefined') {
self.lastQuery = null;
self.setTextboxValue('');
self.addItem(value);
if (self.settings.closeAfterSelect) {
self.close();
} else if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) {
self.setActiveOption(self.getOption(value));
}
}
}
} | javascript | function(e) {
var value, $target, $option, self = this;
if (e.preventDefault) {
e.preventDefault();
e.stopPropagation();
}
$target = $(e.currentTarget);
if ($target.hasClass('create')) {
self.createItem(null, function() {
if (self.settings.closeAfterSelect) {
self.close();
}
});
} else {
value = $target.attr('data-value');
if (typeof value !== 'undefined') {
self.lastQuery = null;
self.setTextboxValue('');
self.addItem(value);
if (self.settings.closeAfterSelect) {
self.close();
} else if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) {
self.setActiveOption(self.getOption(value));
}
}
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"value",
",",
"$target",
",",
"$option",
",",
"self",
"=",
"this",
";",
"if",
"(",
"e",
".",
"preventDefault",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"}",
"$target",
"=",
"$",
"(",
"e",
".",
"currentTarget",
")",
";",
"if",
"(",
"$target",
".",
"hasClass",
"(",
"'create'",
")",
")",
"{",
"self",
".",
"createItem",
"(",
"null",
",",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"settings",
".",
"closeAfterSelect",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"value",
"=",
"$target",
".",
"attr",
"(",
"'data-value'",
")",
";",
"if",
"(",
"typeof",
"value",
"!==",
"'undefined'",
")",
"{",
"self",
".",
"lastQuery",
"=",
"null",
";",
"self",
".",
"setTextboxValue",
"(",
"''",
")",
";",
"self",
".",
"addItem",
"(",
"value",
")",
";",
"if",
"(",
"self",
".",
"settings",
".",
"closeAfterSelect",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"self",
".",
"settings",
".",
"hideSelected",
"&&",
"e",
".",
"type",
"&&",
"/",
"mouse",
"/",
".",
"test",
"(",
"e",
".",
"type",
")",
")",
"{",
"self",
".",
"setActiveOption",
"(",
"self",
".",
"getOption",
"(",
"value",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Triggered when the user clicks on an option
in the autocomplete dropdown menu.
@param {object} e
@returns {boolean} | [
"Triggered",
"when",
"the",
"user",
"clicks",
"on",
"an",
"option",
"in",
"the",
"autocomplete",
"dropdown",
"menu",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1713-L1741 |
|
5,756 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(e) {
var self = this;
if (self.isLocked) return;
if (self.settings.mode === 'multi') {
e.preventDefault();
self.setActiveItem(e.currentTarget, e);
}
} | javascript | function(e) {
var self = this;
if (self.isLocked) return;
if (self.settings.mode === 'multi') {
e.preventDefault();
self.setActiveItem(e.currentTarget, e);
}
} | [
"function",
"(",
"e",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"self",
".",
"isLocked",
")",
"return",
";",
"if",
"(",
"self",
".",
"settings",
".",
"mode",
"===",
"'multi'",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"self",
".",
"setActiveItem",
"(",
"e",
".",
"currentTarget",
",",
"e",
")",
";",
"}",
"}"
] | Triggered when the user clicks on an item
that has been selected.
@param {object} e
@returns {boolean} | [
"Triggered",
"when",
"the",
"user",
"clicks",
"on",
"an",
"item",
"that",
"has",
"been",
"selected",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1750-L1758 |
|
5,757 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value) {
var $input = this.$control_input;
var changed = $input.val() !== value;
if (changed) {
$input.val(value).triggerHandler('update');
this.lastValue = value;
}
} | javascript | function(value) {
var $input = this.$control_input;
var changed = $input.val() !== value;
if (changed) {
$input.val(value).triggerHandler('update');
this.lastValue = value;
}
} | [
"function",
"(",
"value",
")",
"{",
"var",
"$input",
"=",
"this",
".",
"$control_input",
";",
"var",
"changed",
"=",
"$input",
".",
"val",
"(",
")",
"!==",
"value",
";",
"if",
"(",
"changed",
")",
"{",
"$input",
".",
"val",
"(",
"value",
")",
".",
"triggerHandler",
"(",
"'update'",
")",
";",
"this",
".",
"lastValue",
"=",
"value",
";",
"}",
"}"
] | Sets the input field of the control to the specified value.
@param {string} value | [
"Sets",
"the",
"input",
"field",
"of",
"the",
"control",
"to",
"the",
"specified",
"value",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1790-L1797 |
|
5,758 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value, silent) {
var events = silent ? [] : ['change'];
debounce_events(this, events, function() {
this.clear();
this.addItems(value, silent);
});
} | javascript | function(value, silent) {
var events = silent ? [] : ['change'];
debounce_events(this, events, function() {
this.clear();
this.addItems(value, silent);
});
} | [
"function",
"(",
"value",
",",
"silent",
")",
"{",
"var",
"events",
"=",
"silent",
"?",
"[",
"]",
":",
"[",
"'change'",
"]",
";",
"debounce_events",
"(",
"this",
",",
"events",
",",
"function",
"(",
")",
"{",
"this",
".",
"clear",
"(",
")",
";",
"this",
".",
"addItems",
"(",
"value",
",",
"silent",
")",
";",
"}",
")",
";",
"}"
] | Resets the selected items to the given value.
@param {mixed} value | [
"Resets",
"the",
"selected",
"items",
"to",
"the",
"given",
"value",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1820-L1827 |
|
5,759 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function($item, e) {
var self = this;
var eventName;
var i, idx, begin, end, item, swap;
var $last;
if (self.settings.mode === 'single') return;
$item = $($item);
// clear the active selection
if (!$item.length) {
$(self.$activeItems).removeClass('active');
self.$activeItems = [];
if (self.isFocused) {
self.showInput();
}
return;
}
// modify selection
eventName = e && e.type.toLowerCase();
if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) {
$last = self.$control.children('.active:last');
begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]);
end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]);
if (begin > end) {
swap = begin;
begin = end;
end = swap;
}
for (i = begin; i <= end; i++) {
item = self.$control[0].childNodes[i];
if (self.$activeItems.indexOf(item) === -1) {
$(item).addClass('active');
self.$activeItems.push(item);
}
}
e.preventDefault();
} else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) {
if ($item.hasClass('active')) {
idx = self.$activeItems.indexOf($item[0]);
self.$activeItems.splice(idx, 1);
$item.removeClass('active');
} else {
self.$activeItems.push($item.addClass('active')[0]);
}
} else {
$(self.$activeItems).removeClass('active');
self.$activeItems = [$item.addClass('active')[0]];
}
// ensure control has focus
self.hideInput();
if (!this.isFocused) {
self.focus();
}
} | javascript | function($item, e) {
var self = this;
var eventName;
var i, idx, begin, end, item, swap;
var $last;
if (self.settings.mode === 'single') return;
$item = $($item);
// clear the active selection
if (!$item.length) {
$(self.$activeItems).removeClass('active');
self.$activeItems = [];
if (self.isFocused) {
self.showInput();
}
return;
}
// modify selection
eventName = e && e.type.toLowerCase();
if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) {
$last = self.$control.children('.active:last');
begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]);
end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]);
if (begin > end) {
swap = begin;
begin = end;
end = swap;
}
for (i = begin; i <= end; i++) {
item = self.$control[0].childNodes[i];
if (self.$activeItems.indexOf(item) === -1) {
$(item).addClass('active');
self.$activeItems.push(item);
}
}
e.preventDefault();
} else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) {
if ($item.hasClass('active')) {
idx = self.$activeItems.indexOf($item[0]);
self.$activeItems.splice(idx, 1);
$item.removeClass('active');
} else {
self.$activeItems.push($item.addClass('active')[0]);
}
} else {
$(self.$activeItems).removeClass('active');
self.$activeItems = [$item.addClass('active')[0]];
}
// ensure control has focus
self.hideInput();
if (!this.isFocused) {
self.focus();
}
} | [
"function",
"(",
"$item",
",",
"e",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"eventName",
";",
"var",
"i",
",",
"idx",
",",
"begin",
",",
"end",
",",
"item",
",",
"swap",
";",
"var",
"$last",
";",
"if",
"(",
"self",
".",
"settings",
".",
"mode",
"===",
"'single'",
")",
"return",
";",
"$item",
"=",
"$",
"(",
"$item",
")",
";",
"// clear the active selection",
"if",
"(",
"!",
"$item",
".",
"length",
")",
"{",
"$",
"(",
"self",
".",
"$activeItems",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"self",
".",
"$activeItems",
"=",
"[",
"]",
";",
"if",
"(",
"self",
".",
"isFocused",
")",
"{",
"self",
".",
"showInput",
"(",
")",
";",
"}",
"return",
";",
"}",
"// modify selection",
"eventName",
"=",
"e",
"&&",
"e",
".",
"type",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"eventName",
"===",
"'mousedown'",
"&&",
"self",
".",
"isShiftDown",
"&&",
"self",
".",
"$activeItems",
".",
"length",
")",
"{",
"$last",
"=",
"self",
".",
"$control",
".",
"children",
"(",
"'.active:last'",
")",
";",
"begin",
"=",
"Array",
".",
"prototype",
".",
"indexOf",
".",
"apply",
"(",
"self",
".",
"$control",
"[",
"0",
"]",
".",
"childNodes",
",",
"[",
"$last",
"[",
"0",
"]",
"]",
")",
";",
"end",
"=",
"Array",
".",
"prototype",
".",
"indexOf",
".",
"apply",
"(",
"self",
".",
"$control",
"[",
"0",
"]",
".",
"childNodes",
",",
"[",
"$item",
"[",
"0",
"]",
"]",
")",
";",
"if",
"(",
"begin",
">",
"end",
")",
"{",
"swap",
"=",
"begin",
";",
"begin",
"=",
"end",
";",
"end",
"=",
"swap",
";",
"}",
"for",
"(",
"i",
"=",
"begin",
";",
"i",
"<=",
"end",
";",
"i",
"++",
")",
"{",
"item",
"=",
"self",
".",
"$control",
"[",
"0",
"]",
".",
"childNodes",
"[",
"i",
"]",
";",
"if",
"(",
"self",
".",
"$activeItems",
".",
"indexOf",
"(",
"item",
")",
"===",
"-",
"1",
")",
"{",
"$",
"(",
"item",
")",
".",
"addClass",
"(",
"'active'",
")",
";",
"self",
".",
"$activeItems",
".",
"push",
"(",
"item",
")",
";",
"}",
"}",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"else",
"if",
"(",
"(",
"eventName",
"===",
"'mousedown'",
"&&",
"self",
".",
"isCtrlDown",
")",
"||",
"(",
"eventName",
"===",
"'keydown'",
"&&",
"this",
".",
"isShiftDown",
")",
")",
"{",
"if",
"(",
"$item",
".",
"hasClass",
"(",
"'active'",
")",
")",
"{",
"idx",
"=",
"self",
".",
"$activeItems",
".",
"indexOf",
"(",
"$item",
"[",
"0",
"]",
")",
";",
"self",
".",
"$activeItems",
".",
"splice",
"(",
"idx",
",",
"1",
")",
";",
"$item",
".",
"removeClass",
"(",
"'active'",
")",
";",
"}",
"else",
"{",
"self",
".",
"$activeItems",
".",
"push",
"(",
"$item",
".",
"addClass",
"(",
"'active'",
")",
"[",
"0",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"(",
"self",
".",
"$activeItems",
")",
".",
"removeClass",
"(",
"'active'",
")",
";",
"self",
".",
"$activeItems",
"=",
"[",
"$item",
".",
"addClass",
"(",
"'active'",
")",
"[",
"0",
"]",
"]",
";",
"}",
"// ensure control has focus",
"self",
".",
"hideInput",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"isFocused",
")",
"{",
"self",
".",
"focus",
"(",
")",
";",
"}",
"}"
] | Sets the selected item.
@param {object} $item
@param {object} e (optional) | [
"Sets",
"the",
"selected",
"item",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1835-L1892 |
|
5,760 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
self.setTextboxValue('');
self.$control_input.css({opacity: 0, position: 'absolute', left: self.rtl ? 10000 : -10000});
self.isInputHidden = true;
} | javascript | function() {
var self = this;
self.setTextboxValue('');
self.$control_input.css({opacity: 0, position: 'absolute', left: self.rtl ? 10000 : -10000});
self.isInputHidden = true;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"setTextboxValue",
"(",
"''",
")",
";",
"self",
".",
"$control_input",
".",
"css",
"(",
"{",
"opacity",
":",
"0",
",",
"position",
":",
"'absolute'",
",",
"left",
":",
"self",
".",
"rtl",
"?",
"10000",
":",
"-",
"10000",
"}",
")",
";",
"self",
".",
"isInputHidden",
"=",
"true",
";",
"}"
] | Hides the input element out of view, while
retaining its focus. | [
"Hides",
"the",
"input",
"element",
"out",
"of",
"view",
"while",
"retaining",
"its",
"focus",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1952-L1958 |
|
5,761 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
if (self.isDisabled) return;
self.ignoreFocus = true;
self.$control_input[0].focus();
window.setTimeout(function() {
self.ignoreFocus = false;
self.onFocus();
}, 0);
} | javascript | function() {
var self = this;
if (self.isDisabled) return;
self.ignoreFocus = true;
self.$control_input[0].focus();
window.setTimeout(function() {
self.ignoreFocus = false;
self.onFocus();
}, 0);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"self",
".",
"isDisabled",
")",
"return",
";",
"self",
".",
"ignoreFocus",
"=",
"true",
";",
"self",
".",
"$control_input",
"[",
"0",
"]",
".",
"focus",
"(",
")",
";",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"self",
".",
"ignoreFocus",
"=",
"false",
";",
"self",
".",
"onFocus",
"(",
")",
";",
"}",
",",
"0",
")",
";",
"}"
] | Gives the control focus. | [
"Gives",
"the",
"control",
"focus",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L1971-L1981 |
|
5,762 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(query) {
var i, value, score, result, calculateScore;
var self = this;
var settings = self.settings;
var options = this.getSearchOptions();
// validate user-provided result scoring function
if (settings.score) {
calculateScore = self.settings.score.apply(this, [query]);
if (typeof calculateScore !== 'function') {
throw new Error('Selectize "score" setting must be a function that returns a function');
}
}
// perform search
if (query !== self.lastQuery) {
self.lastQuery = query;
result = self.sifter.search(query, $.extend(options, {score: calculateScore}));
self.currentResults = result;
} else {
result = $.extend(true, {}, self.currentResults);
}
// filter out selected items
if (settings.hideSelected) {
for (i = result.items.length - 1; i >= 0; i--) {
if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) {
result.items.splice(i, 1);
}
}
}
return result;
} | javascript | function(query) {
var i, value, score, result, calculateScore;
var self = this;
var settings = self.settings;
var options = this.getSearchOptions();
// validate user-provided result scoring function
if (settings.score) {
calculateScore = self.settings.score.apply(this, [query]);
if (typeof calculateScore !== 'function') {
throw new Error('Selectize "score" setting must be a function that returns a function');
}
}
// perform search
if (query !== self.lastQuery) {
self.lastQuery = query;
result = self.sifter.search(query, $.extend(options, {score: calculateScore}));
self.currentResults = result;
} else {
result = $.extend(true, {}, self.currentResults);
}
// filter out selected items
if (settings.hideSelected) {
for (i = result.items.length - 1; i >= 0; i--) {
if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) {
result.items.splice(i, 1);
}
}
}
return result;
} | [
"function",
"(",
"query",
")",
"{",
"var",
"i",
",",
"value",
",",
"score",
",",
"result",
",",
"calculateScore",
";",
"var",
"self",
"=",
"this",
";",
"var",
"settings",
"=",
"self",
".",
"settings",
";",
"var",
"options",
"=",
"this",
".",
"getSearchOptions",
"(",
")",
";",
"// validate user-provided result scoring function",
"if",
"(",
"settings",
".",
"score",
")",
"{",
"calculateScore",
"=",
"self",
".",
"settings",
".",
"score",
".",
"apply",
"(",
"this",
",",
"[",
"query",
"]",
")",
";",
"if",
"(",
"typeof",
"calculateScore",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Selectize \"score\" setting must be a function that returns a function'",
")",
";",
"}",
"}",
"// perform search",
"if",
"(",
"query",
"!==",
"self",
".",
"lastQuery",
")",
"{",
"self",
".",
"lastQuery",
"=",
"query",
";",
"result",
"=",
"self",
".",
"sifter",
".",
"search",
"(",
"query",
",",
"$",
".",
"extend",
"(",
"options",
",",
"{",
"score",
":",
"calculateScore",
"}",
")",
")",
";",
"self",
".",
"currentResults",
"=",
"result",
";",
"}",
"else",
"{",
"result",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"self",
".",
"currentResults",
")",
";",
"}",
"// filter out selected items",
"if",
"(",
"settings",
".",
"hideSelected",
")",
"{",
"for",
"(",
"i",
"=",
"result",
".",
"items",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"self",
".",
"items",
".",
"indexOf",
"(",
"hash_key",
"(",
"result",
".",
"items",
"[",
"i",
"]",
".",
"id",
")",
")",
"!==",
"-",
"1",
")",
"{",
"result",
".",
"items",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Searches through available options and returns
a sorted array of matches.
Returns an object containing:
- query {string}
- tokens {array}
- total {int}
- items {array}
@param {string} query
@returns {object} | [
"Searches",
"through",
"available",
"options",
"and",
"returns",
"a",
"sorted",
"array",
"of",
"matches",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2041-L2074 |
|
5,763 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(data) {
var key = hash_key(data[this.settings.optgroupValueField]);
if (!key) return false;
data.$order = data.$order || ++this.order;
this.optgroups[key] = data;
return key;
} | javascript | function(data) {
var key = hash_key(data[this.settings.optgroupValueField]);
if (!key) return false;
data.$order = data.$order || ++this.order;
this.optgroups[key] = data;
return key;
} | [
"function",
"(",
"data",
")",
"{",
"var",
"key",
"=",
"hash_key",
"(",
"data",
"[",
"this",
".",
"settings",
".",
"optgroupValueField",
"]",
")",
";",
"if",
"(",
"!",
"key",
")",
"return",
"false",
";",
"data",
".",
"$order",
"=",
"data",
".",
"$order",
"||",
"++",
"this",
".",
"order",
";",
"this",
".",
"optgroups",
"[",
"key",
"]",
"=",
"data",
";",
"return",
"key",
";",
"}"
] | Registers an option group to the pool of option groups.
@param {object} data
@return {boolean|string} | [
"Registers",
"an",
"option",
"group",
"to",
"the",
"pool",
"of",
"option",
"groups",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2251-L2258 |
|
5,764 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(id, data) {
data[this.settings.optgroupValueField] = id;
if (id = this.registerOptionGroup(data)) {
this.trigger('optgroup_add', id, data);
}
} | javascript | function(id, data) {
data[this.settings.optgroupValueField] = id;
if (id = this.registerOptionGroup(data)) {
this.trigger('optgroup_add', id, data);
}
} | [
"function",
"(",
"id",
",",
"data",
")",
"{",
"data",
"[",
"this",
".",
"settings",
".",
"optgroupValueField",
"]",
"=",
"id",
";",
"if",
"(",
"id",
"=",
"this",
".",
"registerOptionGroup",
"(",
"data",
")",
")",
"{",
"this",
".",
"trigger",
"(",
"'optgroup_add'",
",",
"id",
",",
"data",
")",
";",
"}",
"}"
] | Registers a new optgroup for options
to be bucketed into.
@param {string} id
@param {object} data | [
"Registers",
"a",
"new",
"optgroup",
"for",
"options",
"to",
"be",
"bucketed",
"into",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2267-L2272 |
|
5,765 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value, data) {
var self = this;
var $item, $item_new;
var value_new, index_item, cache_items, cache_options, order_old;
value = hash_key(value);
value_new = hash_key(data[self.settings.valueField]);
// sanity checks
if (value === null) return;
if (!self.options.hasOwnProperty(value)) return;
if (typeof value_new !== 'string') throw new Error('Value must be set in option data');
order_old = self.options[value].$order;
// update references
if (value_new !== value) {
delete self.options[value];
index_item = self.items.indexOf(value);
if (index_item !== -1) {
self.items.splice(index_item, 1, value_new);
}
}
data.$order = data.$order || order_old;
self.options[value_new] = data;
// invalidate render cache
cache_items = self.renderCache['item'];
cache_options = self.renderCache['option'];
if (cache_items) {
delete cache_items[value];
delete cache_items[value_new];
}
if (cache_options) {
delete cache_options[value];
delete cache_options[value_new];
}
// update the item if it's selected
if (self.items.indexOf(value_new) !== -1) {
$item = self.getItem(value);
$item_new = $(self.render('item', data));
if ($item.hasClass('active')) $item_new.addClass('active');
$item.replaceWith($item_new);
}
// invalidate last query because we might have updated the sortField
self.lastQuery = null;
// update dropdown contents
if (self.isOpen) {
self.refreshOptions(false);
}
} | javascript | function(value, data) {
var self = this;
var $item, $item_new;
var value_new, index_item, cache_items, cache_options, order_old;
value = hash_key(value);
value_new = hash_key(data[self.settings.valueField]);
// sanity checks
if (value === null) return;
if (!self.options.hasOwnProperty(value)) return;
if (typeof value_new !== 'string') throw new Error('Value must be set in option data');
order_old = self.options[value].$order;
// update references
if (value_new !== value) {
delete self.options[value];
index_item = self.items.indexOf(value);
if (index_item !== -1) {
self.items.splice(index_item, 1, value_new);
}
}
data.$order = data.$order || order_old;
self.options[value_new] = data;
// invalidate render cache
cache_items = self.renderCache['item'];
cache_options = self.renderCache['option'];
if (cache_items) {
delete cache_items[value];
delete cache_items[value_new];
}
if (cache_options) {
delete cache_options[value];
delete cache_options[value_new];
}
// update the item if it's selected
if (self.items.indexOf(value_new) !== -1) {
$item = self.getItem(value);
$item_new = $(self.render('item', data));
if ($item.hasClass('active')) $item_new.addClass('active');
$item.replaceWith($item_new);
}
// invalidate last query because we might have updated the sortField
self.lastQuery = null;
// update dropdown contents
if (self.isOpen) {
self.refreshOptions(false);
}
} | [
"function",
"(",
"value",
",",
"data",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"$item",
",",
"$item_new",
";",
"var",
"value_new",
",",
"index_item",
",",
"cache_items",
",",
"cache_options",
",",
"order_old",
";",
"value",
"=",
"hash_key",
"(",
"value",
")",
";",
"value_new",
"=",
"hash_key",
"(",
"data",
"[",
"self",
".",
"settings",
".",
"valueField",
"]",
")",
";",
"// sanity checks",
"if",
"(",
"value",
"===",
"null",
")",
"return",
";",
"if",
"(",
"!",
"self",
".",
"options",
".",
"hasOwnProperty",
"(",
"value",
")",
")",
"return",
";",
"if",
"(",
"typeof",
"value_new",
"!==",
"'string'",
")",
"throw",
"new",
"Error",
"(",
"'Value must be set in option data'",
")",
";",
"order_old",
"=",
"self",
".",
"options",
"[",
"value",
"]",
".",
"$order",
";",
"// update references",
"if",
"(",
"value_new",
"!==",
"value",
")",
"{",
"delete",
"self",
".",
"options",
"[",
"value",
"]",
";",
"index_item",
"=",
"self",
".",
"items",
".",
"indexOf",
"(",
"value",
")",
";",
"if",
"(",
"index_item",
"!==",
"-",
"1",
")",
"{",
"self",
".",
"items",
".",
"splice",
"(",
"index_item",
",",
"1",
",",
"value_new",
")",
";",
"}",
"}",
"data",
".",
"$order",
"=",
"data",
".",
"$order",
"||",
"order_old",
";",
"self",
".",
"options",
"[",
"value_new",
"]",
"=",
"data",
";",
"// invalidate render cache",
"cache_items",
"=",
"self",
".",
"renderCache",
"[",
"'item'",
"]",
";",
"cache_options",
"=",
"self",
".",
"renderCache",
"[",
"'option'",
"]",
";",
"if",
"(",
"cache_items",
")",
"{",
"delete",
"cache_items",
"[",
"value",
"]",
";",
"delete",
"cache_items",
"[",
"value_new",
"]",
";",
"}",
"if",
"(",
"cache_options",
")",
"{",
"delete",
"cache_options",
"[",
"value",
"]",
";",
"delete",
"cache_options",
"[",
"value_new",
"]",
";",
"}",
"// update the item if it's selected",
"if",
"(",
"self",
".",
"items",
".",
"indexOf",
"(",
"value_new",
")",
"!==",
"-",
"1",
")",
"{",
"$item",
"=",
"self",
".",
"getItem",
"(",
"value",
")",
";",
"$item_new",
"=",
"$",
"(",
"self",
".",
"render",
"(",
"'item'",
",",
"data",
")",
")",
";",
"if",
"(",
"$item",
".",
"hasClass",
"(",
"'active'",
")",
")",
"$item_new",
".",
"addClass",
"(",
"'active'",
")",
";",
"$item",
".",
"replaceWith",
"(",
"$item_new",
")",
";",
"}",
"// invalidate last query because we might have updated the sortField",
"self",
".",
"lastQuery",
"=",
"null",
";",
"// update dropdown contents",
"if",
"(",
"self",
".",
"isOpen",
")",
"{",
"self",
".",
"refreshOptions",
"(",
"false",
")",
";",
"}",
"}"
] | Updates an option available for selection. If
it is visible in the selected items or options
dropdown, it will be re-rendered automatically.
@param {string} value
@param {object} data | [
"Updates",
"an",
"option",
"available",
"for",
"selection",
".",
"If",
"it",
"is",
"visible",
"in",
"the",
"selected",
"items",
"or",
"options",
"dropdown",
"it",
"will",
"be",
"re",
"-",
"rendered",
"automatically",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2304-L2358 |
|
5,766 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value, silent) {
var self = this;
value = hash_key(value);
var cache_items = self.renderCache['item'];
var cache_options = self.renderCache['option'];
if (cache_items) delete cache_items[value];
if (cache_options) delete cache_options[value];
delete self.userOptions[value];
delete self.options[value];
self.lastQuery = null;
self.trigger('option_remove', value);
self.removeItem(value, silent);
} | javascript | function(value, silent) {
var self = this;
value = hash_key(value);
var cache_items = self.renderCache['item'];
var cache_options = self.renderCache['option'];
if (cache_items) delete cache_items[value];
if (cache_options) delete cache_options[value];
delete self.userOptions[value];
delete self.options[value];
self.lastQuery = null;
self.trigger('option_remove', value);
self.removeItem(value, silent);
} | [
"function",
"(",
"value",
",",
"silent",
")",
"{",
"var",
"self",
"=",
"this",
";",
"value",
"=",
"hash_key",
"(",
"value",
")",
";",
"var",
"cache_items",
"=",
"self",
".",
"renderCache",
"[",
"'item'",
"]",
";",
"var",
"cache_options",
"=",
"self",
".",
"renderCache",
"[",
"'option'",
"]",
";",
"if",
"(",
"cache_items",
")",
"delete",
"cache_items",
"[",
"value",
"]",
";",
"if",
"(",
"cache_options",
")",
"delete",
"cache_options",
"[",
"value",
"]",
";",
"delete",
"self",
".",
"userOptions",
"[",
"value",
"]",
";",
"delete",
"self",
".",
"options",
"[",
"value",
"]",
";",
"self",
".",
"lastQuery",
"=",
"null",
";",
"self",
".",
"trigger",
"(",
"'option_remove'",
",",
"value",
")",
";",
"self",
".",
"removeItem",
"(",
"value",
",",
"silent",
")",
";",
"}"
] | Removes a single option.
@param {string} value
@param {boolean} silent | [
"Removes",
"a",
"single",
"option",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2366-L2380 |
|
5,767 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
self.loadedSearches = {};
self.userOptions = {};
self.renderCache = {};
self.options = self.sifter.items = {};
self.lastQuery = null;
self.trigger('option_clear');
self.clear();
} | javascript | function() {
var self = this;
self.loadedSearches = {};
self.userOptions = {};
self.renderCache = {};
self.options = self.sifter.items = {};
self.lastQuery = null;
self.trigger('option_clear');
self.clear();
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"loadedSearches",
"=",
"{",
"}",
";",
"self",
".",
"userOptions",
"=",
"{",
"}",
";",
"self",
".",
"renderCache",
"=",
"{",
"}",
";",
"self",
".",
"options",
"=",
"self",
".",
"sifter",
".",
"items",
"=",
"{",
"}",
";",
"self",
".",
"lastQuery",
"=",
"null",
";",
"self",
".",
"trigger",
"(",
"'option_clear'",
")",
";",
"self",
".",
"clear",
"(",
")",
";",
"}"
] | Clears all options. | [
"Clears",
"all",
"options",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2385-L2395 |
|
5,768 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(value, $els) {
value = hash_key(value);
if (typeof value !== 'undefined' && value !== null) {
for (var i = 0, n = $els.length; i < n; i++) {
if ($els[i].getAttribute('data-value') === value) {
return $($els[i]);
}
}
}
return $();
} | javascript | function(value, $els) {
value = hash_key(value);
if (typeof value !== 'undefined' && value !== null) {
for (var i = 0, n = $els.length; i < n; i++) {
if ($els[i].getAttribute('data-value') === value) {
return $($els[i]);
}
}
}
return $();
} | [
"function",
"(",
"value",
",",
"$els",
")",
"{",
"value",
"=",
"hash_key",
"(",
"value",
")",
";",
"if",
"(",
"typeof",
"value",
"!==",
"'undefined'",
"&&",
"value",
"!==",
"null",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"$els",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"if",
"(",
"$els",
"[",
"i",
"]",
".",
"getAttribute",
"(",
"'data-value'",
")",
"===",
"value",
")",
"{",
"return",
"$",
"(",
"$els",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"(",
")",
";",
"}"
] | Finds the first element with a "data-value" attribute
that matches the given value.
@param {mixed} value
@param {object} $els
@return {object} | [
"Finds",
"the",
"first",
"element",
"with",
"a",
"data",
"-",
"value",
"attribute",
"that",
"matches",
"the",
"given",
"value",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2431-L2443 |
|
5,769 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(values, silent) {
var items = $.isArray(values) ? values : [values];
for (var i = 0, n = items.length; i < n; i++) {
this.isPending = (i < n - 1);
this.addItem(items[i], silent);
}
} | javascript | function(values, silent) {
var items = $.isArray(values) ? values : [values];
for (var i = 0, n = items.length; i < n; i++) {
this.isPending = (i < n - 1);
this.addItem(items[i], silent);
}
} | [
"function",
"(",
"values",
",",
"silent",
")",
"{",
"var",
"items",
"=",
"$",
".",
"isArray",
"(",
"values",
")",
"?",
"values",
":",
"[",
"values",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"items",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"this",
".",
"isPending",
"=",
"(",
"i",
"<",
"n",
"-",
"1",
")",
";",
"this",
".",
"addItem",
"(",
"items",
"[",
"i",
"]",
",",
"silent",
")",
";",
"}",
"}"
] | "Selects" multiple items at once. Adds them to the list
at the current caret position.
@param {string} value
@param {boolean} silent | [
"Selects",
"multiple",
"items",
"at",
"once",
".",
"Adds",
"them",
"to",
"the",
"list",
"at",
"the",
"current",
"caret",
"position",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2463-L2469 |
|
5,770 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(input, triggerDropdown) {
var self = this;
var caret = self.caretPos;
input = input || $.trim(self.$control_input.val() || '');
var callback = arguments[arguments.length - 1];
if (typeof callback !== 'function') callback = function() {};
if (typeof triggerDropdown !== 'boolean') {
triggerDropdown = true;
}
if (!self.canCreate(input)) {
callback();
return false;
}
self.lock();
var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
var data = {};
data[self.settings.labelField] = input;
data[self.settings.valueField] = input;
return data;
};
var create = once(function(data) {
self.unlock();
if (!data || typeof data !== 'object') return callback();
var value = hash_key(data[self.settings.valueField]);
if (typeof value !== 'string') return callback();
self.setTextboxValue('');
self.addOption(data);
self.setCaret(caret);
self.addItem(value);
self.refreshOptions(triggerDropdown && self.settings.mode !== 'single');
callback(data);
});
var output = setup.apply(this, [input, create]);
if (typeof output !== 'undefined') {
create(output);
}
return true;
} | javascript | function(input, triggerDropdown) {
var self = this;
var caret = self.caretPos;
input = input || $.trim(self.$control_input.val() || '');
var callback = arguments[arguments.length - 1];
if (typeof callback !== 'function') callback = function() {};
if (typeof triggerDropdown !== 'boolean') {
triggerDropdown = true;
}
if (!self.canCreate(input)) {
callback();
return false;
}
self.lock();
var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
var data = {};
data[self.settings.labelField] = input;
data[self.settings.valueField] = input;
return data;
};
var create = once(function(data) {
self.unlock();
if (!data || typeof data !== 'object') return callback();
var value = hash_key(data[self.settings.valueField]);
if (typeof value !== 'string') return callback();
self.setTextboxValue('');
self.addOption(data);
self.setCaret(caret);
self.addItem(value);
self.refreshOptions(triggerDropdown && self.settings.mode !== 'single');
callback(data);
});
var output = setup.apply(this, [input, create]);
if (typeof output !== 'undefined') {
create(output);
}
return true;
} | [
"function",
"(",
"input",
",",
"triggerDropdown",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"caret",
"=",
"self",
".",
"caretPos",
";",
"input",
"=",
"input",
"||",
"$",
".",
"trim",
"(",
"self",
".",
"$control_input",
".",
"val",
"(",
")",
"||",
"''",
")",
";",
"var",
"callback",
"=",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"callback",
"=",
"function",
"(",
")",
"{",
"}",
";",
"if",
"(",
"typeof",
"triggerDropdown",
"!==",
"'boolean'",
")",
"{",
"triggerDropdown",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"self",
".",
"canCreate",
"(",
"input",
")",
")",
"{",
"callback",
"(",
")",
";",
"return",
"false",
";",
"}",
"self",
".",
"lock",
"(",
")",
";",
"var",
"setup",
"=",
"(",
"typeof",
"self",
".",
"settings",
".",
"create",
"===",
"'function'",
")",
"?",
"this",
".",
"settings",
".",
"create",
":",
"function",
"(",
"input",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"data",
"[",
"self",
".",
"settings",
".",
"labelField",
"]",
"=",
"input",
";",
"data",
"[",
"self",
".",
"settings",
".",
"valueField",
"]",
"=",
"input",
";",
"return",
"data",
";",
"}",
";",
"var",
"create",
"=",
"once",
"(",
"function",
"(",
"data",
")",
"{",
"self",
".",
"unlock",
"(",
")",
";",
"if",
"(",
"!",
"data",
"||",
"typeof",
"data",
"!==",
"'object'",
")",
"return",
"callback",
"(",
")",
";",
"var",
"value",
"=",
"hash_key",
"(",
"data",
"[",
"self",
".",
"settings",
".",
"valueField",
"]",
")",
";",
"if",
"(",
"typeof",
"value",
"!==",
"'string'",
")",
"return",
"callback",
"(",
")",
";",
"self",
".",
"setTextboxValue",
"(",
"''",
")",
";",
"self",
".",
"addOption",
"(",
"data",
")",
";",
"self",
".",
"setCaret",
"(",
"caret",
")",
";",
"self",
".",
"addItem",
"(",
"value",
")",
";",
"self",
".",
"refreshOptions",
"(",
"triggerDropdown",
"&&",
"self",
".",
"settings",
".",
"mode",
"!==",
"'single'",
")",
";",
"callback",
"(",
"data",
")",
";",
"}",
")",
";",
"var",
"output",
"=",
"setup",
".",
"apply",
"(",
"this",
",",
"[",
"input",
",",
"create",
"]",
")",
";",
"if",
"(",
"typeof",
"output",
"!==",
"'undefined'",
")",
"{",
"create",
"(",
"output",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Invokes the `create` method provided in the
selectize options that should provide the data
for the new item, given the user input.
Once this completes, it will be added
to the item list.
@param {string} value
@param {boolean} [triggerDropdown]
@param {function} [callback]
@return {boolean} | [
"Invokes",
"the",
"create",
"method",
"provided",
"in",
"the",
"selectize",
"options",
"that",
"should",
"provide",
"the",
"data",
"for",
"the",
"new",
"item",
"given",
"the",
"user",
"input",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2584-L2631 |
|
5,771 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var invalid, self = this;
if (self.isRequired) {
if (self.items.length) self.isInvalid = false;
self.$control_input.prop('required', invalid);
}
self.refreshClasses();
} | javascript | function() {
var invalid, self = this;
if (self.isRequired) {
if (self.items.length) self.isInvalid = false;
self.$control_input.prop('required', invalid);
}
self.refreshClasses();
} | [
"function",
"(",
")",
"{",
"var",
"invalid",
",",
"self",
"=",
"this",
";",
"if",
"(",
"self",
".",
"isRequired",
")",
"{",
"if",
"(",
"self",
".",
"items",
".",
"length",
")",
"self",
".",
"isInvalid",
"=",
"false",
";",
"self",
".",
"$control_input",
".",
"prop",
"(",
"'required'",
",",
"invalid",
")",
";",
"}",
"self",
".",
"refreshClasses",
"(",
")",
";",
"}"
] | Updates all state-dependent attributes
and CSS classes. | [
"Updates",
"all",
"state",
"-",
"dependent",
"attributes",
"and",
"CSS",
"classes",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2651-L2658 |
|
5,772 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
var isFull = self.isFull();
var isLocked = self.isLocked;
self.$wrapper
.toggleClass('rtl', self.rtl);
self.$control
.toggleClass('focus', self.isFocused)
.toggleClass('disabled', self.isDisabled)
.toggleClass('required', self.isRequired)
.toggleClass('invalid', self.isInvalid)
.toggleClass('locked', isLocked)
.toggleClass('full', isFull).toggleClass('not-full', !isFull)
.toggleClass('input-active', self.isFocused && !self.isInputHidden)
.toggleClass('dropdown-active', self.isOpen)
.toggleClass('has-options', !$.isEmptyObject(self.options))
.toggleClass('has-items', self.items.length > 0);
self.$control_input.data('grow', !isFull && !isLocked);
} | javascript | function() {
var self = this;
var isFull = self.isFull();
var isLocked = self.isLocked;
self.$wrapper
.toggleClass('rtl', self.rtl);
self.$control
.toggleClass('focus', self.isFocused)
.toggleClass('disabled', self.isDisabled)
.toggleClass('required', self.isRequired)
.toggleClass('invalid', self.isInvalid)
.toggleClass('locked', isLocked)
.toggleClass('full', isFull).toggleClass('not-full', !isFull)
.toggleClass('input-active', self.isFocused && !self.isInputHidden)
.toggleClass('dropdown-active', self.isOpen)
.toggleClass('has-options', !$.isEmptyObject(self.options))
.toggleClass('has-items', self.items.length > 0);
self.$control_input.data('grow', !isFull && !isLocked);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"isFull",
"=",
"self",
".",
"isFull",
"(",
")",
";",
"var",
"isLocked",
"=",
"self",
".",
"isLocked",
";",
"self",
".",
"$wrapper",
".",
"toggleClass",
"(",
"'rtl'",
",",
"self",
".",
"rtl",
")",
";",
"self",
".",
"$control",
".",
"toggleClass",
"(",
"'focus'",
",",
"self",
".",
"isFocused",
")",
".",
"toggleClass",
"(",
"'disabled'",
",",
"self",
".",
"isDisabled",
")",
".",
"toggleClass",
"(",
"'required'",
",",
"self",
".",
"isRequired",
")",
".",
"toggleClass",
"(",
"'invalid'",
",",
"self",
".",
"isInvalid",
")",
".",
"toggleClass",
"(",
"'locked'",
",",
"isLocked",
")",
".",
"toggleClass",
"(",
"'full'",
",",
"isFull",
")",
".",
"toggleClass",
"(",
"'not-full'",
",",
"!",
"isFull",
")",
".",
"toggleClass",
"(",
"'input-active'",
",",
"self",
".",
"isFocused",
"&&",
"!",
"self",
".",
"isInputHidden",
")",
".",
"toggleClass",
"(",
"'dropdown-active'",
",",
"self",
".",
"isOpen",
")",
".",
"toggleClass",
"(",
"'has-options'",
",",
"!",
"$",
".",
"isEmptyObject",
"(",
"self",
".",
"options",
")",
")",
".",
"toggleClass",
"(",
"'has-items'",
",",
"self",
".",
"items",
".",
"length",
">",
"0",
")",
";",
"self",
".",
"$control_input",
".",
"data",
"(",
"'grow'",
",",
"!",
"isFull",
"&&",
"!",
"isLocked",
")",
";",
"}"
] | Updates all state-dependent CSS classes. | [
"Updates",
"all",
"state",
"-",
"dependent",
"CSS",
"classes",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2663-L2684 |
|
5,773 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return;
self.focus();
self.isOpen = true;
self.refreshState();
self.$dropdown.css({visibility: 'hidden', display: 'block'});
self.positionDropdown();
self.$dropdown.css({visibility: 'visible'});
self.trigger('dropdown_open', self.$dropdown);
} | javascript | function() {
var self = this;
if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return;
self.focus();
self.isOpen = true;
self.refreshState();
self.$dropdown.css({visibility: 'hidden', display: 'block'});
self.positionDropdown();
self.$dropdown.css({visibility: 'visible'});
self.trigger('dropdown_open', self.$dropdown);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"self",
".",
"isLocked",
"||",
"self",
".",
"isOpen",
"||",
"(",
"self",
".",
"settings",
".",
"mode",
"===",
"'multi'",
"&&",
"self",
".",
"isFull",
"(",
")",
")",
")",
"return",
";",
"self",
".",
"focus",
"(",
")",
";",
"self",
".",
"isOpen",
"=",
"true",
";",
"self",
".",
"refreshState",
"(",
")",
";",
"self",
".",
"$dropdown",
".",
"css",
"(",
"{",
"visibility",
":",
"'hidden'",
",",
"display",
":",
"'block'",
"}",
")",
";",
"self",
".",
"positionDropdown",
"(",
")",
";",
"self",
".",
"$dropdown",
".",
"css",
"(",
"{",
"visibility",
":",
"'visible'",
"}",
")",
";",
"self",
".",
"trigger",
"(",
"'dropdown_open'",
",",
"self",
".",
"$dropdown",
")",
";",
"}"
] | Shows the autocomplete dropdown containing
the available options. | [
"Shows",
"the",
"autocomplete",
"dropdown",
"containing",
"the",
"available",
"options",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2746-L2757 |
|
5,774 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var $control = this.$control;
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
offset.top += $control.outerHeight(true);
this.$dropdown.css({
width : $control.outerWidth(),
top : offset.top,
left : offset.left
});
} | javascript | function() {
var $control = this.$control;
var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
offset.top += $control.outerHeight(true);
this.$dropdown.css({
width : $control.outerWidth(),
top : offset.top,
left : offset.left
});
} | [
"function",
"(",
")",
"{",
"var",
"$control",
"=",
"this",
".",
"$control",
";",
"var",
"offset",
"=",
"this",
".",
"settings",
".",
"dropdownParent",
"===",
"'body'",
"?",
"$control",
".",
"offset",
"(",
")",
":",
"$control",
".",
"position",
"(",
")",
";",
"offset",
".",
"top",
"+=",
"$control",
".",
"outerHeight",
"(",
"true",
")",
";",
"this",
".",
"$dropdown",
".",
"css",
"(",
"{",
"width",
":",
"$control",
".",
"outerWidth",
"(",
")",
",",
"top",
":",
"offset",
".",
"top",
",",
"left",
":",
"offset",
".",
"left",
"}",
")",
";",
"}"
] | Calculates and applies the appropriate
position of the dropdown. | [
"Calculates",
"and",
"applies",
"the",
"appropriate",
"position",
"of",
"the",
"dropdown",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2782-L2792 |
|
5,775 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function($el) {
var caret = Math.min(this.caretPos, this.items.length);
if (caret === 0) {
this.$control.prepend($el);
} else {
$(this.$control[0].childNodes[caret]).before($el);
}
this.setCaret(caret + 1);
} | javascript | function($el) {
var caret = Math.min(this.caretPos, this.items.length);
if (caret === 0) {
this.$control.prepend($el);
} else {
$(this.$control[0].childNodes[caret]).before($el);
}
this.setCaret(caret + 1);
} | [
"function",
"(",
"$el",
")",
"{",
"var",
"caret",
"=",
"Math",
".",
"min",
"(",
"this",
".",
"caretPos",
",",
"this",
".",
"items",
".",
"length",
")",
";",
"if",
"(",
"caret",
"===",
"0",
")",
"{",
"this",
".",
"$control",
".",
"prepend",
"(",
"$el",
")",
";",
"}",
"else",
"{",
"$",
"(",
"this",
".",
"$control",
"[",
"0",
"]",
".",
"childNodes",
"[",
"caret",
"]",
")",
".",
"before",
"(",
"$el",
")",
";",
"}",
"this",
".",
"setCaret",
"(",
"caret",
"+",
"1",
")",
";",
"}"
] | A helper method for inserting an element
at the current caret position.
@param {object} $el | [
"A",
"helper",
"method",
"for",
"inserting",
"an",
"element",
"at",
"the",
"current",
"caret",
"position",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2822-L2830 |
|
5,776 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(i) {
var self = this;
if (self.settings.mode === 'single') {
i = self.items.length;
} else {
i = Math.max(0, Math.min(self.items.length, i));
}
if(!self.isPending) {
// the input must be moved by leaving it in place and moving the
// siblings, due to the fact that focus cannot be restored once lost
// on mobile webkit devices
var j, n, fn, $children, $child;
$children = self.$control.children(':not(input)');
for (j = 0, n = $children.length; j < n; j++) {
$child = $($children[j]).detach();
if (j < i) {
self.$control_input.before($child);
} else {
self.$control.append($child);
}
}
}
self.caretPos = i;
} | javascript | function(i) {
var self = this;
if (self.settings.mode === 'single') {
i = self.items.length;
} else {
i = Math.max(0, Math.min(self.items.length, i));
}
if(!self.isPending) {
// the input must be moved by leaving it in place and moving the
// siblings, due to the fact that focus cannot be restored once lost
// on mobile webkit devices
var j, n, fn, $children, $child;
$children = self.$control.children(':not(input)');
for (j = 0, n = $children.length; j < n; j++) {
$child = $($children[j]).detach();
if (j < i) {
self.$control_input.before($child);
} else {
self.$control.append($child);
}
}
}
self.caretPos = i;
} | [
"function",
"(",
"i",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"self",
".",
"settings",
".",
"mode",
"===",
"'single'",
")",
"{",
"i",
"=",
"self",
".",
"items",
".",
"length",
";",
"}",
"else",
"{",
"i",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"self",
".",
"items",
".",
"length",
",",
"i",
")",
")",
";",
"}",
"if",
"(",
"!",
"self",
".",
"isPending",
")",
"{",
"// the input must be moved by leaving it in place and moving the",
"// siblings, due to the fact that focus cannot be restored once lost",
"// on mobile webkit devices",
"var",
"j",
",",
"n",
",",
"fn",
",",
"$children",
",",
"$child",
";",
"$children",
"=",
"self",
".",
"$control",
".",
"children",
"(",
"':not(input)'",
")",
";",
"for",
"(",
"j",
"=",
"0",
",",
"n",
"=",
"$children",
".",
"length",
";",
"j",
"<",
"n",
";",
"j",
"++",
")",
"{",
"$child",
"=",
"$",
"(",
"$children",
"[",
"j",
"]",
")",
".",
"detach",
"(",
")",
";",
"if",
"(",
"j",
"<",
"i",
")",
"{",
"self",
".",
"$control_input",
".",
"before",
"(",
"$child",
")",
";",
"}",
"else",
"{",
"self",
".",
"$control",
".",
"append",
"(",
"$child",
")",
";",
"}",
"}",
"}",
"self",
".",
"caretPos",
"=",
"i",
";",
"}"
] | Moves the caret to the specified index.
@param {int} i | [
"Moves",
"the",
"caret",
"to",
"the",
"specified",
"index",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L2968-L2994 |
|
5,777 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
self.$input.prop('disabled', true);
self.$control_input.prop('disabled', true).prop('tabindex', -1);
self.isDisabled = true;
self.lock();
} | javascript | function() {
var self = this;
self.$input.prop('disabled', true);
self.$control_input.prop('disabled', true).prop('tabindex', -1);
self.isDisabled = true;
self.lock();
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"$input",
".",
"prop",
"(",
"'disabled'",
",",
"true",
")",
";",
"self",
".",
"$control_input",
".",
"prop",
"(",
"'disabled'",
",",
"true",
")",
".",
"prop",
"(",
"'tabindex'",
",",
"-",
"1",
")",
";",
"self",
".",
"isDisabled",
"=",
"true",
";",
"self",
".",
"lock",
"(",
")",
";",
"}"
] | Disables user input on the control completely.
While disabled, it cannot receive focus. | [
"Disables",
"user",
"input",
"on",
"the",
"control",
"completely",
".",
"While",
"disabled",
"it",
"cannot",
"receive",
"focus",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L3018-L3024 |
|
5,778 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
self.$input.prop('disabled', false);
self.$control_input.prop('disabled', false).prop('tabindex', self.tabIndex);
self.isDisabled = false;
self.unlock();
} | javascript | function() {
var self = this;
self.$input.prop('disabled', false);
self.$control_input.prop('disabled', false).prop('tabindex', self.tabIndex);
self.isDisabled = false;
self.unlock();
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"$input",
".",
"prop",
"(",
"'disabled'",
",",
"false",
")",
";",
"self",
".",
"$control_input",
".",
"prop",
"(",
"'disabled'",
",",
"false",
")",
".",
"prop",
"(",
"'tabindex'",
",",
"self",
".",
"tabIndex",
")",
";",
"self",
".",
"isDisabled",
"=",
"false",
";",
"self",
".",
"unlock",
"(",
")",
";",
"}"
] | Enables the control so that it can respond
to focus and user input. | [
"Enables",
"the",
"control",
"so",
"that",
"it",
"can",
"respond",
"to",
"focus",
"and",
"user",
"input",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L3030-L3036 |
|
5,779 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function() {
var self = this;
var eventNS = self.eventNS;
var revertSettings = self.revertSettings;
self.trigger('destroy');
self.off();
self.$wrapper.remove();
self.$dropdown.remove();
self.$input
.html('')
.append(revertSettings.$children)
.removeAttr('tabindex')
.removeClass('selectized')
.attr({tabindex: revertSettings.tabindex})
.show();
self.$control_input.removeData('grow');
self.$input.removeData('selectize');
$(window).off(eventNS);
$(document).off(eventNS);
$(document.body).off(eventNS);
delete self.$input[0].selectize;
} | javascript | function() {
var self = this;
var eventNS = self.eventNS;
var revertSettings = self.revertSettings;
self.trigger('destroy');
self.off();
self.$wrapper.remove();
self.$dropdown.remove();
self.$input
.html('')
.append(revertSettings.$children)
.removeAttr('tabindex')
.removeClass('selectized')
.attr({tabindex: revertSettings.tabindex})
.show();
self.$control_input.removeData('grow');
self.$input.removeData('selectize');
$(window).off(eventNS);
$(document).off(eventNS);
$(document.body).off(eventNS);
delete self.$input[0].selectize;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"eventNS",
"=",
"self",
".",
"eventNS",
";",
"var",
"revertSettings",
"=",
"self",
".",
"revertSettings",
";",
"self",
".",
"trigger",
"(",
"'destroy'",
")",
";",
"self",
".",
"off",
"(",
")",
";",
"self",
".",
"$wrapper",
".",
"remove",
"(",
")",
";",
"self",
".",
"$dropdown",
".",
"remove",
"(",
")",
";",
"self",
".",
"$input",
".",
"html",
"(",
"''",
")",
".",
"append",
"(",
"revertSettings",
".",
"$children",
")",
".",
"removeAttr",
"(",
"'tabindex'",
")",
".",
"removeClass",
"(",
"'selectized'",
")",
".",
"attr",
"(",
"{",
"tabindex",
":",
"revertSettings",
".",
"tabindex",
"}",
")",
".",
"show",
"(",
")",
";",
"self",
".",
"$control_input",
".",
"removeData",
"(",
"'grow'",
")",
";",
"self",
".",
"$input",
".",
"removeData",
"(",
"'selectize'",
")",
";",
"$",
"(",
"window",
")",
".",
"off",
"(",
"eventNS",
")",
";",
"$",
"(",
"document",
")",
".",
"off",
"(",
"eventNS",
")",
";",
"$",
"(",
"document",
".",
"body",
")",
".",
"off",
"(",
"eventNS",
")",
";",
"delete",
"self",
".",
"$input",
"[",
"0",
"]",
".",
"selectize",
";",
"}"
] | Completely destroys the control and
unbinds all event listeners so that it can
be garbage collected. | [
"Completely",
"destroys",
"the",
"control",
"and",
"unbinds",
"all",
"event",
"listeners",
"so",
"that",
"it",
"can",
"be",
"garbage",
"collected",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L3043-L3069 |
|
5,780 | sdelements/lets-chat | media/js/vendor/selectize/selectize.js | function(input) {
var self = this;
if (!self.settings.create) return false;
var filter = self.settings.createFilter;
return input.length
&& (typeof filter !== 'function' || filter.apply(self, [input]))
&& (typeof filter !== 'string' || new RegExp(filter).test(input))
&& (!(filter instanceof RegExp) || filter.test(input));
} | javascript | function(input) {
var self = this;
if (!self.settings.create) return false;
var filter = self.settings.createFilter;
return input.length
&& (typeof filter !== 'function' || filter.apply(self, [input]))
&& (typeof filter !== 'string' || new RegExp(filter).test(input))
&& (!(filter instanceof RegExp) || filter.test(input));
} | [
"function",
"(",
"input",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"self",
".",
"settings",
".",
"create",
")",
"return",
"false",
";",
"var",
"filter",
"=",
"self",
".",
"settings",
".",
"createFilter",
";",
"return",
"input",
".",
"length",
"&&",
"(",
"typeof",
"filter",
"!==",
"'function'",
"||",
"filter",
".",
"apply",
"(",
"self",
",",
"[",
"input",
"]",
")",
")",
"&&",
"(",
"typeof",
"filter",
"!==",
"'string'",
"||",
"new",
"RegExp",
"(",
"filter",
")",
".",
"test",
"(",
"input",
")",
")",
"&&",
"(",
"!",
"(",
"filter",
"instanceof",
"RegExp",
")",
"||",
"filter",
".",
"test",
"(",
"input",
")",
")",
";",
"}"
] | Determines whether or not to display the
create item prompt, given a user input.
@param {string} input
@return {boolean} | [
"Determines",
"whether",
"or",
"not",
"to",
"display",
"the",
"create",
"item",
"prompt",
"given",
"a",
"user",
"input",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/selectize/selectize.js#L3147-L3155 |
|
5,781 | sdelements/lets-chat | media/js/vendor/bootstrap-daterangepicker/daterangepicker.js | function (e) {
var el = $(e.target);
var date = moment(el.val(), this.format);
if (!date.isValid()) return;
var startDate, endDate;
if (el.attr('name') === 'daterangepicker_start') {
startDate = date;
endDate = this.endDate;
} else {
startDate = this.startDate;
endDate = date;
}
this.setCustomDates(startDate, endDate);
} | javascript | function (e) {
var el = $(e.target);
var date = moment(el.val(), this.format);
if (!date.isValid()) return;
var startDate, endDate;
if (el.attr('name') === 'daterangepicker_start') {
startDate = date;
endDate = this.endDate;
} else {
startDate = this.startDate;
endDate = date;
}
this.setCustomDates(startDate, endDate);
} | [
"function",
"(",
"e",
")",
"{",
"var",
"el",
"=",
"$",
"(",
"e",
".",
"target",
")",
";",
"var",
"date",
"=",
"moment",
"(",
"el",
".",
"val",
"(",
")",
",",
"this",
".",
"format",
")",
";",
"if",
"(",
"!",
"date",
".",
"isValid",
"(",
")",
")",
"return",
";",
"var",
"startDate",
",",
"endDate",
";",
"if",
"(",
"el",
".",
"attr",
"(",
"'name'",
")",
"===",
"'daterangepicker_start'",
")",
"{",
"startDate",
"=",
"date",
";",
"endDate",
"=",
"this",
".",
"endDate",
";",
"}",
"else",
"{",
"startDate",
"=",
"this",
".",
"startDate",
";",
"endDate",
"=",
"date",
";",
"}",
"this",
".",
"setCustomDates",
"(",
"startDate",
",",
"endDate",
")",
";",
"}"
] | when a date is typed into the start to end date textboxes | [
"when",
"a",
"date",
"is",
"typed",
"into",
"the",
"start",
"to",
"end",
"date",
"textboxes"
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/bootstrap-daterangepicker/daterangepicker.js#L675-L689 |
|
5,782 | sdelements/lets-chat | media/js/vendor/jquery-validate/jquery.validate.js | function( element, method ) {
return $( element ).data( "msg" + method[ 0 ].toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data("msg");
} | javascript | function( element, method ) {
return $( element ).data( "msg" + method[ 0 ].toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data("msg");
} | [
"function",
"(",
"element",
",",
"method",
")",
"{",
"return",
"$",
"(",
"element",
")",
".",
"data",
"(",
"\"msg\"",
"+",
"method",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"method",
".",
"substring",
"(",
"1",
")",
".",
"toLowerCase",
"(",
")",
")",
"||",
"$",
"(",
"element",
")",
".",
"data",
"(",
"\"msg\"",
")",
";",
"}"
] | return the custom message for the given element and validation method specified in the element's HTML5 data attribute return the generic message if present and no method specific message is present | [
"return",
"the",
"custom",
"message",
"for",
"the",
"given",
"element",
"and",
"validation",
"method",
"specified",
"in",
"the",
"element",
"s",
"HTML5",
"data",
"attribute",
"return",
"the",
"generic",
"message",
"if",
"present",
"and",
"no",
"method",
"specific",
"message",
"is",
"present"
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/jquery-validate/jquery.validate.js#L627-L630 |
|
5,783 | sdelements/lets-chat | media/js/vendor/jquery-validate/jquery.validate.js | function( name, method ) {
var m = this.settings.messages[name];
return m && (m.constructor === String ? m : m[method]);
} | javascript | function( name, method ) {
var m = this.settings.messages[name];
return m && (m.constructor === String ? m : m[method]);
} | [
"function",
"(",
"name",
",",
"method",
")",
"{",
"var",
"m",
"=",
"this",
".",
"settings",
".",
"messages",
"[",
"name",
"]",
";",
"return",
"m",
"&&",
"(",
"m",
".",
"constructor",
"===",
"String",
"?",
"m",
":",
"m",
"[",
"method",
"]",
")",
";",
"}"
] | return the custom message for the given element name and validation method | [
"return",
"the",
"custom",
"message",
"for",
"the",
"given",
"element",
"name",
"and",
"validation",
"method"
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/jquery-validate/jquery.validate.js#L633-L636 |
|
5,784 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | compareAscending | function compareAscending(a, b) {
var ac = a.criteria,
bc = b.criteria,
index = -1,
length = ac.length;
while (++index < length) {
var value = ac[index],
other = bc[index];
if (value !== other) {
if (value > other || typeof value == 'undefined') {
return 1;
}
if (value < other || typeof other == 'undefined') {
return -1;
}
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to return the same value for
// `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247
//
// This also ensures a stable sort in V8 and other engines.
// See http://code.google.com/p/v8/issues/detail?id=90
return a.index - b.index;
} | javascript | function compareAscending(a, b) {
var ac = a.criteria,
bc = b.criteria,
index = -1,
length = ac.length;
while (++index < length) {
var value = ac[index],
other = bc[index];
if (value !== other) {
if (value > other || typeof value == 'undefined') {
return 1;
}
if (value < other || typeof other == 'undefined') {
return -1;
}
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to return the same value for
// `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247
//
// This also ensures a stable sort in V8 and other engines.
// See http://code.google.com/p/v8/issues/detail?id=90
return a.index - b.index;
} | [
"function",
"compareAscending",
"(",
"a",
",",
"b",
")",
"{",
"var",
"ac",
"=",
"a",
".",
"criteria",
",",
"bc",
"=",
"b",
".",
"criteria",
",",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"ac",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"ac",
"[",
"index",
"]",
",",
"other",
"=",
"bc",
"[",
"index",
"]",
";",
"if",
"(",
"value",
"!==",
"other",
")",
"{",
"if",
"(",
"value",
">",
"other",
"||",
"typeof",
"value",
"==",
"'undefined'",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"value",
"<",
"other",
"||",
"typeof",
"other",
"==",
"'undefined'",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"}",
"// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications",
"// that causes it, under certain circumstances, to return the same value for",
"// `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247",
"//",
"// This also ensures a stable sort in V8 and other engines.",
"// See http://code.google.com/p/v8/issues/detail?id=90",
"return",
"a",
".",
"index",
"-",
"b",
".",
"index",
";",
"}"
] | Used by `sortBy` to compare transformed `collection` elements, stable sorting
them in ascending order.
@private
@param {Object} a The object to compare to `b`.
@param {Object} b The object to compare to `a`.
@returns {number} Returns the sort order indicator of `1` or `-1`. | [
"Used",
"by",
"sortBy",
"to",
"compare",
"transformed",
"collection",
"elements",
"stable",
"sorting",
"them",
"in",
"ascending",
"order",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L116-L142 |
5,785 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | slice | function slice(array, start, end) {
start || (start = 0);
if (typeof end == 'undefined') {
end = array ? array.length : 0;
}
var index = -1,
length = end - start || 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = array[start + index];
}
return result;
} | javascript | function slice(array, start, end) {
start || (start = 0);
if (typeof end == 'undefined') {
end = array ? array.length : 0;
}
var index = -1,
length = end - start || 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = array[start + index];
}
return result;
} | [
"function",
"slice",
"(",
"array",
",",
"start",
",",
"end",
")",
"{",
"start",
"||",
"(",
"start",
"=",
"0",
")",
";",
"if",
"(",
"typeof",
"end",
"==",
"'undefined'",
")",
"{",
"end",
"=",
"array",
"?",
"array",
".",
"length",
":",
"0",
";",
"}",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"end",
"-",
"start",
"||",
"0",
",",
"result",
"=",
"Array",
"(",
"length",
"<",
"0",
"?",
"0",
":",
"length",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"result",
"[",
"index",
"]",
"=",
"array",
"[",
"start",
"+",
"index",
"]",
";",
"}",
"return",
"result",
";",
"}"
] | Slices the `collection` from the `start` index up to, but not including,
the `end` index.
Note: This function is used instead of `Array#slice` to support node lists
in IE < 9 and to ensure dense arrays are returned.
@private
@param {Array|Object|string} collection The collection to slice.
@param {number} start The start index.
@param {number} end The end index.
@returns {Array} Returns the new array. | [
"Slices",
"the",
"collection",
"from",
"the",
"start",
"index",
"up",
"to",
"but",
"not",
"including",
"the",
"end",
"index",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L169-L182 |
5,786 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | createAggregator | function createAggregator(setter) {
return function(collection, callback, thisArg) {
var result = {};
callback = createCallback(callback, thisArg, 3);
var index = -1,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
while (++index < length) {
var value = collection[index];
setter(result, value, callback(value, index, collection), collection);
}
} else {
forOwn(collection, function(value, key, collection) {
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};
} | javascript | function createAggregator(setter) {
return function(collection, callback, thisArg) {
var result = {};
callback = createCallback(callback, thisArg, 3);
var index = -1,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
while (++index < length) {
var value = collection[index];
setter(result, value, callback(value, index, collection), collection);
}
} else {
forOwn(collection, function(value, key, collection) {
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};
} | [
"function",
"createAggregator",
"(",
"setter",
")",
"{",
"return",
"function",
"(",
"collection",
",",
"callback",
",",
"thisArg",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"callback",
"=",
"createCallback",
"(",
"callback",
",",
"thisArg",
",",
"3",
")",
";",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"collection",
"?",
"collection",
".",
"length",
":",
"0",
";",
"if",
"(",
"typeof",
"length",
"==",
"'number'",
")",
"{",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"collection",
"[",
"index",
"]",
";",
"setter",
"(",
"result",
",",
"value",
",",
"callback",
"(",
"value",
",",
"index",
",",
"collection",
")",
",",
"collection",
")",
";",
"}",
"}",
"else",
"{",
"forOwn",
"(",
"collection",
",",
"function",
"(",
"value",
",",
"key",
",",
"collection",
")",
"{",
"setter",
"(",
"result",
",",
"value",
",",
"callback",
"(",
"value",
",",
"key",
",",
"collection",
")",
",",
"collection",
")",
";",
"}",
")",
";",
"}",
"return",
"result",
";",
"}",
";",
"}"
] | Creates a function that aggregates a collection, creating an object composed
of keys generated from the results of running each element of the collection
through a callback. The given `setter` function sets the keys and values
of the composed object.
@private
@param {Function} setter The setter function.
@returns {Function} Returns the new aggregator function. | [
"Creates",
"a",
"function",
"that",
"aggregates",
"a",
"collection",
"creating",
"an",
"object",
"composed",
"of",
"keys",
"generated",
"from",
"the",
"results",
"of",
"running",
"each",
"element",
"of",
"the",
"collection",
"through",
"a",
"callback",
".",
"The",
"given",
"setter",
"function",
"sets",
"the",
"keys",
"and",
"values",
"of",
"the",
"composed",
"object",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L775-L795 |
5,787 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | invert | function invert(object) {
var index = -1,
props = keys(object),
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
result[object[key]] = key;
}
return result;
} | javascript | function invert(object) {
var index = -1,
props = keys(object),
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
result[object[key]] = key;
}
return result;
} | [
"function",
"invert",
"(",
"object",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"props",
"=",
"keys",
"(",
"object",
")",
",",
"length",
"=",
"props",
".",
"length",
",",
"result",
"=",
"{",
"}",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"key",
"=",
"props",
"[",
"index",
"]",
";",
"result",
"[",
"object",
"[",
"key",
"]",
"]",
"=",
"key",
";",
"}",
"return",
"result",
";",
"}"
] | Creates an object composed of the inverted keys and values of the given object.
@static
@memberOf _
@category Objects
@param {Object} object The object to invert.
@returns {Object} Returns the created inverted object.
@example
_.invert({ 'first': 'fred', 'second': 'barney' });
// => { 'fred': 'first', 'barney': 'second' } | [
"Creates",
"an",
"object",
"composed",
"of",
"the",
"inverted",
"keys",
"and",
"values",
"of",
"the",
"given",
"object",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L1266-L1277 |
5,788 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | isBoolean | function isBoolean(value) {
return value === true || value === false ||
value && typeof value == 'object' && toString.call(value) == boolClass || false;
} | javascript | function isBoolean(value) {
return value === true || value === false ||
value && typeof value == 'object' && toString.call(value) == boolClass || false;
} | [
"function",
"isBoolean",
"(",
"value",
")",
"{",
"return",
"value",
"===",
"true",
"||",
"value",
"===",
"false",
"||",
"value",
"&&",
"typeof",
"value",
"==",
"'object'",
"&&",
"toString",
".",
"call",
"(",
"value",
")",
"==",
"boolClass",
"||",
"false",
";",
"}"
] | Checks if `value` is a boolean value.
@static
@memberOf _
@category Objects
@param {*} value The value to check.
@returns {boolean} Returns `true` if the `value` is a boolean value, else `false`.
@example
_.isBoolean(null);
// => false | [
"Checks",
"if",
"value",
"is",
"a",
"boolean",
"value",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L1292-L1295 |
5,789 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | isString | function isString(value) {
return typeof value == 'string' ||
value && typeof value == 'object' && toString.call(value) == stringClass || false;
} | javascript | function isString(value) {
return typeof value == 'string' ||
value && typeof value == 'object' && toString.call(value) == stringClass || false;
} | [
"function",
"isString",
"(",
"value",
")",
"{",
"return",
"typeof",
"value",
"==",
"'string'",
"||",
"value",
"&&",
"typeof",
"value",
"==",
"'object'",
"&&",
"toString",
".",
"call",
"(",
"value",
")",
"==",
"stringClass",
"||",
"false",
";",
"}"
] | Checks if `value` is a string.
@static
@memberOf _
@category Objects
@param {*} value The value to check.
@returns {boolean} Returns `true` if the `value` is a string, else `false`.
@example
_.isString('fred');
// => true | [
"Checks",
"if",
"value",
"is",
"a",
"string",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L1593-L1596 |
5,790 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | values | function values(object) {
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
result[index] = object[props[index]];
}
return result;
} | javascript | function values(object) {
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
result[index] = object[props[index]];
}
return result;
} | [
"function",
"values",
"(",
"object",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"props",
"=",
"keys",
"(",
"object",
")",
",",
"length",
"=",
"props",
".",
"length",
",",
"result",
"=",
"Array",
"(",
"length",
")",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"result",
"[",
"index",
"]",
"=",
"object",
"[",
"props",
"[",
"index",
"]",
"]",
";",
"}",
"return",
"result",
";",
"}"
] | Creates an array composed of the own enumerable property values of `object`.
@static
@memberOf _
@category Objects
@param {Object} object The object to inspect.
@returns {Array} Returns an array of property values.
@example
_.values({ 'one': 1, 'two': 2, 'three': 3 });
// => [1, 2, 3] (property order is not guaranteed across environments) | [
"Creates",
"an",
"array",
"composed",
"of",
"the",
"own",
"enumerable",
"property",
"values",
"of",
"object",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L1741-L1751 |
5,791 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | where | function where(collection, properties, first) {
return (first && isEmpty(properties))
? undefined
: (first ? find : filter)(collection, properties);
} | javascript | function where(collection, properties, first) {
return (first && isEmpty(properties))
? undefined
: (first ? find : filter)(collection, properties);
} | [
"function",
"where",
"(",
"collection",
",",
"properties",
",",
"first",
")",
"{",
"return",
"(",
"first",
"&&",
"isEmpty",
"(",
"properties",
")",
")",
"?",
"undefined",
":",
"(",
"first",
"?",
"find",
":",
"filter",
")",
"(",
"collection",
",",
"properties",
")",
";",
"}"
] | Performs a deep comparison of each element in a `collection` to the given
`properties` object, returning an array of all elements that have equivalent
property values.
@static
@memberOf _
@type Function
@category Collections
@param {Array|Object|string} collection The collection to iterate over.
@param {Object} props The object of property values to filter by.
@returns {Array} Returns a new array of elements that have the given properties.
@example
var characters = [
{ 'name': 'barney', 'age': 36, 'pets': ['hoppy'] },
{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }
];
_.where(characters, { 'age': 36 });
// => [{ 'name': 'barney', 'age': 36, 'pets': ['hoppy'] }]
_.where(characters, { 'pets': ['dino'] });
// => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }] | [
"Performs",
"a",
"deep",
"comparison",
"of",
"each",
"element",
"in",
"a",
"collection",
"to",
"the",
"given",
"properties",
"object",
"returning",
"an",
"array",
"of",
"all",
"elements",
"that",
"have",
"equivalent",
"property",
"values",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L2870-L2874 |
5,792 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | defer | function defer(func) {
if (!isFunction(func)) {
throw new TypeError;
}
var args = slice(arguments, 1);
return setTimeout(function() { func.apply(undefined, args); }, 1);
} | javascript | function defer(func) {
if (!isFunction(func)) {
throw new TypeError;
}
var args = slice(arguments, 1);
return setTimeout(function() { func.apply(undefined, args); }, 1);
} | [
"function",
"defer",
"(",
"func",
")",
"{",
"if",
"(",
"!",
"isFunction",
"(",
"func",
")",
")",
"{",
"throw",
"new",
"TypeError",
";",
"}",
"var",
"args",
"=",
"slice",
"(",
"arguments",
",",
"1",
")",
";",
"return",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"func",
".",
"apply",
"(",
"undefined",
",",
"args",
")",
";",
"}",
",",
"1",
")",
";",
"}"
] | Defers executing the `func` function until the current call stack has cleared.
Additional arguments will be provided to `func` when it is invoked.
@static
@memberOf _
@category Functions
@param {Function} func The function to defer.
@param {...*} [arg] Arguments to invoke the function with.
@returns {number} Returns the timer id.
@example
_.defer(function(text) { console.log(text); }, 'deferred');
// logs 'deferred' after one or more milliseconds | [
"Defers",
"executing",
"the",
"func",
"function",
"until",
"the",
"current",
"call",
"stack",
"has",
"cleared",
".",
"Additional",
"arguments",
"will",
"be",
"provided",
"to",
"func",
"when",
"it",
"is",
"invoked",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L3947-L3953 |
5,793 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | result | function result(object, key) {
if (object) {
var value = object[key];
return isFunction(value) ? object[key]() : value;
}
} | javascript | function result(object, key) {
if (object) {
var value = object[key];
return isFunction(value) ? object[key]() : value;
}
} | [
"function",
"result",
"(",
"object",
",",
"key",
")",
"{",
"if",
"(",
"object",
")",
"{",
"var",
"value",
"=",
"object",
"[",
"key",
"]",
";",
"return",
"isFunction",
"(",
"value",
")",
"?",
"object",
"[",
"key",
"]",
"(",
")",
":",
"value",
";",
"}",
"}"
] | Resolves the value of property `key` on `object`. If `key` is a function
it will be invoked with the `this` binding of `object` and its result returned,
else the property value is returned. If `object` is falsey then `undefined`
is returned.
@static
@memberOf _
@category Utilities
@param {Object} object The object to inspect.
@param {string} key The name of the property to resolve.
@returns {*} Returns the resolved value.
@example
var object = {
'cheese': 'crumpets',
'stuff': function() {
return 'nonsense';
}
};
_.result(object, 'cheese');
// => 'crumpets'
_.result(object, 'stuff');
// => 'nonsense' | [
"Resolves",
"the",
"value",
"of",
"property",
"key",
"on",
"object",
".",
"If",
"key",
"is",
"a",
"function",
"it",
"will",
"be",
"invoked",
"with",
"the",
"this",
"binding",
"of",
"object",
"and",
"its",
"result",
"returned",
"else",
"the",
"property",
"value",
"is",
"returned",
".",
"If",
"object",
"is",
"falsey",
"then",
"undefined",
"is",
"returned",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L4446-L4451 |
5,794 | sdelements/lets-chat | media/js/vendor/lodash/lodash.underscore.js | template | function template(text, data, options) {
var _ = lodash,
settings = _.templateSettings;
text = String(text || '');
options = defaults({}, options, settings);
var index = 0,
source = "__p += '",
variable = options.variable;
var reDelimiters = RegExp(
(options.escape || reNoMatch).source + '|' +
(options.interpolate || reNoMatch).source + '|' +
(options.evaluate || reNoMatch).source + '|$'
, 'g');
text.replace(reDelimiters, function(match, escapeValue, interpolateValue, evaluateValue, offset) {
source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);
if (escapeValue) {
source += "' +\n_.escape(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
source += "';\n" + evaluateValue + ";\n__p += '";
}
if (interpolateValue) {
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
}
index = offset + match.length;
return match;
});
source += "';\n";
if (!variable) {
variable = 'obj';
source = 'with (' + variable + ' || {}) {\n' + source + '\n}\n';
}
source = 'function(' + variable + ') {\n' +
"var __t, __p = '', __j = Array.prototype.join;\n" +
"function print() { __p += __j.call(arguments, '') }\n" +
source +
'return __p\n}';
try {
var result = Function('_', 'return ' + source)(_);
} catch(e) {
e.source = source;
throw e;
}
if (data) {
return result(data);
}
result.source = source;
return result;
} | javascript | function template(text, data, options) {
var _ = lodash,
settings = _.templateSettings;
text = String(text || '');
options = defaults({}, options, settings);
var index = 0,
source = "__p += '",
variable = options.variable;
var reDelimiters = RegExp(
(options.escape || reNoMatch).source + '|' +
(options.interpolate || reNoMatch).source + '|' +
(options.evaluate || reNoMatch).source + '|$'
, 'g');
text.replace(reDelimiters, function(match, escapeValue, interpolateValue, evaluateValue, offset) {
source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);
if (escapeValue) {
source += "' +\n_.escape(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
source += "';\n" + evaluateValue + ";\n__p += '";
}
if (interpolateValue) {
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
}
index = offset + match.length;
return match;
});
source += "';\n";
if (!variable) {
variable = 'obj';
source = 'with (' + variable + ' || {}) {\n' + source + '\n}\n';
}
source = 'function(' + variable + ') {\n' +
"var __t, __p = '', __j = Array.prototype.join;\n" +
"function print() { __p += __j.call(arguments, '') }\n" +
source +
'return __p\n}';
try {
var result = Function('_', 'return ' + source)(_);
} catch(e) {
e.source = source;
throw e;
}
if (data) {
return result(data);
}
result.source = source;
return result;
} | [
"function",
"template",
"(",
"text",
",",
"data",
",",
"options",
")",
"{",
"var",
"_",
"=",
"lodash",
",",
"settings",
"=",
"_",
".",
"templateSettings",
";",
"text",
"=",
"String",
"(",
"text",
"||",
"''",
")",
";",
"options",
"=",
"defaults",
"(",
"{",
"}",
",",
"options",
",",
"settings",
")",
";",
"var",
"index",
"=",
"0",
",",
"source",
"=",
"\"__p += '\"",
",",
"variable",
"=",
"options",
".",
"variable",
";",
"var",
"reDelimiters",
"=",
"RegExp",
"(",
"(",
"options",
".",
"escape",
"||",
"reNoMatch",
")",
".",
"source",
"+",
"'|'",
"+",
"(",
"options",
".",
"interpolate",
"||",
"reNoMatch",
")",
".",
"source",
"+",
"'|'",
"+",
"(",
"options",
".",
"evaluate",
"||",
"reNoMatch",
")",
".",
"source",
"+",
"'|$'",
",",
"'g'",
")",
";",
"text",
".",
"replace",
"(",
"reDelimiters",
",",
"function",
"(",
"match",
",",
"escapeValue",
",",
"interpolateValue",
",",
"evaluateValue",
",",
"offset",
")",
"{",
"source",
"+=",
"text",
".",
"slice",
"(",
"index",
",",
"offset",
")",
".",
"replace",
"(",
"reUnescapedString",
",",
"escapeStringChar",
")",
";",
"if",
"(",
"escapeValue",
")",
"{",
"source",
"+=",
"\"' +\\n_.escape(\"",
"+",
"escapeValue",
"+",
"\") +\\n'\"",
";",
"}",
"if",
"(",
"evaluateValue",
")",
"{",
"source",
"+=",
"\"';\\n\"",
"+",
"evaluateValue",
"+",
"\";\\n__p += '\"",
";",
"}",
"if",
"(",
"interpolateValue",
")",
"{",
"source",
"+=",
"\"' +\\n((__t = (\"",
"+",
"interpolateValue",
"+",
"\")) == null ? '' : __t) +\\n'\"",
";",
"}",
"index",
"=",
"offset",
"+",
"match",
".",
"length",
";",
"return",
"match",
";",
"}",
")",
";",
"source",
"+=",
"\"';\\n\"",
";",
"if",
"(",
"!",
"variable",
")",
"{",
"variable",
"=",
"'obj'",
";",
"source",
"=",
"'with ('",
"+",
"variable",
"+",
"' || {}) {\\n'",
"+",
"source",
"+",
"'\\n}\\n'",
";",
"}",
"source",
"=",
"'function('",
"+",
"variable",
"+",
"') {\\n'",
"+",
"\"var __t, __p = '', __j = Array.prototype.join;\\n\"",
"+",
"\"function print() { __p += __j.call(arguments, '') }\\n\"",
"+",
"source",
"+",
"'return __p\\n}'",
";",
"try",
"{",
"var",
"result",
"=",
"Function",
"(",
"'_'",
",",
"'return '",
"+",
"source",
")",
"(",
"_",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"e",
".",
"source",
"=",
"source",
";",
"throw",
"e",
";",
"}",
"if",
"(",
"data",
")",
"{",
"return",
"result",
"(",
"data",
")",
";",
"}",
"result",
".",
"source",
"=",
"source",
";",
"return",
"result",
";",
"}"
] | A micro-templating method that handles arbitrary delimiters, preserves
whitespace, and correctly escapes quotes within interpolated code.
Note: In the development build, `_.template` utilizes sourceURLs for easier
debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
For more information on precompiling templates see:
http://lodash.com/custom-builds
For more information on Chrome extension sandboxes see:
http://developer.chrome.com/stable/extensions/sandboxingEval.html
@static
@memberOf _
@category Utilities
@param {string} text The template text.
@param {Object} data The data object used to populate the text.
@param {Object} [options] The options object.
@param {RegExp} [options.escape] The "escape" delimiter.
@param {RegExp} [options.evaluate] The "evaluate" delimiter.
@param {Object} [options.imports] An object to import into the template as local variables.
@param {RegExp} [options.interpolate] The "interpolate" delimiter.
@param {string} [sourceURL] The sourceURL of the template's compiled source.
@param {string} [variable] The data object variable name.
@returns {Function|string} Returns a compiled function when no `data` object
is given, else it returns the interpolated text.
@example
// using the "interpolate" delimiter to create a compiled template
var compiled = _.template('hello <%= name %>');
compiled({ 'name': 'fred' });
// => 'hello fred'
// using the "escape" delimiter to escape HTML in data property values
_.template('<b><%- value %></b>', { 'value': '<script>' });
// => '<b><script></b>'
// using the "evaluate" delimiter to generate HTML
var list = '<% _.forEach(people, function(name) { %><li><%- name %></li><% }); %>';
_.template(list, { 'people': ['fred', 'barney'] });
// => '<li>fred</li><li>barney</li>'
// using the ES6 delimiter as an alternative to the default "interpolate" delimiter
_.template('hello ${ name }', { 'name': 'pebbles' });
// => 'hello pebbles'
// using the internal `print` function in "evaluate" delimiters
_.template('<% print("hello " + name); %>!', { 'name': 'barney' });
// => 'hello barney!'
// using a custom template delimiters
_.templateSettings = {
'interpolate': /{{([\s\S]+?)}}/g
};
_.template('hello {{ name }}!', { 'name': 'mustache' });
// => 'hello mustache!'
// using the `imports` option to import jQuery
var list = '<% jq.each(people, function(name) { %><li><%- name %></li><% }); %>';
_.template(list, { 'people': ['fred', 'barney'] }, { 'imports': { 'jq': jQuery } });
// => '<li>fred</li><li>barney</li>'
// using the `sourceURL` option to specify a custom sourceURL for the template
var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
compiled(data);
// => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
// using the `variable` option to ensure a with-statement isn't used in the compiled template
var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' });
compiled.source;
// => function(data) {
var __t, __p = '', __e = _.escape;
__p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!';
return __p;
}
// using the `source` property to inline compiled templates for meaningful
// line numbers in error messages and a stack trace
fs.writeFileSync(path.join(cwd, 'jst.js'), '\
var JST = {\
"main": ' + _.template(mainText).source + '\
};\
'); | [
"A",
"micro",
"-",
"templating",
"method",
"that",
"handles",
"arbitrary",
"delimiters",
"preserves",
"whitespace",
"and",
"correctly",
"escapes",
"quotes",
"within",
"interpolated",
"code",
"."
] | 318d2ed0852d2f299fc76b32f2240371ccee95ad | https://github.com/sdelements/lets-chat/blob/318d2ed0852d2f299fc76b32f2240371ccee95ad/media/js/vendor/lodash/lodash.underscore.js#L4539-L4593 |
5,795 | brianc/node-postgres | lib/result.js | function (rowMode, types) {
this.command = null
this.rowCount = null
this.oid = null
this.rows = []
this.fields = []
this._parsers = []
this._types = types
this.RowCtor = null
this.rowAsArray = rowMode === 'array'
if (this.rowAsArray) {
this.parseRow = this._parseRowAsArray
}
} | javascript | function (rowMode, types) {
this.command = null
this.rowCount = null
this.oid = null
this.rows = []
this.fields = []
this._parsers = []
this._types = types
this.RowCtor = null
this.rowAsArray = rowMode === 'array'
if (this.rowAsArray) {
this.parseRow = this._parseRowAsArray
}
} | [
"function",
"(",
"rowMode",
",",
"types",
")",
"{",
"this",
".",
"command",
"=",
"null",
"this",
".",
"rowCount",
"=",
"null",
"this",
".",
"oid",
"=",
"null",
"this",
".",
"rows",
"=",
"[",
"]",
"this",
".",
"fields",
"=",
"[",
"]",
"this",
".",
"_parsers",
"=",
"[",
"]",
"this",
".",
"_types",
"=",
"types",
"this",
".",
"RowCtor",
"=",
"null",
"this",
".",
"rowAsArray",
"=",
"rowMode",
"===",
"'array'",
"if",
"(",
"this",
".",
"rowAsArray",
")",
"{",
"this",
".",
"parseRow",
"=",
"this",
".",
"_parseRowAsArray",
"}",
"}"
] | result object returned from query in the 'end' event and also passed as second argument to provided callback | [
"result",
"object",
"returned",
"from",
"query",
"in",
"the",
"end",
"event",
"and",
"also",
"passed",
"as",
"second",
"argument",
"to",
"provided",
"callback"
] | 4b530a9e0fb317567766260a2c57e28c88d55861 | https://github.com/brianc/node-postgres/blob/4b530a9e0fb317567766260a2c57e28c88d55861/lib/result.js#L15-L28 |
|
5,796 | brianc/node-postgres | lib/utils.js | arrayString | function arrayString (val) {
var result = '{'
for (var i = 0; i < val.length; i++) {
if (i > 0) {
result = result + ','
}
if (val[i] === null || typeof val[i] === 'undefined') {
result = result + 'NULL'
} else if (Array.isArray(val[i])) {
result = result + arrayString(val[i])
} else if (val[i] instanceof Buffer) {
result += '\\\\x' + val[i].toString('hex')
} else {
result += escapeElement(prepareValue(val[i]))
}
}
result = result + '}'
return result
} | javascript | function arrayString (val) {
var result = '{'
for (var i = 0; i < val.length; i++) {
if (i > 0) {
result = result + ','
}
if (val[i] === null || typeof val[i] === 'undefined') {
result = result + 'NULL'
} else if (Array.isArray(val[i])) {
result = result + arrayString(val[i])
} else if (val[i] instanceof Buffer) {
result += '\\\\x' + val[i].toString('hex')
} else {
result += escapeElement(prepareValue(val[i]))
}
}
result = result + '}'
return result
} | [
"function",
"arrayString",
"(",
"val",
")",
"{",
"var",
"result",
"=",
"'{'",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"val",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
">",
"0",
")",
"{",
"result",
"=",
"result",
"+",
"','",
"}",
"if",
"(",
"val",
"[",
"i",
"]",
"===",
"null",
"||",
"typeof",
"val",
"[",
"i",
"]",
"===",
"'undefined'",
")",
"{",
"result",
"=",
"result",
"+",
"'NULL'",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
"[",
"i",
"]",
")",
")",
"{",
"result",
"=",
"result",
"+",
"arrayString",
"(",
"val",
"[",
"i",
"]",
")",
"}",
"else",
"if",
"(",
"val",
"[",
"i",
"]",
"instanceof",
"Buffer",
")",
"{",
"result",
"+=",
"'\\\\\\\\x'",
"+",
"val",
"[",
"i",
"]",
".",
"toString",
"(",
"'hex'",
")",
"}",
"else",
"{",
"result",
"+=",
"escapeElement",
"(",
"prepareValue",
"(",
"val",
"[",
"i",
"]",
")",
")",
"}",
"}",
"result",
"=",
"result",
"+",
"'}'",
"return",
"result",
"}"
] | convert a JS array to a postgres array literal uses comma separator so won't work for types like box that use a different array separator. | [
"convert",
"a",
"JS",
"array",
"to",
"a",
"postgres",
"array",
"literal",
"uses",
"comma",
"separator",
"so",
"won",
"t",
"work",
"for",
"types",
"like",
"box",
"that",
"use",
"a",
"different",
"array",
"separator",
"."
] | 4b530a9e0fb317567766260a2c57e28c88d55861 | https://github.com/brianc/node-postgres/blob/4b530a9e0fb317567766260a2c57e28c88d55861/lib/utils.js#L25-L43 |
5,797 | nicolodavis/boardgame.io | src/client/debug/debug.js | SanitizeCtx | function SanitizeCtx(ctx) {
let r = {};
for (const key in ctx) {
if (!key.startsWith('_')) {
r[key] = ctx[key];
}
}
return r;
} | javascript | function SanitizeCtx(ctx) {
let r = {};
for (const key in ctx) {
if (!key.startsWith('_')) {
r[key] = ctx[key];
}
}
return r;
} | [
"function",
"SanitizeCtx",
"(",
"ctx",
")",
"{",
"let",
"r",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"key",
"in",
"ctx",
")",
"{",
"if",
"(",
"!",
"key",
".",
"startsWith",
"(",
"'_'",
")",
")",
"{",
"r",
"[",
"key",
"]",
"=",
"ctx",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"r",
";",
"}"
] | Removes all the keys in ctx that begin with a _. | [
"Removes",
"all",
"the",
"keys",
"in",
"ctx",
"that",
"begin",
"with",
"a",
"_",
"."
] | e46f19552ede4751af97e2fac8086add3bed220a | https://github.com/nicolodavis/boardgame.io/blob/e46f19552ede4751af97e2fac8086add3bed220a/src/client/debug/debug.js#L25-L33 |
5,798 | nicolodavis/boardgame.io | examples/react-web/src/ui/chess3d/game.js | Load | function Load(pgn) {
let chess = null;
if (Chess.Chess) {
chess = new Chess.Chess();
} else {
chess = new Chess();
}
chess.load_pgn(pgn);
return chess;
} | javascript | function Load(pgn) {
let chess = null;
if (Chess.Chess) {
chess = new Chess.Chess();
} else {
chess = new Chess();
}
chess.load_pgn(pgn);
return chess;
} | [
"function",
"Load",
"(",
"pgn",
")",
"{",
"let",
"chess",
"=",
"null",
";",
"if",
"(",
"Chess",
".",
"Chess",
")",
"{",
"chess",
"=",
"new",
"Chess",
".",
"Chess",
"(",
")",
";",
"}",
"else",
"{",
"chess",
"=",
"new",
"Chess",
"(",
")",
";",
"}",
"chess",
".",
"load_pgn",
"(",
"pgn",
")",
";",
"return",
"chess",
";",
"}"
] | Helper to instantiate chess.js correctly on both browser and Node. | [
"Helper",
"to",
"instantiate",
"chess",
".",
"js",
"correctly",
"on",
"both",
"browser",
"and",
"Node",
"."
] | e46f19552ede4751af97e2fac8086add3bed220a | https://github.com/nicolodavis/boardgame.io/blob/e46f19552ede4751af97e2fac8086add3bed220a/examples/react-web/src/ui/chess3d/game.js#L14-L23 |
5,799 | loadimpact/k6 | samples/pantheon.js | doLogin | function doLogin() {
// Request the login page.
let res = http.get(baseURL + "/user/login");
check(res, {
"title is correct": (res) => res.html("title").text() == "User account | David li commerce-test",
});
// TODO: Add attr() to k6/html!
// Extract hidden input fields.
let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
group("login", function() {
// Pick a random set of credentials.
let creds = credentials[Math.floor(Math.random()*credentials.length)];
// Create login request.
let formdata = {
name: creds.username,
pass: creds.password,
form_build_id: formBuildID,
form_id: "user_login",
op: "Log in",
};
let headers = { "Content-Type": "application/x-www-form-urlencoded" };
// Send login request
let res = http.post(baseURL + "/user/login", formdata, { headers: headers });
// Verify that we ended up on the user page
check(res, {
"login succeeded": (res) => res.url == `${baseURL}/users/${creds.username}`,
}) || fail("login failed");
});
} | javascript | function doLogin() {
// Request the login page.
let res = http.get(baseURL + "/user/login");
check(res, {
"title is correct": (res) => res.html("title").text() == "User account | David li commerce-test",
});
// TODO: Add attr() to k6/html!
// Extract hidden input fields.
let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
group("login", function() {
// Pick a random set of credentials.
let creds = credentials[Math.floor(Math.random()*credentials.length)];
// Create login request.
let formdata = {
name: creds.username,
pass: creds.password,
form_build_id: formBuildID,
form_id: "user_login",
op: "Log in",
};
let headers = { "Content-Type": "application/x-www-form-urlencoded" };
// Send login request
let res = http.post(baseURL + "/user/login", formdata, { headers: headers });
// Verify that we ended up on the user page
check(res, {
"login succeeded": (res) => res.url == `${baseURL}/users/${creds.username}`,
}) || fail("login failed");
});
} | [
"function",
"doLogin",
"(",
")",
"{",
"// Request the login page.",
"let",
"res",
"=",
"http",
".",
"get",
"(",
"baseURL",
"+",
"\"/user/login\"",
")",
";",
"check",
"(",
"res",
",",
"{",
"\"title is correct\"",
":",
"(",
"res",
")",
"=>",
"res",
".",
"html",
"(",
"\"title\"",
")",
".",
"text",
"(",
")",
"==",
"\"User account | David li commerce-test\"",
",",
"}",
")",
";",
"// TODO: Add attr() to k6/html!",
"// Extract hidden input fields.",
"let",
"formBuildID",
"=",
"res",
".",
"body",
".",
"match",
"(",
"'name=\"form_build_id\" value=\"(.*)\"'",
")",
"[",
"1",
"]",
";",
"group",
"(",
"\"login\"",
",",
"function",
"(",
")",
"{",
"// Pick a random set of credentials.",
"let",
"creds",
"=",
"credentials",
"[",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"credentials",
".",
"length",
")",
"]",
";",
"// Create login request.",
"let",
"formdata",
"=",
"{",
"name",
":",
"creds",
".",
"username",
",",
"pass",
":",
"creds",
".",
"password",
",",
"form_build_id",
":",
"formBuildID",
",",
"form_id",
":",
"\"user_login\"",
",",
"op",
":",
"\"Log in\"",
",",
"}",
";",
"let",
"headers",
"=",
"{",
"\"Content-Type\"",
":",
"\"application/x-www-form-urlencoded\"",
"}",
";",
"// Send login request",
"let",
"res",
"=",
"http",
".",
"post",
"(",
"baseURL",
"+",
"\"/user/login\"",
",",
"formdata",
",",
"{",
"headers",
":",
"headers",
"}",
")",
";",
"// Verify that we ended up on the user page",
"check",
"(",
"res",
",",
"{",
"\"login succeeded\"",
":",
"(",
"res",
")",
"=>",
"res",
".",
"url",
"==",
"`",
"${",
"baseURL",
"}",
"${",
"creds",
".",
"username",
"}",
"`",
",",
"}",
")",
"||",
"fail",
"(",
"\"login failed\"",
")",
";",
"}",
")",
";",
"}"
] | Request the login page and perform a user login | [
"Request",
"the",
"login",
"page",
"and",
"perform",
"a",
"user",
"login"
] | 03645ba7059a4ca9eb22035f5adb52f1a91e7534 | https://github.com/loadimpact/k6/blob/03645ba7059a4ca9eb22035f5adb52f1a91e7534/samples/pantheon.js#L130-L161 |
Subsets and Splits