id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
52,100
|
tolokoban/ToloFrameWork
|
lib/boilerplate.view.js
|
outputAll
|
function outputAll( code, moduleName ) {
try {
let out = outputComments( code );
out += " module.exports = function() {\n";
out += outputNeededConstants( code );
out += ` //-------------------
// Class definition.
const ViewClass = function( args ) {
try {
if( typeof args === 'undefined' ) args = {};
this.$elements = {};
${outputClassBody(code)}
}
catch( ex ) {
console.error('${moduleName}', ex);
throw Error('Instantiation error in XJS of ${JSON.stringify(moduleName)}:\\n' + ex)
}
};\n`;
out += generate( code.section.statics, "Static members.", " " );
out += " return ViewClass;\n";
out += " }();\n";
return out;
} catch ( ex ) {
bubble( ex, "outputAll()" );
return null;
}
}
|
javascript
|
function outputAll( code, moduleName ) {
try {
let out = outputComments( code );
out += " module.exports = function() {\n";
out += outputNeededConstants( code );
out += ` //-------------------
// Class definition.
const ViewClass = function( args ) {
try {
if( typeof args === 'undefined' ) args = {};
this.$elements = {};
${outputClassBody(code)}
}
catch( ex ) {
console.error('${moduleName}', ex);
throw Error('Instantiation error in XJS of ${JSON.stringify(moduleName)}:\\n' + ex)
}
};\n`;
out += generate( code.section.statics, "Static members.", " " );
out += " return ViewClass;\n";
out += " }();\n";
return out;
} catch ( ex ) {
bubble( ex, "outputAll()" );
return null;
}
}
|
[
"function",
"outputAll",
"(",
"code",
",",
"moduleName",
")",
"{",
"try",
"{",
"let",
"out",
"=",
"outputComments",
"(",
"code",
")",
";",
"out",
"+=",
"\" module.exports = function() {\\n\"",
";",
"out",
"+=",
"outputNeededConstants",
"(",
"code",
")",
";",
"out",
"+=",
"`",
"${",
"outputClassBody",
"(",
"code",
")",
"}",
"${",
"moduleName",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"moduleName",
")",
"}",
"\\\\",
"\\n",
"`",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"statics",
",",
"\"Static members.\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"\" return ViewClass;\\n\"",
";",
"out",
"+=",
"\" }();\\n\"",
";",
"return",
"out",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"bubble",
"(",
"ex",
",",
"\"outputAll()\"",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
Generate the JS code for the XJS module.
@param {object} code - Helper for Javascript code writing.
@param {string} moduleName - Javascript module name.
@return {string} Resulting JS code.
|
[
"Generate",
"the",
"JS",
"code",
"for",
"the",
"XJS",
"module",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/boilerplate.view.js#L1460-L1486
|
52,101
|
tolokoban/ToloFrameWork
|
lib/boilerplate.view.js
|
outputComments
|
function outputComments( code ) {
try {
let out = '';
if ( code.section.comments.length > 0 ) {
out += ` /**\n * ${code.section.comments.join("\n * ")}\n */\n`;
}
return out;
} catch ( ex ) {
bubble( ex, "outputComments" );
return null;
}
}
|
javascript
|
function outputComments( code ) {
try {
let out = '';
if ( code.section.comments.length > 0 ) {
out += ` /**\n * ${code.section.comments.join("\n * ")}\n */\n`;
}
return out;
} catch ( ex ) {
bubble( ex, "outputComments" );
return null;
}
}
|
[
"function",
"outputComments",
"(",
"code",
")",
"{",
"try",
"{",
"let",
"out",
"=",
"''",
";",
"if",
"(",
"code",
".",
"section",
".",
"comments",
".",
"length",
">",
"0",
")",
"{",
"out",
"+=",
"`",
"\\n",
"${",
"code",
".",
"section",
".",
"comments",
".",
"join",
"(",
"\"\\n * \"",
")",
"}",
"\\n",
"\\n",
"`",
";",
"}",
"return",
"out",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"bubble",
"(",
"ex",
",",
"\"outputComments\"",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
Possible comments.
@param {object} code - See below.
@param {array} code.section.comments - Lines of comments.
@return {string} Resulting JS code.
|
[
"Possible",
"comments",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/boilerplate.view.js#L1496-L1507
|
52,102
|
tolokoban/ToloFrameWork
|
lib/boilerplate.view.js
|
outputNeededConstants
|
function outputNeededConstants( code ) {
try {
let out = arrayToCodeWithNewLine( code.generateRequires(), " " );
out += arrayToCodeWithNewLine( code.generateNeededBehindFunctions(), " " );
out += arrayToCodeWithNewLine( code.generateFunctions(), " " );
out += arrayToCodeWithNewLine( code.generateGlobalVariables(), " " );
return out;
} catch ( ex ) {
bubble( ex, "outputNeededConstants" );
return null;
}
}
|
javascript
|
function outputNeededConstants( code ) {
try {
let out = arrayToCodeWithNewLine( code.generateRequires(), " " );
out += arrayToCodeWithNewLine( code.generateNeededBehindFunctions(), " " );
out += arrayToCodeWithNewLine( code.generateFunctions(), " " );
out += arrayToCodeWithNewLine( code.generateGlobalVariables(), " " );
return out;
} catch ( ex ) {
bubble( ex, "outputNeededConstants" );
return null;
}
}
|
[
"function",
"outputNeededConstants",
"(",
"code",
")",
"{",
"try",
"{",
"let",
"out",
"=",
"arrayToCodeWithNewLine",
"(",
"code",
".",
"generateRequires",
"(",
")",
",",
"\" \"",
")",
";",
"out",
"+=",
"arrayToCodeWithNewLine",
"(",
"code",
".",
"generateNeededBehindFunctions",
"(",
")",
",",
"\" \"",
")",
";",
"out",
"+=",
"arrayToCodeWithNewLine",
"(",
"code",
".",
"generateFunctions",
"(",
")",
",",
"\" \"",
")",
";",
"out",
"+=",
"arrayToCodeWithNewLine",
"(",
"code",
".",
"generateGlobalVariables",
"(",
")",
",",
"\" \"",
")",
";",
"return",
"out",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"bubble",
"(",
"ex",
",",
"\"outputNeededConstants\"",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
Declare requires, converters, global variables, list of needed behind functions, ...
@param {object} code - Helper for Javascript code writing.
@return {string} Resulting JS code.
|
[
"Declare",
"requires",
"converters",
"global",
"variables",
"list",
"of",
"needed",
"behind",
"functions",
"..."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/boilerplate.view.js#L1516-L1527
|
52,103
|
tolokoban/ToloFrameWork
|
lib/boilerplate.view.js
|
outputClassBody
|
function outputClassBody( code ) {
try {
let out = '';
if ( code.that ) out += " const that = this;\n";
if ( code.pm ) out += " const pm = PM(this);\n";
out += generate( code.section.attribs.define, "Create attributes", " " );
out += generate( code.section.elements.define, "Create elements", " " );
out += generate( code.section.events, "Events", " " );
out += arrayToCodeWithNewLine( code.generateLinks(), " " );
out += generate( code.section.ons, "On attribute changed", " " );
out += generate( code.section.elements.init, "Initialize elements", " " );
out += generate( code.section.attribs.init, "Initialize attributes", " " );
if ( code.section.init ) {
out += " // Initialization.\n";
out += ` CODE_BEHIND.${code.section.init}.call( this );\n`;
}
out += " $.addClass(this, 'view', 'custom');\n";
return out;
} catch ( ex ) {
bubble( ex, "outputClassBody" );
return null;
}
}
|
javascript
|
function outputClassBody( code ) {
try {
let out = '';
if ( code.that ) out += " const that = this;\n";
if ( code.pm ) out += " const pm = PM(this);\n";
out += generate( code.section.attribs.define, "Create attributes", " " );
out += generate( code.section.elements.define, "Create elements", " " );
out += generate( code.section.events, "Events", " " );
out += arrayToCodeWithNewLine( code.generateLinks(), " " );
out += generate( code.section.ons, "On attribute changed", " " );
out += generate( code.section.elements.init, "Initialize elements", " " );
out += generate( code.section.attribs.init, "Initialize attributes", " " );
if ( code.section.init ) {
out += " // Initialization.\n";
out += ` CODE_BEHIND.${code.section.init}.call( this );\n`;
}
out += " $.addClass(this, 'view', 'custom');\n";
return out;
} catch ( ex ) {
bubble( ex, "outputClassBody" );
return null;
}
}
|
[
"function",
"outputClassBody",
"(",
"code",
")",
"{",
"try",
"{",
"let",
"out",
"=",
"''",
";",
"if",
"(",
"code",
".",
"that",
")",
"out",
"+=",
"\" const that = this;\\n\"",
";",
"if",
"(",
"code",
".",
"pm",
")",
"out",
"+=",
"\" const pm = PM(this);\\n\"",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"attribs",
".",
"define",
",",
"\"Create attributes\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"elements",
".",
"define",
",",
"\"Create elements\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"events",
",",
"\"Events\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"arrayToCodeWithNewLine",
"(",
"code",
".",
"generateLinks",
"(",
")",
",",
"\" \"",
")",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"ons",
",",
"\"On attribute changed\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"elements",
".",
"init",
",",
"\"Initialize elements\"",
",",
"\" \"",
")",
";",
"out",
"+=",
"generate",
"(",
"code",
".",
"section",
".",
"attribs",
".",
"init",
",",
"\"Initialize attributes\"",
",",
"\" \"",
")",
";",
"if",
"(",
"code",
".",
"section",
".",
"init",
")",
"{",
"out",
"+=",
"\" // Initialization.\\n\"",
";",
"out",
"+=",
"`",
"${",
"code",
".",
"section",
".",
"init",
"}",
"\\n",
"`",
";",
"}",
"out",
"+=",
"\" $.addClass(this, 'view', 'custom');\\n\"",
";",
"return",
"out",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"bubble",
"(",
"ex",
",",
"\"outputClassBody\"",
")",
";",
"return",
"null",
";",
"}",
"}"
] |
Class body.
@param {object} code - Helper for Javascript code writing.
@return {string} Resulting JS code.
|
[
"Class",
"body",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/boilerplate.view.js#L1536-L1558
|
52,104
|
tolokoban/ToloFrameWork
|
lib/boilerplate.view.js
|
bubble
|
function bubble( ex, origin ) {
if ( typeof ex === 'string' ) {
throw Error( `${ex}\n...in ${origin}` );
}
throw Error( `${ex.message}\n...in ${origin}` );
}
|
javascript
|
function bubble( ex, origin ) {
if ( typeof ex === 'string' ) {
throw Error( `${ex}\n...in ${origin}` );
}
throw Error( `${ex.message}\n...in ${origin}` );
}
|
[
"function",
"bubble",
"(",
"ex",
",",
"origin",
")",
"{",
"if",
"(",
"typeof",
"ex",
"===",
"'string'",
")",
"{",
"throw",
"Error",
"(",
"`",
"${",
"ex",
"}",
"\\n",
"${",
"origin",
"}",
"`",
")",
";",
"}",
"throw",
"Error",
"(",
"`",
"${",
"ex",
".",
"message",
"}",
"\\n",
"${",
"origin",
"}",
"`",
")",
";",
"}"
] |
Bubble an exception by providing it's origin.
@param {string|Error} ex - Exception.
@param {string} origin - From where the exception has been thrown.
@return {undefined}
|
[
"Bubble",
"an",
"exception",
"by",
"providing",
"it",
"s",
"origin",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/boilerplate.view.js#L1568-L1573
|
52,105
|
strekmann/libby
|
lib/mongostore.js
|
MongoStore
|
function MongoStore(uri, options) {
var self = this;
this.options = options || (options = {});
options.collectionName = options.collectionName || 'sessions';
// 1 day
options.ttl = options.ttl || 24 * 60 * 60 * 1000;
// 60 s
options.cleanupInterval = options.cleanupInterval || 60 * 1000;
options.server = options.server || {};
options.server.auto_reconnect = options.server.auto_reconnect != null ? options.server.auto_reconnect : true;
this._error = function(err) {
if (err) { self.emit('error', err); }
};
// It's a Db instance.
if (uri.collection) {
this.db = uri;
this._setup();
} else {
MongoClient.connect(uri, options, function(err, db) {
if (err) { return self._error(err); }
self.db = db;
self._setup();
});
}
}
|
javascript
|
function MongoStore(uri, options) {
var self = this;
this.options = options || (options = {});
options.collectionName = options.collectionName || 'sessions';
// 1 day
options.ttl = options.ttl || 24 * 60 * 60 * 1000;
// 60 s
options.cleanupInterval = options.cleanupInterval || 60 * 1000;
options.server = options.server || {};
options.server.auto_reconnect = options.server.auto_reconnect != null ? options.server.auto_reconnect : true;
this._error = function(err) {
if (err) { self.emit('error', err); }
};
// It's a Db instance.
if (uri.collection) {
this.db = uri;
this._setup();
} else {
MongoClient.connect(uri, options, function(err, db) {
if (err) { return self._error(err); }
self.db = db;
self._setup();
});
}
}
|
[
"function",
"MongoStore",
"(",
"uri",
",",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"options",
"=",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"options",
".",
"collectionName",
"=",
"options",
".",
"collectionName",
"||",
"'sessions'",
";",
"// 1 day",
"options",
".",
"ttl",
"=",
"options",
".",
"ttl",
"||",
"24",
"*",
"60",
"*",
"60",
"*",
"1000",
";",
"// 60 s",
"options",
".",
"cleanupInterval",
"=",
"options",
".",
"cleanupInterval",
"||",
"60",
"*",
"1000",
";",
"options",
".",
"server",
"=",
"options",
".",
"server",
"||",
"{",
"}",
";",
"options",
".",
"server",
".",
"auto_reconnect",
"=",
"options",
".",
"server",
".",
"auto_reconnect",
"!=",
"null",
"?",
"options",
".",
"server",
".",
"auto_reconnect",
":",
"true",
";",
"this",
".",
"_error",
"=",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"self",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"}",
"}",
";",
"// It's a Db instance.",
"if",
"(",
"uri",
".",
"collection",
")",
"{",
"this",
".",
"db",
"=",
"uri",
";",
"this",
".",
"_setup",
"(",
")",
";",
"}",
"else",
"{",
"MongoClient",
".",
"connect",
"(",
"uri",
",",
"options",
",",
"function",
"(",
"err",
",",
"db",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"self",
".",
"_error",
"(",
"err",
")",
";",
"}",
"self",
".",
"db",
"=",
"db",
";",
"self",
".",
"_setup",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Initialize a new `MongoStore`.
@api public
|
[
"Initialize",
"a",
"new",
"MongoStore",
"."
] |
9a43f756cf5f43771fa70514f352a16276eb0c98
|
https://github.com/strekmann/libby/blob/9a43f756cf5f43771fa70514f352a16276eb0c98/lib/mongostore.js#L19-L46
|
52,106
|
jaredhanson/crane-amqp
|
lib/message.js
|
Message
|
function Message(message, headers, deliveryInfo, obj) {
// Crane uses slash ('/') separators rather than period ('.')
this.topic = deliveryInfo.routingKey.replace(/\./g, '/');
this.headers = headers;
if (deliveryInfo.contentType) { this.headers['content-type'] = deliveryInfo.contentType; }
if (Buffer.isBuffer(message.data)) {
this.data = message.data;
} else {
this.body = message;
}
this.__msg = obj;
}
|
javascript
|
function Message(message, headers, deliveryInfo, obj) {
// Crane uses slash ('/') separators rather than period ('.')
this.topic = deliveryInfo.routingKey.replace(/\./g, '/');
this.headers = headers;
if (deliveryInfo.contentType) { this.headers['content-type'] = deliveryInfo.contentType; }
if (Buffer.isBuffer(message.data)) {
this.data = message.data;
} else {
this.body = message;
}
this.__msg = obj;
}
|
[
"function",
"Message",
"(",
"message",
",",
"headers",
",",
"deliveryInfo",
",",
"obj",
")",
"{",
"// Crane uses slash ('/') separators rather than period ('.')",
"this",
".",
"topic",
"=",
"deliveryInfo",
".",
"routingKey",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"'/'",
")",
";",
"this",
".",
"headers",
"=",
"headers",
";",
"if",
"(",
"deliveryInfo",
".",
"contentType",
")",
"{",
"this",
".",
"headers",
"[",
"'content-type'",
"]",
"=",
"deliveryInfo",
".",
"contentType",
";",
"}",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"message",
".",
"data",
")",
")",
"{",
"this",
".",
"data",
"=",
"message",
".",
"data",
";",
"}",
"else",
"{",
"this",
".",
"body",
"=",
"message",
";",
"}",
"this",
".",
"__msg",
"=",
"obj",
";",
"}"
] |
`Message` constructor.
@api protected
|
[
"Message",
"constructor",
"."
] |
2f2a653a5567550d035daf8a2587fac0ebc9d8ce
|
https://github.com/jaredhanson/crane-amqp/blob/2f2a653a5567550d035daf8a2587fac0ebc9d8ce/lib/message.js#L6-L19
|
52,107
|
tombenke/proper
|
processor.js
|
function(processingQueue, phase) {
var that = this;
verbose && console.log('phase is: ' + phase, processors);
processingQueue.forEach(function(context) {
var processor = processors[phase][context.fileType];
verbose && console.log('runProcessor with ', that, context );
context.graph = processor.apply(that, [context]);
});
return that;
}
|
javascript
|
function(processingQueue, phase) {
var that = this;
verbose && console.log('phase is: ' + phase, processors);
processingQueue.forEach(function(context) {
var processor = processors[phase][context.fileType];
verbose && console.log('runProcessor with ', that, context );
context.graph = processor.apply(that, [context]);
});
return that;
}
|
[
"function",
"(",
"processingQueue",
",",
"phase",
")",
"{",
"var",
"that",
"=",
"this",
";",
"verbose",
"&&",
"console",
".",
"log",
"(",
"'phase is: '",
"+",
"phase",
",",
"processors",
")",
";",
"processingQueue",
".",
"forEach",
"(",
"function",
"(",
"context",
")",
"{",
"var",
"processor",
"=",
"processors",
"[",
"phase",
"]",
"[",
"context",
".",
"fileType",
"]",
";",
"verbose",
"&&",
"console",
".",
"log",
"(",
"'runProcessor with '",
",",
"that",
",",
"context",
")",
";",
"context",
".",
"graph",
"=",
"processor",
".",
"apply",
"(",
"that",
",",
"[",
"context",
"]",
")",
";",
"}",
")",
";",
"return",
"that",
";",
"}"
] |
Runs a set of processors using their configurations
@param {Array} processingQueue The processor set with their configuration data
@return {Object} The result graph of processing
|
[
"Runs",
"a",
"set",
"of",
"processors",
"using",
"their",
"configurations"
] |
3f766df6ec7dbb0c4d136373a94002d00d340a48
|
https://github.com/tombenke/proper/blob/3f766df6ec7dbb0c4d136373a94002d00d340a48/processor.js#L260-L271
|
|
52,108
|
IMCampbell/ubcscrapr
|
src/index.js
|
getRoomSlots
|
function getRoomSlots (semester, minRequestSpace = 1000, verbose = false, departments = []) {
validateInput("semester", semester, [1, 2], "set");
validateInput("minRequestSpace", minRequestSpace, [0, 100000], "range");
validateInput("verbose", verbose, [true, false], "set");
validateInput("departments", departments, "Array", "type");
return scrapeRS(semester, verbose, minRequestSpace, departments);
}
|
javascript
|
function getRoomSlots (semester, minRequestSpace = 1000, verbose = false, departments = []) {
validateInput("semester", semester, [1, 2], "set");
validateInput("minRequestSpace", minRequestSpace, [0, 100000], "range");
validateInput("verbose", verbose, [true, false], "set");
validateInput("departments", departments, "Array", "type");
return scrapeRS(semester, verbose, minRequestSpace, departments);
}
|
[
"function",
"getRoomSlots",
"(",
"semester",
",",
"minRequestSpace",
"=",
"1000",
",",
"verbose",
"=",
"false",
",",
"departments",
"=",
"[",
"]",
")",
"{",
"validateInput",
"(",
"\"semester\"",
",",
"semester",
",",
"[",
"1",
",",
"2",
"]",
",",
"\"set\"",
")",
";",
"validateInput",
"(",
"\"minRequestSpace\"",
",",
"minRequestSpace",
",",
"[",
"0",
",",
"100000",
"]",
",",
"\"range\"",
")",
";",
"validateInput",
"(",
"\"verbose\"",
",",
"verbose",
",",
"[",
"true",
",",
"false",
"]",
",",
"\"set\"",
")",
";",
"validateInput",
"(",
"\"departments\"",
",",
"departments",
",",
"\"Array\"",
",",
"\"type\"",
")",
";",
"return",
"scrapeRS",
"(",
"semester",
",",
"verbose",
",",
"minRequestSpace",
",",
"departments",
")",
";",
"}"
] |
Returns an object containing all class sections with their weekday, time, room, building, and address
@param semester: the semester that the classes belong to
@param minRequestSpace: the minimum amount of time between requests to UBCs webserver in milliseconds
@param verbose: whether or not you want to see console.logs
@param departments: an optional list that if present will tell the scrapr to only scrape the given departments
|
[
"Returns",
"an",
"object",
"containing",
"all",
"class",
"sections",
"with",
"their",
"weekday",
"time",
"room",
"building",
"and",
"address"
] |
42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c
|
https://github.com/IMCampbell/ubcscrapr/blob/42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c/src/index.js#L11-L17
|
52,109
|
IMCampbell/ubcscrapr
|
src/index.js
|
getHours
|
function getHours (verbose = false, minRequestSpace = 500) {
validateInput("verbose", verbose, [true, false], "set");
validateInput("minRequestSpace", minRequestSpace, [0, 100000], "range");
return scrapeBuildings(verbose, minRequestSpace);
}
|
javascript
|
function getHours (verbose = false, minRequestSpace = 500) {
validateInput("verbose", verbose, [true, false], "set");
validateInput("minRequestSpace", minRequestSpace, [0, 100000], "range");
return scrapeBuildings(verbose, minRequestSpace);
}
|
[
"function",
"getHours",
"(",
"verbose",
"=",
"false",
",",
"minRequestSpace",
"=",
"500",
")",
"{",
"validateInput",
"(",
"\"verbose\"",
",",
"verbose",
",",
"[",
"true",
",",
"false",
"]",
",",
"\"set\"",
")",
";",
"validateInput",
"(",
"\"minRequestSpace\"",
",",
"minRequestSpace",
",",
"[",
"0",
",",
"100000",
"]",
",",
"\"range\"",
")",
";",
"return",
"scrapeBuildings",
"(",
"verbose",
",",
"minRequestSpace",
")",
";",
"}"
] |
Gets the hours for all buildings listed on the Buildings and classrooms section of the student services page
@param verbose: whether or not you want to see console.logs
@param minRequestSpace: the minimum amount of time between requests to UBCs webserver in milliseconds
|
[
"Gets",
"the",
"hours",
"for",
"all",
"buildings",
"listed",
"on",
"the",
"Buildings",
"and",
"classrooms",
"section",
"of",
"the",
"student",
"services",
"page"
] |
42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c
|
https://github.com/IMCampbell/ubcscrapr/blob/42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c/src/index.js#L24-L28
|
52,110
|
IMCampbell/ubcscrapr
|
src/index.js
|
validateInput
|
function validateInput(inputName, input, acceptableValues, acceptableValueType) {
let validInput = true;
if (acceptableValueType == "range") {
if (input < Math.min(...acceptableValues) || input > Math.max(...acceptableValues)) {
validInput = false;
}
} else if (acceptableValueType == "set") {
if (acceptableValues.indexOf(input) == -1) {
validInput = false;
}
} else if (acceptableValueType == "type") {
if (!typeof input == acceptableValues) {
validInput = false;
}
}
if (!validInput) {
throw(`Invalid ${inputName} given, valid options are: ${acceptableValues}`);
}
}
|
javascript
|
function validateInput(inputName, input, acceptableValues, acceptableValueType) {
let validInput = true;
if (acceptableValueType == "range") {
if (input < Math.min(...acceptableValues) || input > Math.max(...acceptableValues)) {
validInput = false;
}
} else if (acceptableValueType == "set") {
if (acceptableValues.indexOf(input) == -1) {
validInput = false;
}
} else if (acceptableValueType == "type") {
if (!typeof input == acceptableValues) {
validInput = false;
}
}
if (!validInput) {
throw(`Invalid ${inputName} given, valid options are: ${acceptableValues}`);
}
}
|
[
"function",
"validateInput",
"(",
"inputName",
",",
"input",
",",
"acceptableValues",
",",
"acceptableValueType",
")",
"{",
"let",
"validInput",
"=",
"true",
";",
"if",
"(",
"acceptableValueType",
"==",
"\"range\"",
")",
"{",
"if",
"(",
"input",
"<",
"Math",
".",
"min",
"(",
"...",
"acceptableValues",
")",
"||",
"input",
">",
"Math",
".",
"max",
"(",
"...",
"acceptableValues",
")",
")",
"{",
"validInput",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"acceptableValueType",
"==",
"\"set\"",
")",
"{",
"if",
"(",
"acceptableValues",
".",
"indexOf",
"(",
"input",
")",
"==",
"-",
"1",
")",
"{",
"validInput",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"acceptableValueType",
"==",
"\"type\"",
")",
"{",
"if",
"(",
"!",
"typeof",
"input",
"==",
"acceptableValues",
")",
"{",
"validInput",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"validInput",
")",
"{",
"throw",
"(",
"`",
"${",
"inputName",
"}",
"${",
"acceptableValues",
"}",
"`",
")",
";",
"}",
"}"
] |
Function to ensure that variables passed to API are of the correct types and bounded by reasonable values.
@param inputName: the name of the variable
@param input: the value of the variable
@param acceptableValues: parameter containing valid values for input to take
@param acceptableValueType: a flag
range means that the acceptableValues is a list containing a min and a max value
set means that the acceptableValues is a list containing all acceptable values
type means that the acceptableValues is a single string containing the type that input must be
|
[
"Function",
"to",
"ensure",
"that",
"variables",
"passed",
"to",
"API",
"are",
"of",
"the",
"correct",
"types",
"and",
"bounded",
"by",
"reasonable",
"values",
"."
] |
42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c
|
https://github.com/IMCampbell/ubcscrapr/blob/42b2d5acfae16f55772f548bb5ca1ac2d2a07a4c/src/index.js#L39-L57
|
52,111
|
oodolabs/cupsdm
|
lib/parser.js
|
parseLine
|
function parseLine(line, lineno, options) {
let command = null;
const lineContinuationRegex = (options && options.lineContinuationRegex
|| TOKEN_LINE_CONTINUATION);
line = line.trim();
if (!line) {
// Ignore empty lines
return { command: null, remainder: '' };
}
if (isComment(line)) {
// Handle comment lines.
command = { name: 'COMMENT', args: line, lineno: lineno };
return { command: command, remainder: '' };
}
if (line.match(lineContinuationRegex)) {
// Line continues on next line.
const remainder = line.replace(lineContinuationRegex, '', 'g');
return { command: null, remainder: remainder };
}
command = splitCommand(line);
command.lineno = lineno;
let commandParserFn = commandParsers[command.name];
if (!commandParserFn) {
// Invalid Dockerfile instruction, but allow it and move on.
// log.debug('Invalid Dockerfile command:', command.name);
commandParserFn = parseString;
}
if (commandParserFn(command)) {
// Successfully converted the arguments.
command.raw = line;
delete command.rest;
}
return { command: command, remainder: '' };
}
|
javascript
|
function parseLine(line, lineno, options) {
let command = null;
const lineContinuationRegex = (options && options.lineContinuationRegex
|| TOKEN_LINE_CONTINUATION);
line = line.trim();
if (!line) {
// Ignore empty lines
return { command: null, remainder: '' };
}
if (isComment(line)) {
// Handle comment lines.
command = { name: 'COMMENT', args: line, lineno: lineno };
return { command: command, remainder: '' };
}
if (line.match(lineContinuationRegex)) {
// Line continues on next line.
const remainder = line.replace(lineContinuationRegex, '', 'g');
return { command: null, remainder: remainder };
}
command = splitCommand(line);
command.lineno = lineno;
let commandParserFn = commandParsers[command.name];
if (!commandParserFn) {
// Invalid Dockerfile instruction, but allow it and move on.
// log.debug('Invalid Dockerfile command:', command.name);
commandParserFn = parseString;
}
if (commandParserFn(command)) {
// Successfully converted the arguments.
command.raw = line;
delete command.rest;
}
return { command: command, remainder: '' };
}
|
[
"function",
"parseLine",
"(",
"line",
",",
"lineno",
",",
"options",
")",
"{",
"let",
"command",
"=",
"null",
";",
"const",
"lineContinuationRegex",
"=",
"(",
"options",
"&&",
"options",
".",
"lineContinuationRegex",
"||",
"TOKEN_LINE_CONTINUATION",
")",
";",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"line",
")",
"{",
"// Ignore empty lines",
"return",
"{",
"command",
":",
"null",
",",
"remainder",
":",
"''",
"}",
";",
"}",
"if",
"(",
"isComment",
"(",
"line",
")",
")",
"{",
"// Handle comment lines.",
"command",
"=",
"{",
"name",
":",
"'COMMENT'",
",",
"args",
":",
"line",
",",
"lineno",
":",
"lineno",
"}",
";",
"return",
"{",
"command",
":",
"command",
",",
"remainder",
":",
"''",
"}",
";",
"}",
"if",
"(",
"line",
".",
"match",
"(",
"lineContinuationRegex",
")",
")",
"{",
"// Line continues on next line.",
"const",
"remainder",
"=",
"line",
".",
"replace",
"(",
"lineContinuationRegex",
",",
"''",
",",
"'g'",
")",
";",
"return",
"{",
"command",
":",
"null",
",",
"remainder",
":",
"remainder",
"}",
";",
"}",
"command",
"=",
"splitCommand",
"(",
"line",
")",
";",
"command",
".",
"lineno",
"=",
"lineno",
";",
"let",
"commandParserFn",
"=",
"commandParsers",
"[",
"command",
".",
"name",
"]",
";",
"if",
"(",
"!",
"commandParserFn",
")",
"{",
"// Invalid Dockerfile instruction, but allow it and move on.",
"// log.debug('Invalid Dockerfile command:', command.name);",
"commandParserFn",
"=",
"parseString",
";",
"}",
"if",
"(",
"commandParserFn",
"(",
"command",
")",
")",
"{",
"// Successfully converted the arguments.",
"command",
".",
"raw",
"=",
"line",
";",
"delete",
"command",
".",
"rest",
";",
"}",
"return",
"{",
"command",
":",
"command",
",",
"remainder",
":",
"''",
"}",
";",
"}"
] |
parse a line and return the remainder.
|
[
"parse",
"a",
"line",
"and",
"return",
"the",
"remainder",
"."
] |
6567c0d6fcfe6cfe999f6c13ea3b1d7ca5f529f7
|
https://github.com/oodolabs/cupsdm/blob/6567c0d6fcfe6cfe999f6c13ea3b1d7ca5f529f7/lib/parser.js#L303-L344
|
52,112
|
phelpstream/svp
|
lib/functions/dig.js
|
dig
|
function dig(obj) {
var iterateeFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (val, key, iterableParent) {
return val;
};
// eslint-disable-line no-unused-vars
// modifierFn = v => v,
return (0, _each2.default)(obj, function iterator(itValue, key, itObj) {
var processedItValue = itValue;
// console.log("processedItValue (before)", processedItValue)
if ((0, _is.isIterable)(itValue, { objects: true })) {
// console.log("Is iterable, key:", key)
processedItValue = (0, _each2.default)(itValue, iterator); // , iterateeFn
}
var iterateeReturnedValue = iterateeFn(processedItValue, key, itObj);
// console.log("iterateeReturnedValue", iterateeReturnedValue)
if ((0, _is.isObject)(iterateeReturnedValue) && (0, _is.isLength)((0, _toKeys2.default)(iterateeReturnedValue), 1) && (0, _get2.default)(iterateeReturnedValue, "$remove", false) === true) {
return { $remove: true };
} else if ((0, _is.isDefined)(iterateeReturnedValue)) {
return iterateeReturnedValue;
} else {
// console.log("processedItValue (after)", processedItValue)
return processedItValue;
}
}
//, iterateeFn
);
}
|
javascript
|
function dig(obj) {
var iterateeFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (val, key, iterableParent) {
return val;
};
// eslint-disable-line no-unused-vars
// modifierFn = v => v,
return (0, _each2.default)(obj, function iterator(itValue, key, itObj) {
var processedItValue = itValue;
// console.log("processedItValue (before)", processedItValue)
if ((0, _is.isIterable)(itValue, { objects: true })) {
// console.log("Is iterable, key:", key)
processedItValue = (0, _each2.default)(itValue, iterator); // , iterateeFn
}
var iterateeReturnedValue = iterateeFn(processedItValue, key, itObj);
// console.log("iterateeReturnedValue", iterateeReturnedValue)
if ((0, _is.isObject)(iterateeReturnedValue) && (0, _is.isLength)((0, _toKeys2.default)(iterateeReturnedValue), 1) && (0, _get2.default)(iterateeReturnedValue, "$remove", false) === true) {
return { $remove: true };
} else if ((0, _is.isDefined)(iterateeReturnedValue)) {
return iterateeReturnedValue;
} else {
// console.log("processedItValue (after)", processedItValue)
return processedItValue;
}
}
//, iterateeFn
);
}
|
[
"function",
"dig",
"(",
"obj",
")",
"{",
"var",
"iterateeFn",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"function",
"(",
"val",
",",
"key",
",",
"iterableParent",
")",
"{",
"return",
"val",
";",
"}",
";",
"// eslint-disable-line no-unused-vars",
"// modifierFn = v => v,",
"return",
"(",
"0",
",",
"_each2",
".",
"default",
")",
"(",
"obj",
",",
"function",
"iterator",
"(",
"itValue",
",",
"key",
",",
"itObj",
")",
"{",
"var",
"processedItValue",
"=",
"itValue",
";",
"// console.log(\"processedItValue (before)\", processedItValue)",
"if",
"(",
"(",
"0",
",",
"_is",
".",
"isIterable",
")",
"(",
"itValue",
",",
"{",
"objects",
":",
"true",
"}",
")",
")",
"{",
"// console.log(\"Is iterable, key:\", key)",
"processedItValue",
"=",
"(",
"0",
",",
"_each2",
".",
"default",
")",
"(",
"itValue",
",",
"iterator",
")",
";",
"// , iterateeFn",
"}",
"var",
"iterateeReturnedValue",
"=",
"iterateeFn",
"(",
"processedItValue",
",",
"key",
",",
"itObj",
")",
";",
"// console.log(\"iterateeReturnedValue\", iterateeReturnedValue)",
"if",
"(",
"(",
"0",
",",
"_is",
".",
"isObject",
")",
"(",
"iterateeReturnedValue",
")",
"&&",
"(",
"0",
",",
"_is",
".",
"isLength",
")",
"(",
"(",
"0",
",",
"_toKeys2",
".",
"default",
")",
"(",
"iterateeReturnedValue",
")",
",",
"1",
")",
"&&",
"(",
"0",
",",
"_get2",
".",
"default",
")",
"(",
"iterateeReturnedValue",
",",
"\"$remove\"",
",",
"false",
")",
"===",
"true",
")",
"{",
"return",
"{",
"$remove",
":",
"true",
"}",
";",
"}",
"else",
"if",
"(",
"(",
"0",
",",
"_is",
".",
"isDefined",
")",
"(",
"iterateeReturnedValue",
")",
")",
"{",
"return",
"iterateeReturnedValue",
";",
"}",
"else",
"{",
"// console.log(\"processedItValue (after)\", processedItValue)",
"return",
"processedItValue",
";",
"}",
"}",
"//, iterateeFn",
")",
";",
"}"
] |
Loop recursively through an iterable data structure.
@param {*} obj The value to iterate over.
@param {Function} iterateeFn The iterateeFn to look at the data.
|
[
"Loop",
"recursively",
"through",
"an",
"iterable",
"data",
"structure",
"."
] |
2f99adb9c5d0709e567264bba896d6a59f6a0a59
|
https://github.com/phelpstream/svp/blob/2f99adb9c5d0709e567264bba896d6a59f6a0a59/lib/functions/dig.js#L29-L55
|
52,113
|
asciidisco/grunt-backbonebuilder
|
lib/builder.js
|
function (bbsource) {
var parts = {
Header: '',
Setup: '// Initial Setup',
Events: '// Backbone.Events',
Model: '// Backbone.Model',
Collection: '// Backbone.Collection',
Router: '// Backbone.Router',
History: '// Backbone.History',
View: '// Backbone.View',
Sync: '// Backbone.sync',
Helpers: '// Helpers'
};
// index & module helper
var lastPos = 0;
var temp = 0;
var keys = Object.keys(parts);
// extract every module
keys.forEach(function (key, idx) {
temp = typeof keys[idx + 1] !== 'undefined' ? bbsource.search(parts[keys[idx + 1]]) : bbsource.length;
parts[key] = extract(bbsource, lastPos, temp);
lastPos = temp;
});
return parts;
}
|
javascript
|
function (bbsource) {
var parts = {
Header: '',
Setup: '// Initial Setup',
Events: '// Backbone.Events',
Model: '// Backbone.Model',
Collection: '// Backbone.Collection',
Router: '// Backbone.Router',
History: '// Backbone.History',
View: '// Backbone.View',
Sync: '// Backbone.sync',
Helpers: '// Helpers'
};
// index & module helper
var lastPos = 0;
var temp = 0;
var keys = Object.keys(parts);
// extract every module
keys.forEach(function (key, idx) {
temp = typeof keys[idx + 1] !== 'undefined' ? bbsource.search(parts[keys[idx + 1]]) : bbsource.length;
parts[key] = extract(bbsource, lastPos, temp);
lastPos = temp;
});
return parts;
}
|
[
"function",
"(",
"bbsource",
")",
"{",
"var",
"parts",
"=",
"{",
"Header",
":",
"''",
",",
"Setup",
":",
"'// Initial Setup'",
",",
"Events",
":",
"'// Backbone.Events'",
",",
"Model",
":",
"'// Backbone.Model'",
",",
"Collection",
":",
"'// Backbone.Collection'",
",",
"Router",
":",
"'// Backbone.Router'",
",",
"History",
":",
"'// Backbone.History'",
",",
"View",
":",
"'// Backbone.View'",
",",
"Sync",
":",
"'// Backbone.sync'",
",",
"Helpers",
":",
"'// Helpers'",
"}",
";",
"// index & module helper",
"var",
"lastPos",
"=",
"0",
";",
"var",
"temp",
"=",
"0",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"parts",
")",
";",
"// extract every module",
"keys",
".",
"forEach",
"(",
"function",
"(",
"key",
",",
"idx",
")",
"{",
"temp",
"=",
"typeof",
"keys",
"[",
"idx",
"+",
"1",
"]",
"!==",
"'undefined'",
"?",
"bbsource",
".",
"search",
"(",
"parts",
"[",
"keys",
"[",
"idx",
"+",
"1",
"]",
"]",
")",
":",
"bbsource",
".",
"length",
";",
"parts",
"[",
"key",
"]",
"=",
"extract",
"(",
"bbsource",
",",
"lastPos",
",",
"temp",
")",
";",
"lastPos",
"=",
"temp",
";",
"}",
")",
";",
"return",
"parts",
";",
"}"
] |
parts are seperated by annotations
|
[
"parts",
"are",
"seperated",
"by",
"annotations"
] |
767fc145bb6f713c3e3daba2fc62c2b8cd02ca67
|
https://github.com/asciidisco/grunt-backbonebuilder/blob/767fc145bb6f713c3e3daba2fc62c2b8cd02ca67/lib/builder.js#L29-L57
|
|
52,114
|
asciidisco/grunt-backbonebuilder
|
lib/builder.js
|
function (combinations, parts, backboneSrc) {
var src = '';
var allCombinations = [];
parts.forEach(function (part) {
allCombinations.push(combinations[_.str.capitalize(part.toLowerCase())]);
});
var neededParts = _.union.apply(_, allCombinations);
var backboneParts = getBackboneParts(backboneSrc);
var finalCombination = _.intersection(combinations.All, neededParts);
finalCombination.forEach(function (part) {
src += backboneParts[_.str.capitalize(part.toLowerCase())];
if (part.toLowerCase() === 'view') {
src = src.replace('Model.extend = Collection.extend = Router.extend = View.extend = extend;', '');
}
});
var extender = '';
if(!_.contains(finalCombination, 'View') && !_.contains(finalCombination, 'view')) {
extender += ' var extend = function (protoProps, classProps) {\n';
extender += ' var child = inherits(this, protoProps, classProps)\n';
extender += ' child.extend = this.extend;\n';
extender += ' return child;\n';
extender += ' };\n\n';
}
// add the extend chain
finalCombination.forEach(function (extendo) {
var lowerEx = extendo.toLowerCase();
if (lowerEx === 'model') {
extender += 'Model.extend = ';
}
if (lowerEx === 'collection') {
extender += 'Collection.extend = ';
}
if (lowerEx === 'router') {
extender += 'Router.extend = ';
}
if (lowerEx === 'view') {
extender += 'View.extend = ';
}
});
extender += 'extend;';
src = src.replace('// Helpers', extender + '\n\n // Helpers');
return src;
}
|
javascript
|
function (combinations, parts, backboneSrc) {
var src = '';
var allCombinations = [];
parts.forEach(function (part) {
allCombinations.push(combinations[_.str.capitalize(part.toLowerCase())]);
});
var neededParts = _.union.apply(_, allCombinations);
var backboneParts = getBackboneParts(backboneSrc);
var finalCombination = _.intersection(combinations.All, neededParts);
finalCombination.forEach(function (part) {
src += backboneParts[_.str.capitalize(part.toLowerCase())];
if (part.toLowerCase() === 'view') {
src = src.replace('Model.extend = Collection.extend = Router.extend = View.extend = extend;', '');
}
});
var extender = '';
if(!_.contains(finalCombination, 'View') && !_.contains(finalCombination, 'view')) {
extender += ' var extend = function (protoProps, classProps) {\n';
extender += ' var child = inherits(this, protoProps, classProps)\n';
extender += ' child.extend = this.extend;\n';
extender += ' return child;\n';
extender += ' };\n\n';
}
// add the extend chain
finalCombination.forEach(function (extendo) {
var lowerEx = extendo.toLowerCase();
if (lowerEx === 'model') {
extender += 'Model.extend = ';
}
if (lowerEx === 'collection') {
extender += 'Collection.extend = ';
}
if (lowerEx === 'router') {
extender += 'Router.extend = ';
}
if (lowerEx === 'view') {
extender += 'View.extend = ';
}
});
extender += 'extend;';
src = src.replace('// Helpers', extender + '\n\n // Helpers');
return src;
}
|
[
"function",
"(",
"combinations",
",",
"parts",
",",
"backboneSrc",
")",
"{",
"var",
"src",
"=",
"''",
";",
"var",
"allCombinations",
"=",
"[",
"]",
";",
"parts",
".",
"forEach",
"(",
"function",
"(",
"part",
")",
"{",
"allCombinations",
".",
"push",
"(",
"combinations",
"[",
"_",
".",
"str",
".",
"capitalize",
"(",
"part",
".",
"toLowerCase",
"(",
")",
")",
"]",
")",
";",
"}",
")",
";",
"var",
"neededParts",
"=",
"_",
".",
"union",
".",
"apply",
"(",
"_",
",",
"allCombinations",
")",
";",
"var",
"backboneParts",
"=",
"getBackboneParts",
"(",
"backboneSrc",
")",
";",
"var",
"finalCombination",
"=",
"_",
".",
"intersection",
"(",
"combinations",
".",
"All",
",",
"neededParts",
")",
";",
"finalCombination",
".",
"forEach",
"(",
"function",
"(",
"part",
")",
"{",
"src",
"+=",
"backboneParts",
"[",
"_",
".",
"str",
".",
"capitalize",
"(",
"part",
".",
"toLowerCase",
"(",
")",
")",
"]",
";",
"if",
"(",
"part",
".",
"toLowerCase",
"(",
")",
"===",
"'view'",
")",
"{",
"src",
"=",
"src",
".",
"replace",
"(",
"'Model.extend = Collection.extend = Router.extend = View.extend = extend;'",
",",
"''",
")",
";",
"}",
"}",
")",
";",
"var",
"extender",
"=",
"''",
";",
"if",
"(",
"!",
"_",
".",
"contains",
"(",
"finalCombination",
",",
"'View'",
")",
"&&",
"!",
"_",
".",
"contains",
"(",
"finalCombination",
",",
"'view'",
")",
")",
"{",
"extender",
"+=",
"' var extend = function (protoProps, classProps) {\\n'",
";",
"extender",
"+=",
"' var child = inherits(this, protoProps, classProps)\\n'",
";",
"extender",
"+=",
"' child.extend = this.extend;\\n'",
";",
"extender",
"+=",
"' return child;\\n'",
";",
"extender",
"+=",
"' };\\n\\n'",
";",
"}",
"// add the extend chain",
"finalCombination",
".",
"forEach",
"(",
"function",
"(",
"extendo",
")",
"{",
"var",
"lowerEx",
"=",
"extendo",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"lowerEx",
"===",
"'model'",
")",
"{",
"extender",
"+=",
"'Model.extend = '",
";",
"}",
"if",
"(",
"lowerEx",
"===",
"'collection'",
")",
"{",
"extender",
"+=",
"'Collection.extend = '",
";",
"}",
"if",
"(",
"lowerEx",
"===",
"'router'",
")",
"{",
"extender",
"+=",
"'Router.extend = '",
";",
"}",
"if",
"(",
"lowerEx",
"===",
"'view'",
")",
"{",
"extender",
"+=",
"'View.extend = '",
";",
"}",
"}",
")",
";",
"extender",
"+=",
"'extend;'",
";",
"src",
"=",
"src",
".",
"replace",
"(",
"'// Helpers'",
",",
"extender",
"+",
"'\\n\\n // Helpers'",
")",
";",
"return",
"src",
";",
"}"
] |
glues the backbone parts together again
|
[
"glues",
"the",
"backbone",
"parts",
"together",
"again"
] |
767fc145bb6f713c3e3daba2fc62c2b8cd02ca67
|
https://github.com/asciidisco/grunt-backbonebuilder/blob/767fc145bb6f713c3e3daba2fc62c2b8cd02ca67/lib/builder.js#L60-L114
|
|
52,115
|
yoshuawuyts/named-level-store
|
index.js
|
namedLevelStore
|
function namedLevelStore (name) {
assert.equal(typeof name, 'string', 'named-level-store: name should be a string')
const location = path.join(process.env.HOME, '.leveldb', name)
mkdirp.sync(location)
const db = level(location)
db.location = location
return db
}
|
javascript
|
function namedLevelStore (name) {
assert.equal(typeof name, 'string', 'named-level-store: name should be a string')
const location = path.join(process.env.HOME, '.leveldb', name)
mkdirp.sync(location)
const db = level(location)
db.location = location
return db
}
|
[
"function",
"namedLevelStore",
"(",
"name",
")",
"{",
"assert",
".",
"equal",
"(",
"typeof",
"name",
",",
"'string'",
",",
"'named-level-store: name should be a string'",
")",
"const",
"location",
"=",
"path",
".",
"join",
"(",
"process",
".",
"env",
".",
"HOME",
",",
"'.leveldb'",
",",
"name",
")",
"mkdirp",
".",
"sync",
"(",
"location",
")",
"const",
"db",
"=",
"level",
"(",
"location",
")",
"db",
".",
"location",
"=",
"location",
"return",
"db",
"}"
] |
Create a levelDB instance on your local machine str -> obj
|
[
"Create",
"a",
"levelDB",
"instance",
"on",
"your",
"local",
"machine",
"str",
"-",
">",
"obj"
] |
8a7448ff89d192a07ac718731f0680d6d4b1cff0
|
https://github.com/yoshuawuyts/named-level-store/blob/8a7448ff89d192a07ac718731f0680d6d4b1cff0/index.js#L10-L17
|
52,116
|
tolokoban/ToloFrameWork
|
lib/source.js
|
removeSrcDirPrefixFromFile
|
function removeSrcDirPrefixFromFile( srcDir, file ) {
if ( typeof srcDir !== 'string' ) return file;
if ( typeof file !== 'string' ) return file;
if ( file.substr( 0, srcDir.length ) !== srcDir ) {
return file;
}
return file.substr( srcDir.length );
}
|
javascript
|
function removeSrcDirPrefixFromFile( srcDir, file ) {
if ( typeof srcDir !== 'string' ) return file;
if ( typeof file !== 'string' ) return file;
if ( file.substr( 0, srcDir.length ) !== srcDir ) {
return file;
}
return file.substr( srcDir.length );
}
|
[
"function",
"removeSrcDirPrefixFromFile",
"(",
"srcDir",
",",
"file",
")",
"{",
"if",
"(",
"typeof",
"srcDir",
"!==",
"'string'",
")",
"return",
"file",
";",
"if",
"(",
"typeof",
"file",
"!==",
"'string'",
")",
"return",
"file",
";",
"if",
"(",
"file",
".",
"substr",
"(",
"0",
",",
"srcDir",
".",
"length",
")",
"!==",
"srcDir",
")",
"{",
"return",
"file",
";",
"}",
"return",
"file",
".",
"substr",
"(",
"srcDir",
".",
"length",
")",
";",
"}"
] |
If present, remove the `srcDir` prefix of `file`.
@param {[type]} srcDir [description]
@param {[type]} file [description]
@returns {[type]} [description]
@example
const f = removeSrcDirPrefixFromFile;
f("/src/", "/myfile.cpp") === "/myfile.cpp";
f("/src/", "/src/myfile2.cpp") === "myfile2.cpp";
|
[
"If",
"present",
"remove",
"the",
"srcDir",
"prefix",
"of",
"file",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/source.js#L233-L241
|
52,117
|
elantion/handyJS
|
raw/browser/ajax.js
|
function (value) {
if (value === null) {
return '';
}
if (value === undefined) {
return '';
}
switch (typeof value) {
case 'object' :
if (value instanceof Blob) {
return value;
} else {
return JSON.stringify(value);
}
break;
case 'string':
return value;
default :
return value;
}
}
|
javascript
|
function (value) {
if (value === null) {
return '';
}
if (value === undefined) {
return '';
}
switch (typeof value) {
case 'object' :
if (value instanceof Blob) {
return value;
} else {
return JSON.stringify(value);
}
break;
case 'string':
return value;
default :
return value;
}
}
|
[
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"value",
"===",
"undefined",
")",
"{",
"return",
"''",
";",
"}",
"switch",
"(",
"typeof",
"value",
")",
"{",
"case",
"'object'",
":",
"if",
"(",
"value",
"instanceof",
"Blob",
")",
"{",
"return",
"value",
";",
"}",
"else",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"value",
")",
";",
"}",
"break",
";",
"case",
"'string'",
":",
"return",
"value",
";",
"default",
":",
"return",
"value",
";",
"}",
"}"
] |
transform some type of value
|
[
"transform",
"some",
"type",
"of",
"value"
] |
7c503d33b668434dd70cefefd6d2f2586c069bd2
|
https://github.com/elantion/handyJS/blob/7c503d33b668434dd70cefefd6d2f2586c069bd2/raw/browser/ajax.js#L57-L77
|
|
52,118
|
philipbordallo/eslint-config
|
src/utilities/createConfig.js
|
createConfig
|
async function createConfig(optionsArgs) {
const options = {
...DEFAULT_OPTIONS,
...optionsArgs,
};
const { rules, base } = options;
const config = {
...base,
rules: base.rules || {},
};
return Object.keys(config)
.reduce(async (collection, key) => {
const previous = await collection;
if (key === 'rules') {
const combinedRules = await combineRules(rules);
return {
...previous,
rules: {
...combinedRules,
...config.rules,
},
};
}
return {
...previous,
[key]: config[key],
};
}, Promise.resolve({}));
}
|
javascript
|
async function createConfig(optionsArgs) {
const options = {
...DEFAULT_OPTIONS,
...optionsArgs,
};
const { rules, base } = options;
const config = {
...base,
rules: base.rules || {},
};
return Object.keys(config)
.reduce(async (collection, key) => {
const previous = await collection;
if (key === 'rules') {
const combinedRules = await combineRules(rules);
return {
...previous,
rules: {
...combinedRules,
...config.rules,
},
};
}
return {
...previous,
[key]: config[key],
};
}, Promise.resolve({}));
}
|
[
"async",
"function",
"createConfig",
"(",
"optionsArgs",
")",
"{",
"const",
"options",
"=",
"{",
"...",
"DEFAULT_OPTIONS",
",",
"...",
"optionsArgs",
",",
"}",
";",
"const",
"{",
"rules",
",",
"base",
"}",
"=",
"options",
";",
"const",
"config",
"=",
"{",
"...",
"base",
",",
"rules",
":",
"base",
".",
"rules",
"||",
"{",
"}",
",",
"}",
";",
"return",
"Object",
".",
"keys",
"(",
"config",
")",
".",
"reduce",
"(",
"async",
"(",
"collection",
",",
"key",
")",
"=>",
"{",
"const",
"previous",
"=",
"await",
"collection",
";",
"if",
"(",
"key",
"===",
"'rules'",
")",
"{",
"const",
"combinedRules",
"=",
"await",
"combineRules",
"(",
"rules",
")",
";",
"return",
"{",
"...",
"previous",
",",
"rules",
":",
"{",
"...",
"combinedRules",
",",
"...",
"config",
".",
"rules",
",",
"}",
",",
"}",
";",
"}",
"return",
"{",
"...",
"previous",
",",
"[",
"key",
"]",
":",
"config",
"[",
"key",
"]",
",",
"}",
";",
"}",
",",
"Promise",
".",
"resolve",
"(",
"{",
"}",
")",
")",
";",
"}"
] |
Create an ESLint config given rules and a base config
@param {Object} optionsArgs
@returns {Promise} A promise to return a full config
|
[
"Create",
"an",
"ESLint",
"config",
"given",
"rules",
"and",
"a",
"base",
"config"
] |
a2f1bff442fdb8ee622f842f075fa10d555302a4
|
https://github.com/philipbordallo/eslint-config/blob/a2f1bff442fdb8ee622f842f075fa10d555302a4/src/utilities/createConfig.js#L14-L47
|
52,119
|
seanpk/simple-command
|
SimpleCommand.js
|
SimpleCommand
|
function SimpleCommand(exec, args, workdir) {
this.exec = /^win/.test(process.platform) ? findWindowsExec(exec) : exec;
this.args = args;
this.workdir = workdir;
this.setOptions();
this.commandLine = util.format('%s %s', this.exec, this.args.join(' '));
}
|
javascript
|
function SimpleCommand(exec, args, workdir) {
this.exec = /^win/.test(process.platform) ? findWindowsExec(exec) : exec;
this.args = args;
this.workdir = workdir;
this.setOptions();
this.commandLine = util.format('%s %s', this.exec, this.args.join(' '));
}
|
[
"function",
"SimpleCommand",
"(",
"exec",
",",
"args",
",",
"workdir",
")",
"{",
"this",
".",
"exec",
"=",
"/",
"^win",
"/",
".",
"test",
"(",
"process",
".",
"platform",
")",
"?",
"findWindowsExec",
"(",
"exec",
")",
":",
"exec",
";",
"this",
".",
"args",
"=",
"args",
";",
"this",
".",
"workdir",
"=",
"workdir",
";",
"this",
".",
"setOptions",
"(",
")",
";",
"this",
".",
"commandLine",
"=",
"util",
".",
"format",
"(",
"'%s %s'",
",",
"this",
".",
"exec",
",",
"this",
".",
"args",
".",
"join",
"(",
"' '",
")",
")",
";",
"}"
] |
SimpleCommand - Constructs a command to run.
@param {string} **exec** the program to run
@param {array} **args** arguments to pass to the program <br/>
__Note:__ the program is executed directly, i.e. no subshell is launched to process globs in args
@param {string} **workdir** working directory from which to run the command
|
[
"SimpleCommand",
"-",
"Constructs",
"a",
"command",
"to",
"run",
"."
] |
d250b9a9b650d5779c9ed1fbc68d9e17d10d3c87
|
https://github.com/seanpk/simple-command/blob/d250b9a9b650d5779c9ed1fbc68d9e17d10d3c87/SimpleCommand.js#L18-L24
|
52,120
|
vamship/wysknd-test
|
lib/fs.js
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no folders specified to create');
}
items.forEach(function(item) {
try {
_fs.mkdirSync(item);
} catch (e) {
// Eat the exception.
}
});
}
|
javascript
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no folders specified to create');
}
items.forEach(function(item) {
try {
_fs.mkdirSync(item);
} catch (e) {
// Eat the exception.
}
});
}
|
[
"function",
"(",
")",
"{",
"var",
"items",
"=",
"_utils",
".",
"getArgArray",
"(",
"arguments",
")",
";",
"if",
"(",
"items",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'no folders specified to create'",
")",
";",
"}",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"try",
"{",
"_fs",
".",
"mkdirSync",
"(",
"item",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Eat the exception.",
"}",
"}",
")",
";",
"}"
] |
Creates all of the folders specified in the array.
|
[
"Creates",
"all",
"of",
"the",
"folders",
"specified",
"in",
"the",
"array",
"."
] |
b7791c42f1c1b36be7738e2c6d24748360634003
|
https://github.com/vamship/wysknd-test/blob/b7791c42f1c1b36be7738e2c6d24748360634003/lib/fs.js#L11-L23
|
|
52,121
|
vamship/wysknd-test
|
lib/fs.js
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no files specified to create');
}
items.forEach(function(item) {
var contents;
var linkTarget;
var filePath;
if (typeof item === 'object') {
filePath = item.path;
contents = item.contents || '';
linkTarget = item.linkTo;
} else if (typeof item === 'string') {
filePath = item;
contents = '';
}
if (typeof filePath !== 'string' || filePath.length === 0) {
throw new Error('file path not specified');
}
contents = contents || '';
try {
if (!!linkTarget) {
_fs.symlinkSync(linkTarget, filePath);
} else {
_fs.writeFileSync(filePath, contents);
}
} catch (e) {
// Eat the exception.
}
});
}
|
javascript
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no files specified to create');
}
items.forEach(function(item) {
var contents;
var linkTarget;
var filePath;
if (typeof item === 'object') {
filePath = item.path;
contents = item.contents || '';
linkTarget = item.linkTo;
} else if (typeof item === 'string') {
filePath = item;
contents = '';
}
if (typeof filePath !== 'string' || filePath.length === 0) {
throw new Error('file path not specified');
}
contents = contents || '';
try {
if (!!linkTarget) {
_fs.symlinkSync(linkTarget, filePath);
} else {
_fs.writeFileSync(filePath, contents);
}
} catch (e) {
// Eat the exception.
}
});
}
|
[
"function",
"(",
")",
"{",
"var",
"items",
"=",
"_utils",
".",
"getArgArray",
"(",
"arguments",
")",
";",
"if",
"(",
"items",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'no files specified to create'",
")",
";",
"}",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"contents",
";",
"var",
"linkTarget",
";",
"var",
"filePath",
";",
"if",
"(",
"typeof",
"item",
"===",
"'object'",
")",
"{",
"filePath",
"=",
"item",
".",
"path",
";",
"contents",
"=",
"item",
".",
"contents",
"||",
"''",
";",
"linkTarget",
"=",
"item",
".",
"linkTo",
";",
"}",
"else",
"if",
"(",
"typeof",
"item",
"===",
"'string'",
")",
"{",
"filePath",
"=",
"item",
";",
"contents",
"=",
"''",
";",
"}",
"if",
"(",
"typeof",
"filePath",
"!==",
"'string'",
"||",
"filePath",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'file path not specified'",
")",
";",
"}",
"contents",
"=",
"contents",
"||",
"''",
";",
"try",
"{",
"if",
"(",
"!",
"!",
"linkTarget",
")",
"{",
"_fs",
".",
"symlinkSync",
"(",
"linkTarget",
",",
"filePath",
")",
";",
"}",
"else",
"{",
"_fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"contents",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"// Eat the exception.",
"}",
"}",
")",
";",
"}"
] |
Creates all of the files specified in the array.
|
[
"Creates",
"all",
"of",
"the",
"files",
"specified",
"in",
"the",
"array",
"."
] |
b7791c42f1c1b36be7738e2c6d24748360634003
|
https://github.com/vamship/wysknd-test/blob/b7791c42f1c1b36be7738e2c6d24748360634003/lib/fs.js#L28-L60
|
|
52,122
|
vamship/wysknd-test
|
lib/fs.js
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no files specified to clean up');
}
items.forEach(function(item) {
try {
var path = (typeof item === 'string') ? item : item.path;
_fs.unlinkSync(path);
} catch (e) {
// Eat the exception.
}
});
}
|
javascript
|
function() {
var items = _utils.getArgArray(arguments);
if (items.length === 0) {
throw new Error('no files specified to clean up');
}
items.forEach(function(item) {
try {
var path = (typeof item === 'string') ? item : item.path;
_fs.unlinkSync(path);
} catch (e) {
// Eat the exception.
}
});
}
|
[
"function",
"(",
")",
"{",
"var",
"items",
"=",
"_utils",
".",
"getArgArray",
"(",
"arguments",
")",
";",
"if",
"(",
"items",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'no files specified to clean up'",
")",
";",
"}",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"try",
"{",
"var",
"path",
"=",
"(",
"typeof",
"item",
"===",
"'string'",
")",
"?",
"item",
":",
"item",
".",
"path",
";",
"_fs",
".",
"unlinkSync",
"(",
"path",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Eat the exception.",
"}",
"}",
")",
";",
"}"
] |
Cleans up all of the files specified in the array. If the file
does not exist, the resultant error will be ignored.
|
[
"Cleans",
"up",
"all",
"of",
"the",
"files",
"specified",
"in",
"the",
"array",
".",
"If",
"the",
"file",
"does",
"not",
"exist",
"the",
"resultant",
"error",
"will",
"be",
"ignored",
"."
] |
b7791c42f1c1b36be7738e2c6d24748360634003
|
https://github.com/vamship/wysknd-test/blob/b7791c42f1c1b36be7738e2c6d24748360634003/lib/fs.js#L84-L97
|
|
52,123
|
jonasfj/time-chunked-stream
|
index.js
|
function(options) {
// Ensure an instance is created
if (!(this instanceof TimeChunkedStream)) {
return new TimeChunkedStream(options);
}
// Always decode strings
options.decodeStrings = true;
// Initialize base class
Transform.call(this, options);
// Create internal buffer
this._buffer = new BufferBuilder();
this._timeout = options.timeout;
this._timer = null;
}
|
javascript
|
function(options) {
// Ensure an instance is created
if (!(this instanceof TimeChunkedStream)) {
return new TimeChunkedStream(options);
}
// Always decode strings
options.decodeStrings = true;
// Initialize base class
Transform.call(this, options);
// Create internal buffer
this._buffer = new BufferBuilder();
this._timeout = options.timeout;
this._timer = null;
}
|
[
"function",
"(",
"options",
")",
"{",
"// Ensure an instance is created",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"TimeChunkedStream",
")",
")",
"{",
"return",
"new",
"TimeChunkedStream",
"(",
"options",
")",
";",
"}",
"// Always decode strings",
"options",
".",
"decodeStrings",
"=",
"true",
";",
"// Initialize base class",
"Transform",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"// Create internal buffer",
"this",
".",
"_buffer",
"=",
"new",
"BufferBuilder",
"(",
")",
";",
"this",
".",
"_timeout",
"=",
"options",
".",
"timeout",
";",
"this",
".",
"_timer",
"=",
"null",
";",
"}"
] |
Construct a new TimeChunkedStream, that will buffer data for
`options.timeout` milliseconds
|
[
"Construct",
"a",
"new",
"TimeChunkedStream",
"that",
"will",
"buffer",
"data",
"for",
"options",
".",
"timeout",
"milliseconds"
] |
06a4378a7e133f495403f96b63cd32a3289baf5a
|
https://github.com/jonasfj/time-chunked-stream/blob/06a4378a7e133f495403f96b63cd32a3289baf5a/index.js#L32-L48
|
|
52,124
|
vincentmac/yeoman-bootstrap
|
install.js
|
linkBootstrap
|
function linkBootstrap() {
fs.symlink(bootstrap, path.resolve(yeoman, 'bootstrap-less'), 'dir', function(err) {
if (err) return console.log('symlink error:', err);
return console.log('Successfully installed yeoman-bootstrap in', bootstrap,
' and created a symlink in', yeoman);
});
}
|
javascript
|
function linkBootstrap() {
fs.symlink(bootstrap, path.resolve(yeoman, 'bootstrap-less'), 'dir', function(err) {
if (err) return console.log('symlink error:', err);
return console.log('Successfully installed yeoman-bootstrap in', bootstrap,
' and created a symlink in', yeoman);
});
}
|
[
"function",
"linkBootstrap",
"(",
")",
"{",
"fs",
".",
"symlink",
"(",
"bootstrap",
",",
"path",
".",
"resolve",
"(",
"yeoman",
",",
"'bootstrap-less'",
")",
",",
"'dir'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"console",
".",
"log",
"(",
"'symlink error:'",
",",
"err",
")",
";",
"return",
"console",
".",
"log",
"(",
"'Successfully installed yeoman-bootstrap in'",
",",
"bootstrap",
",",
"' and created a symlink in'",
",",
"yeoman",
")",
";",
"}",
")",
";",
"}"
] |
Create new symlink to the bootstrap generator
|
[
"Create",
"new",
"symlink",
"to",
"the",
"bootstrap",
"generator"
] |
b510ebe30244fdcf957e11fd2197995a3ab71bdc
|
https://github.com/vincentmac/yeoman-bootstrap/blob/b510ebe30244fdcf957e11fd2197995a3ab71bdc/install.js#L39-L45
|
52,125
|
byron-dupreez/aws-stream-consumer-core
|
settings.js
|
toPropertyNamesArray
|
function toPropertyNamesArray(propertyNamesString, separator) {
return propertyNamesString.split(separator || PROPERTY_NAME_SEPARATOR).map(s => trim(s)).filter(s => !!s);
}
|
javascript
|
function toPropertyNamesArray(propertyNamesString, separator) {
return propertyNamesString.split(separator || PROPERTY_NAME_SEPARATOR).map(s => trim(s)).filter(s => !!s);
}
|
[
"function",
"toPropertyNamesArray",
"(",
"propertyNamesString",
",",
"separator",
")",
"{",
"return",
"propertyNamesString",
".",
"split",
"(",
"separator",
"||",
"PROPERTY_NAME_SEPARATOR",
")",
".",
"map",
"(",
"s",
"=>",
"trim",
"(",
"s",
")",
")",
".",
"filter",
"(",
"s",
"=>",
"!",
"!",
"s",
")",
";",
"}"
] |
Converts the given property names string into an array of property names
@param {string} propertyNamesString - a string of property name(s) separated by the given separator
@param {string|undefined} [separator] - the separator to use to split the property names (defaults to PROPERTY_NAME_SEPARATOR if omitted)
@returns {Array.<string>} an array of property names (if any)
|
[
"Converts",
"the",
"given",
"property",
"names",
"string",
"into",
"an",
"array",
"of",
"property",
"names"
] |
9b256084297f80d373bcf483aaf68a9da176b3d7
|
https://github.com/byron-dupreez/aws-stream-consumer-core/blob/9b256084297f80d373bcf483aaf68a9da176b3d7/settings.js#L436-L438
|
52,126
|
redisjs/jsr-store
|
lib/command/list.js
|
linsert
|
function linsert(key, beforeAfter, pivot, value, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
return val.linsert(beforeAfter, pivot, value);
}
|
javascript
|
function linsert(key, beforeAfter, pivot, value, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
return val.linsert(beforeAfter, pivot, value);
}
|
[
"function",
"linsert",
"(",
"key",
",",
"beforeAfter",
",",
"pivot",
",",
"value",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"0",
";",
"return",
"val",
".",
"linsert",
"(",
"beforeAfter",
",",
"pivot",
",",
"value",
")",
";",
"}"
] |
Inserts value in the list stored at key either before
or after the reference value pivot.
|
[
"Inserts",
"value",
"in",
"the",
"list",
"stored",
"at",
"key",
"either",
"before",
"or",
"after",
"the",
"reference",
"value",
"pivot",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L24-L28
|
52,127
|
redisjs/jsr-store
|
lib/command/list.js
|
lindex
|
function lindex(key, index, req) {
var val = this.getKey(key, req);
if(!val) return null;
return val.lindex(index);
}
|
javascript
|
function lindex(key, index, req) {
var val = this.getKey(key, req);
if(!val) return null;
return val.lindex(index);
}
|
[
"function",
"lindex",
"(",
"key",
",",
"index",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"!",
"val",
")",
"return",
"null",
";",
"return",
"val",
".",
"lindex",
"(",
"index",
")",
";",
"}"
] |
Returns the list element stored at index.
|
[
"Returns",
"the",
"list",
"element",
"stored",
"at",
"index",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L33-L37
|
52,128
|
redisjs/jsr-store
|
lib/command/list.js
|
lpush
|
function lpush(key /*value-1, value-N, req*/) {
var val = this.getKey(key, req)
, args = slice.call(arguments, 1)
, req;
if(typeof args[args.length - 1] === 'object') {
req = args.pop();
}
if(val === undefined) {
val = new List();
this.setKey(key, val, undefined, undefined, undefined, req);
}
return val.lpush(args);
}
|
javascript
|
function lpush(key /*value-1, value-N, req*/) {
var val = this.getKey(key, req)
, args = slice.call(arguments, 1)
, req;
if(typeof args[args.length - 1] === 'object') {
req = args.pop();
}
if(val === undefined) {
val = new List();
this.setKey(key, val, undefined, undefined, undefined, req);
}
return val.lpush(args);
}
|
[
"function",
"lpush",
"(",
"key",
"/*value-1, value-N, req*/",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
",",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
",",
"req",
";",
"if",
"(",
"typeof",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
"===",
"'object'",
")",
"{",
"req",
"=",
"args",
".",
"pop",
"(",
")",
";",
"}",
"if",
"(",
"val",
"===",
"undefined",
")",
"{",
"val",
"=",
"new",
"List",
"(",
")",
";",
"this",
".",
"setKey",
"(",
"key",
",",
"val",
",",
"undefined",
",",
"undefined",
",",
"undefined",
",",
"req",
")",
";",
"}",
"return",
"val",
".",
"lpush",
"(",
"args",
")",
";",
"}"
] |
Insert all the specified values at the head of the list stored at key.
|
[
"Insert",
"all",
"the",
"specified",
"values",
"at",
"the",
"head",
"of",
"the",
"list",
"stored",
"at",
"key",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L42-L54
|
52,129
|
redisjs/jsr-store
|
lib/command/list.js
|
lpushx
|
function lpushx(key, value, req) {
var val = this.getKey(key, req);
if(val === undefined) {
return 0;
}
return val.lpush([value]);
}
|
javascript
|
function lpushx(key, value, req) {
var val = this.getKey(key, req);
if(val === undefined) {
return 0;
}
return val.lpush([value]);
}
|
[
"function",
"lpushx",
"(",
"key",
",",
"value",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"{",
"return",
"0",
";",
"}",
"return",
"val",
".",
"lpush",
"(",
"[",
"value",
"]",
")",
";",
"}"
] |
Insert values at the head of the list stored at key
only if key exists.
|
[
"Insert",
"values",
"at",
"the",
"head",
"of",
"the",
"list",
"stored",
"at",
"key",
"only",
"if",
"key",
"exists",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L77-L83
|
52,130
|
redisjs/jsr-store
|
lib/command/list.js
|
rpushx
|
function rpushx(key, value, req) {
var val = this.getKey(key, req);
if(val === undefined) {
return 0;
}
return val.rpush([value]);
}
|
javascript
|
function rpushx(key, value, req) {
var val = this.getKey(key, req);
if(val === undefined) {
return 0;
}
return val.rpush([value]);
}
|
[
"function",
"rpushx",
"(",
"key",
",",
"value",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"{",
"return",
"0",
";",
"}",
"return",
"val",
".",
"rpush",
"(",
"[",
"value",
"]",
")",
";",
"}"
] |
Insert values at the tail of the list stored at key
only if key exists.
|
[
"Insert",
"values",
"at",
"the",
"tail",
"of",
"the",
"list",
"stored",
"at",
"key",
"only",
"if",
"key",
"exists",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L89-L95
|
52,131
|
redisjs/jsr-store
|
lib/command/list.js
|
lpop
|
function lpop(key, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
var element = val.lpop();
if(val.llen() === 0) {
this.delKey(key, req);
}
return element;
}
|
javascript
|
function lpop(key, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
var element = val.lpop();
if(val.llen() === 0) {
this.delKey(key, req);
}
return element;
}
|
[
"function",
"lpop",
"(",
"key",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"null",
";",
"var",
"element",
"=",
"val",
".",
"lpop",
"(",
")",
";",
"if",
"(",
"val",
".",
"llen",
"(",
")",
"===",
"0",
")",
"{",
"this",
".",
"delKey",
"(",
"key",
",",
"req",
")",
";",
"}",
"return",
"element",
";",
"}"
] |
Removes and returns the first element of the list stored at key.
|
[
"Removes",
"and",
"returns",
"the",
"first",
"element",
"of",
"the",
"list",
"stored",
"at",
"key",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L100-L108
|
52,132
|
redisjs/jsr-store
|
lib/command/list.js
|
lrem
|
function lrem(key, count, value, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
var deleted = val.lrem(count, value);
if(val.llen() === 0) {
this.delKey(key, req);
}
return deleted;
}
|
javascript
|
function lrem(key, count, value, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
var deleted = val.lrem(count, value);
if(val.llen() === 0) {
this.delKey(key, req);
}
return deleted;
}
|
[
"function",
"lrem",
"(",
"key",
",",
"count",
",",
"value",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"0",
";",
"var",
"deleted",
"=",
"val",
".",
"lrem",
"(",
"count",
",",
"value",
")",
";",
"if",
"(",
"val",
".",
"llen",
"(",
")",
"===",
"0",
")",
"{",
"this",
".",
"delKey",
"(",
"key",
",",
"req",
")",
";",
"}",
"return",
"deleted",
";",
"}"
] |
Removes the first count occurrences of elements equal to value
from the list stored at key.
|
[
"Removes",
"the",
"first",
"count",
"occurrences",
"of",
"elements",
"equal",
"to",
"value",
"from",
"the",
"list",
"stored",
"at",
"key",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L127-L135
|
52,133
|
redisjs/jsr-store
|
lib/command/list.js
|
ltrim
|
function ltrim(key, start, stop, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
val.ltrim(start, stop);
if(val.llen() === 0) {
this.delKey(key, req);
}
return OK;
}
|
javascript
|
function ltrim(key, start, stop, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
val.ltrim(start, stop);
if(val.llen() === 0) {
this.delKey(key, req);
}
return OK;
}
|
[
"function",
"ltrim",
"(",
"key",
",",
"start",
",",
"stop",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"null",
";",
"val",
".",
"ltrim",
"(",
"start",
",",
"stop",
")",
";",
"if",
"(",
"val",
".",
"llen",
"(",
")",
"===",
"0",
")",
"{",
"this",
".",
"delKey",
"(",
"key",
",",
"req",
")",
";",
"}",
"return",
"OK",
";",
"}"
] |
Trim an existing list so that it will contain only the specified
range of elements.
|
[
"Trim",
"an",
"existing",
"list",
"so",
"that",
"it",
"will",
"contain",
"only",
"the",
"specified",
"range",
"of",
"elements",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L141-L149
|
52,134
|
redisjs/jsr-store
|
lib/command/list.js
|
lrange
|
function lrange(key, start, stop, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
return val.lrange(start, stop);
}
|
javascript
|
function lrange(key, start, stop, req) {
var val = this.getKey(key, req);
if(val === undefined) return null;
return val.lrange(start, stop);
}
|
[
"function",
"lrange",
"(",
"key",
",",
"start",
",",
"stop",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"null",
";",
"return",
"val",
".",
"lrange",
"(",
"start",
",",
"stop",
")",
";",
"}"
] |
Returns the specified elements of the list stored at key.
|
[
"Returns",
"the",
"specified",
"elements",
"of",
"the",
"list",
"stored",
"at",
"key",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L154-L158
|
52,135
|
redisjs/jsr-store
|
lib/command/list.js
|
llen
|
function llen(key, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
return val.llen();
}
|
javascript
|
function llen(key, req) {
var val = this.getKey(key, req);
if(val === undefined) return 0;
return val.llen();
}
|
[
"function",
"llen",
"(",
"key",
",",
"req",
")",
"{",
"var",
"val",
"=",
"this",
".",
"getKey",
"(",
"key",
",",
"req",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"0",
";",
"return",
"val",
".",
"llen",
"(",
")",
";",
"}"
] |
Returns the length of the list stored at key.
|
[
"Returns",
"the",
"length",
"of",
"the",
"list",
"stored",
"at",
"key",
"."
] |
b2b5c5b0347819f8a388b5d67e121ee8d73f328c
|
https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/command/list.js#L163-L167
|
52,136
|
rabchev/passport-oauth-wrap
|
example/index.js
|
processToken
|
function processToken(token, done) {
var user = _.find(users, function (item) {
return item.username === token[claims.username];
});
if (!user) {
user = {
id : token[claims.id] || currId++,
username : token[claims.username],
email : token[claims.email],
firstName : token[claims.firstName],
lastName : token[claims.lastName]
};
var roles = token[claims.role];
if (!roles) {
roles = ["guest"];
} else if (!(roles instanceof Array)) {
roles = [roles];
}
user.roles = roles;
users.push(user);
}
done(null, user);
}
|
javascript
|
function processToken(token, done) {
var user = _.find(users, function (item) {
return item.username === token[claims.username];
});
if (!user) {
user = {
id : token[claims.id] || currId++,
username : token[claims.username],
email : token[claims.email],
firstName : token[claims.firstName],
lastName : token[claims.lastName]
};
var roles = token[claims.role];
if (!roles) {
roles = ["guest"];
} else if (!(roles instanceof Array)) {
roles = [roles];
}
user.roles = roles;
users.push(user);
}
done(null, user);
}
|
[
"function",
"processToken",
"(",
"token",
",",
"done",
")",
"{",
"var",
"user",
"=",
"_",
".",
"find",
"(",
"users",
",",
"function",
"(",
"item",
")",
"{",
"return",
"item",
".",
"username",
"===",
"token",
"[",
"claims",
".",
"username",
"]",
";",
"}",
")",
";",
"if",
"(",
"!",
"user",
")",
"{",
"user",
"=",
"{",
"id",
":",
"token",
"[",
"claims",
".",
"id",
"]",
"||",
"currId",
"++",
",",
"username",
":",
"token",
"[",
"claims",
".",
"username",
"]",
",",
"email",
":",
"token",
"[",
"claims",
".",
"email",
"]",
",",
"firstName",
":",
"token",
"[",
"claims",
".",
"firstName",
"]",
",",
"lastName",
":",
"token",
"[",
"claims",
".",
"lastName",
"]",
"}",
";",
"var",
"roles",
"=",
"token",
"[",
"claims",
".",
"role",
"]",
";",
"if",
"(",
"!",
"roles",
")",
"{",
"roles",
"=",
"[",
"\"guest\"",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"roles",
"instanceof",
"Array",
")",
")",
"{",
"roles",
"=",
"[",
"roles",
"]",
";",
"}",
"user",
".",
"roles",
"=",
"roles",
";",
"users",
".",
"push",
"(",
"user",
")",
";",
"}",
"done",
"(",
"null",
",",
"user",
")",
";",
"}"
] |
We have to build and register the user with the supplied claims from the access token. The token could be either Simple Web Token or JSON Web Token by specification.
|
[
"We",
"have",
"to",
"build",
"and",
"register",
"the",
"user",
"with",
"the",
"supplied",
"claims",
"from",
"the",
"access",
"token",
".",
"The",
"token",
"could",
"be",
"either",
"Simple",
"Web",
"Token",
"or",
"JSON",
"Web",
"Token",
"by",
"specification",
"."
] |
7f23fe82b5614859b5024aa3317b7e07f2aecaa5
|
https://github.com/rabchev/passport-oauth-wrap/blob/7f23fe82b5614859b5024aa3317b7e07f2aecaa5/example/index.js#L39-L61
|
52,137
|
seriousManual/winston-splunkstorm
|
index.js
|
function (options) {
winston.Transport.call(this, options);
options = options || {};
var apiKey = options.apiKey;
var projectId = options.projectId;
var apiHostName = options.apiHostName;
var formatter = options.formatter || 'kvp';
if (!apiKey || !projectId || !apiHostName) {
throw new Error('apiKey, projectId and apiHostName are neccessary');
}
this._storm = new SplunkStorm({
apiKey: apiKey,
projectId: projectId,
apiHostName: apiHostName,
formatter: formatter
});
this._sourceType = options.sourceType || 'syslog';
this._source = options.source || '';
this._host = options.host || os.hostname();
this._options = options;
}
|
javascript
|
function (options) {
winston.Transport.call(this, options);
options = options || {};
var apiKey = options.apiKey;
var projectId = options.projectId;
var apiHostName = options.apiHostName;
var formatter = options.formatter || 'kvp';
if (!apiKey || !projectId || !apiHostName) {
throw new Error('apiKey, projectId and apiHostName are neccessary');
}
this._storm = new SplunkStorm({
apiKey: apiKey,
projectId: projectId,
apiHostName: apiHostName,
formatter: formatter
});
this._sourceType = options.sourceType || 'syslog';
this._source = options.source || '';
this._host = options.host || os.hostname();
this._options = options;
}
|
[
"function",
"(",
"options",
")",
"{",
"winston",
".",
"Transport",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"apiKey",
"=",
"options",
".",
"apiKey",
";",
"var",
"projectId",
"=",
"options",
".",
"projectId",
";",
"var",
"apiHostName",
"=",
"options",
".",
"apiHostName",
";",
"var",
"formatter",
"=",
"options",
".",
"formatter",
"||",
"'kvp'",
";",
"if",
"(",
"!",
"apiKey",
"||",
"!",
"projectId",
"||",
"!",
"apiHostName",
")",
"{",
"throw",
"new",
"Error",
"(",
"'apiKey, projectId and apiHostName are neccessary'",
")",
";",
"}",
"this",
".",
"_storm",
"=",
"new",
"SplunkStorm",
"(",
"{",
"apiKey",
":",
"apiKey",
",",
"projectId",
":",
"projectId",
",",
"apiHostName",
":",
"apiHostName",
",",
"formatter",
":",
"formatter",
"}",
")",
";",
"this",
".",
"_sourceType",
"=",
"options",
".",
"sourceType",
"||",
"'syslog'",
";",
"this",
".",
"_source",
"=",
"options",
".",
"source",
"||",
"''",
";",
"this",
".",
"_host",
"=",
"options",
".",
"host",
"||",
"os",
".",
"hostname",
"(",
")",
";",
"this",
".",
"_options",
"=",
"options",
";",
"}"
] |
Constructor function for the Splunkstorm constructor
@param options
@constructor
|
[
"Constructor",
"function",
"for",
"the",
"Splunkstorm",
"constructor"
] |
9c37c83c60ad1ac8aee2ea400388805e188de4ed
|
https://github.com/seriousManual/winston-splunkstorm/blob/9c37c83c60ad1ac8aee2ea400388805e188de4ed/index.js#L15-L40
|
|
52,138
|
tolokoban/ToloFrameWork
|
lib/tolojson.js
|
stringify
|
function stringify(js, indent, indentUnit) {
if (typeof indent === 'undefined') indent = '';
if (typeof indentUnit === 'undefined') indentUnit = ' ';
var t = typeof js;
if (t === 'string') {
return JSON.stringify(js);
}
if (t === 'number') {
return js;
}
if (t === 'boolean') {
return js ? "true" : "false";
}
var out = '', txt, small, lastIndent;
if (Array.isArray(js)) {
out = '[';
txt = JSON.stringify(js);
small = txt.length < 40;
if (!small) out += "\n" + indent;
js.forEach(
function(itm, idx) {
if (idx > 0) {
out += "," + (small ? " " : "\n" + indent);
}
out += stringify(itm, indent + indentUnit);
}
);
out += ']';
return out;
}
if (t === 'object') {
lastIndent = indent;
indent += indentUnit;
out = '{';
txt = JSON.stringify(js);
small = txt.length < 40;
if (!small) out += "\n" + indent;
var k, v, idx = 0;
for (k in js) {
v = js[k];
if (idx > 0) {
out += "," + (small ? " " : "\n" + indent);
}
out += JSON.stringify(k) + ": " + stringify(v, indent);
idx++;
}
out += (small ? "" : "\n" + lastIndent) + '}';
return out;
}
return '"<' + t + '>"';
}
|
javascript
|
function stringify(js, indent, indentUnit) {
if (typeof indent === 'undefined') indent = '';
if (typeof indentUnit === 'undefined') indentUnit = ' ';
var t = typeof js;
if (t === 'string') {
return JSON.stringify(js);
}
if (t === 'number') {
return js;
}
if (t === 'boolean') {
return js ? "true" : "false";
}
var out = '', txt, small, lastIndent;
if (Array.isArray(js)) {
out = '[';
txt = JSON.stringify(js);
small = txt.length < 40;
if (!small) out += "\n" + indent;
js.forEach(
function(itm, idx) {
if (idx > 0) {
out += "," + (small ? " " : "\n" + indent);
}
out += stringify(itm, indent + indentUnit);
}
);
out += ']';
return out;
}
if (t === 'object') {
lastIndent = indent;
indent += indentUnit;
out = '{';
txt = JSON.stringify(js);
small = txt.length < 40;
if (!small) out += "\n" + indent;
var k, v, idx = 0;
for (k in js) {
v = js[k];
if (idx > 0) {
out += "," + (small ? " " : "\n" + indent);
}
out += JSON.stringify(k) + ": " + stringify(v, indent);
idx++;
}
out += (small ? "" : "\n" + lastIndent) + '}';
return out;
}
return '"<' + t + '>"';
}
|
[
"function",
"stringify",
"(",
"js",
",",
"indent",
",",
"indentUnit",
")",
"{",
"if",
"(",
"typeof",
"indent",
"===",
"'undefined'",
")",
"indent",
"=",
"''",
";",
"if",
"(",
"typeof",
"indentUnit",
"===",
"'undefined'",
")",
"indentUnit",
"=",
"' '",
";",
"var",
"t",
"=",
"typeof",
"js",
";",
"if",
"(",
"t",
"===",
"'string'",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"js",
")",
";",
"}",
"if",
"(",
"t",
"===",
"'number'",
")",
"{",
"return",
"js",
";",
"}",
"if",
"(",
"t",
"===",
"'boolean'",
")",
"{",
"return",
"js",
"?",
"\"true\"",
":",
"\"false\"",
";",
"}",
"var",
"out",
"=",
"''",
",",
"txt",
",",
"small",
",",
"lastIndent",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"js",
")",
")",
"{",
"out",
"=",
"'['",
";",
"txt",
"=",
"JSON",
".",
"stringify",
"(",
"js",
")",
";",
"small",
"=",
"txt",
".",
"length",
"<",
"40",
";",
"if",
"(",
"!",
"small",
")",
"out",
"+=",
"\"\\n\"",
"+",
"indent",
";",
"js",
".",
"forEach",
"(",
"function",
"(",
"itm",
",",
"idx",
")",
"{",
"if",
"(",
"idx",
">",
"0",
")",
"{",
"out",
"+=",
"\",\"",
"+",
"(",
"small",
"?",
"\" \"",
":",
"\"\\n\"",
"+",
"indent",
")",
";",
"}",
"out",
"+=",
"stringify",
"(",
"itm",
",",
"indent",
"+",
"indentUnit",
")",
";",
"}",
")",
";",
"out",
"+=",
"']'",
";",
"return",
"out",
";",
"}",
"if",
"(",
"t",
"===",
"'object'",
")",
"{",
"lastIndent",
"=",
"indent",
";",
"indent",
"+=",
"indentUnit",
";",
"out",
"=",
"'{'",
";",
"txt",
"=",
"JSON",
".",
"stringify",
"(",
"js",
")",
";",
"small",
"=",
"txt",
".",
"length",
"<",
"40",
";",
"if",
"(",
"!",
"small",
")",
"out",
"+=",
"\"\\n\"",
"+",
"indent",
";",
"var",
"k",
",",
"v",
",",
"idx",
"=",
"0",
";",
"for",
"(",
"k",
"in",
"js",
")",
"{",
"v",
"=",
"js",
"[",
"k",
"]",
";",
"if",
"(",
"idx",
">",
"0",
")",
"{",
"out",
"+=",
"\",\"",
"+",
"(",
"small",
"?",
"\" \"",
":",
"\"\\n\"",
"+",
"indent",
")",
";",
"}",
"out",
"+=",
"JSON",
".",
"stringify",
"(",
"k",
")",
"+",
"\": \"",
"+",
"stringify",
"(",
"v",
",",
"indent",
")",
";",
"idx",
"++",
";",
"}",
"out",
"+=",
"(",
"small",
"?",
"\"\"",
":",
"\"\\n\"",
"+",
"lastIndent",
")",
"+",
"'}'",
";",
"return",
"out",
";",
"}",
"return",
"'\"<'",
"+",
"t",
"+",
"'>\"'",
";",
"}"
] |
ToloJSON can parse JSON with comments, and can stringify JSON with indentation and comments.
This is useful for configuration files.
|
[
"ToloJSON",
"can",
"parse",
"JSON",
"with",
"comments",
"and",
"can",
"stringify",
"JSON",
"with",
"indentation",
"and",
"comments",
".",
"This",
"is",
"useful",
"for",
"configuration",
"files",
"."
] |
730845a833a9660ebfdb60ad027ebaab5ac871b6
|
https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/tolojson.js#L6-L56
|
52,139
|
kt3k/cli-dispatch
|
index.js
|
main
|
function main (action, argv, options) {
options = options || {}
const cli = new CliDispatch(action, options.actions || 'actions', options.base || callersDir())
setImmediate(() => cli.dispatch(argv))
return cli
}
|
javascript
|
function main (action, argv, options) {
options = options || {}
const cli = new CliDispatch(action, options.actions || 'actions', options.base || callersDir())
setImmediate(() => cli.dispatch(argv))
return cli
}
|
[
"function",
"main",
"(",
"action",
",",
"argv",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"const",
"cli",
"=",
"new",
"CliDispatch",
"(",
"action",
",",
"options",
".",
"actions",
"||",
"'actions'",
",",
"options",
".",
"base",
"||",
"callersDir",
"(",
")",
")",
"setImmediate",
"(",
"(",
")",
"=>",
"cli",
".",
"dispatch",
"(",
"argv",
")",
")",
"return",
"cli",
"}"
] |
Dispatches the action by the given paramters.
@param {string} action The action name
@param {object} argv The parameters for the actions
@param {string} [options.actions] The action's directory (relative path)
@param {string} [options.base] The action's base directory (absolute path)
@return {CliDispatch}
|
[
"Dispatches",
"the",
"action",
"by",
"the",
"given",
"paramters",
"."
] |
26ff44ab019f49bf977f5113cf261129743efcef
|
https://github.com/kt3k/cli-dispatch/blob/26ff44ab019f49bf977f5113cf261129743efcef/index.js#L21-L28
|
52,140
|
kt3k/cli-dispatch
|
index.js
|
lookup
|
function lookup (action, options) {
options = options || {}
const cli = new CliDispatch(action, options.actions || 'actions', options.base || callersDir())
return cli.lookup()
}
|
javascript
|
function lookup (action, options) {
options = options || {}
const cli = new CliDispatch(action, options.actions || 'actions', options.base || callersDir())
return cli.lookup()
}
|
[
"function",
"lookup",
"(",
"action",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"const",
"cli",
"=",
"new",
"CliDispatch",
"(",
"action",
",",
"options",
".",
"actions",
"||",
"'actions'",
",",
"options",
".",
"base",
"||",
"callersDir",
"(",
")",
")",
"return",
"cli",
".",
"lookup",
"(",
")",
"}"
] |
Looks up the action by the given paramters.
@param {string} action The action name
@param {string} [options.actions] The action's directory (relative path)
@param {string} [options.base] The action's base directory (absolute path)
@return {CliDispatch}
|
[
"Looks",
"up",
"the",
"action",
"by",
"the",
"given",
"paramters",
"."
] |
26ff44ab019f49bf977f5113cf261129743efcef
|
https://github.com/kt3k/cli-dispatch/blob/26ff44ab019f49bf977f5113cf261129743efcef/index.js#L37-L42
|
52,141
|
kt3k/cli-dispatch
|
index.js
|
CliDispatch
|
function CliDispatch (action, dir, baseDir) {
this.action = action
this.dir = dir
this.baseDir = baseDir
}
|
javascript
|
function CliDispatch (action, dir, baseDir) {
this.action = action
this.dir = dir
this.baseDir = baseDir
}
|
[
"function",
"CliDispatch",
"(",
"action",
",",
"dir",
",",
"baseDir",
")",
"{",
"this",
".",
"action",
"=",
"action",
"this",
".",
"dir",
"=",
"dir",
"this",
".",
"baseDir",
"=",
"baseDir",
"}"
] |
CliDispatch internal class.
@param {string} action The action name
@param {string} dir The directory name (relative path)
@param {string} baseDir The base directory name (absolute path)
|
[
"CliDispatch",
"internal",
"class",
"."
] |
26ff44ab019f49bf977f5113cf261129743efcef
|
https://github.com/kt3k/cli-dispatch/blob/26ff44ab019f49bf977f5113cf261129743efcef/index.js#L50-L54
|
52,142
|
ibm-bluemix-mobile-services/bms-mca-oauth-sdk
|
lib/util/token-util.js
|
getCliendIdFromCert
|
function getCliendIdFromCert() {
var x509 = require('x509');
var certJson = x509.parseCert(fs.readFileSync(process.cwd()+Constant.CERTIFICATE_PATH).toString());
var cliendId = cert && cert.subject && cert.subject.commonName;
return clientId;
}
|
javascript
|
function getCliendIdFromCert() {
var x509 = require('x509');
var certJson = x509.parseCert(fs.readFileSync(process.cwd()+Constant.CERTIFICATE_PATH).toString());
var cliendId = cert && cert.subject && cert.subject.commonName;
return clientId;
}
|
[
"function",
"getCliendIdFromCert",
"(",
")",
"{",
"var",
"x509",
"=",
"require",
"(",
"'x509'",
")",
";",
"var",
"certJson",
"=",
"x509",
".",
"parseCert",
"(",
"fs",
".",
"readFileSync",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"Constant",
".",
"CERTIFICATE_PATH",
")",
".",
"toString",
"(",
")",
")",
";",
"var",
"cliendId",
"=",
"cert",
"&&",
"cert",
".",
"subject",
"&&",
"cert",
".",
"subject",
".",
"commonName",
";",
"return",
"clientId",
";",
"}"
] |
Parse the certificate, and return the clientId from the commonName field in subject.
@returns
|
[
"Parse",
"the",
"certificate",
"and",
"return",
"the",
"clientId",
"from",
"the",
"commonName",
"field",
"in",
"subject",
"."
] |
6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83
|
https://github.com/ibm-bluemix-mobile-services/bms-mca-oauth-sdk/blob/6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83/lib/util/token-util.js#L130-L136
|
52,143
|
ibm-bluemix-mobile-services/bms-mca-oauth-sdk
|
lib/util/token-util.js
|
verifyPermission
|
function verifyPermission(appId,uaaCredential) {
var deferred = Q.defer();
var cloudControllerUrl = process.env.cloudControllerUrl;
if (!cloudControllerUrl) {
var errMsg = "The system variable 'cloudControllerUrl' is missing.";
ibmlogger.getLogger().error(errMsg);
deferred.reject({code:Constant.MISSING_CLOUDCONTROLLERURL_ERROR,message:errMsg});
return;
}
if (cloudControllerUrl[cloudControllerUrl.length-1]!='/') {
cloudControllerUrl += '/';
}
cloudControllerUrl += 'v2/apps/'+appId+'/summary';
var requestOptions = {url: cloudControllerUrl,headers: {'Authorization': uaaCredential}};
request.get(requestOptions, function(error,response,body){
if (error || response.statusCode != 200) {
var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Access Url '"+requestUrl+"' failed";
ibmlogger.getLogger().error(errMsg);
return deferred.reject(false);
}
else {
return deferred.resolve(true);
}
});
return deferred.promise;
}
|
javascript
|
function verifyPermission(appId,uaaCredential) {
var deferred = Q.defer();
var cloudControllerUrl = process.env.cloudControllerUrl;
if (!cloudControllerUrl) {
var errMsg = "The system variable 'cloudControllerUrl' is missing.";
ibmlogger.getLogger().error(errMsg);
deferred.reject({code:Constant.MISSING_CLOUDCONTROLLERURL_ERROR,message:errMsg});
return;
}
if (cloudControllerUrl[cloudControllerUrl.length-1]!='/') {
cloudControllerUrl += '/';
}
cloudControllerUrl += 'v2/apps/'+appId+'/summary';
var requestOptions = {url: cloudControllerUrl,headers: {'Authorization': uaaCredential}};
request.get(requestOptions, function(error,response,body){
if (error || response.statusCode != 200) {
var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Access Url '"+requestUrl+"' failed";
ibmlogger.getLogger().error(errMsg);
return deferred.reject(false);
}
else {
return deferred.resolve(true);
}
});
return deferred.promise;
}
|
[
"function",
"verifyPermission",
"(",
"appId",
",",
"uaaCredential",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"cloudControllerUrl",
"=",
"process",
".",
"env",
".",
"cloudControllerUrl",
";",
"if",
"(",
"!",
"cloudControllerUrl",
")",
"{",
"var",
"errMsg",
"=",
"\"The system variable 'cloudControllerUrl' is missing.\"",
";",
"ibmlogger",
".",
"getLogger",
"(",
")",
".",
"error",
"(",
"errMsg",
")",
";",
"deferred",
".",
"reject",
"(",
"{",
"code",
":",
"Constant",
".",
"MISSING_CLOUDCONTROLLERURL_ERROR",
",",
"message",
":",
"errMsg",
"}",
")",
";",
"return",
";",
"}",
"if",
"(",
"cloudControllerUrl",
"[",
"cloudControllerUrl",
".",
"length",
"-",
"1",
"]",
"!=",
"'/'",
")",
"{",
"cloudControllerUrl",
"+=",
"'/'",
";",
"}",
"cloudControllerUrl",
"+=",
"'v2/apps/'",
"+",
"appId",
"+",
"'/summary'",
";",
"var",
"requestOptions",
"=",
"{",
"url",
":",
"cloudControllerUrl",
",",
"headers",
":",
"{",
"'Authorization'",
":",
"uaaCredential",
"}",
"}",
";",
"request",
".",
"get",
"(",
"requestOptions",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"error",
"||",
"response",
".",
"statusCode",
"!=",
"200",
")",
"{",
"var",
"errMsg",
"=",
"error",
"?",
"\"[\"",
"+",
"error",
"+",
"\"]\"",
":",
"\"[\"",
"+",
"response",
".",
"statusCode",
"+",
"\":\"",
"+",
"body",
"+",
"\"] Access Url '\"",
"+",
"requestUrl",
"+",
"\"' failed\"",
";",
"ibmlogger",
".",
"getLogger",
"(",
")",
".",
"error",
"(",
"errMsg",
")",
";",
"return",
"deferred",
".",
"reject",
"(",
"false",
")",
";",
"}",
"else",
"{",
"return",
"deferred",
".",
"resolve",
"(",
"true",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Check if the given uaa credential has permisstion to access the appid.
@param appId
@param uaaCredential
@returns
|
[
"Check",
"if",
"the",
"given",
"uaa",
"credential",
"has",
"permisstion",
"to",
"access",
"the",
"appid",
"."
] |
6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83
|
https://github.com/ibm-bluemix-mobile-services/bms-mca-oauth-sdk/blob/6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83/lib/util/token-util.js#L144-L174
|
52,144
|
ibm-bluemix-mobile-services/bms-mca-oauth-sdk
|
lib/util/token-util.js
|
getOAuthAccessToken
|
function getOAuthAccessToken(appId,clientId,imfCert,properties) {
var deferred = Q.defer();
var imfServiceUrl = process.env.imfServiceUrl;
var requestUrl = imfServiceUrl+"/authorization/v1/apps/"+appId+"/token";
var requestOptions = {url: requestUrl,headers: {'Authorization': 'IMFCert '+imfCert}, form:{'grant_type':'client_credentials','client_id':clientId,'properties':properties}};
request.post(requestOptions, function(error,response,body){
if (error || response.statusCode != 200) {
requestUrl = requestUrl ? requestUrl : "";
body = body ? body : "";
var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Generate IMF Token from '"+requestUrl+"' failed.";
ibmlogger.getLogger().error(errMsg);
return deferred.reject({code:Constant.TOKEN_GENERATE_ERROR,message:errMsg});
}
else {
var tokenJson = Util.getJson(body);
return deferred.resolve(tokenJson);
}
});
return deferred.promise;
}
|
javascript
|
function getOAuthAccessToken(appId,clientId,imfCert,properties) {
var deferred = Q.defer();
var imfServiceUrl = process.env.imfServiceUrl;
var requestUrl = imfServiceUrl+"/authorization/v1/apps/"+appId+"/token";
var requestOptions = {url: requestUrl,headers: {'Authorization': 'IMFCert '+imfCert}, form:{'grant_type':'client_credentials','client_id':clientId,'properties':properties}};
request.post(requestOptions, function(error,response,body){
if (error || response.statusCode != 200) {
requestUrl = requestUrl ? requestUrl : "";
body = body ? body : "";
var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Generate IMF Token from '"+requestUrl+"' failed.";
ibmlogger.getLogger().error(errMsg);
return deferred.reject({code:Constant.TOKEN_GENERATE_ERROR,message:errMsg});
}
else {
var tokenJson = Util.getJson(body);
return deferred.resolve(tokenJson);
}
});
return deferred.promise;
}
|
[
"function",
"getOAuthAccessToken",
"(",
"appId",
",",
"clientId",
",",
"imfCert",
",",
"properties",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"imfServiceUrl",
"=",
"process",
".",
"env",
".",
"imfServiceUrl",
";",
"var",
"requestUrl",
"=",
"imfServiceUrl",
"+",
"\"/authorization/v1/apps/\"",
"+",
"appId",
"+",
"\"/token\"",
";",
"var",
"requestOptions",
"=",
"{",
"url",
":",
"requestUrl",
",",
"headers",
":",
"{",
"'Authorization'",
":",
"'IMFCert '",
"+",
"imfCert",
"}",
",",
"form",
":",
"{",
"'grant_type'",
":",
"'client_credentials'",
",",
"'client_id'",
":",
"clientId",
",",
"'properties'",
":",
"properties",
"}",
"}",
";",
"request",
".",
"post",
"(",
"requestOptions",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"error",
"||",
"response",
".",
"statusCode",
"!=",
"200",
")",
"{",
"requestUrl",
"=",
"requestUrl",
"?",
"requestUrl",
":",
"\"\"",
";",
"body",
"=",
"body",
"?",
"body",
":",
"\"\"",
";",
"var",
"errMsg",
"=",
"error",
"?",
"\"[\"",
"+",
"error",
"+",
"\"]\"",
":",
"\"[\"",
"+",
"response",
".",
"statusCode",
"+",
"\":\"",
"+",
"body",
"+",
"\"] Generate IMF Token from '\"",
"+",
"requestUrl",
"+",
"\"' failed.\"",
";",
"ibmlogger",
".",
"getLogger",
"(",
")",
".",
"error",
"(",
"errMsg",
")",
";",
"return",
"deferred",
".",
"reject",
"(",
"{",
"code",
":",
"Constant",
".",
"TOKEN_GENERATE_ERROR",
",",
"message",
":",
"errMsg",
"}",
")",
";",
"}",
"else",
"{",
"var",
"tokenJson",
"=",
"Util",
".",
"getJson",
"(",
"body",
")",
";",
"return",
"deferred",
".",
"resolve",
"(",
"tokenJson",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Get the OAuth access token from IMF AZ service
@param appId
@param clientId
@param imfCert
@param properties
|
[
"Get",
"the",
"OAuth",
"access",
"token",
"from",
"IMF",
"AZ",
"service"
] |
6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83
|
https://github.com/ibm-bluemix-mobile-services/bms-mca-oauth-sdk/blob/6a23ab1353c64ba60d8d75d0b0d3d9eaf60bed83/lib/util/token-util.js#L183-L206
|
52,145
|
derdesign/protos
|
lib/command.js
|
CommandLine
|
function CommandLine(commands) {
this.keys = Object.keys(commands);
this.commands = commands;
this.args = process.argv.slice(2);
this.context = this.args[0] || null;
this.help = {
before: '',
after: ''
}
}
|
javascript
|
function CommandLine(commands) {
this.keys = Object.keys(commands);
this.commands = commands;
this.args = process.argv.slice(2);
this.context = this.args[0] || null;
this.help = {
before: '',
after: ''
}
}
|
[
"function",
"CommandLine",
"(",
"commands",
")",
"{",
"this",
".",
"keys",
"=",
"Object",
".",
"keys",
"(",
"commands",
")",
";",
"this",
".",
"commands",
"=",
"commands",
";",
"this",
".",
"args",
"=",
"process",
".",
"argv",
".",
"slice",
"(",
"2",
")",
";",
"this",
".",
"context",
"=",
"this",
".",
"args",
"[",
"0",
"]",
"||",
"null",
";",
"this",
".",
"help",
"=",
"{",
"before",
":",
"''",
",",
"after",
":",
"''",
"}",
"}"
] |
Command Line class
@private
@constructor
@class CommandLine
@param {object} commands Commands object to pass
|
[
"Command",
"Line",
"class"
] |
0b679b2a7581dfbb5d065fd4b0914436ef4ef2c9
|
https://github.com/derdesign/protos/blob/0b679b2a7581dfbb5d065fd4b0914436ef4ef2c9/lib/command.js#L19-L28
|
52,146
|
derdesign/protos
|
lib/command.js
|
padString
|
function padString(str, len) {
return str.split().concat(new Array(len-str.length)).join(' ');
}
|
javascript
|
function padString(str, len) {
return str.split().concat(new Array(len-str.length)).join(' ');
}
|
[
"function",
"padString",
"(",
"str",
",",
"len",
")",
"{",
"return",
"str",
".",
"split",
"(",
")",
".",
"concat",
"(",
"new",
"Array",
"(",
"len",
"-",
"str",
".",
"length",
")",
")",
".",
"join",
"(",
"' '",
")",
";",
"}"
] |
Pads a string a certain amount of characters
|
[
"Pads",
"a",
"string",
"a",
"certain",
"amount",
"of",
"characters"
] |
0b679b2a7581dfbb5d065fd4b0914436ef4ef2c9
|
https://github.com/derdesign/protos/blob/0b679b2a7581dfbb5d065fd4b0914436ef4ef2c9/lib/command.js#L227-L229
|
52,147
|
MakerCollider/node-red-contrib-smartnode-hook
|
html/scripts/highchart/modules/data.src.js
|
function () {
if (this.options.switchRowsAndColumns) {
this.columns = this.rowsToColumns(this.columns);
}
// Interpret the info about series and columns
this.getColumnDistribution();
// Interpret the values into right types
this.parseTypes();
// Handle columns if a handleColumns callback is given
if (this.parsed() !== false) {
// Complete if a complete callback is given
this.complete();
}
}
|
javascript
|
function () {
if (this.options.switchRowsAndColumns) {
this.columns = this.rowsToColumns(this.columns);
}
// Interpret the info about series and columns
this.getColumnDistribution();
// Interpret the values into right types
this.parseTypes();
// Handle columns if a handleColumns callback is given
if (this.parsed() !== false) {
// Complete if a complete callback is given
this.complete();
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"switchRowsAndColumns",
")",
"{",
"this",
".",
"columns",
"=",
"this",
".",
"rowsToColumns",
"(",
"this",
".",
"columns",
")",
";",
"}",
"// Interpret the info about series and columns",
"this",
".",
"getColumnDistribution",
"(",
")",
";",
"// Interpret the values into right types",
"this",
".",
"parseTypes",
"(",
")",
";",
"// Handle columns if a handleColumns callback is given",
"if",
"(",
"this",
".",
"parsed",
"(",
")",
"!==",
"false",
")",
"{",
"// Complete if a complete callback is given",
"this",
".",
"complete",
"(",
")",
";",
"}",
"}"
] |
When the data is parsed into columns, either by CSV, table, GS or direct input,
continue with other operations.
|
[
"When",
"the",
"data",
"is",
"parsed",
"into",
"columns",
"either",
"by",
"CSV",
"table",
"GS",
"or",
"direct",
"input",
"continue",
"with",
"other",
"operations",
"."
] |
245c267e832968bad880ca009929043e82c7bc25
|
https://github.com/MakerCollider/node-red-contrib-smartnode-hook/blob/245c267e832968bad880ca009929043e82c7bc25/html/scripts/highchart/modules/data.src.js#L153-L172
|
|
52,148
|
MakerCollider/node-red-contrib-smartnode-hook
|
html/scripts/highchart/modules/data.src.js
|
function (str, inside) {
if (typeof str === 'string') {
str = str.replace(/^\s+|\s+$/g, '');
// Clear white space insdie the string, like thousands separators
if (inside && /^[0-9\s]+$/.test(str)) {
str = str.replace(/\s/g, '');
}
if (this.decimalRegex) {
str = str.replace(this.decimalRegex, '$1.$2');
}
}
return str;
}
|
javascript
|
function (str, inside) {
if (typeof str === 'string') {
str = str.replace(/^\s+|\s+$/g, '');
// Clear white space insdie the string, like thousands separators
if (inside && /^[0-9\s]+$/.test(str)) {
str = str.replace(/\s/g, '');
}
if (this.decimalRegex) {
str = str.replace(this.decimalRegex, '$1.$2');
}
}
return str;
}
|
[
"function",
"(",
"str",
",",
"inside",
")",
"{",
"if",
"(",
"typeof",
"str",
"===",
"'string'",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"^\\s+|\\s+$",
"/",
"g",
",",
"''",
")",
";",
"// Clear white space insdie the string, like thousands separators",
"if",
"(",
"inside",
"&&",
"/",
"^[0-9\\s]+$",
"/",
".",
"test",
"(",
"str",
")",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\s",
"/",
"g",
",",
"''",
")",
";",
"}",
"if",
"(",
"this",
".",
"decimalRegex",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"this",
".",
"decimalRegex",
",",
"'$1.$2'",
")",
";",
"}",
"}",
"return",
"str",
";",
"}"
] |
Trim a string from whitespace
|
[
"Trim",
"a",
"string",
"from",
"whitespace"
] |
245c267e832968bad880ca009929043e82c7bc25
|
https://github.com/MakerCollider/node-red-contrib-smartnode-hook/blob/245c267e832968bad880ca009929043e82c7bc25/html/scripts/highchart/modules/data.src.js#L332-L346
|
|
52,149
|
gethuman/pancakes-angular
|
lib/ngapp/tap.track.js
|
doAction
|
function doAction() {
var now = (new Date()).getTime();
var diff = now - lastTapTime;
var isDiffElemSafeDelay = elem !== lastElemTapped && diff > 200;
var isSameElemSafeDelay = elem === lastElemTapped && diff > sameElemSafeDelay;
if (tapped && (isDiffElemSafeDelay || isSameElemSafeDelay)) {
lastElemTapped = elem;
lastTapTime = now;
safeApply(action, scope);
}
// reset tapped at end
tapped = false;
}
|
javascript
|
function doAction() {
var now = (new Date()).getTime();
var diff = now - lastTapTime;
var isDiffElemSafeDelay = elem !== lastElemTapped && diff > 200;
var isSameElemSafeDelay = elem === lastElemTapped && diff > sameElemSafeDelay;
if (tapped && (isDiffElemSafeDelay || isSameElemSafeDelay)) {
lastElemTapped = elem;
lastTapTime = now;
safeApply(action, scope);
}
// reset tapped at end
tapped = false;
}
|
[
"function",
"doAction",
"(",
")",
"{",
"var",
"now",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"var",
"diff",
"=",
"now",
"-",
"lastTapTime",
";",
"var",
"isDiffElemSafeDelay",
"=",
"elem",
"!==",
"lastElemTapped",
"&&",
"diff",
">",
"200",
";",
"var",
"isSameElemSafeDelay",
"=",
"elem",
"===",
"lastElemTapped",
"&&",
"diff",
">",
"sameElemSafeDelay",
";",
"if",
"(",
"tapped",
"&&",
"(",
"isDiffElemSafeDelay",
"||",
"isSameElemSafeDelay",
")",
")",
"{",
"lastElemTapped",
"=",
"elem",
";",
"lastTapTime",
"=",
"now",
";",
"safeApply",
"(",
"action",
",",
"scope",
")",
";",
"}",
"// reset tapped at end",
"tapped",
"=",
"false",
";",
"}"
] |
Attempt to do the action as long as tap not already in progress
|
[
"Attempt",
"to",
"do",
"the",
"action",
"as",
"long",
"as",
"tap",
"not",
"already",
"in",
"progress"
] |
9589b7ba09619843e271293088005c62ed23f355
|
https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/tap.track.js#L29-L43
|
52,150
|
pratishshr/sort-o
|
src/sorto.js
|
getComparator
|
function getComparator(sortOrder) {
if (typeof sortOrder === 'function') {
return sortOrder;
}
const comparators = {
[ASC]: ascendingSort,
[DESC]: descendingSort,
[ASC_LENGTH]: lengthSort,
[DESC_LENGTH]: lengthReverseSort
};
return comparators[sortOrder];
}
|
javascript
|
function getComparator(sortOrder) {
if (typeof sortOrder === 'function') {
return sortOrder;
}
const comparators = {
[ASC]: ascendingSort,
[DESC]: descendingSort,
[ASC_LENGTH]: lengthSort,
[DESC_LENGTH]: lengthReverseSort
};
return comparators[sortOrder];
}
|
[
"function",
"getComparator",
"(",
"sortOrder",
")",
"{",
"if",
"(",
"typeof",
"sortOrder",
"===",
"'function'",
")",
"{",
"return",
"sortOrder",
";",
"}",
"const",
"comparators",
"=",
"{",
"[",
"ASC",
"]",
":",
"ascendingSort",
",",
"[",
"DESC",
"]",
":",
"descendingSort",
",",
"[",
"ASC_LENGTH",
"]",
":",
"lengthSort",
",",
"[",
"DESC_LENGTH",
"]",
":",
"lengthReverseSort",
"}",
";",
"return",
"comparators",
"[",
"sortOrder",
"]",
";",
"}"
] |
Returns appropriate comparator as per the sort string.
If a function is supplied, it returns the function itself.
@param {String|Function} sortOrder
@returns {Function}
|
[
"Returns",
"appropriate",
"comparator",
"as",
"per",
"the",
"sort",
"string",
".",
"If",
"a",
"function",
"is",
"supplied",
"it",
"returns",
"the",
"function",
"itself",
"."
] |
5bd5d659f4ea518fd5705d5ab96e2694fb6ecfe6
|
https://github.com/pratishshr/sort-o/blob/5bd5d659f4ea518fd5705d5ab96e2694fb6ecfe6/src/sorto.js#L13-L26
|
52,151
|
ryanfitzer/comment-serializer
|
index.js
|
stripAndSerializeComment
|
function stripAndSerializeComment( lineNumber, sourceStr ) {
// Strip comment delimiter tokens
let stripped = sourceStr
.replace( patterns.commentBegin, '' )
.replace( patterns.commentEnd, '' )
.split( '\n' )
.map( line => line.replace( rCommentLinePrefix, '' ) );
// Determine the number of leading spaces to strip
const prefixSpaces = stripped.reduce( function ( accum, line ) {
if ( !accum.length && line.match( /\s*\S|\n/ ) ) {
accum = line.match( /\s*/ )[0];
}
return accum;
});
// Strip leading spaces
stripped = stripped.map( line => line.replace( prefixSpaces, '' ) );
// Get line number for first tag
const firstTagLineNumber = stripped.reduce( function ( accum, line, index ) {
if ( isNaN( accum ) && line.match( rTagName ) ) {
accum = index;
}
return accum;
}, undefined );
const comment = stripped.join( '\n' ).trim();
const tags = stripped.splice( firstTagLineNumber ).join( '\n' );
const preface = stripped.join( '\n' ).trim();
return {
preface,
content: comment,
tags: serializeTags( lineNumber + firstTagLineNumber, tags )
};
}
|
javascript
|
function stripAndSerializeComment( lineNumber, sourceStr ) {
// Strip comment delimiter tokens
let stripped = sourceStr
.replace( patterns.commentBegin, '' )
.replace( patterns.commentEnd, '' )
.split( '\n' )
.map( line => line.replace( rCommentLinePrefix, '' ) );
// Determine the number of leading spaces to strip
const prefixSpaces = stripped.reduce( function ( accum, line ) {
if ( !accum.length && line.match( /\s*\S|\n/ ) ) {
accum = line.match( /\s*/ )[0];
}
return accum;
});
// Strip leading spaces
stripped = stripped.map( line => line.replace( prefixSpaces, '' ) );
// Get line number for first tag
const firstTagLineNumber = stripped.reduce( function ( accum, line, index ) {
if ( isNaN( accum ) && line.match( rTagName ) ) {
accum = index;
}
return accum;
}, undefined );
const comment = stripped.join( '\n' ).trim();
const tags = stripped.splice( firstTagLineNumber ).join( '\n' );
const preface = stripped.join( '\n' ).trim();
return {
preface,
content: comment,
tags: serializeTags( lineNumber + firstTagLineNumber, tags )
};
}
|
[
"function",
"stripAndSerializeComment",
"(",
"lineNumber",
",",
"sourceStr",
")",
"{",
"// Strip comment delimiter tokens",
"let",
"stripped",
"=",
"sourceStr",
".",
"replace",
"(",
"patterns",
".",
"commentBegin",
",",
"''",
")",
".",
"replace",
"(",
"patterns",
".",
"commentEnd",
",",
"''",
")",
".",
"split",
"(",
"'\\n'",
")",
".",
"map",
"(",
"line",
"=>",
"line",
".",
"replace",
"(",
"rCommentLinePrefix",
",",
"''",
")",
")",
";",
"// Determine the number of leading spaces to strip",
"const",
"prefixSpaces",
"=",
"stripped",
".",
"reduce",
"(",
"function",
"(",
"accum",
",",
"line",
")",
"{",
"if",
"(",
"!",
"accum",
".",
"length",
"&&",
"line",
".",
"match",
"(",
"/",
"\\s*\\S|\\n",
"/",
")",
")",
"{",
"accum",
"=",
"line",
".",
"match",
"(",
"/",
"\\s*",
"/",
")",
"[",
"0",
"]",
";",
"}",
"return",
"accum",
";",
"}",
")",
";",
"// Strip leading spaces",
"stripped",
"=",
"stripped",
".",
"map",
"(",
"line",
"=>",
"line",
".",
"replace",
"(",
"prefixSpaces",
",",
"''",
")",
")",
";",
"// Get line number for first tag",
"const",
"firstTagLineNumber",
"=",
"stripped",
".",
"reduce",
"(",
"function",
"(",
"accum",
",",
"line",
",",
"index",
")",
"{",
"if",
"(",
"isNaN",
"(",
"accum",
")",
"&&",
"line",
".",
"match",
"(",
"rTagName",
")",
")",
"{",
"accum",
"=",
"index",
";",
"}",
"return",
"accum",
";",
"}",
",",
"undefined",
")",
";",
"const",
"comment",
"=",
"stripped",
".",
"join",
"(",
"'\\n'",
")",
".",
"trim",
"(",
")",
";",
"const",
"tags",
"=",
"stripped",
".",
"splice",
"(",
"firstTagLineNumber",
")",
".",
"join",
"(",
"'\\n'",
")",
";",
"const",
"preface",
"=",
"stripped",
".",
"join",
"(",
"'\\n'",
")",
".",
"trim",
"(",
")",
";",
"return",
"{",
"preface",
",",
"content",
":",
"comment",
",",
"tags",
":",
"serializeTags",
"(",
"lineNumber",
"+",
"firstTagLineNumber",
",",
"tags",
")",
"}",
";",
"}"
] |
Strip and serialize a comment into its various parts.
- comment: the comment block stripped delimiters and leading spaces.
- preface
- tags
@param {Number} lineNumber The comment's starting line number.
@param {String} sourceStr The comment's source.
@returns {Object}
|
[
"Strip",
"and",
"serialize",
"a",
"comment",
"into",
"its",
"various",
"parts",
"."
] |
73c2b961f54af42d357737b4f13c137269912549
|
https://github.com/ryanfitzer/comment-serializer/blob/73c2b961f54af42d357737b4f13c137269912549/index.js#L81-L123
|
52,152
|
ryanfitzer/comment-serializer
|
index.js
|
serializeTags
|
function serializeTags( lineNumber, tags ) {
return tags.split( /\n/ )
.reduce( function ( acc, line, index ) {
if ( !index || rTagName.test( line ) ) {
acc.push( `${line}\n` );
}
else {
acc[ acc.length - 1 ] += `${line}\n`;
}
return acc;
}, [] )
.map( function ( block ) {
const trimmed = block.trim();
const tag = block.match( rTagName )[0];
const result = {
line: lineNumber,
tag: tag.replace( patterns.tagPrefix, '' ),
value: trimmed.replace( tag, '' ).replace( rLeadSpaces, '' ),
valueParsed: [],
source: trimmed
};
lineNumber = lineNumber + getLinesLength( block );
return result;
})
.map( function ( tag ) {
const parser = parsers[ tag.tag ];
if ( parser ) {
try {
tag.valueParsed = parser( tag.value );
}
catch ( err ) {
tag.error = err;
}
}
return tag;
});
}
|
javascript
|
function serializeTags( lineNumber, tags ) {
return tags.split( /\n/ )
.reduce( function ( acc, line, index ) {
if ( !index || rTagName.test( line ) ) {
acc.push( `${line}\n` );
}
else {
acc[ acc.length - 1 ] += `${line}\n`;
}
return acc;
}, [] )
.map( function ( block ) {
const trimmed = block.trim();
const tag = block.match( rTagName )[0];
const result = {
line: lineNumber,
tag: tag.replace( patterns.tagPrefix, '' ),
value: trimmed.replace( tag, '' ).replace( rLeadSpaces, '' ),
valueParsed: [],
source: trimmed
};
lineNumber = lineNumber + getLinesLength( block );
return result;
})
.map( function ( tag ) {
const parser = parsers[ tag.tag ];
if ( parser ) {
try {
tag.valueParsed = parser( tag.value );
}
catch ( err ) {
tag.error = err;
}
}
return tag;
});
}
|
[
"function",
"serializeTags",
"(",
"lineNumber",
",",
"tags",
")",
"{",
"return",
"tags",
".",
"split",
"(",
"/",
"\\n",
"/",
")",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"line",
",",
"index",
")",
"{",
"if",
"(",
"!",
"index",
"||",
"rTagName",
".",
"test",
"(",
"line",
")",
")",
"{",
"acc",
".",
"push",
"(",
"`",
"${",
"line",
"}",
"\\n",
"`",
")",
";",
"}",
"else",
"{",
"acc",
"[",
"acc",
".",
"length",
"-",
"1",
"]",
"+=",
"`",
"${",
"line",
"}",
"\\n",
"`",
";",
"}",
"return",
"acc",
";",
"}",
",",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"block",
")",
"{",
"const",
"trimmed",
"=",
"block",
".",
"trim",
"(",
")",
";",
"const",
"tag",
"=",
"block",
".",
"match",
"(",
"rTagName",
")",
"[",
"0",
"]",
";",
"const",
"result",
"=",
"{",
"line",
":",
"lineNumber",
",",
"tag",
":",
"tag",
".",
"replace",
"(",
"patterns",
".",
"tagPrefix",
",",
"''",
")",
",",
"value",
":",
"trimmed",
".",
"replace",
"(",
"tag",
",",
"''",
")",
".",
"replace",
"(",
"rLeadSpaces",
",",
"''",
")",
",",
"valueParsed",
":",
"[",
"]",
",",
"source",
":",
"trimmed",
"}",
";",
"lineNumber",
"=",
"lineNumber",
"+",
"getLinesLength",
"(",
"block",
")",
";",
"return",
"result",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"tag",
")",
"{",
"const",
"parser",
"=",
"parsers",
"[",
"tag",
".",
"tag",
"]",
";",
"if",
"(",
"parser",
")",
"{",
"try",
"{",
"tag",
".",
"valueParsed",
"=",
"parser",
"(",
"tag",
".",
"value",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"tag",
".",
"error",
"=",
"err",
";",
"}",
"}",
"return",
"tag",
";",
"}",
")",
";",
"}"
] |
Takes a tags block and serializes it into individual tag objects.
@param {Number} lineNumber The tags block starting line number.
@param {String} tags The tags block.
@returns {Array}
|
[
"Takes",
"a",
"tags",
"block",
"and",
"serializes",
"it",
"into",
"individual",
"tag",
"objects",
"."
] |
73c2b961f54af42d357737b4f13c137269912549
|
https://github.com/ryanfitzer/comment-serializer/blob/73c2b961f54af42d357737b4f13c137269912549/index.js#L132-L182
|
52,153
|
iopa-io/iopa-test
|
src/stubServer.js
|
StubServer
|
function StubServer(app) {
_classCallCheck(this, StubServer);
this._app = app;
app.createServer = this.createServer_.bind(this, app.createServer || function () { throw new Error("no registered transport provider"); });
}
|
javascript
|
function StubServer(app) {
_classCallCheck(this, StubServer);
this._app = app;
app.createServer = this.createServer_.bind(this, app.createServer || function () { throw new Error("no registered transport provider"); });
}
|
[
"function",
"StubServer",
"(",
"app",
")",
"{",
"_classCallCheck",
"(",
"this",
",",
"StubServer",
")",
";",
"this",
".",
"_app",
"=",
"app",
";",
"app",
".",
"createServer",
"=",
"this",
".",
"createServer_",
".",
"bind",
"(",
"this",
",",
"app",
".",
"createServer",
"||",
"function",
"(",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"no registered transport provider\"",
")",
";",
"}",
")",
";",
"}"
] |
Representes Stub Server
@class StubServer
@param app IOPA AppBuilder App
@constructor
@public
|
[
"Representes",
"Stub",
"Server"
] |
1fac6ea54d4e0e83f4b1278897dfa9a4dc684543
|
https://github.com/iopa-io/iopa-test/blob/1fac6ea54d4e0e83f4b1278897dfa9a4dc684543/src/stubServer.js#L37-L43
|
52,154
|
Elao/validator-framework
|
src/validator.js
|
getValueAt
|
function getValueAt(dataObject, path)
{
if (_.isUndefined(dataObject)) {
return undefined;
}
if (!_.isString(path)) {
return dataObject;
}
var tokens = path.split('.');
var property = tokens[0];
var subpath = tokens.slice(1).join('.');
var data = dataObject[property];
if (tokens.length > 1 && !_.isUndefined(data))
{
return getValueAt(data, subpath);
} else {
return data;
}
}
|
javascript
|
function getValueAt(dataObject, path)
{
if (_.isUndefined(dataObject)) {
return undefined;
}
if (!_.isString(path)) {
return dataObject;
}
var tokens = path.split('.');
var property = tokens[0];
var subpath = tokens.slice(1).join('.');
var data = dataObject[property];
if (tokens.length > 1 && !_.isUndefined(data))
{
return getValueAt(data, subpath);
} else {
return data;
}
}
|
[
"function",
"getValueAt",
"(",
"dataObject",
",",
"path",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"dataObject",
")",
")",
"{",
"return",
"undefined",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"path",
")",
")",
"{",
"return",
"dataObject",
";",
"}",
"var",
"tokens",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"property",
"=",
"tokens",
"[",
"0",
"]",
";",
"var",
"subpath",
"=",
"tokens",
".",
"slice",
"(",
"1",
")",
".",
"join",
"(",
"'.'",
")",
";",
"var",
"data",
"=",
"dataObject",
"[",
"property",
"]",
";",
"if",
"(",
"tokens",
".",
"length",
">",
"1",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"data",
")",
")",
"{",
"return",
"getValueAt",
"(",
"data",
",",
"subpath",
")",
";",
"}",
"else",
"{",
"return",
"data",
";",
"}",
"}"
] |
Given a data object and a path, return the corresponding value
@param object data A data object
@param string path A value path with dot notation
@return mixed Return the value found at path or undefined if value doesn't exists
|
[
"Given",
"a",
"data",
"object",
"and",
"a",
"path",
"return",
"the",
"corresponding",
"value"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L38-L58
|
52,155
|
Elao/validator-framework
|
src/validator.js
|
matchGroups
|
function matchGroups(groupsConfig, wantedGroups)
{
var defaultGroups = ['default'];
var groups = _.map([groupsConfig, wantedGroups], function(grp) {
if (_.isUndefined(grp)) {
return defaultGroups;
} else if (_.isString(grp)) {
return [grp];
} else if (_.isArray(grp)) {
return grp;
}else if (_.isFunction(grp)) {
var r = grp();
if (_.isString(r)) {
return [r];
} else if (_.isArray(r)) {
return r;
}
}
return defaultGroups;
});
return _.intersection(groups[0], groups[1]).length > 0;
}
|
javascript
|
function matchGroups(groupsConfig, wantedGroups)
{
var defaultGroups = ['default'];
var groups = _.map([groupsConfig, wantedGroups], function(grp) {
if (_.isUndefined(grp)) {
return defaultGroups;
} else if (_.isString(grp)) {
return [grp];
} else if (_.isArray(grp)) {
return grp;
}else if (_.isFunction(grp)) {
var r = grp();
if (_.isString(r)) {
return [r];
} else if (_.isArray(r)) {
return r;
}
}
return defaultGroups;
});
return _.intersection(groups[0], groups[1]).length > 0;
}
|
[
"function",
"matchGroups",
"(",
"groupsConfig",
",",
"wantedGroups",
")",
"{",
"var",
"defaultGroups",
"=",
"[",
"'default'",
"]",
";",
"var",
"groups",
"=",
"_",
".",
"map",
"(",
"[",
"groupsConfig",
",",
"wantedGroups",
"]",
",",
"function",
"(",
"grp",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"grp",
")",
")",
"{",
"return",
"defaultGroups",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isString",
"(",
"grp",
")",
")",
"{",
"return",
"[",
"grp",
"]",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isArray",
"(",
"grp",
")",
")",
"{",
"return",
"grp",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isFunction",
"(",
"grp",
")",
")",
"{",
"var",
"r",
"=",
"grp",
"(",
")",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"r",
")",
")",
"{",
"return",
"[",
"r",
"]",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isArray",
"(",
"r",
")",
")",
"{",
"return",
"r",
";",
"}",
"}",
"return",
"defaultGroups",
";",
"}",
")",
";",
"return",
"_",
".",
"intersection",
"(",
"groups",
"[",
"0",
"]",
",",
"groups",
"[",
"1",
"]",
")",
".",
"length",
">",
"0",
";",
"}"
] |
Given 2 lists of groups, return true if the two groups lists share common groups and false otherwise
Return the default group if the group value is invalid
@param array groupsConfig The first groups list
@param array wantedGroups The second groups list
@return boolean true if groups lists match
|
[
"Given",
"2",
"lists",
"of",
"groups",
"return",
"true",
"if",
"the",
"two",
"groups",
"lists",
"share",
"common",
"groups",
"and",
"false",
"otherwise",
"Return",
"the",
"default",
"group",
"if",
"the",
"group",
"value",
"is",
"invalid"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L67-L88
|
52,156
|
Elao/validator-framework
|
src/validator.js
|
RulesConfigurationError
|
function RulesConfigurationError(message, path)
{
var self = new Error();
self.path = path;
self.message = "Rules configuration error : "+message+(path ? " at path : "+path : "");
self.name = 'RulesConfigurationError';
self.__proto__ = RulesConfigurationError.prototype;
return self;
}
|
javascript
|
function RulesConfigurationError(message, path)
{
var self = new Error();
self.path = path;
self.message = "Rules configuration error : "+message+(path ? " at path : "+path : "");
self.name = 'RulesConfigurationError';
self.__proto__ = RulesConfigurationError.prototype;
return self;
}
|
[
"function",
"RulesConfigurationError",
"(",
"message",
",",
"path",
")",
"{",
"var",
"self",
"=",
"new",
"Error",
"(",
")",
";",
"self",
".",
"path",
"=",
"path",
";",
"self",
".",
"message",
"=",
"\"Rules configuration error : \"",
"+",
"message",
"+",
"(",
"path",
"?",
"\" at path : \"",
"+",
"path",
":",
"\"\"",
")",
";",
"self",
".",
"name",
"=",
"'RulesConfigurationError'",
";",
"self",
".",
"__proto__",
"=",
"RulesConfigurationError",
".",
"prototype",
";",
"return",
"self",
";",
"}"
] |
Error class for invalid rules definition
@param string message The error message
@param string path The path of the invalid definition
|
[
"Error",
"class",
"for",
"invalid",
"rules",
"definition"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L95-L103
|
52,157
|
Elao/validator-framework
|
src/validator.js
|
function(path, fieldValue, errors, errorsContent)
{
var e = {};
var er = {};
if (_.isArray(errors) && errors.length > 0) {
er.errors = errors;
}
if (_.isArray(errorsContent) && errorsContent.length > 0) {
er.content = errorsContent;
}
var self = new Error();
self.__proto__ = FieldValidatorError.prototype;
self.message = er;
self.name = 'FieldValidatorError';
self.path = path;
self.fieldValue = fieldValue;
self.errors = errors || [];
self.errorsContent = errorsContent || [];
return self;
}
|
javascript
|
function(path, fieldValue, errors, errorsContent)
{
var e = {};
var er = {};
if (_.isArray(errors) && errors.length > 0) {
er.errors = errors;
}
if (_.isArray(errorsContent) && errorsContent.length > 0) {
er.content = errorsContent;
}
var self = new Error();
self.__proto__ = FieldValidatorError.prototype;
self.message = er;
self.name = 'FieldValidatorError';
self.path = path;
self.fieldValue = fieldValue;
self.errors = errors || [];
self.errorsContent = errorsContent || [];
return self;
}
|
[
"function",
"(",
"path",
",",
"fieldValue",
",",
"errors",
",",
"errorsContent",
")",
"{",
"var",
"e",
"=",
"{",
"}",
";",
"var",
"er",
"=",
"{",
"}",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"errors",
")",
"&&",
"errors",
".",
"length",
">",
"0",
")",
"{",
"er",
".",
"errors",
"=",
"errors",
";",
"}",
"if",
"(",
"_",
".",
"isArray",
"(",
"errorsContent",
")",
"&&",
"errorsContent",
".",
"length",
">",
"0",
")",
"{",
"er",
".",
"content",
"=",
"errorsContent",
";",
"}",
"var",
"self",
"=",
"new",
"Error",
"(",
")",
";",
"self",
".",
"__proto__",
"=",
"FieldValidatorError",
".",
"prototype",
";",
"self",
".",
"message",
"=",
"er",
";",
"self",
".",
"name",
"=",
"'FieldValidatorError'",
";",
"self",
".",
"path",
"=",
"path",
";",
"self",
".",
"fieldValue",
"=",
"fieldValue",
";",
"self",
".",
"errors",
"=",
"errors",
"||",
"[",
"]",
";",
"self",
".",
"errorsContent",
"=",
"errorsContent",
"||",
"[",
"]",
";",
"return",
"self",
";",
"}"
] |
Error class to handle validation errors on a field
@param string path The field's path
@param mixed fieldValue The field value
@param array errors An array of ValidationError
@param array errorsContent An array of ValidationError on the field children
|
[
"Error",
"class",
"to",
"handle",
"validation",
"errors",
"on",
"a",
"field"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L313-L334
|
|
52,158
|
Elao/validator-framework
|
src/validator.js
|
FieldValidator
|
function FieldValidator(rules, config)
{
this.rules = rules;
this.fieldLabel = undefined;
if (config) {
this.setConfig(config);
}
}
|
javascript
|
function FieldValidator(rules, config)
{
this.rules = rules;
this.fieldLabel = undefined;
if (config) {
this.setConfig(config);
}
}
|
[
"function",
"FieldValidator",
"(",
"rules",
",",
"config",
")",
"{",
"this",
".",
"rules",
"=",
"rules",
";",
"this",
".",
"fieldLabel",
"=",
"undefined",
";",
"if",
"(",
"config",
")",
"{",
"this",
".",
"setConfig",
"(",
"config",
")",
";",
"}",
"}"
] |
Object to validate rules again data field
@param array rules list of rules to apply
@param object config configuration object
|
[
"Object",
"to",
"validate",
"rules",
"again",
"data",
"field"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L357-L364
|
52,159
|
Elao/validator-framework
|
src/validator.js
|
Validator
|
function Validator(type, config)
{
this.type = type;
this.message = undefined;
this.value = undefined;
this.groups = undefined;
this.fieldValidator = undefined;
this.parent = undefined;
if (typeof(config) === 'object') {
this.groups = config.groups;
if (_.has(config, 'message'))
this.message = config.message;
if (_.has(config, 'value') && !_.isUndefined(config.value))
this.value = config.value;
} else if (!_.isUndefined(config)) {
this.value = config;
}
return this;
}
|
javascript
|
function Validator(type, config)
{
this.type = type;
this.message = undefined;
this.value = undefined;
this.groups = undefined;
this.fieldValidator = undefined;
this.parent = undefined;
if (typeof(config) === 'object') {
this.groups = config.groups;
if (_.has(config, 'message'))
this.message = config.message;
if (_.has(config, 'value') && !_.isUndefined(config.value))
this.value = config.value;
} else if (!_.isUndefined(config)) {
this.value = config;
}
return this;
}
|
[
"function",
"Validator",
"(",
"type",
",",
"config",
")",
"{",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"message",
"=",
"undefined",
";",
"this",
".",
"value",
"=",
"undefined",
";",
"this",
".",
"groups",
"=",
"undefined",
";",
"this",
".",
"fieldValidator",
"=",
"undefined",
";",
"this",
".",
"parent",
"=",
"undefined",
";",
"if",
"(",
"typeof",
"(",
"config",
")",
"===",
"'object'",
")",
"{",
"this",
".",
"groups",
"=",
"config",
".",
"groups",
";",
"if",
"(",
"_",
".",
"has",
"(",
"config",
",",
"'message'",
")",
")",
"this",
".",
"message",
"=",
"config",
".",
"message",
";",
"if",
"(",
"_",
".",
"has",
"(",
"config",
",",
"'value'",
")",
"&&",
"!",
"_",
".",
"isUndefined",
"(",
"config",
".",
"value",
")",
")",
"this",
".",
"value",
"=",
"config",
".",
"value",
";",
"}",
"else",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"config",
")",
")",
"{",
"this",
".",
"value",
"=",
"config",
";",
"}",
"return",
"this",
";",
"}"
] |
Validator object validate a data based on a configured rule. It raise an error or reject a promise
@param string type The validator type (must be present in the rules objects)
@param object config The validator type configuration
|
[
"Validator",
"object",
"validate",
"a",
"data",
"based",
"on",
"a",
"configured",
"rule",
".",
"It",
"raise",
"an",
"error",
"or",
"reject",
"a",
"promise"
] |
77a91e655d3a65f1098e868404a59ee60d2a0f95
|
https://github.com/Elao/validator-framework/blob/77a91e655d3a65f1098e868404a59ee60d2a0f95/src/validator.js#L521-L544
|
52,160
|
origin1tech/chek
|
dist/modules/to.js
|
toBoolean
|
function toBoolean(val, def) {
if (is_1.isBoolean(val))
return val;
if (!is_1.isValue(val))
return toDefault(null, def);
val = val.toString();
return (parseFloat(val) > 0 ||
is_1.isInfinite(val) ||
val === 'true' ||
val === 'yes' ||
val === '1' ||
val === '+');
}
|
javascript
|
function toBoolean(val, def) {
if (is_1.isBoolean(val))
return val;
if (!is_1.isValue(val))
return toDefault(null, def);
val = val.toString();
return (parseFloat(val) > 0 ||
is_1.isInfinite(val) ||
val === 'true' ||
val === 'yes' ||
val === '1' ||
val === '+');
}
|
[
"function",
"toBoolean",
"(",
"val",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isBoolean",
"(",
"val",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"is_1",
".",
"isValue",
"(",
"val",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"val",
"=",
"val",
".",
"toString",
"(",
")",
";",
"return",
"(",
"parseFloat",
"(",
"val",
")",
">",
"0",
"||",
"is_1",
".",
"isInfinite",
"(",
"val",
")",
"||",
"val",
"===",
"'true'",
"||",
"val",
"===",
"'yes'",
"||",
"val",
"===",
"'1'",
"||",
"val",
"===",
"'+'",
")",
";",
"}"
] |
To Boolean
Converts value if not boolean to boolean.
Will convert 'true', '1', 'yes' or '+' to true.
@param val the value to inspect.
@param def optional default value on null.
|
[
"To",
"Boolean",
"Converts",
"value",
"if",
"not",
"boolean",
"to",
"boolean",
".",
"Will",
"convert",
"true",
"1",
"yes",
"or",
"+",
"to",
"true",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L53-L65
|
52,161
|
origin1tech/chek
|
dist/modules/to.js
|
toDate
|
function toDate(val, format, def) {
if (is_1.isDate(format)) {
def = format;
format = undefined;
}
var opts = format;
// Date format options a simple timezine
// ex: 'America/Los_Angeles'.
if (is_1.isString(opts)) {
opts = {
timeZone: format
};
}
// This just checks loosely if string is
// date like string, below parse should
// catch majority of scenarios.
function canParse() {
return !/^[0-9]+$/.test(val) &&
(is_1.isString(val) && /[0-9]/g.test(val) &&
/(\.|\/|-|:)/g.test(val));
}
function parseDate() {
var epoch = Date.parse(val);
if (!isNaN(epoch)) {
var date = from_1.fromEpoch(epoch);
if (opts) {
opts.locales = opts.locales || 'en-US';
date = new Date(date.toLocaleString(opts.locales, opts));
}
return date;
}
return toDefault(null, def);
}
if (is_1.isDate(val))
return val;
if (!canParse())
return toDefault(null, def);
return function_1.tryWrap(parseDate)(def);
}
|
javascript
|
function toDate(val, format, def) {
if (is_1.isDate(format)) {
def = format;
format = undefined;
}
var opts = format;
// Date format options a simple timezine
// ex: 'America/Los_Angeles'.
if (is_1.isString(opts)) {
opts = {
timeZone: format
};
}
// This just checks loosely if string is
// date like string, below parse should
// catch majority of scenarios.
function canParse() {
return !/^[0-9]+$/.test(val) &&
(is_1.isString(val) && /[0-9]/g.test(val) &&
/(\.|\/|-|:)/g.test(val));
}
function parseDate() {
var epoch = Date.parse(val);
if (!isNaN(epoch)) {
var date = from_1.fromEpoch(epoch);
if (opts) {
opts.locales = opts.locales || 'en-US';
date = new Date(date.toLocaleString(opts.locales, opts));
}
return date;
}
return toDefault(null, def);
}
if (is_1.isDate(val))
return val;
if (!canParse())
return toDefault(null, def);
return function_1.tryWrap(parseDate)(def);
}
|
[
"function",
"toDate",
"(",
"val",
",",
"format",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isDate",
"(",
"format",
")",
")",
"{",
"def",
"=",
"format",
";",
"format",
"=",
"undefined",
";",
"}",
"var",
"opts",
"=",
"format",
";",
"// Date format options a simple timezine",
"// ex: 'America/Los_Angeles'.",
"if",
"(",
"is_1",
".",
"isString",
"(",
"opts",
")",
")",
"{",
"opts",
"=",
"{",
"timeZone",
":",
"format",
"}",
";",
"}",
"// This just checks loosely if string is",
"// date like string, below parse should",
"// catch majority of scenarios.",
"function",
"canParse",
"(",
")",
"{",
"return",
"!",
"/",
"^[0-9]+$",
"/",
".",
"test",
"(",
"val",
")",
"&&",
"(",
"is_1",
".",
"isString",
"(",
"val",
")",
"&&",
"/",
"[0-9]",
"/",
"g",
".",
"test",
"(",
"val",
")",
"&&",
"/",
"(\\.|\\/|-|:)",
"/",
"g",
".",
"test",
"(",
"val",
")",
")",
";",
"}",
"function",
"parseDate",
"(",
")",
"{",
"var",
"epoch",
"=",
"Date",
".",
"parse",
"(",
"val",
")",
";",
"if",
"(",
"!",
"isNaN",
"(",
"epoch",
")",
")",
"{",
"var",
"date",
"=",
"from_1",
".",
"fromEpoch",
"(",
"epoch",
")",
";",
"if",
"(",
"opts",
")",
"{",
"opts",
".",
"locales",
"=",
"opts",
".",
"locales",
"||",
"'en-US'",
";",
"date",
"=",
"new",
"Date",
"(",
"date",
".",
"toLocaleString",
"(",
"opts",
".",
"locales",
",",
"opts",
")",
")",
";",
"}",
"return",
"date",
";",
"}",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"}",
"if",
"(",
"is_1",
".",
"isDate",
"(",
"val",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"canParse",
"(",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"return",
"function_1",
".",
"tryWrap",
"(",
"parseDate",
")",
"(",
"def",
")",
";",
"}"
] |
To Date
Converts value to date using Date.parse when string.
Optionally you can pass a format object containing
Intl.DateFormatOptions and locales. You may also pass
the timezone ONLY as a string. In this case locale en-US
is assumed.
@param val the value to be converted to date.
@param format date locale format options.
@param def a default date when null.
|
[
"To",
"Date",
"Converts",
"value",
"to",
"date",
"using",
"Date",
".",
"parse",
"when",
"string",
".",
"Optionally",
"you",
"can",
"pass",
"a",
"format",
"object",
"containing",
"Intl",
".",
"DateFormatOptions",
"and",
"locales",
".",
"You",
"may",
"also",
"pass",
"the",
"timezone",
"ONLY",
"as",
"a",
"string",
".",
"In",
"this",
"case",
"locale",
"en",
"-",
"US",
"is",
"assumed",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L79-L117
|
52,162
|
origin1tech/chek
|
dist/modules/to.js
|
canParse
|
function canParse() {
return !/^[0-9]+$/.test(val) &&
(is_1.isString(val) && /[0-9]/g.test(val) &&
/(\.|\/|-|:)/g.test(val));
}
|
javascript
|
function canParse() {
return !/^[0-9]+$/.test(val) &&
(is_1.isString(val) && /[0-9]/g.test(val) &&
/(\.|\/|-|:)/g.test(val));
}
|
[
"function",
"canParse",
"(",
")",
"{",
"return",
"!",
"/",
"^[0-9]+$",
"/",
".",
"test",
"(",
"val",
")",
"&&",
"(",
"is_1",
".",
"isString",
"(",
"val",
")",
"&&",
"/",
"[0-9]",
"/",
"g",
".",
"test",
"(",
"val",
")",
"&&",
"/",
"(\\.|\\/|-|:)",
"/",
"g",
".",
"test",
"(",
"val",
")",
")",
";",
"}"
] |
This just checks loosely if string is date like string, below parse should catch majority of scenarios.
|
[
"This",
"just",
"checks",
"loosely",
"if",
"string",
"is",
"date",
"like",
"string",
"below",
"parse",
"should",
"catch",
"majority",
"of",
"scenarios",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L95-L99
|
52,163
|
origin1tech/chek
|
dist/modules/to.js
|
toDefault
|
function toDefault(val, def) {
if (is_1.isValue(val) && !(is_1.isEmpty(val) && !is_1.isEmpty(def)))
return val;
return is_1.isValue(def) ? def : null;
}
|
javascript
|
function toDefault(val, def) {
if (is_1.isValue(val) && !(is_1.isEmpty(val) && !is_1.isEmpty(def)))
return val;
return is_1.isValue(def) ? def : null;
}
|
[
"function",
"toDefault",
"(",
"val",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isValue",
"(",
"val",
")",
"&&",
"!",
"(",
"is_1",
".",
"isEmpty",
"(",
"val",
")",
"&&",
"!",
"is_1",
".",
"isEmpty",
"(",
"def",
")",
")",
")",
"return",
"val",
";",
"return",
"is_1",
".",
"isValue",
"(",
"def",
")",
"?",
"def",
":",
"null",
";",
"}"
] |
To Default
Returns a default value when provided if
primary value is null or undefined. If neither
then null is returned.
@param val the value to return if defined.
@param def an optional default value to be returned.
|
[
"To",
"Default",
"Returns",
"a",
"default",
"value",
"when",
"provided",
"if",
"primary",
"value",
"is",
"null",
"or",
"undefined",
".",
"If",
"neither",
"then",
"null",
"is",
"returned",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L128-L132
|
52,164
|
origin1tech/chek
|
dist/modules/to.js
|
toEpoch
|
function toEpoch(val, def) {
return toDefault((is_1.isDate(val) && val.getTime()), def);
}
|
javascript
|
function toEpoch(val, def) {
return toDefault((is_1.isDate(val) && val.getTime()), def);
}
|
[
"function",
"toEpoch",
"(",
"val",
",",
"def",
")",
"{",
"return",
"toDefault",
"(",
"(",
"is_1",
".",
"isDate",
"(",
"val",
")",
"&&",
"val",
".",
"getTime",
"(",
")",
")",
",",
"def",
")",
";",
"}"
] |
To Epoch
Converts a Date type to an epoch.
@param val the date value to convert.
@param def optional default value when null.
|
[
"To",
"Epoch",
"Converts",
"a",
"Date",
"type",
"to",
"an",
"epoch",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L141-L143
|
52,165
|
origin1tech/chek
|
dist/modules/to.js
|
toFloat
|
function toFloat(val, def) {
if (is_1.isFloat(val))
return val;
if (!is_1.isValue(val))
return toDefault(null, def);
var parsed = function_1.tryWrap(parseFloat, val)(def);
if (is_1.isFloat(parsed) || is_1.isNumber(parsed))
return parsed;
if (toBoolean(val))
return 1;
return 0;
}
|
javascript
|
function toFloat(val, def) {
if (is_1.isFloat(val))
return val;
if (!is_1.isValue(val))
return toDefault(null, def);
var parsed = function_1.tryWrap(parseFloat, val)(def);
if (is_1.isFloat(parsed) || is_1.isNumber(parsed))
return parsed;
if (toBoolean(val))
return 1;
return 0;
}
|
[
"function",
"toFloat",
"(",
"val",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isFloat",
"(",
"val",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"is_1",
".",
"isValue",
"(",
"val",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"var",
"parsed",
"=",
"function_1",
".",
"tryWrap",
"(",
"parseFloat",
",",
"val",
")",
"(",
"def",
")",
";",
"if",
"(",
"is_1",
".",
"isFloat",
"(",
"parsed",
")",
"||",
"is_1",
".",
"isNumber",
"(",
"parsed",
")",
")",
"return",
"parsed",
";",
"if",
"(",
"toBoolean",
"(",
"val",
")",
")",
"return",
"1",
";",
"return",
"0",
";",
"}"
] |
To Float
Converts value to a float.
@param val the value to convert to float.
|
[
"To",
"Float",
"Converts",
"value",
"to",
"a",
"float",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L151-L162
|
52,166
|
origin1tech/chek
|
dist/modules/to.js
|
toJSON
|
function toJSON(obj, pretty, def) {
if (is_1.isString(pretty)) {
def = pretty;
pretty = undefined;
}
var tabs = 0;
pretty = is_1.isBoolean(pretty) ? 2 : pretty;
tabs = pretty ? pretty : tabs;
if (!is_1.isObject(obj))
return toDefault(null, def);
return function_1.tryWrap(JSON.stringify, obj, null, tabs)(def);
}
|
javascript
|
function toJSON(obj, pretty, def) {
if (is_1.isString(pretty)) {
def = pretty;
pretty = undefined;
}
var tabs = 0;
pretty = is_1.isBoolean(pretty) ? 2 : pretty;
tabs = pretty ? pretty : tabs;
if (!is_1.isObject(obj))
return toDefault(null, def);
return function_1.tryWrap(JSON.stringify, obj, null, tabs)(def);
}
|
[
"function",
"toJSON",
"(",
"obj",
",",
"pretty",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isString",
"(",
"pretty",
")",
")",
"{",
"def",
"=",
"pretty",
";",
"pretty",
"=",
"undefined",
";",
"}",
"var",
"tabs",
"=",
"0",
";",
"pretty",
"=",
"is_1",
".",
"isBoolean",
"(",
"pretty",
")",
"?",
"2",
":",
"pretty",
";",
"tabs",
"=",
"pretty",
"?",
"pretty",
":",
"tabs",
";",
"if",
"(",
"!",
"is_1",
".",
"isObject",
"(",
"obj",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"return",
"function_1",
".",
"tryWrap",
"(",
"JSON",
".",
"stringify",
",",
"obj",
",",
"null",
",",
"tabs",
")",
"(",
"def",
")",
";",
"}"
] |
To JSON
Simple wrapper to strinigy using JSON.
@param obj the object to be stringified.
@param pretty an integer or true for tabs in JSON.
@param def optional default value on null.
|
[
"To",
"JSON",
"Simple",
"wrapper",
"to",
"strinigy",
"using",
"JSON",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L172-L183
|
52,167
|
origin1tech/chek
|
dist/modules/to.js
|
toInteger
|
function toInteger(val, def) {
if (!is_1.isValue(val))
return toDefault(null, def);
var parsed = function_1.tryWrap(parseInt, val)(def);
if (is_1.isInteger(parsed))
return parsed;
if (toBoolean(val))
return 1;
return 0;
}
|
javascript
|
function toInteger(val, def) {
if (!is_1.isValue(val))
return toDefault(null, def);
var parsed = function_1.tryWrap(parseInt, val)(def);
if (is_1.isInteger(parsed))
return parsed;
if (toBoolean(val))
return 1;
return 0;
}
|
[
"function",
"toInteger",
"(",
"val",
",",
"def",
")",
"{",
"if",
"(",
"!",
"is_1",
".",
"isValue",
"(",
"val",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"var",
"parsed",
"=",
"function_1",
".",
"tryWrap",
"(",
"parseInt",
",",
"val",
")",
"(",
"def",
")",
";",
"if",
"(",
"is_1",
".",
"isInteger",
"(",
"parsed",
")",
")",
"return",
"parsed",
";",
"if",
"(",
"toBoolean",
"(",
"val",
")",
")",
"return",
"1",
";",
"return",
"0",
";",
"}"
] |
To Integer
Convert value to integer.
@param val the value to convert to integer.
@param def optional default value on null or error.
|
[
"To",
"Integer",
"Convert",
"value",
"to",
"integer",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L192-L201
|
52,168
|
origin1tech/chek
|
dist/modules/to.js
|
toMap
|
function toMap(val, id, def) {
if (is_1.isValue(id) && !is_1.isString(id)) {
def = id;
id = undefined;
}
if (is_1.isPlainObject(val))
return val;
if (!is_1.isValue(val) || (!is_1.isString(val) && !is_1.isArray(val)))
return toDefault(null, def);
// Default id key.
id = id || '$id';
var exp = /(\/|\.|,|;|\|)/g;
var i = 0;
var obj = {};
if (is_1.isString(val)) {
// simple string.
if (!exp.test(val))
return { 0: val };
// split string into array, iterate.
val = string_1.split(val);
val.forEach(function (v, i) { return obj[i] = v; });
return obj;
}
while (i < val.length) {
if (is_1.isString(val[i])) {
obj[i] = val[i];
}
else if (is_1.isPlainObject(val[i])) {
var itm = Object.assign({}, val[i]);
var key = itm[id] ? itm[id] : i;
obj[key] = itm[id] ? object_1.del(itm, id) : itm;
}
i++;
}
return obj;
}
|
javascript
|
function toMap(val, id, def) {
if (is_1.isValue(id) && !is_1.isString(id)) {
def = id;
id = undefined;
}
if (is_1.isPlainObject(val))
return val;
if (!is_1.isValue(val) || (!is_1.isString(val) && !is_1.isArray(val)))
return toDefault(null, def);
// Default id key.
id = id || '$id';
var exp = /(\/|\.|,|;|\|)/g;
var i = 0;
var obj = {};
if (is_1.isString(val)) {
// simple string.
if (!exp.test(val))
return { 0: val };
// split string into array, iterate.
val = string_1.split(val);
val.forEach(function (v, i) { return obj[i] = v; });
return obj;
}
while (i < val.length) {
if (is_1.isString(val[i])) {
obj[i] = val[i];
}
else if (is_1.isPlainObject(val[i])) {
var itm = Object.assign({}, val[i]);
var key = itm[id] ? itm[id] : i;
obj[key] = itm[id] ? object_1.del(itm, id) : itm;
}
i++;
}
return obj;
}
|
[
"function",
"toMap",
"(",
"val",
",",
"id",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isValue",
"(",
"id",
")",
"&&",
"!",
"is_1",
".",
"isString",
"(",
"id",
")",
")",
"{",
"def",
"=",
"id",
";",
"id",
"=",
"undefined",
";",
"}",
"if",
"(",
"is_1",
".",
"isPlainObject",
"(",
"val",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"is_1",
".",
"isValue",
"(",
"val",
")",
"||",
"(",
"!",
"is_1",
".",
"isString",
"(",
"val",
")",
"&&",
"!",
"is_1",
".",
"isArray",
"(",
"val",
")",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"// Default id key.",
"id",
"=",
"id",
"||",
"'$id'",
";",
"var",
"exp",
"=",
"/",
"(\\/|\\.|,|;|\\|)",
"/",
"g",
";",
"var",
"i",
"=",
"0",
";",
"var",
"obj",
"=",
"{",
"}",
";",
"if",
"(",
"is_1",
".",
"isString",
"(",
"val",
")",
")",
"{",
"// simple string.",
"if",
"(",
"!",
"exp",
".",
"test",
"(",
"val",
")",
")",
"return",
"{",
"0",
":",
"val",
"}",
";",
"// split string into array, iterate.",
"val",
"=",
"string_1",
".",
"split",
"(",
"val",
")",
";",
"val",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"return",
"obj",
"[",
"i",
"]",
"=",
"v",
";",
"}",
")",
";",
"return",
"obj",
";",
"}",
"while",
"(",
"i",
"<",
"val",
".",
"length",
")",
"{",
"if",
"(",
"is_1",
".",
"isString",
"(",
"val",
"[",
"i",
"]",
")",
")",
"{",
"obj",
"[",
"i",
"]",
"=",
"val",
"[",
"i",
"]",
";",
"}",
"else",
"if",
"(",
"is_1",
".",
"isPlainObject",
"(",
"val",
"[",
"i",
"]",
")",
")",
"{",
"var",
"itm",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"val",
"[",
"i",
"]",
")",
";",
"var",
"key",
"=",
"itm",
"[",
"id",
"]",
"?",
"itm",
"[",
"id",
"]",
":",
"i",
";",
"obj",
"[",
"key",
"]",
"=",
"itm",
"[",
"id",
"]",
"?",
"object_1",
".",
"del",
"(",
"itm",
",",
"id",
")",
":",
"itm",
";",
"}",
"i",
"++",
";",
"}",
"return",
"obj",
";",
"}"
] |
To Map
Converts arrays, strings, to an object literal.
@example
Array: ['one', 'two', 'three'] Maps To: { 0: 'one', 1: 'two', 2: 'three' }
String: 'Star Wars' Maps To: { 0: 'Star Wars' }
String: 'Star Wars, Star Trek' Maps To { 0: 'Star Wars', 1: 'Star Trek' }
Array: [{ id: '123', name: 'Joe' }] Maps To: { 123: { name: 'Joe' }}
Array: [{ name: 'Joe' }, { name: 'Amy' }]
Maps To: { 0: { name: 'Joe' }, 2: { name: 'Amy' }}
NOTE: mixed content arrays not supported.
@param val the value to be mapped.
@param id optional id key when iterating array of objects.
@param def optional default value on null or error.
|
[
"To",
"Map",
"Converts",
"arrays",
"strings",
"to",
"an",
"object",
"literal",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L221-L256
|
52,169
|
origin1tech/chek
|
dist/modules/to.js
|
toNested
|
function toNested(val, def) {
function nest(src) {
var dest = {};
for (var p in src) {
if (src.hasOwnProperty(p))
if (/\./g.test(p))
object_1.set(dest, p, src[p]);
else
dest[p] = src[p];
}
return dest;
}
return function_1.tryWrap(nest, val)(def);
}
|
javascript
|
function toNested(val, def) {
function nest(src) {
var dest = {};
for (var p in src) {
if (src.hasOwnProperty(p))
if (/\./g.test(p))
object_1.set(dest, p, src[p]);
else
dest[p] = src[p];
}
return dest;
}
return function_1.tryWrap(nest, val)(def);
}
|
[
"function",
"toNested",
"(",
"val",
",",
"def",
")",
"{",
"function",
"nest",
"(",
"src",
")",
"{",
"var",
"dest",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"p",
"in",
"src",
")",
"{",
"if",
"(",
"src",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"if",
"(",
"/",
"\\.",
"/",
"g",
".",
"test",
"(",
"p",
")",
")",
"object_1",
".",
"set",
"(",
"dest",
",",
"p",
",",
"src",
"[",
"p",
"]",
")",
";",
"else",
"dest",
"[",
"p",
"]",
"=",
"src",
"[",
"p",
"]",
";",
"}",
"return",
"dest",
";",
"}",
"return",
"function_1",
".",
"tryWrap",
"(",
"nest",
",",
"val",
")",
"(",
"def",
")",
";",
"}"
] |
To Nested
Takes an object that was flattened by toUnnested
and re-nests it.
@param val the flattened object to be nested.
|
[
"To",
"Nested",
"Takes",
"an",
"object",
"that",
"was",
"flattened",
"by",
"toUnnested",
"and",
"re",
"-",
"nests",
"it",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L265-L278
|
52,170
|
origin1tech/chek
|
dist/modules/to.js
|
toRegExp
|
function toRegExp(val, def) {
var exp = /^\/.+\/(g|i|m)?([m,i,u,y]{1,4})?/;
var optsExp = /(g|i|m)?([m,i,u,y]{1,4})?$/;
if (is_1.isRegExp(val))
return val;
if (!is_1.isValue(val) || !is_1.isString(val))
return toDefault(null, def);
function regExpFromStr() {
var opts;
if (exp.test(val)) {
opts = optsExp.exec(val)[0];
val = val.replace(/^\//, '').replace(optsExp, '').replace(/\/$/, '');
}
return new RegExp(val, opts);
}
return function_1.tryWrap(regExpFromStr)(def);
}
|
javascript
|
function toRegExp(val, def) {
var exp = /^\/.+\/(g|i|m)?([m,i,u,y]{1,4})?/;
var optsExp = /(g|i|m)?([m,i,u,y]{1,4})?$/;
if (is_1.isRegExp(val))
return val;
if (!is_1.isValue(val) || !is_1.isString(val))
return toDefault(null, def);
function regExpFromStr() {
var opts;
if (exp.test(val)) {
opts = optsExp.exec(val)[0];
val = val.replace(/^\//, '').replace(optsExp, '').replace(/\/$/, '');
}
return new RegExp(val, opts);
}
return function_1.tryWrap(regExpFromStr)(def);
}
|
[
"function",
"toRegExp",
"(",
"val",
",",
"def",
")",
"{",
"var",
"exp",
"=",
"/",
"^\\/.+\\/(g|i|m)?([m,i,u,y]{1,4})?",
"/",
";",
"var",
"optsExp",
"=",
"/",
"(g|i|m)?([m,i,u,y]{1,4})?$",
"/",
";",
"if",
"(",
"is_1",
".",
"isRegExp",
"(",
"val",
")",
")",
"return",
"val",
";",
"if",
"(",
"!",
"is_1",
".",
"isValue",
"(",
"val",
")",
"||",
"!",
"is_1",
".",
"isString",
"(",
"val",
")",
")",
"return",
"toDefault",
"(",
"null",
",",
"def",
")",
";",
"function",
"regExpFromStr",
"(",
")",
"{",
"var",
"opts",
";",
"if",
"(",
"exp",
".",
"test",
"(",
"val",
")",
")",
"{",
"opts",
"=",
"optsExp",
".",
"exec",
"(",
"val",
")",
"[",
"0",
"]",
";",
"val",
"=",
"val",
".",
"replace",
"(",
"/",
"^\\/",
"/",
",",
"''",
")",
".",
"replace",
"(",
"optsExp",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\/$",
"/",
",",
"''",
")",
";",
"}",
"return",
"new",
"RegExp",
"(",
"val",
",",
"opts",
")",
";",
"}",
"return",
"function_1",
".",
"tryWrap",
"(",
"regExpFromStr",
")",
"(",
"def",
")",
";",
"}"
] |
To Regular Expression
Attempts to convert to a regular expression
from a string.
@param val the value to convert to RegExp.
@param def optional express as default on null.
|
[
"To",
"Regular",
"Expression",
"Attempts",
"to",
"convert",
"to",
"a",
"regular",
"expression",
"from",
"a",
"string",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L299-L315
|
52,171
|
origin1tech/chek
|
dist/modules/to.js
|
toUnnested
|
function toUnnested(obj, prefix, def) {
if (is_1.isValue(prefix) && !is_1.isBoolean(prefix)) {
def = prefix;
prefix = undefined;
}
var dupes = 0;
function unnest(src, dest, pre) {
dest = dest || {};
for (var p in src) {
if (dupes > 0)
return;
if (src.hasOwnProperty(p)) {
if (is_1.isPlainObject(src[p])) {
var parent = prefix !== false &&
(pre && pre.length) ?
pre + '.' + p : p;
unnest(src[p], dest, parent);
}
else {
var name = prefix !== false &&
pre && pre.length ?
pre + '.' + p : p;
if (dest[name])
dupes += 1;
else
dest[name] = src[p];
}
}
}
if (dupes > 0)
return null;
return dest;
}
return function_1.tryWrap(unnest, object_1.clone(obj))(def);
}
|
javascript
|
function toUnnested(obj, prefix, def) {
if (is_1.isValue(prefix) && !is_1.isBoolean(prefix)) {
def = prefix;
prefix = undefined;
}
var dupes = 0;
function unnest(src, dest, pre) {
dest = dest || {};
for (var p in src) {
if (dupes > 0)
return;
if (src.hasOwnProperty(p)) {
if (is_1.isPlainObject(src[p])) {
var parent = prefix !== false &&
(pre && pre.length) ?
pre + '.' + p : p;
unnest(src[p], dest, parent);
}
else {
var name = prefix !== false &&
pre && pre.length ?
pre + '.' + p : p;
if (dest[name])
dupes += 1;
else
dest[name] = src[p];
}
}
}
if (dupes > 0)
return null;
return dest;
}
return function_1.tryWrap(unnest, object_1.clone(obj))(def);
}
|
[
"function",
"toUnnested",
"(",
"obj",
",",
"prefix",
",",
"def",
")",
"{",
"if",
"(",
"is_1",
".",
"isValue",
"(",
"prefix",
")",
"&&",
"!",
"is_1",
".",
"isBoolean",
"(",
"prefix",
")",
")",
"{",
"def",
"=",
"prefix",
";",
"prefix",
"=",
"undefined",
";",
"}",
"var",
"dupes",
"=",
"0",
";",
"function",
"unnest",
"(",
"src",
",",
"dest",
",",
"pre",
")",
"{",
"dest",
"=",
"dest",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"p",
"in",
"src",
")",
"{",
"if",
"(",
"dupes",
">",
"0",
")",
"return",
";",
"if",
"(",
"src",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"if",
"(",
"is_1",
".",
"isPlainObject",
"(",
"src",
"[",
"p",
"]",
")",
")",
"{",
"var",
"parent",
"=",
"prefix",
"!==",
"false",
"&&",
"(",
"pre",
"&&",
"pre",
".",
"length",
")",
"?",
"pre",
"+",
"'.'",
"+",
"p",
":",
"p",
";",
"unnest",
"(",
"src",
"[",
"p",
"]",
",",
"dest",
",",
"parent",
")",
";",
"}",
"else",
"{",
"var",
"name",
"=",
"prefix",
"!==",
"false",
"&&",
"pre",
"&&",
"pre",
".",
"length",
"?",
"pre",
"+",
"'.'",
"+",
"p",
":",
"p",
";",
"if",
"(",
"dest",
"[",
"name",
"]",
")",
"dupes",
"+=",
"1",
";",
"else",
"dest",
"[",
"name",
"]",
"=",
"src",
"[",
"p",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"dupes",
">",
"0",
")",
"return",
"null",
";",
"return",
"dest",
";",
"}",
"return",
"function_1",
".",
"tryWrap",
"(",
"unnest",
",",
"object_1",
".",
"clone",
"(",
"obj",
")",
")",
"(",
"def",
")",
";",
"}"
] |
To Unnested
Takes a nested object and flattens it
to a single level safely. To disable key
prefixing set prefix to false.
@param val the object to be unnested.
@param prefix when NOT false parent key is prefixed to children.
@param def optional default value on null.
|
[
"To",
"Unnested",
"Takes",
"a",
"nested",
"object",
"and",
"flattens",
"it",
"to",
"a",
"single",
"level",
"safely",
".",
"To",
"disable",
"key",
"prefixing",
"set",
"prefix",
"to",
"false",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L345-L379
|
52,172
|
origin1tech/chek
|
dist/modules/to.js
|
toWindow
|
function toWindow(key, val, exclude) {
/* istanbul ignore if */
if (!is_1.isBrowser())
return;
exclude = toArray(exclude);
var _keys, i;
// key/val was passed.
if (is_1.isString(key)) {
if (!is_1.isPlainObject(val)) {
window[key] = val;
}
else {
var obj = {};
_keys = array_1.keys(val);
i = _keys.length;
while (i--) {
if (!array_1.contains(exclude, _keys[i]))
obj[_keys[i]] = val[_keys[i]];
}
window[key] = obj;
}
}
// object passed to key.
else if (is_1.isPlainObject(key)) {
_keys = array_1.keys(key);
i = _keys.length;
while (i--) {
if (!array_1.contains(exclude, _keys[i]))
window[_keys[i]] = key[_keys[i]];
}
}
}
|
javascript
|
function toWindow(key, val, exclude) {
/* istanbul ignore if */
if (!is_1.isBrowser())
return;
exclude = toArray(exclude);
var _keys, i;
// key/val was passed.
if (is_1.isString(key)) {
if (!is_1.isPlainObject(val)) {
window[key] = val;
}
else {
var obj = {};
_keys = array_1.keys(val);
i = _keys.length;
while (i--) {
if (!array_1.contains(exclude, _keys[i]))
obj[_keys[i]] = val[_keys[i]];
}
window[key] = obj;
}
}
// object passed to key.
else if (is_1.isPlainObject(key)) {
_keys = array_1.keys(key);
i = _keys.length;
while (i--) {
if (!array_1.contains(exclude, _keys[i]))
window[_keys[i]] = key[_keys[i]];
}
}
}
|
[
"function",
"toWindow",
"(",
"key",
",",
"val",
",",
"exclude",
")",
"{",
"/* istanbul ignore if */",
"if",
"(",
"!",
"is_1",
".",
"isBrowser",
"(",
")",
")",
"return",
";",
"exclude",
"=",
"toArray",
"(",
"exclude",
")",
";",
"var",
"_keys",
",",
"i",
";",
"// key/val was passed.",
"if",
"(",
"is_1",
".",
"isString",
"(",
"key",
")",
")",
"{",
"if",
"(",
"!",
"is_1",
".",
"isPlainObject",
"(",
"val",
")",
")",
"{",
"window",
"[",
"key",
"]",
"=",
"val",
";",
"}",
"else",
"{",
"var",
"obj",
"=",
"{",
"}",
";",
"_keys",
"=",
"array_1",
".",
"keys",
"(",
"val",
")",
";",
"i",
"=",
"_keys",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"if",
"(",
"!",
"array_1",
".",
"contains",
"(",
"exclude",
",",
"_keys",
"[",
"i",
"]",
")",
")",
"obj",
"[",
"_keys",
"[",
"i",
"]",
"]",
"=",
"val",
"[",
"_keys",
"[",
"i",
"]",
"]",
";",
"}",
"window",
"[",
"key",
"]",
"=",
"obj",
";",
"}",
"}",
"// object passed to key.",
"else",
"if",
"(",
"is_1",
".",
"isPlainObject",
"(",
"key",
")",
")",
"{",
"_keys",
"=",
"array_1",
".",
"keys",
"(",
"key",
")",
";",
"i",
"=",
"_keys",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"if",
"(",
"!",
"array_1",
".",
"contains",
"(",
"exclude",
",",
"_keys",
"[",
"i",
"]",
")",
")",
"window",
"[",
"_keys",
"[",
"i",
"]",
"]",
"=",
"key",
"[",
"_keys",
"[",
"i",
"]",
"]",
";",
"}",
"}",
"}"
] |
To Window
Adds key to window object if is browser.
@param key the key or object to add to the window object.
@param val the corresponding value to add to window object.
@param exclude string or array of keys to exclude.
|
[
"To",
"Window",
"Adds",
"key",
"to",
"window",
"object",
"if",
"is",
"browser",
"."
] |
6bc3ab0ac36126cc7918a244a606009749897b2e
|
https://github.com/origin1tech/chek/blob/6bc3ab0ac36126cc7918a244a606009749897b2e/dist/modules/to.js#L389-L420
|
52,173
|
chrisui/Constructr
|
src/constructr.js
|
function(child, parent, protoProps, staticProps) {
// Inherit prototype properties from parent
// Set the prototype chain to inherit without calling parent's constructor function.
SharedConstructor.prototype = parent.prototype;
child.prototype = new SharedConstructor();
child.prototype.constructor = child;
// Extend with prototype and static properties
extendObj(child.prototype, protoProps);
extendObj(child, staticProps);
// Set a convenience property in case the parent's prototype is needed later.
child.__super__ = parent.prototype;
// Copy references to static methods we want to extend
child.extendWithConstructor = Constructr.extendWithConstructor;
child.extend = Constructr.extend;
child.mixes = Constructr.mixes;
child.def = Constructr.def;
return child;
}
|
javascript
|
function(child, parent, protoProps, staticProps) {
// Inherit prototype properties from parent
// Set the prototype chain to inherit without calling parent's constructor function.
SharedConstructor.prototype = parent.prototype;
child.prototype = new SharedConstructor();
child.prototype.constructor = child;
// Extend with prototype and static properties
extendObj(child.prototype, protoProps);
extendObj(child, staticProps);
// Set a convenience property in case the parent's prototype is needed later.
child.__super__ = parent.prototype;
// Copy references to static methods we want to extend
child.extendWithConstructor = Constructr.extendWithConstructor;
child.extend = Constructr.extend;
child.mixes = Constructr.mixes;
child.def = Constructr.def;
return child;
}
|
[
"function",
"(",
"child",
",",
"parent",
",",
"protoProps",
",",
"staticProps",
")",
"{",
"// Inherit prototype properties from parent",
"// Set the prototype chain to inherit without calling parent's constructor function.",
"SharedConstructor",
".",
"prototype",
"=",
"parent",
".",
"prototype",
";",
"child",
".",
"prototype",
"=",
"new",
"SharedConstructor",
"(",
")",
";",
"child",
".",
"prototype",
".",
"constructor",
"=",
"child",
";",
"// Extend with prototype and static properties",
"extendObj",
"(",
"child",
".",
"prototype",
",",
"protoProps",
")",
";",
"extendObj",
"(",
"child",
",",
"staticProps",
")",
";",
"// Set a convenience property in case the parent's prototype is needed later.",
"child",
".",
"__super__",
"=",
"parent",
".",
"prototype",
";",
"// Copy references to static methods we want to extend",
"child",
".",
"extendWithConstructor",
"=",
"Constructr",
".",
"extendWithConstructor",
";",
"child",
".",
"extend",
"=",
"Constructr",
".",
"extend",
";",
"child",
".",
"mixes",
"=",
"Constructr",
".",
"mixes",
";",
"child",
".",
"def",
"=",
"Constructr",
".",
"def",
";",
"return",
"child",
";",
"}"
] |
Correctly setup the prototype chain for sub classes while optionally passing
new prototype and static properties to be mixed in with the new child
@return {Constructr}
|
[
"Correctly",
"setup",
"the",
"prototype",
"chain",
"for",
"sub",
"classes",
"while",
"optionally",
"passing",
"new",
"prototype",
"and",
"static",
"properties",
"to",
"be",
"mixed",
"in",
"with",
"the",
"new",
"child"
] |
e970a612acd28ca8e33a755e595823996a5ccd75
|
https://github.com/chrisui/Constructr/blob/e970a612acd28ca8e33a755e595823996a5ccd75/src/constructr.js#L49-L70
|
|
52,174
|
linyngfly/omelo-admin
|
lib/monitor/monitorAgent.js
|
function(opts) {
EventEmitter.call(this);
this.reqId = 1;
this.opts = opts;
this.id = opts.id;
this.socket = null;
this.callbacks = {};
this.type = opts.type;
this.info = opts.info;
this.state = ST_INITED;
this.consoleService = opts.consoleService;
}
|
javascript
|
function(opts) {
EventEmitter.call(this);
this.reqId = 1;
this.opts = opts;
this.id = opts.id;
this.socket = null;
this.callbacks = {};
this.type = opts.type;
this.info = opts.info;
this.state = ST_INITED;
this.consoleService = opts.consoleService;
}
|
[
"function",
"(",
"opts",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"reqId",
"=",
"1",
";",
"this",
".",
"opts",
"=",
"opts",
";",
"this",
".",
"id",
"=",
"opts",
".",
"id",
";",
"this",
".",
"socket",
"=",
"null",
";",
"this",
".",
"callbacks",
"=",
"{",
"}",
";",
"this",
".",
"type",
"=",
"opts",
".",
"type",
";",
"this",
".",
"info",
"=",
"opts",
".",
"info",
";",
"this",
".",
"state",
"=",
"ST_INITED",
";",
"this",
".",
"consoleService",
"=",
"opts",
".",
"consoleService",
";",
"}"
] |
60 seconds
MonitorAgent Constructor
@class MasterAgent
@constructor
@param {Object} opts construct parameter
opts.consoleService {Object} consoleService
opts.id {String} server id
opts.type {String} server type, 'master', 'connector', etc.
opts.info {Object} more server info for current server, {id, serverType, host, port}
@api public
|
[
"60",
"seconds",
"MonitorAgent",
"Constructor"
] |
1cd692c16ab63b9c0d4009535f300f2ca584b691
|
https://github.com/linyngfly/omelo-admin/blob/1cd692c16ab63b9c0d4009535f300f2ca584b691/lib/monitor/monitorAgent.js#L26-L37
|
|
52,175
|
savushkin-yauheni/our-connect
|
lib/proto.js
|
call
|
function call(handle, route, err, req, res, next) {
var arity = handle.length;
var hasError = Boolean(err);
debug('%s %s : %s', handle.name || '<anonymous>', route, req.originalUrl);
try {
if (hasError && arity === 4) {
// error-handling middleware
handle(err, req, res, next);
return;
} else if (!hasError && arity < 4) {
// request-handling middleware
handle(req, res, next);
return;
}
} catch (e) {
// reset the error
err = e;
}
// continue
next(err);
}
|
javascript
|
function call(handle, route, err, req, res, next) {
var arity = handle.length;
var hasError = Boolean(err);
debug('%s %s : %s', handle.name || '<anonymous>', route, req.originalUrl);
try {
if (hasError && arity === 4) {
// error-handling middleware
handle(err, req, res, next);
return;
} else if (!hasError && arity < 4) {
// request-handling middleware
handle(req, res, next);
return;
}
} catch (e) {
// reset the error
err = e;
}
// continue
next(err);
}
|
[
"function",
"call",
"(",
"handle",
",",
"route",
",",
"err",
",",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"arity",
"=",
"handle",
".",
"length",
";",
"var",
"hasError",
"=",
"Boolean",
"(",
"err",
")",
";",
"debug",
"(",
"'%s %s : %s'",
",",
"handle",
".",
"name",
"||",
"'<anonymous>'",
",",
"route",
",",
"req",
".",
"originalUrl",
")",
";",
"try",
"{",
"if",
"(",
"hasError",
"&&",
"arity",
"===",
"4",
")",
"{",
"// error-handling middleware",
"handle",
"(",
"err",
",",
"req",
",",
"res",
",",
"next",
")",
";",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"hasError",
"&&",
"arity",
"<",
"4",
")",
"{",
"// request-handling middleware",
"handle",
"(",
"req",
",",
"res",
",",
"next",
")",
";",
"return",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"// reset the error",
"err",
"=",
"e",
";",
"}",
"// continue",
"next",
"(",
"err",
")",
";",
"}"
] |
Invoke a route handle.
@api private
|
[
"Invoke",
"a",
"route",
"handle",
"."
] |
aa327a2a87a788535b1e5f6be5503a4419d3aabf
|
https://github.com/savushkin-yauheni/our-connect/blob/aa327a2a87a788535b1e5f6be5503a4419d3aabf/lib/proto.js#L192-L215
|
52,176
|
Becklyn/becklyn-gulp
|
tasks/jshint.js
|
lintAllFiles
|
function lintAllFiles (src, options)
{
glob(src,
function (err, files)
{
if (err) throw err;
for (var i = 0, l = files.length; i < l; i++)
{
jsHintHelper.lintFile(files[i], options.rules);
}
}
);
}
|
javascript
|
function lintAllFiles (src, options)
{
glob(src,
function (err, files)
{
if (err) throw err;
for (var i = 0, l = files.length; i < l; i++)
{
jsHintHelper.lintFile(files[i], options.rules);
}
}
);
}
|
[
"function",
"lintAllFiles",
"(",
"src",
",",
"options",
")",
"{",
"glob",
"(",
"src",
",",
"function",
"(",
"err",
",",
"files",
")",
"{",
"if",
"(",
"err",
")",
"throw",
"err",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"files",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"jsHintHelper",
".",
"lintFile",
"(",
"files",
"[",
"i",
"]",
",",
"options",
".",
"rules",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Lints all files in a given glob
@param {string} src
@param {JsHintTaskOptions} options
|
[
"Lints",
"all",
"files",
"in",
"a",
"given",
"glob"
] |
1c633378d561f07101f9db19ccd153617b8e0252
|
https://github.com/Becklyn/becklyn-gulp/blob/1c633378d561f07101f9db19ccd153617b8e0252/tasks/jshint.js#L25-L38
|
52,177
|
jkresner/meanair-server
|
lib/configure.merge.js
|
mergeRecursive
|
function mergeRecursive(key, defaults, app) {
key = key ? key.toUpperCase() : null
if (app === undefined || app == undefine || process.env[key] == undefine)
return undefine
var config = defaults
var atOverrideVal = app === null ? false : atLeaf(app)
var atDefaultVal = defaults === null || atLeaf(defaults)
if (atOverrideVal || atDefaultVal) {
if (process.env[key] !== undefined) config = process.env[key]
else if (app !== null) config = app
if (config == '{{required}}')
throw Error(`Configure failed. Override or environment var required for config.${key}`)
if (config === false || config && atLeaf(config)) {
if (config != undefine) $logConfig(key, config)
return config
}
}
for (var attr in defaults) {
var childKey = key ? `${key}_${attr}` : attr
var childOverrides = app && app.hasOwnProperty(attr) ? app[attr] : null
config[attr] = mergeRecursive(childKey, defaults[attr], childOverrides)
if (config[attr] == undefine)
delete config[attr]
}
for (var attr in app) {
if (!(defaults||{}).hasOwnProperty(attr)) { // && app[attr]
var childKey = key ? `${key}_${attr}` : attr
config[attr] = mergeRecursive(childKey, null, app[attr])
if (config[attr] == undefine)
delete config[attr]
}
}
return config
}
|
javascript
|
function mergeRecursive(key, defaults, app) {
key = key ? key.toUpperCase() : null
if (app === undefined || app == undefine || process.env[key] == undefine)
return undefine
var config = defaults
var atOverrideVal = app === null ? false : atLeaf(app)
var atDefaultVal = defaults === null || atLeaf(defaults)
if (atOverrideVal || atDefaultVal) {
if (process.env[key] !== undefined) config = process.env[key]
else if (app !== null) config = app
if (config == '{{required}}')
throw Error(`Configure failed. Override or environment var required for config.${key}`)
if (config === false || config && atLeaf(config)) {
if (config != undefine) $logConfig(key, config)
return config
}
}
for (var attr in defaults) {
var childKey = key ? `${key}_${attr}` : attr
var childOverrides = app && app.hasOwnProperty(attr) ? app[attr] : null
config[attr] = mergeRecursive(childKey, defaults[attr], childOverrides)
if (config[attr] == undefine)
delete config[attr]
}
for (var attr in app) {
if (!(defaults||{}).hasOwnProperty(attr)) { // && app[attr]
var childKey = key ? `${key}_${attr}` : attr
config[attr] = mergeRecursive(childKey, null, app[attr])
if (config[attr] == undefine)
delete config[attr]
}
}
return config
}
|
[
"function",
"mergeRecursive",
"(",
"key",
",",
"defaults",
",",
"app",
")",
"{",
"key",
"=",
"key",
"?",
"key",
".",
"toUpperCase",
"(",
")",
":",
"null",
"if",
"(",
"app",
"===",
"undefined",
"||",
"app",
"==",
"undefine",
"||",
"process",
".",
"env",
"[",
"key",
"]",
"==",
"undefine",
")",
"return",
"undefine",
"var",
"config",
"=",
"defaults",
"var",
"atOverrideVal",
"=",
"app",
"===",
"null",
"?",
"false",
":",
"atLeaf",
"(",
"app",
")",
"var",
"atDefaultVal",
"=",
"defaults",
"===",
"null",
"||",
"atLeaf",
"(",
"defaults",
")",
"if",
"(",
"atOverrideVal",
"||",
"atDefaultVal",
")",
"{",
"if",
"(",
"process",
".",
"env",
"[",
"key",
"]",
"!==",
"undefined",
")",
"config",
"=",
"process",
".",
"env",
"[",
"key",
"]",
"else",
"if",
"(",
"app",
"!==",
"null",
")",
"config",
"=",
"app",
"if",
"(",
"config",
"==",
"'{{required}}'",
")",
"throw",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
"if",
"(",
"config",
"===",
"false",
"||",
"config",
"&&",
"atLeaf",
"(",
"config",
")",
")",
"{",
"if",
"(",
"config",
"!=",
"undefine",
")",
"$logConfig",
"(",
"key",
",",
"config",
")",
"return",
"config",
"}",
"}",
"for",
"(",
"var",
"attr",
"in",
"defaults",
")",
"{",
"var",
"childKey",
"=",
"key",
"?",
"`",
"${",
"key",
"}",
"${",
"attr",
"}",
"`",
":",
"attr",
"var",
"childOverrides",
"=",
"app",
"&&",
"app",
".",
"hasOwnProperty",
"(",
"attr",
")",
"?",
"app",
"[",
"attr",
"]",
":",
"null",
"config",
"[",
"attr",
"]",
"=",
"mergeRecursive",
"(",
"childKey",
",",
"defaults",
"[",
"attr",
"]",
",",
"childOverrides",
")",
"if",
"(",
"config",
"[",
"attr",
"]",
"==",
"undefine",
")",
"delete",
"config",
"[",
"attr",
"]",
"}",
"for",
"(",
"var",
"attr",
"in",
"app",
")",
"{",
"if",
"(",
"!",
"(",
"defaults",
"||",
"{",
"}",
")",
".",
"hasOwnProperty",
"(",
"attr",
")",
")",
"{",
"// && app[attr]",
"var",
"childKey",
"=",
"key",
"?",
"`",
"${",
"key",
"}",
"${",
"attr",
"}",
"`",
":",
"attr",
"config",
"[",
"attr",
"]",
"=",
"mergeRecursive",
"(",
"childKey",
",",
"null",
",",
"app",
"[",
"attr",
"]",
")",
"if",
"(",
"config",
"[",
"attr",
"]",
"==",
"undefine",
")",
"delete",
"config",
"[",
"attr",
"]",
"}",
"}",
"return",
"config",
"}"
] |
recusiveMerge(
Recursively traverse and merge
String @key to check for environment values to apply
Object @defaults (meanair default base config : configure.defaults.js)
Object @app (application specific sections / exclusions
@return tree (or leaf) of instance of config combining defaults,
app and environment vars
/ )
|
[
"recusiveMerge",
"(",
"Recursively",
"traverse",
"and",
"merge"
] |
54acca001b1e185c93992cb64c88478b0289a6e5
|
https://github.com/jkresner/meanair-server/blob/54acca001b1e185c93992cb64c88478b0289a6e5/lib/configure.merge.js#L17-L60
|
52,178
|
yanatan16/multipart-pipe
|
index.js
|
s3streamer
|
function s3streamer(s3, opts) {
var headers = (opts || {}).headers || { }
return function (file, filename, mimetype, encoding, callback) {
headers['Content-Type'] = mimetype
var buf = Buffer(0)
file.on('data', function (chunk) {
buf = Buffer.concat([buf, chunk])
})
file.on('end', function () {
s3.putBuffer(buf, filename, headers, function (err, s3resp) {
if (err) {
return callback(err)
} else if (s3resp.statusCode < 200 || s3resp.statusCode > 299) {
return callback(new Error('Error uploading to s3: ' + s3resp.statusCode), s3resp)
}
s3resp.resume() // This finalizes the stream response
callback()
})
})
}
}
|
javascript
|
function s3streamer(s3, opts) {
var headers = (opts || {}).headers || { }
return function (file, filename, mimetype, encoding, callback) {
headers['Content-Type'] = mimetype
var buf = Buffer(0)
file.on('data', function (chunk) {
buf = Buffer.concat([buf, chunk])
})
file.on('end', function () {
s3.putBuffer(buf, filename, headers, function (err, s3resp) {
if (err) {
return callback(err)
} else if (s3resp.statusCode < 200 || s3resp.statusCode > 299) {
return callback(new Error('Error uploading to s3: ' + s3resp.statusCode), s3resp)
}
s3resp.resume() // This finalizes the stream response
callback()
})
})
}
}
|
[
"function",
"s3streamer",
"(",
"s3",
",",
"opts",
")",
"{",
"var",
"headers",
"=",
"(",
"opts",
"||",
"{",
"}",
")",
".",
"headers",
"||",
"{",
"}",
"return",
"function",
"(",
"file",
",",
"filename",
",",
"mimetype",
",",
"encoding",
",",
"callback",
")",
"{",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"mimetype",
"var",
"buf",
"=",
"Buffer",
"(",
"0",
")",
"file",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"buf",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"chunk",
"]",
")",
"}",
")",
"file",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"s3",
".",
"putBuffer",
"(",
"buf",
",",
"filename",
",",
"headers",
",",
"function",
"(",
"err",
",",
"s3resp",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
"}",
"else",
"if",
"(",
"s3resp",
".",
"statusCode",
"<",
"200",
"||",
"s3resp",
".",
"statusCode",
">",
"299",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Error uploading to s3: '",
"+",
"s3resp",
".",
"statusCode",
")",
",",
"s3resp",
")",
"}",
"s3resp",
".",
"resume",
"(",
")",
"// This finalizes the stream response",
"callback",
"(",
")",
"}",
")",
"}",
")",
"}",
"}"
] |
An s3 streamer
|
[
"An",
"s3",
"streamer"
] |
676363d98dc04e898206175daa028253ec2f4cb9
|
https://github.com/yanatan16/multipart-pipe/blob/676363d98dc04e898206175daa028253ec2f4cb9/index.js#L86-L107
|
52,179
|
pattern-library/pattern-library-utilities
|
lib/gulp-tasks/patterns-import.js
|
function () {
'use strict';
// default options for angularTemplatecache gulp task
var options = {
config: {
compilePatternsOnImport: false,
dataSource: 'pattern',
dataFileName: 'pattern.yml',
htmlTemplateDest: './source/_patterns',
stylesDest: './source/css/scss',
scriptsDest: './source/js',
cssCompiler: 'sass', // sass, less, stylus, none
templateEngine: 'twig',
templateEngineOptions: {
base: 'node_modules/pattern-library/patterns/',
async: false
},
templateDonut: {
twig: './node_modules/pattern-importer/templates/donut.twig'
},
convertCategoryTitles: true
},
src: ['./node_modules/pattern-library/patterns/**/pattern.yml'],
taskName: 'patterns-import', // default task name
dependencies: [] // gulp tasks which should be run before this task
};
return options;
}
|
javascript
|
function () {
'use strict';
// default options for angularTemplatecache gulp task
var options = {
config: {
compilePatternsOnImport: false,
dataSource: 'pattern',
dataFileName: 'pattern.yml',
htmlTemplateDest: './source/_patterns',
stylesDest: './source/css/scss',
scriptsDest: './source/js',
cssCompiler: 'sass', // sass, less, stylus, none
templateEngine: 'twig',
templateEngineOptions: {
base: 'node_modules/pattern-library/patterns/',
async: false
},
templateDonut: {
twig: './node_modules/pattern-importer/templates/donut.twig'
},
convertCategoryTitles: true
},
src: ['./node_modules/pattern-library/patterns/**/pattern.yml'],
taskName: 'patterns-import', // default task name
dependencies: [] // gulp tasks which should be run before this task
};
return options;
}
|
[
"function",
"(",
")",
"{",
"'use strict'",
";",
"// default options for angularTemplatecache gulp task",
"var",
"options",
"=",
"{",
"config",
":",
"{",
"compilePatternsOnImport",
":",
"false",
",",
"dataSource",
":",
"'pattern'",
",",
"dataFileName",
":",
"'pattern.yml'",
",",
"htmlTemplateDest",
":",
"'./source/_patterns'",
",",
"stylesDest",
":",
"'./source/css/scss'",
",",
"scriptsDest",
":",
"'./source/js'",
",",
"cssCompiler",
":",
"'sass'",
",",
"// sass, less, stylus, none",
"templateEngine",
":",
"'twig'",
",",
"templateEngineOptions",
":",
"{",
"base",
":",
"'node_modules/pattern-library/patterns/'",
",",
"async",
":",
"false",
"}",
",",
"templateDonut",
":",
"{",
"twig",
":",
"'./node_modules/pattern-importer/templates/donut.twig'",
"}",
",",
"convertCategoryTitles",
":",
"true",
"}",
",",
"src",
":",
"[",
"'./node_modules/pattern-library/patterns/**/pattern.yml'",
"]",
",",
"taskName",
":",
"'patterns-import'",
",",
"// default task name",
"dependencies",
":",
"[",
"]",
"// gulp tasks which should be run before this task",
"}",
";",
"return",
"options",
";",
"}"
] |
Function to get default options for an implementation of patternlab-import
@return {Object} options an object of default patternlab-import options
|
[
"Function",
"to",
"get",
"default",
"options",
"for",
"an",
"implementation",
"of",
"patternlab",
"-",
"import"
] |
a0198f7bb698eb5b859576b11afa3d0ebd3e5911
|
https://github.com/pattern-library/pattern-library-utilities/blob/a0198f7bb698eb5b859576b11afa3d0ebd3e5911/lib/gulp-tasks/patterns-import.js#L15-L44
|
|
52,180
|
sendanor/nor-db
|
lib/mysql/Pool.js
|
Pool
|
function Pool(config) {
if(!(this instanceof Pool)) {
return new Pool(config);
}
var self = this;
if(!config) { throw new TypeError("config not set"); }
self._pool = require('mysql').createPool(config);
self._get_connection = Q.nfbind(self._pool.getConnection.bind(self._pool));
db.Pool.call(this);
}
|
javascript
|
function Pool(config) {
if(!(this instanceof Pool)) {
return new Pool(config);
}
var self = this;
if(!config) { throw new TypeError("config not set"); }
self._pool = require('mysql').createPool(config);
self._get_connection = Q.nfbind(self._pool.getConnection.bind(self._pool));
db.Pool.call(this);
}
|
[
"function",
"Pool",
"(",
"config",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Pool",
")",
")",
"{",
"return",
"new",
"Pool",
"(",
"config",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"config",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"config not set\"",
")",
";",
"}",
"self",
".",
"_pool",
"=",
"require",
"(",
"'mysql'",
")",
".",
"createPool",
"(",
"config",
")",
";",
"self",
".",
"_get_connection",
"=",
"Q",
".",
"nfbind",
"(",
"self",
".",
"_pool",
".",
"getConnection",
".",
"bind",
"(",
"self",
".",
"_pool",
")",
")",
";",
"db",
".",
"Pool",
".",
"call",
"(",
"this",
")",
";",
"}"
] |
Create MySQL connection pool object
|
[
"Create",
"MySQL",
"connection",
"pool",
"object"
] |
db4b78691956a49370fc9d9a4eed27e7d3720aeb
|
https://github.com/sendanor/nor-db/blob/db4b78691956a49370fc9d9a4eed27e7d3720aeb/lib/mysql/Pool.js#L11-L20
|
52,181
|
Psychopoulet/node-promfs
|
lib/extends/_filesToString.js
|
_filesToString
|
function _filesToString (files, encoding, separator, callback) {
if ("undefined" === typeof files) {
throw new ReferenceError("missing \"files\" argument");
}
else if ("object" !== typeof files || !(files instanceof Array)) {
throw new TypeError("\"files\" argument is not an Array");
}
else if ("undefined" === typeof callback && "undefined" === typeof separator && "undefined" === typeof encoding) {
throw new ReferenceError("missing \"callback\" argument");
}
else if ("function" !== typeof callback && "function" !== typeof separator && "function" !== typeof encoding) {
throw new TypeError("\"callback\" argument is not a function");
}
else {
let _callback = callback;
if ("undefined" === typeof _callback) {
if ("undefined" === typeof separator) {
_callback = encoding;
}
else {
_callback = separator;
}
}
filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {
return new Promise((resolve, reject) => {
let data = "";
let error = false;
readStream.once("error", (_err) => {
error = true;
reject(_err);
}).on("data", (chunk) => {
data += chunk.toString("string" === typeof encoding ? encoding : "utf8");
}).once("end", () => {
if (!error) {
resolve(data);
}
});
});
}).then((data) => {
_callback(null, data);
}).catch(_callback);
}
}
|
javascript
|
function _filesToString (files, encoding, separator, callback) {
if ("undefined" === typeof files) {
throw new ReferenceError("missing \"files\" argument");
}
else if ("object" !== typeof files || !(files instanceof Array)) {
throw new TypeError("\"files\" argument is not an Array");
}
else if ("undefined" === typeof callback && "undefined" === typeof separator && "undefined" === typeof encoding) {
throw new ReferenceError("missing \"callback\" argument");
}
else if ("function" !== typeof callback && "function" !== typeof separator && "function" !== typeof encoding) {
throw new TypeError("\"callback\" argument is not a function");
}
else {
let _callback = callback;
if ("undefined" === typeof _callback) {
if ("undefined" === typeof separator) {
_callback = encoding;
}
else {
_callback = separator;
}
}
filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {
return new Promise((resolve, reject) => {
let data = "";
let error = false;
readStream.once("error", (_err) => {
error = true;
reject(_err);
}).on("data", (chunk) => {
data += chunk.toString("string" === typeof encoding ? encoding : "utf8");
}).once("end", () => {
if (!error) {
resolve(data);
}
});
});
}).then((data) => {
_callback(null, data);
}).catch(_callback);
}
}
|
[
"function",
"_filesToString",
"(",
"files",
",",
"encoding",
",",
"separator",
",",
"callback",
")",
"{",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"files",
")",
"{",
"throw",
"new",
"ReferenceError",
"(",
"\"missing \\\"files\\\" argument\"",
")",
";",
"}",
"else",
"if",
"(",
"\"object\"",
"!==",
"typeof",
"files",
"||",
"!",
"(",
"files",
"instanceof",
"Array",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"files\\\" argument is not an Array\"",
")",
";",
"}",
"else",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"callback",
"&&",
"\"undefined\"",
"===",
"typeof",
"separator",
"&&",
"\"undefined\"",
"===",
"typeof",
"encoding",
")",
"{",
"throw",
"new",
"ReferenceError",
"(",
"\"missing \\\"callback\\\" argument\"",
")",
";",
"}",
"else",
"if",
"(",
"\"function\"",
"!==",
"typeof",
"callback",
"&&",
"\"function\"",
"!==",
"typeof",
"separator",
"&&",
"\"function\"",
"!==",
"typeof",
"encoding",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"callback\\\" argument is not a function\"",
")",
";",
"}",
"else",
"{",
"let",
"_callback",
"=",
"callback",
";",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"_callback",
")",
"{",
"if",
"(",
"\"undefined\"",
"===",
"typeof",
"separator",
")",
"{",
"_callback",
"=",
"encoding",
";",
"}",
"else",
"{",
"_callback",
"=",
"separator",
";",
"}",
"}",
"filesToStreamProm",
"(",
"files",
",",
"\"string\"",
"===",
"typeof",
"separator",
"?",
"separator",
":",
"\" \"",
")",
".",
"then",
"(",
"(",
"readStream",
")",
"=>",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"data",
"=",
"\"\"",
";",
"let",
"error",
"=",
"false",
";",
"readStream",
".",
"once",
"(",
"\"error\"",
",",
"(",
"_err",
")",
"=>",
"{",
"error",
"=",
"true",
";",
"reject",
"(",
"_err",
")",
";",
"}",
")",
".",
"on",
"(",
"\"data\"",
",",
"(",
"chunk",
")",
"=>",
"{",
"data",
"+=",
"chunk",
".",
"toString",
"(",
"\"string\"",
"===",
"typeof",
"encoding",
"?",
"encoding",
":",
"\"utf8\"",
")",
";",
"}",
")",
".",
"once",
"(",
"\"end\"",
",",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"resolve",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"data",
")",
"=>",
"{",
"_callback",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
".",
"catch",
"(",
"_callback",
")",
";",
"}",
"}"
] |
methods
Async filesToString
@param {Array} files : files to read
@param {string} encoding : encoding
@param {string} separator : files separator
@param {function|null} callback : operation's result
@returns {void}
|
[
"methods",
"Async",
"filesToString"
] |
016e272fc58c6ef6eae5ea551a0e8873f0ac20cc
|
https://github.com/Psychopoulet/node-promfs/blob/016e272fc58c6ef6eae5ea551a0e8873f0ac20cc/lib/extends/_filesToString.js#L25-L84
|
52,182
|
fnogatz/tconsole
|
lib/insert.js
|
insert
|
function insert (table, object, fields) {
var input = this
if (input instanceof Array) {
insertArray.call(input, table, object, fields)
} else {
insertObject.call(input, table, object, fields)
}
}
|
javascript
|
function insert (table, object, fields) {
var input = this
if (input instanceof Array) {
insertArray.call(input, table, object, fields)
} else {
insertObject.call(input, table, object, fields)
}
}
|
[
"function",
"insert",
"(",
"table",
",",
"object",
",",
"fields",
")",
"{",
"var",
"input",
"=",
"this",
"if",
"(",
"input",
"instanceof",
"Array",
")",
"{",
"insertArray",
".",
"call",
"(",
"input",
",",
"table",
",",
"object",
",",
"fields",
")",
"}",
"else",
"{",
"insertObject",
".",
"call",
"(",
"input",
",",
"table",
",",
"object",
",",
"fields",
")",
"}",
"}"
] |
Default renderer.insert function, `this` bound to the input.
@param {Table} table cli-table
@param {Object} object renderer object
@param {Array} fields fields to show
|
[
"Default",
"renderer",
".",
"insert",
"function",
"this",
"bound",
"to",
"the",
"input",
"."
] |
debcdaf916f7e8f43b35c4c907b585f5c1c69f0f
|
https://github.com/fnogatz/tconsole/blob/debcdaf916f7e8f43b35c4c907b585f5c1c69f0f/lib/insert.js#L11-L19
|
52,183
|
fnogatz/tconsole
|
lib/insert.js
|
insertArray
|
function insertArray (table, object, fields) {
var input = this
input.forEach(function addRow (entry, rowNo) {
var tableRow = fields.map(function cell (fieldName) {
return getCellContent.call(entry, object.fields[fieldName], rowNo)
})
table.push(tableRow)
})
}
|
javascript
|
function insertArray (table, object, fields) {
var input = this
input.forEach(function addRow (entry, rowNo) {
var tableRow = fields.map(function cell (fieldName) {
return getCellContent.call(entry, object.fields[fieldName], rowNo)
})
table.push(tableRow)
})
}
|
[
"function",
"insertArray",
"(",
"table",
",",
"object",
",",
"fields",
")",
"{",
"var",
"input",
"=",
"this",
"input",
".",
"forEach",
"(",
"function",
"addRow",
"(",
"entry",
",",
"rowNo",
")",
"{",
"var",
"tableRow",
"=",
"fields",
".",
"map",
"(",
"function",
"cell",
"(",
"fieldName",
")",
"{",
"return",
"getCellContent",
".",
"call",
"(",
"entry",
",",
"object",
".",
"fields",
"[",
"fieldName",
"]",
",",
"rowNo",
")",
"}",
")",
"table",
".",
"push",
"(",
"tableRow",
")",
"}",
")",
"}"
] |
renderer.insert function for rendering arrays,
`this` bound to the input.
@param {Table} table cli-table
@param {Object} object renderer object
@param {Array} fields fields to show
|
[
"renderer",
".",
"insert",
"function",
"for",
"rendering",
"arrays",
"this",
"bound",
"to",
"the",
"input",
"."
] |
debcdaf916f7e8f43b35c4c907b585f5c1c69f0f
|
https://github.com/fnogatz/tconsole/blob/debcdaf916f7e8f43b35c4c907b585f5c1c69f0f/lib/insert.js#L28-L37
|
52,184
|
fnogatz/tconsole
|
lib/insert.js
|
insertObject
|
function insertObject (table, object, fields) {
var input = this
fields.forEach(function addField (field) {
var cells = {}
cells[field] = getCellContent.call(input, object.fields[field])
table.push(cells)
})
}
|
javascript
|
function insertObject (table, object, fields) {
var input = this
fields.forEach(function addField (field) {
var cells = {}
cells[field] = getCellContent.call(input, object.fields[field])
table.push(cells)
})
}
|
[
"function",
"insertObject",
"(",
"table",
",",
"object",
",",
"fields",
")",
"{",
"var",
"input",
"=",
"this",
"fields",
".",
"forEach",
"(",
"function",
"addField",
"(",
"field",
")",
"{",
"var",
"cells",
"=",
"{",
"}",
"cells",
"[",
"field",
"]",
"=",
"getCellContent",
".",
"call",
"(",
"input",
",",
"object",
".",
"fields",
"[",
"field",
"]",
")",
"table",
".",
"push",
"(",
"cells",
")",
"}",
")",
"}"
] |
renderer.insert function for rendering objects,
`this` bound to the input.
@param {Table} table cli-table
@param {Object} object renderer object
@param {Array} fields fields to show
|
[
"renderer",
".",
"insert",
"function",
"for",
"rendering",
"objects",
"this",
"bound",
"to",
"the",
"input",
"."
] |
debcdaf916f7e8f43b35c4c907b585f5c1c69f0f
|
https://github.com/fnogatz/tconsole/blob/debcdaf916f7e8f43b35c4c907b585f5c1c69f0f/lib/insert.js#L46-L54
|
52,185
|
fnogatz/tconsole
|
lib/insert.js
|
getCellContent
|
function getCellContent (field) {
var entry = this
var args = Array.prototype.slice.call(arguments, 1)
if (typeof field === 'string') {
return field
}
if (typeof field === 'function') {
var value
try {
value = field.apply(entry, args)
} catch (e) {
value = '(err)'
}
if (value === undefined || value === null) {
return ''
}
return value.toString()
}
return ''
}
|
javascript
|
function getCellContent (field) {
var entry = this
var args = Array.prototype.slice.call(arguments, 1)
if (typeof field === 'string') {
return field
}
if (typeof field === 'function') {
var value
try {
value = field.apply(entry, args)
} catch (e) {
value = '(err)'
}
if (value === undefined || value === null) {
return ''
}
return value.toString()
}
return ''
}
|
[
"function",
"getCellContent",
"(",
"field",
")",
"{",
"var",
"entry",
"=",
"this",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
"if",
"(",
"typeof",
"field",
"===",
"'string'",
")",
"{",
"return",
"field",
"}",
"if",
"(",
"typeof",
"field",
"===",
"'function'",
")",
"{",
"var",
"value",
"try",
"{",
"value",
"=",
"field",
".",
"apply",
"(",
"entry",
",",
"args",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"value",
"=",
"'(err)'",
"}",
"if",
"(",
"value",
"===",
"undefined",
"||",
"value",
"===",
"null",
")",
"{",
"return",
"''",
"}",
"return",
"value",
".",
"toString",
"(",
")",
"}",
"return",
"''",
"}"
] |
Get the content of a cell. `field` is the function or string
to use. `this` should be bound to the actual entry.
Additional parameters are forwarded to the function `field`.
@param {Function|String} field
@return {String}
|
[
"Get",
"the",
"content",
"of",
"a",
"cell",
".",
"field",
"is",
"the",
"function",
"or",
"string",
"to",
"use",
".",
"this",
"should",
"be",
"bound",
"to",
"the",
"actual",
"entry",
".",
"Additional",
"parameters",
"are",
"forwarded",
"to",
"the",
"function",
"field",
"."
] |
debcdaf916f7e8f43b35c4c907b585f5c1c69f0f
|
https://github.com/fnogatz/tconsole/blob/debcdaf916f7e8f43b35c4c907b585f5c1c69f0f/lib/insert.js#L63-L84
|
52,186
|
wrote/read
|
build/index.js
|
readBuffer
|
async function readBuffer(path) {
const rs = createReadStream(path)
/** @type {Buffer} */
const res = await collect(rs, { binary: true })
return res
}
|
javascript
|
async function readBuffer(path) {
const rs = createReadStream(path)
/** @type {Buffer} */
const res = await collect(rs, { binary: true })
return res
}
|
[
"async",
"function",
"readBuffer",
"(",
"path",
")",
"{",
"const",
"rs",
"=",
"createReadStream",
"(",
"path",
")",
"/** @type {Buffer} */",
"const",
"res",
"=",
"await",
"collect",
"(",
"rs",
",",
"{",
"binary",
":",
"true",
"}",
")",
"return",
"res",
"}"
] |
Read a file as a buffer.
@param {string} path The path to the file to read.
|
[
"Read",
"a",
"file",
"as",
"a",
"buffer",
"."
] |
503ae9ab03e9654fea77276a076562afff3aeb24
|
https://github.com/wrote/read/blob/503ae9ab03e9654fea77276a076562afff3aeb24/build/index.js#L19-L24
|
52,187
|
rkamradt/meta-app-mem
|
index.js
|
function(data, done) {
this._data.push(this._clone(data));
var ret = this._data.length;
done(null, ret);
}
|
javascript
|
function(data, done) {
this._data.push(this._clone(data));
var ret = this._data.length;
done(null, ret);
}
|
[
"function",
"(",
"data",
",",
"done",
")",
"{",
"this",
".",
"_data",
".",
"push",
"(",
"this",
".",
"_clone",
"(",
"data",
")",
")",
";",
"var",
"ret",
"=",
"this",
".",
"_data",
".",
"length",
";",
"done",
"(",
"null",
",",
"ret",
")",
";",
"}"
] |
add an item to the store
@param {Object} data The item to store
@param {Function} done The callback when done
|
[
"add",
"an",
"item",
"to",
"the",
"store"
] |
9602b1eb44fad27cec9a05bcbd652dcf3202dbc7
|
https://github.com/rkamradt/meta-app-mem/blob/9602b1eb44fad27cec9a05bcbd652dcf3202dbc7/index.js#L41-L45
|
|
52,188
|
rkamradt/meta-app-mem
|
index.js
|
function(data, done) {
if(!this._key) {
done('no key found for metadata');
return;
}
var key = data[this._key.getName()];
var ix = -1;
for(var i = 0; i < this._data.length; i++) {
if(this._data[i][this._key.getName()] === key) {
ix = i;
break;
}
}
if(ix === -1) {
this._data.push(this._clone(data));
} else {
this._data[ix] = this._clone(data);
}
done(null);
}
|
javascript
|
function(data, done) {
if(!this._key) {
done('no key found for metadata');
return;
}
var key = data[this._key.getName()];
var ix = -1;
for(var i = 0; i < this._data.length; i++) {
if(this._data[i][this._key.getName()] === key) {
ix = i;
break;
}
}
if(ix === -1) {
this._data.push(this._clone(data));
} else {
this._data[ix] = this._clone(data);
}
done(null);
}
|
[
"function",
"(",
"data",
",",
"done",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_key",
")",
"{",
"done",
"(",
"'no key found for metadata'",
")",
";",
"return",
";",
"}",
"var",
"key",
"=",
"data",
"[",
"this",
".",
"_key",
".",
"getName",
"(",
")",
"]",
";",
"var",
"ix",
"=",
"-",
"1",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_data",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"_data",
"[",
"i",
"]",
"[",
"this",
".",
"_key",
".",
"getName",
"(",
")",
"]",
"===",
"key",
")",
"{",
"ix",
"=",
"i",
";",
"break",
";",
"}",
"}",
"if",
"(",
"ix",
"===",
"-",
"1",
")",
"{",
"this",
".",
"_data",
".",
"push",
"(",
"this",
".",
"_clone",
"(",
"data",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"_data",
"[",
"ix",
"]",
"=",
"this",
".",
"_clone",
"(",
"data",
")",
";",
"}",
"done",
"(",
"null",
")",
";",
"}"
] |
update an item in the store
@param {Object} data The item to update
@param {Function} done The callback when done
|
[
"update",
"an",
"item",
"in",
"the",
"store"
] |
9602b1eb44fad27cec9a05bcbd652dcf3202dbc7
|
https://github.com/rkamradt/meta-app-mem/blob/9602b1eb44fad27cec9a05bcbd652dcf3202dbc7/index.js#L51-L70
|
|
52,189
|
rkamradt/meta-app-mem
|
index.js
|
function(key, done) {
if(!this._key) {
done('no key found for metadata');
return;
}
var ret = null; // if not found return null
for(var i = 0; i < this._data.length; i++) {
if(this._data[i][this._key.getName()] === key) {
ret = this._clone(this._data[i]);
break;
}
}
done(null, ret);
}
|
javascript
|
function(key, done) {
if(!this._key) {
done('no key found for metadata');
return;
}
var ret = null; // if not found return null
for(var i = 0; i < this._data.length; i++) {
if(this._data[i][this._key.getName()] === key) {
ret = this._clone(this._data[i]);
break;
}
}
done(null, ret);
}
|
[
"function",
"(",
"key",
",",
"done",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_key",
")",
"{",
"done",
"(",
"'no key found for metadata'",
")",
";",
"return",
";",
"}",
"var",
"ret",
"=",
"null",
";",
"// if not found return null",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_data",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"_data",
"[",
"i",
"]",
"[",
"this",
".",
"_key",
".",
"getName",
"(",
")",
"]",
"===",
"key",
")",
"{",
"ret",
"=",
"this",
".",
"_clone",
"(",
"this",
".",
"_data",
"[",
"i",
"]",
")",
";",
"break",
";",
"}",
"}",
"done",
"(",
"null",
",",
"ret",
")",
";",
"}"
] |
return an item by id
@param {String} key The key value
@param {Function} done The callback when done
|
[
"return",
"an",
"item",
"by",
"id"
] |
9602b1eb44fad27cec9a05bcbd652dcf3202dbc7
|
https://github.com/rkamradt/meta-app-mem/blob/9602b1eb44fad27cec9a05bcbd652dcf3202dbc7/index.js#L87-L100
|
|
52,190
|
gethuman/pancakes-recipe
|
batch/db.purge/db.purge.batch.js
|
purgeResource
|
function purgeResource(resource, archive) {
if (!resource.purge) { return true; }
var criteria = resource.purge();
var deferred = Q.defer();
archive.bind(resource.name);
archive[resource.name].remove(criteria, function (err, results) {
err ? deferred.reject(err) : deferred.resolve(results);
});
return deferred.promise;
}
|
javascript
|
function purgeResource(resource, archive) {
if (!resource.purge) { return true; }
var criteria = resource.purge();
var deferred = Q.defer();
archive.bind(resource.name);
archive[resource.name].remove(criteria, function (err, results) {
err ? deferred.reject(err) : deferred.resolve(results);
});
return deferred.promise;
}
|
[
"function",
"purgeResource",
"(",
"resource",
",",
"archive",
")",
"{",
"if",
"(",
"!",
"resource",
".",
"purge",
")",
"{",
"return",
"true",
";",
"}",
"var",
"criteria",
"=",
"resource",
".",
"purge",
"(",
")",
";",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"archive",
".",
"bind",
"(",
"resource",
".",
"name",
")",
";",
"archive",
"[",
"resource",
".",
"name",
"]",
".",
"remove",
"(",
"criteria",
",",
"function",
"(",
"err",
",",
"results",
")",
"{",
"err",
"?",
"deferred",
".",
"reject",
"(",
"err",
")",
":",
"deferred",
".",
"resolve",
"(",
"results",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Purge one particular resource
@param resource
@param archive
|
[
"Purge",
"one",
"particular",
"resource"
] |
ea3feb8839e2edaf1b4577c052b8958953db4498
|
https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/batch/db.purge/db.purge.batch.js#L43-L54
|
52,191
|
billinghamj/resilient-mailer-mandrill
|
lib/mandrill-provider.js
|
MandrillProvider
|
function MandrillProvider(apiKey, options) {
if (typeof apiKey !== 'string') {
throw new Error('Invalid parameters');
}
options = options || {};
if (typeof options.async === 'undefined')
options.async = false;
if (typeof options.apiSecure === 'undefined')
options.apiSecure = true;
options.apiHostname = options.apiHostname || 'mandrillapp.com';
options.apiPort = options.apiPort || (options.apiSecure ? 443 : 80);
this.apiKey = apiKey;
this.options = options;
}
|
javascript
|
function MandrillProvider(apiKey, options) {
if (typeof apiKey !== 'string') {
throw new Error('Invalid parameters');
}
options = options || {};
if (typeof options.async === 'undefined')
options.async = false;
if (typeof options.apiSecure === 'undefined')
options.apiSecure = true;
options.apiHostname = options.apiHostname || 'mandrillapp.com';
options.apiPort = options.apiPort || (options.apiSecure ? 443 : 80);
this.apiKey = apiKey;
this.options = options;
}
|
[
"function",
"MandrillProvider",
"(",
"apiKey",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"apiKey",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid parameters'",
")",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"options",
".",
"async",
"===",
"'undefined'",
")",
"options",
".",
"async",
"=",
"false",
";",
"if",
"(",
"typeof",
"options",
".",
"apiSecure",
"===",
"'undefined'",
")",
"options",
".",
"apiSecure",
"=",
"true",
";",
"options",
".",
"apiHostname",
"=",
"options",
".",
"apiHostname",
"||",
"'mandrillapp.com'",
";",
"options",
".",
"apiPort",
"=",
"options",
".",
"apiPort",
"||",
"(",
"options",
".",
"apiSecure",
"?",
"443",
":",
"80",
")",
";",
"this",
".",
"apiKey",
"=",
"apiKey",
";",
"this",
".",
"options",
"=",
"options",
";",
"}"
] |
Creates an instance of the Mandrill email provider.
@constructor
@this {MandrillProvider}
@param {string} apiKey API Key for the Mandrill account.
@param {object} [options] Additional optional configuration.
@param {string} [options.async=false] See 'async' field: {@link https://mandrillapp.com/api/docs/messages.html#method-send}
@param {string} [options.ipPool] See: {@link http://help.mandrill.com/entries/24182062}
@param {boolean} [options.apiSecure=true] API connection protocol - true = HTTPS, false = HTTP
@param {string} [options.apiHostname=mandrillapp.com] Hostname for the API connection
@param {number} [options.apiPort] Port for the API connection - defaults to match the protocol (HTTPS-443, HTTP-80)
|
[
"Creates",
"an",
"instance",
"of",
"the",
"Mandrill",
"email",
"provider",
"."
] |
630e82a8c39d36361c42bde463a40afea993bfb9
|
https://github.com/billinghamj/resilient-mailer-mandrill/blob/630e82a8c39d36361c42bde463a40afea993bfb9/lib/mandrill-provider.js#L19-L37
|
52,192
|
MarkNijhof/client.express.js
|
src/client.express.ondomready.js
|
function (event){
//IE compatibility
event = event || window.event;
//Mozilla, Opera, & Legacy
if(event && event.type && (/DOMContentLoaded|load/).test(event.type)) {
fireDOMReady();
//Legacy
} else if(document.readyState) {
if ((/loaded|complete/).test(doc.readyState)) {
fireDOMReady();
//IE, courtesy of Diego Perini (http://javascript.nwbox.com/IEContentLoaded/)
} else if(document.documentElement.doScroll) {
try {
ready || document.documentElement.doScroll('left');
} catch(ex) {
return;
}
//If no error was thrown, the DOM must be ready
fireDOMReady();
}
}
}
|
javascript
|
function (event){
//IE compatibility
event = event || window.event;
//Mozilla, Opera, & Legacy
if(event && event.type && (/DOMContentLoaded|load/).test(event.type)) {
fireDOMReady();
//Legacy
} else if(document.readyState) {
if ((/loaded|complete/).test(doc.readyState)) {
fireDOMReady();
//IE, courtesy of Diego Perini (http://javascript.nwbox.com/IEContentLoaded/)
} else if(document.documentElement.doScroll) {
try {
ready || document.documentElement.doScroll('left');
} catch(ex) {
return;
}
//If no error was thrown, the DOM must be ready
fireDOMReady();
}
}
}
|
[
"function",
"(",
"event",
")",
"{",
"//IE compatibility",
"event",
"=",
"event",
"||",
"window",
".",
"event",
";",
"//Mozilla, Opera, & Legacy",
"if",
"(",
"event",
"&&",
"event",
".",
"type",
"&&",
"(",
"/",
"DOMContentLoaded|load",
"/",
")",
".",
"test",
"(",
"event",
".",
"type",
")",
")",
"{",
"fireDOMReady",
"(",
")",
";",
"//Legacy\t",
"}",
"else",
"if",
"(",
"document",
".",
"readyState",
")",
"{",
"if",
"(",
"(",
"/",
"loaded|complete",
"/",
")",
".",
"test",
"(",
"doc",
".",
"readyState",
")",
")",
"{",
"fireDOMReady",
"(",
")",
";",
"//IE, courtesy of Diego Perini (http://javascript.nwbox.com/IEContentLoaded/)",
"}",
"else",
"if",
"(",
"document",
".",
"documentElement",
".",
"doScroll",
")",
"{",
"try",
"{",
"ready",
"||",
"document",
".",
"documentElement",
".",
"doScroll",
"(",
"'left'",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"return",
";",
"}",
"//If no error was thrown, the DOM must be ready",
"fireDOMReady",
"(",
")",
";",
"}",
"}",
"}"
] |
Responsible for handling events and each tick of the interval
|
[
"Responsible",
"for",
"handling",
"events",
"and",
"each",
"tick",
"of",
"the",
"interval"
] |
8737f5885014e80f89a5e14cbeed6658e21d1f33
|
https://github.com/MarkNijhof/client.express.js/blob/8737f5885014e80f89a5e14cbeed6658e21d1f33/src/client.express.ondomready.js#L12-L33
|
|
52,193
|
MarkNijhof/client.express.js
|
src/client.express.ondomready.js
|
function() {
if (!ready) {
ready = true;
//Call the stack of onload functions in given context or window object
for (var i=0, len=stack.length; i < len; i++) {
stack[i][0].call(stack[i][1]);
}
//Clean up after the DOM is ready
if (document.removeEventListener) {
document.removeEventListener("DOMContentLoaded", onStateChange, false);
}
//Clear the interval
clearInterval(timer);
//Null the timer and event handlers to release memory
document.onreadystatechange = window.onload = timer = null;
}
}
|
javascript
|
function() {
if (!ready) {
ready = true;
//Call the stack of onload functions in given context or window object
for (var i=0, len=stack.length; i < len; i++) {
stack[i][0].call(stack[i][1]);
}
//Clean up after the DOM is ready
if (document.removeEventListener) {
document.removeEventListener("DOMContentLoaded", onStateChange, false);
}
//Clear the interval
clearInterval(timer);
//Null the timer and event handlers to release memory
document.onreadystatechange = window.onload = timer = null;
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"ready",
")",
"{",
"ready",
"=",
"true",
";",
"//Call the stack of onload functions in given context or window object",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"stack",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"stack",
"[",
"i",
"]",
"[",
"0",
"]",
".",
"call",
"(",
"stack",
"[",
"i",
"]",
"[",
"1",
"]",
")",
";",
"}",
"//Clean up after the DOM is ready",
"if",
"(",
"document",
".",
"removeEventListener",
")",
"{",
"document",
".",
"removeEventListener",
"(",
"\"DOMContentLoaded\"",
",",
"onStateChange",
",",
"false",
")",
";",
"}",
"//Clear the interval\t",
"clearInterval",
"(",
"timer",
")",
";",
"//Null the timer and event handlers to release memory",
"document",
".",
"onreadystatechange",
"=",
"window",
".",
"onload",
"=",
"timer",
"=",
"null",
";",
"}",
"}"
] |
Fires all the functions and cleans up memory
|
[
"Fires",
"all",
"the",
"functions",
"and",
"cleans",
"up",
"memory"
] |
8737f5885014e80f89a5e14cbeed6658e21d1f33
|
https://github.com/MarkNijhof/client.express.js/blob/8737f5885014e80f89a5e14cbeed6658e21d1f33/src/client.express.ondomready.js#L36-L52
|
|
52,194
|
vkiding/judpack-lib
|
src/hooks/HooksRunner.js
|
runScript
|
function runScript(script, context) {
if (typeof script.useModuleLoader == 'undefined') {
// if it is not explicitly defined whether we should use modeule loader or not
// we assume we should use module loader for .js files
script.useModuleLoader = path.extname(script.path).toLowerCase() == '.js';
}
var source;
var relativePath;
if (script.plugin) {
source = 'plugin ' + script.plugin.id;
relativePath = path.join('plugins', script.plugin.id, script.path);
} else if (script.useModuleLoader) {
source = 'config.xml';
relativePath = path.normalize(script.path);
} else {
source = 'hooks directory';
relativePath = path.join('hooks', context.hook, script.path);
}
events.emit('verbose', 'Executing script found in ' + source + ' for hook "' + context.hook + '": ' + relativePath);
if(script.useModuleLoader) {
return runScriptViaModuleLoader(script, context);
} else {
return runScriptViaChildProcessSpawn(script, context);
}
}
|
javascript
|
function runScript(script, context) {
if (typeof script.useModuleLoader == 'undefined') {
// if it is not explicitly defined whether we should use modeule loader or not
// we assume we should use module loader for .js files
script.useModuleLoader = path.extname(script.path).toLowerCase() == '.js';
}
var source;
var relativePath;
if (script.plugin) {
source = 'plugin ' + script.plugin.id;
relativePath = path.join('plugins', script.plugin.id, script.path);
} else if (script.useModuleLoader) {
source = 'config.xml';
relativePath = path.normalize(script.path);
} else {
source = 'hooks directory';
relativePath = path.join('hooks', context.hook, script.path);
}
events.emit('verbose', 'Executing script found in ' + source + ' for hook "' + context.hook + '": ' + relativePath);
if(script.useModuleLoader) {
return runScriptViaModuleLoader(script, context);
} else {
return runScriptViaChildProcessSpawn(script, context);
}
}
|
[
"function",
"runScript",
"(",
"script",
",",
"context",
")",
"{",
"if",
"(",
"typeof",
"script",
".",
"useModuleLoader",
"==",
"'undefined'",
")",
"{",
"// if it is not explicitly defined whether we should use modeule loader or not",
"// we assume we should use module loader for .js files",
"script",
".",
"useModuleLoader",
"=",
"path",
".",
"extname",
"(",
"script",
".",
"path",
")",
".",
"toLowerCase",
"(",
")",
"==",
"'.js'",
";",
"}",
"var",
"source",
";",
"var",
"relativePath",
";",
"if",
"(",
"script",
".",
"plugin",
")",
"{",
"source",
"=",
"'plugin '",
"+",
"script",
".",
"plugin",
".",
"id",
";",
"relativePath",
"=",
"path",
".",
"join",
"(",
"'plugins'",
",",
"script",
".",
"plugin",
".",
"id",
",",
"script",
".",
"path",
")",
";",
"}",
"else",
"if",
"(",
"script",
".",
"useModuleLoader",
")",
"{",
"source",
"=",
"'config.xml'",
";",
"relativePath",
"=",
"path",
".",
"normalize",
"(",
"script",
".",
"path",
")",
";",
"}",
"else",
"{",
"source",
"=",
"'hooks directory'",
";",
"relativePath",
"=",
"path",
".",
"join",
"(",
"'hooks'",
",",
"context",
".",
"hook",
",",
"script",
".",
"path",
")",
";",
"}",
"events",
".",
"emit",
"(",
"'verbose'",
",",
"'Executing script found in '",
"+",
"source",
"+",
"' for hook \"'",
"+",
"context",
".",
"hook",
"+",
"'\": '",
"+",
"relativePath",
")",
";",
"if",
"(",
"script",
".",
"useModuleLoader",
")",
"{",
"return",
"runScriptViaModuleLoader",
"(",
"script",
",",
"context",
")",
";",
"}",
"else",
"{",
"return",
"runScriptViaChildProcessSpawn",
"(",
"script",
",",
"context",
")",
";",
"}",
"}"
] |
Async runs single script file.
|
[
"Async",
"runs",
"single",
"script",
"file",
"."
] |
8657cecfec68221109279106adca8dbc81f430f4
|
https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/hooks/HooksRunner.js#L141-L169
|
52,195
|
vkiding/judpack-lib
|
src/hooks/HooksRunner.js
|
runScriptViaModuleLoader
|
function runScriptViaModuleLoader(script, context) {
if(!fs.existsSync(script.fullPath)) {
events.emit('warn', 'Script file does\'t exist and will be skipped: ' + script.fullPath);
return Q();
}
var scriptFn = require(script.fullPath);
context.scriptLocation = script.fullPath;
context.opts.plugin = script.plugin;
// We can't run script if it is a plain Node script - it will run its commands when we require it.
// This is not a desired case as we want to pass context, but added for compatibility.
if (scriptFn instanceof Function) {
// If hook is async it can return promise instance and we will handle it.
return Q(scriptFn(context));
} else {
return Q();
}
}
|
javascript
|
function runScriptViaModuleLoader(script, context) {
if(!fs.existsSync(script.fullPath)) {
events.emit('warn', 'Script file does\'t exist and will be skipped: ' + script.fullPath);
return Q();
}
var scriptFn = require(script.fullPath);
context.scriptLocation = script.fullPath;
context.opts.plugin = script.plugin;
// We can't run script if it is a plain Node script - it will run its commands when we require it.
// This is not a desired case as we want to pass context, but added for compatibility.
if (scriptFn instanceof Function) {
// If hook is async it can return promise instance and we will handle it.
return Q(scriptFn(context));
} else {
return Q();
}
}
|
[
"function",
"runScriptViaModuleLoader",
"(",
"script",
",",
"context",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"script",
".",
"fullPath",
")",
")",
"{",
"events",
".",
"emit",
"(",
"'warn'",
",",
"'Script file does\\'t exist and will be skipped: '",
"+",
"script",
".",
"fullPath",
")",
";",
"return",
"Q",
"(",
")",
";",
"}",
"var",
"scriptFn",
"=",
"require",
"(",
"script",
".",
"fullPath",
")",
";",
"context",
".",
"scriptLocation",
"=",
"script",
".",
"fullPath",
";",
"context",
".",
"opts",
".",
"plugin",
"=",
"script",
".",
"plugin",
";",
"// We can't run script if it is a plain Node script - it will run its commands when we require it.",
"// This is not a desired case as we want to pass context, but added for compatibility.",
"if",
"(",
"scriptFn",
"instanceof",
"Function",
")",
"{",
"// If hook is async it can return promise instance and we will handle it.",
"return",
"Q",
"(",
"scriptFn",
"(",
"context",
")",
")",
";",
"}",
"else",
"{",
"return",
"Q",
"(",
")",
";",
"}",
"}"
] |
Runs script using require.
Returns a promise.
|
[
"Runs",
"script",
"using",
"require",
".",
"Returns",
"a",
"promise",
"."
] |
8657cecfec68221109279106adca8dbc81f430f4
|
https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/hooks/HooksRunner.js#L174-L191
|
52,196
|
vkiding/judpack-lib
|
src/hooks/HooksRunner.js
|
runScriptViaChildProcessSpawn
|
function runScriptViaChildProcessSpawn(script, context) {
var opts = context.opts;
var command = script.fullPath;
var args = [opts.projectRoot];
if (fs.statSync(script.fullPath).isDirectory()) {
events.emit('verbose', 'Skipped directory "' + script.fullPath + '" within hook directory');
return Q();
}
if (isWindows) {
// TODO: Make shebang sniffing a setting (not everyone will want this).
var interpreter = extractSheBangInterpreter(script.fullPath);
// we have shebang, so try to run this script using correct interpreter
if (interpreter) {
args.unshift(command);
command = interpreter;
}
}
var execOpts = {cwd: opts.projectRoot, printCommand: true, stdio: 'inherit'};
execOpts.env = {};
execOpts.env.CORDOVA_VERSION = require('../../package').version;
execOpts.env.CORDOVA_PLATFORMS = opts.platforms ? opts.platforms.join() : '';
execOpts.env.CORDOVA_PLUGINS = opts.plugins ? opts.plugins.join() : '';
execOpts.env.CORDOVA_HOOK = script.fullPath;
execOpts.env.CORDOVA_CMDLINE = process.argv.join(' ');
return superspawn.spawn(command, args, execOpts)
.catch(function(err) {
// Don't treat non-executable files as errors. They could be READMEs, or Windows-only scripts.
if (!isWindows && err.code == 'EACCES') {
events.emit('verbose', 'Skipped non-executable file: ' + script.fullPath);
} else {
throw new Error('Hook failed with error code ' + err.code + ': ' + script.fullPath);
}
});
}
|
javascript
|
function runScriptViaChildProcessSpawn(script, context) {
var opts = context.opts;
var command = script.fullPath;
var args = [opts.projectRoot];
if (fs.statSync(script.fullPath).isDirectory()) {
events.emit('verbose', 'Skipped directory "' + script.fullPath + '" within hook directory');
return Q();
}
if (isWindows) {
// TODO: Make shebang sniffing a setting (not everyone will want this).
var interpreter = extractSheBangInterpreter(script.fullPath);
// we have shebang, so try to run this script using correct interpreter
if (interpreter) {
args.unshift(command);
command = interpreter;
}
}
var execOpts = {cwd: opts.projectRoot, printCommand: true, stdio: 'inherit'};
execOpts.env = {};
execOpts.env.CORDOVA_VERSION = require('../../package').version;
execOpts.env.CORDOVA_PLATFORMS = opts.platforms ? opts.platforms.join() : '';
execOpts.env.CORDOVA_PLUGINS = opts.plugins ? opts.plugins.join() : '';
execOpts.env.CORDOVA_HOOK = script.fullPath;
execOpts.env.CORDOVA_CMDLINE = process.argv.join(' ');
return superspawn.spawn(command, args, execOpts)
.catch(function(err) {
// Don't treat non-executable files as errors. They could be READMEs, or Windows-only scripts.
if (!isWindows && err.code == 'EACCES') {
events.emit('verbose', 'Skipped non-executable file: ' + script.fullPath);
} else {
throw new Error('Hook failed with error code ' + err.code + ': ' + script.fullPath);
}
});
}
|
[
"function",
"runScriptViaChildProcessSpawn",
"(",
"script",
",",
"context",
")",
"{",
"var",
"opts",
"=",
"context",
".",
"opts",
";",
"var",
"command",
"=",
"script",
".",
"fullPath",
";",
"var",
"args",
"=",
"[",
"opts",
".",
"projectRoot",
"]",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"script",
".",
"fullPath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"events",
".",
"emit",
"(",
"'verbose'",
",",
"'Skipped directory \"'",
"+",
"script",
".",
"fullPath",
"+",
"'\" within hook directory'",
")",
";",
"return",
"Q",
"(",
")",
";",
"}",
"if",
"(",
"isWindows",
")",
"{",
"// TODO: Make shebang sniffing a setting (not everyone will want this).",
"var",
"interpreter",
"=",
"extractSheBangInterpreter",
"(",
"script",
".",
"fullPath",
")",
";",
"// we have shebang, so try to run this script using correct interpreter",
"if",
"(",
"interpreter",
")",
"{",
"args",
".",
"unshift",
"(",
"command",
")",
";",
"command",
"=",
"interpreter",
";",
"}",
"}",
"var",
"execOpts",
"=",
"{",
"cwd",
":",
"opts",
".",
"projectRoot",
",",
"printCommand",
":",
"true",
",",
"stdio",
":",
"'inherit'",
"}",
";",
"execOpts",
".",
"env",
"=",
"{",
"}",
";",
"execOpts",
".",
"env",
".",
"CORDOVA_VERSION",
"=",
"require",
"(",
"'../../package'",
")",
".",
"version",
";",
"execOpts",
".",
"env",
".",
"CORDOVA_PLATFORMS",
"=",
"opts",
".",
"platforms",
"?",
"opts",
".",
"platforms",
".",
"join",
"(",
")",
":",
"''",
";",
"execOpts",
".",
"env",
".",
"CORDOVA_PLUGINS",
"=",
"opts",
".",
"plugins",
"?",
"opts",
".",
"plugins",
".",
"join",
"(",
")",
":",
"''",
";",
"execOpts",
".",
"env",
".",
"CORDOVA_HOOK",
"=",
"script",
".",
"fullPath",
";",
"execOpts",
".",
"env",
".",
"CORDOVA_CMDLINE",
"=",
"process",
".",
"argv",
".",
"join",
"(",
"' '",
")",
";",
"return",
"superspawn",
".",
"spawn",
"(",
"command",
",",
"args",
",",
"execOpts",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"// Don't treat non-executable files as errors. They could be READMEs, or Windows-only scripts.",
"if",
"(",
"!",
"isWindows",
"&&",
"err",
".",
"code",
"==",
"'EACCES'",
")",
"{",
"events",
".",
"emit",
"(",
"'verbose'",
",",
"'Skipped non-executable file: '",
"+",
"script",
".",
"fullPath",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Hook failed with error code '",
"+",
"err",
".",
"code",
"+",
"': '",
"+",
"script",
".",
"fullPath",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Runs script using child_process spawn method.
Returns a promise.
|
[
"Runs",
"script",
"using",
"child_process",
"spawn",
"method",
".",
"Returns",
"a",
"promise",
"."
] |
8657cecfec68221109279106adca8dbc81f430f4
|
https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/hooks/HooksRunner.js#L196-L233
|
52,197
|
vkiding/judpack-lib
|
src/hooks/HooksRunner.js
|
extractSheBangInterpreter
|
function extractSheBangInterpreter(fullpath) {
var fileChunk;
var octetsRead;
var fileData;
var hookFd = fs.openSync(fullpath, 'r');
try {
// this is a modern cluster size. no need to read less
fileData = new Buffer(4096);
octetsRead = fs.readSync(hookFd, fileData, 0, 4096, 0);
fileChunk = fileData.toString();
} finally {
fs.closeSync(hookFd);
}
var hookCmd, shMatch;
// Filter out /usr/bin/env so that "/usr/bin/env node" works like "node".
var shebangMatch = fileChunk.match(/^#!(?:\/usr\/bin\/env )?([^\r\n]+)/m);
if (octetsRead == 4096 && !fileChunk.match(/[\r\n]/))
events.emit('warn', 'shebang is too long for "' + fullpath + '"');
if (shebangMatch)
hookCmd = shebangMatch[1];
// Likewise, make /usr/bin/bash work like "bash".
if (hookCmd)
shMatch = hookCmd.match(/bin\/((?:ba)?sh)$/);
if (shMatch)
hookCmd = shMatch[1];
return hookCmd;
}
|
javascript
|
function extractSheBangInterpreter(fullpath) {
var fileChunk;
var octetsRead;
var fileData;
var hookFd = fs.openSync(fullpath, 'r');
try {
// this is a modern cluster size. no need to read less
fileData = new Buffer(4096);
octetsRead = fs.readSync(hookFd, fileData, 0, 4096, 0);
fileChunk = fileData.toString();
} finally {
fs.closeSync(hookFd);
}
var hookCmd, shMatch;
// Filter out /usr/bin/env so that "/usr/bin/env node" works like "node".
var shebangMatch = fileChunk.match(/^#!(?:\/usr\/bin\/env )?([^\r\n]+)/m);
if (octetsRead == 4096 && !fileChunk.match(/[\r\n]/))
events.emit('warn', 'shebang is too long for "' + fullpath + '"');
if (shebangMatch)
hookCmd = shebangMatch[1];
// Likewise, make /usr/bin/bash work like "bash".
if (hookCmd)
shMatch = hookCmd.match(/bin\/((?:ba)?sh)$/);
if (shMatch)
hookCmd = shMatch[1];
return hookCmd;
}
|
[
"function",
"extractSheBangInterpreter",
"(",
"fullpath",
")",
"{",
"var",
"fileChunk",
";",
"var",
"octetsRead",
";",
"var",
"fileData",
";",
"var",
"hookFd",
"=",
"fs",
".",
"openSync",
"(",
"fullpath",
",",
"'r'",
")",
";",
"try",
"{",
"// this is a modern cluster size. no need to read less",
"fileData",
"=",
"new",
"Buffer",
"(",
"4096",
")",
";",
"octetsRead",
"=",
"fs",
".",
"readSync",
"(",
"hookFd",
",",
"fileData",
",",
"0",
",",
"4096",
",",
"0",
")",
";",
"fileChunk",
"=",
"fileData",
".",
"toString",
"(",
")",
";",
"}",
"finally",
"{",
"fs",
".",
"closeSync",
"(",
"hookFd",
")",
";",
"}",
"var",
"hookCmd",
",",
"shMatch",
";",
"// Filter out /usr/bin/env so that \"/usr/bin/env node\" works like \"node\".",
"var",
"shebangMatch",
"=",
"fileChunk",
".",
"match",
"(",
"/",
"^#!(?:\\/usr\\/bin\\/env )?([^\\r\\n]+)",
"/",
"m",
")",
";",
"if",
"(",
"octetsRead",
"==",
"4096",
"&&",
"!",
"fileChunk",
".",
"match",
"(",
"/",
"[\\r\\n]",
"/",
")",
")",
"events",
".",
"emit",
"(",
"'warn'",
",",
"'shebang is too long for \"'",
"+",
"fullpath",
"+",
"'\"'",
")",
";",
"if",
"(",
"shebangMatch",
")",
"hookCmd",
"=",
"shebangMatch",
"[",
"1",
"]",
";",
"// Likewise, make /usr/bin/bash work like \"bash\".",
"if",
"(",
"hookCmd",
")",
"shMatch",
"=",
"hookCmd",
".",
"match",
"(",
"/",
"bin\\/((?:ba)?sh)$",
"/",
")",
";",
"if",
"(",
"shMatch",
")",
"hookCmd",
"=",
"shMatch",
"[",
"1",
"]",
";",
"return",
"hookCmd",
";",
"}"
] |
Extracts shebang interpreter from script' source.
|
[
"Extracts",
"shebang",
"interpreter",
"from",
"script",
"source",
"."
] |
8657cecfec68221109279106adca8dbc81f430f4
|
https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/hooks/HooksRunner.js#L237-L264
|
52,198
|
nbrownus/ppunit
|
lib/PPUnit.js
|
function (options) {
var self = this
PPUnit.super_.call(self)
options = options || {}
self.concurrency = options.concurrency || -1
self.rootSuite = new Suite(undefined)
self.rootSuite.timeout(2000)
self.rootSuite.globallyExclusive()
self.rootSuite.locallyExclusiveTests()
self.allTests = []
self.failures = []
self.tickId = 0
self.stats = {
suites: 0
, tests: 0
, skipped: 0
, passes: 0
, failures: 0
, completed: 0
, startTime: 0
, maxConcurrency: 0
, currentlyRunning: 0
, end: undefined
, duration: undefined
}
self._queue = []
self._nextId = 1
self._files = []
self._bailing = false
process.on('SIGINT', function () {
self._bail()
})
}
|
javascript
|
function (options) {
var self = this
PPUnit.super_.call(self)
options = options || {}
self.concurrency = options.concurrency || -1
self.rootSuite = new Suite(undefined)
self.rootSuite.timeout(2000)
self.rootSuite.globallyExclusive()
self.rootSuite.locallyExclusiveTests()
self.allTests = []
self.failures = []
self.tickId = 0
self.stats = {
suites: 0
, tests: 0
, skipped: 0
, passes: 0
, failures: 0
, completed: 0
, startTime: 0
, maxConcurrency: 0
, currentlyRunning: 0
, end: undefined
, duration: undefined
}
self._queue = []
self._nextId = 1
self._files = []
self._bailing = false
process.on('SIGINT', function () {
self._bail()
})
}
|
[
"function",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
"PPUnit",
".",
"super_",
".",
"call",
"(",
"self",
")",
"options",
"=",
"options",
"||",
"{",
"}",
"self",
".",
"concurrency",
"=",
"options",
".",
"concurrency",
"||",
"-",
"1",
"self",
".",
"rootSuite",
"=",
"new",
"Suite",
"(",
"undefined",
")",
"self",
".",
"rootSuite",
".",
"timeout",
"(",
"2000",
")",
"self",
".",
"rootSuite",
".",
"globallyExclusive",
"(",
")",
"self",
".",
"rootSuite",
".",
"locallyExclusiveTests",
"(",
")",
"self",
".",
"allTests",
"=",
"[",
"]",
"self",
".",
"failures",
"=",
"[",
"]",
"self",
".",
"tickId",
"=",
"0",
"self",
".",
"stats",
"=",
"{",
"suites",
":",
"0",
",",
"tests",
":",
"0",
",",
"skipped",
":",
"0",
",",
"passes",
":",
"0",
",",
"failures",
":",
"0",
",",
"completed",
":",
"0",
",",
"startTime",
":",
"0",
",",
"maxConcurrency",
":",
"0",
",",
"currentlyRunning",
":",
"0",
",",
"end",
":",
"undefined",
",",
"duration",
":",
"undefined",
"}",
"self",
".",
"_queue",
"=",
"[",
"]",
"self",
".",
"_nextId",
"=",
"1",
"self",
".",
"_files",
"=",
"[",
"]",
"self",
".",
"_bailing",
"=",
"false",
"process",
".",
"on",
"(",
"'SIGINT'",
",",
"function",
"(",
")",
"{",
"self",
".",
"_bail",
"(",
")",
"}",
")",
"}"
] |
Creates a new PPUnit object
@constructor
|
[
"Creates",
"a",
"new",
"PPUnit",
"object"
] |
dcce602497d9548ce9085a8db115e65561dcc3de
|
https://github.com/nbrownus/ppunit/blob/dcce602497d9548ce9085a8db115e65561dcc3de/lib/PPUnit.js#L14-L53
|
|
52,199
|
deftly/node-deftly
|
src/log.js
|
addAdapter
|
function addAdapter (state, name, config, logger) {
if (_.isFunction(name)) {
logger = name
name = logger.name
config = config || {}
} else if (_.isFunction(config)) {
logger = config
if (_.isObject(name)) {
config = name
name = logger.name
} else {
config = {}
}
} else if (_.isObject(name)) {
logger = name
name = logger.name
config = config || {}
} else if (config && config.fatal) {
logger = config
config = {}
}
addLogger(state, name, config, logger)
}
|
javascript
|
function addAdapter (state, name, config, logger) {
if (_.isFunction(name)) {
logger = name
name = logger.name
config = config || {}
} else if (_.isFunction(config)) {
logger = config
if (_.isObject(name)) {
config = name
name = logger.name
} else {
config = {}
}
} else if (_.isObject(name)) {
logger = name
name = logger.name
config = config || {}
} else if (config && config.fatal) {
logger = config
config = {}
}
addLogger(state, name, config, logger)
}
|
[
"function",
"addAdapter",
"(",
"state",
",",
"name",
",",
"config",
",",
"logger",
")",
"{",
"if",
"(",
"_",
".",
"isFunction",
"(",
"name",
")",
")",
"{",
"logger",
"=",
"name",
"name",
"=",
"logger",
".",
"name",
"config",
"=",
"config",
"||",
"{",
"}",
"}",
"else",
"if",
"(",
"_",
".",
"isFunction",
"(",
"config",
")",
")",
"{",
"logger",
"=",
"config",
"if",
"(",
"_",
".",
"isObject",
"(",
"name",
")",
")",
"{",
"config",
"=",
"name",
"name",
"=",
"logger",
".",
"name",
"}",
"else",
"{",
"config",
"=",
"{",
"}",
"}",
"}",
"else",
"if",
"(",
"_",
".",
"isObject",
"(",
"name",
")",
")",
"{",
"logger",
"=",
"name",
"name",
"=",
"logger",
".",
"name",
"config",
"=",
"config",
"||",
"{",
"}",
"}",
"else",
"if",
"(",
"config",
"&&",
"config",
".",
"fatal",
")",
"{",
"logger",
"=",
"config",
"config",
"=",
"{",
"}",
"}",
"addLogger",
"(",
"state",
",",
"name",
",",
"config",
",",
"logger",
")",
"}"
] |
normalizes arguments for logger creation from a user supplied object or function
|
[
"normalizes",
"arguments",
"for",
"logger",
"creation",
"from",
"a",
"user",
"supplied",
"object",
"or",
"function"
] |
0c34205fd6726356b69bcdd6dec4fcba55027af6
|
https://github.com/deftly/node-deftly/blob/0c34205fd6726356b69bcdd6dec4fcba55027af6/src/log.js#L27-L49
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.