repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1
value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sembaye/numberconverter | index.js | bintodecoutput | function bintodecoutput(bin){
var len = bin.length;
var decoutput = String();
var work = new Array(len);
var outputlen = 0;
for(var i=0; i<len; i++){work[i] = bin[i];}
while(len){
// as long as a remaining value exists
var lead = false;
var bit0;
var bit1;
var bit2;
var bit3;
var... | javascript | function bintodecoutput(bin){
var len = bin.length;
var decoutput = String();
var work = new Array(len);
var outputlen = 0;
for(var i=0; i<len; i++){work[i] = bin[i];}
while(len){
// as long as a remaining value exists
var lead = false;
var bit0;
var bit1;
var bit2;
var bit3;
var... | [
"function",
"bintodecoutput",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"decoutput",
"=",
"String",
"(",
")",
";",
"var",
"work",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"var",
"outputlen",
"=",
"0",
";",
"for",
... | Formats the given binary array to a decimal output string | [
"Formats",
"the",
"given",
"binary",
"array",
"to",
"a",
"decimal",
"output",
"string"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L108-L176 | train |
sembaye/numberconverter | index.js | bintohexoutput | function bintohexoutput(bin){
var len = bin.length;
var hexoutput = String();
for(var i=0; i<len; i+=4){
if((i > 0) && !(i%8)){hexoutput = " " + hexoutput;}
var value = 0;
if(bin[len - 1 - i - 0]){value+=1;}
if(bin[len - 1 - i - 1]){value+=2;}
if(bin[len - 1 - i - 2]){value+=4;}
if(bin[len... | javascript | function bintohexoutput(bin){
var len = bin.length;
var hexoutput = String();
for(var i=0; i<len; i+=4){
if((i > 0) && !(i%8)){hexoutput = " " + hexoutput;}
var value = 0;
if(bin[len - 1 - i - 0]){value+=1;}
if(bin[len - 1 - i - 1]){value+=2;}
if(bin[len - 1 - i - 2]){value+=4;}
if(bin[len... | [
"function",
"bintohexoutput",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"hexoutput",
"=",
"String",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"4",
")",
"{",
"if",
"... | Formats the given binary array to a hexadecimal output string | [
"Formats",
"the",
"given",
"binary",
"array",
"to",
"a",
"hexadecimal",
"output",
"string"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L179-L211 | train |
sembaye/numberconverter | index.js | bintobinoutput | function bintobinoutput(bin){
var len = bin.length;
var binoutput = String();
for(var i=0; i<len; i++){
if((i > 0) && !(i%8)){binoutput = " " + binoutput;}
if(bin[len - 1 - i]){binoutput = "1" + binoutput;}else{binoutput = "0" + binoutput;}
}
// todo: make faster
return binoutput;
} | javascript | function bintobinoutput(bin){
var len = bin.length;
var binoutput = String();
for(var i=0; i<len; i++){
if((i > 0) && !(i%8)){binoutput = " " + binoutput;}
if(bin[len - 1 - i]){binoutput = "1" + binoutput;}else{binoutput = "0" + binoutput;}
}
// todo: make faster
return binoutput;
} | [
"function",
"bintobinoutput",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"binoutput",
"=",
"String",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"... | Formats the given binary array to a binary output string | [
"Formats",
"the",
"given",
"binary",
"array",
"to",
"a",
"binary",
"output",
"string"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L214-L223 | train |
sembaye/numberconverter | index.js | bintooctoutput | function bintooctoutput(bin){
var len = bin.length;
var octoutput = String();
for(var i=0; i<len; i+=3){
if((i > 0) && !(i%24)){octoutput = " " + octoutput;}
var value = 0;
if(bin[len - 1 - i - 0]){value+=1;}
if(bin[len - 1 - i - 1]){value+=2;}
if(bin[len - 1 - i - 2]){value+=4;}
switch(va... | javascript | function bintooctoutput(bin){
var len = bin.length;
var octoutput = String();
for(var i=0; i<len; i+=3){
if((i > 0) && !(i%24)){octoutput = " " + octoutput;}
var value = 0;
if(bin[len - 1 - i - 0]){value+=1;}
if(bin[len - 1 - i - 1]){value+=2;}
if(bin[len - 1 - i - 2]){value+=4;}
switch(va... | [
"function",
"bintooctoutput",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"octoutput",
"=",
"String",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"3",
")",
"{",
"if",
"... | Formats the given binary array to a octal output string | [
"Formats",
"the",
"given",
"binary",
"array",
"to",
"a",
"octal",
"output",
"string"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L226-L249 | train |
sembaye/numberconverter | index.js | filledarray | function filledarray(value, size){
var a = new Array(size);
for(var i=0; i<size; i++){a[i] = value;}
return a;
} | javascript | function filledarray(value, size){
var a = new Array(size);
for(var i=0; i<size; i++){a[i] = value;}
return a;
} | [
"function",
"filledarray",
"(",
"value",
",",
"size",
")",
"{",
"var",
"a",
"=",
"new",
"Array",
"(",
"size",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"a",
"[",
"i",
"]",
"=",
"value",
";"... | Returns an array of a given size filled with the given value. | [
"Returns",
"an",
"array",
"of",
"a",
"given",
"size",
"filled",
"with",
"the",
"given",
"value",
"."
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L252-L256 | train |
sembaye/numberconverter | index.js | binadd | function binadd(bin1, bin2){
var i1 = bin1.length;
var i2 = bin2.length;
var i3 = (i1 > i2) ? (i1 + 1) : (i2 + 1);
var result = new Array(i3);
var c = 0;
// Add the two arrays as long as there exist elements in the arrays
while((i1 > 0) && (i2 > 0)){
i1--;
i2--;
i3--;
if(bin1[i1]){c++;}
... | javascript | function binadd(bin1, bin2){
var i1 = bin1.length;
var i2 = bin2.length;
var i3 = (i1 > i2) ? (i1 + 1) : (i2 + 1);
var result = new Array(i3);
var c = 0;
// Add the two arrays as long as there exist elements in the arrays
while((i1 > 0) && (i2 > 0)){
i1--;
i2--;
i3--;
if(bin1[i1]){c++;}
... | [
"function",
"binadd",
"(",
"bin1",
",",
"bin2",
")",
"{",
"var",
"i1",
"=",
"bin1",
".",
"length",
";",
"var",
"i2",
"=",
"bin2",
".",
"length",
";",
"var",
"i3",
"=",
"(",
"i1",
">",
"i2",
")",
"?",
"(",
"i1",
"+",
"1",
")",
":",
"(",
"i2"... | Addition of two binary arrays | [
"Addition",
"of",
"two",
"binary",
"arrays"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L259-L295 | train |
sembaye/numberconverter | index.js | binaddone | function binaddone(bin){
var len = bin.length;
var result = new Array(len + 1);
var c = true; // carry bit
var i = len; // i points at the bit in bin one after the untouched bit
while(c && (i > 0)){
i--;
c = bin[i];
result[i+1] = !c;
}
if(i){
// Return remaining untouched bin concatena... | javascript | function binaddone(bin){
var len = bin.length;
var result = new Array(len + 1);
var c = true; // carry bit
var i = len; // i points at the bit in bin one after the untouched bit
while(c && (i > 0)){
i--;
c = bin[i];
result[i+1] = !c;
}
if(i){
// Return remaining untouched bin concatena... | [
"function",
"binaddone",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"result",
"=",
"new",
"Array",
"(",
"len",
"+",
"1",
")",
";",
"var",
"c",
"=",
"true",
";",
"// carry bit",
"var",
"i",
"=",
"len",
";",
"// i po... | Addition of 1 to a binary array | [
"Addition",
"of",
"1",
"to",
"a",
"binary",
"array"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L298-L321 | train |
sembaye/numberconverter | index.js | bintruncate | function bintruncate(bin, size){
var len = bin.length;
if(len < size){
return filledarray(false, size-len).concat(bin);
}else{
return bin.slice(len - size);
}
} | javascript | function bintruncate(bin, size){
var len = bin.length;
if(len < size){
return filledarray(false, size-len).concat(bin);
}else{
return bin.slice(len - size);
}
} | [
"function",
"bintruncate",
"(",
"bin",
",",
"size",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"if",
"(",
"len",
"<",
"size",
")",
"{",
"return",
"filledarray",
"(",
"false",
",",
"size",
"-",
"len",
")",
".",
"concat",
"(",
"bin",
"... | Either truncates the binary array or fills the MSBs with 0 to fit the size. | [
"Either",
"truncates",
"the",
"binary",
"array",
"or",
"fills",
"the",
"MSBs",
"with",
"0",
"to",
"fit",
"the",
"size",
"."
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L353-L360 | train |
sembaye/numberconverter | index.js | onescomplement | function onescomplement(bin){
var len = bin.length;
var onebin = new Array(len);
for (var i=0; i<len; i++){onebin[i] = !bin[i];}
return onebin;
} | javascript | function onescomplement(bin){
var len = bin.length;
var onebin = new Array(len);
for (var i=0; i<len; i++){onebin[i] = !bin[i];}
return onebin;
} | [
"function",
"onescomplement",
"(",
"bin",
")",
"{",
"var",
"len",
"=",
"bin",
".",
"length",
";",
"var",
"onebin",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"o... | Computes the one's complement of the binary number | [
"Computes",
"the",
"one",
"s",
"complement",
"of",
"the",
"binary",
"number"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L363-L368 | train |
sembaye/numberconverter | index.js | updatedec | function updatedec(){
var dec = decinputfield;
if(decinputvalue != dec){
updateall(decinputtobin(dec));
clearallinputs();
decinputfield = dec;
decinputvalue = dec;
}
} | javascript | function updatedec(){
var dec = decinputfield;
if(decinputvalue != dec){
updateall(decinputtobin(dec));
clearallinputs();
decinputfield = dec;
decinputvalue = dec;
}
} | [
"function",
"updatedec",
"(",
")",
"{",
"var",
"dec",
"=",
"decinputfield",
";",
"if",
"(",
"decinputvalue",
"!=",
"dec",
")",
"{",
"updateall",
"(",
"decinputtobin",
"(",
"dec",
")",
")",
";",
"clearallinputs",
"(",
")",
";",
"decinputfield",
"=",
"dec"... | The decimal input field has been changed | [
"The",
"decimal",
"input",
"field",
"has",
"been",
"changed"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L388-L396 | train |
sembaye/numberconverter | index.js | updatehex | function updatehex(){
var hex = hexinputfield;
if(hexinputvalue != hex){
updateall(hexinputtobin(hex));
clearallinputs();
hexinputfield = hex;
hexinputvalue = hex;
}
} | javascript | function updatehex(){
var hex = hexinputfield;
if(hexinputvalue != hex){
updateall(hexinputtobin(hex));
clearallinputs();
hexinputfield = hex;
hexinputvalue = hex;
}
} | [
"function",
"updatehex",
"(",
")",
"{",
"var",
"hex",
"=",
"hexinputfield",
";",
"if",
"(",
"hexinputvalue",
"!=",
"hex",
")",
"{",
"updateall",
"(",
"hexinputtobin",
"(",
"hex",
")",
")",
";",
"clearallinputs",
"(",
")",
";",
"hexinputfield",
"=",
"hex"... | The hexadecimal input field has been changed | [
"The",
"hexadecimal",
"input",
"field",
"has",
"been",
"changed"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L399-L407 | train |
sembaye/numberconverter | index.js | updatebin | function updatebin(){
var bin = bininputfield;
if(bininputvalue != bin){
updateall(bininputtobin(bin));
clearallinputs();
bininputfield = bin;
bininputvalue = bin;
}
} | javascript | function updatebin(){
var bin = bininputfield;
if(bininputvalue != bin){
updateall(bininputtobin(bin));
clearallinputs();
bininputfield = bin;
bininputvalue = bin;
}
} | [
"function",
"updatebin",
"(",
")",
"{",
"var",
"bin",
"=",
"bininputfield",
";",
"if",
"(",
"bininputvalue",
"!=",
"bin",
")",
"{",
"updateall",
"(",
"bininputtobin",
"(",
"bin",
")",
")",
";",
"clearallinputs",
"(",
")",
";",
"bininputfield",
"=",
"bin"... | The binary input field has been changed | [
"The",
"binary",
"input",
"field",
"has",
"been",
"changed"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L410-L418 | train |
sembaye/numberconverter | index.js | updateoct | function updateoct(){
var oct = octinputfield;
if(octinputvalue != oct){
updateall(octinputtobin(oct));
clearallinputs();
octinputfield = oct;
octinputvalue = oct;
}
} | javascript | function updateoct(){
var oct = octinputfield;
if(octinputvalue != oct){
updateall(octinputtobin(oct));
clearallinputs();
octinputfield = oct;
octinputvalue = oct;
}
} | [
"function",
"updateoct",
"(",
")",
"{",
"var",
"oct",
"=",
"octinputfield",
";",
"if",
"(",
"octinputvalue",
"!=",
"oct",
")",
"{",
"updateall",
"(",
"octinputtobin",
"(",
"oct",
")",
")",
";",
"clearallinputs",
"(",
")",
";",
"octinputfield",
"=",
"oct"... | The octal input field has been changed | [
"The",
"octal",
"input",
"field",
"has",
"been",
"changed"
] | c3cd4c0c567e520354e0e4fb60a669fd5f07877a | https://github.com/sembaye/numberconverter/blob/c3cd4c0c567e520354e0e4fb60a669fd5f07877a/index.js#L421-L429 | train |
ryb73/dealers-choice-meta | packages/front-end/src/components/dc-game-canvas/animation-throttler.js | AnimationThrottler | function AnimationThrottler(delay) {
if(!delay) delay = DELAY;
// Anim is considered active if it's running or queued
var currentDelay = 0;
// func: Function that takes no params and returns a promise
function requestAnim(func) {
var result = q.delay(currentDelay)
.thenResolve(func)
.then(st... | javascript | function AnimationThrottler(delay) {
if(!delay) delay = DELAY;
// Anim is considered active if it's running or queued
var currentDelay = 0;
// func: Function that takes no params and returns a promise
function requestAnim(func) {
var result = q.delay(currentDelay)
.thenResolve(func)
.then(st... | [
"function",
"AnimationThrottler",
"(",
"delay",
")",
"{",
"if",
"(",
"!",
"delay",
")",
"delay",
"=",
"DELAY",
";",
"// Anim is considered active if it's running or queued",
"var",
"currentDelay",
"=",
"0",
";",
"// func: Function that takes no params and returns a promise"... | Manges a queue of pending animates so that, if many are requested, not all of them run at once. An example of a situation where many animations would be requested at once is at the beginning of the game when cards are being dealt. | [
"Manges",
"a",
"queue",
"of",
"pending",
"animates",
"so",
"that",
"if",
"many",
"are",
"requested",
"not",
"all",
"of",
"them",
"run",
"at",
"once",
".",
"An",
"example",
"of",
"a",
"situation",
"where",
"many",
"animations",
"would",
"be",
"requested",
... | 4632e8897c832b01d944a340cf87d5c807809925 | https://github.com/ryb73/dealers-choice-meta/blob/4632e8897c832b01d944a340cf87d5c807809925/packages/front-end/src/components/dc-game-canvas/animation-throttler.js#L14-L44 | train |
chapmanu/hb | lib/hummingbird.js | function(service, credentials) {
Services.load(service);
process.nextTick(function() {
Services.boot(service, credentials);
}.bind(this));
} | javascript | function(service, credentials) {
Services.load(service);
process.nextTick(function() {
Services.boot(service, credentials);
}.bind(this));
} | [
"function",
"(",
"service",
",",
"credentials",
")",
"{",
"Services",
".",
"load",
"(",
"service",
")",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"Services",
".",
"boot",
"(",
"service",
",",
"credentials",
")",
";",
"}",
".",
... | Add a service to be streamed
@param {string} service - identifier of service, 'twitter', 'instagram', etc.
@param {object} credentials - API credentials for the service | [
"Add",
"a",
"service",
"to",
"be",
"streamed"
] | 5edd8de89c7c5fdffc3df0c627513889220f7d51 | https://github.com/chapmanu/hb/blob/5edd8de89c7c5fdffc3df0c627513889220f7d51/lib/hummingbird.js#L38-L43 | train | |
DScheglov/merest | lib/controllers/update.js | update | function update(req, res, next) {
res.__apiMethod = 'update';
const self = this;
const id = req.params.id;
let filter = this.option('update', 'filter');
const fields = this.option('update', 'fields');
const populate = this.option('update', 'populate');
const readonly = this.option('update', 'readon... | javascript | function update(req, res, next) {
res.__apiMethod = 'update';
const self = this;
const id = req.params.id;
let filter = this.option('update', 'filter');
const fields = this.option('update', 'fields');
const populate = this.option('update', 'populate');
const readonly = this.option('update', 'readon... | [
"function",
"update",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"__apiMethod",
"=",
"'update'",
";",
"const",
"self",
"=",
"this",
";",
"const",
"id",
"=",
"req",
".",
"params",
".",
"id",
";",
"let",
"filter",
"=",
"this",
".",
... | update - controller that updates a model instance
@param {express.Request} req Request
@param {express.Response} res Response
@param {Function} next Callback to pass a thrown exception
@throws ModelAPIError(404, '...')
@throws ModelAPIError(422, '...')
@memberof ModelAPIRouter | [
"update",
"-",
"controller",
"that",
"updates",
"a",
"model",
"instance"
] | d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/update.js#L18-L71 | train |
cheminfo-js/peaks-similarity | src/index.js | getOverlapTrapezoid | function getOverlapTrapezoid(x1, y1, x2, y2) {
var factor = 2 / (widthTop + widthBottom); // correction for surface=1
if (y1 === 0 || y2 === 0) return 0;
if (x1 === x2) { // they have the same position
return Math.min(y1, y2);
}
var diff = Math.abs(x1 - x2);
if (diff >= widthBottom) retur... | javascript | function getOverlapTrapezoid(x1, y1, x2, y2) {
var factor = 2 / (widthTop + widthBottom); // correction for surface=1
if (y1 === 0 || y2 === 0) return 0;
if (x1 === x2) { // they have the same position
return Math.min(y1, y2);
}
var diff = Math.abs(x1 - x2);
if (diff >= widthBottom) retur... | [
"function",
"getOverlapTrapezoid",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"{",
"var",
"factor",
"=",
"2",
"/",
"(",
"widthTop",
"+",
"widthBottom",
")",
";",
"// correction for surface=1",
"if",
"(",
"y1",
"===",
"0",
"||",
"y2",
"===",
"0",
... | This is the old trapezoid similarity | [
"This",
"is",
"the",
"old",
"trapezoid",
"similarity"
] | d1b011072c953458f05d3aa1f18d420a67cf717f | https://github.com/cheminfo-js/peaks-similarity/blob/d1b011072c953458f05d3aa1f18d420a67cf717f/src/index.js#L157-L213 | train |
cheminfo-js/peaks-similarity | src/index.js | calculateDiff | function calculateDiff() {
// we need to take 2 pointers
// and travel progressively between them ...
var newFirst = [
[].concat(array1Extract[0]),
[].concat(array1Extract[1])
];
var newSecond = [
[].concat(array2Extract[0]),
[].concat(array2Extract[1])
];
var array1L... | javascript | function calculateDiff() {
// we need to take 2 pointers
// and travel progressively between them ...
var newFirst = [
[].concat(array1Extract[0]),
[].concat(array1Extract[1])
];
var newSecond = [
[].concat(array2Extract[0]),
[].concat(array2Extract[1])
];
var array1L... | [
"function",
"calculateDiff",
"(",
")",
"{",
"// we need to take 2 pointers",
"// and travel progressively between them ...",
"var",
"newFirst",
"=",
"[",
"[",
"]",
".",
"concat",
"(",
"array1Extract",
"[",
"0",
"]",
")",
",",
"[",
"]",
".",
"concat",
"(",
"array... | this method calculates the total diff. The sum of positive value will yield to overlap | [
"this",
"method",
"calculates",
"the",
"total",
"diff",
".",
"The",
"sum",
"of",
"positive",
"value",
"will",
"yield",
"to",
"overlap"
] | d1b011072c953458f05d3aa1f18d420a67cf717f | https://github.com/cheminfo-js/peaks-similarity/blob/d1b011072c953458f05d3aa1f18d420a67cf717f/src/index.js#L217-L262 | train |
cheminfo-js/peaks-similarity | src/index.js | commonExtractAndNormalize | function commonExtractAndNormalize(array1, array2, width, from, to, common) {
if (!(Array.isArray(array1)) || !(Array.isArray(array2))) {
return {
info: undefined,
data: undefined
};
}
var extract1 = extract(array1, from, to);
var extract2 = extract(array2, from, to);
var common1, common2,... | javascript | function commonExtractAndNormalize(array1, array2, width, from, to, common) {
if (!(Array.isArray(array1)) || !(Array.isArray(array2))) {
return {
info: undefined,
data: undefined
};
}
var extract1 = extract(array1, from, to);
var extract2 = extract(array2, from, to);
var common1, common2,... | [
"function",
"commonExtractAndNormalize",
"(",
"array1",
",",
"array2",
",",
"width",
",",
"from",
",",
"to",
",",
"common",
")",
"{",
"if",
"(",
"!",
"(",
"Array",
".",
"isArray",
"(",
"array1",
")",
")",
"||",
"!",
"(",
"Array",
".",
"isArray",
"(",... | this method will systematically take care of both array | [
"this",
"method",
"will",
"systematically",
"take",
"care",
"of",
"both",
"array"
] | d1b011072c953458f05d3aa1f18d420a67cf717f | https://github.com/cheminfo-js/peaks-similarity/blob/d1b011072c953458f05d3aa1f18d420a67cf717f/src/index.js#L396-L427 | train |
henrytseng/angular-state-router | src/services/state-router.js | function(nameParams) {
if(nameParams && nameParams.match(/^[a-zA-Z0-9_\.]*\(.*\)$/)) {
var npart = nameParams.substring(0, nameParams.indexOf('('));
var ppart = Parameters( nameParams.substring(nameParams.indexOf('(')+1, nameParams.lastIndexOf(')')) );
return {
name: npart,
params... | javascript | function(nameParams) {
if(nameParams && nameParams.match(/^[a-zA-Z0-9_\.]*\(.*\)$/)) {
var npart = nameParams.substring(0, nameParams.indexOf('('));
var ppart = Parameters( nameParams.substring(nameParams.indexOf('(')+1, nameParams.lastIndexOf(')')) );
return {
name: npart,
params... | [
"function",
"(",
"nameParams",
")",
"{",
"if",
"(",
"nameParams",
"&&",
"nameParams",
".",
"match",
"(",
"/",
"^[a-zA-Z0-9_\\.]*\\(.*\\)$",
"/",
")",
")",
"{",
"var",
"npart",
"=",
"nameParams",
".",
"substring",
"(",
"0",
",",
"nameParams",
".",
"indexOf"... | Parse state notation name-params.
Assume all parameter values are strings
@param {String} nameParams A name-params string
@return {Object} A name string and param Object | [
"Parse",
"state",
"notation",
"name",
"-",
"params",
"."
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L33-L49 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(name) {
name = name || '';
// TODO optimize with RegExp
var nameChain = name.split('.');
for(var i=0; i<nameChain.length; i++) {
if(!nameChain[i].match(/[a-zA-Z0-9_]+/)) {
return false;
}
}
return true;
} | javascript | function(name) {
name = name || '';
// TODO optimize with RegExp
var nameChain = name.split('.');
for(var i=0; i<nameChain.length; i++) {
if(!nameChain[i].match(/[a-zA-Z0-9_]+/)) {
return false;
}
}
return true;
} | [
"function",
"(",
"name",
")",
"{",
"name",
"=",
"name",
"||",
"''",
";",
"// TODO optimize with RegExp",
"var",
"nameChain",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nameChain",
".",
"length",... | Validate state name
@param {String} name A unique identifier for the state; using dot-notation
@return {Boolean} True if name is valid, false if not | [
"Validate",
"state",
"name"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L70-L83 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(query) {
query = query || '';
// TODO optimize with RegExp
var nameChain = query.split('.');
for(var i=0; i<nameChain.length; i++) {
if(!nameChain[i].match(/(\*(\*)?|[a-zA-Z0-9_]+)/)) {
return false;
}
}
return true;
} | javascript | function(query) {
query = query || '';
// TODO optimize with RegExp
var nameChain = query.split('.');
for(var i=0; i<nameChain.length; i++) {
if(!nameChain[i].match(/(\*(\*)?|[a-zA-Z0-9_]+)/)) {
return false;
}
}
return true;
} | [
"function",
"(",
"query",
")",
"{",
"query",
"=",
"query",
"||",
"''",
";",
"// TODO optimize with RegExp",
"var",
"nameChain",
"=",
"query",
".",
"split",
"(",
"'.'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nameChain",
".",
"leng... | Validate state query
@param {String} query A query for the state; using dot-notation
@return {Boolean} True if name is valid, false if not | [
"Validate",
"state",
"query"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L91-L104 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(a, b) {
a = a || {};
b = b || {};
return a.name === b.name && angular.equals(a.params, b.params);
} | javascript | function(a, b) {
a = a || {};
b = b || {};
return a.name === b.name && angular.equals(a.params, b.params);
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"a",
"=",
"a",
"||",
"{",
"}",
";",
"b",
"=",
"b",
"||",
"{",
"}",
";",
"return",
"a",
".",
"name",
"===",
"b",
".",
"name",
"&&",
"angular",
".",
"equals",
"(",
"a",
".",
"params",
",",
"b",
".",... | Compare two states, compares values.
@return {Boolean} True if states are the same, false if states are different | [
"Compare",
"two",
"states",
"compares",
"values",
"."
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L111-L115 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(name) {
var nameList = name.split('.');
return nameList
.map(function(item, i, list) {
return list.slice(0, i+1).join('.');
})
.filter(function(item) {
return item !== null;
});
} | javascript | function(name) {
var nameList = name.split('.');
return nameList
.map(function(item, i, list) {
return list.slice(0, i+1).join('.');
})
.filter(function(item) {
return item !== null;
});
} | [
"function",
"(",
"name",
")",
"{",
"var",
"nameList",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
";",
"return",
"nameList",
".",
"map",
"(",
"function",
"(",
"item",
",",
"i",
",",
"list",
")",
"{",
"return",
"list",
".",
"slice",
"(",
"0",
",",... | Get a list of parent states
@param {String} name A unique identifier for the state; using dot-notation
@return {Array} An Array of parent states | [
"Get",
"a",
"list",
"of",
"parent",
"states"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L123-L133 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(name) {
name = name || '';
var state = null;
// Only use valid state queries
if(!_validateStateName(name)) {
return null;
// Use cache if exists
} else if(_stateCache[name]) {
return _stateCache[name];
}
var nameChain = _getNameChain(name);
var stateChain... | javascript | function(name) {
name = name || '';
var state = null;
// Only use valid state queries
if(!_validateStateName(name)) {
return null;
// Use cache if exists
} else if(_stateCache[name]) {
return _stateCache[name];
}
var nameChain = _getNameChain(name);
var stateChain... | [
"function",
"(",
"name",
")",
"{",
"name",
"=",
"name",
"||",
"''",
";",
"var",
"state",
"=",
"null",
";",
"// Only use valid state queries",
"if",
"(",
"!",
"_validateStateName",
"(",
"name",
")",
")",
"{",
"return",
"null",
";",
"// Use cache if exists",
... | Internal method to crawl library heirarchy
@param {String} name A unique identifier for the state; using state-notation
@return {Object} A state data Object | [
"Internal",
"method",
"to",
"crawl",
"library",
"heirarchy"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L141-L179 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(name, data) {
if(name === null || typeof name === 'undefined') {
throw new Error('Name cannot be null.');
// Only use valid state names
} else if(!_validateStateName(name)) {
throw new Error('Invalid state name.');
}
// Create state
var state = angular.copy(data);
... | javascript | function(name, data) {
if(name === null || typeof name === 'undefined') {
throw new Error('Name cannot be null.');
// Only use valid state names
} else if(!_validateStateName(name)) {
throw new Error('Invalid state name.');
}
// Create state
var state = angular.copy(data);
... | [
"function",
"(",
"name",
",",
"data",
")",
"{",
"if",
"(",
"name",
"===",
"null",
"||",
"typeof",
"name",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Name cannot be null.'",
")",
";",
"// Only use valid state names",
"}",
"else",
"if",
... | Internal method to store a state definition. Parameters should be included in data Object not state name.
@param {String} name A unique identifier for the state; using state-notation
@param {Object} data A state definition data Object
@return {Object} A state data Object | [
"Internal",
"method",
"to",
"store",
"a",
"state",
"definition",
".",
"Parameters",
"should",
"be",
"included",
"in",
"data",
"Object",
"not",
"state",
"name",
"."
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L188-L218 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(data) {
// Keep the last n states (e.g. - defaults 5)
var historyLength = _options.historyLength || 5;
if(data) {
_history.push(data);
}
// Update length
if(_history.length > historyLength) {
_history.splice(0, _history.length - historyLength);
}
... | javascript | function(data) {
// Keep the last n states (e.g. - defaults 5)
var historyLength = _options.historyLength || 5;
if(data) {
_history.push(data);
}
// Update length
if(_history.length > historyLength) {
_history.splice(0, _history.length - historyLength);
}
... | [
"function",
"(",
"data",
")",
"{",
"// Keep the last n states (e.g. - defaults 5)",
"var",
"historyLength",
"=",
"_options",
".",
"historyLength",
"||",
"5",
";",
"if",
"(",
"data",
")",
"{",
"_history",
".",
"push",
"(",
"data",
")",
";",
"}",
"// Update leng... | Internal method to add history and correct length
@param {Object} data An Object | [
"Internal",
"method",
"to",
"add",
"history",
"and",
"correct",
"length"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L290-L302 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(name, params) {
return _changeState(name, params).then(function() {
$rootScope.$broadcast('$stateChangeComplete', null, _current);
}, function(err) {
$rootScope.$broadcast('$stateChangeComplete', err, _current);
});
} | javascript | function(name, params) {
return _changeState(name, params).then(function() {
$rootScope.$broadcast('$stateChangeComplete', null, _current);
}, function(err) {
$rootScope.$broadcast('$stateChangeComplete', err, _current);
});
} | [
"function",
"(",
"name",
",",
"params",
")",
"{",
"return",
"_changeState",
"(",
"name",
",",
"params",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"$rootScope",
".",
"$broadcast",
"(",
"'$stateChangeComplete'",
",",
"null",
",",
"_current",
")",
"... | Internal method to change to state and broadcast completion
@param {String} name A unique identifier for the state; using state-notation including optional parameters
@param {Object} params A data object of params
@return {Promise} A promise fulfilled when state change occurs | [
"Internal",
"method",
"to",
"change",
"to",
"state",
"and",
"broadcast",
"completion"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L414-L420 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function() {
var deferred = $q.defer();
$rootScope.$evalAsync(function() {
var n = _current.name;
var p = angular.copy(_current.params);
if(!_current.params) {
_current.params = {};
}
_current.params.deprecated = true;
// Notify
$rootScope.... | javascript | function() {
var deferred = $q.defer();
$rootScope.$evalAsync(function() {
var n = _current.name;
var p = angular.copy(_current.params);
if(!_current.params) {
_current.params = {};
}
_current.params.deprecated = true;
// Notify
$rootScope.... | [
"function",
"(",
")",
"{",
"var",
"deferred",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"$rootScope",
".",
"$evalAsync",
"(",
"function",
"(",
")",
"{",
"var",
"n",
"=",
"_current",
".",
"name",
";",
"var",
"p",
"=",
"angular",
".",
"copy",
"(",
"_... | Reloads the current state
@return {Promise} A promise fulfilled when state change occurs | [
"Reloads",
"the",
"current",
"state"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L427-L449 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(handler, priority) {
if(typeof handler !== 'function') {
throw new Error('Middleware must be a function.');
}
if(typeof priority !== 'undefined') handler.priority = priority;
_layerList.push(handler);
return _inst;
} | javascript | function(handler, priority) {
if(typeof handler !== 'function') {
throw new Error('Middleware must be a function.');
}
if(typeof priority !== 'undefined') handler.priority = priority;
_layerList.push(handler);
return _inst;
} | [
"function",
"(",
"handler",
",",
"priority",
")",
"{",
"if",
"(",
"typeof",
"handler",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Middleware must be a function.'",
")",
";",
"}",
"if",
"(",
"typeof",
"priority",
"!==",
"'undefined'",
")",... | Internal method to add middleware; called during state transition
@param {Function} handler A callback, function(request, next)
@param {Number} priority A number denoting priority
@return {$state} Itself; chainable | [
"Internal",
"method",
"to",
"add",
"middleware",
";",
"called",
"during",
"state",
"transition"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L496-L504 | train | |
henrytseng/angular-state-router | src/services/state-router.js | function(query, params) {
query = query || '';
// No state
if(!_current) {
return false;
// Use RegExp matching
} else if(query instanceof RegExp) {
return !!_current.name.match(query);
// String; state dot-notation
} else if(typeof ... | javascript | function(query, params) {
query = query || '';
// No state
if(!_current) {
return false;
// Use RegExp matching
} else if(query instanceof RegExp) {
return !!_current.name.match(query);
// String; state dot-notation
} else if(typeof ... | [
"function",
"(",
"query",
",",
"params",
")",
"{",
"query",
"=",
"query",
"||",
"''",
";",
"// No state",
"if",
"(",
"!",
"_current",
")",
"{",
"return",
"false",
";",
"// Use RegExp matching",
"}",
"else",
"if",
"(",
"query",
"instanceof",
"RegExp",
")"... | Check query against current state
@param {Mixed} query A string using state notation or a RegExp
@param {Object} params A parameters data object
@return {Boolean} A true if state is parent to current state | [
"Check",
"query",
"against",
"current",
"state"
] | 5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b | https://github.com/henrytseng/angular-state-router/blob/5b8147d5f5fe8a8e8453dddf61fe0b01fe5b5e9b/src/services/state-router.js#L635-L675 | train | |
bikejs/bike | src/bike.js | support | function support (name) {
try {
return BIKE.require(BIKEname + '-' + name);
}
catch (e) {
return BIKE.require(name);
}
} | javascript | function support (name) {
try {
return BIKE.require(BIKEname + '-' + name);
}
catch (e) {
return BIKE.require(name);
}
} | [
"function",
"support",
"(",
"name",
")",
"{",
"try",
"{",
"return",
"BIKE",
".",
"require",
"(",
"BIKEname",
"+",
"'-'",
"+",
"name",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"BIKE",
".",
"require",
"(",
"name",
")",
";",
"}",
"}"
] | Retreive a submodule
@param {String} name Submodule's name
@return {Mixied} Found object | [
"Retreive",
"a",
"submodule"
] | 90c014b7a2cf8f8b92c945b934db526c2ae7e37c | https://github.com/bikejs/bike/blob/90c014b7a2cf8f8b92c945b934db526c2ae7e37c/src/bike.js#L20-L27 | train |
nodejitsu/contour | pagelets/button.js | define | function define() {
var type = this.data.type || this.defaults.type
, collection = this.collection;
this.data.use = collection[type].class;
this.data.text = this.data.text || collection[type].text;
this.data.href = this.data.href || collection[type].href;
return this;
} | javascript | function define() {
var type = this.data.type || this.defaults.type
, collection = this.collection;
this.data.use = collection[type].class;
this.data.text = this.data.text || collection[type].text;
this.data.href = this.data.href || collection[type].href;
return this;
} | [
"function",
"define",
"(",
")",
"{",
"var",
"type",
"=",
"this",
".",
"data",
".",
"type",
"||",
"this",
".",
"defaults",
".",
"type",
",",
"collection",
"=",
"this",
".",
"collection",
";",
"this",
".",
"data",
".",
"use",
"=",
"collection",
"[",
... | Define the class and text that are on the button. Called by set on default.
@returns {Pagelet}
@api private | [
"Define",
"the",
"class",
"and",
"text",
"that",
"are",
"on",
"the",
"button",
".",
"Called",
"by",
"set",
"on",
"default",
"."
] | 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/button.js#L62-L71 | train |
chapmanu/hb | lib/services/wordpress/stream.js | function(service, credentials, accounts, keywords) {
Stream.call(this, service, credentials, accounts, keywords);
// Initialize responder
this.responder = new Responder();
} | javascript | function(service, credentials, accounts, keywords) {
Stream.call(this, service, credentials, accounts, keywords);
// Initialize responder
this.responder = new Responder();
} | [
"function",
"(",
"service",
",",
"credentials",
",",
"accounts",
",",
"keywords",
")",
"{",
"Stream",
".",
"call",
"(",
"this",
",",
"service",
",",
"credentials",
",",
"accounts",
",",
"keywords",
")",
";",
"// Initialize responder",
"this",
".",
"responder... | Manages the streaming connection to Wordpress
@constructor
@extends Stream | [
"Manages",
"the",
"streaming",
"connection",
"to",
"Wordpress"
] | 5edd8de89c7c5fdffc3df0c627513889220f7d51 | https://github.com/chapmanu/hb/blob/5edd8de89c7c5fdffc3df0c627513889220f7d51/lib/services/wordpress/stream.js#L13-L19 | train | |
feilaoda/power | public/javascripts/vendor/javascripts/moment.js | getLangDefinition | function getLangDefinition(m) {
var langKey = (typeof m === 'string') && m ||
m && m._lang ||
null;
return langKey ? (languages[langKey] || loadLang(langKey)) : moment;
} | javascript | function getLangDefinition(m) {
var langKey = (typeof m === 'string') && m ||
m && m._lang ||
null;
return langKey ? (languages[langKey] || loadLang(langKey)) : moment;
} | [
"function",
"getLangDefinition",
"(",
"m",
")",
"{",
"var",
"langKey",
"=",
"(",
"typeof",
"m",
"===",
"'string'",
")",
"&&",
"m",
"||",
"m",
"&&",
"m",
".",
"_lang",
"||",
"null",
";",
"return",
"langKey",
"?",
"(",
"languages",
"[",
"langKey",
"]",... | Determines which language definition to use and returns it. With no parameters, it will return the global language. If you pass in a language key, such as 'en', it will return the definition for 'en', so long as 'en' has already been loaded using moment.lang. If you pass in a moment or duration instance, it will dec... | [
"Determines",
"which",
"language",
"definition",
"to",
"use",
"and",
"returns",
"it",
".",
"With",
"no",
"parameters",
"it",
"will",
"return",
"the",
"global",
"language",
".",
"If",
"you",
"pass",
"in",
"a",
"language",
"key",
"such",
"as",
"en",
"it",
... | 89432e5b8e455eceef5f5098d479ad94c88acc59 | https://github.com/feilaoda/power/blob/89432e5b8e455eceef5f5098d479ad94c88acc59/public/javascripts/vendor/javascripts/moment.js#L414-L420 | train |
godaddy/node-gd-assets | lib/config.js | _flatten | function _flatten(groups, groupName, alreadySeen)
{
alreadySeen = alreadySeen || [];
var ret = {};
// Intialize each key to empty so we don't have to check if they exist later
HANDLER_KEYS.forEach(function(key) {
ret[key] = [];
});
var thisGroup = groups[groupName];
if ( !thisGroup )
throw new ... | javascript | function _flatten(groups, groupName, alreadySeen)
{
alreadySeen = alreadySeen || [];
var ret = {};
// Intialize each key to empty so we don't have to check if they exist later
HANDLER_KEYS.forEach(function(key) {
ret[key] = [];
});
var thisGroup = groups[groupName];
if ( !thisGroup )
throw new ... | [
"function",
"_flatten",
"(",
"groups",
",",
"groupName",
",",
"alreadySeen",
")",
"{",
"alreadySeen",
"=",
"alreadySeen",
"||",
"[",
"]",
";",
"var",
"ret",
"=",
"{",
"}",
";",
"// Intialize each key to empty so we don't have to check if they exist later",
"HANDLER_KE... | Flatten a single group into a list of files required for it | [
"Flatten",
"a",
"single",
"group",
"into",
"a",
"list",
"of",
"files",
"required",
"for",
"it"
] | 14723940592090855b95ea5d20abe6291f1a5696 | https://github.com/godaddy/node-gd-assets/blob/14723940592090855b95ea5d20abe6291f1a5696/lib/config.js#L117-L168 | train |
godaddy/node-gd-assets | lib/config.js | resolveFile | function resolveFile(baseDirs, addType, fileName, type, cb)
{
// The label this file will have in the output
// For hbs views, this is the name that it will be save as into the template array.
var label = pathlib.basename(fileName);
// Label can be overridden with entries of the form: "label:file-name-or-path"... | javascript | function resolveFile(baseDirs, addType, fileName, type, cb)
{
// The label this file will have in the output
// For hbs views, this is the name that it will be save as into the template array.
var label = pathlib.basename(fileName);
// Label can be overridden with entries of the form: "label:file-name-or-path"... | [
"function",
"resolveFile",
"(",
"baseDirs",
",",
"addType",
",",
"fileName",
",",
"type",
",",
"cb",
")",
"{",
"// The label this file will have in the output",
"// For hbs views, this is the name that it will be save as into the template array.",
"var",
"label",
"=",
"pathlib"... | Resolve a file name into an absolute path Async if called with a cb, synchronous if not | [
"Resolve",
"a",
"file",
"name",
"into",
"an",
"absolute",
"path",
"Async",
"if",
"called",
"with",
"a",
"cb",
"synchronous",
"if",
"not"
] | 14723940592090855b95ea5d20abe6291f1a5696 | https://github.com/godaddy/node-gd-assets/blob/14723940592090855b95ea5d20abe6291f1a5696/lib/config.js#L184-L242 | train |
Krinkle/node-colorfactory | src/ColorHelper.js | makeStrProtoFn | function makeStrProtoFn(method) {
return function () {
// Convert `arguments` into an array (usually empty or has 1 parameter)
var args = slice.call(arguments, 0);
// Add the current string as the first argument
args.unshift(this);
return ColorHelper[method].apply(ColorHelper, args);
};
} | javascript | function makeStrProtoFn(method) {
return function () {
// Convert `arguments` into an array (usually empty or has 1 parameter)
var args = slice.call(arguments, 0);
// Add the current string as the first argument
args.unshift(this);
return ColorHelper[method].apply(ColorHelper, args);
};
} | [
"function",
"makeStrProtoFn",
"(",
"method",
")",
"{",
"return",
"function",
"(",
")",
"{",
"// Convert `arguments` into an array (usually empty or has 1 parameter)",
"var",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"// Add the current s... | Can't be used inline in the for-loop, because of variable scope.
Otherwise all methods would be pointing to the method as put in
the variable that lives on until after the loop itself. | [
"Can",
"t",
"be",
"used",
"inline",
"in",
"the",
"for",
"-",
"loop",
"because",
"of",
"variable",
"scope",
".",
"Otherwise",
"all",
"methods",
"would",
"be",
"pointing",
"to",
"the",
"method",
"as",
"put",
"in",
"the",
"variable",
"that",
"lives",
"on",
... | 4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0 | https://github.com/Krinkle/node-colorfactory/blob/4c9cec8f3f8e95a3fa402233ceef2dd9c2b040b0/src/ColorHelper.js#L208-L216 | train |
naomiaro/fade-curves | index.js | sCurve | function sCurve(length, rotation) {
var curve = new Float32Array(length),
i,
phase = rotation > 0 ? Math.PI / 2 : -(Math.PI / 2);
for (i = 0; i < length; ++i) {
curve[i] = Math.sin(Math.PI * i / length - phase) / 2 + 0.5;
}
return curve;
} | javascript | function sCurve(length, rotation) {
var curve = new Float32Array(length),
i,
phase = rotation > 0 ? Math.PI / 2 : -(Math.PI / 2);
for (i = 0; i < length; ++i) {
curve[i] = Math.sin(Math.PI * i / length - phase) / 2 + 0.5;
}
return curve;
} | [
"function",
"sCurve",
"(",
"length",
",",
"rotation",
")",
"{",
"var",
"curve",
"=",
"new",
"Float32Array",
"(",
"length",
")",
",",
"i",
",",
"phase",
"=",
"rotation",
">",
"0",
"?",
"Math",
".",
"PI",
"/",
"2",
":",
"-",
"(",
"Math",
".",
"PI",... | creating a curve to simulate an S-curve with setValueCurveAtTime. | [
"creating",
"a",
"curve",
"to",
"simulate",
"an",
"S",
"-",
"curve",
"with",
"setValueCurveAtTime",
"."
] | 795ed73fe0cbc110287c2d48a01afdb6b4a49512 | https://github.com/naomiaro/fade-curves/blob/795ed73fe0cbc110287c2d48a01afdb6b4a49512/index.js#L47-L56 | train |
naomiaro/fade-curves | index.js | logarithmic | function logarithmic(length, base, rotation) {
var curve = new Float32Array(length),
index,
x = 0,
i;
for (i = 0; i < length; i++) {
//index for the curve array.
index = rotation > 0 ? i : length - 1 - i;
x = i / length;
curve[index] = Math.log(1 + base ... | javascript | function logarithmic(length, base, rotation) {
var curve = new Float32Array(length),
index,
x = 0,
i;
for (i = 0; i < length; i++) {
//index for the curve array.
index = rotation > 0 ? i : length - 1 - i;
x = i / length;
curve[index] = Math.log(1 + base ... | [
"function",
"logarithmic",
"(",
"length",
",",
"base",
",",
"rotation",
")",
"{",
"var",
"curve",
"=",
"new",
"Float32Array",
"(",
"length",
")",
",",
"index",
",",
"x",
"=",
"0",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",... | creating a curve to simulate a logarithmic curve with setValueCurveAtTime. | [
"creating",
"a",
"curve",
"to",
"simulate",
"a",
"logarithmic",
"curve",
"with",
"setValueCurveAtTime",
"."
] | 795ed73fe0cbc110287c2d48a01afdb6b4a49512 | https://github.com/naomiaro/fade-curves/blob/795ed73fe0cbc110287c2d48a01afdb6b4a49512/index.js#L59-L74 | train |
imjching/node-hackerearth | lib/hackerearth/HackerEarthAPI.js | HackerEarthAPI | function HackerEarthAPI (clientSecretKey, options) {
if (typeof clientSecretKey != 'string') {
clientSecretKey = null;
options = clientSecretKey;
}
if (!options) {
options = {};
}
if (!clientSecretKey) {
throw new Error('You have to provide a client secret key for this to work. If you do not ... | javascript | function HackerEarthAPI (clientSecretKey, options) {
if (typeof clientSecretKey != 'string') {
clientSecretKey = null;
options = clientSecretKey;
}
if (!options) {
options = {};
}
if (!clientSecretKey) {
throw new Error('You have to provide a client secret key for this to work. If you do not ... | [
"function",
"HackerEarthAPI",
"(",
"clientSecretKey",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"clientSecretKey",
"!=",
"'string'",
")",
"{",
"clientSecretKey",
"=",
"null",
";",
"options",
"=",
"clientSecretKey",
";",
"}",
"if",
"(",
"!",
"options",
"... | Returns a HackerEarth API wrapper object of the specified version. Currently,
only version 3 is supported by this wrapper as HackerEarth has already discontinued
version 2.
Available options are:
- version The API version to use (2, 3). Defaults to 3.
@param clientSecretKey The client secret key to access the Hacker... | [
"Returns",
"a",
"HackerEarth",
"API",
"wrapper",
"object",
"of",
"the",
"specified",
"version",
".",
"Currently",
"only",
"version",
"3",
"is",
"supported",
"by",
"this",
"wrapper",
"as",
"HackerEarth",
"has",
"already",
"discontinued",
"version",
"2",
"."
] | 62354fd8af0fa82b4dcecce96bf4c09ba24826e4 | https://github.com/imjching/node-hackerearth/blob/62354fd8af0fa82b4dcecce96bf4c09ba24826e4/lib/hackerearth/HackerEarthAPI.js#L16-L41 | train |
styonsk/elmongoose | lib/elmongoose.js | unindex | function unindex (options) {
var self = this
var unindexUri = helpers.makeDocumentUri(options, self)
// console.log('unindex:', unindexUri)
var reqOpts = {
method: 'DELETE',
url: unindexUri
}
if(options.auth) {
reqOpts.auth = {
user: options.auth.user,
... | javascript | function unindex (options) {
var self = this
var unindexUri = helpers.makeDocumentUri(options, self)
// console.log('unindex:', unindexUri)
var reqOpts = {
method: 'DELETE',
url: unindexUri
}
if(options.auth) {
reqOpts.auth = {
user: options.auth.user,
... | [
"function",
"unindex",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"unindexUri",
"=",
"helpers",
".",
"makeDocumentUri",
"(",
"options",
",",
"self",
")",
"// console.log('unindex:', unindexUri)",
"var",
"reqOpts",
"=",
"{",
"method",
":",
"'D... | Remove a document from elasticsearch
@param {Object} options elasticsearch options object. Keys: host, port, index, type | [
"Remove",
"a",
"document",
"from",
"elasticsearch"
] | b83f7dd67330c7288e7f17866d3e67f12a2adc1d | https://github.com/styonsk/elmongoose/blob/b83f7dd67330c7288e7f17866d3e67f12a2adc1d/lib/elmongoose.js#L165-L197 | train |
jonschlinkert/engine-cache | index.js | normalizeEngine | function normalizeEngine(fn, options) {
if (utils.isEngine(options)) {
return normalizeEngine(options, fn); //<= reverse args
}
if (!isObject(fn) && typeof fn !== 'function') {
throw new TypeError('expected an object or function');
}
var engine = {};
engine.render = fn.render || fn;
engine.optio... | javascript | function normalizeEngine(fn, options) {
if (utils.isEngine(options)) {
return normalizeEngine(options, fn); //<= reverse args
}
if (!isObject(fn) && typeof fn !== 'function') {
throw new TypeError('expected an object or function');
}
var engine = {};
engine.render = fn.render || fn;
engine.optio... | [
"function",
"normalizeEngine",
"(",
"fn",
",",
"options",
")",
"{",
"if",
"(",
"utils",
".",
"isEngine",
"(",
"options",
")",
")",
"{",
"return",
"normalizeEngine",
"(",
"options",
",",
"fn",
")",
";",
"//<= reverse args",
"}",
"if",
"(",
"!",
"isObject"... | Normalize engine so that `.render` is a property on the `engine` object. | [
"Normalize",
"engine",
"so",
"that",
".",
"render",
"is",
"a",
"property",
"on",
"the",
"engine",
"object",
"."
] | 9df4c7e7abcbbed76fda79f354f040f2c68cb670 | https://github.com/jonschlinkert/engine-cache/blob/9df4c7e7abcbbed76fda79f354f040f2c68cb670/index.js#L151-L183 | train |
jonschlinkert/engine-cache | index.js | inspect | function inspect(engine) {
var inspect = ['"' + engine.name + '"'];
var exts = utils.arrayify(engine.options.ext).join(', ');
inspect.push('<ext "' + exts + '">');
engine.inspect = function() {
return '<Engine ' + inspect.join(' ') + '>';
};
} | javascript | function inspect(engine) {
var inspect = ['"' + engine.name + '"'];
var exts = utils.arrayify(engine.options.ext).join(', ');
inspect.push('<ext "' + exts + '">');
engine.inspect = function() {
return '<Engine ' + inspect.join(' ') + '>';
};
} | [
"function",
"inspect",
"(",
"engine",
")",
"{",
"var",
"inspect",
"=",
"[",
"'\"'",
"+",
"engine",
".",
"name",
"+",
"'\"'",
"]",
";",
"var",
"exts",
"=",
"utils",
".",
"arrayify",
"(",
"engine",
".",
"options",
".",
"ext",
")",
".",
"join",
"(",
... | Add a custom inspect function onto the engine. | [
"Add",
"a",
"custom",
"inspect",
"function",
"onto",
"the",
"engine",
"."
] | 9df4c7e7abcbbed76fda79f354f040f2c68cb670 | https://github.com/jonschlinkert/engine-cache/blob/9df4c7e7abcbbed76fda79f354f040f2c68cb670/index.js#L360-L367 | train |
jonschlinkert/engine-cache | index.js | mergeHelpers | function mergeHelpers(engine, options) {
if (!options || typeof options !== 'object') {
throw new TypeError('expected an object');
}
var opts = extend({}, options);
var helpers = merge({}, engine.helpers.cache, opts.helpers);
var keys = Object.keys(helpers);
for (var i = 0; i < keys.length; i++) {
... | javascript | function mergeHelpers(engine, options) {
if (!options || typeof options !== 'object') {
throw new TypeError('expected an object');
}
var opts = extend({}, options);
var helpers = merge({}, engine.helpers.cache, opts.helpers);
var keys = Object.keys(helpers);
for (var i = 0; i < keys.length; i++) {
... | [
"function",
"mergeHelpers",
"(",
"engine",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
"||",
"typeof",
"options",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected an object'",
")",
";",
"}",
"var",
"opts",
"=",
"extend",
... | Merge the local engine helpers with the options helpers.
@param {Object} `options` Options passed into `render` or `compile`
@return {Object} Options object with merged helpers | [
"Merge",
"the",
"local",
"engine",
"helpers",
"with",
"the",
"options",
"helpers",
"."
] | 9df4c7e7abcbbed76fda79f354f040f2c68cb670 | https://github.com/jonschlinkert/engine-cache/blob/9df4c7e7abcbbed76fda79f354f040f2c68cb670/index.js#L376-L391 | train |
vadr-vr/VR-Analytics-JSCore | js/dataManager/dataManager.js | init | function init(){
eventDataPairs = 0;
currentSession = sessionManager.createSession();
lastRequestTime = utils.getUnixTimeInSeconds();
mediaPlaying = false;
// checks if time since last request has exceeded the maximum request time
if (timeSinceRequestChecker){
clearInterval(timeSinceR... | javascript | function init(){
eventDataPairs = 0;
currentSession = sessionManager.createSession();
lastRequestTime = utils.getUnixTimeInSeconds();
mediaPlaying = false;
// checks if time since last request has exceeded the maximum request time
if (timeSinceRequestChecker){
clearInterval(timeSinceR... | [
"function",
"init",
"(",
")",
"{",
"eventDataPairs",
"=",
"0",
";",
"currentSession",
"=",
"sessionManager",
".",
"createSession",
"(",
")",
";",
"lastRequestTime",
"=",
"utils",
".",
"getUnixTimeInSeconds",
"(",
")",
";",
"mediaPlaying",
"=",
"false",
";",
... | Init the collection of data
@memberof DataManager | [
"Init",
"the",
"collection",
"of",
"data"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/dataManager/dataManager.js#L29-L55 | train |
vadr-vr/VR-Analytics-JSCore | js/dataManager/dataManager.js | addScene | function addScene(sceneId, sceneName){
if (!sceneId && !sceneName){
logger.warn('SceneId or SceneName is required to starting a new scene session. Aborting');
return;
}
// close any previous media
if (mediaPlaying)
closeMedia();
currentSession.addScene(sceneId, s... | javascript | function addScene(sceneId, sceneName){
if (!sceneId && !sceneName){
logger.warn('SceneId or SceneName is required to starting a new scene session. Aborting');
return;
}
// close any previous media
if (mediaPlaying)
closeMedia();
currentSession.addScene(sceneId, s... | [
"function",
"addScene",
"(",
"sceneId",
",",
"sceneName",
")",
"{",
"if",
"(",
"!",
"sceneId",
"&&",
"!",
"sceneName",
")",
"{",
"logger",
".",
"warn",
"(",
"'SceneId or SceneName is required to starting a new scene session. Aborting'",
")",
";",
"return",
";",
"}... | Functions related to creating and deleting scene sessions and media sessions
create scene session
@memberof DataManager
@param {string} sceneId id of the new scene [optional - either this or sceneName]
@param {string} sceneName name of the new scene [optional - either this or sceneId] | [
"Functions",
"related",
"to",
"creating",
"and",
"deleting",
"scene",
"sessions",
"and",
"media",
"sessions",
"create",
"scene",
"session"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/dataManager/dataManager.js#L75-L90 | train |
vadr-vr/VR-Analytics-JSCore | js/dataManager/dataManager.js | addMedia | function addMedia(mediaId, name, type, url){
// close any previous media
if (mediaPlaying)
closeMedia();
if (type != enums.media360.video && type != enums.media360.image){
logger.warn('Media type not supported. Aborting addind media.');
return;
}
if (type... | javascript | function addMedia(mediaId, name, type, url){
// close any previous media
if (mediaPlaying)
closeMedia();
if (type != enums.media360.video && type != enums.media360.image){
logger.warn('Media type not supported. Aborting addind media.');
return;
}
if (type... | [
"function",
"addMedia",
"(",
"mediaId",
",",
"name",
",",
"type",
",",
"url",
")",
"{",
"// close any previous media",
"if",
"(",
"mediaPlaying",
")",
"closeMedia",
"(",
")",
";",
"if",
"(",
"type",
"!=",
"enums",
".",
"media360",
".",
"video",
"&&",
"ty... | Adds media to the media list
@memberof DataManager
@param {string} mediaId Developer defined mediaId for the media
@param {string} name Media name to be displayed to the analytics user
@param {number} type Type of media 1 - Video, 2 - Photo
@param {string} url Url for the media [optional] | [
"Adds",
"media",
"to",
"the",
"media",
"list"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/dataManager/dataManager.js#L115-L137 | train |
vadr-vr/VR-Analytics-JSCore | js/dataManager/dataManager.js | registerEvent | function registerEvent(eventName, position, extra){
currentSession.registerEvent(eventName, position, extra);
// check size of events and handle making request
_checkDataPairs();
} | javascript | function registerEvent(eventName, position, extra){
currentSession.registerEvent(eventName, position, extra);
// check size of events and handle making request
_checkDataPairs();
} | [
"function",
"registerEvent",
"(",
"eventName",
",",
"position",
",",
"extra",
")",
"{",
"currentSession",
".",
"registerEvent",
"(",
"eventName",
",",
"position",
",",
"extra",
")",
";",
"// check size of events and handle making request",
"_checkDataPairs",
"(",
")",... | Adds event to event list of media if it exists, else to its own events list
@memberof DataManager
@param {string} eventName name of the event
@param {string} position 3D position associated with the event
@param {object} extra extra information and filter key-value pairs in the event | [
"Adds",
"event",
"to",
"event",
"list",
"of",
"media",
"if",
"it",
"exists",
"else",
"to",
"its",
"own",
"events",
"list"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/dataManager/dataManager.js#L212-L219 | train |
vadr-vr/VR-Analytics-JSCore | js/dataManager/dataManager.js | _createDataRequest | function _createDataRequest(){
logger.info('Creating data request');
eventDataPairs = 0;
const currentSessionData = currentSession.getDictionary();
serverRequestManager.addDataRequest(currentSessionData);
currentSession = currentSession.getDuplicate();
lastRequestTime = utils.getUnixTimeIn... | javascript | function _createDataRequest(){
logger.info('Creating data request');
eventDataPairs = 0;
const currentSessionData = currentSession.getDictionary();
serverRequestManager.addDataRequest(currentSessionData);
currentSession = currentSession.getDuplicate();
lastRequestTime = utils.getUnixTimeIn... | [
"function",
"_createDataRequest",
"(",
")",
"{",
"logger",
".",
"info",
"(",
"'Creating data request'",
")",
";",
"eventDataPairs",
"=",
"0",
";",
"const",
"currentSessionData",
"=",
"currentSession",
".",
"getDictionary",
"(",
")",
";",
"serverRequestManager",
".... | list all the private functions
Pushes the stored data till now to request manager, clears the session data
@memberof DataManager
@private | [
"list",
"all",
"the",
"private",
"functions",
"Pushes",
"the",
"stored",
"data",
"till",
"now",
"to",
"request",
"manager",
"clears",
"the",
"session",
"data"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/dataManager/dataManager.js#L246-L257 | train |
atd-schubert/node-tor-relay | relay.js | function () {
return crypto.createHash('sha1')
.update(Date.now().toString() + Math.random().toString())
.digest('hex');
} | javascript | function () {
return crypto.createHash('sha1')
.update(Date.now().toString() + Math.random().toString())
.digest('hex');
} | [
"function",
"(",
")",
"{",
"return",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
".",
"update",
"(",
"Date",
".",
"now",
"(",
")",
".",
"toString",
"(",
")",
"+",
"Math",
".",
"random",
"(",
")",
".",
"toString",
"(",
")",
")",
".",
"digest"... | Create random credentials
@private
@returns {*} | [
"Create",
"random",
"credentials"
] | 816a9ca623dffe5b51f9b41b070a0404deb2897f | https://github.com/atd-schubert/node-tor-relay/blob/816a9ca623dffe5b51f9b41b070a0404deb2897f/relay.js#L18-L22 | train | |
atd-schubert/node-tor-relay | relay.js | TorRelay | function TorRelay(opts) {
var self = this;
opts = opts || {};
if (!opts.hasOwnProperty('autoCredentials')) {
opts.autoCredentials = true;
}
this.dataDirectory = opts.dataDirectory || null;
if (!opts.hasOwnProperty('cleanUpOnExit')) {
this.cleanUpOnExit = true;
} else {
... | javascript | function TorRelay(opts) {
var self = this;
opts = opts || {};
if (!opts.hasOwnProperty('autoCredentials')) {
opts.autoCredentials = true;
}
this.dataDirectory = opts.dataDirectory || null;
if (!opts.hasOwnProperty('cleanUpOnExit')) {
this.cleanUpOnExit = true;
} else {
... | [
"function",
"TorRelay",
"(",
"opts",
")",
"{",
"var",
"self",
"=",
"this",
";",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"hasOwnProperty",
"(",
"'autoCredentials'",
")",
")",
"{",
"opts",
".",
"autoCredentials",
"=",
"tr... | Relay class for tor relays
@param {{}} [opts] - Options for relay
@param {boolean} [opts.autoCredentials] - Automatically create credentials
@param {boolean} [opts.cleanUpOnExit=true] - Remove temporary dir an close unused child-processes on exit
@param {string} [opts.dataDirectory] - Specify a directory to store tor d... | [
"Relay",
"class",
"for",
"tor",
"relays"
] | 816a9ca623dffe5b51f9b41b070a0404deb2897f | https://github.com/atd-schubert/node-tor-relay/blob/816a9ca623dffe5b51f9b41b070a0404deb2897f/relay.js#L39-L92 | train |
atd-schubert/node-tor-relay | relay.js | restartRelay | function restartRelay(cb) {
var self = this;
this.stop(function (err) {
if (err) {
return cb(err);
}
self.start(cb);
});
} | javascript | function restartRelay(cb) {
var self = this;
this.stop(function (err) {
if (err) {
return cb(err);
}
self.start(cb);
});
} | [
"function",
"restartRelay",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"stop",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"self",
".",
"start",
"(",
"cb"... | Stop and start relay
@param {TorRelay~startCallback} cb | [
"Stop",
"and",
"start",
"relay"
] | 816a9ca623dffe5b51f9b41b070a0404deb2897f | https://github.com/atd-schubert/node-tor-relay/blob/816a9ca623dffe5b51f9b41b070a0404deb2897f/relay.js#L309-L317 | train |
ExclamationLabs/sevr-cli | lib/manage/commands/find.js | function(doc, fields) {
return Object.keys(fields).reduce((prev, key) => {
let val
if (fields[key].hasOwnProperty('referenceCollection')) {
const displayField = fields[key].referenceCollection.defaultField
if (Array.isArray(doc[key])) {
val = doc[key].map(data => {
return data[displayField]
})... | javascript | function(doc, fields) {
return Object.keys(fields).reduce((prev, key) => {
let val
if (fields[key].hasOwnProperty('referenceCollection')) {
const displayField = fields[key].referenceCollection.defaultField
if (Array.isArray(doc[key])) {
val = doc[key].map(data => {
return data[displayField]
})... | [
"function",
"(",
"doc",
",",
"fields",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"fields",
")",
".",
"reduce",
"(",
"(",
"prev",
",",
"key",
")",
"=>",
"{",
"let",
"val",
"if",
"(",
"fields",
"[",
"key",
"]",
".",
"hasOwnProperty",
"(",
"'r... | Replace populated fields with only the default field value
@param {Object} doc
@param {Object} fields
@return {Object} | [
"Replace",
"populated",
"fields",
"with",
"only",
"the",
"default",
"field",
"value"
] | a528cfd534d382fe17fcc50fe21664a01bef9e89 | https://github.com/ExclamationLabs/sevr-cli/blob/a528cfd534d382fe17fcc50fe21664a01bef9e89/lib/manage/commands/find.js#L66-L87 | train | |
ExclamationLabs/sevr-cli | lib/manage/commands/find.js | function(doc, def, labelTemplate) {
return Object.keys(doc)
.map(key => {
const field = doc[key]
const fieldDef = def[key]
if (!field || (!fieldDef && key != '_id')) {
return null
}
const name = key == '_id' ? 'id' : fieldDef.label
const template = labelTemplate || '%s'
const label = util.... | javascript | function(doc, def, labelTemplate) {
return Object.keys(doc)
.map(key => {
const field = doc[key]
const fieldDef = def[key]
if (!field || (!fieldDef && key != '_id')) {
return null
}
const name = key == '_id' ? 'id' : fieldDef.label
const template = labelTemplate || '%s'
const label = util.... | [
"function",
"(",
"doc",
",",
"def",
",",
"labelTemplate",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"doc",
")",
".",
"map",
"(",
"key",
"=>",
"{",
"const",
"field",
"=",
"doc",
"[",
"key",
"]",
"const",
"fieldDef",
"=",
"def",
"[",
"key",
"... | Get the string representation of the document
@param {Object} doc
@param {Object} def
@param {String} [labelTemplate='%s']
@return {String} | [
"Get",
"the",
"string",
"representation",
"of",
"the",
"document"
] | a528cfd534d382fe17fcc50fe21664a01bef9e89 | https://github.com/ExclamationLabs/sevr-cli/blob/a528cfd534d382fe17fcc50fe21664a01bef9e89/lib/manage/commands/find.js#L96-L119 | train | |
SpoonX/typer | index.js | function (value) {
value += '';
if (value.search(/^\-?\d+$/) > -1) {
return 'integer';
}
if (value.search(/^\-?\d+\.\d+[\d.]*$/) > -1) {
return 'float';
}
if ('false' === value || 'true' === value) {
return 'boolean';
}
if (value.search(/^\d{4}\-\d{2}\-\d{2}T\d{2}:\... | javascript | function (value) {
value += '';
if (value.search(/^\-?\d+$/) > -1) {
return 'integer';
}
if (value.search(/^\-?\d+\.\d+[\d.]*$/) > -1) {
return 'float';
}
if ('false' === value || 'true' === value) {
return 'boolean';
}
if (value.search(/^\d{4}\-\d{2}\-\d{2}T\d{2}:\... | [
"function",
"(",
"value",
")",
"{",
"value",
"+=",
"''",
";",
"if",
"(",
"value",
".",
"search",
"(",
"/",
"^\\-?\\d+$",
"/",
")",
">",
"-",
"1",
")",
"{",
"return",
"'integer'",
";",
"}",
"if",
"(",
"value",
".",
"search",
"(",
"/",
"^\\-?\\d+\\... | Detect the type of `value`. Returns 'integer', 'float', 'boolean' or 'string'; defaults to 'string'.
@param {*} value
@returns {String} | [
"Detect",
"the",
"type",
"of",
"value",
".",
"Returns",
"integer",
"float",
"boolean",
"or",
"string",
";",
"defaults",
"to",
"string",
"."
] | d949e57d70f195b534f0f5632791e861404b47de | https://github.com/SpoonX/typer/blob/d949e57d70f195b534f0f5632791e861404b47de/index.js#L9-L29 | train | |
SpoonX/typer | index.js | function (value, type) {
type = type || 'smart';
switch (type) {
case 'boolean':
case 'bool':
if (typeof value !== 'string') {
value = !!value;
} else {
value = ['null', 'undefined', '0', 'false'].indexOf(value) === -1;
}
break;
case 'stri... | javascript | function (value, type) {
type = type || 'smart';
switch (type) {
case 'boolean':
case 'bool':
if (typeof value !== 'string') {
value = !!value;
} else {
value = ['null', 'undefined', '0', 'false'].indexOf(value) === -1;
}
break;
case 'stri... | [
"function",
"(",
"value",
",",
"type",
")",
"{",
"type",
"=",
"type",
"||",
"'smart'",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"'boolean'",
":",
"case",
"'bool'",
":",
"if",
"(",
"typeof",
"value",
"!==",
"'string'",
")",
"{",
"value",
"=",
"... | Cast `value` to given `type`.
@param {*} value
@param {String} [type]
@returns {*} | [
"Cast",
"value",
"to",
"given",
"type",
"."
] | d949e57d70f195b534f0f5632791e861404b47de | https://github.com/SpoonX/typer/blob/d949e57d70f195b534f0f5632791e861404b47de/index.js#L39-L82 | train | |
tensor5/JSLinter | lib/jslint.js | next_line | function next_line() {
// Put the next line of source in source_line. If the line contains tabs,
// replace them with spaces and give a warning. Also warn if the line contains
// unsafe characters or is too damn long.
let at;
column = 0;
line += 1;
source_line = lines[l... | javascript | function next_line() {
// Put the next line of source in source_line. If the line contains tabs,
// replace them with spaces and give a warning. Also warn if the line contains
// unsafe characters or is too damn long.
let at;
column = 0;
line += 1;
source_line = lines[l... | [
"function",
"next_line",
"(",
")",
"{",
"// Put the next line of source in source_line. If the line contains tabs,",
"// replace them with spaces and give a warning. Also warn if the line contains",
"// unsafe characters or is too damn long.",
"let",
"at",
";",
"column",
"=",
"0",
";",
... | the current line source string | [
"the",
"current",
"line",
"source",
"string"
] | de21e3a5c790ecc4a7373ab86a9bef479453834d | https://github.com/tensor5/JSLinter/blob/de21e3a5c790ecc4a7373ab86a9bef479453834d/lib/jslint.js#L633-L671 | train |
tensor5/JSLinter | lib/jslint.js | enroll | function enroll(name, role, readonly) {
// Enroll a name into the current function context. The role can be exception,
// function, label, parameter, or variable. We look for variable redefinition
// because it causes confusion.
const id = name.id;
// Reserved words may not be enrolled.
if (syntax[i... | javascript | function enroll(name, role, readonly) {
// Enroll a name into the current function context. The role can be exception,
// function, label, parameter, or variable. We look for variable redefinition
// because it causes confusion.
const id = name.id;
// Reserved words may not be enrolled.
if (syntax[i... | [
"function",
"enroll",
"(",
"name",
",",
"role",
",",
"readonly",
")",
"{",
"// Enroll a name into the current function context. The role can be exception,",
"// function, label, parameter, or variable. We look for variable redefinition",
"// because it causes confusion.",
"const",
"id",
... | Now we parse JavaScript. | [
"Now",
"we",
"parse",
"JavaScript",
"."
] | de21e3a5c790ecc4a7373ab86a9bef479453834d | https://github.com/tensor5/JSLinter/blob/de21e3a5c790ecc4a7373ab86a9bef479453834d/lib/jslint.js#L1788-L1857 | train |
vid/SenseBase | services/annotators/annotationSet.js | setAnnotationSets | function setAnnotationSets(sets) {
annotationSets = sets.map(function(s) {
var r = '\\b(' + s.terms.join('|') + ')\\b';
s.re = new RegExp(r, 'mi');
return s;
});
} | javascript | function setAnnotationSets(sets) {
annotationSets = sets.map(function(s) {
var r = '\\b(' + s.terms.join('|') + ')\\b';
s.re = new RegExp(r, 'mi');
return s;
});
} | [
"function",
"setAnnotationSets",
"(",
"sets",
")",
"{",
"annotationSets",
"=",
"sets",
".",
"map",
"(",
"function",
"(",
"s",
")",
"{",
"var",
"r",
"=",
"'\\\\b('",
"+",
"s",
".",
"terms",
".",
"join",
"(",
"'|'",
")",
"+",
"')\\\\b'",
";",
"s",
".... | configure with these annotation sets | [
"configure",
"with",
"these",
"annotation",
"sets"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/services/annotators/annotationSet.js#L29-L35 | train |
imbo/imboclient-js-metadata | index.js | buildQuery | function buildQuery(opts, globalSearch) {
var imboQuery = new ImboQuery();
imboQuery.page(opts.page);
imboQuery.limit(opts.limit);
if (opts.users && globalSearch) {
imboQuery.users(opts.users);
}
if (opts.fields) {
imboQuery.fields(opts.fields);
}
if (opts.sort) {
... | javascript | function buildQuery(opts, globalSearch) {
var imboQuery = new ImboQuery();
imboQuery.page(opts.page);
imboQuery.limit(opts.limit);
if (opts.users && globalSearch) {
imboQuery.users(opts.users);
}
if (opts.fields) {
imboQuery.fields(opts.fields);
}
if (opts.sort) {
... | [
"function",
"buildQuery",
"(",
"opts",
",",
"globalSearch",
")",
"{",
"var",
"imboQuery",
"=",
"new",
"ImboQuery",
"(",
")",
";",
"imboQuery",
".",
"page",
"(",
"opts",
".",
"page",
")",
";",
"imboQuery",
".",
"limit",
"(",
"opts",
".",
"limit",
")",
... | Build the query object used to build the URI string
@param {Object} opts - Metadata query options
@param {bool} globalSearch - Whether we're searching globally or not
@return {Query} | [
"Build",
"the",
"query",
"object",
"used",
"to",
"build",
"the",
"URI",
"string"
] | d99a989f1fbb68612e92b53fc2f64a87cfc52f1d | https://github.com/imbo/imboclient-js-metadata/blob/d99a989f1fbb68612e92b53fc2f64a87cfc52f1d/index.js#L13-L36 | train |
imbo/imboclient-js-metadata | index.js | searchGlobalMetadata | function searchGlobalMetadata(query, opts, callback) {
if (typeof opts === 'function' && !callback) {
callback = opts;
opts = {};
}
var searchEndpointUrl = this.getResourceUrl({
path: '/images',
user: null,
query: buildQuery(opts, true).toString()
});
reques... | javascript | function searchGlobalMetadata(query, opts, callback) {
if (typeof opts === 'function' && !callback) {
callback = opts;
opts = {};
}
var searchEndpointUrl = this.getResourceUrl({
path: '/images',
user: null,
query: buildQuery(opts, true).toString()
});
reques... | [
"function",
"searchGlobalMetadata",
"(",
"query",
",",
"opts",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"opts",
"===",
"'function'",
"&&",
"!",
"callback",
")",
"{",
"callback",
"=",
"opts",
";",
"opts",
"=",
"{",
"}",
";",
"}",
"var",
"searchEn... | Search globally for images using metadata
@param {Object} query - Metadata search query
@param {Object} opts - Metadata query options
@param {Function} callback - Function to call with the search result
@return {boolean}
@this ImboClient | [
"Search",
"globally",
"for",
"images",
"using",
"metadata"
] | d99a989f1fbb68612e92b53fc2f64a87cfc52f1d | https://github.com/imbo/imboclient-js-metadata/blob/d99a989f1fbb68612e92b53fc2f64a87cfc52f1d/index.js#L47-L77 | train |
glaunay/ms-jobmanager | build/nativeJS/job-manager-server.js | granted | function granted(data, socket) {
return new Promise((resolve, reject) => {
setTimeout(() => {
logger.debug(`i grant access to ${util.format(data.id)}`);
broadcast('available');
let socketNamespace = data.id;
let newData = {
script: ss.createStr... | javascript | function granted(data, socket) {
return new Promise((resolve, reject) => {
setTimeout(() => {
logger.debug(`i grant access to ${util.format(data.id)}`);
broadcast('available');
let socketNamespace = data.id;
let newData = {
script: ss.createStr... | [
"function",
"granted",
"(",
"data",
",",
"socket",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"logger",
".",
"debug",
"(",
"`",
"${",
"util",
".",
"format",
"(",... | We build streams only at granted | [
"We",
"build",
"streams",
"only",
"at",
"granted"
] | 997d4fb25fd1d2b41acfae1dd576b33f2c92bd15 | https://github.com/glaunay/ms-jobmanager/blob/997d4fb25fd1d2b41acfae1dd576b33f2c92bd15/build/nativeJS/job-manager-server.js#L97-L127 | train |
lial/coordist | coordist.js | getDecimalDegree | function getDecimalDegree(deg, min, sec) {
if (min == undefined) min = 0;
if (sec == undefined) sec = 0;
return deg < 0 ?
(Math.abs(deg) + Math.abs(min) / 60 + Math.absabs(sec) / 3600) * -1 :
Math.absabs(deg) + Math.absabs(min) / 60 + Math.absabs(sec) / 3600;
} | javascript | function getDecimalDegree(deg, min, sec) {
if (min == undefined) min = 0;
if (sec == undefined) sec = 0;
return deg < 0 ?
(Math.abs(deg) + Math.abs(min) / 60 + Math.absabs(sec) / 3600) * -1 :
Math.absabs(deg) + Math.absabs(min) / 60 + Math.absabs(sec) / 3600;
} | [
"function",
"getDecimalDegree",
"(",
"deg",
",",
"min",
",",
"sec",
")",
"{",
"if",
"(",
"min",
"==",
"undefined",
")",
"min",
"=",
"0",
";",
"if",
"(",
"sec",
"==",
"undefined",
")",
"sec",
"=",
"0",
";",
"return",
"deg",
"<",
"0",
"?",
"(",
"... | Return decimal value of angle
@param Number deg Value in degrees
@param Number min Value in minutes
@param Number sec Value in seconds
@return Number | [
"Return",
"decimal",
"value",
"of",
"angle"
] | 57cfd7ed3da23a8417550e672647729b0ebb8f73 | https://github.com/lial/coordist/blob/57cfd7ed3da23a8417550e672647729b0ebb8f73/coordist.js#L74-L81 | train |
lial/coordist | coordist.js | getTrueAngle | function getTrueAngle(point) {
return Math.atan((minorAxisSquare / majorAxisSquare) * Math.tan(Deg2Rad(point.lat))) * 180 / Math.PI;
} | javascript | function getTrueAngle(point) {
return Math.atan((minorAxisSquare / majorAxisSquare) * Math.tan(Deg2Rad(point.lat))) * 180 / Math.PI;
} | [
"function",
"getTrueAngle",
"(",
"point",
")",
"{",
"return",
"Math",
".",
"atan",
"(",
"(",
"minorAxisSquare",
"/",
"majorAxisSquare",
")",
"*",
"Math",
".",
"tan",
"(",
"Deg2Rad",
"(",
"point",
".",
"lat",
")",
")",
")",
"*",
"180",
"/",
"Math",
".... | Determine true angle for point on surface
@param Object point Point on surface
@var point {lat, lng, alt}
@var lat - latitude (широта)
@var lng - longitude (долгота)
@var alt - altitude (высота над уровнем моря)
@return Number | [
"Determine",
"true",
"angle",
"for",
"point",
"on",
"surface"
] | 57cfd7ed3da23a8417550e672647729b0ebb8f73 | https://github.com/lial/coordist/blob/57cfd7ed3da23a8417550e672647729b0ebb8f73/coordist.js#L96-L98 | train |
warehouseai/warehouse-models | lib/package.js | tryParse | function tryParse(data) {
var json;
try {
json = JSON.parse(data);
} catch (ex) { debug('tryParse exception %s for data %s', ex, data); }
return json || data;
} | javascript | function tryParse(data) {
var json;
try {
json = JSON.parse(data);
} catch (ex) { debug('tryParse exception %s for data %s', ex, data); }
return json || data;
} | [
"function",
"tryParse",
"(",
"data",
")",
"{",
"var",
"json",
";",
"try",
"{",
"json",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"debug",
"(",
"'tryParse exception %s for data %s'",
",",
"ex",
",",
"data",
"... | Try to parse a string as JSON, otherwise return the string | [
"Try",
"to",
"parse",
"a",
"string",
"as",
"JSON",
"otherwise",
"return",
"the",
"string"
] | ee65aa759adc6a7f83f4b02608a4e74fe562aa89 | https://github.com/warehouseai/warehouse-models/blob/ee65aa759adc6a7f83f4b02608a4e74fe562aa89/lib/package.js#L229-L236 | train |
christill/grunt-sanitize | tasks/sanitize.js | formatFileName | function formatFileName(filepath) {
var validFilename;
validFilename = filepath.replace(/\s/g, options.separator);
validFilename = validFilename.replace(/[^a-zA-Z_0-9.]/, '');
validFilename = validFilename.toLowerCase();
return validFilename;
} | javascript | function formatFileName(filepath) {
var validFilename;
validFilename = filepath.replace(/\s/g, options.separator);
validFilename = validFilename.replace(/[^a-zA-Z_0-9.]/, '');
validFilename = validFilename.toLowerCase();
return validFilename;
} | [
"function",
"formatFileName",
"(",
"filepath",
")",
"{",
"var",
"validFilename",
";",
"validFilename",
"=",
"filepath",
".",
"replace",
"(",
"/",
"\\s",
"/",
"g",
",",
"options",
".",
"separator",
")",
";",
"validFilename",
"=",
"validFilename",
".",
"replac... | Format file name
@param {String} path
@return {String} | [
"Format",
"file",
"name"
] | 2df717ed926a5b40f251ce6b5b1209756548d65d | https://github.com/christill/grunt-sanitize/blob/2df717ed926a5b40f251ce6b5b1209756548d65d/tasks/sanitize.js#L22-L31 | train |
KeithPepin/prevent-forbidden-code | index.js | checkFile | function checkFile(fileName, contents) {
forbiddenCode.forEach(function(forbiddenItem) {
if (contents.indexOf(forbiddenItem) > -1) {
/* eslint-disable */
console.log('FAILURE: '.red + 'You left a '.reset + forbiddenItem.yellow + ' in '.reset + fileName.cyan);
/* eslint-en... | javascript | function checkFile(fileName, contents) {
forbiddenCode.forEach(function(forbiddenItem) {
if (contents.indexOf(forbiddenItem) > -1) {
/* eslint-disable */
console.log('FAILURE: '.red + 'You left a '.reset + forbiddenItem.yellow + ' in '.reset + fileName.cyan);
/* eslint-en... | [
"function",
"checkFile",
"(",
"fileName",
",",
"contents",
")",
"{",
"forbiddenCode",
".",
"forEach",
"(",
"function",
"(",
"forbiddenItem",
")",
"{",
"if",
"(",
"contents",
".",
"indexOf",
"(",
"forbiddenItem",
")",
">",
"-",
"1",
")",
"{",
"/* eslint-dis... | Analyzes a given file for forbidden code
@param {String} fileName
@param {String} contents | [
"Analyzes",
"a",
"given",
"file",
"for",
"forbidden",
"code"
] | 64eb3038a47494d55251c5c68e327919f5ba7b33 | https://github.com/KeithPepin/prevent-forbidden-code/blob/64eb3038a47494d55251c5c68e327919f5ba7b33/index.js#L37-L46 | train |
KeithPepin/prevent-forbidden-code | index.js | fileExists | function fileExists(file) {
var fileExists = true;
try {
fs.statSync(file, function(err, stat) {
if (err == null) {
fileExists = true;
} else {
fileExists = false;
}
});
} catch (e) {
fileExists = false;
}
... | javascript | function fileExists(file) {
var fileExists = true;
try {
fs.statSync(file, function(err, stat) {
if (err == null) {
fileExists = true;
} else {
fileExists = false;
}
});
} catch (e) {
fileExists = false;
}
... | [
"function",
"fileExists",
"(",
"file",
")",
"{",
"var",
"fileExists",
"=",
"true",
";",
"try",
"{",
"fs",
".",
"statSync",
"(",
"file",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
"==",
"null",
")",
"{",
"fileExists",
"=",... | Indicates if a given file exists or not
@param {String} file
@return {boolean} | [
"Indicates",
"if",
"a",
"given",
"file",
"exists",
"or",
"not"
] | 64eb3038a47494d55251c5c68e327919f5ba7b33 | https://github.com/KeithPepin/prevent-forbidden-code/blob/64eb3038a47494d55251c5c68e327919f5ba7b33/index.js#L64-L80 | train |
opentargets/RestApiJs | src/structure.js | cloneNode | function cloneNode (n) {
var c = {
__association_score: n.__association_score,
__evidence_count: n.__evidence_count,
id: n.id,
__id: n.__id,
__name: n.__name,
target: {
id: n.target.id,
name: n.target.gene_info.name,
symbol: n.targe... | javascript | function cloneNode (n) {
var c = {
__association_score: n.__association_score,
__evidence_count: n.__evidence_count,
id: n.id,
__id: n.__id,
__name: n.__name,
target: {
id: n.target.id,
name: n.target.gene_info.name,
symbol: n.targe... | [
"function",
"cloneNode",
"(",
"n",
")",
"{",
"var",
"c",
"=",
"{",
"__association_score",
":",
"n",
".",
"__association_score",
",",
"__evidence_count",
":",
"n",
".",
"__evidence_count",
",",
"id",
":",
"n",
".",
"id",
",",
"__id",
":",
"n",
".",
"__i... | Fast clone methods | [
"Fast",
"clone",
"methods"
] | afe7dcc61223419c4677b2ab69db17d26ca58a90 | https://github.com/opentargets/RestApiJs/blob/afe7dcc61223419c4677b2ab69db17d26ca58a90/src/structure.js#L155-L175 | train |
Whitebolt/require-extra | src/try.js | _tryModuleSync | function _tryModuleSync(modulePath, defaultReturnValue) {
try {
return syncRequire({squashErrors:true}, modulePath.shift());
} catch (err) { }
if(!modulePath.length) return defaultReturnValue;
return _tryModuleSync(modulePath, defaultReturnValue);
} | javascript | function _tryModuleSync(modulePath, defaultReturnValue) {
try {
return syncRequire({squashErrors:true}, modulePath.shift());
} catch (err) { }
if(!modulePath.length) return defaultReturnValue;
return _tryModuleSync(modulePath, defaultReturnValue);
} | [
"function",
"_tryModuleSync",
"(",
"modulePath",
",",
"defaultReturnValue",
")",
"{",
"try",
"{",
"return",
"syncRequire",
"(",
"{",
"squashErrors",
":",
"true",
"}",
",",
"modulePath",
".",
"shift",
"(",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{"... | Load a module or return a default value. Can take an array to try. Will load module synchronously.
@private
@async
@param {Array.<string>} modulePath Paths to try.
@param {*} defaultReturnValue Default value to return.
@returns {*} | [
"Load",
"a",
"module",
"or",
"return",
"a",
"default",
"value",
".",
"Can",
"take",
"an",
"array",
"to",
"try",
".",
"Will",
"load",
"module",
"synchronously",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/src/try.js#L53-L59 | train |
synder/xpress | demo/body-parser/lib/types/json.js | json | function json (options) {
var opts = options || {}
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var inflate = opts.inflate !== false
var reviver = opts.reviver
var strict = opts.strict !== false
var type = opts.type || 'application/json'
var verify ... | javascript | function json (options) {
var opts = options || {}
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var inflate = opts.inflate !== false
var reviver = opts.reviver
var strict = opts.strict !== false
var type = opts.type || 'application/json'
var verify ... | [
"function",
"json",
"(",
"options",
")",
"{",
"var",
"opts",
"=",
"options",
"||",
"{",
"}",
"var",
"limit",
"=",
"typeof",
"opts",
".",
"limit",
"!==",
"'number'",
"?",
"bytes",
".",
"parse",
"(",
"opts",
".",
"limit",
"||",
"'100kb'",
")",
":",
"... | Create a middleware to parse JSON bodies.
@param {object} [options]
@return {function}
@public | [
"Create",
"a",
"middleware",
"to",
"parse",
"JSON",
"bodies",
"."
] | 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/json.js#L50-L134 | train |
Yoobic/loopback-connector-rethinkdbdash | lib/rethink.js | _hasIndex | function _hasIndex(_this, model, key) {
// Primary key always hasIndex
if(key === 'id') {
return true;
}
var modelDef = _this._models[model];
var retval = (_.isObject(modelDef.properties[key]) && modelDef.properties[key].index) || (_.isObject(modelDef.settings[key]) && modelDef.settings[ke... | javascript | function _hasIndex(_this, model, key) {
// Primary key always hasIndex
if(key === 'id') {
return true;
}
var modelDef = _this._models[model];
var retval = (_.isObject(modelDef.properties[key]) && modelDef.properties[key].index) || (_.isObject(modelDef.settings[key]) && modelDef.settings[ke... | [
"function",
"_hasIndex",
"(",
"_this",
",",
"model",
",",
"key",
")",
"{",
"// Primary key always hasIndex",
"if",
"(",
"key",
"===",
"'id'",
")",
"{",
"return",
"true",
";",
"}",
"var",
"modelDef",
"=",
"_this",
".",
"_models",
"[",
"model",
"]",
";",
... | need to rewrite the function as it does not take into account a different name for the index | [
"need",
"to",
"rewrite",
"the",
"function",
"as",
"it",
"does",
"not",
"take",
"into",
"account",
"a",
"different",
"name",
"for",
"the",
"index"
] | ac300966f8da483e014f5544cc726e12d1f8bfd9 | https://github.com/Yoobic/loopback-connector-rethinkdbdash/blob/ac300966f8da483e014f5544cc726e12d1f8bfd9/lib/rethink.js#L550-L560 | train |
folkelib/folke-ko-grid | dist/index.js | register | function register() {
ko.extenders['searchArray'] = searchArrayExtension;
ko.components.register('grid', {
template: template,
viewModel: viewModel
});
} | javascript | function register() {
ko.extenders['searchArray'] = searchArrayExtension;
ko.components.register('grid', {
template: template,
viewModel: viewModel
});
} | [
"function",
"register",
"(",
")",
"{",
"ko",
".",
"extenders",
"[",
"'searchArray'",
"]",
"=",
"searchArrayExtension",
";",
"ko",
".",
"components",
".",
"register",
"(",
"'grid'",
",",
"{",
"template",
":",
"template",
",",
"viewModel",
":",
"viewModel",
... | Register the extensions | [
"Register",
"the",
"extensions"
] | 153185a15a10ab01e7f095732e970941f5d74ebc | https://github.com/folkelib/folke-ko-grid/blob/153185a15a10ab01e7f095732e970941f5d74ebc/dist/index.js#L110-L116 | train |
Cellarise/gulp-async-func-runner | tasks/lib/coverageStats.js | addStats | function addStats(collection, pkg) {
var coverageType, stat;
for (coverageType in collection) {
if (collection.hasOwnProperty(coverageType)) {
for (stat in collection[coverageType]) {
if (collection[coverageType].hasOwnProperty(stat)) {
collection[coverageTy... | javascript | function addStats(collection, pkg) {
var coverageType, stat;
for (coverageType in collection) {
if (collection.hasOwnProperty(coverageType)) {
for (stat in collection[coverageType]) {
if (collection[coverageType].hasOwnProperty(stat)) {
collection[coverageTy... | [
"function",
"addStats",
"(",
"collection",
",",
"pkg",
")",
"{",
"var",
"coverageType",
",",
"stat",
";",
"for",
"(",
"coverageType",
"in",
"collection",
")",
"{",
"if",
"(",
"collection",
".",
"hasOwnProperty",
"(",
"coverageType",
")",
")",
"{",
"for",
... | Helper function to append statistic properties from the provided collection to the provided package.json
@param {Object} collection - a collection of statistic properties
@param {Object} pkg - package.json object | [
"Helper",
"function",
"to",
"append",
"statistic",
"properties",
"from",
"the",
"provided",
"collection",
"to",
"the",
"provided",
"package",
".",
"json"
] | 80cc072ca4b8585619f41f5b7bed20960b55f444 | https://github.com/Cellarise/gulp-async-func-runner/blob/80cc072ca4b8585619f41f5b7bed20960b55f444/tasks/lib/coverageStats.js#L17-L29 | train |
Cellarise/gulp-async-func-runner | tasks/lib/coverageStats.js | deleteStats | function deleteStats(collection) {
var coverageType;
for (coverageType in collection) {
if (collection.hasOwnProperty(coverageType)) {
if (collection[coverageType].hasOwnProperty("total")) {
delete collection[coverageType].total;
}
if (collection[cove... | javascript | function deleteStats(collection) {
var coverageType;
for (coverageType in collection) {
if (collection.hasOwnProperty(coverageType)) {
if (collection[coverageType].hasOwnProperty("total")) {
delete collection[coverageType].total;
}
if (collection[cove... | [
"function",
"deleteStats",
"(",
"collection",
")",
"{",
"var",
"coverageType",
";",
"for",
"(",
"coverageType",
"in",
"collection",
")",
"{",
"if",
"(",
"collection",
".",
"hasOwnProperty",
"(",
"coverageType",
")",
")",
"{",
"if",
"(",
"collection",
"[",
... | Helper function to delete total, covered and skipped statistic properties from a collection
@param {Object} collection - a collection of statistic properties | [
"Helper",
"function",
"to",
"delete",
"total",
"covered",
"and",
"skipped",
"statistic",
"properties",
"from",
"a",
"collection"
] | 80cc072ca4b8585619f41f5b7bed20960b55f444 | https://github.com/Cellarise/gulp-async-func-runner/blob/80cc072ca4b8585619f41f5b7bed20960b55f444/tasks/lib/coverageStats.js#L35-L50 | train |
Cellarise/gulp-async-func-runner | tasks/lib/coverageStats.js | badgeColour | function badgeColour(collection, stat, watermarks) {
var watermarkType = stat === "overall" ? "lines" : stat;
var low = watermarks[watermarkType][0];
var high = watermarks[watermarkType][1];
var mid = (high - low) / 2;
var value = collection[stat].pct;
if (value < low) {
... | javascript | function badgeColour(collection, stat, watermarks) {
var watermarkType = stat === "overall" ? "lines" : stat;
var low = watermarks[watermarkType][0];
var high = watermarks[watermarkType][1];
var mid = (high - low) / 2;
var value = collection[stat].pct;
if (value < low) {
... | [
"function",
"badgeColour",
"(",
"collection",
",",
"stat",
",",
"watermarks",
")",
"{",
"var",
"watermarkType",
"=",
"stat",
"===",
"\"overall\"",
"?",
"\"lines\"",
":",
"stat",
";",
"var",
"low",
"=",
"watermarks",
"[",
"watermarkType",
"]",
"[",
"0",
"]"... | Helper function to determine badge colour
@param {Object} collection - a collection of statistic properties
@param {Object} stat - a statistic from the collection to calculate the badge for
@param {Object} watermarks - the high and low watermarks for each statistic in collection | [
"Helper",
"function",
"to",
"determine",
"badge",
"colour"
] | 80cc072ca4b8585619f41f5b7bed20960b55f444 | https://github.com/Cellarise/gulp-async-func-runner/blob/80cc072ca4b8585619f41f5b7bed20960b55f444/tasks/lib/coverageStats.js#L58-L75 | train |
nfroidure/http-auth-utils | src/mechanisms/digest.js | computeHash | function computeHash(data) {
const ha1 =
data.ha1 ||
_computeHash(
data.algorithm,
[data.username, data.realm, data.password].join(':'),
);
const ha2 = _computeHash(data.algorithm, [data.method, data.uri].join(':'));
return _computeHash(
data.algorithm,
[ha1, d... | javascript | function computeHash(data) {
const ha1 =
data.ha1 ||
_computeHash(
data.algorithm,
[data.username, data.realm, data.password].join(':'),
);
const ha2 = _computeHash(data.algorithm, [data.method, data.uri].join(':'));
return _computeHash(
data.algorithm,
[ha1, d... | [
"function",
"computeHash",
"(",
"data",
")",
"{",
"const",
"ha1",
"=",
"data",
".",
"ha1",
"||",
"_computeHash",
"(",
"data",
".",
"algorithm",
",",
"[",
"data",
".",
"username",
",",
"data",
".",
"realm",
",",
"data",
".",
"password",
"]",
".",
"joi... | Compute the Digest authentication hash from the given credentials.
@param {Object} data The credentials to encode and other encoding details.
@return {String} The hash representing the credentials.
@example
assert.equal(
DIGEST.computeHash({
username: 'Mufasa',
realm: 'testrealm@host.com',
password: 'Circl... | [
"Compute",
"the",
"Digest",
"authentication",
"hash",
"from",
"the",
"given",
"credentials",
"."
] | 5941dcb853c1eed68fbc5d748c15a09774482cf0 | https://github.com/nfroidure/http-auth-utils/blob/5941dcb853c1eed68fbc5d748c15a09774482cf0/src/mechanisms/digest.js#L199-L212 | train |
onecommons/base | routes/login.js | function(req, res) {
var url = passport.config.loginRedirect || '/profile';
var statusCode = 302; //303 is more accurate but express redirect() defaults
//to 302 so stick to that for consistency
if (req.session && req.session.returnTo) {
if (req.session.returnToMethod == req.method) {
... | javascript | function(req, res) {
var url = passport.config.loginRedirect || '/profile';
var statusCode = 302; //303 is more accurate but express redirect() defaults
//to 302 so stick to that for consistency
if (req.session && req.session.returnTo) {
if (req.session.returnToMethod == req.method) {
... | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"var",
"url",
"=",
"passport",
".",
"config",
".",
"loginRedirect",
"||",
"'/profile'",
";",
"var",
"statusCode",
"=",
"302",
";",
"//303 is more accurate but express redirect() defaults",
"//to 302 so stick to that for co... | replace passport's successReturnToOrRedirect option with one that preserves the http method so that we can return to a redirected POST. | [
"replace",
"passport",
"s",
"successReturnToOrRedirect",
"option",
"with",
"one",
"that",
"preserves",
"the",
"http",
"method",
"so",
"that",
"we",
"can",
"return",
"to",
"a",
"redirected",
"POST",
"."
] | 4f35d9f714d0367b0622a3504802363404290246 | https://github.com/onecommons/base/blob/4f35d9f714d0367b0622a3504802363404290246/routes/login.js#L31-L47 | train | |
vadr-vr/VR-Analytics-JSCore | js/logger.js | setLogLevel | function setLogLevel(level){
level = level > 0 ? level : 0;
level = level < 4 ? level : 4;
level = parseInt(level);
logLevel = level;
} | javascript | function setLogLevel(level){
level = level > 0 ? level : 0;
level = level < 4 ? level : 4;
level = parseInt(level);
logLevel = level;
} | [
"function",
"setLogLevel",
"(",
"level",
")",
"{",
"level",
"=",
"level",
">",
"0",
"?",
"level",
":",
"0",
";",
"level",
"=",
"level",
"<",
"4",
"?",
"level",
":",
"4",
";",
"level",
"=",
"parseInt",
"(",
"level",
")",
";",
"logLevel",
"=",
"lev... | Set log level for analytics
@memberof Logger
@param {number} level Integer logLevel value between 0 and 4 | [
"Set",
"log",
"level",
"for",
"analytics"
] | 7e4a493c824c2c1716360dcb6a3bfecfede5df3b | https://github.com/vadr-vr/VR-Analytics-JSCore/blob/7e4a493c824c2c1716360dcb6a3bfecfede5df3b/js/logger.js#L29-L37 | train |
mikefrey/utml | utml.js | fromCache | function fromCache(options) {
var filename = options.filename;
if (options.cache) {
if (filename) {
if (cache[filename]) {
return cache[filename];
}
}
else {
throw new Error('filename is required when using the cache option');
}
}
return false;
} | javascript | function fromCache(options) {
var filename = options.filename;
if (options.cache) {
if (filename) {
if (cache[filename]) {
return cache[filename];
}
}
else {
throw new Error('filename is required when using the cache option');
}
}
return false;
} | [
"function",
"fromCache",
"(",
"options",
")",
"{",
"var",
"filename",
"=",
"options",
".",
"filename",
";",
"if",
"(",
"options",
".",
"cache",
")",
"{",
"if",
"(",
"filename",
")",
"{",
"if",
"(",
"cache",
"[",
"filename",
"]",
")",
"{",
"return",
... | Get a template from the cache
@param {object} options
@return {Function} | [
"Get",
"a",
"template",
"from",
"the",
"cache"
] | e9f7c3da635557bc5be06383228956dddc39c280 | https://github.com/mikefrey/utml/blob/e9f7c3da635557bc5be06383228956dddc39c280/utml.js#L61-L74 | train |
mikefrey/utml | utml.js | cacheTemplate | function cacheTemplate(fn, options) {
if (options.cache && options.filename) {
cache[options.filename] = fn;
}
} | javascript | function cacheTemplate(fn, options) {
if (options.cache && options.filename) {
cache[options.filename] = fn;
}
} | [
"function",
"cacheTemplate",
"(",
"fn",
",",
"options",
")",
"{",
"if",
"(",
"options",
".",
"cache",
"&&",
"options",
".",
"filename",
")",
"{",
"cache",
"[",
"options",
".",
"filename",
"]",
"=",
"fn",
";",
"}",
"}"
] | Store the given fn in the cache
@param {Function} fn
@param {object} options | [
"Store",
"the",
"given",
"fn",
"in",
"the",
"cache"
] | e9f7c3da635557bc5be06383228956dddc39c280 | https://github.com/mikefrey/utml/blob/e9f7c3da635557bc5be06383228956dddc39c280/utml.js#L83-L87 | train |
kbarresi/calais-entity-extractor | lib/calais-entity-extractor.js | function (cb, text) {
var calais = this;
if (!calais.validateOptions())
return cb({}, 'Bad options');
if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
text = this.options.content;
if (this._undefinedOrNull(text) || typeof text != '... | javascript | function (cb, text) {
var calais = this;
if (!calais.validateOptions())
return cb({}, 'Bad options');
if (this._undefinedOrNull(text) || typeof text != 'string' || text.length == 0)
text = this.options.content;
if (this._undefinedOrNull(text) || typeof text != '... | [
"function",
"(",
"cb",
",",
"text",
")",
"{",
"var",
"calais",
"=",
"this",
";",
"if",
"(",
"!",
"calais",
".",
"validateOptions",
"(",
")",
")",
"return",
"cb",
"(",
"{",
"}",
",",
"'Bad options'",
")",
";",
"if",
"(",
"this",
".",
"_undefinedOrNu... | Perform the analysis request with Calais. If no |text| is given or |text| is empty,
then we fall back to the set options.content value. If that is also empty, an error is
returned.
@param cb Callback function of form function(resultData, error);
@param text Optional, the text to perform extraction on. If not set, the ... | [
"Perform",
"the",
"analysis",
"request",
"with",
"Calais",
".",
"If",
"no",
"|text|",
"is",
"given",
"or",
"|text|",
"is",
"empty",
"then",
"we",
"fall",
"back",
"to",
"the",
"set",
"options",
".",
"content",
"value",
".",
"If",
"that",
"is",
"also",
"... | 5f32b956a664ae745d4ec84717479f99b9d6dbe2 | https://github.com/kbarresi/calais-entity-extractor/blob/5f32b956a664ae745d4ec84717479f99b9d6dbe2/lib/calais-entity-extractor.js#L324-L386 | train | |
kbarresi/calais-entity-extractor | lib/calais-entity-extractor.js | function(url, cb) {
var calais = this;
if (!calais.validateOptions())
return cb({}, 'Bad options');
//Make sure we were given a URL.
if (this._undefinedOrNull(url) || typeof url != 'string' || url.length == 0)
return cb({}, 'No URL given.');
//Make sure... | javascript | function(url, cb) {
var calais = this;
if (!calais.validateOptions())
return cb({}, 'Bad options');
//Make sure we were given a URL.
if (this._undefinedOrNull(url) || typeof url != 'string' || url.length == 0)
return cb({}, 'No URL given.');
//Make sure... | [
"function",
"(",
"url",
",",
"cb",
")",
"{",
"var",
"calais",
"=",
"this",
";",
"if",
"(",
"!",
"calais",
".",
"validateOptions",
"(",
")",
")",
"return",
"cb",
"(",
"{",
"}",
",",
"'Bad options'",
")",
";",
"//Make sure we were given a URL.",
"if",
"(... | Extract tags and entities from a given URL. We download the HTML from the URL, and submit
that to Calais using the extractFromText function
@param url The URL to analyze.
@param cb The callback function, of form function(result, error) | [
"Extract",
"tags",
"and",
"entities",
"from",
"a",
"given",
"URL",
".",
"We",
"download",
"the",
"HTML",
"from",
"the",
"URL",
"and",
"submit",
"that",
"to",
"Calais",
"using",
"the",
"extractFromText",
"function"
] | 5f32b956a664ae745d4ec84717479f99b9d6dbe2 | https://github.com/kbarresi/calais-entity-extractor/blob/5f32b956a664ae745d4ec84717479f99b9d6dbe2/lib/calais-entity-extractor.js#L395-L472 | train | |
KAIT-HEMS/node-picogw-plugin-admin | ipv4.js | convToNum | function convToNum(ipstr) {
let ret = 0;
let mul = 256*256*256;
ipstr.split('.').forEach((numstr)=>{
ret += parseInt(numstr)*mul;
mul >>= 8;
});
return ret;
} | javascript | function convToNum(ipstr) {
let ret = 0;
let mul = 256*256*256;
ipstr.split('.').forEach((numstr)=>{
ret += parseInt(numstr)*mul;
mul >>= 8;
});
return ret;
} | [
"function",
"convToNum",
"(",
"ipstr",
")",
"{",
"let",
"ret",
"=",
"0",
";",
"let",
"mul",
"=",
"256",
"*",
"256",
"*",
"256",
";",
"ipstr",
".",
"split",
"(",
"'.'",
")",
".",
"forEach",
"(",
"(",
"numstr",
")",
"=>",
"{",
"ret",
"+=",
"parse... | Convert to number value from string IP address
@param {string} ipstr : string IP address
@return {number} number value of IP address | [
"Convert",
"to",
"number",
"value",
"from",
"string",
"IP",
"address"
] | 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/ipv4.js#L147-L155 | train |
KAIT-HEMS/node-picogw-plugin-admin | ipv4.js | startCheckingArpTable | function startCheckingArpTable() {
setInterval(()=>{
chkArpTable();
for (const macinfo of Object.values(macs)) {
pingNet(macinfo.net, macinfo.ip);
}
}, CHECK_ARP_TABLE_AND_PING_INTERVAL);
// Initial check
chkArpTable();
} | javascript | function startCheckingArpTable() {
setInterval(()=>{
chkArpTable();
for (const macinfo of Object.values(macs)) {
pingNet(macinfo.net, macinfo.ip);
}
}, CHECK_ARP_TABLE_AND_PING_INTERVAL);
// Initial check
chkArpTable();
} | [
"function",
"startCheckingArpTable",
"(",
")",
"{",
"setInterval",
"(",
"(",
")",
"=>",
"{",
"chkArpTable",
"(",
")",
";",
"for",
"(",
"const",
"macinfo",
"of",
"Object",
".",
"values",
"(",
"macs",
")",
")",
"{",
"pingNet",
"(",
"macinfo",
".",
"net",... | Start checking the arp table | [
"Start",
"checking",
"the",
"arp",
"table"
] | 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/ipv4.js#L284-L293 | train |
KAIT-HEMS/node-picogw-plugin-admin | ipv4.js | getNetworkInterfaces | function getNetworkInterfaces() {
const ret = {};
for (const macinfo of Object.values(macs)) {
if (!macinfo.self) {
continue;
}
ret[macinfo.net] = objCpy(macinfo);
}
return ret;
} | javascript | function getNetworkInterfaces() {
const ret = {};
for (const macinfo of Object.values(macs)) {
if (!macinfo.self) {
continue;
}
ret[macinfo.net] = objCpy(macinfo);
}
return ret;
} | [
"function",
"getNetworkInterfaces",
"(",
")",
"{",
"const",
"ret",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"macinfo",
"of",
"Object",
".",
"values",
"(",
"macs",
")",
")",
"{",
"if",
"(",
"!",
"macinfo",
".",
"self",
")",
"{",
"continue",
";",
"}"... | Return the network list for each interface
@return {object} network list | [
"Return",
"the",
"network",
"list",
"for",
"each",
"interface"
] | 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/ipv4.js#L301-L310 | train |
KAIT-HEMS/node-picogw-plugin-admin | ipv4.js | searchNetworkInterface | function searchNetworkInterface(ip, networks) {
networks = networks || getNetworkInterfaces();
for (const [net, netinfo] of Object.entries(networks)) {
const ipnet = netinfo.ip;
const mask = netinfo.netmask;
if (isNetworkSame(mask, ip, ipnet)) {
return net;
}
}
... | javascript | function searchNetworkInterface(ip, networks) {
networks = networks || getNetworkInterfaces();
for (const [net, netinfo] of Object.entries(networks)) {
const ipnet = netinfo.ip;
const mask = netinfo.netmask;
if (isNetworkSame(mask, ip, ipnet)) {
return net;
}
}
... | [
"function",
"searchNetworkInterface",
"(",
"ip",
",",
"networks",
")",
"{",
"networks",
"=",
"networks",
"||",
"getNetworkInterfaces",
"(",
")",
";",
"for",
"(",
"const",
"[",
"net",
",",
"netinfo",
"]",
"of",
"Object",
".",
"entries",
"(",
"networks",
")"... | Look for the network interface from the IP address
@param {string} ip : IP address
@param {object} [networks] : List of my network interfaces. This is the same as getNetworks () 's return value.
@return {string} network interface. e.g. 'eth0' or 'wlan0' | [
"Look",
"for",
"the",
"network",
"interface",
"from",
"the",
"IP",
"address"
] | 8c7ec31271b164eb90e12444388234a40cb470be | https://github.com/KAIT-HEMS/node-picogw-plugin-admin/blob/8c7ec31271b164eb90e12444388234a40cb470be/ipv4.js#L320-L330 | train |
johnpaulvaughan/itunes-music-library-tracks | index.js | getItunesTracks | function getItunesTracks(librarypath) {
var libraryID;
var trackObj = {};
var isTrack = false;
var line;
var trackCount = 0;
var streamIn;
var streamOut = new stream_1.Readable;
streamOut._read = function () { };
streamIn = fs.createReadStream(librarypath);
streamIn.on('error', f... | javascript | function getItunesTracks(librarypath) {
var libraryID;
var trackObj = {};
var isTrack = false;
var line;
var trackCount = 0;
var streamIn;
var streamOut = new stream_1.Readable;
streamOut._read = function () { };
streamIn = fs.createReadStream(librarypath);
streamIn.on('error', f... | [
"function",
"getItunesTracks",
"(",
"librarypath",
")",
"{",
"var",
"libraryID",
";",
"var",
"trackObj",
"=",
"{",
"}",
";",
"var",
"isTrack",
"=",
"false",
";",
"var",
"line",
";",
"var",
"trackCount",
"=",
"0",
";",
"var",
"streamIn",
";",
"var",
"st... | Creates an stream of JSON tracks from an iTunes Library XML file.
@param String
@return ReadableStream of JSON objects | [
"Creates",
"an",
"stream",
"of",
"JSON",
"tracks",
"from",
"an",
"iTunes",
"Library",
"XML",
"file",
"."
] | c96dd579bc6b225d6d8c1d4c2d4f0c25d5dff4a2 | https://github.com/johnpaulvaughan/itunes-music-library-tracks/blob/c96dd579bc6b225d6d8c1d4c2d4f0c25d5dff4a2/index.js#L12-L66 | train |
johnpaulvaughan/itunes-music-library-tracks | index.js | objectIsMusicTrack | function objectIsMusicTrack(obj) {
if ((obj.Name || obj.Artist)
&& !obj['Playlist ID']
&& (obj.Kind ==
('MPEG audio file'
|| 'AAC audio file'
|| 'Matched AAC audio file'
|| 'Protected AAC audio file'
|| 'Purchased AAC audio ... | javascript | function objectIsMusicTrack(obj) {
if ((obj.Name || obj.Artist)
&& !obj['Playlist ID']
&& (obj.Kind ==
('MPEG audio file'
|| 'AAC audio file'
|| 'Matched AAC audio file'
|| 'Protected AAC audio file'
|| 'Purchased AAC audio ... | [
"function",
"objectIsMusicTrack",
"(",
"obj",
")",
"{",
"if",
"(",
"(",
"obj",
".",
"Name",
"||",
"obj",
".",
"Artist",
")",
"&&",
"!",
"obj",
"[",
"'Playlist ID'",
"]",
"&&",
"(",
"obj",
".",
"Kind",
"==",
"(",
"'MPEG audio file'",
"||",
"'AAC audio f... | Ensures we have a music track and not a video or other non-music item.
@param Object
@return Boolean | [
"Ensures",
"we",
"have",
"a",
"music",
"track",
"and",
"not",
"a",
"video",
"or",
"other",
"non",
"-",
"music",
"item",
"."
] | c96dd579bc6b225d6d8c1d4c2d4f0c25d5dff4a2 | https://github.com/johnpaulvaughan/itunes-music-library-tracks/blob/c96dd579bc6b225d6d8c1d4c2d4f0c25d5dff4a2/index.js#L87-L99 | train |
godmodelabs/flora-errors | index.js | format | function format(err, options) {
const error = { message: 'Internal Server Error' };
options = options || {};
if (options.exposeErrors || (err.httpStatusCode && err.httpStatusCode < 500)) {
error.message = err.message;
if (err.code) error.code = err.code;
if (err.validation) error.v... | javascript | function format(err, options) {
const error = { message: 'Internal Server Error' };
options = options || {};
if (options.exposeErrors || (err.httpStatusCode && err.httpStatusCode < 500)) {
error.message = err.message;
if (err.code) error.code = err.code;
if (err.validation) error.v... | [
"function",
"format",
"(",
"err",
",",
"options",
")",
"{",
"const",
"error",
"=",
"{",
"message",
":",
"'Internal Server Error'",
"}",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"options",
".",
"exposeErrors",
"||",
"(",
"err",
".... | Converts an error object to a stringifyable object format for use
in Flora responses.
@param {FloraError} err object
@param {Object=} options | [
"Converts",
"an",
"error",
"object",
"to",
"a",
"stringifyable",
"object",
"format",
"for",
"use",
"in",
"Flora",
"responses",
"."
] | 87235f2fac83a550d2e6a134f2bc311807dc4197 | https://github.com/godmodelabs/flora-errors/blob/87235f2fac83a550d2e6a134f2bc311807dc4197/index.js#L100-L122 | train |
RainBirdAi/rainbird-linter | lib/filesets.js | validateFileset | function validateFileset(fileset, setter) {
if (Array.isArray(fileset)) {
async.each(fileset, function(path, callback) {
if (typeof path === 'string') {
callback();
} else {
callback(util.format('Invalid path: %s', path));
}
}, func... | javascript | function validateFileset(fileset, setter) {
if (Array.isArray(fileset)) {
async.each(fileset, function(path, callback) {
if (typeof path === 'string') {
callback();
} else {
callback(util.format('Invalid path: %s', path));
}
}, func... | [
"function",
"validateFileset",
"(",
"fileset",
",",
"setter",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"fileset",
")",
")",
"{",
"async",
".",
"each",
"(",
"fileset",
",",
"function",
"(",
"path",
",",
"callback",
")",
"{",
"if",
"(",
"type... | Filesets are validated by ensuring the fileset is an array and each item is a string. Valid filesets are applied, invalid ones are ignored. | [
"Filesets",
"are",
"validated",
"by",
"ensuring",
"the",
"fileset",
"is",
"an",
"array",
"and",
"each",
"item",
"is",
"a",
"string",
".",
"Valid",
"filesets",
"are",
"applied",
"invalid",
"ones",
"are",
"ignored",
"."
] | 2831a0286bfe3fb956b5188f0508752c6d16a4de | https://github.com/RainBirdAi/rainbird-linter/blob/2831a0286bfe3fb956b5188f0508752c6d16a4de/lib/filesets.js#L26-L44 | train |
RainBirdAi/rainbird-linter | lib/filesets.js | platoExcludes | function platoExcludes() {
var excludes = '';
excludeFileset.forEach(function (file) {
if (isDirectory(file)) {
excludes += file.replace(/\//g, '\/');
} else {
excludes += file;
}
excludes += '|';
});
if (excludes !== '') {
return new RegE... | javascript | function platoExcludes() {
var excludes = '';
excludeFileset.forEach(function (file) {
if (isDirectory(file)) {
excludes += file.replace(/\//g, '\/');
} else {
excludes += file;
}
excludes += '|';
});
if (excludes !== '') {
return new RegE... | [
"function",
"platoExcludes",
"(",
")",
"{",
"var",
"excludes",
"=",
"''",
";",
"excludeFileset",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"isDirectory",
"(",
"file",
")",
")",
"{",
"excludes",
"+=",
"file",
".",
"replace",
"("... | Plato uses a regular expression to exclude files so turn the list of exclude files into a properly formatted, pipe delimited list of files. If there are no filesets to exclude then `null` is returned. | [
"Plato",
"uses",
"a",
"regular",
"expression",
"to",
"exclude",
"files",
"so",
"turn",
"the",
"list",
"of",
"exclude",
"files",
"into",
"a",
"properly",
"formatted",
"pipe",
"delimited",
"list",
"of",
"files",
".",
"If",
"there",
"are",
"no",
"filesets",
"... | 2831a0286bfe3fb956b5188f0508752c6d16a4de | https://github.com/RainBirdAi/rainbird-linter/blob/2831a0286bfe3fb956b5188f0508752c6d16a4de/lib/filesets.js#L85-L101 | train |
mchalapuk/hyper-text-slider | lib/polyfills/class-list.js | applyPolyfill | function applyPolyfill(ElementClass) {
if (ElementClass.prototype.hasOwnProperty('classList')) {
return;
}
Object.defineProperty(ElementClass.prototype, 'classList', {
get: lazyDefinePropertyValue('classList', function() {
if (!(this instanceof ElementClass)) {
throw new Error(
... | javascript | function applyPolyfill(ElementClass) {
if (ElementClass.prototype.hasOwnProperty('classList')) {
return;
}
Object.defineProperty(ElementClass.prototype, 'classList', {
get: lazyDefinePropertyValue('classList', function() {
if (!(this instanceof ElementClass)) {
throw new Error(
... | [
"function",
"applyPolyfill",
"(",
"ElementClass",
")",
"{",
"if",
"(",
"ElementClass",
".",
"prototype",
".",
"hasOwnProperty",
"(",
"'classList'",
")",
")",
"{",
"return",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"ElementClass",
".",
"prototype",
",",
... | Checks if prototype of passed ElementClass contains classList and,
in case not, creates a polyfill implementation. | [
"Checks",
"if",
"prototype",
"of",
"passed",
"ElementClass",
"contains",
"classList",
"and",
"in",
"case",
"not",
"creates",
"a",
"polyfill",
"implementation",
"."
] | 2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4 | https://github.com/mchalapuk/hyper-text-slider/blob/2711b41b9bbf1d528e4a0bd31b2efdf91dce55b4/lib/polyfills/class-list.js#L28-L45 | train |
tableflip/footballbot-workshop | stubs/serialport.js | SpyConstructor | function SpyConstructor (opts) {
Constructor.call(this, opts)
// Spy on Constructor functions
for (var key in this) {
if (this[key] instanceof Function) {
this[key] = sinon.spy(this[key])
}
}
SpyConstructor.instances.push(this)
} | javascript | function SpyConstructor (opts) {
Constructor.call(this, opts)
// Spy on Constructor functions
for (var key in this) {
if (this[key] instanceof Function) {
this[key] = sinon.spy(this[key])
}
}
SpyConstructor.instances.push(this)
} | [
"function",
"SpyConstructor",
"(",
"opts",
")",
"{",
"Constructor",
".",
"call",
"(",
"this",
",",
"opts",
")",
"// Spy on Constructor functions",
"for",
"(",
"var",
"key",
"in",
"this",
")",
"{",
"if",
"(",
"this",
"[",
"key",
"]",
"instanceof",
"Function... | Wrap methods with spies and store instances | [
"Wrap",
"methods",
"with",
"spies",
"and",
"store",
"instances"
] | 3d9a31da2fe399b74199c7874caf4b5fcec42f8c | https://github.com/tableflip/footballbot-workshop/blob/3d9a31da2fe399b74199c7874caf4b5fcec42f8c/stubs/serialport.js#L18-L29 | train |
socialally/air | lib/air/text.js | text | function text(txt) {
if(!this.length) {
return this;
}
if(txt === undefined) {
return this.dom[0].textContent;
}
txt = txt || '';
this.each(function(el) {
el.textContent = txt;
});
return this;
} | javascript | function text(txt) {
if(!this.length) {
return this;
}
if(txt === undefined) {
return this.dom[0].textContent;
}
txt = txt || '';
this.each(function(el) {
el.textContent = txt;
});
return this;
} | [
"function",
"text",
"(",
"txt",
")",
"{",
"if",
"(",
"!",
"this",
".",
"length",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"txt",
"===",
"undefined",
")",
"{",
"return",
"this",
".",
"dom",
"[",
"0",
"]",
".",
"textContent",
";",
"}",
"t... | IE9 supports textContent and innerText has various issues.
See: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
See: http://www.kellegous.com/j/2013/02/27/innertext-vs-textcontent/ | [
"IE9",
"supports",
"textContent",
"and",
"innerText",
"has",
"various",
"issues",
"."
] | a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air/text.js#L7-L19 | train |
OpenSmartEnvironment/ose | lib/http/content.js | init | function init(path, name) { // {{{2
/**
* Class constructor
*
* @param name {String} Name of HttpContent instance
* @param path {String} Path to content
*
* @method init
*/
this.modules = {};
this.handlers = {};
this.scripts = [];
this.styles = [];
this.path = path || Path.dirname(this.O.module.file... | javascript | function init(path, name) { // {{{2
/**
* Class constructor
*
* @param name {String} Name of HttpContent instance
* @param path {String} Path to content
*
* @method init
*/
this.modules = {};
this.handlers = {};
this.scripts = [];
this.styles = [];
this.path = path || Path.dirname(this.O.module.file... | [
"function",
"init",
"(",
"path",
",",
"name",
")",
"{",
"// {{{2",
"/**\n * Class constructor\n *\n * @param name {String} Name of HttpContent instance\n * @param path {String} Path to content\n *\n * @method init\n */",
"this",
".",
"modules",
"=",
"{",
"}",
";",
"this",
".",
... | List of handlers provided by this content instance.
@property handlers
@type Object
Public {{{1 | [
"List",
"of",
"handlers",
"provided",
"by",
"this",
"content",
"instance",
"."
] | 2ab051d9db6e77341c40abb9cbdae6ce586917e0 | https://github.com/OpenSmartEnvironment/ose/blob/2ab051d9db6e77341c40abb9cbdae6ce586917e0/lib/http/content.js#L71-L94 | train |
nodejitsu/contour | pagelets/navigation.js | links | function links(data, page, options) {
if (!data || !data.length) return;
var targets = ['self', 'blank', 'parent', 'top']
, navigation = this;
return data.reduce(function reduce(menu, item) {
var url = item.href.split('/').filter(String)
, active = url.shift();
if (page) active ... | javascript | function links(data, page, options) {
if (!data || !data.length) return;
var targets = ['self', 'blank', 'parent', 'top']
, navigation = this;
return data.reduce(function reduce(menu, item) {
var url = item.href.split('/').filter(String)
, active = url.shift();
if (page) active ... | [
"function",
"links",
"(",
"data",
",",
"page",
",",
"options",
")",
"{",
"if",
"(",
"!",
"data",
"||",
"!",
"data",
".",
"length",
")",
"return",
";",
"var",
"targets",
"=",
"[",
"'self'",
",",
"'blank'",
",",
"'parent'",
",",
"'top'",
"]",
",",
... | Handblebar helper to generate the navigation entries. The base is defined by
the active page and should match the first part of the `href` route or the
provided menu entry `base`.
@param {Object} options
@param {Boolean} page Current iteration over page or root of url
@return {String} generated template
@api private | [
"Handblebar",
"helper",
"to",
"generate",
"the",
"navigation",
"entries",
".",
"The",
"base",
"is",
"defined",
"by",
"the",
"active",
"page",
"and",
"should",
"match",
"the",
"first",
"part",
"of",
"the",
"href",
"route",
"or",
"the",
"provided",
"menu",
"... | 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/navigation.js#L93-L114 | train |
vid/SenseBase | services/annotators/structural.js | function(sMatch, text) {
for (var i = 0; i < sMatch.matches.length; i++) {
var r = sMatch.matches[i];
var found = text.match(r);
if (found) {
var exact = found[0];
var value = found[1].trim();
var key = sMatch.fields[i];
annoRows.push(annotations.cr... | javascript | function(sMatch, text) {
for (var i = 0; i < sMatch.matches.length; i++) {
var r = sMatch.matches[i];
var found = text.match(r);
if (found) {
var exact = found[0];
var value = found[1].trim();
var key = sMatch.fields[i];
annoRows.push(annotations.cr... | [
"function",
"(",
"sMatch",
",",
"text",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"sMatch",
".",
"matches",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"r",
"=",
"sMatch",
".",
"matches",
"[",
"i",
"]",
";",
"var",
"found... | match a series of regexes, setting any found values | [
"match",
"a",
"series",
"of",
"regexes",
"setting",
"any",
"found",
"values"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/services/annotators/structural.js#L64-L77 | train | |
shamoons/linguist-samples | samples/JavaScript/json2_backbone.js | function(model, options) {
options || (options = {});
model = this._prepareModel(model, options);
if (!model) return false;
var already = this.getByCid(model) || this.get(model);
if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
this._byId[model.i... | javascript | function(model, options) {
options || (options = {});
model = this._prepareModel(model, options);
if (!model) return false;
var already = this.getByCid(model) || this.get(model);
if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
this._byId[model.i... | [
"function",
"(",
"model",
",",
"options",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"model",
"=",
"this",
".",
"_prepareModel",
"(",
"model",
",",
"options",
")",
";",
"if",
"(",
"!",
"model",
")",
"return",
"false",
";",
... | Internal implementation of adding a single model to the set, updating hash indexes for `id` and `cid` lookups. Returns the model, or 'false' if validation on a new model fails. | [
"Internal",
"implementation",
"of",
"adding",
"a",
"single",
"model",
"to",
"the",
"set",
"updating",
"hash",
"indexes",
"for",
"id",
"and",
"cid",
"lookups",
".",
"Returns",
"the",
"model",
"or",
"false",
"if",
"validation",
"on",
"a",
"new",
"model",
"fa... | 71c5ec1a535f7dde31f9e407679475f57fae0c08 | https://github.com/shamoons/linguist-samples/blob/71c5ec1a535f7dde31f9e407679475f57fae0c08/samples/JavaScript/json2_backbone.js#L584-L600 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.