id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
18,200
|
Yomguithereal/talisman
|
src/stemmers/french/carry.js
|
applyRules
|
function applyRules(rules, stem) {
for (let i = 0, l = rules.length; i < l; i++) {
const [min, pattern, replacement = ''] = rules[i];
if (stem.slice(-pattern.length) === pattern) {
const newStem = stem.slice(0, -pattern.length) + replacement,
m = computeM(newStem);
if (m <= min)
continue;
return newStem;
}
}
return stem;
}
|
javascript
|
function applyRules(rules, stem) {
for (let i = 0, l = rules.length; i < l; i++) {
const [min, pattern, replacement = ''] = rules[i];
if (stem.slice(-pattern.length) === pattern) {
const newStem = stem.slice(0, -pattern.length) + replacement,
m = computeM(newStem);
if (m <= min)
continue;
return newStem;
}
}
return stem;
}
|
[
"function",
"applyRules",
"(",
"rules",
",",
"stem",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"rules",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"[",
"min",
",",
"pattern",
",",
"replacement",
"=",
"''",
"]",
"=",
"rules",
"[",
"i",
"]",
";",
"if",
"(",
"stem",
".",
"slice",
"(",
"-",
"pattern",
".",
"length",
")",
"===",
"pattern",
")",
"{",
"const",
"newStem",
"=",
"stem",
".",
"slice",
"(",
"0",
",",
"-",
"pattern",
".",
"length",
")",
"+",
"replacement",
",",
"m",
"=",
"computeM",
"(",
"newStem",
")",
";",
"if",
"(",
"m",
"<=",
"min",
")",
"continue",
";",
"return",
"newStem",
";",
"}",
"}",
"return",
"stem",
";",
"}"
] |
Function used to apply a set of rules to the current stem.
@param {string} stem - Target stem.
@return {string} - The resulting stem.
|
[
"Function",
"used",
"to",
"apply",
"a",
"set",
"of",
"rules",
"to",
"the",
"current",
"stem",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/stemmers/french/carry.js#L314-L331
|
18,201
|
Yomguithereal/talisman
|
src/stats/inferential.js
|
genericVariance
|
function genericVariance(ddof, sequence) {
const length = sequence.length;
if (!length)
throw Error('talisman/stats/inferential#variance: the given list is empty.');
// Returning 0 if the denominator would be <= 0
const denominator = length - ddof;
if (denominator <= 0)
return 0;
const m = mean(sequence);
let s = 0;
for (let i = 0; i < length; i++)
s += Math.pow(sequence[i] - m, 2);
return s / denominator;
}
|
javascript
|
function genericVariance(ddof, sequence) {
const length = sequence.length;
if (!length)
throw Error('talisman/stats/inferential#variance: the given list is empty.');
// Returning 0 if the denominator would be <= 0
const denominator = length - ddof;
if (denominator <= 0)
return 0;
const m = mean(sequence);
let s = 0;
for (let i = 0; i < length; i++)
s += Math.pow(sequence[i] - m, 2);
return s / denominator;
}
|
[
"function",
"genericVariance",
"(",
"ddof",
",",
"sequence",
")",
"{",
"const",
"length",
"=",
"sequence",
".",
"length",
";",
"if",
"(",
"!",
"length",
")",
"throw",
"Error",
"(",
"'talisman/stats/inferential#variance: the given list is empty.'",
")",
";",
"// Returning 0 if the denominator would be <= 0",
"const",
"denominator",
"=",
"length",
"-",
"ddof",
";",
"if",
"(",
"denominator",
"<=",
"0",
")",
"return",
"0",
";",
"const",
"m",
"=",
"mean",
"(",
"sequence",
")",
";",
"let",
"s",
"=",
"0",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"s",
"+=",
"Math",
".",
"pow",
"(",
"sequence",
"[",
"i",
"]",
"-",
"m",
",",
"2",
")",
";",
"return",
"s",
"/",
"denominator",
";",
"}"
] |
Function computing the sample variance of the given sequence.
@param {number} ddof - Delta degrees of freedom.
@param {array} sequence - The sequence to process.
@return {number} - The variance.
@throws {Error} - The function expects a non-empty list.
|
[
"Function",
"computing",
"the",
"sample",
"variance",
"of",
"the",
"given",
"sequence",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/stats/inferential.js#L18-L38
|
18,202
|
Yomguithereal/talisman
|
src/stats/inferential.js
|
genericStdev
|
function genericStdev(ddof, sequence) {
const v = genericVariance(ddof, sequence);
return Math.sqrt(v);
}
|
javascript
|
function genericStdev(ddof, sequence) {
const v = genericVariance(ddof, sequence);
return Math.sqrt(v);
}
|
[
"function",
"genericStdev",
"(",
"ddof",
",",
"sequence",
")",
"{",
"const",
"v",
"=",
"genericVariance",
"(",
"ddof",
",",
"sequence",
")",
";",
"return",
"Math",
".",
"sqrt",
"(",
"v",
")",
";",
"}"
] |
Function computing the sample standard deviation of the given sequence.
@param {number} ddof - Delta degrees of freedom.
@param {array} sequence - The sequence to process.
@return {number} - The variance.
@throws {Error} - The function expects a non-empty list.
|
[
"Function",
"computing",
"the",
"sample",
"standard",
"deviation",
"of",
"the",
"given",
"sequence",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/stats/inferential.js#L49-L53
|
18,203
|
Yomguithereal/talisman
|
src/metrics/distance/sift4.js
|
withoutTranspositions
|
function withoutTranspositions(maxOffset, maxDistance, a, b) {
// Early termination
if (a === b)
return 0;
const la = a.length,
lb = b.length;
if (!la || !lb)
return Math.max(la, lb);
let cursorA = 0,
cursorB = 0,
longestCommonSubsequence = 0,
localCommonSubstring = 0;
while (cursorA < la && cursorB < lb) {
if (a[cursorA] === b[cursorB]) {
localCommonSubstring++;
}
else {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
if (cursorA !== cursorB)
cursorA = cursorB = Math.max(cursorA, cursorB);
for (let i = 0; i < maxOffset && (cursorA + i < la || cursorB + i < lb); i++) {
if (cursorA + i < la && a[cursorA + i] === b[cursorB]) {
cursorA += i;
localCommonSubstring++;
break;
}
if (cursorB + i < lb && a[cursorA] === b[cursorB + i]) {
cursorB += i;
localCommonSubstring++;
break;
}
}
}
cursorA++;
cursorB++;
if (maxDistance) {
const tempDistance = Math.max(cursorA, cursorB) - longestCommonSubsequence;
if (tempDistance === maxDistance)
return maxDistance;
if (tempDistance > maxDistance)
return Infinity;
}
}
longestCommonSubsequence += localCommonSubstring;
return Math.max(la, lb) - longestCommonSubsequence;
}
|
javascript
|
function withoutTranspositions(maxOffset, maxDistance, a, b) {
// Early termination
if (a === b)
return 0;
const la = a.length,
lb = b.length;
if (!la || !lb)
return Math.max(la, lb);
let cursorA = 0,
cursorB = 0,
longestCommonSubsequence = 0,
localCommonSubstring = 0;
while (cursorA < la && cursorB < lb) {
if (a[cursorA] === b[cursorB]) {
localCommonSubstring++;
}
else {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
if (cursorA !== cursorB)
cursorA = cursorB = Math.max(cursorA, cursorB);
for (let i = 0; i < maxOffset && (cursorA + i < la || cursorB + i < lb); i++) {
if (cursorA + i < la && a[cursorA + i] === b[cursorB]) {
cursorA += i;
localCommonSubstring++;
break;
}
if (cursorB + i < lb && a[cursorA] === b[cursorB + i]) {
cursorB += i;
localCommonSubstring++;
break;
}
}
}
cursorA++;
cursorB++;
if (maxDistance) {
const tempDistance = Math.max(cursorA, cursorB) - longestCommonSubsequence;
if (tempDistance === maxDistance)
return maxDistance;
if (tempDistance > maxDistance)
return Infinity;
}
}
longestCommonSubsequence += localCommonSubstring;
return Math.max(la, lb) - longestCommonSubsequence;
}
|
[
"function",
"withoutTranspositions",
"(",
"maxOffset",
",",
"maxDistance",
",",
"a",
",",
"b",
")",
"{",
"// Early termination",
"if",
"(",
"a",
"===",
"b",
")",
"return",
"0",
";",
"const",
"la",
"=",
"a",
".",
"length",
",",
"lb",
"=",
"b",
".",
"length",
";",
"if",
"(",
"!",
"la",
"||",
"!",
"lb",
")",
"return",
"Math",
".",
"max",
"(",
"la",
",",
"lb",
")",
";",
"let",
"cursorA",
"=",
"0",
",",
"cursorB",
"=",
"0",
",",
"longestCommonSubsequence",
"=",
"0",
",",
"localCommonSubstring",
"=",
"0",
";",
"while",
"(",
"cursorA",
"<",
"la",
"&&",
"cursorB",
"<",
"lb",
")",
"{",
"if",
"(",
"a",
"[",
"cursorA",
"]",
"===",
"b",
"[",
"cursorB",
"]",
")",
"{",
"localCommonSubstring",
"++",
";",
"}",
"else",
"{",
"longestCommonSubsequence",
"+=",
"localCommonSubstring",
";",
"localCommonSubstring",
"=",
"0",
";",
"if",
"(",
"cursorA",
"!==",
"cursorB",
")",
"cursorA",
"=",
"cursorB",
"=",
"Math",
".",
"max",
"(",
"cursorA",
",",
"cursorB",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"maxOffset",
"&&",
"(",
"cursorA",
"+",
"i",
"<",
"la",
"||",
"cursorB",
"+",
"i",
"<",
"lb",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cursorA",
"+",
"i",
"<",
"la",
"&&",
"a",
"[",
"cursorA",
"+",
"i",
"]",
"===",
"b",
"[",
"cursorB",
"]",
")",
"{",
"cursorA",
"+=",
"i",
";",
"localCommonSubstring",
"++",
";",
"break",
";",
"}",
"if",
"(",
"cursorB",
"+",
"i",
"<",
"lb",
"&&",
"a",
"[",
"cursorA",
"]",
"===",
"b",
"[",
"cursorB",
"+",
"i",
"]",
")",
"{",
"cursorB",
"+=",
"i",
";",
"localCommonSubstring",
"++",
";",
"break",
";",
"}",
"}",
"}",
"cursorA",
"++",
";",
"cursorB",
"++",
";",
"if",
"(",
"maxDistance",
")",
"{",
"const",
"tempDistance",
"=",
"Math",
".",
"max",
"(",
"cursorA",
",",
"cursorB",
")",
"-",
"longestCommonSubsequence",
";",
"if",
"(",
"tempDistance",
"===",
"maxDistance",
")",
"return",
"maxDistance",
";",
"if",
"(",
"tempDistance",
">",
"maxDistance",
")",
"return",
"Infinity",
";",
"}",
"}",
"longestCommonSubsequence",
"+=",
"localCommonSubstring",
";",
"return",
"Math",
".",
"max",
"(",
"la",
",",
"lb",
")",
"-",
"longestCommonSubsequence",
";",
"}"
] |
Simplest version of the SIFT4 algorithm.
@param {number} maxOffset - Search window.
@param {number} maxDistance - Maximum distance before exiting.
@param {string|array} a - First sequence.
@param {string|array} b - Second sequence.
@return {number} - The distance.
|
[
"Simplest",
"version",
"of",
"the",
"SIFT4",
"algorithm",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/metrics/distance/sift4.js#L35-L94
|
18,204
|
Yomguithereal/talisman
|
src/metrics/distance/sift4.js
|
withTranspositions
|
function withTranspositions(maxOffset, maxDistance, a, b) {
// Early termination
if (a === b)
return 0;
const la = a.length,
lb = b.length;
if (!la || !lb)
return Math.max(la, lb);
let cursorA = 0,
cursorB = 0,
longestCommonSubsequence = 0,
localCommonSubstring = 0,
transpositions = 0;
const offsetArray = [];
while (cursorA < la && cursorB < lb) {
if (a[cursorA] === b[cursorB]) {
localCommonSubstring++;
let isTransposition = false,
i = 0;
while (i < offsetArray.length) {
const offset = offsetArray[i];
if (cursorA <= offset.cursorA || cursorB <= offset.cursorB) {
isTransposition = Math.abs(cursorB - cursorA) >= Math.abs(offset.cursorB - offset.cursorA);
if (isTransposition) {
transpositions++;
}
else {
if (!offset.isTransposition) {
offset.isTransposition = true;
transpositions++;
}
}
break;
}
else {
// NOTE: we could marginally enhance the performance of the algo
// by using an object rather than splicing the array
if (cursorA > offset.cursorB && cursorB > offset.cursorA)
offsetArray.splice(i, 1);
else
i++;
}
}
offsetArray.push({
cursorA,
cursorB,
isTransposition
});
}
else {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
if (cursorA !== cursorB)
cursorA = cursorB = Math.min(cursorA, cursorB);
for (let i = 0; i < maxOffset && (cursorA + i < la || cursorB + i < lb); i++) {
if ((cursorA + i < la) && a[cursorA + i] === b[cursorB]) {
cursorA += i - 1;
cursorB--;
break;
}
if ((cursorB + i < lb) && a[cursorA] === b[cursorB + i]) {
cursorA--;
cursorB += i - 1;
break;
}
}
}
cursorA++;
cursorB++;
// NOTE: this was below maxDistance check in original implemenation but
// this looked suspicious
if (cursorA >= la || cursorB >= lb) {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
cursorA = cursorB = Math.min(cursorA, cursorB);
}
if (maxDistance) {
const tempDistance = (
Math.max(cursorA, cursorB) -
longestCommonSubsequence +
transpositions
);
if (tempDistance === maxDistance)
return maxDistance;
if (tempDistance > maxDistance)
return Infinity;
}
}
longestCommonSubsequence += localCommonSubstring;
return Math.max(la, lb) - longestCommonSubsequence + transpositions;
}
|
javascript
|
function withTranspositions(maxOffset, maxDistance, a, b) {
// Early termination
if (a === b)
return 0;
const la = a.length,
lb = b.length;
if (!la || !lb)
return Math.max(la, lb);
let cursorA = 0,
cursorB = 0,
longestCommonSubsequence = 0,
localCommonSubstring = 0,
transpositions = 0;
const offsetArray = [];
while (cursorA < la && cursorB < lb) {
if (a[cursorA] === b[cursorB]) {
localCommonSubstring++;
let isTransposition = false,
i = 0;
while (i < offsetArray.length) {
const offset = offsetArray[i];
if (cursorA <= offset.cursorA || cursorB <= offset.cursorB) {
isTransposition = Math.abs(cursorB - cursorA) >= Math.abs(offset.cursorB - offset.cursorA);
if (isTransposition) {
transpositions++;
}
else {
if (!offset.isTransposition) {
offset.isTransposition = true;
transpositions++;
}
}
break;
}
else {
// NOTE: we could marginally enhance the performance of the algo
// by using an object rather than splicing the array
if (cursorA > offset.cursorB && cursorB > offset.cursorA)
offsetArray.splice(i, 1);
else
i++;
}
}
offsetArray.push({
cursorA,
cursorB,
isTransposition
});
}
else {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
if (cursorA !== cursorB)
cursorA = cursorB = Math.min(cursorA, cursorB);
for (let i = 0; i < maxOffset && (cursorA + i < la || cursorB + i < lb); i++) {
if ((cursorA + i < la) && a[cursorA + i] === b[cursorB]) {
cursorA += i - 1;
cursorB--;
break;
}
if ((cursorB + i < lb) && a[cursorA] === b[cursorB + i]) {
cursorA--;
cursorB += i - 1;
break;
}
}
}
cursorA++;
cursorB++;
// NOTE: this was below maxDistance check in original implemenation but
// this looked suspicious
if (cursorA >= la || cursorB >= lb) {
longestCommonSubsequence += localCommonSubstring;
localCommonSubstring = 0;
cursorA = cursorB = Math.min(cursorA, cursorB);
}
if (maxDistance) {
const tempDistance = (
Math.max(cursorA, cursorB) -
longestCommonSubsequence +
transpositions
);
if (tempDistance === maxDistance)
return maxDistance;
if (tempDistance > maxDistance)
return Infinity;
}
}
longestCommonSubsequence += localCommonSubstring;
return Math.max(la, lb) - longestCommonSubsequence + transpositions;
}
|
[
"function",
"withTranspositions",
"(",
"maxOffset",
",",
"maxDistance",
",",
"a",
",",
"b",
")",
"{",
"// Early termination",
"if",
"(",
"a",
"===",
"b",
")",
"return",
"0",
";",
"const",
"la",
"=",
"a",
".",
"length",
",",
"lb",
"=",
"b",
".",
"length",
";",
"if",
"(",
"!",
"la",
"||",
"!",
"lb",
")",
"return",
"Math",
".",
"max",
"(",
"la",
",",
"lb",
")",
";",
"let",
"cursorA",
"=",
"0",
",",
"cursorB",
"=",
"0",
",",
"longestCommonSubsequence",
"=",
"0",
",",
"localCommonSubstring",
"=",
"0",
",",
"transpositions",
"=",
"0",
";",
"const",
"offsetArray",
"=",
"[",
"]",
";",
"while",
"(",
"cursorA",
"<",
"la",
"&&",
"cursorB",
"<",
"lb",
")",
"{",
"if",
"(",
"a",
"[",
"cursorA",
"]",
"===",
"b",
"[",
"cursorB",
"]",
")",
"{",
"localCommonSubstring",
"++",
";",
"let",
"isTransposition",
"=",
"false",
",",
"i",
"=",
"0",
";",
"while",
"(",
"i",
"<",
"offsetArray",
".",
"length",
")",
"{",
"const",
"offset",
"=",
"offsetArray",
"[",
"i",
"]",
";",
"if",
"(",
"cursorA",
"<=",
"offset",
".",
"cursorA",
"||",
"cursorB",
"<=",
"offset",
".",
"cursorB",
")",
"{",
"isTransposition",
"=",
"Math",
".",
"abs",
"(",
"cursorB",
"-",
"cursorA",
")",
">=",
"Math",
".",
"abs",
"(",
"offset",
".",
"cursorB",
"-",
"offset",
".",
"cursorA",
")",
";",
"if",
"(",
"isTransposition",
")",
"{",
"transpositions",
"++",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"offset",
".",
"isTransposition",
")",
"{",
"offset",
".",
"isTransposition",
"=",
"true",
";",
"transpositions",
"++",
";",
"}",
"}",
"break",
";",
"}",
"else",
"{",
"// NOTE: we could marginally enhance the performance of the algo",
"// by using an object rather than splicing the array",
"if",
"(",
"cursorA",
">",
"offset",
".",
"cursorB",
"&&",
"cursorB",
">",
"offset",
".",
"cursorA",
")",
"offsetArray",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"else",
"i",
"++",
";",
"}",
"}",
"offsetArray",
".",
"push",
"(",
"{",
"cursorA",
",",
"cursorB",
",",
"isTransposition",
"}",
")",
";",
"}",
"else",
"{",
"longestCommonSubsequence",
"+=",
"localCommonSubstring",
";",
"localCommonSubstring",
"=",
"0",
";",
"if",
"(",
"cursorA",
"!==",
"cursorB",
")",
"cursorA",
"=",
"cursorB",
"=",
"Math",
".",
"min",
"(",
"cursorA",
",",
"cursorB",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"maxOffset",
"&&",
"(",
"cursorA",
"+",
"i",
"<",
"la",
"||",
"cursorB",
"+",
"i",
"<",
"lb",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"cursorA",
"+",
"i",
"<",
"la",
")",
"&&",
"a",
"[",
"cursorA",
"+",
"i",
"]",
"===",
"b",
"[",
"cursorB",
"]",
")",
"{",
"cursorA",
"+=",
"i",
"-",
"1",
";",
"cursorB",
"--",
";",
"break",
";",
"}",
"if",
"(",
"(",
"cursorB",
"+",
"i",
"<",
"lb",
")",
"&&",
"a",
"[",
"cursorA",
"]",
"===",
"b",
"[",
"cursorB",
"+",
"i",
"]",
")",
"{",
"cursorA",
"--",
";",
"cursorB",
"+=",
"i",
"-",
"1",
";",
"break",
";",
"}",
"}",
"}",
"cursorA",
"++",
";",
"cursorB",
"++",
";",
"// NOTE: this was below maxDistance check in original implemenation but",
"// this looked suspicious",
"if",
"(",
"cursorA",
">=",
"la",
"||",
"cursorB",
">=",
"lb",
")",
"{",
"longestCommonSubsequence",
"+=",
"localCommonSubstring",
";",
"localCommonSubstring",
"=",
"0",
";",
"cursorA",
"=",
"cursorB",
"=",
"Math",
".",
"min",
"(",
"cursorA",
",",
"cursorB",
")",
";",
"}",
"if",
"(",
"maxDistance",
")",
"{",
"const",
"tempDistance",
"=",
"(",
"Math",
".",
"max",
"(",
"cursorA",
",",
"cursorB",
")",
"-",
"longestCommonSubsequence",
"+",
"transpositions",
")",
";",
"if",
"(",
"tempDistance",
"===",
"maxDistance",
")",
"return",
"maxDistance",
";",
"if",
"(",
"tempDistance",
">",
"maxDistance",
")",
"return",
"Infinity",
";",
"}",
"}",
"longestCommonSubsequence",
"+=",
"localCommonSubstring",
";",
"return",
"Math",
".",
"max",
"(",
"la",
",",
"lb",
")",
"-",
"longestCommonSubsequence",
"+",
"transpositions",
";",
"}"
] |
Version of the SIFT4 function computing transpositions.
@param {number} maxOffset - Search window.
@param {number} maxDistance - Maximum distance before exiting.
@param {string|array} a - First sequence.
@param {string|array} b - Second sequence.
@return {number} - The distance.
|
[
"Version",
"of",
"the",
"SIFT4",
"function",
"computing",
"transpositions",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/metrics/distance/sift4.js#L105-L223
|
18,205
|
Yomguithereal/talisman
|
src/tag/averaged-perceptron.js
|
createContext
|
function createContext(sentence) {
const context = new Array(sentence.length + 4);
context[0] = START[0];
context[1] = START[1];
for (let j = 0, m = sentence.length; j < m; j++)
context[j + 2] = normalize(sentence[j][0]);
context[context.length - 2] = END[0];
context[context.length - 1] = END[1];
return context;
}
|
javascript
|
function createContext(sentence) {
const context = new Array(sentence.length + 4);
context[0] = START[0];
context[1] = START[1];
for (let j = 0, m = sentence.length; j < m; j++)
context[j + 2] = normalize(sentence[j][0]);
context[context.length - 2] = END[0];
context[context.length - 1] = END[1];
return context;
}
|
[
"function",
"createContext",
"(",
"sentence",
")",
"{",
"const",
"context",
"=",
"new",
"Array",
"(",
"sentence",
".",
"length",
"+",
"4",
")",
";",
"context",
"[",
"0",
"]",
"=",
"START",
"[",
"0",
"]",
";",
"context",
"[",
"1",
"]",
"=",
"START",
"[",
"1",
"]",
";",
"for",
"(",
"let",
"j",
"=",
"0",
",",
"m",
"=",
"sentence",
".",
"length",
";",
"j",
"<",
"m",
";",
"j",
"++",
")",
"context",
"[",
"j",
"+",
"2",
"]",
"=",
"normalize",
"(",
"sentence",
"[",
"j",
"]",
"[",
"0",
"]",
")",
";",
"context",
"[",
"context",
".",
"length",
"-",
"2",
"]",
"=",
"END",
"[",
"0",
"]",
";",
"context",
"[",
"context",
".",
"length",
"-",
"1",
"]",
"=",
"END",
"[",
"1",
"]",
";",
"return",
"context",
";",
"}"
] |
Function used to build a context from the given tokenized sentence.
@param {array} sentence - Target sentence.
@return {array} - Context.
|
[
"Function",
"used",
"to",
"build",
"a",
"context",
"from",
"the",
"given",
"tokenized",
"sentence",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/tag/averaged-perceptron.js#L123-L135
|
18,206
|
Yomguithereal/talisman
|
src/inflectors/spanish/noun.js
|
transferCase
|
function transferCase(source, target) {
let cased = '';
for (let i = 0, l = target.length; i < l; i++) {
const c = source[i].toLowerCase() === source[i] ?
'toLowerCase' :
'toUpperCase';
cased += target[i][c]();
}
return cased;
}
|
javascript
|
function transferCase(source, target) {
let cased = '';
for (let i = 0, l = target.length; i < l; i++) {
const c = source[i].toLowerCase() === source[i] ?
'toLowerCase' :
'toUpperCase';
cased += target[i][c]();
}
return cased;
}
|
[
"function",
"transferCase",
"(",
"source",
",",
"target",
")",
"{",
"let",
"cased",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"target",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"c",
"=",
"source",
"[",
"i",
"]",
".",
"toLowerCase",
"(",
")",
"===",
"source",
"[",
"i",
"]",
"?",
"'toLowerCase'",
":",
"'toUpperCase'",
";",
"cased",
"+=",
"target",
"[",
"i",
"]",
"[",
"c",
"]",
"(",
")",
";",
"}",
"return",
"cased",
";",
"}"
] |
Function used to apply source word's case to target word.
@param {string} source - Source word.
@param {string} target - Target word.
@return {string}
|
[
"Function",
"used",
"to",
"apply",
"source",
"word",
"s",
"case",
"to",
"target",
"word",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/inflectors/spanish/noun.js#L77-L89
|
18,207
|
Yomguithereal/talisman
|
src/phonetics/nysiis.js
|
nysiis
|
function nysiis(type, name) {
if (typeof name !== 'string')
throw Error('talisman/phonetics/nysiis: the given name is not a string.');
// Preparing the string
name = deburr(name)
.toUpperCase()
.trim()
.replace(/[^A-Z]/g, '');
// Getting the proper patterns
const patterns = PATTERNS[type];
// Applying the first substitutions
for (let i = 0, l = patterns.first.length; i < l; i++) {
const [match, replacement] = patterns.first[i];
name = name.replace(match, replacement);
}
// Storing the first letter
const firstLetter = name.charAt(0);
// Eating the first letter if applying the original algorithm
if (type === 'original')
name = name.slice(1);
// Applying the second substitutions
for (let i = 0, l = patterns.second.length; i < l; i++) {
const [match, replacement] = patterns.second[i];
name = name.replace(match, replacement);
}
// Returning the squeezed code
return firstLetter + squeeze(name);
}
|
javascript
|
function nysiis(type, name) {
if (typeof name !== 'string')
throw Error('talisman/phonetics/nysiis: the given name is not a string.');
// Preparing the string
name = deburr(name)
.toUpperCase()
.trim()
.replace(/[^A-Z]/g, '');
// Getting the proper patterns
const patterns = PATTERNS[type];
// Applying the first substitutions
for (let i = 0, l = patterns.first.length; i < l; i++) {
const [match, replacement] = patterns.first[i];
name = name.replace(match, replacement);
}
// Storing the first letter
const firstLetter = name.charAt(0);
// Eating the first letter if applying the original algorithm
if (type === 'original')
name = name.slice(1);
// Applying the second substitutions
for (let i = 0, l = patterns.second.length; i < l; i++) {
const [match, replacement] = patterns.second[i];
name = name.replace(match, replacement);
}
// Returning the squeezed code
return firstLetter + squeeze(name);
}
|
[
"function",
"nysiis",
"(",
"type",
",",
"name",
")",
"{",
"if",
"(",
"typeof",
"name",
"!==",
"'string'",
")",
"throw",
"Error",
"(",
"'talisman/phonetics/nysiis: the given name is not a string.'",
")",
";",
"// Preparing the string",
"name",
"=",
"deburr",
"(",
"name",
")",
".",
"toUpperCase",
"(",
")",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"[^A-Z]",
"/",
"g",
",",
"''",
")",
";",
"// Getting the proper patterns",
"const",
"patterns",
"=",
"PATTERNS",
"[",
"type",
"]",
";",
"// Applying the first substitutions",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"patterns",
".",
"first",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"[",
"match",
",",
"replacement",
"]",
"=",
"patterns",
".",
"first",
"[",
"i",
"]",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"match",
",",
"replacement",
")",
";",
"}",
"// Storing the first letter",
"const",
"firstLetter",
"=",
"name",
".",
"charAt",
"(",
"0",
")",
";",
"// Eating the first letter if applying the original algorithm",
"if",
"(",
"type",
"===",
"'original'",
")",
"name",
"=",
"name",
".",
"slice",
"(",
"1",
")",
";",
"// Applying the second substitutions",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"patterns",
".",
"second",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"[",
"match",
",",
"replacement",
"]",
"=",
"patterns",
".",
"second",
"[",
"i",
"]",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"match",
",",
"replacement",
")",
";",
"}",
"// Returning the squeezed code",
"return",
"firstLetter",
"+",
"squeeze",
"(",
"name",
")",
";",
"}"
] |
Function taking a single name and computing its NYSIIS code.
@param {string} name - The name to process.
@return {string} - The NYSIIS code.
@throws {Error} The function expects the name to be a string.
|
[
"Function",
"taking",
"a",
"single",
"name",
"and",
"computing",
"its",
"NYSIIS",
"code",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/phonetics/nysiis.js#L92-L128
|
18,208
|
Yomguithereal/talisman
|
src/stats/frequencies.js
|
frequencies
|
function frequencies(sequence) {
const index = {};
// Handling strings
sequence = seq(sequence);
for (let i = 0, l = sequence.length; i < l; i++) {
const element = sequence[i];
if (!index[element])
index[element] = 0;
index[element]++;
}
return index;
}
|
javascript
|
function frequencies(sequence) {
const index = {};
// Handling strings
sequence = seq(sequence);
for (let i = 0, l = sequence.length; i < l; i++) {
const element = sequence[i];
if (!index[element])
index[element] = 0;
index[element]++;
}
return index;
}
|
[
"function",
"frequencies",
"(",
"sequence",
")",
"{",
"const",
"index",
"=",
"{",
"}",
";",
"// Handling strings",
"sequence",
"=",
"seq",
"(",
"sequence",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"sequence",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"element",
"=",
"sequence",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"index",
"[",
"element",
"]",
")",
"index",
"[",
"element",
"]",
"=",
"0",
";",
"index",
"[",
"element",
"]",
"++",
";",
"}",
"return",
"index",
";",
"}"
] |
Function taking a sequence and computing its frequencies.
@param {mixed} sequence - The sequence to process.
@return {object} - A dict of the sequence's frequencies.
@example
// frequencies([1, 1, 2, 3, 3, 3]) => {1: 2, 2: 1, 3: 3}
// frequencies('test') => {t: 2, e: 1, s: 1}
|
[
"Function",
"taking",
"a",
"sequence",
"and",
"computing",
"its",
"frequencies",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/stats/frequencies.js#L19-L34
|
18,209
|
Yomguithereal/talisman
|
src/stats/frequencies.js
|
relativeFrequencies
|
function relativeFrequencies(sequence) {
let index,
length;
// Handling the object polymorphism
if (typeof sequence === 'object' && !Array.isArray(sequence)) {
index = sequence;
length = 0;
for (const k in index)
length += index[k];
}
else {
length = sequence.length;
index = frequencies(sequence);
}
const relativeIndex = {};
for (const k in index)
relativeIndex[k] = index[k] / length;
return relativeIndex;
}
|
javascript
|
function relativeFrequencies(sequence) {
let index,
length;
// Handling the object polymorphism
if (typeof sequence === 'object' && !Array.isArray(sequence)) {
index = sequence;
length = 0;
for (const k in index)
length += index[k];
}
else {
length = sequence.length;
index = frequencies(sequence);
}
const relativeIndex = {};
for (const k in index)
relativeIndex[k] = index[k] / length;
return relativeIndex;
}
|
[
"function",
"relativeFrequencies",
"(",
"sequence",
")",
"{",
"let",
"index",
",",
"length",
";",
"// Handling the object polymorphism",
"if",
"(",
"typeof",
"sequence",
"===",
"'object'",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"sequence",
")",
")",
"{",
"index",
"=",
"sequence",
";",
"length",
"=",
"0",
";",
"for",
"(",
"const",
"k",
"in",
"index",
")",
"length",
"+=",
"index",
"[",
"k",
"]",
";",
"}",
"else",
"{",
"length",
"=",
"sequence",
".",
"length",
";",
"index",
"=",
"frequencies",
"(",
"sequence",
")",
";",
"}",
"const",
"relativeIndex",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"k",
"in",
"index",
")",
"relativeIndex",
"[",
"k",
"]",
"=",
"index",
"[",
"k",
"]",
"/",
"length",
";",
"return",
"relativeIndex",
";",
"}"
] |
Relative version of the `frequencies` function.
@param {mixed} sequence - The sequence to process. If an object is passed
the function will assume it's representing
absolute frequencies.
@return {object} - A dict of the sequence's relative frequencies.
@example
// frequencies([1, 1, 2, 3, 3, 3]) => {1: ~0.33, 2: ~0.16, 3: 0.5}
// frequencies('test') => {t: 0.5, e: 0.25, s: 0.25}
|
[
"Relative",
"version",
"of",
"the",
"frequencies",
"function",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/stats/frequencies.js#L48-L71
|
18,210
|
Yomguithereal/talisman
|
src/tokenizers/sentences/punkt.js
|
dunningLogLikelihood
|
function dunningLogLikelihood(a, b, ab, N) {
const p1 = b / N,
p2 = 0.99;
const nullHypothesis = ab * Math.log(p1) + (a - ab) * Math.log(1 - p1),
alternativeHyphothesis = ab * Math.log(p2) + (a - ab) * Math.log(1 - p2);
const likelihood = nullHypothesis - alternativeHyphothesis;
return (-2 * likelihood);
}
|
javascript
|
function dunningLogLikelihood(a, b, ab, N) {
const p1 = b / N,
p2 = 0.99;
const nullHypothesis = ab * Math.log(p1) + (a - ab) * Math.log(1 - p1),
alternativeHyphothesis = ab * Math.log(p2) + (a - ab) * Math.log(1 - p2);
const likelihood = nullHypothesis - alternativeHyphothesis;
return (-2 * likelihood);
}
|
[
"function",
"dunningLogLikelihood",
"(",
"a",
",",
"b",
",",
"ab",
",",
"N",
")",
"{",
"const",
"p1",
"=",
"b",
"/",
"N",
",",
"p2",
"=",
"0.99",
";",
"const",
"nullHypothesis",
"=",
"ab",
"*",
"Math",
".",
"log",
"(",
"p1",
")",
"+",
"(",
"a",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p1",
")",
",",
"alternativeHyphothesis",
"=",
"ab",
"*",
"Math",
".",
"log",
"(",
"p2",
")",
"+",
"(",
"a",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p2",
")",
";",
"const",
"likelihood",
"=",
"nullHypothesis",
"-",
"alternativeHyphothesis",
";",
"return",
"(",
"-",
"2",
"*",
"likelihood",
")",
";",
"}"
] |
Miscellaneous helpers.
Computing the Dunning log-likelihood ratio scores for abbreviation
candidates.
@param {number} a - Count of <a>.
@param {number} b - Count of <b>.
@param {number} ab - Count of <ab>.
@param {number} N - Number of elements in the distribution.
@return {number} - The log-likelihood.
|
[
"Miscellaneous",
"helpers",
".",
"Computing",
"the",
"Dunning",
"log",
"-",
"likelihood",
"ratio",
"scores",
"for",
"abbreviation",
"candidates",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/tokenizers/sentences/punkt.js#L428-L438
|
18,211
|
Yomguithereal/talisman
|
src/tokenizers/sentences/punkt.js
|
colLogLikelihood
|
function colLogLikelihood(a, b, ab, N) {
const p = b / N,
p1 = ab / a,
p2 = (b - ab) / (N - a);
const summand1 = ab * Math.log(p) + (a - ab) * Math.log(1 - p),
summand2 = (b - ab) * Math.log(p) + (N - a - b + ab) * Math.log(1 - p);
let summand3 = 0;
if (a !== ab)
summand3 = ab * Math.log(p1) + (a - ab) * Math.log(1 - p1);
let summand4 = 0;
if (b !== ab)
summand4 = (b - ab) * Math.log(p2) + (N - a - b + ab) * Math.log(1 - p2);
const likelihood = summand1 + summand2 - summand3 - summand4;
return (-2 * likelihood);
}
|
javascript
|
function colLogLikelihood(a, b, ab, N) {
const p = b / N,
p1 = ab / a,
p2 = (b - ab) / (N - a);
const summand1 = ab * Math.log(p) + (a - ab) * Math.log(1 - p),
summand2 = (b - ab) * Math.log(p) + (N - a - b + ab) * Math.log(1 - p);
let summand3 = 0;
if (a !== ab)
summand3 = ab * Math.log(p1) + (a - ab) * Math.log(1 - p1);
let summand4 = 0;
if (b !== ab)
summand4 = (b - ab) * Math.log(p2) + (N - a - b + ab) * Math.log(1 - p2);
const likelihood = summand1 + summand2 - summand3 - summand4;
return (-2 * likelihood);
}
|
[
"function",
"colLogLikelihood",
"(",
"a",
",",
"b",
",",
"ab",
",",
"N",
")",
"{",
"const",
"p",
"=",
"b",
"/",
"N",
",",
"p1",
"=",
"ab",
"/",
"a",
",",
"p2",
"=",
"(",
"b",
"-",
"ab",
")",
"/",
"(",
"N",
"-",
"a",
")",
";",
"const",
"summand1",
"=",
"ab",
"*",
"Math",
".",
"log",
"(",
"p",
")",
"+",
"(",
"a",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p",
")",
",",
"summand2",
"=",
"(",
"b",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"p",
")",
"+",
"(",
"N",
"-",
"a",
"-",
"b",
"+",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p",
")",
";",
"let",
"summand3",
"=",
"0",
";",
"if",
"(",
"a",
"!==",
"ab",
")",
"summand3",
"=",
"ab",
"*",
"Math",
".",
"log",
"(",
"p1",
")",
"+",
"(",
"a",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p1",
")",
";",
"let",
"summand4",
"=",
"0",
";",
"if",
"(",
"b",
"!==",
"ab",
")",
"summand4",
"=",
"(",
"b",
"-",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"p2",
")",
"+",
"(",
"N",
"-",
"a",
"-",
"b",
"+",
"ab",
")",
"*",
"Math",
".",
"log",
"(",
"1",
"-",
"p2",
")",
";",
"const",
"likelihood",
"=",
"summand1",
"+",
"summand2",
"-",
"summand3",
"-",
"summand4",
";",
"return",
"(",
"-",
"2",
"*",
"likelihood",
")",
";",
"}"
] |
A function that wil just compute log-likelihood estimate, in the original
paper, it's described in algorithm 6 and 7.
Note: this SHOULD be the original Dunning log-likelihood values.
@param {number} a - Count of <a>.
@param {number} b - Count of <b>.
@param {number} ab - Count of <ab>.
@param {number} N - Number of elements in the distribution.
@return {number} - The log-likelihood.
|
[
"A",
"function",
"that",
"wil",
"just",
"compute",
"log",
"-",
"likelihood",
"estimate",
"in",
"the",
"original",
"paper",
"it",
"s",
"described",
"in",
"algorithm",
"6",
"and",
"7",
"."
] |
51756b23cfd7e32c61f11c2f5a31f6396d15812a
|
https://github.com/Yomguithereal/talisman/blob/51756b23cfd7e32c61f11c2f5a31f6396d15812a/src/tokenizers/sentences/punkt.js#L452-L471
|
18,212
|
filamentgroup/politespace
|
dist/libs/libs.js
|
function( name, value ) {
if ( completed == null ) {
name = requestHeadersNames[ name.toLowerCase() ] =
requestHeadersNames[ name.toLowerCase() ] || name;
requestHeaders[ name ] = value;
}
return this;
}
|
javascript
|
function( name, value ) {
if ( completed == null ) {
name = requestHeadersNames[ name.toLowerCase() ] =
requestHeadersNames[ name.toLowerCase() ] || name;
requestHeaders[ name ] = value;
}
return this;
}
|
[
"function",
"(",
"name",
",",
"value",
")",
"{",
"if",
"(",
"completed",
"==",
"null",
")",
"{",
"name",
"=",
"requestHeadersNames",
"[",
"name",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"requestHeadersNames",
"[",
"name",
".",
"toLowerCase",
"(",
")",
"]",
"||",
"name",
";",
"requestHeaders",
"[",
"name",
"]",
"=",
"value",
";",
"}",
"return",
"this",
";",
"}"
] |
Caches the header
|
[
"Caches",
"the",
"header"
] |
4486a6d036e21821c27f491d2524e02a7f61ffbd
|
https://github.com/filamentgroup/politespace/blob/4486a6d036e21821c27f491d2524e02a7f61ffbd/dist/libs/libs.js#L8953-L8960
|
|
18,213
|
mikaelbr/marked-terminal
|
index.js
|
reflowText
|
function reflowText (text, width, gfm) {
// Hard break was inserted by Renderer.prototype.br or is
// <br /> when gfm is true
var splitRe = gfm ? HARD_RETURN_GFM_RE : HARD_RETURN_RE,
sections = text.split(splitRe),
reflowed = [];
sections.forEach(function (section) {
// Split the section by escape codes so that we can
// deal with them separately.
var fragments = section.split(/(\u001b\[(?:\d{1,3})(?:;\d{1,3})*m)/g);
var column = 0;
var currentLine = '';
var lastWasEscapeChar = false;
while (fragments.length) {
var fragment = fragments[0];
if (fragment === '') {
fragments.splice(0, 1);
lastWasEscapeChar = false;
continue;
}
// This is an escape code - leave it whole and
// move to the next fragment.
if (!textLength(fragment)) {
currentLine += fragment;
fragments.splice(0, 1);
lastWasEscapeChar = true;
continue;
}
var words = fragment.split(/[ \t\n]+/);
for (var i = 0; i < words.length; i++) {
var word = words[i];
var addSpace = column != 0;
if (lastWasEscapeChar) addSpace = false;
// If adding the new word overflows the required width
if (column + word.length + addSpace > width) {
if (word.length <= width) {
// If the new word is smaller than the required width
// just add it at the beginning of a new line
reflowed.push(currentLine);
currentLine = word;
column = word.length;
} else {
// If the new word is longer than the required width
// split this word into smaller parts.
var w = word.substr(0, width - column - addSpace);
if (addSpace) currentLine += ' ';
currentLine += w;
reflowed.push(currentLine);
currentLine = '';
column = 0;
word = word.substr(w.length);
while (word.length) {
var w = word.substr(0, width);
if (!w.length) break;
if (w.length < width) {
currentLine = w;
column = w.length;
break;
} else {
reflowed.push(w);
word = word.substr(width);
}
}
}
} else {
if (addSpace) {
currentLine += ' ';
column++;
}
currentLine += word;
column += word.length;
}
lastWasEscapeChar = false;
}
fragments.splice(0, 1);
}
if (textLength(currentLine)) reflowed.push(currentLine);
});
return reflowed.join('\n');
}
|
javascript
|
function reflowText (text, width, gfm) {
// Hard break was inserted by Renderer.prototype.br or is
// <br /> when gfm is true
var splitRe = gfm ? HARD_RETURN_GFM_RE : HARD_RETURN_RE,
sections = text.split(splitRe),
reflowed = [];
sections.forEach(function (section) {
// Split the section by escape codes so that we can
// deal with them separately.
var fragments = section.split(/(\u001b\[(?:\d{1,3})(?:;\d{1,3})*m)/g);
var column = 0;
var currentLine = '';
var lastWasEscapeChar = false;
while (fragments.length) {
var fragment = fragments[0];
if (fragment === '') {
fragments.splice(0, 1);
lastWasEscapeChar = false;
continue;
}
// This is an escape code - leave it whole and
// move to the next fragment.
if (!textLength(fragment)) {
currentLine += fragment;
fragments.splice(0, 1);
lastWasEscapeChar = true;
continue;
}
var words = fragment.split(/[ \t\n]+/);
for (var i = 0; i < words.length; i++) {
var word = words[i];
var addSpace = column != 0;
if (lastWasEscapeChar) addSpace = false;
// If adding the new word overflows the required width
if (column + word.length + addSpace > width) {
if (word.length <= width) {
// If the new word is smaller than the required width
// just add it at the beginning of a new line
reflowed.push(currentLine);
currentLine = word;
column = word.length;
} else {
// If the new word is longer than the required width
// split this word into smaller parts.
var w = word.substr(0, width - column - addSpace);
if (addSpace) currentLine += ' ';
currentLine += w;
reflowed.push(currentLine);
currentLine = '';
column = 0;
word = word.substr(w.length);
while (word.length) {
var w = word.substr(0, width);
if (!w.length) break;
if (w.length < width) {
currentLine = w;
column = w.length;
break;
} else {
reflowed.push(w);
word = word.substr(width);
}
}
}
} else {
if (addSpace) {
currentLine += ' ';
column++;
}
currentLine += word;
column += word.length;
}
lastWasEscapeChar = false;
}
fragments.splice(0, 1);
}
if (textLength(currentLine)) reflowed.push(currentLine);
});
return reflowed.join('\n');
}
|
[
"function",
"reflowText",
"(",
"text",
",",
"width",
",",
"gfm",
")",
"{",
"// Hard break was inserted by Renderer.prototype.br or is",
"// <br /> when gfm is true",
"var",
"splitRe",
"=",
"gfm",
"?",
"HARD_RETURN_GFM_RE",
":",
"HARD_RETURN_RE",
",",
"sections",
"=",
"text",
".",
"split",
"(",
"splitRe",
")",
",",
"reflowed",
"=",
"[",
"]",
";",
"sections",
".",
"forEach",
"(",
"function",
"(",
"section",
")",
"{",
"// Split the section by escape codes so that we can",
"// deal with them separately.",
"var",
"fragments",
"=",
"section",
".",
"split",
"(",
"/",
"(\\u001b\\[(?:\\d{1,3})(?:;\\d{1,3})*m)",
"/",
"g",
")",
";",
"var",
"column",
"=",
"0",
";",
"var",
"currentLine",
"=",
"''",
";",
"var",
"lastWasEscapeChar",
"=",
"false",
";",
"while",
"(",
"fragments",
".",
"length",
")",
"{",
"var",
"fragment",
"=",
"fragments",
"[",
"0",
"]",
";",
"if",
"(",
"fragment",
"===",
"''",
")",
"{",
"fragments",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"lastWasEscapeChar",
"=",
"false",
";",
"continue",
";",
"}",
"// This is an escape code - leave it whole and",
"// move to the next fragment.",
"if",
"(",
"!",
"textLength",
"(",
"fragment",
")",
")",
"{",
"currentLine",
"+=",
"fragment",
";",
"fragments",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"lastWasEscapeChar",
"=",
"true",
";",
"continue",
";",
"}",
"var",
"words",
"=",
"fragment",
".",
"split",
"(",
"/",
"[ \\t\\n]+",
"/",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"words",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"word",
"=",
"words",
"[",
"i",
"]",
";",
"var",
"addSpace",
"=",
"column",
"!=",
"0",
";",
"if",
"(",
"lastWasEscapeChar",
")",
"addSpace",
"=",
"false",
";",
"// If adding the new word overflows the required width",
"if",
"(",
"column",
"+",
"word",
".",
"length",
"+",
"addSpace",
">",
"width",
")",
"{",
"if",
"(",
"word",
".",
"length",
"<=",
"width",
")",
"{",
"// If the new word is smaller than the required width",
"// just add it at the beginning of a new line",
"reflowed",
".",
"push",
"(",
"currentLine",
")",
";",
"currentLine",
"=",
"word",
";",
"column",
"=",
"word",
".",
"length",
";",
"}",
"else",
"{",
"// If the new word is longer than the required width",
"// split this word into smaller parts.",
"var",
"w",
"=",
"word",
".",
"substr",
"(",
"0",
",",
"width",
"-",
"column",
"-",
"addSpace",
")",
";",
"if",
"(",
"addSpace",
")",
"currentLine",
"+=",
"' '",
";",
"currentLine",
"+=",
"w",
";",
"reflowed",
".",
"push",
"(",
"currentLine",
")",
";",
"currentLine",
"=",
"''",
";",
"column",
"=",
"0",
";",
"word",
"=",
"word",
".",
"substr",
"(",
"w",
".",
"length",
")",
";",
"while",
"(",
"word",
".",
"length",
")",
"{",
"var",
"w",
"=",
"word",
".",
"substr",
"(",
"0",
",",
"width",
")",
";",
"if",
"(",
"!",
"w",
".",
"length",
")",
"break",
";",
"if",
"(",
"w",
".",
"length",
"<",
"width",
")",
"{",
"currentLine",
"=",
"w",
";",
"column",
"=",
"w",
".",
"length",
";",
"break",
";",
"}",
"else",
"{",
"reflowed",
".",
"push",
"(",
"w",
")",
";",
"word",
"=",
"word",
".",
"substr",
"(",
"width",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"addSpace",
")",
"{",
"currentLine",
"+=",
"' '",
";",
"column",
"++",
";",
"}",
"currentLine",
"+=",
"word",
";",
"column",
"+=",
"word",
".",
"length",
";",
"}",
"lastWasEscapeChar",
"=",
"false",
";",
"}",
"fragments",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"}",
"if",
"(",
"textLength",
"(",
"currentLine",
")",
")",
"reflowed",
".",
"push",
"(",
"currentLine",
")",
";",
"}",
")",
";",
"return",
"reflowed",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] |
Munge \n's and spaces in "text" so that the number of characters between \n's is less than or equal to "width".
|
[
"Munge",
"\\",
"n",
"s",
"and",
"spaces",
"in",
"text",
"so",
"that",
"the",
"number",
"of",
"characters",
"between",
"\\",
"n",
"s",
"is",
"less",
"than",
"or",
"equal",
"to",
"width",
"."
] |
b799d0444739c184018a73174867cb42f6201f10
|
https://github.com/mikaelbr/marked-terminal/blob/b799d0444739c184018a73174867cb42f6201f10/index.js#L226-L321
|
18,214
|
mikaelbr/marked-terminal
|
index.js
|
fixNestedLists
|
function fixNestedLists (body, indent) {
var regex = new RegExp('' +
'(\\S(?: | )?)' + // Last char of current point, plus one or two spaces
// to allow trailing spaces
'((?:' + indent + ')+)' + // Indentation of sub point
'(' + POINT_REGEX + '(?:.*)+)$', 'gm'); // Body of subpoint
return body.replace(regex, '$1\n' + indent + '$2$3');
}
|
javascript
|
function fixNestedLists (body, indent) {
var regex = new RegExp('' +
'(\\S(?: | )?)' + // Last char of current point, plus one or two spaces
// to allow trailing spaces
'((?:' + indent + ')+)' + // Indentation of sub point
'(' + POINT_REGEX + '(?:.*)+)$', 'gm'); // Body of subpoint
return body.replace(regex, '$1\n' + indent + '$2$3');
}
|
[
"function",
"fixNestedLists",
"(",
"body",
",",
"indent",
")",
"{",
"var",
"regex",
"=",
"new",
"RegExp",
"(",
"''",
"+",
"'(\\\\S(?: | )?)'",
"+",
"// Last char of current point, plus one or two spaces",
"// to allow trailing spaces",
"'((?:'",
"+",
"indent",
"+",
"')+)'",
"+",
"// Indentation of sub point",
"'('",
"+",
"POINT_REGEX",
"+",
"'(?:.*)+)$'",
",",
"'gm'",
")",
";",
"// Body of subpoint",
"return",
"body",
".",
"replace",
"(",
"regex",
",",
"'$1\\n'",
"+",
"indent",
"+",
"'$2$3'",
")",
";",
"}"
] |
Prevents nested lists from joining their parent list's last line
|
[
"Prevents",
"nested",
"lists",
"from",
"joining",
"their",
"parent",
"list",
"s",
"last",
"line"
] |
b799d0444739c184018a73174867cb42f6201f10
|
https://github.com/mikaelbr/marked-terminal/blob/b799d0444739c184018a73174867cb42f6201f10/index.js#L337-L344
|
18,215
|
helion3/inspire-tree
|
src/tree.js
|
map
|
function map(tree, method, args) {
return tree.model[method].apply(tree.model, args);
}
|
javascript
|
function map(tree, method, args) {
return tree.model[method].apply(tree.model, args);
}
|
[
"function",
"map",
"(",
"tree",
",",
"method",
",",
"args",
")",
"{",
"return",
"tree",
".",
"model",
"[",
"method",
"]",
".",
"apply",
"(",
"tree",
".",
"model",
",",
"args",
")",
";",
"}"
] |
Maps a method to the root TreeNodes collection.
@private
@param {InspireTree} tree Tree instance.
@param {string} method Method name.
@param {arguments} args Proxied arguments.
@return {mixed} Proxied return value.
|
[
"Maps",
"a",
"method",
"to",
"the",
"root",
"TreeNodes",
"collection",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/tree.js#L20-L22
|
18,216
|
helion3/inspire-tree
|
src/treenodes.js
|
getPredicateFunction
|
function getPredicateFunction(predicate) {
let fn = predicate;
if (_.isString(predicate)) {
fn = node => (_.isFunction(node[predicate]) ? node[predicate]() : node[predicate]);
}
return fn;
}
|
javascript
|
function getPredicateFunction(predicate) {
let fn = predicate;
if (_.isString(predicate)) {
fn = node => (_.isFunction(node[predicate]) ? node[predicate]() : node[predicate]);
}
return fn;
}
|
[
"function",
"getPredicateFunction",
"(",
"predicate",
")",
"{",
"let",
"fn",
"=",
"predicate",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"predicate",
")",
")",
"{",
"fn",
"=",
"node",
"=>",
"(",
"_",
".",
"isFunction",
"(",
"node",
"[",
"predicate",
"]",
")",
"?",
"node",
"[",
"predicate",
"]",
"(",
")",
":",
"node",
"[",
"predicate",
"]",
")",
";",
"}",
"return",
"fn",
";",
"}"
] |
Creates a predicate function.
@private
@param {string|function} predicate Property name or custom function.
@return {function} Predicate function.
|
[
"Creates",
"a",
"predicate",
"function",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/treenodes.js#L42-L49
|
18,217
|
helion3/inspire-tree
|
src/treenodes.js
|
baseStatePredicate
|
function baseStatePredicate(state, full) {
if (full) {
return this.extract(state);
}
// Cache a state predicate function
const fn = getPredicateFunction(state);
return this.flatten(node => {
// Never include removed nodes unless specifically requested
if (state !== 'removed' && node.removed()) {
return false;
}
return fn(node);
});
}
|
javascript
|
function baseStatePredicate(state, full) {
if (full) {
return this.extract(state);
}
// Cache a state predicate function
const fn = getPredicateFunction(state);
return this.flatten(node => {
// Never include removed nodes unless specifically requested
if (state !== 'removed' && node.removed()) {
return false;
}
return fn(node);
});
}
|
[
"function",
"baseStatePredicate",
"(",
"state",
",",
"full",
")",
"{",
"if",
"(",
"full",
")",
"{",
"return",
"this",
".",
"extract",
"(",
"state",
")",
";",
"}",
"// Cache a state predicate function",
"const",
"fn",
"=",
"getPredicateFunction",
"(",
"state",
")",
";",
"return",
"this",
".",
"flatten",
"(",
"node",
"=>",
"{",
"// Never include removed nodes unless specifically requested",
"if",
"(",
"state",
"!==",
"'removed'",
"&&",
"node",
".",
"removed",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"fn",
"(",
"node",
")",
";",
"}",
")",
";",
"}"
] |
Base function to filter nodes by state value.
@private
@param {string} state State property
@param {boolean} full Return a non-flat hierarchy
@return {TreeNodes} Array of matching nodes.
|
[
"Base",
"function",
"to",
"filter",
"nodes",
"by",
"state",
"value",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/treenodes.js#L59-L75
|
18,218
|
helion3/inspire-tree
|
src/treenode.js
|
cloneItree
|
function cloneItree(itree, excludeKeys) {
const clone = {};
excludeKeys = _.castArray(excludeKeys);
excludeKeys.push('ref');
_.each(itree, (v, k) => {
if (!_.includes(excludeKeys, k)) {
clone[k] = _.cloneDeep(v);
}
});
return clone;
}
|
javascript
|
function cloneItree(itree, excludeKeys) {
const clone = {};
excludeKeys = _.castArray(excludeKeys);
excludeKeys.push('ref');
_.each(itree, (v, k) => {
if (!_.includes(excludeKeys, k)) {
clone[k] = _.cloneDeep(v);
}
});
return clone;
}
|
[
"function",
"cloneItree",
"(",
"itree",
",",
"excludeKeys",
")",
"{",
"const",
"clone",
"=",
"{",
"}",
";",
"excludeKeys",
"=",
"_",
".",
"castArray",
"(",
"excludeKeys",
")",
";",
"excludeKeys",
".",
"push",
"(",
"'ref'",
")",
";",
"_",
".",
"each",
"(",
"itree",
",",
"(",
"v",
",",
"k",
")",
"=>",
"{",
"if",
"(",
"!",
"_",
".",
"includes",
"(",
"excludeKeys",
",",
"k",
")",
")",
"{",
"clone",
"[",
"k",
"]",
"=",
"_",
".",
"cloneDeep",
"(",
"v",
")",
";",
"}",
"}",
")",
";",
"return",
"clone",
";",
"}"
] |
Helper method to clone an ITree config object.
Rejects non-clonable properties like ref.
@private
@param {object} itree ITree configuration object
@param {array} excludeKeys Keys to exclude, if any
@return {object} Cloned ITree.
|
[
"Helper",
"method",
"to",
"clone",
"an",
"ITree",
"config",
"object",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/treenode.js#L20-L32
|
18,219
|
helion3/inspire-tree
|
src/treenode.js
|
baseState
|
function baseState(node, property, val) {
const currentVal = node.itree.state[property];
if (typeof val !== 'undefined' && currentVal !== val) {
// Update values
node.itree.state[property] = val;
if (property !== 'rendered') {
node.markDirty();
}
// Emit an event
node._tree.emit('node.state.changed', node, property, currentVal, val);
}
return currentVal;
}
|
javascript
|
function baseState(node, property, val) {
const currentVal = node.itree.state[property];
if (typeof val !== 'undefined' && currentVal !== val) {
// Update values
node.itree.state[property] = val;
if (property !== 'rendered') {
node.markDirty();
}
// Emit an event
node._tree.emit('node.state.changed', node, property, currentVal, val);
}
return currentVal;
}
|
[
"function",
"baseState",
"(",
"node",
",",
"property",
",",
"val",
")",
"{",
"const",
"currentVal",
"=",
"node",
".",
"itree",
".",
"state",
"[",
"property",
"]",
";",
"if",
"(",
"typeof",
"val",
"!==",
"'undefined'",
"&&",
"currentVal",
"!==",
"val",
")",
"{",
"// Update values",
"node",
".",
"itree",
".",
"state",
"[",
"property",
"]",
"=",
"val",
";",
"if",
"(",
"property",
"!==",
"'rendered'",
")",
"{",
"node",
".",
"markDirty",
"(",
")",
";",
"}",
"// Emit an event",
"node",
".",
"_tree",
".",
"emit",
"(",
"'node.state.changed'",
",",
"node",
",",
"property",
",",
"currentVal",
",",
"val",
")",
";",
"}",
"return",
"currentVal",
";",
"}"
] |
Get or set a state value.
This is a base method and will not invoke related changes, for example
setting selected=false will not trigger any deselection logic.
@private
@param {TreeNode} node Tree node.
@param {string} property Property name.
@param {boolean} val New value, if setting.
@return {boolean} Current value on read, old value on set.
|
[
"Get",
"or",
"set",
"a",
"state",
"value",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/treenode.js#L46-L62
|
18,220
|
helion3/inspire-tree
|
src/lib/base-state-change.js
|
resetState
|
function resetState(node) {
_.each(node._tree.defaultState, (val, prop) => {
node.state(prop, val);
});
return node;
}
|
javascript
|
function resetState(node) {
_.each(node._tree.defaultState, (val, prop) => {
node.state(prop, val);
});
return node;
}
|
[
"function",
"resetState",
"(",
"node",
")",
"{",
"_",
".",
"each",
"(",
"node",
".",
"_tree",
".",
"defaultState",
",",
"(",
"val",
",",
"prop",
")",
"=>",
"{",
"node",
".",
"state",
"(",
"prop",
",",
"val",
")",
";",
"}",
")",
";",
"return",
"node",
";",
"}"
] |
Reset a node's state to the tree default.
@private
@param {TreeNode} node Node object.
@returns {TreeNode} Node object.
|
[
"Reset",
"a",
"node",
"s",
"state",
"to",
"the",
"tree",
"default",
"."
] |
f2c62437e3fe9c89544064e18191cd62673e38c2
|
https://github.com/helion3/inspire-tree/blob/f2c62437e3fe9c89544064e18191cd62673e38c2/src/lib/base-state-change.js#L10-L16
|
18,221
|
uphold/github-changelog-generator
|
src/index.js
|
run
|
async function run() {
const fetcher = new ChangelogFetcher({ base, futureRelease, futureReleaseTag, labels, owner, repo, token });
const releases = await fetcher.fetchChangelog();
formatChangelog(releases).forEach(line => process.stdout.write(line));
}
|
javascript
|
async function run() {
const fetcher = new ChangelogFetcher({ base, futureRelease, futureReleaseTag, labels, owner, repo, token });
const releases = await fetcher.fetchChangelog();
formatChangelog(releases).forEach(line => process.stdout.write(line));
}
|
[
"async",
"function",
"run",
"(",
")",
"{",
"const",
"fetcher",
"=",
"new",
"ChangelogFetcher",
"(",
"{",
"base",
",",
"futureRelease",
",",
"futureReleaseTag",
",",
"labels",
",",
"owner",
",",
"repo",
",",
"token",
"}",
")",
";",
"const",
"releases",
"=",
"await",
"fetcher",
".",
"fetchChangelog",
"(",
")",
";",
"formatChangelog",
"(",
"releases",
")",
".",
"forEach",
"(",
"line",
"=>",
"process",
".",
"stdout",
".",
"write",
"(",
"line",
")",
")",
";",
"}"
] |
Run the changelog generator.
|
[
"Run",
"the",
"changelog",
"generator",
"."
] |
788c260ded8f121c7f255b101b352c9d065866ec
|
https://github.com/uphold/github-changelog-generator/blob/788c260ded8f121c7f255b101b352c9d065866ec/src/index.js#L64-L69
|
18,222
|
gjunge/rateit.js
|
scripts/jquery.rateit.js
|
function (element, event) {
var pageX = (event.changedTouches) ? event.changedTouches[0].pageX : event.pageX;
var offsetx = pageX - $(element).offset().left;
if (!ltr) { offsetx = range.width() - offsetx };
if (offsetx > range.width()) { offsetx = range.width(); }
if (offsetx < 0) { offsetx = 0; }
return score = Math.ceil(offsetx / itemdata('starwidth') * (1 / itemdata('step')));
}
|
javascript
|
function (element, event) {
var pageX = (event.changedTouches) ? event.changedTouches[0].pageX : event.pageX;
var offsetx = pageX - $(element).offset().left;
if (!ltr) { offsetx = range.width() - offsetx };
if (offsetx > range.width()) { offsetx = range.width(); }
if (offsetx < 0) { offsetx = 0; }
return score = Math.ceil(offsetx / itemdata('starwidth') * (1 / itemdata('step')));
}
|
[
"function",
"(",
"element",
",",
"event",
")",
"{",
"var",
"pageX",
"=",
"(",
"event",
".",
"changedTouches",
")",
"?",
"event",
".",
"changedTouches",
"[",
"0",
"]",
".",
"pageX",
":",
"event",
".",
"pageX",
";",
"var",
"offsetx",
"=",
"pageX",
"-",
"$",
"(",
"element",
")",
".",
"offset",
"(",
")",
".",
"left",
";",
"if",
"(",
"!",
"ltr",
")",
"{",
"offsetx",
"=",
"range",
".",
"width",
"(",
")",
"-",
"offsetx",
"}",
";",
"if",
"(",
"offsetx",
">",
"range",
".",
"width",
"(",
")",
")",
"{",
"offsetx",
"=",
"range",
".",
"width",
"(",
")",
";",
"}",
"if",
"(",
"offsetx",
"<",
"0",
")",
"{",
"offsetx",
"=",
"0",
";",
"}",
"return",
"score",
"=",
"Math",
".",
"ceil",
"(",
"offsetx",
"/",
"itemdata",
"(",
"'starwidth'",
")",
"*",
"(",
"1",
"/",
"itemdata",
"(",
"'step'",
")",
")",
")",
";",
"}"
] |
this function calculates the score based on the current position of the mouse.
|
[
"this",
"function",
"calculates",
"the",
"score",
"based",
"on",
"the",
"current",
"position",
"of",
"the",
"mouse",
"."
] |
4310c1d307949f3c487ea143e8f6660358765777
|
https://github.com/gjunge/rateit.js/blob/4310c1d307949f3c487ea143e8f6660358765777/scripts/jquery.rateit.js#L282-L291
|
|
18,223
|
gjunge/rateit.js
|
scripts/jquery.rateit.js
|
function (score) {
var w = score * itemdata('starwidth') * itemdata('step');
var h = range.find('.rateit-hover');
if (h.data('width') != w) {
range.find('.rateit-selected').hide();
h.width(w).show().data('width', w);
var data = [(score * itemdata('step')) + itemdata('min')];
item.trigger('hover', data).trigger('over', data);
}
}
|
javascript
|
function (score) {
var w = score * itemdata('starwidth') * itemdata('step');
var h = range.find('.rateit-hover');
if (h.data('width') != w) {
range.find('.rateit-selected').hide();
h.width(w).show().data('width', w);
var data = [(score * itemdata('step')) + itemdata('min')];
item.trigger('hover', data).trigger('over', data);
}
}
|
[
"function",
"(",
"score",
")",
"{",
"var",
"w",
"=",
"score",
"*",
"itemdata",
"(",
"'starwidth'",
")",
"*",
"itemdata",
"(",
"'step'",
")",
";",
"var",
"h",
"=",
"range",
".",
"find",
"(",
"'.rateit-hover'",
")",
";",
"if",
"(",
"h",
".",
"data",
"(",
"'width'",
")",
"!=",
"w",
")",
"{",
"range",
".",
"find",
"(",
"'.rateit-selected'",
")",
".",
"hide",
"(",
")",
";",
"h",
".",
"width",
"(",
"w",
")",
".",
"show",
"(",
")",
".",
"data",
"(",
"'width'",
",",
"w",
")",
";",
"var",
"data",
"=",
"[",
"(",
"score",
"*",
"itemdata",
"(",
"'step'",
")",
")",
"+",
"itemdata",
"(",
"'min'",
")",
"]",
";",
"item",
".",
"trigger",
"(",
"'hover'",
",",
"data",
")",
".",
"trigger",
"(",
"'over'",
",",
"data",
")",
";",
"}",
"}"
] |
sets the hover element based on the score.
|
[
"sets",
"the",
"hover",
"element",
"based",
"on",
"the",
"score",
"."
] |
4310c1d307949f3c487ea143e8f6660358765777
|
https://github.com/gjunge/rateit.js/blob/4310c1d307949f3c487ea143e8f6660358765777/scripts/jquery.rateit.js#L294-L303
|
|
18,224
|
cytoscape/cytoscape.js-popper
|
src/collection.js
|
getRenderedCenter
|
function getRenderedCenter(target, renderedDimensions){
let pos = target.renderedPosition();
let dimensions = renderedDimensions(target);
let offsetX = dimensions.w / 2;
let offsetY = dimensions.h / 2;
return {
x : (pos.x - offsetX),
y : (pos.y - offsetY)
};
}
|
javascript
|
function getRenderedCenter(target, renderedDimensions){
let pos = target.renderedPosition();
let dimensions = renderedDimensions(target);
let offsetX = dimensions.w / 2;
let offsetY = dimensions.h / 2;
return {
x : (pos.x - offsetX),
y : (pos.y - offsetY)
};
}
|
[
"function",
"getRenderedCenter",
"(",
"target",
",",
"renderedDimensions",
")",
"{",
"let",
"pos",
"=",
"target",
".",
"renderedPosition",
"(",
")",
";",
"let",
"dimensions",
"=",
"renderedDimensions",
"(",
"target",
")",
";",
"let",
"offsetX",
"=",
"dimensions",
".",
"w",
"/",
"2",
";",
"let",
"offsetY",
"=",
"dimensions",
".",
"h",
"/",
"2",
";",
"return",
"{",
"x",
":",
"(",
"pos",
".",
"x",
"-",
"offsetX",
")",
",",
"y",
":",
"(",
"pos",
".",
"y",
"-",
"offsetY",
")",
"}",
";",
"}"
] |
Get the rendered center
|
[
"Get",
"the",
"rendered",
"center"
] |
0372af85ef1c02dedc9bb29278391f7566844404
|
https://github.com/cytoscape/cytoscape.js-popper/blob/0372af85ef1c02dedc9bb29278391f7566844404/src/collection.js#L29-L39
|
18,225
|
cytoscape/cytoscape.js-popper
|
src/collection.js
|
getRenderedMidpoint
|
function getRenderedMidpoint(target){
let p = target.midpoint();
let pan = target.cy().pan();
let zoom = target.cy().zoom();
return {
x: p.x * zoom + pan.x,
y: p.y * zoom + pan.y
};
}
|
javascript
|
function getRenderedMidpoint(target){
let p = target.midpoint();
let pan = target.cy().pan();
let zoom = target.cy().zoom();
return {
x: p.x * zoom + pan.x,
y: p.y * zoom + pan.y
};
}
|
[
"function",
"getRenderedMidpoint",
"(",
"target",
")",
"{",
"let",
"p",
"=",
"target",
".",
"midpoint",
"(",
")",
";",
"let",
"pan",
"=",
"target",
".",
"cy",
"(",
")",
".",
"pan",
"(",
")",
";",
"let",
"zoom",
"=",
"target",
".",
"cy",
"(",
")",
".",
"zoom",
"(",
")",
";",
"return",
"{",
"x",
":",
"p",
".",
"x",
"*",
"zoom",
"+",
"pan",
".",
"x",
",",
"y",
":",
"p",
".",
"y",
"*",
"zoom",
"+",
"pan",
".",
"y",
"}",
";",
"}"
] |
Get the rendered position of the midpoint
|
[
"Get",
"the",
"rendered",
"position",
"of",
"the",
"midpoint"
] |
0372af85ef1c02dedc9bb29278391f7566844404
|
https://github.com/cytoscape/cytoscape.js-popper/blob/0372af85ef1c02dedc9bb29278391f7566844404/src/collection.js#L42-L51
|
18,226
|
cytoscape/cytoscape.js-popper
|
src/popper.js
|
getPopper
|
function getPopper(target, opts) {
let refObject = getRef(target, opts);
let content = getContent(target, opts.content);
let popperOpts = assign({}, popperDefaults, opts.popper);
return new Popper(refObject, content, popperOpts);
}
|
javascript
|
function getPopper(target, opts) {
let refObject = getRef(target, opts);
let content = getContent(target, opts.content);
let popperOpts = assign({}, popperDefaults, opts.popper);
return new Popper(refObject, content, popperOpts);
}
|
[
"function",
"getPopper",
"(",
"target",
",",
"opts",
")",
"{",
"let",
"refObject",
"=",
"getRef",
"(",
"target",
",",
"opts",
")",
";",
"let",
"content",
"=",
"getContent",
"(",
"target",
",",
"opts",
".",
"content",
")",
";",
"let",
"popperOpts",
"=",
"assign",
"(",
"{",
"}",
",",
"popperDefaults",
",",
"opts",
".",
"popper",
")",
";",
"return",
"new",
"Popper",
"(",
"refObject",
",",
"content",
",",
"popperOpts",
")",
";",
"}"
] |
Create a new popper object for a core or element target
|
[
"Create",
"a",
"new",
"popper",
"object",
"for",
"a",
"core",
"or",
"element",
"target"
] |
0372af85ef1c02dedc9bb29278391f7566844404
|
https://github.com/cytoscape/cytoscape.js-popper/blob/0372af85ef1c02dedc9bb29278391f7566844404/src/popper.js#L15-L21
|
18,227
|
cytoscape/cytoscape.js-popper
|
src/core.js
|
createOptionsObject
|
function createOptionsObject(target, opts) {
let defaults = {
boundingBox : {
top: 0,
left: 0,
right: 0,
bottom: 0,
w: 3,
h: 3,
},
renderedDimensions : () => ({w: 3, h: 3}),
redneredPosition : () => ({x : 0, y : 0}),
popper : {},
cy : target
};
return assign( {}, defaults, opts );
}
|
javascript
|
function createOptionsObject(target, opts) {
let defaults = {
boundingBox : {
top: 0,
left: 0,
right: 0,
bottom: 0,
w: 3,
h: 3,
},
renderedDimensions : () => ({w: 3, h: 3}),
redneredPosition : () => ({x : 0, y : 0}),
popper : {},
cy : target
};
return assign( {}, defaults, opts );
}
|
[
"function",
"createOptionsObject",
"(",
"target",
",",
"opts",
")",
"{",
"let",
"defaults",
"=",
"{",
"boundingBox",
":",
"{",
"top",
":",
"0",
",",
"left",
":",
"0",
",",
"right",
":",
"0",
",",
"bottom",
":",
"0",
",",
"w",
":",
"3",
",",
"h",
":",
"3",
",",
"}",
",",
"renderedDimensions",
":",
"(",
")",
"=>",
"(",
"{",
"w",
":",
"3",
",",
"h",
":",
"3",
"}",
")",
",",
"redneredPosition",
":",
"(",
")",
"=>",
"(",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
")",
",",
"popper",
":",
"{",
"}",
",",
"cy",
":",
"target",
"}",
";",
"return",
"assign",
"(",
"{",
"}",
",",
"defaults",
",",
"opts",
")",
";",
"}"
] |
Create a options object with required default values
|
[
"Create",
"a",
"options",
"object",
"with",
"required",
"default",
"values"
] |
0372af85ef1c02dedc9bb29278391f7566844404
|
https://github.com/cytoscape/cytoscape.js-popper/blob/0372af85ef1c02dedc9bb29278391f7566844404/src/core.js#L15-L32
|
18,228
|
felixrieseberg/electron-windows-store
|
lib/utils.js
|
ensureWindows
|
function ensureWindows () {
if (process.platform !== 'win32') {
log('This tool requires Windows 10.\n')
log('You can run a virtual machine using the free VirtualBox and')
log('the free Windows Virtual Machines found at http://modern.ie.\n')
log('For more information, please see the readme.')
process.exit(1)
}
let release = require('os').release()
let major = parseInt(release.slice(0, 2), 10)
let minor = parseInt(release.slice(3, 4), 10)
let build = parseInt(release.slice(5), 10)
if (major < 10 || (minor === 0 && build < 14316)) {
log(`You are running Windows ${release}. You need at least Windows 10.0.14316.`)
log('We can\'t confirm that you\'re running the right version, but we won\'t stop')
log('this process - should things fail though, you might have to update your')
log('Windows.')
}
}
|
javascript
|
function ensureWindows () {
if (process.platform !== 'win32') {
log('This tool requires Windows 10.\n')
log('You can run a virtual machine using the free VirtualBox and')
log('the free Windows Virtual Machines found at http://modern.ie.\n')
log('For more information, please see the readme.')
process.exit(1)
}
let release = require('os').release()
let major = parseInt(release.slice(0, 2), 10)
let minor = parseInt(release.slice(3, 4), 10)
let build = parseInt(release.slice(5), 10)
if (major < 10 || (minor === 0 && build < 14316)) {
log(`You are running Windows ${release}. You need at least Windows 10.0.14316.`)
log('We can\'t confirm that you\'re running the right version, but we won\'t stop')
log('this process - should things fail though, you might have to update your')
log('Windows.')
}
}
|
[
"function",
"ensureWindows",
"(",
")",
"{",
"if",
"(",
"process",
".",
"platform",
"!==",
"'win32'",
")",
"{",
"log",
"(",
"'This tool requires Windows 10.\\n'",
")",
"log",
"(",
"'You can run a virtual machine using the free VirtualBox and'",
")",
"log",
"(",
"'the free Windows Virtual Machines found at http://modern.ie.\\n'",
")",
"log",
"(",
"'For more information, please see the readme.'",
")",
"process",
".",
"exit",
"(",
"1",
")",
"}",
"let",
"release",
"=",
"require",
"(",
"'os'",
")",
".",
"release",
"(",
")",
"let",
"major",
"=",
"parseInt",
"(",
"release",
".",
"slice",
"(",
"0",
",",
"2",
")",
",",
"10",
")",
"let",
"minor",
"=",
"parseInt",
"(",
"release",
".",
"slice",
"(",
"3",
",",
"4",
")",
",",
"10",
")",
"let",
"build",
"=",
"parseInt",
"(",
"release",
".",
"slice",
"(",
"5",
")",
",",
"10",
")",
"if",
"(",
"major",
"<",
"10",
"||",
"(",
"minor",
"===",
"0",
"&&",
"build",
"<",
"14316",
")",
")",
"{",
"log",
"(",
"`",
"${",
"release",
"}",
"`",
")",
"log",
"(",
"'We can\\'t confirm that you\\'re running the right version, but we won\\'t stop'",
")",
"log",
"(",
"'this process - should things fail though, you might have to update your'",
")",
"log",
"(",
"'Windows.'",
")",
"}",
"}"
] |
Ensures that the currently running platform is Windows,
exiting the process if it is not
|
[
"Ensures",
"that",
"the",
"currently",
"running",
"platform",
"is",
"Windows",
"exiting",
"the",
"process",
"if",
"it",
"is",
"not"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/utils.js#L9-L29
|
18,229
|
felixrieseberg/electron-windows-store
|
lib/utils.js
|
hasVariableResources
|
function hasVariableResources (assetsDirectory) {
const files = require('fs-extra').readdirSync(assetsDirectory)
const hasScale = files.find(file => /\.scale-...\./g.test(file))
return (!!hasScale)
}
|
javascript
|
function hasVariableResources (assetsDirectory) {
const files = require('fs-extra').readdirSync(assetsDirectory)
const hasScale = files.find(file => /\.scale-...\./g.test(file))
return (!!hasScale)
}
|
[
"function",
"hasVariableResources",
"(",
"assetsDirectory",
")",
"{",
"const",
"files",
"=",
"require",
"(",
"'fs-extra'",
")",
".",
"readdirSync",
"(",
"assetsDirectory",
")",
"const",
"hasScale",
"=",
"files",
".",
"find",
"(",
"file",
"=>",
"/",
"\\.scale-...\\.",
"/",
"g",
".",
"test",
"(",
"file",
")",
")",
"return",
"(",
"!",
"!",
"hasScale",
")",
"}"
] |
Makes an educated guess whether or not resources have
multiple variations or resource versions for
language, scale, contrast, etc
@param assetsDirectory - Path to a the assets directory
@returns {boolean} - Are the assets variable?
|
[
"Makes",
"an",
"educated",
"guess",
"whether",
"or",
"not",
"resources",
"have",
"multiple",
"variations",
"or",
"resource",
"versions",
"for",
"language",
"scale",
"contrast",
"etc"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/utils.js#L39-L44
|
18,230
|
felixrieseberg/electron-windows-store
|
lib/utils.js
|
executeChildProcess
|
function executeChildProcess (fileName, args, options) {
return new Promise((resolve, reject) => {
const child = require('child_process').spawn(fileName, args, options)
child.stdout.on('data', (data) => log(data.toString()))
child.stderr.on('data', (data) => log(data.toString()))
child.on('exit', (code) => {
if (code !== 0) {
return reject(new Error(fileName + ' exited with code: ' + code))
}
return resolve()
})
child.stdin.end()
})
}
|
javascript
|
function executeChildProcess (fileName, args, options) {
return new Promise((resolve, reject) => {
const child = require('child_process').spawn(fileName, args, options)
child.stdout.on('data', (data) => log(data.toString()))
child.stderr.on('data', (data) => log(data.toString()))
child.on('exit', (code) => {
if (code !== 0) {
return reject(new Error(fileName + ' exited with code: ' + code))
}
return resolve()
})
child.stdin.end()
})
}
|
[
"function",
"executeChildProcess",
"(",
"fileName",
",",
"args",
",",
"options",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"child",
"=",
"require",
"(",
"'child_process'",
")",
".",
"spawn",
"(",
"fileName",
",",
"args",
",",
"options",
")",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"log",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"log",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
"code",
")",
"=>",
"{",
"if",
"(",
"code",
"!==",
"0",
")",
"{",
"return",
"reject",
"(",
"new",
"Error",
"(",
"fileName",
"+",
"' exited with code: '",
"+",
"code",
")",
")",
"}",
"return",
"resolve",
"(",
")",
"}",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Starts a child process using the provided executable
@param fileName - Path to the executable to start
@param args - Arguments for spawn
@param options - Options passed to spawn
@returns {Promise} - A promise that resolves when the
process exits
|
[
"Starts",
"a",
"child",
"process",
"using",
"the",
"provided",
"executable"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/utils.js#L65-L81
|
18,231
|
felixrieseberg/electron-windows-store
|
lib/setup.js
|
isSetupRequired
|
function isSetupRequired (program) {
const config = dotfile.get() || {}
const hasPublisher = (config.publisher || program.publisher)
const hasDevCert = (config.devCert || program.devCert)
const hasWindowsKit = (config.windowsKit || program.windowsKit)
const hasBaseImage = (config.expandedBaseImage || program.expandedBaseImage)
const hasConverterTools = (config.desktopConverter || program.desktopConverter)
if (!program.containerVirtualization) {
return (hasPublisher && hasDevCert && hasWindowsKit)
} else {
return (hasPublisher && hasDevCert && hasWindowsKit && hasBaseImage && hasConverterTools)
}
}
|
javascript
|
function isSetupRequired (program) {
const config = dotfile.get() || {}
const hasPublisher = (config.publisher || program.publisher)
const hasDevCert = (config.devCert || program.devCert)
const hasWindowsKit = (config.windowsKit || program.windowsKit)
const hasBaseImage = (config.expandedBaseImage || program.expandedBaseImage)
const hasConverterTools = (config.desktopConverter || program.desktopConverter)
if (!program.containerVirtualization) {
return (hasPublisher && hasDevCert && hasWindowsKit)
} else {
return (hasPublisher && hasDevCert && hasWindowsKit && hasBaseImage && hasConverterTools)
}
}
|
[
"function",
"isSetupRequired",
"(",
"program",
")",
"{",
"const",
"config",
"=",
"dotfile",
".",
"get",
"(",
")",
"||",
"{",
"}",
"const",
"hasPublisher",
"=",
"(",
"config",
".",
"publisher",
"||",
"program",
".",
"publisher",
")",
"const",
"hasDevCert",
"=",
"(",
"config",
".",
"devCert",
"||",
"program",
".",
"devCert",
")",
"const",
"hasWindowsKit",
"=",
"(",
"config",
".",
"windowsKit",
"||",
"program",
".",
"windowsKit",
")",
"const",
"hasBaseImage",
"=",
"(",
"config",
".",
"expandedBaseImage",
"||",
"program",
".",
"expandedBaseImage",
")",
"const",
"hasConverterTools",
"=",
"(",
"config",
".",
"desktopConverter",
"||",
"program",
".",
"desktopConverter",
")",
"if",
"(",
"!",
"program",
".",
"containerVirtualization",
")",
"{",
"return",
"(",
"hasPublisher",
"&&",
"hasDevCert",
"&&",
"hasWindowsKit",
")",
"}",
"else",
"{",
"return",
"(",
"hasPublisher",
"&&",
"hasDevCert",
"&&",
"hasWindowsKit",
"&&",
"hasBaseImage",
"&&",
"hasConverterTools",
")",
"}",
"}"
] |
Determines whether all setup settings are okay.
@returns {boolean} - Whether everything is setup correctly.
|
[
"Determines",
"whether",
"all",
"setup",
"settings",
"are",
"okay",
"."
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/setup.js#L27-L40
|
18,232
|
felixrieseberg/electron-windows-store
|
lib/setup.js
|
wizardSetup
|
function wizardSetup (program) {
const welcome = multiline.stripIndent(function () { /*
Welcome to the Electron-Windows-Store tool!
This tool will assist you with turning your Electron app into
a swanky Windows Store app.
We need to know some settings. We will ask you only once and store
your answers in your profile folder in a .electron-windows-store
file.
*/
})
const complete = multiline.stripIndent(function () { /*
Setup complete, moving on to package your app!
*/
})
let questions = [
{
name: 'desktopConverter',
type: 'input',
message: 'Please enter the path to your Desktop App Converter (DesktopAppConverter.ps1): ',
validate: (input) => pathExists.sync(input),
when: () => (!program.desktopConverter)
},
{
name: 'expandedBaseImage',
type: 'input',
message: 'Please enter the path to your Expanded Base Image: ',
default: 'C:\\ProgramData\\Microsoft\\Windows\\Images\\BaseImage-14316\\',
validate: (input) => pathExists.sync(input),
when: () => (!program.expandedBaseImage)
},
{
name: 'devCert',
type: 'input',
message: 'Please enter the path to your development PFX certficate: ',
default: null,
when: () => (!dotfile.get().makeCertificate || !program.devCert)
},
{
name: 'publisher',
type: 'input',
message: 'Please enter your publisher identity: ',
default: 'CN=developmentca',
when: () => (!program.publisher)
},
{
name: 'windowsKit',
type: 'input',
message: "Please enter the location of your Windows Kit's bin folder: ",
default: utils.getDefaultWindowsKitLocation(),
when: () => (!program.windowsKit)
}
]
if (!program.isModuleUse) {
utils.log(welcome)
}
// Remove the Desktop Converter Questions if not installed
if (program.didInstallDesktopAppConverter === false) {
questions = questions.slice(3)
}
if (program.isModuleUse) {
program.windowsKit = program.windowsKit || utils.getDefaultWindowsKitLocation()
return Promise.resolve(program)
}
return inquirer.prompt(questions)
.then((answers) => {
dotfile.set({
desktopConverter: answers.desktopConverter || false,
expandedBaseImage: answers.expandedBaseImage || false,
devCert: answers.devCert,
publisher: answers.publisher,
windowsKit: answers.windowsKit,
makeCertificate: dotfile.get().makeCertificate
})
program.desktopConverter = answers.desktopConverter
program.expandedBaseImage = answers.expandedBaseImage
program.devCert = answers.devCert
program.publisher = answers.publisher
program.windowsKit = answers.windowsKit
if (program.makeCertificate) {
utils.log(chalk.bold.green('Creating Certficate'))
let publisher = dotfile.get().publisher.split('=')[1]
let certFolder = path.join(process.env.APPDATA, 'electron-windows-store', publisher)
return sign.makeCert({ publisherName: publisher, certFilePath: certFolder, program: program })
.then(pfxFile => {
utils.log('Created and installed certificate:')
utils.log(pfxFile)
dotfile.set({ devCert: pfxFile })
})
}
utils.log(complete)
})
}
|
javascript
|
function wizardSetup (program) {
const welcome = multiline.stripIndent(function () { /*
Welcome to the Electron-Windows-Store tool!
This tool will assist you with turning your Electron app into
a swanky Windows Store app.
We need to know some settings. We will ask you only once and store
your answers in your profile folder in a .electron-windows-store
file.
*/
})
const complete = multiline.stripIndent(function () { /*
Setup complete, moving on to package your app!
*/
})
let questions = [
{
name: 'desktopConverter',
type: 'input',
message: 'Please enter the path to your Desktop App Converter (DesktopAppConverter.ps1): ',
validate: (input) => pathExists.sync(input),
when: () => (!program.desktopConverter)
},
{
name: 'expandedBaseImage',
type: 'input',
message: 'Please enter the path to your Expanded Base Image: ',
default: 'C:\\ProgramData\\Microsoft\\Windows\\Images\\BaseImage-14316\\',
validate: (input) => pathExists.sync(input),
when: () => (!program.expandedBaseImage)
},
{
name: 'devCert',
type: 'input',
message: 'Please enter the path to your development PFX certficate: ',
default: null,
when: () => (!dotfile.get().makeCertificate || !program.devCert)
},
{
name: 'publisher',
type: 'input',
message: 'Please enter your publisher identity: ',
default: 'CN=developmentca',
when: () => (!program.publisher)
},
{
name: 'windowsKit',
type: 'input',
message: "Please enter the location of your Windows Kit's bin folder: ",
default: utils.getDefaultWindowsKitLocation(),
when: () => (!program.windowsKit)
}
]
if (!program.isModuleUse) {
utils.log(welcome)
}
// Remove the Desktop Converter Questions if not installed
if (program.didInstallDesktopAppConverter === false) {
questions = questions.slice(3)
}
if (program.isModuleUse) {
program.windowsKit = program.windowsKit || utils.getDefaultWindowsKitLocation()
return Promise.resolve(program)
}
return inquirer.prompt(questions)
.then((answers) => {
dotfile.set({
desktopConverter: answers.desktopConverter || false,
expandedBaseImage: answers.expandedBaseImage || false,
devCert: answers.devCert,
publisher: answers.publisher,
windowsKit: answers.windowsKit,
makeCertificate: dotfile.get().makeCertificate
})
program.desktopConverter = answers.desktopConverter
program.expandedBaseImage = answers.expandedBaseImage
program.devCert = answers.devCert
program.publisher = answers.publisher
program.windowsKit = answers.windowsKit
if (program.makeCertificate) {
utils.log(chalk.bold.green('Creating Certficate'))
let publisher = dotfile.get().publisher.split('=')[1]
let certFolder = path.join(process.env.APPDATA, 'electron-windows-store', publisher)
return sign.makeCert({ publisherName: publisher, certFilePath: certFolder, program: program })
.then(pfxFile => {
utils.log('Created and installed certificate:')
utils.log(pfxFile)
dotfile.set({ devCert: pfxFile })
})
}
utils.log(complete)
})
}
|
[
"function",
"wizardSetup",
"(",
"program",
")",
"{",
"const",
"welcome",
"=",
"multiline",
".",
"stripIndent",
"(",
"function",
"(",
")",
"{",
"/*\n Welcome to the Electron-Windows-Store tool!\n\n This tool will assist you with turning your Electron app into\n a swanky Windows Store app.\n\n We need to know some settings. We will ask you only once and store\n your answers in your profile folder in a .electron-windows-store\n file.\n\n */",
"}",
")",
"const",
"complete",
"=",
"multiline",
".",
"stripIndent",
"(",
"function",
"(",
")",
"{",
"/*\n\n Setup complete, moving on to package your app!\n\n */",
"}",
")",
"let",
"questions",
"=",
"[",
"{",
"name",
":",
"'desktopConverter'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"'Please enter the path to your Desktop App Converter (DesktopAppConverter.ps1): '",
",",
"validate",
":",
"(",
"input",
")",
"=>",
"pathExists",
".",
"sync",
"(",
"input",
")",
",",
"when",
":",
"(",
")",
"=>",
"(",
"!",
"program",
".",
"desktopConverter",
")",
"}",
",",
"{",
"name",
":",
"'expandedBaseImage'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"'Please enter the path to your Expanded Base Image: '",
",",
"default",
":",
"'C:\\\\ProgramData\\\\Microsoft\\\\Windows\\\\Images\\\\BaseImage-14316\\\\'",
",",
"validate",
":",
"(",
"input",
")",
"=>",
"pathExists",
".",
"sync",
"(",
"input",
")",
",",
"when",
":",
"(",
")",
"=>",
"(",
"!",
"program",
".",
"expandedBaseImage",
")",
"}",
",",
"{",
"name",
":",
"'devCert'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"'Please enter the path to your development PFX certficate: '",
",",
"default",
":",
"null",
",",
"when",
":",
"(",
")",
"=>",
"(",
"!",
"dotfile",
".",
"get",
"(",
")",
".",
"makeCertificate",
"||",
"!",
"program",
".",
"devCert",
")",
"}",
",",
"{",
"name",
":",
"'publisher'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"'Please enter your publisher identity: '",
",",
"default",
":",
"'CN=developmentca'",
",",
"when",
":",
"(",
")",
"=>",
"(",
"!",
"program",
".",
"publisher",
")",
"}",
",",
"{",
"name",
":",
"'windowsKit'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"\"Please enter the location of your Windows Kit's bin folder: \"",
",",
"default",
":",
"utils",
".",
"getDefaultWindowsKitLocation",
"(",
")",
",",
"when",
":",
"(",
")",
"=>",
"(",
"!",
"program",
".",
"windowsKit",
")",
"}",
"]",
"if",
"(",
"!",
"program",
".",
"isModuleUse",
")",
"{",
"utils",
".",
"log",
"(",
"welcome",
")",
"}",
"// Remove the Desktop Converter Questions if not installed",
"if",
"(",
"program",
".",
"didInstallDesktopAppConverter",
"===",
"false",
")",
"{",
"questions",
"=",
"questions",
".",
"slice",
"(",
"3",
")",
"}",
"if",
"(",
"program",
".",
"isModuleUse",
")",
"{",
"program",
".",
"windowsKit",
"=",
"program",
".",
"windowsKit",
"||",
"utils",
".",
"getDefaultWindowsKitLocation",
"(",
")",
"return",
"Promise",
".",
"resolve",
"(",
"program",
")",
"}",
"return",
"inquirer",
".",
"prompt",
"(",
"questions",
")",
".",
"then",
"(",
"(",
"answers",
")",
"=>",
"{",
"dotfile",
".",
"set",
"(",
"{",
"desktopConverter",
":",
"answers",
".",
"desktopConverter",
"||",
"false",
",",
"expandedBaseImage",
":",
"answers",
".",
"expandedBaseImage",
"||",
"false",
",",
"devCert",
":",
"answers",
".",
"devCert",
",",
"publisher",
":",
"answers",
".",
"publisher",
",",
"windowsKit",
":",
"answers",
".",
"windowsKit",
",",
"makeCertificate",
":",
"dotfile",
".",
"get",
"(",
")",
".",
"makeCertificate",
"}",
")",
"program",
".",
"desktopConverter",
"=",
"answers",
".",
"desktopConverter",
"program",
".",
"expandedBaseImage",
"=",
"answers",
".",
"expandedBaseImage",
"program",
".",
"devCert",
"=",
"answers",
".",
"devCert",
"program",
".",
"publisher",
"=",
"answers",
".",
"publisher",
"program",
".",
"windowsKit",
"=",
"answers",
".",
"windowsKit",
"if",
"(",
"program",
".",
"makeCertificate",
")",
"{",
"utils",
".",
"log",
"(",
"chalk",
".",
"bold",
".",
"green",
"(",
"'Creating Certficate'",
")",
")",
"let",
"publisher",
"=",
"dotfile",
".",
"get",
"(",
")",
".",
"publisher",
".",
"split",
"(",
"'='",
")",
"[",
"1",
"]",
"let",
"certFolder",
"=",
"path",
".",
"join",
"(",
"process",
".",
"env",
".",
"APPDATA",
",",
"'electron-windows-store'",
",",
"publisher",
")",
"return",
"sign",
".",
"makeCert",
"(",
"{",
"publisherName",
":",
"publisher",
",",
"certFilePath",
":",
"certFolder",
",",
"program",
":",
"program",
"}",
")",
".",
"then",
"(",
"pfxFile",
"=>",
"{",
"utils",
".",
"log",
"(",
"'Created and installed certificate:'",
")",
"utils",
".",
"log",
"(",
"pfxFile",
")",
"dotfile",
".",
"set",
"(",
"{",
"devCert",
":",
"pfxFile",
"}",
")",
"}",
")",
"}",
"utils",
".",
"log",
"(",
"complete",
")",
"}",
")",
"}"
] |
Runs a wizard, helping the user setup configuration
@param program - Commander program object
@returns {Promise} - Promsise that returns once wizard completed
|
[
"Runs",
"a",
"wizard",
"helping",
"the",
"user",
"setup",
"configuration"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/setup.js#L79-L185
|
18,233
|
felixrieseberg/electron-windows-store
|
lib/setup.js
|
logConfiguration
|
function logConfiguration (program) {
utils.log(chalk.bold.green.underline('\nConfiguration: '))
utils.log(`Desktop Converter Location: ${program.desktopConverter}`)
utils.log(`Expanded Base Image: ${program.expandedBaseImage}`)
utils.log(`Publisher: ${program.publisher}`)
utils.log(`Dev Certificate: ${program.devCert}`)
utils.log(`Windows Kit Location: ${program.windowsKit}
`)
}
|
javascript
|
function logConfiguration (program) {
utils.log(chalk.bold.green.underline('\nConfiguration: '))
utils.log(`Desktop Converter Location: ${program.desktopConverter}`)
utils.log(`Expanded Base Image: ${program.expandedBaseImage}`)
utils.log(`Publisher: ${program.publisher}`)
utils.log(`Dev Certificate: ${program.devCert}`)
utils.log(`Windows Kit Location: ${program.windowsKit}
`)
}
|
[
"function",
"logConfiguration",
"(",
"program",
")",
"{",
"utils",
".",
"log",
"(",
"chalk",
".",
"bold",
".",
"green",
".",
"underline",
"(",
"'\\nConfiguration: '",
")",
")",
"utils",
".",
"log",
"(",
"`",
"${",
"program",
".",
"desktopConverter",
"}",
"`",
")",
"utils",
".",
"log",
"(",
"`",
"${",
"program",
".",
"expandedBaseImage",
"}",
"`",
")",
"utils",
".",
"log",
"(",
"`",
"${",
"program",
".",
"publisher",
"}",
"`",
")",
"utils",
".",
"log",
"(",
"`",
"${",
"program",
".",
"devCert",
"}",
"`",
")",
"utils",
".",
"log",
"(",
"`",
"${",
"program",
".",
"windowsKit",
"}",
"`",
")",
"}"
] |
Logs the current configuration to utils
@param program - Commander program object
|
[
"Logs",
"the",
"current",
"configuration",
"to",
"utils"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/setup.js#L192-L200
|
18,234
|
felixrieseberg/electron-windows-store
|
lib/setup.js
|
setup
|
function setup (program) {
return new Promise((resolve, reject) => {
if (isSetupRequired(program)) {
// If we're setup, merge the dotfile configuration into the program
defaults(program, dotfile.get())
logConfiguration(program)
resolve()
} else {
// We're not setup, let's do that now
askForDependencies(program)
.then(() => wizardSetup(program))
.then(() => logConfiguration(program))
.then(() => resolve())
.catch((e) => reject(e))
}
})
}
|
javascript
|
function setup (program) {
return new Promise((resolve, reject) => {
if (isSetupRequired(program)) {
// If we're setup, merge the dotfile configuration into the program
defaults(program, dotfile.get())
logConfiguration(program)
resolve()
} else {
// We're not setup, let's do that now
askForDependencies(program)
.then(() => wizardSetup(program))
.then(() => logConfiguration(program))
.then(() => resolve())
.catch((e) => reject(e))
}
})
}
|
[
"function",
"setup",
"(",
"program",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"isSetupRequired",
"(",
"program",
")",
")",
"{",
"// If we're setup, merge the dotfile configuration into the program",
"defaults",
"(",
"program",
",",
"dotfile",
".",
"get",
"(",
")",
")",
"logConfiguration",
"(",
"program",
")",
"resolve",
"(",
")",
"}",
"else",
"{",
"// We're not setup, let's do that now",
"askForDependencies",
"(",
"program",
")",
".",
"then",
"(",
"(",
")",
"=>",
"wizardSetup",
"(",
"program",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"logConfiguration",
"(",
"program",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"resolve",
"(",
")",
")",
".",
"catch",
"(",
"(",
"e",
")",
"=>",
"reject",
"(",
"e",
")",
")",
"}",
"}",
")",
"}"
] |
Runs setup, checking if all configuration is existent,
and merging the dotfile with the program object
@param program - Commander program object
@returns {Promise} - Promsise that returns once setup completed
|
[
"Runs",
"setup",
"checking",
"if",
"all",
"configuration",
"is",
"existent",
"and",
"merging",
"the",
"dotfile",
"with",
"the",
"program",
"object"
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/setup.js#L209-L225
|
18,235
|
felixrieseberg/electron-windows-store
|
lib/convert.js
|
convertWithContainer
|
function convertWithContainer (program) {
return new Promise((resolve, reject) => {
if (!program.desktopConverter) {
utils.log('Could not find the Project Centennial Desktop App Converter, which is required to')
utils.log('run the conversion to appx using a Windows Container.\n')
utils.log('Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\n')
utils.log('You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\n')
utils.log('Exiting now - restart when you downloaded and unpacked the Desktop App Converter!')
process.exit(0)
}
let preAppx = path.join(program.outputDirectory, 'pre-appx')
let installer = path.join(program.outputDirectory, 'ElectronInstaller.exe')
let logfile = path.join(program.outputDirectory, 'logs', 'conversion.log')
let converterArgs = [
`-LogFile ${logfile}`,
`-Installer '${installer}'`,
`-Converter '${path.join(program.desktopConverter, 'DesktopAppConverter.ps1')}'`,
`-ExpandedBaseImage ${program.expandedBaseImage}`,
`-Destination '${preAppx}'`,
`-PackageName "${program.packageName}"`,
`-Version ${program.packageVersion}`,
`-Publisher "${program.publisher}"`,
`-AppExecutable '${program.packageExecutable}'`
]
let args = `& {& '${path.resolve(__dirname, '..', 'ps1', 'convert.ps1')}' ${converterArgs.join(' ')}}`
let child, tail
utils.log(chalk.green.bold('Starting Conversion...'))
utils.debug(`Conversion parameters used: ${JSON.stringify(converterArgs)}`)
try {
child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', args])
} catch (error) {
reject(error)
}
child.stdout.on('data', (data) => utils.debug(data.toString()))
child.stderr.on('data', (data) => utils.debug(data.toString()))
child.on('exit', () => {
// The conversion process exited, let's look for a log file
// However, give the PS process a 3s headstart, since we'll
// crash if the logfile does not exist yet
setTimeout(() => {
tail = new Tail(logfile, {
fromBeginning: true
})
tail.on('line', (data) => {
utils.log(data)
if (data.indexOf('Conversion complete') > -1) {
utils.log('')
tail.unwatch()
resolve()
} else if (data.indexOf('An error occurred') > -1) {
tail.unwatch()
reject(new Error('Detected error in conversion log'))
}
})
tail.on('error', (err) => utils.log(err))
}, 3000)
})
child.stdin.end()
})
}
|
javascript
|
function convertWithContainer (program) {
return new Promise((resolve, reject) => {
if (!program.desktopConverter) {
utils.log('Could not find the Project Centennial Desktop App Converter, which is required to')
utils.log('run the conversion to appx using a Windows Container.\n')
utils.log('Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\n')
utils.log('You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\n')
utils.log('Exiting now - restart when you downloaded and unpacked the Desktop App Converter!')
process.exit(0)
}
let preAppx = path.join(program.outputDirectory, 'pre-appx')
let installer = path.join(program.outputDirectory, 'ElectronInstaller.exe')
let logfile = path.join(program.outputDirectory, 'logs', 'conversion.log')
let converterArgs = [
`-LogFile ${logfile}`,
`-Installer '${installer}'`,
`-Converter '${path.join(program.desktopConverter, 'DesktopAppConverter.ps1')}'`,
`-ExpandedBaseImage ${program.expandedBaseImage}`,
`-Destination '${preAppx}'`,
`-PackageName "${program.packageName}"`,
`-Version ${program.packageVersion}`,
`-Publisher "${program.publisher}"`,
`-AppExecutable '${program.packageExecutable}'`
]
let args = `& {& '${path.resolve(__dirname, '..', 'ps1', 'convert.ps1')}' ${converterArgs.join(' ')}}`
let child, tail
utils.log(chalk.green.bold('Starting Conversion...'))
utils.debug(`Conversion parameters used: ${JSON.stringify(converterArgs)}`)
try {
child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', args])
} catch (error) {
reject(error)
}
child.stdout.on('data', (data) => utils.debug(data.toString()))
child.stderr.on('data', (data) => utils.debug(data.toString()))
child.on('exit', () => {
// The conversion process exited, let's look for a log file
// However, give the PS process a 3s headstart, since we'll
// crash if the logfile does not exist yet
setTimeout(() => {
tail = new Tail(logfile, {
fromBeginning: true
})
tail.on('line', (data) => {
utils.log(data)
if (data.indexOf('Conversion complete') > -1) {
utils.log('')
tail.unwatch()
resolve()
} else if (data.indexOf('An error occurred') > -1) {
tail.unwatch()
reject(new Error('Detected error in conversion log'))
}
})
tail.on('error', (err) => utils.log(err))
}, 3000)
})
child.stdin.end()
})
}
|
[
"function",
"convertWithContainer",
"(",
"program",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"!",
"program",
".",
"desktopConverter",
")",
"{",
"utils",
".",
"log",
"(",
"'Could not find the Project Centennial Desktop App Converter, which is required to'",
")",
"utils",
".",
"log",
"(",
"'run the conversion to appx using a Windows Container.\\n'",
")",
"utils",
".",
"log",
"(",
"'Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\\n'",
")",
"utils",
".",
"log",
"(",
"'You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\\n'",
")",
"utils",
".",
"log",
"(",
"'Exiting now - restart when you downloaded and unpacked the Desktop App Converter!'",
")",
"process",
".",
"exit",
"(",
"0",
")",
"}",
"let",
"preAppx",
"=",
"path",
".",
"join",
"(",
"program",
".",
"outputDirectory",
",",
"'pre-appx'",
")",
"let",
"installer",
"=",
"path",
".",
"join",
"(",
"program",
".",
"outputDirectory",
",",
"'ElectronInstaller.exe'",
")",
"let",
"logfile",
"=",
"path",
".",
"join",
"(",
"program",
".",
"outputDirectory",
",",
"'logs'",
",",
"'conversion.log'",
")",
"let",
"converterArgs",
"=",
"[",
"`",
"${",
"logfile",
"}",
"`",
",",
"`",
"${",
"installer",
"}",
"`",
",",
"`",
"${",
"path",
".",
"join",
"(",
"program",
".",
"desktopConverter",
",",
"'DesktopAppConverter.ps1'",
")",
"}",
"`",
",",
"`",
"${",
"program",
".",
"expandedBaseImage",
"}",
"`",
",",
"`",
"${",
"preAppx",
"}",
"`",
",",
"`",
"${",
"program",
".",
"packageName",
"}",
"`",
",",
"`",
"${",
"program",
".",
"packageVersion",
"}",
"`",
",",
"`",
"${",
"program",
".",
"publisher",
"}",
"`",
",",
"`",
"${",
"program",
".",
"packageExecutable",
"}",
"`",
"]",
"let",
"args",
"=",
"`",
"${",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'..'",
",",
"'ps1'",
",",
"'convert.ps1'",
")",
"}",
"${",
"converterArgs",
".",
"join",
"(",
"' '",
")",
"}",
"`",
"let",
"child",
",",
"tail",
"utils",
".",
"log",
"(",
"chalk",
".",
"green",
".",
"bold",
"(",
"'Starting Conversion...'",
")",
")",
"utils",
".",
"debug",
"(",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"converterArgs",
")",
"}",
"`",
")",
"try",
"{",
"child",
"=",
"spawn",
"(",
"'powershell.exe'",
",",
"[",
"'-NoProfile'",
",",
"'-NoLogo'",
",",
"args",
"]",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
"}",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"utils",
".",
"debug",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"(",
"data",
")",
"=>",
"utils",
".",
"debug",
"(",
"data",
".",
"toString",
"(",
")",
")",
")",
"child",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"{",
"// The conversion process exited, let's look for a log file",
"// However, give the PS process a 3s headstart, since we'll",
"// crash if the logfile does not exist yet",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"tail",
"=",
"new",
"Tail",
"(",
"logfile",
",",
"{",
"fromBeginning",
":",
"true",
"}",
")",
"tail",
".",
"on",
"(",
"'line'",
",",
"(",
"data",
")",
"=>",
"{",
"utils",
".",
"log",
"(",
"data",
")",
"if",
"(",
"data",
".",
"indexOf",
"(",
"'Conversion complete'",
")",
">",
"-",
"1",
")",
"{",
"utils",
".",
"log",
"(",
"''",
")",
"tail",
".",
"unwatch",
"(",
")",
"resolve",
"(",
")",
"}",
"else",
"if",
"(",
"data",
".",
"indexOf",
"(",
"'An error occurred'",
")",
">",
"-",
"1",
")",
"{",
"tail",
".",
"unwatch",
"(",
")",
"reject",
"(",
"new",
"Error",
"(",
"'Detected error in conversion log'",
")",
")",
"}",
"}",
")",
"tail",
".",
"on",
"(",
"'error'",
",",
"(",
"err",
")",
"=>",
"utils",
".",
"log",
"(",
"err",
")",
")",
"}",
",",
"3000",
")",
"}",
")",
"child",
".",
"stdin",
".",
"end",
"(",
")",
"}",
")",
"}"
] |
Converts the given Electron app using Project Centennial
Container Virtualization.
@param program - Program object containing the user's instructions
@returns - Promise
|
[
"Converts",
"the",
"given",
"Electron",
"app",
"using",
"Project",
"Centennial",
"Container",
"Virtualization",
"."
] |
ecdcee197df30e21a2a094edfc350eac1c3cddc5
|
https://github.com/felixrieseberg/electron-windows-store/blob/ecdcee197df30e21a2a094edfc350eac1c3cddc5/lib/convert.js#L18-L86
|
18,236
|
Sage/streamlinejs
|
lib/register.js
|
specialRequire
|
function specialRequire(name, fromDir) {
if (!fromDir) fromDir = process.cwd();
var paths = Module._nodeModulePaths(fromDir);
var path = Module._findPath(name, paths);
return path ? require(path) : require(name);
}
|
javascript
|
function specialRequire(name, fromDir) {
if (!fromDir) fromDir = process.cwd();
var paths = Module._nodeModulePaths(fromDir);
var path = Module._findPath(name, paths);
return path ? require(path) : require(name);
}
|
[
"function",
"specialRequire",
"(",
"name",
",",
"fromDir",
")",
"{",
"if",
"(",
"!",
"fromDir",
")",
"fromDir",
"=",
"process",
".",
"cwd",
"(",
")",
";",
"var",
"paths",
"=",
"Module",
".",
"_nodeModulePaths",
"(",
"fromDir",
")",
";",
"var",
"path",
"=",
"Module",
".",
"_findPath",
"(",
"name",
",",
"paths",
")",
";",
"return",
"path",
"?",
"require",
"(",
"path",
")",
":",
"require",
"(",
"name",
")",
";",
"}"
] |
special require for CoffeeScript registration
|
[
"special",
"require",
"for",
"CoffeeScript",
"registration"
] |
fbd28601ddb00a337a39e044eb035b6b7890abc1
|
https://github.com/Sage/streamlinejs/blob/fbd28601ddb00a337a39e044eb035b6b7890abc1/lib/register.js#L12-L17
|
18,237
|
Sage/streamlinejs
|
examples/streamlineMe/streamlineMe.js
|
_transform
|
function _transform() {
var codeIn = $('#codeIn').val();
try {
var codeOut = Streamline.transform(codeIn, {
runtime: _generators ? "generators" : "callbacks",
});
$('#codeOut').val(codeOut);
info("ready");
} catch (ex) {
console.error(ex);
error(ex.message);
}
}
|
javascript
|
function _transform() {
var codeIn = $('#codeIn').val();
try {
var codeOut = Streamline.transform(codeIn, {
runtime: _generators ? "generators" : "callbacks",
});
$('#codeOut').val(codeOut);
info("ready");
} catch (ex) {
console.error(ex);
error(ex.message);
}
}
|
[
"function",
"_transform",
"(",
")",
"{",
"var",
"codeIn",
"=",
"$",
"(",
"'#codeIn'",
")",
".",
"val",
"(",
")",
";",
"try",
"{",
"var",
"codeOut",
"=",
"Streamline",
".",
"transform",
"(",
"codeIn",
",",
"{",
"runtime",
":",
"_generators",
"?",
"\"generators\"",
":",
"\"callbacks\"",
",",
"}",
")",
";",
"$",
"(",
"'#codeOut'",
")",
".",
"val",
"(",
"codeOut",
")",
";",
"info",
"(",
"\"ready\"",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"console",
".",
"error",
"(",
"ex",
")",
";",
"error",
"(",
"ex",
".",
"message",
")",
";",
"}",
"}"
] |
define demo if user does not execute intro
|
[
"define",
"demo",
"if",
"user",
"does",
"not",
"execute",
"intro"
] |
fbd28601ddb00a337a39e044eb035b6b7890abc1
|
https://github.com/Sage/streamlinejs/blob/fbd28601ddb00a337a39e044eb035b6b7890abc1/examples/streamlineMe/streamlineMe.js#L153-L165
|
18,238
|
jshttp/on-finished
|
index.js
|
onFinished
|
function onFinished (msg, listener) {
if (isFinished(msg) !== false) {
defer(listener, null, msg)
return msg
}
// attach the listener to the message
attachListener(msg, listener)
return msg
}
|
javascript
|
function onFinished (msg, listener) {
if (isFinished(msg) !== false) {
defer(listener, null, msg)
return msg
}
// attach the listener to the message
attachListener(msg, listener)
return msg
}
|
[
"function",
"onFinished",
"(",
"msg",
",",
"listener",
")",
"{",
"if",
"(",
"isFinished",
"(",
"msg",
")",
"!==",
"false",
")",
"{",
"defer",
"(",
"listener",
",",
"null",
",",
"msg",
")",
"return",
"msg",
"}",
"// attach the listener to the message",
"attachListener",
"(",
"msg",
",",
"listener",
")",
"return",
"msg",
"}"
] |
Invoke callback when the response has finished, useful for
cleaning up resources afterwards.
@param {object} msg
@param {function} listener
@return {object}
@public
|
[
"Invoke",
"callback",
"when",
"the",
"response",
"has",
"finished",
"useful",
"for",
"cleaning",
"up",
"resources",
"afterwards",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L45-L55
|
18,239
|
jshttp/on-finished
|
index.js
|
isFinished
|
function isFinished (msg) {
var socket = msg.socket
if (typeof msg.finished === 'boolean') {
// OutgoingMessage
return Boolean(msg.finished || (socket && !socket.writable))
}
if (typeof msg.complete === 'boolean') {
// IncomingMessage
return Boolean(msg.upgrade || !socket || !socket.readable || (msg.complete && !msg.readable))
}
// don't know
return undefined
}
|
javascript
|
function isFinished (msg) {
var socket = msg.socket
if (typeof msg.finished === 'boolean') {
// OutgoingMessage
return Boolean(msg.finished || (socket && !socket.writable))
}
if (typeof msg.complete === 'boolean') {
// IncomingMessage
return Boolean(msg.upgrade || !socket || !socket.readable || (msg.complete && !msg.readable))
}
// don't know
return undefined
}
|
[
"function",
"isFinished",
"(",
"msg",
")",
"{",
"var",
"socket",
"=",
"msg",
".",
"socket",
"if",
"(",
"typeof",
"msg",
".",
"finished",
"===",
"'boolean'",
")",
"{",
"// OutgoingMessage",
"return",
"Boolean",
"(",
"msg",
".",
"finished",
"||",
"(",
"socket",
"&&",
"!",
"socket",
".",
"writable",
")",
")",
"}",
"if",
"(",
"typeof",
"msg",
".",
"complete",
"===",
"'boolean'",
")",
"{",
"// IncomingMessage",
"return",
"Boolean",
"(",
"msg",
".",
"upgrade",
"||",
"!",
"socket",
"||",
"!",
"socket",
".",
"readable",
"||",
"(",
"msg",
".",
"complete",
"&&",
"!",
"msg",
".",
"readable",
")",
")",
"}",
"// don't know",
"return",
"undefined",
"}"
] |
Determine if message is already finished.
@param {object} msg
@return {boolean}
@public
|
[
"Determine",
"if",
"message",
"is",
"already",
"finished",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L65-L80
|
18,240
|
jshttp/on-finished
|
index.js
|
attachFinishedListener
|
function attachFinishedListener (msg, callback) {
var eeMsg
var eeSocket
var finished = false
function onFinish (error) {
eeMsg.cancel()
eeSocket.cancel()
finished = true
callback(error)
}
// finished on first message event
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
function onSocket (socket) {
// remove listener
msg.removeListener('socket', onSocket)
if (finished) return
if (eeMsg !== eeSocket) return
// finished on first socket event
eeSocket = first([[socket, 'error', 'close']], onFinish)
}
if (msg.socket) {
// socket already assigned
onSocket(msg.socket)
return
}
// wait for socket to be assigned
msg.on('socket', onSocket)
if (msg.socket === undefined) {
// istanbul ignore next: node.js 0.8 patch
patchAssignSocket(msg, onSocket)
}
}
|
javascript
|
function attachFinishedListener (msg, callback) {
var eeMsg
var eeSocket
var finished = false
function onFinish (error) {
eeMsg.cancel()
eeSocket.cancel()
finished = true
callback(error)
}
// finished on first message event
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
function onSocket (socket) {
// remove listener
msg.removeListener('socket', onSocket)
if (finished) return
if (eeMsg !== eeSocket) return
// finished on first socket event
eeSocket = first([[socket, 'error', 'close']], onFinish)
}
if (msg.socket) {
// socket already assigned
onSocket(msg.socket)
return
}
// wait for socket to be assigned
msg.on('socket', onSocket)
if (msg.socket === undefined) {
// istanbul ignore next: node.js 0.8 patch
patchAssignSocket(msg, onSocket)
}
}
|
[
"function",
"attachFinishedListener",
"(",
"msg",
",",
"callback",
")",
"{",
"var",
"eeMsg",
"var",
"eeSocket",
"var",
"finished",
"=",
"false",
"function",
"onFinish",
"(",
"error",
")",
"{",
"eeMsg",
".",
"cancel",
"(",
")",
"eeSocket",
".",
"cancel",
"(",
")",
"finished",
"=",
"true",
"callback",
"(",
"error",
")",
"}",
"// finished on first message event",
"eeMsg",
"=",
"eeSocket",
"=",
"first",
"(",
"[",
"[",
"msg",
",",
"'end'",
",",
"'finish'",
"]",
"]",
",",
"onFinish",
")",
"function",
"onSocket",
"(",
"socket",
")",
"{",
"// remove listener",
"msg",
".",
"removeListener",
"(",
"'socket'",
",",
"onSocket",
")",
"if",
"(",
"finished",
")",
"return",
"if",
"(",
"eeMsg",
"!==",
"eeSocket",
")",
"return",
"// finished on first socket event",
"eeSocket",
"=",
"first",
"(",
"[",
"[",
"socket",
",",
"'error'",
",",
"'close'",
"]",
"]",
",",
"onFinish",
")",
"}",
"if",
"(",
"msg",
".",
"socket",
")",
"{",
"// socket already assigned",
"onSocket",
"(",
"msg",
".",
"socket",
")",
"return",
"}",
"// wait for socket to be assigned",
"msg",
".",
"on",
"(",
"'socket'",
",",
"onSocket",
")",
"if",
"(",
"msg",
".",
"socket",
"===",
"undefined",
")",
"{",
"// istanbul ignore next: node.js 0.8 patch",
"patchAssignSocket",
"(",
"msg",
",",
"onSocket",
")",
"}",
"}"
] |
Attach a finished listener to the message.
@param {object} msg
@param {function} callback
@private
|
[
"Attach",
"a",
"finished",
"listener",
"to",
"the",
"message",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L90-L130
|
18,241
|
jshttp/on-finished
|
index.js
|
attachListener
|
function attachListener (msg, listener) {
var attached = msg.__onFinished
// create a private single listener with queue
if (!attached || !attached.queue) {
attached = msg.__onFinished = createListener(msg)
attachFinishedListener(msg, attached)
}
attached.queue.push(listener)
}
|
javascript
|
function attachListener (msg, listener) {
var attached = msg.__onFinished
// create a private single listener with queue
if (!attached || !attached.queue) {
attached = msg.__onFinished = createListener(msg)
attachFinishedListener(msg, attached)
}
attached.queue.push(listener)
}
|
[
"function",
"attachListener",
"(",
"msg",
",",
"listener",
")",
"{",
"var",
"attached",
"=",
"msg",
".",
"__onFinished",
"// create a private single listener with queue",
"if",
"(",
"!",
"attached",
"||",
"!",
"attached",
".",
"queue",
")",
"{",
"attached",
"=",
"msg",
".",
"__onFinished",
"=",
"createListener",
"(",
"msg",
")",
"attachFinishedListener",
"(",
"msg",
",",
"attached",
")",
"}",
"attached",
".",
"queue",
".",
"push",
"(",
"listener",
")",
"}"
] |
Attach the listener to the message.
@param {object} msg
@return {function}
@private
|
[
"Attach",
"the",
"listener",
"to",
"the",
"message",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L140-L150
|
18,242
|
jshttp/on-finished
|
index.js
|
createListener
|
function createListener (msg) {
function listener (err) {
if (msg.__onFinished === listener) msg.__onFinished = null
if (!listener.queue) return
var queue = listener.queue
listener.queue = null
for (var i = 0; i < queue.length; i++) {
queue[i](err, msg)
}
}
listener.queue = []
return listener
}
|
javascript
|
function createListener (msg) {
function listener (err) {
if (msg.__onFinished === listener) msg.__onFinished = null
if (!listener.queue) return
var queue = listener.queue
listener.queue = null
for (var i = 0; i < queue.length; i++) {
queue[i](err, msg)
}
}
listener.queue = []
return listener
}
|
[
"function",
"createListener",
"(",
"msg",
")",
"{",
"function",
"listener",
"(",
"err",
")",
"{",
"if",
"(",
"msg",
".",
"__onFinished",
"===",
"listener",
")",
"msg",
".",
"__onFinished",
"=",
"null",
"if",
"(",
"!",
"listener",
".",
"queue",
")",
"return",
"var",
"queue",
"=",
"listener",
".",
"queue",
"listener",
".",
"queue",
"=",
"null",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"queue",
".",
"length",
";",
"i",
"++",
")",
"{",
"queue",
"[",
"i",
"]",
"(",
"err",
",",
"msg",
")",
"}",
"}",
"listener",
".",
"queue",
"=",
"[",
"]",
"return",
"listener",
"}"
] |
Create listener on message.
@param {object} msg
@return {function}
@private
|
[
"Create",
"listener",
"on",
"message",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L160-L176
|
18,243
|
jshttp/on-finished
|
index.js
|
patchAssignSocket
|
function patchAssignSocket (res, callback) {
var assignSocket = res.assignSocket
if (typeof assignSocket !== 'function') return
// res.on('socket', callback) is broken in 0.8
res.assignSocket = function _assignSocket (socket) {
assignSocket.call(this, socket)
callback(socket)
}
}
|
javascript
|
function patchAssignSocket (res, callback) {
var assignSocket = res.assignSocket
if (typeof assignSocket !== 'function') return
// res.on('socket', callback) is broken in 0.8
res.assignSocket = function _assignSocket (socket) {
assignSocket.call(this, socket)
callback(socket)
}
}
|
[
"function",
"patchAssignSocket",
"(",
"res",
",",
"callback",
")",
"{",
"var",
"assignSocket",
"=",
"res",
".",
"assignSocket",
"if",
"(",
"typeof",
"assignSocket",
"!==",
"'function'",
")",
"return",
"// res.on('socket', callback) is broken in 0.8",
"res",
".",
"assignSocket",
"=",
"function",
"_assignSocket",
"(",
"socket",
")",
"{",
"assignSocket",
".",
"call",
"(",
"this",
",",
"socket",
")",
"callback",
"(",
"socket",
")",
"}",
"}"
] |
Patch ServerResponse.prototype.assignSocket for node.js 0.8.
@param {ServerResponse} res
@param {function} callback
@private
istanbul ignore next: node.js 0.8 patch
|
[
"Patch",
"ServerResponse",
".",
"prototype",
".",
"assignSocket",
"for",
"node",
".",
"js",
"0",
".",
"8",
"."
] |
08345db3b23a2db01c6dfe720aff51385fe801d4
|
https://github.com/jshttp/on-finished/blob/08345db3b23a2db01c6dfe720aff51385fe801d4/index.js#L187-L197
|
18,244
|
seek-oss/serverless-haskell
|
serverless-plugin/ld.js
|
parseLdOutput
|
function parseLdOutput(output) {
const libraryList = output.split('\n').filter(ln => ln.includes('=>'));
const result = {};
libraryList.forEach(s => {
const [name, _, libPath] = s.trim().split(' ');
result[name] = libPath;
});
return result;
}
|
javascript
|
function parseLdOutput(output) {
const libraryList = output.split('\n').filter(ln => ln.includes('=>'));
const result = {};
libraryList.forEach(s => {
const [name, _, libPath] = s.trim().split(' ');
result[name] = libPath;
});
return result;
}
|
[
"function",
"parseLdOutput",
"(",
"output",
")",
"{",
"const",
"libraryList",
"=",
"output",
".",
"split",
"(",
"'\\n'",
")",
".",
"filter",
"(",
"ln",
"=>",
"ln",
".",
"includes",
"(",
"'=>'",
")",
")",
";",
"const",
"result",
"=",
"{",
"}",
";",
"libraryList",
".",
"forEach",
"(",
"s",
"=>",
"{",
"const",
"[",
"name",
",",
"_",
",",
"libPath",
"]",
"=",
"s",
".",
"trim",
"(",
")",
".",
"split",
"(",
"' '",
")",
";",
"result",
"[",
"name",
"]",
"=",
"libPath",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] |
Parse output of ldd or ldconfig and return a map of library names to paths
|
[
"Parse",
"output",
"of",
"ldd",
"or",
"ldconfig",
"and",
"return",
"a",
"map",
"of",
"library",
"names",
"to",
"paths"
] |
04f67b86b6b23f3e44a8d9ad651f5020e399834a
|
https://github.com/seek-oss/serverless-haskell/blob/04f67b86b6b23f3e44a8d9ad651f5020e399834a/serverless-plugin/ld.js#L6-L16
|
18,245
|
logux/core
|
base-node.js
|
BaseNode
|
function BaseNode (nodeId, log, connection, options) {
/**
* Unique current machine name.
* @type {string}
*
* @example
* console.log(node.localNodeId + ' is started')
*/
this.localNodeId = nodeId
/**
* Log for synchronization.
* @type {Log}
*/
this.log = log
/**
* Connection used to communicate to remote node.
* @type {Connection}
*/
this.connection = connection
/**
* Synchronization options.
* @type {object}
*/
this.options = options || { }
if (this.options.ping && !this.options.timeout) {
throw new Error('You must set timeout option to use ping')
}
/**
* Is synchronization in process.
* @type {boolean}
*
* @example
* node.on('disconnect', () => {
* node.connected //=> false
* })
*/
this.connected = false
/**
* Did we finish remote node authentication.
* @type {boolean}
*/
this.authenticated = false
this.unauthenticated = []
this.timeFix = 0
this.syncing = 0
this.received = { }
/**
* Latest current log `added` time, which was successfully synchronized.
* It will be saves in log store.
* @type {number}
*/
this.lastSent = 0
/**
* Latest remote node’s log `added` time, which was successfully synchronized.
* It will be saves in log store.
* @type {number}
*/
this.lastReceived = 0
/**
* Current synchronization state.
*
* * `disconnected`: no connection, but no new actions to synchronization.
* * `connecting`: connection was started and we wait for node answer.
* * `sending`: new actions was sent, waiting for answer.
* * `synchronized`: all actions was synchronized and we keep connection.
*
* @type {"disconnected"|"connecting"|"sending"|"synchronized"}
*
* @example
* node.on('state', () => {
* if (node.state === 'sending') {
* console.log('Do not close browser')
* }
* })
*/
this.state = 'disconnected'
this.emitter = new NanoEvents()
this.timeouts = []
this.throwsError = true
this.unbind = []
var node = this
this.unbind.push(log.on('add', function (action, meta) {
node.onAdd(action, meta)
}))
this.unbind.push(connection.on('connecting', function () {
node.onConnecting()
}))
this.unbind.push(connection.on('connect', function () {
node.onConnect()
}))
this.unbind.push(connection.on('message', function (message) {
node.onMessage(message)
}))
this.unbind.push(connection.on('error', function (error) {
if (error.message === 'Wrong message format') {
node.sendError(new LoguxError('wrong-format', error.received))
node.connection.disconnect('error')
} else {
node.error(error)
}
}))
this.unbind.push(connection.on('disconnect', function () {
node.onDisconnect()
}))
this.initialized = false
this.lastAddedCache = 0
this.initializing = this.initialize()
}
|
javascript
|
function BaseNode (nodeId, log, connection, options) {
/**
* Unique current machine name.
* @type {string}
*
* @example
* console.log(node.localNodeId + ' is started')
*/
this.localNodeId = nodeId
/**
* Log for synchronization.
* @type {Log}
*/
this.log = log
/**
* Connection used to communicate to remote node.
* @type {Connection}
*/
this.connection = connection
/**
* Synchronization options.
* @type {object}
*/
this.options = options || { }
if (this.options.ping && !this.options.timeout) {
throw new Error('You must set timeout option to use ping')
}
/**
* Is synchronization in process.
* @type {boolean}
*
* @example
* node.on('disconnect', () => {
* node.connected //=> false
* })
*/
this.connected = false
/**
* Did we finish remote node authentication.
* @type {boolean}
*/
this.authenticated = false
this.unauthenticated = []
this.timeFix = 0
this.syncing = 0
this.received = { }
/**
* Latest current log `added` time, which was successfully synchronized.
* It will be saves in log store.
* @type {number}
*/
this.lastSent = 0
/**
* Latest remote node’s log `added` time, which was successfully synchronized.
* It will be saves in log store.
* @type {number}
*/
this.lastReceived = 0
/**
* Current synchronization state.
*
* * `disconnected`: no connection, but no new actions to synchronization.
* * `connecting`: connection was started and we wait for node answer.
* * `sending`: new actions was sent, waiting for answer.
* * `synchronized`: all actions was synchronized and we keep connection.
*
* @type {"disconnected"|"connecting"|"sending"|"synchronized"}
*
* @example
* node.on('state', () => {
* if (node.state === 'sending') {
* console.log('Do not close browser')
* }
* })
*/
this.state = 'disconnected'
this.emitter = new NanoEvents()
this.timeouts = []
this.throwsError = true
this.unbind = []
var node = this
this.unbind.push(log.on('add', function (action, meta) {
node.onAdd(action, meta)
}))
this.unbind.push(connection.on('connecting', function () {
node.onConnecting()
}))
this.unbind.push(connection.on('connect', function () {
node.onConnect()
}))
this.unbind.push(connection.on('message', function (message) {
node.onMessage(message)
}))
this.unbind.push(connection.on('error', function (error) {
if (error.message === 'Wrong message format') {
node.sendError(new LoguxError('wrong-format', error.received))
node.connection.disconnect('error')
} else {
node.error(error)
}
}))
this.unbind.push(connection.on('disconnect', function () {
node.onDisconnect()
}))
this.initialized = false
this.lastAddedCache = 0
this.initializing = this.initialize()
}
|
[
"function",
"BaseNode",
"(",
"nodeId",
",",
"log",
",",
"connection",
",",
"options",
")",
"{",
"/**\n * Unique current machine name.\n * @type {string}\n *\n * @example\n * console.log(node.localNodeId + ' is started')\n */",
"this",
".",
"localNodeId",
"=",
"nodeId",
"/**\n * Log for synchronization.\n * @type {Log}\n */",
"this",
".",
"log",
"=",
"log",
"/**\n * Connection used to communicate to remote node.\n * @type {Connection}\n */",
"this",
".",
"connection",
"=",
"connection",
"/**\n * Synchronization options.\n * @type {object}\n */",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
"if",
"(",
"this",
".",
"options",
".",
"ping",
"&&",
"!",
"this",
".",
"options",
".",
"timeout",
")",
"{",
"throw",
"new",
"Error",
"(",
"'You must set timeout option to use ping'",
")",
"}",
"/**\n * Is synchronization in process.\n * @type {boolean}\n *\n * @example\n * node.on('disconnect', () => {\n * node.connected //=> false\n * })\n */",
"this",
".",
"connected",
"=",
"false",
"/**\n * Did we finish remote node authentication.\n * @type {boolean}\n */",
"this",
".",
"authenticated",
"=",
"false",
"this",
".",
"unauthenticated",
"=",
"[",
"]",
"this",
".",
"timeFix",
"=",
"0",
"this",
".",
"syncing",
"=",
"0",
"this",
".",
"received",
"=",
"{",
"}",
"/**\n * Latest current log `added` time, which was successfully synchronized.\n * It will be saves in log store.\n * @type {number}\n */",
"this",
".",
"lastSent",
"=",
"0",
"/**\n * Latest remote node’s log `added` time, which was successfully synchronized.\n * It will be saves in log store.\n * @type {number}\n */",
"this",
".",
"lastReceived",
"=",
"0",
"/**\n * Current synchronization state.\n *\n * * `disconnected`: no connection, but no new actions to synchronization.\n * * `connecting`: connection was started and we wait for node answer.\n * * `sending`: new actions was sent, waiting for answer.\n * * `synchronized`: all actions was synchronized and we keep connection.\n *\n * @type {\"disconnected\"|\"connecting\"|\"sending\"|\"synchronized\"}\n *\n * @example\n * node.on('state', () => {\n * if (node.state === 'sending') {\n * console.log('Do not close browser')\n * }\n * })\n */",
"this",
".",
"state",
"=",
"'disconnected'",
"this",
".",
"emitter",
"=",
"new",
"NanoEvents",
"(",
")",
"this",
".",
"timeouts",
"=",
"[",
"]",
"this",
".",
"throwsError",
"=",
"true",
"this",
".",
"unbind",
"=",
"[",
"]",
"var",
"node",
"=",
"this",
"this",
".",
"unbind",
".",
"push",
"(",
"log",
".",
"on",
"(",
"'add'",
",",
"function",
"(",
"action",
",",
"meta",
")",
"{",
"node",
".",
"onAdd",
"(",
"action",
",",
"meta",
")",
"}",
")",
")",
"this",
".",
"unbind",
".",
"push",
"(",
"connection",
".",
"on",
"(",
"'connecting'",
",",
"function",
"(",
")",
"{",
"node",
".",
"onConnecting",
"(",
")",
"}",
")",
")",
"this",
".",
"unbind",
".",
"push",
"(",
"connection",
".",
"on",
"(",
"'connect'",
",",
"function",
"(",
")",
"{",
"node",
".",
"onConnect",
"(",
")",
"}",
")",
")",
"this",
".",
"unbind",
".",
"push",
"(",
"connection",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"message",
")",
"{",
"node",
".",
"onMessage",
"(",
"message",
")",
"}",
")",
")",
"this",
".",
"unbind",
".",
"push",
"(",
"connection",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
".",
"message",
"===",
"'Wrong message format'",
")",
"{",
"node",
".",
"sendError",
"(",
"new",
"LoguxError",
"(",
"'wrong-format'",
",",
"error",
".",
"received",
")",
")",
"node",
".",
"connection",
".",
"disconnect",
"(",
"'error'",
")",
"}",
"else",
"{",
"node",
".",
"error",
"(",
"error",
")",
"}",
"}",
")",
")",
"this",
".",
"unbind",
".",
"push",
"(",
"connection",
".",
"on",
"(",
"'disconnect'",
",",
"function",
"(",
")",
"{",
"node",
".",
"onDisconnect",
"(",
")",
"}",
")",
")",
"this",
".",
"initialized",
"=",
"false",
"this",
".",
"lastAddedCache",
"=",
"0",
"this",
".",
"initializing",
"=",
"this",
".",
"initialize",
"(",
")",
"}"
] |
Base methods for synchronization nodes. Client and server nodes
are based on this module.
@param {string} nodeId Unique current machine name.
@param {Log} log Logux log instance to be synchronized.
@param {Connection} connection Connection to remote node.
@param {object} [options] Synchronization options.
@param {object} [options.credentials] Client credentials.
For example, access token.
@param {authCallback} [options.auth] Function to check client credentials.
@param {boolean} [options.fixTime=false] Detect difference between client
and server and fix time
in synchronized actions.
@param {number} [options.timeout=0] Timeout in milliseconds to wait answer
before disconnect.
@param {number} [options.ping=0] Milliseconds since last message to test
connection by sending ping.
@param {filter} [options.inFilter] Function to filter actions
from remote node. Best place
for access control.
@param {mapper} [options.inMap] Map function to change remote node’s action
before put it to current log.
@param {filter} [options.outFilter] Filter function to select actions
to synchronization.
@param {mapper} [options.outMap] Map function to change action
before sending it to remote client.
@param {string} [options.subprotocol] Application subprotocol version
in SemVer format.
@abstract
@class
|
[
"Base",
"methods",
"for",
"synchronization",
"nodes",
".",
"Client",
"and",
"server",
"nodes",
"are",
"based",
"on",
"this",
"module",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/base-node.js#L73-L189
|
18,246
|
logux/core
|
base-node.js
|
destroy
|
function destroy () {
if (this.connection.destroy) {
this.connection.destroy()
} else if (this.connected) {
this.connection.disconnect('destroy')
}
for (var i = 0; i < this.unbind.length; i++) {
this.unbind[i]()
}
clearTimeout(this.pingTimeout)
this.endTimeout()
}
|
javascript
|
function destroy () {
if (this.connection.destroy) {
this.connection.destroy()
} else if (this.connected) {
this.connection.disconnect('destroy')
}
for (var i = 0; i < this.unbind.length; i++) {
this.unbind[i]()
}
clearTimeout(this.pingTimeout)
this.endTimeout()
}
|
[
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"this",
".",
"connection",
".",
"destroy",
")",
"{",
"this",
".",
"connection",
".",
"destroy",
"(",
")",
"}",
"else",
"if",
"(",
"this",
".",
"connected",
")",
"{",
"this",
".",
"connection",
".",
"disconnect",
"(",
"'destroy'",
")",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"unbind",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"unbind",
"[",
"i",
"]",
"(",
")",
"}",
"clearTimeout",
"(",
"this",
".",
"pingTimeout",
")",
"this",
".",
"endTimeout",
"(",
")",
"}"
] |
Shut down the connection and unsubscribe from log events.
@return {undefined}
@example
connection.on('disconnect', () => {
server.destroy()
})
|
[
"Shut",
"down",
"the",
"connection",
"and",
"unsubscribe",
"from",
"log",
"events",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/base-node.js#L335-L346
|
18,247
|
logux/core
|
server-node.js
|
ServerNode
|
function ServerNode (nodeId, log, connection, options) {
options = merge(options, DEFAULT_OPTIONS)
BaseNode.call(this, nodeId, log, connection, options)
if (this.options.fixTime) {
throw new Error(
'Logux Server could not fix time. Set opts.fixTime for Client node.')
}
this.state = 'connecting'
}
|
javascript
|
function ServerNode (nodeId, log, connection, options) {
options = merge(options, DEFAULT_OPTIONS)
BaseNode.call(this, nodeId, log, connection, options)
if (this.options.fixTime) {
throw new Error(
'Logux Server could not fix time. Set opts.fixTime for Client node.')
}
this.state = 'connecting'
}
|
[
"function",
"ServerNode",
"(",
"nodeId",
",",
"log",
",",
"connection",
",",
"options",
")",
"{",
"options",
"=",
"merge",
"(",
"options",
",",
"DEFAULT_OPTIONS",
")",
"BaseNode",
".",
"call",
"(",
"this",
",",
"nodeId",
",",
"log",
",",
"connection",
",",
"options",
")",
"if",
"(",
"this",
".",
"options",
".",
"fixTime",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Logux Server could not fix time. Set opts.fixTime for Client node.'",
")",
"}",
"this",
".",
"state",
"=",
"'connecting'",
"}"
] |
Server node in synchronization pair.
Instead of client node, it doesn’t initialize synchronization
and destroy itself on disconnect.
@param {string} nodeId Unique current machine name.
@param {Log} log Logux log instance to be synchronized.
@param {Connection} connection Connection to remote node.
@param {object} [options] Synchronization options.
@param {object} [options.credentials] Server credentials.
For example, access token.
@param {authCallback} [options.auth] Function to check client credentials.
@param {number} [options.timeout=20000] Timeout in milliseconds
to wait answer before disconnect.
@param {number} [options.ping=10000] Milliseconds since last message to test
connection by sending ping.
@param {filter} [options.inFilter] Function to filter actions from client.
Best place for permissions control.
@param {mapper} [options.inMap] Map function to change remote node’s action
before put it to current log.
@param {filter} [options.outFilter] Filter function to select actions
to synchronization.
@param {mapper} [options.outMap] Map function to change action
before sending it to remote client.
@param {string} [options.subprotocol] Application subprotocol version
in SemVer format.
@example
import { ServerNode } from 'logux-core'
startServer(ws => {
const connection = new ServerConnection(ws)
const node = new ServerNode('server' + id, log, connection)
})
@extends BaseNode
@class
|
[
"Server",
"node",
"in",
"synchronization",
"pair",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/server-node.js#L48-L58
|
18,248
|
logux/core
|
client-node.js
|
ClientNode
|
function ClientNode (nodeId, log, connection, options) {
options = merge(options, DEFAULT_OPTIONS)
BaseNode.call(this, nodeId, log, connection, options)
}
|
javascript
|
function ClientNode (nodeId, log, connection, options) {
options = merge(options, DEFAULT_OPTIONS)
BaseNode.call(this, nodeId, log, connection, options)
}
|
[
"function",
"ClientNode",
"(",
"nodeId",
",",
"log",
",",
"connection",
",",
"options",
")",
"{",
"options",
"=",
"merge",
"(",
"options",
",",
"DEFAULT_OPTIONS",
")",
"BaseNode",
".",
"call",
"(",
"this",
",",
"nodeId",
",",
"log",
",",
"connection",
",",
"options",
")",
"}"
] |
Client node in synchronization pair.
Instead of server node, it initializes synchronization
and sends connect message.
@param {string} nodeId Unique current machine name.
@param {Log} log Logux log instance to be synchronized.
@param {Connection} connection Connection to remote node.
@param {object} [options] Synchronization options.
@param {object} [options.credentials] Client credentials.
For example, access token.
@param {authCallback} [options.auth] Function to check server credentials.
@param {boolean} [options.fixTime=true] Detect difference between client
and server and fix time
in synchronized actions.
@param {number} [options.timeout=20000] Timeout in milliseconds
to wait answer before disconnect.
@param {number} [options.ping=5000] Milliseconds since last message to test
connection by sending ping.
@param {filter} [options.inFilter] Function to filter actions from server.
Best place for permissions control.
@param {mapper} [options.inMap] Map function to change remote node’s action
before put it to current log.
@param {filter} [options.outFilter] Filter function to select actions
to synchronization.
@param {mapper} [options.outMap] Map function to change action
before sending it to remote client.
@param {string} [options.subprotocol] Application subprotocol version
in SemVer format.
@example
import { ClientNode } from 'logux-core'
const connection = new BrowserConnection(url)
const node = new ClientNode(nodeId, log, connection)
@extends BaseNode
@class
|
[
"Client",
"node",
"in",
"synchronization",
"pair",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/client-node.js#L49-L52
|
18,249
|
logux/core
|
log.js
|
Log
|
function Log (opts) {
if (!opts) opts = { }
if (typeof opts.nodeId === 'undefined') {
throw new Error('Expected node ID')
}
if (typeof opts.store !== 'object') {
throw new Error('Expected store')
}
if (opts.nodeId.indexOf(' ') !== -1) {
throw new Error('Space is prohibited in node ID')
}
/**
* Unique node ID. It is used in action IDs.
* @type {string|number}
*/
this.nodeId = opts.nodeId
this.lastTime = 0
this.sequence = 0
this.store = opts.store
this.emitter = new NanoEvents()
}
|
javascript
|
function Log (opts) {
if (!opts) opts = { }
if (typeof opts.nodeId === 'undefined') {
throw new Error('Expected node ID')
}
if (typeof opts.store !== 'object') {
throw new Error('Expected store')
}
if (opts.nodeId.indexOf(' ') !== -1) {
throw new Error('Space is prohibited in node ID')
}
/**
* Unique node ID. It is used in action IDs.
* @type {string|number}
*/
this.nodeId = opts.nodeId
this.lastTime = 0
this.sequence = 0
this.store = opts.store
this.emitter = new NanoEvents()
}
|
[
"function",
"Log",
"(",
"opts",
")",
"{",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
"if",
"(",
"typeof",
"opts",
".",
"nodeId",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected node ID'",
")",
"}",
"if",
"(",
"typeof",
"opts",
".",
"store",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected store'",
")",
"}",
"if",
"(",
"opts",
".",
"nodeId",
".",
"indexOf",
"(",
"' '",
")",
"!==",
"-",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Space is prohibited in node ID'",
")",
"}",
"/**\n * Unique node ID. It is used in action IDs.\n * @type {string|number}\n */",
"this",
".",
"nodeId",
"=",
"opts",
".",
"nodeId",
"this",
".",
"lastTime",
"=",
"0",
"this",
".",
"sequence",
"=",
"0",
"this",
".",
"store",
"=",
"opts",
".",
"store",
"this",
".",
"emitter",
"=",
"new",
"NanoEvents",
"(",
")",
"}"
] |
Stores actions with time marks. Log is main idea in Logux.
In most end-user tools you will work with log and should know log API.
@param {object} opts Options.
@param {Store} opts.store Store for log.
@param {string|number} opts.nodeId Unique current machine name.
@example
import Log from 'logux-core/log'
const log = new Log({
store: new MemoryStore(),
nodeId: 'client:134'
})
log.on('add', beeper)
log.add({ type: 'beep' })
@class
|
[
"Stores",
"actions",
"with",
"time",
"marks",
".",
"Log",
"is",
"main",
"idea",
"in",
"Logux",
".",
"In",
"most",
"end",
"-",
"user",
"tools",
"you",
"will",
"work",
"with",
"log",
"and",
"should",
"know",
"log",
"API",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/log.js#L23-L48
|
18,250
|
logux/core
|
log.js
|
add
|
function add (action, meta) {
if (typeof action.type === 'undefined') {
throw new Error('Expected "type" in action')
}
if (!meta) meta = { }
var newId = false
if (typeof meta.id === 'undefined') {
newId = true
meta.id = this.generateId()
}
if (typeof meta.time === 'undefined') {
meta.time = parseInt(meta.id)
}
if (typeof meta.reasons === 'undefined') {
meta.reasons = []
} else if (!Array.isArray(meta.reasons)) {
meta.reasons = [meta.reasons]
}
meta.reasons.forEach(function (reason) {
if (typeof reason !== 'string') {
throw new Error('Expected "reasons" to be strings')
}
})
var log = this
this.emitter.emit('preadd', action, meta)
if (meta.keepLast) {
this.removeReason(meta.keepLast, { olderThan: meta })
meta.reasons.push(meta.keepLast)
}
if (meta.reasons.length === 0 && newId) {
this.emitter.emit('add', action, meta)
this.emitter.emit('clean', action, meta)
return Promise.resolve(meta)
} else if (meta.reasons.length === 0) {
return this.store.byId(meta.id).then(function (result) {
if (result[0]) {
return false
} else {
log.emitter.emit('add', action, meta)
log.emitter.emit('clean', action, meta)
return meta
}
})
} else {
return this.store.add(action, meta).then(function (addedMeta) {
if (addedMeta === false) {
return false
} else {
log.emitter.emit('add', action, addedMeta)
return addedMeta
}
})
}
}
|
javascript
|
function add (action, meta) {
if (typeof action.type === 'undefined') {
throw new Error('Expected "type" in action')
}
if (!meta) meta = { }
var newId = false
if (typeof meta.id === 'undefined') {
newId = true
meta.id = this.generateId()
}
if (typeof meta.time === 'undefined') {
meta.time = parseInt(meta.id)
}
if (typeof meta.reasons === 'undefined') {
meta.reasons = []
} else if (!Array.isArray(meta.reasons)) {
meta.reasons = [meta.reasons]
}
meta.reasons.forEach(function (reason) {
if (typeof reason !== 'string') {
throw new Error('Expected "reasons" to be strings')
}
})
var log = this
this.emitter.emit('preadd', action, meta)
if (meta.keepLast) {
this.removeReason(meta.keepLast, { olderThan: meta })
meta.reasons.push(meta.keepLast)
}
if (meta.reasons.length === 0 && newId) {
this.emitter.emit('add', action, meta)
this.emitter.emit('clean', action, meta)
return Promise.resolve(meta)
} else if (meta.reasons.length === 0) {
return this.store.byId(meta.id).then(function (result) {
if (result[0]) {
return false
} else {
log.emitter.emit('add', action, meta)
log.emitter.emit('clean', action, meta)
return meta
}
})
} else {
return this.store.add(action, meta).then(function (addedMeta) {
if (addedMeta === false) {
return false
} else {
log.emitter.emit('add', action, addedMeta)
return addedMeta
}
})
}
}
|
[
"function",
"add",
"(",
"action",
",",
"meta",
")",
"{",
"if",
"(",
"typeof",
"action",
".",
"type",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected \"type\" in action'",
")",
"}",
"if",
"(",
"!",
"meta",
")",
"meta",
"=",
"{",
"}",
"var",
"newId",
"=",
"false",
"if",
"(",
"typeof",
"meta",
".",
"id",
"===",
"'undefined'",
")",
"{",
"newId",
"=",
"true",
"meta",
".",
"id",
"=",
"this",
".",
"generateId",
"(",
")",
"}",
"if",
"(",
"typeof",
"meta",
".",
"time",
"===",
"'undefined'",
")",
"{",
"meta",
".",
"time",
"=",
"parseInt",
"(",
"meta",
".",
"id",
")",
"}",
"if",
"(",
"typeof",
"meta",
".",
"reasons",
"===",
"'undefined'",
")",
"{",
"meta",
".",
"reasons",
"=",
"[",
"]",
"}",
"else",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"meta",
".",
"reasons",
")",
")",
"{",
"meta",
".",
"reasons",
"=",
"[",
"meta",
".",
"reasons",
"]",
"}",
"meta",
".",
"reasons",
".",
"forEach",
"(",
"function",
"(",
"reason",
")",
"{",
"if",
"(",
"typeof",
"reason",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected \"reasons\" to be strings'",
")",
"}",
"}",
")",
"var",
"log",
"=",
"this",
"this",
".",
"emitter",
".",
"emit",
"(",
"'preadd'",
",",
"action",
",",
"meta",
")",
"if",
"(",
"meta",
".",
"keepLast",
")",
"{",
"this",
".",
"removeReason",
"(",
"meta",
".",
"keepLast",
",",
"{",
"olderThan",
":",
"meta",
"}",
")",
"meta",
".",
"reasons",
".",
"push",
"(",
"meta",
".",
"keepLast",
")",
"}",
"if",
"(",
"meta",
".",
"reasons",
".",
"length",
"===",
"0",
"&&",
"newId",
")",
"{",
"this",
".",
"emitter",
".",
"emit",
"(",
"'add'",
",",
"action",
",",
"meta",
")",
"this",
".",
"emitter",
".",
"emit",
"(",
"'clean'",
",",
"action",
",",
"meta",
")",
"return",
"Promise",
".",
"resolve",
"(",
"meta",
")",
"}",
"else",
"if",
"(",
"meta",
".",
"reasons",
".",
"length",
"===",
"0",
")",
"{",
"return",
"this",
".",
"store",
".",
"byId",
"(",
"meta",
".",
"id",
")",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"result",
"[",
"0",
"]",
")",
"{",
"return",
"false",
"}",
"else",
"{",
"log",
".",
"emitter",
".",
"emit",
"(",
"'add'",
",",
"action",
",",
"meta",
")",
"log",
".",
"emitter",
".",
"emit",
"(",
"'clean'",
",",
"action",
",",
"meta",
")",
"return",
"meta",
"}",
"}",
")",
"}",
"else",
"{",
"return",
"this",
".",
"store",
".",
"add",
"(",
"action",
",",
"meta",
")",
".",
"then",
"(",
"function",
"(",
"addedMeta",
")",
"{",
"if",
"(",
"addedMeta",
"===",
"false",
")",
"{",
"return",
"false",
"}",
"else",
"{",
"log",
".",
"emitter",
".",
"emit",
"(",
"'add'",
",",
"action",
",",
"addedMeta",
")",
"return",
"addedMeta",
"}",
"}",
")",
"}",
"}"
] |
Add action to log.
It will set `id`, `time` (if they was missed) and `added` property
to `meta` and call all listeners.
@param {Action} action The new action.
@param {Meta} [meta] Open structure for action metadata.
@param {string} [meta.id] Unique action ID.
@param {number} [meta.time] Action created time.
Milliseconds since UNIX epoch.
@param {string[]} [meta.reasons] Why action should be kept in log.
Action without reasons will be removed.
@param {string} [meta.keepLast] Set code as reason and remove this reasons
from previous actions.
@return {Promise} Promise with `meta` if action was added to log
or `false` if action was already in log
@example
removeButton.addEventListener('click', () => {
log.add({ type: 'users:remove', user: id })
})
|
[
"Add",
"action",
"to",
"log",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/log.js#L100-L161
|
18,251
|
logux/core
|
log.js
|
generateId
|
function generateId () {
var now = Date.now()
if (now <= this.lastTime) {
now = this.lastTime
this.sequence += 1
} else {
this.lastTime = now
this.sequence = 0
}
return now + ' ' + this.nodeId + ' ' + this.sequence
}
|
javascript
|
function generateId () {
var now = Date.now()
if (now <= this.lastTime) {
now = this.lastTime
this.sequence += 1
} else {
this.lastTime = now
this.sequence = 0
}
return now + ' ' + this.nodeId + ' ' + this.sequence
}
|
[
"function",
"generateId",
"(",
")",
"{",
"var",
"now",
"=",
"Date",
".",
"now",
"(",
")",
"if",
"(",
"now",
"<=",
"this",
".",
"lastTime",
")",
"{",
"now",
"=",
"this",
".",
"lastTime",
"this",
".",
"sequence",
"+=",
"1",
"}",
"else",
"{",
"this",
".",
"lastTime",
"=",
"now",
"this",
".",
"sequence",
"=",
"0",
"}",
"return",
"now",
"+",
"' '",
"+",
"this",
".",
"nodeId",
"+",
"' '",
"+",
"this",
".",
"sequence",
"}"
] |
Generate next unique action ID.
@return {string} Unique action ID.
@example
const id = log.generateId()
|
[
"Generate",
"next",
"unique",
"action",
"ID",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/log.js#L171-L181
|
18,252
|
logux/core
|
log.js
|
each
|
function each (opts, callback) {
if (!callback) {
callback = opts
opts = { order: 'created' }
}
var store = this.store
return new Promise(function (resolve) {
function nextPage (get) {
get().then(function (page) {
var result
for (var i = page.entries.length - 1; i >= 0; i--) {
var entry = page.entries[i]
result = callback(entry[0], entry[1])
if (result === false) break
}
if (result === false || !page.next) {
resolve()
} else {
nextPage(page.next)
}
})
}
nextPage(store.get.bind(store, opts))
})
}
|
javascript
|
function each (opts, callback) {
if (!callback) {
callback = opts
opts = { order: 'created' }
}
var store = this.store
return new Promise(function (resolve) {
function nextPage (get) {
get().then(function (page) {
var result
for (var i = page.entries.length - 1; i >= 0; i--) {
var entry = page.entries[i]
result = callback(entry[0], entry[1])
if (result === false) break
}
if (result === false || !page.next) {
resolve()
} else {
nextPage(page.next)
}
})
}
nextPage(store.get.bind(store, opts))
})
}
|
[
"function",
"each",
"(",
"opts",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"callback",
")",
"{",
"callback",
"=",
"opts",
"opts",
"=",
"{",
"order",
":",
"'created'",
"}",
"}",
"var",
"store",
"=",
"this",
".",
"store",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"function",
"nextPage",
"(",
"get",
")",
"{",
"get",
"(",
")",
".",
"then",
"(",
"function",
"(",
"page",
")",
"{",
"var",
"result",
"for",
"(",
"var",
"i",
"=",
"page",
".",
"entries",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"entry",
"=",
"page",
".",
"entries",
"[",
"i",
"]",
"result",
"=",
"callback",
"(",
"entry",
"[",
"0",
"]",
",",
"entry",
"[",
"1",
"]",
")",
"if",
"(",
"result",
"===",
"false",
")",
"break",
"}",
"if",
"(",
"result",
"===",
"false",
"||",
"!",
"page",
".",
"next",
")",
"{",
"resolve",
"(",
")",
"}",
"else",
"{",
"nextPage",
"(",
"page",
".",
"next",
")",
"}",
"}",
")",
"}",
"nextPage",
"(",
"store",
".",
"get",
".",
"bind",
"(",
"store",
",",
"opts",
")",
")",
"}",
")",
"}"
] |
Iterates through all actions, from last to first.
Return false from callback if you want to stop iteration.
@param {object} [opts] Iterator options.
@param {'added'|'created'} [opts.order='created'] Sort entries by created
time or when they was
added to this log.
@param {iterator} callback Function will be executed on every action.
@return {Promise} When iteration will be finished
by iterator or end of actions.
@example
log.each((action, meta) => {
if (compareTime(meta.id, lastBeep) <= 0) {
return false;
} else if (action.type === 'beep') {
beep()
lastBeep = meta.id
return false;
}
})
|
[
"Iterates",
"through",
"all",
"actions",
"from",
"last",
"to",
"first",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/log.js#L208-L235
|
18,253
|
logux/core
|
ws-connection.js
|
WsConnection
|
function WsConnection (url, WS, opts) {
this.connected = false
this.emitter = new NanoEvents()
if (WS) {
this.WS = WS
} else if (typeof WebSocket !== 'undefined') {
this.WS = WebSocket
} else {
throw new Error('No WebSocket support')
}
this.url = url
this.opts = opts
}
|
javascript
|
function WsConnection (url, WS, opts) {
this.connected = false
this.emitter = new NanoEvents()
if (WS) {
this.WS = WS
} else if (typeof WebSocket !== 'undefined') {
this.WS = WebSocket
} else {
throw new Error('No WebSocket support')
}
this.url = url
this.opts = opts
}
|
[
"function",
"WsConnection",
"(",
"url",
",",
"WS",
",",
"opts",
")",
"{",
"this",
".",
"connected",
"=",
"false",
"this",
".",
"emitter",
"=",
"new",
"NanoEvents",
"(",
")",
"if",
"(",
"WS",
")",
"{",
"this",
".",
"WS",
"=",
"WS",
"}",
"else",
"if",
"(",
"typeof",
"WebSocket",
"!==",
"'undefined'",
")",
"{",
"this",
".",
"WS",
"=",
"WebSocket",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'No WebSocket support'",
")",
"}",
"this",
".",
"url",
"=",
"url",
"this",
".",
"opts",
"=",
"opts",
"}"
] |
Logux connection for browser WebSocket.
@param {string} url WebSocket server URL.
@param {function} [WS] WebSocket class if you want change implementation.
@param {object} opts Extra option for WebSocket constructor.
@example
import { WsConnection } from 'logux-core'
const connection = new WsConnection('wss://logux.example.com/')
const node = new ClientNode(nodeId, log, connection, opts)
@class
@extends Connection
|
[
"Logux",
"connection",
"for",
"browser",
"WebSocket",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/ws-connection.js#L19-L31
|
18,254
|
logux/core
|
is-first-older.js
|
isFirstOlder
|
function isFirstOlder (firstMeta, secondMeta) {
if (firstMeta && !secondMeta) {
return false
} else if (!firstMeta && secondMeta) {
return true
}
if (firstMeta.time > secondMeta.time) {
return false
} else if (firstMeta.time < secondMeta.time) {
return true
}
var first = split(firstMeta.id)
var second = split(secondMeta.id)
if (first[1] > second[1]) {
return false
} else if (first[1] < second[1]) {
return true
}
if (first[0] > second[0]) {
return false
} else if (first[0] < second[0]) {
return true
}
return false
}
|
javascript
|
function isFirstOlder (firstMeta, secondMeta) {
if (firstMeta && !secondMeta) {
return false
} else if (!firstMeta && secondMeta) {
return true
}
if (firstMeta.time > secondMeta.time) {
return false
} else if (firstMeta.time < secondMeta.time) {
return true
}
var first = split(firstMeta.id)
var second = split(secondMeta.id)
if (first[1] > second[1]) {
return false
} else if (first[1] < second[1]) {
return true
}
if (first[0] > second[0]) {
return false
} else if (first[0] < second[0]) {
return true
}
return false
}
|
[
"function",
"isFirstOlder",
"(",
"firstMeta",
",",
"secondMeta",
")",
"{",
"if",
"(",
"firstMeta",
"&&",
"!",
"secondMeta",
")",
"{",
"return",
"false",
"}",
"else",
"if",
"(",
"!",
"firstMeta",
"&&",
"secondMeta",
")",
"{",
"return",
"true",
"}",
"if",
"(",
"firstMeta",
".",
"time",
">",
"secondMeta",
".",
"time",
")",
"{",
"return",
"false",
"}",
"else",
"if",
"(",
"firstMeta",
".",
"time",
"<",
"secondMeta",
".",
"time",
")",
"{",
"return",
"true",
"}",
"var",
"first",
"=",
"split",
"(",
"firstMeta",
".",
"id",
")",
"var",
"second",
"=",
"split",
"(",
"secondMeta",
".",
"id",
")",
"if",
"(",
"first",
"[",
"1",
"]",
">",
"second",
"[",
"1",
"]",
")",
"{",
"return",
"false",
"}",
"else",
"if",
"(",
"first",
"[",
"1",
"]",
"<",
"second",
"[",
"1",
"]",
")",
"{",
"return",
"true",
"}",
"if",
"(",
"first",
"[",
"0",
"]",
">",
"second",
"[",
"0",
"]",
")",
"{",
"return",
"false",
"}",
"else",
"if",
"(",
"first",
"[",
"0",
"]",
"<",
"second",
"[",
"0",
"]",
")",
"{",
"return",
"true",
"}",
"return",
"false",
"}"
] |
Compare time, when log entries were created.
It uses `meta.time` and `meta.id` to detect entries order.
@param {Meta} firstMeta Some action’s metadata.
@param {Meta} secondMeta Other action’s metadata.
@return {boolean} Is first action is older than second.
@example
import { isFirstOlder } from 'logux-core'
if (isFirstOlder(lastBeep, meta) {
beep(action)
lastBeep = meta
}
|
[
"Compare",
"time",
"when",
"log",
"entries",
"were",
"created",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/is-first-older.js#L23-L51
|
18,255
|
logux/core
|
logux-error.js
|
LoguxError
|
function LoguxError (type, options, received) {
Error.call(this, type)
/**
* Always equal to `LoguxError`. The best way to check error class.
* @type {string}
*
* @example
* if (error.name === 'LoguxError') { }
*/
this.name = 'LoguxError'
/**
* The error code.
* @type {string}
*
* @example
* if (error.type === 'timeout') {
* fixNetwork()
* }
*/
this.type = type
/**
* Error options depends on error type.
* @type {any}
*
* @example
* if (error.type === 'timeout') {
* console.error('A timeout was reached (' + error.options + ' ms)')
* }
*/
this.options = options
/**
* Human-readable error description.
* @type {string}
*
* @example
* console.log('Server throws: ' + error.description)
*/
this.description = LoguxError.describe(type, options)
/**
* Was error received from remote client.
* @type {boolean}
*/
this.received = !!received
this.message = ''
if (received) {
this.message += 'Logux received ' + this.type + ' error'
if (this.description !== this.type) {
this.message += ' (' + this.description + ')'
}
} else {
this.message = this.description
}
if (Error.captureStackTrace) {
Error.captureStackTrace(this, LoguxError)
}
}
|
javascript
|
function LoguxError (type, options, received) {
Error.call(this, type)
/**
* Always equal to `LoguxError`. The best way to check error class.
* @type {string}
*
* @example
* if (error.name === 'LoguxError') { }
*/
this.name = 'LoguxError'
/**
* The error code.
* @type {string}
*
* @example
* if (error.type === 'timeout') {
* fixNetwork()
* }
*/
this.type = type
/**
* Error options depends on error type.
* @type {any}
*
* @example
* if (error.type === 'timeout') {
* console.error('A timeout was reached (' + error.options + ' ms)')
* }
*/
this.options = options
/**
* Human-readable error description.
* @type {string}
*
* @example
* console.log('Server throws: ' + error.description)
*/
this.description = LoguxError.describe(type, options)
/**
* Was error received from remote client.
* @type {boolean}
*/
this.received = !!received
this.message = ''
if (received) {
this.message += 'Logux received ' + this.type + ' error'
if (this.description !== this.type) {
this.message += ' (' + this.description + ')'
}
} else {
this.message = this.description
}
if (Error.captureStackTrace) {
Error.captureStackTrace(this, LoguxError)
}
}
|
[
"function",
"LoguxError",
"(",
"type",
",",
"options",
",",
"received",
")",
"{",
"Error",
".",
"call",
"(",
"this",
",",
"type",
")",
"/**\n * Always equal to `LoguxError`. The best way to check error class.\n * @type {string}\n *\n * @example\n * if (error.name === 'LoguxError') { }\n */",
"this",
".",
"name",
"=",
"'LoguxError'",
"/**\n * The error code.\n * @type {string}\n *\n * @example\n * if (error.type === 'timeout') {\n * fixNetwork()\n * }\n */",
"this",
".",
"type",
"=",
"type",
"/**\n * Error options depends on error type.\n * @type {any}\n *\n * @example\n * if (error.type === 'timeout') {\n * console.error('A timeout was reached (' + error.options + ' ms)')\n * }\n */",
"this",
".",
"options",
"=",
"options",
"/**\n * Human-readable error description.\n * @type {string}\n *\n * @example\n * console.log('Server throws: ' + error.description)\n */",
"this",
".",
"description",
"=",
"LoguxError",
".",
"describe",
"(",
"type",
",",
"options",
")",
"/**\n * Was error received from remote client.\n * @type {boolean}\n */",
"this",
".",
"received",
"=",
"!",
"!",
"received",
"this",
".",
"message",
"=",
"''",
"if",
"(",
"received",
")",
"{",
"this",
".",
"message",
"+=",
"'Logux received '",
"+",
"this",
".",
"type",
"+",
"' error'",
"if",
"(",
"this",
".",
"description",
"!==",
"this",
".",
"type",
")",
"{",
"this",
".",
"message",
"+=",
"' ('",
"+",
"this",
".",
"description",
"+",
"')'",
"}",
"}",
"else",
"{",
"this",
".",
"message",
"=",
"this",
".",
"description",
"}",
"if",
"(",
"Error",
".",
"captureStackTrace",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"LoguxError",
")",
"}",
"}"
] |
Logux error in logs synchronization.
@param {string} type The error code.
@param {any} options The error option.
@param {boolean} received Was error received from remote node.
@example
if (error.name === 'LoguxError') {
console.log('Server throws: ' + error.description)
}
@extends Error
@class
|
[
"Logux",
"error",
"in",
"logs",
"synchronization",
"."
] |
fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23
|
https://github.com/logux/core/blob/fd5ab2eddd0b7ec8fa77ba55e8a30e5cad09ab23/logux-error.js#L16-L78
|
18,256
|
azuqua/cassanknex
|
schema/keyspaceBuilder.js
|
_getStrategyGrouping
|
function _getStrategyGrouping(_class) {
return function () {
var replicationParams = _.toArray(arguments)
, replication = {"class": _class};
if (_class === methods.withSimpleStrategy.name) {
if (typeof replicationParams[0] === "undefined")
throw new Error("SimpleStrategy requires replication parameters.");
replication.replication_factor = replicationParams[0];
}
else if (_class === methods.withNetworkTopologyStrategy.name) {
var filter = function (param) {
return typeof param === "object" && Object.keys(param).length >= 1;
};
var dataCenterParams = _.filter(arguments, filter);
if (!dataCenterParams.length)
throw new Error("NetworkTopologyStrategy requires a variable length argument list of data center param objecs => '{ dataCenterName: dataCenterReplicationFactor }'.");
_.each(dataCenterParams, function (dataCenterParam) {
_.each(Object.keys(dataCenterParam), function (k) {
replication[k] = dataCenterParam[k];
});
});
}
this._statements.push({
grouping: "strategy",
type: methods[nameToCallMap[_class]].name,
value: replication
});
return this;
};
}
|
javascript
|
function _getStrategyGrouping(_class) {
return function () {
var replicationParams = _.toArray(arguments)
, replication = {"class": _class};
if (_class === methods.withSimpleStrategy.name) {
if (typeof replicationParams[0] === "undefined")
throw new Error("SimpleStrategy requires replication parameters.");
replication.replication_factor = replicationParams[0];
}
else if (_class === methods.withNetworkTopologyStrategy.name) {
var filter = function (param) {
return typeof param === "object" && Object.keys(param).length >= 1;
};
var dataCenterParams = _.filter(arguments, filter);
if (!dataCenterParams.length)
throw new Error("NetworkTopologyStrategy requires a variable length argument list of data center param objecs => '{ dataCenterName: dataCenterReplicationFactor }'.");
_.each(dataCenterParams, function (dataCenterParam) {
_.each(Object.keys(dataCenterParam), function (k) {
replication[k] = dataCenterParam[k];
});
});
}
this._statements.push({
grouping: "strategy",
type: methods[nameToCallMap[_class]].name,
value: replication
});
return this;
};
}
|
[
"function",
"_getStrategyGrouping",
"(",
"_class",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"replicationParams",
"=",
"_",
".",
"toArray",
"(",
"arguments",
")",
",",
"replication",
"=",
"{",
"\"class\"",
":",
"_class",
"}",
";",
"if",
"(",
"_class",
"===",
"methods",
".",
"withSimpleStrategy",
".",
"name",
")",
"{",
"if",
"(",
"typeof",
"replicationParams",
"[",
"0",
"]",
"===",
"\"undefined\"",
")",
"throw",
"new",
"Error",
"(",
"\"SimpleStrategy requires replication parameters.\"",
")",
";",
"replication",
".",
"replication_factor",
"=",
"replicationParams",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"_class",
"===",
"methods",
".",
"withNetworkTopologyStrategy",
".",
"name",
")",
"{",
"var",
"filter",
"=",
"function",
"(",
"param",
")",
"{",
"return",
"typeof",
"param",
"===",
"\"object\"",
"&&",
"Object",
".",
"keys",
"(",
"param",
")",
".",
"length",
">=",
"1",
";",
"}",
";",
"var",
"dataCenterParams",
"=",
"_",
".",
"filter",
"(",
"arguments",
",",
"filter",
")",
";",
"if",
"(",
"!",
"dataCenterParams",
".",
"length",
")",
"throw",
"new",
"Error",
"(",
"\"NetworkTopologyStrategy requires a variable length argument list of data center param objecs => '{ dataCenterName: dataCenterReplicationFactor }'.\"",
")",
";",
"_",
".",
"each",
"(",
"dataCenterParams",
",",
"function",
"(",
"dataCenterParam",
")",
"{",
"_",
".",
"each",
"(",
"Object",
".",
"keys",
"(",
"dataCenterParam",
")",
",",
"function",
"(",
"k",
")",
"{",
"replication",
"[",
"k",
"]",
"=",
"dataCenterParam",
"[",
"k",
"]",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"\"strategy\"",
",",
"type",
":",
"methods",
"[",
"nameToCallMap",
"[",
"_class",
"]",
"]",
".",
"name",
",",
"value",
":",
"replication",
"}",
")",
";",
"return",
"this",
";",
"}",
";",
"}"
] |
Returns function used to build the `with replication` clause in a create keyspace statement
@param _class
@returns {Function}
@private
|
[
"Returns",
"function",
"used",
"to",
"build",
"the",
"with",
"replication",
"clause",
"in",
"a",
"create",
"keyspace",
"statement"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/schema/keyspaceBuilder.js#L41-L78
|
18,257
|
azuqua/cassanknex
|
schema/keyspaceBuilder.js
|
_getAndGrouping
|
function _getAndGrouping(type) {
return function () {
var boolean = _.toArray(arguments);
this._statements.push({
grouping: "and",
type: type,
value: arguments[0] ? arguments[0] : false
});
return this;
};
}
|
javascript
|
function _getAndGrouping(type) {
return function () {
var boolean = _.toArray(arguments);
this._statements.push({
grouping: "and",
type: type,
value: arguments[0] ? arguments[0] : false
});
return this;
};
}
|
[
"function",
"_getAndGrouping",
"(",
"type",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"boolean",
"=",
"_",
".",
"toArray",
"(",
"arguments",
")",
";",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"\"and\"",
",",
"type",
":",
"type",
",",
"value",
":",
"arguments",
"[",
"0",
"]",
"?",
"arguments",
"[",
"0",
"]",
":",
"false",
"}",
")",
";",
"return",
"this",
";",
"}",
";",
"}"
] |
returns function used to build the `and` clause of a create keyspace statement
@param type
@returns {Function}
@private
|
[
"returns",
"function",
"used",
"to",
"build",
"the",
"and",
"clause",
"of",
"a",
"create",
"keyspace",
"statement"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/schema/keyspaceBuilder.js#L87-L99
|
18,258
|
azuqua/cassanknex
|
index.js
|
_attachExecMethod
|
function _attachExecMethod(qb) {
/**
* Create the exec function for a pass through to the datastax driver.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Function} cb` => function(err, result) {}
* @returns {Client|exports|module.exports}
*/
qb.exec = function (options, cb) {
var _options = typeof options !== "undefined" && _.isFunction(options) ? {} : options
, _cb;
if (!_.has(_options, "prepare")) {
_options.prepare = qb._execPrepare;
}
if (_.isFunction(options)) {
_cb = options;
}
else if (_.isFunction(cb)) {
_cb = cb;
}
else {
_cb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.execute(cql, qb.bindings(), _options, _cb);
}
else {
_cb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
javascript
|
function _attachExecMethod(qb) {
/**
* Create the exec function for a pass through to the datastax driver.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Function} cb` => function(err, result) {}
* @returns {Client|exports|module.exports}
*/
qb.exec = function (options, cb) {
var _options = typeof options !== "undefined" && _.isFunction(options) ? {} : options
, _cb;
if (!_.has(_options, "prepare")) {
_options.prepare = qb._execPrepare;
}
if (_.isFunction(options)) {
_cb = options;
}
else if (_.isFunction(cb)) {
_cb = cb;
}
else {
_cb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.execute(cql, qb.bindings(), _options, _cb);
}
else {
_cb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
[
"function",
"_attachExecMethod",
"(",
"qb",
")",
"{",
"/**\n * Create the exec function for a pass through to the datastax driver.\n *\n * @param `{Object} options` optional argument passed to datastax driver upon query execution\n * @param `{Function} cb` => function(err, result) {}\n * @returns {Client|exports|module.exports}\n */",
"qb",
".",
"exec",
"=",
"function",
"(",
"options",
",",
"cb",
")",
"{",
"var",
"_options",
"=",
"typeof",
"options",
"!==",
"\"undefined\"",
"&&",
"_",
".",
"isFunction",
"(",
"options",
")",
"?",
"{",
"}",
":",
"options",
",",
"_cb",
";",
"if",
"(",
"!",
"_",
".",
"has",
"(",
"_options",
",",
"\"prepare\"",
")",
")",
"{",
"_options",
".",
"prepare",
"=",
"qb",
".",
"_execPrepare",
";",
"}",
"if",
"(",
"_",
".",
"isFunction",
"(",
"options",
")",
")",
"{",
"_cb",
"=",
"options",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isFunction",
"(",
"cb",
")",
")",
"{",
"_cb",
"=",
"cb",
";",
"}",
"else",
"{",
"_cb",
"=",
"_",
".",
"noop",
";",
"}",
"if",
"(",
"cassandra",
"!==",
"null",
"&&",
"cassandra",
".",
"connected",
")",
"{",
"var",
"cql",
"=",
"qb",
".",
"cql",
"(",
")",
";",
"cassandra",
".",
"execute",
"(",
"cql",
",",
"qb",
".",
"bindings",
"(",
")",
",",
"_options",
",",
"_cb",
")",
";",
"}",
"else",
"{",
"_cb",
"(",
"new",
"Error",
"(",
"\"Cassandra client is not initialized.\"",
")",
")",
";",
"}",
"// maintain chain",
"return",
"qb",
";",
"}",
";",
"}"
] |
hooks the 'exec' cassandra client method to our query builder object
@param qb
@private
|
[
"hooks",
"the",
"exec",
"cassandra",
"client",
"method",
"to",
"our",
"query",
"builder",
"object"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/index.js#L132-L170
|
18,259
|
azuqua/cassanknex
|
index.js
|
_attachStreamMethod
|
function _attachStreamMethod(qb) {
/**
* Create the stream function for a pass through to the datastax driver,
* all callbacks are defaulted to lodash#noop if not declared.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Object} cbs` =>
* {
* readable: function() {},
* end: function() {},
* error: function(err) {}
* }
* @returns {Client|exports|module.exports}
*/
qb.stream = function (options, cbs) {
var _options = _.isObject(cbs) ? options : {}
, _cbs = _.isObject(cbs) ? cbs : options
, onReadable = _cbs.readable || _.noop
, onEnd = _cbs.end || _.noop
, onError = _cbs.error || _.noop;
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.stream(cql, qb.bindings(), _options)
.on("readable", onReadable)
.on("end", onEnd)
.on("error", onError);
}
else {
console.error("Cassandra client is not initialized.");
onError(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
javascript
|
function _attachStreamMethod(qb) {
/**
* Create the stream function for a pass through to the datastax driver,
* all callbacks are defaulted to lodash#noop if not declared.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Object} cbs` =>
* {
* readable: function() {},
* end: function() {},
* error: function(err) {}
* }
* @returns {Client|exports|module.exports}
*/
qb.stream = function (options, cbs) {
var _options = _.isObject(cbs) ? options : {}
, _cbs = _.isObject(cbs) ? cbs : options
, onReadable = _cbs.readable || _.noop
, onEnd = _cbs.end || _.noop
, onError = _cbs.error || _.noop;
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.stream(cql, qb.bindings(), _options)
.on("readable", onReadable)
.on("end", onEnd)
.on("error", onError);
}
else {
console.error("Cassandra client is not initialized.");
onError(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
[
"function",
"_attachStreamMethod",
"(",
"qb",
")",
"{",
"/**\n * Create the stream function for a pass through to the datastax driver,\n * all callbacks are defaulted to lodash#noop if not declared.\n *\n * @param `{Object} options` optional argument passed to datastax driver upon query execution\n * @param `{Object} cbs` =>\n * {\n * readable: function() {},\n * end: function() {},\n * error: function(err) {}\n * }\n * @returns {Client|exports|module.exports}\n */",
"qb",
".",
"stream",
"=",
"function",
"(",
"options",
",",
"cbs",
")",
"{",
"var",
"_options",
"=",
"_",
".",
"isObject",
"(",
"cbs",
")",
"?",
"options",
":",
"{",
"}",
",",
"_cbs",
"=",
"_",
".",
"isObject",
"(",
"cbs",
")",
"?",
"cbs",
":",
"options",
",",
"onReadable",
"=",
"_cbs",
".",
"readable",
"||",
"_",
".",
"noop",
",",
"onEnd",
"=",
"_cbs",
".",
"end",
"||",
"_",
".",
"noop",
",",
"onError",
"=",
"_cbs",
".",
"error",
"||",
"_",
".",
"noop",
";",
"if",
"(",
"cassandra",
"!==",
"null",
"&&",
"cassandra",
".",
"connected",
")",
"{",
"var",
"cql",
"=",
"qb",
".",
"cql",
"(",
")",
";",
"cassandra",
".",
"stream",
"(",
"cql",
",",
"qb",
".",
"bindings",
"(",
")",
",",
"_options",
")",
".",
"on",
"(",
"\"readable\"",
",",
"onReadable",
")",
".",
"on",
"(",
"\"end\"",
",",
"onEnd",
")",
".",
"on",
"(",
"\"error\"",
",",
"onError",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"Cassandra client is not initialized.\"",
")",
";",
"onError",
"(",
"new",
"Error",
"(",
"\"Cassandra client is not initialized.\"",
")",
")",
";",
"}",
"// maintain chain",
"return",
"qb",
";",
"}",
";",
"}"
] |
hooks the 'stream' cassandra client method to our query builder object
@param qb
@private
|
[
"hooks",
"the",
"stream",
"cassandra",
"client",
"method",
"to",
"our",
"query",
"builder",
"object"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/index.js#L177-L214
|
18,260
|
azuqua/cassanknex
|
index.js
|
_attachEachRowMethod
|
function _attachEachRowMethod(qb) {
/**
* Create the eachRow function for a pass through to the datastax driver.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Function} rowCb` => function(row) {}
* @param `{Function} errorCb` => function(err) {}
* @returns {Client|exports|module.exports}
*/
qb.eachRow = function (options, rowCb, errorCb) {
// options is really rowCB
if (_.isFunction(options)) {
errorCb = rowCb;
rowCb = options;
}
var _options = _.isObject(options) ? options : {};
if (!_.isFunction(rowCb)) {
rowCb = _.noop;
}
if (!_.isFunction(errorCb)) {
errorCb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.eachRow(cql, qb.bindings(), _options, rowCb, errorCb);
}
else {
errorCb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
javascript
|
function _attachEachRowMethod(qb) {
/**
* Create the eachRow function for a pass through to the datastax driver.
*
* @param `{Object} options` optional argument passed to datastax driver upon query execution
* @param `{Function} rowCb` => function(row) {}
* @param `{Function} errorCb` => function(err) {}
* @returns {Client|exports|module.exports}
*/
qb.eachRow = function (options, rowCb, errorCb) {
// options is really rowCB
if (_.isFunction(options)) {
errorCb = rowCb;
rowCb = options;
}
var _options = _.isObject(options) ? options : {};
if (!_.isFunction(rowCb)) {
rowCb = _.noop;
}
if (!_.isFunction(errorCb)) {
errorCb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var cql = qb.cql();
cassandra.eachRow(cql, qb.bindings(), _options, rowCb, errorCb);
}
else {
errorCb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
[
"function",
"_attachEachRowMethod",
"(",
"qb",
")",
"{",
"/**\n * Create the eachRow function for a pass through to the datastax driver.\n *\n * @param `{Object} options` optional argument passed to datastax driver upon query execution\n * @param `{Function} rowCb` => function(row) {}\n * @param `{Function} errorCb` => function(err) {}\n * @returns {Client|exports|module.exports}\n */",
"qb",
".",
"eachRow",
"=",
"function",
"(",
"options",
",",
"rowCb",
",",
"errorCb",
")",
"{",
"// options is really rowCB",
"if",
"(",
"_",
".",
"isFunction",
"(",
"options",
")",
")",
"{",
"errorCb",
"=",
"rowCb",
";",
"rowCb",
"=",
"options",
";",
"}",
"var",
"_options",
"=",
"_",
".",
"isObject",
"(",
"options",
")",
"?",
"options",
":",
"{",
"}",
";",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"rowCb",
")",
")",
"{",
"rowCb",
"=",
"_",
".",
"noop",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"errorCb",
")",
")",
"{",
"errorCb",
"=",
"_",
".",
"noop",
";",
"}",
"if",
"(",
"cassandra",
"!==",
"null",
"&&",
"cassandra",
".",
"connected",
")",
"{",
"var",
"cql",
"=",
"qb",
".",
"cql",
"(",
")",
";",
"cassandra",
".",
"eachRow",
"(",
"cql",
",",
"qb",
".",
"bindings",
"(",
")",
",",
"_options",
",",
"rowCb",
",",
"errorCb",
")",
";",
"}",
"else",
"{",
"errorCb",
"(",
"new",
"Error",
"(",
"\"Cassandra client is not initialized.\"",
")",
")",
";",
"}",
"// maintain chain",
"return",
"qb",
";",
"}",
";",
"}"
] |
hooks the 'eachRow' cassandra client method to our query builder object
@param qb
@private
|
[
"hooks",
"the",
"eachRow",
"cassandra",
"client",
"method",
"to",
"our",
"query",
"builder",
"object"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/index.js#L221-L258
|
18,261
|
azuqua/cassanknex
|
index.js
|
_attachBatchMethod
|
function _attachBatchMethod(qb) {
/**
*
* @param options
* @param cassakni
* @param cb
* @returns {Client|exports|module.exports}
*/
qb.batch = function (options, cassakni, cb) {
var _options
, _cassakni
, _cb;
// options is really cassakni, cassakni is cb
if (_.isArray(options)) {
_options = {};
_cassakni = options;
_cb = cassakni;
}
// standard order
else {
_options = options;
_cassakni = cassakni;
_cb = cb;
}
if (!_.isFunction(_cb)) {
_cb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var error = null
, statements = _.map(_cassakni, function (qb) {
if (!qb.toString || qb.toString() !== duckType) {
error = new Error("Invalid input to CassanKnex#batch.");
return {};
}
else {
return {query: qb.cql(), params: qb.bindings()};
}
});
if (error) {
return _cb(error);
}
cassandra.batch(statements, _options, _cb);
}
else {
_cb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
javascript
|
function _attachBatchMethod(qb) {
/**
*
* @param options
* @param cassakni
* @param cb
* @returns {Client|exports|module.exports}
*/
qb.batch = function (options, cassakni, cb) {
var _options
, _cassakni
, _cb;
// options is really cassakni, cassakni is cb
if (_.isArray(options)) {
_options = {};
_cassakni = options;
_cb = cassakni;
}
// standard order
else {
_options = options;
_cassakni = cassakni;
_cb = cb;
}
if (!_.isFunction(_cb)) {
_cb = _.noop;
}
if (cassandra !== null && cassandra.connected) {
var error = null
, statements = _.map(_cassakni, function (qb) {
if (!qb.toString || qb.toString() !== duckType) {
error = new Error("Invalid input to CassanKnex#batch.");
return {};
}
else {
return {query: qb.cql(), params: qb.bindings()};
}
});
if (error) {
return _cb(error);
}
cassandra.batch(statements, _options, _cb);
}
else {
_cb(new Error("Cassandra client is not initialized."));
}
// maintain chain
return qb;
};
}
|
[
"function",
"_attachBatchMethod",
"(",
"qb",
")",
"{",
"/**\n *\n * @param options\n * @param cassakni\n * @param cb\n * @returns {Client|exports|module.exports}\n */",
"qb",
".",
"batch",
"=",
"function",
"(",
"options",
",",
"cassakni",
",",
"cb",
")",
"{",
"var",
"_options",
",",
"_cassakni",
",",
"_cb",
";",
"// options is really cassakni, cassakni is cb",
"if",
"(",
"_",
".",
"isArray",
"(",
"options",
")",
")",
"{",
"_options",
"=",
"{",
"}",
";",
"_cassakni",
"=",
"options",
";",
"_cb",
"=",
"cassakni",
";",
"}",
"// standard order",
"else",
"{",
"_options",
"=",
"options",
";",
"_cassakni",
"=",
"cassakni",
";",
"_cb",
"=",
"cb",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"_cb",
")",
")",
"{",
"_cb",
"=",
"_",
".",
"noop",
";",
"}",
"if",
"(",
"cassandra",
"!==",
"null",
"&&",
"cassandra",
".",
"connected",
")",
"{",
"var",
"error",
"=",
"null",
",",
"statements",
"=",
"_",
".",
"map",
"(",
"_cassakni",
",",
"function",
"(",
"qb",
")",
"{",
"if",
"(",
"!",
"qb",
".",
"toString",
"||",
"qb",
".",
"toString",
"(",
")",
"!==",
"duckType",
")",
"{",
"error",
"=",
"new",
"Error",
"(",
"\"Invalid input to CassanKnex#batch.\"",
")",
";",
"return",
"{",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"query",
":",
"qb",
".",
"cql",
"(",
")",
",",
"params",
":",
"qb",
".",
"bindings",
"(",
")",
"}",
";",
"}",
"}",
")",
";",
"if",
"(",
"error",
")",
"{",
"return",
"_cb",
"(",
"error",
")",
";",
"}",
"cassandra",
".",
"batch",
"(",
"statements",
",",
"_options",
",",
"_cb",
")",
";",
"}",
"else",
"{",
"_cb",
"(",
"new",
"Error",
"(",
"\"Cassandra client is not initialized.\"",
")",
")",
";",
"}",
"// maintain chain",
"return",
"qb",
";",
"}",
";",
"}"
] |
hooks the 'batch' cassandra client method to our query builder object
@param qb
@private
|
[
"hooks",
"the",
"batch",
"cassandra",
"client",
"method",
"to",
"our",
"query",
"builder",
"object"
] |
341826b8a4b99042abba4032058131967629e110
|
https://github.com/azuqua/cassanknex/blob/341826b8a4b99042abba4032058131967629e110/index.js#L265-L323
|
18,262
|
vue-typed/vue-typed
|
gulpfile.js
|
startWatch
|
function startWatch() {
var rp = path.join(rootPath, '/**/*.md')
watcher = gulp.watch([rp, '!' + rp + '/_book/'], function() {
rebuildBook(reload)
})
return watcher
}
|
javascript
|
function startWatch() {
var rp = path.join(rootPath, '/**/*.md')
watcher = gulp.watch([rp, '!' + rp + '/_book/'], function() {
rebuildBook(reload)
})
return watcher
}
|
[
"function",
"startWatch",
"(",
")",
"{",
"var",
"rp",
"=",
"path",
".",
"join",
"(",
"rootPath",
",",
"'/**/*.md'",
")",
"watcher",
"=",
"gulp",
".",
"watch",
"(",
"[",
"rp",
",",
"'!'",
"+",
"rp",
"+",
"'/_book/'",
"]",
",",
"function",
"(",
")",
"{",
"rebuildBook",
"(",
"reload",
")",
"}",
")",
"return",
"watcher",
"}"
] |
start watching md files + when files changed reload browser
|
[
"start",
"watching",
"md",
"files",
"+",
"when",
"files",
"changed",
"reload",
"browser"
] |
c7946ef5091a9edba6402b9a72bd80df33f4c651
|
https://github.com/vue-typed/vue-typed/blob/c7946ef5091a9edba6402b9a72bd80df33f4c651/gulpfile.js#L68-L74
|
18,263
|
jsvine/notebookjs
|
notebook.js
|
function (format) {
return function (data) {
var el = makeElement("img", [ "image-output" ]);
el.src = "data:image/" + format + ";base64," + joinText(data).replace(/\n/g, "");
return el;
};
}
|
javascript
|
function (format) {
return function (data) {
var el = makeElement("img", [ "image-output" ]);
el.src = "data:image/" + format + ";base64," + joinText(data).replace(/\n/g, "");
return el;
};
}
|
[
"function",
"(",
"format",
")",
"{",
"return",
"function",
"(",
"data",
")",
"{",
"var",
"el",
"=",
"makeElement",
"(",
"\"img\"",
",",
"[",
"\"image-output\"",
"]",
")",
";",
"el",
".",
"src",
"=",
"\"data:image/\"",
"+",
"format",
"+",
"\";base64,\"",
"+",
"joinText",
"(",
"data",
")",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"\"\"",
")",
";",
"return",
"el",
";",
"}",
";",
"}"
] |
Outputs and output-renderers
|
[
"Outputs",
"and",
"output",
"-",
"renderers"
] |
b594a4046b864722a147632d2abd08f94f8393ed
|
https://github.com/jsvine/notebookjs/blob/b594a4046b864722a147632d2abd08f94f8393ed/notebook.js#L92-L98
|
|
18,264
|
appium/appium-doctor
|
lib/utils.js
|
resolveExecutablePath
|
async function resolveExecutablePath (cmd) {
let executablePath;
try {
executablePath = await fs.which(cmd);
if (executablePath && await fs.exists(executablePath)) {
return executablePath;
}
} catch (err) {
if ((/not found/gi).test(err.message)) {
log.debug(err);
} else {
log.warn(err);
}
}
log.debug(`No executable path of '${cmd}'.`);
if (executablePath) {
log.debug(`Does '${executablePath}' exist?`);
}
return null;
}
|
javascript
|
async function resolveExecutablePath (cmd) {
let executablePath;
try {
executablePath = await fs.which(cmd);
if (executablePath && await fs.exists(executablePath)) {
return executablePath;
}
} catch (err) {
if ((/not found/gi).test(err.message)) {
log.debug(err);
} else {
log.warn(err);
}
}
log.debug(`No executable path of '${cmd}'.`);
if (executablePath) {
log.debug(`Does '${executablePath}' exist?`);
}
return null;
}
|
[
"async",
"function",
"resolveExecutablePath",
"(",
"cmd",
")",
"{",
"let",
"executablePath",
";",
"try",
"{",
"executablePath",
"=",
"await",
"fs",
".",
"which",
"(",
"cmd",
")",
";",
"if",
"(",
"executablePath",
"&&",
"await",
"fs",
".",
"exists",
"(",
"executablePath",
")",
")",
"{",
"return",
"executablePath",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"(",
"/",
"not found",
"/",
"gi",
")",
".",
"test",
"(",
"err",
".",
"message",
")",
")",
"{",
"log",
".",
"debug",
"(",
"err",
")",
";",
"}",
"else",
"{",
"log",
".",
"warn",
"(",
"err",
")",
";",
"}",
"}",
"log",
".",
"debug",
"(",
"`",
"${",
"cmd",
"}",
"`",
")",
";",
"if",
"(",
"executablePath",
")",
"{",
"log",
".",
"debug",
"(",
"`",
"${",
"executablePath",
"}",
"`",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Return an executable path of cmd
@param {string} cmd Standard output by command
@return {?string} The full path of cmd. `null` if the cmd is not found.
|
[
"Return",
"an",
"executable",
"path",
"of",
"cmd"
] |
c00f604047b2addb7c544e12ddb524169bf8067e
|
https://github.com/appium/appium-doctor/blob/c00f604047b2addb7c544e12ddb524169bf8067e/lib/utils.js#L42-L61
|
18,265
|
AFASSoftware/maquette
|
website/source/tutorial/assets/saucer-orbit.js
|
tick
|
function tick() {
var moment = (new Date().getTime() - startDate)/1000;
x = Math.round(150 * Math.sin(moment));
y = Math.round(150 * Math.cos(moment));
requestAnimationFrame(tick);
}
|
javascript
|
function tick() {
var moment = (new Date().getTime() - startDate)/1000;
x = Math.round(150 * Math.sin(moment));
y = Math.round(150 * Math.cos(moment));
requestAnimationFrame(tick);
}
|
[
"function",
"tick",
"(",
")",
"{",
"var",
"moment",
"=",
"(",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
"-",
"startDate",
")",
"/",
"1000",
";",
"x",
"=",
"Math",
".",
"round",
"(",
"150",
"*",
"Math",
".",
"sin",
"(",
"moment",
")",
")",
";",
"y",
"=",
"Math",
".",
"round",
"(",
"150",
"*",
"Math",
".",
"cos",
"(",
"moment",
")",
")",
";",
"requestAnimationFrame",
"(",
"tick",
")",
";",
"}"
] |
This function continually adjusts the saucer position
|
[
"This",
"function",
"continually",
"adjusts",
"the",
"saucer",
"position"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/website/source/tutorial/assets/saucer-orbit.js#L14-L19
|
18,266
|
AFASSoftware/maquette
|
examples/todomvc/js/components/todoListComponent.js
|
function (todo) {
model.remove(todo.id, function () {
todos.splice(todos.indexOf(todo), 1);
if (todo.completed) {
completedCount--;
} else {
itemsLeft--;
checkedAll = completedCount === todos.length;
}
});
}
|
javascript
|
function (todo) {
model.remove(todo.id, function () {
todos.splice(todos.indexOf(todo), 1);
if (todo.completed) {
completedCount--;
} else {
itemsLeft--;
checkedAll = completedCount === todos.length;
}
});
}
|
[
"function",
"(",
"todo",
")",
"{",
"model",
".",
"remove",
"(",
"todo",
".",
"id",
",",
"function",
"(",
")",
"{",
"todos",
".",
"splice",
"(",
"todos",
".",
"indexOf",
"(",
"todo",
")",
",",
"1",
")",
";",
"if",
"(",
"todo",
".",
"completed",
")",
"{",
"completedCount",
"--",
";",
"}",
"else",
"{",
"itemsLeft",
"--",
";",
"checkedAll",
"=",
"completedCount",
"===",
"todos",
".",
"length",
";",
"}",
"}",
")",
";",
"}"
] |
the todoComponent currently being edited
|
[
"the",
"todoComponent",
"currently",
"being",
"edited"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/components/todoListComponent.js#L97-L107
|
|
18,267
|
AFASSoftware/maquette
|
examples/todomvc/js/models/store.js
|
function (query, callback) {
if (!callback) {
return;
}
var todos = data.todos;
callback.call(undefined, todos.filter(function (todo) {
for (var q in query) {
if (query[q] !== todo[q]) {
return false;
}
}
return true;
}));
}
|
javascript
|
function (query, callback) {
if (!callback) {
return;
}
var todos = data.todos;
callback.call(undefined, todos.filter(function (todo) {
for (var q in query) {
if (query[q] !== todo[q]) {
return false;
}
}
return true;
}));
}
|
[
"function",
"(",
"query",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"callback",
")",
"{",
"return",
";",
"}",
"var",
"todos",
"=",
"data",
".",
"todos",
";",
"callback",
".",
"call",
"(",
"undefined",
",",
"todos",
".",
"filter",
"(",
"function",
"(",
"todo",
")",
"{",
"for",
"(",
"var",
"q",
"in",
"query",
")",
"{",
"if",
"(",
"query",
"[",
"q",
"]",
"!==",
"todo",
"[",
"q",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
")",
";",
"}"
] |
Finds items based on a query given as a JS object
@param {object} query The query to match against (i.e. {foo: 'bar'})
@param {function} callback The callback to fire when the query has
completed running
@example
db.find({foo: 'bar', hello: 'world'}, function (data) {
// data will return any items that have foo: bar and
// hello: world in their properties
});
|
[
"Finds",
"items",
"based",
"on",
"a",
"query",
"given",
"as",
"a",
"JS",
"object"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/store.js#L49-L64
|
|
18,268
|
AFASSoftware/maquette
|
examples/todomvc/js/models/store.js
|
function (updateData, callback, id) {
var todos = data.todos;
callback = callback || function () { };
// If an ID was actually given, find the item and update each property
if (id) {
for (var i = 0; i < todos.length; i++) {
if (todos[i].id === id) {
for (var key in updateData) {
todos[i][key] = updateData[key];
}
break;
}
}
flush();
callback.call(undefined, data.todos);
} else {
// Generate an ID
updateData.id = new Date().getTime();
todos.push(updateData);
flush();
callback.call(undefined, [updateData]);
}
}
|
javascript
|
function (updateData, callback, id) {
var todos = data.todos;
callback = callback || function () { };
// If an ID was actually given, find the item and update each property
if (id) {
for (var i = 0; i < todos.length; i++) {
if (todos[i].id === id) {
for (var key in updateData) {
todos[i][key] = updateData[key];
}
break;
}
}
flush();
callback.call(undefined, data.todos);
} else {
// Generate an ID
updateData.id = new Date().getTime();
todos.push(updateData);
flush();
callback.call(undefined, [updateData]);
}
}
|
[
"function",
"(",
"updateData",
",",
"callback",
",",
"id",
")",
"{",
"var",
"todos",
"=",
"data",
".",
"todos",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"// If an ID was actually given, find the item and update each property",
"if",
"(",
"id",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"todos",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"todos",
"[",
"i",
"]",
".",
"id",
"===",
"id",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"updateData",
")",
"{",
"todos",
"[",
"i",
"]",
"[",
"key",
"]",
"=",
"updateData",
"[",
"key",
"]",
";",
"}",
"break",
";",
"}",
"}",
"flush",
"(",
")",
";",
"callback",
".",
"call",
"(",
"undefined",
",",
"data",
".",
"todos",
")",
";",
"}",
"else",
"{",
"// Generate an ID",
"updateData",
".",
"id",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"todos",
".",
"push",
"(",
"updateData",
")",
";",
"flush",
"(",
")",
";",
"callback",
".",
"call",
"(",
"undefined",
",",
"[",
"updateData",
"]",
")",
";",
"}",
"}"
] |
Will save the given data to the DB. If no item exists it will create a new
item, otherwise it'll simply update an existing item's properties
@param {object} updateData The data to save back into the DB
@param {function} callback The callback to fire after saving
@param {number} id An optional param to enter an ID of an item to update
|
[
"Will",
"save",
"the",
"given",
"data",
"to",
"the",
"DB",
".",
"If",
"no",
"item",
"exists",
"it",
"will",
"create",
"a",
"new",
"item",
"otherwise",
"it",
"ll",
"simply",
"update",
"an",
"existing",
"item",
"s",
"properties"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/store.js#L84-L111
|
|
18,269
|
AFASSoftware/maquette
|
examples/todomvc/js/models/store.js
|
function (id, callback) {
var todos = data.todos;
for (var i = 0; i < todos.length; i++) {
if (todos[i].id == id) {
todos.splice(i, 1);
break;
}
}
flush();
callback.call(undefined, data.todos);
}
|
javascript
|
function (id, callback) {
var todos = data.todos;
for (var i = 0; i < todos.length; i++) {
if (todos[i].id == id) {
todos.splice(i, 1);
break;
}
}
flush();
callback.call(undefined, data.todos);
}
|
[
"function",
"(",
"id",
",",
"callback",
")",
"{",
"var",
"todos",
"=",
"data",
".",
"todos",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"todos",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"todos",
"[",
"i",
"]",
".",
"id",
"==",
"id",
")",
"{",
"todos",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"flush",
"(",
")",
";",
"callback",
".",
"call",
"(",
"undefined",
",",
"data",
".",
"todos",
")",
";",
"}"
] |
Will remove an item from the Store based on its ID
@param {number} id The ID of the item you want to remove
@param {function} callback The callback to fire after saving
|
[
"Will",
"remove",
"an",
"item",
"from",
"the",
"Store",
"based",
"on",
"its",
"ID"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/store.js#L119-L131
|
|
18,270
|
AFASSoftware/maquette
|
examples/tonic-example.js
|
render
|
function render() {
return h('div', [
h('input', {
type: 'text', placeholder: 'What is your name?',
value: yourName, oninput: handleNameInput
}),
h('p.output', ['Hello ' + (yourName || 'you') + '!'])
]);
}
|
javascript
|
function render() {
return h('div', [
h('input', {
type: 'text', placeholder: 'What is your name?',
value: yourName, oninput: handleNameInput
}),
h('p.output', ['Hello ' + (yourName || 'you') + '!'])
]);
}
|
[
"function",
"render",
"(",
")",
"{",
"return",
"h",
"(",
"'div'",
",",
"[",
"h",
"(",
"'input'",
",",
"{",
"type",
":",
"'text'",
",",
"placeholder",
":",
"'What is your name?'",
",",
"value",
":",
"yourName",
",",
"oninput",
":",
"handleNameInput",
"}",
")",
",",
"h",
"(",
"'p.output'",
",",
"[",
"'Hello '",
"+",
"(",
"yourName",
"||",
"'you'",
")",
"+",
"'!'",
"]",
")",
"]",
")",
";",
"}"
] |
This function uses the 'hyperscript' notation to create the virtual DOM.
|
[
"This",
"function",
"uses",
"the",
"hyperscript",
"notation",
"to",
"create",
"the",
"virtual",
"DOM",
"."
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/tonic-example.js#L13-L21
|
18,271
|
AFASSoftware/maquette
|
examples/todomvc/js/models/model.js
|
function (title, callback) {
title = title || '';
callback = callback || function () { };
var newItem = {
title: title.trim(),
completed: false
};
storage.save(newItem, callback);
}
|
javascript
|
function (title, callback) {
title = title || '';
callback = callback || function () { };
var newItem = {
title: title.trim(),
completed: false
};
storage.save(newItem, callback);
}
|
[
"function",
"(",
"title",
",",
"callback",
")",
"{",
"title",
"=",
"title",
"||",
"''",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"newItem",
"=",
"{",
"title",
":",
"title",
".",
"trim",
"(",
")",
",",
"completed",
":",
"false",
"}",
";",
"storage",
".",
"save",
"(",
"newItem",
",",
"callback",
")",
";",
"}"
] |
Creates a new todo model
@param {string} [title] The title of the task
@param {function} [callback] The callback to fire after the model is created
|
[
"Creates",
"a",
"new",
"todo",
"model"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/model.js#L20-L30
|
|
18,272
|
AFASSoftware/maquette
|
examples/todomvc/js/models/model.js
|
function (query, callback) {
var queryType = typeof query;
callback = callback || function () { };
if (queryType === 'function') {
callback = query;
storage.findAll(callback);
} else if (queryType === 'string' || queryType === 'number') {
query = parseInt(query, 10);
storage.find({ id: query }, callback);
} else {
storage.find(query, callback);
}
}
|
javascript
|
function (query, callback) {
var queryType = typeof query;
callback = callback || function () { };
if (queryType === 'function') {
callback = query;
storage.findAll(callback);
} else if (queryType === 'string' || queryType === 'number') {
query = parseInt(query, 10);
storage.find({ id: query }, callback);
} else {
storage.find(query, callback);
}
}
|
[
"function",
"(",
"query",
",",
"callback",
")",
"{",
"var",
"queryType",
"=",
"typeof",
"query",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"if",
"(",
"queryType",
"===",
"'function'",
")",
"{",
"callback",
"=",
"query",
";",
"storage",
".",
"findAll",
"(",
"callback",
")",
";",
"}",
"else",
"if",
"(",
"queryType",
"===",
"'string'",
"||",
"queryType",
"===",
"'number'",
")",
"{",
"query",
"=",
"parseInt",
"(",
"query",
",",
"10",
")",
";",
"storage",
".",
"find",
"(",
"{",
"id",
":",
"query",
"}",
",",
"callback",
")",
";",
"}",
"else",
"{",
"storage",
".",
"find",
"(",
"query",
",",
"callback",
")",
";",
"}",
"}"
] |
Finds and returns a model in storage. If no query is given it'll simply
return everything. If you pass in a string or number it'll look that up as
the ID of the model to find. Lastly, you can pass it an object to match
against.
@param {string|number|object} [query] A query to match models against
@param {function} [callback] The callback to fire after the model is found
@example
model.read(1, func); // Will find the model with an ID of 1
model.read('1'); // Same as above
//Below will find a model with foo equalling bar and hello equalling world.
model.read({ foo: 'bar', hello: 'world' });
|
[
"Finds",
"and",
"returns",
"a",
"model",
"in",
"storage",
".",
"If",
"no",
"query",
"is",
"given",
"it",
"ll",
"simply",
"return",
"everything",
".",
"If",
"you",
"pass",
"in",
"a",
"string",
"or",
"number",
"it",
"ll",
"look",
"that",
"up",
"as",
"the",
"ID",
"of",
"the",
"model",
"to",
"find",
".",
"Lastly",
"you",
"can",
"pass",
"it",
"an",
"object",
"to",
"match",
"against",
"."
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/model.js#L47-L60
|
|
18,273
|
AFASSoftware/maquette
|
examples/todomvc/js/models/model.js
|
function (callback) {
var todos = {
active: 0,
completed: 0,
total: 0
};
storage.findAll(function (data) {
data.forEach(function (todo) {
if (todo.completed) {
todos.completed++;
} else {
todos.active++;
}
todos.total++;
});
callback(todos);
});
}
|
javascript
|
function (callback) {
var todos = {
active: 0,
completed: 0,
total: 0
};
storage.findAll(function (data) {
data.forEach(function (todo) {
if (todo.completed) {
todos.completed++;
} else {
todos.active++;
}
todos.total++;
});
callback(todos);
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"todos",
"=",
"{",
"active",
":",
"0",
",",
"completed",
":",
"0",
",",
"total",
":",
"0",
"}",
";",
"storage",
".",
"findAll",
"(",
"function",
"(",
"data",
")",
"{",
"data",
".",
"forEach",
"(",
"function",
"(",
"todo",
")",
"{",
"if",
"(",
"todo",
".",
"completed",
")",
"{",
"todos",
".",
"completed",
"++",
";",
"}",
"else",
"{",
"todos",
".",
"active",
"++",
";",
"}",
"todos",
".",
"total",
"++",
";",
"}",
")",
";",
"callback",
"(",
"todos",
")",
";",
"}",
")",
";",
"}"
] |
Returns a count of all todos
|
[
"Returns",
"a",
"count",
"of",
"all",
"todos"
] |
a65ae617d5f04d4804a2b4dc40263d0a90cd2c10
|
https://github.com/AFASSoftware/maquette/blob/a65ae617d5f04d4804a2b4dc40263d0a90cd2c10/examples/todomvc/js/models/model.js#L96-L115
|
|
18,274
|
mapbox/stylelint-processor-arbitrary-tags
|
index.js
|
isFileProcessable
|
function isFileProcessable(filepath) {
if (options.fileFilterRegex.length === 0) {
return true;
}
return options.fileFilterRegex.some((regex) => filepath.match(regex) !== null);
}
|
javascript
|
function isFileProcessable(filepath) {
if (options.fileFilterRegex.length === 0) {
return true;
}
return options.fileFilterRegex.some((regex) => filepath.match(regex) !== null);
}
|
[
"function",
"isFileProcessable",
"(",
"filepath",
")",
"{",
"if",
"(",
"options",
".",
"fileFilterRegex",
".",
"length",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"return",
"options",
".",
"fileFilterRegex",
".",
"some",
"(",
"(",
"regex",
")",
"=>",
"filepath",
".",
"match",
"(",
"regex",
")",
"!==",
"null",
")",
";",
"}"
] |
Checks whether the given file is allowed by the filter
|
[
"Checks",
"whether",
"the",
"given",
"file",
"is",
"allowed",
"by",
"the",
"filter"
] |
f453dd4d43a656e6acca17a1bb997a5187942132
|
https://github.com/mapbox/stylelint-processor-arbitrary-tags/blob/f453dd4d43a656e6acca17a1bb997a5187942132/index.js#L21-L27
|
18,275
|
koajs/generic-session
|
src/session.js
|
session
|
async function session(ctx, next) {
ctx.sessionStore = store
if (ctx.session || ctx._session) {
return next()
}
const result = await getSession(ctx)
if (!result) {
return next()
}
addCommonAPI(ctx)
ctx._session = result.session
// more flexible
Object.defineProperty(ctx, 'session', {
get() {
return this._session
},
set(sess) {
this._session = sess
}
})
ctx.regenerateSession = async function regenerateSession() {
debug('regenerating session')
if (!result.isNew) {
// destroy the old session
debug('destroying previous session')
await store.destroy(ctx.sessionId)
}
ctx.session = generateSession()
ctx.sessionId = genSid.call(ctx, 24)
sessionIdStore.reset.call(ctx)
debug('created new session: %s', ctx.sessionId)
result.isNew = true
}
// make sure `refreshSession` always called
let firstError = null
try {
await next()
} catch (err) {
debug('next logic error: %s', err.message)
firstError = err
}
// can't use finally because `refreshSession` is async
try {
await refreshSession(ctx, ctx.session, result.originalHash, result.isNew)
} catch (err) {
debug('refresh session error: %s', err.message)
if (firstError) ctx.app.emit('error', err, ctx)
firstError = firstError || err
}
if (firstError) throw firstError
}
|
javascript
|
async function session(ctx, next) {
ctx.sessionStore = store
if (ctx.session || ctx._session) {
return next()
}
const result = await getSession(ctx)
if (!result) {
return next()
}
addCommonAPI(ctx)
ctx._session = result.session
// more flexible
Object.defineProperty(ctx, 'session', {
get() {
return this._session
},
set(sess) {
this._session = sess
}
})
ctx.regenerateSession = async function regenerateSession() {
debug('regenerating session')
if (!result.isNew) {
// destroy the old session
debug('destroying previous session')
await store.destroy(ctx.sessionId)
}
ctx.session = generateSession()
ctx.sessionId = genSid.call(ctx, 24)
sessionIdStore.reset.call(ctx)
debug('created new session: %s', ctx.sessionId)
result.isNew = true
}
// make sure `refreshSession` always called
let firstError = null
try {
await next()
} catch (err) {
debug('next logic error: %s', err.message)
firstError = err
}
// can't use finally because `refreshSession` is async
try {
await refreshSession(ctx, ctx.session, result.originalHash, result.isNew)
} catch (err) {
debug('refresh session error: %s', err.message)
if (firstError) ctx.app.emit('error', err, ctx)
firstError = firstError || err
}
if (firstError) throw firstError
}
|
[
"async",
"function",
"session",
"(",
"ctx",
",",
"next",
")",
"{",
"ctx",
".",
"sessionStore",
"=",
"store",
"if",
"(",
"ctx",
".",
"session",
"||",
"ctx",
".",
"_session",
")",
"{",
"return",
"next",
"(",
")",
"}",
"const",
"result",
"=",
"await",
"getSession",
"(",
"ctx",
")",
"if",
"(",
"!",
"result",
")",
"{",
"return",
"next",
"(",
")",
"}",
"addCommonAPI",
"(",
"ctx",
")",
"ctx",
".",
"_session",
"=",
"result",
".",
"session",
"// more flexible",
"Object",
".",
"defineProperty",
"(",
"ctx",
",",
"'session'",
",",
"{",
"get",
"(",
")",
"{",
"return",
"this",
".",
"_session",
"}",
",",
"set",
"(",
"sess",
")",
"{",
"this",
".",
"_session",
"=",
"sess",
"}",
"}",
")",
"ctx",
".",
"regenerateSession",
"=",
"async",
"function",
"regenerateSession",
"(",
")",
"{",
"debug",
"(",
"'regenerating session'",
")",
"if",
"(",
"!",
"result",
".",
"isNew",
")",
"{",
"// destroy the old session",
"debug",
"(",
"'destroying previous session'",
")",
"await",
"store",
".",
"destroy",
"(",
"ctx",
".",
"sessionId",
")",
"}",
"ctx",
".",
"session",
"=",
"generateSession",
"(",
")",
"ctx",
".",
"sessionId",
"=",
"genSid",
".",
"call",
"(",
"ctx",
",",
"24",
")",
"sessionIdStore",
".",
"reset",
".",
"call",
"(",
"ctx",
")",
"debug",
"(",
"'created new session: %s'",
",",
"ctx",
".",
"sessionId",
")",
"result",
".",
"isNew",
"=",
"true",
"}",
"// make sure `refreshSession` always called",
"let",
"firstError",
"=",
"null",
"try",
"{",
"await",
"next",
"(",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"debug",
"(",
"'next logic error: %s'",
",",
"err",
".",
"message",
")",
"firstError",
"=",
"err",
"}",
"// can't use finally because `refreshSession` is async",
"try",
"{",
"await",
"refreshSession",
"(",
"ctx",
",",
"ctx",
".",
"session",
",",
"result",
".",
"originalHash",
",",
"result",
".",
"isNew",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"debug",
"(",
"'refresh session error: %s'",
",",
"err",
".",
"message",
")",
"if",
"(",
"firstError",
")",
"ctx",
".",
"app",
".",
"emit",
"(",
"'error'",
",",
"err",
",",
"ctx",
")",
"firstError",
"=",
"firstError",
"||",
"err",
"}",
"if",
"(",
"firstError",
")",
"throw",
"firstError",
"}"
] |
common session middleware
each request will generate a new session
```
let session = this.session
```
|
[
"common",
"session",
"middleware",
"each",
"request",
"will",
"generate",
"a",
"new",
"session"
] |
85a6ae64b6a3e7966fa6299536acfe54ad575c13
|
https://github.com/koajs/generic-session/blob/85a6ae64b6a3e7966fa6299536acfe54ad575c13/src/session.js#L303-L360
|
18,276
|
koajs/generic-session
|
src/session.js
|
deferSession
|
async function deferSession(ctx, next) {
ctx.sessionStore = store
// TODO:
// Accessing ctx.session when it's defined is causing problems
// because it has side effect. So, here we use a flag to determine
// that session property is already defined.
if (ctx.__isSessionDefined) {
return next()
}
let isNew = false
let originalHash = null
let touchSession = false
let getter = false
// if path not match
if (!matchPath(ctx)) {
return next()
}
addCommonAPI(ctx)
Object.defineProperty(ctx, 'session', {
async get() {
if (touchSession) {
return this._session
}
touchSession = true
getter = true
const result = await getSession(this)
// if cookie path not match
// this route's controller should never use session
if (!result) return
originalHash = result.originalHash
isNew = result.isNew
this._session = result.session
return this._session
},
set(value) {
touchSession = true
this._session = value
}
})
// internal flag to determine that session is already defined
ctx.__isSessionDefined = true
ctx.regenerateSession = async function regenerateSession() {
debug('regenerating session')
// make sure that the session has been loaded
await ctx.session
if (!isNew) {
// destroy the old session
debug('destroying previous session')
await store.destroy(ctx.sessionId)
}
ctx._session = generateSession()
ctx.sessionId = genSid.call(ctx, 24)
sessionIdStore.reset.call(ctx)
debug('created new session: %s', ctx.sessionId)
isNew = true
return ctx._session
}
await next()
if (touchSession) {
// if only this.session=, need try to decode and get the sessionID
if (!getter) {
ctx.sessionId = sessionIdStore.get.call(ctx)
}
await refreshSession(ctx, ctx._session, originalHash, isNew)
}
}
|
javascript
|
async function deferSession(ctx, next) {
ctx.sessionStore = store
// TODO:
// Accessing ctx.session when it's defined is causing problems
// because it has side effect. So, here we use a flag to determine
// that session property is already defined.
if (ctx.__isSessionDefined) {
return next()
}
let isNew = false
let originalHash = null
let touchSession = false
let getter = false
// if path not match
if (!matchPath(ctx)) {
return next()
}
addCommonAPI(ctx)
Object.defineProperty(ctx, 'session', {
async get() {
if (touchSession) {
return this._session
}
touchSession = true
getter = true
const result = await getSession(this)
// if cookie path not match
// this route's controller should never use session
if (!result) return
originalHash = result.originalHash
isNew = result.isNew
this._session = result.session
return this._session
},
set(value) {
touchSession = true
this._session = value
}
})
// internal flag to determine that session is already defined
ctx.__isSessionDefined = true
ctx.regenerateSession = async function regenerateSession() {
debug('regenerating session')
// make sure that the session has been loaded
await ctx.session
if (!isNew) {
// destroy the old session
debug('destroying previous session')
await store.destroy(ctx.sessionId)
}
ctx._session = generateSession()
ctx.sessionId = genSid.call(ctx, 24)
sessionIdStore.reset.call(ctx)
debug('created new session: %s', ctx.sessionId)
isNew = true
return ctx._session
}
await next()
if (touchSession) {
// if only this.session=, need try to decode and get the sessionID
if (!getter) {
ctx.sessionId = sessionIdStore.get.call(ctx)
}
await refreshSession(ctx, ctx._session, originalHash, isNew)
}
}
|
[
"async",
"function",
"deferSession",
"(",
"ctx",
",",
"next",
")",
"{",
"ctx",
".",
"sessionStore",
"=",
"store",
"// TODO:",
"// Accessing ctx.session when it's defined is causing problems",
"// because it has side effect. So, here we use a flag to determine",
"// that session property is already defined.",
"if",
"(",
"ctx",
".",
"__isSessionDefined",
")",
"{",
"return",
"next",
"(",
")",
"}",
"let",
"isNew",
"=",
"false",
"let",
"originalHash",
"=",
"null",
"let",
"touchSession",
"=",
"false",
"let",
"getter",
"=",
"false",
"// if path not match",
"if",
"(",
"!",
"matchPath",
"(",
"ctx",
")",
")",
"{",
"return",
"next",
"(",
")",
"}",
"addCommonAPI",
"(",
"ctx",
")",
"Object",
".",
"defineProperty",
"(",
"ctx",
",",
"'session'",
",",
"{",
"async",
"get",
"(",
")",
"{",
"if",
"(",
"touchSession",
")",
"{",
"return",
"this",
".",
"_session",
"}",
"touchSession",
"=",
"true",
"getter",
"=",
"true",
"const",
"result",
"=",
"await",
"getSession",
"(",
"this",
")",
"// if cookie path not match",
"// this route's controller should never use session",
"if",
"(",
"!",
"result",
")",
"return",
"originalHash",
"=",
"result",
".",
"originalHash",
"isNew",
"=",
"result",
".",
"isNew",
"this",
".",
"_session",
"=",
"result",
".",
"session",
"return",
"this",
".",
"_session",
"}",
",",
"set",
"(",
"value",
")",
"{",
"touchSession",
"=",
"true",
"this",
".",
"_session",
"=",
"value",
"}",
"}",
")",
"// internal flag to determine that session is already defined",
"ctx",
".",
"__isSessionDefined",
"=",
"true",
"ctx",
".",
"regenerateSession",
"=",
"async",
"function",
"regenerateSession",
"(",
")",
"{",
"debug",
"(",
"'regenerating session'",
")",
"// make sure that the session has been loaded",
"await",
"ctx",
".",
"session",
"if",
"(",
"!",
"isNew",
")",
"{",
"// destroy the old session",
"debug",
"(",
"'destroying previous session'",
")",
"await",
"store",
".",
"destroy",
"(",
"ctx",
".",
"sessionId",
")",
"}",
"ctx",
".",
"_session",
"=",
"generateSession",
"(",
")",
"ctx",
".",
"sessionId",
"=",
"genSid",
".",
"call",
"(",
"ctx",
",",
"24",
")",
"sessionIdStore",
".",
"reset",
".",
"call",
"(",
"ctx",
")",
"debug",
"(",
"'created new session: %s'",
",",
"ctx",
".",
"sessionId",
")",
"isNew",
"=",
"true",
"return",
"ctx",
".",
"_session",
"}",
"await",
"next",
"(",
")",
"if",
"(",
"touchSession",
")",
"{",
"// if only this.session=, need try to decode and get the sessionID",
"if",
"(",
"!",
"getter",
")",
"{",
"ctx",
".",
"sessionId",
"=",
"sessionIdStore",
".",
"get",
".",
"call",
"(",
"ctx",
")",
"}",
"await",
"refreshSession",
"(",
"ctx",
",",
"ctx",
".",
"_session",
",",
"originalHash",
",",
"isNew",
")",
"}",
"}"
] |
defer session middleware
only generate and get session when request use session
```
let session = yield this.session
```
|
[
"defer",
"session",
"middleware",
"only",
"generate",
"and",
"get",
"session",
"when",
"request",
"use",
"session"
] |
85a6ae64b6a3e7966fa6299536acfe54ad575c13
|
https://github.com/koajs/generic-session/blob/85a6ae64b6a3e7966fa6299536acfe54ad575c13/src/session.js#L370-L448
|
18,277
|
Reportr/dashboard
|
public/build/static/application.js
|
getScriptData
|
function getScriptData(evt) {
//Using currentTarget instead of target for Firefox 2.0's sake. Not
//all old browsers will be supported, but this one was easy enough
//to support and still makes sense.
var node = evt.currentTarget || evt.srcElement;
//Remove the listeners once here.
removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
removeListener(node, context.onScriptError, 'error');
return {
node: node,
id: node && node.getAttribute('data-requiremodule')
};
}
|
javascript
|
function getScriptData(evt) {
//Using currentTarget instead of target for Firefox 2.0's sake. Not
//all old browsers will be supported, but this one was easy enough
//to support and still makes sense.
var node = evt.currentTarget || evt.srcElement;
//Remove the listeners once here.
removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
removeListener(node, context.onScriptError, 'error');
return {
node: node,
id: node && node.getAttribute('data-requiremodule')
};
}
|
[
"function",
"getScriptData",
"(",
"evt",
")",
"{",
"//Using currentTarget instead of target for Firefox 2.0's sake. Not",
"//all old browsers will be supported, but this one was easy enough",
"//to support and still makes sense.",
"var",
"node",
"=",
"evt",
".",
"currentTarget",
"||",
"evt",
".",
"srcElement",
";",
"//Remove the listeners once here.",
"removeListener",
"(",
"node",
",",
"context",
".",
"onScriptLoad",
",",
"'load'",
",",
"'onreadystatechange'",
")",
";",
"removeListener",
"(",
"node",
",",
"context",
".",
"onScriptError",
",",
"'error'",
")",
";",
"return",
"{",
"node",
":",
"node",
",",
"id",
":",
"node",
"&&",
"node",
".",
"getAttribute",
"(",
"'data-requiremodule'",
")",
"}",
";",
"}"
] |
Given an event from a script node, get the requirejs info from it,
and then removes the event listeners on the node.
@param {Event} evt
@returns {Object}
|
[
"Given",
"an",
"event",
"from",
"a",
"script",
"node",
"get",
"the",
"requirejs",
"info",
"from",
"it",
"and",
"then",
"removes",
"the",
"event",
"listeners",
"on",
"the",
"node",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L1195-L1209
|
18,278
|
Reportr/dashboard
|
public/build/static/application.js
|
completed
|
function completed() {
document.removeEventListener( "DOMContentLoaded", completed, false );
window.removeEventListener( "load", completed, false );
jQuery.ready();
}
|
javascript
|
function completed() {
document.removeEventListener( "DOMContentLoaded", completed, false );
window.removeEventListener( "load", completed, false );
jQuery.ready();
}
|
[
"function",
"completed",
"(",
")",
"{",
"document",
".",
"removeEventListener",
"(",
"\"DOMContentLoaded\"",
",",
"completed",
",",
"false",
")",
";",
"window",
".",
"removeEventListener",
"(",
"\"load\"",
",",
"completed",
",",
"false",
")",
";",
"jQuery",
".",
"ready",
"(",
")",
";",
"}"
] |
The ready event handler and self cleanup method
|
[
"The",
"ready",
"event",
"handler",
"and",
"self",
"cleanup",
"method"
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L5426-L5430
|
18,279
|
Reportr/dashboard
|
public/build/static/application.js
|
computePixelPositionAndBoxSizingReliable
|
function computePixelPositionAndBoxSizingReliable() {
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
"box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;" +
"position:absolute;top:1%";
docElem.appendChild( container );
var divStyle = window.getComputedStyle( div, null );
pixelPositionVal = divStyle.top !== "1%";
boxSizingReliableVal = divStyle.width === "4px";
docElem.removeChild( container );
}
|
javascript
|
function computePixelPositionAndBoxSizingReliable() {
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
"box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;" +
"position:absolute;top:1%";
docElem.appendChild( container );
var divStyle = window.getComputedStyle( div, null );
pixelPositionVal = divStyle.top !== "1%";
boxSizingReliableVal = divStyle.width === "4px";
docElem.removeChild( container );
}
|
[
"function",
"computePixelPositionAndBoxSizingReliable",
"(",
")",
"{",
"// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).",
"div",
".",
"style",
".",
"cssText",
"=",
"\"-webkit-box-sizing:border-box;-moz-box-sizing:border-box;\"",
"+",
"\"box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;\"",
"+",
"\"position:absolute;top:1%\"",
";",
"docElem",
".",
"appendChild",
"(",
"container",
")",
";",
"var",
"divStyle",
"=",
"window",
".",
"getComputedStyle",
"(",
"div",
",",
"null",
")",
";",
"pixelPositionVal",
"=",
"divStyle",
".",
"top",
"!==",
"\"1%\"",
";",
"boxSizingReliableVal",
"=",
"divStyle",
".",
"width",
"===",
"\"4px\"",
";",
"docElem",
".",
"removeChild",
"(",
"container",
")",
";",
"}"
] |
Executing both pixelPosition & boxSizingReliable tests require only one layout so they're executed at the same time to save the second computation.
|
[
"Executing",
"both",
"pixelPosition",
"&",
"boxSizingReliable",
"tests",
"require",
"only",
"one",
"layout",
"so",
"they",
"re",
"executed",
"at",
"the",
"same",
"time",
"to",
"save",
"the",
"second",
"computation",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L7611-L7623
|
18,280
|
Reportr/dashboard
|
public/build/static/application.js
|
compareAscending
|
function compareAscending(a, b) {
return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index;
}
|
javascript
|
function compareAscending(a, b) {
return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index;
}
|
[
"function",
"compareAscending",
"(",
"a",
",",
"b",
")",
"{",
"return",
"baseCompareAscending",
"(",
"a",
".",
"criteria",
",",
"b",
".",
"criteria",
")",
"||",
"a",
".",
"index",
"-",
"b",
".",
"index",
";",
"}"
] |
Used by `sortBy` to compare transformed elements of a collection and stable
sort 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 for `a`.
|
[
"Used",
"by",
"sortBy",
"to",
"compare",
"transformed",
"elements",
"of",
"a",
"collection",
"and",
"stable",
"sort",
"them",
"in",
"ascending",
"order",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13462-L13464
|
18,281
|
Reportr/dashboard
|
public/build/static/application.js
|
compareMultipleAscending
|
function compareMultipleAscending(a, b) {
var ac = a.criteria,
bc = b.criteria,
index = -1,
length = ac.length;
while (++index < length) {
var result = baseCompareAscending(ac[index], bc[index]);
if (result) {
return result;
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provided 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 https://code.google.com/p/v8/issues/detail?id=90
return a.index - b.index;
}
|
javascript
|
function compareMultipleAscending(a, b) {
var ac = a.criteria,
bc = b.criteria,
index = -1,
length = ac.length;
while (++index < length) {
var result = baseCompareAscending(ac[index], bc[index]);
if (result) {
return result;
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provided 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 https://code.google.com/p/v8/issues/detail?id=90
return a.index - b.index;
}
|
[
"function",
"compareMultipleAscending",
"(",
"a",
",",
"b",
")",
"{",
"var",
"ac",
"=",
"a",
".",
"criteria",
",",
"bc",
"=",
"b",
".",
"criteria",
",",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"ac",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"result",
"=",
"baseCompareAscending",
"(",
"ac",
"[",
"index",
"]",
",",
"bc",
"[",
"index",
"]",
")",
";",
"if",
"(",
"result",
")",
"{",
"return",
"result",
";",
"}",
"}",
"// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications",
"// that causes it, under certain circumstances, to provided 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 https://code.google.com/p/v8/issues/detail?id=90",
"return",
"a",
".",
"index",
"-",
"b",
".",
"index",
";",
"}"
] |
Used by `sortBy` to compare multiple properties of each element in a
collection and stable sort 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 for `a`.
|
[
"Used",
"by",
"sortBy",
"to",
"compare",
"multiple",
"properties",
"of",
"each",
"element",
"in",
"a",
"collection",
"and",
"stable",
"sort",
"them",
"in",
"ascending",
"order",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13475-L13494
|
18,282
|
Reportr/dashboard
|
public/build/static/application.js
|
releaseArray
|
function releaseArray(array) {
array.length = 0;
if (arrayPool.length < MAX_POOL_SIZE) {
arrayPool.push(array);
}
}
|
javascript
|
function releaseArray(array) {
array.length = 0;
if (arrayPool.length < MAX_POOL_SIZE) {
arrayPool.push(array);
}
}
|
[
"function",
"releaseArray",
"(",
"array",
")",
"{",
"array",
".",
"length",
"=",
"0",
";",
"if",
"(",
"arrayPool",
".",
"length",
"<",
"MAX_POOL_SIZE",
")",
"{",
"arrayPool",
".",
"push",
"(",
"array",
")",
";",
"}",
"}"
] |
Releases `array` back to the array pool.
@private
@param {Array} array The array to release.
|
[
"Releases",
"array",
"back",
"to",
"the",
"array",
"pool",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13562-L13567
|
18,283
|
Reportr/dashboard
|
public/build/static/application.js
|
releaseObject
|
function releaseObject(object) {
object.criteria = object.value = null;
if (objectPool.length < MAX_POOL_SIZE) {
objectPool.push(object);
}
}
|
javascript
|
function releaseObject(object) {
object.criteria = object.value = null;
if (objectPool.length < MAX_POOL_SIZE) {
objectPool.push(object);
}
}
|
[
"function",
"releaseObject",
"(",
"object",
")",
"{",
"object",
".",
"criteria",
"=",
"object",
".",
"value",
"=",
"null",
";",
"if",
"(",
"objectPool",
".",
"length",
"<",
"MAX_POOL_SIZE",
")",
"{",
"objectPool",
".",
"push",
"(",
"object",
")",
";",
"}",
"}"
] |
Releases `object` back to the object pool.
@private
@param {Object} object The object to release.
|
[
"Releases",
"object",
"back",
"to",
"the",
"object",
"pool",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13575-L13580
|
18,284
|
Reportr/dashboard
|
public/build/static/application.js
|
shimTrimLeft
|
function shimTrimLeft(string, chars) {
string = string == null ? '' : String(string);
if (!string) {
return string;
}
if (chars == null) {
return string.slice(trimmedLeftIndex(string))
}
chars = String(chars);
return string.slice(charsLeftIndex(string, chars));
}
|
javascript
|
function shimTrimLeft(string, chars) {
string = string == null ? '' : String(string);
if (!string) {
return string;
}
if (chars == null) {
return string.slice(trimmedLeftIndex(string))
}
chars = String(chars);
return string.slice(charsLeftIndex(string, chars));
}
|
[
"function",
"shimTrimLeft",
"(",
"string",
",",
"chars",
")",
"{",
"string",
"=",
"string",
"==",
"null",
"?",
"''",
":",
"String",
"(",
"string",
")",
";",
"if",
"(",
"!",
"string",
")",
"{",
"return",
"string",
";",
"}",
"if",
"(",
"chars",
"==",
"null",
")",
"{",
"return",
"string",
".",
"slice",
"(",
"trimmedLeftIndex",
"(",
"string",
")",
")",
"}",
"chars",
"=",
"String",
"(",
"chars",
")",
";",
"return",
"string",
".",
"slice",
"(",
"charsLeftIndex",
"(",
"string",
",",
"chars",
")",
")",
";",
"}"
] |
A fallback implementation of `trimLeft` to remove leading whitespace or
specified characters from `string`.
@private
@param {string} string The string to trim.
@param {string} [chars=whitespace] The characters to trim.
@returns {string} Returns the trimmed string.
|
[
"A",
"fallback",
"implementation",
"of",
"trimLeft",
"to",
"remove",
"leading",
"whitespace",
"or",
"specified",
"characters",
"from",
"string",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13612-L13622
|
18,285
|
Reportr/dashboard
|
public/build/static/application.js
|
shimTrimRight
|
function shimTrimRight(string, chars) {
string = string == null ? '' : String(string);
if (!string) {
return string;
}
if (chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1)
}
chars = String(chars);
return string.slice(0, charsRightIndex(string, chars) + 1);
}
|
javascript
|
function shimTrimRight(string, chars) {
string = string == null ? '' : String(string);
if (!string) {
return string;
}
if (chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1)
}
chars = String(chars);
return string.slice(0, charsRightIndex(string, chars) + 1);
}
|
[
"function",
"shimTrimRight",
"(",
"string",
",",
"chars",
")",
"{",
"string",
"=",
"string",
"==",
"null",
"?",
"''",
":",
"String",
"(",
"string",
")",
";",
"if",
"(",
"!",
"string",
")",
"{",
"return",
"string",
";",
"}",
"if",
"(",
"chars",
"==",
"null",
")",
"{",
"return",
"string",
".",
"slice",
"(",
"0",
",",
"trimmedRightIndex",
"(",
"string",
")",
"+",
"1",
")",
"}",
"chars",
"=",
"String",
"(",
"chars",
")",
";",
"return",
"string",
".",
"slice",
"(",
"0",
",",
"charsRightIndex",
"(",
"string",
",",
"chars",
")",
"+",
"1",
")",
";",
"}"
] |
A fallback implementation of `trimRight` to remove trailing whitespace or
specified characters from `string`.
@private
@param {string} string The string to trim.
@param {string} [chars=whitespace] The characters to trim.
@returns {string} Returns the trimmed string.
|
[
"A",
"fallback",
"implementation",
"of",
"trimRight",
"to",
"remove",
"trailing",
"whitespace",
"or",
"specified",
"characters",
"from",
"string",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13633-L13643
|
18,286
|
Reportr/dashboard
|
public/build/static/application.js
|
trimmedLeftIndex
|
function trimmedLeftIndex(string) {
var index = -1,
length = string.length;
while (++index < length) {
var c = string.charCodeAt(index);
if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 ||
(c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c == 12288 || c == 65279)))) {
break;
}
}
return index;
}
|
javascript
|
function trimmedLeftIndex(string) {
var index = -1,
length = string.length;
while (++index < length) {
var c = string.charCodeAt(index);
if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 ||
(c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c == 12288 || c == 65279)))) {
break;
}
}
return index;
}
|
[
"function",
"trimmedLeftIndex",
"(",
"string",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"string",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"c",
"=",
"string",
".",
"charCodeAt",
"(",
"index",
")",
";",
"if",
"(",
"!",
"(",
"(",
"c",
"<=",
"160",
"&&",
"(",
"c",
">=",
"9",
"&&",
"c",
"<=",
"13",
")",
"||",
"c",
"==",
"32",
"||",
"c",
"==",
"160",
")",
"||",
"c",
"==",
"5760",
"||",
"c",
"==",
"6158",
"||",
"(",
"c",
">=",
"8192",
"&&",
"(",
"c",
"<=",
"8202",
"||",
"c",
"==",
"8232",
"||",
"c",
"==",
"8233",
"||",
"c",
"==",
"8239",
"||",
"c",
"==",
"8287",
"||",
"c",
"==",
"12288",
"||",
"c",
"==",
"65279",
")",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"index",
";",
"}"
] |
Gets the index of the first non-whitespace character of `string`.
@private
@param {string} string The string to inspect.
@returns {number} Returns the index of the first non-whitespace character.
|
[
"Gets",
"the",
"index",
"of",
"the",
"first",
"non",
"-",
"whitespace",
"character",
"of",
"string",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13652-L13664
|
18,287
|
Reportr/dashboard
|
public/build/static/application.js
|
trimmedRightIndex
|
function trimmedRightIndex(string) {
var index = string.length;
while (index--) {
var c = string.charCodeAt(index);
if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 ||
(c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c == 12288 || c == 65279)))) {
break;
}
}
return index;
}
|
javascript
|
function trimmedRightIndex(string) {
var index = string.length;
while (index--) {
var c = string.charCodeAt(index);
if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 ||
(c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c == 12288 || c == 65279)))) {
break;
}
}
return index;
}
|
[
"function",
"trimmedRightIndex",
"(",
"string",
")",
"{",
"var",
"index",
"=",
"string",
".",
"length",
";",
"while",
"(",
"index",
"--",
")",
"{",
"var",
"c",
"=",
"string",
".",
"charCodeAt",
"(",
"index",
")",
";",
"if",
"(",
"!",
"(",
"(",
"c",
"<=",
"160",
"&&",
"(",
"c",
">=",
"9",
"&&",
"c",
"<=",
"13",
")",
"||",
"c",
"==",
"32",
"||",
"c",
"==",
"160",
")",
"||",
"c",
"==",
"5760",
"||",
"c",
"==",
"6158",
"||",
"(",
"c",
">=",
"8192",
"&&",
"(",
"c",
"<=",
"8202",
"||",
"c",
"==",
"8232",
"||",
"c",
"==",
"8233",
"||",
"c",
"==",
"8239",
"||",
"c",
"==",
"8287",
"||",
"c",
"==",
"12288",
"||",
"c",
"==",
"65279",
")",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"index",
";",
"}"
] |
Gets the index of the last non-whitespace character of `string`.
@private
@param {string} string The string to inspect.
@returns {number} Returns the index of the last non-whitespace character.
|
[
"Gets",
"the",
"index",
"of",
"the",
"last",
"non",
"-",
"whitespace",
"character",
"of",
"string",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L13673-L13683
|
18,288
|
Reportr/dashboard
|
public/build/static/application.js
|
baseEach
|
function baseEach(collection, callback) {
var index = -1,
iterable = collection,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
if (support.unindexedChars && isString(iterable)) {
iterable = iterable.split('');
}
while (++index < length) {
if (callback(iterable[index], index, collection) === false) {
break;
}
}
} else {
baseForOwn(collection, callback);
}
return collection;
}
|
javascript
|
function baseEach(collection, callback) {
var index = -1,
iterable = collection,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
if (support.unindexedChars && isString(iterable)) {
iterable = iterable.split('');
}
while (++index < length) {
if (callback(iterable[index], index, collection) === false) {
break;
}
}
} else {
baseForOwn(collection, callback);
}
return collection;
}
|
[
"function",
"baseEach",
"(",
"collection",
",",
"callback",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"iterable",
"=",
"collection",
",",
"length",
"=",
"collection",
"?",
"collection",
".",
"length",
":",
"0",
";",
"if",
"(",
"typeof",
"length",
"==",
"'number'",
")",
"{",
"if",
"(",
"support",
".",
"unindexedChars",
"&&",
"isString",
"(",
"iterable",
")",
")",
"{",
"iterable",
"=",
"iterable",
".",
"split",
"(",
"''",
")",
";",
"}",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"callback",
"(",
"iterable",
"[",
"index",
"]",
",",
"index",
",",
"collection",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"baseForOwn",
"(",
"collection",
",",
"callback",
")",
";",
"}",
"return",
"collection",
";",
"}"
] |
The base implementation of `_.forEach` without support for callback
shorthands or `thisArg` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} callback The function called per iteration.
@returns {Array|Object|string} Returns `collection`.
|
[
"The",
"base",
"implementation",
"of",
"_",
".",
"forEach",
"without",
"support",
"for",
"callback",
"shorthands",
"or",
"thisArg",
"binding",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L14516-L14534
|
18,289
|
Reportr/dashboard
|
public/build/static/application.js
|
baseEachRight
|
function baseEachRight(collection, callback) {
var iterable = collection,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
if (support.unindexedChars && isString(iterable)) {
iterable = iterable.split('');
}
while (length--) {
if (callback(iterable[length], length, collection) === false) {
break;
}
}
} else {
baseForOwnRight(collection, callback);
}
return collection;
}
|
javascript
|
function baseEachRight(collection, callback) {
var iterable = collection,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
if (support.unindexedChars && isString(iterable)) {
iterable = iterable.split('');
}
while (length--) {
if (callback(iterable[length], length, collection) === false) {
break;
}
}
} else {
baseForOwnRight(collection, callback);
}
return collection;
}
|
[
"function",
"baseEachRight",
"(",
"collection",
",",
"callback",
")",
"{",
"var",
"iterable",
"=",
"collection",
",",
"length",
"=",
"collection",
"?",
"collection",
".",
"length",
":",
"0",
";",
"if",
"(",
"typeof",
"length",
"==",
"'number'",
")",
"{",
"if",
"(",
"support",
".",
"unindexedChars",
"&&",
"isString",
"(",
"iterable",
")",
")",
"{",
"iterable",
"=",
"iterable",
".",
"split",
"(",
"''",
")",
";",
"}",
"while",
"(",
"length",
"--",
")",
"{",
"if",
"(",
"callback",
"(",
"iterable",
"[",
"length",
"]",
",",
"length",
",",
"collection",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"baseForOwnRight",
"(",
"collection",
",",
"callback",
")",
";",
"}",
"return",
"collection",
";",
"}"
] |
The base implementation of `_.forEachRight` without support for callback
shorthands or `thisArg` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} callback The function called per iteration.
@returns {Array|Object|string} Returns `collection`.
|
[
"The",
"base",
"implementation",
"of",
"_",
".",
"forEachRight",
"without",
"support",
"for",
"callback",
"shorthands",
"or",
"thisArg",
"binding",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L14545-L14562
|
18,290
|
Reportr/dashboard
|
public/build/static/application.js
|
baseForOwn
|
function baseForOwn(object, callback) {
var index = -1,
props = keys(object),
length = props.length;
while (++index < length) {
var key = props[index];
if (callback(object[key], key, object) === false) {
break;
}
}
return object;
}
|
javascript
|
function baseForOwn(object, callback) {
var index = -1,
props = keys(object),
length = props.length;
while (++index < length) {
var key = props[index];
if (callback(object[key], key, object) === false) {
break;
}
}
return object;
}
|
[
"function",
"baseForOwn",
"(",
"object",
",",
"callback",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"props",
"=",
"keys",
"(",
"object",
")",
",",
"length",
"=",
"props",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"key",
"=",
"props",
"[",
"index",
"]",
";",
"if",
"(",
"callback",
"(",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"return",
"object",
";",
"}"
] |
The base implementation of `_.forOwn` without support for callback
shorthands or `thisArg` binding.
@private
@param {Object} object The object to iterate over.
@param {Function} callback The function called per iteration.
@returns {Object} Returns `object`.
|
[
"The",
"base",
"implementation",
"of",
"_",
".",
"forOwn",
"without",
"support",
"for",
"callback",
"shorthands",
"or",
"thisArg",
"binding",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L14613-L14625
|
18,291
|
Reportr/dashboard
|
public/build/static/application.js
|
baseForOwnRight
|
function baseForOwnRight(object, callback) {
var props = keys(object),
length = props.length;
while (length--) {
var key = props[length];
if (callback(object[key], key, object) === false) {
break;
}
}
return object;
}
|
javascript
|
function baseForOwnRight(object, callback) {
var props = keys(object),
length = props.length;
while (length--) {
var key = props[length];
if (callback(object[key], key, object) === false) {
break;
}
}
return object;
}
|
[
"function",
"baseForOwnRight",
"(",
"object",
",",
"callback",
")",
"{",
"var",
"props",
"=",
"keys",
"(",
"object",
")",
",",
"length",
"=",
"props",
".",
"length",
";",
"while",
"(",
"length",
"--",
")",
"{",
"var",
"key",
"=",
"props",
"[",
"length",
"]",
";",
"if",
"(",
"callback",
"(",
"object",
"[",
"key",
"]",
",",
"key",
",",
"object",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"return",
"object",
";",
"}"
] |
The base implementation of `_.forOwnRight` without support for callback
shorthands or `thisArg` binding.
@private
@param {Object} object The object to iterate over.
@param {Function} callback The function called per iteration.
@returns {Object} Returns `object`.
|
[
"The",
"base",
"implementation",
"of",
"_",
".",
"forOwnRight",
"without",
"support",
"for",
"callback",
"shorthands",
"or",
"thisArg",
"binding",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L14636-L14647
|
18,292
|
Reportr/dashboard
|
public/build/static/application.js
|
baseMerge
|
function baseMerge(object, source, callback, stackA, stackB) {
(isArray(source) ? baseEach : baseForOwn)(source, function(source, key) {
var found,
isArr,
result = source,
value = object[key];
if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
// avoid merging previously merged cyclic sources
var stackLength = stackA.length;
while (stackLength--) {
if ((found = stackA[stackLength] == source)) {
value = stackB[stackLength];
break;
}
}
if (!found) {
var isShallow;
if (callback) {
result = callback(value, source);
if ((isShallow = typeof result != 'undefined')) {
value = result;
}
}
if (!isShallow) {
value = isArr
? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {});
}
// add `source` and associated `value` to the stack of traversed objects
stackA.push(source);
stackB.push(value);
// recursively merge objects and arrays (susceptible to call stack limits)
if (!isShallow) {
baseMerge(value, source, callback, stackA, stackB);
}
}
}
else {
if (callback) {
result = callback(value, source);
if (typeof result == 'undefined') {
result = source;
}
}
if (typeof result != 'undefined') {
value = result;
}
}
object[key] = value;
});
}
|
javascript
|
function baseMerge(object, source, callback, stackA, stackB) {
(isArray(source) ? baseEach : baseForOwn)(source, function(source, key) {
var found,
isArr,
result = source,
value = object[key];
if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
// avoid merging previously merged cyclic sources
var stackLength = stackA.length;
while (stackLength--) {
if ((found = stackA[stackLength] == source)) {
value = stackB[stackLength];
break;
}
}
if (!found) {
var isShallow;
if (callback) {
result = callback(value, source);
if ((isShallow = typeof result != 'undefined')) {
value = result;
}
}
if (!isShallow) {
value = isArr
? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {});
}
// add `source` and associated `value` to the stack of traversed objects
stackA.push(source);
stackB.push(value);
// recursively merge objects and arrays (susceptible to call stack limits)
if (!isShallow) {
baseMerge(value, source, callback, stackA, stackB);
}
}
}
else {
if (callback) {
result = callback(value, source);
if (typeof result == 'undefined') {
result = source;
}
}
if (typeof result != 'undefined') {
value = result;
}
}
object[key] = value;
});
}
|
[
"function",
"baseMerge",
"(",
"object",
",",
"source",
",",
"callback",
",",
"stackA",
",",
"stackB",
")",
"{",
"(",
"isArray",
"(",
"source",
")",
"?",
"baseEach",
":",
"baseForOwn",
")",
"(",
"source",
",",
"function",
"(",
"source",
",",
"key",
")",
"{",
"var",
"found",
",",
"isArr",
",",
"result",
"=",
"source",
",",
"value",
"=",
"object",
"[",
"key",
"]",
";",
"if",
"(",
"source",
"&&",
"(",
"(",
"isArr",
"=",
"isArray",
"(",
"source",
")",
")",
"||",
"isPlainObject",
"(",
"source",
")",
")",
")",
"{",
"// avoid merging previously merged cyclic sources",
"var",
"stackLength",
"=",
"stackA",
".",
"length",
";",
"while",
"(",
"stackLength",
"--",
")",
"{",
"if",
"(",
"(",
"found",
"=",
"stackA",
"[",
"stackLength",
"]",
"==",
"source",
")",
")",
"{",
"value",
"=",
"stackB",
"[",
"stackLength",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"found",
")",
"{",
"var",
"isShallow",
";",
"if",
"(",
"callback",
")",
"{",
"result",
"=",
"callback",
"(",
"value",
",",
"source",
")",
";",
"if",
"(",
"(",
"isShallow",
"=",
"typeof",
"result",
"!=",
"'undefined'",
")",
")",
"{",
"value",
"=",
"result",
";",
"}",
"}",
"if",
"(",
"!",
"isShallow",
")",
"{",
"value",
"=",
"isArr",
"?",
"(",
"isArray",
"(",
"value",
")",
"?",
"value",
":",
"[",
"]",
")",
":",
"(",
"isPlainObject",
"(",
"value",
")",
"?",
"value",
":",
"{",
"}",
")",
";",
"}",
"// add `source` and associated `value` to the stack of traversed objects",
"stackA",
".",
"push",
"(",
"source",
")",
";",
"stackB",
".",
"push",
"(",
"value",
")",
";",
"// recursively merge objects and arrays (susceptible to call stack limits)",
"if",
"(",
"!",
"isShallow",
")",
"{",
"baseMerge",
"(",
"value",
",",
"source",
",",
"callback",
",",
"stackA",
",",
"stackB",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"callback",
")",
"{",
"result",
"=",
"callback",
"(",
"value",
",",
"source",
")",
";",
"if",
"(",
"typeof",
"result",
"==",
"'undefined'",
")",
"{",
"result",
"=",
"source",
";",
"}",
"}",
"if",
"(",
"typeof",
"result",
"!=",
"'undefined'",
")",
"{",
"value",
"=",
"result",
";",
"}",
"}",
"object",
"[",
"key",
"]",
"=",
"value",
";",
"}",
")",
";",
"}"
] |
The base implementation of `_.merge` without argument juggling or support
for `thisArg` binding.
@private
@param {Object} object The destination object.
@param {Object} source The source object.
@param {Function} [callback] The function to customize merging properties.
@param {Array} [stackA=[]] Tracks traversed source objects.
@param {Array} [stackB=[]] Associates values with source counterparts.
|
[
"The",
"base",
"implementation",
"of",
"_",
".",
"merge",
"without",
"argument",
"juggling",
"or",
"support",
"for",
"thisArg",
"binding",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L14836-L14888
|
18,293
|
Reportr/dashboard
|
public/build/static/application.js
|
createAggregator
|
function createAggregator(setter, retArray) {
return function(collection, callback, thisArg) {
var result = retArray ? [[], []] : {};
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
setter(result, value, callback(value, index, collection), collection);
}
} else {
baseEach(collection, function(value, key, collection) {
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};
}
|
javascript
|
function createAggregator(setter, retArray) {
return function(collection, callback, thisArg) {
var result = retArray ? [[], []] : {};
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
setter(result, value, callback(value, index, collection), collection);
}
} else {
baseEach(collection, function(value, key, collection) {
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};
}
|
[
"function",
"createAggregator",
"(",
"setter",
",",
"retArray",
")",
"{",
"return",
"function",
"(",
"collection",
",",
"callback",
",",
"thisArg",
")",
"{",
"var",
"result",
"=",
"retArray",
"?",
"[",
"[",
"]",
",",
"[",
"]",
"]",
":",
"{",
"}",
";",
"callback",
"=",
"lodash",
".",
"createCallback",
"(",
"callback",
",",
"thisArg",
",",
"3",
")",
";",
"if",
"(",
"isArray",
"(",
"collection",
")",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"collection",
".",
"length",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"var",
"value",
"=",
"collection",
"[",
"index",
"]",
";",
"setter",
"(",
"result",
",",
"value",
",",
"callback",
"(",
"value",
",",
"index",
",",
"collection",
")",
",",
"collection",
")",
";",
"}",
"}",
"else",
"{",
"baseEach",
"(",
"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 or
array composed 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 or array.
@private
@param {Function} setter The setter function.
@param {boolean} [retArray=false] A flag to indicate that the aggregator
function should return an array.
@returns {Function} Returns the new aggregator function.
|
[
"Creates",
"a",
"function",
"that",
"aggregates",
"a",
"collection",
"creating",
"an",
"object",
"or",
"array",
"composed",
"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",
"or",
"array",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L15020-L15040
|
18,294
|
Reportr/dashboard
|
public/build/static/application.js
|
createIterator
|
function createIterator(options) {
options.shadowedProps = shadowedProps;
options.support = support;
// create the function factory
var factory = Function(
'errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, ' +
'nonEnumProps, stringClass, stringProto, toString',
'return function(' + options.args + ') {\n' + iteratorTemplate(options) + '\n}'
);
// return the compiled function
return factory(
errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto,
nonEnumProps, stringClass, stringProto, toString
);
}
|
javascript
|
function createIterator(options) {
options.shadowedProps = shadowedProps;
options.support = support;
// create the function factory
var factory = Function(
'errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, ' +
'nonEnumProps, stringClass, stringProto, toString',
'return function(' + options.args + ') {\n' + iteratorTemplate(options) + '\n}'
);
// return the compiled function
return factory(
errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto,
nonEnumProps, stringClass, stringProto, toString
);
}
|
[
"function",
"createIterator",
"(",
"options",
")",
"{",
"options",
".",
"shadowedProps",
"=",
"shadowedProps",
";",
"options",
".",
"support",
"=",
"support",
";",
"// create the function factory",
"var",
"factory",
"=",
"Function",
"(",
"'errorClass, errorProto, hasOwnProperty, isArguments, isObject, objectProto, '",
"+",
"'nonEnumProps, stringClass, stringProto, toString'",
",",
"'return function('",
"+",
"options",
".",
"args",
"+",
"') {\\n'",
"+",
"iteratorTemplate",
"(",
"options",
")",
"+",
"'\\n}'",
")",
";",
"// return the compiled function",
"return",
"factory",
"(",
"errorClass",
",",
"errorProto",
",",
"hasOwnProperty",
",",
"isArguments",
",",
"isObject",
",",
"objectProto",
",",
"nonEnumProps",
",",
"stringClass",
",",
"stringProto",
",",
"toString",
")",
";",
"}"
] |
Creates compiled iteration functions.
@private
@param {Object} [options] The compile options object.
@param {string} [options.args] A comma separated string of iteration function arguments.
@param {string} [options.init] The string representation of the initial `result` value.
@param {string} [options.loop] Code to execute in the object loop.
@param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop.
@returns {Function} Returns the compiled function.
|
[
"Creates",
"compiled",
"iteration",
"functions",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L15176-L15192
|
18,295
|
Reportr/dashboard
|
public/build/static/application.js
|
getHolders
|
function getHolders(array) {
var index = -1,
length = array.length,
result = [];
while (++index < length) {
if (array[index] === lodash) {
result.push(index);
}
}
return result;
}
|
javascript
|
function getHolders(array) {
var index = -1,
length = array.length,
result = [];
while (++index < length) {
if (array[index] === lodash) {
result.push(index);
}
}
return result;
}
|
[
"function",
"getHolders",
"(",
"array",
")",
"{",
"var",
"index",
"=",
"-",
"1",
",",
"length",
"=",
"array",
".",
"length",
",",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"array",
"[",
"index",
"]",
"===",
"lodash",
")",
"{",
"result",
".",
"push",
"(",
"index",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Finds the indexes of all placeholder elements in a given array.
@private
@param {Array} array The array to inspect.
@returns {Array} Returns a new array of placeholder indexes.
|
[
"Finds",
"the",
"indexes",
"of",
"all",
"placeholder",
"elements",
"in",
"a",
"given",
"array",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L15201-L15212
|
18,296
|
Reportr/dashboard
|
public/build/static/application.js
|
sample
|
function sample(collection, n, guard) {
if (collection && typeof collection.length != 'number') {
collection = values(collection);
} else if (support.unindexedChars && isString(collection)) {
collection = collection.split('');
}
if (n == null || guard) {
return collection ? collection[baseRandom(0, collection.length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(nativeMax(0, n), result.length);
return result;
}
|
javascript
|
function sample(collection, n, guard) {
if (collection && typeof collection.length != 'number') {
collection = values(collection);
} else if (support.unindexedChars && isString(collection)) {
collection = collection.split('');
}
if (n == null || guard) {
return collection ? collection[baseRandom(0, collection.length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(nativeMax(0, n), result.length);
return result;
}
|
[
"function",
"sample",
"(",
"collection",
",",
"n",
",",
"guard",
")",
"{",
"if",
"(",
"collection",
"&&",
"typeof",
"collection",
".",
"length",
"!=",
"'number'",
")",
"{",
"collection",
"=",
"values",
"(",
"collection",
")",
";",
"}",
"else",
"if",
"(",
"support",
".",
"unindexedChars",
"&&",
"isString",
"(",
"collection",
")",
")",
"{",
"collection",
"=",
"collection",
".",
"split",
"(",
"''",
")",
";",
"}",
"if",
"(",
"n",
"==",
"null",
"||",
"guard",
")",
"{",
"return",
"collection",
"?",
"collection",
"[",
"baseRandom",
"(",
"0",
",",
"collection",
".",
"length",
"-",
"1",
")",
"]",
":",
"undefined",
";",
"}",
"var",
"result",
"=",
"shuffle",
"(",
"collection",
")",
";",
"result",
".",
"length",
"=",
"nativeMin",
"(",
"nativeMax",
"(",
"0",
",",
"n",
")",
",",
"result",
".",
"length",
")",
";",
"return",
"result",
";",
"}"
] |
Retrieves a random element or `n` random elements from a collection.
@static
@memberOf _
@category Collections
@param {Array|Object|string} collection The collection to sample.
@param {number} [n] The number of elements to sample.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {*} Returns the random sample(s) of `collection`.
@example
_.sample([1, 2, 3, 4]);
// => 2
_.sample([1, 2, 3, 4], 2);
// => [3, 1]
|
[
"Retrieves",
"a",
"random",
"element",
"or",
"n",
"random",
"elements",
"from",
"a",
"collection",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L17557-L17569
|
18,297
|
Reportr/dashboard
|
public/build/static/application.js
|
partialRight
|
function partialRight(func) {
if (func) {
var arity = func[expando] ? func[expando][2] : func.length,
partialRightArgs = slice(arguments, 1);
arity -= partialRightArgs.length;
}
return createWrapper(func, PARTIAL_RIGHT_FLAG, arity, null, null, partialRightArgs);
}
|
javascript
|
function partialRight(func) {
if (func) {
var arity = func[expando] ? func[expando][2] : func.length,
partialRightArgs = slice(arguments, 1);
arity -= partialRightArgs.length;
}
return createWrapper(func, PARTIAL_RIGHT_FLAG, arity, null, null, partialRightArgs);
}
|
[
"function",
"partialRight",
"(",
"func",
")",
"{",
"if",
"(",
"func",
")",
"{",
"var",
"arity",
"=",
"func",
"[",
"expando",
"]",
"?",
"func",
"[",
"expando",
"]",
"[",
"2",
"]",
":",
"func",
".",
"length",
",",
"partialRightArgs",
"=",
"slice",
"(",
"arguments",
",",
"1",
")",
";",
"arity",
"-=",
"partialRightArgs",
".",
"length",
";",
"}",
"return",
"createWrapper",
"(",
"func",
",",
"PARTIAL_RIGHT_FLAG",
",",
"arity",
",",
"null",
",",
"null",
",",
"partialRightArgs",
")",
";",
"}"
] |
This method is like `_.partial` except that partially applied arguments
are appended to those provided to the new function.
Note: This method does not set the `length` property of partially applied
functions.
@static
@memberOf _
@category Functions
@param {Function} func The function to partially apply arguments to.
@param {...*} [args] Arguments to be partially applied.
@returns {Function} Returns the new partially applied function.
@example
var defaultsDeep = _.partialRight(_.merge, _.defaults);
var options = {
'variable': 'data',
'imports': { 'jq': $ }
};
defaultsDeep(options, _.templateSettings);
options.variable
// => 'data'
options.imports
// => { '_': _, 'jq': $ }
|
[
"This",
"method",
"is",
"like",
"_",
".",
"partial",
"except",
"that",
"partially",
"applied",
"arguments",
"are",
"appended",
"to",
"those",
"provided",
"to",
"the",
"new",
"function",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L18401-L18409
|
18,298
|
Reportr/dashboard
|
public/build/static/application.js
|
functions
|
function functions(object) {
var result = [];
baseForIn(object, function(value, key) {
if (isFunction(value)) {
result.push(key);
}
});
return result.sort();
}
|
javascript
|
function functions(object) {
var result = [];
baseForIn(object, function(value, key) {
if (isFunction(value)) {
result.push(key);
}
});
return result.sort();
}
|
[
"function",
"functions",
"(",
"object",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"baseForIn",
"(",
"object",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"if",
"(",
"isFunction",
"(",
"value",
")",
")",
"{",
"result",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"sort",
"(",
")",
";",
"}"
] |
Creates a sorted array of property names of all enumerable properties,
own and inherited, of `object` that have function values.
@static
@memberOf _
@alias methods
@category Objects
@param {Object} object The object to inspect.
@returns {Array} Returns an array of property names that have function values.
@example
_.functions(_);
// => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...]
|
[
"Creates",
"a",
"sorted",
"array",
"of",
"property",
"names",
"of",
"all",
"enumerable",
"properties",
"own",
"and",
"inherited",
"of",
"object",
"that",
"have",
"function",
"values",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L19000-L19008
|
18,299
|
Reportr/dashboard
|
public/build/static/application.js
|
matches
|
function matches(source) {
source || (source = {});
var props = keys(source),
key = props[0],
a = source[key];
// fast path the common case of providing an object with a single
// property containing a primitive value
if (props.length == 1 && a === a && !isObject(a)) {
return function(object) {
if (!hasOwnProperty.call(object, key)) {
return false;
}
var b = object[key];
return a === b && (a !== 0 || (1 / a == 1 / b));
};
}
return function(object) {
var length = props.length,
result = false;
while (length--) {
var key = props[length];
if (!(result = hasOwnProperty.call(object, key) &&
baseIsEqual(object[key], source[key], null, true))) {
break;
}
}
return result;
};
}
|
javascript
|
function matches(source) {
source || (source = {});
var props = keys(source),
key = props[0],
a = source[key];
// fast path the common case of providing an object with a single
// property containing a primitive value
if (props.length == 1 && a === a && !isObject(a)) {
return function(object) {
if (!hasOwnProperty.call(object, key)) {
return false;
}
var b = object[key];
return a === b && (a !== 0 || (1 / a == 1 / b));
};
}
return function(object) {
var length = props.length,
result = false;
while (length--) {
var key = props[length];
if (!(result = hasOwnProperty.call(object, key) &&
baseIsEqual(object[key], source[key], null, true))) {
break;
}
}
return result;
};
}
|
[
"function",
"matches",
"(",
"source",
")",
"{",
"source",
"||",
"(",
"source",
"=",
"{",
"}",
")",
";",
"var",
"props",
"=",
"keys",
"(",
"source",
")",
",",
"key",
"=",
"props",
"[",
"0",
"]",
",",
"a",
"=",
"source",
"[",
"key",
"]",
";",
"// fast path the common case of providing an object with a single",
"// property containing a primitive value",
"if",
"(",
"props",
".",
"length",
"==",
"1",
"&&",
"a",
"===",
"a",
"&&",
"!",
"isObject",
"(",
"a",
")",
")",
"{",
"return",
"function",
"(",
"object",
")",
"{",
"if",
"(",
"!",
"hasOwnProperty",
".",
"call",
"(",
"object",
",",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"b",
"=",
"object",
"[",
"key",
"]",
";",
"return",
"a",
"===",
"b",
"&&",
"(",
"a",
"!==",
"0",
"||",
"(",
"1",
"/",
"a",
"==",
"1",
"/",
"b",
")",
")",
";",
"}",
";",
"}",
"return",
"function",
"(",
"object",
")",
"{",
"var",
"length",
"=",
"props",
".",
"length",
",",
"result",
"=",
"false",
";",
"while",
"(",
"length",
"--",
")",
"{",
"var",
"key",
"=",
"props",
"[",
"length",
"]",
";",
"if",
"(",
"!",
"(",
"result",
"=",
"hasOwnProperty",
".",
"call",
"(",
"object",
",",
"key",
")",
"&&",
"baseIsEqual",
"(",
"object",
"[",
"key",
"]",
",",
"source",
"[",
"key",
"]",
",",
"null",
",",
"true",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"result",
";",
"}",
";",
"}"
] |
Creates a "_.where" style function, which performs a deep comparison
between a given object and the `source` object, returning `true` if the
given object has equivalent property values, else `false`.
@static
@memberOf _
@category Utilities
@param {Object} source The object of property values to match.
@returns {Function} Returns the new function.
@example
var characters = [
{ 'name': 'fred', 'age': 40 },
{ 'name': 'barney', 'age': 36 }
];
var matchesAge = _.matches({ 'age': 36 });
_.filter(characters, matchesAge);
// => [{ 'name': 'barney', 'age': 36 }]
_.find(characters, matchesAge);
// => { 'name': 'barney', 'age': 36 }
|
[
"Creates",
"a",
"_",
".",
"where",
"style",
"function",
"which",
"performs",
"a",
"deep",
"comparison",
"between",
"a",
"given",
"object",
"and",
"the",
"source",
"object",
"returning",
"true",
"if",
"the",
"given",
"object",
"has",
"equivalent",
"property",
"values",
"else",
"false",
"."
] |
bff0ea7f324de78ab8bf8c4301ce30696ad7d960
|
https://github.com/Reportr/dashboard/blob/bff0ea7f324de78ab8bf8c4301ce30696ad7d960/public/build/static/application.js#L20306-L20337
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.