id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
54,100 | megahertz/node-comments-parser | index.js | applyJsDocTags | function applyJsDocTags(comment, removeTagLine) {
removeTagLine = (undefined !== removeTagLine) ? removeTagLine : true;
var lines = [];
comment.tags = [];
for (var i = 0; i < comment.lines.length; i++) {
var line = comment.lines[i];
if ('@' === line.charAt(0)) {
var spacePos = line.indexOf(' ');
if (-1 === spacePos) {
spacePos = line.length;
}
var tag = line.substr(1, spacePos).trim();
var value = line.substr(spacePos).trim();
comment.tags.push({ name: tag, value: value || true });
} else {
lines.push(line);
}
}
if (removeTagLine) {
comment.lines = lines;
}
} | javascript | function applyJsDocTags(comment, removeTagLine) {
removeTagLine = (undefined !== removeTagLine) ? removeTagLine : true;
var lines = [];
comment.tags = [];
for (var i = 0; i < comment.lines.length; i++) {
var line = comment.lines[i];
if ('@' === line.charAt(0)) {
var spacePos = line.indexOf(' ');
if (-1 === spacePos) {
spacePos = line.length;
}
var tag = line.substr(1, spacePos).trim();
var value = line.substr(spacePos).trim();
comment.tags.push({ name: tag, value: value || true });
} else {
lines.push(line);
}
}
if (removeTagLine) {
comment.lines = lines;
}
} | [
"function",
"applyJsDocTags",
"(",
"comment",
",",
"removeTagLine",
")",
"{",
"removeTagLine",
"=",
"(",
"undefined",
"!==",
"removeTagLine",
")",
"?",
"removeTagLine",
":",
"true",
";",
"var",
"lines",
"=",
"[",
"]",
";",
"comment",
".",
"tags",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"comment",
".",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"line",
"=",
"comment",
".",
"lines",
"[",
"i",
"]",
";",
"if",
"(",
"'@'",
"===",
"line",
".",
"charAt",
"(",
"0",
")",
")",
"{",
"var",
"spacePos",
"=",
"line",
".",
"indexOf",
"(",
"' '",
")",
";",
"if",
"(",
"-",
"1",
"===",
"spacePos",
")",
"{",
"spacePos",
"=",
"line",
".",
"length",
";",
"}",
"var",
"tag",
"=",
"line",
".",
"substr",
"(",
"1",
",",
"spacePos",
")",
".",
"trim",
"(",
")",
";",
"var",
"value",
"=",
"line",
".",
"substr",
"(",
"spacePos",
")",
".",
"trim",
"(",
")",
";",
"comment",
".",
"tags",
".",
"push",
"(",
"{",
"name",
":",
"tag",
",",
"value",
":",
"value",
"||",
"true",
"}",
")",
";",
"}",
"else",
"{",
"lines",
".",
"push",
"(",
"line",
")",
";",
"}",
"}",
"if",
"(",
"removeTagLine",
")",
"{",
"comment",
".",
"lines",
"=",
"lines",
";",
"}",
"}"
] | Find tags in comment, remove this lines and apply as property
@param {Object} comment
@param {boolean} [removeTagLine=true] | [
"Find",
"tags",
"in",
"comment",
"remove",
"this",
"lines",
"and",
"apply",
"as",
"property"
] | d849f23bf4210e999a2aa56ebad31588b2199cb5 | https://github.com/megahertz/node-comments-parser/blob/d849f23bf4210e999a2aa56ebad31588b2199cb5/index.js#L106-L130 |
54,101 | megahertz/node-comments-parser | index.js | defaults | function defaults(object, options) {
object = object || {};
for (var i in options) {
if (undefined === object[i] && options.hasOwnProperty(i)) {
object[i] = options[i];
}
}
return object;
} | javascript | function defaults(object, options) {
object = object || {};
for (var i in options) {
if (undefined === object[i] && options.hasOwnProperty(i)) {
object[i] = options[i];
}
}
return object;
} | [
"function",
"defaults",
"(",
"object",
",",
"options",
")",
"{",
"object",
"=",
"object",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"options",
")",
"{",
"if",
"(",
"undefined",
"===",
"object",
"[",
"i",
"]",
"&&",
"options",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"object",
"[",
"i",
"]",
"=",
"options",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"object",
";",
"}"
] | Extend object if a property is not defined yet
@param {Object} object
@param {Object} options
@returns {Object} | [
"Extend",
"object",
"if",
"a",
"property",
"is",
"not",
"defined",
"yet"
] | d849f23bf4210e999a2aa56ebad31588b2199cb5 | https://github.com/megahertz/node-comments-parser/blob/d849f23bf4210e999a2aa56ebad31588b2199cb5/index.js#L161-L169 |
54,102 | jakwings/meta-matter | index.js | matter | function matter(str, opts) {
str = formatString(str);
opts = formatOptions(opts);
var result = {src: str, data: null, body: str};
if (!str) {
return result;
}
var strict = !opts.loose;
var header = opts.delims[0];
var footer = opts.delims[1];
var dataStart, dataEnd;
// Front matter must start from the first byte.
if (str.substr(0, header.length) !== header ||
// Whether the delimiter is followed by a strange character.
(!opts.loose && header.length < str.length &&
str[header.length] !== '\n' &&
str[header.length] === header[header.length-1]) ||
// Metadata and delimiters should be separated with linefeeds.
(dataStart = str.indexOf('\n', header.length)) < 0 ||
(dataEnd = str.indexOf('\n' + footer, dataStart)) < 0) {
return result;
}
var bodyStart = dataEnd + 1 + footer.length;
// Whether the delimiter is followed by strange characters.
if (strict && bodyStart < str.length) {
if (str[bodyStart] !== '\n' && str[bodyStart] === footer[footer.length-1]) {
return result;
}
while (bodyStart < str.length && str[bodyStart] !== '\n') {
if (/^[^\s]$/.test(str[bodyStart])) {
return result;
}
bodyStart++;
}
} // else: Tolerate the case that a linefeed is missing: <end-delimiter><body>
if (str[bodyStart] === '\r') { bodyStart++; }
if (str[bodyStart] === '\n') { bodyStart++; }
var data;
if (dataStart < dataEnd &&
(data = str.substr(dataStart, dataEnd - dataStart).trim())) {
var lang = str.substr(header.length, dataStart - header.length)
.trim().toLowerCase() || opts.lang;
var parse;
if (typeof opts.parsers === 'function') {
parse = opts.parsers;
} else if (opts.parsers != null && opts.parsers[lang]) {
parse = opts.parsers[lang];
} else {
parse = matter.parsers[lang];
}
if (typeof parse === 'function') {
result.data = parse(data, {loose: opts.loose});
} else {
throw new Error(message('No parser found for the language: ' + lang));
}
}
result.body = result.body.substr(bodyStart);
return result;
} | javascript | function matter(str, opts) {
str = formatString(str);
opts = formatOptions(opts);
var result = {src: str, data: null, body: str};
if (!str) {
return result;
}
var strict = !opts.loose;
var header = opts.delims[0];
var footer = opts.delims[1];
var dataStart, dataEnd;
// Front matter must start from the first byte.
if (str.substr(0, header.length) !== header ||
// Whether the delimiter is followed by a strange character.
(!opts.loose && header.length < str.length &&
str[header.length] !== '\n' &&
str[header.length] === header[header.length-1]) ||
// Metadata and delimiters should be separated with linefeeds.
(dataStart = str.indexOf('\n', header.length)) < 0 ||
(dataEnd = str.indexOf('\n' + footer, dataStart)) < 0) {
return result;
}
var bodyStart = dataEnd + 1 + footer.length;
// Whether the delimiter is followed by strange characters.
if (strict && bodyStart < str.length) {
if (str[bodyStart] !== '\n' && str[bodyStart] === footer[footer.length-1]) {
return result;
}
while (bodyStart < str.length && str[bodyStart] !== '\n') {
if (/^[^\s]$/.test(str[bodyStart])) {
return result;
}
bodyStart++;
}
} // else: Tolerate the case that a linefeed is missing: <end-delimiter><body>
if (str[bodyStart] === '\r') { bodyStart++; }
if (str[bodyStart] === '\n') { bodyStart++; }
var data;
if (dataStart < dataEnd &&
(data = str.substr(dataStart, dataEnd - dataStart).trim())) {
var lang = str.substr(header.length, dataStart - header.length)
.trim().toLowerCase() || opts.lang;
var parse;
if (typeof opts.parsers === 'function') {
parse = opts.parsers;
} else if (opts.parsers != null && opts.parsers[lang]) {
parse = opts.parsers[lang];
} else {
parse = matter.parsers[lang];
}
if (typeof parse === 'function') {
result.data = parse(data, {loose: opts.loose});
} else {
throw new Error(message('No parser found for the language: ' + lang));
}
}
result.body = result.body.substr(bodyStart);
return result;
} | [
"function",
"matter",
"(",
"str",
",",
"opts",
")",
"{",
"str",
"=",
"formatString",
"(",
"str",
")",
";",
"opts",
"=",
"formatOptions",
"(",
"opts",
")",
";",
"var",
"result",
"=",
"{",
"src",
":",
"str",
",",
"data",
":",
"null",
",",
"body",
":",
"str",
"}",
";",
"if",
"(",
"!",
"str",
")",
"{",
"return",
"result",
";",
"}",
"var",
"strict",
"=",
"!",
"opts",
".",
"loose",
";",
"var",
"header",
"=",
"opts",
".",
"delims",
"[",
"0",
"]",
";",
"var",
"footer",
"=",
"opts",
".",
"delims",
"[",
"1",
"]",
";",
"var",
"dataStart",
",",
"dataEnd",
";",
"// Front matter must start from the first byte.",
"if",
"(",
"str",
".",
"substr",
"(",
"0",
",",
"header",
".",
"length",
")",
"!==",
"header",
"||",
"// Whether the delimiter is followed by a strange character.",
"(",
"!",
"opts",
".",
"loose",
"&&",
"header",
".",
"length",
"<",
"str",
".",
"length",
"&&",
"str",
"[",
"header",
".",
"length",
"]",
"!==",
"'\\n'",
"&&",
"str",
"[",
"header",
".",
"length",
"]",
"===",
"header",
"[",
"header",
".",
"length",
"-",
"1",
"]",
")",
"||",
"// Metadata and delimiters should be separated with linefeeds.",
"(",
"dataStart",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
",",
"header",
".",
"length",
")",
")",
"<",
"0",
"||",
"(",
"dataEnd",
"=",
"str",
".",
"indexOf",
"(",
"'\\n'",
"+",
"footer",
",",
"dataStart",
")",
")",
"<",
"0",
")",
"{",
"return",
"result",
";",
"}",
"var",
"bodyStart",
"=",
"dataEnd",
"+",
"1",
"+",
"footer",
".",
"length",
";",
"// Whether the delimiter is followed by strange characters.",
"if",
"(",
"strict",
"&&",
"bodyStart",
"<",
"str",
".",
"length",
")",
"{",
"if",
"(",
"str",
"[",
"bodyStart",
"]",
"!==",
"'\\n'",
"&&",
"str",
"[",
"bodyStart",
"]",
"===",
"footer",
"[",
"footer",
".",
"length",
"-",
"1",
"]",
")",
"{",
"return",
"result",
";",
"}",
"while",
"(",
"bodyStart",
"<",
"str",
".",
"length",
"&&",
"str",
"[",
"bodyStart",
"]",
"!==",
"'\\n'",
")",
"{",
"if",
"(",
"/",
"^[^\\s]$",
"/",
".",
"test",
"(",
"str",
"[",
"bodyStart",
"]",
")",
")",
"{",
"return",
"result",
";",
"}",
"bodyStart",
"++",
";",
"}",
"}",
"// else: Tolerate the case that a linefeed is missing: <end-delimiter><body>",
"if",
"(",
"str",
"[",
"bodyStart",
"]",
"===",
"'\\r'",
")",
"{",
"bodyStart",
"++",
";",
"}",
"if",
"(",
"str",
"[",
"bodyStart",
"]",
"===",
"'\\n'",
")",
"{",
"bodyStart",
"++",
";",
"}",
"var",
"data",
";",
"if",
"(",
"dataStart",
"<",
"dataEnd",
"&&",
"(",
"data",
"=",
"str",
".",
"substr",
"(",
"dataStart",
",",
"dataEnd",
"-",
"dataStart",
")",
".",
"trim",
"(",
")",
")",
")",
"{",
"var",
"lang",
"=",
"str",
".",
"substr",
"(",
"header",
".",
"length",
",",
"dataStart",
"-",
"header",
".",
"length",
")",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
"||",
"opts",
".",
"lang",
";",
"var",
"parse",
";",
"if",
"(",
"typeof",
"opts",
".",
"parsers",
"===",
"'function'",
")",
"{",
"parse",
"=",
"opts",
".",
"parsers",
";",
"}",
"else",
"if",
"(",
"opts",
".",
"parsers",
"!=",
"null",
"&&",
"opts",
".",
"parsers",
"[",
"lang",
"]",
")",
"{",
"parse",
"=",
"opts",
".",
"parsers",
"[",
"lang",
"]",
";",
"}",
"else",
"{",
"parse",
"=",
"matter",
".",
"parsers",
"[",
"lang",
"]",
";",
"}",
"if",
"(",
"typeof",
"parse",
"===",
"'function'",
")",
"{",
"result",
".",
"data",
"=",
"parse",
"(",
"data",
",",
"{",
"loose",
":",
"opts",
".",
"loose",
"}",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"message",
"(",
"'No parser found for the language: '",
"+",
"lang",
")",
")",
";",
"}",
"}",
"result",
".",
"body",
"=",
"result",
".",
"body",
".",
"substr",
"(",
"bodyStart",
")",
";",
"return",
"result",
";",
"}"
] | Parse the input string with options.
@param {String} str The string to parse.
@param {Object?} opts
@param {Boolean?} opts.loose Whether to tolerate ambiguous delimiters. Default: false
@param {String?} opts.lang The name of the parser to use if opts.parsers is not a function. Default: 'yaml'
@param {(String|Array)?} opts.delims Custom delimiter(s). Default: '---' or ['---', '---']
@param {(Function|Object.<String, Function>)?} opts.parsers Custom parser(s). Default: {'yaml':yaml,'toml':toml}
@return {Object} result
@param {String} result.src The original input string.
@param {String} result.body The input string without front matter.
@param {Mixed} result.data The data returned from the parsers. Default: null | [
"Parse",
"the",
"input",
"string",
"with",
"options",
"."
] | c8e3f4daffb09485bd8a18e6337d17fee0a20460 | https://github.com/jakwings/meta-matter/blob/c8e3f4daffb09485bd8a18e6337d17fee0a20460/index.js#L18-L79 |
54,103 | yeptlabs/wns | src/core/base/wnModule.js | function (classesSource)
{
this.e.log&&this.e.log('Importing core classes...','system');
var classesSource = classesSource||global.wns.coreClasses;
var classBuilder = new process.wns.wnBuild(classesSource,this);
this.setComponent('classBuilder',classBuilder);
classBuilder.build();
return this;
} | javascript | function (classesSource)
{
this.e.log&&this.e.log('Importing core classes...','system');
var classesSource = classesSource||global.wns.coreClasses;
var classBuilder = new process.wns.wnBuild(classesSource,this);
this.setComponent('classBuilder',classBuilder);
classBuilder.build();
return this;
} | [
"function",
"(",
"classesSource",
")",
"{",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'Importing core classes...'",
",",
"'system'",
")",
";",
"var",
"classesSource",
"=",
"classesSource",
"||",
"global",
".",
"wns",
".",
"coreClasses",
";",
"var",
"classBuilder",
"=",
"new",
"process",
".",
"wns",
".",
"wnBuild",
"(",
"classesSource",
",",
"this",
")",
";",
"this",
".",
"setComponent",
"(",
"'classBuilder'",
",",
"classBuilder",
")",
";",
"classBuilder",
".",
"build",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Compile module's classes.
It gets classes source you give or from the core classes.
@param $classesSource (optional)
@return this | [
"Compile",
"module",
"s",
"classes",
".",
"It",
"gets",
"classes",
"source",
"you",
"give",
"or",
"from",
"the",
"core",
"classes",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L142-L152 |
|
54,104 | yeptlabs/wns | src/core/base/wnModule.js | function ()
{
var nmPath = this.modulePath + 'node_modules/';
var pkgJson;
var pkgName;
var pkgInfo;
var packageList = {};
var validScript = /[\w|\W]+\.[js|coffee]+$/;
if (fs.existsSync(nmPath))
{
this.e.log&&this.e.log('Importing packages...','system');
var packages = fs.readdirSync(nmPath);
for (p in packages)
{
try {
if (packages[p].indexOf('wns')!==-1 &&
(packages[p].indexOf('pkg') !== -1 || packages[p].indexOf('package') !== -1))
{
pkgName = packages[p];
pkgDir = nmPath + pkgName;
pkgJson = pkgDir + '/package.json';
if (fs.existsSync(pkgJson))
{
pkgInfo = JSON.parse(fs.readFileSync(pkgJson));
pkgInfo.require = pkgInfo.require||{};
Object.defineProperty(pkgInfo,'classes',{ value: {}, enumerable: false })
var files = fs.readdirSync(pkgDir);
for (f in files)
{
var fileName = files[f].split('/').pop();
if (validScript.test(fileName))
{
var className = fileName.split('.');
className.splice(-1);
pkgInfo.classes[className] = pkgDir+'/'+fileName;
}
}
packageList[pkgInfo.name]=pkgInfo;
}
}
} catch (e)
{
console.error('Error on loading package `'+pkgName+"`.")
throw e;
}
}
}
this.removeInvalidPackages(packageList);
this.loadPackages(packageList);
} | javascript | function ()
{
var nmPath = this.modulePath + 'node_modules/';
var pkgJson;
var pkgName;
var pkgInfo;
var packageList = {};
var validScript = /[\w|\W]+\.[js|coffee]+$/;
if (fs.existsSync(nmPath))
{
this.e.log&&this.e.log('Importing packages...','system');
var packages = fs.readdirSync(nmPath);
for (p in packages)
{
try {
if (packages[p].indexOf('wns')!==-1 &&
(packages[p].indexOf('pkg') !== -1 || packages[p].indexOf('package') !== -1))
{
pkgName = packages[p];
pkgDir = nmPath + pkgName;
pkgJson = pkgDir + '/package.json';
if (fs.existsSync(pkgJson))
{
pkgInfo = JSON.parse(fs.readFileSync(pkgJson));
pkgInfo.require = pkgInfo.require||{};
Object.defineProperty(pkgInfo,'classes',{ value: {}, enumerable: false })
var files = fs.readdirSync(pkgDir);
for (f in files)
{
var fileName = files[f].split('/').pop();
if (validScript.test(fileName))
{
var className = fileName.split('.');
className.splice(-1);
pkgInfo.classes[className] = pkgDir+'/'+fileName;
}
}
packageList[pkgInfo.name]=pkgInfo;
}
}
} catch (e)
{
console.error('Error on loading package `'+pkgName+"`.")
throw e;
}
}
}
this.removeInvalidPackages(packageList);
this.loadPackages(packageList);
} | [
"function",
"(",
")",
"{",
"var",
"nmPath",
"=",
"this",
".",
"modulePath",
"+",
"'node_modules/'",
";",
"var",
"pkgJson",
";",
"var",
"pkgName",
";",
"var",
"pkgInfo",
";",
"var",
"packageList",
"=",
"{",
"}",
";",
"var",
"validScript",
"=",
"/",
"[\\w|\\W]+\\.[js|coffee]+$",
"/",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"nmPath",
")",
")",
"{",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'Importing packages...'",
",",
"'system'",
")",
";",
"var",
"packages",
"=",
"fs",
".",
"readdirSync",
"(",
"nmPath",
")",
";",
"for",
"(",
"p",
"in",
"packages",
")",
"{",
"try",
"{",
"if",
"(",
"packages",
"[",
"p",
"]",
".",
"indexOf",
"(",
"'wns'",
")",
"!==",
"-",
"1",
"&&",
"(",
"packages",
"[",
"p",
"]",
".",
"indexOf",
"(",
"'pkg'",
")",
"!==",
"-",
"1",
"||",
"packages",
"[",
"p",
"]",
".",
"indexOf",
"(",
"'package'",
")",
"!==",
"-",
"1",
")",
")",
"{",
"pkgName",
"=",
"packages",
"[",
"p",
"]",
";",
"pkgDir",
"=",
"nmPath",
"+",
"pkgName",
";",
"pkgJson",
"=",
"pkgDir",
"+",
"'/package.json'",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"pkgJson",
")",
")",
"{",
"pkgInfo",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"pkgJson",
")",
")",
";",
"pkgInfo",
".",
"require",
"=",
"pkgInfo",
".",
"require",
"||",
"{",
"}",
";",
"Object",
".",
"defineProperty",
"(",
"pkgInfo",
",",
"'classes'",
",",
"{",
"value",
":",
"{",
"}",
",",
"enumerable",
":",
"false",
"}",
")",
"var",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"pkgDir",
")",
";",
"for",
"(",
"f",
"in",
"files",
")",
"{",
"var",
"fileName",
"=",
"files",
"[",
"f",
"]",
".",
"split",
"(",
"'/'",
")",
".",
"pop",
"(",
")",
";",
"if",
"(",
"validScript",
".",
"test",
"(",
"fileName",
")",
")",
"{",
"var",
"className",
"=",
"fileName",
".",
"split",
"(",
"'.'",
")",
";",
"className",
".",
"splice",
"(",
"-",
"1",
")",
";",
"pkgInfo",
".",
"classes",
"[",
"className",
"]",
"=",
"pkgDir",
"+",
"'/'",
"+",
"fileName",
";",
"}",
"}",
"packageList",
"[",
"pkgInfo",
".",
"name",
"]",
"=",
"pkgInfo",
";",
"}",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'Error on loading package `'",
"+",
"pkgName",
"+",
"\"`.\"",
")",
"throw",
"e",
";",
"}",
"}",
"}",
"this",
".",
"removeInvalidPackages",
"(",
"packageList",
")",
";",
"this",
".",
"loadPackages",
"(",
"packageList",
")",
";",
"}"
] | Import package classes from node_modules directory | [
"Import",
"package",
"classes",
"from",
"node_modules",
"directory"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L157-L207 |
|
54,105 | yeptlabs/wns | src/core/base/wnModule.js | function (packageList)
{
if (!_.isObject(packageList))
return false;
var pkgList = _.keys(packageList);
var pkgRequire;
var pkgName;
var pkgInfo;
var depName;
var depVersion;
var i=0;
var valid;
var error;
while (pkgList.length > 0)
{
valid=true;
error=[];
pkgName=pkgList[i];
pkgInfo=packageList[pkgName];
pkgRequire=pkgInfo.require;
for (p in pkgRequire)
{
depName = p;
depVersion = pkgRequire[p];
if (packageList[depName]==undefined)
{ error.push(depName+'@'+depVersion+' is not installed.'); continue; }
if (depVersion!=="*" && packageList[depName].version!=depVersion)
{ error.push(depName+' needs to be '+depVersion); }
}
if (valid||error.length>0)
{
if (error.length>0)
{
delete packageList[pkgName];
for (e in error)
self.e.log('Error on loading `'+pkgName+'`: '+error[e],'error');
}
pkgList.splice(i,1);
}
i++;
if (i>=pkgList.length)
i=0;
}
} | javascript | function (packageList)
{
if (!_.isObject(packageList))
return false;
var pkgList = _.keys(packageList);
var pkgRequire;
var pkgName;
var pkgInfo;
var depName;
var depVersion;
var i=0;
var valid;
var error;
while (pkgList.length > 0)
{
valid=true;
error=[];
pkgName=pkgList[i];
pkgInfo=packageList[pkgName];
pkgRequire=pkgInfo.require;
for (p in pkgRequire)
{
depName = p;
depVersion = pkgRequire[p];
if (packageList[depName]==undefined)
{ error.push(depName+'@'+depVersion+' is not installed.'); continue; }
if (depVersion!=="*" && packageList[depName].version!=depVersion)
{ error.push(depName+' needs to be '+depVersion); }
}
if (valid||error.length>0)
{
if (error.length>0)
{
delete packageList[pkgName];
for (e in error)
self.e.log('Error on loading `'+pkgName+'`: '+error[e],'error');
}
pkgList.splice(i,1);
}
i++;
if (i>=pkgList.length)
i=0;
}
} | [
"function",
"(",
"packageList",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"packageList",
")",
")",
"return",
"false",
";",
"var",
"pkgList",
"=",
"_",
".",
"keys",
"(",
"packageList",
")",
";",
"var",
"pkgRequire",
";",
"var",
"pkgName",
";",
"var",
"pkgInfo",
";",
"var",
"depName",
";",
"var",
"depVersion",
";",
"var",
"i",
"=",
"0",
";",
"var",
"valid",
";",
"var",
"error",
";",
"while",
"(",
"pkgList",
".",
"length",
">",
"0",
")",
"{",
"valid",
"=",
"true",
";",
"error",
"=",
"[",
"]",
";",
"pkgName",
"=",
"pkgList",
"[",
"i",
"]",
";",
"pkgInfo",
"=",
"packageList",
"[",
"pkgName",
"]",
";",
"pkgRequire",
"=",
"pkgInfo",
".",
"require",
";",
"for",
"(",
"p",
"in",
"pkgRequire",
")",
"{",
"depName",
"=",
"p",
";",
"depVersion",
"=",
"pkgRequire",
"[",
"p",
"]",
";",
"if",
"(",
"packageList",
"[",
"depName",
"]",
"==",
"undefined",
")",
"{",
"error",
".",
"push",
"(",
"depName",
"+",
"'@'",
"+",
"depVersion",
"+",
"' is not installed.'",
")",
";",
"continue",
";",
"}",
"if",
"(",
"depVersion",
"!==",
"\"*\"",
"&&",
"packageList",
"[",
"depName",
"]",
".",
"version",
"!=",
"depVersion",
")",
"{",
"error",
".",
"push",
"(",
"depName",
"+",
"' needs to be '",
"+",
"depVersion",
")",
";",
"}",
"}",
"if",
"(",
"valid",
"||",
"error",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"error",
".",
"length",
">",
"0",
")",
"{",
"delete",
"packageList",
"[",
"pkgName",
"]",
";",
"for",
"(",
"e",
"in",
"error",
")",
"self",
".",
"e",
".",
"log",
"(",
"'Error on loading `'",
"+",
"pkgName",
"+",
"'`: '",
"+",
"error",
"[",
"e",
"]",
",",
"'error'",
")",
";",
"}",
"pkgList",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"i",
"++",
";",
"if",
"(",
"i",
">=",
"pkgList",
".",
"length",
")",
"i",
"=",
"0",
";",
"}",
"}"
] | Remove invalid packages from the packageList.
@param object $packageList | [
"Remove",
"invalid",
"packages",
"from",
"the",
"packageList",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L213-L261 |
|
54,106 | yeptlabs/wns | src/core/base/wnModule.js | function (packageList)
{
var classes;
var className;
var classSource;
var classBuilder = this.getComponent('classBuilder');
for (p in packageList)
{
classes = packageList[p].classes;
for (c in classes)
{
className = c;
classBuilder.addSource(className,classes[c],true);
}
}
classBuilder.load();
classBuilder.build();
} | javascript | function (packageList)
{
var classes;
var className;
var classSource;
var classBuilder = this.getComponent('classBuilder');
for (p in packageList)
{
classes = packageList[p].classes;
for (c in classes)
{
className = c;
classBuilder.addSource(className,classes[c],true);
}
}
classBuilder.load();
classBuilder.build();
} | [
"function",
"(",
"packageList",
")",
"{",
"var",
"classes",
";",
"var",
"className",
";",
"var",
"classSource",
";",
"var",
"classBuilder",
"=",
"this",
".",
"getComponent",
"(",
"'classBuilder'",
")",
";",
"for",
"(",
"p",
"in",
"packageList",
")",
"{",
"classes",
"=",
"packageList",
"[",
"p",
"]",
".",
"classes",
";",
"for",
"(",
"c",
"in",
"classes",
")",
"{",
"className",
"=",
"c",
";",
"classBuilder",
".",
"addSource",
"(",
"className",
",",
"classes",
"[",
"c",
"]",
",",
"true",
")",
";",
"}",
"}",
"classBuilder",
".",
"load",
"(",
")",
";",
"classBuilder",
".",
"build",
"(",
")",
";",
"}"
] | Load all packages on the classes of the packageList.
@param object $packageList | [
"Load",
"all",
"packages",
"on",
"the",
"classes",
"of",
"the",
"packageList",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L267-L285 |
|
54,107 | yeptlabs/wns | src/core/base/wnModule.js | function ()
{
this.e.log&&this.e.log('Importing from config...','system');
var importConfig = this.getConfig('import');
var cb = this.getComponent('classBuilder');
var validScript = /[\w|\W]+\.[js|coffee]+$/;
for (i in importConfig)
{
var path = this.modulePath+importConfig[i];
if (fs.existsSync(path))
{
this.e.log&&this.e.log('Importing '+path+'...','system');
var classes = fs.readdirSync(path);
for (c in classes)
{
if (!validScript.test(classes[c]))
continue;
var className = classes[c].split('.')[0];
cb.addSource(className,path+classes[c]);
cb.classes[c]=cb.buildClass(className);
}
}
}
} | javascript | function ()
{
this.e.log&&this.e.log('Importing from config...','system');
var importConfig = this.getConfig('import');
var cb = this.getComponent('classBuilder');
var validScript = /[\w|\W]+\.[js|coffee]+$/;
for (i in importConfig)
{
var path = this.modulePath+importConfig[i];
if (fs.existsSync(path))
{
this.e.log&&this.e.log('Importing '+path+'...','system');
var classes = fs.readdirSync(path);
for (c in classes)
{
if (!validScript.test(classes[c]))
continue;
var className = classes[c].split('.')[0];
cb.addSource(className,path+classes[c]);
cb.classes[c]=cb.buildClass(className);
}
}
}
} | [
"function",
"(",
")",
"{",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'Importing from config...'",
",",
"'system'",
")",
";",
"var",
"importConfig",
"=",
"this",
".",
"getConfig",
"(",
"'import'",
")",
";",
"var",
"cb",
"=",
"this",
".",
"getComponent",
"(",
"'classBuilder'",
")",
";",
"var",
"validScript",
"=",
"/",
"[\\w|\\W]+\\.[js|coffee]+$",
"/",
";",
"for",
"(",
"i",
"in",
"importConfig",
")",
"{",
"var",
"path",
"=",
"this",
".",
"modulePath",
"+",
"importConfig",
"[",
"i",
"]",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"path",
")",
")",
"{",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'Importing '",
"+",
"path",
"+",
"'...'",
",",
"'system'",
")",
";",
"var",
"classes",
"=",
"fs",
".",
"readdirSync",
"(",
"path",
")",
";",
"for",
"(",
"c",
"in",
"classes",
")",
"{",
"if",
"(",
"!",
"validScript",
".",
"test",
"(",
"classes",
"[",
"c",
"]",
")",
")",
"continue",
";",
"var",
"className",
"=",
"classes",
"[",
"c",
"]",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
";",
"cb",
".",
"addSource",
"(",
"className",
",",
"path",
"+",
"classes",
"[",
"c",
"]",
")",
";",
"cb",
".",
"classes",
"[",
"c",
"]",
"=",
"cb",
".",
"buildClass",
"(",
"className",
")",
";",
"}",
"}",
"}",
"}"
] | Import classes from the paths from configuration. | [
"Import",
"classes",
"from",
"the",
"paths",
"from",
"configuration",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L290-L316 |
|
54,108 | yeptlabs/wns | src/core/base/wnModule.js | function ()
{
for (c in this.c)
{
if (this.c[c].build && this.c[c].build.extend && this.c[c].build.extend.indexOf('wnActiveRecord')!=-1)
{
this.prepareModel(c);
}
}
} | javascript | function ()
{
for (c in this.c)
{
if (this.c[c].build && this.c[c].build.extend && this.c[c].build.extend.indexOf('wnActiveRecord')!=-1)
{
this.prepareModel(c);
}
}
} | [
"function",
"(",
")",
"{",
"for",
"(",
"c",
"in",
"this",
".",
"c",
")",
"{",
"if",
"(",
"this",
".",
"c",
"[",
"c",
"]",
".",
"build",
"&&",
"this",
".",
"c",
"[",
"c",
"]",
".",
"build",
".",
"extend",
"&&",
"this",
".",
"c",
"[",
"c",
"]",
".",
"build",
".",
"extend",
".",
"indexOf",
"(",
"'wnActiveRecord'",
")",
"!=",
"-",
"1",
")",
"{",
"this",
".",
"prepareModel",
"(",
"c",
")",
";",
"}",
"}",
"}"
] | Prepare all models | [
"Prepare",
"all",
"models"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L321-L330 |
|
54,109 | yeptlabs/wns | src/core/base/wnModule.js | function (model) {
var c = this.c,
s = this;
this.m[model]=function () {
var modelClass = c[model];
return new modelClass({ autoInit: true }, s.c, s, s.db);
};
} | javascript | function (model) {
var c = this.c,
s = this;
this.m[model]=function () {
var modelClass = c[model];
return new modelClass({ autoInit: true }, s.c, s, s.db);
};
} | [
"function",
"(",
"model",
")",
"{",
"var",
"c",
"=",
"this",
".",
"c",
",",
"s",
"=",
"this",
";",
"this",
".",
"m",
"[",
"model",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"modelClass",
"=",
"c",
"[",
"model",
"]",
";",
"return",
"new",
"modelClass",
"(",
"{",
"autoInit",
":",
"true",
"}",
",",
"s",
".",
"c",
",",
"s",
",",
"s",
".",
"db",
")",
";",
"}",
";",
"}"
] | Prepare the model
@param $model | [
"Prepare",
"the",
"model"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L336-L343 |
|
54,110 | yeptlabs/wns | src/core/base/wnModule.js | function (file)
{
if (!_.isString(file))
return false;
var file = file+'';
this.e.log&&this.e.log('Loading module configuration from file: '+file,'system');
if (fs.statSync(file).isFile() && path.extname(file) == '.json')
{
var _data = (fs.readFileSync(file,'utf8').toString())
.replace(/\\/g,function () { return "\\"+arguments[0]; })
.replace(/\/\/.+?(?=\n|\r|$)|\/\*[\s\S]+?\*\//g,'');
if(_data = JSON.parse(_data))
{
this.setConfig(_data,true);
return true;
}
}
return false;
} | javascript | function (file)
{
if (!_.isString(file))
return false;
var file = file+'';
this.e.log&&this.e.log('Loading module configuration from file: '+file,'system');
if (fs.statSync(file).isFile() && path.extname(file) == '.json')
{
var _data = (fs.readFileSync(file,'utf8').toString())
.replace(/\\/g,function () { return "\\"+arguments[0]; })
.replace(/\/\/.+?(?=\n|\r|$)|\/\*[\s\S]+?\*\//g,'');
if(_data = JSON.parse(_data))
{
this.setConfig(_data,true);
return true;
}
}
return false;
} | [
"function",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"file",
")",
")",
"return",
"false",
";",
"var",
"file",
"=",
"file",
"+",
"''",
";",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'Loading module configuration from file: '",
"+",
"file",
",",
"'system'",
")",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"file",
")",
".",
"isFile",
"(",
")",
"&&",
"path",
".",
"extname",
"(",
"file",
")",
"==",
"'.json'",
")",
"{",
"var",
"_data",
"=",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"'utf8'",
")",
".",
"toString",
"(",
")",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"function",
"(",
")",
"{",
"return",
"\"\\\\\"",
"+",
"arguments",
"[",
"0",
"]",
";",
"}",
")",
".",
"replace",
"(",
"/",
"\\/\\/.+?(?=\\n|\\r|$)|\\/\\*[\\s\\S]+?\\*\\/",
"/",
"g",
",",
"''",
")",
";",
"if",
"(",
"_data",
"=",
"JSON",
".",
"parse",
"(",
"_data",
")",
")",
"{",
"this",
".",
"setConfig",
"(",
"_data",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get a JSON configuration from file then send it to the `setConfig`
@param string $file path to the file
@return boolean success? | [
"Get",
"a",
"JSON",
"configuration",
"from",
"file",
"then",
"send",
"it",
"to",
"the",
"setConfig"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L381-L401 |
|
54,111 | yeptlabs/wns | src/core/base/wnModule.js | function (components)
{
for (c in components)
{
_componentsConfig[c]=_.merge({}, components[c]);
if (this.hasComponent(c))
_.merge(_componentsConfig[c],this.getComponentsConfig[c]);
}
return this;
} | javascript | function (components)
{
for (c in components)
{
_componentsConfig[c]=_.merge({}, components[c]);
if (this.hasComponent(c))
_.merge(_componentsConfig[c],this.getComponentsConfig[c]);
}
return this;
} | [
"function",
"(",
"components",
")",
"{",
"for",
"(",
"c",
"in",
"components",
")",
"{",
"_componentsConfig",
"[",
"c",
"]",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"components",
"[",
"c",
"]",
")",
";",
"if",
"(",
"this",
".",
"hasComponent",
"(",
"c",
")",
")",
"_",
".",
"merge",
"(",
"_componentsConfig",
"[",
"c",
"]",
",",
"this",
".",
"getComponentsConfig",
"[",
"c",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Set new properties to the component configuration.
@param object $components components(id=>component configuration or instances)
Defaults to true, meaning the previously registered component configuration of the same ID
will be merged with the new configuration. If false, the existing configuration will be replaced completely. | [
"Set",
"new",
"properties",
"to",
"the",
"component",
"configuration",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L410-L419 |
|
54,112 | yeptlabs/wns | src/core/base/wnModule.js | function (className,config)
{
var component = this.createClass(className,config);
if (component)
component.setParent(this);
return component;
} | javascript | function (className,config)
{
var component = this.createClass(className,config);
if (component)
component.setParent(this);
return component;
} | [
"function",
"(",
"className",
",",
"config",
")",
"{",
"var",
"component",
"=",
"this",
".",
"createClass",
"(",
"className",
",",
"config",
")",
";",
"if",
"(",
"component",
")",
"component",
".",
"setParent",
"(",
"this",
")",
";",
"return",
"component",
";",
"}"
] | Create a new instance of the component.
@param string $className component class (case-sensitive)
@param string $config component custom config
@return wnModule the module instance, false if the module is disabled or does not exist. | [
"Create",
"a",
"new",
"instance",
"of",
"the",
"component",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L494-L500 |
|
54,113 | yeptlabs/wns | src/core/base/wnModule.js | function ()
{
this.setConfig({components: this.preload});
var preload = this.getConfig().components;
if (preload != undefined)
{
this.setComponents(preload);
}
return this;
} | javascript | function ()
{
this.setConfig({components: this.preload});
var preload = this.getConfig().components;
if (preload != undefined)
{
this.setComponents(preload);
}
return this;
} | [
"function",
"(",
")",
"{",
"this",
".",
"setConfig",
"(",
"{",
"components",
":",
"this",
".",
"preload",
"}",
")",
";",
"var",
"preload",
"=",
"this",
".",
"getConfig",
"(",
")",
".",
"components",
";",
"if",
"(",
"preload",
"!=",
"undefined",
")",
"{",
"this",
".",
"setComponents",
"(",
"preload",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Preload all required components | [
"Preload",
"all",
"required",
"components"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L541-L550 |
|
54,114 | yeptlabs/wns | src/core/base/wnModule.js | function ()
{
var cps=this.getComponentsConfig();
for (c in cps)
{
var cpnt=this.getComponent(c);
if (cpnt)
this.e.log&&this.e.log('- Started component: '+cps[c].class+(cpnt.getConfig('alias')?' (as '+cpnt.getConfig('alias')+')':''),'system');
}
return this;
} | javascript | function ()
{
var cps=this.getComponentsConfig();
for (c in cps)
{
var cpnt=this.getComponent(c);
if (cpnt)
this.e.log&&this.e.log('- Started component: '+cps[c].class+(cpnt.getConfig('alias')?' (as '+cpnt.getConfig('alias')+')':''),'system');
}
return this;
} | [
"function",
"(",
")",
"{",
"var",
"cps",
"=",
"this",
".",
"getComponentsConfig",
"(",
")",
";",
"for",
"(",
"c",
"in",
"cps",
")",
"{",
"var",
"cpnt",
"=",
"this",
".",
"getComponent",
"(",
"c",
")",
";",
"if",
"(",
"cpnt",
")",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'- Started component: '",
"+",
"cps",
"[",
"c",
"]",
".",
"class",
"+",
"(",
"cpnt",
".",
"getConfig",
"(",
"'alias'",
")",
"?",
"' (as '",
"+",
"cpnt",
".",
"getConfig",
"(",
"'alias'",
")",
"+",
"')'",
":",
"''",
")",
",",
"'system'",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Start all preloaded components | [
"Start",
"all",
"preloaded",
"components"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L555-L565 |
|
54,115 | yeptlabs/wns | src/core/base/wnModule.js | function (modules)
{
for (m in modules)
{
_modulesConfig[m]=_.merge({}, modules[m]);
if (this.hasModule(m))
_.merge(_modulesConfig[m],this.getModulesConfig[m]);
}
return this;
} | javascript | function (modules)
{
for (m in modules)
{
_modulesConfig[m]=_.merge({}, modules[m]);
if (this.hasModule(m))
_.merge(_modulesConfig[m],this.getModulesConfig[m]);
}
return this;
} | [
"function",
"(",
"modules",
")",
"{",
"for",
"(",
"m",
"in",
"modules",
")",
"{",
"_modulesConfig",
"[",
"m",
"]",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"modules",
"[",
"m",
"]",
")",
";",
"if",
"(",
"this",
".",
"hasModule",
"(",
"m",
")",
")",
"_",
".",
"merge",
"(",
"_modulesConfig",
"[",
"m",
"]",
",",
"this",
".",
"getModulesConfig",
"[",
"m",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Merge new configuration into the module configuration
@param object $modules application modules(id=>module configuration or instances)
Defaults to true, meaning the previously registered module configuration of the same ID
will be merged with the new configuration. If false, the existing configuration will be replaced completely. | [
"Merge",
"new",
"configuration",
"into",
"the",
"module",
"configuration"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L574-L583 |
|
54,116 | yeptlabs/wns | src/core/base/wnModule.js | function (id,onLoad)
{
if (_modules[id] != undefined)
return _modules[id];
else if (this.hasComponent('classBuilder'))
{
try {
var config = _modulesConfig[id] || {},
modulePath = config.modulePath || id,
className = config.class;
if (fs.existsSync(this.modulePath+modulePath) && className != undefined)
{
config.id = id;
config.autoInit = !(config.autoInit == false);
var npmPath = [];
for (n in self.npmPath)
npmPath.push(self.npmPath[n]);
npmPath.unshift(this.modulePath+modulePath+'/node_modules/');
var module = this.createModule(className,config,modulePath,npmPath);
if (module)
{
_modules[id] = module;
this.attachModuleEvents(id);
onLoad&&onLoad(module);
self.e.loadModule(id,module);
process.nextTick(function () {
module.e.ready(modulePath,config);
});
return _modules[id];
}
return false;
} else
return false;
} catch (e)
{
this.e.log&&
this.e.log('wnModule.getModule: Error at loading `'+id+'`');
this.e.exception&&
this.e.exception(e);
}
}
} | javascript | function (id,onLoad)
{
if (_modules[id] != undefined)
return _modules[id];
else if (this.hasComponent('classBuilder'))
{
try {
var config = _modulesConfig[id] || {},
modulePath = config.modulePath || id,
className = config.class;
if (fs.existsSync(this.modulePath+modulePath) && className != undefined)
{
config.id = id;
config.autoInit = !(config.autoInit == false);
var npmPath = [];
for (n in self.npmPath)
npmPath.push(self.npmPath[n]);
npmPath.unshift(this.modulePath+modulePath+'/node_modules/');
var module = this.createModule(className,config,modulePath,npmPath);
if (module)
{
_modules[id] = module;
this.attachModuleEvents(id);
onLoad&&onLoad(module);
self.e.loadModule(id,module);
process.nextTick(function () {
module.e.ready(modulePath,config);
});
return _modules[id];
}
return false;
} else
return false;
} catch (e)
{
this.e.log&&
this.e.log('wnModule.getModule: Error at loading `'+id+'`');
this.e.exception&&
this.e.exception(e);
}
}
} | [
"function",
"(",
"id",
",",
"onLoad",
")",
"{",
"if",
"(",
"_modules",
"[",
"id",
"]",
"!=",
"undefined",
")",
"return",
"_modules",
"[",
"id",
"]",
";",
"else",
"if",
"(",
"this",
".",
"hasComponent",
"(",
"'classBuilder'",
")",
")",
"{",
"try",
"{",
"var",
"config",
"=",
"_modulesConfig",
"[",
"id",
"]",
"||",
"{",
"}",
",",
"modulePath",
"=",
"config",
".",
"modulePath",
"||",
"id",
",",
"className",
"=",
"config",
".",
"class",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"this",
".",
"modulePath",
"+",
"modulePath",
")",
"&&",
"className",
"!=",
"undefined",
")",
"{",
"config",
".",
"id",
"=",
"id",
";",
"config",
".",
"autoInit",
"=",
"!",
"(",
"config",
".",
"autoInit",
"==",
"false",
")",
";",
"var",
"npmPath",
"=",
"[",
"]",
";",
"for",
"(",
"n",
"in",
"self",
".",
"npmPath",
")",
"npmPath",
".",
"push",
"(",
"self",
".",
"npmPath",
"[",
"n",
"]",
")",
";",
"npmPath",
".",
"unshift",
"(",
"this",
".",
"modulePath",
"+",
"modulePath",
"+",
"'/node_modules/'",
")",
";",
"var",
"module",
"=",
"this",
".",
"createModule",
"(",
"className",
",",
"config",
",",
"modulePath",
",",
"npmPath",
")",
";",
"if",
"(",
"module",
")",
"{",
"_modules",
"[",
"id",
"]",
"=",
"module",
";",
"this",
".",
"attachModuleEvents",
"(",
"id",
")",
";",
"onLoad",
"&&",
"onLoad",
"(",
"module",
")",
";",
"self",
".",
"e",
".",
"loadModule",
"(",
"id",
",",
"module",
")",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"module",
".",
"e",
".",
"ready",
"(",
"modulePath",
",",
"config",
")",
";",
"}",
")",
";",
"return",
"_modules",
"[",
"id",
"]",
";",
"}",
"return",
"false",
";",
"}",
"else",
"return",
"false",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"'wnModule.getModule: Error at loading `'",
"+",
"id",
"+",
"'`'",
")",
";",
"this",
".",
"e",
".",
"exception",
"&&",
"this",
".",
"e",
".",
"exception",
"(",
"e",
")",
";",
"}",
"}",
"}"
] | Retrieves the named application module.
The module has to be declared in the global modules list. A new instance will be created
when calling this method with the given ID for the first time.
@param string $id application module ID (case-sensitive)
@param function $onLoad function called when app loaded
@return wnModule the module instance, null if the module is disabled or does not exist. | [
"Retrieves",
"the",
"named",
"application",
"module",
".",
"The",
"module",
"has",
"to",
"be",
"declared",
"in",
"the",
"global",
"modules",
"list",
".",
"A",
"new",
"instance",
"will",
"be",
"created",
"when",
"calling",
"this",
"method",
"with",
"the",
"given",
"ID",
"for",
"the",
"first",
"time",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L593-L634 |
|
54,117 | yeptlabs/wns | src/core/base/wnModule.js | function (className,config,modulePath,npmPath)
{
var module = this.createClass(className,config,modulePath,npmPath);
return module;
} | javascript | function (className,config,modulePath,npmPath)
{
var module = this.createClass(className,config,modulePath,npmPath);
return module;
} | [
"function",
"(",
"className",
",",
"config",
",",
"modulePath",
",",
"npmPath",
")",
"{",
"var",
"module",
"=",
"this",
".",
"createClass",
"(",
"className",
",",
"config",
",",
"modulePath",
",",
"npmPath",
")",
";",
"return",
"module",
";",
"}"
] | Create a new instance of a module.
@param string $className
@param string $modulePath
@param object $config
@param string $npmPath
@return object | [
"Create",
"a",
"new",
"instance",
"of",
"a",
"module",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L654-L658 |
|
54,118 | yeptlabs/wns | src/core/base/wnModule.js | function (id) {
if (!_.isString(id))
return false;
var module = this.getModule(id),
events;
this.e.log&&this.e.log("Attaching module's events...",'system');
if (module != undefined && (events=module.getEvents()) && !_.isEmpty(events)) {
for (e in events)
{
var evtConfig = {},
eventName = 'module.'+e.split('-').pop(),
evtCnf = events[e].getConfig(),
event = events[e],
eventClass;
if (!this.hasEvent(eventName) && evtCnf.bubble && e.indexOf('event-module') == -1)
{
evtConfig[eventName]=_.merge({},evtCnf);
evtConfig[eventName].listenEvent=null;
evtConfig[eventName].handler=null;
this.setEvents(evtConfig);
this.getEvent(eventName);
}
if (this.hasEvent(eventName) && e.indexOf('event-module') == -1)
{
eventClass = this.getEvent(eventName);
event.prependListener(function (e) {
if (typeof e == 'object'
&& e.stopPropagation == true)
return false;
eventClass.emit.apply(eventClass,arguments);
});
}
}
this.attachEventsHandlers();
}
return this;
} | javascript | function (id) {
if (!_.isString(id))
return false;
var module = this.getModule(id),
events;
this.e.log&&this.e.log("Attaching module's events...",'system');
if (module != undefined && (events=module.getEvents()) && !_.isEmpty(events)) {
for (e in events)
{
var evtConfig = {},
eventName = 'module.'+e.split('-').pop(),
evtCnf = events[e].getConfig(),
event = events[e],
eventClass;
if (!this.hasEvent(eventName) && evtCnf.bubble && e.indexOf('event-module') == -1)
{
evtConfig[eventName]=_.merge({},evtCnf);
evtConfig[eventName].listenEvent=null;
evtConfig[eventName].handler=null;
this.setEvents(evtConfig);
this.getEvent(eventName);
}
if (this.hasEvent(eventName) && e.indexOf('event-module') == -1)
{
eventClass = this.getEvent(eventName);
event.prependListener(function (e) {
if (typeof e == 'object'
&& e.stopPropagation == true)
return false;
eventClass.emit.apply(eventClass,arguments);
});
}
}
this.attachEventsHandlers();
}
return this;
} | [
"function",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"id",
")",
")",
"return",
"false",
";",
"var",
"module",
"=",
"this",
".",
"getModule",
"(",
"id",
")",
",",
"events",
";",
"this",
".",
"e",
".",
"log",
"&&",
"this",
".",
"e",
".",
"log",
"(",
"\"Attaching module's events...\"",
",",
"'system'",
")",
";",
"if",
"(",
"module",
"!=",
"undefined",
"&&",
"(",
"events",
"=",
"module",
".",
"getEvents",
"(",
")",
")",
"&&",
"!",
"_",
".",
"isEmpty",
"(",
"events",
")",
")",
"{",
"for",
"(",
"e",
"in",
"events",
")",
"{",
"var",
"evtConfig",
"=",
"{",
"}",
",",
"eventName",
"=",
"'module.'",
"+",
"e",
".",
"split",
"(",
"'-'",
")",
".",
"pop",
"(",
")",
",",
"evtCnf",
"=",
"events",
"[",
"e",
"]",
".",
"getConfig",
"(",
")",
",",
"event",
"=",
"events",
"[",
"e",
"]",
",",
"eventClass",
";",
"if",
"(",
"!",
"this",
".",
"hasEvent",
"(",
"eventName",
")",
"&&",
"evtCnf",
".",
"bubble",
"&&",
"e",
".",
"indexOf",
"(",
"'event-module'",
")",
"==",
"-",
"1",
")",
"{",
"evtConfig",
"[",
"eventName",
"]",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"evtCnf",
")",
";",
"evtConfig",
"[",
"eventName",
"]",
".",
"listenEvent",
"=",
"null",
";",
"evtConfig",
"[",
"eventName",
"]",
".",
"handler",
"=",
"null",
";",
"this",
".",
"setEvents",
"(",
"evtConfig",
")",
";",
"this",
".",
"getEvent",
"(",
"eventName",
")",
";",
"}",
"if",
"(",
"this",
".",
"hasEvent",
"(",
"eventName",
")",
"&&",
"e",
".",
"indexOf",
"(",
"'event-module'",
")",
"==",
"-",
"1",
")",
"{",
"eventClass",
"=",
"this",
".",
"getEvent",
"(",
"eventName",
")",
";",
"event",
".",
"prependListener",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"typeof",
"e",
"==",
"'object'",
"&&",
"e",
".",
"stopPropagation",
"==",
"true",
")",
"return",
"false",
";",
"eventClass",
".",
"emit",
".",
"apply",
"(",
"eventClass",
",",
"arguments",
")",
";",
"}",
")",
";",
"}",
"}",
"this",
".",
"attachEventsHandlers",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Attach to this module all bubble-events from loaded modules
This create a Bubble-Event to answer to each event that bubles from the module's modules.
Also attach to all modules' events and handler to dispatch the event.
@param string $id source module id | [
"Attach",
"to",
"this",
"module",
"all",
"bubble",
"-",
"events",
"from",
"loaded",
"modules",
"This",
"create",
"a",
"Bubble",
"-",
"Event",
"to",
"answer",
"to",
"each",
"event",
"that",
"bubles",
"from",
"the",
"module",
"s",
"modules",
".",
"Also",
"attach",
"to",
"all",
"modules",
"events",
"and",
"handler",
"to",
"dispatch",
"the",
"event",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L684-L724 |
|
54,119 | yeptlabs/wns | src/core/base/wnModule.js | function (scripts)
{
var script = {};
for (s in scripts)
{
var ref=scripts[s],
scriptName = s.substr(0,1).toUpperCase()+s.substr(1).toLowerCase(),
s = 'script-'+s.replace('-','.');
script[s]=ref;
script[s].class='wnScript'+scriptName || 'wnScript';
_componentsConfig[s]=_.merge({}, script[s]);
}
return this;
} | javascript | function (scripts)
{
var script = {};
for (s in scripts)
{
var ref=scripts[s],
scriptName = s.substr(0,1).toUpperCase()+s.substr(1).toLowerCase(),
s = 'script-'+s.replace('-','.');
script[s]=ref;
script[s].class='wnScript'+scriptName || 'wnScript';
_componentsConfig[s]=_.merge({}, script[s]);
}
return this;
} | [
"function",
"(",
"scripts",
")",
"{",
"var",
"script",
"=",
"{",
"}",
";",
"for",
"(",
"s",
"in",
"scripts",
")",
"{",
"var",
"ref",
"=",
"scripts",
"[",
"s",
"]",
",",
"scriptName",
"=",
"s",
".",
"substr",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"s",
".",
"substr",
"(",
"1",
")",
".",
"toLowerCase",
"(",
")",
",",
"s",
"=",
"'script-'",
"+",
"s",
".",
"replace",
"(",
"'-'",
",",
"'.'",
")",
";",
"script",
"[",
"s",
"]",
"=",
"ref",
";",
"script",
"[",
"s",
"]",
".",
"class",
"=",
"'wnScript'",
"+",
"scriptName",
"||",
"'wnScript'",
";",
"_componentsConfig",
"[",
"s",
"]",
"=",
"_",
".",
"merge",
"(",
"{",
"}",
",",
"script",
"[",
"s",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Set new properties to the respective scripts
@param OBJECT $scripts scripts configurations | [
"Set",
"new",
"properties",
"to",
"the",
"respective",
"scripts"
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L740-L753 |
|
54,120 | yeptlabs/wns | src/core/base/wnModule.js | function (value)
{
if (value != undefined && fs.statSync(value).isDirectory())
{
this.modulePath = value;
this.setConfig('modulePath',value);
}
return this;
} | javascript | function (value)
{
if (value != undefined && fs.statSync(value).isDirectory())
{
this.modulePath = value;
this.setConfig('modulePath',value);
}
return this;
} | [
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"!=",
"undefined",
"&&",
"fs",
".",
"statSync",
"(",
"value",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"this",
".",
"modulePath",
"=",
"value",
";",
"this",
".",
"setConfig",
"(",
"'modulePath'",
",",
"value",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Sets the directory that contains the application modules.
@param string $value the directory that contains the application modules. | [
"Sets",
"the",
"directory",
"that",
"contains",
"the",
"application",
"modules",
"."
] | c42602b062dcf6bbffc22e4365bba2cbf363fe2f | https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnModule.js#L816-L824 |
|
54,121 | microservice-framework/microservice-client | index.js | MicroserviceClient | function MicroserviceClient(settings) {
var self = this;
self.settings = settings;
self.get = bind(self.get, self);
self.post = bind(self.post, self);
self.put = bind(self.put, self);
self.delete = bind(self.delete, self);
self.search = bind(self.search, self);
self._request = bind(self._request, self);
} | javascript | function MicroserviceClient(settings) {
var self = this;
self.settings = settings;
self.get = bind(self.get, self);
self.post = bind(self.post, self);
self.put = bind(self.put, self);
self.delete = bind(self.delete, self);
self.search = bind(self.search, self);
self._request = bind(self._request, self);
} | [
"function",
"MicroserviceClient",
"(",
"settings",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"settings",
"=",
"settings",
";",
"self",
".",
"get",
"=",
"bind",
"(",
"self",
".",
"get",
",",
"self",
")",
";",
"self",
".",
"post",
"=",
"bind",
"(",
"self",
".",
"post",
",",
"self",
")",
";",
"self",
".",
"put",
"=",
"bind",
"(",
"self",
".",
"put",
",",
"self",
")",
";",
"self",
".",
"delete",
"=",
"bind",
"(",
"self",
".",
"delete",
",",
"self",
")",
";",
"self",
".",
"search",
"=",
"bind",
"(",
"self",
".",
"search",
",",
"self",
")",
";",
"self",
".",
"_request",
"=",
"bind",
"(",
"self",
".",
"_request",
",",
"self",
")",
";",
"}"
] | Constructor of MicroserviceClientClient object.
.
settings.URL = process.env.SELF_URL;
settings.secureKey = process.env.SECURE_KEY;
settings.accessToken = if microservice-auth used, accessToken can be set here. | [
"Constructor",
"of",
"MicroserviceClientClient",
"object",
".",
".",
"settings",
".",
"URL",
"=",
"process",
".",
"env",
".",
"SELF_URL",
";",
"settings",
".",
"secureKey",
"=",
"process",
".",
"env",
".",
"SECURE_KEY",
";",
"settings",
".",
"accessToken",
"=",
"if",
"microservice",
"-",
"auth",
"used",
"accessToken",
"can",
"be",
"set",
"here",
"."
] | 48651abb0b715721210e5acd56149da8623ed3af | https://github.com/microservice-framework/microservice-client/blob/48651abb0b715721210e5acd56149da8623ed3af/index.js#L18-L27 |
54,122 | Wiredcraft/handle-http-error | lib/buildHandler.js | buildHandler | function buildHandler(overrides) {
const parseError = buildHandler.parseError;
const buildError = buildHandler.buildError;
/**
* .
*/
return function handler(error) {
const found = parseError.apply(this, arguments);
if (!found) {
if (error instanceof Error) {
Error.captureStackTrace(error, handler);
throw error;
}
return sliced(arguments);
}
error = buildError.apply(this, found);
if (notEmptyObject(overrides)) {
Object.assign(error, overrides);
}
Error.captureStackTrace(error, handler);
throw error;
};
} | javascript | function buildHandler(overrides) {
const parseError = buildHandler.parseError;
const buildError = buildHandler.buildError;
/**
* .
*/
return function handler(error) {
const found = parseError.apply(this, arguments);
if (!found) {
if (error instanceof Error) {
Error.captureStackTrace(error, handler);
throw error;
}
return sliced(arguments);
}
error = buildError.apply(this, found);
if (notEmptyObject(overrides)) {
Object.assign(error, overrides);
}
Error.captureStackTrace(error, handler);
throw error;
};
} | [
"function",
"buildHandler",
"(",
"overrides",
")",
"{",
"const",
"parseError",
"=",
"buildHandler",
".",
"parseError",
";",
"const",
"buildError",
"=",
"buildHandler",
".",
"buildError",
";",
"/**\n * .\n */",
"return",
"function",
"handler",
"(",
"error",
")",
"{",
"const",
"found",
"=",
"parseError",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"!",
"found",
")",
"{",
"if",
"(",
"error",
"instanceof",
"Error",
")",
"{",
"Error",
".",
"captureStackTrace",
"(",
"error",
",",
"handler",
")",
";",
"throw",
"error",
";",
"}",
"return",
"sliced",
"(",
"arguments",
")",
";",
"}",
"error",
"=",
"buildError",
".",
"apply",
"(",
"this",
",",
"found",
")",
";",
"if",
"(",
"notEmptyObject",
"(",
"overrides",
")",
")",
"{",
"Object",
".",
"assign",
"(",
"error",
",",
"overrides",
")",
";",
"}",
"Error",
".",
"captureStackTrace",
"(",
"error",
",",
"handler",
")",
";",
"throw",
"error",
";",
"}",
";",
"}"
] | Build a handler.
@param {Object} overrides override the error attributes
@return {Function} the handler | [
"Build",
"a",
"handler",
"."
] | 2054c1ade9f5e4b11fd64c432317c815cb97063a | https://github.com/Wiredcraft/handle-http-error/blob/2054c1ade9f5e4b11fd64c432317c815cb97063a/lib/buildHandler.js#L23-L46 |
54,123 | tbremer/verboser | index.js | function (string) {
color = chalk.cyan;
if (args.verbose) {
if (typeof string === "string") {
console.log(color(string));
}
if (isArray(string)) {
console.log(color(arrayToString(string)));
}
}
return this;
} | javascript | function (string) {
color = chalk.cyan;
if (args.verbose) {
if (typeof string === "string") {
console.log(color(string));
}
if (isArray(string)) {
console.log(color(arrayToString(string)));
}
}
return this;
} | [
"function",
"(",
"string",
")",
"{",
"color",
"=",
"chalk",
".",
"cyan",
";",
"if",
"(",
"args",
".",
"verbose",
")",
"{",
"if",
"(",
"typeof",
"string",
"===",
"\"string\"",
")",
"{",
"console",
".",
"log",
"(",
"color",
"(",
"string",
")",
")",
";",
"}",
"if",
"(",
"isArray",
"(",
"string",
")",
")",
"{",
"console",
".",
"log",
"(",
"color",
"(",
"arrayToString",
"(",
"string",
")",
")",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | verbose.log | [
"verbose",
".",
"log"
] | 2ad328c6f56e21f798b2e1760325a243b4df368a | https://github.com/tbremer/verboser/blob/2ad328c6f56e21f798b2e1760325a243b4df368a/index.js#L67-L78 |
|
54,124 | mrdaniellewis/node-stream-collect | index.js | addListener | function addListener(name) {
if (name !== 'collect') {
return;
}
if (this._collecting) {
// Don't add more than once
return;
}
debug('adding collect method', this._readableState.objectMode, this._readableState.encoding);
let collected;
if (this._readableState.objectMode) {
collected = [];
} else if (this._readableState.encoding === null) {
collected = Buffer.from('');
} else {
collected = '';
}
this
.on('readable', () => {
let chunk;
while ((chunk = this.read()) !== null) {
debug('data', chunk);
if (chunk !== null) {
if (this._readableState.objectMode) {
collected.push(chunk);
} else if (this._readableState.encoding === null) {
collected = Buffer.concat([collected, chunk]);
} else {
collected += chunk;
}
}
}
})
.on('end', () => this.emit('collect', collected));
this._collecting = true;
} | javascript | function addListener(name) {
if (name !== 'collect') {
return;
}
if (this._collecting) {
// Don't add more than once
return;
}
debug('adding collect method', this._readableState.objectMode, this._readableState.encoding);
let collected;
if (this._readableState.objectMode) {
collected = [];
} else if (this._readableState.encoding === null) {
collected = Buffer.from('');
} else {
collected = '';
}
this
.on('readable', () => {
let chunk;
while ((chunk = this.read()) !== null) {
debug('data', chunk);
if (chunk !== null) {
if (this._readableState.objectMode) {
collected.push(chunk);
} else if (this._readableState.encoding === null) {
collected = Buffer.concat([collected, chunk]);
} else {
collected += chunk;
}
}
}
})
.on('end', () => this.emit('collect', collected));
this._collecting = true;
} | [
"function",
"addListener",
"(",
"name",
")",
"{",
"if",
"(",
"name",
"!==",
"'collect'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
".",
"_collecting",
")",
"{",
"// Don't add more than once",
"return",
";",
"}",
"debug",
"(",
"'adding collect method'",
",",
"this",
".",
"_readableState",
".",
"objectMode",
",",
"this",
".",
"_readableState",
".",
"encoding",
")",
";",
"let",
"collected",
";",
"if",
"(",
"this",
".",
"_readableState",
".",
"objectMode",
")",
"{",
"collected",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_readableState",
".",
"encoding",
"===",
"null",
")",
"{",
"collected",
"=",
"Buffer",
".",
"from",
"(",
"''",
")",
";",
"}",
"else",
"{",
"collected",
"=",
"''",
";",
"}",
"this",
".",
"on",
"(",
"'readable'",
",",
"(",
")",
"=>",
"{",
"let",
"chunk",
";",
"while",
"(",
"(",
"chunk",
"=",
"this",
".",
"read",
"(",
")",
")",
"!==",
"null",
")",
"{",
"debug",
"(",
"'data'",
",",
"chunk",
")",
";",
"if",
"(",
"chunk",
"!==",
"null",
")",
"{",
"if",
"(",
"this",
".",
"_readableState",
".",
"objectMode",
")",
"{",
"collected",
".",
"push",
"(",
"chunk",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"_readableState",
".",
"encoding",
"===",
"null",
")",
"{",
"collected",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"collected",
",",
"chunk",
"]",
")",
";",
"}",
"else",
"{",
"collected",
"+=",
"chunk",
";",
"}",
"}",
"}",
"}",
")",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"this",
".",
"emit",
"(",
"'collect'",
",",
"collected",
")",
")",
";",
"this",
".",
"_collecting",
"=",
"true",
";",
"}"
] | When a listener for an event named collect is added start collecting the data | [
"When",
"a",
"listener",
"for",
"an",
"event",
"named",
"collect",
"is",
"added",
"start",
"collecting",
"the",
"data"
] | cd651cdcd46ca9ecd71849cc5e1ed57a533af25f | https://github.com/mrdaniellewis/node-stream-collect/blob/cd651cdcd46ca9ecd71849cc5e1ed57a533af25f/index.js#L9-L50 |
54,125 | mrdaniellewis/node-stream-collect | index.js | addToStream | function addToStream(stream) {
// Don't add more than once
if (stream.listeners('addListener').includes(addListener)) {
return stream;
}
stream.on('newListener', addListener);
return stream;
} | javascript | function addToStream(stream) {
// Don't add more than once
if (stream.listeners('addListener').includes(addListener)) {
return stream;
}
stream.on('newListener', addListener);
return stream;
} | [
"function",
"addToStream",
"(",
"stream",
")",
"{",
"// Don't add more than once",
"if",
"(",
"stream",
".",
"listeners",
"(",
"'addListener'",
")",
".",
"includes",
"(",
"addListener",
")",
")",
"{",
"return",
"stream",
";",
"}",
"stream",
".",
"on",
"(",
"'newListener'",
",",
"addListener",
")",
";",
"return",
"stream",
";",
"}"
] | Add the collect event to the stream
@param {Stream} stream | [
"Add",
"the",
"collect",
"event",
"to",
"the",
"stream"
] | cd651cdcd46ca9ecd71849cc5e1ed57a533af25f | https://github.com/mrdaniellewis/node-stream-collect/blob/cd651cdcd46ca9ecd71849cc5e1ed57a533af25f/index.js#L56-L65 |
54,126 | mrdaniellewis/node-stream-collect | index.js | collect | function collect(stream, encoding, cb = () => {}) {
if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
return stream
.pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
.collect()
.then((data) => {
cb(null, data);
return data;
})
.catch((e) => {
cb(e);
throw e;
});
} | javascript | function collect(stream, encoding, cb = () => {}) {
if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
return stream
.pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
.collect()
.then((data) => {
cb(null, data);
return data;
})
.catch((e) => {
cb(e);
throw e;
});
} | [
"function",
"collect",
"(",
"stream",
",",
"encoding",
",",
"cb",
"=",
"(",
")",
"=>",
"{",
"}",
")",
"{",
"if",
"(",
"typeof",
"encoding",
"===",
"'function'",
")",
"{",
"cb",
"=",
"encoding",
";",
"encoding",
"=",
"null",
";",
"}",
"return",
"stream",
".",
"pipe",
"(",
"new",
"Collect",
"(",
"{",
"encoding",
",",
"objectMode",
":",
"stream",
".",
"_readableState",
".",
"objectMode",
"}",
")",
")",
".",
"collect",
"(",
")",
".",
"then",
"(",
"(",
"data",
")",
"=>",
"{",
"cb",
"(",
"null",
",",
"data",
")",
";",
"return",
"data",
";",
"}",
")",
".",
"catch",
"(",
"(",
"e",
")",
"=>",
"{",
"cb",
"(",
"e",
")",
";",
"throw",
"e",
";",
"}",
")",
";",
"}"
] | Collect all data in a stream and return as a promise or in a callback
@param {Stream} stream A stream
@param {String} [encoding] Stream encoding - optional
@param {Function} cb Callback, the first argument will be the data
@returns {Promise} | [
"Collect",
"all",
"data",
"in",
"a",
"stream",
"and",
"return",
"as",
"a",
"promise",
"or",
"in",
"a",
"callback"
] | cd651cdcd46ca9ecd71849cc5e1ed57a533af25f | https://github.com/mrdaniellewis/node-stream-collect/blob/cd651cdcd46ca9ecd71849cc5e1ed57a533af25f/index.js#L115-L132 |
54,127 | shawnbissell/obicallerid | obicallerid.js | ObiCallerID | function ObiCallerID() {
this.fromRegex = /^INVITE[\S\s]*From:\s*"?([\w\s\.\+\?\$]*?)"?<sip:((.*)@)?(.*)>;.*/;
this.cidRegex = /<7> \[SLIC\] CID to deliver: '([\w\s\.\+\?\$]*?)' (\d*).*/;
this.cnams = {};
this.lastSentTime = new Date();
this.outlookImported = false;
this.addressbookImported = false;
this.lastGrowlName = "";
this.lastGrowlNumber = "";
} | javascript | function ObiCallerID() {
this.fromRegex = /^INVITE[\S\s]*From:\s*"?([\w\s\.\+\?\$]*?)"?<sip:((.*)@)?(.*)>;.*/;
this.cidRegex = /<7> \[SLIC\] CID to deliver: '([\w\s\.\+\?\$]*?)' (\d*).*/;
this.cnams = {};
this.lastSentTime = new Date();
this.outlookImported = false;
this.addressbookImported = false;
this.lastGrowlName = "";
this.lastGrowlNumber = "";
} | [
"function",
"ObiCallerID",
"(",
")",
"{",
"this",
".",
"fromRegex",
"=",
"/",
"^INVITE[\\S\\s]*From:\\s*\"?([\\w\\s\\.\\+\\?\\$]*?)\"?<sip:((.*)@)?(.*)>;.*",
"/",
";",
"this",
".",
"cidRegex",
"=",
"/",
"<7> \\[SLIC\\] CID to deliver: '([\\w\\s\\.\\+\\?\\$]*?)' (\\d*).*",
"/",
";",
"this",
".",
"cnams",
"=",
"{",
"}",
";",
"this",
".",
"lastSentTime",
"=",
"new",
"Date",
"(",
")",
";",
"this",
".",
"outlookImported",
"=",
"false",
";",
"this",
".",
"addressbookImported",
"=",
"false",
";",
"this",
".",
"lastGrowlName",
"=",
"\"\"",
";",
"this",
".",
"lastGrowlNumber",
"=",
"\"\"",
";",
"}"
] | An ObiCallerID object
@constructor | [
"An",
"ObiCallerID",
"object"
] | 923ad68a38d3e170fe784109108bf06d52960df8 | https://github.com/shawnbissell/obicallerid/blob/923ad68a38d3e170fe784109108bf06d52960df8/obicallerid.js#L21-L30 |
54,128 | richardschneider/sally | lib/writer.js | SallyWriter | function SallyWriter(opts)
{
this.sally = require('./sally');
opts = opts || {};
this.path = opts.path || 'sally.log';
this.prefix = opts.prefix || '';
this.digest = undefined;
this.onLog = this.onLog.bind(this);
this.onEpochStart = this.onEpochStart.bind(this);
this.onEpochEnd = this.onEpochEnd.bind(this);
this.onCycleStart = this.onCycleStart.bind(this);
this.onCycleEnd = this.onCycleEnd.bind(this);
this.sally
.on('log', this.onLog)
.on('epochStart', this.onEpochStart)
.on('epochEnd', this.onEpochEnd)
.on('cycleStart', this.onCycleStart)
.on('cycleEnd', this.onCycleEnd)
.configure(opts);
} | javascript | function SallyWriter(opts)
{
this.sally = require('./sally');
opts = opts || {};
this.path = opts.path || 'sally.log';
this.prefix = opts.prefix || '';
this.digest = undefined;
this.onLog = this.onLog.bind(this);
this.onEpochStart = this.onEpochStart.bind(this);
this.onEpochEnd = this.onEpochEnd.bind(this);
this.onCycleStart = this.onCycleStart.bind(this);
this.onCycleEnd = this.onCycleEnd.bind(this);
this.sally
.on('log', this.onLog)
.on('epochStart', this.onEpochStart)
.on('epochEnd', this.onEpochEnd)
.on('cycleStart', this.onCycleStart)
.on('cycleEnd', this.onCycleEnd)
.configure(opts);
} | [
"function",
"SallyWriter",
"(",
"opts",
")",
"{",
"this",
".",
"sally",
"=",
"require",
"(",
"'./sally'",
")",
";",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"path",
"=",
"opts",
".",
"path",
"||",
"'sally.log'",
";",
"this",
".",
"prefix",
"=",
"opts",
".",
"prefix",
"||",
"''",
";",
"this",
".",
"digest",
"=",
"undefined",
";",
"this",
".",
"onLog",
"=",
"this",
".",
"onLog",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"onEpochStart",
"=",
"this",
".",
"onEpochStart",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"onEpochEnd",
"=",
"this",
".",
"onEpochEnd",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"onCycleStart",
"=",
"this",
".",
"onCycleStart",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"onCycleEnd",
"=",
"this",
".",
"onCycleEnd",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"sally",
".",
"on",
"(",
"'log'",
",",
"this",
".",
"onLog",
")",
".",
"on",
"(",
"'epochStart'",
",",
"this",
".",
"onEpochStart",
")",
".",
"on",
"(",
"'epochEnd'",
",",
"this",
".",
"onEpochEnd",
")",
".",
"on",
"(",
"'cycleStart'",
",",
"this",
".",
"onCycleStart",
")",
".",
"on",
"(",
"'cycleEnd'",
",",
"this",
".",
"onCycleEnd",
")",
".",
"configure",
"(",
"opts",
")",
";",
"}"
] | AuditFile constructor. | [
"AuditFile",
"constructor",
"."
] | 45f34ab121faced90ca1a2cd2b9b19c7e95c9f54 | https://github.com/richardschneider/sally/blob/45f34ab121faced90ca1a2cd2b9b19c7e95c9f54/lib/writer.js#L13-L33 |
54,129 | linyngfly/omelo | lib/components/proxy.js | function(client, app, sinfos) {
let item;
for (let i = 0, l = sinfos.length; i < l; i++) {
item = sinfos[i];
if (hasProxy(client, item)) {
continue;
}
client.addProxies(getProxyRecords(app, item));
}
} | javascript | function(client, app, sinfos) {
let item;
for (let i = 0, l = sinfos.length; i < l; i++) {
item = sinfos[i];
if (hasProxy(client, item)) {
continue;
}
client.addProxies(getProxyRecords(app, item));
}
} | [
"function",
"(",
"client",
",",
"app",
",",
"sinfos",
")",
"{",
"let",
"item",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"sinfos",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"item",
"=",
"sinfos",
"[",
"i",
"]",
";",
"if",
"(",
"hasProxy",
"(",
"client",
",",
"item",
")",
")",
"{",
"continue",
";",
"}",
"client",
".",
"addProxies",
"(",
"getProxyRecords",
"(",
"app",
",",
"item",
")",
")",
";",
"}",
"}"
] | Generate proxy for the server infos.
@param {Object} client rpc client instance
@param {Object} app application context
@param {Array} sinfos server info list | [
"Generate",
"proxy",
"for",
"the",
"server",
"infos",
"."
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/components/proxy.js#L177-L186 |
|
54,130 | linyngfly/omelo | lib/components/proxy.js | function(client, sinfo) {
let proxy = client.proxies;
return !!proxy.sys && !! proxy.sys[sinfo.serverType];
} | javascript | function(client, sinfo) {
let proxy = client.proxies;
return !!proxy.sys && !! proxy.sys[sinfo.serverType];
} | [
"function",
"(",
"client",
",",
"sinfo",
")",
"{",
"let",
"proxy",
"=",
"client",
".",
"proxies",
";",
"return",
"!",
"!",
"proxy",
".",
"sys",
"&&",
"!",
"!",
"proxy",
".",
"sys",
"[",
"sinfo",
".",
"serverType",
"]",
";",
"}"
] | Check a server whether has generated proxy before
@param {Object} client rpc client instance
@param {Object} sinfo server info
@return {Boolean} true or false | [
"Check",
"a",
"server",
"whether",
"has",
"generated",
"proxy",
"before"
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/components/proxy.js#L195-L198 |
|
54,131 | linyngfly/omelo | lib/components/proxy.js | function(app, sinfo) {
let records = [],
appBase = app.getBase(),
record;
// sys remote service path record
if (app.isFrontend(sinfo)) {
record = pathUtil.getSysRemotePath('frontend');
} else {
record = pathUtil.getSysRemotePath('backend');
}
if (record) {
records.push(pathUtil.remotePathRecord('sys', sinfo.serverType, record));
}
// user remote service path record
record = pathUtil.getUserRemotePath(appBase, sinfo.serverType);
if (record) {
records.push(pathUtil.remotePathRecord('user', sinfo.serverType, record));
}
return records;
} | javascript | function(app, sinfo) {
let records = [],
appBase = app.getBase(),
record;
// sys remote service path record
if (app.isFrontend(sinfo)) {
record = pathUtil.getSysRemotePath('frontend');
} else {
record = pathUtil.getSysRemotePath('backend');
}
if (record) {
records.push(pathUtil.remotePathRecord('sys', sinfo.serverType, record));
}
// user remote service path record
record = pathUtil.getUserRemotePath(appBase, sinfo.serverType);
if (record) {
records.push(pathUtil.remotePathRecord('user', sinfo.serverType, record));
}
return records;
} | [
"function",
"(",
"app",
",",
"sinfo",
")",
"{",
"let",
"records",
"=",
"[",
"]",
",",
"appBase",
"=",
"app",
".",
"getBase",
"(",
")",
",",
"record",
";",
"// sys remote service path record",
"if",
"(",
"app",
".",
"isFrontend",
"(",
"sinfo",
")",
")",
"{",
"record",
"=",
"pathUtil",
".",
"getSysRemotePath",
"(",
"'frontend'",
")",
";",
"}",
"else",
"{",
"record",
"=",
"pathUtil",
".",
"getSysRemotePath",
"(",
"'backend'",
")",
";",
"}",
"if",
"(",
"record",
")",
"{",
"records",
".",
"push",
"(",
"pathUtil",
".",
"remotePathRecord",
"(",
"'sys'",
",",
"sinfo",
".",
"serverType",
",",
"record",
")",
")",
";",
"}",
"// user remote service path record",
"record",
"=",
"pathUtil",
".",
"getUserRemotePath",
"(",
"appBase",
",",
"sinfo",
".",
"serverType",
")",
";",
"if",
"(",
"record",
")",
"{",
"records",
".",
"push",
"(",
"pathUtil",
".",
"remotePathRecord",
"(",
"'user'",
",",
"sinfo",
".",
"serverType",
",",
"record",
")",
")",
";",
"}",
"return",
"records",
";",
"}"
] | Get proxy path for rpc client.
Iterate all the remote service path and create remote path record.
@param {Object} app current application context
@param {Object} sinfo server info, format: {id, serverType, host, port}
@return {Array} remote path record array | [
"Get",
"proxy",
"path",
"for",
"rpc",
"client",
".",
"Iterate",
"all",
"the",
"remote",
"service",
"path",
"and",
"create",
"remote",
"path",
"record",
"."
] | fb5f79fa31c69de36bd1c370bad5edfa753ca601 | https://github.com/linyngfly/omelo/blob/fb5f79fa31c69de36bd1c370bad5edfa753ca601/lib/components/proxy.js#L208-L229 |
|
54,132 | clarkmalmgren/angular-onselect | dist/angular-onselect.js | snapToWord | function snapToWord() {
if (isHighlighted()) {
throw new Error("Can't modify range after highlighting");
}
var start = selection.range.startOffset;
var startNode = selection.range.startContainer;
while (startNode.textContent.charAt(start) != ' ' && start > 0) {
start--;
}
if (start != 0 && start != selection.range.startOffset) {
start++;
}
var end = selection.range.endOffset;
var endNode = selection.range.endContainer;
while (endNode.textContent.charAt(end) != ' ' && end < endNode.length) {
end++;
}
selection.range.setStart(startNode, start);
selection.range.setEnd(endNode, end);
selection.text = selection.range.toString();
} | javascript | function snapToWord() {
if (isHighlighted()) {
throw new Error("Can't modify range after highlighting");
}
var start = selection.range.startOffset;
var startNode = selection.range.startContainer;
while (startNode.textContent.charAt(start) != ' ' && start > 0) {
start--;
}
if (start != 0 && start != selection.range.startOffset) {
start++;
}
var end = selection.range.endOffset;
var endNode = selection.range.endContainer;
while (endNode.textContent.charAt(end) != ' ' && end < endNode.length) {
end++;
}
selection.range.setStart(startNode, start);
selection.range.setEnd(endNode, end);
selection.text = selection.range.toString();
} | [
"function",
"snapToWord",
"(",
")",
"{",
"if",
"(",
"isHighlighted",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Can't modify range after highlighting\"",
")",
";",
"}",
"var",
"start",
"=",
"selection",
".",
"range",
".",
"startOffset",
";",
"var",
"startNode",
"=",
"selection",
".",
"range",
".",
"startContainer",
";",
"while",
"(",
"startNode",
".",
"textContent",
".",
"charAt",
"(",
"start",
")",
"!=",
"' '",
"&&",
"start",
">",
"0",
")",
"{",
"start",
"--",
";",
"}",
"if",
"(",
"start",
"!=",
"0",
"&&",
"start",
"!=",
"selection",
".",
"range",
".",
"startOffset",
")",
"{",
"start",
"++",
";",
"}",
"var",
"end",
"=",
"selection",
".",
"range",
".",
"endOffset",
";",
"var",
"endNode",
"=",
"selection",
".",
"range",
".",
"endContainer",
";",
"while",
"(",
"endNode",
".",
"textContent",
".",
"charAt",
"(",
"end",
")",
"!=",
"' '",
"&&",
"end",
"<",
"endNode",
".",
"length",
")",
"{",
"end",
"++",
";",
"}",
"selection",
".",
"range",
".",
"setStart",
"(",
"startNode",
",",
"start",
")",
";",
"selection",
".",
"range",
".",
"setEnd",
"(",
"endNode",
",",
"end",
")",
";",
"selection",
".",
"text",
"=",
"selection",
".",
"range",
".",
"toString",
"(",
")",
";",
"}"
] | Expand the current range so that both the beginning and end end at word boundaries.
@memeberOf onselect.Selection
@name snapToWord | [
"Expand",
"the",
"current",
"range",
"so",
"that",
"both",
"the",
"beginning",
"and",
"end",
"end",
"at",
"word",
"boundaries",
"."
] | 07a986af1690dc7c98e0b24706ceadb2fe663e9f | https://github.com/clarkmalmgren/angular-onselect/blob/07a986af1690dc7c98e0b24706ceadb2fe663e9f/dist/angular-onselect.js#L204-L229 |
54,133 | clarkmalmgren/angular-onselect | dist/angular-onselect.js | removeHighlight | function removeHighlight() {
for (var h in selection._highlighter) {
var highlighter = selection._highlighter[h];
var parent = highlighter.parentNode;
while (highlighter.firstChild) {
parent.insertBefore(highlighter.firstChild, highlighter);
}
parent.removeChild(highlighter);
}
selection._highlighter = undefined;
} | javascript | function removeHighlight() {
for (var h in selection._highlighter) {
var highlighter = selection._highlighter[h];
var parent = highlighter.parentNode;
while (highlighter.firstChild) {
parent.insertBefore(highlighter.firstChild, highlighter);
}
parent.removeChild(highlighter);
}
selection._highlighter = undefined;
} | [
"function",
"removeHighlight",
"(",
")",
"{",
"for",
"(",
"var",
"h",
"in",
"selection",
".",
"_highlighter",
")",
"{",
"var",
"highlighter",
"=",
"selection",
".",
"_highlighter",
"[",
"h",
"]",
";",
"var",
"parent",
"=",
"highlighter",
".",
"parentNode",
";",
"while",
"(",
"highlighter",
".",
"firstChild",
")",
"{",
"parent",
".",
"insertBefore",
"(",
"highlighter",
".",
"firstChild",
",",
"highlighter",
")",
";",
"}",
"parent",
".",
"removeChild",
"(",
"highlighter",
")",
";",
"}",
"selection",
".",
"_highlighter",
"=",
"undefined",
";",
"}"
] | Remove highlighting if it currently exists.
@memeberOf onselect.Selection
@name removeHighlight | [
"Remove",
"highlighting",
"if",
"it",
"currently",
"exists",
"."
] | 07a986af1690dc7c98e0b24706ceadb2fe663e9f | https://github.com/clarkmalmgren/angular-onselect/blob/07a986af1690dc7c98e0b24706ceadb2fe663e9f/dist/angular-onselect.js#L272-L284 |
54,134 | clarkmalmgren/angular-onselect | dist/angular-onselect.js | shard | function shard() {
var treeNode = new RangeTreeNode();
treeNode.setStart(range.startContainer, range.startOffset);
var current = range.startContainer;
var distance = 0;
while (current != range.endContainer && distance < 50) {
var last = current;
if (current.firstChild) {
current = current.firstChild;
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.createNewChild();
} else if (current.nextSibling) {
current = current.nextSibling;
if (current.nodeType != 3) {
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.getNextSibling();
}
} else if (current.parentNode.nextSibling) {
current = current.parentNode.nextSibling;
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.getParent().getNextSibling();
}
if (current.nodeType == 3 && !treeNode.start) {
treeNode.setStart(current, 0);
}
distance++;
}
treeNode.setEnd(range.endContainer, range.endOffset );
return treeNode.toRanges();
} | javascript | function shard() {
var treeNode = new RangeTreeNode();
treeNode.setStart(range.startContainer, range.startOffset);
var current = range.startContainer;
var distance = 0;
while (current != range.endContainer && distance < 50) {
var last = current;
if (current.firstChild) {
current = current.firstChild;
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.createNewChild();
} else if (current.nextSibling) {
current = current.nextSibling;
if (current.nodeType != 3) {
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.getNextSibling();
}
} else if (current.parentNode.nextSibling) {
current = current.parentNode.nextSibling;
treeNode.setEnd(last, last.length - 1);
treeNode = treeNode.getParent().getNextSibling();
}
if (current.nodeType == 3 && !treeNode.start) {
treeNode.setStart(current, 0);
}
distance++;
}
treeNode.setEnd(range.endContainer, range.endOffset );
return treeNode.toRanges();
} | [
"function",
"shard",
"(",
")",
"{",
"var",
"treeNode",
"=",
"new",
"RangeTreeNode",
"(",
")",
";",
"treeNode",
".",
"setStart",
"(",
"range",
".",
"startContainer",
",",
"range",
".",
"startOffset",
")",
";",
"var",
"current",
"=",
"range",
".",
"startContainer",
";",
"var",
"distance",
"=",
"0",
";",
"while",
"(",
"current",
"!=",
"range",
".",
"endContainer",
"&&",
"distance",
"<",
"50",
")",
"{",
"var",
"last",
"=",
"current",
";",
"if",
"(",
"current",
".",
"firstChild",
")",
"{",
"current",
"=",
"current",
".",
"firstChild",
";",
"treeNode",
".",
"setEnd",
"(",
"last",
",",
"last",
".",
"length",
"-",
"1",
")",
";",
"treeNode",
"=",
"treeNode",
".",
"createNewChild",
"(",
")",
";",
"}",
"else",
"if",
"(",
"current",
".",
"nextSibling",
")",
"{",
"current",
"=",
"current",
".",
"nextSibling",
";",
"if",
"(",
"current",
".",
"nodeType",
"!=",
"3",
")",
"{",
"treeNode",
".",
"setEnd",
"(",
"last",
",",
"last",
".",
"length",
"-",
"1",
")",
";",
"treeNode",
"=",
"treeNode",
".",
"getNextSibling",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"current",
".",
"parentNode",
".",
"nextSibling",
")",
"{",
"current",
"=",
"current",
".",
"parentNode",
".",
"nextSibling",
";",
"treeNode",
".",
"setEnd",
"(",
"last",
",",
"last",
".",
"length",
"-",
"1",
")",
";",
"treeNode",
"=",
"treeNode",
".",
"getParent",
"(",
")",
".",
"getNextSibling",
"(",
")",
";",
"}",
"if",
"(",
"current",
".",
"nodeType",
"==",
"3",
"&&",
"!",
"treeNode",
".",
"start",
")",
"{",
"treeNode",
".",
"setStart",
"(",
"current",
",",
"0",
")",
";",
"}",
"distance",
"++",
";",
"}",
"treeNode",
".",
"setEnd",
"(",
"range",
".",
"endContainer",
",",
"range",
".",
"endOffset",
")",
";",
"return",
"treeNode",
".",
"toRanges",
"(",
")",
";",
"}"
] | Split the current range into ranges that can actually be highlighted. This is required for doing complex
DOM highlights where the highlight HTML node would need to only partially include a non-text node.
@memberOf onselect.Selection
@name shard
@return {[Range]} the array of ranges | [
"Split",
"the",
"current",
"range",
"into",
"ranges",
"that",
"can",
"actually",
"be",
"highlighted",
".",
"This",
"is",
"required",
"for",
"doing",
"complex",
"DOM",
"highlights",
"where",
"the",
"highlight",
"HTML",
"node",
"would",
"need",
"to",
"only",
"partially",
"include",
"a",
"non",
"-",
"text",
"node",
"."
] | 07a986af1690dc7c98e0b24706ceadb2fe663e9f | https://github.com/clarkmalmgren/angular-onselect/blob/07a986af1690dc7c98e0b24706ceadb2fe663e9f/dist/angular-onselect.js#L304-L343 |
54,135 | itsravenous/i3s-db-utils | index.js | getFingerprintsForAnimal | function getFingerprintsForAnimal(animalDir) {
if (!fs.existsSync(animalDir) || !fs.statSync(animalDir).isDirectory()) {
return false;
}
var fgpFiles = fs.readdirSync(animalDir).filter(function (entry) {
return entry.split('.').pop().toLowerCase() == 'fgp';
});
var fgps = [];
fgpFiles.forEach(function (fgpFile) {
fgpFile = path.join(animalDir, fgpFile);
var fgpData = fgpReader(fgpFile);
fgps.push({
id: path.basename(fgpFile, '.fgp'),
fgp: fgpData,
img64: 'data:image/jpeg;base64,' + fs.readFileSync(getFGPImageName(fgpFile)).toString('base64')
});
});
return fgps;
} | javascript | function getFingerprintsForAnimal(animalDir) {
if (!fs.existsSync(animalDir) || !fs.statSync(animalDir).isDirectory()) {
return false;
}
var fgpFiles = fs.readdirSync(animalDir).filter(function (entry) {
return entry.split('.').pop().toLowerCase() == 'fgp';
});
var fgps = [];
fgpFiles.forEach(function (fgpFile) {
fgpFile = path.join(animalDir, fgpFile);
var fgpData = fgpReader(fgpFile);
fgps.push({
id: path.basename(fgpFile, '.fgp'),
fgp: fgpData,
img64: 'data:image/jpeg;base64,' + fs.readFileSync(getFGPImageName(fgpFile)).toString('base64')
});
});
return fgps;
} | [
"function",
"getFingerprintsForAnimal",
"(",
"animalDir",
")",
"{",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"animalDir",
")",
"||",
"!",
"fs",
".",
"statSync",
"(",
"animalDir",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"var",
"fgpFiles",
"=",
"fs",
".",
"readdirSync",
"(",
"animalDir",
")",
".",
"filter",
"(",
"function",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"split",
"(",
"'.'",
")",
".",
"pop",
"(",
")",
".",
"toLowerCase",
"(",
")",
"==",
"'fgp'",
";",
"}",
")",
";",
"var",
"fgps",
"=",
"[",
"]",
";",
"fgpFiles",
".",
"forEach",
"(",
"function",
"(",
"fgpFile",
")",
"{",
"fgpFile",
"=",
"path",
".",
"join",
"(",
"animalDir",
",",
"fgpFile",
")",
";",
"var",
"fgpData",
"=",
"fgpReader",
"(",
"fgpFile",
")",
";",
"fgps",
".",
"push",
"(",
"{",
"id",
":",
"path",
".",
"basename",
"(",
"fgpFile",
",",
"'.fgp'",
")",
",",
"fgp",
":",
"fgpData",
",",
"img64",
":",
"'data:image/jpeg;base64,'",
"+",
"fs",
".",
"readFileSync",
"(",
"getFGPImageName",
"(",
"fgpFile",
")",
")",
".",
"toString",
"(",
"'base64'",
")",
"}",
")",
";",
"}",
")",
";",
"return",
"fgps",
";",
"}"
] | Fetches fingerprints for an individual
@param {String} individual ID
@return {Array} | [
"Fetches",
"fingerprints",
"for",
"an",
"individual"
] | 7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043 | https://github.com/itsravenous/i3s-db-utils/blob/7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043/index.js#L24-L44 |
54,136 | itsravenous/i3s-db-utils | index.js | getAllFingerprints | function getAllFingerprints(dir) {
var ids = getAnimals();
var fgps = ids.map(function (id) {
return getFingerprintsForAnimal(path.join(dir, id));
}).filter(function (fgp) { return fgp; });
return fgps;
} | javascript | function getAllFingerprints(dir) {
var ids = getAnimals();
var fgps = ids.map(function (id) {
return getFingerprintsForAnimal(path.join(dir, id));
}).filter(function (fgp) { return fgp; });
return fgps;
} | [
"function",
"getAllFingerprints",
"(",
"dir",
")",
"{",
"var",
"ids",
"=",
"getAnimals",
"(",
")",
";",
"var",
"fgps",
"=",
"ids",
".",
"map",
"(",
"function",
"(",
"id",
")",
"{",
"return",
"getFingerprintsForAnimal",
"(",
"path",
".",
"join",
"(",
"dir",
",",
"id",
")",
")",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"fgp",
")",
"{",
"return",
"fgp",
";",
"}",
")",
";",
"return",
"fgps",
";",
"}"
] | Fetches fingerprints for all individuals
@return {Array} | [
"Fetches",
"fingerprints",
"for",
"all",
"individuals"
] | 7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043 | https://github.com/itsravenous/i3s-db-utils/blob/7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043/index.js#L50-L56 |
54,137 | itsravenous/i3s-db-utils | index.js | getAnimals | function getAnimals(dir) {
var ids = fs.readdirSync(dir).filter(function (id) {
return fs.statSync(path.join(dir, id)).isDirectory();
});
return ids;
} | javascript | function getAnimals(dir) {
var ids = fs.readdirSync(dir).filter(function (id) {
return fs.statSync(path.join(dir, id)).isDirectory();
});
return ids;
} | [
"function",
"getAnimals",
"(",
"dir",
")",
"{",
"var",
"ids",
"=",
"fs",
".",
"readdirSync",
"(",
"dir",
")",
".",
"filter",
"(",
"function",
"(",
"id",
")",
"{",
"return",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"dir",
",",
"id",
")",
")",
".",
"isDirectory",
"(",
")",
";",
"}",
")",
";",
"return",
"ids",
";",
"}"
] | Fetches all individuals
@param {String} DB dir
@return {Array} | [
"Fetches",
"all",
"individuals"
] | 7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043 | https://github.com/itsravenous/i3s-db-utils/blob/7d3a7d0b2d5345e2a9a3dd9dcaab9ef2e3e72043/index.js#L63-L68 |
54,138 | bmeck/node-devtools | lib/readline2/terminal_util.js | moveCursorRelative | function moveCursorRelative(stream, dx, dy) {
if (dx < 0) {
stream.write('\x1b[' + (-dx) + 'D');
} else if (dx > 0) {
stream.write('\x1b[' + dx + 'C');
}
if (dy < 0) {
stream.write('\x1b[' + (-dy) + 'A');
} else if (dy > 0) {
stream.write('\x1b[' + dy + 'B');
}
} | javascript | function moveCursorRelative(stream, dx, dy) {
if (dx < 0) {
stream.write('\x1b[' + (-dx) + 'D');
} else if (dx > 0) {
stream.write('\x1b[' + dx + 'C');
}
if (dy < 0) {
stream.write('\x1b[' + (-dy) + 'A');
} else if (dy > 0) {
stream.write('\x1b[' + dy + 'B');
}
} | [
"function",
"moveCursorRelative",
"(",
"stream",
",",
"dx",
",",
"dy",
")",
"{",
"if",
"(",
"dx",
"<",
"0",
")",
"{",
"stream",
".",
"write",
"(",
"'\\x1b['",
"+",
"(",
"-",
"dx",
")",
"+",
"'D'",
")",
";",
"}",
"else",
"if",
"(",
"dx",
">",
"0",
")",
"{",
"stream",
".",
"write",
"(",
"'\\x1b['",
"+",
"dx",
"+",
"'C'",
")",
";",
"}",
"if",
"(",
"dy",
"<",
"0",
")",
"{",
"stream",
".",
"write",
"(",
"'\\x1b['",
"+",
"(",
"-",
"dy",
")",
"+",
"'A'",
")",
";",
"}",
"else",
"if",
"(",
"dy",
">",
"0",
")",
"{",
"stream",
".",
"write",
"(",
"'\\x1b['",
"+",
"dy",
"+",
"'B'",
")",
";",
"}",
"}"
] | moves the cursor relative to its current location | [
"moves",
"the",
"cursor",
"relative",
"to",
"its",
"current",
"location"
] | 331adcae6090b85a8da126d6707f627524aa9a84 | https://github.com/bmeck/node-devtools/blob/331adcae6090b85a8da126d6707f627524aa9a84/lib/readline2/terminal_util.js#L55-L67 |
54,139 | boylesoftware/x2node-validators | index.js | createValidationErrorMessages | function createValidationErrorMessages(base, subjDef) {
if (!subjDef.validationErrorMessages &&
(base !== standard.VALIDATION_ERROR_MESSAGES))
return base;
const validationErrorMessages = Object.create(base);
for (let messageId in subjDef.validationErrorMessages) {
const messageDef = subjDef.validationErrorMessages[messageId];
const existingMessageDef = validationErrorMessages[messageId];
let newMessageDef;
if (existingMessageDef &&
(typeof existingMessageDef) === 'object' &&
(typeof messageDef) === 'object') {
newMessageDef = Object.create(existingMessageDef);
for (let lang in messageDef)
newMessageDef[lang] = messageDef[lang];
} else {
newMessageDef = messageDef;
}
validationErrorMessages[messageId] = newMessageDef;
}
return validationErrorMessages;
} | javascript | function createValidationErrorMessages(base, subjDef) {
if (!subjDef.validationErrorMessages &&
(base !== standard.VALIDATION_ERROR_MESSAGES))
return base;
const validationErrorMessages = Object.create(base);
for (let messageId in subjDef.validationErrorMessages) {
const messageDef = subjDef.validationErrorMessages[messageId];
const existingMessageDef = validationErrorMessages[messageId];
let newMessageDef;
if (existingMessageDef &&
(typeof existingMessageDef) === 'object' &&
(typeof messageDef) === 'object') {
newMessageDef = Object.create(existingMessageDef);
for (let lang in messageDef)
newMessageDef[lang] = messageDef[lang];
} else {
newMessageDef = messageDef;
}
validationErrorMessages[messageId] = newMessageDef;
}
return validationErrorMessages;
} | [
"function",
"createValidationErrorMessages",
"(",
"base",
",",
"subjDef",
")",
"{",
"if",
"(",
"!",
"subjDef",
".",
"validationErrorMessages",
"&&",
"(",
"base",
"!==",
"standard",
".",
"VALIDATION_ERROR_MESSAGES",
")",
")",
"return",
"base",
";",
"const",
"validationErrorMessages",
"=",
"Object",
".",
"create",
"(",
"base",
")",
";",
"for",
"(",
"let",
"messageId",
"in",
"subjDef",
".",
"validationErrorMessages",
")",
"{",
"const",
"messageDef",
"=",
"subjDef",
".",
"validationErrorMessages",
"[",
"messageId",
"]",
";",
"const",
"existingMessageDef",
"=",
"validationErrorMessages",
"[",
"messageId",
"]",
";",
"let",
"newMessageDef",
";",
"if",
"(",
"existingMessageDef",
"&&",
"(",
"typeof",
"existingMessageDef",
")",
"===",
"'object'",
"&&",
"(",
"typeof",
"messageDef",
")",
"===",
"'object'",
")",
"{",
"newMessageDef",
"=",
"Object",
".",
"create",
"(",
"existingMessageDef",
")",
";",
"for",
"(",
"let",
"lang",
"in",
"messageDef",
")",
"newMessageDef",
"[",
"lang",
"]",
"=",
"messageDef",
"[",
"lang",
"]",
";",
"}",
"else",
"{",
"newMessageDef",
"=",
"messageDef",
";",
"}",
"validationErrorMessages",
"[",
"messageId",
"]",
"=",
"newMessageDef",
";",
"}",
"return",
"validationErrorMessages",
";",
"}"
] | Create validation error messages set for the specified container or property.
@private
@param {Object.<string,Object<string,string>>} base Base validation error
messages set from the context.
@param {Object} subjDef Subject definition object possibly containing a
<code>validationErrorMessages</code> attribute.
@returns {Object.<string,Object<string,string>>} Validation error messages set
to use for the subject. | [
"Create",
"validation",
"error",
"messages",
"set",
"for",
"the",
"specified",
"container",
"or",
"property",
"."
] | e98a65c13a4092f80e96517c8e8c9523f8e84c63 | https://github.com/boylesoftware/x2node-validators/blob/e98a65c13a4092f80e96517c8e8c9523f8e84c63/index.js#L266-L290 |
54,140 | boylesoftware/x2node-validators | index.js | createValidatorFuncs | function createValidatorFuncs(base, subjDef, subjDescription) {
if (!subjDef.validatorDefs && (base !== standard.VALIDATOR_DEFS))
return base;
const validatorFuncs = Object.create(base);
for (let validatorId in subjDef.validatorDefs) {
const validatorFunc = subjDef.validatorDefs[validatorId];
if ((typeof validatorFunc) !== 'function')
throw new common.X2UsageError(
'Validator definition "' + validatorId + '" on ' +
subjDescription + ' is not a function.');
validatorFuncs[validatorId] = validatorFunc;
}
return validatorFuncs;
} | javascript | function createValidatorFuncs(base, subjDef, subjDescription) {
if (!subjDef.validatorDefs && (base !== standard.VALIDATOR_DEFS))
return base;
const validatorFuncs = Object.create(base);
for (let validatorId in subjDef.validatorDefs) {
const validatorFunc = subjDef.validatorDefs[validatorId];
if ((typeof validatorFunc) !== 'function')
throw new common.X2UsageError(
'Validator definition "' + validatorId + '" on ' +
subjDescription + ' is not a function.');
validatorFuncs[validatorId] = validatorFunc;
}
return validatorFuncs;
} | [
"function",
"createValidatorFuncs",
"(",
"base",
",",
"subjDef",
",",
"subjDescription",
")",
"{",
"if",
"(",
"!",
"subjDef",
".",
"validatorDefs",
"&&",
"(",
"base",
"!==",
"standard",
".",
"VALIDATOR_DEFS",
")",
")",
"return",
"base",
";",
"const",
"validatorFuncs",
"=",
"Object",
".",
"create",
"(",
"base",
")",
";",
"for",
"(",
"let",
"validatorId",
"in",
"subjDef",
".",
"validatorDefs",
")",
"{",
"const",
"validatorFunc",
"=",
"subjDef",
".",
"validatorDefs",
"[",
"validatorId",
"]",
";",
"if",
"(",
"(",
"typeof",
"validatorFunc",
")",
"!==",
"'function'",
")",
"throw",
"new",
"common",
".",
"X2UsageError",
"(",
"'Validator definition \"'",
"+",
"validatorId",
"+",
"'\" on '",
"+",
"subjDescription",
"+",
"' is not a function.'",
")",
";",
"validatorFuncs",
"[",
"validatorId",
"]",
"=",
"validatorFunc",
";",
"}",
"return",
"validatorFuncs",
";",
"}"
] | Create validator functions set for the specified container or property.
@private
@param {Object.<string,module:x2node-validators.validator>} base Base
validator functions set from the context.
@param {Object} subjDef Subject definition object possibly containing a
<code>validatorDefs</code> attribute.
@param {string} subjDescription Subject description for error messages.
@returns {Object.<string,module:x2node-validators.validator>} validator
functions set to use for the subject. | [
"Create",
"validator",
"functions",
"set",
"for",
"the",
"specified",
"container",
"or",
"property",
"."
] | e98a65c13a4092f80e96517c8e8c9523f8e84c63 | https://github.com/boylesoftware/x2node-validators/blob/e98a65c13a4092f80e96517c8e8c9523f8e84c63/index.js#L304-L320 |
54,141 | r12f/hexo-heading-index | lib/index-maker.js | function (num, uppercase) {
var digits = String(+num).split(""),
key = ["","c","cc","ccc","cd","d","dc","dcc","dccc","cm",
"","x","xx","xxx","xl","l","lx","lxx","lxxx","xc",
"","i","ii","iii","iv","v","vi","vii","viii","ix"],
roman = "",
i = 3;
while (i--)
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
var index = Array(+digits.join("") + 1).join("m") + roman;
return uppercase ? index.toUpperCase() : index;
} | javascript | function (num, uppercase) {
var digits = String(+num).split(""),
key = ["","c","cc","ccc","cd","d","dc","dcc","dccc","cm",
"","x","xx","xxx","xl","l","lx","lxx","lxxx","xc",
"","i","ii","iii","iv","v","vi","vii","viii","ix"],
roman = "",
i = 3;
while (i--)
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
var index = Array(+digits.join("") + 1).join("m") + roman;
return uppercase ? index.toUpperCase() : index;
} | [
"function",
"(",
"num",
",",
"uppercase",
")",
"{",
"var",
"digits",
"=",
"String",
"(",
"+",
"num",
")",
".",
"split",
"(",
"\"\"",
")",
",",
"key",
"=",
"[",
"\"\"",
",",
"\"c\"",
",",
"\"cc\"",
",",
"\"ccc\"",
",",
"\"cd\"",
",",
"\"d\"",
",",
"\"dc\"",
",",
"\"dcc\"",
",",
"\"dccc\"",
",",
"\"cm\"",
",",
"\"\"",
",",
"\"x\"",
",",
"\"xx\"",
",",
"\"xxx\"",
",",
"\"xl\"",
",",
"\"l\"",
",",
"\"lx\"",
",",
"\"lxx\"",
",",
"\"lxxx\"",
",",
"\"xc\"",
",",
"\"\"",
",",
"\"i\"",
",",
"\"ii\"",
",",
"\"iii\"",
",",
"\"iv\"",
",",
"\"v\"",
",",
"\"vi\"",
",",
"\"vii\"",
",",
"\"viii\"",
",",
"\"ix\"",
"]",
",",
"roman",
"=",
"\"\"",
",",
"i",
"=",
"3",
";",
"while",
"(",
"i",
"--",
")",
"roman",
"=",
"(",
"key",
"[",
"+",
"digits",
".",
"pop",
"(",
")",
"+",
"(",
"i",
"*",
"10",
")",
"]",
"||",
"\"\"",
")",
"+",
"roman",
";",
"var",
"index",
"=",
"Array",
"(",
"+",
"digits",
".",
"join",
"(",
"\"\"",
")",
"+",
"1",
")",
".",
"join",
"(",
"\"m\"",
")",
"+",
"roman",
";",
"return",
"uppercase",
"?",
"index",
".",
"toUpperCase",
"(",
")",
":",
"index",
";",
"}"
] | JavaScript Roman Numeral Converter (Thanks to Steven Levithan @slevithan) http://blog.stevenlevithan.com/archives/javascript-roman-numeral-converter | [
"JavaScript",
"Roman",
"Numeral",
"Converter",
"(",
"Thanks",
"to",
"Steven",
"Levithan"
] | 0bc92fd74bf7110bd07c8cb49ce8cd759dda99c5 | https://github.com/r12f/hexo-heading-index/blob/0bc92fd74bf7110bd07c8cb49ce8cd759dda99c5/lib/index-maker.js#L29-L41 |
|
54,142 | soixantecircuits/media-helper | media-helper.js | getMimeType | function getMimeType (media) {
return new Promise((resolve, reject) => {
if (isFile(media)) {
typechecker.detectFile(media, (err, result) => {
err && reject(err)
resolve(result)
})
} else if (isBuffer(media)) {
typechecker.detect(media, (err, result) => {
err && reject(err)
resolve(result)
})
} else if (isBase64(media)) {
return getMimeType(toBuffer(media))
} else if (isURL(media)) {
return getMimeType(toBuffer(media))
} else {
reject('media is not a file')
}
})
} | javascript | function getMimeType (media) {
return new Promise((resolve, reject) => {
if (isFile(media)) {
typechecker.detectFile(media, (err, result) => {
err && reject(err)
resolve(result)
})
} else if (isBuffer(media)) {
typechecker.detect(media, (err, result) => {
err && reject(err)
resolve(result)
})
} else if (isBase64(media)) {
return getMimeType(toBuffer(media))
} else if (isURL(media)) {
return getMimeType(toBuffer(media))
} else {
reject('media is not a file')
}
})
} | [
"function",
"getMimeType",
"(",
"media",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"isFile",
"(",
"media",
")",
")",
"{",
"typechecker",
".",
"detectFile",
"(",
"media",
",",
"(",
"err",
",",
"result",
")",
"=>",
"{",
"err",
"&&",
"reject",
"(",
"err",
")",
"resolve",
"(",
"result",
")",
"}",
")",
"}",
"else",
"if",
"(",
"isBuffer",
"(",
"media",
")",
")",
"{",
"typechecker",
".",
"detect",
"(",
"media",
",",
"(",
"err",
",",
"result",
")",
"=>",
"{",
"err",
"&&",
"reject",
"(",
"err",
")",
"resolve",
"(",
"result",
")",
"}",
")",
"}",
"else",
"if",
"(",
"isBase64",
"(",
"media",
")",
")",
"{",
"return",
"getMimeType",
"(",
"toBuffer",
"(",
"media",
")",
")",
"}",
"else",
"if",
"(",
"isURL",
"(",
"media",
")",
")",
"{",
"return",
"getMimeType",
"(",
"toBuffer",
"(",
"media",
")",
")",
"}",
"else",
"{",
"reject",
"(",
"'media is not a file'",
")",
"}",
"}",
")",
"}"
] | Determines the mime-type of a file
@param {string} media - either path, URL or base64 datas.
@returns {Promise} | [
"Determines",
"the",
"mime",
"-",
"type",
"of",
"a",
"file"
] | af032cd54fca424f06c26c8a6110f7f0bfe0fc1b | https://github.com/soixantecircuits/media-helper/blob/af032cd54fca424f06c26c8a6110f7f0bfe0fc1b/media-helper.js#L58-L78 |
54,143 | soixantecircuits/media-helper | media-helper.js | isImage | function isImage (path) {
return new Promise((resolve, reject) => {
getMimeType(path)
.then((type) => {
;(type.indexOf('image') > -1) ? resolve(true) : resolve(false)
})
.catch(err => reject(err))
})
} | javascript | function isImage (path) {
return new Promise((resolve, reject) => {
getMimeType(path)
.then((type) => {
;(type.indexOf('image') > -1) ? resolve(true) : resolve(false)
})
.catch(err => reject(err))
})
} | [
"function",
"isImage",
"(",
"path",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"getMimeType",
"(",
"path",
")",
".",
"then",
"(",
"(",
"type",
")",
"=>",
"{",
";",
"(",
"type",
".",
"indexOf",
"(",
"'image'",
")",
">",
"-",
"1",
")",
"?",
"resolve",
"(",
"true",
")",
":",
"resolve",
"(",
"false",
")",
"}",
")",
".",
"catch",
"(",
"err",
"=>",
"reject",
"(",
"err",
")",
")",
"}",
")",
"}"
] | Determines if a file is an image
@param {string} path - Path to a file
@returns {Promise} | [
"Determines",
"if",
"a",
"file",
"is",
"an",
"image"
] | af032cd54fca424f06c26c8a6110f7f0bfe0fc1b | https://github.com/soixantecircuits/media-helper/blob/af032cd54fca424f06c26c8a6110f7f0bfe0fc1b/media-helper.js#L94-L102 |
54,144 | soixantecircuits/media-helper | media-helper.js | urlToBase64 | function urlToBase64 (url) {
return new Promise((resolve, reject) => {
request.get(url, (err, response, body) => {
err && reject(err)
resolve(body.toString('base64'))
})
})
} | javascript | function urlToBase64 (url) {
return new Promise((resolve, reject) => {
request.get(url, (err, response, body) => {
err && reject(err)
resolve(body.toString('base64'))
})
})
} | [
"function",
"urlToBase64",
"(",
"url",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"request",
".",
"get",
"(",
"url",
",",
"(",
"err",
",",
"response",
",",
"body",
")",
"=>",
"{",
"err",
"&&",
"reject",
"(",
"err",
")",
"resolve",
"(",
"body",
".",
"toString",
"(",
"'base64'",
")",
")",
"}",
")",
"}",
")",
"}"
] | Reads an image from url and convert it to base64
@param {string} url
@returns {Promise} | [
"Reads",
"an",
"image",
"from",
"url",
"and",
"convert",
"it",
"to",
"base64"
] | af032cd54fca424f06c26c8a6110f7f0bfe0fc1b | https://github.com/soixantecircuits/media-helper/blob/af032cd54fca424f06c26c8a6110f7f0bfe0fc1b/media-helper.js#L124-L131 |
54,145 | soixantecircuits/media-helper | media-helper.js | toBase64 | function toBase64 (media) {
return new Promise((resolve, reject) => {
if (isBase64(media)) {
resolve(media)
} else if (isURL(media)) {
urlToBase64(media)
.then(data => resolve(data))
.catch(error => reject(error))
} else if (isFile(media)) {
fileToBase64(media)
.then(data => resolve(data))
.catch(error => reject(error))
} else if (isBuffer(media)) {
const base64 = media.toString('base64')
resolve(base64)
} else {
reject('Error: toBase64(): cannot convert media')
}
})
} | javascript | function toBase64 (media) {
return new Promise((resolve, reject) => {
if (isBase64(media)) {
resolve(media)
} else if (isURL(media)) {
urlToBase64(media)
.then(data => resolve(data))
.catch(error => reject(error))
} else if (isFile(media)) {
fileToBase64(media)
.then(data => resolve(data))
.catch(error => reject(error))
} else if (isBuffer(media)) {
const base64 = media.toString('base64')
resolve(base64)
} else {
reject('Error: toBase64(): cannot convert media')
}
})
} | [
"function",
"toBase64",
"(",
"media",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"isBase64",
"(",
"media",
")",
")",
"{",
"resolve",
"(",
"media",
")",
"}",
"else",
"if",
"(",
"isURL",
"(",
"media",
")",
")",
"{",
"urlToBase64",
"(",
"media",
")",
".",
"then",
"(",
"data",
"=>",
"resolve",
"(",
"data",
")",
")",
".",
"catch",
"(",
"error",
"=>",
"reject",
"(",
"error",
")",
")",
"}",
"else",
"if",
"(",
"isFile",
"(",
"media",
")",
")",
"{",
"fileToBase64",
"(",
"media",
")",
".",
"then",
"(",
"data",
"=>",
"resolve",
"(",
"data",
")",
")",
".",
"catch",
"(",
"error",
"=>",
"reject",
"(",
"error",
")",
")",
"}",
"else",
"if",
"(",
"isBuffer",
"(",
"media",
")",
")",
"{",
"const",
"base64",
"=",
"media",
".",
"toString",
"(",
"'base64'",
")",
"resolve",
"(",
"base64",
")",
"}",
"else",
"{",
"reject",
"(",
"'Error: toBase64(): cannot convert media'",
")",
"}",
"}",
")",
"}"
] | Reads an image from file or url and convert it to base64
@param {string} media - url or path
@returns {Promise} | [
"Reads",
"an",
"image",
"from",
"file",
"or",
"url",
"and",
"convert",
"it",
"to",
"base64"
] | af032cd54fca424f06c26c8a6110f7f0bfe0fc1b | https://github.com/soixantecircuits/media-helper/blob/af032cd54fca424f06c26c8a6110f7f0bfe0fc1b/media-helper.js#L152-L171 |
54,146 | soixantecircuits/media-helper | media-helper.js | toBuffer | function toBuffer (media) {
return new Promise((resolve, reject) => {
if (isURL(media)) {
toBase64(media)
.then(data => {
toBuffer(data)
.then(data => resolve(data))
.catch(error => reject(error))
})
.catch(error => reject(error))
} else if (isBase64(media)) {
try {
resolve(Buffer.from(media))
} catch (ex) {
reject(ex)
}
} else if (isFile(media)) {
fs.readFile(media, (err, data) => {
err && reject(err)
resolve(data)
})
} else {
reject('Error: toBuffer(): argument must be file, url or file')
}
})
} | javascript | function toBuffer (media) {
return new Promise((resolve, reject) => {
if (isURL(media)) {
toBase64(media)
.then(data => {
toBuffer(data)
.then(data => resolve(data))
.catch(error => reject(error))
})
.catch(error => reject(error))
} else if (isBase64(media)) {
try {
resolve(Buffer.from(media))
} catch (ex) {
reject(ex)
}
} else if (isFile(media)) {
fs.readFile(media, (err, data) => {
err && reject(err)
resolve(data)
})
} else {
reject('Error: toBuffer(): argument must be file, url or file')
}
})
} | [
"function",
"toBuffer",
"(",
"media",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"isURL",
"(",
"media",
")",
")",
"{",
"toBase64",
"(",
"media",
")",
".",
"then",
"(",
"data",
"=>",
"{",
"toBuffer",
"(",
"data",
")",
".",
"then",
"(",
"data",
"=>",
"resolve",
"(",
"data",
")",
")",
".",
"catch",
"(",
"error",
"=>",
"reject",
"(",
"error",
")",
")",
"}",
")",
".",
"catch",
"(",
"error",
"=>",
"reject",
"(",
"error",
")",
")",
"}",
"else",
"if",
"(",
"isBase64",
"(",
"media",
")",
")",
"{",
"try",
"{",
"resolve",
"(",
"Buffer",
".",
"from",
"(",
"media",
")",
")",
"}",
"catch",
"(",
"ex",
")",
"{",
"reject",
"(",
"ex",
")",
"}",
"}",
"else",
"if",
"(",
"isFile",
"(",
"media",
")",
")",
"{",
"fs",
".",
"readFile",
"(",
"media",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"err",
"&&",
"reject",
"(",
"err",
")",
"resolve",
"(",
"data",
")",
"}",
")",
"}",
"else",
"{",
"reject",
"(",
"'Error: toBuffer(): argument must be file, url or file'",
")",
"}",
"}",
")",
"}"
] | Reads an image from file or url and convert it to Buffer
@param {media} media - file, url or path
@returns {Promise} | [
"Reads",
"an",
"image",
"from",
"file",
"or",
"url",
"and",
"convert",
"it",
"to",
"Buffer"
] | af032cd54fca424f06c26c8a6110f7f0bfe0fc1b | https://github.com/soixantecircuits/media-helper/blob/af032cd54fca424f06c26c8a6110f7f0bfe0fc1b/media-helper.js#L188-L213 |
54,147 | chrishayesmu/DubBotBase | src/translator.js | translateDateTimestamp | function translateDateTimestamp(timestamp) {
if (!timestamp) {
LOG.warn("Received an invalid timestamp: {}", timestamp);
return Date.now();
}
return new Date(timestamp);
} | javascript | function translateDateTimestamp(timestamp) {
if (!timestamp) {
LOG.warn("Received an invalid timestamp: {}", timestamp);
return Date.now();
}
return new Date(timestamp);
} | [
"function",
"translateDateTimestamp",
"(",
"timestamp",
")",
"{",
"if",
"(",
"!",
"timestamp",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Received an invalid timestamp: {}\"",
",",
"timestamp",
")",
";",
"return",
"Date",
".",
"now",
"(",
")",
";",
"}",
"return",
"new",
"Date",
"(",
"timestamp",
")",
";",
"}"
] | Translates a date string from Dubtrack into a Javascript date.
@param {integer} timestamp - A timestamp from DubAPI
@returns {integer} The UNIX timestamp represented by the string,
or the current time if string is null/empty | [
"Translates",
"a",
"date",
"string",
"from",
"Dubtrack",
"into",
"a",
"Javascript",
"date",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/translator.js#L25-L32 |
54,148 | chrishayesmu/DubBotBase | src/translator.js | translateRole | function translateRole(role) {
switch (role) {
case "5615fa9ae596154a5c000000":
return Types.UserRole.COOWNER;
case "5615fd84e596150061000003":
return Types.UserRole.MANAGER;
case "52d1ce33c38a06510c000001":
return Types.UserRole.MOD;
case "5615fe1ee596154fc2000001":
return Types.UserRole.VIP;
case "5615feb8e596154fc2000002":
return Types.UserRole.RESIDENT_DJ;
case "564435423f6ba174d2000001":
return Types.UserRole.DJ;
default:
return Types.UserRole.NONE;
}
} | javascript | function translateRole(role) {
switch (role) {
case "5615fa9ae596154a5c000000":
return Types.UserRole.COOWNER;
case "5615fd84e596150061000003":
return Types.UserRole.MANAGER;
case "52d1ce33c38a06510c000001":
return Types.UserRole.MOD;
case "5615fe1ee596154fc2000001":
return Types.UserRole.VIP;
case "5615feb8e596154fc2000002":
return Types.UserRole.RESIDENT_DJ;
case "564435423f6ba174d2000001":
return Types.UserRole.DJ;
default:
return Types.UserRole.NONE;
}
} | [
"function",
"translateRole",
"(",
"role",
")",
"{",
"switch",
"(",
"role",
")",
"{",
"case",
"\"5615fa9ae596154a5c000000\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"COOWNER",
";",
"case",
"\"5615fd84e596150061000003\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"MANAGER",
";",
"case",
"\"52d1ce33c38a06510c000001\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"MOD",
";",
"case",
"\"5615fe1ee596154fc2000001\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"VIP",
";",
"case",
"\"5615feb8e596154fc2000002\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"RESIDENT_DJ",
";",
"case",
"\"564435423f6ba174d2000001\"",
":",
"return",
"Types",
".",
"UserRole",
".",
"DJ",
";",
"default",
":",
"return",
"Types",
".",
"UserRole",
".",
"NONE",
";",
"}",
"}"
] | Translates the role integer returned by the dubtrack.fm API into an internal model.
@param {integer} roleAsInt - The dubtrack.fm API role
@returns {object} A corresponding object from the UserRole enum | [
"Translates",
"the",
"role",
"integer",
"returned",
"by",
"the",
"dubtrack",
".",
"fm",
"API",
"into",
"an",
"internal",
"model",
"."
] | 0e4b5e65531c23293d22ac766850c802b1266e48 | https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/src/translator.js#L216-L233 |
54,149 | NumminorihSF/bramqp-wrapper | domain/basic.js | Basic | function Basic(client, channel, done){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
this.publishCallbackMethod = DEFAULT_PUBLISH_ANSWER_WAIT_MECHANISM;
this.timeout = DEFAULT_WAIT_TIMEOUT;
this.lastConfirmSendId = 1;
this.lastMessageId = 1;
this.done = done;
this.lastError = null;
return this;
} | javascript | function Basic(client, channel, done){
EE.call(this);
this.client = client;
this.channel = channel;
this.id = channel.$getId();
this.publishCallbackMethod = DEFAULT_PUBLISH_ANSWER_WAIT_MECHANISM;
this.timeout = DEFAULT_WAIT_TIMEOUT;
this.lastConfirmSendId = 1;
this.lastMessageId = 1;
this.done = done;
this.lastError = null;
return this;
} | [
"function",
"Basic",
"(",
"client",
",",
"channel",
",",
"done",
")",
"{",
"EE",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"client",
"=",
"client",
";",
"this",
".",
"channel",
"=",
"channel",
";",
"this",
".",
"id",
"=",
"channel",
".",
"$getId",
"(",
")",
";",
"this",
".",
"publishCallbackMethod",
"=",
"DEFAULT_PUBLISH_ANSWER_WAIT_MECHANISM",
";",
"this",
".",
"timeout",
"=",
"DEFAULT_WAIT_TIMEOUT",
";",
"this",
".",
"lastConfirmSendId",
"=",
"1",
";",
"this",
".",
"lastMessageId",
"=",
"1",
";",
"this",
".",
"done",
"=",
"done",
";",
"this",
".",
"lastError",
"=",
"null",
";",
"return",
"this",
";",
"}"
] | Work with basic content.
The Basic class provides methods that support an industry-standard messaging model. Work with channels.
@class Basic
@extends EventEmitter
@param {BRAMQPClient} client Client object that returns from bramqp#openAMQPCommunication() method.
@param {Channel} channel Channel object (should be opened).
@param {Function} done
@return {Basic}
@constructor | [
"Work",
"with",
"basic",
"content",
"."
] | 3e2bd769a2828f7592eba79556c9ef1491177781 | https://github.com/NumminorihSF/bramqp-wrapper/blob/3e2bd769a2828f7592eba79556c9ef1491177781/domain/basic.js#L35-L50 |
54,150 | ironboy/warp-core | include-common-imports.js | getJSFiles | function getJSFiles(folder = srcFolder){
let all = [];
let f = fs.readdirSync(folder);
for(file of f){
all.push(path.join(folder,file))
if(fs.lstatSync(path.join(folder,file)).isDirectory()){
all = all.concat(getJSFiles(path.join(folder,file)));
}
}
return all.filter(x => x.endsWith('.js'));
} | javascript | function getJSFiles(folder = srcFolder){
let all = [];
let f = fs.readdirSync(folder);
for(file of f){
all.push(path.join(folder,file))
if(fs.lstatSync(path.join(folder,file)).isDirectory()){
all = all.concat(getJSFiles(path.join(folder,file)));
}
}
return all.filter(x => x.endsWith('.js'));
} | [
"function",
"getJSFiles",
"(",
"folder",
"=",
"srcFolder",
")",
"{",
"let",
"all",
"=",
"[",
"]",
";",
"let",
"f",
"=",
"fs",
".",
"readdirSync",
"(",
"folder",
")",
";",
"for",
"(",
"file",
"of",
"f",
")",
"{",
"all",
".",
"push",
"(",
"path",
".",
"join",
"(",
"folder",
",",
"file",
")",
")",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"path",
".",
"join",
"(",
"folder",
",",
"file",
")",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"all",
"=",
"all",
".",
"concat",
"(",
"getJSFiles",
"(",
"path",
".",
"join",
"(",
"folder",
",",
"file",
")",
")",
")",
";",
"}",
"}",
"return",
"all",
".",
"filter",
"(",
"x",
"=>",
"x",
".",
"endsWith",
"(",
"'.js'",
")",
")",
";",
"}"
] | get all js file paths in a folder recursively | [
"get",
"all",
"js",
"file",
"paths",
"in",
"a",
"folder",
"recursively"
] | 0e3556e41e40cdfc0dafdfd4d9e02662010e9379 | https://github.com/ironboy/warp-core/blob/0e3556e41e40cdfc0dafdfd4d9e02662010e9379/include-common-imports.js#L74-L84 |
54,151 | camshaft/reference-count | index.js | Sweep | function Sweep(actor, context) {
this.actor = actor;
this.context = context;
this.prev = context.actors[actor] || {};
this.resources = context.actors[actor] = {};
} | javascript | function Sweep(actor, context) {
this.actor = actor;
this.context = context;
this.prev = context.actors[actor] || {};
this.resources = context.actors[actor] = {};
} | [
"function",
"Sweep",
"(",
"actor",
",",
"context",
")",
"{",
"this",
".",
"actor",
"=",
"actor",
";",
"this",
".",
"context",
"=",
"context",
";",
"this",
".",
"prev",
"=",
"context",
".",
"actors",
"[",
"actor",
"]",
"||",
"{",
"}",
";",
"this",
".",
"resources",
"=",
"context",
".",
"actors",
"[",
"actor",
"]",
"=",
"{",
"}",
";",
"}"
] | Create a sweep instance
@param {String} actor
@param {Object} prev
@param {Context} context | [
"Create",
"a",
"sweep",
"instance"
] | b08bd3c676af742584e3f0101100f8fad6e33ba3 | https://github.com/camshaft/reference-count/blob/b08bd3c676af742584e3f0101100f8fad6e33ba3/index.js#L54-L59 |
54,152 | iolo/express-toybox | session.js | session | function session(options) {
options = options || {};
DEBUG && debug('configure http session middleware', options);
if (options.store) {
try {
var storeModule = options.store.module;
var SessionStore = require(storeModule)(express);
// replace store options with store object
options.store = new SessionStore(options.store.options);
return expressSession(options);
} catch (e) {
console.error('failed to configure http session store', e);
//process.exit(1);
}
}
console.warn('**fallback** use default session middleware');
return expressSession(options);
} | javascript | function session(options) {
options = options || {};
DEBUG && debug('configure http session middleware', options);
if (options.store) {
try {
var storeModule = options.store.module;
var SessionStore = require(storeModule)(express);
// replace store options with store object
options.store = new SessionStore(options.store.options);
return expressSession(options);
} catch (e) {
console.error('failed to configure http session store', e);
//process.exit(1);
}
}
console.warn('**fallback** use default session middleware');
return expressSession(options);
} | [
"function",
"session",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"DEBUG",
"&&",
"debug",
"(",
"'configure http session middleware'",
",",
"options",
")",
";",
"if",
"(",
"options",
".",
"store",
")",
"{",
"try",
"{",
"var",
"storeModule",
"=",
"options",
".",
"store",
".",
"module",
";",
"var",
"SessionStore",
"=",
"require",
"(",
"storeModule",
")",
"(",
"express",
")",
";",
"// replace store options with store object",
"options",
".",
"store",
"=",
"new",
"SessionStore",
"(",
"options",
".",
"store",
".",
"options",
")",
";",
"return",
"expressSession",
"(",
"options",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'failed to configure http session store'",
",",
"e",
")",
";",
"//process.exit(1);",
"}",
"}",
"console",
".",
"warn",
"(",
"'**fallback** use default session middleware'",
")",
";",
"return",
"expressSession",
"(",
"options",
")",
";",
"}"
] | session middleware.
@param {*} [options]
@param {*} [options.store]
@param {String} [options.store.module]
@param {*} [options.store.options] store specific options
@returns {function} connect/express middleware function
@see https://github.com/expressjs/session | [
"session",
"middleware",
"."
] | c375a1388cfc167017e8dcd2325e71ca86ccb994 | https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/session.js#L20-L37 |
54,153 | zenparsing/moon-unit | build/moon-unit.js | forEachDesc | function forEachDesc(obj, fn) {
var names = Object.getOwnPropertyNames(obj);
for (var i$0 = 0; i$0 < names.length; ++i$0)
fn(names[i$0], Object.getOwnPropertyDescriptor(obj, names[i$0]));
names = Object.getOwnPropertySymbols(obj);
for (var i$1 = 0; i$1 < names.length; ++i$1)
fn(names[i$1], Object.getOwnPropertyDescriptor(obj, names[i$1]));
return obj;
} | javascript | function forEachDesc(obj, fn) {
var names = Object.getOwnPropertyNames(obj);
for (var i$0 = 0; i$0 < names.length; ++i$0)
fn(names[i$0], Object.getOwnPropertyDescriptor(obj, names[i$0]));
names = Object.getOwnPropertySymbols(obj);
for (var i$1 = 0; i$1 < names.length; ++i$1)
fn(names[i$1], Object.getOwnPropertyDescriptor(obj, names[i$1]));
return obj;
} | [
"function",
"forEachDesc",
"(",
"obj",
",",
"fn",
")",
"{",
"var",
"names",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"obj",
")",
";",
"for",
"(",
"var",
"i$0",
"=",
"0",
";",
"i$0",
"<",
"names",
".",
"length",
";",
"++",
"i$0",
")",
"fn",
"(",
"names",
"[",
"i$0",
"]",
",",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj",
",",
"names",
"[",
"i$0",
"]",
")",
")",
";",
"names",
"=",
"Object",
".",
"getOwnPropertySymbols",
"(",
"obj",
")",
";",
"for",
"(",
"var",
"i$1",
"=",
"0",
";",
"i$1",
"<",
"names",
".",
"length",
";",
"++",
"i$1",
")",
"fn",
"(",
"names",
"[",
"i$1",
"]",
",",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj",
",",
"names",
"[",
"i$1",
"]",
")",
")",
";",
"return",
"obj",
";",
"}"
] | Iterates over the descriptors for each own property of an object | [
"Iterates",
"over",
"the",
"descriptors",
"for",
"each",
"own",
"property",
"of",
"an",
"object"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L22-L35 |
54,154 | zenparsing/moon-unit | build/moon-unit.js | mergeProperty | function mergeProperty(target, name, desc, enumerable) {
if (desc.get || desc.set) {
var d$0 = { configurable: true };
if (desc.get) d$0.get = desc.get;
if (desc.set) d$0.set = desc.set;
desc = d$0;
}
desc.enumerable = enumerable;
Object.defineProperty(target, name, desc);
} | javascript | function mergeProperty(target, name, desc, enumerable) {
if (desc.get || desc.set) {
var d$0 = { configurable: true };
if (desc.get) d$0.get = desc.get;
if (desc.set) d$0.set = desc.set;
desc = d$0;
}
desc.enumerable = enumerable;
Object.defineProperty(target, name, desc);
} | [
"function",
"mergeProperty",
"(",
"target",
",",
"name",
",",
"desc",
",",
"enumerable",
")",
"{",
"if",
"(",
"desc",
".",
"get",
"||",
"desc",
".",
"set",
")",
"{",
"var",
"d$0",
"=",
"{",
"configurable",
":",
"true",
"}",
";",
"if",
"(",
"desc",
".",
"get",
")",
"d$0",
".",
"get",
"=",
"desc",
".",
"get",
";",
"if",
"(",
"desc",
".",
"set",
")",
"d$0",
".",
"set",
"=",
"desc",
".",
"set",
";",
"desc",
"=",
"d$0",
";",
"}",
"desc",
".",
"enumerable",
"=",
"enumerable",
";",
"Object",
".",
"defineProperty",
"(",
"target",
",",
"name",
",",
"desc",
")",
";",
"}"
] | Installs a property into an object, merging "get" and "set" functions | [
"Installs",
"a",
"property",
"into",
"an",
"object",
"merging",
"get",
"and",
"set",
"functions"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L38-L50 |
54,155 | zenparsing/moon-unit | build/moon-unit.js | mergeProperties | function mergeProperties(target, source, enumerable) {
forEachDesc(source, function(name, desc) { return mergeProperty(target, name, desc, enumerable); });
} | javascript | function mergeProperties(target, source, enumerable) {
forEachDesc(source, function(name, desc) { return mergeProperty(target, name, desc, enumerable); });
} | [
"function",
"mergeProperties",
"(",
"target",
",",
"source",
",",
"enumerable",
")",
"{",
"forEachDesc",
"(",
"source",
",",
"function",
"(",
"name",
",",
"desc",
")",
"{",
"return",
"mergeProperty",
"(",
"target",
",",
"name",
",",
"desc",
",",
"enumerable",
")",
";",
"}",
")",
";",
"}"
] | Installs properties on an object, merging "get" and "set" functions | [
"Installs",
"properties",
"on",
"an",
"object",
"merging",
"get",
"and",
"set",
"functions"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L53-L56 |
54,156 | zenparsing/moon-unit | build/moon-unit.js | buildClass | function buildClass(base, def) {
var parent;
if (def === void 0) {
// If no base class is specified, then Object.prototype
// is the parent prototype
def = base;
base = null;
parent = Object.prototype;
} else if (base === null) {
// If the base is null, then then then the parent prototype is null
parent = null;
} else if (typeof base === "function") {
parent = base.prototype;
// Prototype must be null or an object
if (parent !== null && Object(parent) !== parent)
parent = void 0;
}
if (parent === void 0)
throw new TypeError;
// Create the prototype object
var proto = Object.create(parent),
statics = {};
function __(target, obj) {
if (!obj) mergeProperties(proto, target, false);
else mergeProperties(target, obj, false);
}
__.static = function(obj) { return mergeProperties(statics, obj, false); };
__.super = parent;
__.csuper = base || Function.prototype;
// Generate method collections, closing over super bindings
def(__);
var ctor = proto.constructor;
// Set constructor's prototype
ctor.prototype = proto;
// Set class "static" methods
forEachDesc(statics, function(name, desc) { return Object.defineProperty(ctor, name, desc); });
// Inherit from base constructor
if (base && ctor.__proto__)
Object.setPrototypeOf(ctor, base);
return ctor;
} | javascript | function buildClass(base, def) {
var parent;
if (def === void 0) {
// If no base class is specified, then Object.prototype
// is the parent prototype
def = base;
base = null;
parent = Object.prototype;
} else if (base === null) {
// If the base is null, then then then the parent prototype is null
parent = null;
} else if (typeof base === "function") {
parent = base.prototype;
// Prototype must be null or an object
if (parent !== null && Object(parent) !== parent)
parent = void 0;
}
if (parent === void 0)
throw new TypeError;
// Create the prototype object
var proto = Object.create(parent),
statics = {};
function __(target, obj) {
if (!obj) mergeProperties(proto, target, false);
else mergeProperties(target, obj, false);
}
__.static = function(obj) { return mergeProperties(statics, obj, false); };
__.super = parent;
__.csuper = base || Function.prototype;
// Generate method collections, closing over super bindings
def(__);
var ctor = proto.constructor;
// Set constructor's prototype
ctor.prototype = proto;
// Set class "static" methods
forEachDesc(statics, function(name, desc) { return Object.defineProperty(ctor, name, desc); });
// Inherit from base constructor
if (base && ctor.__proto__)
Object.setPrototypeOf(ctor, base);
return ctor;
} | [
"function",
"buildClass",
"(",
"base",
",",
"def",
")",
"{",
"var",
"parent",
";",
"if",
"(",
"def",
"===",
"void",
"0",
")",
"{",
"// If no base class is specified, then Object.prototype",
"// is the parent prototype",
"def",
"=",
"base",
";",
"base",
"=",
"null",
";",
"parent",
"=",
"Object",
".",
"prototype",
";",
"}",
"else",
"if",
"(",
"base",
"===",
"null",
")",
"{",
"// If the base is null, then then then the parent prototype is null",
"parent",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"typeof",
"base",
"===",
"\"function\"",
")",
"{",
"parent",
"=",
"base",
".",
"prototype",
";",
"// Prototype must be null or an object",
"if",
"(",
"parent",
"!==",
"null",
"&&",
"Object",
"(",
"parent",
")",
"!==",
"parent",
")",
"parent",
"=",
"void",
"0",
";",
"}",
"if",
"(",
"parent",
"===",
"void",
"0",
")",
"throw",
"new",
"TypeError",
";",
"// Create the prototype object",
"var",
"proto",
"=",
"Object",
".",
"create",
"(",
"parent",
")",
",",
"statics",
"=",
"{",
"}",
";",
"function",
"__",
"(",
"target",
",",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"mergeProperties",
"(",
"proto",
",",
"target",
",",
"false",
")",
";",
"else",
"mergeProperties",
"(",
"target",
",",
"obj",
",",
"false",
")",
";",
"}",
"__",
".",
"static",
"=",
"function",
"(",
"obj",
")",
"{",
"return",
"mergeProperties",
"(",
"statics",
",",
"obj",
",",
"false",
")",
";",
"}",
";",
"__",
".",
"super",
"=",
"parent",
";",
"__",
".",
"csuper",
"=",
"base",
"||",
"Function",
".",
"prototype",
";",
"// Generate method collections, closing over super bindings",
"def",
"(",
"__",
")",
";",
"var",
"ctor",
"=",
"proto",
".",
"constructor",
";",
"// Set constructor's prototype",
"ctor",
".",
"prototype",
"=",
"proto",
";",
"// Set class \"static\" methods",
"forEachDesc",
"(",
"statics",
",",
"function",
"(",
"name",
",",
"desc",
")",
"{",
"return",
"Object",
".",
"defineProperty",
"(",
"ctor",
",",
"name",
",",
"desc",
")",
";",
"}",
")",
";",
"// Inherit from base constructor",
"if",
"(",
"base",
"&&",
"ctor",
".",
"__proto__",
")",
"Object",
".",
"setPrototypeOf",
"(",
"ctor",
",",
"base",
")",
";",
"return",
"ctor",
";",
"}"
] | Builds a class | [
"Builds",
"a",
"class"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L59-L118 |
54,157 | zenparsing/moon-unit | build/moon-unit.js | function(target) {
for (var i$2 = 1; i$2 < arguments.length; i$2 += 3) {
var desc$0 = Object.getOwnPropertyDescriptor(arguments[i$2 + 1], "_");
mergeProperty(target, arguments[i$2], desc$0, true);
if (i$2 + 2 < arguments.length)
mergeProperties(target, arguments[i$2 + 2], true);
}
return target;
} | javascript | function(target) {
for (var i$2 = 1; i$2 < arguments.length; i$2 += 3) {
var desc$0 = Object.getOwnPropertyDescriptor(arguments[i$2 + 1], "_");
mergeProperty(target, arguments[i$2], desc$0, true);
if (i$2 + 2 < arguments.length)
mergeProperties(target, arguments[i$2 + 2], true);
}
return target;
} | [
"function",
"(",
"target",
")",
"{",
"for",
"(",
"var",
"i$2",
"=",
"1",
";",
"i$2",
"<",
"arguments",
".",
"length",
";",
"i$2",
"+=",
"3",
")",
"{",
"var",
"desc$0",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"arguments",
"[",
"i$2",
"+",
"1",
"]",
",",
"\"_\"",
")",
";",
"mergeProperty",
"(",
"target",
",",
"arguments",
"[",
"i$2",
"]",
",",
"desc$0",
",",
"true",
")",
";",
"if",
"(",
"i$2",
"+",
"2",
"<",
"arguments",
".",
"length",
")",
"mergeProperties",
"(",
"target",
",",
"arguments",
"[",
"i$2",
"+",
"2",
"]",
",",
"true",
")",
";",
"}",
"return",
"target",
";",
"}"
] | Support for computed property names | [
"Support",
"for",
"computed",
"property",
"names"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L130-L142 |
|
54,158 | zenparsing/moon-unit | build/moon-unit.js | function(iter) {
var front = null, back = null;
return _esdown.computed({
next: function(val) { return send("next", val) },
throw: function(val) { return send("throw", val) },
return: function(val) { return send("return", val) },
}, Symbol.asyncIterator, { _: function() { return this },
});
function send(type, value) {
return new Promise(function(resolve, reject) {
var x = { type: type, value: value, resolve: resolve, reject: reject, next: null };
if (back) {
// If list is not empty, then push onto the end
back = back.next = x;
} else {
// Create new list and resume generator
front = back = x;
resume(type, value);
}
});
}
function fulfill(type, value) {
switch (type) {
case "return":
front.resolve({ value: value, done: true });
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({ value: value, done: false });
break;
}
front = front.next;
if (front) resume(front.type, front.value);
else back = null;
}
function awaitValue(result) {
var value = result.value;
if (typeof value === "object" && "_esdown_await" in value) {
if (result.done)
throw new Error("Invalid async generator return");
return value._esdown_await;
}
return null;
}
function resume(type, value) {
// HACK: If the generator does not support the "return" method, then
// emulate it (poorly) using throw. (V8 circa 2015-02-13 does not support
// generator.return.)
if (type === "return" && !(type in iter)) {
type = "throw";
value = { value: value, __return: true };
}
try {
var result$1 = iter[type](value),
awaited$0 = awaitValue(result$1);
if (awaited$0) {
Promise.resolve(awaited$0).then(
function(x) { return resume("next", x); },
function(x) { return resume("throw", x); });
} else {
Promise.resolve(result$1.value).then(
function(x) { return fulfill(result$1.done ? "return" : "normal", x); },
function(x) { return fulfill("throw", x); });
}
} catch (x) {
// HACK: Return-as-throw
if (x && x.__return === true)
return fulfill("return", x.value);
fulfill("throw", x);
}
}
} | javascript | function(iter) {
var front = null, back = null;
return _esdown.computed({
next: function(val) { return send("next", val) },
throw: function(val) { return send("throw", val) },
return: function(val) { return send("return", val) },
}, Symbol.asyncIterator, { _: function() { return this },
});
function send(type, value) {
return new Promise(function(resolve, reject) {
var x = { type: type, value: value, resolve: resolve, reject: reject, next: null };
if (back) {
// If list is not empty, then push onto the end
back = back.next = x;
} else {
// Create new list and resume generator
front = back = x;
resume(type, value);
}
});
}
function fulfill(type, value) {
switch (type) {
case "return":
front.resolve({ value: value, done: true });
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({ value: value, done: false });
break;
}
front = front.next;
if (front) resume(front.type, front.value);
else back = null;
}
function awaitValue(result) {
var value = result.value;
if (typeof value === "object" && "_esdown_await" in value) {
if (result.done)
throw new Error("Invalid async generator return");
return value._esdown_await;
}
return null;
}
function resume(type, value) {
// HACK: If the generator does not support the "return" method, then
// emulate it (poorly) using throw. (V8 circa 2015-02-13 does not support
// generator.return.)
if (type === "return" && !(type in iter)) {
type = "throw";
value = { value: value, __return: true };
}
try {
var result$1 = iter[type](value),
awaited$0 = awaitValue(result$1);
if (awaited$0) {
Promise.resolve(awaited$0).then(
function(x) { return resume("next", x); },
function(x) { return resume("throw", x); });
} else {
Promise.resolve(result$1.value).then(
function(x) { return fulfill(result$1.done ? "return" : "normal", x); },
function(x) { return fulfill("throw", x); });
}
} catch (x) {
// HACK: Return-as-throw
if (x && x.__return === true)
return fulfill("return", x.value);
fulfill("throw", x);
}
}
} | [
"function",
"(",
"iter",
")",
"{",
"var",
"front",
"=",
"null",
",",
"back",
"=",
"null",
";",
"return",
"_esdown",
".",
"computed",
"(",
"{",
"next",
":",
"function",
"(",
"val",
")",
"{",
"return",
"send",
"(",
"\"next\"",
",",
"val",
")",
"}",
",",
"throw",
":",
"function",
"(",
"val",
")",
"{",
"return",
"send",
"(",
"\"throw\"",
",",
"val",
")",
"}",
",",
"return",
":",
"function",
"(",
"val",
")",
"{",
"return",
"send",
"(",
"\"return\"",
",",
"val",
")",
"}",
",",
"}",
",",
"Symbol",
".",
"asyncIterator",
",",
"{",
"_",
":",
"function",
"(",
")",
"{",
"return",
"this",
"}",
",",
"}",
")",
";",
"function",
"send",
"(",
"type",
",",
"value",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"x",
"=",
"{",
"type",
":",
"type",
",",
"value",
":",
"value",
",",
"resolve",
":",
"resolve",
",",
"reject",
":",
"reject",
",",
"next",
":",
"null",
"}",
";",
"if",
"(",
"back",
")",
"{",
"// If list is not empty, then push onto the end",
"back",
"=",
"back",
".",
"next",
"=",
"x",
";",
"}",
"else",
"{",
"// Create new list and resume generator",
"front",
"=",
"back",
"=",
"x",
";",
"resume",
"(",
"type",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"}",
"function",
"fulfill",
"(",
"type",
",",
"value",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"\"return\"",
":",
"front",
".",
"resolve",
"(",
"{",
"value",
":",
"value",
",",
"done",
":",
"true",
"}",
")",
";",
"break",
";",
"case",
"\"throw\"",
":",
"front",
".",
"reject",
"(",
"value",
")",
";",
"break",
";",
"default",
":",
"front",
".",
"resolve",
"(",
"{",
"value",
":",
"value",
",",
"done",
":",
"false",
"}",
")",
";",
"break",
";",
"}",
"front",
"=",
"front",
".",
"next",
";",
"if",
"(",
"front",
")",
"resume",
"(",
"front",
".",
"type",
",",
"front",
".",
"value",
")",
";",
"else",
"back",
"=",
"null",
";",
"}",
"function",
"awaitValue",
"(",
"result",
")",
"{",
"var",
"value",
"=",
"result",
".",
"value",
";",
"if",
"(",
"typeof",
"value",
"===",
"\"object\"",
"&&",
"\"_esdown_await\"",
"in",
"value",
")",
"{",
"if",
"(",
"result",
".",
"done",
")",
"throw",
"new",
"Error",
"(",
"\"Invalid async generator return\"",
")",
";",
"return",
"value",
".",
"_esdown_await",
";",
"}",
"return",
"null",
";",
"}",
"function",
"resume",
"(",
"type",
",",
"value",
")",
"{",
"// HACK: If the generator does not support the \"return\" method, then",
"// emulate it (poorly) using throw. (V8 circa 2015-02-13 does not support",
"// generator.return.)",
"if",
"(",
"type",
"===",
"\"return\"",
"&&",
"!",
"(",
"type",
"in",
"iter",
")",
")",
"{",
"type",
"=",
"\"throw\"",
";",
"value",
"=",
"{",
"value",
":",
"value",
",",
"__return",
":",
"true",
"}",
";",
"}",
"try",
"{",
"var",
"result$1",
"=",
"iter",
"[",
"type",
"]",
"(",
"value",
")",
",",
"awaited$0",
"=",
"awaitValue",
"(",
"result$1",
")",
";",
"if",
"(",
"awaited$0",
")",
"{",
"Promise",
".",
"resolve",
"(",
"awaited$0",
")",
".",
"then",
"(",
"function",
"(",
"x",
")",
"{",
"return",
"resume",
"(",
"\"next\"",
",",
"x",
")",
";",
"}",
",",
"function",
"(",
"x",
")",
"{",
"return",
"resume",
"(",
"\"throw\"",
",",
"x",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"Promise",
".",
"resolve",
"(",
"result$1",
".",
"value",
")",
".",
"then",
"(",
"function",
"(",
"x",
")",
"{",
"return",
"fulfill",
"(",
"result$1",
".",
"done",
"?",
"\"return\"",
":",
"\"normal\"",
",",
"x",
")",
";",
"}",
",",
"function",
"(",
"x",
")",
"{",
"return",
"fulfill",
"(",
"\"throw\"",
",",
"x",
")",
";",
"}",
")",
";",
"}",
"}",
"catch",
"(",
"x",
")",
"{",
"// HACK: Return-as-throw",
"if",
"(",
"x",
"&&",
"x",
".",
"__return",
"===",
"true",
")",
"return",
"fulfill",
"(",
"\"return\"",
",",
"x",
".",
"value",
")",
";",
"fulfill",
"(",
"\"throw\"",
",",
"x",
")",
";",
"}",
"}",
"}"
] | Support for async generators | [
"Support",
"for",
"async",
"generators"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L181-L289 |
|
54,159 | zenparsing/moon-unit | build/moon-unit.js | function(initial) {
return {
a: initial || [],
// Add items
s: function() {
for (var i$3 = 0; i$3 < arguments.length; ++i$3)
this.a.push(arguments[i$3]);
return this;
},
// Add the contents of iterables
i: function(list) {
if (Array.isArray(list)) {
this.a.push.apply(this.a, list);
} else {
for (var __$0 = (list)[Symbol.iterator](), __$1; __$1 = __$0.next(), !__$1.done;)
{ var item$0 = __$1.value; this.a.push(item$0); }
}
return this;
}
};
} | javascript | function(initial) {
return {
a: initial || [],
// Add items
s: function() {
for (var i$3 = 0; i$3 < arguments.length; ++i$3)
this.a.push(arguments[i$3]);
return this;
},
// Add the contents of iterables
i: function(list) {
if (Array.isArray(list)) {
this.a.push.apply(this.a, list);
} else {
for (var __$0 = (list)[Symbol.iterator](), __$1; __$1 = __$0.next(), !__$1.done;)
{ var item$0 = __$1.value; this.a.push(item$0); }
}
return this;
}
};
} | [
"function",
"(",
"initial",
")",
"{",
"return",
"{",
"a",
":",
"initial",
"||",
"[",
"]",
",",
"// Add items",
"s",
":",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i$3",
"=",
"0",
";",
"i$3",
"<",
"arguments",
".",
"length",
";",
"++",
"i$3",
")",
"this",
".",
"a",
".",
"push",
"(",
"arguments",
"[",
"i$3",
"]",
")",
";",
"return",
"this",
";",
"}",
",",
"// Add the contents of iterables",
"i",
":",
"function",
"(",
"list",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"list",
")",
")",
"{",
"this",
".",
"a",
".",
"push",
".",
"apply",
"(",
"this",
".",
"a",
",",
"list",
")",
";",
"}",
"else",
"{",
"for",
"(",
"var",
"__$0",
"=",
"(",
"list",
")",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"__$1",
";",
"__$1",
"=",
"__$0",
".",
"next",
"(",
")",
",",
"!",
"__$1",
".",
"done",
";",
")",
"{",
"var",
"item$0",
"=",
"__$1",
".",
"value",
";",
"this",
".",
"a",
".",
"push",
"(",
"item$0",
")",
";",
"}",
"}",
"return",
"this",
";",
"}",
"}",
";",
"}"
] | Support for spread operations | [
"Support",
"for",
"spread",
"operations"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L292-L324 |
|
54,160 | zenparsing/moon-unit | build/moon-unit.js | function(list) {
if (Array.isArray(list)) {
this.a.push.apply(this.a, list);
} else {
for (var __$0 = (list)[Symbol.iterator](), __$1; __$1 = __$0.next(), !__$1.done;)
{ var item$0 = __$1.value; this.a.push(item$0); }
}
return this;
} | javascript | function(list) {
if (Array.isArray(list)) {
this.a.push.apply(this.a, list);
} else {
for (var __$0 = (list)[Symbol.iterator](), __$1; __$1 = __$0.next(), !__$1.done;)
{ var item$0 = __$1.value; this.a.push(item$0); }
}
return this;
} | [
"function",
"(",
"list",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"list",
")",
")",
"{",
"this",
".",
"a",
".",
"push",
".",
"apply",
"(",
"this",
".",
"a",
",",
"list",
")",
";",
"}",
"else",
"{",
"for",
"(",
"var",
"__$0",
"=",
"(",
"list",
")",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"__$1",
";",
"__$1",
"=",
"__$0",
".",
"next",
"(",
")",
",",
"!",
"__$1",
".",
"done",
";",
")",
"{",
"var",
"item$0",
"=",
"__$1",
".",
"value",
";",
"this",
".",
"a",
".",
"push",
"(",
"item$0",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Add the contents of iterables | [
"Add",
"the",
"contents",
"of",
"iterables"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L308-L321 |
|
54,161 | zenparsing/moon-unit | build/moon-unit.js | function(obj) {
if (Array.isArray(obj)) {
return {
at: function(skip, pos) { return obj[pos] },
rest: function(skip, pos) { return obj.slice(pos) }
};
}
var iter = toObject(obj)[Symbol.iterator]();
return {
at: function(skip) {
var r;
while (skip--)
r = iter.next();
return r.value;
},
rest: function(skip) {
var a = [], r;
while (--skip)
r = iter.next();
while (r = iter.next(), !r.done)
a.push(r.value);
return a;
}
};
} | javascript | function(obj) {
if (Array.isArray(obj)) {
return {
at: function(skip, pos) { return obj[pos] },
rest: function(skip, pos) { return obj.slice(pos) }
};
}
var iter = toObject(obj)[Symbol.iterator]();
return {
at: function(skip) {
var r;
while (skip--)
r = iter.next();
return r.value;
},
rest: function(skip) {
var a = [], r;
while (--skip)
r = iter.next();
while (r = iter.next(), !r.done)
a.push(r.value);
return a;
}
};
} | [
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"{",
"at",
":",
"function",
"(",
"skip",
",",
"pos",
")",
"{",
"return",
"obj",
"[",
"pos",
"]",
"}",
",",
"rest",
":",
"function",
"(",
"skip",
",",
"pos",
")",
"{",
"return",
"obj",
".",
"slice",
"(",
"pos",
")",
"}",
"}",
";",
"}",
"var",
"iter",
"=",
"toObject",
"(",
"obj",
")",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
";",
"return",
"{",
"at",
":",
"function",
"(",
"skip",
")",
"{",
"var",
"r",
";",
"while",
"(",
"skip",
"--",
")",
"r",
"=",
"iter",
".",
"next",
"(",
")",
";",
"return",
"r",
".",
"value",
";",
"}",
",",
"rest",
":",
"function",
"(",
"skip",
")",
"{",
"var",
"a",
"=",
"[",
"]",
",",
"r",
";",
"while",
"(",
"--",
"skip",
")",
"r",
"=",
"iter",
".",
"next",
"(",
")",
";",
"while",
"(",
"r",
"=",
"iter",
".",
"next",
"(",
")",
",",
"!",
"r",
".",
"done",
")",
"a",
".",
"push",
"(",
"r",
".",
"value",
")",
";",
"return",
"a",
";",
"}",
"}",
";",
"}"
] | Support for array destructuring | [
"Support",
"for",
"array",
"destructuring"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L333-L371 |
|
54,162 | zenparsing/moon-unit | build/moon-unit.js | function(obj, map, name) {
var entry = map.get(Object(obj));
if (!entry)
throw new TypeError;
return entry[name];
} | javascript | function(obj, map, name) {
var entry = map.get(Object(obj));
if (!entry)
throw new TypeError;
return entry[name];
} | [
"function",
"(",
"obj",
",",
"map",
",",
"name",
")",
"{",
"var",
"entry",
"=",
"map",
".",
"get",
"(",
"Object",
"(",
"obj",
")",
")",
";",
"if",
"(",
"!",
"entry",
")",
"throw",
"new",
"TypeError",
";",
"return",
"entry",
"[",
"name",
"]",
";",
"}"
] | Support for private fields | [
"Support",
"for",
"private",
"fields"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L374-L382 |
|
54,163 | zenparsing/moon-unit | build/moon-unit.js | getClass | function getClass(o) {
if (o === null || o === undefined) return "Object";
return OP_toString.call(o).slice("[object ".length, -1);
} | javascript | function getClass(o) {
if (o === null || o === undefined) return "Object";
return OP_toString.call(o).slice("[object ".length, -1);
} | [
"function",
"getClass",
"(",
"o",
")",
"{",
"if",
"(",
"o",
"===",
"null",
"||",
"o",
"===",
"undefined",
")",
"return",
"\"Object\"",
";",
"return",
"OP_toString",
".",
"call",
"(",
"o",
")",
".",
"slice",
"(",
"\"[object \"",
".",
"length",
",",
"-",
"1",
")",
";",
"}"
] | Returns the internal class of an object | [
"Returns",
"the",
"internal",
"class",
"of",
"an",
"object"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L409-L413 |
54,164 | zenparsing/moon-unit | build/moon-unit.js | equal | function equal(a, b) {
if (Object.is(a, b))
return true;
// Dates must have equal time values
if (isDate(a) && isDate(b))
return a.getTime() === b.getTime();
// Non-objects must be strictly equal (types must be equal)
if (!isObject(a) || !isObject(b))
return a === b;
// Prototypes must be identical. getPrototypeOf may throw on
// ES3 engines that don't provide access to the prototype.
try {
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
return false;
} catch (err) {}
var aKeys = Object.keys(a),
bKeys = Object.keys(b);
// Number of own properties must be identical
if (aKeys.length !== bKeys.length)
return false;
for (var i$0 = 0; i$0 < aKeys.length; ++i$0) {
// Names of own properties must be identical
if (!OP_hasOwnProperty.call(b, aKeys[i$0]))
return false;
// Values of own properties must be equal
if (!equal(a[aKeys[i$0]], b[aKeys[i$0]]))
return false;
}
return true;
} | javascript | function equal(a, b) {
if (Object.is(a, b))
return true;
// Dates must have equal time values
if (isDate(a) && isDate(b))
return a.getTime() === b.getTime();
// Non-objects must be strictly equal (types must be equal)
if (!isObject(a) || !isObject(b))
return a === b;
// Prototypes must be identical. getPrototypeOf may throw on
// ES3 engines that don't provide access to the prototype.
try {
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
return false;
} catch (err) {}
var aKeys = Object.keys(a),
bKeys = Object.keys(b);
// Number of own properties must be identical
if (aKeys.length !== bKeys.length)
return false;
for (var i$0 = 0; i$0 < aKeys.length; ++i$0) {
// Names of own properties must be identical
if (!OP_hasOwnProperty.call(b, aKeys[i$0]))
return false;
// Values of own properties must be equal
if (!equal(a[aKeys[i$0]], b[aKeys[i$0]]))
return false;
}
return true;
} | [
"function",
"equal",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"Object",
".",
"is",
"(",
"a",
",",
"b",
")",
")",
"return",
"true",
";",
"// Dates must have equal time values",
"if",
"(",
"isDate",
"(",
"a",
")",
"&&",
"isDate",
"(",
"b",
")",
")",
"return",
"a",
".",
"getTime",
"(",
")",
"===",
"b",
".",
"getTime",
"(",
")",
";",
"// Non-objects must be strictly equal (types must be equal)",
"if",
"(",
"!",
"isObject",
"(",
"a",
")",
"||",
"!",
"isObject",
"(",
"b",
")",
")",
"return",
"a",
"===",
"b",
";",
"// Prototypes must be identical. getPrototypeOf may throw on",
"// ES3 engines that don't provide access to the prototype.",
"try",
"{",
"if",
"(",
"Object",
".",
"getPrototypeOf",
"(",
"a",
")",
"!==",
"Object",
".",
"getPrototypeOf",
"(",
"b",
")",
")",
"return",
"false",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"}",
"var",
"aKeys",
"=",
"Object",
".",
"keys",
"(",
"a",
")",
",",
"bKeys",
"=",
"Object",
".",
"keys",
"(",
"b",
")",
";",
"// Number of own properties must be identical",
"if",
"(",
"aKeys",
".",
"length",
"!==",
"bKeys",
".",
"length",
")",
"return",
"false",
";",
"for",
"(",
"var",
"i$0",
"=",
"0",
";",
"i$0",
"<",
"aKeys",
".",
"length",
";",
"++",
"i$0",
")",
"{",
"// Names of own properties must be identical",
"if",
"(",
"!",
"OP_hasOwnProperty",
".",
"call",
"(",
"b",
",",
"aKeys",
"[",
"i$0",
"]",
")",
")",
"return",
"false",
";",
"// Values of own properties must be equal",
"if",
"(",
"!",
"equal",
"(",
"a",
"[",
"aKeys",
"[",
"i$0",
"]",
"]",
",",
"b",
"[",
"aKeys",
"[",
"i$0",
"]",
"]",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true if the arguments are "equal" | [
"Returns",
"true",
"if",
"the",
"arguments",
"are",
"equal"
] | 5fbe6805e3d382a0ce9e2913da65613ec33b19cb | https://github.com/zenparsing/moon-unit/blob/5fbe6805e3d382a0ce9e2913da65613ec33b19cb/build/moon-unit.js#L428-L469 |
54,165 | davidmarkclements/seneca-scheduler | lib/scheduler.js | punch | function punch(date) {
Object.defineProperty(date, '_isValid', {
get: function() {
return this.toDate() !== this.lang().invalidDate()
}
});
return date;
} | javascript | function punch(date) {
Object.defineProperty(date, '_isValid', {
get: function() {
return this.toDate() !== this.lang().invalidDate()
}
});
return date;
} | [
"function",
"punch",
"(",
"date",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"date",
",",
"'_isValid'",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"toDate",
"(",
")",
"!==",
"this",
".",
"lang",
"(",
")",
".",
"invalidDate",
"(",
")",
"}",
"}",
")",
";",
"return",
"date",
";",
"}"
] | monkey punch moment to get around a validation bug | [
"monkey",
"punch",
"moment",
"to",
"get",
"around",
"a",
"validation",
"bug"
] | 3a2b3c40c086b244f985bd1612e6af677e2df9e5 | https://github.com/davidmarkclements/seneca-scheduler/blob/3a2b3c40c086b244f985bd1612e6af677e2df9e5/lib/scheduler.js#L13-L20 |
54,166 | spacemaus/postvox | vox-server/interchangesockets.js | handleSocketMessage | function handleSocketMessage(method, data, replyFn) {
debug('%s %s %s', socket.id, method, data.url, data.payload);
eyes.mark('sockets.' + method);
var url = data.url;
if (!url) {
replyFn({ status: 400, message: 'No URL given in request!' });
return;
}
if (url.indexOf('/') == -1) {
url += '/'; // Ensure that the URL can be routed.
}
var req = {
context: context,
method: method,
url: url,
remoteAddress: remoteAddress,
payload: data.payload
};
if (!req.payload) {
req.payload = {};
}
var replied = false;
var res = {
json: function(reply) {
replyFn(reply);
replied = true;
debug('%s reply %s %s', socket.id, method, data.url);
eyes.mark('sockets.' + method + '.status.200');
},
sendStatus: function(statusCode, message) {
replyFn({ status: statusCode, message: message });
replied = true;
debug('%s reply %s %s', socket.id, method, data.url, statusCode);
eyes.mark('sockets.' + method + '.status.' + statusCode);
}
};
service.commandRouter.handle(req, res, function(err) {
if (err) {
console.error('Error handling %s %s:', method, data.url, err, err.stack);
if (!replied) {
console.error('No reply sent for %s %s...sending 500 error.', method, data.url);
res.sendStatus(500, 'Server error');
}
} else if (!replied) {
debug('No route found for %s %s...sending 404', method, data.url);
res.sendStatus(404, 'Not found: ' + data.url);
}
});
} | javascript | function handleSocketMessage(method, data, replyFn) {
debug('%s %s %s', socket.id, method, data.url, data.payload);
eyes.mark('sockets.' + method);
var url = data.url;
if (!url) {
replyFn({ status: 400, message: 'No URL given in request!' });
return;
}
if (url.indexOf('/') == -1) {
url += '/'; // Ensure that the URL can be routed.
}
var req = {
context: context,
method: method,
url: url,
remoteAddress: remoteAddress,
payload: data.payload
};
if (!req.payload) {
req.payload = {};
}
var replied = false;
var res = {
json: function(reply) {
replyFn(reply);
replied = true;
debug('%s reply %s %s', socket.id, method, data.url);
eyes.mark('sockets.' + method + '.status.200');
},
sendStatus: function(statusCode, message) {
replyFn({ status: statusCode, message: message });
replied = true;
debug('%s reply %s %s', socket.id, method, data.url, statusCode);
eyes.mark('sockets.' + method + '.status.' + statusCode);
}
};
service.commandRouter.handle(req, res, function(err) {
if (err) {
console.error('Error handling %s %s:', method, data.url, err, err.stack);
if (!replied) {
console.error('No reply sent for %s %s...sending 500 error.', method, data.url);
res.sendStatus(500, 'Server error');
}
} else if (!replied) {
debug('No route found for %s %s...sending 404', method, data.url);
res.sendStatus(404, 'Not found: ' + data.url);
}
});
} | [
"function",
"handleSocketMessage",
"(",
"method",
",",
"data",
",",
"replyFn",
")",
"{",
"debug",
"(",
"'%s %s %s'",
",",
"socket",
".",
"id",
",",
"method",
",",
"data",
".",
"url",
",",
"data",
".",
"payload",
")",
";",
"eyes",
".",
"mark",
"(",
"'sockets.'",
"+",
"method",
")",
";",
"var",
"url",
"=",
"data",
".",
"url",
";",
"if",
"(",
"!",
"url",
")",
"{",
"replyFn",
"(",
"{",
"status",
":",
"400",
",",
"message",
":",
"'No URL given in request!'",
"}",
")",
";",
"return",
";",
"}",
"if",
"(",
"url",
".",
"indexOf",
"(",
"'/'",
")",
"==",
"-",
"1",
")",
"{",
"url",
"+=",
"'/'",
";",
"// Ensure that the URL can be routed.",
"}",
"var",
"req",
"=",
"{",
"context",
":",
"context",
",",
"method",
":",
"method",
",",
"url",
":",
"url",
",",
"remoteAddress",
":",
"remoteAddress",
",",
"payload",
":",
"data",
".",
"payload",
"}",
";",
"if",
"(",
"!",
"req",
".",
"payload",
")",
"{",
"req",
".",
"payload",
"=",
"{",
"}",
";",
"}",
"var",
"replied",
"=",
"false",
";",
"var",
"res",
"=",
"{",
"json",
":",
"function",
"(",
"reply",
")",
"{",
"replyFn",
"(",
"reply",
")",
";",
"replied",
"=",
"true",
";",
"debug",
"(",
"'%s reply %s %s'",
",",
"socket",
".",
"id",
",",
"method",
",",
"data",
".",
"url",
")",
";",
"eyes",
".",
"mark",
"(",
"'sockets.'",
"+",
"method",
"+",
"'.status.200'",
")",
";",
"}",
",",
"sendStatus",
":",
"function",
"(",
"statusCode",
",",
"message",
")",
"{",
"replyFn",
"(",
"{",
"status",
":",
"statusCode",
",",
"message",
":",
"message",
"}",
")",
";",
"replied",
"=",
"true",
";",
"debug",
"(",
"'%s reply %s %s'",
",",
"socket",
".",
"id",
",",
"method",
",",
"data",
".",
"url",
",",
"statusCode",
")",
";",
"eyes",
".",
"mark",
"(",
"'sockets.'",
"+",
"method",
"+",
"'.status.'",
"+",
"statusCode",
")",
";",
"}",
"}",
";",
"service",
".",
"commandRouter",
".",
"handle",
"(",
"req",
",",
"res",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Error handling %s %s:'",
",",
"method",
",",
"data",
".",
"url",
",",
"err",
",",
"err",
".",
"stack",
")",
";",
"if",
"(",
"!",
"replied",
")",
"{",
"console",
".",
"error",
"(",
"'No reply sent for %s %s...sending 500 error.'",
",",
"method",
",",
"data",
".",
"url",
")",
";",
"res",
".",
"sendStatus",
"(",
"500",
",",
"'Server error'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"replied",
")",
"{",
"debug",
"(",
"'No route found for %s %s...sending 404'",
",",
"method",
",",
"data",
".",
"url",
")",
";",
"res",
".",
"sendStatus",
"(",
"404",
",",
"'Not found: '",
"+",
"data",
".",
"url",
")",
";",
"}",
"}",
")",
";",
"}"
] | Handles the VOX command. A VOX command wraps a URL, HTTP method, and JSON
data payload, and it expects a JSON response.
@param method {String} The command's HTTP-like method. E.g. "POST".
@param data.url {String} The URL of the command. E.g.,
"vox://<source>/threads/<threadId>".
@param data.payload {Object} The command's JSON payload. | [
"Handles",
"the",
"VOX",
"command",
".",
"A",
"VOX",
"command",
"wraps",
"a",
"URL",
"HTTP",
"method",
"and",
"JSON",
"data",
"payload",
"and",
"it",
"expects",
"a",
"JSON",
"response",
"."
] | de98e5ed37edaee1b1edadf93e15eb8f8d21f457 | https://github.com/spacemaus/postvox/blob/de98e5ed37edaee1b1edadf93e15eb8f8d21f457/vox-server/interchangesockets.js#L71-L119 |
54,167 | shama/cettings | namespace.js | getParts | function getParts(str) {
return str.replace(/\\\./g, '\uffff').split('.').map(function(s) {
return s.replace(/\uffff/g, '.');
});
} | javascript | function getParts(str) {
return str.replace(/\\\./g, '\uffff').split('.').map(function(s) {
return s.replace(/\uffff/g, '.');
});
} | [
"function",
"getParts",
"(",
"str",
")",
"{",
"return",
"str",
".",
"replace",
"(",
"/",
"\\\\\\.",
"/",
"g",
",",
"'\\uffff'",
")",
".",
"split",
"(",
"'.'",
")",
".",
"map",
"(",
"function",
"(",
"s",
")",
"{",
"return",
"s",
".",
"replace",
"(",
"/",
"\\uffff",
"/",
"g",
",",
"'.'",
")",
";",
"}",
")",
";",
"}"
] | Split strings on dot, but only if dot isn't preceded by a backslash. Since JavaScript doesn't support lookbehinds, use a placeholder for "\.", split on dot, then replace the placeholder character with a dot. | [
"Split",
"strings",
"on",
"dot",
"but",
"only",
"if",
"dot",
"isn",
"t",
"preceded",
"by",
"a",
"backslash",
".",
"Since",
"JavaScript",
"doesn",
"t",
"support",
"lookbehinds",
"use",
"a",
"placeholder",
"for",
"\\",
".",
"split",
"on",
"dot",
"then",
"replace",
"the",
"placeholder",
"character",
"with",
"a",
"dot",
"."
] | 886eeec0c1fb92a2d1ce9926c8c1edf61c678c03 | https://github.com/shama/cettings/blob/886eeec0c1fb92a2d1ce9926c8c1edf61c678c03/namespace.js#L17-L21 |
54,168 | slikts/promiseproxy | src/cached.js | CachedPromiseProxy | function CachedPromiseProxy(target, context, cache = new WeakMap(), factory = PromiseProxy) {
const cached = cache.get(target)
if (cached) {
return cached
}
const obj = factory(target, context,
(target, context) => CachedPromiseProxy(target, context, cache))
cache.set(target, obj)
return obj
} | javascript | function CachedPromiseProxy(target, context, cache = new WeakMap(), factory = PromiseProxy) {
const cached = cache.get(target)
if (cached) {
return cached
}
const obj = factory(target, context,
(target, context) => CachedPromiseProxy(target, context, cache))
cache.set(target, obj)
return obj
} | [
"function",
"CachedPromiseProxy",
"(",
"target",
",",
"context",
",",
"cache",
"=",
"new",
"WeakMap",
"(",
")",
",",
"factory",
"=",
"PromiseProxy",
")",
"{",
"const",
"cached",
"=",
"cache",
".",
"get",
"(",
"target",
")",
"if",
"(",
"cached",
")",
"{",
"return",
"cached",
"}",
"const",
"obj",
"=",
"factory",
"(",
"target",
",",
"context",
",",
"(",
"target",
",",
"context",
")",
"=>",
"CachedPromiseProxy",
"(",
"target",
",",
"context",
",",
"cache",
")",
")",
"cache",
".",
"set",
"(",
"target",
",",
"obj",
")",
"return",
"obj",
"}"
] | Wraps PromiseProxy factory and caches instances in a WeakMap | [
"Wraps",
"PromiseProxy",
"factory",
"and",
"caches",
"instances",
"in",
"a",
"WeakMap"
] | bcda1b4372bf03a86af7d2bb1ba01a746a9ba952 | https://github.com/slikts/promiseproxy/blob/bcda1b4372bf03a86af7d2bb1ba01a746a9ba952/src/cached.js#L6-L15 |
54,169 | alex-seville/feta | dist/devtools.js | checkIfPlaying | function checkIfPlaying(){
runInPage(window.fetaSource.isPlayingStr(),
function(result){
if(!result){
setTimeout(checkIfPlaying,500);
}else{
_window.msgFromDevtools("revertRun",{data: result});
}
},
function(err){
alert(errorMessage+"error playing script, line 96.");
});
} | javascript | function checkIfPlaying(){
runInPage(window.fetaSource.isPlayingStr(),
function(result){
if(!result){
setTimeout(checkIfPlaying,500);
}else{
_window.msgFromDevtools("revertRun",{data: result});
}
},
function(err){
alert(errorMessage+"error playing script, line 96.");
});
} | [
"function",
"checkIfPlaying",
"(",
")",
"{",
"runInPage",
"(",
"window",
".",
"fetaSource",
".",
"isPlayingStr",
"(",
")",
",",
"function",
"(",
"result",
")",
"{",
"if",
"(",
"!",
"result",
")",
"{",
"setTimeout",
"(",
"checkIfPlaying",
",",
"500",
")",
";",
"}",
"else",
"{",
"_window",
".",
"msgFromDevtools",
"(",
"\"revertRun\"",
",",
"{",
"data",
":",
"result",
"}",
")",
";",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"alert",
"(",
"errorMessage",
"+",
"\"error playing script, line 96.\"",
")",
";",
"}",
")",
";",
"}"
] | we check if the test is still running when it isn't running anymore we update the run test button | [
"we",
"check",
"if",
"the",
"test",
"is",
"still",
"running",
"when",
"it",
"isn",
"t",
"running",
"anymore",
"we",
"update",
"the",
"run",
"test",
"button"
] | 2ba603320ccba3fec313d26a3a70fab3d6f39e3a | https://github.com/alex-seville/feta/blob/2ba603320ccba3fec313d26a3a70fab3d6f39e3a/dist/devtools.js#L86-L98 |
54,170 | alex-seville/feta | dist/devtools.js | doFeta | function doFeta(msg) {
if(msg){
runInPage(window.fetaSource.startStr(),
function(){
btn.update("images/recording.png", "Stop Recording");
});
}else{
runInPage(window.fetaSource.stopStr(),
function(result){
btn.update("images/record.png", "Start Recording");
_window.msgFromDevtools("saveFile",{data:result});
});
}
} | javascript | function doFeta(msg) {
if(msg){
runInPage(window.fetaSource.startStr(),
function(){
btn.update("images/recording.png", "Stop Recording");
});
}else{
runInPage(window.fetaSource.stopStr(),
function(result){
btn.update("images/record.png", "Start Recording");
_window.msgFromDevtools("saveFile",{data:result});
});
}
} | [
"function",
"doFeta",
"(",
"msg",
")",
"{",
"if",
"(",
"msg",
")",
"{",
"runInPage",
"(",
"window",
".",
"fetaSource",
".",
"startStr",
"(",
")",
",",
"function",
"(",
")",
"{",
"btn",
".",
"update",
"(",
"\"images/recording.png\"",
",",
"\"Stop Recording\"",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"runInPage",
"(",
"window",
".",
"fetaSource",
".",
"stopStr",
"(",
")",
",",
"function",
"(",
"result",
")",
"{",
"btn",
".",
"update",
"(",
"\"images/record.png\"",
",",
"\"Start Recording\"",
")",
";",
"_window",
".",
"msgFromDevtools",
"(",
"\"saveFile\"",
",",
"{",
"data",
":",
"result",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
] | we inject feta.start or feta.stop depending on the mode. we update the panel button as well | [
"we",
"inject",
"feta",
".",
"start",
"or",
"feta",
".",
"stop",
"depending",
"on",
"the",
"mode",
".",
"we",
"update",
"the",
"panel",
"button",
"as",
"well"
] | 2ba603320ccba3fec313d26a3a70fab3d6f39e3a | https://github.com/alex-seville/feta/blob/2ba603320ccba3fec313d26a3a70fab3d6f39e3a/dist/devtools.js#L102-L115 |
54,171 | alex-seville/feta | dist/devtools.js | makeDownload | function makeDownload(url,fname){
fname = fname === "" ? "feta_output.js" : fname;
//this code is from SO, but I'm missing the link right now
var s = "var a = document.createElement('a');";
s+= "a.href = '"+url+"';";
s+= "a.download = '"+ fname +"';"; // set the file name
s+= "a.style.display = 'none';";
s+= "document.body.appendChild(a);";
s+= "a.click();"; //this is probably the key - simulatating a click on a download link
s+= "delete a;";// we don't need this anymore
runInPage(s,doNothing);
} | javascript | function makeDownload(url,fname){
fname = fname === "" ? "feta_output.js" : fname;
//this code is from SO, but I'm missing the link right now
var s = "var a = document.createElement('a');";
s+= "a.href = '"+url+"';";
s+= "a.download = '"+ fname +"';"; // set the file name
s+= "a.style.display = 'none';";
s+= "document.body.appendChild(a);";
s+= "a.click();"; //this is probably the key - simulatating a click on a download link
s+= "delete a;";// we don't need this anymore
runInPage(s,doNothing);
} | [
"function",
"makeDownload",
"(",
"url",
",",
"fname",
")",
"{",
"fname",
"=",
"fname",
"===",
"\"\"",
"?",
"\"feta_output.js\"",
":",
"fname",
";",
"//this code is from SO, but I'm missing the link right now",
"var",
"s",
"=",
"\"var a = document.createElement('a');\"",
";",
"s",
"+=",
"\"a.href = '\"",
"+",
"url",
"+",
"\"';\"",
";",
"s",
"+=",
"\"a.download = '\"",
"+",
"fname",
"+",
"\"';\"",
";",
"// set the file name",
"s",
"+=",
"\"a.style.display = 'none';\"",
";",
"s",
"+=",
"\"document.body.appendChild(a);\"",
";",
"s",
"+=",
"\"a.click();\"",
";",
"//this is probably the key - simulatating a click on a download link",
"s",
"+=",
"\"delete a;\"",
";",
"// we don't need this anymore",
"runInPage",
"(",
"s",
",",
"doNothing",
")",
";",
"}"
] | create a link element and click it to download the file | [
"create",
"a",
"link",
"element",
"and",
"click",
"it",
"to",
"download",
"the",
"file"
] | 2ba603320ccba3fec313d26a3a70fab3d6f39e3a | https://github.com/alex-seville/feta/blob/2ba603320ccba3fec313d26a3a70fab3d6f39e3a/dist/devtools.js#L123-L134 |
54,172 | alex-seville/feta | dist/devtools.js | runInPage | function runInPage(code,callback,errorCallback){
errorCallback = errorCallback || function(err){ alert(errorMessage+err); };
chrome.devtools.inspectedWindow["eval"](
code,
function(result, isException) {
if (isException)
errorCallback(isException);
else{
callback(result);
}
});
} | javascript | function runInPage(code,callback,errorCallback){
errorCallback = errorCallback || function(err){ alert(errorMessage+err); };
chrome.devtools.inspectedWindow["eval"](
code,
function(result, isException) {
if (isException)
errorCallback(isException);
else{
callback(result);
}
});
} | [
"function",
"runInPage",
"(",
"code",
",",
"callback",
",",
"errorCallback",
")",
"{",
"errorCallback",
"=",
"errorCallback",
"||",
"function",
"(",
"err",
")",
"{",
"alert",
"(",
"errorMessage",
"+",
"err",
")",
";",
"}",
";",
"chrome",
".",
"devtools",
".",
"inspectedWindow",
"[",
"\"eval\"",
"]",
"(",
"code",
",",
"function",
"(",
"result",
",",
"isException",
")",
"{",
"if",
"(",
"isException",
")",
"errorCallback",
"(",
"isException",
")",
";",
"else",
"{",
"callback",
"(",
"result",
")",
";",
"}",
"}",
")",
";",
"}"
] | helper function to evaluate code in the inspected page context with access to the JS and the DOM | [
"helper",
"function",
"to",
"evaluate",
"code",
"in",
"the",
"inspected",
"page",
"context",
"with",
"access",
"to",
"the",
"JS",
"and",
"the",
"DOM"
] | 2ba603320ccba3fec313d26a3a70fab3d6f39e3a | https://github.com/alex-seville/feta/blob/2ba603320ccba3fec313d26a3a70fab3d6f39e3a/dist/devtools.js#L143-L154 |
54,173 | nullivex/oose-sdk | helpers/api.js | function(err){
//if this is already a network error just throw it
if(err instanceof NetworkError){
throw err
}
//convert strings to errors
if('string' === typeof err){
err = new Error(err)
}
//check if the error message matches a known TCP error
var error
for(var i = 0; i < tcpErrors.length; i++){
if(err.message.indexOf(tcpErrors[i]) >= 0){
//lets throw a NetworkError
error = new NetworkError(err.message)
//preserve the original stack trace so we can actually debug these
error.stack = err.stack
throw error
}
}
//if we make it here it is not an error we can handle just throw it
throw err
} | javascript | function(err){
//if this is already a network error just throw it
if(err instanceof NetworkError){
throw err
}
//convert strings to errors
if('string' === typeof err){
err = new Error(err)
}
//check if the error message matches a known TCP error
var error
for(var i = 0; i < tcpErrors.length; i++){
if(err.message.indexOf(tcpErrors[i]) >= 0){
//lets throw a NetworkError
error = new NetworkError(err.message)
//preserve the original stack trace so we can actually debug these
error.stack = err.stack
throw error
}
}
//if we make it here it is not an error we can handle just throw it
throw err
} | [
"function",
"(",
"err",
")",
"{",
"//if this is already a network error just throw it",
"if",
"(",
"err",
"instanceof",
"NetworkError",
")",
"{",
"throw",
"err",
"}",
"//convert strings to errors",
"if",
"(",
"'string'",
"===",
"typeof",
"err",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"err",
")",
"}",
"//check if the error message matches a known TCP error",
"var",
"error",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tcpErrors",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"err",
".",
"message",
".",
"indexOf",
"(",
"tcpErrors",
"[",
"i",
"]",
")",
">=",
"0",
")",
"{",
"//lets throw a NetworkError",
"error",
"=",
"new",
"NetworkError",
"(",
"err",
".",
"message",
")",
"//preserve the original stack trace so we can actually debug these",
"error",
".",
"stack",
"=",
"err",
".",
"stack",
"throw",
"error",
"}",
"}",
"//if we make it here it is not an error we can handle just throw it",
"throw",
"err",
"}"
] | Handle network errors
@param {Error} err | [
"Handle",
"network",
"errors"
] | 46a3a950107b904825195b2a6645d9db5a3dd5bd | https://github.com/nullivex/oose-sdk/blob/46a3a950107b904825195b2a6645d9db5a3dd5bd/helpers/api.js#L102-L124 |
|
54,174 | nullivex/oose-sdk | helpers/api.js | function(type,options){
var cacheKey = type + ':' + options.host + ':' + options.port
if(!cache[cacheKey]){
debug('cache miss',cacheKey)
var reqDefaults = {
rejectUnauthorized: false,
json: true,
timeout:
+process.env.REQUEST_TIMEOUT ||
+options.timeout ||
2147483647, //equiv to timeout max in node.js/lib/timers.js
pool: pool
}
if(options.username || (config[type] && config[type].username)){
reqDefaults.auth = {
username: options.username || config[type].username
}
}
if(options.password || (config[type] && config[type].password)){
if(reqDefaults.auth){
reqDefaults.auth.password = options.password || config[type].password
} else {
reqDefaults.auth = {
password: options.password || config[type].password
}
}
}
var req = request.defaults(reqDefaults)
cache[cacheKey] = extendRequest(req,type,options)
} else {
debug('cache hit',cacheKey)
}
return cache[cacheKey]
} | javascript | function(type,options){
var cacheKey = type + ':' + options.host + ':' + options.port
if(!cache[cacheKey]){
debug('cache miss',cacheKey)
var reqDefaults = {
rejectUnauthorized: false,
json: true,
timeout:
+process.env.REQUEST_TIMEOUT ||
+options.timeout ||
2147483647, //equiv to timeout max in node.js/lib/timers.js
pool: pool
}
if(options.username || (config[type] && config[type].username)){
reqDefaults.auth = {
username: options.username || config[type].username
}
}
if(options.password || (config[type] && config[type].password)){
if(reqDefaults.auth){
reqDefaults.auth.password = options.password || config[type].password
} else {
reqDefaults.auth = {
password: options.password || config[type].password
}
}
}
var req = request.defaults(reqDefaults)
cache[cacheKey] = extendRequest(req,type,options)
} else {
debug('cache hit',cacheKey)
}
return cache[cacheKey]
} | [
"function",
"(",
"type",
",",
"options",
")",
"{",
"var",
"cacheKey",
"=",
"type",
"+",
"':'",
"+",
"options",
".",
"host",
"+",
"':'",
"+",
"options",
".",
"port",
"if",
"(",
"!",
"cache",
"[",
"cacheKey",
"]",
")",
"{",
"debug",
"(",
"'cache miss'",
",",
"cacheKey",
")",
"var",
"reqDefaults",
"=",
"{",
"rejectUnauthorized",
":",
"false",
",",
"json",
":",
"true",
",",
"timeout",
":",
"+",
"process",
".",
"env",
".",
"REQUEST_TIMEOUT",
"||",
"+",
"options",
".",
"timeout",
"||",
"2147483647",
",",
"//equiv to timeout max in node.js/lib/timers.js",
"pool",
":",
"pool",
"}",
"if",
"(",
"options",
".",
"username",
"||",
"(",
"config",
"[",
"type",
"]",
"&&",
"config",
"[",
"type",
"]",
".",
"username",
")",
")",
"{",
"reqDefaults",
".",
"auth",
"=",
"{",
"username",
":",
"options",
".",
"username",
"||",
"config",
"[",
"type",
"]",
".",
"username",
"}",
"}",
"if",
"(",
"options",
".",
"password",
"||",
"(",
"config",
"[",
"type",
"]",
"&&",
"config",
"[",
"type",
"]",
".",
"password",
")",
")",
"{",
"if",
"(",
"reqDefaults",
".",
"auth",
")",
"{",
"reqDefaults",
".",
"auth",
".",
"password",
"=",
"options",
".",
"password",
"||",
"config",
"[",
"type",
"]",
".",
"password",
"}",
"else",
"{",
"reqDefaults",
".",
"auth",
"=",
"{",
"password",
":",
"options",
".",
"password",
"||",
"config",
"[",
"type",
"]",
".",
"password",
"}",
"}",
"}",
"var",
"req",
"=",
"request",
".",
"defaults",
"(",
"reqDefaults",
")",
"cache",
"[",
"cacheKey",
"]",
"=",
"extendRequest",
"(",
"req",
",",
"type",
",",
"options",
")",
"}",
"else",
"{",
"debug",
"(",
"'cache hit'",
",",
"cacheKey",
")",
"}",
"return",
"cache",
"[",
"cacheKey",
"]",
"}"
] | Setup a new request object
@param {string} type
@param {object} options
@return {request} | [
"Setup",
"a",
"new",
"request",
"object"
] | 46a3a950107b904825195b2a6645d9db5a3dd5bd | https://github.com/nullivex/oose-sdk/blob/46a3a950107b904825195b2a6645d9db5a3dd5bd/helpers/api.js#L151-L184 |
|
54,175 | Vanessa219/gulp-header-license | index.js | isMatch | function isMatch(file, license, rate, srcNLReg) {
var srcLines = file.contents.toString('utf8').split(/\r?\n/),
templateLines = license.split(/\r?\n/),
type = path.extname(file.path),
matchRates = 0,
removed = false;
// after '<?php' has new line, remove it
switch (type) {
case '.php':
if (srcLines[1].replace(/\s/, '') === '') {
srcLines.splice(1, 1);
removed = true;
}
break;
default:
break;
}
// count match line
var minLength = templateLines.length > srcLines.length ? srcLines.length : templateLines.length;
for (var i = 0; i < minLength; i++) {
if (templateLines[templateLines.length - 1] === '' && i === templateLines.length - 1) {
matchRates += 1;
} else {
switch (type) {
case '.php':
matchRates += getMatchRate(srcLines[i + 1], templateLines[i]);
break;
default:
matchRates += getMatchRate(srcLines[i], templateLines[i]);
break;
}
}
}
// has similar license, remove the license.
var matchPer = matchRates / templateLines.length;
if (matchPer >= rate && matchPer < 1) {
// remove
switch (type) {
case '.php':
if (srcLines[templateLines.length].replace(/\s/, '') === '' && !removed) {
// after license, should be have a blank line. if has not, we don't need remove blank line. && after '<?php' has not new line
srcLines.splice(1, templateLines.length);
} else {
srcLines.splice(1, templateLines.length - 1);
}
file.contents = new Buffer(srcLines.join(srcNLReg));
break;
default:
// after license, should be have a blank line. if have not, we don't need remove blank line.
if (srcLines[templateLines.length - 1].replace(/\s/, '') === '') {
srcLines.splice(0, templateLines.length);
} else {
srcLines.splice(0, templateLines.length - 1);
}
file.contents = new Buffer(srcLines.join(srcNLReg));
break;
}
return false;
} else if (matchPer === 1) {
return true;
}
} | javascript | function isMatch(file, license, rate, srcNLReg) {
var srcLines = file.contents.toString('utf8').split(/\r?\n/),
templateLines = license.split(/\r?\n/),
type = path.extname(file.path),
matchRates = 0,
removed = false;
// after '<?php' has new line, remove it
switch (type) {
case '.php':
if (srcLines[1].replace(/\s/, '') === '') {
srcLines.splice(1, 1);
removed = true;
}
break;
default:
break;
}
// count match line
var minLength = templateLines.length > srcLines.length ? srcLines.length : templateLines.length;
for (var i = 0; i < minLength; i++) {
if (templateLines[templateLines.length - 1] === '' && i === templateLines.length - 1) {
matchRates += 1;
} else {
switch (type) {
case '.php':
matchRates += getMatchRate(srcLines[i + 1], templateLines[i]);
break;
default:
matchRates += getMatchRate(srcLines[i], templateLines[i]);
break;
}
}
}
// has similar license, remove the license.
var matchPer = matchRates / templateLines.length;
if (matchPer >= rate && matchPer < 1) {
// remove
switch (type) {
case '.php':
if (srcLines[templateLines.length].replace(/\s/, '') === '' && !removed) {
// after license, should be have a blank line. if has not, we don't need remove blank line. && after '<?php' has not new line
srcLines.splice(1, templateLines.length);
} else {
srcLines.splice(1, templateLines.length - 1);
}
file.contents = new Buffer(srcLines.join(srcNLReg));
break;
default:
// after license, should be have a blank line. if have not, we don't need remove blank line.
if (srcLines[templateLines.length - 1].replace(/\s/, '') === '') {
srcLines.splice(0, templateLines.length);
} else {
srcLines.splice(0, templateLines.length - 1);
}
file.contents = new Buffer(srcLines.join(srcNLReg));
break;
}
return false;
} else if (matchPer === 1) {
return true;
}
} | [
"function",
"isMatch",
"(",
"file",
",",
"license",
",",
"rate",
",",
"srcNLReg",
")",
"{",
"var",
"srcLines",
"=",
"file",
".",
"contents",
".",
"toString",
"(",
"'utf8'",
")",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
")",
",",
"templateLines",
"=",
"license",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
")",
",",
"type",
"=",
"path",
".",
"extname",
"(",
"file",
".",
"path",
")",
",",
"matchRates",
"=",
"0",
",",
"removed",
"=",
"false",
";",
"// after '<?php' has new line, remove it ",
"switch",
"(",
"type",
")",
"{",
"case",
"'.php'",
":",
"if",
"(",
"srcLines",
"[",
"1",
"]",
".",
"replace",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"===",
"''",
")",
"{",
"srcLines",
".",
"splice",
"(",
"1",
",",
"1",
")",
";",
"removed",
"=",
"true",
";",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"// count match line",
"var",
"minLength",
"=",
"templateLines",
".",
"length",
">",
"srcLines",
".",
"length",
"?",
"srcLines",
".",
"length",
":",
"templateLines",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"minLength",
";",
"i",
"++",
")",
"{",
"if",
"(",
"templateLines",
"[",
"templateLines",
".",
"length",
"-",
"1",
"]",
"===",
"''",
"&&",
"i",
"===",
"templateLines",
".",
"length",
"-",
"1",
")",
"{",
"matchRates",
"+=",
"1",
";",
"}",
"else",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"'.php'",
":",
"matchRates",
"+=",
"getMatchRate",
"(",
"srcLines",
"[",
"i",
"+",
"1",
"]",
",",
"templateLines",
"[",
"i",
"]",
")",
";",
"break",
";",
"default",
":",
"matchRates",
"+=",
"getMatchRate",
"(",
"srcLines",
"[",
"i",
"]",
",",
"templateLines",
"[",
"i",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"// has similar license, remove the license.",
"var",
"matchPer",
"=",
"matchRates",
"/",
"templateLines",
".",
"length",
";",
"if",
"(",
"matchPer",
">=",
"rate",
"&&",
"matchPer",
"<",
"1",
")",
"{",
"// remove",
"switch",
"(",
"type",
")",
"{",
"case",
"'.php'",
":",
"if",
"(",
"srcLines",
"[",
"templateLines",
".",
"length",
"]",
".",
"replace",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"===",
"''",
"&&",
"!",
"removed",
")",
"{",
"// after license, should be have a blank line. if has not, we don't need remove blank line. && after '<?php' has not new line",
"srcLines",
".",
"splice",
"(",
"1",
",",
"templateLines",
".",
"length",
")",
";",
"}",
"else",
"{",
"srcLines",
".",
"splice",
"(",
"1",
",",
"templateLines",
".",
"length",
"-",
"1",
")",
";",
"}",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"srcLines",
".",
"join",
"(",
"srcNLReg",
")",
")",
";",
"break",
";",
"default",
":",
"// after license, should be have a blank line. if have not, we don't need remove blank line.",
"if",
"(",
"srcLines",
"[",
"templateLines",
".",
"length",
"-",
"1",
"]",
".",
"replace",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"===",
"''",
")",
"{",
"srcLines",
".",
"splice",
"(",
"0",
",",
"templateLines",
".",
"length",
")",
";",
"}",
"else",
"{",
"srcLines",
".",
"splice",
"(",
"0",
",",
"templateLines",
".",
"length",
"-",
"1",
")",
";",
"}",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"srcLines",
".",
"join",
"(",
"srcNLReg",
")",
")",
";",
"break",
";",
"}",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"matchPer",
"===",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}"
] | According to rate, get matching.
@param {object} file nodeJS file object.
@param {string} license The license template string.
@param {float} rate Matching rate.
@param {string} srcNLReg new line char code.
@returns {boolean} dose match. | [
"According",
"to",
"rate",
"get",
"matching",
"."
] | 41e5287a7a58aab7f1799d916d8c0ccaf3353358 | https://github.com/Vanessa219/gulp-header-license/blob/41e5287a7a58aab7f1799d916d8c0ccaf3353358/index.js#L39-L104 |
54,176 | Vanessa219/gulp-header-license | index.js | getMatchRate | function getMatchRate(src, str) {
if (typeof (src) === 'undefined' || typeof (str) === 'undefined') {
return 0;
}
var maxLength = src.length > str.length ? src.length : str.length,
matchCnt = 0;
if (maxLength === 0) {
return 1;
}
for (var i = 0; i < maxLength; i++) {
if (str.charAt(i) === src.charAt(i)) {
matchCnt++;
}
}
if (matchCnt === 0) {
return 0;
}
return matchCnt / maxLength;
} | javascript | function getMatchRate(src, str) {
if (typeof (src) === 'undefined' || typeof (str) === 'undefined') {
return 0;
}
var maxLength = src.length > str.length ? src.length : str.length,
matchCnt = 0;
if (maxLength === 0) {
return 1;
}
for (var i = 0; i < maxLength; i++) {
if (str.charAt(i) === src.charAt(i)) {
matchCnt++;
}
}
if (matchCnt === 0) {
return 0;
}
return matchCnt / maxLength;
} | [
"function",
"getMatchRate",
"(",
"src",
",",
"str",
")",
"{",
"if",
"(",
"typeof",
"(",
"src",
")",
"===",
"'undefined'",
"||",
"typeof",
"(",
"str",
")",
"===",
"'undefined'",
")",
"{",
"return",
"0",
";",
"}",
"var",
"maxLength",
"=",
"src",
".",
"length",
">",
"str",
".",
"length",
"?",
"src",
".",
"length",
":",
"str",
".",
"length",
",",
"matchCnt",
"=",
"0",
";",
"if",
"(",
"maxLength",
"===",
"0",
")",
"{",
"return",
"1",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"maxLength",
";",
"i",
"++",
")",
"{",
"if",
"(",
"str",
".",
"charAt",
"(",
"i",
")",
"===",
"src",
".",
"charAt",
"(",
"i",
")",
")",
"{",
"matchCnt",
"++",
";",
"}",
"}",
"if",
"(",
"matchCnt",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"return",
"matchCnt",
"/",
"maxLength",
";",
"}"
] | Compare each character for ever line, and get ever line match rate.
@param {type} src text for template.
@param {type} str text for file.
@returns {float} match rate. | [
"Compare",
"each",
"character",
"for",
"ever",
"line",
"and",
"get",
"ever",
"line",
"match",
"rate",
"."
] | 41e5287a7a58aab7f1799d916d8c0ccaf3353358 | https://github.com/Vanessa219/gulp-header-license/blob/41e5287a7a58aab7f1799d916d8c0ccaf3353358/index.js#L113-L135 |
54,177 | Vanessa219/gulp-header-license | index.js | getSeparator | function getSeparator(str, str2) {
// 13 \r 10 \n
for (var i = str.length; i > -1; i--) {
if (str.charCodeAt(i) === 10) {
if (str.charCodeAt(i - 1) === 13) {
return '\r\n';
}
if (str.charCodeAt(i + 1) === 13) {
return '\n\r';
}
return '\n';
}
if (str.charCodeAt(i) === 13) {
if (str.charCodeAt(i - 1) === 10) {
return '\n\r';
}
if (str.charCodeAt(i + 1) === 10) {
return '\r\n';
}
return '\r';
}
}
// if file no newline, will use template
for (var i = str2.length; i > -1; i--) {
if (str2.charCodeAt(i) === 10) {
if (str2.charCodeAt(i - 1) === 13) {
return '\r\n';
}
if (str2.charCodeAt(i + 1) === 13) {
return '\n\r';
}
return '\n';
}
if (str2.charCodeAt(i) === 13) {
if (str2.charCodeAt(i - 1) === 10) {
return '\n\r';
}
if (str2.charCodeAt(i + 1) === 10) {
return '\r\n';
}
return '\r';
}
}
} | javascript | function getSeparator(str, str2) {
// 13 \r 10 \n
for (var i = str.length; i > -1; i--) {
if (str.charCodeAt(i) === 10) {
if (str.charCodeAt(i - 1) === 13) {
return '\r\n';
}
if (str.charCodeAt(i + 1) === 13) {
return '\n\r';
}
return '\n';
}
if (str.charCodeAt(i) === 13) {
if (str.charCodeAt(i - 1) === 10) {
return '\n\r';
}
if (str.charCodeAt(i + 1) === 10) {
return '\r\n';
}
return '\r';
}
}
// if file no newline, will use template
for (var i = str2.length; i > -1; i--) {
if (str2.charCodeAt(i) === 10) {
if (str2.charCodeAt(i - 1) === 13) {
return '\r\n';
}
if (str2.charCodeAt(i + 1) === 13) {
return '\n\r';
}
return '\n';
}
if (str2.charCodeAt(i) === 13) {
if (str2.charCodeAt(i - 1) === 10) {
return '\n\r';
}
if (str2.charCodeAt(i + 1) === 10) {
return '\r\n';
}
return '\r';
}
}
} | [
"function",
"getSeparator",
"(",
"str",
",",
"str2",
")",
"{",
"// 13 \\r 10 \\n",
"for",
"(",
"var",
"i",
"=",
"str",
".",
"length",
";",
"i",
">",
"-",
"1",
";",
"i",
"--",
")",
"{",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
")",
"===",
"10",
")",
"{",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
"-",
"1",
")",
"===",
"13",
")",
"{",
"return",
"'\\r\\n'",
";",
"}",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"===",
"13",
")",
"{",
"return",
"'\\n\\r'",
";",
"}",
"return",
"'\\n'",
";",
"}",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
")",
"===",
"13",
")",
"{",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
"-",
"1",
")",
"===",
"10",
")",
"{",
"return",
"'\\n\\r'",
";",
"}",
"if",
"(",
"str",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"===",
"10",
")",
"{",
"return",
"'\\r\\n'",
";",
"}",
"return",
"'\\r'",
";",
"}",
"}",
"// if file no newline, will use template",
"for",
"(",
"var",
"i",
"=",
"str2",
".",
"length",
";",
"i",
">",
"-",
"1",
";",
"i",
"--",
")",
"{",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
")",
"===",
"10",
")",
"{",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
"-",
"1",
")",
"===",
"13",
")",
"{",
"return",
"'\\r\\n'",
";",
"}",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"===",
"13",
")",
"{",
"return",
"'\\n\\r'",
";",
"}",
"return",
"'\\n'",
";",
"}",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
")",
"===",
"13",
")",
"{",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
"-",
"1",
")",
"===",
"10",
")",
"{",
"return",
"'\\n\\r'",
";",
"}",
"if",
"(",
"str2",
".",
"charCodeAt",
"(",
"i",
"+",
"1",
")",
"===",
"10",
")",
"{",
"return",
"'\\r\\n'",
";",
"}",
"return",
"'\\r'",
";",
"}",
"}",
"}"
] | Test first newline character and get newline character.
@param {type} str file content.
@returns {String} newline character. | [
"Test",
"first",
"newline",
"character",
"and",
"get",
"newline",
"character",
"."
] | 41e5287a7a58aab7f1799d916d8c0ccaf3353358 | https://github.com/Vanessa219/gulp-header-license/blob/41e5287a7a58aab7f1799d916d8c0ccaf3353358/index.js#L143-L190 |
54,178 | joneit/extend-me | index.js | function(memberName) {
var parent = this.super;
do { parent = Object.getPrototypeOf(parent); } while (!parent.hasOwnProperty(memberName));
return parent && parent[memberName];
} | javascript | function(memberName) {
var parent = this.super;
do { parent = Object.getPrototypeOf(parent); } while (!parent.hasOwnProperty(memberName));
return parent && parent[memberName];
} | [
"function",
"(",
"memberName",
")",
"{",
"var",
"parent",
"=",
"this",
".",
"super",
";",
"do",
"{",
"parent",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"parent",
")",
";",
"}",
"while",
"(",
"!",
"parent",
".",
"hasOwnProperty",
"(",
"memberName",
")",
")",
";",
"return",
"parent",
"&&",
"parent",
"[",
"memberName",
"]",
";",
"}"
] | Find member on prototype chain beginning with super class.
@param {string} memberName
@returns {undefined|*} `undefined` if not found; value otherwise. | [
"Find",
"member",
"on",
"prototype",
"chain",
"beginning",
"with",
"super",
"class",
"."
] | 727386ee29ab77ec0eb48bcc995dcd20b72ff091 | https://github.com/joneit/extend-me/blob/727386ee29ab77ec0eb48bcc995dcd20b72ff091/index.js#L146-L150 |
|
54,179 | SwirlNetworks/discus | src/super.js | findSuper | function findSuper(methodName, childObject) {
var object = childObject;
while (object[methodName] === childObject[methodName]) {
object = object.constructor.__super__;
if (!object) {
throw new Error('Class has no super method for', methodName, '. Remove the _super call to the non-existent method');
}
}
return object;
} | javascript | function findSuper(methodName, childObject) {
var object = childObject;
while (object[methodName] === childObject[methodName]) {
object = object.constructor.__super__;
if (!object) {
throw new Error('Class has no super method for', methodName, '. Remove the _super call to the non-existent method');
}
}
return object;
} | [
"function",
"findSuper",
"(",
"methodName",
",",
"childObject",
")",
"{",
"var",
"object",
"=",
"childObject",
";",
"while",
"(",
"object",
"[",
"methodName",
"]",
"===",
"childObject",
"[",
"methodName",
"]",
")",
"{",
"object",
"=",
"object",
".",
"constructor",
".",
"__super__",
";",
"if",
"(",
"!",
"object",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Class has no super method for'",
",",
"methodName",
",",
"'. Remove the _super call to the non-existent method'",
")",
";",
"}",
"}",
"return",
"object",
";",
"}"
] | Find the next object up the prototype chain that has a different implementation of the method. | [
"Find",
"the",
"next",
"object",
"up",
"the",
"prototype",
"chain",
"that",
"has",
"a",
"different",
"implementation",
"of",
"the",
"method",
"."
] | 79df8de5ec268879e50ec1e12e78b62a13b4a427 | https://github.com/SwirlNetworks/discus/blob/79df8de5ec268879e50ec1e12e78b62a13b4a427/src/super.js#L5-L15 |
54,180 | teabyii/qa | lib/index.js | prompt | function prompt (config) {
const controller = new Controller()
return controller
.prompt(config)
.then(function (answer) {
controller.destroy()
return answer
})
} | javascript | function prompt (config) {
const controller = new Controller()
return controller
.prompt(config)
.then(function (answer) {
controller.destroy()
return answer
})
} | [
"function",
"prompt",
"(",
"config",
")",
"{",
"const",
"controller",
"=",
"new",
"Controller",
"(",
")",
"return",
"controller",
".",
"prompt",
"(",
"config",
")",
".",
"then",
"(",
"function",
"(",
"answer",
")",
"{",
"controller",
".",
"destroy",
"(",
")",
"return",
"answer",
"}",
")",
"}"
] | Prompt use not in `qa`, provide new constroller to take.
@param {Object} config
@returns {Promise} | [
"Prompt",
"use",
"not",
"in",
"qa",
"provide",
"new",
"constroller",
"to",
"take",
"."
] | 9224180dcb9e6b57c021f83b259316e84ebc573e | https://github.com/teabyii/qa/blob/9224180dcb9e6b57c021f83b259316e84ebc573e/lib/index.js#L10-L18 |
54,181 | teabyii/qa | lib/index.js | function (gen) {
var main = co.wrap(gen)
const controller = new Controller()
function finish () {
controller.destroy()
return controller.answers
}
function error (error) {
console.error(error.stack)
}
return main(function (config) {
return controller.prompt(config)
}, register).then(finish, error)
} | javascript | function (gen) {
var main = co.wrap(gen)
const controller = new Controller()
function finish () {
controller.destroy()
return controller.answers
}
function error (error) {
console.error(error.stack)
}
return main(function (config) {
return controller.prompt(config)
}, register).then(finish, error)
} | [
"function",
"(",
"gen",
")",
"{",
"var",
"main",
"=",
"co",
".",
"wrap",
"(",
"gen",
")",
"const",
"controller",
"=",
"new",
"Controller",
"(",
")",
"function",
"finish",
"(",
")",
"{",
"controller",
".",
"destroy",
"(",
")",
"return",
"controller",
".",
"answers",
"}",
"function",
"error",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"error",
".",
"stack",
")",
"}",
"return",
"main",
"(",
"function",
"(",
"config",
")",
"{",
"return",
"controller",
".",
"prompt",
"(",
"config",
")",
"}",
",",
"register",
")",
".",
"then",
"(",
"finish",
",",
"error",
")",
"}"
] | Method to run a generator for interative command line program.
@param {Generator} gen The generator to put program.
@returns {Promise} The Promise to end program and take answers. | [
"Method",
"to",
"run",
"a",
"generator",
"for",
"interative",
"command",
"line",
"program",
"."
] | 9224180dcb9e6b57c021f83b259316e84ebc573e | https://github.com/teabyii/qa/blob/9224180dcb9e6b57c021f83b259316e84ebc573e/lib/index.js#L37-L53 |
|
54,182 | fczbkk/style-properties | src/parse-property-value.js | convertColorComponent | function convertColorComponent (input) {
let result = input.toString(16);
if (result.length < 2) {
result = '0' + result
}
return result;
} | javascript | function convertColorComponent (input) {
let result = input.toString(16);
if (result.length < 2) {
result = '0' + result
}
return result;
} | [
"function",
"convertColorComponent",
"(",
"input",
")",
"{",
"let",
"result",
"=",
"input",
".",
"toString",
"(",
"16",
")",
";",
"if",
"(",
"result",
".",
"length",
"<",
"2",
")",
"{",
"result",
"=",
"'0'",
"+",
"result",
"}",
"return",
"result",
";",
"}"
] | converts number in base 10 to base 16, adds padding zero if needed | [
"converts",
"number",
"in",
"base",
"10",
"to",
"base",
"16",
"adds",
"padding",
"zero",
"if",
"needed"
] | d4e7b271001c0cd555534eb4a3bfde7795c58eed | https://github.com/fczbkk/style-properties/blob/d4e7b271001c0cd555534eb4a3bfde7795c58eed/src/parse-property-value.js#L6-L12 |
54,183 | liuhaixia888/fis-parser-less-px2rem | index.js | function(s1, s2, s5, val){
return s1 ?
[s1 + s2 + val, 'px' + s5].join(''):
[s2 + val, 'px' + s5].join('');
} | javascript | function(s1, s2, s5, val){
return s1 ?
[s1 + s2 + val, 'px' + s5].join(''):
[s2 + val, 'px' + s5].join('');
} | [
"function",
"(",
"s1",
",",
"s2",
",",
"s5",
",",
"val",
")",
"{",
"return",
"s1",
"?",
"[",
"s1",
"+",
"s2",
"+",
"val",
",",
"'px'",
"+",
"s5",
"]",
".",
"join",
"(",
"''",
")",
":",
"[",
"s2",
"+",
"val",
",",
"'px'",
"+",
"s5",
"]",
".",
"join",
"(",
"''",
")",
";",
"}"
] | REM => PX | [
"REM",
"=",
">",
"PX"
] | b56011a0749e607828c3a04e0b846fe727a8b18f | https://github.com/liuhaixia888/fis-parser-less-px2rem/blob/b56011a0749e607828c3a04e0b846fe727a8b18f/index.js#L24-L28 |
|
54,184 | carrascoMDD/protractor-relaunchable | lib/taskScheduler.js | function(capability, specLists) {
this.capability = capability;
this.numRunningInstances = 0;
this.maxInstance = capability.maxInstances || 1;
this.specsIndex = 0;
this.specLists = specLists;
} | javascript | function(capability, specLists) {
this.capability = capability;
this.numRunningInstances = 0;
this.maxInstance = capability.maxInstances || 1;
this.specsIndex = 0;
this.specLists = specLists;
} | [
"function",
"(",
"capability",
",",
"specLists",
")",
"{",
"this",
".",
"capability",
"=",
"capability",
";",
"this",
".",
"numRunningInstances",
"=",
"0",
";",
"this",
".",
"maxInstance",
"=",
"capability",
".",
"maxInstances",
"||",
"1",
";",
"this",
".",
"specsIndex",
"=",
"0",
";",
"this",
".",
"specLists",
"=",
"specLists",
";",
"}"
] | A queue of specs for a particular capacity | [
"A",
"queue",
"of",
"specs",
"for",
"a",
"particular",
"capacity"
] | c18e17ecd8b5b036217f87680800c6e14b47361f | https://github.com/carrascoMDD/protractor-relaunchable/blob/c18e17ecd8b5b036217f87680800c6e14b47361f/lib/taskScheduler.js#L10-L16 |
|
54,185 | MRN-Code/decentralized-laplacian-ridge-regression | src/local.js | addBias | function addBias(arr) {
if (!Array.isArray(arr) || !arr.length) {
throw new Error(`Expected ${arr} to be an array with length`);
} else if (!arr.every(Array.isArray)) {
throw new Error(`Expected every item of ${arr} to be an array`);
}
return arr.map(row => [1].concat(row));
} | javascript | function addBias(arr) {
if (!Array.isArray(arr) || !arr.length) {
throw new Error(`Expected ${arr} to be an array with length`);
} else if (!arr.every(Array.isArray)) {
throw new Error(`Expected every item of ${arr} to be an array`);
}
return arr.map(row => [1].concat(row));
} | [
"function",
"addBias",
"(",
"arr",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"arr",
")",
"||",
"!",
"arr",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"arr",
"}",
"`",
")",
";",
"}",
"else",
"if",
"(",
"!",
"arr",
".",
"every",
"(",
"Array",
".",
"isArray",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"arr",
"}",
"`",
")",
";",
"}",
"return",
"arr",
".",
"map",
"(",
"row",
"=>",
"[",
"1",
"]",
".",
"concat",
"(",
"row",
")",
")",
";",
"}"
] | Add bias.
@param {?} A
@returns {Array} | [
"Add",
"bias",
"."
] | 38fbd789c90d0b6b7e320cca735b51c246179f3b | https://github.com/MRN-Code/decentralized-laplacian-ridge-regression/blob/38fbd789c90d0b6b7e320cca735b51c246179f3b/src/local.js#L16-L24 |
54,186 | MRN-Code/decentralized-laplacian-ridge-regression | src/local.js | getNormalizedTags | function getNormalizedTags(tags) {
return Object.keys(tags).sort().reduce((memo, tag) => {
const value = tags[tag];
if (typeof value === 'boolean') {
return memo.concat(value === true ? 1 : -1);
} else if (typeof value === 'number') {
return memo.concat(value);
}
return memo;
}, []);
} | javascript | function getNormalizedTags(tags) {
return Object.keys(tags).sort().reduce((memo, tag) => {
const value = tags[tag];
if (typeof value === 'boolean') {
return memo.concat(value === true ? 1 : -1);
} else if (typeof value === 'number') {
return memo.concat(value);
}
return memo;
}, []);
} | [
"function",
"getNormalizedTags",
"(",
"tags",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"tags",
")",
".",
"sort",
"(",
")",
".",
"reduce",
"(",
"(",
"memo",
",",
"tag",
")",
"=>",
"{",
"const",
"value",
"=",
"tags",
"[",
"tag",
"]",
";",
"if",
"(",
"typeof",
"value",
"===",
"'boolean'",
")",
"{",
"return",
"memo",
".",
"concat",
"(",
"value",
"===",
"true",
"?",
"1",
":",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"value",
"===",
"'number'",
")",
"{",
"return",
"memo",
".",
"concat",
"(",
"value",
")",
";",
"}",
"return",
"memo",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Get normalized co-variate values.
@todo This ignores non-numeric and non-boolean tag values. Determine
an effective way to map strings and non-primitives to numbers.
@param {Object} tags Hash of tag names to tag values
@returns {Array} | [
"Get",
"normalized",
"co",
"-",
"variate",
"values",
"."
] | 38fbd789c90d0b6b7e320cca735b51c246179f3b | https://github.com/MRN-Code/decentralized-laplacian-ridge-regression/blob/38fbd789c90d0b6b7e320cca735b51c246179f3b/src/local.js#L35-L47 |
54,187 | tanem/stweam | lib/stweam.js | Stweam | function Stweam(opts) {
stream.Transform.call(this);
opts = opts || {};
if (!opts.consumerKey) throw new Error('consumer key is required');
if (!opts.consumerSecret) throw new Error('consumer secret is required');
if (!opts.token) throw new Error('token is required');
if (!opts.tokenSecret) throw new Error('token secret is required');
this.consumerKey = opts.consumerKey;
this.consumerSecret = opts.consumerSecret;
this.token = opts.token;
this.tokenSecret = opts.tokenSecret;
this._keywords = '';
this._language = 'en';
this._follow = '';
this._initBackoffs();
} | javascript | function Stweam(opts) {
stream.Transform.call(this);
opts = opts || {};
if (!opts.consumerKey) throw new Error('consumer key is required');
if (!opts.consumerSecret) throw new Error('consumer secret is required');
if (!opts.token) throw new Error('token is required');
if (!opts.tokenSecret) throw new Error('token secret is required');
this.consumerKey = opts.consumerKey;
this.consumerSecret = opts.consumerSecret;
this.token = opts.token;
this.tokenSecret = opts.tokenSecret;
this._keywords = '';
this._language = 'en';
this._follow = '';
this._initBackoffs();
} | [
"function",
"Stweam",
"(",
"opts",
")",
"{",
"stream",
".",
"Transform",
".",
"call",
"(",
"this",
")",
";",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"consumerKey",
")",
"throw",
"new",
"Error",
"(",
"'consumer key is required'",
")",
";",
"if",
"(",
"!",
"opts",
".",
"consumerSecret",
")",
"throw",
"new",
"Error",
"(",
"'consumer secret is required'",
")",
";",
"if",
"(",
"!",
"opts",
".",
"token",
")",
"throw",
"new",
"Error",
"(",
"'token is required'",
")",
";",
"if",
"(",
"!",
"opts",
".",
"tokenSecret",
")",
"throw",
"new",
"Error",
"(",
"'token secret is required'",
")",
";",
"this",
".",
"consumerKey",
"=",
"opts",
".",
"consumerKey",
";",
"this",
".",
"consumerSecret",
"=",
"opts",
".",
"consumerSecret",
";",
"this",
".",
"token",
"=",
"opts",
".",
"token",
";",
"this",
".",
"tokenSecret",
"=",
"opts",
".",
"tokenSecret",
";",
"this",
".",
"_keywords",
"=",
"''",
";",
"this",
".",
"_language",
"=",
"'en'",
";",
"this",
".",
"_follow",
"=",
"''",
";",
"this",
".",
"_initBackoffs",
"(",
")",
";",
"}"
] | Initialise a new `Stweam` with the given `opts`.
@param {String} opts.consumerKey
@param {String} opts.consumerSecret
@param {String} opts.token
@param {String} opts.tokenSecret
@api public | [
"Initialise",
"a",
"new",
"Stweam",
"with",
"the",
"given",
"opts",
"."
] | 287469074655f7a120684b121876b470525bf963 | https://github.com/tanem/stweam/blob/287469074655f7a120684b121876b470525bf963/lib/stweam.js#L22-L37 |
54,188 | azendal/argon | argon/model.js | all | function all(callback) {
var Model = this;
var request = {
find : 'find',
model : Model
};
this.dispatch('beforeAll');
this.storage.find(request, function findCallback(data) {
if (callback) {
callback(data);
Model.dispatch('afterAll');
}
});
return this;
} | javascript | function all(callback) {
var Model = this;
var request = {
find : 'find',
model : Model
};
this.dispatch('beforeAll');
this.storage.find(request, function findCallback(data) {
if (callback) {
callback(data);
Model.dispatch('afterAll');
}
});
return this;
} | [
"function",
"all",
"(",
"callback",
")",
"{",
"var",
"Model",
"=",
"this",
";",
"var",
"request",
"=",
"{",
"find",
":",
"'find'",
",",
"model",
":",
"Model",
"}",
";",
"this",
".",
"dispatch",
"(",
"'beforeAll'",
")",
";",
"this",
".",
"storage",
".",
"find",
"(",
"request",
",",
"function",
"findCallback",
"(",
"data",
")",
"{",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"Model",
".",
"dispatch",
"(",
"'afterAll'",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Fetches all records of a given Model and creates the instances.
@method all <public, static>
@argument callback <optional> [Function] method to handle data.
@return [Argon.Model]. | [
"Fetches",
"all",
"records",
"of",
"a",
"given",
"Model",
"and",
"creates",
"the",
"instances",
"."
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L24-L40 |
54,189 | azendal/argon | argon/model.js | find | function find(id, callback) {
var Model, request;
Model = this;
request = {
action : 'findOne',
model : Model,
params : {
id : id
}
};
this.storage.findOne(request, function findOneCallback(data) {
if (callback) {
callback(data);
}
});
return this;
} | javascript | function find(id, callback) {
var Model, request;
Model = this;
request = {
action : 'findOne',
model : Model,
params : {
id : id
}
};
this.storage.findOne(request, function findOneCallback(data) {
if (callback) {
callback(data);
}
});
return this;
} | [
"function",
"find",
"(",
"id",
",",
"callback",
")",
"{",
"var",
"Model",
",",
"request",
";",
"Model",
"=",
"this",
";",
"request",
"=",
"{",
"action",
":",
"'findOne'",
",",
"model",
":",
"Model",
",",
"params",
":",
"{",
"id",
":",
"id",
"}",
"}",
";",
"this",
".",
"storage",
".",
"findOne",
"(",
"request",
",",
"function",
"findOneCallback",
"(",
"data",
")",
"{",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Fetches one record of a given Model and creates the instance.
@method find <public, static>
@argument id <required> [Object] the id of the record.
@argument callback <optional> [Function] method to handle data.
@return [Argon.Model]. | [
"Fetches",
"one",
"record",
"of",
"a",
"given",
"Model",
"and",
"creates",
"the",
"instance",
"."
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L49-L66 |
54,190 | azendal/argon | argon/model.js | init | function init(properties) {
this.eventListeners = [];
if (typeof properties !== 'undefined') {
Object.keys(properties).forEach(function (property) {
this[property] = properties[property];
}, this);
}
return this;
} | javascript | function init(properties) {
this.eventListeners = [];
if (typeof properties !== 'undefined') {
Object.keys(properties).forEach(function (property) {
this[property] = properties[property];
}, this);
}
return this;
} | [
"function",
"init",
"(",
"properties",
")",
"{",
"this",
".",
"eventListeners",
"=",
"[",
"]",
";",
"if",
"(",
"typeof",
"properties",
"!==",
"'undefined'",
")",
"{",
"Object",
".",
"keys",
"(",
"properties",
")",
".",
"forEach",
"(",
"function",
"(",
"property",
")",
"{",
"this",
"[",
"property",
"]",
"=",
"properties",
"[",
"property",
"]",
";",
"}",
",",
"this",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Object initializer, this method server as the real constructor
@method init <public>
@argument properties <optional> [Object] ({}) the attributes for the model isntance | [
"Object",
"initializer",
"this",
"method",
"server",
"as",
"the",
"real",
"constructor"
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L75-L85 |
54,191 | azendal/argon | argon/model.js | setProperty | function setProperty(property, newValue) {
var originalValue;
if (newValue != originalValue) {
originalValue = this[property];
this[property] = newValue;
this.dispatch('change:' + property, {
originalValue : originalValue,
newValue : newValue
});
}
return this;
} | javascript | function setProperty(property, newValue) {
var originalValue;
if (newValue != originalValue) {
originalValue = this[property];
this[property] = newValue;
this.dispatch('change:' + property, {
originalValue : originalValue,
newValue : newValue
});
}
return this;
} | [
"function",
"setProperty",
"(",
"property",
",",
"newValue",
")",
"{",
"var",
"originalValue",
";",
"if",
"(",
"newValue",
"!=",
"originalValue",
")",
"{",
"originalValue",
"=",
"this",
"[",
"property",
"]",
";",
"this",
"[",
"property",
"]",
"=",
"newValue",
";",
"this",
".",
"dispatch",
"(",
"'change:'",
"+",
"property",
",",
"{",
"originalValue",
":",
"originalValue",
",",
"newValue",
":",
"newValue",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Sets the value of a property.
@method setProperty <public>
@argument property <required> [String] the property to write.
@argument newValue <required> [String] the value for the property.
@return [Object] instance of the model. | [
"Sets",
"the",
"value",
"of",
"a",
"property",
"."
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L104-L118 |
54,192 | azendal/argon | argon/model.js | save | function save(callback) {
var model, request;
model = this;
this.constructor.dispatch('beforeSave', {
data : {
model : this
}
});
this.dispatch('beforeSave');
this.isValid(function (isValid) {
if (isValid) {
if (model.hasOwnProperty('id') && model.id !== '') {
request = {
action : 'update',
data : model,
model : model.constructor
};
model.constructor.storage.update(request, function updateCallback(data) {
model.constructor.dispatch('afterSave', {
data : {
model : model
}
});
model.dispatch('afterSave');
if (callback) {
callback(data);
}
});
}
else {
request = {
action : 'create',
data : model,
model : model.constructor
};
model.constructor.storage.create(request, function createCallback(data) {
model.constructor.dispatch('afterSave', {
data : {
model : model
}
});
model.dispatch('afterSave');
if (callback) {
callback(data);
}
});
}
} else {
if (callback) {
callback(data);
}
}
});
} | javascript | function save(callback) {
var model, request;
model = this;
this.constructor.dispatch('beforeSave', {
data : {
model : this
}
});
this.dispatch('beforeSave');
this.isValid(function (isValid) {
if (isValid) {
if (model.hasOwnProperty('id') && model.id !== '') {
request = {
action : 'update',
data : model,
model : model.constructor
};
model.constructor.storage.update(request, function updateCallback(data) {
model.constructor.dispatch('afterSave', {
data : {
model : model
}
});
model.dispatch('afterSave');
if (callback) {
callback(data);
}
});
}
else {
request = {
action : 'create',
data : model,
model : model.constructor
};
model.constructor.storage.create(request, function createCallback(data) {
model.constructor.dispatch('afterSave', {
data : {
model : model
}
});
model.dispatch('afterSave');
if (callback) {
callback(data);
}
});
}
} else {
if (callback) {
callback(data);
}
}
});
} | [
"function",
"save",
"(",
"callback",
")",
"{",
"var",
"model",
",",
"request",
";",
"model",
"=",
"this",
";",
"this",
".",
"constructor",
".",
"dispatch",
"(",
"'beforeSave'",
",",
"{",
"data",
":",
"{",
"model",
":",
"this",
"}",
"}",
")",
";",
"this",
".",
"dispatch",
"(",
"'beforeSave'",
")",
";",
"this",
".",
"isValid",
"(",
"function",
"(",
"isValid",
")",
"{",
"if",
"(",
"isValid",
")",
"{",
"if",
"(",
"model",
".",
"hasOwnProperty",
"(",
"'id'",
")",
"&&",
"model",
".",
"id",
"!==",
"''",
")",
"{",
"request",
"=",
"{",
"action",
":",
"'update'",
",",
"data",
":",
"model",
",",
"model",
":",
"model",
".",
"constructor",
"}",
";",
"model",
".",
"constructor",
".",
"storage",
".",
"update",
"(",
"request",
",",
"function",
"updateCallback",
"(",
"data",
")",
"{",
"model",
".",
"constructor",
".",
"dispatch",
"(",
"'afterSave'",
",",
"{",
"data",
":",
"{",
"model",
":",
"model",
"}",
"}",
")",
";",
"model",
".",
"dispatch",
"(",
"'afterSave'",
")",
";",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"request",
"=",
"{",
"action",
":",
"'create'",
",",
"data",
":",
"model",
",",
"model",
":",
"model",
".",
"constructor",
"}",
";",
"model",
".",
"constructor",
".",
"storage",
".",
"create",
"(",
"request",
",",
"function",
"createCallback",
"(",
"data",
")",
"{",
"model",
".",
"constructor",
".",
"dispatch",
"(",
"'afterSave'",
",",
"{",
"data",
":",
"{",
"model",
":",
"model",
"}",
"}",
")",
";",
"model",
".",
"dispatch",
"(",
"'afterSave'",
")",
";",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"data",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Saves the model to storage.
@method save <public>
@argument callback <required> [Function] function to manage response.
@return Noting. | [
"Saves",
"the",
"model",
"to",
"storage",
"."
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L126-L185 |
54,193 | azendal/argon | argon/model.js | destroy | function destroy(callback) {
var model = this;
var request = {
action : 'remove',
model : model.constructor,
data : this
};
this.dispatch('beforeDestroy');
this.constructor.storage.remove(request, function destroyCallback() {
model.setProperty('id', null);
model.dispatch('afterDestroy');
if (callback) {
callback(model);
}
});
} | javascript | function destroy(callback) {
var model = this;
var request = {
action : 'remove',
model : model.constructor,
data : this
};
this.dispatch('beforeDestroy');
this.constructor.storage.remove(request, function destroyCallback() {
model.setProperty('id', null);
model.dispatch('afterDestroy');
if (callback) {
callback(model);
}
});
} | [
"function",
"destroy",
"(",
"callback",
")",
"{",
"var",
"model",
"=",
"this",
";",
"var",
"request",
"=",
"{",
"action",
":",
"'remove'",
",",
"model",
":",
"model",
".",
"constructor",
",",
"data",
":",
"this",
"}",
";",
"this",
".",
"dispatch",
"(",
"'beforeDestroy'",
")",
";",
"this",
".",
"constructor",
".",
"storage",
".",
"remove",
"(",
"request",
",",
"function",
"destroyCallback",
"(",
")",
"{",
"model",
".",
"setProperty",
"(",
"'id'",
",",
"null",
")",
";",
"model",
".",
"dispatch",
"(",
"'afterDestroy'",
")",
";",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"model",
")",
";",
"}",
"}",
")",
";",
"}"
] | Removes a record from storage.
@method destroy <public>
@argument callback [Function] function to manage response.
@return Noting. | [
"Removes",
"a",
"record",
"from",
"storage",
"."
] | 0cfd3a3b3731b69abca55c956c757476779ec1bd | https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/model.js#L193-L209 |
54,194 | sebv/mocha-bdd-with-opts | common.js | function(mocha, test) {
test.parent._onlyTests = test.parent._onlyTests.concat(test);
mocha.options.hasOnly = true;
return test;
} | javascript | function(mocha, test) {
test.parent._onlyTests = test.parent._onlyTests.concat(test);
mocha.options.hasOnly = true;
return test;
} | [
"function",
"(",
"mocha",
",",
"test",
")",
"{",
"test",
".",
"parent",
".",
"_onlyTests",
"=",
"test",
".",
"parent",
".",
"_onlyTests",
".",
"concat",
"(",
"test",
")",
";",
"mocha",
".",
"options",
".",
"hasOnly",
"=",
"true",
";",
"return",
"test",
";",
"}"
] | Exclusive test-case.
@param {Object} mocha
@param {Function} test
@returns {*} | [
"Exclusive",
"test",
"-",
"case",
"."
] | bc15bb96aa2ebda5b4427f8729b4e1cc5da69396 | https://github.com/sebv/mocha-bdd-with-opts/blob/bc15bb96aa2ebda5b4427f8729b4e1cc5da69396/common.js#L139-L143 |
|
54,195 | cirocosta/yaspm | src/Machines.js | Machines | function Machines (sigTerm) {
if (!(this instanceof Machines))
return new Machines(sigTerm);
this._sigTerm = sigTerm;
this._devices = {};
EventEmitter.call(this);
} | javascript | function Machines (sigTerm) {
if (!(this instanceof Machines))
return new Machines(sigTerm);
this._sigTerm = sigTerm;
this._devices = {};
EventEmitter.call(this);
} | [
"function",
"Machines",
"(",
"sigTerm",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Machines",
")",
")",
"return",
"new",
"Machines",
"(",
"sigTerm",
")",
";",
"this",
".",
"_sigTerm",
"=",
"sigTerm",
";",
"this",
".",
"_devices",
"=",
"{",
"}",
";",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"}"
] | Describes the conjunction of machines to
search for.
emits:
- removeddevice,
- device,
- invaliddevice,
- validdevice.
@param {string} sigTerm signature string to
match. | [
"Describes",
"the",
"conjunction",
"of",
"machines",
"to",
"search",
"for",
"."
] | 676524906425ba99b1e6f95a75ce4a82501a0ee9 | https://github.com/cirocosta/yaspm/blob/676524906425ba99b1e6f95a75ce4a82501a0ee9/src/Machines.js#L24-L32 |
54,196 | deanlandolt/bytespace | index.js | addHook | function addHook(hooks, hook) {
hooks.push(hook)
return function () {
var i = hooks.indexOf(hook)
if (i >= 0) return hooks.splice(i, 1)
}
} | javascript | function addHook(hooks, hook) {
hooks.push(hook)
return function () {
var i = hooks.indexOf(hook)
if (i >= 0) return hooks.splice(i, 1)
}
} | [
"function",
"addHook",
"(",
"hooks",
",",
"hook",
")",
"{",
"hooks",
".",
"push",
"(",
"hook",
")",
"return",
"function",
"(",
")",
"{",
"var",
"i",
"=",
"hooks",
".",
"indexOf",
"(",
"hook",
")",
"if",
"(",
"i",
">=",
"0",
")",
"return",
"hooks",
".",
"splice",
"(",
"i",
",",
"1",
")",
"}",
"}"
] | helper to register pre and post commit hooks | [
"helper",
"to",
"register",
"pre",
"and",
"post",
"commit",
"hooks"
] | 3d3b92d5a8999eedf766fea62bfa7f5643fd467d | https://github.com/deanlandolt/bytespace/blob/3d3b92d5a8999eedf766fea62bfa7f5643fd467d/index.js#L150-L156 |
54,197 | deanlandolt/bytespace | index.js | decodeStream | function decodeStream(opts) {
opts || (opts = {})
var stream = Transform({ objectMode: true })
stream._transform = function (data, _, cb) {
try {
// decode keys even when keys or values aren't requested specifically
if ((opts.keys && opts.values) || (!opts.keys && !opts.values)) {
data.key = ns.decode(data.key, opts)
}
else if (opts.keys) {
data = ns.decode(data, opts)
}
}
catch (err) {
return cb(err)
}
cb(null, data)
}
return stream
} | javascript | function decodeStream(opts) {
opts || (opts = {})
var stream = Transform({ objectMode: true })
stream._transform = function (data, _, cb) {
try {
// decode keys even when keys or values aren't requested specifically
if ((opts.keys && opts.values) || (!opts.keys && !opts.values)) {
data.key = ns.decode(data.key, opts)
}
else if (opts.keys) {
data = ns.decode(data, opts)
}
}
catch (err) {
return cb(err)
}
cb(null, data)
}
return stream
} | [
"function",
"decodeStream",
"(",
"opts",
")",
"{",
"opts",
"||",
"(",
"opts",
"=",
"{",
"}",
")",
"var",
"stream",
"=",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
"}",
")",
"stream",
".",
"_transform",
"=",
"function",
"(",
"data",
",",
"_",
",",
"cb",
")",
"{",
"try",
"{",
"// decode keys even when keys or values aren't requested specifically",
"if",
"(",
"(",
"opts",
".",
"keys",
"&&",
"opts",
".",
"values",
")",
"||",
"(",
"!",
"opts",
".",
"keys",
"&&",
"!",
"opts",
".",
"values",
")",
")",
"{",
"data",
".",
"key",
"=",
"ns",
".",
"decode",
"(",
"data",
".",
"key",
",",
"opts",
")",
"}",
"else",
"if",
"(",
"opts",
".",
"keys",
")",
"{",
"data",
"=",
"ns",
".",
"decode",
"(",
"data",
",",
"opts",
")",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
"}",
"cb",
"(",
"null",
",",
"data",
")",
"}",
"return",
"stream",
"}"
] | transform stream to decode data keys | [
"transform",
"stream",
"to",
"decode",
"data",
"keys"
] | 3d3b92d5a8999eedf766fea62bfa7f5643fd467d | https://github.com/deanlandolt/bytespace/blob/3d3b92d5a8999eedf766fea62bfa7f5643fd467d/index.js#L284-L305 |
54,198 | Irrelon/overload | Overload.js | function (def) {
if (def) {
var self = this,
index,
count,
tmpDef,
defNewKey,
sigIndex,
signatures;
if (!(def instanceof Array)) {
tmpDef = {};
// Def is an object, make sure all prop names are devoid of spaces
for (index in def) {
if (def.hasOwnProperty(index)) {
defNewKey = index.replace(/ /g, '');
// Check if the definition array has a * string in it
if (defNewKey.indexOf('*') === -1) {
// No * found
tmpDef[defNewKey] = def[index];
} else {
// A * was found, generate the different signatures that this
// definition could represent
signatures = this.generateSignaturePermutations(defNewKey);
for (sigIndex = 0; sigIndex < signatures.length; sigIndex++) {
if (!tmpDef[signatures[sigIndex]]) {
tmpDef[signatures[sigIndex]] = def[index];
}
}
}
}
}
def = tmpDef;
}
return function () {
var arr = [],
lookup,
type;
// Check if we are being passed a key/function object or an array of functions
if (def instanceof Array) {
// We were passed an array of functions
count = def.length;
for (index = 0; index < count; index++) {
if (def[index].length === arguments.length) {
return self.callExtend(this, '$main', def, def[index], arguments);
}
}
} else {
// Generate lookup key from arguments
// Copy arguments to an array
for (index = 0; index < arguments.length; index++) {
type = typeof arguments[index];
// Handle detecting arrays
if (type === 'object' && arguments[index] instanceof Array) {
type = 'array';
}
// Handle been presented with a single undefined argument
if (arguments.length === 1 && type === 'undefined') {
break;
}
// Add the type to the argument types array
arr.push(type);
}
lookup = arr.join(',');
// Check for an exact lookup match
if (def[lookup]) {
return self.callExtend(this, '$main', def, def[lookup], arguments);
} else {
for (index = arr.length; index >= 0; index--) {
// Get the closest match
lookup = arr.slice(0, index).join(',');
if (def[lookup + ',...']) {
// Matched against arguments + "any other"
return self.callExtend(this, '$main', def, def[lookup + ',...'], arguments);
}
}
}
}
throw('Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: ' + JSON.stringify(arr));
};
}
return function () {};
} | javascript | function (def) {
if (def) {
var self = this,
index,
count,
tmpDef,
defNewKey,
sigIndex,
signatures;
if (!(def instanceof Array)) {
tmpDef = {};
// Def is an object, make sure all prop names are devoid of spaces
for (index in def) {
if (def.hasOwnProperty(index)) {
defNewKey = index.replace(/ /g, '');
// Check if the definition array has a * string in it
if (defNewKey.indexOf('*') === -1) {
// No * found
tmpDef[defNewKey] = def[index];
} else {
// A * was found, generate the different signatures that this
// definition could represent
signatures = this.generateSignaturePermutations(defNewKey);
for (sigIndex = 0; sigIndex < signatures.length; sigIndex++) {
if (!tmpDef[signatures[sigIndex]]) {
tmpDef[signatures[sigIndex]] = def[index];
}
}
}
}
}
def = tmpDef;
}
return function () {
var arr = [],
lookup,
type;
// Check if we are being passed a key/function object or an array of functions
if (def instanceof Array) {
// We were passed an array of functions
count = def.length;
for (index = 0; index < count; index++) {
if (def[index].length === arguments.length) {
return self.callExtend(this, '$main', def, def[index], arguments);
}
}
} else {
// Generate lookup key from arguments
// Copy arguments to an array
for (index = 0; index < arguments.length; index++) {
type = typeof arguments[index];
// Handle detecting arrays
if (type === 'object' && arguments[index] instanceof Array) {
type = 'array';
}
// Handle been presented with a single undefined argument
if (arguments.length === 1 && type === 'undefined') {
break;
}
// Add the type to the argument types array
arr.push(type);
}
lookup = arr.join(',');
// Check for an exact lookup match
if (def[lookup]) {
return self.callExtend(this, '$main', def, def[lookup], arguments);
} else {
for (index = arr.length; index >= 0; index--) {
// Get the closest match
lookup = arr.slice(0, index).join(',');
if (def[lookup + ',...']) {
// Matched against arguments + "any other"
return self.callExtend(this, '$main', def, def[lookup + ',...'], arguments);
}
}
}
}
throw('Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: ' + JSON.stringify(arr));
};
}
return function () {};
} | [
"function",
"(",
"def",
")",
"{",
"if",
"(",
"def",
")",
"{",
"var",
"self",
"=",
"this",
",",
"index",
",",
"count",
",",
"tmpDef",
",",
"defNewKey",
",",
"sigIndex",
",",
"signatures",
";",
"if",
"(",
"!",
"(",
"def",
"instanceof",
"Array",
")",
")",
"{",
"tmpDef",
"=",
"{",
"}",
";",
"// Def is an object, make sure all prop names are devoid of spaces",
"for",
"(",
"index",
"in",
"def",
")",
"{",
"if",
"(",
"def",
".",
"hasOwnProperty",
"(",
"index",
")",
")",
"{",
"defNewKey",
"=",
"index",
".",
"replace",
"(",
"/",
" ",
"/",
"g",
",",
"''",
")",
";",
"// Check if the definition array has a * string in it",
"if",
"(",
"defNewKey",
".",
"indexOf",
"(",
"'*'",
")",
"===",
"-",
"1",
")",
"{",
"// No * found",
"tmpDef",
"[",
"defNewKey",
"]",
"=",
"def",
"[",
"index",
"]",
";",
"}",
"else",
"{",
"// A * was found, generate the different signatures that this",
"// definition could represent",
"signatures",
"=",
"this",
".",
"generateSignaturePermutations",
"(",
"defNewKey",
")",
";",
"for",
"(",
"sigIndex",
"=",
"0",
";",
"sigIndex",
"<",
"signatures",
".",
"length",
";",
"sigIndex",
"++",
")",
"{",
"if",
"(",
"!",
"tmpDef",
"[",
"signatures",
"[",
"sigIndex",
"]",
"]",
")",
"{",
"tmpDef",
"[",
"signatures",
"[",
"sigIndex",
"]",
"]",
"=",
"def",
"[",
"index",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"def",
"=",
"tmpDef",
";",
"}",
"return",
"function",
"(",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
",",
"lookup",
",",
"type",
";",
"// Check if we are being passed a key/function object or an array of functions",
"if",
"(",
"def",
"instanceof",
"Array",
")",
"{",
"// We were passed an array of functions",
"count",
"=",
"def",
".",
"length",
";",
"for",
"(",
"index",
"=",
"0",
";",
"index",
"<",
"count",
";",
"index",
"++",
")",
"{",
"if",
"(",
"def",
"[",
"index",
"]",
".",
"length",
"===",
"arguments",
".",
"length",
")",
"{",
"return",
"self",
".",
"callExtend",
"(",
"this",
",",
"'$main'",
",",
"def",
",",
"def",
"[",
"index",
"]",
",",
"arguments",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Generate lookup key from arguments",
"// Copy arguments to an array",
"for",
"(",
"index",
"=",
"0",
";",
"index",
"<",
"arguments",
".",
"length",
";",
"index",
"++",
")",
"{",
"type",
"=",
"typeof",
"arguments",
"[",
"index",
"]",
";",
"// Handle detecting arrays",
"if",
"(",
"type",
"===",
"'object'",
"&&",
"arguments",
"[",
"index",
"]",
"instanceof",
"Array",
")",
"{",
"type",
"=",
"'array'",
";",
"}",
"// Handle been presented with a single undefined argument",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
"&&",
"type",
"===",
"'undefined'",
")",
"{",
"break",
";",
"}",
"// Add the type to the argument types array",
"arr",
".",
"push",
"(",
"type",
")",
";",
"}",
"lookup",
"=",
"arr",
".",
"join",
"(",
"','",
")",
";",
"// Check for an exact lookup match",
"if",
"(",
"def",
"[",
"lookup",
"]",
")",
"{",
"return",
"self",
".",
"callExtend",
"(",
"this",
",",
"'$main'",
",",
"def",
",",
"def",
"[",
"lookup",
"]",
",",
"arguments",
")",
";",
"}",
"else",
"{",
"for",
"(",
"index",
"=",
"arr",
".",
"length",
";",
"index",
">=",
"0",
";",
"index",
"--",
")",
"{",
"// Get the closest match",
"lookup",
"=",
"arr",
".",
"slice",
"(",
"0",
",",
"index",
")",
".",
"join",
"(",
"','",
")",
";",
"if",
"(",
"def",
"[",
"lookup",
"+",
"',...'",
"]",
")",
"{",
"// Matched against arguments + \"any other\"",
"return",
"self",
".",
"callExtend",
"(",
"this",
",",
"'$main'",
",",
"def",
",",
"def",
"[",
"lookup",
"+",
"',...'",
"]",
",",
"arguments",
")",
";",
"}",
"}",
"}",
"}",
"throw",
"(",
"'Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: '",
"+",
"JSON",
".",
"stringify",
"(",
"arr",
")",
")",
";",
"}",
";",
"}",
"return",
"function",
"(",
")",
"{",
"}",
";",
"}"
] | Allows a method to accept overloaded calls with different parameters controlling
which passed overload function is called.
@param {Object} def
@returns {Function}
@constructor | [
"Allows",
"a",
"method",
"to",
"accept",
"overloaded",
"calls",
"with",
"different",
"parameters",
"controlling",
"which",
"passed",
"overload",
"function",
"is",
"called",
"."
] | cfa76f0e2c1112938c27364c031dae8d530183b8 | https://github.com/Irrelon/overload/blob/cfa76f0e2c1112938c27364c031dae8d530183b8/Overload.js#L10-L106 |
|
54,199 | hammy2899/circle-assign | src/internals.js | mergeObject | function mergeObject(target, source) {
// create a variable to hold the target object
// so it can be changed if its not an object
let targetObject = target;
let sourceObject = source;
if (!isObj(target)) {
targetObject = {};
}
if (!isObj(source)) {
sourceObject = {};
}
// get the object keys for the target and source objects
const targetKeys = Object.keys(targetObject);
const sourceKeys = Object.keys(sourceObject);
// create a empty object for the result
const result = {};
// go through all the target keys
targetKeys.forEach((key) => {
// check if the source object contains the key
if (sourceKeys.indexOf(key) !== -1) {
// check if the target value is null if it is
// set the result as the source value, this
// should be fine because if the source value
// is null it isn't overriding the target value
// and if it isn't null it is overriding
// as expected
if (targetObject[key] === null) {
result[key] = sourceObject[key];
} else if (isObj(targetObject[key])) {
// check if the source value is an object if
// it is then we need to merge both objects and
// set the result value to the merged object
if (isObj(sourceObject[key])) {
result[key] = mergeObject(targetObject[key], sourceObject[key]);
} else {
// if the source value isn't an object we can
// simply override the value
result[key] = sourceObject[key];
}
} else {
// if the target value isn't an object we can
// simply override the value
result[key] = sourceObject[key];
}
} else {
// if the source doesn't contain the key set the result
// as the original from the target
result[key] = targetObject[key];
}
});
// go through all the source keys
sourceKeys.forEach((key) => {
// if the target doesn't contain the key
// then the value is new and should be added
// to the result object
if (targetKeys.indexOf(key) === -1) {
result[key] = sourceObject[key];
}
});
return result;
} | javascript | function mergeObject(target, source) {
// create a variable to hold the target object
// so it can be changed if its not an object
let targetObject = target;
let sourceObject = source;
if (!isObj(target)) {
targetObject = {};
}
if (!isObj(source)) {
sourceObject = {};
}
// get the object keys for the target and source objects
const targetKeys = Object.keys(targetObject);
const sourceKeys = Object.keys(sourceObject);
// create a empty object for the result
const result = {};
// go through all the target keys
targetKeys.forEach((key) => {
// check if the source object contains the key
if (sourceKeys.indexOf(key) !== -1) {
// check if the target value is null if it is
// set the result as the source value, this
// should be fine because if the source value
// is null it isn't overriding the target value
// and if it isn't null it is overriding
// as expected
if (targetObject[key] === null) {
result[key] = sourceObject[key];
} else if (isObj(targetObject[key])) {
// check if the source value is an object if
// it is then we need to merge both objects and
// set the result value to the merged object
if (isObj(sourceObject[key])) {
result[key] = mergeObject(targetObject[key], sourceObject[key]);
} else {
// if the source value isn't an object we can
// simply override the value
result[key] = sourceObject[key];
}
} else {
// if the target value isn't an object we can
// simply override the value
result[key] = sourceObject[key];
}
} else {
// if the source doesn't contain the key set the result
// as the original from the target
result[key] = targetObject[key];
}
});
// go through all the source keys
sourceKeys.forEach((key) => {
// if the target doesn't contain the key
// then the value is new and should be added
// to the result object
if (targetKeys.indexOf(key) === -1) {
result[key] = sourceObject[key];
}
});
return result;
} | [
"function",
"mergeObject",
"(",
"target",
",",
"source",
")",
"{",
"// create a variable to hold the target object",
"// so it can be changed if its not an object",
"let",
"targetObject",
"=",
"target",
";",
"let",
"sourceObject",
"=",
"source",
";",
"if",
"(",
"!",
"isObj",
"(",
"target",
")",
")",
"{",
"targetObject",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"isObj",
"(",
"source",
")",
")",
"{",
"sourceObject",
"=",
"{",
"}",
";",
"}",
"// get the object keys for the target and source objects",
"const",
"targetKeys",
"=",
"Object",
".",
"keys",
"(",
"targetObject",
")",
";",
"const",
"sourceKeys",
"=",
"Object",
".",
"keys",
"(",
"sourceObject",
")",
";",
"// create a empty object for the result",
"const",
"result",
"=",
"{",
"}",
";",
"// go through all the target keys",
"targetKeys",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"// check if the source object contains the key",
"if",
"(",
"sourceKeys",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"{",
"// check if the target value is null if it is",
"// set the result as the source value, this",
"// should be fine because if the source value",
"// is null it isn't overriding the target value",
"// and if it isn't null it is overriding",
"// as expected",
"if",
"(",
"targetObject",
"[",
"key",
"]",
"===",
"null",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"sourceObject",
"[",
"key",
"]",
";",
"}",
"else",
"if",
"(",
"isObj",
"(",
"targetObject",
"[",
"key",
"]",
")",
")",
"{",
"// check if the source value is an object if",
"// it is then we need to merge both objects and",
"// set the result value to the merged object",
"if",
"(",
"isObj",
"(",
"sourceObject",
"[",
"key",
"]",
")",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"mergeObject",
"(",
"targetObject",
"[",
"key",
"]",
",",
"sourceObject",
"[",
"key",
"]",
")",
";",
"}",
"else",
"{",
"// if the source value isn't an object we can",
"// simply override the value",
"result",
"[",
"key",
"]",
"=",
"sourceObject",
"[",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"// if the target value isn't an object we can",
"// simply override the value",
"result",
"[",
"key",
"]",
"=",
"sourceObject",
"[",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"// if the source doesn't contain the key set the result",
"// as the original from the target",
"result",
"[",
"key",
"]",
"=",
"targetObject",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"// go through all the source keys",
"sourceKeys",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"// if the target doesn't contain the key",
"// then the value is new and should be added",
"// to the result object",
"if",
"(",
"targetKeys",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"result",
"[",
"key",
"]",
"=",
"sourceObject",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Merge the specified source object into the target object
@param {Object} target The base target object
@param {Object} source The object to merge into the target
@returns {Object} The merged object | [
"Merge",
"the",
"specified",
"source",
"object",
"into",
"the",
"target",
"object"
] | 4eb202021279b789ce758b3feae2417eb7f2ded5 | https://github.com/hammy2899/circle-assign/blob/4eb202021279b789ce758b3feae2417eb7f2ded5/src/internals.js#L21-L88 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.