id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
55,700 | AndreasMadsen/immortal | lib/core/process.js | interceptDeath | function interceptDeath(process, events) {
var closeEvent = helpers.support.close;
// all channels are closed
process.once(closeEvent ? 'close' : 'exit', events.close);
// the process died
if (closeEvent) {
process.once('exit', events.exit);
} else {
// intercept internal onexit call
var internalHandle = process._internal.onexit;
process._internal.onexit = function () {
events.exit();
internalHandle.apply(this, arguments);
};
}
} | javascript | function interceptDeath(process, events) {
var closeEvent = helpers.support.close;
// all channels are closed
process.once(closeEvent ? 'close' : 'exit', events.close);
// the process died
if (closeEvent) {
process.once('exit', events.exit);
} else {
// intercept internal onexit call
var internalHandle = process._internal.onexit;
process._internal.onexit = function () {
events.exit();
internalHandle.apply(this, arguments);
};
}
} | [
"function",
"interceptDeath",
"(",
"process",
",",
"events",
")",
"{",
"var",
"closeEvent",
"=",
"helpers",
".",
"support",
".",
"close",
";",
"// all channels are closed",
"process",
".",
"once",
"(",
"closeEvent",
"?",
"'close'",
":",
"'exit'",
",",
"events",
".",
"close",
")",
";",
"// the process died",
"if",
"(",
"closeEvent",
")",
"{",
"process",
".",
"once",
"(",
"'exit'",
",",
"events",
".",
"exit",
")",
";",
"}",
"else",
"{",
"// intercept internal onexit call",
"var",
"internalHandle",
"=",
"process",
".",
"_internal",
".",
"onexit",
";",
"process",
".",
"_internal",
".",
"onexit",
"=",
"function",
"(",
")",
"{",
"events",
".",
"exit",
"(",
")",
";",
"internalHandle",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
";",
"}",
"}"
] | An helper function there will intercept internal exit event if necessary | [
"An",
"helper",
"function",
"there",
"will",
"intercept",
"internal",
"exit",
"event",
"if",
"necessary"
] | c1ab5a4287a543fdfd980604a9e9927d663a9ef2 | https://github.com/AndreasMadsen/immortal/blob/c1ab5a4287a543fdfd980604a9e9927d663a9ef2/lib/core/process.js#L204-L222 |
55,701 | DearDesi/desirae | lib/browser-adapters.js | hashsum | function hashsum(hash, str) {
// you have to convert from string to array buffer
var ab
// you have to represent the algorithm as an object
, algo = { name: algos[hash] }
;
if ('string' === typeof str) {
ab = str2ab(str);
} else {
ab = str;
}
// All crypto digest methods return a promise
return crypto.subtle.digest(algo, ab).then(function (digest) {
// you have to convert the ArrayBuffer to a DataView and then to a hex String
return ab2hex(digest);
}).catch(function (e) {
// if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error
console.error('sha1sum ERROR');
console.error(e);
throw e;
});
} | javascript | function hashsum(hash, str) {
// you have to convert from string to array buffer
var ab
// you have to represent the algorithm as an object
, algo = { name: algos[hash] }
;
if ('string' === typeof str) {
ab = str2ab(str);
} else {
ab = str;
}
// All crypto digest methods return a promise
return crypto.subtle.digest(algo, ab).then(function (digest) {
// you have to convert the ArrayBuffer to a DataView and then to a hex String
return ab2hex(digest);
}).catch(function (e) {
// if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error
console.error('sha1sum ERROR');
console.error(e);
throw e;
});
} | [
"function",
"hashsum",
"(",
"hash",
",",
"str",
")",
"{",
"// you have to convert from string to array buffer",
"var",
"ab",
"// you have to represent the algorithm as an object ",
",",
"algo",
"=",
"{",
"name",
":",
"algos",
"[",
"hash",
"]",
"}",
";",
"if",
"(",
"'string'",
"===",
"typeof",
"str",
")",
"{",
"ab",
"=",
"str2ab",
"(",
"str",
")",
";",
"}",
"else",
"{",
"ab",
"=",
"str",
";",
"}",
"// All crypto digest methods return a promise",
"return",
"crypto",
".",
"subtle",
".",
"digest",
"(",
"algo",
",",
"ab",
")",
".",
"then",
"(",
"function",
"(",
"digest",
")",
"{",
"// you have to convert the ArrayBuffer to a DataView and then to a hex String",
"return",
"ab2hex",
"(",
"digest",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"e",
")",
"{",
"// if you specify an unsupported digest algorithm or non-ArrayBuffer, you'll get an error",
"console",
".",
"error",
"(",
"'sha1sum ERROR'",
")",
";",
"console",
".",
"error",
"(",
"e",
")",
";",
"throw",
"e",
";",
"}",
")",
";",
"}"
] | a more general convenience function | [
"a",
"more",
"general",
"convenience",
"function"
] | 7b043c898d668b07c39a154e215ddfa55444a5f2 | https://github.com/DearDesi/desirae/blob/7b043c898d668b07c39a154e215ddfa55444a5f2/lib/browser-adapters.js#L26-L49 |
55,702 | DearDesi/desirae | lib/browser-adapters.js | ab2hex | function ab2hex(ab) {
var dv = new DataView(ab)
, i
, len
, hex = ''
, c
;
for (i = 0, len = dv.byteLength; i < len; i += 1) {
c = dv.getUint8(i).toString(16);
if (c.length < 2) {
c = '0' + c;
}
hex += c;
}
return hex;
} | javascript | function ab2hex(ab) {
var dv = new DataView(ab)
, i
, len
, hex = ''
, c
;
for (i = 0, len = dv.byteLength; i < len; i += 1) {
c = dv.getUint8(i).toString(16);
if (c.length < 2) {
c = '0' + c;
}
hex += c;
}
return hex;
} | [
"function",
"ab2hex",
"(",
"ab",
")",
"{",
"var",
"dv",
"=",
"new",
"DataView",
"(",
"ab",
")",
",",
"i",
",",
"len",
",",
"hex",
"=",
"''",
",",
"c",
";",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"dv",
".",
"byteLength",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"1",
")",
"{",
"c",
"=",
"dv",
".",
"getUint8",
"(",
"i",
")",
".",
"toString",
"(",
"16",
")",
";",
"if",
"(",
"c",
".",
"length",
"<",
"2",
")",
"{",
"c",
"=",
"'0'",
"+",
"c",
";",
"}",
"hex",
"+=",
"c",
";",
"}",
"return",
"hex",
";",
"}"
] | convert from arraybuffer to hex | [
"convert",
"from",
"arraybuffer",
"to",
"hex"
] | 7b043c898d668b07c39a154e215ddfa55444a5f2 | https://github.com/DearDesi/desirae/blob/7b043c898d668b07c39a154e215ddfa55444a5f2/lib/browser-adapters.js#L52-L71 |
55,703 | DearDesi/desirae | lib/browser-adapters.js | str2ab | function str2ab(stringToEncode, insertBom) {
stringToEncode = stringToEncode.replace(/\r\n/g,"\n");
var utftext = []
, n
, c
;
if (true === insertBom) {
utftext[0] = 0xef;
utftext[1] = 0xbb;
utftext[2] = 0xbf;
}
for (n = 0; n < stringToEncode.length; n += 1) {
c = stringToEncode.charCodeAt(n);
if (c < 128) {
utftext[utftext.length]= c;
}
else if((c > 127) && (c < 2048)) {
utftext[utftext.length] = (c >> 6) | 192;
utftext[utftext.length] = (c & 63) | 128;
}
else {
utftext[utftext.length] = (c >> 12) | 224;
utftext[utftext.length] = ((c >> 6) & 63) | 128;
utftext[utftext.length] = (c & 63) | 128;
}
}
return new Uint8Array(utftext).buffer;
} | javascript | function str2ab(stringToEncode, insertBom) {
stringToEncode = stringToEncode.replace(/\r\n/g,"\n");
var utftext = []
, n
, c
;
if (true === insertBom) {
utftext[0] = 0xef;
utftext[1] = 0xbb;
utftext[2] = 0xbf;
}
for (n = 0; n < stringToEncode.length; n += 1) {
c = stringToEncode.charCodeAt(n);
if (c < 128) {
utftext[utftext.length]= c;
}
else if((c > 127) && (c < 2048)) {
utftext[utftext.length] = (c >> 6) | 192;
utftext[utftext.length] = (c & 63) | 128;
}
else {
utftext[utftext.length] = (c >> 12) | 224;
utftext[utftext.length] = ((c >> 6) & 63) | 128;
utftext[utftext.length] = (c & 63) | 128;
}
}
return new Uint8Array(utftext).buffer;
} | [
"function",
"str2ab",
"(",
"stringToEncode",
",",
"insertBom",
")",
"{",
"stringToEncode",
"=",
"stringToEncode",
".",
"replace",
"(",
"/",
"\\r\\n",
"/",
"g",
",",
"\"\\n\"",
")",
";",
"var",
"utftext",
"=",
"[",
"]",
",",
"n",
",",
"c",
";",
"if",
"(",
"true",
"===",
"insertBom",
")",
"{",
"utftext",
"[",
"0",
"]",
"=",
"0xef",
";",
"utftext",
"[",
"1",
"]",
"=",
"0xbb",
";",
"utftext",
"[",
"2",
"]",
"=",
"0xbf",
";",
"}",
"for",
"(",
"n",
"=",
"0",
";",
"n",
"<",
"stringToEncode",
".",
"length",
";",
"n",
"+=",
"1",
")",
"{",
"c",
"=",
"stringToEncode",
".",
"charCodeAt",
"(",
"n",
")",
";",
"if",
"(",
"c",
"<",
"128",
")",
"{",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"c",
";",
"}",
"else",
"if",
"(",
"(",
"c",
">",
"127",
")",
"&&",
"(",
"c",
"<",
"2048",
")",
")",
"{",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"(",
"c",
">>",
"6",
")",
"|",
"192",
";",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"(",
"c",
"&",
"63",
")",
"|",
"128",
";",
"}",
"else",
"{",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"(",
"c",
">>",
"12",
")",
"|",
"224",
";",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"(",
"(",
"c",
">>",
"6",
")",
"&",
"63",
")",
"|",
"128",
";",
"utftext",
"[",
"utftext",
".",
"length",
"]",
"=",
"(",
"c",
"&",
"63",
")",
"|",
"128",
";",
"}",
"}",
"return",
"new",
"Uint8Array",
"(",
"utftext",
")",
".",
"buffer",
";",
"}"
] | convert from string to arraybuffer | [
"convert",
"from",
"string",
"to",
"arraybuffer"
] | 7b043c898d668b07c39a154e215ddfa55444a5f2 | https://github.com/DearDesi/desirae/blob/7b043c898d668b07c39a154e215ddfa55444a5f2/lib/browser-adapters.js#L74-L107 |
55,704 | espadrine/fleau | fleau.js | escapeCurly | function escapeCurly (text, escapes) {
var newText = text.slice (0, escapes[0]);
for (var i = 0; i < escapes.length; i += 3) {
var from = escapes[i];
var to = escapes[i + 1];
var type = escapes[i + 2];
// Which escape do we have here?
if (type === 0) { newText += '{{';
} else { newText += '}}';
}
newText += text.slice (to, escapes[i+3]);
}
return newText;
} | javascript | function escapeCurly (text, escapes) {
var newText = text.slice (0, escapes[0]);
for (var i = 0; i < escapes.length; i += 3) {
var from = escapes[i];
var to = escapes[i + 1];
var type = escapes[i + 2];
// Which escape do we have here?
if (type === 0) { newText += '{{';
} else { newText += '}}';
}
newText += text.slice (to, escapes[i+3]);
}
return newText;
} | [
"function",
"escapeCurly",
"(",
"text",
",",
"escapes",
")",
"{",
"var",
"newText",
"=",
"text",
".",
"slice",
"(",
"0",
",",
"escapes",
"[",
"0",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"escapes",
".",
"length",
";",
"i",
"+=",
"3",
")",
"{",
"var",
"from",
"=",
"escapes",
"[",
"i",
"]",
";",
"var",
"to",
"=",
"escapes",
"[",
"i",
"+",
"1",
"]",
";",
"var",
"type",
"=",
"escapes",
"[",
"i",
"+",
"2",
"]",
";",
"// Which escape do we have here?",
"if",
"(",
"type",
"===",
"0",
")",
"{",
"newText",
"+=",
"'{{'",
";",
"}",
"else",
"{",
"newText",
"+=",
"'}}'",
";",
"}",
"newText",
"+=",
"text",
".",
"slice",
"(",
"to",
",",
"escapes",
"[",
"i",
"+",
"3",
"]",
")",
";",
"}",
"return",
"newText",
";",
"}"
] | Return a text where all escapes as defined in the toplevel function are indeed escaped. | [
"Return",
"a",
"text",
"where",
"all",
"escapes",
"as",
"defined",
"in",
"the",
"toplevel",
"function",
"are",
"indeed",
"escaped",
"."
] | 31b5f7783347deac4527a63afa522bc2e2ca8849 | https://github.com/espadrine/fleau/blob/31b5f7783347deac4527a63afa522bc2e2ca8849/fleau.js#L90-L103 |
55,705 | espadrine/fleau | fleau.js | function(input, output, literal, cb) {
var text = '';
input.on ('data', function gatherer (data) {
text += '' + data; // Converting to UTF-8 string.
});
input.on ('end', function writer () {
try {
var write = function(data) { output.write(data); };
template(text)(write, literal);
} catch (e) {
if (cb) { cb (e); }
} finally {
// There are streams you cannot end.
try {
output.end ();
} catch (e) {} finally {
if (cb) { cb (null); }
}
}
});
} | javascript | function(input, output, literal, cb) {
var text = '';
input.on ('data', function gatherer (data) {
text += '' + data; // Converting to UTF-8 string.
});
input.on ('end', function writer () {
try {
var write = function(data) { output.write(data); };
template(text)(write, literal);
} catch (e) {
if (cb) { cb (e); }
} finally {
// There are streams you cannot end.
try {
output.end ();
} catch (e) {} finally {
if (cb) { cb (null); }
}
}
});
} | [
"function",
"(",
"input",
",",
"output",
",",
"literal",
",",
"cb",
")",
"{",
"var",
"text",
"=",
"''",
";",
"input",
".",
"on",
"(",
"'data'",
",",
"function",
"gatherer",
"(",
"data",
")",
"{",
"text",
"+=",
"''",
"+",
"data",
";",
"// Converting to UTF-8 string.",
"}",
")",
";",
"input",
".",
"on",
"(",
"'end'",
",",
"function",
"writer",
"(",
")",
"{",
"try",
"{",
"var",
"write",
"=",
"function",
"(",
"data",
")",
"{",
"output",
".",
"write",
"(",
"data",
")",
";",
"}",
";",
"template",
"(",
"text",
")",
"(",
"write",
",",
"literal",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
"e",
")",
";",
"}",
"}",
"finally",
"{",
"// There are streams you cannot end.",
"try",
"{",
"output",
".",
"end",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"finally",
"{",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
"null",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
] | Main entry point. input and output are two streams, one readable, the other writable. | [
"Main",
"entry",
"point",
".",
"input",
"and",
"output",
"are",
"two",
"streams",
"one",
"readable",
"the",
"other",
"writable",
"."
] | 31b5f7783347deac4527a63afa522bc2e2ca8849 | https://github.com/espadrine/fleau/blob/31b5f7783347deac4527a63afa522bc2e2ca8849/fleau.js#L138-L158 |
|
55,706 | espadrine/fleau | fleau.js | function(input) {
var code = 'var $_isidentifier = ' + $_isidentifier.toString() + ';\n' +
// FIXME: could we remove that eval?
'eval((' + literaltovar.toString() + ')($_scope));\n';
code += 'var $_parsers = {\n';
var parsernames = Object.keys(parsers);
for (var i = 0; i < parsernames.length; i++) {
code += ' ' + JSON.stringify(parsernames[i]) + ': ' +
parsers[parsernames[i]].toString() + ',\n';
};
code += '}\n';
code += 'var $_written = "";\n' +
'var $_write = function(data) { $_written += data; };\n';
code += compile(input);
code += '$_written\n';
return function($_write, $_scope, timeout, cb) {
var res;
try {
res = vm.runInNewContext(code, {$_scope: $_scope},
{timeout: timeout || 1000});
} catch(err) {
console.error(err); $_write('');
if (cb) { cb(err); }
return;
}
$_write(res);
if (cb) { cb(null); }
};
} | javascript | function(input) {
var code = 'var $_isidentifier = ' + $_isidentifier.toString() + ';\n' +
// FIXME: could we remove that eval?
'eval((' + literaltovar.toString() + ')($_scope));\n';
code += 'var $_parsers = {\n';
var parsernames = Object.keys(parsers);
for (var i = 0; i < parsernames.length; i++) {
code += ' ' + JSON.stringify(parsernames[i]) + ': ' +
parsers[parsernames[i]].toString() + ',\n';
};
code += '}\n';
code += 'var $_written = "";\n' +
'var $_write = function(data) { $_written += data; };\n';
code += compile(input);
code += '$_written\n';
return function($_write, $_scope, timeout, cb) {
var res;
try {
res = vm.runInNewContext(code, {$_scope: $_scope},
{timeout: timeout || 1000});
} catch(err) {
console.error(err); $_write('');
if (cb) { cb(err); }
return;
}
$_write(res);
if (cb) { cb(null); }
};
} | [
"function",
"(",
"input",
")",
"{",
"var",
"code",
"=",
"'var $_isidentifier = '",
"+",
"$_isidentifier",
".",
"toString",
"(",
")",
"+",
"';\\n'",
"+",
"// FIXME: could we remove that eval?",
"'eval(('",
"+",
"literaltovar",
".",
"toString",
"(",
")",
"+",
"')($_scope));\\n'",
";",
"code",
"+=",
"'var $_parsers = {\\n'",
";",
"var",
"parsernames",
"=",
"Object",
".",
"keys",
"(",
"parsers",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parsernames",
".",
"length",
";",
"i",
"++",
")",
"{",
"code",
"+=",
"' '",
"+",
"JSON",
".",
"stringify",
"(",
"parsernames",
"[",
"i",
"]",
")",
"+",
"': '",
"+",
"parsers",
"[",
"parsernames",
"[",
"i",
"]",
"]",
".",
"toString",
"(",
")",
"+",
"',\\n'",
";",
"}",
";",
"code",
"+=",
"'}\\n'",
";",
"code",
"+=",
"'var $_written = \"\";\\n'",
"+",
"'var $_write = function(data) { $_written += data; };\\n'",
";",
"code",
"+=",
"compile",
"(",
"input",
")",
";",
"code",
"+=",
"'$_written\\n'",
";",
"return",
"function",
"(",
"$_write",
",",
"$_scope",
",",
"timeout",
",",
"cb",
")",
"{",
"var",
"res",
";",
"try",
"{",
"res",
"=",
"vm",
".",
"runInNewContext",
"(",
"code",
",",
"{",
"$_scope",
":",
"$_scope",
"}",
",",
"{",
"timeout",
":",
"timeout",
"||",
"1000",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"$_write",
"(",
"''",
")",
";",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"return",
";",
"}",
"$_write",
"(",
"res",
")",
";",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
"null",
")",
";",
"}",
"}",
";",
"}"
] | Like template, with a timeout and sandbox. | [
"Like",
"template",
"with",
"a",
"timeout",
"and",
"sandbox",
"."
] | 31b5f7783347deac4527a63afa522bc2e2ca8849 | https://github.com/espadrine/fleau/blob/31b5f7783347deac4527a63afa522bc2e2ca8849/fleau.js#L177-L205 |
|
55,707 | espadrine/fleau | fleau.js | function(input) {
var code = 'var $_parsers = {\n';
var parsernames = Object.keys(parsers);
for (var i = 0; i < parsernames.length; i++) {
code += ' ' + JSON.stringify(parsernames[i]) + ': ' +
parsers[parsernames[i]].toString() + ',\n';
};
code += '}\n';
code += compile(input) + '\nif (typeof $_end === "function") {$_end();}';
var script = new vm.Script(code, {timeout: 4 * 60 * 1000});
var runner = function(scope) {
var output = '';
var pipeOpen = false;
var ended = false;
var stream = new Readable({
encoding: 'utf8',
read: function() {
pipeOpen = true;
if (ended && output === '') {
pipeOpen = this.push(null);
} else if (output !== '') {
pipeOpen = this.push(output);
output = '';
}
},
});
scope.$_scope = scope;
scope.$_write = function(data) {
output += '' + data;
if (pipeOpen && output !== '') {
pipeOpen = stream.push(output);
output = '';
}
};
scope.$_end = function() {
ended = true;
if (pipeOpen) { stream.push(null); }
};
script.runInNewContext(scope)
return stream;
};
runner.code = code;
return runner;
} | javascript | function(input) {
var code = 'var $_parsers = {\n';
var parsernames = Object.keys(parsers);
for (var i = 0; i < parsernames.length; i++) {
code += ' ' + JSON.stringify(parsernames[i]) + ': ' +
parsers[parsernames[i]].toString() + ',\n';
};
code += '}\n';
code += compile(input) + '\nif (typeof $_end === "function") {$_end();}';
var script = new vm.Script(code, {timeout: 4 * 60 * 1000});
var runner = function(scope) {
var output = '';
var pipeOpen = false;
var ended = false;
var stream = new Readable({
encoding: 'utf8',
read: function() {
pipeOpen = true;
if (ended && output === '') {
pipeOpen = this.push(null);
} else if (output !== '') {
pipeOpen = this.push(output);
output = '';
}
},
});
scope.$_scope = scope;
scope.$_write = function(data) {
output += '' + data;
if (pipeOpen && output !== '') {
pipeOpen = stream.push(output);
output = '';
}
};
scope.$_end = function() {
ended = true;
if (pipeOpen) { stream.push(null); }
};
script.runInNewContext(scope)
return stream;
};
runner.code = code;
return runner;
} | [
"function",
"(",
"input",
")",
"{",
"var",
"code",
"=",
"'var $_parsers = {\\n'",
";",
"var",
"parsernames",
"=",
"Object",
".",
"keys",
"(",
"parsers",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parsernames",
".",
"length",
";",
"i",
"++",
")",
"{",
"code",
"+=",
"' '",
"+",
"JSON",
".",
"stringify",
"(",
"parsernames",
"[",
"i",
"]",
")",
"+",
"': '",
"+",
"parsers",
"[",
"parsernames",
"[",
"i",
"]",
"]",
".",
"toString",
"(",
")",
"+",
"',\\n'",
";",
"}",
";",
"code",
"+=",
"'}\\n'",
";",
"code",
"+=",
"compile",
"(",
"input",
")",
"+",
"'\\nif (typeof $_end === \"function\") {$_end();}'",
";",
"var",
"script",
"=",
"new",
"vm",
".",
"Script",
"(",
"code",
",",
"{",
"timeout",
":",
"4",
"*",
"60",
"*",
"1000",
"}",
")",
";",
"var",
"runner",
"=",
"function",
"(",
"scope",
")",
"{",
"var",
"output",
"=",
"''",
";",
"var",
"pipeOpen",
"=",
"false",
";",
"var",
"ended",
"=",
"false",
";",
"var",
"stream",
"=",
"new",
"Readable",
"(",
"{",
"encoding",
":",
"'utf8'",
",",
"read",
":",
"function",
"(",
")",
"{",
"pipeOpen",
"=",
"true",
";",
"if",
"(",
"ended",
"&&",
"output",
"===",
"''",
")",
"{",
"pipeOpen",
"=",
"this",
".",
"push",
"(",
"null",
")",
";",
"}",
"else",
"if",
"(",
"output",
"!==",
"''",
")",
"{",
"pipeOpen",
"=",
"this",
".",
"push",
"(",
"output",
")",
";",
"output",
"=",
"''",
";",
"}",
"}",
",",
"}",
")",
";",
"scope",
".",
"$_scope",
"=",
"scope",
";",
"scope",
".",
"$_write",
"=",
"function",
"(",
"data",
")",
"{",
"output",
"+=",
"''",
"+",
"data",
";",
"if",
"(",
"pipeOpen",
"&&",
"output",
"!==",
"''",
")",
"{",
"pipeOpen",
"=",
"stream",
".",
"push",
"(",
"output",
")",
";",
"output",
"=",
"''",
";",
"}",
"}",
";",
"scope",
".",
"$_end",
"=",
"function",
"(",
")",
"{",
"ended",
"=",
"true",
";",
"if",
"(",
"pipeOpen",
")",
"{",
"stream",
".",
"push",
"(",
"null",
")",
";",
"}",
"}",
";",
"script",
".",
"runInNewContext",
"(",
"scope",
")",
"return",
"stream",
";",
"}",
";",
"runner",
".",
"code",
"=",
"code",
";",
"return",
"runner",
";",
"}"
] | string is a template. Return a function that takes a scope and returns a readable stream. | [
"string",
"is",
"a",
"template",
".",
"Return",
"a",
"function",
"that",
"takes",
"a",
"scope",
"and",
"returns",
"a",
"readable",
"stream",
"."
] | 31b5f7783347deac4527a63afa522bc2e2ca8849 | https://github.com/espadrine/fleau/blob/31b5f7783347deac4527a63afa522bc2e2ca8849/fleau.js#L209-L252 |
|
55,708 | Pocketbrain/native-ads-web-ad-library | src/ads/adManager.js | function (applicationId, deviceDetails, environment) {
if(!applicationId) {
logger.wtf('No applicationID specified');
}
this.applicationId = applicationId;
this.deviceDetails = deviceDetails;
this.environment = environment;
this._currentAds = [];
this._loadingAds = [];
this._adsWithoutImages = [];
} | javascript | function (applicationId, deviceDetails, environment) {
if(!applicationId) {
logger.wtf('No applicationID specified');
}
this.applicationId = applicationId;
this.deviceDetails = deviceDetails;
this.environment = environment;
this._currentAds = [];
this._loadingAds = [];
this._adsWithoutImages = [];
} | [
"function",
"(",
"applicationId",
",",
"deviceDetails",
",",
"environment",
")",
"{",
"if",
"(",
"!",
"applicationId",
")",
"{",
"logger",
".",
"wtf",
"(",
"'No applicationID specified'",
")",
";",
"}",
"this",
".",
"applicationId",
"=",
"applicationId",
";",
"this",
".",
"deviceDetails",
"=",
"deviceDetails",
";",
"this",
".",
"environment",
"=",
"environment",
";",
"this",
".",
"_currentAds",
"=",
"[",
"]",
";",
"this",
".",
"_loadingAds",
"=",
"[",
"]",
";",
"this",
".",
"_adsWithoutImages",
"=",
"[",
"]",
";",
"}"
] | Creates a new instance of the adManager
@param applicationId - The ID of the application to receive ads for
@param deviceDetails - Details about the current users' device
@param environment - Environment specific functions.
@constructor | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"adManager"
] | aafee1c42e0569ee77f334fc2c4eb71eb146957e | https://github.com/Pocketbrain/native-ads-web-ad-library/blob/aafee1c42e0569ee77f334fc2c4eb71eb146957e/src/ads/adManager.js#L21-L32 |
|
55,709 | juttle/juttle-gmail-adapter | create_oauth_token.js | getNewToken | function getNewToken(credentials, oauth2Client, callback) {
var authUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: SCOPES
});
console.log('Authorize this app by visiting this url: ', authUrl);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter the code from that page here: ', function(code) {
rl.close();
oauth2Client.getToken(code, function(err, token) {
if (err) {
console.log('Error while trying to retrieve access token', err);
return;
}
oauth2Client.credentials = token;
storeToken(credentials, token);
callback(oauth2Client);
});
});
} | javascript | function getNewToken(credentials, oauth2Client, callback) {
var authUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: SCOPES
});
console.log('Authorize this app by visiting this url: ', authUrl);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter the code from that page here: ', function(code) {
rl.close();
oauth2Client.getToken(code, function(err, token) {
if (err) {
console.log('Error while trying to retrieve access token', err);
return;
}
oauth2Client.credentials = token;
storeToken(credentials, token);
callback(oauth2Client);
});
});
} | [
"function",
"getNewToken",
"(",
"credentials",
",",
"oauth2Client",
",",
"callback",
")",
"{",
"var",
"authUrl",
"=",
"oauth2Client",
".",
"generateAuthUrl",
"(",
"{",
"access_type",
":",
"'offline'",
",",
"scope",
":",
"SCOPES",
"}",
")",
";",
"console",
".",
"log",
"(",
"'Authorize this app by visiting this url: '",
",",
"authUrl",
")",
";",
"var",
"rl",
"=",
"readline",
".",
"createInterface",
"(",
"{",
"input",
":",
"process",
".",
"stdin",
",",
"output",
":",
"process",
".",
"stdout",
"}",
")",
";",
"rl",
".",
"question",
"(",
"'Enter the code from that page here: '",
",",
"function",
"(",
"code",
")",
"{",
"rl",
".",
"close",
"(",
")",
";",
"oauth2Client",
".",
"getToken",
"(",
"code",
",",
"function",
"(",
"err",
",",
"token",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'Error while trying to retrieve access token'",
",",
"err",
")",
";",
"return",
";",
"}",
"oauth2Client",
".",
"credentials",
"=",
"token",
";",
"storeToken",
"(",
"credentials",
",",
"token",
")",
";",
"callback",
"(",
"oauth2Client",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Get and store new token after prompting for user authorization, and then
execute the given callback with the authorized OAuth2 client.
@param {Object} credentials The authorization client credentials.
@param {google.auth.OAuth2} oauth2Client The OAuth2 client to get token for.
@param {getEventsCallback} callback The callback to call with the authorized
client. | [
"Get",
"and",
"store",
"new",
"token",
"after",
"prompting",
"for",
"user",
"authorization",
"and",
"then",
"execute",
"the",
"given",
"callback",
"with",
"the",
"authorized",
"OAuth2",
"client",
"."
] | f535da123962c5b8e48ba4a2113469fed69248e3 | https://github.com/juttle/juttle-gmail-adapter/blob/f535da123962c5b8e48ba4a2113469fed69248e3/create_oauth_token.js#L56-L78 |
55,710 | juttle/juttle-gmail-adapter | create_oauth_token.js | listLabels | function listLabels(auth) {
var gmail = google.gmail('v1');
gmail.users.labels.list({
auth: auth,
userId: 'me',
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var labels = response.labels;
if (labels.length === 0) {
console.log('No labels found.');
} else {
console.log('Labels:');
for (var i = 0; i < labels.length; i++) {
var label = labels[i];
console.log('- %s', label.name);
}
}
});
} | javascript | function listLabels(auth) {
var gmail = google.gmail('v1');
gmail.users.labels.list({
auth: auth,
userId: 'me',
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var labels = response.labels;
if (labels.length === 0) {
console.log('No labels found.');
} else {
console.log('Labels:');
for (var i = 0; i < labels.length; i++) {
var label = labels[i];
console.log('- %s', label.name);
}
}
});
} | [
"function",
"listLabels",
"(",
"auth",
")",
"{",
"var",
"gmail",
"=",
"google",
".",
"gmail",
"(",
"'v1'",
")",
";",
"gmail",
".",
"users",
".",
"labels",
".",
"list",
"(",
"{",
"auth",
":",
"auth",
",",
"userId",
":",
"'me'",
",",
"}",
",",
"function",
"(",
"err",
",",
"response",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'The API returned an error: '",
"+",
"err",
")",
";",
"return",
";",
"}",
"var",
"labels",
"=",
"response",
".",
"labels",
";",
"if",
"(",
"labels",
".",
"length",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'No labels found.'",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Labels:'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"labels",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"label",
"=",
"labels",
"[",
"i",
"]",
";",
"console",
".",
"log",
"(",
"'- %s'",
",",
"label",
".",
"name",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Lists the labels in the user's account.
@param {google.auth.OAuth2} auth An authorized OAuth2 client. | [
"Lists",
"the",
"labels",
"in",
"the",
"user",
"s",
"account",
"."
] | f535da123962c5b8e48ba4a2113469fed69248e3 | https://github.com/juttle/juttle-gmail-adapter/blob/f535da123962c5b8e48ba4a2113469fed69248e3/create_oauth_token.js#L110-L131 |
55,711 | juju/maraca | lib/delta-handlers.js | processDeltas | function processDeltas(deltas) {
let updates = {
changed: {},
removed: {}
};
deltas.forEach(delta => {
const entityType = delta[0];
const changeType = delta[1];
const entity = delta[2];
const key = _getEntityKey(entityType, entity);
if (!key) {
// We don't know how to manage this entity, so ignore it.
return;
}
const entityGroup = _getEntityGroup(entityType);
const updateCollection = updates[changeType + 'd'];
if (!updateCollection[entityGroup]) {
updateCollection[entityGroup] = {};
}
updateCollection[entityGroup][key] = _parseEntity(entityType, entity);
});
return updates;
} | javascript | function processDeltas(deltas) {
let updates = {
changed: {},
removed: {}
};
deltas.forEach(delta => {
const entityType = delta[0];
const changeType = delta[1];
const entity = delta[2];
const key = _getEntityKey(entityType, entity);
if (!key) {
// We don't know how to manage this entity, so ignore it.
return;
}
const entityGroup = _getEntityGroup(entityType);
const updateCollection = updates[changeType + 'd'];
if (!updateCollection[entityGroup]) {
updateCollection[entityGroup] = {};
}
updateCollection[entityGroup][key] = _parseEntity(entityType, entity);
});
return updates;
} | [
"function",
"processDeltas",
"(",
"deltas",
")",
"{",
"let",
"updates",
"=",
"{",
"changed",
":",
"{",
"}",
",",
"removed",
":",
"{",
"}",
"}",
";",
"deltas",
".",
"forEach",
"(",
"delta",
"=>",
"{",
"const",
"entityType",
"=",
"delta",
"[",
"0",
"]",
";",
"const",
"changeType",
"=",
"delta",
"[",
"1",
"]",
";",
"const",
"entity",
"=",
"delta",
"[",
"2",
"]",
";",
"const",
"key",
"=",
"_getEntityKey",
"(",
"entityType",
",",
"entity",
")",
";",
"if",
"(",
"!",
"key",
")",
"{",
"// We don't know how to manage this entity, so ignore it.",
"return",
";",
"}",
"const",
"entityGroup",
"=",
"_getEntityGroup",
"(",
"entityType",
")",
";",
"const",
"updateCollection",
"=",
"updates",
"[",
"changeType",
"+",
"'d'",
"]",
";",
"if",
"(",
"!",
"updateCollection",
"[",
"entityGroup",
"]",
")",
"{",
"updateCollection",
"[",
"entityGroup",
"]",
"=",
"{",
"}",
";",
"}",
"updateCollection",
"[",
"entityGroup",
"]",
"[",
"key",
"]",
"=",
"_parseEntity",
"(",
"entityType",
",",
"entity",
")",
";",
"}",
")",
";",
"return",
"updates",
";",
"}"
] | Get the consolidated updates from the deltas.
@param {Array} deltas - The list of deltas.
@returns {Object} return - The delta updates.
@returns {Object} return.changed - The entities to change.
@returns {Object} return.removed - The entities to remove. | [
"Get",
"the",
"consolidated",
"updates",
"from",
"the",
"deltas",
"."
] | 0f245c6e09ef215fb4726bf7650320be2f49b6a0 | https://github.com/juju/maraca/blob/0f245c6e09ef215fb4726bf7650320be2f49b6a0/lib/delta-handlers.js#L13-L35 |
55,712 | juju/maraca | lib/delta-handlers.js | _getEntityKey | function _getEntityKey(entityType, entity) {
switch (entityType) {
case 'remote-application':
case 'application':
case 'unit':
return entity.name;
case 'machine':
case 'relation':
return entity.id;
case 'annotation':
return entity.tag;
default:
// This is an unknown entity type so ignore it as we don't know how to
// handle it.
return null;
}
} | javascript | function _getEntityKey(entityType, entity) {
switch (entityType) {
case 'remote-application':
case 'application':
case 'unit':
return entity.name;
case 'machine':
case 'relation':
return entity.id;
case 'annotation':
return entity.tag;
default:
// This is an unknown entity type so ignore it as we don't know how to
// handle it.
return null;
}
} | [
"function",
"_getEntityKey",
"(",
"entityType",
",",
"entity",
")",
"{",
"switch",
"(",
"entityType",
")",
"{",
"case",
"'remote-application'",
":",
"case",
"'application'",
":",
"case",
"'unit'",
":",
"return",
"entity",
".",
"name",
";",
"case",
"'machine'",
":",
"case",
"'relation'",
":",
"return",
"entity",
".",
"id",
";",
"case",
"'annotation'",
":",
"return",
"entity",
".",
"tag",
";",
"default",
":",
"// This is an unknown entity type so ignore it as we don't know how to",
"// handle it.",
"return",
"null",
";",
"}",
"}"
] | Get the identifier for the entity based upon its type.
@param {String} entityType - The type of entity.
@param {Object} entity - The entity details.
@returns {String} The entity key. | [
"Get",
"the",
"identifier",
"for",
"the",
"entity",
"based",
"upon",
"its",
"type",
"."
] | 0f245c6e09ef215fb4726bf7650320be2f49b6a0 | https://github.com/juju/maraca/blob/0f245c6e09ef215fb4726bf7650320be2f49b6a0/lib/delta-handlers.js#L43-L59 |
55,713 | juju/maraca | lib/delta-handlers.js | _parseEntity | function _parseEntity(entityType, entity) {
switch (entityType) {
case 'remote-application':
return parsers.parseRemoteApplication(entity);
case 'application':
return parsers.parseApplication(entity);
case 'unit':
return parsers.parseUnit(entity);
case 'machine':
return parsers.parseMachine(entity);
case 'relation':
return parsers.parseRelation(entity);
case 'annotation':
return parsers.parseAnnotation(entity);
default:
// This is an unknown entity type so ignore it as we don't know how to
// handle it.
return null;
}
} | javascript | function _parseEntity(entityType, entity) {
switch (entityType) {
case 'remote-application':
return parsers.parseRemoteApplication(entity);
case 'application':
return parsers.parseApplication(entity);
case 'unit':
return parsers.parseUnit(entity);
case 'machine':
return parsers.parseMachine(entity);
case 'relation':
return parsers.parseRelation(entity);
case 'annotation':
return parsers.parseAnnotation(entity);
default:
// This is an unknown entity type so ignore it as we don't know how to
// handle it.
return null;
}
} | [
"function",
"_parseEntity",
"(",
"entityType",
",",
"entity",
")",
"{",
"switch",
"(",
"entityType",
")",
"{",
"case",
"'remote-application'",
":",
"return",
"parsers",
".",
"parseRemoteApplication",
"(",
"entity",
")",
";",
"case",
"'application'",
":",
"return",
"parsers",
".",
"parseApplication",
"(",
"entity",
")",
";",
"case",
"'unit'",
":",
"return",
"parsers",
".",
"parseUnit",
"(",
"entity",
")",
";",
"case",
"'machine'",
":",
"return",
"parsers",
".",
"parseMachine",
"(",
"entity",
")",
";",
"case",
"'relation'",
":",
"return",
"parsers",
".",
"parseRelation",
"(",
"entity",
")",
";",
"case",
"'annotation'",
":",
"return",
"parsers",
".",
"parseAnnotation",
"(",
"entity",
")",
";",
"default",
":",
"// This is an unknown entity type so ignore it as we don't know how to",
"// handle it.",
"return",
"null",
";",
"}",
"}"
] | Parse the entity response into a friendly format.
@param {String} entityType - The type of entity.
@param {Object} entity - The entity details.
@returns {Object} The parsed entity. | [
"Parse",
"the",
"entity",
"response",
"into",
"a",
"friendly",
"format",
"."
] | 0f245c6e09ef215fb4726bf7650320be2f49b6a0 | https://github.com/juju/maraca/blob/0f245c6e09ef215fb4726bf7650320be2f49b6a0/lib/delta-handlers.js#L81-L100 |
55,714 | meepobrother/meepo-loader | demo/assets/meepo.libs/masonry/masonry.pkgd.js | getMilliseconds | function getMilliseconds( time ) {
if ( typeof time == 'number' ) {
return time;
}
var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
var num = matches && matches[1];
var unit = matches && matches[2];
if ( !num.length ) {
return 0;
}
num = parseFloat( num );
var mult = msUnits[ unit ] || 1;
return num * mult;
} | javascript | function getMilliseconds( time ) {
if ( typeof time == 'number' ) {
return time;
}
var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
var num = matches && matches[1];
var unit = matches && matches[2];
if ( !num.length ) {
return 0;
}
num = parseFloat( num );
var mult = msUnits[ unit ] || 1;
return num * mult;
} | [
"function",
"getMilliseconds",
"(",
"time",
")",
"{",
"if",
"(",
"typeof",
"time",
"==",
"'number'",
")",
"{",
"return",
"time",
";",
"}",
"var",
"matches",
"=",
"time",
".",
"match",
"(",
"/",
"(^\\d*\\.?\\d*)(\\w*)",
"/",
")",
";",
"var",
"num",
"=",
"matches",
"&&",
"matches",
"[",
"1",
"]",
";",
"var",
"unit",
"=",
"matches",
"&&",
"matches",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"num",
".",
"length",
")",
"{",
"return",
"0",
";",
"}",
"num",
"=",
"parseFloat",
"(",
"num",
")",
";",
"var",
"mult",
"=",
"msUnits",
"[",
"unit",
"]",
"||",
"1",
";",
"return",
"num",
"*",
"mult",
";",
"}"
] | munge time-like parameter into millisecond number '0.4s' -> 40 | [
"munge",
"time",
"-",
"like",
"parameter",
"into",
"millisecond",
"number",
"0",
".",
"4s",
"-",
">",
"40"
] | c0acb052d3c31b15d1b9cbb7b82659df78d50094 | https://github.com/meepobrother/meepo-loader/blob/c0acb052d3c31b15d1b9cbb7b82659df78d50094/demo/assets/meepo.libs/masonry/masonry.pkgd.js#L2239-L2252 |
55,715 | helinjiang/babel-d | lib/babel-compile.js | compileFile | function compileFile(srcFullPath, saveOutFullPath, onlyCopy) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var content = fs.readFileSync(srcFullPath, 'utf8');
//when get file content empty, maybe file is locked
if (!content) {
return;
}
// only copy file content
if (onlyCopy) {
fse.copySync(srcFullPath, saveOutFullPath);
return;
}
try {
var startTime = Date.now();
var data = compileByBabel(content, {
filename: srcFullPath
// sourceMaps: true,
// sourceFileName: relativePath
});
var endTime = Date.now();
if (options.debug) {
console.log('Compile file ' + srcFullPath, 'Babel cost ' + (endTime - startTime) + ' ms');
}
// save file
fse.outputFileSync(saveOutFullPath, data.code);
return true;
} catch (e) {
console.error('compile file ' + srcFullPath + ' error', e);
}
return false;
} | javascript | function compileFile(srcFullPath, saveOutFullPath, onlyCopy) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var content = fs.readFileSync(srcFullPath, 'utf8');
//when get file content empty, maybe file is locked
if (!content) {
return;
}
// only copy file content
if (onlyCopy) {
fse.copySync(srcFullPath, saveOutFullPath);
return;
}
try {
var startTime = Date.now();
var data = compileByBabel(content, {
filename: srcFullPath
// sourceMaps: true,
// sourceFileName: relativePath
});
var endTime = Date.now();
if (options.debug) {
console.log('Compile file ' + srcFullPath, 'Babel cost ' + (endTime - startTime) + ' ms');
}
// save file
fse.outputFileSync(saveOutFullPath, data.code);
return true;
} catch (e) {
console.error('compile file ' + srcFullPath + ' error', e);
}
return false;
} | [
"function",
"compileFile",
"(",
"srcFullPath",
",",
"saveOutFullPath",
",",
"onlyCopy",
")",
"{",
"var",
"options",
"=",
"arguments",
".",
"length",
">",
"3",
"&&",
"arguments",
"[",
"3",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"3",
"]",
":",
"{",
"}",
";",
"var",
"content",
"=",
"fs",
".",
"readFileSync",
"(",
"srcFullPath",
",",
"'utf8'",
")",
";",
"//when get file content empty, maybe file is locked",
"if",
"(",
"!",
"content",
")",
"{",
"return",
";",
"}",
"// only copy file content",
"if",
"(",
"onlyCopy",
")",
"{",
"fse",
".",
"copySync",
"(",
"srcFullPath",
",",
"saveOutFullPath",
")",
";",
"return",
";",
"}",
"try",
"{",
"var",
"startTime",
"=",
"Date",
".",
"now",
"(",
")",
";",
"var",
"data",
"=",
"compileByBabel",
"(",
"content",
",",
"{",
"filename",
":",
"srcFullPath",
"// sourceMaps: true,",
"// sourceFileName: relativePath",
"}",
")",
";",
"var",
"endTime",
"=",
"Date",
".",
"now",
"(",
")",
";",
"if",
"(",
"options",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"'Compile file '",
"+",
"srcFullPath",
",",
"'Babel cost '",
"+",
"(",
"endTime",
"-",
"startTime",
")",
"+",
"' ms'",
")",
";",
"}",
"// save file",
"fse",
".",
"outputFileSync",
"(",
"saveOutFullPath",
",",
"data",
".",
"code",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'compile file '",
"+",
"srcFullPath",
"+",
"' error'",
",",
"e",
")",
";",
"}",
"return",
"false",
";",
"}"
] | compile single file
@param {String} srcFullPath
@param {String} saveOutFullPath
@param {Boolean} [onlyCopy]
@param {Object} [options]
@param {String} [options.debug] only for debug | [
"compile",
"single",
"file"
] | 12e05f8702f850f7427416489097c50b93093abb | https://github.com/helinjiang/babel-d/blob/12e05f8702f850f7427416489097c50b93093abb/lib/babel-compile.js#L118-L158 |
55,716 | helinjiang/babel-d | lib/babel-compile.js | getFiles | function getFiles(paths) {
var result = fileUtil.getAllFiles(paths);
var files = result.map(function (item) {
return item.relativePath;
// return path.join(item.basePath, item.relativePath);
});
return files;
} | javascript | function getFiles(paths) {
var result = fileUtil.getAllFiles(paths);
var files = result.map(function (item) {
return item.relativePath;
// return path.join(item.basePath, item.relativePath);
});
return files;
} | [
"function",
"getFiles",
"(",
"paths",
")",
"{",
"var",
"result",
"=",
"fileUtil",
".",
"getAllFiles",
"(",
"paths",
")",
";",
"var",
"files",
"=",
"result",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"relativePath",
";",
"// return path.join(item.basePath, item.relativePath);",
"}",
")",
";",
"return",
"files",
";",
"}"
] | get all files
@param paths | [
"get",
"all",
"files"
] | 12e05f8702f850f7427416489097c50b93093abb | https://github.com/helinjiang/babel-d/blob/12e05f8702f850f7427416489097c50b93093abb/lib/babel-compile.js#L175-L184 |
55,717 | byu-oit/fully-typed | bin/one-of.js | TypedOneOf | function TypedOneOf (config) {
const oneOf = this;
// validate oneOf
if (!config.hasOwnProperty('oneOf')) {
throw Error('Invalid configuration. Missing required one-of property: oneOf. Must be an array of schema configurations.');
}
if (!Array.isArray(config.oneOf) || config.oneOf.filter(v => !v || typeof v !== 'object').length) {
throw Error('Invalid configuration value for property: oneOf. Must be an array of schema configurations.');
}
// create each unique schema
const hashes = {};
const schemas = config.oneOf
.map(item => FullyTyped(item))
.filter(schema => {
const hash = schema.hash();
if (hashes[hash]) return false;
hashes[hash] = true;
return true;
});
// define properties
Object.defineProperties(oneOf, {
oneOf: {
/**
* @property
* @name TypedOneOf#oneOf
* @type {object}
*/
value: schemas,
writable: false
}
});
return oneOf;
} | javascript | function TypedOneOf (config) {
const oneOf = this;
// validate oneOf
if (!config.hasOwnProperty('oneOf')) {
throw Error('Invalid configuration. Missing required one-of property: oneOf. Must be an array of schema configurations.');
}
if (!Array.isArray(config.oneOf) || config.oneOf.filter(v => !v || typeof v !== 'object').length) {
throw Error('Invalid configuration value for property: oneOf. Must be an array of schema configurations.');
}
// create each unique schema
const hashes = {};
const schemas = config.oneOf
.map(item => FullyTyped(item))
.filter(schema => {
const hash = schema.hash();
if (hashes[hash]) return false;
hashes[hash] = true;
return true;
});
// define properties
Object.defineProperties(oneOf, {
oneOf: {
/**
* @property
* @name TypedOneOf#oneOf
* @type {object}
*/
value: schemas,
writable: false
}
});
return oneOf;
} | [
"function",
"TypedOneOf",
"(",
"config",
")",
"{",
"const",
"oneOf",
"=",
"this",
";",
"// validate oneOf",
"if",
"(",
"!",
"config",
".",
"hasOwnProperty",
"(",
"'oneOf'",
")",
")",
"{",
"throw",
"Error",
"(",
"'Invalid configuration. Missing required one-of property: oneOf. Must be an array of schema configurations.'",
")",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"config",
".",
"oneOf",
")",
"||",
"config",
".",
"oneOf",
".",
"filter",
"(",
"v",
"=>",
"!",
"v",
"||",
"typeof",
"v",
"!==",
"'object'",
")",
".",
"length",
")",
"{",
"throw",
"Error",
"(",
"'Invalid configuration value for property: oneOf. Must be an array of schema configurations.'",
")",
";",
"}",
"// create each unique schema",
"const",
"hashes",
"=",
"{",
"}",
";",
"const",
"schemas",
"=",
"config",
".",
"oneOf",
".",
"map",
"(",
"item",
"=>",
"FullyTyped",
"(",
"item",
")",
")",
".",
"filter",
"(",
"schema",
"=>",
"{",
"const",
"hash",
"=",
"schema",
".",
"hash",
"(",
")",
";",
"if",
"(",
"hashes",
"[",
"hash",
"]",
")",
"return",
"false",
";",
"hashes",
"[",
"hash",
"]",
"=",
"true",
";",
"return",
"true",
";",
"}",
")",
";",
"// define properties",
"Object",
".",
"defineProperties",
"(",
"oneOf",
",",
"{",
"oneOf",
":",
"{",
"/**\n * @property\n * @name TypedOneOf#oneOf\n * @type {object}\n */",
"value",
":",
"schemas",
",",
"writable",
":",
"false",
"}",
"}",
")",
";",
"return",
"oneOf",
";",
"}"
] | Create a TypedOneOf instance.
@param {object} config
@returns {TypedOneOf}
@augments Typed
@constructor | [
"Create",
"a",
"TypedOneOf",
"instance",
"."
] | ed6b3ed88ffc72990acffb765232eaaee261afef | https://github.com/byu-oit/fully-typed/blob/ed6b3ed88ffc72990acffb765232eaaee261afef/bin/one-of.js#L29-L67 |
55,718 | melvincarvalho/rdf-shell | bin/mv.js | bin | function bin (argv) {
program.version(pkg.version)
.usage('[options] <sourceURI> <destURI>')
.parse(argv)
var sourceURI = program.args[0]
var destURI = program.args[1]
if (!sourceURI || !destURI) {
program.help()
}
shell.mv(sourceURI, destURI, function (err, res, uri) {
if (!err) {
debug(res)
} else {
console.error(err)
}
})
} | javascript | function bin (argv) {
program.version(pkg.version)
.usage('[options] <sourceURI> <destURI>')
.parse(argv)
var sourceURI = program.args[0]
var destURI = program.args[1]
if (!sourceURI || !destURI) {
program.help()
}
shell.mv(sourceURI, destURI, function (err, res, uri) {
if (!err) {
debug(res)
} else {
console.error(err)
}
})
} | [
"function",
"bin",
"(",
"argv",
")",
"{",
"program",
".",
"version",
"(",
"pkg",
".",
"version",
")",
".",
"usage",
"(",
"'[options] <sourceURI> <destURI>'",
")",
".",
"parse",
"(",
"argv",
")",
"var",
"sourceURI",
"=",
"program",
".",
"args",
"[",
"0",
"]",
"var",
"destURI",
"=",
"program",
".",
"args",
"[",
"1",
"]",
"if",
"(",
"!",
"sourceURI",
"||",
"!",
"destURI",
")",
"{",
"program",
".",
"help",
"(",
")",
"}",
"shell",
".",
"mv",
"(",
"sourceURI",
",",
"destURI",
",",
"function",
"(",
"err",
",",
"res",
",",
"uri",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"debug",
"(",
"res",
")",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"err",
")",
"}",
"}",
")",
"}"
] | mv as a command.
@param {Array} argv Arguments | [
"mv",
"as",
"a",
"command",
"."
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/bin/mv.js#L12-L31 |
55,719 | waka/node-bowl | lib/watcher.js | function(evt) {
if (evt !== 'change' && evt !== 'rename') {
return;
}
fs.stat(file, function(err, current) {
if (err) {
self.logger_.error(err.message);
self.emit('error.watch', err.message);
return;
}
if (current.size !== prev.size || +current.mtime > +prev.mtime) {
prev = current; // save new stats
self.logger_.debug(util.format('%s has been modified', file));
self.emit('watch');
}
});
} | javascript | function(evt) {
if (evt !== 'change' && evt !== 'rename') {
return;
}
fs.stat(file, function(err, current) {
if (err) {
self.logger_.error(err.message);
self.emit('error.watch', err.message);
return;
}
if (current.size !== prev.size || +current.mtime > +prev.mtime) {
prev = current; // save new stats
self.logger_.debug(util.format('%s has been modified', file));
self.emit('watch');
}
});
} | [
"function",
"(",
"evt",
")",
"{",
"if",
"(",
"evt",
"!==",
"'change'",
"&&",
"evt",
"!==",
"'rename'",
")",
"{",
"return",
";",
"}",
"fs",
".",
"stat",
"(",
"file",
",",
"function",
"(",
"err",
",",
"current",
")",
"{",
"if",
"(",
"err",
")",
"{",
"self",
".",
"logger_",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"self",
".",
"emit",
"(",
"'error.watch'",
",",
"err",
".",
"message",
")",
";",
"return",
";",
"}",
"if",
"(",
"current",
".",
"size",
"!==",
"prev",
".",
"size",
"||",
"+",
"current",
".",
"mtime",
">",
"+",
"prev",
".",
"mtime",
")",
"{",
"prev",
"=",
"current",
";",
"// save new stats",
"self",
".",
"logger_",
".",
"debug",
"(",
"util",
".",
"format",
"(",
"'%s has been modified'",
",",
"file",
")",
")",
";",
"self",
".",
"emit",
"(",
"'watch'",
")",
";",
"}",
"}",
")",
";",
"}"
] | filename is not supported when MacOSX | [
"filename",
"is",
"not",
"supported",
"when",
"MacOSX"
] | 671e8b16371a279e23b65bb9b2ff9dae047b6644 | https://github.com/waka/node-bowl/blob/671e8b16371a279e23b65bb9b2ff9dae047b6644/lib/watcher.js#L166-L182 |
|
55,720 | matterial/oknow | oknow.js | function(fn, syntheticArgs) {
var $this = this;
syntheticArgs = syntheticArgs || [];
/**
* Ensure to have it in the next event loop for better async
*/
var processResponder = function() {
try {
if (fn) {
/**
* Insert a done() or ok() argument to other needed arguments
*/
syntheticArgs.unshift(function() {
/**
* Call the next in queue
*/
$this.next.apply($this, arguments);
});
/**
* Call the function finally
*/
fn.apply(this, syntheticArgs);
} else {
syntheticArgs = syntheticArgs || [];
/**
* If no function passed, call the next in queue
*/
$this.next.apply(this, syntheticArgs);
}
} catch(e) {
/**
* An error caught is thrown directly to the catch handler, if any
*/
if (this.onCatch) {
this.onCatch(e);
} else {
throw e;
}
}
};
if (typeof process === "undefined") {
processResponder();
} else {
process.nextTick(processResponder);
}
/**
* Return self for chaining
*/
return this;
} | javascript | function(fn, syntheticArgs) {
var $this = this;
syntheticArgs = syntheticArgs || [];
/**
* Ensure to have it in the next event loop for better async
*/
var processResponder = function() {
try {
if (fn) {
/**
* Insert a done() or ok() argument to other needed arguments
*/
syntheticArgs.unshift(function() {
/**
* Call the next in queue
*/
$this.next.apply($this, arguments);
});
/**
* Call the function finally
*/
fn.apply(this, syntheticArgs);
} else {
syntheticArgs = syntheticArgs || [];
/**
* If no function passed, call the next in queue
*/
$this.next.apply(this, syntheticArgs);
}
} catch(e) {
/**
* An error caught is thrown directly to the catch handler, if any
*/
if (this.onCatch) {
this.onCatch(e);
} else {
throw e;
}
}
};
if (typeof process === "undefined") {
processResponder();
} else {
process.nextTick(processResponder);
}
/**
* Return self for chaining
*/
return this;
} | [
"function",
"(",
"fn",
",",
"syntheticArgs",
")",
"{",
"var",
"$this",
"=",
"this",
";",
"syntheticArgs",
"=",
"syntheticArgs",
"||",
"[",
"]",
";",
"/**\n\t\t * Ensure to have it in the next event loop for better async\n\t\t */",
"var",
"processResponder",
"=",
"function",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"fn",
")",
"{",
"/**\n\t\t\t\t\t * Insert a done() or ok() argument to other needed arguments\n\t\t\t\t\t */",
"syntheticArgs",
".",
"unshift",
"(",
"function",
"(",
")",
"{",
"/**\n\t\t\t\t\t\t * Call the next in queue\n\t\t\t\t\t\t */",
"$this",
".",
"next",
".",
"apply",
"(",
"$this",
",",
"arguments",
")",
";",
"}",
")",
";",
"/**\n\t\t\t\t\t * Call the function finally\n\t\t\t\t\t */",
"fn",
".",
"apply",
"(",
"this",
",",
"syntheticArgs",
")",
";",
"}",
"else",
"{",
"syntheticArgs",
"=",
"syntheticArgs",
"||",
"[",
"]",
";",
"/**\n\t\t\t\t\t * If no function passed, call the next in queue\n\t\t\t\t\t */",
"$this",
".",
"next",
".",
"apply",
"(",
"this",
",",
"syntheticArgs",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"/**\n\t\t\t\t * An error caught is thrown directly to the catch handler, if any\n\t\t\t\t */",
"if",
"(",
"this",
".",
"onCatch",
")",
"{",
"this",
".",
"onCatch",
"(",
"e",
")",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}",
";",
"if",
"(",
"typeof",
"process",
"===",
"\"undefined\"",
")",
"{",
"processResponder",
"(",
")",
";",
"}",
"else",
"{",
"process",
".",
"nextTick",
"(",
"processResponder",
")",
";",
"}",
"/**\n\t\t * Return self for chaining\n\t\t */",
"return",
"this",
";",
"}"
] | Executes a given function with provided arguments, and then calls the next one in queue
@param {Function} fn Function to execute
@param {Array} syntheticArgs Arguments to be passed to the function called
@return {Promise} Returns self object for chaining | [
"Executes",
"a",
"given",
"function",
"with",
"provided",
"arguments",
"and",
"then",
"calls",
"the",
"next",
"one",
"in",
"queue"
] | 71008691603c776f534eb53fb73a3a0eb137a52a | https://github.com/matterial/oknow/blob/71008691603c776f534eb53fb73a3a0eb137a52a/oknow.js#L47-L96 |
|
55,721 | matterial/oknow | oknow.js | function() {
try {
if (fn) {
/**
* Insert a done() or ok() argument to other needed arguments
*/
syntheticArgs.unshift(function() {
/**
* Call the next in queue
*/
$this.next.apply($this, arguments);
});
/**
* Call the function finally
*/
fn.apply(this, syntheticArgs);
} else {
syntheticArgs = syntheticArgs || [];
/**
* If no function passed, call the next in queue
*/
$this.next.apply(this, syntheticArgs);
}
} catch(e) {
/**
* An error caught is thrown directly to the catch handler, if any
*/
if (this.onCatch) {
this.onCatch(e);
} else {
throw e;
}
}
} | javascript | function() {
try {
if (fn) {
/**
* Insert a done() or ok() argument to other needed arguments
*/
syntheticArgs.unshift(function() {
/**
* Call the next in queue
*/
$this.next.apply($this, arguments);
});
/**
* Call the function finally
*/
fn.apply(this, syntheticArgs);
} else {
syntheticArgs = syntheticArgs || [];
/**
* If no function passed, call the next in queue
*/
$this.next.apply(this, syntheticArgs);
}
} catch(e) {
/**
* An error caught is thrown directly to the catch handler, if any
*/
if (this.onCatch) {
this.onCatch(e);
} else {
throw e;
}
}
} | [
"function",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"fn",
")",
"{",
"/**\n\t\t\t\t\t * Insert a done() or ok() argument to other needed arguments\n\t\t\t\t\t */",
"syntheticArgs",
".",
"unshift",
"(",
"function",
"(",
")",
"{",
"/**\n\t\t\t\t\t\t * Call the next in queue\n\t\t\t\t\t\t */",
"$this",
".",
"next",
".",
"apply",
"(",
"$this",
",",
"arguments",
")",
";",
"}",
")",
";",
"/**\n\t\t\t\t\t * Call the function finally\n\t\t\t\t\t */",
"fn",
".",
"apply",
"(",
"this",
",",
"syntheticArgs",
")",
";",
"}",
"else",
"{",
"syntheticArgs",
"=",
"syntheticArgs",
"||",
"[",
"]",
";",
"/**\n\t\t\t\t\t * If no function passed, call the next in queue\n\t\t\t\t\t */",
"$this",
".",
"next",
".",
"apply",
"(",
"this",
",",
"syntheticArgs",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"/**\n\t\t\t\t * An error caught is thrown directly to the catch handler, if any\n\t\t\t\t */",
"if",
"(",
"this",
".",
"onCatch",
")",
"{",
"this",
".",
"onCatch",
"(",
"e",
")",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}"
] | Ensure to have it in the next event loop for better async | [
"Ensure",
"to",
"have",
"it",
"in",
"the",
"next",
"event",
"loop",
"for",
"better",
"async"
] | 71008691603c776f534eb53fb73a3a0eb137a52a | https://github.com/matterial/oknow/blob/71008691603c776f534eb53fb73a3a0eb137a52a/oknow.js#L53-L86 |
|
55,722 | matterial/oknow | oknow.js | function(err) {
/**
* If err is an Error object, break the chain and call catch
*/
if (err && (err.constructor.name === "Error" || err.constructor.name === "TypeError") && this.onCatch) {
this.onCatch(err);
return;
}
var nextFn = this.fnStack.shift();
if (nextFn) {
/**
* Ensure arguments are passed as an Array
*/
var args = Array.prototype.slice.call(arguments);
return this.execute(nextFn.fn, args);
}
} | javascript | function(err) {
/**
* If err is an Error object, break the chain and call catch
*/
if (err && (err.constructor.name === "Error" || err.constructor.name === "TypeError") && this.onCatch) {
this.onCatch(err);
return;
}
var nextFn = this.fnStack.shift();
if (nextFn) {
/**
* Ensure arguments are passed as an Array
*/
var args = Array.prototype.slice.call(arguments);
return this.execute(nextFn.fn, args);
}
} | [
"function",
"(",
"err",
")",
"{",
"/**\n\t\t * If err is an Error object, break the chain and call catch\n\t\t */",
"if",
"(",
"err",
"&&",
"(",
"err",
".",
"constructor",
".",
"name",
"===",
"\"Error\"",
"||",
"err",
".",
"constructor",
".",
"name",
"===",
"\"TypeError\"",
")",
"&&",
"this",
".",
"onCatch",
")",
"{",
"this",
".",
"onCatch",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"nextFn",
"=",
"this",
".",
"fnStack",
".",
"shift",
"(",
")",
";",
"if",
"(",
"nextFn",
")",
"{",
"/**\n\t\t\t * Ensure arguments are passed as an Array\n\t\t\t */",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"return",
"this",
".",
"execute",
"(",
"nextFn",
".",
"fn",
",",
"args",
")",
";",
"}",
"}"
] | Calls the next function in queue, or calls the function passed in `catch` if error occurs
@param {Error} err Error object optionally passed
@return {Promise} Return self for chaining | [
"Calls",
"the",
"next",
"function",
"in",
"queue",
"or",
"calls",
"the",
"function",
"passed",
"in",
"catch",
"if",
"error",
"occurs"
] | 71008691603c776f534eb53fb73a3a0eb137a52a | https://github.com/matterial/oknow/blob/71008691603c776f534eb53fb73a3a0eb137a52a/oknow.js#L111-L128 |
|
55,723 | 4ndr01d3/js-components | biojs-rest-jsdas/src/jsdas.js | function(xml, command, version) {
var formatVersion = version || JSDAS.Formats.current;
var format = JSDAS.Formats[formatVersion][command];
var json = JSDAS.Parser.parseElement(xml, format);
return json;
} | javascript | function(xml, command, version) {
var formatVersion = version || JSDAS.Formats.current;
var format = JSDAS.Formats[formatVersion][command];
var json = JSDAS.Parser.parseElement(xml, format);
return json;
} | [
"function",
"(",
"xml",
",",
"command",
",",
"version",
")",
"{",
"var",
"formatVersion",
"=",
"version",
"||",
"JSDAS",
".",
"Formats",
".",
"current",
";",
"var",
"format",
"=",
"JSDAS",
".",
"Formats",
"[",
"formatVersion",
"]",
"[",
"command",
"]",
";",
"var",
"json",
"=",
"JSDAS",
".",
"Parser",
".",
"parseElement",
"(",
"xml",
",",
"format",
")",
";",
"return",
"json",
";",
"}"
] | Private methods Given a valid DAS XML, it returns its translation to JSON | [
"Private",
"methods",
"Given",
"a",
"valid",
"DAS",
"XML",
"it",
"returns",
"its",
"translation",
"to",
"JSON"
] | d6abbc49a79fe89ba9b1b1ef2307790693900440 | https://github.com/4ndr01d3/js-components/blob/d6abbc49a79fe89ba9b1b1ef2307790693900440/biojs-rest-jsdas/src/jsdas.js#L27-L32 |
|
55,724 | 4ndr01d3/js-components | biojs-rest-jsdas/src/jsdas.js | function(xml, format) {
var out = {};
//The Document object does not have all the functionality of a standard node (i.e. it can't have attributes).
//So, if we are in the Document element, move to its ¿¿only?? child, the root.
if(xml.nodeType == 9) { //detect the Document node type
xml = xml.firstChild;
while(xml.nodeType != 1 && xml.nextSibling) //Document nodes (9) can't have text (3) nodes as children. Test only for elements (1)
xml = xml.nextSibling;
}
//get properties
if (format.properties) {
var props = format.properties;
for (var nprop = 0, lenprop = props.length; nprop < lenprop; ++nprop) {
var f = props[nprop];
var name = f.jsname || f.name;
out[name] = this.parseProperty(xml, f);
}
}
//get childs
if (format.childs) {
var ch = format.childs;
if (ch === 'text') { //if thextual child
/*
* Due to browser compatibility the textContent may come from this 3 different methods:
* xml.innerText = IE
* xml.textContent = Firefox
* xml.text = IE
*/
out['textContent'] = xml.innerText || xml.textContent || xml.text;
}
else { //childs different than text
for (var i = 0, len = ch.length; i < len; ++i) {
var f = ch[i];
//var els = xml.getElementsByTagName(f.tagname);
//Hack: since getElementsByTagName is case sensitive for XML documents and DAS XMLs can be found
//in different casing, use a regular expresion tofilter the elements.
//FIX: This is an unefficient parsing method. Other ways should be explored.
var els = [];
var all_els = xml.getElementsByTagName('*');
for(var iael=0, lenael=all_els.length; iael<lenael; ++iael) {
var curr_node = all_els[iael];
if(new RegExp('^'+f.tagname+'$', 'i').test(curr_node.nodeName)) {
els.push(curr_node);
}
}
//End of tag casing hack
if (f.mandatory && this.checkMandatoryElements && (!els || els.length == 0)) { //if a mandatory element is not present...
//JSDAS.Console.log("Mandatory element is not present.");
}
if (els.length>0) { //if there are elements of the given tagName
var name = f.jsname || f.tagname;
if (f.multiple) { //if its a multiple instance child, create an array and push all instances
out[name] = [];
for (var iel = 0, lenel = els.length; iel < lenel; ++iel) {
out[name].push(this.parseElement(els[iel], f));
}
}
else {
out[name] = this.parseElement(els[0], f);
}
}
}
}
}
return out;
} | javascript | function(xml, format) {
var out = {};
//The Document object does not have all the functionality of a standard node (i.e. it can't have attributes).
//So, if we are in the Document element, move to its ¿¿only?? child, the root.
if(xml.nodeType == 9) { //detect the Document node type
xml = xml.firstChild;
while(xml.nodeType != 1 && xml.nextSibling) //Document nodes (9) can't have text (3) nodes as children. Test only for elements (1)
xml = xml.nextSibling;
}
//get properties
if (format.properties) {
var props = format.properties;
for (var nprop = 0, lenprop = props.length; nprop < lenprop; ++nprop) {
var f = props[nprop];
var name = f.jsname || f.name;
out[name] = this.parseProperty(xml, f);
}
}
//get childs
if (format.childs) {
var ch = format.childs;
if (ch === 'text') { //if thextual child
/*
* Due to browser compatibility the textContent may come from this 3 different methods:
* xml.innerText = IE
* xml.textContent = Firefox
* xml.text = IE
*/
out['textContent'] = xml.innerText || xml.textContent || xml.text;
}
else { //childs different than text
for (var i = 0, len = ch.length; i < len; ++i) {
var f = ch[i];
//var els = xml.getElementsByTagName(f.tagname);
//Hack: since getElementsByTagName is case sensitive for XML documents and DAS XMLs can be found
//in different casing, use a regular expresion tofilter the elements.
//FIX: This is an unefficient parsing method. Other ways should be explored.
var els = [];
var all_els = xml.getElementsByTagName('*');
for(var iael=0, lenael=all_els.length; iael<lenael; ++iael) {
var curr_node = all_els[iael];
if(new RegExp('^'+f.tagname+'$', 'i').test(curr_node.nodeName)) {
els.push(curr_node);
}
}
//End of tag casing hack
if (f.mandatory && this.checkMandatoryElements && (!els || els.length == 0)) { //if a mandatory element is not present...
//JSDAS.Console.log("Mandatory element is not present.");
}
if (els.length>0) { //if there are elements of the given tagName
var name = f.jsname || f.tagname;
if (f.multiple) { //if its a multiple instance child, create an array and push all instances
out[name] = [];
for (var iel = 0, lenel = els.length; iel < lenel; ++iel) {
out[name].push(this.parseElement(els[iel], f));
}
}
else {
out[name] = this.parseElement(els[0], f);
}
}
}
}
}
return out;
} | [
"function",
"(",
"xml",
",",
"format",
")",
"{",
"var",
"out",
"=",
"{",
"}",
";",
"//The Document object does not have all the functionality of a standard node (i.e. it can't have attributes).",
"//So, if we are in the Document element, move to its ¿¿only?? child, the root.",
"if",
"(",
"xml",
".",
"nodeType",
"==",
"9",
")",
"{",
"//detect the Document node type",
"xml",
"=",
"xml",
".",
"firstChild",
";",
"while",
"(",
"xml",
".",
"nodeType",
"!=",
"1",
"&&",
"xml",
".",
"nextSibling",
")",
"//Document nodes (9) can't have text (3) nodes as children. Test only for elements (1)",
"xml",
"=",
"xml",
".",
"nextSibling",
";",
"}",
"//get properties",
"if",
"(",
"format",
".",
"properties",
")",
"{",
"var",
"props",
"=",
"format",
".",
"properties",
";",
"for",
"(",
"var",
"nprop",
"=",
"0",
",",
"lenprop",
"=",
"props",
".",
"length",
";",
"nprop",
"<",
"lenprop",
";",
"++",
"nprop",
")",
"{",
"var",
"f",
"=",
"props",
"[",
"nprop",
"]",
";",
"var",
"name",
"=",
"f",
".",
"jsname",
"||",
"f",
".",
"name",
";",
"out",
"[",
"name",
"]",
"=",
"this",
".",
"parseProperty",
"(",
"xml",
",",
"f",
")",
";",
"}",
"}",
"//get childs",
"if",
"(",
"format",
".",
"childs",
")",
"{",
"var",
"ch",
"=",
"format",
".",
"childs",
";",
"if",
"(",
"ch",
"===",
"'text'",
")",
"{",
"//if thextual child",
"/*\n\t\t\t\t * Due to browser compatibility the textContent may come from this 3 different methods:\n\t\t\t\t * xml.innerText = IE\n\t\t\t\t * xml.textContent = Firefox\n\t\t\t\t * xml.text = IE\n\t\t\t\t */",
"out",
"[",
"'textContent'",
"]",
"=",
"xml",
".",
"innerText",
"||",
"xml",
".",
"textContent",
"||",
"xml",
".",
"text",
";",
"}",
"else",
"{",
"//childs different than text",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"ch",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"f",
"=",
"ch",
"[",
"i",
"]",
";",
"//var els = xml.getElementsByTagName(f.tagname);",
"//Hack: since getElementsByTagName is case sensitive for XML documents and DAS XMLs can be found ",
"//in different casing, use a regular expresion tofilter the elements.",
"//FIX: This is an unefficient parsing method. Other ways should be explored.",
"var",
"els",
"=",
"[",
"]",
";",
"var",
"all_els",
"=",
"xml",
".",
"getElementsByTagName",
"(",
"'*'",
")",
";",
"for",
"(",
"var",
"iael",
"=",
"0",
",",
"lenael",
"=",
"all_els",
".",
"length",
";",
"iael",
"<",
"lenael",
";",
"++",
"iael",
")",
"{",
"var",
"curr_node",
"=",
"all_els",
"[",
"iael",
"]",
";",
"if",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"f",
".",
"tagname",
"+",
"'$'",
",",
"'i'",
")",
".",
"test",
"(",
"curr_node",
".",
"nodeName",
")",
")",
"{",
"els",
".",
"push",
"(",
"curr_node",
")",
";",
"}",
"}",
"//End of tag casing hack",
"if",
"(",
"f",
".",
"mandatory",
"&&",
"this",
".",
"checkMandatoryElements",
"&&",
"(",
"!",
"els",
"||",
"els",
".",
"length",
"==",
"0",
")",
")",
"{",
"//if a mandatory element is not present...",
"//JSDAS.Console.log(\"Mandatory element is not present.\");",
"}",
"if",
"(",
"els",
".",
"length",
">",
"0",
")",
"{",
"//if there are elements of the given tagName",
"var",
"name",
"=",
"f",
".",
"jsname",
"||",
"f",
".",
"tagname",
";",
"if",
"(",
"f",
".",
"multiple",
")",
"{",
"//if its a multiple instance child, create an array and push all instances",
"out",
"[",
"name",
"]",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"iel",
"=",
"0",
",",
"lenel",
"=",
"els",
".",
"length",
";",
"iel",
"<",
"lenel",
";",
"++",
"iel",
")",
"{",
"out",
"[",
"name",
"]",
".",
"push",
"(",
"this",
".",
"parseElement",
"(",
"els",
"[",
"iel",
"]",
",",
"f",
")",
")",
";",
"}",
"}",
"else",
"{",
"out",
"[",
"name",
"]",
"=",
"this",
".",
"parseElement",
"(",
"els",
"[",
"0",
"]",
",",
"f",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"out",
";",
"}"
] | true to raise an error if a mandatory element is not present Private functions (actually not really private. just not API documented | [
"true",
"to",
"raise",
"an",
"error",
"if",
"a",
"mandatory",
"element",
"is",
"not",
"present",
"Private",
"functions",
"(",
"actually",
"not",
"really",
"private",
".",
"just",
"not",
"API",
"documented"
] | d6abbc49a79fe89ba9b1b1ef2307790693900440 | https://github.com/4ndr01d3/js-components/blob/d6abbc49a79fe89ba9b1b1ef2307790693900440/biojs-rest-jsdas/src/jsdas.js#L2222-L2289 |
|
55,725 | 4ndr01d3/js-components | biojs-rest-jsdas/src/jsdas.js | function(url, callback, errorcallback){
if (!this.initialized) {
this.initialize();
}
var xmlloader = JSDAS.XMLLoader; //get a reference to myself
var usingCORS = true;
var xhr = this.xhrCORS('GET', url);
if(!xhr) { //if the browser is not CORS capable, fallback to proxy if available
if(this.proxyURL) {
var xhr = this.xhr();
xhr.open('GET', this.proxyURL+'?url='+url, true);
usingCORS = false;
} else {
errorcallback && errorcallback({id: 'no_proxy', msg: "Cross-Origin requests are not supported but no proxy has been defined"});
}
}
//At this point, we've got a valid XHR
//xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
//xhr.setRequestHeader("Accept", "application/xml, text/xml");
var xmlloader = this; //necessary so the closures get the variable
var change = function(xhr){
if (xhr && (xhr.readyState == 4)) {
if (xmlloader.httpSuccess(xhr)) {
processResponse(xhr);
}
else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
xhr=undefined;
usingCORS = false;
var new_xhr = xmlloader.xhr();
new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
new_xhr.onreadystatechange = function() {change(new_xhr);}
new_xhr.send(null);
} else {
errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
}
}
//to prevent IE memory leaks
xhr = undefined;
}
};
var processResponse = function(xhr) {
//WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated.
//var ct = xhr.getResponseHeader("content-type");
//var xml = ct && ct.indexOf("xml") >= 0;
//if (xml) {
var data = xhr.responseXML;
if(!data) { //This block is here since we cannot rely on content type headers
errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
}
if(data.documentElement.nodeName != 'parsererror') {
callback(data);
return;
}
//} //if anything went wrong, the document was not XML
//errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
};
xhr.onreadystatechange = function() {change(xhr);};
// Send the data
try {
xhr.send(null);
} catch(e) {
//This code will rarely be called. Only when there's a problem on sernding the request.
if(usingCORS && this.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
var xhr = this.xhr();
xhr.open('GET', this.proxyURL+'?url='+url, true);
xhr.onreadystatechange = function() {change(xhr);}
try {
xhr.send(null);
} catch(e) {
errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
}
} else {
errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
}
}
} | javascript | function(url, callback, errorcallback){
if (!this.initialized) {
this.initialize();
}
var xmlloader = JSDAS.XMLLoader; //get a reference to myself
var usingCORS = true;
var xhr = this.xhrCORS('GET', url);
if(!xhr) { //if the browser is not CORS capable, fallback to proxy if available
if(this.proxyURL) {
var xhr = this.xhr();
xhr.open('GET', this.proxyURL+'?url='+url, true);
usingCORS = false;
} else {
errorcallback && errorcallback({id: 'no_proxy', msg: "Cross-Origin requests are not supported but no proxy has been defined"});
}
}
//At this point, we've got a valid XHR
//xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
//xhr.setRequestHeader("Accept", "application/xml, text/xml");
var xmlloader = this; //necessary so the closures get the variable
var change = function(xhr){
if (xhr && (xhr.readyState == 4)) {
if (xmlloader.httpSuccess(xhr)) {
processResponse(xhr);
}
else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
xhr=undefined;
usingCORS = false;
var new_xhr = xmlloader.xhr();
new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
new_xhr.onreadystatechange = function() {change(new_xhr);}
new_xhr.send(null);
} else {
errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
}
}
//to prevent IE memory leaks
xhr = undefined;
}
};
var processResponse = function(xhr) {
//WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated.
//var ct = xhr.getResponseHeader("content-type");
//var xml = ct && ct.indexOf("xml") >= 0;
//if (xml) {
var data = xhr.responseXML;
if(!data) { //This block is here since we cannot rely on content type headers
errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
}
if(data.documentElement.nodeName != 'parsererror') {
callback(data);
return;
}
//} //if anything went wrong, the document was not XML
//errorcallback && errorcallback({id: 'not_xml', msg: "The response was not XML"});
};
xhr.onreadystatechange = function() {change(xhr);};
// Send the data
try {
xhr.send(null);
} catch(e) {
//This code will rarely be called. Only when there's a problem on sernding the request.
if(usingCORS && this.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
var xhr = this.xhr();
xhr.open('GET', this.proxyURL+'?url='+url, true);
xhr.onreadystatechange = function() {change(xhr);}
try {
xhr.send(null);
} catch(e) {
errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
}
} else {
errorcallback && errorcallback({id: 'sending_error', msg: "There was an error when sending the request"});
}
}
} | [
"function",
"(",
"url",
",",
"callback",
",",
"errorcallback",
")",
"{",
"if",
"(",
"!",
"this",
".",
"initialized",
")",
"{",
"this",
".",
"initialize",
"(",
")",
";",
"}",
"var",
"xmlloader",
"=",
"JSDAS",
".",
"XMLLoader",
";",
"//get a reference to myself",
"var",
"usingCORS",
"=",
"true",
";",
"var",
"xhr",
"=",
"this",
".",
"xhrCORS",
"(",
"'GET'",
",",
"url",
")",
";",
"if",
"(",
"!",
"xhr",
")",
"{",
"//if the browser is not CORS capable, fallback to proxy if available",
"if",
"(",
"this",
".",
"proxyURL",
")",
"{",
"var",
"xhr",
"=",
"this",
".",
"xhr",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"this",
".",
"proxyURL",
"+",
"'?url='",
"+",
"url",
",",
"true",
")",
";",
"usingCORS",
"=",
"false",
";",
"}",
"else",
"{",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"'no_proxy'",
",",
"msg",
":",
"\"Cross-Origin requests are not supported but no proxy has been defined\"",
"}",
")",
";",
"}",
"}",
"//At this point, we've got a valid XHR",
"//xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");",
"//xhr.setRequestHeader(\"Accept\", \"application/xml, text/xml\");",
"var",
"xmlloader",
"=",
"this",
";",
"//necessary so the closures get the variable",
"var",
"change",
"=",
"function",
"(",
"xhr",
")",
"{",
"if",
"(",
"xhr",
"&&",
"(",
"xhr",
".",
"readyState",
"==",
"4",
")",
")",
"{",
"if",
"(",
"xmlloader",
".",
"httpSuccess",
"(",
"xhr",
")",
")",
"{",
"processResponse",
"(",
"xhr",
")",
";",
"}",
"else",
"{",
"//if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring",
"if",
"(",
"usingCORS",
"&&",
"xmlloader",
".",
"proxyURL",
")",
"{",
"//if it failed when using CORS and we've got a proxy, try to get the data via the proxy",
"xhr",
"=",
"undefined",
";",
"usingCORS",
"=",
"false",
";",
"var",
"new_xhr",
"=",
"xmlloader",
".",
"xhr",
"(",
")",
";",
"new_xhr",
".",
"open",
"(",
"'GET'",
",",
"xmlloader",
".",
"proxyURL",
"+",
"'?url='",
"+",
"url",
",",
"true",
")",
";",
"new_xhr",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"change",
"(",
"new_xhr",
")",
";",
"}",
"new_xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"else",
"{",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"\"xmlhttprequest_error\"",
",",
"msg",
":",
"xhr",
".",
"status",
"}",
")",
";",
"}",
"}",
"//to prevent IE memory leaks",
"xhr",
"=",
"undefined",
";",
"}",
"}",
";",
"var",
"processResponse",
"=",
"function",
"(",
"xhr",
")",
"{",
"//WARNING: Since Uniprot (and maybe others) do not respond with a correct content-type, we cannot check it here. Should be reactivated as soon as the servers are updated.",
"//var ct = xhr.getResponseHeader(\"content-type\");",
"//var xml = ct && ct.indexOf(\"xml\") >= 0;",
"//if (xml) {",
"var",
"data",
"=",
"xhr",
".",
"responseXML",
";",
"if",
"(",
"!",
"data",
")",
"{",
"//This block is here since we cannot rely on content type headers",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"'not_xml'",
",",
"msg",
":",
"\"The response was not XML\"",
"}",
")",
";",
"}",
"if",
"(",
"data",
".",
"documentElement",
".",
"nodeName",
"!=",
"'parsererror'",
")",
"{",
"callback",
"(",
"data",
")",
";",
"return",
";",
"}",
"//} //if anything went wrong, the document was not XML",
"//errorcallback && errorcallback({id: 'not_xml', msg: \"The response was not XML\"});",
"}",
";",
"xhr",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"change",
"(",
"xhr",
")",
";",
"}",
";",
"// Send the data",
"try",
"{",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"//This code will rarely be called. Only when there's a problem on sernding the request.",
"if",
"(",
"usingCORS",
"&&",
"this",
".",
"proxyURL",
")",
"{",
"//if it failed when using CORS and we've got a proxy, try to get the data via the proxy",
"var",
"xhr",
"=",
"this",
".",
"xhr",
"(",
")",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"this",
".",
"proxyURL",
"+",
"'?url='",
"+",
"url",
",",
"true",
")",
";",
"xhr",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"change",
"(",
"xhr",
")",
";",
"}",
"try",
"{",
"xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"'sending_error'",
",",
"msg",
":",
"\"There was an error when sending the request\"",
"}",
")",
";",
"}",
"}",
"else",
"{",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"'sending_error'",
",",
"msg",
":",
"\"There was an error when sending the request\"",
"}",
")",
";",
"}",
"}",
"}"
] | This function loads an external XML using a proxy on the server to comply with the SOP
@param {Object} url
@param {Object} callback | [
"This",
"function",
"loads",
"an",
"external",
"XML",
"using",
"a",
"proxy",
"on",
"the",
"server",
"to",
"comply",
"with",
"the",
"SOP"
] | d6abbc49a79fe89ba9b1b1ef2307790693900440 | https://github.com/4ndr01d3/js-components/blob/d6abbc49a79fe89ba9b1b1ef2307790693900440/biojs-rest-jsdas/src/jsdas.js#L2374-L2458 |
|
55,726 | 4ndr01d3/js-components | biojs-rest-jsdas/src/jsdas.js | function(xhr){
if (xhr && (xhr.readyState == 4)) {
if (xmlloader.httpSuccess(xhr)) {
processResponse(xhr);
}
else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
xhr=undefined;
usingCORS = false;
var new_xhr = xmlloader.xhr();
new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
new_xhr.onreadystatechange = function() {change(new_xhr);}
new_xhr.send(null);
} else {
errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
}
}
//to prevent IE memory leaks
xhr = undefined;
}
} | javascript | function(xhr){
if (xhr && (xhr.readyState == 4)) {
if (xmlloader.httpSuccess(xhr)) {
processResponse(xhr);
}
else { //if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring
if(usingCORS && xmlloader.proxyURL) { //if it failed when using CORS and we've got a proxy, try to get the data via the proxy
xhr=undefined;
usingCORS = false;
var new_xhr = xmlloader.xhr();
new_xhr.open('GET', xmlloader.proxyURL+'?url='+url, true);
new_xhr.onreadystatechange = function() {change(new_xhr);}
new_xhr.send(null);
} else {
errorcallback && errorcallback({id: "xmlhttprequest_error", msg: xhr.status});
}
}
//to prevent IE memory leaks
xhr = undefined;
}
} | [
"function",
"(",
"xhr",
")",
"{",
"if",
"(",
"xhr",
"&&",
"(",
"xhr",
".",
"readyState",
"==",
"4",
")",
")",
"{",
"if",
"(",
"xmlloader",
".",
"httpSuccess",
"(",
"xhr",
")",
")",
"{",
"processResponse",
"(",
"xhr",
")",
";",
"}",
"else",
"{",
"//if it failed, it mighht be that the source has no CORS enabled. In such case, fallback to proxy before erroring",
"if",
"(",
"usingCORS",
"&&",
"xmlloader",
".",
"proxyURL",
")",
"{",
"//if it failed when using CORS and we've got a proxy, try to get the data via the proxy",
"xhr",
"=",
"undefined",
";",
"usingCORS",
"=",
"false",
";",
"var",
"new_xhr",
"=",
"xmlloader",
".",
"xhr",
"(",
")",
";",
"new_xhr",
".",
"open",
"(",
"'GET'",
",",
"xmlloader",
".",
"proxyURL",
"+",
"'?url='",
"+",
"url",
",",
"true",
")",
";",
"new_xhr",
".",
"onreadystatechange",
"=",
"function",
"(",
")",
"{",
"change",
"(",
"new_xhr",
")",
";",
"}",
"new_xhr",
".",
"send",
"(",
"null",
")",
";",
"}",
"else",
"{",
"errorcallback",
"&&",
"errorcallback",
"(",
"{",
"id",
":",
"\"xmlhttprequest_error\"",
",",
"msg",
":",
"xhr",
".",
"status",
"}",
")",
";",
"}",
"}",
"//to prevent IE memory leaks",
"xhr",
"=",
"undefined",
";",
"}",
"}"
] | necessary so the closures get the variable | [
"necessary",
"so",
"the",
"closures",
"get",
"the",
"variable"
] | d6abbc49a79fe89ba9b1b1ef2307790693900440 | https://github.com/4ndr01d3/js-components/blob/d6abbc49a79fe89ba9b1b1ef2307790693900440/biojs-rest-jsdas/src/jsdas.js#L2399-L2419 |
|
55,727 | epii-io/epii-node-render | recipe/view.js | writeLaunchCode | function writeLaunchCode(config) {
var { name, stub } = config.holder
if (!name || !stub) {
throw new Error('invalid name or stub')
}
var code = `
;(function () {
var root = document.getElementById('${name}');
if (!root) throw new Error('undefined ${stub} root');
var view = window.${stub}.entry;
if (!view) throw new Error('undefined ${stub} view');
ReactDOM.render(React.createElement(view), root);
}());
`.replace(/\n|(\s{2})/g, '')
var output = path.join(config.$path.target.client, 'launch.js')
fs.writeFileSync(output, code, 'utf8')
logger.done('view ::', 'launch code generated')
} | javascript | function writeLaunchCode(config) {
var { name, stub } = config.holder
if (!name || !stub) {
throw new Error('invalid name or stub')
}
var code = `
;(function () {
var root = document.getElementById('${name}');
if (!root) throw new Error('undefined ${stub} root');
var view = window.${stub}.entry;
if (!view) throw new Error('undefined ${stub} view');
ReactDOM.render(React.createElement(view), root);
}());
`.replace(/\n|(\s{2})/g, '')
var output = path.join(config.$path.target.client, 'launch.js')
fs.writeFileSync(output, code, 'utf8')
logger.done('view ::', 'launch code generated')
} | [
"function",
"writeLaunchCode",
"(",
"config",
")",
"{",
"var",
"{",
"name",
",",
"stub",
"}",
"=",
"config",
".",
"holder",
"if",
"(",
"!",
"name",
"||",
"!",
"stub",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid name or stub'",
")",
"}",
"var",
"code",
"=",
"`",
"${",
"name",
"}",
"${",
"stub",
"}",
"${",
"stub",
"}",
"${",
"stub",
"}",
"`",
".",
"replace",
"(",
"/",
"\\n|(\\s{2})",
"/",
"g",
",",
"''",
")",
"var",
"output",
"=",
"path",
".",
"join",
"(",
"config",
".",
"$path",
".",
"target",
".",
"client",
",",
"'launch.js'",
")",
"fs",
".",
"writeFileSync",
"(",
"output",
",",
"code",
",",
"'utf8'",
")",
"logger",
".",
"done",
"(",
"'view ::'",
",",
"'launch code generated'",
")",
"}"
] | write launch code
@param {Object} config | [
"write",
"launch",
"code"
] | e8afa57066251e173b3a6455d47218c95f30f563 | https://github.com/epii-io/epii-node-render/blob/e8afa57066251e173b3a6455d47218c95f30f563/recipe/view.js#L49-L66 |
55,728 | mattdesl/simplex-sampler | index.js | NoiseSampler | function NoiseSampler(size) {
if (!size)
throw "no size specified to NoiseSampler";
this.size = size;
this.scale = 1;
this.offset = 0;
this.smooth = true;
this.seamless = false;
// this.scales = [
// 10, 0.1, 0.2, 1
// ];
// this.strengths = [
// 0.1, 0.3, 0.2, 1
// ];
this.scales = [
1, 20, 0.5
];
this.strengths = [
1, 0.1, 0.5
];
this.data = new Float32Array(this.size * this.size);
} | javascript | function NoiseSampler(size) {
if (!size)
throw "no size specified to NoiseSampler";
this.size = size;
this.scale = 1;
this.offset = 0;
this.smooth = true;
this.seamless = false;
// this.scales = [
// 10, 0.1, 0.2, 1
// ];
// this.strengths = [
// 0.1, 0.3, 0.2, 1
// ];
this.scales = [
1, 20, 0.5
];
this.strengths = [
1, 0.1, 0.5
];
this.data = new Float32Array(this.size * this.size);
} | [
"function",
"NoiseSampler",
"(",
"size",
")",
"{",
"if",
"(",
"!",
"size",
")",
"throw",
"\"no size specified to NoiseSampler\"",
";",
"this",
".",
"size",
"=",
"size",
";",
"this",
".",
"scale",
"=",
"1",
";",
"this",
".",
"offset",
"=",
"0",
";",
"this",
".",
"smooth",
"=",
"true",
";",
"this",
".",
"seamless",
"=",
"false",
";",
"// this.scales = [",
"// 10, 0.1, 0.2, 1",
"// ];",
"// this.strengths = [",
"// 0.1, 0.3, 0.2, 1",
"// ];",
"this",
".",
"scales",
"=",
"[",
"1",
",",
"20",
",",
"0.5",
"]",
";",
"this",
".",
"strengths",
"=",
"[",
"1",
",",
"0.1",
",",
"0.5",
"]",
";",
"this",
".",
"data",
"=",
"new",
"Float32Array",
"(",
"this",
".",
"size",
"*",
"this",
".",
"size",
")",
";",
"}"
] | Samples a 1-component texture, noise in this case | [
"Samples",
"a",
"1",
"-",
"component",
"texture",
"noise",
"in",
"this",
"case"
] | 5900d05b77f876b2d54b88d3017c31b8d4a77587 | https://github.com/mattdesl/simplex-sampler/blob/5900d05b77f876b2d54b88d3017c31b8d4a77587/index.js#L21-L46 |
55,729 | mattdesl/simplex-sampler | index.js | function(x, y) {
//avoid negatives
if (this.seamless) {
x = (x%this.size + this.size)%this.size
y = (y%this.size + this.size)%this.size
} else {
x = clamp(x, 0, this.size)
y = clamp(y, 0, this.size)
}
if (this.smooth)
return sampling.bilinear(this.data, this.size, this.size, x, y);
else
return sampling.nearest(this.data, this.size, this.size, x, y);
} | javascript | function(x, y) {
//avoid negatives
if (this.seamless) {
x = (x%this.size + this.size)%this.size
y = (y%this.size + this.size)%this.size
} else {
x = clamp(x, 0, this.size)
y = clamp(y, 0, this.size)
}
if (this.smooth)
return sampling.bilinear(this.data, this.size, this.size, x, y);
else
return sampling.nearest(this.data, this.size, this.size, x, y);
} | [
"function",
"(",
"x",
",",
"y",
")",
"{",
"//avoid negatives",
"if",
"(",
"this",
".",
"seamless",
")",
"{",
"x",
"=",
"(",
"x",
"%",
"this",
".",
"size",
"+",
"this",
".",
"size",
")",
"%",
"this",
".",
"size",
"y",
"=",
"(",
"y",
"%",
"this",
".",
"size",
"+",
"this",
".",
"size",
")",
"%",
"this",
".",
"size",
"}",
"else",
"{",
"x",
"=",
"clamp",
"(",
"x",
",",
"0",
",",
"this",
".",
"size",
")",
"y",
"=",
"clamp",
"(",
"y",
",",
"0",
",",
"this",
".",
"size",
")",
"}",
"if",
"(",
"this",
".",
"smooth",
")",
"return",
"sampling",
".",
"bilinear",
"(",
"this",
".",
"data",
",",
"this",
".",
"size",
",",
"this",
".",
"size",
",",
"x",
",",
"y",
")",
";",
"else",
"return",
"sampling",
".",
"nearest",
"(",
"this",
".",
"data",
",",
"this",
".",
"size",
",",
"this",
".",
"size",
",",
"x",
",",
"y",
")",
";",
"}"
] | returns a float, -1 to 1 | [
"returns",
"a",
"float",
"-",
"1",
"to",
"1"
] | 5900d05b77f876b2d54b88d3017c31b8d4a77587 | https://github.com/mattdesl/simplex-sampler/blob/5900d05b77f876b2d54b88d3017c31b8d4a77587/index.js#L99-L113 |
|
55,730 | darkobits/interface | src/interface.js | is | function is (constructor, value) {
return value !== null && (value.constructor === constructor || value instanceof constructor);
} | javascript | function is (constructor, value) {
return value !== null && (value.constructor === constructor || value instanceof constructor);
} | [
"function",
"is",
"(",
"constructor",
",",
"value",
")",
"{",
"return",
"value",
"!==",
"null",
"&&",
"(",
"value",
".",
"constructor",
"===",
"constructor",
"||",
"value",
"instanceof",
"constructor",
")",
";",
"}"
] | Determines if 'value' is an instance of 'constructor'.
@private
@param {object} constructor
@param {*} value
@return {boolean} | [
"Determines",
"if",
"value",
"is",
"an",
"instance",
"of",
"constructor",
"."
] | 819aec7ca45484cdd53208864d8fdaad96dad3c2 | https://github.com/darkobits/interface/blob/819aec7ca45484cdd53208864d8fdaad96dad3c2/src/interface.js#L20-L22 |
55,731 | usco/usco-stl-parser | dist/utils.js | isDataBinaryRobust | function isDataBinaryRobust(data) {
// console.log('data is binary ?')
var patternVertex = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
var text = ensureString(data);
var isBinary = patternVertex.exec(text) === null;
return isBinary;
} | javascript | function isDataBinaryRobust(data) {
// console.log('data is binary ?')
var patternVertex = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
var text = ensureString(data);
var isBinary = patternVertex.exec(text) === null;
return isBinary;
} | [
"function",
"isDataBinaryRobust",
"(",
"data",
")",
"{",
"// console.log('data is binary ?')",
"var",
"patternVertex",
"=",
"/",
"vertex[\\s]+([\\-+]?[0-9]+\\.?[0-9]*([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+[\\s]+([\\-+]?[0-9]*\\.?[0-9]+([eE][\\-+]?[0-9]+)?)+",
"/",
"g",
";",
"var",
"text",
"=",
"ensureString",
"(",
"data",
")",
";",
"var",
"isBinary",
"=",
"patternVertex",
".",
"exec",
"(",
"text",
")",
"===",
"null",
";",
"return",
"isBinary",
";",
"}"
] | a more robust version of the above, that does NOT require the whole file | [
"a",
"more",
"robust",
"version",
"of",
"the",
"above",
"that",
"does",
"NOT",
"require",
"the",
"whole",
"file"
] | 49eb402f124723d8f74cc67f24a7017c2b99bca4 | https://github.com/usco/usco-stl-parser/blob/49eb402f124723d8f74cc67f24a7017c2b99bca4/dist/utils.js#L53-L59 |
55,732 | Industryswarm/isnode-mod-data | lib/mongodb/mongodb-core/lib/auth/scram.js | function(err, r) {
if (err) {
numberOfValidConnections = numberOfValidConnections - 1;
errorObject = err;
return false;
} else if (r.result['$err']) {
errorObject = r.result;
return false;
} else if (r.result['errmsg']) {
errorObject = r.result;
return false;
} else {
numberOfValidConnections = numberOfValidConnections + 1;
}
return true;
} | javascript | function(err, r) {
if (err) {
numberOfValidConnections = numberOfValidConnections - 1;
errorObject = err;
return false;
} else if (r.result['$err']) {
errorObject = r.result;
return false;
} else if (r.result['errmsg']) {
errorObject = r.result;
return false;
} else {
numberOfValidConnections = numberOfValidConnections + 1;
}
return true;
} | [
"function",
"(",
"err",
",",
"r",
")",
"{",
"if",
"(",
"err",
")",
"{",
"numberOfValidConnections",
"=",
"numberOfValidConnections",
"-",
"1",
";",
"errorObject",
"=",
"err",
";",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"r",
".",
"result",
"[",
"'$err'",
"]",
")",
"{",
"errorObject",
"=",
"r",
".",
"result",
";",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"r",
".",
"result",
"[",
"'errmsg'",
"]",
")",
"{",
"errorObject",
"=",
"r",
".",
"result",
";",
"return",
"false",
";",
"}",
"else",
"{",
"numberOfValidConnections",
"=",
"numberOfValidConnections",
"+",
"1",
";",
"}",
"return",
"true",
";",
"}"
] | Handle the error | [
"Handle",
"the",
"error"
] | 5adc639b88a0d72cbeef23a6b5df7f4540745089 | https://github.com/Industryswarm/isnode-mod-data/blob/5adc639b88a0d72cbeef23a6b5df7f4540745089/lib/mongodb/mongodb-core/lib/auth/scram.js#L205-L221 |
|
55,733 | dak0rn/espressojs | index.js | function(options) {
Configurable.call(this);
this._resources = [];
this._serializer = require(__dirname + '/lib/Serializer');
this.setAll( _.extend({}, defaults, options) );
// List of IDs used to find duplicate handlers fast
this._ids = {
// id: handler
};
// List of names for handlers set by the user
this._names = {
// name: handler
};
} | javascript | function(options) {
Configurable.call(this);
this._resources = [];
this._serializer = require(__dirname + '/lib/Serializer');
this.setAll( _.extend({}, defaults, options) );
// List of IDs used to find duplicate handlers fast
this._ids = {
// id: handler
};
// List of names for handlers set by the user
this._names = {
// name: handler
};
} | [
"function",
"(",
"options",
")",
"{",
"Configurable",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_resources",
"=",
"[",
"]",
";",
"this",
".",
"_serializer",
"=",
"require",
"(",
"__dirname",
"+",
"'/lib/Serializer'",
")",
";",
"this",
".",
"setAll",
"(",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"defaults",
",",
"options",
")",
")",
";",
"// List of IDs used to find duplicate handlers fast",
"this",
".",
"_ids",
"=",
"{",
"// id: handler",
"}",
";",
"// List of names for handlers set by the user",
"this",
".",
"_names",
"=",
"{",
"// name: handler",
"}",
";",
"}"
] | espressojs constructor function
@param {object} options Optional options object | [
"espressojs",
"constructor",
"function"
] | 7f8e015f31113215abbe9988ae7f2c7dd5d8572b | https://github.com/dak0rn/espressojs/blob/7f8e015f31113215abbe9988ae7f2c7dd5d8572b/index.js#L22-L40 |
|
55,734 | jshanley/motivejs | dist/motive.cjs.js | makeValidation | function makeValidation(name, exp, parser) {
return function (input) {
if (typeof input !== 'string') {
throw new TypeError('Cannot validate ' + name + '. Input must be a string.');
}
var validate = function () {
return input.match(exp) ? true : false;
};
return {
valid: validate(),
parse: function () {
if (!validate()) {
return false;
}
var captures = exp.exec(input);
return parser(captures);
}
};
};
} | javascript | function makeValidation(name, exp, parser) {
return function (input) {
if (typeof input !== 'string') {
throw new TypeError('Cannot validate ' + name + '. Input must be a string.');
}
var validate = function () {
return input.match(exp) ? true : false;
};
return {
valid: validate(),
parse: function () {
if (!validate()) {
return false;
}
var captures = exp.exec(input);
return parser(captures);
}
};
};
} | [
"function",
"makeValidation",
"(",
"name",
",",
"exp",
",",
"parser",
")",
"{",
"return",
"function",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Cannot validate '",
"+",
"name",
"+",
"'. Input must be a string.'",
")",
";",
"}",
"var",
"validate",
"=",
"function",
"(",
")",
"{",
"return",
"input",
".",
"match",
"(",
"exp",
")",
"?",
"true",
":",
"false",
";",
"}",
";",
"return",
"{",
"valid",
":",
"validate",
"(",
")",
",",
"parse",
":",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"validate",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"captures",
"=",
"exp",
".",
"exec",
"(",
"input",
")",
";",
"return",
"parser",
"(",
"captures",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | this makes a validation function for a string type defined by 'name' | [
"this",
"makes",
"a",
"validation",
"function",
"for",
"a",
"string",
"type",
"defined",
"by",
"name"
] | ba11720e0580da4657374dc47b177be15a723f6a | https://github.com/jshanley/motivejs/blob/ba11720e0580da4657374dc47b177be15a723f6a/dist/motive.cjs.js#L49-L68 |
55,735 | bestander/pong-mmo-server | game/socket/pongSocket.js | pipeEvents | function pipeEvents(source, destination, event) {
source.on(event, function (data) {
destination.emit(event, data);
});
} | javascript | function pipeEvents(source, destination, event) {
source.on(event, function (data) {
destination.emit(event, data);
});
} | [
"function",
"pipeEvents",
"(",
"source",
",",
"destination",
",",
"event",
")",
"{",
"source",
".",
"on",
"(",
"event",
",",
"function",
"(",
"data",
")",
"{",
"destination",
".",
"emit",
"(",
"event",
",",
"data",
")",
";",
"}",
")",
";",
"}"
] | pipe specific events from source event emitter to destination event emitter
@param source event emitter
@param destination event emitter
@param event event name | [
"pipe",
"specific",
"events",
"from",
"source",
"event",
"emitter",
"to",
"destination",
"event",
"emitter"
] | 7a54644bbf8b224f5010a30bacc98778201fe01c | https://github.com/bestander/pong-mmo-server/blob/7a54644bbf8b224f5010a30bacc98778201fe01c/game/socket/pongSocket.js#L70-L74 |
55,736 | danmasta/env | index.js | get | function get(key) {
let val = process.env[key];
return val in types ? types[val] : util.isNumeric(val) ? parseFloat(val) : val;
} | javascript | function get(key) {
let val = process.env[key];
return val in types ? types[val] : util.isNumeric(val) ? parseFloat(val) : val;
} | [
"function",
"get",
"(",
"key",
")",
"{",
"let",
"val",
"=",
"process",
".",
"env",
"[",
"key",
"]",
";",
"return",
"val",
"in",
"types",
"?",
"types",
"[",
"val",
"]",
":",
"util",
".",
"isNumeric",
"(",
"val",
")",
"?",
"parseFloat",
"(",
"val",
")",
":",
"val",
";",
"}"
] | get env variable, converts to native type | [
"get",
"env",
"variable",
"converts",
"to",
"native",
"type"
] | cd6df18f4f837797d47cd96bcfb125c0264685a7 | https://github.com/danmasta/env/blob/cd6df18f4f837797d47cd96bcfb125c0264685a7/index.js#L12-L18 |
55,737 | danmasta/env | index.js | set | function set(key, val) {
return process.env[key] = (process.env[key] === undefined ? val : process.env[key]);
} | javascript | function set(key, val) {
return process.env[key] = (process.env[key] === undefined ? val : process.env[key]);
} | [
"function",
"set",
"(",
"key",
",",
"val",
")",
"{",
"return",
"process",
".",
"env",
"[",
"key",
"]",
"=",
"(",
"process",
".",
"env",
"[",
"key",
"]",
"===",
"undefined",
"?",
"val",
":",
"process",
".",
"env",
"[",
"key",
"]",
")",
";",
"}"
] | sets environment variable if it does not exist already env variables are stringified when set | [
"sets",
"environment",
"variable",
"if",
"it",
"does",
"not",
"exist",
"already",
"env",
"variables",
"are",
"stringified",
"when",
"set"
] | cd6df18f4f837797d47cd96bcfb125c0264685a7 | https://github.com/danmasta/env/blob/cd6df18f4f837797d47cd96bcfb125c0264685a7/index.js#L22-L24 |
55,738 | danmasta/env | index.js | load | function load(file) {
let contents = null;
file = path.resolve(file);
// handle .env files
if (constants.REGEX.envfile.test(file)) {
contents = util.parse(fs.readFileSync(file, 'utf8'));
// handle .js/.json files
} else {
contents = require(file);
}
return env(contents);
} | javascript | function load(file) {
let contents = null;
file = path.resolve(file);
// handle .env files
if (constants.REGEX.envfile.test(file)) {
contents = util.parse(fs.readFileSync(file, 'utf8'));
// handle .js/.json files
} else {
contents = require(file);
}
return env(contents);
} | [
"function",
"load",
"(",
"file",
")",
"{",
"let",
"contents",
"=",
"null",
";",
"file",
"=",
"path",
".",
"resolve",
"(",
"file",
")",
";",
"// handle .env files",
"if",
"(",
"constants",
".",
"REGEX",
".",
"envfile",
".",
"test",
"(",
"file",
")",
")",
"{",
"contents",
"=",
"util",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"'utf8'",
")",
")",
";",
"// handle .js/.json files",
"}",
"else",
"{",
"contents",
"=",
"require",
"(",
"file",
")",
";",
"}",
"return",
"env",
"(",
"contents",
")",
";",
"}"
] | load a file's contents and add to env | [
"load",
"a",
"file",
"s",
"contents",
"and",
"add",
"to",
"env"
] | cd6df18f4f837797d47cd96bcfb125c0264685a7 | https://github.com/danmasta/env/blob/cd6df18f4f837797d47cd96bcfb125c0264685a7/index.js#L50-L67 |
55,739 | danmasta/env | index.js | init | function init(){
// set NODE_ENV to --env value
if (argv.env) {
set('NODE_ENV', argv.env);
}
// load evironment files
['./.env', './config/.env', './env', './config/env'].map(file => {
try {
load(file);
} catch(err) {
if (env('DEBUG')) {
console.error(`Env: ${err.message}`);
}
}
});
// set default vars
set('NODE_ENV', 'development');
['DEVELOPMENT', 'PRODUCTION'].map(str => {
set(str, get('NODE_ENV') === str.toLowerCase());
});
} | javascript | function init(){
// set NODE_ENV to --env value
if (argv.env) {
set('NODE_ENV', argv.env);
}
// load evironment files
['./.env', './config/.env', './env', './config/env'].map(file => {
try {
load(file);
} catch(err) {
if (env('DEBUG')) {
console.error(`Env: ${err.message}`);
}
}
});
// set default vars
set('NODE_ENV', 'development');
['DEVELOPMENT', 'PRODUCTION'].map(str => {
set(str, get('NODE_ENV') === str.toLowerCase());
});
} | [
"function",
"init",
"(",
")",
"{",
"// set NODE_ENV to --env value",
"if",
"(",
"argv",
".",
"env",
")",
"{",
"set",
"(",
"'NODE_ENV'",
",",
"argv",
".",
"env",
")",
";",
"}",
"// load evironment files",
"[",
"'./.env'",
",",
"'./config/.env'",
",",
"'./env'",
",",
"'./config/env'",
"]",
".",
"map",
"(",
"file",
"=>",
"{",
"try",
"{",
"load",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"env",
"(",
"'DEBUG'",
")",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"err",
".",
"message",
"}",
"`",
")",
";",
"}",
"}",
"}",
")",
";",
"// set default vars",
"set",
"(",
"'NODE_ENV'",
",",
"'development'",
")",
";",
"[",
"'DEVELOPMENT'",
",",
"'PRODUCTION'",
"]",
".",
"map",
"(",
"str",
"=>",
"{",
"set",
"(",
"str",
",",
"get",
"(",
"'NODE_ENV'",
")",
"===",
"str",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | attempt to load env configuration files | [
"attempt",
"to",
"load",
"env",
"configuration",
"files"
] | cd6df18f4f837797d47cd96bcfb125c0264685a7 | https://github.com/danmasta/env/blob/cd6df18f4f837797d47cd96bcfb125c0264685a7/index.js#L70-L101 |
55,740 | jchartrand/CWRC-WriterLayout | src/modules/structureTree.js | _expandParentsForNode | function _expandParentsForNode(node) {
// get the actual parent nodes in the editor
var parents = [];
$(node).parentsUntil('#tinymce').each(function(index, el) {
parents.push(el.id);
});
parents.reverse();
// TODO handling for readonly mode where only headings are in the tree
// expand the corresponding nodes in the tree
for (var i = 0; i < parents.length; i++) {
var parentId = parents[i];
var parentNode = $('[name="'+parentId+'"]', $tree);
var isOpen = $tree.jstree('is_open', parentNode);
if (!isOpen) {
$tree.jstree('open_node', parentNode, null, false);
}
}
} | javascript | function _expandParentsForNode(node) {
// get the actual parent nodes in the editor
var parents = [];
$(node).parentsUntil('#tinymce').each(function(index, el) {
parents.push(el.id);
});
parents.reverse();
// TODO handling for readonly mode where only headings are in the tree
// expand the corresponding nodes in the tree
for (var i = 0; i < parents.length; i++) {
var parentId = parents[i];
var parentNode = $('[name="'+parentId+'"]', $tree);
var isOpen = $tree.jstree('is_open', parentNode);
if (!isOpen) {
$tree.jstree('open_node', parentNode, null, false);
}
}
} | [
"function",
"_expandParentsForNode",
"(",
"node",
")",
"{",
"// get the actual parent nodes in the editor",
"var",
"parents",
"=",
"[",
"]",
";",
"$",
"(",
"node",
")",
".",
"parentsUntil",
"(",
"'#tinymce'",
")",
".",
"each",
"(",
"function",
"(",
"index",
",",
"el",
")",
"{",
"parents",
".",
"push",
"(",
"el",
".",
"id",
")",
";",
"}",
")",
";",
"parents",
".",
"reverse",
"(",
")",
";",
"// TODO handling for readonly mode where only headings are in the tree",
"// expand the corresponding nodes in the tree",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"parentId",
"=",
"parents",
"[",
"i",
"]",
";",
"var",
"parentNode",
"=",
"$",
"(",
"'[name=\"'",
"+",
"parentId",
"+",
"'\"]'",
",",
"$tree",
")",
";",
"var",
"isOpen",
"=",
"$tree",
".",
"jstree",
"(",
"'is_open'",
",",
"parentNode",
")",
";",
"if",
"(",
"!",
"isOpen",
")",
"{",
"$tree",
".",
"jstree",
"(",
"'open_node'",
",",
"parentNode",
",",
"null",
",",
"false",
")",
";",
"}",
"}",
"}"
] | Expands the parents of a particular node
@param {element} node A node that exists in the editor | [
"Expands",
"the",
"parents",
"of",
"a",
"particular",
"node"
] | 4a4b75af695043bc276efd3a9e5eb7e836c52d6e | https://github.com/jchartrand/CWRC-WriterLayout/blob/4a4b75af695043bc276efd3a9e5eb7e836c52d6e/src/modules/structureTree.js#L148-L167 |
55,741 | jchartrand/CWRC-WriterLayout | src/modules/structureTree.js | selectNode | function selectNode($node, selectContents, multiselect, external) {
var id = $node.attr('name');
_removeCustomClasses();
// clear other selections if not multiselect
if (!multiselect) {
if (tree.currentlySelectedNodes.indexOf(id) != -1) {
tree.currentlySelectedNodes = [id];
} else {
tree.currentlySelectedNodes = [];
}
}
if (id) {
var isEntity = w.entitiesManager.getEntity(id) !== undefined;
var aChildren = $node.children('a');
if (isEntity) {
tree.currentlySelectedNodes = [];
aChildren.addClass('nodeSelected').removeClass('contentsSelected');
if (tree.currentlySelectedEntity !== id) {
tree.currentlySelectedEntity = id;
tree.selectionType = null;
if (!external) {
ignoreSelect = true;
w.entitiesManager.highlightEntity(id, null, true);
}
}
} else if (w.structs[id] != null) {
tree.currentlySelectedEntity = null;
if (tree.currentlySelectedNodes.indexOf(id) != -1 && !external) {
// already selected node, toggle selection type
selectContents = !selectContents;
} else {
tree.currentlySelectedNodes.push(id);
}
if (selectContents) {
aChildren.addClass('contentsSelected').removeClass('nodeSelected');
} else {
aChildren.addClass('nodeSelected').removeClass('contentsSelected');
}
tree.selectionType = selectContents ? tree.CONTENTS_SELECTED : tree.NODE_SELECTED;
if (!external) {
if (w.structs[id]._tag == w.header) {
w.dialogManager.show('header');
} else {
ignoreSelect = true; // set to true so tree.highlightNode code isn't run by editor's onNodeChange handler
w.selectStructureTag(tree.currentlySelectedNodes, selectContents);
}
}
}
}
} | javascript | function selectNode($node, selectContents, multiselect, external) {
var id = $node.attr('name');
_removeCustomClasses();
// clear other selections if not multiselect
if (!multiselect) {
if (tree.currentlySelectedNodes.indexOf(id) != -1) {
tree.currentlySelectedNodes = [id];
} else {
tree.currentlySelectedNodes = [];
}
}
if (id) {
var isEntity = w.entitiesManager.getEntity(id) !== undefined;
var aChildren = $node.children('a');
if (isEntity) {
tree.currentlySelectedNodes = [];
aChildren.addClass('nodeSelected').removeClass('contentsSelected');
if (tree.currentlySelectedEntity !== id) {
tree.currentlySelectedEntity = id;
tree.selectionType = null;
if (!external) {
ignoreSelect = true;
w.entitiesManager.highlightEntity(id, null, true);
}
}
} else if (w.structs[id] != null) {
tree.currentlySelectedEntity = null;
if (tree.currentlySelectedNodes.indexOf(id) != -1 && !external) {
// already selected node, toggle selection type
selectContents = !selectContents;
} else {
tree.currentlySelectedNodes.push(id);
}
if (selectContents) {
aChildren.addClass('contentsSelected').removeClass('nodeSelected');
} else {
aChildren.addClass('nodeSelected').removeClass('contentsSelected');
}
tree.selectionType = selectContents ? tree.CONTENTS_SELECTED : tree.NODE_SELECTED;
if (!external) {
if (w.structs[id]._tag == w.header) {
w.dialogManager.show('header');
} else {
ignoreSelect = true; // set to true so tree.highlightNode code isn't run by editor's onNodeChange handler
w.selectStructureTag(tree.currentlySelectedNodes, selectContents);
}
}
}
}
} | [
"function",
"selectNode",
"(",
"$node",
",",
"selectContents",
",",
"multiselect",
",",
"external",
")",
"{",
"var",
"id",
"=",
"$node",
".",
"attr",
"(",
"'name'",
")",
";",
"_removeCustomClasses",
"(",
")",
";",
"// clear other selections if not multiselect",
"if",
"(",
"!",
"multiselect",
")",
"{",
"if",
"(",
"tree",
".",
"currentlySelectedNodes",
".",
"indexOf",
"(",
"id",
")",
"!=",
"-",
"1",
")",
"{",
"tree",
".",
"currentlySelectedNodes",
"=",
"[",
"id",
"]",
";",
"}",
"else",
"{",
"tree",
".",
"currentlySelectedNodes",
"=",
"[",
"]",
";",
"}",
"}",
"if",
"(",
"id",
")",
"{",
"var",
"isEntity",
"=",
"w",
".",
"entitiesManager",
".",
"getEntity",
"(",
"id",
")",
"!==",
"undefined",
";",
"var",
"aChildren",
"=",
"$node",
".",
"children",
"(",
"'a'",
")",
";",
"if",
"(",
"isEntity",
")",
"{",
"tree",
".",
"currentlySelectedNodes",
"=",
"[",
"]",
";",
"aChildren",
".",
"addClass",
"(",
"'nodeSelected'",
")",
".",
"removeClass",
"(",
"'contentsSelected'",
")",
";",
"if",
"(",
"tree",
".",
"currentlySelectedEntity",
"!==",
"id",
")",
"{",
"tree",
".",
"currentlySelectedEntity",
"=",
"id",
";",
"tree",
".",
"selectionType",
"=",
"null",
";",
"if",
"(",
"!",
"external",
")",
"{",
"ignoreSelect",
"=",
"true",
";",
"w",
".",
"entitiesManager",
".",
"highlightEntity",
"(",
"id",
",",
"null",
",",
"true",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"w",
".",
"structs",
"[",
"id",
"]",
"!=",
"null",
")",
"{",
"tree",
".",
"currentlySelectedEntity",
"=",
"null",
";",
"if",
"(",
"tree",
".",
"currentlySelectedNodes",
".",
"indexOf",
"(",
"id",
")",
"!=",
"-",
"1",
"&&",
"!",
"external",
")",
"{",
"// already selected node, toggle selection type",
"selectContents",
"=",
"!",
"selectContents",
";",
"}",
"else",
"{",
"tree",
".",
"currentlySelectedNodes",
".",
"push",
"(",
"id",
")",
";",
"}",
"if",
"(",
"selectContents",
")",
"{",
"aChildren",
".",
"addClass",
"(",
"'contentsSelected'",
")",
".",
"removeClass",
"(",
"'nodeSelected'",
")",
";",
"}",
"else",
"{",
"aChildren",
".",
"addClass",
"(",
"'nodeSelected'",
")",
".",
"removeClass",
"(",
"'contentsSelected'",
")",
";",
"}",
"tree",
".",
"selectionType",
"=",
"selectContents",
"?",
"tree",
".",
"CONTENTS_SELECTED",
":",
"tree",
".",
"NODE_SELECTED",
";",
"if",
"(",
"!",
"external",
")",
"{",
"if",
"(",
"w",
".",
"structs",
"[",
"id",
"]",
".",
"_tag",
"==",
"w",
".",
"header",
")",
"{",
"w",
".",
"dialogManager",
".",
"show",
"(",
"'header'",
")",
";",
"}",
"else",
"{",
"ignoreSelect",
"=",
"true",
";",
"// set to true so tree.highlightNode code isn't run by editor's onNodeChange handler",
"w",
".",
"selectStructureTag",
"(",
"tree",
".",
"currentlySelectedNodes",
",",
"selectContents",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Performs actual selection of a tree node
@param {Element} $node A jquery node (LI) in the tree
@param {Boolean} selectContents True to select contents
@param {Boolean} multiselect True if ctrl or select was held when selecting
@param {Boolean} external True if selectNode came from outside structureTree, i.e. tree.selectNode | [
"Performs",
"actual",
"selection",
"of",
"a",
"tree",
"node"
] | 4a4b75af695043bc276efd3a9e5eb7e836c52d6e | https://github.com/jchartrand/CWRC-WriterLayout/blob/4a4b75af695043bc276efd3a9e5eb7e836c52d6e/src/modules/structureTree.js#L243-L300 |
55,742 | themouette/screenstory | lib/runner/resolveWdOptions.js | resolveCapabilities | function resolveCapabilities(capabilities, capabilitiesDictionary) {
if (typeof capabilities !== "string") {
// we do not know how to parse non string capabilities, let's assume it
// is selenium compliant capabilities and return it.
return capabilities;
}
// try to parse as a JSON string
try {
return JSON.parse(capabilities);
} catch (e) { }
// No luck with JSON assumption.
// Try to read from configuration.
if (capabilities in capabilitiesDictionary) {
return capabilitiesDictionary[capabilities];
}
// still no luck ?
// assume this is browserName...
return { browserName: capabilities };
} | javascript | function resolveCapabilities(capabilities, capabilitiesDictionary) {
if (typeof capabilities !== "string") {
// we do not know how to parse non string capabilities, let's assume it
// is selenium compliant capabilities and return it.
return capabilities;
}
// try to parse as a JSON string
try {
return JSON.parse(capabilities);
} catch (e) { }
// No luck with JSON assumption.
// Try to read from configuration.
if (capabilities in capabilitiesDictionary) {
return capabilitiesDictionary[capabilities];
}
// still no luck ?
// assume this is browserName...
return { browserName: capabilities };
} | [
"function",
"resolveCapabilities",
"(",
"capabilities",
",",
"capabilitiesDictionary",
")",
"{",
"if",
"(",
"typeof",
"capabilities",
"!==",
"\"string\"",
")",
"{",
"// we do not know how to parse non string capabilities, let's assume it",
"// is selenium compliant capabilities and return it.",
"return",
"capabilities",
";",
"}",
"// try to parse as a JSON string",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"capabilities",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"// No luck with JSON assumption.",
"// Try to read from configuration.",
"if",
"(",
"capabilities",
"in",
"capabilitiesDictionary",
")",
"{",
"return",
"capabilitiesDictionary",
"[",
"capabilities",
"]",
";",
"}",
"// still no luck ?",
"// assume this is browserName...",
"return",
"{",
"browserName",
":",
"capabilities",
"}",
";",
"}"
] | Actual resolution for capabilities. | [
"Actual",
"resolution",
"for",
"capabilities",
"."
] | 0c847f5514a55e7c2f59728565591d4bb5788915 | https://github.com/themouette/screenstory/blob/0c847f5514a55e7c2f59728565591d4bb5788915/lib/runner/resolveWdOptions.js#L110-L132 |
55,743 | codeactual/sinon-doublist-fs | lib/sinon-doublist-fs/index.js | sinonDoublistFs | function sinonDoublistFs(test) {
if (module.exports.trace) {
nodeConsole = require('long-con').create();
log = nodeConsole
.set('nlFirst', true)
.set('time', false)
.set('traceDepth', true)
.create(null, console.log); // eslint-disable-line no-console
nodeConsole.traceMethods('FileStub', FileStub, log, null, /^prototype$/);
nodeConsole.traceMethods('FileStub', FileStub.prototype, log, null, /^(get|set)$/);
nodeConsole.traceMethods('wrapFs', wrapFs, log);
nodeConsole.traceMethods('mixin', mixin, log);
} else {
log = function noOpLogger() {};
}
if (is.string(test)) { globalInjector[test](); return; } // Ex. 'mocha'
if (is.fn(realFs.exists)) { return; } // Already doubled
// Mix in stubFile(), stubTree(), etc.
Object.keys(mixin).forEach(function forEachMixinMethod(method) { test[method] = mixin[method].bind(test); });
// Replace a selection of `fs`
Object.keys(wrapFs).forEach(function forEachWrapFsMethod(method) {
realFs[method] = fs[method];
fs[method] = wrapFs[method];
});
fileStubMap = {};
context = test;
} | javascript | function sinonDoublistFs(test) {
if (module.exports.trace) {
nodeConsole = require('long-con').create();
log = nodeConsole
.set('nlFirst', true)
.set('time', false)
.set('traceDepth', true)
.create(null, console.log); // eslint-disable-line no-console
nodeConsole.traceMethods('FileStub', FileStub, log, null, /^prototype$/);
nodeConsole.traceMethods('FileStub', FileStub.prototype, log, null, /^(get|set)$/);
nodeConsole.traceMethods('wrapFs', wrapFs, log);
nodeConsole.traceMethods('mixin', mixin, log);
} else {
log = function noOpLogger() {};
}
if (is.string(test)) { globalInjector[test](); return; } // Ex. 'mocha'
if (is.fn(realFs.exists)) { return; } // Already doubled
// Mix in stubFile(), stubTree(), etc.
Object.keys(mixin).forEach(function forEachMixinMethod(method) { test[method] = mixin[method].bind(test); });
// Replace a selection of `fs`
Object.keys(wrapFs).forEach(function forEachWrapFsMethod(method) {
realFs[method] = fs[method];
fs[method] = wrapFs[method];
});
fileStubMap = {};
context = test;
} | [
"function",
"sinonDoublistFs",
"(",
"test",
")",
"{",
"if",
"(",
"module",
".",
"exports",
".",
"trace",
")",
"{",
"nodeConsole",
"=",
"require",
"(",
"'long-con'",
")",
".",
"create",
"(",
")",
";",
"log",
"=",
"nodeConsole",
".",
"set",
"(",
"'nlFirst'",
",",
"true",
")",
".",
"set",
"(",
"'time'",
",",
"false",
")",
".",
"set",
"(",
"'traceDepth'",
",",
"true",
")",
".",
"create",
"(",
"null",
",",
"console",
".",
"log",
")",
";",
"// eslint-disable-line no-console",
"nodeConsole",
".",
"traceMethods",
"(",
"'FileStub'",
",",
"FileStub",
",",
"log",
",",
"null",
",",
"/",
"^prototype$",
"/",
")",
";",
"nodeConsole",
".",
"traceMethods",
"(",
"'FileStub'",
",",
"FileStub",
".",
"prototype",
",",
"log",
",",
"null",
",",
"/",
"^(get|set)$",
"/",
")",
";",
"nodeConsole",
".",
"traceMethods",
"(",
"'wrapFs'",
",",
"wrapFs",
",",
"log",
")",
";",
"nodeConsole",
".",
"traceMethods",
"(",
"'mixin'",
",",
"mixin",
",",
"log",
")",
";",
"}",
"else",
"{",
"log",
"=",
"function",
"noOpLogger",
"(",
")",
"{",
"}",
";",
"}",
"if",
"(",
"is",
".",
"string",
"(",
"test",
")",
")",
"{",
"globalInjector",
"[",
"test",
"]",
"(",
")",
";",
"return",
";",
"}",
"// Ex. 'mocha'",
"if",
"(",
"is",
".",
"fn",
"(",
"realFs",
".",
"exists",
")",
")",
"{",
"return",
";",
"}",
"// Already doubled",
"// Mix in stubFile(), stubTree(), etc.",
"Object",
".",
"keys",
"(",
"mixin",
")",
".",
"forEach",
"(",
"function",
"forEachMixinMethod",
"(",
"method",
")",
"{",
"test",
"[",
"method",
"]",
"=",
"mixin",
"[",
"method",
"]",
".",
"bind",
"(",
"test",
")",
";",
"}",
")",
";",
"// Replace a selection of `fs`",
"Object",
".",
"keys",
"(",
"wrapFs",
")",
".",
"forEach",
"(",
"function",
"forEachWrapFsMethod",
"(",
"method",
")",
"{",
"realFs",
"[",
"method",
"]",
"=",
"fs",
"[",
"method",
"]",
";",
"fs",
"[",
"method",
"]",
"=",
"wrapFs",
"[",
"method",
"]",
";",
"}",
")",
";",
"fileStubMap",
"=",
"{",
"}",
";",
"context",
"=",
"test",
";",
"}"
] | Init `fs` stubs.
@param {object|string} test Test context *OR* name of supported test runner
- `{object}` Context object including `sandbox` from prior `sinonDoublist()` call
- `{string}` Named runner will be configured to automatically set-up/tear-down.
- Supported runners: 'mocha' | [
"Init",
"fs",
"stubs",
"."
] | 7f32af1bba609bccf26ec2ce333dca27efc6f78f | https://github.com/codeactual/sinon-doublist-fs/blob/7f32af1bba609bccf26ec2ce333dca27efc6f78f/lib/sinon-doublist-fs/index.js#L39-L69 |
55,744 | codeactual/sinon-doublist-fs | lib/sinon-doublist-fs/index.js | FileStub | function FileStub() {
this.settings = {
name: '',
buffer: new Buffer(0),
readdir: false,
parentName: '',
stats: {
dev: 2114,
ino: 48064969,
mode: 33188,
nlink: 1,
uid: 85,
gid: 100,
rdev: 0,
size: 0,
blksize: 4096,
blocks: 0,
atime: 'Mon, 10 Oct 2011 23:24:11 GMT',
mtime: 'Mon, 10 Oct 2011 23:24:11 GMT',
ctime: 'Mon, 10 Oct 2011 23:24:11 GMT'
}
};
} | javascript | function FileStub() {
this.settings = {
name: '',
buffer: new Buffer(0),
readdir: false,
parentName: '',
stats: {
dev: 2114,
ino: 48064969,
mode: 33188,
nlink: 1,
uid: 85,
gid: 100,
rdev: 0,
size: 0,
blksize: 4096,
blocks: 0,
atime: 'Mon, 10 Oct 2011 23:24:11 GMT',
mtime: 'Mon, 10 Oct 2011 23:24:11 GMT',
ctime: 'Mon, 10 Oct 2011 23:24:11 GMT'
}
};
} | [
"function",
"FileStub",
"(",
")",
"{",
"this",
".",
"settings",
"=",
"{",
"name",
":",
"''",
",",
"buffer",
":",
"new",
"Buffer",
"(",
"0",
")",
",",
"readdir",
":",
"false",
",",
"parentName",
":",
"''",
",",
"stats",
":",
"{",
"dev",
":",
"2114",
",",
"ino",
":",
"48064969",
",",
"mode",
":",
"33188",
",",
"nlink",
":",
"1",
",",
"uid",
":",
"85",
",",
"gid",
":",
"100",
",",
"rdev",
":",
"0",
",",
"size",
":",
"0",
",",
"blksize",
":",
"4096",
",",
"blocks",
":",
"0",
",",
"atime",
":",
"'Mon, 10 Oct 2011 23:24:11 GMT'",
",",
"mtime",
":",
"'Mon, 10 Oct 2011 23:24:11 GMT'",
",",
"ctime",
":",
"'Mon, 10 Oct 2011 23:24:11 GMT'",
"}",
"}",
";",
"}"
] | FileStub constructor.
An entry in the map of stubbed files/directories.
Usage:
const stub = new FileStub();
stub
.set('name', '/path/to/file')
.stat('size', 50)
.stat('gid', 2000)
.make();
Configuration:
- `{string} name` Absolute path w/out trailing slash
- Trailing slashes will be dropped.
- `{boolean|array} readdir` Names of direct descendant files/directories
- `false` will lead to `isFile()` returning `true`
- `{string} parentName` Absolute path w/out trailing slash
- `{object} stats` Attributes to be returned by `stat*()` and `lstat*()`
- Initial values are from the `fs.Stats` manual entry. | [
"FileStub",
"constructor",
"."
] | 7f32af1bba609bccf26ec2ce333dca27efc6f78f | https://github.com/codeactual/sinon-doublist-fs/blob/7f32af1bba609bccf26ec2ce333dca27efc6f78f/lib/sinon-doublist-fs/index.js#L533-L555 |
55,745 | codeactual/sinon-doublist-fs | lib/sinon-doublist-fs/index.js | intermediatePaths | function intermediatePaths(sparse) {
const dense = {};
[].concat(sparse).forEach(function forEachPath(path) {
path = rtrimSlash(path);
dense[path] = {}; // Store as keys to omit dupes
const curParts = trimSlash(path).split('/');
const gapParts = [];
curParts.forEach(function forEachPart(part) {
const parent = '/' + gapParts.join('/');
gapParts.push(part); // Incrementally include all parts to collect gaps
const intermediate = '/' + gapParts.join('/');
if (!dense[intermediate]) { dense[intermediate] = {}; } // Collect gap
if (!dense[parent]) { dense[parent] = {}; } // Store its relatinship
if (parent === '/') {
dense[parent][trimSlash(intermediate.slice(1))] = 1;
} else {
// Guard against '' child name from sparse path w/ trailing slash
const childName = intermediate.replace(parent + '/', '');
if (childName) {
dense[parent][childName] = 1;
}
}
});
});
Object.keys(dense).forEach(function forEachDensePath(name) {
dense[name] = Object.keys(dense[name]);
});
return dense;
} | javascript | function intermediatePaths(sparse) {
const dense = {};
[].concat(sparse).forEach(function forEachPath(path) {
path = rtrimSlash(path);
dense[path] = {}; // Store as keys to omit dupes
const curParts = trimSlash(path).split('/');
const gapParts = [];
curParts.forEach(function forEachPart(part) {
const parent = '/' + gapParts.join('/');
gapParts.push(part); // Incrementally include all parts to collect gaps
const intermediate = '/' + gapParts.join('/');
if (!dense[intermediate]) { dense[intermediate] = {}; } // Collect gap
if (!dense[parent]) { dense[parent] = {}; } // Store its relatinship
if (parent === '/') {
dense[parent][trimSlash(intermediate.slice(1))] = 1;
} else {
// Guard against '' child name from sparse path w/ trailing slash
const childName = intermediate.replace(parent + '/', '');
if (childName) {
dense[parent][childName] = 1;
}
}
});
});
Object.keys(dense).forEach(function forEachDensePath(name) {
dense[name] = Object.keys(dense[name]);
});
return dense;
} | [
"function",
"intermediatePaths",
"(",
"sparse",
")",
"{",
"const",
"dense",
"=",
"{",
"}",
";",
"[",
"]",
".",
"concat",
"(",
"sparse",
")",
".",
"forEach",
"(",
"function",
"forEachPath",
"(",
"path",
")",
"{",
"path",
"=",
"rtrimSlash",
"(",
"path",
")",
";",
"dense",
"[",
"path",
"]",
"=",
"{",
"}",
";",
"// Store as keys to omit dupes",
"const",
"curParts",
"=",
"trimSlash",
"(",
"path",
")",
".",
"split",
"(",
"'/'",
")",
";",
"const",
"gapParts",
"=",
"[",
"]",
";",
"curParts",
".",
"forEach",
"(",
"function",
"forEachPart",
"(",
"part",
")",
"{",
"const",
"parent",
"=",
"'/'",
"+",
"gapParts",
".",
"join",
"(",
"'/'",
")",
";",
"gapParts",
".",
"push",
"(",
"part",
")",
";",
"// Incrementally include all parts to collect gaps",
"const",
"intermediate",
"=",
"'/'",
"+",
"gapParts",
".",
"join",
"(",
"'/'",
")",
";",
"if",
"(",
"!",
"dense",
"[",
"intermediate",
"]",
")",
"{",
"dense",
"[",
"intermediate",
"]",
"=",
"{",
"}",
";",
"}",
"// Collect gap",
"if",
"(",
"!",
"dense",
"[",
"parent",
"]",
")",
"{",
"dense",
"[",
"parent",
"]",
"=",
"{",
"}",
";",
"}",
"// Store its relatinship",
"if",
"(",
"parent",
"===",
"'/'",
")",
"{",
"dense",
"[",
"parent",
"]",
"[",
"trimSlash",
"(",
"intermediate",
".",
"slice",
"(",
"1",
")",
")",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"// Guard against '' child name from sparse path w/ trailing slash",
"const",
"childName",
"=",
"intermediate",
".",
"replace",
"(",
"parent",
"+",
"'/'",
",",
"''",
")",
";",
"if",
"(",
"childName",
")",
"{",
"dense",
"[",
"parent",
"]",
"[",
"childName",
"]",
"=",
"1",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"dense",
")",
".",
"forEach",
"(",
"function",
"forEachDensePath",
"(",
"name",
")",
"{",
"dense",
"[",
"name",
"]",
"=",
"Object",
".",
"keys",
"(",
"dense",
"[",
"name",
"]",
")",
";",
"}",
")",
";",
"return",
"dense",
";",
"}"
] | Given an array files and directories, in any order and relationship,
return an object describing how to build file trees that contain them
all with no directory gaps.
Ex. given just '/path/to/file.js', it include '/path' and '/to' in the
results.
@param {string|array} sparse Normalized, absolute paths
@return {object}
Keys: Absolute paths including 'sparse' and any filled 'gaps'.
Values: Arrays of direct descendants' absolute paths.
@api private | [
"Given",
"an",
"array",
"files",
"and",
"directories",
"in",
"any",
"order",
"and",
"relationship",
"return",
"an",
"object",
"describing",
"how",
"to",
"build",
"file",
"trees",
"that",
"contain",
"them",
"all",
"with",
"no",
"directory",
"gaps",
"."
] | 7f32af1bba609bccf26ec2ce333dca27efc6f78f | https://github.com/codeactual/sinon-doublist-fs/blob/7f32af1bba609bccf26ec2ce333dca27efc6f78f/lib/sinon-doublist-fs/index.js#L764-L795 |
55,746 | elidoran/node-use | lib/index.js | withOptions | function withOptions(scope, defaultOptions) {
return function(plugin, options) {
return scope.use(this, scope, plugin, scope.combine(defaultOptions, options))
}
} | javascript | function withOptions(scope, defaultOptions) {
return function(plugin, options) {
return scope.use(this, scope, plugin, scope.combine(defaultOptions, options))
}
} | [
"function",
"withOptions",
"(",
"scope",
",",
"defaultOptions",
")",
"{",
"return",
"function",
"(",
"plugin",
",",
"options",
")",
"{",
"return",
"scope",
".",
"use",
"(",
"this",
",",
"scope",
",",
"plugin",
",",
"scope",
".",
"combine",
"(",
"defaultOptions",
",",
"options",
")",
")",
"}",
"}"
] | create a closure to hold the provided `scope` and `defaultOptions`. | [
"create",
"a",
"closure",
"to",
"hold",
"the",
"provided",
"scope",
"and",
"defaultOptions",
"."
] | 72349bad08f253dc226cbd031a1495ae44bd733c | https://github.com/elidoran/node-use/blob/72349bad08f253dc226cbd031a1495ae44bd733c/lib/index.js#L61-L65 |
55,747 | adiwidjaja/frontend-pagebuilder | js/tinymce/plugins/help/plugin.js | function (o) {
var r = [];
for (var i in o) {
if (o.hasOwnProperty(i)) {
r.push(i);
}
}
return r;
} | javascript | function (o) {
var r = [];
for (var i in o) {
if (o.hasOwnProperty(i)) {
r.push(i);
}
}
return r;
} | [
"function",
"(",
"o",
")",
"{",
"var",
"r",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"in",
"o",
")",
"{",
"if",
"(",
"o",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"r",
".",
"push",
"(",
"i",
")",
";",
"}",
"}",
"return",
"r",
";",
"}"
] | This technically means that 'each' and 'find' on IE8 iterate through the object twice. This code doesn't run on IE8 much, so it's an acceptable tradeoff. If it becomes a problem we can always duplicate the feature detection inside each and find as well. | [
"This",
"technically",
"means",
"that",
"each",
"and",
"find",
"on",
"IE8",
"iterate",
"through",
"the",
"object",
"twice",
".",
"This",
"code",
"doesn",
"t",
"run",
"on",
"IE8",
"much",
"so",
"it",
"s",
"an",
"acceptable",
"tradeoff",
".",
"If",
"it",
"becomes",
"a",
"problem",
"we",
"can",
"always",
"duplicate",
"the",
"feature",
"detection",
"inside",
"each",
"and",
"find",
"as",
"well",
"."
] | a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f | https://github.com/adiwidjaja/frontend-pagebuilder/blob/a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f/js/tinymce/plugins/help/plugin.js#L825-L833 |
|
55,748 | commenthol/hashtree | hashtree.js | splitKeys | function splitKeys (keys) {
if (typeof(keys) === 'string') {
return keys.replace(/^\s*\.\s*/,'')
.replace(/(?:\s*\.\s*)+/g, '.')
.split('.');
}
else if (Array.isArray(keys)) {
return [].concat(keys);
}
return;
} | javascript | function splitKeys (keys) {
if (typeof(keys) === 'string') {
return keys.replace(/^\s*\.\s*/,'')
.replace(/(?:\s*\.\s*)+/g, '.')
.split('.');
}
else if (Array.isArray(keys)) {
return [].concat(keys);
}
return;
} | [
"function",
"splitKeys",
"(",
"keys",
")",
"{",
"if",
"(",
"typeof",
"(",
"keys",
")",
"===",
"'string'",
")",
"{",
"return",
"keys",
".",
"replace",
"(",
"/",
"^\\s*\\.\\s*",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"(?:\\s*\\.\\s*)+",
"/",
"g",
",",
"'.'",
")",
".",
"split",
"(",
"'.'",
")",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"keys",
")",
")",
"{",
"return",
"[",
"]",
".",
"concat",
"(",
"keys",
")",
";",
"}",
"return",
";",
"}"
] | Normalize and split `keys` for `get` and `set` method.
Splits by "."
@param {String|Array} keys
@api private | [
"Normalize",
"and",
"split",
"keys",
"for",
"get",
"and",
"set",
"method",
".",
"Splits",
"by",
"."
] | eb66d5b72af17ded1913f5abb9b49ebfb2b000c1 | https://github.com/commenthol/hashtree/blob/eb66d5b72af17ded1913f5abb9b49ebfb2b000c1/hashtree.js#L477-L487 |
55,749 | commenthol/hashtree | hashtree.js | Ops | function Ops (ref, key) {
this.ref = ref;
this.key = key;
if (this.ref[this.key] === undefined) {
this.ref[this.key] = 0;
}
this._toNumber();
this.isNumber = (typeof this.ref[this.key] === 'number');
this.isBoolean = (typeof this.ref[this.key] === 'boolean');
this.isString = (typeof this.ref[this.key] === 'string');
this.isArray = Array.isArray(this.ref[this.key]);
this.isObject = (!this.isArray && typeof this.ref[this.key] === 'object');
} | javascript | function Ops (ref, key) {
this.ref = ref;
this.key = key;
if (this.ref[this.key] === undefined) {
this.ref[this.key] = 0;
}
this._toNumber();
this.isNumber = (typeof this.ref[this.key] === 'number');
this.isBoolean = (typeof this.ref[this.key] === 'boolean');
this.isString = (typeof this.ref[this.key] === 'string');
this.isArray = Array.isArray(this.ref[this.key]);
this.isObject = (!this.isArray && typeof this.ref[this.key] === 'object');
} | [
"function",
"Ops",
"(",
"ref",
",",
"key",
")",
"{",
"this",
".",
"ref",
"=",
"ref",
";",
"this",
".",
"key",
"=",
"key",
";",
"if",
"(",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"===",
"undefined",
")",
"{",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"=",
"0",
";",
"}",
"this",
".",
"_toNumber",
"(",
")",
";",
"this",
".",
"isNumber",
"=",
"(",
"typeof",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"===",
"'number'",
")",
";",
"this",
".",
"isBoolean",
"=",
"(",
"typeof",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"===",
"'boolean'",
")",
";",
"this",
".",
"isString",
"=",
"(",
"typeof",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"===",
"'string'",
")",
";",
"this",
".",
"isArray",
"=",
"Array",
".",
"isArray",
"(",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
")",
";",
"this",
".",
"isObject",
"=",
"(",
"!",
"this",
".",
"isArray",
"&&",
"typeof",
"this",
".",
"ref",
"[",
"this",
".",
"key",
"]",
"===",
"'object'",
")",
";",
"}"
] | Helper class for hashTree.use
@param {Object} ref : reference in object
@param {String} key : key for value to change | [
"Helper",
"class",
"for",
"hashTree",
".",
"use"
] | eb66d5b72af17ded1913f5abb9b49ebfb2b000c1 | https://github.com/commenthol/hashtree/blob/eb66d5b72af17ded1913f5abb9b49ebfb2b000c1/hashtree.js#L494-L508 |
55,750 | sreenaths/em-tgraph | addon/utils/tip.js | _createList | function _createList(list) {
var listContent = [];
if(list) {
listContent.push("<table>");
Ember.$.each(list, function (property, value) {
listContent.push(
"<tr><td>",
property,
"</td><td>",
value,
"</td></tr>"
);
});
listContent.push("</table>");
return listContent.join("");
}
} | javascript | function _createList(list) {
var listContent = [];
if(list) {
listContent.push("<table>");
Ember.$.each(list, function (property, value) {
listContent.push(
"<tr><td>",
property,
"</td><td>",
value,
"</td></tr>"
);
});
listContent.push("</table>");
return listContent.join("");
}
} | [
"function",
"_createList",
"(",
"list",
")",
"{",
"var",
"listContent",
"=",
"[",
"]",
";",
"if",
"(",
"list",
")",
"{",
"listContent",
".",
"push",
"(",
"\"<table>\"",
")",
";",
"Ember",
".",
"$",
".",
"each",
"(",
"list",
",",
"function",
"(",
"property",
",",
"value",
")",
"{",
"listContent",
".",
"push",
"(",
"\"<tr><td>\"",
",",
"property",
",",
"\"</td><td>\"",
",",
"value",
",",
"\"</td></tr>\"",
")",
";",
"}",
")",
";",
"listContent",
".",
"push",
"(",
"\"</table>\"",
")",
";",
"return",
"listContent",
".",
"join",
"(",
"\"\"",
")",
";",
"}",
"}"
] | Last node over which tooltip was displayed
Converts the provided list object into a tabular form.
@param list {Object} : An object with properties to be displayed as key value pairs
{
propertyName1: "property value 1",
..
propertyNameN: "property value N",
} | [
"Last",
"node",
"over",
"which",
"tooltip",
"was",
"displayed",
"Converts",
"the",
"provided",
"list",
"object",
"into",
"a",
"tabular",
"form",
"."
] | 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/tip.js#L25-L44 |
55,751 | sreenaths/em-tgraph | addon/utils/tip.js | _setData | function _setData(data) {
_element.find('.tip-title').html(data.title || "");
_element.find('.tip-text').html(data.text || "");
_element.find('.tip-text')[data.text ? 'show' : 'hide']();
_element.find('.tip-list').html(_createList(data.kvList) || "");
} | javascript | function _setData(data) {
_element.find('.tip-title').html(data.title || "");
_element.find('.tip-text').html(data.text || "");
_element.find('.tip-text')[data.text ? 'show' : 'hide']();
_element.find('.tip-list').html(_createList(data.kvList) || "");
} | [
"function",
"_setData",
"(",
"data",
")",
"{",
"_element",
".",
"find",
"(",
"'.tip-title'",
")",
".",
"html",
"(",
"data",
".",
"title",
"||",
"\"\"",
")",
";",
"_element",
".",
"find",
"(",
"'.tip-text'",
")",
".",
"html",
"(",
"data",
".",
"text",
"||",
"\"\"",
")",
";",
"_element",
".",
"find",
"(",
"'.tip-text'",
")",
"[",
"data",
".",
"text",
"?",
"'show'",
":",
"'hide'",
"]",
"(",
")",
";",
"_element",
".",
"find",
"(",
"'.tip-list'",
")",
".",
"html",
"(",
"_createList",
"(",
"data",
".",
"kvList",
")",
"||",
"\"\"",
")",
";",
"}"
] | Tip supports 3 visual entities in the tooltip. Title, description text and a list.
_setData sets all these based on the passed data object
@param data {Object} An object of the format
{
title: "tip title",
text: "tip description text",
kvList: {
propertyName1: "property value 1",
..
propertyNameN: "property value N",
}
} | [
"Tip",
"supports",
"3",
"visual",
"entities",
"in",
"the",
"tooltip",
".",
"Title",
"description",
"text",
"and",
"a",
"list",
".",
"_setData",
"sets",
"all",
"these",
"based",
"on",
"the",
"passed",
"data",
"object"
] | 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/tip.js#L60-L65 |
55,752 | sreenaths/em-tgraph | addon/utils/tip.js | function (tipElement, svg) {
_element = tipElement;
_bubble = _element.find('.bubble');
_svg = svg;
_svgPoint = svg[0].createSVGPoint();
} | javascript | function (tipElement, svg) {
_element = tipElement;
_bubble = _element.find('.bubble');
_svg = svg;
_svgPoint = svg[0].createSVGPoint();
} | [
"function",
"(",
"tipElement",
",",
"svg",
")",
"{",
"_element",
"=",
"tipElement",
";",
"_bubble",
"=",
"_element",
".",
"find",
"(",
"'.bubble'",
")",
";",
"_svg",
"=",
"svg",
";",
"_svgPoint",
"=",
"svg",
"[",
"0",
"]",
".",
"createSVGPoint",
"(",
")",
";",
"}"
] | Set the tip defaults
@param tipElement {$} jQuery reference to the tooltip DOM element.
The element must contain 3 children with class tip-title, tip-text & tip-list.
@param svg {$} jQuery reference to svg html element | [
"Set",
"the",
"tip",
"defaults"
] | 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/tip.js#L74-L79 |
|
55,753 | sreenaths/em-tgraph | addon/utils/tip.js | function (node, data, event) {
var point = data.position || (node.getScreenCTM ? _svgPoint.matrixTransform(
node.getScreenCTM()
) : {
x: event.x,
y: event.y
}),
windMid = _window.height() >> 1,
winWidth = _window.width(),
showAbove = point.y < windMid,
offsetX = 0,
width = 0;
if(_data !== data) {
_data = data;
_node = node;
_setData(data);
}
if(showAbove) {
_element.removeClass('below');
_element.addClass('above');
}
else {
_element.removeClass('above');
_element.addClass('below');
point.y -= _element.height();
}
width = _element.width();
offsetX = (width - 11) >> 1;
if(point.x - offsetX < 0) {
offsetX = point.x - 20;
}
else if(point.x + offsetX > winWidth) {
offsetX = point.x - (winWidth - 10 - width);
}
_bubble.css({
left: -offsetX
});
Ember.run.debounce(Tip, "showTip", 500);
_element.css({
left: point.x,
top: point.y
});
} | javascript | function (node, data, event) {
var point = data.position || (node.getScreenCTM ? _svgPoint.matrixTransform(
node.getScreenCTM()
) : {
x: event.x,
y: event.y
}),
windMid = _window.height() >> 1,
winWidth = _window.width(),
showAbove = point.y < windMid,
offsetX = 0,
width = 0;
if(_data !== data) {
_data = data;
_node = node;
_setData(data);
}
if(showAbove) {
_element.removeClass('below');
_element.addClass('above');
}
else {
_element.removeClass('above');
_element.addClass('below');
point.y -= _element.height();
}
width = _element.width();
offsetX = (width - 11) >> 1;
if(point.x - offsetX < 0) {
offsetX = point.x - 20;
}
else if(point.x + offsetX > winWidth) {
offsetX = point.x - (winWidth - 10 - width);
}
_bubble.css({
left: -offsetX
});
Ember.run.debounce(Tip, "showTip", 500);
_element.css({
left: point.x,
top: point.y
});
} | [
"function",
"(",
"node",
",",
"data",
",",
"event",
")",
"{",
"var",
"point",
"=",
"data",
".",
"position",
"||",
"(",
"node",
".",
"getScreenCTM",
"?",
"_svgPoint",
".",
"matrixTransform",
"(",
"node",
".",
"getScreenCTM",
"(",
")",
")",
":",
"{",
"x",
":",
"event",
".",
"x",
",",
"y",
":",
"event",
".",
"y",
"}",
")",
",",
"windMid",
"=",
"_window",
".",
"height",
"(",
")",
">>",
"1",
",",
"winWidth",
"=",
"_window",
".",
"width",
"(",
")",
",",
"showAbove",
"=",
"point",
".",
"y",
"<",
"windMid",
",",
"offsetX",
"=",
"0",
",",
"width",
"=",
"0",
";",
"if",
"(",
"_data",
"!==",
"data",
")",
"{",
"_data",
"=",
"data",
";",
"_node",
"=",
"node",
";",
"_setData",
"(",
"data",
")",
";",
"}",
"if",
"(",
"showAbove",
")",
"{",
"_element",
".",
"removeClass",
"(",
"'below'",
")",
";",
"_element",
".",
"addClass",
"(",
"'above'",
")",
";",
"}",
"else",
"{",
"_element",
".",
"removeClass",
"(",
"'above'",
")",
";",
"_element",
".",
"addClass",
"(",
"'below'",
")",
";",
"point",
".",
"y",
"-=",
"_element",
".",
"height",
"(",
")",
";",
"}",
"width",
"=",
"_element",
".",
"width",
"(",
")",
";",
"offsetX",
"=",
"(",
"width",
"-",
"11",
")",
">>",
"1",
";",
"if",
"(",
"point",
".",
"x",
"-",
"offsetX",
"<",
"0",
")",
"{",
"offsetX",
"=",
"point",
".",
"x",
"-",
"20",
";",
"}",
"else",
"if",
"(",
"point",
".",
"x",
"+",
"offsetX",
">",
"winWidth",
")",
"{",
"offsetX",
"=",
"point",
".",
"x",
"-",
"(",
"winWidth",
"-",
"10",
"-",
"width",
")",
";",
"}",
"_bubble",
".",
"css",
"(",
"{",
"left",
":",
"-",
"offsetX",
"}",
")",
";",
"Ember",
".",
"run",
".",
"debounce",
"(",
"Tip",
",",
"\"showTip\"",
",",
"500",
")",
";",
"_element",
".",
"css",
"(",
"{",
"left",
":",
"point",
".",
"x",
",",
"top",
":",
"point",
".",
"y",
"}",
")",
";",
"}"
] | Display a tooltip over an svg element.
@param node {SVG Element} Svg element over which tooltip must be displayed.
@param data {Object} An object of the format
{
title: "tip title",
text: "tip description text",
kvList: {
propertyName1: "property value 1",
..
propertyNameN: "property value N",
}
}
@param event {MouseEvent} Event that triggered the tooltip. | [
"Display",
"a",
"tooltip",
"over",
"an",
"svg",
"element",
"."
] | 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/tip.js#L100-L153 |
|
55,754 | mongodb-js/mocha-evergreen-reporter | index.js | report | function report(test) {
return {
test_file: test.file + ': ' + test.fullTitle(),
start: test.start,
end: test.end,
exit_code: test.exit_code,
elapsed: test.duration / 1000,
error: errorJSON(test.err || {}),
url: test.url,
status: test.state
};
} | javascript | function report(test) {
return {
test_file: test.file + ': ' + test.fullTitle(),
start: test.start,
end: test.end,
exit_code: test.exit_code,
elapsed: test.duration / 1000,
error: errorJSON(test.err || {}),
url: test.url,
status: test.state
};
} | [
"function",
"report",
"(",
"test",
")",
"{",
"return",
"{",
"test_file",
":",
"test",
".",
"file",
"+",
"': '",
"+",
"test",
".",
"fullTitle",
"(",
")",
",",
"start",
":",
"test",
".",
"start",
",",
"end",
":",
"test",
".",
"end",
",",
"exit_code",
":",
"test",
".",
"exit_code",
",",
"elapsed",
":",
"test",
".",
"duration",
"/",
"1000",
",",
"error",
":",
"errorJSON",
"(",
"test",
".",
"err",
"||",
"{",
"}",
")",
",",
"url",
":",
"test",
".",
"url",
",",
"status",
":",
"test",
".",
"state",
"}",
";",
"}"
] | Return an object with all of the relevant information for the test.
@api private
@param {Object} test
@return {Object} | [
"Return",
"an",
"object",
"with",
"all",
"of",
"the",
"relevant",
"information",
"for",
"the",
"test",
"."
] | b4b25074acf49cb74740688b4afeb161c5e2a64f | https://github.com/mongodb-js/mocha-evergreen-reporter/blob/b4b25074acf49cb74740688b4afeb161c5e2a64f/index.js#L158-L169 |
55,755 | mongodb-js/mocha-evergreen-reporter | index.js | writeLogs | function writeLogs(test, dirName) {
var logs =
test.fullTitle() +
'\n' +
test.file +
'\nStart: ' +
test.start +
'\nEnd: ' +
test.end +
'\nElapsed: ' +
test.duration +
'\nStatus: ' +
test.state;
if (test.state === 'fail') {
logs += '\nError: ' + test.err.stack;
}
mkdirp.sync(testDir(test, dirName));
fs.writeFileSync(testURL(test, dirName), logs);
test.url = testURL(test, dirName);
} | javascript | function writeLogs(test, dirName) {
var logs =
test.fullTitle() +
'\n' +
test.file +
'\nStart: ' +
test.start +
'\nEnd: ' +
test.end +
'\nElapsed: ' +
test.duration +
'\nStatus: ' +
test.state;
if (test.state === 'fail') {
logs += '\nError: ' + test.err.stack;
}
mkdirp.sync(testDir(test, dirName));
fs.writeFileSync(testURL(test, dirName), logs);
test.url = testURL(test, dirName);
} | [
"function",
"writeLogs",
"(",
"test",
",",
"dirName",
")",
"{",
"var",
"logs",
"=",
"test",
".",
"fullTitle",
"(",
")",
"+",
"'\\n'",
"+",
"test",
".",
"file",
"+",
"'\\nStart: '",
"+",
"test",
".",
"start",
"+",
"'\\nEnd: '",
"+",
"test",
".",
"end",
"+",
"'\\nElapsed: '",
"+",
"test",
".",
"duration",
"+",
"'\\nStatus: '",
"+",
"test",
".",
"state",
";",
"if",
"(",
"test",
".",
"state",
"===",
"'fail'",
")",
"{",
"logs",
"+=",
"'\\nError: '",
"+",
"test",
".",
"err",
".",
"stack",
";",
"}",
"mkdirp",
".",
"sync",
"(",
"testDir",
"(",
"test",
",",
"dirName",
")",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"testURL",
"(",
"test",
",",
"dirName",
")",
",",
"logs",
")",
";",
"test",
".",
"url",
"=",
"testURL",
"(",
"test",
",",
"dirName",
")",
";",
"}"
] | Writes logs to a file in the specified directory
@param {test} test
@param {string} dirName | [
"Writes",
"logs",
"to",
"a",
"file",
"in",
"the",
"specified",
"directory"
] | b4b25074acf49cb74740688b4afeb161c5e2a64f | https://github.com/mongodb-js/mocha-evergreen-reporter/blob/b4b25074acf49cb74740688b4afeb161c5e2a64f/index.js#L176-L195 |
55,756 | MCluck90/clairvoyant | src/compiler.js | generateFileName | function generateFileName(className) {
return className
.replace(/component/gi, '')
.replace(/system/gi, '')
.replace('2D', '2d')
.replace('3D', '3d')
.replace(/^[A-Z]/, function(c) {
return c.toLowerCase();
})
.replace(/[A-Z]/g, function(c) {
return '-' + c.toLowerCase();
}) + '.js';
} | javascript | function generateFileName(className) {
return className
.replace(/component/gi, '')
.replace(/system/gi, '')
.replace('2D', '2d')
.replace('3D', '3d')
.replace(/^[A-Z]/, function(c) {
return c.toLowerCase();
})
.replace(/[A-Z]/g, function(c) {
return '-' + c.toLowerCase();
}) + '.js';
} | [
"function",
"generateFileName",
"(",
"className",
")",
"{",
"return",
"className",
".",
"replace",
"(",
"/",
"component",
"/",
"gi",
",",
"''",
")",
".",
"replace",
"(",
"/",
"system",
"/",
"gi",
",",
"''",
")",
".",
"replace",
"(",
"'2D'",
",",
"'2d'",
")",
".",
"replace",
"(",
"'3D'",
",",
"'3d'",
")",
".",
"replace",
"(",
"/",
"^[A-Z]",
"/",
",",
"function",
"(",
"c",
")",
"{",
"return",
"c",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
".",
"replace",
"(",
"/",
"[A-Z]",
"/",
"g",
",",
"function",
"(",
"c",
")",
"{",
"return",
"'-'",
"+",
"c",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
"+",
"'.js'",
";",
"}"
] | Generates a filename based on the class name given
@param {string} className
@returns {string} | [
"Generates",
"a",
"filename",
"based",
"on",
"the",
"class",
"name",
"given"
] | 4c347499c5fe0f561a53e180d141884b1fa8c21b | https://github.com/MCluck90/clairvoyant/blob/4c347499c5fe0f561a53e180d141884b1fa8c21b/src/compiler.js#L17-L29 |
55,757 | MCluck90/clairvoyant | src/compiler.js | function(ast, reporter, version) {
this.ast = ast;
this.reporter = reporter;
this.psykickVersion = 'psykick' + version;
// Store the Templates so the Systems can access them later
this._templatesByName = {};
} | javascript | function(ast, reporter, version) {
this.ast = ast;
this.reporter = reporter;
this.psykickVersion = 'psykick' + version;
// Store the Templates so the Systems can access them later
this._templatesByName = {};
} | [
"function",
"(",
"ast",
",",
"reporter",
",",
"version",
")",
"{",
"this",
".",
"ast",
"=",
"ast",
";",
"this",
".",
"reporter",
"=",
"reporter",
";",
"this",
".",
"psykickVersion",
"=",
"'psykick'",
"+",
"version",
";",
"// Store the Templates so the Systems can access them later",
"this",
".",
"_templatesByName",
"=",
"{",
"}",
";",
"}"
] | Compiles the AST into actual code
@param {AST} ast
@param {Reporter} reporter
@param {string} version
@constructor | [
"Compiles",
"the",
"AST",
"into",
"actual",
"code"
] | 4c347499c5fe0f561a53e180d141884b1fa8c21b | https://github.com/MCluck90/clairvoyant/blob/4c347499c5fe0f561a53e180d141884b1fa8c21b/src/compiler.js#L38-L45 |
|
55,758 | enbock/corejs-w3c | src/core.js | CoreEvent | function CoreEvent(typeArg, detail) {
if (detail == undefined) {
detail = {};
}
/**
* Error:
* Failed to construct 'CustomEvent': Please use the 'new' operator, this
* DOM object constructor cannot be called as a function.
*
* In reason of that the browser did not allow to extend CustomEvent in
* common way, we use our event class only as constant holder.
*/
return new CustomEvent(typeArg, { detail: detail });
} | javascript | function CoreEvent(typeArg, detail) {
if (detail == undefined) {
detail = {};
}
/**
* Error:
* Failed to construct 'CustomEvent': Please use the 'new' operator, this
* DOM object constructor cannot be called as a function.
*
* In reason of that the browser did not allow to extend CustomEvent in
* common way, we use our event class only as constant holder.
*/
return new CustomEvent(typeArg, { detail: detail });
} | [
"function",
"CoreEvent",
"(",
"typeArg",
",",
"detail",
")",
"{",
"if",
"(",
"detail",
"==",
"undefined",
")",
"{",
"detail",
"=",
"{",
"}",
";",
"}",
"/**\r\n\t * Error:\r\n\t * Failed to construct 'CustomEvent': Please use the 'new' operator, this \r\n\t * DOM object constructor cannot be called as a function.\r\n\t * \r\n\t * In reason of that the browser did not allow to extend CustomEvent in\r\n\t * common way, we use our event class only as constant holder. \r\n\t */",
"return",
"new",
"CustomEvent",
"(",
"typeArg",
",",
"{",
"detail",
":",
"detail",
"}",
")",
";",
"}"
] | CoreJS events.
@constructor
@param {String} typeArg - Is a String representing the name of the event.
@param {(Object|String|Number)} [detail] - Data to transport over the event. | [
"CoreJS",
"events",
"."
] | ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04 | https://github.com/enbock/corejs-w3c/blob/ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04/src/core.js#L132-L145 |
55,759 | enbock/corejs-w3c | src/core.js | Ajax | function Ajax(method, url, sendData) {
DOMEventListener.call(this);
/**
* Request object.
*
* @access protected
* @type {XMLHttpRequest}
*/
this._request = new Ajax.XHRSystem();
/**
* Method of the request.
*
* @access protected
* @type {String}
*/
this._method = method;
/**
* Address of request.
*
* @access protected
* @type {String}
*/
this._url = url;
/**
* Data to send.
*
* @access protected
* @type {(Object|String)}
*/
this._sendData = sendData;
/**
* The content type of sending data.
*
* @access public
* @type {String}
*/
this.contentType = "application/binary";
/**
* Context conatiner.
* @access private
*/
var self = this;
/**
* Override onload of XMLHTTPRequest.
* Convert callback function into `Event`.
*/
this._request.onload = function (event) {
self.dispatchEvent(
new Ajax.Event(Ajax.Event.LOAD, {
response: self._request.response,
responseText: self._request.responseText,
responseType: self._request.responseType,
responseURL: self._request.responseURL,
responseXML: self._request.responseXML,
status: self._request.status,
lengthComputable: event.lengthComputable,
loaded: event.loaded,
total: event.total
})
);
};
/**
* Override onprogress of XMLHTTPRequest.
* Convert callback function into `Event`.
*/
this._request.onprogress = function (event) {
self.dispatchEvent(
new Ajax.Event(Ajax.Event.PROGRESS, {
lengthComputable: event.lengthComputable,
loaded: event.loaded,
total: event.total
})
);
};
} | javascript | function Ajax(method, url, sendData) {
DOMEventListener.call(this);
/**
* Request object.
*
* @access protected
* @type {XMLHttpRequest}
*/
this._request = new Ajax.XHRSystem();
/**
* Method of the request.
*
* @access protected
* @type {String}
*/
this._method = method;
/**
* Address of request.
*
* @access protected
* @type {String}
*/
this._url = url;
/**
* Data to send.
*
* @access protected
* @type {(Object|String)}
*/
this._sendData = sendData;
/**
* The content type of sending data.
*
* @access public
* @type {String}
*/
this.contentType = "application/binary";
/**
* Context conatiner.
* @access private
*/
var self = this;
/**
* Override onload of XMLHTTPRequest.
* Convert callback function into `Event`.
*/
this._request.onload = function (event) {
self.dispatchEvent(
new Ajax.Event(Ajax.Event.LOAD, {
response: self._request.response,
responseText: self._request.responseText,
responseType: self._request.responseType,
responseURL: self._request.responseURL,
responseXML: self._request.responseXML,
status: self._request.status,
lengthComputable: event.lengthComputable,
loaded: event.loaded,
total: event.total
})
);
};
/**
* Override onprogress of XMLHTTPRequest.
* Convert callback function into `Event`.
*/
this._request.onprogress = function (event) {
self.dispatchEvent(
new Ajax.Event(Ajax.Event.PROGRESS, {
lengthComputable: event.lengthComputable,
loaded: event.loaded,
total: event.total
})
);
};
} | [
"function",
"Ajax",
"(",
"method",
",",
"url",
",",
"sendData",
")",
"{",
"DOMEventListener",
".",
"call",
"(",
"this",
")",
";",
"/**\r\n\t * Request object.\r\n\t *\r\n\t * @access protected\r\n\t * @type {XMLHttpRequest}\r\n\t */",
"this",
".",
"_request",
"=",
"new",
"Ajax",
".",
"XHRSystem",
"(",
")",
";",
"/**\r\n\t * Method of the request.\r\n\t *\r\n\t * @access protected \r\n\t * @type {String}\r\n\t */",
"this",
".",
"_method",
"=",
"method",
";",
"/**\r\n\t * Address of request.\r\n\t *\r\n\t * @access protected\r\n\t * @type {String}\r\n\t */",
"this",
".",
"_url",
"=",
"url",
";",
"/**\r\n\t * Data to send.\r\n\t *\r\n\t * @access protected\r\n\t * @type {(Object|String)}\r\n\t */",
"this",
".",
"_sendData",
"=",
"sendData",
";",
"/**\r\n\t * The content type of sending data.\r\n\t * \r\n\t * @access public\r\n\t * @type {String}\r\n\t */",
"this",
".",
"contentType",
"=",
"\"application/binary\"",
";",
"/**\r\n\t * Context conatiner.\r\n\t * @access private\r\n\t */",
"var",
"self",
"=",
"this",
";",
"/**\r\n\t * Override onload of XMLHTTPRequest.\r\n\t * Convert callback function into `Event`.\r\n\t */",
"this",
".",
"_request",
".",
"onload",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"dispatchEvent",
"(",
"new",
"Ajax",
".",
"Event",
"(",
"Ajax",
".",
"Event",
".",
"LOAD",
",",
"{",
"response",
":",
"self",
".",
"_request",
".",
"response",
",",
"responseText",
":",
"self",
".",
"_request",
".",
"responseText",
",",
"responseType",
":",
"self",
".",
"_request",
".",
"responseType",
",",
"responseURL",
":",
"self",
".",
"_request",
".",
"responseURL",
",",
"responseXML",
":",
"self",
".",
"_request",
".",
"responseXML",
",",
"status",
":",
"self",
".",
"_request",
".",
"status",
",",
"lengthComputable",
":",
"event",
".",
"lengthComputable",
",",
"loaded",
":",
"event",
".",
"loaded",
",",
"total",
":",
"event",
".",
"total",
"}",
")",
")",
";",
"}",
";",
"/**\r\n\t * Override onprogress of XMLHTTPRequest.\r\n\t * Convert callback function into `Event`.\r\n\t */",
"this",
".",
"_request",
".",
"onprogress",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"dispatchEvent",
"(",
"new",
"Ajax",
".",
"Event",
"(",
"Ajax",
".",
"Event",
".",
"PROGRESS",
",",
"{",
"lengthComputable",
":",
"event",
".",
"lengthComputable",
",",
"loaded",
":",
"event",
".",
"loaded",
",",
"total",
":",
"event",
".",
"total",
"}",
")",
")",
";",
"}",
";",
"}"
] | Asynchronous JavaScript and XML.
Wrapper to equalize and simplify the usage for AJAX calls.
@constructor
@param {String} method - Type of request (get, post, put, ...).
@param {String} url - Request address.
@param {(Object|String)} sendData - Data to send. | [
"Asynchronous",
"JavaScript",
"and",
"XML",
".",
"Wrapper",
"to",
"equalize",
"and",
"simplify",
"the",
"usage",
"for",
"AJAX",
"calls",
"."
] | ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04 | https://github.com/enbock/corejs-w3c/blob/ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04/src/core.js#L162-L244 |
55,760 | enbock/corejs-w3c | src/core.js | use | function use(fullQualifiedClassName) {
var container = use.getContainer(fullQualifiedClassName)
;
if (container._loader === null) {
use.loadCount++;
container._loader = Ajax.factory(
"get", container._path + use.fileExtension
);
container._loader.addEventListener(Ajax.Event.LOAD, function(event) {
var domains
, className
;
use.loadCount--;
// Load into script ram
container._class = new Function(event.detail.responseText);
// Import into context
domains = fullQualifiedClassName.split(use.classPathDelimiter);
className = domains.pop();
namespace(domains.join(use.classPathDelimiter), function() {
var contextBackup = null
, property
;
// Save old class name
if(this.hasOwnProperty(className)) {
contextBackup = this[className];
}
// Run loaded code
container._class.call(this);
// Restore backup
if (contextBackup === null) return;
if (this[className] !== contextBackup) {
for(property in contextBackup) {
if(property == className) continue;
if(this[className].hasOwnProperty(property)) {
throw new Error(
"CoreJs: "
+ "Overlapping namespace with class "
+ "property '"
+ fullQualifiedClassName +"."+property
+"' detected."
);
} else {
this[className][property] = contextBackup[property];
}
}
}
});
});
container._loader.addEventListener(
Ajax.Event.LOAD, namespace.handleEvent
);
container._loader.load();
}
} | javascript | function use(fullQualifiedClassName) {
var container = use.getContainer(fullQualifiedClassName)
;
if (container._loader === null) {
use.loadCount++;
container._loader = Ajax.factory(
"get", container._path + use.fileExtension
);
container._loader.addEventListener(Ajax.Event.LOAD, function(event) {
var domains
, className
;
use.loadCount--;
// Load into script ram
container._class = new Function(event.detail.responseText);
// Import into context
domains = fullQualifiedClassName.split(use.classPathDelimiter);
className = domains.pop();
namespace(domains.join(use.classPathDelimiter), function() {
var contextBackup = null
, property
;
// Save old class name
if(this.hasOwnProperty(className)) {
contextBackup = this[className];
}
// Run loaded code
container._class.call(this);
// Restore backup
if (contextBackup === null) return;
if (this[className] !== contextBackup) {
for(property in contextBackup) {
if(property == className) continue;
if(this[className].hasOwnProperty(property)) {
throw new Error(
"CoreJs: "
+ "Overlapping namespace with class "
+ "property '"
+ fullQualifiedClassName +"."+property
+"' detected."
);
} else {
this[className][property] = contextBackup[property];
}
}
}
});
});
container._loader.addEventListener(
Ajax.Event.LOAD, namespace.handleEvent
);
container._loader.load();
}
} | [
"function",
"use",
"(",
"fullQualifiedClassName",
")",
"{",
"var",
"container",
"=",
"use",
".",
"getContainer",
"(",
"fullQualifiedClassName",
")",
";",
"if",
"(",
"container",
".",
"_loader",
"===",
"null",
")",
"{",
"use",
".",
"loadCount",
"++",
";",
"container",
".",
"_loader",
"=",
"Ajax",
".",
"factory",
"(",
"\"get\"",
",",
"container",
".",
"_path",
"+",
"use",
".",
"fileExtension",
")",
";",
"container",
".",
"_loader",
".",
"addEventListener",
"(",
"Ajax",
".",
"Event",
".",
"LOAD",
",",
"function",
"(",
"event",
")",
"{",
"var",
"domains",
",",
"className",
";",
"use",
".",
"loadCount",
"--",
";",
"// Load into script ram\r",
"container",
".",
"_class",
"=",
"new",
"Function",
"(",
"event",
".",
"detail",
".",
"responseText",
")",
";",
"// Import into context\r",
"domains",
"=",
"fullQualifiedClassName",
".",
"split",
"(",
"use",
".",
"classPathDelimiter",
")",
";",
"className",
"=",
"domains",
".",
"pop",
"(",
")",
";",
"namespace",
"(",
"domains",
".",
"join",
"(",
"use",
".",
"classPathDelimiter",
")",
",",
"function",
"(",
")",
"{",
"var",
"contextBackup",
"=",
"null",
",",
"property",
";",
"// Save old class name\r",
"if",
"(",
"this",
".",
"hasOwnProperty",
"(",
"className",
")",
")",
"{",
"contextBackup",
"=",
"this",
"[",
"className",
"]",
";",
"}",
"// Run loaded code\r",
"container",
".",
"_class",
".",
"call",
"(",
"this",
")",
";",
"// Restore backup\r",
"if",
"(",
"contextBackup",
"===",
"null",
")",
"return",
";",
"if",
"(",
"this",
"[",
"className",
"]",
"!==",
"contextBackup",
")",
"{",
"for",
"(",
"property",
"in",
"contextBackup",
")",
"{",
"if",
"(",
"property",
"==",
"className",
")",
"continue",
";",
"if",
"(",
"this",
"[",
"className",
"]",
".",
"hasOwnProperty",
"(",
"property",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"CoreJs: \"",
"+",
"\"Overlapping namespace with class \"",
"+",
"\"property '\"",
"+",
"fullQualifiedClassName",
"+",
"\".\"",
"+",
"property",
"+",
"\"' detected.\"",
")",
";",
"}",
"else",
"{",
"this",
"[",
"className",
"]",
"[",
"property",
"]",
"=",
"contextBackup",
"[",
"property",
"]",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"container",
".",
"_loader",
".",
"addEventListener",
"(",
"Ajax",
".",
"Event",
".",
"LOAD",
",",
"namespace",
".",
"handleEvent",
")",
";",
"container",
".",
"_loader",
".",
"load",
"(",
")",
";",
"}",
"}"
] | Auto load system.
@signleton | [
"Auto",
"load",
"system",
"."
] | ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04 | https://github.com/enbock/corejs-w3c/blob/ae6b78f17152b1e8ddf1c0031b4f54cb0e419d04/src/core.js#L399-L455 |
55,761 | SoftEng-HEIGVD/iflux-node-client | lib/client.js | Client | function Client(endpointUrl, sourceId) {
this.restClient = new restClient.Client();
this.endpointUrl = endpointUrl;
if (this.endpointUrl) {
// Remove the trailing slash if necessary
if (this.endpointUrl.indexOf('/', this.endpointUrl.length - 1) !== -1) {
this.endpointUrl = this.endpointUrl.substr(0, this.endpointUrl.length - 2);
}
// Add the default version if not present
// TODO: The client should take care of the version in a better way
if (this.endpointUrl.indexOf('/v1', this.endpointUrl.length - 3) === -1) {
this.endpointUrl = this.endpointUrl + '/v1';
}
}
if (sourceId !== undefined) {
this.sourceId = sourceId;
}
} | javascript | function Client(endpointUrl, sourceId) {
this.restClient = new restClient.Client();
this.endpointUrl = endpointUrl;
if (this.endpointUrl) {
// Remove the trailing slash if necessary
if (this.endpointUrl.indexOf('/', this.endpointUrl.length - 1) !== -1) {
this.endpointUrl = this.endpointUrl.substr(0, this.endpointUrl.length - 2);
}
// Add the default version if not present
// TODO: The client should take care of the version in a better way
if (this.endpointUrl.indexOf('/v1', this.endpointUrl.length - 3) === -1) {
this.endpointUrl = this.endpointUrl + '/v1';
}
}
if (sourceId !== undefined) {
this.sourceId = sourceId;
}
} | [
"function",
"Client",
"(",
"endpointUrl",
",",
"sourceId",
")",
"{",
"this",
".",
"restClient",
"=",
"new",
"restClient",
".",
"Client",
"(",
")",
";",
"this",
".",
"endpointUrl",
"=",
"endpointUrl",
";",
"if",
"(",
"this",
".",
"endpointUrl",
")",
"{",
"// Remove the trailing slash if necessary",
"if",
"(",
"this",
".",
"endpointUrl",
".",
"indexOf",
"(",
"'/'",
",",
"this",
".",
"endpointUrl",
".",
"length",
"-",
"1",
")",
"!==",
"-",
"1",
")",
"{",
"this",
".",
"endpointUrl",
"=",
"this",
".",
"endpointUrl",
".",
"substr",
"(",
"0",
",",
"this",
".",
"endpointUrl",
".",
"length",
"-",
"2",
")",
";",
"}",
"// Add the default version if not present",
"// TODO: The client should take care of the version in a better way",
"if",
"(",
"this",
".",
"endpointUrl",
".",
"indexOf",
"(",
"'/v1'",
",",
"this",
".",
"endpointUrl",
".",
"length",
"-",
"3",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"endpointUrl",
"=",
"this",
".",
"endpointUrl",
"+",
"'/v1'",
";",
"}",
"}",
"if",
"(",
"sourceId",
"!==",
"undefined",
")",
"{",
"this",
".",
"sourceId",
"=",
"sourceId",
";",
"}",
"}"
] | Constructor for the iFLUX Client.
@param {string} endpointUrl The URL prefix for the API (e.g. http://api.iflux.io/api)
@param {string} sourceId The event source id
@constructor | [
"Constructor",
"for",
"the",
"iFLUX",
"Client",
"."
] | 5cb9fb4c0ca34ce120a876f6a64577fa97e3aac5 | https://github.com/SoftEng-HEIGVD/iflux-node-client/blob/5cb9fb4c0ca34ce120a876f6a64577fa97e3aac5/lib/client.js#L11-L32 |
55,762 | fieosa/webcomponent-mdl | src/utils/jsxdom.js | processChildren | function processChildren(ele, children) {
if (children && children.constructor === Array) {
for(var i = 0; i < children.length; i++) {
processChildren(ele, children[i]);
}
} else if (children instanceof Node) {
ele.appendChild(children);
} else if (children) {
ele.appendChild(document.createTextNode(children));
}
} | javascript | function processChildren(ele, children) {
if (children && children.constructor === Array) {
for(var i = 0; i < children.length; i++) {
processChildren(ele, children[i]);
}
} else if (children instanceof Node) {
ele.appendChild(children);
} else if (children) {
ele.appendChild(document.createTextNode(children));
}
} | [
"function",
"processChildren",
"(",
"ele",
",",
"children",
")",
"{",
"if",
"(",
"children",
"&&",
"children",
".",
"constructor",
"===",
"Array",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"processChildren",
"(",
"ele",
",",
"children",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"children",
"instanceof",
"Node",
")",
"{",
"ele",
".",
"appendChild",
"(",
"children",
")",
";",
"}",
"else",
"if",
"(",
"children",
")",
"{",
"ele",
".",
"appendChild",
"(",
"document",
".",
"createTextNode",
"(",
"children",
")",
")",
";",
"}",
"}"
] | Implementation of templating syntax for jsx.
To support tag nesting syntax:
examples:
<p>
<div></div>
<span><span/>
</p>
1. Recursively call processChildren which the 'children' parameter is an instance of n-dimensional array.
The above example is an array of [[div], [span]] as the children of <p> tag.
To support {this.children} syntax:
1. In processChildren, detect the type of this.children which is an instance of HTMLCollection.
2. Note that HTMLCollection is a list of HTMLElement extends from Object.
To support {this.childNodes} syntax:
1. In processChildren, detect the type of this.childNodes which is an instance of NodeList.
2. Note that NodeList is a list of Node extends from Object.
To support customizing attributes:
example:
for (var attrName in attributes) {
attributeHookFunction(ele, attrName, attrValue);
}
1. Mutate element through attributeHookFunction which passed to this module. | [
"Implementation",
"of",
"templating",
"syntax",
"for",
"jsx",
"."
] | 5aec1bfd5110addcbeedd01ba07b8a01c836c511 | https://github.com/fieosa/webcomponent-mdl/blob/5aec1bfd5110addcbeedd01ba07b8a01c836c511/src/utils/jsxdom.js#L33-L43 |
55,763 | overlookmotel/drive-watch | lib/index.js | getDrives | function getDrives() {
return getDrivesNow().then(function(drives) {
// if new drive events during scan, redo scan
if (newEvents) return getDrives();
recordDrives(drives);
if (self.options.scanInterval) self.scanTimer = setTimeout(updateDrives, self.options.scanInterval);
// return drives array, cloned so not altered by future events
return self.drives.slice(0);
});
} | javascript | function getDrives() {
return getDrivesNow().then(function(drives) {
// if new drive events during scan, redo scan
if (newEvents) return getDrives();
recordDrives(drives);
if (self.options.scanInterval) self.scanTimer = setTimeout(updateDrives, self.options.scanInterval);
// return drives array, cloned so not altered by future events
return self.drives.slice(0);
});
} | [
"function",
"getDrives",
"(",
")",
"{",
"return",
"getDrivesNow",
"(",
")",
".",
"then",
"(",
"function",
"(",
"drives",
")",
"{",
"// if new drive events during scan, redo scan",
"if",
"(",
"newEvents",
")",
"return",
"getDrives",
"(",
")",
";",
"recordDrives",
"(",
"drives",
")",
";",
"if",
"(",
"self",
".",
"options",
".",
"scanInterval",
")",
"self",
".",
"scanTimer",
"=",
"setTimeout",
"(",
"updateDrives",
",",
"self",
".",
"options",
".",
"scanInterval",
")",
";",
"// return drives array, cloned so not altered by future events",
"return",
"self",
".",
"drives",
".",
"slice",
"(",
"0",
")",
";",
"}",
")",
";",
"}"
] | get drives initially connected | [
"get",
"drives",
"initially",
"connected"
] | 61ca4c8c82aba06f0c3af3ca17cc4fd15fb78ed4 | https://github.com/overlookmotel/drive-watch/blob/61ca4c8c82aba06f0c3af3ca17cc4fd15fb78ed4/lib/index.js#L65-L76 |
55,764 | overlookmotel/drive-watch | lib/index.js | getDrivesNow | function getDrivesNow() {
reading = true;
newEvents = false;
return fs.readdirAsync(drivesPath)
.then(function(files) {
var drives = files.filter(function(name) {
return name != '.DS_Store';
});
return drives;
});
} | javascript | function getDrivesNow() {
reading = true;
newEvents = false;
return fs.readdirAsync(drivesPath)
.then(function(files) {
var drives = files.filter(function(name) {
return name != '.DS_Store';
});
return drives;
});
} | [
"function",
"getDrivesNow",
"(",
")",
"{",
"reading",
"=",
"true",
";",
"newEvents",
"=",
"false",
";",
"return",
"fs",
".",
"readdirAsync",
"(",
"drivesPath",
")",
".",
"then",
"(",
"function",
"(",
"files",
")",
"{",
"var",
"drives",
"=",
"files",
".",
"filter",
"(",
"function",
"(",
"name",
")",
"{",
"return",
"name",
"!=",
"'.DS_Store'",
";",
"}",
")",
";",
"return",
"drives",
";",
"}",
")",
";",
"}"
] | scan for connected drives | [
"scan",
"for",
"connected",
"drives"
] | 61ca4c8c82aba06f0c3af3ca17cc4fd15fb78ed4 | https://github.com/overlookmotel/drive-watch/blob/61ca4c8c82aba06f0c3af3ca17cc4fd15fb78ed4/lib/index.js#L107-L119 |
55,765 | fazo96/LC2.js | cli.js | onRead | function onRead (key) {
if (key !== null) {
if (cli.debug) console.log('Key:', key)
// Exits on CTRL-C
if (key === '\u0003') process.exit()
// If enter is pressed and the program is waiting for the user to press enter
// so that the emulator can step forward, then call the appropriate callback
if (key.charCodeAt(0) === 13 && readingFn() && onReadCb) onReadCb(key.charCodeAt(0))
else if (cpu) {
// Since the CPU is initialized and the program is not waiting for the user
// to press enter, pass the pressed key to the LC-2 CPU Console.
cpu.console.input(key)
}
readingFn(false)
}
} | javascript | function onRead (key) {
if (key !== null) {
if (cli.debug) console.log('Key:', key)
// Exits on CTRL-C
if (key === '\u0003') process.exit()
// If enter is pressed and the program is waiting for the user to press enter
// so that the emulator can step forward, then call the appropriate callback
if (key.charCodeAt(0) === 13 && readingFn() && onReadCb) onReadCb(key.charCodeAt(0))
else if (cpu) {
// Since the CPU is initialized and the program is not waiting for the user
// to press enter, pass the pressed key to the LC-2 CPU Console.
cpu.console.input(key)
}
readingFn(false)
}
} | [
"function",
"onRead",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"!==",
"null",
")",
"{",
"if",
"(",
"cli",
".",
"debug",
")",
"console",
".",
"log",
"(",
"'Key:'",
",",
"key",
")",
"// Exits on CTRL-C",
"if",
"(",
"key",
"===",
"'\\u0003'",
")",
"process",
".",
"exit",
"(",
")",
"// If enter is pressed and the program is waiting for the user to press enter",
"// so that the emulator can step forward, then call the appropriate callback",
"if",
"(",
"key",
".",
"charCodeAt",
"(",
"0",
")",
"===",
"13",
"&&",
"readingFn",
"(",
")",
"&&",
"onReadCb",
")",
"onReadCb",
"(",
"key",
".",
"charCodeAt",
"(",
"0",
")",
")",
"else",
"if",
"(",
"cpu",
")",
"{",
"// Since the CPU is initialized and the program is not waiting for the user",
"// to press enter, pass the pressed key to the LC-2 CPU Console.",
"cpu",
".",
"console",
".",
"input",
"(",
"key",
")",
"}",
"readingFn",
"(",
"false",
")",
"}",
"}"
] | This function processes an input key from STDIN. | [
"This",
"function",
"processes",
"an",
"input",
"key",
"from",
"STDIN",
"."
] | 33b1d1e84d5da7c0df16290fc1289628ba65b430 | https://github.com/fazo96/LC2.js/blob/33b1d1e84d5da7c0df16290fc1289628ba65b430/cli.js#L48-L63 |
55,766 | fazo96/LC2.js | cli.js | end | function end () {
console.log('\n=== REG DUMP ===\n' + cpu.regdump().join('\n'))
if (options.memDump) console.log('\n\n=== MEM DUMP ===\n' + cpu.memdump(0, 65535).join('\n'))
process.exit() // workaround for stdin event listener hanging
} | javascript | function end () {
console.log('\n=== REG DUMP ===\n' + cpu.regdump().join('\n'))
if (options.memDump) console.log('\n\n=== MEM DUMP ===\n' + cpu.memdump(0, 65535).join('\n'))
process.exit() // workaround for stdin event listener hanging
} | [
"function",
"end",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'\\n=== REG DUMP ===\\n'",
"+",
"cpu",
".",
"regdump",
"(",
")",
".",
"join",
"(",
"'\\n'",
")",
")",
"if",
"(",
"options",
".",
"memDump",
")",
"console",
".",
"log",
"(",
"'\\n\\n=== MEM DUMP ===\\n'",
"+",
"cpu",
".",
"memdump",
"(",
"0",
",",
"65535",
")",
".",
"join",
"(",
"'\\n'",
")",
")",
"process",
".",
"exit",
"(",
")",
"// workaround for stdin event listener hanging",
"}"
] | Called when the LC-2 program has finished running | [
"Called",
"when",
"the",
"LC",
"-",
"2",
"program",
"has",
"finished",
"running"
] | 33b1d1e84d5da7c0df16290fc1289628ba65b430 | https://github.com/fazo96/LC2.js/blob/33b1d1e84d5da7c0df16290fc1289628ba65b430/cli.js#L138-L142 |
55,767 | hitchyjs/server-dev-tools | bin/hitchy-pm.js | processSimple | function processSimple( names, current, stopAt, collector, done ) {
const name = names[current];
File.stat( Path.join( "node_modules", name, "hitchy.json" ), ( error, stat ) => {
if ( error ) {
if ( error.code === "ENOENT" ) {
collector.push( name );
} else {
done( error );
return;
}
} else if ( stat.isFile() ) {
if ( !quiet ) {
console.error( `${name} ... found` );
}
} else {
done( new Error( `dependency ${name}: not a folder` ) );
return;
}
if ( ++current < stopAt ) {
processSimple( names, current, stopAt, collector, done );
} else {
done( null, collector );
}
} );
} | javascript | function processSimple( names, current, stopAt, collector, done ) {
const name = names[current];
File.stat( Path.join( "node_modules", name, "hitchy.json" ), ( error, stat ) => {
if ( error ) {
if ( error.code === "ENOENT" ) {
collector.push( name );
} else {
done( error );
return;
}
} else if ( stat.isFile() ) {
if ( !quiet ) {
console.error( `${name} ... found` );
}
} else {
done( new Error( `dependency ${name}: not a folder` ) );
return;
}
if ( ++current < stopAt ) {
processSimple( names, current, stopAt, collector, done );
} else {
done( null, collector );
}
} );
} | [
"function",
"processSimple",
"(",
"names",
",",
"current",
",",
"stopAt",
",",
"collector",
",",
"done",
")",
"{",
"const",
"name",
"=",
"names",
"[",
"current",
"]",
";",
"File",
".",
"stat",
"(",
"Path",
".",
"join",
"(",
"\"node_modules\"",
",",
"name",
",",
"\"hitchy.json\"",
")",
",",
"(",
"error",
",",
"stat",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"if",
"(",
"error",
".",
"code",
"===",
"\"ENOENT\"",
")",
"{",
"collector",
".",
"push",
"(",
"name",
")",
";",
"}",
"else",
"{",
"done",
"(",
"error",
")",
";",
"return",
";",
"}",
"}",
"else",
"if",
"(",
"stat",
".",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"!",
"quiet",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
";",
"}",
"}",
"else",
"{",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"++",
"current",
"<",
"stopAt",
")",
"{",
"processSimple",
"(",
"names",
",",
"current",
",",
"stopAt",
",",
"collector",
",",
"done",
")",
";",
"}",
"else",
"{",
"done",
"(",
"null",
",",
"collector",
")",
";",
"}",
"}",
")",
";",
"}"
] | Successively tests provided names of dependencies for matching existing
folder in local sub-folder `node_modules` each containing file hitchy.json.
@param {string[]} names list of dependency names to be tested
@param {int} current index of next item in provided list to be processed
@param {int} stopAt index to stop at
@param {string[]} collector lists names considered missing related folder in local `node_modules`
@param {function(?Error)} done callback invoked on error or when done | [
"Successively",
"tests",
"provided",
"names",
"of",
"dependencies",
"for",
"matching",
"existing",
"folder",
"in",
"local",
"sub",
"-",
"folder",
"node_modules",
"each",
"containing",
"file",
"hitchy",
".",
"json",
"."
] | 352c0de74b532b474a71816fdc63d2218c126536 | https://github.com/hitchyjs/server-dev-tools/blob/352c0de74b532b474a71816fdc63d2218c126536/bin/hitchy-pm.js#L125-L151 |
55,768 | hitchyjs/server-dev-tools | bin/hitchy-pm.js | installMissing | function installMissing( error, collected ) {
if ( error ) {
console.error( `checking dependencies failed: ${error.message}` );
process.exit( 1 );
return;
}
if ( collected.length < 1 ) {
postProcess( 0 );
} else {
if ( !quiet ) {
console.error( `installing missing dependencies:\n${collected.map( d => `* ${d}`).join( "\n" )}` );
}
const npm = Child.exec( `npm install --no-save ${collected.join( " " )}`, {
stdio: "pipe",
} );
npm.stdout.pipe( process.stdout );
npm.stderr.pipe( process.stderr );
npm.on( "exit", postProcess );
}
} | javascript | function installMissing( error, collected ) {
if ( error ) {
console.error( `checking dependencies failed: ${error.message}` );
process.exit( 1 );
return;
}
if ( collected.length < 1 ) {
postProcess( 0 );
} else {
if ( !quiet ) {
console.error( `installing missing dependencies:\n${collected.map( d => `* ${d}`).join( "\n" )}` );
}
const npm = Child.exec( `npm install --no-save ${collected.join( " " )}`, {
stdio: "pipe",
} );
npm.stdout.pipe( process.stdout );
npm.stderr.pipe( process.stderr );
npm.on( "exit", postProcess );
}
} | [
"function",
"installMissing",
"(",
"error",
",",
"collected",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"error",
".",
"message",
"}",
"`",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"return",
";",
"}",
"if",
"(",
"collected",
".",
"length",
"<",
"1",
")",
"{",
"postProcess",
"(",
"0",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"quiet",
")",
"{",
"console",
".",
"error",
"(",
"`",
"\\n",
"${",
"collected",
".",
"map",
"(",
"d",
"=>",
"`",
"${",
"d",
"}",
"`",
")",
".",
"join",
"(",
"\"\\n\"",
")",
"}",
"`",
")",
";",
"}",
"const",
"npm",
"=",
"Child",
".",
"exec",
"(",
"`",
"${",
"collected",
".",
"join",
"(",
"\" \"",
")",
"}",
"`",
",",
"{",
"stdio",
":",
"\"pipe\"",
",",
"}",
")",
";",
"npm",
".",
"stdout",
".",
"pipe",
"(",
"process",
".",
"stdout",
")",
";",
"npm",
".",
"stderr",
".",
"pipe",
"(",
"process",
".",
"stderr",
")",
";",
"npm",
".",
"on",
"(",
"\"exit\"",
",",
"postProcess",
")",
";",
"}",
"}"
] | Installs collected dependencies considered missing or handles provided error.
@param {Error} error encountered error
@param {string[]} collected list of dependencies considered missing | [
"Installs",
"collected",
"dependencies",
"considered",
"missing",
"or",
"handles",
"provided",
"error",
"."
] | 352c0de74b532b474a71816fdc63d2218c126536 | https://github.com/hitchyjs/server-dev-tools/blob/352c0de74b532b474a71816fdc63d2218c126536/bin/hitchy-pm.js#L159-L183 |
55,769 | hitchyjs/server-dev-tools | bin/hitchy-pm.js | postProcess | function postProcess( errorCode ) {
if ( errorCode ) {
console.error( `running npm for installing missing dependencies ${collected.join( ", " )} exited on error (${errorCode})` );
} else if ( exec ) {
const cmd = exec.join( " " );
if ( !quiet ) {
console.error( `invoking follow-up command: ${cmd}` );
}
const followup = Child.exec( cmd );
followup.stdout.pipe( process.stdout );
followup.stderr.pipe( process.stderr );
followup.on( "exit", code => {
process.exit( code );
} );
return;
}
process.exit( errorCode );
} | javascript | function postProcess( errorCode ) {
if ( errorCode ) {
console.error( `running npm for installing missing dependencies ${collected.join( ", " )} exited on error (${errorCode})` );
} else if ( exec ) {
const cmd = exec.join( " " );
if ( !quiet ) {
console.error( `invoking follow-up command: ${cmd}` );
}
const followup = Child.exec( cmd );
followup.stdout.pipe( process.stdout );
followup.stderr.pipe( process.stderr );
followup.on( "exit", code => {
process.exit( code );
} );
return;
}
process.exit( errorCode );
} | [
"function",
"postProcess",
"(",
"errorCode",
")",
"{",
"if",
"(",
"errorCode",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"collected",
".",
"join",
"(",
"\", \"",
")",
"}",
"${",
"errorCode",
"}",
"`",
")",
";",
"}",
"else",
"if",
"(",
"exec",
")",
"{",
"const",
"cmd",
"=",
"exec",
".",
"join",
"(",
"\" \"",
")",
";",
"if",
"(",
"!",
"quiet",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"cmd",
"}",
"`",
")",
";",
"}",
"const",
"followup",
"=",
"Child",
".",
"exec",
"(",
"cmd",
")",
";",
"followup",
".",
"stdout",
".",
"pipe",
"(",
"process",
".",
"stdout",
")",
";",
"followup",
".",
"stderr",
".",
"pipe",
"(",
"process",
".",
"stderr",
")",
";",
"followup",
".",
"on",
"(",
"\"exit\"",
",",
"code",
"=>",
"{",
"process",
".",
"exit",
"(",
"code",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"process",
".",
"exit",
"(",
"errorCode",
")",
";",
"}"
] | Handles event of having passed installation of missing dependencies.
@param {int} errorCode status code on exit of npm installing missing dependencies | [
"Handles",
"event",
"of",
"having",
"passed",
"installation",
"of",
"missing",
"dependencies",
"."
] | 352c0de74b532b474a71816fdc63d2218c126536 | https://github.com/hitchyjs/server-dev-tools/blob/352c0de74b532b474a71816fdc63d2218c126536/bin/hitchy-pm.js#L190-L213 |
55,770 | shinuza/captain-admin | public/js/lib/alertify.js | function (fn) {
var hasOK = (typeof btnOK !== "undefined"),
hasCancel = (typeof btnCancel !== "undefined"),
hasInput = (typeof input !== "undefined"),
val = "",
self = this,
ok, cancel, common, key, reset;
// ok event handler
ok = function (event) {
if (typeof event.preventDefault !== "undefined") event.preventDefault();
common(event);
if (typeof input !== "undefined") val = input.value;
if (typeof fn === "function") {
if (typeof input !== "undefined") {
fn(true, val);
}
else fn(true);
}
return false;
};
// cancel event handler
cancel = function (event) {
if (typeof event.preventDefault !== "undefined") event.preventDefault();
common(event);
if (typeof fn === "function") fn(false);
return false;
};
// common event handler (keyup, ok and cancel)
common = function (event) {
self.hide();
self.unbind(document.body, "keyup", key);
self.unbind(btnReset, "focus", reset);
if (hasInput) self.unbind(form, "submit", ok);
if (hasOK) self.unbind(btnOK, "click", ok);
if (hasCancel) self.unbind(btnCancel, "click", cancel);
};
// keyup handler
key = function (event) {
var keyCode = event.keyCode;
if (keyCode === keys.SPACE && !hasInput) ok(event);
if (keyCode === keys.ESC && hasCancel) cancel(event);
};
// reset focus to first item in the dialog
reset = function (event) {
if (hasInput) input.focus();
else if (!hasCancel || self.buttonReverse) btnOK.focus();
else btnCancel.focus();
};
// handle reset focus link
// this ensures that the keyboard focus does not
// ever leave the dialog box until an action has
// been taken
this.bind(btnReset, "focus", reset);
// handle OK click
if (hasOK) this.bind(btnOK, "click", ok);
// handle Cancel click
if (hasCancel) this.bind(btnCancel, "click", cancel);
// listen for keys, Cancel => ESC
this.bind(document.body, "keyup", key);
// bind form submit
if (hasInput) this.bind(form, "submit", ok);
if (!this.transition.supported) {
this.setFocus();
}
} | javascript | function (fn) {
var hasOK = (typeof btnOK !== "undefined"),
hasCancel = (typeof btnCancel !== "undefined"),
hasInput = (typeof input !== "undefined"),
val = "",
self = this,
ok, cancel, common, key, reset;
// ok event handler
ok = function (event) {
if (typeof event.preventDefault !== "undefined") event.preventDefault();
common(event);
if (typeof input !== "undefined") val = input.value;
if (typeof fn === "function") {
if (typeof input !== "undefined") {
fn(true, val);
}
else fn(true);
}
return false;
};
// cancel event handler
cancel = function (event) {
if (typeof event.preventDefault !== "undefined") event.preventDefault();
common(event);
if (typeof fn === "function") fn(false);
return false;
};
// common event handler (keyup, ok and cancel)
common = function (event) {
self.hide();
self.unbind(document.body, "keyup", key);
self.unbind(btnReset, "focus", reset);
if (hasInput) self.unbind(form, "submit", ok);
if (hasOK) self.unbind(btnOK, "click", ok);
if (hasCancel) self.unbind(btnCancel, "click", cancel);
};
// keyup handler
key = function (event) {
var keyCode = event.keyCode;
if (keyCode === keys.SPACE && !hasInput) ok(event);
if (keyCode === keys.ESC && hasCancel) cancel(event);
};
// reset focus to first item in the dialog
reset = function (event) {
if (hasInput) input.focus();
else if (!hasCancel || self.buttonReverse) btnOK.focus();
else btnCancel.focus();
};
// handle reset focus link
// this ensures that the keyboard focus does not
// ever leave the dialog box until an action has
// been taken
this.bind(btnReset, "focus", reset);
// handle OK click
if (hasOK) this.bind(btnOK, "click", ok);
// handle Cancel click
if (hasCancel) this.bind(btnCancel, "click", cancel);
// listen for keys, Cancel => ESC
this.bind(document.body, "keyup", key);
// bind form submit
if (hasInput) this.bind(form, "submit", ok);
if (!this.transition.supported) {
this.setFocus();
}
} | [
"function",
"(",
"fn",
")",
"{",
"var",
"hasOK",
"=",
"(",
"typeof",
"btnOK",
"!==",
"\"undefined\"",
")",
",",
"hasCancel",
"=",
"(",
"typeof",
"btnCancel",
"!==",
"\"undefined\"",
")",
",",
"hasInput",
"=",
"(",
"typeof",
"input",
"!==",
"\"undefined\"",
")",
",",
"val",
"=",
"\"\"",
",",
"self",
"=",
"this",
",",
"ok",
",",
"cancel",
",",
"common",
",",
"key",
",",
"reset",
";",
"// ok event handler",
"ok",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"typeof",
"event",
".",
"preventDefault",
"!==",
"\"undefined\"",
")",
"event",
".",
"preventDefault",
"(",
")",
";",
"common",
"(",
"event",
")",
";",
"if",
"(",
"typeof",
"input",
"!==",
"\"undefined\"",
")",
"val",
"=",
"input",
".",
"value",
";",
"if",
"(",
"typeof",
"fn",
"===",
"\"function\"",
")",
"{",
"if",
"(",
"typeof",
"input",
"!==",
"\"undefined\"",
")",
"{",
"fn",
"(",
"true",
",",
"val",
")",
";",
"}",
"else",
"fn",
"(",
"true",
")",
";",
"}",
"return",
"false",
";",
"}",
";",
"// cancel event handler",
"cancel",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"typeof",
"event",
".",
"preventDefault",
"!==",
"\"undefined\"",
")",
"event",
".",
"preventDefault",
"(",
")",
";",
"common",
"(",
"event",
")",
";",
"if",
"(",
"typeof",
"fn",
"===",
"\"function\"",
")",
"fn",
"(",
"false",
")",
";",
"return",
"false",
";",
"}",
";",
"// common event handler (keyup, ok and cancel)",
"common",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"hide",
"(",
")",
";",
"self",
".",
"unbind",
"(",
"document",
".",
"body",
",",
"\"keyup\"",
",",
"key",
")",
";",
"self",
".",
"unbind",
"(",
"btnReset",
",",
"\"focus\"",
",",
"reset",
")",
";",
"if",
"(",
"hasInput",
")",
"self",
".",
"unbind",
"(",
"form",
",",
"\"submit\"",
",",
"ok",
")",
";",
"if",
"(",
"hasOK",
")",
"self",
".",
"unbind",
"(",
"btnOK",
",",
"\"click\"",
",",
"ok",
")",
";",
"if",
"(",
"hasCancel",
")",
"self",
".",
"unbind",
"(",
"btnCancel",
",",
"\"click\"",
",",
"cancel",
")",
";",
"}",
";",
"// keyup handler",
"key",
"=",
"function",
"(",
"event",
")",
"{",
"var",
"keyCode",
"=",
"event",
".",
"keyCode",
";",
"if",
"(",
"keyCode",
"===",
"keys",
".",
"SPACE",
"&&",
"!",
"hasInput",
")",
"ok",
"(",
"event",
")",
";",
"if",
"(",
"keyCode",
"===",
"keys",
".",
"ESC",
"&&",
"hasCancel",
")",
"cancel",
"(",
"event",
")",
";",
"}",
";",
"// reset focus to first item in the dialog",
"reset",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"hasInput",
")",
"input",
".",
"focus",
"(",
")",
";",
"else",
"if",
"(",
"!",
"hasCancel",
"||",
"self",
".",
"buttonReverse",
")",
"btnOK",
".",
"focus",
"(",
")",
";",
"else",
"btnCancel",
".",
"focus",
"(",
")",
";",
"}",
";",
"// handle reset focus link",
"// this ensures that the keyboard focus does not",
"// ever leave the dialog box until an action has",
"// been taken",
"this",
".",
"bind",
"(",
"btnReset",
",",
"\"focus\"",
",",
"reset",
")",
";",
"// handle OK click",
"if",
"(",
"hasOK",
")",
"this",
".",
"bind",
"(",
"btnOK",
",",
"\"click\"",
",",
"ok",
")",
";",
"// handle Cancel click",
"if",
"(",
"hasCancel",
")",
"this",
".",
"bind",
"(",
"btnCancel",
",",
"\"click\"",
",",
"cancel",
")",
";",
"// listen for keys, Cancel => ESC",
"this",
".",
"bind",
"(",
"document",
".",
"body",
",",
"\"keyup\"",
",",
"key",
")",
";",
"// bind form submit",
"if",
"(",
"hasInput",
")",
"this",
".",
"bind",
"(",
"form",
",",
"\"submit\"",
",",
"ok",
")",
";",
"if",
"(",
"!",
"this",
".",
"transition",
".",
"supported",
")",
"{",
"this",
".",
"setFocus",
"(",
")",
";",
"}",
"}"
] | Set the proper button click events
@param {Function} fn [Optional] Callback function
@return {undefined} | [
"Set",
"the",
"proper",
"button",
"click",
"events"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L119-L189 |
|
55,771 | shinuza/captain-admin | public/js/lib/alertify.js | function (item) {
var html = "",
type = item.type,
message = item.message,
css = item.cssClass || "";
html += "<div class=\"alertify-dialog\">";
if (_alertify.buttonFocus === "none") html += "<a href=\"#\" id=\"alertify-noneFocus\" class=\"alertify-hidden\"></a>";
if (type === "prompt") html += "<form id=\"alertify-form\">";
html += "<article class=\"alertify-inner\">";
html += dialogs.message.replace("{{message}}", message);
if (type === "prompt") html += dialogs.input;
html += dialogs.buttons.holder;
html += "</article>";
if (type === "prompt") html += "</form>";
html += "<a id=\"alertify-resetFocus\" class=\"alertify-resetFocus\" href=\"#\">Reset Focus</a>";
html += "</div>";
switch (type) {
case "confirm":
html = html.replace("{{buttons}}", this.appendButtons(dialogs.buttons.cancel, dialogs.buttons.ok));
html = html.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
break;
case "prompt":
html = html.replace("{{buttons}}", this.appendButtons(dialogs.buttons.cancel, dialogs.buttons.submit));
html = html.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
break;
case "alert":
html = html.replace("{{buttons}}", dialogs.buttons.ok);
html = html.replace("{{ok}}", this.labels.ok);
break;
default:
break;
}
elDialog.className = "alertify alertify-" + type + " " + css;
elCover.className = "alertify-cover";
return html;
} | javascript | function (item) {
var html = "",
type = item.type,
message = item.message,
css = item.cssClass || "";
html += "<div class=\"alertify-dialog\">";
if (_alertify.buttonFocus === "none") html += "<a href=\"#\" id=\"alertify-noneFocus\" class=\"alertify-hidden\"></a>";
if (type === "prompt") html += "<form id=\"alertify-form\">";
html += "<article class=\"alertify-inner\">";
html += dialogs.message.replace("{{message}}", message);
if (type === "prompt") html += dialogs.input;
html += dialogs.buttons.holder;
html += "</article>";
if (type === "prompt") html += "</form>";
html += "<a id=\"alertify-resetFocus\" class=\"alertify-resetFocus\" href=\"#\">Reset Focus</a>";
html += "</div>";
switch (type) {
case "confirm":
html = html.replace("{{buttons}}", this.appendButtons(dialogs.buttons.cancel, dialogs.buttons.ok));
html = html.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
break;
case "prompt":
html = html.replace("{{buttons}}", this.appendButtons(dialogs.buttons.cancel, dialogs.buttons.submit));
html = html.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
break;
case "alert":
html = html.replace("{{buttons}}", dialogs.buttons.ok);
html = html.replace("{{ok}}", this.labels.ok);
break;
default:
break;
}
elDialog.className = "alertify alertify-" + type + " " + css;
elCover.className = "alertify-cover";
return html;
} | [
"function",
"(",
"item",
")",
"{",
"var",
"html",
"=",
"\"\"",
",",
"type",
"=",
"item",
".",
"type",
",",
"message",
"=",
"item",
".",
"message",
",",
"css",
"=",
"item",
".",
"cssClass",
"||",
"\"\"",
";",
"html",
"+=",
"\"<div class=\\\"alertify-dialog\\\">\"",
";",
"if",
"(",
"_alertify",
".",
"buttonFocus",
"===",
"\"none\"",
")",
"html",
"+=",
"\"<a href=\\\"#\\\" id=\\\"alertify-noneFocus\\\" class=\\\"alertify-hidden\\\"></a>\"",
";",
"if",
"(",
"type",
"===",
"\"prompt\"",
")",
"html",
"+=",
"\"<form id=\\\"alertify-form\\\">\"",
";",
"html",
"+=",
"\"<article class=\\\"alertify-inner\\\">\"",
";",
"html",
"+=",
"dialogs",
".",
"message",
".",
"replace",
"(",
"\"{{message}}\"",
",",
"message",
")",
";",
"if",
"(",
"type",
"===",
"\"prompt\"",
")",
"html",
"+=",
"dialogs",
".",
"input",
";",
"html",
"+=",
"dialogs",
".",
"buttons",
".",
"holder",
";",
"html",
"+=",
"\"</article>\"",
";",
"if",
"(",
"type",
"===",
"\"prompt\"",
")",
"html",
"+=",
"\"</form>\"",
";",
"html",
"+=",
"\"<a id=\\\"alertify-resetFocus\\\" class=\\\"alertify-resetFocus\\\" href=\\\"#\\\">Reset Focus</a>\"",
";",
"html",
"+=",
"\"</div>\"",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"\"confirm\"",
":",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{buttons}}\"",
",",
"this",
".",
"appendButtons",
"(",
"dialogs",
".",
"buttons",
".",
"cancel",
",",
"dialogs",
".",
"buttons",
".",
"ok",
")",
")",
";",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{ok}}\"",
",",
"this",
".",
"labels",
".",
"ok",
")",
".",
"replace",
"(",
"\"{{cancel}}\"",
",",
"this",
".",
"labels",
".",
"cancel",
")",
";",
"break",
";",
"case",
"\"prompt\"",
":",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{buttons}}\"",
",",
"this",
".",
"appendButtons",
"(",
"dialogs",
".",
"buttons",
".",
"cancel",
",",
"dialogs",
".",
"buttons",
".",
"submit",
")",
")",
";",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{ok}}\"",
",",
"this",
".",
"labels",
".",
"ok",
")",
".",
"replace",
"(",
"\"{{cancel}}\"",
",",
"this",
".",
"labels",
".",
"cancel",
")",
";",
"break",
";",
"case",
"\"alert\"",
":",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{buttons}}\"",
",",
"dialogs",
".",
"buttons",
".",
"ok",
")",
";",
"html",
"=",
"html",
".",
"replace",
"(",
"\"{{ok}}\"",
",",
"this",
".",
"labels",
".",
"ok",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"elDialog",
".",
"className",
"=",
"\"alertify alertify-\"",
"+",
"type",
"+",
"\" \"",
"+",
"css",
";",
"elCover",
".",
"className",
"=",
"\"alertify-cover\"",
";",
"return",
"html",
";",
"}"
] | Build the proper message box
@param {Object} item Current object in the queue
@return {String} An HTML string of the message box | [
"Build",
"the",
"proper",
"message",
"box"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L244-L289 |
|
55,772 | shinuza/captain-admin | public/js/lib/alertify.js | function (elem, wait) {
// Unary Plus: +"2" === 2
var timer = (wait && !isNaN(wait)) ? +wait : this.delay,
self = this,
hideElement, transitionDone;
// set click event on log messages
this.bind(elem, "click", function () {
hideElement(elem);
});
// Hide the dialog box after transition
// This ensure it doens't block any element from being clicked
transitionDone = function (event) {
event.stopPropagation();
// unbind event so function only gets called once
self.unbind(this, self.transition.type, transitionDone);
// remove log message
elLog.removeChild(this);
if (!elLog.hasChildNodes()) elLog.className += " alertify-logs-hidden";
};
// this sets the hide class to transition out
// or removes the child if css transitions aren't supported
hideElement = function (el) {
// ensure element exists
if (typeof el !== "undefined" && el.parentNode === elLog) {
// whether CSS transition exists
if (self.transition.supported) {
self.bind(el, self.transition.type, transitionDone);
el.className += " alertify-log-hide";
} else {
elLog.removeChild(el);
if (!elLog.hasChildNodes()) elLog.className += " alertify-logs-hidden";
}
}
};
// never close (until click) if wait is set to 0
if (wait === 0) return;
// set timeout to auto close the log message
setTimeout(function () { hideElement(elem); }, timer);
} | javascript | function (elem, wait) {
// Unary Plus: +"2" === 2
var timer = (wait && !isNaN(wait)) ? +wait : this.delay,
self = this,
hideElement, transitionDone;
// set click event on log messages
this.bind(elem, "click", function () {
hideElement(elem);
});
// Hide the dialog box after transition
// This ensure it doens't block any element from being clicked
transitionDone = function (event) {
event.stopPropagation();
// unbind event so function only gets called once
self.unbind(this, self.transition.type, transitionDone);
// remove log message
elLog.removeChild(this);
if (!elLog.hasChildNodes()) elLog.className += " alertify-logs-hidden";
};
// this sets the hide class to transition out
// or removes the child if css transitions aren't supported
hideElement = function (el) {
// ensure element exists
if (typeof el !== "undefined" && el.parentNode === elLog) {
// whether CSS transition exists
if (self.transition.supported) {
self.bind(el, self.transition.type, transitionDone);
el.className += " alertify-log-hide";
} else {
elLog.removeChild(el);
if (!elLog.hasChildNodes()) elLog.className += " alertify-logs-hidden";
}
}
};
// never close (until click) if wait is set to 0
if (wait === 0) return;
// set timeout to auto close the log message
setTimeout(function () { hideElement(elem); }, timer);
} | [
"function",
"(",
"elem",
",",
"wait",
")",
"{",
"// Unary Plus: +\"2\" === 2",
"var",
"timer",
"=",
"(",
"wait",
"&&",
"!",
"isNaN",
"(",
"wait",
")",
")",
"?",
"+",
"wait",
":",
"this",
".",
"delay",
",",
"self",
"=",
"this",
",",
"hideElement",
",",
"transitionDone",
";",
"// set click event on log messages",
"this",
".",
"bind",
"(",
"elem",
",",
"\"click\"",
",",
"function",
"(",
")",
"{",
"hideElement",
"(",
"elem",
")",
";",
"}",
")",
";",
"// Hide the dialog box after transition",
"// This ensure it doens't block any element from being clicked",
"transitionDone",
"=",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"// unbind event so function only gets called once",
"self",
".",
"unbind",
"(",
"this",
",",
"self",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"// remove log message",
"elLog",
".",
"removeChild",
"(",
"this",
")",
";",
"if",
"(",
"!",
"elLog",
".",
"hasChildNodes",
"(",
")",
")",
"elLog",
".",
"className",
"+=",
"\" alertify-logs-hidden\"",
";",
"}",
";",
"// this sets the hide class to transition out",
"// or removes the child if css transitions aren't supported",
"hideElement",
"=",
"function",
"(",
"el",
")",
"{",
"// ensure element exists",
"if",
"(",
"typeof",
"el",
"!==",
"\"undefined\"",
"&&",
"el",
".",
"parentNode",
"===",
"elLog",
")",
"{",
"// whether CSS transition exists",
"if",
"(",
"self",
".",
"transition",
".",
"supported",
")",
"{",
"self",
".",
"bind",
"(",
"el",
",",
"self",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"el",
".",
"className",
"+=",
"\" alertify-log-hide\"",
";",
"}",
"else",
"{",
"elLog",
".",
"removeChild",
"(",
"el",
")",
";",
"if",
"(",
"!",
"elLog",
".",
"hasChildNodes",
"(",
")",
")",
"elLog",
".",
"className",
"+=",
"\" alertify-logs-hidden\"",
";",
"}",
"}",
"}",
";",
"// never close (until click) if wait is set to 0",
"if",
"(",
"wait",
"===",
"0",
")",
"return",
";",
"// set timeout to auto close the log message",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"hideElement",
"(",
"elem",
")",
";",
"}",
",",
"timer",
")",
";",
"}"
] | Close the log messages
@param {Object} elem HTML Element of log message to close
@param {Number} wait [optional] Time (in ms) to wait before automatically hiding the message, if 0 never hide
@return {undefined} | [
"Close",
"the",
"log",
"messages"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L299-L338 |
|
55,773 | shinuza/captain-admin | public/js/lib/alertify.js | function (message, type, fn, placeholder, cssClass) {
// set the current active element
// this allows the keyboard focus to be resetted
// after the dialog box is closed
elCallee = document.activeElement;
// check to ensure the alertify dialog element
// has been successfully created
var check = function () {
if ((elLog && elLog.scrollTop !== null) && (elCover && elCover.scrollTop !== null)) return;
else check();
};
// error catching
if (typeof message !== "string") throw new Error("message must be a string");
if (typeof type !== "string") throw new Error("type must be a string");
if (typeof fn !== "undefined" && typeof fn !== "function") throw new Error("fn must be a function");
// initialize alertify if it hasn't already been done
if (typeof this.init === "function") {
this.init();
check();
}
queue.push({ type: type, message: message, callback: fn, placeholder: placeholder, cssClass: cssClass });
if (!isopen) this.setup();
return this;
} | javascript | function (message, type, fn, placeholder, cssClass) {
// set the current active element
// this allows the keyboard focus to be resetted
// after the dialog box is closed
elCallee = document.activeElement;
// check to ensure the alertify dialog element
// has been successfully created
var check = function () {
if ((elLog && elLog.scrollTop !== null) && (elCover && elCover.scrollTop !== null)) return;
else check();
};
// error catching
if (typeof message !== "string") throw new Error("message must be a string");
if (typeof type !== "string") throw new Error("type must be a string");
if (typeof fn !== "undefined" && typeof fn !== "function") throw new Error("fn must be a function");
// initialize alertify if it hasn't already been done
if (typeof this.init === "function") {
this.init();
check();
}
queue.push({ type: type, message: message, callback: fn, placeholder: placeholder, cssClass: cssClass });
if (!isopen) this.setup();
return this;
} | [
"function",
"(",
"message",
",",
"type",
",",
"fn",
",",
"placeholder",
",",
"cssClass",
")",
"{",
"// set the current active element",
"// this allows the keyboard focus to be resetted",
"// after the dialog box is closed",
"elCallee",
"=",
"document",
".",
"activeElement",
";",
"// check to ensure the alertify dialog element",
"// has been successfully created",
"var",
"check",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"(",
"elLog",
"&&",
"elLog",
".",
"scrollTop",
"!==",
"null",
")",
"&&",
"(",
"elCover",
"&&",
"elCover",
".",
"scrollTop",
"!==",
"null",
")",
")",
"return",
";",
"else",
"check",
"(",
")",
";",
"}",
";",
"// error catching",
"if",
"(",
"typeof",
"message",
"!==",
"\"string\"",
")",
"throw",
"new",
"Error",
"(",
"\"message must be a string\"",
")",
";",
"if",
"(",
"typeof",
"type",
"!==",
"\"string\"",
")",
"throw",
"new",
"Error",
"(",
"\"type must be a string\"",
")",
";",
"if",
"(",
"typeof",
"fn",
"!==",
"\"undefined\"",
"&&",
"typeof",
"fn",
"!==",
"\"function\"",
")",
"throw",
"new",
"Error",
"(",
"\"fn must be a function\"",
")",
";",
"// initialize alertify if it hasn't already been done",
"if",
"(",
"typeof",
"this",
".",
"init",
"===",
"\"function\"",
")",
"{",
"this",
".",
"init",
"(",
")",
";",
"check",
"(",
")",
";",
"}",
"queue",
".",
"push",
"(",
"{",
"type",
":",
"type",
",",
"message",
":",
"message",
",",
"callback",
":",
"fn",
",",
"placeholder",
":",
"placeholder",
",",
"cssClass",
":",
"cssClass",
"}",
")",
";",
"if",
"(",
"!",
"isopen",
")",
"this",
".",
"setup",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Create a dialog box
@param {String} message The message passed from the callee
@param {String} type Type of dialog to create
@param {Function} fn [Optional] Callback function
@param {String} placeholder [Optional] Default value for prompt input field
@param {String} cssClass [Optional] Class(es) to append to dialog box
@return {Object} | [
"Create",
"a",
"dialog",
"box"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L351-L376 |
|
55,774 | shinuza/captain-admin | public/js/lib/alertify.js | function () {
var transitionDone,
self = this;
// remove reference from queue
queue.splice(0,1);
// if items remaining in the queue
if (queue.length > 0) this.setup(true);
else {
isopen = false;
// Hide the dialog box after transition
// This ensure it doens't block any element from being clicked
transitionDone = function (event) {
event.stopPropagation();
elDialog.className += " alertify-isHidden";
// unbind event so function only gets called once
self.unbind(elDialog, self.transition.type, transitionDone);
};
// whether CSS transition exists
if (this.transition.supported) {
this.bind(elDialog, this.transition.type, transitionDone);
elDialog.className = "alertify alertify-hide alertify-hidden";
} else {
elDialog.className = "alertify alertify-hide alertify-hidden alertify-isHidden";
}
elCover.className = "alertify-cover alertify-cover-hidden";
// set focus to the last element or body
// after the dialog is closed
elCallee.focus();
}
} | javascript | function () {
var transitionDone,
self = this;
// remove reference from queue
queue.splice(0,1);
// if items remaining in the queue
if (queue.length > 0) this.setup(true);
else {
isopen = false;
// Hide the dialog box after transition
// This ensure it doens't block any element from being clicked
transitionDone = function (event) {
event.stopPropagation();
elDialog.className += " alertify-isHidden";
// unbind event so function only gets called once
self.unbind(elDialog, self.transition.type, transitionDone);
};
// whether CSS transition exists
if (this.transition.supported) {
this.bind(elDialog, this.transition.type, transitionDone);
elDialog.className = "alertify alertify-hide alertify-hidden";
} else {
elDialog.className = "alertify alertify-hide alertify-hidden alertify-isHidden";
}
elCover.className = "alertify-cover alertify-cover-hidden";
// set focus to the last element or body
// after the dialog is closed
elCallee.focus();
}
} | [
"function",
"(",
")",
"{",
"var",
"transitionDone",
",",
"self",
"=",
"this",
";",
"// remove reference from queue",
"queue",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"// if items remaining in the queue",
"if",
"(",
"queue",
".",
"length",
">",
"0",
")",
"this",
".",
"setup",
"(",
"true",
")",
";",
"else",
"{",
"isopen",
"=",
"false",
";",
"// Hide the dialog box after transition",
"// This ensure it doens't block any element from being clicked",
"transitionDone",
"=",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"elDialog",
".",
"className",
"+=",
"\" alertify-isHidden\"",
";",
"// unbind event so function only gets called once",
"self",
".",
"unbind",
"(",
"elDialog",
",",
"self",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"}",
";",
"// whether CSS transition exists",
"if",
"(",
"this",
".",
"transition",
".",
"supported",
")",
"{",
"this",
".",
"bind",
"(",
"elDialog",
",",
"this",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"elDialog",
".",
"className",
"=",
"\"alertify alertify-hide alertify-hidden\"",
";",
"}",
"else",
"{",
"elDialog",
".",
"className",
"=",
"\"alertify alertify-hide alertify-hidden alertify-isHidden\"",
";",
"}",
"elCover",
".",
"className",
"=",
"\"alertify-cover alertify-cover-hidden\"",
";",
"// set focus to the last element or body",
"// after the dialog is closed",
"elCallee",
".",
"focus",
"(",
")",
";",
"}",
"}"
] | Hide the dialog and rest to defaults
@return {undefined} | [
"Hide",
"the",
"dialog",
"and",
"rest",
"to",
"defaults"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L398-L427 |
|
55,775 | shinuza/captain-admin | public/js/lib/alertify.js | function () {
// ensure legacy browsers support html5 tags
document.createElement("nav");
document.createElement("article");
document.createElement("section");
// cover
elCover = document.createElement("div");
elCover.setAttribute("id", "alertify-cover");
elCover.className = "alertify-cover alertify-cover-hidden";
document.body.appendChild(elCover);
// main element
elDialog = document.createElement("section");
elDialog.setAttribute("id", "alertify");
elDialog.className = "alertify alertify-hidden";
document.body.appendChild(elDialog);
// log element
elLog = document.createElement("section");
elLog.setAttribute("id", "alertify-logs");
elLog.className = "alertify-logs alertify-logs-hidden";
document.body.appendChild(elLog);
// set tabindex attribute on body element
// this allows script to give it focus
// after the dialog is closed
document.body.setAttribute("tabindex", "0");
// set transition type
this.transition = getTransitionEvent();
// clean up init method
delete this.init;
} | javascript | function () {
// ensure legacy browsers support html5 tags
document.createElement("nav");
document.createElement("article");
document.createElement("section");
// cover
elCover = document.createElement("div");
elCover.setAttribute("id", "alertify-cover");
elCover.className = "alertify-cover alertify-cover-hidden";
document.body.appendChild(elCover);
// main element
elDialog = document.createElement("section");
elDialog.setAttribute("id", "alertify");
elDialog.className = "alertify alertify-hidden";
document.body.appendChild(elDialog);
// log element
elLog = document.createElement("section");
elLog.setAttribute("id", "alertify-logs");
elLog.className = "alertify-logs alertify-logs-hidden";
document.body.appendChild(elLog);
// set tabindex attribute on body element
// this allows script to give it focus
// after the dialog is closed
document.body.setAttribute("tabindex", "0");
// set transition type
this.transition = getTransitionEvent();
// clean up init method
delete this.init;
} | [
"function",
"(",
")",
"{",
"// ensure legacy browsers support html5 tags",
"document",
".",
"createElement",
"(",
"\"nav\"",
")",
";",
"document",
".",
"createElement",
"(",
"\"article\"",
")",
";",
"document",
".",
"createElement",
"(",
"\"section\"",
")",
";",
"// cover",
"elCover",
"=",
"document",
".",
"createElement",
"(",
"\"div\"",
")",
";",
"elCover",
".",
"setAttribute",
"(",
"\"id\"",
",",
"\"alertify-cover\"",
")",
";",
"elCover",
".",
"className",
"=",
"\"alertify-cover alertify-cover-hidden\"",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"elCover",
")",
";",
"// main element",
"elDialog",
"=",
"document",
".",
"createElement",
"(",
"\"section\"",
")",
";",
"elDialog",
".",
"setAttribute",
"(",
"\"id\"",
",",
"\"alertify\"",
")",
";",
"elDialog",
".",
"className",
"=",
"\"alertify alertify-hidden\"",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"elDialog",
")",
";",
"// log element",
"elLog",
"=",
"document",
".",
"createElement",
"(",
"\"section\"",
")",
";",
"elLog",
".",
"setAttribute",
"(",
"\"id\"",
",",
"\"alertify-logs\"",
")",
";",
"elLog",
".",
"className",
"=",
"\"alertify-logs alertify-logs-hidden\"",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"elLog",
")",
";",
"// set tabindex attribute on body element",
"// this allows script to give it focus",
"// after the dialog is closed",
"document",
".",
"body",
".",
"setAttribute",
"(",
"\"tabindex\"",
",",
"\"0\"",
")",
";",
"// set transition type",
"this",
".",
"transition",
"=",
"getTransitionEvent",
"(",
")",
";",
"// clean up init method",
"delete",
"this",
".",
"init",
";",
"}"
] | Initialize Alertify
Create the 2 main elements
@return {undefined} | [
"Initialize",
"Alertify",
"Create",
"the",
"2",
"main",
"elements"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L435-L463 |
|
55,776 | shinuza/captain-admin | public/js/lib/alertify.js | function (message, type, wait) {
// check to ensure the alertify dialog element
// has been successfully created
var check = function () {
if (elLog && elLog.scrollTop !== null) return;
else check();
};
// initialize alertify if it hasn't already been done
if (typeof this.init === "function") {
this.init();
check();
}
elLog.className = "alertify-logs";
this.notify(message, type, wait);
return this;
} | javascript | function (message, type, wait) {
// check to ensure the alertify dialog element
// has been successfully created
var check = function () {
if (elLog && elLog.scrollTop !== null) return;
else check();
};
// initialize alertify if it hasn't already been done
if (typeof this.init === "function") {
this.init();
check();
}
elLog.className = "alertify-logs";
this.notify(message, type, wait);
return this;
} | [
"function",
"(",
"message",
",",
"type",
",",
"wait",
")",
"{",
"// check to ensure the alertify dialog element",
"// has been successfully created",
"var",
"check",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"elLog",
"&&",
"elLog",
".",
"scrollTop",
"!==",
"null",
")",
"return",
";",
"else",
"check",
"(",
")",
";",
"}",
";",
"// initialize alertify if it hasn't already been done",
"if",
"(",
"typeof",
"this",
".",
"init",
"===",
"\"function\"",
")",
"{",
"this",
".",
"init",
"(",
")",
";",
"check",
"(",
")",
";",
"}",
"elLog",
".",
"className",
"=",
"\"alertify-logs\"",
";",
"this",
".",
"notify",
"(",
"message",
",",
"type",
",",
"wait",
")",
";",
"return",
"this",
";",
"}"
] | Show a new log message box
@param {String} message The message passed from the callee
@param {String} type [Optional] Optional type of log message
@param {Number} wait [Optional] Time (in ms) to wait before auto-hiding the log
@return {Object} | [
"Show",
"a",
"new",
"log",
"message",
"box"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L474-L489 |
|
55,777 | shinuza/captain-admin | public/js/lib/alertify.js | function (fromQueue) {
var item = queue[0],
self = this,
transitionDone;
// dialog is open
isopen = true;
// Set button focus after transition
transitionDone = function (event) {
event.stopPropagation();
self.setFocus();
// unbind event so function only gets called once
self.unbind(elDialog, self.transition.type, transitionDone);
};
// whether CSS transition exists
if (this.transition.supported && !fromQueue) {
this.bind(elDialog, this.transition.type, transitionDone);
}
// build the proper dialog HTML
elDialog.innerHTML = this.build(item);
// assign all the common elements
btnReset = $("alertify-resetFocus");
btnOK = $("alertify-ok") || undefined;
btnCancel = $("alertify-cancel") || undefined;
btnFocus = (_alertify.buttonFocus === "cancel") ? btnCancel : ((_alertify.buttonFocus === "none") ? $("alertify-noneFocus") : btnOK),
input = $("alertify-text") || undefined;
form = $("alertify-form") || undefined;
// add placeholder value to the input field
if (typeof item.placeholder === "string" && item.placeholder !== "") input.value = item.placeholder;
if (fromQueue) this.setFocus();
this.addListeners(item.callback);
} | javascript | function (fromQueue) {
var item = queue[0],
self = this,
transitionDone;
// dialog is open
isopen = true;
// Set button focus after transition
transitionDone = function (event) {
event.stopPropagation();
self.setFocus();
// unbind event so function only gets called once
self.unbind(elDialog, self.transition.type, transitionDone);
};
// whether CSS transition exists
if (this.transition.supported && !fromQueue) {
this.bind(elDialog, this.transition.type, transitionDone);
}
// build the proper dialog HTML
elDialog.innerHTML = this.build(item);
// assign all the common elements
btnReset = $("alertify-resetFocus");
btnOK = $("alertify-ok") || undefined;
btnCancel = $("alertify-cancel") || undefined;
btnFocus = (_alertify.buttonFocus === "cancel") ? btnCancel : ((_alertify.buttonFocus === "none") ? $("alertify-noneFocus") : btnOK),
input = $("alertify-text") || undefined;
form = $("alertify-form") || undefined;
// add placeholder value to the input field
if (typeof item.placeholder === "string" && item.placeholder !== "") input.value = item.placeholder;
if (fromQueue) this.setFocus();
this.addListeners(item.callback);
} | [
"function",
"(",
"fromQueue",
")",
"{",
"var",
"item",
"=",
"queue",
"[",
"0",
"]",
",",
"self",
"=",
"this",
",",
"transitionDone",
";",
"// dialog is open",
"isopen",
"=",
"true",
";",
"// Set button focus after transition",
"transitionDone",
"=",
"function",
"(",
"event",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"self",
".",
"setFocus",
"(",
")",
";",
"// unbind event so function only gets called once",
"self",
".",
"unbind",
"(",
"elDialog",
",",
"self",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"}",
";",
"// whether CSS transition exists",
"if",
"(",
"this",
".",
"transition",
".",
"supported",
"&&",
"!",
"fromQueue",
")",
"{",
"this",
".",
"bind",
"(",
"elDialog",
",",
"this",
".",
"transition",
".",
"type",
",",
"transitionDone",
")",
";",
"}",
"// build the proper dialog HTML",
"elDialog",
".",
"innerHTML",
"=",
"this",
".",
"build",
"(",
"item",
")",
";",
"// assign all the common elements",
"btnReset",
"=",
"$",
"(",
"\"alertify-resetFocus\"",
")",
";",
"btnOK",
"=",
"$",
"(",
"\"alertify-ok\"",
")",
"||",
"undefined",
";",
"btnCancel",
"=",
"$",
"(",
"\"alertify-cancel\"",
")",
"||",
"undefined",
";",
"btnFocus",
"=",
"(",
"_alertify",
".",
"buttonFocus",
"===",
"\"cancel\"",
")",
"?",
"btnCancel",
":",
"(",
"(",
"_alertify",
".",
"buttonFocus",
"===",
"\"none\"",
")",
"?",
"$",
"(",
"\"alertify-noneFocus\"",
")",
":",
"btnOK",
")",
",",
"input",
"=",
"$",
"(",
"\"alertify-text\"",
")",
"||",
"undefined",
";",
"form",
"=",
"$",
"(",
"\"alertify-form\"",
")",
"||",
"undefined",
";",
"// add placeholder value to the input field",
"if",
"(",
"typeof",
"item",
".",
"placeholder",
"===",
"\"string\"",
"&&",
"item",
".",
"placeholder",
"!==",
"\"\"",
")",
"input",
".",
"value",
"=",
"item",
".",
"placeholder",
";",
"if",
"(",
"fromQueue",
")",
"this",
".",
"setFocus",
"(",
")",
";",
"this",
".",
"addListeners",
"(",
"item",
".",
"callback",
")",
";",
"}"
] | Initiate all the required pieces for the dialog box
@return {undefined} | [
"Initiate",
"all",
"the",
"required",
"pieces",
"for",
"the",
"dialog",
"box"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L550-L581 |
|
55,778 | shinuza/captain-admin | public/js/lib/alertify.js | function (el, event, fn) {
if (typeof el.removeEventListener === "function") {
el.removeEventListener(event, fn, false);
} else if (el.detachEvent) {
el.detachEvent("on" + event, fn);
}
} | javascript | function (el, event, fn) {
if (typeof el.removeEventListener === "function") {
el.removeEventListener(event, fn, false);
} else if (el.detachEvent) {
el.detachEvent("on" + event, fn);
}
} | [
"function",
"(",
"el",
",",
"event",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"el",
".",
"removeEventListener",
"===",
"\"function\"",
")",
"{",
"el",
".",
"removeEventListener",
"(",
"event",
",",
"fn",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"el",
".",
"detachEvent",
")",
"{",
"el",
".",
"detachEvent",
"(",
"\"on\"",
"+",
"event",
",",
"fn",
")",
";",
"}",
"}"
] | Unbind events to elements
@param {Object} el HTML Object
@param {Event} event Event to detach to element
@param {Function} fn Callback function
@return {undefined} | [
"Unbind",
"events",
"to",
"elements"
] | e63408c5206d22b348580a5e1345f5da1cd1d99f | https://github.com/shinuza/captain-admin/blob/e63408c5206d22b348580a5e1345f5da1cd1d99f/public/js/lib/alertify.js#L592-L598 |
|
55,779 | YusukeHirao/sceg | lib/fn/output.js | output | function output(sourceCode, filePath) {
return new Promise(function (resolve, reject) {
mkdirp(path.dirname(filePath), function (ioErr) {
if (ioErr) {
reject(ioErr);
throw ioErr;
}
fs.writeFile(filePath, sourceCode, function (writeErr) {
if (writeErr) {
reject(writeErr);
throw writeErr;
}
resolve();
});
});
});
} | javascript | function output(sourceCode, filePath) {
return new Promise(function (resolve, reject) {
mkdirp(path.dirname(filePath), function (ioErr) {
if (ioErr) {
reject(ioErr);
throw ioErr;
}
fs.writeFile(filePath, sourceCode, function (writeErr) {
if (writeErr) {
reject(writeErr);
throw writeErr;
}
resolve();
});
});
});
} | [
"function",
"output",
"(",
"sourceCode",
",",
"filePath",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"mkdirp",
"(",
"path",
".",
"dirname",
"(",
"filePath",
")",
",",
"function",
"(",
"ioErr",
")",
"{",
"if",
"(",
"ioErr",
")",
"{",
"reject",
"(",
"ioErr",
")",
";",
"throw",
"ioErr",
";",
"}",
"fs",
".",
"writeFile",
"(",
"filePath",
",",
"sourceCode",
",",
"function",
"(",
"writeErr",
")",
"{",
"if",
"(",
"writeErr",
")",
"{",
"reject",
"(",
"writeErr",
")",
";",
"throw",
"writeErr",
";",
"}",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Output file by source code string
@param sourceCode Source code string
@param filePath Destination path and file name | [
"Output",
"file",
"by",
"source",
"code",
"string"
] | 4cde1e56d48dd3b604cc2ddff36b2e9de3348771 | https://github.com/YusukeHirao/sceg/blob/4cde1e56d48dd3b604cc2ddff36b2e9de3348771/lib/fn/output.js#L13-L29 |
55,780 | amooj/node-xcheck | lib/templates.js | ValueTemplate | function ValueTemplate(type, defaultValue, validator){
this.type = type;
this.defaultValue = defaultValue;
this.validator = validator;
} | javascript | function ValueTemplate(type, defaultValue, validator){
this.type = type;
this.defaultValue = defaultValue;
this.validator = validator;
} | [
"function",
"ValueTemplate",
"(",
"type",
",",
"defaultValue",
",",
"validator",
")",
"{",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"defaultValue",
"=",
"defaultValue",
";",
"this",
".",
"validator",
"=",
"validator",
";",
"}"
] | Creates a ValueTemplate.
@param {string} type - type of the value.
@param {Object|undefined} defaultValue - default value.
@param {Object} [validator] - value validator(reserved, not used yet).
@constructor | [
"Creates",
"a",
"ValueTemplate",
"."
] | 33b2b59f7d81a8e0421a468a405f15a19126bedf | https://github.com/amooj/node-xcheck/blob/33b2b59f7d81a8e0421a468a405f15a19126bedf/lib/templates.js#L15-L19 |
55,781 | amooj/node-xcheck | lib/templates.js | PropertyTemplate | function PropertyTemplate(name, required, nullable, template){
this.name = name;
this.required = required;
this.nullable = nullable;
this.template = template;
} | javascript | function PropertyTemplate(name, required, nullable, template){
this.name = name;
this.required = required;
this.nullable = nullable;
this.template = template;
} | [
"function",
"PropertyTemplate",
"(",
"name",
",",
"required",
",",
"nullable",
",",
"template",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"required",
"=",
"required",
";",
"this",
".",
"nullable",
"=",
"nullable",
";",
"this",
".",
"template",
"=",
"template",
";",
"}"
] | Creates a PropertyTemplate.
@param {object} name - property name.
@param {boolean} required - whether this property is required.
@param {boolean} nullable - whether this property value can be null.
@param {object} template - property value template.
@constructor | [
"Creates",
"a",
"PropertyTemplate",
"."
] | 33b2b59f7d81a8e0421a468a405f15a19126bedf | https://github.com/amooj/node-xcheck/blob/33b2b59f7d81a8e0421a468a405f15a19126bedf/lib/templates.js#L276-L281 |
55,782 | frnd/metalsmith-imagecover | lib/index.js | getByFirstImage | function getByFirstImage(file, attributes) {
var $ = cheerio.load(file.contents.toString()),
img = $('img').first(),
obj = {};
if (img.length) {
_.forEach(attributes, function(attribute) {
obj[attribute] = img.attr(attribute);
});
return obj;
} else {
return undefined;
}
} | javascript | function getByFirstImage(file, attributes) {
var $ = cheerio.load(file.contents.toString()),
img = $('img').first(),
obj = {};
if (img.length) {
_.forEach(attributes, function(attribute) {
obj[attribute] = img.attr(attribute);
});
return obj;
} else {
return undefined;
}
} | [
"function",
"getByFirstImage",
"(",
"file",
",",
"attributes",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"file",
".",
"contents",
".",
"toString",
"(",
")",
")",
",",
"img",
"=",
"$",
"(",
"'img'",
")",
".",
"first",
"(",
")",
",",
"obj",
"=",
"{",
"}",
";",
"if",
"(",
"img",
".",
"length",
")",
"{",
"_",
".",
"forEach",
"(",
"attributes",
",",
"function",
"(",
"attribute",
")",
"{",
"obj",
"[",
"attribute",
"]",
"=",
"img",
".",
"attr",
"(",
"attribute",
")",
";",
"}",
")",
";",
"return",
"obj",
";",
"}",
"else",
"{",
"return",
"undefined",
";",
"}",
"}"
] | retrieve cover from file object by extracting the first image
@param {Object} file file object
@return {Object} cover | [
"retrieve",
"cover",
"from",
"file",
"object",
"by",
"extracting",
"the",
"first",
"image"
] | 7d864004027b01cab2a162bfdc523d9b148c015d | https://github.com/frnd/metalsmith-imagecover/blob/7d864004027b01cab2a162bfdc523d9b148c015d/lib/index.js#L44-L56 |
55,783 | DarkPark/code-proxy | server/wspool.js | function ( name, socket ) {
var self = this;
// check input
if ( name && socket ) {
log('ws', 'init', name, 'connection');
// main data structure
pool[name] = {
socket: socket,
time: +new Date(),
count: 0,
active: true
};
// disable link on close
pool[name].socket.on('close', function () {
self.remove(name);
});
// await for an answer
pool[name].socket.on('message', function ( message ) {
// has link to talk back
if ( pool[name].response ) {
log('ws', 'get', name, message);
pool[name].response.end(message);
}
});
return true;
}
// failure
log('ws', 'init', name, 'fail to connect (wrong name or link)');
return false;
} | javascript | function ( name, socket ) {
var self = this;
// check input
if ( name && socket ) {
log('ws', 'init', name, 'connection');
// main data structure
pool[name] = {
socket: socket,
time: +new Date(),
count: 0,
active: true
};
// disable link on close
pool[name].socket.on('close', function () {
self.remove(name);
});
// await for an answer
pool[name].socket.on('message', function ( message ) {
// has link to talk back
if ( pool[name].response ) {
log('ws', 'get', name, message);
pool[name].response.end(message);
}
});
return true;
}
// failure
log('ws', 'init', name, 'fail to connect (wrong name or link)');
return false;
} | [
"function",
"(",
"name",
",",
"socket",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// check input",
"if",
"(",
"name",
"&&",
"socket",
")",
"{",
"log",
"(",
"'ws'",
",",
"'init'",
",",
"name",
",",
"'connection'",
")",
";",
"// main data structure",
"pool",
"[",
"name",
"]",
"=",
"{",
"socket",
":",
"socket",
",",
"time",
":",
"+",
"new",
"Date",
"(",
")",
",",
"count",
":",
"0",
",",
"active",
":",
"true",
"}",
";",
"// disable link on close",
"pool",
"[",
"name",
"]",
".",
"socket",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"self",
".",
"remove",
"(",
"name",
")",
";",
"}",
")",
";",
"// await for an answer",
"pool",
"[",
"name",
"]",
".",
"socket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"message",
")",
"{",
"// has link to talk back",
"if",
"(",
"pool",
"[",
"name",
"]",
".",
"response",
")",
"{",
"log",
"(",
"'ws'",
",",
"'get'",
",",
"name",
",",
"message",
")",
";",
"pool",
"[",
"name",
"]",
".",
"response",
".",
"end",
"(",
"message",
")",
";",
"}",
"}",
")",
";",
"return",
"true",
";",
"}",
"// failure",
"log",
"(",
"'ws'",
",",
"'init'",
",",
"name",
",",
"'fail to connect (wrong name or link)'",
")",
";",
"return",
"false",
";",
"}"
] | New WebSocket creation.
@param {String} name unique identifier for session
@param {Object} socket websocket resource
@return {Boolean} true if was deleted successfully | [
"New",
"WebSocket",
"creation",
"."
] | d281c796706e26269bac99c92d5aca7884e68e19 | https://github.com/DarkPark/code-proxy/blob/d281c796706e26269bac99c92d5aca7884e68e19/server/wspool.js#L25-L59 |
|
55,784 | DarkPark/code-proxy | server/wspool.js | function ( name ) {
// valid connection
if ( name in pool ) {
log('ws', 'exit', name, 'close');
return delete pool[name];
}
// failure
log('ws', 'del', name, 'fail to remove (invalid connection)');
return false;
} | javascript | function ( name ) {
// valid connection
if ( name in pool ) {
log('ws', 'exit', name, 'close');
return delete pool[name];
}
// failure
log('ws', 'del', name, 'fail to remove (invalid connection)');
return false;
} | [
"function",
"(",
"name",
")",
"{",
"// valid connection",
"if",
"(",
"name",
"in",
"pool",
")",
"{",
"log",
"(",
"'ws'",
",",
"'exit'",
",",
"name",
",",
"'close'",
")",
";",
"return",
"delete",
"pool",
"[",
"name",
"]",
";",
"}",
"// failure",
"log",
"(",
"'ws'",
",",
"'del'",
",",
"name",
",",
"'fail to remove (invalid connection)'",
")",
";",
"return",
"false",
";",
"}"
] | Clear resources on WebSocket deletion.
@param {String} name session name
@return {Boolean} true if was deleted successfully | [
"Clear",
"resources",
"on",
"WebSocket",
"deletion",
"."
] | d281c796706e26269bac99c92d5aca7884e68e19 | https://github.com/DarkPark/code-proxy/blob/d281c796706e26269bac99c92d5aca7884e68e19/server/wspool.js#L67-L77 |
|
55,785 | DarkPark/code-proxy | server/wspool.js | function ( name ) {
// valid connection
if ( name in pool ) {
return {
active: pool[name].active,
count: pool[name].count
};
}
// failure
return {active: false};
} | javascript | function ( name ) {
// valid connection
if ( name in pool ) {
return {
active: pool[name].active,
count: pool[name].count
};
}
// failure
return {active: false};
} | [
"function",
"(",
"name",
")",
"{",
"// valid connection",
"if",
"(",
"name",
"in",
"pool",
")",
"{",
"return",
"{",
"active",
":",
"pool",
"[",
"name",
"]",
".",
"active",
",",
"count",
":",
"pool",
"[",
"name",
"]",
".",
"count",
"}",
";",
"}",
"// failure",
"return",
"{",
"active",
":",
"false",
"}",
";",
"}"
] | Detailed information of the named WebSocket instance.
@param {String} name session name
@return {{active:Boolean, count:Number}|{active:Boolean}} info | [
"Detailed",
"information",
"of",
"the",
"named",
"WebSocket",
"instance",
"."
] | d281c796706e26269bac99c92d5aca7884e68e19 | https://github.com/DarkPark/code-proxy/blob/d281c796706e26269bac99c92d5aca7884e68e19/server/wspool.js#L86-L97 |
|
55,786 | DarkPark/code-proxy | server/wspool.js | function ( name, data, response ) {
log('ws', 'send', name, data);
// store link to talk back when ready
pool[name].response = response;
// actual post
pool[name].socket.send(data);
pool[name].count++;
} | javascript | function ( name, data, response ) {
log('ws', 'send', name, data);
// store link to talk back when ready
pool[name].response = response;
// actual post
pool[name].socket.send(data);
pool[name].count++;
} | [
"function",
"(",
"name",
",",
"data",
",",
"response",
")",
"{",
"log",
"(",
"'ws'",
",",
"'send'",
",",
"name",
",",
"data",
")",
";",
"// store link to talk back when ready",
"pool",
"[",
"name",
"]",
".",
"response",
"=",
"response",
";",
"// actual post",
"pool",
"[",
"name",
"]",
".",
"socket",
".",
"send",
"(",
"data",
")",
";",
"pool",
"[",
"name",
"]",
".",
"count",
"++",
";",
"}"
] | Forward the request to the given session.
@param {String} name session name
@param {String} data post data from guest to host
@param {ServerResponse} response link to HTTP response object to send back data | [
"Forward",
"the",
"request",
"to",
"the",
"given",
"session",
"."
] | d281c796706e26269bac99c92d5aca7884e68e19 | https://github.com/DarkPark/code-proxy/blob/d281c796706e26269bac99c92d5aca7884e68e19/server/wspool.js#L106-L113 |
|
55,787 | conoremclaughlin/bones-boiler | server/backbone.js | function(req, res) {
if (res.locals.success) {
options.success(model, response);
} else {
options.error(model, response);
}
} | javascript | function(req, res) {
if (res.locals.success) {
options.success(model, response);
} else {
options.error(model, response);
}
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"res",
".",
"locals",
".",
"success",
")",
"{",
"options",
".",
"success",
"(",
"model",
",",
"response",
")",
";",
"}",
"else",
"{",
"options",
".",
"error",
"(",
"model",
",",
"response",
")",
";",
"}",
"}"
] | Create a route handler wrapper to call success or error. | [
"Create",
"a",
"route",
"handler",
"wrapper",
"to",
"call",
"success",
"or",
"error",
"."
] | 65e8ce58da75f0f3235342ba3c42084ded0ea450 | https://github.com/conoremclaughlin/bones-boiler/blob/65e8ce58da75f0f3235342ba3c42084ded0ea450/server/backbone.js#L22-L28 |
|
55,788 | epferrari/immutable-state | index.js | function(s){
var currentState = history[historyIndex];
if(typeof s === 'function'){
s = s( history[historyIndex].toJS() );
}
var newState = currentState.merge(s);
history = history.slice(0,historyIndex + 1);
history.push(newState);
historyIndex++;
return new Immutable.Map(history[historyIndex]).toJS();
} | javascript | function(s){
var currentState = history[historyIndex];
if(typeof s === 'function'){
s = s( history[historyIndex].toJS() );
}
var newState = currentState.merge(s);
history = history.slice(0,historyIndex + 1);
history.push(newState);
historyIndex++;
return new Immutable.Map(history[historyIndex]).toJS();
} | [
"function",
"(",
"s",
")",
"{",
"var",
"currentState",
"=",
"history",
"[",
"historyIndex",
"]",
";",
"if",
"(",
"typeof",
"s",
"===",
"'function'",
")",
"{",
"s",
"=",
"s",
"(",
"history",
"[",
"historyIndex",
"]",
".",
"toJS",
"(",
")",
")",
";",
"}",
"var",
"newState",
"=",
"currentState",
".",
"merge",
"(",
"s",
")",
";",
"history",
"=",
"history",
".",
"slice",
"(",
"0",
",",
"historyIndex",
"+",
"1",
")",
";",
"history",
".",
"push",
"(",
"newState",
")",
";",
"historyIndex",
"++",
";",
"return",
"new",
"Immutable",
".",
"Map",
"(",
"history",
"[",
"historyIndex",
"]",
")",
".",
"toJS",
"(",
")",
";",
"}"
] | ensure that setting state via assignment performs an immutable operation | [
"ensure",
"that",
"setting",
"state",
"via",
"assignment",
"performs",
"an",
"immutable",
"operation"
] | fe510a17f2f809032a6c8a9eb2e523b60d9f0e48 | https://github.com/epferrari/immutable-state/blob/fe510a17f2f809032a6c8a9eb2e523b60d9f0e48/index.js#L24-L35 |
|
55,789 | kmalakoff/backbone-articulation | vendor/optional/backbone-relational-0.4.0.js | function( name ) {
var type = _.reduce( name.split('.'), function( memo, val ) {
return memo[ val ];
}, exports);
return type !== exports ? type: null;
} | javascript | function( name ) {
var type = _.reduce( name.split('.'), function( memo, val ) {
return memo[ val ];
}, exports);
return type !== exports ? type: null;
} | [
"function",
"(",
"name",
")",
"{",
"var",
"type",
"=",
"_",
".",
"reduce",
"(",
"name",
".",
"split",
"(",
"'.'",
")",
",",
"function",
"(",
"memo",
",",
"val",
")",
"{",
"return",
"memo",
"[",
"val",
"]",
";",
"}",
",",
"exports",
")",
";",
"return",
"type",
"!==",
"exports",
"?",
"type",
":",
"null",
";",
"}"
] | Find a type on the global object by name. Splits name on dots.
@param {string} name | [
"Find",
"a",
"type",
"on",
"the",
"global",
"object",
"by",
"name",
".",
"Splits",
"name",
"on",
"dots",
"."
] | ce093551bab078369b5f9f4244873d108a344eb5 | https://github.com/kmalakoff/backbone-articulation/blob/ce093551bab078369b5f9f4244873d108a344eb5/vendor/optional/backbone-relational-0.4.0.js#L179-L184 |
|
55,790 | kmalakoff/backbone-articulation | vendor/optional/backbone-relational-0.4.0.js | function( model ) {
var coll = this.getCollection( model );
coll._onModelEvent( 'change:' + model.idAttribute, model, coll );
} | javascript | function( model ) {
var coll = this.getCollection( model );
coll._onModelEvent( 'change:' + model.idAttribute, model, coll );
} | [
"function",
"(",
"model",
")",
"{",
"var",
"coll",
"=",
"this",
".",
"getCollection",
"(",
"model",
")",
";",
"coll",
".",
"_onModelEvent",
"(",
"'change:'",
"+",
"model",
".",
"idAttribute",
",",
"model",
",",
"coll",
")",
";",
"}"
] | Explicitly update a model's id in it's store collection | [
"Explicitly",
"update",
"a",
"model",
"s",
"id",
"in",
"it",
"s",
"store",
"collection"
] | ce093551bab078369b5f9f4244873d108a344eb5 | https://github.com/kmalakoff/backbone-articulation/blob/ce093551bab078369b5f9f4244873d108a344eb5/vendor/optional/backbone-relational-0.4.0.js#L223-L226 |
|
55,791 | kmalakoff/backbone-articulation | vendor/optional/backbone-relational-0.4.0.js | function() {
Backbone.Relational.store.getCollection( this.instance )
.unbind( 'relational:remove', this._modelRemovedFromCollection );
Backbone.Relational.store.getCollection( this.relatedModel )
.unbind( 'relational:add', this._relatedModelAdded )
.unbind( 'relational:remove', this._relatedModelRemoved );
_.each( this.getReverseRelations(), function( relation ) {
relation.removeRelated( this.instance );
}, this );
} | javascript | function() {
Backbone.Relational.store.getCollection( this.instance )
.unbind( 'relational:remove', this._modelRemovedFromCollection );
Backbone.Relational.store.getCollection( this.relatedModel )
.unbind( 'relational:add', this._relatedModelAdded )
.unbind( 'relational:remove', this._relatedModelRemoved );
_.each( this.getReverseRelations(), function( relation ) {
relation.removeRelated( this.instance );
}, this );
} | [
"function",
"(",
")",
"{",
"Backbone",
".",
"Relational",
".",
"store",
".",
"getCollection",
"(",
"this",
".",
"instance",
")",
".",
"unbind",
"(",
"'relational:remove'",
",",
"this",
".",
"_modelRemovedFromCollection",
")",
";",
"Backbone",
".",
"Relational",
".",
"store",
".",
"getCollection",
"(",
"this",
".",
"relatedModel",
")",
".",
"unbind",
"(",
"'relational:add'",
",",
"this",
".",
"_relatedModelAdded",
")",
".",
"unbind",
"(",
"'relational:remove'",
",",
"this",
".",
"_relatedModelRemoved",
")",
";",
"_",
".",
"each",
"(",
"this",
".",
"getReverseRelations",
"(",
")",
",",
"function",
"(",
"relation",
")",
"{",
"relation",
".",
"removeRelated",
"(",
"this",
".",
"instance",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Cleanup. Get reverse relation, call removeRelated on each. | [
"Cleanup",
".",
"Get",
"reverse",
"relation",
"call",
"removeRelated",
"on",
"each",
"."
] | ce093551bab078369b5f9f4244873d108a344eb5 | https://github.com/kmalakoff/backbone-articulation/blob/ce093551bab078369b5f9f4244873d108a344eb5/vendor/optional/backbone-relational-0.4.0.js#L441-L452 |
|
55,792 | campsi/campsi-service-auth | lib/passportMiddleware.js | proxyVerifyCallback | function proxyVerifyCallback (fn, args, done) {
const {callback, index} = findCallback(args);
args[index] = function (err, user) {
done(err, user, callback);
};
fn.apply(null, args);
} | javascript | function proxyVerifyCallback (fn, args, done) {
const {callback, index} = findCallback(args);
args[index] = function (err, user) {
done(err, user, callback);
};
fn.apply(null, args);
} | [
"function",
"proxyVerifyCallback",
"(",
"fn",
",",
"args",
",",
"done",
")",
"{",
"const",
"{",
"callback",
",",
"index",
"}",
"=",
"findCallback",
"(",
"args",
")",
";",
"args",
"[",
"index",
"]",
"=",
"function",
"(",
"err",
",",
"user",
")",
"{",
"done",
"(",
"err",
",",
"user",
",",
"callback",
")",
";",
"}",
";",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}"
] | Intercepts passport callback
@param fn
@param args
@param done | [
"Intercepts",
"passport",
"callback"
] | f877626496de2288f9cfb50024accca2a88e179d | https://github.com/campsi/campsi-service-auth/blob/f877626496de2288f9cfb50024accca2a88e179d/lib/passportMiddleware.js#L10-L16 |
55,793 | IonicaBizau/set-or-get.js | lib/index.js | SetOrGet | function SetOrGet(input, field, def) {
return input[field] = Deffy(input[field], def);
} | javascript | function SetOrGet(input, field, def) {
return input[field] = Deffy(input[field], def);
} | [
"function",
"SetOrGet",
"(",
"input",
",",
"field",
",",
"def",
")",
"{",
"return",
"input",
"[",
"field",
"]",
"=",
"Deffy",
"(",
"input",
"[",
"field",
"]",
",",
"def",
")",
";",
"}"
] | SetOrGet
Sets or gets an object field value.
@name SetOrGet
@function
@param {Object|Array} input The cache/input object.
@param {String|Number} field The field you want to update/create.
@param {Object|Array} def The default value.
@return {Object|Array} The field value. | [
"SetOrGet",
"Sets",
"or",
"gets",
"an",
"object",
"field",
"value",
"."
] | 65baa42d1188dff894a2497b4cad25bb36a757fa | https://github.com/IonicaBizau/set-or-get.js/blob/65baa42d1188dff894a2497b4cad25bb36a757fa/lib/index.js#L15-L17 |
55,794 | kemitchell/tcp-log-client.js | index.js | proxyEvent | function proxyEvent (emitter, event, optionalCallback) {
emitter.on(event, function () {
if (optionalCallback) {
optionalCallback.apply(client, arguments)
}
client.emit(event)
})
} | javascript | function proxyEvent (emitter, event, optionalCallback) {
emitter.on(event, function () {
if (optionalCallback) {
optionalCallback.apply(client, arguments)
}
client.emit(event)
})
} | [
"function",
"proxyEvent",
"(",
"emitter",
",",
"event",
",",
"optionalCallback",
")",
"{",
"emitter",
".",
"on",
"(",
"event",
",",
"function",
"(",
")",
"{",
"if",
"(",
"optionalCallback",
")",
"{",
"optionalCallback",
".",
"apply",
"(",
"client",
",",
"arguments",
")",
"}",
"client",
".",
"emit",
"(",
"event",
")",
"}",
")",
"}"
] | Emit events from a stream the client manages as the client's own. | [
"Emit",
"events",
"from",
"a",
"stream",
"the",
"client",
"manages",
"as",
"the",
"client",
"s",
"own",
"."
] | bce29ef06c9306db269a6f3e0de83c48def16654 | https://github.com/kemitchell/tcp-log-client.js/blob/bce29ef06c9306db269a6f3e0de83c48def16654/index.js#L109-L116 |
55,795 | conoremclaughlin/bones-boiler | servers/Middleware.bones.js | function(parent, app) {
this.use(middleware.sanitizeHost(app));
this.use(middleware.bodyParser());
this.use(middleware.cookieParser());
this.use(middleware.fragmentRedirect());
} | javascript | function(parent, app) {
this.use(middleware.sanitizeHost(app));
this.use(middleware.bodyParser());
this.use(middleware.cookieParser());
this.use(middleware.fragmentRedirect());
} | [
"function",
"(",
"parent",
",",
"app",
")",
"{",
"this",
".",
"use",
"(",
"middleware",
".",
"sanitizeHost",
"(",
"app",
")",
")",
";",
"this",
".",
"use",
"(",
"middleware",
".",
"bodyParser",
"(",
")",
")",
";",
"this",
".",
"use",
"(",
"middleware",
".",
"cookieParser",
"(",
")",
")",
";",
"this",
".",
"use",
"(",
"middleware",
".",
"fragmentRedirect",
"(",
")",
")",
";",
"}"
] | Removing validateCSRFToken to replace with connect's csrf middleware.
Double CSRF protection makes dealing with static forms difficult by default. | [
"Removing",
"validateCSRFToken",
"to",
"replace",
"with",
"connect",
"s",
"csrf",
"middleware",
".",
"Double",
"CSRF",
"protection",
"makes",
"dealing",
"with",
"static",
"forms",
"difficult",
"by",
"default",
"."
] | 65e8ce58da75f0f3235342ba3c42084ded0ea450 | https://github.com/conoremclaughlin/bones-boiler/blob/65e8ce58da75f0f3235342ba3c42084ded0ea450/servers/Middleware.bones.js#L9-L14 |
|
55,796 | skira-project/core | src/scope.js | Scope | function Scope(site, page, params) {
this.site = site
this.page = page
this.params = params || {}
this.status = 200
this._headers = {}
this.locale = site.locales.default
// Set default headers.
this.header("Content-Type", "text/html; charset=utf-8")
this.header("Connection", "close")
this.header("Server", "Skira")
} | javascript | function Scope(site, page, params) {
this.site = site
this.page = page
this.params = params || {}
this.status = 200
this._headers = {}
this.locale = site.locales.default
// Set default headers.
this.header("Content-Type", "text/html; charset=utf-8")
this.header("Connection", "close")
this.header("Server", "Skira")
} | [
"function",
"Scope",
"(",
"site",
",",
"page",
",",
"params",
")",
"{",
"this",
".",
"site",
"=",
"site",
"this",
".",
"page",
"=",
"page",
"this",
".",
"params",
"=",
"params",
"||",
"{",
"}",
"this",
".",
"status",
"=",
"200",
"this",
".",
"_headers",
"=",
"{",
"}",
"this",
".",
"locale",
"=",
"site",
".",
"locales",
".",
"default",
"// Set default headers.",
"this",
".",
"header",
"(",
"\"Content-Type\"",
",",
"\"text/html; charset=utf-8\"",
")",
"this",
".",
"header",
"(",
"\"Connection\"",
",",
"\"close\"",
")",
"this",
".",
"header",
"(",
"\"Server\"",
",",
"\"Skira\"",
")",
"}"
] | The state object are all variables made available to views and modules.
@param {object} site - global Skira site
@param {object} page - resolved page
@param {object} params - params parsed by the router | [
"The",
"state",
"object",
"are",
"all",
"variables",
"made",
"available",
"to",
"views",
"and",
"modules",
"."
] | 41f93199acad0118aa3d86cc15b3afea67bf2085 | https://github.com/skira-project/core/blob/41f93199acad0118aa3d86cc15b3afea67bf2085/src/scope.js#L8-L20 |
55,797 | OpenCrisp/Crisp.EventJS | dist/crisp-event.js | function( option ) {
if ( this._self === option.exporter ) {
return;
}
if ( this._action && !this._action.test( option.action ) ) {
return;
}
if ( this._path && !this._path.test( option.path ) ) {
return;
}
if ( this._notePath || this._noteAction ) {
if ( !(option instanceof EventPicker) || option.Test( this ) ) {
return;
}
}
utilTick( this._self, this._listen, option, this._async );
} | javascript | function( option ) {
if ( this._self === option.exporter ) {
return;
}
if ( this._action && !this._action.test( option.action ) ) {
return;
}
if ( this._path && !this._path.test( option.path ) ) {
return;
}
if ( this._notePath || this._noteAction ) {
if ( !(option instanceof EventPicker) || option.Test( this ) ) {
return;
}
}
utilTick( this._self, this._listen, option, this._async );
} | [
"function",
"(",
"option",
")",
"{",
"if",
"(",
"this",
".",
"_self",
"===",
"option",
".",
"exporter",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_action",
"&&",
"!",
"this",
".",
"_action",
".",
"test",
"(",
"option",
".",
"action",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_path",
"&&",
"!",
"this",
".",
"_path",
".",
"test",
"(",
"option",
".",
"path",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_notePath",
"||",
"this",
".",
"_noteAction",
")",
"{",
"if",
"(",
"!",
"(",
"option",
"instanceof",
"EventPicker",
")",
"||",
"option",
".",
"Test",
"(",
"this",
")",
")",
"{",
"return",
";",
"}",
"}",
"utilTick",
"(",
"this",
".",
"_self",
",",
"this",
".",
"_listen",
",",
"option",
",",
"this",
".",
"_async",
")",
";",
"}"
] | execute event list
@param {external:Object} option | [
"execute",
"event",
"list"
] | f9e29899a65cf8a8ab7ba1c04a5f591a64e12059 | https://github.com/OpenCrisp/Crisp.EventJS/blob/f9e29899a65cf8a8ab7ba1c04a5f591a64e12059/dist/crisp-event.js#L415-L437 |
|
55,798 | independentgeorge/glupost | index.js | glupost | function glupost(configuration) {
const tasks = configuration.tasks || {}
const template = configuration.template || {}
// Expand template object with defaults.
expand(template, { transforms: [], dest: "." })
// Create tasks.
const names = Object.keys(tasks)
for (const name of names) {
const task = retrieve(tasks, name)
if (typeof task === "object")
expand(task, template)
gulp.task(name, compose(task))
}
watch(tasks)
} | javascript | function glupost(configuration) {
const tasks = configuration.tasks || {}
const template = configuration.template || {}
// Expand template object with defaults.
expand(template, { transforms: [], dest: "." })
// Create tasks.
const names = Object.keys(tasks)
for (const name of names) {
const task = retrieve(tasks, name)
if (typeof task === "object")
expand(task, template)
gulp.task(name, compose(task))
}
watch(tasks)
} | [
"function",
"glupost",
"(",
"configuration",
")",
"{",
"const",
"tasks",
"=",
"configuration",
".",
"tasks",
"||",
"{",
"}",
"const",
"template",
"=",
"configuration",
".",
"template",
"||",
"{",
"}",
"// Expand template object with defaults.",
"expand",
"(",
"template",
",",
"{",
"transforms",
":",
"[",
"]",
",",
"dest",
":",
"\".\"",
"}",
")",
"// Create tasks.",
"const",
"names",
"=",
"Object",
".",
"keys",
"(",
"tasks",
")",
"for",
"(",
"const",
"name",
"of",
"names",
")",
"{",
"const",
"task",
"=",
"retrieve",
"(",
"tasks",
",",
"name",
")",
"if",
"(",
"typeof",
"task",
"===",
"\"object\"",
")",
"expand",
"(",
"task",
",",
"template",
")",
"gulp",
".",
"task",
"(",
"name",
",",
"compose",
"(",
"task",
")",
")",
"}",
"watch",
"(",
"tasks",
")",
"}"
] | Create gulp tasks. | [
"Create",
"gulp",
"tasks",
"."
] | 3a66d6d460d8e63552cecf28c32dfabe98fbd689 | https://github.com/independentgeorge/glupost/blob/3a66d6d460d8e63552cecf28c32dfabe98fbd689/index.js#L40-L62 |
55,799 | independentgeorge/glupost | index.js | compose | function compose(task) {
// Already composed action.
if (task.action)
return task.action
// 1. named task.
if (typeof task === "string")
return task
// 2. a function directly.
if (typeof task === "function")
return task.length ? task : () => Promise.resolve(task())
// 3. task object.
if (typeof task !== "object")
throw new Error("A task must be a string, function, or object.")
if (task.watch === true) {
// Watching task without a valid path.
if (!task.src)
throw new Error("No path given to watch.")
task.watch = task.src
}
let transform
if (task.src)
transform = () => pipify(task)
// No transform function and no series/parallel.
if (!transform && !task.series && !task.parallel)
throw new Error("A task must do something.")
// Both series and parallel.
if (task.series && task.parallel)
throw new Error("A task can't have both .series and .parallel properties.")
// Only transform function.
if (!task.series && !task.parallel) {
task.action = transform
}
// Series/parallel sequence of tasks.
else {
const sequence = task.series ? "series" : "parallel"
if (transform)
task[sequence].push(transform)
task.action = gulp[sequence](...task[sequence].map(compose))
}
return task.action
} | javascript | function compose(task) {
// Already composed action.
if (task.action)
return task.action
// 1. named task.
if (typeof task === "string")
return task
// 2. a function directly.
if (typeof task === "function")
return task.length ? task : () => Promise.resolve(task())
// 3. task object.
if (typeof task !== "object")
throw new Error("A task must be a string, function, or object.")
if (task.watch === true) {
// Watching task without a valid path.
if (!task.src)
throw new Error("No path given to watch.")
task.watch = task.src
}
let transform
if (task.src)
transform = () => pipify(task)
// No transform function and no series/parallel.
if (!transform && !task.series && !task.parallel)
throw new Error("A task must do something.")
// Both series and parallel.
if (task.series && task.parallel)
throw new Error("A task can't have both .series and .parallel properties.")
// Only transform function.
if (!task.series && !task.parallel) {
task.action = transform
}
// Series/parallel sequence of tasks.
else {
const sequence = task.series ? "series" : "parallel"
if (transform)
task[sequence].push(transform)
task.action = gulp[sequence](...task[sequence].map(compose))
}
return task.action
} | [
"function",
"compose",
"(",
"task",
")",
"{",
"// Already composed action.",
"if",
"(",
"task",
".",
"action",
")",
"return",
"task",
".",
"action",
"// 1. named task.",
"if",
"(",
"typeof",
"task",
"===",
"\"string\"",
")",
"return",
"task",
"// 2. a function directly.",
"if",
"(",
"typeof",
"task",
"===",
"\"function\"",
")",
"return",
"task",
".",
"length",
"?",
"task",
":",
"(",
")",
"=>",
"Promise",
".",
"resolve",
"(",
"task",
"(",
")",
")",
"// 3. task object.",
"if",
"(",
"typeof",
"task",
"!==",
"\"object\"",
")",
"throw",
"new",
"Error",
"(",
"\"A task must be a string, function, or object.\"",
")",
"if",
"(",
"task",
".",
"watch",
"===",
"true",
")",
"{",
"// Watching task without a valid path.",
"if",
"(",
"!",
"task",
".",
"src",
")",
"throw",
"new",
"Error",
"(",
"\"No path given to watch.\"",
")",
"task",
".",
"watch",
"=",
"task",
".",
"src",
"}",
"let",
"transform",
"if",
"(",
"task",
".",
"src",
")",
"transform",
"=",
"(",
")",
"=>",
"pipify",
"(",
"task",
")",
"// No transform function and no series/parallel.",
"if",
"(",
"!",
"transform",
"&&",
"!",
"task",
".",
"series",
"&&",
"!",
"task",
".",
"parallel",
")",
"throw",
"new",
"Error",
"(",
"\"A task must do something.\"",
")",
"// Both series and parallel.",
"if",
"(",
"task",
".",
"series",
"&&",
"task",
".",
"parallel",
")",
"throw",
"new",
"Error",
"(",
"\"A task can't have both .series and .parallel properties.\"",
")",
"// Only transform function.",
"if",
"(",
"!",
"task",
".",
"series",
"&&",
"!",
"task",
".",
"parallel",
")",
"{",
"task",
".",
"action",
"=",
"transform",
"}",
"// Series/parallel sequence of tasks.",
"else",
"{",
"const",
"sequence",
"=",
"task",
".",
"series",
"?",
"\"series\"",
":",
"\"parallel\"",
"if",
"(",
"transform",
")",
"task",
"[",
"sequence",
"]",
".",
"push",
"(",
"transform",
")",
"task",
".",
"action",
"=",
"gulp",
"[",
"sequence",
"]",
"(",
"...",
"task",
"[",
"sequence",
"]",
".",
"map",
"(",
"compose",
")",
")",
"}",
"return",
"task",
".",
"action",
"}"
] | Convert task object to a function. | [
"Convert",
"task",
"object",
"to",
"a",
"function",
"."
] | 3a66d6d460d8e63552cecf28c32dfabe98fbd689 | https://github.com/independentgeorge/glupost/blob/3a66d6d460d8e63552cecf28c32dfabe98fbd689/index.js#L66-L120 |
Subsets and Splits