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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
feedhenry/fh-reportingclient | lib/sync.js | syncBatch | function syncBatch(batch, cb) {
if (batch && batch.length > 0) {
var mbaasClient = new MBaaSClient(ENVIRONMENT, {
url: URL.format(PROTOCOL + '://' + HOST),
accessKey: ACCESS_KEY,
project: PROJECT,
app: GUID,
appApiKey: API_KEY
});
// /api/app/:domain/:enviro... | javascript | function syncBatch(batch, cb) {
if (batch && batch.length > 0) {
var mbaasClient = new MBaaSClient(ENVIRONMENT, {
url: URL.format(PROTOCOL + '://' + HOST),
accessKey: ACCESS_KEY,
project: PROJECT,
app: GUID,
appApiKey: API_KEY
});
// /api/app/:domain/:enviro... | [
"function",
"syncBatch",
"(",
"batch",
",",
"cb",
")",
"{",
"if",
"(",
"batch",
"&&",
"batch",
".",
"length",
">",
"0",
")",
"{",
"var",
"mbaasClient",
"=",
"new",
"MBaaSClient",
"(",
"ENVIRONMENT",
",",
"{",
"url",
":",
"URL",
".",
"format",
"(",
... | send data to fhmbaas | [
"send",
"data",
"to",
"fhmbaas"
] | a0e2c959ce73addbf138d48f3ed46ef87229ae1a | https://github.com/feedhenry/fh-reportingclient/blob/a0e2c959ce73addbf138d48f3ed46ef87229ae1a/lib/sync.js#L29-L55 | train |
haeric/bailey.js | src/compiler.js | normalizeBlocks | function normalizeBlocks(input) {
var numberOfLinesToIndent = 0;
var thisLineContainsStuff = false;
var thisLinesIndentation = '';
var out = '';
for (var i = 0; i < input.length; i++) {
var chr = input[i];
if (chr == '\r') {
continue;
}
if (chr === '\... | javascript | function normalizeBlocks(input) {
var numberOfLinesToIndent = 0;
var thisLineContainsStuff = false;
var thisLinesIndentation = '';
var out = '';
for (var i = 0; i < input.length; i++) {
var chr = input[i];
if (chr == '\r') {
continue;
}
if (chr === '\... | [
"function",
"normalizeBlocks",
"(",
"input",
")",
"{",
"var",
"numberOfLinesToIndent",
"=",
"0",
";",
"var",
"thisLineContainsStuff",
"=",
"false",
";",
"var",
"thisLinesIndentation",
"=",
"''",
";",
"var",
"out",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=... | Whenever we hit an indented block, make sure all preceding empty lines are made to have this indentation level | [
"Whenever",
"we",
"hit",
"an",
"indented",
"block",
"make",
"sure",
"all",
"preceding",
"empty",
"lines",
"are",
"made",
"to",
"have",
"this",
"indentation",
"level"
] | c8152d809d5be4ca48d059b907a8ba896bf1245b | https://github.com/haeric/bailey.js/blob/c8152d809d5be4ca48d059b907a8ba896bf1245b/src/compiler.js#L9-L62 | train |
commonform/cftemplate | index.js | addPosition | function addPosition (error, message) {
error.message = (
message + ' at ' +
'line ' + token.position.line + ', ' +
'column ' + token.position.column
)
error.position = token.position
return error
} | javascript | function addPosition (error, message) {
error.message = (
message + ' at ' +
'line ' + token.position.line + ', ' +
'column ' + token.position.column
)
error.position = token.position
return error
} | [
"function",
"addPosition",
"(",
"error",
",",
"message",
")",
"{",
"error",
".",
"message",
"=",
"(",
"message",
"+",
"' at '",
"+",
"'line '",
"+",
"token",
".",
"position",
".",
"line",
"+",
"', '",
"+",
"'column '",
"+",
"token",
".",
"position",
".... | Add position information to errors. | [
"Add",
"position",
"information",
"to",
"errors",
"."
] | 259b9d59e8a39c4505e185249a2f9055e91dddf9 | https://github.com/commonform/cftemplate/blob/259b9d59e8a39c4505e185249a2f9055e91dddf9/index.js#L52-L60 | train |
commonform/cftemplate | index.js | format | function format (form) {
return formToMarkup(form)
// Split lines.
.split('\n')
.map(function (line, index) {
return EMPTY_LINE.test(line)
// If the line is empty, leave it empty.
? line
: index === 0
? line
// On subseq... | javascript | function format (form) {
return formToMarkup(form)
// Split lines.
.split('\n')
.map(function (line, index) {
return EMPTY_LINE.test(line)
// If the line is empty, leave it empty.
? line
: index === 0
? line
// On subseq... | [
"function",
"format",
"(",
"form",
")",
"{",
"return",
"formToMarkup",
"(",
"form",
")",
"// Split lines.",
".",
"split",
"(",
"'\\n'",
")",
".",
"map",
"(",
"function",
"(",
"line",
",",
"index",
")",
"{",
"return",
"EMPTY_LINE",
".",
"test",
"(",
"li... | Format markup for insertion at the current position. | [
"Format",
"markup",
"for",
"insertion",
"at",
"the",
"current",
"position",
"."
] | 259b9d59e8a39c4505e185249a2f9055e91dddf9 | https://github.com/commonform/cftemplate/blob/259b9d59e8a39c4505e185249a2f9055e91dddf9/index.js#L63-L78 | train |
commonform/cftemplate | index.js | function (path, done) {
fs.access(path, fs.R_OK, function (error) {
done(!error)
})
} | javascript | function (path, done) {
fs.access(path, fs.R_OK, function (error) {
done(!error)
})
} | [
"function",
"(",
"path",
",",
"done",
")",
"{",
"fs",
".",
"access",
"(",
"path",
",",
"fs",
".",
"R_OK",
",",
"function",
"(",
"error",
")",
"{",
"done",
"(",
"!",
"error",
")",
"}",
")",
"}"
] | Can we read the file? | [
"Can",
"we",
"read",
"the",
"file?"
] | 259b9d59e8a39c4505e185249a2f9055e91dddf9 | https://github.com/commonform/cftemplate/blob/259b9d59e8a39c4505e185249a2f9055e91dddf9/index.js#L127-L131 | train | |
liziqiang/simple-webpack-progress-plugin | index.js | logStage | function logStage(stage) {
if (!spinner) {
spinner = ora({
color: 'green',
text: chalk.green(defaults.text)
}).info();
}
if (!stage || (lastStage && lastStage !== stage)) {
spinner.succeed(chalk.grey(lastStage));
}
... | javascript | function logStage(stage) {
if (!spinner) {
spinner = ora({
color: 'green',
text: chalk.green(defaults.text)
}).info();
}
if (!stage || (lastStage && lastStage !== stage)) {
spinner.succeed(chalk.grey(lastStage));
}
... | [
"function",
"logStage",
"(",
"stage",
")",
"{",
"if",
"(",
"!",
"spinner",
")",
"{",
"spinner",
"=",
"ora",
"(",
"{",
"color",
":",
"'green'",
",",
"text",
":",
"chalk",
".",
"green",
"(",
"defaults",
".",
"text",
")",
"}",
")",
".",
"info",
"(",... | output stage message | [
"output",
"stage",
"message"
] | 6dba2a1aa81de5d515afc72bae05237834ca73ce | https://github.com/liziqiang/simple-webpack-progress-plugin/blob/6dba2a1aa81de5d515afc72bae05237834ca73ce/index.js#L25-L38 | train |
vid/SenseBase | web/lib/results.js | addUpdated | function addUpdated(results) {
results.forEach(function(result) {
result = normalizeResult(result);
if (!lastQuery.results.hits) {
lastQuery = { results: { hits: { total : 0, hits: [] } } };
} else {
var i = 0, l = lastQuery.results.hits.hits.length;
for (i; i < l; i++) {
if (las... | javascript | function addUpdated(results) {
results.forEach(function(result) {
result = normalizeResult(result);
if (!lastQuery.results.hits) {
lastQuery = { results: { hits: { total : 0, hits: [] } } };
} else {
var i = 0, l = lastQuery.results.hits.hits.length;
for (i; i < l; i++) {
if (las... | [
"function",
"addUpdated",
"(",
"results",
")",
"{",
"results",
".",
"forEach",
"(",
"function",
"(",
"result",
")",
"{",
"result",
"=",
"normalizeResult",
"(",
"result",
")",
";",
"if",
"(",
"!",
"lastQuery",
".",
"results",
".",
"hits",
")",
"{",
"las... | add updated items | [
"add",
"updated",
"items"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L90-L107 | train |
vid/SenseBase | web/lib/results.js | normalizeResult | function normalizeResult(result) {
if (result.uri) {
console.log('normalizing', result);
if (!result._source) {
result._source = {};
}
['title', 'timestamp', 'uri', 'annotationSummary', 'annotations', 'visitors'].forEach(function(f) {
result._source[f] = result[f];
});
}
return res... | javascript | function normalizeResult(result) {
if (result.uri) {
console.log('normalizing', result);
if (!result._source) {
result._source = {};
}
['title', 'timestamp', 'uri', 'annotationSummary', 'annotations', 'visitors'].forEach(function(f) {
result._source[f] = result[f];
});
}
return res... | [
"function",
"normalizeResult",
"(",
"result",
")",
"{",
"if",
"(",
"result",
".",
"uri",
")",
"{",
"console",
".",
"log",
"(",
"'normalizing'",
",",
"result",
")",
";",
"if",
"(",
"!",
"result",
".",
"_source",
")",
"{",
"result",
".",
"_source",
"="... | FIXME normalize fields between base and _source | [
"FIXME",
"normalize",
"fields",
"between",
"base",
"and",
"_source"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L116-L127 | train |
vid/SenseBase | web/lib/results.js | gotResults | function gotResults(results) {
results.JSONquery = JSON.stringify(results.query, null, 2);
console.log('gotResults', results);
updateResults(results);
} | javascript | function gotResults(results) {
results.JSONquery = JSON.stringify(results.query, null, 2);
console.log('gotResults', results);
updateResults(results);
} | [
"function",
"gotResults",
"(",
"results",
")",
"{",
"results",
".",
"JSONquery",
"=",
"JSON",
".",
"stringify",
"(",
"results",
".",
"query",
",",
"null",
",",
"2",
")",
";",
"console",
".",
"log",
"(",
"'gotResults'",
",",
"results",
")",
";",
"update... | Query results were received | [
"Query",
"results",
"were",
"received"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L134-L138 | train |
vid/SenseBase | web/lib/results.js | gotNavigation | function gotNavigation(results) {
console.log('gotNavigation', results, browser);
var browser;
if (results.navigator === 'treemap') {
browser = browseTreemap;
} else if (results.navigator === 'facet') {
browser = browseFacet;
} else if (results.navigator === 'cluster') {
browser = browseCluster;
... | javascript | function gotNavigation(results) {
console.log('gotNavigation', results, browser);
var browser;
if (results.navigator === 'treemap') {
browser = browseTreemap;
} else if (results.navigator === 'facet') {
browser = browseFacet;
} else if (results.navigator === 'cluster') {
browser = browseCluster;
... | [
"function",
"gotNavigation",
"(",
"results",
")",
"{",
"console",
".",
"log",
"(",
"'gotNavigation'",
",",
"results",
",",
"browser",
")",
";",
"var",
"browser",
";",
"if",
"(",
"results",
".",
"navigator",
"===",
"'treemap'",
")",
"{",
"browser",
"=",
"... | Navigation results to accompany results | [
"Navigation",
"results",
"to",
"accompany",
"results"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L141-L160 | train |
vid/SenseBase | web/lib/results.js | updateResults | function updateResults(res) {
if (res === undefined) {
res = lastQuery;
}
var results = res.results;
lastQuery = res;
// content is being viewed or edited, delay updates
if (noUpdates) {
console.log('in noUpdates');
hasQueuedUpdates = true;
clearTimeout(queuedNotifier);
queuedNotifier =... | javascript | function updateResults(res) {
if (res === undefined) {
res = lastQuery;
}
var results = res.results;
lastQuery = res;
// content is being viewed or edited, delay updates
if (noUpdates) {
console.log('in noUpdates');
hasQueuedUpdates = true;
clearTimeout(queuedNotifier);
queuedNotifier =... | [
"function",
"updateResults",
"(",
"res",
")",
"{",
"if",
"(",
"res",
"===",
"undefined",
")",
"{",
"res",
"=",
"lastQuery",
";",
"}",
"var",
"results",
"=",
"res",
".",
"results",
";",
"lastQuery",
"=",
"res",
";",
"// content is being viewed or edited, dela... | Update displayed results using results view. If passed results are null, use lastQuery. | [
"Update",
"displayed",
"results",
"using",
"results",
"view",
".",
"If",
"passed",
"results",
"are",
"null",
"use",
"lastQuery",
"."
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L203-L246 | train |
vid/SenseBase | web/lib/results.js | getSelected | function getSelected() {
var selected = [];
$('.selectItem').each(function() {
if ($(this).is(':checked')) {
selected.push(utils.deEncID($(this).attr('name').replace('cb_', '')));
}
});
return selected;
} | javascript | function getSelected() {
var selected = [];
$('.selectItem').each(function() {
if ($(this).is(':checked')) {
selected.push(utils.deEncID($(this).attr('name').replace('cb_', '')));
}
});
return selected;
} | [
"function",
"getSelected",
"(",
")",
"{",
"var",
"selected",
"=",
"[",
"]",
";",
"$",
"(",
"'.selectItem'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"$",
"(",
"this",
")",
".",
"is",
"(",
"':checked'",
")",
")",
"{",
"selected... | return all items selected | [
"return",
"all",
"items",
"selected"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/web/lib/results.js#L265-L273 | train |
vladaspasic/ember-cli-data-validation | addon/error.js | ValidationError | function ValidationError(message, errors) {
Error.call(this, message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ValidationError);
}
this.message = message;
this.errors = errors;
} | javascript | function ValidationError(message, errors) {
Error.call(this, message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ValidationError);
}
this.message = message;
this.errors = errors;
} | [
"function",
"ValidationError",
"(",
"message",
",",
"errors",
")",
"{",
"Error",
".",
"call",
"(",
"this",
",",
"message",
")",
";",
"if",
"(",
"Error",
".",
"captureStackTrace",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"ValidationErr... | Error thrown when a Model validation fails.
This error contains the `DS.Errors` object from the Model.
@class ValidationError
@extends {Error}
@param {Srting} message
@param {DS.Errors} errors | [
"Error",
"thrown",
"when",
"a",
"Model",
"validation",
"fails",
"."
] | 08ee8694b9276bf7cbb40e8bc69c52592bb512d3 | https://github.com/vladaspasic/ember-cli-data-validation/blob/08ee8694b9276bf7cbb40e8bc69c52592bb512d3/addon/error.js#L11-L20 | train |
socialally/air | lib/air.js | Air | function Air(el, context) {
if(!(this instanceof Air)) {
return new Air(el, context);
}
if(typeof context === 'string') {
context = document.querySelector(context);
}else if(context instanceof Air) {
context = context.get(0);
}
context = context || document;
// NOTE: do not... | javascript | function Air(el, context) {
if(!(this instanceof Air)) {
return new Air(el, context);
}
if(typeof context === 'string') {
context = document.querySelector(context);
}else if(context instanceof Air) {
context = context.get(0);
}
context = context || document;
// NOTE: do not... | [
"function",
"Air",
"(",
"el",
",",
"context",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Air",
")",
")",
"{",
"return",
"new",
"Air",
"(",
"el",
",",
"context",
")",
";",
"}",
"if",
"(",
"typeof",
"context",
"===",
"'string'",
")",
"{"... | Chainable wrapper class.
This is the core of the entire plugin system and typically you extend
functionality by adding methods to the prototype of this function.
However a plugin may also add static methods to the main function,
see the `create` plugin for an example of adding static methods.
This implementation tar... | [
"Chainable",
"wrapper",
"class",
"."
] | a3d94de58aaa4930a425fbcc7266764bf6ca8ca6 | https://github.com/socialally/air/blob/a3d94de58aaa4930a425fbcc7266764bf6ca8ca6/lib/air.js#L22-L50 | train |
DScheglov/merest | lib/controllers/find-by-id.js | findById | function findById(method, req, res, next) {
res.__apiMethod = method;
var self = this;
var id = req.params.id;
var fields = this.option(method, 'fields');
var populate = this.option(method, 'populate');
var filter = this.option(method, 'filter');
if (filter instanceof Function) filter = filter.call... | javascript | function findById(method, req, res, next) {
res.__apiMethod = method;
var self = this;
var id = req.params.id;
var fields = this.option(method, 'fields');
var populate = this.option(method, 'populate');
var filter = this.option(method, 'filter');
if (filter instanceof Function) filter = filter.call... | [
"function",
"findById",
"(",
"method",
",",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"__apiMethod",
"=",
"method",
";",
"var",
"self",
"=",
"this",
";",
"var",
"id",
"=",
"req",
".",
"params",
".",
"id",
";",
"var",
"fields",
"=",
"t... | findById - sub-controller that is used to response
with one model instance
@param {String} method the name of main controller
@param {express.Request} req the http(s) request
@param {express.Response} res the http(s) response
@param {Function} next the callback should be ca... | [
"findById",
"-",
"sub",
"-",
"controller",
"that",
"is",
"used",
"to",
"response",
"with",
"one",
"model",
"instance"
] | d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/find-by-id.js#L19-L44 | train |
odogono/elsinore-js | src/query/attr.js | commandAttr | function commandAttr(context, attributes) {
let ii, jj, len, jlen, result;
let entity = context.entity;
// let debug = context.debug;
const componentIDs = context.componentIDs;
// printIns( context,1 );
// if( debug ){ console.log('ATTR> ' + stringify(componentIDs) + ' ' + stringify( _.rest(arg... | javascript | function commandAttr(context, attributes) {
let ii, jj, len, jlen, result;
let entity = context.entity;
// let debug = context.debug;
const componentIDs = context.componentIDs;
// printIns( context,1 );
// if( debug ){ console.log('ATTR> ' + stringify(componentIDs) + ' ' + stringify( _.rest(arg... | [
"function",
"commandAttr",
"(",
"context",
",",
"attributes",
")",
"{",
"let",
"ii",
",",
"jj",
",",
"len",
",",
"jlen",
",",
"result",
";",
"let",
"entity",
"=",
"context",
".",
"entity",
";",
"// let debug = context.debug;",
"const",
"componentIDs",
"=",
... | Takes the attribute value of the given component and returns it
This command operates on the single entity within context. | [
"Takes",
"the",
"attribute",
"value",
"of",
"the",
"given",
"component",
"and",
"returns",
"it"
] | 1ecce67ad0022646419a740def029b1ba92dd558 | https://github.com/odogono/elsinore-js/blob/1ecce67ad0022646419a740def029b1ba92dd558/src/query/attr.js#L20-L63 | train |
Rafflecopter/deetoo | lib/util.js | partial | function partial(fn) {
var preset=_slice.call(arguments, 1), self=this
return function(){ return fn.apply(self, arrfill(preset, arguments)) }
} | javascript | function partial(fn) {
var preset=_slice.call(arguments, 1), self=this
return function(){ return fn.apply(self, arrfill(preset, arguments)) }
} | [
"function",
"partial",
"(",
"fn",
")",
"{",
"var",
"preset",
"=",
"_slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
",",
"self",
"=",
"this",
"return",
"function",
"(",
")",
"{",
"return",
"fn",
".",
"apply",
"(",
"self",
",",
"arrfill",
"(",... | allows out-of-order arguments by using `undefined` | [
"allows",
"out",
"-",
"of",
"-",
"order",
"arguments",
"by",
"using",
"undefined"
] | 4d7932efeab35e01fa3a584b6c1253b21f0c4515 | https://github.com/Rafflecopter/deetoo/blob/4d7932efeab35e01fa3a584b6c1253b21f0c4515/lib/util.js#L11-L14 | train |
ryanflorence/detect-globals | lib/detect-globals.js | setupContext | function setupContext(node) {
if (node.type === 'Program') {
node.context = GLOBAL_CONTEXT;
return;
}
// default context is the parent context
node.context = node.parent.context;
// IIFE (function(win){ win.x = 'x' }(window))
if ( isIIFE(node) ) {
var args = node.arguments;
var params = no... | javascript | function setupContext(node) {
if (node.type === 'Program') {
node.context = GLOBAL_CONTEXT;
return;
}
// default context is the parent context
node.context = node.parent.context;
// IIFE (function(win){ win.x = 'x' }(window))
if ( isIIFE(node) ) {
var args = node.arguments;
var params = no... | [
"function",
"setupContext",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'Program'",
")",
"{",
"node",
".",
"context",
"=",
"GLOBAL_CONTEXT",
";",
"return",
";",
"}",
"// default context is the parent context",
"node",
".",
"context",
"=",
... | gets reference to the "this" value | [
"gets",
"reference",
"to",
"the",
"this",
"value"
] | da2242ee01c3617d54fd79e8373dd44a7c876181 | https://github.com/ryanflorence/detect-globals/blob/da2242ee01c3617d54fd79e8373dd44a7c876181/lib/detect-globals.js#L64-L130 | train |
HelpfulHuman/Router-Kit | src/connectHistory.js | assertHistoryType | function assertHistoryType (history) {
assertType("history", "object", history);
assertType("history.listen", "function", history.listen);
assertType("history.push", "function", history.push);
assertType("history.replace", "function", history.replace);
assertType("history.goBack", "function", history.goBack);... | javascript | function assertHistoryType (history) {
assertType("history", "object", history);
assertType("history.listen", "function", history.listen);
assertType("history.push", "function", history.push);
assertType("history.replace", "function", history.replace);
assertType("history.goBack", "function", history.goBack);... | [
"function",
"assertHistoryType",
"(",
"history",
")",
"{",
"assertType",
"(",
"\"history\"",
",",
"\"object\"",
",",
"history",
")",
";",
"assertType",
"(",
"\"history.listen\"",
",",
"\"function\"",
",",
"history",
".",
"listen",
")",
";",
"assertType",
"(",
... | Throws an error if object shape is not that of a history object.
@param {History} history | [
"Throws",
"an",
"error",
"if",
"object",
"shape",
"is",
"not",
"that",
"of",
"a",
"history",
"object",
"."
] | 2864833465348d0b38ee6652ea5d872f0a793ded | https://github.com/HelpfulHuman/Router-Kit/blob/2864833465348d0b38ee6652ea5d872f0a793ded/src/connectHistory.js#L9-L15 | train |
HelpfulHuman/Router-Kit | src/connectHistory.js | createDefaultHandler | function createDefaultHandler (history) {
return function (context, runMiddleware) {
runMiddleware(context, function (err, redirect) {
if (err) {
console.error(`${context.uri} -> ${err.message}`, err);
} else if (redirect) {
history.replace(redirect);
}
});
}
} | javascript | function createDefaultHandler (history) {
return function (context, runMiddleware) {
runMiddleware(context, function (err, redirect) {
if (err) {
console.error(`${context.uri} -> ${err.message}`, err);
} else if (redirect) {
history.replace(redirect);
}
});
}
} | [
"function",
"createDefaultHandler",
"(",
"history",
")",
"{",
"return",
"function",
"(",
"context",
",",
"runMiddleware",
")",
"{",
"runMiddleware",
"(",
"context",
",",
"function",
"(",
"err",
",",
"redirect",
")",
"{",
"if",
"(",
"err",
")",
"{",
"consol... | Create a default handler for connecting a router to a history object.
@param {History} history
@return {Function} | [
"Create",
"a",
"default",
"handler",
"for",
"connecting",
"a",
"router",
"to",
"a",
"history",
"object",
"."
] | 2864833465348d0b38ee6652ea5d872f0a793ded | https://github.com/HelpfulHuman/Router-Kit/blob/2864833465348d0b38ee6652ea5d872f0a793ded/src/connectHistory.js#L23-L33 | train |
vid/SenseBase | util/mapJsonToItemAnnotation.js | flatten | function flatten(level, map) {
for (var key in map) {
var kmap = map[key];
// we found a definition
if (kmap._VAL_ || kmap._TAG_) {
if (kmap._VAL_) {
flatFields[key] = { level: level, _VAL_ : kmap._VAL_};
} else {
flatFields[key] = { level: level, _TAG_ : kmap._TAG_};
}
... | javascript | function flatten(level, map) {
for (var key in map) {
var kmap = map[key];
// we found a definition
if (kmap._VAL_ || kmap._TAG_) {
if (kmap._VAL_) {
flatFields[key] = { level: level, _VAL_ : kmap._VAL_};
} else {
flatFields[key] = { level: level, _TAG_ : kmap._TAG_};
}
... | [
"function",
"flatten",
"(",
"level",
",",
"map",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"map",
")",
"{",
"var",
"kmap",
"=",
"map",
"[",
"key",
"]",
";",
"// we found a definition",
"if",
"(",
"kmap",
".",
"_VAL_",
"||",
"kmap",
".",
"_TAG_",
")... | recursively flatten fields to flatFields for fast lookups | [
"recursively",
"flatten",
"fields",
"to",
"flatFields",
"for",
"fast",
"lookups"
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/util/mapJsonToItemAnnotation.js#L136-L153 | train |
cfpb/AtomicComponent | src/utilities/function-bind/index.js | bind | function bind( fn, context ) {
if ( Function.prototype.bind ) {
return fn.bind.apply( fn, Array.prototype.slice.call( arguments, 1 ) );
}
return function() {
return fn.apply( context, arguments );
};
} | javascript | function bind( fn, context ) {
if ( Function.prototype.bind ) {
return fn.bind.apply( fn, Array.prototype.slice.call( arguments, 1 ) );
}
return function() {
return fn.apply( context, arguments );
};
} | [
"function",
"bind",
"(",
"fn",
",",
"context",
")",
"{",
"if",
"(",
"Function",
".",
"prototype",
".",
"bind",
")",
"{",
"return",
"fn",
".",
"bind",
".",
"apply",
"(",
"fn",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"argument... | Function.prototype.bind polyfill.
@access private
@function bind
@param {Function} fn - A function you want to change `this` reference to.
@param {Object} context - The `this` you want to call the function with.
@returns {Function} The wrapped version of the supplied function. | [
"Function",
".",
"prototype",
".",
"bind",
"polyfill",
"."
] | f45d7ded6687672c8b701c9910ddfe90c7ede742 | https://github.com/cfpb/AtomicComponent/blob/f45d7ded6687672c8b701c9910ddfe90c7ede742/src/utilities/function-bind/index.js#L22-L30 | train |
bminer/trivial-port | serialport.js | openSerialPortDevice | function openSerialPortDevice(readFd) {
//Save TTY streams
self._readStream = new tty.ReadStream(readFd);
self._readStream.setRawMode(true);
self._writeStream = self._readStream;
//Setup error handlers
self._readStream.on("error", function(err) {
self.emit("error", err);
});
//Setup read event handle... | javascript | function openSerialPortDevice(readFd) {
//Save TTY streams
self._readStream = new tty.ReadStream(readFd);
self._readStream.setRawMode(true);
self._writeStream = self._readStream;
//Setup error handlers
self._readStream.on("error", function(err) {
self.emit("error", err);
});
//Setup read event handle... | [
"function",
"openSerialPortDevice",
"(",
"readFd",
")",
"{",
"//Save TTY streams",
"self",
".",
"_readStream",
"=",
"new",
"tty",
".",
"ReadStream",
"(",
"readFd",
")",
";",
"self",
".",
"_readStream",
".",
"setRawMode",
"(",
"true",
")",
";",
"self",
".",
... | Once the process exits successfully, we call this function | [
"Once",
"the",
"process",
"exits",
"successfully",
"we",
"call",
"this",
"function"
] | f0db774ae14b2af3a75789060c9c2999c24d27a6 | https://github.com/bminer/trivial-port/blob/f0db774ae14b2af3a75789060c9c2999c24d27a6/serialport.js#L152-L173 | train |
donothingloop/netinterfaces | lib/index.js | findIntf | function findIntf(intf, osIntfs) {
var keys = Object.keys(osIntfs);
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
if (intf === key) {
return osIntfs[key];
}
}
return null;
} | javascript | function findIntf(intf, osIntfs) {
var keys = Object.keys(osIntfs);
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
if (intf === key) {
return osIntfs[key];
}
}
return null;
} | [
"function",
"findIntf",
"(",
"intf",
",",
"osIntfs",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"osIntfs",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
... | Find the interface by interface name in the data returned by os.networkInterfaces.
@param intf
@param osIntfs | [
"Find",
"the",
"interface",
"by",
"interface",
"name",
"in",
"the",
"data",
"returned",
"by",
"os",
".",
"networkInterfaces",
"."
] | 83327e9c930693db0ec2e443343ef29ed318246c | https://github.com/donothingloop/netinterfaces/blob/83327e9c930693db0ec2e443343ef29ed318246c/lib/index.js#L24-L35 | train |
mesmotronic/conbo | src/conbo/net/Router.js | function(route, name, callback)
{
var regExp = conbo.isRegExp(route) ? route : this.__routeToRegExp(route);
if (!callback)
{
callback = this[name];
}
if (conbo.isFunction(name))
{
callback = name;
name = '';
}
if (!callback)
{
callback = this[name];
}
... | javascript | function(route, name, callback)
{
var regExp = conbo.isRegExp(route) ? route : this.__routeToRegExp(route);
if (!callback)
{
callback = this[name];
}
if (conbo.isFunction(name))
{
callback = name;
name = '';
}
if (!callback)
{
callback = this[name];
}
... | [
"function",
"(",
"route",
",",
"name",
",",
"callback",
")",
"{",
"var",
"regExp",
"=",
"conbo",
".",
"isRegExp",
"(",
"route",
")",
"?",
"route",
":",
"this",
".",
"__routeToRegExp",
"(",
"route",
")",
";",
"if",
"(",
"!",
"callback",
")",
"{",
"c... | Adds a named route
@example
this.addRoute('search/:query/p:num', 'search', function(query, num) {
...
}); | [
"Adds",
"a",
"named",
"route"
] | 339df613eefc48e054e115337079573ad842f717 | https://github.com/mesmotronic/conbo/blob/339df613eefc48e054e115337079573ad842f717/src/conbo/net/Router.js#L87-L134 | train | |
mesmotronic/conbo | src/conbo/net/Router.js | function(path, options)
{
options = conbo.setDefaults({}, options, {trigger:true});
this.__history.setPath(path, options);
return this;
} | javascript | function(path, options)
{
options = conbo.setDefaults({}, options, {trigger:true});
this.__history.setPath(path, options);
return this;
} | [
"function",
"(",
"path",
",",
"options",
")",
"{",
"options",
"=",
"conbo",
".",
"setDefaults",
"(",
"{",
"}",
",",
"options",
",",
"{",
"trigger",
":",
"true",
"}",
")",
";",
"this",
".",
"__history",
".",
"setPath",
"(",
"path",
",",
"options",
"... | Sets the current path, optionally replacing the current path or silently
without triggering a route event
@param {string} path - The path to navigate to
@param {Object} [options] - Object containing options: trigger (default: true) and replace (default: false) | [
"Sets",
"the",
"current",
"path",
"optionally",
"replacing",
"the",
"current",
"path",
"or",
"silently",
"without",
"triggering",
"a",
"route",
"event"
] | 339df613eefc48e054e115337079573ad842f717 | https://github.com/mesmotronic/conbo/blob/339df613eefc48e054e115337079573ad842f717/src/conbo/net/Router.js#L143-L149 | train | |
mesmotronic/conbo | src/conbo/net/Router.js | function()
{
if (!this.routes) return;
var route;
var routes = conbo.keys(this.routes);
while ((route = routes.pop()) != null)
{
this.addRoute(route, this.routes[route]);
}
} | javascript | function()
{
if (!this.routes) return;
var route;
var routes = conbo.keys(this.routes);
while ((route = routes.pop()) != null)
{
this.addRoute(route, this.routes[route]);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"routes",
")",
"return",
";",
"var",
"route",
";",
"var",
"routes",
"=",
"conbo",
".",
"keys",
"(",
"this",
".",
"routes",
")",
";",
"while",
"(",
"(",
"route",
"=",
"routes",
".",
"pop",
... | Bind all defined routes. We have to reverse the
order of the routes here to support behavior where the most general
routes can be defined at the bottom of the route map.
@private | [
"Bind",
"all",
"defined",
"routes",
".",
"We",
"have",
"to",
"reverse",
"the",
"order",
"of",
"the",
"routes",
"here",
"to",
"support",
"behavior",
"where",
"the",
"most",
"general",
"routes",
"can",
"be",
"defined",
"at",
"the",
"bottom",
"of",
"the",
"... | 339df613eefc48e054e115337079573ad842f717 | https://github.com/mesmotronic/conbo/blob/339df613eefc48e054e115337079573ad842f717/src/conbo/net/Router.js#L177-L188 | train | |
edappy/bunyan-config | index.js | convertConfig | function convertConfig(jsonConfig) {
var bunyanConfig = extend({}, jsonConfig);
if (Array.isArray(bunyanConfig.streams)) {
bunyanConfig.streams = bunyanConfig.streams.map(convertStream);
}
if (bunyanConfig.serializers) {
bunyanConfig.serializers = convertSerializers(bunyanConfig.serializers);
}
r... | javascript | function convertConfig(jsonConfig) {
var bunyanConfig = extend({}, jsonConfig);
if (Array.isArray(bunyanConfig.streams)) {
bunyanConfig.streams = bunyanConfig.streams.map(convertStream);
}
if (bunyanConfig.serializers) {
bunyanConfig.serializers = convertSerializers(bunyanConfig.serializers);
}
r... | [
"function",
"convertConfig",
"(",
"jsonConfig",
")",
"{",
"var",
"bunyanConfig",
"=",
"extend",
"(",
"{",
"}",
",",
"jsonConfig",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"bunyanConfig",
".",
"streams",
")",
")",
"{",
"bunyanConfig",
".",
"stre... | Converts jsonConfig into proper bunyan config. The original object is not modified.
@param {Object} jsonConfig
@returns {Object} bunyanConfig | [
"Converts",
"jsonConfig",
"into",
"proper",
"bunyan",
"config",
".",
"The",
"original",
"object",
"is",
"not",
"modified",
"."
] | de3213cb3cad1c41855987d85c0eac37fc04bade | https://github.com/edappy/bunyan-config/blob/de3213cb3cad1c41855987d85c0eac37fc04bade/index.js#L37-L49 | train |
bahrus/templ-mount | first-templ.js | def | function def(p) {
if (p && p.tagName && p.cls) {
if (customElements.get(p.tagName)) {
console.warn(p.tagName + '!!');
}
else {
customElements.define(p.tagName, p.cls);
}
}
} | javascript | function def(p) {
if (p && p.tagName && p.cls) {
if (customElements.get(p.tagName)) {
console.warn(p.tagName + '!!');
}
else {
customElements.define(p.tagName, p.cls);
}
}
} | [
"function",
"def",
"(",
"p",
")",
"{",
"if",
"(",
"p",
"&&",
"p",
".",
"tagName",
"&&",
"p",
".",
"cls",
")",
"{",
"if",
"(",
"customElements",
".",
"get",
"(",
"p",
".",
"tagName",
")",
")",
"{",
"console",
".",
"warn",
"(",
"p",
".",
"tagNa... | fetch in progress | [
"fetch",
"in",
"progress"
] | e5d4719547632df9c6a21713bbe2c807943d4ef3 | https://github.com/bahrus/templ-mount/blob/e5d4719547632df9c6a21713bbe2c807943d4ef3/first-templ.js#L3-L12 | train |
fullcube/loopback-component-meta | models/meta.js | formatProperties | function formatProperties (properties) {
const result = {}
Object.keys(properties).forEach(key => {
debug('formatProperties: key: ' + key)
if (properties.hasOwnProperty(key)) {
result[ key ] = _.clone(properties[ key ])
result[ key ].type = properties[ key ].type.name
}
})
... | javascript | function formatProperties (properties) {
const result = {}
Object.keys(properties).forEach(key => {
debug('formatProperties: key: ' + key)
if (properties.hasOwnProperty(key)) {
result[ key ] = _.clone(properties[ key ])
result[ key ].type = properties[ key ].type.name
}
})
... | [
"function",
"formatProperties",
"(",
"properties",
")",
"{",
"const",
"result",
"=",
"{",
"}",
"Object",
".",
"keys",
"(",
"properties",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"debug",
"(",
"'formatProperties: key: '",
"+",
"key",
")",
"if",
"(",
"p... | Helper method for format the type of the properties | [
"Helper",
"method",
"for",
"format",
"the",
"type",
"of",
"the",
"properties"
] | b91bc0e93881f8e47ac88a77d4a91231053b219a | https://github.com/fullcube/loopback-component-meta/blob/b91bc0e93881f8e47ac88a77d4a91231053b219a/models/meta.js#L30-L40 | train |
fullcube/loopback-component-meta | models/meta.js | getModelInfo | function getModelInfo (modelName) {
debug('getModelInfo: ' + modelName)
// Get the model
const model = Meta.app.models[ modelName ]
// Create the base return object
const result = {
id: model.definition.name,
name: model.definition.name,
properties: formatProperties(model.definit... | javascript | function getModelInfo (modelName) {
debug('getModelInfo: ' + modelName)
// Get the model
const model = Meta.app.models[ modelName ]
// Create the base return object
const result = {
id: model.definition.name,
name: model.definition.name,
properties: formatProperties(model.definit... | [
"function",
"getModelInfo",
"(",
"modelName",
")",
"{",
"debug",
"(",
"'getModelInfo: '",
"+",
"modelName",
")",
"// Get the model",
"const",
"model",
"=",
"Meta",
".",
"app",
".",
"models",
"[",
"modelName",
"]",
"// Create the base return object",
"const",
"resu... | Get the definition of a model and format the result in a way that's similar to a LoopBack model definition file | [
"Get",
"the",
"definition",
"of",
"a",
"model",
"and",
"format",
"the",
"result",
"in",
"a",
"way",
"that",
"s",
"similar",
"to",
"a",
"LoopBack",
"model",
"definition",
"file"
] | b91bc0e93881f8e47ac88a77d4a91231053b219a | https://github.com/fullcube/loopback-component-meta/blob/b91bc0e93881f8e47ac88a77d4a91231053b219a/models/meta.js#L45-L79 | train |
theworkers/W.js | redis/redis-set-storage.js | function (req, res) {
self.getItems(function (err, result) {
if (!err) {
res.json( result );
} else {
res.json(500, { error: err });
}
});
} | javascript | function (req, res) {
self.getItems(function (err, result) {
if (!err) {
res.json( result );
} else {
res.json(500, { error: err });
}
});
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"self",
".",
"getItems",
"(",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"res",
".",
"json",
"(",
"result",
")",
";",
"}",
"else",
"{",
"res",
".",
"json",
"... | Returns a JSON list of all the items | [
"Returns",
"a",
"JSON",
"list",
"of",
"all",
"the",
"items"
] | 25a11baf8edb27c306f2baf6438bed2faf935bc6 | https://github.com/theworkers/W.js/blob/25a11baf8edb27c306f2baf6438bed2faf935bc6/redis/redis-set-storage.js#L11-L19 | train | |
theworkers/W.js | redis/redis-set-storage.js | function (req, res) {
// Add items
if (req.body.items instanceof Array) {
self.removeItems(req.body.items, function (err, result) {
if (!err) {
res.json( result );
} else {
res.json(500, { err... | javascript | function (req, res) {
// Add items
if (req.body.items instanceof Array) {
self.removeItems(req.body.items, function (err, result) {
if (!err) {
res.json( result );
} else {
res.json(500, { err... | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"// Add items",
"if",
"(",
"req",
".",
"body",
".",
"items",
"instanceof",
"Array",
")",
"{",
"self",
".",
"removeItems",
"(",
"req",
".",
"body",
".",
"items",
",",
"function",
"(",
"err",
",",
"result",... | Expects an JSON object in the request with an array of items called `items`. | [
"Expects",
"an",
"JSON",
"object",
"in",
"the",
"request",
"with",
"an",
"array",
"of",
"items",
"called",
"items",
"."
] | 25a11baf8edb27c306f2baf6438bed2faf935bc6 | https://github.com/theworkers/W.js/blob/25a11baf8edb27c306f2baf6438bed2faf935bc6/redis/redis-set-storage.js#L21-L34 | train | |
cheminfo-js/mzData | src/index.js | mzData | function mzData(xml) {
xml = ensureText(xml);
if (typeof xml !== 'string') throw new TypeError('xml must be a string');
let parsed = FastXmlParser.parse(xml, {
textNodeName: '_data',
attributeNamePrefix: '',
parseAttributeValue: true,
attrNodeName: '_attr',
ignoreAttributes: false
});
i... | javascript | function mzData(xml) {
xml = ensureText(xml);
if (typeof xml !== 'string') throw new TypeError('xml must be a string');
let parsed = FastXmlParser.parse(xml, {
textNodeName: '_data',
attributeNamePrefix: '',
parseAttributeValue: true,
attrNodeName: '_attr',
ignoreAttributes: false
});
i... | [
"function",
"mzData",
"(",
"xml",
")",
"{",
"xml",
"=",
"ensureText",
"(",
"xml",
")",
";",
"if",
"(",
"typeof",
"xml",
"!==",
"'string'",
")",
"throw",
"new",
"TypeError",
"(",
"'xml must be a string'",
")",
";",
"let",
"parsed",
"=",
"FastXmlParser",
"... | Reads a mzData v1.05 file
@param {ArrayBuffer|string} xml - ArrayBuffer or String or any Typed Array (including Node.js' Buffer from v4) with the data
@return {{times: Array<number>, series: { ms: { data:Array<Array<number>>}}}} | [
"Reads",
"a",
"mzData",
"v1",
".",
"05",
"file"
] | 85b2d8d5ca3a72bd2c93f6c3f823d24471b1879a | https://github.com/cheminfo-js/mzData/blob/85b2d8d5ca3a72bd2c93f6c3f823d24471b1879a/src/index.js#L14-L44 | train |
Tixit/EmitterB | src/EmitterB.js | triggerIfHandlers | function triggerIfHandlers(that, handlerListName, event) {
triggerIfHandlerList(that[handlerListName][event], event)
triggerIfHandlerList(that[normalHandlerToAllHandlerProperty(handlerListName)], event)
} | javascript | function triggerIfHandlers(that, handlerListName, event) {
triggerIfHandlerList(that[handlerListName][event], event)
triggerIfHandlerList(that[normalHandlerToAllHandlerProperty(handlerListName)], event)
} | [
"function",
"triggerIfHandlers",
"(",
"that",
",",
"handlerListName",
",",
"event",
")",
"{",
"triggerIfHandlerList",
"(",
"that",
"[",
"handlerListName",
"]",
"[",
"event",
"]",
",",
"event",
")",
"triggerIfHandlerList",
"(",
"that",
"[",
"normalHandlerToAllHandl... | triggers the if handlers from the normal list and the "all" list | [
"triggers",
"the",
"if",
"handlers",
"from",
"the",
"normal",
"list",
"and",
"the",
"all",
"list"
] | b94a9ad7a1fb26bb1918a30e2c3dff3e93a2e378 | https://github.com/Tixit/EmitterB/blob/b94a9ad7a1fb26bb1918a30e2c3dff3e93a2e378/src/EmitterB.js#L129-L132 | train |
synder/xpress | demo/body-parser/lib/types/raw.js | raw | function raw (options) {
var opts = options || {}
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'application/octet-stream'
var verify = opts.verify || false
if (verify !== false && typeof ve... | javascript | function raw (options) {
var opts = options || {}
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'application/octet-stream'
var verify = opts.verify || false
if (verify !== false && typeof ve... | [
"function",
"raw",
"(",
"options",
")",
"{",
"var",
"opts",
"=",
"options",
"||",
"{",
"}",
"var",
"inflate",
"=",
"opts",
".",
"inflate",
"!==",
"false",
"var",
"limit",
"=",
"typeof",
"opts",
".",
"limit",
"!==",
"'number'",
"?",
"bytes",
".",
"par... | Create a middleware to parse raw bodies.
@param {object} [options]
@return {function}
@api public | [
"Create",
"a",
"middleware",
"to",
"parse",
"raw",
"bodies",
"."
] | 4b1e89208b6f34cd78ce90b8a858592115b6ccb5 | https://github.com/synder/xpress/blob/4b1e89208b6f34cd78ce90b8a858592115b6ccb5/demo/body-parser/lib/types/raw.js#L32-L88 | train |
feilaoda/power | public/javascripts/vendor/javascripts/validator.js | filter_attributes | function filter_attributes(str) {
var comments = /\/\*.*?\*\//g;
return str.replace(/\s*[a-z-]+\s*=\s*'[^']*'/gi, function (m) {
return m.replace(comments, '');
}).replace(/\s*[a-z-]+\s*=\s*"[^"]*"/gi, function (m) {
return m.replace(comments, '');
}).replace(/\s*... | javascript | function filter_attributes(str) {
var comments = /\/\*.*?\*\//g;
return str.replace(/\s*[a-z-]+\s*=\s*'[^']*'/gi, function (m) {
return m.replace(comments, '');
}).replace(/\s*[a-z-]+\s*=\s*"[^"]*"/gi, function (m) {
return m.replace(comments, '');
}).replace(/\s*... | [
"function",
"filter_attributes",
"(",
"str",
")",
"{",
"var",
"comments",
"=",
"/",
"\\/\\*.*?\\*\\/",
"/",
"g",
";",
"return",
"str",
".",
"replace",
"(",
"/",
"\\s*[a-z-]+\\s*=\\s*'[^']*'",
"/",
"gi",
",",
"function",
"(",
"m",
")",
"{",
"return",
"m",
... | Filter Attributes - filters tag attributes for consistency and safety | [
"Filter",
"Attributes",
"-",
"filters",
"tag",
"attributes",
"for",
"consistency",
"and",
"safety"
] | 89432e5b8e455eceef5f5098d479ad94c88acc59 | https://github.com/feilaoda/power/blob/89432e5b8e455eceef5f5098d479ad94c88acc59/public/javascripts/vendor/javascripts/validator.js#L514-L523 | train |
bonesoul/node-hpool-web | public/js/plugins/input-mask/jquery.inputmask.js | getMaskTemplate | function getMaskTemplate(mask) {
if (opts.numericInput) {
mask = mask.split('').reverse().join('');
}
var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
if (repeat == "*") greedy = false;
//if... | javascript | function getMaskTemplate(mask) {
if (opts.numericInput) {
mask = mask.split('').reverse().join('');
}
var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
if (repeat == "*") greedy = false;
//if... | [
"function",
"getMaskTemplate",
"(",
"mask",
")",
"{",
"if",
"(",
"opts",
".",
"numericInput",
")",
"{",
"mask",
"=",
"mask",
".",
"split",
"(",
"''",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"''",
")",
";",
"}",
"var",
"escaped",
"=",
"fa... | used to keep track of the masks that where processed, to avoid duplicates | [
"used",
"to",
"keep",
"track",
"of",
"the",
"masks",
"that",
"where",
"processed",
"to",
"avoid",
"duplicates"
] | 3d7749b2bcff8b59243939b5b3da19396c4878ff | https://github.com/bonesoul/node-hpool-web/blob/3d7749b2bcff8b59243939b5b3da19396c4878ff/public/js/plugins/input-mask/jquery.inputmask.js#L36-L71 | train |
bonesoul/node-hpool-web | public/js/plugins/input-mask/jquery.inputmask.js | _isValid | function _isValid(position, activeMaskset, c, strict) {
var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '', buffer = activeMaskset["buffer"];
for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
chrs += g... | javascript | function _isValid(position, activeMaskset, c, strict) {
var testPos = determineTestPosition(position), loopend = c ? 1 : 0, chrs = '', buffer = activeMaskset["buffer"];
for (var i = activeMaskset['tests'][testPos].cardinality; i > loopend; i--) {
chrs += g... | [
"function",
"_isValid",
"(",
"position",
",",
"activeMaskset",
",",
"c",
",",
"strict",
")",
"{",
"var",
"testPos",
"=",
"determineTestPosition",
"(",
"position",
")",
",",
"loopend",
"=",
"c",
"?",
"1",
":",
"0",
",",
"chrs",
"=",
"''",
",",
"buffer",... | always set a value to strict to prevent possible strange behavior in the extensions | [
"always",
"set",
"a",
"value",
"to",
"strict",
"to",
"prevent",
"possible",
"strange",
"behavior",
"in",
"the",
"extensions"
] | 3d7749b2bcff8b59243939b5b3da19396c4878ff | https://github.com/bonesoul/node-hpool-web/blob/3d7749b2bcff8b59243939b5b3da19396c4878ff/public/js/plugins/input-mask/jquery.inputmask.js#L266-L282 | train |
bonesoul/node-hpool-web | public/js/plugins/input-mask/jquery.inputmask.js | prepareBuffer | function prepareBuffer(buffer, position) {
var j;
while (buffer[position] == undefined && buffer.length < getMaskLength()) {
j = 0;
while (getActiveBufferTemplate()[j] !== undefined) { //add a new buffer
buffer.push(getActiv... | javascript | function prepareBuffer(buffer, position) {
var j;
while (buffer[position] == undefined && buffer.length < getMaskLength()) {
j = 0;
while (getActiveBufferTemplate()[j] !== undefined) { //add a new buffer
buffer.push(getActiv... | [
"function",
"prepareBuffer",
"(",
"buffer",
",",
"position",
")",
"{",
"var",
"j",
";",
"while",
"(",
"buffer",
"[",
"position",
"]",
"==",
"undefined",
"&&",
"buffer",
".",
"length",
"<",
"getMaskLength",
"(",
")",
")",
"{",
"j",
"=",
"0",
";",
"whi... | needed to handle the non-greedy mask repetitions | [
"needed",
"to",
"handle",
"the",
"non",
"-",
"greedy",
"mask",
"repetitions"
] | 3d7749b2bcff8b59243939b5b3da19396c4878ff | https://github.com/bonesoul/node-hpool-web/blob/3d7749b2bcff8b59243939b5b3da19396c4878ff/public/js/plugins/input-mask/jquery.inputmask.js#L497-L507 | train |
bonesoul/node-hpool-web | public/js/plugins/input-mask/jquery.inputmask.js | shiftL | function shiftL(start, end, c, maskJumps) {
var buffer = getActiveBuffer();
if (maskJumps !== false) //jumping over nonmask position
while (!isMask(start) && start - 1 >= 0) start--;
for (var i = start; i < end && i < getMaskLength() ; i++) {
... | javascript | function shiftL(start, end, c, maskJumps) {
var buffer = getActiveBuffer();
if (maskJumps !== false) //jumping over nonmask position
while (!isMask(start) && start - 1 >= 0) start--;
for (var i = start; i < end && i < getMaskLength() ; i++) {
... | [
"function",
"shiftL",
"(",
"start",
",",
"end",
",",
"c",
",",
"maskJumps",
")",
"{",
"var",
"buffer",
"=",
"getActiveBuffer",
"(",
")",
";",
"if",
"(",
"maskJumps",
"!==",
"false",
")",
"//jumping over nonmask position",
"while",
"(",
"!",
"isMask",
"(",
... | shift chars to left from start to end and put c at end position if defined | [
"shift",
"chars",
"to",
"left",
"from",
"start",
"to",
"end",
"and",
"put",
"c",
"at",
"end",
"position",
"if",
"defined"
] | 3d7749b2bcff8b59243939b5b3da19396c4878ff | https://github.com/bonesoul/node-hpool-web/blob/3d7749b2bcff8b59243939b5b3da19396c4878ff/public/js/plugins/input-mask/jquery.inputmask.js#L791-L824 | train |
onecommons/base | lib/createmodel.js | function(){
baseSchema.constructor.apply(this, arguments);
//copy base schema
var This = this;
baseSchema.eachPath(function(key, val) {
if (key != '__t')
This.paths[key] = val;
});
} | javascript | function(){
baseSchema.constructor.apply(this, arguments);
//copy base schema
var This = this;
baseSchema.eachPath(function(key, val) {
if (key != '__t')
This.paths[key] = val;
});
} | [
"function",
"(",
")",
"{",
"baseSchema",
".",
"constructor",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"//copy base schema",
"var",
"This",
"=",
"this",
";",
"baseSchema",
".",
"eachPath",
"(",
"function",
"(",
"key",
",",
"val",
")",
"{",
... | schema is just the definition create a new schema class derived from the base class | [
"schema",
"is",
"just",
"the",
"definition",
"create",
"a",
"new",
"schema",
"class",
"derived",
"from",
"the",
"base",
"class"
] | 4f35d9f714d0367b0622a3504802363404290246 | https://github.com/onecommons/base/blob/4f35d9f714d0367b0622a3504802363404290246/lib/createmodel.js#L195-L203 | train | |
Whitebolt/require-extra | gulpfile.js | tree | function tree(root) {
var structure = {};
var _files = fs.readdirSync(root);
for(var i=0; i<_files.length; i++) {
if ((_files[i] !== '.') && (_files[i] !== '..')) {
var stats = fs.statSync(root + '/' + _files[i]);
if (stats.isDirectory()) {
structure[_files[i]] = tree(root + '/' + _files[i]);
} else ... | javascript | function tree(root) {
var structure = {};
var _files = fs.readdirSync(root);
for(var i=0; i<_files.length; i++) {
if ((_files[i] !== '.') && (_files[i] !== '..')) {
var stats = fs.statSync(root + '/' + _files[i]);
if (stats.isDirectory()) {
structure[_files[i]] = tree(root + '/' + _files[i]);
} else ... | [
"function",
"tree",
"(",
"root",
")",
"{",
"var",
"structure",
"=",
"{",
"}",
";",
"var",
"_files",
"=",
"fs",
".",
"readdirSync",
"(",
"root",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"_files",
".",
"length",
";",
"i",
"++",
... | Get a tree structure from a directory with given root. Returns required files if files is .js.
@param {string} root The starting directory.
@returns {Object} The structure. | [
"Get",
"a",
"tree",
"structure",
"from",
"a",
"directory",
"with",
"given",
"root",
".",
"Returns",
"required",
"files",
"if",
"files",
"is",
".",
"js",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/gulpfile.js#L21-L42 | train |
Whitebolt/require-extra | gulpfile.js | _createTasks | function _createTasks(tree, parent, tasks) {
parent = parent || "";
tasks = tasks || {};
for (var id in tree) {
if (tree[id].deps && tree[id].fn) {
tasks[parentId(parent, id)] = tree[id];
} else {
_createTasks(tree[id], parentId(parent, id) + ':', tasks)
}
}
return tasks;
} | javascript | function _createTasks(tree, parent, tasks) {
parent = parent || "";
tasks = tasks || {};
for (var id in tree) {
if (tree[id].deps && tree[id].fn) {
tasks[parentId(parent, id)] = tree[id];
} else {
_createTasks(tree[id], parentId(parent, id) + ':', tasks)
}
}
return tasks;
} | [
"function",
"_createTasks",
"(",
"tree",
",",
"parent",
",",
"tasks",
")",
"{",
"parent",
"=",
"parent",
"||",
"\"\"",
";",
"tasks",
"=",
"tasks",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"id",
"in",
"tree",
")",
"{",
"if",
"(",
"tree",
"[",
"id",... | Given a tree structure, create an object of tasks-ids against task objects.
@param {Object} tree The directory tree from tree().
@param {string} [parent=""] The current parent id.
@param {Object} [tasks={}] The task object.
@returns {Object} The flat object, tasks. | [
"Given",
"a",
"tree",
"structure",
"create",
"an",
"object",
"of",
"tasks",
"-",
"ids",
"against",
"task",
"objects",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/gulpfile.js#L63-L76 | train |
Whitebolt/require-extra | gulpfile.js | createTask | function createTask(taskId) {
return function (done) {
var stream = tasks[taskId].fn(gulp, done);
if (stream) {
if (stream.on) stream.on('end', done);
if (stream.then) stream.then(done);
}
};
} | javascript | function createTask(taskId) {
return function (done) {
var stream = tasks[taskId].fn(gulp, done);
if (stream) {
if (stream.on) stream.on('end', done);
if (stream.then) stream.then(done);
}
};
} | [
"function",
"createTask",
"(",
"taskId",
")",
"{",
"return",
"function",
"(",
"done",
")",
"{",
"var",
"stream",
"=",
"tasks",
"[",
"taskId",
"]",
".",
"fn",
"(",
"gulp",
",",
"done",
")",
";",
"if",
"(",
"stream",
")",
"{",
"if",
"(",
"stream",
... | Create a gulp task for the given id.
@param {string} taskId Task id to lookup in tasks and assign.
@returns {Function} The gulp function. | [
"Create",
"a",
"gulp",
"task",
"for",
"the",
"given",
"id",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/gulpfile.js#L94-L102 | train |
EightMedia/collect-components | lib/parser.js | getComponents | function getComponents(templateSrc, filename, options){
var $ = cheerio.load('<div>' + templateSrc + '</div>');
var components = [];
var nodeIndex = 0;
$('*').contents().map(function(index, $el) {
if ($el.type === 'comment') {
var src = $el.data.trim();
// keyword check
if(isComponen... | javascript | function getComponents(templateSrc, filename, options){
var $ = cheerio.load('<div>' + templateSrc + '</div>');
var components = [];
var nodeIndex = 0;
$('*').contents().map(function(index, $el) {
if ($el.type === 'comment') {
var src = $el.data.trim();
// keyword check
if(isComponen... | [
"function",
"getComponents",
"(",
"templateSrc",
",",
"filename",
",",
"options",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"'<div>'",
"+",
"templateSrc",
"+",
"'</div>'",
")",
";",
"var",
"components",
"=",
"[",
"]",
";",
"var",
"nodeIndex... | Returns all components for the given code | [
"Returns",
"all",
"components",
"for",
"the",
"given",
"code"
] | b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4 | https://github.com/EightMedia/collect-components/blob/b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4/lib/parser.js#L35-L71 | train |
EightMedia/collect-components | lib/parser.js | getComponentHtml | function getComponentHtml($, $el, $siblings, keyword, meta) {
var capture = meta.capture;
// default to single node
if (typeof capture === 'undefined') {
capture = 1;
}
// capture fixed number of nodes
if (Number.isInteger(capture) || typeof capture === 'undefined') {
return captureNumber($, $sib... | javascript | function getComponentHtml($, $el, $siblings, keyword, meta) {
var capture = meta.capture;
// default to single node
if (typeof capture === 'undefined') {
capture = 1;
}
// capture fixed number of nodes
if (Number.isInteger(capture) || typeof capture === 'undefined') {
return captureNumber($, $sib... | [
"function",
"getComponentHtml",
"(",
"$",
",",
"$el",
",",
"$siblings",
",",
"keyword",
",",
"meta",
")",
"{",
"var",
"capture",
"=",
"meta",
".",
"capture",
";",
"// default to single node",
"if",
"(",
"typeof",
"capture",
"===",
"'undefined'",
")",
"{",
... | Get html component | [
"Get",
"html",
"component"
] | b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4 | https://github.com/EightMedia/collect-components/blob/b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4/lib/parser.js#L78-L101 | train |
EightMedia/collect-components | lib/parser.js | captureNumber | function captureNumber($, $siblings, capture) {
var nodes = [];
if (typeof capture === 'undefined') {
capture = 1;
}
$($siblings).each(function(n, $node) {
if (n < capture) {
nodes.push($.html($node))
}
});
return nodes;
} | javascript | function captureNumber($, $siblings, capture) {
var nodes = [];
if (typeof capture === 'undefined') {
capture = 1;
}
$($siblings).each(function(n, $node) {
if (n < capture) {
nodes.push($.html($node))
}
});
return nodes;
} | [
"function",
"captureNumber",
"(",
"$",
",",
"$siblings",
",",
"capture",
")",
"{",
"var",
"nodes",
"=",
"[",
"]",
";",
"if",
"(",
"typeof",
"capture",
"===",
"'undefined'",
")",
"{",
"capture",
"=",
"1",
";",
"}",
"$",
"(",
"$siblings",
")",
".",
"... | Capture fixed number of nodes | [
"Capture",
"fixed",
"number",
"of",
"nodes"
] | b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4 | https://github.com/EightMedia/collect-components/blob/b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4/lib/parser.js#L108-L122 | train |
EightMedia/collect-components | lib/parser.js | getExamples | function getExamples(meta){
var examples = [];
if(meta.example){
examples = examples.concat(meta.example);
}
if(meta.examples){
examples = examples.concat(meta.examples);
}
return examples;
} | javascript | function getExamples(meta){
var examples = [];
if(meta.example){
examples = examples.concat(meta.example);
}
if(meta.examples){
examples = examples.concat(meta.examples);
}
return examples;
} | [
"function",
"getExamples",
"(",
"meta",
")",
"{",
"var",
"examples",
"=",
"[",
"]",
";",
"if",
"(",
"meta",
".",
"example",
")",
"{",
"examples",
"=",
"examples",
".",
"concat",
"(",
"meta",
".",
"example",
")",
";",
"}",
"if",
"(",
"meta",
".",
... | get all examples from the meta object
either one or both of meta.example and meta.examples can be given | [
"get",
"all",
"examples",
"from",
"the",
"meta",
"object",
"either",
"one",
"or",
"both",
"of",
"meta",
".",
"example",
"and",
"meta",
".",
"examples",
"can",
"be",
"given"
] | b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4 | https://github.com/EightMedia/collect-components/blob/b83f7b3d771ef9393e5cf6ed4807f4caca6bbfa4/lib/parser.js#L210-L219 | train |
haraldrudell/nodegod | lib/masterlink.js | write | function write(data) {
if (typeof process.send == 'function') process.send(data)
else console.log(emitter.id, 'ipc not available')
} | javascript | function write(data) {
if (typeof process.send == 'function') process.send(data)
else console.log(emitter.id, 'ipc not available')
} | [
"function",
"write",
"(",
"data",
")",
"{",
"if",
"(",
"typeof",
"process",
".",
"send",
"==",
"'function'",
")",
"process",
".",
"send",
"(",
"data",
")",
"else",
"console",
".",
"log",
"(",
"emitter",
".",
"id",
",",
"'ipc not available'",
")",
"}"
] | messages to master process | [
"messages",
"to",
"master",
"process"
] | 3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21 | https://github.com/haraldrudell/nodegod/blob/3be4fb280fb18e0ec0a1c1a8fea3254d92f00b21/lib/masterlink.js#L32-L35 | train |
odogono/elsinore-js | src/entity_set/async_view.js | createUpdateStream | function createUpdateStream(origin, target, options, completeCb) {
// console.log('[EntitySetAsyncView][createUpdateStream]', 'from', origin.cid, 'to', target.cid );
// let source = origin.source(options);
// let sink = target.sink({}, completeCb);
options = { ...options, emitEntities: true };
let ... | javascript | function createUpdateStream(origin, target, options, completeCb) {
// console.log('[EntitySetAsyncView][createUpdateStream]', 'from', origin.cid, 'to', target.cid );
// let source = origin.source(options);
// let sink = target.sink({}, completeCb);
options = { ...options, emitEntities: true };
let ... | [
"function",
"createUpdateStream",
"(",
"origin",
",",
"target",
",",
"options",
",",
"completeCb",
")",
"{",
"// console.log('[EntitySetAsyncView][createUpdateStream]', 'from', origin.cid, 'to', target.cid );",
"// let source = origin.source(options);",
"// let sink = target.sink({}, com... | Creates a pull-stream from the source to the destination
@param {*} entitySet
@param {*} view | [
"Creates",
"a",
"pull",
"-",
"stream",
"from",
"the",
"source",
"to",
"the",
"destination"
] | 1ecce67ad0022646419a740def029b1ba92dd558 | https://github.com/odogono/elsinore-js/blob/1ecce67ad0022646419a740def029b1ba92dd558/src/entity_set/async_view.js#L89-L114 | train |
vid/SenseBase | util/entrez-esearch.js | search | function search(options, callback) {
var queryURI = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=' + options.terms + '&retmode=json&retmax=' + (options.count || 10);
utils.retrieve(queryURI, callback);
} | javascript | function search(options, callback) {
var queryURI = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=' + options.terms + '&retmode=json&retmax=' + (options.count || 10);
utils.retrieve(queryURI, callback);
} | [
"function",
"search",
"(",
"options",
",",
"callback",
")",
"{",
"var",
"queryURI",
"=",
"'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='",
"+",
"options",
".",
"terms",
"+",
"'&retmode=json&retmax='",
"+",
"(",
"options",
".",
"count",
"||",... | Do the actual search. | [
"Do",
"the",
"actual",
"search",
"."
] | d60bcf28239e7dde437d8a6bdae41a6921dcd05b | https://github.com/vid/SenseBase/blob/d60bcf28239e7dde437d8a6bdae41a6921dcd05b/util/entrez-esearch.js#L38-L41 | train |
linyngfly/omelo-scheduler | lib/simpleTrigger.js | function(trigger, job){
this.nextTime = (!!trigger.start)?trigger.start:Date.now();
//The rec
this.period = (!!trigger.period)?trigger.period:-1;
//The running count of the job, -1 means no limit
this.count = (!!trigger.count)?trigger.count:-1;
this.job = job;
} | javascript | function(trigger, job){
this.nextTime = (!!trigger.start)?trigger.start:Date.now();
//The rec
this.period = (!!trigger.period)?trigger.period:-1;
//The running count of the job, -1 means no limit
this.count = (!!trigger.count)?trigger.count:-1;
this.job = job;
} | [
"function",
"(",
"trigger",
",",
"job",
")",
"{",
"this",
".",
"nextTime",
"=",
"(",
"!",
"!",
"trigger",
".",
"start",
")",
"?",
"trigger",
".",
"start",
":",
"Date",
".",
"now",
"(",
")",
";",
"//The rec",
"this",
".",
"period",
"=",
"(",
"!",
... | The constructor of simple trigger | [
"The",
"constructor",
"of",
"simple",
"trigger"
] | aa7775eb2b8b31160669c8fedccd84e2108797eb | https://github.com/linyngfly/omelo-scheduler/blob/aa7775eb2b8b31160669c8fedccd84e2108797eb/lib/simpleTrigger.js#L9-L19 | train | |
gavagai-corp/gavagai-node | lib/RestClient.js | RestClient | function RestClient(apikey, options) {
//Required client config
if (!apikey) {
if (process.env.GAVAGAI_APIKEY) {
this.apikey = process.env.GAVAGAI_APIKEY;
}
else {
throw new Error('RestClient requires an apikey set explicitly or via the GAVAGAI_APIKEY environment... | javascript | function RestClient(apikey, options) {
//Required client config
if (!apikey) {
if (process.env.GAVAGAI_APIKEY) {
this.apikey = process.env.GAVAGAI_APIKEY;
}
else {
throw new Error('RestClient requires an apikey set explicitly or via the GAVAGAI_APIKEY environment... | [
"function",
"RestClient",
"(",
"apikey",
",",
"options",
")",
"{",
"//Required client config",
"if",
"(",
"!",
"apikey",
")",
"{",
"if",
"(",
"process",
".",
"env",
".",
"GAVAGAI_APIKEY",
")",
"{",
"this",
".",
"apikey",
"=",
"process",
".",
"env",
".",
... | The Gavagai REST API client
@constructor
@param {string} apikey - The apikey obtained from Gavagai developer portal
@param {object} options (optional) - optional config for the REST client
- @member {string} host - host for the Gavagai REST API (default: api.gavagai.se)
- @member {string} apiVersion - the Gavagai REST ... | [
"The",
"Gavagai",
"REST",
"API",
"client"
] | d3f5e3f59f25d9c3ebbf6fd3a3ecb70b3a4047eb | https://github.com/gavagai-corp/gavagai-node/blob/d3f5e3f59f25d9c3ebbf6fd3a3ecb70b3a4047eb/lib/RestClient.js#L23-L50 | train |
VizArtJS/vizart-core | src/color/kmeans/index.js | makeMatrix | function makeMatrix(columns, rows) {
let matrix = [];
for (let i = 0; i < columns; i++) {
let column = [];
for (let j = 0; j < rows; j++) {
column.push(0);
}
matrix.push(column);
}
return matrix;
} | javascript | function makeMatrix(columns, rows) {
let matrix = [];
for (let i = 0; i < columns; i++) {
let column = [];
for (let j = 0; j < rows; j++) {
column.push(0);
}
matrix.push(column);
}
return matrix;
} | [
"function",
"makeMatrix",
"(",
"columns",
",",
"rows",
")",
"{",
"let",
"matrix",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"columns",
";",
"i",
"++",
")",
"{",
"let",
"column",
"=",
"[",
"]",
";",
"for",
"(",
"let"... | Create a new column x row matrix.
@private
@param {number} columns
@param {number} rows
@return {Array<Array<number>>} matrix
@example
makeMatrix(10, 10); | [
"Create",
"a",
"new",
"column",
"x",
"row",
"matrix",
"."
] | ac1d050d2ccaca75bf223439cd6e856b4eb2d69c | https://github.com/VizArtJS/vizart-core/blob/ac1d050d2ccaca75bf223439cd6e856b4eb2d69c/src/color/kmeans/index.js#L15-L25 | train |
VizArtJS/vizart-core | src/color/kmeans/index.js | ssq | function ssq(j, i, sums, sumsOfSquares) {
let sji; // s(j, i)
if (j > 0) {
let muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)
sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;
} else {
sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);
}
if (sji < 0) {
re... | javascript | function ssq(j, i, sums, sumsOfSquares) {
let sji; // s(j, i)
if (j > 0) {
let muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)
sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;
} else {
sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);
}
if (sji < 0) {
re... | [
"function",
"ssq",
"(",
"j",
",",
"i",
",",
"sums",
",",
"sumsOfSquares",
")",
"{",
"let",
"sji",
";",
"// s(j, i)",
"if",
"(",
"j",
">",
"0",
")",
"{",
"let",
"muji",
"=",
"(",
"sums",
"[",
"i",
"]",
"-",
"sums",
"[",
"j",
"-",
"1",
"]",
"... | Generates incrementally computed values based on the sums and sums of
squares for the data array
@private
@param {number} j
@param {number} i
@param {Array<number>} sums
@param {Array<number>} sumsOfSquares
@return {number}
@example
ssq(0, 1, [-1, 0, 2], [1, 1, 5]); | [
"Generates",
"incrementally",
"computed",
"values",
"based",
"on",
"the",
"sums",
"and",
"sums",
"of",
"squares",
"for",
"the",
"data",
"array"
] | ac1d050d2ccaca75bf223439cd6e856b4eb2d69c | https://github.com/VizArtJS/vizart-core/blob/ac1d050d2ccaca75bf223439cd6e856b4eb2d69c/src/color/kmeans/index.js#L40-L52 | train |
VizArtJS/vizart-core | src/color/kmeans/index.js | fillMatrixColumn | function fillMatrixColumn(
iMin,
iMax,
cluster,
matrix,
backtrackMatrix,
sums,
sumsOfSquares
) {
if (iMin > iMax) {
return;
}
// Start at midpoint between iMin and iMax
let i = Math.floor((iMin + iMax) / 2);
matrix[cluster][i] = matrix[cluster - 1][i - 1];
backtrackMatrix[cluster][i] = i... | javascript | function fillMatrixColumn(
iMin,
iMax,
cluster,
matrix,
backtrackMatrix,
sums,
sumsOfSquares
) {
if (iMin > iMax) {
return;
}
// Start at midpoint between iMin and iMax
let i = Math.floor((iMin + iMax) / 2);
matrix[cluster][i] = matrix[cluster - 1][i - 1];
backtrackMatrix[cluster][i] = i... | [
"function",
"fillMatrixColumn",
"(",
"iMin",
",",
"iMax",
",",
"cluster",
",",
"matrix",
",",
"backtrackMatrix",
",",
"sums",
",",
"sumsOfSquares",
")",
"{",
"if",
"(",
"iMin",
">",
"iMax",
")",
"{",
"return",
";",
"}",
"// Start at midpoint between iMin and i... | Function that recursively divides and conquers computations
for cluster j
@private
@param {number} iMin Minimum index in cluster to be computed
@param {number} iMax Maximum index in cluster to be computed
@param {number} cluster Index of the cluster currently being computed
@param {Array<Array<number>>} matrix
@param ... | [
"Function",
"that",
"recursively",
"divides",
"and",
"conquers",
"computations",
"for",
"cluster",
"j"
] | ac1d050d2ccaca75bf223439cd6e856b4eb2d69c | https://github.com/VizArtJS/vizart-core/blob/ac1d050d2ccaca75bf223439cd6e856b4eb2d69c/src/color/kmeans/index.js#L67-L146 | train |
VizArtJS/vizart-core | src/color/kmeans/index.js | fillMatrices | function fillMatrices(data, matrix, backtrackMatrix) {
let nValues = matrix[0].length;
// Shift values by the median to improve numeric stability
let shift = data[Math.floor(nValues / 2)];
// Cumulative sum and cumulative sum of squares for all values in data array
let sums = [];
let sumsOfSquares = [];
... | javascript | function fillMatrices(data, matrix, backtrackMatrix) {
let nValues = matrix[0].length;
// Shift values by the median to improve numeric stability
let shift = data[Math.floor(nValues / 2)];
// Cumulative sum and cumulative sum of squares for all values in data array
let sums = [];
let sumsOfSquares = [];
... | [
"function",
"fillMatrices",
"(",
"data",
",",
"matrix",
",",
"backtrackMatrix",
")",
"{",
"let",
"nValues",
"=",
"matrix",
"[",
"0",
"]",
".",
"length",
";",
"// Shift values by the median to improve numeric stability",
"let",
"shift",
"=",
"data",
"[",
"Math",
... | Initializes the main matrices used in Ckmeans and kicks
off the divide and conquer cluster computation strategy
@private
@param {Array<number>} data sorted array of values
@param {Array<Array<number>>} matrix
@param {Array<Array<number>>} backtrackMatrix | [
"Initializes",
"the",
"main",
"matrices",
"used",
"in",
"Ckmeans",
"and",
"kicks",
"off",
"the",
"divide",
"and",
"conquer",
"cluster",
"computation",
"strategy"
] | ac1d050d2ccaca75bf223439cd6e856b4eb2d69c | https://github.com/VizArtJS/vizart-core/blob/ac1d050d2ccaca75bf223439cd6e856b4eb2d69c/src/color/kmeans/index.js#L157-L203 | train |
ayebear/picoes | src/utilities.js | invoke | function invoke(object, method, ...args) {
if (object && typeof object[method] === 'function') {
return object[method].call(object, ...args)
}
} | javascript | function invoke(object, method, ...args) {
if (object && typeof object[method] === 'function') {
return object[method].call(object, ...args)
}
} | [
"function",
"invoke",
"(",
"object",
",",
"method",
",",
"...",
"args",
")",
"{",
"if",
"(",
"object",
"&&",
"typeof",
"object",
"[",
"method",
"]",
"===",
"'function'",
")",
"{",
"return",
"object",
"[",
"method",
"]",
".",
"call",
"(",
"object",
",... | Utility function for invoking methods inside objects, binding "this" to the object.
@ignore
@param {Object} object - The object
@param {Function} method - The method
@param {Array} args - The arguments
@return {Object} Returns what the called method returns | [
"Utility",
"function",
"for",
"invoking",
"methods",
"inside",
"objects",
"binding",
"this",
"to",
"the",
"object",
"."
] | 2f3055172ed28047ae9ba0ade802a286a9bf6649 | https://github.com/ayebear/picoes/blob/2f3055172ed28047ae9ba0ade802a286a9bf6649/src/utilities.js#L12-L16 | train |
simonsmith/grunt-suitcss | tasks/grunt-suitcss.js | buildComponentAndCheckConformance | function buildComponentAndCheckConformance(filepath) {
var componentDir = path.join(process.cwd(), path.dirname(filepath));
var deferred = Q.defer();
resolve(componentDir, options.resolveOpts, function(err, tree) {
if (err) {
return deferred.reject(err);
}
var build = Build(flatten(tree));
... | javascript | function buildComponentAndCheckConformance(filepath) {
var componentDir = path.join(process.cwd(), path.dirname(filepath));
var deferred = Q.defer();
resolve(componentDir, options.resolveOpts, function(err, tree) {
if (err) {
return deferred.reject(err);
}
var build = Build(flatten(tree));
... | [
"function",
"buildComponentAndCheckConformance",
"(",
"filepath",
")",
"{",
"var",
"componentDir",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"path",
".",
"dirname",
"(",
"filepath",
")",
")",
";",
"var",
"deferred",
"=",
"Q",
"... | Builds a component package based on a component.json file.
Will install packages if they don't exist locally.
Validate each component before returning built files | [
"Builds",
"a",
"component",
"package",
"based",
"on",
"a",
"component",
".",
"json",
"file",
".",
"Will",
"install",
"packages",
"if",
"they",
"don",
"t",
"exist",
"locally",
".",
"Validate",
"each",
"component",
"before",
"returning",
"built",
"files"
] | 132018dcfc8f08fc4bbcba198b77c3e230cc5e75 | https://github.com/simonsmith/grunt-suitcss/blob/132018dcfc8f08fc4bbcba198b77c3e230cc5e75/tasks/grunt-suitcss.js#L75-L116 | train |
simonsmith/grunt-suitcss | tasks/grunt-suitcss.js | checkConformance | function checkConformance(filepath) {
var file = grunt.file.read(filepath);
var deferred = Q.defer();
if (options.conform) {
try {
conform(file);
} catch (e) {
deferred.reject(e);
return deferred.promise;
}
}
deferred.resolve(file);
return deferred.promise;
} | javascript | function checkConformance(filepath) {
var file = grunt.file.read(filepath);
var deferred = Q.defer();
if (options.conform) {
try {
conform(file);
} catch (e) {
deferred.reject(e);
return deferred.promise;
}
}
deferred.resolve(file);
return deferred.promise;
} | [
"function",
"checkConformance",
"(",
"filepath",
")",
"{",
"var",
"file",
"=",
"grunt",
".",
"file",
".",
"read",
"(",
"filepath",
")",
";",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"if",
"(",
"options",
".",
"conform",
")",
"{",
"... | Run on individual components | [
"Run",
"on",
"individual",
"components"
] | 132018dcfc8f08fc4bbcba198b77c3e230cc5e75 | https://github.com/simonsmith/grunt-suitcss/blob/132018dcfc8f08fc4bbcba198b77c3e230cc5e75/tasks/grunt-suitcss.js#L121-L136 | train |
feedhenry/fh-mbaas-client | lib/admin/appdata/import.js | startJob | function startJob(params, cb) {
var resourcePath = config.addURIParams(constants.APPDATA_BASE_PATH + "/import", params);
var method = "POST";
params.resourcePath = resourcePath;
params.method = method;
params.data = {
filename: params.filename,
filesize: params.filesize
};
mbaasRequest.admin(par... | javascript | function startJob(params, cb) {
var resourcePath = config.addURIParams(constants.APPDATA_BASE_PATH + "/import", params);
var method = "POST";
params.resourcePath = resourcePath;
params.method = method;
params.data = {
filename: params.filename,
filesize: params.filesize
};
mbaasRequest.admin(par... | [
"function",
"startJob",
"(",
"params",
",",
"cb",
")",
"{",
"var",
"resourcePath",
"=",
"config",
".",
"addURIParams",
"(",
"constants",
".",
"APPDATA_BASE_PATH",
"+",
"\"/import\"",
",",
"params",
")",
";",
"var",
"method",
"=",
"\"POST\"",
";",
"params",
... | Start a new appdata import job given domain, environment and app id
@param params Object containing environment, appid and domain | [
"Start",
"a",
"new",
"appdata",
"import",
"job",
"given",
"domain",
"environment",
"and",
"app",
"id"
] | 2d5a9cbb32e1b2464d71ffa18513358fea388859 | https://github.com/feedhenry/fh-mbaas-client/blob/2d5a9cbb32e1b2464d71ffa18513358fea388859/lib/admin/appdata/import.js#L30-L42 | train |
DScheglov/merest | lib/controllers/create.js | create | function create(req, res, next) {
res.__apiMethod = 'create';
const self = this;
const readonly = this.option('create', 'readonly');
const method = this.option('create', 'method');
let data = (method !== 'get') ? req.body : req.query;
if (readonly) {
try {
data = helpers.validateReadonly(
... | javascript | function create(req, res, next) {
res.__apiMethod = 'create';
const self = this;
const readonly = this.option('create', 'readonly');
const method = this.option('create', 'method');
let data = (method !== 'get') ? req.body : req.query;
if (readonly) {
try {
data = helpers.validateReadonly(
... | [
"function",
"create",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"__apiMethod",
"=",
"'create'",
";",
"const",
"self",
"=",
"this",
";",
"const",
"readonly",
"=",
"this",
".",
"option",
"(",
"'create'",
",",
"'readonly'",
")",
";",
"c... | create - the controller that creates a model instance
if instance is creared successfully this controller calls findById controller
@param {express.Request} req the http(s) request
@param {express.Response} res the http(s) response
@param {Function} next the callback should be called if... | [
"create",
"-",
"the",
"controller",
"that",
"creates",
"a",
"model",
"instance",
"if",
"instance",
"is",
"creared",
"successfully",
"this",
"controller",
"calls",
"findById",
"controller"
] | d39e7ef0d56236247773467e9bfe83cb128ebc01 | https://github.com/DScheglov/merest/blob/d39e7ef0d56236247773467e9bfe83cb128ebc01/lib/controllers/create.js#L20-L48 | train |
Whitebolt/require-extra | src/importSettings.js | loadConfig | function loadConfig(id, copyProps, defaultPropValues) {
var cwd = path.normalize(__dirname + '/../');
/**
* Get the package file without error-ing on fail,
*
* @param {string} [filename='package.json'] Package source name.
* @returns {Object} The package file.
*/
func... | javascript | function loadConfig(id, copyProps, defaultPropValues) {
var cwd = path.normalize(__dirname + '/../');
/**
* Get the package file without error-ing on fail,
*
* @param {string} [filename='package.json'] Package source name.
* @returns {Object} The package file.
*/
func... | [
"function",
"loadConfig",
"(",
"id",
",",
"copyProps",
",",
"defaultPropValues",
")",
"{",
"var",
"cwd",
"=",
"path",
".",
"normalize",
"(",
"__dirname",
"+",
"'/../'",
")",
";",
"/**\n * Get the package file without error-ing on fail,\n *\n * @param {string} [filen... | Load config properties from package.json of module.
@param {string} id Id in package.json to grab from.
@param {Array} copyProps Properties to get.
@param {Object} defaultPropValues Default values to apply.
@returns {Object} The config. | [
"Load",
"config",
"properties",
"from",
"package",
".",
"json",
"of",
"module",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/src/importSettings.js#L15-L79 | train |
Whitebolt/require-extra | src/importSettings.js | pick | function pick(from, picks, defaults) {
picks = picks || [];
defaults = defaults || {};
var obj = {};
for (var n=0; n<picks.length; n++) obj[picks[n]] = from[picks[n]] || defaults[picks[n]];
return obj;
} | javascript | function pick(from, picks, defaults) {
picks = picks || [];
defaults = defaults || {};
var obj = {};
for (var n=0; n<picks.length; n++) obj[picks[n]] = from[picks[n]] || defaults[picks[n]];
return obj;
} | [
"function",
"pick",
"(",
"from",
",",
"picks",
",",
"defaults",
")",
"{",
"picks",
"=",
"picks",
"||",
"[",
"]",
";",
"defaults",
"=",
"defaults",
"||",
"{",
"}",
";",
"var",
"obj",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"... | Pick the given properties from the given object, returning a new object.
@param {Object} from Object to take from.
@param {Array} [picks=[]] Properties to pick.
@param {Object} [defaults={}] Defaults to apply.
@returns {Object} | [
"Pick",
"the",
"given",
"properties",
"from",
"the",
"given",
"object",
"returning",
"a",
"new",
"object",
"."
] | 2a8f737aab67305c9fda3ee56aa7953e97cee859 | https://github.com/Whitebolt/require-extra/blob/2a8f737aab67305c9fda3ee56aa7953e97cee859/src/importSettings.js#L58-L65 | train |
cfpb/AtomicComponent | src/components/AtomicComponent.js | function() {
if ( !this.modifiers ) {
return;
}
this.modifiers.forEach( function( modifier ) {
if ( classList.contains( this.element, modifier.ui.base ) ) {
if ( modifier.initialize ) {
this.initializers.push( modifier.initialize );
delete modifier.initialize;
... | javascript | function() {
if ( !this.modifiers ) {
return;
}
this.modifiers.forEach( function( modifier ) {
if ( classList.contains( this.element, modifier.ui.base ) ) {
if ( modifier.initialize ) {
this.initializers.push( modifier.initialize );
delete modifier.initialize;
... | [
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"modifiers",
")",
"{",
"return",
";",
"}",
"this",
".",
"modifiers",
".",
"forEach",
"(",
"function",
"(",
"modifier",
")",
"{",
"if",
"(",
"classList",
".",
"contains",
"(",
"this",
".",
"ele... | Function used to process class modifiers. These should
correspond with BEM modifiers.
@param {Object} attributes - Hash of attributes to set on base element.
@param {Object} atomicComponent - Base component. | [
"Function",
"used",
"to",
"process",
"class",
"modifiers",
".",
"These",
"should",
"correspond",
"with",
"BEM",
"modifiers",
"."
] | f45d7ded6687672c8b701c9910ddfe90c7ede742 | https://github.com/cfpb/AtomicComponent/blob/f45d7ded6687672c8b701c9910ddfe90c7ede742/src/components/AtomicComponent.js#L58-L72 | train | |
tmorin/ceb | dist/systemjs/helper/objects.js | result | function result(object, propName) {
var value = object[propName];
return isFunction(value) ? value() : value;
} | javascript | function result(object, propName) {
var value = object[propName];
return isFunction(value) ? value() : value;
} | [
"function",
"result",
"(",
"object",
",",
"propName",
")",
"{",
"var",
"value",
"=",
"object",
"[",
"propName",
"]",
";",
"return",
"isFunction",
"(",
"value",
")",
"?",
"value",
"(",
")",
":",
"value",
";",
"}"
] | Resolve the value of propName into object.
If the value is a function, it will be executed.
@param {!Object} object the object
@param {!string} propName the property name
@return the resolved value. | [
"Resolve",
"the",
"value",
"of",
"propName",
"into",
"object",
".",
"If",
"the",
"value",
"is",
"a",
"function",
"it",
"will",
"be",
"executed",
"."
] | 7cc0904b482aa99e5123302c5de4401f7a80af02 | https://github.com/tmorin/ceb/blob/7cc0904b482aa99e5123302c5de4401f7a80af02/dist/systemjs/helper/objects.js#L16-L19 | train |
z-open/zlog | lib/zlog.js | getLoggers | function getLoggers() {
return _.sortBy(
loggers.map(function (logger) {
return {
name: logger.name,
level: logger.getLevel(),
parent: logger.getParent() ? logger.getParent().name : ''
};
}),
function (logger) {
... | javascript | function getLoggers() {
return _.sortBy(
loggers.map(function (logger) {
return {
name: logger.name,
level: logger.getLevel(),
parent: logger.getParent() ? logger.getParent().name : ''
};
}),
function (logger) {
... | [
"function",
"getLoggers",
"(",
")",
"{",
"return",
"_",
".",
"sortBy",
"(",
"loggers",
".",
"map",
"(",
"function",
"(",
"logger",
")",
"{",
"return",
"{",
"name",
":",
"logger",
".",
"name",
",",
"level",
":",
"logger",
".",
"getLevel",
"(",
")",
... | provide available loggers and their current level | [
"provide",
"available",
"loggers",
"and",
"their",
"current",
"level"
] | 756f3d1f9e79e3159c5be87ce65da80b4b71f12b | https://github.com/z-open/zlog/blob/756f3d1f9e79e3159c5be87ce65da80b4b71f12b/lib/zlog.js#L66-L78 | train |
z-open/zlog | lib/zlog.js | print | function print() {
getLoggers().forEach(function (logger) {
consoleAppender.log(formatText('Logger %b: %b, parent:%b', logger.name, logger.level, logger.parent));
});
} | javascript | function print() {
getLoggers().forEach(function (logger) {
consoleAppender.log(formatText('Logger %b: %b, parent:%b', logger.name, logger.level, logger.parent));
});
} | [
"function",
"print",
"(",
")",
"{",
"getLoggers",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"logger",
")",
"{",
"consoleAppender",
".",
"log",
"(",
"formatText",
"(",
"'Logger %b: %b, parent:%b'",
",",
"logger",
".",
"name",
",",
"logger",
".",
"leve... | print to the console the logger statuses | [
"print",
"to",
"the",
"console",
"the",
"logger",
"statuses"
] | 756f3d1f9e79e3159c5be87ce65da80b4b71f12b | https://github.com/z-open/zlog/blob/756f3d1f9e79e3159c5be87ce65da80b4b71f12b/lib/zlog.js#L84-L88 | train |
z-open/zlog | lib/zlog.js | setLogger | function setLogger(name, level, appenderNames) {
try {
var logger = getLogger(name);
logger.setLevel(level);
if (appenderNames) {
logger.clearAppenders();
appenderNames.forEach(function (name) {
logger.addAppender(name);
});
}
... | javascript | function setLogger(name, level, appenderNames) {
try {
var logger = getLogger(name);
logger.setLevel(level);
if (appenderNames) {
logger.clearAppenders();
appenderNames.forEach(function (name) {
logger.addAppender(name);
});
}
... | [
"function",
"setLogger",
"(",
"name",
",",
"level",
",",
"appenderNames",
")",
"{",
"try",
"{",
"var",
"logger",
"=",
"getLogger",
"(",
"name",
")",
";",
"logger",
".",
"setLevel",
"(",
"level",
")",
";",
"if",
"(",
"appenderNames",
")",
"{",
"logger",... | if appenderNames are not provided, the rootLogger appender will be used. | [
"if",
"appenderNames",
"are",
"not",
"provided",
"the",
"rootLogger",
"appender",
"will",
"be",
"used",
"."
] | 756f3d1f9e79e3159c5be87ce65da80b4b71f12b | https://github.com/z-open/zlog/blob/756f3d1f9e79e3159c5be87ce65da80b4b71f12b/lib/zlog.js#L157-L173 | train |
z-open/zlog | lib/zlog.js | writeLog | function writeLog(logLevel, writeArgs) {
var logName = loggerName || 'ROOT';
var levelAppenders = [];
var logger;
// child level always overwrite parent levels
// if the child does not allow, no appender even parents' ones won't show
if (getLevelNumber(thisLogger.getLev... | javascript | function writeLog(logLevel, writeArgs) {
var logName = loggerName || 'ROOT';
var levelAppenders = [];
var logger;
// child level always overwrite parent levels
// if the child does not allow, no appender even parents' ones won't show
if (getLevelNumber(thisLogger.getLev... | [
"function",
"writeLog",
"(",
"logLevel",
",",
"writeArgs",
")",
"{",
"var",
"logName",
"=",
"loggerName",
"||",
"'ROOT'",
";",
"var",
"levelAppenders",
"=",
"[",
"]",
";",
"var",
"logger",
";",
"// child level always overwrite parent levels",
"// if the child does n... | write a log entry to all appenders.
All parent loggers will be checked to see if their appenders - if any - should write the log.
Up to the rootLogger. | [
"write",
"a",
"log",
"entry",
"to",
"all",
"appenders",
"."
] | 756f3d1f9e79e3159c5be87ce65da80b4b71f12b | https://github.com/z-open/zlog/blob/756f3d1f9e79e3159c5be87ce65da80b4b71f12b/lib/zlog.js#L301-L328 | train |
z-open/zlog | lib/zlog.js | findLoggerParent | function findLoggerParent(logger) {
if (rootLogger === logger) {
return null;
}
var deep = true;
var hierachy = getHierarchy(logger.name);
var parent;
for (var n = hierachy.length - 1; n >= 0 && !parent; n--) {
parent = _.find(loggers, { name: hierachy[n] })
}
return par... | javascript | function findLoggerParent(logger) {
if (rootLogger === logger) {
return null;
}
var deep = true;
var hierachy = getHierarchy(logger.name);
var parent;
for (var n = hierachy.length - 1; n >= 0 && !parent; n--) {
parent = _.find(loggers, { name: hierachy[n] })
}
return par... | [
"function",
"findLoggerParent",
"(",
"logger",
")",
"{",
"if",
"(",
"rootLogger",
"===",
"logger",
")",
"{",
"return",
"null",
";",
"}",
"var",
"deep",
"=",
"true",
";",
"var",
"hierachy",
"=",
"getHierarchy",
"(",
"logger",
".",
"name",
")",
";",
"var... | Check the logger name and find out if there is any defined parent loggers | [
"Check",
"the",
"logger",
"name",
"and",
"find",
"out",
"if",
"there",
"is",
"any",
"defined",
"parent",
"loggers"
] | 756f3d1f9e79e3159c5be87ce65da80b4b71f12b | https://github.com/z-open/zlog/blob/756f3d1f9e79e3159c5be87ce65da80b4b71f12b/lib/zlog.js#L339-L352 | train |
thinkkoa/think_lib | index.js | define | function define(obj, property, value, setter = false) {
if (setter) {
return Object.defineProperty(obj, property, {
value: value,
writable: true,
configurable: false,
enumerable: true
});
} else {
return Object.defineProperty(obj, property,... | javascript | function define(obj, property, value, setter = false) {
if (setter) {
return Object.defineProperty(obj, property, {
value: value,
writable: true,
configurable: false,
enumerable: true
});
} else {
return Object.defineProperty(obj, property,... | [
"function",
"define",
"(",
"obj",
",",
"property",
",",
"value",
",",
"setter",
"=",
"false",
")",
"{",
"if",
"(",
"setter",
")",
"{",
"return",
"Object",
".",
"defineProperty",
"(",
"obj",
",",
"property",
",",
"{",
"value",
":",
"value",
",",
"writ... | Short for Object.defineProperty,
the property is getter when setter is false
@param {any} obj
@param {any} property
@param {any} value
@param {boolean} [setter=false]
@returns {void} | [
"Short",
"for",
"Object",
".",
"defineProperty",
"the",
"property",
"is",
"getter",
"when",
"setter",
"is",
"false"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L52-L69 | train |
thinkkoa/think_lib | index.js | isNumberString | function isNumberString(value) {
let numberReg = /^((-?\d*\.?\d*(?:e[+-]?\d*(?:\d?\.?|\.?\d?)\d*)?)|(0[0-7]+)|(0x[0-9a-f]+))$/i;
return lodash.isString(value) && !isEmpty(value) && numberReg.test(value);
} | javascript | function isNumberString(value) {
let numberReg = /^((-?\d*\.?\d*(?:e[+-]?\d*(?:\d?\.?|\.?\d?)\d*)?)|(0[0-7]+)|(0x[0-9a-f]+))$/i;
return lodash.isString(value) && !isEmpty(value) && numberReg.test(value);
} | [
"function",
"isNumberString",
"(",
"value",
")",
"{",
"let",
"numberReg",
"=",
"/",
"^((-?\\d*\\.?\\d*(?:e[+-]?\\d*(?:\\d?\\.?|\\.?\\d?)\\d*)?)|(0[0-7]+)|(0x[0-9a-f]+))$",
"/",
"i",
";",
"return",
"lodash",
".",
"isString",
"(",
"value",
")",
"&&",
"!",
"isEmpty",
"("... | Checks if value is a string that contains only numbers
@param {any} value
@returns {boolean} | [
"Checks",
"if",
"value",
"is",
"a",
"string",
"that",
"contains",
"only",
"numbers"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L77-L80 | train |
thinkkoa/think_lib | index.js | isJSONStr | function isJSONStr(value) {
if (!lodash.isString(value)) {
return false;
}
try {
return isJSONObj(JSON.parse(value));
} catch (e) {
return false;
}
} | javascript | function isJSONStr(value) {
if (!lodash.isString(value)) {
return false;
}
try {
return isJSONObj(JSON.parse(value));
} catch (e) {
return false;
}
} | [
"function",
"isJSONStr",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"lodash",
".",
"isString",
"(",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"return",
"isJSONObj",
"(",
"JSON",
".",
"parse",
"(",
"value",
")",
")",
";",
"}",
... | Checks if value is a standard JSON string,
must be a string, and can be deserialized as an plain object or array
@param {any} value
@returns {boolean} | [
"Checks",
"if",
"value",
"is",
"a",
"standard",
"JSON",
"string",
"must",
"be",
"a",
"string",
"and",
"can",
"be",
"deserialized",
"as",
"an",
"plain",
"object",
"or",
"array"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L97-L106 | train |
thinkkoa/think_lib | index.js | isTrueEmpty | function isTrueEmpty(value) {
if (value === undefined || value === null || value === '') {
return true;
}
if (lodash.isNumber(value)) {
return isNaN(value);
}
return false;
} | javascript | function isTrueEmpty(value) {
if (value === undefined || value === null || value === '') {
return true;
}
if (lodash.isNumber(value)) {
return isNaN(value);
}
return false;
} | [
"function",
"isTrueEmpty",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"undefined",
"||",
"value",
"===",
"null",
"||",
"value",
"===",
"''",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"lodash",
".",
"isNumber",
"(",
"value",
")",
")",
... | Checks value is empty,
do not consider empty objects, empty arrays, spaces, tabs, form breaks, etc.
@param {any} value
@returns {boolean} | [
"Checks",
"value",
"is",
"empty",
"do",
"not",
"consider",
"empty",
"objects",
"empty",
"arrays",
"spaces",
"tabs",
"form",
"breaks",
"etc",
"."
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L114-L122 | train |
thinkkoa/think_lib | index.js | ucFirst | function ucFirst(value) {
value = lodash.toString(value || '');
return value.slice(0, 1).toUpperCase() + value.slice(1).toLowerCase();
} | javascript | function ucFirst(value) {
value = lodash.toString(value || '');
return value.slice(0, 1).toUpperCase() + value.slice(1).toLowerCase();
} | [
"function",
"ucFirst",
"(",
"value",
")",
"{",
"value",
"=",
"lodash",
".",
"toString",
"(",
"value",
"||",
"''",
")",
";",
"return",
"value",
".",
"slice",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"value",
".",
"slice",
"(",
"... | Convert the first letter in the value to uppercase
@param {string} value
@returns {string} | [
"Convert",
"the",
"first",
"letter",
"in",
"the",
"value",
"to",
"uppercase"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L193-L196 | train |
thinkkoa/think_lib | index.js | md5 | function md5(value) {
let ins = crypto.createHash('md5');
ins.update(value);
return ins.digest('hex');
} | javascript | function md5(value) {
let ins = crypto.createHash('md5');
ins.update(value);
return ins.digest('hex');
} | [
"function",
"md5",
"(",
"value",
")",
"{",
"let",
"ins",
"=",
"crypto",
".",
"createHash",
"(",
"'md5'",
")",
";",
"ins",
".",
"update",
"(",
"value",
")",
";",
"return",
"ins",
".",
"digest",
"(",
"'hex'",
")",
";",
"}"
] | Calculate the MD5 hash of value
@param {string} value
@returns {string} | [
"Calculate",
"the",
"MD5",
"hash",
"of",
"value"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L204-L208 | train |
thinkkoa/think_lib | index.js | md5Salt | function md5Salt(value, salt = 'abcdefghijklmnopqrstuvwxyz1234567890') {
let ins = crypto.createHash('md5');
value = value + salt.slice(value.length % salt.length, salt.length);
ins.update(value);
return ins.digest('hex');
} | javascript | function md5Salt(value, salt = 'abcdefghijklmnopqrstuvwxyz1234567890') {
let ins = crypto.createHash('md5');
value = value + salt.slice(value.length % salt.length, salt.length);
ins.update(value);
return ins.digest('hex');
} | [
"function",
"md5Salt",
"(",
"value",
",",
"salt",
"=",
"'abcdefghijklmnopqrstuvwxyz1234567890'",
")",
"{",
"let",
"ins",
"=",
"crypto",
".",
"createHash",
"(",
"'md5'",
")",
";",
"value",
"=",
"value",
"+",
"salt",
".",
"slice",
"(",
"value",
".",
"length"... | Calculate the value of MD5 hash value, including simple salt
@param {string} value
@param {string} [salt='abcdefghijklmnopqrstuvwxyz1234567890']
@returns | [
"Calculate",
"the",
"value",
"of",
"MD5",
"hash",
"value",
"including",
"simple",
"salt"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L217-L222 | train |
thinkkoa/think_lib | index.js | inArray | function inArray(value, arr) {
let len = arr.length;
for (let i = 0; i < len; i++) {
if (arr[i] == value) {
return true;
}
}
return false;
} | javascript | function inArray(value, arr) {
let len = arr.length;
for (let i = 0; i < len; i++) {
if (arr[i] == value) {
return true;
}
}
return false;
} | [
"function",
"inArray",
"(",
"value",
",",
"arr",
")",
"{",
"let",
"len",
"=",
"arr",
".",
"length",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"arr",
"[",
"i",
"]",
"==",
"value",
")",
... | Determines whether value is an element of array arr,
only determine the same value with the element, do not determine the type
@param {any} value
@param {any[]} arr
@returns {boolean} | [
"Determines",
"whether",
"value",
"is",
"an",
"element",
"of",
"array",
"arr",
"only",
"determine",
"the",
"same",
"value",
"with",
"the",
"element",
"do",
"not",
"determine",
"the",
"type"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L288-L296 | train |
thinkkoa/think_lib | index.js | arrRemove | function arrRemove(arr, index) {
return lodash.remove(arr, function (n, i) {
return i !== index;
});
} | javascript | function arrRemove(arr, index) {
return lodash.remove(arr, function (n, i) {
return i !== index;
});
} | [
"function",
"arrRemove",
"(",
"arr",
",",
"index",
")",
"{",
"return",
"lodash",
".",
"remove",
"(",
"arr",
",",
"function",
"(",
"n",
",",
"i",
")",
"{",
"return",
"i",
"!==",
"index",
";",
"}",
")",
";",
"}"
] | Removes the specified index element from the array
@param {any[]} arr
@param {number} index
@returns {any[]} | [
"Removes",
"the",
"specified",
"index",
"element",
"from",
"the",
"array"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L305-L309 | train |
thinkkoa/think_lib | index.js | isFile | function isFile(p) {
if (!fs.existsSync(p)) {
return false;
}
try {
let stats = fs.statSync(p);
return stats.isFile();
} catch (e) {
return false;
}
} | javascript | function isFile(p) {
if (!fs.existsSync(p)) {
return false;
}
try {
let stats = fs.statSync(p);
return stats.isFile();
} catch (e) {
return false;
}
} | [
"function",
"isFile",
"(",
"p",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"let",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"p",
")",
";",
"return",
"stats",
".",
"isFile... | Checks if p is a file
@param {string} p
@returns {boolean} | [
"Checks",
"if",
"p",
"is",
"a",
"file"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L317-L327 | train |
thinkkoa/think_lib | index.js | isDir | function isDir(p) {
if (!fs.existsSync(p)) {
return false;
}
try {
let stats = fs.statSync(p);
return stats.isDirectory();
} catch (e) {
return false;
}
} | javascript | function isDir(p) {
if (!fs.existsSync(p)) {
return false;
}
try {
let stats = fs.statSync(p);
return stats.isDirectory();
} catch (e) {
return false;
}
} | [
"function",
"isDir",
"(",
"p",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"let",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"p",
")",
";",
"return",
"stats",
".",
"isDirec... | Checks if p is a dir
@param {string} p
@returns {boolean} | [
"Checks",
"if",
"p",
"is",
"a",
"dir"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L335-L345 | train |
thinkkoa/think_lib | index.js | isWritable | function isWritable(p) {
if (!fs.existsSync(p)) {
return false;
}
let stats = fs.statSync(p);
let mode = stats.mode;
let uid = process.getuid ? process.getuid() : 0;
let gid = process.getgid ? process.getgid() : 0;
let owner = uid === stats.uid;
let group = gid === stats.gid;
... | javascript | function isWritable(p) {
if (!fs.existsSync(p)) {
return false;
}
let stats = fs.statSync(p);
let mode = stats.mode;
let uid = process.getuid ? process.getuid() : 0;
let gid = process.getgid ? process.getgid() : 0;
let owner = uid === stats.uid;
let group = gid === stats.gid;
... | [
"function",
"isWritable",
"(",
"p",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"return",
"false",
";",
"}",
"let",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"p",
")",
";",
"let",
"mode",
"=",
"stats",
".",
"mode... | Checks if the file or folder p is writable
@param {string} p
@returns {boolean} | [
"Checks",
"if",
"the",
"file",
"or",
"folder",
"p",
"is",
"writable"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L353-L366 | train |
thinkkoa/think_lib | index.js | chmod | function chmod(p, mode) {
mode = mode || 0777;
if (!fs.existsSync(p)) {
return true;
}
return fs.chmodSync(p, mode);
} | javascript | function chmod(p, mode) {
mode = mode || 0777;
if (!fs.existsSync(p)) {
return true;
}
return fs.chmodSync(p, mode);
} | [
"function",
"chmod",
"(",
"p",
",",
"mode",
")",
"{",
"mode",
"=",
"mode",
"||",
"0777",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"fs",
".",
"chmodSync",
"(",
"p",
",",
"mode",... | Modify the permissions of the file or folder p.
Synchronous mode
@param {string} p
@param {number} mode
@returns {*} | [
"Modify",
"the",
"permissions",
"of",
"the",
"file",
"or",
"folder",
"p",
".",
"Synchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L375-L381 | train |
thinkkoa/think_lib | index.js | readFile | function readFile(filename, enc) {
return new Promise(function (fulfill, reject) {
fs.readFile(filename, enc || 'utf8', function (err, res) {
return err ? reject(err) : fulfill(res);
});
});
} | javascript | function readFile(filename, enc) {
return new Promise(function (fulfill, reject) {
fs.readFile(filename, enc || 'utf8', function (err, res) {
return err ? reject(err) : fulfill(res);
});
});
} | [
"function",
"readFile",
"(",
"filename",
",",
"enc",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"fulfill",
",",
"reject",
")",
"{",
"fs",
".",
"readFile",
"(",
"filename",
",",
"enc",
"||",
"'utf8'",
",",
"function",
"(",
"err",
",",
... | Read the contents of the file filename.
Asynchronous mode
@param {string} filename 文件物理路径
@param {undefined | string} enc 为空返回Buffer类型,'utf8'返回String类型
@returns {promise} | [
"Read",
"the",
"contents",
"of",
"the",
"file",
"filename",
".",
"Asynchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L390-L396 | train |
thinkkoa/think_lib | index.js | writeFile | function writeFile(filename, data) {
return new Promise(function (fulfill, reject) {
fs.writeFile(filename, data, function (err, res) {
return err ? reject(err) : fulfill(res);
});
});
} | javascript | function writeFile(filename, data) {
return new Promise(function (fulfill, reject) {
fs.writeFile(filename, data, function (err, res) {
return err ? reject(err) : fulfill(res);
});
});
} | [
"function",
"writeFile",
"(",
"filename",
",",
"data",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"fulfill",
",",
"reject",
")",
"{",
"fs",
".",
"writeFile",
"(",
"filename",
",",
"data",
",",
"function",
"(",
"err",
",",
"res",
")",
... | Write the string data to file.
Asynchronous mode
@param {string} filename
@param {string} data
@returns {promise} | [
"Write",
"the",
"string",
"data",
"to",
"file",
".",
"Asynchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L405-L411 | train |
thinkkoa/think_lib | index.js | reFile | function reFile(filename, nfilename) {
return new Promise(function (fulfill, reject) {
fs.rename(filename, nfilename, function (err) {
return err ? reject(err) : fulfill();
});
});
} | javascript | function reFile(filename, nfilename) {
return new Promise(function (fulfill, reject) {
fs.rename(filename, nfilename, function (err) {
return err ? reject(err) : fulfill();
});
});
} | [
"function",
"reFile",
"(",
"filename",
",",
"nfilename",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"fulfill",
",",
"reject",
")",
"{",
"fs",
".",
"rename",
"(",
"filename",
",",
"nfilename",
",",
"function",
"(",
"err",
")",
"{",
"ret... | Rename the filename to nfilename. If nfilename and filename are not in the same physical path, the move file action will be triggered.
Asynchronous mode
@param {string} filename
@param {string} nfilename
@returns {*} | [
"Rename",
"the",
"filename",
"to",
"nfilename",
".",
"If",
"nfilename",
"and",
"filename",
"are",
"not",
"in",
"the",
"same",
"physical",
"path",
"the",
"move",
"file",
"action",
"will",
"be",
"triggered",
".",
"Asynchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L420-L426 | train |
thinkkoa/think_lib | index.js | mkDir | function mkDir(p, mode = 0777) {
if (fs.existsSync(p)) {
chmod(p, mode);
return true;
} else {
if (mkDir(path.dirname(p))) {
fs.mkdirSync(p, mode);
return true;
}
}
} | javascript | function mkDir(p, mode = 0777) {
if (fs.existsSync(p)) {
chmod(p, mode);
return true;
} else {
if (mkDir(path.dirname(p))) {
fs.mkdirSync(p, mode);
return true;
}
}
} | [
"function",
"mkDir",
"(",
"p",
",",
"mode",
"=",
"0777",
")",
"{",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"p",
")",
")",
"{",
"chmod",
"(",
"p",
",",
"mode",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"mkDir",
"(",
"path"... | According to the path p to create a folder, p contains multi-level new path will be automatically recursively created.
Synchronous mode
@param {string} p
@param {number} mode
@returns {*} | [
"According",
"to",
"the",
"path",
"p",
"to",
"create",
"a",
"folder",
"p",
"contains",
"multi",
"-",
"level",
"new",
"path",
"will",
"be",
"automatically",
"recursively",
"created",
".",
"Synchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L449-L459 | train |
thinkkoa/think_lib | index.js | readDir | function readDir(p, filter, files, prefix) {
prefix = prefix || '';
files = files || [];
filter = filter || function (x) {
return x[0] !== '.';
};
let dir = path.join(p, prefix);
if (!fs.existsSync(dir)) {
return files;
}
if (fs.statSync(dir).isDirectory()) {
fs.... | javascript | function readDir(p, filter, files, prefix) {
prefix = prefix || '';
files = files || [];
filter = filter || function (x) {
return x[0] !== '.';
};
let dir = path.join(p, prefix);
if (!fs.existsSync(dir)) {
return files;
}
if (fs.statSync(dir).isDirectory()) {
fs.... | [
"function",
"readDir",
"(",
"p",
",",
"filter",
",",
"files",
",",
"prefix",
")",
"{",
"prefix",
"=",
"prefix",
"||",
"''",
";",
"files",
"=",
"files",
"||",
"[",
"]",
";",
"filter",
"=",
"filter",
"||",
"function",
"(",
"x",
")",
"{",
"return",
... | Recursively read the path under the p folder.
Synchronous mode
@param {any} p
@param {any} filter
@param {any} files
@param {any} prefix
@returns {*} | [
"Recursively",
"read",
"the",
"path",
"under",
"the",
"p",
"folder",
".",
"Synchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L470-L489 | train |
thinkkoa/think_lib | index.js | rmDir | function rmDir(p, reserve) {
if (!isDir(p)) {
return Promise.resolve(null);
}
let deferred = getDefer();
fs.readdir(p, function (err, files) {
if (err) {
return deferred.reject(err);
}
let spromise = Promise.resolve(null);
if (files.length > 0) {
... | javascript | function rmDir(p, reserve) {
if (!isDir(p)) {
return Promise.resolve(null);
}
let deferred = getDefer();
fs.readdir(p, function (err, files) {
if (err) {
return deferred.reject(err);
}
let spromise = Promise.resolve(null);
if (files.length > 0) {
... | [
"function",
"rmDir",
"(",
"p",
",",
"reserve",
")",
"{",
"if",
"(",
"!",
"isDir",
"(",
"p",
")",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"null",
")",
";",
"}",
"let",
"deferred",
"=",
"getDefer",
"(",
")",
";",
"fs",
".",
"readdir",
... | Subfolders of path p are recursively deleted. When reserve is true, the top-level folder is deleted
Asynchronous mode
@template T
@param {string} p
@param {boolean} reserve
@returns {*} | [
"Subfolders",
"of",
"path",
"p",
"are",
"recursively",
"deleted",
".",
"When",
"reserve",
"is",
"true",
"the",
"top",
"-",
"level",
"folder",
"is",
"deleted",
"Asynchronous",
"mode"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L499-L541 | train |
thinkkoa/think_lib | index.js | generatorToPromise | function generatorToPromise(fn) {
if (typeof fn !== 'function') {
throw Error('fn is not a function');
}
if (!isGenerator(fn)) {
// assume it's Promise-based
return fn;
}
return co.wrap(fn);
} | javascript | function generatorToPromise(fn) {
if (typeof fn !== 'function') {
throw Error('fn is not a function');
}
if (!isGenerator(fn)) {
// assume it's Promise-based
return fn;
}
return co.wrap(fn);
} | [
"function",
"generatorToPromise",
"(",
"fn",
")",
"{",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"{",
"throw",
"Error",
"(",
"'fn is not a function'",
")",
";",
"}",
"if",
"(",
"!",
"isGenerator",
"(",
"fn",
")",
")",
"{",
"// assume it's Promis... | Convert GeneratorFunction fn to Promise
@param {Function} fn
@returns {Promise} | [
"Convert",
"GeneratorFunction",
"fn",
"to",
"Promise"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L597-L606 | train |
thinkkoa/think_lib | index.js | clone | function clone(source, deep) {
if (deep) {
return lodash.cloneDeep(source);
} else {
return lodash.clone(source);
}
} | javascript | function clone(source, deep) {
if (deep) {
return lodash.cloneDeep(source);
} else {
return lodash.clone(source);
}
} | [
"function",
"clone",
"(",
"source",
",",
"deep",
")",
"{",
"if",
"(",
"deep",
")",
"{",
"return",
"lodash",
".",
"cloneDeep",
"(",
"source",
")",
";",
"}",
"else",
"{",
"return",
"lodash",
".",
"clone",
"(",
"source",
")",
";",
"}",
"}"
] | Copy the source, deep deep to true depth copy
@param {any} source
@param {any} deep
@returns {*} | [
"Copy",
"the",
"source",
"deep",
"deep",
"to",
"true",
"depth",
"copy"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L649-L655 | train |
thinkkoa/think_lib | index.js | extend | function extend(source, target, deep) {
if (deep) {
return lodash.merge(lodash.cloneDeep(source), target);
} else {
return lodash.assignIn(source, target);
}
} | javascript | function extend(source, target, deep) {
if (deep) {
return lodash.merge(lodash.cloneDeep(source), target);
} else {
return lodash.assignIn(source, target);
}
} | [
"function",
"extend",
"(",
"source",
",",
"target",
",",
"deep",
")",
"{",
"if",
"(",
"deep",
")",
"{",
"return",
"lodash",
".",
"merge",
"(",
"lodash",
".",
"cloneDeep",
"(",
"source",
")",
",",
"target",
")",
";",
"}",
"else",
"{",
"return",
"lod... | So that the target object inherits the source,
deep depth is true depth inheritance
@param {any} source
@param {any} target
@param {any} deep
@returns {*} | [
"So",
"that",
"the",
"target",
"object",
"inherits",
"the",
"source",
"deep",
"depth",
"is",
"true",
"depth",
"inheritance"
] | 1934e363fb931820c1cca746f34a7306084fa342 | https://github.com/thinkkoa/think_lib/blob/1934e363fb931820c1cca746f34a7306084fa342/index.js#L665-L671 | train |
odogono/elsinore-js | src/entity_set/source.js | pushComponent | function pushComponent(pushable, component, cdefMap, isAnonymous = false, options) {
// if( cdefMap ){
let json = component.toJSON({ cdefMap });
if (isAnonymous) {
delete json[ENTITY_ID];
delete json[COMPONENT_ID];
}
return pushable.push([json, options]);
// }
// pushable.pu... | javascript | function pushComponent(pushable, component, cdefMap, isAnonymous = false, options) {
// if( cdefMap ){
let json = component.toJSON({ cdefMap });
if (isAnonymous) {
delete json[ENTITY_ID];
delete json[COMPONENT_ID];
}
return pushable.push([json, options]);
// }
// pushable.pu... | [
"function",
"pushComponent",
"(",
"pushable",
",",
"component",
",",
"cdefMap",
",",
"isAnonymous",
"=",
"false",
",",
"options",
")",
"{",
"// if( cdefMap ){",
"let",
"json",
"=",
"component",
".",
"toJSON",
"(",
"{",
"cdefMap",
"}",
")",
";",
"if",
"(",
... | Push details of the component to the Pushable stream
@param {*} pushable
@param {*} component
@param {*} cdefMap
@param {*} isAnonymous | [
"Push",
"details",
"of",
"the",
"component",
"to",
"the",
"Pushable",
"stream"
] | 1ecce67ad0022646419a740def029b1ba92dd558 | https://github.com/odogono/elsinore-js/blob/1ecce67ad0022646419a740def029b1ba92dd558/src/entity_set/source.js#L196-L207 | train |
nodejitsu/contour | pagelets/share.js | define | function define() {
var defaults = this.defaults
, data = this.data
, load = data.load || defaults.load
, href = this.href
, def = [];
//
// Check what social media to load, if none provided load defaults in `load`.
//
Object.keys(load).forEach(function checkLoad(key) {
... | javascript | function define() {
var defaults = this.defaults
, data = this.data
, load = data.load || defaults.load
, href = this.href
, def = [];
//
// Check what social media to load, if none provided load defaults in `load`.
//
Object.keys(load).forEach(function checkLoad(key) {
... | [
"function",
"define",
"(",
")",
"{",
"var",
"defaults",
"=",
"this",
".",
"defaults",
",",
"data",
"=",
"this",
".",
"data",
",",
"load",
"=",
"data",
".",
"load",
"||",
"defaults",
".",
"load",
",",
"href",
"=",
"this",
".",
"href",
",",
"def",
... | Define what external JS script should be loaded.
@return {Pagelet}
@api private | [
"Define",
"what",
"external",
"JS",
"script",
"should",
"be",
"loaded",
"."
] | 0828e9bd25ef1eeb97ea231c447118d9867021b6 | https://github.com/nodejitsu/contour/blob/0828e9bd25ef1eeb97ea231c447118d9867021b6/pagelets/share.js#L52-L69 | train |
boneskull/node-fogbugz | index.js | _extractEmptyResponse | function _extractEmptyResponse(xml, dfrd) {
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, res) {
if (err) {
dfrd.reject();
return MODULE_ERRORS.xmlParseError;
}
if (res.response.error) {
dfrd.reject(res.response.error);
}
});
} | javascript | function _extractEmptyResponse(xml, dfrd) {
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, res) {
if (err) {
dfrd.reject();
return MODULE_ERRORS.xmlParseError;
}
if (res.response.error) {
dfrd.reject(res.response.error);
}
});
} | [
"function",
"_extractEmptyResponse",
"(",
"xml",
",",
"dfrd",
")",
"{",
"var",
"parser",
"=",
"new",
"xml2js",
".",
"Parser",
"(",
")",
";",
"parser",
".",
"parseString",
"(",
"xml",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err"... | Basically just asserts an empty response has no errors in it.
@param {string} xml XML to parse
@param {Q.defer} dfrd Q deferred object | [
"Basically",
"just",
"asserts",
"an",
"empty",
"response",
"has",
"no",
"errors",
"in",
"it",
"."
] | 7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a | https://github.com/boneskull/node-fogbugz/blob/7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a/index.js#L159-L170 | train |
boneskull/node-fogbugz | index.js | logoff | function logoff() {
var token = cache.get('token');
var dfrd = Q.defer();
if (!token) {
dfrd.reject(MODULE_ERRORS.undefinedToken);
} else {
request(format(URLs.logoff, PROTOCOL, conf.host, token),
function(err) {
if (err) {
dfrd.reject(err);
} else {
... | javascript | function logoff() {
var token = cache.get('token');
var dfrd = Q.defer();
if (!token) {
dfrd.reject(MODULE_ERRORS.undefinedToken);
} else {
request(format(URLs.logoff, PROTOCOL, conf.host, token),
function(err) {
if (err) {
dfrd.reject(err);
} else {
... | [
"function",
"logoff",
"(",
")",
"{",
"var",
"token",
"=",
"cache",
".",
"get",
"(",
"'token'",
")",
";",
"var",
"dfrd",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"if",
"(",
"!",
"token",
")",
"{",
"dfrd",
".",
"reject",
"(",
"MODULE_ERRORS",
".",
... | Assuming you are logged in and have a cached token, this will log you out.
@method logoff
@returns {Function|promise|Q.promise} Promise | [
"Assuming",
"you",
"are",
"logged",
"in",
"and",
"have",
"a",
"cached",
"token",
"this",
"will",
"log",
"you",
"out",
"."
] | 7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a | https://github.com/boneskull/node-fogbugz/blob/7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a/index.js#L198-L214 | train |
boneskull/node-fogbugz | index.js | logon | function logon() {
var dfrd = Q.defer();
var token = cache.get('token');
function extractToken(xml) {
var r = _parse(xml, dfrd);
if (r) {
return r.response.token[0];
}
}
if (token) {
dfrd.resolve({
token: token,
cached: true
});
}
requ... | javascript | function logon() {
var dfrd = Q.defer();
var token = cache.get('token');
function extractToken(xml) {
var r = _parse(xml, dfrd);
if (r) {
return r.response.token[0];
}
}
if (token) {
dfrd.resolve({
token: token,
cached: true
});
}
requ... | [
"function",
"logon",
"(",
")",
"{",
"var",
"dfrd",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"token",
"=",
"cache",
".",
"get",
"(",
"'token'",
")",
";",
"function",
"extractToken",
"(",
"xml",
")",
"{",
"var",
"r",
"=",
"_parse",
"(",
"xml",... | Logs you into FogBugz based on contents of `fogbugz.conf.json`.
@method logon
@returns {Function|promise|Q.promise} Promise | [
"Logs",
"you",
"into",
"FogBugz",
"based",
"on",
"contents",
"of",
"fogbugz",
".",
"conf",
".",
"json",
"."
] | 7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a | https://github.com/boneskull/node-fogbugz/blob/7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a/index.js#L221-L259 | train |
boneskull/node-fogbugz | index.js | setCurrentFilter | function setCurrentFilter(filter) {
var token = cache.get('token');
var dfrd = Q.defer();
var id;
if (!token) {
dfrd.reject(MODULE_ERRORS.undefinedToken);
} else {
id = typeof filter === 'string' ? filter : filter.id;
request(format(URLs.setCurrentFilter, PROTOCOL, conf.host, id,
... | javascript | function setCurrentFilter(filter) {
var token = cache.get('token');
var dfrd = Q.defer();
var id;
if (!token) {
dfrd.reject(MODULE_ERRORS.undefinedToken);
} else {
id = typeof filter === 'string' ? filter : filter.id;
request(format(URLs.setCurrentFilter, PROTOCOL, conf.host, id,
... | [
"function",
"setCurrentFilter",
"(",
"filter",
")",
"{",
"var",
"token",
"=",
"cache",
".",
"get",
"(",
"'token'",
")",
";",
"var",
"dfrd",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"id",
";",
"if",
"(",
"!",
"token",
")",
"{",
"dfrd",
".",
... | Sets the current Filter. I'm not sure what this does exactly.
@method setCurrentFilter
@param {Filter|string} filter Filter object or string ID
@see class fogbugz.Filter
@returns {Promise.<boolean>} True if success | [
"Sets",
"the",
"current",
"Filter",
".",
"I",
"m",
"not",
"sure",
"what",
"this",
"does",
"exactly",
"."
] | 7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a | https://github.com/boneskull/node-fogbugz/blob/7e5001b5e5b4383348a2713c5ddc943bc8e6fe0a/index.js#L322-L341 | 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.