id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
56,800 | oleics/node-xcouch | registry.js | setDatabaseSecurity | function setDatabaseSecurity(name, cb) {
// Get _security first
getSecurity(name, function(err, d) {
if(err) return cb(err)
// Make name an admin
if(d.admins.names.indexOf(name) === -1) {
d.admins.names.push(name)
}
// Make name a reader
if(d.readers.names.indexOf(name) === -1) {
d.readers.names.push(name)
}
// Merge with _security template
d = mergeSecurity(_security, d)
// Apply changes
setSecurity(name, d, function(err) {
if(err) return cb(err)
cb()
})
})
} | javascript | function setDatabaseSecurity(name, cb) {
// Get _security first
getSecurity(name, function(err, d) {
if(err) return cb(err)
// Make name an admin
if(d.admins.names.indexOf(name) === -1) {
d.admins.names.push(name)
}
// Make name a reader
if(d.readers.names.indexOf(name) === -1) {
d.readers.names.push(name)
}
// Merge with _security template
d = mergeSecurity(_security, d)
// Apply changes
setSecurity(name, d, function(err) {
if(err) return cb(err)
cb()
})
})
} | [
"function",
"setDatabaseSecurity",
"(",
"name",
",",
"cb",
")",
"{",
"// Get _security first",
"getSecurity",
"(",
"name",
",",
"function",
"(",
"err",
",",
"d",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"// Make name an admin",
"if",
"(",
"d",
".",
"admins",
".",
"names",
".",
"indexOf",
"(",
"name",
")",
"===",
"-",
"1",
")",
"{",
"d",
".",
"admins",
".",
"names",
".",
"push",
"(",
"name",
")",
"}",
"// Make name a reader",
"if",
"(",
"d",
".",
"readers",
".",
"names",
".",
"indexOf",
"(",
"name",
")",
"===",
"-",
"1",
")",
"{",
"d",
".",
"readers",
".",
"names",
".",
"push",
"(",
"name",
")",
"}",
"// Merge with _security template",
"d",
"=",
"mergeSecurity",
"(",
"_security",
",",
"d",
")",
"// Apply changes",
"setSecurity",
"(",
"name",
",",
"d",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"cb",
"(",
")",
"}",
")",
"}",
")",
"}"
] | Sets the _security document of a database | [
"Sets",
"the",
"_security",
"document",
"of",
"a",
"database"
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L217-L241 |
56,801 | oleics/node-xcouch | registry.js | loginUser | function loginUser(name, pass, cb) {
// Get the user
var db = nano().use(user_dbname)
db.get(user_namespace+':'+name, function(err, doc) {
if(err) return cb(err)
// Check pass
var hash = crypto.createHash('sha1')
hash.update(pass)
hash.update(doc.salt)
var password_sha = hash.digest('hex')
if(doc.password_sha === password_sha) {
return cb(null, doc)
}
cb(new Error('Access denied.'))
})
} | javascript | function loginUser(name, pass, cb) {
// Get the user
var db = nano().use(user_dbname)
db.get(user_namespace+':'+name, function(err, doc) {
if(err) return cb(err)
// Check pass
var hash = crypto.createHash('sha1')
hash.update(pass)
hash.update(doc.salt)
var password_sha = hash.digest('hex')
if(doc.password_sha === password_sha) {
return cb(null, doc)
}
cb(new Error('Access denied.'))
})
} | [
"function",
"loginUser",
"(",
"name",
",",
"pass",
",",
"cb",
")",
"{",
"// Get the user",
"var",
"db",
"=",
"nano",
"(",
")",
".",
"use",
"(",
"user_dbname",
")",
"db",
".",
"get",
"(",
"user_namespace",
"+",
"':'",
"+",
"name",
",",
"function",
"(",
"err",
",",
"doc",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"// Check pass",
"var",
"hash",
"=",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
"hash",
".",
"update",
"(",
"pass",
")",
"hash",
".",
"update",
"(",
"doc",
".",
"salt",
")",
"var",
"password_sha",
"=",
"hash",
".",
"digest",
"(",
"'hex'",
")",
"if",
"(",
"doc",
".",
"password_sha",
"===",
"password_sha",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"doc",
")",
"}",
"cb",
"(",
"new",
"Error",
"(",
"'Access denied.'",
")",
")",
"}",
")",
"}"
] | Checks loginUser credenciales | [
"Checks",
"loginUser",
"credenciales"
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L244-L261 |
56,802 | oleics/node-xcouch | registry.js | destroyDatabase | function destroyDatabase(name, cb) {
if(name === user_dbname)
throw new Error('We never ever delete that database.')
nano().db.destroy(name, function(err) {
if(err && err.status_code !== 404) return cb(err)
cb(null, err ? false : true)
})
} | javascript | function destroyDatabase(name, cb) {
if(name === user_dbname)
throw new Error('We never ever delete that database.')
nano().db.destroy(name, function(err) {
if(err && err.status_code !== 404) return cb(err)
cb(null, err ? false : true)
})
} | [
"function",
"destroyDatabase",
"(",
"name",
",",
"cb",
")",
"{",
"if",
"(",
"name",
"===",
"user_dbname",
")",
"throw",
"new",
"Error",
"(",
"'We never ever delete that database.'",
")",
"nano",
"(",
")",
".",
"db",
".",
"destroy",
"(",
"name",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"status_code",
"!==",
"404",
")",
"return",
"cb",
"(",
"err",
")",
"cb",
"(",
"null",
",",
"err",
"?",
"false",
":",
"true",
")",
"}",
")",
"}"
] | Destroys a database | [
"Destroys",
"a",
"database"
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L264-L271 |
56,803 | oleics/node-xcouch | registry.js | destroyUser | function destroyUser(name, pass, cb) {
loginUser(name, pass, function(err, user) {
if(err) return cb(err)
nano().use(user_dbname).destroy(user._id, user._rev, function(err, doc) {
if(err) return cb(err)
user._id = doc.id
user._rev = doc.rev
destroyDatabase(name, function(err) {
if(err) return cb(err)
cb(null, user)
})
})
})
// var db = nano().use(user_dbname)
// db.head(user_namespace+':'+name, function(err, b, h) {
// if(err) return cb(err)
// db.destroy(user_namespace+':'+name, JSON.parse(h.etag), function(err, doc) {
// if(err) return cb(err)
// destroyDatabase(name, function(err) {
// if(err) return cb(err)
// cb(null, doc)
// })
// })
// })
} | javascript | function destroyUser(name, pass, cb) {
loginUser(name, pass, function(err, user) {
if(err) return cb(err)
nano().use(user_dbname).destroy(user._id, user._rev, function(err, doc) {
if(err) return cb(err)
user._id = doc.id
user._rev = doc.rev
destroyDatabase(name, function(err) {
if(err) return cb(err)
cb(null, user)
})
})
})
// var db = nano().use(user_dbname)
// db.head(user_namespace+':'+name, function(err, b, h) {
// if(err) return cb(err)
// db.destroy(user_namespace+':'+name, JSON.parse(h.etag), function(err, doc) {
// if(err) return cb(err)
// destroyDatabase(name, function(err) {
// if(err) return cb(err)
// cb(null, doc)
// })
// })
// })
} | [
"function",
"destroyUser",
"(",
"name",
",",
"pass",
",",
"cb",
")",
"{",
"loginUser",
"(",
"name",
",",
"pass",
",",
"function",
"(",
"err",
",",
"user",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"nano",
"(",
")",
".",
"use",
"(",
"user_dbname",
")",
".",
"destroy",
"(",
"user",
".",
"_id",
",",
"user",
".",
"_rev",
",",
"function",
"(",
"err",
",",
"doc",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"user",
".",
"_id",
"=",
"doc",
".",
"id",
"user",
".",
"_rev",
"=",
"doc",
".",
"rev",
"destroyDatabase",
"(",
"name",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"cb",
"(",
"null",
",",
"user",
")",
"}",
")",
"}",
")",
"}",
")",
"// var db = nano().use(user_dbname)",
"// db.head(user_namespace+':'+name, function(err, b, h) {",
"// if(err) return cb(err)",
"// db.destroy(user_namespace+':'+name, JSON.parse(h.etag), function(err, doc) {",
"// if(err) return cb(err)",
"// destroyDatabase(name, function(err) {",
"// if(err) return cb(err)",
"// cb(null, doc)",
"// })",
"// })",
"// })",
"}"
] | Destroys a user AND her database | [
"Destroys",
"a",
"user",
"AND",
"her",
"database"
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L274-L298 |
56,804 | commenthol/streamss | lib/jsonarray.js | JsonArray | function JsonArray (options) {
if (!(this instanceof JsonArray)) {
return new JsonArray(options)
}
this.options = Object.assign({}, options, { objectMode: true })
this.count = 0
this.map = ['[\n', ',\n', '\n]\n']
if (this.options.validJson === false) {
this.map = ['', '\n', '\n']
}
if (this.options.stringify) {
this._transform = this._stringify
this._flush = function (done) {
this.push(this.map[2])
setTimeout(function () {
done()
}, 2)
}
} else {
this._transform = this._parse
}
Transform.call(this, _omit(this.options, ['error', 'validJson', 'stringify']))
return this
} | javascript | function JsonArray (options) {
if (!(this instanceof JsonArray)) {
return new JsonArray(options)
}
this.options = Object.assign({}, options, { objectMode: true })
this.count = 0
this.map = ['[\n', ',\n', '\n]\n']
if (this.options.validJson === false) {
this.map = ['', '\n', '\n']
}
if (this.options.stringify) {
this._transform = this._stringify
this._flush = function (done) {
this.push(this.map[2])
setTimeout(function () {
done()
}, 2)
}
} else {
this._transform = this._parse
}
Transform.call(this, _omit(this.options, ['error', 'validJson', 'stringify']))
return this
} | [
"function",
"JsonArray",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"JsonArray",
")",
")",
"{",
"return",
"new",
"JsonArray",
"(",
"options",
")",
"}",
"this",
".",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
",",
"{",
"objectMode",
":",
"true",
"}",
")",
"this",
".",
"count",
"=",
"0",
"this",
".",
"map",
"=",
"[",
"'[\\n'",
",",
"',\\n'",
",",
"'\\n]\\n'",
"]",
"if",
"(",
"this",
".",
"options",
".",
"validJson",
"===",
"false",
")",
"{",
"this",
".",
"map",
"=",
"[",
"''",
",",
"'\\n'",
",",
"'\\n'",
"]",
"}",
"if",
"(",
"this",
".",
"options",
".",
"stringify",
")",
"{",
"this",
".",
"_transform",
"=",
"this",
".",
"_stringify",
"this",
".",
"_flush",
"=",
"function",
"(",
"done",
")",
"{",
"this",
".",
"push",
"(",
"this",
".",
"map",
"[",
"2",
"]",
")",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"done",
"(",
")",
"}",
",",
"2",
")",
"}",
"}",
"else",
"{",
"this",
".",
"_transform",
"=",
"this",
".",
"_parse",
"}",
"Transform",
".",
"call",
"(",
"this",
",",
"_omit",
"(",
"this",
".",
"options",
",",
"[",
"'error'",
",",
"'validJson'",
",",
"'stringify'",
"]",
")",
")",
"return",
"this",
"}"
] | JSON.parse a line and push as object down the pipe.
If `stringify: true` is set, a received object is stringified with JSON.stringify
The output of the stream will be a valid JSON array.
NOTE: Requires that the stream is split beforehand using `Split` or `SplitLine`.
@constructor
@param {Object} [options] - Stream Options `{encoding, highWaterMark, decodeStrings, ...}`
@param {Boolean} options.error - Emit parsing errors as `Error` objects. Default=false.
@param {Boolean} options.validJson - Write out a valid json file, which can be parsed as a whole. Default=true.
@param {Boolean} options.stringify - Transforms an object into a string using JSON.stringify. Default=false.
@return {Transform} A transform stream | [
"JSON",
".",
"parse",
"a",
"line",
"and",
"push",
"as",
"object",
"down",
"the",
"pipe",
"."
] | cfef5d0ed30c7efe002018886e2e843c91d3558f | https://github.com/commenthol/streamss/blob/cfef5d0ed30c7efe002018886e2e843c91d3558f/lib/jsonarray.js#L29-L57 |
56,805 | seiyugi/debuguy | lib/parser.js | pr_parse | function pr_parse(options) {
this.traverse(options, function (dir, item, out) {
fs.readFile(dir + item, function(err, data) {
console.log('adding log ' + dir + item);
if (err) {
console.log(err);
console.log(data);
return;
}
var source = data.toString();
var output;
// if no match in the file
if (!source.match(regex)) {
return;
}
output = source.replace(regex, replacer);
fs.writeFile(out + item, output, function(err) {
if (err) {
console.log(err);
} else {
console.log(out + item + ' was saved!');
}
});
});
});
} | javascript | function pr_parse(options) {
this.traverse(options, function (dir, item, out) {
fs.readFile(dir + item, function(err, data) {
console.log('adding log ' + dir + item);
if (err) {
console.log(err);
console.log(data);
return;
}
var source = data.toString();
var output;
// if no match in the file
if (!source.match(regex)) {
return;
}
output = source.replace(regex, replacer);
fs.writeFile(out + item, output, function(err) {
if (err) {
console.log(err);
} else {
console.log(out + item + ' was saved!');
}
});
});
});
} | [
"function",
"pr_parse",
"(",
"options",
")",
"{",
"this",
".",
"traverse",
"(",
"options",
",",
"function",
"(",
"dir",
",",
"item",
",",
"out",
")",
"{",
"fs",
".",
"readFile",
"(",
"dir",
"+",
"item",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"console",
".",
"log",
"(",
"'adding log '",
"+",
"dir",
"+",
"item",
")",
";",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"data",
")",
";",
"return",
";",
"}",
"var",
"source",
"=",
"data",
".",
"toString",
"(",
")",
";",
"var",
"output",
";",
"// if no match in the file",
"if",
"(",
"!",
"source",
".",
"match",
"(",
"regex",
")",
")",
"{",
"return",
";",
"}",
"output",
"=",
"source",
".",
"replace",
"(",
"regex",
",",
"replacer",
")",
";",
"fs",
".",
"writeFile",
"(",
"out",
"+",
"item",
",",
"output",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"out",
"+",
"item",
"+",
"' was saved!'",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Replace debuguy comments to predifined condole logs.
@param {[type]} options [description]
@return {[type]} [description] | [
"Replace",
"debuguy",
"comments",
"to",
"predifined",
"condole",
"logs",
"."
] | 60b18e44b9dd1bcc7a160aac56b570eec6e5e4b4 | https://github.com/seiyugi/debuguy/blob/60b18e44b9dd1bcc7a160aac56b570eec6e5e4b4/lib/parser.js#L169-L199 |
56,806 | seiyugi/debuguy | lib/parser.js | pr_autolog | function pr_autolog(options) {
function espectRewrite(filepath, outpath, template) {
var autologret = require(template);
autologret(filepath, outpath);
}
function insertReturnLog(source, endLine) {
var sourceRet;
// Insert ending log at return statement.
sourceRet = source.replace(/(\s|;)return(\s|;)/g, "$1" + endLine + "return$2");
// Remove any ending log that added twice.
while(sourceRet.indexOf(endLine + endLine) !== -1) {
sourceRet = sourceRet.replace(endLine + endLine, endLine);
}
return sourceRet;
}
function insertEnterAndLeaveLog(item, node, functionName) {
var fnoutLine = 'var DEBOUT="debuguy,"' +
' + (new Date()).getTime() + ",' +
item.substring(0, item.lastIndexOf('.')) + '.' +
functionName + '@' +
node.loc.start.line + '";console.log(DEBOUT + ",ENTER," + Date.now());';
var fnEndLine = 'console.log(DEBOUT + ",LEAVE," + Date.now());';
var startLine = node.getSource().indexOf('{') + 1;
var endLine = node.getSource().lastIndexOf('}');
var source = node.getSource().substr(0, startLine) + fnoutLine +
node.getSource().substr(startLine, endLine - startLine) + fnEndLine +
node.getSource().substr(endLine);
source = insertReturnLog(source, fnEndLine);
return source;
}
function insertEnterLog(item, node, functionName) {
var fnoutLine = '\nconsole.log("debuguy,"' +
' + (new Date()).getTime() + ",' +
item.substring(0, item.lastIndexOf('.')) + '.' +
functionName + '@' +
node.loc.start.line + '");';
var startLine = node.getSource().indexOf('{') + 1;
var source = node.getSource().substr(0, startLine) + fnoutLine +
node.getSource().substr(startLine);
return source;
}
this.traverse(options, function insertLog (dir, item, out) {
if (options.xEspect) {
var templatefile = __dirname + '/autolog.esp.js';
if ('string' === typeof options.xEspect) {
templatefile = options.xEspect;
}
espectRewrite(dir + item, out + item, templatefile);
return;
}
fs.readFile(dir + item, function(err, data) {
console.log('adding log ' + dir + item);
if (err) {
console.log(err);
console.log(data);
return;
}
var text = data.toString();
var output;
try {
output = esprimaTraversal(text, {loc:true})
.traverse(function (node) {
if (node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression') {
// Get the name of the function
var functionName = 'anonymous';
if (node.id) {
functionName = node.id.name;
} else if (node.parent) {
switch (node.parent.type) {
case 'VariableDeclarator':
functionName = node.parent.id.name;
break;
case 'Property':
functionName = node.parent.key.name;
break;
case 'AssignmentExpression':
if (node.parent.left.type === 'MemberExpression') {
functionName = node.parent.left.property.name ||
node.parent.left.property.value;
}
else if (node.parent.left.type === 'Identifier') {
functionName = node.parent.left.name;
}
break;
}
}
// Build the console log output
var source;
if (options.callStackGraph) {
source = insertEnterAndLeaveLog(item, node, functionName);
} else {
source = insertEnterLog(item, node, functionName);
}
node.updateSource(source);
}
});
fs.writeFile(out + item, output, function(err) {
if (err) {
console.log(err);
} else {
console.log(out + item + ' was saved!');
}
});
}
catch (e) {
console.log('parsing failed: ' + dir + item);
console.log(e);
}
});
});
} | javascript | function pr_autolog(options) {
function espectRewrite(filepath, outpath, template) {
var autologret = require(template);
autologret(filepath, outpath);
}
function insertReturnLog(source, endLine) {
var sourceRet;
// Insert ending log at return statement.
sourceRet = source.replace(/(\s|;)return(\s|;)/g, "$1" + endLine + "return$2");
// Remove any ending log that added twice.
while(sourceRet.indexOf(endLine + endLine) !== -1) {
sourceRet = sourceRet.replace(endLine + endLine, endLine);
}
return sourceRet;
}
function insertEnterAndLeaveLog(item, node, functionName) {
var fnoutLine = 'var DEBOUT="debuguy,"' +
' + (new Date()).getTime() + ",' +
item.substring(0, item.lastIndexOf('.')) + '.' +
functionName + '@' +
node.loc.start.line + '";console.log(DEBOUT + ",ENTER," + Date.now());';
var fnEndLine = 'console.log(DEBOUT + ",LEAVE," + Date.now());';
var startLine = node.getSource().indexOf('{') + 1;
var endLine = node.getSource().lastIndexOf('}');
var source = node.getSource().substr(0, startLine) + fnoutLine +
node.getSource().substr(startLine, endLine - startLine) + fnEndLine +
node.getSource().substr(endLine);
source = insertReturnLog(source, fnEndLine);
return source;
}
function insertEnterLog(item, node, functionName) {
var fnoutLine = '\nconsole.log("debuguy,"' +
' + (new Date()).getTime() + ",' +
item.substring(0, item.lastIndexOf('.')) + '.' +
functionName + '@' +
node.loc.start.line + '");';
var startLine = node.getSource().indexOf('{') + 1;
var source = node.getSource().substr(0, startLine) + fnoutLine +
node.getSource().substr(startLine);
return source;
}
this.traverse(options, function insertLog (dir, item, out) {
if (options.xEspect) {
var templatefile = __dirname + '/autolog.esp.js';
if ('string' === typeof options.xEspect) {
templatefile = options.xEspect;
}
espectRewrite(dir + item, out + item, templatefile);
return;
}
fs.readFile(dir + item, function(err, data) {
console.log('adding log ' + dir + item);
if (err) {
console.log(err);
console.log(data);
return;
}
var text = data.toString();
var output;
try {
output = esprimaTraversal(text, {loc:true})
.traverse(function (node) {
if (node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression') {
// Get the name of the function
var functionName = 'anonymous';
if (node.id) {
functionName = node.id.name;
} else if (node.parent) {
switch (node.parent.type) {
case 'VariableDeclarator':
functionName = node.parent.id.name;
break;
case 'Property':
functionName = node.parent.key.name;
break;
case 'AssignmentExpression':
if (node.parent.left.type === 'MemberExpression') {
functionName = node.parent.left.property.name ||
node.parent.left.property.value;
}
else if (node.parent.left.type === 'Identifier') {
functionName = node.parent.left.name;
}
break;
}
}
// Build the console log output
var source;
if (options.callStackGraph) {
source = insertEnterAndLeaveLog(item, node, functionName);
} else {
source = insertEnterLog(item, node, functionName);
}
node.updateSource(source);
}
});
fs.writeFile(out + item, output, function(err) {
if (err) {
console.log(err);
} else {
console.log(out + item + ' was saved!');
}
});
}
catch (e) {
console.log('parsing failed: ' + dir + item);
console.log(e);
}
});
});
} | [
"function",
"pr_autolog",
"(",
"options",
")",
"{",
"function",
"espectRewrite",
"(",
"filepath",
",",
"outpath",
",",
"template",
")",
"{",
"var",
"autologret",
"=",
"require",
"(",
"template",
")",
";",
"autologret",
"(",
"filepath",
",",
"outpath",
")",
";",
"}",
"function",
"insertReturnLog",
"(",
"source",
",",
"endLine",
")",
"{",
"var",
"sourceRet",
";",
"// Insert ending log at return statement.",
"sourceRet",
"=",
"source",
".",
"replace",
"(",
"/",
"(\\s|;)return(\\s|;)",
"/",
"g",
",",
"\"$1\"",
"+",
"endLine",
"+",
"\"return$2\"",
")",
";",
"// Remove any ending log that added twice.",
"while",
"(",
"sourceRet",
".",
"indexOf",
"(",
"endLine",
"+",
"endLine",
")",
"!==",
"-",
"1",
")",
"{",
"sourceRet",
"=",
"sourceRet",
".",
"replace",
"(",
"endLine",
"+",
"endLine",
",",
"endLine",
")",
";",
"}",
"return",
"sourceRet",
";",
"}",
"function",
"insertEnterAndLeaveLog",
"(",
"item",
",",
"node",
",",
"functionName",
")",
"{",
"var",
"fnoutLine",
"=",
"'var DEBOUT=\"debuguy,\"'",
"+",
"' + (new Date()).getTime() + \",'",
"+",
"item",
".",
"substring",
"(",
"0",
",",
"item",
".",
"lastIndexOf",
"(",
"'.'",
")",
")",
"+",
"'.'",
"+",
"functionName",
"+",
"'@'",
"+",
"node",
".",
"loc",
".",
"start",
".",
"line",
"+",
"'\";console.log(DEBOUT + \",ENTER,\" + Date.now());'",
";",
"var",
"fnEndLine",
"=",
"'console.log(DEBOUT + \",LEAVE,\" + Date.now());'",
";",
"var",
"startLine",
"=",
"node",
".",
"getSource",
"(",
")",
".",
"indexOf",
"(",
"'{'",
")",
"+",
"1",
";",
"var",
"endLine",
"=",
"node",
".",
"getSource",
"(",
")",
".",
"lastIndexOf",
"(",
"'}'",
")",
";",
"var",
"source",
"=",
"node",
".",
"getSource",
"(",
")",
".",
"substr",
"(",
"0",
",",
"startLine",
")",
"+",
"fnoutLine",
"+",
"node",
".",
"getSource",
"(",
")",
".",
"substr",
"(",
"startLine",
",",
"endLine",
"-",
"startLine",
")",
"+",
"fnEndLine",
"+",
"node",
".",
"getSource",
"(",
")",
".",
"substr",
"(",
"endLine",
")",
";",
"source",
"=",
"insertReturnLog",
"(",
"source",
",",
"fnEndLine",
")",
";",
"return",
"source",
";",
"}",
"function",
"insertEnterLog",
"(",
"item",
",",
"node",
",",
"functionName",
")",
"{",
"var",
"fnoutLine",
"=",
"'\\nconsole.log(\"debuguy,\"'",
"+",
"' + (new Date()).getTime() + \",'",
"+",
"item",
".",
"substring",
"(",
"0",
",",
"item",
".",
"lastIndexOf",
"(",
"'.'",
")",
")",
"+",
"'.'",
"+",
"functionName",
"+",
"'@'",
"+",
"node",
".",
"loc",
".",
"start",
".",
"line",
"+",
"'\");'",
";",
"var",
"startLine",
"=",
"node",
".",
"getSource",
"(",
")",
".",
"indexOf",
"(",
"'{'",
")",
"+",
"1",
";",
"var",
"source",
"=",
"node",
".",
"getSource",
"(",
")",
".",
"substr",
"(",
"0",
",",
"startLine",
")",
"+",
"fnoutLine",
"+",
"node",
".",
"getSource",
"(",
")",
".",
"substr",
"(",
"startLine",
")",
";",
"return",
"source",
";",
"}",
"this",
".",
"traverse",
"(",
"options",
",",
"function",
"insertLog",
"(",
"dir",
",",
"item",
",",
"out",
")",
"{",
"if",
"(",
"options",
".",
"xEspect",
")",
"{",
"var",
"templatefile",
"=",
"__dirname",
"+",
"'/autolog.esp.js'",
";",
"if",
"(",
"'string'",
"===",
"typeof",
"options",
".",
"xEspect",
")",
"{",
"templatefile",
"=",
"options",
".",
"xEspect",
";",
"}",
"espectRewrite",
"(",
"dir",
"+",
"item",
",",
"out",
"+",
"item",
",",
"templatefile",
")",
";",
"return",
";",
"}",
"fs",
".",
"readFile",
"(",
"dir",
"+",
"item",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"console",
".",
"log",
"(",
"'adding log '",
"+",
"dir",
"+",
"item",
")",
";",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"data",
")",
";",
"return",
";",
"}",
"var",
"text",
"=",
"data",
".",
"toString",
"(",
")",
";",
"var",
"output",
";",
"try",
"{",
"output",
"=",
"esprimaTraversal",
"(",
"text",
",",
"{",
"loc",
":",
"true",
"}",
")",
".",
"traverse",
"(",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'ArrowFunctionExpression'",
"||",
"node",
".",
"type",
"===",
"'FunctionDeclaration'",
"||",
"node",
".",
"type",
"===",
"'FunctionExpression'",
")",
"{",
"// Get the name of the function",
"var",
"functionName",
"=",
"'anonymous'",
";",
"if",
"(",
"node",
".",
"id",
")",
"{",
"functionName",
"=",
"node",
".",
"id",
".",
"name",
";",
"}",
"else",
"if",
"(",
"node",
".",
"parent",
")",
"{",
"switch",
"(",
"node",
".",
"parent",
".",
"type",
")",
"{",
"case",
"'VariableDeclarator'",
":",
"functionName",
"=",
"node",
".",
"parent",
".",
"id",
".",
"name",
";",
"break",
";",
"case",
"'Property'",
":",
"functionName",
"=",
"node",
".",
"parent",
".",
"key",
".",
"name",
";",
"break",
";",
"case",
"'AssignmentExpression'",
":",
"if",
"(",
"node",
".",
"parent",
".",
"left",
".",
"type",
"===",
"'MemberExpression'",
")",
"{",
"functionName",
"=",
"node",
".",
"parent",
".",
"left",
".",
"property",
".",
"name",
"||",
"node",
".",
"parent",
".",
"left",
".",
"property",
".",
"value",
";",
"}",
"else",
"if",
"(",
"node",
".",
"parent",
".",
"left",
".",
"type",
"===",
"'Identifier'",
")",
"{",
"functionName",
"=",
"node",
".",
"parent",
".",
"left",
".",
"name",
";",
"}",
"break",
";",
"}",
"}",
"// Build the console log output",
"var",
"source",
";",
"if",
"(",
"options",
".",
"callStackGraph",
")",
"{",
"source",
"=",
"insertEnterAndLeaveLog",
"(",
"item",
",",
"node",
",",
"functionName",
")",
";",
"}",
"else",
"{",
"source",
"=",
"insertEnterLog",
"(",
"item",
",",
"node",
",",
"functionName",
")",
";",
"}",
"node",
".",
"updateSource",
"(",
"source",
")",
";",
"}",
"}",
")",
";",
"fs",
".",
"writeFile",
"(",
"out",
"+",
"item",
",",
"output",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"out",
"+",
"item",
"+",
"' was saved!'",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'parsing failed: '",
"+",
"dir",
"+",
"item",
")",
";",
"console",
".",
"log",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Automatically insert console logs in javascript functions.
@param {[type]} options [description]
@return {[type]} [description] | [
"Automatically",
"insert",
"console",
"logs",
"in",
"javascript",
"functions",
"."
] | 60b18e44b9dd1bcc7a160aac56b570eec6e5e4b4 | https://github.com/seiyugi/debuguy/blob/60b18e44b9dd1bcc7a160aac56b570eec6e5e4b4/lib/parser.js#L205-L328 |
56,807 | greggman/hft-game-utils | src/hft/scripts/misc/timeout.js | function(callback, timeInMs) {
var timeout = makeTimeout(callback);
setTriggerTime(timeout, timeInMs);
s_timeoutsToInsert.push(timeout);
return timeout.id;
} | javascript | function(callback, timeInMs) {
var timeout = makeTimeout(callback);
setTriggerTime(timeout, timeInMs);
s_timeoutsToInsert.push(timeout);
return timeout.id;
} | [
"function",
"(",
"callback",
",",
"timeInMs",
")",
"{",
"var",
"timeout",
"=",
"makeTimeout",
"(",
"callback",
")",
";",
"setTriggerTime",
"(",
"timeout",
",",
"timeInMs",
")",
";",
"s_timeoutsToInsert",
".",
"push",
"(",
"timeout",
")",
";",
"return",
"timeout",
".",
"id",
";",
"}"
] | Same as normal setTimeout
@param {callback} callback function to call when it times out
@param {number} timeInMs duration of timeout
@return {number} id for timeout
@memberOf module:Timeout | [
"Same",
"as",
"normal",
"setTimeout"
] | 071a0feebeed79d3597efd63e682392179cf0d30 | https://github.com/greggman/hft-game-utils/blob/071a0feebeed79d3597efd63e682392179cf0d30/src/hft/scripts/misc/timeout.js#L106-L111 |
|
56,808 | greggman/hft-game-utils | src/hft/scripts/misc/timeout.js | function(callback, timeInMs) {
var timeout = makeTimeout(function() {
setTriggerTime(timeout, timeout.timeInMs);
s_timeoutsToInsert.push(timeout);
callback();
});
timeout.timeInMs = timeInMs;
s_timeoutsToInsert.push(timeout);
return timeout.id;
} | javascript | function(callback, timeInMs) {
var timeout = makeTimeout(function() {
setTriggerTime(timeout, timeout.timeInMs);
s_timeoutsToInsert.push(timeout);
callback();
});
timeout.timeInMs = timeInMs;
s_timeoutsToInsert.push(timeout);
return timeout.id;
} | [
"function",
"(",
"callback",
",",
"timeInMs",
")",
"{",
"var",
"timeout",
"=",
"makeTimeout",
"(",
"function",
"(",
")",
"{",
"setTriggerTime",
"(",
"timeout",
",",
"timeout",
".",
"timeInMs",
")",
";",
"s_timeoutsToInsert",
".",
"push",
"(",
"timeout",
")",
";",
"callback",
"(",
")",
";",
"}",
")",
";",
"timeout",
".",
"timeInMs",
"=",
"timeInMs",
";",
"s_timeoutsToInsert",
".",
"push",
"(",
"timeout",
")",
";",
"return",
"timeout",
".",
"id",
";",
"}"
] | Same as normal setInterval
@param {callback} callback function to call at each interval
@param {number} timeInMs duration of internval
@return {number} id for interval
@memberOf module:Timeout | [
"Same",
"as",
"normal",
"setInterval"
] | 071a0feebeed79d3597efd63e682392179cf0d30 | https://github.com/greggman/hft-game-utils/blob/071a0feebeed79d3597efd63e682392179cf0d30/src/hft/scripts/misc/timeout.js#L120-L129 |
|
56,809 | greggman/hft-game-utils | src/hft/scripts/misc/timeout.js | function(elapsedTimeInSeconds) {
// insert any unscheduled timeouts
if (s_timeoutsToInsert.length) {
s_timeoutsToInsert.forEach(insertTimeout);
s_timeoutsToInsert = [];
}
// Now remove any
if (s_timeoutsToRemoveById.length) {
s_timeoutsToRemoveById.forEach(removeTimeoutById);
s_timeoutsToRemoveById = [];
}
s_clockInMs += elapsedTimeInSeconds * 1000;
// process timeouts
for (var ii = 0; ii < s_timeouts.length; ++ii) {
var timeout = s_timeouts[ii];
if (s_clockInMs < timeout.timeToTrigger) {
break;
}
timeout.callback();
}
// remove expired timeouts
s_timeouts.splice(0, ii);
} | javascript | function(elapsedTimeInSeconds) {
// insert any unscheduled timeouts
if (s_timeoutsToInsert.length) {
s_timeoutsToInsert.forEach(insertTimeout);
s_timeoutsToInsert = [];
}
// Now remove any
if (s_timeoutsToRemoveById.length) {
s_timeoutsToRemoveById.forEach(removeTimeoutById);
s_timeoutsToRemoveById = [];
}
s_clockInMs += elapsedTimeInSeconds * 1000;
// process timeouts
for (var ii = 0; ii < s_timeouts.length; ++ii) {
var timeout = s_timeouts[ii];
if (s_clockInMs < timeout.timeToTrigger) {
break;
}
timeout.callback();
}
// remove expired timeouts
s_timeouts.splice(0, ii);
} | [
"function",
"(",
"elapsedTimeInSeconds",
")",
"{",
"// insert any unscheduled timeouts",
"if",
"(",
"s_timeoutsToInsert",
".",
"length",
")",
"{",
"s_timeoutsToInsert",
".",
"forEach",
"(",
"insertTimeout",
")",
";",
"s_timeoutsToInsert",
"=",
"[",
"]",
";",
"}",
"// Now remove any",
"if",
"(",
"s_timeoutsToRemoveById",
".",
"length",
")",
"{",
"s_timeoutsToRemoveById",
".",
"forEach",
"(",
"removeTimeoutById",
")",
";",
"s_timeoutsToRemoveById",
"=",
"[",
"]",
";",
"}",
"s_clockInMs",
"+=",
"elapsedTimeInSeconds",
"*",
"1000",
";",
"// process timeouts",
"for",
"(",
"var",
"ii",
"=",
"0",
";",
"ii",
"<",
"s_timeouts",
".",
"length",
";",
"++",
"ii",
")",
"{",
"var",
"timeout",
"=",
"s_timeouts",
"[",
"ii",
"]",
";",
"if",
"(",
"s_clockInMs",
"<",
"timeout",
".",
"timeToTrigger",
")",
"{",
"break",
";",
"}",
"timeout",
".",
"callback",
"(",
")",
";",
"}",
"// remove expired timeouts",
"s_timeouts",
".",
"splice",
"(",
"0",
",",
"ii",
")",
";",
"}"
] | Processes the intervals and timeouts
This is how you control the clock for the timouts
A typical usage might be
var g = {};
GameSupport.run(g, mainloop);
function mainloop() {
Timeout.process(globals.elapsedTime);
};
@param {number} elapsedTimeInSeconds number of seconds to advance the clock.
@memberOf module:Timeout | [
"Processes",
"the",
"intervals",
"and",
"timeouts"
] | 071a0feebeed79d3597efd63e682392179cf0d30 | https://github.com/greggman/hft-game-utils/blob/071a0feebeed79d3597efd63e682392179cf0d30/src/hft/scripts/misc/timeout.js#L167-L193 |
|
56,810 | node-jpi/jpi-models | array.js | function () {
const result = Array.prototype.pop.apply(arr)
fn('pop', arr, {
value: result
})
return result
} | javascript | function () {
const result = Array.prototype.pop.apply(arr)
fn('pop', arr, {
value: result
})
return result
} | [
"function",
"(",
")",
"{",
"const",
"result",
"=",
"Array",
".",
"prototype",
".",
"pop",
".",
"apply",
"(",
"arr",
")",
"fn",
"(",
"'pop'",
",",
"arr",
",",
"{",
"value",
":",
"result",
"}",
")",
"return",
"result",
"}"
] | Proxied array mutators methods
@param {Object} obj
@return {Object}
@api private | [
"Proxied",
"array",
"mutators",
"methods"
] | f0c34626d004d720cefdbb4ad5d33d84057fd78d | https://github.com/node-jpi/jpi-models/blob/f0c34626d004d720cefdbb4ad5d33d84057fd78d/array.js#L13-L21 |
|
56,811 | nodejitsu/npm-dependencies-pagelet | index.js | process | function process(data) {
//
// Apply previous post processing.
//
data = Pagelet.prototype.postprocess.call(this, data);
data.stats = {
outofdate: 0,
uptodate: 0,
pinned: 0
};
data.shrinkwrap.forEach(function shrinkwrap(module) {
if (module.pinned) data.stats.pinned++;
if (module.uptodate) data.stats.uptodate++;
else data.stats.outofdate++;
});
return data;
} | javascript | function process(data) {
//
// Apply previous post processing.
//
data = Pagelet.prototype.postprocess.call(this, data);
data.stats = {
outofdate: 0,
uptodate: 0,
pinned: 0
};
data.shrinkwrap.forEach(function shrinkwrap(module) {
if (module.pinned) data.stats.pinned++;
if (module.uptodate) data.stats.uptodate++;
else data.stats.outofdate++;
});
return data;
} | [
"function",
"process",
"(",
"data",
")",
"{",
"//",
"// Apply previous post processing.",
"//",
"data",
"=",
"Pagelet",
".",
"prototype",
".",
"postprocess",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"data",
".",
"stats",
"=",
"{",
"outofdate",
":",
"0",
",",
"uptodate",
":",
"0",
",",
"pinned",
":",
"0",
"}",
";",
"data",
".",
"shrinkwrap",
".",
"forEach",
"(",
"function",
"shrinkwrap",
"(",
"module",
")",
"{",
"if",
"(",
"module",
".",
"pinned",
")",
"data",
".",
"stats",
".",
"pinned",
"++",
";",
"if",
"(",
"module",
".",
"uptodate",
")",
"data",
".",
"stats",
".",
"uptodate",
"++",
";",
"else",
"data",
".",
"stats",
".",
"outofdate",
"++",
";",
"}",
")",
";",
"return",
"data",
";",
"}"
] | Remove JS dependency.
Final post processing step on the data.
@param {Object} data The resolved data from cache.
@returns {Object} data
@api private | [
"Remove",
"JS",
"dependency",
".",
"Final",
"post",
"processing",
"step",
"on",
"the",
"data",
"."
] | 5a43cfa31eb0e9ccec609204d0a8dc6a29080e0a | https://github.com/nodejitsu/npm-dependencies-pagelet/blob/5a43cfa31eb0e9ccec609204d0a8dc6a29080e0a/index.js#L22-L41 |
56,812 | muttr/libmuttr | lib/session.js | Session | function Session(identity, connection, options) {
if (!(this instanceof Session)) {
return new Session(identity, connection, options);
}
assert(identity instanceof Identity, 'Invalid identity supplied');
if (!(connection instanceof Connection)) {
options = connection || {};
options.passive = true;
}
this.options = merge(Object.create(Session.DEFAULTS), options);
this.client = new Client(identity);
this._identity = identity;
if (!this.options.passive) {
this._connection = connection;
this._connection.open(this._onConnect.bind(this));
} else {
this._onConnect();
}
if (this.options.subscribe) {
this.client.on('message', this._onMessage.bind(this)).subscribe();
}
} | javascript | function Session(identity, connection, options) {
if (!(this instanceof Session)) {
return new Session(identity, connection, options);
}
assert(identity instanceof Identity, 'Invalid identity supplied');
if (!(connection instanceof Connection)) {
options = connection || {};
options.passive = true;
}
this.options = merge(Object.create(Session.DEFAULTS), options);
this.client = new Client(identity);
this._identity = identity;
if (!this.options.passive) {
this._connection = connection;
this._connection.open(this._onConnect.bind(this));
} else {
this._onConnect();
}
if (this.options.subscribe) {
this.client.on('message', this._onMessage.bind(this)).subscribe();
}
} | [
"function",
"Session",
"(",
"identity",
",",
"connection",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Session",
")",
")",
"{",
"return",
"new",
"Session",
"(",
"identity",
",",
"connection",
",",
"options",
")",
";",
"}",
"assert",
"(",
"identity",
"instanceof",
"Identity",
",",
"'Invalid identity supplied'",
")",
";",
"if",
"(",
"!",
"(",
"connection",
"instanceof",
"Connection",
")",
")",
"{",
"options",
"=",
"connection",
"||",
"{",
"}",
";",
"options",
".",
"passive",
"=",
"true",
";",
"}",
"this",
".",
"options",
"=",
"merge",
"(",
"Object",
".",
"create",
"(",
"Session",
".",
"DEFAULTS",
")",
",",
"options",
")",
";",
"this",
".",
"client",
"=",
"new",
"Client",
"(",
"identity",
")",
";",
"this",
".",
"_identity",
"=",
"identity",
";",
"if",
"(",
"!",
"this",
".",
"options",
".",
"passive",
")",
"{",
"this",
".",
"_connection",
"=",
"connection",
";",
"this",
".",
"_connection",
".",
"open",
"(",
"this",
".",
"_onConnect",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"_onConnect",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"options",
".",
"subscribe",
")",
"{",
"this",
".",
"client",
".",
"on",
"(",
"'message'",
",",
"this",
".",
"_onMessage",
".",
"bind",
"(",
"this",
")",
")",
".",
"subscribe",
"(",
")",
";",
"}",
"}"
] | Creates a sandbox for Muttr apps by the given identity
@constructor
@param {Identity} identity
@param {Connection} connection
@param {object} options | [
"Creates",
"a",
"sandbox",
"for",
"Muttr",
"apps",
"by",
"the",
"given",
"identity"
] | 2e4fda9cb2b47b8febe30585f54196d39d79e2e5 | https://github.com/muttr/libmuttr/blob/2e4fda9cb2b47b8febe30585f54196d39d79e2e5/lib/session.js#L34-L60 |
56,813 | codenothing/munit | lib/assert.js | function(){
var self = this,
logs = self._filterLogs(),
all = logs.all,
keys = logs.keys,
time = munit._relativeTime( self.end - self.start );
// Root module
if ( ! self.callback ) {
munit.color.green( "=== All submodules of " + self.nsPath + " have finished ===" );
return;
}
// Content
munit.color.blue( "\n" + self.nsPath );
munit.each( self.tests, function( test ) {
if ( keys[ test.name ] && keys[ test.name ].length ) {
keys[ test.name ].forEach(function( args ) {
munit.log.apply( munit, args );
});
}
if ( test.error ) {
munit.color.red( test.ns );
munit.log( "\n", test.error.stack );
munit.log( "\n" );
}
else if ( test.skip ) {
munit.color.gray( "[skipped] " + test.ns );
munit.color.gray( "\treason: " + test.skip );
}
else {
munit.color.green( test.ns );
}
});
// Logs made after the final test
if ( all.length ) {
all.forEach(function( args ) {
munit.log.apply( munit, args );
});
}
// Final Output
if ( self.failed ) {
munit.color.red( "\n-- " + self.failed + " tests failed on " + self.nsPath + " (" + time + ") --\n" );
}
else {
munit.color.green( "\n-- All " + self.passed + " tests passed on " + self.nsPath + " (" + time + ") --\n" );
}
} | javascript | function(){
var self = this,
logs = self._filterLogs(),
all = logs.all,
keys = logs.keys,
time = munit._relativeTime( self.end - self.start );
// Root module
if ( ! self.callback ) {
munit.color.green( "=== All submodules of " + self.nsPath + " have finished ===" );
return;
}
// Content
munit.color.blue( "\n" + self.nsPath );
munit.each( self.tests, function( test ) {
if ( keys[ test.name ] && keys[ test.name ].length ) {
keys[ test.name ].forEach(function( args ) {
munit.log.apply( munit, args );
});
}
if ( test.error ) {
munit.color.red( test.ns );
munit.log( "\n", test.error.stack );
munit.log( "\n" );
}
else if ( test.skip ) {
munit.color.gray( "[skipped] " + test.ns );
munit.color.gray( "\treason: " + test.skip );
}
else {
munit.color.green( test.ns );
}
});
// Logs made after the final test
if ( all.length ) {
all.forEach(function( args ) {
munit.log.apply( munit, args );
});
}
// Final Output
if ( self.failed ) {
munit.color.red( "\n-- " + self.failed + " tests failed on " + self.nsPath + " (" + time + ") --\n" );
}
else {
munit.color.green( "\n-- All " + self.passed + " tests passed on " + self.nsPath + " (" + time + ") --\n" );
}
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"logs",
"=",
"self",
".",
"_filterLogs",
"(",
")",
",",
"all",
"=",
"logs",
".",
"all",
",",
"keys",
"=",
"logs",
".",
"keys",
",",
"time",
"=",
"munit",
".",
"_relativeTime",
"(",
"self",
".",
"end",
"-",
"self",
".",
"start",
")",
";",
"// Root module",
"if",
"(",
"!",
"self",
".",
"callback",
")",
"{",
"munit",
".",
"color",
".",
"green",
"(",
"\"=== All submodules of \"",
"+",
"self",
".",
"nsPath",
"+",
"\" have finished ===\"",
")",
";",
"return",
";",
"}",
"// Content",
"munit",
".",
"color",
".",
"blue",
"(",
"\"\\n\"",
"+",
"self",
".",
"nsPath",
")",
";",
"munit",
".",
"each",
"(",
"self",
".",
"tests",
",",
"function",
"(",
"test",
")",
"{",
"if",
"(",
"keys",
"[",
"test",
".",
"name",
"]",
"&&",
"keys",
"[",
"test",
".",
"name",
"]",
".",
"length",
")",
"{",
"keys",
"[",
"test",
".",
"name",
"]",
".",
"forEach",
"(",
"function",
"(",
"args",
")",
"{",
"munit",
".",
"log",
".",
"apply",
"(",
"munit",
",",
"args",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"test",
".",
"error",
")",
"{",
"munit",
".",
"color",
".",
"red",
"(",
"test",
".",
"ns",
")",
";",
"munit",
".",
"log",
"(",
"\"\\n\"",
",",
"test",
".",
"error",
".",
"stack",
")",
";",
"munit",
".",
"log",
"(",
"\"\\n\"",
")",
";",
"}",
"else",
"if",
"(",
"test",
".",
"skip",
")",
"{",
"munit",
".",
"color",
".",
"gray",
"(",
"\"[skipped] \"",
"+",
"test",
".",
"ns",
")",
";",
"munit",
".",
"color",
".",
"gray",
"(",
"\"\\treason: \"",
"+",
"test",
".",
"skip",
")",
";",
"}",
"else",
"{",
"munit",
".",
"color",
".",
"green",
"(",
"test",
".",
"ns",
")",
";",
"}",
"}",
")",
";",
"// Logs made after the final test",
"if",
"(",
"all",
".",
"length",
")",
"{",
"all",
".",
"forEach",
"(",
"function",
"(",
"args",
")",
"{",
"munit",
".",
"log",
".",
"apply",
"(",
"munit",
",",
"args",
")",
";",
"}",
")",
";",
"}",
"// Final Output",
"if",
"(",
"self",
".",
"failed",
")",
"{",
"munit",
".",
"color",
".",
"red",
"(",
"\"\\n-- \"",
"+",
"self",
".",
"failed",
"+",
"\" tests failed on \"",
"+",
"self",
".",
"nsPath",
"+",
"\" (\"",
"+",
"time",
"+",
"\") --\\n\"",
")",
";",
"}",
"else",
"{",
"munit",
".",
"color",
".",
"green",
"(",
"\"\\n-- All \"",
"+",
"self",
".",
"passed",
"+",
"\" tests passed on \"",
"+",
"self",
".",
"nsPath",
"+",
"\" (\"",
"+",
"time",
"+",
"\") --\\n\"",
")",
";",
"}",
"}"
] | Prints module results to cli | [
"Prints",
"module",
"results",
"to",
"cli"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L46-L96 |
|
56,814 | codenothing/munit | lib/assert.js | function(){
var self = this,
all = [],
keys = {},
current = null;
self._logs.reverse().forEach(function( log ) {
if ( log instanceof AssertResult ) {
current = log.name;
return;
}
var name = log[ 0 ];
if ( log.length > 1 && munit.isString( name ) && self.tests[ name ] ) {
if ( ! keys[ name ] ) {
keys[ name ] = [];
}
keys[ name ].unshift( log.slice( 1 ) );
}
else if ( current && self.tests[ current ] ) {
if ( ! keys[ current ] ) {
keys[ current ] = [];
}
keys[ current ].unshift( log );
}
else {
all.unshift( log );
}
});
return { all: all, keys: keys };
} | javascript | function(){
var self = this,
all = [],
keys = {},
current = null;
self._logs.reverse().forEach(function( log ) {
if ( log instanceof AssertResult ) {
current = log.name;
return;
}
var name = log[ 0 ];
if ( log.length > 1 && munit.isString( name ) && self.tests[ name ] ) {
if ( ! keys[ name ] ) {
keys[ name ] = [];
}
keys[ name ].unshift( log.slice( 1 ) );
}
else if ( current && self.tests[ current ] ) {
if ( ! keys[ current ] ) {
keys[ current ] = [];
}
keys[ current ].unshift( log );
}
else {
all.unshift( log );
}
});
return { all: all, keys: keys };
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"all",
"=",
"[",
"]",
",",
"keys",
"=",
"{",
"}",
",",
"current",
"=",
"null",
";",
"self",
".",
"_logs",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"log",
")",
"{",
"if",
"(",
"log",
"instanceof",
"AssertResult",
")",
"{",
"current",
"=",
"log",
".",
"name",
";",
"return",
";",
"}",
"var",
"name",
"=",
"log",
"[",
"0",
"]",
";",
"if",
"(",
"log",
".",
"length",
">",
"1",
"&&",
"munit",
".",
"isString",
"(",
"name",
")",
"&&",
"self",
".",
"tests",
"[",
"name",
"]",
")",
"{",
"if",
"(",
"!",
"keys",
"[",
"name",
"]",
")",
"{",
"keys",
"[",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"keys",
"[",
"name",
"]",
".",
"unshift",
"(",
"log",
".",
"slice",
"(",
"1",
")",
")",
";",
"}",
"else",
"if",
"(",
"current",
"&&",
"self",
".",
"tests",
"[",
"current",
"]",
")",
"{",
"if",
"(",
"!",
"keys",
"[",
"current",
"]",
")",
"{",
"keys",
"[",
"current",
"]",
"=",
"[",
"]",
";",
"}",
"keys",
"[",
"current",
"]",
".",
"unshift",
"(",
"log",
")",
";",
"}",
"else",
"{",
"all",
".",
"unshift",
"(",
"log",
")",
";",
"}",
"}",
")",
";",
"return",
"{",
"all",
":",
"all",
",",
"keys",
":",
"keys",
"}",
";",
"}"
] | Generates log arrays based on current test keys | [
"Generates",
"log",
"arrays",
"based",
"on",
"current",
"test",
"keys"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L99-L132 |
|
56,815 | codenothing/munit | lib/assert.js | function( name, error, skip ) {
var self = this,
now = Date.now(),
last = ! self.isAsync && self._lastTest ? self._lastTest : self.start,
result = new AssertResult( name, self.nsPath, now - last, error, skip );
self.tests[ name ] = result;
self.list.push( result );
self._logs.push( result );
self._lastTest = now;
} | javascript | function( name, error, skip ) {
var self = this,
now = Date.now(),
last = ! self.isAsync && self._lastTest ? self._lastTest : self.start,
result = new AssertResult( name, self.nsPath, now - last, error, skip );
self.tests[ name ] = result;
self.list.push( result );
self._logs.push( result );
self._lastTest = now;
} | [
"function",
"(",
"name",
",",
"error",
",",
"skip",
")",
"{",
"var",
"self",
"=",
"this",
",",
"now",
"=",
"Date",
".",
"now",
"(",
")",
",",
"last",
"=",
"!",
"self",
".",
"isAsync",
"&&",
"self",
".",
"_lastTest",
"?",
"self",
".",
"_lastTest",
":",
"self",
".",
"start",
",",
"result",
"=",
"new",
"AssertResult",
"(",
"name",
",",
"self",
".",
"nsPath",
",",
"now",
"-",
"last",
",",
"error",
",",
"skip",
")",
";",
"self",
".",
"tests",
"[",
"name",
"]",
"=",
"result",
";",
"self",
".",
"list",
".",
"push",
"(",
"result",
")",
";",
"self",
".",
"_logs",
".",
"push",
"(",
"result",
")",
";",
"self",
".",
"_lastTest",
"=",
"now",
";",
"}"
] | Returns a configured result object | [
"Returns",
"a",
"configured",
"result",
"object"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L135-L145 |
|
56,816 | codenothing/munit | lib/assert.js | function( actual, expected, prefix ) {
var self = this, keys, expectedKeys;
prefix = prefix || '';
if ( munit.isArray( actual ) && munit.isArray( expected ) ) {
if ( actual.length !== expected.length ) {
throw "\nActual: actual" + prefix + ".length = " + actual.length +
"\nExpected: expected" + prefix + ".length = " + expected.length;
}
munit.each( actual, function( item, i ) {
if ( munit.isArray( item ) || munit.isObject( item ) ) {
self._objectMatch( item, expected[ i ], prefix + "[" + i + "]" );
}
else if ( item !== expected[ i ] ) {
throw "\nActual: actual" + prefix + "[" + i + "] = " + item +
"\nExpected: expected" + prefix + "[" + i + "] = " + expected[ i ];
}
});
}
else if ( munit.isObject( actual ) && munit.isObject( expected ) ) {
keys = Object.keys( actual );
expectedKeys = Object.keys( expected );
if ( keys.length !== expectedKeys.length ) {
throw "\nActual: actual" + prefix + ".length = " + keys.length +
"\nExpected: expected" + prefix + ".length = " + expectedKeys.length;
}
munit.each( keys, function( key ) {
var item = actual[ key ];
if ( munit.isArray( item ) || munit.isObject( item ) ) {
self._objectMatch( item, expected[ key ], prefix + "[" + key + "]" );
}
else if ( item !== expected[ key ] ) {
throw "\nActual: actual" + prefix + "[" + key + "] = " + item +
"\nExpected: expected" + prefix + "[" + key + "] = " + expected[ key ];
}
});
}
else if ( actual !== expected ) {
throw "\nActual: actual" + prefix + " = " + actual +
"\nExpected: expected" + prefix + " = " + expected;
}
} | javascript | function( actual, expected, prefix ) {
var self = this, keys, expectedKeys;
prefix = prefix || '';
if ( munit.isArray( actual ) && munit.isArray( expected ) ) {
if ( actual.length !== expected.length ) {
throw "\nActual: actual" + prefix + ".length = " + actual.length +
"\nExpected: expected" + prefix + ".length = " + expected.length;
}
munit.each( actual, function( item, i ) {
if ( munit.isArray( item ) || munit.isObject( item ) ) {
self._objectMatch( item, expected[ i ], prefix + "[" + i + "]" );
}
else if ( item !== expected[ i ] ) {
throw "\nActual: actual" + prefix + "[" + i + "] = " + item +
"\nExpected: expected" + prefix + "[" + i + "] = " + expected[ i ];
}
});
}
else if ( munit.isObject( actual ) && munit.isObject( expected ) ) {
keys = Object.keys( actual );
expectedKeys = Object.keys( expected );
if ( keys.length !== expectedKeys.length ) {
throw "\nActual: actual" + prefix + ".length = " + keys.length +
"\nExpected: expected" + prefix + ".length = " + expectedKeys.length;
}
munit.each( keys, function( key ) {
var item = actual[ key ];
if ( munit.isArray( item ) || munit.isObject( item ) ) {
self._objectMatch( item, expected[ key ], prefix + "[" + key + "]" );
}
else if ( item !== expected[ key ] ) {
throw "\nActual: actual" + prefix + "[" + key + "] = " + item +
"\nExpected: expected" + prefix + "[" + key + "] = " + expected[ key ];
}
});
}
else if ( actual !== expected ) {
throw "\nActual: actual" + prefix + " = " + actual +
"\nExpected: expected" + prefix + " = " + expected;
}
} | [
"function",
"(",
"actual",
",",
"expected",
",",
"prefix",
")",
"{",
"var",
"self",
"=",
"this",
",",
"keys",
",",
"expectedKeys",
";",
"prefix",
"=",
"prefix",
"||",
"''",
";",
"if",
"(",
"munit",
".",
"isArray",
"(",
"actual",
")",
"&&",
"munit",
".",
"isArray",
"(",
"expected",
")",
")",
"{",
"if",
"(",
"actual",
".",
"length",
"!==",
"expected",
".",
"length",
")",
"{",
"throw",
"\"\\nActual: actual\"",
"+",
"prefix",
"+",
"\".length = \"",
"+",
"actual",
".",
"length",
"+",
"\"\\nExpected: expected\"",
"+",
"prefix",
"+",
"\".length = \"",
"+",
"expected",
".",
"length",
";",
"}",
"munit",
".",
"each",
"(",
"actual",
",",
"function",
"(",
"item",
",",
"i",
")",
"{",
"if",
"(",
"munit",
".",
"isArray",
"(",
"item",
")",
"||",
"munit",
".",
"isObject",
"(",
"item",
")",
")",
"{",
"self",
".",
"_objectMatch",
"(",
"item",
",",
"expected",
"[",
"i",
"]",
",",
"prefix",
"+",
"\"[\"",
"+",
"i",
"+",
"\"]\"",
")",
";",
"}",
"else",
"if",
"(",
"item",
"!==",
"expected",
"[",
"i",
"]",
")",
"{",
"throw",
"\"\\nActual: actual\"",
"+",
"prefix",
"+",
"\"[\"",
"+",
"i",
"+",
"\"] = \"",
"+",
"item",
"+",
"\"\\nExpected: expected\"",
"+",
"prefix",
"+",
"\"[\"",
"+",
"i",
"+",
"\"] = \"",
"+",
"expected",
"[",
"i",
"]",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"munit",
".",
"isObject",
"(",
"actual",
")",
"&&",
"munit",
".",
"isObject",
"(",
"expected",
")",
")",
"{",
"keys",
"=",
"Object",
".",
"keys",
"(",
"actual",
")",
";",
"expectedKeys",
"=",
"Object",
".",
"keys",
"(",
"expected",
")",
";",
"if",
"(",
"keys",
".",
"length",
"!==",
"expectedKeys",
".",
"length",
")",
"{",
"throw",
"\"\\nActual: actual\"",
"+",
"prefix",
"+",
"\".length = \"",
"+",
"keys",
".",
"length",
"+",
"\"\\nExpected: expected\"",
"+",
"prefix",
"+",
"\".length = \"",
"+",
"expectedKeys",
".",
"length",
";",
"}",
"munit",
".",
"each",
"(",
"keys",
",",
"function",
"(",
"key",
")",
"{",
"var",
"item",
"=",
"actual",
"[",
"key",
"]",
";",
"if",
"(",
"munit",
".",
"isArray",
"(",
"item",
")",
"||",
"munit",
".",
"isObject",
"(",
"item",
")",
")",
"{",
"self",
".",
"_objectMatch",
"(",
"item",
",",
"expected",
"[",
"key",
"]",
",",
"prefix",
"+",
"\"[\"",
"+",
"key",
"+",
"\"]\"",
")",
";",
"}",
"else",
"if",
"(",
"item",
"!==",
"expected",
"[",
"key",
"]",
")",
"{",
"throw",
"\"\\nActual: actual\"",
"+",
"prefix",
"+",
"\"[\"",
"+",
"key",
"+",
"\"] = \"",
"+",
"item",
"+",
"\"\\nExpected: expected\"",
"+",
"prefix",
"+",
"\"[\"",
"+",
"key",
"+",
"\"] = \"",
"+",
"expected",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"}",
"else",
"if",
"(",
"actual",
"!==",
"expected",
")",
"{",
"throw",
"\"\\nActual: actual\"",
"+",
"prefix",
"+",
"\" = \"",
"+",
"actual",
"+",
"\"\\nExpected: expected\"",
"+",
"prefix",
"+",
"\" = \"",
"+",
"expected",
";",
"}",
"}"
] | Key matching for object match | [
"Key",
"matching",
"for",
"object",
"match"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L148-L193 |
|
56,817 | codenothing/munit | lib/assert.js | function( e, match ) {
var result = { passed: false }, message = '';
// Get a string for matching on the error
if ( munit.isError( e ) ) {
message = e.message;
}
else if ( munit.isString( e ) ) {
message = e;
}
// No match required
if ( match === undefined ) {
result.passed = true;
}
// Non Error/String error object, string matching required
else if ( ! munit.isError( e ) && ! munit.isString( e ) ) {
if ( e === match ) {
result.passed = true;
}
else {
result.extra = "Match object '" + match + "' does not match error '" + e + "'";
}
}
// Function error class matching
else if ( munit.isFunction( match ) ) {
if ( e instanceof match ) {
result.passed = true;
}
else {
result.extra = "Error does not match class '" + match.name + "'";
}
}
// Regex checking on the error message
else if ( munit.isRegExp( match ) ) {
if ( match.exec( message ) ) {
result.passed = true;
}
else {
result.extra = "Regex (" + match + ") could not find match on:\n" + message;
}
}
// String matching on the error message
else if ( munit.isString( match ) ) {
if ( match === message ) {
result.passed = true;
}
else {
result.extra = "Error message doesn't match:\nActual: " + message + "\nExpected: " + match;
}
}
// Unkown error type passed
else {
result.extra = "Unknown error match type '" + match + "'";
}
return result;
} | javascript | function( e, match ) {
var result = { passed: false }, message = '';
// Get a string for matching on the error
if ( munit.isError( e ) ) {
message = e.message;
}
else if ( munit.isString( e ) ) {
message = e;
}
// No match required
if ( match === undefined ) {
result.passed = true;
}
// Non Error/String error object, string matching required
else if ( ! munit.isError( e ) && ! munit.isString( e ) ) {
if ( e === match ) {
result.passed = true;
}
else {
result.extra = "Match object '" + match + "' does not match error '" + e + "'";
}
}
// Function error class matching
else if ( munit.isFunction( match ) ) {
if ( e instanceof match ) {
result.passed = true;
}
else {
result.extra = "Error does not match class '" + match.name + "'";
}
}
// Regex checking on the error message
else if ( munit.isRegExp( match ) ) {
if ( match.exec( message ) ) {
result.passed = true;
}
else {
result.extra = "Regex (" + match + ") could not find match on:\n" + message;
}
}
// String matching on the error message
else if ( munit.isString( match ) ) {
if ( match === message ) {
result.passed = true;
}
else {
result.extra = "Error message doesn't match:\nActual: " + message + "\nExpected: " + match;
}
}
// Unkown error type passed
else {
result.extra = "Unknown error match type '" + match + "'";
}
return result;
} | [
"function",
"(",
"e",
",",
"match",
")",
"{",
"var",
"result",
"=",
"{",
"passed",
":",
"false",
"}",
",",
"message",
"=",
"''",
";",
"// Get a string for matching on the error",
"if",
"(",
"munit",
".",
"isError",
"(",
"e",
")",
")",
"{",
"message",
"=",
"e",
".",
"message",
";",
"}",
"else",
"if",
"(",
"munit",
".",
"isString",
"(",
"e",
")",
")",
"{",
"message",
"=",
"e",
";",
"}",
"// No match required",
"if",
"(",
"match",
"===",
"undefined",
")",
"{",
"result",
".",
"passed",
"=",
"true",
";",
"}",
"// Non Error/String error object, string matching required",
"else",
"if",
"(",
"!",
"munit",
".",
"isError",
"(",
"e",
")",
"&&",
"!",
"munit",
".",
"isString",
"(",
"e",
")",
")",
"{",
"if",
"(",
"e",
"===",
"match",
")",
"{",
"result",
".",
"passed",
"=",
"true",
";",
"}",
"else",
"{",
"result",
".",
"extra",
"=",
"\"Match object '\"",
"+",
"match",
"+",
"\"' does not match error '\"",
"+",
"e",
"+",
"\"'\"",
";",
"}",
"}",
"// Function error class matching",
"else",
"if",
"(",
"munit",
".",
"isFunction",
"(",
"match",
")",
")",
"{",
"if",
"(",
"e",
"instanceof",
"match",
")",
"{",
"result",
".",
"passed",
"=",
"true",
";",
"}",
"else",
"{",
"result",
".",
"extra",
"=",
"\"Error does not match class '\"",
"+",
"match",
".",
"name",
"+",
"\"'\"",
";",
"}",
"}",
"// Regex checking on the error message",
"else",
"if",
"(",
"munit",
".",
"isRegExp",
"(",
"match",
")",
")",
"{",
"if",
"(",
"match",
".",
"exec",
"(",
"message",
")",
")",
"{",
"result",
".",
"passed",
"=",
"true",
";",
"}",
"else",
"{",
"result",
".",
"extra",
"=",
"\"Regex (\"",
"+",
"match",
"+",
"\") could not find match on:\\n\"",
"+",
"message",
";",
"}",
"}",
"// String matching on the error message",
"else",
"if",
"(",
"munit",
".",
"isString",
"(",
"match",
")",
")",
"{",
"if",
"(",
"match",
"===",
"message",
")",
"{",
"result",
".",
"passed",
"=",
"true",
";",
"}",
"else",
"{",
"result",
".",
"extra",
"=",
"\"Error message doesn't match:\\nActual: \"",
"+",
"message",
"+",
"\"\\nExpected: \"",
"+",
"match",
";",
"}",
"}",
"// Unkown error type passed",
"else",
"{",
"result",
".",
"extra",
"=",
"\"Unknown error match type '\"",
"+",
"match",
"+",
"\"'\"",
";",
"}",
"return",
"result",
";",
"}"
] | Utility for error object matching | [
"Utility",
"for",
"error",
"object",
"matching"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L196-L253 |
|
56,818 | codenothing/munit | lib/assert.js | function( name, startFunc, error ) {
var self = this, result;
// Assign proper error
if ( ! error ) {
error = new munit.AssertionError( "'" + name + "' test failed", startFunc );
}
else if ( ! ( error instanceof Error ) ) {
error = new munit.AssertionError( error, startFunc );
}
// Increment error count and jump
self._addResult( name, error );
self.failed++;
self.count++;
munit.failed++;
// Kill on test failure
if ( self.options.stopOnFail ) {
self._flush();
munit.exit( 1 );
}
} | javascript | function( name, startFunc, error ) {
var self = this, result;
// Assign proper error
if ( ! error ) {
error = new munit.AssertionError( "'" + name + "' test failed", startFunc );
}
else if ( ! ( error instanceof Error ) ) {
error = new munit.AssertionError( error, startFunc );
}
// Increment error count and jump
self._addResult( name, error );
self.failed++;
self.count++;
munit.failed++;
// Kill on test failure
if ( self.options.stopOnFail ) {
self._flush();
munit.exit( 1 );
}
} | [
"function",
"(",
"name",
",",
"startFunc",
",",
"error",
")",
"{",
"var",
"self",
"=",
"this",
",",
"result",
";",
"// Assign proper error",
"if",
"(",
"!",
"error",
")",
"{",
"error",
"=",
"new",
"munit",
".",
"AssertionError",
"(",
"\"'\"",
"+",
"name",
"+",
"\"' test failed\"",
",",
"startFunc",
")",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"error",
"instanceof",
"Error",
")",
")",
"{",
"error",
"=",
"new",
"munit",
".",
"AssertionError",
"(",
"error",
",",
"startFunc",
")",
";",
"}",
"// Increment error count and jump",
"self",
".",
"_addResult",
"(",
"name",
",",
"error",
")",
";",
"self",
".",
"failed",
"++",
";",
"self",
".",
"count",
"++",
";",
"munit",
".",
"failed",
"++",
";",
"// Kill on test failure",
"if",
"(",
"self",
".",
"options",
".",
"stopOnFail",
")",
"{",
"self",
".",
"_flush",
"(",
")",
";",
"munit",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Failed test storage | [
"Failed",
"test",
"storage"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L256-L278 |
|
56,819 | codenothing/munit | lib/assert.js | function( name ) {
var self = this;
self._addResult( name );
self.passed++;
self.count++;
munit.passed++;
} | javascript | function( name ) {
var self = this;
self._addResult( name );
self.passed++;
self.count++;
munit.passed++;
} | [
"function",
"(",
"name",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"_addResult",
"(",
"name",
")",
";",
"self",
".",
"passed",
"++",
";",
"self",
".",
"count",
"++",
";",
"munit",
".",
"passed",
"++",
";",
"}"
] | Passed test storage | [
"Passed",
"test",
"storage"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L281-L288 |
|
56,820 | codenothing/munit | lib/assert.js | function( required, startFunc ) {
var self = this;
if ( required !== self.state ) {
self._stateError( startFunc || self.requireState );
}
return self;
} | javascript | function( required, startFunc ) {
var self = this;
if ( required !== self.state ) {
self._stateError( startFunc || self.requireState );
}
return self;
} | [
"function",
"(",
"required",
",",
"startFunc",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"required",
"!==",
"self",
".",
"state",
")",
"{",
"self",
".",
"_stateError",
"(",
"startFunc",
"||",
"self",
".",
"requireState",
")",
";",
"}",
"return",
"self",
";",
"}"
] | Throws an error if module isn't in the required state | [
"Throws",
"an",
"error",
"if",
"module",
"isn",
"t",
"in",
"the",
"required",
"state"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L305-L313 |
|
56,821 | codenothing/munit | lib/assert.js | function( time, callback ) {
var self = this, timeid;
// Can only delay an active module
self.requireState( munit.ASSERT_STATE_ACTIVE, self.delay );
// Time parameter is required
if ( ! munit.isNumber( time ) ) {
throw new munit.AssertionError( "Time parameter not passed to assert.delay", self.delay );
}
// Module has yet to complete the callback cycle,
// Start async extension now
if ( ! self.isAsync ) {
self.isAsync = true;
self.options.timeout = time;
self._timerStart = Date.now();
self._timeid = timeid = setTimeout(function(){
if ( munit.isFunction( callback ) ) {
callback( self );
}
if ( timeid === self._timeid && self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, time );
}
// Only extend current timeout if it is less then requested delay
else if ( ( self._timerStart + self.options.timeout ) < ( Date.now() + time ) ) {
if ( self._timeid ) {
self._timeid = clearTimeout( self._timeid );
}
self.isAsync = true;
self._timerStart = Date.now();
self._timeid = timeid = setTimeout(function(){
if ( munit.isFunction( callback ) ) {
callback( self );
}
if ( timeid === self._timeid && self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, time );
}
// Force block any delay that does not extend longer than current timeout
else {
throw new munit.AssertionError( "delay time doesn't extend further than the current timeout", self.delay );
}
} | javascript | function( time, callback ) {
var self = this, timeid;
// Can only delay an active module
self.requireState( munit.ASSERT_STATE_ACTIVE, self.delay );
// Time parameter is required
if ( ! munit.isNumber( time ) ) {
throw new munit.AssertionError( "Time parameter not passed to assert.delay", self.delay );
}
// Module has yet to complete the callback cycle,
// Start async extension now
if ( ! self.isAsync ) {
self.isAsync = true;
self.options.timeout = time;
self._timerStart = Date.now();
self._timeid = timeid = setTimeout(function(){
if ( munit.isFunction( callback ) ) {
callback( self );
}
if ( timeid === self._timeid && self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, time );
}
// Only extend current timeout if it is less then requested delay
else if ( ( self._timerStart + self.options.timeout ) < ( Date.now() + time ) ) {
if ( self._timeid ) {
self._timeid = clearTimeout( self._timeid );
}
self.isAsync = true;
self._timerStart = Date.now();
self._timeid = timeid = setTimeout(function(){
if ( munit.isFunction( callback ) ) {
callback( self );
}
if ( timeid === self._timeid && self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, time );
}
// Force block any delay that does not extend longer than current timeout
else {
throw new munit.AssertionError( "delay time doesn't extend further than the current timeout", self.delay );
}
} | [
"function",
"(",
"time",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"timeid",
";",
"// Can only delay an active module",
"self",
".",
"requireState",
"(",
"munit",
".",
"ASSERT_STATE_ACTIVE",
",",
"self",
".",
"delay",
")",
";",
"// Time parameter is required",
"if",
"(",
"!",
"munit",
".",
"isNumber",
"(",
"time",
")",
")",
"{",
"throw",
"new",
"munit",
".",
"AssertionError",
"(",
"\"Time parameter not passed to assert.delay\"",
",",
"self",
".",
"delay",
")",
";",
"}",
"// Module has yet to complete the callback cycle,",
"// Start async extension now",
"if",
"(",
"!",
"self",
".",
"isAsync",
")",
"{",
"self",
".",
"isAsync",
"=",
"true",
";",
"self",
".",
"options",
".",
"timeout",
"=",
"time",
";",
"self",
".",
"_timerStart",
"=",
"Date",
".",
"now",
"(",
")",
";",
"self",
".",
"_timeid",
"=",
"timeid",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"munit",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
"self",
")",
";",
"}",
"if",
"(",
"timeid",
"===",
"self",
".",
"_timeid",
"&&",
"self",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_TEARDOWN",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"}",
",",
"time",
")",
";",
"}",
"// Only extend current timeout if it is less then requested delay",
"else",
"if",
"(",
"(",
"self",
".",
"_timerStart",
"+",
"self",
".",
"options",
".",
"timeout",
")",
"<",
"(",
"Date",
".",
"now",
"(",
")",
"+",
"time",
")",
")",
"{",
"if",
"(",
"self",
".",
"_timeid",
")",
"{",
"self",
".",
"_timeid",
"=",
"clearTimeout",
"(",
"self",
".",
"_timeid",
")",
";",
"}",
"self",
".",
"isAsync",
"=",
"true",
";",
"self",
".",
"_timerStart",
"=",
"Date",
".",
"now",
"(",
")",
";",
"self",
".",
"_timeid",
"=",
"timeid",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"munit",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
"self",
")",
";",
"}",
"if",
"(",
"timeid",
"===",
"self",
".",
"_timeid",
"&&",
"self",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_TEARDOWN",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"}",
",",
"time",
")",
";",
"}",
"// Force block any delay that does not extend longer than current timeout",
"else",
"{",
"throw",
"new",
"munit",
".",
"AssertionError",
"(",
"\"delay time doesn't extend further than the current timeout\"",
",",
"self",
".",
"delay",
")",
";",
"}",
"}"
] | Makes module asynchronous | [
"Makes",
"module",
"asynchronous"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L352-L401 |
|
56,822 | codenothing/munit | lib/assert.js | function( name, test, startFunc, extra ) {
var self = this;
// Require an active state for tests
self.requireState( munit.ASSERT_STATE_ACTIVE, startFunc || self.ok );
// Prevent non empty string names
if ( ! munit.isString( name ) || ! name.length ) {
throw new munit.AssertionError(
"Name not found for test on '" + self.nsPath + "'",
startFunc || self.ok
);
}
// Prevent duplicate tests
else if ( self.tests[ name ] ) {
throw new munit.AssertionError(
"Duplicate Test '" + name + "' on '" + self.nsPath + "'",
startFunc || self.ok
);
}
// Increment test count and mark it
self[ !!( test ) ? '_pass' : '_fail' ]( name, startFunc || self.ok, extra );
// Reached expected number of tests, close off
if ( self.options.expect > 0 && self.count >= self.options.expect ) {
self.close();
}
return self;
} | javascript | function( name, test, startFunc, extra ) {
var self = this;
// Require an active state for tests
self.requireState( munit.ASSERT_STATE_ACTIVE, startFunc || self.ok );
// Prevent non empty string names
if ( ! munit.isString( name ) || ! name.length ) {
throw new munit.AssertionError(
"Name not found for test on '" + self.nsPath + "'",
startFunc || self.ok
);
}
// Prevent duplicate tests
else if ( self.tests[ name ] ) {
throw new munit.AssertionError(
"Duplicate Test '" + name + "' on '" + self.nsPath + "'",
startFunc || self.ok
);
}
// Increment test count and mark it
self[ !!( test ) ? '_pass' : '_fail' ]( name, startFunc || self.ok, extra );
// Reached expected number of tests, close off
if ( self.options.expect > 0 && self.count >= self.options.expect ) {
self.close();
}
return self;
} | [
"function",
"(",
"name",
",",
"test",
",",
"startFunc",
",",
"extra",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// Require an active state for tests",
"self",
".",
"requireState",
"(",
"munit",
".",
"ASSERT_STATE_ACTIVE",
",",
"startFunc",
"||",
"self",
".",
"ok",
")",
";",
"// Prevent non empty string names",
"if",
"(",
"!",
"munit",
".",
"isString",
"(",
"name",
")",
"||",
"!",
"name",
".",
"length",
")",
"{",
"throw",
"new",
"munit",
".",
"AssertionError",
"(",
"\"Name not found for test on '\"",
"+",
"self",
".",
"nsPath",
"+",
"\"'\"",
",",
"startFunc",
"||",
"self",
".",
"ok",
")",
";",
"}",
"// Prevent duplicate tests",
"else",
"if",
"(",
"self",
".",
"tests",
"[",
"name",
"]",
")",
"{",
"throw",
"new",
"munit",
".",
"AssertionError",
"(",
"\"Duplicate Test '\"",
"+",
"name",
"+",
"\"' on '\"",
"+",
"self",
".",
"nsPath",
"+",
"\"'\"",
",",
"startFunc",
"||",
"self",
".",
"ok",
")",
";",
"}",
"// Increment test count and mark it",
"self",
"[",
"!",
"!",
"(",
"test",
")",
"?",
"'_pass'",
":",
"'_fail'",
"]",
"(",
"name",
",",
"startFunc",
"||",
"self",
".",
"ok",
",",
"extra",
")",
";",
"// Reached expected number of tests, close off",
"if",
"(",
"self",
".",
"options",
".",
"expect",
">",
"0",
"&&",
"self",
".",
"count",
">=",
"self",
".",
"options",
".",
"expect",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"return",
"self",
";",
"}"
] | Basic boolean test | [
"Basic",
"boolean",
"test"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L441-L471 |
|
56,823 | codenothing/munit | lib/assert.js | function( name, startFunc, extra ) {
if ( extra === undefined && ! munit.isFunction( startFunc ) ) {
extra = startFunc;
startFunc = undefined;
}
if ( munit.isError( extra ) ) {
extra = extra.message;
}
return this.ok( name, false, startFunc || this.fail, extra );
} | javascript | function( name, startFunc, extra ) {
if ( extra === undefined && ! munit.isFunction( startFunc ) ) {
extra = startFunc;
startFunc = undefined;
}
if ( munit.isError( extra ) ) {
extra = extra.message;
}
return this.ok( name, false, startFunc || this.fail, extra );
} | [
"function",
"(",
"name",
",",
"startFunc",
",",
"extra",
")",
"{",
"if",
"(",
"extra",
"===",
"undefined",
"&&",
"!",
"munit",
".",
"isFunction",
"(",
"startFunc",
")",
")",
"{",
"extra",
"=",
"startFunc",
";",
"startFunc",
"=",
"undefined",
";",
"}",
"if",
"(",
"munit",
".",
"isError",
"(",
"extra",
")",
")",
"{",
"extra",
"=",
"extra",
".",
"message",
";",
"}",
"return",
"this",
".",
"ok",
"(",
"name",
",",
"false",
",",
"startFunc",
"||",
"this",
".",
"fail",
",",
"extra",
")",
";",
"}"
] | Shortcut for explicit failures | [
"Shortcut",
"for",
"explicit",
"failures"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L479-L490 |
|
56,824 | codenothing/munit | lib/assert.js | function( name, value, match ) {
var self = this,
result = munit.isError( value ) ?
self._errorMatch( value, match ) :
{ passed: false, extra: "Value is not an Error '" + value + "'" };
return self.ok( name, result.passed, self.isError, result.extra );
} | javascript | function( name, value, match ) {
var self = this,
result = munit.isError( value ) ?
self._errorMatch( value, match ) :
{ passed: false, extra: "Value is not an Error '" + value + "'" };
return self.ok( name, result.passed, self.isError, result.extra );
} | [
"function",
"(",
"name",
",",
"value",
",",
"match",
")",
"{",
"var",
"self",
"=",
"this",
",",
"result",
"=",
"munit",
".",
"isError",
"(",
"value",
")",
"?",
"self",
".",
"_errorMatch",
"(",
"value",
",",
"match",
")",
":",
"{",
"passed",
":",
"false",
",",
"extra",
":",
"\"Value is not an Error '\"",
"+",
"value",
"+",
"\"'\"",
"}",
";",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"result",
".",
"passed",
",",
"self",
".",
"isError",
",",
"result",
".",
"extra",
")",
";",
"}"
] | Testing value for Error object | [
"Testing",
"value",
"for",
"Error",
"object"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L553-L560 |
|
56,825 | codenothing/munit | lib/assert.js | function( name, actual, expected ) {
return this.ok( name, actual !== expected, this.notEqual, "\nValues should not match\nActual:" + actual + "\nExpected:" + expected );
} | javascript | function( name, actual, expected ) {
return this.ok( name, actual !== expected, this.notEqual, "\nValues should not match\nActual:" + actual + "\nExpected:" + expected );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"expected",
")",
"{",
"return",
"this",
".",
"ok",
"(",
"name",
",",
"actual",
"!==",
"expected",
",",
"this",
".",
"notEqual",
",",
"\"\\nValues should not match\\nActual:\"",
"+",
"actual",
"+",
"\"\\nExpected:\"",
"+",
"expected",
")",
";",
"}"
] | Strict un-comparison | [
"Strict",
"un",
"-",
"comparison"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L578-L580 |
|
56,826 | codenothing/munit | lib/assert.js | function( name, upper, lower ) {
return this.ok( name, upper > lower, this.greaterThan, "\nUpper Value '" + upper + "' is not greater than lower value '" + lower + "'" );
} | javascript | function( name, upper, lower ) {
return this.ok( name, upper > lower, this.greaterThan, "\nUpper Value '" + upper + "' is not greater than lower value '" + lower + "'" );
} | [
"function",
"(",
"name",
",",
"upper",
",",
"lower",
")",
"{",
"return",
"this",
".",
"ok",
"(",
"name",
",",
"upper",
">",
"lower",
",",
"this",
".",
"greaterThan",
",",
"\"\\nUpper Value '\"",
"+",
"upper",
"+",
"\"' is not greater than lower value '\"",
"+",
"lower",
"+",
"\"'\"",
")",
";",
"}"
] | Greater than comparison | [
"Greater",
"than",
"comparison"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L583-L585 |
|
56,827 | codenothing/munit | lib/assert.js | function( name, lower, upper ) {
return this.ok( name, lower < upper, this.lessThan, "\nLower Value '" + lower + "' is not less than upper value '" + upper + "'" );
} | javascript | function( name, lower, upper ) {
return this.ok( name, lower < upper, this.lessThan, "\nLower Value '" + lower + "' is not less than upper value '" + upper + "'" );
} | [
"function",
"(",
"name",
",",
"lower",
",",
"upper",
")",
"{",
"return",
"this",
".",
"ok",
"(",
"name",
",",
"lower",
"<",
"upper",
",",
"this",
".",
"lessThan",
",",
"\"\\nLower Value '\"",
"+",
"lower",
"+",
"\"' is not less than upper value '\"",
"+",
"upper",
"+",
"\"'\"",
")",
";",
"}"
] | Less than comparison | [
"Less",
"than",
"comparison"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L588-L590 |
|
56,828 | codenothing/munit | lib/assert.js | function( name, value, lower, upper ) {
return this.ok(
name,
value > lower && value < upper,
this.between,
"\nValue '" + value + "' is not inbetween '" + lower + "' and '" + upper + "'"
);
} | javascript | function( name, value, lower, upper ) {
return this.ok(
name,
value > lower && value < upper,
this.between,
"\nValue '" + value + "' is not inbetween '" + lower + "' and '" + upper + "'"
);
} | [
"function",
"(",
"name",
",",
"value",
",",
"lower",
",",
"upper",
")",
"{",
"return",
"this",
".",
"ok",
"(",
"name",
",",
"value",
">",
"lower",
"&&",
"value",
"<",
"upper",
",",
"this",
".",
"between",
",",
"\"\\nValue '\"",
"+",
"value",
"+",
"\"' is not inbetween '\"",
"+",
"lower",
"+",
"\"' and '\"",
"+",
"upper",
"+",
"\"'\"",
")",
";",
"}"
] | Value between boundary | [
"Value",
"between",
"boundary"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L593-L600 |
|
56,829 | codenothing/munit | lib/assert.js | function( name, actual, expected ) {
var self = this, passed = true, extra = '';
try {
self._objectMatch( actual, expected );
}
catch ( e ) {
passed = false;
extra = e;
if ( ! munit.isString( e ) ) {
throw e;
}
}
return self.ok( name, passed, self.deepEqual, extra );
} | javascript | function( name, actual, expected ) {
var self = this, passed = true, extra = '';
try {
self._objectMatch( actual, expected );
}
catch ( e ) {
passed = false;
extra = e;
if ( ! munit.isString( e ) ) {
throw e;
}
}
return self.ok( name, passed, self.deepEqual, extra );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"expected",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"true",
",",
"extra",
"=",
"''",
";",
"try",
"{",
"self",
".",
"_objectMatch",
"(",
"actual",
",",
"expected",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"passed",
"=",
"false",
";",
"extra",
"=",
"e",
";",
"if",
"(",
"!",
"munit",
".",
"isString",
"(",
"e",
")",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"deepEqual",
",",
"extra",
")",
";",
"}"
] | Deep equal handle | [
"Deep",
"equal",
"handle"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L603-L619 |
|
56,830 | codenothing/munit | lib/assert.js | function( name, actual, expected ) {
var self = this, passed = true;
try {
self._objectMatch( actual, expected );
passed = false;
}
catch ( e ) {
}
return self.ok( name, passed, self.notDeepEqual, 'Objects are not supposed to match' );
} | javascript | function( name, actual, expected ) {
var self = this, passed = true;
try {
self._objectMatch( actual, expected );
passed = false;
}
catch ( e ) {
}
return self.ok( name, passed, self.notDeepEqual, 'Objects are not supposed to match' );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"expected",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"true",
";",
"try",
"{",
"self",
".",
"_objectMatch",
"(",
"actual",
",",
"expected",
")",
";",
"passed",
"=",
"false",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"notDeepEqual",
",",
"'Objects are not supposed to match'",
")",
";",
"}"
] | Not deep equal handle | [
"Not",
"deep",
"equal",
"handle"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L622-L633 |
|
56,831 | codenothing/munit | lib/assert.js | function( name, match, block ) {
var self = this, result = { passed: false, extra: 'Block did not throw error' };
// Variable arguments
if ( block === undefined && munit.isFunction( match ) ) {
block = match;
match = undefined;
}
// Fail quick if block isn't a function
if ( ! munit.isFunction( block ) ) {
throw new Error( "Block passed to assert.throws is not a function: '" + block + "'" );
}
// test for throwing
try {
block();
}
catch ( e ) {
result = self._errorMatch( e, match );
}
return self.ok( name, result.passed, self.throws, result.extra );
} | javascript | function( name, match, block ) {
var self = this, result = { passed: false, extra: 'Block did not throw error' };
// Variable arguments
if ( block === undefined && munit.isFunction( match ) ) {
block = match;
match = undefined;
}
// Fail quick if block isn't a function
if ( ! munit.isFunction( block ) ) {
throw new Error( "Block passed to assert.throws is not a function: '" + block + "'" );
}
// test for throwing
try {
block();
}
catch ( e ) {
result = self._errorMatch( e, match );
}
return self.ok( name, result.passed, self.throws, result.extra );
} | [
"function",
"(",
"name",
",",
"match",
",",
"block",
")",
"{",
"var",
"self",
"=",
"this",
",",
"result",
"=",
"{",
"passed",
":",
"false",
",",
"extra",
":",
"'Block did not throw error'",
"}",
";",
"// Variable arguments",
"if",
"(",
"block",
"===",
"undefined",
"&&",
"munit",
".",
"isFunction",
"(",
"match",
")",
")",
"{",
"block",
"=",
"match",
";",
"match",
"=",
"undefined",
";",
"}",
"// Fail quick if block isn't a function",
"if",
"(",
"!",
"munit",
".",
"isFunction",
"(",
"block",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Block passed to assert.throws is not a function: '\"",
"+",
"block",
"+",
"\"'\"",
")",
";",
"}",
"// test for throwing",
"try",
"{",
"block",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"result",
"=",
"self",
".",
"_errorMatch",
"(",
"e",
",",
"match",
")",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"result",
".",
"passed",
",",
"self",
".",
"throws",
",",
"result",
".",
"extra",
")",
";",
"}"
] | Run internal throw handle | [
"Run",
"internal",
"throw",
"handle"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L636-L659 |
|
56,832 | codenothing/munit | lib/assert.js | function( name, block ) {
var self = this, passed = true;
try {
block();
}
catch ( e ) {
passed = false;
}
return self.ok( name, passed, self.doesNotThrow, 'Block does throw error' );
} | javascript | function( name, block ) {
var self = this, passed = true;
try {
block();
}
catch ( e ) {
passed = false;
}
return self.ok( name, passed, self.doesNotThrow, 'Block does throw error' );
} | [
"function",
"(",
"name",
",",
"block",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"true",
";",
"try",
"{",
"block",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"passed",
"=",
"false",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"doesNotThrow",
",",
"'Block does throw error'",
")",
";",
"}"
] | Run internal notThrow handle | [
"Run",
"internal",
"notThrow",
"handle"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L662-L673 |
|
56,833 | codenothing/munit | lib/assert.js | function( name, actual, expected ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( expected ) ) {
passed = actual.getTime() === expected.getTime();
message = "Date '" + actual + "' does not match '" + expected + "'";
}
else {
message = munit.isDate( actual ) ?
"Expected value is not a Date object '" + expected + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateEquals, message );
} | javascript | function( name, actual, expected ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( expected ) ) {
passed = actual.getTime() === expected.getTime();
message = "Date '" + actual + "' does not match '" + expected + "'";
}
else {
message = munit.isDate( actual ) ?
"Expected value is not a Date object '" + expected + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateEquals, message );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"expected",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"false",
",",
"message",
"=",
"''",
";",
"if",
"(",
"munit",
".",
"isDate",
"(",
"actual",
")",
"&&",
"munit",
".",
"isDate",
"(",
"expected",
")",
")",
"{",
"passed",
"=",
"actual",
".",
"getTime",
"(",
")",
"===",
"expected",
".",
"getTime",
"(",
")",
";",
"message",
"=",
"\"Date '\"",
"+",
"actual",
"+",
"\"' does not match '\"",
"+",
"expected",
"+",
"\"'\"",
";",
"}",
"else",
"{",
"message",
"=",
"munit",
".",
"isDate",
"(",
"actual",
")",
"?",
"\"Expected value is not a Date object '\"",
"+",
"expected",
"+",
"\"'\"",
":",
"\"Actual value is not a Date object '\"",
"+",
"actual",
"+",
"\"'\"",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"dateEquals",
",",
"message",
")",
";",
"}"
] | Matching date objects | [
"Matching",
"date",
"objects"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L676-L692 |
|
56,834 | codenothing/munit | lib/assert.js | function( name, actual, lower ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( lower ) ) {
passed = actual.getTime() > lower.getTime();
message = "Date '" + actual + "' is not after '" + lower + "'";
}
else {
message = munit.isDate( actual ) ?
"Lower value is not a Date object '" + lower + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateAfter, message );
} | javascript | function( name, actual, lower ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( lower ) ) {
passed = actual.getTime() > lower.getTime();
message = "Date '" + actual + "' is not after '" + lower + "'";
}
else {
message = munit.isDate( actual ) ?
"Lower value is not a Date object '" + lower + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateAfter, message );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"lower",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"false",
",",
"message",
"=",
"''",
";",
"if",
"(",
"munit",
".",
"isDate",
"(",
"actual",
")",
"&&",
"munit",
".",
"isDate",
"(",
"lower",
")",
")",
"{",
"passed",
"=",
"actual",
".",
"getTime",
"(",
")",
">",
"lower",
".",
"getTime",
"(",
")",
";",
"message",
"=",
"\"Date '\"",
"+",
"actual",
"+",
"\"' is not after '\"",
"+",
"lower",
"+",
"\"'\"",
";",
"}",
"else",
"{",
"message",
"=",
"munit",
".",
"isDate",
"(",
"actual",
")",
"?",
"\"Lower value is not a Date object '\"",
"+",
"lower",
"+",
"\"'\"",
":",
"\"Actual value is not a Date object '\"",
"+",
"actual",
"+",
"\"'\"",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"dateAfter",
",",
"message",
")",
";",
"}"
] | Tests date is after another date | [
"Tests",
"date",
"is",
"after",
"another",
"date"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L695-L711 |
|
56,835 | codenothing/munit | lib/assert.js | function( name, actual, upper ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( upper ) ) {
passed = actual.getTime() < upper.getTime();
message = "Date '" + actual + "' is not before '" + upper + "'";
}
else {
message = munit.isDate( actual ) ?
"Upper value is not a Date object '" + upper + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateBefore, message );
} | javascript | function( name, actual, upper ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( upper ) ) {
passed = actual.getTime() < upper.getTime();
message = "Date '" + actual + "' is not before '" + upper + "'";
}
else {
message = munit.isDate( actual ) ?
"Upper value is not a Date object '" + upper + "'" :
"Actual value is not a Date object '" + actual + "'";
}
return self.ok( name, passed, self.dateBefore, message );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"upper",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"false",
",",
"message",
"=",
"''",
";",
"if",
"(",
"munit",
".",
"isDate",
"(",
"actual",
")",
"&&",
"munit",
".",
"isDate",
"(",
"upper",
")",
")",
"{",
"passed",
"=",
"actual",
".",
"getTime",
"(",
")",
"<",
"upper",
".",
"getTime",
"(",
")",
";",
"message",
"=",
"\"Date '\"",
"+",
"actual",
"+",
"\"' is not before '\"",
"+",
"upper",
"+",
"\"'\"",
";",
"}",
"else",
"{",
"message",
"=",
"munit",
".",
"isDate",
"(",
"actual",
")",
"?",
"\"Upper value is not a Date object '\"",
"+",
"upper",
"+",
"\"'\"",
":",
"\"Actual value is not a Date object '\"",
"+",
"actual",
"+",
"\"'\"",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"dateBefore",
",",
"message",
")",
";",
"}"
] | Tests date is before another date | [
"Tests",
"date",
"is",
"before",
"another",
"date"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L714-L730 |
|
56,836 | codenothing/munit | lib/assert.js | function( name, actual, lower, upper ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( lower ) && munit.isDate( upper ) ) {
passed = actual.getTime() > lower.getTime() && actual.getTime() < upper.getTime();
message = "Date '" + actual + "' is not between '" + lower + "' and '" + upper + "'";
}
else {
message = ! munit.isDate( actual ) ? "Actual value is not a Date object '" + actual + "'" :
! munit.isDate( lower ) ? "Lower value is not a Date object '" + lower + "'" :
"Upper value is not a Date object '" + upper + "'";
}
return self.ok( name, passed, self.dateBetween, message );
} | javascript | function( name, actual, lower, upper ) {
var self = this,
passed = false,
message = '';
if ( munit.isDate( actual ) && munit.isDate( lower ) && munit.isDate( upper ) ) {
passed = actual.getTime() > lower.getTime() && actual.getTime() < upper.getTime();
message = "Date '" + actual + "' is not between '" + lower + "' and '" + upper + "'";
}
else {
message = ! munit.isDate( actual ) ? "Actual value is not a Date object '" + actual + "'" :
! munit.isDate( lower ) ? "Lower value is not a Date object '" + lower + "'" :
"Upper value is not a Date object '" + upper + "'";
}
return self.ok( name, passed, self.dateBetween, message );
} | [
"function",
"(",
"name",
",",
"actual",
",",
"lower",
",",
"upper",
")",
"{",
"var",
"self",
"=",
"this",
",",
"passed",
"=",
"false",
",",
"message",
"=",
"''",
";",
"if",
"(",
"munit",
".",
"isDate",
"(",
"actual",
")",
"&&",
"munit",
".",
"isDate",
"(",
"lower",
")",
"&&",
"munit",
".",
"isDate",
"(",
"upper",
")",
")",
"{",
"passed",
"=",
"actual",
".",
"getTime",
"(",
")",
">",
"lower",
".",
"getTime",
"(",
")",
"&&",
"actual",
".",
"getTime",
"(",
")",
"<",
"upper",
".",
"getTime",
"(",
")",
";",
"message",
"=",
"\"Date '\"",
"+",
"actual",
"+",
"\"' is not between '\"",
"+",
"lower",
"+",
"\"' and '\"",
"+",
"upper",
"+",
"\"'\"",
";",
"}",
"else",
"{",
"message",
"=",
"!",
"munit",
".",
"isDate",
"(",
"actual",
")",
"?",
"\"Actual value is not a Date object '\"",
"+",
"actual",
"+",
"\"'\"",
":",
"!",
"munit",
".",
"isDate",
"(",
"lower",
")",
"?",
"\"Lower value is not a Date object '\"",
"+",
"lower",
"+",
"\"'\"",
":",
"\"Upper value is not a Date object '\"",
"+",
"upper",
"+",
"\"'\"",
";",
"}",
"return",
"self",
".",
"ok",
"(",
"name",
",",
"passed",
",",
"self",
".",
"dateBetween",
",",
"message",
")",
";",
"}"
] | Tests date is between two other dates | [
"Tests",
"date",
"is",
"between",
"two",
"other",
"dates"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L733-L749 |
|
56,837 | codenothing/munit | lib/assert.js | function( name, handle ) {
var self = this;
// Can only add custom assertions when module hasn't been triggered yet
self.requireMaxState( munit.ASSERT_STATE_DEFAULT, self.custom );
// Block on reserved words
if ( munit.customReserved.indexOf( name ) > -1 ) {
throw new Error( "'" + name + "' is a reserved name and cannot be added as a custom assertion test" );
}
// Attach handle to assertion module and all submodules
self[ name ] = handle;
munit.each( self.ns, function( mod ) {
mod.custom( name, handle );
});
return self;
} | javascript | function( name, handle ) {
var self = this;
// Can only add custom assertions when module hasn't been triggered yet
self.requireMaxState( munit.ASSERT_STATE_DEFAULT, self.custom );
// Block on reserved words
if ( munit.customReserved.indexOf( name ) > -1 ) {
throw new Error( "'" + name + "' is a reserved name and cannot be added as a custom assertion test" );
}
// Attach handle to assertion module and all submodules
self[ name ] = handle;
munit.each( self.ns, function( mod ) {
mod.custom( name, handle );
});
return self;
} | [
"function",
"(",
"name",
",",
"handle",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// Can only add custom assertions when module hasn't been triggered yet",
"self",
".",
"requireMaxState",
"(",
"munit",
".",
"ASSERT_STATE_DEFAULT",
",",
"self",
".",
"custom",
")",
";",
"// Block on reserved words",
"if",
"(",
"munit",
".",
"customReserved",
".",
"indexOf",
"(",
"name",
")",
">",
"-",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"'\"",
"+",
"name",
"+",
"\"' is a reserved name and cannot be added as a custom assertion test\"",
")",
";",
"}",
"// Attach handle to assertion module and all submodules",
"self",
"[",
"name",
"]",
"=",
"handle",
";",
"munit",
".",
"each",
"(",
"self",
".",
"ns",
",",
"function",
"(",
"mod",
")",
"{",
"mod",
".",
"custom",
"(",
"name",
",",
"handle",
")",
";",
"}",
")",
";",
"return",
"self",
";",
"}"
] | Custom test additions | [
"Custom",
"test",
"additions"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L787-L805 |
|
56,838 | codenothing/munit | lib/assert.js | function(){
var self = this;
// Can only start a module that hasn't been started yet
self.requireState( munit.ASSERT_STATE_DEFAULT, self.trigger );
// Setup and trigger module
self.start = self.end = Date.now();
// Parent namespaces sometimes don't have tests
// Also close out paths that aren't part of the focus
if ( ! self.callback || ! munit.render.focusPath( self.nsPath ) ) {
self.state = munit.ASSERT_STATE_CLOSED;
return self._close();
}
// Trigger test setup first
self._setup(function( e, setupCallback ) {
if ( e ) {
self.fail( "[munit] Failed to setup '" + self.nsPath + "' module", setupCallback, e );
return self.close();
}
// Run test
self.callback( self, self.queue );
// If module isn't finished, then prove that it's supposed to be asynchronous
if ( self.state < munit.ASSERT_STATE_TEARDOWN ) {
// Only tear it down if no timeout is specified
if ( self.options.timeout < 1 ) {
self.close();
}
// Delayed close
else if ( ! self.isAsync ) {
self.isAsync = true;
self._timerStart = Date.now();
self._timeid = setTimeout(function(){
if ( self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, self.options.timeout );
}
}
});
return self;
} | javascript | function(){
var self = this;
// Can only start a module that hasn't been started yet
self.requireState( munit.ASSERT_STATE_DEFAULT, self.trigger );
// Setup and trigger module
self.start = self.end = Date.now();
// Parent namespaces sometimes don't have tests
// Also close out paths that aren't part of the focus
if ( ! self.callback || ! munit.render.focusPath( self.nsPath ) ) {
self.state = munit.ASSERT_STATE_CLOSED;
return self._close();
}
// Trigger test setup first
self._setup(function( e, setupCallback ) {
if ( e ) {
self.fail( "[munit] Failed to setup '" + self.nsPath + "' module", setupCallback, e );
return self.close();
}
// Run test
self.callback( self, self.queue );
// If module isn't finished, then prove that it's supposed to be asynchronous
if ( self.state < munit.ASSERT_STATE_TEARDOWN ) {
// Only tear it down if no timeout is specified
if ( self.options.timeout < 1 ) {
self.close();
}
// Delayed close
else if ( ! self.isAsync ) {
self.isAsync = true;
self._timerStart = Date.now();
self._timeid = setTimeout(function(){
if ( self.state < munit.ASSERT_STATE_TEARDOWN ) {
self.close();
}
}, self.options.timeout );
}
}
});
return self;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// Can only start a module that hasn't been started yet",
"self",
".",
"requireState",
"(",
"munit",
".",
"ASSERT_STATE_DEFAULT",
",",
"self",
".",
"trigger",
")",
";",
"// Setup and trigger module",
"self",
".",
"start",
"=",
"self",
".",
"end",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// Parent namespaces sometimes don't have tests",
"// Also close out paths that aren't part of the focus",
"if",
"(",
"!",
"self",
".",
"callback",
"||",
"!",
"munit",
".",
"render",
".",
"focusPath",
"(",
"self",
".",
"nsPath",
")",
")",
"{",
"self",
".",
"state",
"=",
"munit",
".",
"ASSERT_STATE_CLOSED",
";",
"return",
"self",
".",
"_close",
"(",
")",
";",
"}",
"// Trigger test setup first",
"self",
".",
"_setup",
"(",
"function",
"(",
"e",
",",
"setupCallback",
")",
"{",
"if",
"(",
"e",
")",
"{",
"self",
".",
"fail",
"(",
"\"[munit] Failed to setup '\"",
"+",
"self",
".",
"nsPath",
"+",
"\"' module\"",
",",
"setupCallback",
",",
"e",
")",
";",
"return",
"self",
".",
"close",
"(",
")",
";",
"}",
"// Run test",
"self",
".",
"callback",
"(",
"self",
",",
"self",
".",
"queue",
")",
";",
"// If module isn't finished, then prove that it's supposed to be asynchronous",
"if",
"(",
"self",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_TEARDOWN",
")",
"{",
"// Only tear it down if no timeout is specified",
"if",
"(",
"self",
".",
"options",
".",
"timeout",
"<",
"1",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"// Delayed close",
"else",
"if",
"(",
"!",
"self",
".",
"isAsync",
")",
"{",
"self",
".",
"isAsync",
"=",
"true",
";",
"self",
".",
"_timerStart",
"=",
"Date",
".",
"now",
"(",
")",
";",
"self",
".",
"_timeid",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_TEARDOWN",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"}",
",",
"self",
".",
"options",
".",
"timeout",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"self",
";",
"}"
] | Trigger module's tests | [
"Trigger",
"module",
"s",
"tests"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L900-L946 |
|
56,839 | codenothing/munit | lib/assert.js | function(){
var self = this,
nodeVersion = process.version.replace( /\./g, '_' ),
xml = "<testsuite name='" + munit._xmlEncode( nodeVersion + self.nsPath ) + "' tests='" + self.count + "' failures='" + self.failed + "' skipped='" + self.skipped + "' time='" + ( ( self.end - self.start ) / 1000 ) + "'>";
self.list.forEach(function( result ) {
xml += result.junit();
});
xml += "</testsuite>";
return xml;
} | javascript | function(){
var self = this,
nodeVersion = process.version.replace( /\./g, '_' ),
xml = "<testsuite name='" + munit._xmlEncode( nodeVersion + self.nsPath ) + "' tests='" + self.count + "' failures='" + self.failed + "' skipped='" + self.skipped + "' time='" + ( ( self.end - self.start ) / 1000 ) + "'>";
self.list.forEach(function( result ) {
xml += result.junit();
});
xml += "</testsuite>";
return xml;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"nodeVersion",
"=",
"process",
".",
"version",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"'_'",
")",
",",
"xml",
"=",
"\"<testsuite name='\"",
"+",
"munit",
".",
"_xmlEncode",
"(",
"nodeVersion",
"+",
"self",
".",
"nsPath",
")",
"+",
"\"' tests='\"",
"+",
"self",
".",
"count",
"+",
"\"' failures='\"",
"+",
"self",
".",
"failed",
"+",
"\"' skipped='\"",
"+",
"self",
".",
"skipped",
"+",
"\"' time='\"",
"+",
"(",
"(",
"self",
".",
"end",
"-",
"self",
".",
"start",
")",
"/",
"1000",
")",
"+",
"\"'>\"",
";",
"self",
".",
"list",
".",
"forEach",
"(",
"function",
"(",
"result",
")",
"{",
"xml",
"+=",
"result",
".",
"junit",
"(",
")",
";",
"}",
")",
";",
"xml",
"+=",
"\"</testsuite>\"",
";",
"return",
"xml",
";",
"}"
] | Returns XML result format | [
"Returns",
"XML",
"result",
"format"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L949-L960 |
|
56,840 | codenothing/munit | lib/assert.js | function(){
var self = this;
return {
name: self.nsPath.split( '.' ).pop(),
nsPath: self.nsPath,
count: self.count,
passed: self.passed,
failed: self.failed,
skipped: self.skipped,
start: self.start,
end: self.end,
time: self.end - self.start,
tests: self.list,
ns: self.ns,
};
} | javascript | function(){
var self = this;
return {
name: self.nsPath.split( '.' ).pop(),
nsPath: self.nsPath,
count: self.count,
passed: self.passed,
failed: self.failed,
skipped: self.skipped,
start: self.start,
end: self.end,
time: self.end - self.start,
tests: self.list,
ns: self.ns,
};
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"return",
"{",
"name",
":",
"self",
".",
"nsPath",
".",
"split",
"(",
"'.'",
")",
".",
"pop",
"(",
")",
",",
"nsPath",
":",
"self",
".",
"nsPath",
",",
"count",
":",
"self",
".",
"count",
",",
"passed",
":",
"self",
".",
"passed",
",",
"failed",
":",
"self",
".",
"failed",
",",
"skipped",
":",
"self",
".",
"skipped",
",",
"start",
":",
"self",
".",
"start",
",",
"end",
":",
"self",
".",
"end",
",",
"time",
":",
"self",
".",
"end",
"-",
"self",
".",
"start",
",",
"tests",
":",
"self",
".",
"list",
",",
"ns",
":",
"self",
".",
"ns",
",",
"}",
";",
"}"
] | JSON result format | [
"JSON",
"result",
"format"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L963-L979 |
|
56,841 | codenothing/munit | lib/assert.js | function( startFunc, forced ) {
var self = this, i, mod;
// Can only close an active module
self.requireState( munit.ASSERT_STATE_ACTIVE, self.close );
// Add fail marker if no tests were ran
if ( self.count < 1 ) {
self.fail( "[munit] No tests ran in this module" );
}
// Auto close out any spies
self._spies.reverse().forEach(function( spy ) {
spy.restore();
});
// Proxy teardown to pass start function and forced state
self._teardown(function( e, teardownCallback ) {
if ( e ) {
self._fail( "[munit] failed to teardown '" + self.nsPath + "' module properly", teardownCallback );
}
self._close( startFunc || self.close, forced );
});
return self;
} | javascript | function( startFunc, forced ) {
var self = this, i, mod;
// Can only close an active module
self.requireState( munit.ASSERT_STATE_ACTIVE, self.close );
// Add fail marker if no tests were ran
if ( self.count < 1 ) {
self.fail( "[munit] No tests ran in this module" );
}
// Auto close out any spies
self._spies.reverse().forEach(function( spy ) {
spy.restore();
});
// Proxy teardown to pass start function and forced state
self._teardown(function( e, teardownCallback ) {
if ( e ) {
self._fail( "[munit] failed to teardown '" + self.nsPath + "' module properly", teardownCallback );
}
self._close( startFunc || self.close, forced );
});
return self;
} | [
"function",
"(",
"startFunc",
",",
"forced",
")",
"{",
"var",
"self",
"=",
"this",
",",
"i",
",",
"mod",
";",
"// Can only close an active module",
"self",
".",
"requireState",
"(",
"munit",
".",
"ASSERT_STATE_ACTIVE",
",",
"self",
".",
"close",
")",
";",
"// Add fail marker if no tests were ran",
"if",
"(",
"self",
".",
"count",
"<",
"1",
")",
"{",
"self",
".",
"fail",
"(",
"\"[munit] No tests ran in this module\"",
")",
";",
"}",
"// Auto close out any spies",
"self",
".",
"_spies",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"spy",
")",
"{",
"spy",
".",
"restore",
"(",
")",
";",
"}",
")",
";",
"// Proxy teardown to pass start function and forced state",
"self",
".",
"_teardown",
"(",
"function",
"(",
"e",
",",
"teardownCallback",
")",
"{",
"if",
"(",
"e",
")",
"{",
"self",
".",
"_fail",
"(",
"\"[munit] failed to teardown '\"",
"+",
"self",
".",
"nsPath",
"+",
"\"' module properly\"",
",",
"teardownCallback",
")",
";",
"}",
"self",
".",
"_close",
"(",
"startFunc",
"||",
"self",
".",
"close",
",",
"forced",
")",
";",
"}",
")",
";",
"return",
"self",
";",
"}"
] | Forcing close of module | [
"Forcing",
"close",
"of",
"module"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L982-L1008 |
|
56,842 | codenothing/munit | lib/assert.js | function( startFunc, forced ) {
var self = this, i, mod;
// Handle invalid number of tests ran
if ( self.options.expect > 0 && self.count < self.options.expect && munit.render.focusPath( self.nsPath ) ) {
self._fail(
'[munit] Unexpected End',
startFunc || self._close,
'Expecting ' + self.options.expect + ' tests, only ' + self.count + ' ran.'
);
}
else if ( self.count < 1 && self.callback && munit.render.focusPath( self.nsPath ) ) {
self._fail(
"[munit] No Tests Found",
startFunc || self._close,
"Module closed without any tests being ran."
);
}
// Remove timer
if ( self._timeid ) {
self._timeid = clearTimeout( self._timeid );
}
// Meta
self.end = Date.now();
// Readd the queue back to the stack
if ( self.options.autoQueue && self.queue ) {
munit.queue.add( self.queue );
self.queue = null;
}
// Check to see if submodules have closed off yet
for ( i in self.ns ) {
mod = self.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_CLOSED ) {
// Force close them if needed
if ( forced ) {
mod.close( startFunc || self._close, forced );
}
else {
return self;
}
}
}
// All submodules have closed off, can mark this one as finished
return self.finish( startFunc, forced );
} | javascript | function( startFunc, forced ) {
var self = this, i, mod;
// Handle invalid number of tests ran
if ( self.options.expect > 0 && self.count < self.options.expect && munit.render.focusPath( self.nsPath ) ) {
self._fail(
'[munit] Unexpected End',
startFunc || self._close,
'Expecting ' + self.options.expect + ' tests, only ' + self.count + ' ran.'
);
}
else if ( self.count < 1 && self.callback && munit.render.focusPath( self.nsPath ) ) {
self._fail(
"[munit] No Tests Found",
startFunc || self._close,
"Module closed without any tests being ran."
);
}
// Remove timer
if ( self._timeid ) {
self._timeid = clearTimeout( self._timeid );
}
// Meta
self.end = Date.now();
// Readd the queue back to the stack
if ( self.options.autoQueue && self.queue ) {
munit.queue.add( self.queue );
self.queue = null;
}
// Check to see if submodules have closed off yet
for ( i in self.ns ) {
mod = self.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_CLOSED ) {
// Force close them if needed
if ( forced ) {
mod.close( startFunc || self._close, forced );
}
else {
return self;
}
}
}
// All submodules have closed off, can mark this one as finished
return self.finish( startFunc, forced );
} | [
"function",
"(",
"startFunc",
",",
"forced",
")",
"{",
"var",
"self",
"=",
"this",
",",
"i",
",",
"mod",
";",
"// Handle invalid number of tests ran",
"if",
"(",
"self",
".",
"options",
".",
"expect",
">",
"0",
"&&",
"self",
".",
"count",
"<",
"self",
".",
"options",
".",
"expect",
"&&",
"munit",
".",
"render",
".",
"focusPath",
"(",
"self",
".",
"nsPath",
")",
")",
"{",
"self",
".",
"_fail",
"(",
"'[munit] Unexpected End'",
",",
"startFunc",
"||",
"self",
".",
"_close",
",",
"'Expecting '",
"+",
"self",
".",
"options",
".",
"expect",
"+",
"' tests, only '",
"+",
"self",
".",
"count",
"+",
"' ran.'",
")",
";",
"}",
"else",
"if",
"(",
"self",
".",
"count",
"<",
"1",
"&&",
"self",
".",
"callback",
"&&",
"munit",
".",
"render",
".",
"focusPath",
"(",
"self",
".",
"nsPath",
")",
")",
"{",
"self",
".",
"_fail",
"(",
"\"[munit] No Tests Found\"",
",",
"startFunc",
"||",
"self",
".",
"_close",
",",
"\"Module closed without any tests being ran.\"",
")",
";",
"}",
"// Remove timer",
"if",
"(",
"self",
".",
"_timeid",
")",
"{",
"self",
".",
"_timeid",
"=",
"clearTimeout",
"(",
"self",
".",
"_timeid",
")",
";",
"}",
"// Meta",
"self",
".",
"end",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// Readd the queue back to the stack",
"if",
"(",
"self",
".",
"options",
".",
"autoQueue",
"&&",
"self",
".",
"queue",
")",
"{",
"munit",
".",
"queue",
".",
"add",
"(",
"self",
".",
"queue",
")",
";",
"self",
".",
"queue",
"=",
"null",
";",
"}",
"// Check to see if submodules have closed off yet",
"for",
"(",
"i",
"in",
"self",
".",
"ns",
")",
"{",
"mod",
"=",
"self",
".",
"ns",
"[",
"i",
"]",
";",
"if",
"(",
"mod",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_CLOSED",
")",
"{",
"// Force close them if needed",
"if",
"(",
"forced",
")",
"{",
"mod",
".",
"close",
"(",
"startFunc",
"||",
"self",
".",
"_close",
",",
"forced",
")",
";",
"}",
"else",
"{",
"return",
"self",
";",
"}",
"}",
"}",
"// All submodules have closed off, can mark this one as finished",
"return",
"self",
".",
"finish",
"(",
"startFunc",
",",
"forced",
")",
";",
"}"
] | Closing of module after teardown process | [
"Closing",
"of",
"module",
"after",
"teardown",
"process"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L1011-L1061 |
|
56,843 | codenothing/munit | lib/assert.js | function( startFunc, forced ) {
var self = this, i, mod;
// Can only finish an module that's in a closed state
self.requireState( munit.ASSERT_STATE_CLOSED, startFunc || self.finish );
// Flip state to finished
self.state = munit.ASSERT_STATE_FINISHED;
// Force close each submodule if necessary
for ( i in self.ns ) {
mod = self.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_CLOSED ) {
mod.close( startFunc || self.finish, true );
}
}
// Only print out results if on the focus path
if ( munit.render.focusPath( self.nsPath ) ) {
self._flush();
}
// Finish parent if not forced by it
if ( ! forced ) {
if ( self.parAssert ) {
if ( self.parAssert.state < munit.ASSERT_STATE_CLOSED ) {
munit.render.check();
return self;
}
for ( i in self.parAssert.ns ) {
mod = self.parAssert.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_FINISHED ) {
munit.render.check();
return self;
}
}
self.parAssert.finish();
}
else {
munit.render.check();
}
}
return self;
} | javascript | function( startFunc, forced ) {
var self = this, i, mod;
// Can only finish an module that's in a closed state
self.requireState( munit.ASSERT_STATE_CLOSED, startFunc || self.finish );
// Flip state to finished
self.state = munit.ASSERT_STATE_FINISHED;
// Force close each submodule if necessary
for ( i in self.ns ) {
mod = self.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_CLOSED ) {
mod.close( startFunc || self.finish, true );
}
}
// Only print out results if on the focus path
if ( munit.render.focusPath( self.nsPath ) ) {
self._flush();
}
// Finish parent if not forced by it
if ( ! forced ) {
if ( self.parAssert ) {
if ( self.parAssert.state < munit.ASSERT_STATE_CLOSED ) {
munit.render.check();
return self;
}
for ( i in self.parAssert.ns ) {
mod = self.parAssert.ns[ i ];
if ( mod.state < munit.ASSERT_STATE_FINISHED ) {
munit.render.check();
return self;
}
}
self.parAssert.finish();
}
else {
munit.render.check();
}
}
return self;
} | [
"function",
"(",
"startFunc",
",",
"forced",
")",
"{",
"var",
"self",
"=",
"this",
",",
"i",
",",
"mod",
";",
"// Can only finish an module that's in a closed state",
"self",
".",
"requireState",
"(",
"munit",
".",
"ASSERT_STATE_CLOSED",
",",
"startFunc",
"||",
"self",
".",
"finish",
")",
";",
"// Flip state to finished",
"self",
".",
"state",
"=",
"munit",
".",
"ASSERT_STATE_FINISHED",
";",
"// Force close each submodule if necessary",
"for",
"(",
"i",
"in",
"self",
".",
"ns",
")",
"{",
"mod",
"=",
"self",
".",
"ns",
"[",
"i",
"]",
";",
"if",
"(",
"mod",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_CLOSED",
")",
"{",
"mod",
".",
"close",
"(",
"startFunc",
"||",
"self",
".",
"finish",
",",
"true",
")",
";",
"}",
"}",
"// Only print out results if on the focus path",
"if",
"(",
"munit",
".",
"render",
".",
"focusPath",
"(",
"self",
".",
"nsPath",
")",
")",
"{",
"self",
".",
"_flush",
"(",
")",
";",
"}",
"// Finish parent if not forced by it",
"if",
"(",
"!",
"forced",
")",
"{",
"if",
"(",
"self",
".",
"parAssert",
")",
"{",
"if",
"(",
"self",
".",
"parAssert",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_CLOSED",
")",
"{",
"munit",
".",
"render",
".",
"check",
"(",
")",
";",
"return",
"self",
";",
"}",
"for",
"(",
"i",
"in",
"self",
".",
"parAssert",
".",
"ns",
")",
"{",
"mod",
"=",
"self",
".",
"parAssert",
".",
"ns",
"[",
"i",
"]",
";",
"if",
"(",
"mod",
".",
"state",
"<",
"munit",
".",
"ASSERT_STATE_FINISHED",
")",
"{",
"munit",
".",
"render",
".",
"check",
"(",
")",
";",
"return",
"self",
";",
"}",
"}",
"self",
".",
"parAssert",
".",
"finish",
"(",
")",
";",
"}",
"else",
"{",
"munit",
".",
"render",
".",
"check",
"(",
")",
";",
"}",
"}",
"return",
"self",
";",
"}"
] | Finish this module and all sub modules | [
"Finish",
"this",
"module",
"and",
"all",
"sub",
"modules"
] | aedf3f31aafc05441970eec49eeeb81174c14033 | https://github.com/codenothing/munit/blob/aedf3f31aafc05441970eec49eeeb81174c14033/lib/assert.js#L1064-L1112 |
|
56,844 | davidrayoussef/funcifyr | funcifyr.js | function(n) {
return function chunk(arg) {
if ( Array.isArray(arg) ) {
return arg.reduce((acc,_,i,a) => {
return i % n === 0 ? acc.concat( [a.slice(i, i + n)] ) : acc;
}, []);
}
else if ( typeof arg === 'string' ) {
return arg.match( new RegExp('.{1,' + n + '}', 'g') ) || [];
}
else throw new TypeError('Incorrect type. Passed in value should be an array or string.');
}
} | javascript | function(n) {
return function chunk(arg) {
if ( Array.isArray(arg) ) {
return arg.reduce((acc,_,i,a) => {
return i % n === 0 ? acc.concat( [a.slice(i, i + n)] ) : acc;
}, []);
}
else if ( typeof arg === 'string' ) {
return arg.match( new RegExp('.{1,' + n + '}', 'g') ) || [];
}
else throw new TypeError('Incorrect type. Passed in value should be an array or string.');
}
} | [
"function",
"(",
"n",
")",
"{",
"return",
"function",
"chunk",
"(",
"arg",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arg",
")",
")",
"{",
"return",
"arg",
".",
"reduce",
"(",
"(",
"acc",
",",
"_",
",",
"i",
",",
"a",
")",
"=>",
"{",
"return",
"i",
"%",
"n",
"===",
"0",
"?",
"acc",
".",
"concat",
"(",
"[",
"a",
".",
"slice",
"(",
"i",
",",
"i",
"+",
"n",
")",
"]",
")",
":",
"acc",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"arg",
"===",
"'string'",
")",
"{",
"return",
"arg",
".",
"match",
"(",
"new",
"RegExp",
"(",
"'.{1,'",
"+",
"n",
"+",
"'}'",
",",
"'g'",
")",
")",
"||",
"[",
"]",
";",
"}",
"else",
"throw",
"new",
"TypeError",
"(",
"'Incorrect type. Passed in value should be an array or string.'",
")",
";",
"}",
"}"
] | Returns an array of arrays or strings in chunks of n.
chunkBy :: (n) → (a) → arr
@param n - A number to use as chunk's length
@returns function
@param arg - An array or string to chunk
@returns array | [
"Returns",
"an",
"array",
"of",
"arrays",
"or",
"strings",
"in",
"chunks",
"of",
"n",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L56-L68 |
|
56,845 | davidrayoussef/funcifyr | funcifyr.js | function(fn1, fn2) {
return function composed() {
return fn1.call(null, fn2.apply(null, arguments));
}
} | javascript | function(fn1, fn2) {
return function composed() {
return fn1.call(null, fn2.apply(null, arguments));
}
} | [
"function",
"(",
"fn1",
",",
"fn2",
")",
"{",
"return",
"function",
"composed",
"(",
")",
"{",
"return",
"fn1",
".",
"call",
"(",
"null",
",",
"fn2",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
")",
";",
"}",
"}"
] | Creates a function from two functions that runs fn1 on the results of fn2.
compose :: (fn, fn) → (a) → r
@param (fn1, fn2) - Two functions
@returns function
@param arguments - Any arguments passed to inner function
@returns Result of fn1(fn2(arguments)) | [
"Creates",
"a",
"function",
"from",
"two",
"functions",
"that",
"runs",
"fn1",
"on",
"the",
"results",
"of",
"fn2",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L80-L84 |
|
56,846 | davidrayoussef/funcifyr | funcifyr.js | function(fn) {
return function curried() {
var gatheredArgs = [].slice.call(arguments);
if ( gatheredArgs.length >= fn.length ) {
return fn.apply(null, gatheredArgs);
}
return function(innerArg) {
var newArgs = [].concat(gatheredArgs, innerArg);
return curried.apply(null, newArgs);
}
}
} | javascript | function(fn) {
return function curried() {
var gatheredArgs = [].slice.call(arguments);
if ( gatheredArgs.length >= fn.length ) {
return fn.apply(null, gatheredArgs);
}
return function(innerArg) {
var newArgs = [].concat(gatheredArgs, innerArg);
return curried.apply(null, newArgs);
}
}
} | [
"function",
"(",
"fn",
")",
"{",
"return",
"function",
"curried",
"(",
")",
"{",
"var",
"gatheredArgs",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"if",
"(",
"gatheredArgs",
".",
"length",
">=",
"fn",
".",
"length",
")",
"{",
"return",
"fn",
".",
"apply",
"(",
"null",
",",
"gatheredArgs",
")",
";",
"}",
"return",
"function",
"(",
"innerArg",
")",
"{",
"var",
"newArgs",
"=",
"[",
"]",
".",
"concat",
"(",
"gatheredArgs",
",",
"innerArg",
")",
";",
"return",
"curried",
".",
"apply",
"(",
"null",
",",
"newArgs",
")",
";",
"}",
"}",
"}"
] | Takes a variadic function and returns unary functions until all parameters are used.
curry :: (fn → (a,b,c,d)) → (a) → (b) → (c) → (d) → r
@param fn - A function to be curried
@returns The curried function
@param arguments - Any arguments passed
@returns Either the result of original function if all params were used, OR a unary function
@param innerArg
@returns Call to curried function with additional arg | [
"Takes",
"a",
"variadic",
"function",
"and",
"returns",
"unary",
"functions",
"until",
"all",
"parameters",
"are",
"used",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L98-L111 |
|
56,847 | davidrayoussef/funcifyr | funcifyr.js | function(value, times) {
if (Array.fill) {
return new Array(times).fill(value);
}
return Array.apply(null, Array(+times)).map(function() {
return value;
});
} | javascript | function(value, times) {
if (Array.fill) {
return new Array(times).fill(value);
}
return Array.apply(null, Array(+times)).map(function() {
return value;
});
} | [
"function",
"(",
"value",
",",
"times",
")",
"{",
"if",
"(",
"Array",
".",
"fill",
")",
"{",
"return",
"new",
"Array",
"(",
"times",
")",
".",
"fill",
"(",
"value",
")",
";",
"}",
"return",
"Array",
".",
"apply",
"(",
"null",
",",
"Array",
"(",
"+",
"times",
")",
")",
".",
"map",
"(",
"function",
"(",
")",
"{",
"return",
"value",
";",
"}",
")",
";",
"}"
] | Returns an array filled with a value repeated a number of times.
fill :: (n, n) → arr
@param (value, times) - The value to fill, and the length of the new array
@returns array | [
"Returns",
"an",
"array",
"filled",
"with",
"a",
"value",
"repeated",
"a",
"number",
"of",
"times",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L121-L128 |
|
56,848 | davidrayoussef/funcifyr | funcifyr.js | function(x, fn) {
if (Array.isArray(x) ) {
return x.reduce(function(acc, curr) {
return acc.concat( funcifyr.flatMap(curr, fn) );
}, []);
}
return fn(x);
} | javascript | function(x, fn) {
if (Array.isArray(x) ) {
return x.reduce(function(acc, curr) {
return acc.concat( funcifyr.flatMap(curr, fn) );
}, []);
}
return fn(x);
} | [
"function",
"(",
"x",
",",
"fn",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"x",
")",
")",
"{",
"return",
"x",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"curr",
")",
"{",
"return",
"acc",
".",
"concat",
"(",
"funcifyr",
".",
"flatMap",
"(",
"curr",
",",
"fn",
")",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"return",
"fn",
"(",
"x",
")",
";",
"}"
] | Takes a multidimensional array and a callback function, and returns a new, flattened array with the
results of calling the callback function on each value.
flatMap :: ([a, [b, [c, d]]], fn) → [a, b, c, d]
@param (x, fn) - A multidimensional array and a callback function
@returns array | [
"Takes",
"a",
"multidimensional",
"array",
"and",
"a",
"callback",
"function",
"and",
"returns",
"a",
"new",
"flattened",
"array",
"with",
"the",
"results",
"of",
"calling",
"the",
"callback",
"function",
"on",
"each",
"value",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L139-L146 |
|
56,849 | davidrayoussef/funcifyr | funcifyr.js | function(key) {
return function group(arr) {
return arr.reduce(function(obj, item) {
(obj[item[key]] = obj[item[key]] || []).push(item);
return obj;
}, {});
}
} | javascript | function(key) {
return function group(arr) {
return arr.reduce(function(obj, item) {
(obj[item[key]] = obj[item[key]] || []).push(item);
return obj;
}, {});
}
} | [
"function",
"(",
"key",
")",
"{",
"return",
"function",
"group",
"(",
"arr",
")",
"{",
"return",
"arr",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"item",
")",
"{",
"(",
"obj",
"[",
"item",
"[",
"key",
"]",
"]",
"=",
"obj",
"[",
"item",
"[",
"key",
"]",
"]",
"||",
"[",
"]",
")",
".",
"push",
"(",
"item",
")",
";",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
"}"
] | Groups together related prop values from an array of objects.
groupBy :: (a) → (arr) → obj
@param key - A property name used to do the grouping
@returns function
@param arr - An array of objects
@returns An object of key-value pairs grouped by the key | [
"Groups",
"together",
"related",
"prop",
"values",
"from",
"an",
"array",
"of",
"objects",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L189-L196 |
|
56,850 | davidrayoussef/funcifyr | funcifyr.js | function(collection, fn) {
if ( Array.isArray(collection) ) {
var result = [];
for (var i = 0; i < collection.length; i++) {
result[i] = fn(collection[i], i, collection);
}
return result;
}
else if ( Object.prototype.toString.call(collection) === '[object Object]' ) {
var result = {};
for (var key in collection) {
if ( collection.hasOwnProperty(key) ) {
result[key] = fn(collection[key]);
}
}
return result;
}
else throw new TypeError('Invalid type. First argument must be an array or an object.');
} | javascript | function(collection, fn) {
if ( Array.isArray(collection) ) {
var result = [];
for (var i = 0; i < collection.length; i++) {
result[i] = fn(collection[i], i, collection);
}
return result;
}
else if ( Object.prototype.toString.call(collection) === '[object Object]' ) {
var result = {};
for (var key in collection) {
if ( collection.hasOwnProperty(key) ) {
result[key] = fn(collection[key]);
}
}
return result;
}
else throw new TypeError('Invalid type. First argument must be an array or an object.');
} | [
"function",
"(",
"collection",
",",
"fn",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"collection",
")",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"collection",
".",
"length",
";",
"i",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"=",
"fn",
"(",
"collection",
"[",
"i",
"]",
",",
"i",
",",
"collection",
")",
";",
"}",
"return",
"result",
";",
"}",
"else",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"collection",
")",
"===",
"'[object Object]'",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"collection",
")",
"{",
"if",
"(",
"collection",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"fn",
"(",
"collection",
"[",
"key",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}",
"else",
"throw",
"new",
"TypeError",
"(",
"'Invalid type. First argument must be an array or an object.'",
")",
";",
"}"
] | Maps over a collection and runs a callback on each item.
map :: (obj, fn) → arr
@param (collection, fn) - An array or object to iterate over, and a callback function to run
@returns array or object | [
"Maps",
"over",
"a",
"collection",
"and",
"runs",
"a",
"callback",
"on",
"each",
"item",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L238-L260 |
|
56,851 | davidrayoussef/funcifyr | funcifyr.js | function(fn1, fn2) {
return function orified(arg) {
return fn1.call(null, arg) || fn2.call(null, arg);
}
} | javascript | function(fn1, fn2) {
return function orified(arg) {
return fn1.call(null, arg) || fn2.call(null, arg);
}
} | [
"function",
"(",
"fn1",
",",
"fn2",
")",
"{",
"return",
"function",
"orified",
"(",
"arg",
")",
"{",
"return",
"fn1",
".",
"call",
"(",
"null",
",",
"arg",
")",
"||",
"fn2",
".",
"call",
"(",
"null",
",",
"arg",
")",
";",
"}",
"}"
] | Runs two predicate functions on an argument and returns true if either are true.
or :: (fn, fn) → (a) → bool
@param (fn1, fn2) - Two predicate functions
@returns function
@param arg - An argument to run the two predicate functions on
@returns true or false | [
"Runs",
"two",
"predicate",
"functions",
"on",
"an",
"argument",
"and",
"returns",
"true",
"if",
"either",
"are",
"true",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L304-L308 |
|
56,852 | davidrayoussef/funcifyr | funcifyr.js | function(/*fns*/) {
var fns = [].slice.call(arguments);
return function piped(/*args*/) {
var args = [].slice.call(arguments);
fns.forEach(function(fn) {
args = [fn.apply(null, args)];
});
return args[0];
};
} | javascript | function(/*fns*/) {
var fns = [].slice.call(arguments);
return function piped(/*args*/) {
var args = [].slice.call(arguments);
fns.forEach(function(fn) {
args = [fn.apply(null, args)];
});
return args[0];
};
} | [
"function",
"(",
"/*fns*/",
")",
"{",
"var",
"fns",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"return",
"function",
"piped",
"(",
"/*args*/",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"fns",
".",
"forEach",
"(",
"function",
"(",
"fn",
")",
"{",
"args",
"=",
"[",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
"]",
";",
"}",
")",
";",
"return",
"args",
"[",
"0",
"]",
";",
"}",
";",
"}"
] | Runs several functions, using the result of one function as the argument for the next.
pipe :: (fns) → (a) → r
@param arguments - A variadic number of functions
@returns function
@param arguments - A variadic number of arguments
@returns The result of calling each function on the arguments | [
"Runs",
"several",
"functions",
"using",
"the",
"result",
"of",
"one",
"function",
"as",
"the",
"argument",
"for",
"the",
"next",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L336-L345 |
|
56,853 | davidrayoussef/funcifyr | funcifyr.js | function(start, stop, step) {
if (arguments.length === 1) return funcifyr.range(1, start, 1);
if (arguments.length === 2) return funcifyr.range(start, stop, 1);
var result = [];
for (var i = start; i <= stop; i += step) {
result.push(i);
}
return result;
} | javascript | function(start, stop, step) {
if (arguments.length === 1) return funcifyr.range(1, start, 1);
if (arguments.length === 2) return funcifyr.range(start, stop, 1);
var result = [];
for (var i = start; i <= stop; i += step) {
result.push(i);
}
return result;
} | [
"function",
"(",
"start",
",",
"stop",
",",
"step",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"return",
"funcifyr",
".",
"range",
"(",
"1",
",",
"start",
",",
"1",
")",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"return",
"funcifyr",
".",
"range",
"(",
"start",
",",
"stop",
",",
"1",
")",
";",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"start",
";",
"i",
"<=",
"stop",
";",
"i",
"+=",
"step",
")",
"{",
"result",
".",
"push",
"(",
"i",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Returns an array of numbers ranging from start to stop, incremented by step.
range :: (n, n, n) → arr
@param (start, stop, step) - A start value, a stop value, and a step value to increment by
@returns An array of the range of numbers | [
"Returns",
"an",
"array",
"of",
"numbers",
"ranging",
"from",
"start",
"to",
"stop",
"incremented",
"by",
"step",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L385-L396 |
|
56,854 | davidrayoussef/funcifyr | funcifyr.js | function(str, times) {
if (String.prototype.repeat) return str.repeat(times);
return Array.apply(null, new Array(times)).map(function() {
return str;
}).join('');
} | javascript | function(str, times) {
if (String.prototype.repeat) return str.repeat(times);
return Array.apply(null, new Array(times)).map(function() {
return str;
}).join('');
} | [
"function",
"(",
"str",
",",
"times",
")",
"{",
"if",
"(",
"String",
".",
"prototype",
".",
"repeat",
")",
"return",
"str",
".",
"repeat",
"(",
"times",
")",
";",
"return",
"Array",
".",
"apply",
"(",
"null",
",",
"new",
"Array",
"(",
"times",
")",
")",
".",
"map",
"(",
"function",
"(",
")",
"{",
"return",
"str",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Repeats a string a number of times.
repeat :: (a, n) → r
@param (str, times) - A string to repeat, and a number for the amount of repetitions
@returns A repeated string | [
"Repeats",
"a",
"string",
"a",
"number",
"of",
"times",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L406-L411 |
|
56,855 | davidrayoussef/funcifyr | funcifyr.js | function(arr) {
for (var i = 0; i < arr.length; i++) {
var randIndex = Math.floor(Math.random() * arr.length);
var temp = arr[randIndex];
arr[randIndex] = arr[i];
arr[i] = temp;
}
return arr;
} | javascript | function(arr) {
for (var i = 0; i < arr.length; i++) {
var randIndex = Math.floor(Math.random() * arr.length);
var temp = arr[randIndex];
arr[randIndex] = arr[i];
arr[i] = temp;
}
return arr;
} | [
"function",
"(",
"arr",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"randIndex",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"arr",
".",
"length",
")",
";",
"var",
"temp",
"=",
"arr",
"[",
"randIndex",
"]",
";",
"arr",
"[",
"randIndex",
"]",
"=",
"arr",
"[",
"i",
"]",
";",
"arr",
"[",
"i",
"]",
"=",
"temp",
";",
"}",
"return",
"arr",
";",
"}"
] | Randomly shuffles items in an array.
shuffle :: (arr) → arr
@param arr - An array to be shuffled
@returns A shuffled array | [
"Randomly",
"shuffles",
"items",
"in",
"an",
"array",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L436-L444 |
|
56,856 | davidrayoussef/funcifyr | funcifyr.js | function(prop) {
return function tallied(arrayOfObjects) {
return arrayOfObjects.reduce(function(acc, curr) {
acc[curr[prop]] = (acc[curr[prop]] || 0) + 1;
return acc;
}, {});
}
} | javascript | function(prop) {
return function tallied(arrayOfObjects) {
return arrayOfObjects.reduce(function(acc, curr) {
acc[curr[prop]] = (acc[curr[prop]] || 0) + 1;
return acc;
}, {});
}
} | [
"function",
"(",
"prop",
")",
"{",
"return",
"function",
"tallied",
"(",
"arrayOfObjects",
")",
"{",
"return",
"arrayOfObjects",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"curr",
")",
"{",
"acc",
"[",
"curr",
"[",
"prop",
"]",
"]",
"=",
"(",
"acc",
"[",
"curr",
"[",
"prop",
"]",
"]",
"||",
"0",
")",
"+",
"1",
";",
"return",
"acc",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
"}"
] | Returns an object with the number of occurrences of a property value found in an array of objects.
tally :: (a) → (arr) → obj
@param prop - A string representation of a property to target
@returns function
@param arrayOfObjects - An array of objects
@returns An object with the prop as a key, and the number of its occurences as the value | [
"Returns",
"an",
"object",
"with",
"the",
"number",
"of",
"occurrences",
"of",
"a",
"property",
"value",
"found",
"in",
"an",
"array",
"of",
"objects",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L456-L463 |
|
56,857 | davidrayoussef/funcifyr | funcifyr.js | function(value) {
return {
value: value,
then: function(fn) {
this.value = fn(this.value);
return this;
},
end: function() {
return this.value;
}
};
} | javascript | function(value) {
return {
value: value,
then: function(fn) {
this.value = fn(this.value);
return this;
},
end: function() {
return this.value;
}
};
} | [
"function",
"(",
"value",
")",
"{",
"return",
"{",
"value",
":",
"value",
",",
"then",
":",
"function",
"(",
"fn",
")",
"{",
"this",
".",
"value",
"=",
"fn",
"(",
"this",
".",
"value",
")",
";",
"return",
"this",
";",
"}",
",",
"end",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"value",
";",
"}",
"}",
";",
"}"
] | Creates sequence of chainable actions.
thenify :: (a) → obj
@param value - An initial value
@returns An object with a then function to run on the value, and an end function to return the final value | [
"Creates",
"sequence",
"of",
"chainable",
"actions",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L473-L484 |
|
56,858 | davidrayoussef/funcifyr | funcifyr.js | function(arr) {
if (Array.prototype.from) return Array.from(new Set(arr));
return arr.filter(function(v,i,a) {
return i === a.indexOf(v);
});
} | javascript | function(arr) {
if (Array.prototype.from) return Array.from(new Set(arr));
return arr.filter(function(v,i,a) {
return i === a.indexOf(v);
});
} | [
"function",
"(",
"arr",
")",
"{",
"if",
"(",
"Array",
".",
"prototype",
".",
"from",
")",
"return",
"Array",
".",
"from",
"(",
"new",
"Set",
"(",
"arr",
")",
")",
";",
"return",
"arr",
".",
"filter",
"(",
"function",
"(",
"v",
",",
"i",
",",
"a",
")",
"{",
"return",
"i",
"===",
"a",
".",
"indexOf",
"(",
"v",
")",
";",
"}",
")",
";",
"}"
] | Takes an array with duplicates and returns a new one with all dupes removed.
unique :: (arr) → arr
@param arr
@returns A new array with duplicates removed | [
"Takes",
"an",
"array",
"with",
"duplicates",
"and",
"returns",
"a",
"new",
"one",
"with",
"all",
"dupes",
"removed",
"."
] | 84042752f605a74953b9698c65db4b90b5c4f484 | https://github.com/davidrayoussef/funcifyr/blob/84042752f605a74953b9698c65db4b90b5c4f484/funcifyr.js#L494-L499 |
|
56,859 | winding-lines/ember-cli-typify | lib/typescript-preprocessor.js | typePaths | function typePaths(config) {
var out = [
"node_modules/@types",
];
var paths = (config.compilerOptions && config.compilerOptions.paths) || {};
Object.keys(paths).forEach( function eachEntry(k) {
// paths may contain a /*, eliminate it
paths[k].forEach(function eachPath(a) {
var p = a.split("/\*")[0];
if (out.indexOf(p) < 0) {
out.push(p);
}
});
});
debug("type paths", out);
return out;
} | javascript | function typePaths(config) {
var out = [
"node_modules/@types",
];
var paths = (config.compilerOptions && config.compilerOptions.paths) || {};
Object.keys(paths).forEach( function eachEntry(k) {
// paths may contain a /*, eliminate it
paths[k].forEach(function eachPath(a) {
var p = a.split("/\*")[0];
if (out.indexOf(p) < 0) {
out.push(p);
}
});
});
debug("type paths", out);
return out;
} | [
"function",
"typePaths",
"(",
"config",
")",
"{",
"var",
"out",
"=",
"[",
"\"node_modules/@types\"",
",",
"]",
";",
"var",
"paths",
"=",
"(",
"config",
".",
"compilerOptions",
"&&",
"config",
".",
"compilerOptions",
".",
"paths",
")",
"||",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"paths",
")",
".",
"forEach",
"(",
"function",
"eachEntry",
"(",
"k",
")",
"{",
"// paths may contain a /*, eliminate it",
"paths",
"[",
"k",
"]",
".",
"forEach",
"(",
"function",
"eachPath",
"(",
"a",
")",
"{",
"var",
"p",
"=",
"a",
".",
"split",
"(",
"\"/\\*\"",
")",
"[",
"0",
"]",
";",
"if",
"(",
"out",
".",
"indexOf",
"(",
"p",
")",
"<",
"0",
")",
"{",
"out",
".",
"push",
"(",
"p",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"debug",
"(",
"\"type paths\"",
",",
"out",
")",
";",
"return",
"out",
";",
"}"
] | Return the paths which contain type information. | [
"Return",
"the",
"paths",
"which",
"contain",
"type",
"information",
"."
] | 3551e75bf6e00850b77365b18c3f6cef8b24137b | https://github.com/winding-lines/ember-cli-typify/blob/3551e75bf6e00850b77365b18c3f6cef8b24137b/lib/typescript-preprocessor.js#L30-L46 |
56,860 | wzrdtales/umigrate-mariadb | index.js | function ( config, callback )
{
var self = this;
var db = Array(),
diff = Array(),
first = true;
for( var c = 0; c < 2; ++c )
{
db[ c ] = Array();
for( var d = 0; d < 2; ++d )
{
db[ c ][ d ] = Array();
}
}
var query = util.format( 'USE %s; SHOW FULL TABLES', config.database );
this.runSql( query, null, { useArray: true } )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row[ 0 ] && row[ 1 ] === 'VIEW' )
db[ 0 ][ 1 ].push( row[ 0 ] );
else if ( row[ 0 ] && row[ 0 ] !== 'migrations' )
db[ 0 ][ 0 ].push( row[ 0 ] );
} );
} )
.on( 'end', function ()
{
if ( config.diffDump )
first = false;
else
callback( db );
} );
if ( config.diffDump )
{
query = util.format( 'USE %s; SHOW FULL TABLES', config.database_diff );
this.runSql( query, null, { useArray: true } )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row[ 0 ] && row[ 1 ] === 'VIEW' )
db[ 1 ][ 1 ].push( row[ 0 ] );
else if ( row[ 0 ] && row[ 0 ] !== 'migrations' )
db[ 1 ][ 0 ].push( row[ 0 ] );
} );
} )
.on( 'end', function ()
{
while ( first )
{
deasync.sleep( 100 );
}
callback( db );
} );
}
} | javascript | function ( config, callback )
{
var self = this;
var db = Array(),
diff = Array(),
first = true;
for( var c = 0; c < 2; ++c )
{
db[ c ] = Array();
for( var d = 0; d < 2; ++d )
{
db[ c ][ d ] = Array();
}
}
var query = util.format( 'USE %s; SHOW FULL TABLES', config.database );
this.runSql( query, null, { useArray: true } )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row[ 0 ] && row[ 1 ] === 'VIEW' )
db[ 0 ][ 1 ].push( row[ 0 ] );
else if ( row[ 0 ] && row[ 0 ] !== 'migrations' )
db[ 0 ][ 0 ].push( row[ 0 ] );
} );
} )
.on( 'end', function ()
{
if ( config.diffDump )
first = false;
else
callback( db );
} );
if ( config.diffDump )
{
query = util.format( 'USE %s; SHOW FULL TABLES', config.database_diff );
this.runSql( query, null, { useArray: true } )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row[ 0 ] && row[ 1 ] === 'VIEW' )
db[ 1 ][ 1 ].push( row[ 0 ] );
else if ( row[ 0 ] && row[ 0 ] !== 'migrations' )
db[ 1 ][ 0 ].push( row[ 0 ] );
} );
} )
.on( 'end', function ()
{
while ( first )
{
deasync.sleep( 100 );
}
callback( db );
} );
}
} | [
"function",
"(",
"config",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"db",
"=",
"Array",
"(",
")",
",",
"diff",
"=",
"Array",
"(",
")",
",",
"first",
"=",
"true",
";",
"for",
"(",
"var",
"c",
"=",
"0",
";",
"c",
"<",
"2",
";",
"++",
"c",
")",
"{",
"db",
"[",
"c",
"]",
"=",
"Array",
"(",
")",
";",
"for",
"(",
"var",
"d",
"=",
"0",
";",
"d",
"<",
"2",
";",
"++",
"d",
")",
"{",
"db",
"[",
"c",
"]",
"[",
"d",
"]",
"=",
"Array",
"(",
")",
";",
"}",
"}",
"var",
"query",
"=",
"util",
".",
"format",
"(",
"'USE %s; SHOW FULL TABLES'",
",",
"config",
".",
"database",
")",
";",
"this",
".",
"runSql",
"(",
"query",
",",
"null",
",",
"{",
"useArray",
":",
"true",
"}",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"if",
"(",
"row",
"[",
"0",
"]",
"&&",
"row",
"[",
"1",
"]",
"===",
"'VIEW'",
")",
"db",
"[",
"0",
"]",
"[",
"1",
"]",
".",
"push",
"(",
"row",
"[",
"0",
"]",
")",
";",
"else",
"if",
"(",
"row",
"[",
"0",
"]",
"&&",
"row",
"[",
"0",
"]",
"!==",
"'migrations'",
")",
"db",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"push",
"(",
"row",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"config",
".",
"diffDump",
")",
"first",
"=",
"false",
";",
"else",
"callback",
"(",
"db",
")",
";",
"}",
")",
";",
"if",
"(",
"config",
".",
"diffDump",
")",
"{",
"query",
"=",
"util",
".",
"format",
"(",
"'USE %s; SHOW FULL TABLES'",
",",
"config",
".",
"database_diff",
")",
";",
"this",
".",
"runSql",
"(",
"query",
",",
"null",
",",
"{",
"useArray",
":",
"true",
"}",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"if",
"(",
"row",
"[",
"0",
"]",
"&&",
"row",
"[",
"1",
"]",
"===",
"'VIEW'",
")",
"db",
"[",
"1",
"]",
"[",
"1",
"]",
".",
"push",
"(",
"row",
"[",
"0",
"]",
")",
";",
"else",
"if",
"(",
"row",
"[",
"0",
"]",
"&&",
"row",
"[",
"0",
"]",
"!==",
"'migrations'",
")",
"db",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"push",
"(",
"row",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"while",
"(",
"first",
")",
"{",
"deasync",
".",
"sleep",
"(",
"100",
")",
";",
"}",
"callback",
"(",
"db",
")",
";",
"}",
")",
";",
"}",
"}"
] | Returns an array containing the Tables.
General return information:
This array has 2 layers, the final information layer has
8 elements.
Array Format:
Layer 1:
[0] = real table, [1] = diff table
Layer 3 (Result formatting):
[0] = table array*, [1] = view array*
Table Array (Content)
List of table name per array element
View Array (Content)
List of view name per array element
@return array | [
"Returns",
"an",
"array",
"containing",
"the",
"Tables",
"."
] | b3ca76d7adb0660044b464c3564a852a454d24f0 | https://github.com/wzrdtales/umigrate-mariadb/blob/b3ca76d7adb0660044b464c3564a852a454d24f0/index.js#L43-L104 |
|
56,861 | wzrdtales/umigrate-mariadb | index.js | function ( config, callback )
{
var self = this;
var db = Array(),
diff = Array(),
first = true;
db[ 0 ] = Array();
db[ 1 ] = Array();
diff[ 0 ] = Array();
diff[ 1 ] = Array();
var query = 'SELECT name, modified, type FROM mysql.proc WHERE db = ?';
this.runSql( query, [ config.database ] )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row.type === 'FUNCTION' )
db[ 0 ].push( [ row.name, row.modified ] );
else if ( row.type === 'PROCEDURE' )
db[ 1 ].push( [ row.name, row.modified ] );
} );
} )
.on( 'end', function ()
{
if ( config.diffDump )
first = false;
else
callback( db );
} );
if ( config.diffDump )
{
var query = 'SELECT name, modified, type FROM mysql.proc WHERE db = ?';
this.runSql( query, [ config.database_diff ], false )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row.type === 'FUNCTION' )
diff[ 0 ].push( [ row.name, row.modified ] );
else if ( row.type === 'PROCEDURE' )
diff[ 1 ].push( [ row.name, row.modified ] );
} );
} )
.on( 'end', function ()
{
while ( first )
{
deasync.sleep( 100 );
}
callback( db, diff );
} );
}
} | javascript | function ( config, callback )
{
var self = this;
var db = Array(),
diff = Array(),
first = true;
db[ 0 ] = Array();
db[ 1 ] = Array();
diff[ 0 ] = Array();
diff[ 1 ] = Array();
var query = 'SELECT name, modified, type FROM mysql.proc WHERE db = ?';
this.runSql( query, [ config.database ] )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row.type === 'FUNCTION' )
db[ 0 ].push( [ row.name, row.modified ] );
else if ( row.type === 'PROCEDURE' )
db[ 1 ].push( [ row.name, row.modified ] );
} );
} )
.on( 'end', function ()
{
if ( config.diffDump )
first = false;
else
callback( db );
} );
if ( config.diffDump )
{
var query = 'SELECT name, modified, type FROM mysql.proc WHERE db = ?';
this.runSql( query, [ config.database_diff ], false )
.on( 'result', function ( res )
{
res.on( 'data', function ( row )
{
if ( row.type === 'FUNCTION' )
diff[ 0 ].push( [ row.name, row.modified ] );
else if ( row.type === 'PROCEDURE' )
diff[ 1 ].push( [ row.name, row.modified ] );
} );
} )
.on( 'end', function ()
{
while ( first )
{
deasync.sleep( 100 );
}
callback( db, diff );
} );
}
} | [
"function",
"(",
"config",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"db",
"=",
"Array",
"(",
")",
",",
"diff",
"=",
"Array",
"(",
")",
",",
"first",
"=",
"true",
";",
"db",
"[",
"0",
"]",
"=",
"Array",
"(",
")",
";",
"db",
"[",
"1",
"]",
"=",
"Array",
"(",
")",
";",
"diff",
"[",
"0",
"]",
"=",
"Array",
"(",
")",
";",
"diff",
"[",
"1",
"]",
"=",
"Array",
"(",
")",
";",
"var",
"query",
"=",
"'SELECT name, modified, type FROM mysql.proc WHERE db = ?'",
";",
"this",
".",
"runSql",
"(",
"query",
",",
"[",
"config",
".",
"database",
"]",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"if",
"(",
"row",
".",
"type",
"===",
"'FUNCTION'",
")",
"db",
"[",
"0",
"]",
".",
"push",
"(",
"[",
"row",
".",
"name",
",",
"row",
".",
"modified",
"]",
")",
";",
"else",
"if",
"(",
"row",
".",
"type",
"===",
"'PROCEDURE'",
")",
"db",
"[",
"1",
"]",
".",
"push",
"(",
"[",
"row",
".",
"name",
",",
"row",
".",
"modified",
"]",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"config",
".",
"diffDump",
")",
"first",
"=",
"false",
";",
"else",
"callback",
"(",
"db",
")",
";",
"}",
")",
";",
"if",
"(",
"config",
".",
"diffDump",
")",
"{",
"var",
"query",
"=",
"'SELECT name, modified, type FROM mysql.proc WHERE db = ?'",
";",
"this",
".",
"runSql",
"(",
"query",
",",
"[",
"config",
".",
"database_diff",
"]",
",",
"false",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"if",
"(",
"row",
".",
"type",
"===",
"'FUNCTION'",
")",
"diff",
"[",
"0",
"]",
".",
"push",
"(",
"[",
"row",
".",
"name",
",",
"row",
".",
"modified",
"]",
")",
";",
"else",
"if",
"(",
"row",
".",
"type",
"===",
"'PROCEDURE'",
")",
"diff",
"[",
"1",
"]",
".",
"push",
"(",
"[",
"row",
".",
"name",
",",
"row",
".",
"modified",
"]",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"while",
"(",
"first",
")",
"{",
"deasync",
".",
"sleep",
"(",
"100",
")",
";",
"}",
"callback",
"(",
"db",
",",
"diff",
")",
";",
"}",
")",
";",
"}",
"}"
] | No specification yet.
@return useless | [
"No",
"specification",
"yet",
"."
] | b3ca76d7adb0660044b464c3564a852a454d24f0 | https://github.com/wzrdtales/umigrate-mariadb/blob/b3ca76d7adb0660044b464c3564a852a454d24f0/index.js#L222-L278 |
|
56,862 | wzrdtales/umigrate-mariadb | index.js | function ( config, tables, context, callback )
{
var self = this;
var db = Array(),
counter = 0,
query = 'SHOW INDEX FROM %s.%s;';
db[ 0 ] = Array();
db[ 1 ] = Array();
var len = ( tables.tables[ 0 ].length > tables.tables[ 1 ].length ) ?
tables.tables[ 0 ].length : tables.tables[ 1 ].length;
for ( var i = 0; i < len; ++i )
{
var q = '',
stmt = 0;
if ( tables.tables[ 0 ][ i ] )
q = util.format( query, config.database, tables.tables[ 0 ][ i ] );
else ++stmt;
if ( tables.tables[ 1 ][ i ] )
q += util.format( query, config.database_diff, tables.tables[ 1 ][ i ] );
//scoping stmt and interator to event
( function ( stmt, i )
{
self.runSql( q, null, { useArray: true } )
.on( 'result', function ( res )
{
var local = stmt++;
res.on( 'data', function ( row )
{
row[ 0 ] = row[ 2 ]; //replace table by key name
row[ 1 ] = row[ 1 ] === '0';
row.splice( 2, 1 ); //delete moved key name
//<-- Seq_in_index has now moved one index lower
row.splice( 4, 4 ); //delete until null info
row[ 4 ] = ( row[ 4 ] === 'YES' ) ? true : false;
//Comment and Index_comment will be simply ignored
//Maybe I'm going to implement them later, but not for now.
if ( !db[ local ][ tables.tables[ local ][ i ] ] )
db[ local ][ tables.tables[ local ][ i ] ] = Array();
db[ local ][ tables.tables[ local ][ i ] ].push( row );
} );
} )
.on( 'end', function ()
{
if ( ++counter >= len )
callback( context, db );
} );
} )( stmt, i );
}
} | javascript | function ( config, tables, context, callback )
{
var self = this;
var db = Array(),
counter = 0,
query = 'SHOW INDEX FROM %s.%s;';
db[ 0 ] = Array();
db[ 1 ] = Array();
var len = ( tables.tables[ 0 ].length > tables.tables[ 1 ].length ) ?
tables.tables[ 0 ].length : tables.tables[ 1 ].length;
for ( var i = 0; i < len; ++i )
{
var q = '',
stmt = 0;
if ( tables.tables[ 0 ][ i ] )
q = util.format( query, config.database, tables.tables[ 0 ][ i ] );
else ++stmt;
if ( tables.tables[ 1 ][ i ] )
q += util.format( query, config.database_diff, tables.tables[ 1 ][ i ] );
//scoping stmt and interator to event
( function ( stmt, i )
{
self.runSql( q, null, { useArray: true } )
.on( 'result', function ( res )
{
var local = stmt++;
res.on( 'data', function ( row )
{
row[ 0 ] = row[ 2 ]; //replace table by key name
row[ 1 ] = row[ 1 ] === '0';
row.splice( 2, 1 ); //delete moved key name
//<-- Seq_in_index has now moved one index lower
row.splice( 4, 4 ); //delete until null info
row[ 4 ] = ( row[ 4 ] === 'YES' ) ? true : false;
//Comment and Index_comment will be simply ignored
//Maybe I'm going to implement them later, but not for now.
if ( !db[ local ][ tables.tables[ local ][ i ] ] )
db[ local ][ tables.tables[ local ][ i ] ] = Array();
db[ local ][ tables.tables[ local ][ i ] ].push( row );
} );
} )
.on( 'end', function ()
{
if ( ++counter >= len )
callback( context, db );
} );
} )( stmt, i );
}
} | [
"function",
"(",
"config",
",",
"tables",
",",
"context",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"db",
"=",
"Array",
"(",
")",
",",
"counter",
"=",
"0",
",",
"query",
"=",
"'SHOW INDEX FROM %s.%s;'",
";",
"db",
"[",
"0",
"]",
"=",
"Array",
"(",
")",
";",
"db",
"[",
"1",
"]",
"=",
"Array",
"(",
")",
";",
"var",
"len",
"=",
"(",
"tables",
".",
"tables",
"[",
"0",
"]",
".",
"length",
">",
"tables",
".",
"tables",
"[",
"1",
"]",
".",
"length",
")",
"?",
"tables",
".",
"tables",
"[",
"0",
"]",
".",
"length",
":",
"tables",
".",
"tables",
"[",
"1",
"]",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"q",
"=",
"''",
",",
"stmt",
"=",
"0",
";",
"if",
"(",
"tables",
".",
"tables",
"[",
"0",
"]",
"[",
"i",
"]",
")",
"q",
"=",
"util",
".",
"format",
"(",
"query",
",",
"config",
".",
"database",
",",
"tables",
".",
"tables",
"[",
"0",
"]",
"[",
"i",
"]",
")",
";",
"else",
"++",
"stmt",
";",
"if",
"(",
"tables",
".",
"tables",
"[",
"1",
"]",
"[",
"i",
"]",
")",
"q",
"+=",
"util",
".",
"format",
"(",
"query",
",",
"config",
".",
"database_diff",
",",
"tables",
".",
"tables",
"[",
"1",
"]",
"[",
"i",
"]",
")",
";",
"//scoping stmt and interator to event",
"(",
"function",
"(",
"stmt",
",",
"i",
")",
"{",
"self",
".",
"runSql",
"(",
"q",
",",
"null",
",",
"{",
"useArray",
":",
"true",
"}",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"var",
"local",
"=",
"stmt",
"++",
";",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"row",
"[",
"0",
"]",
"=",
"row",
"[",
"2",
"]",
";",
"//replace table by key name",
"row",
"[",
"1",
"]",
"=",
"row",
"[",
"1",
"]",
"===",
"'0'",
";",
"row",
".",
"splice",
"(",
"2",
",",
"1",
")",
";",
"//delete moved key name",
"//<-- Seq_in_index has now moved one index lower",
"row",
".",
"splice",
"(",
"4",
",",
"4",
")",
";",
"//delete until null info",
"row",
"[",
"4",
"]",
"=",
"(",
"row",
"[",
"4",
"]",
"===",
"'YES'",
")",
"?",
"true",
":",
"false",
";",
"//Comment and Index_comment will be simply ignored",
"//Maybe I'm going to implement them later, but not for now.",
"if",
"(",
"!",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
")",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
"=",
"Array",
"(",
")",
";",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
".",
"push",
"(",
"row",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"++",
"counter",
">=",
"len",
")",
"callback",
"(",
"context",
",",
"db",
")",
";",
"}",
")",
";",
"}",
")",
"(",
"stmt",
",",
"i",
")",
";",
"}",
"}"
] | Returns an array containing the indizies.
General return information:
This array has 3 layers, the final information layer has
6 elements.
Array Format:
Layer 1:
[0] = real table, [1] = diff table
Layer 2:
['tablename'] = Array for final table indizies information
Layer 3 (Result formatting):
[0] = key name, [1] = unique( true or false ),
[2] = Position of column in index (Sequence in index),
[3] = column name, [4] = Nullable, [5] = index type
@return array | [
"Returns",
"an",
"array",
"containing",
"the",
"indizies",
"."
] | b3ca76d7adb0660044b464c3564a852a454d24f0 | https://github.com/wzrdtales/umigrate-mariadb/blob/b3ca76d7adb0660044b464c3564a852a454d24f0/index.js#L369-L426 |
|
56,863 | wzrdtales/umigrate-mariadb | index.js | function ( config, tables, context, callback )
{
var self = this,
db = Array(),
counter = 0;
db[ 0 ] = Array();
db[ 1 ] = Array();
var len = ( tables.tables[ 0 ].length > tables.tables[ 1 ].length ) ?
tables.tables[ 0 ].length : tables.tables[ 1 ].length;
var query = [
'SELECT const.CONSTRAINT_NAME, const.CONSTRAINT_SCHEMA,const.TABLE_NAME,',
'const.REFERENCED_TABLE_NAME,const.UPDATE_RULE,const.DELETE_RULE,',
'const_keys.COLUMN_NAME,const_keys.POSITION_IN_UNIQUE_CONSTRAINT,',
'const_keys.REFERENCED_COLUMN_NAME,const_keys.REFERENCED_TABLE_SCHEMA',
'FROM information_schema.REFERENTIAL_CONSTRAINTS const',
'INNER JOIN information_schema.KEY_COLUMN_USAGE const_keys ON ( ',
'const_keys.CONSTRAINT_SCHEMA = const.CONSTRAINT_SCHEMA',
'AND const_keys.CONSTRAINT_NAME = const.CONSTRAINT_NAME )',
'WHERE const.CONSTRAINT_SCHEMA = ?',
'AND const.TABLE_NAME = ?;'
]
.join( ' ' );
for ( var i = 0; i < len; ++i )
{
var q = '',
params = Array(),
stmt = 0;
if ( tables.tables[ 0 ][ i ] )
{
q = query;
params.push( config.database );
params.push( tables.tables[ 0 ][ i ] );
}
else ++stmt;
if ( tables.tables[ 1 ][ i ] )
{
q += query;
params.push( config.database_diff );
params.push( tables.tables[ 1 ][ i ] );
}
//scoping stmt and interator to event
( function ( stmt, i )
{
self.runSql( q, params, { useArray: true } )
.on( 'result', function ( res )
{
var local = stmt++;
res.on( 'data', function ( row )
{
constraint = Array();
if ( !db[ local ][ tables.tables[ local ][ i ] ] )
db[ local ][ tables.tables[ local ][ i ] ] = Array();
constraint[ 0 ] = row[ 0 ]; //constraint_name
constraint[ 1 ] = row[ 6 ]; //column_name
constraint[ 2 ] = row[ 9 ]; //referenced_table_schema
constraint[ 3 ] = row[ 3 ]; //referenced_table_name
constraint[ 4 ] = row[ 8 ]; //referenced_column_name
constraint[ 5 ] = row[ 7 ]; //position_in_unique_constraint
constraint[ 6 ] = row[ 4 ]; //on_update
constraint[ 7 ] = row[ 5 ]; //on_delete
db[ local ][ tables.tables[ local ][ i ] ].push( constraint );
} );
} )
.on( 'end', function ()
{
if ( ++counter >= len )
callback( context, db );
} );
} )( stmt, i );
}
} | javascript | function ( config, tables, context, callback )
{
var self = this,
db = Array(),
counter = 0;
db[ 0 ] = Array();
db[ 1 ] = Array();
var len = ( tables.tables[ 0 ].length > tables.tables[ 1 ].length ) ?
tables.tables[ 0 ].length : tables.tables[ 1 ].length;
var query = [
'SELECT const.CONSTRAINT_NAME, const.CONSTRAINT_SCHEMA,const.TABLE_NAME,',
'const.REFERENCED_TABLE_NAME,const.UPDATE_RULE,const.DELETE_RULE,',
'const_keys.COLUMN_NAME,const_keys.POSITION_IN_UNIQUE_CONSTRAINT,',
'const_keys.REFERENCED_COLUMN_NAME,const_keys.REFERENCED_TABLE_SCHEMA',
'FROM information_schema.REFERENTIAL_CONSTRAINTS const',
'INNER JOIN information_schema.KEY_COLUMN_USAGE const_keys ON ( ',
'const_keys.CONSTRAINT_SCHEMA = const.CONSTRAINT_SCHEMA',
'AND const_keys.CONSTRAINT_NAME = const.CONSTRAINT_NAME )',
'WHERE const.CONSTRAINT_SCHEMA = ?',
'AND const.TABLE_NAME = ?;'
]
.join( ' ' );
for ( var i = 0; i < len; ++i )
{
var q = '',
params = Array(),
stmt = 0;
if ( tables.tables[ 0 ][ i ] )
{
q = query;
params.push( config.database );
params.push( tables.tables[ 0 ][ i ] );
}
else ++stmt;
if ( tables.tables[ 1 ][ i ] )
{
q += query;
params.push( config.database_diff );
params.push( tables.tables[ 1 ][ i ] );
}
//scoping stmt and interator to event
( function ( stmt, i )
{
self.runSql( q, params, { useArray: true } )
.on( 'result', function ( res )
{
var local = stmt++;
res.on( 'data', function ( row )
{
constraint = Array();
if ( !db[ local ][ tables.tables[ local ][ i ] ] )
db[ local ][ tables.tables[ local ][ i ] ] = Array();
constraint[ 0 ] = row[ 0 ]; //constraint_name
constraint[ 1 ] = row[ 6 ]; //column_name
constraint[ 2 ] = row[ 9 ]; //referenced_table_schema
constraint[ 3 ] = row[ 3 ]; //referenced_table_name
constraint[ 4 ] = row[ 8 ]; //referenced_column_name
constraint[ 5 ] = row[ 7 ]; //position_in_unique_constraint
constraint[ 6 ] = row[ 4 ]; //on_update
constraint[ 7 ] = row[ 5 ]; //on_delete
db[ local ][ tables.tables[ local ][ i ] ].push( constraint );
} );
} )
.on( 'end', function ()
{
if ( ++counter >= len )
callback( context, db );
} );
} )( stmt, i );
}
} | [
"function",
"(",
"config",
",",
"tables",
",",
"context",
",",
"callback",
")",
"{",
"var",
"self",
"=",
"this",
",",
"db",
"=",
"Array",
"(",
")",
",",
"counter",
"=",
"0",
";",
"db",
"[",
"0",
"]",
"=",
"Array",
"(",
")",
";",
"db",
"[",
"1",
"]",
"=",
"Array",
"(",
")",
";",
"var",
"len",
"=",
"(",
"tables",
".",
"tables",
"[",
"0",
"]",
".",
"length",
">",
"tables",
".",
"tables",
"[",
"1",
"]",
".",
"length",
")",
"?",
"tables",
".",
"tables",
"[",
"0",
"]",
".",
"length",
":",
"tables",
".",
"tables",
"[",
"1",
"]",
".",
"length",
";",
"var",
"query",
"=",
"[",
"'SELECT const.CONSTRAINT_NAME, const.CONSTRAINT_SCHEMA,const.TABLE_NAME,'",
",",
"'const.REFERENCED_TABLE_NAME,const.UPDATE_RULE,const.DELETE_RULE,'",
",",
"'const_keys.COLUMN_NAME,const_keys.POSITION_IN_UNIQUE_CONSTRAINT,'",
",",
"'const_keys.REFERENCED_COLUMN_NAME,const_keys.REFERENCED_TABLE_SCHEMA'",
",",
"'FROM information_schema.REFERENTIAL_CONSTRAINTS const'",
",",
"'INNER JOIN information_schema.KEY_COLUMN_USAGE const_keys ON ( '",
",",
"'const_keys.CONSTRAINT_SCHEMA = const.CONSTRAINT_SCHEMA'",
",",
"'AND const_keys.CONSTRAINT_NAME = const.CONSTRAINT_NAME )'",
",",
"'WHERE const.CONSTRAINT_SCHEMA = ?'",
",",
"'AND const.TABLE_NAME = ?;'",
"]",
".",
"join",
"(",
"' '",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"q",
"=",
"''",
",",
"params",
"=",
"Array",
"(",
")",
",",
"stmt",
"=",
"0",
";",
"if",
"(",
"tables",
".",
"tables",
"[",
"0",
"]",
"[",
"i",
"]",
")",
"{",
"q",
"=",
"query",
";",
"params",
".",
"push",
"(",
"config",
".",
"database",
")",
";",
"params",
".",
"push",
"(",
"tables",
".",
"tables",
"[",
"0",
"]",
"[",
"i",
"]",
")",
";",
"}",
"else",
"++",
"stmt",
";",
"if",
"(",
"tables",
".",
"tables",
"[",
"1",
"]",
"[",
"i",
"]",
")",
"{",
"q",
"+=",
"query",
";",
"params",
".",
"push",
"(",
"config",
".",
"database_diff",
")",
";",
"params",
".",
"push",
"(",
"tables",
".",
"tables",
"[",
"1",
"]",
"[",
"i",
"]",
")",
";",
"}",
"//scoping stmt and interator to event",
"(",
"function",
"(",
"stmt",
",",
"i",
")",
"{",
"self",
".",
"runSql",
"(",
"q",
",",
"params",
",",
"{",
"useArray",
":",
"true",
"}",
")",
".",
"on",
"(",
"'result'",
",",
"function",
"(",
"res",
")",
"{",
"var",
"local",
"=",
"stmt",
"++",
";",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"row",
")",
"{",
"constraint",
"=",
"Array",
"(",
")",
";",
"if",
"(",
"!",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
")",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
"=",
"Array",
"(",
")",
";",
"constraint",
"[",
"0",
"]",
"=",
"row",
"[",
"0",
"]",
";",
"//constraint_name",
"constraint",
"[",
"1",
"]",
"=",
"row",
"[",
"6",
"]",
";",
"//column_name",
"constraint",
"[",
"2",
"]",
"=",
"row",
"[",
"9",
"]",
";",
"//referenced_table_schema",
"constraint",
"[",
"3",
"]",
"=",
"row",
"[",
"3",
"]",
";",
"//referenced_table_name",
"constraint",
"[",
"4",
"]",
"=",
"row",
"[",
"8",
"]",
";",
"//referenced_column_name",
"constraint",
"[",
"5",
"]",
"=",
"row",
"[",
"7",
"]",
";",
"//position_in_unique_constraint",
"constraint",
"[",
"6",
"]",
"=",
"row",
"[",
"4",
"]",
";",
"//on_update",
"constraint",
"[",
"7",
"]",
"=",
"row",
"[",
"5",
"]",
";",
"//on_delete",
"db",
"[",
"local",
"]",
"[",
"tables",
".",
"tables",
"[",
"local",
"]",
"[",
"i",
"]",
"]",
".",
"push",
"(",
"constraint",
")",
";",
"}",
")",
";",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"++",
"counter",
">=",
"len",
")",
"callback",
"(",
"context",
",",
"db",
")",
";",
"}",
")",
";",
"}",
")",
"(",
"stmt",
",",
"i",
")",
";",
"}",
"}"
] | Returns an array containing the foreign keys.
General return information:
This array has 3 layers, the final information layer has
8 elements.
Array Format:
Layer 1:
[0] = real table, [1] = diff table
Layer 2:
['tablename'] = Array for final table indizies information
Layer 3 (Result formatting):
[0] = foreign_key_name, [1] = column_name, [2] = referenced_table_schema,
[3] = referenced_table_name, [4] = referenced_column_name,
[5] = position_in_unique_constraint, [6] = on_update,
[7] = on_delete
@return array | [
"Returns",
"an",
"array",
"containing",
"the",
"foreign",
"keys",
"."
] | b3ca76d7adb0660044b464c3564a852a454d24f0 | https://github.com/wzrdtales/umigrate-mariadb/blob/b3ca76d7adb0660044b464c3564a852a454d24f0/index.js#L451-L531 |
|
56,864 | Arcath/etch-router | docs/js/components/static.js | function (wholeMatch, match, left, right) {
// unescape match to prevent double escaping
match = htmlunencode(match);
return left + hljs.highlightAuto(match).value + right;
} | javascript | function (wholeMatch, match, left, right) {
// unescape match to prevent double escaping
match = htmlunencode(match);
return left + hljs.highlightAuto(match).value + right;
} | [
"function",
"(",
"wholeMatch",
",",
"match",
",",
"left",
",",
"right",
")",
"{",
"// unescape match to prevent double escaping",
"match",
"=",
"htmlunencode",
"(",
"match",
")",
";",
"return",
"left",
"+",
"hljs",
".",
"highlightAuto",
"(",
"match",
")",
".",
"value",
"+",
"right",
";",
"}"
] | use new shodown's regexp engine to conditionally parse codeblocks | [
"use",
"new",
"shodown",
"s",
"regexp",
"engine",
"to",
"conditionally",
"parse",
"codeblocks"
] | 90b1e2f69c567d6b9f7165a13ca0144e789d7edb | https://github.com/Arcath/etch-router/blob/90b1e2f69c567d6b9f7165a13ca0144e789d7edb/docs/js/components/static.js#L23-L27 |
|
56,865 | heroqu/hash-through | index.js | HashThrough | function HashThrough (createHash) {
const hashThrough = new Transform()
const hash = createHash()
hashThrough._transform = function (chunk, encoding, cb) {
setImmediate(_ => {
try {
hash.update(chunk)
cb(null, chunk)
} catch (err) {
cb(err)
}
})
}
// bind the digest function to hash object
hashThrough.digest = format => hash.digest(format)
return hashThrough
} | javascript | function HashThrough (createHash) {
const hashThrough = new Transform()
const hash = createHash()
hashThrough._transform = function (chunk, encoding, cb) {
setImmediate(_ => {
try {
hash.update(chunk)
cb(null, chunk)
} catch (err) {
cb(err)
}
})
}
// bind the digest function to hash object
hashThrough.digest = format => hash.digest(format)
return hashThrough
} | [
"function",
"HashThrough",
"(",
"createHash",
")",
"{",
"const",
"hashThrough",
"=",
"new",
"Transform",
"(",
")",
"const",
"hash",
"=",
"createHash",
"(",
")",
"hashThrough",
".",
"_transform",
"=",
"function",
"(",
"chunk",
",",
"encoding",
",",
"cb",
")",
"{",
"setImmediate",
"(",
"_",
"=>",
"{",
"try",
"{",
"hash",
".",
"update",
"(",
"chunk",
")",
"cb",
"(",
"null",
",",
"chunk",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
"}",
"}",
")",
"}",
"// bind the digest function to hash object",
"hashThrough",
".",
"digest",
"=",
"format",
"=>",
"hash",
".",
"digest",
"(",
"format",
")",
"return",
"hashThrough",
"}"
] | Effectively a PassThrough stream that taps to chunks flow
and accumulating the hash | [
"Effectively",
"a",
"PassThrough",
"stream",
"that",
"taps",
"to",
"chunks",
"flow",
"and",
"accumulating",
"the",
"hash"
] | 47a8d55b581cbc6f22f1b2be4f8f88ceeb5612b3 | https://github.com/heroqu/hash-through/blob/47a8d55b581cbc6f22f1b2be4f8f88ceeb5612b3/index.js#L11-L31 |
56,866 | kuhnza/node-tubesio | lib/tubesio/logging.js | Logger | function Logger(level) {
if (_.isString(level) && _.has(LogLevel, level)) {
this.level = LogLevel[level];
} else if (_.isNumber(level) && level >= 0 && level <= 4) {
this.level = level;
} else {
this.level = LogLevel.info;
}
} | javascript | function Logger(level) {
if (_.isString(level) && _.has(LogLevel, level)) {
this.level = LogLevel[level];
} else if (_.isNumber(level) && level >= 0 && level <= 4) {
this.level = level;
} else {
this.level = LogLevel.info;
}
} | [
"function",
"Logger",
"(",
"level",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"level",
")",
"&&",
"_",
".",
"has",
"(",
"LogLevel",
",",
"level",
")",
")",
"{",
"this",
".",
"level",
"=",
"LogLevel",
"[",
"level",
"]",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isNumber",
"(",
"level",
")",
"&&",
"level",
">=",
"0",
"&&",
"level",
"<=",
"4",
")",
"{",
"this",
".",
"level",
"=",
"level",
";",
"}",
"else",
"{",
"this",
".",
"level",
"=",
"LogLevel",
".",
"info",
";",
"}",
"}"
] | Logger that logs exclusively to stderr so that logging doesn't pollute the
scraper result which is written to stdout. | [
"Logger",
"that",
"logs",
"exclusively",
"to",
"stderr",
"so",
"that",
"logging",
"doesn",
"t",
"pollute",
"the",
"scraper",
"result",
"which",
"is",
"written",
"to",
"stdout",
"."
] | 198d005de764480485fe038d1832ccb0f6e0596e | https://github.com/kuhnza/node-tubesio/blob/198d005de764480485fe038d1832ccb0f6e0596e/lib/tubesio/logging.js#L27-L35 |
56,867 | hl198181/neptune | misc/demo/public/vendor/angular/docs/js/docs.js | localSearchFactory | function localSearchFactory($http, $timeout, NG_PAGES) {
console.log('Using Local Search Index');
// Create the lunr index
var index = lunr(function() {
this.ref('path');
this.field('titleWords', {boost: 50});
this.field('members', { boost: 40});
this.field('keywords', { boost : 20 });
});
// Delay building the index by loading the data asynchronously
var indexReadyPromise = $http.get('js/search-data.json').then(function(response) {
var searchData = response.data;
// Delay building the index for 500ms to allow the page to render
return $timeout(function() {
// load the page data into the index
angular.forEach(searchData, function(page) {
index.add(page);
});
}, 500);
});
// The actual service is a function that takes a query string and
// returns a promise to the search results
// (In this case we just resolve the promise immediately as it is not
// inherently an async process)
return function(q) {
return indexReadyPromise.then(function() {
var hits = index.search(q);
var results = [];
angular.forEach(hits, function(hit) {
results.push(NG_PAGES[hit.ref]);
});
return results;
});
};
} | javascript | function localSearchFactory($http, $timeout, NG_PAGES) {
console.log('Using Local Search Index');
// Create the lunr index
var index = lunr(function() {
this.ref('path');
this.field('titleWords', {boost: 50});
this.field('members', { boost: 40});
this.field('keywords', { boost : 20 });
});
// Delay building the index by loading the data asynchronously
var indexReadyPromise = $http.get('js/search-data.json').then(function(response) {
var searchData = response.data;
// Delay building the index for 500ms to allow the page to render
return $timeout(function() {
// load the page data into the index
angular.forEach(searchData, function(page) {
index.add(page);
});
}, 500);
});
// The actual service is a function that takes a query string and
// returns a promise to the search results
// (In this case we just resolve the promise immediately as it is not
// inherently an async process)
return function(q) {
return indexReadyPromise.then(function() {
var hits = index.search(q);
var results = [];
angular.forEach(hits, function(hit) {
results.push(NG_PAGES[hit.ref]);
});
return results;
});
};
} | [
"function",
"localSearchFactory",
"(",
"$http",
",",
"$timeout",
",",
"NG_PAGES",
")",
"{",
"console",
".",
"log",
"(",
"'Using Local Search Index'",
")",
";",
"// Create the lunr index",
"var",
"index",
"=",
"lunr",
"(",
"function",
"(",
")",
"{",
"this",
".",
"ref",
"(",
"'path'",
")",
";",
"this",
".",
"field",
"(",
"'titleWords'",
",",
"{",
"boost",
":",
"50",
"}",
")",
";",
"this",
".",
"field",
"(",
"'members'",
",",
"{",
"boost",
":",
"40",
"}",
")",
";",
"this",
".",
"field",
"(",
"'keywords'",
",",
"{",
"boost",
":",
"20",
"}",
")",
";",
"}",
")",
";",
"// Delay building the index by loading the data asynchronously",
"var",
"indexReadyPromise",
"=",
"$http",
".",
"get",
"(",
"'js/search-data.json'",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"var",
"searchData",
"=",
"response",
".",
"data",
";",
"// Delay building the index for 500ms to allow the page to render",
"return",
"$timeout",
"(",
"function",
"(",
")",
"{",
"// load the page data into the index",
"angular",
".",
"forEach",
"(",
"searchData",
",",
"function",
"(",
"page",
")",
"{",
"index",
".",
"add",
"(",
"page",
")",
";",
"}",
")",
";",
"}",
",",
"500",
")",
";",
"}",
")",
";",
"// The actual service is a function that takes a query string and",
"// returns a promise to the search results",
"// (In this case we just resolve the promise immediately as it is not",
"// inherently an async process)",
"return",
"function",
"(",
"q",
")",
"{",
"return",
"indexReadyPromise",
".",
"then",
"(",
"function",
"(",
")",
"{",
"var",
"hits",
"=",
"index",
".",
"search",
"(",
"q",
")",
";",
"var",
"results",
"=",
"[",
"]",
";",
"angular",
".",
"forEach",
"(",
"hits",
",",
"function",
"(",
"hit",
")",
"{",
"results",
".",
"push",
"(",
"NG_PAGES",
"[",
"hit",
".",
"ref",
"]",
")",
";",
"}",
")",
";",
"return",
"results",
";",
"}",
")",
";",
"}",
";",
"}"
] | This version of the service builds the index in the current thread, which blocks rendering and other browser activities. It should only be used where the browser does not support WebWorkers | [
"This",
"version",
"of",
"the",
"service",
"builds",
"the",
"index",
"in",
"the",
"current",
"thread",
"which",
"blocks",
"rendering",
"and",
"other",
"browser",
"activities",
".",
"It",
"should",
"only",
"be",
"used",
"where",
"the",
"browser",
"does",
"not",
"support",
"WebWorkers"
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/angular/docs/js/docs.js#L354-L392 |
56,868 | hl198181/neptune | misc/demo/public/vendor/angular/docs/js/docs.js | webWorkerSearchFactory | function webWorkerSearchFactory($q, $rootScope, NG_PAGES) {
console.log('Using WebWorker Search Index')
var searchIndex = $q.defer();
var results;
var worker = new Worker('js/search-worker.js');
// The worker will send us a message in two situations:
// - when the index has been built, ready to run a query
// - when it has completed a search query and the results are available
worker.onmessage = function(oEvent) {
$rootScope.$apply(function() {
switch(oEvent.data.e) {
case 'index-ready':
searchIndex.resolve();
break;
case 'query-ready':
var pages = oEvent.data.d.map(function(path) {
return NG_PAGES[path];
});
results.resolve(pages);
break;
}
});
};
// The actual service is a function that takes a query string and
// returns a promise to the search results
return function(q) {
// We only run the query once the index is ready
return searchIndex.promise.then(function() {
results = $q.defer();
worker.postMessage({ q: q });
return results.promise;
});
};
} | javascript | function webWorkerSearchFactory($q, $rootScope, NG_PAGES) {
console.log('Using WebWorker Search Index')
var searchIndex = $q.defer();
var results;
var worker = new Worker('js/search-worker.js');
// The worker will send us a message in two situations:
// - when the index has been built, ready to run a query
// - when it has completed a search query and the results are available
worker.onmessage = function(oEvent) {
$rootScope.$apply(function() {
switch(oEvent.data.e) {
case 'index-ready':
searchIndex.resolve();
break;
case 'query-ready':
var pages = oEvent.data.d.map(function(path) {
return NG_PAGES[path];
});
results.resolve(pages);
break;
}
});
};
// The actual service is a function that takes a query string and
// returns a promise to the search results
return function(q) {
// We only run the query once the index is ready
return searchIndex.promise.then(function() {
results = $q.defer();
worker.postMessage({ q: q });
return results.promise;
});
};
} | [
"function",
"webWorkerSearchFactory",
"(",
"$q",
",",
"$rootScope",
",",
"NG_PAGES",
")",
"{",
"console",
".",
"log",
"(",
"'Using WebWorker Search Index'",
")",
"var",
"searchIndex",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"var",
"results",
";",
"var",
"worker",
"=",
"new",
"Worker",
"(",
"'js/search-worker.js'",
")",
";",
"// The worker will send us a message in two situations:",
"// - when the index has been built, ready to run a query",
"// - when it has completed a search query and the results are available",
"worker",
".",
"onmessage",
"=",
"function",
"(",
"oEvent",
")",
"{",
"$rootScope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"switch",
"(",
"oEvent",
".",
"data",
".",
"e",
")",
"{",
"case",
"'index-ready'",
":",
"searchIndex",
".",
"resolve",
"(",
")",
";",
"break",
";",
"case",
"'query-ready'",
":",
"var",
"pages",
"=",
"oEvent",
".",
"data",
".",
"d",
".",
"map",
"(",
"function",
"(",
"path",
")",
"{",
"return",
"NG_PAGES",
"[",
"path",
"]",
";",
"}",
")",
";",
"results",
".",
"resolve",
"(",
"pages",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"}",
";",
"// The actual service is a function that takes a query string and",
"// returns a promise to the search results",
"return",
"function",
"(",
"q",
")",
"{",
"// We only run the query once the index is ready",
"return",
"searchIndex",
".",
"promise",
".",
"then",
"(",
"function",
"(",
")",
"{",
"results",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"worker",
".",
"postMessage",
"(",
"{",
"q",
":",
"q",
"}",
")",
";",
"return",
"results",
".",
"promise",
";",
"}",
")",
";",
"}",
";",
"}"
] | This version of the service builds the index in a WebWorker, which does not block rendering and other browser activities. It should only be used where the browser does support WebWorkers | [
"This",
"version",
"of",
"the",
"service",
"builds",
"the",
"index",
"in",
"a",
"WebWorker",
"which",
"does",
"not",
"block",
"rendering",
"and",
"other",
"browser",
"activities",
".",
"It",
"should",
"only",
"be",
"used",
"where",
"the",
"browser",
"does",
"support",
"WebWorkers"
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/angular/docs/js/docs.js#L398-L439 |
56,869 | dominictarr/level-queue | index.js | queue | function queue (job, value, put) {
var ts = timestamp()
var key = toKey(job, ts)
var id = hash(job+':'+value)
if(pending[id]) return null //this job is already queued.
pending[id] = Date.now()
if(put === false) {
//return the job to be queued, to include it in a batch insert.
return {
type: 'put',
key: Buffer.isBuffer(key) ? key : new Buffer(key),
value: Buffer.isBuffer(key) ? value : new Buffer(value)
}
} else {
db.put(key, value)
}
} | javascript | function queue (job, value, put) {
var ts = timestamp()
var key = toKey(job, ts)
var id = hash(job+':'+value)
if(pending[id]) return null //this job is already queued.
pending[id] = Date.now()
if(put === false) {
//return the job to be queued, to include it in a batch insert.
return {
type: 'put',
key: Buffer.isBuffer(key) ? key : new Buffer(key),
value: Buffer.isBuffer(key) ? value : new Buffer(value)
}
} else {
db.put(key, value)
}
} | [
"function",
"queue",
"(",
"job",
",",
"value",
",",
"put",
")",
"{",
"var",
"ts",
"=",
"timestamp",
"(",
")",
"var",
"key",
"=",
"toKey",
"(",
"job",
",",
"ts",
")",
"var",
"id",
"=",
"hash",
"(",
"job",
"+",
"':'",
"+",
"value",
")",
"if",
"(",
"pending",
"[",
"id",
"]",
")",
"return",
"null",
"//this job is already queued.",
"pending",
"[",
"id",
"]",
"=",
"Date",
".",
"now",
"(",
")",
"if",
"(",
"put",
"===",
"false",
")",
"{",
"//return the job to be queued, to include it in a batch insert.",
"return",
"{",
"type",
":",
"'put'",
",",
"key",
":",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
"?",
"key",
":",
"new",
"Buffer",
"(",
"key",
")",
",",
"value",
":",
"Buffer",
".",
"isBuffer",
"(",
"key",
")",
"?",
"value",
":",
"new",
"Buffer",
"(",
"value",
")",
"}",
"}",
"else",
"{",
"db",
".",
"put",
"(",
"key",
",",
"value",
")",
"}",
"}"
] | put=false means return a job to be queued | [
"put",
"=",
"false",
"means",
"return",
"a",
"job",
"to",
"be",
"queued"
] | 2ac2ee1f088a86d14e58e4d5c140498e7ba30875 | https://github.com/dominictarr/level-queue/blob/2ac2ee1f088a86d14e58e4d5c140498e7ba30875/index.js#L117-L135 |
56,870 | pinyin/outline | vendor/transformation-matrix/skew.js | skew | function skew(ax, ay) {
return {
a: 1, c: tan(ax), e: 0,
b: tan(ay), d: 1, f: 0
};
} | javascript | function skew(ax, ay) {
return {
a: 1, c: tan(ax), e: 0,
b: tan(ay), d: 1, f: 0
};
} | [
"function",
"skew",
"(",
"ax",
",",
"ay",
")",
"{",
"return",
"{",
"a",
":",
"1",
",",
"c",
":",
"tan",
"(",
"ax",
")",
",",
"e",
":",
"0",
",",
"b",
":",
"tan",
"(",
"ay",
")",
",",
"d",
":",
"1",
",",
"f",
":",
"0",
"}",
";",
"}"
] | Calculate a skew matrix
@param ax Skew on axis x
@param ay Skew on axis y
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"skew",
"matrix"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/skew.js#L18-L23 |
56,871 | pinyin/outline | vendor/transformation-matrix/skew.js | skewDEG | function skewDEG(ax, ay) {
return skew(ax * Math.PI / 180, ay * Math.PI / 180);
} | javascript | function skewDEG(ax, ay) {
return skew(ax * Math.PI / 180, ay * Math.PI / 180);
} | [
"function",
"skewDEG",
"(",
"ax",
",",
"ay",
")",
"{",
"return",
"skew",
"(",
"ax",
"*",
"Math",
".",
"PI",
"/",
"180",
",",
"ay",
"*",
"Math",
".",
"PI",
"/",
"180",
")",
";",
"}"
] | Calculate a skew matrix using DEG angles
@param ax Skew on axis x
@param ay Skew on axis y
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"skew",
"matrix",
"using",
"DEG",
"angles"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/skew.js#L31-L33 |
56,872 | Industryswarm/isnode-mod-data | lib/mongodb/bson/lib/bson/objectid.js | ObjectID | function ObjectID(id) {
// Duck-typing to support ObjectId from different npm packages
if (id instanceof ObjectID) return id;
if (!(this instanceof ObjectID)) return new ObjectID(id);
this._bsontype = 'ObjectID';
// The most common usecase (blank id, new objectId instance)
if (id == null || typeof id === 'number') {
// Generate a new id
this.id = this.generate(id);
// If we are caching the hex string
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
// Return the object
return;
}
// Check if the passed in id is valid
var valid = ObjectID.isValid(id);
// Throw an error if it's not a valid setup
if (!valid && id != null) {
throw new Error(
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
);
} else if (valid && typeof id === 'string' && id.length === 24 && hasBufferType) {
return new ObjectID(new Buffer(id, 'hex'));
} else if (valid && typeof id === 'string' && id.length === 24) {
return ObjectID.createFromHexString(id);
} else if (id != null && id.length === 12) {
// assume 12 byte string
this.id = id;
} else if (id != null && id.toHexString) {
// Duck-typing to support ObjectId from different npm packages
return id;
} else {
throw new Error(
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
);
}
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
} | javascript | function ObjectID(id) {
// Duck-typing to support ObjectId from different npm packages
if (id instanceof ObjectID) return id;
if (!(this instanceof ObjectID)) return new ObjectID(id);
this._bsontype = 'ObjectID';
// The most common usecase (blank id, new objectId instance)
if (id == null || typeof id === 'number') {
// Generate a new id
this.id = this.generate(id);
// If we are caching the hex string
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
// Return the object
return;
}
// Check if the passed in id is valid
var valid = ObjectID.isValid(id);
// Throw an error if it's not a valid setup
if (!valid && id != null) {
throw new Error(
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
);
} else if (valid && typeof id === 'string' && id.length === 24 && hasBufferType) {
return new ObjectID(new Buffer(id, 'hex'));
} else if (valid && typeof id === 'string' && id.length === 24) {
return ObjectID.createFromHexString(id);
} else if (id != null && id.length === 12) {
// assume 12 byte string
this.id = id;
} else if (id != null && id.toHexString) {
// Duck-typing to support ObjectId from different npm packages
return id;
} else {
throw new Error(
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
);
}
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
} | [
"function",
"ObjectID",
"(",
"id",
")",
"{",
"// Duck-typing to support ObjectId from different npm packages",
"if",
"(",
"id",
"instanceof",
"ObjectID",
")",
"return",
"id",
";",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ObjectID",
")",
")",
"return",
"new",
"ObjectID",
"(",
"id",
")",
";",
"this",
".",
"_bsontype",
"=",
"'ObjectID'",
";",
"// The most common usecase (blank id, new objectId instance)",
"if",
"(",
"id",
"==",
"null",
"||",
"typeof",
"id",
"===",
"'number'",
")",
"{",
"// Generate a new id",
"this",
".",
"id",
"=",
"this",
".",
"generate",
"(",
"id",
")",
";",
"// If we are caching the hex string",
"if",
"(",
"ObjectID",
".",
"cacheHexString",
")",
"this",
".",
"__id",
"=",
"this",
".",
"toString",
"(",
"'hex'",
")",
";",
"// Return the object",
"return",
";",
"}",
"// Check if the passed in id is valid",
"var",
"valid",
"=",
"ObjectID",
".",
"isValid",
"(",
"id",
")",
";",
"// Throw an error if it's not a valid setup",
"if",
"(",
"!",
"valid",
"&&",
"id",
"!=",
"null",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'",
")",
";",
"}",
"else",
"if",
"(",
"valid",
"&&",
"typeof",
"id",
"===",
"'string'",
"&&",
"id",
".",
"length",
"===",
"24",
"&&",
"hasBufferType",
")",
"{",
"return",
"new",
"ObjectID",
"(",
"new",
"Buffer",
"(",
"id",
",",
"'hex'",
")",
")",
";",
"}",
"else",
"if",
"(",
"valid",
"&&",
"typeof",
"id",
"===",
"'string'",
"&&",
"id",
".",
"length",
"===",
"24",
")",
"{",
"return",
"ObjectID",
".",
"createFromHexString",
"(",
"id",
")",
";",
"}",
"else",
"if",
"(",
"id",
"!=",
"null",
"&&",
"id",
".",
"length",
"===",
"12",
")",
"{",
"// assume 12 byte string",
"this",
".",
"id",
"=",
"id",
";",
"}",
"else",
"if",
"(",
"id",
"!=",
"null",
"&&",
"id",
".",
"toHexString",
")",
"{",
"// Duck-typing to support ObjectId from different npm packages",
"return",
"id",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'",
")",
";",
"}",
"if",
"(",
"ObjectID",
".",
"cacheHexString",
")",
"this",
".",
"__id",
"=",
"this",
".",
"toString",
"(",
"'hex'",
")",
";",
"}"
] | Create a new ObjectID instance
@class
@param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number.
@property {number} generationTime The generation time of this ObjectId instance
@return {ObjectID} instance of ObjectID. | [
"Create",
"a",
"new",
"ObjectID",
"instance"
] | 5adc639b88a0d72cbeef23a6b5df7f4540745089 | https://github.com/Industryswarm/isnode-mod-data/blob/5adc639b88a0d72cbeef23a6b5df7f4540745089/lib/mongodb/bson/lib/bson/objectid.js#L35-L77 |
56,873 | nathanfrancy/safetext | lib/index.js | init | function init(masterPassword, map) {
var fileContents = JSON.stringify(map);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | javascript | function init(masterPassword, map) {
var fileContents = JSON.stringify(map);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | [
"function",
"init",
"(",
"masterPassword",
",",
"map",
")",
"{",
"var",
"fileContents",
"=",
"JSON",
".",
"stringify",
"(",
"map",
")",
";",
"var",
"encryptedFileContents",
"=",
"encryption",
".",
"encrypt",
"(",
"fileContents",
",",
"masterPassword",
")",
";",
"file",
".",
"writeToFile",
"(",
"encryptedFileContents",
")",
";",
"}"
] | Make a new safetext file with encrypted contents.
@param masterPassword
@param map
@returns {Promise.<TResult>} | [
"Make",
"a",
"new",
"safetext",
"file",
"with",
"encrypted",
"contents",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L10-L14 |
56,874 | nathanfrancy/safetext | lib/index.js | getContents | function getContents(masterPassword) {
var encryptedContents = file.readFile();
try {
var contents = encryption.decrypt(encryptedContents, masterPassword);
return JSON.parse(contents);
} catch(err) {
console.log(err);
throw new Error("Error reading file contents. This most likely means the provided password is wrong.");
}
} | javascript | function getContents(masterPassword) {
var encryptedContents = file.readFile();
try {
var contents = encryption.decrypt(encryptedContents, masterPassword);
return JSON.parse(contents);
} catch(err) {
console.log(err);
throw new Error("Error reading file contents. This most likely means the provided password is wrong.");
}
} | [
"function",
"getContents",
"(",
"masterPassword",
")",
"{",
"var",
"encryptedContents",
"=",
"file",
".",
"readFile",
"(",
")",
";",
"try",
"{",
"var",
"contents",
"=",
"encryption",
".",
"decrypt",
"(",
"encryptedContents",
",",
"masterPassword",
")",
";",
"return",
"JSON",
".",
"parse",
"(",
"contents",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Error reading file contents. This most likely means the provided password is wrong.\"",
")",
";",
"}",
"}"
] | Read object out of safetext, must include master password.
@param masterPassword
@returns {Promise.<TResult>} | [
"Read",
"object",
"out",
"of",
"safetext",
"must",
"include",
"master",
"password",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L21-L30 |
56,875 | nathanfrancy/safetext | lib/index.js | getKey | function getKey(key, masterPassword) {
var contents = getContents(masterPassword);
if (contents[key] != undefined) return contents[key];
else throw new Error(`Unable to find key '${key}' in password safe.`);
} | javascript | function getKey(key, masterPassword) {
var contents = getContents(masterPassword);
if (contents[key] != undefined) return contents[key];
else throw new Error(`Unable to find key '${key}' in password safe.`);
} | [
"function",
"getKey",
"(",
"key",
",",
"masterPassword",
")",
"{",
"var",
"contents",
"=",
"getContents",
"(",
"masterPassword",
")",
";",
"if",
"(",
"contents",
"[",
"key",
"]",
"!=",
"undefined",
")",
"return",
"contents",
"[",
"key",
"]",
";",
"else",
"throw",
"new",
"Error",
"(",
"`",
"${",
"key",
"}",
"`",
")",
";",
"}"
] | Get a specific key value from safetext file.
@param key
@param masterPassword
@returns {Promise.<TResult>} | [
"Get",
"a",
"specific",
"key",
"value",
"from",
"safetext",
"file",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L54-L58 |
56,876 | nathanfrancy/safetext | lib/index.js | writeKey | function writeKey(key, value, masterPassword) {
var contents = getContents(masterPassword);
contents[key] = value;
var fileContents = JSON.stringify(contents);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | javascript | function writeKey(key, value, masterPassword) {
var contents = getContents(masterPassword);
contents[key] = value;
var fileContents = JSON.stringify(contents);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | [
"function",
"writeKey",
"(",
"key",
",",
"value",
",",
"masterPassword",
")",
"{",
"var",
"contents",
"=",
"getContents",
"(",
"masterPassword",
")",
";",
"contents",
"[",
"key",
"]",
"=",
"value",
";",
"var",
"fileContents",
"=",
"JSON",
".",
"stringify",
"(",
"contents",
")",
";",
"var",
"encryptedFileContents",
"=",
"encryption",
".",
"encrypt",
"(",
"fileContents",
",",
"masterPassword",
")",
";",
"file",
".",
"writeToFile",
"(",
"encryptedFileContents",
")",
";",
"}"
] | Writes a key to the safetext file.
@param key
@param value
@param masterPassword
@returns {Promise.<TResult>} | [
"Writes",
"a",
"key",
"to",
"the",
"safetext",
"file",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L67-L73 |
56,877 | nathanfrancy/safetext | lib/index.js | removeKey | function removeKey(key, masterPassword) {
var contents = getContents(masterPassword);
if (contents[key] != undefined) delete contents[key];
var fileContents = JSON.stringify(contents);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | javascript | function removeKey(key, masterPassword) {
var contents = getContents(masterPassword);
if (contents[key] != undefined) delete contents[key];
var fileContents = JSON.stringify(contents);
var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
file.writeToFile(encryptedFileContents);
} | [
"function",
"removeKey",
"(",
"key",
",",
"masterPassword",
")",
"{",
"var",
"contents",
"=",
"getContents",
"(",
"masterPassword",
")",
";",
"if",
"(",
"contents",
"[",
"key",
"]",
"!=",
"undefined",
")",
"delete",
"contents",
"[",
"key",
"]",
";",
"var",
"fileContents",
"=",
"JSON",
".",
"stringify",
"(",
"contents",
")",
";",
"var",
"encryptedFileContents",
"=",
"encryption",
".",
"encrypt",
"(",
"fileContents",
",",
"masterPassword",
")",
";",
"file",
".",
"writeToFile",
"(",
"encryptedFileContents",
")",
";",
"}"
] | Removes a key from the safetext password file.
@param key
@param masterPassword
@returns {Promise.<TResult>} | [
"Removes",
"a",
"key",
"from",
"the",
"safetext",
"password",
"file",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L81-L88 |
56,878 | nathanfrancy/safetext | lib/index.js | changePassword | function changePassword(masterPassword, newPassword1, newPassword2) {
if (newPassword1 !== newPassword2) throw new Error("New passwords must match.");
else {
var contents = getContents(masterPassword);
init(newPassword1, contents);
}
} | javascript | function changePassword(masterPassword, newPassword1, newPassword2) {
if (newPassword1 !== newPassword2) throw new Error("New passwords must match.");
else {
var contents = getContents(masterPassword);
init(newPassword1, contents);
}
} | [
"function",
"changePassword",
"(",
"masterPassword",
",",
"newPassword1",
",",
"newPassword2",
")",
"{",
"if",
"(",
"newPassword1",
"!==",
"newPassword2",
")",
"throw",
"new",
"Error",
"(",
"\"New passwords must match.\"",
")",
";",
"else",
"{",
"var",
"contents",
"=",
"getContents",
"(",
"masterPassword",
")",
";",
"init",
"(",
"newPassword1",
",",
"contents",
")",
";",
"}",
"}"
] | Changes the password of the safetext file.
@param masterPassword
@param newPassword1
@param newPassword2 | [
"Changes",
"the",
"password",
"of",
"the",
"safetext",
"file",
"."
] | 960733dacae4edd522f35178a99fc80e4ac8d096 | https://github.com/nathanfrancy/safetext/blob/960733dacae4edd522f35178a99fc80e4ac8d096/lib/index.js#L96-L102 |
56,879 | ibc/eventcollector | lib/eventcollector.js | function(total, timeout) {
events.EventEmitter.call(this);
if (! isPositiveInteger(total)) {
throw new Error('`total` must be a positive integer');
}
if (timeout && ! isPositiveInteger(timeout)) {
throw new Error('`timeout` must be a positive integer');
}
this.destroyed = false;
this.total = total;
this.fired = 0;
if (timeout) {
this.timer = setTimeout(function() {
this.onTimeout();
}.bind(this), timeout);
}
} | javascript | function(total, timeout) {
events.EventEmitter.call(this);
if (! isPositiveInteger(total)) {
throw new Error('`total` must be a positive integer');
}
if (timeout && ! isPositiveInteger(timeout)) {
throw new Error('`timeout` must be a positive integer');
}
this.destroyed = false;
this.total = total;
this.fired = 0;
if (timeout) {
this.timer = setTimeout(function() {
this.onTimeout();
}.bind(this), timeout);
}
} | [
"function",
"(",
"total",
",",
"timeout",
")",
"{",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"!",
"isPositiveInteger",
"(",
"total",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'`total` must be a positive integer'",
")",
";",
"}",
"if",
"(",
"timeout",
"&&",
"!",
"isPositiveInteger",
"(",
"timeout",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'`timeout` must be a positive integer'",
")",
";",
"}",
"this",
".",
"destroyed",
"=",
"false",
";",
"this",
".",
"total",
"=",
"total",
";",
"this",
".",
"fired",
"=",
"0",
";",
"if",
"(",
"timeout",
")",
"{",
"this",
".",
"timer",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"this",
".",
"onTimeout",
"(",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"timeout",
")",
";",
"}",
"}"
] | EventCollector class.
@class EventCollector
@constructor
@param {Number} total Number of events that must fire. | [
"EventCollector",
"class",
"."
] | 685c533d50076a6d9d5b67bbeb5f9f081f53aa9a | https://github.com/ibc/eventcollector/blob/685c533d50076a6d9d5b67bbeb5f9f081f53aa9a/lib/eventcollector.js#L56-L75 |
|
56,880 | switer/block-ast | index.js | _join | function _join(arr1, arr2) {
var len = arr1.length > arr2 ? arr1.length : arr2.length
var joinedArr = []
while(len --) {
joinedArr.push(arr1.shift())
joinedArr.push(arr2.shift())
}
// merge remains
return joinedArr.concat(arr1).concat(arr2)
} | javascript | function _join(arr1, arr2) {
var len = arr1.length > arr2 ? arr1.length : arr2.length
var joinedArr = []
while(len --) {
joinedArr.push(arr1.shift())
joinedArr.push(arr2.shift())
}
// merge remains
return joinedArr.concat(arr1).concat(arr2)
} | [
"function",
"_join",
"(",
"arr1",
",",
"arr2",
")",
"{",
"var",
"len",
"=",
"arr1",
".",
"length",
">",
"arr2",
"?",
"arr1",
".",
"length",
":",
"arr2",
".",
"length",
"var",
"joinedArr",
"=",
"[",
"]",
"while",
"(",
"len",
"--",
")",
"{",
"joinedArr",
".",
"push",
"(",
"arr1",
".",
"shift",
"(",
")",
")",
"joinedArr",
".",
"push",
"(",
"arr2",
".",
"shift",
"(",
")",
")",
"}",
"// merge remains",
"return",
"joinedArr",
".",
"concat",
"(",
"arr1",
")",
".",
"concat",
"(",
"arr2",
")",
"}"
] | join arr2's items to arr
@param {Array} arr1 odd number index items
@param {Array} arr2 even number index items
@return {Array} new array with join result | [
"join",
"arr2",
"s",
"items",
"to",
"arr"
] | cebc9b7671df8088f12538b9d748bbcbd4630f3e | https://github.com/switer/block-ast/blob/cebc9b7671df8088f12538b9d748bbcbd4630f3e/index.js#L14-L23 |
56,881 | jansedivy/potion | examples/demo-pixi-bunny/pixi.dev.js | callCompat | function callCompat(obj) {
if(obj) {
obj = obj.prototype || obj;
PIXI.EventTarget.mixin(obj);
}
} | javascript | function callCompat(obj) {
if(obj) {
obj = obj.prototype || obj;
PIXI.EventTarget.mixin(obj);
}
} | [
"function",
"callCompat",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
")",
"{",
"obj",
"=",
"obj",
".",
"prototype",
"||",
"obj",
";",
"PIXI",
".",
"EventTarget",
".",
"mixin",
"(",
"obj",
")",
";",
"}",
"}"
] | Backward compat from when this used to be a function | [
"Backward",
"compat",
"from",
"when",
"this",
"used",
"to",
"be",
"a",
"function"
] | 2e740ee68898d8ec8a34f8a3b6ee8e8faffce253 | https://github.com/jansedivy/potion/blob/2e740ee68898d8ec8a34f8a3b6ee8e8faffce253/examples/demo-pixi-bunny/pixi.dev.js#L5459-L5464 |
56,882 | jansedivy/potion | examples/demo-pixi-bunny/pixi.dev.js | function () {
var ikConstraints = this.ikConstraints;
var ikConstraintsCount = ikConstraints.length;
var arrayCount = ikConstraintsCount + 1;
var boneCache = this.boneCache;
if (boneCache.length > arrayCount) boneCache.length = arrayCount;
for (var i = 0, n = boneCache.length; i < n; i++)
boneCache[i].length = 0;
while (boneCache.length < arrayCount)
boneCache[boneCache.length] = [];
var nonIkBones = boneCache[0];
var bones = this.bones;
outer:
for (var i = 0, n = bones.length; i < n; i++) {
var bone = bones[i];
var current = bone;
do {
for (var ii = 0; ii < ikConstraintsCount; ii++) {
var ikConstraint = ikConstraints[ii];
var parent = ikConstraint.bones[0];
var child= ikConstraint.bones[ikConstraint.bones.length - 1];
while (true) {
if (current == child) {
boneCache[ii].push(bone);
boneCache[ii + 1].push(bone);
continue outer;
}
if (child == parent) break;
child = child.parent;
}
}
current = current.parent;
} while (current);
nonIkBones[nonIkBones.length] = bone;
}
} | javascript | function () {
var ikConstraints = this.ikConstraints;
var ikConstraintsCount = ikConstraints.length;
var arrayCount = ikConstraintsCount + 1;
var boneCache = this.boneCache;
if (boneCache.length > arrayCount) boneCache.length = arrayCount;
for (var i = 0, n = boneCache.length; i < n; i++)
boneCache[i].length = 0;
while (boneCache.length < arrayCount)
boneCache[boneCache.length] = [];
var nonIkBones = boneCache[0];
var bones = this.bones;
outer:
for (var i = 0, n = bones.length; i < n; i++) {
var bone = bones[i];
var current = bone;
do {
for (var ii = 0; ii < ikConstraintsCount; ii++) {
var ikConstraint = ikConstraints[ii];
var parent = ikConstraint.bones[0];
var child= ikConstraint.bones[ikConstraint.bones.length - 1];
while (true) {
if (current == child) {
boneCache[ii].push(bone);
boneCache[ii + 1].push(bone);
continue outer;
}
if (child == parent) break;
child = child.parent;
}
}
current = current.parent;
} while (current);
nonIkBones[nonIkBones.length] = bone;
}
} | [
"function",
"(",
")",
"{",
"var",
"ikConstraints",
"=",
"this",
".",
"ikConstraints",
";",
"var",
"ikConstraintsCount",
"=",
"ikConstraints",
".",
"length",
";",
"var",
"arrayCount",
"=",
"ikConstraintsCount",
"+",
"1",
";",
"var",
"boneCache",
"=",
"this",
".",
"boneCache",
";",
"if",
"(",
"boneCache",
".",
"length",
">",
"arrayCount",
")",
"boneCache",
".",
"length",
"=",
"arrayCount",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"boneCache",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"boneCache",
"[",
"i",
"]",
".",
"length",
"=",
"0",
";",
"while",
"(",
"boneCache",
".",
"length",
"<",
"arrayCount",
")",
"boneCache",
"[",
"boneCache",
".",
"length",
"]",
"=",
"[",
"]",
";",
"var",
"nonIkBones",
"=",
"boneCache",
"[",
"0",
"]",
";",
"var",
"bones",
"=",
"this",
".",
"bones",
";",
"outer",
":",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"bones",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"var",
"bone",
"=",
"bones",
"[",
"i",
"]",
";",
"var",
"current",
"=",
"bone",
";",
"do",
"{",
"for",
"(",
"var",
"ii",
"=",
"0",
";",
"ii",
"<",
"ikConstraintsCount",
";",
"ii",
"++",
")",
"{",
"var",
"ikConstraint",
"=",
"ikConstraints",
"[",
"ii",
"]",
";",
"var",
"parent",
"=",
"ikConstraint",
".",
"bones",
"[",
"0",
"]",
";",
"var",
"child",
"=",
"ikConstraint",
".",
"bones",
"[",
"ikConstraint",
".",
"bones",
".",
"length",
"-",
"1",
"]",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"current",
"==",
"child",
")",
"{",
"boneCache",
"[",
"ii",
"]",
".",
"push",
"(",
"bone",
")",
";",
"boneCache",
"[",
"ii",
"+",
"1",
"]",
".",
"push",
"(",
"bone",
")",
";",
"continue",
"outer",
";",
"}",
"if",
"(",
"child",
"==",
"parent",
")",
"break",
";",
"child",
"=",
"child",
".",
"parent",
";",
"}",
"}",
"current",
"=",
"current",
".",
"parent",
";",
"}",
"while",
"(",
"current",
")",
";",
"nonIkBones",
"[",
"nonIkBones",
".",
"length",
"]",
"=",
"bone",
";",
"}",
"}"
] | Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or removed. | [
"Caches",
"information",
"about",
"bones",
"and",
"IK",
"constraints",
".",
"Must",
"be",
"called",
"if",
"bones",
"or",
"IK",
"constraints",
"are",
"added",
"or",
"removed",
"."
] | 2e740ee68898d8ec8a34f8a3b6ee8e8faffce253 | https://github.com/jansedivy/potion/blob/2e740ee68898d8ec8a34f8a3b6ee8e8faffce253/examples/demo-pixi-bunny/pixi.dev.js#L15018-L15056 |
|
56,883 | darrencruse/sugarlisp-async | gentab.js | asyncifyFunctions | function asyncifyFunctions(forms) {
// for each subexpression form...
forms.forEach(function(form) {
if (sl.isList(form)) {
if(sl.typeOf(form[0]) === 'symbol' &&
sl.valueOf(form[0]) === 'function' &&
asyncNeeded(form)) {
form.unshift(sl.atom("async"));
asyncifyFunctions(form);
}
else {
asyncifyFunctions(form);
}
}
});
} | javascript | function asyncifyFunctions(forms) {
// for each subexpression form...
forms.forEach(function(form) {
if (sl.isList(form)) {
if(sl.typeOf(form[0]) === 'symbol' &&
sl.valueOf(form[0]) === 'function' &&
asyncNeeded(form)) {
form.unshift(sl.atom("async"));
asyncifyFunctions(form);
}
else {
asyncifyFunctions(form);
}
}
});
} | [
"function",
"asyncifyFunctions",
"(",
"forms",
")",
"{",
"// for each subexpression form...",
"forms",
".",
"forEach",
"(",
"function",
"(",
"form",
")",
"{",
"if",
"(",
"sl",
".",
"isList",
"(",
"form",
")",
")",
"{",
"if",
"(",
"sl",
".",
"typeOf",
"(",
"form",
"[",
"0",
"]",
")",
"===",
"'symbol'",
"&&",
"sl",
".",
"valueOf",
"(",
"form",
"[",
"0",
"]",
")",
"===",
"'function'",
"&&",
"asyncNeeded",
"(",
"form",
")",
")",
"{",
"form",
".",
"unshift",
"(",
"sl",
".",
"atom",
"(",
"\"async\"",
")",
")",
";",
"asyncifyFunctions",
"(",
"form",
")",
";",
"}",
"else",
"{",
"asyncifyFunctions",
"(",
"form",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Had to timebox this - double check it later - I've yet to handle functions nested down under other functions - in that case isn't co.wrap needed to be added both at the lowest level and at the higher levels? Right now I stop at the higher levels. | [
"Had",
"to",
"timebox",
"this",
"-",
"double",
"check",
"it",
"later",
"-",
"I",
"ve",
"yet",
"to",
"handle",
"functions",
"nested",
"down",
"under",
"other",
"functions",
"-",
"in",
"that",
"case",
"isn",
"t",
"co",
".",
"wrap",
"needed",
"to",
"be",
"added",
"both",
"at",
"the",
"lowest",
"level",
"and",
"at",
"the",
"higher",
"levels?",
"Right",
"now",
"I",
"stop",
"at",
"the",
"higher",
"levels",
"."
] | f7c909da54396165ddc42b73749f98a19e01c595 | https://github.com/darrencruse/sugarlisp-async/blob/f7c909da54396165ddc42b73749f98a19e01c595/gentab.js#L73-L88 |
56,884 | psiolent/trigger-maker | index.js | on | function on(event, fn) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
if (!(fn instanceof Function)) {
throw new Error('"fn" not a Function');
}
if (hasListener(event, fn)) {
return false;
}
if (!hasListeners(event)) {
listeners[event] = [];
}
listeners[event].push(fn);
return true;
} | javascript | function on(event, fn) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
if (!(fn instanceof Function)) {
throw new Error('"fn" not a Function');
}
if (hasListener(event, fn)) {
return false;
}
if (!hasListeners(event)) {
listeners[event] = [];
}
listeners[event].push(fn);
return true;
} | [
"function",
"on",
"(",
"event",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"event",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"event\" not a string'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"fn",
"instanceof",
"Function",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"fn\" not a Function'",
")",
";",
"}",
"if",
"(",
"hasListener",
"(",
"event",
",",
"fn",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"hasListeners",
"(",
"event",
")",
")",
"{",
"listeners",
"[",
"event",
"]",
"=",
"[",
"]",
";",
"}",
"listeners",
"[",
"event",
"]",
".",
"push",
"(",
"fn",
")",
";",
"return",
"true",
";",
"}"
] | Registers a listener for a type of event.
@param {string} event the event type
@param {Function} fn the function to invoke to handle the event
@return {boolean} true if listener set was modified, false if not | [
"Registers",
"a",
"listener",
"for",
"a",
"type",
"of",
"event",
"."
] | 10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7 | https://github.com/psiolent/trigger-maker/blob/10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7/index.js#L26-L44 |
56,885 | psiolent/trigger-maker | index.js | off | function off(event, fn) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
if (fn !== undefined && !(fn instanceof Function)) {
throw new Error('"fn" not a Function');
}
if (fn) {
// do we event have this listener
if (!hasListener(event, fn)) {
return false;
}
// unregistering a specific listener for the event
listeners[event] = listeners[event].filter(function(l) {
return l !== fn;
});
if (listeners[event].length === 0) {
delete listeners[event];
}
} else {
// do we have any listeners for this event?
if (!hasListeners(event)) {
return false;
}
// unregistering all listeners for the event
delete listeners[event];
}
return true;
} | javascript | function off(event, fn) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
if (fn !== undefined && !(fn instanceof Function)) {
throw new Error('"fn" not a Function');
}
if (fn) {
// do we event have this listener
if (!hasListener(event, fn)) {
return false;
}
// unregistering a specific listener for the event
listeners[event] = listeners[event].filter(function(l) {
return l !== fn;
});
if (listeners[event].length === 0) {
delete listeners[event];
}
} else {
// do we have any listeners for this event?
if (!hasListeners(event)) {
return false;
}
// unregistering all listeners for the event
delete listeners[event];
}
return true;
} | [
"function",
"off",
"(",
"event",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"event",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"event\" not a string'",
")",
";",
"}",
"if",
"(",
"fn",
"!==",
"undefined",
"&&",
"!",
"(",
"fn",
"instanceof",
"Function",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"fn\" not a Function'",
")",
";",
"}",
"if",
"(",
"fn",
")",
"{",
"// do we event have this listener",
"if",
"(",
"!",
"hasListener",
"(",
"event",
",",
"fn",
")",
")",
"{",
"return",
"false",
";",
"}",
"// unregistering a specific listener for the event",
"listeners",
"[",
"event",
"]",
"=",
"listeners",
"[",
"event",
"]",
".",
"filter",
"(",
"function",
"(",
"l",
")",
"{",
"return",
"l",
"!==",
"fn",
";",
"}",
")",
";",
"if",
"(",
"listeners",
"[",
"event",
"]",
".",
"length",
"===",
"0",
")",
"{",
"delete",
"listeners",
"[",
"event",
"]",
";",
"}",
"}",
"else",
"{",
"// do we have any listeners for this event?",
"if",
"(",
"!",
"hasListeners",
"(",
"event",
")",
")",
"{",
"return",
"false",
";",
"}",
"// unregistering all listeners for the event",
"delete",
"listeners",
"[",
"event",
"]",
";",
"}",
"return",
"true",
";",
"}"
] | Unregisters one or all listeners for an event.
@param event the event to unregister for
@param [fn] if provided, the listener function to unregister; if not
provided, all listeners will be unregistered
@return {boolean} true if listener set was modified, false if not | [
"Unregisters",
"one",
"or",
"all",
"listeners",
"for",
"an",
"event",
"."
] | 10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7 | https://github.com/psiolent/trigger-maker/blob/10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7/index.js#L53-L85 |
56,886 | psiolent/trigger-maker | index.js | fire | function fire(event) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
// any listeners registered?
if (!hasListeners(event)) {
return triggerObject;
}
// get optional arguments
var args = Array.prototype.slice.call(arguments, 1);
// invoke listener functions
listeners[event].slice(0).forEach(function(fn) {
fn.apply(global, args);
});
return triggerObject;
} | javascript | function fire(event) {
if (typeof event !== 'string') {
throw new Error('"event" not a string');
}
// any listeners registered?
if (!hasListeners(event)) {
return triggerObject;
}
// get optional arguments
var args = Array.prototype.slice.call(arguments, 1);
// invoke listener functions
listeners[event].slice(0).forEach(function(fn) {
fn.apply(global, args);
});
return triggerObject;
} | [
"function",
"fire",
"(",
"event",
")",
"{",
"if",
"(",
"typeof",
"event",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"event\" not a string'",
")",
";",
"}",
"// any listeners registered?",
"if",
"(",
"!",
"hasListeners",
"(",
"event",
")",
")",
"{",
"return",
"triggerObject",
";",
"}",
"// get optional arguments",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"// invoke listener functions",
"listeners",
"[",
"event",
"]",
".",
"slice",
"(",
"0",
")",
".",
"forEach",
"(",
"function",
"(",
"fn",
")",
"{",
"fn",
".",
"apply",
"(",
"global",
",",
"args",
")",
";",
"}",
")",
";",
"return",
"triggerObject",
";",
"}"
] | Fires an event.
@param {string} event the event to fire
@param {...*} arguments to pass to the event listeners
@returns {Object} this trigger object | [
"Fires",
"an",
"event",
"."
] | 10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7 | https://github.com/psiolent/trigger-maker/blob/10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7/index.js#L93-L112 |
56,887 | psiolent/trigger-maker | index.js | fireAsync | function fireAsync(event) {
var args = Array.prototype.slice.call(arguments);
setTimeout(function() {
fire.apply(triggerObject, args);
}, 0);
return triggerObject;
} | javascript | function fireAsync(event) {
var args = Array.prototype.slice.call(arguments);
setTimeout(function() {
fire.apply(triggerObject, args);
}, 0);
return triggerObject;
} | [
"function",
"fireAsync",
"(",
"event",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"fire",
".",
"apply",
"(",
"triggerObject",
",",
"args",
")",
";",
"}",
",",
"0",
")",
";",
"return",
"triggerObject",
";",
"}"
] | Fires an event asynchronously. Event listeners are invoked
on the next tick rather than immediately.
@param {string} event the event to fire
@param {...*} arguments to pass to the event listeners
@returns {Object} this trigger object | [
"Fires",
"an",
"event",
"asynchronously",
".",
"Event",
"listeners",
"are",
"invoked",
"on",
"the",
"next",
"tick",
"rather",
"than",
"immediately",
"."
] | 10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7 | https://github.com/psiolent/trigger-maker/blob/10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7/index.js#L121-L127 |
56,888 | psiolent/trigger-maker | index.js | hasListener | function hasListener(event, fn) {
return listeners[event] ?
listeners[event].some(function(l) {
return l === fn;
}) :
false;
} | javascript | function hasListener(event, fn) {
return listeners[event] ?
listeners[event].some(function(l) {
return l === fn;
}) :
false;
} | [
"function",
"hasListener",
"(",
"event",
",",
"fn",
")",
"{",
"return",
"listeners",
"[",
"event",
"]",
"?",
"listeners",
"[",
"event",
"]",
".",
"some",
"(",
"function",
"(",
"l",
")",
"{",
"return",
"l",
"===",
"fn",
";",
"}",
")",
":",
"false",
";",
"}"
] | Returns whether the specified event has the specified listener.
@param event the event to check for the listener
@param fn the listener to check for
@returns {boolean} whether the specified event has the specified listener | [
"Returns",
"whether",
"the",
"specified",
"event",
"has",
"the",
"specified",
"listener",
"."
] | 10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7 | https://github.com/psiolent/trigger-maker/blob/10d6a3e0f204f6d5bc8c4565ee29236158a4c4b7/index.js#L153-L159 |
56,889 | nickschot/lux-jwt | lib/index.js | validCorsPreflight | function validCorsPreflight(request) {
if (request.method === 'OPTIONS' && request.headers.has('access-control-request-headers')) {
return request.headers.get('access-control-request-headers').split(',').map(function (header) {
return header.trim();
}).includes('authorization');
} else {
return false;
}
} | javascript | function validCorsPreflight(request) {
if (request.method === 'OPTIONS' && request.headers.has('access-control-request-headers')) {
return request.headers.get('access-control-request-headers').split(',').map(function (header) {
return header.trim();
}).includes('authorization');
} else {
return false;
}
} | [
"function",
"validCorsPreflight",
"(",
"request",
")",
"{",
"if",
"(",
"request",
".",
"method",
"===",
"'OPTIONS'",
"&&",
"request",
".",
"headers",
".",
"has",
"(",
"'access-control-request-headers'",
")",
")",
"{",
"return",
"request",
".",
"headers",
".",
"get",
"(",
"'access-control-request-headers'",
")",
".",
"split",
"(",
"','",
")",
".",
"map",
"(",
"function",
"(",
"header",
")",
"{",
"return",
"header",
".",
"trim",
"(",
")",
";",
"}",
")",
".",
"includes",
"(",
"'authorization'",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Checks if an OPTIONS request with the access-control-request-headers containing authorization is being made
@param request
@returns {boolean} | [
"Checks",
"if",
"an",
"OPTIONS",
"request",
"with",
"the",
"access",
"-",
"control",
"-",
"request",
"-",
"headers",
"containing",
"authorization",
"is",
"being",
"made"
] | eeb03fefcc954ea675ad44870b4f123a41f0d585 | https://github.com/nickschot/lux-jwt/blob/eeb03fefcc954ea675ad44870b4f123a41f0d585/lib/index.js#L88-L96 |
56,890 | nickschot/lux-jwt | lib/index.js | getTokenFromHeader | function getTokenFromHeader(request) {
if (!request.headers || !request.headers.has('authorization')) {
throw new UnauthorizedError('No authorization header present');
}
const parts = request.headers.get('authorization').split(" ");
if (parts.length === 2) {
const scheme = parts[0];
const credentials = parts[1];
if (/^Bearer$/i.test(scheme)) {
return credentials;
} else {
throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
}
} else {
throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
}
} | javascript | function getTokenFromHeader(request) {
if (!request.headers || !request.headers.has('authorization')) {
throw new UnauthorizedError('No authorization header present');
}
const parts = request.headers.get('authorization').split(" ");
if (parts.length === 2) {
const scheme = parts[0];
const credentials = parts[1];
if (/^Bearer$/i.test(scheme)) {
return credentials;
} else {
throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
}
} else {
throw new UnauthorizedError('Bad Authorization header format. Format is "Authorization: Bearer token"');
}
} | [
"function",
"getTokenFromHeader",
"(",
"request",
")",
"{",
"if",
"(",
"!",
"request",
".",
"headers",
"||",
"!",
"request",
".",
"headers",
".",
"has",
"(",
"'authorization'",
")",
")",
"{",
"throw",
"new",
"UnauthorizedError",
"(",
"'No authorization header present'",
")",
";",
"}",
"const",
"parts",
"=",
"request",
".",
"headers",
".",
"get",
"(",
"'authorization'",
")",
".",
"split",
"(",
"\" \"",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"2",
")",
"{",
"const",
"scheme",
"=",
"parts",
"[",
"0",
"]",
";",
"const",
"credentials",
"=",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"/",
"^Bearer$",
"/",
"i",
".",
"test",
"(",
"scheme",
")",
")",
"{",
"return",
"credentials",
";",
"}",
"else",
"{",
"throw",
"new",
"UnauthorizedError",
"(",
"'Bad Authorization header format. Format is \"Authorization: Bearer token\"'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnauthorizedError",
"(",
"'Bad Authorization header format. Format is \"Authorization: Bearer token\"'",
")",
";",
"}",
"}"
] | Retrieves the JWT from the authorization header
@param request
@returns {string} The JWT | [
"Retrieves",
"the",
"JWT",
"from",
"the",
"authorization",
"header"
] | eeb03fefcc954ea675ad44870b4f123a41f0d585 | https://github.com/nickschot/lux-jwt/blob/eeb03fefcc954ea675ad44870b4f123a41f0d585/lib/index.js#L103-L122 |
56,891 | pierrec/node-atok-parser | examples/block_stream.js | myParser | function myParser (size) {
if (typeof size !== 'number')
throw new Error('Invalid block size: ' + size)
function isEnd () {
return atok.ending ? atok.length - atok.offset : -1
}
atok
.trim()
.addRule(size, function (data) {
self.emit('data', data)
})
.addRule('', isEnd, function (data) {
var len = data.length
if (typeof data === 'string') {
var lastBlock = data + new Array(size - len + 1).join('0')
} else {
var lastBlock = new Buffer(size)
lastBlock.fill(0, len)
data.copy(lastBlock, 0)
}
self.emit('data', lastBlock)
})
.on('end', function () {
self.emit('end')
})
} | javascript | function myParser (size) {
if (typeof size !== 'number')
throw new Error('Invalid block size: ' + size)
function isEnd () {
return atok.ending ? atok.length - atok.offset : -1
}
atok
.trim()
.addRule(size, function (data) {
self.emit('data', data)
})
.addRule('', isEnd, function (data) {
var len = data.length
if (typeof data === 'string') {
var lastBlock = data + new Array(size - len + 1).join('0')
} else {
var lastBlock = new Buffer(size)
lastBlock.fill(0, len)
data.copy(lastBlock, 0)
}
self.emit('data', lastBlock)
})
.on('end', function () {
self.emit('end')
})
} | [
"function",
"myParser",
"(",
"size",
")",
"{",
"if",
"(",
"typeof",
"size",
"!==",
"'number'",
")",
"throw",
"new",
"Error",
"(",
"'Invalid block size: '",
"+",
"size",
")",
"function",
"isEnd",
"(",
")",
"{",
"return",
"atok",
".",
"ending",
"?",
"atok",
".",
"length",
"-",
"atok",
".",
"offset",
":",
"-",
"1",
"}",
"atok",
".",
"trim",
"(",
")",
".",
"addRule",
"(",
"size",
",",
"function",
"(",
"data",
")",
"{",
"self",
".",
"emit",
"(",
"'data'",
",",
"data",
")",
"}",
")",
".",
"addRule",
"(",
"''",
",",
"isEnd",
",",
"function",
"(",
"data",
")",
"{",
"var",
"len",
"=",
"data",
".",
"length",
"if",
"(",
"typeof",
"data",
"===",
"'string'",
")",
"{",
"var",
"lastBlock",
"=",
"data",
"+",
"new",
"Array",
"(",
"size",
"-",
"len",
"+",
"1",
")",
".",
"join",
"(",
"'0'",
")",
"}",
"else",
"{",
"var",
"lastBlock",
"=",
"new",
"Buffer",
"(",
"size",
")",
"lastBlock",
".",
"fill",
"(",
"0",
",",
"len",
")",
"data",
".",
"copy",
"(",
"lastBlock",
",",
"0",
")",
"}",
"self",
".",
"emit",
"(",
"'data'",
",",
"lastBlock",
")",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'end'",
")",
"}",
")",
"}"
] | Stream data in blocks | [
"Stream",
"data",
"in",
"blocks"
] | 414d39904dff73ffdde049212076c14ca40aa20b | https://github.com/pierrec/node-atok-parser/blob/414d39904dff73ffdde049212076c14ca40aa20b/examples/block_stream.js#L4-L32 |
56,892 | AdityaHegde/ember-object-utils | addon/objectWithArrayMixin.js | getArrayFromRange | function getArrayFromRange(l, h, s) {
var a = [];
s = s || 1;
for(var i = l; i < h; i += s) {
a.push(i);
}
return a;
} | javascript | function getArrayFromRange(l, h, s) {
var a = [];
s = s || 1;
for(var i = l; i < h; i += s) {
a.push(i);
}
return a;
} | [
"function",
"getArrayFromRange",
"(",
"l",
",",
"h",
",",
"s",
")",
"{",
"var",
"a",
"=",
"[",
"]",
";",
"s",
"=",
"s",
"||",
"1",
";",
"for",
"(",
"var",
"i",
"=",
"l",
";",
"i",
"<",
"h",
";",
"i",
"+=",
"s",
")",
"{",
"a",
".",
"push",
"(",
"i",
")",
";",
"}",
"return",
"a",
";",
"}"
] | Returns an array of integers from a starting number to another number with steps.
@method getArrayFromRange
@static
@param {Number} l Starting number.
@param {Number} h Ending number.
@param {Number} s Steps.
@returns {Array} | [
"Returns",
"an",
"array",
"of",
"integers",
"from",
"a",
"starting",
"number",
"to",
"another",
"number",
"with",
"steps",
"."
] | bc57203c4b523fd3a632735b25a5bb1bbf55dbcb | https://github.com/AdityaHegde/ember-object-utils/blob/bc57203c4b523fd3a632735b25a5bb1bbf55dbcb/addon/objectWithArrayMixin.js#L13-L20 |
56,893 | tabone/ipc-emitter | src/master.js | handleMasterPayload | function handleMasterPayload (payload) {
// Parse and validate received payload.
if ((payload = utils.parsePayload(payload)) === null) return
// Notify all workers except the worker who emitted the event.
sendPayload.call(this, payload)
} | javascript | function handleMasterPayload (payload) {
// Parse and validate received payload.
if ((payload = utils.parsePayload(payload)) === null) return
// Notify all workers except the worker who emitted the event.
sendPayload.call(this, payload)
} | [
"function",
"handleMasterPayload",
"(",
"payload",
")",
"{",
"// Parse and validate received payload.",
"if",
"(",
"(",
"payload",
"=",
"utils",
".",
"parsePayload",
"(",
"payload",
")",
")",
"===",
"null",
")",
"return",
"// Notify all workers except the worker who emitted the event.",
"sendPayload",
".",
"call",
"(",
"this",
",",
"payload",
")",
"}"
] | handleMasterPayload handles the payload recieved by the master process. If
payload is valid it is echoed back to all workers. Note that unlike the
handleWorkerPayload the listeners of the instance won't be notified.
@param {String} payload Payload received from a worker. | [
"handleMasterPayload",
"handles",
"the",
"payload",
"recieved",
"by",
"the",
"master",
"process",
".",
"If",
"payload",
"is",
"valid",
"it",
"is",
"echoed",
"back",
"to",
"all",
"workers",
".",
"Note",
"that",
"unlike",
"the",
"handleWorkerPayload",
"the",
"listeners",
"of",
"the",
"instance",
"won",
"t",
"be",
"notified",
"."
] | 4717a9e228ab8b28f2fd6d0966779c452ad38405 | https://github.com/tabone/ipc-emitter/blob/4717a9e228ab8b28f2fd6d0966779c452ad38405/src/master.js#L208-L214 |
56,894 | tabone/ipc-emitter | src/master.js | handleWorkerPayload | function handleWorkerPayload (payload) {
// Parse and validate received payload.
if ((payload = utils.parsePayload(payload)) === null) return
// If the master is configured to echo events to its own master, the event
// emitted by the worker should be echoed to the master.
if (this.__echoEvents === true) {
const echoPayload = JSON.parse(JSON.stringify(payload))
// Update PID as if the payload is originating from this process, the master
// is in. If this is not done, the master of this process, will resend the
// payload since the PID is different.
echoPayload[fields.pid] = process.pid
process.send(echoPayload)
}
// Unmarshal args.
payload[fields.args] = marshaller.unmarshal(payload[fields.args])
// Notify instance listeners.
events.prototype.emit.call(this, payload[fields.event],
...payload[fields.args])
// Notify all workers except the worker who emitted the event.
sendPayload.call(this, payload)
} | javascript | function handleWorkerPayload (payload) {
// Parse and validate received payload.
if ((payload = utils.parsePayload(payload)) === null) return
// If the master is configured to echo events to its own master, the event
// emitted by the worker should be echoed to the master.
if (this.__echoEvents === true) {
const echoPayload = JSON.parse(JSON.stringify(payload))
// Update PID as if the payload is originating from this process, the master
// is in. If this is not done, the master of this process, will resend the
// payload since the PID is different.
echoPayload[fields.pid] = process.pid
process.send(echoPayload)
}
// Unmarshal args.
payload[fields.args] = marshaller.unmarshal(payload[fields.args])
// Notify instance listeners.
events.prototype.emit.call(this, payload[fields.event],
...payload[fields.args])
// Notify all workers except the worker who emitted the event.
sendPayload.call(this, payload)
} | [
"function",
"handleWorkerPayload",
"(",
"payload",
")",
"{",
"// Parse and validate received payload.",
"if",
"(",
"(",
"payload",
"=",
"utils",
".",
"parsePayload",
"(",
"payload",
")",
")",
"===",
"null",
")",
"return",
"// If the master is configured to echo events to its own master, the event",
"// emitted by the worker should be echoed to the master.",
"if",
"(",
"this",
".",
"__echoEvents",
"===",
"true",
")",
"{",
"const",
"echoPayload",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"payload",
")",
")",
"// Update PID as if the payload is originating from this process, the master",
"// is in. If this is not done, the master of this process, will resend the",
"// payload since the PID is different.",
"echoPayload",
"[",
"fields",
".",
"pid",
"]",
"=",
"process",
".",
"pid",
"process",
".",
"send",
"(",
"echoPayload",
")",
"}",
"// Unmarshal args.",
"payload",
"[",
"fields",
".",
"args",
"]",
"=",
"marshaller",
".",
"unmarshal",
"(",
"payload",
"[",
"fields",
".",
"args",
"]",
")",
"// Notify instance listeners.",
"events",
".",
"prototype",
".",
"emit",
".",
"call",
"(",
"this",
",",
"payload",
"[",
"fields",
".",
"event",
"]",
",",
"...",
"payload",
"[",
"fields",
".",
"args",
"]",
")",
"// Notify all workers except the worker who emitted the event.",
"sendPayload",
".",
"call",
"(",
"this",
",",
"payload",
")",
"}"
] | handleWorkerPayload handles the payload received by a worker. If payload is
valid it is echoed back to all workers except the worker that it was received
from.
@param {String} payload Payload received from a worker. | [
"handleWorkerPayload",
"handles",
"the",
"payload",
"received",
"by",
"a",
"worker",
".",
"If",
"payload",
"is",
"valid",
"it",
"is",
"echoed",
"back",
"to",
"all",
"workers",
"except",
"the",
"worker",
"that",
"it",
"was",
"received",
"from",
"."
] | 4717a9e228ab8b28f2fd6d0966779c452ad38405 | https://github.com/tabone/ipc-emitter/blob/4717a9e228ab8b28f2fd6d0966779c452ad38405/src/master.js#L222-L246 |
56,895 | forfuturellc/svc-fbr | src/lib/db.js | getModels | function getModels(done) {
if (models) {
return done(models);
}
return orm.initialize(ormConfig, function(err, m) {
if (err) {
throw err;
}
// make the models available as soon as possible for other functions
models = m;
// ignore error if groups already created
let catcher = (createErr) => { if (createErr && createErr.code !== "E_VALIDATION") { throw createErr; } };
// create the administrators group
createGroup("admin", catcher);
// create the public group
createGroup("public", catcher);
return done(models);
});
} | javascript | function getModels(done) {
if (models) {
return done(models);
}
return orm.initialize(ormConfig, function(err, m) {
if (err) {
throw err;
}
// make the models available as soon as possible for other functions
models = m;
// ignore error if groups already created
let catcher = (createErr) => { if (createErr && createErr.code !== "E_VALIDATION") { throw createErr; } };
// create the administrators group
createGroup("admin", catcher);
// create the public group
createGroup("public", catcher);
return done(models);
});
} | [
"function",
"getModels",
"(",
"done",
")",
"{",
"if",
"(",
"models",
")",
"{",
"return",
"done",
"(",
"models",
")",
";",
"}",
"return",
"orm",
".",
"initialize",
"(",
"ormConfig",
",",
"function",
"(",
"err",
",",
"m",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"// make the models available as soon as possible for other functions",
"models",
"=",
"m",
";",
"// ignore error if groups already created",
"let",
"catcher",
"=",
"(",
"createErr",
")",
"=>",
"{",
"if",
"(",
"createErr",
"&&",
"createErr",
".",
"code",
"!==",
"\"E_VALIDATION\"",
")",
"{",
"throw",
"createErr",
";",
"}",
"}",
";",
"// create the administrators group",
"createGroup",
"(",
"\"admin\"",
",",
"catcher",
")",
";",
"// create the public group",
"createGroup",
"(",
"\"public\"",
",",
"catcher",
")",
";",
"return",
"done",
"(",
"models",
")",
";",
"}",
")",
";",
"}"
] | return models. It initializes Waterfall if not yet initialized in
this process.
@param {Function} done - done(models) | [
"return",
"models",
".",
"It",
"initializes",
"Waterfall",
"if",
"not",
"yet",
"initialized",
"in",
"this",
"process",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L145-L169 |
56,896 | forfuturellc/svc-fbr | src/lib/db.js | createGroup | function createGroup(name, done) {
return getModels(function(m) {
return m.collections.group.create({ name }, done);
});
} | javascript | function createGroup(name, done) {
return getModels(function(m) {
return m.collections.group.create({ name }, done);
});
} | [
"function",
"createGroup",
"(",
"name",
",",
"done",
")",
"{",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"collections",
".",
"group",
".",
"create",
"(",
"{",
"name",
"}",
",",
"done",
")",
";",
"}",
")",
";",
"}"
] | Create a new group | [
"Create",
"a",
"new",
"group"
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L175-L179 |
56,897 | forfuturellc/svc-fbr | src/lib/db.js | getGroup | function getGroup(name, done) {
return getModels(function(m) {
return m.collections.group.findOne({ name })
.populate("members").populate("leaders").exec(done);
});
} | javascript | function getGroup(name, done) {
return getModels(function(m) {
return m.collections.group.findOne({ name })
.populate("members").populate("leaders").exec(done);
});
} | [
"function",
"getGroup",
"(",
"name",
",",
"done",
")",
"{",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"collections",
".",
"group",
".",
"findOne",
"(",
"{",
"name",
"}",
")",
".",
"populate",
"(",
"\"members\"",
")",
".",
"populate",
"(",
"\"leaders\"",
")",
".",
"exec",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Get a group. It populates the members and leaders automatically.
@param {String} name
@param {Function} done - done(err, group) | [
"Get",
"a",
"group",
".",
"It",
"populates",
"the",
"members",
"and",
"leaders",
"automatically",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L188-L193 |
56,898 | forfuturellc/svc-fbr | src/lib/db.js | getGroups | function getGroups(done) {
return getModels(function(m) {
return m.collections.group.find().exec(done);
});
} | javascript | function getGroups(done) {
return getModels(function(m) {
return m.collections.group.find().exec(done);
});
} | [
"function",
"getGroups",
"(",
"done",
")",
"{",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"collections",
".",
"group",
".",
"find",
"(",
")",
".",
"exec",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Get all groups. Members and leaders are not loaded automatically.
This is by design; avoid too much data fetching.
@param {Function} done - done(err, groups) | [
"Get",
"all",
"groups",
".",
"Members",
"and",
"leaders",
"are",
"not",
"loaded",
"automatically",
".",
"This",
"is",
"by",
"design",
";",
"avoid",
"too",
"much",
"data",
"fetching",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L202-L206 |
56,899 | forfuturellc/svc-fbr | src/lib/db.js | deleteGroup | function deleteGroup(name, done) {
return getGroup(name, function(getGroupErr, group) {
if (getGroupErr) {
return done(getGroupErr);
}
if (!group) {
return done(new Error(`group '${name}' not found`));
}
return group.destroy(done);
});
} | javascript | function deleteGroup(name, done) {
return getGroup(name, function(getGroupErr, group) {
if (getGroupErr) {
return done(getGroupErr);
}
if (!group) {
return done(new Error(`group '${name}' not found`));
}
return group.destroy(done);
});
} | [
"function",
"deleteGroup",
"(",
"name",
",",
"done",
")",
"{",
"return",
"getGroup",
"(",
"name",
",",
"function",
"(",
"getGroupErr",
",",
"group",
")",
"{",
"if",
"(",
"getGroupErr",
")",
"{",
"return",
"done",
"(",
"getGroupErr",
")",
";",
"}",
"if",
"(",
"!",
"group",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"name",
"}",
"`",
")",
")",
";",
"}",
"return",
"group",
".",
"destroy",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Delete a group
@param {String} name
@param {Function} done - done(err) | [
"Delete",
"a",
"group"
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L215-L227 |
Subsets and Splits