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,700 | espadrine/travel-scrapper | uk.js | getCookies | function getCookies() {
return new Promise((resolve, reject) => {
request.get(rootUrl, function(err, res, body) {
if (err != null && res.statusCode !== 200) {
reject(err || new Error('Accessing UK information failed'))
return
}
resolve()
})
})
} | javascript | function getCookies() {
return new Promise((resolve, reject) => {
request.get(rootUrl, function(err, res, body) {
if (err != null && res.statusCode !== 200) {
reject(err || new Error('Accessing UK information failed'))
return
}
resolve()
})
})
} | [
"function",
"getCookies",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"request",
".",
"get",
"(",
"rootUrl",
",",
"function",
"(",
"err",
",",
"res",
",",
"body",
")",
"{",
"if",
"(",
"err",
"!=",
"null",
"&&",
"res",
".",
"statusCode",
"!==",
"200",
")",
"{",
"reject",
"(",
"err",
"||",
"new",
"Error",
"(",
"'Accessing UK information failed'",
")",
")",
"return",
"}",
"resolve",
"(",
")",
"}",
")",
"}",
")",
"}"
] | Return a promise. | [
"Return",
"a",
"promise",
"."
] | 5ed137e967a8a2de67f988922ec66222f464ea96 | https://github.com/espadrine/travel-scrapper/blob/5ed137e967a8a2de67f988922ec66222f464ea96/uk.js#L150-L160 |
51,701 | markhuge/aws-sdk-sugar | lib/ec2.js | WTFAmazon | function WTFAmazon (array) {
var result = {};
array.map(function (item) { result[item.Key] = item.Value; });
return result;
} | javascript | function WTFAmazon (array) {
var result = {};
array.map(function (item) { result[item.Key] = item.Value; });
return result;
} | [
"function",
"WTFAmazon",
"(",
"array",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"array",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"result",
"[",
"item",
".",
"Key",
"]",
"=",
"item",
".",
"Value",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Convert AWW's batshit map arrays to an object | [
"Convert",
"AWW",
"s",
"batshit",
"map",
"arrays",
"to",
"an",
"object"
] | 16f8c1275b3f730c57d06aece6ebb0a34e492163 | https://github.com/markhuge/aws-sdk-sugar/blob/16f8c1275b3f730c57d06aece6ebb0a34e492163/lib/ec2.js#L29-L33 |
51,702 | milojs/ml-check | lib/check.js | _prependPath | function _prependPath(key, base) {
if ((typeof key) === "number" || key.match(/^[0-9]+$/))
key = "[" + key + "]";
else if (!key.match(Match.IdentifierString) || _jsKeywords.indexOf(key) !== -1)
key = JSON.stringify([key]);
if (base && base[0] !== "[")
return key + '.' + base;
return key + base;
} | javascript | function _prependPath(key, base) {
if ((typeof key) === "number" || key.match(/^[0-9]+$/))
key = "[" + key + "]";
else if (!key.match(Match.IdentifierString) || _jsKeywords.indexOf(key) !== -1)
key = JSON.stringify([key]);
if (base && base[0] !== "[")
return key + '.' + base;
return key + base;
} | [
"function",
"_prependPath",
"(",
"key",
",",
"base",
")",
"{",
"if",
"(",
"(",
"typeof",
"key",
")",
"===",
"\"number\"",
"||",
"key",
".",
"match",
"(",
"/",
"^[0-9]+$",
"/",
")",
")",
"key",
"=",
"\"[\"",
"+",
"key",
"+",
"\"]\"",
";",
"else",
"if",
"(",
"!",
"key",
".",
"match",
"(",
"Match",
".",
"IdentifierString",
")",
"||",
"_jsKeywords",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"key",
"=",
"JSON",
".",
"stringify",
"(",
"[",
"key",
"]",
")",
";",
"if",
"(",
"base",
"&&",
"base",
"[",
"0",
"]",
"!==",
"\"[\"",
")",
"return",
"key",
"+",
"'.'",
"+",
"base",
";",
"return",
"key",
"+",
"base",
";",
"}"
] | Assumes the base of path is already escaped properly returns key + base | [
"Assumes",
"the",
"base",
"of",
"path",
"is",
"already",
"escaped",
"properly",
"returns",
"key",
"+",
"base"
] | 1b61af65796ddbfd8cfba0fdcc37769fab7e768f | https://github.com/milojs/ml-check/blob/1b61af65796ddbfd8cfba0fdcc37769fab7e768f/lib/check.js#L291-L300 |
51,703 | shama/dom-tilemap | index.js | detach | function detach(el) {
var parent = el.parentNode
var next = el.nextSibling
parent.removeChild(el)
return function() {
if (next) parent.insertBefore(el, next)
else parent.appendChild(el)
}
} | javascript | function detach(el) {
var parent = el.parentNode
var next = el.nextSibling
parent.removeChild(el)
return function() {
if (next) parent.insertBefore(el, next)
else parent.appendChild(el)
}
} | [
"function",
"detach",
"(",
"el",
")",
"{",
"var",
"parent",
"=",
"el",
".",
"parentNode",
"var",
"next",
"=",
"el",
".",
"nextSibling",
"parent",
".",
"removeChild",
"(",
"el",
")",
"return",
"function",
"(",
")",
"{",
"if",
"(",
"next",
")",
"parent",
".",
"insertBefore",
"(",
"el",
",",
"next",
")",
"else",
"parent",
".",
"appendChild",
"(",
"el",
")",
"}",
"}"
] | for faster DOM manipulation - not faster in this case | [
"for",
"faster",
"DOM",
"manipulation",
"-",
"not",
"faster",
"in",
"this",
"case"
] | cd4af98e9066606717f04a1978cd162867eab160 | https://github.com/shama/dom-tilemap/blob/cd4af98e9066606717f04a1978cd162867eab160/index.js#L85-L93 |
51,704 | psalaets/pie-slice | index.js | function(sliceCount, options) {
validateSliceCount(sliceCount)
options = options || {}
var slices = []
var step = 360 / sliceCount
var halfStep = step / 2
var min = 0
var max = min + step
var sliceNumber = 0
if (options.firstSliceFacesUp) {
// first slice straddles angle 0 and is actually two slice objects
slices.push(createSlice(0, 360 - halfStep, 360))
slices.push(createSlice(0, 0, halfStep))
// tweak to account for first slice already existing
sliceNumber = 1
min = halfStep
max = min + step
}
for (; sliceNumber < sliceCount; sliceNumber++, min += step, max += step) {
slices.push(createSlice(sliceNumber, min, max))
}
return createPie(slices, !!options.yDown)
} | javascript | function(sliceCount, options) {
validateSliceCount(sliceCount)
options = options || {}
var slices = []
var step = 360 / sliceCount
var halfStep = step / 2
var min = 0
var max = min + step
var sliceNumber = 0
if (options.firstSliceFacesUp) {
// first slice straddles angle 0 and is actually two slice objects
slices.push(createSlice(0, 360 - halfStep, 360))
slices.push(createSlice(0, 0, halfStep))
// tweak to account for first slice already existing
sliceNumber = 1
min = halfStep
max = min + step
}
for (; sliceNumber < sliceCount; sliceNumber++, min += step, max += step) {
slices.push(createSlice(sliceNumber, min, max))
}
return createPie(slices, !!options.yDown)
} | [
"function",
"(",
"sliceCount",
",",
"options",
")",
"{",
"validateSliceCount",
"(",
"sliceCount",
")",
"options",
"=",
"options",
"||",
"{",
"}",
"var",
"slices",
"=",
"[",
"]",
"var",
"step",
"=",
"360",
"/",
"sliceCount",
"var",
"halfStep",
"=",
"step",
"/",
"2",
"var",
"min",
"=",
"0",
"var",
"max",
"=",
"min",
"+",
"step",
"var",
"sliceNumber",
"=",
"0",
"if",
"(",
"options",
".",
"firstSliceFacesUp",
")",
"{",
"// first slice straddles angle 0 and is actually two slice objects",
"slices",
".",
"push",
"(",
"createSlice",
"(",
"0",
",",
"360",
"-",
"halfStep",
",",
"360",
")",
")",
"slices",
".",
"push",
"(",
"createSlice",
"(",
"0",
",",
"0",
",",
"halfStep",
")",
")",
"// tweak to account for first slice already existing",
"sliceNumber",
"=",
"1",
"min",
"=",
"halfStep",
"max",
"=",
"min",
"+",
"step",
"}",
"for",
"(",
";",
"sliceNumber",
"<",
"sliceCount",
";",
"sliceNumber",
"++",
",",
"min",
"+=",
"step",
",",
"max",
"+=",
"step",
")",
"{",
"slices",
".",
"push",
"(",
"createSlice",
"(",
"sliceNumber",
",",
"min",
",",
"max",
")",
")",
"}",
"return",
"createPie",
"(",
"slices",
",",
"!",
"!",
"options",
".",
"yDown",
")",
"}"
] | Create a pie with certain number of slices.
@param sliceCount Number of slices. Must be between 2 and 360, inclusive.
@param options Hash of extra options. Options:
- firstSliceFacesUp - true to make first slice point straight up so it's
bissected by angle 0. Otherwise first slice *begins* at angle 0.
Defaults to false.
@return sliced pie | [
"Create",
"a",
"pie",
"with",
"certain",
"number",
"of",
"slices",
"."
] | ca119bb63ccefc09cc66ebfdf0bc19ebce364b88 | https://github.com/psalaets/pie-slice/blob/ca119bb63ccefc09cc66ebfdf0bc19ebce364b88/index.js#L21-L49 |
|
51,705 | vweevers/doctap | lib/transform.js | parseComment | function parseComment (comment) {
const body = j('[' + comment + ']').nodes()[0].program.body
const array = body[0].expression
return array.elements
} | javascript | function parseComment (comment) {
const body = j('[' + comment + ']').nodes()[0].program.body
const array = body[0].expression
return array.elements
} | [
"function",
"parseComment",
"(",
"comment",
")",
"{",
"const",
"body",
"=",
"j",
"(",
"'['",
"+",
"comment",
"+",
"']'",
")",
".",
"nodes",
"(",
")",
"[",
"0",
"]",
".",
"program",
".",
"body",
"const",
"array",
"=",
"body",
"[",
"0",
"]",
".",
"expression",
"return",
"array",
".",
"elements",
"}"
] | Because we take the comment as JavaScript source code, it can reference variables and do all sorts of crazy stuff. | [
"Because",
"we",
"take",
"the",
"comment",
"as",
"JavaScript",
"source",
"code",
"it",
"can",
"reference",
"variables",
"and",
"do",
"all",
"sorts",
"of",
"crazy",
"stuff",
"."
] | 3c93981e2c7dc4db3245e44495a2f8e841008f5c | https://github.com/vweevers/doctap/blob/3c93981e2c7dc4db3245e44495a2f8e841008f5c/lib/transform.js#L308-L312 |
51,706 | vweevers/doctap | lib/transform.js | identifierFactory | function identifierFactory (ast, reserved) {
reserved = reserved || new Set
ast.find(j.Identifier).forEach(path => {
reserved.add(path.node.name)
})
ast.find(j.FunctionDeclaration).forEach(path => {
reserved.add(path.node.id.name)
})
function identifier (name, suffix) {
return j.identifier(identifier.string(name, suffix))
}
identifier.string = function (name, suffix) {
let sfx = suffix == null ? '' : suffix
, unique = name + sfx
, n = 0
while (reserved.has(unique)) {
unique = name + (n++) + sfx
}
return unique
}
return identifier
} | javascript | function identifierFactory (ast, reserved) {
reserved = reserved || new Set
ast.find(j.Identifier).forEach(path => {
reserved.add(path.node.name)
})
ast.find(j.FunctionDeclaration).forEach(path => {
reserved.add(path.node.id.name)
})
function identifier (name, suffix) {
return j.identifier(identifier.string(name, suffix))
}
identifier.string = function (name, suffix) {
let sfx = suffix == null ? '' : suffix
, unique = name + sfx
, n = 0
while (reserved.has(unique)) {
unique = name + (n++) + sfx
}
return unique
}
return identifier
} | [
"function",
"identifierFactory",
"(",
"ast",
",",
"reserved",
")",
"{",
"reserved",
"=",
"reserved",
"||",
"new",
"Set",
"ast",
".",
"find",
"(",
"j",
".",
"Identifier",
")",
".",
"forEach",
"(",
"path",
"=>",
"{",
"reserved",
".",
"add",
"(",
"path",
".",
"node",
".",
"name",
")",
"}",
")",
"ast",
".",
"find",
"(",
"j",
".",
"FunctionDeclaration",
")",
".",
"forEach",
"(",
"path",
"=>",
"{",
"reserved",
".",
"add",
"(",
"path",
".",
"node",
".",
"id",
".",
"name",
")",
"}",
")",
"function",
"identifier",
"(",
"name",
",",
"suffix",
")",
"{",
"return",
"j",
".",
"identifier",
"(",
"identifier",
".",
"string",
"(",
"name",
",",
"suffix",
")",
")",
"}",
"identifier",
".",
"string",
"=",
"function",
"(",
"name",
",",
"suffix",
")",
"{",
"let",
"sfx",
"=",
"suffix",
"==",
"null",
"?",
"''",
":",
"suffix",
",",
"unique",
"=",
"name",
"+",
"sfx",
",",
"n",
"=",
"0",
"while",
"(",
"reserved",
".",
"has",
"(",
"unique",
")",
")",
"{",
"unique",
"=",
"name",
"+",
"(",
"n",
"++",
")",
"+",
"sfx",
"}",
"return",
"unique",
"}",
"return",
"identifier",
"}"
] | Make identifiers with unique names | [
"Make",
"identifiers",
"with",
"unique",
"names"
] | 3c93981e2c7dc4db3245e44495a2f8e841008f5c | https://github.com/vweevers/doctap/blob/3c93981e2c7dc4db3245e44495a2f8e841008f5c/lib/transform.js#L315-L343 |
51,707 | rudiculous/node-function-signature | index.js | getFunctionSignature | function getFunctionSignature(fn) {
let str = fn.toString()
// Strip comments.
str = str.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g, '')
const match = str.match(/\(([^)]*)\)/)
if (match) {
let res = match[1]
// Strip leading and trailing whitespace.
res = res.replace(/^\s+|\s+$/g, '')
let sig = res.split(/\s*,\s*/)
if (sig.length === 1 && !sig[0]) {
sig.length = 0
}
const signature = []
for (let key of sig) {
// TODO: Handle rest parameters. The position of the rest
// parameter matters, so this requires some thought. The
// following signatures are all different:
// * function (...rest, foo, bar)
// * function (foo, ...rest, bar)
// * function (foo, bar, ...rest)
// For now, just ignore rest parameters...
if (key.indexOf('...') === 0) {
continue
}
// If there is a default value defined, remove it from the
// key.
key = key.replace(/\s*=.*$/, '')
// TODO: Should we do something with destructuring
// assignments?
signature.push(key)
}
return signature
}
else {
return []
}
} | javascript | function getFunctionSignature(fn) {
let str = fn.toString()
// Strip comments.
str = str.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g, '')
const match = str.match(/\(([^)]*)\)/)
if (match) {
let res = match[1]
// Strip leading and trailing whitespace.
res = res.replace(/^\s+|\s+$/g, '')
let sig = res.split(/\s*,\s*/)
if (sig.length === 1 && !sig[0]) {
sig.length = 0
}
const signature = []
for (let key of sig) {
// TODO: Handle rest parameters. The position of the rest
// parameter matters, so this requires some thought. The
// following signatures are all different:
// * function (...rest, foo, bar)
// * function (foo, ...rest, bar)
// * function (foo, bar, ...rest)
// For now, just ignore rest parameters...
if (key.indexOf('...') === 0) {
continue
}
// If there is a default value defined, remove it from the
// key.
key = key.replace(/\s*=.*$/, '')
// TODO: Should we do something with destructuring
// assignments?
signature.push(key)
}
return signature
}
else {
return []
}
} | [
"function",
"getFunctionSignature",
"(",
"fn",
")",
"{",
"let",
"str",
"=",
"fn",
".",
"toString",
"(",
")",
"// Strip comments.",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\/\\/[^\\r\\n]*|\\/\\*[\\s\\S]*?\\*\\/",
"/",
"g",
",",
"''",
")",
"const",
"match",
"=",
"str",
".",
"match",
"(",
"/",
"\\(([^)]*)\\)",
"/",
")",
"if",
"(",
"match",
")",
"{",
"let",
"res",
"=",
"match",
"[",
"1",
"]",
"// Strip leading and trailing whitespace.",
"res",
"=",
"res",
".",
"replace",
"(",
"/",
"^\\s+|\\s+$",
"/",
"g",
",",
"''",
")",
"let",
"sig",
"=",
"res",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
"if",
"(",
"sig",
".",
"length",
"===",
"1",
"&&",
"!",
"sig",
"[",
"0",
"]",
")",
"{",
"sig",
".",
"length",
"=",
"0",
"}",
"const",
"signature",
"=",
"[",
"]",
"for",
"(",
"let",
"key",
"of",
"sig",
")",
"{",
"// TODO: Handle rest parameters. The position of the rest",
"// parameter matters, so this requires some thought. The",
"// following signatures are all different:",
"// * function (...rest, foo, bar)",
"// * function (foo, ...rest, bar)",
"// * function (foo, bar, ...rest)",
"// For now, just ignore rest parameters...",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'...'",
")",
"===",
"0",
")",
"{",
"continue",
"}",
"// If there is a default value defined, remove it from the",
"// key.",
"key",
"=",
"key",
".",
"replace",
"(",
"/",
"\\s*=.*$",
"/",
",",
"''",
")",
"// TODO: Should we do something with destructuring",
"// assignments?",
"signature",
".",
"push",
"(",
"key",
")",
"}",
"return",
"signature",
"}",
"else",
"{",
"return",
"[",
"]",
"}",
"}"
] | Parses a function to get its parameters.
@param {Function} fn The function to parse.
@return {Array} A list of the function arguments.
@public | [
"Parses",
"a",
"function",
"to",
"get",
"its",
"parameters",
"."
] | 16edab38d4bb2db26ed5bbfbaafd2b46d93dd438 | https://github.com/rudiculous/node-function-signature/blob/16edab38d4bb2db26ed5bbfbaafd2b46d93dd438/index.js#L11-L60 |
51,708 | gethuman/pancakes-angular | lib/ngapp/focus.js | blur | function blur(selector) {
$timeout(function blurFocus() {
// fix for iOS
if (document && document.activeElement && document.activeElement.blur) {
document.activeElement.blur();
}
var el = jQuery(selector);
if (el && el.length) {
el[0].blur();
}
}, 100);
} | javascript | function blur(selector) {
$timeout(function blurFocus() {
// fix for iOS
if (document && document.activeElement && document.activeElement.blur) {
document.activeElement.blur();
}
var el = jQuery(selector);
if (el && el.length) {
el[0].blur();
}
}, 100);
} | [
"function",
"blur",
"(",
"selector",
")",
"{",
"$timeout",
"(",
"function",
"blurFocus",
"(",
")",
"{",
"// fix for iOS",
"if",
"(",
"document",
"&&",
"document",
".",
"activeElement",
"&&",
"document",
".",
"activeElement",
".",
"blur",
")",
"{",
"document",
".",
"activeElement",
".",
"blur",
"(",
")",
";",
"}",
"var",
"el",
"=",
"jQuery",
"(",
"selector",
")",
";",
"if",
"(",
"el",
"&&",
"el",
".",
"length",
")",
"{",
"el",
"[",
"0",
"]",
".",
"blur",
"(",
")",
";",
"}",
"}",
",",
"100",
")",
";",
"}"
] | Blur an element
@param selector | [
"Blur",
"an",
"element"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/focus.js#L29-L42 |
51,709 | Wiredcraft/carcass | lib/proto/register.js | function() {
var lib, name, names, _i, _len;
lib = arguments[0], names = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
for (_i = 0, _len = names.length; _i < _len; _i++) {
name = names[_i];
if (lib[name] == null) {
return;
}
if (this[name] == null) {
this[name] = {};
}
if (!isObject(this[name])) {
return;
}
mixin(this[name], lib[name]);
}
return this;
} | javascript | function() {
var lib, name, names, _i, _len;
lib = arguments[0], names = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
for (_i = 0, _len = names.length; _i < _len; _i++) {
name = names[_i];
if (lib[name] == null) {
return;
}
if (this[name] == null) {
this[name] = {};
}
if (!isObject(this[name])) {
return;
}
mixin(this[name], lib[name]);
}
return this;
} | [
"function",
"(",
")",
"{",
"var",
"lib",
",",
"name",
",",
"names",
",",
"_i",
",",
"_len",
";",
"lib",
"=",
"arguments",
"[",
"0",
"]",
",",
"names",
"=",
"2",
"<=",
"arguments",
".",
"length",
"?",
"__slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
":",
"[",
"]",
";",
"for",
"(",
"_i",
"=",
"0",
",",
"_len",
"=",
"names",
".",
"length",
";",
"_i",
"<",
"_len",
";",
"_i",
"++",
")",
"{",
"name",
"=",
"names",
"[",
"_i",
"]",
";",
"if",
"(",
"lib",
"[",
"name",
"]",
"==",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"this",
"[",
"name",
"]",
"==",
"null",
")",
"{",
"this",
"[",
"name",
"]",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"isObject",
"(",
"this",
"[",
"name",
"]",
")",
")",
"{",
"return",
";",
"}",
"mixin",
"(",
"this",
"[",
"name",
"]",
",",
"lib",
"[",
"name",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Extend with another register.
@param lib
@param *name
@return {this} | [
"Extend",
"with",
"another",
"register",
"."
] | 3527ec0253f55abba8e6b255e7bf3412b3ca7501 | https://github.com/Wiredcraft/carcass/blob/3527ec0253f55abba8e6b255e7bf3412b3ca7501/lib/proto/register.js#L57-L74 |
|
51,710 | tolokoban/ToloFrameWork | lib/init.js | menu | function menu( items, nextStep ) {
const rl = RL.createInterface( {
input: process.stdin,
output: process.stdout
} );
console.log();
items.forEach( function ( item, idx ) {
var out = idx < 10 ? ' ' : '';
out += ( "" + ( 1 + idx ) + ") " ).yellow;
out += item;
console.log( out );
} );
console.log();
rl.question( "Your choice: ", ( ans ) => {
rl.close();
var choice = parseInt( ans );
if ( isNaN( ans ) || ans < 1 || ans > items.length ) {
menu( items, nextStep );
} else {
console.log();
nextStep( choice );
}
} );
} | javascript | function menu( items, nextStep ) {
const rl = RL.createInterface( {
input: process.stdin,
output: process.stdout
} );
console.log();
items.forEach( function ( item, idx ) {
var out = idx < 10 ? ' ' : '';
out += ( "" + ( 1 + idx ) + ") " ).yellow;
out += item;
console.log( out );
} );
console.log();
rl.question( "Your choice: ", ( ans ) => {
rl.close();
var choice = parseInt( ans );
if ( isNaN( ans ) || ans < 1 || ans > items.length ) {
menu( items, nextStep );
} else {
console.log();
nextStep( choice );
}
} );
} | [
"function",
"menu",
"(",
"items",
",",
"nextStep",
")",
"{",
"const",
"rl",
"=",
"RL",
".",
"createInterface",
"(",
"{",
"input",
":",
"process",
".",
"stdin",
",",
"output",
":",
"process",
".",
"stdout",
"}",
")",
";",
"console",
".",
"log",
"(",
")",
";",
"items",
".",
"forEach",
"(",
"function",
"(",
"item",
",",
"idx",
")",
"{",
"var",
"out",
"=",
"idx",
"<",
"10",
"?",
"' '",
":",
"''",
";",
"out",
"+=",
"(",
"\"\"",
"+",
"(",
"1",
"+",
"idx",
")",
"+",
"\") \"",
")",
".",
"yellow",
";",
"out",
"+=",
"item",
";",
"console",
".",
"log",
"(",
"out",
")",
";",
"}",
")",
";",
"console",
".",
"log",
"(",
")",
";",
"rl",
".",
"question",
"(",
"\"Your choice: \"",
",",
"(",
"ans",
")",
"=>",
"{",
"rl",
".",
"close",
"(",
")",
";",
"var",
"choice",
"=",
"parseInt",
"(",
"ans",
")",
";",
"if",
"(",
"isNaN",
"(",
"ans",
")",
"||",
"ans",
"<",
"1",
"||",
"ans",
">",
"items",
".",
"length",
")",
"{",
"menu",
"(",
"items",
",",
"nextStep",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
")",
";",
"nextStep",
"(",
"choice",
")",
";",
"}",
"}",
")",
";",
"}"
] | Display a list of items and ask the user to select one.
Each item is numbered and the menu is displayed again if the user
enter a non-existing value.
The function `nextStep` is called with the choice as a number. | [
"Display",
"a",
"list",
"of",
"items",
"and",
"ask",
"the",
"user",
"to",
"select",
"one",
".",
"Each",
"item",
"is",
"numbered",
"and",
"the",
"menu",
"is",
"displayed",
"again",
"if",
"the",
"user",
"enter",
"a",
"non",
"-",
"existing",
"value",
".",
"The",
"function",
"nextStep",
"is",
"called",
"with",
"the",
"choice",
"as",
"a",
"number",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/init.js#L229-L252 |
51,711 | tolokoban/ToloFrameWork | lib/init.js | isInEmptyFolder | function isInEmptyFolder() {
var files = FS.readdirSync( '.' );
try {
if ( files.length == 0 ) return true;
console.log( Fatal.format(
"You should be in an empty folder to create a new project!\n" +
"If you continue, all the files in this folder will be DELETED!"
) );
console.log( "\nWe suggest that you create an fresh new directory, like this:" );
console.log( "\n> " + "mkdir my-project-folder".yellow.italic );
console.log( "> " + "cd my-project-folder".yellow.italic );
console.log( "> " + "tfw init".yellow.italic );
return false;
} catch ( ex ) {
fatal( "Fatal error in function `files`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | javascript | function isInEmptyFolder() {
var files = FS.readdirSync( '.' );
try {
if ( files.length == 0 ) return true;
console.log( Fatal.format(
"You should be in an empty folder to create a new project!\n" +
"If you continue, all the files in this folder will be DELETED!"
) );
console.log( "\nWe suggest that you create an fresh new directory, like this:" );
console.log( "\n> " + "mkdir my-project-folder".yellow.italic );
console.log( "> " + "cd my-project-folder".yellow.italic );
console.log( "> " + "tfw init".yellow.italic );
return false;
} catch ( ex ) {
fatal( "Fatal error in function `files`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | [
"function",
"isInEmptyFolder",
"(",
")",
"{",
"var",
"files",
"=",
"FS",
".",
"readdirSync",
"(",
"'.'",
")",
";",
"try",
"{",
"if",
"(",
"files",
".",
"length",
"==",
"0",
")",
"return",
"true",
";",
"console",
".",
"log",
"(",
"Fatal",
".",
"format",
"(",
"\"You should be in an empty folder to create a new project!\\n\"",
"+",
"\"If you continue, all the files in this folder will be DELETED!\"",
")",
")",
";",
"console",
".",
"log",
"(",
"\"\\nWe suggest that you create an fresh new directory, like this:\"",
")",
";",
"console",
".",
"log",
"(",
"\"\\n> \"",
"+",
"\"mkdir my-project-folder\"",
".",
"yellow",
".",
"italic",
")",
";",
"console",
".",
"log",
"(",
"\"> \"",
"+",
"\"cd my-project-folder\"",
".",
"yellow",
".",
"italic",
")",
";",
"console",
".",
"log",
"(",
"\"> \"",
"+",
"\"tfw init\"",
".",
"yellow",
".",
"italic",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"fatal",
"(",
"\"Fatal error in function `files`!\\n\"",
"+",
"JSON",
".",
"stringify",
"(",
"ex",
",",
"null",
",",
"' '",
")",
")",
";",
"}",
"}"
] | Check if we are in an empty folder. | [
"Check",
"if",
"we",
"are",
"in",
"an",
"empty",
"folder",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/init.js#L331-L347 |
51,712 | tolokoban/ToloFrameWork | lib/init.js | isGitInstalled | function isGitInstalled() {
var result = exec( "git --version", true );
try {
if ( !result || result.indexOf( "git" ) < 0 || result.indexOf( "version" ) < 0 ) {
console.log( Fatal.format(
"`git` is required by the ToloFrameWork!\n" +
"Please install it:" ) );
console.log( "\n> " + "sudo apt-get install git".yellow.italic );
return false;
}
return true;
} catch ( ex ) {
fatal( "Fatal error in function `result`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | javascript | function isGitInstalled() {
var result = exec( "git --version", true );
try {
if ( !result || result.indexOf( "git" ) < 0 || result.indexOf( "version" ) < 0 ) {
console.log( Fatal.format(
"`git` is required by the ToloFrameWork!\n" +
"Please install it:" ) );
console.log( "\n> " + "sudo apt-get install git".yellow.italic );
return false;
}
return true;
} catch ( ex ) {
fatal( "Fatal error in function `result`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | [
"function",
"isGitInstalled",
"(",
")",
"{",
"var",
"result",
"=",
"exec",
"(",
"\"git --version\"",
",",
"true",
")",
";",
"try",
"{",
"if",
"(",
"!",
"result",
"||",
"result",
".",
"indexOf",
"(",
"\"git\"",
")",
"<",
"0",
"||",
"result",
".",
"indexOf",
"(",
"\"version\"",
")",
"<",
"0",
")",
"{",
"console",
".",
"log",
"(",
"Fatal",
".",
"format",
"(",
"\"`git` is required by the ToloFrameWork!\\n\"",
"+",
"\"Please install it:\"",
")",
")",
";",
"console",
".",
"log",
"(",
"\"\\n> \"",
"+",
"\"sudo apt-get install git\"",
".",
"yellow",
".",
"italic",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"fatal",
"(",
"\"Fatal error in function `result`!\\n\"",
"+",
"JSON",
".",
"stringify",
"(",
"ex",
",",
"null",
",",
"' '",
")",
")",
";",
"}",
"}"
] | Check if `git` is installed on this system. | [
"Check",
"if",
"git",
"is",
"installed",
"on",
"this",
"system",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/init.js#L352-L366 |
51,713 | tolokoban/ToloFrameWork | lib/init.js | cleanDir | function cleanDir( path ) {
var files = FS.readdirSync( path );
try {
files.forEach( function ( file ) {
var fullpath = Path.join( path, file );
if ( !FS.existsSync( fullpath ) ) return;
var stat = FS.statSync( fullpath );
try {
if ( stat.isDirectory() ) PathUtils.rmdir( fullpath );
else FS.unlinkSync( fullpath );
} catch ( ex ) {
console.error( "Unable to delete `" + fullpath + "`!" );
console.error( ex );
}
} );
} catch ( ex ) {
fatal( "Fatal error in function `files`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | javascript | function cleanDir( path ) {
var files = FS.readdirSync( path );
try {
files.forEach( function ( file ) {
var fullpath = Path.join( path, file );
if ( !FS.existsSync( fullpath ) ) return;
var stat = FS.statSync( fullpath );
try {
if ( stat.isDirectory() ) PathUtils.rmdir( fullpath );
else FS.unlinkSync( fullpath );
} catch ( ex ) {
console.error( "Unable to delete `" + fullpath + "`!" );
console.error( ex );
}
} );
} catch ( ex ) {
fatal( "Fatal error in function `files`!\n" + JSON.stringify( ex, null, ' ' ) );
}
} | [
"function",
"cleanDir",
"(",
"path",
")",
"{",
"var",
"files",
"=",
"FS",
".",
"readdirSync",
"(",
"path",
")",
";",
"try",
"{",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"fullpath",
"=",
"Path",
".",
"join",
"(",
"path",
",",
"file",
")",
";",
"if",
"(",
"!",
"FS",
".",
"existsSync",
"(",
"fullpath",
")",
")",
"return",
";",
"var",
"stat",
"=",
"FS",
".",
"statSync",
"(",
"fullpath",
")",
";",
"try",
"{",
"if",
"(",
"stat",
".",
"isDirectory",
"(",
")",
")",
"PathUtils",
".",
"rmdir",
"(",
"fullpath",
")",
";",
"else",
"FS",
".",
"unlinkSync",
"(",
"fullpath",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"console",
".",
"error",
"(",
"\"Unable to delete `\"",
"+",
"fullpath",
"+",
"\"`!\"",
")",
";",
"console",
".",
"error",
"(",
"ex",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"fatal",
"(",
"\"Fatal error in function `files`!\\n\"",
"+",
"JSON",
".",
"stringify",
"(",
"ex",
",",
"null",
",",
"' '",
")",
")",
";",
"}",
"}"
] | Remove all the files and folder in `path`, but not `path` itself. | [
"Remove",
"all",
"the",
"files",
"and",
"folder",
"in",
"path",
"but",
"not",
"path",
"itself",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/lib/init.js#L396-L414 |
51,714 | closealert/async-lru-cache | example.js | checkHost | function checkHost(host,callback) {
if(hostCache.get(host,callback)) {
console.log('checkHost: Resolved %s from hostCache...',host);
return true;
}
console.log('checkHost: Looking up %s...',host);
var options = {
host: host,
port: 80,
path: '/',
method: 'GET'
};
var req = http.request(options, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
hostCache.set(host,true);
});
res.on('error',function() {
hostCache.set(host,false);
});
});
req.on('error',function() {
hostCache.set(host,false);
});
req.end();
} | javascript | function checkHost(host,callback) {
if(hostCache.get(host,callback)) {
console.log('checkHost: Resolved %s from hostCache...',host);
return true;
}
console.log('checkHost: Looking up %s...',host);
var options = {
host: host,
port: 80,
path: '/',
method: 'GET'
};
var req = http.request(options, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
hostCache.set(host,true);
});
res.on('error',function() {
hostCache.set(host,false);
});
});
req.on('error',function() {
hostCache.set(host,false);
});
req.end();
} | [
"function",
"checkHost",
"(",
"host",
",",
"callback",
")",
"{",
"if",
"(",
"hostCache",
".",
"get",
"(",
"host",
",",
"callback",
")",
")",
"{",
"console",
".",
"log",
"(",
"'checkHost: Resolved %s from hostCache...'",
",",
"host",
")",
";",
"return",
"true",
";",
"}",
"console",
".",
"log",
"(",
"'checkHost: Looking up %s...'",
",",
"host",
")",
";",
"var",
"options",
"=",
"{",
"host",
":",
"host",
",",
"port",
":",
"80",
",",
"path",
":",
"'/'",
",",
"method",
":",
"'GET'",
"}",
";",
"var",
"req",
"=",
"http",
".",
"request",
"(",
"options",
",",
"function",
"(",
"res",
")",
"{",
"var",
"data",
"=",
"''",
";",
"res",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"data",
"+=",
"chunk",
";",
"}",
")",
";",
"res",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"hostCache",
".",
"set",
"(",
"host",
",",
"true",
")",
";",
"}",
")",
";",
"res",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
")",
"{",
"hostCache",
".",
"set",
"(",
"host",
",",
"false",
")",
";",
"}",
")",
";",
"}",
")",
";",
"req",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
")",
"{",
"hostCache",
".",
"set",
"(",
"host",
",",
"false",
")",
";",
"}",
")",
";",
"req",
".",
"end",
"(",
")",
";",
"}"
] | Function with single argument callback
Connects to a host and returns true or false wether a connection was made
@param key Hostname
@param Function Callback | [
"Function",
"with",
"single",
"argument",
"callback",
"Connects",
"to",
"a",
"host",
"and",
"returns",
"true",
"or",
"false",
"wether",
"a",
"connection",
"was",
"made"
] | ba15c1c4f64ba841a97b8946b71c004ea6b20b22 | https://github.com/closealert/async-lru-cache/blob/ba15c1c4f64ba841a97b8946b71c004ea6b20b22/example.js#L14-L48 |
51,715 | Digznav/bilberry | git-current-branch.js | gitCurrentBranch | function gitCurrentBranch() {
return git('status --porcelain -b', stdout => {
const status = gitUtil.extractStatus(stdout);
return status.branch.split('...')[0];
});
} | javascript | function gitCurrentBranch() {
return git('status --porcelain -b', stdout => {
const status = gitUtil.extractStatus(stdout);
return status.branch.split('...')[0];
});
} | [
"function",
"gitCurrentBranch",
"(",
")",
"{",
"return",
"git",
"(",
"'status --porcelain -b'",
",",
"stdout",
"=>",
"{",
"const",
"status",
"=",
"gitUtil",
".",
"extractStatus",
"(",
"stdout",
")",
";",
"return",
"status",
".",
"branch",
".",
"split",
"(",
"'...'",
")",
"[",
"0",
"]",
";",
"}",
")",
";",
"}"
] | Get the current branch.
@return {promise} A promise get the current branch, | [
"Get",
"the",
"current",
"branch",
"."
] | ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4 | https://github.com/Digznav/bilberry/blob/ef6db49de6c8b0d2f4f9d3e10e8a8153e39ffcc4/git-current-branch.js#L8-L13 |
51,716 | reklatsmasters/trace-inline-parse | index.js | node | function node(name, accessor) {
if (!name) {
return false
}
return {
name: name,
accessor: accessor ? accessor : false
}
} | javascript | function node(name, accessor) {
if (!name) {
return false
}
return {
name: name,
accessor: accessor ? accessor : false
}
} | [
"function",
"node",
"(",
"name",
",",
"accessor",
")",
"{",
"if",
"(",
"!",
"name",
")",
"{",
"return",
"false",
"}",
"return",
"{",
"name",
":",
"name",
",",
"accessor",
":",
"accessor",
"?",
"accessor",
":",
"false",
"}",
"}"
] | create `target` or `caller` nodes | [
"create",
"target",
"or",
"caller",
"nodes"
] | e029463fd6a08d7849c823ed1c3379878b30e8f2 | https://github.com/reklatsmasters/trace-inline-parse/blob/e029463fd6a08d7849c823ed1c3379878b30e8f2/index.js#L67-L76 |
51,717 | redisjs/jsr-server | lib/command/connection/select.js | execute | function execute(req, res) {
// if we have a sparse db store we need
// to ensure a database exists
if(!this.store.databases[req.args[0]]) {
this.store.getDatabase(req.args[0], {pattern: this.pattern});
}
// update the connection with their selected db index
req.conn.db = req.args[0];
res.send(null, Constants.OK);
} | javascript | function execute(req, res) {
// if we have a sparse db store we need
// to ensure a database exists
if(!this.store.databases[req.args[0]]) {
this.store.getDatabase(req.args[0], {pattern: this.pattern});
}
// update the connection with their selected db index
req.conn.db = req.args[0];
res.send(null, Constants.OK);
} | [
"function",
"execute",
"(",
"req",
",",
"res",
")",
"{",
"// if we have a sparse db store we need",
"// to ensure a database exists",
"if",
"(",
"!",
"this",
".",
"store",
".",
"databases",
"[",
"req",
".",
"args",
"[",
"0",
"]",
"]",
")",
"{",
"this",
".",
"store",
".",
"getDatabase",
"(",
"req",
".",
"args",
"[",
"0",
"]",
",",
"{",
"pattern",
":",
"this",
".",
"pattern",
"}",
")",
";",
"}",
"// update the connection with their selected db index",
"req",
".",
"conn",
".",
"db",
"=",
"req",
".",
"args",
"[",
"0",
"]",
";",
"res",
".",
"send",
"(",
"null",
",",
"Constants",
".",
"OK",
")",
";",
"}"
] | Respond to the SELECT command. | [
"Respond",
"to",
"the",
"SELECT",
"command",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/connection/select.js#L21-L33 |
51,718 | redisjs/jsr-server | lib/command/connection/select.js | validate | function validate(cmd, args, info) {
AbstractCommand.prototype.validate.apply(this, arguments);
var index = parseInt(args[0]);
if(isNaN(index) || index < 0 || index >= info.conf.databases) {
throw DatabaseIndex;
}
// update the index with the integer value
// connection expects an integer
args[0] = index;
} | javascript | function validate(cmd, args, info) {
AbstractCommand.prototype.validate.apply(this, arguments);
var index = parseInt(args[0]);
if(isNaN(index) || index < 0 || index >= info.conf.databases) {
throw DatabaseIndex;
}
// update the index with the integer value
// connection expects an integer
args[0] = index;
} | [
"function",
"validate",
"(",
"cmd",
",",
"args",
",",
"info",
")",
"{",
"AbstractCommand",
".",
"prototype",
".",
"validate",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"index",
"=",
"parseInt",
"(",
"args",
"[",
"0",
"]",
")",
";",
"if",
"(",
"isNaN",
"(",
"index",
")",
"||",
"index",
"<",
"0",
"||",
"index",
">=",
"info",
".",
"conf",
".",
"databases",
")",
"{",
"throw",
"DatabaseIndex",
";",
"}",
"// update the index with the integer value",
"// connection expects an integer",
"args",
"[",
"0",
"]",
"=",
"index",
";",
"}"
] | Validate the SELECT command. | [
"Validate",
"the",
"SELECT",
"command",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/connection/select.js#L38-L47 |
51,719 | feedhenry/fh-mbaas-middleware | lib/models/appEnv.js | getOpenshiftEnvVars | function getOpenshiftEnvVars(params){
var appMbaas = params.appMbaas;
var mbaasUrl = _parseMbaasUrl(appMbaas.mbaasUrl);
var appEnvs = {};
appEnvs.FH_MBAAS_PROTOCOL = mbaasUrl.protocol;
//App Mbaas Host. Used for apps calling mbaas hosts.
appEnvs.FH_MBAAS_HOST = mbaasUrl.host;
//Access key to verify apps calling Mbaas App APIs.
appEnvs.FH_MBAAS_ENV_ACCESS_KEY = appMbaas.accessKey;
//If the app is a service, ensure the FH_SERVICE_ACCESS_KEY env var is set.
//This will allow authorised data sources to access the service using the X-FH-SERViCE-ACCESS-KEY header.
if(appMbaas.isServiceApp){
appEnvs.FH_SERVICE_ACCESS_KEY = appMbaas.serviceAccessKey;
}
return appEnvs;
} | javascript | function getOpenshiftEnvVars(params){
var appMbaas = params.appMbaas;
var mbaasUrl = _parseMbaasUrl(appMbaas.mbaasUrl);
var appEnvs = {};
appEnvs.FH_MBAAS_PROTOCOL = mbaasUrl.protocol;
//App Mbaas Host. Used for apps calling mbaas hosts.
appEnvs.FH_MBAAS_HOST = mbaasUrl.host;
//Access key to verify apps calling Mbaas App APIs.
appEnvs.FH_MBAAS_ENV_ACCESS_KEY = appMbaas.accessKey;
//If the app is a service, ensure the FH_SERVICE_ACCESS_KEY env var is set.
//This will allow authorised data sources to access the service using the X-FH-SERViCE-ACCESS-KEY header.
if(appMbaas.isServiceApp){
appEnvs.FH_SERVICE_ACCESS_KEY = appMbaas.serviceAccessKey;
}
return appEnvs;
} | [
"function",
"getOpenshiftEnvVars",
"(",
"params",
")",
"{",
"var",
"appMbaas",
"=",
"params",
".",
"appMbaas",
";",
"var",
"mbaasUrl",
"=",
"_parseMbaasUrl",
"(",
"appMbaas",
".",
"mbaasUrl",
")",
";",
"var",
"appEnvs",
"=",
"{",
"}",
";",
"appEnvs",
".",
"FH_MBAAS_PROTOCOL",
"=",
"mbaasUrl",
".",
"protocol",
";",
"//App Mbaas Host. Used for apps calling mbaas hosts.",
"appEnvs",
".",
"FH_MBAAS_HOST",
"=",
"mbaasUrl",
".",
"host",
";",
"//Access key to verify apps calling Mbaas App APIs.",
"appEnvs",
".",
"FH_MBAAS_ENV_ACCESS_KEY",
"=",
"appMbaas",
".",
"accessKey",
";",
"//If the app is a service, ensure the FH_SERVICE_ACCESS_KEY env var is set.",
"//This will allow authorised data sources to access the service using the X-FH-SERViCE-ACCESS-KEY header.",
"if",
"(",
"appMbaas",
".",
"isServiceApp",
")",
"{",
"appEnvs",
".",
"FH_SERVICE_ACCESS_KEY",
"=",
"appMbaas",
".",
"serviceAccessKey",
";",
"}",
"return",
"appEnvs",
";",
"}"
] | Getting Environment Variables For Openshift Apps.
@param params | [
"Getting",
"Environment",
"Variables",
"For",
"Openshift",
"Apps",
"."
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/models/appEnv.js#L18-L37 |
51,720 | docvy/utils | lib/index.js | getPath | function getPath(pathname) {
var _paths = { };
_paths["app.home"] = path.join(process.env.HOME, ".docvy");
_paths["app.cache"] = path.join(_paths["app.home"], "cache");
_paths["app.cache.plugins"] = path.join(_paths["app.cache"], "plugins");
_paths["app.logs"] = path.join(_paths["app.home"], "logs");
_paths["app.plugins"] = path.join(_paths["app.home"], "plugins");
var target = _paths[pathname] || null;
if (target) {
mkdirp.sync(target);
}
return target;
} | javascript | function getPath(pathname) {
var _paths = { };
_paths["app.home"] = path.join(process.env.HOME, ".docvy");
_paths["app.cache"] = path.join(_paths["app.home"], "cache");
_paths["app.cache.plugins"] = path.join(_paths["app.cache"], "plugins");
_paths["app.logs"] = path.join(_paths["app.home"], "logs");
_paths["app.plugins"] = path.join(_paths["app.home"], "plugins");
var target = _paths[pathname] || null;
if (target) {
mkdirp.sync(target);
}
return target;
} | [
"function",
"getPath",
"(",
"pathname",
")",
"{",
"var",
"_paths",
"=",
"{",
"}",
";",
"_paths",
"[",
"\"app.home\"",
"]",
"=",
"path",
".",
"join",
"(",
"process",
".",
"env",
".",
"HOME",
",",
"\".docvy\"",
")",
";",
"_paths",
"[",
"\"app.cache\"",
"]",
"=",
"path",
".",
"join",
"(",
"_paths",
"[",
"\"app.home\"",
"]",
",",
"\"cache\"",
")",
";",
"_paths",
"[",
"\"app.cache.plugins\"",
"]",
"=",
"path",
".",
"join",
"(",
"_paths",
"[",
"\"app.cache\"",
"]",
",",
"\"plugins\"",
")",
";",
"_paths",
"[",
"\"app.logs\"",
"]",
"=",
"path",
".",
"join",
"(",
"_paths",
"[",
"\"app.home\"",
"]",
",",
"\"logs\"",
")",
";",
"_paths",
"[",
"\"app.plugins\"",
"]",
"=",
"path",
".",
"join",
"(",
"_paths",
"[",
"\"app.home\"",
"]",
",",
"\"plugins\"",
")",
";",
"var",
"target",
"=",
"_paths",
"[",
"pathname",
"]",
"||",
"null",
";",
"if",
"(",
"target",
")",
"{",
"mkdirp",
".",
"sync",
"(",
"target",
")",
";",
"}",
"return",
"target",
";",
"}"
] | Returns application-specific paths
@param {String} pathname - name of path
@return {String} absolute path | [
"Returns",
"application",
"-",
"specific",
"paths"
] | 9bdf093238feff6fb1741d85f7d6a443adc882ac | https://github.com/docvy/utils/blob/9bdf093238feff6fb1741d85f7d6a443adc882ac/lib/index.js#L64-L76 |
51,721 | docvy/utils | lib/index.js | defineError | function defineError(code, message) {
var ErrorClass = errors.helpers.generateClass(code);
function ExportedError(err) {
ErrorClass.call(this, message, err);
return this;
}
util.inherits(ExportedError, ErrorClass);
return ExportedError;
} | javascript | function defineError(code, message) {
var ErrorClass = errors.helpers.generateClass(code);
function ExportedError(err) {
ErrorClass.call(this, message, err);
return this;
}
util.inherits(ExportedError, ErrorClass);
return ExportedError;
} | [
"function",
"defineError",
"(",
"code",
",",
"message",
")",
"{",
"var",
"ErrorClass",
"=",
"errors",
".",
"helpers",
".",
"generateClass",
"(",
"code",
")",
";",
"function",
"ExportedError",
"(",
"err",
")",
"{",
"ErrorClass",
".",
"call",
"(",
"this",
",",
"message",
",",
"err",
")",
";",
"return",
"this",
";",
"}",
"util",
".",
"inherits",
"(",
"ExportedError",
",",
"ErrorClass",
")",
";",
"return",
"ExportedError",
";",
"}"
] | Defines an error | [
"Defines",
"an",
"error"
] | 9bdf093238feff6fb1741d85f7d6a443adc882ac | https://github.com/docvy/utils/blob/9bdf093238feff6fb1741d85f7d6a443adc882ac/lib/index.js#L82-L90 |
51,722 | philipbordallo/eslint-config | version.js | updateVersion | async function updateVersion(file) {
const { default: config } = await import(`${CONFIGS_PATH}/${file}`);
const { packageName } = config;
const packageInfoFile = `${PACKAGES_PATH}/${packageName}/package.json`;
const { default: packageInfo } = await import(packageInfoFile);
if (info.version !== packageInfo.version) {
const newPackageInfo = {
...packageInfo,
version: info.version,
};
writeFileAsync(packageInfoFile, JSON.stringify(newPackageInfo, null, ' '))
.then(
() => console.log(`Updated ${packageName} to ${info.version}`),
error => console.log(error),
);
}
} | javascript | async function updateVersion(file) {
const { default: config } = await import(`${CONFIGS_PATH}/${file}`);
const { packageName } = config;
const packageInfoFile = `${PACKAGES_PATH}/${packageName}/package.json`;
const { default: packageInfo } = await import(packageInfoFile);
if (info.version !== packageInfo.version) {
const newPackageInfo = {
...packageInfo,
version: info.version,
};
writeFileAsync(packageInfoFile, JSON.stringify(newPackageInfo, null, ' '))
.then(
() => console.log(`Updated ${packageName} to ${info.version}`),
error => console.log(error),
);
}
} | [
"async",
"function",
"updateVersion",
"(",
"file",
")",
"{",
"const",
"{",
"default",
":",
"config",
"}",
"=",
"await",
"import",
"(",
"`",
"${",
"CONFIGS_PATH",
"}",
"${",
"file",
"}",
"`",
")",
";",
"const",
"{",
"packageName",
"}",
"=",
"config",
";",
"const",
"packageInfoFile",
"=",
"`",
"${",
"PACKAGES_PATH",
"}",
"${",
"packageName",
"}",
"`",
";",
"const",
"{",
"default",
":",
"packageInfo",
"}",
"=",
"await",
"import",
"(",
"packageInfoFile",
")",
";",
"if",
"(",
"info",
".",
"version",
"!==",
"packageInfo",
".",
"version",
")",
"{",
"const",
"newPackageInfo",
"=",
"{",
"...",
"packageInfo",
",",
"version",
":",
"info",
".",
"version",
",",
"}",
";",
"writeFileAsync",
"(",
"packageInfoFile",
",",
"JSON",
".",
"stringify",
"(",
"newPackageInfo",
",",
"null",
",",
"' '",
")",
")",
".",
"then",
"(",
"(",
")",
"=>",
"console",
".",
"log",
"(",
"`",
"${",
"packageName",
"}",
"${",
"info",
".",
"version",
"}",
"`",
")",
",",
"error",
"=>",
"console",
".",
"log",
"(",
"error",
")",
",",
")",
";",
"}",
"}"
] | Update all packages to latest version
@param {string} file | [
"Update",
"all",
"packages",
"to",
"latest",
"version"
] | a2f1bff442fdb8ee622f842f075fa10d555302a4 | https://github.com/philipbordallo/eslint-config/blob/a2f1bff442fdb8ee622f842f075fa10d555302a4/version.js#L15-L34 |
51,723 | appcelerator-archive/appc-connector-utils | lib/model/api.js | createFromMetadata | function createFromMetadata (connector, modelsMetadata) {
if (!connector || !modelsMetadata) {
throw new Error('Please provide both connector and metadata so Arrow could create models')
}
const loadModels = connector.config.generateModels
return Object.keys(modelsMetadata).reduce(function (previousModels, modelName) {
const persistModels = connector.config.persistModels
if (loadModels && loadModels.indexOf(modelName) === -1) {
return previousModels
}
const metadata = modelsMetadata[modelName]
metadata.autogen = !!connector.config.modelAutogen
metadata.generated = true
metadata.connector = connector.name
metadata.name = modelName
dataValidator.validate(metadata, metadataSchema)
if (persistModels) {
utils.saveModelSync(createModelName(connector, modelName), metadata, connector.modelDir)
} else {
previousModels[modelName] = Arrow.createModel(createModelName(connector, modelName), metadata)
}
return previousModels
}, {})
} | javascript | function createFromMetadata (connector, modelsMetadata) {
if (!connector || !modelsMetadata) {
throw new Error('Please provide both connector and metadata so Arrow could create models')
}
const loadModels = connector.config.generateModels
return Object.keys(modelsMetadata).reduce(function (previousModels, modelName) {
const persistModels = connector.config.persistModels
if (loadModels && loadModels.indexOf(modelName) === -1) {
return previousModels
}
const metadata = modelsMetadata[modelName]
metadata.autogen = !!connector.config.modelAutogen
metadata.generated = true
metadata.connector = connector.name
metadata.name = modelName
dataValidator.validate(metadata, metadataSchema)
if (persistModels) {
utils.saveModelSync(createModelName(connector, modelName), metadata, connector.modelDir)
} else {
previousModels[modelName] = Arrow.createModel(createModelName(connector, modelName), metadata)
}
return previousModels
}, {})
} | [
"function",
"createFromMetadata",
"(",
"connector",
",",
"modelsMetadata",
")",
"{",
"if",
"(",
"!",
"connector",
"||",
"!",
"modelsMetadata",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please provide both connector and metadata so Arrow could create models'",
")",
"}",
"const",
"loadModels",
"=",
"connector",
".",
"config",
".",
"generateModels",
"return",
"Object",
".",
"keys",
"(",
"modelsMetadata",
")",
".",
"reduce",
"(",
"function",
"(",
"previousModels",
",",
"modelName",
")",
"{",
"const",
"persistModels",
"=",
"connector",
".",
"config",
".",
"persistModels",
"if",
"(",
"loadModels",
"&&",
"loadModels",
".",
"indexOf",
"(",
"modelName",
")",
"===",
"-",
"1",
")",
"{",
"return",
"previousModels",
"}",
"const",
"metadata",
"=",
"modelsMetadata",
"[",
"modelName",
"]",
"metadata",
".",
"autogen",
"=",
"!",
"!",
"connector",
".",
"config",
".",
"modelAutogen",
"metadata",
".",
"generated",
"=",
"true",
"metadata",
".",
"connector",
"=",
"connector",
".",
"name",
"metadata",
".",
"name",
"=",
"modelName",
"dataValidator",
".",
"validate",
"(",
"metadata",
",",
"metadataSchema",
")",
"if",
"(",
"persistModels",
")",
"{",
"utils",
".",
"saveModelSync",
"(",
"createModelName",
"(",
"connector",
",",
"modelName",
")",
",",
"metadata",
",",
"connector",
".",
"modelDir",
")",
"}",
"else",
"{",
"previousModels",
"[",
"modelName",
"]",
"=",
"Arrow",
".",
"createModel",
"(",
"createModelName",
"(",
"connector",
",",
"modelName",
")",
",",
"metadata",
")",
"}",
"return",
"previousModels",
"}",
",",
"{",
"}",
")",
"}"
] | Create models in memory on persist them on disk depending on the configured strategy.
@param {object} connector
@param {object} modelsMetadata
@return object that holds all the models or empty object in case we use persistence strategy | [
"Create",
"models",
"in",
"memory",
"on",
"persist",
"them",
"on",
"disk",
"depending",
"on",
"the",
"configured",
"strategy",
"."
] | 4af3bb7d24c5780270d7ba0ec98017b1f58f1aa8 | https://github.com/appcelerator-archive/appc-connector-utils/blob/4af3bb7d24c5780270d7ba0ec98017b1f58f1aa8/lib/model/api.js#L26-L53 |
51,724 | appcelerator-archive/appc-connector-utils | lib/model/api.js | getRootModelName | function getRootModelName (model) {
if (!model) {
throw new Error('Please provide Arrow Model')
}
const namespaceDelimiter = '/'
var parent = model
while (parent._parent && parent._parent.name) {
parent = parent._parent
}
if (!parent.name) {
throw new Error('The provided model has no name or parent with name')
}
const name = parent.name.split(namespaceDelimiter).pop()
return {
nameOnly: name,
nameOnlyPlural: pluralize(name),
withNamespace: parent.name
}
} | javascript | function getRootModelName (model) {
if (!model) {
throw new Error('Please provide Arrow Model')
}
const namespaceDelimiter = '/'
var parent = model
while (parent._parent && parent._parent.name) {
parent = parent._parent
}
if (!parent.name) {
throw new Error('The provided model has no name or parent with name')
}
const name = parent.name.split(namespaceDelimiter).pop()
return {
nameOnly: name,
nameOnlyPlural: pluralize(name),
withNamespace: parent.name
}
} | [
"function",
"getRootModelName",
"(",
"model",
")",
"{",
"if",
"(",
"!",
"model",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Please provide Arrow Model'",
")",
"}",
"const",
"namespaceDelimiter",
"=",
"'/'",
"var",
"parent",
"=",
"model",
"while",
"(",
"parent",
".",
"_parent",
"&&",
"parent",
".",
"_parent",
".",
"name",
")",
"{",
"parent",
"=",
"parent",
".",
"_parent",
"}",
"if",
"(",
"!",
"parent",
".",
"name",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The provided model has no name or parent with name'",
")",
"}",
"const",
"name",
"=",
"parent",
".",
"name",
".",
"split",
"(",
"namespaceDelimiter",
")",
".",
"pop",
"(",
")",
"return",
"{",
"nameOnly",
":",
"name",
",",
"nameOnlyPlural",
":",
"pluralize",
"(",
"name",
")",
",",
"withNamespace",
":",
"parent",
".",
"name",
"}",
"}"
] | Gets parent model name or if the model has no parent the model name itself.
@param {Arrow.Model} model the model which name must be evaluated
@return {Object} object literal that contains the clean and namespaced model name | [
"Gets",
"parent",
"model",
"name",
"or",
"if",
"the",
"model",
"has",
"no",
"parent",
"the",
"model",
"name",
"itself",
"."
] | 4af3bb7d24c5780270d7ba0ec98017b1f58f1aa8 | https://github.com/appcelerator-archive/appc-connector-utils/blob/4af3bb7d24c5780270d7ba0ec98017b1f58f1aa8/lib/model/api.js#L61-L80 |
51,725 | lotaris/api-copilot | lib/client.js | function(options) {
if (!_.isString(options.method)) {
throw new Error('"method" must be a string, got ' + options.method);
} else if (!_.isString(options.url)) {
throw new Error('"url" must be a string, got ' + options.url);
}
return options;
} | javascript | function(options) {
if (!_.isString(options.method)) {
throw new Error('"method" must be a string, got ' + options.method);
} else if (!_.isString(options.url)) {
throw new Error('"url" must be a string, got ' + options.url);
}
return options;
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"options",
".",
"method",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"method\" must be a string, got '",
"+",
"options",
".",
"method",
")",
";",
"}",
"else",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"options",
".",
"url",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"url\" must be a string, got '",
"+",
"options",
".",
"url",
")",
";",
"}",
"return",
"options",
";",
"}"
] | An error is thrown if either the `method` or the `url` option is not a string. Note that this error is caught by the promise chain and causes the returned promise to be rejected. | [
"An",
"error",
"is",
"thrown",
"if",
"either",
"the",
"method",
"or",
"the",
"url",
"option",
"is",
"not",
"a",
"string",
".",
"Note",
"that",
"this",
"error",
"is",
"caught",
"by",
"the",
"promise",
"chain",
"and",
"causes",
"the",
"returned",
"promise",
"to",
"be",
"rejected",
"."
] | 7df124602c79b8528b7fdbda1fd962e6763f2408 | https://github.com/lotaris/api-copilot/blob/7df124602c79b8528b7fdbda1fd962e6763f2408/lib/client.js#L156-L164 |
|
51,726 | lotaris/api-copilot | lib/client.js | function(filterIndex, options) {
if (options === undefined) {
throw new Error('Request filter at index ' + filterIndex + ' returned nothing; it must return the filtered request options');
} else if (!_.isObject(options)) {
throw new Error('Expected request filter at index ' + filterIndex + ' to return the request options as an object, got ' + typeof(options));
}
return options;
} | javascript | function(filterIndex, options) {
if (options === undefined) {
throw new Error('Request filter at index ' + filterIndex + ' returned nothing; it must return the filtered request options');
} else if (!_.isObject(options)) {
throw new Error('Expected request filter at index ' + filterIndex + ' to return the request options as an object, got ' + typeof(options));
}
return options;
} | [
"function",
"(",
"filterIndex",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Request filter at index '",
"+",
"filterIndex",
"+",
"' returned nothing; it must return the filtered request options'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"options",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected request filter at index '",
"+",
"filterIndex",
"+",
"' to return the request options as an object, got '",
"+",
"typeof",
"(",
"options",
")",
")",
";",
"}",
"return",
"options",
";",
"}"
] | After each filter, this check ensures that the returned request options are valid. Again, any error is caught by the promise chain and causes the returned promise to be rejected. | [
"After",
"each",
"filter",
"this",
"check",
"ensures",
"that",
"the",
"returned",
"request",
"options",
"are",
"valid",
".",
"Again",
"any",
"error",
"is",
"caught",
"by",
"the",
"promise",
"chain",
"and",
"causes",
"the",
"returned",
"promise",
"to",
"be",
"rejected",
"."
] | 7df124602c79b8528b7fdbda1fd962e6763f2408 | https://github.com/lotaris/api-copilot/blob/7df124602c79b8528b7fdbda1fd962e6763f2408/lib/client.js#L199-L207 |
|
51,727 | billinghamj/resilient-mailer-mailjet | lib/mailjet-provider.js | MailjetProvider | function MailjetProvider(apiKey, apiSecret, options) {
if (typeof apiKey !== 'string'
|| typeof apiSecret !== 'string') {
throw new Error('Invalid parameters');
}
options = options || {};
if (typeof options.apiSecure === 'undefined')
options.apiSecure = true;
options.apiHostname = options.apiHostname || 'api.mailjet.com';
options.apiPort = options.apiPort || (options.apiSecure ? 443 : 80);
this.apiKey = apiKey;
this.apiSecret = apiSecret;
this.options = options;
} | javascript | function MailjetProvider(apiKey, apiSecret, options) {
if (typeof apiKey !== 'string'
|| typeof apiSecret !== 'string') {
throw new Error('Invalid parameters');
}
options = options || {};
if (typeof options.apiSecure === 'undefined')
options.apiSecure = true;
options.apiHostname = options.apiHostname || 'api.mailjet.com';
options.apiPort = options.apiPort || (options.apiSecure ? 443 : 80);
this.apiKey = apiKey;
this.apiSecret = apiSecret;
this.options = options;
} | [
"function",
"MailjetProvider",
"(",
"apiKey",
",",
"apiSecret",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"apiKey",
"!==",
"'string'",
"||",
"typeof",
"apiSecret",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid parameters'",
")",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"options",
".",
"apiSecure",
"===",
"'undefined'",
")",
"options",
".",
"apiSecure",
"=",
"true",
";",
"options",
".",
"apiHostname",
"=",
"options",
".",
"apiHostname",
"||",
"'api.mailjet.com'",
";",
"options",
".",
"apiPort",
"=",
"options",
".",
"apiPort",
"||",
"(",
"options",
".",
"apiSecure",
"?",
"443",
":",
"80",
")",
";",
"this",
".",
"apiKey",
"=",
"apiKey",
";",
"this",
".",
"apiSecret",
"=",
"apiSecret",
";",
"this",
".",
"options",
"=",
"options",
";",
"}"
] | Creates an instance of the Mailjet email provider.
@constructor
@this {MailjetProvider}
@param {string} apiKey API Key for the Mailjet account.
@param {string} apiSecret API Key for the Mailjet account.
@param {object} [options] Additional optional configuration.
@param {boolean} [options.apiSecure=true] API connection protocol - true = HTTPS, false = HTTP
@param {string} [options.apiHostname=api.mailjet.com] Hostname for the API connection
@param {number} [options.apiPort] Port for the API connection - defaults to match the protocol (HTTPS-443, HTTP-80) | [
"Creates",
"an",
"instance",
"of",
"the",
"Mailjet",
"email",
"provider",
"."
] | b02d7eeae020b83db8468f214870ba9b9207f994 | https://github.com/billinghamj/resilient-mailer-mailjet/blob/b02d7eeae020b83db8468f214870ba9b9207f994/lib/mailjet-provider.js#L19-L36 |
51,728 | gethuman/pancakes-recipe | utils/date.formater.js | getFormattedDate | function getFormattedDate(date, lang, type) {
date = date || new Date();
lang = lang || 'en';
type = type || 'long';
// set the language for en
if (lang === 'en' && type === 'short') { lang = 'enshort'; }
if (lang === 'en' && type === 'medium') { lang = 'enmedium'; }
// get the date string
return moment(date).locale(lang).fromNow();
} | javascript | function getFormattedDate(date, lang, type) {
date = date || new Date();
lang = lang || 'en';
type = type || 'long';
// set the language for en
if (lang === 'en' && type === 'short') { lang = 'enshort'; }
if (lang === 'en' && type === 'medium') { lang = 'enmedium'; }
// get the date string
return moment(date).locale(lang).fromNow();
} | [
"function",
"getFormattedDate",
"(",
"date",
",",
"lang",
",",
"type",
")",
"{",
"date",
"=",
"date",
"||",
"new",
"Date",
"(",
")",
";",
"lang",
"=",
"lang",
"||",
"'en'",
";",
"type",
"=",
"type",
"||",
"'long'",
";",
"// set the language for en",
"if",
"(",
"lang",
"===",
"'en'",
"&&",
"type",
"===",
"'short'",
")",
"{",
"lang",
"=",
"'enshort'",
";",
"}",
"if",
"(",
"lang",
"===",
"'en'",
"&&",
"type",
"===",
"'medium'",
")",
"{",
"lang",
"=",
"'enmedium'",
";",
"}",
"// get the date string",
"return",
"moment",
"(",
"date",
")",
".",
"locale",
"(",
"lang",
")",
".",
"fromNow",
"(",
")",
";",
"}"
] | Use moment to format the date
@param date
@param lang
@param type
@returns {*} | [
"Use",
"moment",
"to",
"format",
"the",
"date"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/utils/date.formater.js#L100-L111 |
51,729 | Insorum/hubot-youtube-feed | src/lib/notification-list.js | function (username, channel) {
var userChannels = this.getUserNotifications(username);
// if the user doesn't already have an entry add one
if (userChannels === null) {
userChannels = [];
// update the user to add them to the latest videos list
this.latestVideos.getLatestVideos(username);
this.notifications.push({
username: username,
channels: userChannels
});
}
// dont allow duplicate channel names
if (userChannels.indexOf(channel) !== -1) {
return false;
}
// add the channel to the user and save data
userChannels.push(channel);
this.saveNotifications();
return true;
} | javascript | function (username, channel) {
var userChannels = this.getUserNotifications(username);
// if the user doesn't already have an entry add one
if (userChannels === null) {
userChannels = [];
// update the user to add them to the latest videos list
this.latestVideos.getLatestVideos(username);
this.notifications.push({
username: username,
channels: userChannels
});
}
// dont allow duplicate channel names
if (userChannels.indexOf(channel) !== -1) {
return false;
}
// add the channel to the user and save data
userChannels.push(channel);
this.saveNotifications();
return true;
} | [
"function",
"(",
"username",
",",
"channel",
")",
"{",
"var",
"userChannels",
"=",
"this",
".",
"getUserNotifications",
"(",
"username",
")",
";",
"// if the user doesn't already have an entry add one",
"if",
"(",
"userChannels",
"===",
"null",
")",
"{",
"userChannels",
"=",
"[",
"]",
";",
"// update the user to add them to the latest videos list",
"this",
".",
"latestVideos",
".",
"getLatestVideos",
"(",
"username",
")",
";",
"this",
".",
"notifications",
".",
"push",
"(",
"{",
"username",
":",
"username",
",",
"channels",
":",
"userChannels",
"}",
")",
";",
"}",
"// dont allow duplicate channel names",
"if",
"(",
"userChannels",
".",
"indexOf",
"(",
"channel",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// add the channel to the user and save data",
"userChannels",
".",
"push",
"(",
"channel",
")",
";",
"this",
".",
"saveNotifications",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Adds the given username to the list of names for notifications
@param {string} username - The account name to check for
@param {string} channel - The channel to send the notification to
@returns {boolean} true if added, false if already in the list | [
"Adds",
"the",
"given",
"username",
"to",
"the",
"list",
"of",
"names",
"for",
"notifications"
] | 6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b | https://github.com/Insorum/hubot-youtube-feed/blob/6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b/src/lib/notification-list.js#L45-L70 |
|
51,730 | Insorum/hubot-youtube-feed | src/lib/notification-list.js | function (username, channel) {
var userChannels = this.getUserNotifications(username);
// dont remove if they dont exist
if (userChannels === null) {
return false;
}
var index = userChannels.indexOf(channel);
// dont remove if the channel doesnt exist
if (index < 0) {
return false;
}
// remove the channel
userChannels.splice(index, 1);
//if no channels left remove the entire user
if (userChannels.length === 0) {
var userIndex = -1;
this.notifications.some(function (element, index) {
if (element.username === username) {
userIndex = index;
return true;
}
return false;
});
this.notifications.splice(userIndex, 1);
this.latestVideos.removeUser(username);
}
// save the new data
this.saveNotifications();
return true;
} | javascript | function (username, channel) {
var userChannels = this.getUserNotifications(username);
// dont remove if they dont exist
if (userChannels === null) {
return false;
}
var index = userChannels.indexOf(channel);
// dont remove if the channel doesnt exist
if (index < 0) {
return false;
}
// remove the channel
userChannels.splice(index, 1);
//if no channels left remove the entire user
if (userChannels.length === 0) {
var userIndex = -1;
this.notifications.some(function (element, index) {
if (element.username === username) {
userIndex = index;
return true;
}
return false;
});
this.notifications.splice(userIndex, 1);
this.latestVideos.removeUser(username);
}
// save the new data
this.saveNotifications();
return true;
} | [
"function",
"(",
"username",
",",
"channel",
")",
"{",
"var",
"userChannels",
"=",
"this",
".",
"getUserNotifications",
"(",
"username",
")",
";",
"// dont remove if they dont exist",
"if",
"(",
"userChannels",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"var",
"index",
"=",
"userChannels",
".",
"indexOf",
"(",
"channel",
")",
";",
"// dont remove if the channel doesnt exist",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"return",
"false",
";",
"}",
"// remove the channel",
"userChannels",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"//if no channels left remove the entire user",
"if",
"(",
"userChannels",
".",
"length",
"===",
"0",
")",
"{",
"var",
"userIndex",
"=",
"-",
"1",
";",
"this",
".",
"notifications",
".",
"some",
"(",
"function",
"(",
"element",
",",
"index",
")",
"{",
"if",
"(",
"element",
".",
"username",
"===",
"username",
")",
"{",
"userIndex",
"=",
"index",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"this",
".",
"notifications",
".",
"splice",
"(",
"userIndex",
",",
"1",
")",
";",
"this",
".",
"latestVideos",
".",
"removeUser",
"(",
"username",
")",
";",
"}",
"// save the new data",
"this",
".",
"saveNotifications",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Removes the given username from the list of names for notifications
@param {string} username - The account name to check for
@param {string} channel - The channel to send notifications to
@returns {boolean} true if removed, false if didn't exist | [
"Removes",
"the",
"given",
"username",
"from",
"the",
"list",
"of",
"names",
"for",
"notifications"
] | 6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b | https://github.com/Insorum/hubot-youtube-feed/blob/6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b/src/lib/notification-list.js#L79-L114 |
|
51,731 | Insorum/hubot-youtube-feed | src/lib/notification-list.js | function (username, channel) {
var list = this.getUserNotifications(username);
// if we are not tracking the user there is no notifications
if (list === null) {
return false;
}
// return if the channel is in the users list
return list.indexOf(channel) >= 0;
} | javascript | function (username, channel) {
var list = this.getUserNotifications(username);
// if we are not tracking the user there is no notifications
if (list === null) {
return false;
}
// return if the channel is in the users list
return list.indexOf(channel) >= 0;
} | [
"function",
"(",
"username",
",",
"channel",
")",
"{",
"var",
"list",
"=",
"this",
".",
"getUserNotifications",
"(",
"username",
")",
";",
"// if we are not tracking the user there is no notifications",
"if",
"(",
"list",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"// return if the channel is in the users list",
"return",
"list",
".",
"indexOf",
"(",
"channel",
")",
">=",
"0",
";",
"}"
] | Is the username setup for notifications?
@param {string} username - The account name to check for
@param {string} channel - The channel to notify in
@returns {boolean} true if in list, false otherwise | [
"Is",
"the",
"username",
"setup",
"for",
"notifications?"
] | 6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b | https://github.com/Insorum/hubot-youtube-feed/blob/6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b/src/lib/notification-list.js#L122-L131 |
|
51,732 | Insorum/hubot-youtube-feed | src/lib/notification-list.js | function (username) {
var channels = null;
// get the user's object
this.notifications.some(function (element) {
if (element.username === username) {
channels = element.channels;
return true;
}
return false;
});
return channels;
} | javascript | function (username) {
var channels = null;
// get the user's object
this.notifications.some(function (element) {
if (element.username === username) {
channels = element.channels;
return true;
}
return false;
});
return channels;
} | [
"function",
"(",
"username",
")",
"{",
"var",
"channels",
"=",
"null",
";",
"// get the user's object",
"this",
".",
"notifications",
".",
"some",
"(",
"function",
"(",
"element",
")",
"{",
"if",
"(",
"element",
".",
"username",
"===",
"username",
")",
"{",
"channels",
"=",
"element",
".",
"channels",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"return",
"channels",
";",
"}"
] | Returns a list of channels the user is notifying for or null if not found
@param {string} username
@returns {string[]|null} | [
"Returns",
"a",
"list",
"of",
"channels",
"the",
"user",
"is",
"notifying",
"for",
"or",
"null",
"if",
"not",
"found"
] | 6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b | https://github.com/Insorum/hubot-youtube-feed/blob/6f55979733fd75c3bb7b8ba0b15ed8da99f85d4b/src/lib/notification-list.js#L138-L149 |
|
51,733 | savushkin-yauheni/our-connect | lib/connect.js | createServer | function createServer() {
function app(req, res, next){ app.handle(req, res, function(){
res.end("", 'utf8');
}); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} | javascript | function createServer() {
function app(req, res, next){ app.handle(req, res, function(){
res.end("", 'utf8');
}); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} | [
"function",
"createServer",
"(",
")",
"{",
"function",
"app",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"app",
".",
"handle",
"(",
"req",
",",
"res",
",",
"function",
"(",
")",
"{",
"res",
".",
"end",
"(",
"\"\"",
",",
"'utf8'",
")",
";",
"}",
")",
";",
"}",
"merge",
"(",
"app",
",",
"proto",
")",
";",
"merge",
"(",
"app",
",",
"EventEmitter",
".",
"prototype",
")",
";",
"app",
".",
"route",
"=",
"'/'",
";",
"app",
".",
"stack",
"=",
"[",
"]",
";",
"return",
"app",
";",
"}"
] | Create a new connect server.
@return {Function}
@api public | [
"Create",
"a",
"new",
"connect",
"server",
"."
] | aa327a2a87a788535b1e5f6be5503a4419d3aabf | https://github.com/savushkin-yauheni/our-connect/blob/aa327a2a87a788535b1e5f6be5503a4419d3aabf/lib/connect.js#L27-L36 |
51,734 | AndreasMadsen/thintalk | lib/core/abstract.js | Request | function Request(method, args, callback) {
this.handle.send('layer', [method, args], function (content) {
callback.apply({}, content);
});
} | javascript | function Request(method, args, callback) {
this.handle.send('layer', [method, args], function (content) {
callback.apply({}, content);
});
} | [
"function",
"Request",
"(",
"method",
",",
"args",
",",
"callback",
")",
"{",
"this",
".",
"handle",
".",
"send",
"(",
"'layer'",
",",
"[",
"method",
",",
"args",
"]",
",",
"function",
"(",
"content",
")",
"{",
"callback",
".",
"apply",
"(",
"{",
"}",
",",
"content",
")",
";",
"}",
")",
";",
"}"
] | Internal RPC - used by transport layers | [
"Internal",
"RPC",
"-",
"used",
"by",
"transport",
"layers"
] | 1ea0c2703d303874fc50d8efb2013ee4d7dadeb1 | https://github.com/AndreasMadsen/thintalk/blob/1ea0c2703d303874fc50d8efb2013ee4d7dadeb1/lib/core/abstract.js#L24-L28 |
51,735 | jgnewman/brightsocket.io | bin/socketpool.js | runAsyncMiddleware | function runAsyncMiddleware(wares, event, payload, callback) {
if (wares.length) {
var ware = wares[0];
var restWares = wares.slice(1);
ware(event, payload, function () {
runAsyncMiddleware(restWares, event, payload, callback);
});
} else {
callback && callback(payload);
}
} | javascript | function runAsyncMiddleware(wares, event, payload, callback) {
if (wares.length) {
var ware = wares[0];
var restWares = wares.slice(1);
ware(event, payload, function () {
runAsyncMiddleware(restWares, event, payload, callback);
});
} else {
callback && callback(payload);
}
} | [
"function",
"runAsyncMiddleware",
"(",
"wares",
",",
"event",
",",
"payload",
",",
"callback",
")",
"{",
"if",
"(",
"wares",
".",
"length",
")",
"{",
"var",
"ware",
"=",
"wares",
"[",
"0",
"]",
";",
"var",
"restWares",
"=",
"wares",
".",
"slice",
"(",
"1",
")",
";",
"ware",
"(",
"event",
",",
"payload",
",",
"function",
"(",
")",
"{",
"runAsyncMiddleware",
"(",
"restWares",
",",
"event",
",",
"payload",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"&&",
"callback",
"(",
"payload",
")",
";",
"}",
"}"
] | Executes each function in a list of asynchronous functions. Each one
is given an argument we call `next`. The only way to get to the next
function in the list is to call `next`. If you don't, the process is
halted.
@param {Array} wares A list of possibly asynchronous functions.
@param {String} event The name of a socket event.
@param {Any} payload The body of the socket message.
@param {Function} callback A function to run after all middleware is executed.
@return {undefined} | [
"Executes",
"each",
"function",
"in",
"a",
"list",
"of",
"asynchronous",
"functions",
".",
"Each",
"one",
"is",
"given",
"an",
"argument",
"we",
"call",
"next",
".",
"The",
"only",
"way",
"to",
"get",
"to",
"the",
"next",
"function",
"in",
"the",
"list",
"is",
"to",
"call",
"next",
".",
"If",
"you",
"don",
"t",
"the",
"process",
"is",
"halted",
"."
] | 19ec67d69946ab09ca389143ebbdcb0a7f22f950 | https://github.com/jgnewman/brightsocket.io/blob/19ec67d69946ab09ca389143ebbdcb0a7f22f950/bin/socketpool.js#L95-L105 |
51,736 | mridevteam/validity_checks | src/isEmptyObject.js | isEmptyObject | function isEmptyObject(item) {
if (item === undefined || item === null) {
return false;
}
return (Object.keys(item).length === 0 && JSON.stringify(item) === JSON.stringify({}));
} | javascript | function isEmptyObject(item) {
if (item === undefined || item === null) {
return false;
}
return (Object.keys(item).length === 0 && JSON.stringify(item) === JSON.stringify({}));
} | [
"function",
"isEmptyObject",
"(",
"item",
")",
"{",
"if",
"(",
"item",
"===",
"undefined",
"||",
"item",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"Object",
".",
"keys",
"(",
"item",
")",
".",
"length",
"===",
"0",
"&&",
"JSON",
".",
"stringify",
"(",
"item",
")",
"===",
"JSON",
".",
"stringify",
"(",
"{",
"}",
")",
")",
";",
"}"
] | Checks to see if a passed in item is an empty
http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
@param {*} item
@returns {boolean} isEmptyObject - is this value a pojo | [
"Checks",
"to",
"see",
"if",
"a",
"passed",
"in",
"item",
"is",
"an",
"empty"
] | e4990c7bbba23f5def0917f80990825748d054a1 | https://github.com/mridevteam/validity_checks/blob/e4990c7bbba23f5def0917f80990825748d054a1/src/isEmptyObject.js#L9-L15 |
51,737 | redisjs/jsr-server | lib/command/server/info.js | execute | function execute(req, res) {
res.send(null, this.info.toString(req.args[0] ? '' + req.args[0] : null));
} | javascript | function execute(req, res) {
res.send(null, this.info.toString(req.args[0] ? '' + req.args[0] : null));
} | [
"function",
"execute",
"(",
"req",
",",
"res",
")",
"{",
"res",
".",
"send",
"(",
"null",
",",
"this",
".",
"info",
".",
"toString",
"(",
"req",
".",
"args",
"[",
"0",
"]",
"?",
"''",
"+",
"req",
".",
"args",
"[",
"0",
"]",
":",
"null",
")",
")",
";",
"}"
] | Respond to the INFO command. | [
"Respond",
"to",
"the",
"INFO",
"command",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/info.js#L17-L19 |
51,738 | tolokoban/ToloFrameWork | ker/mod/dom.fx.js | next | function next( session ) {
if ( session !== this._session ) return;
if ( this._index >= this._tasks.length ) {
this._index = 0;
this._started = false;
delete this._session;
this._onEnd( this );
return;
}
const
that = this,
tsk = this._tasks[ this._index++ ];
if ( this._debug ) {
console.info(
`[dom.fx] tsk[${this._index - 1}]: `, tsk.label,
`(${Date.now() - this._startTime} ms)`, tsk.args, session
);
}
tsk( function () {
delay( next.bind( that, session ) );
}, true );
} | javascript | function next( session ) {
if ( session !== this._session ) return;
if ( this._index >= this._tasks.length ) {
this._index = 0;
this._started = false;
delete this._session;
this._onEnd( this );
return;
}
const
that = this,
tsk = this._tasks[ this._index++ ];
if ( this._debug ) {
console.info(
`[dom.fx] tsk[${this._index - 1}]: `, tsk.label,
`(${Date.now() - this._startTime} ms)`, tsk.args, session
);
}
tsk( function () {
delay( next.bind( that, session ) );
}, true );
} | [
"function",
"next",
"(",
"session",
")",
"{",
"if",
"(",
"session",
"!==",
"this",
".",
"_session",
")",
"return",
";",
"if",
"(",
"this",
".",
"_index",
">=",
"this",
".",
"_tasks",
".",
"length",
")",
"{",
"this",
".",
"_index",
"=",
"0",
";",
"this",
".",
"_started",
"=",
"false",
";",
"delete",
"this",
".",
"_session",
";",
"this",
".",
"_onEnd",
"(",
"this",
")",
";",
"return",
";",
"}",
"const",
"that",
"=",
"this",
",",
"tsk",
"=",
"this",
".",
"_tasks",
"[",
"this",
".",
"_index",
"++",
"]",
";",
"if",
"(",
"this",
".",
"_debug",
")",
"{",
"console",
".",
"info",
"(",
"`",
"${",
"this",
".",
"_index",
"-",
"1",
"}",
"`",
",",
"tsk",
".",
"label",
",",
"`",
"${",
"Date",
".",
"now",
"(",
")",
"-",
"this",
".",
"_startTime",
"}",
"`",
",",
"tsk",
".",
"args",
",",
"session",
")",
";",
"}",
"tsk",
"(",
"function",
"(",
")",
"{",
"delay",
"(",
"next",
".",
"bind",
"(",
"that",
",",
"session",
")",
")",
";",
"}",
",",
"true",
")",
";",
"}"
] | Next step of the animation.
@this Fx
@param {object} session - ``{ $id }
@returns {undefined} | [
"Next",
"step",
"of",
"the",
"animation",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/dom.fx.js#L70-L92 |
51,739 | tjmonsi/littleq-router | demo/script/main.js | combineReducers | function combineReducers(reducers) {
var reducerKeys = Object.keys(reducers);
var finalReducers = {};
for (var i = 0; i < reducerKeys.length; i++) {
var key = reducerKeys[i];
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
(0, _warning2.default)('No reducer provided for key "' + key + '"');
}
}
if (typeof reducers[key] === 'function') {
finalReducers[key] = reducers[key];
}
}
var finalReducerKeys = Object.keys(finalReducers);
var unexpectedKeyCache = void 0;
if (process.env.NODE_ENV !== 'production') {
unexpectedKeyCache = {};
}
var shapeAssertionError = void 0;
try {
assertReducerShape(finalReducers);
} catch (e) {
shapeAssertionError = e;
}
return function combination() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments[1];
if (shapeAssertionError) {
throw shapeAssertionError;
}
if (process.env.NODE_ENV !== 'production') {
var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
if (warningMessage) {
(0, _warning2.default)(warningMessage);
}
}
var hasChanged = false;
var nextState = {};
for (var _i = 0; _i < finalReducerKeys.length; _i++) {
var _key = finalReducerKeys[_i];
var reducer = finalReducers[_key];
var previousStateForKey = state[_key];
var nextStateForKey = reducer(previousStateForKey, action);
if (typeof nextStateForKey === 'undefined') {
var errorMessage = getUndefinedStateErrorMessage(_key, action);
throw new Error(errorMessage);
}
nextState[_key] = nextStateForKey;
hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
}
return hasChanged ? nextState : state;
};
} | javascript | function combineReducers(reducers) {
var reducerKeys = Object.keys(reducers);
var finalReducers = {};
for (var i = 0; i < reducerKeys.length; i++) {
var key = reducerKeys[i];
if (process.env.NODE_ENV !== 'production') {
if (typeof reducers[key] === 'undefined') {
(0, _warning2.default)('No reducer provided for key "' + key + '"');
}
}
if (typeof reducers[key] === 'function') {
finalReducers[key] = reducers[key];
}
}
var finalReducerKeys = Object.keys(finalReducers);
var unexpectedKeyCache = void 0;
if (process.env.NODE_ENV !== 'production') {
unexpectedKeyCache = {};
}
var shapeAssertionError = void 0;
try {
assertReducerShape(finalReducers);
} catch (e) {
shapeAssertionError = e;
}
return function combination() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments[1];
if (shapeAssertionError) {
throw shapeAssertionError;
}
if (process.env.NODE_ENV !== 'production') {
var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
if (warningMessage) {
(0, _warning2.default)(warningMessage);
}
}
var hasChanged = false;
var nextState = {};
for (var _i = 0; _i < finalReducerKeys.length; _i++) {
var _key = finalReducerKeys[_i];
var reducer = finalReducers[_key];
var previousStateForKey = state[_key];
var nextStateForKey = reducer(previousStateForKey, action);
if (typeof nextStateForKey === 'undefined') {
var errorMessage = getUndefinedStateErrorMessage(_key, action);
throw new Error(errorMessage);
}
nextState[_key] = nextStateForKey;
hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
}
return hasChanged ? nextState : state;
};
} | [
"function",
"combineReducers",
"(",
"reducers",
")",
"{",
"var",
"reducerKeys",
"=",
"Object",
".",
"keys",
"(",
"reducers",
")",
";",
"var",
"finalReducers",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"reducerKeys",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"reducerKeys",
"[",
"i",
"]",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"if",
"(",
"typeof",
"reducers",
"[",
"key",
"]",
"===",
"'undefined'",
")",
"{",
"(",
"0",
",",
"_warning2",
".",
"default",
")",
"(",
"'No reducer provided for key \"'",
"+",
"key",
"+",
"'\"'",
")",
";",
"}",
"}",
"if",
"(",
"typeof",
"reducers",
"[",
"key",
"]",
"===",
"'function'",
")",
"{",
"finalReducers",
"[",
"key",
"]",
"=",
"reducers",
"[",
"key",
"]",
";",
"}",
"}",
"var",
"finalReducerKeys",
"=",
"Object",
".",
"keys",
"(",
"finalReducers",
")",
";",
"var",
"unexpectedKeyCache",
"=",
"void",
"0",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"unexpectedKeyCache",
"=",
"{",
"}",
";",
"}",
"var",
"shapeAssertionError",
"=",
"void",
"0",
";",
"try",
"{",
"assertReducerShape",
"(",
"finalReducers",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"shapeAssertionError",
"=",
"e",
";",
"}",
"return",
"function",
"combination",
"(",
")",
"{",
"var",
"state",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"action",
"=",
"arguments",
"[",
"1",
"]",
";",
"if",
"(",
"shapeAssertionError",
")",
"{",
"throw",
"shapeAssertionError",
";",
"}",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"var",
"warningMessage",
"=",
"getUnexpectedStateShapeWarningMessage",
"(",
"state",
",",
"finalReducers",
",",
"action",
",",
"unexpectedKeyCache",
")",
";",
"if",
"(",
"warningMessage",
")",
"{",
"(",
"0",
",",
"_warning2",
".",
"default",
")",
"(",
"warningMessage",
")",
";",
"}",
"}",
"var",
"hasChanged",
"=",
"false",
";",
"var",
"nextState",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
";",
"_i",
"<",
"finalReducerKeys",
".",
"length",
";",
"_i",
"++",
")",
"{",
"var",
"_key",
"=",
"finalReducerKeys",
"[",
"_i",
"]",
";",
"var",
"reducer",
"=",
"finalReducers",
"[",
"_key",
"]",
";",
"var",
"previousStateForKey",
"=",
"state",
"[",
"_key",
"]",
";",
"var",
"nextStateForKey",
"=",
"reducer",
"(",
"previousStateForKey",
",",
"action",
")",
";",
"if",
"(",
"typeof",
"nextStateForKey",
"===",
"'undefined'",
")",
"{",
"var",
"errorMessage",
"=",
"getUndefinedStateErrorMessage",
"(",
"_key",
",",
"action",
")",
";",
"throw",
"new",
"Error",
"(",
"errorMessage",
")",
";",
"}",
"nextState",
"[",
"_key",
"]",
"=",
"nextStateForKey",
";",
"hasChanged",
"=",
"hasChanged",
"||",
"nextStateForKey",
"!==",
"previousStateForKey",
";",
"}",
"return",
"hasChanged",
"?",
"nextState",
":",
"state",
";",
"}",
";",
"}"
] | Turns an object whose values are different reducer functions, into a single
reducer function. It will call every child reducer, and gather their results
into a single state object, whose keys correspond to the keys of the passed
reducer functions.
@param {Object} reducers An object whose values correspond to different
reducer functions that need to be combined into one. One handy way to obtain
it is to use ES6 `import * as reducers` syntax. The reducers may never return
undefined for any action. Instead, they should return their initial state
if the state passed to them was undefined, and the current state for any
unrecognized action.
@returns {Function} A reducer function that invokes every reducer inside the
passed object, and builds a state object with the same shape. | [
"Turns",
"an",
"object",
"whose",
"values",
"are",
"different",
"reducer",
"functions",
"into",
"a",
"single",
"reducer",
"function",
".",
"It",
"will",
"call",
"every",
"child",
"reducer",
"and",
"gather",
"their",
"results",
"into",
"a",
"single",
"state",
"object",
"whose",
"keys",
"correspond",
"to",
"the",
"keys",
"of",
"the",
"passed",
"reducer",
"functions",
"."
] | 38c766a6de8e3e061c7c3d359c995ec06336b4db | https://github.com/tjmonsi/littleq-router/blob/38c766a6de8e3e061c7c3d359c995ec06336b4db/demo/script/main.js#L2823-L2884 |
51,740 | tjmonsi/littleq-router | demo/script/main.js | bind | function bind(element, properties) {
var bindings = Object.keys(properties).filter(function (name) {
var property = properties[name];
if (Object.prototype.hasOwnProperty.call(property, 'statePath')) {
if (!property.readOnly && property.notify) {
console.warn('PolymerRedux: <' + element.constructor.is + '>.' + name + ' has "notify" enabled, two-way bindings goes against Redux\'s paradigm');
}
return true;
}
return false;
});
/**
* Updates an element's properties with the given state.
*
* @private
* @param {Object} state
*/
var update = function update(state) {
var propertiesChanged = false;
bindings.forEach(function (name) {
// Perhaps .reduce() to a boolean?
var statePath = properties[name].statePath;
var value = typeof statePath === 'function' ? statePath.call(element, state) : (0, _path.get)(state, statePath);
var changed = element._setPendingPropertyOrPath(name, value, true);
propertiesChanged = propertiesChanged || changed;
});
if (propertiesChanged) {
element._invalidateProperties();
}
};
// Redux listener
var unsubscribe = store.subscribe(function () {
var detail = store.getState();
update(detail);
element.dispatchEvent(new window.CustomEvent('state-changed', { detail: detail }));
});
subscribers.set(element, unsubscribe);
return update(store.getState());
} | javascript | function bind(element, properties) {
var bindings = Object.keys(properties).filter(function (name) {
var property = properties[name];
if (Object.prototype.hasOwnProperty.call(property, 'statePath')) {
if (!property.readOnly && property.notify) {
console.warn('PolymerRedux: <' + element.constructor.is + '>.' + name + ' has "notify" enabled, two-way bindings goes against Redux\'s paradigm');
}
return true;
}
return false;
});
/**
* Updates an element's properties with the given state.
*
* @private
* @param {Object} state
*/
var update = function update(state) {
var propertiesChanged = false;
bindings.forEach(function (name) {
// Perhaps .reduce() to a boolean?
var statePath = properties[name].statePath;
var value = typeof statePath === 'function' ? statePath.call(element, state) : (0, _path.get)(state, statePath);
var changed = element._setPendingPropertyOrPath(name, value, true);
propertiesChanged = propertiesChanged || changed;
});
if (propertiesChanged) {
element._invalidateProperties();
}
};
// Redux listener
var unsubscribe = store.subscribe(function () {
var detail = store.getState();
update(detail);
element.dispatchEvent(new window.CustomEvent('state-changed', { detail: detail }));
});
subscribers.set(element, unsubscribe);
return update(store.getState());
} | [
"function",
"bind",
"(",
"element",
",",
"properties",
")",
"{",
"var",
"bindings",
"=",
"Object",
".",
"keys",
"(",
"properties",
")",
".",
"filter",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"property",
"=",
"properties",
"[",
"name",
"]",
";",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"property",
",",
"'statePath'",
")",
")",
"{",
"if",
"(",
"!",
"property",
".",
"readOnly",
"&&",
"property",
".",
"notify",
")",
"{",
"console",
".",
"warn",
"(",
"'PolymerRedux: <'",
"+",
"element",
".",
"constructor",
".",
"is",
"+",
"'>.'",
"+",
"name",
"+",
"' has \"notify\" enabled, two-way bindings goes against Redux\\'s paradigm'",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"/**\n * Updates an element's properties with the given state.\n *\n * @private\n * @param {Object} state\n */",
"var",
"update",
"=",
"function",
"update",
"(",
"state",
")",
"{",
"var",
"propertiesChanged",
"=",
"false",
";",
"bindings",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"// Perhaps .reduce() to a boolean?",
"var",
"statePath",
"=",
"properties",
"[",
"name",
"]",
".",
"statePath",
";",
"var",
"value",
"=",
"typeof",
"statePath",
"===",
"'function'",
"?",
"statePath",
".",
"call",
"(",
"element",
",",
"state",
")",
":",
"(",
"0",
",",
"_path",
".",
"get",
")",
"(",
"state",
",",
"statePath",
")",
";",
"var",
"changed",
"=",
"element",
".",
"_setPendingPropertyOrPath",
"(",
"name",
",",
"value",
",",
"true",
")",
";",
"propertiesChanged",
"=",
"propertiesChanged",
"||",
"changed",
";",
"}",
")",
";",
"if",
"(",
"propertiesChanged",
")",
"{",
"element",
".",
"_invalidateProperties",
"(",
")",
";",
"}",
"}",
";",
"// Redux listener",
"var",
"unsubscribe",
"=",
"store",
".",
"subscribe",
"(",
"function",
"(",
")",
"{",
"var",
"detail",
"=",
"store",
".",
"getState",
"(",
")",
";",
"update",
"(",
"detail",
")",
";",
"element",
".",
"dispatchEvent",
"(",
"new",
"window",
".",
"CustomEvent",
"(",
"'state-changed'",
",",
"{",
"detail",
":",
"detail",
"}",
")",
")",
";",
"}",
")",
";",
"subscribers",
".",
"set",
"(",
"element",
",",
"unsubscribe",
")",
";",
"return",
"update",
"(",
"store",
".",
"getState",
"(",
")",
")",
";",
"}"
] | Binds element's properties to state changes from the Redux store.
@example
const update = bind(el, props) // set bindings
update(state) // manual update
@private
@param {HTMLElement} element
@param {Object} properties
@return {Function} Update function. | [
"Binds",
"element",
"s",
"properties",
"to",
"state",
"changes",
"from",
"the",
"Redux",
"store",
"."
] | 38c766a6de8e3e061c7c3d359c995ec06336b4db | https://github.com/tjmonsi/littleq-router/blob/38c766a6de8e3e061c7c3d359c995ec06336b4db/demo/script/main.js#L3082-L3127 |
51,741 | tjmonsi/littleq-router | demo/script/main.js | update | function update(state) {
var propertiesChanged = false;
bindings.forEach(function (name) {
// Perhaps .reduce() to a boolean?
var statePath = properties[name].statePath;
var value = typeof statePath === 'function' ? statePath.call(element, state) : (0, _path.get)(state, statePath);
var changed = element._setPendingPropertyOrPath(name, value, true);
propertiesChanged = propertiesChanged || changed;
});
if (propertiesChanged) {
element._invalidateProperties();
}
} | javascript | function update(state) {
var propertiesChanged = false;
bindings.forEach(function (name) {
// Perhaps .reduce() to a boolean?
var statePath = properties[name].statePath;
var value = typeof statePath === 'function' ? statePath.call(element, state) : (0, _path.get)(state, statePath);
var changed = element._setPendingPropertyOrPath(name, value, true);
propertiesChanged = propertiesChanged || changed;
});
if (propertiesChanged) {
element._invalidateProperties();
}
} | [
"function",
"update",
"(",
"state",
")",
"{",
"var",
"propertiesChanged",
"=",
"false",
";",
"bindings",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"// Perhaps .reduce() to a boolean?",
"var",
"statePath",
"=",
"properties",
"[",
"name",
"]",
".",
"statePath",
";",
"var",
"value",
"=",
"typeof",
"statePath",
"===",
"'function'",
"?",
"statePath",
".",
"call",
"(",
"element",
",",
"state",
")",
":",
"(",
"0",
",",
"_path",
".",
"get",
")",
"(",
"state",
",",
"statePath",
")",
";",
"var",
"changed",
"=",
"element",
".",
"_setPendingPropertyOrPath",
"(",
"name",
",",
"value",
",",
"true",
")",
";",
"propertiesChanged",
"=",
"propertiesChanged",
"||",
"changed",
";",
"}",
")",
";",
"if",
"(",
"propertiesChanged",
")",
"{",
"element",
".",
"_invalidateProperties",
"(",
")",
";",
"}",
"}"
] | Updates an element's properties with the given state.
@private
@param {Object} state | [
"Updates",
"an",
"element",
"s",
"properties",
"with",
"the",
"given",
"state",
"."
] | 38c766a6de8e3e061c7c3d359c995ec06336b4db | https://github.com/tjmonsi/littleq-router/blob/38c766a6de8e3e061c7c3d359c995ec06336b4db/demo/script/main.js#L3100-L3114 |
51,742 | tjmonsi/littleq-router | demo/script/main.js | collect | function collect(what, which) {
var res = {};
while (what) {
res = Object.assign({}, what[which], res); // Respect prototype priority
what = Object.getPrototypeOf(what);
}
return res;
} | javascript | function collect(what, which) {
var res = {};
while (what) {
res = Object.assign({}, what[which], res); // Respect prototype priority
what = Object.getPrototypeOf(what);
}
return res;
} | [
"function",
"collect",
"(",
"what",
",",
"which",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"while",
"(",
"what",
")",
"{",
"res",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"what",
"[",
"which",
"]",
",",
"res",
")",
";",
"// Respect prototype priority",
"what",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"what",
")",
";",
"}",
"return",
"res",
";",
"}"
] | Merges a property's object value using the defaults way.
@private
@param {Object} what Initial prototype
@param {String} which Property to collect.
@return {Object} the collected values | [
"Merges",
"a",
"property",
"s",
"object",
"value",
"using",
"the",
"defaults",
"way",
"."
] | 38c766a6de8e3e061c7c3d359c995ec06336b4db | https://github.com/tjmonsi/littleq-router/blob/38c766a6de8e3e061c7c3d359c995ec06336b4db/demo/script/main.js#L3150-L3157 |
51,743 | vesln/r...e | lib/range.js | Range | function Range(min, max, step) {
var scope = null
, re = /^([A-Za-z]|\d+)\.{2}([A-Za-z]|\d+)$/;
if (typeof min === 'string' && min.match(re)) {
step = max;
scope = min.split('..');
min = cast(scope[0]);
max = cast(scope[1]);
}
this.min(min);
this.max(max);
this.step(step);
} | javascript | function Range(min, max, step) {
var scope = null
, re = /^([A-Za-z]|\d+)\.{2}([A-Za-z]|\d+)$/;
if (typeof min === 'string' && min.match(re)) {
step = max;
scope = min.split('..');
min = cast(scope[0]);
max = cast(scope[1]);
}
this.min(min);
this.max(max);
this.step(step);
} | [
"function",
"Range",
"(",
"min",
",",
"max",
",",
"step",
")",
"{",
"var",
"scope",
"=",
"null",
",",
"re",
"=",
"/",
"^([A-Za-z]|\\d+)\\.{2}([A-Za-z]|\\d+)$",
"/",
";",
"if",
"(",
"typeof",
"min",
"===",
"'string'",
"&&",
"min",
".",
"match",
"(",
"re",
")",
")",
"{",
"step",
"=",
"max",
";",
"scope",
"=",
"min",
".",
"split",
"(",
"'..'",
")",
";",
"min",
"=",
"cast",
"(",
"scope",
"[",
"0",
"]",
")",
";",
"max",
"=",
"cast",
"(",
"scope",
"[",
"1",
"]",
")",
";",
"}",
"this",
".",
"min",
"(",
"min",
")",
";",
"this",
".",
"max",
"(",
"max",
")",
";",
"this",
".",
"step",
"(",
"step",
")",
";",
"}"
] | Range constructor.
@param {Number|String} min
@param {Number|String} max
@param {Number} step
@constructor | [
"Range",
"constructor",
"."
] | e252b3b6341934d43571318ddaea0634a366a4bd | https://github.com/vesln/r...e/blob/e252b3b6341934d43571318ddaea0634a366a4bd/lib/range.js#L20-L34 |
51,744 | rqt/ip | build/index.js | ip | async function ip(options = {}) {
const {
host = 'https://api.ipify.org',
} = options
const res = await rqt(host)
return res
} | javascript | async function ip(options = {}) {
const {
host = 'https://api.ipify.org',
} = options
const res = await rqt(host)
return res
} | [
"async",
"function",
"ip",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"const",
"{",
"host",
"=",
"'https://api.ipify.org'",
",",
"}",
"=",
"options",
"const",
"res",
"=",
"await",
"rqt",
"(",
"host",
")",
"return",
"res",
"}"
] | Returns a public IP address of the host.
@param {Options} options Options for the request.
@param {string} [options.host="https://api.ipify.org"] The address from which to get the IP address. Default `https://api.ipify.org`. | [
"Returns",
"a",
"public",
"IP",
"address",
"of",
"the",
"host",
"."
] | a4c927896e7718137c3bfdc1a39d83339e97a821 | https://github.com/rqt/ip/blob/a4c927896e7718137c3bfdc1a39d83339e97a821/build/index.js#L8-L14 |
51,745 | b-heilman/bmoor | src/string.js | trim | function trim( str, chr ){
if ( !chr ){
chr = '\\s';
}
return str.replace( new RegExp('^'+chr+'+|'+chr+'+$','g'), '' );
} | javascript | function trim( str, chr ){
if ( !chr ){
chr = '\\s';
}
return str.replace( new RegExp('^'+chr+'+|'+chr+'+$','g'), '' );
} | [
"function",
"trim",
"(",
"str",
",",
"chr",
")",
"{",
"if",
"(",
"!",
"chr",
")",
"{",
"chr",
"=",
"'\\\\s'",
";",
"}",
"return",
"str",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'^'",
"+",
"chr",
"+",
"'+|'",
"+",
"chr",
"+",
"'+$'",
",",
"'g'",
")",
",",
"''",
")",
";",
"}"
] | Array helper functions
@module bmoor.string | [
"Array",
"helper",
"functions"
] | b21a315b477093c14e5f32d857b4644a5a0a36fd | https://github.com/b-heilman/bmoor/blob/b21a315b477093c14e5f32d857b4644a5a0a36fd/src/string.js#L8-L13 |
51,746 | robojones/better-events | lib/shareEvent.js | shareEvent | function shareEvent(eventName, source, target, once = false) {
verifyEventEmitter(source, 'source')
verifyEventEmitter(target, 'target')
const cb = target.emit.bind(target, eventName)
source[once ? 'once' : 'on'](eventName, cb)
return cb
} | javascript | function shareEvent(eventName, source, target, once = false) {
verifyEventEmitter(source, 'source')
verifyEventEmitter(target, 'target')
const cb = target.emit.bind(target, eventName)
source[once ? 'once' : 'on'](eventName, cb)
return cb
} | [
"function",
"shareEvent",
"(",
"eventName",
",",
"source",
",",
"target",
",",
"once",
"=",
"false",
")",
"{",
"verifyEventEmitter",
"(",
"source",
",",
"'source'",
")",
"verifyEventEmitter",
"(",
"target",
",",
"'target'",
")",
"const",
"cb",
"=",
"target",
".",
"emit",
".",
"bind",
"(",
"target",
",",
"eventName",
")",
"source",
"[",
"once",
"?",
"'once'",
":",
"'on'",
"]",
"(",
"eventName",
",",
"cb",
")",
"return",
"cb",
"}"
] | Share an event from the source with the target.
@param {string} eventName - The name of the event.
@param {*} source - The EventEmitter that emits the event.
@param {*} target - The EventEmitter that should also emit the event.
@param {boolean} [once] - Share the event only once.
@returns {function} - The callback that has been applied to the target. | [
"Share",
"an",
"event",
"from",
"the",
"source",
"with",
"the",
"target",
"."
] | 78934b6f8506327b332325158a9bf83e8b541601 | https://github.com/robojones/better-events/blob/78934b6f8506327b332325158a9bf83e8b541601/lib/shareEvent.js#L11-L20 |
51,747 | capsela/testpilot | lib/FileSystem.js | stat | function stat(p) {
var def = Q.defer();
fs.stat(p, def.makeNodeResolver());
return def.promise;
} | javascript | function stat(p) {
var def = Q.defer();
fs.stat(p, def.makeNodeResolver());
return def.promise;
} | [
"function",
"stat",
"(",
"p",
")",
"{",
"var",
"def",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"fs",
".",
"stat",
"(",
"p",
",",
"def",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"def",
".",
"promise",
";",
"}"
] | Promise wrapper for fs.stat
@param p | [
"Promise",
"wrapper",
"for",
"fs",
".",
"stat"
] | 44f9527e6444236406fc0deac9b84ac420db3c1b | https://github.com/capsela/testpilot/blob/44f9527e6444236406fc0deac9b84ac420db3c1b/lib/FileSystem.js#L35-L39 |
51,748 | capsela/testpilot | lib/FileSystem.js | list | function list(p) {
var def = Q.defer();
fs.readdir(p, def.makeNodeResolver());
return def.promise;
} | javascript | function list(p) {
var def = Q.defer();
fs.readdir(p, def.makeNodeResolver());
return def.promise;
} | [
"function",
"list",
"(",
"p",
")",
"{",
"var",
"def",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"fs",
".",
"readdir",
"(",
"p",
",",
"def",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"def",
".",
"promise",
";",
"}"
] | Promise wrapper for fs.list
@param p | [
"Promise",
"wrapper",
"for",
"fs",
".",
"list"
] | 44f9527e6444236406fc0deac9b84ac420db3c1b | https://github.com/capsela/testpilot/blob/44f9527e6444236406fc0deac9b84ac420db3c1b/lib/FileSystem.js#L48-L52 |
51,749 | capsela/testpilot | lib/FileSystem.js | writeFile | function writeFile(p, data, encoding) {
var def = Q.defer();
fs.writeFile(p, data, encoding, def.makeNodeResolver());
return def.promise
} | javascript | function writeFile(p, data, encoding) {
var def = Q.defer();
fs.writeFile(p, data, encoding, def.makeNodeResolver());
return def.promise
} | [
"function",
"writeFile",
"(",
"p",
",",
"data",
",",
"encoding",
")",
"{",
"var",
"def",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"fs",
".",
"writeFile",
"(",
"p",
",",
"data",
",",
"encoding",
",",
"def",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"def",
".",
"promise",
"}"
] | Promise wrapper for fs.writeFile
@param p | [
"Promise",
"wrapper",
"for",
"fs",
".",
"writeFile"
] | 44f9527e6444236406fc0deac9b84ac420db3c1b | https://github.com/capsela/testpilot/blob/44f9527e6444236406fc0deac9b84ac420db3c1b/lib/FileSystem.js#L61-L65 |
51,750 | capsela/testpilot | lib/FileSystem.js | readFile | function readFile(p, encoding) {
var def = Q.defer();
fs.readFile(p, encoding, def.makeNodeResolver());
return def.promise
} | javascript | function readFile(p, encoding) {
var def = Q.defer();
fs.readFile(p, encoding, def.makeNodeResolver());
return def.promise
} | [
"function",
"readFile",
"(",
"p",
",",
"encoding",
")",
"{",
"var",
"def",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"fs",
".",
"readFile",
"(",
"p",
",",
"encoding",
",",
"def",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"def",
".",
"promise",
"}"
] | Promise wrapper for fs.readFile
@param p | [
"Promise",
"wrapper",
"for",
"fs",
".",
"readFile"
] | 44f9527e6444236406fc0deac9b84ac420db3c1b | https://github.com/capsela/testpilot/blob/44f9527e6444236406fc0deac9b84ac420db3c1b/lib/FileSystem.js#L74-L78 |
51,751 | capsela/testpilot | lib/FileSystem.js | listTree | function listTree(basePath, guard) {
basePath = path.resolve(basePath);
return stat(basePath).then(
function(topStat) {
var results = [];
if (!guard || guard(basePath, topStat)) {
results.push(basePath);
}
if (topStat.isDirectory()) {
return list(basePath).then(
function(items) {
return Q.all(items.map(
function(item) {
var fullPath = path.join(basePath, item);
return listTree(fullPath, guard);
}
));
}
).then(
function(sets) {
return Array.prototype.concat.apply(results, sets).sort();
}
);
}
return results;
},
function() {
// not found or not accessible, so the list is empty
return [];
}
);
} | javascript | function listTree(basePath, guard) {
basePath = path.resolve(basePath);
return stat(basePath).then(
function(topStat) {
var results = [];
if (!guard || guard(basePath, topStat)) {
results.push(basePath);
}
if (topStat.isDirectory()) {
return list(basePath).then(
function(items) {
return Q.all(items.map(
function(item) {
var fullPath = path.join(basePath, item);
return listTree(fullPath, guard);
}
));
}
).then(
function(sets) {
return Array.prototype.concat.apply(results, sets).sort();
}
);
}
return results;
},
function() {
// not found or not accessible, so the list is empty
return [];
}
);
} | [
"function",
"listTree",
"(",
"basePath",
",",
"guard",
")",
"{",
"basePath",
"=",
"path",
".",
"resolve",
"(",
"basePath",
")",
";",
"return",
"stat",
"(",
"basePath",
")",
".",
"then",
"(",
"function",
"(",
"topStat",
")",
"{",
"var",
"results",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"guard",
"||",
"guard",
"(",
"basePath",
",",
"topStat",
")",
")",
"{",
"results",
".",
"push",
"(",
"basePath",
")",
";",
"}",
"if",
"(",
"topStat",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
"list",
"(",
"basePath",
")",
".",
"then",
"(",
"function",
"(",
"items",
")",
"{",
"return",
"Q",
".",
"all",
"(",
"items",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"fullPath",
"=",
"path",
".",
"join",
"(",
"basePath",
",",
"item",
")",
";",
"return",
"listTree",
"(",
"fullPath",
",",
"guard",
")",
";",
"}",
")",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"sets",
")",
"{",
"return",
"Array",
".",
"prototype",
".",
"concat",
".",
"apply",
"(",
"results",
",",
"sets",
")",
".",
"sort",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"results",
";",
"}",
",",
"function",
"(",
")",
"{",
"// not found or not accessible, so the list is empty",
"return",
"[",
"]",
";",
"}",
")",
";",
"}"
] | Independent implementation of Kris Kowal's Q-fs listTree method. Here
to avoid depending on the whole of Q-fs for one little function.
@param basePath
@param guard | [
"Independent",
"implementation",
"of",
"Kris",
"Kowal",
"s",
"Q",
"-",
"fs",
"listTree",
"method",
".",
"Here",
"to",
"avoid",
"depending",
"on",
"the",
"whole",
"of",
"Q",
"-",
"fs",
"for",
"one",
"little",
"function",
"."
] | 44f9527e6444236406fc0deac9b84ac420db3c1b | https://github.com/capsela/testpilot/blob/44f9527e6444236406fc0deac9b84ac420db3c1b/lib/FileSystem.js#L90-L126 |
51,752 | ActiveObject/immutable-trie | src/common.js | popcount | function popcount(i) {
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
} | javascript | function popcount(i) {
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
} | [
"function",
"popcount",
"(",
"i",
")",
"{",
"i",
"=",
"i",
"-",
"(",
"(",
"i",
">>",
"1",
")",
"&",
"0x55555555",
")",
";",
"i",
"=",
"(",
"i",
"&",
"0x33333333",
")",
"+",
"(",
"(",
"i",
">>",
"2",
")",
"&",
"0x33333333",
")",
";",
"return",
"(",
"(",
"(",
"i",
"+",
"(",
"i",
">>",
"4",
")",
")",
"&",
"0x0F0F0F0F",
")",
"*",
"0x01010101",
")",
">>",
"24",
";",
"}"
] | Calculate Hamming weight for a given bitmap. Also known as 'population count'
operation.
@link http://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer/109025#109025 | [
"Calculate",
"Hamming",
"weight",
"for",
"a",
"given",
"bitmap",
".",
"Also",
"known",
"as",
"population",
"count",
"operation",
"."
] | 11ced2a0d480eeb2f6dc89626f2a77798bb5cb58 | https://github.com/ActiveObject/immutable-trie/blob/11ced2a0d480eeb2f6dc89626f2a77798bb5cb58/src/common.js#L6-L10 |
51,753 | ActiveObject/immutable-trie | src/common.js | insertAt | function insertAt(items, item, index) {
var copy = items.slice();
copy.splice(index, 0, item);
return copy;
} | javascript | function insertAt(items, item, index) {
var copy = items.slice();
copy.splice(index, 0, item);
return copy;
} | [
"function",
"insertAt",
"(",
"items",
",",
"item",
",",
"index",
")",
"{",
"var",
"copy",
"=",
"items",
".",
"slice",
"(",
")",
";",
"copy",
".",
"splice",
"(",
"index",
",",
"0",
",",
"item",
")",
";",
"return",
"copy",
";",
"}"
] | Insert item into position at given index.
Doesn't modify source array.
@param {Array} items
@param {*} item
@param {Number} index
@return {Array} | [
"Insert",
"item",
"into",
"position",
"at",
"given",
"index",
".",
"Doesn",
"t",
"modify",
"source",
"array",
"."
] | 11ced2a0d480eeb2f6dc89626f2a77798bb5cb58 | https://github.com/ActiveObject/immutable-trie/blob/11ced2a0d480eeb2f6dc89626f2a77798bb5cb58/src/common.js#L34-L38 |
51,754 | ActiveObject/immutable-trie | src/common.js | replaceAt | function replaceAt(items, item, index) {
var copy = items.slice();
copy.splice(index, 1, item);
return copy;
} | javascript | function replaceAt(items, item, index) {
var copy = items.slice();
copy.splice(index, 1, item);
return copy;
} | [
"function",
"replaceAt",
"(",
"items",
",",
"item",
",",
"index",
")",
"{",
"var",
"copy",
"=",
"items",
".",
"slice",
"(",
")",
";",
"copy",
".",
"splice",
"(",
"index",
",",
"1",
",",
"item",
")",
";",
"return",
"copy",
";",
"}"
] | Replace array element at given index with new item.
Doesn't modify source array.
@param {Array} items
@param {*} item
@param {Number} index
@return {Array} | [
"Replace",
"array",
"element",
"at",
"given",
"index",
"with",
"new",
"item",
".",
"Doesn",
"t",
"modify",
"source",
"array",
"."
] | 11ced2a0d480eeb2f6dc89626f2a77798bb5cb58 | https://github.com/ActiveObject/immutable-trie/blob/11ced2a0d480eeb2f6dc89626f2a77798bb5cb58/src/common.js#L48-L52 |
51,755 | ActiveObject/immutable-trie | src/common.js | removeAt | function removeAt(items, index) {
var copy = items.slice();
copy.splice(index, 1);
return copy;
} | javascript | function removeAt(items, index) {
var copy = items.slice();
copy.splice(index, 1);
return copy;
} | [
"function",
"removeAt",
"(",
"items",
",",
"index",
")",
"{",
"var",
"copy",
"=",
"items",
".",
"slice",
"(",
")",
";",
"copy",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"return",
"copy",
";",
"}"
] | Remove element from array at given index.
Doesn't modify source array.
@param {Array} items
@param {Number} index
@return {Array} | [
"Remove",
"element",
"from",
"array",
"at",
"given",
"index",
".",
"Doesn",
"t",
"modify",
"source",
"array",
"."
] | 11ced2a0d480eeb2f6dc89626f2a77798bb5cb58 | https://github.com/ActiveObject/immutable-trie/blob/11ced2a0d480eeb2f6dc89626f2a77798bb5cb58/src/common.js#L61-L65 |
51,756 | ActiveObject/immutable-trie | src/common.js | find | function find(items, pred) {
var len = items.length,
i = -1;
while(++i < len) {
if (pred(items[i], i)) {
return items[i];
}
}
return null;
} | javascript | function find(items, pred) {
var len = items.length,
i = -1;
while(++i < len) {
if (pred(items[i], i)) {
return items[i];
}
}
return null;
} | [
"function",
"find",
"(",
"items",
",",
"pred",
")",
"{",
"var",
"len",
"=",
"items",
".",
"length",
",",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"if",
"(",
"pred",
"(",
"items",
"[",
"i",
"]",
",",
"i",
")",
")",
"{",
"return",
"items",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find first element for which predicate is true
@param {Array} items
@param {Function} pred
@return {*} | [
"Find",
"first",
"element",
"for",
"which",
"predicate",
"is",
"true"
] | 11ced2a0d480eeb2f6dc89626f2a77798bb5cb58 | https://github.com/ActiveObject/immutable-trie/blob/11ced2a0d480eeb2f6dc89626f2a77798bb5cb58/src/common.js#L73-L84 |
51,757 | AckerApple/ack-webpack | webpacker.js | watchCompiler | function watchCompiler(compiler, options={}){
let watching = false
log('Watch Building')
const startWatchTime = Date.now()
const watchConfig = { // watch options:
//aggregateTimeout: 300, // wait so long for more changes
//poll: true // use polling instead of native watchers
// pass a number to set the polling interval
}
options.onRebuild = options.onRebuild || function(){}
return new Promise(function(res,rej){
//webpack watch functionality
compiler.watch(watchConfig, function(err,stats){
if(err)return rej(err)
if(watching){
log('Rebuilt '+getServerTime())
options.onRebuild(stats)
}else{
watching = true
log('Watching '+(Date.now()-startWatchTime)/1000+' seconds')
res( this )
}
});
})
} | javascript | function watchCompiler(compiler, options={}){
let watching = false
log('Watch Building')
const startWatchTime = Date.now()
const watchConfig = { // watch options:
//aggregateTimeout: 300, // wait so long for more changes
//poll: true // use polling instead of native watchers
// pass a number to set the polling interval
}
options.onRebuild = options.onRebuild || function(){}
return new Promise(function(res,rej){
//webpack watch functionality
compiler.watch(watchConfig, function(err,stats){
if(err)return rej(err)
if(watching){
log('Rebuilt '+getServerTime())
options.onRebuild(stats)
}else{
watching = true
log('Watching '+(Date.now()-startWatchTime)/1000+' seconds')
res( this )
}
});
})
} | [
"function",
"watchCompiler",
"(",
"compiler",
",",
"options",
"=",
"{",
"}",
")",
"{",
"let",
"watching",
"=",
"false",
"log",
"(",
"'Watch Building'",
")",
"const",
"startWatchTime",
"=",
"Date",
".",
"now",
"(",
")",
"const",
"watchConfig",
"=",
"{",
"// watch options:",
"//aggregateTimeout: 300, // wait so long for more changes",
"//poll: true // use polling instead of native watchers",
"// pass a number to set the polling interval",
"}",
"options",
".",
"onRebuild",
"=",
"options",
".",
"onRebuild",
"||",
"function",
"(",
")",
"{",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"res",
",",
"rej",
")",
"{",
"//webpack watch functionality",
"compiler",
".",
"watch",
"(",
"watchConfig",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"return",
"rej",
"(",
"err",
")",
"if",
"(",
"watching",
")",
"{",
"log",
"(",
"'Rebuilt '",
"+",
"getServerTime",
"(",
")",
")",
"options",
".",
"onRebuild",
"(",
"stats",
")",
"}",
"else",
"{",
"watching",
"=",
"true",
"log",
"(",
"'Watching '",
"+",
"(",
"Date",
".",
"now",
"(",
")",
"-",
"startWatchTime",
")",
"/",
"1000",
"+",
"' seconds'",
")",
"res",
"(",
"this",
")",
"}",
"}",
")",
";",
"}",
")",
"}"
] | use npm watch for file watching
@options{
onRebuild
} | [
"use",
"npm",
"watch",
"for",
"file",
"watching"
] | 6c0a49dea358c992f18002deec430ef371ba5a95 | https://github.com/AckerApple/ack-webpack/blob/6c0a49dea358c992f18002deec430ef371ba5a95/webpacker.js#L111-L138 |
51,758 | wunderbyte/grunt-spiritual-dox | src/js/[email protected]/spirits/output/dox.TreeOutputSpirit.js | step4 | function step4 ( folder ) {
while ( folder.nodes.length === 1 && folder.nodes [ 0 ].nodes ) {
//folder.hidden = true;
folder = folder.nodes [ 0 ];
}
return folder;
} | javascript | function step4 ( folder ) {
while ( folder.nodes.length === 1 && folder.nodes [ 0 ].nodes ) {
//folder.hidden = true;
folder = folder.nodes [ 0 ];
}
return folder;
} | [
"function",
"step4",
"(",
"folder",
")",
"{",
"while",
"(",
"folder",
".",
"nodes",
".",
"length",
"===",
"1",
"&&",
"folder",
".",
"nodes",
"[",
"0",
"]",
".",
"nodes",
")",
"{",
"//folder.hidden = true;",
"folder",
"=",
"folder",
".",
"nodes",
"[",
"0",
"]",
";",
"}",
"return",
"folder",
";",
"}"
] | Reduce to minimum viable root folder. | [
"Reduce",
"to",
"minimum",
"viable",
"root",
"folder",
"."
] | 5afcfe31ddbf7d654166aa15b938553b61de5811 | https://github.com/wunderbyte/grunt-spiritual-dox/blob/5afcfe31ddbf7d654166aa15b938553b61de5811/src/js/[email protected]/spirits/output/dox.TreeOutputSpirit.js#L86-L92 |
51,759 | wunderbyte/grunt-spiritual-dox | src/js/[email protected]/spirits/output/dox.TreeOutputSpirit.js | step5 | function step5 ( folder ) {
folder.filenames = folder.filenames || folder.nodes.map ( function ( node ) {
return node.nodes ? step5 ( node ).filenames : node.name.toLowerCase ();
}).join ( " " );
return folder;
} | javascript | function step5 ( folder ) {
folder.filenames = folder.filenames || folder.nodes.map ( function ( node ) {
return node.nodes ? step5 ( node ).filenames : node.name.toLowerCase ();
}).join ( " " );
return folder;
} | [
"function",
"step5",
"(",
"folder",
")",
"{",
"folder",
".",
"filenames",
"=",
"folder",
".",
"filenames",
"||",
"folder",
".",
"nodes",
".",
"map",
"(",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"nodes",
"?",
"step5",
"(",
"node",
")",
".",
"filenames",
":",
"node",
".",
"name",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
".",
"join",
"(",
"\" \"",
")",
";",
"return",
"folder",
";",
"}"
] | Preoptimize search by stamping descendant filenames onto folders. | [
"Preoptimize",
"search",
"by",
"stamping",
"descendant",
"filenames",
"onto",
"folders",
"."
] | 5afcfe31ddbf7d654166aa15b938553b61de5811 | https://github.com/wunderbyte/grunt-spiritual-dox/blob/5afcfe31ddbf7d654166aa15b938553b61de5811/src/js/[email protected]/spirits/output/dox.TreeOutputSpirit.js#L96-L101 |
51,760 | zthun/zbuildtools | src/webpack/zwebpack.js | rule | function rule(test, loaders, exclude) {
var rule = {
test: test,
use: loaders
};
if (exclude) {
rule.exclude = exclude;
}
return rule;
} | javascript | function rule(test, loaders, exclude) {
var rule = {
test: test,
use: loaders
};
if (exclude) {
rule.exclude = exclude;
}
return rule;
} | [
"function",
"rule",
"(",
"test",
",",
"loaders",
",",
"exclude",
")",
"{",
"var",
"rule",
"=",
"{",
"test",
":",
"test",
",",
"use",
":",
"loaders",
"}",
";",
"if",
"(",
"exclude",
")",
"{",
"rule",
".",
"exclude",
"=",
"exclude",
";",
"}",
"return",
"rule",
";",
"}"
] | Constructs a rule object.
@param {RegEx} test The regular expression to use when testing a file path name.
@param {Array} loaders The list of loaders to run the file through if it matches the test regex.
@param {RegEx} exclude The regular express to use when excluding specific files that match the test regex. | [
"Constructs",
"a",
"rule",
"object",
"."
] | f9b339fc3c3b8188638ccd17a96cb44d457bafd4 | https://github.com/zthun/zbuildtools/blob/f9b339fc3c3b8188638ccd17a96cb44d457bafd4/src/webpack/zwebpack.js#L13-L24 |
51,761 | tab58/minimatrix | src/math-helpers.js | rrefInPlace | function rrefInPlace (M, TOL = 1e-14) {
const me = M.elements;
// iterate through all rows to get to REF
for (let i = 0; i < 3; ++i) {
// search for largest in col and swap
const k = findLargestInCol(M, i, i);
if (k !== i) {
swapRowsInPlace(M, i, k);
}
// scale and add current row to all rows underneath
const largestElem = me[(i * 3) + i];
if (!Compare.isZero(largestElem, TOL)) {
scaleRow(M, i, 1.0 / largestElem);
for (let j = i + 1; j < 3; ++j) {
const scaleElem = me[(i * 3) + j];
if (!Compare.isZero(scaleElem, TOL)) {
scaleAndAddRow(M, i, j, -scaleElem);
}
}
}
}
// iterate back through to get RREF since everything on diagonals should be 1 or 0
for (let i = 2; i >= 0; --i) {
const val = me[(i * 3) + i];
if (!Compare.isZero(val, TOL)) {
for (let j = i - 1; j >= 0; --j) {
const scaleElem = me[(i * 3) + j];
if (!Compare.isZero(scaleElem, TOL)) {
scaleAndAddRow(M, i, j, -scaleElem);
}
}
}
}
return M;
} | javascript | function rrefInPlace (M, TOL = 1e-14) {
const me = M.elements;
// iterate through all rows to get to REF
for (let i = 0; i < 3; ++i) {
// search for largest in col and swap
const k = findLargestInCol(M, i, i);
if (k !== i) {
swapRowsInPlace(M, i, k);
}
// scale and add current row to all rows underneath
const largestElem = me[(i * 3) + i];
if (!Compare.isZero(largestElem, TOL)) {
scaleRow(M, i, 1.0 / largestElem);
for (let j = i + 1; j < 3; ++j) {
const scaleElem = me[(i * 3) + j];
if (!Compare.isZero(scaleElem, TOL)) {
scaleAndAddRow(M, i, j, -scaleElem);
}
}
}
}
// iterate back through to get RREF since everything on diagonals should be 1 or 0
for (let i = 2; i >= 0; --i) {
const val = me[(i * 3) + i];
if (!Compare.isZero(val, TOL)) {
for (let j = i - 1; j >= 0; --j) {
const scaleElem = me[(i * 3) + j];
if (!Compare.isZero(scaleElem, TOL)) {
scaleAndAddRow(M, i, j, -scaleElem);
}
}
}
}
return M;
} | [
"function",
"rrefInPlace",
"(",
"M",
",",
"TOL",
"=",
"1e-14",
")",
"{",
"const",
"me",
"=",
"M",
".",
"elements",
";",
"// iterate through all rows to get to REF",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"++",
"i",
")",
"{",
"// search for largest in col and swap",
"const",
"k",
"=",
"findLargestInCol",
"(",
"M",
",",
"i",
",",
"i",
")",
";",
"if",
"(",
"k",
"!==",
"i",
")",
"{",
"swapRowsInPlace",
"(",
"M",
",",
"i",
",",
"k",
")",
";",
"}",
"// scale and add current row to all rows underneath",
"const",
"largestElem",
"=",
"me",
"[",
"(",
"i",
"*",
"3",
")",
"+",
"i",
"]",
";",
"if",
"(",
"!",
"Compare",
".",
"isZero",
"(",
"largestElem",
",",
"TOL",
")",
")",
"{",
"scaleRow",
"(",
"M",
",",
"i",
",",
"1.0",
"/",
"largestElem",
")",
";",
"for",
"(",
"let",
"j",
"=",
"i",
"+",
"1",
";",
"j",
"<",
"3",
";",
"++",
"j",
")",
"{",
"const",
"scaleElem",
"=",
"me",
"[",
"(",
"i",
"*",
"3",
")",
"+",
"j",
"]",
";",
"if",
"(",
"!",
"Compare",
".",
"isZero",
"(",
"scaleElem",
",",
"TOL",
")",
")",
"{",
"scaleAndAddRow",
"(",
"M",
",",
"i",
",",
"j",
",",
"-",
"scaleElem",
")",
";",
"}",
"}",
"}",
"}",
"// iterate back through to get RREF since everything on diagonals should be 1 or 0",
"for",
"(",
"let",
"i",
"=",
"2",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"{",
"const",
"val",
"=",
"me",
"[",
"(",
"i",
"*",
"3",
")",
"+",
"i",
"]",
";",
"if",
"(",
"!",
"Compare",
".",
"isZero",
"(",
"val",
",",
"TOL",
")",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"i",
"-",
"1",
";",
"j",
">=",
"0",
";",
"--",
"j",
")",
"{",
"const",
"scaleElem",
"=",
"me",
"[",
"(",
"i",
"*",
"3",
")",
"+",
"j",
"]",
";",
"if",
"(",
"!",
"Compare",
".",
"isZero",
"(",
"scaleElem",
",",
"TOL",
")",
")",
"{",
"scaleAndAddRow",
"(",
"M",
",",
"i",
",",
"j",
",",
"-",
"scaleElem",
")",
";",
"}",
"}",
"}",
"}",
"return",
"M",
";",
"}"
] | Reduces a matrix to reduced row echelon form.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} TOL The numerical tolerance for zero comparison. | [
"Reduces",
"a",
"matrix",
"to",
"reduced",
"row",
"echelon",
"form",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L16-L50 |
51,762 | tab58/minimatrix | src/math-helpers.js | isRowNonzero | function isRowNonzero (M, i, TOL = 1e-14) {
const me = M.elements;
return !(Compare.isZero(me[i], TOL) &&
Compare.isZero(me[i + 3], TOL) &&
Compare.isZero(me[i + 6], TOL));
} | javascript | function isRowNonzero (M, i, TOL = 1e-14) {
const me = M.elements;
return !(Compare.isZero(me[i], TOL) &&
Compare.isZero(me[i + 3], TOL) &&
Compare.isZero(me[i + 6], TOL));
} | [
"function",
"isRowNonzero",
"(",
"M",
",",
"i",
",",
"TOL",
"=",
"1e-14",
")",
"{",
"const",
"me",
"=",
"M",
".",
"elements",
";",
"return",
"!",
"(",
"Compare",
".",
"isZero",
"(",
"me",
"[",
"i",
"]",
",",
"TOL",
")",
"&&",
"Compare",
".",
"isZero",
"(",
"me",
"[",
"i",
"+",
"3",
"]",
",",
"TOL",
")",
"&&",
"Compare",
".",
"isZero",
"(",
"me",
"[",
"i",
"+",
"6",
"]",
",",
"TOL",
")",
")",
";",
"}"
] | Tests if a row in a matrix is nonzero.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} i The row index.
@param {number} TOL The numerical tolerance. | [
"Tests",
"if",
"a",
"row",
"in",
"a",
"matrix",
"is",
"nonzero",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L59-L64 |
51,763 | tab58/minimatrix | src/math-helpers.js | findLargestAbsElement | function findLargestAbsElement (M) {
const te = M.elements;
const n = M.dimension;
let max = _Math.abs(te[0]);
let rowCol = {
row: 0,
column: 0,
value: te[0]
};
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
const val = te[i * n + j];
const ti = _Math.abs(val);
if (ti > max) {
max = ti;
rowCol.row = j;
rowCol.column = i;
rowCol.value = val;
}
}
}
return rowCol;
} | javascript | function findLargestAbsElement (M) {
const te = M.elements;
const n = M.dimension;
let max = _Math.abs(te[0]);
let rowCol = {
row: 0,
column: 0,
value: te[0]
};
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
const val = te[i * n + j];
const ti = _Math.abs(val);
if (ti > max) {
max = ti;
rowCol.row = j;
rowCol.column = i;
rowCol.value = val;
}
}
}
return rowCol;
} | [
"function",
"findLargestAbsElement",
"(",
"M",
")",
"{",
"const",
"te",
"=",
"M",
".",
"elements",
";",
"const",
"n",
"=",
"M",
".",
"dimension",
";",
"let",
"max",
"=",
"_Math",
".",
"abs",
"(",
"te",
"[",
"0",
"]",
")",
";",
"let",
"rowCol",
"=",
"{",
"row",
":",
"0",
",",
"column",
":",
"0",
",",
"value",
":",
"te",
"[",
"0",
"]",
"}",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"const",
"val",
"=",
"te",
"[",
"i",
"*",
"n",
"+",
"j",
"]",
";",
"const",
"ti",
"=",
"_Math",
".",
"abs",
"(",
"val",
")",
";",
"if",
"(",
"ti",
">",
"max",
")",
"{",
"max",
"=",
"ti",
";",
"rowCol",
".",
"row",
"=",
"j",
";",
"rowCol",
".",
"column",
"=",
"i",
";",
"rowCol",
".",
"value",
"=",
"val",
";",
"}",
"}",
"}",
"return",
"rowCol",
";",
"}"
] | Finds the largest absolute valued element in a matrix.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix. | [
"Finds",
"the",
"largest",
"absolute",
"valued",
"element",
"in",
"a",
"matrix",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L71-L93 |
51,764 | tab58/minimatrix | src/math-helpers.js | findLargestInRow | function findLargestInRow (M, i) {
// get the row:
const m = M.elements;
const n = M.dimension;
const offset = i;
let j = 0;
let lrgElem = _Math.abs(m[offset]);
let lrgCol = j;
for (j = 1; j < n; ++j) {
const val = _Math.abs(m[offset + j * n]);
if (val > lrgElem) {
lrgCol = j;
lrgElem = val;
}
}
return lrgCol;
} | javascript | function findLargestInRow (M, i) {
// get the row:
const m = M.elements;
const n = M.dimension;
const offset = i;
let j = 0;
let lrgElem = _Math.abs(m[offset]);
let lrgCol = j;
for (j = 1; j < n; ++j) {
const val = _Math.abs(m[offset + j * n]);
if (val > lrgElem) {
lrgCol = j;
lrgElem = val;
}
}
return lrgCol;
} | [
"function",
"findLargestInRow",
"(",
"M",
",",
"i",
")",
"{",
"// get the row:",
"const",
"m",
"=",
"M",
".",
"elements",
";",
"const",
"n",
"=",
"M",
".",
"dimension",
";",
"const",
"offset",
"=",
"i",
";",
"let",
"j",
"=",
"0",
";",
"let",
"lrgElem",
"=",
"_Math",
".",
"abs",
"(",
"m",
"[",
"offset",
"]",
")",
";",
"let",
"lrgCol",
"=",
"j",
";",
"for",
"(",
"j",
"=",
"1",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"const",
"val",
"=",
"_Math",
".",
"abs",
"(",
"m",
"[",
"offset",
"+",
"j",
"*",
"n",
"]",
")",
";",
"if",
"(",
"val",
">",
"lrgElem",
")",
"{",
"lrgCol",
"=",
"j",
";",
"lrgElem",
"=",
"val",
";",
"}",
"}",
"return",
"lrgCol",
";",
"}"
] | Finds the largest element in the matrix row.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} i The row index.
@returns {number} The column index of the row's largest element. | [
"Finds",
"the",
"largest",
"element",
"in",
"the",
"matrix",
"row",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L102-L119 |
51,765 | tab58/minimatrix | src/math-helpers.js | findLargestInCol | function findLargestInCol (M, i, startAtRow = 0) {
let me = M.elements;
let n = M.dimension;
let offset = i * n;
let maxIdx = startAtRow;
let maxVal = _Math.abs(me[offset + maxIdx]);
for (let i = maxIdx + 1; i < n; ++i) {
let val = _Math.abs(me[offset + i]);
if (val > maxVal) {
maxIdx = i;
maxVal = val;
}
}
return maxIdx;
} | javascript | function findLargestInCol (M, i, startAtRow = 0) {
let me = M.elements;
let n = M.dimension;
let offset = i * n;
let maxIdx = startAtRow;
let maxVal = _Math.abs(me[offset + maxIdx]);
for (let i = maxIdx + 1; i < n; ++i) {
let val = _Math.abs(me[offset + i]);
if (val > maxVal) {
maxIdx = i;
maxVal = val;
}
}
return maxIdx;
} | [
"function",
"findLargestInCol",
"(",
"M",
",",
"i",
",",
"startAtRow",
"=",
"0",
")",
"{",
"let",
"me",
"=",
"M",
".",
"elements",
";",
"let",
"n",
"=",
"M",
".",
"dimension",
";",
"let",
"offset",
"=",
"i",
"*",
"n",
";",
"let",
"maxIdx",
"=",
"startAtRow",
";",
"let",
"maxVal",
"=",
"_Math",
".",
"abs",
"(",
"me",
"[",
"offset",
"+",
"maxIdx",
"]",
")",
";",
"for",
"(",
"let",
"i",
"=",
"maxIdx",
"+",
"1",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"let",
"val",
"=",
"_Math",
".",
"abs",
"(",
"me",
"[",
"offset",
"+",
"i",
"]",
")",
";",
"if",
"(",
"val",
">",
"maxVal",
")",
"{",
"maxIdx",
"=",
"i",
";",
"maxVal",
"=",
"val",
";",
"}",
"}",
"return",
"maxIdx",
";",
"}"
] | Finds the largest element in the matrix column.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} i The column index.
@returns {number} The row index of the column's largest element. | [
"Finds",
"the",
"largest",
"element",
"in",
"the",
"matrix",
"column",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L128-L142 |
51,766 | tab58/minimatrix | src/math-helpers.js | findFirstNonvanishing | function findFirstNonvanishing (M, TOL) {
const te = M.elements;
const n = M.dimension;
let rowCol = {
row: 0,
column: 0,
value: te[0]
};
if (Compare.isZero(te[0], TOL)) {
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
const val = te[i * n + j];
if (!Compare.isZero(val, TOL)) {
rowCol.row = j;
rowCol.column = i;
rowCol.value = val;
return rowCol;
}
}
}
}
return rowCol;
} | javascript | function findFirstNonvanishing (M, TOL) {
const te = M.elements;
const n = M.dimension;
let rowCol = {
row: 0,
column: 0,
value: te[0]
};
if (Compare.isZero(te[0], TOL)) {
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
const val = te[i * n + j];
if (!Compare.isZero(val, TOL)) {
rowCol.row = j;
rowCol.column = i;
rowCol.value = val;
return rowCol;
}
}
}
}
return rowCol;
} | [
"function",
"findFirstNonvanishing",
"(",
"M",
",",
"TOL",
")",
"{",
"const",
"te",
"=",
"M",
".",
"elements",
";",
"const",
"n",
"=",
"M",
".",
"dimension",
";",
"let",
"rowCol",
"=",
"{",
"row",
":",
"0",
",",
"column",
":",
"0",
",",
"value",
":",
"te",
"[",
"0",
"]",
"}",
";",
"if",
"(",
"Compare",
".",
"isZero",
"(",
"te",
"[",
"0",
"]",
",",
"TOL",
")",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"const",
"val",
"=",
"te",
"[",
"i",
"*",
"n",
"+",
"j",
"]",
";",
"if",
"(",
"!",
"Compare",
".",
"isZero",
"(",
"val",
",",
"TOL",
")",
")",
"{",
"rowCol",
".",
"row",
"=",
"j",
";",
"rowCol",
".",
"column",
"=",
"i",
";",
"rowCol",
".",
"value",
"=",
"val",
";",
"return",
"rowCol",
";",
"}",
"}",
"}",
"}",
"return",
"rowCol",
";",
"}"
] | Finds the first nonvanishing element.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} TOL The numerical tolerance.
@returns {Object} The information for the nonvanishing element. | [
"Finds",
"the",
"first",
"nonvanishing",
"element",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L151-L173 |
51,767 | tab58/minimatrix | src/math-helpers.js | swapValuesInArray | function swapValuesInArray (A, i, j) {
if (i !== j) {
const tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
return A;
} | javascript | function swapValuesInArray (A, i, j) {
if (i !== j) {
const tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
return A;
} | [
"function",
"swapValuesInArray",
"(",
"A",
",",
"i",
",",
"j",
")",
"{",
"if",
"(",
"i",
"!==",
"j",
")",
"{",
"const",
"tmp",
"=",
"A",
"[",
"i",
"]",
";",
"A",
"[",
"i",
"]",
"=",
"A",
"[",
"j",
"]",
";",
"A",
"[",
"j",
"]",
"=",
"tmp",
";",
"}",
"return",
"A",
";",
"}"
] | Swaps the values in the array.
@memberof Helpers
@param {number[]} A The array.
@param {number} i The index of the first value.
@param {number} j The index of the second value. | [
"Swaps",
"the",
"values",
"in",
"the",
"array",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L182-L189 |
51,768 | tab58/minimatrix | src/math-helpers.js | swapRowsInPlace | function swapRowsInPlace (M, i, j) {
const me = M.elements;
let a1 = me[i];
let a2 = me[i + 3];
let a3 = me[i + 6];
me[i] = me[j];
me[i + 3] = me[j + 3];
me[i + 6] = me[j + 6];
me[j] = a1;
me[j + 3] = a2;
me[j + 6] = a3;
} | javascript | function swapRowsInPlace (M, i, j) {
const me = M.elements;
let a1 = me[i];
let a2 = me[i + 3];
let a3 = me[i + 6];
me[i] = me[j];
me[i + 3] = me[j + 3];
me[i + 6] = me[j + 6];
me[j] = a1;
me[j + 3] = a2;
me[j + 6] = a3;
} | [
"function",
"swapRowsInPlace",
"(",
"M",
",",
"i",
",",
"j",
")",
"{",
"const",
"me",
"=",
"M",
".",
"elements",
";",
"let",
"a1",
"=",
"me",
"[",
"i",
"]",
";",
"let",
"a2",
"=",
"me",
"[",
"i",
"+",
"3",
"]",
";",
"let",
"a3",
"=",
"me",
"[",
"i",
"+",
"6",
"]",
";",
"me",
"[",
"i",
"]",
"=",
"me",
"[",
"j",
"]",
";",
"me",
"[",
"i",
"+",
"3",
"]",
"=",
"me",
"[",
"j",
"+",
"3",
"]",
";",
"me",
"[",
"i",
"+",
"6",
"]",
"=",
"me",
"[",
"j",
"+",
"6",
"]",
";",
"me",
"[",
"j",
"]",
"=",
"a1",
";",
"me",
"[",
"j",
"+",
"3",
"]",
"=",
"a2",
";",
"me",
"[",
"j",
"+",
"6",
"]",
"=",
"a3",
";",
"}"
] | Swaps two rows in the matrix.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} i The first row index.
@param {number} j The second row index. | [
"Swaps",
"two",
"rows",
"in",
"the",
"matrix",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L198-L211 |
51,769 | tab58/minimatrix | src/math-helpers.js | scaleRow | function scaleRow (M, row, scale) {
const me = M.elements;
let i = row;
let alpha = (scale === undefined ? 1.0 : scale);
me[i] *= alpha;
me[i + 3] *= alpha;
me[i + 6] *= alpha;
} | javascript | function scaleRow (M, row, scale) {
const me = M.elements;
let i = row;
let alpha = (scale === undefined ? 1.0 : scale);
me[i] *= alpha;
me[i + 3] *= alpha;
me[i + 6] *= alpha;
} | [
"function",
"scaleRow",
"(",
"M",
",",
"row",
",",
"scale",
")",
"{",
"const",
"me",
"=",
"M",
".",
"elements",
";",
"let",
"i",
"=",
"row",
";",
"let",
"alpha",
"=",
"(",
"scale",
"===",
"undefined",
"?",
"1.0",
":",
"scale",
")",
";",
"me",
"[",
"i",
"]",
"*=",
"alpha",
";",
"me",
"[",
"i",
"+",
"3",
"]",
"*=",
"alpha",
";",
"me",
"[",
"i",
"+",
"6",
"]",
"*=",
"alpha",
";",
"}"
] | Scales the row in the matrix given by the index.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix.
@param {number} row The row index.
@param {number} scale The number to scale by. | [
"Scales",
"the",
"row",
"in",
"the",
"matrix",
"given",
"by",
"the",
"index",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L220-L227 |
51,770 | tab58/minimatrix | src/math-helpers.js | scaleAndAddRow | function scaleAndAddRow (m, srcRow, destRow, scale) {
const me = m.elements;
let i = destRow;
let j = srcRow;
let alpha = (scale === undefined ? 1.0 : scale);
me[i] += me[j] * alpha;
me[i + 3] += me[j + 3] * alpha;
me[i + 6] += me[j + 6] * alpha;
} | javascript | function scaleAndAddRow (m, srcRow, destRow, scale) {
const me = m.elements;
let i = destRow;
let j = srcRow;
let alpha = (scale === undefined ? 1.0 : scale);
me[i] += me[j] * alpha;
me[i + 3] += me[j + 3] * alpha;
me[i + 6] += me[j + 6] * alpha;
} | [
"function",
"scaleAndAddRow",
"(",
"m",
",",
"srcRow",
",",
"destRow",
",",
"scale",
")",
"{",
"const",
"me",
"=",
"m",
".",
"elements",
";",
"let",
"i",
"=",
"destRow",
";",
"let",
"j",
"=",
"srcRow",
";",
"let",
"alpha",
"=",
"(",
"scale",
"===",
"undefined",
"?",
"1.0",
":",
"scale",
")",
";",
"me",
"[",
"i",
"]",
"+=",
"me",
"[",
"j",
"]",
"*",
"alpha",
";",
"me",
"[",
"i",
"+",
"3",
"]",
"+=",
"me",
"[",
"j",
"+",
"3",
"]",
"*",
"alpha",
";",
"me",
"[",
"i",
"+",
"6",
"]",
"+=",
"me",
"[",
"j",
"+",
"6",
"]",
"*",
"alpha",
";",
"}"
] | Scales and adds the source row to the destination row.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} m The matrix.
@param {number} srcRow The original row index.
@param {number} destRow The destination row index for the sum to be in.
@param {number} scale The number to scale the source row by. | [
"Scales",
"and",
"adds",
"the",
"source",
"row",
"to",
"the",
"destination",
"row",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L237-L245 |
51,771 | tab58/minimatrix | src/math-helpers.js | thresholdToZero | function thresholdToZero (m, TOL) {
const me = m.elements;
for (let i = 0; i < 9; ++i) {
if (Compare.isZero(me[i], TOL)) {
me[i] = 0;
}
}
return m;
} | javascript | function thresholdToZero (m, TOL) {
const me = m.elements;
for (let i = 0; i < 9; ++i) {
if (Compare.isZero(me[i], TOL)) {
me[i] = 0;
}
}
return m;
} | [
"function",
"thresholdToZero",
"(",
"m",
",",
"TOL",
")",
"{",
"const",
"me",
"=",
"m",
".",
"elements",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"9",
";",
"++",
"i",
")",
"{",
"if",
"(",
"Compare",
".",
"isZero",
"(",
"me",
"[",
"i",
"]",
",",
"TOL",
")",
")",
"{",
"me",
"[",
"i",
"]",
"=",
"0",
";",
"}",
"}",
"return",
"m",
";",
"}"
] | Thresholds all values of a matrix whose magnitude is less than the numerical tolerance.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} m The matrix.
@param {number} TOL The numerical tolerance. | [
"Thresholds",
"all",
"values",
"of",
"a",
"matrix",
"whose",
"magnitude",
"is",
"less",
"than",
"the",
"numerical",
"tolerance",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L253-L261 |
51,772 | tab58/minimatrix | src/math-helpers.js | luSolve | function luSolve (A, P, b, X) {
// Since PA = LU, then L(U x) = Pb
const a = A.elements;
const n = A.dimension;
// L * y = P * b, solve for y.
// Implicit 1's on the diagonal.
for (let i = 0; i < n; ++i) {
let sum = 0;
for (let j = 0; j < i; ++j) {
sum += a[i + j * n] * X.getComponent(j);
}
const xi = b.getComponent(P[i]) - sum;
X.setComponent(i, xi);
}
// U * x = y ==> i = n-1 -> 0, j = 0
for (let i = n - 1; i >= 0; --i) {
let sum = 0;
for (let j = i + 1; j < n; ++j) {
sum += a[i + j * n] * X.getComponent(j);
}
const scale = a[i + i * n];
// if (scale === 0) {
// consoleWarning(`luSolve(): x[${i}] is free.`);
// }
X.setComponent(i, (X.getComponent(i) - sum) / scale);
}
return X;
} | javascript | function luSolve (A, P, b, X) {
// Since PA = LU, then L(U x) = Pb
const a = A.elements;
const n = A.dimension;
// L * y = P * b, solve for y.
// Implicit 1's on the diagonal.
for (let i = 0; i < n; ++i) {
let sum = 0;
for (let j = 0; j < i; ++j) {
sum += a[i + j * n] * X.getComponent(j);
}
const xi = b.getComponent(P[i]) - sum;
X.setComponent(i, xi);
}
// U * x = y ==> i = n-1 -> 0, j = 0
for (let i = n - 1; i >= 0; --i) {
let sum = 0;
for (let j = i + 1; j < n; ++j) {
sum += a[i + j * n] * X.getComponent(j);
}
const scale = a[i + i * n];
// if (scale === 0) {
// consoleWarning(`luSolve(): x[${i}] is free.`);
// }
X.setComponent(i, (X.getComponent(i) - sum) / scale);
}
return X;
} | [
"function",
"luSolve",
"(",
"A",
",",
"P",
",",
"b",
",",
"X",
")",
"{",
"// Since PA = LU, then L(U x) = Pb",
"const",
"a",
"=",
"A",
".",
"elements",
";",
"const",
"n",
"=",
"A",
".",
"dimension",
";",
"// L * y = P * b, solve for y.",
"// Implicit 1's on the diagonal.",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"let",
"sum",
"=",
"0",
";",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"i",
";",
"++",
"j",
")",
"{",
"sum",
"+=",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"*",
"X",
".",
"getComponent",
"(",
"j",
")",
";",
"}",
"const",
"xi",
"=",
"b",
".",
"getComponent",
"(",
"P",
"[",
"i",
"]",
")",
"-",
"sum",
";",
"X",
".",
"setComponent",
"(",
"i",
",",
"xi",
")",
";",
"}",
"// U * x = y ==> i = n-1 -> 0, j = 0",
"for",
"(",
"let",
"i",
"=",
"n",
"-",
"1",
";",
"i",
">=",
"0",
";",
"--",
"i",
")",
"{",
"let",
"sum",
"=",
"0",
";",
"for",
"(",
"let",
"j",
"=",
"i",
"+",
"1",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"sum",
"+=",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"*",
"X",
".",
"getComponent",
"(",
"j",
")",
";",
"}",
"const",
"scale",
"=",
"a",
"[",
"i",
"+",
"i",
"*",
"n",
"]",
";",
"// if (scale === 0) {",
"// consoleWarning(`luSolve(): x[${i}] is free.`);",
"// }",
"X",
".",
"setComponent",
"(",
"i",
",",
"(",
"X",
".",
"getComponent",
"(",
"i",
")",
"-",
"sum",
")",
"/",
"scale",
")",
";",
"}",
"return",
"X",
";",
"}"
] | Solves the Ax=b problem with an LU decomposition.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} A The LU decomposed matrix.
@param {number[]} P The permutation array.
@param {Vector2|Vector3|Vector4} b The right side vector in the Ax=b problem.
@param {Vector2|Vector3|Vector4} X The solution to the problem. | [
"Solves",
"the",
"Ax",
"=",
"b",
"problem",
"with",
"an",
"LU",
"decomposition",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L271-L299 |
51,773 | tab58/minimatrix | src/math-helpers.js | luDecomposition | function luDecomposition (A, inPlace) {
const n = A.dimension;
const AA = inPlace ? A : A.clone();
const a = AA.elements; // indexed via a_ij = a[i + j * n]
const P = [];
const rowScalers = [];
for (let i = 0; i < n; ++i) {
P.push(i);
const col = findLargestInRow(A, i);
const scaler = a[col * n + i]; // row scaling
if (scaler === 0) {
throw new Error('luDecomposition(): matrix is singular and cannot be LU factorized.');
}
rowScalers[i] = scaler; // don't actually want to scale the matrix or else (PA != LU).
}
// iterate over columns to reduce the matrix
// implicitly reduce the matrix
for (let j = 0; j < n; ++j) {
for (let i = 0; i < j; ++i) {
// compute upper tri, computes values across the row
let sum = 0;
for (let k = 0; k < i; ++k) {
sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
}
a[i + j * n] = a[i + j * n] - sum;
}
let pivotLrgElem = 0;
let pivotIndex = j;
for (let i = j; i < n; ++i) {
// compute lower tri and diagonal, computes values down the column
let sum = 0;
for (let k = 0; k < j; ++k) {
sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
}
a[i + j * n] = a[i + j * n] - sum;
// find the pivot element
const pivotTest = rowScalers[i] * Math.abs(a[i + j * n]);
if (pivotTest > pivotLrgElem) {
pivotLrgElem = pivotTest;
pivotIndex = i;
}
}
swapRowsInPlace(A, j, pivotIndex);
swapValuesInArray(P, j, pivotIndex);
swapValuesInArray(rowScalers, j, pivotIndex);
if (j < n - 1) {
const pivotScale = a[j + j * n];
for (let i = j + 1; i < n; ++i) {
a[i + j * n] /= pivotScale;
}
}
}
return {
P,
A
};
} | javascript | function luDecomposition (A, inPlace) {
const n = A.dimension;
const AA = inPlace ? A : A.clone();
const a = AA.elements; // indexed via a_ij = a[i + j * n]
const P = [];
const rowScalers = [];
for (let i = 0; i < n; ++i) {
P.push(i);
const col = findLargestInRow(A, i);
const scaler = a[col * n + i]; // row scaling
if (scaler === 0) {
throw new Error('luDecomposition(): matrix is singular and cannot be LU factorized.');
}
rowScalers[i] = scaler; // don't actually want to scale the matrix or else (PA != LU).
}
// iterate over columns to reduce the matrix
// implicitly reduce the matrix
for (let j = 0; j < n; ++j) {
for (let i = 0; i < j; ++i) {
// compute upper tri, computes values across the row
let sum = 0;
for (let k = 0; k < i; ++k) {
sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
}
a[i + j * n] = a[i + j * n] - sum;
}
let pivotLrgElem = 0;
let pivotIndex = j;
for (let i = j; i < n; ++i) {
// compute lower tri and diagonal, computes values down the column
let sum = 0;
for (let k = 0; k < j; ++k) {
sum += a[i + k * n] * a[k + j * n]; // avoid big + small roundoffs
}
a[i + j * n] = a[i + j * n] - sum;
// find the pivot element
const pivotTest = rowScalers[i] * Math.abs(a[i + j * n]);
if (pivotTest > pivotLrgElem) {
pivotLrgElem = pivotTest;
pivotIndex = i;
}
}
swapRowsInPlace(A, j, pivotIndex);
swapValuesInArray(P, j, pivotIndex);
swapValuesInArray(rowScalers, j, pivotIndex);
if (j < n - 1) {
const pivotScale = a[j + j * n];
for (let i = j + 1; i < n; ++i) {
a[i + j * n] /= pivotScale;
}
}
}
return {
P,
A
};
} | [
"function",
"luDecomposition",
"(",
"A",
",",
"inPlace",
")",
"{",
"const",
"n",
"=",
"A",
".",
"dimension",
";",
"const",
"AA",
"=",
"inPlace",
"?",
"A",
":",
"A",
".",
"clone",
"(",
")",
";",
"const",
"a",
"=",
"AA",
".",
"elements",
";",
"// indexed via a_ij = a[i + j * n]",
"const",
"P",
"=",
"[",
"]",
";",
"const",
"rowScalers",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"P",
".",
"push",
"(",
"i",
")",
";",
"const",
"col",
"=",
"findLargestInRow",
"(",
"A",
",",
"i",
")",
";",
"const",
"scaler",
"=",
"a",
"[",
"col",
"*",
"n",
"+",
"i",
"]",
";",
"// row scaling",
"if",
"(",
"scaler",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'luDecomposition(): matrix is singular and cannot be LU factorized.'",
")",
";",
"}",
"rowScalers",
"[",
"i",
"]",
"=",
"scaler",
";",
"// don't actually want to scale the matrix or else (PA != LU).",
"}",
"// iterate over columns to reduce the matrix",
"// implicitly reduce the matrix",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"j",
";",
"++",
"i",
")",
"{",
"// compute upper tri, computes values across the row",
"let",
"sum",
"=",
"0",
";",
"for",
"(",
"let",
"k",
"=",
"0",
";",
"k",
"<",
"i",
";",
"++",
"k",
")",
"{",
"sum",
"+=",
"a",
"[",
"i",
"+",
"k",
"*",
"n",
"]",
"*",
"a",
"[",
"k",
"+",
"j",
"*",
"n",
"]",
";",
"// avoid big + small roundoffs",
"}",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"=",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"-",
"sum",
";",
"}",
"let",
"pivotLrgElem",
"=",
"0",
";",
"let",
"pivotIndex",
"=",
"j",
";",
"for",
"(",
"let",
"i",
"=",
"j",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"// compute lower tri and diagonal, computes values down the column",
"let",
"sum",
"=",
"0",
";",
"for",
"(",
"let",
"k",
"=",
"0",
";",
"k",
"<",
"j",
";",
"++",
"k",
")",
"{",
"sum",
"+=",
"a",
"[",
"i",
"+",
"k",
"*",
"n",
"]",
"*",
"a",
"[",
"k",
"+",
"j",
"*",
"n",
"]",
";",
"// avoid big + small roundoffs",
"}",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"=",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"-",
"sum",
";",
"// find the pivot element",
"const",
"pivotTest",
"=",
"rowScalers",
"[",
"i",
"]",
"*",
"Math",
".",
"abs",
"(",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
")",
";",
"if",
"(",
"pivotTest",
">",
"pivotLrgElem",
")",
"{",
"pivotLrgElem",
"=",
"pivotTest",
";",
"pivotIndex",
"=",
"i",
";",
"}",
"}",
"swapRowsInPlace",
"(",
"A",
",",
"j",
",",
"pivotIndex",
")",
";",
"swapValuesInArray",
"(",
"P",
",",
"j",
",",
"pivotIndex",
")",
";",
"swapValuesInArray",
"(",
"rowScalers",
",",
"j",
",",
"pivotIndex",
")",
";",
"if",
"(",
"j",
"<",
"n",
"-",
"1",
")",
"{",
"const",
"pivotScale",
"=",
"a",
"[",
"j",
"+",
"j",
"*",
"n",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"j",
"+",
"1",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"a",
"[",
"i",
"+",
"j",
"*",
"n",
"]",
"/=",
"pivotScale",
";",
"}",
"}",
"}",
"return",
"{",
"P",
",",
"A",
"}",
";",
"}"
] | Computes the LU decomposition.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} A The matrix to decompose.
@param {boolean} inPlace Overwrites the A matrix with the LU decomposition if true, creates a new matrix if false. | [
"Computes",
"the",
"LU",
"decomposition",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L307-L365 |
51,774 | tab58/minimatrix | src/math-helpers.js | proj | function proj (u, v) {
return u.clone().multiplyScalar(u.dot(v) / u.dot(u));
} | javascript | function proj (u, v) {
return u.clone().multiplyScalar(u.dot(v) / u.dot(u));
} | [
"function",
"proj",
"(",
"u",
",",
"v",
")",
"{",
"return",
"u",
".",
"clone",
"(",
")",
".",
"multiplyScalar",
"(",
"u",
".",
"dot",
"(",
"v",
")",
"/",
"u",
".",
"dot",
"(",
"u",
")",
")",
";",
"}"
] | Computes the projection of one vector against another.
@memberof Helpers
@param {Vector2|Vector3|Vector4} u The vector to project.
@param {Vector2|Vector3|Vector4} v The vector to be projected against. | [
"Computes",
"the",
"projection",
"of",
"one",
"vector",
"against",
"another",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L373-L375 |
51,775 | tab58/minimatrix | src/math-helpers.js | modifiedGramSchmidt | function modifiedGramSchmidt (m) {
const n = m.dimension;
const v0 = m.getColumn(0);
const u0 = v0;
const v1 = m.getColumn(1);
const u1 = v1.clone().sub(proj(u0, v1));
if (n === 2) {
m.setColumns(v0, v1);
return;
}
const v2 = m.getColumn(2);
const u2t = v2.clone().sub(proj(u0, v2));
const u2 = u2t.sub(proj(u1, u2t));
if (n === 3) {
m.setColumns(u0, u1, u2);
// return;
}
} | javascript | function modifiedGramSchmidt (m) {
const n = m.dimension;
const v0 = m.getColumn(0);
const u0 = v0;
const v1 = m.getColumn(1);
const u1 = v1.clone().sub(proj(u0, v1));
if (n === 2) {
m.setColumns(v0, v1);
return;
}
const v2 = m.getColumn(2);
const u2t = v2.clone().sub(proj(u0, v2));
const u2 = u2t.sub(proj(u1, u2t));
if (n === 3) {
m.setColumns(u0, u1, u2);
// return;
}
} | [
"function",
"modifiedGramSchmidt",
"(",
"m",
")",
"{",
"const",
"n",
"=",
"m",
".",
"dimension",
";",
"const",
"v0",
"=",
"m",
".",
"getColumn",
"(",
"0",
")",
";",
"const",
"u0",
"=",
"v0",
";",
"const",
"v1",
"=",
"m",
".",
"getColumn",
"(",
"1",
")",
";",
"const",
"u1",
"=",
"v1",
".",
"clone",
"(",
")",
".",
"sub",
"(",
"proj",
"(",
"u0",
",",
"v1",
")",
")",
";",
"if",
"(",
"n",
"===",
"2",
")",
"{",
"m",
".",
"setColumns",
"(",
"v0",
",",
"v1",
")",
";",
"return",
";",
"}",
"const",
"v2",
"=",
"m",
".",
"getColumn",
"(",
"2",
")",
";",
"const",
"u2t",
"=",
"v2",
".",
"clone",
"(",
")",
".",
"sub",
"(",
"proj",
"(",
"u0",
",",
"v2",
")",
")",
";",
"const",
"u2",
"=",
"u2t",
".",
"sub",
"(",
"proj",
"(",
"u1",
",",
"u2t",
")",
")",
";",
"if",
"(",
"n",
"===",
"3",
")",
"{",
"m",
".",
"setColumns",
"(",
"u0",
",",
"u1",
",",
"u2",
")",
";",
"// return;",
"}",
"}"
] | Orthogonalizes a matrix using the modified Gram-Schmidt algorithm.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} m The matrix. | [
"Orthogonalizes",
"a",
"matrix",
"using",
"the",
"modified",
"Gram",
"-",
"Schmidt",
"algorithm",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L382-L400 |
51,776 | tab58/minimatrix | src/math-helpers.js | rotg | function rotg (a, b, csr) {
// Based on Algorithm 4 from "Discontinuous Plane
// Rotations and the Symmetric Eigenvalue Problem"
// by Anderson, 2000.
let c = 0;
let s = 0;
let r = 0;
let t = 0;
let u = 0;
if (b === 0) {
c = _Math.sign(a);
s = 0;
r = _Math.abs(a);
} else if (a === 0) {
c = 0;
s = _Math.sign(b);
r = _Math.abs(b);
} else if (_Math.abs(a) > _Math.abs(b)) {
t = b / a;
u = _Math.sign(a) * _Math.sqrt(1 + t * t);
c = 1 / u;
s = t * c;
r = a * u;
} else {
t = a / b;
u = _Math.sign(a) * _Math.sqrt(1 + t * t);
s = 1 / u;
c = t * s;
r = b * u;
}
// try to save some unnecessary object creation
if (csr !== undefined && csr.length > 2) {
csr[0] = c;
csr[1] = s;
csr[2] = r;
} else {
return [c, s, r];
}
} | javascript | function rotg (a, b, csr) {
// Based on Algorithm 4 from "Discontinuous Plane
// Rotations and the Symmetric Eigenvalue Problem"
// by Anderson, 2000.
let c = 0;
let s = 0;
let r = 0;
let t = 0;
let u = 0;
if (b === 0) {
c = _Math.sign(a);
s = 0;
r = _Math.abs(a);
} else if (a === 0) {
c = 0;
s = _Math.sign(b);
r = _Math.abs(b);
} else if (_Math.abs(a) > _Math.abs(b)) {
t = b / a;
u = _Math.sign(a) * _Math.sqrt(1 + t * t);
c = 1 / u;
s = t * c;
r = a * u;
} else {
t = a / b;
u = _Math.sign(a) * _Math.sqrt(1 + t * t);
s = 1 / u;
c = t * s;
r = b * u;
}
// try to save some unnecessary object creation
if (csr !== undefined && csr.length > 2) {
csr[0] = c;
csr[1] = s;
csr[2] = r;
} else {
return [c, s, r];
}
} | [
"function",
"rotg",
"(",
"a",
",",
"b",
",",
"csr",
")",
"{",
"// Based on Algorithm 4 from \"Discontinuous Plane",
"// Rotations and the Symmetric Eigenvalue Problem\"",
"// by Anderson, 2000.",
"let",
"c",
"=",
"0",
";",
"let",
"s",
"=",
"0",
";",
"let",
"r",
"=",
"0",
";",
"let",
"t",
"=",
"0",
";",
"let",
"u",
"=",
"0",
";",
"if",
"(",
"b",
"===",
"0",
")",
"{",
"c",
"=",
"_Math",
".",
"sign",
"(",
"a",
")",
";",
"s",
"=",
"0",
";",
"r",
"=",
"_Math",
".",
"abs",
"(",
"a",
")",
";",
"}",
"else",
"if",
"(",
"a",
"===",
"0",
")",
"{",
"c",
"=",
"0",
";",
"s",
"=",
"_Math",
".",
"sign",
"(",
"b",
")",
";",
"r",
"=",
"_Math",
".",
"abs",
"(",
"b",
")",
";",
"}",
"else",
"if",
"(",
"_Math",
".",
"abs",
"(",
"a",
")",
">",
"_Math",
".",
"abs",
"(",
"b",
")",
")",
"{",
"t",
"=",
"b",
"/",
"a",
";",
"u",
"=",
"_Math",
".",
"sign",
"(",
"a",
")",
"*",
"_Math",
".",
"sqrt",
"(",
"1",
"+",
"t",
"*",
"t",
")",
";",
"c",
"=",
"1",
"/",
"u",
";",
"s",
"=",
"t",
"*",
"c",
";",
"r",
"=",
"a",
"*",
"u",
";",
"}",
"else",
"{",
"t",
"=",
"a",
"/",
"b",
";",
"u",
"=",
"_Math",
".",
"sign",
"(",
"a",
")",
"*",
"_Math",
".",
"sqrt",
"(",
"1",
"+",
"t",
"*",
"t",
")",
";",
"s",
"=",
"1",
"/",
"u",
";",
"c",
"=",
"t",
"*",
"s",
";",
"r",
"=",
"b",
"*",
"u",
";",
"}",
"// try to save some unnecessary object creation",
"if",
"(",
"csr",
"!==",
"undefined",
"&&",
"csr",
".",
"length",
">",
"2",
")",
"{",
"csr",
"[",
"0",
"]",
"=",
"c",
";",
"csr",
"[",
"1",
"]",
"=",
"s",
";",
"csr",
"[",
"2",
"]",
"=",
"r",
";",
"}",
"else",
"{",
"return",
"[",
"c",
",",
"s",
",",
"r",
"]",
";",
"}",
"}"
] | Computes the Givens rotation values for a vector.
@memberof Helpers
@param {number} a The x-component of a vector rotated back to a vector on the X-axis.
@param {number} b The y-component of a vector rotated back to a vector on the X-axis.
@param {array} csr (Optional) An array for the values to saved into, if provided. If not, a new array is created. | [
"Computes",
"the",
"Givens",
"rotation",
"values",
"for",
"a",
"vector",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L409-L448 |
51,777 | tab58/minimatrix | src/math-helpers.js | qrDecomposition | function qrDecomposition (A, inPlace) {
const Q = A.clone().identity();
const R = inPlace ? A : A.clone();
const qe = Q.elements;
const re = R.elements;
const csr = [0, 0, 0];
const DIM = Q.dimension;
const m = DIM;
const n = DIM;
for (let j = 0; j < n; ++j) {
for (let i = m - 1; i >= j + 1; --i) {
const a = re[n * j + (i - 1)]; // R.get(i - 1, j);
const b = re[n * j + i]; // R.get(i, j);
if (a === 0 && b === 0) {
continue;
}
rotg(a, b, csr);
const c = csr[0];
const s = csr[1];
let tmp1 = 0;
let tmp2 = 0;
// R' = G * R
for (let x = 0; x < n; ++x) {
tmp1 = re[n * x + (i - 1)]; // R.get(i - 1, x);
tmp2 = re[n * x + i]; // R.get(i, x);
re[n * x + (i - 1)] = tmp1 * c + tmp2 * s; // R.set(i - 1, x, tmp1 * c + tmp2 * s);
re[n * x + i] = -tmp1 * s + tmp2 * c; // R.set(i, x, -tmp1 * s + tmp2 * c);
}
re[n * j + (i - 1)] = csr[2]; // R.set(i - 1, j, csr[2]);
re[n * j + i] = 0; // R.set(i, j, 0);
// Q' = Q * G^T
for (let x = 0; x < m; ++x) {
tmp1 = qe[n * (i - 1) + x]; // Q.get(x, i - 1);
tmp2 = qe[n * i + x]; // Q.get(x, i);
qe[n * (i - 1) + x] = tmp1 * c + tmp2 * s; // Q.set(x, i - 1, tmp1 * c + tmp2 * s);
qe[n * i + x] = -tmp1 * s + tmp2 * c; // Q.set(x, i, -tmp1 * s + tmp2 * c);
}
}
}
return { Q, R };
} | javascript | function qrDecomposition (A, inPlace) {
const Q = A.clone().identity();
const R = inPlace ? A : A.clone();
const qe = Q.elements;
const re = R.elements;
const csr = [0, 0, 0];
const DIM = Q.dimension;
const m = DIM;
const n = DIM;
for (let j = 0; j < n; ++j) {
for (let i = m - 1; i >= j + 1; --i) {
const a = re[n * j + (i - 1)]; // R.get(i - 1, j);
const b = re[n * j + i]; // R.get(i, j);
if (a === 0 && b === 0) {
continue;
}
rotg(a, b, csr);
const c = csr[0];
const s = csr[1];
let tmp1 = 0;
let tmp2 = 0;
// R' = G * R
for (let x = 0; x < n; ++x) {
tmp1 = re[n * x + (i - 1)]; // R.get(i - 1, x);
tmp2 = re[n * x + i]; // R.get(i, x);
re[n * x + (i - 1)] = tmp1 * c + tmp2 * s; // R.set(i - 1, x, tmp1 * c + tmp2 * s);
re[n * x + i] = -tmp1 * s + tmp2 * c; // R.set(i, x, -tmp1 * s + tmp2 * c);
}
re[n * j + (i - 1)] = csr[2]; // R.set(i - 1, j, csr[2]);
re[n * j + i] = 0; // R.set(i, j, 0);
// Q' = Q * G^T
for (let x = 0; x < m; ++x) {
tmp1 = qe[n * (i - 1) + x]; // Q.get(x, i - 1);
tmp2 = qe[n * i + x]; // Q.get(x, i);
qe[n * (i - 1) + x] = tmp1 * c + tmp2 * s; // Q.set(x, i - 1, tmp1 * c + tmp2 * s);
qe[n * i + x] = -tmp1 * s + tmp2 * c; // Q.set(x, i, -tmp1 * s + tmp2 * c);
}
}
}
return { Q, R };
} | [
"function",
"qrDecomposition",
"(",
"A",
",",
"inPlace",
")",
"{",
"const",
"Q",
"=",
"A",
".",
"clone",
"(",
")",
".",
"identity",
"(",
")",
";",
"const",
"R",
"=",
"inPlace",
"?",
"A",
":",
"A",
".",
"clone",
"(",
")",
";",
"const",
"qe",
"=",
"Q",
".",
"elements",
";",
"const",
"re",
"=",
"R",
".",
"elements",
";",
"const",
"csr",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
";",
"const",
"DIM",
"=",
"Q",
".",
"dimension",
";",
"const",
"m",
"=",
"DIM",
";",
"const",
"n",
"=",
"DIM",
";",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"n",
";",
"++",
"j",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"m",
"-",
"1",
";",
"i",
">=",
"j",
"+",
"1",
";",
"--",
"i",
")",
"{",
"const",
"a",
"=",
"re",
"[",
"n",
"*",
"j",
"+",
"(",
"i",
"-",
"1",
")",
"]",
";",
"// R.get(i - 1, j);",
"const",
"b",
"=",
"re",
"[",
"n",
"*",
"j",
"+",
"i",
"]",
";",
"// R.get(i, j);",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"rotg",
"(",
"a",
",",
"b",
",",
"csr",
")",
";",
"const",
"c",
"=",
"csr",
"[",
"0",
"]",
";",
"const",
"s",
"=",
"csr",
"[",
"1",
"]",
";",
"let",
"tmp1",
"=",
"0",
";",
"let",
"tmp2",
"=",
"0",
";",
"// R' = G * R",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"n",
";",
"++",
"x",
")",
"{",
"tmp1",
"=",
"re",
"[",
"n",
"*",
"x",
"+",
"(",
"i",
"-",
"1",
")",
"]",
";",
"// R.get(i - 1, x);",
"tmp2",
"=",
"re",
"[",
"n",
"*",
"x",
"+",
"i",
"]",
";",
"// R.get(i, x);",
"re",
"[",
"n",
"*",
"x",
"+",
"(",
"i",
"-",
"1",
")",
"]",
"=",
"tmp1",
"*",
"c",
"+",
"tmp2",
"*",
"s",
";",
"// R.set(i - 1, x, tmp1 * c + tmp2 * s);",
"re",
"[",
"n",
"*",
"x",
"+",
"i",
"]",
"=",
"-",
"tmp1",
"*",
"s",
"+",
"tmp2",
"*",
"c",
";",
"// R.set(i, x, -tmp1 * s + tmp2 * c);",
"}",
"re",
"[",
"n",
"*",
"j",
"+",
"(",
"i",
"-",
"1",
")",
"]",
"=",
"csr",
"[",
"2",
"]",
";",
"// R.set(i - 1, j, csr[2]);",
"re",
"[",
"n",
"*",
"j",
"+",
"i",
"]",
"=",
"0",
";",
"// R.set(i, j, 0);",
"// Q' = Q * G^T",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"m",
";",
"++",
"x",
")",
"{",
"tmp1",
"=",
"qe",
"[",
"n",
"*",
"(",
"i",
"-",
"1",
")",
"+",
"x",
"]",
";",
"// Q.get(x, i - 1);",
"tmp2",
"=",
"qe",
"[",
"n",
"*",
"i",
"+",
"x",
"]",
";",
"// Q.get(x, i);",
"qe",
"[",
"n",
"*",
"(",
"i",
"-",
"1",
")",
"+",
"x",
"]",
"=",
"tmp1",
"*",
"c",
"+",
"tmp2",
"*",
"s",
";",
"// Q.set(x, i - 1, tmp1 * c + tmp2 * s);",
"qe",
"[",
"n",
"*",
"i",
"+",
"x",
"]",
"=",
"-",
"tmp1",
"*",
"s",
"+",
"tmp2",
"*",
"c",
";",
"// Q.set(x, i, -tmp1 * s + tmp2 * c);",
"}",
"}",
"}",
"return",
"{",
"Q",
",",
"R",
"}",
";",
"}"
] | Computes the QR decomposition of a matrix.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} A The matrix to decompose.
@param {boolean} inPlace Overwrites the A matrix with the R matrix. | [
"Computes",
"the",
"QR",
"decomposition",
"of",
"a",
"matrix",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L456-L499 |
51,778 | tab58/minimatrix | src/math-helpers.js | getRank | function getRank (M, EPS) {
const n = M.dimension;
const { R } = qrDecomposition(M);
// TODO: this is a bad way of doing this probably
R.thresholdEntriesToZero(100 * EPS);
let rank = 0;
rrefInPlace(R);
for (let i = 0; i < n; ++i) {
if (isRowNonzero(R, i)) {
rank++;
}
}
return rank;
} | javascript | function getRank (M, EPS) {
const n = M.dimension;
const { R } = qrDecomposition(M);
// TODO: this is a bad way of doing this probably
R.thresholdEntriesToZero(100 * EPS);
let rank = 0;
rrefInPlace(R);
for (let i = 0; i < n; ++i) {
if (isRowNonzero(R, i)) {
rank++;
}
}
return rank;
} | [
"function",
"getRank",
"(",
"M",
",",
"EPS",
")",
"{",
"const",
"n",
"=",
"M",
".",
"dimension",
";",
"const",
"{",
"R",
"}",
"=",
"qrDecomposition",
"(",
"M",
")",
";",
"// TODO: this is a bad way of doing this probably",
"R",
".",
"thresholdEntriesToZero",
"(",
"100",
"*",
"EPS",
")",
";",
"let",
"rank",
"=",
"0",
";",
"rrefInPlace",
"(",
"R",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"if",
"(",
"isRowNonzero",
"(",
"R",
",",
"i",
")",
")",
"{",
"rank",
"++",
";",
"}",
"}",
"return",
"rank",
";",
"}"
] | Computes the rank of a matrix.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix to get the rank of.
@param {number} EPS The numerical tolerance for an element to be zero. | [
"Computes",
"the",
"rank",
"of",
"a",
"matrix",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L507-L520 |
51,779 | tab58/minimatrix | src/math-helpers.js | householderTransform | function householderTransform (x) {
// Based on "Matrix Computations" by Golub, Van Loan
const n = x.dimension;
const v = x.clone();
v.x = 1;
let sigma = 0;
for (let i = 1; i < n; ++i) {
const vi = v.getComponent(i);
sigma += vi * vi;
}
let beta = 0;
if (sigma !== 0) {
const x1 = x.x;
const mu = _Math.sqrt(x1 * x1 + sigma);
const v1 = (x1 <= 0 ? x1 - mu : -sigma / (x1 + mu));
v.x = v1;
beta = 2 * v1 * v1 / (sigma + v1 * v1);
v.multiplyScalar(1.0 / v1);
}
return {
v,
beta
};
} | javascript | function householderTransform (x) {
// Based on "Matrix Computations" by Golub, Van Loan
const n = x.dimension;
const v = x.clone();
v.x = 1;
let sigma = 0;
for (let i = 1; i < n; ++i) {
const vi = v.getComponent(i);
sigma += vi * vi;
}
let beta = 0;
if (sigma !== 0) {
const x1 = x.x;
const mu = _Math.sqrt(x1 * x1 + sigma);
const v1 = (x1 <= 0 ? x1 - mu : -sigma / (x1 + mu));
v.x = v1;
beta = 2 * v1 * v1 / (sigma + v1 * v1);
v.multiplyScalar(1.0 / v1);
}
return {
v,
beta
};
} | [
"function",
"householderTransform",
"(",
"x",
")",
"{",
"// Based on \"Matrix Computations\" by Golub, Van Loan",
"const",
"n",
"=",
"x",
".",
"dimension",
";",
"const",
"v",
"=",
"x",
".",
"clone",
"(",
")",
";",
"v",
".",
"x",
"=",
"1",
";",
"let",
"sigma",
"=",
"0",
";",
"for",
"(",
"let",
"i",
"=",
"1",
";",
"i",
"<",
"n",
";",
"++",
"i",
")",
"{",
"const",
"vi",
"=",
"v",
".",
"getComponent",
"(",
"i",
")",
";",
"sigma",
"+=",
"vi",
"*",
"vi",
";",
"}",
"let",
"beta",
"=",
"0",
";",
"if",
"(",
"sigma",
"!==",
"0",
")",
"{",
"const",
"x1",
"=",
"x",
".",
"x",
";",
"const",
"mu",
"=",
"_Math",
".",
"sqrt",
"(",
"x1",
"*",
"x1",
"+",
"sigma",
")",
";",
"const",
"v1",
"=",
"(",
"x1",
"<=",
"0",
"?",
"x1",
"-",
"mu",
":",
"-",
"sigma",
"/",
"(",
"x1",
"+",
"mu",
")",
")",
";",
"v",
".",
"x",
"=",
"v1",
";",
"beta",
"=",
"2",
"*",
"v1",
"*",
"v1",
"/",
"(",
"sigma",
"+",
"v1",
"*",
"v1",
")",
";",
"v",
".",
"multiplyScalar",
"(",
"1.0",
"/",
"v1",
")",
";",
"}",
"return",
"{",
"v",
",",
"beta",
"}",
";",
"}"
] | Computes the Householder transform vector and scale.
@memberof Helpers
@param {Vector2|Vector3|Vector4} x The vector to rotate. | [
"Computes",
"the",
"Householder",
"transform",
"vector",
"and",
"scale",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L527-L550 |
51,780 | tab58/minimatrix | src/math-helpers.js | hessenbergQRStep | function hessenbergQRStep (M) {
const n = M.dimension;
const me = M.elements;
const csr = [0, 0, 0];
const cs = [];
for (let k = 0; k < n - 1; ++k) {
const row1 = k;
const row2 = k + 1;
const colK = k * n;
const a = me[row1 + colK];
const b = me[row2 + colK];
rotg(a, b, csr);
const c = csr[0];
const s = csr[1];
const r = csr[2];
cs[k] = [c, s];
for (let x = k; x < n; ++x) {
const colX = x * n;
const tmp1 = me[row1 + colX];
const tmp2 = me[row2 + colX];
me[row1 + colX] = c * tmp1 + s * tmp2;
me[row2 + colX] = -s * tmp1 + c * tmp2;
}
me[row1 + colK] = r;
me[row2 + colK] = 0;
}
for (let k = 0; k < n - 1; ++k) {
const col1 = k * n;
const col2 = (k + 1) * n;
const [c, s] = cs[k];
for (let x = 0; x <= k + 1; ++x) {
const rowX = x;
const tmp1 = me[rowX + col1];
const tmp2 = me[rowX + col2];
me[rowX + col1] = tmp1 * c + tmp2 * s;
me[rowX + col2] = -tmp1 * s + tmp2 * c;
}
}
return M;
} | javascript | function hessenbergQRStep (M) {
const n = M.dimension;
const me = M.elements;
const csr = [0, 0, 0];
const cs = [];
for (let k = 0; k < n - 1; ++k) {
const row1 = k;
const row2 = k + 1;
const colK = k * n;
const a = me[row1 + colK];
const b = me[row2 + colK];
rotg(a, b, csr);
const c = csr[0];
const s = csr[1];
const r = csr[2];
cs[k] = [c, s];
for (let x = k; x < n; ++x) {
const colX = x * n;
const tmp1 = me[row1 + colX];
const tmp2 = me[row2 + colX];
me[row1 + colX] = c * tmp1 + s * tmp2;
me[row2 + colX] = -s * tmp1 + c * tmp2;
}
me[row1 + colK] = r;
me[row2 + colK] = 0;
}
for (let k = 0; k < n - 1; ++k) {
const col1 = k * n;
const col2 = (k + 1) * n;
const [c, s] = cs[k];
for (let x = 0; x <= k + 1; ++x) {
const rowX = x;
const tmp1 = me[rowX + col1];
const tmp2 = me[rowX + col2];
me[rowX + col1] = tmp1 * c + tmp2 * s;
me[rowX + col2] = -tmp1 * s + tmp2 * c;
}
}
return M;
} | [
"function",
"hessenbergQRStep",
"(",
"M",
")",
"{",
"const",
"n",
"=",
"M",
".",
"dimension",
";",
"const",
"me",
"=",
"M",
".",
"elements",
";",
"const",
"csr",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
";",
"const",
"cs",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"k",
"=",
"0",
";",
"k",
"<",
"n",
"-",
"1",
";",
"++",
"k",
")",
"{",
"const",
"row1",
"=",
"k",
";",
"const",
"row2",
"=",
"k",
"+",
"1",
";",
"const",
"colK",
"=",
"k",
"*",
"n",
";",
"const",
"a",
"=",
"me",
"[",
"row1",
"+",
"colK",
"]",
";",
"const",
"b",
"=",
"me",
"[",
"row2",
"+",
"colK",
"]",
";",
"rotg",
"(",
"a",
",",
"b",
",",
"csr",
")",
";",
"const",
"c",
"=",
"csr",
"[",
"0",
"]",
";",
"const",
"s",
"=",
"csr",
"[",
"1",
"]",
";",
"const",
"r",
"=",
"csr",
"[",
"2",
"]",
";",
"cs",
"[",
"k",
"]",
"=",
"[",
"c",
",",
"s",
"]",
";",
"for",
"(",
"let",
"x",
"=",
"k",
";",
"x",
"<",
"n",
";",
"++",
"x",
")",
"{",
"const",
"colX",
"=",
"x",
"*",
"n",
";",
"const",
"tmp1",
"=",
"me",
"[",
"row1",
"+",
"colX",
"]",
";",
"const",
"tmp2",
"=",
"me",
"[",
"row2",
"+",
"colX",
"]",
";",
"me",
"[",
"row1",
"+",
"colX",
"]",
"=",
"c",
"*",
"tmp1",
"+",
"s",
"*",
"tmp2",
";",
"me",
"[",
"row2",
"+",
"colX",
"]",
"=",
"-",
"s",
"*",
"tmp1",
"+",
"c",
"*",
"tmp2",
";",
"}",
"me",
"[",
"row1",
"+",
"colK",
"]",
"=",
"r",
";",
"me",
"[",
"row2",
"+",
"colK",
"]",
"=",
"0",
";",
"}",
"for",
"(",
"let",
"k",
"=",
"0",
";",
"k",
"<",
"n",
"-",
"1",
";",
"++",
"k",
")",
"{",
"const",
"col1",
"=",
"k",
"*",
"n",
";",
"const",
"col2",
"=",
"(",
"k",
"+",
"1",
")",
"*",
"n",
";",
"const",
"[",
"c",
",",
"s",
"]",
"=",
"cs",
"[",
"k",
"]",
";",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<=",
"k",
"+",
"1",
";",
"++",
"x",
")",
"{",
"const",
"rowX",
"=",
"x",
";",
"const",
"tmp1",
"=",
"me",
"[",
"rowX",
"+",
"col1",
"]",
";",
"const",
"tmp2",
"=",
"me",
"[",
"rowX",
"+",
"col2",
"]",
";",
"me",
"[",
"rowX",
"+",
"col1",
"]",
"=",
"tmp1",
"*",
"c",
"+",
"tmp2",
"*",
"s",
";",
"me",
"[",
"rowX",
"+",
"col2",
"]",
"=",
"-",
"tmp1",
"*",
"s",
"+",
"tmp2",
"*",
"c",
";",
"}",
"}",
"return",
"M",
";",
"}"
] | Computes a Hessenberg step of the QR algorithm.
@memberof Helpers
@param {Matrix2|Matrix3|Matrix4} M The matrix to step. | [
"Computes",
"a",
"Hessenberg",
"step",
"of",
"the",
"QR",
"algorithm",
"."
] | 542f1d964b7ae92f96b1069ff5f3495561fe75cd | https://github.com/tab58/minimatrix/blob/542f1d964b7ae92f96b1069ff5f3495561fe75cd/src/math-helpers.js#L557-L596 |
51,781 | unshiftio/hang | index.js | bro | function bro() {
var self = this;
//
// Time has passed since we've generated this function so we're going to
// assume that this function is already executed async.
//
if (+(new Date()) > start) {
return fn.apply(self, arguments);
}
for (var i = 0, l = arguments.length, args = new Array(l); i < l; i++) {
args[i] = arguments[i];
}
(global.setImmediate || global.setTimeout)(function delay() {
fn.apply(self, args);
self = args = null;
}, 0);
} | javascript | function bro() {
var self = this;
//
// Time has passed since we've generated this function so we're going to
// assume that this function is already executed async.
//
if (+(new Date()) > start) {
return fn.apply(self, arguments);
}
for (var i = 0, l = arguments.length, args = new Array(l); i < l; i++) {
args[i] = arguments[i];
}
(global.setImmediate || global.setTimeout)(function delay() {
fn.apply(self, args);
self = args = null;
}, 0);
} | [
"function",
"bro",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"//",
"// Time has passed since we've generated this function so we're going to",
"// assume that this function is already executed async.",
"//",
"if",
"(",
"+",
"(",
"new",
"Date",
"(",
")",
")",
">",
"start",
")",
"{",
"return",
"fn",
".",
"apply",
"(",
"self",
",",
"arguments",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"l",
")",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"args",
"[",
"i",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"(",
"global",
".",
"setImmediate",
"||",
"global",
".",
"setTimeout",
")",
"(",
"function",
"delay",
"(",
")",
"{",
"fn",
".",
"apply",
"(",
"self",
",",
"args",
")",
";",
"self",
"=",
"args",
"=",
"null",
";",
"}",
",",
"0",
")",
";",
"}"
] | The wrapped function.
@api private | [
"The",
"wrapped",
"function",
"."
] | 375f30d5bdb0ad22349dabe52855b123dda9b8b4 | https://github.com/unshiftio/hang/blob/375f30d5bdb0ad22349dabe52855b123dda9b8b4/index.js#L18-L37 |
51,782 | fin-hypergrid/hyper-analytics | js/util/Mappy.js | betterIndexOf | function betterIndexOf(arr, value) {
if (value != value || value === 0) { // eslint-disable-line eqeqeq
var i = arr.length;
while (i-- && !is(arr[i], value)) {
// eslint-disable-line no-empty
}
} else {
i = [].indexOf.call(arr, value);
}
return i;
} | javascript | function betterIndexOf(arr, value) {
if (value != value || value === 0) { // eslint-disable-line eqeqeq
var i = arr.length;
while (i-- && !is(arr[i], value)) {
// eslint-disable-line no-empty
}
} else {
i = [].indexOf.call(arr, value);
}
return i;
} | [
"function",
"betterIndexOf",
"(",
"arr",
",",
"value",
")",
"{",
"if",
"(",
"value",
"!=",
"value",
"||",
"value",
"===",
"0",
")",
"{",
"// eslint-disable-line eqeqeq",
"var",
"i",
"=",
"arr",
".",
"length",
";",
"while",
"(",
"i",
"--",
"&&",
"!",
"is",
"(",
"arr",
"[",
"i",
"]",
",",
"value",
")",
")",
"{",
"// eslint-disable-line no-empty",
"}",
"}",
"else",
"{",
"i",
"=",
"[",
"]",
".",
"indexOf",
".",
"call",
"(",
"arr",
",",
"value",
")",
";",
"}",
"return",
"i",
";",
"}"
] | More reliable indexOf, courtesy of @WebReflection | [
"More",
"reliable",
"indexOf",
"courtesy",
"of"
] | 70257bf0d0388d29177ce86192d0d08508b2a22e | https://github.com/fin-hypergrid/hyper-analytics/blob/70257bf0d0388d29177ce86192d0d08508b2a22e/js/util/Mappy.js#L173-L183 |
51,783 | andrewscwei/requiem | src/helpers/isCustomElement.js | isCustomElement | function isCustomElement(element) {
assertType(element, Node, false, 'Invalid element specified');
let is = getAttribute(element, 'is');
let tag = element.tagName.toLowerCase();
if (is && (getElementRegistry(is) !== undefined)) return true;
if (tag && (getElementRegistry(tag) !== undefined)) return true;
return false;
} | javascript | function isCustomElement(element) {
assertType(element, Node, false, 'Invalid element specified');
let is = getAttribute(element, 'is');
let tag = element.tagName.toLowerCase();
if (is && (getElementRegistry(is) !== undefined)) return true;
if (tag && (getElementRegistry(tag) !== undefined)) return true;
return false;
} | [
"function",
"isCustomElement",
"(",
"element",
")",
"{",
"assertType",
"(",
"element",
",",
"Node",
",",
"false",
",",
"'Invalid element specified'",
")",
";",
"let",
"is",
"=",
"getAttribute",
"(",
"element",
",",
"'is'",
")",
";",
"let",
"tag",
"=",
"element",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"is",
"&&",
"(",
"getElementRegistry",
"(",
"is",
")",
"!==",
"undefined",
")",
")",
"return",
"true",
";",
"if",
"(",
"tag",
"&&",
"(",
"getElementRegistry",
"(",
"tag",
")",
"!==",
"undefined",
")",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Verifies that the specified element is a custom Requiem element.
@param {Node} element - Target element.
@return {boolean} True if recognized as custom Requiem element, false
otherwise.
@alias module:requiem~helpers.isCustomElement | [
"Verifies",
"that",
"the",
"specified",
"element",
"is",
"a",
"custom",
"Requiem",
"element",
"."
] | c4182bfffc9841c6de5718f689ad3c2060511777 | https://github.com/andrewscwei/requiem/blob/c4182bfffc9841c6de5718f689ad3c2060511777/src/helpers/isCustomElement.js#L19-L28 |
51,784 | vkiding/judpack-lib | src/gitclone.js | clone | function clone(git_url, git_ref, clone_dir){
var needsGitCheckout = !!git_ref;
if (!shell.which('git')) {
return Q.reject(new Error('"git" command line tool is not installed: make sure it is accessible on your PATH.'));
}
// If no clone_dir is specified, create a tmp dir which git will clone into.
var tmp_dir = clone_dir;
if(!tmp_dir){
tmp_dir = path.join(os.tmpdir(), 'git', String((new Date()).valueOf()));
}
shell.rm('-rf', tmp_dir);
shell.mkdir('-p', tmp_dir);
var cloneArgs = ['clone'];
if(!needsGitCheckout) {
// only get depth of 1 if there is no branch/commit specified
cloneArgs.push('--depth=1');
}
cloneArgs.push(git_url, tmp_dir);
return superspawn.spawn('git', cloneArgs)
.then(function() {
if (needsGitCheckout){
return superspawn.spawn('git', ['checkout', git_ref], {
cwd: tmp_dir
});
}
})
.then(function(){
events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + (git_ref || 'master') + '".');
return tmp_dir;
})
.fail(function (err) {
shell.rm('-rf', tmp_dir);
return Q.reject(err);
});
} | javascript | function clone(git_url, git_ref, clone_dir){
var needsGitCheckout = !!git_ref;
if (!shell.which('git')) {
return Q.reject(new Error('"git" command line tool is not installed: make sure it is accessible on your PATH.'));
}
// If no clone_dir is specified, create a tmp dir which git will clone into.
var tmp_dir = clone_dir;
if(!tmp_dir){
tmp_dir = path.join(os.tmpdir(), 'git', String((new Date()).valueOf()));
}
shell.rm('-rf', tmp_dir);
shell.mkdir('-p', tmp_dir);
var cloneArgs = ['clone'];
if(!needsGitCheckout) {
// only get depth of 1 if there is no branch/commit specified
cloneArgs.push('--depth=1');
}
cloneArgs.push(git_url, tmp_dir);
return superspawn.spawn('git', cloneArgs)
.then(function() {
if (needsGitCheckout){
return superspawn.spawn('git', ['checkout', git_ref], {
cwd: tmp_dir
});
}
})
.then(function(){
events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + (git_ref || 'master') + '".');
return tmp_dir;
})
.fail(function (err) {
shell.rm('-rf', tmp_dir);
return Q.reject(err);
});
} | [
"function",
"clone",
"(",
"git_url",
",",
"git_ref",
",",
"clone_dir",
")",
"{",
"var",
"needsGitCheckout",
"=",
"!",
"!",
"git_ref",
";",
"if",
"(",
"!",
"shell",
".",
"which",
"(",
"'git'",
")",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"new",
"Error",
"(",
"'\"git\" command line tool is not installed: make sure it is accessible on your PATH.'",
")",
")",
";",
"}",
"// If no clone_dir is specified, create a tmp dir which git will clone into.",
"var",
"tmp_dir",
"=",
"clone_dir",
";",
"if",
"(",
"!",
"tmp_dir",
")",
"{",
"tmp_dir",
"=",
"path",
".",
"join",
"(",
"os",
".",
"tmpdir",
"(",
")",
",",
"'git'",
",",
"String",
"(",
"(",
"new",
"Date",
"(",
")",
")",
".",
"valueOf",
"(",
")",
")",
")",
";",
"}",
"shell",
".",
"rm",
"(",
"'-rf'",
",",
"tmp_dir",
")",
";",
"shell",
".",
"mkdir",
"(",
"'-p'",
",",
"tmp_dir",
")",
";",
"var",
"cloneArgs",
"=",
"[",
"'clone'",
"]",
";",
"if",
"(",
"!",
"needsGitCheckout",
")",
"{",
"// only get depth of 1 if there is no branch/commit specified",
"cloneArgs",
".",
"push",
"(",
"'--depth=1'",
")",
";",
"}",
"cloneArgs",
".",
"push",
"(",
"git_url",
",",
"tmp_dir",
")",
";",
"return",
"superspawn",
".",
"spawn",
"(",
"'git'",
",",
"cloneArgs",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"needsGitCheckout",
")",
"{",
"return",
"superspawn",
".",
"spawn",
"(",
"'git'",
",",
"[",
"'checkout'",
",",
"git_ref",
"]",
",",
"{",
"cwd",
":",
"tmp_dir",
"}",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"events",
".",
"emit",
"(",
"'log'",
",",
"'Repository \"'",
"+",
"git_url",
"+",
"'\" checked out to git ref \"'",
"+",
"(",
"git_ref",
"||",
"'master'",
")",
"+",
"'\".'",
")",
";",
"return",
"tmp_dir",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"shell",
".",
"rm",
"(",
"'-rf'",
",",
"tmp_dir",
")",
";",
"return",
"Q",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | clone_dir, if provided is the directory that git will clone into. if no clone_dir is supplied, a temp directory will be created and used by git. | [
"clone_dir",
"if",
"provided",
"is",
"the",
"directory",
"that",
"git",
"will",
"clone",
"into",
".",
"if",
"no",
"clone_dir",
"is",
"supplied",
"a",
"temp",
"directory",
"will",
"be",
"created",
"and",
"used",
"by",
"git",
"."
] | 8657cecfec68221109279106adca8dbc81f430f4 | https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/gitclone.js#L32-L69 |
51,785 | repetere/periodicjs.core.cache | lib/viewcache.js | function (options) {
var defaultOptions = {
viewCacheDir: viewCacheDir,
expires: 3600
};
this.type='flatfile';
this.prefix='flatfile';
this.driver = 'fs';
this._size = 0;
this._hits = 0;
this._misses = 0;
this.options = merge(defaultOptions,options);
this.expires = this.options.expires;
viewCacheDir = this.options.viewCacheDir;
fs.ensureDir(viewCacheDir,function(err){
if(err){
console.error(err);
}
});
} | javascript | function (options) {
var defaultOptions = {
viewCacheDir: viewCacheDir,
expires: 3600
};
this.type='flatfile';
this.prefix='flatfile';
this.driver = 'fs';
this._size = 0;
this._hits = 0;
this._misses = 0;
this.options = merge(defaultOptions,options);
this.expires = this.options.expires;
viewCacheDir = this.options.viewCacheDir;
fs.ensureDir(viewCacheDir,function(err){
if(err){
console.error(err);
}
});
} | [
"function",
"(",
"options",
")",
"{",
"var",
"defaultOptions",
"=",
"{",
"viewCacheDir",
":",
"viewCacheDir",
",",
"expires",
":",
"3600",
"}",
";",
"this",
".",
"type",
"=",
"'flatfile'",
";",
"this",
".",
"prefix",
"=",
"'flatfile'",
";",
"this",
".",
"driver",
"=",
"'fs'",
";",
"this",
".",
"_size",
"=",
"0",
";",
"this",
".",
"_hits",
"=",
"0",
";",
"this",
".",
"_misses",
"=",
"0",
";",
"this",
".",
"options",
"=",
"merge",
"(",
"defaultOptions",
",",
"options",
")",
";",
"this",
".",
"expires",
"=",
"this",
".",
"options",
".",
"expires",
";",
"viewCacheDir",
"=",
"this",
".",
"options",
".",
"viewCacheDir",
";",
"fs",
".",
"ensureDir",
"(",
"viewCacheDir",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] | A core constructor that provides numerous cache helper functions.
@{@link https://github.com/typesettin/periodicjs.core.cache}
@author Yaw Joseph Etse
@constructor
@copyright Copyright (c) 2014 Typesettin. All rights reserved.
@license MIT
@requires module:fs-extra
@requires module:path
@requires module:du
@param {object} options {viewCacheDir} | [
"A",
"core",
"constructor",
"that",
"provides",
"numerous",
"cache",
"helper",
"functions",
"."
] | c78f633b575d8ba5d59f3517b525860b59e05927 | https://github.com/repetere/periodicjs.core.cache/blob/c78f633b575d8ba5d59f3517b525860b59e05927/lib/viewcache.js#L28-L47 |
|
51,786 | aureooms/js-grammar | lib/util/setadd.js | setadd | function setadd(set, element) {
if (set.has(element)) return false;
set.add(element);
return true;
} | javascript | function setadd(set, element) {
if (set.has(element)) return false;
set.add(element);
return true;
} | [
"function",
"setadd",
"(",
"set",
",",
"element",
")",
"{",
"if",
"(",
"set",
".",
"has",
"(",
"element",
")",
")",
"return",
"false",
";",
"set",
".",
"add",
"(",
"element",
")",
";",
"return",
"true",
";",
"}"
] | Adds an element to a set and returns true if the set has changed.
@param {Set} set - The set to add to.
@param {Object} element - The element to add to the set.
@returns {Boolean} Whether <code>set</code> has changed. | [
"Adds",
"an",
"element",
"to",
"a",
"set",
"and",
"returns",
"true",
"if",
"the",
"set",
"has",
"changed",
"."
] | 28c4d1a3175327b33766c34539eab317303e26c5 | https://github.com/aureooms/js-grammar/blob/28c4d1a3175327b33766c34539eab317303e26c5/lib/util/setadd.js#L15-L19 |
51,787 | redisjs/jsr-server | lib/argv.js | argv | function argv(args) {
var out = {directives: {}}
, i = 0;
/* istanbul ignore next: never use process.argv in tests */
args = args || process.argv.slice(2);
if(!args.length) return out;
// read conf from stdin
if(args[i] === STDIN) {
out.stdin = true;
i++;
// conf should be first arg
}else if(!PTN.test(args[i])) {
out.file = args[i];
i++;
}
function add(key, value) {
if(!key || value === null) return;
if(!out.directives[key]) {
out.directives[key] = value;
// handle repeated directives, create an array
}else if(out.directives[key]
&& !Array.isArray(out.directives[key])){
out.directives[key] = [out.directives[key]];
out.directives[key].push(value)
// append to existing array value
}else{
out.directives[key].push(value)
}
}
function gobble(arg, key, value) {
if(arg === undefined) return add(key, value);
value = value || '';
if(PTN.test(arg)) {
key = arg.replace(PTN, '');
// gobble up value arguments
while((arg = args[i++]) !== undefined && !PTN.test(arg)) {
if(value) value += ' ';
value += arg;
}
if(PTN.test(arg)) i--;
add(key, value);
value = null;
}else{
if(value) value += ' ';
value += arg;
}
gobble(args[i++], key, value);
}
gobble(args[i]);
return out;
} | javascript | function argv(args) {
var out = {directives: {}}
, i = 0;
/* istanbul ignore next: never use process.argv in tests */
args = args || process.argv.slice(2);
if(!args.length) return out;
// read conf from stdin
if(args[i] === STDIN) {
out.stdin = true;
i++;
// conf should be first arg
}else if(!PTN.test(args[i])) {
out.file = args[i];
i++;
}
function add(key, value) {
if(!key || value === null) return;
if(!out.directives[key]) {
out.directives[key] = value;
// handle repeated directives, create an array
}else if(out.directives[key]
&& !Array.isArray(out.directives[key])){
out.directives[key] = [out.directives[key]];
out.directives[key].push(value)
// append to existing array value
}else{
out.directives[key].push(value)
}
}
function gobble(arg, key, value) {
if(arg === undefined) return add(key, value);
value = value || '';
if(PTN.test(arg)) {
key = arg.replace(PTN, '');
// gobble up value arguments
while((arg = args[i++]) !== undefined && !PTN.test(arg)) {
if(value) value += ' ';
value += arg;
}
if(PTN.test(arg)) i--;
add(key, value);
value = null;
}else{
if(value) value += ' ';
value += arg;
}
gobble(args[i++], key, value);
}
gobble(args[i]);
return out;
} | [
"function",
"argv",
"(",
"args",
")",
"{",
"var",
"out",
"=",
"{",
"directives",
":",
"{",
"}",
"}",
",",
"i",
"=",
"0",
";",
"/* istanbul ignore next: never use process.argv in tests */",
"args",
"=",
"args",
"||",
"process",
".",
"argv",
".",
"slice",
"(",
"2",
")",
";",
"if",
"(",
"!",
"args",
".",
"length",
")",
"return",
"out",
";",
"// read conf from stdin",
"if",
"(",
"args",
"[",
"i",
"]",
"===",
"STDIN",
")",
"{",
"out",
".",
"stdin",
"=",
"true",
";",
"i",
"++",
";",
"// conf should be first arg",
"}",
"else",
"if",
"(",
"!",
"PTN",
".",
"test",
"(",
"args",
"[",
"i",
"]",
")",
")",
"{",
"out",
".",
"file",
"=",
"args",
"[",
"i",
"]",
";",
"i",
"++",
";",
"}",
"function",
"add",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"!",
"key",
"||",
"value",
"===",
"null",
")",
"return",
";",
"if",
"(",
"!",
"out",
".",
"directives",
"[",
"key",
"]",
")",
"{",
"out",
".",
"directives",
"[",
"key",
"]",
"=",
"value",
";",
"// handle repeated directives, create an array",
"}",
"else",
"if",
"(",
"out",
".",
"directives",
"[",
"key",
"]",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"out",
".",
"directives",
"[",
"key",
"]",
")",
")",
"{",
"out",
".",
"directives",
"[",
"key",
"]",
"=",
"[",
"out",
".",
"directives",
"[",
"key",
"]",
"]",
";",
"out",
".",
"directives",
"[",
"key",
"]",
".",
"push",
"(",
"value",
")",
"// append to existing array value",
"}",
"else",
"{",
"out",
".",
"directives",
"[",
"key",
"]",
".",
"push",
"(",
"value",
")",
"}",
"}",
"function",
"gobble",
"(",
"arg",
",",
"key",
",",
"value",
")",
"{",
"if",
"(",
"arg",
"===",
"undefined",
")",
"return",
"add",
"(",
"key",
",",
"value",
")",
";",
"value",
"=",
"value",
"||",
"''",
";",
"if",
"(",
"PTN",
".",
"test",
"(",
"arg",
")",
")",
"{",
"key",
"=",
"arg",
".",
"replace",
"(",
"PTN",
",",
"''",
")",
";",
"// gobble up value arguments",
"while",
"(",
"(",
"arg",
"=",
"args",
"[",
"i",
"++",
"]",
")",
"!==",
"undefined",
"&&",
"!",
"PTN",
".",
"test",
"(",
"arg",
")",
")",
"{",
"if",
"(",
"value",
")",
"value",
"+=",
"' '",
";",
"value",
"+=",
"arg",
";",
"}",
"if",
"(",
"PTN",
".",
"test",
"(",
"arg",
")",
")",
"i",
"--",
";",
"add",
"(",
"key",
",",
"value",
")",
";",
"value",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"value",
")",
"value",
"+=",
"' '",
";",
"value",
"+=",
"arg",
";",
"}",
"gobble",
"(",
"args",
"[",
"i",
"++",
"]",
",",
"key",
",",
"value",
")",
";",
"}",
"gobble",
"(",
"args",
"[",
"i",
"]",
")",
";",
"return",
"out",
";",
"}"
] | Parse arguments redis-server style. | [
"Parse",
"arguments",
"redis",
"-",
"server",
"style",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/argv.js#L7-L61 |
51,788 | redisjs/jsr-server | lib/connection.js | Connection | function Connection(socket) {
events.EventEmitter.call(this);
// underlying socket
this._socket = socket;
// flag whether this connection is paused
this._paused = false;
// external or in-process client connection
this._tcp = (this._socket instanceof Socket);
// state information
this._client = new Client(socket);
this.data = this.data.bind(this);
this._socket.once('close', this._close.bind(this));
this._socket.on('data', this.data);
// using a tcp socket connection
if(this._tcp) {
this.encoder = new Encoder({return_buffers: true})
this.encoder.on('push', onPush.bind(this));
this.encoder.pipe(this._socket);
this.decoder = new Decoder({return_buffers: true});
this.decoder.on('reply', this.decoded.bind(this));
this.decoder.on('error', this.decoded.bind(this));
function onSocketError(err) {
log.warning(err.message);
}
this._socket.on('error', onSocketError.bind(this));
}
this.onWrite = this.onWrite.bind(this);
} | javascript | function Connection(socket) {
events.EventEmitter.call(this);
// underlying socket
this._socket = socket;
// flag whether this connection is paused
this._paused = false;
// external or in-process client connection
this._tcp = (this._socket instanceof Socket);
// state information
this._client = new Client(socket);
this.data = this.data.bind(this);
this._socket.once('close', this._close.bind(this));
this._socket.on('data', this.data);
// using a tcp socket connection
if(this._tcp) {
this.encoder = new Encoder({return_buffers: true})
this.encoder.on('push', onPush.bind(this));
this.encoder.pipe(this._socket);
this.decoder = new Decoder({return_buffers: true});
this.decoder.on('reply', this.decoded.bind(this));
this.decoder.on('error', this.decoded.bind(this));
function onSocketError(err) {
log.warning(err.message);
}
this._socket.on('error', onSocketError.bind(this));
}
this.onWrite = this.onWrite.bind(this);
} | [
"function",
"Connection",
"(",
"socket",
")",
"{",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"// underlying socket",
"this",
".",
"_socket",
"=",
"socket",
";",
"// flag whether this connection is paused",
"this",
".",
"_paused",
"=",
"false",
";",
"// external or in-process client connection",
"this",
".",
"_tcp",
"=",
"(",
"this",
".",
"_socket",
"instanceof",
"Socket",
")",
";",
"// state information",
"this",
".",
"_client",
"=",
"new",
"Client",
"(",
"socket",
")",
";",
"this",
".",
"data",
"=",
"this",
".",
"data",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_socket",
".",
"once",
"(",
"'close'",
",",
"this",
".",
"_close",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"_socket",
".",
"on",
"(",
"'data'",
",",
"this",
".",
"data",
")",
";",
"// using a tcp socket connection",
"if",
"(",
"this",
".",
"_tcp",
")",
"{",
"this",
".",
"encoder",
"=",
"new",
"Encoder",
"(",
"{",
"return_buffers",
":",
"true",
"}",
")",
"this",
".",
"encoder",
".",
"on",
"(",
"'push'",
",",
"onPush",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"encoder",
".",
"pipe",
"(",
"this",
".",
"_socket",
")",
";",
"this",
".",
"decoder",
"=",
"new",
"Decoder",
"(",
"{",
"return_buffers",
":",
"true",
"}",
")",
";",
"this",
".",
"decoder",
".",
"on",
"(",
"'reply'",
",",
"this",
".",
"decoded",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"decoder",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"decoded",
".",
"bind",
"(",
"this",
")",
")",
";",
"function",
"onSocketError",
"(",
"err",
")",
"{",
"log",
".",
"warning",
"(",
"err",
".",
"message",
")",
";",
"}",
"this",
".",
"_socket",
".",
"on",
"(",
"'error'",
",",
"onSocketError",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
"this",
".",
"onWrite",
"=",
"this",
".",
"onWrite",
".",
"bind",
"(",
"this",
")",
";",
"}"
] | Encapsulates a client socket connection. | [
"Encapsulates",
"a",
"client",
"socket",
"connection",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L24-L61 |
51,789 | redisjs/jsr-server | lib/connection.js | resume | function resume() {
this._paused = false;
if(this.client._qbuf.length) {
this.data(this.client._qbuf);
this.client._qbuf = new Buffer(0);
}
} | javascript | function resume() {
this._paused = false;
if(this.client._qbuf.length) {
this.data(this.client._qbuf);
this.client._qbuf = new Buffer(0);
}
} | [
"function",
"resume",
"(",
")",
"{",
"this",
".",
"_paused",
"=",
"false",
";",
"if",
"(",
"this",
".",
"client",
".",
"_qbuf",
".",
"length",
")",
"{",
"this",
".",
"data",
"(",
"this",
".",
"client",
".",
"_qbuf",
")",
";",
"this",
".",
"client",
".",
"_qbuf",
"=",
"new",
"Buffer",
"(",
"0",
")",
";",
"}",
"}"
] | Resume this client connection and flush buffered
commands. | [
"Resume",
"this",
"client",
"connection",
"and",
"flush",
"buffered",
"commands",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L76-L82 |
51,790 | redisjs/jsr-server | lib/connection.js | onWrite | function onWrite(req) {
if(!this.transaction || !this.watched || req.conn.id === this.id) {
return false;
}
//console.dir(req.keys);
//console.dir(req.args);
var keys = req.keys || req.def.getKeys(req.args), i, key;
for(i = 0;i < keys.length;i++) {
key = '' + keys[i];
//console.error('got change with key %s', key);
//console.error('got change with value %s', value);
//console.error('got change with conn id %j', req.conn.id);
if(~this.watched.indexOf(key)) {
//console.error('setting conflict on %s', keys[i]);
//console.error('setting conflict from %s', req.conn.id);
this.transaction.conflict = true;
return true;
}
}
} | javascript | function onWrite(req) {
if(!this.transaction || !this.watched || req.conn.id === this.id) {
return false;
}
//console.dir(req.keys);
//console.dir(req.args);
var keys = req.keys || req.def.getKeys(req.args), i, key;
for(i = 0;i < keys.length;i++) {
key = '' + keys[i];
//console.error('got change with key %s', key);
//console.error('got change with value %s', value);
//console.error('got change with conn id %j', req.conn.id);
if(~this.watched.indexOf(key)) {
//console.error('setting conflict on %s', keys[i]);
//console.error('setting conflict from %s', req.conn.id);
this.transaction.conflict = true;
return true;
}
}
} | [
"function",
"onWrite",
"(",
"req",
")",
"{",
"if",
"(",
"!",
"this",
".",
"transaction",
"||",
"!",
"this",
".",
"watched",
"||",
"req",
".",
"conn",
".",
"id",
"===",
"this",
".",
"id",
")",
"{",
"return",
"false",
";",
"}",
"//console.dir(req.keys);",
"//console.dir(req.args);",
"var",
"keys",
"=",
"req",
".",
"keys",
"||",
"req",
".",
"def",
".",
"getKeys",
"(",
"req",
".",
"args",
")",
",",
"i",
",",
"key",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"key",
"=",
"''",
"+",
"keys",
"[",
"i",
"]",
";",
"//console.error('got change with key %s', key);",
"//console.error('got change with value %s', value);",
"//console.error('got change with conn id %j', req.conn.id);",
"if",
"(",
"~",
"this",
".",
"watched",
".",
"indexOf",
"(",
"key",
")",
")",
"{",
"//console.error('setting conflict on %s', keys[i]);",
"//console.error('setting conflict from %s', req.conn.id);",
"this",
".",
"transaction",
".",
"conflict",
"=",
"true",
";",
"return",
"true",
";",
"}",
"}",
"}"
] | Listener for write events emitted by the database.
Inspects the request object and if the request keys
match any keys being watched by this connection and
the request was from another connection then a conflict
if flagged on a transaction if a transaction exists. | [
"Listener",
"for",
"write",
"events",
"emitted",
"by",
"the",
"database",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L92-L113 |
51,791 | redisjs/jsr-server | lib/connection.js | watch | function watch(keys, database) {
keys = keys.map(function(k) {
if(k instanceof Buffer) return k.toString();
return k;
})
//console.dir(keys);
// watch can be called multiple times
// with the same keys, prevent listener leaks
this.unwatch(database);
database.on('write', this.onWrite);
this.watched = keys;
} | javascript | function watch(keys, database) {
keys = keys.map(function(k) {
if(k instanceof Buffer) return k.toString();
return k;
})
//console.dir(keys);
// watch can be called multiple times
// with the same keys, prevent listener leaks
this.unwatch(database);
database.on('write', this.onWrite);
this.watched = keys;
} | [
"function",
"watch",
"(",
"keys",
",",
"database",
")",
"{",
"keys",
"=",
"keys",
".",
"map",
"(",
"function",
"(",
"k",
")",
"{",
"if",
"(",
"k",
"instanceof",
"Buffer",
")",
"return",
"k",
".",
"toString",
"(",
")",
";",
"return",
"k",
";",
"}",
")",
"//console.dir(keys);",
"// watch can be called multiple times",
"// with the same keys, prevent listener leaks",
"this",
".",
"unwatch",
"(",
"database",
")",
";",
"database",
".",
"on",
"(",
"'write'",
",",
"this",
".",
"onWrite",
")",
";",
"this",
".",
"watched",
"=",
"keys",
";",
"}"
] | Watch an array of keys. | [
"Watch",
"an",
"array",
"of",
"keys",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L118-L133 |
51,792 | redisjs/jsr-server | lib/connection.js | data | function data(buf) {
if(this._tcp) {
if(this._paused) {
this.client._qbuf = Buffer.concat(
[this.client._qbuf, buf], this.client._qbuf.length + buf.length);
return false;
}
this.emit('input', buf.length);
this._process(buf);
}else{
// TODO: handle pausing internal connections!
// not actually a buffer for internal sockets
// rather the raw request itself, ie: array with command
// and arguments
this.decoded(null, buf);
}
} | javascript | function data(buf) {
if(this._tcp) {
if(this._paused) {
this.client._qbuf = Buffer.concat(
[this.client._qbuf, buf], this.client._qbuf.length + buf.length);
return false;
}
this.emit('input', buf.length);
this._process(buf);
}else{
// TODO: handle pausing internal connections!
// not actually a buffer for internal sockets
// rather the raw request itself, ie: array with command
// and arguments
this.decoded(null, buf);
}
} | [
"function",
"data",
"(",
"buf",
")",
"{",
"if",
"(",
"this",
".",
"_tcp",
")",
"{",
"if",
"(",
"this",
".",
"_paused",
")",
"{",
"this",
".",
"client",
".",
"_qbuf",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"this",
".",
"client",
".",
"_qbuf",
",",
"buf",
"]",
",",
"this",
".",
"client",
".",
"_qbuf",
".",
"length",
"+",
"buf",
".",
"length",
")",
";",
"return",
"false",
";",
"}",
"this",
".",
"emit",
"(",
"'input'",
",",
"buf",
".",
"length",
")",
";",
"this",
".",
"_process",
"(",
"buf",
")",
";",
"}",
"else",
"{",
"// TODO: handle pausing internal connections!",
"// not actually a buffer for internal sockets",
"// rather the raw request itself, ie: array with command",
"// and arguments",
"this",
".",
"decoded",
"(",
"null",
",",
"buf",
")",
";",
"}",
"}"
] | Read incoming data on the socket connection.
@param buf The incoming buffer or internal request
array. | [
"Read",
"incoming",
"data",
"on",
"the",
"socket",
"connection",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L149-L166 |
51,793 | redisjs/jsr-server | lib/connection.js | monitor | function monitor(server) {
// cannot receive data anymore we just send it
this.removeAllListeners('data');
var listener = this.request.bind(this);
// keep track of the monitor listeners
// for clean up
server._monitor[this.id] = listener;
// flag on the client for client list flags
this._client.monitor = true;
server.on('monitor', listener);
} | javascript | function monitor(server) {
// cannot receive data anymore we just send it
this.removeAllListeners('data');
var listener = this.request.bind(this);
// keep track of the monitor listeners
// for clean up
server._monitor[this.id] = listener;
// flag on the client for client list flags
this._client.monitor = true;
server.on('monitor', listener);
} | [
"function",
"monitor",
"(",
"server",
")",
"{",
"// cannot receive data anymore we just send it",
"this",
".",
"removeAllListeners",
"(",
"'data'",
")",
";",
"var",
"listener",
"=",
"this",
".",
"request",
".",
"bind",
"(",
"this",
")",
";",
"// keep track of the monitor listeners",
"// for clean up",
"server",
".",
"_monitor",
"[",
"this",
".",
"id",
"]",
"=",
"listener",
";",
"// flag on the client for client list flags",
"this",
".",
"_client",
".",
"monitor",
"=",
"true",
";",
"server",
".",
"on",
"(",
"'monitor'",
",",
"listener",
")",
";",
"}"
] | Send this client into a monitor state. | [
"Send",
"this",
"client",
"into",
"a",
"monitor",
"state",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L171-L185 |
51,794 | redisjs/jsr-server | lib/connection.js | decoded | function decoded(err, reply) {
//console.error('got decoder err %s', err );
//console.error('got decoder reply %j',reply );
var res = new Response(this), req, cmd, args;
if(err) {
// return decoder errors to the client
return res.send(err);
}
// we should only be handling array request types
if(!Array.isArray(reply)) {
return res.send(new Error('bad request, array expected'));
}else if(!reply.length) {
return res.send(new Error('bad request, empty array invalid'));
}
cmd = reply.shift();
if(cmd instanceof Buffer) cmd = cmd.toString();
if(typeof cmd !== 'string') {
return res.send(new Error('bad request, string command expected'));
}
cmd = cmd.toLowerCase();
// keep track of last command
this._client.cmd = cmd;
//console.error('got decoder cmd %s', cmd );
//console.error('got decoder args %j', reply );
req = new Request(this, cmd, reply);
this.emit('command', req, res);
} | javascript | function decoded(err, reply) {
//console.error('got decoder err %s', err );
//console.error('got decoder reply %j',reply );
var res = new Response(this), req, cmd, args;
if(err) {
// return decoder errors to the client
return res.send(err);
}
// we should only be handling array request types
if(!Array.isArray(reply)) {
return res.send(new Error('bad request, array expected'));
}else if(!reply.length) {
return res.send(new Error('bad request, empty array invalid'));
}
cmd = reply.shift();
if(cmd instanceof Buffer) cmd = cmd.toString();
if(typeof cmd !== 'string') {
return res.send(new Error('bad request, string command expected'));
}
cmd = cmd.toLowerCase();
// keep track of last command
this._client.cmd = cmd;
//console.error('got decoder cmd %s', cmd );
//console.error('got decoder args %j', reply );
req = new Request(this, cmd, reply);
this.emit('command', req, res);
} | [
"function",
"decoded",
"(",
"err",
",",
"reply",
")",
"{",
"//console.error('got decoder err %s', err );",
"//console.error('got decoder reply %j',reply );",
"var",
"res",
"=",
"new",
"Response",
"(",
"this",
")",
",",
"req",
",",
"cmd",
",",
"args",
";",
"if",
"(",
"err",
")",
"{",
"// return decoder errors to the client",
"return",
"res",
".",
"send",
"(",
"err",
")",
";",
"}",
"// we should only be handling array request types",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"reply",
")",
")",
"{",
"return",
"res",
".",
"send",
"(",
"new",
"Error",
"(",
"'bad request, array expected'",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"reply",
".",
"length",
")",
"{",
"return",
"res",
".",
"send",
"(",
"new",
"Error",
"(",
"'bad request, empty array invalid'",
")",
")",
";",
"}",
"cmd",
"=",
"reply",
".",
"shift",
"(",
")",
";",
"if",
"(",
"cmd",
"instanceof",
"Buffer",
")",
"cmd",
"=",
"cmd",
".",
"toString",
"(",
")",
";",
"if",
"(",
"typeof",
"cmd",
"!==",
"'string'",
")",
"{",
"return",
"res",
".",
"send",
"(",
"new",
"Error",
"(",
"'bad request, string command expected'",
")",
")",
";",
"}",
"cmd",
"=",
"cmd",
".",
"toLowerCase",
"(",
")",
";",
"// keep track of last command",
"this",
".",
"_client",
".",
"cmd",
"=",
"cmd",
";",
"//console.error('got decoder cmd %s', cmd );",
"//console.error('got decoder args %j', reply );",
"req",
"=",
"new",
"Request",
"(",
"this",
",",
"cmd",
",",
"reply",
")",
";",
"this",
".",
"emit",
"(",
"'command'",
",",
"req",
",",
"res",
")",
";",
"}"
] | Handle an incoming decoded RESP message. | [
"Handle",
"an",
"incoming",
"decoded",
"RESP",
"message",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L198-L233 |
51,795 | redisjs/jsr-server | lib/connection.js | _process | function _process(buf) {
var b = buf[0], cli, cmd, req, res;
//console.dir('' + buf);
// does it look like a RESP message
if(b === STR
|| b === ERR
|| b === INT
|| b === BST
|| b === ARR
// already buffered some data, chunked request
|| (this.decoder.isBuffered())) {
//console.dir('writing buffer to decoder..');
this.decoder.write(buf);
}else{
try {
cli = itr.interpret(buf.toString());
}catch(e) {
// ignore empty command strings
return;
}
cmd = (cli.shift() + '').toLowerCase();
req = new Request(this, cmd, cli);
res = new Response(this);
this.emit('command', req, res);
}
} | javascript | function _process(buf) {
var b = buf[0], cli, cmd, req, res;
//console.dir('' + buf);
// does it look like a RESP message
if(b === STR
|| b === ERR
|| b === INT
|| b === BST
|| b === ARR
// already buffered some data, chunked request
|| (this.decoder.isBuffered())) {
//console.dir('writing buffer to decoder..');
this.decoder.write(buf);
}else{
try {
cli = itr.interpret(buf.toString());
}catch(e) {
// ignore empty command strings
return;
}
cmd = (cli.shift() + '').toLowerCase();
req = new Request(this, cmd, cli);
res = new Response(this);
this.emit('command', req, res);
}
} | [
"function",
"_process",
"(",
"buf",
")",
"{",
"var",
"b",
"=",
"buf",
"[",
"0",
"]",
",",
"cli",
",",
"cmd",
",",
"req",
",",
"res",
";",
"//console.dir('' + buf);",
"// does it look like a RESP message",
"if",
"(",
"b",
"===",
"STR",
"||",
"b",
"===",
"ERR",
"||",
"b",
"===",
"INT",
"||",
"b",
"===",
"BST",
"||",
"b",
"===",
"ARR",
"// already buffered some data, chunked request",
"||",
"(",
"this",
".",
"decoder",
".",
"isBuffered",
"(",
")",
")",
")",
"{",
"//console.dir('writing buffer to decoder..');",
"this",
".",
"decoder",
".",
"write",
"(",
"buf",
")",
";",
"}",
"else",
"{",
"try",
"{",
"cli",
"=",
"itr",
".",
"interpret",
"(",
"buf",
".",
"toString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// ignore empty command strings",
"return",
";",
"}",
"cmd",
"=",
"(",
"cli",
".",
"shift",
"(",
")",
"+",
"''",
")",
".",
"toLowerCase",
"(",
")",
";",
"req",
"=",
"new",
"Request",
"(",
"this",
",",
"cmd",
",",
"cli",
")",
";",
"res",
"=",
"new",
"Response",
"(",
"this",
")",
";",
"this",
".",
"emit",
"(",
"'command'",
",",
"req",
",",
"res",
")",
";",
"}",
"}"
] | Process incoming data and respond accordingly.
@param buf The incoming buffer. | [
"Process",
"incoming",
"data",
"and",
"respond",
"accordingly",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L240-L267 |
51,796 | redisjs/jsr-server | lib/connection.js | end | function end(cb) {
if(typeof cb === 'function') {
this.once('disconnect', cb);
}
if(this.tcp) {
// must call destroy to terminate immediately
this._socket.destroy();
}else{
this._socket.end();
}
} | javascript | function end(cb) {
if(typeof cb === 'function') {
this.once('disconnect', cb);
}
if(this.tcp) {
// must call destroy to terminate immediately
this._socket.destroy();
}else{
this._socket.end();
}
} | [
"function",
"end",
"(",
"cb",
")",
"{",
"if",
"(",
"typeof",
"cb",
"===",
"'function'",
")",
"{",
"this",
".",
"once",
"(",
"'disconnect'",
",",
"cb",
")",
";",
"}",
"if",
"(",
"this",
".",
"tcp",
")",
"{",
"// must call destroy to terminate immediately",
"this",
".",
"_socket",
".",
"destroy",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"_socket",
".",
"end",
"(",
")",
";",
"}",
"}"
] | Proxy end to the underlying socket. | [
"Proxy",
"end",
"to",
"the",
"underlying",
"socket",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L272-L283 |
51,797 | redisjs/jsr-server | lib/connection.js | write | function write(data, cb) {
if(this._tcp) {
//this.emit('output', data);
this.encoder.write(data, cb);
}else{
this._socket.write.call(this._socket, data, cb);
}
} | javascript | function write(data, cb) {
if(this._tcp) {
//this.emit('output', data);
this.encoder.write(data, cb);
}else{
this._socket.write.call(this._socket, data, cb);
}
} | [
"function",
"write",
"(",
"data",
",",
"cb",
")",
"{",
"if",
"(",
"this",
".",
"_tcp",
")",
"{",
"//this.emit('output', data);",
"this",
".",
"encoder",
".",
"write",
"(",
"data",
",",
"cb",
")",
";",
"}",
"else",
"{",
"this",
".",
"_socket",
".",
"write",
".",
"call",
"(",
"this",
".",
"_socket",
",",
"data",
",",
"cb",
")",
";",
"}",
"}"
] | Proxy write to the underlying socket. | [
"Proxy",
"write",
"to",
"the",
"underlying",
"socket",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/connection.js#L297-L304 |
51,798 | 0of/ver-iterator | lib/npm.js | publishedVers | function publishedVers(name) {
var _child$spawnSync = _child_process2['default'].spawnSync(npmCommand, ['view', name, 'versions', '--json']);
var stdout = _child$spawnSync.stdout;
var error = _child$spawnSync.error;
if (error) throw error;
return JSON.parse(stdout.toString());
} | javascript | function publishedVers(name) {
var _child$spawnSync = _child_process2['default'].spawnSync(npmCommand, ['view', name, 'versions', '--json']);
var stdout = _child$spawnSync.stdout;
var error = _child$spawnSync.error;
if (error) throw error;
return JSON.parse(stdout.toString());
} | [
"function",
"publishedVers",
"(",
"name",
")",
"{",
"var",
"_child$spawnSync",
"=",
"_child_process2",
"[",
"'default'",
"]",
".",
"spawnSync",
"(",
"npmCommand",
",",
"[",
"'view'",
",",
"name",
",",
"'versions'",
",",
"'--json'",
"]",
")",
";",
"var",
"stdout",
"=",
"_child$spawnSync",
".",
"stdout",
";",
"var",
"error",
"=",
"_child$spawnSync",
".",
"error",
";",
"if",
"(",
"error",
")",
"throw",
"error",
";",
"return",
"JSON",
".",
"parse",
"(",
"stdout",
".",
"toString",
"(",
")",
")",
";",
"}"
] | get published versions via npm
@param {String} [name] published package name
@return {Array} versions
@public | [
"get",
"published",
"versions",
"via",
"npm"
] | a51726c02dfd14488190860f4d90903574ed8e37 | https://github.com/0of/ver-iterator/blob/a51726c02dfd14488190860f4d90903574ed8e37/lib/npm.js#L23-L32 |
51,799 | 0of/ver-iterator | lib/npm.js | installVer | function installVer(name, ver, dir) {
var _child$spawnSync2 = _child_process2['default'].spawnSync(npmCommand, ['install', name + '@' + ver], { cwd: dir });
var error = _child$spawnSync2.error;
if (error) throw error;
} | javascript | function installVer(name, ver, dir) {
var _child$spawnSync2 = _child_process2['default'].spawnSync(npmCommand, ['install', name + '@' + ver], { cwd: dir });
var error = _child$spawnSync2.error;
if (error) throw error;
} | [
"function",
"installVer",
"(",
"name",
",",
"ver",
",",
"dir",
")",
"{",
"var",
"_child$spawnSync2",
"=",
"_child_process2",
"[",
"'default'",
"]",
".",
"spawnSync",
"(",
"npmCommand",
",",
"[",
"'install'",
",",
"name",
"+",
"'@'",
"+",
"ver",
"]",
",",
"{",
"cwd",
":",
"dir",
"}",
")",
";",
"var",
"error",
"=",
"_child$spawnSync2",
".",
"error",
";",
"if",
"(",
"error",
")",
"throw",
"error",
";",
"}"
] | install package via npm
@param {String} [name] published package name
@param {String} [ver] install version
@param {String} [dir] install directory
@public | [
"install",
"package",
"via",
"npm"
] | a51726c02dfd14488190860f4d90903574ed8e37 | https://github.com/0of/ver-iterator/blob/a51726c02dfd14488190860f4d90903574ed8e37/lib/npm.js#L42-L48 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.