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
|
---|---|---|---|---|---|---|---|---|---|---|---|
51,800 | 0of/ver-iterator | lib/npm.js | listInstalledVer | function listInstalledVer(name, dir) {
var _child$spawnSync3 = _child_process2['default'].spawnSync(npmCommand, ['list', name, '--depth', '0', '--json'], { cwd: dir });
var stdout = _child$spawnSync3.stdout;
var error = _child$spawnSync3.error;
var status = _child$spawnSync3.status;
// the package is invalid or uninstalled
if (error || 0 !== status) {
return '';
}
return JSON.parse(stdout)['version'];
} | javascript | function listInstalledVer(name, dir) {
var _child$spawnSync3 = _child_process2['default'].spawnSync(npmCommand, ['list', name, '--depth', '0', '--json'], { cwd: dir });
var stdout = _child$spawnSync3.stdout;
var error = _child$spawnSync3.error;
var status = _child$spawnSync3.status;
// the package is invalid or uninstalled
if (error || 0 !== status) {
return '';
}
return JSON.parse(stdout)['version'];
} | [
"function",
"listInstalledVer",
"(",
"name",
",",
"dir",
")",
"{",
"var",
"_child$spawnSync3",
"=",
"_child_process2",
"[",
"'default'",
"]",
".",
"spawnSync",
"(",
"npmCommand",
",",
"[",
"'list'",
",",
"name",
",",
"'--depth'",
",",
"'0'",
",",
"'--json'",
"]",
",",
"{",
"cwd",
":",
"dir",
"}",
")",
";",
"var",
"stdout",
"=",
"_child$spawnSync3",
".",
"stdout",
";",
"var",
"error",
"=",
"_child$spawnSync3",
".",
"error",
";",
"var",
"status",
"=",
"_child$spawnSync3",
".",
"status",
";",
"// the package is invalid or uninstalled",
"if",
"(",
"error",
"||",
"0",
"!==",
"status",
")",
"{",
"return",
"''",
";",
"}",
"return",
"JSON",
".",
"parse",
"(",
"stdout",
")",
"[",
"'version'",
"]",
";",
"}"
] | list specific package version via npm
@param {String} [name] published package name
@param {String} [dir] list directory
@public | [
"list",
"specific",
"package",
"version",
"via",
"npm"
] | a51726c02dfd14488190860f4d90903574ed8e37 | https://github.com/0of/ver-iterator/blob/a51726c02dfd14488190860f4d90903574ed8e37/lib/npm.js#L57-L70 |
51,801 | 0of/ver-iterator | lib/npm.js | uninstalledVer | function uninstalledVer(name, ver, dir) {
var _child$spawnSync4 = _child_process2['default'].spawnSync(npmCommand, ['uninstall', ver.length === 0 ? name : name + '@' + ver], { cwd: dir });
var error = _child$spawnSync4.error;
if (error) throw error;
} | javascript | function uninstalledVer(name, ver, dir) {
var _child$spawnSync4 = _child_process2['default'].spawnSync(npmCommand, ['uninstall', ver.length === 0 ? name : name + '@' + ver], { cwd: dir });
var error = _child$spawnSync4.error;
if (error) throw error;
} | [
"function",
"uninstalledVer",
"(",
"name",
",",
"ver",
",",
"dir",
")",
"{",
"var",
"_child$spawnSync4",
"=",
"_child_process2",
"[",
"'default'",
"]",
".",
"spawnSync",
"(",
"npmCommand",
",",
"[",
"'uninstall'",
",",
"ver",
".",
"length",
"===",
"0",
"?",
"name",
":",
"name",
"+",
"'@'",
"+",
"ver",
"]",
",",
"{",
"cwd",
":",
"dir",
"}",
")",
";",
"var",
"error",
"=",
"_child$spawnSync4",
".",
"error",
";",
"if",
"(",
"error",
")",
"throw",
"error",
";",
"}"
] | uninstall package via npm
@param {String} [name] published package name
@param {String} [ver] install version
@param {String} [dir] uninstall directory
@public | [
"uninstall",
"package",
"via",
"npm"
] | a51726c02dfd14488190860f4d90903574ed8e37 | https://github.com/0of/ver-iterator/blob/a51726c02dfd14488190860f4d90903574ed8e37/lib/npm.js#L80-L86 |
51,802 | gethuman/pancakes-recipe | utils/validation.js | getSchema | function getSchema(path) {
var parts = path.split('.');
var collectionName = parts[0];
var fieldName = parts[1];
// if format not user.field or field not in the schemaDefinitions object, then log error without breaking
if (parts.length !== 2 || !schemaDefinitions[collectionName] || !schemaDefinitions[collectionName][fieldName]) {
log.error('No schemaDefinitions for : ' + path, null);
return {};
}
return schemaDefinitions[collectionName][fieldName];
} | javascript | function getSchema(path) {
var parts = path.split('.');
var collectionName = parts[0];
var fieldName = parts[1];
// if format not user.field or field not in the schemaDefinitions object, then log error without breaking
if (parts.length !== 2 || !schemaDefinitions[collectionName] || !schemaDefinitions[collectionName][fieldName]) {
log.error('No schemaDefinitions for : ' + path, null);
return {};
}
return schemaDefinitions[collectionName][fieldName];
} | [
"function",
"getSchema",
"(",
"path",
")",
"{",
"var",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"collectionName",
"=",
"parts",
"[",
"0",
"]",
";",
"var",
"fieldName",
"=",
"parts",
"[",
"1",
"]",
";",
"// if format not user.field or field not in the schemaDefinitions object, then log error without breaking",
"if",
"(",
"parts",
".",
"length",
"!==",
"2",
"||",
"!",
"schemaDefinitions",
"[",
"collectionName",
"]",
"||",
"!",
"schemaDefinitions",
"[",
"collectionName",
"]",
"[",
"fieldName",
"]",
")",
"{",
"log",
".",
"error",
"(",
"'No schemaDefinitions for : '",
"+",
"path",
",",
"null",
")",
";",
"return",
"{",
"}",
";",
"}",
"return",
"schemaDefinitions",
"[",
"collectionName",
"]",
"[",
"fieldName",
"]",
";",
"}"
] | Take a string like user.password and get the schemaDefinitions for it
@param path
@returns {*} | [
"Take",
"a",
"string",
"like",
"user",
".",
"password",
"and",
"get",
"the",
"schemaDefinitions",
"for",
"it"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/utils/validation.js#L61-L73 |
51,803 | gethuman/pancakes-recipe | utils/validation.js | parseValidateAttr | function parseValidateAttr(validateAttr, schema, validateFns) {
// if an array, loop through and recurse
if (_.isArray(validateAttr)) {
_.each(validateAttr, function (validator) {
parseValidateAttr(validator, schema, validateFns);
});
return;
}
// if validateAttr is a string, then assume it is field reference
if (_.isString(validateAttr)) {
_.extend(schema, getSchema(validateAttr));
}
else if (_.isFunction(validateAttr)) {
validateFns.push(wrapFn(validateAttr));
}
else if (_.isObject(validateAttr)) {
_.extend(schema, validateAttr);
}
} | javascript | function parseValidateAttr(validateAttr, schema, validateFns) {
// if an array, loop through and recurse
if (_.isArray(validateAttr)) {
_.each(validateAttr, function (validator) {
parseValidateAttr(validator, schema, validateFns);
});
return;
}
// if validateAttr is a string, then assume it is field reference
if (_.isString(validateAttr)) {
_.extend(schema, getSchema(validateAttr));
}
else if (_.isFunction(validateAttr)) {
validateFns.push(wrapFn(validateAttr));
}
else if (_.isObject(validateAttr)) {
_.extend(schema, validateAttr);
}
} | [
"function",
"parseValidateAttr",
"(",
"validateAttr",
",",
"schema",
",",
"validateFns",
")",
"{",
"// if an array, loop through and recurse",
"if",
"(",
"_",
".",
"isArray",
"(",
"validateAttr",
")",
")",
"{",
"_",
".",
"each",
"(",
"validateAttr",
",",
"function",
"(",
"validator",
")",
"{",
"parseValidateAttr",
"(",
"validator",
",",
"schema",
",",
"validateFns",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"// if validateAttr is a string, then assume it is field reference",
"if",
"(",
"_",
".",
"isString",
"(",
"validateAttr",
")",
")",
"{",
"_",
".",
"extend",
"(",
"schema",
",",
"getSchema",
"(",
"validateAttr",
")",
")",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isFunction",
"(",
"validateAttr",
")",
")",
"{",
"validateFns",
".",
"push",
"(",
"wrapFn",
"(",
"validateAttr",
")",
")",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isObject",
"(",
"validateAttr",
")",
")",
"{",
"_",
".",
"extend",
"(",
"schema",
",",
"validateAttr",
")",
";",
"}",
"}"
] | Take thing originally from the gh-validate attribute and turn it into an obj and fns array
@param validateAttr
@param schema
@param validateFns | [
"Take",
"thing",
"originally",
"from",
"the",
"gh",
"-",
"validate",
"attribute",
"and",
"turn",
"it",
"into",
"an",
"obj",
"and",
"fns",
"array"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/utils/validation.js#L92-L113 |
51,804 | gethuman/pancakes-recipe | utils/validation.js | generateValidationFn | function generateValidationFn(schema) {
return function (req) {
// if already an error, return without doing any additional validation
if (req.error) { return req; }
var keys = Object.keys(schema);
var len = (req.value && req.value.trim().length) || 0;
var i, key, originalKey;
for (i = 0; i < keys.length; i++) {
key = originalKey = keys[i];
if (key.indexOf('ui-') === 0) {
key = key.substring(3);
}
// if validation function exists but it returns false then we have error
if (check[key] && !check[key](schema, req.value)) {
var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
req.error = errMsg
.replace('{' + key + '}', schema[originalKey])
.replace('{value}', req.value)
.replace('{length}', len);
break;
}
}
return req;
};
} | javascript | function generateValidationFn(schema) {
return function (req) {
// if already an error, return without doing any additional validation
if (req.error) { return req; }
var keys = Object.keys(schema);
var len = (req.value && req.value.trim().length) || 0;
var i, key, originalKey;
for (i = 0; i < keys.length; i++) {
key = originalKey = keys[i];
if (key.indexOf('ui-') === 0) {
key = key.substring(3);
}
// if validation function exists but it returns false then we have error
if (check[key] && !check[key](schema, req.value)) {
var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
req.error = errMsg
.replace('{' + key + '}', schema[originalKey])
.replace('{value}', req.value)
.replace('{length}', len);
break;
}
}
return req;
};
} | [
"function",
"generateValidationFn",
"(",
"schema",
")",
"{",
"return",
"function",
"(",
"req",
")",
"{",
"// if already an error, return without doing any additional validation",
"if",
"(",
"req",
".",
"error",
")",
"{",
"return",
"req",
";",
"}",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"schema",
")",
";",
"var",
"len",
"=",
"(",
"req",
".",
"value",
"&&",
"req",
".",
"value",
".",
"trim",
"(",
")",
".",
"length",
")",
"||",
"0",
";",
"var",
"i",
",",
"key",
",",
"originalKey",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"key",
"=",
"originalKey",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'ui-'",
")",
"===",
"0",
")",
"{",
"key",
"=",
"key",
".",
"substring",
"(",
"3",
")",
";",
"}",
"// if validation function exists but it returns false then we have error",
"if",
"(",
"check",
"[",
"key",
"]",
"&&",
"!",
"check",
"[",
"key",
"]",
"(",
"schema",
",",
"req",
".",
"value",
")",
")",
"{",
"var",
"errMsg",
"=",
"schema",
"[",
"key",
"+",
"'Desc'",
"]",
"||",
"errorMessage",
"[",
"key",
"]",
"||",
"'Invalid input'",
";",
"req",
".",
"error",
"=",
"errMsg",
".",
"replace",
"(",
"'{'",
"+",
"key",
"+",
"'}'",
",",
"schema",
"[",
"originalKey",
"]",
")",
".",
"replace",
"(",
"'{value}'",
",",
"req",
".",
"value",
")",
".",
"replace",
"(",
"'{length}'",
",",
"len",
")",
";",
"break",
";",
"}",
"}",
"return",
"req",
";",
"}",
";",
"}"
] | Generate validator function off of the given schema object
@param schema
@returns {Function} | [
"Generate",
"validator",
"function",
"off",
"of",
"the",
"given",
"schema",
"object"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/utils/validation.js#L120-L149 |
51,805 | tolokoban/ToloFrameWork | lib/module.js | getCandidates | function getCandidates(moduleName, srcPath) {
const
candidates = [],
moduleNames = getSynonyms(moduleName);
for( const path of srcPath) {
for( const name of moduleNames) {
candidates.push( Path.resolve( path, "mod", name) );
}
}
return candidates;
} | javascript | function getCandidates(moduleName, srcPath) {
const
candidates = [],
moduleNames = getSynonyms(moduleName);
for( const path of srcPath) {
for( const name of moduleNames) {
candidates.push( Path.resolve( path, "mod", name) );
}
}
return candidates;
} | [
"function",
"getCandidates",
"(",
"moduleName",
",",
"srcPath",
")",
"{",
"const",
"candidates",
"=",
"[",
"]",
",",
"moduleNames",
"=",
"getSynonyms",
"(",
"moduleName",
")",
";",
"for",
"(",
"const",
"path",
"of",
"srcPath",
")",
"{",
"for",
"(",
"const",
"name",
"of",
"moduleNames",
")",
"{",
"candidates",
".",
"push",
"(",
"Path",
".",
"resolve",
"(",
"path",
",",
"\"mod\"",
",",
"name",
")",
")",
";",
"}",
"}",
"return",
"candidates",
";",
"}"
] | List all possible absolute pathes for the given module.
@param {string} moduleName - Name of the module (with dots).
@param {array} srcPath - Array of absolute pathes where to look for sources.
Module's files lie in the subdirectory `mod/` of a source directory.
@returns {array} Array of absolute module pathes in order of preferrence.
Because a module can be made of several different files with the same basename,
These pathes have no file extension. | [
"List",
"all",
"possible",
"absolute",
"pathes",
"for",
"the",
"given",
"module",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/module.js#L65-L76 |
51,806 | tolokoban/ToloFrameWork | lib/module.js | getFirstViableCandidate | function getFirstViableCandidate(candidates) {
for( const candidate of candidates) {
const fileJS = `${candidate}.js`;
if( Fs.existsSync(fileJS) ) return candidate;
const fileXJS = `${candidate}.xjs`;
if( Fs.existsSync(fileXJS) ) return candidate;
}
return candidates[0];
} | javascript | function getFirstViableCandidate(candidates) {
for( const candidate of candidates) {
const fileJS = `${candidate}.js`;
if( Fs.existsSync(fileJS) ) return candidate;
const fileXJS = `${candidate}.xjs`;
if( Fs.existsSync(fileXJS) ) return candidate;
}
return candidates[0];
} | [
"function",
"getFirstViableCandidate",
"(",
"candidates",
")",
"{",
"for",
"(",
"const",
"candidate",
"of",
"candidates",
")",
"{",
"const",
"fileJS",
"=",
"`",
"${",
"candidate",
"}",
"`",
";",
"if",
"(",
"Fs",
".",
"existsSync",
"(",
"fileJS",
")",
")",
"return",
"candidate",
";",
"const",
"fileXJS",
"=",
"`",
"${",
"candidate",
"}",
"`",
";",
"if",
"(",
"Fs",
".",
"existsSync",
"(",
"fileXJS",
")",
")",
"return",
"candidate",
";",
"}",
"return",
"candidates",
"[",
"0",
"]",
";",
"}"
] | A candidate is viable if the `js` or the `xjs` file exists.
@param {array} candidates - Pathes of module files (without extension).
@returns {string} The first candidate if no module has been found. | [
"A",
"candidate",
"is",
"viable",
"if",
"the",
"js",
"or",
"the",
"xjs",
"file",
"exists",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/module.js#L103-L112 |
51,807 | mrcarlberg/objj-transpiler | ObjJAcornCompiler.js | setupOptions | function setupOptions(opts) {
var options = Object.create(null);
for (var opt in defaultOptions) {
if (opts && Object.prototype.hasOwnProperty.call(opts, opt)) {
var incomingOpt = opts[opt];
options[opt] = typeof incomingOpt === 'function' ? incomingOpt() : incomingOpt;
} else if (defaultOptions.hasOwnProperty(opt)) {
var defaultOpt = defaultOptions[opt];
options[opt] = typeof defaultOpt === 'function' ? defaultOpt() : defaultOpt;
}
}
return options;
} | javascript | function setupOptions(opts) {
var options = Object.create(null);
for (var opt in defaultOptions) {
if (opts && Object.prototype.hasOwnProperty.call(opts, opt)) {
var incomingOpt = opts[opt];
options[opt] = typeof incomingOpt === 'function' ? incomingOpt() : incomingOpt;
} else if (defaultOptions.hasOwnProperty(opt)) {
var defaultOpt = defaultOptions[opt];
options[opt] = typeof defaultOpt === 'function' ? defaultOpt() : defaultOpt;
}
}
return options;
} | [
"function",
"setupOptions",
"(",
"opts",
")",
"{",
"var",
"options",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"for",
"(",
"var",
"opt",
"in",
"defaultOptions",
")",
"{",
"if",
"(",
"opts",
"&&",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"opts",
",",
"opt",
")",
")",
"{",
"var",
"incomingOpt",
"=",
"opts",
"[",
"opt",
"]",
";",
"options",
"[",
"opt",
"]",
"=",
"typeof",
"incomingOpt",
"===",
"'function'",
"?",
"incomingOpt",
"(",
")",
":",
"incomingOpt",
";",
"}",
"else",
"if",
"(",
"defaultOptions",
".",
"hasOwnProperty",
"(",
"opt",
")",
")",
"{",
"var",
"defaultOpt",
"=",
"defaultOptions",
"[",
"opt",
"]",
";",
"options",
"[",
"opt",
"]",
"=",
"typeof",
"defaultOpt",
"===",
"'function'",
"?",
"defaultOpt",
"(",
")",
":",
"defaultOpt",
";",
"}",
"}",
"return",
"options",
";",
"}"
] | We copy the options to a new object as we don't want to mess up incoming options when we start compiling. | [
"We",
"copy",
"the",
"options",
"to",
"a",
"new",
"object",
"as",
"we",
"don",
"t",
"want",
"to",
"mess",
"up",
"incoming",
"options",
"when",
"we",
"start",
"compiling",
"."
] | d9117b580cb829142fdbebf6806e9a78e7c51f46 | https://github.com/mrcarlberg/objj-transpiler/blob/d9117b580cb829142fdbebf6806e9a78e7c51f46/ObjJAcornCompiler.js#L685-L697 |
51,808 | mrcarlberg/objj-transpiler | ObjJAcornCompiler.js | surroundExpression | function surroundExpression(c) {
return function(node, st, override, format) {
st.compiler.jsBuffer.concat("(");
c(node, st, override, format);
st.compiler.jsBuffer.concat(")");
}
} | javascript | function surroundExpression(c) {
return function(node, st, override, format) {
st.compiler.jsBuffer.concat("(");
c(node, st, override, format);
st.compiler.jsBuffer.concat(")");
}
} | [
"function",
"surroundExpression",
"(",
"c",
")",
"{",
"return",
"function",
"(",
"node",
",",
"st",
",",
"override",
",",
"format",
")",
"{",
"st",
".",
"compiler",
".",
"jsBuffer",
".",
"concat",
"(",
"\"(\"",
")",
";",
"c",
"(",
"node",
",",
"st",
",",
"override",
",",
"format",
")",
";",
"st",
".",
"compiler",
".",
"jsBuffer",
".",
"concat",
"(",
"\")\"",
")",
";",
"}",
"}"
] | Surround expression with parentheses | [
"Surround",
"expression",
"with",
"parentheses"
] | d9117b580cb829142fdbebf6806e9a78e7c51f46 | https://github.com/mrcarlberg/objj-transpiler/blob/d9117b580cb829142fdbebf6806e9a78e7c51f46/ObjJAcornCompiler.js#L1183-L1189 |
51,809 | mrcarlberg/objj-transpiler | ObjJAcornCompiler.js | function(node, st, c) {
var compiler = st.compiler;
if (compiler.generate)
compiler.jsBuffer.concat(node.name, node);
} | javascript | function(node, st, c) {
var compiler = st.compiler;
if (compiler.generate)
compiler.jsBuffer.concat(node.name, node);
} | [
"function",
"(",
"node",
",",
"st",
",",
"c",
")",
"{",
"var",
"compiler",
"=",
"st",
".",
"compiler",
";",
"if",
"(",
"compiler",
".",
"generate",
")",
"compiler",
".",
"jsBuffer",
".",
"concat",
"(",
"node",
".",
"name",
",",
"node",
")",
";",
"}"
] | Use this when there should not be a look up to issue warnings or add 'self.' before ivars | [
"Use",
"this",
"when",
"there",
"should",
"not",
"be",
"a",
"look",
"up",
"to",
"issue",
"warnings",
"or",
"add",
"self",
".",
"before",
"ivars"
] | d9117b580cb829142fdbebf6806e9a78e7c51f46 | https://github.com/mrcarlberg/objj-transpiler/blob/d9117b580cb829142fdbebf6806e9a78e7c51f46/ObjJAcornCompiler.js#L2282-L2286 |
|
51,810 | feedhenry/fh-mbaas-middleware | lib/util/common.js | buildErrorObject | function buildErrorObject(params){
params = params || {};
//If the userDetail is already set, not building the error object again.
if(params.err && params.err.userDetail){
return params;
}
var err = params.err || {message: "Unexpected Error"};
var msg = params.msg || params.err.message || "Unexpected Error";
var httpCode = params.httpCode || 500;
//Custom Error Code
var code = params.code || "FH-MBAAS-ERROR";
var response = {
errorFields: {
userDetail: msg,
systemDetail: msg + ' - ' + util.inspect(err),
code: code
},
httpCode: httpCode
};
if (params.explain) {
response.errorFields.explain = params.explain;
}
return response;
} | javascript | function buildErrorObject(params){
params = params || {};
//If the userDetail is already set, not building the error object again.
if(params.err && params.err.userDetail){
return params;
}
var err = params.err || {message: "Unexpected Error"};
var msg = params.msg || params.err.message || "Unexpected Error";
var httpCode = params.httpCode || 500;
//Custom Error Code
var code = params.code || "FH-MBAAS-ERROR";
var response = {
errorFields: {
userDetail: msg,
systemDetail: msg + ' - ' + util.inspect(err),
code: code
},
httpCode: httpCode
};
if (params.explain) {
response.errorFields.explain = params.explain;
}
return response;
} | [
"function",
"buildErrorObject",
"(",
"params",
")",
"{",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"//If the userDetail is already set, not building the error object again.",
"if",
"(",
"params",
".",
"err",
"&&",
"params",
".",
"err",
".",
"userDetail",
")",
"{",
"return",
"params",
";",
"}",
"var",
"err",
"=",
"params",
".",
"err",
"||",
"{",
"message",
":",
"\"Unexpected Error\"",
"}",
";",
"var",
"msg",
"=",
"params",
".",
"msg",
"||",
"params",
".",
"err",
".",
"message",
"||",
"\"Unexpected Error\"",
";",
"var",
"httpCode",
"=",
"params",
".",
"httpCode",
"||",
"500",
";",
"//Custom Error Code",
"var",
"code",
"=",
"params",
".",
"code",
"||",
"\"FH-MBAAS-ERROR\"",
";",
"var",
"response",
"=",
"{",
"errorFields",
":",
"{",
"userDetail",
":",
"msg",
",",
"systemDetail",
":",
"msg",
"+",
"' - '",
"+",
"util",
".",
"inspect",
"(",
"err",
")",
",",
"code",
":",
"code",
"}",
",",
"httpCode",
":",
"httpCode",
"}",
";",
"if",
"(",
"params",
".",
"explain",
")",
"{",
"response",
".",
"errorFields",
".",
"explain",
"=",
"params",
".",
"explain",
";",
"}",
"return",
"response",
";",
"}"
] | First step to creating common error codes.
TODO: Make A Module..
@param err
@param msg
@param code
@returns {{error: string}} | [
"First",
"step",
"to",
"creating",
"common",
"error",
"codes",
"."
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/util/common.js#L19-L46 |
51,811 | feedhenry/fh-mbaas-middleware | lib/util/common.js | setResponseHeaders | function setResponseHeaders(res) {
if(res.setHeader) {
var contentType = res.getHeader('content-type');
if (!contentType) {
res.setHeader('Content-Type', 'application/json');
}
}
} | javascript | function setResponseHeaders(res) {
if(res.setHeader) {
var contentType = res.getHeader('content-type');
if (!contentType) {
res.setHeader('Content-Type', 'application/json');
}
}
} | [
"function",
"setResponseHeaders",
"(",
"res",
")",
"{",
"if",
"(",
"res",
".",
"setHeader",
")",
"{",
"var",
"contentType",
"=",
"res",
".",
"getHeader",
"(",
"'content-type'",
")",
";",
"if",
"(",
"!",
"contentType",
")",
"{",
"res",
".",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
";",
"}",
"}",
"}"
] | set default response headers | [
"set",
"default",
"response",
"headers"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/util/common.js#L49-L56 |
51,812 | feedhenry/fh-mbaas-middleware | lib/util/common.js | handleError | function handleError(err, msg, code, req, res){
logError(err, msg, code, req);
var response = buildErrorObject({
err: err,
msg: msg,
httpCode: code
});
res.statusCode = response.httpCode;
res.end(JSON.stringify(response.errorFields));
} | javascript | function handleError(err, msg, code, req, res){
logError(err, msg, code, req);
var response = buildErrorObject({
err: err,
msg: msg,
httpCode: code
});
res.statusCode = response.httpCode;
res.end(JSON.stringify(response.errorFields));
} | [
"function",
"handleError",
"(",
"err",
",",
"msg",
",",
"code",
",",
"req",
",",
"res",
")",
"{",
"logError",
"(",
"err",
",",
"msg",
",",
"code",
",",
"req",
")",
";",
"var",
"response",
"=",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"msg",
",",
"httpCode",
":",
"code",
"}",
")",
";",
"res",
".",
"statusCode",
"=",
"response",
".",
"httpCode",
";",
"res",
".",
"end",
"(",
"JSON",
".",
"stringify",
"(",
"response",
".",
"errorFields",
")",
")",
";",
"}"
] | generic error handler | [
"generic",
"error",
"handler"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/util/common.js#L79-L90 |
51,813 | feedhenry/fh-mbaas-middleware | lib/util/common.js | sortObject | function sortObject(obj) {
assert.ok(_.isObject(obj), 'Parameter should be an object! - ' + util.inspect(obj));
assert.ok(!_.isArray(obj), 'Parameter should be an object, got array: ' + util.inspect(obj));
var sortedKeys = _.keys(obj).sort();
var sortedObjs = [];
_.each(sortedKeys, function(key) {
var val = {};
val[key] = obj[key];
sortedObjs.push(val);
});
return sortedObjs;
} | javascript | function sortObject(obj) {
assert.ok(_.isObject(obj), 'Parameter should be an object! - ' + util.inspect(obj));
assert.ok(!_.isArray(obj), 'Parameter should be an object, got array: ' + util.inspect(obj));
var sortedKeys = _.keys(obj).sort();
var sortedObjs = [];
_.each(sortedKeys, function(key) {
var val = {};
val[key] = obj[key];
sortedObjs.push(val);
});
return sortedObjs;
} | [
"function",
"sortObject",
"(",
"obj",
")",
"{",
"assert",
".",
"ok",
"(",
"_",
".",
"isObject",
"(",
"obj",
")",
",",
"'Parameter should be an object! - '",
"+",
"util",
".",
"inspect",
"(",
"obj",
")",
")",
";",
"assert",
".",
"ok",
"(",
"!",
"_",
".",
"isArray",
"(",
"obj",
")",
",",
"'Parameter should be an object, got array: '",
"+",
"util",
".",
"inspect",
"(",
"obj",
")",
")",
";",
"var",
"sortedKeys",
"=",
"_",
".",
"keys",
"(",
"obj",
")",
".",
"sort",
"(",
")",
";",
"var",
"sortedObjs",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"sortedKeys",
",",
"function",
"(",
"key",
")",
"{",
"var",
"val",
"=",
"{",
"}",
";",
"val",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"sortedObjs",
".",
"push",
"(",
"val",
")",
";",
"}",
")",
";",
"return",
"sortedObjs",
";",
"}"
] | converts an object with arbitrary keys into an array sorted by keys | [
"converts",
"an",
"object",
"with",
"arbitrary",
"keys",
"into",
"an",
"array",
"sorted",
"by",
"keys"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/util/common.js#L105-L119 |
51,814 | Digznav/bilberry | git-tags-info.js | gitTagsInfo | function gitTagsInfo(newTag) {
const date = new Date().toISOString();
return Promise.all([
git('git tag -l', stdout => {
const allTags = stdout
.toString()
.trim()
.split('\n')
.sort((a, b) => {
if (Semver.lt(a, b)) return -1;
if (Semver.gt(a, b)) return 1;
return 0;
});
return allTags;
})
.then(infoOfTags => {
const tagsHolder = {};
let currentMajor = 1;
let nextMajor = 2;
let groups = [];
infoOfTags.push(newTag);
infoOfTags.forEach((tag, idx) => {
groups.push({
tag,
date: tag === newTag ? date.substring(0, date.indexOf('T')) : gitDateOf(tag)
});
if (Semver.valid(infoOfTags[idx + 1])) {
if (Semver.major(infoOfTags[idx + 1]) === nextMajor) {
tagsHolder[`v${currentMajor}`] = groups;
currentMajor += 1;
nextMajor += 1;
groups = [];
}
} else {
tagsHolder[`v${currentMajor}`] = groups;
}
});
return tagsHolder;
})
.catch(log.error),
git('rev-list HEAD | tail -n 1')
]);
} | javascript | function gitTagsInfo(newTag) {
const date = new Date().toISOString();
return Promise.all([
git('git tag -l', stdout => {
const allTags = stdout
.toString()
.trim()
.split('\n')
.sort((a, b) => {
if (Semver.lt(a, b)) return -1;
if (Semver.gt(a, b)) return 1;
return 0;
});
return allTags;
})
.then(infoOfTags => {
const tagsHolder = {};
let currentMajor = 1;
let nextMajor = 2;
let groups = [];
infoOfTags.push(newTag);
infoOfTags.forEach((tag, idx) => {
groups.push({
tag,
date: tag === newTag ? date.substring(0, date.indexOf('T')) : gitDateOf(tag)
});
if (Semver.valid(infoOfTags[idx + 1])) {
if (Semver.major(infoOfTags[idx + 1]) === nextMajor) {
tagsHolder[`v${currentMajor}`] = groups;
currentMajor += 1;
nextMajor += 1;
groups = [];
}
} else {
tagsHolder[`v${currentMajor}`] = groups;
}
});
return tagsHolder;
})
.catch(log.error),
git('rev-list HEAD | tail -n 1')
]);
} | [
"function",
"gitTagsInfo",
"(",
"newTag",
")",
"{",
"const",
"date",
"=",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"[",
"git",
"(",
"'git tag -l'",
",",
"stdout",
"=>",
"{",
"const",
"allTags",
"=",
"stdout",
".",
"toString",
"(",
")",
".",
"trim",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
".",
"sort",
"(",
"(",
"a",
",",
"b",
")",
"=>",
"{",
"if",
"(",
"Semver",
".",
"lt",
"(",
"a",
",",
"b",
")",
")",
"return",
"-",
"1",
";",
"if",
"(",
"Semver",
".",
"gt",
"(",
"a",
",",
"b",
")",
")",
"return",
"1",
";",
"return",
"0",
";",
"}",
")",
";",
"return",
"allTags",
";",
"}",
")",
".",
"then",
"(",
"infoOfTags",
"=>",
"{",
"const",
"tagsHolder",
"=",
"{",
"}",
";",
"let",
"currentMajor",
"=",
"1",
";",
"let",
"nextMajor",
"=",
"2",
";",
"let",
"groups",
"=",
"[",
"]",
";",
"infoOfTags",
".",
"push",
"(",
"newTag",
")",
";",
"infoOfTags",
".",
"forEach",
"(",
"(",
"tag",
",",
"idx",
")",
"=>",
"{",
"groups",
".",
"push",
"(",
"{",
"tag",
",",
"date",
":",
"tag",
"===",
"newTag",
"?",
"date",
".",
"substring",
"(",
"0",
",",
"date",
".",
"indexOf",
"(",
"'T'",
")",
")",
":",
"gitDateOf",
"(",
"tag",
")",
"}",
")",
";",
"if",
"(",
"Semver",
".",
"valid",
"(",
"infoOfTags",
"[",
"idx",
"+",
"1",
"]",
")",
")",
"{",
"if",
"(",
"Semver",
".",
"major",
"(",
"infoOfTags",
"[",
"idx",
"+",
"1",
"]",
")",
"===",
"nextMajor",
")",
"{",
"tagsHolder",
"[",
"`",
"${",
"currentMajor",
"}",
"`",
"]",
"=",
"groups",
";",
"currentMajor",
"+=",
"1",
";",
"nextMajor",
"+=",
"1",
";",
"groups",
"=",
"[",
"]",
";",
"}",
"}",
"else",
"{",
"tagsHolder",
"[",
"`",
"${",
"currentMajor",
"}",
"`",
"]",
"=",
"groups",
";",
"}",
"}",
")",
";",
"return",
"tagsHolder",
";",
"}",
")",
".",
"catch",
"(",
"log",
".",
"error",
")",
",",
"git",
"(",
"'rev-list HEAD | tail -n 1'",
")",
"]",
")",
";",
"}"
] | Information of existing tags.
@param {string} newTag Tag.
@return {array} Full info of tags and the first commit. | [
"Information",
"of",
"existing",
"tags",
"."
] | ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4 | https://github.com/Digznav/bilberry/blob/ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4/git-tags-info.js#L11-L61 |
51,815 | sendanor/nor-nopg | src/schema/v0026.js | get_property | function get_property(obj, path) {
if(!is_object(obj)) { return error('get_property(obj, ...) not object: '+ obj); }
if(!is_string(path)) { return error('get_property(..., path) not string: '+ path); }
return path.split('.').reduce(get_property_step, obj);
} | javascript | function get_property(obj, path) {
if(!is_object(obj)) { return error('get_property(obj, ...) not object: '+ obj); }
if(!is_string(path)) { return error('get_property(..., path) not string: '+ path); }
return path.split('.').reduce(get_property_step, obj);
} | [
"function",
"get_property",
"(",
"obj",
",",
"path",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"obj",
")",
")",
"{",
"return",
"error",
"(",
"'get_property(obj, ...) not object: '",
"+",
"obj",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"path",
")",
")",
"{",
"return",
"error",
"(",
"'get_property(..., path) not string: '",
"+",
"path",
")",
";",
"}",
"return",
"path",
".",
"split",
"(",
"'.'",
")",
".",
"reduce",
"(",
"get_property_step",
",",
"obj",
")",
";",
"}"
] | Get value of property from provided object using a path.
@param obj {object} The object from where to find the value.
@param path {string} The path to the value in object.
@returns {mixed} The value from the object at the end of path or `undefined` if any part is missing. | [
"Get",
"value",
"of",
"property",
"from",
"provided",
"object",
"using",
"a",
"path",
"."
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/schema/v0026.js#L104-L108 |
51,816 | sendanor/nor-nopg | src/schema/v0026.js | get_pg_prop | function get_pg_prop(name) {
if(name[0] === '$') {
return name.substr(1);
}
var parts = name.split('.');
if(parts.length === 1) {
return "content->>'" + name + "'";
}
if(parts.length === 2) {
return "content->'" + parts.join("'->>'") + "'";
}
return "content->'" + parts.slice(0, parts.length-1).join("'->'") + "'->>'" + parts[parts.length-1] + "'";
} | javascript | function get_pg_prop(name) {
if(name[0] === '$') {
return name.substr(1);
}
var parts = name.split('.');
if(parts.length === 1) {
return "content->>'" + name + "'";
}
if(parts.length === 2) {
return "content->'" + parts.join("'->>'") + "'";
}
return "content->'" + parts.slice(0, parts.length-1).join("'->'") + "'->>'" + parts[parts.length-1] + "'";
} | [
"function",
"get_pg_prop",
"(",
"name",
")",
"{",
"if",
"(",
"name",
"[",
"0",
"]",
"===",
"'$'",
")",
"{",
"return",
"name",
".",
"substr",
"(",
"1",
")",
";",
"}",
"var",
"parts",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"1",
")",
"{",
"return",
"\"content->>'\"",
"+",
"name",
"+",
"\"'\"",
";",
"}",
"if",
"(",
"parts",
".",
"length",
"===",
"2",
")",
"{",
"return",
"\"content->'\"",
"+",
"parts",
".",
"join",
"(",
"\"'->>'\"",
")",
"+",
"\"'\"",
";",
"}",
"return",
"\"content->'\"",
"+",
"parts",
".",
"slice",
"(",
"0",
",",
"parts",
".",
"length",
"-",
"1",
")",
".",
"join",
"(",
"\"'->'\"",
")",
"+",
"\"'->>'\"",
"+",
"parts",
"[",
"parts",
".",
"length",
"-",
"1",
"]",
"+",
"\"'\"",
";",
"}"
] | Get PostgreSQL style property expression | [
"Get",
"PostgreSQL",
"style",
"property",
"expression"
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/schema/v0026.js#L111-L128 |
51,817 | sendanor/nor-nopg | src/schema/v0026.js | expression_query | function expression_query(parent, prop, type_name, type_prop, fields) {
fields = (fields || [{'query':'*'}]);
var map = {};
var query = "SELECT "+fields.map(function(f, i) {
var k;
if(f.key) {
k = 'p__' + i;
map[k] = f;
return f.query + ' AS ' + k;
} else {
return f.query;
}
}).join(', ')+" FROM documents WHERE type = $1 AND "+get_pg_prop(type_prop)+" = $2";
var rows = plv8.execute(query, [type_name, parent.id]);
if(!is_array(rows)) {
return rows;
}
var errors = [];
rows = rows.map(function(obj) {
Object.keys(obj).forEach(function(key) {
if(!map.hasOwnProperty(key)) {
return;
}
var spec = map[key];
if(!is_object(spec)) {
errors.push( error('mapped resource missing') );
return;
}
if(!is_string(spec.key)) {
errors.push( error('key missing') );
return;
}
var value = obj[key];
delete obj[key];
if(is_string(spec.datakey)) {
if(!obj[spec.datakey]) {
obj[spec.datakey] = {};
}
obj[spec.datakey][spec.key] = value;
} else {
obj[spec.key] = value;
}
});
return obj;
});
if(errors.length >= 1) {
return errors.shift();
}
return rows;
} | javascript | function expression_query(parent, prop, type_name, type_prop, fields) {
fields = (fields || [{'query':'*'}]);
var map = {};
var query = "SELECT "+fields.map(function(f, i) {
var k;
if(f.key) {
k = 'p__' + i;
map[k] = f;
return f.query + ' AS ' + k;
} else {
return f.query;
}
}).join(', ')+" FROM documents WHERE type = $1 AND "+get_pg_prop(type_prop)+" = $2";
var rows = plv8.execute(query, [type_name, parent.id]);
if(!is_array(rows)) {
return rows;
}
var errors = [];
rows = rows.map(function(obj) {
Object.keys(obj).forEach(function(key) {
if(!map.hasOwnProperty(key)) {
return;
}
var spec = map[key];
if(!is_object(spec)) {
errors.push( error('mapped resource missing') );
return;
}
if(!is_string(spec.key)) {
errors.push( error('key missing') );
return;
}
var value = obj[key];
delete obj[key];
if(is_string(spec.datakey)) {
if(!obj[spec.datakey]) {
obj[spec.datakey] = {};
}
obj[spec.datakey][spec.key] = value;
} else {
obj[spec.key] = value;
}
});
return obj;
});
if(errors.length >= 1) {
return errors.shift();
}
return rows;
} | [
"function",
"expression_query",
"(",
"parent",
",",
"prop",
",",
"type_name",
",",
"type_prop",
",",
"fields",
")",
"{",
"fields",
"=",
"(",
"fields",
"||",
"[",
"{",
"'query'",
":",
"'*'",
"}",
"]",
")",
";",
"var",
"map",
"=",
"{",
"}",
";",
"var",
"query",
"=",
"\"SELECT \"",
"+",
"fields",
".",
"map",
"(",
"function",
"(",
"f",
",",
"i",
")",
"{",
"var",
"k",
";",
"if",
"(",
"f",
".",
"key",
")",
"{",
"k",
"=",
"'p__'",
"+",
"i",
";",
"map",
"[",
"k",
"]",
"=",
"f",
";",
"return",
"f",
".",
"query",
"+",
"' AS '",
"+",
"k",
";",
"}",
"else",
"{",
"return",
"f",
".",
"query",
";",
"}",
"}",
")",
".",
"join",
"(",
"', '",
")",
"+",
"\" FROM documents WHERE type = $1 AND \"",
"+",
"get_pg_prop",
"(",
"type_prop",
")",
"+",
"\" = $2\"",
";",
"var",
"rows",
"=",
"plv8",
".",
"execute",
"(",
"query",
",",
"[",
"type_name",
",",
"parent",
".",
"id",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"rows",
")",
")",
"{",
"return",
"rows",
";",
"}",
"var",
"errors",
"=",
"[",
"]",
";",
"rows",
"=",
"rows",
".",
"map",
"(",
"function",
"(",
"obj",
")",
"{",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"map",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"return",
";",
"}",
"var",
"spec",
"=",
"map",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"is_object",
"(",
"spec",
")",
")",
"{",
"errors",
".",
"push",
"(",
"error",
"(",
"'mapped resource missing'",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"spec",
".",
"key",
")",
")",
"{",
"errors",
".",
"push",
"(",
"error",
"(",
"'key missing'",
")",
")",
";",
"return",
";",
"}",
"var",
"value",
"=",
"obj",
"[",
"key",
"]",
";",
"delete",
"obj",
"[",
"key",
"]",
";",
"if",
"(",
"is_string",
"(",
"spec",
".",
"datakey",
")",
")",
"{",
"if",
"(",
"!",
"obj",
"[",
"spec",
".",
"datakey",
"]",
")",
"{",
"obj",
"[",
"spec",
".",
"datakey",
"]",
"=",
"{",
"}",
";",
"}",
"obj",
"[",
"spec",
".",
"datakey",
"]",
"[",
"spec",
".",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"obj",
"[",
"spec",
".",
"key",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"return",
"obj",
";",
"}",
")",
";",
"if",
"(",
"errors",
".",
"length",
">=",
"1",
")",
"{",
"return",
"errors",
".",
"shift",
"(",
")",
";",
"}",
"return",
"rows",
";",
"}"
] | Execute query for document expressions
@param parent {object} The parent document object
@param prop {string} The name of the property where results are saved in the parent
@param type_name {string} The name of the type of related documents
@param type_prop {string} The property name in the related document for the UUID of parent
@param fields {array} The fields in the related document that should be returned | [
"Execute",
"query",
"for",
"document",
"expressions"
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/schema/v0026.js#L137-L196 |
51,818 | sdolard/node-netasqsyslog | lib/syslog.js | function (config) { // ctor
var
me = this;
config = config || {};
this.directory = config.directory;
this.output = config.output || process.stdout;
this.filesMaxSize = config.filesMaxSize || 1024 * 1024 * 1024 * 4 // 4 Go
this.writer = syslogwriter.create({
directory: this.directory,
filesMaxSize: this.filesMaxSize
});
this.writer.on('error', function(exception) {
me.emit('error', exception);
});
Syslog.call(this, config);
} | javascript | function (config) { // ctor
var
me = this;
config = config || {};
this.directory = config.directory;
this.output = config.output || process.stdout;
this.filesMaxSize = config.filesMaxSize || 1024 * 1024 * 1024 * 4 // 4 Go
this.writer = syslogwriter.create({
directory: this.directory,
filesMaxSize: this.filesMaxSize
});
this.writer.on('error', function(exception) {
me.emit('error', exception);
});
Syslog.call(this, config);
} | [
"function",
"(",
"config",
")",
"{",
"// ctor",
"var",
"me",
"=",
"this",
";",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"this",
".",
"directory",
"=",
"config",
".",
"directory",
";",
"this",
".",
"output",
"=",
"config",
".",
"output",
"||",
"process",
".",
"stdout",
";",
"this",
".",
"filesMaxSize",
"=",
"config",
".",
"filesMaxSize",
"||",
"1024",
"*",
"1024",
"*",
"1024",
"*",
"4",
"// 4 Go",
"this",
".",
"writer",
"=",
"syslogwriter",
".",
"create",
"(",
"{",
"directory",
":",
"this",
".",
"directory",
",",
"filesMaxSize",
":",
"this",
".",
"filesMaxSize",
"}",
")",
";",
"this",
".",
"writer",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"exception",
")",
"{",
"me",
".",
"emit",
"(",
"'error'",
",",
"exception",
")",
";",
"}",
")",
";",
"Syslog",
".",
"call",
"(",
"this",
",",
"config",
")",
";",
"}"
] | Read NETASQ syslog and put them in files
@public
@class
@param config.directory: {directory}
@param config.output: {Writable Stream} // default to process.stdout
@param config.filesMaxSize: {number} as Bytes // default 4GB
@param Syslog.config {object}
@inherits Syslog | [
"Read",
"NETASQ",
"syslog",
"and",
"put",
"them",
"in",
"files"
] | a626249695971f47f0a63d22a2dd496560d66094 | https://github.com/sdolard/node-netasqsyslog/blob/a626249695971f47f0a63d22a2dd496560d66094/lib/syslog.js#L195-L214 |
|
51,819 | tolokoban/ToloFrameWork | ker/mod/tfw.font-loader.js | fontAPI | function fontAPI( fonts ) {
var promises = [];
fonts.forEach(function (font) {
var pro = document.fonts.load( '64px "' + font + '"' );
promises.push( pro );
});
return Promise.all( promises );
} | javascript | function fontAPI( fonts ) {
var promises = [];
fonts.forEach(function (font) {
var pro = document.fonts.load( '64px "' + font + '"' );
promises.push( pro );
});
return Promise.all( promises );
} | [
"function",
"fontAPI",
"(",
"fonts",
")",
"{",
"var",
"promises",
"=",
"[",
"]",
";",
"fonts",
".",
"forEach",
"(",
"function",
"(",
"font",
")",
"{",
"var",
"pro",
"=",
"document",
".",
"fonts",
".",
"load",
"(",
"'64px \"'",
"+",
"font",
"+",
"'\"'",
")",
";",
"promises",
".",
"push",
"(",
"pro",
")",
";",
"}",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
";",
"}"
] | Use the modern Font API. | [
"Use",
"the",
"modern",
"Font",
"API",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.font-loader.js#L18-L25 |
51,820 | tolokoban/ToloFrameWork | ker/mod/tfw.font-loader.js | fallback | function fallback( fonts ) {
return new Promise(function (resolve, reject) {
var divs = [];
var body = document.body;
fonts.forEach(function (font) {
var div = document.createElement( 'div' );
div.className = 'tfw-font-loader';
div.style.fontFamily = font;
body.appendChild( div );
});
// Ugly trick: juste wait 1.5 second.
window.setTimeout(function () {
divs.forEach(function (d) {
body.removeChild( d );
});
resolve( fonts );
}, 1500);
});
} | javascript | function fallback( fonts ) {
return new Promise(function (resolve, reject) {
var divs = [];
var body = document.body;
fonts.forEach(function (font) {
var div = document.createElement( 'div' );
div.className = 'tfw-font-loader';
div.style.fontFamily = font;
body.appendChild( div );
});
// Ugly trick: juste wait 1.5 second.
window.setTimeout(function () {
divs.forEach(function (d) {
body.removeChild( d );
});
resolve( fonts );
}, 1500);
});
} | [
"function",
"fallback",
"(",
"fonts",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"divs",
"=",
"[",
"]",
";",
"var",
"body",
"=",
"document",
".",
"body",
";",
"fonts",
".",
"forEach",
"(",
"function",
"(",
"font",
")",
"{",
"var",
"div",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"div",
".",
"className",
"=",
"'tfw-font-loader'",
";",
"div",
".",
"style",
".",
"fontFamily",
"=",
"font",
";",
"body",
".",
"appendChild",
"(",
"div",
")",
";",
"}",
")",
";",
"// Ugly trick: juste wait 1.5 second.",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"divs",
".",
"forEach",
"(",
"function",
"(",
"d",
")",
"{",
"body",
".",
"removeChild",
"(",
"d",
")",
";",
"}",
")",
";",
"resolve",
"(",
"fonts",
")",
";",
"}",
",",
"1500",
")",
";",
"}",
")",
";",
"}"
] | For old browsers, use a not-always-working trick. | [
"For",
"old",
"browsers",
"use",
"a",
"not",
"-",
"always",
"-",
"working",
"trick",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.font-loader.js#L31-L49 |
51,821 | Crafity/crafity-core | lib/modules/crafity.Exception.js | Exception | function Exception(message, innerException) {
if (!message) {
throw new Exception("Argument 'message' is required but was '" +
(message === null ? "null" : "undefined") + "'");
}
if (typeof message !== 'string') {
throw new Exception("Argument 'message' must be of type 'string' but was '" + typeof message + "'");
}
if (innerException === undefined && typeof message !== 'string') {
innerException = message;
message = innerException.message || innerException.toString();
}
this.message = message;
this.innerException = innerException;
this.toString = function () {
return message;
};
} | javascript | function Exception(message, innerException) {
if (!message) {
throw new Exception("Argument 'message' is required but was '" +
(message === null ? "null" : "undefined") + "'");
}
if (typeof message !== 'string') {
throw new Exception("Argument 'message' must be of type 'string' but was '" + typeof message + "'");
}
if (innerException === undefined && typeof message !== 'string') {
innerException = message;
message = innerException.message || innerException.toString();
}
this.message = message;
this.innerException = innerException;
this.toString = function () {
return message;
};
} | [
"function",
"Exception",
"(",
"message",
",",
"innerException",
")",
"{",
"if",
"(",
"!",
"message",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Argument 'message' is required but was '\"",
"+",
"(",
"message",
"===",
"null",
"?",
"\"null\"",
":",
"\"undefined\"",
")",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"typeof",
"message",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Argument 'message' must be of type 'string' but was '\"",
"+",
"typeof",
"message",
"+",
"\"'\"",
")",
";",
"}",
"if",
"(",
"innerException",
"===",
"undefined",
"&&",
"typeof",
"message",
"!==",
"'string'",
")",
"{",
"innerException",
"=",
"message",
";",
"message",
"=",
"innerException",
".",
"message",
"||",
"innerException",
".",
"toString",
"(",
")",
";",
"}",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"innerException",
"=",
"innerException",
";",
"this",
".",
"toString",
"=",
"function",
"(",
")",
"{",
"return",
"message",
";",
"}",
";",
"}"
] | A type representing an Exception
@param message The message for the exception
@param innerException The inner exception
@param constructor A constructor of an object to inherit from Exception | [
"A",
"type",
"representing",
"an",
"Exception"
] | c0f2271fa6f9c1164450928b2b480f397c9ec20b | https://github.com/Crafity/crafity-core/blob/c0f2271fa6f9c1164450928b2b480f397c9ec20b/lib/modules/crafity.Exception.js#L25-L44 |
51,822 | LevInteractive/allwrite-middleware-connect | index.js | request | function request(remoteUrl) {
return new Promise((resolve, reject) => {
const get = adapters[url.parse(remoteUrl).protocol].get;
get(remoteUrl, res => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
let rawData = '';
// If it's not a 200 and not a 404 there's another issue. Allwrite will
// only return these two statuses.
if (statusCode !== 200 && statusCode !== 404) {
const error = new Error('Allwrite: Request Failed.\n' +
`Status Code: ${statusCode}`);
error.code = statusCode;
return reject(error);
} else if (!/^application\/json/.test(contentType)) {
const error = new Error('Allwrite: Invalid content-type.\n' +
`Expected application/json but got ${contentType}`);
return reject(error);
}
res.setEncoding("utf8");
res.on("data", chunk => rawData += chunk);
res.on("end", () => {
try {
resolve(JSON.parse(rawData));
} catch (e) {
reject(new Error("Allwrite response parsing error: " + e.message));
}
});
});
});
} | javascript | function request(remoteUrl) {
return new Promise((resolve, reject) => {
const get = adapters[url.parse(remoteUrl).protocol].get;
get(remoteUrl, res => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
let rawData = '';
// If it's not a 200 and not a 404 there's another issue. Allwrite will
// only return these two statuses.
if (statusCode !== 200 && statusCode !== 404) {
const error = new Error('Allwrite: Request Failed.\n' +
`Status Code: ${statusCode}`);
error.code = statusCode;
return reject(error);
} else if (!/^application\/json/.test(contentType)) {
const error = new Error('Allwrite: Invalid content-type.\n' +
`Expected application/json but got ${contentType}`);
return reject(error);
}
res.setEncoding("utf8");
res.on("data", chunk => rawData += chunk);
res.on("end", () => {
try {
resolve(JSON.parse(rawData));
} catch (e) {
reject(new Error("Allwrite response parsing error: " + e.message));
}
});
});
});
} | [
"function",
"request",
"(",
"remoteUrl",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"get",
"=",
"adapters",
"[",
"url",
".",
"parse",
"(",
"remoteUrl",
")",
".",
"protocol",
"]",
".",
"get",
";",
"get",
"(",
"remoteUrl",
",",
"res",
"=>",
"{",
"const",
"{",
"statusCode",
"}",
"=",
"res",
";",
"const",
"contentType",
"=",
"res",
".",
"headers",
"[",
"'content-type'",
"]",
";",
"let",
"rawData",
"=",
"''",
";",
"// If it's not a 200 and not a 404 there's another issue. Allwrite will",
"// only return these two statuses.",
"if",
"(",
"statusCode",
"!==",
"200",
"&&",
"statusCode",
"!==",
"404",
")",
"{",
"const",
"error",
"=",
"new",
"Error",
"(",
"'Allwrite: Request Failed.\\n'",
"+",
"`",
"${",
"statusCode",
"}",
"`",
")",
";",
"error",
".",
"code",
"=",
"statusCode",
";",
"return",
"reject",
"(",
"error",
")",
";",
"}",
"else",
"if",
"(",
"!",
"/",
"^application\\/json",
"/",
".",
"test",
"(",
"contentType",
")",
")",
"{",
"const",
"error",
"=",
"new",
"Error",
"(",
"'Allwrite: Invalid content-type.\\n'",
"+",
"`",
"${",
"contentType",
"}",
"`",
")",
";",
"return",
"reject",
"(",
"error",
")",
";",
"}",
"res",
".",
"setEncoding",
"(",
"\"utf8\"",
")",
";",
"res",
".",
"on",
"(",
"\"data\"",
",",
"chunk",
"=>",
"rawData",
"+=",
"chunk",
")",
";",
"res",
".",
"on",
"(",
"\"end\"",
",",
"(",
")",
"=>",
"{",
"try",
"{",
"resolve",
"(",
"JSON",
".",
"parse",
"(",
"rawData",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"reject",
"(",
"new",
"Error",
"(",
"\"Allwrite response parsing error: \"",
"+",
"e",
".",
"message",
")",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Request Allwrite Server.
@param {string} url The url to request.
@return {Promise} | [
"Request",
"Allwrite",
"Server",
"."
] | 03f85b741a667d81f9954924083499bc060e2a4b | https://github.com/LevInteractive/allwrite-middleware-connect/blob/03f85b741a667d81f9954924083499bc060e2a4b/index.js#L13-L45 |
51,823 | bdchauvette/nano-blue | lib/nano-blue.js | deepPromisify | function deepPromisify(obj) {
return _.transform(obj, function(promisifiedObj, value, key) {
if (blacklist.has(key)) {
promisifiedObj[key] = value;
return;
}
if (typeof value === 'function') {
promisifiedObj[key] = bluebird.promisify(value, obj);
} else if (typeof value === 'object') {
promisifiedObj[key] = deepPromisify(value);
} else {
promisifiedObj[key] = value;
}
});
} | javascript | function deepPromisify(obj) {
return _.transform(obj, function(promisifiedObj, value, key) {
if (blacklist.has(key)) {
promisifiedObj[key] = value;
return;
}
if (typeof value === 'function') {
promisifiedObj[key] = bluebird.promisify(value, obj);
} else if (typeof value === 'object') {
promisifiedObj[key] = deepPromisify(value);
} else {
promisifiedObj[key] = value;
}
});
} | [
"function",
"deepPromisify",
"(",
"obj",
")",
"{",
"return",
"_",
".",
"transform",
"(",
"obj",
",",
"function",
"(",
"promisifiedObj",
",",
"value",
",",
"key",
")",
"{",
"if",
"(",
"blacklist",
".",
"has",
"(",
"key",
")",
")",
"{",
"promisifiedObj",
"[",
"key",
"]",
"=",
"value",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
")",
"{",
"promisifiedObj",
"[",
"key",
"]",
"=",
"bluebird",
".",
"promisify",
"(",
"value",
",",
"obj",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"value",
"===",
"'object'",
")",
"{",
"promisifiedObj",
"[",
"key",
"]",
"=",
"deepPromisify",
"(",
"value",
")",
";",
"}",
"else",
"{",
"promisifiedObj",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"}"
] | Promisifies the exposed functions on an object
Based on a similar function in `qano`
@ref https://github.com/jclohmann/qano | [
"Promisifies",
"the",
"exposed",
"functions",
"on",
"an",
"object",
"Based",
"on",
"a",
"similar",
"function",
"in",
"qano"
] | 9dc0563eeaf40e9cb141c4478afece6d1f81aab5 | https://github.com/bdchauvette/nano-blue/blob/9dc0563eeaf40e9cb141c4478afece6d1f81aab5/lib/nano-blue.js#L15-L30 |
51,824 | nrn/mid | t/mid.js | rep | function rep (num, str) {
return function (arr, done) {
arr.forEach(function (i, idx) {
var s = ''
if (typeof i === 'string') s = i
if (idx === 0) return
else if (idx/num === Math.floor(idx/num)) arr[idx] = s + str
})
done()
}
} | javascript | function rep (num, str) {
return function (arr, done) {
arr.forEach(function (i, idx) {
var s = ''
if (typeof i === 'string') s = i
if (idx === 0) return
else if (idx/num === Math.floor(idx/num)) arr[idx] = s + str
})
done()
}
} | [
"function",
"rep",
"(",
"num",
",",
"str",
")",
"{",
"return",
"function",
"(",
"arr",
",",
"done",
")",
"{",
"arr",
".",
"forEach",
"(",
"function",
"(",
"i",
",",
"idx",
")",
"{",
"var",
"s",
"=",
"''",
"if",
"(",
"typeof",
"i",
"===",
"'string'",
")",
"s",
"=",
"i",
"if",
"(",
"idx",
"===",
"0",
")",
"return",
"else",
"if",
"(",
"idx",
"/",
"num",
"===",
"Math",
".",
"floor",
"(",
"idx",
"/",
"num",
")",
")",
"arr",
"[",
"idx",
"]",
"=",
"s",
"+",
"str",
"}",
")",
"done",
"(",
")",
"}",
"}"
] | Work for tests | [
"Work",
"for",
"tests"
] | d7a5555565292777947a24fe053b690b101b361b | https://github.com/nrn/mid/blob/d7a5555565292777947a24fe053b690b101b361b/t/mid.js#L52-L62 |
51,825 | ashleydavis/routey | fileMgr.js | function (dirPath) {
var dirContents = fs.readdirSync(dirPath);
return dirContents.filter(function (subDirName) {
// Filter out non-directories.
var subDirPath = path.join(dirPath, subDirName);
return fs.lstatSync(subDirPath).isDirectory();
});
} | javascript | function (dirPath) {
var dirContents = fs.readdirSync(dirPath);
return dirContents.filter(function (subDirName) {
// Filter out non-directories.
var subDirPath = path.join(dirPath, subDirName);
return fs.lstatSync(subDirPath).isDirectory();
});
} | [
"function",
"(",
"dirPath",
")",
"{",
"var",
"dirContents",
"=",
"fs",
".",
"readdirSync",
"(",
"dirPath",
")",
";",
"return",
"dirContents",
".",
"filter",
"(",
"function",
"(",
"subDirName",
")",
"{",
"// Filter out non-directories.",
"var",
"subDirPath",
"=",
"path",
".",
"join",
"(",
"dirPath",
",",
"subDirName",
")",
";",
"return",
"fs",
".",
"lstatSync",
"(",
"subDirPath",
")",
".",
"isDirectory",
"(",
")",
";",
"}",
")",
";",
"}"
] | Get a list of directories from the specified path. | [
"Get",
"a",
"list",
"of",
"directories",
"from",
"the",
"specified",
"path",
"."
] | dd5e797603f6f0b584d6712165e9b73c7d8efc78 | https://github.com/ashleydavis/routey/blob/dd5e797603f6f0b584d6712165e9b73c7d8efc78/fileMgr.js#L13-L21 |
|
51,826 | jmjuanes/utily | lib/task.js | function(name)
{
//Check if the queue exists
if(typeof tasks[name] !== 'object'){ return; }
//Check if queue is paused
if(tasks[name].paused === true)
{
//Set task queue running false
tasks[name].running = false;
}
else
{
//Set queue running
tasks[name].running = true;
//Check the number of tasks on this tag
if(tasks[name].handlers.length === 0)
{
//Delete this path object
delete tasks[name];
}
else
{
//Get the function to run
var handler = tasks[name].handlers.shift();
//Run this task
return handler.call(null, function()
{
//Continue with the next task
return process.nextTick(function()
{
//Continue with the next task in the queue
return task_run(name);
});
});
}
}
} | javascript | function(name)
{
//Check if the queue exists
if(typeof tasks[name] !== 'object'){ return; }
//Check if queue is paused
if(tasks[name].paused === true)
{
//Set task queue running false
tasks[name].running = false;
}
else
{
//Set queue running
tasks[name].running = true;
//Check the number of tasks on this tag
if(tasks[name].handlers.length === 0)
{
//Delete this path object
delete tasks[name];
}
else
{
//Get the function to run
var handler = tasks[name].handlers.shift();
//Run this task
return handler.call(null, function()
{
//Continue with the next task
return process.nextTick(function()
{
//Continue with the next task in the queue
return task_run(name);
});
});
}
}
} | [
"function",
"(",
"name",
")",
"{",
"//Check if the queue exists",
"if",
"(",
"typeof",
"tasks",
"[",
"name",
"]",
"!==",
"'object'",
")",
"{",
"return",
";",
"}",
"//Check if queue is paused",
"if",
"(",
"tasks",
"[",
"name",
"]",
".",
"paused",
"===",
"true",
")",
"{",
"//Set task queue running false",
"tasks",
"[",
"name",
"]",
".",
"running",
"=",
"false",
";",
"}",
"else",
"{",
"//Set queue running",
"tasks",
"[",
"name",
"]",
".",
"running",
"=",
"true",
";",
"//Check the number of tasks on this tag",
"if",
"(",
"tasks",
"[",
"name",
"]",
".",
"handlers",
".",
"length",
"===",
"0",
")",
"{",
"//Delete this path object",
"delete",
"tasks",
"[",
"name",
"]",
";",
"}",
"else",
"{",
"//Get the function to run",
"var",
"handler",
"=",
"tasks",
"[",
"name",
"]",
".",
"handlers",
".",
"shift",
"(",
")",
";",
"//Run this task",
"return",
"handler",
".",
"call",
"(",
"null",
",",
"function",
"(",
")",
"{",
"//Continue with the next task",
"return",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"//Continue with the next task in the queue",
"return",
"task_run",
"(",
"name",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | Run a task by name | [
"Run",
"a",
"task",
"by",
"name"
] | f620180aa21fc8ece0f7b2c268cda335e9e28831 | https://github.com/jmjuanes/utily/blob/f620180aa21fc8ece0f7b2c268cda335e9e28831/lib/task.js#L5-L44 |
|
51,827 | copress/copress-component-oauth2 | lib/errors/oauth2error.js | OAuth2Error | function OAuth2Error(message, code, uri, status) {
Error.call(this);
this.message = message;
this.code = code || 'server_error';
this.uri = uri;
this.status = status || 500;
} | javascript | function OAuth2Error(message, code, uri, status) {
Error.call(this);
this.message = message;
this.code = code || 'server_error';
this.uri = uri;
this.status = status || 500;
} | [
"function",
"OAuth2Error",
"(",
"message",
",",
"code",
",",
"uri",
",",
"status",
")",
"{",
"Error",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"code",
"=",
"code",
"||",
"'server_error'",
";",
"this",
".",
"uri",
"=",
"uri",
";",
"this",
".",
"status",
"=",
"status",
"||",
"500",
";",
"}"
] | `OAuth2Error` error.
@api public | [
"OAuth2Error",
"error",
"."
] | 4819f379a0d42753bfd51e237c5c3aaddee37544 | https://github.com/copress/copress-component-oauth2/blob/4819f379a0d42753bfd51e237c5c3aaddee37544/lib/errors/oauth2error.js#L6-L12 |
51,828 | asavoy/grunt-requirejs-auto-bundles | lib/factorise.js | factoriseBundles | function factoriseBundles(modules, duplicates, loaderConfig, maxBundles) {
// Remember all dependencies, along with related information.
// dependencyId -> { mains: [...], size: 123 }
var allDependencies = {};
// Each module that is duplicated, is a module shared by two or more mains.
// So we group the duplicates into bundles, grouped by the set of mains that
// share them.
var bundles = {};
_.forIn(duplicates, function(dependentMains, dependencyPath) {
// If we don't convert to a module ID, the output bundles config
// doesn't match anything when it comes to loading the shared modules...
var dependencyId = amd.modulePathToId(dependencyPath);
// This is necessary because the RequireJS optimizer breaks when it
// sees more than one kind of reference to a module -- and this includes
// references in the bundle config.
dependencyId = amd.convertToAlias(dependencyId, loaderConfig.paths);
// Bundle name must be unique for each set of dependent mains, that's
// how we group them.
var bundleName = bundle.generateBundleName(dependentMains);
// If the bundle doesn't exist yet, create one.
if (!bundles[bundleName]) {
bundles[bundleName] = {
name: bundleName,
dependentMains: [],
dependencies: [],
size: 0
};
}
bundles[bundleName].dependencies.push(dependencyId);
bundles[bundleName].dependentMains = _.union(
bundles[bundleName].dependentMains,
dependentMains
);
// Remember all dependencies.
allDependencies[dependencyId] = {
mains: dependentMains,
size: amd.moduleSize(dependencyPath, loaderConfig.paths) || 1024
};
});
// Reduce the number of bundles.
bundles = reduce.reduceBundles(
bundles, allDependencies, maxBundles
);
// Exclude contents of all bundles, from each of the mains. This prevents
// including of the bundled shared modules into the mains.
var bundleNames = _.keys(bundles);
_.forEach(modules, function(module) {
if (!module.exclude) {
module.exclude = [];
}
module.exclude = module.exclude.concat(bundleNames);
});
// Register each of the bundles as a module. This tells the optimizer to
// create each bundle, and to package the right shared modules into it.
// To prevent shared modules being duplicated inbetween bundles, we
// exclude all other dependencies not belonging to this bundle.
var allDependencyIds = _.keys(allDependencies);
_.forIn(bundles, function(bundle, bundleName) {
modules.unshift({
create: true,
name: bundleName,
include: bundle.dependencies,
excludeShallow: _.difference(allDependencyIds, bundle.dependencies)
});
});
// And we're done.
return {
bundles: bundles,
modules: modules
}
} | javascript | function factoriseBundles(modules, duplicates, loaderConfig, maxBundles) {
// Remember all dependencies, along with related information.
// dependencyId -> { mains: [...], size: 123 }
var allDependencies = {};
// Each module that is duplicated, is a module shared by two or more mains.
// So we group the duplicates into bundles, grouped by the set of mains that
// share them.
var bundles = {};
_.forIn(duplicates, function(dependentMains, dependencyPath) {
// If we don't convert to a module ID, the output bundles config
// doesn't match anything when it comes to loading the shared modules...
var dependencyId = amd.modulePathToId(dependencyPath);
// This is necessary because the RequireJS optimizer breaks when it
// sees more than one kind of reference to a module -- and this includes
// references in the bundle config.
dependencyId = amd.convertToAlias(dependencyId, loaderConfig.paths);
// Bundle name must be unique for each set of dependent mains, that's
// how we group them.
var bundleName = bundle.generateBundleName(dependentMains);
// If the bundle doesn't exist yet, create one.
if (!bundles[bundleName]) {
bundles[bundleName] = {
name: bundleName,
dependentMains: [],
dependencies: [],
size: 0
};
}
bundles[bundleName].dependencies.push(dependencyId);
bundles[bundleName].dependentMains = _.union(
bundles[bundleName].dependentMains,
dependentMains
);
// Remember all dependencies.
allDependencies[dependencyId] = {
mains: dependentMains,
size: amd.moduleSize(dependencyPath, loaderConfig.paths) || 1024
};
});
// Reduce the number of bundles.
bundles = reduce.reduceBundles(
bundles, allDependencies, maxBundles
);
// Exclude contents of all bundles, from each of the mains. This prevents
// including of the bundled shared modules into the mains.
var bundleNames = _.keys(bundles);
_.forEach(modules, function(module) {
if (!module.exclude) {
module.exclude = [];
}
module.exclude = module.exclude.concat(bundleNames);
});
// Register each of the bundles as a module. This tells the optimizer to
// create each bundle, and to package the right shared modules into it.
// To prevent shared modules being duplicated inbetween bundles, we
// exclude all other dependencies not belonging to this bundle.
var allDependencyIds = _.keys(allDependencies);
_.forIn(bundles, function(bundle, bundleName) {
modules.unshift({
create: true,
name: bundleName,
include: bundle.dependencies,
excludeShallow: _.difference(allDependencyIds, bundle.dependencies)
});
});
// And we're done.
return {
bundles: bundles,
modules: modules
}
} | [
"function",
"factoriseBundles",
"(",
"modules",
",",
"duplicates",
",",
"loaderConfig",
",",
"maxBundles",
")",
"{",
"// Remember all dependencies, along with related information.",
"// dependencyId -> { mains: [...], size: 123 }",
"var",
"allDependencies",
"=",
"{",
"}",
";",
"// Each module that is duplicated, is a module shared by two or more mains.",
"// So we group the duplicates into bundles, grouped by the set of mains that",
"// share them.",
"var",
"bundles",
"=",
"{",
"}",
";",
"_",
".",
"forIn",
"(",
"duplicates",
",",
"function",
"(",
"dependentMains",
",",
"dependencyPath",
")",
"{",
"// If we don't convert to a module ID, the output bundles config",
"// doesn't match anything when it comes to loading the shared modules...",
"var",
"dependencyId",
"=",
"amd",
".",
"modulePathToId",
"(",
"dependencyPath",
")",
";",
"// This is necessary because the RequireJS optimizer breaks when it",
"// sees more than one kind of reference to a module -- and this includes",
"// references in the bundle config.",
"dependencyId",
"=",
"amd",
".",
"convertToAlias",
"(",
"dependencyId",
",",
"loaderConfig",
".",
"paths",
")",
";",
"// Bundle name must be unique for each set of dependent mains, that's",
"// how we group them.",
"var",
"bundleName",
"=",
"bundle",
".",
"generateBundleName",
"(",
"dependentMains",
")",
";",
"// If the bundle doesn't exist yet, create one.",
"if",
"(",
"!",
"bundles",
"[",
"bundleName",
"]",
")",
"{",
"bundles",
"[",
"bundleName",
"]",
"=",
"{",
"name",
":",
"bundleName",
",",
"dependentMains",
":",
"[",
"]",
",",
"dependencies",
":",
"[",
"]",
",",
"size",
":",
"0",
"}",
";",
"}",
"bundles",
"[",
"bundleName",
"]",
".",
"dependencies",
".",
"push",
"(",
"dependencyId",
")",
";",
"bundles",
"[",
"bundleName",
"]",
".",
"dependentMains",
"=",
"_",
".",
"union",
"(",
"bundles",
"[",
"bundleName",
"]",
".",
"dependentMains",
",",
"dependentMains",
")",
";",
"// Remember all dependencies.",
"allDependencies",
"[",
"dependencyId",
"]",
"=",
"{",
"mains",
":",
"dependentMains",
",",
"size",
":",
"amd",
".",
"moduleSize",
"(",
"dependencyPath",
",",
"loaderConfig",
".",
"paths",
")",
"||",
"1024",
"}",
";",
"}",
")",
";",
"// Reduce the number of bundles.",
"bundles",
"=",
"reduce",
".",
"reduceBundles",
"(",
"bundles",
",",
"allDependencies",
",",
"maxBundles",
")",
";",
"// Exclude contents of all bundles, from each of the mains. This prevents",
"// including of the bundled shared modules into the mains.",
"var",
"bundleNames",
"=",
"_",
".",
"keys",
"(",
"bundles",
")",
";",
"_",
".",
"forEach",
"(",
"modules",
",",
"function",
"(",
"module",
")",
"{",
"if",
"(",
"!",
"module",
".",
"exclude",
")",
"{",
"module",
".",
"exclude",
"=",
"[",
"]",
";",
"}",
"module",
".",
"exclude",
"=",
"module",
".",
"exclude",
".",
"concat",
"(",
"bundleNames",
")",
";",
"}",
")",
";",
"// Register each of the bundles as a module. This tells the optimizer to",
"// create each bundle, and to package the right shared modules into it.",
"// To prevent shared modules being duplicated inbetween bundles, we",
"// exclude all other dependencies not belonging to this bundle.",
"var",
"allDependencyIds",
"=",
"_",
".",
"keys",
"(",
"allDependencies",
")",
";",
"_",
".",
"forIn",
"(",
"bundles",
",",
"function",
"(",
"bundle",
",",
"bundleName",
")",
"{",
"modules",
".",
"unshift",
"(",
"{",
"create",
":",
"true",
",",
"name",
":",
"bundleName",
",",
"include",
":",
"bundle",
".",
"dependencies",
",",
"excludeShallow",
":",
"_",
".",
"difference",
"(",
"allDependencyIds",
",",
"bundle",
".",
"dependencies",
")",
"}",
")",
";",
"}",
")",
";",
"// And we're done.",
"return",
"{",
"bundles",
":",
"bundles",
",",
"modules",
":",
"modules",
"}",
"}"
] | Calculate bundles from list of main modules and duplicates.
Modules should be same as modules: used in requirejs config options.
Duplicates looks like:
{
"jquery/jquery.js": ["pages/page1.js", "pages/page2.js"]
}
The output should be:
{
"bundles: {
"bundle1": ["jquery"],
"bundle2": ["lodash"]
},
"modules: [{
"name": "bundle1",
"include": ["jquery"]
}, {
"name": "bundle2",
"include": ["lodash"]
}, {
"name": "pages/page1",
"exclude": ["bundle1", "bundle2"]
}, {
"name": "pages/page2",
"exclude": ["bundle1", "bundle2"]
}]
} | [
"Calculate",
"bundles",
"from",
"list",
"of",
"main",
"modules",
"and",
"duplicates",
"."
] | c0f587c9720943dd32098203d2c71ab1387f1700 | https://github.com/asavoy/grunt-requirejs-auto-bundles/blob/c0f587c9720943dd32098203d2c71ab1387f1700/lib/factorise.js#L39-L118 |
51,829 | MostlyJS/mostly-feathers-mongoose | src/plugins/mongoose-cache.js | function (collectionKey, queryKey) {
return new Promise(function (ok) {
redisClient.multi().get(collectionKey).get(queryKey).exec(function (err, results) {
if (err) {
err.message = util.format('mongoose cache error %s', queryKey);
debug(err);
ok([null, null]); // ignore error, instead reject
//return error(err);
}
var collectionData = results[0] && JSON.parse(results[0]),
queryData = results[1] && JSON.parse(results[1]);
//debug('redis cache object size', queryKey, helpers.getObjectSize(queryData));
// special cache miss where it is out of date
if (queryData && collectionData && collectionData.lastWrite > queryData.metadata.lastWrite) {
debug('mongoose cache out of date: ', queryKey);
queryData = null;
}
ok([collectionData, queryData]);
});
});
} | javascript | function (collectionKey, queryKey) {
return new Promise(function (ok) {
redisClient.multi().get(collectionKey).get(queryKey).exec(function (err, results) {
if (err) {
err.message = util.format('mongoose cache error %s', queryKey);
debug(err);
ok([null, null]); // ignore error, instead reject
//return error(err);
}
var collectionData = results[0] && JSON.parse(results[0]),
queryData = results[1] && JSON.parse(results[1]);
//debug('redis cache object size', queryKey, helpers.getObjectSize(queryData));
// special cache miss where it is out of date
if (queryData && collectionData && collectionData.lastWrite > queryData.metadata.lastWrite) {
debug('mongoose cache out of date: ', queryKey);
queryData = null;
}
ok([collectionData, queryData]);
});
});
} | [
"function",
"(",
"collectionKey",
",",
"queryKey",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"ok",
")",
"{",
"redisClient",
".",
"multi",
"(",
")",
".",
"get",
"(",
"collectionKey",
")",
".",
"get",
"(",
"queryKey",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"results",
")",
"{",
"if",
"(",
"err",
")",
"{",
"err",
".",
"message",
"=",
"util",
".",
"format",
"(",
"'mongoose cache error %s'",
",",
"queryKey",
")",
";",
"debug",
"(",
"err",
")",
";",
"ok",
"(",
"[",
"null",
",",
"null",
"]",
")",
";",
"// ignore error, instead reject",
"//return error(err);",
"}",
"var",
"collectionData",
"=",
"results",
"[",
"0",
"]",
"&&",
"JSON",
".",
"parse",
"(",
"results",
"[",
"0",
"]",
")",
",",
"queryData",
"=",
"results",
"[",
"1",
"]",
"&&",
"JSON",
".",
"parse",
"(",
"results",
"[",
"1",
"]",
")",
";",
"//debug('redis cache object size', queryKey, helpers.getObjectSize(queryData));",
"// special cache miss where it is out of date",
"if",
"(",
"queryData",
"&&",
"collectionData",
"&&",
"collectionData",
".",
"lastWrite",
">",
"queryData",
".",
"metadata",
".",
"lastWrite",
")",
"{",
"debug",
"(",
"'mongoose cache out of date: '",
",",
"queryKey",
")",
";",
"queryData",
"=",
"null",
";",
"}",
"ok",
"(",
"[",
"collectionData",
",",
"queryData",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | get query result = require(redis cache and check lastWrite | [
"get",
"query",
"result",
"=",
"require",
"(",
"redis",
"cache",
"and",
"check",
"lastWrite"
] | d20e150e054c784cc7db7c2487399e4f4eb730de | https://github.com/MostlyJS/mostly-feathers-mongoose/blob/d20e150e054c784cc7db7c2487399e4f4eb730de/src/plugins/mongoose-cache.js#L21-L43 |
|
51,830 | alex-wdmg/jquery-helper | build/helper.js | smoothScroll | function smoothScroll() {
if (window.addEventListener)
window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
var hb = {
sTop: 0,
sDelta: 0
};
function wheel(event) {
var distance = jQuery.browser.webkit ? 60 : 120;
if (event.wheelDelta)
delta = event.wheelDelta / 120;
else if (event.detail)
delta = -event.detail / 3;
hb.sTop = jQuery(window).scrollTop();
hb.sDelta = hb.sDelta + delta * distance;
jQuery(hb).stop().animate({
sTop: jQuery(window).scrollTop() - hb.sDelta,
sDelta: 0
}, {
duration: 200,
easing: 'linear',
step: function(now, ex) {
if (ex.prop == 'sTop') jQuery('html, body').scrollTop(now)
},
});
if (event.preventDefault)
event.preventDefault();
event.returnValue = false
}
} | javascript | function smoothScroll() {
if (window.addEventListener)
window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
var hb = {
sTop: 0,
sDelta: 0
};
function wheel(event) {
var distance = jQuery.browser.webkit ? 60 : 120;
if (event.wheelDelta)
delta = event.wheelDelta / 120;
else if (event.detail)
delta = -event.detail / 3;
hb.sTop = jQuery(window).scrollTop();
hb.sDelta = hb.sDelta + delta * distance;
jQuery(hb).stop().animate({
sTop: jQuery(window).scrollTop() - hb.sDelta,
sDelta: 0
}, {
duration: 200,
easing: 'linear',
step: function(now, ex) {
if (ex.prop == 'sTop') jQuery('html, body').scrollTop(now)
},
});
if (event.preventDefault)
event.preventDefault();
event.returnValue = false
}
} | [
"function",
"smoothScroll",
"(",
")",
"{",
"if",
"(",
"window",
".",
"addEventListener",
")",
"window",
".",
"addEventListener",
"(",
"'DOMMouseScroll'",
",",
"wheel",
",",
"false",
")",
";",
"window",
".",
"onmousewheel",
"=",
"document",
".",
"onmousewheel",
"=",
"wheel",
";",
"var",
"hb",
"=",
"{",
"sTop",
":",
"0",
",",
"sDelta",
":",
"0",
"}",
";",
"function",
"wheel",
"(",
"event",
")",
"{",
"var",
"distance",
"=",
"jQuery",
".",
"browser",
".",
"webkit",
"?",
"60",
":",
"120",
";",
"if",
"(",
"event",
".",
"wheelDelta",
")",
"delta",
"=",
"event",
".",
"wheelDelta",
"/",
"120",
";",
"else",
"if",
"(",
"event",
".",
"detail",
")",
"delta",
"=",
"-",
"event",
".",
"detail",
"/",
"3",
";",
"hb",
".",
"sTop",
"=",
"jQuery",
"(",
"window",
")",
".",
"scrollTop",
"(",
")",
";",
"hb",
".",
"sDelta",
"=",
"hb",
".",
"sDelta",
"+",
"delta",
"*",
"distance",
";",
"jQuery",
"(",
"hb",
")",
".",
"stop",
"(",
")",
".",
"animate",
"(",
"{",
"sTop",
":",
"jQuery",
"(",
"window",
")",
".",
"scrollTop",
"(",
")",
"-",
"hb",
".",
"sDelta",
",",
"sDelta",
":",
"0",
"}",
",",
"{",
"duration",
":",
"200",
",",
"easing",
":",
"'linear'",
",",
"step",
":",
"function",
"(",
"now",
",",
"ex",
")",
"{",
"if",
"(",
"ex",
".",
"prop",
"==",
"'sTop'",
")",
"jQuery",
"(",
"'html, body'",
")",
".",
"scrollTop",
"(",
"now",
")",
"}",
",",
"}",
")",
";",
"if",
"(",
"event",
".",
"preventDefault",
")",
"event",
".",
"preventDefault",
"(",
")",
";",
"event",
".",
"returnValue",
"=",
"false",
"}",
"}"
] | Smooth scroll plugin | [
"Smooth",
"scroll",
"plugin"
] | 39f8ac6c6b72fbf51f7aa5026d8a0d2c8361be57 | https://github.com/alex-wdmg/jquery-helper/blob/39f8ac6c6b72fbf51f7aa5026d8a0d2c8361be57/build/helper.js#L717-L757 |
51,831 | vimsucks/ezini | dist/ini.js | stringifySync | function stringifySync(obj) {
var output = "";
var firstOccur = true;
Object.keys(obj).forEach(function (key) {
if (typeof obj[key] === "string") {
output += key + "=" + obj[key];
output += os.EOL;
} else {
if (firstOccur) {
firstOccur = false;
} else {
output += os.EOL;
}
output += "[" + key + "]";
output += os.EOL;
Object.keys(obj[key]).forEach(function (innerKey) {
var value = obj[key][innerKey];
if (typeof value === "string") {
// if value can ber converted to number or boolean,
// but it should be a string,
// so keep the quotes to indicate its type
if (!isNaN(value) || value.toLowerCase() === "true" || value.toLowerCase() === "false") {
value = "\"" + value + "\"";
}
}
output += innerKey + "=" + value;
output += os.EOL;
});
}
});
return output;
} | javascript | function stringifySync(obj) {
var output = "";
var firstOccur = true;
Object.keys(obj).forEach(function (key) {
if (typeof obj[key] === "string") {
output += key + "=" + obj[key];
output += os.EOL;
} else {
if (firstOccur) {
firstOccur = false;
} else {
output += os.EOL;
}
output += "[" + key + "]";
output += os.EOL;
Object.keys(obj[key]).forEach(function (innerKey) {
var value = obj[key][innerKey];
if (typeof value === "string") {
// if value can ber converted to number or boolean,
// but it should be a string,
// so keep the quotes to indicate its type
if (!isNaN(value) || value.toLowerCase() === "true" || value.toLowerCase() === "false") {
value = "\"" + value + "\"";
}
}
output += innerKey + "=" + value;
output += os.EOL;
});
}
});
return output;
} | [
"function",
"stringifySync",
"(",
"obj",
")",
"{",
"var",
"output",
"=",
"\"\"",
";",
"var",
"firstOccur",
"=",
"true",
";",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"typeof",
"obj",
"[",
"key",
"]",
"===",
"\"string\"",
")",
"{",
"output",
"+=",
"key",
"+",
"\"=\"",
"+",
"obj",
"[",
"key",
"]",
";",
"output",
"+=",
"os",
".",
"EOL",
";",
"}",
"else",
"{",
"if",
"(",
"firstOccur",
")",
"{",
"firstOccur",
"=",
"false",
";",
"}",
"else",
"{",
"output",
"+=",
"os",
".",
"EOL",
";",
"}",
"output",
"+=",
"\"[\"",
"+",
"key",
"+",
"\"]\"",
";",
"output",
"+=",
"os",
".",
"EOL",
";",
"Object",
".",
"keys",
"(",
"obj",
"[",
"key",
"]",
")",
".",
"forEach",
"(",
"function",
"(",
"innerKey",
")",
"{",
"var",
"value",
"=",
"obj",
"[",
"key",
"]",
"[",
"innerKey",
"]",
";",
"if",
"(",
"typeof",
"value",
"===",
"\"string\"",
")",
"{",
"// if value can ber converted to number or boolean,",
"// but it should be a string,",
"// so keep the quotes to indicate its type",
"if",
"(",
"!",
"isNaN",
"(",
"value",
")",
"||",
"value",
".",
"toLowerCase",
"(",
")",
"===",
"\"true\"",
"||",
"value",
".",
"toLowerCase",
"(",
")",
"===",
"\"false\"",
")",
"{",
"value",
"=",
"\"\\\"\"",
"+",
"value",
"+",
"\"\\\"\"",
";",
"}",
"}",
"output",
"+=",
"innerKey",
"+",
"\"=\"",
"+",
"value",
";",
"output",
"+=",
"os",
".",
"EOL",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"output",
";",
"}"
] | Stringify an object to an ini-format string
@param {Object} obj Object to be stringify
@returns {string} INI-format string which is stringified from given object | [
"Stringify",
"an",
"object",
"to",
"an",
"ini",
"-",
"format",
"string"
] | 3bd04b8cd0694213dcfa3075b56536bf725daefe | https://github.com/vimsucks/ezini/blob/3bd04b8cd0694213dcfa3075b56536bf725daefe/dist/ini.js#L72-L107 |
51,832 | vimsucks/ezini | dist/ini.js | stringify | function stringify(obj, callback) {
process.nextTick(function () {
var str = stringifySync(obj);
callback(str);
});
} | javascript | function stringify(obj, callback) {
process.nextTick(function () {
var str = stringifySync(obj);
callback(str);
});
} | [
"function",
"stringify",
"(",
"obj",
",",
"callback",
")",
"{",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"var",
"str",
"=",
"stringifySync",
"(",
"obj",
")",
";",
"callback",
"(",
"str",
")",
";",
"}",
")",
";",
"}"
] | Async wrapper of function stringifySync
@param {Object} obj Object to be stringify
@param callback Callback after parsing complete,
should have one parameter: str(stringified from given object) | [
"Async",
"wrapper",
"of",
"function",
"stringifySync"
] | 3bd04b8cd0694213dcfa3075b56536bf725daefe | https://github.com/vimsucks/ezini/blob/3bd04b8cd0694213dcfa3075b56536bf725daefe/dist/ini.js#L115-L120 |
51,833 | warmsea/WarmseaJS | dist/warmsea.js | function(behavior) {
return function(obj, iteratee, context) {
var result = {};
iteratee = _.iteratee(iteratee, context);
_.each(obj, function(value, index) {
var key = iteratee(value, index, obj);
behavior(result, value, key);
});
return result;
};
} | javascript | function(behavior) {
return function(obj, iteratee, context) {
var result = {};
iteratee = _.iteratee(iteratee, context);
_.each(obj, function(value, index) {
var key = iteratee(value, index, obj);
behavior(result, value, key);
});
return result;
};
} | [
"function",
"(",
"behavior",
")",
"{",
"return",
"function",
"(",
"obj",
",",
"iteratee",
",",
"context",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"iteratee",
"=",
"_",
".",
"iteratee",
"(",
"iteratee",
",",
"context",
")",
";",
"_",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"value",
",",
"index",
")",
"{",
"var",
"key",
"=",
"iteratee",
"(",
"value",
",",
"index",
",",
"obj",
")",
";",
"behavior",
"(",
"result",
",",
"value",
",",
"key",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}",
";",
"}"
] | An internal function used for aggregate "group by" operations. | [
"An",
"internal",
"function",
"used",
"for",
"aggregate",
"group",
"by",
"operations",
"."
] | 58c32c75b26647bbec39dc401a78b0fdb5896c8d | https://github.com/warmsea/WarmseaJS/blob/58c32c75b26647bbec39dc401a78b0fdb5896c8d/dist/warmsea.js#L370-L380 |
|
51,834 | mysticatea/warun | bin/events.js | emitSIGINT | function emitSIGINT() {
if (rl) {
rl.close()
rl = null
}
if (ipcListener) {
process.removeListener("message", ipcListener)
ipcListener = null
}
emitter.emit("SIGINT")
} | javascript | function emitSIGINT() {
if (rl) {
rl.close()
rl = null
}
if (ipcListener) {
process.removeListener("message", ipcListener)
ipcListener = null
}
emitter.emit("SIGINT")
} | [
"function",
"emitSIGINT",
"(",
")",
"{",
"if",
"(",
"rl",
")",
"{",
"rl",
".",
"close",
"(",
")",
"rl",
"=",
"null",
"}",
"if",
"(",
"ipcListener",
")",
"{",
"process",
".",
"removeListener",
"(",
"\"message\"",
",",
"ipcListener",
")",
"ipcListener",
"=",
"null",
"}",
"emitter",
".",
"emit",
"(",
"\"SIGINT\"",
")",
"}"
] | Emit SIGINT event.
@returns {void} | [
"Emit",
"SIGINT",
"event",
"."
] | 9dc36fa1aeddf6540f0effd6726a056d9a3287f1 | https://github.com/mysticatea/warun/blob/9dc36fa1aeddf6540f0effd6726a056d9a3287f1/bin/events.js#L19-L30 |
51,835 | tolokoban/ToloFrameWork | ker/tfw3.js | function(className) {
var cls = _classes[className];
if (!cls) {
var k, name,
def = window["TFW::" + className];
if (!def) {
throw new Error(
"[TFW3] This class has not been defined: \"" + className + "\"!\n"
+ "Did you forget to include it?"
);
}
// Création de la classe à partir de sa définition.
cls = function () {};
var superclass = TFW3Object;
if (def.superclass) {
superclass = loadClass(def.superclass);
}
// Héritage
cls.prototype = new superclass();
// Eviter que le constructeur de cette classe soit celui de la super classe.
cls.prototype.constructor = cls;
// Définition de l'attribut $parent pour accéder aux méthodes parentes.
cls.prototype.$parent = superclass.prototype;
// Multilangues.
if (typeof def.lang === "object") {
cls.prototype.$lang = def.lang;
for (k in def.lang) {
cls.prototype.$defLang = k;
break;
}
} else {
cls.prototype.$lang = superclass.prototype.$lang || {};
cls.prototype.$defLang = superclass.prototype.$defLang || "en";
}
// Conserver le nom de la super classe.
cls.prototype.$superclass = superclass.prototype.$classname;
// Conserver le nom de la classe.
cls.prototype.$classname = className;
// Les noms des signals.
cls.prototype.$signals = def.signals;
// Est-ce un singleton ?
cls.prototype.$singleton = def.singleton;
// Espace réservé aux membres statiques de la classe.
var staticVars = {className: className};
_statics[className] = staticVars;
cls.prototype.$static = staticVars;
// Valeurs par défaut des attributs.
if (def.attributes) {
for (k in def.attributes) {
cls.prototype["_" + k] = def.attributes[k];
}
}
// Déclaration du constructeur.
cls.prototype.$init = def.init;
// Définition des méthodes liées aux signaux.
if (def.signals) {
for (i in def.signals) {
declareSignal(
cls,
def.signals[i]
);
}
}
// Assigner toutes les méthodes.
for (name in def.functions) {
if (def.superclass && cls.prototype[name]) {
// This is an ovveride.
cls.prototype[def.superclass + "$" + name] = cls.prototype[name];
}
cls.prototype[name] = def.functions[name];
}
// Mise en cache de la classe.
_classes[className] = cls;
// Appel d'un éventuel constructeur de classe.
if (typeof def.classInit === "function") {
def.classInit(staticVars);
}
}
return cls;
} | javascript | function(className) {
var cls = _classes[className];
if (!cls) {
var k, name,
def = window["TFW::" + className];
if (!def) {
throw new Error(
"[TFW3] This class has not been defined: \"" + className + "\"!\n"
+ "Did you forget to include it?"
);
}
// Création de la classe à partir de sa définition.
cls = function () {};
var superclass = TFW3Object;
if (def.superclass) {
superclass = loadClass(def.superclass);
}
// Héritage
cls.prototype = new superclass();
// Eviter que le constructeur de cette classe soit celui de la super classe.
cls.prototype.constructor = cls;
// Définition de l'attribut $parent pour accéder aux méthodes parentes.
cls.prototype.$parent = superclass.prototype;
// Multilangues.
if (typeof def.lang === "object") {
cls.prototype.$lang = def.lang;
for (k in def.lang) {
cls.prototype.$defLang = k;
break;
}
} else {
cls.prototype.$lang = superclass.prototype.$lang || {};
cls.prototype.$defLang = superclass.prototype.$defLang || "en";
}
// Conserver le nom de la super classe.
cls.prototype.$superclass = superclass.prototype.$classname;
// Conserver le nom de la classe.
cls.prototype.$classname = className;
// Les noms des signals.
cls.prototype.$signals = def.signals;
// Est-ce un singleton ?
cls.prototype.$singleton = def.singleton;
// Espace réservé aux membres statiques de la classe.
var staticVars = {className: className};
_statics[className] = staticVars;
cls.prototype.$static = staticVars;
// Valeurs par défaut des attributs.
if (def.attributes) {
for (k in def.attributes) {
cls.prototype["_" + k] = def.attributes[k];
}
}
// Déclaration du constructeur.
cls.prototype.$init = def.init;
// Définition des méthodes liées aux signaux.
if (def.signals) {
for (i in def.signals) {
declareSignal(
cls,
def.signals[i]
);
}
}
// Assigner toutes les méthodes.
for (name in def.functions) {
if (def.superclass && cls.prototype[name]) {
// This is an ovveride.
cls.prototype[def.superclass + "$" + name] = cls.prototype[name];
}
cls.prototype[name] = def.functions[name];
}
// Mise en cache de la classe.
_classes[className] = cls;
// Appel d'un éventuel constructeur de classe.
if (typeof def.classInit === "function") {
def.classInit(staticVars);
}
}
return cls;
} | [
"function",
"(",
"className",
")",
"{",
"var",
"cls",
"=",
"_classes",
"[",
"className",
"]",
";",
"if",
"(",
"!",
"cls",
")",
"{",
"var",
"k",
",",
"name",
",",
"def",
"=",
"window",
"[",
"\"TFW::\"",
"+",
"className",
"]",
";",
"if",
"(",
"!",
"def",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"[TFW3] This class has not been defined: \\\"\"",
"+",
"className",
"+",
"\"\\\"!\\n\"",
"+",
"\"Did you forget to include it?\"",
")",
";",
"}",
"// Création de la classe à partir de sa définition.",
"cls",
"=",
"function",
"(",
")",
"{",
"}",
";",
"var",
"superclass",
"=",
"TFW3Object",
";",
"if",
"(",
"def",
".",
"superclass",
")",
"{",
"superclass",
"=",
"loadClass",
"(",
"def",
".",
"superclass",
")",
";",
"}",
"// Héritage",
"cls",
".",
"prototype",
"=",
"new",
"superclass",
"(",
")",
";",
"// Eviter que le constructeur de cette classe soit celui de la super classe.",
"cls",
".",
"prototype",
".",
"constructor",
"=",
"cls",
";",
"// Définition de l'attribut $parent pour accéder aux méthodes parentes.",
"cls",
".",
"prototype",
".",
"$parent",
"=",
"superclass",
".",
"prototype",
";",
"// Multilangues.",
"if",
"(",
"typeof",
"def",
".",
"lang",
"===",
"\"object\"",
")",
"{",
"cls",
".",
"prototype",
".",
"$lang",
"=",
"def",
".",
"lang",
";",
"for",
"(",
"k",
"in",
"def",
".",
"lang",
")",
"{",
"cls",
".",
"prototype",
".",
"$defLang",
"=",
"k",
";",
"break",
";",
"}",
"}",
"else",
"{",
"cls",
".",
"prototype",
".",
"$lang",
"=",
"superclass",
".",
"prototype",
".",
"$lang",
"||",
"{",
"}",
";",
"cls",
".",
"prototype",
".",
"$defLang",
"=",
"superclass",
".",
"prototype",
".",
"$defLang",
"||",
"\"en\"",
";",
"}",
"// Conserver le nom de la super classe.",
"cls",
".",
"prototype",
".",
"$superclass",
"=",
"superclass",
".",
"prototype",
".",
"$classname",
";",
"// Conserver le nom de la classe.",
"cls",
".",
"prototype",
".",
"$classname",
"=",
"className",
";",
"// Les noms des signals.",
"cls",
".",
"prototype",
".",
"$signals",
"=",
"def",
".",
"signals",
";",
"// Est-ce un singleton ?",
"cls",
".",
"prototype",
".",
"$singleton",
"=",
"def",
".",
"singleton",
";",
"// Espace réservé aux membres statiques de la classe.",
"var",
"staticVars",
"=",
"{",
"className",
":",
"className",
"}",
";",
"_statics",
"[",
"className",
"]",
"=",
"staticVars",
";",
"cls",
".",
"prototype",
".",
"$static",
"=",
"staticVars",
";",
"// Valeurs par défaut des attributs.",
"if",
"(",
"def",
".",
"attributes",
")",
"{",
"for",
"(",
"k",
"in",
"def",
".",
"attributes",
")",
"{",
"cls",
".",
"prototype",
"[",
"\"_\"",
"+",
"k",
"]",
"=",
"def",
".",
"attributes",
"[",
"k",
"]",
";",
"}",
"}",
"// Déclaration du constructeur.",
"cls",
".",
"prototype",
".",
"$init",
"=",
"def",
".",
"init",
";",
"// Définition des méthodes liées aux signaux.",
"if",
"(",
"def",
".",
"signals",
")",
"{",
"for",
"(",
"i",
"in",
"def",
".",
"signals",
")",
"{",
"declareSignal",
"(",
"cls",
",",
"def",
".",
"signals",
"[",
"i",
"]",
")",
";",
"}",
"}",
"// Assigner toutes les méthodes.",
"for",
"(",
"name",
"in",
"def",
".",
"functions",
")",
"{",
"if",
"(",
"def",
".",
"superclass",
"&&",
"cls",
".",
"prototype",
"[",
"name",
"]",
")",
"{",
"// This is an ovveride.",
"cls",
".",
"prototype",
"[",
"def",
".",
"superclass",
"+",
"\"$\"",
"+",
"name",
"]",
"=",
"cls",
".",
"prototype",
"[",
"name",
"]",
";",
"}",
"cls",
".",
"prototype",
"[",
"name",
"]",
"=",
"def",
".",
"functions",
"[",
"name",
"]",
";",
"}",
"// Mise en cache de la classe.",
"_classes",
"[",
"className",
"]",
"=",
"cls",
";",
"// Appel d'un éventuel constructeur de classe.",
"if",
"(",
"typeof",
"def",
".",
"classInit",
"===",
"\"function\"",
")",
"{",
"def",
".",
"classInit",
"(",
"staticVars",
")",
";",
"}",
"}",
"return",
"cls",
";",
"}"
] | Load class definition. | [
"Load",
"class",
"definition",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/tfw3.js#L261-L341 |
|
51,836 | hypergroup/hyper-json-immutable-parse | index.js | parse | function parse(base, key, value) {
var type = typeof value;
// resolve local JSON pointers
if (key === 'href' && type === 'string') return formatHref(base, value);
// TODO resolve "/" paths
if (!value || type !== 'object') return value;
var obj = copy(value);
if (key === '' || obj.href) seal(base || obj.href, obj, []);
return obj;
} | javascript | function parse(base, key, value) {
var type = typeof value;
// resolve local JSON pointers
if (key === 'href' && type === 'string') return formatHref(base, value);
// TODO resolve "/" paths
if (!value || type !== 'object') return value;
var obj = copy(value);
if (key === '' || obj.href) seal(base || obj.href, obj, []);
return obj;
} | [
"function",
"parse",
"(",
"base",
",",
"key",
",",
"value",
")",
"{",
"var",
"type",
"=",
"typeof",
"value",
";",
"// resolve local JSON pointers",
"if",
"(",
"key",
"===",
"'href'",
"&&",
"type",
"===",
"'string'",
")",
"return",
"formatHref",
"(",
"base",
",",
"value",
")",
";",
"// TODO resolve \"/\" paths",
"if",
"(",
"!",
"value",
"||",
"type",
"!==",
"'object'",
")",
"return",
"value",
";",
"var",
"obj",
"=",
"copy",
"(",
"value",
")",
";",
"if",
"(",
"key",
"===",
"''",
"||",
"obj",
".",
"href",
")",
"seal",
"(",
"base",
"||",
"obj",
".",
"href",
",",
"obj",
",",
"[",
"]",
")",
";",
"return",
"obj",
";",
"}"
] | Parse a key value pair
@param {String} href
@param {String} key
@param {Any} value | [
"Parse",
"a",
"key",
"value",
"pair"
] | b77467c70bfe1c5b49f749a915fe585d7bac256d | https://github.com/hypergroup/hyper-json-immutable-parse/blob/b77467c70bfe1c5b49f749a915fe585d7bac256d/index.js#L26-L40 |
51,837 | zipscene/polytoken | lib/geometry.js | getPointLineSegmentState | function getPointLineSegmentState([ x, y ], [ [ beginX, beginY ], [ endX, endY ] ]) {
if (!isPointInLine([ x, y ], [ [ beginX, beginY ], [ endX, endY ] ])) {
return OUTSIDE;
}
if (beginX === endX) {
if (roundToFiveSignificantDigits((y - beginY) * (y - endY)) < 0) {
return INSIDE;
} else if (roundToFiveSignificantDigits((y - beginY) * (y - endY)) === 0) {
return TANGENT;
} else {
return OUTSIDE;
}
}
if (beginY === endY) {
if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) < 0) {
return INSIDE;
} else if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) === 0) {
return TANGENT;
} else {
return OUTSIDE;
}
}
if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) < 0
&& roundToFiveSignificantDigits((y - beginY) * (y - endY)) < 0) {
return INSIDE;
} else if (x === beginX && y === beginY || (x === endX && y === endY)) {
return TANGENT;
} else {
return OUTSIDE;
}
} | javascript | function getPointLineSegmentState([ x, y ], [ [ beginX, beginY ], [ endX, endY ] ]) {
if (!isPointInLine([ x, y ], [ [ beginX, beginY ], [ endX, endY ] ])) {
return OUTSIDE;
}
if (beginX === endX) {
if (roundToFiveSignificantDigits((y - beginY) * (y - endY)) < 0) {
return INSIDE;
} else if (roundToFiveSignificantDigits((y - beginY) * (y - endY)) === 0) {
return TANGENT;
} else {
return OUTSIDE;
}
}
if (beginY === endY) {
if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) < 0) {
return INSIDE;
} else if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) === 0) {
return TANGENT;
} else {
return OUTSIDE;
}
}
if (roundToFiveSignificantDigits((x - beginX) * (x - endX)) < 0
&& roundToFiveSignificantDigits((y - beginY) * (y - endY)) < 0) {
return INSIDE;
} else if (x === beginX && y === beginY || (x === endX && y === endY)) {
return TANGENT;
} else {
return OUTSIDE;
}
} | [
"function",
"getPointLineSegmentState",
"(",
"[",
"x",
",",
"y",
"]",
",",
"[",
"[",
"beginX",
",",
"beginY",
"]",
",",
"[",
"endX",
",",
"endY",
"]",
"]",
")",
"{",
"if",
"(",
"!",
"isPointInLine",
"(",
"[",
"x",
",",
"y",
"]",
",",
"[",
"[",
"beginX",
",",
"beginY",
"]",
",",
"[",
"endX",
",",
"endY",
"]",
"]",
")",
")",
"{",
"return",
"OUTSIDE",
";",
"}",
"if",
"(",
"beginX",
"===",
"endX",
")",
"{",
"if",
"(",
"roundToFiveSignificantDigits",
"(",
"(",
"y",
"-",
"beginY",
")",
"*",
"(",
"y",
"-",
"endY",
")",
")",
"<",
"0",
")",
"{",
"return",
"INSIDE",
";",
"}",
"else",
"if",
"(",
"roundToFiveSignificantDigits",
"(",
"(",
"y",
"-",
"beginY",
")",
"*",
"(",
"y",
"-",
"endY",
")",
")",
"===",
"0",
")",
"{",
"return",
"TANGENT",
";",
"}",
"else",
"{",
"return",
"OUTSIDE",
";",
"}",
"}",
"if",
"(",
"beginY",
"===",
"endY",
")",
"{",
"if",
"(",
"roundToFiveSignificantDigits",
"(",
"(",
"x",
"-",
"beginX",
")",
"*",
"(",
"x",
"-",
"endX",
")",
")",
"<",
"0",
")",
"{",
"return",
"INSIDE",
";",
"}",
"else",
"if",
"(",
"roundToFiveSignificantDigits",
"(",
"(",
"x",
"-",
"beginX",
")",
"*",
"(",
"x",
"-",
"endX",
")",
")",
"===",
"0",
")",
"{",
"return",
"TANGENT",
";",
"}",
"else",
"{",
"return",
"OUTSIDE",
";",
"}",
"}",
"if",
"(",
"roundToFiveSignificantDigits",
"(",
"(",
"x",
"-",
"beginX",
")",
"*",
"(",
"x",
"-",
"endX",
")",
")",
"<",
"0",
"&&",
"roundToFiveSignificantDigits",
"(",
"(",
"y",
"-",
"beginY",
")",
"*",
"(",
"y",
"-",
"endY",
")",
")",
"<",
"0",
")",
"{",
"return",
"INSIDE",
";",
"}",
"else",
"if",
"(",
"x",
"===",
"beginX",
"&&",
"y",
"===",
"beginY",
"||",
"(",
"x",
"===",
"endX",
"&&",
"y",
"===",
"endY",
")",
")",
"{",
"return",
"TANGENT",
";",
"}",
"else",
"{",
"return",
"OUTSIDE",
";",
"}",
"}"
] | Get the state of a point in relationship to a line segment
@method getPointLineSegmentState
@param {Number[]} [ x, y ] - coordinates of the point
@param {Number[][]} [ [ beginX, beginY ], [ endX, endY ] ] - coordinates of begin and end points of the line segment
@return {String} - return the state of the point. Can only be one of: 'inside', 'outside' and 'tangent' | [
"Get",
"the",
"state",
"of",
"a",
"point",
"in",
"relationship",
"to",
"a",
"line",
"segment"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L45-L75 |
51,838 | zipscene/polytoken | lib/geometry.js | getLineIntersect | function getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]) {
let [ x1Begin, y1Begin ] = line1Begin;
let [ x1End, y1End ] = line1End;
let [ x2Begin, y2Begin ] = line2Begin;
let [ x2End, y2End ] = line2End;
if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
}
let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
let intercept1;
if (x1Begin === x1End) {
intercept1 = x1Begin;
} else if (y1Begin === y1End) {
intercept1 = y1Begin;
} else {
intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
}
let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
let intercept2;
if (x2Begin === x2End) {
intercept2 = x2Begin;
} else if (y2Begin === y2End) {
intercept2 = y2Begin;
} else {
intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
}
let intersectX, intersectY;
if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
throw new XError(XError.INVALID_ARGUMENT, 'Can\'t get intersect of lines with the same slope');
} else {
if (Math.abs(slope1) === Infinity) {
intersectX = x1Begin;
intersectY = roundToFiveSignificantDigits(slope2 * x1Begin + intercept2);
} else if (Math.abs(slope2) === Infinity) {
intersectX = x2Begin;
intersectY = roundToFiveSignificantDigits(slope1 * x2Begin + intercept1);
} else if (slope1 === 0) {
intersectY = y1Begin;
intersectX = roundToFiveSignificantDigits((intersectY - intercept2) / slope2);
} else if (slope2 === 0) {
intersectY = y2Begin;
intersectX = roundToFiveSignificantDigits((intersectY - intercept1) / slope1);
} else {
intersectX = roundToFiveSignificantDigits((intercept2 - intercept1) / (slope1 - slope2));
intersectY = roundToFiveSignificantDigits(((slope1 * intercept2)
- (slope2 * intercept1)) / (slope1 - slope2));
}
}
return [ intersectX, intersectY ];
} | javascript | function getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]) {
let [ x1Begin, y1Begin ] = line1Begin;
let [ x1End, y1End ] = line1End;
let [ x2Begin, y2Begin ] = line2Begin;
let [ x2End, y2End ] = line2End;
if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
}
let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
let intercept1;
if (x1Begin === x1End) {
intercept1 = x1Begin;
} else if (y1Begin === y1End) {
intercept1 = y1Begin;
} else {
intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
}
let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
let intercept2;
if (x2Begin === x2End) {
intercept2 = x2Begin;
} else if (y2Begin === y2End) {
intercept2 = y2Begin;
} else {
intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
}
let intersectX, intersectY;
if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
throw new XError(XError.INVALID_ARGUMENT, 'Can\'t get intersect of lines with the same slope');
} else {
if (Math.abs(slope1) === Infinity) {
intersectX = x1Begin;
intersectY = roundToFiveSignificantDigits(slope2 * x1Begin + intercept2);
} else if (Math.abs(slope2) === Infinity) {
intersectX = x2Begin;
intersectY = roundToFiveSignificantDigits(slope1 * x2Begin + intercept1);
} else if (slope1 === 0) {
intersectY = y1Begin;
intersectX = roundToFiveSignificantDigits((intersectY - intercept2) / slope2);
} else if (slope2 === 0) {
intersectY = y2Begin;
intersectX = roundToFiveSignificantDigits((intersectY - intercept1) / slope1);
} else {
intersectX = roundToFiveSignificantDigits((intercept2 - intercept1) / (slope1 - slope2));
intersectY = roundToFiveSignificantDigits(((slope1 * intercept2)
- (slope2 * intercept1)) / (slope1 - slope2));
}
}
return [ intersectX, intersectY ];
} | [
"function",
"getLineIntersect",
"(",
"[",
"line1Begin",
",",
"line1End",
"]",
",",
"[",
"line2Begin",
",",
"line2End",
"]",
")",
"{",
"let",
"[",
"x1Begin",
",",
"y1Begin",
"]",
"=",
"line1Begin",
";",
"let",
"[",
"x1End",
",",
"y1End",
"]",
"=",
"line1End",
";",
"let",
"[",
"x2Begin",
",",
"y2Begin",
"]",
"=",
"line2Begin",
";",
"let",
"[",
"x2End",
",",
"y2End",
"]",
"=",
"line2End",
";",
"if",
"(",
"(",
"x1Begin",
"===",
"x1End",
"&&",
"y1Begin",
"===",
"y1End",
")",
"||",
"(",
"x2Begin",
"===",
"x2End",
"&&",
"y2Begin",
"===",
"y2End",
")",
")",
"{",
"throw",
"new",
"XError",
"(",
"XError",
".",
"INVALID_ARGUMENT",
",",
"'start and end point of line must not be the same'",
")",
";",
"}",
"let",
"slope1",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y1Begin",
"-",
"y1End",
")",
"/",
"(",
"x1Begin",
"-",
"x1End",
")",
")",
";",
"let",
"intercept1",
";",
"if",
"(",
"x1Begin",
"===",
"x1End",
")",
"{",
"intercept1",
"=",
"x1Begin",
";",
"}",
"else",
"if",
"(",
"y1Begin",
"===",
"y1End",
")",
"{",
"intercept1",
"=",
"y1Begin",
";",
"}",
"else",
"{",
"intercept1",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y1Begin",
"*",
"x1End",
"-",
"y1End",
"*",
"x1Begin",
")",
"/",
"(",
"x1End",
"-",
"x1Begin",
")",
")",
";",
"}",
"let",
"slope2",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y2Begin",
"-",
"y2End",
")",
"/",
"(",
"x2Begin",
"-",
"x2End",
")",
")",
";",
"let",
"intercept2",
";",
"if",
"(",
"x2Begin",
"===",
"x2End",
")",
"{",
"intercept2",
"=",
"x2Begin",
";",
"}",
"else",
"if",
"(",
"y2Begin",
"===",
"y2End",
")",
"{",
"intercept2",
"=",
"y2Begin",
";",
"}",
"else",
"{",
"intercept2",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y2Begin",
"*",
"x2End",
"-",
"y2End",
"*",
"x2Begin",
")",
"/",
"(",
"x2End",
"-",
"x2Begin",
")",
")",
";",
"}",
"let",
"intersectX",
",",
"intersectY",
";",
"if",
"(",
"slope1",
"===",
"slope2",
"||",
"(",
"Math",
".",
"abs",
"(",
"slope1",
")",
"===",
"Infinity",
"&&",
"Math",
".",
"abs",
"(",
"slope2",
")",
"===",
"Infinity",
")",
")",
"{",
"throw",
"new",
"XError",
"(",
"XError",
".",
"INVALID_ARGUMENT",
",",
"'Can\\'t get intersect of lines with the same slope'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Math",
".",
"abs",
"(",
"slope1",
")",
"===",
"Infinity",
")",
"{",
"intersectX",
"=",
"x1Begin",
";",
"intersectY",
"=",
"roundToFiveSignificantDigits",
"(",
"slope2",
"*",
"x1Begin",
"+",
"intercept2",
")",
";",
"}",
"else",
"if",
"(",
"Math",
".",
"abs",
"(",
"slope2",
")",
"===",
"Infinity",
")",
"{",
"intersectX",
"=",
"x2Begin",
";",
"intersectY",
"=",
"roundToFiveSignificantDigits",
"(",
"slope1",
"*",
"x2Begin",
"+",
"intercept1",
")",
";",
"}",
"else",
"if",
"(",
"slope1",
"===",
"0",
")",
"{",
"intersectY",
"=",
"y1Begin",
";",
"intersectX",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"intersectY",
"-",
"intercept2",
")",
"/",
"slope2",
")",
";",
"}",
"else",
"if",
"(",
"slope2",
"===",
"0",
")",
"{",
"intersectY",
"=",
"y2Begin",
";",
"intersectX",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"intersectY",
"-",
"intercept1",
")",
"/",
"slope1",
")",
";",
"}",
"else",
"{",
"intersectX",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"intercept2",
"-",
"intercept1",
")",
"/",
"(",
"slope1",
"-",
"slope2",
")",
")",
";",
"intersectY",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"(",
"slope1",
"*",
"intercept2",
")",
"-",
"(",
"slope2",
"*",
"intercept1",
")",
")",
"/",
"(",
"slope1",
"-",
"slope2",
")",
")",
";",
"}",
"}",
"return",
"[",
"intersectX",
",",
"intersectY",
"]",
";",
"}"
] | Get the intersect point of two lines
@method getLineIntersect
@param {Number[]} line1Begin - coordianates of first point in line1
@param {Number[]} line1End - coordianates of second point of line1
@param {Number[]} line2Begin - coordianates of first point in line2
@param {Number[]} line2End - coordianates of second point of line2
@return {Number[]} - returns the coordianates of intersect point | [
"Get",
"the",
"intersect",
"point",
"of",
"two",
"lines"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L115-L168 |
51,839 | zipscene/polytoken | lib/geometry.js | getLineSegmentsIntersectState | function getLineSegmentsIntersectState([ line1Begin, line1End ], [ line2Begin, line2End ]) {
let [ x1Begin, y1Begin ] = line1Begin;
let [ x1End, y1End ] = line1End;
let [ x2Begin, y2Begin ] = line2Begin;
let [ x2End, y2End ] = line2End;
if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
}
let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
let intercept1;
if (x1Begin === x1End) {
intercept1 = x1Begin;
} else if (y1Begin === y1End) {
intercept1 = y1Begin;
} else {
intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
}
let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
let intercept2;
if (x2Begin === x2End) {
intercept2 = x2Begin;
} else if (y2Begin === y2End) {
intercept2 = y2Begin;
} else {
intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
}
if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
if (intercept1 !== intercept2) {
return UNINTERSECT;
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) !== OUTSIDE
&& getPointLineSegmentState(line2End, [ line1Begin, line1End ]) !== OUTSIDE
) {
return INCLUDED;
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) === OUTSIDE
&& getPointLineSegmentState(line2End, [ line1Begin, line1End ]) === OUTSIDE
) {
if ((line2Begin - line1Begin) * (line2End - line1Begin) > 0) {
return UNINTERSECT;
} else {
return OVERLAP;
}
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) === TANGENT
|| getPointLineSegmentState(line2End, [ line1Begin, line1End ]) === TANGENT
) {
return TANGENT;
} else {
return OVERLAP;
}
} else {
let intersect = getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]);
let line1State = getPointLineSegmentState(intersect, [ line1Begin, line1End ]);
let line2State = getPointLineSegmentState(intersect, [ line2Begin, line2End ]);
if (line1State === OUTSIDE || line2State === OUTSIDE) return UNINTERSECT;
if (line1State === TANGENT || line2State === TANGENT) return TANGENT;
return INTERSECT;
}
} | javascript | function getLineSegmentsIntersectState([ line1Begin, line1End ], [ line2Begin, line2End ]) {
let [ x1Begin, y1Begin ] = line1Begin;
let [ x1End, y1End ] = line1End;
let [ x2Begin, y2Begin ] = line2Begin;
let [ x2End, y2End ] = line2End;
if ((x1Begin === x1End && y1Begin === y1End) || (x2Begin === x2End && y2Begin === y2End)) {
throw new XError(XError.INVALID_ARGUMENT, 'start and end point of line must not be the same');
}
let slope1 = roundToFiveSignificantDigits((y1Begin - y1End) / (x1Begin - x1End));
let intercept1;
if (x1Begin === x1End) {
intercept1 = x1Begin;
} else if (y1Begin === y1End) {
intercept1 = y1Begin;
} else {
intercept1 = roundToFiveSignificantDigits((y1Begin * x1End - y1End * x1Begin) / (x1End - x1Begin));
}
let slope2 = roundToFiveSignificantDigits((y2Begin - y2End) / (x2Begin - x2End));
let intercept2;
if (x2Begin === x2End) {
intercept2 = x2Begin;
} else if (y2Begin === y2End) {
intercept2 = y2Begin;
} else {
intercept2 = roundToFiveSignificantDigits((y2Begin * x2End - y2End * x2Begin) / (x2End - x2Begin));
}
if (slope1 === slope2 || (Math.abs(slope1) === Infinity && Math.abs(slope2) === Infinity)) {
if (intercept1 !== intercept2) {
return UNINTERSECT;
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) !== OUTSIDE
&& getPointLineSegmentState(line2End, [ line1Begin, line1End ]) !== OUTSIDE
) {
return INCLUDED;
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) === OUTSIDE
&& getPointLineSegmentState(line2End, [ line1Begin, line1End ]) === OUTSIDE
) {
if ((line2Begin - line1Begin) * (line2End - line1Begin) > 0) {
return UNINTERSECT;
} else {
return OVERLAP;
}
} else if (getPointLineSegmentState(line2Begin, [ line1Begin, line1End ]) === TANGENT
|| getPointLineSegmentState(line2End, [ line1Begin, line1End ]) === TANGENT
) {
return TANGENT;
} else {
return OVERLAP;
}
} else {
let intersect = getLineIntersect([ line1Begin, line1End ], [ line2Begin, line2End ]);
let line1State = getPointLineSegmentState(intersect, [ line1Begin, line1End ]);
let line2State = getPointLineSegmentState(intersect, [ line2Begin, line2End ]);
if (line1State === OUTSIDE || line2State === OUTSIDE) return UNINTERSECT;
if (line1State === TANGENT || line2State === TANGENT) return TANGENT;
return INTERSECT;
}
} | [
"function",
"getLineSegmentsIntersectState",
"(",
"[",
"line1Begin",
",",
"line1End",
"]",
",",
"[",
"line2Begin",
",",
"line2End",
"]",
")",
"{",
"let",
"[",
"x1Begin",
",",
"y1Begin",
"]",
"=",
"line1Begin",
";",
"let",
"[",
"x1End",
",",
"y1End",
"]",
"=",
"line1End",
";",
"let",
"[",
"x2Begin",
",",
"y2Begin",
"]",
"=",
"line2Begin",
";",
"let",
"[",
"x2End",
",",
"y2End",
"]",
"=",
"line2End",
";",
"if",
"(",
"(",
"x1Begin",
"===",
"x1End",
"&&",
"y1Begin",
"===",
"y1End",
")",
"||",
"(",
"x2Begin",
"===",
"x2End",
"&&",
"y2Begin",
"===",
"y2End",
")",
")",
"{",
"throw",
"new",
"XError",
"(",
"XError",
".",
"INVALID_ARGUMENT",
",",
"'start and end point of line must not be the same'",
")",
";",
"}",
"let",
"slope1",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y1Begin",
"-",
"y1End",
")",
"/",
"(",
"x1Begin",
"-",
"x1End",
")",
")",
";",
"let",
"intercept1",
";",
"if",
"(",
"x1Begin",
"===",
"x1End",
")",
"{",
"intercept1",
"=",
"x1Begin",
";",
"}",
"else",
"if",
"(",
"y1Begin",
"===",
"y1End",
")",
"{",
"intercept1",
"=",
"y1Begin",
";",
"}",
"else",
"{",
"intercept1",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y1Begin",
"*",
"x1End",
"-",
"y1End",
"*",
"x1Begin",
")",
"/",
"(",
"x1End",
"-",
"x1Begin",
")",
")",
";",
"}",
"let",
"slope2",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y2Begin",
"-",
"y2End",
")",
"/",
"(",
"x2Begin",
"-",
"x2End",
")",
")",
";",
"let",
"intercept2",
";",
"if",
"(",
"x2Begin",
"===",
"x2End",
")",
"{",
"intercept2",
"=",
"x2Begin",
";",
"}",
"else",
"if",
"(",
"y2Begin",
"===",
"y2End",
")",
"{",
"intercept2",
"=",
"y2Begin",
";",
"}",
"else",
"{",
"intercept2",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"y2Begin",
"*",
"x2End",
"-",
"y2End",
"*",
"x2Begin",
")",
"/",
"(",
"x2End",
"-",
"x2Begin",
")",
")",
";",
"}",
"if",
"(",
"slope1",
"===",
"slope2",
"||",
"(",
"Math",
".",
"abs",
"(",
"slope1",
")",
"===",
"Infinity",
"&&",
"Math",
".",
"abs",
"(",
"slope2",
")",
"===",
"Infinity",
")",
")",
"{",
"if",
"(",
"intercept1",
"!==",
"intercept2",
")",
"{",
"return",
"UNINTERSECT",
";",
"}",
"else",
"if",
"(",
"getPointLineSegmentState",
"(",
"line2Begin",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"!==",
"OUTSIDE",
"&&",
"getPointLineSegmentState",
"(",
"line2End",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"!==",
"OUTSIDE",
")",
"{",
"return",
"INCLUDED",
";",
"}",
"else",
"if",
"(",
"getPointLineSegmentState",
"(",
"line2Begin",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"===",
"OUTSIDE",
"&&",
"getPointLineSegmentState",
"(",
"line2End",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"===",
"OUTSIDE",
")",
"{",
"if",
"(",
"(",
"line2Begin",
"-",
"line1Begin",
")",
"*",
"(",
"line2End",
"-",
"line1Begin",
")",
">",
"0",
")",
"{",
"return",
"UNINTERSECT",
";",
"}",
"else",
"{",
"return",
"OVERLAP",
";",
"}",
"}",
"else",
"if",
"(",
"getPointLineSegmentState",
"(",
"line2Begin",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"===",
"TANGENT",
"||",
"getPointLineSegmentState",
"(",
"line2End",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
"===",
"TANGENT",
")",
"{",
"return",
"TANGENT",
";",
"}",
"else",
"{",
"return",
"OVERLAP",
";",
"}",
"}",
"else",
"{",
"let",
"intersect",
"=",
"getLineIntersect",
"(",
"[",
"line1Begin",
",",
"line1End",
"]",
",",
"[",
"line2Begin",
",",
"line2End",
"]",
")",
";",
"let",
"line1State",
"=",
"getPointLineSegmentState",
"(",
"intersect",
",",
"[",
"line1Begin",
",",
"line1End",
"]",
")",
";",
"let",
"line2State",
"=",
"getPointLineSegmentState",
"(",
"intersect",
",",
"[",
"line2Begin",
",",
"line2End",
"]",
")",
";",
"if",
"(",
"line1State",
"===",
"OUTSIDE",
"||",
"line2State",
"===",
"OUTSIDE",
")",
"return",
"UNINTERSECT",
";",
"if",
"(",
"line1State",
"===",
"TANGENT",
"||",
"line2State",
"===",
"TANGENT",
")",
"return",
"TANGENT",
";",
"return",
"INTERSECT",
";",
"}",
"}"
] | Get the state of line segment line2 relative to line segment line1. Available states are INTERSECT,
UNINTERSECT, INCLUDED, OVERLAP and TANGENT
@getLineSegmentsIntersectState
@param {Number[][]} - coordinates of begin and end of line segment line1
@param {Number[][]} - coordinates of begin and end of line segment line2
@return {String} - return the state. Can only be one of: 'intersect', '~intersect', 'included', 'overlap'
and 'tangent' | [
"Get",
"the",
"state",
"of",
"line",
"segment",
"line2",
"relative",
"to",
"line",
"segment",
"line1",
".",
"Available",
"states",
"are",
"INTERSECT",
"UNINTERSECT",
"INCLUDED",
"OVERLAP",
"and",
"TANGENT"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L181-L239 |
51,840 | zipscene/polytoken | lib/geometry.js | getRandPointInLineSegment | function getRandPointInLineSegment([ [ beginX, beginY ], [ endX, endY ] ]) {
let smallX = beginX <= endX ? beginX : endX;
let largeX = beginX >= endX ? beginX : endX;
let smallY = beginY <= endY ? beginY : endY;
let largeY = beginY >= endY ? beginY : endY;
if (beginY === endY) return [ roundToFiveSignificantDigits(smallX + Math.random() * (largeX - smallX)), beginY ];
if (beginX === endX) return [ beginX, roundToFiveSignificantDigits(smallY + Math.random() * (largeY - smallY)) ];
let slope = roundToFiveSignificantDigits((beginY - endY) / (beginX - endX));
let intercept = roundToFiveSignificantDigits((beginX * endY - endX * beginY) / (beginX - endX));
let randX = roundToFiveSignificantDigits(smallX + Math.random() * (largeX - smallX));
let randY = roundToFiveSignificantDigits(slope * randX + intercept);
return [ randX, randY ];
} | javascript | function getRandPointInLineSegment([ [ beginX, beginY ], [ endX, endY ] ]) {
let smallX = beginX <= endX ? beginX : endX;
let largeX = beginX >= endX ? beginX : endX;
let smallY = beginY <= endY ? beginY : endY;
let largeY = beginY >= endY ? beginY : endY;
if (beginY === endY) return [ roundToFiveSignificantDigits(smallX + Math.random() * (largeX - smallX)), beginY ];
if (beginX === endX) return [ beginX, roundToFiveSignificantDigits(smallY + Math.random() * (largeY - smallY)) ];
let slope = roundToFiveSignificantDigits((beginY - endY) / (beginX - endX));
let intercept = roundToFiveSignificantDigits((beginX * endY - endX * beginY) / (beginX - endX));
let randX = roundToFiveSignificantDigits(smallX + Math.random() * (largeX - smallX));
let randY = roundToFiveSignificantDigits(slope * randX + intercept);
return [ randX, randY ];
} | [
"function",
"getRandPointInLineSegment",
"(",
"[",
"[",
"beginX",
",",
"beginY",
"]",
",",
"[",
"endX",
",",
"endY",
"]",
"]",
")",
"{",
"let",
"smallX",
"=",
"beginX",
"<=",
"endX",
"?",
"beginX",
":",
"endX",
";",
"let",
"largeX",
"=",
"beginX",
">=",
"endX",
"?",
"beginX",
":",
"endX",
";",
"let",
"smallY",
"=",
"beginY",
"<=",
"endY",
"?",
"beginY",
":",
"endY",
";",
"let",
"largeY",
"=",
"beginY",
">=",
"endY",
"?",
"beginY",
":",
"endY",
";",
"if",
"(",
"beginY",
"===",
"endY",
")",
"return",
"[",
"roundToFiveSignificantDigits",
"(",
"smallX",
"+",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"largeX",
"-",
"smallX",
")",
")",
",",
"beginY",
"]",
";",
"if",
"(",
"beginX",
"===",
"endX",
")",
"return",
"[",
"beginX",
",",
"roundToFiveSignificantDigits",
"(",
"smallY",
"+",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"largeY",
"-",
"smallY",
")",
")",
"]",
";",
"let",
"slope",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"beginY",
"-",
"endY",
")",
"/",
"(",
"beginX",
"-",
"endX",
")",
")",
";",
"let",
"intercept",
"=",
"roundToFiveSignificantDigits",
"(",
"(",
"beginX",
"*",
"endY",
"-",
"endX",
"*",
"beginY",
")",
"/",
"(",
"beginX",
"-",
"endX",
")",
")",
";",
"let",
"randX",
"=",
"roundToFiveSignificantDigits",
"(",
"smallX",
"+",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"largeX",
"-",
"smallX",
")",
")",
";",
"let",
"randY",
"=",
"roundToFiveSignificantDigits",
"(",
"slope",
"*",
"randX",
"+",
"intercept",
")",
";",
"return",
"[",
"randX",
",",
"randY",
"]",
";",
"}"
] | Get a random point in given line segment
@method getRandPointInLineSegment
@param {Number[][]} - coordinates of begin and end points of the line segment
@return {Number[]} - coordinates of generated random point | [
"Get",
"a",
"random",
"point",
"in",
"given",
"line",
"segment"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L249-L261 |
51,841 | zipscene/polytoken | lib/geometry.js | getLinearRingsIntersectState | function getLinearRingsIntersectState(linearRing1, linearRing2) {
let isLinearRingsTouching = false;
for (let i = 0; i < linearRing1.length - 1; i++) {
for (let j = 0; j < linearRing2.length - 1; j++) {
let state = getLineSegmentsIntersectState(
[ linearRing2[j], linearRing2[j + 1] ], [ linearRing1[i], linearRing1[i + 1] ]);
// the two linearRings intersect with each other
if (state === INTERSECT) {
return INTERSECT;
}
if (state !== UNINTERSECT) {
isLinearRingsTouching = true;
}
}
}
if (!isLinearRingsTouching) {
let foundOutside = false, foundInside = false;
for (let i = 0; i < linearRing2.length - 1; i++) {
let state = pointLinearRingState(linearRing2[i], linearRing1);
if (state === OUTSIDE) {
foundOutside = true;
} else if (state === INSIDE) {
foundInside = true;
}
if (foundInside && foundOutside) break;
}
if (foundOutside && foundInside) {
return INTERSECT;
} else if (foundInside) {
return INSIDE;
} else {
return OUTSIDE;
}
} else {
let foundOutside = false, foundInside = false;
for (let i = 0; i < linearRing2.length - 1; i++) {
for (let j = 0; j < 250; j++) {
let randPoint = getRandPointInLineSegment([ linearRing2[i], linearRing2[i + 1] ]);
let state = pointLinearRingState(randPoint, linearRing1);
if (state === OUTSIDE) {
foundOutside = true;
} else if (state === INSIDE) {
foundInside = true;
}
if (foundInside && foundInside) break;
}
}
// The two linear rings are identical if all points of three levels are on the edges of linearRing1.
// We mark identical linear ring as INSIDE
if (!foundOutside && !foundInside) return INSIDE;
if (foundOutside && foundInside) return INTERSECT;
if (foundInside) return INSIDE;
return OUTSIDE;
}
} | javascript | function getLinearRingsIntersectState(linearRing1, linearRing2) {
let isLinearRingsTouching = false;
for (let i = 0; i < linearRing1.length - 1; i++) {
for (let j = 0; j < linearRing2.length - 1; j++) {
let state = getLineSegmentsIntersectState(
[ linearRing2[j], linearRing2[j + 1] ], [ linearRing1[i], linearRing1[i + 1] ]);
// the two linearRings intersect with each other
if (state === INTERSECT) {
return INTERSECT;
}
if (state !== UNINTERSECT) {
isLinearRingsTouching = true;
}
}
}
if (!isLinearRingsTouching) {
let foundOutside = false, foundInside = false;
for (let i = 0; i < linearRing2.length - 1; i++) {
let state = pointLinearRingState(linearRing2[i], linearRing1);
if (state === OUTSIDE) {
foundOutside = true;
} else if (state === INSIDE) {
foundInside = true;
}
if (foundInside && foundOutside) break;
}
if (foundOutside && foundInside) {
return INTERSECT;
} else if (foundInside) {
return INSIDE;
} else {
return OUTSIDE;
}
} else {
let foundOutside = false, foundInside = false;
for (let i = 0; i < linearRing2.length - 1; i++) {
for (let j = 0; j < 250; j++) {
let randPoint = getRandPointInLineSegment([ linearRing2[i], linearRing2[i + 1] ]);
let state = pointLinearRingState(randPoint, linearRing1);
if (state === OUTSIDE) {
foundOutside = true;
} else if (state === INSIDE) {
foundInside = true;
}
if (foundInside && foundInside) break;
}
}
// The two linear rings are identical if all points of three levels are on the edges of linearRing1.
// We mark identical linear ring as INSIDE
if (!foundOutside && !foundInside) return INSIDE;
if (foundOutside && foundInside) return INTERSECT;
if (foundInside) return INSIDE;
return OUTSIDE;
}
} | [
"function",
"getLinearRingsIntersectState",
"(",
"linearRing1",
",",
"linearRing2",
")",
"{",
"let",
"isLinearRingsTouching",
"=",
"false",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"linearRing1",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"linearRing2",
".",
"length",
"-",
"1",
";",
"j",
"++",
")",
"{",
"let",
"state",
"=",
"getLineSegmentsIntersectState",
"(",
"[",
"linearRing2",
"[",
"j",
"]",
",",
"linearRing2",
"[",
"j",
"+",
"1",
"]",
"]",
",",
"[",
"linearRing1",
"[",
"i",
"]",
",",
"linearRing1",
"[",
"i",
"+",
"1",
"]",
"]",
")",
";",
"// the two linearRings intersect with each other",
"if",
"(",
"state",
"===",
"INTERSECT",
")",
"{",
"return",
"INTERSECT",
";",
"}",
"if",
"(",
"state",
"!==",
"UNINTERSECT",
")",
"{",
"isLinearRingsTouching",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isLinearRingsTouching",
")",
"{",
"let",
"foundOutside",
"=",
"false",
",",
"foundInside",
"=",
"false",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"linearRing2",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"let",
"state",
"=",
"pointLinearRingState",
"(",
"linearRing2",
"[",
"i",
"]",
",",
"linearRing1",
")",
";",
"if",
"(",
"state",
"===",
"OUTSIDE",
")",
"{",
"foundOutside",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"INSIDE",
")",
"{",
"foundInside",
"=",
"true",
";",
"}",
"if",
"(",
"foundInside",
"&&",
"foundOutside",
")",
"break",
";",
"}",
"if",
"(",
"foundOutside",
"&&",
"foundInside",
")",
"{",
"return",
"INTERSECT",
";",
"}",
"else",
"if",
"(",
"foundInside",
")",
"{",
"return",
"INSIDE",
";",
"}",
"else",
"{",
"return",
"OUTSIDE",
";",
"}",
"}",
"else",
"{",
"let",
"foundOutside",
"=",
"false",
",",
"foundInside",
"=",
"false",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"linearRing2",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"250",
";",
"j",
"++",
")",
"{",
"let",
"randPoint",
"=",
"getRandPointInLineSegment",
"(",
"[",
"linearRing2",
"[",
"i",
"]",
",",
"linearRing2",
"[",
"i",
"+",
"1",
"]",
"]",
")",
";",
"let",
"state",
"=",
"pointLinearRingState",
"(",
"randPoint",
",",
"linearRing1",
")",
";",
"if",
"(",
"state",
"===",
"OUTSIDE",
")",
"{",
"foundOutside",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"INSIDE",
")",
"{",
"foundInside",
"=",
"true",
";",
"}",
"if",
"(",
"foundInside",
"&&",
"foundInside",
")",
"break",
";",
"}",
"}",
"// The two linear rings are identical if all points of three levels are on the edges of linearRing1.",
"// We mark identical linear ring as INSIDE",
"if",
"(",
"!",
"foundOutside",
"&&",
"!",
"foundInside",
")",
"return",
"INSIDE",
";",
"if",
"(",
"foundOutside",
"&&",
"foundInside",
")",
"return",
"INTERSECT",
";",
"if",
"(",
"foundInside",
")",
"return",
"INSIDE",
";",
"return",
"OUTSIDE",
";",
"}",
"}"
] | Get the state of lienarRing2 in relationship to linearRing1
@method getLinearRingsIntersectState
@param {Number[][]} - coordinates of linearRing1
@param {Number\[][]} - coordinates of linearRing2
@return {String} - return the state. It can only be one of: 'intersect', 'outside'
and 'inside' | [
"Get",
"the",
"state",
"of",
"lienarRing2",
"in",
"relationship",
"to",
"linearRing1"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L273-L327 |
51,842 | zipscene/polytoken | lib/geometry.js | getRayLineSegmentIntersectState | function getRayLineSegmentIntersectState([ rayOrigin, rayPoint ], [ lineBegin, lineEnd ]) {
// Find unit deviations for ray and point
let dRay = vectorSubtract(rayPoint, rayOrigin);
let dLine = vectorSubtract(lineEnd, lineBegin);
if (vectorCross(dRay, dLine) === 0) {
if (vectorCross(vectorSubtract(lineBegin, rayOrigin), dRay) === 0) {
// Lines are parallel and collinear
// Find out if any part of the ray intersects with the line segment
let t1 = vectorDot(vectorSubtract(lineEnd, rayOrigin), dRay) / vectorDot(dRay, dRay);
if (t1 >= 0) {
return OVERLAP;
} else {
return UNINTERSECT;
}
} else {
// Lines are parallel and not collinear
return UNINTERSECT;
}
} else {
// Find solution to parametrized line intersect equations
let tRay = vectorCross(vectorSubtract(lineBegin, rayOrigin), dLine) / vectorCross(dRay, dLine);
let tLine = vectorCross(vectorSubtract(rayOrigin, lineBegin), dRay) / vectorCross(dLine, dRay);
if (tRay > 0 && tLine > 0 && tLine < 1) {
return INTERSECT;
} else if (tRay > 0 && (tLine === 0 || tLine === 1)) {
// Intersects at an endpoint of the line
return TANGENT;
} else {
return UNINTERSECT;
}
}
} | javascript | function getRayLineSegmentIntersectState([ rayOrigin, rayPoint ], [ lineBegin, lineEnd ]) {
// Find unit deviations for ray and point
let dRay = vectorSubtract(rayPoint, rayOrigin);
let dLine = vectorSubtract(lineEnd, lineBegin);
if (vectorCross(dRay, dLine) === 0) {
if (vectorCross(vectorSubtract(lineBegin, rayOrigin), dRay) === 0) {
// Lines are parallel and collinear
// Find out if any part of the ray intersects with the line segment
let t1 = vectorDot(vectorSubtract(lineEnd, rayOrigin), dRay) / vectorDot(dRay, dRay);
if (t1 >= 0) {
return OVERLAP;
} else {
return UNINTERSECT;
}
} else {
// Lines are parallel and not collinear
return UNINTERSECT;
}
} else {
// Find solution to parametrized line intersect equations
let tRay = vectorCross(vectorSubtract(lineBegin, rayOrigin), dLine) / vectorCross(dRay, dLine);
let tLine = vectorCross(vectorSubtract(rayOrigin, lineBegin), dRay) / vectorCross(dLine, dRay);
if (tRay > 0 && tLine > 0 && tLine < 1) {
return INTERSECT;
} else if (tRay > 0 && (tLine === 0 || tLine === 1)) {
// Intersects at an endpoint of the line
return TANGENT;
} else {
return UNINTERSECT;
}
}
} | [
"function",
"getRayLineSegmentIntersectState",
"(",
"[",
"rayOrigin",
",",
"rayPoint",
"]",
",",
"[",
"lineBegin",
",",
"lineEnd",
"]",
")",
"{",
"// Find unit deviations for ray and point",
"let",
"dRay",
"=",
"vectorSubtract",
"(",
"rayPoint",
",",
"rayOrigin",
")",
";",
"let",
"dLine",
"=",
"vectorSubtract",
"(",
"lineEnd",
",",
"lineBegin",
")",
";",
"if",
"(",
"vectorCross",
"(",
"dRay",
",",
"dLine",
")",
"===",
"0",
")",
"{",
"if",
"(",
"vectorCross",
"(",
"vectorSubtract",
"(",
"lineBegin",
",",
"rayOrigin",
")",
",",
"dRay",
")",
"===",
"0",
")",
"{",
"// Lines are parallel and collinear",
"// Find out if any part of the ray intersects with the line segment",
"let",
"t1",
"=",
"vectorDot",
"(",
"vectorSubtract",
"(",
"lineEnd",
",",
"rayOrigin",
")",
",",
"dRay",
")",
"/",
"vectorDot",
"(",
"dRay",
",",
"dRay",
")",
";",
"if",
"(",
"t1",
">=",
"0",
")",
"{",
"return",
"OVERLAP",
";",
"}",
"else",
"{",
"return",
"UNINTERSECT",
";",
"}",
"}",
"else",
"{",
"// Lines are parallel and not collinear",
"return",
"UNINTERSECT",
";",
"}",
"}",
"else",
"{",
"// Find solution to parametrized line intersect equations",
"let",
"tRay",
"=",
"vectorCross",
"(",
"vectorSubtract",
"(",
"lineBegin",
",",
"rayOrigin",
")",
",",
"dLine",
")",
"/",
"vectorCross",
"(",
"dRay",
",",
"dLine",
")",
";",
"let",
"tLine",
"=",
"vectorCross",
"(",
"vectorSubtract",
"(",
"rayOrigin",
",",
"lineBegin",
")",
",",
"dRay",
")",
"/",
"vectorCross",
"(",
"dLine",
",",
"dRay",
")",
";",
"if",
"(",
"tRay",
">",
"0",
"&&",
"tLine",
">",
"0",
"&&",
"tLine",
"<",
"1",
")",
"{",
"return",
"INTERSECT",
";",
"}",
"else",
"if",
"(",
"tRay",
">",
"0",
"&&",
"(",
"tLine",
"===",
"0",
"||",
"tLine",
"===",
"1",
")",
")",
"{",
"// Intersects at an endpoint of the line",
"return",
"TANGENT",
";",
"}",
"else",
"{",
"return",
"UNINTERSECT",
";",
"}",
"}",
"}"
] | get the state of ray in relationship to a line segment
@method getRayLineSegmentIntersectState
@param {Number[][]} [ point, point2 ] - `point` is the begin point of the ray. `point2` is a point in ray
@param {Number[][]} [ lineBegin, lineEnd ] - coordinates of begin and end point of line segment
@return {String} - return the state string. Can only be one of: '~intersect', 'intersect', 'overlap' and 'tangent' | [
"get",
"the",
"state",
"of",
"ray",
"in",
"relationship",
"to",
"a",
"line",
"segment"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L338-L370 |
51,843 | zipscene/polytoken | lib/geometry.js | pointLinearRingState | function pointLinearRingState(point, linearRing) {
let { topLeftVertex, width, height } = getBoundingBox(linearRing);
let [ minX, maxY ] = topLeftVertex;
let maxX = minX + width;
let minY = maxY - height;
let [ x, y ] = point;
if (x < minX || x > maxX || y < minY || y > maxY) return OUTSIDE;
for (let i = 0; i < linearRing.length - 1; i++) {
if (isPointInLine(point, [ linearRing[i], linearRing[i + 1] ])) {
if (getPointLineSegmentState(point, [ linearRing[i], linearRing[i + 1] ])) {
return TANGENT;
}
}
}
let numIntersect = 0;
let slope = 0;
let determinedState = false;
while (!determinedState) {
let state;
let intercept = roundToFiveSignificantDigits(point[1] - slope * point[0]);
let point2 = [ roundToFiveSignificantDigits(point[0] + 1),
roundToFiveSignificantDigits(slope * (point[0] + 1) + intercept) ];
for (let i = 0; i < linearRing.length - 1; i++) {
state = getRayLineSegmentIntersectState([ point, point2 ], [ linearRing[i], linearRing[i + 1] ]);
if (state === TANGENT || state === OVERLAP) {
break;
} else if (state === INTERSECT) {
numIntersect++;
}
}
if (state === INTERSECT || state === UNINTERSECT) {
determinedState = true;
} else {
numIntersect = 0;
slope += 0.01;
}
}
return numIntersect % 2 === 1 ? INSIDE : OUTSIDE;
} | javascript | function pointLinearRingState(point, linearRing) {
let { topLeftVertex, width, height } = getBoundingBox(linearRing);
let [ minX, maxY ] = topLeftVertex;
let maxX = minX + width;
let minY = maxY - height;
let [ x, y ] = point;
if (x < minX || x > maxX || y < minY || y > maxY) return OUTSIDE;
for (let i = 0; i < linearRing.length - 1; i++) {
if (isPointInLine(point, [ linearRing[i], linearRing[i + 1] ])) {
if (getPointLineSegmentState(point, [ linearRing[i], linearRing[i + 1] ])) {
return TANGENT;
}
}
}
let numIntersect = 0;
let slope = 0;
let determinedState = false;
while (!determinedState) {
let state;
let intercept = roundToFiveSignificantDigits(point[1] - slope * point[0]);
let point2 = [ roundToFiveSignificantDigits(point[0] + 1),
roundToFiveSignificantDigits(slope * (point[0] + 1) + intercept) ];
for (let i = 0; i < linearRing.length - 1; i++) {
state = getRayLineSegmentIntersectState([ point, point2 ], [ linearRing[i], linearRing[i + 1] ]);
if (state === TANGENT || state === OVERLAP) {
break;
} else if (state === INTERSECT) {
numIntersect++;
}
}
if (state === INTERSECT || state === UNINTERSECT) {
determinedState = true;
} else {
numIntersect = 0;
slope += 0.01;
}
}
return numIntersect % 2 === 1 ? INSIDE : OUTSIDE;
} | [
"function",
"pointLinearRingState",
"(",
"point",
",",
"linearRing",
")",
"{",
"let",
"{",
"topLeftVertex",
",",
"width",
",",
"height",
"}",
"=",
"getBoundingBox",
"(",
"linearRing",
")",
";",
"let",
"[",
"minX",
",",
"maxY",
"]",
"=",
"topLeftVertex",
";",
"let",
"maxX",
"=",
"minX",
"+",
"width",
";",
"let",
"minY",
"=",
"maxY",
"-",
"height",
";",
"let",
"[",
"x",
",",
"y",
"]",
"=",
"point",
";",
"if",
"(",
"x",
"<",
"minX",
"||",
"x",
">",
"maxX",
"||",
"y",
"<",
"minY",
"||",
"y",
">",
"maxY",
")",
"return",
"OUTSIDE",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"linearRing",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"if",
"(",
"isPointInLine",
"(",
"point",
",",
"[",
"linearRing",
"[",
"i",
"]",
",",
"linearRing",
"[",
"i",
"+",
"1",
"]",
"]",
")",
")",
"{",
"if",
"(",
"getPointLineSegmentState",
"(",
"point",
",",
"[",
"linearRing",
"[",
"i",
"]",
",",
"linearRing",
"[",
"i",
"+",
"1",
"]",
"]",
")",
")",
"{",
"return",
"TANGENT",
";",
"}",
"}",
"}",
"let",
"numIntersect",
"=",
"0",
";",
"let",
"slope",
"=",
"0",
";",
"let",
"determinedState",
"=",
"false",
";",
"while",
"(",
"!",
"determinedState",
")",
"{",
"let",
"state",
";",
"let",
"intercept",
"=",
"roundToFiveSignificantDigits",
"(",
"point",
"[",
"1",
"]",
"-",
"slope",
"*",
"point",
"[",
"0",
"]",
")",
";",
"let",
"point2",
"=",
"[",
"roundToFiveSignificantDigits",
"(",
"point",
"[",
"0",
"]",
"+",
"1",
")",
",",
"roundToFiveSignificantDigits",
"(",
"slope",
"*",
"(",
"point",
"[",
"0",
"]",
"+",
"1",
")",
"+",
"intercept",
")",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"linearRing",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"state",
"=",
"getRayLineSegmentIntersectState",
"(",
"[",
"point",
",",
"point2",
"]",
",",
"[",
"linearRing",
"[",
"i",
"]",
",",
"linearRing",
"[",
"i",
"+",
"1",
"]",
"]",
")",
";",
"if",
"(",
"state",
"===",
"TANGENT",
"||",
"state",
"===",
"OVERLAP",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"INTERSECT",
")",
"{",
"numIntersect",
"++",
";",
"}",
"}",
"if",
"(",
"state",
"===",
"INTERSECT",
"||",
"state",
"===",
"UNINTERSECT",
")",
"{",
"determinedState",
"=",
"true",
";",
"}",
"else",
"{",
"numIntersect",
"=",
"0",
";",
"slope",
"+=",
"0.01",
";",
"}",
"}",
"return",
"numIntersect",
"%",
"2",
"===",
"1",
"?",
"INSIDE",
":",
"OUTSIDE",
";",
"}"
] | Get the state of point in relationship to a linear ring
@method pointLinearRingState
@param {Number[]} point - coordinates of the point
@param {Number[][]} - linearRing - coordinates of vertexes of the linear ring
@return {String} - return the state. Can only be one of: 'outside', 'inside'
and 'tangent' | [
"Get",
"the",
"state",
"of",
"point",
"in",
"relationship",
"to",
"a",
"linear",
"ring"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L382-L420 |
51,844 | zipscene/polytoken | lib/geometry.js | getBoundingBox | function getBoundingBox(linearRing) {
if (!Array.isArray(linearRing)) {
throw new XError(XError.INVALID_ARGUMENT, 'linearRing must be an array');
}
let leftX = Infinity;
let rightX = -Infinity;
let bottomY = Infinity;
let topY = -Infinity;
for (let point of linearRing) {
if (!Array.isArray(point) || point.length !== 2 || point.some((coord) => typeof coord !== 'number')) {
throw new XError(XError.INVALID_ARGUMENT, 'invalid point in linear ring');
}
let [ x, y ] = point;
if (x < leftX) leftX = x;
if (x > rightX) rightX = x;
if (y < bottomY) bottomY = y;
if (y > topY) topY = y;
}
return {
topLeftVertex: [ leftX, topY ],
width: rightX - leftX,
height: topY - bottomY
};
} | javascript | function getBoundingBox(linearRing) {
if (!Array.isArray(linearRing)) {
throw new XError(XError.INVALID_ARGUMENT, 'linearRing must be an array');
}
let leftX = Infinity;
let rightX = -Infinity;
let bottomY = Infinity;
let topY = -Infinity;
for (let point of linearRing) {
if (!Array.isArray(point) || point.length !== 2 || point.some((coord) => typeof coord !== 'number')) {
throw new XError(XError.INVALID_ARGUMENT, 'invalid point in linear ring');
}
let [ x, y ] = point;
if (x < leftX) leftX = x;
if (x > rightX) rightX = x;
if (y < bottomY) bottomY = y;
if (y > topY) topY = y;
}
return {
topLeftVertex: [ leftX, topY ],
width: rightX - leftX,
height: topY - bottomY
};
} | [
"function",
"getBoundingBox",
"(",
"linearRing",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"linearRing",
")",
")",
"{",
"throw",
"new",
"XError",
"(",
"XError",
".",
"INVALID_ARGUMENT",
",",
"'linearRing must be an array'",
")",
";",
"}",
"let",
"leftX",
"=",
"Infinity",
";",
"let",
"rightX",
"=",
"-",
"Infinity",
";",
"let",
"bottomY",
"=",
"Infinity",
";",
"let",
"topY",
"=",
"-",
"Infinity",
";",
"for",
"(",
"let",
"point",
"of",
"linearRing",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"point",
")",
"||",
"point",
".",
"length",
"!==",
"2",
"||",
"point",
".",
"some",
"(",
"(",
"coord",
")",
"=>",
"typeof",
"coord",
"!==",
"'number'",
")",
")",
"{",
"throw",
"new",
"XError",
"(",
"XError",
".",
"INVALID_ARGUMENT",
",",
"'invalid point in linear ring'",
")",
";",
"}",
"let",
"[",
"x",
",",
"y",
"]",
"=",
"point",
";",
"if",
"(",
"x",
"<",
"leftX",
")",
"leftX",
"=",
"x",
";",
"if",
"(",
"x",
">",
"rightX",
")",
"rightX",
"=",
"x",
";",
"if",
"(",
"y",
"<",
"bottomY",
")",
"bottomY",
"=",
"y",
";",
"if",
"(",
"y",
">",
"topY",
")",
"topY",
"=",
"y",
";",
"}",
"return",
"{",
"topLeftVertex",
":",
"[",
"leftX",
",",
"topY",
"]",
",",
"width",
":",
"rightX",
"-",
"leftX",
",",
"height",
":",
"topY",
"-",
"bottomY",
"}",
";",
"}"
] | Get the bounding box of given linear ring
@method getBoundingBox
@param {Number[][]} linearRing - coordinates of vertexes of the linear ring
@return {Object} - return an object like this: { topLeftVertex: [ 2, 3 ], width: 1, height: 2 },
where `topLeftVertex` is the top left vertex of the bounding box | [
"Get",
"the",
"bounding",
"box",
"of",
"given",
"linear",
"ring"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L431-L455 |
51,845 | zipscene/polytoken | lib/geometry.js | squareLinearRingIntersectState | function squareLinearRingIntersectState(linearRing, topLeftVertex, squareSize) {
let [ topLeftX, topLeftY ] = topLeftVertex;
let topRightVertex = [ topLeftX + squareSize, topLeftY ];
let bottomRightVertex = [ topLeftX + squareSize, topLeftY - squareSize ];
let bottomLeftVertex = [ topLeftX, topLeftY - squareSize ];
let squareLinearRing = [ topLeftVertex, topRightVertex, bottomRightVertex, bottomLeftVertex, topLeftVertex ];
return getLinearRingsIntersectState(linearRing, squareLinearRing);
} | javascript | function squareLinearRingIntersectState(linearRing, topLeftVertex, squareSize) {
let [ topLeftX, topLeftY ] = topLeftVertex;
let topRightVertex = [ topLeftX + squareSize, topLeftY ];
let bottomRightVertex = [ topLeftX + squareSize, topLeftY - squareSize ];
let bottomLeftVertex = [ topLeftX, topLeftY - squareSize ];
let squareLinearRing = [ topLeftVertex, topRightVertex, bottomRightVertex, bottomLeftVertex, topLeftVertex ];
return getLinearRingsIntersectState(linearRing, squareLinearRing);
} | [
"function",
"squareLinearRingIntersectState",
"(",
"linearRing",
",",
"topLeftVertex",
",",
"squareSize",
")",
"{",
"let",
"[",
"topLeftX",
",",
"topLeftY",
"]",
"=",
"topLeftVertex",
";",
"let",
"topRightVertex",
"=",
"[",
"topLeftX",
"+",
"squareSize",
",",
"topLeftY",
"]",
";",
"let",
"bottomRightVertex",
"=",
"[",
"topLeftX",
"+",
"squareSize",
",",
"topLeftY",
"-",
"squareSize",
"]",
";",
"let",
"bottomLeftVertex",
"=",
"[",
"topLeftX",
",",
"topLeftY",
"-",
"squareSize",
"]",
";",
"let",
"squareLinearRing",
"=",
"[",
"topLeftVertex",
",",
"topRightVertex",
",",
"bottomRightVertex",
",",
"bottomLeftVertex",
",",
"topLeftVertex",
"]",
";",
"return",
"getLinearRingsIntersectState",
"(",
"linearRing",
",",
"squareLinearRing",
")",
";",
"}"
] | Get the state of a square linear ring in relationship to another linear ring
@method squareLinearRingIntersectState
@param {Numner[][]} linearRing - coordinates of the linear ring
@param {Number[]} topLeftVertex - coordinates of the top left vertx of the square
@param {Number} squareSize - size of edge of the square
@return {String} - return the state. it should share the same set of values with the
the return value of `getLinearRingsIntersectState` | [
"Get",
"the",
"state",
"of",
"a",
"square",
"linear",
"ring",
"in",
"relationship",
"to",
"another",
"linear",
"ring"
] | e2cab71d0c3cdec6ff702b7bb434b585ba13efe0 | https://github.com/zipscene/polytoken/blob/e2cab71d0c3cdec6ff702b7bb434b585ba13efe0/lib/geometry.js#L468-L475 |
51,846 | defeo/was_framework | demo/static/update_user.js | ajax_return | function ajax_return(data, status, xhr) {
// If the update was successfull
if (data.ok) {
// Forget old value
this.removeData('old-value');
// Add a green V to the right
this.parent().next()
.off('click')
.html('V')
.css('color', 'LimeGreen')
.attr('title', 'Update OK');
// If we modified the id
if (this.attr('id') == 'id') {
var url = '/user?id=' + encodeURIComponent(this.val());
// update the link in the header...
$('#user-link')
.text(this.val())
.attr('href', url);
// ...and the url in the adress bar
history.pushState(null, null, url);
}
} else {
// Add a red X to the right
var elem = this;
elem.parent().next()
.html('X')
.css('color', 'red')
.attr('title', data.message)
.one('click', function() { // if the X is clicked, restore original data
elem.val(elem.data('old-value'));
$(this)
.empty()
.removeAttr('title');
});
}
// reactivate the control
this.prop('disabled', false);
} | javascript | function ajax_return(data, status, xhr) {
// If the update was successfull
if (data.ok) {
// Forget old value
this.removeData('old-value');
// Add a green V to the right
this.parent().next()
.off('click')
.html('V')
.css('color', 'LimeGreen')
.attr('title', 'Update OK');
// If we modified the id
if (this.attr('id') == 'id') {
var url = '/user?id=' + encodeURIComponent(this.val());
// update the link in the header...
$('#user-link')
.text(this.val())
.attr('href', url);
// ...and the url in the adress bar
history.pushState(null, null, url);
}
} else {
// Add a red X to the right
var elem = this;
elem.parent().next()
.html('X')
.css('color', 'red')
.attr('title', data.message)
.one('click', function() { // if the X is clicked, restore original data
elem.val(elem.data('old-value'));
$(this)
.empty()
.removeAttr('title');
});
}
// reactivate the control
this.prop('disabled', false);
} | [
"function",
"ajax_return",
"(",
"data",
",",
"status",
",",
"xhr",
")",
"{",
"// If the update was successfull",
"if",
"(",
"data",
".",
"ok",
")",
"{",
"// Forget old value",
"this",
".",
"removeData",
"(",
"'old-value'",
")",
";",
"// Add a green V to the right",
"this",
".",
"parent",
"(",
")",
".",
"next",
"(",
")",
".",
"off",
"(",
"'click'",
")",
".",
"html",
"(",
"'V'",
")",
".",
"css",
"(",
"'color'",
",",
"'LimeGreen'",
")",
".",
"attr",
"(",
"'title'",
",",
"'Update OK'",
")",
";",
"// If we modified the id",
"if",
"(",
"this",
".",
"attr",
"(",
"'id'",
")",
"==",
"'id'",
")",
"{",
"var",
"url",
"=",
"'/user?id='",
"+",
"encodeURIComponent",
"(",
"this",
".",
"val",
"(",
")",
")",
";",
"// update the link in the header...",
"$",
"(",
"'#user-link'",
")",
".",
"text",
"(",
"this",
".",
"val",
"(",
")",
")",
".",
"attr",
"(",
"'href'",
",",
"url",
")",
";",
"// ...and the url in the adress bar",
"history",
".",
"pushState",
"(",
"null",
",",
"null",
",",
"url",
")",
";",
"}",
"}",
"else",
"{",
"// Add a red X to the right",
"var",
"elem",
"=",
"this",
";",
"elem",
".",
"parent",
"(",
")",
".",
"next",
"(",
")",
".",
"html",
"(",
"'X'",
")",
".",
"css",
"(",
"'color'",
",",
"'red'",
")",
".",
"attr",
"(",
"'title'",
",",
"data",
".",
"message",
")",
".",
"one",
"(",
"'click'",
",",
"function",
"(",
")",
"{",
"// if the X is clicked, restore original data",
"elem",
".",
"val",
"(",
"elem",
".",
"data",
"(",
"'old-value'",
")",
")",
";",
"$",
"(",
"this",
")",
".",
"empty",
"(",
")",
".",
"removeAttr",
"(",
"'title'",
")",
";",
"}",
")",
";",
"}",
"// reactivate the control",
"this",
".",
"prop",
"(",
"'disabled'",
",",
"false",
")",
";",
"}"
] | This function is called when the AJAX request returns | [
"This",
"function",
"is",
"called",
"when",
"the",
"AJAX",
"request",
"returns"
] | ab52bbbf5943e9062fe6ea82f1fea637a11d727a | https://github.com/defeo/was_framework/blob/ab52bbbf5943e9062fe6ea82f1fea637a11d727a/demo/static/update_user.js#L63-L101 |
51,847 | feedhenry/fh-mbaas-middleware | lib/models.js | init | function init(config, cb) {
connection = mongoose.createConnection(config.mongoUrl);
var firstCallback = true;
connection.on('error', function(err) {
log.logger.error('Mongo error: ' + util.inspect(err));
if (firstCallback) {
firstCallback = false;
return cb(err);
} else {
log.logger.error('Mongo error: ' + util.inspect(err));
return cb(err);
}
});
connection.once('open', function callback() {
if (firstCallback) {
log.logger.debug('Mongoose connected.');
firstCallback = false;
return cb(null,connection);
}
else {
return cb();
}
});
connection.on('disconnected', function() {
log.logger.debug('Mongoose event - disconnect');
});
// Load schemas
models.Mbaas = connection.model('Mbaas', require('./models/mbaas.js'));
models.AppMbaas = connection.model('AppMbaas', require('./models/appMbaas.js'));
models.Event = connection.model('Events', require('./models/events.js').EventSchema);
models.Alert = connection.model('Alerts', require('./models/alerts.js').AlertSchema);
models.Notification = connection.model("Notification",require('./models/notifications').NotificationSchema);
models.Crash = connection.model("Crash",require('./models/crash').CrashSchema);
} | javascript | function init(config, cb) {
connection = mongoose.createConnection(config.mongoUrl);
var firstCallback = true;
connection.on('error', function(err) {
log.logger.error('Mongo error: ' + util.inspect(err));
if (firstCallback) {
firstCallback = false;
return cb(err);
} else {
log.logger.error('Mongo error: ' + util.inspect(err));
return cb(err);
}
});
connection.once('open', function callback() {
if (firstCallback) {
log.logger.debug('Mongoose connected.');
firstCallback = false;
return cb(null,connection);
}
else {
return cb();
}
});
connection.on('disconnected', function() {
log.logger.debug('Mongoose event - disconnect');
});
// Load schemas
models.Mbaas = connection.model('Mbaas', require('./models/mbaas.js'));
models.AppMbaas = connection.model('AppMbaas', require('./models/appMbaas.js'));
models.Event = connection.model('Events', require('./models/events.js').EventSchema);
models.Alert = connection.model('Alerts', require('./models/alerts.js').AlertSchema);
models.Notification = connection.model("Notification",require('./models/notifications').NotificationSchema);
models.Crash = connection.model("Crash",require('./models/crash').CrashSchema);
} | [
"function",
"init",
"(",
"config",
",",
"cb",
")",
"{",
"connection",
"=",
"mongoose",
".",
"createConnection",
"(",
"config",
".",
"mongoUrl",
")",
";",
"var",
"firstCallback",
"=",
"true",
";",
"connection",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"'Mongo error: '",
"+",
"util",
".",
"inspect",
"(",
"err",
")",
")",
";",
"if",
"(",
"firstCallback",
")",
"{",
"firstCallback",
"=",
"false",
";",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"else",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"'Mongo error: '",
"+",
"util",
".",
"inspect",
"(",
"err",
")",
")",
";",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"connection",
".",
"once",
"(",
"'open'",
",",
"function",
"callback",
"(",
")",
"{",
"if",
"(",
"firstCallback",
")",
"{",
"log",
".",
"logger",
".",
"debug",
"(",
"'Mongoose connected.'",
")",
";",
"firstCallback",
"=",
"false",
";",
"return",
"cb",
"(",
"null",
",",
"connection",
")",
";",
"}",
"else",
"{",
"return",
"cb",
"(",
")",
";",
"}",
"}",
")",
";",
"connection",
".",
"on",
"(",
"'disconnected'",
",",
"function",
"(",
")",
"{",
"log",
".",
"logger",
".",
"debug",
"(",
"'Mongoose event - disconnect'",
")",
";",
"}",
")",
";",
"// Load schemas",
"models",
".",
"Mbaas",
"=",
"connection",
".",
"model",
"(",
"'Mbaas'",
",",
"require",
"(",
"'./models/mbaas.js'",
")",
")",
";",
"models",
".",
"AppMbaas",
"=",
"connection",
".",
"model",
"(",
"'AppMbaas'",
",",
"require",
"(",
"'./models/appMbaas.js'",
")",
")",
";",
"models",
".",
"Event",
"=",
"connection",
".",
"model",
"(",
"'Events'",
",",
"require",
"(",
"'./models/events.js'",
")",
".",
"EventSchema",
")",
";",
"models",
".",
"Alert",
"=",
"connection",
".",
"model",
"(",
"'Alerts'",
",",
"require",
"(",
"'./models/alerts.js'",
")",
".",
"AlertSchema",
")",
";",
"models",
".",
"Notification",
"=",
"connection",
".",
"model",
"(",
"\"Notification\"",
",",
"require",
"(",
"'./models/notifications'",
")",
".",
"NotificationSchema",
")",
";",
"models",
".",
"Crash",
"=",
"connection",
".",
"model",
"(",
"\"Crash\"",
",",
"require",
"(",
"'./models/crash'",
")",
".",
"CrashSchema",
")",
";",
"}"
] | init our Mongo database | [
"init",
"our",
"Mongo",
"database"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/models.js#L9-L47 |
51,848 | feedhenry/fh-mbaas-middleware | lib/models.js | disconnect | function disconnect(cb) {
if (connection) {
log.logger.debug('Mongoose disconnected');
connection.close(cb);
} else {
cb();
}
} | javascript | function disconnect(cb) {
if (connection) {
log.logger.debug('Mongoose disconnected');
connection.close(cb);
} else {
cb();
}
} | [
"function",
"disconnect",
"(",
"cb",
")",
"{",
"if",
"(",
"connection",
")",
"{",
"log",
".",
"logger",
".",
"debug",
"(",
"'Mongoose disconnected'",
")",
";",
"connection",
".",
"close",
"(",
"cb",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}"
] | Close all db handles, etc | [
"Close",
"all",
"db",
"handles",
"etc"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/models.js#L50-L57 |
51,849 | andrewscwei/requiem | src/dom/removeFromChildRegistry.js | removeFromChildRegistry | function removeFromChildRegistry(childRegistry, child) {
assertType(childRegistry, 'object', false, 'Invalid child registry specified');
assertType(child, [Node, Array, 'string'], false, 'Invalid child(ren) or name specified');
if (typeof child === 'string') {
let targets = child.split('.');
let currentTarget = targets.shift();
let c = childRegistry[currentTarget];
if (targets.length > 0) {
if (c instanceof Array) {
let n = c.length;
for (let i = 0; i < n; i++)
removeFromChildRegistry(getChildRegistry(c[i]), targets);
}
else {
removeFromChildRegistry(getChildRegistry(c), targets);
}
}
else {
delete childRegistry[currentTarget];
}
}
else {
for (let key in childRegistry) {
let value = childRegistry[key];
if (value instanceof Array) {
let n = value.length;
let t = -1;
for (let i = 0; i < n; i++) {
let e = value[i];
if (e === child) {
t = i;
break;
}
}
if (~t) value.splice(t, 1);
if (value.length === 0) delete childRegistry[key];
}
else {
if (value === child) {
delete childRegistry[key];
}
else {
removeFromChildRegistry(getChildRegistry(child), value);
}
}
}
}
} | javascript | function removeFromChildRegistry(childRegistry, child) {
assertType(childRegistry, 'object', false, 'Invalid child registry specified');
assertType(child, [Node, Array, 'string'], false, 'Invalid child(ren) or name specified');
if (typeof child === 'string') {
let targets = child.split('.');
let currentTarget = targets.shift();
let c = childRegistry[currentTarget];
if (targets.length > 0) {
if (c instanceof Array) {
let n = c.length;
for (let i = 0; i < n; i++)
removeFromChildRegistry(getChildRegistry(c[i]), targets);
}
else {
removeFromChildRegistry(getChildRegistry(c), targets);
}
}
else {
delete childRegistry[currentTarget];
}
}
else {
for (let key in childRegistry) {
let value = childRegistry[key];
if (value instanceof Array) {
let n = value.length;
let t = -1;
for (let i = 0; i < n; i++) {
let e = value[i];
if (e === child) {
t = i;
break;
}
}
if (~t) value.splice(t, 1);
if (value.length === 0) delete childRegistry[key];
}
else {
if (value === child) {
delete childRegistry[key];
}
else {
removeFromChildRegistry(getChildRegistry(child), value);
}
}
}
}
} | [
"function",
"removeFromChildRegistry",
"(",
"childRegistry",
",",
"child",
")",
"{",
"assertType",
"(",
"childRegistry",
",",
"'object'",
",",
"false",
",",
"'Invalid child registry specified'",
")",
";",
"assertType",
"(",
"child",
",",
"[",
"Node",
",",
"Array",
",",
"'string'",
"]",
",",
"false",
",",
"'Invalid child(ren) or name specified'",
")",
";",
"if",
"(",
"typeof",
"child",
"===",
"'string'",
")",
"{",
"let",
"targets",
"=",
"child",
".",
"split",
"(",
"'.'",
")",
";",
"let",
"currentTarget",
"=",
"targets",
".",
"shift",
"(",
")",
";",
"let",
"c",
"=",
"childRegistry",
"[",
"currentTarget",
"]",
";",
"if",
"(",
"targets",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"c",
"instanceof",
"Array",
")",
"{",
"let",
"n",
"=",
"c",
".",
"length",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"removeFromChildRegistry",
"(",
"getChildRegistry",
"(",
"c",
"[",
"i",
"]",
")",
",",
"targets",
")",
";",
"}",
"else",
"{",
"removeFromChildRegistry",
"(",
"getChildRegistry",
"(",
"c",
")",
",",
"targets",
")",
";",
"}",
"}",
"else",
"{",
"delete",
"childRegistry",
"[",
"currentTarget",
"]",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"let",
"key",
"in",
"childRegistry",
")",
"{",
"let",
"value",
"=",
"childRegistry",
"[",
"key",
"]",
";",
"if",
"(",
"value",
"instanceof",
"Array",
")",
"{",
"let",
"n",
"=",
"value",
".",
"length",
";",
"let",
"t",
"=",
"-",
"1",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"let",
"e",
"=",
"value",
"[",
"i",
"]",
";",
"if",
"(",
"e",
"===",
"child",
")",
"{",
"t",
"=",
"i",
";",
"break",
";",
"}",
"}",
"if",
"(",
"~",
"t",
")",
"value",
".",
"splice",
"(",
"t",
",",
"1",
")",
";",
"if",
"(",
"value",
".",
"length",
"===",
"0",
")",
"delete",
"childRegistry",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"value",
"===",
"child",
")",
"{",
"delete",
"childRegistry",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"removeFromChildRegistry",
"(",
"getChildRegistry",
"(",
"child",
")",
",",
"value",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Removes a child or an array of children with the same name from the specified
child registry.
@param {Object} childRegistry - The child registry.
@param {Node|Array|string} child - Either one child element or an array of
multiple child elements with the same name
or the name in dot notation.
@alias module:requiem~dom.removeFromChildRegistry | [
"Removes",
"a",
"child",
"or",
"an",
"array",
"of",
"children",
"with",
"the",
"same",
"name",
"from",
"the",
"specified",
"child",
"registry",
"."
] | c4182bfffc9841c6de5718f689ad3c2060511777 | https://github.com/andrewscwei/requiem/blob/c4182bfffc9841c6de5718f689ad3c2060511777/src/dom/removeFromChildRegistry.js#L19-L71 |
51,850 | matter-in-motion/mm-http | http.js | function(path, contract) {
if (!contract) {
contract = path;
path = '/';
}
if (contract.handle) {
this.root.use(path, (req, res, next) => {
contract.handle(req, res, next)
});
} else {
this.root.use(path, contract);
}
return this;
} | javascript | function(path, contract) {
if (!contract) {
contract = path;
path = '/';
}
if (contract.handle) {
this.root.use(path, (req, res, next) => {
contract.handle(req, res, next)
});
} else {
this.root.use(path, contract);
}
return this;
} | [
"function",
"(",
"path",
",",
"contract",
")",
"{",
"if",
"(",
"!",
"contract",
")",
"{",
"contract",
"=",
"path",
";",
"path",
"=",
"'/'",
";",
"}",
"if",
"(",
"contract",
".",
"handle",
")",
"{",
"this",
".",
"root",
".",
"use",
"(",
"path",
",",
"(",
"req",
",",
"res",
",",
"next",
")",
"=>",
"{",
"contract",
".",
"handle",
"(",
"req",
",",
"res",
",",
"next",
")",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"root",
".",
"use",
"(",
"path",
",",
"contract",
")",
";",
"}",
"return",
"this",
";",
"}"
] | use function will be added as the app use method | [
"use",
"function",
"will",
"be",
"added",
"as",
"the",
"app",
"use",
"method"
] | 0947bf7f6a5fa794a0d13d97d7162feaae895291 | https://github.com/matter-in-motion/mm-http/blob/0947bf7f6a5fa794a0d13d97d7162feaae895291/http.js#L19-L33 |
|
51,851 | Becklyn/becklyn-gulp | tasks/js_bundle.js | logJsHintWarning | function logJsHintWarning (errors)
{
totalIssues += errors.length;
var sourceFile = pathHelper.makeRelative(this.resourcePath);
gulpUtil.log(gulpUtil.colors.yellow("jshint warning") + " in " + sourceFile);
for (var i = 0, l = errors.length; i < l; i++)
{
var error = errors[i];
gulpUtil.log(
" in " +
gulpUtil.colors.blue("line " + error.line + " @ char " + error.character) +
": " +
error.reason +
" (" + error.code + ")"
);
if (typeof error.evidence === "string")
{
gulpUtil.log(
" " +
gulpUtil.colors.gray(error.evidence.replace(/^\s*|\s*$/, ""))
);
}
gulpUtil.log("");
}
} | javascript | function logJsHintWarning (errors)
{
totalIssues += errors.length;
var sourceFile = pathHelper.makeRelative(this.resourcePath);
gulpUtil.log(gulpUtil.colors.yellow("jshint warning") + " in " + sourceFile);
for (var i = 0, l = errors.length; i < l; i++)
{
var error = errors[i];
gulpUtil.log(
" in " +
gulpUtil.colors.blue("line " + error.line + " @ char " + error.character) +
": " +
error.reason +
" (" + error.code + ")"
);
if (typeof error.evidence === "string")
{
gulpUtil.log(
" " +
gulpUtil.colors.gray(error.evidence.replace(/^\s*|\s*$/, ""))
);
}
gulpUtil.log("");
}
} | [
"function",
"logJsHintWarning",
"(",
"errors",
")",
"{",
"totalIssues",
"+=",
"errors",
".",
"length",
";",
"var",
"sourceFile",
"=",
"pathHelper",
".",
"makeRelative",
"(",
"this",
".",
"resourcePath",
")",
";",
"gulpUtil",
".",
"log",
"(",
"gulpUtil",
".",
"colors",
".",
"yellow",
"(",
"\"jshint warning\"",
")",
"+",
"\" in \"",
"+",
"sourceFile",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"errors",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"var",
"error",
"=",
"errors",
"[",
"i",
"]",
";",
"gulpUtil",
".",
"log",
"(",
"\" in \"",
"+",
"gulpUtil",
".",
"colors",
".",
"blue",
"(",
"\"line \"",
"+",
"error",
".",
"line",
"+",
"\" @ char \"",
"+",
"error",
".",
"character",
")",
"+",
"\": \"",
"+",
"error",
".",
"reason",
"+",
"\" (\"",
"+",
"error",
".",
"code",
"+",
"\")\"",
")",
";",
"if",
"(",
"typeof",
"error",
".",
"evidence",
"===",
"\"string\"",
")",
"{",
"gulpUtil",
".",
"log",
"(",
"\" \"",
"+",
"gulpUtil",
".",
"colors",
".",
"gray",
"(",
"error",
".",
"evidence",
".",
"replace",
"(",
"/",
"^\\s*|\\s*$",
"/",
",",
"\"\"",
")",
")",
")",
";",
"}",
"gulpUtil",
".",
"log",
"(",
"\"\"",
")",
";",
"}",
"}"
] | Logs jsHint warnings to the console
@param {Array.<{
raw: string,
code: string,
evidence: string,
line: number,
character: number,
scope: string,
reason: string
}>} errors | [
"Logs",
"jsHint",
"warnings",
"to",
"the",
"console"
] | 1c633378d561f07101f9db19ccd153617b8e0252 | https://github.com/Becklyn/becklyn-gulp/blob/1c633378d561f07101f9db19ccd153617b8e0252/tasks/js_bundle.js#L39-L68 |
51,852 | Becklyn/becklyn-gulp | tasks/js_bundle.js | reportTotalIssueCount | function reportTotalIssueCount ()
{
var outputColor = gulpUtil.colors.green;
if (totalIssues > 0)
{
outputColor = gulpUtil.colors.red;
}
gulpUtil.log(gulpUtil.colors.yellow('»»'), 'Total JS issues:', outputColor(totalIssues));
// Reset the issue count so we don't increment it every time a file has been modified while it is being watched
totalIssues = 0;
} | javascript | function reportTotalIssueCount ()
{
var outputColor = gulpUtil.colors.green;
if (totalIssues > 0)
{
outputColor = gulpUtil.colors.red;
}
gulpUtil.log(gulpUtil.colors.yellow('»»'), 'Total JS issues:', outputColor(totalIssues));
// Reset the issue count so we don't increment it every time a file has been modified while it is being watched
totalIssues = 0;
} | [
"function",
"reportTotalIssueCount",
"(",
")",
"{",
"var",
"outputColor",
"=",
"gulpUtil",
".",
"colors",
".",
"green",
";",
"if",
"(",
"totalIssues",
">",
"0",
")",
"{",
"outputColor",
"=",
"gulpUtil",
".",
"colors",
".",
"red",
";",
"}",
"gulpUtil",
".",
"log",
"(",
"gulpUtil",
".",
"colors",
".",
"yellow",
"(",
"'»»'),",
" ",
"'",
"otal JS issues:', ",
"o",
"tputColor(t",
"o",
"talIssues))",
";",
"",
"",
"// Reset the issue count so we don't increment it every time a file has been modified while it is being watched",
"totalIssues",
"=",
"0",
";",
"}"
] | Reports the total amount of JavaScript issues detected by JsHint | [
"Reports",
"the",
"total",
"amount",
"of",
"JavaScript",
"issues",
"detected",
"by",
"JsHint"
] | 1c633378d561f07101f9db19ccd153617b8e0252 | https://github.com/Becklyn/becklyn-gulp/blob/1c633378d561f07101f9db19ccd153617b8e0252/tasks/js_bundle.js#L74-L86 |
51,853 | JustZisGuy/wildling | src/token.js | getTokenParameters | function getTokenParameters(index) {
let stringLength;
let indexWithOffset;
indexWithOffset = index;
for (stringLength = startLength; stringLength <= endLength; stringLength += 1) {
const offsetCount = variants.length ** stringLength;
if (indexWithOffset < offsetCount) {
break;
} else {
indexWithOffset -= offsetCount;
}
}
return {
indexWithOffset,
stringLength,
};
} | javascript | function getTokenParameters(index) {
let stringLength;
let indexWithOffset;
indexWithOffset = index;
for (stringLength = startLength; stringLength <= endLength; stringLength += 1) {
const offsetCount = variants.length ** stringLength;
if (indexWithOffset < offsetCount) {
break;
} else {
indexWithOffset -= offsetCount;
}
}
return {
indexWithOffset,
stringLength,
};
} | [
"function",
"getTokenParameters",
"(",
"index",
")",
"{",
"let",
"stringLength",
";",
"let",
"indexWithOffset",
";",
"indexWithOffset",
"=",
"index",
";",
"for",
"(",
"stringLength",
"=",
"startLength",
";",
"stringLength",
"<=",
"endLength",
";",
"stringLength",
"+=",
"1",
")",
"{",
"const",
"offsetCount",
"=",
"variants",
".",
"length",
"**",
"stringLength",
";",
"if",
"(",
"indexWithOffset",
"<",
"offsetCount",
")",
"{",
"break",
";",
"}",
"else",
"{",
"indexWithOffset",
"-=",
"offsetCount",
";",
"}",
"}",
"return",
"{",
"indexWithOffset",
",",
"stringLength",
",",
"}",
";",
"}"
] | calculate length of target combination and index for that particular length | [
"calculate",
"length",
"of",
"target",
"combination",
"and",
"index",
"for",
"that",
"particular",
"length"
] | 4745a99e523213cb3bfde5759c8390b79fa6ab88 | https://github.com/JustZisGuy/wildling/blob/4745a99e523213cb3bfde5759c8390b79fa6ab88/src/token.js#L16-L34 |
51,854 | byron-dupreez/aws-stream-consumer-core | esm-cache.js | clearCache | function clearCache() {
let deletedCount = 0;
const iter = eventSourceMappingKeysByFunctionAndStream.entries();
let next = iter.next();
while (!next.done) {
const [k, key] = next.value;
const deleted = eventSourceMappingPromisesByKey.delete(key);
eventSourceMappingKeysByFunctionAndStream.delete(k);
if (deleted) {
++deletedCount;
}
next = iter.next();
}
return deletedCount;
} | javascript | function clearCache() {
let deletedCount = 0;
const iter = eventSourceMappingKeysByFunctionAndStream.entries();
let next = iter.next();
while (!next.done) {
const [k, key] = next.value;
const deleted = eventSourceMappingPromisesByKey.delete(key);
eventSourceMappingKeysByFunctionAndStream.delete(k);
if (deleted) {
++deletedCount;
}
next = iter.next();
}
return deletedCount;
} | [
"function",
"clearCache",
"(",
")",
"{",
"let",
"deletedCount",
"=",
"0",
";",
"const",
"iter",
"=",
"eventSourceMappingKeysByFunctionAndStream",
".",
"entries",
"(",
")",
";",
"let",
"next",
"=",
"iter",
".",
"next",
"(",
")",
";",
"while",
"(",
"!",
"next",
".",
"done",
")",
"{",
"const",
"[",
"k",
",",
"key",
"]",
"=",
"next",
".",
"value",
";",
"const",
"deleted",
"=",
"eventSourceMappingPromisesByKey",
".",
"delete",
"(",
"key",
")",
";",
"eventSourceMappingKeysByFunctionAndStream",
".",
"delete",
"(",
"k",
")",
";",
"if",
"(",
"deleted",
")",
"{",
"++",
"deletedCount",
";",
"}",
"next",
"=",
"iter",
".",
"next",
"(",
")",
";",
"}",
"return",
"deletedCount",
";",
"}"
] | Clears the event source mapping key and promise caches.
@return {number} the number of promises removed from the cache | [
"Clears",
"the",
"event",
"source",
"mapping",
"key",
"and",
"promise",
"caches",
"."
] | 9b256084297f80d373bcf483aaf68a9da176b3d7 | https://github.com/byron-dupreez/aws-stream-consumer-core/blob/9b256084297f80d373bcf483aaf68a9da176b3d7/esm-cache.js#L115-L134 |
51,855 | jsekamane/Cree | client/cree-client.js | loadPage | function loadPage(url) {
$("#container").load(url+" #container > *", function(response, status, xhr){
$('html,body').scrollTop(0); // Scroll to the top when loading new page.
if(status == "error"){
$("#container").prepend('<p class="alert alert-danger" role="alert"><strong>'+msgError+'</strong> '+xhr.status+' '+xhr.statusText+' <small>'+url+'</small></p>');
} else if(status == "success"){
cloak.message('loaded', url); // Respond back to server with 'loaded' message
}
});
} | javascript | function loadPage(url) {
$("#container").load(url+" #container > *", function(response, status, xhr){
$('html,body').scrollTop(0); // Scroll to the top when loading new page.
if(status == "error"){
$("#container").prepend('<p class="alert alert-danger" role="alert"><strong>'+msgError+'</strong> '+xhr.status+' '+xhr.statusText+' <small>'+url+'</small></p>');
} else if(status == "success"){
cloak.message('loaded', url); // Respond back to server with 'loaded' message
}
});
} | [
"function",
"loadPage",
"(",
"url",
")",
"{",
"$",
"(",
"\"#container\"",
")",
".",
"load",
"(",
"url",
"+",
"\" #container > *\"",
",",
"function",
"(",
"response",
",",
"status",
",",
"xhr",
")",
"{",
"$",
"(",
"'html,body'",
")",
".",
"scrollTop",
"(",
"0",
")",
";",
"// Scroll to the top when loading new page.",
"if",
"(",
"status",
"==",
"\"error\"",
")",
"{",
"$",
"(",
"\"#container\"",
")",
".",
"prepend",
"(",
"'<p class=\"alert alert-danger\" role=\"alert\"><strong>'",
"+",
"msgError",
"+",
"'</strong> '",
"+",
"xhr",
".",
"status",
"+",
"' '",
"+",
"xhr",
".",
"statusText",
"+",
"' <small>'",
"+",
"url",
"+",
"'</small></p>'",
")",
";",
"}",
"else",
"if",
"(",
"status",
"==",
"\"success\"",
")",
"{",
"cloak",
".",
"message",
"(",
"'loaded'",
",",
"url",
")",
";",
"// Respond back to server with 'loaded' message",
"}",
"}",
")",
";",
"}"
] | Using AJAX, load the url that was received from the server through a 'load' message. | [
"Using",
"AJAX",
"load",
"the",
"url",
"that",
"was",
"received",
"from",
"the",
"server",
"through",
"a",
"load",
"message",
"."
] | ccff87d4bb5b95c8d96c44731033f29a82df871e | https://github.com/jsekamane/Cree/blob/ccff87d4bb5b95c8d96c44731033f29a82df871e/client/cree-client.js#L51-L61 |
51,856 | jsekamane/Cree | client/cree-client.js | next | function next() {
var data = new Object();
// Submit content of all forms -- except those with class 'ignore-form' -- before going to next page.
$('#container form:not(.ignore-form)').each(function(index) {
//console.log("Form no. "+index + " with the ID #" + $(this).attr('id') );
//console.log($( this ).serializeArray() );
data[$(this).attr('id')] = $( this ).serializeArray(); // Add each form's data to the data object.
});
if(isEmpty(data))
cloak.message('next');
else
cloak.message('next', data);
} | javascript | function next() {
var data = new Object();
// Submit content of all forms -- except those with class 'ignore-form' -- before going to next page.
$('#container form:not(.ignore-form)').each(function(index) {
//console.log("Form no. "+index + " with the ID #" + $(this).attr('id') );
//console.log($( this ).serializeArray() );
data[$(this).attr('id')] = $( this ).serializeArray(); // Add each form's data to the data object.
});
if(isEmpty(data))
cloak.message('next');
else
cloak.message('next', data);
} | [
"function",
"next",
"(",
")",
"{",
"var",
"data",
"=",
"new",
"Object",
"(",
")",
";",
"// Submit content of all forms -- except those with class 'ignore-form' -- before going to next page.",
"$",
"(",
"'#container form:not(.ignore-form)'",
")",
".",
"each",
"(",
"function",
"(",
"index",
")",
"{",
"//console.log(\"Form no. \"+index + \" with the ID #\" + $(this).attr('id') );",
"//console.log($( this ).serializeArray() );",
"data",
"[",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'id'",
")",
"]",
"=",
"$",
"(",
"this",
")",
".",
"serializeArray",
"(",
")",
";",
"// Add each form's data to the data object.",
"}",
")",
";",
"if",
"(",
"isEmpty",
"(",
"data",
")",
")",
"cloak",
".",
"message",
"(",
"'next'",
")",
";",
"else",
"cloak",
".",
"message",
"(",
"'next'",
",",
"data",
")",
";",
"}"
] | Continue to next stage | [
"Continue",
"to",
"next",
"stage"
] | ccff87d4bb5b95c8d96c44731033f29a82df871e | https://github.com/jsekamane/Cree/blob/ccff87d4bb5b95c8d96c44731033f29a82df871e/client/cree-client.js#L70-L84 |
51,857 | commonform-archive/commonform-serve-projects | index.js | requireAuthorization | function requireAuthorization(handler) {
return function(request, response, store, parameters) {
var handlerArguments = arguments
var publisher = parameters.publisher
var authorization = request.headers.authorization
if (authorization) {
var parsed = parseAuthorization(authorization)
if (parsed === false || parsed.user !== publisher) {
respond401(response) }
else {
checkPassword(publisher, parsed.password, function(error, valid) {
if (error) {
respond500(request, response, error) }
else {
if (valid) {
handler.apply(this, handlerArguments) }
else {
respond401(response) } } }) } }
else {
respond401(response) } } } | javascript | function requireAuthorization(handler) {
return function(request, response, store, parameters) {
var handlerArguments = arguments
var publisher = parameters.publisher
var authorization = request.headers.authorization
if (authorization) {
var parsed = parseAuthorization(authorization)
if (parsed === false || parsed.user !== publisher) {
respond401(response) }
else {
checkPassword(publisher, parsed.password, function(error, valid) {
if (error) {
respond500(request, response, error) }
else {
if (valid) {
handler.apply(this, handlerArguments) }
else {
respond401(response) } } }) } }
else {
respond401(response) } } } | [
"function",
"requireAuthorization",
"(",
"handler",
")",
"{",
"return",
"function",
"(",
"request",
",",
"response",
",",
"store",
",",
"parameters",
")",
"{",
"var",
"handlerArguments",
"=",
"arguments",
"var",
"publisher",
"=",
"parameters",
".",
"publisher",
"var",
"authorization",
"=",
"request",
".",
"headers",
".",
"authorization",
"if",
"(",
"authorization",
")",
"{",
"var",
"parsed",
"=",
"parseAuthorization",
"(",
"authorization",
")",
"if",
"(",
"parsed",
"===",
"false",
"||",
"parsed",
".",
"user",
"!==",
"publisher",
")",
"{",
"respond401",
"(",
"response",
")",
"}",
"else",
"{",
"checkPassword",
"(",
"publisher",
",",
"parsed",
".",
"password",
",",
"function",
"(",
"error",
",",
"valid",
")",
"{",
"if",
"(",
"error",
")",
"{",
"respond500",
"(",
"request",
",",
"response",
",",
"error",
")",
"}",
"else",
"{",
"if",
"(",
"valid",
")",
"{",
"handler",
".",
"apply",
"(",
"this",
",",
"handlerArguments",
")",
"}",
"else",
"{",
"respond401",
"(",
"response",
")",
"}",
"}",
"}",
")",
"}",
"}",
"else",
"{",
"respond401",
"(",
"response",
")",
"}",
"}",
"}"
] | Wrap a request handler function to check authoriztion. | [
"Wrap",
"a",
"request",
"handler",
"function",
"to",
"check",
"authoriztion",
"."
] | f4a6b40ba7f19a579b52ffbce88eeeaa11685bd5 | https://github.com/commonform-archive/commonform-serve-projects/blob/f4a6b40ba7f19a579b52ffbce88eeeaa11685bd5/index.js#L233-L252 |
51,858 | gethuman/pancakes-angular | lib/transformers/ng.apiclient.transformer.js | transform | function transform(flapjack, options) {
var moduleName = options.moduleName;
var filePath = options.filePath;
var appName = this.getAppName(filePath, options.appName);
var resource = this.pancakes.cook(moduleName, { flapjack: flapjack });
var templateModel = this.getTemplateModel(options.prefix, resource, appName);
return templateModel ? this.template(templateModel) : null;
} | javascript | function transform(flapjack, options) {
var moduleName = options.moduleName;
var filePath = options.filePath;
var appName = this.getAppName(filePath, options.appName);
var resource = this.pancakes.cook(moduleName, { flapjack: flapjack });
var templateModel = this.getTemplateModel(options.prefix, resource, appName);
return templateModel ? this.template(templateModel) : null;
} | [
"function",
"transform",
"(",
"flapjack",
",",
"options",
")",
"{",
"var",
"moduleName",
"=",
"options",
".",
"moduleName",
";",
"var",
"filePath",
"=",
"options",
".",
"filePath",
";",
"var",
"appName",
"=",
"this",
".",
"getAppName",
"(",
"filePath",
",",
"options",
".",
"appName",
")",
";",
"var",
"resource",
"=",
"this",
".",
"pancakes",
".",
"cook",
"(",
"moduleName",
",",
"{",
"flapjack",
":",
"flapjack",
"}",
")",
";",
"var",
"templateModel",
"=",
"this",
".",
"getTemplateModel",
"(",
"options",
".",
"prefix",
",",
"resource",
",",
"appName",
")",
";",
"return",
"templateModel",
"?",
"this",
".",
"template",
"(",
"templateModel",
")",
":",
"null",
";",
"}"
] | Do the transformation
@param flapjack
@param options
@returns {*} | [
"Do",
"the",
"transformation"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/transformers/ng.apiclient.transformer.js#L16-L23 |
51,859 | gethuman/pancakes-angular | lib/transformers/ng.apiclient.transformer.js | getTemplateModel | function getTemplateModel(prefix, resource, appName) {
var methods = {};
// if no api or browser apiclient, then return null since we will skip
if (!resource.api || resource.adapters.browser !== 'apiclient') {
return null;
}
// loop through API routes and create method objects for the template
_.each(resource.api, function (urlMappings, httpMethod) {
_.each(urlMappings, function (methodName, url) {
methods[methodName] = {
httpMethod: httpMethod,
url: url
};
});
});
return {
resourceName: resource.name,
appName: this.getAppModuleName(prefix, appName),
serviceName: this.pancakes.utils.getCamelCase(resource.name + '.service'),
modelName: this.pancakes.utils.getPascalCase(resource.name),
methods: JSON.stringify(methods)
};
} | javascript | function getTemplateModel(prefix, resource, appName) {
var methods = {};
// if no api or browser apiclient, then return null since we will skip
if (!resource.api || resource.adapters.browser !== 'apiclient') {
return null;
}
// loop through API routes and create method objects for the template
_.each(resource.api, function (urlMappings, httpMethod) {
_.each(urlMappings, function (methodName, url) {
methods[methodName] = {
httpMethod: httpMethod,
url: url
};
});
});
return {
resourceName: resource.name,
appName: this.getAppModuleName(prefix, appName),
serviceName: this.pancakes.utils.getCamelCase(resource.name + '.service'),
modelName: this.pancakes.utils.getPascalCase(resource.name),
methods: JSON.stringify(methods)
};
} | [
"function",
"getTemplateModel",
"(",
"prefix",
",",
"resource",
",",
"appName",
")",
"{",
"var",
"methods",
"=",
"{",
"}",
";",
"// if no api or browser apiclient, then return null since we will skip",
"if",
"(",
"!",
"resource",
".",
"api",
"||",
"resource",
".",
"adapters",
".",
"browser",
"!==",
"'apiclient'",
")",
"{",
"return",
"null",
";",
"}",
"// loop through API routes and create method objects for the template",
"_",
".",
"each",
"(",
"resource",
".",
"api",
",",
"function",
"(",
"urlMappings",
",",
"httpMethod",
")",
"{",
"_",
".",
"each",
"(",
"urlMappings",
",",
"function",
"(",
"methodName",
",",
"url",
")",
"{",
"methods",
"[",
"methodName",
"]",
"=",
"{",
"httpMethod",
":",
"httpMethod",
",",
"url",
":",
"url",
"}",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"{",
"resourceName",
":",
"resource",
".",
"name",
",",
"appName",
":",
"this",
".",
"getAppModuleName",
"(",
"prefix",
",",
"appName",
")",
",",
"serviceName",
":",
"this",
".",
"pancakes",
".",
"utils",
".",
"getCamelCase",
"(",
"resource",
".",
"name",
"+",
"'.service'",
")",
",",
"modelName",
":",
"this",
".",
"pancakes",
".",
"utils",
".",
"getPascalCase",
"(",
"resource",
".",
"name",
")",
",",
"methods",
":",
"JSON",
".",
"stringify",
"(",
"methods",
")",
"}",
";",
"}"
] | Get the template model for an API Client
@param prefix
@param resource
@param appName
@returns {*} | [
"Get",
"the",
"template",
"model",
"for",
"an",
"API",
"Client"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/transformers/ng.apiclient.transformer.js#L32-L57 |
51,860 | hex7c0/logger-request-cli | lib/in.js | cc | function cc(line, params) {
var event = params[0];
var what = params[1];
try {
++event[line[what]].counter;
} catch (TypeError) {
event[line[what]] = {
counter: 1
};
}
return event;
} | javascript | function cc(line, params) {
var event = params[0];
var what = params[1];
try {
++event[line[what]].counter;
} catch (TypeError) {
event[line[what]] = {
counter: 1
};
}
return event;
} | [
"function",
"cc",
"(",
"line",
",",
"params",
")",
"{",
"var",
"event",
"=",
"params",
"[",
"0",
"]",
";",
"var",
"what",
"=",
"params",
"[",
"1",
"]",
";",
"try",
"{",
"++",
"event",
"[",
"line",
"[",
"what",
"]",
"]",
".",
"counter",
";",
"}",
"catch",
"(",
"TypeError",
")",
"{",
"event",
"[",
"line",
"[",
"what",
"]",
"]",
"=",
"{",
"counter",
":",
"1",
"}",
";",
"}",
"return",
"event",
";",
"}"
] | input for counter
@function cc
@param {String} line - line read
@param {Array} output - object stored
@return {Object} | [
"input",
"for",
"counter"
] | b1110592dd62e673561a1a4e1c4e122a2a93890a | https://github.com/hex7c0/logger-request-cli/blob/b1110592dd62e673561a1a4e1c4e122a2a93890a/lib/in.js#L53-L65 |
51,861 | hex7c0/logger-request-cli | lib/in.js | avg | function avg(line, params) {
var event = params[0];
var what = params[1];
var r = Number(line[what]);
event.what += r;
++event.total;
if (r > event.max) {
event.max = r;
}
if (r < event.min) {
event.min = r;
}
return event;
} | javascript | function avg(line, params) {
var event = params[0];
var what = params[1];
var r = Number(line[what]);
event.what += r;
++event.total;
if (r > event.max) {
event.max = r;
}
if (r < event.min) {
event.min = r;
}
return event;
} | [
"function",
"avg",
"(",
"line",
",",
"params",
")",
"{",
"var",
"event",
"=",
"params",
"[",
"0",
"]",
";",
"var",
"what",
"=",
"params",
"[",
"1",
"]",
";",
"var",
"r",
"=",
"Number",
"(",
"line",
"[",
"what",
"]",
")",
";",
"event",
".",
"what",
"+=",
"r",
";",
"++",
"event",
".",
"total",
";",
"if",
"(",
"r",
">",
"event",
".",
"max",
")",
"{",
"event",
".",
"max",
"=",
"r",
";",
"}",
"if",
"(",
"r",
"<",
"event",
".",
"min",
")",
"{",
"event",
".",
"min",
"=",
"r",
";",
"}",
"return",
"event",
";",
"}"
] | input for average
@function avg
@param {String} line - line read
@param {Array} output - object stored
@return {Object} | [
"input",
"for",
"average"
] | b1110592dd62e673561a1a4e1c4e122a2a93890a | https://github.com/hex7c0/logger-request-cli/blob/b1110592dd62e673561a1a4e1c4e122a2a93890a/lib/in.js#L75-L89 |
51,862 | influx6/ToolStack | lib/stack.utility.js | function(a,b,beStrict){
if(this.isArray(a) && this.isArray(b)){
var alen = a.length, i = 0;
if(beStrict){
if(alen !== (b).length){ return false; }
}
for(; i < alen; i++){
if(a[i] === undefined || b[i] === undefined) break;
if(b[i] !== a[i]){
return false;
break;
}
}
return true;
}
} | javascript | function(a,b,beStrict){
if(this.isArray(a) && this.isArray(b)){
var alen = a.length, i = 0;
if(beStrict){
if(alen !== (b).length){ return false; }
}
for(; i < alen; i++){
if(a[i] === undefined || b[i] === undefined) break;
if(b[i] !== a[i]){
return false;
break;
}
}
return true;
}
} | [
"function",
"(",
"a",
",",
"b",
",",
"beStrict",
")",
"{",
"if",
"(",
"this",
".",
"isArray",
"(",
"a",
")",
"&&",
"this",
".",
"isArray",
"(",
"b",
")",
")",
"{",
"var",
"alen",
"=",
"a",
".",
"length",
",",
"i",
"=",
"0",
";",
"if",
"(",
"beStrict",
")",
"{",
"if",
"(",
"alen",
"!==",
"(",
"b",
")",
".",
"length",
")",
"{",
"return",
"false",
";",
"}",
"}",
"for",
"(",
";",
"i",
"<",
"alen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"a",
"[",
"i",
"]",
"===",
"undefined",
"||",
"b",
"[",
"i",
"]",
"===",
"undefined",
")",
"break",
";",
"if",
"(",
"b",
"[",
"i",
"]",
"!==",
"a",
"[",
"i",
"]",
")",
"{",
"return",
"false",
";",
"break",
";",
"}",
"}",
"return",
"true",
";",
"}",
"}"
] | use to match arrays to arrays to ensure values are equal to each other, useStrict when set to true,ensures the size of properties of both arrays are the same | [
"use",
"to",
"match",
"arrays",
"to",
"arrays",
"to",
"ensure",
"values",
"are",
"equal",
"to",
"each",
"other",
"useStrict",
"when",
"set",
"to",
"true",
"ensures",
"the",
"size",
"of",
"properties",
"of",
"both",
"arrays",
"are",
"the",
"same"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L135-L151 |
|
51,863 | influx6/ToolStack | lib/stack.utility.js | function(a,b,beStrict){
if(this.isObject(a) && this.isObject(b)){
var alen = this.keys(a).length, i;
for(i in a){
if(beStrict){
if(!(i in b)){
return false;
break;
}
}
if((i in b)){
if(b[i] !== a[i]){
return false;
break;
}
}
}
return true;
}
} | javascript | function(a,b,beStrict){
if(this.isObject(a) && this.isObject(b)){
var alen = this.keys(a).length, i;
for(i in a){
if(beStrict){
if(!(i in b)){
return false;
break;
}
}
if((i in b)){
if(b[i] !== a[i]){
return false;
break;
}
}
}
return true;
}
} | [
"function",
"(",
"a",
",",
"b",
",",
"beStrict",
")",
"{",
"if",
"(",
"this",
".",
"isObject",
"(",
"a",
")",
"&&",
"this",
".",
"isObject",
"(",
"b",
")",
")",
"{",
"var",
"alen",
"=",
"this",
".",
"keys",
"(",
"a",
")",
".",
"length",
",",
"i",
";",
"for",
"(",
"i",
"in",
"a",
")",
"{",
"if",
"(",
"beStrict",
")",
"{",
"if",
"(",
"!",
"(",
"i",
"in",
"b",
")",
")",
"{",
"return",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"(",
"i",
"in",
"b",
")",
")",
"{",
"if",
"(",
"b",
"[",
"i",
"]",
"!==",
"a",
"[",
"i",
"]",
")",
"{",
"return",
"false",
";",
"break",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}",
"}"
] | alternative when matching objects to objects,beStrict criteria here is to check if the object to be matched and the object to use to match have the same properties | [
"alternative",
"when",
"matching",
"objects",
"to",
"objects",
"beStrict",
"criteria",
"here",
"is",
"to",
"check",
"if",
"the",
"object",
"to",
"be",
"matched",
"and",
"the",
"object",
"to",
"use",
"to",
"match",
"have",
"the",
"same",
"properties"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L156-L176 |
|
51,864 | influx6/ToolStack | lib/stack.utility.js | function(args){
if(this.isObject(args)){
return [this.keys(args),this.values(args)];
}
if(this.isArgument(args)){
return [].splice.call(args,0);
}
if(!this.isArray(args) && !this.isObject(args)){
return [args];
}
} | javascript | function(args){
if(this.isObject(args)){
return [this.keys(args),this.values(args)];
}
if(this.isArgument(args)){
return [].splice.call(args,0);
}
if(!this.isArray(args) && !this.isObject(args)){
return [args];
}
} | [
"function",
"(",
"args",
")",
"{",
"if",
"(",
"this",
".",
"isObject",
"(",
"args",
")",
")",
"{",
"return",
"[",
"this",
".",
"keys",
"(",
"args",
")",
",",
"this",
".",
"values",
"(",
"args",
")",
"]",
";",
"}",
"if",
"(",
"this",
".",
"isArgument",
"(",
"args",
")",
")",
"{",
"return",
"[",
"]",
".",
"splice",
".",
"call",
"(",
"args",
",",
"0",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"isArray",
"(",
"args",
")",
"&&",
"!",
"this",
".",
"isObject",
"(",
"args",
")",
")",
"{",
"return",
"[",
"args",
"]",
";",
"}",
"}"
] | takes a single supplied value and turns it into an array,if its an object returns an array containing two subarrays of keys and values in the return array,if a single variable,simple wraps it in an array, | [
"takes",
"a",
"single",
"supplied",
"value",
"and",
"turns",
"it",
"into",
"an",
"array",
"if",
"its",
"an",
"object",
"returns",
"an",
"array",
"containing",
"two",
"subarrays",
"of",
"keys",
"and",
"values",
"in",
"the",
"return",
"array",
"if",
"a",
"single",
"variable",
"simple",
"wraps",
"it",
"in",
"an",
"array"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L212-L222 |
|
51,865 | influx6/ToolStack | lib/stack.utility.js | function () {
var val = (1 + (Math.random() * (30000)) | 3);
if(!(val >= 10000)){
val += (10000 * Math.floor(Math.random * 9));
}
return val;
} | javascript | function () {
var val = (1 + (Math.random() * (30000)) | 3);
if(!(val >= 10000)){
val += (10000 * Math.floor(Math.random * 9));
}
return val;
} | [
"function",
"(",
")",
"{",
"var",
"val",
"=",
"(",
"1",
"+",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"(",
"30000",
")",
")",
"|",
"3",
")",
";",
"if",
"(",
"!",
"(",
"val",
">=",
"10000",
")",
")",
"{",
"val",
"+=",
"(",
"10000",
"*",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"*",
"9",
")",
")",
";",
"}",
"return",
"val",
";",
"}"
] | simple function to generate random numbers of 4 lengths | [
"simple",
"function",
"to",
"generate",
"random",
"numbers",
"of",
"4",
"lengths"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L225-L231 |
|
51,866 | influx6/ToolStack | lib/stack.utility.js | function(i,value){
if(!value) return;
var i = i || 1,message = "";
while(true){
message += value;
if((--i) <= 0) break;
}
return message;
} | javascript | function(i,value){
if(!value) return;
var i = i || 1,message = "";
while(true){
message += value;
if((--i) <= 0) break;
}
return message;
} | [
"function",
"(",
"i",
",",
"value",
")",
"{",
"if",
"(",
"!",
"value",
")",
"return",
";",
"var",
"i",
"=",
"i",
"||",
"1",
",",
"message",
"=",
"\"\"",
";",
"while",
"(",
"true",
")",
"{",
"message",
"+=",
"value",
";",
"if",
"(",
"(",
"--",
"i",
")",
"<=",
"0",
")",
"break",
";",
"}",
"return",
"message",
";",
"}"
] | for string just iterates a single as specificed in the first arguments | [
"for",
"string",
"just",
"iterates",
"a",
"single",
"as",
"specificed",
"in",
"the",
"first",
"arguments"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L242-L251 |
|
51,867 | influx6/ToolStack | lib/stack.utility.js | function(o,value,fn){
if(this.isArray(o)){
return this._anyArray(o,value,fn);
}
if(this.isObject(o)){
return this._anyObject(o,value,fn);
}
} | javascript | function(o,value,fn){
if(this.isArray(o)){
return this._anyArray(o,value,fn);
}
if(this.isObject(o)){
return this._anyObject(o,value,fn);
}
} | [
"function",
"(",
"o",
",",
"value",
",",
"fn",
")",
"{",
"if",
"(",
"this",
".",
"isArray",
"(",
"o",
")",
")",
"{",
"return",
"this",
".",
"_anyArray",
"(",
"o",
",",
"value",
",",
"fn",
")",
";",
"}",
"if",
"(",
"this",
".",
"isObject",
"(",
"o",
")",
")",
"{",
"return",
"this",
".",
"_anyObject",
"(",
"o",
",",
"value",
",",
"fn",
")",
";",
"}",
"}"
] | returns the position of the first item that meets the value in an array | [
"returns",
"the",
"position",
"of",
"the",
"first",
"item",
"that",
"meets",
"the",
"value",
"in",
"an",
"array"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L352-L359 |
|
51,868 | influx6/ToolStack | lib/stack.utility.js | function(arrays,result){
var self = this,flat = result || [];
this.forEach(arrays,function(a){
if(self.isArray(a)){
self.flatten(a,flat);
}else{
flat.push(a);
}
},self);
return flat;
} | javascript | function(arrays,result){
var self = this,flat = result || [];
this.forEach(arrays,function(a){
if(self.isArray(a)){
self.flatten(a,flat);
}else{
flat.push(a);
}
},self);
return flat;
} | [
"function",
"(",
"arrays",
",",
"result",
")",
"{",
"var",
"self",
"=",
"this",
",",
"flat",
"=",
"result",
"||",
"[",
"]",
";",
"this",
".",
"forEach",
"(",
"arrays",
",",
"function",
"(",
"a",
")",
"{",
"if",
"(",
"self",
".",
"isArray",
"(",
"a",
")",
")",
"{",
"self",
".",
"flatten",
"(",
"a",
",",
"flat",
")",
";",
"}",
"else",
"{",
"flat",
".",
"push",
"(",
"a",
")",
";",
"}",
"}",
",",
"self",
")",
";",
"return",
"flat",
";",
"}"
] | mainly works wth arrays only flattens an array that contains multiple arrays into a single array | [
"mainly",
"works",
"wth",
"arrays",
"only",
"flattens",
"an",
"array",
"that",
"contains",
"multiple",
"arrays",
"into",
"a",
"single",
"array"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L455-L468 |
|
51,869 | influx6/ToolStack | lib/stack.utility.js | function(o,value){
var occurence = [];
this.forEach(o,function occurmover(e,i,b){
if(e === value){ occurence.push(i); }
},this);
return occurence;
} | javascript | function(o,value){
var occurence = [];
this.forEach(o,function occurmover(e,i,b){
if(e === value){ occurence.push(i); }
},this);
return occurence;
} | [
"function",
"(",
"o",
",",
"value",
")",
"{",
"var",
"occurence",
"=",
"[",
"]",
";",
"this",
".",
"forEach",
"(",
"o",
",",
"function",
"occurmover",
"(",
"e",
",",
"i",
",",
"b",
")",
"{",
"if",
"(",
"e",
"===",
"value",
")",
"{",
"occurence",
".",
"push",
"(",
"i",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"occurence",
";",
"}"
] | returns an array of occurences index of a particular value | [
"returns",
"an",
"array",
"of",
"occurences",
"index",
"of",
"a",
"particular",
"value"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L482-L488 |
|
51,870 | influx6/ToolStack | lib/stack.utility.js | function(o,value,fn){
this.forEach(o,function everymover(e,i,b){
if(e === value){
if(fn) fn.call(this,e,i,b);
}
},this);
return;
} | javascript | function(o,value,fn){
this.forEach(o,function everymover(e,i,b){
if(e === value){
if(fn) fn.call(this,e,i,b);
}
},this);
return;
} | [
"function",
"(",
"o",
",",
"value",
",",
"fn",
")",
"{",
"this",
".",
"forEach",
"(",
"o",
",",
"function",
"everymover",
"(",
"e",
",",
"i",
",",
"b",
")",
"{",
"if",
"(",
"e",
"===",
"value",
")",
"{",
"if",
"(",
"fn",
")",
"fn",
".",
"call",
"(",
"this",
",",
"e",
",",
"i",
",",
"b",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
";",
"}"
] | performs an operation on every item that has a particular value in the object | [
"performs",
"an",
"operation",
"on",
"every",
"item",
"that",
"has",
"a",
"particular",
"value",
"in",
"the",
"object"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L491-L498 |
|
51,871 | influx6/ToolStack | lib/stack.utility.js | function(o,start,end){
var i = 0,len = o.length;
if(!len || len <= 0) return false;
start = Math.abs(start); end = Math.abs(end);
if(end > (len - start)){
end = (len - start);
}
for(; i < len; i++){
o[i] = o[start];
start +=1;
if(i >= end) break;
}
o.length = end;
return o;
} | javascript | function(o,start,end){
var i = 0,len = o.length;
if(!len || len <= 0) return false;
start = Math.abs(start); end = Math.abs(end);
if(end > (len - start)){
end = (len - start);
}
for(; i < len; i++){
o[i] = o[start];
start +=1;
if(i >= end) break;
}
o.length = end;
return o;
} | [
"function",
"(",
"o",
",",
"start",
",",
"end",
")",
"{",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"o",
".",
"length",
";",
"if",
"(",
"!",
"len",
"||",
"len",
"<=",
"0",
")",
"return",
"false",
";",
"start",
"=",
"Math",
".",
"abs",
"(",
"start",
")",
";",
"end",
"=",
"Math",
".",
"abs",
"(",
"end",
")",
";",
"if",
"(",
"end",
">",
"(",
"len",
"-",
"start",
")",
")",
"{",
"end",
"=",
"(",
"len",
"-",
"start",
")",
";",
"}",
"for",
"(",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"o",
"[",
"i",
"]",
"=",
"o",
"[",
"start",
"]",
";",
"start",
"+=",
"1",
";",
"if",
"(",
"i",
">=",
"end",
")",
"break",
";",
"}",
"o",
".",
"length",
"=",
"end",
";",
"return",
"o",
";",
"}"
] | destructive splice,changes the giving array instead of returning a new one writing to only work with positive numbers only | [
"destructive",
"splice",
"changes",
"the",
"giving",
"array",
"instead",
"of",
"returning",
"a",
"new",
"one",
"writing",
"to",
"only",
"work",
"with",
"positive",
"numbers",
"only"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L516-L533 |
|
51,872 | influx6/ToolStack | lib/stack.utility.js | function(a){
if(!a || !this.isArray(a)) return;
var i = 0,start = 0,len = a.length;
for(;i < len; i++){
if(!this.isUndefined(a[i]) && !this.isNull(a[i]) && !(this.isEmpty(a[i]))){
a[start]=a[i];
start += 1;
}
}
a.length = start;
return a;
} | javascript | function(a){
if(!a || !this.isArray(a)) return;
var i = 0,start = 0,len = a.length;
for(;i < len; i++){
if(!this.isUndefined(a[i]) && !this.isNull(a[i]) && !(this.isEmpty(a[i]))){
a[start]=a[i];
start += 1;
}
}
a.length = start;
return a;
} | [
"function",
"(",
"a",
")",
"{",
"if",
"(",
"!",
"a",
"||",
"!",
"this",
".",
"isArray",
"(",
"a",
")",
")",
"return",
";",
"var",
"i",
"=",
"0",
",",
"start",
"=",
"0",
",",
"len",
"=",
"a",
".",
"length",
";",
"for",
"(",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isUndefined",
"(",
"a",
"[",
"i",
"]",
")",
"&&",
"!",
"this",
".",
"isNull",
"(",
"a",
"[",
"i",
"]",
")",
"&&",
"!",
"(",
"this",
".",
"isEmpty",
"(",
"a",
"[",
"i",
"]",
")",
")",
")",
"{",
"a",
"[",
"start",
"]",
"=",
"a",
"[",
"i",
"]",
";",
"start",
"+=",
"1",
";",
"}",
"}",
"a",
".",
"length",
"=",
"start",
";",
"return",
"a",
";",
"}"
] | normalizes an array,ensures theres no undefined or empty spaces between arrays | [
"normalizes",
"an",
"array",
"ensures",
"theres",
"no",
"undefined",
"or",
"empty",
"spaces",
"between",
"arrays"
] | d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db | https://github.com/influx6/ToolStack/blob/d0c7b1acc1546f5e7ff9d04ca6c9222b2577e0db/lib/stack.utility.js#L944-L958 |
|
51,873 | atd-schubert/node-stream-lib | lib/random.js | Random | function Random(opts) {
Readable.apply(this, arguments);
if (opts && opts.objectMode) {
this.objectMode = true;
}
this.dictionary = ['1', '0'];
} | javascript | function Random(opts) {
Readable.apply(this, arguments);
if (opts && opts.objectMode) {
this.objectMode = true;
}
this.dictionary = ['1', '0'];
} | [
"function",
"Random",
"(",
"opts",
")",
"{",
"Readable",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"objectMode",
")",
"{",
"this",
".",
"objectMode",
"=",
"true",
";",
"}",
"this",
".",
"dictionary",
"=",
"[",
"'1'",
",",
"'0'",
"]",
";",
"}"
] | Create a stream of random values from dictionary
@author Arne Schubert <[email protected]>
@constructor
@memberOf streamLib
@augments {stream.Readable} | [
"Create",
"a",
"stream",
"of",
"random",
"values",
"from",
"dictionary"
] | 90f27042fae84d2fbdbf9d28149b0673997f151a | https://github.com/atd-schubert/node-stream-lib/blob/90f27042fae84d2fbdbf9d28149b0673997f151a/lib/random.js#L18-L26 |
51,874 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | createLocalCache | function createLocalCache() {
var localCache = lruCache({ max: 100, maxAge: 60000 });
return {
get: function (key) {
return new Q(localCache.get(key));
},
set: function (key, value) {
localCache.set(key, value);
},
del: function (key) {
localCache.set(key, null);
}
};
} | javascript | function createLocalCache() {
var localCache = lruCache({ max: 100, maxAge: 60000 });
return {
get: function (key) {
return new Q(localCache.get(key));
},
set: function (key, value) {
localCache.set(key, value);
},
del: function (key) {
localCache.set(key, null);
}
};
} | [
"function",
"createLocalCache",
"(",
")",
"{",
"var",
"localCache",
"=",
"lruCache",
"(",
"{",
"max",
":",
"100",
",",
"maxAge",
":",
"60000",
"}",
")",
";",
"return",
"{",
"get",
":",
"function",
"(",
"key",
")",
"{",
"return",
"new",
"Q",
"(",
"localCache",
".",
"get",
"(",
"key",
")",
")",
";",
"}",
",",
"set",
":",
"function",
"(",
"key",
",",
"value",
")",
"{",
"localCache",
".",
"set",
"(",
"key",
",",
"value",
")",
";",
"}",
",",
"del",
":",
"function",
"(",
"key",
")",
"{",
"localCache",
".",
"set",
"(",
"key",
",",
"null",
")",
";",
"}",
"}",
";",
"}"
] | Create local cache with same interface as remote
@returns {{get: Function, set: *}} | [
"Create",
"local",
"cache",
"with",
"same",
"interface",
"as",
"remote"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L68-L81 |
51,875 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | connectToRedis | function connectToRedis(db, opts) {
// get the redis client
var client = redis.createClient(opts.port, opts.host);
// log any errors
client.on('error', function (err) {
redisOffline = true;
console.log('connectToRedis error: ' + err);
});
client.on('ready', function () {
redisOffline = false;
});
// if there is a password, do auth
var deferred = Q.defer();
if (opts.password) {
client.auth(opts.password, function (authErr) {
if (authErr) {
deferred.reject(authErr);
return;
}
client.select(db, function (err) {
err ? deferred.reject(err) : deferred.resolve(client);
});
});
}
else {
client.select(db, function (err) {
err ? deferred.reject(err) : deferred.resolve(client);
});
}
return deferred.promise;
} | javascript | function connectToRedis(db, opts) {
// get the redis client
var client = redis.createClient(opts.port, opts.host);
// log any errors
client.on('error', function (err) {
redisOffline = true;
console.log('connectToRedis error: ' + err);
});
client.on('ready', function () {
redisOffline = false;
});
// if there is a password, do auth
var deferred = Q.defer();
if (opts.password) {
client.auth(opts.password, function (authErr) {
if (authErr) {
deferred.reject(authErr);
return;
}
client.select(db, function (err) {
err ? deferred.reject(err) : deferred.resolve(client);
});
});
}
else {
client.select(db, function (err) {
err ? deferred.reject(err) : deferred.resolve(client);
});
}
return deferred.promise;
} | [
"function",
"connectToRedis",
"(",
"db",
",",
"opts",
")",
"{",
"// get the redis client",
"var",
"client",
"=",
"redis",
".",
"createClient",
"(",
"opts",
".",
"port",
",",
"opts",
".",
"host",
")",
";",
"// log any errors",
"client",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"redisOffline",
"=",
"true",
";",
"console",
".",
"log",
"(",
"'connectToRedis error: '",
"+",
"err",
")",
";",
"}",
")",
";",
"client",
".",
"on",
"(",
"'ready'",
",",
"function",
"(",
")",
"{",
"redisOffline",
"=",
"false",
";",
"}",
")",
";",
"// if there is a password, do auth",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"if",
"(",
"opts",
".",
"password",
")",
"{",
"client",
".",
"auth",
"(",
"opts",
".",
"password",
",",
"function",
"(",
"authErr",
")",
"{",
"if",
"(",
"authErr",
")",
"{",
"deferred",
".",
"reject",
"(",
"authErr",
")",
";",
"return",
";",
"}",
"client",
".",
"select",
"(",
"db",
",",
"function",
"(",
"err",
")",
"{",
"err",
"?",
"deferred",
".",
"reject",
"(",
"err",
")",
":",
"deferred",
".",
"resolve",
"(",
"client",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"client",
".",
"select",
"(",
"db",
",",
"function",
"(",
"err",
")",
"{",
"err",
"?",
"deferred",
".",
"reject",
"(",
"err",
")",
":",
"deferred",
".",
"resolve",
"(",
"client",
")",
";",
"}",
")",
";",
"}",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Create a connection to redis and select the appropriate database
@param db
@param opts
@returns {*} | [
"Create",
"a",
"connection",
"to",
"redis",
"and",
"select",
"the",
"appropriate",
"database"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L89-L125 |
51,876 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | init | function init(config) {
var promises = [];
if (config.redis) {
_.each(config.redis.dbs, function (idx, name) {
promises.push(
connectToRedis(idx, config.redis)
.then(function (remoteCache) {
caches[name] = wrapRemoteCache(remoteCache);
return true;
})
);
});
}
// initialization done once all connections established
return Q.all(promises)
.then(function () {
return config;
});
} | javascript | function init(config) {
var promises = [];
if (config.redis) {
_.each(config.redis.dbs, function (idx, name) {
promises.push(
connectToRedis(idx, config.redis)
.then(function (remoteCache) {
caches[name] = wrapRemoteCache(remoteCache);
return true;
})
);
});
}
// initialization done once all connections established
return Q.all(promises)
.then(function () {
return config;
});
} | [
"function",
"init",
"(",
"config",
")",
"{",
"var",
"promises",
"=",
"[",
"]",
";",
"if",
"(",
"config",
".",
"redis",
")",
"{",
"_",
".",
"each",
"(",
"config",
".",
"redis",
".",
"dbs",
",",
"function",
"(",
"idx",
",",
"name",
")",
"{",
"promises",
".",
"push",
"(",
"connectToRedis",
"(",
"idx",
",",
"config",
".",
"redis",
")",
".",
"then",
"(",
"function",
"(",
"remoteCache",
")",
"{",
"caches",
"[",
"name",
"]",
"=",
"wrapRemoteCache",
"(",
"remoteCache",
")",
";",
"return",
"true",
";",
"}",
")",
")",
";",
"}",
")",
";",
"}",
"// initialization done once all connections established",
"return",
"Q",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"config",
";",
"}",
")",
";",
"}"
] | During the initialization of a pancakes app, this will be called
and all the redis connections will be established.
@param config
@returns {*} | [
"During",
"the",
"initialization",
"of",
"a",
"pancakes",
"app",
"this",
"will",
"be",
"called",
"and",
"all",
"the",
"redis",
"connections",
"will",
"be",
"established",
"."
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L134-L154 |
51,877 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | get | function get(req) {
var cache = caches[this.name];
var returnVal = null;
if (cache && !redisOffline) {
try {
returnVal = cache.get(req.key);
}
catch (err) {
console.log('redis get err: ' + err);
}
}
return new Q(returnVal);
} | javascript | function get(req) {
var cache = caches[this.name];
var returnVal = null;
if (cache && !redisOffline) {
try {
returnVal = cache.get(req.key);
}
catch (err) {
console.log('redis get err: ' + err);
}
}
return new Q(returnVal);
} | [
"function",
"get",
"(",
"req",
")",
"{",
"var",
"cache",
"=",
"caches",
"[",
"this",
".",
"name",
"]",
";",
"var",
"returnVal",
"=",
"null",
";",
"if",
"(",
"cache",
"&&",
"!",
"redisOffline",
")",
"{",
"try",
"{",
"returnVal",
"=",
"cache",
".",
"get",
"(",
"req",
".",
"key",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'redis get err: '",
"+",
"err",
")",
";",
"}",
"}",
"return",
"new",
"Q",
"(",
"returnVal",
")",
";",
"}"
] | Get a value from cache
@param req | [
"Get",
"a",
"value",
"from",
"cache"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L179-L193 |
51,878 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | set | function set(req) {
var cache = caches[this.name];
if (!cache) {
cache = caches[this.name] = createLocalCache();
}
if (!redisOffline) {
try {
(req.value || !cache.del) ?
cache.set(req.key, req.value) :
cache.del(req.key);
}
catch (err) {
console.log('redis set err: ' + err);
}
}
} | javascript | function set(req) {
var cache = caches[this.name];
if (!cache) {
cache = caches[this.name] = createLocalCache();
}
if (!redisOffline) {
try {
(req.value || !cache.del) ?
cache.set(req.key, req.value) :
cache.del(req.key);
}
catch (err) {
console.log('redis set err: ' + err);
}
}
} | [
"function",
"set",
"(",
"req",
")",
"{",
"var",
"cache",
"=",
"caches",
"[",
"this",
".",
"name",
"]",
";",
"if",
"(",
"!",
"cache",
")",
"{",
"cache",
"=",
"caches",
"[",
"this",
".",
"name",
"]",
"=",
"createLocalCache",
"(",
")",
";",
"}",
"if",
"(",
"!",
"redisOffline",
")",
"{",
"try",
"{",
"(",
"req",
".",
"value",
"||",
"!",
"cache",
".",
"del",
")",
"?",
"cache",
".",
"set",
"(",
"req",
".",
"key",
",",
"req",
".",
"value",
")",
":",
"cache",
".",
"del",
"(",
"req",
".",
"key",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'redis set err: '",
"+",
"err",
")",
";",
"}",
"}",
"}"
] | Set a value in the cache
@param req | [
"Set",
"a",
"value",
"in",
"the",
"cache"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L199-L215 |
51,879 | gethuman/pancakes-recipe | services/adapters/redis/redis.adapter.js | clear | function clear() {
var cache = caches[this.name];
if (cache && cache.flush && !redisOffline) {
cache.flush();
}
} | javascript | function clear() {
var cache = caches[this.name];
if (cache && cache.flush && !redisOffline) {
cache.flush();
}
} | [
"function",
"clear",
"(",
")",
"{",
"var",
"cache",
"=",
"caches",
"[",
"this",
".",
"name",
"]",
";",
"if",
"(",
"cache",
"&&",
"cache",
".",
"flush",
"&&",
"!",
"redisOffline",
")",
"{",
"cache",
".",
"flush",
"(",
")",
";",
"}",
"}"
] | Remove all items from this cache | [
"Remove",
"all",
"items",
"from",
"this",
"cache"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/services/adapters/redis/redis.adapter.js#L220-L225 |
51,880 | warelab/gramene-taxonomy-with-genomes | index.js | addCounts | function addCounts(o1, o2) {
var result;
if (o1 && o2) {
result = _.merge(o1, o2, function (a, b) {
return a + b;
});
}
else if (o1) {
result = o1;
}
else {
result = o2;
}
return result;
} | javascript | function addCounts(o1, o2) {
var result;
if (o1 && o2) {
result = _.merge(o1, o2, function (a, b) {
return a + b;
});
}
else if (o1) {
result = o1;
}
else {
result = o2;
}
return result;
} | [
"function",
"addCounts",
"(",
"o1",
",",
"o2",
")",
"{",
"var",
"result",
";",
"if",
"(",
"o1",
"&&",
"o2",
")",
"{",
"result",
"=",
"_",
".",
"merge",
"(",
"o1",
",",
"o2",
",",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
"+",
"b",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"o1",
")",
"{",
"result",
"=",
"o1",
";",
"}",
"else",
"{",
"result",
"=",
"o2",
";",
"}",
"return",
"result",
";",
"}"
] | given two objects that have the same keys and whose values are all integers return a new object that sums them together. If either object is null, return the other one. | [
"given",
"two",
"objects",
"that",
"have",
"the",
"same",
"keys",
"and",
"whose",
"values",
"are",
"all",
"integers",
"return",
"a",
"new",
"object",
"that",
"sums",
"them",
"together",
".",
"If",
"either",
"object",
"is",
"null",
"return",
"the",
"other",
"one",
"."
] | 347a7c8af49d0130941964944b4adfcde65c23c1 | https://github.com/warelab/gramene-taxonomy-with-genomes/blob/347a7c8af49d0130941964944b4adfcde65c23c1/index.js#L11-L25 |
51,881 | cmcampione/thingshub.org | server/src/bl/thingsMngr.js | getThingUserRights | function getThingUserRights(userId, username, thing) {
if (!userId && !username)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "userId or usernane must be not empty", 28);
if (!thing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 27);
let thingUserRights = null;
if (userId)
thingUserRights = thing.usersRights.find(u => u.userId == userId);
if (!thingUserRights && username)
thingUserRights = thing.usersRights.find(u => u.username == username);
return thingUserRights;
} | javascript | function getThingUserRights(userId, username, thing) {
if (!userId && !username)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "userId or usernane must be not empty", 28);
if (!thing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 27);
let thingUserRights = null;
if (userId)
thingUserRights = thing.usersRights.find(u => u.userId == userId);
if (!thingUserRights && username)
thingUserRights = thing.usersRights.find(u => u.username == username);
return thingUserRights;
} | [
"function",
"getThingUserRights",
"(",
"userId",
",",
"username",
",",
"thing",
")",
"{",
"if",
"(",
"!",
"userId",
"&&",
"!",
"username",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"INTERNAL_SERVER_ERROR",
",",
"\"userId or usernane must be not empty\"",
",",
"28",
")",
";",
"if",
"(",
"!",
"thing",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"INTERNAL_SERVER_ERROR",
",",
"\"Thing can't be null\"",
",",
"27",
")",
";",
"let",
"thingUserRights",
"=",
"null",
";",
"if",
"(",
"userId",
")",
"thingUserRights",
"=",
"thing",
".",
"usersRights",
".",
"find",
"(",
"u",
"=>",
"u",
".",
"userId",
"==",
"userId",
")",
";",
"if",
"(",
"!",
"thingUserRights",
"&&",
"username",
")",
"thingUserRights",
"=",
"thing",
".",
"usersRights",
".",
"find",
"(",
"u",
"=>",
"u",
".",
"username",
"==",
"username",
")",
";",
"return",
"thingUserRights",
";",
"}"
] | First search is by userId after it searchs by username Can return null | [
"First",
"search",
"is",
"by",
"userId",
"after",
"it",
"searchs",
"by",
"username",
"Can",
"return",
"null"
] | b9a2e74bddebb80ff473001be93e19ef1578892a | https://github.com/cmcampione/thingshub.org/blob/b9a2e74bddebb80ff473001be93e19ef1578892a/server/src/bl/thingsMngr.js#L19-L34 |
51,882 | cmcampione/thingshub.org | server/src/bl/thingsMngr.js | getThingUserClaims | function getThingUserClaims(user, thing, isSuperAdministrator) {
if (!thing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 26);
let thingUserClaimsAndRights = {
read : thing.publicReadClaims,
change : thing.publicChangeClaims
};
if (user) {
thingUserClaimsAndRights.read = thingUserClaimsAndRights.read | thing.everyoneReadClaims;
thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thing.everyoneChangeClaims;
var thingUserRights = getThingUserRights(user._id, user.username, thing);
if (thingUserRights)
{
thingUserClaimsAndRights.read = thingUserClaimsAndRights.read | thingUserRights.userReadClaims;
thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thingUserRights.userChangeClaims;
}
if (isSuperAdministrator)
{
thingUserClaimsAndRights.read = thConstants.ThingUserReadClaims.AllClaims;
thingUserClaimsAndRights.change = thConstants.ThingUserChangeClaims.AllClaims;
}
}
return thingUserClaimsAndRights;
} | javascript | function getThingUserClaims(user, thing, isSuperAdministrator) {
if (!thing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 26);
let thingUserClaimsAndRights = {
read : thing.publicReadClaims,
change : thing.publicChangeClaims
};
if (user) {
thingUserClaimsAndRights.read = thingUserClaimsAndRights.read | thing.everyoneReadClaims;
thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thing.everyoneChangeClaims;
var thingUserRights = getThingUserRights(user._id, user.username, thing);
if (thingUserRights)
{
thingUserClaimsAndRights.read = thingUserClaimsAndRights.read | thingUserRights.userReadClaims;
thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thingUserRights.userChangeClaims;
}
if (isSuperAdministrator)
{
thingUserClaimsAndRights.read = thConstants.ThingUserReadClaims.AllClaims;
thingUserClaimsAndRights.change = thConstants.ThingUserChangeClaims.AllClaims;
}
}
return thingUserClaimsAndRights;
} | [
"function",
"getThingUserClaims",
"(",
"user",
",",
"thing",
",",
"isSuperAdministrator",
")",
"{",
"if",
"(",
"!",
"thing",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"INTERNAL_SERVER_ERROR",
",",
"\"Thing can't be null\"",
",",
"26",
")",
";",
"let",
"thingUserClaimsAndRights",
"=",
"{",
"read",
":",
"thing",
".",
"publicReadClaims",
",",
"change",
":",
"thing",
".",
"publicChangeClaims",
"}",
";",
"if",
"(",
"user",
")",
"{",
"thingUserClaimsAndRights",
".",
"read",
"=",
"thingUserClaimsAndRights",
".",
"read",
"|",
"thing",
".",
"everyoneReadClaims",
";",
"thingUserClaimsAndRights",
".",
"change",
"=",
"thingUserClaimsAndRights",
".",
"change",
"|",
"thing",
".",
"everyoneChangeClaims",
";",
"var",
"thingUserRights",
"=",
"getThingUserRights",
"(",
"user",
".",
"_id",
",",
"user",
".",
"username",
",",
"thing",
")",
";",
"if",
"(",
"thingUserRights",
")",
"{",
"thingUserClaimsAndRights",
".",
"read",
"=",
"thingUserClaimsAndRights",
".",
"read",
"|",
"thingUserRights",
".",
"userReadClaims",
";",
"thingUserClaimsAndRights",
".",
"change",
"=",
"thingUserClaimsAndRights",
".",
"change",
"|",
"thingUserRights",
".",
"userChangeClaims",
";",
"}",
"if",
"(",
"isSuperAdministrator",
")",
"{",
"thingUserClaimsAndRights",
".",
"read",
"=",
"thConstants",
".",
"ThingUserReadClaims",
".",
"AllClaims",
";",
"thingUserClaimsAndRights",
".",
"change",
"=",
"thConstants",
".",
"ThingUserChangeClaims",
".",
"AllClaims",
";",
"}",
"}",
"return",
"thingUserClaimsAndRights",
";",
"}"
] | All paths return to something. It never returns null except for exceptions The User may be null as anonymous. If User is anonymous returns Thing's PublicClaims | [
"All",
"paths",
"return",
"to",
"something",
".",
"It",
"never",
"returns",
"null",
"except",
"for",
"exceptions",
"The",
"User",
"may",
"be",
"null",
"as",
"anonymous",
".",
"If",
"User",
"is",
"anonymous",
"returns",
"Thing",
"s",
"PublicClaims"
] | b9a2e74bddebb80ff473001be93e19ef1578892a | https://github.com/cmcampione/thingshub.org/blob/b9a2e74bddebb80ff473001be93e19ef1578892a/server/src/bl/thingsMngr.js#L38-L67 |
51,883 | cmcampione/thingshub.org | server/src/bl/thingsMngr.js | getThing | async function getThing(user, thingId, deletedStatus, userRole, userStatus, userVisibility) {
if (!thingId)
throw new utils.ErrorCustom(httpStatusCodes.BAD_REQUEST, "Thing's Id not valid", 37);
let thing = await findThingById(thingId);
if (!thing)
{
// Returns httpStatusCodes.UNAUTHORIZED to Reset Some Malicious Logon Access
if (!user)
throw new utils.ErrorCustom(httpStatusCodes.UNAUTHORIZED, "Unauthorized user", 38);
throw new utils.ErrorCustom(httpStatusCodes.NOT_FOUND, "Thing not found", 39);
}
if (deletedStatus != thConstants.ThingDeletedStates.NoMatter && thing.deletedStatus != deletedStatus)
throw new utils.ErrorCustom(httpStatusCodes.BAD_REQUEST, "Thing's Deletedstatus not valid", 40);
if ((thing.publicReadClaims & thConstants.ThingUserReadClaims.AllClaims) != 0
|| (thing.publicChangeClaims & thConstants.ThingUserChangeClaims.AllClaims) != 0)
{
// This is a condition I do not remember why it was put on. I consider it important.
// At this time it is commented why when I try to assign a pos to Thing
// for an unnamed user who does not have a relationship with Thing the condition does not let me pass.
// if (user == null && userRole == ThingUserRoles.NoMatter && userStatus == ThingUserStates.NoMatter && userVisibility == thConstants.ThingUserVisibility.NoMatter)
return thing;
}
if (!user)
throw new utils.ErrorCustom(httpStatusCodes.UNAUTHORIZED, "Unauthorized user", 41);
// If User is Super Administrator returns Thing whatever filters(userRole) are passed as parameters
if (user.isSuperAdministrator)
return thing;
if ((thing.everyoneReadClaims & thConstants.ThingUserReadClaims.AllClaims) != 0
|| (thing.everyoneChangeClaims & thConstants.ThingUserChangeClaims.AllClaims) != 0)
return thing;
var thingUserRights = getThingUserRights(user._id, user.username, thing);
if (thingUserRights)
{
if (userStatus != thConstants.ThingUserStates.NoMatter && ((thingUserRights.userStatus & userStatus) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 42);
if (userRole != thConstants.ThingUserRoles.NoMatter && ((thingUserRights.userRole & userRole) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 43);
if (userVisibility != thConstants.ThingUserVisibility.NoMatter && ((thingUserRights.userVisibility & userVisibility) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 48);
return thing;
}
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 44);
} | javascript | async function getThing(user, thingId, deletedStatus, userRole, userStatus, userVisibility) {
if (!thingId)
throw new utils.ErrorCustom(httpStatusCodes.BAD_REQUEST, "Thing's Id not valid", 37);
let thing = await findThingById(thingId);
if (!thing)
{
// Returns httpStatusCodes.UNAUTHORIZED to Reset Some Malicious Logon Access
if (!user)
throw new utils.ErrorCustom(httpStatusCodes.UNAUTHORIZED, "Unauthorized user", 38);
throw new utils.ErrorCustom(httpStatusCodes.NOT_FOUND, "Thing not found", 39);
}
if (deletedStatus != thConstants.ThingDeletedStates.NoMatter && thing.deletedStatus != deletedStatus)
throw new utils.ErrorCustom(httpStatusCodes.BAD_REQUEST, "Thing's Deletedstatus not valid", 40);
if ((thing.publicReadClaims & thConstants.ThingUserReadClaims.AllClaims) != 0
|| (thing.publicChangeClaims & thConstants.ThingUserChangeClaims.AllClaims) != 0)
{
// This is a condition I do not remember why it was put on. I consider it important.
// At this time it is commented why when I try to assign a pos to Thing
// for an unnamed user who does not have a relationship with Thing the condition does not let me pass.
// if (user == null && userRole == ThingUserRoles.NoMatter && userStatus == ThingUserStates.NoMatter && userVisibility == thConstants.ThingUserVisibility.NoMatter)
return thing;
}
if (!user)
throw new utils.ErrorCustom(httpStatusCodes.UNAUTHORIZED, "Unauthorized user", 41);
// If User is Super Administrator returns Thing whatever filters(userRole) are passed as parameters
if (user.isSuperAdministrator)
return thing;
if ((thing.everyoneReadClaims & thConstants.ThingUserReadClaims.AllClaims) != 0
|| (thing.everyoneChangeClaims & thConstants.ThingUserChangeClaims.AllClaims) != 0)
return thing;
var thingUserRights = getThingUserRights(user._id, user.username, thing);
if (thingUserRights)
{
if (userStatus != thConstants.ThingUserStates.NoMatter && ((thingUserRights.userStatus & userStatus) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 42);
if (userRole != thConstants.ThingUserRoles.NoMatter && ((thingUserRights.userRole & userRole) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 43);
if (userVisibility != thConstants.ThingUserVisibility.NoMatter && ((thingUserRights.userVisibility & userVisibility) == 0))
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 48);
return thing;
}
throw new utils.ErrorCustom(httpStatusCodes.FORBIDDEN, "Unauthorized user", 44);
} | [
"async",
"function",
"getThing",
"(",
"user",
",",
"thingId",
",",
"deletedStatus",
",",
"userRole",
",",
"userStatus",
",",
"userVisibility",
")",
"{",
"if",
"(",
"!",
"thingId",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"BAD_REQUEST",
",",
"\"Thing's Id not valid\"",
",",
"37",
")",
";",
"let",
"thing",
"=",
"await",
"findThingById",
"(",
"thingId",
")",
";",
"if",
"(",
"!",
"thing",
")",
"{",
"// Returns httpStatusCodes.UNAUTHORIZED to Reset Some Malicious Logon Access",
"if",
"(",
"!",
"user",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"UNAUTHORIZED",
",",
"\"Unauthorized user\"",
",",
"38",
")",
";",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"NOT_FOUND",
",",
"\"Thing not found\"",
",",
"39",
")",
";",
"}",
"if",
"(",
"deletedStatus",
"!=",
"thConstants",
".",
"ThingDeletedStates",
".",
"NoMatter",
"&&",
"thing",
".",
"deletedStatus",
"!=",
"deletedStatus",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"BAD_REQUEST",
",",
"\"Thing's Deletedstatus not valid\"",
",",
"40",
")",
";",
"if",
"(",
"(",
"thing",
".",
"publicReadClaims",
"&",
"thConstants",
".",
"ThingUserReadClaims",
".",
"AllClaims",
")",
"!=",
"0",
"||",
"(",
"thing",
".",
"publicChangeClaims",
"&",
"thConstants",
".",
"ThingUserChangeClaims",
".",
"AllClaims",
")",
"!=",
"0",
")",
"{",
"// This is a condition I do not remember why it was put on. I consider it important.",
"// At this time it is commented why when I try to assign a pos to Thing",
"// for an unnamed user who does not have a relationship with Thing the condition does not let me pass.",
"// if (user == null && userRole == ThingUserRoles.NoMatter && userStatus == ThingUserStates.NoMatter && userVisibility == thConstants.ThingUserVisibility.NoMatter)",
"return",
"thing",
";",
"}",
"if",
"(",
"!",
"user",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"UNAUTHORIZED",
",",
"\"Unauthorized user\"",
",",
"41",
")",
";",
"// If User is Super Administrator returns Thing whatever filters(userRole) are passed as parameters",
"if",
"(",
"user",
".",
"isSuperAdministrator",
")",
"return",
"thing",
";",
"if",
"(",
"(",
"thing",
".",
"everyoneReadClaims",
"&",
"thConstants",
".",
"ThingUserReadClaims",
".",
"AllClaims",
")",
"!=",
"0",
"||",
"(",
"thing",
".",
"everyoneChangeClaims",
"&",
"thConstants",
".",
"ThingUserChangeClaims",
".",
"AllClaims",
")",
"!=",
"0",
")",
"return",
"thing",
";",
"var",
"thingUserRights",
"=",
"getThingUserRights",
"(",
"user",
".",
"_id",
",",
"user",
".",
"username",
",",
"thing",
")",
";",
"if",
"(",
"thingUserRights",
")",
"{",
"if",
"(",
"userStatus",
"!=",
"thConstants",
".",
"ThingUserStates",
".",
"NoMatter",
"&&",
"(",
"(",
"thingUserRights",
".",
"userStatus",
"&",
"userStatus",
")",
"==",
"0",
")",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"FORBIDDEN",
",",
"\"Unauthorized user\"",
",",
"42",
")",
";",
"if",
"(",
"userRole",
"!=",
"thConstants",
".",
"ThingUserRoles",
".",
"NoMatter",
"&&",
"(",
"(",
"thingUserRights",
".",
"userRole",
"&",
"userRole",
")",
"==",
"0",
")",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"FORBIDDEN",
",",
"\"Unauthorized user\"",
",",
"43",
")",
";",
"if",
"(",
"userVisibility",
"!=",
"thConstants",
".",
"ThingUserVisibility",
".",
"NoMatter",
"&&",
"(",
"(",
"thingUserRights",
".",
"userVisibility",
"&",
"userVisibility",
")",
"==",
"0",
")",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"FORBIDDEN",
",",
"\"Unauthorized user\"",
",",
"48",
")",
";",
"return",
"thing",
";",
"}",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"FORBIDDEN",
",",
"\"Unauthorized user\"",
",",
"44",
")",
";",
"}"
] | Not optimized using the CheckThingAccess function. It does not get optimized because staying so you have a capillary control of where it eventually snaps the error | [
"Not",
"optimized",
"using",
"the",
"CheckThingAccess",
"function",
".",
"It",
"does",
"not",
"get",
"optimized",
"because",
"staying",
"so",
"you",
"have",
"a",
"capillary",
"control",
"of",
"where",
"it",
"eventually",
"snaps",
"the",
"error"
] | b9a2e74bddebb80ff473001be93e19ef1578892a | https://github.com/cmcampione/thingshub.org/blob/b9a2e74bddebb80ff473001be93e19ef1578892a/server/src/bl/thingsMngr.js#L127-L181 |
51,884 | cmcampione/thingshub.org | server/src/bl/thingsMngr.js | getThingPosition | function getThingPosition(user, parentThing, childThing) {
if (!childThing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Child Thing can't be null", 29);
// If User is equal to null as it may be anonymous or is a SuperAdministrator who has no relationship with Thing
if (!user)
return null;
let userId = user._id;
let parentThingId = parentThing ? parentThing._id : null;
return childThing.parentsThingsIds.find(p => p.userId == userId && p.parentThingId == parentThingId);
} | javascript | function getThingPosition(user, parentThing, childThing) {
if (!childThing)
throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Child Thing can't be null", 29);
// If User is equal to null as it may be anonymous or is a SuperAdministrator who has no relationship with Thing
if (!user)
return null;
let userId = user._id;
let parentThingId = parentThing ? parentThing._id : null;
return childThing.parentsThingsIds.find(p => p.userId == userId && p.parentThingId == parentThingId);
} | [
"function",
"getThingPosition",
"(",
"user",
",",
"parentThing",
",",
"childThing",
")",
"{",
"if",
"(",
"!",
"childThing",
")",
"throw",
"new",
"utils",
".",
"ErrorCustom",
"(",
"httpStatusCodes",
".",
"INTERNAL_SERVER_ERROR",
",",
"\"Child Thing can't be null\"",
",",
"29",
")",
";",
"// If User is equal to null as it may be anonymous or is a SuperAdministrator who has no relationship with Thing",
"if",
"(",
"!",
"user",
")",
"return",
"null",
";",
"let",
"userId",
"=",
"user",
".",
"_id",
";",
"let",
"parentThingId",
"=",
"parentThing",
"?",
"parentThing",
".",
"_id",
":",
"null",
";",
"return",
"childThing",
".",
"parentsThingsIds",
".",
"find",
"(",
"p",
"=>",
"p",
".",
"userId",
"==",
"userId",
"&&",
"p",
".",
"parentThingId",
"==",
"parentThingId",
")",
";",
"}"
] | User may be null as it may be anonymous or is a SuperAdministrator who has no relationship with Thing It may return null for old Thing created before Position Management | [
"User",
"may",
"be",
"null",
"as",
"it",
"may",
"be",
"anonymous",
"or",
"is",
"a",
"SuperAdministrator",
"who",
"has",
"no",
"relationship",
"with",
"Thing",
"It",
"may",
"return",
"null",
"for",
"old",
"Thing",
"created",
"before",
"Position",
"Management"
] | b9a2e74bddebb80ff473001be93e19ef1578892a | https://github.com/cmcampione/thingshub.org/blob/b9a2e74bddebb80ff473001be93e19ef1578892a/server/src/bl/thingsMngr.js#L277-L290 |
51,885 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(signal, arg, emitter) {
var widget = this,
slot;
if (typeof emitter === 'undefined') emitter = this;
console.log("fire(" + signal + ")", arg);
if (signal.charAt(0) == '@') {
// This is a global signal.
slot = $$.statics("WTag");
if (slot) {
slot = slot.globalSlots[signal];
if (slot) {
slot[1].call(slot[0], arg, signal, emitter);
} else {
console.error(
"[WTag.fire] Nothing is binded on global signal \""
+ signal + "\"!"
);
}
}
}
if (signal.charAt(0) == '$') {
// Assign a value to a data.
this.data(signal.substr(1).trim(), arg);
}
else {
while (widget) {
slot = widget._slots[signal];
if (typeof slot === 'function') {
if (false !== slot.call(widget, arg, signal, emitter)) {
return;
}
}
widget = widget.parentWidget();
}
console.warning("Signal lost: " + signal + "!");
}
} | javascript | function(signal, arg, emitter) {
var widget = this,
slot;
if (typeof emitter === 'undefined') emitter = this;
console.log("fire(" + signal + ")", arg);
if (signal.charAt(0) == '@') {
// This is a global signal.
slot = $$.statics("WTag");
if (slot) {
slot = slot.globalSlots[signal];
if (slot) {
slot[1].call(slot[0], arg, signal, emitter);
} else {
console.error(
"[WTag.fire] Nothing is binded on global signal \""
+ signal + "\"!"
);
}
}
}
if (signal.charAt(0) == '$') {
// Assign a value to a data.
this.data(signal.substr(1).trim(), arg);
}
else {
while (widget) {
slot = widget._slots[signal];
if (typeof slot === 'function') {
if (false !== slot.call(widget, arg, signal, emitter)) {
return;
}
}
widget = widget.parentWidget();
}
console.warning("Signal lost: " + signal + "!");
}
} | [
"function",
"(",
"signal",
",",
"arg",
",",
"emitter",
")",
"{",
"var",
"widget",
"=",
"this",
",",
"slot",
";",
"if",
"(",
"typeof",
"emitter",
"===",
"'undefined'",
")",
"emitter",
"=",
"this",
";",
"console",
".",
"log",
"(",
"\"fire(\"",
"+",
"signal",
"+",
"\")\"",
",",
"arg",
")",
";",
"if",
"(",
"signal",
".",
"charAt",
"(",
"0",
")",
"==",
"'@'",
")",
"{",
"// This is a global signal.",
"slot",
"=",
"$$",
".",
"statics",
"(",
"\"WTag\"",
")",
";",
"if",
"(",
"slot",
")",
"{",
"slot",
"=",
"slot",
".",
"globalSlots",
"[",
"signal",
"]",
";",
"if",
"(",
"slot",
")",
"{",
"slot",
"[",
"1",
"]",
".",
"call",
"(",
"slot",
"[",
"0",
"]",
",",
"arg",
",",
"signal",
",",
"emitter",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"[WTag.fire] Nothing is binded on global signal \\\"\"",
"+",
"signal",
"+",
"\"\\\"!\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"signal",
".",
"charAt",
"(",
"0",
")",
"==",
"'$'",
")",
"{",
"// Assign a value to a data.",
"this",
".",
"data",
"(",
"signal",
".",
"substr",
"(",
"1",
")",
".",
"trim",
"(",
")",
",",
"arg",
")",
";",
"}",
"else",
"{",
"while",
"(",
"widget",
")",
"{",
"slot",
"=",
"widget",
".",
"_slots",
"[",
"signal",
"]",
";",
"if",
"(",
"typeof",
"slot",
"===",
"'function'",
")",
"{",
"if",
"(",
"false",
"!==",
"slot",
".",
"call",
"(",
"widget",
",",
"arg",
",",
"signal",
",",
"emitter",
")",
")",
"{",
"return",
";",
"}",
"}",
"widget",
"=",
"widget",
".",
"parentWidget",
"(",
")",
";",
"}",
"console",
".",
"warning",
"(",
"\"Signal lost: \"",
"+",
"signal",
"+",
"\"!\"",
")",
";",
"}",
"}"
] | Fire a "signal" up to the parents widgets.
If a slot returns false, the event is fired up to the parents.
@param signal Name of the signal to trigger.
@param arg Optional argument to sent with this signal.
@param emitter Optional reference to the signal's emitter.
@memberof WTag | [
"Fire",
"a",
"signal",
"up",
"to",
"the",
"parents",
"widgets",
".",
"If",
"a",
"slot",
"returns",
"false",
"the",
"event",
"is",
"fired",
"up",
"to",
"the",
"parents",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L89-L125 |
|
51,886 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(signal, arg) {
var slot = this._slots[signal];
if (slot) {
slot.call(this, arg, signal);
return true;
}
return false;
} | javascript | function(signal, arg) {
var slot = this._slots[signal];
if (slot) {
slot.call(this, arg, signal);
return true;
}
return false;
} | [
"function",
"(",
"signal",
",",
"arg",
")",
"{",
"var",
"slot",
"=",
"this",
".",
"_slots",
"[",
"signal",
"]",
";",
"if",
"(",
"slot",
")",
"{",
"slot",
".",
"call",
"(",
"this",
",",
"arg",
",",
"signal",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Call the slot mapped to the "signal".
@param signal : name of the signal on which this object may be registred.
@param arg : argument to pass to the registred slot.
@memberof WTag | [
"Call",
"the",
"slot",
"mapped",
"to",
"the",
"signal",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L161-L168 |
|
51,887 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function() {
var element = this._element;
while (element.parentNode) {
element = element.parentNode;
if (element.$widget) {
return element.$widget;
}
}
return null;
} | javascript | function() {
var element = this._element;
while (element.parentNode) {
element = element.parentNode;
if (element.$widget) {
return element.$widget;
}
}
return null;
} | [
"function",
"(",
")",
"{",
"var",
"element",
"=",
"this",
".",
"_element",
";",
"while",
"(",
"element",
".",
"parentNode",
")",
"{",
"element",
"=",
"element",
".",
"parentNode",
";",
"if",
"(",
"element",
".",
"$widget",
")",
"{",
"return",
"element",
".",
"$widget",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get the parent widget.
@memberof WTag | [
"Get",
"the",
"parent",
"widget",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L182-L191 |
|
51,888 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(id) {
if (!$$.App) $$.App = this;
if (!$$.App._languages) {
// Initialise localization.
var languages = [],
langStyle = document.createElement("style"),
children = document.querySelectorAll("[lang]");
document.head.appendChild(langStyle);
$$.App._langStyle = langStyle;
for (var i = 0 ; i < children.length ; i++) {
var child = children[i];
lang = child.getAttribute("lang");
found = false;
for (k = 0 ; k < languages.length ; k++) {
if (languages[k] == lang) {
found = true;
break;
}
}
if (!found) {
languages.push(lang);
}
}
$$.App._languages = languages;
}
var that = this, lang, k, found, first, txt;
languages = $$.App._languages;
if (id === undefined) {
// Return current language.
lang = $$.lang(); // localStorage.getItem("wtag-language");
if (!lang) {
lang = navigator.language || navigator.browserLanguage || "fr";
lang = lang.substr(0, 2);
}
$$.lang(lang);
// localStorage.setItem("wtag-language", lang);
return lang;
} else {
// Set current language and display localized elements.
found = false;
for (k = 0 ; k < languages.length ; k++) {
if (languages[k] == id) {
found = true;
break;
}
}
if (!found) {
id = languages[0];
}
txt = "";
first = true;
for (k = 0 ; k < languages.length ; k++) {
lang = languages[k];
if (lang != id) {
if (first) {
first = false;
} else {
txt += ",";
}
txt += "[lang=" + lang + "]";
}
}
$$.App._langStyle.textContent = txt + "{display: none}";
$$.lang(id);
//localStorage.setItem("wtag-language", id);
}
} | javascript | function(id) {
if (!$$.App) $$.App = this;
if (!$$.App._languages) {
// Initialise localization.
var languages = [],
langStyle = document.createElement("style"),
children = document.querySelectorAll("[lang]");
document.head.appendChild(langStyle);
$$.App._langStyle = langStyle;
for (var i = 0 ; i < children.length ; i++) {
var child = children[i];
lang = child.getAttribute("lang");
found = false;
for (k = 0 ; k < languages.length ; k++) {
if (languages[k] == lang) {
found = true;
break;
}
}
if (!found) {
languages.push(lang);
}
}
$$.App._languages = languages;
}
var that = this, lang, k, found, first, txt;
languages = $$.App._languages;
if (id === undefined) {
// Return current language.
lang = $$.lang(); // localStorage.getItem("wtag-language");
if (!lang) {
lang = navigator.language || navigator.browserLanguage || "fr";
lang = lang.substr(0, 2);
}
$$.lang(lang);
// localStorage.setItem("wtag-language", lang);
return lang;
} else {
// Set current language and display localized elements.
found = false;
for (k = 0 ; k < languages.length ; k++) {
if (languages[k] == id) {
found = true;
break;
}
}
if (!found) {
id = languages[0];
}
txt = "";
first = true;
for (k = 0 ; k < languages.length ; k++) {
lang = languages[k];
if (lang != id) {
if (first) {
first = false;
} else {
txt += ",";
}
txt += "[lang=" + lang + "]";
}
}
$$.App._langStyle.textContent = txt + "{display: none}";
$$.lang(id);
//localStorage.setItem("wtag-language", id);
}
} | [
"function",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"$$",
".",
"App",
")",
"$$",
".",
"App",
"=",
"this",
";",
"if",
"(",
"!",
"$$",
".",
"App",
".",
"_languages",
")",
"{",
"// Initialise localization.",
"var",
"languages",
"=",
"[",
"]",
",",
"langStyle",
"=",
"document",
".",
"createElement",
"(",
"\"style\"",
")",
",",
"children",
"=",
"document",
".",
"querySelectorAll",
"(",
"\"[lang]\"",
")",
";",
"document",
".",
"head",
".",
"appendChild",
"(",
"langStyle",
")",
";",
"$$",
".",
"App",
".",
"_langStyle",
"=",
"langStyle",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"child",
"=",
"children",
"[",
"i",
"]",
";",
"lang",
"=",
"child",
".",
"getAttribute",
"(",
"\"lang\"",
")",
";",
"found",
"=",
"false",
";",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"languages",
".",
"length",
";",
"k",
"++",
")",
"{",
"if",
"(",
"languages",
"[",
"k",
"]",
"==",
"lang",
")",
"{",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"found",
")",
"{",
"languages",
".",
"push",
"(",
"lang",
")",
";",
"}",
"}",
"$$",
".",
"App",
".",
"_languages",
"=",
"languages",
";",
"}",
"var",
"that",
"=",
"this",
",",
"lang",
",",
"k",
",",
"found",
",",
"first",
",",
"txt",
";",
"languages",
"=",
"$$",
".",
"App",
".",
"_languages",
";",
"if",
"(",
"id",
"===",
"undefined",
")",
"{",
"// Return current language.",
"lang",
"=",
"$$",
".",
"lang",
"(",
")",
";",
"// localStorage.getItem(\"wtag-language\");",
"if",
"(",
"!",
"lang",
")",
"{",
"lang",
"=",
"navigator",
".",
"language",
"||",
"navigator",
".",
"browserLanguage",
"||",
"\"fr\"",
";",
"lang",
"=",
"lang",
".",
"substr",
"(",
"0",
",",
"2",
")",
";",
"}",
"$$",
".",
"lang",
"(",
"lang",
")",
";",
"// localStorage.setItem(\"wtag-language\", lang);",
"return",
"lang",
";",
"}",
"else",
"{",
"// Set current language and display localized elements.",
"found",
"=",
"false",
";",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"languages",
".",
"length",
";",
"k",
"++",
")",
"{",
"if",
"(",
"languages",
"[",
"k",
"]",
"==",
"id",
")",
"{",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"found",
")",
"{",
"id",
"=",
"languages",
"[",
"0",
"]",
";",
"}",
"txt",
"=",
"\"\"",
";",
"first",
"=",
"true",
";",
"for",
"(",
"k",
"=",
"0",
";",
"k",
"<",
"languages",
".",
"length",
";",
"k",
"++",
")",
"{",
"lang",
"=",
"languages",
"[",
"k",
"]",
";",
"if",
"(",
"lang",
"!=",
"id",
")",
"{",
"if",
"(",
"first",
")",
"{",
"first",
"=",
"false",
";",
"}",
"else",
"{",
"txt",
"+=",
"\",\"",
";",
"}",
"txt",
"+=",
"\"[lang=\"",
"+",
"lang",
"+",
"\"]\"",
";",
"}",
"}",
"$$",
".",
"App",
".",
"_langStyle",
".",
"textContent",
"=",
"txt",
"+",
"\"{display: none}\"",
";",
"$$",
".",
"lang",
"(",
"id",
")",
";",
"//localStorage.setItem(\"wtag-language\", id);",
"}",
"}"
] | Return or set the current language.
@memberof WTag | [
"Return",
"or",
"set",
"the",
"current",
"language",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L197-L264 |
|
51,889 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(name) {
if (typeof name === 'undefined') return this._element;
var e = this._element.querySelector("[name='" + name + "']");
if (!e) {
throw new Error(
"[WTag.get] Can't find child [name=\""
+ name + "\"] in element \"" + this._id + "\"!"
);
}
return e;
} | javascript | function(name) {
if (typeof name === 'undefined') return this._element;
var e = this._element.querySelector("[name='" + name + "']");
if (!e) {
throw new Error(
"[WTag.get] Can't find child [name=\""
+ name + "\"] in element \"" + this._id + "\"!"
);
}
return e;
} | [
"function",
"(",
"name",
")",
"{",
"if",
"(",
"typeof",
"name",
"===",
"'undefined'",
")",
"return",
"this",
".",
"_element",
";",
"var",
"e",
"=",
"this",
".",
"_element",
".",
"querySelector",
"(",
"\"[name='\"",
"+",
"name",
"+",
"\"']\"",
")",
";",
"if",
"(",
"!",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"[WTag.get] Can't find child [name=\\\"\"",
"+",
"name",
"+",
"\"\\\"] in element \\\"\"",
"+",
"this",
".",
"_id",
"+",
"\"\\\"!\"",
")",
";",
"}",
"return",
"e",
";",
"}"
] | Get an element with this `name` among this element's
children.
@memberof WTag | [
"Get",
"an",
"element",
"with",
"this",
"name",
"among",
"this",
"element",
"s",
"children",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L271-L281 |
|
51,890 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(vars, slot, getter) {
if (!Array.isArray(vars)) {
vars = [vars];
}
if (vars.length == 0) return null;
if (typeof slot === 'string') {
slot = this[slot];
}
if (typeof getter === 'undefined') {
getter = function() {
return this.data(vars[0]);
};
}
var listener = {
obj: this,
slot: slot,
getter: getter
};
vars.forEach(
function(name) {
var data = this.findDataBinding(name);
data[1].push(listener);
}, this
);
return listener;
} | javascript | function(vars, slot, getter) {
if (!Array.isArray(vars)) {
vars = [vars];
}
if (vars.length == 0) return null;
if (typeof slot === 'string') {
slot = this[slot];
}
if (typeof getter === 'undefined') {
getter = function() {
return this.data(vars[0]);
};
}
var listener = {
obj: this,
slot: slot,
getter: getter
};
vars.forEach(
function(name) {
var data = this.findDataBinding(name);
data[1].push(listener);
}, this
);
return listener;
} | [
"function",
"(",
"vars",
",",
"slot",
",",
"getter",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"vars",
")",
")",
"{",
"vars",
"=",
"[",
"vars",
"]",
";",
"}",
"if",
"(",
"vars",
".",
"length",
"==",
"0",
")",
"return",
"null",
";",
"if",
"(",
"typeof",
"slot",
"===",
"'string'",
")",
"{",
"slot",
"=",
"this",
"[",
"slot",
"]",
";",
"}",
"if",
"(",
"typeof",
"getter",
"===",
"'undefined'",
")",
"{",
"getter",
"=",
"function",
"(",
")",
"{",
"return",
"this",
".",
"data",
"(",
"vars",
"[",
"0",
"]",
")",
";",
"}",
";",
"}",
"var",
"listener",
"=",
"{",
"obj",
":",
"this",
",",
"slot",
":",
"slot",
",",
"getter",
":",
"getter",
"}",
";",
"vars",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"data",
"=",
"this",
".",
"findDataBinding",
"(",
"name",
")",
";",
"data",
"[",
"1",
"]",
".",
"push",
"(",
"listener",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"listener",
";",
"}"
] | Bind to data updates.
When the data changed, the `slot` is call with `this` object
and the data's value as unique argument.
@param {array} vars array of names of data to watch.
@param {function} slot function to call when data changed.
@param {string} slot name of the method to call when data changed.
@param {function} getter function getting the binded value.
@return {object} the listener you can give to `unbindData`.
@memberof WTag | [
"Bind",
"to",
"data",
"updates",
".",
"When",
"the",
"data",
"changed",
"the",
"slot",
"is",
"call",
"with",
"this",
"object",
"and",
"the",
"data",
"s",
"value",
"as",
"unique",
"argument",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L398-L423 |
|
51,891 | tolokoban/ToloFrameWork | ker/cls/WTag.js | function(vars, listener) {
if (!Array.isArray(vars)) {
vars = [vars];
}
if (vars.length == 0) return null;
var found = false;
vars.forEach(
function(name) {
var data = this.findDataBinding(name);
var i, target;
for (i = 0 ; i < data[1].length ; i++) {
target = data[1][i];
if (listener === target) {
data[1].splice(i, 1);
found = true;
return;
}
}
}, this
);
return found;
} | javascript | function(vars, listener) {
if (!Array.isArray(vars)) {
vars = [vars];
}
if (vars.length == 0) return null;
var found = false;
vars.forEach(
function(name) {
var data = this.findDataBinding(name);
var i, target;
for (i = 0 ; i < data[1].length ; i++) {
target = data[1][i];
if (listener === target) {
data[1].splice(i, 1);
found = true;
return;
}
}
}, this
);
return found;
} | [
"function",
"(",
"vars",
",",
"listener",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"vars",
")",
")",
"{",
"vars",
"=",
"[",
"vars",
"]",
";",
"}",
"if",
"(",
"vars",
".",
"length",
"==",
"0",
")",
"return",
"null",
";",
"var",
"found",
"=",
"false",
";",
"vars",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"data",
"=",
"this",
".",
"findDataBinding",
"(",
"name",
")",
";",
"var",
"i",
",",
"target",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"data",
"[",
"1",
"]",
".",
"length",
";",
"i",
"++",
")",
"{",
"target",
"=",
"data",
"[",
"1",
"]",
"[",
"i",
"]",
";",
"if",
"(",
"listener",
"===",
"target",
")",
"{",
"data",
"[",
"1",
"]",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"found",
"=",
"true",
";",
"return",
";",
"}",
"}",
"}",
",",
"this",
")",
";",
"return",
"found",
";",
"}"
] | Detach this object from data binding.
@param {array} vars array of names of data to watch.
@param {object} listner the listener to remove.
@memberof WTag | [
"Detach",
"this",
"object",
"from",
"data",
"binding",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/cls/WTag.js#L432-L453 |
|
51,892 | jmjuanes/minsql | lib/query/where.js | QueryWhere | function QueryWhere(data)
{
//Initialize the string
var sql = '';
//Check the type
if(typeof data === 'string')
{
//Return the where
return data;
}
//Get all data
for(var key in data)
{
//Save data value
var value = data[key];
//Check the data type
if(typeof value === 'string' || value instanceof String)
{
//Add the quotes
value = '"' + value + '"';
}
//Check if is necessary add the AND
if(sql !== '')
{
//Add the AND
sql = sql + ' AND ';
}
//Add the key=value
sql = sql + key + '=' + value;
}
//Return the string
return sql;
} | javascript | function QueryWhere(data)
{
//Initialize the string
var sql = '';
//Check the type
if(typeof data === 'string')
{
//Return the where
return data;
}
//Get all data
for(var key in data)
{
//Save data value
var value = data[key];
//Check the data type
if(typeof value === 'string' || value instanceof String)
{
//Add the quotes
value = '"' + value + '"';
}
//Check if is necessary add the AND
if(sql !== '')
{
//Add the AND
sql = sql + ' AND ';
}
//Add the key=value
sql = sql + key + '=' + value;
}
//Return the string
return sql;
} | [
"function",
"QueryWhere",
"(",
"data",
")",
"{",
"//Initialize the string\r",
"var",
"sql",
"=",
"''",
";",
"//Check the type\r",
"if",
"(",
"typeof",
"data",
"===",
"'string'",
")",
"{",
"//Return the where\r",
"return",
"data",
";",
"}",
"//Get all data\r",
"for",
"(",
"var",
"key",
"in",
"data",
")",
"{",
"//Save data value\r",
"var",
"value",
"=",
"data",
"[",
"key",
"]",
";",
"//Check the data type\r",
"if",
"(",
"typeof",
"value",
"===",
"'string'",
"||",
"value",
"instanceof",
"String",
")",
"{",
"//Add the quotes\r",
"value",
"=",
"'\"'",
"+",
"value",
"+",
"'\"'",
";",
"}",
"//Check if is necessary add the AND\r",
"if",
"(",
"sql",
"!==",
"''",
")",
"{",
"//Add the AND\r",
"sql",
"=",
"sql",
"+",
"' AND '",
";",
"}",
"//Add the key=value\r",
"sql",
"=",
"sql",
"+",
"key",
"+",
"'='",
"+",
"value",
";",
"}",
"//Return the string\r",
"return",
"sql",
";",
"}"
] | Query String Where function | [
"Query",
"String",
"Where",
"function"
] | 80eddd97e858545997b30e3c9bc067d5fc2df5a0 | https://github.com/jmjuanes/minsql/blob/80eddd97e858545997b30e3c9bc067d5fc2df5a0/lib/query/where.js#L2-L40 |
51,893 | Nazariglez/perenquen | lib/pixi/src/filters/rgb/RGBSplitFilter.js | RGBSplitFilter | function RGBSplitFilter()
{
core.AbstractFilter.call(this,
// vertex shader
null,
// fragment shader
fs.readFileSync(__dirname + '/rgbSplit.frag', 'utf8'),
// custom uniforms
{
red: { type: 'v2', value: { x: 20, y: 20 } },
green: { type: 'v2', value: { x: -20, y: 20 } },
blue: { type: 'v2', value: { x: 20, y: -20 } },
dimensions: { type: '4fv', value: [0, 0, 0, 0] }
}
);
} | javascript | function RGBSplitFilter()
{
core.AbstractFilter.call(this,
// vertex shader
null,
// fragment shader
fs.readFileSync(__dirname + '/rgbSplit.frag', 'utf8'),
// custom uniforms
{
red: { type: 'v2', value: { x: 20, y: 20 } },
green: { type: 'v2', value: { x: -20, y: 20 } },
blue: { type: 'v2', value: { x: 20, y: -20 } },
dimensions: { type: '4fv', value: [0, 0, 0, 0] }
}
);
} | [
"function",
"RGBSplitFilter",
"(",
")",
"{",
"core",
".",
"AbstractFilter",
".",
"call",
"(",
"this",
",",
"// vertex shader",
"null",
",",
"// fragment shader",
"fs",
".",
"readFileSync",
"(",
"__dirname",
"+",
"'/rgbSplit.frag'",
",",
"'utf8'",
")",
",",
"// custom uniforms",
"{",
"red",
":",
"{",
"type",
":",
"'v2'",
",",
"value",
":",
"{",
"x",
":",
"20",
",",
"y",
":",
"20",
"}",
"}",
",",
"green",
":",
"{",
"type",
":",
"'v2'",
",",
"value",
":",
"{",
"x",
":",
"-",
"20",
",",
"y",
":",
"20",
"}",
"}",
",",
"blue",
":",
"{",
"type",
":",
"'v2'",
",",
"value",
":",
"{",
"x",
":",
"20",
",",
"y",
":",
"-",
"20",
"}",
"}",
",",
"dimensions",
":",
"{",
"type",
":",
"'4fv'",
",",
"value",
":",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
"}",
"}",
")",
";",
"}"
] | An RGB Split Filter.
@class
@extends AbstractFilter
@namespace PIXI | [
"An",
"RGB",
"Split",
"Filter",
"."
] | e023964d05afeefebdcac4e2044819fdfa3899ae | https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/filters/rgb/RGBSplitFilter.js#L12-L27 |
51,894 | Tennu/tennu-plugins | lib/errors.js | NoSuchPlugin | function NoSuchPlugin (message, name, paths) {
UnmetDependency.call(this, message);
this.name = name;
this.paths = paths;
} | javascript | function NoSuchPlugin (message, name, paths) {
UnmetDependency.call(this, message);
this.name = name;
this.paths = paths;
} | [
"function",
"NoSuchPlugin",
"(",
"message",
",",
"name",
",",
"paths",
")",
"{",
"UnmetDependency",
".",
"call",
"(",
"this",
",",
"message",
")",
";",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"paths",
"=",
"paths",
";",
"}"
] | Thrown when a module cannot be found. | [
"Thrown",
"when",
"a",
"module",
"cannot",
"be",
"found",
"."
] | 4d93df08514e9ccabf71a907e785d67cebfc9755 | https://github.com/Tennu/tennu-plugins/blob/4d93df08514e9ccabf71a907e785d67cebfc9755/lib/errors.js#L11-L15 |
51,895 | Tennu/tennu-plugins | lib/errors.js | PluginInitializationError | function PluginInitializationError (message, module) {
this.message = message;
this.stack = new Error().stack;
this.module = module;
} | javascript | function PluginInitializationError (message, module) {
this.message = message;
this.stack = new Error().stack;
this.module = module;
} | [
"function",
"PluginInitializationError",
"(",
"message",
",",
"module",
")",
"{",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"stack",
"=",
"new",
"Error",
"(",
")",
".",
"stack",
";",
"this",
".",
"module",
"=",
"module",
";",
"}"
] | Thrown when a module cannot be initialized. | [
"Thrown",
"when",
"a",
"module",
"cannot",
"be",
"initialized",
"."
] | 4d93df08514e9ccabf71a907e785d67cebfc9755 | https://github.com/Tennu/tennu-plugins/blob/4d93df08514e9ccabf71a907e785d67cebfc9755/lib/errors.js#L39-L43 |
51,896 | chanoch/simple-react-router | src/Configuration.js | instantiateDrivers | function instantiateDrivers(config, defaultDriverInstance) {
config.actionConfigs.forEach(action => {
action.driverInstance=action.driver?action.driver():defaultDriverInstance;
});
return config;
} | javascript | function instantiateDrivers(config, defaultDriverInstance) {
config.actionConfigs.forEach(action => {
action.driverInstance=action.driver?action.driver():defaultDriverInstance;
});
return config;
} | [
"function",
"instantiateDrivers",
"(",
"config",
",",
"defaultDriverInstance",
")",
"{",
"config",
".",
"actionConfigs",
".",
"forEach",
"(",
"action",
"=>",
"{",
"action",
".",
"driverInstance",
"=",
"action",
".",
"driver",
"?",
"action",
".",
"driver",
"(",
")",
":",
"defaultDriverInstance",
";",
"}",
")",
";",
"return",
"config",
";",
"}"
] | Instantiate the driver for each configuration. If no driver has been specified,
this will provide the config with a default driver.
The default driver is usually a null driver - which has no impact. | [
"Instantiate",
"the",
"driver",
"for",
"each",
"configuration",
".",
"If",
"no",
"driver",
"has",
"been",
"specified",
"this",
"will",
"provide",
"the",
"config",
"with",
"a",
"default",
"driver",
"."
] | 3c71feeeb039111f33c934257732e2ea6ddde9ff | https://github.com/chanoch/simple-react-router/blob/3c71feeeb039111f33c934257732e2ea6ddde9ff/src/Configuration.js#L109-L114 |
51,897 | chanoch/simple-react-router | src/Configuration.js | initEnhancers | function initEnhancers(routes) {
invariant(routes.filter(actionConfig => !actionConfig.driverInstance).length===0, 'Routes must have instantiated drivers');
return routes
.filter(actionConfig => actionConfig.driverInstance.middleware)
.map(actionConfig => actionConfig.driverInstance.middleware());
} | javascript | function initEnhancers(routes) {
invariant(routes.filter(actionConfig => !actionConfig.driverInstance).length===0, 'Routes must have instantiated drivers');
return routes
.filter(actionConfig => actionConfig.driverInstance.middleware)
.map(actionConfig => actionConfig.driverInstance.middleware());
} | [
"function",
"initEnhancers",
"(",
"routes",
")",
"{",
"invariant",
"(",
"routes",
".",
"filter",
"(",
"actionConfig",
"=>",
"!",
"actionConfig",
".",
"driverInstance",
")",
".",
"length",
"===",
"0",
",",
"'Routes must have instantiated drivers'",
")",
";",
"return",
"routes",
".",
"filter",
"(",
"actionConfig",
"=>",
"actionConfig",
".",
"driverInstance",
".",
"middleware",
")",
".",
"map",
"(",
"actionConfig",
"=>",
"actionConfig",
".",
"driverInstance",
".",
"middleware",
"(",
")",
")",
";",
"}"
] | Get a list of action configurations which have a middleware defined and
return an array of those redux state enhancers functions
@param {ActionConfig} actionConfigs | [
"Get",
"a",
"list",
"of",
"action",
"configurations",
"which",
"have",
"a",
"middleware",
"defined",
"and",
"return",
"an",
"array",
"of",
"those",
"redux",
"state",
"enhancers",
"functions"
] | 3c71feeeb039111f33c934257732e2ea6ddde9ff | https://github.com/chanoch/simple-react-router/blob/3c71feeeb039111f33c934257732e2ea6ddde9ff/src/Configuration.js#L142-L148 |
51,898 | jtanx/ctagz | ctagz.js | findCTagsFile | function findCTagsFile(searchPath, tagFilePattern = '{.,}tags') {
const ctagsFinder = function ctagsFinder(tagPath) {
console.error(`ctagz: Searching ${tagPath}`)
return fs.readdirAsync(tagPath).then(files => {
const matched = files.filter(minimatch.filter(tagFilePattern)).sort()
const ret = !matched ? Promise.resolve(null) :
Promise.reduce(matched, (acc, match) => {
if (acc) {
return acc
}
const matchPath = path.join(tagPath, match)
return fs.statAsync(matchPath).then(stats => {
if (!stats.isFile()) {
return null
}
return fs.openAsync(matchPath, 'r').then(fd => new CTags(matchPath, fd))
.catch(() => null)
})
}, null)
return ret.then(result => {
const newTagPath = path.dirname(tagPath)
if (!result && newTagPath !== tagPath) {
return ctagsFinder(newTagPath)
}
return result
})
})
}
let tagPath = path.resolve(searchPath)
return fs.statAsync(tagPath).then(stats => {
if (stats.isFile()) {
tagPath = path.dirname(tagPath)
}
return ctagsFinder(tagPath)
})
} | javascript | function findCTagsFile(searchPath, tagFilePattern = '{.,}tags') {
const ctagsFinder = function ctagsFinder(tagPath) {
console.error(`ctagz: Searching ${tagPath}`)
return fs.readdirAsync(tagPath).then(files => {
const matched = files.filter(minimatch.filter(tagFilePattern)).sort()
const ret = !matched ? Promise.resolve(null) :
Promise.reduce(matched, (acc, match) => {
if (acc) {
return acc
}
const matchPath = path.join(tagPath, match)
return fs.statAsync(matchPath).then(stats => {
if (!stats.isFile()) {
return null
}
return fs.openAsync(matchPath, 'r').then(fd => new CTags(matchPath, fd))
.catch(() => null)
})
}, null)
return ret.then(result => {
const newTagPath = path.dirname(tagPath)
if (!result && newTagPath !== tagPath) {
return ctagsFinder(newTagPath)
}
return result
})
})
}
let tagPath = path.resolve(searchPath)
return fs.statAsync(tagPath).then(stats => {
if (stats.isFile()) {
tagPath = path.dirname(tagPath)
}
return ctagsFinder(tagPath)
})
} | [
"function",
"findCTagsFile",
"(",
"searchPath",
",",
"tagFilePattern",
"=",
"'{.,}tags'",
")",
"{",
"const",
"ctagsFinder",
"=",
"function",
"ctagsFinder",
"(",
"tagPath",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"tagPath",
"}",
"`",
")",
"return",
"fs",
".",
"readdirAsync",
"(",
"tagPath",
")",
".",
"then",
"(",
"files",
"=>",
"{",
"const",
"matched",
"=",
"files",
".",
"filter",
"(",
"minimatch",
".",
"filter",
"(",
"tagFilePattern",
")",
")",
".",
"sort",
"(",
")",
"const",
"ret",
"=",
"!",
"matched",
"?",
"Promise",
".",
"resolve",
"(",
"null",
")",
":",
"Promise",
".",
"reduce",
"(",
"matched",
",",
"(",
"acc",
",",
"match",
")",
"=>",
"{",
"if",
"(",
"acc",
")",
"{",
"return",
"acc",
"}",
"const",
"matchPath",
"=",
"path",
".",
"join",
"(",
"tagPath",
",",
"match",
")",
"return",
"fs",
".",
"statAsync",
"(",
"matchPath",
")",
".",
"then",
"(",
"stats",
"=>",
"{",
"if",
"(",
"!",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"return",
"null",
"}",
"return",
"fs",
".",
"openAsync",
"(",
"matchPath",
",",
"'r'",
")",
".",
"then",
"(",
"fd",
"=>",
"new",
"CTags",
"(",
"matchPath",
",",
"fd",
")",
")",
".",
"catch",
"(",
"(",
")",
"=>",
"null",
")",
"}",
")",
"}",
",",
"null",
")",
"return",
"ret",
".",
"then",
"(",
"result",
"=>",
"{",
"const",
"newTagPath",
"=",
"path",
".",
"dirname",
"(",
"tagPath",
")",
"if",
"(",
"!",
"result",
"&&",
"newTagPath",
"!==",
"tagPath",
")",
"{",
"return",
"ctagsFinder",
"(",
"newTagPath",
")",
"}",
"return",
"result",
"}",
")",
"}",
")",
"}",
"let",
"tagPath",
"=",
"path",
".",
"resolve",
"(",
"searchPath",
")",
"return",
"fs",
".",
"statAsync",
"(",
"tagPath",
")",
".",
"then",
"(",
"stats",
"=>",
"{",
"if",
"(",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"tagPath",
"=",
"path",
".",
"dirname",
"(",
"tagPath",
")",
"}",
"return",
"ctagsFinder",
"(",
"tagPath",
")",
"}",
")",
"}"
] | Finds the CTags file from the specified search path and pattern
@param {string} searchPath The path to search. This may either be a
file or directory. If a file is passed,
its directory is searched. If the tag file
is not found, its parent directories are
then searched.
@param {string} tagFilePattern The search pattern to use when searching
for the tag file. This pattern can be
anything that the minimatch package
supports. However, if more than one file
matches, the results are sorted, and only
the first file is used as the tag file.
@return {any[]} An new CTags instance.
The caller call destroy() when finished with it. | [
"Finds",
"the",
"CTags",
"file",
"from",
"the",
"specified",
"search",
"path",
"and",
"pattern"
] | 9f9da9c578c78ba2b3b869ea3cfe465d50681740 | https://github.com/jtanx/ctagz/blob/9f9da9c578c78ba2b3b869ea3cfe465d50681740/ctagz.js#L444-L482 |
51,899 | jtanx/ctagz | ctagz.js | findCTagsBSearch | function findCTagsBSearch(searchPath, tag, ignoreCase = false, tagFilePattern = '{.,}tags') {
const ctags = findCTagsFile(searchPath, tagFilePattern)
.disposer(tags => {
if (tags) {
tags.destroy()
}
})
return Promise.using(ctags, tags => {
if (tags) {
return tags.init()
.then(() => tags.findBinary(tag, ignoreCase))
.then(result => ({ tagsFile: tags.tagsFile, results: result }))
}
return { tagsFile: '', results: [] }
})
} | javascript | function findCTagsBSearch(searchPath, tag, ignoreCase = false, tagFilePattern = '{.,}tags') {
const ctags = findCTagsFile(searchPath, tagFilePattern)
.disposer(tags => {
if (tags) {
tags.destroy()
}
})
return Promise.using(ctags, tags => {
if (tags) {
return tags.init()
.then(() => tags.findBinary(tag, ignoreCase))
.then(result => ({ tagsFile: tags.tagsFile, results: result }))
}
return { tagsFile: '', results: [] }
})
} | [
"function",
"findCTagsBSearch",
"(",
"searchPath",
",",
"tag",
",",
"ignoreCase",
"=",
"false",
",",
"tagFilePattern",
"=",
"'{.,}tags'",
")",
"{",
"const",
"ctags",
"=",
"findCTagsFile",
"(",
"searchPath",
",",
"tagFilePattern",
")",
".",
"disposer",
"(",
"tags",
"=>",
"{",
"if",
"(",
"tags",
")",
"{",
"tags",
".",
"destroy",
"(",
")",
"}",
"}",
")",
"return",
"Promise",
".",
"using",
"(",
"ctags",
",",
"tags",
"=>",
"{",
"if",
"(",
"tags",
")",
"{",
"return",
"tags",
".",
"init",
"(",
")",
".",
"then",
"(",
"(",
")",
"=>",
"tags",
".",
"findBinary",
"(",
"tag",
",",
"ignoreCase",
")",
")",
".",
"then",
"(",
"result",
"=>",
"(",
"{",
"tagsFile",
":",
"tags",
".",
"tagsFile",
",",
"results",
":",
"result",
"}",
")",
")",
"}",
"return",
"{",
"tagsFile",
":",
"''",
",",
"results",
":",
"[",
"]",
"}",
"}",
")",
"}"
] | Finds the CTags file from the specified search pattern and
searches it for the specified tag
@param {string} searchPath The path to search for the tags file
@param {string} tag The tag to search for in the tags file
@param {bool} ignoreCase Whether or not to ignore case when searching
@param {string} tagFilePattern The pattern to use when looking for
the tags file (refer to findCTagsFile)
@return {any[]} A promise, resolving to a list of found entries,
or an empty array if none found | [
"Finds",
"the",
"CTags",
"file",
"from",
"the",
"specified",
"search",
"pattern",
"and",
"searches",
"it",
"for",
"the",
"specified",
"tag"
] | 9f9da9c578c78ba2b3b869ea3cfe465d50681740 | https://github.com/jtanx/ctagz/blob/9f9da9c578c78ba2b3b869ea3cfe465d50681740/ctagz.js#L495-L511 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.