repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1
value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
baijijs/baiji | lib/utils/compose.js | handleError | function handleError(promise) {
if (canHandleError) {
return promise.catch(function(err) {
if (ctx) {
ctx.error = err;
if (ctx.emit) ctx.emit('error', ctx);
} else {
ctx = { error: err };
}
return onError(ctx, next).catch(function... | javascript | function handleError(promise) {
if (canHandleError) {
return promise.catch(function(err) {
if (ctx) {
ctx.error = err;
if (ctx.emit) ctx.emit('error', ctx);
} else {
ctx = { error: err };
}
return onError(ctx, next).catch(function... | [
"function",
"handleError",
"(",
"promise",
")",
"{",
"if",
"(",
"canHandleError",
")",
"{",
"return",
"promise",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"ctx",
")",
"{",
"ctx",
".",
"error",
"=",
"err",
";",
"if",
"(",
"ctx"... | Handle possible error for each promise | [
"Handle",
"possible",
"error",
"for",
"each",
"promise"
] | 9e5938d5ce4991d0f9d12dbb4f50b3f30adbe601 | https://github.com/baijijs/baiji/blob/9e5938d5ce4991d0f9d12dbb4f50b3f30adbe601/lib/utils/compose.js#L50-L67 | train |
khalyomede/aegean | dist/main.js | aegean | function aegean(path) {
if (path === null || path === undefined || path.constructor !== String) {
throw new Error("aegean expects parameter 1 to be a string");
}
if (fs_1.existsSync(path) === false) {
throw new Error("file \"" + path + "\" does not exist");
}
var stat = fs_1.lstatSyn... | javascript | function aegean(path) {
if (path === null || path === undefined || path.constructor !== String) {
throw new Error("aegean expects parameter 1 to be a string");
}
if (fs_1.existsSync(path) === false) {
throw new Error("file \"" + path + "\" does not exist");
}
var stat = fs_1.lstatSyn... | [
"function",
"aegean",
"(",
"path",
")",
"{",
"if",
"(",
"path",
"===",
"null",
"||",
"path",
"===",
"undefined",
"||",
"path",
".",
"constructor",
"!==",
"String",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"aegean expects parameter 1 to be a string\"",
")",
... | Include imports statements down to the importing file.
@param {String} path The path to the file to inline.
@return {String} The inlined content.
@throws {Error} If the first parameter is not a string.
@throws {Error} If the path target a non existing file.
@throws {Error} If the path does not target a file. | [
"Include",
"imports",
"statements",
"down",
"to",
"the",
"importing",
"file",
"."
] | 99957eb9df483bb8b9e864af848af2371a6efa96 | https://github.com/khalyomede/aegean/blob/99957eb9df483bb8b9e864af848af2371a6efa96/dist/main.js#L14-L28 | train |
khalyomede/aegean | dist/main.js | inline | function inline(content, path) {
var result = content;
var ast = babylon.parse(content, {
allowImportExportEverywhere: true
});
var statements = ast.program.body;
var gap = 0;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements... | javascript | function inline(content, path) {
var result = content;
var ast = babylon.parse(content, {
allowImportExportEverywhere: true
});
var statements = ast.program.body;
var gap = 0;
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements... | [
"function",
"inline",
"(",
"content",
",",
"path",
")",
"{",
"var",
"result",
"=",
"content",
";",
"var",
"ast",
"=",
"babylon",
".",
"parse",
"(",
"content",
",",
"{",
"allowImportExportEverywhere",
":",
"true",
"}",
")",
";",
"var",
"statements",
"=",
... | Traverse a content and import recursively all the import statement contents into the content.
@param {String} content The file that could contain import statement.
@param {String} path The path to the file.
@return {String} The content with potential inlined import statements.
@throws {Error} If one of the sub import ... | [
"Traverse",
"a",
"content",
"and",
"import",
"recursively",
"all",
"the",
"import",
"statement",
"contents",
"into",
"the",
"content",
"."
] | 99957eb9df483bb8b9e864af848af2371a6efa96 | https://github.com/khalyomede/aegean/blob/99957eb9df483bb8b9e864af848af2371a6efa96/dist/main.js#L38-L79 | train |
mattma/ngd3 | build.js | spawnObservable | function spawnObservable(command, args) {
return Observable.create(observer => {
const cmd = spawn(command, args);
observer.next(''); // hack to kick things off, not every command will have a stdout
cmd.stdout.on('data', (data) => { observer.next(data.toString('utf8')); });
cmd.stderr.on('data', (data... | javascript | function spawnObservable(command, args) {
return Observable.create(observer => {
const cmd = spawn(command, args);
observer.next(''); // hack to kick things off, not every command will have a stdout
cmd.stdout.on('data', (data) => { observer.next(data.toString('utf8')); });
cmd.stderr.on('data', (data... | [
"function",
"spawnObservable",
"(",
"command",
",",
"args",
")",
"{",
"return",
"Observable",
".",
"create",
"(",
"observer",
"=>",
"{",
"const",
"cmd",
"=",
"spawn",
"(",
"command",
",",
"args",
")",
";",
"observer",
".",
"next",
"(",
"''",
")",
";",
... | Create an Observable of a spawned child process.
@param {string} command
@param {string[]} args | [
"Create",
"an",
"Observable",
"of",
"a",
"spawned",
"child",
"process",
"."
] | bdc5bf20e51c1a5f64f54ea1c083316d540560b1 | https://github.com/mattma/ngd3/blob/bdc5bf20e51c1a5f64f54ea1c083316d540560b1/build.js#L32-L40 | train |
mattma/ngd3 | build.js | createUmd | function createUmd(name, globals) {
// core module is ngd3 the rest are ngd3.feature
const MODULE_NAMES = {
ngd3: 'ngd3',
};
const ENTRIES = {
ngd3: `${process.cwd()}/dist/index.js`,
};
const moduleName = MODULE_NAMES[name];
const entry = ENTRIES[name];
return generateBundle(entry, {
dest: ... | javascript | function createUmd(name, globals) {
// core module is ngd3 the rest are ngd3.feature
const MODULE_NAMES = {
ngd3: 'ngd3',
};
const ENTRIES = {
ngd3: `${process.cwd()}/dist/index.js`,
};
const moduleName = MODULE_NAMES[name];
const entry = ENTRIES[name];
return generateBundle(entry, {
dest: ... | [
"function",
"createUmd",
"(",
"name",
",",
"globals",
")",
"{",
"// core module is ngd3 the rest are ngd3.feature",
"const",
"MODULE_NAMES",
"=",
"{",
"ngd3",
":",
"'ngd3'",
",",
"}",
";",
"const",
"ENTRIES",
"=",
"{",
"ngd3",
":",
"`",
"${",
"process",
".",
... | Create a UMD bundle given a module name.
@param {string} name
@param {Object} globals | [
"Create",
"a",
"UMD",
"bundle",
"given",
"a",
"module",
"name",
"."
] | bdc5bf20e51c1a5f64f54ea1c083316d540560b1 | https://github.com/mattma/ngd3/blob/bdc5bf20e51c1a5f64f54ea1c083316d540560b1/build.js#L60-L76 | train |
mattma/ngd3 | build.js | replaceVersionsObservable | function replaceVersionsObservable(name, versions) {
return Observable.create((observer) => {
const package = getSrcPackageFile(name);
let pkg = readFileSync(package, 'utf8');
const regexs = Object.keys(versions).map(key =>
({ expr: new RegExp(key, 'g'), key, val: versions[key] }));
regexs.forEa... | javascript | function replaceVersionsObservable(name, versions) {
return Observable.create((observer) => {
const package = getSrcPackageFile(name);
let pkg = readFileSync(package, 'utf8');
const regexs = Object.keys(versions).map(key =>
({ expr: new RegExp(key, 'g'), key, val: versions[key] }));
regexs.forEa... | [
"function",
"replaceVersionsObservable",
"(",
"name",
",",
"versions",
")",
"{",
"return",
"Observable",
".",
"create",
"(",
"(",
"observer",
")",
"=>",
"{",
"const",
"package",
"=",
"getSrcPackageFile",
"(",
"name",
")",
";",
"let",
"pkg",
"=",
"readFileSyn... | Create an observable of package.json dependency version replacements.
This keeps the dependency versions across each package in sync.
@param {string} name
@param {Object} versions | [
"Create",
"an",
"observable",
"of",
"package",
".",
"json",
"dependency",
"version",
"replacements",
".",
"This",
"keeps",
"the",
"dependency",
"versions",
"across",
"each",
"package",
"in",
"sync",
"."
] | bdc5bf20e51c1a5f64f54ea1c083316d540560b1 | https://github.com/mattma/ngd3/blob/bdc5bf20e51c1a5f64f54ea1c083316d540560b1/build.js#L106-L125 | train |
mattma/ngd3 | build.js | getVersions | function getVersions() {
const paths = [
getDestPackageFile('ngd3'),
];
return paths
.map(path => require(path))
.map(pkgs => pkgs.version);
} | javascript | function getVersions() {
const paths = [
getDestPackageFile('ngd3'),
];
return paths
.map(path => require(path))
.map(pkgs => pkgs.version);
} | [
"function",
"getVersions",
"(",
")",
"{",
"const",
"paths",
"=",
"[",
"getDestPackageFile",
"(",
"'ngd3'",
")",
",",
"]",
";",
"return",
"paths",
".",
"map",
"(",
"path",
"=>",
"require",
"(",
"path",
")",
")",
".",
"map",
"(",
"pkgs",
"=>",
"pkgs",
... | Returns each version of each NgD3 module.
This is used to help ensure each package has the same version. | [
"Returns",
"each",
"version",
"of",
"each",
"NgD3",
"module",
".",
"This",
"is",
"used",
"to",
"help",
"ensure",
"each",
"package",
"has",
"the",
"same",
"version",
"."
] | bdc5bf20e51c1a5f64f54ea1c083316d540560b1 | https://github.com/mattma/ngd3/blob/bdc5bf20e51c1a5f64f54ea1c083316d540560b1/build.js#L151-L159 | train |
erossignon/redmine-api | lib/redmine_web_server.js | fixUnicode | function fixUnicode(txt) {
txt = txt.replace(/\003/g, ' ');
txt = txt.replace(/\004/g, ' ');
txt = txt.replace(/(\r|\n)/g, ' ');
txt = txt.replace(/[\u007f-\uffff]/g, function (c) {
return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
});
return txt;
} | javascript | function fixUnicode(txt) {
txt = txt.replace(/\003/g, ' ');
txt = txt.replace(/\004/g, ' ');
txt = txt.replace(/(\r|\n)/g, ' ');
txt = txt.replace(/[\u007f-\uffff]/g, function (c) {
return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
});
return txt;
} | [
"function",
"fixUnicode",
"(",
"txt",
")",
"{",
"txt",
"=",
"txt",
".",
"replace",
"(",
"/",
"\\003",
"/",
"g",
",",
"' '",
")",
";",
"txt",
"=",
"txt",
".",
"replace",
"(",
"/",
"\\004",
"/",
"g",
",",
"' '",
")",
";",
"txt",
"=",
"txt",
"."... | Fix Unicode String that would cause JSON.parse to fail | [
"Fix",
"Unicode",
"String",
"that",
"would",
"cause",
"JSON",
".",
"parse",
"to",
"fail"
] | 8850f38c10fedf1d891cf3670863aed08c70745a | https://github.com/erossignon/redmine-api/blob/8850f38c10fedf1d891cf3670863aed08c70745a/lib/redmine_web_server.js#L41-L49 | train |
erossignon/redmine-api | lib/redmine_web_server.js | __fetchTicketInfo | function __fetchTicketInfo(server, ticketid, callback) {
assert(server.cache_folder);
var filename = server._ticket_cache_file(ticketid);
//xx console.log("filename " , filename.red);
assert(_.isFunction(callback));
var command = 'issues/' + ticketid.toString() + '.json?include=relations,journal... | javascript | function __fetchTicketInfo(server, ticketid, callback) {
assert(server.cache_folder);
var filename = server._ticket_cache_file(ticketid);
//xx console.log("filename " , filename.red);
assert(_.isFunction(callback));
var command = 'issues/' + ticketid.toString() + '.json?include=relations,journal... | [
"function",
"__fetchTicketInfo",
"(",
"server",
",",
"ticketid",
",",
"callback",
")",
"{",
"assert",
"(",
"server",
".",
"cache_folder",
")",
";",
"var",
"filename",
"=",
"server",
".",
"_ticket_cache_file",
"(",
"ticketid",
")",
";",
"//xx console.log(\"filena... | \brief extract the full raw information for a given ticket out of redmine
and store it to a json file in the cache.
any old version of the ticket json file will be overwritten | [
"\\",
"brief",
"extract",
"the",
"full",
"raw",
"information",
"for",
"a",
"given",
"ticket",
"out",
"of",
"redmine",
"and",
"store",
"it",
"to",
"a",
"json",
"file",
"in",
"the",
"cache",
".",
"any",
"old",
"version",
"of",
"the",
"ticket",
"json",
"f... | 8850f38c10fedf1d891cf3670863aed08c70745a | https://github.com/erossignon/redmine-api/blob/8850f38c10fedf1d891cf3670863aed08c70745a/lib/redmine_web_server.js#L327-L360 | train |
Kurento/kurento-module-crowddetector-js | lib/complexTypes/RelativePoint.js | RelativePoint | function RelativePoint(relativePointDict){
if(!(this instanceof RelativePoint))
return new RelativePoint(relativePointDict)
relativePointDict = relativePointDict || {}
// Check relativePointDict has the required fields
//
// checkType('float', 'relativePointDict.x', relativePointDict.x, {required: true... | javascript | function RelativePoint(relativePointDict){
if(!(this instanceof RelativePoint))
return new RelativePoint(relativePointDict)
relativePointDict = relativePointDict || {}
// Check relativePointDict has the required fields
//
// checkType('float', 'relativePointDict.x', relativePointDict.x, {required: true... | [
"function",
"RelativePoint",
"(",
"relativePointDict",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"RelativePoint",
")",
")",
"return",
"new",
"RelativePoint",
"(",
"relativePointDict",
")",
"relativePointDict",
"=",
"relativePointDict",
"||",
"{",
"}",
... | Relative points in a physical screen, values are a percentage relative to the
@constructor module:crowddetector/complexTypes.RelativePoint
@property {external:Number} x
Percentage relative to the image width to calculate the X coordinate of the
point [0..1]
@property {external:Number} y
Percentage relative to the ima... | [
"Relative",
"points",
"in",
"a",
"physical",
"screen",
"values",
"are",
"a",
"percentage",
"relative",
"to",
"the"
] | ae0a03c5d6bbc07a23d083fe8916017cb4a63855 | https://github.com/Kurento/kurento-module-crowddetector-js/blob/ae0a03c5d6bbc07a23d083fe8916017cb4a63855/lib/complexTypes/RelativePoint.js#L40-L69 | train |
adplabs/PigeonKeeper | lib/pigeonkeeper.js | initializeStates | function initializeStates()
{
// Set all states to NOT_READY
var numVertices = graph.vertexCount();
var vertexIds = graph.getVertexIds();
for(var i = 0; i < numVertices; i++)
{
graph.getVertex(vertexIds[i]).setState("NOT_READY");
}
} | javascript | function initializeStates()
{
// Set all states to NOT_READY
var numVertices = graph.vertexCount();
var vertexIds = graph.getVertexIds();
for(var i = 0; i < numVertices; i++)
{
graph.getVertex(vertexIds[i]).setState("NOT_READY");
}
} | [
"function",
"initializeStates",
"(",
")",
"{",
"// Set all states to NOT_READY",
"var",
"numVertices",
"=",
"graph",
".",
"vertexCount",
"(",
")",
";",
"var",
"vertexIds",
"=",
"graph",
".",
"getVertexIds",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
... | Sets states of all vertices to be NOT_READY
@private | [
"Sets",
"states",
"of",
"all",
"vertices",
"to",
"be",
"NOT_READY"
] | c0a92d2032415617c2b6f6bd49d00a2c59bfaa41 | https://github.com/adplabs/PigeonKeeper/blob/c0a92d2032415617c2b6f6bd49d00a2c59bfaa41/lib/pigeonkeeper.js#L404-L414 | train |
adplabs/PigeonKeeper | lib/pigeonkeeper.js | startReadyProcesses | function startReadyProcesses()
{
// Start as many processes as we can!
//writeToLog("INFO", "***** maxNumberOfRunningProcesses = " + maxNumberOfRunningProcesses + "; numberOfRunningProcesses = " + numberOfRunningProcesses);
var numVertices = graph.vertexCount();
var vertexIds = graph... | javascript | function startReadyProcesses()
{
// Start as many processes as we can!
//writeToLog("INFO", "***** maxNumberOfRunningProcesses = " + maxNumberOfRunningProcesses + "; numberOfRunningProcesses = " + numberOfRunningProcesses);
var numVertices = graph.vertexCount();
var vertexIds = graph... | [
"function",
"startReadyProcesses",
"(",
")",
"{",
"// Start as many processes as we can!",
"//writeToLog(\"INFO\", \"***** maxNumberOfRunningProcesses = \" + maxNumberOfRunningProcesses + \"; numberOfRunningProcesses = \" + numberOfRunningProcesses);",
"var",
"numVertices",
"=",
"graph",
".",
... | Starts all processes where associated vertices are READY
@private | [
"Starts",
"all",
"processes",
"where",
"associated",
"vertices",
"are",
"READY"
] | c0a92d2032415617c2b6f6bd49d00a2c59bfaa41 | https://github.com/adplabs/PigeonKeeper/blob/c0a92d2032415617c2b6f6bd49d00a2c59bfaa41/lib/pigeonkeeper.js#L484-L507 | train |
adplabs/PigeonKeeper | lib/pigeonkeeper.js | vertexIdsFromArray | function vertexIdsFromArray(arr)
{
var numVertices = arr.length;
var vertexIds = [];
for(var i = 0; i < numVertices; i++)
{
vertexIds.push(arr[i].id);
}
return vertexIds;
} | javascript | function vertexIdsFromArray(arr)
{
var numVertices = arr.length;
var vertexIds = [];
for(var i = 0; i < numVertices; i++)
{
vertexIds.push(arr[i].id);
}
return vertexIds;
} | [
"function",
"vertexIdsFromArray",
"(",
"arr",
")",
"{",
"var",
"numVertices",
"=",
"arr",
".",
"length",
";",
"var",
"vertexIds",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"numVertices",
";",
"i",
"++",
")",
"{",
"vertexI... | Extracts the vertexIDs from a given array of vertices
@private
@param {Array} arr - Array of vertices
@returns {Array} | [
"Extracts",
"the",
"vertexIDs",
"from",
"a",
"given",
"array",
"of",
"vertices"
] | c0a92d2032415617c2b6f6bd49d00a2c59bfaa41 | https://github.com/adplabs/PigeonKeeper/blob/c0a92d2032415617c2b6f6bd49d00a2c59bfaa41/lib/pigeonkeeper.js#L516-L527 | train |
adplabs/PigeonKeeper | lib/pigeonkeeper.js | writeToLog | function writeToLog(level, msg)
{
var displayPrefix = "PK-" + pkGuid + ": ";
if(loggingMechanism && logUserObject)
{
loggingMechanism.addLog(level, displayPrefix + msg, logUserObject);
}
else
{
console.log(displayPrefix + msg);
}
} | javascript | function writeToLog(level, msg)
{
var displayPrefix = "PK-" + pkGuid + ": ";
if(loggingMechanism && logUserObject)
{
loggingMechanism.addLog(level, displayPrefix + msg, logUserObject);
}
else
{
console.log(displayPrefix + msg);
}
} | [
"function",
"writeToLog",
"(",
"level",
",",
"msg",
")",
"{",
"var",
"displayPrefix",
"=",
"\"PK-\"",
"+",
"pkGuid",
"+",
"\": \"",
";",
"if",
"(",
"loggingMechanism",
"&&",
"logUserObject",
")",
"{",
"loggingMechanism",
".",
"addLog",
"(",
"level",
",",
"... | Wrapper around logging mechanism's addLog method
@private
@param level
@param {string} msg | [
"Wrapper",
"around",
"logging",
"mechanism",
"s",
"addLog",
"method"
] | c0a92d2032415617c2b6f6bd49d00a2c59bfaa41 | https://github.com/adplabs/PigeonKeeper/blob/c0a92d2032415617c2b6f6bd49d00a2c59bfaa41/lib/pigeonkeeper.js#L536-L547 | train |
ebrelsford/cartocss2json | index.js | zoomCondition | function zoomCondition(zoom) {
var zooms = [];
for (var i = 0; i <= _carto2['default'].tree.Zoom.maxZoom; i++) {
if (zoom & 1 << i) {
zooms.push(i);
}
}
var zoomRanges = detectZoomRanges(zooms),
value,
operator;
if (zoomRanges.length > 1) {
operat... | javascript | function zoomCondition(zoom) {
var zooms = [];
for (var i = 0; i <= _carto2['default'].tree.Zoom.maxZoom; i++) {
if (zoom & 1 << i) {
zooms.push(i);
}
}
var zoomRanges = detectZoomRanges(zooms),
value,
operator;
if (zoomRanges.length > 1) {
operat... | [
"function",
"zoomCondition",
"(",
"zoom",
")",
"{",
"var",
"zooms",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<=",
"_carto2",
"[",
"'default'",
"]",
".",
"tree",
".",
"Zoom",
".",
"maxZoom",
";",
"i",
"++",
")",
"{",
"if"... | Create a zoom condition given a zoom integer | [
"Create",
"a",
"zoom",
"condition",
"given",
"a",
"zoom",
"integer"
] | 4c1d47ce55da7cac97666439579781dd4d21b802 | https://github.com/ebrelsford/cartocss2json/blob/4c1d47ce55da7cac97666439579781dd4d21b802/index.js#L169-L206 | train |
ebrelsford/cartocss2json | index.js | detectZoomRanges | function detectZoomRanges(zooms) {
var ranges = [];
var currentRange = [];
for (var i = 0, z = zooms[0]; i <= zooms.length; i++, z = zooms[i]) {
if (currentRange.length < 2) {
currentRange.push(z);
continue;
}
if (currentRange.length === 2) {
if (z... | javascript | function detectZoomRanges(zooms) {
var ranges = [];
var currentRange = [];
for (var i = 0, z = zooms[0]; i <= zooms.length; i++, z = zooms[i]) {
if (currentRange.length < 2) {
currentRange.push(z);
continue;
}
if (currentRange.length === 2) {
if (z... | [
"function",
"detectZoomRanges",
"(",
"zooms",
")",
"{",
"var",
"ranges",
"=",
"[",
"]",
";",
"var",
"currentRange",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"z",
"=",
"zooms",
"[",
"0",
"]",
";",
"i",
"<=",
"zooms",
".",
"leng... | Find zoom ranges in a set of zooms | [
"Find",
"zoom",
"ranges",
"in",
"a",
"set",
"of",
"zooms"
] | 4c1d47ce55da7cac97666439579781dd4d21b802 | https://github.com/ebrelsford/cartocss2json/blob/4c1d47ce55da7cac97666439579781dd4d21b802/index.js#L211-L232 | train |
joneit/filter-tree | js/FilterTree.js | onchange | function onchange(evt) { // called in context
var ctrl = evt.target;
if (ctrl.parentElement === this.el) {
if (ctrl.value === 'subexp') {
this.children.push(new FilterTree({
parent: this
}));
} else {
this.add({
state: { editor:... | javascript | function onchange(evt) { // called in context
var ctrl = evt.target;
if (ctrl.parentElement === this.el) {
if (ctrl.value === 'subexp') {
this.children.push(new FilterTree({
parent: this
}));
} else {
this.add({
state: { editor:... | [
"function",
"onchange",
"(",
"evt",
")",
"{",
"// called in context",
"var",
"ctrl",
"=",
"evt",
".",
"target",
";",
"if",
"(",
"ctrl",
".",
"parentElement",
"===",
"this",
".",
"el",
")",
"{",
"if",
"(",
"ctrl",
".",
"value",
"===",
"'subexp'",
")",
... | Some event handlers bound to FilterTree object | [
"Some",
"event",
"handlers",
"bound",
"to",
"FilterTree",
"object"
] | c070a4045fced3e4ab20ed2e0c706c9a5fd07d1e | https://github.com/joneit/filter-tree/blob/c070a4045fced3e4ab20ed2e0c706c9a5fd07d1e/js/FilterTree.js#L463-L478 | train |
ev3-js/ev3-client | lib/move.js | move | function move (leftPort, rightPort) {
leftPort = leftPort || 'b'
rightPort = rightPort || 'c'
var write = writeAction('motors_write', [leftPort, rightPort])
/**
* Run motors forever
* @param {Number} speed speed of motor
* @param {Object} opts object of optional params
*/
function * forever (sp... | javascript | function move (leftPort, rightPort) {
leftPort = leftPort || 'b'
rightPort = rightPort || 'c'
var write = writeAction('motors_write', [leftPort, rightPort])
/**
* Run motors forever
* @param {Number} speed speed of motor
* @param {Object} opts object of optional params
*/
function * forever (sp... | [
"function",
"move",
"(",
"leftPort",
",",
"rightPort",
")",
"{",
"leftPort",
"=",
"leftPort",
"||",
"'b'",
"rightPort",
"=",
"rightPort",
"||",
"'c'",
"var",
"write",
"=",
"writeAction",
"(",
"'motors_write'",
",",
"[",
"leftPort",
",",
"rightPort",
"]",
"... | Set up drive motors and returns functions to control them.
@param {string} leftPort port that the left motor is connected to
@param {string} rightPort port that the right motor is connected to
@return {object} steering functions | [
"Set",
"up",
"drive",
"motors",
"and",
"returns",
"functions",
"to",
"control",
"them",
"."
] | e63dad977a77b6d2ecc7b81ebf288cc595d76771 | https://github.com/ev3-js/ev3-client/blob/e63dad977a77b6d2ecc7b81ebf288cc595d76771/lib/move.js#L32-L142 | train |
ev3-js/ev3-client | lib/move.js | turnToSpeeds | function turnToSpeeds (turn, speed) {
turn = Math.max(Math.min(turn, 100), -100)
var reducedSpeed = otherSpeed(turn, speed)
reducedSpeed = percentToSpeed(reducedSpeed)
speed = percentToSpeed(speed)
return {
left: turn < 0 ? reducedSpeed : speed,
right: turn > 0 ? reducedSpeed : speed
}
} | javascript | function turnToSpeeds (turn, speed) {
turn = Math.max(Math.min(turn, 100), -100)
var reducedSpeed = otherSpeed(turn, speed)
reducedSpeed = percentToSpeed(reducedSpeed)
speed = percentToSpeed(speed)
return {
left: turn < 0 ? reducedSpeed : speed,
right: turn > 0 ? reducedSpeed : speed
}
} | [
"function",
"turnToSpeeds",
"(",
"turn",
",",
"speed",
")",
"{",
"turn",
"=",
"Math",
".",
"max",
"(",
"Math",
".",
"min",
"(",
"turn",
",",
"100",
")",
",",
"-",
"100",
")",
"var",
"reducedSpeed",
"=",
"otherSpeed",
"(",
"turn",
",",
"speed",
")",... | Convert turn in to left and right speeds
@param {Number} turn -100 to 100
@param {Number} speed
@return {Object} | [
"Convert",
"turn",
"in",
"to",
"left",
"and",
"right",
"speeds"
] | e63dad977a77b6d2ecc7b81ebf288cc595d76771 | https://github.com/ev3-js/ev3-client/blob/e63dad977a77b6d2ecc7b81ebf288cc595d76771/lib/move.js#L150-L161 | train |
ev3-js/ev3-client | lib/move.js | turnToDegrees | function turnToDegrees (turn, speed, degrees) {
turn = Math.max(Math.min(turn, 100), -100)
var opts = turnToSpeeds(turn, speed)
opts.left = { speed: opts.left }
opts.right = { speed: opts.right }
var reducedSpeed = otherSpeed(turn, speed)
var reducedDegrees = Math.round((reducedSpeed / speed) * degrees)
... | javascript | function turnToDegrees (turn, speed, degrees) {
turn = Math.max(Math.min(turn, 100), -100)
var opts = turnToSpeeds(turn, speed)
opts.left = { speed: opts.left }
opts.right = { speed: opts.right }
var reducedSpeed = otherSpeed(turn, speed)
var reducedDegrees = Math.round((reducedSpeed / speed) * degrees)
... | [
"function",
"turnToDegrees",
"(",
"turn",
",",
"speed",
",",
"degrees",
")",
"{",
"turn",
"=",
"Math",
".",
"max",
"(",
"Math",
".",
"min",
"(",
"turn",
",",
"100",
")",
",",
"-",
"100",
")",
"var",
"opts",
"=",
"turnToSpeeds",
"(",
"turn",
",",
... | Params for degrees based on turn
@param {Number} turn
@param {Number} speed
@param {Number} degrees
@return {Object} opts object of degrees and speed for each motor | [
"Params",
"for",
"degrees",
"based",
"on",
"turn"
] | e63dad977a77b6d2ecc7b81ebf288cc595d76771 | https://github.com/ev3-js/ev3-client/blob/e63dad977a77b6d2ecc7b81ebf288cc595d76771/lib/move.js#L170-L184 | train |
overlookmotel/lock-queue | lib/index.js | joinQueue | function joinQueue(fn, ctx, exclusive) {
// Promisify `fn`
fn = promisify(fn, 0);
// Add into queue
var deferred = defer();
this.queue.push({fn: fn, ctx: ctx, deferred: deferred, exclusive: exclusive});
// Run queue
runQueue.call(this);
// Return deferred promise
return deferred.p... | javascript | function joinQueue(fn, ctx, exclusive) {
// Promisify `fn`
fn = promisify(fn, 0);
// Add into queue
var deferred = defer();
this.queue.push({fn: fn, ctx: ctx, deferred: deferred, exclusive: exclusive});
// Run queue
runQueue.call(this);
// Return deferred promise
return deferred.p... | [
"function",
"joinQueue",
"(",
"fn",
",",
"ctx",
",",
"exclusive",
")",
"{",
"// Promisify `fn`",
"fn",
"=",
"promisify",
"(",
"fn",
",",
"0",
")",
";",
"// Add into queue",
"var",
"deferred",
"=",
"defer",
"(",
")",
";",
"this",
".",
"queue",
".",
"pus... | Add process to the queue and run queue
@param {Function} fn - Function to queue
@param {*} [ctx] - `this` context to run function with
@param {boolean} - `true` if function requires an exclusive lock
@returns {Promise} - Promise which resolves/rejects with eventual outcome of `fn()` | [
"Add",
"process",
"to",
"the",
"queue",
"and",
"run",
"queue"
] | 1d0eed62b63f49b25d1648f5d7cad02602989daf | https://github.com/overlookmotel/lock-queue/blob/1d0eed62b63f49b25d1648f5d7cad02602989daf/lib/index.js#L74-L87 | train |
overlookmotel/lock-queue | lib/index.js | runNext | function runNext() {
if (this.locked) return false;
var item = this.queue[0];
if (!item) return false;
if (item.exclusive) {
if (this.running) return false;
this.locked = true;
}
this.queue.shift();
this.running++;
var self = this;
item.fn.call(item.ctx).then(function(res... | javascript | function runNext() {
if (this.locked) return false;
var item = this.queue[0];
if (!item) return false;
if (item.exclusive) {
if (this.running) return false;
this.locked = true;
}
this.queue.shift();
this.running++;
var self = this;
item.fn.call(item.ctx).then(function(res... | [
"function",
"runNext",
"(",
")",
"{",
"if",
"(",
"this",
".",
"locked",
")",
"return",
"false",
";",
"var",
"item",
"=",
"this",
".",
"queue",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"item",
")",
"return",
"false",
";",
"if",
"(",
"item",
".",
"exc... | Run next item in queue
@returns {boolean} - `true` if was able to run an item, `false` if not | [
"Run",
"next",
"item",
"in",
"queue"
] | 1d0eed62b63f49b25d1648f5d7cad02602989daf | https://github.com/overlookmotel/lock-queue/blob/1d0eed62b63f49b25d1648f5d7cad02602989daf/lib/index.js#L108-L131 | train |
overlookmotel/lock-queue | lib/index.js | runDone | function runDone(item, resolved, res) {
// Adjust state of lock
this.running--;
if (this.locked) this.locked = false;
// Resolve/reject promise
item.deferred[resolved ? 'resolve' : 'reject'](res);
// Run queue again
runQueue.call(this);
} | javascript | function runDone(item, resolved, res) {
// Adjust state of lock
this.running--;
if (this.locked) this.locked = false;
// Resolve/reject promise
item.deferred[resolved ? 'resolve' : 'reject'](res);
// Run queue again
runQueue.call(this);
} | [
"function",
"runDone",
"(",
"item",
",",
"resolved",
",",
"res",
")",
"{",
"// Adjust state of lock",
"this",
".",
"running",
"--",
";",
"if",
"(",
"this",
".",
"locked",
")",
"this",
".",
"locked",
"=",
"false",
";",
"// Resolve/reject promise",
"item",
"... | Run complete.
Update state, resolve deferred promise, and run queue again.
@param {Object} - Queue item
@param {boolean} - `true` if function resolved, `false` if rejected
@param {*} - Result of function (resolve value or reject reason)
@returns {undefined} | [
"Run",
"complete",
".",
"Update",
"state",
"resolve",
"deferred",
"promise",
"and",
"run",
"queue",
"again",
"."
] | 1d0eed62b63f49b25d1648f5d7cad02602989daf | https://github.com/overlookmotel/lock-queue/blob/1d0eed62b63f49b25d1648f5d7cad02602989daf/lib/index.js#L141-L151 | train |
anvaka/circle-enclose | index.js | encloseN | function encloseN(L, B) {
var circle,
l0 = null,
l1 = L.head,
l2,
p1;
switch (B.length) {
case 1: circle = enclose1(B[0]); break;
case 2: circle = enclose2(B[0], B[1]); break;
case 3: circle = enclose3(B[0], B[1], B[2]); break;
}
while (l1) {
p1 = l1._, l2 = l1.next;
... | javascript | function encloseN(L, B) {
var circle,
l0 = null,
l1 = L.head,
l2,
p1;
switch (B.length) {
case 1: circle = enclose1(B[0]); break;
case 2: circle = enclose2(B[0], B[1]); break;
case 3: circle = enclose3(B[0], B[1], B[2]); break;
}
while (l1) {
p1 = l1._, l2 = l1.next;
... | [
"function",
"encloseN",
"(",
"L",
",",
"B",
")",
"{",
"var",
"circle",
",",
"l0",
"=",
"null",
",",
"l1",
"=",
"L",
".",
"head",
",",
"l2",
",",
"p1",
";",
"switch",
"(",
"B",
".",
"length",
")",
"{",
"case",
"1",
":",
"circle",
"=",
"enclose... | Returns the smallest circle that contains circles L and intersects circles B. | [
"Returns",
"the",
"smallest",
"circle",
"that",
"contains",
"circles",
"L",
"and",
"intersects",
"circles",
"B",
"."
] | f411a81cdbc5964daaa30a81e3d96becca804248 | https://github.com/anvaka/circle-enclose/blob/f411a81cdbc5964daaa30a81e3d96becca804248/index.js#L57-L95 | train |
yoshuawuyts/koa-watchify | index.js | kw | function kw(bundler) {
assert.equal(typeof bundler, 'object')
const handler = thenify(wreq(bundler))
// Koa middleware.
// @param {Function} next
// @return {Promise}
return function *watchifyRequest(next) {
const ctx = this
return yield handler(this.req, this.res)
.then(success)
.catc... | javascript | function kw(bundler) {
assert.equal(typeof bundler, 'object')
const handler = thenify(wreq(bundler))
// Koa middleware.
// @param {Function} next
// @return {Promise}
return function *watchifyRequest(next) {
const ctx = this
return yield handler(this.req, this.res)
.then(success)
.catc... | [
"function",
"kw",
"(",
"bundler",
")",
"{",
"assert",
".",
"equal",
"(",
"typeof",
"bundler",
",",
"'object'",
")",
"const",
"handler",
"=",
"thenify",
"(",
"wreq",
"(",
"bundler",
")",
")",
"// Koa middleware.",
"// @param {Function} next",
"// @return {Promise... | Wrap `watchify-request` in koa middleware. @param {Object} bundler @return {Function*} | [
"Wrap",
"watchify",
"-",
"request",
"in",
"koa",
"middleware",
"."
] | ee0b62723822465881e8558f5011b22ef501a79e | https://github.com/yoshuawuyts/koa-watchify/blob/ee0b62723822465881e8558f5011b22ef501a79e/index.js#L10-L32 | train |
deanlandolt/bytewise-core | index.js | serialize | function serialize(type, source, options) {
var codec = type.codec
if (!codec)
return postEncode(new Buffer([ type.byte ]), options)
var buffer = codec.encode(source, bytewise)
if (options && options.nested && codec.escape)
buffer = codec.escape(buffer)
var hint = typeof codec.length === 'number' ?... | javascript | function serialize(type, source, options) {
var codec = type.codec
if (!codec)
return postEncode(new Buffer([ type.byte ]), options)
var buffer = codec.encode(source, bytewise)
if (options && options.nested && codec.escape)
buffer = codec.escape(buffer)
var hint = typeof codec.length === 'number' ?... | [
"function",
"serialize",
"(",
"type",
",",
"source",
",",
"options",
")",
"{",
"var",
"codec",
"=",
"type",
".",
"codec",
"if",
"(",
"!",
"codec",
")",
"return",
"postEncode",
"(",
"new",
"Buffer",
"(",
"[",
"type",
".",
"byte",
"]",
")",
",",
"opt... | generate a buffer with type's byte prefix from source value | [
"generate",
"a",
"buffer",
"with",
"type",
"s",
"byte",
"prefix",
"from",
"source",
"value"
] | 293f2eb2623903baf0fc02fd81a770f06d62c8de | https://github.com/deanlandolt/bytewise-core/blob/293f2eb2623903baf0fc02fd81a770f06d62c8de/index.js#L18-L31 | train |
deanlandolt/bytewise-core | index.js | postEncode | function postEncode(encoded, options) {
if (options === null)
return encoded
return bytewise.postEncode(encoded, options)
} | javascript | function postEncode(encoded, options) {
if (options === null)
return encoded
return bytewise.postEncode(encoded, options)
} | [
"function",
"postEncode",
"(",
"encoded",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"null",
")",
"return",
"encoded",
"return",
"bytewise",
".",
"postEncode",
"(",
"encoded",
",",
"options",
")",
"}"
] | process top level | [
"process",
"top",
"level"
] | 293f2eb2623903baf0fc02fd81a770f06d62c8de | https://github.com/deanlandolt/bytewise-core/blob/293f2eb2623903baf0fc02fd81a770f06d62c8de/index.js#L106-L111 | train |
joneit/filter-tree | js/FilterLeaf.js | cleanUpAndMoveOn | function cleanUpAndMoveOn(evt) {
var el = evt.target;
// remove `error` CSS class, which may have been added by `FilterLeaf.prototype.invalid`
el.classList.remove('filter-tree-error');
// set or remove 'warning' CSS class, as per el.value
FilterNode.setWarningClass(el);
if (el === this.view.c... | javascript | function cleanUpAndMoveOn(evt) {
var el = evt.target;
// remove `error` CSS class, which may have been added by `FilterLeaf.prototype.invalid`
el.classList.remove('filter-tree-error');
// set or remove 'warning' CSS class, as per el.value
FilterNode.setWarningClass(el);
if (el === this.view.c... | [
"function",
"cleanUpAndMoveOn",
"(",
"evt",
")",
"{",
"var",
"el",
"=",
"evt",
".",
"target",
";",
"// remove `error` CSS class, which may have been added by `FilterLeaf.prototype.invalid`",
"el",
".",
"classList",
".",
"remove",
"(",
"'filter-tree-error'",
")",
";",
"/... | `change` event handler for all form controls.
Rebuilds the operator drop-down as needed.
Removes error CSS class from control.
Adds warning CSS class from control if blank; removes if not blank.
Adds warning CSS class from control if blank; removes if not blank.
Moves focus to next non-blank sibling control.
@this {Fil... | [
"change",
"event",
"handler",
"for",
"all",
"form",
"controls",
".",
"Rebuilds",
"the",
"operator",
"drop",
"-",
"down",
"as",
"needed",
".",
"Removes",
"error",
"CSS",
"class",
"from",
"control",
".",
"Adds",
"warning",
"CSS",
"class",
"from",
"control",
... | c070a4045fced3e4ab20ed2e0c706c9a5fd07d1e | https://github.com/joneit/filter-tree/blob/c070a4045fced3e4ab20ed2e0c706c9a5fd07d1e/js/FilterLeaf.js#L412-L443 | train |
Kurento/kurento-module-crowddetector-js | lib/complexTypes/RegionOfInterest.js | RegionOfInterest | function RegionOfInterest(regionOfInterestDict){
if(!(this instanceof RegionOfInterest))
return new RegionOfInterest(regionOfInterestDict)
regionOfInterestDict = regionOfInterestDict || {}
// Check regionOfInterestDict has the required fields
//
// checkType('RelativePoint', 'regionOfInterestDict.point... | javascript | function RegionOfInterest(regionOfInterestDict){
if(!(this instanceof RegionOfInterest))
return new RegionOfInterest(regionOfInterestDict)
regionOfInterestDict = regionOfInterestDict || {}
// Check regionOfInterestDict has the required fields
//
// checkType('RelativePoint', 'regionOfInterestDict.point... | [
"function",
"RegionOfInterest",
"(",
"regionOfInterestDict",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"RegionOfInterest",
")",
")",
"return",
"new",
"RegionOfInterest",
"(",
"regionOfInterestDict",
")",
"regionOfInterestDict",
"=",
"regionOfInterestDict",
... | Region of interest for some events in a video processing filter
@constructor module:crowddetector/complexTypes.RegionOfInterest
@property {module:crowddetector/complexTypes.RelativePoint} points
list of points delimiting the region of interest
@property {module:crowddetector/complexTypes.RegionOfInterestConfig} regio... | [
"Region",
"of",
"interest",
"for",
"some",
"events",
"in",
"a",
"video",
"processing",
"filter"
] | ae0a03c5d6bbc07a23d083fe8916017cb4a63855 | https://github.com/Kurento/kurento-module-crowddetector-js/blob/ae0a03c5d6bbc07a23d083fe8916017cb4a63855/lib/complexTypes/RegionOfInterest.js#L42-L78 | train |
wilmoore/brackets2dots.js | index.js | brackets2dots | function brackets2dots(string) {
return ({}).toString.call(string) == '[object String]'
? string.replace(REPLACE_BRACKETS, '.$1').replace(LFT_RT_TRIM_DOTS, '')
: ''
} | javascript | function brackets2dots(string) {
return ({}).toString.call(string) == '[object String]'
? string.replace(REPLACE_BRACKETS, '.$1').replace(LFT_RT_TRIM_DOTS, '')
: ''
} | [
"function",
"brackets2dots",
"(",
"string",
")",
"{",
"return",
"(",
"{",
"}",
")",
".",
"toString",
".",
"call",
"(",
"string",
")",
"==",
"'[object String]'",
"?",
"string",
".",
"replace",
"(",
"REPLACE_BRACKETS",
",",
"'.$1'",
")",
".",
"replace",
"(... | Convert string with bracket notation to dot property notation.
### Examples:
brackets2dots('group[0].section.a.seat[3]')
//=> 'group.0.section.a.seat.3'
brackets2dots('[0].section.a.seat[3]')
//=> '0.section.a.seat.3'
brackets2dots('people[*].age')
//=> 'people.*.age'
@param {String} string
original string
@retu... | [
"Convert",
"string",
"with",
"bracket",
"notation",
"to",
"dot",
"property",
"notation",
"."
] | 83feb1226d0ede5306233721a488a4ac6ae7d8cd | https://github.com/wilmoore/brackets2dots.js/blob/83feb1226d0ede5306233721a488a4ac6ae7d8cd/index.js#L37-L41 | train |
nickdeis/metric-lcs | index.js | metriclcs | function metriclcs(s1, s2) {
if (typeof s1 !== "string" || typeof s1 !== "string") return NaN;
if (s1 === s2) return 1;
const mlen = Math.max(s1.length, s2.length);
if (mlen === 0) return 1;
return lcsLength(s1, s2) / mlen;
} | javascript | function metriclcs(s1, s2) {
if (typeof s1 !== "string" || typeof s1 !== "string") return NaN;
if (s1 === s2) return 1;
const mlen = Math.max(s1.length, s2.length);
if (mlen === 0) return 1;
return lcsLength(s1, s2) / mlen;
} | [
"function",
"metriclcs",
"(",
"s1",
",",
"s2",
")",
"{",
"if",
"(",
"typeof",
"s1",
"!==",
"\"string\"",
"||",
"typeof",
"s1",
"!==",
"\"string\"",
")",
"return",
"NaN",
";",
"if",
"(",
"s1",
"===",
"s2",
")",
"return",
"1",
";",
"const",
"mlen",
"... | Returns a number between 1 and 0, where 1 means they are exactly the same and 0 means no common subsequences.
If either string is not a string, returns NaN
@param {string} s1
@param {string} s2
@returns {number} | [
"Returns",
"a",
"number",
"between",
"1",
"and",
"0",
"where",
"1",
"means",
"they",
"are",
"exactly",
"the",
"same",
"and",
"0",
"means",
"no",
"common",
"subsequences",
".",
"If",
"either",
"string",
"is",
"not",
"a",
"string",
"returns",
"NaN"
] | bcbfb61d3f8b1297d5ac7e109f0d1b000f3b0658 | https://github.com/nickdeis/metric-lcs/blob/bcbfb61d3f8b1297d5ac7e109f0d1b000f3b0658/index.js#L32-L39 | train |
firesideguru/metalsmith-nested | lib/index.js | plugin | function plugin (config) {
/**
* Init
*/
// Throw an error if non-object supplied as `options`
if (config && (typeof(config) !== 'object' || config instanceof Array)) {
throw new Error('metalsmith-nested error: options argument must be an object');
}
config = config || {};
// Set opti... | javascript | function plugin (config) {
/**
* Init
*/
// Throw an error if non-object supplied as `options`
if (config && (typeof(config) !== 'object' || config instanceof Array)) {
throw new Error('metalsmith-nested error: options argument must be an object');
}
config = config || {};
// Set opti... | [
"function",
"plugin",
"(",
"config",
")",
"{",
"/**\n * Init\n */",
"// Throw an error if non-object supplied as `options`",
"if",
"(",
"config",
"&&",
"(",
"typeof",
"(",
"config",
")",
"!==",
"'object'",
"||",
"config",
"instanceof",
"Array",
")",
")",
"{",
... | Metalsmith plugin to extend `metalsmith-layouts` to
allow nested layouts using the `handlebars` engine
@param {Object} options (optional)
@property {String} directory (optional)
@property {String} generated (optional)
@property {String} pattern (optional)
@property {String} default (optional)
@return {Function} | [
"Metalsmith",
"plugin",
"to",
"extend",
"metalsmith",
"-",
"layouts",
"to",
"allow",
"nested",
"layouts",
"using",
"the",
"handlebars",
"engine"
] | 925bbe0a4f078da1ea791504abd58808621d89d4 | https://github.com/firesideguru/metalsmith-nested/blob/925bbe0a4f078da1ea791504abd58808621d89d4/lib/index.js#L37-L208 | train |
firesideguru/metalsmith-nested | lib/index.js | check | function check(files, file, pattern, def) {
let data = files[file];
// Only process utf8 encoded files (so no binary)
if (!utf8(data.contents)) {
return false;
}
// Only process files that match the pattern (if there is a pattern)
if (pattern && !match(file, pattern)[0]) {
... | javascript | function check(files, file, pattern, def) {
let data = files[file];
// Only process utf8 encoded files (so no binary)
if (!utf8(data.contents)) {
return false;
}
// Only process files that match the pattern (if there is a pattern)
if (pattern && !match(file, pattern)[0]) {
... | [
"function",
"check",
"(",
"files",
",",
"file",
",",
"pattern",
",",
"def",
")",
"{",
"let",
"data",
"=",
"files",
"[",
"file",
"]",
";",
"// Only process utf8 encoded files (so no binary)",
"if",
"(",
"!",
"utf8",
"(",
"data",
".",
"contents",
")",
")",
... | Test if file has layout front-matter or matches pattern with default layout
Code source:
https://github.com/superwolff/metalsmith-layouts/blob/master/lib/helpers/check.js
@param {Object} files
@param {String} file
@param {String} pattern
@param {String} default
@return {Boolean} | [
"Test",
"if",
"file",
"has",
"layout",
"front",
"-",
"matter",
"or",
"matches",
"pattern",
"with",
"default",
"layout"
] | 925bbe0a4f078da1ea791504abd58808621d89d4 | https://github.com/firesideguru/metalsmith-nested/blob/925bbe0a4f078da1ea791504abd58808621d89d4/lib/index.js#L76-L92 | train |
firesideguru/metalsmith-nested | lib/index.js | resolveTemplate | function resolveTemplate (tfiles, tfile, resolved, temp = '') {
// If parent layout was called by a page directly (vs. through a child layout)
// inject already resolved content with child `temp`
if (resolved[tfile]) {
return injectContent(resolved[tfile], temp);
}
// Process layout ... | javascript | function resolveTemplate (tfiles, tfile, resolved, temp = '') {
// If parent layout was called by a page directly (vs. through a child layout)
// inject already resolved content with child `temp`
if (resolved[tfile]) {
return injectContent(resolved[tfile], temp);
}
// Process layout ... | [
"function",
"resolveTemplate",
"(",
"tfiles",
",",
"tfile",
",",
"resolved",
",",
"temp",
"=",
"''",
")",
"{",
"// If parent layout was called by a page directly (vs. through a child layout)",
"// inject already resolved content with child `temp`",
"if",
"(",
"resolved",
"[",
... | Recursively look up specified `layout` in front-matter and combine
contents with previous results on `temp` via `injectContent` method
@param {Object} tfiles
@param {String} tfile
@param {Object} resolved
@param {String} temp
@return {String} | [
"Recursively",
"look",
"up",
"specified",
"layout",
"in",
"front",
"-",
"matter",
"and",
"combine",
"contents",
"with",
"previous",
"results",
"on",
"temp",
"via",
"injectContent",
"method"
] | 925bbe0a4f078da1ea791504abd58808621d89d4 | https://github.com/firesideguru/metalsmith-nested/blob/925bbe0a4f078da1ea791504abd58808621d89d4/lib/index.js#L105-L128 | train |
rtm/upward | src/Str.js | dasherize | function dasherize(str) {
return str.replace(
/([a-z])([A-Z])/g,
(_, let1, let2) => `${let1}-${let2.toLowerCase()}`
);
} | javascript | function dasherize(str) {
return str.replace(
/([a-z])([A-Z])/g,
(_, let1, let2) => `${let1}-${let2.toLowerCase()}`
);
} | [
"function",
"dasherize",
"(",
"str",
")",
"{",
"return",
"str",
".",
"replace",
"(",
"/",
"([a-z])([A-Z])",
"/",
"g",
",",
"(",
"_",
",",
"let1",
",",
"let2",
")",
"=>",
"`",
"${",
"let1",
"}",
"${",
"let2",
".",
"toLowerCase",
"(",
")",
"}",
"`"... | `myClass` => `my-class` | [
"myClass",
"=",
">",
"my",
"-",
"class"
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Str.js#L14-L19 | train |
ev3-js/ev3-client | lib/actions.js | write | function write (type, port) {
return createAction(WRITE, writeCommand)
/**
* function that returns a write actions
* @private
* @param {string} command
* @param {object} opts move object
* @return {object} write action object
*/
function writeCommand (command, opts) {
return {
... | javascript | function write (type, port) {
return createAction(WRITE, writeCommand)
/**
* function that returns a write actions
* @private
* @param {string} command
* @param {object} opts move object
* @return {object} write action object
*/
function writeCommand (command, opts) {
return {
... | [
"function",
"write",
"(",
"type",
",",
"port",
")",
"{",
"return",
"createAction",
"(",
"WRITE",
",",
"writeCommand",
")",
"/**\n * function that returns a write actions\n * @private\n * @param {string} command\n * @param {object} opts move object\n * @return {object} ... | curried function to return a write action creator
@private
@param {string} type The type of write command
@param {string|array} port The port or ports that write action corresponds to
@return {function} {@link writeCommand} | [
"curried",
"function",
"to",
"return",
"a",
"write",
"action",
"creator"
] | e63dad977a77b6d2ecc7b81ebf288cc595d76771 | https://github.com/ev3-js/ev3-client/blob/e63dad977a77b6d2ecc7b81ebf288cc595d76771/lib/actions.js#L76-L94 | train |
ev3-js/ev3-client | lib/actions.js | writeCommand | function writeCommand (command, opts) {
return {
type: type,
command: command,
opts: opts,
port: port
}
} | javascript | function writeCommand (command, opts) {
return {
type: type,
command: command,
opts: opts,
port: port
}
} | [
"function",
"writeCommand",
"(",
"command",
",",
"opts",
")",
"{",
"return",
"{",
"type",
":",
"type",
",",
"command",
":",
"command",
",",
"opts",
":",
"opts",
",",
"port",
":",
"port",
"}",
"}"
] | function that returns a write actions
@private
@param {string} command
@param {object} opts move object
@return {object} write action object | [
"function",
"that",
"returns",
"a",
"write",
"actions"
] | e63dad977a77b6d2ecc7b81ebf288cc595d76771 | https://github.com/ev3-js/ev3-client/blob/e63dad977a77b6d2ecc7b81ebf288cc595d76771/lib/actions.js#L86-L93 | train |
smravi/docco-plus | Gruntfile.js | function(filepath) {
// Construct the destination file path.
var dest = path.join(
grunt.config('copy.coverage.dest'),
path.relative(process.cwd(), filepath)
);
// Retu... | javascript | function(filepath) {
// Construct the destination file path.
var dest = path.join(
grunt.config('copy.coverage.dest'),
path.relative(process.cwd(), filepath)
);
// Retu... | [
"function",
"(",
"filepath",
")",
"{",
"// Construct the destination file path.",
"var",
"dest",
"=",
"path",
".",
"join",
"(",
"grunt",
".",
"config",
"(",
"'copy.coverage.dest'",
")",
",",
"path",
".",
"relative",
"(",
"process",
".",
"cwd",
"(",
")",
",",... | Copy if file does not exist. | [
"Copy",
"if",
"file",
"does",
"not",
"exist",
"."
] | 16a7b3fe3a5c591ed685ff2d853a0a7ad7ed63fb | https://github.com/smravi/docco-plus/blob/16a7b3fe3a5c591ed685ff2d853a0a7ad7ed63fb/Gruntfile.js#L56-L64 | train | |
woaiso/auto-upgrade-npm-version | lib.js | getPackageVersion | function getPackageVersion() {
var packageJson = path.join(process.cwd(), 'package.json'),
version;
try {
version = require(packageJson).version;
} catch (unused) {
throw new Error('Could not load package.json, please make sure it exists');
}
if (!semver.valid(version)) {
throw new Error('Inva... | javascript | function getPackageVersion() {
var packageJson = path.join(process.cwd(), 'package.json'),
version;
try {
version = require(packageJson).version;
} catch (unused) {
throw new Error('Could not load package.json, please make sure it exists');
}
if (!semver.valid(version)) {
throw new Error('Inva... | [
"function",
"getPackageVersion",
"(",
")",
"{",
"var",
"packageJson",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"'package.json'",
")",
",",
"version",
";",
"try",
"{",
"version",
"=",
"require",
"(",
"packageJson",
")",
".",
... | Get the current version from the package.json
@method getPackageVersion
@return {String} MAJOR.MINOR version | [
"Get",
"the",
"current",
"version",
"from",
"the",
"package",
".",
"json"
] | 5bce6e238d8952b03cc30962285b2b91d0fde228 | https://github.com/woaiso/auto-upgrade-npm-version/blob/5bce6e238d8952b03cc30962285b2b91d0fde228/lib.js#L13-L26 | train |
woaiso/auto-upgrade-npm-version | lib.js | writePackageVersion | function writePackageVersion(newVersion) {
var packageJson = path.join(process.cwd(), 'package.json'),
raw = require(packageJson);
raw.version = newVersion;
fs.writeFileSync(packageJson, JSON.stringify(raw, null, 2));
} | javascript | function writePackageVersion(newVersion) {
var packageJson = path.join(process.cwd(), 'package.json'),
raw = require(packageJson);
raw.version = newVersion;
fs.writeFileSync(packageJson, JSON.stringify(raw, null, 2));
} | [
"function",
"writePackageVersion",
"(",
"newVersion",
")",
"{",
"var",
"packageJson",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"'package.json'",
")",
",",
"raw",
"=",
"require",
"(",
"packageJson",
")",
";",
"raw",
".",
"versi... | Updates the package.json with the new version number
@method writePackageVersion
@param {String} newVersion New version string MAJOR.MINOR.PATCH | [
"Updates",
"the",
"package",
".",
"json",
"with",
"the",
"new",
"version",
"number"
] | 5bce6e238d8952b03cc30962285b2b91d0fde228 | https://github.com/woaiso/auto-upgrade-npm-version/blob/5bce6e238d8952b03cc30962285b2b91d0fde228/lib.js#L44-L51 | train |
desmondmorris/node-mta | lib/utils.js | function (obj) {
var ret = {};
if( Object.prototype.toString.call(obj) === '[object Object]' ) {
for (var key in obj) {
ret[key] = arrayClean(obj[key]);
}
}
else if( Object.prototype.toString.call(obj) === '[object Array]' ) {
if (obj.length === 1) {
ret = arrayClean(obj[0]);
}
... | javascript | function (obj) {
var ret = {};
if( Object.prototype.toString.call(obj) === '[object Object]' ) {
for (var key in obj) {
ret[key] = arrayClean(obj[key]);
}
}
else if( Object.prototype.toString.call(obj) === '[object Array]' ) {
if (obj.length === 1) {
ret = arrayClean(obj[0]);
}
... | [
"function",
"(",
"obj",
")",
"{",
"var",
"ret",
"=",
"{",
"}",
";",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"obj",
")",
"===",
"'[object Object]'",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"ret"... | Recursively removes extraneous nested arrays from objects
@param {Object|Array|String|Integer} obj
@return {Object} | [
"Recursively",
"removes",
"extraneous",
"nested",
"arrays",
"from",
"objects"
] | e87b57b4518b603a5f17ff4aecf0694d37c45b71 | https://github.com/desmondmorris/node-mta/blob/e87b57b4518b603a5f17ff4aecf0694d37c45b71/lib/utils.js#L29-L52 | train | |
areslabs/babel-plugin-import-css | src/util.js | queryImport | function queryImport(styles) {
if (styles.indexOf('@import') < 0) return []
const arr = []
const ast = csstree.parse(styles);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Atrule' && node.name === 'import') {
const pat = node.prelude.children.head.da... | javascript | function queryImport(styles) {
if (styles.indexOf('@import') < 0) return []
const arr = []
const ast = csstree.parse(styles);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Atrule' && node.name === 'import') {
const pat = node.prelude.children.head.da... | [
"function",
"queryImport",
"(",
"styles",
")",
"{",
"if",
"(",
"styles",
".",
"indexOf",
"(",
"'@import'",
")",
"<",
"0",
")",
"return",
"[",
"]",
"const",
"arr",
"=",
"[",
"]",
"const",
"ast",
"=",
"csstree",
".",
"parse",
"(",
"styles",
")",
";",... | get import content in css file,may import multi times
@param styles css file content
@returns {Array} result | [
"get",
"import",
"content",
"in",
"css",
"file",
"may",
"import",
"multi",
"times"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L11-L24 | train |
areslabs/babel-plugin-import-css | src/util.js | handleImportStyle | function handleImportStyle(styles, initPath, mayRM) {
if (!!mayRM) {
styles = styles.replace(mayRM, '')
}
if (styles.indexOf('@import') < 0) return styles
const ast = csstree.parse(styles);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Atrule') {
... | javascript | function handleImportStyle(styles, initPath, mayRM) {
if (!!mayRM) {
styles = styles.replace(mayRM, '')
}
if (styles.indexOf('@import') < 0) return styles
const ast = csstree.parse(styles);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Atrule') {
... | [
"function",
"handleImportStyle",
"(",
"styles",
",",
"initPath",
",",
"mayRM",
")",
"{",
"if",
"(",
"!",
"!",
"mayRM",
")",
"{",
"styles",
"=",
"styles",
".",
"replace",
"(",
"mayRM",
",",
"''",
")",
"}",
"if",
"(",
"styles",
".",
"indexOf",
"(",
"... | handle with import procedure,may search involved file in project
@param styles styles css file content
@param initPath project path, used for searching target file
@param mayRM this param avoid loop importing
@returns handled styles content | [
"handle",
"with",
"import",
"procedure",
"may",
"search",
"involved",
"file",
"in",
"project"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L33-L58 | train |
areslabs/babel-plugin-import-css | src/util.js | createStylefromCode | function createStylefromCode(styles, abspath) {
//may import other file
const arr = queryImport(styles)
const baseRes = handleImportStyle(styles, abspath)
const obj = {}
const ast = csstree.parse(baseRes);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Rule' ... | javascript | function createStylefromCode(styles, abspath) {
//may import other file
const arr = queryImport(styles)
const baseRes = handleImportStyle(styles, abspath)
const obj = {}
const ast = csstree.parse(baseRes);
csstree.walk(ast, {
enter: function (node) {
if (node.type === 'Rule' ... | [
"function",
"createStylefromCode",
"(",
"styles",
",",
"abspath",
")",
"{",
"//may import other file",
"const",
"arr",
"=",
"queryImport",
"(",
"styles",
")",
"const",
"baseRes",
"=",
"handleImportStyle",
"(",
"styles",
",",
"abspath",
")",
"const",
"obj",
"=",
... | create style object from css file content,which is raw string.
@param styles styles styles css file content
@param abspath project file path
@returns {{styles, imports: Array}} | [
"create",
"style",
"object",
"from",
"css",
"file",
"content",
"which",
"is",
"raw",
"string",
"."
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L66-L109 | train |
areslabs/babel-plugin-import-css | src/util.js | createStyleDictionary | function createStyleDictionary(styles) {
let total = {}
for (let k in styles) {
const val = styles[k]
//sort clz name to judge arbitrary order in multi-className
k = sortSeq(k)
//merge style chain from last condition
const lastEle = getLastEle(k)
//no sharing data... | javascript | function createStyleDictionary(styles) {
let total = {}
for (let k in styles) {
const val = styles[k]
//sort clz name to judge arbitrary order in multi-className
k = sortSeq(k)
//merge style chain from last condition
const lastEle = getLastEle(k)
//no sharing data... | [
"function",
"createStyleDictionary",
"(",
"styles",
")",
"{",
"let",
"total",
"=",
"{",
"}",
"for",
"(",
"let",
"k",
"in",
"styles",
")",
"{",
"const",
"val",
"=",
"styles",
"[",
"k",
"]",
"//sort clz name to judge arbitrary order in multi-className",
"k",
"="... | create special style dict structure for high performance query
@param styles style object | [
"create",
"special",
"style",
"dict",
"structure",
"for",
"high",
"performance",
"query"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L115-L132 | train |
areslabs/babel-plugin-import-css | src/util.js | selectorBlockHandler | function selectorBlockHandler(element) {
if (element.type === 'Selector') {
const name = []
let discard = false
element.children.forEach(e => {
switch (e.type) {
case "ClassSelector":
name.push("." + e.name);
break;
... | javascript | function selectorBlockHandler(element) {
if (element.type === 'Selector') {
const name = []
let discard = false
element.children.forEach(e => {
switch (e.type) {
case "ClassSelector":
name.push("." + e.name);
break;
... | [
"function",
"selectorBlockHandler",
"(",
"element",
")",
"{",
"if",
"(",
"element",
".",
"type",
"===",
"'Selector'",
")",
"{",
"const",
"name",
"=",
"[",
"]",
"let",
"discard",
"=",
"false",
"element",
".",
"children",
".",
"forEach",
"(",
"e",
"=>",
... | handle with selector part in node's structure
@param element node to be searched
@return {*} | [
"handle",
"with",
"selector",
"part",
"in",
"node",
"s",
"structure"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L240-L276 | train |
areslabs/babel-plugin-import-css | src/util.js | paddingElementForTransform | function paddingElementForTransform(proper, arr) {
//RN not support multi font-family keywords
if (proper === 'font-family') {
return [proper, arr.pop()]
}
//not support such shorthand
if (proper === 'background') {
return ['background-color', arr.join(" ")]
}
//not support s... | javascript | function paddingElementForTransform(proper, arr) {
//RN not support multi font-family keywords
if (proper === 'font-family') {
return [proper, arr.pop()]
}
//not support such shorthand
if (proper === 'background') {
return ['background-color', arr.join(" ")]
}
//not support s... | [
"function",
"paddingElementForTransform",
"(",
"proper",
",",
"arr",
")",
"{",
"//RN not support multi font-family keywords",
"if",
"(",
"proper",
"===",
"'font-family'",
")",
"{",
"return",
"[",
"proper",
",",
"arr",
".",
"pop",
"(",
")",
"]",
"}",
"//not suppo... | do some padding modification,to produce more stable run-time environment
@param proper
@param arr
@return {*} | [
"do",
"some",
"padding",
"modification",
"to",
"produce",
"more",
"stable",
"run",
"-",
"time",
"environment"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L284-L302 | train |
areslabs/babel-plugin-import-css | src/util.js | styleBlockHandler | function styleBlockHandler(element) {
const {property, value} = element
let result = []
const styleContent = value && value.children ? value.children : []
const defaultUnit = "px"
styleContent.forEach(e => {
switch (e.type) {
case "Identifier":
result.push(e.name)... | javascript | function styleBlockHandler(element) {
const {property, value} = element
let result = []
const styleContent = value && value.children ? value.children : []
const defaultUnit = "px"
styleContent.forEach(e => {
switch (e.type) {
case "Identifier":
result.push(e.name)... | [
"function",
"styleBlockHandler",
"(",
"element",
")",
"{",
"const",
"{",
"property",
",",
"value",
"}",
"=",
"element",
"let",
"result",
"=",
"[",
"]",
"const",
"styleContent",
"=",
"value",
"&&",
"value",
".",
"children",
"?",
"value",
".",
"children",
... | handle with different node structure in ast
@param element
@return {*} | [
"handle",
"with",
"different",
"node",
"structure",
"in",
"ast"
] | b90d3a4ec3a644edcaa1c803314e2c39de1d29c9 | https://github.com/areslabs/babel-plugin-import-css/blob/b90d3a4ec3a644edcaa1c803314e2c39de1d29c9/src/util.js#L318-L373 | train |
poynt/traildb-node | lib/traildb.js | function (uuid) {
uuid = ref.reinterpret(uuid, 16).toString('hex');
return [
uuid.slice(0, 8),
uuid.slice(8, 12),
uuid.slice(12, 16),
uuid.slice(16, 20),
uuid.slice(20, 32)
].join('-');
} | javascript | function (uuid) {
uuid = ref.reinterpret(uuid, 16).toString('hex');
return [
uuid.slice(0, 8),
uuid.slice(8, 12),
uuid.slice(12, 16),
uuid.slice(16, 20),
uuid.slice(20, 32)
].join('-');
} | [
"function",
"(",
"uuid",
")",
"{",
"uuid",
"=",
"ref",
".",
"reinterpret",
"(",
"uuid",
",",
"16",
")",
".",
"toString",
"(",
"'hex'",
")",
";",
"return",
"[",
"uuid",
".",
"slice",
"(",
"0",
",",
"8",
")",
",",
"uuid",
".",
"slice",
"(",
"8",
... | Returns a UUID hex string.
@param {Array[Byte]} uuid - UUID buffer.
@return {String} uuid - UUID string. | [
"Returns",
"a",
"UUID",
"hex",
"string",
"."
] | c174ae3e417877eeeae6e0e1af013a7182f6c65a | https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L169-L178 | train | |
poynt/traildb-node | lib/traildb.js | function (trail, options) {
this.trail = trail;
this.options = options || {};
this.cursor = lib.tdb_cursor_new(this.trail.tdb._db);
/*\
|*| Filter logic
\*/
if (typeof this.options.filter != 'undefined') {
const err = lib.tdb_cursor_set_event_filter(this.cursor, this.options.filter);
if (err) {
... | javascript | function (trail, options) {
this.trail = trail;
this.options = options || {};
this.cursor = lib.tdb_cursor_new(this.trail.tdb._db);
/*\
|*| Filter logic
\*/
if (typeof this.options.filter != 'undefined') {
const err = lib.tdb_cursor_set_event_filter(this.cursor, this.options.filter);
if (err) {
... | [
"function",
"(",
"trail",
",",
"options",
")",
"{",
"this",
".",
"trail",
"=",
"trail",
";",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"cursor",
"=",
"lib",
".",
"tdb_cursor_new",
"(",
"this",
".",
"trail",
".",
"tdb... | Initialize a new EventsIterator. Iterate over all events in a trail..
@param {TrailDB} tdb - TrailDB object.
@param {Boolean,Object}
options.toMap - Whether the iterator should return a map for each event,
grabbing the appropriate key names. Defaults to a list with
just values.
options.filter - T_TDB_FILTER event filte... | [
"Initialize",
"a",
"new",
"EventsIterator",
".",
"Iterate",
"over",
"all",
"events",
"in",
"a",
"trail",
".."
] | c174ae3e417877eeeae6e0e1af013a7182f6c65a | https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L244-L263 | train | |
poynt/traildb-node | lib/traildb.js | function (options) {
if (!options.path) {
throw new TrailDBError('Path is required');
}
if (!options.fieldNames || !options.fieldNames.length) {
throw new TrailDBError('Field names are required');
}
if (options.path.slice(-4) === '.tdb') {
options.path = options.path.slice(0, -4);
}
this._co... | javascript | function (options) {
if (!options.path) {
throw new TrailDBError('Path is required');
}
if (!options.fieldNames || !options.fieldNames.length) {
throw new TrailDBError('Field names are required');
}
if (options.path.slice(-4) === '.tdb') {
options.path = options.path.slice(0, -4);
}
this._co... | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
".",
"path",
")",
"{",
"throw",
"new",
"TrailDBError",
"(",
"'Path is required'",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"fieldNames",
"||",
"!",
"options",
".",
"fieldNames",
"."... | TrailDBConstructor class Construct a new TrailDB.
Initialize a new TrailDBConstructor.
@param {String} options.path - TrailDB output path (without .tdb).
@param {Array[String]} options.fieldNames - Array of field names in this TrailDB.
@return {Object} cons - TrailDB constructor object. | [
"TrailDBConstructor",
"class",
"Construct",
"a",
"new",
"TrailDB",
".",
"Initialize",
"a",
"new",
"TrailDBConstructor",
"."
] | c174ae3e417877eeeae6e0e1af013a7182f6c65a | https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L324-L359 | train | |
poynt/traildb-node | lib/traildb.js | function (options) {
this._db = lib.tdb_init();
const r = lib.tdb_open(this._db, ref.allocCString(options.path));
if (r !== 0) {
throw new TrailDBError('Could not open TrailDB: ' + r);
}
this.numTrails = lib.tdb_num_trails(this._db);
this.numEvents = lib.tdb_num_events(this._db);
this.numFields = li... | javascript | function (options) {
this._db = lib.tdb_init();
const r = lib.tdb_open(this._db, ref.allocCString(options.path));
if (r !== 0) {
throw new TrailDBError('Could not open TrailDB: ' + r);
}
this.numTrails = lib.tdb_num_trails(this._db);
this.numEvents = lib.tdb_num_events(this._db);
this.numFields = li... | [
"function",
"(",
"options",
")",
"{",
"this",
".",
"_db",
"=",
"lib",
".",
"tdb_init",
"(",
")",
";",
"const",
"r",
"=",
"lib",
".",
"tdb_open",
"(",
"this",
".",
"_db",
",",
"ref",
".",
"allocCString",
"(",
"options",
".",
"path",
")",
")",
";",... | TrailDB class Query a TrailDB.
Opens a TrailDB at path.
@param {String} options.path - TrailDB output path (without .tdb).
@return {Object} tdb - TrailDB object. | [
"TrailDB",
"class",
"Query",
"a",
"TrailDB",
".",
"Opens",
"a",
"TrailDB",
"at",
"path",
"."
] | c174ae3e417877eeeae6e0e1af013a7182f6c65a | https://github.com/poynt/traildb-node/blob/c174ae3e417877eeeae6e0e1af013a7182f6c65a/lib/traildb.js#L470-L490 | train | |
deanlandolt/bytewise-core | util.js | encodeBound | function encodeBound(data, base) {
var prefix = data.prefix
var buffer = prefix ? base.encode(prefix, null) : new Buffer([ data.byte ])
if (data.upper)
buffer = Buffer.concat([ buffer, new Buffer([ 0xff ]) ])
return util.encodedBound(data, buffer)
} | javascript | function encodeBound(data, base) {
var prefix = data.prefix
var buffer = prefix ? base.encode(prefix, null) : new Buffer([ data.byte ])
if (data.upper)
buffer = Buffer.concat([ buffer, new Buffer([ 0xff ]) ])
return util.encodedBound(data, buffer)
} | [
"function",
"encodeBound",
"(",
"data",
",",
"base",
")",
"{",
"var",
"prefix",
"=",
"data",
".",
"prefix",
"var",
"buffer",
"=",
"prefix",
"?",
"base",
".",
"encode",
"(",
"prefix",
",",
"null",
")",
":",
"new",
"Buffer",
"(",
"[",
"data",
".",
"b... | helpers for encoding boundary types | [
"helpers",
"for",
"encoding",
"boundary",
"types"
] | 293f2eb2623903baf0fc02fd81a770f06d62c8de | https://github.com/deanlandolt/bytewise-core/blob/293f2eb2623903baf0fc02fd81a770f06d62c8de/util.js#L286-L294 | train |
zackurben/event-chain | lib/index.js | function(required, cb) {
var chain = new Chain(config);
chain.on(required, cb);
return chain;
} | javascript | function(required, cb) {
var chain = new Chain(config);
chain.on(required, cb);
return chain;
} | [
"function",
"(",
"required",
",",
"cb",
")",
"{",
"var",
"chain",
"=",
"new",
"Chain",
"(",
"config",
")",
";",
"chain",
".",
"on",
"(",
"required",
",",
"cb",
")",
";",
"return",
"chain",
";",
"}"
] | EventChain factory.
@param required
The list of events that are required before invoking the callback function.
@param cb
The callback to invoke after all required events have been fired.
@returns {Chain|exports|module.exports} | [
"EventChain",
"factory",
"."
] | d6b12f569afb58cb6b01e85dbb7dbf320583ed7b | https://github.com/zackurben/event-chain/blob/d6b12f569afb58cb6b01e85dbb7dbf320583ed7b/lib/index.js#L23-L27 | train | |
alexindigo/batcher | lib/command_factory.js | commandFactory | function commandFactory(combos, cmd)
{
var command;
// if no combos provided
// consider it as a single command run
if (!cmd)
{
cmd = combos;
combos = [{}];
}
command = partial(iterate, combos, cmd);
command.commandDescription = partial(commandDescription, cmd);
return command;
} | javascript | function commandFactory(combos, cmd)
{
var command;
// if no combos provided
// consider it as a single command run
if (!cmd)
{
cmd = combos;
combos = [{}];
}
command = partial(iterate, combos, cmd);
command.commandDescription = partial(commandDescription, cmd);
return command;
} | [
"function",
"commandFactory",
"(",
"combos",
",",
"cmd",
")",
"{",
"var",
"command",
";",
"// if no combos provided",
"// consider it as a single command run",
"if",
"(",
"!",
"cmd",
")",
"{",
"cmd",
"=",
"combos",
";",
"combos",
"=",
"[",
"{",
"}",
"]",
";"... | Creates command executor from state property
@param {array|string} [combos] – list of combinations
@param {string} cmd - state property to get command from
@returns {function} function that executes the command | [
"Creates",
"command",
"executor",
"from",
"state",
"property"
] | 73d9c8c994f915688db0627ea3b4854ead771138 | https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L23-L38 | train |
alexindigo/batcher | lib/command_factory.js | forEachFactory | function forEachFactory(properties)
{
// expand object's combinations into an array of objects
if (typeOf(properties) == 'object')
{
properties = cartesian(clone(properties));
}
return {command: partial(commandFactory, properties)};
} | javascript | function forEachFactory(properties)
{
// expand object's combinations into an array of objects
if (typeOf(properties) == 'object')
{
properties = cartesian(clone(properties));
}
return {command: partial(commandFactory, properties)};
} | [
"function",
"forEachFactory",
"(",
"properties",
")",
"{",
"// expand object's combinations into an array of objects",
"if",
"(",
"typeOf",
"(",
"properties",
")",
"==",
"'object'",
")",
"{",
"properties",
"=",
"cartesian",
"(",
"clone",
"(",
"properties",
")",
")",... | Constructs set of commands for each property of the passed object
with loops over passed arrays
@param {object|array|string} properties - list of properties to run a command with
@returns {object} run command factory | [
"Constructs",
"set",
"of",
"commands",
"for",
"each",
"property",
"of",
"the",
"passed",
"object",
"with",
"loops",
"over",
"passed",
"arrays"
] | 73d9c8c994f915688db0627ea3b4854ead771138 | https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L47-L56 | train |
alexindigo/batcher | lib/command_factory.js | valueFactory | function valueFactory(value)
{
function command(cb)
{
cb(null, value);
}
command.commandDescription = partial(commandDescription, 'VALUE SETTER');
return command;
} | javascript | function valueFactory(value)
{
function command(cb)
{
cb(null, value);
}
command.commandDescription = partial(commandDescription, 'VALUE SETTER');
return command;
} | [
"function",
"valueFactory",
"(",
"value",
")",
"{",
"function",
"command",
"(",
"cb",
")",
"{",
"cb",
"(",
"null",
",",
"value",
")",
";",
"}",
"command",
".",
"commandDescription",
"=",
"partial",
"(",
"commandDescription",
",",
"'VALUE SETTER'",
")",
";"... | Creates function that returns provided value
@param {mixed} value - value to return during execution time
@returns {function} function that executes the command | [
"Creates",
"function",
"that",
"returns",
"provided",
"value"
] | 73d9c8c994f915688db0627ea3b4854ead771138 | https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L64-L72 | train |
alexindigo/batcher | lib/command_factory.js | commandDescription | function commandDescription(desc, state)
{
desc = state[desc] || desc;
return desc.join ? '[' + desc.join(', ') + ']' : desc.toString();
} | javascript | function commandDescription(desc, state)
{
desc = state[desc] || desc;
return desc.join ? '[' + desc.join(', ') + ']' : desc.toString();
} | [
"function",
"commandDescription",
"(",
"desc",
",",
"state",
")",
"{",
"desc",
"=",
"state",
"[",
"desc",
"]",
"||",
"desc",
";",
"return",
"desc",
".",
"join",
"?",
"'['",
"+",
"desc",
".",
"join",
"(",
"', '",
")",
"+",
"']'",
":",
"desc",
".",
... | Provides command description, finds matching within state object
or uses provided one as is
@private
@param {string} desc - command's description or property
to fetch command from current state
@param {object} state - current state
@returns {string} - command's description | [
"Provides",
"command",
"description",
"finds",
"matching",
"within",
"state",
"object",
"or",
"uses",
"provided",
"one",
"as",
"is"
] | 73d9c8c994f915688db0627ea3b4854ead771138 | https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L84-L88 | train |
alexindigo/batcher | lib/command_factory.js | iterate | function iterate(accumulator, combos, cmd, callback)
{
var params;
// initial call might not have accumulator
if (arguments.length == 3)
{
callback = cmd;
cmd = combos;
combos = accumulator;
accumulator = [];
}
// resolve params from combo reference
if (typeof combos == '... | javascript | function iterate(accumulator, combos, cmd, callback)
{
var params;
// initial call might not have accumulator
if (arguments.length == 3)
{
callback = cmd;
cmd = combos;
combos = accumulator;
accumulator = [];
}
// resolve params from combo reference
if (typeof combos == '... | [
"function",
"iterate",
"(",
"accumulator",
",",
"combos",
",",
"cmd",
",",
"callback",
")",
"{",
"var",
"params",
";",
"// initial call might not have accumulator",
"if",
"(",
"arguments",
".",
"length",
"==",
"3",
")",
"{",
"callback",
"=",
"cmd",
";",
"cmd... | Runs provided command with each of the combinations
@private
@param {array} [accumulator] – accumulates commands output
@param {array|string} combos – list of combinations
@param {string|array} cmd - command to run
@param {function} callback - invoked after commands finished executing
@returns {void} | [
"Runs",
"provided",
"command",
"with",
"each",
"of",
"the",
"combinations"
] | 73d9c8c994f915688db0627ea3b4854ead771138 | https://github.com/alexindigo/batcher/blob/73d9c8c994f915688db0627ea3b4854ead771138/lib/command_factory.js#L100-L167 | train |
rtm/upward | src/Ass.js | keepAssigned | function keepAssigned(...objs) {
var ka = create(keepAssignedPrototype);
defineProperty(ka, 'objs', { value: [] }); // first-come first-served
[...objs].forEach(o => _keepAssigned(ka, o));
return ka;
} | javascript | function keepAssigned(...objs) {
var ka = create(keepAssignedPrototype);
defineProperty(ka, 'objs', { value: [] }); // first-come first-served
[...objs].forEach(o => _keepAssigned(ka, o));
return ka;
} | [
"function",
"keepAssigned",
"(",
"...",
"objs",
")",
"{",
"var",
"ka",
"=",
"create",
"(",
"keepAssignedPrototype",
")",
";",
"defineProperty",
"(",
"ka",
",",
"'objs'",
",",
"{",
"value",
":",
"[",
"]",
"}",
")",
";",
"// first-come first-served",
"[",
... | Create the `keepAssigned` object. | [
"Create",
"the",
"keepAssigned",
"object",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L20-L25 | train |
rtm/upward | src/Ass.js | findFirstProp | function findFirstProp(objs, p) {
for (let obj of objs) {
if (obj && obj.hasOwnProperty(p)) { return valueize(obj[p]); }
}
} | javascript | function findFirstProp(objs, p) {
for (let obj of objs) {
if (obj && obj.hasOwnProperty(p)) { return valueize(obj[p]); }
}
} | [
"function",
"findFirstProp",
"(",
"objs",
",",
"p",
")",
"{",
"for",
"(",
"let",
"obj",
"of",
"objs",
")",
"{",
"if",
"(",
"obj",
"&&",
"obj",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"return",
"valueize",
"(",
"obj",
"[",
"p",
"]",
")",
... | Return property's value from the first object in which it appears. | [
"Return",
"property",
"s",
"value",
"from",
"the",
"first",
"object",
"in",
"which",
"it",
"appears",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L28-L32 | train |
rtm/upward | src/Ass.js | calcProp | function calcProp(ka, p) {
var val = ka[p];
if (isKeepAssigned(val)) {
recalc(val);
} else {
val.val = findFirstProp(ka.objs, p);
}
} | javascript | function calcProp(ka, p) {
var val = ka[p];
if (isKeepAssigned(val)) {
recalc(val);
} else {
val.val = findFirstProp(ka.objs, p);
}
} | [
"function",
"calcProp",
"(",
"ka",
",",
"p",
")",
"{",
"var",
"val",
"=",
"ka",
"[",
"p",
"]",
";",
"if",
"(",
"isKeepAssigned",
"(",
"val",
")",
")",
"{",
"recalc",
"(",
"val",
")",
";",
"}",
"else",
"{",
"val",
".",
"val",
"=",
"findFirstProp... | Calculate value for a property, recursively. | [
"Calculate",
"value",
"for",
"a",
"property",
"recursively",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L35-L42 | train |
rtm/upward | src/Ass.js | placeKey | function placeKey(ka, v, k, pusher) {
if (isObject(v)) {
if (k in ka) {
_keepAssigned(ka[k], v, pusher);
} else {
ka[k] = subKeepAssigned(ka.objs, k, pusher);
}
} else {
if (k in ka) {
ka[k].val = calcProp(ka, k);
} else {
defineProperty(ka, k, {
get() { return U(... | javascript | function placeKey(ka, v, k, pusher) {
if (isObject(v)) {
if (k in ka) {
_keepAssigned(ka[k], v, pusher);
} else {
ka[k] = subKeepAssigned(ka.objs, k, pusher);
}
} else {
if (k in ka) {
ka[k].val = calcProp(ka, k);
} else {
defineProperty(ka, k, {
get() { return U(... | [
"function",
"placeKey",
"(",
"ka",
",",
"v",
",",
"k",
",",
"pusher",
")",
"{",
"if",
"(",
"isObject",
"(",
"v",
")",
")",
"{",
"if",
"(",
"k",
"in",
"ka",
")",
"{",
"_keepAssigned",
"(",
"ka",
"[",
"k",
"]",
",",
"v",
",",
"pusher",
")",
"... | Place a key in the kept object. | [
"Place",
"a",
"key",
"in",
"the",
"kept",
"object",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L45-L63 | train |
rtm/upward | src/Ass.js | recalc | function recalc(ka) {
for (let [key, val] of objectPairs(ka)) {
if (isKeepAssigned(val)) { recalc(val); }
else { val.val = getter(key); }
}
} | javascript | function recalc(ka) {
for (let [key, val] of objectPairs(ka)) {
if (isKeepAssigned(val)) { recalc(val); }
else { val.val = getter(key); }
}
} | [
"function",
"recalc",
"(",
"ka",
")",
"{",
"for",
"(",
"let",
"[",
"key",
",",
"val",
"]",
"of",
"objectPairs",
"(",
"ka",
")",
")",
"{",
"if",
"(",
"isKeepAssigned",
"(",
"val",
")",
")",
"{",
"recalc",
"(",
"val",
")",
";",
"}",
"else",
"{",
... | Recalculate values for all keys, as when an object changes. | [
"Recalculate",
"values",
"for",
"all",
"keys",
"as",
"when",
"an",
"object",
"changes",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L66-L71 | train |
rtm/upward | src/Ass.js | subKeepAssigned | function subKeepAssigned(objs, k, pusher) {
var ka = keepAssigned();
objs
.map(propGetter(k))
.filter(Boolean)
.forEach(o => _keepAssigned(ka, o, pusher));
return ka;
} | javascript | function subKeepAssigned(objs, k, pusher) {
var ka = keepAssigned();
objs
.map(propGetter(k))
.filter(Boolean)
.forEach(o => _keepAssigned(ka, o, pusher));
return ka;
} | [
"function",
"subKeepAssigned",
"(",
"objs",
",",
"k",
",",
"pusher",
")",
"{",
"var",
"ka",
"=",
"keepAssigned",
"(",
")",
";",
"objs",
".",
"map",
"(",
"propGetter",
"(",
"k",
")",
")",
".",
"filter",
"(",
"Boolean",
")",
".",
"forEach",
"(",
"o",... | Make a keepAssigned object for subobjects with some key. | [
"Make",
"a",
"keepAssigned",
"object",
"for",
"subobjects",
"with",
"some",
"key",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L74-L81 | train |
rtm/upward | src/Ass.js | _keepAssigned | function _keepAssigned(ka, o, pusher = unshift) {
// Handle an upwardable object changing, in case of `O(model.obj)`.
function objectChanged(_o) {
replace(ka.objs, o, _o);
recalc(ka);
}
// @TODO: figure out how to handle this.
// upward(o, objectChanged);
function key(v, k) {
placeKey(ka, v,... | javascript | function _keepAssigned(ka, o, pusher = unshift) {
// Handle an upwardable object changing, in case of `O(model.obj)`.
function objectChanged(_o) {
replace(ka.objs, o, _o);
recalc(ka);
}
// @TODO: figure out how to handle this.
// upward(o, objectChanged);
function key(v, k) {
placeKey(ka, v,... | [
"function",
"_keepAssigned",
"(",
"ka",
",",
"o",
",",
"pusher",
"=",
"unshift",
")",
"{",
"// Handle an upwardable object changing, in case of `O(model.obj)`.",
"function",
"objectChanged",
"(",
"_o",
")",
"{",
"replace",
"(",
"ka",
".",
"objs",
",",
"o",
",",
... | Push one object onto a keepAssigned object, either at the front or back. | [
"Push",
"one",
"object",
"onto",
"a",
"keepAssigned",
"object",
"either",
"at",
"the",
"front",
"or",
"back",
"."
] | 82495c34f70c9a4336a3b34cc6781e5662324c03 | https://github.com/rtm/upward/blob/82495c34f70c9a4336a3b34cc6781e5662324c03/src/Ass.js#L84-L117 | train |
iLambda/sparse-binary-matrix | lib/sbm.js | function(source, dimension) {
// create the matrix
var mat = {}
// if dimension is an integer, the matrix is square
if (_.isFunction(source)
&& _.isInteger(dimension) && dimension >= 0) {
dimension = { x:dimension, y:dimension }
}
// source can be a 2-var predicate function or... | javascript | function(source, dimension) {
// create the matrix
var mat = {}
// if dimension is an integer, the matrix is square
if (_.isFunction(source)
&& _.isInteger(dimension) && dimension >= 0) {
dimension = { x:dimension, y:dimension }
}
// source can be a 2-var predicate function or... | [
"function",
"(",
"source",
",",
"dimension",
")",
"{",
"// create the matrix",
"var",
"mat",
"=",
"{",
"}",
"// if dimension is an integer, the matrix is square",
"if",
"(",
"_",
".",
"isFunction",
"(",
"source",
")",
"&&",
"_",
".",
"isInteger",
"(",
"dimension... | creates a sparse binary matrix | [
"creates",
"a",
"sparse",
"binary",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L5-L49 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm) {
// creating matrix
var mat = []
// populate
for (var i = 0; i < sbm.x; i++) {
mat.push([])
for (var j = 0; j < sbm.y; j++) {
mat[i][j] = _.includes(sbm.data[i], j) ? 1 : 0
}
}
// return the matrix
return mat
} | javascript | function(sbm) {
// creating matrix
var mat = []
// populate
for (var i = 0; i < sbm.x; i++) {
mat.push([])
for (var j = 0; j < sbm.y; j++) {
mat[i][j] = _.includes(sbm.data[i], j) ? 1 : 0
}
}
// return the matrix
return mat
} | [
"function",
"(",
"sbm",
")",
"{",
"// creating matrix",
"var",
"mat",
"=",
"[",
"]",
"// populate",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"sbm",
".",
"x",
";",
"i",
"++",
")",
"{",
"mat",
".",
"push",
"(",
"[",
"]",
")",
"for",
"("... | returns the sbm in line-based matrix form | [
"returns",
"the",
"sbm",
"in",
"line",
"-",
"based",
"matrix",
"form"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L51-L63 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(n) {
n = _.isInteger(n) ? n : 0
return {
x: n,
y: n,
data: _.map(_.range(n), function (num) {
return [num]
})
}
} | javascript | function(n) {
n = _.isInteger(n) ? n : 0
return {
x: n,
y: n,
data: _.map(_.range(n), function (num) {
return [num]
})
}
} | [
"function",
"(",
"n",
")",
"{",
"n",
"=",
"_",
".",
"isInteger",
"(",
"n",
")",
"?",
"n",
":",
"0",
"return",
"{",
"x",
":",
"n",
",",
"y",
":",
"n",
",",
"data",
":",
"_",
".",
"map",
"(",
"_",
".",
"range",
"(",
"n",
")",
",",
"functi... | returns the identity matrix for a given dimension | [
"returns",
"the",
"identity",
"matrix",
"for",
"a",
"given",
"dimension"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L71-L81 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(matrix) {
// if not square
if (matrix.x != matrix.y) {
return
}
// return trace
return _.filter(matrix.data, function (line, number) {
return _.includes(line, number)
}).length
} | javascript | function(matrix) {
// if not square
if (matrix.x != matrix.y) {
return
}
// return trace
return _.filter(matrix.data, function (line, number) {
return _.includes(line, number)
}).length
} | [
"function",
"(",
"matrix",
")",
"{",
"// if not square",
"if",
"(",
"matrix",
".",
"x",
"!=",
"matrix",
".",
"y",
")",
"{",
"return",
"}",
"// return trace",
"return",
"_",
".",
"filter",
"(",
"matrix",
".",
"data",
",",
"function",
"(",
"line",
",",
... | computes the trace of the matrix | [
"computes",
"the",
"trace",
"of",
"the",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L110-L119 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm) {
// create the matrix
var mat = {}
mat.x = sbm.y
mat.y = sbm.x
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data.push([])
for (var j = 0; j < mat.y; j++) {
if (_.includes(sbm.data[j], i)) {
mat.data[i].push(j)
}
... | javascript | function(sbm) {
// create the matrix
var mat = {}
mat.x = sbm.y
mat.y = sbm.x
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data.push([])
for (var j = 0; j < mat.y; j++) {
if (_.includes(sbm.data[j], i)) {
mat.data[i].push(j)
}
... | [
"function",
"(",
"sbm",
")",
"{",
"// create the matrix",
"var",
"mat",
"=",
"{",
"}",
"mat",
".",
"x",
"=",
"sbm",
".",
"y",
"mat",
".",
"y",
"=",
"sbm",
".",
"x",
"mat",
".",
"data",
"=",
"[",
"]",
"// populate",
"for",
"(",
"var",
"i",
"=",
... | transposes the matrix | [
"transposes",
"the",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L122-L138 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbmA, sbmB) {
// check size
if (sbmA.x !== sbmB.x || sbmA.y !== sbmB.y) {
return false
}
// check
return _.every(sbmA.data, function (line, idx) {
return _.isEqual(line.sort(), sbmB.data[idx].sort())
})
} | javascript | function(sbmA, sbmB) {
// check size
if (sbmA.x !== sbmB.x || sbmA.y !== sbmB.y) {
return false
}
// check
return _.every(sbmA.data, function (line, idx) {
return _.isEqual(line.sort(), sbmB.data[idx].sort())
})
} | [
"function",
"(",
"sbmA",
",",
"sbmB",
")",
"{",
"// check size",
"if",
"(",
"sbmA",
".",
"x",
"!==",
"sbmB",
".",
"x",
"||",
"sbmA",
".",
"y",
"!==",
"sbmB",
".",
"y",
")",
"{",
"return",
"false",
"}",
"// check",
"return",
"_",
".",
"every",
"("... | are both matrices equal ? | [
"are",
"both",
"matrices",
"equal",
"?"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L142-L152 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm) {
// create the matrix
var mat = {}
mat.x = sbm.x
mat.y = sbm.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.difference(_.range(mat.y), sbm.data[i])
}
// return matrix
return mat
} | javascript | function(sbm) {
// create the matrix
var mat = {}
mat.x = sbm.x
mat.y = sbm.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.difference(_.range(mat.y), sbm.data[i])
}
// return matrix
return mat
} | [
"function",
"(",
"sbm",
")",
"{",
"// create the matrix",
"var",
"mat",
"=",
"{",
"}",
"mat",
".",
"x",
"=",
"sbm",
".",
"x",
"mat",
".",
"y",
"=",
"sbm",
".",
"y",
"mat",
".",
"data",
"=",
"[",
"]",
"// populate",
"for",
"(",
"var",
"i",
"=",
... | NOT the matrix | [
"NOT",
"the",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L155-L167 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbmA, sbmB) {
// if not the same sizes
if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) {
return
}
// create the matrix
var mat = {}
mat.x = sbmA.x
mat.y = sbmA.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.intersection(sbmA.data[i], ... | javascript | function(sbmA, sbmB) {
// if not the same sizes
if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) {
return
}
// create the matrix
var mat = {}
mat.x = sbmA.x
mat.y = sbmA.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.intersection(sbmA.data[i], ... | [
"function",
"(",
"sbmA",
",",
"sbmB",
")",
"{",
"// if not the same sizes",
"if",
"(",
"sbmA",
".",
"x",
"!=",
"sbmB",
".",
"x",
"||",
"sbmA",
".",
"y",
"!=",
"sbmB",
".",
"y",
")",
"{",
"return",
"}",
"// create the matrix",
"var",
"mat",
"=",
"{",
... | AND the two matrices | [
"AND",
"the",
"two",
"matrices"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L169-L185 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbmA, sbmB) {
// if not the same sizes
if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) {
return
}
// create the matrix
var mat = {}
mat.x = sbmA.x
mat.y = sbmA.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.union(sbmA.data[i], sbmB.da... | javascript | function(sbmA, sbmB) {
// if not the same sizes
if (sbmA.x != sbmB.x || sbmA.y != sbmB.y) {
return
}
// create the matrix
var mat = {}
mat.x = sbmA.x
mat.y = sbmA.y
mat.data = []
// populate
for (var i = 0; i < mat.x; i++) {
mat.data[i] = _.union(sbmA.data[i], sbmB.da... | [
"function",
"(",
"sbmA",
",",
"sbmB",
")",
"{",
"// if not the same sizes",
"if",
"(",
"sbmA",
".",
"x",
"!=",
"sbmB",
".",
"x",
"||",
"sbmA",
".",
"y",
"!=",
"sbmB",
".",
"y",
")",
"{",
"return",
"}",
"// create the matrix",
"var",
"mat",
"=",
"{",
... | OR the two matrices | [
"OR",
"the",
"two",
"matrices"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L187-L203 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbmA, sbmB) {
// check if size compatible
if (sbmA.y !== sbmB.x) {
return
}
// create a new matrix
return this.make((function (i, j) {
return _.reduce(_.map(_.range(sbmA.y), (function(id) {
return this.check(sbmA, i, id) && this.check(sbmB, id, j)
}).bind(this)), f... | javascript | function(sbmA, sbmB) {
// check if size compatible
if (sbmA.y !== sbmB.x) {
return
}
// create a new matrix
return this.make((function (i, j) {
return _.reduce(_.map(_.range(sbmA.y), (function(id) {
return this.check(sbmA, i, id) && this.check(sbmB, id, j)
}).bind(this)), f... | [
"function",
"(",
"sbmA",
",",
"sbmB",
")",
"{",
"// check if size compatible",
"if",
"(",
"sbmA",
".",
"y",
"!==",
"sbmB",
".",
"x",
")",
"{",
"return",
"}",
"// create a new matrix",
"return",
"this",
".",
"make",
"(",
"(",
"function",
"(",
"i",
",",
... | multiply two matrices | [
"multiply",
"two",
"matrices"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L226-L239 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm, n) {
if (n == 0) {
return this.identity(n)
} else if (n == 1) {
return sbm
} else if (n % 2 == 0) {
return this.pow(this.multiply(sbm, sbm), n/2)
} else {
return this.multiply(sbm, this.pow(this.multiply(sbm, sbm), (n-1)/2))
}
} | javascript | function(sbm, n) {
if (n == 0) {
return this.identity(n)
} else if (n == 1) {
return sbm
} else if (n % 2 == 0) {
return this.pow(this.multiply(sbm, sbm), n/2)
} else {
return this.multiply(sbm, this.pow(this.multiply(sbm, sbm), (n-1)/2))
}
} | [
"function",
"(",
"sbm",
",",
"n",
")",
"{",
"if",
"(",
"n",
"==",
"0",
")",
"{",
"return",
"this",
".",
"identity",
"(",
"n",
")",
"}",
"else",
"if",
"(",
"n",
"==",
"1",
")",
"{",
"return",
"sbm",
"}",
"else",
"if",
"(",
"n",
"%",
"2",
"... | power of the matrix | [
"power",
"of",
"the",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L241-L251 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm) {
// if the matrix ain't square, symmetry is off
if (sbm.x !== sbm.y) {
return false
}
// symmetry status
var symmetry = true
// iterate
for (var i = 0; i < sbm.x; i++) {
for (var j = 0; j <= i; j++) {
symmetry = symmetry && ((_.includes(sbm.data[i], j) ^ _... | javascript | function(sbm) {
// if the matrix ain't square, symmetry is off
if (sbm.x !== sbm.y) {
return false
}
// symmetry status
var symmetry = true
// iterate
for (var i = 0; i < sbm.x; i++) {
for (var j = 0; j <= i; j++) {
symmetry = symmetry && ((_.includes(sbm.data[i], j) ^ _... | [
"function",
"(",
"sbm",
")",
"{",
"// if the matrix ain't square, symmetry is off",
"if",
"(",
"sbm",
".",
"x",
"!==",
"sbm",
".",
"y",
")",
"{",
"return",
"false",
"}",
"// symmetry status",
"var",
"symmetry",
"=",
"true",
"// iterate",
"for",
"(",
"var",
"... | returns true if the matrix is symmetric | [
"returns",
"true",
"if",
"the",
"matrix",
"is",
"symmetric"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L254-L270 | train | |
iLambda/sparse-binary-matrix | lib/sbm.js | function(sbm) {
return _.sum(_.map(sbm.data, function (ar) { return ar.length }))
} | javascript | function(sbm) {
return _.sum(_.map(sbm.data, function (ar) { return ar.length }))
} | [
"function",
"(",
"sbm",
")",
"{",
"return",
"_",
".",
"sum",
"(",
"_",
".",
"map",
"(",
"sbm",
".",
"data",
",",
"function",
"(",
"ar",
")",
"{",
"return",
"ar",
".",
"length",
"}",
")",
")",
"}"
] | returns the number of 1 in the matrix | [
"returns",
"the",
"number",
"of",
"1",
"in",
"the",
"matrix"
] | cface7e5679f7e7c71fa37a4967413589e02eb42 | https://github.com/iLambda/sparse-binary-matrix/blob/cface7e5679f7e7c71fa37a4967413589e02eb42/lib/sbm.js#L272-L274 | train | |
Aigeec/mandrill-webhook-event-parser | src/mandrill-webhook-event-parser.js | function() {
if (!(this instanceof EventParser)) {
return new EventParser();
}
/**
* Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body mandrill_events parameter. Please see Madrills article {@link https://mandrill.zendesk.com/hc/en-us/... | javascript | function() {
if (!(this instanceof EventParser)) {
return new EventParser();
}
/**
* Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body mandrill_events parameter. Please see Madrills article {@link https://mandrill.zendesk.com/hc/en-us/... | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"EventParser",
")",
")",
"{",
"return",
"new",
"EventParser",
"(",
")",
";",
"}",
"/**\n * Parses Mandrill Events request. Sets mandrillEvents property on req. Expects body to contain decoded post body... | Simple express middleware for parsing Inbound Mandrill Webhook events
@Module MandrillWebhookEventParser | [
"Simple",
"express",
"middleware",
"for",
"parsing",
"Inbound",
"Mandrill",
"Webhook",
"events"
] | 94cffaa6e3258950d43e67aae0a5d6d04e3b948f | https://github.com/Aigeec/mandrill-webhook-event-parser/blob/94cffaa6e3258950d43e67aae0a5d6d04e3b948f/src/mandrill-webhook-event-parser.js#L12-L38 | train | |
reelyactive/chickadee | lib/routes/associations.js | retrieveAssociations | function retrieveAssociations(req, res) {
switch(req.accepts(['json', 'html'])) {
// TODO: support HTML in future
//case 'html':
// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));
// break;
default:
var rootUrl = req.protocol + '://' + req.get('host');
var quer... | javascript | function retrieveAssociations(req, res) {
switch(req.accepts(['json', 'html'])) {
// TODO: support HTML in future
//case 'html':
// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));
// break;
default:
var rootUrl = req.protocol + '://' + req.get('host');
var quer... | [
"function",
"retrieveAssociations",
"(",
"req",
",",
"res",
")",
"{",
"switch",
"(",
"req",
".",
"accepts",
"(",
"[",
"'json'",
",",
"'html'",
"]",
")",
")",
"{",
"// TODO: support HTML in future",
"//case 'html':",
"// res.sendFile(path.resolve(__dirname + '/../../w... | Retrieve all available associations.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Retrieve",
"all",
"available",
"associations",
"."
] | 1f65c2d369694d93796aae63318fa76326275120 | https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L83-L98 | train |
reelyactive/chickadee | lib/routes/associations.js | retrieveAssociation | function retrieveAssociation(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
switch(req.accepts(['json', 'html'])) {
// TODO: support HTML in future
//case 'html':
// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));
// break;
default:
var id ... | javascript | function retrieveAssociation(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
switch(req.accepts(['json', 'html'])) {
// TODO: support HTML in future
//case 'html':
// res.sendFile(path.resolve(__dirname + '/../../web/association.html'));
// break;
default:
var id ... | [
"function",
"retrieveAssociation",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"redirect",
"(",
"req",
".",
"params",
".",
"id",
",",
"''",
",",
"''",
",",
"res",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"req",
".",
"accepts",
"(",
"[",... | Retrieve the given association.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Retrieve",
"the",
"given",
"association",
"."
] | 1f65c2d369694d93796aae63318fa76326275120 | https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L106-L126 | train |
reelyactive/chickadee | lib/routes/associations.js | replaceAssociation | function replaceAssociation(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
var id = req.params.id;
var url = req.body.url;
var directory = req.body.directory;
var tags = req.body.tags;
var position = req.body.position;
var rootUrl = req.protocol + '://' + req.get('host');
var qu... | javascript | function replaceAssociation(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
var id = req.params.id;
var url = req.body.url;
var directory = req.body.directory;
var tags = req.body.tags;
var position = req.body.position;
var rootUrl = req.protocol + '://' + req.get('host');
var qu... | [
"function",
"replaceAssociation",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"redirect",
"(",
"req",
".",
"params",
".",
"id",
",",
"''",
",",
"''",
",",
"res",
")",
")",
"{",
"return",
";",
"}",
"var",
"id",
"=",
"req",
".",
"params",
".",
"... | Replace the specified association.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Replace",
"the",
"specified",
"association",
"."
] | 1f65c2d369694d93796aae63318fa76326275120 | https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L134-L150 | train |
reelyactive/chickadee | lib/routes/associations.js | replaceAssociationPosition | function replaceAssociationPosition(req, res) {
if(redirect(req.params.id, '../', '/tags', res)) {
return;
}
var id = req.params.id;
var position = req.body.position;
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.chickadee.setAssociation(req, id, null, nul... | javascript | function replaceAssociationPosition(req, res) {
if(redirect(req.params.id, '../', '/tags', res)) {
return;
}
var id = req.params.id;
var position = req.body.position;
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.chickadee.setAssociation(req, id, null, nul... | [
"function",
"replaceAssociationPosition",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"redirect",
"(",
"req",
".",
"params",
".",
"id",
",",
"'../'",
",",
"'/tags'",
",",
"res",
")",
")",
"{",
"return",
";",
"}",
"var",
"id",
"=",
"req",
".",
"par... | Replace the specified association position.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Replace",
"the",
"specified",
"association",
"position",
"."
] | 1f65c2d369694d93796aae63318fa76326275120 | https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L413-L426 | train |
reelyactive/chickadee | lib/routes/associations.js | deleteAssociationPosition | function deleteAssociationPosition(req, res) {
if(redirect(req.params.id, '../', '/tags', res)) {
return;
}
var id = req.params.id;
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.chickadee.removeAssociation(req, id, 'position', rootUrl, queryPath,
... | javascript | function deleteAssociationPosition(req, res) {
if(redirect(req.params.id, '../', '/tags', res)) {
return;
}
var id = req.params.id;
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.chickadee.removeAssociation(req, id, 'position', rootUrl, queryPath,
... | [
"function",
"deleteAssociationPosition",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"redirect",
"(",
"req",
".",
"params",
".",
"id",
",",
"'../'",
",",
"'/tags'",
",",
"res",
")",
")",
"{",
"return",
";",
"}",
"var",
"id",
"=",
"req",
".",
"para... | Delete the specified association position.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Delete",
"the",
"specified",
"association",
"position",
"."
] | 1f65c2d369694d93796aae63318fa76326275120 | https://github.com/reelyactive/chickadee/blob/1f65c2d369694d93796aae63318fa76326275120/lib/routes/associations.js#L434-L446 | train |
rhardin/node-statistics2 | lib/statistics2.js | p_nor | function p_nor(z) {
var e, z2, prev = 0.0, t, p, i = 3;
if (z < -12) { return 0.0; }
if (z > 12) { return 1.0; }
if (z === 0.0) { return 0.5; }
if (z > 0) {
e = true;
} else {
e = false;
z = -z;
}
z2 = z * z;
p... | javascript | function p_nor(z) {
var e, z2, prev = 0.0, t, p, i = 3;
if (z < -12) { return 0.0; }
if (z > 12) { return 1.0; }
if (z === 0.0) { return 0.5; }
if (z > 0) {
e = true;
} else {
e = false;
z = -z;
}
z2 = z * z;
p... | [
"function",
"p_nor",
"(",
"z",
")",
"{",
"var",
"e",
",",
"z2",
",",
"prev",
"=",
"0.0",
",",
"t",
",",
"p",
",",
"i",
"=",
"3",
";",
"if",
"(",
"z",
"<",
"-",
"12",
")",
"{",
"return",
"0.0",
";",
"}",
"if",
"(",
"z",
">",
"12",
")",
... | normal-distribution (-\infty, z] | [
"normal",
"-",
"distribution",
"(",
"-",
"\\",
"infty",
"z",
"]"
] | b00400adc7c3a0df43dee8d94b20affbb62be1ba | https://github.com/rhardin/node-statistics2/blob/b00400adc7c3a0df43dee8d94b20affbb62be1ba/lib/statistics2.js#L292-L317 | train |
rhardin/node-statistics2 | lib/statistics2.js | pf | function pf(q, n1, n2) {
var eps, fw, s, qe, w1, w2, w3, w4, u, u2, a, b, c, d;
if (q < 0.0 || q > 1.0 || n1 < 1 || n2 < 1) {
console.error('Error : Illegal parameter in pf()!');
return 0.0;
}
if (n1 <= 240 || n2 <= 240) { eps = 1.0e-5; }
if (n2 === 1) {... | javascript | function pf(q, n1, n2) {
var eps, fw, s, qe, w1, w2, w3, w4, u, u2, a, b, c, d;
if (q < 0.0 || q > 1.0 || n1 < 1 || n2 < 1) {
console.error('Error : Illegal parameter in pf()!');
return 0.0;
}
if (n1 <= 240 || n2 <= 240) { eps = 1.0e-5; }
if (n2 === 1) {... | [
"function",
"pf",
"(",
"q",
",",
"n1",
",",
"n2",
")",
"{",
"var",
"eps",
",",
"fw",
",",
"s",
",",
"qe",
",",
"w1",
",",
"w2",
",",
"w3",
",",
"w4",
",",
"u",
",",
"u2",
",",
"a",
",",
"b",
",",
"c",
",",
"d",
";",
"if",
"(",
"q",
... | [x, \infty) | [
"[",
"x",
"\\",
"infty",
")"
] | b00400adc7c3a0df43dee8d94b20affbb62be1ba | https://github.com/rhardin/node-statistics2/blob/b00400adc7c3a0df43dee8d94b20affbb62be1ba/lib/statistics2.js#L551-L602 | train |
Jmlevick/node-exec | lib/main.js | puts | function puts(error, stdout, stderr) {
if (error || stderr) {
let err = null;
if (error) {
err = `${error}`;
} else if (stderr) {
err = `${stderr}`;
}
returnObj.code = 1;
returnObj.error = err;
}
else if (stdout) {
returnObj.code = 0;
returnObj... | javascript | function puts(error, stdout, stderr) {
if (error || stderr) {
let err = null;
if (error) {
err = `${error}`;
} else if (stderr) {
err = `${stderr}`;
}
returnObj.code = 1;
returnObj.error = err;
}
else if (stdout) {
returnObj.code = 0;
returnObj... | [
"function",
"puts",
"(",
"error",
",",
"stdout",
",",
"stderr",
")",
"{",
"if",
"(",
"error",
"||",
"stderr",
")",
"{",
"let",
"err",
"=",
"null",
";",
"if",
"(",
"error",
")",
"{",
"err",
"=",
"`",
"${",
"error",
"}",
"`",
";",
"}",
"else",
... | Helpers
Callback for exec
@param {any} error
@param {any} stdout
@param {any} stderr | [
"Helpers",
"Callback",
"for",
"exec"
] | afb2d31eda9cbb0911820dc2f78ef23f87d40187 | https://github.com/Jmlevick/node-exec/blob/afb2d31eda9cbb0911820dc2f78ef23f87d40187/lib/main.js#L20-L39 | train |
jurca/namespace-proxy | es2015/createNamespaceProxy.js | createProxy | function createProxy(instance, symbols, enumerable) {
return new Proxy(instance, {
set: (target, propertyName, value) => {
let { symbol, isNew } = getSymbol(symbols, propertyName)
instance[symbol] = value
if (!enumerable && isNew) {
Object.defineProperty(instance, symbol, {
enu... | javascript | function createProxy(instance, symbols, enumerable) {
return new Proxy(instance, {
set: (target, propertyName, value) => {
let { symbol, isNew } = getSymbol(symbols, propertyName)
instance[symbol] = value
if (!enumerable && isNew) {
Object.defineProperty(instance, symbol, {
enu... | [
"function",
"createProxy",
"(",
"instance",
",",
"symbols",
",",
"enumerable",
")",
"{",
"return",
"new",
"Proxy",
"(",
"instance",
",",
"{",
"set",
":",
"(",
"target",
",",
"propertyName",
",",
"value",
")",
"=>",
"{",
"let",
"{",
"symbol",
",",
"isNe... | Creates a proxy for retrieving and setting the values of the private
properties of the provided instance.
@param {Object} instance The instance for which the proxy should be created.
@param {Map<string, symbol>} symbols Cache of private property symbols.
@param {boolean} enumerable The flag specifying whether or not t... | [
"Creates",
"a",
"proxy",
"for",
"retrieving",
"and",
"setting",
"the",
"values",
"of",
"the",
"private",
"properties",
"of",
"the",
"provided",
"instance",
"."
] | b3526c8788930362694920d94a10848352436492 | https://github.com/jurca/namespace-proxy/blob/b3526c8788930362694920d94a10848352436492/es2015/createNamespaceProxy.js#L57-L79 | train |
jurca/namespace-proxy | es2015/createNamespaceProxy.js | getSymbol | function getSymbol(symbols, propertyName) {
if (symbols.has(propertyName)) {
return {
symbol: symbols.get(propertyName),
isNew: false
}
}
let symbol = Symbol(propertyName)
symbols.set(propertyName, symbol)
return {
symbol,
isNew: true
}
} | javascript | function getSymbol(symbols, propertyName) {
if (symbols.has(propertyName)) {
return {
symbol: symbols.get(propertyName),
isNew: false
}
}
let symbol = Symbol(propertyName)
symbols.set(propertyName, symbol)
return {
symbol,
isNew: true
}
} | [
"function",
"getSymbol",
"(",
"symbols",
",",
"propertyName",
")",
"{",
"if",
"(",
"symbols",
".",
"has",
"(",
"propertyName",
")",
")",
"{",
"return",
"{",
"symbol",
":",
"symbols",
".",
"get",
"(",
"propertyName",
")",
",",
"isNew",
":",
"false",
"}"... | Retrieves or generates and caches the private field symbol for the private
property of the specified name.
@param {Map<string, symbol>} symbols Cache of private property symbols.
@param {string} propertyName The name of the private property.
@return {{symbol: symbol, isNew: boolean}} An object wrapping the symbol to
u... | [
"Retrieves",
"or",
"generates",
"and",
"caches",
"the",
"private",
"field",
"symbol",
"for",
"the",
"private",
"property",
"of",
"the",
"specified",
"name",
"."
] | b3526c8788930362694920d94a10848352436492 | https://github.com/jurca/namespace-proxy/blob/b3526c8788930362694920d94a10848352436492/es2015/createNamespaceProxy.js#L92-L106 | train |
neoziro/image-size-parser | index.js | parse | function parse(size) {
var matches = size.match(regexp);
if (!matches)
return null;
var multiplicator = matches[3] ? +matches[3].replace(/x$/, '') : 1;
return {
width: +matches[1] * multiplicator,
height: +matches[2] * multiplicator
};
} | javascript | function parse(size) {
var matches = size.match(regexp);
if (!matches)
return null;
var multiplicator = matches[3] ? +matches[3].replace(/x$/, '') : 1;
return {
width: +matches[1] * multiplicator,
height: +matches[2] * multiplicator
};
} | [
"function",
"parse",
"(",
"size",
")",
"{",
"var",
"matches",
"=",
"size",
".",
"match",
"(",
"regexp",
")",
";",
"if",
"(",
"!",
"matches",
")",
"return",
"null",
";",
"var",
"multiplicator",
"=",
"matches",
"[",
"3",
"]",
"?",
"+",
"matches",
"["... | Parse image size.
@param {string} size Size string
@returns {object} size Size object
@returns {number} size.width Width
@returns {number} size.height Height | [
"Parse",
"image",
"size",
"."
] | 4b6594ae71a01900e9ace09a7a589c8976e5715e | https://github.com/neoziro/image-size-parser/blob/4b6594ae71a01900e9ace09a7a589c8976e5715e/index.js#L15-L27 | train |
AutocratJS/autocrat | lib/law.js | function() {
var streams = this.sourceStreams = toArray(arguments);
if(streams.length > 1) {
this.resultStream = Bacon.mergeAll(streams);
} else {
this.resultStream = streams[0];
}
this.streamsHash = this._computeStreamsHash('any', streams);
// invalidate 'all'
return this;
... | javascript | function() {
var streams = this.sourceStreams = toArray(arguments);
if(streams.length > 1) {
this.resultStream = Bacon.mergeAll(streams);
} else {
this.resultStream = streams[0];
}
this.streamsHash = this._computeStreamsHash('any', streams);
// invalidate 'all'
return this;
... | [
"function",
"(",
")",
"{",
"var",
"streams",
"=",
"this",
".",
"sourceStreams",
"=",
"toArray",
"(",
"arguments",
")",
";",
"if",
"(",
"streams",
".",
"length",
">",
"1",
")",
"{",
"this",
".",
"resultStream",
"=",
"Bacon",
".",
"mergeAll",
"(",
"str... | Produce a side effect when any of the Law events occur
@function
@name whenAny
@instance
@memberof Law | [
"Produce",
"a",
"side",
"effect",
"when",
"any",
"of",
"the",
"Law",
"events",
"occur"
] | ca1466f851c4dbc5237fbbb2ee7caa1cff964f51 | https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L155-L168 | train | |
AutocratJS/autocrat | lib/law.js | function() {
var streams = this.sourceStreams = toArray(arguments);
if(streams.length === 1) {
this.any.apply(this, streams);
return this;
}
this.resultStream = Bacon.zipAsArray(streams);
this.streamsHash = this._computeStreamsHash('all', streams);
// invalidate 'any'
return ... | javascript | function() {
var streams = this.sourceStreams = toArray(arguments);
if(streams.length === 1) {
this.any.apply(this, streams);
return this;
}
this.resultStream = Bacon.zipAsArray(streams);
this.streamsHash = this._computeStreamsHash('all', streams);
// invalidate 'any'
return ... | [
"function",
"(",
")",
"{",
"var",
"streams",
"=",
"this",
".",
"sourceStreams",
"=",
"toArray",
"(",
"arguments",
")",
";",
"if",
"(",
"streams",
".",
"length",
"===",
"1",
")",
"{",
"this",
".",
"any",
".",
"apply",
"(",
"this",
",",
"streams",
")... | Produce a side effect only after all of the Law events occur
@function whenAll
@name whenAll
@instance
@memberof Law | [
"Produce",
"a",
"side",
"effect",
"only",
"after",
"all",
"of",
"the",
"Law",
"events",
"occur"
] | ca1466f851c4dbc5237fbbb2ee7caa1cff964f51 | https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L178-L192 | train | |
AutocratJS/autocrat | lib/law.js | function(autocrat, governor, origHandler, context) {
var streamsHash = this.streamsHash,
handlerSequence, isFirstHandler, deferred, handler;
context || (context = this.governor);
if(isFunction(origHandler)) {
origHandler = bind(origHandler, context);
} else if(isString(origHandler)){
... | javascript | function(autocrat, governor, origHandler, context) {
var streamsHash = this.streamsHash,
handlerSequence, isFirstHandler, deferred, handler;
context || (context = this.governor);
if(isFunction(origHandler)) {
origHandler = bind(origHandler, context);
} else if(isString(origHandler)){
... | [
"function",
"(",
"autocrat",
",",
"governor",
",",
"origHandler",
",",
"context",
")",
"{",
"var",
"streamsHash",
"=",
"this",
".",
"streamsHash",
",",
"handlerSequence",
",",
"isFirstHandler",
",",
"deferred",
",",
"handler",
";",
"context",
"||",
"(",
"con... | Explicitly specify a side effect function
@function then
@name then
@instance
@memberof Law | [
"Explicitly",
"specify",
"a",
"side",
"effect",
"function"
] | ca1466f851c4dbc5237fbbb2ee7caa1cff964f51 | https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L202-L235 | train | |
AutocratJS/autocrat | lib/law.js | function(propName, updater) {
var updaterName, handler;
if(!isFunction(updater)) {
updaterName = 'update' + propName[0].toUpperCase() + propName.slice(1);
updater = this.governor[updaterName];
}
if(updater) {
this.then(function(advisorEvent, deferred, consequenceActions, streamEvent)... | javascript | function(propName, updater) {
var updaterName, handler;
if(!isFunction(updater)) {
updaterName = 'update' + propName[0].toUpperCase() + propName.slice(1);
updater = this.governor[updaterName];
}
if(updater) {
this.then(function(advisorEvent, deferred, consequenceActions, streamEvent)... | [
"function",
"(",
"propName",
",",
"updater",
")",
"{",
"var",
"updaterName",
",",
"handler",
";",
"if",
"(",
"!",
"isFunction",
"(",
"updater",
")",
")",
"{",
"updaterName",
"=",
"'update'",
"+",
"propName",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",... | Indicate which property update function should be called in response to
Advisor events.
@function updateProp
@name updateProp
@instance
@memberof Law | [
"Indicate",
"which",
"property",
"update",
"function",
"should",
"be",
"called",
"in",
"response",
"to",
"Advisor",
"events",
"."
] | ca1466f851c4dbc5237fbbb2ee7caa1cff964f51 | https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L246-L271 | train | |
AutocratJS/autocrat | lib/law.js | function() {
var props = arguments.length ? toArray(arguments) : keys(this.governor.props);
forEach(props, this.updateProp, this);
return this;
} | javascript | function() {
var props = arguments.length ? toArray(arguments) : keys(this.governor.props);
forEach(props, this.updateProp, this);
return this;
} | [
"function",
"(",
")",
"{",
"var",
"props",
"=",
"arguments",
".",
"length",
"?",
"toArray",
"(",
"arguments",
")",
":",
"keys",
"(",
"this",
".",
"governor",
".",
"props",
")",
";",
"forEach",
"(",
"props",
",",
"this",
".",
"updateProp",
",",
"this"... | Indicate that all prop update functions should be called in resonse to a
Law's Advisor events.
@function updateProps
@name updateProps
@instance
@memberof Law | [
"Indicate",
"that",
"all",
"prop",
"update",
"functions",
"should",
"be",
"called",
"in",
"resonse",
"to",
"a",
"Law",
"s",
"Advisor",
"events",
"."
] | ca1466f851c4dbc5237fbbb2ee7caa1cff964f51 | https://github.com/AutocratJS/autocrat/blob/ca1466f851c4dbc5237fbbb2ee7caa1cff964f51/lib/law.js#L282-L286 | train | |
hawtio/hawtio-utilities | dist/hawtio-utilities.js | removeElements | function removeElements(collection, newCollection, index) {
if (index === void 0) { index = 'id'; }
var oldLength = collection.length;
_.remove(collection, function (item) { return !_.some(newCollection, function (c) { return c[index] === item[index]; }); });
return collection.length !==... | javascript | function removeElements(collection, newCollection, index) {
if (index === void 0) { index = 'id'; }
var oldLength = collection.length;
_.remove(collection, function (item) { return !_.some(newCollection, function (c) { return c[index] === item[index]; }); });
return collection.length !==... | [
"function",
"removeElements",
"(",
"collection",
",",
"newCollection",
",",
"index",
")",
"{",
"if",
"(",
"index",
"===",
"void",
"0",
")",
"{",
"index",
"=",
"'id'",
";",
"}",
"var",
"oldLength",
"=",
"collection",
".",
"length",
";",
"_",
".",
"remov... | Removes elements in the target array based on the new collection, returns true if
any changes were made | [
"Removes",
"elements",
"in",
"the",
"target",
"array",
"based",
"on",
"the",
"new",
"collection",
"returns",
"true",
"if",
"any",
"changes",
"were",
"made"
] | c938a8936a0e547d61b0dfdfdc94145c280d2eeb | https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L17-L22 | train |
hawtio/hawtio-utilities | dist/hawtio-utilities.js | sync | function sync(collection, newCollection, index) {
if (index === void 0) { index = 'id'; }
var answer = removeElements(collection, newCollection, index);
if (newCollection) {
newCollection.forEach(function (item) {
var oldItem = _.find(collection, function (c) { return... | javascript | function sync(collection, newCollection, index) {
if (index === void 0) { index = 'id'; }
var answer = removeElements(collection, newCollection, index);
if (newCollection) {
newCollection.forEach(function (item) {
var oldItem = _.find(collection, function (c) { return... | [
"function",
"sync",
"(",
"collection",
",",
"newCollection",
",",
"index",
")",
"{",
"if",
"(",
"index",
"===",
"void",
"0",
")",
"{",
"index",
"=",
"'id'",
";",
"}",
"var",
"answer",
"=",
"removeElements",
"(",
"collection",
",",
"newCollection",
",",
... | Changes the existing collection to match the new collection to avoid re-assigning
the array pointer, returns true if the array size has changed | [
"Changes",
"the",
"existing",
"collection",
"to",
"match",
"the",
"new",
"collection",
"to",
"avoid",
"re",
"-",
"assigning",
"the",
"array",
"pointer",
"returns",
"true",
"if",
"the",
"array",
"size",
"has",
"changed"
] | c938a8936a0e547d61b0dfdfdc94145c280d2eeb | https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L28-L47 | train |
hawtio/hawtio-utilities | dist/hawtio-utilities.js | escapeColons | function escapeColons(url) {
var answer = url;
if (_.startsWith(url, 'proxy')) {
answer = url.replace(/:/g, '\\:');
}
else {
answer = url.replace(/:([^\/])/, '\\:$1');
}
return answer;
} | javascript | function escapeColons(url) {
var answer = url;
if (_.startsWith(url, 'proxy')) {
answer = url.replace(/:/g, '\\:');
}
else {
answer = url.replace(/:([^\/])/, '\\:$1');
}
return answer;
} | [
"function",
"escapeColons",
"(",
"url",
")",
"{",
"var",
"answer",
"=",
"url",
";",
"if",
"(",
"_",
".",
"startsWith",
"(",
"url",
",",
"'proxy'",
")",
")",
"{",
"answer",
"=",
"url",
".",
"replace",
"(",
"/",
":",
"/",
"g",
",",
"'\\\\:'",
")",
... | Escape any colons in the URL for ng-resource, mostly useful for handling proxified URLs
@param url
@returns {*} | [
"Escape",
"any",
"colons",
"in",
"the",
"URL",
"for",
"ng",
"-",
"resource",
"mostly",
"useful",
"for",
"handling",
"proxified",
"URLs"
] | c938a8936a0e547d61b0dfdfdc94145c280d2eeb | https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L207-L216 | train |
hawtio/hawtio-utilities | dist/hawtio-utilities.js | url | function url(path) {
if (path) {
if (_.startsWith(path, "/")) {
if (!_urlPrefix) {
// lets discover the base url via the base html element
_urlPrefix = $('base').attr('href') || "";
if (_.endsWith(_urlPrefix, '/')) {
... | javascript | function url(path) {
if (path) {
if (_.startsWith(path, "/")) {
if (!_urlPrefix) {
// lets discover the base url via the base html element
_urlPrefix = $('base').attr('href') || "";
if (_.endsWith(_urlPrefix, '/')) {
... | [
"function",
"url",
"(",
"path",
")",
"{",
"if",
"(",
"path",
")",
"{",
"if",
"(",
"_",
".",
"startsWith",
"(",
"path",
",",
"\"/\"",
")",
")",
"{",
"if",
"(",
"!",
"_urlPrefix",
")",
"{",
"// lets discover the base url via the base html element",
"_urlPref... | Prefixes absolute URLs with current window.location.pathname
@param path
@returns {string} | [
"Prefixes",
"absolute",
"URLs",
"with",
"current",
"window",
".",
"location",
".",
"pathname"
] | c938a8936a0e547d61b0dfdfdc94145c280d2eeb | https://github.com/hawtio/hawtio-utilities/blob/c938a8936a0e547d61b0dfdfdc94145c280d2eeb/dist/hawtio-utilities.js#L239-L255 | train |
Subsets and Splits
SQL Console for semeru/code-text-javascript
Retrieves 20,000 non-null code samples labeled as JavaScript, providing a basic overview of the dataset.