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 |
---|---|---|---|---|---|---|---|---|---|---|---|
greggman/hft-sample-ui | src/hft/scripts/misc/strings.js | function(str, end) {
return (str.length >= end.length &&
str.substring(str.length - end.length) === end);
} | javascript | function(str, end) {
return (str.length >= end.length &&
str.substring(str.length - end.length) === end);
} | [
"function",
"(",
"str",
",",
"end",
")",
"{",
"return",
"(",
"str",
".",
"length",
">=",
"end",
".",
"length",
"&&",
"str",
".",
"substring",
"(",
"str",
".",
"length",
"-",
"end",
".",
"length",
")",
"===",
"end",
")",
";",
"}"
]
| True if string ends with suffix
@param {String} str string to check for start
@param {String} suffix start value
@returns {Boolean} true if str starts with suffix
@memberOf module:Strings | [
"True",
"if",
"string",
"ends",
"with",
"suffix"
]
| b9e20afd5183db73522bcfae48225c87e01f68c0 | https://github.com/greggman/hft-sample-ui/blob/b9e20afd5183db73522bcfae48225c87e01f68c0/src/hft/scripts/misc/strings.js#L163-L166 | train |
|
vonWolfehaus/gulp-sort-amd | shim/define.js | set | function set(key, module, global) {
var m = null;
var isGlobal = global && typeof global !== 'undefined';
// check to make sure the module has been assigned only once
if (isGlobal) {
if (global.hasOwnProperty(key)) {
throw '[define-shim] Module ' + key + ' already exists';
}
}
else if (_map.hasOwnProperty(key)) {
throw '[define-shim] Module ' + key + ' already exists';
return;
}
// construct the module if needed
if (typeof module === 'function') m = module(get);
else m = module;
// assign the module to whichever object is preferred
if (isGlobal) global[key] = m;
else _map[key] = m;
} | javascript | function set(key, module, global) {
var m = null;
var isGlobal = global && typeof global !== 'undefined';
// check to make sure the module has been assigned only once
if (isGlobal) {
if (global.hasOwnProperty(key)) {
throw '[define-shim] Module ' + key + ' already exists';
}
}
else if (_map.hasOwnProperty(key)) {
throw '[define-shim] Module ' + key + ' already exists';
return;
}
// construct the module if needed
if (typeof module === 'function') m = module(get);
else m = module;
// assign the module to whichever object is preferred
if (isGlobal) global[key] = m;
else _map[key] = m;
} | [
"function",
"set",
"(",
"key",
",",
"module",
",",
"global",
")",
"{",
"var",
"m",
"=",
"null",
";",
"var",
"isGlobal",
"=",
"global",
"&&",
"typeof",
"global",
"!==",
"'undefined'",
";",
"if",
"(",
"isGlobal",
")",
"{",
"if",
"(",
"global",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"throw",
"'[define-shim] Module '",
"+",
"key",
"+",
"' already exists'",
";",
"}",
"}",
"else",
"if",
"(",
"_map",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"throw",
"'[define-shim] Module '",
"+",
"key",
"+",
"' already exists'",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"module",
"===",
"'function'",
")",
"m",
"=",
"module",
"(",
"get",
")",
";",
"else",
"m",
"=",
"module",
";",
"if",
"(",
"isGlobal",
")",
"global",
"[",
"key",
"]",
"=",
"m",
";",
"else",
"_map",
"[",
"key",
"]",
"=",
"m",
";",
"}"
]
| global is an optional object and will attach the constructed module to it if present | [
"global",
"is",
"an",
"optional",
"object",
"and",
"will",
"attach",
"the",
"constructed",
"module",
"to",
"it",
"if",
"present"
]
| d778710d95e0d82de68bd767f063b7430815c330 | https://github.com/vonWolfehaus/gulp-sort-amd/blob/d778710d95e0d82de68bd767f063b7430815c330/shim/define.js#L11-L33 | train |
queckezz/list | lib/insert.js | insert | function insert (i, val, array) {
array = copy(array)
array.splice(i, 0, val)
return array
} | javascript | function insert (i, val, array) {
array = copy(array)
array.splice(i, 0, val)
return array
} | [
"function",
"insert",
"(",
"i",
",",
"val",
",",
"array",
")",
"{",
"array",
"=",
"copy",
"(",
"array",
")",
"array",
".",
"splice",
"(",
"i",
",",
"0",
",",
"val",
")",
"return",
"array",
"}"
]
| Returns a new array with the supplied element inserted
at index `i`.
@param {Int} i
@param {Any} val
@param {Array} array
@return {Array} | [
"Returns",
"a",
"new",
"array",
"with",
"the",
"supplied",
"element",
"inserted",
"at",
"index",
"i",
"."
]
| a26130020b447a1aa136f0fed3283821490f7da4 | https://github.com/queckezz/list/blob/a26130020b447a1aa136f0fed3283821490f7da4/lib/insert.js#L14-L18 | train |
AmrEldib/agol-data-faker | index.js | generateFakeDataForSchema | function generateFakeDataForSchema(schemaName) {
return new RSVP.Promise(function (resolve, reject) {
agolSchemas.getSchema(schemaName).then(function (schema) {
// Generate fake data
var fakeData = jsf(schema);
// return fake data
resolve(fakeData);
});
});
} | javascript | function generateFakeDataForSchema(schemaName) {
return new RSVP.Promise(function (resolve, reject) {
agolSchemas.getSchema(schemaName).then(function (schema) {
// Generate fake data
var fakeData = jsf(schema);
// return fake data
resolve(fakeData);
});
});
} | [
"function",
"generateFakeDataForSchema",
"(",
"schemaName",
")",
"{",
"return",
"new",
"RSVP",
".",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"agolSchemas",
".",
"getSchema",
"(",
"schemaName",
")",
".",
"then",
"(",
"function",
"(",
"schema",
")",
"{",
"var",
"fakeData",
"=",
"jsf",
"(",
"schema",
")",
";",
"resolve",
"(",
"fakeData",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Generate fake data for a certain schema
@param {string} schemaName Name of the schema to be generated.
@returns {object} Promise. The resolve function has one parameter representing the generated fake data. | [
"Generate",
"fake",
"data",
"for",
"a",
"certain",
"schema"
]
| 9bb7e29698a34effd98afe135d053256050a072e | https://github.com/AmrEldib/agol-data-faker/blob/9bb7e29698a34effd98afe135d053256050a072e/index.js#L16-L25 | train |
byu-oit/fully-typed | bin/fully-typed.js | FullyTyped | function FullyTyped (configuration) {
if (arguments.length === 0 || configuration === null) configuration = {};
// validate input parameter
if (!util.isPlainObject(configuration)) {
throw Error('If provided, the schema configuration must be a plain object. Received: ' + configuration);
}
// get a copy of the configuration
const config = util.copy(configuration);
// if type is not specified then use the default
if (!config.type) config.type = 'typed';
// get the controller data
const data = FullyTyped.controllers.get(config.type);
// type is invalid
if (!data) throw Error('Unknown type: ' + config.type);
// return a schema object
return new Schema(config, data);
} | javascript | function FullyTyped (configuration) {
if (arguments.length === 0 || configuration === null) configuration = {};
// validate input parameter
if (!util.isPlainObject(configuration)) {
throw Error('If provided, the schema configuration must be a plain object. Received: ' + configuration);
}
// get a copy of the configuration
const config = util.copy(configuration);
// if type is not specified then use the default
if (!config.type) config.type = 'typed';
// get the controller data
const data = FullyTyped.controllers.get(config.type);
// type is invalid
if (!data) throw Error('Unknown type: ' + config.type);
// return a schema object
return new Schema(config, data);
} | [
"function",
"FullyTyped",
"(",
"configuration",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
"||",
"configuration",
"===",
"null",
")",
"configuration",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"util",
".",
"isPlainObject",
"(",
"configuration",
")",
")",
"{",
"throw",
"Error",
"(",
"'If provided, the schema configuration must be a plain object. Received: '",
"+",
"configuration",
")",
";",
"}",
"const",
"config",
"=",
"util",
".",
"copy",
"(",
"configuration",
")",
";",
"if",
"(",
"!",
"config",
".",
"type",
")",
"config",
".",
"type",
"=",
"'typed'",
";",
"const",
"data",
"=",
"FullyTyped",
".",
"controllers",
".",
"get",
"(",
"config",
".",
"type",
")",
";",
"if",
"(",
"!",
"data",
")",
"throw",
"Error",
"(",
"'Unknown type: '",
"+",
"config",
".",
"type",
")",
";",
"return",
"new",
"Schema",
"(",
"config",
",",
"data",
")",
";",
"}"
]
| Validate a value against the schema and throw an error if encountered.
@function
@name FullyTyped#validate
@param {*} value
@param {string} [prefix='']
@throws {Error}
Get a typed schema.
@constructor
@param {object, object[]} [configuration={}]
@returns {FullyTyped} | [
"Validate",
"a",
"value",
"against",
"the",
"schema",
"and",
"throw",
"an",
"error",
"if",
"encountered",
"."
]
| ed6b3ed88ffc72990acffb765232eaaee261afef | https://github.com/byu-oit/fully-typed/blob/ed6b3ed88ffc72990acffb765232eaaee261afef/bin/fully-typed.js#L71-L93 | train |
justinhelmer/vinyl-tasks | lib/hooks.js | validate | function validate(task, options) {
if (!task) {
if (options.verbose) {
console.log(' -', chalk.bold.yellow('[WARNING]:'), 'Task does not exist');
}
return Promise.resolve(false);
}
return new Promise(function(resolve, reject) {
var hooks = task.hooks(options) || {};
if (hooks.validate) {
var result = hooks.validate();
if (isPromise(result)) {
result.then(function(result) {
resolve(result !== false); // undefined should represent truthy
});
} else {
resolve(result);
}
} else {
resolve(true);
}
});
} | javascript | function validate(task, options) {
if (!task) {
if (options.verbose) {
console.log(' -', chalk.bold.yellow('[WARNING]:'), 'Task does not exist');
}
return Promise.resolve(false);
}
return new Promise(function(resolve, reject) {
var hooks = task.hooks(options) || {};
if (hooks.validate) {
var result = hooks.validate();
if (isPromise(result)) {
result.then(function(result) {
resolve(result !== false); // undefined should represent truthy
});
} else {
resolve(result);
}
} else {
resolve(true);
}
});
} | [
"function",
"validate",
"(",
"task",
",",
"options",
")",
"{",
"if",
"(",
"!",
"task",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"console",
".",
"log",
"(",
"' -'",
",",
"chalk",
".",
"bold",
".",
"yellow",
"(",
"'[WARNING]:'",
")",
",",
"'Task does not exist'",
")",
";",
"}",
"return",
"Promise",
".",
"resolve",
"(",
"false",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"hooks",
"=",
"task",
".",
"hooks",
"(",
"options",
")",
"||",
"{",
"}",
";",
"if",
"(",
"hooks",
".",
"validate",
")",
"{",
"var",
"result",
"=",
"hooks",
".",
"validate",
"(",
")",
";",
"if",
"(",
"isPromise",
"(",
"result",
")",
")",
"{",
"result",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"resolve",
"(",
"result",
"!==",
"false",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"result",
")",
";",
"}",
"}",
"else",
"{",
"resolve",
"(",
"true",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Hook executed before task is run.
Validate whether or not the task should be run. Should return `true` or `false` to indicate whether or not to run the task.
Can also return a bluebird promise that resolves with the value of `true` or `false`.
@name validate
@param {object} task - The task object.
@param {object} [options] - Options passed to the task runner. Uses options.verbose.
@return {bluebird promise} - Resolves with `true` if the task validation succeeds, or `false` if the task validation fails. | [
"Hook",
"executed",
"before",
"task",
"is",
"run",
"."
]
| eca1f79065a3653023896c4f546dc44dbac81e62 | https://github.com/justinhelmer/vinyl-tasks/blob/eca1f79065a3653023896c4f546dc44dbac81e62/lib/hooks.js#L66-L92 | train |
leomp12/console-files | index.js | log | function log (out, desc) {
logger.log(header())
if (desc) {
logger.log(desc)
}
logger.log(out)
logger.log()
} | javascript | function log (out, desc) {
logger.log(header())
if (desc) {
logger.log(desc)
}
logger.log(out)
logger.log()
} | [
"function",
"log",
"(",
"out",
",",
"desc",
")",
"{",
"logger",
".",
"log",
"(",
"header",
"(",
")",
")",
"if",
"(",
"desc",
")",
"{",
"logger",
".",
"log",
"(",
"desc",
")",
"}",
"logger",
".",
"log",
"(",
"out",
")",
"logger",
".",
"log",
"(",
")",
"}"
]
| function to substitute console.log | [
"function",
"to",
"substitute",
"console",
".",
"log"
]
| 07b12b6adee0db8f1bc819f500a3be667838de74 | https://github.com/leomp12/console-files/blob/07b12b6adee0db8f1bc819f500a3be667838de74/index.js#L33-L40 | train |
leomp12/console-files | index.js | error | function error (out, desc) {
logger.error(header())
if (desc) {
logger.error(desc)
}
logger.error(out)
logger.error()
} | javascript | function error (out, desc) {
logger.error(header())
if (desc) {
logger.error(desc)
}
logger.error(out)
logger.error()
} | [
"function",
"error",
"(",
"out",
",",
"desc",
")",
"{",
"logger",
".",
"error",
"(",
"header",
"(",
")",
")",
"if",
"(",
"desc",
")",
"{",
"logger",
".",
"error",
"(",
"desc",
")",
"}",
"logger",
".",
"error",
"(",
"out",
")",
"logger",
".",
"error",
"(",
")",
"}"
]
| function to substitute console.error | [
"function",
"to",
"substitute",
"console",
".",
"error"
]
| 07b12b6adee0db8f1bc819f500a3be667838de74 | https://github.com/leomp12/console-files/blob/07b12b6adee0db8f1bc819f500a3be667838de74/index.js#L43-L50 | train |
robertblackwell/yake | src/yake.js | watch | function watch(glob, taskName)
{
var watcher = chokidar.watch(glob, {persistent: true,});
watcher.on('ready', ()=>
{
watcher.on('all', (event, path)=>
{
invokeTask(taskName);
});
});
} | javascript | function watch(glob, taskName)
{
var watcher = chokidar.watch(glob, {persistent: true,});
watcher.on('ready', ()=>
{
watcher.on('all', (event, path)=>
{
invokeTask(taskName);
});
});
} | [
"function",
"watch",
"(",
"glob",
",",
"taskName",
")",
"{",
"var",
"watcher",
"=",
"chokidar",
".",
"watch",
"(",
"glob",
",",
"{",
"persistent",
":",
"true",
",",
"}",
")",
";",
"watcher",
".",
"on",
"(",
"'ready'",
",",
"(",
")",
"=>",
"{",
"watcher",
".",
"on",
"(",
"'all'",
",",
"(",
"event",
",",
"path",
")",
"=>",
"{",
"invokeTask",
"(",
"taskName",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Watch files and then invoke a task | [
"Watch",
"files",
"and",
"then",
"invoke",
"a",
"task"
]
| 172b02e29303fb718bac88bbda9b85749c57169c | https://github.com/robertblackwell/yake/blob/172b02e29303fb718bac88bbda9b85749c57169c/src/yake.js#L52-L62 | train |
robertblackwell/yake | src/yake.js | invokeTask | function invokeTask(taskName)
{
const tc = TASKS.globals.globalTaskCollection;
const t = tc.getByName(taskName);
if (t === undefined)
{
YERROR.raiseError(`task ${taskName} not found`);
}
TASKS.invokeTask(tc, t);
} | javascript | function invokeTask(taskName)
{
const tc = TASKS.globals.globalTaskCollection;
const t = tc.getByName(taskName);
if (t === undefined)
{
YERROR.raiseError(`task ${taskName} not found`);
}
TASKS.invokeTask(tc, t);
} | [
"function",
"invokeTask",
"(",
"taskName",
")",
"{",
"const",
"tc",
"=",
"TASKS",
".",
"globals",
".",
"globalTaskCollection",
";",
"const",
"t",
"=",
"tc",
".",
"getByName",
"(",
"taskName",
")",
";",
"if",
"(",
"t",
"===",
"undefined",
")",
"{",
"YERROR",
".",
"raiseError",
"(",
"`",
"${",
"taskName",
"}",
"`",
")",
";",
"}",
"TASKS",
".",
"invokeTask",
"(",
"tc",
",",
"t",
")",
";",
"}"
]
| Invoke a task by name | [
"Invoke",
"a",
"task",
"by",
"name"
]
| 172b02e29303fb718bac88bbda9b85749c57169c | https://github.com/robertblackwell/yake/blob/172b02e29303fb718bac88bbda9b85749c57169c/src/yake.js#L67-L77 | train |
creationix/git-node-platform | sha1.js | create | function create() {
var sha1sum = crypto.createHash('sha1');
return { update: update, digest: digest };
function update(data) {
sha1sum.update(data);
}
function digest() {
return sha1sum.digest('hex');
}
} | javascript | function create() {
var sha1sum = crypto.createHash('sha1');
return { update: update, digest: digest };
function update(data) {
sha1sum.update(data);
}
function digest() {
return sha1sum.digest('hex');
}
} | [
"function",
"create",
"(",
")",
"{",
"var",
"sha1sum",
"=",
"crypto",
".",
"createHash",
"(",
"'sha1'",
")",
";",
"return",
"{",
"update",
":",
"update",
",",
"digest",
":",
"digest",
"}",
";",
"function",
"update",
"(",
"data",
")",
"{",
"sha1sum",
".",
"update",
"(",
"data",
")",
";",
"}",
"function",
"digest",
"(",
")",
"{",
"return",
"sha1sum",
".",
"digest",
"(",
"'hex'",
")",
";",
"}",
"}"
]
| A streaming interface for when nothing is passed in. | [
"A",
"streaming",
"interface",
"for",
"when",
"nothing",
"is",
"passed",
"in",
"."
]
| fa9b0367e3b92b6f4f50d93b0d2d7ba93cb27fb9 | https://github.com/creationix/git-node-platform/blob/fa9b0367e3b92b6f4f50d93b0d2d7ba93cb27fb9/sha1.js#L11-L22 | train |
georgenorman/tessel-kit | lib/general-utils.js | function(obj, maxNumProperties) {
var result = "";
maxNumProperties = maxNumProperties === undefined ? Number.MAX_VALUE : maxNumProperties;
if (obj !== undefined && obj !== null) {
var separator = "";
var propCount = 0;
for (var propertyName in obj) {
var objValue;
if ((obj[propertyName]) === undefined) {
objValue = "*** undefined ***";
} else {
objValue = obj[propertyName];
}
result += separator + propertyName + " = " + objValue;
separator = ",\n";
propCount++;
if (propCount >= maxNumProperties) {
break;
}
}
}
return result;
} | javascript | function(obj, maxNumProperties) {
var result = "";
maxNumProperties = maxNumProperties === undefined ? Number.MAX_VALUE : maxNumProperties;
if (obj !== undefined && obj !== null) {
var separator = "";
var propCount = 0;
for (var propertyName in obj) {
var objValue;
if ((obj[propertyName]) === undefined) {
objValue = "*** undefined ***";
} else {
objValue = obj[propertyName];
}
result += separator + propertyName + " = " + objValue;
separator = ",\n";
propCount++;
if (propCount >= maxNumProperties) {
break;
}
}
}
return result;
} | [
"function",
"(",
"obj",
",",
"maxNumProperties",
")",
"{",
"var",
"result",
"=",
"\"\"",
";",
"maxNumProperties",
"=",
"maxNumProperties",
"===",
"undefined",
"?",
"Number",
".",
"MAX_VALUE",
":",
"maxNumProperties",
";",
"if",
"(",
"obj",
"!==",
"undefined",
"&&",
"obj",
"!==",
"null",
")",
"{",
"var",
"separator",
"=",
"\"\"",
";",
"var",
"propCount",
"=",
"0",
";",
"for",
"(",
"var",
"propertyName",
"in",
"obj",
")",
"{",
"var",
"objValue",
";",
"if",
"(",
"(",
"obj",
"[",
"propertyName",
"]",
")",
"===",
"undefined",
")",
"{",
"objValue",
"=",
"\"*** undefined ***\"",
";",
"}",
"else",
"{",
"objValue",
"=",
"obj",
"[",
"propertyName",
"]",
";",
"}",
"result",
"+=",
"separator",
"+",
"propertyName",
"+",
"\" = \"",
"+",
"objValue",
";",
"separator",
"=",
"\",\\n\"",
";",
"\\n",
"propCount",
"++",
";",
"}",
"}",
"if",
"(",
"propCount",
">=",
"maxNumProperties",
")",
"{",
"break",
";",
"}",
"}"
]
| Return a String, of the form "propertyName = propertyValue\n", for every property of the given obj, or until
maxNumProperties has been reached.
@param obj object to retrieve the properties from.
@param maxNumProperties optional limiter for the number of properties to retrieve.
@returns {string} new-line separated set of property/value pairs | [
"Return",
"a",
"String",
"of",
"the",
"form",
"propertyName",
"=",
"propertyValue",
"\\",
"n",
"for",
"every",
"property",
"of",
"the",
"given",
"obj",
"or",
"until",
"maxNumProperties",
"has",
"been",
"reached",
"."
]
| 487e91360f0ecf8500d24297228842e2c01ac762 | https://github.com/georgenorman/tessel-kit/blob/487e91360f0ecf8500d24297228842e2c01ac762/lib/general-utils.js#L86-L115 | train |
|
georgenorman/tessel-kit | lib/general-utils.js | function(argumentName, defaultValue) {
var result = argMap[argumentName];
if (this.isEmpty(result) && this.isNotEmpty(defaultValue)) {
if (typeof defaultValue === 'object') {
result = defaultValue[argumentName];
} else {
result = defaultValue;
}
}
return result;
} | javascript | function(argumentName, defaultValue) {
var result = argMap[argumentName];
if (this.isEmpty(result) && this.isNotEmpty(defaultValue)) {
if (typeof defaultValue === 'object') {
result = defaultValue[argumentName];
} else {
result = defaultValue;
}
}
return result;
} | [
"function",
"(",
"argumentName",
",",
"defaultValue",
")",
"{",
"var",
"result",
"=",
"argMap",
"[",
"argumentName",
"]",
";",
"if",
"(",
"this",
".",
"isEmpty",
"(",
"result",
")",
"&&",
"this",
".",
"isNotEmpty",
"(",
"defaultValue",
")",
")",
"{",
"if",
"(",
"typeof",
"defaultValue",
"===",
"'object'",
")",
"{",
"result",
"=",
"defaultValue",
"[",
"argumentName",
"]",
";",
"}",
"else",
"{",
"result",
"=",
"defaultValue",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Return the commandline argument specified by argumentName. If not found, then return the specified defaultValue.
Example commandline:
"tessel run app/app.js climatePort=A foo=1.23 bar=4.56"
Example Usages (for the commandline shown above):
// returns "1.23"
tesselKit.tesselUtils.getArgumentValue("foo", "asdfgh");
// returns "qwerty"
tesselKit.tesselUtils.getArgumentValue("test", "qwerty"); | [
"Return",
"the",
"commandline",
"argument",
"specified",
"by",
"argumentName",
".",
"If",
"not",
"found",
"then",
"return",
"the",
"specified",
"defaultValue",
"."
]
| 487e91360f0ecf8500d24297228842e2c01ac762 | https://github.com/georgenorman/tessel-kit/blob/487e91360f0ecf8500d24297228842e2c01ac762/lib/general-utils.js#L155-L167 | train |
|
nutella-framework/nutella_lib.js | gulpfile.js | bundle | function bundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('nutella_lib.js'))
.pipe(gulp.dest('./dist'));
} | javascript | function bundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('nutella_lib.js'))
.pipe(gulp.dest('./dist'));
} | [
"function",
"bundle",
"(",
")",
"{",
"return",
"bundler",
".",
"bundle",
"(",
")",
".",
"on",
"(",
"'error'",
",",
"gutil",
".",
"log",
".",
"bind",
"(",
"gutil",
",",
"'Browserify Error'",
")",
")",
".",
"pipe",
"(",
"source",
"(",
"'nutella_lib.js'",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"'./dist'",
")",
")",
";",
"}"
]
| output build logs to terminal | [
"output",
"build",
"logs",
"to",
"terminal"
]
| b3a3406a407e2a1ada6edcc503b70991f9cb249b | https://github.com/nutella-framework/nutella_lib.js/blob/b3a3406a407e2a1ada6edcc503b70991f9cb249b/gulpfile.js#L17-L23 | train |
TheRoSS/jsfilter | lib/error.js | JFP_Error | function JFP_Error(message) {
Error.call(this, message);
Object.defineProperty(this, "name", {
value: this.constructor.name
});
Object.defineProperty(this, "message", {
value: message
});
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
} else {
Object.defineProperty(this, "stack", {
value: (new Error()).stack
});
}
} | javascript | function JFP_Error(message) {
Error.call(this, message);
Object.defineProperty(this, "name", {
value: this.constructor.name
});
Object.defineProperty(this, "message", {
value: message
});
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
} else {
Object.defineProperty(this, "stack", {
value: (new Error()).stack
});
}
} | [
"function",
"JFP_Error",
"(",
"message",
")",
"{",
"Error",
".",
"call",
"(",
"this",
",",
"message",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"name\"",
",",
"{",
"value",
":",
"this",
".",
"constructor",
".",
"name",
"}",
")",
";",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"message\"",
",",
"{",
"value",
":",
"message",
"}",
")",
";",
"if",
"(",
"Error",
".",
"captureStackTrace",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"}",
"else",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"stack\"",
",",
"{",
"value",
":",
"(",
"new",
"Error",
"(",
")",
")",
".",
"stack",
"}",
")",
";",
"}",
"}"
]
| JFP_Error - base error class
@param {string} message
@constructor | [
"JFP_Error",
"-",
"base",
"error",
"class"
]
| e06e689e7ad175eb1479645c9b4e38fadc385cf5 | https://github.com/TheRoSS/jsfilter/blob/e06e689e7ad175eb1479645c9b4e38fadc385cf5/lib/error.js#L17-L35 | train |
AndreasMadsen/piccolo | lib/modules/util.js | type | function type(input) {
//If the input value is null, undefined or NaN the toStringTypes object shouldn't be used
if (input === null || input === undefined || (input !== input && String(input) === "NaN")) {
return String(input);
}
// use the typeMap to detect the type and fallback to object if the type wasn't found
return typeMap[Object.prototype.toString.call(input)] || "object";
} | javascript | function type(input) {
//If the input value is null, undefined or NaN the toStringTypes object shouldn't be used
if (input === null || input === undefined || (input !== input && String(input) === "NaN")) {
return String(input);
}
// use the typeMap to detect the type and fallback to object if the type wasn't found
return typeMap[Object.prototype.toString.call(input)] || "object";
} | [
"function",
"type",
"(",
"input",
")",
"{",
"if",
"(",
"input",
"===",
"null",
"||",
"input",
"===",
"undefined",
"||",
"(",
"input",
"!==",
"input",
"&&",
"String",
"(",
"input",
")",
"===",
"\"NaN\"",
")",
")",
"{",
"return",
"String",
"(",
"input",
")",
";",
"}",
"return",
"typeMap",
"[",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"input",
")",
"]",
"||",
"\"object\"",
";",
"}"
]
| detect type using typeMap | [
"detect",
"type",
"using",
"typeMap"
]
| ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/util.js#L14-L23 | train |
AndreasMadsen/piccolo | lib/modules/util.js | inherits | function inherits(constructor, superConstructor) {
constructor.super_ = superConstructor;
constructor.prototype = Object.create(superConstructor.prototype, {
'constructor': {
'value': constructor,
'enumerable': false,
'writable': true,
'configurable': true
}
});
} | javascript | function inherits(constructor, superConstructor) {
constructor.super_ = superConstructor;
constructor.prototype = Object.create(superConstructor.prototype, {
'constructor': {
'value': constructor,
'enumerable': false,
'writable': true,
'configurable': true
}
});
} | [
"function",
"inherits",
"(",
"constructor",
",",
"superConstructor",
")",
"{",
"constructor",
".",
"super_",
"=",
"superConstructor",
";",
"constructor",
".",
"prototype",
"=",
"Object",
".",
"create",
"(",
"superConstructor",
".",
"prototype",
",",
"{",
"'constructor'",
":",
"{",
"'value'",
":",
"constructor",
",",
"'enumerable'",
":",
"false",
",",
"'writable'",
":",
"true",
",",
"'configurable'",
":",
"true",
"}",
"}",
")",
";",
"}"
]
| Inherit the prototype methods from one constructor into another | [
"Inherit",
"the",
"prototype",
"methods",
"from",
"one",
"constructor",
"into",
"another"
]
| ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d | https://github.com/AndreasMadsen/piccolo/blob/ef43f5634c564eef0d21a4a6aa103b2f1e3baa3d/lib/modules/util.js#L37-L47 | train |
enten/confectioner | lib/confectioner.js | Confectioner | function Confectioner() {
if (!(this instanceof Confectioner)) {
var instance = Object.create(clazz);
Confectioner.apply(instance, arguments);
return instance;
}
this.keys = [];
this.addKey.apply(this, Array.prototype.slice.call(arguments));
} | javascript | function Confectioner() {
if (!(this instanceof Confectioner)) {
var instance = Object.create(clazz);
Confectioner.apply(instance, arguments);
return instance;
}
this.keys = [];
this.addKey.apply(this, Array.prototype.slice.call(arguments));
} | [
"function",
"Confectioner",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Confectioner",
")",
")",
"{",
"var",
"instance",
"=",
"Object",
".",
"create",
"(",
"clazz",
")",
";",
"Confectioner",
".",
"apply",
"(",
"instance",
",",
"arguments",
")",
";",
"return",
"instance",
";",
"}",
"this",
".",
"keys",
"=",
"[",
"]",
";",
"this",
".",
"addKey",
".",
"apply",
"(",
"this",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
";",
"}"
]
| Initialize a new `Confectioner`.
@public
@class
@constructor Confectioner
@param {Mixed} ...
@example var config = Confectioner();
@example var config = Confectioner('env', 'NODE_ENV', 'development');
@example var config = Confectioner({
host: { envName: 'MY_HOST', defValue: 'localhost' },
port: { envName: 'MY_PORT', defValue: 1337 },
}); | [
"Initialize",
"a",
"new",
"Confectioner",
"."
]
| 4f735e8ee1e36ebe250a2a866b07e10820207346 | https://github.com/enten/confectioner/blob/4f735e8ee1e36ebe250a2a866b07e10820207346/lib/confectioner.js#L193-L203 | train |
fardog/node-random-lib | index.js | floatFromBuffer | function floatFromBuffer (buf) {
if (buf.length < FLOAT_ENTROPY_BYTES) {
throw new Error(
'buffer must contain at least ' + FLOAT_ENTROPY_BYTES + ' bytes of entropy'
)
}
var position = 0
// http://stackoverflow.com/questions/15753019/floating-point-number-from-crypto-randombytes-in-javascript
return (((((((
buf[position++] % 32) / 32 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position]) / 256
} | javascript | function floatFromBuffer (buf) {
if (buf.length < FLOAT_ENTROPY_BYTES) {
throw new Error(
'buffer must contain at least ' + FLOAT_ENTROPY_BYTES + ' bytes of entropy'
)
}
var position = 0
// http://stackoverflow.com/questions/15753019/floating-point-number-from-crypto-randombytes-in-javascript
return (((((((
buf[position++] % 32) / 32 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position++]) / 256 +
buf[position]) / 256
} | [
"function",
"floatFromBuffer",
"(",
"buf",
")",
"{",
"if",
"(",
"buf",
".",
"length",
"<",
"FLOAT_ENTROPY_BYTES",
")",
"{",
"throw",
"new",
"Error",
"(",
"'buffer must contain at least '",
"+",
"FLOAT_ENTROPY_BYTES",
"+",
"' bytes of entropy'",
")",
"}",
"var",
"position",
"=",
"0",
"return",
"(",
"(",
"(",
"(",
"(",
"(",
"(",
"buf",
"[",
"position",
"++",
"]",
"%",
"32",
")",
"/",
"32",
"+",
"buf",
"[",
"position",
"++",
"]",
")",
"/",
"256",
"+",
"buf",
"[",
"position",
"++",
"]",
")",
"/",
"256",
"+",
"buf",
"[",
"position",
"++",
"]",
")",
"/",
"256",
"+",
"buf",
"[",
"position",
"++",
"]",
")",
"/",
"256",
"+",
"buf",
"[",
"position",
"++",
"]",
")",
"/",
"256",
"+",
"buf",
"[",
"position",
"]",
")",
"/",
"256",
"}"
]
| Given a buffer containing bytes of entropy, generate a double-precision
64-bit float.
@param {Buffer} buf a buffer of bytes
@returns {Number} a float | [
"Given",
"a",
"buffer",
"containing",
"bytes",
"of",
"entropy",
"generate",
"a",
"double",
"-",
"precision",
"64",
"-",
"bit",
"float",
"."
]
| 1dc05c8ada71049cbd2382239c1c6c6042bf3d97 | https://github.com/fardog/node-random-lib/blob/1dc05c8ada71049cbd2382239c1c6c6042bf3d97/index.js#L142-L159 | train |
fardog/node-random-lib | index.js | applyNSync | function applyNSync () {
var args = Array.prototype.slice.call(arguments)
var fn = args.shift()
var num = args.shift()
var arr = []
for (var i = 0; i < num; ++i) {
arr.push(fn.apply(null, args))
}
return arr
} | javascript | function applyNSync () {
var args = Array.prototype.slice.call(arguments)
var fn = args.shift()
var num = args.shift()
var arr = []
for (var i = 0; i < num; ++i) {
arr.push(fn.apply(null, args))
}
return arr
} | [
"function",
"applyNSync",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
"var",
"fn",
"=",
"args",
".",
"shift",
"(",
")",
"var",
"num",
"=",
"args",
".",
"shift",
"(",
")",
"var",
"arr",
"=",
"[",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"num",
";",
"++",
"i",
")",
"{",
"arr",
".",
"push",
"(",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
")",
"}",
"return",
"arr",
"}"
]
| Apply a function a number of times, returning an array of the results.
@param {Function} fn the function to call on each
@param {Number} num the size of the array to generate
@param {*} args... a list of args to pass to the function fn
@returns {Array} the filled array | [
"Apply",
"a",
"function",
"a",
"number",
"of",
"times",
"returning",
"an",
"array",
"of",
"the",
"results",
"."
]
| 1dc05c8ada71049cbd2382239c1c6c6042bf3d97 | https://github.com/fardog/node-random-lib/blob/1dc05c8ada71049cbd2382239c1c6c6042bf3d97/index.js#L169-L181 | train |
fardog/node-random-lib | index.js | applyN | function applyN (fn, opts, ready) {
var num = opts.num || 0
var unique = opts.unique
var arr = []
fn(opts, onValue)
function onValue (err, value) {
if (err) {
return ready(err)
}
if (!unique || arr.indexOf(value) === -1) {
arr.push(value)
}
if (arr.length >= num) {
return ready(null, arr)
}
process.nextTick(function () {
fn(opts, onValue)
})
}
} | javascript | function applyN (fn, opts, ready) {
var num = opts.num || 0
var unique = opts.unique
var arr = []
fn(opts, onValue)
function onValue (err, value) {
if (err) {
return ready(err)
}
if (!unique || arr.indexOf(value) === -1) {
arr.push(value)
}
if (arr.length >= num) {
return ready(null, arr)
}
process.nextTick(function () {
fn(opts, onValue)
})
}
} | [
"function",
"applyN",
"(",
"fn",
",",
"opts",
",",
"ready",
")",
"{",
"var",
"num",
"=",
"opts",
".",
"num",
"||",
"0",
"var",
"unique",
"=",
"opts",
".",
"unique",
"var",
"arr",
"=",
"[",
"]",
"fn",
"(",
"opts",
",",
"onValue",
")",
"function",
"onValue",
"(",
"err",
",",
"value",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"ready",
"(",
"err",
")",
"}",
"if",
"(",
"!",
"unique",
"||",
"arr",
".",
"indexOf",
"(",
"value",
")",
"===",
"-",
"1",
")",
"{",
"arr",
".",
"push",
"(",
"value",
")",
"}",
"if",
"(",
"arr",
".",
"length",
">=",
"num",
")",
"{",
"return",
"ready",
"(",
"null",
",",
"arr",
")",
"}",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"fn",
"(",
"opts",
",",
"onValue",
")",
"}",
")",
"}",
"}"
]
| Creates an array of items, whose contents are the result of calling
asynchronous function fn once for each item in the array. The function is
called in series, until the array is filled.
@param {Function} fn the function to be called with ({Objct} opts, ready)
where `ready` must be called with (err, value)
@param {Object} opts the options hash that random-lib expects
@param {Function} ready the function to be called with (err, {Array} values) | [
"Creates",
"an",
"array",
"of",
"items",
"whose",
"contents",
"are",
"the",
"result",
"of",
"calling",
"asynchronous",
"function",
"fn",
"once",
"for",
"each",
"item",
"in",
"the",
"array",
".",
"The",
"function",
"is",
"called",
"in",
"series",
"until",
"the",
"array",
"is",
"filled",
"."
]
| 1dc05c8ada71049cbd2382239c1c6c6042bf3d97 | https://github.com/fardog/node-random-lib/blob/1dc05c8ada71049cbd2382239c1c6c6042bf3d97/index.js#L193-L218 | train |
Zenedith/npm-my-restify-api | lib/plugin/cors.js | restifyCORSSimple | function restifyCORSSimple(req, res, next) {
var origin;
if (!(origin = matchOrigin(req, origins))) {
next();
return;
}
function corsOnHeader() {
origin = req.headers.origin;
if (opts.credentials) {
res.setHeader(AC_ALLOW_CREDS, 'true');
}
res.setHeader(AC_ALLOW_ORIGIN, origin);
res.setHeader(AC_EXPOSE_HEADERS, headers.join(', '));
res.setHeader(AC_ALLOW_METHODS, ALLOW_METHODS.join(', '));
res.setHeader(AC_ALLOW_HEADERS, ALLOW_HEADERS.join(', '));
res.setHeader(AC_REQUEST_HEADERS, REQUEST_HEADERS.join(', '));
}
res.once('header', corsOnHeader);
next();
} | javascript | function restifyCORSSimple(req, res, next) {
var origin;
if (!(origin = matchOrigin(req, origins))) {
next();
return;
}
function corsOnHeader() {
origin = req.headers.origin;
if (opts.credentials) {
res.setHeader(AC_ALLOW_CREDS, 'true');
}
res.setHeader(AC_ALLOW_ORIGIN, origin);
res.setHeader(AC_EXPOSE_HEADERS, headers.join(', '));
res.setHeader(AC_ALLOW_METHODS, ALLOW_METHODS.join(', '));
res.setHeader(AC_ALLOW_HEADERS, ALLOW_HEADERS.join(', '));
res.setHeader(AC_REQUEST_HEADERS, REQUEST_HEADERS.join(', '));
}
res.once('header', corsOnHeader);
next();
} | [
"function",
"restifyCORSSimple",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"origin",
";",
"if",
"(",
"!",
"(",
"origin",
"=",
"matchOrigin",
"(",
"req",
",",
"origins",
")",
")",
")",
"{",
"next",
"(",
")",
";",
"return",
";",
"}",
"function",
"corsOnHeader",
"(",
")",
"{",
"origin",
"=",
"req",
".",
"headers",
".",
"origin",
";",
"if",
"(",
"opts",
".",
"credentials",
")",
"{",
"res",
".",
"setHeader",
"(",
"AC_ALLOW_CREDS",
",",
"'true'",
")",
";",
"}",
"res",
".",
"setHeader",
"(",
"AC_ALLOW_ORIGIN",
",",
"origin",
")",
";",
"res",
".",
"setHeader",
"(",
"AC_EXPOSE_HEADERS",
",",
"headers",
".",
"join",
"(",
"', '",
")",
")",
";",
"res",
".",
"setHeader",
"(",
"AC_ALLOW_METHODS",
",",
"ALLOW_METHODS",
".",
"join",
"(",
"', '",
")",
")",
";",
"res",
".",
"setHeader",
"(",
"AC_ALLOW_HEADERS",
",",
"ALLOW_HEADERS",
".",
"join",
"(",
"', '",
")",
")",
";",
"res",
".",
"setHeader",
"(",
"AC_REQUEST_HEADERS",
",",
"REQUEST_HEADERS",
".",
"join",
"(",
"', '",
")",
")",
";",
"}",
"res",
".",
"once",
"(",
"'header'",
",",
"corsOnHeader",
")",
";",
"next",
"(",
")",
";",
"}"
]
| Handler for simple requests | [
"Handler",
"for",
"simple",
"requests"
]
| 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/plugin/cors.js#L82-L105 | train |
Itee/i-return | builds/i-return.js | processErrorAndData | function processErrorAndData (error, data) {
if (_cb.beforeReturnErrorAndData) { _cb.beforeReturnErrorAndData(error, data); }
if (_cb.returnErrorAndData) { _cb.returnErrorAndData(error, data, response); }
if (_cb.afterReturnErrorAndData) { _cb.afterReturnErrorAndData(error, data); }
} | javascript | function processErrorAndData (error, data) {
if (_cb.beforeReturnErrorAndData) { _cb.beforeReturnErrorAndData(error, data); }
if (_cb.returnErrorAndData) { _cb.returnErrorAndData(error, data, response); }
if (_cb.afterReturnErrorAndData) { _cb.afterReturnErrorAndData(error, data); }
} | [
"function",
"processErrorAndData",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"_cb",
".",
"beforeReturnErrorAndData",
")",
"{",
"_cb",
".",
"beforeReturnErrorAndData",
"(",
"error",
",",
"data",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"returnErrorAndData",
")",
"{",
"_cb",
".",
"returnErrorAndData",
"(",
"error",
",",
"data",
",",
"response",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"afterReturnErrorAndData",
")",
"{",
"_cb",
".",
"afterReturnErrorAndData",
"(",
"error",
",",
"data",
")",
";",
"}",
"}"
]
| Call provided callback for error and data case.
@param error - The database receive error
@param data - The database retrieved data | [
"Call",
"provided",
"callback",
"for",
"error",
"and",
"data",
"case",
"."
]
| 895953cb344e0929883863808429a3b8fa61d678 | https://github.com/Itee/i-return/blob/895953cb344e0929883863808429a3b8fa61d678/builds/i-return.js#L314-L318 | train |
Itee/i-return | builds/i-return.js | processError | function processError (error) {
if (_cb.beforeReturnError) { _cb.beforeReturnError(error); }
if (_cb.returnError) { _cb.returnError(error, response); }
if (_cb.afterReturnError) { _cb.afterReturnError(error); }
} | javascript | function processError (error) {
if (_cb.beforeReturnError) { _cb.beforeReturnError(error); }
if (_cb.returnError) { _cb.returnError(error, response); }
if (_cb.afterReturnError) { _cb.afterReturnError(error); }
} | [
"function",
"processError",
"(",
"error",
")",
"{",
"if",
"(",
"_cb",
".",
"beforeReturnError",
")",
"{",
"_cb",
".",
"beforeReturnError",
"(",
"error",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"returnError",
")",
"{",
"_cb",
".",
"returnError",
"(",
"error",
",",
"response",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"afterReturnError",
")",
"{",
"_cb",
".",
"afterReturnError",
"(",
"error",
")",
";",
"}",
"}"
]
| Call provided callback for error case.
@param error - The database receive error | [
"Call",
"provided",
"callback",
"for",
"error",
"case",
"."
]
| 895953cb344e0929883863808429a3b8fa61d678 | https://github.com/Itee/i-return/blob/895953cb344e0929883863808429a3b8fa61d678/builds/i-return.js#L325-L329 | train |
Itee/i-return | builds/i-return.js | processData | function processData (data) {
if (_cb.beforeReturnData) { _cb.beforeReturnData(data); }
if (_cb.returnData) { _cb.returnData(data, response); }
if (_cb.afterReturnData) { _cb.afterReturnData(data); }
} | javascript | function processData (data) {
if (_cb.beforeReturnData) { _cb.beforeReturnData(data); }
if (_cb.returnData) { _cb.returnData(data, response); }
if (_cb.afterReturnData) { _cb.afterReturnData(data); }
} | [
"function",
"processData",
"(",
"data",
")",
"{",
"if",
"(",
"_cb",
".",
"beforeReturnData",
")",
"{",
"_cb",
".",
"beforeReturnData",
"(",
"data",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"returnData",
")",
"{",
"_cb",
".",
"returnData",
"(",
"data",
",",
"response",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"afterReturnData",
")",
"{",
"_cb",
".",
"afterReturnData",
"(",
"data",
")",
";",
"}",
"}"
]
| Call provided callback for data case.
@param data - The database retrieved data | [
"Call",
"provided",
"callback",
"for",
"data",
"case",
"."
]
| 895953cb344e0929883863808429a3b8fa61d678 | https://github.com/Itee/i-return/blob/895953cb344e0929883863808429a3b8fa61d678/builds/i-return.js#L336-L340 | train |
Itee/i-return | builds/i-return.js | processNotFound | function processNotFound () {
if (_cb.beforeReturnNotFound) { _cb.beforeReturnNotFound(); }
if (_cb.returnNotFound) { _cb.returnNotFound(response); }
if (_cb.afterReturnNotFound) { _cb.afterReturnNotFound(); }
} | javascript | function processNotFound () {
if (_cb.beforeReturnNotFound) { _cb.beforeReturnNotFound(); }
if (_cb.returnNotFound) { _cb.returnNotFound(response); }
if (_cb.afterReturnNotFound) { _cb.afterReturnNotFound(); }
} | [
"function",
"processNotFound",
"(",
")",
"{",
"if",
"(",
"_cb",
".",
"beforeReturnNotFound",
")",
"{",
"_cb",
".",
"beforeReturnNotFound",
"(",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"returnNotFound",
")",
"{",
"_cb",
".",
"returnNotFound",
"(",
"response",
")",
";",
"}",
"if",
"(",
"_cb",
".",
"afterReturnNotFound",
")",
"{",
"_cb",
".",
"afterReturnNotFound",
"(",
")",
";",
"}",
"}"
]
| Call provided callback for not found data case. | [
"Call",
"provided",
"callback",
"for",
"not",
"found",
"data",
"case",
"."
]
| 895953cb344e0929883863808429a3b8fa61d678 | https://github.com/Itee/i-return/blob/895953cb344e0929883863808429a3b8fa61d678/builds/i-return.js#L345-L349 | train |
aaaschmitt/hubot-google-auth | auth.js | function(token) {
this.oauthClient.setCredentials(token);
this.brain.set(this.TOKEN_KEY, token.access_token);
if (token.refresh_token) {
this.brain.set(this.REFRESH_KEY, token.refresh_token);
}
this.brain.set(this.EXPIRY_KEY, +token.expiry_date);
this.brain.save();
this.brain.resetSaveInterval(60);
} | javascript | function(token) {
this.oauthClient.setCredentials(token);
this.brain.set(this.TOKEN_KEY, token.access_token);
if (token.refresh_token) {
this.brain.set(this.REFRESH_KEY, token.refresh_token);
}
this.brain.set(this.EXPIRY_KEY, +token.expiry_date);
this.brain.save();
this.brain.resetSaveInterval(60);
} | [
"function",
"(",
"token",
")",
"{",
"this",
".",
"oauthClient",
".",
"setCredentials",
"(",
"token",
")",
";",
"this",
".",
"brain",
".",
"set",
"(",
"this",
".",
"TOKEN_KEY",
",",
"token",
".",
"access_token",
")",
";",
"if",
"(",
"token",
".",
"refresh_token",
")",
"{",
"this",
".",
"brain",
".",
"set",
"(",
"this",
".",
"REFRESH_KEY",
",",
"token",
".",
"refresh_token",
")",
";",
"}",
"this",
".",
"brain",
".",
"set",
"(",
"this",
".",
"EXPIRY_KEY",
",",
"+",
"token",
".",
"expiry_date",
")",
";",
"this",
".",
"brain",
".",
"save",
"(",
")",
";",
"this",
".",
"brain",
".",
"resetSaveInterval",
"(",
"60",
")",
";",
"}"
]
| Stores the token and expire time into the robot brain and
Sets it in the oauthClient
@param token the token object returned from google oauth2 | [
"Stores",
"the",
"token",
"and",
"expire",
"time",
"into",
"the",
"robot",
"brain",
"and",
"Sets",
"it",
"in",
"the",
"oauthClient"
]
| 046c70965022f1aeebc03eede375650c8dcf1b7c | https://github.com/aaaschmitt/hubot-google-auth/blob/046c70965022f1aeebc03eede375650c8dcf1b7c/auth.js#L65-L74 | train |
|
aaaschmitt/hubot-google-auth | auth.js | function(code, cb) {
var self = this;
this.oauthClient.getToken(code, function(err, token) {
if (err) {
cb({
err: err,
msg: 'Error while trying to retrieve access token'
});
return;
}
self.storeToken(token);
cb(null, {
resp: token,
msg: "Google auth code successfully set"
});
});
} | javascript | function(code, cb) {
var self = this;
this.oauthClient.getToken(code, function(err, token) {
if (err) {
cb({
err: err,
msg: 'Error while trying to retrieve access token'
});
return;
}
self.storeToken(token);
cb(null, {
resp: token,
msg: "Google auth code successfully set"
});
});
} | [
"function",
"(",
"code",
",",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"oauthClient",
".",
"getToken",
"(",
"code",
",",
"function",
"(",
"err",
",",
"token",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Error while trying to retrieve access token'",
"}",
")",
";",
"return",
";",
"}",
"self",
".",
"storeToken",
"(",
"token",
")",
";",
"cb",
"(",
"null",
",",
"{",
"resp",
":",
"token",
",",
"msg",
":",
"\"Google auth code successfully set\"",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Used to set the code provided by the generated auth url.
This code is generated for a user and is needed to initiate the oauth2 handshake
@param code the code obtained by a user from the auth url | [
"Used",
"to",
"set",
"the",
"code",
"provided",
"by",
"the",
"generated",
"auth",
"url",
".",
"This",
"code",
"is",
"generated",
"for",
"a",
"user",
"and",
"is",
"needed",
"to",
"initiate",
"the",
"oauth2",
"handshake"
]
| 046c70965022f1aeebc03eede375650c8dcf1b7c | https://github.com/aaaschmitt/hubot-google-auth/blob/046c70965022f1aeebc03eede375650c8dcf1b7c/auth.js#L101-L117 | train |
|
aaaschmitt/hubot-google-auth | auth.js | function(cb) {
var at = this.brain.get(this.TOKEN_KEY),
rt = this.brain.get(this.REFRESH_KEY);
if (at == null || rt == null) {
cb({
err: null,
msg: 'Error: No tokens found. Please authorize this app and store a refresh token'
});
return;
}
var expirTime = this.brain.get(this.EXPIRY_KEY),
curTime = (new Date()) / 1;
var self = this;
if (expirTime < curTime) {
this.oauthClient.refreshAccessToken(function(err, token) {
if (err != null) {
cb({
err: err,
msg: 'Google Authentication Error: error refreshing token'
}, null);
return;
}
self.storeToken(token);
cb(null, {
resp: token,
msg: 'Token refreshed'
});
});
} else {
cb(null);
}
} | javascript | function(cb) {
var at = this.brain.get(this.TOKEN_KEY),
rt = this.brain.get(this.REFRESH_KEY);
if (at == null || rt == null) {
cb({
err: null,
msg: 'Error: No tokens found. Please authorize this app and store a refresh token'
});
return;
}
var expirTime = this.brain.get(this.EXPIRY_KEY),
curTime = (new Date()) / 1;
var self = this;
if (expirTime < curTime) {
this.oauthClient.refreshAccessToken(function(err, token) {
if (err != null) {
cb({
err: err,
msg: 'Google Authentication Error: error refreshing token'
}, null);
return;
}
self.storeToken(token);
cb(null, {
resp: token,
msg: 'Token refreshed'
});
});
} else {
cb(null);
}
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"at",
"=",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"TOKEN_KEY",
")",
",",
"rt",
"=",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"REFRESH_KEY",
")",
";",
"if",
"(",
"at",
"==",
"null",
"||",
"rt",
"==",
"null",
")",
"{",
"cb",
"(",
"{",
"err",
":",
"null",
",",
"msg",
":",
"'Error: No tokens found. Please authorize this app and store a refresh token'",
"}",
")",
";",
"return",
";",
"}",
"var",
"expirTime",
"=",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"EXPIRY_KEY",
")",
",",
"curTime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
"/",
"1",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"expirTime",
"<",
"curTime",
")",
"{",
"this",
".",
"oauthClient",
".",
"refreshAccessToken",
"(",
"function",
"(",
"err",
",",
"token",
")",
"{",
"if",
"(",
"err",
"!=",
"null",
")",
"{",
"cb",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Google Authentication Error: error refreshing token'",
"}",
",",
"null",
")",
";",
"return",
";",
"}",
"self",
".",
"storeToken",
"(",
"token",
")",
";",
"cb",
"(",
"null",
",",
"{",
"resp",
":",
"token",
",",
"msg",
":",
"'Token refreshed'",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"null",
")",
";",
"}",
"}"
]
| Checks the current expire time and determines if the token is valid.
Refreshes the token if it is not valid.
@param cb the callback function (err, resp), use this to make api calls | [
"Checks",
"the",
"current",
"expire",
"time",
"and",
"determines",
"if",
"the",
"token",
"is",
"valid",
".",
"Refreshes",
"the",
"token",
"if",
"it",
"is",
"not",
"valid",
"."
]
| 046c70965022f1aeebc03eede375650c8dcf1b7c | https://github.com/aaaschmitt/hubot-google-auth/blob/046c70965022f1aeebc03eede375650c8dcf1b7c/auth.js#L125-L161 | train |
|
aaaschmitt/hubot-google-auth | auth.js | function() {
return {
token: this.brain.get(this.TOKEN_KEY),
refresh_token: this.brain.get(this.REFRESH_KEY),
expire_date: this.brain.get(this.EXPIRY_KEY)
}
} | javascript | function() {
return {
token: this.brain.get(this.TOKEN_KEY),
refresh_token: this.brain.get(this.REFRESH_KEY),
expire_date: this.brain.get(this.EXPIRY_KEY)
}
} | [
"function",
"(",
")",
"{",
"return",
"{",
"token",
":",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"TOKEN_KEY",
")",
",",
"refresh_token",
":",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"REFRESH_KEY",
")",
",",
"expire_date",
":",
"this",
".",
"brain",
".",
"get",
"(",
"this",
".",
"EXPIRY_KEY",
")",
"}",
"}"
]
| Returns the current set of tokens | [
"Returns",
"the",
"current",
"set",
"of",
"tokens"
]
| 046c70965022f1aeebc03eede375650c8dcf1b7c | https://github.com/aaaschmitt/hubot-google-auth/blob/046c70965022f1aeebc03eede375650c8dcf1b7c/auth.js#L166-L172 | train |
|
CodersBrothers/BtcAverage | btcaverage.js | findValueByPath | function findValueByPath(jsonData, path){
var errorParts = false;
path.split('.').forEach(function(part){
if(!errorParts){
jsonData = jsonData[part];
if(!jsonData) errorParts = true;
}
});
return errorParts ? 0 : parseFloat(jsonData);
} | javascript | function findValueByPath(jsonData, path){
var errorParts = false;
path.split('.').forEach(function(part){
if(!errorParts){
jsonData = jsonData[part];
if(!jsonData) errorParts = true;
}
});
return errorParts ? 0 : parseFloat(jsonData);
} | [
"function",
"findValueByPath",
"(",
"jsonData",
",",
"path",
")",
"{",
"var",
"errorParts",
"=",
"false",
";",
"path",
".",
"split",
"(",
"'.'",
")",
".",
"forEach",
"(",
"function",
"(",
"part",
")",
"{",
"if",
"(",
"!",
"errorParts",
")",
"{",
"jsonData",
"=",
"jsonData",
"[",
"part",
"]",
";",
"if",
"(",
"!",
"jsonData",
")",
"errorParts",
"=",
"true",
";",
"}",
"}",
")",
";",
"return",
"errorParts",
"?",
"0",
":",
"parseFloat",
"(",
"jsonData",
")",
";",
"}"
]
| FIND VALUE BY PATH
@param {Object} jsonData
@param {String} path | [
"FIND",
"VALUE",
"BY",
"PATH"
]
| ef936af295f55a3328a790ebb2bcba6df4c1b378 | https://github.com/CodersBrothers/BtcAverage/blob/ef936af295f55a3328a790ebb2bcba6df4c1b378/btcaverage.js#L17-L26 | train |
CodersBrothers/BtcAverage | btcaverage.js | requestPrice | function requestPrice(urlAPI, callback){
request({
method: 'GET',
url: urlAPI,
timeout: TIMEOUT,
maxRedirects: 2
}, function(error, res, body){
if(!error){
try{
var current = JSON.parse(body);
callback(current);
}catch(e){}
}
if(!current) {
callback({});
}
});
} | javascript | function requestPrice(urlAPI, callback){
request({
method: 'GET',
url: urlAPI,
timeout: TIMEOUT,
maxRedirects: 2
}, function(error, res, body){
if(!error){
try{
var current = JSON.parse(body);
callback(current);
}catch(e){}
}
if(!current) {
callback({});
}
});
} | [
"function",
"requestPrice",
"(",
"urlAPI",
",",
"callback",
")",
"{",
"request",
"(",
"{",
"method",
":",
"'GET'",
",",
"url",
":",
"urlAPI",
",",
"timeout",
":",
"TIMEOUT",
",",
"maxRedirects",
":",
"2",
"}",
",",
"function",
"(",
"error",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"try",
"{",
"var",
"current",
"=",
"JSON",
".",
"parse",
"(",
"body",
")",
";",
"callback",
"(",
"current",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"!",
"current",
")",
"{",
"callback",
"(",
"{",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
]
| GET PRICE FROM API SERVICE
@param {String} urlAPI
@param {Function} callback | [
"GET",
"PRICE",
"FROM",
"API",
"SERVICE"
]
| ef936af295f55a3328a790ebb2bcba6df4c1b378 | https://github.com/CodersBrothers/BtcAverage/blob/ef936af295f55a3328a790ebb2bcba6df4c1b378/btcaverage.js#L34-L51 | train |
isaacperaza/elixir-busting | index.js | function(buildPath, manifest) {
fs.stat(manifest, function(err, stat) {
if (! err) {
manifest = JSON.parse(fs.readFileSync(manifest));
for (var key in manifest) {
del.sync(buildPath + '/' + manifest[key], { force: true });
}
}
});
} | javascript | function(buildPath, manifest) {
fs.stat(manifest, function(err, stat) {
if (! err) {
manifest = JSON.parse(fs.readFileSync(manifest));
for (var key in manifest) {
del.sync(buildPath + '/' + manifest[key], { force: true });
}
}
});
} | [
"function",
"(",
"buildPath",
",",
"manifest",
")",
"{",
"fs",
".",
"stat",
"(",
"manifest",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"manifest",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"manifest",
")",
")",
";",
"for",
"(",
"var",
"key",
"in",
"manifest",
")",
"{",
"del",
".",
"sync",
"(",
"buildPath",
"+",
"'/'",
"+",
"manifest",
"[",
"key",
"]",
",",
"{",
"force",
":",
"true",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
]
| Empty all relevant files from the build directory.
@param {string} buildPath
@param {string} manifest | [
"Empty",
"all",
"relevant",
"files",
"from",
"the",
"build",
"directory",
"."
]
| 7238222465f73dfedd8f049b6daf32b5cbaddcf9 | https://github.com/isaacperaza/elixir-busting/blob/7238222465f73dfedd8f049b6daf32b5cbaddcf9/index.js#L90-L100 | train |
|
skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/htmlparser/node.js | function() {
var children = this.parent.children,
index = CKEDITOR.tools.indexOf( children, this ),
previous = this.previous,
next = this.next;
previous && ( previous.next = next );
next && ( next.previous = previous );
children.splice( index, 1 );
this.parent = null;
} | javascript | function() {
var children = this.parent.children,
index = CKEDITOR.tools.indexOf( children, this ),
previous = this.previous,
next = this.next;
previous && ( previous.next = next );
next && ( next.previous = previous );
children.splice( index, 1 );
this.parent = null;
} | [
"function",
"(",
")",
"{",
"var",
"children",
"=",
"this",
".",
"parent",
".",
"children",
",",
"index",
"=",
"CKEDITOR",
".",
"tools",
".",
"indexOf",
"(",
"children",
",",
"this",
")",
",",
"previous",
"=",
"this",
".",
"previous",
",",
"next",
"=",
"this",
".",
"next",
";",
"previous",
"&&",
"(",
"previous",
".",
"next",
"=",
"next",
")",
";",
"next",
"&&",
"(",
"next",
".",
"previous",
"=",
"previous",
")",
";",
"children",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"this",
".",
"parent",
"=",
"null",
";",
"}"
]
| Remove this node from a tree.
@since 4.1 | [
"Remove",
"this",
"node",
"from",
"a",
"tree",
"."
]
| 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/htmlparser/node.js#L24-L34 | train |
|
skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/htmlparser/node.js | function( condition ) {
var checkFn =
typeof condition == 'function' ?
condition :
typeof condition == 'string' ?
function( el ) {
return el.name == condition;
} :
function( el ) {
return el.name in condition;
};
var parent = this.parent;
// Parent has to be an element - don't check doc fragment.
while ( parent && parent.type == CKEDITOR.NODE_ELEMENT ) {
if ( checkFn( parent ) )
return parent;
parent = parent.parent;
}
return null;
} | javascript | function( condition ) {
var checkFn =
typeof condition == 'function' ?
condition :
typeof condition == 'string' ?
function( el ) {
return el.name == condition;
} :
function( el ) {
return el.name in condition;
};
var parent = this.parent;
// Parent has to be an element - don't check doc fragment.
while ( parent && parent.type == CKEDITOR.NODE_ELEMENT ) {
if ( checkFn( parent ) )
return parent;
parent = parent.parent;
}
return null;
} | [
"function",
"(",
"condition",
")",
"{",
"var",
"checkFn",
"=",
"typeof",
"condition",
"==",
"'function'",
"?",
"condition",
":",
"typeof",
"condition",
"==",
"'string'",
"?",
"function",
"(",
"el",
")",
"{",
"return",
"el",
".",
"name",
"==",
"condition",
";",
"}",
":",
"function",
"(",
"el",
")",
"{",
"return",
"el",
".",
"name",
"in",
"condition",
";",
"}",
";",
"var",
"parent",
"=",
"this",
".",
"parent",
";",
"while",
"(",
"parent",
"&&",
"parent",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
")",
"{",
"if",
"(",
"checkFn",
"(",
"parent",
")",
")",
"return",
"parent",
";",
"parent",
"=",
"parent",
".",
"parent",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets the closest ancestor element of this element which satisfies given condition
@since 4.3
@param {String/Object/Function} condition Name of an ancestor, hash of names or validator function.
@returns {CKEDITOR.htmlParser.element} The closest ancestor which satisfies given condition or `null`. | [
"Gets",
"the",
"closest",
"ancestor",
"element",
"of",
"this",
"element",
"which",
"satisfies",
"given",
"condition"
]
| 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/htmlparser/node.js#L105-L127 | train |
|
leocornus/leocornus-visualdata | src/zoomable-circles.js | function(d) {
var self = this;
$('#circle-info').html(d.name);
console.log(d);
var focus0 = self.focus;
self.focus = d;
var transition = d3.transition()
.duration(d3.event.altKey ? 7500 : 750)
.tween("zoom", function(d) {
var i = d3.interpolateZoom(self.view,
[self.focus.x, self.focus.y,
self.focus.r * 2 + self.options.margin]);
return function(t) {
self.zoomTo(i(t));
};
});
transition.selectAll("text")
.filter(function(d) {
return d.parent === self.focus ||
this.style.display === "inline" ||
d.parent === focus0;
})
.style("fill-opacity", function(d) {
return d.parent === self.focus ? 1 : 0.5;
})
.each("start", function(d) {
if (d.parent === self.focus)
this.style.display = "inline";
})
.each("end", function(d) {
if (d.parent !== self.focus)
this.style.display = "none";
});
// logos are opaque at root level only
transition.selectAll("use")
.style("opacity", function(d) {
return self.focus.depth === 0 ? 1 : 0.8;
});
} | javascript | function(d) {
var self = this;
$('#circle-info').html(d.name);
console.log(d);
var focus0 = self.focus;
self.focus = d;
var transition = d3.transition()
.duration(d3.event.altKey ? 7500 : 750)
.tween("zoom", function(d) {
var i = d3.interpolateZoom(self.view,
[self.focus.x, self.focus.y,
self.focus.r * 2 + self.options.margin]);
return function(t) {
self.zoomTo(i(t));
};
});
transition.selectAll("text")
.filter(function(d) {
return d.parent === self.focus ||
this.style.display === "inline" ||
d.parent === focus0;
})
.style("fill-opacity", function(d) {
return d.parent === self.focus ? 1 : 0.5;
})
.each("start", function(d) {
if (d.parent === self.focus)
this.style.display = "inline";
})
.each("end", function(d) {
if (d.parent !== self.focus)
this.style.display = "none";
});
// logos are opaque at root level only
transition.selectAll("use")
.style("opacity", function(d) {
return self.focus.depth === 0 ? 1 : 0.8;
});
} | [
"function",
"(",
"d",
")",
"{",
"var",
"self",
"=",
"this",
";",
"$",
"(",
"'#circle-info'",
")",
".",
"html",
"(",
"d",
".",
"name",
")",
";",
"console",
".",
"log",
"(",
"d",
")",
";",
"var",
"focus0",
"=",
"self",
".",
"focus",
";",
"self",
".",
"focus",
"=",
"d",
";",
"var",
"transition",
"=",
"d3",
".",
"transition",
"(",
")",
".",
"duration",
"(",
"d3",
".",
"event",
".",
"altKey",
"?",
"7500",
":",
"750",
")",
".",
"tween",
"(",
"\"zoom\"",
",",
"function",
"(",
"d",
")",
"{",
"var",
"i",
"=",
"d3",
".",
"interpolateZoom",
"(",
"self",
".",
"view",
",",
"[",
"self",
".",
"focus",
".",
"x",
",",
"self",
".",
"focus",
".",
"y",
",",
"self",
".",
"focus",
".",
"r",
"*",
"2",
"+",
"self",
".",
"options",
".",
"margin",
"]",
")",
";",
"return",
"function",
"(",
"t",
")",
"{",
"self",
".",
"zoomTo",
"(",
"i",
"(",
"t",
")",
")",
";",
"}",
";",
"}",
")",
";",
"transition",
".",
"selectAll",
"(",
"\"text\"",
")",
".",
"filter",
"(",
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"parent",
"===",
"self",
".",
"focus",
"||",
"this",
".",
"style",
".",
"display",
"===",
"\"inline\"",
"||",
"d",
".",
"parent",
"===",
"focus0",
";",
"}",
")",
".",
"style",
"(",
"\"fill-opacity\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"parent",
"===",
"self",
".",
"focus",
"?",
"1",
":",
"0.5",
";",
"}",
")",
".",
"each",
"(",
"\"start\"",
",",
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"parent",
"===",
"self",
".",
"focus",
")",
"this",
".",
"style",
".",
"display",
"=",
"\"inline\"",
";",
"}",
")",
".",
"each",
"(",
"\"end\"",
",",
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"parent",
"!==",
"self",
".",
"focus",
")",
"this",
".",
"style",
".",
"display",
"=",
"\"none\"",
";",
"}",
")",
";",
"transition",
".",
"selectAll",
"(",
"\"use\"",
")",
".",
"style",
"(",
"\"opacity\"",
",",
"function",
"(",
"d",
")",
"{",
"return",
"self",
".",
"focus",
".",
"depth",
"===",
"0",
"?",
"1",
":",
"0.8",
";",
"}",
")",
";",
"}"
]
| a function responsible for zooming in on circles | [
"a",
"function",
"responsible",
"for",
"zooming",
"in",
"on",
"circles"
]
| 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/zoomable-circles.js#L273-L317 | train |
|
AKST/nuimo-client.js | src/withNuimo.js | discoverServicesAndCharacteristics | function discoverServicesAndCharacteristics(error) {
if (error) { return reject(error); }
peripheral.discoverSomeServicesAndCharacteristics(
ALL_SERVICES,
ALL_CHARACTERISTICS,
setupEmitter
);
} | javascript | function discoverServicesAndCharacteristics(error) {
if (error) { return reject(error); }
peripheral.discoverSomeServicesAndCharacteristics(
ALL_SERVICES,
ALL_CHARACTERISTICS,
setupEmitter
);
} | [
"function",
"discoverServicesAndCharacteristics",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"reject",
"(",
"error",
")",
";",
"}",
"peripheral",
".",
"discoverSomeServicesAndCharacteristics",
"(",
"ALL_SERVICES",
",",
"ALL_CHARACTERISTICS",
",",
"setupEmitter",
")",
";",
"}"
]
| discovers the sensor service and it's characteristics
@param {error} | [
"discovers",
"the",
"sensor",
"service",
"and",
"it",
"s",
"characteristics"
]
| a37977b604aef33abb02f9fdde1a4f64d9a0c906 | https://github.com/AKST/nuimo-client.js/blob/a37977b604aef33abb02f9fdde1a4f64d9a0c906/src/withNuimo.js#L66-L73 | train |
AKST/nuimo-client.js | src/withNuimo.js | setupEmitter | function setupEmitter(error) {
if (error) { return reject(error); }
const sensorService = getService(SERVICE_SENSOR_UUID, peripheral);
const notifiable = sensorService.characteristics;
const withNotified = Promise.all(notifiable.map(characteristic =>
new Promise((resolve, reject) =>
void characteristic.notify([], error =>
void (!!error ? reject(error) : resolve(characteristic))))));
withNotified.then(characteristics => {
const emitter = new EventEmitter();
const onData = uuid => buffer =>
void emitter.emit("data", { characteristic: uuid, buffer });
characteristics.forEach(characteristic =>
void characteristic.on('data', onData(characteristic.uuid)));
const matrixCharacteristic =
getCharacteristic(CHARACTERISTIC_MATRIX_UUID,
getService(SERVICE_MATRIX_UUID, peripheral));
resolve(new client.NuimoClient(emitter, matrixCharacteristic, peripheral));
}).catch(reject);
} | javascript | function setupEmitter(error) {
if (error) { return reject(error); }
const sensorService = getService(SERVICE_SENSOR_UUID, peripheral);
const notifiable = sensorService.characteristics;
const withNotified = Promise.all(notifiable.map(characteristic =>
new Promise((resolve, reject) =>
void characteristic.notify([], error =>
void (!!error ? reject(error) : resolve(characteristic))))));
withNotified.then(characteristics => {
const emitter = new EventEmitter();
const onData = uuid => buffer =>
void emitter.emit("data", { characteristic: uuid, buffer });
characteristics.forEach(characteristic =>
void characteristic.on('data', onData(characteristic.uuid)));
const matrixCharacteristic =
getCharacteristic(CHARACTERISTIC_MATRIX_UUID,
getService(SERVICE_MATRIX_UUID, peripheral));
resolve(new client.NuimoClient(emitter, matrixCharacteristic, peripheral));
}).catch(reject);
} | [
"function",
"setupEmitter",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"return",
"reject",
"(",
"error",
")",
";",
"}",
"const",
"sensorService",
"=",
"getService",
"(",
"SERVICE_SENSOR_UUID",
",",
"peripheral",
")",
";",
"const",
"notifiable",
"=",
"sensorService",
".",
"characteristics",
";",
"const",
"withNotified",
"=",
"Promise",
".",
"all",
"(",
"notifiable",
".",
"map",
"(",
"characteristic",
"=>",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"void",
"characteristic",
".",
"notify",
"(",
"[",
"]",
",",
"error",
"=>",
"void",
"(",
"!",
"!",
"error",
"?",
"reject",
"(",
"error",
")",
":",
"resolve",
"(",
"characteristic",
")",
")",
")",
")",
")",
")",
";",
"withNotified",
".",
"then",
"(",
"characteristics",
"=>",
"{",
"const",
"emitter",
"=",
"new",
"EventEmitter",
"(",
")",
";",
"const",
"onData",
"=",
"uuid",
"=>",
"buffer",
"=>",
"void",
"emitter",
".",
"emit",
"(",
"\"data\"",
",",
"{",
"characteristic",
":",
"uuid",
",",
"buffer",
"}",
")",
";",
"characteristics",
".",
"forEach",
"(",
"characteristic",
"=>",
"void",
"characteristic",
".",
"on",
"(",
"'data'",
",",
"onData",
"(",
"characteristic",
".",
"uuid",
")",
")",
")",
";",
"const",
"matrixCharacteristic",
"=",
"getCharacteristic",
"(",
"CHARACTERISTIC_MATRIX_UUID",
",",
"getService",
"(",
"SERVICE_MATRIX_UUID",
",",
"peripheral",
")",
")",
";",
"resolve",
"(",
"new",
"client",
".",
"NuimoClient",
"(",
"emitter",
",",
"matrixCharacteristic",
",",
"peripheral",
")",
")",
";",
"}",
")",
".",
"catch",
"(",
"reject",
")",
";",
"}"
]
| setup each service characteristic of the sensor to emit data on new data
when all have been setup with characteristic.notify then resolve the promise
@param {error} | [
"setup",
"each",
"service",
"characteristic",
"of",
"the",
"sensor",
"to",
"emit",
"data",
"on",
"new",
"data",
"when",
"all",
"have",
"been",
"setup",
"with",
"characteristic",
".",
"notify",
"then",
"resolve",
"the",
"promise"
]
| a37977b604aef33abb02f9fdde1a4f64d9a0c906 | https://github.com/AKST/nuimo-client.js/blob/a37977b604aef33abb02f9fdde1a4f64d9a0c906/src/withNuimo.js#L80-L104 | train |
jasonrhodes/pagemaki | pagemaki.js | function (config) {
this.globals = config.globals || {};
this.templates = {};
this.config = _.extend({}, defaults, config);
this.config.optionsRegex = new RegExp("^" + this.config.optionsDelimiter + "([\\S\\s]+)" + this.config.optionsDelimiter + "([\\S\\s]+)");
} | javascript | function (config) {
this.globals = config.globals || {};
this.templates = {};
this.config = _.extend({}, defaults, config);
this.config.optionsRegex = new RegExp("^" + this.config.optionsDelimiter + "([\\S\\s]+)" + this.config.optionsDelimiter + "([\\S\\s]+)");
} | [
"function",
"(",
"config",
")",
"{",
"this",
".",
"globals",
"=",
"config",
".",
"globals",
"||",
"{",
"}",
";",
"this",
".",
"templates",
"=",
"{",
"}",
";",
"this",
".",
"config",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"defaults",
",",
"config",
")",
";",
"this",
".",
"config",
".",
"optionsRegex",
"=",
"new",
"RegExp",
"(",
"\"^\"",
"+",
"this",
".",
"config",
".",
"optionsDelimiter",
"+",
"\"([\\\\S\\\\s]+)\"",
"+",
"\\\\",
"+",
"\\\\",
")",
";",
"}"
]
| Constructor for the Pagemaki class
@param {[type]} config [description] | [
"Constructor",
"for",
"the",
"Pagemaki",
"class"
]
| 843892a62696a6db392d9f4646818a31b44a8da2 | https://github.com/jasonrhodes/pagemaki/blob/843892a62696a6db392d9f4646818a31b44a8da2/pagemaki.js#L47-L52 | train |
|
blake-regalia/rmprop.js | lib/index.js | function(z_real, w_copy, s_property) {
// property is a function (ie: instance method)
if('function' === typeof z_real[s_property]) {
// implement same method name in virtual object
w_copy[s_property] = function() {
// forward to real class
return z_real[s_property].apply(z_real, arguments);
};
}
// read/write property
else {
// try to override object property
try {
Object.defineProperty(w_copy, s_property, {
// grant user full capability to modify this property
configurable: true,
// give enumerability setting same value as original
enumerable: z_real.propertyIsEnumerable(s_property),
// fetch property from real object
get: () => {
return z_real[s_property];
},
// set property on real object
set: (z_value) => {
z_real[s_property] = z_value;
},
});
}
// cannot redefine property
catch(d_redef_err) {
// try again, this time only set the value and enumerability
try {
Object.defineProperty(w_copy, s_property, {
// give enumerability setting same value as original
enumerable: z_real.propertyIsEnumerable(s_property),
// mask w undef
value: undefined,
});
// was not exepecting this property to give us trouble
if(!A_TROUBLE_PROPERTIES.includes(s_property)) {
console.warn('was not expecting "'+s_property+'" to prohibit redefinition on '+arginfo(w_copy));
}
}
// cannot even do that?!
catch(d_enum_err) {
// last try, this time only set the value
try {
Object.defineProperty(w_copy, s_property, {
// mask w undef
value: undefined,
});
// was not exepecting this property to give us trouble
if(!A_TROUBLE_PROPERTIES.includes(s_property)) {
console.warn('was not expecting "'+s_property+'" to prohibit redefinition on '+arginfo(w_copy));
}
}
// fail
catch(d_value_err) {
throw 'cannot override property "'+s_property+'" on '+arginfo(w_copy);
}
}
}
}
} | javascript | function(z_real, w_copy, s_property) {
// property is a function (ie: instance method)
if('function' === typeof z_real[s_property]) {
// implement same method name in virtual object
w_copy[s_property] = function() {
// forward to real class
return z_real[s_property].apply(z_real, arguments);
};
}
// read/write property
else {
// try to override object property
try {
Object.defineProperty(w_copy, s_property, {
// grant user full capability to modify this property
configurable: true,
// give enumerability setting same value as original
enumerable: z_real.propertyIsEnumerable(s_property),
// fetch property from real object
get: () => {
return z_real[s_property];
},
// set property on real object
set: (z_value) => {
z_real[s_property] = z_value;
},
});
}
// cannot redefine property
catch(d_redef_err) {
// try again, this time only set the value and enumerability
try {
Object.defineProperty(w_copy, s_property, {
// give enumerability setting same value as original
enumerable: z_real.propertyIsEnumerable(s_property),
// mask w undef
value: undefined,
});
// was not exepecting this property to give us trouble
if(!A_TROUBLE_PROPERTIES.includes(s_property)) {
console.warn('was not expecting "'+s_property+'" to prohibit redefinition on '+arginfo(w_copy));
}
}
// cannot even do that?!
catch(d_enum_err) {
// last try, this time only set the value
try {
Object.defineProperty(w_copy, s_property, {
// mask w undef
value: undefined,
});
// was not exepecting this property to give us trouble
if(!A_TROUBLE_PROPERTIES.includes(s_property)) {
console.warn('was not expecting "'+s_property+'" to prohibit redefinition on '+arginfo(w_copy));
}
}
// fail
catch(d_value_err) {
throw 'cannot override property "'+s_property+'" on '+arginfo(w_copy);
}
}
}
}
} | [
"function",
"(",
"z_real",
",",
"w_copy",
",",
"s_property",
")",
"{",
"if",
"(",
"'function'",
"===",
"typeof",
"z_real",
"[",
"s_property",
"]",
")",
"{",
"w_copy",
"[",
"s_property",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"z_real",
"[",
"s_property",
"]",
".",
"apply",
"(",
"z_real",
",",
"arguments",
")",
";",
"}",
";",
"}",
"else",
"{",
"try",
"{",
"Object",
".",
"defineProperty",
"(",
"w_copy",
",",
"s_property",
",",
"{",
"configurable",
":",
"true",
",",
"enumerable",
":",
"z_real",
".",
"propertyIsEnumerable",
"(",
"s_property",
")",
",",
"get",
":",
"(",
")",
"=>",
"{",
"return",
"z_real",
"[",
"s_property",
"]",
";",
"}",
",",
"set",
":",
"(",
"z_value",
")",
"=>",
"{",
"z_real",
"[",
"s_property",
"]",
"=",
"z_value",
";",
"}",
",",
"}",
")",
";",
"}",
"catch",
"(",
"d_redef_err",
")",
"{",
"try",
"{",
"Object",
".",
"defineProperty",
"(",
"w_copy",
",",
"s_property",
",",
"{",
"enumerable",
":",
"z_real",
".",
"propertyIsEnumerable",
"(",
"s_property",
")",
",",
"value",
":",
"undefined",
",",
"}",
")",
";",
"if",
"(",
"!",
"A_TROUBLE_PROPERTIES",
".",
"includes",
"(",
"s_property",
")",
")",
"{",
"console",
".",
"warn",
"(",
"'was not expecting \"'",
"+",
"s_property",
"+",
"'\" to prohibit redefinition on '",
"+",
"arginfo",
"(",
"w_copy",
")",
")",
";",
"}",
"}",
"catch",
"(",
"d_enum_err",
")",
"{",
"try",
"{",
"Object",
".",
"defineProperty",
"(",
"w_copy",
",",
"s_property",
",",
"{",
"value",
":",
"undefined",
",",
"}",
")",
";",
"if",
"(",
"!",
"A_TROUBLE_PROPERTIES",
".",
"includes",
"(",
"s_property",
")",
")",
"{",
"console",
".",
"warn",
"(",
"'was not expecting \"'",
"+",
"s_property",
"+",
"'\" to prohibit redefinition on '",
"+",
"arginfo",
"(",
"w_copy",
")",
")",
";",
"}",
"}",
"catch",
"(",
"d_value_err",
")",
"{",
"throw",
"'cannot override property \"'",
"+",
"s_property",
"+",
"'\" on '",
"+",
"arginfo",
"(",
"w_copy",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| creates a transparent property on w_copy using z_real | [
"creates",
"a",
"transparent",
"property",
"on",
"w_copy",
"using",
"z_real"
]
| 864ff0c4d24f2a4fcf684d5729bc5dafe14b3671 | https://github.com/blake-regalia/rmprop.js/blob/864ff0c4d24f2a4fcf684d5729bc5dafe14b3671/lib/index.js#L85-L163 | train |
|
tbashor/architect-debug-logger | logger.js | logFn | function logFn(level){
return function(msg){
var args = Array.prototype.slice.call(arguments);
if (level === 'hr'){
args = ['------------------------------------------------------------'];
args.push({_hr: true});
level = 'debug';
}
var logFn = logger[level] || console[level].bind(console);
if (enabled.enabled) logFn.apply(logger, args);
};
} | javascript | function logFn(level){
return function(msg){
var args = Array.prototype.slice.call(arguments);
if (level === 'hr'){
args = ['------------------------------------------------------------'];
args.push({_hr: true});
level = 'debug';
}
var logFn = logger[level] || console[level].bind(console);
if (enabled.enabled) logFn.apply(logger, args);
};
} | [
"function",
"logFn",
"(",
"level",
")",
"{",
"return",
"function",
"(",
"msg",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"if",
"(",
"level",
"===",
"'hr'",
")",
"{",
"args",
"=",
"[",
"'------------------------------------------------------------'",
"]",
";",
"args",
".",
"push",
"(",
"{",
"_hr",
":",
"true",
"}",
")",
";",
"level",
"=",
"'debug'",
";",
"}",
"var",
"logFn",
"=",
"logger",
"[",
"level",
"]",
"||",
"console",
"[",
"level",
"]",
".",
"bind",
"(",
"console",
")",
";",
"if",
"(",
"enabled",
".",
"enabled",
")",
"logFn",
".",
"apply",
"(",
"logger",
",",
"args",
")",
";",
"}",
";",
"}"
]
| Wrap winston logger to be somewhat api compatible with debug | [
"Wrap",
"winston",
"logger",
"to",
"be",
"somewhat",
"api",
"compatible",
"with",
"debug"
]
| 1d2806d2ffb8f66892f6ed7b65bd5b5abc501973 | https://github.com/tbashor/architect-debug-logger/blob/1d2806d2ffb8f66892f6ed7b65bd5b5abc501973/logger.js#L156-L169 | train |
tbashor/architect-debug-logger | logger.js | disable | function disable(namespaces) {
var split = (namespaces || '').split(/[\s,]+/);
var len = split.length;
function removeNamespaceFromNames(namespaces){
_.remove(exports.names, function(name){
return name.toString() === '/^' + namespaces + '$/';
});
}
for (var i = 0; i < len; i++) {
if (!split[i]) continue; // ignore empty strings
namespaces = split[i].replace(/\*/g, '.*?');
if (namespaces[0] === '-') {
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
} else {
removeNamespaceFromNames(namespaces);
exports.skips.push(new RegExp('^' + namespaces + '$'));
loggerEventBus.emit('disable', split[i]);
}
}
exports.save(namespaces);
} | javascript | function disable(namespaces) {
var split = (namespaces || '').split(/[\s,]+/);
var len = split.length;
function removeNamespaceFromNames(namespaces){
_.remove(exports.names, function(name){
return name.toString() === '/^' + namespaces + '$/';
});
}
for (var i = 0; i < len; i++) {
if (!split[i]) continue; // ignore empty strings
namespaces = split[i].replace(/\*/g, '.*?');
if (namespaces[0] === '-') {
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
} else {
removeNamespaceFromNames(namespaces);
exports.skips.push(new RegExp('^' + namespaces + '$'));
loggerEventBus.emit('disable', split[i]);
}
}
exports.save(namespaces);
} | [
"function",
"disable",
"(",
"namespaces",
")",
"{",
"var",
"split",
"=",
"(",
"namespaces",
"||",
"''",
")",
".",
"split",
"(",
"/",
"[\\s,]+",
"/",
")",
";",
"var",
"len",
"=",
"split",
".",
"length",
";",
"function",
"removeNamespaceFromNames",
"(",
"namespaces",
")",
"{",
"_",
".",
"remove",
"(",
"exports",
".",
"names",
",",
"function",
"(",
"name",
")",
"{",
"return",
"name",
".",
"toString",
"(",
")",
"===",
"'/^'",
"+",
"namespaces",
"+",
"'$/'",
";",
"}",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"split",
"[",
"i",
"]",
")",
"continue",
";",
"namespaces",
"=",
"split",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"\\*",
"/",
"g",
",",
"'.*?'",
")",
";",
"if",
"(",
"namespaces",
"[",
"0",
"]",
"===",
"'-'",
")",
"{",
"exports",
".",
"skips",
".",
"push",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"namespaces",
".",
"substr",
"(",
"1",
")",
"+",
"'$'",
")",
")",
";",
"}",
"else",
"{",
"removeNamespaceFromNames",
"(",
"namespaces",
")",
";",
"exports",
".",
"skips",
".",
"push",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"namespaces",
"+",
"'$'",
")",
")",
";",
"loggerEventBus",
".",
"emit",
"(",
"'disable'",
",",
"split",
"[",
"i",
"]",
")",
";",
"}",
"}",
"exports",
".",
"save",
"(",
"namespaces",
")",
";",
"}"
]
| Disables a debug mode by namespaces. This can include modes
separated by a colon and wildcards.
@param {String} namespaces
@api public | [
"Disables",
"a",
"debug",
"mode",
"by",
"namespaces",
".",
"This",
"can",
"include",
"modes",
"separated",
"by",
"a",
"colon",
"and",
"wildcards",
"."
]
| 1d2806d2ffb8f66892f6ed7b65bd5b5abc501973 | https://github.com/tbashor/architect-debug-logger/blob/1d2806d2ffb8f66892f6ed7b65bd5b5abc501973/logger.js#L236-L259 | train |
zuzana/mocha-xunit-zh | xunit-zh.js | XUnitZH | function XUnitZH(runner) {
var tests = [],
passes = 0,
failures = 0;
runner.on('pass', function(test){
test.state = 'passed';
passes++;
tests.push(test);
test.number = tests.length;
});
runner.on('fail', function(test){
test.state = 'failed';
failures++;
tests.push(test);
test.number = tests.length;
});
runner.on('end', function(){
console.log();
console.log('testsuite: Mocha Tests'
+ ', tests: ' + tests.length
+ ', failures: ' + failures
+ ', errors: ' + failures
+ ', skipped: ' + (tests.length - failures - passes)
+ ', time: ' + 0
);
appendLine(tag('testsuite', {
name: 'Mocha Tests'
, tests: tests.length
, failures: failures
, errors: failures
, skipped: tests.length - failures - passes
, timestamp: (new Date).toUTCString()
, time: 0
}, false));
tests.forEach(test);
appendLine('</testsuite>');
fs.closeSync(fd);
process.exit(failures);
});
} | javascript | function XUnitZH(runner) {
var tests = [],
passes = 0,
failures = 0;
runner.on('pass', function(test){
test.state = 'passed';
passes++;
tests.push(test);
test.number = tests.length;
});
runner.on('fail', function(test){
test.state = 'failed';
failures++;
tests.push(test);
test.number = tests.length;
});
runner.on('end', function(){
console.log();
console.log('testsuite: Mocha Tests'
+ ', tests: ' + tests.length
+ ', failures: ' + failures
+ ', errors: ' + failures
+ ', skipped: ' + (tests.length - failures - passes)
+ ', time: ' + 0
);
appendLine(tag('testsuite', {
name: 'Mocha Tests'
, tests: tests.length
, failures: failures
, errors: failures
, skipped: tests.length - failures - passes
, timestamp: (new Date).toUTCString()
, time: 0
}, false));
tests.forEach(test);
appendLine('</testsuite>');
fs.closeSync(fd);
process.exit(failures);
});
} | [
"function",
"XUnitZH",
"(",
"runner",
")",
"{",
"var",
"tests",
"=",
"[",
"]",
",",
"passes",
"=",
"0",
",",
"failures",
"=",
"0",
";",
"runner",
".",
"on",
"(",
"'pass'",
",",
"function",
"(",
"test",
")",
"{",
"test",
".",
"state",
"=",
"'passed'",
";",
"passes",
"++",
";",
"tests",
".",
"push",
"(",
"test",
")",
";",
"test",
".",
"number",
"=",
"tests",
".",
"length",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'fail'",
",",
"function",
"(",
"test",
")",
"{",
"test",
".",
"state",
"=",
"'failed'",
";",
"failures",
"++",
";",
"tests",
".",
"push",
"(",
"test",
")",
";",
"test",
".",
"number",
"=",
"tests",
".",
"length",
";",
"}",
")",
";",
"runner",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
")",
";",
"console",
".",
"log",
"(",
"'testsuite: Mocha Tests'",
"+",
"', tests: '",
"+",
"tests",
".",
"length",
"+",
"', failures: '",
"+",
"failures",
"+",
"', errors: '",
"+",
"failures",
"+",
"', skipped: '",
"+",
"(",
"tests",
".",
"length",
"-",
"failures",
"-",
"passes",
")",
"+",
"', time: '",
"+",
"0",
")",
";",
"appendLine",
"(",
"tag",
"(",
"'testsuite'",
",",
"{",
"name",
":",
"'Mocha Tests'",
",",
"tests",
":",
"tests",
".",
"length",
",",
"failures",
":",
"failures",
",",
"errors",
":",
"failures",
",",
"skipped",
":",
"tests",
".",
"length",
"-",
"failures",
"-",
"passes",
",",
"timestamp",
":",
"(",
"new",
"Date",
")",
".",
"toUTCString",
"(",
")",
",",
"time",
":",
"0",
"}",
",",
"false",
")",
")",
";",
"tests",
".",
"forEach",
"(",
"test",
")",
";",
"appendLine",
"(",
"'</testsuite>'",
")",
";",
"fs",
".",
"closeSync",
"(",
"fd",
")",
";",
"process",
".",
"exit",
"(",
"failures",
")",
";",
"}",
")",
";",
"}"
]
| Initialize a new `XUnitZH` reporter.
@param {Runner} runner
@api public | [
"Initialize",
"a",
"new",
"XUnitZH",
"reporter",
"."
]
| 9c8862fb0562eae3f0cc9d09704f55a093203e81 | https://github.com/zuzana/mocha-xunit-zh/blob/9c8862fb0562eae3f0cc9d09704f55a093203e81/xunit-zh.js#L35-L80 | train |
zuzana/mocha-xunit-zh | xunit-zh.js | toConsole | function toConsole(number, name, state, content){
console.log(number + ') ' + state + ' ' + name);
if (content) {
console.log('\t' + content);
}
} | javascript | function toConsole(number, name, state, content){
console.log(number + ') ' + state + ' ' + name);
if (content) {
console.log('\t' + content);
}
} | [
"function",
"toConsole",
"(",
"number",
",",
"name",
",",
"state",
",",
"content",
")",
"{",
"console",
".",
"log",
"(",
"number",
"+",
"') '",
"+",
"state",
"+",
"' '",
"+",
"name",
")",
";",
"if",
"(",
"content",
")",
"{",
"console",
".",
"log",
"(",
"'\\t'",
"+",
"\\t",
")",
";",
"}",
"}"
]
| Output to console | [
"Output",
"to",
"console"
]
| 9c8862fb0562eae3f0cc9d09704f55a093203e81 | https://github.com/zuzana/mocha-xunit-zh/blob/9c8862fb0562eae3f0cc9d09704f55a093203e81/xunit-zh.js#L128-L133 | train |
TribeMedia/tribemedia-kurento-client-elements-js | lib/complexTypes/IceComponentState.js | checkIceComponentState | function checkIceComponentState(key, value)
{
if(typeof value != 'string')
throw SyntaxError(key+' param should be a String, not '+typeof value);
if(!value.match('DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED'))
throw SyntaxError(key+' param is not one of [DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED] ('+value+')');
} | javascript | function checkIceComponentState(key, value)
{
if(typeof value != 'string')
throw SyntaxError(key+' param should be a String, not '+typeof value);
if(!value.match('DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED'))
throw SyntaxError(key+' param is not one of [DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED] ('+value+')');
} | [
"function",
"checkIceComponentState",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"typeof",
"value",
"!=",
"'string'",
")",
"throw",
"SyntaxError",
"(",
"key",
"+",
"' param should be a String, not '",
"+",
"typeof",
"value",
")",
";",
"if",
"(",
"!",
"value",
".",
"match",
"(",
"'DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED'",
")",
")",
"throw",
"SyntaxError",
"(",
"key",
"+",
"' param is not one of [DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED] ('",
"+",
"value",
"+",
"')'",
")",
";",
"}"
]
| States of an ICE component.
@typedef elements/complexTypes.IceComponentState
@type {(DISCONNECTED|GATHERING|CONNECTING|CONNECTED|READY|FAILED)}
Checker for {@link elements/complexTypes.IceComponentState}
@memberof module:elements/complexTypes
@param {external:String} key
@param {module:elements/complexTypes.IceComponentState} value | [
"States",
"of",
"an",
"ICE",
"component",
"."
]
| 1a5570f05bf8c2c25bbeceb4f96cb2770f634de9 | https://github.com/TribeMedia/tribemedia-kurento-client-elements-js/blob/1a5570f05bf8c2c25bbeceb4f96cb2770f634de9/lib/complexTypes/IceComponentState.js#L37-L44 | train |
dlindahl/stemcell | src/components/Bit.js | applyStyles | function applyStyles (css) {
return flattenDeep(css)
.reduce(
(classNames, declarations) => {
if (!declarations) {
return classNames
}
classNames.push(glamor(declarations))
return classNames
},
[]
)
.join(' ')
} | javascript | function applyStyles (css) {
return flattenDeep(css)
.reduce(
(classNames, declarations) => {
if (!declarations) {
return classNames
}
classNames.push(glamor(declarations))
return classNames
},
[]
)
.join(' ')
} | [
"function",
"applyStyles",
"(",
"css",
")",
"{",
"return",
"flattenDeep",
"(",
"css",
")",
".",
"reduce",
"(",
"(",
"classNames",
",",
"declarations",
")",
"=>",
"{",
"if",
"(",
"!",
"declarations",
")",
"{",
"return",
"classNames",
"}",
"classNames",
".",
"push",
"(",
"glamor",
"(",
"declarations",
")",
")",
"return",
"classNames",
"}",
",",
"[",
"]",
")",
".",
"join",
"(",
"' '",
")",
"}"
]
| Generate CSS classnames from CSS props | [
"Generate",
"CSS",
"classnames",
"from",
"CSS",
"props"
]
| 1901c637bb5d7dc00e45184a424c429c8b9dc3be | https://github.com/dlindahl/stemcell/blob/1901c637bb5d7dc00e45184a424c429c8b9dc3be/src/components/Bit.js#L18-L31 | train |
sreenaths/em-tgraph | addon/utils/data-processor.js | centericMap | function centericMap(array, callback) {
var retArray = [],
length,
left, right;
if(array) {
length = array.length - 1;
left = length >> 1;
while(left >= 0) {
retArray[left] = callback(array[left]);
right = length - left;
if(right !== left) {
retArray[right] = callback(array[right]);
}
left--;
}
}
return retArray;
} | javascript | function centericMap(array, callback) {
var retArray = [],
length,
left, right;
if(array) {
length = array.length - 1;
left = length >> 1;
while(left >= 0) {
retArray[left] = callback(array[left]);
right = length - left;
if(right !== left) {
retArray[right] = callback(array[right]);
}
left--;
}
}
return retArray;
} | [
"function",
"centericMap",
"(",
"array",
",",
"callback",
")",
"{",
"var",
"retArray",
"=",
"[",
"]",
",",
"length",
",",
"left",
",",
"right",
";",
"if",
"(",
"array",
")",
"{",
"length",
"=",
"array",
".",
"length",
"-",
"1",
";",
"left",
"=",
"length",
">>",
"1",
";",
"while",
"(",
"left",
">=",
"0",
")",
"{",
"retArray",
"[",
"left",
"]",
"=",
"callback",
"(",
"array",
"[",
"left",
"]",
")",
";",
"right",
"=",
"length",
"-",
"left",
";",
"if",
"(",
"right",
"!==",
"left",
")",
"{",
"retArray",
"[",
"right",
"]",
"=",
"callback",
"(",
"array",
"[",
"right",
"]",
")",
";",
"}",
"left",
"--",
";",
"}",
"}",
"return",
"retArray",
";",
"}"
]
| Iterates the array in a symmetric order, from middle to outwards
@param array {Array} Array to be iterated
@param callback {Function} Function to be called for each item
@return A new array created with value returned by callback | [
"Iterates",
"the",
"array",
"in",
"a",
"symmetric",
"order",
"from",
"middle",
"to",
"outwards"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L160-L179 | train |
sreenaths/em-tgraph | addon/utils/data-processor.js | function (children) {
var allChildren = this.get('allChildren');
if(allChildren) {
this._setChildren(allChildren.filter(function (child) {
return children.indexOf(child) !== -1; // true if child is in children
}));
}
} | javascript | function (children) {
var allChildren = this.get('allChildren');
if(allChildren) {
this._setChildren(allChildren.filter(function (child) {
return children.indexOf(child) !== -1; // true if child is in children
}));
}
} | [
"function",
"(",
"children",
")",
"{",
"var",
"allChildren",
"=",
"this",
".",
"get",
"(",
"'allChildren'",
")",
";",
"if",
"(",
"allChildren",
")",
"{",
"this",
".",
"_setChildren",
"(",
"allChildren",
".",
"filter",
"(",
"function",
"(",
"child",
")",
"{",
"return",
"children",
".",
"indexOf",
"(",
"child",
")",
"!==",
"-",
"1",
";",
"}",
")",
")",
";",
"}",
"}"
]
| Public function.
Set the child array after filtering
@param children {Array} Array of DataNodes to be set | [
"Public",
"function",
".",
"Set",
"the",
"child",
"array",
"after",
"filtering"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L215-L222 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function (childrenToRemove) {
var children = this.get('children');
if(children) {
children = children.filter(function (child) {
return childrenToRemove.indexOf(child) === -1; // false if child is in children
});
this._setChildren(children);
}
} | javascript | function (childrenToRemove) {
var children = this.get('children');
if(children) {
children = children.filter(function (child) {
return childrenToRemove.indexOf(child) === -1; // false if child is in children
});
this._setChildren(children);
}
} | [
"function",
"(",
"childrenToRemove",
")",
"{",
"var",
"children",
"=",
"this",
".",
"get",
"(",
"'children'",
")",
";",
"if",
"(",
"children",
")",
"{",
"children",
"=",
"children",
".",
"filter",
"(",
"function",
"(",
"child",
")",
"{",
"return",
"childrenToRemove",
".",
"indexOf",
"(",
"child",
")",
"===",
"-",
"1",
";",
"}",
")",
";",
"this",
".",
"_setChildren",
"(",
"children",
")",
";",
"}",
"}"
]
| Filter out the given children from the children array.
@param childrenToRemove {Array} Array of DataNodes to be removed | [
"Filter",
"out",
"the",
"given",
"children",
"from",
"the",
"children",
"array",
"."
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L227-L235 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function (property, callback, thisArg) {
if(this.get(property)) {
this.get(property).forEach(callback, thisArg);
}
} | javascript | function (property, callback, thisArg) {
if(this.get(property)) {
this.get(property).forEach(callback, thisArg);
}
} | [
"function",
"(",
"property",
",",
"callback",
",",
"thisArg",
")",
"{",
"if",
"(",
"this",
".",
"get",
"(",
"property",
")",
")",
"{",
"this",
".",
"get",
"(",
"property",
")",
".",
"forEach",
"(",
"callback",
",",
"thisArg",
")",
";",
"}",
"}"
]
| If the property is available, expects it to be an array and iterate over
its elements using the callback.
@param vertex {DataNode}
@param callback {Function}
@param thisArg {} Will be value of this inside the callback | [
"If",
"the",
"property",
"is",
"available",
"expects",
"it",
"to",
"be",
"an",
"array",
"and",
"iterate",
"over",
"its",
"elements",
"using",
"the",
"callback",
"."
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L258-L262 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function (depth) {
this.set('depth', depth);
depth++;
this.get('inputs').forEach(function (input) {
input.set('depth', depth);
});
} | javascript | function (depth) {
this.set('depth', depth);
depth++;
this.get('inputs').forEach(function (input) {
input.set('depth', depth);
});
} | [
"function",
"(",
"depth",
")",
"{",
"this",
".",
"set",
"(",
"'depth'",
",",
"depth",
")",
";",
"depth",
"++",
";",
"this",
".",
"get",
"(",
"'inputs'",
")",
".",
"forEach",
"(",
"function",
"(",
"input",
")",
"{",
"input",
".",
"set",
"(",
"'depth'",
",",
"depth",
")",
";",
"}",
")",
";",
"}"
]
| Sets depth of the vertex and all its input children
@param depth {Number} | [
"Sets",
"depth",
"of",
"the",
"vertex",
"and",
"all",
"its",
"input",
"children"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L315-L322 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function() {
this.setChildren(this.get('inputs').concat(this.get('children') || []));
var ancestor = this.get('parent.parent');
if(ancestor) {
ancestor.setChildren(this.get('outputs').concat(ancestor.get('children') || []));
}
this.set('_additionalsIncluded', true);
} | javascript | function() {
this.setChildren(this.get('inputs').concat(this.get('children') || []));
var ancestor = this.get('parent.parent');
if(ancestor) {
ancestor.setChildren(this.get('outputs').concat(ancestor.get('children') || []));
}
this.set('_additionalsIncluded', true);
} | [
"function",
"(",
")",
"{",
"this",
".",
"setChildren",
"(",
"this",
".",
"get",
"(",
"'inputs'",
")",
".",
"concat",
"(",
"this",
".",
"get",
"(",
"'children'",
")",
"||",
"[",
"]",
")",
")",
";",
"var",
"ancestor",
"=",
"this",
".",
"get",
"(",
"'parent.parent'",
")",
";",
"if",
"(",
"ancestor",
")",
"{",
"ancestor",
".",
"setChildren",
"(",
"this",
".",
"get",
"(",
"'outputs'",
")",
".",
"concat",
"(",
"ancestor",
".",
"get",
"(",
"'children'",
")",
"||",
"[",
"]",
")",
")",
";",
"}",
"this",
".",
"set",
"(",
"'_additionalsIncluded'",
",",
"true",
")",
";",
"}"
]
| Include sources and sinks in the children list, so that they are displayed | [
"Include",
"sources",
"and",
"sinks",
"in",
"the",
"children",
"list",
"so",
"that",
"they",
"are",
"displayed"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L335-L343 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function() {
this.removeChildren(this.get('inputs'));
var ancestor = this.get('parent.parent');
if(ancestor) {
ancestor.removeChildren(this.get('outputs'));
}
this.set('_additionalsIncluded', false);
} | javascript | function() {
this.removeChildren(this.get('inputs'));
var ancestor = this.get('parent.parent');
if(ancestor) {
ancestor.removeChildren(this.get('outputs'));
}
this.set('_additionalsIncluded', false);
} | [
"function",
"(",
")",
"{",
"this",
".",
"removeChildren",
"(",
"this",
".",
"get",
"(",
"'inputs'",
")",
")",
";",
"var",
"ancestor",
"=",
"this",
".",
"get",
"(",
"'parent.parent'",
")",
";",
"if",
"(",
"ancestor",
")",
"{",
"ancestor",
".",
"removeChildren",
"(",
"this",
".",
"get",
"(",
"'outputs'",
")",
")",
";",
"}",
"this",
".",
"set",
"(",
"'_additionalsIncluded'",
",",
"false",
")",
";",
"}"
]
| Exclude sources and sinks in the children list, so that they are hidden | [
"Exclude",
"sources",
"and",
"sinks",
"in",
"the",
"children",
"list",
"so",
"that",
"they",
"are",
"hidden"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L347-L355 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function () {
var vertex = this.get('vertex');
this._super();
// Initialize data members
this.setProperties({
id: vertex.get('vertexName') + this.get('name'),
depth: vertex.get('depth') + 1
});
} | javascript | function () {
var vertex = this.get('vertex');
this._super();
// Initialize data members
this.setProperties({
id: vertex.get('vertexName') + this.get('name'),
depth: vertex.get('depth') + 1
});
} | [
"function",
"(",
")",
"{",
"var",
"vertex",
"=",
"this",
".",
"get",
"(",
"'vertex'",
")",
";",
"this",
".",
"_super",
"(",
")",
";",
"this",
".",
"setProperties",
"(",
"{",
"id",
":",
"vertex",
".",
"get",
"(",
"'vertexName'",
")",
"+",
"this",
".",
"get",
"(",
"'name'",
")",
",",
"depth",
":",
"vertex",
".",
"get",
"(",
"'depth'",
")",
"+",
"1",
"}",
")",
";",
"}"
]
| The vertex DataNode to which this node is linked | [
"The",
"vertex",
"DataNode",
"to",
"which",
"this",
"node",
"is",
"linked"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L375-L384 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | function (vertex, data) {
return InputDataNode.create(Ember.$.extend(data, {
treeParent: vertex,
vertex: vertex
}));
} | javascript | function (vertex, data) {
return InputDataNode.create(Ember.$.extend(data, {
treeParent: vertex,
vertex: vertex
}));
} | [
"function",
"(",
"vertex",
",",
"data",
")",
"{",
"return",
"InputDataNode",
".",
"create",
"(",
"Ember",
".",
"$",
".",
"extend",
"(",
"data",
",",
"{",
"treeParent",
":",
"vertex",
",",
"vertex",
":",
"vertex",
"}",
")",
")",
";",
"}"
]
| Initiate an InputDataNode
@param vertex {DataNode}
@param data {Object} | [
"Initiate",
"an",
"InputDataNode"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L391-L396 | train |
|
sreenaths/em-tgraph | addon/utils/data-processor.js | _normalizeVertexTree | function _normalizeVertexTree(vertex) {
var children = vertex.get('children');
if(children) {
children = children.filter(function (child) {
_normalizeVertexTree(child);
return child.get('type') !== 'vertex' || child.get('treeParent') === vertex;
});
vertex._setChildren(children);
}
return vertex;
} | javascript | function _normalizeVertexTree(vertex) {
var children = vertex.get('children');
if(children) {
children = children.filter(function (child) {
_normalizeVertexTree(child);
return child.get('type') !== 'vertex' || child.get('treeParent') === vertex;
});
vertex._setChildren(children);
}
return vertex;
} | [
"function",
"_normalizeVertexTree",
"(",
"vertex",
")",
"{",
"var",
"children",
"=",
"vertex",
".",
"get",
"(",
"'children'",
")",
";",
"if",
"(",
"children",
")",
"{",
"children",
"=",
"children",
".",
"filter",
"(",
"function",
"(",
"child",
")",
"{",
"_normalizeVertexTree",
"(",
"child",
")",
";",
"return",
"child",
".",
"get",
"(",
"'type'",
")",
"!==",
"'vertex'",
"||",
"child",
".",
"get",
"(",
"'treeParent'",
")",
"===",
"vertex",
";",
"}",
")",
";",
"vertex",
".",
"_setChildren",
"(",
"children",
")",
";",
"}",
"return",
"vertex",
";",
"}"
]
| Part of step 1
To remove recurring vertices in the tree
@param vertex {Object} root vertex | [
"Part",
"of",
"step",
"1",
"To",
"remove",
"recurring",
"vertices",
"in",
"the",
"tree"
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L495-L508 | train |
sreenaths/em-tgraph | addon/utils/data-processor.js | _normalizeRawData | function _normalizeRawData(data) {
var EmObj = Ember.Object,
vertices, // Hash of vertices
edges, // Hash of edges
rootVertices = []; // Vertices without out-edges are considered root vertices
vertices = data.vertices.reduce(function (obj, vertex) {
vertex = VertexDataNode.create(vertex);
if(!vertex.outEdgeIds) {
rootVertices.push(vertex);
}
obj[vertex.vertexName] = vertex;
return obj;
}, {});
edges = !data.edges ? [] : data.edges.reduce(function (obj, edge) {
obj[edge.edgeId] = EmObj.create(edge);
return obj;
}, {});
if(data.vertexGroups) {
data.vertexGroups.forEach(function (group) {
group.groupMembers.forEach(function (vertex) {
vertices[vertex].vertexGroup = EmObj.create(group);
});
});
}
return {
vertices: EmObj.create(vertices),
edges: EmObj.create(edges),
rootVertices: rootVertices
};
} | javascript | function _normalizeRawData(data) {
var EmObj = Ember.Object,
vertices, // Hash of vertices
edges, // Hash of edges
rootVertices = []; // Vertices without out-edges are considered root vertices
vertices = data.vertices.reduce(function (obj, vertex) {
vertex = VertexDataNode.create(vertex);
if(!vertex.outEdgeIds) {
rootVertices.push(vertex);
}
obj[vertex.vertexName] = vertex;
return obj;
}, {});
edges = !data.edges ? [] : data.edges.reduce(function (obj, edge) {
obj[edge.edgeId] = EmObj.create(edge);
return obj;
}, {});
if(data.vertexGroups) {
data.vertexGroups.forEach(function (group) {
group.groupMembers.forEach(function (vertex) {
vertices[vertex].vertexGroup = EmObj.create(group);
});
});
}
return {
vertices: EmObj.create(vertices),
edges: EmObj.create(edges),
rootVertices: rootVertices
};
} | [
"function",
"_normalizeRawData",
"(",
"data",
")",
"{",
"var",
"EmObj",
"=",
"Ember",
".",
"Object",
",",
"vertices",
",",
"edges",
",",
"rootVertices",
"=",
"[",
"]",
";",
"vertices",
"=",
"data",
".",
"vertices",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"vertex",
")",
"{",
"vertex",
"=",
"VertexDataNode",
".",
"create",
"(",
"vertex",
")",
";",
"if",
"(",
"!",
"vertex",
".",
"outEdgeIds",
")",
"{",
"rootVertices",
".",
"push",
"(",
"vertex",
")",
";",
"}",
"obj",
"[",
"vertex",
".",
"vertexName",
"]",
"=",
"vertex",
";",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"edges",
"=",
"!",
"data",
".",
"edges",
"?",
"[",
"]",
":",
"data",
".",
"edges",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"edge",
")",
"{",
"obj",
"[",
"edge",
".",
"edgeId",
"]",
"=",
"EmObj",
".",
"create",
"(",
"edge",
")",
";",
"return",
"obj",
";",
"}",
",",
"{",
"}",
")",
";",
"if",
"(",
"data",
".",
"vertexGroups",
")",
"{",
"data",
".",
"vertexGroups",
".",
"forEach",
"(",
"function",
"(",
"group",
")",
"{",
"group",
".",
"groupMembers",
".",
"forEach",
"(",
"function",
"(",
"vertex",
")",
"{",
"vertices",
"[",
"vertex",
"]",
".",
"vertexGroup",
"=",
"EmObj",
".",
"create",
"(",
"group",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"{",
"vertices",
":",
"EmObj",
".",
"create",
"(",
"vertices",
")",
",",
"edges",
":",
"EmObj",
".",
"create",
"(",
"edges",
")",
",",
"rootVertices",
":",
"rootVertices",
"}",
";",
"}"
]
| Converts vertices & edges into hashes for easy access.
Makes vertexGroup a property of the respective vertices.
@param data {Object}
@return {Object} An object with vertices hash, edges hash and array of root vertices. | [
"Converts",
"vertices",
"&",
"edges",
"into",
"hashes",
"for",
"easy",
"access",
".",
"Makes",
"vertexGroup",
"a",
"property",
"of",
"the",
"respective",
"vertices",
"."
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L664-L697 | train |
sreenaths/em-tgraph | addon/utils/data-processor.js | function (data) {
var dummy = DataNode.create({
type: types.DUMMY,
vertexName: 'dummy',
depth: 1
}),
root = RootDataNode.create({
dummy: dummy
});
if(!data.vertices) {
return "Vertices not found!";
}
_data = _normalizeRawData(data);
if(!_data.rootVertices.length) {
return "Sink vertex not found!";
}
dummy._setChildren(centericMap(_data.rootVertices, function (vertex) {
return _normalizeVertexTree(_treefyData(vertex, 2));
}));
_addOutputs(root);
_cacheChildren(root);
return _getGraphDetails(root);
} | javascript | function (data) {
var dummy = DataNode.create({
type: types.DUMMY,
vertexName: 'dummy',
depth: 1
}),
root = RootDataNode.create({
dummy: dummy
});
if(!data.vertices) {
return "Vertices not found!";
}
_data = _normalizeRawData(data);
if(!_data.rootVertices.length) {
return "Sink vertex not found!";
}
dummy._setChildren(centericMap(_data.rootVertices, function (vertex) {
return _normalizeVertexTree(_treefyData(vertex, 2));
}));
_addOutputs(root);
_cacheChildren(root);
return _getGraphDetails(root);
} | [
"function",
"(",
"data",
")",
"{",
"var",
"dummy",
"=",
"DataNode",
".",
"create",
"(",
"{",
"type",
":",
"types",
".",
"DUMMY",
",",
"vertexName",
":",
"'dummy'",
",",
"depth",
":",
"1",
"}",
")",
",",
"root",
"=",
"RootDataNode",
".",
"create",
"(",
"{",
"dummy",
":",
"dummy",
"}",
")",
";",
"if",
"(",
"!",
"data",
".",
"vertices",
")",
"{",
"return",
"\"Vertices not found!\"",
";",
"}",
"_data",
"=",
"_normalizeRawData",
"(",
"data",
")",
";",
"if",
"(",
"!",
"_data",
".",
"rootVertices",
".",
"length",
")",
"{",
"return",
"\"Sink vertex not found!\"",
";",
"}",
"dummy",
".",
"_setChildren",
"(",
"centericMap",
"(",
"_data",
".",
"rootVertices",
",",
"function",
"(",
"vertex",
")",
"{",
"return",
"_normalizeVertexTree",
"(",
"_treefyData",
"(",
"vertex",
",",
"2",
")",
")",
";",
"}",
")",
")",
";",
"_addOutputs",
"(",
"root",
")",
";",
"_cacheChildren",
"(",
"root",
")",
";",
"return",
"_getGraphDetails",
"(",
"root",
")",
";",
"}"
]
| Converts raw DAG-plan into an internal data representation that graph-view,
and in turn d3.layout.tree can digest.
@param data {Object} Dag-plan data
@return {Object/String}
- Object with values tree, links, maxDepth & maxHeight
- Error message if the data was not as expected. | [
"Converts",
"raw",
"DAG",
"-",
"plan",
"into",
"an",
"internal",
"data",
"representation",
"that",
"graph",
"-",
"view",
"and",
"in",
"turn",
"d3",
".",
"layout",
".",
"tree",
"can",
"digest",
"."
]
| 8d6a8f46b911a165ac16561731735ab762954996 | https://github.com/sreenaths/em-tgraph/blob/8d6a8f46b911a165ac16561731735ab762954996/addon/utils/data-processor.js#L711-L740 | train |
|
arpadHegedus/postcss-plugin-utilities | inc/sass-get-var.js | gather | function gather (variable, node) {
if (node.parent) {
let values = []
for (let n of Object.values(node.parent.nodes)) {
if (n.type === 'decl' && n.prop === `$${variable}`) {
values.push(n.value)
}
}
values.reverse()
let parentValues = node.parent.parent ? gather(variable, node.parent) : null
if (parentValues) {
values = values.concat(parentValues)
}
return values
}
return null
} | javascript | function gather (variable, node) {
if (node.parent) {
let values = []
for (let n of Object.values(node.parent.nodes)) {
if (n.type === 'decl' && n.prop === `$${variable}`) {
values.push(n.value)
}
}
values.reverse()
let parentValues = node.parent.parent ? gather(variable, node.parent) : null
if (parentValues) {
values = values.concat(parentValues)
}
return values
}
return null
} | [
"function",
"gather",
"(",
"variable",
",",
"node",
")",
"{",
"if",
"(",
"node",
".",
"parent",
")",
"{",
"let",
"values",
"=",
"[",
"]",
"for",
"(",
"let",
"n",
"of",
"Object",
".",
"values",
"(",
"node",
".",
"parent",
".",
"nodes",
")",
")",
"{",
"if",
"(",
"n",
".",
"type",
"===",
"'decl'",
"&&",
"n",
".",
"prop",
"===",
"`",
"${",
"variable",
"}",
"`",
")",
"{",
"values",
".",
"push",
"(",
"n",
".",
"value",
")",
"}",
"}",
"values",
".",
"reverse",
"(",
")",
"let",
"parentValues",
"=",
"node",
".",
"parent",
".",
"parent",
"?",
"gather",
"(",
"variable",
",",
"node",
".",
"parent",
")",
":",
"null",
"if",
"(",
"parentValues",
")",
"{",
"values",
"=",
"values",
".",
"concat",
"(",
"parentValues",
")",
"}",
"return",
"values",
"}",
"return",
"null",
"}"
]
| get the value of a sass variable
@param {string} variable
@param {object} node | [
"get",
"the",
"value",
"of",
"a",
"sass",
"variable"
]
| 1edbeb95e30d2965ffb6c3907e8b87f887c58018 | https://github.com/arpadHegedus/postcss-plugin-utilities/blob/1edbeb95e30d2965ffb6c3907e8b87f887c58018/inc/sass-get-var.js#L7-L23 | train |
digiaonline/generator-nord-backbone | app/templates/core/app.js | function (selector, args, cb) {
selector = selector || document;
args = args || {};
var self = this;
$(selector).find('*[data-view]').each(function () {
var viewArgs = _.extend({}, args);
viewArgs.el = this;
self.getComponent('viewManager').createView($(this).data('view'), viewArgs)
.then(cb);
});
} | javascript | function (selector, args, cb) {
selector = selector || document;
args = args || {};
var self = this;
$(selector).find('*[data-view]').each(function () {
var viewArgs = _.extend({}, args);
viewArgs.el = this;
self.getComponent('viewManager').createView($(this).data('view'), viewArgs)
.then(cb);
});
} | [
"function",
"(",
"selector",
",",
"args",
",",
"cb",
")",
"{",
"selector",
"=",
"selector",
"||",
"document",
";",
"args",
"=",
"args",
"||",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"$",
"(",
"selector",
")",
".",
"find",
"(",
"'*[data-view]'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"viewArgs",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"args",
")",
";",
"viewArgs",
".",
"el",
"=",
"this",
";",
"self",
".",
"getComponent",
"(",
"'viewManager'",
")",
".",
"createView",
"(",
"$",
"(",
"this",
")",
".",
"data",
"(",
"'view'",
")",
",",
"viewArgs",
")",
".",
"then",
"(",
"cb",
")",
";",
"}",
")",
";",
"}"
]
| Initializes views within a specific DOM element.
@param {string} selector element CSS selector
@param {Object<string, *>} args view options
@param {Function} cb optional callback function to call when the view is loaded. | [
"Initializes",
"views",
"within",
"a",
"specific",
"DOM",
"element",
"."
]
| bc962e16b6354c7a4034ce09cf4030b9d300202e | https://github.com/digiaonline/generator-nord-backbone/blob/bc962e16b6354c7a4034ce09cf4030b9d300202e/app/templates/core/app.js#L53-L65 | train |
|
AndiDittrich/Node.async-magic | lib/promisify-all.js | promisifyAll | function promisifyAll(sourceObject, keys){
// promisified output
const promisifiedFunctions = {};
// process each object key
for (const name of keys){
// function exist in source object ?
if (name in sourceObject && typeof sourceObject[name] === 'function'){
// create promisified named version
promisifiedFunctions[name] = _promisify(sourceObject[name], name);
}
}
return promisifiedFunctions;
} | javascript | function promisifyAll(sourceObject, keys){
// promisified output
const promisifiedFunctions = {};
// process each object key
for (const name of keys){
// function exist in source object ?
if (name in sourceObject && typeof sourceObject[name] === 'function'){
// create promisified named version
promisifiedFunctions[name] = _promisify(sourceObject[name], name);
}
}
return promisifiedFunctions;
} | [
"function",
"promisifyAll",
"(",
"sourceObject",
",",
"keys",
")",
"{",
"const",
"promisifiedFunctions",
"=",
"{",
"}",
";",
"for",
"(",
"const",
"name",
"of",
"keys",
")",
"{",
"if",
"(",
"name",
"in",
"sourceObject",
"&&",
"typeof",
"sourceObject",
"[",
"name",
"]",
"===",
"'function'",
")",
"{",
"promisifiedFunctions",
"[",
"name",
"]",
"=",
"_promisify",
"(",
"sourceObject",
"[",
"name",
"]",
",",
"name",
")",
";",
"}",
"}",
"return",
"promisifiedFunctions",
";",
"}"
]
| apply promisify function to all elements of sourceObject included in key list | [
"apply",
"promisify",
"function",
"to",
"all",
"elements",
"of",
"sourceObject",
"included",
"in",
"key",
"list"
]
| 0c41dd27d8f7539bb24034bc23ce870f5f8a10b3 | https://github.com/AndiDittrich/Node.async-magic/blob/0c41dd27d8f7539bb24034bc23ce870f5f8a10b3/lib/promisify-all.js#L4-L18 | train |
dpjanes/iotdb-helpers | lib/q.js | function (name, paramd) {
var self = this;
paramd = (paramd !== undefined) ? paramd : {};
self.name = (name !== undefined) ? name : "unnamed-queue";
self.qitems = [];
self.qurrents = [];
self.qn = (paramd.qn !== undefined) ? paramd.qn : 1;
self.qid = 0;
self.paused = false;
} | javascript | function (name, paramd) {
var self = this;
paramd = (paramd !== undefined) ? paramd : {};
self.name = (name !== undefined) ? name : "unnamed-queue";
self.qitems = [];
self.qurrents = [];
self.qn = (paramd.qn !== undefined) ? paramd.qn : 1;
self.qid = 0;
self.paused = false;
} | [
"function",
"(",
"name",
",",
"paramd",
")",
"{",
"var",
"self",
"=",
"this",
";",
"paramd",
"=",
"(",
"paramd",
"!==",
"undefined",
")",
"?",
"paramd",
":",
"{",
"}",
";",
"self",
".",
"name",
"=",
"(",
"name",
"!==",
"undefined",
")",
"?",
"name",
":",
"\"unnamed-queue\"",
";",
"self",
".",
"qitems",
"=",
"[",
"]",
";",
"self",
".",
"qurrents",
"=",
"[",
"]",
";",
"self",
".",
"qn",
"=",
"(",
"paramd",
".",
"qn",
"!==",
"undefined",
")",
"?",
"paramd",
".",
"qn",
":",
"1",
";",
"self",
".",
"qid",
"=",
"0",
";",
"self",
".",
"paused",
"=",
"false",
";",
"}"
]
| Make a FIFOQueue called 'name'.
@param {string} name
A human friendly name for this queue,
occassionally printed out
@param {dictionary} paramd
@param {integer} paramd.qn
How many items this queue can be executing
at once. Defaults to 1.
@classdesc
FIFO Queue stuff. This is useful e.g. in {@link Driver Drivers}
when you don't want to be pounding on a device's URL with
multiple requests at the same time.
<hr />
@constructor | [
"Make",
"a",
"FIFOQueue",
"called",
"name",
"."
]
| c31ecb2302b9c6a4f41ef3f0b835d483b1d53c0e | https://github.com/dpjanes/iotdb-helpers/blob/c31ecb2302b9c6a4f41ef3f0b835d483b1d53c0e/lib/q.js#L51-L62 | train |
|
twolfson/finder | finder.js | startSearch | function startSearch() {
iface.question('Enter search: ', function (query) {
// Get the results of our query
var matches = fileFinder.query(query),
len = matches.length;
// If no results were found
if (len === 0) {
console.log('No results found for: ' + query);
startSearch();
} else if (len === 1) {
var item = matches[0];
// If there is one, skip to go
console.log('Opening: ' + item);
fileFinder.open(item);
// Begin the search again
startSearch();
} else {
// Otherwise, list options
console.log('');
console.log('----------------');
console.log('Search Results');
console.log('----------------');
for (i = 0; i < len; i++) {
console.log(i + ': ' + matches[i]);
}
// Ask for a number
iface.question('Which item would you like to open? ', function (numStr) {
var num = +numStr,
item;
// If the number is not NaN and we were not given an empty string
if (num === num && numStr !== '') {
// and if it is in our result set
if (num >= 0 && num < len) {
// Open it
item = matches[num];
console.log('Opening: ' + item);
fileFinder.open(item);
}
} else {
// Otherwise, if there was a word in there so we are assuming it was 'rescan'
// Rescan
console.log('Rescanning...');
fileFinder.scan();
}
// Begin the search again
startSearch();
});
}
});
} | javascript | function startSearch() {
iface.question('Enter search: ', function (query) {
// Get the results of our query
var matches = fileFinder.query(query),
len = matches.length;
// If no results were found
if (len === 0) {
console.log('No results found for: ' + query);
startSearch();
} else if (len === 1) {
var item = matches[0];
// If there is one, skip to go
console.log('Opening: ' + item);
fileFinder.open(item);
// Begin the search again
startSearch();
} else {
// Otherwise, list options
console.log('');
console.log('----------------');
console.log('Search Results');
console.log('----------------');
for (i = 0; i < len; i++) {
console.log(i + ': ' + matches[i]);
}
// Ask for a number
iface.question('Which item would you like to open? ', function (numStr) {
var num = +numStr,
item;
// If the number is not NaN and we were not given an empty string
if (num === num && numStr !== '') {
// and if it is in our result set
if (num >= 0 && num < len) {
// Open it
item = matches[num];
console.log('Opening: ' + item);
fileFinder.open(item);
}
} else {
// Otherwise, if there was a word in there so we are assuming it was 'rescan'
// Rescan
console.log('Rescanning...');
fileFinder.scan();
}
// Begin the search again
startSearch();
});
}
});
} | [
"function",
"startSearch",
"(",
")",
"{",
"iface",
".",
"question",
"(",
"'Enter search: '",
",",
"function",
"(",
"query",
")",
"{",
"var",
"matches",
"=",
"fileFinder",
".",
"query",
"(",
"query",
")",
",",
"len",
"=",
"matches",
".",
"length",
";",
"if",
"(",
"len",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'No results found for: '",
"+",
"query",
")",
";",
"startSearch",
"(",
")",
";",
"}",
"else",
"if",
"(",
"len",
"===",
"1",
")",
"{",
"var",
"item",
"=",
"matches",
"[",
"0",
"]",
";",
"console",
".",
"log",
"(",
"'Opening: '",
"+",
"item",
")",
";",
"fileFinder",
".",
"open",
"(",
"item",
")",
";",
"startSearch",
"(",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"''",
")",
";",
"console",
".",
"log",
"(",
"'----------------'",
")",
";",
"console",
".",
"log",
"(",
"'Search Results'",
")",
";",
"console",
".",
"log",
"(",
"'----------------'",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"console",
".",
"log",
"(",
"i",
"+",
"': '",
"+",
"matches",
"[",
"i",
"]",
")",
";",
"}",
"iface",
".",
"question",
"(",
"'Which item would you like to open? '",
",",
"function",
"(",
"numStr",
")",
"{",
"var",
"num",
"=",
"+",
"numStr",
",",
"item",
";",
"if",
"(",
"num",
"===",
"num",
"&&",
"numStr",
"!==",
"''",
")",
"{",
"if",
"(",
"num",
">=",
"0",
"&&",
"num",
"<",
"len",
")",
"{",
"item",
"=",
"matches",
"[",
"num",
"]",
";",
"console",
".",
"log",
"(",
"'Opening: '",
"+",
"item",
")",
";",
"fileFinder",
".",
"open",
"(",
"item",
")",
";",
"}",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Rescanning...'",
")",
";",
"fileFinder",
".",
"scan",
"(",
")",
";",
"}",
"startSearch",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Set up startSearch for calling later | [
"Set",
"up",
"startSearch",
"for",
"calling",
"later"
]
| e365823cc35f1aaefaf7c1a75fbfea18234fa379 | https://github.com/twolfson/finder/blob/e365823cc35f1aaefaf7c1a75fbfea18234fa379/finder.js#L128-L182 | train |
Ma3Route/node-sdk | example/utils.js | getAuth | function getAuth() {
if (!auth.key || auth.key.indexOf("goes-here") !== -1) {
var err = new Error("API key missing");
out.error(err.message);
throw err;
}
if (!auth.secret || auth.secret.indexOf("goes-here") !== -1) {
var err = new Error("API secret missing");
out.error(err.message);
throw err;
}
return auth;
} | javascript | function getAuth() {
if (!auth.key || auth.key.indexOf("goes-here") !== -1) {
var err = new Error("API key missing");
out.error(err.message);
throw err;
}
if (!auth.secret || auth.secret.indexOf("goes-here") !== -1) {
var err = new Error("API secret missing");
out.error(err.message);
throw err;
}
return auth;
} | [
"function",
"getAuth",
"(",
")",
"{",
"if",
"(",
"!",
"auth",
".",
"key",
"||",
"auth",
".",
"key",
".",
"indexOf",
"(",
"\"goes-here\"",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"\"API key missing\"",
")",
";",
"out",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"throw",
"err",
";",
"}",
"if",
"(",
"!",
"auth",
".",
"secret",
"||",
"auth",
".",
"secret",
".",
"indexOf",
"(",
"\"goes-here\"",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"\"API secret missing\"",
")",
";",
"out",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"throw",
"err",
";",
"}",
"return",
"auth",
";",
"}"
]
| Return the authentication parameters, if available.
Otherwise, log to stderr and throw an error indicating missing
authentication parameters.
@return {Object} auth | [
"Return",
"the",
"authentication",
"parameters",
"if",
"available",
".",
"Otherwise",
"log",
"to",
"stderr",
"and",
"throw",
"an",
"error",
"indicating",
"missing",
"authentication",
"parameters",
"."
]
| a2769d97d77d6f762d23e743bf4c749e2bad0d8a | https://github.com/Ma3Route/node-sdk/blob/a2769d97d77d6f762d23e743bf4c749e2bad0d8a/example/utils.js#L25-L37 | train |
allanmboyd/docit | lib/parser.js | sortComments | function sortComments(comments) {
var moduleComments = [];
var typeComments = [];
var varComments = [];
var methodComments = [];
var typelessComments = [];
comments.forEach(function (comment) {
if(comment.type) {
switch(comment.type) {
case exports.COMMENT_TYPES.MODULE:
moduleComments.push(comment);
break;
case exports.COMMENT_TYPES.METHOD:
methodComments.push(comment);
break;
case exports.COMMENT_TYPES.TYPE:
typeComments.push(comment);
break;
case exports.COMMENT_TYPES.VARIABLE:
varComments.push(comment);
break;
}
} else {
typelessComments.push(comment);
}
});
return moduleComments.concat(typeComments.concat(varComments.concat(methodComments.concat(typelessComments))));
} | javascript | function sortComments(comments) {
var moduleComments = [];
var typeComments = [];
var varComments = [];
var methodComments = [];
var typelessComments = [];
comments.forEach(function (comment) {
if(comment.type) {
switch(comment.type) {
case exports.COMMENT_TYPES.MODULE:
moduleComments.push(comment);
break;
case exports.COMMENT_TYPES.METHOD:
methodComments.push(comment);
break;
case exports.COMMENT_TYPES.TYPE:
typeComments.push(comment);
break;
case exports.COMMENT_TYPES.VARIABLE:
varComments.push(comment);
break;
}
} else {
typelessComments.push(comment);
}
});
return moduleComments.concat(typeComments.concat(varComments.concat(methodComments.concat(typelessComments))));
} | [
"function",
"sortComments",
"(",
"comments",
")",
"{",
"var",
"moduleComments",
"=",
"[",
"]",
";",
"var",
"typeComments",
"=",
"[",
"]",
";",
"var",
"varComments",
"=",
"[",
"]",
";",
"var",
"methodComments",
"=",
"[",
"]",
";",
"var",
"typelessComments",
"=",
"[",
"]",
";",
"comments",
".",
"forEach",
"(",
"function",
"(",
"comment",
")",
"{",
"if",
"(",
"comment",
".",
"type",
")",
"{",
"switch",
"(",
"comment",
".",
"type",
")",
"{",
"case",
"exports",
".",
"COMMENT_TYPES",
".",
"MODULE",
":",
"moduleComments",
".",
"push",
"(",
"comment",
")",
";",
"break",
";",
"case",
"exports",
".",
"COMMENT_TYPES",
".",
"METHOD",
":",
"methodComments",
".",
"push",
"(",
"comment",
")",
";",
"break",
";",
"case",
"exports",
".",
"COMMENT_TYPES",
".",
"TYPE",
":",
"typeComments",
".",
"push",
"(",
"comment",
")",
";",
"break",
";",
"case",
"exports",
".",
"COMMENT_TYPES",
".",
"VARIABLE",
":",
"varComments",
".",
"push",
"(",
"comment",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"typelessComments",
".",
"push",
"(",
"comment",
")",
";",
"}",
"}",
")",
";",
"return",
"moduleComments",
".",
"concat",
"(",
"typeComments",
".",
"concat",
"(",
"varComments",
".",
"concat",
"(",
"methodComments",
".",
"concat",
"(",
"typelessComments",
")",
")",
")",
")",
";",
"}"
]
| Sort mapped reduced comments. Module comments first followed by class, variables and methods.
@param {Comment[]} comments an array of mapped-reduced comments
@return {Comment[]} sorted comments array
@private | [
"Sort",
"mapped",
"reduced",
"comments",
".",
"Module",
"comments",
"first",
"followed",
"by",
"class",
"variables",
"and",
"methods",
"."
]
| e972b6e3a9792f649e9fed9115b45cb010c90c8f | https://github.com/allanmboyd/docit/blob/e972b6e3a9792f649e9fed9115b45cb010c90c8f/lib/parser.js#L303-L332 | train |
allanmboyd/docit | lib/parser.js | identifyCommentType | function identifyCommentType(tag) {
var commentType = null;
for (var tagName in tag) {
if (tag.hasOwnProperty(tagName)) {
switch (tagName) {
case exports.TAG_NAMES.API:
case exports.TAG_NAMES.METHOD:
case exports.TAG_NAMES.METHOD_SIGNATURE:
case exports.TAG_NAMES.METHOD_NAME:
case exports.TAG_NAMES.PARAM:
case exports.TAG_NAMES.RETURN:
case exports.TAG_NAMES.THROWS:
commentType = exports.COMMENT_TYPES.METHOD;
break;
case exports.TAG_NAMES.MODULE:
case exports.TAG_NAMES.REQUIRES:
commentType = exports.COMMENT_TYPES.MODULE;
break;
case exports.TAG_NAMES.CLASS:
commentType = exports.COMMENT_TYPES.TYPE;
break;
case exports.TAG_NAMES.VARIABLE_NAME:
commentType = exports.COMMENT_TYPES.VARIABLE;
break;
}
}
}
return commentType;
} | javascript | function identifyCommentType(tag) {
var commentType = null;
for (var tagName in tag) {
if (tag.hasOwnProperty(tagName)) {
switch (tagName) {
case exports.TAG_NAMES.API:
case exports.TAG_NAMES.METHOD:
case exports.TAG_NAMES.METHOD_SIGNATURE:
case exports.TAG_NAMES.METHOD_NAME:
case exports.TAG_NAMES.PARAM:
case exports.TAG_NAMES.RETURN:
case exports.TAG_NAMES.THROWS:
commentType = exports.COMMENT_TYPES.METHOD;
break;
case exports.TAG_NAMES.MODULE:
case exports.TAG_NAMES.REQUIRES:
commentType = exports.COMMENT_TYPES.MODULE;
break;
case exports.TAG_NAMES.CLASS:
commentType = exports.COMMENT_TYPES.TYPE;
break;
case exports.TAG_NAMES.VARIABLE_NAME:
commentType = exports.COMMENT_TYPES.VARIABLE;
break;
}
}
}
return commentType;
} | [
"function",
"identifyCommentType",
"(",
"tag",
")",
"{",
"var",
"commentType",
"=",
"null",
";",
"for",
"(",
"var",
"tagName",
"in",
"tag",
")",
"{",
"if",
"(",
"tag",
".",
"hasOwnProperty",
"(",
"tagName",
")",
")",
"{",
"switch",
"(",
"tagName",
")",
"{",
"case",
"exports",
".",
"TAG_NAMES",
".",
"API",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"METHOD",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"METHOD_SIGNATURE",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"METHOD_NAME",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"PARAM",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"RETURN",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"THROWS",
":",
"commentType",
"=",
"exports",
".",
"COMMENT_TYPES",
".",
"METHOD",
";",
"break",
";",
"case",
"exports",
".",
"TAG_NAMES",
".",
"MODULE",
":",
"case",
"exports",
".",
"TAG_NAMES",
".",
"REQUIRES",
":",
"commentType",
"=",
"exports",
".",
"COMMENT_TYPES",
".",
"MODULE",
";",
"break",
";",
"case",
"exports",
".",
"TAG_NAMES",
".",
"CLASS",
":",
"commentType",
"=",
"exports",
".",
"COMMENT_TYPES",
".",
"TYPE",
";",
"break",
";",
"case",
"exports",
".",
"TAG_NAMES",
".",
"VARIABLE_NAME",
":",
"commentType",
"=",
"exports",
".",
"COMMENT_TYPES",
".",
"VARIABLE",
";",
"break",
";",
"}",
"}",
"}",
"return",
"commentType",
";",
"}"
]
| Try to identify the type of a comment from a comment tag.
@param tag a tag
@return {String} the type of the comment or null if not identified
@private | [
"Try",
"to",
"identify",
"the",
"type",
"of",
"a",
"comment",
"from",
"a",
"comment",
"tag",
"."
]
| e972b6e3a9792f649e9fed9115b45cb010c90c8f | https://github.com/allanmboyd/docit/blob/e972b6e3a9792f649e9fed9115b45cb010c90c8f/lib/parser.js#L339-L368 | train |
jkroso/balance-svg-paths | index.js | balance | function balance(a, b){
var diff = a.length - b.length
var short = diff >= 0 ? b : a
diff = Math.abs(diff)
while (diff--) short.push(['c',0,0,0,0,0,0])
return [a, b]
} | javascript | function balance(a, b){
var diff = a.length - b.length
var short = diff >= 0 ? b : a
diff = Math.abs(diff)
while (diff--) short.push(['c',0,0,0,0,0,0])
return [a, b]
} | [
"function",
"balance",
"(",
"a",
",",
"b",
")",
"{",
"var",
"diff",
"=",
"a",
".",
"length",
"-",
"b",
".",
"length",
"var",
"short",
"=",
"diff",
">=",
"0",
"?",
"b",
":",
"a",
"diff",
"=",
"Math",
".",
"abs",
"(",
"diff",
")",
"while",
"(",
"diff",
"--",
")",
"short",
".",
"push",
"(",
"[",
"'c'",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
")",
"return",
"[",
"a",
",",
"b",
"]",
"}"
]
| define `a` and `b` using the same number of
path segments while preserving their shape
@param {Array} a
@param {Array} b
@return {Array} | [
"define",
"a",
"and",
"b",
"using",
"the",
"same",
"number",
"of",
"path",
"segments",
"while",
"preserving",
"their",
"shape"
]
| 3985c03857ef3e7811ab3a0a25fffba96cd3f2aa | https://github.com/jkroso/balance-svg-paths/blob/3985c03857ef3e7811ab3a0a25fffba96cd3f2aa/index.js#L13-L19 | train |
tlid/tlid | src/vscode/tlid-vscode/extension.js | activate | function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "Tlid" is now active!');
// // The command has been defined in the package.json file
// // Now provide the implementation of the command with registerCommand
// // The commandId parameter must match the command field in package.json
// let disposable = vscode.commands.registerCommand('extension.sayHello', function () {
// // The code you place here will be executed every time your command is executed
// // Display a message box to the user
// vscode.window.showInformationMessage('Hello World!');
// });
let disposableTlidGet = vscode.commands.registerCommand('extension.TlidGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Tlid...");
var tlidValue = tlid.get();
clipboardy.writeSync(tlidValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidValue);
});
let disposableTlidLineToJSON = vscode.commands.registerCommand('extension.TlidLineToJSON', function () {
// The code you place here will be executed every time your command is executed
// vscode.window.showInformationMessage("Transforming Tlid line...");
var tlidLine = clipboardy.readSync();
var tlidValue = tlid.get();
var r =
gixdeco.geto(tlidLine);
try {
if (r['tlid'] == null)
r['tlid'] = tlidValue; //setting it up
} catch (error) {
}
// if (r.tlid == null || r.tlid == "-1")
var out = JSON.stringify(r);
clipboardy.writeSync(out);
// Display a message box to the user
vscode.window.showInformationMessage(out);
// vscode.window.showInformationMessage(tlidLine);
});
let disposableTlidGetJSON = vscode.commands.registerCommand('extension.TlidGetJSON', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating JSON Tlid...");
var tlidValue = tlid.json();
clipboardy.writeSync(tlidValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidValue);
});
let disposableTlidugGet = vscode.commands.registerCommand('extension.TlidugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Tlidug...");
var tlidugValue = tlidug.get();
clipboardy.writeSync(tlidugValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidugValue);
});
let disposableIdugGet = vscode.commands.registerCommand('extension.IdugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Idug...");
var idugValue = idug.get();
clipboardy.writeSync(idugValue);
// Display a message box to the user
vscode.window.showInformationMessage(idugValue);
});
let disposableUnIdugGet = vscode.commands.registerCommand('extension.UnIdugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating UnDashed Idug...");
var idugValue = idug.un();
clipboardy.writeSync(idugValue);
// Display a message box to the user
vscode.window.showInformationMessage(idugValue);
});
context.subscriptions.push(disposableTlidLineToJSON);
context.subscriptions.push(disposableUnIdugGet);
context.subscriptions.push(disposableIdugGet);
context.subscriptions.push(disposableTlidGet);
context.subscriptions.push(disposableTlidGetJSON);
context.subscriptions.push(disposableTlidugGet);
} | javascript | function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "Tlid" is now active!');
// // The command has been defined in the package.json file
// // Now provide the implementation of the command with registerCommand
// // The commandId parameter must match the command field in package.json
// let disposable = vscode.commands.registerCommand('extension.sayHello', function () {
// // The code you place here will be executed every time your command is executed
// // Display a message box to the user
// vscode.window.showInformationMessage('Hello World!');
// });
let disposableTlidGet = vscode.commands.registerCommand('extension.TlidGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Tlid...");
var tlidValue = tlid.get();
clipboardy.writeSync(tlidValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidValue);
});
let disposableTlidLineToJSON = vscode.commands.registerCommand('extension.TlidLineToJSON', function () {
// The code you place here will be executed every time your command is executed
// vscode.window.showInformationMessage("Transforming Tlid line...");
var tlidLine = clipboardy.readSync();
var tlidValue = tlid.get();
var r =
gixdeco.geto(tlidLine);
try {
if (r['tlid'] == null)
r['tlid'] = tlidValue; //setting it up
} catch (error) {
}
// if (r.tlid == null || r.tlid == "-1")
var out = JSON.stringify(r);
clipboardy.writeSync(out);
// Display a message box to the user
vscode.window.showInformationMessage(out);
// vscode.window.showInformationMessage(tlidLine);
});
let disposableTlidGetJSON = vscode.commands.registerCommand('extension.TlidGetJSON', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating JSON Tlid...");
var tlidValue = tlid.json();
clipboardy.writeSync(tlidValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidValue);
});
let disposableTlidugGet = vscode.commands.registerCommand('extension.TlidugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Tlidug...");
var tlidugValue = tlidug.get();
clipboardy.writeSync(tlidugValue);
// Display a message box to the user
vscode.window.showInformationMessage(tlidugValue);
});
let disposableIdugGet = vscode.commands.registerCommand('extension.IdugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating Idug...");
var idugValue = idug.get();
clipboardy.writeSync(idugValue);
// Display a message box to the user
vscode.window.showInformationMessage(idugValue);
});
let disposableUnIdugGet = vscode.commands.registerCommand('extension.UnIdugGet', function () {
// The code you place here will be executed every time your command is executed
vscode.window.showInformationMessage("Creating UnDashed Idug...");
var idugValue = idug.un();
clipboardy.writeSync(idugValue);
// Display a message box to the user
vscode.window.showInformationMessage(idugValue);
});
context.subscriptions.push(disposableTlidLineToJSON);
context.subscriptions.push(disposableUnIdugGet);
context.subscriptions.push(disposableIdugGet);
context.subscriptions.push(disposableTlidGet);
context.subscriptions.push(disposableTlidGetJSON);
context.subscriptions.push(disposableTlidugGet);
} | [
"function",
"activate",
"(",
"context",
")",
"{",
"console",
".",
"log",
"(",
"'Congratulations, your extension \"Tlid\" is now active!'",
")",
";",
"let",
"disposableTlidGet",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.TlidGet'",
",",
"function",
"(",
")",
"{",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"\"Creating Tlid...\"",
")",
";",
"var",
"tlidValue",
"=",
"tlid",
".",
"get",
"(",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"tlidValue",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"tlidValue",
")",
";",
"}",
")",
";",
"let",
"disposableTlidLineToJSON",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.TlidLineToJSON'",
",",
"function",
"(",
")",
"{",
"var",
"tlidLine",
"=",
"clipboardy",
".",
"readSync",
"(",
")",
";",
"var",
"tlidValue",
"=",
"tlid",
".",
"get",
"(",
")",
";",
"var",
"r",
"=",
"gixdeco",
".",
"geto",
"(",
"tlidLine",
")",
";",
"try",
"{",
"if",
"(",
"r",
"[",
"'tlid'",
"]",
"==",
"null",
")",
"r",
"[",
"'tlid'",
"]",
"=",
"tlidValue",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"}",
"var",
"out",
"=",
"JSON",
".",
"stringify",
"(",
"r",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"out",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"out",
")",
";",
"}",
")",
";",
"let",
"disposableTlidGetJSON",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.TlidGetJSON'",
",",
"function",
"(",
")",
"{",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"\"Creating JSON Tlid...\"",
")",
";",
"var",
"tlidValue",
"=",
"tlid",
".",
"json",
"(",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"tlidValue",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"tlidValue",
")",
";",
"}",
")",
";",
"let",
"disposableTlidugGet",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.TlidugGet'",
",",
"function",
"(",
")",
"{",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"\"Creating Tlidug...\"",
")",
";",
"var",
"tlidugValue",
"=",
"tlidug",
".",
"get",
"(",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"tlidugValue",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"tlidugValue",
")",
";",
"}",
")",
";",
"let",
"disposableIdugGet",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.IdugGet'",
",",
"function",
"(",
")",
"{",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"\"Creating Idug...\"",
")",
";",
"var",
"idugValue",
"=",
"idug",
".",
"get",
"(",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"idugValue",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"idugValue",
")",
";",
"}",
")",
";",
"let",
"disposableUnIdugGet",
"=",
"vscode",
".",
"commands",
".",
"registerCommand",
"(",
"'extension.UnIdugGet'",
",",
"function",
"(",
")",
"{",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"\"Creating UnDashed Idug...\"",
")",
";",
"var",
"idugValue",
"=",
"idug",
".",
"un",
"(",
")",
";",
"clipboardy",
".",
"writeSync",
"(",
"idugValue",
")",
";",
"vscode",
".",
"window",
".",
"showInformationMessage",
"(",
"idugValue",
")",
";",
"}",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableTlidLineToJSON",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableUnIdugGet",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableIdugGet",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableTlidGet",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableTlidGetJSON",
")",
";",
"context",
".",
"subscriptions",
".",
"push",
"(",
"disposableTlidugGet",
")",
";",
"}"
]
| this method is called when your extension is activated your extension is activated the very first time the command is executed | [
"this",
"method",
"is",
"called",
"when",
"your",
"extension",
"is",
"activated",
"your",
"extension",
"is",
"activated",
"the",
"very",
"first",
"time",
"the",
"command",
"is",
"executed"
]
| ddfab991965c1cf01abdde0311e1ee96f8defab3 | https://github.com/tlid/tlid/blob/ddfab991965c1cf01abdde0311e1ee96f8defab3/src/vscode/tlid-vscode/extension.js#L22-L126 | train |
byu-oit/fully-typed | bin/string.js | TypedString | function TypedString (config) {
const string = this;
// validate min length
if (config.hasOwnProperty('minLength') && (!util.isInteger(config.minLength) || config.minLength < 0)) {
const message = util.propertyErrorMessage('minLength', config.minLength, 'Must be an integer that is greater than or equal to zero.');
throw Error(message);
}
const minLength = config.hasOwnProperty('minLength') ? config.minLength : 0;
// validate max length
if (config.hasOwnProperty('maxLength') && (!util.isInteger(config.maxLength) || config.maxLength < minLength)) {
const message = util.propertyErrorMessage('maxLength', config.maxLength, 'Must be an integer that is greater than or equal to the minLength.');
throw Error(message);
}
// validate pattern
if (config.hasOwnProperty('pattern') && !(config.pattern instanceof RegExp)) {
const message = util.propertyErrorMessage('pattern', config.pattern, 'Must be a regular expression object.');
throw Error(message);
}
// define properties
Object.defineProperties(string, {
maxLength: {
/**
* @property
* @name TypedString#maxLength
* @type {number}
*/
value: Math.round(config.maxLength),
writable: false
},
minLength: {
/**
* @property
* @name TypedString#minLength
* @type {number}
*/
value: Math.round(config.minLength),
writable: false
},
pattern: {
/**
* @property
* @name TypedString#pattern
* @type {RegExp}
*/
value: config.pattern,
writable: false
}
});
return string;
} | javascript | function TypedString (config) {
const string = this;
// validate min length
if (config.hasOwnProperty('minLength') && (!util.isInteger(config.minLength) || config.minLength < 0)) {
const message = util.propertyErrorMessage('minLength', config.minLength, 'Must be an integer that is greater than or equal to zero.');
throw Error(message);
}
const minLength = config.hasOwnProperty('minLength') ? config.minLength : 0;
// validate max length
if (config.hasOwnProperty('maxLength') && (!util.isInteger(config.maxLength) || config.maxLength < minLength)) {
const message = util.propertyErrorMessage('maxLength', config.maxLength, 'Must be an integer that is greater than or equal to the minLength.');
throw Error(message);
}
// validate pattern
if (config.hasOwnProperty('pattern') && !(config.pattern instanceof RegExp)) {
const message = util.propertyErrorMessage('pattern', config.pattern, 'Must be a regular expression object.');
throw Error(message);
}
// define properties
Object.defineProperties(string, {
maxLength: {
/**
* @property
* @name TypedString#maxLength
* @type {number}
*/
value: Math.round(config.maxLength),
writable: false
},
minLength: {
/**
* @property
* @name TypedString#minLength
* @type {number}
*/
value: Math.round(config.minLength),
writable: false
},
pattern: {
/**
* @property
* @name TypedString#pattern
* @type {RegExp}
*/
value: config.pattern,
writable: false
}
});
return string;
} | [
"function",
"TypedString",
"(",
"config",
")",
"{",
"const",
"string",
"=",
"this",
";",
"if",
"(",
"config",
".",
"hasOwnProperty",
"(",
"'minLength'",
")",
"&&",
"(",
"!",
"util",
".",
"isInteger",
"(",
"config",
".",
"minLength",
")",
"||",
"config",
".",
"minLength",
"<",
"0",
")",
")",
"{",
"const",
"message",
"=",
"util",
".",
"propertyErrorMessage",
"(",
"'minLength'",
",",
"config",
".",
"minLength",
",",
"'Must be an integer that is greater than or equal to zero.'",
")",
";",
"throw",
"Error",
"(",
"message",
")",
";",
"}",
"const",
"minLength",
"=",
"config",
".",
"hasOwnProperty",
"(",
"'minLength'",
")",
"?",
"config",
".",
"minLength",
":",
"0",
";",
"if",
"(",
"config",
".",
"hasOwnProperty",
"(",
"'maxLength'",
")",
"&&",
"(",
"!",
"util",
".",
"isInteger",
"(",
"config",
".",
"maxLength",
")",
"||",
"config",
".",
"maxLength",
"<",
"minLength",
")",
")",
"{",
"const",
"message",
"=",
"util",
".",
"propertyErrorMessage",
"(",
"'maxLength'",
",",
"config",
".",
"maxLength",
",",
"'Must be an integer that is greater than or equal to the minLength.'",
")",
";",
"throw",
"Error",
"(",
"message",
")",
";",
"}",
"if",
"(",
"config",
".",
"hasOwnProperty",
"(",
"'pattern'",
")",
"&&",
"!",
"(",
"config",
".",
"pattern",
"instanceof",
"RegExp",
")",
")",
"{",
"const",
"message",
"=",
"util",
".",
"propertyErrorMessage",
"(",
"'pattern'",
",",
"config",
".",
"pattern",
",",
"'Must be a regular expression object.'",
")",
";",
"throw",
"Error",
"(",
"message",
")",
";",
"}",
"Object",
".",
"defineProperties",
"(",
"string",
",",
"{",
"maxLength",
":",
"{",
"value",
":",
"Math",
".",
"round",
"(",
"config",
".",
"maxLength",
")",
",",
"writable",
":",
"false",
"}",
",",
"minLength",
":",
"{",
"value",
":",
"Math",
".",
"round",
"(",
"config",
".",
"minLength",
")",
",",
"writable",
":",
"false",
"}",
",",
"pattern",
":",
"{",
"value",
":",
"config",
".",
"pattern",
",",
"writable",
":",
"false",
"}",
"}",
")",
";",
"return",
"string",
";",
"}"
]
| Create a TypedString instance.
@param {object} config
@returns {TypedString}
@augments Typed
@constructor | [
"Create",
"a",
"TypedString",
"instance",
"."
]
| ed6b3ed88ffc72990acffb765232eaaee261afef | https://github.com/byu-oit/fully-typed/blob/ed6b3ed88ffc72990acffb765232eaaee261afef/bin/string.js#L29-L87 | train |
frankwallis/component-resolve-fields | lib/index.js | custom | function custom(options, onfile, done) {
if ((!options) || (typeof(options) == 'function'))
throw new Error("please provide some options");
if (!options.fields)
throw new Error("please provide some fields");
return resolveList(builder.files, options, [], onfile, done);
} | javascript | function custom(options, onfile, done) {
if ((!options) || (typeof(options) == 'function'))
throw new Error("please provide some options");
if (!options.fields)
throw new Error("please provide some fields");
return resolveList(builder.files, options, [], onfile, done);
} | [
"function",
"custom",
"(",
"options",
",",
"onfile",
",",
"done",
")",
"{",
"if",
"(",
"(",
"!",
"options",
")",
"||",
"(",
"typeof",
"(",
"options",
")",
"==",
"'function'",
")",
")",
"throw",
"new",
"Error",
"(",
"\"please provide some options\"",
")",
";",
"if",
"(",
"!",
"options",
".",
"fields",
")",
"throw",
"new",
"Error",
"(",
"\"please provide some fields\"",
")",
";",
"return",
"resolveList",
"(",
"builder",
".",
"files",
",",
"options",
",",
"[",
"]",
",",
"onfile",
",",
"done",
")",
";",
"}"
]
| lets you specifiy all the fields | [
"lets",
"you",
"specifiy",
"all",
"the",
"fields"
]
| b376968181302d9a41511668ef5d44b8f23edb4e | https://github.com/frankwallis/component-resolve-fields/blob/b376968181302d9a41511668ef5d44b8f23edb4e/lib/index.js#L32-L41 | train |
mnichols/ankh | lib/index.js | Ankh | function Ankh(kernel) {
Object.defineProperty(this,'kernel',{
value: (kernel || new Kernel())
,configurable: false
,writable: false
,enumerable: true
})
} | javascript | function Ankh(kernel) {
Object.defineProperty(this,'kernel',{
value: (kernel || new Kernel())
,configurable: false
,writable: false
,enumerable: true
})
} | [
"function",
"Ankh",
"(",
"kernel",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'kernel'",
",",
"{",
"value",
":",
"(",
"kernel",
"||",
"new",
"Kernel",
"(",
")",
")",
",",
"configurable",
":",
"false",
",",
"writable",
":",
"false",
",",
"enumerable",
":",
"true",
"}",
")",
"}"
]
| The primary object for interacting with the container.
@class Ankh | [
"The",
"primary",
"object",
"for",
"interacting",
"with",
"the",
"container",
"."
]
| b5f6eae24b2dece4025b4f11cea7f1560d3b345f | https://github.com/mnichols/ankh/blob/b5f6eae24b2dece4025b4f11cea7f1560d3b345f/lib/index.js#L13-L20 | train |
prodest/node-mw-api-prodest | lib/errors.js | notFound | function notFound( req, res, next ) {
var err = new Error( 'Not Found' );
err.status = 404;
next( err );
} | javascript | function notFound( req, res, next ) {
var err = new Error( 'Not Found' );
err.status = 404;
next( err );
} | [
"function",
"notFound",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'Not Found'",
")",
";",
"err",
".",
"status",
"=",
"404",
";",
"next",
"(",
"err",
")",
";",
"}"
]
| catch 404 and forward to error handler | [
"catch",
"404",
"and",
"forward",
"to",
"error",
"handler"
]
| b9b34fbd92d14e996629d6ddb5ea1700076ee83e | https://github.com/prodest/node-mw-api-prodest/blob/b9b34fbd92d14e996629d6ddb5ea1700076ee83e/lib/errors.js#L8-L13 | train |
prodest/node-mw-api-prodest | lib/errors.js | debug | function debug( err, req, res, next ) {
res.status( err.status || 500 );
err.guid = uuid.v4();
console.error( err );
res.json( {
error: err.message,
message: err.userMessage,
handled: err.handled || false,
guid: err.guid,
stack: err.stack
} );
} | javascript | function debug( err, req, res, next ) {
res.status( err.status || 500 );
err.guid = uuid.v4();
console.error( err );
res.json( {
error: err.message,
message: err.userMessage,
handled: err.handled || false,
guid: err.guid,
stack: err.stack
} );
} | [
"function",
"debug",
"(",
"err",
",",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"status",
"(",
"err",
".",
"status",
"||",
"500",
")",
";",
"err",
".",
"guid",
"=",
"uuid",
".",
"v4",
"(",
")",
";",
"console",
".",
"error",
"(",
"err",
")",
";",
"res",
".",
"json",
"(",
"{",
"error",
":",
"err",
".",
"message",
",",
"message",
":",
"err",
".",
"userMessage",
",",
"handled",
":",
"err",
".",
"handled",
"||",
"false",
",",
"guid",
":",
"err",
".",
"guid",
",",
"stack",
":",
"err",
".",
"stack",
"}",
")",
";",
"}"
]
| development error handler will print full error | [
"development",
"error",
"handler",
"will",
"print",
"full",
"error"
]
| b9b34fbd92d14e996629d6ddb5ea1700076ee83e | https://github.com/prodest/node-mw-api-prodest/blob/b9b34fbd92d14e996629d6ddb5ea1700076ee83e/lib/errors.js#L17-L31 | train |
Fauntleroy/Igneous | examples/jquery-tmpl/assets/scripts/jquery.tmpl.js | function( tmpl, data, options, parentItem ) {
var ret, topLevel = !parentItem;
if ( topLevel ) {
// This is a top-level tmpl call (not from a nested template using {{tmpl}})
parentItem = topTmplItem;
tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
} else if ( !tmpl ) {
// The template item is already associated with DOM - this is a refresh.
// Re-evaluate rendered template for the parentItem
tmpl = parentItem.tmpl;
newTmplItems[parentItem.key] = parentItem;
parentItem.nodes = [];
if ( parentItem.wrapped ) {
updateWrapped( parentItem, parentItem.wrapped );
}
// Rebuild, without creating a new template item
return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
}
if ( !tmpl ) {
return []; // Could throw...
}
if ( typeof data === "function" ) {
data = data.call( parentItem || {} );
}
if ( options && options.wrapped ) {
updateWrapped( options, options.wrapped );
}
ret = jQuery.isArray( data ) ?
jQuery.map( data, function( dataItem ) {
return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
}) :
[ newTmplItem( options, parentItem, tmpl, data ) ];
return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
} | javascript | function( tmpl, data, options, parentItem ) {
var ret, topLevel = !parentItem;
if ( topLevel ) {
// This is a top-level tmpl call (not from a nested template using {{tmpl}})
parentItem = topTmplItem;
tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level
} else if ( !tmpl ) {
// The template item is already associated with DOM - this is a refresh.
// Re-evaluate rendered template for the parentItem
tmpl = parentItem.tmpl;
newTmplItems[parentItem.key] = parentItem;
parentItem.nodes = [];
if ( parentItem.wrapped ) {
updateWrapped( parentItem, parentItem.wrapped );
}
// Rebuild, without creating a new template item
return jQuery( build( parentItem, null, parentItem.tmpl( jQuery, parentItem ) ));
}
if ( !tmpl ) {
return []; // Could throw...
}
if ( typeof data === "function" ) {
data = data.call( parentItem || {} );
}
if ( options && options.wrapped ) {
updateWrapped( options, options.wrapped );
}
ret = jQuery.isArray( data ) ?
jQuery.map( data, function( dataItem ) {
return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
}) :
[ newTmplItem( options, parentItem, tmpl, data ) ];
return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
} | [
"function",
"(",
"tmpl",
",",
"data",
",",
"options",
",",
"parentItem",
")",
"{",
"var",
"ret",
",",
"topLevel",
"=",
"!",
"parentItem",
";",
"if",
"(",
"topLevel",
")",
"{",
"parentItem",
"=",
"topTmplItem",
";",
"tmpl",
"=",
"jQuery",
".",
"template",
"[",
"tmpl",
"]",
"||",
"jQuery",
".",
"template",
"(",
"null",
",",
"tmpl",
")",
";",
"wrappedItems",
"=",
"{",
"}",
";",
"}",
"else",
"if",
"(",
"!",
"tmpl",
")",
"{",
"tmpl",
"=",
"parentItem",
".",
"tmpl",
";",
"newTmplItems",
"[",
"parentItem",
".",
"key",
"]",
"=",
"parentItem",
";",
"parentItem",
".",
"nodes",
"=",
"[",
"]",
";",
"if",
"(",
"parentItem",
".",
"wrapped",
")",
"{",
"updateWrapped",
"(",
"parentItem",
",",
"parentItem",
".",
"wrapped",
")",
";",
"}",
"return",
"jQuery",
"(",
"build",
"(",
"parentItem",
",",
"null",
",",
"parentItem",
".",
"tmpl",
"(",
"jQuery",
",",
"parentItem",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"tmpl",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"typeof",
"data",
"===",
"\"function\"",
")",
"{",
"data",
"=",
"data",
".",
"call",
"(",
"parentItem",
"||",
"{",
"}",
")",
";",
"}",
"if",
"(",
"options",
"&&",
"options",
".",
"wrapped",
")",
"{",
"updateWrapped",
"(",
"options",
",",
"options",
".",
"wrapped",
")",
";",
"}",
"ret",
"=",
"jQuery",
".",
"isArray",
"(",
"data",
")",
"?",
"jQuery",
".",
"map",
"(",
"data",
",",
"function",
"(",
"dataItem",
")",
"{",
"return",
"dataItem",
"?",
"newTmplItem",
"(",
"options",
",",
"parentItem",
",",
"tmpl",
",",
"dataItem",
")",
":",
"null",
";",
"}",
")",
":",
"[",
"newTmplItem",
"(",
"options",
",",
"parentItem",
",",
"tmpl",
",",
"data",
")",
"]",
";",
"return",
"topLevel",
"?",
"jQuery",
"(",
"build",
"(",
"parentItem",
",",
"null",
",",
"ret",
")",
")",
":",
"ret",
";",
"}"
]
| Return wrapped set of template items, obtained by rendering template against data. | [
"Return",
"wrapped",
"set",
"of",
"template",
"items",
"obtained",
"by",
"rendering",
"template",
"against",
"data",
"."
]
| 73318fad5cac8a1b5114b8b80ff39dfd2a4542fa | https://github.com/Fauntleroy/Igneous/blob/73318fad5cac8a1b5114b8b80ff39dfd2a4542fa/examples/jquery-tmpl/assets/scripts/jquery.tmpl.js#L119-L153 | train |
|
Fauntleroy/Igneous | examples/jquery-tmpl/assets/scripts/jquery.tmpl.js | function( elem ) {
var tmplItem;
if ( elem instanceof jQuery ) {
elem = elem[0];
}
while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
return tmplItem || topTmplItem;
} | javascript | function( elem ) {
var tmplItem;
if ( elem instanceof jQuery ) {
elem = elem[0];
}
while ( elem && elem.nodeType === 1 && !(tmplItem = jQuery.data( elem, "tmplItem" )) && (elem = elem.parentNode) ) {}
return tmplItem || topTmplItem;
} | [
"function",
"(",
"elem",
")",
"{",
"var",
"tmplItem",
";",
"if",
"(",
"elem",
"instanceof",
"jQuery",
")",
"{",
"elem",
"=",
"elem",
"[",
"0",
"]",
";",
"}",
"while",
"(",
"elem",
"&&",
"elem",
".",
"nodeType",
"===",
"1",
"&&",
"!",
"(",
"tmplItem",
"=",
"jQuery",
".",
"data",
"(",
"elem",
",",
"\"tmplItem\"",
")",
")",
"&&",
"(",
"elem",
"=",
"elem",
".",
"parentNode",
")",
")",
"{",
"}",
"return",
"tmplItem",
"||",
"topTmplItem",
";",
"}"
]
| Return rendered template item for an element. | [
"Return",
"rendered",
"template",
"item",
"for",
"an",
"element",
"."
]
| 73318fad5cac8a1b5114b8b80ff39dfd2a4542fa | https://github.com/Fauntleroy/Igneous/blob/73318fad5cac8a1b5114b8b80ff39dfd2a4542fa/examples/jquery-tmpl/assets/scripts/jquery.tmpl.js#L156-L163 | train |
|
nicktindall/cyclon.p2p-common | lib/ConsoleLogger.js | ConsoleLogger | function ConsoleLogger() {
this.error = function () {
if (loggingLevel(ERROR)) {
console.error.apply(this, arguments);
}
};
this.warn = function () {
if (loggingLevel(WARN)) {
console.warn.apply(this, arguments);
}
};
this.info = function () {
if (loggingLevel(INFO)) {
console.info.apply(this, arguments);
}
};
this.log = function () {
if (loggingLevel(INFO)) {
console.log.apply(this, arguments);
}
};
this.debug = function () {
if (loggingLevel(DEBUG)) {
console.log.apply(this, arguments);
}
};
this.setLevelToInfo = function () {
setLevel(INFO);
};
this.setLevelToDebug = function() {
setLevel(DEBUG);
};
this.setLevelToWarning = function() {
setLevel(WARN);
};
this.setLevelToError = function() {
setLevel(ERROR);
};
} | javascript | function ConsoleLogger() {
this.error = function () {
if (loggingLevel(ERROR)) {
console.error.apply(this, arguments);
}
};
this.warn = function () {
if (loggingLevel(WARN)) {
console.warn.apply(this, arguments);
}
};
this.info = function () {
if (loggingLevel(INFO)) {
console.info.apply(this, arguments);
}
};
this.log = function () {
if (loggingLevel(INFO)) {
console.log.apply(this, arguments);
}
};
this.debug = function () {
if (loggingLevel(DEBUG)) {
console.log.apply(this, arguments);
}
};
this.setLevelToInfo = function () {
setLevel(INFO);
};
this.setLevelToDebug = function() {
setLevel(DEBUG);
};
this.setLevelToWarning = function() {
setLevel(WARN);
};
this.setLevelToError = function() {
setLevel(ERROR);
};
} | [
"function",
"ConsoleLogger",
"(",
")",
"{",
"this",
".",
"error",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"loggingLevel",
"(",
"ERROR",
")",
")",
"{",
"console",
".",
"error",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"this",
".",
"warn",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"loggingLevel",
"(",
"WARN",
")",
")",
"{",
"console",
".",
"warn",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"this",
".",
"info",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"loggingLevel",
"(",
"INFO",
")",
")",
"{",
"console",
".",
"info",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"this",
".",
"log",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"loggingLevel",
"(",
"INFO",
")",
")",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"this",
".",
"debug",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"loggingLevel",
"(",
"DEBUG",
")",
")",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"}",
";",
"this",
".",
"setLevelToInfo",
"=",
"function",
"(",
")",
"{",
"setLevel",
"(",
"INFO",
")",
";",
"}",
";",
"this",
".",
"setLevelToDebug",
"=",
"function",
"(",
")",
"{",
"setLevel",
"(",
"DEBUG",
")",
";",
"}",
";",
"this",
".",
"setLevelToWarning",
"=",
"function",
"(",
")",
"{",
"setLevel",
"(",
"WARN",
")",
";",
"}",
";",
"this",
".",
"setLevelToError",
"=",
"function",
"(",
")",
"{",
"setLevel",
"(",
"ERROR",
")",
";",
"}",
";",
"}"
]
| Configurable console logger, default level is INFO
@constructor | [
"Configurable",
"console",
"logger",
"default",
"level",
"is",
"INFO"
]
| 04ee34984c9d5145e265a886bf261cb64dc20e3c | https://github.com/nicktindall/cyclon.p2p-common/blob/04ee34984c9d5145e265a886bf261cb64dc20e3c/lib/ConsoleLogger.js#L13-L60 | train |
skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/dom/iterator.js | getNestedEditableIn | function getNestedEditableIn( editablesContainer, remainingEditables ) {
if ( remainingEditables == null )
remainingEditables = findNestedEditables( editablesContainer );
var editable;
while ( ( editable = remainingEditables.shift() ) ) {
if ( isIterableEditable( editable ) )
return { element: editable, remaining: remainingEditables };
}
return null;
} | javascript | function getNestedEditableIn( editablesContainer, remainingEditables ) {
if ( remainingEditables == null )
remainingEditables = findNestedEditables( editablesContainer );
var editable;
while ( ( editable = remainingEditables.shift() ) ) {
if ( isIterableEditable( editable ) )
return { element: editable, remaining: remainingEditables };
}
return null;
} | [
"function",
"getNestedEditableIn",
"(",
"editablesContainer",
",",
"remainingEditables",
")",
"{",
"if",
"(",
"remainingEditables",
"==",
"null",
")",
"remainingEditables",
"=",
"findNestedEditables",
"(",
"editablesContainer",
")",
";",
"var",
"editable",
";",
"while",
"(",
"(",
"editable",
"=",
"remainingEditables",
".",
"shift",
"(",
")",
")",
")",
"{",
"if",
"(",
"isIterableEditable",
"(",
"editable",
")",
")",
"return",
"{",
"element",
":",
"editable",
",",
"remaining",
":",
"remainingEditables",
"}",
";",
"}",
"return",
"null",
";",
"}"
]
| Does a nested editables lookup inside editablesContainer. If remainingEditables is set will lookup inside this array. @param {CKEDITOR.dom.element} editablesContainer @param {CKEDITOR.dom.element[]} [remainingEditables] | [
"Does",
"a",
"nested",
"editables",
"lookup",
"inside",
"editablesContainer",
".",
"If",
"remainingEditables",
"is",
"set",
"will",
"lookup",
"inside",
"this",
"array",
"."
]
| 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/dom/iterator.js#L438-L450 | train |
skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/dom/iterator.js | rangeAtInnerBlockBoundary | function rangeAtInnerBlockBoundary( range, block, checkEnd ) {
if ( !block )
return false;
var testRange = range.clone();
testRange.collapse( !checkEnd );
return testRange.checkBoundaryOfElement( block, checkEnd ? CKEDITOR.START : CKEDITOR.END );
} | javascript | function rangeAtInnerBlockBoundary( range, block, checkEnd ) {
if ( !block )
return false;
var testRange = range.clone();
testRange.collapse( !checkEnd );
return testRange.checkBoundaryOfElement( block, checkEnd ? CKEDITOR.START : CKEDITOR.END );
} | [
"function",
"rangeAtInnerBlockBoundary",
"(",
"range",
",",
"block",
",",
"checkEnd",
")",
"{",
"if",
"(",
"!",
"block",
")",
"return",
"false",
";",
"var",
"testRange",
"=",
"range",
".",
"clone",
"(",
")",
";",
"testRange",
".",
"collapse",
"(",
"!",
"checkEnd",
")",
";",
"return",
"testRange",
".",
"checkBoundaryOfElement",
"(",
"block",
",",
"checkEnd",
"?",
"CKEDITOR",
".",
"START",
":",
"CKEDITOR",
".",
"END",
")",
";",
"}"
]
| Checks whether range starts or ends at inner block boundary. See usage comments to learn more. | [
"Checks",
"whether",
"range",
"starts",
"or",
"ends",
"at",
"inner",
"block",
"boundary",
".",
"See",
"usage",
"comments",
"to",
"learn",
"more",
"."
]
| 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/dom/iterator.js#L515-L522 | train |
jonschlinkert/orgs | index.js | orgs | async function orgs(users, options) {
const opts = Object.assign({}, options);
const acc = { orgs: [], names: [] };
if (isObject(users)) {
return github('paged', '/user/orgs', users).then(res => addOrgs(acc, res));
}
if (typeof users === 'string') users = [users];
if (!Array.isArray(users)) {
return Promise.reject(new TypeError('expected users to be a string or array'));
}
const pending = [];
for (const name of users) {
pending.push(getOrgs(acc, name, options));
}
await Promise.all(pending);
if (opts.sort !== false) {
return acc.orgs.sort(compare('login'));
}
return acc.orgs;
} | javascript | async function orgs(users, options) {
const opts = Object.assign({}, options);
const acc = { orgs: [], names: [] };
if (isObject(users)) {
return github('paged', '/user/orgs', users).then(res => addOrgs(acc, res));
}
if (typeof users === 'string') users = [users];
if (!Array.isArray(users)) {
return Promise.reject(new TypeError('expected users to be a string or array'));
}
const pending = [];
for (const name of users) {
pending.push(getOrgs(acc, name, options));
}
await Promise.all(pending);
if (opts.sort !== false) {
return acc.orgs.sort(compare('login'));
}
return acc.orgs;
} | [
"async",
"function",
"orgs",
"(",
"users",
",",
"options",
")",
"{",
"const",
"opts",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"options",
")",
";",
"const",
"acc",
"=",
"{",
"orgs",
":",
"[",
"]",
",",
"names",
":",
"[",
"]",
"}",
";",
"if",
"(",
"isObject",
"(",
"users",
")",
")",
"{",
"return",
"github",
"(",
"'paged'",
",",
"'/user/orgs'",
",",
"users",
")",
".",
"then",
"(",
"res",
"=>",
"addOrgs",
"(",
"acc",
",",
"res",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"users",
"===",
"'string'",
")",
"users",
"=",
"[",
"users",
"]",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"users",
")",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"'expected users to be a string or array'",
")",
")",
";",
"}",
"const",
"pending",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"name",
"of",
"users",
")",
"{",
"pending",
".",
"push",
"(",
"getOrgs",
"(",
"acc",
",",
"name",
",",
"options",
")",
")",
";",
"}",
"await",
"Promise",
".",
"all",
"(",
"pending",
")",
";",
"if",
"(",
"opts",
".",
"sort",
"!==",
"false",
")",
"{",
"return",
"acc",
".",
"orgs",
".",
"sort",
"(",
"compare",
"(",
"'login'",
")",
")",
";",
"}",
"return",
"acc",
".",
"orgs",
";",
"}"
]
| Get publicly available information from the GitHub API for one or
more users or organizations. If user names are passed, all orgs for those
users are returned. If organization names are passed, an object is
returned with information about each org.
```js
const orgs = require('orgs');
// see github-base for other authentication options
orgs(['doowb', 'jonschlinkert'], { token: 'YOUR_GITHUB_AUTH_TOKEN' })
.then(orgs => {
// array of organization objects from the GitHub API
console.log(orgs);
})
.catch(console.error)l
```
@param {String|Array} `users` One or more users or organization names.
@param {Object} `options`
@return {Promise}
@api public | [
"Get",
"publicly",
"available",
"information",
"from",
"the",
"GitHub",
"API",
"for",
"one",
"or",
"more",
"users",
"or",
"organizations",
".",
"If",
"user",
"names",
"are",
"passed",
"all",
"orgs",
"for",
"those",
"users",
"are",
"returned",
".",
"If",
"organization",
"names",
"are",
"passed",
"an",
"object",
"is",
"returned",
"with",
"information",
"about",
"each",
"org",
"."
]
| 1f11e3d2c08bd7d54934b74dfce350ae9b7a4f58 | https://github.com/jonschlinkert/orgs/blob/1f11e3d2c08bd7d54934b74dfce350ae9b7a4f58/index.js#L29-L53 | train |
moraispgsi/fsm-core | src/indexOld.js | init | function init(){
debug("Checking if there is a repository");
return co(function*(){
let repo;
try {
repo = yield nodegit.Repository.open(repositoryPath);
} catch(err) {
debug("Repository not found.");
repo = yield _createRepository();
}
debug("Repository is ready");
return repo;
});
} | javascript | function init(){
debug("Checking if there is a repository");
return co(function*(){
let repo;
try {
repo = yield nodegit.Repository.open(repositoryPath);
} catch(err) {
debug("Repository not found.");
repo = yield _createRepository();
}
debug("Repository is ready");
return repo;
});
} | [
"function",
"init",
"(",
")",
"{",
"debug",
"(",
"\"Checking if there is a repository\"",
")",
";",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"let",
"repo",
";",
"try",
"{",
"repo",
"=",
"yield",
"nodegit",
".",
"Repository",
".",
"open",
"(",
"repositoryPath",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"debug",
"(",
"\"Repository not found.\"",
")",
";",
"repo",
"=",
"yield",
"_createRepository",
"(",
")",
";",
"}",
"debug",
"(",
"\"Repository is ready\"",
")",
";",
"return",
"repo",
";",
"}",
")",
";",
"}"
]
| Initializes the repository connection
@method init
@returns {Promise} Repository connection | [
"Initializes",
"the",
"repository",
"connection"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L34-L50 | train |
moraispgsi/fsm-core | src/indexOld.js | _getFiles | function _getFiles(path){
let files = [];
fs.readdirSync(path).forEach(function(file){
let subpath = path + '/' + file;
if(fs.lstatSync(subpath).isDirectory()){
let filesReturned = _getFiles(subpath);
files = files.concat(filesReturned);
} else {
files.push(path + '/' + file);
}
});
return files;
} | javascript | function _getFiles(path){
let files = [];
fs.readdirSync(path).forEach(function(file){
let subpath = path + '/' + file;
if(fs.lstatSync(subpath).isDirectory()){
let filesReturned = _getFiles(subpath);
files = files.concat(filesReturned);
} else {
files.push(path + '/' + file);
}
});
return files;
} | [
"function",
"_getFiles",
"(",
"path",
")",
"{",
"let",
"files",
"=",
"[",
"]",
";",
"fs",
".",
"readdirSync",
"(",
"path",
")",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"let",
"subpath",
"=",
"path",
"+",
"'/'",
"+",
"file",
";",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"subpath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"let",
"filesReturned",
"=",
"_getFiles",
"(",
"subpath",
")",
";",
"files",
"=",
"files",
".",
"concat",
"(",
"filesReturned",
")",
";",
"}",
"else",
"{",
"files",
".",
"push",
"(",
"path",
"+",
"'/'",
"+",
"file",
")",
";",
"}",
"}",
")",
";",
"return",
"files",
";",
"}"
]
| Recursively gather the paths of the files inside a directory path
@method _getFiles
@param {String} path The directory path to search
@returns {Array} An Array of file paths belonging to the directory path provided | [
"Recursively",
"gather",
"the",
"paths",
"of",
"the",
"files",
"inside",
"a",
"directory",
"path"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L58-L70 | train |
moraispgsi/fsm-core | src/indexOld.js | _commit | function _commit(repo, pathsToStage, message, pathsToUnstage) {
return co(function*(){
repo = repo || (yield nodegit.Repository.open(repositoryPath));
debug("Adding files to the index");
let index = yield repo.refreshIndex(repositoryPath + "/.git/index");
if(pathsToUnstage && pathsToUnstage.length && pathsToUnstage.length > 0) {
for(let file of pathsToUnstage) {
yield index.removeByPath(file);
}
yield index.write();
yield index.writeTree();
}
debug("Creating main files");
let signature = nodegit.Signature.default(repo);
debug("Commiting");
yield repo.createCommitOnHead(pathsToStage, signature, signature, message || "Automatic initialization");
});
} | javascript | function _commit(repo, pathsToStage, message, pathsToUnstage) {
return co(function*(){
repo = repo || (yield nodegit.Repository.open(repositoryPath));
debug("Adding files to the index");
let index = yield repo.refreshIndex(repositoryPath + "/.git/index");
if(pathsToUnstage && pathsToUnstage.length && pathsToUnstage.length > 0) {
for(let file of pathsToUnstage) {
yield index.removeByPath(file);
}
yield index.write();
yield index.writeTree();
}
debug("Creating main files");
let signature = nodegit.Signature.default(repo);
debug("Commiting");
yield repo.createCommitOnHead(pathsToStage, signature, signature, message || "Automatic initialization");
});
} | [
"function",
"_commit",
"(",
"repo",
",",
"pathsToStage",
",",
"message",
",",
"pathsToUnstage",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"repo",
"=",
"repo",
"||",
"(",
"yield",
"nodegit",
".",
"Repository",
".",
"open",
"(",
"repositoryPath",
")",
")",
";",
"debug",
"(",
"\"Adding files to the index\"",
")",
";",
"let",
"index",
"=",
"yield",
"repo",
".",
"refreshIndex",
"(",
"repositoryPath",
"+",
"\"/.git/index\"",
")",
";",
"if",
"(",
"pathsToUnstage",
"&&",
"pathsToUnstage",
".",
"length",
"&&",
"pathsToUnstage",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"let",
"file",
"of",
"pathsToUnstage",
")",
"{",
"yield",
"index",
".",
"removeByPath",
"(",
"file",
")",
";",
"}",
"yield",
"index",
".",
"write",
"(",
")",
";",
"yield",
"index",
".",
"writeTree",
"(",
")",
";",
"}",
"debug",
"(",
"\"Creating main files\"",
")",
";",
"let",
"signature",
"=",
"nodegit",
".",
"Signature",
".",
"default",
"(",
"repo",
")",
";",
"debug",
"(",
"\"Commiting\"",
")",
";",
"yield",
"repo",
".",
"createCommitOnHead",
"(",
"pathsToStage",
",",
"signature",
",",
"signature",
",",
"message",
"||",
"\"Automatic initialization\"",
")",
";",
"}",
")",
";",
"}"
]
| Commit to the repository
@method _commit
@param {Repository} repo The repository connection object
@param {Array} pathsToStage The array of file paths(relative to the repository) to be staged
@param {String} message The message to go along with this commit
@param {Array} pathsToUnstage The array of file paths(relative to the repository) to be un-staged
@returns {Array} An Array of file paths belonging to the directory path provided | [
"Commit",
"to",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L81-L100 | train |
moraispgsi/fsm-core | src/indexOld.js | _createRepository | function _createRepository() {
return co(function*(){
try {
debug("Creating a new one");
let repo = yield nodegit.Repository.init(repositoryPath, 0);
debug("Connection established");
debug("Creating main files");
yield _createManifest(repo);
yield _createConfig(repo);
fs.mkdirSync(machinesDirPath);
yield _commit(repo, ["manifest.json", "config.json"]);
debug("Repository was successfully created");
return repo;
} catch (err) {
debug(err);
debug("Nuking the repository");
yield new Promise(function(resolve, reject) {
rimraf(repositoryPath, function () {
resolve();
});
}).then();
throw new Error(err);
}
});
} | javascript | function _createRepository() {
return co(function*(){
try {
debug("Creating a new one");
let repo = yield nodegit.Repository.init(repositoryPath, 0);
debug("Connection established");
debug("Creating main files");
yield _createManifest(repo);
yield _createConfig(repo);
fs.mkdirSync(machinesDirPath);
yield _commit(repo, ["manifest.json", "config.json"]);
debug("Repository was successfully created");
return repo;
} catch (err) {
debug(err);
debug("Nuking the repository");
yield new Promise(function(resolve, reject) {
rimraf(repositoryPath, function () {
resolve();
});
}).then();
throw new Error(err);
}
});
} | [
"function",
"_createRepository",
"(",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"try",
"{",
"debug",
"(",
"\"Creating a new one\"",
")",
";",
"let",
"repo",
"=",
"yield",
"nodegit",
".",
"Repository",
".",
"init",
"(",
"repositoryPath",
",",
"0",
")",
";",
"debug",
"(",
"\"Connection established\"",
")",
";",
"debug",
"(",
"\"Creating main files\"",
")",
";",
"yield",
"_createManifest",
"(",
"repo",
")",
";",
"yield",
"_createConfig",
"(",
"repo",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"machinesDirPath",
")",
";",
"yield",
"_commit",
"(",
"repo",
",",
"[",
"\"manifest.json\"",
",",
"\"config.json\"",
"]",
")",
";",
"debug",
"(",
"\"Repository was successfully created\"",
")",
";",
"return",
"repo",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"debug",
"(",
"err",
")",
";",
"debug",
"(",
"\"Nuking the repository\"",
")",
";",
"yield",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"rimraf",
"(",
"repositoryPath",
",",
"function",
"(",
")",
"{",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
")",
";",
"throw",
"new",
"Error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Create a new repository
@method _createRepository
@returns {Promise} Repository connection | [
"Create",
"a",
"new",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L107-L131 | train |
moraispgsi/fsm-core | src/indexOld.js | _createManifest | function _createManifest(){
let file = repositoryPath + '/manifest.json';
let manifest = {
machines: {}
};
return new Promise(function(resolve, reject) {
debug("Creating manifest file");
jsonfile.writeFile(file, manifest, function (err) {
if(err){
debug("Failed to create the manifest file");
reject(err);
return;
}
resolve();
});
});
} | javascript | function _createManifest(){
let file = repositoryPath + '/manifest.json';
let manifest = {
machines: {}
};
return new Promise(function(resolve, reject) {
debug("Creating manifest file");
jsonfile.writeFile(file, manifest, function (err) {
if(err){
debug("Failed to create the manifest file");
reject(err);
return;
}
resolve();
});
});
} | [
"function",
"_createManifest",
"(",
")",
"{",
"let",
"file",
"=",
"repositoryPath",
"+",
"'/manifest.json'",
";",
"let",
"manifest",
"=",
"{",
"machines",
":",
"{",
"}",
"}",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"debug",
"(",
"\"Creating manifest file\"",
")",
";",
"jsonfile",
".",
"writeFile",
"(",
"file",
",",
"manifest",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"\"Failed to create the manifest file\"",
")",
";",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Create the manifest file inside the repository
@method _createManifest
@returns {Promise} | [
"Create",
"the",
"manifest",
"file",
"inside",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L138-L155 | train |
moraispgsi/fsm-core | src/indexOld.js | _createConfig | function _createConfig(){
let file = repositoryPath + '/config.json';
let config = {
simulation: false
};
return new Promise(function(resolve, reject) {
jsonfile.writeFile(file, config, function (err) {
if(err){
reject(err);
return;
}
resolve();
});
});
} | javascript | function _createConfig(){
let file = repositoryPath + '/config.json';
let config = {
simulation: false
};
return new Promise(function(resolve, reject) {
jsonfile.writeFile(file, config, function (err) {
if(err){
reject(err);
return;
}
resolve();
});
});
} | [
"function",
"_createConfig",
"(",
")",
"{",
"let",
"file",
"=",
"repositoryPath",
"+",
"'/config.json'",
";",
"let",
"config",
"=",
"{",
"simulation",
":",
"false",
"}",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"jsonfile",
".",
"writeFile",
"(",
"file",
",",
"config",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Create the config file inside the repository
@method _createManifest
@returns {Promise} | [
"Create",
"the",
"config",
"file",
"inside",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L162-L177 | train |
moraispgsi/fsm-core | src/indexOld.js | setManifest | function setManifest(manifest, withCommit, message){
jsonfile.writeFileSync(manifestPath, manifest, {spaces: 2});
if(withCommit) {
return _commit(null, ["manifest.json"],
message || "Changed the manifest file");
}
} | javascript | function setManifest(manifest, withCommit, message){
jsonfile.writeFileSync(manifestPath, manifest, {spaces: 2});
if(withCommit) {
return _commit(null, ["manifest.json"],
message || "Changed the manifest file");
}
} | [
"function",
"setManifest",
"(",
"manifest",
",",
"withCommit",
",",
"message",
")",
"{",
"jsonfile",
".",
"writeFileSync",
"(",
"manifestPath",
",",
"manifest",
",",
"{",
"spaces",
":",
"2",
"}",
")",
";",
"if",
"(",
"withCommit",
")",
"{",
"return",
"_commit",
"(",
"null",
",",
"[",
"\"manifest.json\"",
"]",
",",
"message",
"||",
"\"Changed the manifest file\"",
")",
";",
"}",
"}"
]
| Update the repository manifest.json file using a JavasScript Object
@method setManifest
@param {Object} manifest The manifest Object to save
@param {boolean} withCommit If true commits the changes to the repository
@param {String} message If supplied it is used as the message for the commit
@returns {Promise} If withCommit is true, the function returns a Promise | [
"Update",
"the",
"repository",
"manifest",
".",
"json",
"file",
"using",
"a",
"JavasScript",
"Object"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L205-L211 | train |
moraispgsi/fsm-core | src/indexOld.js | setConfig | function setConfig(config, withCommit, message){
jsonfile.writeFileSync(configPath, config, {spaces: 2});
if(withCommit) {
return _commit(null, ["config.json"],
message || "Changed the config file");
}
} | javascript | function setConfig(config, withCommit, message){
jsonfile.writeFileSync(configPath, config, {spaces: 2});
if(withCommit) {
return _commit(null, ["config.json"],
message || "Changed the config file");
}
} | [
"function",
"setConfig",
"(",
"config",
",",
"withCommit",
",",
"message",
")",
"{",
"jsonfile",
".",
"writeFileSync",
"(",
"configPath",
",",
"config",
",",
"{",
"spaces",
":",
"2",
"}",
")",
";",
"if",
"(",
"withCommit",
")",
"{",
"return",
"_commit",
"(",
"null",
",",
"[",
"\"config.json\"",
"]",
",",
"message",
"||",
"\"Changed the config file\"",
")",
";",
"}",
"}"
]
| Update the repository config.json file using a JavasScript Object
@method setConfig
@param {Object} config The config Object to save
@param {boolean} withCommit If true commits the changes to the repository
@param {String} message If supplied it is used as the message for the commit
@returns {Promise} If withCommit is true, the function returns a Promise | [
"Update",
"the",
"repository",
"config",
".",
"json",
"file",
"using",
"a",
"JavasScript",
"Object"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L230-L236 | train |
moraispgsi/fsm-core | src/indexOld.js | addMachine | function addMachine(name) {
return co(function*(){
debug("Adding a new machine with the name '%s'", name);
let manifest = getManifest();
if(manifest.machines[name]) {
debug("Machine already exists");
throw new Error("Machine already exists");
}
manifest.machines[name] = {
route: "machines/" + name,
"versions": {
"version1": {
"route": "machines/" + name + "/versions/version1",
"instances": {}
}
}
};
let machineDirPath = "machines/" + name;
let machineVersionsDirPath = machineDirPath + "/versions";
let version1DirPath = machineVersionsDirPath + "/version1";
let version1InstancesDirPath = version1DirPath + "/instances";
let modelFile = version1DirPath + '/model.scxml';
let infoFile = version1DirPath + "/info.json";
debug("Creating the directories");
fs.mkdirSync(repositoryPath + "/" + machineDirPath);
fs.mkdirSync(repositoryPath + "/" + machineVersionsDirPath);
fs.mkdirSync(repositoryPath + "/" + version1DirPath);
fs.mkdirSync(repositoryPath + "/" + version1InstancesDirPath);
debug("Creating the base.scxml file");
fs.copySync(__dirname + '/base.scxml', repositoryPath + "/" + modelFile);
debug("Creating the version info.json file");
let infoVersion1 = { "isSealed": false };
jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion1);
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json", modelFile, infoFile], "Added '" + name + "' machine");
debug("A new machine with the name '%s' was successfully added", name);
});
} | javascript | function addMachine(name) {
return co(function*(){
debug("Adding a new machine with the name '%s'", name);
let manifest = getManifest();
if(manifest.machines[name]) {
debug("Machine already exists");
throw new Error("Machine already exists");
}
manifest.machines[name] = {
route: "machines/" + name,
"versions": {
"version1": {
"route": "machines/" + name + "/versions/version1",
"instances": {}
}
}
};
let machineDirPath = "machines/" + name;
let machineVersionsDirPath = machineDirPath + "/versions";
let version1DirPath = machineVersionsDirPath + "/version1";
let version1InstancesDirPath = version1DirPath + "/instances";
let modelFile = version1DirPath + '/model.scxml';
let infoFile = version1DirPath + "/info.json";
debug("Creating the directories");
fs.mkdirSync(repositoryPath + "/" + machineDirPath);
fs.mkdirSync(repositoryPath + "/" + machineVersionsDirPath);
fs.mkdirSync(repositoryPath + "/" + version1DirPath);
fs.mkdirSync(repositoryPath + "/" + version1InstancesDirPath);
debug("Creating the base.scxml file");
fs.copySync(__dirname + '/base.scxml', repositoryPath + "/" + modelFile);
debug("Creating the version info.json file");
let infoVersion1 = { "isSealed": false };
jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion1);
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json", modelFile, infoFile], "Added '" + name + "' machine");
debug("A new machine with the name '%s' was successfully added", name);
});
} | [
"function",
"addMachine",
"(",
"name",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"debug",
"(",
"\"Adding a new machine with the name '%s'\"",
",",
"name",
")",
";",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"if",
"(",
"manifest",
".",
"machines",
"[",
"name",
"]",
")",
"{",
"debug",
"(",
"\"Machine already exists\"",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Machine already exists\"",
")",
";",
"}",
"manifest",
".",
"machines",
"[",
"name",
"]",
"=",
"{",
"route",
":",
"\"machines/\"",
"+",
"name",
",",
"\"versions\"",
":",
"{",
"\"version1\"",
":",
"{",
"\"route\"",
":",
"\"machines/\"",
"+",
"name",
"+",
"\"/versions/version1\"",
",",
"\"instances\"",
":",
"{",
"}",
"}",
"}",
"}",
";",
"let",
"machineDirPath",
"=",
"\"machines/\"",
"+",
"name",
";",
"let",
"machineVersionsDirPath",
"=",
"machineDirPath",
"+",
"\"/versions\"",
";",
"let",
"version1DirPath",
"=",
"machineVersionsDirPath",
"+",
"\"/version1\"",
";",
"let",
"version1InstancesDirPath",
"=",
"version1DirPath",
"+",
"\"/instances\"",
";",
"let",
"modelFile",
"=",
"version1DirPath",
"+",
"'/model.scxml'",
";",
"let",
"infoFile",
"=",
"version1DirPath",
"+",
"\"/info.json\"",
";",
"debug",
"(",
"\"Creating the directories\"",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"machineDirPath",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"machineVersionsDirPath",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"version1DirPath",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"version1InstancesDirPath",
")",
";",
"debug",
"(",
"\"Creating the base.scxml file\"",
")",
";",
"fs",
".",
"copySync",
"(",
"__dirname",
"+",
"'/base.scxml'",
",",
"repositoryPath",
"+",
"\"/\"",
"+",
"modelFile",
")",
";",
"debug",
"(",
"\"Creating the version info.json file\"",
")",
";",
"let",
"infoVersion1",
"=",
"{",
"\"isSealed\"",
":",
"false",
"}",
";",
"jsonfile",
".",
"writeFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"infoFile",
",",
"infoVersion1",
")",
";",
"debug",
"(",
"\"Setting the manifest\"",
")",
";",
"setManifest",
"(",
"manifest",
")",
";",
"yield",
"_commit",
"(",
"null",
",",
"[",
"\"manifest.json\"",
",",
"modelFile",
",",
"infoFile",
"]",
",",
"\"Added '\"",
"+",
"name",
"+",
"\"' machine\"",
")",
";",
"debug",
"(",
"\"A new machine with the name '%s' was successfully added\"",
",",
"name",
")",
";",
"}",
")",
";",
"}"
]
| Add a new machine to the repository
@method addMachine
@param {String} name The name of the new machine
@returns {Promise} | [
"Add",
"a",
"new",
"machine",
"to",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L254-L300 | train |
moraispgsi/fsm-core | src/indexOld.js | removeMachine | function removeMachine(name) {
return co(function*(){
debug("Removing the machine");
let manifest = getManifest();
if(!manifest.machines[name]) {
debug("Machine doesn't exists");
return;
}
let machinePath = machinesDirPath + "/" + name;
let removedFileNames = _getFiles(machinePath).map((f)=>f.substring(repositoryPath.length + 1));
delete manifest.machines[name];
yield new Promise(function(resolve, reject) {
rimraf(machinesDirPath + "/" + name, function () {
resolve();
});
}).then();
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json"], "Removed '" + name + "' machine.", removedFileNames);
return Object.keys(manifest.machines);
});
} | javascript | function removeMachine(name) {
return co(function*(){
debug("Removing the machine");
let manifest = getManifest();
if(!manifest.machines[name]) {
debug("Machine doesn't exists");
return;
}
let machinePath = machinesDirPath + "/" + name;
let removedFileNames = _getFiles(machinePath).map((f)=>f.substring(repositoryPath.length + 1));
delete manifest.machines[name];
yield new Promise(function(resolve, reject) {
rimraf(machinesDirPath + "/" + name, function () {
resolve();
});
}).then();
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json"], "Removed '" + name + "' machine.", removedFileNames);
return Object.keys(manifest.machines);
});
} | [
"function",
"removeMachine",
"(",
"name",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"debug",
"(",
"\"Removing the machine\"",
")",
";",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"if",
"(",
"!",
"manifest",
".",
"machines",
"[",
"name",
"]",
")",
"{",
"debug",
"(",
"\"Machine doesn't exists\"",
")",
";",
"return",
";",
"}",
"let",
"machinePath",
"=",
"machinesDirPath",
"+",
"\"/\"",
"+",
"name",
";",
"let",
"removedFileNames",
"=",
"_getFiles",
"(",
"machinePath",
")",
".",
"map",
"(",
"(",
"f",
")",
"=>",
"f",
".",
"substring",
"(",
"repositoryPath",
".",
"length",
"+",
"1",
")",
")",
";",
"delete",
"manifest",
".",
"machines",
"[",
"name",
"]",
";",
"yield",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"rimraf",
"(",
"machinesDirPath",
"+",
"\"/\"",
"+",
"name",
",",
"function",
"(",
")",
"{",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
")",
";",
"debug",
"(",
"\"Setting the manifest\"",
")",
";",
"setManifest",
"(",
"manifest",
")",
";",
"yield",
"_commit",
"(",
"null",
",",
"[",
"\"manifest.json\"",
"]",
",",
"\"Removed '\"",
"+",
"name",
"+",
"\"' machine.\"",
",",
"removedFileNames",
")",
";",
"return",
"Object",
".",
"keys",
"(",
"manifest",
".",
"machines",
")",
";",
"}",
")",
";",
"}"
]
| Remove a machine from the repository
@method removeMachine
@param {String} name The name of the machine
@returns {Promise} | [
"Remove",
"a",
"machine",
"from",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L308-L336 | train |
moraispgsi/fsm-core | src/indexOld.js | getVersionsKeys | function getVersionsKeys(machineName) {
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
return Object.keys(manifest.machines[machineName].versions);
} | javascript | function getVersionsKeys(machineName) {
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
return Object.keys(manifest.machines[machineName].versions);
} | [
"function",
"getVersionsKeys",
"(",
"machineName",
")",
"{",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"if",
"(",
"!",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Machine does not exists\"",
")",
";",
"}",
"return",
"Object",
".",
"keys",
"(",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"versions",
")",
";",
"}"
]
| Get the keys of all of the versions of machine in the repository
@method getVersionsKeys
@param {String} machineName The name of the machine to get the version's keys
@returns {Array} An array with all the version's keys of the machine | [
"Get",
"the",
"keys",
"of",
"all",
"of",
"the",
"versions",
"of",
"machine",
"in",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L344-L350 | train |
moraispgsi/fsm-core | src/indexOld.js | getVersionRoute | function getVersionRoute(machineName, versionKey) {
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
if (!manifest.machines[machineName].versions[versionKey]) {
throw new Error("Version does not exists");
}
return manifest.machines[machineName].versions[versionKey].route;
} | javascript | function getVersionRoute(machineName, versionKey) {
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
if (!manifest.machines[machineName].versions[versionKey]) {
throw new Error("Version does not exists");
}
return manifest.machines[machineName].versions[versionKey].route;
} | [
"function",
"getVersionRoute",
"(",
"machineName",
",",
"versionKey",
")",
"{",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"if",
"(",
"!",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Machine does not exists\"",
")",
";",
"}",
"if",
"(",
"!",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"versions",
"[",
"versionKey",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Version does not exists\"",
")",
";",
"}",
"return",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"versions",
"[",
"versionKey",
"]",
".",
"route",
";",
"}"
]
| Retrieve the version directory path
@method getVersionRoute
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@returns {String} The route | [
"Retrieve",
"the",
"version",
"directory",
"path"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L359-L371 | train |
moraispgsi/fsm-core | src/indexOld.js | getVersionInfo | function getVersionInfo(machineName, versionKey) {
let route = getVersionInfoRoute(machineName, versionKey);
return jsonfile.readFileSync(repositoryPath + "/" + route);
} | javascript | function getVersionInfo(machineName, versionKey) {
let route = getVersionInfoRoute(machineName, versionKey);
return jsonfile.readFileSync(repositoryPath + "/" + route);
} | [
"function",
"getVersionInfo",
"(",
"machineName",
",",
"versionKey",
")",
"{",
"let",
"route",
"=",
"getVersionInfoRoute",
"(",
"machineName",
",",
"versionKey",
")",
";",
"return",
"jsonfile",
".",
"readFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"route",
")",
";",
"}"
]
| Retrieve the version info.json file as a JavasScript Object
@method getVersionInfo
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@returns {Object} The info Object | [
"Retrieve",
"the",
"version",
"info",
".",
"json",
"file",
"as",
"a",
"JavasScript",
"Object"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L402-L405 | train |
moraispgsi/fsm-core | src/indexOld.js | setVersionInfo | function setVersionInfo(machineName, versionKey, info, withCommit, message) {
let route = getVersionInfoRoute(machineName, versionKey);
let previousInfo = jsonfile.readFileSync(repositoryPath + "/" + route);
if(previousInfo.isSealed) {
throw new Error("Cannot change the version SCXML because the version is sealed.")
}
jsonfile.writeFileSync(repositoryPath + "/" + route, info, {spaces: 2});
if(withCommit) {
return _commit(null, [route],
message || "Changed the info for the " + versionKey + " of the '" + machineName + "' machine" );
}
} | javascript | function setVersionInfo(machineName, versionKey, info, withCommit, message) {
let route = getVersionInfoRoute(machineName, versionKey);
let previousInfo = jsonfile.readFileSync(repositoryPath + "/" + route);
if(previousInfo.isSealed) {
throw new Error("Cannot change the version SCXML because the version is sealed.")
}
jsonfile.writeFileSync(repositoryPath + "/" + route, info, {spaces: 2});
if(withCommit) {
return _commit(null, [route],
message || "Changed the info for the " + versionKey + " of the '" + machineName + "' machine" );
}
} | [
"function",
"setVersionInfo",
"(",
"machineName",
",",
"versionKey",
",",
"info",
",",
"withCommit",
",",
"message",
")",
"{",
"let",
"route",
"=",
"getVersionInfoRoute",
"(",
"machineName",
",",
"versionKey",
")",
";",
"let",
"previousInfo",
"=",
"jsonfile",
".",
"readFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"route",
")",
";",
"if",
"(",
"previousInfo",
".",
"isSealed",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Cannot change the version SCXML because the version is sealed.\"",
")",
"}",
"jsonfile",
".",
"writeFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"route",
",",
"info",
",",
"{",
"spaces",
":",
"2",
"}",
")",
";",
"if",
"(",
"withCommit",
")",
"{",
"return",
"_commit",
"(",
"null",
",",
"[",
"route",
"]",
",",
"message",
"||",
"\"Changed the info for the \"",
"+",
"versionKey",
"+",
"\" of the '\"",
"+",
"machineName",
"+",
"\"' machine\"",
")",
";",
"}",
"}"
]
| Update the version info.json file using a JavasScript Object
@method setVersionInfo
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@param {Object} info The info Object to save
@param {boolean} withCommit If true commits the changes to the repository
@param {String} message If supplied it is used as the message for the commit
@returns {Promise} If withCommit is true, the function returns a Promise | [
"Update",
"the",
"version",
"info",
".",
"json",
"file",
"using",
"a",
"JavasScript",
"Object"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L417-L432 | train |
moraispgsi/fsm-core | src/indexOld.js | addVersion | function addVersion(machineName) {
return co(function*() {
debug("Adding a new version to the '" + machineName + "' machine");
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
let versions = manifest.machines[machineName].versions;
let versionKeys = Object.keys(versions);
let lastVersionKey = versionKeys[versionKeys.length - 1];
let lastVersion = versions[lastVersionKey];
let lastVersionInfoFile = lastVersion.route + "/info.json";
let lastVersionInfo = jsonfile.readFileSync(repositoryPath + "/" + lastVersionInfoFile);
let lastVersionModelFile = lastVersion.route + '/model.scxml';
if(!lastVersionInfo.isSealed) {
throw new Error("The last versions is not sealed yet");
}
let newVersionKey = "version" + (versionKeys.length + 1);
let versionDirPath = manifest.machines[machineName].route + "/versions/" + newVersionKey;
manifest.machines[machineName].versions[newVersionKey] = {
"route": versionDirPath,
"instances": {}
};
let versionInstancesDirPath = versionDirPath + "/instances";
let modelFile = versionDirPath + '/model.scxml';
let infoFile = versionDirPath + "/info.json";
debug("Creating the directories");
fs.mkdirSync(repositoryPath + "/" + versionDirPath);
fs.mkdirSync(repositoryPath + "/" + versionInstancesDirPath);
debug("Copying the previous version's model.scxml");
fs.copySync(repositoryPath + "/" + lastVersionModelFile, repositoryPath + "/" + modelFile);
debug("Creating the version info.json file");
let infoVersion = { "isSealed": false };
jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion);
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json", modelFile, infoFile],
"Created the "+newVersionKey+" for the '" + machineName + "' machine");
return newVersionKey;
});
} | javascript | function addVersion(machineName) {
return co(function*() {
debug("Adding a new version to the '" + machineName + "' machine");
let manifest = getManifest();
if (!manifest.machines[machineName]) {
throw new Error("Machine does not exists");
}
let versions = manifest.machines[machineName].versions;
let versionKeys = Object.keys(versions);
let lastVersionKey = versionKeys[versionKeys.length - 1];
let lastVersion = versions[lastVersionKey];
let lastVersionInfoFile = lastVersion.route + "/info.json";
let lastVersionInfo = jsonfile.readFileSync(repositoryPath + "/" + lastVersionInfoFile);
let lastVersionModelFile = lastVersion.route + '/model.scxml';
if(!lastVersionInfo.isSealed) {
throw new Error("The last versions is not sealed yet");
}
let newVersionKey = "version" + (versionKeys.length + 1);
let versionDirPath = manifest.machines[machineName].route + "/versions/" + newVersionKey;
manifest.machines[machineName].versions[newVersionKey] = {
"route": versionDirPath,
"instances": {}
};
let versionInstancesDirPath = versionDirPath + "/instances";
let modelFile = versionDirPath + '/model.scxml';
let infoFile = versionDirPath + "/info.json";
debug("Creating the directories");
fs.mkdirSync(repositoryPath + "/" + versionDirPath);
fs.mkdirSync(repositoryPath + "/" + versionInstancesDirPath);
debug("Copying the previous version's model.scxml");
fs.copySync(repositoryPath + "/" + lastVersionModelFile, repositoryPath + "/" + modelFile);
debug("Creating the version info.json file");
let infoVersion = { "isSealed": false };
jsonfile.writeFileSync(repositoryPath + "/" + infoFile, infoVersion);
debug("Setting the manifest");
setManifest(manifest);
yield _commit(null, ["manifest.json", modelFile, infoFile],
"Created the "+newVersionKey+" for the '" + machineName + "' machine");
return newVersionKey;
});
} | [
"function",
"addVersion",
"(",
"machineName",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"debug",
"(",
"\"Adding a new version to the '\"",
"+",
"machineName",
"+",
"\"' machine\"",
")",
";",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"if",
"(",
"!",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Machine does not exists\"",
")",
";",
"}",
"let",
"versions",
"=",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"versions",
";",
"let",
"versionKeys",
"=",
"Object",
".",
"keys",
"(",
"versions",
")",
";",
"let",
"lastVersionKey",
"=",
"versionKeys",
"[",
"versionKeys",
".",
"length",
"-",
"1",
"]",
";",
"let",
"lastVersion",
"=",
"versions",
"[",
"lastVersionKey",
"]",
";",
"let",
"lastVersionInfoFile",
"=",
"lastVersion",
".",
"route",
"+",
"\"/info.json\"",
";",
"let",
"lastVersionInfo",
"=",
"jsonfile",
".",
"readFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"lastVersionInfoFile",
")",
";",
"let",
"lastVersionModelFile",
"=",
"lastVersion",
".",
"route",
"+",
"'/model.scxml'",
";",
"if",
"(",
"!",
"lastVersionInfo",
".",
"isSealed",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The last versions is not sealed yet\"",
")",
";",
"}",
"let",
"newVersionKey",
"=",
"\"version\"",
"+",
"(",
"versionKeys",
".",
"length",
"+",
"1",
")",
";",
"let",
"versionDirPath",
"=",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"route",
"+",
"\"/versions/\"",
"+",
"newVersionKey",
";",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
".",
"versions",
"[",
"newVersionKey",
"]",
"=",
"{",
"\"route\"",
":",
"versionDirPath",
",",
"\"instances\"",
":",
"{",
"}",
"}",
";",
"let",
"versionInstancesDirPath",
"=",
"versionDirPath",
"+",
"\"/instances\"",
";",
"let",
"modelFile",
"=",
"versionDirPath",
"+",
"'/model.scxml'",
";",
"let",
"infoFile",
"=",
"versionDirPath",
"+",
"\"/info.json\"",
";",
"debug",
"(",
"\"Creating the directories\"",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"versionDirPath",
")",
";",
"fs",
".",
"mkdirSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"versionInstancesDirPath",
")",
";",
"debug",
"(",
"\"Copying the previous version's model.scxml\"",
")",
";",
"fs",
".",
"copySync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"lastVersionModelFile",
",",
"repositoryPath",
"+",
"\"/\"",
"+",
"modelFile",
")",
";",
"debug",
"(",
"\"Creating the version info.json file\"",
")",
";",
"let",
"infoVersion",
"=",
"{",
"\"isSealed\"",
":",
"false",
"}",
";",
"jsonfile",
".",
"writeFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"infoFile",
",",
"infoVersion",
")",
";",
"debug",
"(",
"\"Setting the manifest\"",
")",
";",
"setManifest",
"(",
"manifest",
")",
";",
"yield",
"_commit",
"(",
"null",
",",
"[",
"\"manifest.json\"",
",",
"modelFile",
",",
"infoFile",
"]",
",",
"\"Created the \"",
"+",
"newVersionKey",
"+",
"\" for the '\"",
"+",
"machineName",
"+",
"\"' machine\"",
")",
";",
"return",
"newVersionKey",
";",
"}",
")",
";",
"}"
]
| Add a new version to a machine
@method addVersion
@param {String} machineName The name of the machine
@returns {Promise} The version key | [
"Add",
"a",
"new",
"version",
"to",
"a",
"machine"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L440-L492 | train |
moraispgsi/fsm-core | src/indexOld.js | sealVersion | function sealVersion(machineName, versionKey) {
return co(function*(){
debug("Attempting to seal the version '%s' of the machine '%s'", versionKey, machineName);
let info = yield getVersionInfo(machineName, versionKey);
if(info.isSealed) {
throw new Error("Version it already sealed");
}
debug("Getting manifest");
let manifest = getManifest();
let model = getVersionSCXML(machineName, versionKey);
let isValid = isSCXMLValid(model);
if(!isValid) {
throw new Error("The model is not valid.");
}
info.isSealed = true;
setVersionInfo(machineName, versionKey, info);
debug("The version '%s' of the machine '%s' was sealed successfully", versionKey, machineName);
});
} | javascript | function sealVersion(machineName, versionKey) {
return co(function*(){
debug("Attempting to seal the version '%s' of the machine '%s'", versionKey, machineName);
let info = yield getVersionInfo(machineName, versionKey);
if(info.isSealed) {
throw new Error("Version it already sealed");
}
debug("Getting manifest");
let manifest = getManifest();
let model = getVersionSCXML(machineName, versionKey);
let isValid = isSCXMLValid(model);
if(!isValid) {
throw new Error("The model is not valid.");
}
info.isSealed = true;
setVersionInfo(machineName, versionKey, info);
debug("The version '%s' of the machine '%s' was sealed successfully", versionKey, machineName);
});
} | [
"function",
"sealVersion",
"(",
"machineName",
",",
"versionKey",
")",
"{",
"return",
"co",
"(",
"function",
"*",
"(",
")",
"{",
"debug",
"(",
"\"Attempting to seal the version '%s' of the machine '%s'\"",
",",
"versionKey",
",",
"machineName",
")",
";",
"let",
"info",
"=",
"yield",
"getVersionInfo",
"(",
"machineName",
",",
"versionKey",
")",
";",
"if",
"(",
"info",
".",
"isSealed",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Version it already sealed\"",
")",
";",
"}",
"debug",
"(",
"\"Getting manifest\"",
")",
";",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"let",
"model",
"=",
"getVersionSCXML",
"(",
"machineName",
",",
"versionKey",
")",
";",
"let",
"isValid",
"=",
"isSCXMLValid",
"(",
"model",
")",
";",
"if",
"(",
"!",
"isValid",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The model is not valid.\"",
")",
";",
"}",
"info",
".",
"isSealed",
"=",
"true",
";",
"setVersionInfo",
"(",
"machineName",
",",
"versionKey",
",",
"info",
")",
";",
"debug",
"(",
"\"The version '%s' of the machine '%s' was sealed successfully\"",
",",
"versionKey",
",",
"machineName",
")",
";",
"}",
")",
";",
"}"
]
| Seal a version of a machine
@method addMachine
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@returns {Promise} | [
"Seal",
"a",
"version",
"of",
"a",
"machine"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L501-L523 | train |
moraispgsi/fsm-core | src/indexOld.js | getVersionSCXML | function getVersionSCXML(machineName, versionKey) {
let route = getVersionModelRoute(machineName, versionKey);
return fs.readFileSync(repositoryPath + "/" + route).toString('utf8');
} | javascript | function getVersionSCXML(machineName, versionKey) {
let route = getVersionModelRoute(machineName, versionKey);
return fs.readFileSync(repositoryPath + "/" + route).toString('utf8');
} | [
"function",
"getVersionSCXML",
"(",
"machineName",
",",
"versionKey",
")",
"{",
"let",
"route",
"=",
"getVersionModelRoute",
"(",
"machineName",
",",
"versionKey",
")",
";",
"return",
"fs",
".",
"readFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"route",
")",
".",
"toString",
"(",
"'utf8'",
")",
";",
"}"
]
| Retrieve the version model.scxml file as a String
@method getVersionSCXML
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@returns {String} The model | [
"Retrieve",
"the",
"version",
"model",
".",
"scxml",
"file",
"as",
"a",
"String"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L533-L536 | train |
moraispgsi/fsm-core | src/indexOld.js | setVersionSCXML | function setVersionSCXML(machineName, versionKey, model, withCommit, message) {
let route = getVersionInfoRoute(machineName, versionKey);
let previousInfo = jsonfile.readFileSync(repositoryPath + "/" + route);
if(previousInfo.isSealed) {
throw new Error("Cannot change the version SCXML because the version is sealed.")
}
let modelRoute = getVersionModelRoute(machineName, versionKey);
fs.writeFileSync(repositoryPath + "/" + modelRoute, model);
if(withCommit) {
return _commit(null, [modelRoute],
"Changed the model.scxml for the " + versionKey + " of the '" + machineName + "' machine");
}
} | javascript | function setVersionSCXML(machineName, versionKey, model, withCommit, message) {
let route = getVersionInfoRoute(machineName, versionKey);
let previousInfo = jsonfile.readFileSync(repositoryPath + "/" + route);
if(previousInfo.isSealed) {
throw new Error("Cannot change the version SCXML because the version is sealed.")
}
let modelRoute = getVersionModelRoute(machineName, versionKey);
fs.writeFileSync(repositoryPath + "/" + modelRoute, model);
if(withCommit) {
return _commit(null, [modelRoute],
"Changed the model.scxml for the " + versionKey + " of the '" + machineName + "' machine");
}
} | [
"function",
"setVersionSCXML",
"(",
"machineName",
",",
"versionKey",
",",
"model",
",",
"withCommit",
",",
"message",
")",
"{",
"let",
"route",
"=",
"getVersionInfoRoute",
"(",
"machineName",
",",
"versionKey",
")",
";",
"let",
"previousInfo",
"=",
"jsonfile",
".",
"readFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"route",
")",
";",
"if",
"(",
"previousInfo",
".",
"isSealed",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Cannot change the version SCXML because the version is sealed.\"",
")",
"}",
"let",
"modelRoute",
"=",
"getVersionModelRoute",
"(",
"machineName",
",",
"versionKey",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"repositoryPath",
"+",
"\"/\"",
"+",
"modelRoute",
",",
"model",
")",
";",
"if",
"(",
"withCommit",
")",
"{",
"return",
"_commit",
"(",
"null",
",",
"[",
"modelRoute",
"]",
",",
"\"Changed the model.scxml for the \"",
"+",
"versionKey",
"+",
"\" of the '\"",
"+",
"machineName",
"+",
"\"' machine\"",
")",
";",
"}",
"}"
]
| Update the version model.scxml file using a String
@method setVersionSCXML
@param {String} model The model
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@param {boolean} withCommit If true commits the changes to the repository
@param {String} message If supplied it is used as the message for the commit
@returns {Promise} If withCommit is true, the function returns a Promise | [
"Update",
"the",
"version",
"model",
".",
"scxml",
"file",
"using",
"a",
"String"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L548-L562 | train |
moraispgsi/fsm-core | src/indexOld.js | isSCXMLValid | function isSCXMLValid(model){
return new Promise(function(resolve, reject) {
if(model === "") {
reject("Model is empty");
return;
}
validator.validateXML(model, __dirname + '/xmlSchemas/scxml.xsd', function(err, result) {
if (err) {
reject(err);
return;
}
resolve(result.valid);
})
});
} | javascript | function isSCXMLValid(model){
return new Promise(function(resolve, reject) {
if(model === "") {
reject("Model is empty");
return;
}
validator.validateXML(model, __dirname + '/xmlSchemas/scxml.xsd', function(err, result) {
if (err) {
reject(err);
return;
}
resolve(result.valid);
})
});
} | [
"function",
"isSCXMLValid",
"(",
"model",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"if",
"(",
"model",
"===",
"\"\"",
")",
"{",
"reject",
"(",
"\"Model is empty\"",
")",
";",
"return",
";",
"}",
"validator",
".",
"validateXML",
"(",
"model",
",",
"__dirname",
"+",
"'/xmlSchemas/scxml.xsd'",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"resolve",
"(",
"result",
".",
"valid",
")",
";",
"}",
")",
"}",
")",
";",
"}"
]
| Validates SCXML markup as a string
@method isSCXMLValid
@param {String} model A string with the SCXML document to validate
@returns {Promise} True if the SCXML is valid false otherwise | [
"Validates",
"SCXML",
"markup",
"as",
"a",
"string"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L570-L585 | train |
moraispgsi/fsm-core | src/indexOld.js | getInstancesKeys | function getInstancesKeys(machineName, versionKey){
let manifest = getManifest();
let machine = manifest.machines[machineName];
if (!machine) {
throw new Error("Machine does not exists");
}
let version = machine.versions[versionKey];
if (!version) {
throw new Error("Version does not exists");
}
return Object.keys(version.instances);
} | javascript | function getInstancesKeys(machineName, versionKey){
let manifest = getManifest();
let machine = manifest.machines[machineName];
if (!machine) {
throw new Error("Machine does not exists");
}
let version = machine.versions[versionKey];
if (!version) {
throw new Error("Version does not exists");
}
return Object.keys(version.instances);
} | [
"function",
"getInstancesKeys",
"(",
"machineName",
",",
"versionKey",
")",
"{",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"let",
"machine",
"=",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
";",
"if",
"(",
"!",
"machine",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Machine does not exists\"",
")",
";",
"}",
"let",
"version",
"=",
"machine",
".",
"versions",
"[",
"versionKey",
"]",
";",
"if",
"(",
"!",
"version",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Version does not exists\"",
")",
";",
"}",
"return",
"Object",
".",
"keys",
"(",
"version",
".",
"instances",
")",
";",
"}"
]
| Gets the keys of all of the instances of a version of the machine in the repository
@method getInstancesKeys
@param {String} machineName The name of the machine to get the instances's keys
@param {String} versionKey The key of the version to get the instances's keys
@returns {Array} An array with all the instance's keys of the the version | [
"Gets",
"the",
"keys",
"of",
"all",
"of",
"the",
"instances",
"of",
"a",
"version",
"of",
"the",
"machine",
"in",
"the",
"repository"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L594-L609 | train |
moraispgsi/fsm-core | src/indexOld.js | getInstanceRoute | function getInstanceRoute(machineName, versionKey, instanceKey){
let manifest = getManifest();
let machine = manifest.machines[machineName];
if (!machine) {
throw new Error("Machine does not exists");
}
let version = machine.versions[versionKey];
if (!version) {
throw new Error("Version does not exists");
}
let instance = version.instances[instanceKey];
if (!instance) {
throw new Error("Instance does not exists");
}
return instance.route;
} | javascript | function getInstanceRoute(machineName, versionKey, instanceKey){
let manifest = getManifest();
let machine = manifest.machines[machineName];
if (!machine) {
throw new Error("Machine does not exists");
}
let version = machine.versions[versionKey];
if (!version) {
throw new Error("Version does not exists");
}
let instance = version.instances[instanceKey];
if (!instance) {
throw new Error("Instance does not exists");
}
return instance.route;
} | [
"function",
"getInstanceRoute",
"(",
"machineName",
",",
"versionKey",
",",
"instanceKey",
")",
"{",
"let",
"manifest",
"=",
"getManifest",
"(",
")",
";",
"let",
"machine",
"=",
"manifest",
".",
"machines",
"[",
"machineName",
"]",
";",
"if",
"(",
"!",
"machine",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Machine does not exists\"",
")",
";",
"}",
"let",
"version",
"=",
"machine",
".",
"versions",
"[",
"versionKey",
"]",
";",
"if",
"(",
"!",
"version",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Version does not exists\"",
")",
";",
"}",
"let",
"instance",
"=",
"version",
".",
"instances",
"[",
"instanceKey",
"]",
";",
"if",
"(",
"!",
"instance",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Instance does not exists\"",
")",
";",
"}",
"return",
"instance",
".",
"route",
";",
"}"
]
| Retrieve the instance's directory path
@method getInstanceRoute
@param {String} machineName The name of the machine
@param {String} versionKey The key of the version
@param {String} instanceKey The key of the instance
@returns {String} The route | [
"Retrieve",
"the",
"instance",
"s",
"directory",
"path"
]
| c07e7c1509b823d5c438a26b29fbf8f40e1e8be7 | https://github.com/moraispgsi/fsm-core/blob/c07e7c1509b823d5c438a26b29fbf8f40e1e8be7/src/indexOld.js#L619-L639 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.