id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
53,500 | jonschlinkert/conflicts | lib/diff.js | diffImage | function diffImage(existing, proposed, options) {
let { bytes, dateformat, imageSize, Table, toFile, colors } = utils;
existing = toFile(existing, options);
proposed = toFile(proposed, options);
let table = new Table({ head: ['Attribute', 'Existing', 'Replacement', 'Diff'] });
let dimensionsA = imageSize(existing.path);
let dimensionsB = imageSize(proposed.path);
let statA = existing.stat;
let statB = proposed.stat;
let isSmaller = existing.size > proposed.size;
let sizeDiff = isSmaller ? '-' : '+';
sizeDiff += bytes(Math.abs(existing.size - proposed.size));
// dates
let mtimeA = statA ? dateformat(statA.mtime) : 'New';
let mtimeB = statB ? dateformat(statB.mtime) : 'New';
if (statA.mtime && statB.mtime && statA.mtime < statB.mtime) {
mtimeB = colors.green(mtimeB);
} else {
mtimeA = colors.green(mtimeA);
}
let birthtimeA = statA ? dateformat(statA.birthtime) : 'New';
let birthtimeB = statB ? dateformat(statB.birthtime) : 'New';
if (statA.birthtime && statB.birthtime && statA.birthtime < statB.birthtime) {
birthtimeB = colors.green(birthtimeB);
} else {
birthtimeA = colors.green(birthtimeA);
}
// size
let sizeA = bytes(existing.size);
let sizeB = bytes(proposed.size);
if (isSmaller) {
sizeDiff = colors.red(sizeDiff);
dimensionsA = colors.green(dimensionsA);
sizeA = colors.green(sizeA);
} else {
sizeDiff = colors.green(sizeDiff);
dimensionsB = colors.green(dimensionsB);
sizeB = colors.green(sizeB);
}
table.push(['Path', existing.relative, proposed.relative, '']);
table.push(['Size', sizeA, sizeB, sizeDiff]);
table.push(['Dimensions', dimensionsA, dimensionsB, 'N/A']);
table.push(['Date created', birthtimeA, birthtimeB, 'N/A']);
table.push(['Date modified', mtimeA, mtimeB, 'N/A']);
return table.toString();
} | javascript | function diffImage(existing, proposed, options) {
let { bytes, dateformat, imageSize, Table, toFile, colors } = utils;
existing = toFile(existing, options);
proposed = toFile(proposed, options);
let table = new Table({ head: ['Attribute', 'Existing', 'Replacement', 'Diff'] });
let dimensionsA = imageSize(existing.path);
let dimensionsB = imageSize(proposed.path);
let statA = existing.stat;
let statB = proposed.stat;
let isSmaller = existing.size > proposed.size;
let sizeDiff = isSmaller ? '-' : '+';
sizeDiff += bytes(Math.abs(existing.size - proposed.size));
// dates
let mtimeA = statA ? dateformat(statA.mtime) : 'New';
let mtimeB = statB ? dateformat(statB.mtime) : 'New';
if (statA.mtime && statB.mtime && statA.mtime < statB.mtime) {
mtimeB = colors.green(mtimeB);
} else {
mtimeA = colors.green(mtimeA);
}
let birthtimeA = statA ? dateformat(statA.birthtime) : 'New';
let birthtimeB = statB ? dateformat(statB.birthtime) : 'New';
if (statA.birthtime && statB.birthtime && statA.birthtime < statB.birthtime) {
birthtimeB = colors.green(birthtimeB);
} else {
birthtimeA = colors.green(birthtimeA);
}
// size
let sizeA = bytes(existing.size);
let sizeB = bytes(proposed.size);
if (isSmaller) {
sizeDiff = colors.red(sizeDiff);
dimensionsA = colors.green(dimensionsA);
sizeA = colors.green(sizeA);
} else {
sizeDiff = colors.green(sizeDiff);
dimensionsB = colors.green(dimensionsB);
sizeB = colors.green(sizeB);
}
table.push(['Path', existing.relative, proposed.relative, '']);
table.push(['Size', sizeA, sizeB, sizeDiff]);
table.push(['Dimensions', dimensionsA, dimensionsB, 'N/A']);
table.push(['Date created', birthtimeA, birthtimeB, 'N/A']);
table.push(['Date modified', mtimeA, mtimeB, 'N/A']);
return table.toString();
} | [
"function",
"diffImage",
"(",
"existing",
",",
"proposed",
",",
"options",
")",
"{",
"let",
"{",
"bytes",
",",
"dateformat",
",",
"imageSize",
",",
"Table",
",",
"toFile",
",",
"colors",
"}",
"=",
"utils",
";",
"existing",
"=",
"toFile",
"(",
"existing",
",",
"options",
")",
";",
"proposed",
"=",
"toFile",
"(",
"proposed",
",",
"options",
")",
";",
"let",
"table",
"=",
"new",
"Table",
"(",
"{",
"head",
":",
"[",
"'Attribute'",
",",
"'Existing'",
",",
"'Replacement'",
",",
"'Diff'",
"]",
"}",
")",
";",
"let",
"dimensionsA",
"=",
"imageSize",
"(",
"existing",
".",
"path",
")",
";",
"let",
"dimensionsB",
"=",
"imageSize",
"(",
"proposed",
".",
"path",
")",
";",
"let",
"statA",
"=",
"existing",
".",
"stat",
";",
"let",
"statB",
"=",
"proposed",
".",
"stat",
";",
"let",
"isSmaller",
"=",
"existing",
".",
"size",
">",
"proposed",
".",
"size",
";",
"let",
"sizeDiff",
"=",
"isSmaller",
"?",
"'-'",
":",
"'+'",
";",
"sizeDiff",
"+=",
"bytes",
"(",
"Math",
".",
"abs",
"(",
"existing",
".",
"size",
"-",
"proposed",
".",
"size",
")",
")",
";",
"// dates",
"let",
"mtimeA",
"=",
"statA",
"?",
"dateformat",
"(",
"statA",
".",
"mtime",
")",
":",
"'New'",
";",
"let",
"mtimeB",
"=",
"statB",
"?",
"dateformat",
"(",
"statB",
".",
"mtime",
")",
":",
"'New'",
";",
"if",
"(",
"statA",
".",
"mtime",
"&&",
"statB",
".",
"mtime",
"&&",
"statA",
".",
"mtime",
"<",
"statB",
".",
"mtime",
")",
"{",
"mtimeB",
"=",
"colors",
".",
"green",
"(",
"mtimeB",
")",
";",
"}",
"else",
"{",
"mtimeA",
"=",
"colors",
".",
"green",
"(",
"mtimeA",
")",
";",
"}",
"let",
"birthtimeA",
"=",
"statA",
"?",
"dateformat",
"(",
"statA",
".",
"birthtime",
")",
":",
"'New'",
";",
"let",
"birthtimeB",
"=",
"statB",
"?",
"dateformat",
"(",
"statB",
".",
"birthtime",
")",
":",
"'New'",
";",
"if",
"(",
"statA",
".",
"birthtime",
"&&",
"statB",
".",
"birthtime",
"&&",
"statA",
".",
"birthtime",
"<",
"statB",
".",
"birthtime",
")",
"{",
"birthtimeB",
"=",
"colors",
".",
"green",
"(",
"birthtimeB",
")",
";",
"}",
"else",
"{",
"birthtimeA",
"=",
"colors",
".",
"green",
"(",
"birthtimeA",
")",
";",
"}",
"// size",
"let",
"sizeA",
"=",
"bytes",
"(",
"existing",
".",
"size",
")",
";",
"let",
"sizeB",
"=",
"bytes",
"(",
"proposed",
".",
"size",
")",
";",
"if",
"(",
"isSmaller",
")",
"{",
"sizeDiff",
"=",
"colors",
".",
"red",
"(",
"sizeDiff",
")",
";",
"dimensionsA",
"=",
"colors",
".",
"green",
"(",
"dimensionsA",
")",
";",
"sizeA",
"=",
"colors",
".",
"green",
"(",
"sizeA",
")",
";",
"}",
"else",
"{",
"sizeDiff",
"=",
"colors",
".",
"green",
"(",
"sizeDiff",
")",
";",
"dimensionsB",
"=",
"colors",
".",
"green",
"(",
"dimensionsB",
")",
";",
"sizeB",
"=",
"colors",
".",
"green",
"(",
"sizeB",
")",
";",
"}",
"table",
".",
"push",
"(",
"[",
"'Path'",
",",
"existing",
".",
"relative",
",",
"proposed",
".",
"relative",
",",
"''",
"]",
")",
";",
"table",
".",
"push",
"(",
"[",
"'Size'",
",",
"sizeA",
",",
"sizeB",
",",
"sizeDiff",
"]",
")",
";",
"table",
".",
"push",
"(",
"[",
"'Dimensions'",
",",
"dimensionsA",
",",
"dimensionsB",
",",
"'N/A'",
"]",
")",
";",
"table",
".",
"push",
"(",
"[",
"'Date created'",
",",
"birthtimeA",
",",
"birthtimeB",
",",
"'N/A'",
"]",
")",
";",
"table",
".",
"push",
"(",
"[",
"'Date modified'",
",",
"mtimeA",
",",
"mtimeB",
",",
"'N/A'",
"]",
")",
";",
"return",
"table",
".",
"toString",
"(",
")",
";",
"}"
] | Shows table of the differences in stats between two binary files.
@param {String} `filepath` File path of the existing (old) file.
@param {Buffer} `contents` Buffered contents of the proposed (new) file. | [
"Shows",
"table",
"of",
"the",
"differences",
"in",
"stats",
"between",
"two",
"binary",
"files",
"."
] | 0f45ab63f6cc24a03ce381b3d2159283923bc20d | https://github.com/jonschlinkert/conflicts/blob/0f45ab63f6cc24a03ce381b3d2159283923bc20d/lib/diff.js#L114-L167 |
53,501 | moxystudio/react-redata | src/composition/compose.js | defaultShouldReload | function defaultShouldReload(items, params) {
// Go through all and check if any redata shouldReload.
for (const key in items) {
if (items[key].shouldReload(params)) {
return true;
}
}
return false;
} | javascript | function defaultShouldReload(items, params) {
// Go through all and check if any redata shouldReload.
for (const key in items) {
if (items[key].shouldReload(params)) {
return true;
}
}
return false;
} | [
"function",
"defaultShouldReload",
"(",
"items",
",",
"params",
")",
"{",
"// Go through all and check if any redata shouldReload.",
"for",
"(",
"const",
"key",
"in",
"items",
")",
"{",
"if",
"(",
"items",
"[",
"key",
"]",
".",
"shouldReload",
"(",
"params",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Default shouldReload that goes through each item redata and asks if the reload is necessary. If any says that it is, a redata happens. | [
"Default",
"shouldReload",
"that",
"goes",
"through",
"each",
"item",
"redata",
"and",
"asks",
"if",
"the",
"reload",
"is",
"necessary",
".",
"If",
"any",
"says",
"that",
"it",
"is",
"a",
"redata",
"happens",
"."
] | 19f5c548b8dbc3f71fb14077e9740f9dd62bb10a | https://github.com/moxystudio/react-redata/blob/19f5c548b8dbc3f71fb14077e9740f9dd62bb10a/src/composition/compose.js#L14-L23 |
53,502 | derikb/rpg-table-randomizer | src/random_name.js | function (number, name_type, create) {
const names = { male: [], female: [] };
if (typeof create === 'undefined') { create = false; }
if (typeof number === 'undefined') { number = 10; }
if (typeof name_type === 'undefined' || name_type === '') {
name_type = 'random';
}
for (let i = 1; i <= number; i++) {
const gender = (i <= Math.ceil(number / 2)) ? 'male' : 'female';
if (create && name_type !== 'holmesian' && name_type !== 'demonic') {
names[gender].push(createName(name_type, gender, true));
} else {
names[gender].push(selectName(name_type, gender));
}
}
return names;
} | javascript | function (number, name_type, create) {
const names = { male: [], female: [] };
if (typeof create === 'undefined') { create = false; }
if (typeof number === 'undefined') { number = 10; }
if (typeof name_type === 'undefined' || name_type === '') {
name_type = 'random';
}
for (let i = 1; i <= number; i++) {
const gender = (i <= Math.ceil(number / 2)) ? 'male' : 'female';
if (create && name_type !== 'holmesian' && name_type !== 'demonic') {
names[gender].push(createName(name_type, gender, true));
} else {
names[gender].push(selectName(name_type, gender));
}
}
return names;
} | [
"function",
"(",
"number",
",",
"name_type",
",",
"create",
")",
"{",
"const",
"names",
"=",
"{",
"male",
":",
"[",
"]",
",",
"female",
":",
"[",
"]",
"}",
";",
"if",
"(",
"typeof",
"create",
"===",
"'undefined'",
")",
"{",
"create",
"=",
"false",
";",
"}",
"if",
"(",
"typeof",
"number",
"===",
"'undefined'",
")",
"{",
"number",
"=",
"10",
";",
"}",
"if",
"(",
"typeof",
"name_type",
"===",
"'undefined'",
"||",
"name_type",
"===",
"''",
")",
"{",
"name_type",
"=",
"'random'",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<=",
"number",
";",
"i",
"++",
")",
"{",
"const",
"gender",
"=",
"(",
"i",
"<=",
"Math",
".",
"ceil",
"(",
"number",
"/",
"2",
")",
")",
"?",
"'male'",
":",
"'female'",
";",
"if",
"(",
"create",
"&&",
"name_type",
"!==",
"'holmesian'",
"&&",
"name_type",
"!==",
"'demonic'",
")",
"{",
"names",
"[",
"gender",
"]",
".",
"push",
"(",
"createName",
"(",
"name_type",
",",
"gender",
",",
"true",
")",
")",
";",
"}",
"else",
"{",
"names",
"[",
"gender",
"]",
".",
"push",
"(",
"selectName",
"(",
"name_type",
",",
"gender",
")",
")",
";",
"}",
"}",
"return",
"names",
";",
"}"
] | Generate a bunch of names, half male, half female
@param {Number} [number=10] number of names in the list (half will be male, half will be female)
@param {String} [name_type] type of name or else it will randomly select
@param {Bool} [create=false] new names or just pick from list
@return {Object} arrays of names inside male/female property | [
"Generate",
"a",
"bunch",
"of",
"names",
"half",
"male",
"half",
"female"
] | 988814794b1ee26c24c2a979646e4d13fdd2b7be | https://github.com/derikb/rpg-table-randomizer/blob/988814794b1ee26c24c2a979646e4d13fdd2b7be/src/random_name.js#L23-L40 |
|
53,503 | derikb/rpg-table-randomizer | src/random_name.js | function (name_type, gender, style) {
let name = '';
if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
// randomize a type...
name_type = randomizer.rollRandom(Object.keys(namedata.options));
}
if (typeof gender === 'undefined' || gender === 'random') {
// randomize a gender...
gender = randomizer.rollRandom(['male', 'female']);
}
if (typeof style === 'undefined' || style !== 'first') {
style = '';
}
switch (name_type) {
case 'holmesian':
name = holmesname();
break;
case 'demonic':
name = demonname();
break;
case 'cornish':
case 'flemish':
case 'dutch':
case 'turkish':
default:
name = randomizer.rollRandom(namedata[name_type][gender]);
if (style !== 'first' && typeof namedata[name_type]['surname'] !== 'undefined' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
name += ' ' + randomizer.rollRandom(namedata[name_type]['surname']);
}
name = randomizer.findToken(name).trim();
break;
}
return capitalizeName(name);
} | javascript | function (name_type, gender, style) {
let name = '';
if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
// randomize a type...
name_type = randomizer.rollRandom(Object.keys(namedata.options));
}
if (typeof gender === 'undefined' || gender === 'random') {
// randomize a gender...
gender = randomizer.rollRandom(['male', 'female']);
}
if (typeof style === 'undefined' || style !== 'first') {
style = '';
}
switch (name_type) {
case 'holmesian':
name = holmesname();
break;
case 'demonic':
name = demonname();
break;
case 'cornish':
case 'flemish':
case 'dutch':
case 'turkish':
default:
name = randomizer.rollRandom(namedata[name_type][gender]);
if (style !== 'first' && typeof namedata[name_type]['surname'] !== 'undefined' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
name += ' ' + randomizer.rollRandom(namedata[name_type]['surname']);
}
name = randomizer.findToken(name).trim();
break;
}
return capitalizeName(name);
} | [
"function",
"(",
"name_type",
",",
"gender",
",",
"style",
")",
"{",
"let",
"name",
"=",
"''",
";",
"if",
"(",
"typeof",
"name_type",
"===",
"'undefined'",
"||",
"name_type",
"===",
"''",
"||",
"name_type",
"===",
"'random'",
")",
"{",
"// randomize a type...",
"name_type",
"=",
"randomizer",
".",
"rollRandom",
"(",
"Object",
".",
"keys",
"(",
"namedata",
".",
"options",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"gender",
"===",
"'undefined'",
"||",
"gender",
"===",
"'random'",
")",
"{",
"// randomize a gender...",
"gender",
"=",
"randomizer",
".",
"rollRandom",
"(",
"[",
"'male'",
",",
"'female'",
"]",
")",
";",
"}",
"if",
"(",
"typeof",
"style",
"===",
"'undefined'",
"||",
"style",
"!==",
"'first'",
")",
"{",
"style",
"=",
"''",
";",
"}",
"switch",
"(",
"name_type",
")",
"{",
"case",
"'holmesian'",
":",
"name",
"=",
"holmesname",
"(",
")",
";",
"break",
";",
"case",
"'demonic'",
":",
"name",
"=",
"demonname",
"(",
")",
";",
"break",
";",
"case",
"'cornish'",
":",
"case",
"'flemish'",
":",
"case",
"'dutch'",
":",
"case",
"'turkish'",
":",
"default",
":",
"name",
"=",
"randomizer",
".",
"rollRandom",
"(",
"namedata",
"[",
"name_type",
"]",
"[",
"gender",
"]",
")",
";",
"if",
"(",
"style",
"!==",
"'first'",
"&&",
"typeof",
"namedata",
"[",
"name_type",
"]",
"[",
"'surname'",
"]",
"!==",
"'undefined'",
"&&",
"!",
"r_helpers",
".",
"isEmpty",
"(",
"namedata",
"[",
"name_type",
"]",
"[",
"'surname'",
"]",
")",
")",
"{",
"name",
"+=",
"' '",
"+",
"randomizer",
".",
"rollRandom",
"(",
"namedata",
"[",
"name_type",
"]",
"[",
"'surname'",
"]",
")",
";",
"}",
"name",
"=",
"randomizer",
".",
"findToken",
"(",
"name",
")",
".",
"trim",
"(",
")",
";",
"break",
";",
"}",
"return",
"capitalizeName",
"(",
"name",
")",
";",
"}"
] | Select a name from one of the lists
@param {String} name_type What name list/process to use else random
@param {String} gender male, female, random, ''
@param {String} style first=first name only, else full name
@returns {String} a name | [
"Select",
"a",
"name",
"from",
"one",
"of",
"the",
"lists"
] | 988814794b1ee26c24c2a979646e4d13fdd2b7be | https://github.com/derikb/rpg-table-randomizer/blob/988814794b1ee26c24c2a979646e4d13fdd2b7be/src/random_name.js#L48-L83 |
|
53,504 | derikb/rpg-table-randomizer | src/random_name.js | function (name_type, gender, style) {
if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
// randomize a type...
name_type = randomizer.rollRandom(Object.keys(namedata.options));
}
if (typeof style === 'undefined') { style = ''; }
if (!namedata[name_type]) { return ''; }
if (typeof gender === 'undefined' || (gender !== 'male' && gender !== 'female')) { gender = randomizer.rollRandom(['male', 'female']); }
const mkey = `${name_type}_${gender}`;
let lastname = '';
let thename = '';
if (!markov.memory) {
markov = new MarkovGenerator({ order: 3 });
}
if (!markov.memory[mkey]) {
// console.log('learn '+mkey);
let namelist = [];
if (gender === '') {
namelist = namedata[name_type]['male'];
namelist = namelist.concat(namedata[name_type]['female']);
} else {
namelist = namedata[name_type][gender];
}
namelist.forEach((v) => {
markov.learn(mkey, v);
});
}
if (style !== 'first' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
const skey = name_type + '_last';
if (!markov.memory[skey]) {
// console.log('learn surname '+skey);
const namelist = namedata[name_type]['surname'];
namelist.forEach((v) => {
markov.learn(skey, v);
});
}
lastname = markov.generate(skey);
}
thename = `${markov.generate(mkey)} ${lastname}`;
return capitalizeName(thename.trim());
} | javascript | function (name_type, gender, style) {
if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
// randomize a type...
name_type = randomizer.rollRandom(Object.keys(namedata.options));
}
if (typeof style === 'undefined') { style = ''; }
if (!namedata[name_type]) { return ''; }
if (typeof gender === 'undefined' || (gender !== 'male' && gender !== 'female')) { gender = randomizer.rollRandom(['male', 'female']); }
const mkey = `${name_type}_${gender}`;
let lastname = '';
let thename = '';
if (!markov.memory) {
markov = new MarkovGenerator({ order: 3 });
}
if (!markov.memory[mkey]) {
// console.log('learn '+mkey);
let namelist = [];
if (gender === '') {
namelist = namedata[name_type]['male'];
namelist = namelist.concat(namedata[name_type]['female']);
} else {
namelist = namedata[name_type][gender];
}
namelist.forEach((v) => {
markov.learn(mkey, v);
});
}
if (style !== 'first' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
const skey = name_type + '_last';
if (!markov.memory[skey]) {
// console.log('learn surname '+skey);
const namelist = namedata[name_type]['surname'];
namelist.forEach((v) => {
markov.learn(skey, v);
});
}
lastname = markov.generate(skey);
}
thename = `${markov.generate(mkey)} ${lastname}`;
return capitalizeName(thename.trim());
} | [
"function",
"(",
"name_type",
",",
"gender",
",",
"style",
")",
"{",
"if",
"(",
"typeof",
"name_type",
"===",
"'undefined'",
"||",
"name_type",
"===",
"''",
"||",
"name_type",
"===",
"'random'",
")",
"{",
"// randomize a type...",
"name_type",
"=",
"randomizer",
".",
"rollRandom",
"(",
"Object",
".",
"keys",
"(",
"namedata",
".",
"options",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"style",
"===",
"'undefined'",
")",
"{",
"style",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"namedata",
"[",
"name_type",
"]",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"typeof",
"gender",
"===",
"'undefined'",
"||",
"(",
"gender",
"!==",
"'male'",
"&&",
"gender",
"!==",
"'female'",
")",
")",
"{",
"gender",
"=",
"randomizer",
".",
"rollRandom",
"(",
"[",
"'male'",
",",
"'female'",
"]",
")",
";",
"}",
"const",
"mkey",
"=",
"`",
"${",
"name_type",
"}",
"${",
"gender",
"}",
"`",
";",
"let",
"lastname",
"=",
"''",
";",
"let",
"thename",
"=",
"''",
";",
"if",
"(",
"!",
"markov",
".",
"memory",
")",
"{",
"markov",
"=",
"new",
"MarkovGenerator",
"(",
"{",
"order",
":",
"3",
"}",
")",
";",
"}",
"if",
"(",
"!",
"markov",
".",
"memory",
"[",
"mkey",
"]",
")",
"{",
"// console.log('learn '+mkey);",
"let",
"namelist",
"=",
"[",
"]",
";",
"if",
"(",
"gender",
"===",
"''",
")",
"{",
"namelist",
"=",
"namedata",
"[",
"name_type",
"]",
"[",
"'male'",
"]",
";",
"namelist",
"=",
"namelist",
".",
"concat",
"(",
"namedata",
"[",
"name_type",
"]",
"[",
"'female'",
"]",
")",
";",
"}",
"else",
"{",
"namelist",
"=",
"namedata",
"[",
"name_type",
"]",
"[",
"gender",
"]",
";",
"}",
"namelist",
".",
"forEach",
"(",
"(",
"v",
")",
"=>",
"{",
"markov",
".",
"learn",
"(",
"mkey",
",",
"v",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"style",
"!==",
"'first'",
"&&",
"!",
"r_helpers",
".",
"isEmpty",
"(",
"namedata",
"[",
"name_type",
"]",
"[",
"'surname'",
"]",
")",
")",
"{",
"const",
"skey",
"=",
"name_type",
"+",
"'_last'",
";",
"if",
"(",
"!",
"markov",
".",
"memory",
"[",
"skey",
"]",
")",
"{",
"// console.log('learn surname '+skey);",
"const",
"namelist",
"=",
"namedata",
"[",
"name_type",
"]",
"[",
"'surname'",
"]",
";",
"namelist",
".",
"forEach",
"(",
"(",
"v",
")",
"=>",
"{",
"markov",
".",
"learn",
"(",
"skey",
",",
"v",
")",
";",
"}",
")",
";",
"}",
"lastname",
"=",
"markov",
".",
"generate",
"(",
"skey",
")",
";",
"}",
"thename",
"=",
"`",
"${",
"markov",
".",
"generate",
"(",
"mkey",
")",
"}",
"${",
"lastname",
"}",
"`",
";",
"return",
"capitalizeName",
"(",
"thename",
".",
"trim",
"(",
")",
")",
";",
"}"
] | Create a name using Markov chains
@param {String} [name_type=random] what list/process to use
@param {String} [gender=random] male or female or both
@param {String} style first=first name only, else full name
@returns {String} a name | [
"Create",
"a",
"name",
"using",
"Markov",
"chains"
] | 988814794b1ee26c24c2a979646e4d13fdd2b7be | https://github.com/derikb/rpg-table-randomizer/blob/988814794b1ee26c24c2a979646e4d13fdd2b7be/src/random_name.js#L120-L165 |
|
53,505 | derikb/rpg-table-randomizer | src/random_name.js | function (name) {
const leave_lower = ['of', 'the', 'from', 'de', 'le', 'la'];
// need to find spaces in name and capitalize letter after space
const parts = name.split(' ');
const upper_parts = parts.map((w) => {
return (leave_lower.indexOf(w) >= 0) ? w : `${r_helpers.capitalize(w)}`;
});
return upper_parts.join(' ');
} | javascript | function (name) {
const leave_lower = ['of', 'the', 'from', 'de', 'le', 'la'];
// need to find spaces in name and capitalize letter after space
const parts = name.split(' ');
const upper_parts = parts.map((w) => {
return (leave_lower.indexOf(w) >= 0) ? w : `${r_helpers.capitalize(w)}`;
});
return upper_parts.join(' ');
} | [
"function",
"(",
"name",
")",
"{",
"const",
"leave_lower",
"=",
"[",
"'of'",
",",
"'the'",
",",
"'from'",
",",
"'de'",
",",
"'le'",
",",
"'la'",
"]",
";",
"// need to find spaces in name and capitalize letter after space",
"const",
"parts",
"=",
"name",
".",
"split",
"(",
"' '",
")",
";",
"const",
"upper_parts",
"=",
"parts",
".",
"map",
"(",
"(",
"w",
")",
"=>",
"{",
"return",
"(",
"leave_lower",
".",
"indexOf",
"(",
"w",
")",
">=",
"0",
")",
"?",
"w",
":",
"`",
"${",
"r_helpers",
".",
"capitalize",
"(",
"w",
")",
"}",
"`",
";",
"}",
")",
";",
"return",
"upper_parts",
".",
"join",
"(",
"' '",
")",
";",
"}"
] | Capitalize names, account for multiword lastnames like "Van Hausen"
@param {String} name a name
@return {String} name capitalized | [
"Capitalize",
"names",
"account",
"for",
"multiword",
"lastnames",
"like",
"Van",
"Hausen"
] | 988814794b1ee26c24c2a979646e4d13fdd2b7be | https://github.com/derikb/rpg-table-randomizer/blob/988814794b1ee26c24c2a979646e4d13fdd2b7be/src/random_name.js#L171-L179 |
|
53,506 | derikb/rpg-table-randomizer | src/random_name.js | function () {
let name = '';
const scount = randomizer.getWeightedRandom(namedata.holmesian_scount.values, namedata.holmesian_scount.weights);
for (let i = 1; i <= scount; i++) {
name += randomizer.rollRandom(namedata.holmesian_syllables); // array
if (i < scount) {
name += randomizer.getWeightedRandom(['', ' ', '-'], [3, 2, 2]);
}
}
name = name.toLowerCase() + ' ' + randomizer.rollRandom(namedata.holmesian_title);
name = randomizer.findToken(name);
name = name.replace(/[\s\-]([a-z]{1})/g, (match) => {
return match.toUpperCase();
});
return name;
} | javascript | function () {
let name = '';
const scount = randomizer.getWeightedRandom(namedata.holmesian_scount.values, namedata.holmesian_scount.weights);
for (let i = 1; i <= scount; i++) {
name += randomizer.rollRandom(namedata.holmesian_syllables); // array
if (i < scount) {
name += randomizer.getWeightedRandom(['', ' ', '-'], [3, 2, 2]);
}
}
name = name.toLowerCase() + ' ' + randomizer.rollRandom(namedata.holmesian_title);
name = randomizer.findToken(name);
name = name.replace(/[\s\-]([a-z]{1})/g, (match) => {
return match.toUpperCase();
});
return name;
} | [
"function",
"(",
")",
"{",
"let",
"name",
"=",
"''",
";",
"const",
"scount",
"=",
"randomizer",
".",
"getWeightedRandom",
"(",
"namedata",
".",
"holmesian_scount",
".",
"values",
",",
"namedata",
".",
"holmesian_scount",
".",
"weights",
")",
";",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<=",
"scount",
";",
"i",
"++",
")",
"{",
"name",
"+=",
"randomizer",
".",
"rollRandom",
"(",
"namedata",
".",
"holmesian_syllables",
")",
";",
"// array",
"if",
"(",
"i",
"<",
"scount",
")",
"{",
"name",
"+=",
"randomizer",
".",
"getWeightedRandom",
"(",
"[",
"''",
",",
"' '",
",",
"'-'",
"]",
",",
"[",
"3",
",",
"2",
",",
"2",
"]",
")",
";",
"}",
"}",
"name",
"=",
"name",
".",
"toLowerCase",
"(",
")",
"+",
"' '",
"+",
"randomizer",
".",
"rollRandom",
"(",
"namedata",
".",
"holmesian_title",
")",
";",
"name",
"=",
"randomizer",
".",
"findToken",
"(",
"name",
")",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"/",
"[\\s\\-]([a-z]{1})",
"/",
"g",
",",
"(",
"match",
")",
"=>",
"{",
"return",
"match",
".",
"toUpperCase",
"(",
")",
";",
"}",
")",
";",
"return",
"name",
";",
"}"
] | Generate a Holmes name
@returns {String} name | [
"Generate",
"a",
"Holmes",
"name"
] | 988814794b1ee26c24c2a979646e4d13fdd2b7be | https://github.com/derikb/rpg-table-randomizer/blob/988814794b1ee26c24c2a979646e4d13fdd2b7be/src/random_name.js#L184-L202 |
|
53,507 | spacemaus/postvox | vox-common/chain.js | isPromise | function isPromise(v) {
return v && v.isFulfilled && v.then && v.catch && v.value;
} | javascript | function isPromise(v) {
return v && v.isFulfilled && v.then && v.catch && v.value;
} | [
"function",
"isPromise",
"(",
"v",
")",
"{",
"return",
"v",
"&&",
"v",
".",
"isFulfilled",
"&&",
"v",
".",
"then",
"&&",
"v",
".",
"catch",
"&&",
"v",
".",
"value",
";",
"}"
] | instanceof doesn't seem to work across modules. | [
"instanceof",
"doesn",
"t",
"seem",
"to",
"work",
"across",
"modules",
"."
] | de98e5ed37edaee1b1edadf93e15eb8f8d21f457 | https://github.com/spacemaus/postvox/blob/de98e5ed37edaee1b1edadf93e15eb8f8d21f457/vox-common/chain.js#L98-L100 |
53,508 | nodejitsu/npm-documentation-pagelet | npm.js | Help | function Help(filename, path, github, preprocess) {
if (!(this instanceof Help)) return new Help(filename, path, preprocess);
this.html = '';
this.path = path;
this.github = github;
this.filename = filename;
this.preprocess = preprocess;
this.url = filename.slice(0, -3);
this.title = filename.slice(0, -3).replace(/\-/g, ' ');
if (this.title in Help.rename) {
this.title = Help.rename[this.title];
}
} | javascript | function Help(filename, path, github, preprocess) {
if (!(this instanceof Help)) return new Help(filename, path, preprocess);
this.html = '';
this.path = path;
this.github = github;
this.filename = filename;
this.preprocess = preprocess;
this.url = filename.slice(0, -3);
this.title = filename.slice(0, -3).replace(/\-/g, ' ');
if (this.title in Help.rename) {
this.title = Help.rename[this.title];
}
} | [
"function",
"Help",
"(",
"filename",
",",
"path",
",",
"github",
",",
"preprocess",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Help",
")",
")",
"return",
"new",
"Help",
"(",
"filename",
",",
"path",
",",
"preprocess",
")",
";",
"this",
".",
"html",
"=",
"''",
";",
"this",
".",
"path",
"=",
"path",
";",
"this",
".",
"github",
"=",
"github",
";",
"this",
".",
"filename",
"=",
"filename",
";",
"this",
".",
"preprocess",
"=",
"preprocess",
";",
"this",
".",
"url",
"=",
"filename",
".",
"slice",
"(",
"0",
",",
"-",
"3",
")",
";",
"this",
".",
"title",
"=",
"filename",
".",
"slice",
"(",
"0",
",",
"-",
"3",
")",
".",
"replace",
"(",
"/",
"\\-",
"/",
"g",
",",
"' '",
")",
";",
"if",
"(",
"this",
".",
"title",
"in",
"Help",
".",
"rename",
")",
"{",
"this",
".",
"title",
"=",
"Help",
".",
"rename",
"[",
"this",
".",
"title",
"]",
";",
"}",
"}"
] | Representation of a single HELP document.
@constructor
@param {String} filename The name of the help file.
@param {String} path The absolute location of the file.
@param {Object} github Github user/repo of the help files.
@param {Function} preprocess Optional content pre-processor.
@api public | [
"Representation",
"of",
"a",
"single",
"HELP",
"document",
"."
] | d45006c68cad8f14c63fd86b6be6f8569d5a1a09 | https://github.com/nodejitsu/npm-documentation-pagelet/blob/d45006c68cad8f14c63fd86b6be6f8569d5a1a09/npm.js#L19-L33 |
53,509 | ericmorand/generator-ahead | lib/util/prompt-suggestion.js | function (question, defaultValue) {
// For simplicity we uncheck all boxes and
// use .default to set the active ones.
_.each(question.choices, function (choice) {
if (typeof choice === 'object') {
choice.checked = false;
}
});
return defaultValue;
} | javascript | function (question, defaultValue) {
// For simplicity we uncheck all boxes and
// use .default to set the active ones.
_.each(question.choices, function (choice) {
if (typeof choice === 'object') {
choice.checked = false;
}
});
return defaultValue;
} | [
"function",
"(",
"question",
",",
"defaultValue",
")",
"{",
"// For simplicity we uncheck all boxes and",
"// use .default to set the active ones.",
"_",
".",
"each",
"(",
"question",
".",
"choices",
",",
"function",
"(",
"choice",
")",
"{",
"if",
"(",
"typeof",
"choice",
"===",
"'object'",
")",
"{",
"choice",
".",
"checked",
"=",
"false",
";",
"}",
"}",
")",
";",
"return",
"defaultValue",
";",
"}"
] | Returns the default value for a checkbox.
@param {Object} question Inquirer prompt item
@param {*} defaultValue The stored default value
@return {*} Default value to set
@private | [
"Returns",
"the",
"default",
"value",
"for",
"a",
"checkbox",
"."
] | 7d9d67e5996881c2b47333f9ae57db7cd4e3cb42 | https://github.com/ericmorand/generator-ahead/blob/7d9d67e5996881c2b47333f9ae57db7cd4e3cb42/lib/util/prompt-suggestion.js#L19-L29 |
|
53,510 | ericmorand/generator-ahead | lib/util/prompt-suggestion.js | function (question, defaultValue) {
var choiceValues = _.map(question.choices, function (choice) {
if (typeof choice === 'object') {
return choice.value;
} else {
return choice;
}
});
return choiceValues.indexOf(defaultValue);
} | javascript | function (question, defaultValue) {
var choiceValues = _.map(question.choices, function (choice) {
if (typeof choice === 'object') {
return choice.value;
} else {
return choice;
}
});
return choiceValues.indexOf(defaultValue);
} | [
"function",
"(",
"question",
",",
"defaultValue",
")",
"{",
"var",
"choiceValues",
"=",
"_",
".",
"map",
"(",
"question",
".",
"choices",
",",
"function",
"(",
"choice",
")",
"{",
"if",
"(",
"typeof",
"choice",
"===",
"'object'",
")",
"{",
"return",
"choice",
".",
"value",
";",
"}",
"else",
"{",
"return",
"choice",
";",
"}",
"}",
")",
";",
"return",
"choiceValues",
".",
"indexOf",
"(",
"defaultValue",
")",
";",
"}"
] | Returns the default value for a list.
@param {Object} question Inquirer prompt item
@param {*} defaultValue The stored default value
@return {*} Default value to set
@private | [
"Returns",
"the",
"default",
"value",
"for",
"a",
"list",
"."
] | 7d9d67e5996881c2b47333f9ae57db7cd4e3cb42 | https://github.com/ericmorand/generator-ahead/blob/7d9d67e5996881c2b47333f9ae57db7cd4e3cb42/lib/util/prompt-suggestion.js#L39-L49 |
|
53,511 | ericmorand/generator-ahead | lib/util/prompt-suggestion.js | function (question, answer) {
var choiceValues = _.map(question.choices, 'value');
var choiceIndex = choiceValues.indexOf(answer);
// Check if answer is not equal to default value
if (question.default !== choiceIndex) {
return true;
}
return false;
} | javascript | function (question, answer) {
var choiceValues = _.map(question.choices, 'value');
var choiceIndex = choiceValues.indexOf(answer);
// Check if answer is not equal to default value
if (question.default !== choiceIndex) {
return true;
}
return false;
} | [
"function",
"(",
"question",
",",
"answer",
")",
"{",
"var",
"choiceValues",
"=",
"_",
".",
"map",
"(",
"question",
".",
"choices",
",",
"'value'",
")",
";",
"var",
"choiceIndex",
"=",
"choiceValues",
".",
"indexOf",
"(",
"answer",
")",
";",
"// Check if answer is not equal to default value",
"if",
"(",
"question",
".",
"default",
"!==",
"choiceIndex",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Return true if the answer should be store in
the global store, otherwise false.
@param {Object} question Inquirer prompt item
@param {String|Array} answer The inquirer answer
@return {Boolean} Answer to be stored
@private | [
"Return",
"true",
"if",
"the",
"answer",
"should",
"be",
"store",
"in",
"the",
"global",
"store",
"otherwise",
"false",
"."
] | 7d9d67e5996881c2b47333f9ae57db7cd4e3cb42 | https://github.com/ericmorand/generator-ahead/blob/7d9d67e5996881c2b47333f9ae57db7cd4e3cb42/lib/util/prompt-suggestion.js#L60-L70 |
|
53,512 | aledbf/deis-api | lib/ps.js | scale | function scale(appName, configuration, callback) {
if (!isObject(configuration)) {
return callback(new Error('To scale pass an object with the type as key'));
}
var url = format('/%s/apps/%s/scale/', deis.version, appName);
commons.post(url, configuration, 204, callback);
} | javascript | function scale(appName, configuration, callback) {
if (!isObject(configuration)) {
return callback(new Error('To scale pass an object with the type as key'));
}
var url = format('/%s/apps/%s/scale/', deis.version, appName);
commons.post(url, configuration, 204, callback);
} | [
"function",
"scale",
"(",
"appName",
",",
"configuration",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"isObject",
"(",
"configuration",
")",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'To scale pass an object with the type as key'",
")",
")",
";",
"}",
"var",
"url",
"=",
"format",
"(",
"'/%s/apps/%s/scale/'",
",",
"deis",
".",
"version",
",",
"appName",
")",
";",
"commons",
".",
"post",
"(",
"url",
",",
"configuration",
",",
"204",
",",
"callback",
")",
";",
"}"
] | scale an application | [
"scale",
"an",
"application"
] | f0833789998032b11221a3a617bb566ade1fcc13 | https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/ps.js#L11-L18 |
53,513 | aledbf/deis-api | lib/ps.js | byType | function byType(appName, type, callback) {
var url = format('/%s/apps/%s/containers/%s/', deis.version, appName, type);
commons.get(url, callback);
} | javascript | function byType(appName, type, callback) {
var url = format('/%s/apps/%s/containers/%s/', deis.version, appName, type);
commons.get(url, callback);
} | [
"function",
"byType",
"(",
"appName",
",",
"type",
",",
"callback",
")",
"{",
"var",
"url",
"=",
"format",
"(",
"'/%s/apps/%s/containers/%s/'",
",",
"deis",
".",
"version",
",",
"appName",
",",
"type",
")",
";",
"commons",
".",
"get",
"(",
"url",
",",
"callback",
")",
";",
"}"
] | list application containers and their status | [
"list",
"application",
"containers",
"and",
"their",
"status"
] | f0833789998032b11221a3a617bb566ade1fcc13 | https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/ps.js#L30-L33 |
53,514 | lesx/lesx-jsx | lib/babel-core/src/config/index.js | loadConfig | function loadConfig(opts) {
if (opts != null && (typeof opts === "undefined" ? "undefined" : (0, _typeof3.default)(opts)) !== "object") {
throw new Error("Babel options must be an object, null, or undefined");
}
return (0, _optionManager2.default)(opts || {});
} | javascript | function loadConfig(opts) {
if (opts != null && (typeof opts === "undefined" ? "undefined" : (0, _typeof3.default)(opts)) !== "object") {
throw new Error("Babel options must be an object, null, or undefined");
}
return (0, _optionManager2.default)(opts || {});
} | [
"function",
"loadConfig",
"(",
"opts",
")",
"{",
"if",
"(",
"opts",
"!=",
"null",
"&&",
"(",
"typeof",
"opts",
"===",
"\"undefined\"",
"?",
"\"undefined\"",
":",
"(",
"0",
",",
"_typeof3",
".",
"default",
")",
"(",
"opts",
")",
")",
"!==",
"\"object\"",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Babel options must be an object, null, or undefined\"",
")",
";",
"}",
"return",
"(",
"0",
",",
"_optionManager2",
".",
"default",
")",
"(",
"opts",
"||",
"{",
"}",
")",
";",
"}"
] | Standard API for loading Babel configuration data. Not for public consumption. | [
"Standard",
"API",
"for",
"loading",
"Babel",
"configuration",
"data",
".",
"Not",
"for",
"public",
"consumption",
"."
] | 6b82f5ee115add3fb61b83c8e22e83fad66ad437 | https://github.com/lesx/lesx-jsx/blob/6b82f5ee115add3fb61b83c8e22e83fad66ad437/lib/babel-core/src/config/index.js#L24-L30 |
53,515 | davidfig/dom-ease | docs/code.js | createVelocity | function createVelocity()
{
const duration = 2000
const easing = 'easeInOutSine'
Velocity(box('scaleX'), { scaleX: 2 }, { duration, easing, loop: true })
Velocity(box('scaleY'), { scaleY: 2 }, { duration, easing, loop: true })
Velocity(box('top/left'), { left: window.innerWidth / 2, top: window.innerHeight / 2 }, { duration, easing, loop: true })
Velocity(box('scale'), { scale: 0 }, { duration, easing, loop: true })
// Velocity(box('backgroundColor'), { backgroundColor: ['red', 'blue', 'transparent'] }, { duration, easing, loop: true })
Velocity(box('opacity'), { opacity: 0 }, { duration, easing, loop: true })
Velocity(box('width'), { width: SIZE * 2 }, { duration, easing, loop: true })
Velocity(box('height'), { height: 0 }, { duration, easing, loop: true })
// Velocity(box('color'), { color: ['green', 'yellow', 'purple'] }, { duration, easing, loop: true })
} | javascript | function createVelocity()
{
const duration = 2000
const easing = 'easeInOutSine'
Velocity(box('scaleX'), { scaleX: 2 }, { duration, easing, loop: true })
Velocity(box('scaleY'), { scaleY: 2 }, { duration, easing, loop: true })
Velocity(box('top/left'), { left: window.innerWidth / 2, top: window.innerHeight / 2 }, { duration, easing, loop: true })
Velocity(box('scale'), { scale: 0 }, { duration, easing, loop: true })
// Velocity(box('backgroundColor'), { backgroundColor: ['red', 'blue', 'transparent'] }, { duration, easing, loop: true })
Velocity(box('opacity'), { opacity: 0 }, { duration, easing, loop: true })
Velocity(box('width'), { width: SIZE * 2 }, { duration, easing, loop: true })
Velocity(box('height'), { height: 0 }, { duration, easing, loop: true })
// Velocity(box('color'), { color: ['green', 'yellow', 'purple'] }, { duration, easing, loop: true })
} | [
"function",
"createVelocity",
"(",
")",
"{",
"const",
"duration",
"=",
"2000",
"const",
"easing",
"=",
"'easeInOutSine'",
"Velocity",
"(",
"box",
"(",
"'scaleX'",
")",
",",
"{",
"scaleX",
":",
"2",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"Velocity",
"(",
"box",
"(",
"'scaleY'",
")",
",",
"{",
"scaleY",
":",
"2",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"Velocity",
"(",
"box",
"(",
"'top/left'",
")",
",",
"{",
"left",
":",
"window",
".",
"innerWidth",
"/",
"2",
",",
"top",
":",
"window",
".",
"innerHeight",
"/",
"2",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"Velocity",
"(",
"box",
"(",
"'scale'",
")",
",",
"{",
"scale",
":",
"0",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"// Velocity(box('backgroundColor'), { backgroundColor: ['red', 'blue', 'transparent'] }, { duration, easing, loop: true })\r",
"Velocity",
"(",
"box",
"(",
"'opacity'",
")",
",",
"{",
"opacity",
":",
"0",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"Velocity",
"(",
"box",
"(",
"'width'",
")",
",",
"{",
"width",
":",
"SIZE",
"*",
"2",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"Velocity",
"(",
"box",
"(",
"'height'",
")",
",",
"{",
"height",
":",
"0",
"}",
",",
"{",
"duration",
",",
"easing",
",",
"loop",
":",
"true",
"}",
")",
"// Velocity(box('color'), { color: ['green', 'yellow', 'purple'] }, { duration, easing, loop: true })\r",
"}"
] | compare speed with velocity-animate | [
"compare",
"speed",
"with",
"velocity",
"-",
"animate"
] | 4abc692d968593dd41546bb4d2fc7d9d861e8007 | https://github.com/davidfig/dom-ease/blob/4abc692d968593dd41546bb4d2fc7d9d861e8007/docs/code.js#L49-L62 |
53,516 | thlorenz/node-traceur | src/node/inline-module.js | wrapProgram | function wrapProgram(tree, url, commonPath) {
var name = generateNameForUrl(url, commonPath);
return new Program(null,
[new ModuleDefinition(null,
createIdentifierToken(name), tree.programElements)]);
} | javascript | function wrapProgram(tree, url, commonPath) {
var name = generateNameForUrl(url, commonPath);
return new Program(null,
[new ModuleDefinition(null,
createIdentifierToken(name), tree.programElements)]);
} | [
"function",
"wrapProgram",
"(",
"tree",
",",
"url",
",",
"commonPath",
")",
"{",
"var",
"name",
"=",
"generateNameForUrl",
"(",
"url",
",",
"commonPath",
")",
";",
"return",
"new",
"Program",
"(",
"null",
",",
"[",
"new",
"ModuleDefinition",
"(",
"null",
",",
"createIdentifierToken",
"(",
"name",
")",
",",
"tree",
".",
"programElements",
")",
"]",
")",
";",
"}"
] | Wraps a program in a module definition.
@param {ProgramTree} tree The original program tree.
@param {string} url The relative URL of the module that the program
represents.
@param {string} commonPath The base path of all the files. This is passed
along to |generateNameForUrl|.
@return {[ProgramTree} A new program tree with only one statement, which is
a module definition. | [
"Wraps",
"a",
"program",
"in",
"a",
"module",
"definition",
"."
] | 79a21ad03831ba36df504988b05022404ad8f9c3 | https://github.com/thlorenz/node-traceur/blob/79a21ad03831ba36df504988b05022404ad8f9c3/src/node/inline-module.js#L51-L56 |
53,517 | thlorenz/node-traceur | src/node/inline-module.js | inlineAndCompile | function inlineAndCompile(filenames, options, reporter, callback, errback) {
// The caller needs to do a chdir.
var basePath = './';
var depTarget = options && options.depTarget;
var loadCount = 0;
var elements = [];
var project = new Project(basePath);
var loader = new InlineCodeLoader(reporter, project, elements, depTarget);
function loadNext() {
var codeUnit = loader.load(filenames[loadCount]);
startCodeUnit = codeUnit;
codeUnit.addListener(function() {
loadCount++;
if (loadCount < filenames.length) {
loadNext();
} else if (depTarget) {
callback(null);
} else {
var tree = allLoaded(basePath, reporter, elements);
callback(tree);
}
}, function() {
console.error(codeUnit.loader.error);
errback(codeUnit.loader.error);
});
}
loadNext();
} | javascript | function inlineAndCompile(filenames, options, reporter, callback, errback) {
// The caller needs to do a chdir.
var basePath = './';
var depTarget = options && options.depTarget;
var loadCount = 0;
var elements = [];
var project = new Project(basePath);
var loader = new InlineCodeLoader(reporter, project, elements, depTarget);
function loadNext() {
var codeUnit = loader.load(filenames[loadCount]);
startCodeUnit = codeUnit;
codeUnit.addListener(function() {
loadCount++;
if (loadCount < filenames.length) {
loadNext();
} else if (depTarget) {
callback(null);
} else {
var tree = allLoaded(basePath, reporter, elements);
callback(tree);
}
}, function() {
console.error(codeUnit.loader.error);
errback(codeUnit.loader.error);
});
}
loadNext();
} | [
"function",
"inlineAndCompile",
"(",
"filenames",
",",
"options",
",",
"reporter",
",",
"callback",
",",
"errback",
")",
"{",
"// The caller needs to do a chdir.",
"var",
"basePath",
"=",
"'./'",
";",
"var",
"depTarget",
"=",
"options",
"&&",
"options",
".",
"depTarget",
";",
"var",
"loadCount",
"=",
"0",
";",
"var",
"elements",
"=",
"[",
"]",
";",
"var",
"project",
"=",
"new",
"Project",
"(",
"basePath",
")",
";",
"var",
"loader",
"=",
"new",
"InlineCodeLoader",
"(",
"reporter",
",",
"project",
",",
"elements",
",",
"depTarget",
")",
";",
"function",
"loadNext",
"(",
")",
"{",
"var",
"codeUnit",
"=",
"loader",
".",
"load",
"(",
"filenames",
"[",
"loadCount",
"]",
")",
";",
"startCodeUnit",
"=",
"codeUnit",
";",
"codeUnit",
".",
"addListener",
"(",
"function",
"(",
")",
"{",
"loadCount",
"++",
";",
"if",
"(",
"loadCount",
"<",
"filenames",
".",
"length",
")",
"{",
"loadNext",
"(",
")",
";",
"}",
"else",
"if",
"(",
"depTarget",
")",
"{",
"callback",
"(",
"null",
")",
";",
"}",
"else",
"{",
"var",
"tree",
"=",
"allLoaded",
"(",
"basePath",
",",
"reporter",
",",
"elements",
")",
";",
"callback",
"(",
"tree",
")",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"console",
".",
"error",
"(",
"codeUnit",
".",
"loader",
".",
"error",
")",
";",
"errback",
"(",
"codeUnit",
".",
"loader",
".",
"error",
")",
";",
"}",
")",
";",
"}",
"loadNext",
"(",
")",
";",
"}"
] | Compiles the files in "filenames" along with any associated modules, into a
single js file, in proper module dependency order.
@param {Array.<string>} filenames The list of files to compile and concat.
@param {Object} options A container for misc options. 'depTarget' is the
only currently available option, which results in the dependencies for
'filenames' being printed to stdout, with 'depTarget' as the target.
@param {ErrorReporter} reporter
@param {Function} callback Callback used to return the result. A null result
indicates that inlineAndCompile has returned successfully from a
non-compile request.
@param {Function} errback Callback used to return errors. | [
"Compiles",
"the",
"files",
"in",
"filenames",
"along",
"with",
"any",
"associated",
"modules",
"into",
"a",
"single",
"js",
"file",
"in",
"proper",
"module",
"dependency",
"order",
"."
] | 79a21ad03831ba36df504988b05022404ad8f9c3 | https://github.com/thlorenz/node-traceur/blob/79a21ad03831ba36df504988b05022404ad8f9c3/src/node/inline-module.js#L181-L213 |
53,518 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_util_copyAll | function sn_util_copyAll(obj1, obj2) {
var keys = Object.getOwnPropertyNames(obj1), i, len, key, desc;
if (obj2 === undefined) {
obj2 = {};
}
for (i = 0, len = keys.length; i < len; i += 1) {
key = keys[i];
desc = Object.getOwnPropertyDescriptor(obj1, key);
if (desc) {
Object.defineProperty(obj2, key, desc);
} else {
obj2[key] = obj1[key];
}
}
return obj2;
} | javascript | function sn_util_copyAll(obj1, obj2) {
var keys = Object.getOwnPropertyNames(obj1), i, len, key, desc;
if (obj2 === undefined) {
obj2 = {};
}
for (i = 0, len = keys.length; i < len; i += 1) {
key = keys[i];
desc = Object.getOwnPropertyDescriptor(obj1, key);
if (desc) {
Object.defineProperty(obj2, key, desc);
} else {
obj2[key] = obj1[key];
}
}
return obj2;
} | [
"function",
"sn_util_copyAll",
"(",
"obj1",
",",
"obj2",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"obj1",
")",
",",
"i",
",",
"len",
",",
"key",
",",
"desc",
";",
"if",
"(",
"obj2",
"===",
"undefined",
")",
"{",
"obj2",
"=",
"{",
"}",
";",
"}",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"1",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"desc",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj1",
",",
"key",
")",
";",
"if",
"(",
"desc",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"obj2",
",",
"key",
",",
"desc",
")",
";",
"}",
"else",
"{",
"obj2",
"[",
"key",
"]",
"=",
"obj1",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"obj2",
";",
"}"
] | Copy the enumerable and non-enumerable own properties of `obj` onto `obj2` and return `obj2`.
@param {Object} obj1 - The object to copy enumerable properties from.
@param {Object} [obj2] - The optional object to copy the properties to. If not
provided a new object will be created.
@returns {Object} The object whose properties were copied to.
@since 0.0.5
@preserve | [
"Copy",
"the",
"enumerable",
"and",
"non",
"-",
"enumerable",
"own",
"properties",
"of",
"obj",
"onto",
"obj2",
"and",
"return",
"obj2",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L86-L101 |
53,519 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_util_merge | function sn_util_merge(obj1, obj2) {
var prop, desc;
if (obj2 === undefined) {
obj2 = {};
}
for (prop in obj1) {
if (obj1.hasOwnProperty(prop) && obj2[prop] === undefined) {
desc = Object.getOwnPropertyDescriptor(obj1, prop);
if (desc) {
Object.defineProperty(obj2, prop, desc);
} else {
obj2[prop] = obj1[prop];
}
}
}
return obj2;
} | javascript | function sn_util_merge(obj1, obj2) {
var prop, desc;
if (obj2 === undefined) {
obj2 = {};
}
for (prop in obj1) {
if (obj1.hasOwnProperty(prop) && obj2[prop] === undefined) {
desc = Object.getOwnPropertyDescriptor(obj1, prop);
if (desc) {
Object.defineProperty(obj2, prop, desc);
} else {
obj2[prop] = obj1[prop];
}
}
}
return obj2;
} | [
"function",
"sn_util_merge",
"(",
"obj1",
",",
"obj2",
")",
"{",
"var",
"prop",
",",
"desc",
";",
"if",
"(",
"obj2",
"===",
"undefined",
")",
"{",
"obj2",
"=",
"{",
"}",
";",
"}",
"for",
"(",
"prop",
"in",
"obj1",
")",
"{",
"if",
"(",
"obj1",
".",
"hasOwnProperty",
"(",
"prop",
")",
"&&",
"obj2",
"[",
"prop",
"]",
"===",
"undefined",
")",
"{",
"desc",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj1",
",",
"prop",
")",
";",
"if",
"(",
"desc",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"obj2",
",",
"prop",
",",
"desc",
")",
";",
"}",
"else",
"{",
"obj2",
"[",
"prop",
"]",
"=",
"obj1",
"[",
"prop",
"]",
";",
"}",
"}",
"}",
"return",
"obj2",
";",
"}"
] | Copy the enumerable own properties of `obj1` that don't already exist on `obj2` into `obj2` and return `obj2`.
@param {Object} obj1 - The object to copy enumerable properties from.
@param {Object} [obj2] - The optional object to copy the properties to. If not
provided a new object will be created.
@returns {Object} The object whose properties were copied to.
@since 0.14.0
@preserve | [
"Copy",
"the",
"enumerable",
"own",
"properties",
"of",
"obj1",
"that",
"don",
"t",
"already",
"exist",
"on",
"obj2",
"into",
"obj2",
"and",
"return",
"obj2",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L112-L128 |
53,520 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_util_arraysAreEqual | function sn_util_arraysAreEqual(a1, a2) {
var i, len;
if (!(Array.isArray(a1) && Array.isArray(a2))) {
return false;
}
if (a1.length !== a2.length) {
return false;
}
for (i = 0, len = a1.length; i < len; i += 1) {
if (Array.isArray(a1[i]) && Array.isArray(a2[i]) && arraysAreEqual(a1[i], a2[i]) !== true) {
return false;
} else if (a1[i] !== a2[i]) {
return false;
}
}
return true;
} | javascript | function sn_util_arraysAreEqual(a1, a2) {
var i, len;
if (!(Array.isArray(a1) && Array.isArray(a2))) {
return false;
}
if (a1.length !== a2.length) {
return false;
}
for (i = 0, len = a1.length; i < len; i += 1) {
if (Array.isArray(a1[i]) && Array.isArray(a2[i]) && arraysAreEqual(a1[i], a2[i]) !== true) {
return false;
} else if (a1[i] !== a2[i]) {
return false;
}
}
return true;
} | [
"function",
"sn_util_arraysAreEqual",
"(",
"a1",
",",
"a2",
")",
"{",
"var",
"i",
",",
"len",
";",
"if",
"(",
"!",
"(",
"Array",
".",
"isArray",
"(",
"a1",
")",
"&&",
"Array",
".",
"isArray",
"(",
"a2",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"a1",
".",
"length",
"!==",
"a2",
".",
"length",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"a1",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"1",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"a1",
"[",
"i",
"]",
")",
"&&",
"Array",
".",
"isArray",
"(",
"a2",
"[",
"i",
"]",
")",
"&&",
"arraysAreEqual",
"(",
"a1",
"[",
"i",
"]",
",",
"a2",
"[",
"i",
"]",
")",
"!==",
"true",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"a1",
"[",
"i",
"]",
"!==",
"a2",
"[",
"i",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Compare two arrays for equality, that is they have the same length and same values
using strict quality.
@param {Array} a1 The first array to compare.
@param {Array} a2 The second array to compare.
@return {Boolean} True if the arrays are equal.
@since 0.2.0
@preserve | [
"Compare",
"two",
"arrays",
"for",
"equality",
"that",
"is",
"they",
"have",
"the",
"same",
"length",
"and",
"same",
"values",
"using",
"strict",
"quality",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L139-L155 |
53,521 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_util_superMethod | function sn_util_superMethod(name) {
var that = this, method = that[name];
return function() {
return method.apply(that, arguments);
};
} | javascript | function sn_util_superMethod(name) {
var that = this, method = that[name];
return function() {
return method.apply(that, arguments);
};
} | [
"function",
"sn_util_superMethod",
"(",
"name",
")",
"{",
"var",
"that",
"=",
"this",
",",
"method",
"=",
"that",
"[",
"name",
"]",
";",
"return",
"function",
"(",
")",
"{",
"return",
"method",
".",
"apply",
"(",
"that",
",",
"arguments",
")",
";",
"}",
";",
"}"
] | Get a proxy method for a "super" class' method on the `this` objct.
@param {String} name - The name of the method to get a proxy for.
@returns {Function} A function that calls the `name` function of the `this` object.
@since 0.0.4
@preserve | [
"Get",
"a",
"proxy",
"method",
"for",
"a",
"super",
"class",
"method",
"on",
"the",
"this",
"objct",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L164-L169 |
53,522 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_api_user_queueInstructionURL | function sn_api_user_queueInstructionURL(topic, parameters) {
var url = sn_api_user_baseURL(this) + "/instr/add?nodeId=" + this.nodeId + "&topic=" + encodeURIComponent(topic);
if (Array.isArray(parameters)) {
var i, len;
for (i = 0, len = parameters.length; i < len; i++) {
url += "&" + encodeURIComponent("parameters[" + i + "].name") + "=" + encodeURIComponent(parameters[i].name) + "&" + encodeURIComponent("parameters[" + i + "].value") + "=" + encodeURIComponent(parameters[i].value);
}
}
return url;
} | javascript | function sn_api_user_queueInstructionURL(topic, parameters) {
var url = sn_api_user_baseURL(this) + "/instr/add?nodeId=" + this.nodeId + "&topic=" + encodeURIComponent(topic);
if (Array.isArray(parameters)) {
var i, len;
for (i = 0, len = parameters.length; i < len; i++) {
url += "&" + encodeURIComponent("parameters[" + i + "].name") + "=" + encodeURIComponent(parameters[i].name) + "&" + encodeURIComponent("parameters[" + i + "].value") + "=" + encodeURIComponent(parameters[i].value);
}
}
return url;
} | [
"function",
"sn_api_user_queueInstructionURL",
"(",
"topic",
",",
"parameters",
")",
"{",
"var",
"url",
"=",
"sn_api_user_baseURL",
"(",
"this",
")",
"+",
"\"/instr/add?nodeId=\"",
"+",
"this",
".",
"nodeId",
"+",
"\"&topic=\"",
"+",
"encodeURIComponent",
"(",
"topic",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"parameters",
")",
")",
"{",
"var",
"i",
",",
"len",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"parameters",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"url",
"+=",
"\"&\"",
"+",
"encodeURIComponent",
"(",
"\"parameters[\"",
"+",
"i",
"+",
"\"].name\"",
")",
"+",
"\"=\"",
"+",
"encodeURIComponent",
"(",
"parameters",
"[",
"i",
"]",
".",
"name",
")",
"+",
"\"&\"",
"+",
"encodeURIComponent",
"(",
"\"parameters[\"",
"+",
"i",
"+",
"\"].value\"",
")",
"+",
"\"=\"",
"+",
"encodeURIComponent",
"(",
"parameters",
"[",
"i",
"]",
".",
"value",
")",
";",
"}",
"}",
"return",
"url",
";",
"}"
] | Generate a URL for posting an instruction request.
@param {String} topic - The instruction topic.
@param {Array} parameters - An array of parameter objects in the form <code>{name:n1, value:v1}</code>.
@preserve | [
"Generate",
"a",
"URL",
"for",
"posting",
"an",
"instruction",
"request",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L458-L467 |
53,523 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(key, enabled) {
var val = enabled;
if (key === undefined) {
return this;
}
if (val === undefined) {
val = this.map[key] === undefined;
}
return this.value(key, val === true ? true : null);
} | javascript | function(key, enabled) {
var val = enabled;
if (key === undefined) {
return this;
}
if (val === undefined) {
val = this.map[key] === undefined;
}
return this.value(key, val === true ? true : null);
} | [
"function",
"(",
"key",
",",
"enabled",
")",
"{",
"var",
"val",
"=",
"enabled",
";",
"if",
"(",
"key",
"===",
"undefined",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"val",
"===",
"undefined",
")",
"{",
"val",
"=",
"this",
".",
"map",
"[",
"key",
"]",
"===",
"undefined",
";",
"}",
"return",
"this",
".",
"value",
"(",
"key",
",",
"val",
"===",
"true",
"?",
"true",
":",
"null",
")",
";",
"}"
] | Set or toggle the enabled status of a given key.
<p>If the <em>enabled</em> parameter is not passed, then the enabled
status will be toggled to its opposite value.</p>
@param {String} key they key to set
@param {Boolean} enabled the optional enabled value to set
@returns {sn.Configuration} this object to allow method chaining
@preserve | [
"Set",
"or",
"toggle",
"the",
"enabled",
"status",
"of",
"a",
"given",
"key",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L1765-L1774 |
|
53,524 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(key, newValue) {
var me = this;
if (arguments.length === 1) {
return this.map[key];
}
if (newValue === null) {
delete this.map[key];
if (this.hasOwnProperty(key)) {
delete this[key];
}
} else {
this.map[key] = newValue;
if (!this.hasOwnProperty(key)) {
Object.defineProperty(this, key, {
enumerable: true,
configurable: true,
get: function() {
return me.map[key];
},
set: function(value) {
me.map[key] = value;
}
});
}
}
return this;
} | javascript | function(key, newValue) {
var me = this;
if (arguments.length === 1) {
return this.map[key];
}
if (newValue === null) {
delete this.map[key];
if (this.hasOwnProperty(key)) {
delete this[key];
}
} else {
this.map[key] = newValue;
if (!this.hasOwnProperty(key)) {
Object.defineProperty(this, key, {
enumerable: true,
configurable: true,
get: function() {
return me.map[key];
},
set: function(value) {
me.map[key] = value;
}
});
}
}
return this;
} | [
"function",
"(",
"key",
",",
"newValue",
")",
"{",
"var",
"me",
"=",
"this",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"return",
"this",
".",
"map",
"[",
"key",
"]",
";",
"}",
"if",
"(",
"newValue",
"===",
"null",
")",
"{",
"delete",
"this",
".",
"map",
"[",
"key",
"]",
";",
"if",
"(",
"this",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"delete",
"this",
"[",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"this",
".",
"map",
"[",
"key",
"]",
"=",
"newValue",
";",
"if",
"(",
"!",
"this",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"key",
",",
"{",
"enumerable",
":",
"true",
",",
"configurable",
":",
"true",
",",
"get",
":",
"function",
"(",
")",
"{",
"return",
"me",
".",
"map",
"[",
"key",
"]",
";",
"}",
",",
"set",
":",
"function",
"(",
"value",
")",
"{",
"me",
".",
"map",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Get or set a configuration value.
@param {String} key The key to get or set the value for
@param [newValue] If defined, the new value to set for the given {@code key}.
If {@code null} then the value will be removed.
@returns If called as a getter, the associated value for the given {@code key},
otherwise this object.
@preserve | [
"Get",
"or",
"set",
"a",
"configuration",
"value",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L1785-L1811 |
|
53,525 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | sn_net_encodeURLQueryTerms | function sn_net_encodeURLQueryTerms(parameters) {
var result = "", prop, val, i, len;
function handleValue(k, v) {
if (result.length) {
result += "&";
}
result += encodeURIComponent(k) + "=" + encodeURIComponent(v);
}
if (parameters) {
for (prop in parameters) {
if (parameters.hasOwnProperty(prop)) {
val = parameters[prop];
if (Array.isArray(val)) {
for (i = 0, len = val.length; i < len; i++) {
handleValue(prop, val[i]);
}
} else {
handleValue(prop, val);
}
}
}
}
return result;
} | javascript | function sn_net_encodeURLQueryTerms(parameters) {
var result = "", prop, val, i, len;
function handleValue(k, v) {
if (result.length) {
result += "&";
}
result += encodeURIComponent(k) + "=" + encodeURIComponent(v);
}
if (parameters) {
for (prop in parameters) {
if (parameters.hasOwnProperty(prop)) {
val = parameters[prop];
if (Array.isArray(val)) {
for (i = 0, len = val.length; i < len; i++) {
handleValue(prop, val[i]);
}
} else {
handleValue(prop, val);
}
}
}
}
return result;
} | [
"function",
"sn_net_encodeURLQueryTerms",
"(",
"parameters",
")",
"{",
"var",
"result",
"=",
"\"\"",
",",
"prop",
",",
"val",
",",
"i",
",",
"len",
";",
"function",
"handleValue",
"(",
"k",
",",
"v",
")",
"{",
"if",
"(",
"result",
".",
"length",
")",
"{",
"result",
"+=",
"\"&\"",
";",
"}",
"result",
"+=",
"encodeURIComponent",
"(",
"k",
")",
"+",
"\"=\"",
"+",
"encodeURIComponent",
"(",
"v",
")",
";",
"}",
"if",
"(",
"parameters",
")",
"{",
"for",
"(",
"prop",
"in",
"parameters",
")",
"{",
"if",
"(",
"parameters",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"val",
"=",
"parameters",
"[",
"prop",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"val",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"handleValue",
"(",
"prop",
",",
"val",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"handleValue",
"(",
"prop",
",",
"val",
")",
";",
"}",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Encode the properties of an object as a URL query string.
<p>If an object property has an array value, multiple URL parameters will be encoded for that property.</p>
@param {Object} an object to encode as URL parameters
@return {String} the encoded query parameters
@preserve | [
"Encode",
"the",
"properties",
"of",
"an",
"object",
"as",
"a",
"URL",
"query",
"string",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6232-L6255 |
53,526 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | generateCanonicalRequestMessage | function generateCanonicalRequestMessage(params) {
var msg = (params.method === undefined ? "GET" : params.method.toUpperCase()) + "\n" + params.uri.path + "\n" + (params.queryParams ? params.queryParams : "") + "\n";
params.headers.headerNames.forEach(function(name) {
msg += name + ":" + params.headers.headers[name] + "\n";
});
msg += params.headers.headerNames.join(";") + "\n";
msg += CryptoJS.enc.Hex.stringify(params.bodyDigest);
return msg;
} | javascript | function generateCanonicalRequestMessage(params) {
var msg = (params.method === undefined ? "GET" : params.method.toUpperCase()) + "\n" + params.uri.path + "\n" + (params.queryParams ? params.queryParams : "") + "\n";
params.headers.headerNames.forEach(function(name) {
msg += name + ":" + params.headers.headers[name] + "\n";
});
msg += params.headers.headerNames.join(";") + "\n";
msg += CryptoJS.enc.Hex.stringify(params.bodyDigest);
return msg;
} | [
"function",
"generateCanonicalRequestMessage",
"(",
"params",
")",
"{",
"var",
"msg",
"=",
"(",
"params",
".",
"method",
"===",
"undefined",
"?",
"\"GET\"",
":",
"params",
".",
"method",
".",
"toUpperCase",
"(",
")",
")",
"+",
"\"\\n\"",
"+",
"params",
".",
"uri",
".",
"path",
"+",
"\"\\n\"",
"+",
"(",
"params",
".",
"queryParams",
"?",
"params",
".",
"queryParams",
":",
"\"\"",
")",
"+",
"\"\\n\"",
";",
"params",
".",
"headers",
".",
"headerNames",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"msg",
"+=",
"name",
"+",
"\":\"",
"+",
"params",
".",
"headers",
".",
"headers",
"[",
"name",
"]",
"+",
"\"\\n\"",
";",
"}",
")",
";",
"msg",
"+=",
"params",
".",
"headers",
".",
"headerNames",
".",
"join",
"(",
"\";\"",
")",
"+",
"\"\\n\"",
";",
"msg",
"+=",
"CryptoJS",
".",
"enc",
".",
"Hex",
".",
"stringify",
"(",
"params",
".",
"bodyDigest",
")",
";",
"return",
"msg",
";",
"}"
] | Generate the canonical request message for a set of request parameters.
@param {Object} params the request parameters
@param {String} params.method the HTTP request method
@param {Object} params.uri a parsed URI object for the request
@param {String} params.queryParams the canonical query parameters string
@param {Object} params.headers the canonical headers object
@param {Object} params.bodyDigest the CryptoJS body content digest
@return {String} the message
@preserve | [
"Generate",
"the",
"canonical",
"request",
"message",
"for",
"a",
"set",
"of",
"request",
"parameters",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6381-L6389 |
53,527 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(location) {
return Math.sqrt(Math.pow(location.x - this.matrix[4], 2), Math.pow(location.y - this.matrix[5], 2));
} | javascript | function(location) {
return Math.sqrt(Math.pow(location.x - this.matrix[4], 2), Math.pow(location.y - this.matrix[5], 2));
} | [
"function",
"(",
"location",
")",
"{",
"return",
"Math",
".",
"sqrt",
"(",
"Math",
".",
"pow",
"(",
"location",
".",
"x",
"-",
"this",
".",
"matrix",
"[",
"4",
"]",
",",
"2",
")",
",",
"Math",
".",
"pow",
"(",
"location",
".",
"y",
"-",
"this",
".",
"matrix",
"[",
"5",
"]",
",",
"2",
")",
")",
";",
"}"
] | Get the 2D distance between a location and this matrix's translation.
@param location a location object, with x,y Number properties
@returns {Number} the calculated distance
@preserve | [
"Get",
"the",
"2D",
"distance",
"between",
"a",
"location",
"and",
"this",
"matrix",
"s",
"translation",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6911-L6913 |
|
53,528 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(elm) {
var m = this.support.use3d === true ? this.toMatrix3D() : this.toMatrix2D();
elm.style[this.support.tProp] = m;
} | javascript | function(elm) {
var m = this.support.use3d === true ? this.toMatrix3D() : this.toMatrix2D();
elm.style[this.support.tProp] = m;
} | [
"function",
"(",
"elm",
")",
"{",
"var",
"m",
"=",
"this",
".",
"support",
".",
"use3d",
"===",
"true",
"?",
"this",
".",
"toMatrix3D",
"(",
")",
":",
"this",
".",
"toMatrix2D",
"(",
")",
";",
"elm",
".",
"style",
"[",
"this",
".",
"support",
".",
"tProp",
"]",
"=",
"m",
";",
"}"
] | Apply the matrix transform to an element.
<p>If {@code support.use3d} is <em>true</em>, the {@link #toMatrix3D()} transform
is used, otherwise {@link #toMatrix2D()} is used. Found that legibility of
text was too blurry on older displays when 3D transform was applied,
but 3D transform provide better performance on hi-res displays.</p>
@param {Element} elm the element to apply the transform to
@preserve | [
"Apply",
"the",
"matrix",
"transform",
"to",
"an",
"element",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6925-L6928 |
|
53,529 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(elm, finished) {
var listener = undefined;
var self = this;
listener = function(event) {
if (event.target === elm) {
elm.removeEventListener(self.support.trEndEvent, listener, false);
finished.apply(elm);
}
};
elm.addEventListener(self.support.trEndEvent, listener, false);
} | javascript | function(elm, finished) {
var listener = undefined;
var self = this;
listener = function(event) {
if (event.target === elm) {
elm.removeEventListener(self.support.trEndEvent, listener, false);
finished.apply(elm);
}
};
elm.addEventListener(self.support.trEndEvent, listener, false);
} | [
"function",
"(",
"elm",
",",
"finished",
")",
"{",
"var",
"listener",
"=",
"undefined",
";",
"var",
"self",
"=",
"this",
";",
"listener",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"event",
".",
"target",
"===",
"elm",
")",
"{",
"elm",
".",
"removeEventListener",
"(",
"self",
".",
"support",
".",
"trEndEvent",
",",
"listener",
",",
"false",
")",
";",
"finished",
".",
"apply",
"(",
"elm",
")",
";",
"}",
"}",
";",
"elm",
".",
"addEventListener",
"(",
"self",
".",
"support",
".",
"trEndEvent",
",",
"listener",
",",
"false",
")",
";",
"}"
] | Apply a one-time animation callback listener.
@param elm the element to add the one-time listener to
@param finished
@preserve | [
"Apply",
"a",
"one",
"-",
"time",
"animation",
"callback",
"listener",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6936-L6946 |
|
53,530 | SolarNetwork/solarnetwork-d3 | solarnetwork-d3.js | function(elm, timing, duration, finished) {
var self = this;
this.animateListen(elm, function() {
elm.style[self.support.trProp] = "";
if (finished !== undefined) {
finished.apply(elm);
}
});
var cssValue = this.support.trTransform + " " + (duration !== undefined ? duration : "0.3s") + " " + (timing !== undefined ? timing : "ease-out");
elm.style[this.support.trProp] = cssValue;
this.apply(elm);
} | javascript | function(elm, timing, duration, finished) {
var self = this;
this.animateListen(elm, function() {
elm.style[self.support.trProp] = "";
if (finished !== undefined) {
finished.apply(elm);
}
});
var cssValue = this.support.trTransform + " " + (duration !== undefined ? duration : "0.3s") + " " + (timing !== undefined ? timing : "ease-out");
elm.style[this.support.trProp] = cssValue;
this.apply(elm);
} | [
"function",
"(",
"elm",
",",
"timing",
",",
"duration",
",",
"finished",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"animateListen",
"(",
"elm",
",",
"function",
"(",
")",
"{",
"elm",
".",
"style",
"[",
"self",
".",
"support",
".",
"trProp",
"]",
"=",
"\"\"",
";",
"if",
"(",
"finished",
"!==",
"undefined",
")",
"{",
"finished",
".",
"apply",
"(",
"elm",
")",
";",
"}",
"}",
")",
";",
"var",
"cssValue",
"=",
"this",
".",
"support",
".",
"trTransform",
"+",
"\" \"",
"+",
"(",
"duration",
"!==",
"undefined",
"?",
"duration",
":",
"\"0.3s\"",
")",
"+",
"\" \"",
"+",
"(",
"timing",
"!==",
"undefined",
"?",
"timing",
":",
"\"ease-out\"",
")",
";",
"elm",
".",
"style",
"[",
"this",
".",
"support",
".",
"trProp",
"]",
"=",
"cssValue",
";",
"this",
".",
"apply",
"(",
"elm",
")",
";",
"}"
] | Apply the matrix transform to an element, with an "ease out" transition.
<p>Calls {@link #apply(elm)} internally.</p>
@param {Element} elm the element to apply the transform to
@param {String} timing the CSS timing function to use
@param {String} duration the CSS duration to use
@param {Function} finished an optional callback function to execute when
the animation completes
@preserve | [
"Apply",
"the",
"matrix",
"transform",
"to",
"an",
"element",
"with",
"an",
"ease",
"out",
"transition",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/solarnetwork-d3.js#L6959-L6970 |
|
53,531 | gyandeeps/load-perf | lib/index.js | check | function check(suppliedOptions){
var options = assign(Object.create(defaultOptions), suppliedOptions || {});
var packageJson = require(path.resolve(process.cwd(), options.package));
var checkDevDependencies = !!options.checkDevDependencies;
var checkDependencies = !!options.checkDependencies;
var moduleTimes = {
dependencies: {},
devDependencies: {}
};
var loadTime = -1;
if(packageJson.main){
loadTime = execSync(execString + path.resolve(process.cwd(), packageJson.main), {encoding: "utf8"});
}
if(checkDependencies){
Object.keys(packageJson.dependencies).forEach(function(depen){
var time = execSync(execString + path.resolve(process.cwd(), "node_modules", depen), {
encoding: "utf8",
cwd: process.cwd()
});
moduleTimes.dependencies[depen] = parseFloat(time);
});
}
if(checkDevDependencies){
Object.keys(packageJson.devDependencies).forEach(function(depen){
var time = execSync(execString + path.resolve(process.cwd(), "node_modules", depen), {
encoding: "utf8",
cwd: process.cwd()
});
moduleTimes.devDependencies[depen] = parseFloat(time);
});
}
return {
moduleTimes: moduleTimes,
loadTime: loadTime
};
} | javascript | function check(suppliedOptions){
var options = assign(Object.create(defaultOptions), suppliedOptions || {});
var packageJson = require(path.resolve(process.cwd(), options.package));
var checkDevDependencies = !!options.checkDevDependencies;
var checkDependencies = !!options.checkDependencies;
var moduleTimes = {
dependencies: {},
devDependencies: {}
};
var loadTime = -1;
if(packageJson.main){
loadTime = execSync(execString + path.resolve(process.cwd(), packageJson.main), {encoding: "utf8"});
}
if(checkDependencies){
Object.keys(packageJson.dependencies).forEach(function(depen){
var time = execSync(execString + path.resolve(process.cwd(), "node_modules", depen), {
encoding: "utf8",
cwd: process.cwd()
});
moduleTimes.dependencies[depen] = parseFloat(time);
});
}
if(checkDevDependencies){
Object.keys(packageJson.devDependencies).forEach(function(depen){
var time = execSync(execString + path.resolve(process.cwd(), "node_modules", depen), {
encoding: "utf8",
cwd: process.cwd()
});
moduleTimes.devDependencies[depen] = parseFloat(time);
});
}
return {
moduleTimes: moduleTimes,
loadTime: loadTime
};
} | [
"function",
"check",
"(",
"suppliedOptions",
")",
"{",
"var",
"options",
"=",
"assign",
"(",
"Object",
".",
"create",
"(",
"defaultOptions",
")",
",",
"suppliedOptions",
"||",
"{",
"}",
")",
";",
"var",
"packageJson",
"=",
"require",
"(",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"options",
".",
"package",
")",
")",
";",
"var",
"checkDevDependencies",
"=",
"!",
"!",
"options",
".",
"checkDevDependencies",
";",
"var",
"checkDependencies",
"=",
"!",
"!",
"options",
".",
"checkDependencies",
";",
"var",
"moduleTimes",
"=",
"{",
"dependencies",
":",
"{",
"}",
",",
"devDependencies",
":",
"{",
"}",
"}",
";",
"var",
"loadTime",
"=",
"-",
"1",
";",
"if",
"(",
"packageJson",
".",
"main",
")",
"{",
"loadTime",
"=",
"execSync",
"(",
"execString",
"+",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"packageJson",
".",
"main",
")",
",",
"{",
"encoding",
":",
"\"utf8\"",
"}",
")",
";",
"}",
"if",
"(",
"checkDependencies",
")",
"{",
"Object",
".",
"keys",
"(",
"packageJson",
".",
"dependencies",
")",
".",
"forEach",
"(",
"function",
"(",
"depen",
")",
"{",
"var",
"time",
"=",
"execSync",
"(",
"execString",
"+",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"\"node_modules\"",
",",
"depen",
")",
",",
"{",
"encoding",
":",
"\"utf8\"",
",",
"cwd",
":",
"process",
".",
"cwd",
"(",
")",
"}",
")",
";",
"moduleTimes",
".",
"dependencies",
"[",
"depen",
"]",
"=",
"parseFloat",
"(",
"time",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"checkDevDependencies",
")",
"{",
"Object",
".",
"keys",
"(",
"packageJson",
".",
"devDependencies",
")",
".",
"forEach",
"(",
"function",
"(",
"depen",
")",
"{",
"var",
"time",
"=",
"execSync",
"(",
"execString",
"+",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"\"node_modules\"",
",",
"depen",
")",
",",
"{",
"encoding",
":",
"\"utf8\"",
",",
"cwd",
":",
"process",
".",
"cwd",
"(",
")",
"}",
")",
";",
"moduleTimes",
".",
"devDependencies",
"[",
"depen",
"]",
"=",
"parseFloat",
"(",
"time",
")",
";",
"}",
")",
";",
"}",
"return",
"{",
"moduleTimes",
":",
"moduleTimes",
",",
"loadTime",
":",
"loadTime",
"}",
";",
"}"
] | Main function which calculates the times for each modules
@param {object} suppliedOptions - Options to be passed in.
@return {{moduleTimes: {dependencies: {}, devDependencies: {}}, loadTime: int}} | [
"Main",
"function",
"which",
"calculates",
"the",
"times",
"for",
"each",
"modules"
] | 045eb27e79699db621f57175db7e62e3857c10c0 | https://github.com/gyandeeps/load-perf/blob/045eb27e79699db621f57175db7e62e3857c10c0/lib/index.js#L24-L65 |
53,532 | purtuga/observables | src/objectWatchProp.js | setCallbackAsWatcherOf | function setCallbackAsWatcherOf(callback, watchersSet) {
if (!callback[WATCHER_IDENTIFIER]) {
defineProperty(callback, WATCHER_IDENTIFIER, { watching: new Set() });
defineProperty(callback, "stopWatchingAll", function(){
callback[WATCHER_IDENTIFIER].watching.forEach(watcherList =>
watcherList.delete(callback)
);
callback[WATCHER_IDENTIFIER].watching.clear();
});
}
callback[WATCHER_IDENTIFIER].watching.add(watchersSet);
} | javascript | function setCallbackAsWatcherOf(callback, watchersSet) {
if (!callback[WATCHER_IDENTIFIER]) {
defineProperty(callback, WATCHER_IDENTIFIER, { watching: new Set() });
defineProperty(callback, "stopWatchingAll", function(){
callback[WATCHER_IDENTIFIER].watching.forEach(watcherList =>
watcherList.delete(callback)
);
callback[WATCHER_IDENTIFIER].watching.clear();
});
}
callback[WATCHER_IDENTIFIER].watching.add(watchersSet);
} | [
"function",
"setCallbackAsWatcherOf",
"(",
"callback",
",",
"watchersSet",
")",
"{",
"if",
"(",
"!",
"callback",
"[",
"WATCHER_IDENTIFIER",
"]",
")",
"{",
"defineProperty",
"(",
"callback",
",",
"WATCHER_IDENTIFIER",
",",
"{",
"watching",
":",
"new",
"Set",
"(",
")",
"}",
")",
";",
"defineProperty",
"(",
"callback",
",",
"\"stopWatchingAll\"",
",",
"function",
"(",
")",
"{",
"callback",
"[",
"WATCHER_IDENTIFIER",
"]",
".",
"watching",
".",
"forEach",
"(",
"watcherList",
"=>",
"watcherList",
".",
"delete",
"(",
"callback",
")",
")",
";",
"callback",
"[",
"WATCHER_IDENTIFIER",
"]",
".",
"watching",
".",
"clear",
"(",
")",
";",
"}",
")",
";",
"}",
"callback",
"[",
"WATCHER_IDENTIFIER",
"]",
".",
"watching",
".",
"add",
"(",
"watchersSet",
")",
";",
"}"
] | Store a reference to the Set instance provided on input, on the callback.
@private
@param {Function} callback
@param {Set} watchersSet | [
"Store",
"a",
"reference",
"to",
"the",
"Set",
"instance",
"provided",
"on",
"input",
"on",
"the",
"callback",
"."
] | 68847b1294734c4cd50b26e5f6156a8b460f77a2 | https://github.com/purtuga/observables/blob/68847b1294734c4cd50b26e5f6156a8b460f77a2/src/objectWatchProp.js#L428-L441 |
53,533 | bobmonteverde/d3-simple-tooltip | src/tooltip.js | offsetTop | function offsetTop (elem) {
let top = 0
do {
if (!isNaN(elem.offsetTop)) top += elem.offsetTop
} while (elem = elem.offsetParent)
return top
} | javascript | function offsetTop (elem) {
let top = 0
do {
if (!isNaN(elem.offsetTop)) top += elem.offsetTop
} while (elem = elem.offsetParent)
return top
} | [
"function",
"offsetTop",
"(",
"elem",
")",
"{",
"let",
"top",
"=",
"0",
"do",
"{",
"if",
"(",
"!",
"isNaN",
"(",
"elem",
".",
"offsetTop",
")",
")",
"top",
"+=",
"elem",
".",
"offsetTop",
"}",
"while",
"(",
"elem",
"=",
"elem",
".",
"offsetParent",
")",
"return",
"top",
"}"
] | Recursively calculate top offset of an element from the body | [
"Recursively",
"calculate",
"top",
"offset",
"of",
"an",
"element",
"from",
"the",
"body"
] | 19994f5bc61cea303b7a855d1aebfccd3220abf6 | https://github.com/bobmonteverde/d3-simple-tooltip/blob/19994f5bc61cea303b7a855d1aebfccd3220abf6/src/tooltip.js#L23-L31 |
53,534 | bobmonteverde/d3-simple-tooltip | src/tooltip.js | offsetLeft | function offsetLeft (elem) {
let left = 0
do {
if (!isNaN(elem.offsetLeft)) left += elem.offsetLeft
} while (elem = elem.offsetParent )
return left
} | javascript | function offsetLeft (elem) {
let left = 0
do {
if (!isNaN(elem.offsetLeft)) left += elem.offsetLeft
} while (elem = elem.offsetParent )
return left
} | [
"function",
"offsetLeft",
"(",
"elem",
")",
"{",
"let",
"left",
"=",
"0",
"do",
"{",
"if",
"(",
"!",
"isNaN",
"(",
"elem",
".",
"offsetLeft",
")",
")",
"left",
"+=",
"elem",
".",
"offsetLeft",
"}",
"while",
"(",
"elem",
"=",
"elem",
".",
"offsetParent",
")",
"return",
"left",
"}"
] | Recursively calculate left offset of an element from the body | [
"Recursively",
"calculate",
"left",
"offset",
"of",
"an",
"element",
"from",
"the",
"body"
] | 19994f5bc61cea303b7a855d1aebfccd3220abf6 | https://github.com/bobmonteverde/d3-simple-tooltip/blob/19994f5bc61cea303b7a855d1aebfccd3220abf6/src/tooltip.js#L34-L42 |
53,535 | cirocosta/yaspm | src/spm.js | enhanceSpm | function enhanceSpm (comName, checkSignature, fn) {
var sp = new SerialPort(comName)
, open = false;
sp.writable = true;
sp.on('open', function() {
open = true;
if (checkSignature)
getSignature(sp, function(e, sig) {
fn(e, sp, sig);
});
else
fn(null, sp, null);
});
sp.once('error', function(e) {
console.log('ERROR', e, comName);
if (!open)
fn(e);
});
} | javascript | function enhanceSpm (comName, checkSignature, fn) {
var sp = new SerialPort(comName)
, open = false;
sp.writable = true;
sp.on('open', function() {
open = true;
if (checkSignature)
getSignature(sp, function(e, sig) {
fn(e, sp, sig);
});
else
fn(null, sp, null);
});
sp.once('error', function(e) {
console.log('ERROR', e, comName);
if (!open)
fn(e);
});
} | [
"function",
"enhanceSpm",
"(",
"comName",
",",
"checkSignature",
",",
"fn",
")",
"{",
"var",
"sp",
"=",
"new",
"SerialPort",
"(",
"comName",
")",
",",
"open",
"=",
"false",
";",
"sp",
".",
"writable",
"=",
"true",
";",
"sp",
".",
"on",
"(",
"'open'",
",",
"function",
"(",
")",
"{",
"open",
"=",
"true",
";",
"if",
"(",
"checkSignature",
")",
"getSignature",
"(",
"sp",
",",
"function",
"(",
"e",
",",
"sig",
")",
"{",
"fn",
"(",
"e",
",",
"sp",
",",
"sig",
")",
";",
"}",
")",
";",
"else",
"fn",
"(",
"null",
",",
"sp",
",",
"null",
")",
";",
"}",
")",
";",
"sp",
".",
"once",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR'",
",",
"e",
",",
"comName",
")",
";",
"if",
"(",
"!",
"open",
")",
"fn",
"(",
"e",
")",
";",
"}",
")",
";",
"}"
] | Main function to be exported. It exposes a
better serialport.
@param {[type]} comName the comName
returned from the
port listing
@param {Function} fn callback function
to be called with
(err|sp|signature) | [
"Main",
"function",
"to",
"be",
"exported",
".",
"It",
"exposes",
"a",
"better",
"serialport",
"."
] | 676524906425ba99b1e6f95a75ce4a82501a0ee9 | https://github.com/cirocosta/yaspm/blob/676524906425ba99b1e6f95a75ce4a82501a0ee9/src/spm.js#L15-L35 |
53,536 | cirocosta/yaspm | src/spm.js | getSignature | function getSignature (sp, fn) {
var start = null
, sig = ''
, timer;
var handleSignature = function(data) {
if (data)
sig += data.toString() || '';
clearTimeout(timer);
if (!start && data) {
start = Date.now();
} else if (Date.now() - start > 100) {
sp.removeListener('data', handleSignature);
return fn(null, sig.trim());
}
timer = setTimeout(handleSignature, 100);
};
sp.on('data', handleSignature);
} | javascript | function getSignature (sp, fn) {
var start = null
, sig = ''
, timer;
var handleSignature = function(data) {
if (data)
sig += data.toString() || '';
clearTimeout(timer);
if (!start && data) {
start = Date.now();
} else if (Date.now() - start > 100) {
sp.removeListener('data', handleSignature);
return fn(null, sig.trim());
}
timer = setTimeout(handleSignature, 100);
};
sp.on('data', handleSignature);
} | [
"function",
"getSignature",
"(",
"sp",
",",
"fn",
")",
"{",
"var",
"start",
"=",
"null",
",",
"sig",
"=",
"''",
",",
"timer",
";",
"var",
"handleSignature",
"=",
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
")",
"sig",
"+=",
"data",
".",
"toString",
"(",
")",
"||",
"''",
";",
"clearTimeout",
"(",
"timer",
")",
";",
"if",
"(",
"!",
"start",
"&&",
"data",
")",
"{",
"start",
"=",
"Date",
".",
"now",
"(",
")",
";",
"}",
"else",
"if",
"(",
"Date",
".",
"now",
"(",
")",
"-",
"start",
">",
"100",
")",
"{",
"sp",
".",
"removeListener",
"(",
"'data'",
",",
"handleSignature",
")",
";",
"return",
"fn",
"(",
"null",
",",
"sig",
".",
"trim",
"(",
")",
")",
";",
"}",
"timer",
"=",
"setTimeout",
"(",
"handleSignature",
",",
"100",
")",
";",
"}",
";",
"sp",
".",
"on",
"(",
"'data'",
",",
"handleSignature",
")",
";",
"}"
] | Given a SerialPort obj, tries to get the
signature emitted from the device.
@param {Object} sp sp
@param {Function} fn callback fn. Resolves
with (err | serialport |
signature) when ready. | [
"Given",
"a",
"SerialPort",
"obj",
"tries",
"to",
"get",
"the",
"signature",
"emitted",
"from",
"the",
"device",
"."
] | 676524906425ba99b1e6f95a75ce4a82501a0ee9 | https://github.com/cirocosta/yaspm/blob/676524906425ba99b1e6f95a75ce4a82501a0ee9/src/spm.js#L45-L67 |
53,537 | BladeRunnerJS/emitr | src/Emitter.js | listen | function listen(eventIdentifier, callback, context) {
if (typeof callback !== 'function') { throw new TypeError('on: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
// This allows us to work even if the constructor hasn't been called. Useful for mixins.
if (this._emitterListeners === undefined) {
this._emitterListeners = new MultiMap();
}
if (typeof eventIdentifier === 'function' && (eventIdentifier.prototype instanceof metaEvents.MetaEvent || eventIdentifier === metaEvents.MetaEvent)) {
// Since triggering meta events can be expensive, we only
// do so if a listener has been added to listen to them.
this._emitterMetaEventsOn = true;
}
var currentListeners = this._emitterListeners.getValues(eventIdentifier);
currentListeners = currentListeners.filter(function(listenerRecord) {
return listenerRecord.registeredContext === context
&& (listenerRecord.callback === callback
|| (listenerRecord.callback._wrappedCallback !== undefined
&& listenerRecord.callback._wrappedCallback === callback._wrappedCallback));
});
if (currentListeners.length > 0) {
throw new Error('This callback is already listening to this event.');
}
this._emitterListeners.add(eventIdentifier, {
eventIdentifier: eventIdentifier,
callback: callback,
registeredContext: context,
context: context !== undefined ? context : this
});
if (this._emitterMetaEventsOn === true) {
this.trigger(new metaEvents.AddListenerEvent(eventIdentifier, callback._onceFunctionMarker === ONCE_FUNCTION_MARKER ? callback._wrappedCallback : callback, context));
}
} | javascript | function listen(eventIdentifier, callback, context) {
if (typeof callback !== 'function') { throw new TypeError('on: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
// This allows us to work even if the constructor hasn't been called. Useful for mixins.
if (this._emitterListeners === undefined) {
this._emitterListeners = new MultiMap();
}
if (typeof eventIdentifier === 'function' && (eventIdentifier.prototype instanceof metaEvents.MetaEvent || eventIdentifier === metaEvents.MetaEvent)) {
// Since triggering meta events can be expensive, we only
// do so if a listener has been added to listen to them.
this._emitterMetaEventsOn = true;
}
var currentListeners = this._emitterListeners.getValues(eventIdentifier);
currentListeners = currentListeners.filter(function(listenerRecord) {
return listenerRecord.registeredContext === context
&& (listenerRecord.callback === callback
|| (listenerRecord.callback._wrappedCallback !== undefined
&& listenerRecord.callback._wrappedCallback === callback._wrappedCallback));
});
if (currentListeners.length > 0) {
throw new Error('This callback is already listening to this event.');
}
this._emitterListeners.add(eventIdentifier, {
eventIdentifier: eventIdentifier,
callback: callback,
registeredContext: context,
context: context !== undefined ? context : this
});
if (this._emitterMetaEventsOn === true) {
this.trigger(new metaEvents.AddListenerEvent(eventIdentifier, callback._onceFunctionMarker === ONCE_FUNCTION_MARKER ? callback._wrappedCallback : callback, context));
}
} | [
"function",
"listen",
"(",
"eventIdentifier",
",",
"callback",
",",
"context",
")",
"{",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'on: Illegal Argument: callback must be a function, was '",
"+",
"(",
"typeof",
"callback",
")",
")",
";",
"}",
"// This allows us to work even if the constructor hasn't been called. Useful for mixins.",
"if",
"(",
"this",
".",
"_emitterListeners",
"===",
"undefined",
")",
"{",
"this",
".",
"_emitterListeners",
"=",
"new",
"MultiMap",
"(",
")",
";",
"}",
"if",
"(",
"typeof",
"eventIdentifier",
"===",
"'function'",
"&&",
"(",
"eventIdentifier",
".",
"prototype",
"instanceof",
"metaEvents",
".",
"MetaEvent",
"||",
"eventIdentifier",
"===",
"metaEvents",
".",
"MetaEvent",
")",
")",
"{",
"// Since triggering meta events can be expensive, we only",
"// do so if a listener has been added to listen to them.",
"this",
".",
"_emitterMetaEventsOn",
"=",
"true",
";",
"}",
"var",
"currentListeners",
"=",
"this",
".",
"_emitterListeners",
".",
"getValues",
"(",
"eventIdentifier",
")",
";",
"currentListeners",
"=",
"currentListeners",
".",
"filter",
"(",
"function",
"(",
"listenerRecord",
")",
"{",
"return",
"listenerRecord",
".",
"registeredContext",
"===",
"context",
"&&",
"(",
"listenerRecord",
".",
"callback",
"===",
"callback",
"||",
"(",
"listenerRecord",
".",
"callback",
".",
"_wrappedCallback",
"!==",
"undefined",
"&&",
"listenerRecord",
".",
"callback",
".",
"_wrappedCallback",
"===",
"callback",
".",
"_wrappedCallback",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"currentListeners",
".",
"length",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'This callback is already listening to this event.'",
")",
";",
"}",
"this",
".",
"_emitterListeners",
".",
"add",
"(",
"eventIdentifier",
",",
"{",
"eventIdentifier",
":",
"eventIdentifier",
",",
"callback",
":",
"callback",
",",
"registeredContext",
":",
"context",
",",
"context",
":",
"context",
"!==",
"undefined",
"?",
"context",
":",
"this",
"}",
")",
";",
"if",
"(",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
")",
"{",
"this",
".",
"trigger",
"(",
"new",
"metaEvents",
".",
"AddListenerEvent",
"(",
"eventIdentifier",
",",
"callback",
".",
"_onceFunctionMarker",
"===",
"ONCE_FUNCTION_MARKER",
"?",
"callback",
".",
"_wrappedCallback",
":",
"callback",
",",
"context",
")",
")",
";",
"}",
"}"
] | Registers a listener for an event.
If context is provided, then the <code>this</code> pointer will refer to it
inside the callback.
@param {*} eventIdentifier The identifier of the event that the callback should listen to.
@param {function} callback The function that should be called whenever the event is triggered. May not be null.
@param {?Object} [context] An optional context that defines what 'this' should be inside the callback. | [
"Registers",
"a",
"listener",
"for",
"an",
"event",
"."
] | 66ec84c3db3ff0f83a6ced87b805b2d3934d5613 | https://github.com/BladeRunnerJS/emitr/blob/66ec84c3db3ff0f83a6ced87b805b2d3934d5613/src/Emitter.js#L70-L105 |
53,538 | BladeRunnerJS/emitr | src/Emitter.js | function(eventIdentifier, callback, context) {
if (typeof callback !== 'function') { throw new TypeError('once: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
var off = this.off.bind(this), hasFired = false;
function onceEventHandler() {
if (hasFired === false) {
hasFired = true;
off(eventIdentifier, onceEventHandler, context);
callback.apply(this, arguments);
}
}
// We need this to enable us to remove the wrapping event handler
// when off is called with the original callback.
onceEventHandler._onceFunctionMarker = ONCE_FUNCTION_MARKER;
onceEventHandler._wrappedCallback = callback;
this.on(eventIdentifier, onceEventHandler, context);
} | javascript | function(eventIdentifier, callback, context) {
if (typeof callback !== 'function') { throw new TypeError('once: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
var off = this.off.bind(this), hasFired = false;
function onceEventHandler() {
if (hasFired === false) {
hasFired = true;
off(eventIdentifier, onceEventHandler, context);
callback.apply(this, arguments);
}
}
// We need this to enable us to remove the wrapping event handler
// when off is called with the original callback.
onceEventHandler._onceFunctionMarker = ONCE_FUNCTION_MARKER;
onceEventHandler._wrappedCallback = callback;
this.on(eventIdentifier, onceEventHandler, context);
} | [
"function",
"(",
"eventIdentifier",
",",
"callback",
",",
"context",
")",
"{",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'once: Illegal Argument: callback must be a function, was '",
"+",
"(",
"typeof",
"callback",
")",
")",
";",
"}",
"var",
"off",
"=",
"this",
".",
"off",
".",
"bind",
"(",
"this",
")",
",",
"hasFired",
"=",
"false",
";",
"function",
"onceEventHandler",
"(",
")",
"{",
"if",
"(",
"hasFired",
"===",
"false",
")",
"{",
"hasFired",
"=",
"true",
";",
"off",
"(",
"eventIdentifier",
",",
"onceEventHandler",
",",
"context",
")",
";",
"callback",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
"// We need this to enable us to remove the wrapping event handler",
"// when off is called with the original callback.",
"onceEventHandler",
".",
"_onceFunctionMarker",
"=",
"ONCE_FUNCTION_MARKER",
";",
"onceEventHandler",
".",
"_wrappedCallback",
"=",
"callback",
";",
"this",
".",
"on",
"(",
"eventIdentifier",
",",
"onceEventHandler",
",",
"context",
")",
";",
"}"
] | Registers a listener to receive an event only once.
If context is provided, then the <code>this</code> pointer will refer to it
inside the callback.
@param {*} eventIdentifier The identifier of the event that the callback should listen to.
@param {function} callback The function that should be called the first time the event is triggered. May not be null.
@param {?Object} [context] An optional context that defines what 'this' should be inside the callback. | [
"Registers",
"a",
"listener",
"to",
"receive",
"an",
"event",
"only",
"once",
"."
] | 66ec84c3db3ff0f83a6ced87b805b2d3934d5613 | https://github.com/BladeRunnerJS/emitr/blob/66ec84c3db3ff0f83a6ced87b805b2d3934d5613/src/Emitter.js#L117-L135 |
|
53,539 | BladeRunnerJS/emitr | src/Emitter.js | off | function off(eventIdentifier, callback, context) {
// not initialised - so no listeners of any kind
if (this._emitterListeners == null) { return false; }
if (arguments.length === 0) {
// clear all listeners.
if (this._emitterMetaEventsOn === true) {
var allListeners = this._emitterListeners.getValues();
notifyRemoves(this, allListeners);
}
this._emitterListeners.clear();
return true;
} else if (arguments.length === 1) {
// clear all listeners for a particular eventIdentifier.
if (this._emitterListeners.hasAny(eventIdentifier)) {
var listeners = this._emitterListeners.getValues(eventIdentifier);
this._emitterListeners['delete'](eventIdentifier);
if (this._emitterMetaEventsOn === true) {
notifyRemoves(this, listeners);
}
return true;
}
return false;
} else if (eventIdentifier === null && callback === null) {
// clear all listeners for a particular context.
return this.clearListeners(context);
} else {
// clear a specific listener.
if (typeof callback !== 'function') { throw new TypeError('off: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
var removedAListener = this._emitterListeners.removeLastMatch(eventIdentifier, function(record) {
var callbackToCompare = record.callback._onceFunctionMarker === ONCE_FUNCTION_MARKER ? record.callback._wrappedCallback : record.callback;
var callbackMatches = callback === callbackToCompare;
var contextMatches = record.registeredContext === context;
return callbackMatches && contextMatches;
});
if (removedAListener && this._emitterMetaEventsOn === true) {
this.trigger(new metaEvents.RemoveListenerEvent(eventIdentifier, callback, context));
}
return removedAListener;
}
} | javascript | function off(eventIdentifier, callback, context) {
// not initialised - so no listeners of any kind
if (this._emitterListeners == null) { return false; }
if (arguments.length === 0) {
// clear all listeners.
if (this._emitterMetaEventsOn === true) {
var allListeners = this._emitterListeners.getValues();
notifyRemoves(this, allListeners);
}
this._emitterListeners.clear();
return true;
} else if (arguments.length === 1) {
// clear all listeners for a particular eventIdentifier.
if (this._emitterListeners.hasAny(eventIdentifier)) {
var listeners = this._emitterListeners.getValues(eventIdentifier);
this._emitterListeners['delete'](eventIdentifier);
if (this._emitterMetaEventsOn === true) {
notifyRemoves(this, listeners);
}
return true;
}
return false;
} else if (eventIdentifier === null && callback === null) {
// clear all listeners for a particular context.
return this.clearListeners(context);
} else {
// clear a specific listener.
if (typeof callback !== 'function') { throw new TypeError('off: Illegal Argument: callback must be a function, was ' + (typeof callback)); }
var removedAListener = this._emitterListeners.removeLastMatch(eventIdentifier, function(record) {
var callbackToCompare = record.callback._onceFunctionMarker === ONCE_FUNCTION_MARKER ? record.callback._wrappedCallback : record.callback;
var callbackMatches = callback === callbackToCompare;
var contextMatches = record.registeredContext === context;
return callbackMatches && contextMatches;
});
if (removedAListener && this._emitterMetaEventsOn === true) {
this.trigger(new metaEvents.RemoveListenerEvent(eventIdentifier, callback, context));
}
return removedAListener;
}
} | [
"function",
"off",
"(",
"eventIdentifier",
",",
"callback",
",",
"context",
")",
"{",
"// not initialised - so no listeners of any kind",
"if",
"(",
"this",
".",
"_emitterListeners",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"// clear all listeners.",
"if",
"(",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
")",
"{",
"var",
"allListeners",
"=",
"this",
".",
"_emitterListeners",
".",
"getValues",
"(",
")",
";",
"notifyRemoves",
"(",
"this",
",",
"allListeners",
")",
";",
"}",
"this",
".",
"_emitterListeners",
".",
"clear",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"// clear all listeners for a particular eventIdentifier.",
"if",
"(",
"this",
".",
"_emitterListeners",
".",
"hasAny",
"(",
"eventIdentifier",
")",
")",
"{",
"var",
"listeners",
"=",
"this",
".",
"_emitterListeners",
".",
"getValues",
"(",
"eventIdentifier",
")",
";",
"this",
".",
"_emitterListeners",
"[",
"'delete'",
"]",
"(",
"eventIdentifier",
")",
";",
"if",
"(",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
")",
"{",
"notifyRemoves",
"(",
"this",
",",
"listeners",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"eventIdentifier",
"===",
"null",
"&&",
"callback",
"===",
"null",
")",
"{",
"// clear all listeners for a particular context.",
"return",
"this",
".",
"clearListeners",
"(",
"context",
")",
";",
"}",
"else",
"{",
"// clear a specific listener.",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'off: Illegal Argument: callback must be a function, was '",
"+",
"(",
"typeof",
"callback",
")",
")",
";",
"}",
"var",
"removedAListener",
"=",
"this",
".",
"_emitterListeners",
".",
"removeLastMatch",
"(",
"eventIdentifier",
",",
"function",
"(",
"record",
")",
"{",
"var",
"callbackToCompare",
"=",
"record",
".",
"callback",
".",
"_onceFunctionMarker",
"===",
"ONCE_FUNCTION_MARKER",
"?",
"record",
".",
"callback",
".",
"_wrappedCallback",
":",
"record",
".",
"callback",
";",
"var",
"callbackMatches",
"=",
"callback",
"===",
"callbackToCompare",
";",
"var",
"contextMatches",
"=",
"record",
".",
"registeredContext",
"===",
"context",
";",
"return",
"callbackMatches",
"&&",
"contextMatches",
";",
"}",
")",
";",
"if",
"(",
"removedAListener",
"&&",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
")",
"{",
"this",
".",
"trigger",
"(",
"new",
"metaEvents",
".",
"RemoveListenerEvent",
"(",
"eventIdentifier",
",",
"callback",
",",
"context",
")",
")",
";",
"}",
"return",
"removedAListener",
";",
"}",
"}"
] | Clear previously registered listeners.
With no arguments, this clears all listeners from this Emitter.
With one argument, this clears all listeners registered to a particular event.
With two or three arguments, this clears a specific listener.
@param {?*} eventIdentifier The identifier of the event to clear. If null, it will clear all events.
@param {?function} callback The callback function to clear.
@param {?Object} context The context object for the callback.
@returns {boolean} true if any listeners were removed. This is not finalised yet and may change (particularly if we want to enable chaining). | [
"Clear",
"previously",
"registered",
"listeners",
"."
] | 66ec84c3db3ff0f83a6ced87b805b2d3934d5613 | https://github.com/BladeRunnerJS/emitr/blob/66ec84c3db3ff0f83a6ced87b805b2d3934d5613/src/Emitter.js#L151-L193 |
53,540 | BladeRunnerJS/emitr | src/Emitter.js | trigger | function trigger(event) {
var args;
var anyListeners = false;
if (this._emitterListeners != null) {
args = slice.call(arguments, 1);
if (this._emitterListeners.hasAny(event)) {
anyListeners = true;
notify(this._emitterListeners.getValues(event), Emitter.suppressErrors, args);
}
// navigate up the prototype chain emitting against the constructors.
if (typeof event === 'object') {
var last = event, proto = Object.getPrototypeOf(event);
while (proto !== null && proto !== last) {
if (this._emitterListeners.hasAny(proto.constructor)) {
anyListeners = true;
notify(this._emitterListeners.getValues(proto.constructor), Emitter.suppressErrors, arguments);
}
last = proto;
proto = Object.getPrototypeOf(proto);
}
}
}
if (this._emitterMetaEventsOn === true && anyListeners === false && event instanceof metaEvents.DeadEvent === false) {
this.trigger(new metaEvents.DeadEvent(event, args));
}
return anyListeners;
} | javascript | function trigger(event) {
var args;
var anyListeners = false;
if (this._emitterListeners != null) {
args = slice.call(arguments, 1);
if (this._emitterListeners.hasAny(event)) {
anyListeners = true;
notify(this._emitterListeners.getValues(event), Emitter.suppressErrors, args);
}
// navigate up the prototype chain emitting against the constructors.
if (typeof event === 'object') {
var last = event, proto = Object.getPrototypeOf(event);
while (proto !== null && proto !== last) {
if (this._emitterListeners.hasAny(proto.constructor)) {
anyListeners = true;
notify(this._emitterListeners.getValues(proto.constructor), Emitter.suppressErrors, arguments);
}
last = proto;
proto = Object.getPrototypeOf(proto);
}
}
}
if (this._emitterMetaEventsOn === true && anyListeners === false && event instanceof metaEvents.DeadEvent === false) {
this.trigger(new metaEvents.DeadEvent(event, args));
}
return anyListeners;
} | [
"function",
"trigger",
"(",
"event",
")",
"{",
"var",
"args",
";",
"var",
"anyListeners",
"=",
"false",
";",
"if",
"(",
"this",
".",
"_emitterListeners",
"!=",
"null",
")",
"{",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"if",
"(",
"this",
".",
"_emitterListeners",
".",
"hasAny",
"(",
"event",
")",
")",
"{",
"anyListeners",
"=",
"true",
";",
"notify",
"(",
"this",
".",
"_emitterListeners",
".",
"getValues",
"(",
"event",
")",
",",
"Emitter",
".",
"suppressErrors",
",",
"args",
")",
";",
"}",
"// navigate up the prototype chain emitting against the constructors.",
"if",
"(",
"typeof",
"event",
"===",
"'object'",
")",
"{",
"var",
"last",
"=",
"event",
",",
"proto",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"event",
")",
";",
"while",
"(",
"proto",
"!==",
"null",
"&&",
"proto",
"!==",
"last",
")",
"{",
"if",
"(",
"this",
".",
"_emitterListeners",
".",
"hasAny",
"(",
"proto",
".",
"constructor",
")",
")",
"{",
"anyListeners",
"=",
"true",
";",
"notify",
"(",
"this",
".",
"_emitterListeners",
".",
"getValues",
"(",
"proto",
".",
"constructor",
")",
",",
"Emitter",
".",
"suppressErrors",
",",
"arguments",
")",
";",
"}",
"last",
"=",
"proto",
";",
"proto",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"proto",
")",
";",
"}",
"}",
"}",
"if",
"(",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
"&&",
"anyListeners",
"===",
"false",
"&&",
"event",
"instanceof",
"metaEvents",
".",
"DeadEvent",
"===",
"false",
")",
"{",
"this",
".",
"trigger",
"(",
"new",
"metaEvents",
".",
"DeadEvent",
"(",
"event",
",",
"args",
")",
")",
";",
"}",
"return",
"anyListeners",
";",
"}"
] | Fires an event, causing all the listeners registered for this event to be called.
If the event is an object, this will also call any listeners registered for
its class or any superclasses will also fire.
@param {*} event The event to fire.
@param {...*} [args] Optional arguments to pass to the listeners.
@returns {boolean} true if any listeners were notified, false otherwise. This is not finalised and may change (particularly if we want to allow chaining). | [
"Fires",
"an",
"event",
"causing",
"all",
"the",
"listeners",
"registered",
"for",
"this",
"event",
"to",
"be",
"called",
"."
] | 66ec84c3db3ff0f83a6ced87b805b2d3934d5613 | https://github.com/BladeRunnerJS/emitr/blob/66ec84c3db3ff0f83a6ced87b805b2d3934d5613/src/Emitter.js#L205-L232 |
53,541 | BladeRunnerJS/emitr | src/Emitter.js | clearListeners | function clearListeners(context) {
if (context == null) { throw new Error('clearListeners: context must be provided.'); }
// notify for every listener we throw out.
var removedListeners, trackRemovals = false;
if (this._emitterMetaEventsOn === true) {
trackRemovals = true;
removedListeners = [];
}
this._emitterListeners.filterAll(function(record) {
var keepListener = record.registeredContext !== context;
if (trackRemovals && keepListener === false) {
removedListeners.push(record);
}
return keepListener;
});
if (trackRemovals && removedListeners.length > 0) {
notifyRemoves(this, removedListeners);
}
} | javascript | function clearListeners(context) {
if (context == null) { throw new Error('clearListeners: context must be provided.'); }
// notify for every listener we throw out.
var removedListeners, trackRemovals = false;
if (this._emitterMetaEventsOn === true) {
trackRemovals = true;
removedListeners = [];
}
this._emitterListeners.filterAll(function(record) {
var keepListener = record.registeredContext !== context;
if (trackRemovals && keepListener === false) {
removedListeners.push(record);
}
return keepListener;
});
if (trackRemovals && removedListeners.length > 0) {
notifyRemoves(this, removedListeners);
}
} | [
"function",
"clearListeners",
"(",
"context",
")",
"{",
"if",
"(",
"context",
"==",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"'clearListeners: context must be provided.'",
")",
";",
"}",
"// notify for every listener we throw out.",
"var",
"removedListeners",
",",
"trackRemovals",
"=",
"false",
";",
"if",
"(",
"this",
".",
"_emitterMetaEventsOn",
"===",
"true",
")",
"{",
"trackRemovals",
"=",
"true",
";",
"removedListeners",
"=",
"[",
"]",
";",
"}",
"this",
".",
"_emitterListeners",
".",
"filterAll",
"(",
"function",
"(",
"record",
")",
"{",
"var",
"keepListener",
"=",
"record",
".",
"registeredContext",
"!==",
"context",
";",
"if",
"(",
"trackRemovals",
"&&",
"keepListener",
"===",
"false",
")",
"{",
"removedListeners",
".",
"push",
"(",
"record",
")",
";",
"}",
"return",
"keepListener",
";",
"}",
")",
";",
"if",
"(",
"trackRemovals",
"&&",
"removedListeners",
".",
"length",
">",
"0",
")",
"{",
"notifyRemoves",
"(",
"this",
",",
"removedListeners",
")",
";",
"}",
"}"
] | Clears all listeners registered for a particular context.
@param {Object} context The context that all listeners should be removed for. May not be null. | [
"Clears",
"all",
"listeners",
"registered",
"for",
"a",
"particular",
"context",
"."
] | 66ec84c3db3ff0f83a6ced87b805b2d3934d5613 | https://github.com/BladeRunnerJS/emitr/blob/66ec84c3db3ff0f83a6ced87b805b2d3934d5613/src/Emitter.js#L239-L257 |
53,542 | highly-attractive-people/jsonapi-relate | index.js | getIncluded | function getIncluded(payload, type, id) {
for (var i = payload.included.length - 1; i >= 0; i--) {
if (payload.included[i].id === id && payload.included[i].type === type) {
return payload.included[i];
}
}
} | javascript | function getIncluded(payload, type, id) {
for (var i = payload.included.length - 1; i >= 0; i--) {
if (payload.included[i].id === id && payload.included[i].type === type) {
return payload.included[i];
}
}
} | [
"function",
"getIncluded",
"(",
"payload",
",",
"type",
",",
"id",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"payload",
".",
"included",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"payload",
".",
"included",
"[",
"i",
"]",
".",
"id",
"===",
"id",
"&&",
"payload",
".",
"included",
"[",
"i",
"]",
".",
"type",
"===",
"type",
")",
"{",
"return",
"payload",
".",
"included",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] | Fetches an included object from a payload by its id
@param {Object} payload
The payload encapsulating the included data
@param {String} type
The entity type to retrieve
@param {String} id
The id of the desired included data
@return {Object}
The found included data | [
"Fetches",
"an",
"included",
"object",
"from",
"a",
"payload",
"by",
"its",
"id"
] | 60da29962ea0fc2767b6d87d0bf8b25669eb996d | https://github.com/highly-attractive-people/jsonapi-relate/blob/60da29962ea0fc2767b6d87d0bf8b25669eb996d/index.js#L14-L20 |
53,543 | highly-attractive-people/jsonapi-relate | index.js | getDeepRelationship | function getDeepRelationship(payload, parentResource, deepKey) {
var path = deepKey.split('.');
var subResources = parentResource;
for (var i = 0; i < path.length; i++) {
if (Array.isArray(subResources)) {
subResources = subResources.reduce(function (results, subResource) {
return results.concat(
subResource && getRelationship(payload, subResource, path[i])
);
}, []);
}
else {
subResources = subResources && getRelationship(payload, subResources, path[i]);
}
}
return subResources;
} | javascript | function getDeepRelationship(payload, parentResource, deepKey) {
var path = deepKey.split('.');
var subResources = parentResource;
for (var i = 0; i < path.length; i++) {
if (Array.isArray(subResources)) {
subResources = subResources.reduce(function (results, subResource) {
return results.concat(
subResource && getRelationship(payload, subResource, path[i])
);
}, []);
}
else {
subResources = subResources && getRelationship(payload, subResources, path[i]);
}
}
return subResources;
} | [
"function",
"getDeepRelationship",
"(",
"payload",
",",
"parentResource",
",",
"deepKey",
")",
"{",
"var",
"path",
"=",
"deepKey",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"subResources",
"=",
"parentResource",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"path",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"subResources",
")",
")",
"{",
"subResources",
"=",
"subResources",
".",
"reduce",
"(",
"function",
"(",
"results",
",",
"subResource",
")",
"{",
"return",
"results",
".",
"concat",
"(",
"subResource",
"&&",
"getRelationship",
"(",
"payload",
",",
"subResource",
",",
"path",
"[",
"i",
"]",
")",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"else",
"{",
"subResources",
"=",
"subResources",
"&&",
"getRelationship",
"(",
"payload",
",",
"subResources",
",",
"path",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"subResources",
";",
"}"
] | Fetches specified related data associated to a resource,
and related data assocociated to that included resource...
@param {Object} payload
The payload encapsulating the included data
@param {Object} parentResource
The first resource to find included data for
@param {String} deepKey
The relationship to included data to retrieve, delimited by periods.
@return {Array|Object|undefined}
The found included data object(s) or undefined if the requested included
data is not part of the API response | [
"Fetches",
"specified",
"related",
"data",
"associated",
"to",
"a",
"resource",
"and",
"related",
"data",
"assocociated",
"to",
"that",
"included",
"resource",
"..."
] | 60da29962ea0fc2767b6d87d0bf8b25669eb996d | https://github.com/highly-attractive-people/jsonapi-relate/blob/60da29962ea0fc2767b6d87d0bf8b25669eb996d/index.js#L86-L102 |
53,544 | rkaw92/esdf | EventSourcedAggregate.js | AggregateTypeMismatch | function AggregateTypeMismatch(expected, got){
this.name = 'AggregateTypeMismatch';
this.message = 'Aggregate type mismatch: expected (' + typeof(expected) + ')' + expected + ', got (' + typeof(got) + ')' + got;
this.labels = {
expected: expected,
got: got,
critical: true // This error precludes retry attempts (assuming a sane retry strategy is employed).
};
} | javascript | function AggregateTypeMismatch(expected, got){
this.name = 'AggregateTypeMismatch';
this.message = 'Aggregate type mismatch: expected (' + typeof(expected) + ')' + expected + ', got (' + typeof(got) + ')' + got;
this.labels = {
expected: expected,
got: got,
critical: true // This error precludes retry attempts (assuming a sane retry strategy is employed).
};
} | [
"function",
"AggregateTypeMismatch",
"(",
"expected",
",",
"got",
")",
"{",
"this",
".",
"name",
"=",
"'AggregateTypeMismatch'",
";",
"this",
".",
"message",
"=",
"'Aggregate type mismatch: expected ('",
"+",
"typeof",
"(",
"expected",
")",
"+",
"')'",
"+",
"expected",
"+",
"', got ('",
"+",
"typeof",
"(",
"got",
")",
"+",
"')'",
"+",
"got",
";",
"this",
".",
"labels",
"=",
"{",
"expected",
":",
"expected",
",",
"got",
":",
"got",
",",
"critical",
":",
"true",
"// This error precludes retry attempts (assuming a sane retry strategy is employed).",
"}",
";",
"}"
] | Aggregate-event type mismatch. Generated when a commit labelled with another AggregateType is applied to an aggregate.
Also occurs when a snapshot type mismatch takes place.
This prevents loading an aggregateID as another, unrelated aggregate type and trashing the database or bypassing logic restrictions.
@constructor
@extends Error | [
"Aggregate",
"-",
"event",
"type",
"mismatch",
".",
"Generated",
"when",
"a",
"commit",
"labelled",
"with",
"another",
"AggregateType",
"is",
"applied",
"to",
"an",
"aggregate",
".",
"Also",
"occurs",
"when",
"a",
"snapshot",
"type",
"mismatch",
"takes",
"place",
".",
"This",
"prevents",
"loading",
"an",
"aggregateID",
"as",
"another",
"unrelated",
"aggregate",
"type",
"and",
"trashing",
"the",
"database",
"or",
"bypassing",
"logic",
"restrictions",
"."
] | 9c6bd2c278428096cb8c1ceeca62a5493d19613e | https://github.com/rkaw92/esdf/blob/9c6bd2c278428096cb8c1ceeca62a5493d19613e/EventSourcedAggregate.js#L21-L29 |
53,545 | four43/admiral-cli | lib/error/abstract-error.js | AbstractCliError | function AbstractCliError(message, statusCode) {
Error.call(this, message, statusCode);
Error.captureStackTrace(this, AbstractCliError);
this.message = message || this.message
} | javascript | function AbstractCliError(message, statusCode) {
Error.call(this, message, statusCode);
Error.captureStackTrace(this, AbstractCliError);
this.message = message || this.message
} | [
"function",
"AbstractCliError",
"(",
"message",
",",
"statusCode",
")",
"{",
"Error",
".",
"call",
"(",
"this",
",",
"message",
",",
"statusCode",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"AbstractCliError",
")",
";",
"this",
".",
"message",
"=",
"message",
"||",
"this",
".",
"message",
"}"
] | Abstract CLI Error
General error for CLI, all errors are children of this.
@param message
@param statusCode
@constructor | [
"Abstract",
"CLI",
"Error"
] | f6049dbb783a2c85c601c09ba7abc7dd87bd11fe | https://github.com/four43/admiral-cli/blob/f6049dbb783a2c85c601c09ba7abc7dd87bd11fe/lib/error/abstract-error.js#L10-L15 |
53,546 | leoasis/makery.js | makery.js | createInstanceOf | function createInstanceOf(ctor, args) {
var tempCtor = function() {
// This will return the instance or the explicit return of the ctor
// accordingly.
// Remember that if you return a primitive type, the constructor will
// still return the object instance.
return ctor.apply(this, args);
};
tempCtor.prototype = ctor.prototype;
return new tempCtor();
} | javascript | function createInstanceOf(ctor, args) {
var tempCtor = function() {
// This will return the instance or the explicit return of the ctor
// accordingly.
// Remember that if you return a primitive type, the constructor will
// still return the object instance.
return ctor.apply(this, args);
};
tempCtor.prototype = ctor.prototype;
return new tempCtor();
} | [
"function",
"createInstanceOf",
"(",
"ctor",
",",
"args",
")",
"{",
"var",
"tempCtor",
"=",
"function",
"(",
")",
"{",
"// This will return the instance or the explicit return of the ctor",
"// accordingly.",
"// Remember that if you return a primitive type, the constructor will",
"// still return the object instance.",
"return",
"ctor",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
";",
"tempCtor",
".",
"prototype",
"=",
"ctor",
".",
"prototype",
";",
"return",
"new",
"tempCtor",
"(",
")",
";",
"}"
] | We need a custom creation of an instance because we cannot pass a dynamic amount of args into a constructor when calling them with "new", so we must first call it with a fake constructor with the same prototype and then apply the real one with the correct args. | [
"We",
"need",
"a",
"custom",
"creation",
"of",
"an",
"instance",
"because",
"we",
"cannot",
"pass",
"a",
"dynamic",
"amount",
"of",
"args",
"into",
"a",
"constructor",
"when",
"calling",
"them",
"with",
"new",
"so",
"we",
"must",
"first",
"call",
"it",
"with",
"a",
"fake",
"constructor",
"with",
"the",
"same",
"prototype",
"and",
"then",
"apply",
"the",
"real",
"one",
"with",
"the",
"correct",
"args",
"."
] | f50201fa2054eb9b8f66f48a1126c4872a569483 | https://github.com/leoasis/makery.js/blob/f50201fa2054eb9b8f66f48a1126c4872a569483/makery.js#L87-L98 |
53,547 | scisco/yaml-files | bin/cli.js | merge | function merge(input, output) {
const text = fs.readFileSync(input, 'utf8');
const loaded = yaml.safeLoad(text.toString(), { schema: yamlfiles.YAML_FILES_SCHEMA });
// write to output
fs.writeFileSync(output, yaml.safeDump(loaded));
return output;
} | javascript | function merge(input, output) {
const text = fs.readFileSync(input, 'utf8');
const loaded = yaml.safeLoad(text.toString(), { schema: yamlfiles.YAML_FILES_SCHEMA });
// write to output
fs.writeFileSync(output, yaml.safeDump(loaded));
return output;
} | [
"function",
"merge",
"(",
"input",
",",
"output",
")",
"{",
"const",
"text",
"=",
"fs",
".",
"readFileSync",
"(",
"input",
",",
"'utf8'",
")",
";",
"const",
"loaded",
"=",
"yaml",
".",
"safeLoad",
"(",
"text",
".",
"toString",
"(",
")",
",",
"{",
"schema",
":",
"yamlfiles",
".",
"YAML_FILES_SCHEMA",
"}",
")",
";",
"// write to output",
"fs",
".",
"writeFileSync",
"(",
"output",
",",
"yaml",
".",
"safeDump",
"(",
"loaded",
")",
")",
";",
"return",
"output",
";",
"}"
] | parse-merge a given yaml file and save it to a
given output
@param {string} input - input yaml file path
@param {string} output - output yaml file path
@returns {string} the output path | [
"parse",
"-",
"merge",
"a",
"given",
"yaml",
"file",
"and",
"save",
"it",
"to",
"a",
"given",
"output"
] | 71de1364800a24a5cf86b12264fb6345eaf8f283 | https://github.com/scisco/yaml-files/blob/71de1364800a24a5cf86b12264fb6345eaf8f283/bin/cli.js#L17-L24 |
53,548 | aleclarson/quest | index.js | concat | function concat(res, done) {
const chunks = []
res
.on('data', chunk => {
chunks.push(chunk)
})
.on('end', () => {
done(Buffer.concat(chunks))
})
} | javascript | function concat(res, done) {
const chunks = []
res
.on('data', chunk => {
chunks.push(chunk)
})
.on('end', () => {
done(Buffer.concat(chunks))
})
} | [
"function",
"concat",
"(",
"res",
",",
"done",
")",
"{",
"const",
"chunks",
"=",
"[",
"]",
"res",
".",
"on",
"(",
"'data'",
",",
"chunk",
"=>",
"{",
"chunks",
".",
"push",
"(",
"chunk",
")",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"{",
"done",
"(",
"Buffer",
".",
"concat",
"(",
"chunks",
")",
")",
"}",
")",
"}"
] | Buffer the entire stream into memory. | [
"Buffer",
"the",
"entire",
"stream",
"into",
"memory",
"."
] | c8f9e1729304aebe6ed6a805f4798f2945eebd2a | https://github.com/aleclarson/quest/blob/c8f9e1729304aebe6ed6a805f4798f2945eebd2a/index.js#L194-L203 |
53,549 | linyngfly/omelo | lib/util/appUtil.js | function(app, args) {
let serverType = args.serverType || Constants.RESERVED.MASTER;
let serverId = args.id || app.getMaster().id;
let mode = args.mode || Constants.RESERVED.CLUSTER;
let masterha = args.masterha || 'false';
let type = args.type || Constants.RESERVED.ALL;
let startId = args.startId;
app.set(Constants.RESERVED.MAIN, args.main, true);
app.set(Constants.RESERVED.SERVER_TYPE, serverType, true);
app.set(Constants.RESERVED.SERVER_ID, serverId, true);
app.set(Constants.RESERVED.MODE, mode, true);
app.set(Constants.RESERVED.TYPE, type, true);
if(!!startId) {
app.set(Constants.RESERVED.STARTID, startId, true);
}
if (masterha === 'true') {
app.master = args;
app.set(Constants.RESERVED.CURRENT_SERVER, args, true);
} else if (serverType !== Constants.RESERVED.MASTER) {
app.set(Constants.RESERVED.CURRENT_SERVER, args, true);
} else {
app.set(Constants.RESERVED.CURRENT_SERVER, app.getMaster(), true);
}
} | javascript | function(app, args) {
let serverType = args.serverType || Constants.RESERVED.MASTER;
let serverId = args.id || app.getMaster().id;
let mode = args.mode || Constants.RESERVED.CLUSTER;
let masterha = args.masterha || 'false';
let type = args.type || Constants.RESERVED.ALL;
let startId = args.startId;
app.set(Constants.RESERVED.MAIN, args.main, true);
app.set(Constants.RESERVED.SERVER_TYPE, serverType, true);
app.set(Constants.RESERVED.SERVER_ID, serverId, true);
app.set(Constants.RESERVED.MODE, mode, true);
app.set(Constants.RESERVED.TYPE, type, true);
if(!!startId) {
app.set(Constants.RESERVED.STARTID, startId, true);
}
if (masterha === 'true') {
app.master = args;
app.set(Constants.RESERVED.CURRENT_SERVER, args, true);
} else if (serverType !== Constants.RESERVED.MASTER) {
app.set(Constants.RESERVED.CURRENT_SERVER, args, true);
} else {
app.set(Constants.RESERVED.CURRENT_SERVER, app.getMaster(), true);
}
} | [
"function",
"(",
"app",
",",
"args",
")",
"{",
"let",
"serverType",
"=",
"args",
".",
"serverType",
"||",
"Constants",
".",
"RESERVED",
".",
"MASTER",
";",
"let",
"serverId",
"=",
"args",
".",
"id",
"||",
"app",
".",
"getMaster",
"(",
")",
".",
"id",
";",
"let",
"mode",
"=",
"args",
".",
"mode",
"||",
"Constants",
".",
"RESERVED",
".",
"CLUSTER",
";",
"let",
"masterha",
"=",
"args",
".",
"masterha",
"||",
"'false'",
";",
"let",
"type",
"=",
"args",
".",
"type",
"||",
"Constants",
".",
"RESERVED",
".",
"ALL",
";",
"let",
"startId",
"=",
"args",
".",
"startId",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"MAIN",
",",
"args",
".",
"main",
",",
"true",
")",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"SERVER_TYPE",
",",
"serverType",
",",
"true",
")",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"SERVER_ID",
",",
"serverId",
",",
"true",
")",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"MODE",
",",
"mode",
",",
"true",
")",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"TYPE",
",",
"type",
",",
"true",
")",
";",
"if",
"(",
"!",
"!",
"startId",
")",
"{",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"STARTID",
",",
"startId",
",",
"true",
")",
";",
"}",
"if",
"(",
"masterha",
"===",
"'true'",
")",
"{",
"app",
".",
"master",
"=",
"args",
";",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"CURRENT_SERVER",
",",
"args",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"serverType",
"!==",
"Constants",
".",
"RESERVED",
".",
"MASTER",
")",
"{",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"CURRENT_SERVER",
",",
"args",
",",
"true",
")",
";",
"}",
"else",
"{",
"app",
".",
"set",
"(",
"Constants",
".",
"RESERVED",
".",
"CURRENT_SERVER",
",",
"app",
".",
"getMaster",
"(",
")",
",",
"true",
")",
";",
"}",
"}"
] | Process server start command | [
"Process",
"server",
"start",
"command"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/util/appUtil.js#L163-L188 |
|
53,550 | yanatan16/node-redis-eval | index.js | onerror | function onerror(cb) {
return function (err) {
if (err) {
shas = {}
arguments[0] = err instanceof Error ? err : new Error(err.toString())
}
cb.apply(null, arguments)
}
} | javascript | function onerror(cb) {
return function (err) {
if (err) {
shas = {}
arguments[0] = err instanceof Error ? err : new Error(err.toString())
}
cb.apply(null, arguments)
}
} | [
"function",
"onerror",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"shas",
"=",
"{",
"}",
"arguments",
"[",
"0",
"]",
"=",
"err",
"instanceof",
"Error",
"?",
"err",
":",
"new",
"Error",
"(",
"err",
".",
"toString",
"(",
")",
")",
"}",
"cb",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"}",
"}"
] | If an error occurs, we must be prudent and assume data was lost. We clean the shas cache. | [
"If",
"an",
"error",
"occurs",
"we",
"must",
"be",
"prudent",
"and",
"assume",
"data",
"was",
"lost",
".",
"We",
"clean",
"the",
"shas",
"cache",
"."
] | 8ce7fda84a8246e8e8f9d39ab3caca506a4960f7 | https://github.com/yanatan16/node-redis-eval/blob/8ce7fda84a8246e8e8f9d39ab3caca506a4960f7/index.js#L51-L59 |
53,551 | yanatan16/node-redis-eval | index.js | evalSha | function evalSha(redis, sha, keys, args, callback) {
if (sha) {
return redis.evalsha.apply(redis, _.flatten([sha, keys.length, keys, args, callback]));
}
return callback(new Error('evalsha called for not loaded script'));
} | javascript | function evalSha(redis, sha, keys, args, callback) {
if (sha) {
return redis.evalsha.apply(redis, _.flatten([sha, keys.length, keys, args, callback]));
}
return callback(new Error('evalsha called for not loaded script'));
} | [
"function",
"evalSha",
"(",
"redis",
",",
"sha",
",",
"keys",
",",
"args",
",",
"callback",
")",
"{",
"if",
"(",
"sha",
")",
"{",
"return",
"redis",
".",
"evalsha",
".",
"apply",
"(",
"redis",
",",
"_",
".",
"flatten",
"(",
"[",
"sha",
",",
"keys",
".",
"length",
",",
"keys",
",",
"args",
",",
"callback",
"]",
")",
")",
";",
"}",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'evalsha called for not loaded script'",
")",
")",
";",
"}"
] | Evaluate a script that is already loaded | [
"Evaluate",
"a",
"script",
"that",
"is",
"already",
"loaded"
] | 8ce7fda84a8246e8e8f9d39ab3caca506a4960f7 | https://github.com/yanatan16/node-redis-eval/blob/8ce7fda84a8246e8e8f9d39ab3caca506a4960f7/index.js#L84-L89 |
53,552 | yanatan16/node-redis-eval | index.js | loadScript | function loadScript(redis, script_name, script, callback) {
redis.multi()
.script('load', script)
.exec(function (err, sha1) {
if (err) {
return callback(err);
}
shas[script_name] = sha1 && sha1.length && sha1[0];
callback(null, sha1);
});
} | javascript | function loadScript(redis, script_name, script, callback) {
redis.multi()
.script('load', script)
.exec(function (err, sha1) {
if (err) {
return callback(err);
}
shas[script_name] = sha1 && sha1.length && sha1[0];
callback(null, sha1);
});
} | [
"function",
"loadScript",
"(",
"redis",
",",
"script_name",
",",
"script",
",",
"callback",
")",
"{",
"redis",
".",
"multi",
"(",
")",
".",
"script",
"(",
"'load'",
",",
"script",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"sha1",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"shas",
"[",
"script_name",
"]",
"=",
"sha1",
"&&",
"sha1",
".",
"length",
"&&",
"sha1",
"[",
"0",
"]",
";",
"callback",
"(",
"null",
",",
"sha1",
")",
";",
"}",
")",
";",
"}"
] | Load a script into the script cache | [
"Load",
"a",
"script",
"into",
"the",
"script",
"cache"
] | 8ce7fda84a8246e8e8f9d39ab3caca506a4960f7 | https://github.com/yanatan16/node-redis-eval/blob/8ce7fda84a8246e8e8f9d39ab3caca506a4960f7/index.js#L92-L102 |
53,553 | linyngfly/omelo | lib/master/starter.js | function(command, host, options, cb) {
let child = null;
if(env === Constants.RESERVED.ENV_DEV) {
child = cp.spawn(command, options);
let prefix = command === Constants.COMMAND.SSH ? '[' + host + '] ' : '';
child.stderr.on('data', function (chunk) {
let msg = chunk.toString();
process.stderr.write(msg);
if(!!cb) {
cb(msg);
}
});
child.stdout.on('data', function (chunk) {
let msg = prefix + chunk.toString();
process.stdout.write(msg);
});
} else {
child = cp.spawn(command, options, {detached: true, stdio: 'inherit'});
child.unref();
}
child.on('exit', function (code) {
if(code !== 0) {
logger.warn('child process exit with error, error code: %s, executed command: %s', code, command);
}
if (typeof cb === 'function') {
cb(code === 0 ? null : code);
}
});
} | javascript | function(command, host, options, cb) {
let child = null;
if(env === Constants.RESERVED.ENV_DEV) {
child = cp.spawn(command, options);
let prefix = command === Constants.COMMAND.SSH ? '[' + host + '] ' : '';
child.stderr.on('data', function (chunk) {
let msg = chunk.toString();
process.stderr.write(msg);
if(!!cb) {
cb(msg);
}
});
child.stdout.on('data', function (chunk) {
let msg = prefix + chunk.toString();
process.stdout.write(msg);
});
} else {
child = cp.spawn(command, options, {detached: true, stdio: 'inherit'});
child.unref();
}
child.on('exit', function (code) {
if(code !== 0) {
logger.warn('child process exit with error, error code: %s, executed command: %s', code, command);
}
if (typeof cb === 'function') {
cb(code === 0 ? null : code);
}
});
} | [
"function",
"(",
"command",
",",
"host",
",",
"options",
",",
"cb",
")",
"{",
"let",
"child",
"=",
"null",
";",
"if",
"(",
"env",
"===",
"Constants",
".",
"RESERVED",
".",
"ENV_DEV",
")",
"{",
"child",
"=",
"cp",
".",
"spawn",
"(",
"command",
",",
"options",
")",
";",
"let",
"prefix",
"=",
"command",
"===",
"Constants",
".",
"COMMAND",
".",
"SSH",
"?",
"'['",
"+",
"host",
"+",
"'] '",
":",
"''",
";",
"child",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"let",
"msg",
"=",
"chunk",
".",
"toString",
"(",
")",
";",
"process",
".",
"stderr",
".",
"write",
"(",
"msg",
")",
";",
"if",
"(",
"!",
"!",
"cb",
")",
"{",
"cb",
"(",
"msg",
")",
";",
"}",
"}",
")",
";",
"child",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"let",
"msg",
"=",
"prefix",
"+",
"chunk",
".",
"toString",
"(",
")",
";",
"process",
".",
"stdout",
".",
"write",
"(",
"msg",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"child",
"=",
"cp",
".",
"spawn",
"(",
"command",
",",
"options",
",",
"{",
"detached",
":",
"true",
",",
"stdio",
":",
"'inherit'",
"}",
")",
";",
"child",
".",
"unref",
"(",
")",
";",
"}",
"child",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"!==",
"0",
")",
"{",
"logger",
".",
"warn",
"(",
"'child process exit with error, error code: %s, executed command: %s'",
",",
"code",
",",
"command",
")",
";",
"}",
"if",
"(",
"typeof",
"cb",
"===",
"'function'",
")",
"{",
"cb",
"(",
"code",
"===",
"0",
"?",
"null",
":",
"code",
")",
";",
"}",
"}",
")",
";",
"}"
] | Fork child process to run command.
@param {String} command
@param {Object} options
@param {Callback} callback | [
"Fork",
"child",
"process",
"to",
"run",
"command",
"."
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/master/starter.js#L188-L220 |
|
53,554 | tmpfs/ttycolor | lib/parse.js | opt | function opt(argv, arg, index, key) {
var value = argv[index + 1], equals = arg.indexOf('=');
if(equals > -1) {
value = arg.substr(equals + 1);
}
if(value && ~keys.indexOf(value)) {
return value;
}
if(arg === option[key]) {
return modes[key];
}
} | javascript | function opt(argv, arg, index, key) {
var value = argv[index + 1], equals = arg.indexOf('=');
if(equals > -1) {
value = arg.substr(equals + 1);
}
if(value && ~keys.indexOf(value)) {
return value;
}
if(arg === option[key]) {
return modes[key];
}
} | [
"function",
"opt",
"(",
"argv",
",",
"arg",
",",
"index",
",",
"key",
")",
"{",
"var",
"value",
"=",
"argv",
"[",
"index",
"+",
"1",
"]",
",",
"equals",
"=",
"arg",
".",
"indexOf",
"(",
"'='",
")",
";",
"if",
"(",
"equals",
">",
"-",
"1",
")",
"{",
"value",
"=",
"arg",
".",
"substr",
"(",
"equals",
"+",
"1",
")",
";",
"}",
"if",
"(",
"value",
"&&",
"~",
"keys",
".",
"indexOf",
"(",
"value",
")",
")",
"{",
"return",
"value",
";",
"}",
"if",
"(",
"arg",
"===",
"option",
"[",
"key",
"]",
")",
"{",
"return",
"modes",
"[",
"key",
"]",
";",
"}",
"}"
] | parse long options | [
"parse",
"long",
"options"
] | 4b72de7f61bfd922f227f3f4e7c61fb95ff9c023 | https://github.com/tmpfs/ttycolor/blob/4b72de7f61bfd922f227f3f4e7c61fb95ff9c023/lib/parse.js#L33-L44 |
53,555 | twolfson/fs-memory-store | lib/fs-memory-store.js | Store | function Store(dir, options) {
// Specify the directory and its options
assert(dir, '`Store` expected a `dir` (directory) to be passed in but it was not defined');
this.dir = dir;
this.memoryCache = {};
// Fallback options
options = options || {};
this.ext = options.ext || Store.ext;
this.stringify = options.stringify || Store.stringify;
this.parse = options.parse || Store.parse;
} | javascript | function Store(dir, options) {
// Specify the directory and its options
assert(dir, '`Store` expected a `dir` (directory) to be passed in but it was not defined');
this.dir = dir;
this.memoryCache = {};
// Fallback options
options = options || {};
this.ext = options.ext || Store.ext;
this.stringify = options.stringify || Store.stringify;
this.parse = options.parse || Store.parse;
} | [
"function",
"Store",
"(",
"dir",
",",
"options",
")",
"{",
"// Specify the directory and its options",
"assert",
"(",
"dir",
",",
"'`Store` expected a `dir` (directory) to be passed in but it was not defined'",
")",
";",
"this",
".",
"dir",
"=",
"dir",
";",
"this",
".",
"memoryCache",
"=",
"{",
"}",
";",
"// Fallback options",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"ext",
"=",
"options",
".",
"ext",
"||",
"Store",
".",
"ext",
";",
"this",
".",
"stringify",
"=",
"options",
".",
"stringify",
"||",
"Store",
".",
"stringify",
";",
"this",
".",
"parse",
"=",
"options",
".",
"parse",
"||",
"Store",
".",
"parse",
";",
"}"
] | Filesystem storage system with in-memory cache
@param dir {String} Directory to generate our store inside of
@param options {Object} Container for options/flags
@param [options.ext='.json'] {String} Optional extension to save values under
@param [options.stringify=JSON.stringify] {Function} Optional stringifier to pass values through
@param [options.parse=JSON.parse] {Function} Optional parser to load values through | [
"Filesystem",
"storage",
"system",
"with",
"in",
"-",
"memory",
"cache"
] | 2f3b6e336097ec1d5f1a29c4ecbed70fbece1032 | https://github.com/twolfson/fs-memory-store/blob/2f3b6e336097ec1d5f1a29c4ecbed70fbece1032/lib/fs-memory-store.js#L16-L27 |
53,556 | soldair/node-repipe | index.js | resumeable | function resumeable(last,source,s){
source.last = last;
source.on('data',function(data){
source.last = data;
s.write(data);
})
var onPause = function(){
source.pause();
};
var onDrain = function(){
source.resume();
};
var onEnd = function(){
source.end();
};
var cleanup = function(){
s.removeListener('pause',onPause);
s.removeListener('drain',onDrain);
s.removeListener('end',onEnd);
};
s.on('pause',onPause);
s.on('drain',onDrain);
s.on('end',onEnd);
source.on('error',function(){
source._errored = true;
cleanup();
});
source.on('end',function(){
cleanup();
if(!source._errored) {
s.end();
}
})
return s;
} | javascript | function resumeable(last,source,s){
source.last = last;
source.on('data',function(data){
source.last = data;
s.write(data);
})
var onPause = function(){
source.pause();
};
var onDrain = function(){
source.resume();
};
var onEnd = function(){
source.end();
};
var cleanup = function(){
s.removeListener('pause',onPause);
s.removeListener('drain',onDrain);
s.removeListener('end',onEnd);
};
s.on('pause',onPause);
s.on('drain',onDrain);
s.on('end',onEnd);
source.on('error',function(){
source._errored = true;
cleanup();
});
source.on('end',function(){
cleanup();
if(!source._errored) {
s.end();
}
})
return s;
} | [
"function",
"resumeable",
"(",
"last",
",",
"source",
",",
"s",
")",
"{",
"source",
".",
"last",
"=",
"last",
";",
"source",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"source",
".",
"last",
"=",
"data",
";",
"s",
".",
"write",
"(",
"data",
")",
";",
"}",
")",
"var",
"onPause",
"=",
"function",
"(",
")",
"{",
"source",
".",
"pause",
"(",
")",
";",
"}",
";",
"var",
"onDrain",
"=",
"function",
"(",
")",
"{",
"source",
".",
"resume",
"(",
")",
";",
"}",
";",
"var",
"onEnd",
"=",
"function",
"(",
")",
"{",
"source",
".",
"end",
"(",
")",
";",
"}",
";",
"var",
"cleanup",
"=",
"function",
"(",
")",
"{",
"s",
".",
"removeListener",
"(",
"'pause'",
",",
"onPause",
")",
";",
"s",
".",
"removeListener",
"(",
"'drain'",
",",
"onDrain",
")",
";",
"s",
".",
"removeListener",
"(",
"'end'",
",",
"onEnd",
")",
";",
"}",
";",
"s",
".",
"on",
"(",
"'pause'",
",",
"onPause",
")",
";",
"s",
".",
"on",
"(",
"'drain'",
",",
"onDrain",
")",
";",
"s",
".",
"on",
"(",
"'end'",
",",
"onEnd",
")",
";",
"source",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
")",
"{",
"source",
".",
"_errored",
"=",
"true",
";",
"cleanup",
"(",
")",
";",
"}",
")",
";",
"source",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"cleanup",
"(",
")",
";",
"if",
"(",
"!",
"source",
".",
"_errored",
")",
"{",
"s",
".",
"end",
"(",
")",
";",
"}",
"}",
")",
"return",
"s",
";",
"}"
] | its kinda like pipe except everythig bubbles. | [
"its",
"kinda",
"like",
"pipe",
"except",
"everythig",
"bubbles",
"."
] | b7e67005a4c49e2820eb08f036b2d441dbf31091 | https://github.com/soldair/node-repipe/blob/b7e67005a4c49e2820eb08f036b2d441dbf31091/index.js#L34-L74 |
53,557 | bvalosek/grunt-infusionsoft | tasks/generator/Scraper.js | function()
{
var url = this.docsUrl;
var _this = this;
var d = Q.defer();
// Need to create an array of promises for all the pages and their hash
Q.nfcall(request, url + '/api-docs').then(function(data) {
var $ = cheerio.load(data);
var list = $('ul.nav-list li a');
var requests = [];
list.each(function() {
var href = $(this).attr('href');
// If a service, get the promise for the scraped data and
// notify when we've got it
if (/service$/.test(href)) {
var p = _this.getServiceInterface(url + href);
p.then(function(s) { d.notify(s.serviceName); });
requests.push(p);
}
});
// Spread out over all of the promises, when they're all done,
// we've got the data in the arguments var, iterate over that and
// build the hash to return
Q.spread(requests, function() {
d.resolve(_(arguments).toArray());
});
});
return d.promise;
} | javascript | function()
{
var url = this.docsUrl;
var _this = this;
var d = Q.defer();
// Need to create an array of promises for all the pages and their hash
Q.nfcall(request, url + '/api-docs').then(function(data) {
var $ = cheerio.load(data);
var list = $('ul.nav-list li a');
var requests = [];
list.each(function() {
var href = $(this).attr('href');
// If a service, get the promise for the scraped data and
// notify when we've got it
if (/service$/.test(href)) {
var p = _this.getServiceInterface(url + href);
p.then(function(s) { d.notify(s.serviceName); });
requests.push(p);
}
});
// Spread out over all of the promises, when they're all done,
// we've got the data in the arguments var, iterate over that and
// build the hash to return
Q.spread(requests, function() {
d.resolve(_(arguments).toArray());
});
});
return d.promise;
} | [
"function",
"(",
")",
"{",
"var",
"url",
"=",
"this",
".",
"docsUrl",
";",
"var",
"_this",
"=",
"this",
";",
"var",
"d",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"// Need to create an array of promises for all the pages and their hash",
"Q",
".",
"nfcall",
"(",
"request",
",",
"url",
"+",
"'/api-docs'",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"data",
")",
";",
"var",
"list",
"=",
"$",
"(",
"'ul.nav-list li a'",
")",
";",
"var",
"requests",
"=",
"[",
"]",
";",
"list",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"href",
"=",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'href'",
")",
";",
"// If a service, get the promise for the scraped data and",
"// notify when we've got it",
"if",
"(",
"/",
"service$",
"/",
".",
"test",
"(",
"href",
")",
")",
"{",
"var",
"p",
"=",
"_this",
".",
"getServiceInterface",
"(",
"url",
"+",
"href",
")",
";",
"p",
".",
"then",
"(",
"function",
"(",
"s",
")",
"{",
"d",
".",
"notify",
"(",
"s",
".",
"serviceName",
")",
";",
"}",
")",
";",
"requests",
".",
"push",
"(",
"p",
")",
";",
"}",
"}",
")",
";",
"// Spread out over all of the promises, when they're all done,",
"// we've got the data in the arguments var, iterate over that and",
"// build the hash to return",
"Q",
".",
"spread",
"(",
"requests",
",",
"function",
"(",
")",
"{",
"d",
".",
"resolve",
"(",
"_",
"(",
"arguments",
")",
".",
"toArray",
"(",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"d",
".",
"promise",
";",
"}"
] | Get a promise representing an eventua lhash for all the infusionsoft API service calls | [
"Get",
"a",
"promise",
"representing",
"an",
"eventua",
"lhash",
"for",
"all",
"the",
"infusionsoft",
"API",
"service",
"calls"
] | 847dfde26021cb228ea4004c6a6d148d56e95703 | https://github.com/bvalosek/grunt-infusionsoft/blob/847dfde26021cb228ea4004c6a6d148d56e95703/tasks/generator/Scraper.js#L29-L63 |
|
53,558 | bvalosek/grunt-infusionsoft | tasks/generator/Scraper.js | function()
{
var url = this.tableUrl;
var _this = this;
var d = new Q.defer();
var tableInfo;
this.getTableInfo()
.then(function(info) {
tableInfo = info;
return Q.nfcall(request, url + '/index.html');
})
.then(function(data) {
var $ = cheerio.load(data);
var list = $('#tables li');
var requests = [];
list.each(function() {
var $this = this;
var title = $this.find('a').text();
var link = $this.find('a').attr('href');
// Once we've got the table, add the description and fire an
// update back on the promise
var p = _this.getTableFields(url + '/' + link);
p.then(function(t) { t.description = tableInfo[t.tableName]; });
p.then(function(s) { d.notify(s.tableName); });
requests.push(p);
});
Q.spread(requests, function() {
d.resolve(_(arguments).toArray());
});
});
return d.promise;
} | javascript | function()
{
var url = this.tableUrl;
var _this = this;
var d = new Q.defer();
var tableInfo;
this.getTableInfo()
.then(function(info) {
tableInfo = info;
return Q.nfcall(request, url + '/index.html');
})
.then(function(data) {
var $ = cheerio.load(data);
var list = $('#tables li');
var requests = [];
list.each(function() {
var $this = this;
var title = $this.find('a').text();
var link = $this.find('a').attr('href');
// Once we've got the table, add the description and fire an
// update back on the promise
var p = _this.getTableFields(url + '/' + link);
p.then(function(t) { t.description = tableInfo[t.tableName]; });
p.then(function(s) { d.notify(s.tableName); });
requests.push(p);
});
Q.spread(requests, function() {
d.resolve(_(arguments).toArray());
});
});
return d.promise;
} | [
"function",
"(",
")",
"{",
"var",
"url",
"=",
"this",
".",
"tableUrl",
";",
"var",
"_this",
"=",
"this",
";",
"var",
"d",
"=",
"new",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"tableInfo",
";",
"this",
".",
"getTableInfo",
"(",
")",
".",
"then",
"(",
"function",
"(",
"info",
")",
"{",
"tableInfo",
"=",
"info",
";",
"return",
"Q",
".",
"nfcall",
"(",
"request",
",",
"url",
"+",
"'/index.html'",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"data",
")",
";",
"var",
"list",
"=",
"$",
"(",
"'#tables li'",
")",
";",
"var",
"requests",
"=",
"[",
"]",
";",
"list",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"this",
";",
"var",
"title",
"=",
"$this",
".",
"find",
"(",
"'a'",
")",
".",
"text",
"(",
")",
";",
"var",
"link",
"=",
"$this",
".",
"find",
"(",
"'a'",
")",
".",
"attr",
"(",
"'href'",
")",
";",
"// Once we've got the table, add the description and fire an",
"// update back on the promise",
"var",
"p",
"=",
"_this",
".",
"getTableFields",
"(",
"url",
"+",
"'/'",
"+",
"link",
")",
";",
"p",
".",
"then",
"(",
"function",
"(",
"t",
")",
"{",
"t",
".",
"description",
"=",
"tableInfo",
"[",
"t",
".",
"tableName",
"]",
";",
"}",
")",
";",
"p",
".",
"then",
"(",
"function",
"(",
"s",
")",
"{",
"d",
".",
"notify",
"(",
"s",
".",
"tableName",
")",
";",
"}",
")",
";",
"requests",
".",
"push",
"(",
"p",
")",
";",
"}",
")",
";",
"Q",
".",
"spread",
"(",
"requests",
",",
"function",
"(",
")",
"{",
"d",
".",
"resolve",
"(",
"_",
"(",
"arguments",
")",
".",
"toArray",
"(",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"d",
".",
"promise",
";",
"}"
] | Load all the tables up | [
"Load",
"all",
"the",
"tables",
"up"
] | 847dfde26021cb228ea4004c6a6d148d56e95703 | https://github.com/bvalosek/grunt-infusionsoft/blob/847dfde26021cb228ea4004c6a6d148d56e95703/tasks/generator/Scraper.js#L66-L103 |
|
53,559 | bvalosek/grunt-infusionsoft | tasks/generator/Scraper.js | function(tableUrl)
{
var _this = this;
return Q.nfcall(request, tableUrl).then(function(data) {
var $ = cheerio.load(data);
var title = $('h2').first().text();
var $rows = $('table tr');
_this.tables.push(title);
var ret = {
tableName: title,
description: '',
fields: []
};
$rows.each(function() {
var $row = $(this);
var name = $row.find('td').first().text();
var type = $row.find('td:nth-child(2)').text();
var access = $row.find('td:nth-child(3)')
.text().toLowerCase().trim().split(' ');
if (!name) return;
ret.fields.push({
name: name,
type: type,
access: access
});
});
return ret;
});
} | javascript | function(tableUrl)
{
var _this = this;
return Q.nfcall(request, tableUrl).then(function(data) {
var $ = cheerio.load(data);
var title = $('h2').first().text();
var $rows = $('table tr');
_this.tables.push(title);
var ret = {
tableName: title,
description: '',
fields: []
};
$rows.each(function() {
var $row = $(this);
var name = $row.find('td').first().text();
var type = $row.find('td:nth-child(2)').text();
var access = $row.find('td:nth-child(3)')
.text().toLowerCase().trim().split(' ');
if (!name) return;
ret.fields.push({
name: name,
type: type,
access: access
});
});
return ret;
});
} | [
"function",
"(",
"tableUrl",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"Q",
".",
"nfcall",
"(",
"request",
",",
"tableUrl",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"data",
")",
";",
"var",
"title",
"=",
"$",
"(",
"'h2'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
";",
"var",
"$rows",
"=",
"$",
"(",
"'table tr'",
")",
";",
"_this",
".",
"tables",
".",
"push",
"(",
"title",
")",
";",
"var",
"ret",
"=",
"{",
"tableName",
":",
"title",
",",
"description",
":",
"''",
",",
"fields",
":",
"[",
"]",
"}",
";",
"$rows",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"$row",
"=",
"$",
"(",
"this",
")",
";",
"var",
"name",
"=",
"$row",
".",
"find",
"(",
"'td'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
";",
"var",
"type",
"=",
"$row",
".",
"find",
"(",
"'td:nth-child(2)'",
")",
".",
"text",
"(",
")",
";",
"var",
"access",
"=",
"$row",
".",
"find",
"(",
"'td:nth-child(3)'",
")",
".",
"text",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"' '",
")",
";",
"if",
"(",
"!",
"name",
")",
"return",
";",
"ret",
".",
"fields",
".",
"push",
"(",
"{",
"name",
":",
"name",
",",
"type",
":",
"type",
",",
"access",
":",
"access",
"}",
")",
";",
"}",
")",
";",
"return",
"ret",
";",
"}",
")",
";",
"}"
] | Scrape the actual table page to get the individiual fields | [
"Scrape",
"the",
"actual",
"table",
"page",
"to",
"get",
"the",
"individiual",
"fields"
] | 847dfde26021cb228ea4004c6a6d148d56e95703 | https://github.com/bvalosek/grunt-infusionsoft/blob/847dfde26021cb228ea4004c6a6d148d56e95703/tasks/generator/Scraper.js#L127-L162 |
|
53,560 | bvalosek/grunt-infusionsoft | tasks/generator/Scraper.js | function(href)
{
var _this = this;
return Q.nfcall(request, href).then(function(data) {
var $ = cheerio.load(data);
var serviceName =
$('.collection')
.first()
.text()
.trim()
.replace(/\./g, '');
var serviceDescription =
$('h1').nextAll('p').first().text();
_this.services.push(serviceName);
var ret = {
serviceName: serviceName,
description: serviceDescription,
methods: []
};
// Extract method information
$('.full_method').each(function() {
var $el = $(this);
var collection = $el.find('.collection')
.text().replace('.','').trim();
var method = $el.find('.method').text().trim();
var description = $el.nextAll('p').first().text();
var $table = $el.nextAll('table.table-striped').first();
var methodInfo = {
name: method,
description: description,
params: []
};
// Fix for documentation not having api keys
if (serviceName == 'DiscountService')
methodInfo.params.push('apiKey');
// iterate over all the paramters
$table.find('tbody tr').each(function() {
var td = $(this).find('td').first().text().trim();
if (td != 'Key' && td != 'privateKey' && td != 'key')
methodInfo.params.push(td);
else
methodInfo.params.push('apiKey');
});
ret.methods.push(methodInfo);
});
return ret;
});
} | javascript | function(href)
{
var _this = this;
return Q.nfcall(request, href).then(function(data) {
var $ = cheerio.load(data);
var serviceName =
$('.collection')
.first()
.text()
.trim()
.replace(/\./g, '');
var serviceDescription =
$('h1').nextAll('p').first().text();
_this.services.push(serviceName);
var ret = {
serviceName: serviceName,
description: serviceDescription,
methods: []
};
// Extract method information
$('.full_method').each(function() {
var $el = $(this);
var collection = $el.find('.collection')
.text().replace('.','').trim();
var method = $el.find('.method').text().trim();
var description = $el.nextAll('p').first().text();
var $table = $el.nextAll('table.table-striped').first();
var methodInfo = {
name: method,
description: description,
params: []
};
// Fix for documentation not having api keys
if (serviceName == 'DiscountService')
methodInfo.params.push('apiKey');
// iterate over all the paramters
$table.find('tbody tr').each(function() {
var td = $(this).find('td').first().text().trim();
if (td != 'Key' && td != 'privateKey' && td != 'key')
methodInfo.params.push(td);
else
methodInfo.params.push('apiKey');
});
ret.methods.push(methodInfo);
});
return ret;
});
} | [
"function",
"(",
"href",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"Q",
".",
"nfcall",
"(",
"request",
",",
"href",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"data",
")",
";",
"var",
"serviceName",
"=",
"$",
"(",
"'.collection'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"''",
")",
";",
"var",
"serviceDescription",
"=",
"$",
"(",
"'h1'",
")",
".",
"nextAll",
"(",
"'p'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
";",
"_this",
".",
"services",
".",
"push",
"(",
"serviceName",
")",
";",
"var",
"ret",
"=",
"{",
"serviceName",
":",
"serviceName",
",",
"description",
":",
"serviceDescription",
",",
"methods",
":",
"[",
"]",
"}",
";",
"// Extract method information",
"$",
"(",
"'.full_method'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"$el",
"=",
"$",
"(",
"this",
")",
";",
"var",
"collection",
"=",
"$el",
".",
"find",
"(",
"'.collection'",
")",
".",
"text",
"(",
")",
".",
"replace",
"(",
"'.'",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"var",
"method",
"=",
"$el",
".",
"find",
"(",
"'.method'",
")",
".",
"text",
"(",
")",
".",
"trim",
"(",
")",
";",
"var",
"description",
"=",
"$el",
".",
"nextAll",
"(",
"'p'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
";",
"var",
"$table",
"=",
"$el",
".",
"nextAll",
"(",
"'table.table-striped'",
")",
".",
"first",
"(",
")",
";",
"var",
"methodInfo",
"=",
"{",
"name",
":",
"method",
",",
"description",
":",
"description",
",",
"params",
":",
"[",
"]",
"}",
";",
"// Fix for documentation not having api keys",
"if",
"(",
"serviceName",
"==",
"'DiscountService'",
")",
"methodInfo",
".",
"params",
".",
"push",
"(",
"'apiKey'",
")",
";",
"// iterate over all the paramters",
"$table",
".",
"find",
"(",
"'tbody tr'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"td",
"=",
"$",
"(",
"this",
")",
".",
"find",
"(",
"'td'",
")",
".",
"first",
"(",
")",
".",
"text",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"td",
"!=",
"'Key'",
"&&",
"td",
"!=",
"'privateKey'",
"&&",
"td",
"!=",
"'key'",
")",
"methodInfo",
".",
"params",
".",
"push",
"(",
"td",
")",
";",
"else",
"methodInfo",
".",
"params",
".",
"push",
"(",
"'apiKey'",
")",
";",
"}",
")",
";",
"ret",
".",
"methods",
".",
"push",
"(",
"methodInfo",
")",
";",
"}",
")",
";",
"return",
"ret",
";",
"}",
")",
";",
"}"
] | Given a URL, parse all of the methods and corresponding parameter names for a Service API endpoint, return promise for node of information | [
"Given",
"a",
"URL",
"parse",
"all",
"of",
"the",
"methods",
"and",
"corresponding",
"parameter",
"names",
"for",
"a",
"Service",
"API",
"endpoint",
"return",
"promise",
"for",
"node",
"of",
"information"
] | 847dfde26021cb228ea4004c6a6d148d56e95703 | https://github.com/bvalosek/grunt-infusionsoft/blob/847dfde26021cb228ea4004c6a6d148d56e95703/tasks/generator/Scraper.js#L166-L224 |
|
53,561 | jurca/js-lock | Lock.js | generateLockName | function generateLockName() {
let subMark = Math.floor(Math.random() * 1000).toString(36)
return `Lock:${Date.now().toString(36)}:${subMark}`
} | javascript | function generateLockName() {
let subMark = Math.floor(Math.random() * 1000).toString(36)
return `Lock:${Date.now().toString(36)}:${subMark}`
} | [
"function",
"generateLockName",
"(",
")",
"{",
"let",
"subMark",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"1000",
")",
".",
"toString",
"(",
"36",
")",
"return",
"`",
"${",
"Date",
".",
"now",
"(",
")",
".",
"toString",
"(",
"36",
")",
"}",
"${",
"subMark",
"}",
"`",
"}"
] | Generates a new, most likely unique, name for a freshly created lock that
was not provided with a custom name.
@return {string} The generated name for the lock. | [
"Generates",
"a",
"new",
"most",
"likely",
"unique",
"name",
"for",
"a",
"freshly",
"created",
"lock",
"that",
"was",
"not",
"provided",
"with",
"a",
"custom",
"name",
"."
] | 096511400e91799529f1225550efec9ae2af84c8 | https://github.com/jurca/js-lock/blob/096511400e91799529f1225550efec9ae2af84c8/Lock.js#L239-L242 |
53,562 | vslinko/mystem-stream | lib/parseResponse.js | parseResponse | function parseResponse(mystemResponse) {
var mystemResponseFacts = mystemResponse.slice(mystemResponse.indexOf("{") + 1, -1),
factRegexp = /([^,]+\([^)]+\)|[^,]+)/g,
facts = [],
fact;
while (fact = factRegexp.exec(mystemResponseFacts)) {
facts.push(fact[0]);
}
var result = {
mystemResponse: mystemResponse,
facts: facts.concat()
};
var firstFact = facts.shift().split('=');
result.stem = firstFact[0].replace(/\?*$/, "");
return result;
} | javascript | function parseResponse(mystemResponse) {
var mystemResponseFacts = mystemResponse.slice(mystemResponse.indexOf("{") + 1, -1),
factRegexp = /([^,]+\([^)]+\)|[^,]+)/g,
facts = [],
fact;
while (fact = factRegexp.exec(mystemResponseFacts)) {
facts.push(fact[0]);
}
var result = {
mystemResponse: mystemResponse,
facts: facts.concat()
};
var firstFact = facts.shift().split('=');
result.stem = firstFact[0].replace(/\?*$/, "");
return result;
} | [
"function",
"parseResponse",
"(",
"mystemResponse",
")",
"{",
"var",
"mystemResponseFacts",
"=",
"mystemResponse",
".",
"slice",
"(",
"mystemResponse",
".",
"indexOf",
"(",
"\"{\"",
")",
"+",
"1",
",",
"-",
"1",
")",
",",
"factRegexp",
"=",
"/",
"([^,]+\\([^)]+\\)|[^,]+)",
"/",
"g",
",",
"facts",
"=",
"[",
"]",
",",
"fact",
";",
"while",
"(",
"fact",
"=",
"factRegexp",
".",
"exec",
"(",
"mystemResponseFacts",
")",
")",
"{",
"facts",
".",
"push",
"(",
"fact",
"[",
"0",
"]",
")",
";",
"}",
"var",
"result",
"=",
"{",
"mystemResponse",
":",
"mystemResponse",
",",
"facts",
":",
"facts",
".",
"concat",
"(",
")",
"}",
";",
"var",
"firstFact",
"=",
"facts",
".",
"shift",
"(",
")",
".",
"split",
"(",
"'='",
")",
";",
"result",
".",
"stem",
"=",
"firstFact",
"[",
"0",
"]",
".",
"replace",
"(",
"/",
"\\?*$",
"/",
",",
"\"\"",
")",
";",
"return",
"result",
";",
"}"
] | Node.js wrapper for `MyStem` morphology text analyzer.
Copyright Vyacheslav Slinko <[email protected]> | [
"Node",
".",
"js",
"wrapper",
"for",
"MyStem",
"morphology",
"text",
"analyzer",
".",
"Copyright",
"Vyacheslav",
"Slinko",
"<vyacheslav",
".",
"slinko"
] | 7f98fac4dfdee2d031eba40f682907cb1f2fdce2 | https://github.com/vslinko/mystem-stream/blob/7f98fac4dfdee2d031eba40f682907cb1f2fdce2/lib/parseResponse.js#L6-L25 |
53,563 | gunins/stonewall | dist/es6/dev/widget/Constructor.js | applyEvents | function applyEvents(context, child, data) {
var events = context.events[child.name];
if (events !== undefined && child.el !== undefined && child.data.type !== 'cp') {
events.forEach((event)=> {
context._events.push(child.on(event.name, event.action, context, data));
});
}
} | javascript | function applyEvents(context, child, data) {
var events = context.events[child.name];
if (events !== undefined && child.el !== undefined && child.data.type !== 'cp') {
events.forEach((event)=> {
context._events.push(child.on(event.name, event.action, context, data));
});
}
} | [
"function",
"applyEvents",
"(",
"context",
",",
"child",
",",
"data",
")",
"{",
"var",
"events",
"=",
"context",
".",
"events",
"[",
"child",
".",
"name",
"]",
";",
"if",
"(",
"events",
"!==",
"undefined",
"&&",
"child",
".",
"el",
"!==",
"undefined",
"&&",
"child",
".",
"data",
".",
"type",
"!==",
"'cp'",
")",
"{",
"events",
".",
"forEach",
"(",
"(",
"event",
")",
"=>",
"{",
"context",
".",
"_events",
".",
"push",
"(",
"child",
".",
"on",
"(",
"event",
".",
"name",
",",
"event",
".",
"action",
",",
"context",
",",
"data",
")",
")",
";",
"}",
")",
";",
"}",
"}"
] | Aplying Events to elements @private applyEvents @param {dom.Element} element @param {Array} events @param {Object} data | [
"Aplying",
"Events",
"to",
"elements"
] | eebc6376f83115b6e29d4539582830e917f0e80e | https://github.com/gunins/stonewall/blob/eebc6376f83115b6e29d4539582830e917f0e80e/dist/es6/dev/widget/Constructor.js#L504-L511 |
53,564 | aigarsdz/metalsmith-mallet | lib/index.js | function (file) {
var match = pattern.exec(basename(file));
return { date: match[1], url: match[2] };
} | javascript | function (file) {
var match = pattern.exec(basename(file));
return { date: match[1], url: match[2] };
} | [
"function",
"(",
"file",
")",
"{",
"var",
"match",
"=",
"pattern",
".",
"exec",
"(",
"basename",
"(",
"file",
")",
")",
";",
"return",
"{",
"date",
":",
"match",
"[",
"1",
"]",
",",
"url",
":",
"match",
"[",
"2",
"]",
"}",
";",
"}"
] | Extracts date and permalink parts from a Jekyll style post.
@example
parseJekyllStylePost("2014-04-05-hello-world.md");
//=> { date: "2014-04-05", url: "hello-world" }
@param {String} file
@return {Object.<string, string>} | [
"Extracts",
"date",
"and",
"permalink",
"parts",
"from",
"a",
"Jekyll",
"style",
"post",
"."
] | 6b2b7398d74aab3c07a80cee52b7b980381fe29a | https://github.com/aigarsdz/metalsmith-mallet/blob/6b2b7398d74aab3c07a80cee52b7b980381fe29a/lib/index.js#L39-L43 |
|
53,565 | aigarsdz/metalsmith-mallet | lib/index.js | function (userOptions) {
var defaultOptions = { ignore: [], collection: null, jekyllStyleLayout: true };
for (var opt in userOptions) defaultOptions[opt] = userOptions[opt];
return defaultOptions;
} | javascript | function (userOptions) {
var defaultOptions = { ignore: [], collection: null, jekyllStyleLayout: true };
for (var opt in userOptions) defaultOptions[opt] = userOptions[opt];
return defaultOptions;
} | [
"function",
"(",
"userOptions",
")",
"{",
"var",
"defaultOptions",
"=",
"{",
"ignore",
":",
"[",
"]",
",",
"collection",
":",
"null",
",",
"jekyllStyleLayout",
":",
"true",
"}",
";",
"for",
"(",
"var",
"opt",
"in",
"userOptions",
")",
"defaultOptions",
"[",
"opt",
"]",
"=",
"userOptions",
"[",
"opt",
"]",
";",
"return",
"defaultOptions",
";",
"}"
] | Merges user provided options with the defaults.
@param {Object} userOptions
@return {Object} Default: { ignore: [] } | [
"Merges",
"user",
"provided",
"options",
"with",
"the",
"defaults",
"."
] | 6b2b7398d74aab3c07a80cee52b7b980381fe29a | https://github.com/aigarsdz/metalsmith-mallet/blob/6b2b7398d74aab3c07a80cee52b7b980381fe29a/lib/index.js#L62-L68 |
|
53,566 | pagespace/pagespace | static/dashboard/app/forms/bs-has-error.js | getClosestFormName | function getClosestFormName(element) {
var parent = element.parent();
if(parent[0].tagName.toLowerCase() === 'form') {
return parent.attr('name') || null;
} else {
return getClosestFormName(parent);
}
} | javascript | function getClosestFormName(element) {
var parent = element.parent();
if(parent[0].tagName.toLowerCase() === 'form') {
return parent.attr('name') || null;
} else {
return getClosestFormName(parent);
}
} | [
"function",
"getClosestFormName",
"(",
"element",
")",
"{",
"var",
"parent",
"=",
"element",
".",
"parent",
"(",
")",
";",
"if",
"(",
"parent",
"[",
"0",
"]",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
"===",
"'form'",
")",
"{",
"return",
"parent",
".",
"attr",
"(",
"'name'",
")",
"||",
"null",
";",
"}",
"else",
"{",
"return",
"getClosestFormName",
"(",
"parent",
")",
";",
"}",
"}"
] | find parent form | [
"find",
"parent",
"form"
] | 943c45ddd9aaa4f3136e1ba4c2593aa0289daf43 | https://github.com/pagespace/pagespace/blob/943c45ddd9aaa4f3136e1ba4c2593aa0289daf43/static/dashboard/app/forms/bs-has-error.js#L8-L15 |
53,567 | zkochan/frame-message | lib/subscriber.js | Subscriber | function Subscriber(opts) {
opts = opts || {};
this._channel = opts.channel || 'default';
this._subscribers = [];
/* for mocking */
var addEventListener = opts.addEventListener || window.addEventListener;
var attachEvent = opts.attachEvent || window.attachEvent;
var _this = this;
function onMessage(e) {
var event = parse(e.data);
if (event.channel === _this._channel) {
for (var i = 0, len = _this._subscribers.length; i < len; i++) {
_this._subscribers[i].apply({}, event.args);
}
}
}
if (addEventListener) {
addEventListener('message', onMessage, false);
} else {
attachEvent('onmessage', onMessage, false);
}
} | javascript | function Subscriber(opts) {
opts = opts || {};
this._channel = opts.channel || 'default';
this._subscribers = [];
/* for mocking */
var addEventListener = opts.addEventListener || window.addEventListener;
var attachEvent = opts.attachEvent || window.attachEvent;
var _this = this;
function onMessage(e) {
var event = parse(e.data);
if (event.channel === _this._channel) {
for (var i = 0, len = _this._subscribers.length; i < len; i++) {
_this._subscribers[i].apply({}, event.args);
}
}
}
if (addEventListener) {
addEventListener('message', onMessage, false);
} else {
attachEvent('onmessage', onMessage, false);
}
} | [
"function",
"Subscriber",
"(",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"_channel",
"=",
"opts",
".",
"channel",
"||",
"'default'",
";",
"this",
".",
"_subscribers",
"=",
"[",
"]",
";",
"/* for mocking */",
"var",
"addEventListener",
"=",
"opts",
".",
"addEventListener",
"||",
"window",
".",
"addEventListener",
";",
"var",
"attachEvent",
"=",
"opts",
".",
"attachEvent",
"||",
"window",
".",
"attachEvent",
";",
"var",
"_this",
"=",
"this",
";",
"function",
"onMessage",
"(",
"e",
")",
"{",
"var",
"event",
"=",
"parse",
"(",
"e",
".",
"data",
")",
";",
"if",
"(",
"event",
".",
"channel",
"===",
"_this",
".",
"_channel",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"_this",
".",
"_subscribers",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"_this",
".",
"_subscribers",
"[",
"i",
"]",
".",
"apply",
"(",
"{",
"}",
",",
"event",
".",
"args",
")",
";",
"}",
"}",
"}",
"if",
"(",
"addEventListener",
")",
"{",
"addEventListener",
"(",
"'message'",
",",
"onMessage",
",",
"false",
")",
";",
"}",
"else",
"{",
"attachEvent",
"(",
"'onmessage'",
",",
"onMessage",
",",
"false",
")",
";",
"}",
"}"
] | An object for subscribing to frame messages.
@param {String} [opts.channel=default] - The name of the messaging channel to
subscribe to. | [
"An",
"object",
"for",
"subscribing",
"to",
"frame",
"messages",
"."
] | 550c49694019f0c8f60fe31140eb93947b52c22a | https://github.com/zkochan/frame-message/blob/550c49694019f0c8f60fe31140eb93947b52c22a/lib/subscriber.js#L19-L44 |
53,568 | joemccann/photopipe | database/redis-client.js | function(keys){
console.log('\nInitializing keys in Redis...\n')
keys.forEach(function(el,i){
client.get(el.key, function(e,d){
if(e) {
console.log("Error trying to get %s ", el.key)
return console.error(e)
}
// checking for falsey values only is a bad idea
if(typeof d === 'undefined'){
console.log("Not OK trying to get %s ", el.key)
client.set(el.key, el.initialValue, function(e,d){
if(e) {
console.log("Error trying to set %s ", el.key)
return console.error(e)
}
if(d !== 'OK') {
console.log("Not OK trying to set %s ", el.key)
return console.warn(el.key + " was not set.")
}
if(d === 'OK') {
console.log("OK setting %s ", el.key)
client.get(el.key, function(e,d){
console.log(d)
})
}
}) // end set.
}
console.log("The value for key %s is %s", el.key.yellow, d.green)
}) // end get
})
} | javascript | function(keys){
console.log('\nInitializing keys in Redis...\n')
keys.forEach(function(el,i){
client.get(el.key, function(e,d){
if(e) {
console.log("Error trying to get %s ", el.key)
return console.error(e)
}
// checking for falsey values only is a bad idea
if(typeof d === 'undefined'){
console.log("Not OK trying to get %s ", el.key)
client.set(el.key, el.initialValue, function(e,d){
if(e) {
console.log("Error trying to set %s ", el.key)
return console.error(e)
}
if(d !== 'OK') {
console.log("Not OK trying to set %s ", el.key)
return console.warn(el.key + " was not set.")
}
if(d === 'OK') {
console.log("OK setting %s ", el.key)
client.get(el.key, function(e,d){
console.log(d)
})
}
}) // end set.
}
console.log("The value for key %s is %s", el.key.yellow, d.green)
}) // end get
})
} | [
"function",
"(",
"keys",
")",
"{",
"console",
".",
"log",
"(",
"'\\nInitializing keys in Redis...\\n'",
")",
"keys",
".",
"forEach",
"(",
"function",
"(",
"el",
",",
"i",
")",
"{",
"client",
".",
"get",
"(",
"el",
".",
"key",
",",
"function",
"(",
"e",
",",
"d",
")",
"{",
"if",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"Error trying to get %s \"",
",",
"el",
".",
"key",
")",
"return",
"console",
".",
"error",
"(",
"e",
")",
"}",
"// checking for falsey values only is a bad idea",
"if",
"(",
"typeof",
"d",
"===",
"'undefined'",
")",
"{",
"console",
".",
"log",
"(",
"\"Not OK trying to get %s \"",
",",
"el",
".",
"key",
")",
"client",
".",
"set",
"(",
"el",
".",
"key",
",",
"el",
".",
"initialValue",
",",
"function",
"(",
"e",
",",
"d",
")",
"{",
"if",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"Error trying to set %s \"",
",",
"el",
".",
"key",
")",
"return",
"console",
".",
"error",
"(",
"e",
")",
"}",
"if",
"(",
"d",
"!==",
"'OK'",
")",
"{",
"console",
".",
"log",
"(",
"\"Not OK trying to set %s \"",
",",
"el",
".",
"key",
")",
"return",
"console",
".",
"warn",
"(",
"el",
".",
"key",
"+",
"\" was not set.\"",
")",
"}",
"if",
"(",
"d",
"===",
"'OK'",
")",
"{",
"console",
".",
"log",
"(",
"\"OK setting %s \"",
",",
"el",
".",
"key",
")",
"client",
".",
"get",
"(",
"el",
".",
"key",
",",
"function",
"(",
"e",
",",
"d",
")",
"{",
"console",
".",
"log",
"(",
"d",
")",
"}",
")",
"}",
"}",
")",
"// end set.",
"}",
"console",
".",
"log",
"(",
"\"The value for key %s is %s\"",
",",
"el",
".",
"key",
".",
"yellow",
",",
"d",
".",
"green",
")",
"}",
")",
"// end get",
"}",
")",
"}"
] | Upon firing up, make sure these baseline keys are set | [
"Upon",
"firing",
"up",
"make",
"sure",
"these",
"baseline",
"keys",
"are",
"set"
] | 20318fde11163a8b732b077a141a8d8530372333 | https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/database/redis-client.js#L15-L57 |
|
53,569 | joemccann/photopipe | database/redis-client.js | function(userObj, setname, hashPrefix, cb){
console.log("\nCreating new user account %s", userObj.network.username)
/*
userObj = {
network: {
type : 'facebook',
first_name: 'Joe',
last_name: 'McCann',
username: 'joemccann',
full_name: 'Joe McCann'
},
email_address: '[email protected]',
oauth: {}
}
*/
// TODO: CHECK IF HASH EXISTS
// Schema should be:
var schema =
{
uuid: null,
networks: {
twitter: {},
facebook: {},
instagram: {},
flickr: {},
dropbox: {},
google_drive: {}
},
email_addresses: [],
cache: {
twitter: null,
facebook: null,
instagram: null,
flickr: null,
dropbox: null,
google_drive: null
}
}
// Generate unique user id
schema.uuid = sha1(redisConfig.salt, userObj.email_address)
// "Official" email address is schema.email_addresses[0]
// Add it to the email addresses for the user
schema.email_addresses.push(userObj.email_address)
// Let's
client.sadd(setname, schema.uuid, function(e,d){
if(cb){
return cb(e,d)
}
userSetAddHandler(e,d)
client.hmset(hashPrefix +":"+schema.uuid, userObj, hmsetCb || userSetHashHandler)
})
} | javascript | function(userObj, setname, hashPrefix, cb){
console.log("\nCreating new user account %s", userObj.network.username)
/*
userObj = {
network: {
type : 'facebook',
first_name: 'Joe',
last_name: 'McCann',
username: 'joemccann',
full_name: 'Joe McCann'
},
email_address: '[email protected]',
oauth: {}
}
*/
// TODO: CHECK IF HASH EXISTS
// Schema should be:
var schema =
{
uuid: null,
networks: {
twitter: {},
facebook: {},
instagram: {},
flickr: {},
dropbox: {},
google_drive: {}
},
email_addresses: [],
cache: {
twitter: null,
facebook: null,
instagram: null,
flickr: null,
dropbox: null,
google_drive: null
}
}
// Generate unique user id
schema.uuid = sha1(redisConfig.salt, userObj.email_address)
// "Official" email address is schema.email_addresses[0]
// Add it to the email addresses for the user
schema.email_addresses.push(userObj.email_address)
// Let's
client.sadd(setname, schema.uuid, function(e,d){
if(cb){
return cb(e,d)
}
userSetAddHandler(e,d)
client.hmset(hashPrefix +":"+schema.uuid, userObj, hmsetCb || userSetHashHandler)
})
} | [
"function",
"(",
"userObj",
",",
"setname",
",",
"hashPrefix",
",",
"cb",
")",
"{",
"console",
".",
"log",
"(",
"\"\\nCreating new user account %s\"",
",",
"userObj",
".",
"network",
".",
"username",
")",
"/*\n userObj = {\n network: {\n type : 'facebook',\n first_name: 'Joe',\n last_name: 'McCann',\n username: 'joemccann',\n full_name: 'Joe McCann'\n },\n email_address: '[email protected]',\n oauth: {}\n }\n */",
"// TODO: CHECK IF HASH EXISTS",
"// Schema should be:",
"var",
"schema",
"=",
"{",
"uuid",
":",
"null",
",",
"networks",
":",
"{",
"twitter",
":",
"{",
"}",
",",
"facebook",
":",
"{",
"}",
",",
"instagram",
":",
"{",
"}",
",",
"flickr",
":",
"{",
"}",
",",
"dropbox",
":",
"{",
"}",
",",
"google_drive",
":",
"{",
"}",
"}",
",",
"email_addresses",
":",
"[",
"]",
",",
"cache",
":",
"{",
"twitter",
":",
"null",
",",
"facebook",
":",
"null",
",",
"instagram",
":",
"null",
",",
"flickr",
":",
"null",
",",
"dropbox",
":",
"null",
",",
"google_drive",
":",
"null",
"}",
"}",
"// Generate unique user id",
"schema",
".",
"uuid",
"=",
"sha1",
"(",
"redisConfig",
".",
"salt",
",",
"userObj",
".",
"email_address",
")",
"// \"Official\" email address is schema.email_addresses[0]",
"// Add it to the email addresses for the user",
"schema",
".",
"email_addresses",
".",
"push",
"(",
"userObj",
".",
"email_address",
")",
"// Let's ",
"client",
".",
"sadd",
"(",
"setname",
",",
"schema",
".",
"uuid",
",",
"function",
"(",
"e",
",",
"d",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"return",
"cb",
"(",
"e",
",",
"d",
")",
"}",
"userSetAddHandler",
"(",
"e",
",",
"d",
")",
"client",
".",
"hmset",
"(",
"hashPrefix",
"+",
"\":\"",
"+",
"schema",
".",
"uuid",
",",
"userObj",
",",
"hmsetCb",
"||",
"userSetHashHandler",
")",
"}",
")",
"}"
] | Create a new user account in Redis setname is the name of the set to add to hashPrefix is the prefix to identify the hash | [
"Create",
"a",
"new",
"user",
"account",
"in",
"Redis",
"setname",
"is",
"the",
"name",
"of",
"the",
"set",
"to",
"add",
"to",
"hashPrefix",
"is",
"the",
"prefix",
"to",
"identify",
"the",
"hash"
] | 20318fde11163a8b732b077a141a8d8530372333 | https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/database/redis-client.js#L138-L201 |
|
53,570 | joemccann/photopipe | database/redis-client.js | function(userObj, setname, hashPrefix, cb){
// client.srem('users',userObj.uuid, redis.print)
var _uuid = sha1('photopipe', userObj.email_address)
client.srem(setname, _uuid, function(e,d){
if(cb){
return cb(e,d)
}
userSetRemoveHandler(e,d)
client.hdel(hashPrefix+':'+_uuid, userObj, userDeleteHashHandler)
})
} | javascript | function(userObj, setname, hashPrefix, cb){
// client.srem('users',userObj.uuid, redis.print)
var _uuid = sha1('photopipe', userObj.email_address)
client.srem(setname, _uuid, function(e,d){
if(cb){
return cb(e,d)
}
userSetRemoveHandler(e,d)
client.hdel(hashPrefix+':'+_uuid, userObj, userDeleteHashHandler)
})
} | [
"function",
"(",
"userObj",
",",
"setname",
",",
"hashPrefix",
",",
"cb",
")",
"{",
"// client.srem('users',userObj.uuid, redis.print)",
"var",
"_uuid",
"=",
"sha1",
"(",
"'photopipe'",
",",
"userObj",
".",
"email_address",
")",
"client",
".",
"srem",
"(",
"setname",
",",
"_uuid",
",",
"function",
"(",
"e",
",",
"d",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"return",
"cb",
"(",
"e",
",",
"d",
")",
"}",
"userSetRemoveHandler",
"(",
"e",
",",
"d",
")",
"client",
".",
"hdel",
"(",
"hashPrefix",
"+",
"':'",
"+",
"_uuid",
",",
"userObj",
",",
"userDeleteHashHandler",
")",
"}",
")",
"}"
] | Delete user's account from Redis. | [
"Delete",
"user",
"s",
"account",
"from",
"Redis",
"."
] | 20318fde11163a8b732b077a141a8d8530372333 | https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/database/redis-client.js#L203-L222 |
|
53,571 | joemccann/photopipe | database/redis-client.js | function(e,d){
if(e){
console.log("User set add data response: %s", d)
e && console.error(e)
return
}
console.log("User set add data response with no error: %s", d)
} | javascript | function(e,d){
if(e){
console.log("User set add data response: %s", d)
e && console.error(e)
return
}
console.log("User set add data response with no error: %s", d)
} | [
"function",
"(",
"e",
",",
"d",
")",
"{",
"if",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"User set add data response: %s\"",
",",
"d",
")",
"e",
"&&",
"console",
".",
"error",
"(",
"e",
")",
"return",
"}",
"console",
".",
"log",
"(",
"\"User set add data response with no error: %s\"",
",",
"d",
")",
"}"
] | Callback after setting user to the set of users | [
"Callback",
"after",
"setting",
"user",
"to",
"the",
"set",
"of",
"users"
] | 20318fde11163a8b732b077a141a8d8530372333 | https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/database/redis-client.js#L224-L231 |
|
53,572 | MegrezZhu/SYSU-JWXT | index.js | decorate | function decorate (fn) {
return async function (...args) {
try {
return fn.call(this, ...args);
} catch (err) {
this.logger && this.logger.error(err.message);
throw err;
}
};
} | javascript | function decorate (fn) {
return async function (...args) {
try {
return fn.call(this, ...args);
} catch (err) {
this.logger && this.logger.error(err.message);
throw err;
}
};
} | [
"function",
"decorate",
"(",
"fn",
")",
"{",
"return",
"async",
"function",
"(",
"...",
"args",
")",
"{",
"try",
"{",
"return",
"fn",
".",
"call",
"(",
"this",
",",
"...",
"args",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"this",
".",
"logger",
"&&",
"this",
".",
"logger",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"throw",
"err",
";",
"}",
"}",
";",
"}"
] | decorator-like function that wraps the methods | [
"decorator",
"-",
"like",
"function",
"that",
"wraps",
"the",
"methods"
] | 125c51328994d8c538463116758a5a710a185646 | https://github.com/MegrezZhu/SYSU-JWXT/blob/125c51328994d8c538463116758a5a710a185646/index.js#L35-L44 |
53,573 | maxcnunes/spawn-auto-restart | src/index.js | start | function start() {
proc = spawn(procCommand, procArgs, procOptions);
var onClose = function (code) {
if (!restarting) {
process.exit(code);
}
start();
restarting = false;
};
proc.on('error', function () {
debug('restarting due error');
restarting = true;
proc.kill('SIGINT');
});
proc.on('close', onClose);
} | javascript | function start() {
proc = spawn(procCommand, procArgs, procOptions);
var onClose = function (code) {
if (!restarting) {
process.exit(code);
}
start();
restarting = false;
};
proc.on('error', function () {
debug('restarting due error');
restarting = true;
proc.kill('SIGINT');
});
proc.on('close', onClose);
} | [
"function",
"start",
"(",
")",
"{",
"proc",
"=",
"spawn",
"(",
"procCommand",
",",
"procArgs",
",",
"procOptions",
")",
";",
"var",
"onClose",
"=",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"!",
"restarting",
")",
"{",
"process",
".",
"exit",
"(",
"code",
")",
";",
"}",
"start",
"(",
")",
";",
"restarting",
"=",
"false",
";",
"}",
";",
"proc",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
")",
"{",
"debug",
"(",
"'restarting due error'",
")",
";",
"restarting",
"=",
"true",
";",
"proc",
".",
"kill",
"(",
"'SIGINT'",
")",
";",
"}",
")",
";",
"proc",
".",
"on",
"(",
"'close'",
",",
"onClose",
")",
";",
"}"
] | start the child process | [
"start",
"the",
"child",
"process"
] | ba0b9cfd4a4b55abe6b65f4c77fc4fa56bff589b | https://github.com/maxcnunes/spawn-auto-restart/blob/ba0b9cfd4a4b55abe6b65f4c77fc4fa56bff589b/src/index.js#L42-L60 |
53,574 | 75lb/common-sequence | lib/common-sequence.js | commonSequence | function commonSequence(a, b){
var result = [];
for (var i = 0; i < Math.min(a.length, b.length); i++){
if (a[i] === b[i]){
result.push(a[i]);
} else {
break;
}
}
return result;
} | javascript | function commonSequence(a, b){
var result = [];
for (var i = 0; i < Math.min(a.length, b.length); i++){
if (a[i] === b[i]){
result.push(a[i]);
} else {
break;
}
}
return result;
} | [
"function",
"commonSequence",
"(",
"a",
",",
"b",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"Math",
".",
"min",
"(",
"a",
".",
"length",
",",
"b",
".",
"length",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"a",
"[",
"i",
"]",
"===",
"b",
"[",
"i",
"]",
")",
"{",
"result",
".",
"push",
"(",
"a",
"[",
"i",
"]",
")",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Returns the initial elements which both input arrays have in common
@param {Array} - first array to compare
@param {Array} - second array to compare
@returns {Array}
@alias module:common-sequence | [
"Returns",
"the",
"initial",
"elements",
"which",
"both",
"input",
"arrays",
"have",
"in",
"common"
] | bdfd45b1358fd8fc8f90c90dde9960cc9555fb01 | https://github.com/75lb/common-sequence/blob/bdfd45b1358fd8fc8f90c90dde9960cc9555fb01/lib/common-sequence.js#L34-L44 |
53,575 | jmanero/simple-uid | index.js | generator | function generator(url) {
var randomnesss = Crypto.randomBytes(24);
randomnesss.writeDoubleBE(Date.now(), 0);
randomnesss.writeUInt32BE(process.pid, 8);
var output = randomnesss.toString('base64');
// URL safe
if (url) {
output = output.replace(/\//g, '_');
output = output.replace(/\+/g, '-');
}
return output;
} | javascript | function generator(url) {
var randomnesss = Crypto.randomBytes(24);
randomnesss.writeDoubleBE(Date.now(), 0);
randomnesss.writeUInt32BE(process.pid, 8);
var output = randomnesss.toString('base64');
// URL safe
if (url) {
output = output.replace(/\//g, '_');
output = output.replace(/\+/g, '-');
}
return output;
} | [
"function",
"generator",
"(",
"url",
")",
"{",
"var",
"randomnesss",
"=",
"Crypto",
".",
"randomBytes",
"(",
"24",
")",
";",
"randomnesss",
".",
"writeDoubleBE",
"(",
"Date",
".",
"now",
"(",
")",
",",
"0",
")",
";",
"randomnesss",
".",
"writeUInt32BE",
"(",
"process",
".",
"pid",
",",
"8",
")",
";",
"var",
"output",
"=",
"randomnesss",
".",
"toString",
"(",
"'base64'",
")",
";",
"// URL safe",
"if",
"(",
"url",
")",
"{",
"output",
"=",
"output",
".",
"replace",
"(",
"/",
"\\/",
"/",
"g",
",",
"'_'",
")",
";",
"output",
"=",
"output",
".",
"replace",
"(",
"/",
"\\+",
"/",
"g",
",",
"'-'",
")",
";",
"}",
"return",
"output",
";",
"}"
] | Generates a string composed of the millisecond date, the current PID, and
some random bytes
@returns String | [
"Generates",
"a",
"string",
"composed",
"of",
"the",
"millisecond",
"date",
"the",
"current",
"PID",
"and",
"some",
"random",
"bytes"
] | 19e8a40bd800b7e31a41b7ca5cfec56e6f8507dd | https://github.com/jmanero/simple-uid/blob/19e8a40bd800b7e31a41b7ca5cfec56e6f8507dd/index.js#L9-L23 |
53,576 | NumminorihSF/bramqp-wrapper | domain/confirm.js | Confirm | function Confirm(client, channel){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
return this;
} | javascript | function Confirm(client, channel){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
return this;
} | [
"function",
"Confirm",
"(",
"client",
",",
"channel",
")",
"{",
"EE",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"client",
"=",
"client",
";",
"this",
".",
"channel",
"=",
"channel",
";",
"this",
".",
"id",
"=",
"channel",
".",
"$getId",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Work with confirms.
The Confirm class allows publishers to put the channel in confirm mode and susequently
be notified when messages have been handled by the broker.
The intention is that all messages published on a channel in confirm mode will be
acknowledged at some point. By acknowledging a message the broker assumes responsibility
for it and indicates that it has done something it deems reasonable with it.
Unroutable mandatory or immediate messages are acknowledged right after the
Basic.Return method. Messages are acknowledged when all queues to which the message has
been routed have either delivered the message and received an acknowledgement (if required),
or enqueued the message (and persisted it if required).
Published messages are assigned ascending sequence numbers,
starting at 1 with the first Confirm.Select method.
The server confirms messages by sending Basic.Ack methods referring to these sequence numbers.
@param {BRAMQPClient} client Client object that returns from bramqp#openAMQPCommunication() method.
@param {Channel} channel Channel object (should be opened).
@return {Confirm}
@constructor | [
"Work",
"with",
"confirms",
"."
] | 3e2bd769a2828f7592eba79556c9ef1491177781 | https://github.com/NumminorihSF/bramqp-wrapper/blob/3e2bd769a2828f7592eba79556c9ef1491177781/domain/confirm.js#L27-L34 |
53,577 | reworkcss/rework-plugin-mixin | index.js | mixin | function mixin(rework, declarations, mixins) {
for (var i = 0; i < declarations.length; ++i) {
var decl = declarations[i];
if ('comment' == decl.type) continue;
var key = decl.property;
var val = decl.value;
var fn = mixins[key];
if (!fn) continue;
// invoke mixin
var ret = fn.call(rework, val);
// apply properties
for (var key in ret) {
var val = ret[key];
if (Array.isArray(val)) {
val.forEach(function(val){
declarations.splice(i++, 0, {
type: 'declaration',
property: key,
value: val
});
});
} else {
declarations.splice(i++, 0, {
type: 'declaration',
property: key,
value: val
});
}
}
// remove original
declarations.splice(i--, 1);
}
} | javascript | function mixin(rework, declarations, mixins) {
for (var i = 0; i < declarations.length; ++i) {
var decl = declarations[i];
if ('comment' == decl.type) continue;
var key = decl.property;
var val = decl.value;
var fn = mixins[key];
if (!fn) continue;
// invoke mixin
var ret = fn.call(rework, val);
// apply properties
for (var key in ret) {
var val = ret[key];
if (Array.isArray(val)) {
val.forEach(function(val){
declarations.splice(i++, 0, {
type: 'declaration',
property: key,
value: val
});
});
} else {
declarations.splice(i++, 0, {
type: 'declaration',
property: key,
value: val
});
}
}
// remove original
declarations.splice(i--, 1);
}
} | [
"function",
"mixin",
"(",
"rework",
",",
"declarations",
",",
"mixins",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"declarations",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"decl",
"=",
"declarations",
"[",
"i",
"]",
";",
"if",
"(",
"'comment'",
"==",
"decl",
".",
"type",
")",
"continue",
";",
"var",
"key",
"=",
"decl",
".",
"property",
";",
"var",
"val",
"=",
"decl",
".",
"value",
";",
"var",
"fn",
"=",
"mixins",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"fn",
")",
"continue",
";",
"// invoke mixin",
"var",
"ret",
"=",
"fn",
".",
"call",
"(",
"rework",
",",
"val",
")",
";",
"// apply properties",
"for",
"(",
"var",
"key",
"in",
"ret",
")",
"{",
"var",
"val",
"=",
"ret",
"[",
"key",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"val",
".",
"forEach",
"(",
"function",
"(",
"val",
")",
"{",
"declarations",
".",
"splice",
"(",
"i",
"++",
",",
"0",
",",
"{",
"type",
":",
"'declaration'",
",",
"property",
":",
"key",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"declarations",
".",
"splice",
"(",
"i",
"++",
",",
"0",
",",
"{",
"type",
":",
"'declaration'",
",",
"property",
":",
"key",
",",
"value",
":",
"val",
"}",
")",
";",
"}",
"}",
"// remove original",
"declarations",
".",
"splice",
"(",
"i",
"--",
",",
"1",
")",
";",
"}",
"}"
] | Visit declarations and apply mixins.
@param {Rework} rework
@param {Array} declarations
@param {Object} mixins
@api private | [
"Visit",
"declarations",
"and",
"apply",
"mixins",
"."
] | cd7c6edfad40cccff67cf764e90e9c4fd0c49f71 | https://github.com/reworkcss/rework-plugin-mixin/blob/cd7c6edfad40cccff67cf764e90e9c4fd0c49f71/index.js#L30-L66 |
53,578 | lamansky/cached-function | index.js | generateKey | function generateKey (args, strictArgMatch = true) {
args = Array.from(args)
if (strictArgMatch) return args
return args.map(arg => maybeStringify(arg))
} | javascript | function generateKey (args, strictArgMatch = true) {
args = Array.from(args)
if (strictArgMatch) return args
return args.map(arg => maybeStringify(arg))
} | [
"function",
"generateKey",
"(",
"args",
",",
"strictArgMatch",
"=",
"true",
")",
"{",
"args",
"=",
"Array",
".",
"from",
"(",
"args",
")",
"if",
"(",
"strictArgMatch",
")",
"return",
"args",
"return",
"args",
".",
"map",
"(",
"arg",
"=>",
"maybeStringify",
"(",
"arg",
")",
")",
"}"
] | Generates the representation of function arguments which will be used to store
and retrieve return values in the cache.
@param {array|object} args An array-like collection of the function's arguments.
@param {bool} [strictArgMatch=true] Whether or not to match function arguments
based on their serialized representation.
@return {array} An array of keys (either the arguments themselves or a
serialization thereof) to use for the cache. | [
"Generates",
"the",
"representation",
"of",
"function",
"arguments",
"which",
"will",
"be",
"used",
"to",
"store",
"and",
"retrieve",
"return",
"values",
"in",
"the",
"cache",
"."
] | 794ade3f2bd93160d110ad776648e75716ea2500 | https://github.com/lamansky/cached-function/blob/794ade3f2bd93160d110ad776648e75716ea2500/index.js#L29-L33 |
53,579 | windmaomao/ng-admin-restify | src/ng-admin.js | function(model) {
var fields = _.keys(model);
var updated = {};
_.each(fields, function(field) {
var updatedField = {};
var modelField = {};
if (!(field === Object(field))) {
updatedField.field = field;
if (!(model[field] === Object(model[field]))) {
modelField = { type: model[field] };
} else {
modelField = model[field];
}
updatedField = _.defaults(updatedField, modelField);
} else {
updatedField = field;
}
updated[updatedField.field] = updatedField;
});
return updated;
} | javascript | function(model) {
var fields = _.keys(model);
var updated = {};
_.each(fields, function(field) {
var updatedField = {};
var modelField = {};
if (!(field === Object(field))) {
updatedField.field = field;
if (!(model[field] === Object(model[field]))) {
modelField = { type: model[field] };
} else {
modelField = model[field];
}
updatedField = _.defaults(updatedField, modelField);
} else {
updatedField = field;
}
updated[updatedField.field] = updatedField;
});
return updated;
} | [
"function",
"(",
"model",
")",
"{",
"var",
"fields",
"=",
"_",
".",
"keys",
"(",
"model",
")",
";",
"var",
"updated",
"=",
"{",
"}",
";",
"_",
".",
"each",
"(",
"fields",
",",
"function",
"(",
"field",
")",
"{",
"var",
"updatedField",
"=",
"{",
"}",
";",
"var",
"modelField",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"(",
"field",
"===",
"Object",
"(",
"field",
")",
")",
")",
"{",
"updatedField",
".",
"field",
"=",
"field",
";",
"if",
"(",
"!",
"(",
"model",
"[",
"field",
"]",
"===",
"Object",
"(",
"model",
"[",
"field",
"]",
")",
")",
")",
"{",
"modelField",
"=",
"{",
"type",
":",
"model",
"[",
"field",
"]",
"}",
";",
"}",
"else",
"{",
"modelField",
"=",
"model",
"[",
"field",
"]",
";",
"}",
"updatedField",
"=",
"_",
".",
"defaults",
"(",
"updatedField",
",",
"modelField",
")",
";",
"}",
"else",
"{",
"updatedField",
"=",
"field",
";",
"}",
"updated",
"[",
"updatedField",
".",
"field",
"]",
"=",
"updatedField",
";",
"}",
")",
";",
"return",
"updated",
";",
"}"
] | convert model and merge with nga fields | [
"convert",
"model",
"and",
"merge",
"with",
"nga",
"fields"
] | d86d8c12eb07e1b23def2f5de0832aa357c2a731 | https://github.com/windmaomao/ng-admin-restify/blob/d86d8c12eb07e1b23def2f5de0832aa357c2a731/src/ng-admin.js#L227-L249 |
|
53,580 | supercrabtree/tie-dye | rgbToHex.js | rgbToHex | function rgbToHex(r, g, b) {
var integer = ((Math.round(r) & 0xFF) << 16)
+ ((Math.round(g) & 0xFF) << 8)
+ (Math.round(b) & 0xFF);
var string = integer.toString(16).toUpperCase();
return '#' + ('000000'.substring(string.length) + string);
} | javascript | function rgbToHex(r, g, b) {
var integer = ((Math.round(r) & 0xFF) << 16)
+ ((Math.round(g) & 0xFF) << 8)
+ (Math.round(b) & 0xFF);
var string = integer.toString(16).toUpperCase();
return '#' + ('000000'.substring(string.length) + string);
} | [
"function",
"rgbToHex",
"(",
"r",
",",
"g",
",",
"b",
")",
"{",
"var",
"integer",
"=",
"(",
"(",
"Math",
".",
"round",
"(",
"r",
")",
"&",
"0xFF",
")",
"<<",
"16",
")",
"+",
"(",
"(",
"Math",
".",
"round",
"(",
"g",
")",
"&",
"0xFF",
")",
"<<",
"8",
")",
"+",
"(",
"Math",
".",
"round",
"(",
"b",
")",
"&",
"0xFF",
")",
";",
"var",
"string",
"=",
"integer",
".",
"toString",
"(",
"16",
")",
".",
"toUpperCase",
"(",
")",
";",
"return",
"'#'",
"+",
"(",
"'000000'",
".",
"substring",
"(",
"string",
".",
"length",
")",
"+",
"string",
")",
";",
"}"
] | Convert a color from RGB to hexidecimal
@param {number} r - A value from 0 - 255
@param {number} g - A value from 0 - 255
@param {number} b - A value from 0 - 255
@returns {string} In the format #000000 | [
"Convert",
"a",
"color",
"from",
"RGB",
"to",
"hexidecimal"
] | 1bf045767ce1a3fcf88450fbf95f72b5646f63df | https://github.com/supercrabtree/tie-dye/blob/1bf045767ce1a3fcf88450fbf95f72b5646f63df/rgbToHex.js#L9-L16 |
53,581 | espadrine/queread | src/tokenizer/time.js | nthWeekDay | function nthWeekDay(countDays, weekDay, year, month, day) {
let countedDays = 0
if (countDays >= 0) {
month = month || 1
let monthStr = String(month)
if (monthStr.length === 1) { monthStr = "0" + monthStr }
day = day || 1
let dayStr = String(day)
if (dayStr.length === 1) { dayStr = "0" + dayStr }
// We stay a minute off midnight to avoid dealing with leap seconds.
let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
let time
for (let i = 0; i < 366; i++) {
time = new Date(timestamp)
if (time.getDay() === weekDay) {countedDays++}
if (countedDays === countDays) {break}
timestamp += 24 * 3600 * 1000
}
return time
} else if (countDays < 0) {
countDays = -countDays
month = month || 12
let monthStr = String(month)
if (monthStr.length === 1) { monthStr = "0" + monthStr }
day = day || 31
let dayStr = String(day)
if (dayStr.length === 1) { dayStr = "0" + dayStr }
// Starting moment, ms.
let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
let time
for (let i = 366; i >= 0; i--) {
time = new Date(timestamp)
if (time.getDay() === weekDay) {countedDays++}
if (countedDays === countDays) {break}
timestamp -= 24 * 3600 * 1000
}
return time
}
} | javascript | function nthWeekDay(countDays, weekDay, year, month, day) {
let countedDays = 0
if (countDays >= 0) {
month = month || 1
let monthStr = String(month)
if (monthStr.length === 1) { monthStr = "0" + monthStr }
day = day || 1
let dayStr = String(day)
if (dayStr.length === 1) { dayStr = "0" + dayStr }
// We stay a minute off midnight to avoid dealing with leap seconds.
let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
let time
for (let i = 0; i < 366; i++) {
time = new Date(timestamp)
if (time.getDay() === weekDay) {countedDays++}
if (countedDays === countDays) {break}
timestamp += 24 * 3600 * 1000
}
return time
} else if (countDays < 0) {
countDays = -countDays
month = month || 12
let monthStr = String(month)
if (monthStr.length === 1) { monthStr = "0" + monthStr }
day = day || 31
let dayStr = String(day)
if (dayStr.length === 1) { dayStr = "0" + dayStr }
// Starting moment, ms.
let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
let time
for (let i = 366; i >= 0; i--) {
time = new Date(timestamp)
if (time.getDay() === weekDay) {countedDays++}
if (countedDays === countDays) {break}
timestamp -= 24 * 3600 * 1000
}
return time
}
} | [
"function",
"nthWeekDay",
"(",
"countDays",
",",
"weekDay",
",",
"year",
",",
"month",
",",
"day",
")",
"{",
"let",
"countedDays",
"=",
"0",
"if",
"(",
"countDays",
">=",
"0",
")",
"{",
"month",
"=",
"month",
"||",
"1",
"let",
"monthStr",
"=",
"String",
"(",
"month",
")",
"if",
"(",
"monthStr",
".",
"length",
"===",
"1",
")",
"{",
"monthStr",
"=",
"\"0\"",
"+",
"monthStr",
"}",
"day",
"=",
"day",
"||",
"1",
"let",
"dayStr",
"=",
"String",
"(",
"day",
")",
"if",
"(",
"dayStr",
".",
"length",
"===",
"1",
")",
"{",
"dayStr",
"=",
"\"0\"",
"+",
"dayStr",
"}",
"// We stay a minute off midnight to avoid dealing with leap seconds.",
"let",
"timestamp",
"=",
"+",
"new",
"Date",
"(",
"`",
"${",
"year",
"}",
"${",
"monthStr",
"}",
"${",
"dayStr",
"}",
"`",
")",
"let",
"time",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"366",
";",
"i",
"++",
")",
"{",
"time",
"=",
"new",
"Date",
"(",
"timestamp",
")",
"if",
"(",
"time",
".",
"getDay",
"(",
")",
"===",
"weekDay",
")",
"{",
"countedDays",
"++",
"}",
"if",
"(",
"countedDays",
"===",
"countDays",
")",
"{",
"break",
"}",
"timestamp",
"+=",
"24",
"*",
"3600",
"*",
"1000",
"}",
"return",
"time",
"}",
"else",
"if",
"(",
"countDays",
"<",
"0",
")",
"{",
"countDays",
"=",
"-",
"countDays",
"month",
"=",
"month",
"||",
"12",
"let",
"monthStr",
"=",
"String",
"(",
"month",
")",
"if",
"(",
"monthStr",
".",
"length",
"===",
"1",
")",
"{",
"monthStr",
"=",
"\"0\"",
"+",
"monthStr",
"}",
"day",
"=",
"day",
"||",
"31",
"let",
"dayStr",
"=",
"String",
"(",
"day",
")",
"if",
"(",
"dayStr",
".",
"length",
"===",
"1",
")",
"{",
"dayStr",
"=",
"\"0\"",
"+",
"dayStr",
"}",
"// Starting moment, ms.",
"let",
"timestamp",
"=",
"+",
"new",
"Date",
"(",
"`",
"${",
"year",
"}",
"${",
"monthStr",
"}",
"${",
"dayStr",
"}",
"`",
")",
"let",
"time",
"for",
"(",
"let",
"i",
"=",
"366",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"time",
"=",
"new",
"Date",
"(",
"timestamp",
")",
"if",
"(",
"time",
".",
"getDay",
"(",
")",
"===",
"weekDay",
")",
"{",
"countedDays",
"++",
"}",
"if",
"(",
"countedDays",
"===",
"countDays",
")",
"{",
"break",
"}",
"timestamp",
"-=",
"24",
"*",
"3600",
"*",
"1000",
"}",
"return",
"time",
"}",
"}"
] | eg. second friday of 2015 | [
"eg",
".",
"second",
"friday",
"of",
"2015"
] | 5a0d5017ee1d1911983cc5252a27e160438837f7 | https://github.com/espadrine/queread/blob/5a0d5017ee1d1911983cc5252a27e160438837f7/src/tokenizer/time.js#L507-L545 |
53,582 | espadrine/queread | src/tokenizer/time.js | lastDayOfMonth | function lastDayOfMonth(time) {
let year = time.getUTCFullYear()
let nextMonth = time.getUTCMonth() + 2
if (nextMonth > 12) {
year++
nextMonth = 1
}
let nextMonthStr = String(nextMonth)
if (nextMonthStr.length === 1) { nextMonthStr = '0' + nextMonthStr }
let date = new Date(`${year}-${nextMonthStr}-01T00:00:00Z`)
return (new Date(+date - 1000)).getUTCDate()
} | javascript | function lastDayOfMonth(time) {
let year = time.getUTCFullYear()
let nextMonth = time.getUTCMonth() + 2
if (nextMonth > 12) {
year++
nextMonth = 1
}
let nextMonthStr = String(nextMonth)
if (nextMonthStr.length === 1) { nextMonthStr = '0' + nextMonthStr }
let date = new Date(`${year}-${nextMonthStr}-01T00:00:00Z`)
return (new Date(+date - 1000)).getUTCDate()
} | [
"function",
"lastDayOfMonth",
"(",
"time",
")",
"{",
"let",
"year",
"=",
"time",
".",
"getUTCFullYear",
"(",
")",
"let",
"nextMonth",
"=",
"time",
".",
"getUTCMonth",
"(",
")",
"+",
"2",
"if",
"(",
"nextMonth",
">",
"12",
")",
"{",
"year",
"++",
"nextMonth",
"=",
"1",
"}",
"let",
"nextMonthStr",
"=",
"String",
"(",
"nextMonth",
")",
"if",
"(",
"nextMonthStr",
".",
"length",
"===",
"1",
")",
"{",
"nextMonthStr",
"=",
"'0'",
"+",
"nextMonthStr",
"}",
"let",
"date",
"=",
"new",
"Date",
"(",
"`",
"${",
"year",
"}",
"${",
"nextMonthStr",
"}",
"`",
")",
"return",
"(",
"new",
"Date",
"(",
"+",
"date",
"-",
"1000",
")",
")",
".",
"getUTCDate",
"(",
")",
"}"
] | Takes a Date, returns the date of the last day of the corresponding month. eg, 31. | [
"Takes",
"a",
"Date",
"returns",
"the",
"date",
"of",
"the",
"last",
"day",
"of",
"the",
"corresponding",
"month",
".",
"eg",
"31",
"."
] | 5a0d5017ee1d1911983cc5252a27e160438837f7 | https://github.com/espadrine/queread/blob/5a0d5017ee1d1911983cc5252a27e160438837f7/src/tokenizer/time.js#L563-L574 |
53,583 | boylesoftware/x2node-rsparser | index.js | processKeyProperty | function processKeyProperty(propDesc, keyPropContainer) {
// get the key property descriptor
const keyPropName = propDesc._keyPropertyName;
if (!keyPropContainer.hasProperty(keyPropName))
throw invalidPropDef(
propDesc, 'key property ' + keyPropName +
' not found among the target object properties.');
const keyPropDesc = keyPropContainer.getPropertyDesc(keyPropName);
// validate the key property type
if (!keyPropDesc.isScalar() || (keyPropDesc.scalarValueType === 'object'))
throw invalidPropDef(
propDesc, 'key property ' + keyPropName +
' is not suitable to be map key.');
// set key value type in the map property descriptor
propDesc._keyValueType = keyPropDesc.scalarValueType;
if (keyPropDesc.isRef())
propDesc._keyRefTarget = keyPropDesc.refTarget;
} | javascript | function processKeyProperty(propDesc, keyPropContainer) {
// get the key property descriptor
const keyPropName = propDesc._keyPropertyName;
if (!keyPropContainer.hasProperty(keyPropName))
throw invalidPropDef(
propDesc, 'key property ' + keyPropName +
' not found among the target object properties.');
const keyPropDesc = keyPropContainer.getPropertyDesc(keyPropName);
// validate the key property type
if (!keyPropDesc.isScalar() || (keyPropDesc.scalarValueType === 'object'))
throw invalidPropDef(
propDesc, 'key property ' + keyPropName +
' is not suitable to be map key.');
// set key value type in the map property descriptor
propDesc._keyValueType = keyPropDesc.scalarValueType;
if (keyPropDesc.isRef())
propDesc._keyRefTarget = keyPropDesc.refTarget;
} | [
"function",
"processKeyProperty",
"(",
"propDesc",
",",
"keyPropContainer",
")",
"{",
"// get the key property descriptor",
"const",
"keyPropName",
"=",
"propDesc",
".",
"_keyPropertyName",
";",
"if",
"(",
"!",
"keyPropContainer",
".",
"hasProperty",
"(",
"keyPropName",
")",
")",
"throw",
"invalidPropDef",
"(",
"propDesc",
",",
"'key property '",
"+",
"keyPropName",
"+",
"' not found among the target object properties.'",
")",
";",
"const",
"keyPropDesc",
"=",
"keyPropContainer",
".",
"getPropertyDesc",
"(",
"keyPropName",
")",
";",
"// validate the key property type",
"if",
"(",
"!",
"keyPropDesc",
".",
"isScalar",
"(",
")",
"||",
"(",
"keyPropDesc",
".",
"scalarValueType",
"===",
"'object'",
")",
")",
"throw",
"invalidPropDef",
"(",
"propDesc",
",",
"'key property '",
"+",
"keyPropName",
"+",
"' is not suitable to be map key.'",
")",
";",
"// set key value type in the map property descriptor",
"propDesc",
".",
"_keyValueType",
"=",
"keyPropDesc",
".",
"scalarValueType",
";",
"if",
"(",
"keyPropDesc",
".",
"isRef",
"(",
")",
")",
"propDesc",
".",
"_keyRefTarget",
"=",
"keyPropDesc",
".",
"refTarget",
";",
"}"
] | Process key property name definition attribute and set the property
descriptor's key property value type and reference target accordingly.
@private
@param {module:x2node-records~PropertyDescriptor} propDesc Map property
descriptor.
@param {module:x2node-records~PropertiesContainer} keyPropContainer Key
property container. | [
"Process",
"key",
"property",
"name",
"definition",
"attribute",
"and",
"set",
"the",
"property",
"descriptor",
"s",
"key",
"property",
"value",
"type",
"and",
"reference",
"target",
"accordingly",
"."
] | 716526a2f2653b22ee1455800dce1bd95f25ddfb | https://github.com/boylesoftware/x2node-rsparser/blob/716526a2f2653b22ee1455800dce1bd95f25ddfb/index.js#L187-L207 |
53,584 | linyngfly/omelo | lib/connectors/commands/handshake.js | function(opts) {
opts = opts || {};
this.userHandshake = opts.handshake;
if(opts.heartbeat) {
this.heartbeatSec = opts.heartbeat;
this.heartbeat = opts.heartbeat * 1000;
}
this.checkClient = opts.checkClient;
this.useDict = opts.useDict;
this.useProtobuf = opts.useProtobuf;
this.useCrypto = opts.useCrypto;
} | javascript | function(opts) {
opts = opts || {};
this.userHandshake = opts.handshake;
if(opts.heartbeat) {
this.heartbeatSec = opts.heartbeat;
this.heartbeat = opts.heartbeat * 1000;
}
this.checkClient = opts.checkClient;
this.useDict = opts.useDict;
this.useProtobuf = opts.useProtobuf;
this.useCrypto = opts.useCrypto;
} | [
"function",
"(",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"userHandshake",
"=",
"opts",
".",
"handshake",
";",
"if",
"(",
"opts",
".",
"heartbeat",
")",
"{",
"this",
".",
"heartbeatSec",
"=",
"opts",
".",
"heartbeat",
";",
"this",
".",
"heartbeat",
"=",
"opts",
".",
"heartbeat",
"*",
"1000",
";",
"}",
"this",
".",
"checkClient",
"=",
"opts",
".",
"checkClient",
";",
"this",
".",
"useDict",
"=",
"opts",
".",
"useDict",
";",
"this",
".",
"useProtobuf",
"=",
"opts",
".",
"useProtobuf",
";",
"this",
".",
"useCrypto",
"=",
"opts",
".",
"useCrypto",
";",
"}"
] | Process the handshake request.
@param {Object} opts option parameters
opts.handshake(msg, cb(err, resp)) handshake callback. msg is the handshake message from client.
opts.hearbeat heartbeat interval (level?)
opts.version required client level | [
"Process",
"the",
"handshake",
"request",
"."
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/connectors/commands/handshake.js#L16-L30 |
|
53,585 | ariatemplates/noder-js | src/plugins/noderError/evalError.js | formatError | function formatError(err, input) {
var msg = err.message.replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number
var bm = ('' + input.slice(0, err.pos)).match(/.*$/i);
var am = ('' + input.slice(err.pos)).match(/.*/i);
var before = bm ? bm[0] : '';
var after = am ? am[0] : '';
// Prepare line info for txt display
var cursorPos = before.length;
var lineStr = before + after;
var lncursor = [];
for (var i = 0, sz = lineStr.length; sz > i; i++) {
lncursor[i] = (i === cursorPos) ? '\u005E' : '-';
}
var lineInfoTxt = lineStr + '\n' + lncursor.join('');
return {
description: msg,
lineInfoTxt: lineInfoTxt,
code: lineStr,
line: err.loc ? err.loc.line : -1,
column: err.loc ? err.loc.column : -1
};
} | javascript | function formatError(err, input) {
var msg = err.message.replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number
var bm = ('' + input.slice(0, err.pos)).match(/.*$/i);
var am = ('' + input.slice(err.pos)).match(/.*/i);
var before = bm ? bm[0] : '';
var after = am ? am[0] : '';
// Prepare line info for txt display
var cursorPos = before.length;
var lineStr = before + after;
var lncursor = [];
for (var i = 0, sz = lineStr.length; sz > i; i++) {
lncursor[i] = (i === cursorPos) ? '\u005E' : '-';
}
var lineInfoTxt = lineStr + '\n' + lncursor.join('');
return {
description: msg,
lineInfoTxt: lineInfoTxt,
code: lineStr,
line: err.loc ? err.loc.line : -1,
column: err.loc ? err.loc.column : -1
};
} | [
"function",
"formatError",
"(",
"err",
",",
"input",
")",
"{",
"var",
"msg",
"=",
"err",
".",
"message",
".",
"replace",
"(",
"/",
"\\s*\\(\\d*\\:\\d*\\)\\s*$",
"/",
"i",
",",
"''",
")",
";",
"// remove line number / col number",
"var",
"bm",
"=",
"(",
"''",
"+",
"input",
".",
"slice",
"(",
"0",
",",
"err",
".",
"pos",
")",
")",
".",
"match",
"(",
"/",
".*$",
"/",
"i",
")",
";",
"var",
"am",
"=",
"(",
"''",
"+",
"input",
".",
"slice",
"(",
"err",
".",
"pos",
")",
")",
".",
"match",
"(",
"/",
".*",
"/",
"i",
")",
";",
"var",
"before",
"=",
"bm",
"?",
"bm",
"[",
"0",
"]",
":",
"''",
";",
"var",
"after",
"=",
"am",
"?",
"am",
"[",
"0",
"]",
":",
"''",
";",
"// Prepare line info for txt display",
"var",
"cursorPos",
"=",
"before",
".",
"length",
";",
"var",
"lineStr",
"=",
"before",
"+",
"after",
";",
"var",
"lncursor",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"sz",
"=",
"lineStr",
".",
"length",
";",
"sz",
">",
"i",
";",
"i",
"++",
")",
"{",
"lncursor",
"[",
"i",
"]",
"=",
"(",
"i",
"===",
"cursorPos",
")",
"?",
"'\\u005E'",
":",
"'-'",
";",
"}",
"var",
"lineInfoTxt",
"=",
"lineStr",
"+",
"'\\n'",
"+",
"lncursor",
".",
"join",
"(",
"''",
")",
";",
"return",
"{",
"description",
":",
"msg",
",",
"lineInfoTxt",
":",
"lineInfoTxt",
",",
"code",
":",
"lineStr",
",",
"line",
":",
"err",
".",
"loc",
"?",
"err",
".",
"loc",
".",
"line",
":",
"-",
"1",
",",
"column",
":",
"err",
".",
"loc",
"?",
"err",
".",
"loc",
".",
"column",
":",
"-",
"1",
"}",
";",
"}"
] | Format the error as an error structure with line extract information | [
"Format",
"the",
"error",
"as",
"an",
"error",
"structure",
"with",
"line",
"extract",
"information"
] | c2db684299d907b2035fa427f030cf08da8ceb57 | https://github.com/ariatemplates/noder-js/blob/c2db684299d907b2035fa427f030cf08da8ceb57/src/plugins/noderError/evalError.js#L22-L46 |
53,586 | SolarNetwork/solarnetwork-d3 | src/ui/pixelWidth.js | sn_ui_pixelWidth | function sn_ui_pixelWidth(selector) {
if ( selector === undefined ) {
return undefined;
}
var styleWidth = d3.select(selector).style('width');
if ( !styleWidth ) {
return null;
}
var pixels = styleWidth.match(/([0-9.]+)px/);
if ( pixels === null ) {
return null;
}
var result = Math.floor(pixels[1]);
if ( isNaN(result) ) {
return null;
}
return result;
} | javascript | function sn_ui_pixelWidth(selector) {
if ( selector === undefined ) {
return undefined;
}
var styleWidth = d3.select(selector).style('width');
if ( !styleWidth ) {
return null;
}
var pixels = styleWidth.match(/([0-9.]+)px/);
if ( pixels === null ) {
return null;
}
var result = Math.floor(pixels[1]);
if ( isNaN(result) ) {
return null;
}
return result;
} | [
"function",
"sn_ui_pixelWidth",
"(",
"selector",
")",
"{",
"if",
"(",
"selector",
"===",
"undefined",
")",
"{",
"return",
"undefined",
";",
"}",
"var",
"styleWidth",
"=",
"d3",
".",
"select",
"(",
"selector",
")",
".",
"style",
"(",
"'width'",
")",
";",
"if",
"(",
"!",
"styleWidth",
")",
"{",
"return",
"null",
";",
"}",
"var",
"pixels",
"=",
"styleWidth",
".",
"match",
"(",
"/",
"([0-9.]+)px",
"/",
")",
";",
"if",
"(",
"pixels",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"var",
"result",
"=",
"Math",
".",
"floor",
"(",
"pixels",
"[",
"1",
"]",
")",
";",
"if",
"(",
"isNaN",
"(",
"result",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"result",
";",
"}"
] | Get the width of an element based on a selector, in pixels.
@param {string} selector - a selector to an element to get the width of
@returns {number} the width, or {@code undefined} if {@code selector} is undefined,
or {@code null} if the width cannot be computed in pixels | [
"Get",
"the",
"width",
"of",
"an",
"element",
"based",
"on",
"a",
"selector",
"in",
"pixels",
"."
] | 26848b1c303b98b7c0ddeefb8c68c5f5bf78927e | https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/ui/pixelWidth.js#L12-L29 |
53,587 | moxystudio/react-redata | src/redata.js | create | function create(loader, shouldReload = defaultShouldReload, mapper = defaultMapper, initialCtx = defaultInitialCtx) {
// Initialise context, which is passed around and holds the lastData.
const ctx = initialCtx; // TODO: instead of providing a full initial context, the redata() function below should receive
// a third argument, initialData, which is stored in the ctx. This allows for composed
// redatas to be fed initially.
function redata(params, onUpdate) {
// console.log('redata()', params);
// If should not reload the data.
if (!shouldReload(params)) {
console.log('will not reload');
// Inform any subscriber.
onUpdate && onUpdate(ctx.lastData);
// Resolve with last data.
return Promise.resolve(ctx.lastData);
}
console.log('will reload');
// Data not valid, will load new data and subscribe to its updates.
// Reset lastData, since it is no longer valid.
ctx.lastData = { ...defaultInitialData };
// debugger;
// Update any subscriber about new data.
onUpdate && onUpdate(ctx.lastData);
// Store promise reference in order to check which is the last one if multiple resolve.
ctx.promise = load(ctx, loader, params, onUpdate);
// console.log('storing ctx promise', ctx.promise);
ctx.promise.loader = loader;
return ctx.promise;
}
// Store shouldReload and mapper for future reference in redata compositions.
redata.shouldReload = shouldReload;
redata.map = mapper;
return redata;
} | javascript | function create(loader, shouldReload = defaultShouldReload, mapper = defaultMapper, initialCtx = defaultInitialCtx) {
// Initialise context, which is passed around and holds the lastData.
const ctx = initialCtx; // TODO: instead of providing a full initial context, the redata() function below should receive
// a third argument, initialData, which is stored in the ctx. This allows for composed
// redatas to be fed initially.
function redata(params, onUpdate) {
// console.log('redata()', params);
// If should not reload the data.
if (!shouldReload(params)) {
console.log('will not reload');
// Inform any subscriber.
onUpdate && onUpdate(ctx.lastData);
// Resolve with last data.
return Promise.resolve(ctx.lastData);
}
console.log('will reload');
// Data not valid, will load new data and subscribe to its updates.
// Reset lastData, since it is no longer valid.
ctx.lastData = { ...defaultInitialData };
// debugger;
// Update any subscriber about new data.
onUpdate && onUpdate(ctx.lastData);
// Store promise reference in order to check which is the last one if multiple resolve.
ctx.promise = load(ctx, loader, params, onUpdate);
// console.log('storing ctx promise', ctx.promise);
ctx.promise.loader = loader;
return ctx.promise;
}
// Store shouldReload and mapper for future reference in redata compositions.
redata.shouldReload = shouldReload;
redata.map = mapper;
return redata;
} | [
"function",
"create",
"(",
"loader",
",",
"shouldReload",
"=",
"defaultShouldReload",
",",
"mapper",
"=",
"defaultMapper",
",",
"initialCtx",
"=",
"defaultInitialCtx",
")",
"{",
"// Initialise context, which is passed around and holds the lastData.",
"const",
"ctx",
"=",
"initialCtx",
";",
"// TODO: instead of providing a full initial context, the redata() function below should receive",
"// a third argument, initialData, which is stored in the ctx. This allows for composed",
"// redatas to be fed initially.",
"function",
"redata",
"(",
"params",
",",
"onUpdate",
")",
"{",
"// console.log('redata()', params);",
"// If should not reload the data.",
"if",
"(",
"!",
"shouldReload",
"(",
"params",
")",
")",
"{",
"console",
".",
"log",
"(",
"'will not reload'",
")",
";",
"// Inform any subscriber.",
"onUpdate",
"&&",
"onUpdate",
"(",
"ctx",
".",
"lastData",
")",
";",
"// Resolve with last data.",
"return",
"Promise",
".",
"resolve",
"(",
"ctx",
".",
"lastData",
")",
";",
"}",
"console",
".",
"log",
"(",
"'will reload'",
")",
";",
"// Data not valid, will load new data and subscribe to its updates.",
"// Reset lastData, since it is no longer valid.",
"ctx",
".",
"lastData",
"=",
"{",
"...",
"defaultInitialData",
"}",
";",
"// debugger;",
"// Update any subscriber about new data.",
"onUpdate",
"&&",
"onUpdate",
"(",
"ctx",
".",
"lastData",
")",
";",
"// Store promise reference in order to check which is the last one if multiple resolve.",
"ctx",
".",
"promise",
"=",
"load",
"(",
"ctx",
",",
"loader",
",",
"params",
",",
"onUpdate",
")",
";",
"// console.log('storing ctx promise', ctx.promise);",
"ctx",
".",
"promise",
".",
"loader",
"=",
"loader",
";",
"return",
"ctx",
".",
"promise",
";",
"}",
"// Store shouldReload and mapper for future reference in redata compositions.",
"redata",
".",
"shouldReload",
"=",
"shouldReload",
";",
"redata",
".",
"map",
"=",
"mapper",
";",
"return",
"redata",
";",
"}"
] | redata's data object definition
@typedef {Object} Data
@property {boolean} loading - true if the loader is still running, false otherwise.
@property {error} error - instance of Error in case the loader failed, undefined otherwise.
@property {*} result - result of the loader, or undefined if the loader is still running.
@param {function} loader - called to fetch new data
@param {function} [shouldReload = defaultShouldReload] - decides whether a redata should occur
@param {function} [mapper = defaultMapper] - maps the {@link Data} object values to your component's props
@param {object} [initialCtx = defaultInitialCtx] - starting point of redata, defines if there's any preloaded data
@returns {function} redata wrapper function | [
"redata",
"s",
"data",
"object",
"definition"
] | 19f5c548b8dbc3f71fb14077e9740f9dd62bb10a | https://github.com/moxystudio/react-redata/blob/19f5c548b8dbc3f71fb14077e9740f9dd62bb10a/src/redata.js#L20-L57 |
53,588 | molnarg/node-http2-protocol | example/client.js | onConnection | function onConnection() {
var endpoint = new http2.Endpoint(log, 'CLIENT', {});
endpoint.pipe(socket).pipe(endpoint);
// Sending request
var stream = endpoint.createStream();
stream.headers({
':method': 'GET',
':scheme': url.protocol.slice(0, url.protocol.length - 1),
':authority': url.hostname,
':path': url.path + (url.hash || '')
});
// Receiving push streams
stream.on('promise', function(push_stream, req_headers) {
var filename = path.join(__dirname, '/push-' + push_count);
push_count += 1;
console.error('Receiving pushed resource: ' + req_headers[':path'] + ' -> ' + filename);
push_stream.pipe(fs.createWriteStream(filename)).on('finish', finish);
});
// Receiving the response body
stream.pipe(process.stdout);
stream.on('end', finish);
} | javascript | function onConnection() {
var endpoint = new http2.Endpoint(log, 'CLIENT', {});
endpoint.pipe(socket).pipe(endpoint);
// Sending request
var stream = endpoint.createStream();
stream.headers({
':method': 'GET',
':scheme': url.protocol.slice(0, url.protocol.length - 1),
':authority': url.hostname,
':path': url.path + (url.hash || '')
});
// Receiving push streams
stream.on('promise', function(push_stream, req_headers) {
var filename = path.join(__dirname, '/push-' + push_count);
push_count += 1;
console.error('Receiving pushed resource: ' + req_headers[':path'] + ' -> ' + filename);
push_stream.pipe(fs.createWriteStream(filename)).on('finish', finish);
});
// Receiving the response body
stream.pipe(process.stdout);
stream.on('end', finish);
} | [
"function",
"onConnection",
"(",
")",
"{",
"var",
"endpoint",
"=",
"new",
"http2",
".",
"Endpoint",
"(",
"log",
",",
"'CLIENT'",
",",
"{",
"}",
")",
";",
"endpoint",
".",
"pipe",
"(",
"socket",
")",
".",
"pipe",
"(",
"endpoint",
")",
";",
"// Sending request",
"var",
"stream",
"=",
"endpoint",
".",
"createStream",
"(",
")",
";",
"stream",
".",
"headers",
"(",
"{",
"':method'",
":",
"'GET'",
",",
"':scheme'",
":",
"url",
".",
"protocol",
".",
"slice",
"(",
"0",
",",
"url",
".",
"protocol",
".",
"length",
"-",
"1",
")",
",",
"':authority'",
":",
"url",
".",
"hostname",
",",
"':path'",
":",
"url",
".",
"path",
"+",
"(",
"url",
".",
"hash",
"||",
"''",
")",
"}",
")",
";",
"// Receiving push streams",
"stream",
".",
"on",
"(",
"'promise'",
",",
"function",
"(",
"push_stream",
",",
"req_headers",
")",
"{",
"var",
"filename",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'/push-'",
"+",
"push_count",
")",
";",
"push_count",
"+=",
"1",
";",
"console",
".",
"error",
"(",
"'Receiving pushed resource: '",
"+",
"req_headers",
"[",
"':path'",
"]",
"+",
"' -> '",
"+",
"filename",
")",
";",
"push_stream",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"filename",
")",
")",
".",
"on",
"(",
"'finish'",
",",
"finish",
")",
";",
"}",
")",
";",
"// Receiving the response body",
"stream",
".",
"pipe",
"(",
"process",
".",
"stdout",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"finish",
")",
";",
"}"
] | Handling the connection | [
"Handling",
"the",
"connection"
] | a03dff630a33771d045ac0362023afb84b441aa4 | https://github.com/molnarg/node-http2-protocol/blob/a03dff630a33771d045ac0362023afb84b441aa4/example/client.js#L25-L49 |
53,589 | thlorenz/node-traceur | demo/generators.js | iterateElements | function iterateElements(array) {
return {
__iterator__: function() {
var index = 0;
var current;
return {
get current() {
return current;
},
moveNext: function() {
if (index < array.length) {
current = array[index++];
return true;
}
return false;
}
};
}
};
} | javascript | function iterateElements(array) {
return {
__iterator__: function() {
var index = 0;
var current;
return {
get current() {
return current;
},
moveNext: function() {
if (index < array.length) {
current = array[index++];
return true;
}
return false;
}
};
}
};
} | [
"function",
"iterateElements",
"(",
"array",
")",
"{",
"return",
"{",
"__iterator__",
":",
"function",
"(",
")",
"{",
"var",
"index",
"=",
"0",
";",
"var",
"current",
";",
"return",
"{",
"get",
"current",
"(",
")",
"{",
"return",
"current",
";",
"}",
",",
"moveNext",
":",
"function",
"(",
")",
"{",
"if",
"(",
"index",
"<",
"array",
".",
"length",
")",
"{",
"current",
"=",
"array",
"[",
"index",
"++",
"]",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}",
"}",
";",
"}"
] | Example 1. Writing an iterator over an array | [
"Example",
"1",
".",
"Writing",
"an",
"iterator",
"over",
"an",
"array"
] | 79a21ad03831ba36df504988b05022404ad8f9c3 | https://github.com/thlorenz/node-traceur/blob/79a21ad03831ba36df504988b05022404ad8f9c3/demo/generators.js#L4-L23 |
53,590 | BetterCallSky/decorate-it | dist/decorator.js | validate | function validate(method) {
var decorated = function validateDecorator() {
var params = method.params;
var schema = method.schema;
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
var value = _combineObject(params, args);
var normalized = void 0;
try {
normalized = _joi2.default.attempt(value, schema);
} catch (e) {
if (method.sync) {
throw e;
}
return _promise2.default.reject(e);
}
var newArgs = [];
// Joi will normalize values
// for example string number '1' to 1
// if schema type is number
_lodash2.default.each(params, function (param) {
newArgs.push(normalized[param]);
});
return method.apply(undefined, newArgs);
};
return _keepProps(method, decorated);
} | javascript | function validate(method) {
var decorated = function validateDecorator() {
var params = method.params;
var schema = method.schema;
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
var value = _combineObject(params, args);
var normalized = void 0;
try {
normalized = _joi2.default.attempt(value, schema);
} catch (e) {
if (method.sync) {
throw e;
}
return _promise2.default.reject(e);
}
var newArgs = [];
// Joi will normalize values
// for example string number '1' to 1
// if schema type is number
_lodash2.default.each(params, function (param) {
newArgs.push(normalized[param]);
});
return method.apply(undefined, newArgs);
};
return _keepProps(method, decorated);
} | [
"function",
"validate",
"(",
"method",
")",
"{",
"var",
"decorated",
"=",
"function",
"validateDecorator",
"(",
")",
"{",
"var",
"params",
"=",
"method",
".",
"params",
";",
"var",
"schema",
"=",
"method",
".",
"schema",
";",
"for",
"(",
"var",
"_len2",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"Array",
"(",
"_len2",
")",
",",
"_key2",
"=",
"0",
";",
"_key2",
"<",
"_len2",
";",
"_key2",
"++",
")",
"{",
"args",
"[",
"_key2",
"]",
"=",
"arguments",
"[",
"_key2",
"]",
";",
"}",
"var",
"value",
"=",
"_combineObject",
"(",
"params",
",",
"args",
")",
";",
"var",
"normalized",
"=",
"void",
"0",
";",
"try",
"{",
"normalized",
"=",
"_joi2",
".",
"default",
".",
"attempt",
"(",
"value",
",",
"schema",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"method",
".",
"sync",
")",
"{",
"throw",
"e",
";",
"}",
"return",
"_promise2",
".",
"default",
".",
"reject",
"(",
"e",
")",
";",
"}",
"var",
"newArgs",
"=",
"[",
"]",
";",
"// Joi will normalize values",
"// for example string number '1' to 1",
"// if schema type is number",
"_lodash2",
".",
"default",
".",
"each",
"(",
"params",
",",
"function",
"(",
"param",
")",
"{",
"newArgs",
".",
"push",
"(",
"normalized",
"[",
"param",
"]",
")",
";",
"}",
")",
";",
"return",
"method",
".",
"apply",
"(",
"undefined",
",",
"newArgs",
")",
";",
"}",
";",
"return",
"_keepProps",
"(",
"method",
",",
"decorated",
")",
";",
"}"
] | Decorator for validating with Joi
@param {Function} method the method to decorate
@param {Array} method.params the method parameters
@param {Object} method.schema the joi schema
@param {Boolean} method.sync the flag if method is sync or async
@returns {Function} the decorator | [
"Decorator",
"for",
"validating",
"with",
"Joi"
] | 8807a65c80a88255227c4ce818d151b4dc979683 | https://github.com/BetterCallSky/decorate-it/blob/8807a65c80a88255227c4ce818d151b4dc979683/dist/decorator.js#L218-L247 |
53,591 | BetterCallSky/decorate-it | dist/decorator.js | decorate | function decorate(service, serviceName) {
var logger = _config.loggerFactory(serviceName, _config);
_lodash2.default.map(service, function (method, name) {
method.methodName = name;
if (!method.params) {
method.params = (0, _getParameterNames2.default)(method);
}
service[name] = log(validate(method), logger, method);
});
} | javascript | function decorate(service, serviceName) {
var logger = _config.loggerFactory(serviceName, _config);
_lodash2.default.map(service, function (method, name) {
method.methodName = name;
if (!method.params) {
method.params = (0, _getParameterNames2.default)(method);
}
service[name] = log(validate(method), logger, method);
});
} | [
"function",
"decorate",
"(",
"service",
",",
"serviceName",
")",
"{",
"var",
"logger",
"=",
"_config",
".",
"loggerFactory",
"(",
"serviceName",
",",
"_config",
")",
";",
"_lodash2",
".",
"default",
".",
"map",
"(",
"service",
",",
"function",
"(",
"method",
",",
"name",
")",
"{",
"method",
".",
"methodName",
"=",
"name",
";",
"if",
"(",
"!",
"method",
".",
"params",
")",
"{",
"method",
".",
"params",
"=",
"(",
"0",
",",
"_getParameterNames2",
".",
"default",
")",
"(",
"method",
")",
";",
"}",
"service",
"[",
"name",
"]",
"=",
"log",
"(",
"validate",
"(",
"method",
")",
",",
"logger",
",",
"method",
")",
";",
"}",
")",
";",
"}"
] | Decorate all methods in the service
@param {Object} service the service object
@param {String} serviceName the service name | [
"Decorate",
"all",
"methods",
"in",
"the",
"service"
] | 8807a65c80a88255227c4ce818d151b4dc979683 | https://github.com/BetterCallSky/decorate-it/blob/8807a65c80a88255227c4ce818d151b4dc979683/dist/decorator.js#L254-L263 |
53,592 | zenozeng/interval.js | lib/interval.js | Interval | function Interval(func, options) {
this.func = func;
this.delay = options.delay || 16;
this.lifetime = options.lifetime;
this.useRequestAnimationFrame = options.useRequestAnimationFrame && window.requestAnimationFrame && window.cancelAnimationFrame;
this.interval = null;
this.gcTimeout = null;
} | javascript | function Interval(func, options) {
this.func = func;
this.delay = options.delay || 16;
this.lifetime = options.lifetime;
this.useRequestAnimationFrame = options.useRequestAnimationFrame && window.requestAnimationFrame && window.cancelAnimationFrame;
this.interval = null;
this.gcTimeout = null;
} | [
"function",
"Interval",
"(",
"func",
",",
"options",
")",
"{",
"this",
".",
"func",
"=",
"func",
";",
"this",
".",
"delay",
"=",
"options",
".",
"delay",
"||",
"16",
";",
"this",
".",
"lifetime",
"=",
"options",
".",
"lifetime",
";",
"this",
".",
"useRequestAnimationFrame",
"=",
"options",
".",
"useRequestAnimationFrame",
"&&",
"window",
".",
"requestAnimationFrame",
"&&",
"window",
".",
"cancelAnimationFrame",
";",
"this",
".",
"interval",
"=",
"null",
";",
"this",
".",
"gcTimeout",
"=",
"null",
";",
"}"
] | Interval.js
@constructor
@param {function} func - The function you want to be called repeatly
@param {int} delay - milliseconds that should wait before each call
@param {int} lifetime - if set, clearInterval will be called after `lifetime` milliseconds | [
"Interval",
".",
"js"
] | 7a8d112378b44a0e2ae6f989c65d290200ea6485 | https://github.com/zenozeng/interval.js/blob/7a8d112378b44a0e2ae6f989c65d290200ea6485/lib/interval.js#L9-L16 |
53,593 | cirocosta/yaspm | src/Device.js | Device | function Device (device, sp) {
if (!(device && sp))
throw new Error('a Device and a SerialPort must be passed');
for (var i in device)
this[i] = device[i];
this._open = false;
this._sp = sp;
EventEmitter.call(this);
} | javascript | function Device (device, sp) {
if (!(device && sp))
throw new Error('a Device and a SerialPort must be passed');
for (var i in device)
this[i] = device[i];
this._open = false;
this._sp = sp;
EventEmitter.call(this);
} | [
"function",
"Device",
"(",
"device",
",",
"sp",
")",
"{",
"if",
"(",
"!",
"(",
"device",
"&&",
"sp",
")",
")",
"throw",
"new",
"Error",
"(",
"'a Device and a SerialPort must be passed'",
")",
";",
"for",
"(",
"var",
"i",
"in",
"device",
")",
"this",
"[",
"i",
"]",
"=",
"device",
"[",
"i",
"]",
";",
"this",
".",
"_open",
"=",
"false",
";",
"this",
".",
"_sp",
"=",
"sp",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"}"
] | Represents a valid Device.
emits:
- connect
- disconnect
- error
@param {obj} device the info about the device
@param {obj} sp serialport object | [
"Represents",
"a",
"valid",
"Device",
"."
] | 676524906425ba99b1e6f95a75ce4a82501a0ee9 | https://github.com/cirocosta/yaspm/blob/676524906425ba99b1e6f95a75ce4a82501a0ee9/src/Device.js#L21-L32 |
53,594 | NumminorihSF/bramqp-wrapper | domain/exchange.js | Exchange | function Exchange(client, channel){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
return this;
} | javascript | function Exchange(client, channel){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
return this;
} | [
"function",
"Exchange",
"(",
"client",
",",
"channel",
")",
"{",
"EE",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"client",
"=",
"client",
";",
"this",
".",
"channel",
"=",
"channel",
";",
"this",
".",
"id",
"=",
"channel",
".",
"$getId",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Work with exchanges.
Exchanges match and distribute messages across queues.
Exchanges can be configured in the server or declared at runtime.
@extends EventEmitter
@param {BRAMQPClient} client Client object that returns from bramqp#openAMQPCommunication() method.
@param {Channel} channel Channel object (should be opened).
@return {Exchange}
@constructor | [
"Work",
"with",
"exchanges",
"."
] | 3e2bd769a2828f7592eba79556c9ef1491177781 | https://github.com/NumminorihSF/bramqp-wrapper/blob/3e2bd769a2828f7592eba79556c9ef1491177781/domain/exchange.js#L26-L33 |
53,595 | brandtabbott/spotify-server | public/js/spotify-client.js | sortByAttributeNameComparitor | function sortByAttributeNameComparitor(a,b) {
if (a.attributes.name < b.attributes.name)
return -1;
if (a.attributes.name > b.attributes.name)
return 1;
return 0;
} | javascript | function sortByAttributeNameComparitor(a,b) {
if (a.attributes.name < b.attributes.name)
return -1;
if (a.attributes.name > b.attributes.name)
return 1;
return 0;
} | [
"function",
"sortByAttributeNameComparitor",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
".",
"attributes",
".",
"name",
"<",
"b",
".",
"attributes",
".",
"name",
")",
"return",
"-",
"1",
";",
"if",
"(",
"a",
".",
"attributes",
".",
"name",
">",
"b",
".",
"attributes",
".",
"name",
")",
"return",
"1",
";",
"return",
"0",
";",
"}"
] | Sort function for playlists | [
"Sort",
"function",
"for",
"playlists"
] | d4451e64faaa201c620a118f4978f3c1b514386f | https://github.com/brandtabbott/spotify-server/blob/d4451e64faaa201c620a118f4978f3c1b514386f/public/js/spotify-client.js#L207-L214 |
53,596 | ashpool/telldus-live-promise | lib/devices.js | turnOn | function turnOn(device) {
return api.request('/device/turnOn?' + querystring.stringify({id: device.id || device}));
} | javascript | function turnOn(device) {
return api.request('/device/turnOn?' + querystring.stringify({id: device.id || device}));
} | [
"function",
"turnOn",
"(",
"device",
")",
"{",
"return",
"api",
".",
"request",
"(",
"'/device/turnOn?'",
"+",
"querystring",
".",
"stringify",
"(",
"{",
"id",
":",
"device",
".",
"id",
"||",
"device",
"}",
")",
")",
";",
"}"
] | Turns a device off
@param device either {id: anId} or anId
@returns {*} a Promise | [
"Turns",
"a",
"device",
"off"
] | ee13365136da640d78907f468b19580bdd8545d8 | https://github.com/ashpool/telldus-live-promise/blob/ee13365136da640d78907f468b19580bdd8545d8/lib/devices.js#L17-L19 |
53,597 | ashpool/telldus-live-promise | lib/devices.js | turnOff | function turnOff(device) {
return api.request('/device/turnOff?' + querystring.stringify({id: device.id || device}));
} | javascript | function turnOff(device) {
return api.request('/device/turnOff?' + querystring.stringify({id: device.id || device}));
} | [
"function",
"turnOff",
"(",
"device",
")",
"{",
"return",
"api",
".",
"request",
"(",
"'/device/turnOff?'",
"+",
"querystring",
".",
"stringify",
"(",
"{",
"id",
":",
"device",
".",
"id",
"||",
"device",
"}",
")",
")",
";",
"}"
] | Turns a device on
@param device either {id: anId} or anId
@returns {*} a Promise | [
"Turns",
"a",
"device",
"on"
] | ee13365136da640d78907f468b19580bdd8545d8 | https://github.com/ashpool/telldus-live-promise/blob/ee13365136da640d78907f468b19580bdd8545d8/lib/devices.js#L26-L28 |
53,598 | ashpool/telldus-live-promise | lib/devices.js | history | function history(device, from, to) {
return api.request('/device/history?' + querystring.stringify({id: device.id || device, from: from, to: to}));
} | javascript | function history(device, from, to) {
return api.request('/device/history?' + querystring.stringify({id: device.id || device, from: from, to: to}));
} | [
"function",
"history",
"(",
"device",
",",
"from",
",",
"to",
")",
"{",
"return",
"api",
".",
"request",
"(",
"'/device/history?'",
"+",
"querystring",
".",
"stringify",
"(",
"{",
"id",
":",
"device",
".",
"id",
"||",
"device",
",",
"from",
":",
"from",
",",
"to",
":",
"to",
"}",
")",
")",
";",
"}"
] | Returns device history
@param device either {id: anId} or anId
@param from timestamp in seconds
@param to timestamp in seconds
@returns {*} a Promise | [
"Returns",
"device",
"history"
] | ee13365136da640d78907f468b19580bdd8545d8 | https://github.com/ashpool/telldus-live-promise/blob/ee13365136da640d78907f468b19580bdd8545d8/lib/devices.js#L37-L39 |
53,599 | iolo/express-toybox | multipart.js | multipart | function multipart(options) {
options = options || {};
DEBUG && debug('configure http multipart middleware', options);
return function (req, res, next) {
if (req._body || !req.is('multipart/form-data') || 'POST' !== req.method) {
return next();
}
DEBUG && debug('got multipart request', req.path);
req.form = new multiparty.Form(options);
req.form.parse(req, function(err, fields, files) {
if (err) {
DEBUG && debug('err', err);
return next(err);
}
DEBUG && debug('fields', fields);
DEBUG && debug('files', files);
req._body = true;
req.body = fields;
req.files = files;
return next();
});
};
} | javascript | function multipart(options) {
options = options || {};
DEBUG && debug('configure http multipart middleware', options);
return function (req, res, next) {
if (req._body || !req.is('multipart/form-data') || 'POST' !== req.method) {
return next();
}
DEBUG && debug('got multipart request', req.path);
req.form = new multiparty.Form(options);
req.form.parse(req, function(err, fields, files) {
if (err) {
DEBUG && debug('err', err);
return next(err);
}
DEBUG && debug('fields', fields);
DEBUG && debug('files', files);
req._body = true;
req.body = fields;
req.files = files;
return next();
});
};
} | [
"function",
"multipart",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"DEBUG",
"&&",
"debug",
"(",
"'configure http multipart middleware'",
",",
"options",
")",
";",
"return",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"req",
".",
"_body",
"||",
"!",
"req",
".",
"is",
"(",
"'multipart/form-data'",
")",
"||",
"'POST'",
"!==",
"req",
".",
"method",
")",
"{",
"return",
"next",
"(",
")",
";",
"}",
"DEBUG",
"&&",
"debug",
"(",
"'got multipart request'",
",",
"req",
".",
"path",
")",
";",
"req",
".",
"form",
"=",
"new",
"multiparty",
".",
"Form",
"(",
"options",
")",
";",
"req",
".",
"form",
".",
"parse",
"(",
"req",
",",
"function",
"(",
"err",
",",
"fields",
",",
"files",
")",
"{",
"if",
"(",
"err",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'err'",
",",
"err",
")",
";",
"return",
"next",
"(",
"err",
")",
";",
"}",
"DEBUG",
"&&",
"debug",
"(",
"'fields'",
",",
"fields",
")",
";",
"DEBUG",
"&&",
"debug",
"(",
"'files'",
",",
"files",
")",
";",
"req",
".",
"_body",
"=",
"true",
";",
"req",
".",
"body",
"=",
"fields",
";",
"req",
".",
"files",
"=",
"files",
";",
"return",
"next",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | multipart middleware using "multiparty".
@param {*} [options]
@param {String} [encoding='utf8']
@param {String} [uploadDir=os.tmpdir()]
@param {String} [keepExtensions=false]
@param {Number} [maxFields=2*1024*1024]
@param {Number} [maxFieldsSize=1000]
@param {Number} [maxFilesSize=Infinity]
@param {String} [hash=false] 'sha1' or 'md5'
@param {boolean} [autoFields]
@param {boolean} [autoFiles]
@returns {Function} connect/express middleware function
@see https://github.com/andrewrk/node-multiparty | [
"multipart",
"middleware",
"using",
"multiparty",
"."
] | c375a1388cfc167017e8dcd2325e71ca86ccb994 | https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/multipart.js#L28-L51 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.