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
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
44,400 | rbackhouse/mpdjs | cordova/mpdjs/jsbuild/r.js | appendToFileContents | function appendToFileContents(fileContents, singleContents, path, config, module, sourceMapGenerator) {
var refPath, sourceMapPath, resourcePath, pluginId, sourceMapLineNumber, lineCount, parts, i;
if (sourceMapGenerator) {
if (config.out) {
refPath = config.baseUrl;
} else if (module && module._buildPath) {
refPath = module._buildPath;
} else {
refPath = "";
}
parts = path.split('!');
if (parts.length === 1) {
//Not a plugin resource, fix the path
sourceMapPath = build.makeRelativeFilePath(refPath, path);
} else {
//Plugin resource. If it looks like just a plugin
//followed by a module ID, pull off the plugin
//and put it at the end of the name, otherwise
//just leave it alone.
pluginId = parts.shift();
resourcePath = parts.join('!');
if (resourceIsModuleIdRegExp.test(resourcePath)) {
sourceMapPath = build.makeRelativeFilePath(refPath, require.toUrl(resourcePath)) +
'!' + pluginId;
} else {
sourceMapPath = path;
}
}
sourceMapLineNumber = fileContents.split('\n').length - 1;
lineCount = singleContents.split('\n').length;
for (i = 1; i <= lineCount; i += 1) {
sourceMapGenerator.addMapping({
generated: {
line: sourceMapLineNumber + i,
column: 0
},
original: {
line: i,
column: 0
},
source: sourceMapPath
});
}
//Store the content of the original in the source
//map since other transforms later like minification
//can mess up translating back to the original
//source.
sourceMapGenerator.setSourceContent(sourceMapPath, singleContents);
}
fileContents += singleContents;
return fileContents;
} | javascript | function appendToFileContents(fileContents, singleContents, path, config, module, sourceMapGenerator) {
var refPath, sourceMapPath, resourcePath, pluginId, sourceMapLineNumber, lineCount, parts, i;
if (sourceMapGenerator) {
if (config.out) {
refPath = config.baseUrl;
} else if (module && module._buildPath) {
refPath = module._buildPath;
} else {
refPath = "";
}
parts = path.split('!');
if (parts.length === 1) {
//Not a plugin resource, fix the path
sourceMapPath = build.makeRelativeFilePath(refPath, path);
} else {
//Plugin resource. If it looks like just a plugin
//followed by a module ID, pull off the plugin
//and put it at the end of the name, otherwise
//just leave it alone.
pluginId = parts.shift();
resourcePath = parts.join('!');
if (resourceIsModuleIdRegExp.test(resourcePath)) {
sourceMapPath = build.makeRelativeFilePath(refPath, require.toUrl(resourcePath)) +
'!' + pluginId;
} else {
sourceMapPath = path;
}
}
sourceMapLineNumber = fileContents.split('\n').length - 1;
lineCount = singleContents.split('\n').length;
for (i = 1; i <= lineCount; i += 1) {
sourceMapGenerator.addMapping({
generated: {
line: sourceMapLineNumber + i,
column: 0
},
original: {
line: i,
column: 0
},
source: sourceMapPath
});
}
//Store the content of the original in the source
//map since other transforms later like minification
//can mess up translating back to the original
//source.
sourceMapGenerator.setSourceContent(sourceMapPath, singleContents);
}
fileContents += singleContents;
return fileContents;
} | [
"function",
"appendToFileContents",
"(",
"fileContents",
",",
"singleContents",
",",
"path",
",",
"config",
",",
"module",
",",
"sourceMapGenerator",
")",
"{",
"var",
"refPath",
",",
"sourceMapPath",
",",
"resourcePath",
",",
"pluginId",
",",
"sourceMapLineNumber",
",",
"lineCount",
",",
"parts",
",",
"i",
";",
"if",
"(",
"sourceMapGenerator",
")",
"{",
"if",
"(",
"config",
".",
"out",
")",
"{",
"refPath",
"=",
"config",
".",
"baseUrl",
";",
"}",
"else",
"if",
"(",
"module",
"&&",
"module",
".",
"_buildPath",
")",
"{",
"refPath",
"=",
"module",
".",
"_buildPath",
";",
"}",
"else",
"{",
"refPath",
"=",
"\"\"",
";",
"}",
"parts",
"=",
"path",
".",
"split",
"(",
"'!'",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"1",
")",
"{",
"//Not a plugin resource, fix the path",
"sourceMapPath",
"=",
"build",
".",
"makeRelativeFilePath",
"(",
"refPath",
",",
"path",
")",
";",
"}",
"else",
"{",
"//Plugin resource. If it looks like just a plugin",
"//followed by a module ID, pull off the plugin",
"//and put it at the end of the name, otherwise",
"//just leave it alone.",
"pluginId",
"=",
"parts",
".",
"shift",
"(",
")",
";",
"resourcePath",
"=",
"parts",
".",
"join",
"(",
"'!'",
")",
";",
"if",
"(",
"resourceIsModuleIdRegExp",
".",
"test",
"(",
"resourcePath",
")",
")",
"{",
"sourceMapPath",
"=",
"build",
".",
"makeRelativeFilePath",
"(",
"refPath",
",",
"require",
".",
"toUrl",
"(",
"resourcePath",
")",
")",
"+",
"'!'",
"+",
"pluginId",
";",
"}",
"else",
"{",
"sourceMapPath",
"=",
"path",
";",
"}",
"}",
"sourceMapLineNumber",
"=",
"fileContents",
".",
"split",
"(",
"'\\n'",
")",
".",
"length",
"-",
"1",
";",
"lineCount",
"=",
"singleContents",
".",
"split",
"(",
"'\\n'",
")",
".",
"length",
";",
"for",
"(",
"i",
"=",
"1",
";",
"i",
"<=",
"lineCount",
";",
"i",
"+=",
"1",
")",
"{",
"sourceMapGenerator",
".",
"addMapping",
"(",
"{",
"generated",
":",
"{",
"line",
":",
"sourceMapLineNumber",
"+",
"i",
",",
"column",
":",
"0",
"}",
",",
"original",
":",
"{",
"line",
":",
"i",
",",
"column",
":",
"0",
"}",
",",
"source",
":",
"sourceMapPath",
"}",
")",
";",
"}",
"//Store the content of the original in the source",
"//map since other transforms later like minification",
"//can mess up translating back to the original",
"//source.",
"sourceMapGenerator",
".",
"setSourceContent",
"(",
"sourceMapPath",
",",
"singleContents",
")",
";",
"}",
"fileContents",
"+=",
"singleContents",
";",
"return",
"fileContents",
";",
"}"
]
| Appends singleContents to fileContents and returns the result. If a sourceMapGenerator
is provided, adds singleContents to the source map.
@param {string} fileContents - The file contents to which to append singleContents
@param {string} singleContents - The additional contents to append to fileContents
@param {string} path - An absolute path of a file whose name to use in the source map.
The file need not actually exist if the code in singleContents is generated.
@param {{out: ?string, baseUrl: ?string}} config - The build configuration object.
@param {?{_buildPath: ?string}} module - An object with module information.
@param {?SourceMapGenerator} sourceMapGenerator - An instance of Mozilla's SourceMapGenerator,
or null if no source map is being generated.
@returns {string} fileContents with singleContents appended | [
"Appends",
"singleContents",
"to",
"fileContents",
"and",
"returns",
"the",
"result",
".",
"If",
"a",
"sourceMapGenerator",
"is",
"provided",
"adds",
"singleContents",
"to",
"the",
"source",
"map",
"."
]
| 23fde33a7a24ba8d516c623643e359a25a46259c | https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L28181-L28234 |
44,401 | swordf1zh/mattermoster | app.js | onError | function onError(error) {
if (error.syscall !== 'listen') throw error;
const bind = (typeof port === 'string')
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
} | javascript | function onError(error) {
if (error.syscall !== 'listen') throw error;
const bind = (typeof port === 'string')
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
} | [
"function",
"onError",
"(",
"error",
")",
"{",
"if",
"(",
"error",
".",
"syscall",
"!==",
"'listen'",
")",
"throw",
"error",
";",
"const",
"bind",
"=",
"(",
"typeof",
"port",
"===",
"'string'",
")",
"?",
"'Pipe '",
"+",
"port",
":",
"'Port '",
"+",
"port",
";",
"// handle specific listen errors with friendly messages",
"switch",
"(",
"error",
".",
"code",
")",
"{",
"case",
"'EACCES'",
":",
"console",
".",
"error",
"(",
"bind",
"+",
"' requires elevated privileges'",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"break",
";",
"case",
"'EADDRINUSE'",
":",
"console",
".",
"error",
"(",
"bind",
"+",
"' is already in use'",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"break",
";",
"default",
":",
"throw",
"error",
";",
"}",
"}"
]
| Event listener for HTTP server "error" event. | [
"Event",
"listener",
"for",
"HTTP",
"server",
"error",
"event",
"."
]
| 10e6c37c80eb023ab8ab044c46445a78a18053e7 | https://github.com/swordf1zh/mattermoster/blob/10e6c37c80eb023ab8ab044c46445a78a18053e7/app.js#L119-L141 |
44,402 | KanoComputing/js-api-resource | lib/util.js | addMultipartData | function addMultipartData (formData, data) {
var key, arr, i;
for (key in data) {
if (data.hasOwnProperty(key) && key !== 'files') {
if (data[key] instanceof Array) {
arr = data[key];
for (i = 0; i < arr.length; i += 1) {
formData.append(key + '[' + i + ']', exports.stringifyIfObject(arr[i]));
}
} else {
formData.append(key, exports.stringifyIfObject(data[key]));
}
}
}
} | javascript | function addMultipartData (formData, data) {
var key, arr, i;
for (key in data) {
if (data.hasOwnProperty(key) && key !== 'files') {
if (data[key] instanceof Array) {
arr = data[key];
for (i = 0; i < arr.length; i += 1) {
formData.append(key + '[' + i + ']', exports.stringifyIfObject(arr[i]));
}
} else {
formData.append(key, exports.stringifyIfObject(data[key]));
}
}
}
} | [
"function",
"addMultipartData",
"(",
"formData",
",",
"data",
")",
"{",
"var",
"key",
",",
"arr",
",",
"i",
";",
"for",
"(",
"key",
"in",
"data",
")",
"{",
"if",
"(",
"data",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"key",
"!==",
"'files'",
")",
"{",
"if",
"(",
"data",
"[",
"key",
"]",
"instanceof",
"Array",
")",
"{",
"arr",
"=",
"data",
"[",
"key",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"formData",
".",
"append",
"(",
"key",
"+",
"'['",
"+",
"i",
"+",
"']'",
",",
"exports",
".",
"stringifyIfObject",
"(",
"arr",
"[",
"i",
"]",
")",
")",
";",
"}",
"}",
"else",
"{",
"formData",
".",
"append",
"(",
"key",
",",
"exports",
".",
"stringifyIfObject",
"(",
"data",
"[",
"key",
"]",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Helper used by `formRequestPayload` to append data to FormData instance | [
"Helper",
"used",
"by",
"formRequestPayload",
"to",
"append",
"data",
"to",
"FormData",
"instance"
]
| 9f8e5a5a07402411ab2a8bbb91d7d8c094b8d9c5 | https://github.com/KanoComputing/js-api-resource/blob/9f8e5a5a07402411ab2a8bbb91d7d8c094b8d9c5/lib/util.js#L46-L62 |
44,403 | KanoComputing/js-api-resource | lib/util.js | addFiles | function addFiles (formData, files) {
var file, arr, key, i = 0, filename;
for (key in files) {
if (files.hasOwnProperty(key) && files[key]) {
if (files[key] instanceof Array) {
arr = files[key];
filename = getFilename(arr[i]) || null;
for (i = 0; i < arr.length; i += 1) {
formData.append(key + '[' + i + ']', arr[i]);
}
} else {
file = files[key];
filename = getFilename(file) || null;
formData.append(key, file, filename);
}
}
}
} | javascript | function addFiles (formData, files) {
var file, arr, key, i = 0, filename;
for (key in files) {
if (files.hasOwnProperty(key) && files[key]) {
if (files[key] instanceof Array) {
arr = files[key];
filename = getFilename(arr[i]) || null;
for (i = 0; i < arr.length; i += 1) {
formData.append(key + '[' + i + ']', arr[i]);
}
} else {
file = files[key];
filename = getFilename(file) || null;
formData.append(key, file, filename);
}
}
}
} | [
"function",
"addFiles",
"(",
"formData",
",",
"files",
")",
"{",
"var",
"file",
",",
"arr",
",",
"key",
",",
"i",
"=",
"0",
",",
"filename",
";",
"for",
"(",
"key",
"in",
"files",
")",
"{",
"if",
"(",
"files",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"files",
"[",
"key",
"]",
")",
"{",
"if",
"(",
"files",
"[",
"key",
"]",
"instanceof",
"Array",
")",
"{",
"arr",
"=",
"files",
"[",
"key",
"]",
";",
"filename",
"=",
"getFilename",
"(",
"arr",
"[",
"i",
"]",
")",
"||",
"null",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"arr",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"formData",
".",
"append",
"(",
"key",
"+",
"'['",
"+",
"i",
"+",
"']'",
",",
"arr",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"file",
"=",
"files",
"[",
"key",
"]",
";",
"filename",
"=",
"getFilename",
"(",
"file",
")",
"||",
"null",
";",
"formData",
".",
"append",
"(",
"key",
",",
"file",
",",
"filename",
")",
";",
"}",
"}",
"}",
"}"
]
| Helper used by `formRequestPayload` to append files to a FormData instance | [
"Helper",
"used",
"by",
"formRequestPayload",
"to",
"append",
"files",
"to",
"a",
"FormData",
"instance"
]
| 9f8e5a5a07402411ab2a8bbb91d7d8c094b8d9c5 | https://github.com/KanoComputing/js-api-resource/blob/9f8e5a5a07402411ab2a8bbb91d7d8c094b8d9c5/lib/util.js#L66-L86 |
44,404 | bigeasy/swimlane | src/swimlane.js | wrap | function wrap (factory, node, tag) {
// If there is a previous node that is not text, insert a new line to
// for
if (node.previousSibling != null && node.previousSibling.nodeType != 3) {
var newline = factory.createTextNode("\n");
body.insertBefore(newline, node);
}
var wrapper = factory.createElement(tag);
node.parentNode.insertBefore(wrapper, node);
wrapper.appendChild(node);
return wrapper;
} | javascript | function wrap (factory, node, tag) {
// If there is a previous node that is not text, insert a new line to
// for
if (node.previousSibling != null && node.previousSibling.nodeType != 3) {
var newline = factory.createTextNode("\n");
body.insertBefore(newline, node);
}
var wrapper = factory.createElement(tag);
node.parentNode.insertBefore(wrapper, node);
wrapper.appendChild(node);
return wrapper;
} | [
"function",
"wrap",
"(",
"factory",
",",
"node",
",",
"tag",
")",
"{",
"// If there is a previous node that is not text, insert a new line to",
"// for ",
"if",
"(",
"node",
".",
"previousSibling",
"!=",
"null",
"&&",
"node",
".",
"previousSibling",
".",
"nodeType",
"!=",
"3",
")",
"{",
"var",
"newline",
"=",
"factory",
".",
"createTextNode",
"(",
"\"\\n\"",
")",
";",
"body",
".",
"insertBefore",
"(",
"newline",
",",
"node",
")",
";",
"}",
"var",
"wrapper",
"=",
"factory",
".",
"createElement",
"(",
"tag",
")",
";",
"node",
".",
"parentNode",
".",
"insertBefore",
"(",
"wrapper",
",",
"node",
")",
";",
"wrapper",
".",
"appendChild",
"(",
"node",
")",
";",
"return",
"wrapper",
";",
"}"
]
| Wraps the given node in a new element with the given tag created using the given factory. | [
"Wraps",
"the",
"given",
"node",
"in",
"a",
"new",
"element",
"with",
"the",
"given",
"tag",
"created",
"using",
"the",
"given",
"factory",
"."
]
| 9e4baffa21761248b7c1a902d6a4a65fca02b3e1 | https://github.com/bigeasy/swimlane/blob/9e4baffa21761248b7c1a902d6a4a65fca02b3e1/src/swimlane.js#L615-L626 |
44,405 | bigeasy/swimlane | src/swimlane.js | text | function text (factory, node, cursor) {
// Process a text node.
var parentNode = node.parentNode;
// If the node is CDATA convert it to text.
if (node.nodeType == 4) {
var text = factory.createTextNode(node.data);
parentNode.insertBefore(text, node);
parentNode.removeChild(node);
node = text;
}
var prev = node.previousSibling;
if (node.nodeType == 3) {
// Combine adjacent text nodes. You'll notice that this means that we
// might be reaching outside the range givne to us to normalize. That is
// if fine. The boundary is guidance to save time, not a firewall.
if (prev != null && prev.nodeType == 3) {
var text = factory.createTextNode(prev.data + node.data);
if (prev == cursor.node) {
cursor.node = text;
}
parentNode.insertBefore(text, prev);
parentNode.removeChild(prev);
parentNode.removeChild(node);
node = text;
}
// Remove duplicate whitespace.
if (/\s\s/.test(node.data)) {
var text = factory.createTextNode(node.data.replace(/\s\s+/g, " "));
parentNode.insertBefore(text, node);
parentNode.removeChild(node);
node = text;
}
}
return node;
} | javascript | function text (factory, node, cursor) {
// Process a text node.
var parentNode = node.parentNode;
// If the node is CDATA convert it to text.
if (node.nodeType == 4) {
var text = factory.createTextNode(node.data);
parentNode.insertBefore(text, node);
parentNode.removeChild(node);
node = text;
}
var prev = node.previousSibling;
if (node.nodeType == 3) {
// Combine adjacent text nodes. You'll notice that this means that we
// might be reaching outside the range givne to us to normalize. That is
// if fine. The boundary is guidance to save time, not a firewall.
if (prev != null && prev.nodeType == 3) {
var text = factory.createTextNode(prev.data + node.data);
if (prev == cursor.node) {
cursor.node = text;
}
parentNode.insertBefore(text, prev);
parentNode.removeChild(prev);
parentNode.removeChild(node);
node = text;
}
// Remove duplicate whitespace.
if (/\s\s/.test(node.data)) {
var text = factory.createTextNode(node.data.replace(/\s\s+/g, " "));
parentNode.insertBefore(text, node);
parentNode.removeChild(node);
node = text;
}
}
return node;
} | [
"function",
"text",
"(",
"factory",
",",
"node",
",",
"cursor",
")",
"{",
"// Process a text node. ",
"var",
"parentNode",
"=",
"node",
".",
"parentNode",
";",
"// If the node is CDATA convert it to text.",
"if",
"(",
"node",
".",
"nodeType",
"==",
"4",
")",
"{",
"var",
"text",
"=",
"factory",
".",
"createTextNode",
"(",
"node",
".",
"data",
")",
";",
"parentNode",
".",
"insertBefore",
"(",
"text",
",",
"node",
")",
";",
"parentNode",
".",
"removeChild",
"(",
"node",
")",
";",
"node",
"=",
"text",
";",
"}",
"var",
"prev",
"=",
"node",
".",
"previousSibling",
";",
"if",
"(",
"node",
".",
"nodeType",
"==",
"3",
")",
"{",
"// Combine adjacent text nodes. You'll notice that this means that we",
"// might be reaching outside the range givne to us to normalize. That is",
"// if fine. The boundary is guidance to save time, not a firewall.",
"if",
"(",
"prev",
"!=",
"null",
"&&",
"prev",
".",
"nodeType",
"==",
"3",
")",
"{",
"var",
"text",
"=",
"factory",
".",
"createTextNode",
"(",
"prev",
".",
"data",
"+",
"node",
".",
"data",
")",
";",
"if",
"(",
"prev",
"==",
"cursor",
".",
"node",
")",
"{",
"cursor",
".",
"node",
"=",
"text",
";",
"}",
"parentNode",
".",
"insertBefore",
"(",
"text",
",",
"prev",
")",
";",
"parentNode",
".",
"removeChild",
"(",
"prev",
")",
";",
"parentNode",
".",
"removeChild",
"(",
"node",
")",
";",
"node",
"=",
"text",
";",
"}",
"// Remove duplicate whitespace.",
"if",
"(",
"/",
"\\s\\s",
"/",
".",
"test",
"(",
"node",
".",
"data",
")",
")",
"{",
"var",
"text",
"=",
"factory",
".",
"createTextNode",
"(",
"node",
".",
"data",
".",
"replace",
"(",
"/",
"\\s\\s+",
"/",
"g",
",",
"\" \"",
")",
")",
";",
"parentNode",
".",
"insertBefore",
"(",
"text",
",",
"node",
")",
";",
"parentNode",
".",
"removeChild",
"(",
"node",
")",
";",
"node",
"=",
"text",
";",
"}",
"}",
"return",
"node",
";",
"}"
]
| Called for each node, this method will normalize the node if it is a text element, but if it is not a text element nothing is done. | [
"Called",
"for",
"each",
"node",
"this",
"method",
"will",
"normalize",
"the",
"node",
"if",
"it",
"is",
"a",
"text",
"element",
"but",
"if",
"it",
"is",
"not",
"a",
"text",
"element",
"nothing",
"is",
"done",
"."
]
| 9e4baffa21761248b7c1a902d6a4a65fca02b3e1 | https://github.com/bigeasy/swimlane/blob/9e4baffa21761248b7c1a902d6a4a65fca02b3e1/src/swimlane.js#L689-L727 |
44,406 | hhff/spree-ember | docs/theme/assets/vendor/foundation/js/foundation.min.js | function (selector, context) {
if (typeof selector === 'string') {
if (context) {
var cont;
if (context.jquery) {
cont = context[0];
if (!cont) {
return context;
}
} else {
cont = context;
}
return $(cont.querySelectorAll(selector));
}
return $(document.querySelectorAll(selector));
}
return $(selector, context);
} | javascript | function (selector, context) {
if (typeof selector === 'string') {
if (context) {
var cont;
if (context.jquery) {
cont = context[0];
if (!cont) {
return context;
}
} else {
cont = context;
}
return $(cont.querySelectorAll(selector));
}
return $(document.querySelectorAll(selector));
}
return $(selector, context);
} | [
"function",
"(",
"selector",
",",
"context",
")",
"{",
"if",
"(",
"typeof",
"selector",
"===",
"'string'",
")",
"{",
"if",
"(",
"context",
")",
"{",
"var",
"cont",
";",
"if",
"(",
"context",
".",
"jquery",
")",
"{",
"cont",
"=",
"context",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"cont",
")",
"{",
"return",
"context",
";",
"}",
"}",
"else",
"{",
"cont",
"=",
"context",
";",
"}",
"return",
"$",
"(",
"cont",
".",
"querySelectorAll",
"(",
"selector",
")",
")",
";",
"}",
"return",
"$",
"(",
"document",
".",
"querySelectorAll",
"(",
"selector",
")",
")",
";",
"}",
"return",
"$",
"(",
"selector",
",",
"context",
")",
";",
"}"
]
| private Fast Selector wrapper, returns jQuery object. Only use where getElementById is not available. | [
"private",
"Fast",
"Selector",
"wrapper",
"returns",
"jQuery",
"object",
".",
"Only",
"use",
"where",
"getElementById",
"is",
"not",
"available",
"."
]
| 31aeaa7a3b909c6524d193beddea1267b211130f | https://github.com/hhff/spree-ember/blob/31aeaa7a3b909c6524d193beddea1267b211130f/docs/theme/assets/vendor/foundation/js/foundation.min.js#L49-L68 |
|
44,407 | hhff/spree-ember | docs/theme/assets/vendor/foundation/js/foundation.min.js | function (init) {
var arr = [];
if (!init) {
arr.push('data');
}
if (this.namespace.length > 0) {
arr.push(this.namespace);
}
arr.push(this.name);
return arr.join('-');
} | javascript | function (init) {
var arr = [];
if (!init) {
arr.push('data');
}
if (this.namespace.length > 0) {
arr.push(this.namespace);
}
arr.push(this.name);
return arr.join('-');
} | [
"function",
"(",
"init",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"init",
")",
"{",
"arr",
".",
"push",
"(",
"'data'",
")",
";",
"}",
"if",
"(",
"this",
".",
"namespace",
".",
"length",
">",
"0",
")",
"{",
"arr",
".",
"push",
"(",
"this",
".",
"namespace",
")",
";",
"}",
"arr",
".",
"push",
"(",
"this",
".",
"name",
")",
";",
"return",
"arr",
".",
"join",
"(",
"'-'",
")",
";",
"}"
]
| Namespace functions. | [
"Namespace",
"functions",
"."
]
| 31aeaa7a3b909c6524d193beddea1267b211130f | https://github.com/hhff/spree-ember/blob/31aeaa7a3b909c6524d193beddea1267b211130f/docs/theme/assets/vendor/foundation/js/foundation.min.js#L72-L83 |
|
44,408 | hhff/spree-ember | docs/theme/assets/vendor/foundation/js/foundation.min.js | function (dropdown, target, settings, position) {
var sheet = Foundation.stylesheet,
pip_offset_base = 8;
if (dropdown.hasClass(settings.mega_class)) {
pip_offset_base = position.left + (target.outerWidth() / 2) - 8;
} else if (this.small()) {
pip_offset_base += position.left - 8;
}
this.rule_idx = sheet.cssRules.length;
//default
var sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left: ' + pip_offset_base + 'px;',
css_after = 'left: ' + (pip_offset_base - 1) + 'px;';
if (position.missRight == true) {
pip_offset_base = dropdown.outerWidth() - 23;
sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left: ' + pip_offset_base + 'px;',
css_after = 'left: ' + (pip_offset_base - 1) + 'px;';
}
//just a case where right is fired, but its not missing right
if (position.triggeredRight == true) {
sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left:-12px;',
css_after = 'left:-14px;';
}
if (sheet.insertRule) {
sheet.insertRule([sel_before, '{', css_before, '}'].join(' '), this.rule_idx);
sheet.insertRule([sel_after, '{', css_after, '}'].join(' '), this.rule_idx + 1);
} else {
sheet.addRule(sel_before, css_before, this.rule_idx);
sheet.addRule(sel_after, css_after, this.rule_idx + 1);
}
} | javascript | function (dropdown, target, settings, position) {
var sheet = Foundation.stylesheet,
pip_offset_base = 8;
if (dropdown.hasClass(settings.mega_class)) {
pip_offset_base = position.left + (target.outerWidth() / 2) - 8;
} else if (this.small()) {
pip_offset_base += position.left - 8;
}
this.rule_idx = sheet.cssRules.length;
//default
var sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left: ' + pip_offset_base + 'px;',
css_after = 'left: ' + (pip_offset_base - 1) + 'px;';
if (position.missRight == true) {
pip_offset_base = dropdown.outerWidth() - 23;
sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left: ' + pip_offset_base + 'px;',
css_after = 'left: ' + (pip_offset_base - 1) + 'px;';
}
//just a case where right is fired, but its not missing right
if (position.triggeredRight == true) {
sel_before = '.f-dropdown.open:before',
sel_after = '.f-dropdown.open:after',
css_before = 'left:-12px;',
css_after = 'left:-14px;';
}
if (sheet.insertRule) {
sheet.insertRule([sel_before, '{', css_before, '}'].join(' '), this.rule_idx);
sheet.insertRule([sel_after, '{', css_after, '}'].join(' '), this.rule_idx + 1);
} else {
sheet.addRule(sel_before, css_before, this.rule_idx);
sheet.addRule(sel_after, css_after, this.rule_idx + 1);
}
} | [
"function",
"(",
"dropdown",
",",
"target",
",",
"settings",
",",
"position",
")",
"{",
"var",
"sheet",
"=",
"Foundation",
".",
"stylesheet",
",",
"pip_offset_base",
"=",
"8",
";",
"if",
"(",
"dropdown",
".",
"hasClass",
"(",
"settings",
".",
"mega_class",
")",
")",
"{",
"pip_offset_base",
"=",
"position",
".",
"left",
"+",
"(",
"target",
".",
"outerWidth",
"(",
")",
"/",
"2",
")",
"-",
"8",
";",
"}",
"else",
"if",
"(",
"this",
".",
"small",
"(",
")",
")",
"{",
"pip_offset_base",
"+=",
"position",
".",
"left",
"-",
"8",
";",
"}",
"this",
".",
"rule_idx",
"=",
"sheet",
".",
"cssRules",
".",
"length",
";",
"//default",
"var",
"sel_before",
"=",
"'.f-dropdown.open:before'",
",",
"sel_after",
"=",
"'.f-dropdown.open:after'",
",",
"css_before",
"=",
"'left: '",
"+",
"pip_offset_base",
"+",
"'px;'",
",",
"css_after",
"=",
"'left: '",
"+",
"(",
"pip_offset_base",
"-",
"1",
")",
"+",
"'px;'",
";",
"if",
"(",
"position",
".",
"missRight",
"==",
"true",
")",
"{",
"pip_offset_base",
"=",
"dropdown",
".",
"outerWidth",
"(",
")",
"-",
"23",
";",
"sel_before",
"=",
"'.f-dropdown.open:before'",
",",
"sel_after",
"=",
"'.f-dropdown.open:after'",
",",
"css_before",
"=",
"'left: '",
"+",
"pip_offset_base",
"+",
"'px;'",
",",
"css_after",
"=",
"'left: '",
"+",
"(",
"pip_offset_base",
"-",
"1",
")",
"+",
"'px;'",
";",
"}",
"//just a case where right is fired, but its not missing right",
"if",
"(",
"position",
".",
"triggeredRight",
"==",
"true",
")",
"{",
"sel_before",
"=",
"'.f-dropdown.open:before'",
",",
"sel_after",
"=",
"'.f-dropdown.open:after'",
",",
"css_before",
"=",
"'left:-12px;'",
",",
"css_after",
"=",
"'left:-14px;'",
";",
"}",
"if",
"(",
"sheet",
".",
"insertRule",
")",
"{",
"sheet",
".",
"insertRule",
"(",
"[",
"sel_before",
",",
"'{'",
",",
"css_before",
",",
"'}'",
"]",
".",
"join",
"(",
"' '",
")",
",",
"this",
".",
"rule_idx",
")",
";",
"sheet",
".",
"insertRule",
"(",
"[",
"sel_after",
",",
"'{'",
",",
"css_after",
",",
"'}'",
"]",
".",
"join",
"(",
"' '",
")",
",",
"this",
".",
"rule_idx",
"+",
"1",
")",
";",
"}",
"else",
"{",
"sheet",
".",
"addRule",
"(",
"sel_before",
",",
"css_before",
",",
"this",
".",
"rule_idx",
")",
";",
"sheet",
".",
"addRule",
"(",
"sel_after",
",",
"css_after",
",",
"this",
".",
"rule_idx",
"+",
"1",
")",
";",
"}",
"}"
]
| Insert rule to style psuedo elements | [
"Insert",
"rule",
"to",
"style",
"psuedo",
"elements"
]
| 31aeaa7a3b909c6524d193beddea1267b211130f | https://github.com/hhff/spree-ember/blob/31aeaa7a3b909c6524d193beddea1267b211130f/docs/theme/assets/vendor/foundation/js/foundation.min.js#L2355-L2396 |
|
44,409 | davidfig/pixel | pixelart.js | function (x1, y1, w, h, color, c)
{
_c = c || _c
if (color)
{
_c.fillStyle = color
}
box(x1 * _scale, y1 * _scale, w * _scale, h * _scale)
} | javascript | function (x1, y1, w, h, color, c)
{
_c = c || _c
if (color)
{
_c.fillStyle = color
}
box(x1 * _scale, y1 * _scale, w * _scale, h * _scale)
} | [
"function",
"(",
"x1",
",",
"y1",
",",
"w",
",",
"h",
",",
"color",
",",
"c",
")",
"{",
"_c",
"=",
"c",
"||",
"_c",
"if",
"(",
"color",
")",
"{",
"_c",
".",
"fillStyle",
"=",
"color",
"}",
"box",
"(",
"x1",
"*",
"_scale",
",",
"y1",
"*",
"_scale",
",",
"w",
"*",
"_scale",
",",
"h",
"*",
"_scale",
")",
"}"
]
| draw and fill rectangle
@param {number} x1 - x
@param {number} y2 - y
@param {number} radius - radius
@param {string} color
@param {CanvasRenderingContext2D} [c] | [
"draw",
"and",
"fill",
"rectangle"
]
| 2713a7922f9e7f4c008c0fc4ec398e9b1b64aace | https://github.com/davidfig/pixel/blob/2713a7922f9e7f4c008c0fc4ec398e9b1b64aace/pixelart.js#L68-L76 |
|
44,410 | davidfig/pixel | pixelart.js | function (x0, y0, radius, color, c)
{
_c = c || _c
if (color)
{
_c.fillStyle = color
}
x0 *= _scale
y0 *= _scale
radius *= _scale
let x = radius
let y = 0
let decisionOver2 = 1 - x // Decision criterion divided by 2 evaluated at x=r, y=0
while (x >= y)
{
box(-x + x0, y + y0, x * 2, 1)
box(-y + x0, x + y0, y * 2, 1)
box(-x + x0, -y + y0, x * 2, 1)
box(-y + x0, -x + y0, y * 2, 1)
y++
if (decisionOver2 <= 0)
{
decisionOver2 += 2 * y + 1 // Change in decision criterion for y -> y+1
} else
{
x--
decisionOver2 += 2 * (y - x) + 1 // Change for y -> y+1, x -> x-1
}
}
} | javascript | function (x0, y0, radius, color, c)
{
_c = c || _c
if (color)
{
_c.fillStyle = color
}
x0 *= _scale
y0 *= _scale
radius *= _scale
let x = radius
let y = 0
let decisionOver2 = 1 - x // Decision criterion divided by 2 evaluated at x=r, y=0
while (x >= y)
{
box(-x + x0, y + y0, x * 2, 1)
box(-y + x0, x + y0, y * 2, 1)
box(-x + x0, -y + y0, x * 2, 1)
box(-y + x0, -x + y0, y * 2, 1)
y++
if (decisionOver2 <= 0)
{
decisionOver2 += 2 * y + 1 // Change in decision criterion for y -> y+1
} else
{
x--
decisionOver2 += 2 * (y - x) + 1 // Change for y -> y+1, x -> x-1
}
}
} | [
"function",
"(",
"x0",
",",
"y0",
",",
"radius",
",",
"color",
",",
"c",
")",
"{",
"_c",
"=",
"c",
"||",
"_c",
"if",
"(",
"color",
")",
"{",
"_c",
".",
"fillStyle",
"=",
"color",
"}",
"x0",
"*=",
"_scale",
"y0",
"*=",
"_scale",
"radius",
"*=",
"_scale",
"let",
"x",
"=",
"radius",
"let",
"y",
"=",
"0",
"let",
"decisionOver2",
"=",
"1",
"-",
"x",
"// Decision criterion divided by 2 evaluated at x=r, y=0",
"while",
"(",
"x",
">=",
"y",
")",
"{",
"box",
"(",
"-",
"x",
"+",
"x0",
",",
"y",
"+",
"y0",
",",
"x",
"*",
"2",
",",
"1",
")",
"box",
"(",
"-",
"y",
"+",
"x0",
",",
"x",
"+",
"y0",
",",
"y",
"*",
"2",
",",
"1",
")",
"box",
"(",
"-",
"x",
"+",
"x0",
",",
"-",
"y",
"+",
"y0",
",",
"x",
"*",
"2",
",",
"1",
")",
"box",
"(",
"-",
"y",
"+",
"x0",
",",
"-",
"x",
"+",
"y0",
",",
"y",
"*",
"2",
",",
"1",
")",
"y",
"++",
"if",
"(",
"decisionOver2",
"<=",
"0",
")",
"{",
"decisionOver2",
"+=",
"2",
"*",
"y",
"+",
"1",
"// Change in decision criterion for y -> y+1",
"}",
"else",
"{",
"x",
"--",
"decisionOver2",
"+=",
"2",
"*",
"(",
"y",
"-",
"x",
")",
"+",
"1",
"// Change for y -> y+1, x -> x-1",
"}",
"}",
"}"
]
| draw and fill circle
@param {number} x0 - x-center
@param {number} y0 - y-center
@param {number} radius - radius
@param {string} color
@param {CanvasRenderingContext2D} [c] | [
"draw",
"and",
"fill",
"circle"
]
| 2713a7922f9e7f4c008c0fc4ec398e9b1b64aace | https://github.com/davidfig/pixel/blob/2713a7922f9e7f4c008c0fc4ec398e9b1b64aace/pixelart.js#L158-L188 |
|
44,411 | davidfig/pixel | pixelart.js | function (x0, y0, width, height, c)
{
_c = c || _c
const data = _c.getImageData(x0, y0, width, height)
const bits = data.data
const pixels = []
for (let y = 0; y < height; y += _scale)
{
for (let x = 0; x < width; x += _scale)
{
const index = x * 4 + y * width * 4
if (bits[index + 3] === 0)
{
pixels.push(null)
}
else
{
const color = Color.rgbToHex(bits[index], bits[index + 1], bits[index + 2])
pixels.push(parseInt(color, 16))
}
}
}
return pixels
} | javascript | function (x0, y0, width, height, c)
{
_c = c || _c
const data = _c.getImageData(x0, y0, width, height)
const bits = data.data
const pixels = []
for (let y = 0; y < height; y += _scale)
{
for (let x = 0; x < width; x += _scale)
{
const index = x * 4 + y * width * 4
if (bits[index + 3] === 0)
{
pixels.push(null)
}
else
{
const color = Color.rgbToHex(bits[index], bits[index + 1], bits[index + 2])
pixels.push(parseInt(color, 16))
}
}
}
return pixels
} | [
"function",
"(",
"x0",
",",
"y0",
",",
"width",
",",
"height",
",",
"c",
")",
"{",
"_c",
"=",
"c",
"||",
"_c",
"const",
"data",
"=",
"_c",
".",
"getImageData",
"(",
"x0",
",",
"y0",
",",
"width",
",",
"height",
")",
"const",
"bits",
"=",
"data",
".",
"data",
"const",
"pixels",
"=",
"[",
"]",
"for",
"(",
"let",
"y",
"=",
"0",
";",
"y",
"<",
"height",
";",
"y",
"+=",
"_scale",
")",
"{",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"width",
";",
"x",
"+=",
"_scale",
")",
"{",
"const",
"index",
"=",
"x",
"*",
"4",
"+",
"y",
"*",
"width",
"*",
"4",
"if",
"(",
"bits",
"[",
"index",
"+",
"3",
"]",
"===",
"0",
")",
"{",
"pixels",
".",
"push",
"(",
"null",
")",
"}",
"else",
"{",
"const",
"color",
"=",
"Color",
".",
"rgbToHex",
"(",
"bits",
"[",
"index",
"]",
",",
"bits",
"[",
"index",
"+",
"1",
"]",
",",
"bits",
"[",
"index",
"+",
"2",
"]",
")",
"pixels",
".",
"push",
"(",
"parseInt",
"(",
"color",
",",
"16",
")",
")",
"}",
"}",
"}",
"return",
"pixels",
"}"
]
| gets data for use with yy-pixel.Pixel file format
@param {number} x0 - starting point in canvas
@param {number} y0
@param {number} width
@param {number} height
@param {HTMLContext} c | [
"gets",
"data",
"for",
"use",
"with",
"yy",
"-",
"pixel",
".",
"Pixel",
"file",
"format"
]
| 2713a7922f9e7f4c008c0fc4ec398e9b1b64aace | https://github.com/davidfig/pixel/blob/2713a7922f9e7f4c008c0fc4ec398e9b1b64aace/pixelart.js#L423-L447 |
|
44,412 | kengz/neo4jKB | lib/parse.js | log | function log(arg) {
var str = JSON.stringify(arg)
console.log(str)
return str;
} | javascript | function log(arg) {
var str = JSON.stringify(arg)
console.log(str)
return str;
} | [
"function",
"log",
"(",
"arg",
")",
"{",
"var",
"str",
"=",
"JSON",
".",
"stringify",
"(",
"arg",
")",
"console",
".",
"log",
"(",
"str",
")",
"return",
"str",
";",
"}"
]
| A conveience method. JSON-stringify the argument, logs it, and return the string.
@param {JSON} arg The JSON to be stringified.
@return {string} the stringified JSON.
/* istanbul ignore next | [
"A",
"conveience",
"method",
".",
"JSON",
"-",
"stringify",
"the",
"argument",
"logs",
"it",
"and",
"return",
"the",
"string",
"."
]
| 8762390ac81974afc6bb44a2dd3c44b44aaaa09a | https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/parse.js#L12-L16 |
44,413 | kengz/neo4jKB | lib/parse.js | picker | function picker(iteratees) {
iteratees = iteratees || ['name']
return _.partial(_.pick, _, iteratees)
} | javascript | function picker(iteratees) {
iteratees = iteratees || ['name']
return _.partial(_.pick, _, iteratees)
} | [
"function",
"picker",
"(",
"iteratees",
")",
"{",
"iteratees",
"=",
"iteratees",
"||",
"[",
"'name'",
"]",
"return",
"_",
".",
"partial",
"(",
"_",
".",
"pick",
",",
"_",
",",
"iteratees",
")",
"}"
]
| For use with transform. Generate a picker function using _.pick with a supplied iteratees.
@param {string|Array} iteratees Of _.pick
@return {Function} That picks iteratees of its argument. | [
"For",
"use",
"with",
"transform",
".",
"Generate",
"a",
"picker",
"function",
"using",
"_",
".",
"pick",
"with",
"a",
"supplied",
"iteratees",
"."
]
| 8762390ac81974afc6bb44a2dd3c44b44aaaa09a | https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/parse.js#L530-L533 |
44,414 | goto-bus-stop/get-artist-title | lib/core.js | combineSplitters | function combineSplitters (splitters) {
var l = splitters.length
return function (str) {
for (var i = 0; i < l; i++) {
var result = splitters[i](str)
if (result) return result
}
}
} | javascript | function combineSplitters (splitters) {
var l = splitters.length
return function (str) {
for (var i = 0; i < l; i++) {
var result = splitters[i](str)
if (result) return result
}
}
} | [
"function",
"combineSplitters",
"(",
"splitters",
")",
"{",
"var",
"l",
"=",
"splitters",
".",
"length",
"return",
"function",
"(",
"str",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"var",
"result",
"=",
"splitters",
"[",
"i",
"]",
"(",
"str",
")",
"if",
"(",
"result",
")",
"return",
"result",
"}",
"}",
"}"
]
| Return the result of the first splitter function that matches. | [
"Return",
"the",
"result",
"of",
"the",
"first",
"splitter",
"function",
"that",
"matches",
"."
]
| dd233b21dba6f26bc137a68c71c35132a26f68f2 | https://github.com/goto-bus-stop/get-artist-title/blob/dd233b21dba6f26bc137a68c71c35132a26f68f2/lib/core.js#L21-L29 |
44,415 | goto-bus-stop/get-artist-title | lib/core.js | reducePlugins | function reducePlugins (plugins) {
var before = []
var split = []
var after = []
plugins.forEach(function (plugin) {
if (plugin.before) before.push(plugin.before)
if (plugin.split) split.push(plugin.split)
if (plugin.after) after.push(plugin.after)
})
return {
before: flow(before),
split: combineSplitters(split),
after: flow(after)
}
} | javascript | function reducePlugins (plugins) {
var before = []
var split = []
var after = []
plugins.forEach(function (plugin) {
if (plugin.before) before.push(plugin.before)
if (plugin.split) split.push(plugin.split)
if (plugin.after) after.push(plugin.after)
})
return {
before: flow(before),
split: combineSplitters(split),
after: flow(after)
}
} | [
"function",
"reducePlugins",
"(",
"plugins",
")",
"{",
"var",
"before",
"=",
"[",
"]",
"var",
"split",
"=",
"[",
"]",
"var",
"after",
"=",
"[",
"]",
"plugins",
".",
"forEach",
"(",
"function",
"(",
"plugin",
")",
"{",
"if",
"(",
"plugin",
".",
"before",
")",
"before",
".",
"push",
"(",
"plugin",
".",
"before",
")",
"if",
"(",
"plugin",
".",
"split",
")",
"split",
".",
"push",
"(",
"plugin",
".",
"split",
")",
"if",
"(",
"plugin",
".",
"after",
")",
"after",
".",
"push",
"(",
"plugin",
".",
"after",
")",
"}",
")",
"return",
"{",
"before",
":",
"flow",
"(",
"before",
")",
",",
"split",
":",
"combineSplitters",
"(",
"split",
")",
",",
"after",
":",
"flow",
"(",
"after",
")",
"}",
"}"
]
| Combine multiple plugins into a single plugin. | [
"Combine",
"multiple",
"plugins",
"into",
"a",
"single",
"plugin",
"."
]
| dd233b21dba6f26bc137a68c71c35132a26f68f2 | https://github.com/goto-bus-stop/get-artist-title/blob/dd233b21dba6f26bc137a68c71c35132a26f68f2/lib/core.js#L32-L46 |
44,416 | goto-bus-stop/get-artist-title | lib/core.js | getSongArtistTitle | function getSongArtistTitle (str, options, plugins) {
if (options) {
if (options.defaultArtist) {
plugins.push(fallBackToArtist(options.defaultArtist))
}
if (options.defaultTitle) {
plugins.push(fallBackToTitle(options.defaultTitle))
}
}
var plugin = reducePlugins(plugins)
checkPlugin(plugin)
var split = plugin.split(plugin.before(str))
if (!split) return
return plugin.after(split)
} | javascript | function getSongArtistTitle (str, options, plugins) {
if (options) {
if (options.defaultArtist) {
plugins.push(fallBackToArtist(options.defaultArtist))
}
if (options.defaultTitle) {
plugins.push(fallBackToTitle(options.defaultTitle))
}
}
var plugin = reducePlugins(plugins)
checkPlugin(plugin)
var split = plugin.split(plugin.before(str))
if (!split) return
return plugin.after(split)
} | [
"function",
"getSongArtistTitle",
"(",
"str",
",",
"options",
",",
"plugins",
")",
"{",
"if",
"(",
"options",
")",
"{",
"if",
"(",
"options",
".",
"defaultArtist",
")",
"{",
"plugins",
".",
"push",
"(",
"fallBackToArtist",
"(",
"options",
".",
"defaultArtist",
")",
")",
"}",
"if",
"(",
"options",
".",
"defaultTitle",
")",
"{",
"plugins",
".",
"push",
"(",
"fallBackToTitle",
"(",
"options",
".",
"defaultTitle",
")",
")",
"}",
"}",
"var",
"plugin",
"=",
"reducePlugins",
"(",
"plugins",
")",
"checkPlugin",
"(",
"plugin",
")",
"var",
"split",
"=",
"plugin",
".",
"split",
"(",
"plugin",
".",
"before",
"(",
"str",
")",
")",
"if",
"(",
"!",
"split",
")",
"return",
"return",
"plugin",
".",
"after",
"(",
"split",
")",
"}"
]
| Get an artist name and song title from a string. | [
"Get",
"an",
"artist",
"name",
"and",
"song",
"title",
"from",
"a",
"string",
"."
]
| dd233b21dba6f26bc137a68c71c35132a26f68f2 | https://github.com/goto-bus-stop/get-artist-title/blob/dd233b21dba6f26bc137a68c71c35132a26f68f2/lib/core.js#L74-L92 |
44,417 | samthor/mocha-headless-server | index.js | flatten | function flatten(test) {
return {
title: test.title,
duration: test.duration,
err: test.err ? Object.assign({}, test.err) : null,
};
} | javascript | function flatten(test) {
return {
title: test.title,
duration: test.duration,
err: test.err ? Object.assign({}, test.err) : null,
};
} | [
"function",
"flatten",
"(",
"test",
")",
"{",
"return",
"{",
"title",
":",
"test",
".",
"title",
",",
"duration",
":",
"test",
".",
"duration",
",",
"err",
":",
"test",
".",
"err",
"?",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"test",
".",
"err",
")",
":",
"null",
",",
"}",
";",
"}"
]
| Flatten Mocha's `Test` object into plain JSON. | [
"Flatten",
"Mocha",
"s",
"Test",
"object",
"into",
"plain",
"JSON",
"."
]
| d07e983726b87368160a4f9ebc37f9bbebe4b4e2 | https://github.com/samthor/mocha-headless-server/blob/d07e983726b87368160a4f9ebc37f9bbebe4b4e2/index.js#L73-L79 |
44,418 | rsamec/business-rules | dist/hobbies/node-business-rules.js | BusinessRules | function BusinessRules(Data) {
this.Data = Data;
this.MainValidator = this.createMainValidator().CreateRule("Data");
this.ValidationResult = this.MainValidator.ValidationResult;
this.HobbiesNumberValidator = this.MainValidator.Validators["Hobbies"];
} | javascript | function BusinessRules(Data) {
this.Data = Data;
this.MainValidator = this.createMainValidator().CreateRule("Data");
this.ValidationResult = this.MainValidator.ValidationResult;
this.HobbiesNumberValidator = this.MainValidator.Validators["Hobbies"];
} | [
"function",
"BusinessRules",
"(",
"Data",
")",
"{",
"this",
".",
"Data",
"=",
"Data",
";",
"this",
".",
"MainValidator",
"=",
"this",
".",
"createMainValidator",
"(",
")",
".",
"CreateRule",
"(",
"\"Data\"",
")",
";",
"this",
".",
"ValidationResult",
"=",
"this",
".",
"MainValidator",
".",
"ValidationResult",
";",
"this",
".",
"HobbiesNumberValidator",
"=",
"this",
".",
"MainValidator",
".",
"Validators",
"[",
"\"Hobbies\"",
"]",
";",
"}"
]
| Default constructor.
@param data | [
"Default",
"constructor",
"."
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/hobbies/node-business-rules.js#L40-L46 |
44,419 | Deathspike/npm-build-tools | src/clean.js | clean | function clean(directoryPath, isRoot, done) {
fs.stat(directoryPath, function(err, stat) {
if (err) return done(isRoot ? undefined : err);
if (stat.isFile()) return fs.unlink(directoryPath, done);
fs.readdir(directoryPath, function(err, relativePaths) {
if (err) return done(err);
each(relativePaths, function(relativePath, next) {
var absolutePath = path.join(directoryPath, relativePath);
fs.stat(absolutePath, function(err, stats) {
if (err) return next(err);
if (!stats.isDirectory()) return fs.unlink(absolutePath, next);
clean(absolutePath, false, next);
});
}, function(err) {
if (err) return done(err);
fs.rmdir(directoryPath, done);
});
});
});
} | javascript | function clean(directoryPath, isRoot, done) {
fs.stat(directoryPath, function(err, stat) {
if (err) return done(isRoot ? undefined : err);
if (stat.isFile()) return fs.unlink(directoryPath, done);
fs.readdir(directoryPath, function(err, relativePaths) {
if (err) return done(err);
each(relativePaths, function(relativePath, next) {
var absolutePath = path.join(directoryPath, relativePath);
fs.stat(absolutePath, function(err, stats) {
if (err) return next(err);
if (!stats.isDirectory()) return fs.unlink(absolutePath, next);
clean(absolutePath, false, next);
});
}, function(err) {
if (err) return done(err);
fs.rmdir(directoryPath, done);
});
});
});
} | [
"function",
"clean",
"(",
"directoryPath",
",",
"isRoot",
",",
"done",
")",
"{",
"fs",
".",
"stat",
"(",
"directoryPath",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"isRoot",
"?",
"undefined",
":",
"err",
")",
";",
"if",
"(",
"stat",
".",
"isFile",
"(",
")",
")",
"return",
"fs",
".",
"unlink",
"(",
"directoryPath",
",",
"done",
")",
";",
"fs",
".",
"readdir",
"(",
"directoryPath",
",",
"function",
"(",
"err",
",",
"relativePaths",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"each",
"(",
"relativePaths",
",",
"function",
"(",
"relativePath",
",",
"next",
")",
"{",
"var",
"absolutePath",
"=",
"path",
".",
"join",
"(",
"directoryPath",
",",
"relativePath",
")",
";",
"fs",
".",
"stat",
"(",
"absolutePath",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"return",
"next",
"(",
"err",
")",
";",
"if",
"(",
"!",
"stats",
".",
"isDirectory",
"(",
")",
")",
"return",
"fs",
".",
"unlink",
"(",
"absolutePath",
",",
"next",
")",
";",
"clean",
"(",
"absolutePath",
",",
"false",
",",
"next",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"fs",
".",
"rmdir",
"(",
"directoryPath",
",",
"done",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Cleans the files and directories in the directory path.
@param {string} directoryPath
@param {function(Error=)} done | [
"Cleans",
"the",
"files",
"and",
"directories",
"in",
"the",
"directory",
"path",
"."
]
| caf2a0933b5900e34dc093f34b070a5b947cce39 | https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/clean.js#L30-L49 |
44,420 | erdtman/content-security-policy | lib/index.js | getDirective | function getDirective (options, name) {
if (!options[name]) {
return null;
}
if (typeof options[name] === 'string') {
return name + ' ' + options[name];
}
if (Array.isArray(options[name])) {
let result = name + ' ';
options[name].forEach(value => {
result += value + ' ';
});
return result;
}
return null;
} | javascript | function getDirective (options, name) {
if (!options[name]) {
return null;
}
if (typeof options[name] === 'string') {
return name + ' ' + options[name];
}
if (Array.isArray(options[name])) {
let result = name + ' ';
options[name].forEach(value => {
result += value + ' ';
});
return result;
}
return null;
} | [
"function",
"getDirective",
"(",
"options",
",",
"name",
")",
"{",
"if",
"(",
"!",
"options",
"[",
"name",
"]",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"typeof",
"options",
"[",
"name",
"]",
"===",
"'string'",
")",
"{",
"return",
"name",
"+",
"' '",
"+",
"options",
"[",
"name",
"]",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
"[",
"name",
"]",
")",
")",
"{",
"let",
"result",
"=",
"name",
"+",
"' '",
";",
"options",
"[",
"name",
"]",
".",
"forEach",
"(",
"value",
"=>",
"{",
"result",
"+=",
"value",
"+",
"' '",
";",
"}",
")",
";",
"return",
"result",
";",
"}",
"return",
"null",
";",
"}"
]
| Helper function to compile one directive. handles strings and arrays.
@param options
all options
@param name
name of the one to compile
@returns compilation of named option | [
"Helper",
"function",
"to",
"compile",
"one",
"directive",
".",
"handles",
"strings",
"and",
"arrays",
"."
]
| 7803af4bec2b4b0ff7fe85b61403160373b96349 | https://github.com/erdtman/content-security-policy/blob/7803af4bec2b4b0ff7fe85b61403160373b96349/lib/index.js#L107-L125 |
44,421 | rbackhouse/mpdjs | cordova/mpdjs/plugins/cordova-plugin-file/www/requestFileSystem.js | function (file_system) {
if (file_system) {
if (successCallback) {
fileSystems.getFs(file_system.name, function (fs) {
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
if (!fs) {
fs = new FileSystem(file_system.name, file_system.root);
}
successCallback(fs);
});
}
} else {
// no FileSystem object returned
fail(FileError.NOT_FOUND_ERR);
}
} | javascript | function (file_system) {
if (file_system) {
if (successCallback) {
fileSystems.getFs(file_system.name, function (fs) {
// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
if (!fs) {
fs = new FileSystem(file_system.name, file_system.root);
}
successCallback(fs);
});
}
} else {
// no FileSystem object returned
fail(FileError.NOT_FOUND_ERR);
}
} | [
"function",
"(",
"file_system",
")",
"{",
"if",
"(",
"file_system",
")",
"{",
"if",
"(",
"successCallback",
")",
"{",
"fileSystems",
".",
"getFs",
"(",
"file_system",
".",
"name",
",",
"function",
"(",
"fs",
")",
"{",
"// This should happen only on platforms that haven't implemented requestAllFileSystems (windows)",
"if",
"(",
"!",
"fs",
")",
"{",
"fs",
"=",
"new",
"FileSystem",
"(",
"file_system",
".",
"name",
",",
"file_system",
".",
"root",
")",
";",
"}",
"successCallback",
"(",
"fs",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"// no FileSystem object returned",
"fail",
"(",
"FileError",
".",
"NOT_FOUND_ERR",
")",
";",
"}",
"}"
]
| if successful, return a FileSystem object | [
"if",
"successful",
"return",
"a",
"FileSystem",
"object"
]
| 23fde33a7a24ba8d516c623643e359a25a46259c | https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/plugins/cordova-plugin-file/www/requestFileSystem.js#L60-L75 |
|
44,422 | seriousManual/node-piglow | lib/PiGlowBackend.js | PiGlow | function PiGlow() {
var that = this;
this._wire = null;
this._currentState = null;
Emitter.call(this);
this._initialize(function (error) {
if (error) {
that.emit('error', error);
} else {
that.emit('initialize');
}
});
} | javascript | function PiGlow() {
var that = this;
this._wire = null;
this._currentState = null;
Emitter.call(this);
this._initialize(function (error) {
if (error) {
that.emit('error', error);
} else {
that.emit('initialize');
}
});
} | [
"function",
"PiGlow",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"this",
".",
"_wire",
"=",
"null",
";",
"this",
".",
"_currentState",
"=",
"null",
";",
"Emitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_initialize",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"that",
".",
"emit",
"(",
"'error'",
",",
"error",
")",
";",
"}",
"else",
"{",
"that",
".",
"emit",
"(",
"'initialize'",
")",
";",
"}",
"}",
")",
";",
"}"
]
| command that causes the hardware board to update its LED values
PiGlow Backend
@constructor | [
"command",
"that",
"causes",
"the",
"hardware",
"board",
"to",
"update",
"its",
"LED",
"values",
"PiGlow",
"Backend"
]
| 2175fda7d56a779adb4aaec29e86cbc7745809ef | https://github.com/seriousManual/node-piglow/blob/2175fda7d56a779adb4aaec29e86cbc7745809ef/lib/PiGlowBackend.js#L19-L34 |
44,423 | serban-petrescu/ui5-jsx-rm | src/visitor.js | buildErrorHandler | function buildErrorHandler(path) {
return function(node, text) {
throw path.hub.file.buildCodeFrameError(node, text);
}
} | javascript | function buildErrorHandler(path) {
return function(node, text) {
throw path.hub.file.buildCodeFrameError(node, text);
}
} | [
"function",
"buildErrorHandler",
"(",
"path",
")",
"{",
"return",
"function",
"(",
"node",
",",
"text",
")",
"{",
"throw",
"path",
".",
"hub",
".",
"file",
".",
"buildCodeFrameError",
"(",
"node",
",",
"text",
")",
";",
"}",
"}"
]
| Builds an error handling function for the given path. | [
"Builds",
"an",
"error",
"handling",
"function",
"for",
"the",
"given",
"path",
"."
]
| 57beb245a6c70d7fad75a69242deb0a1ee7f3ee0 | https://github.com/serban-petrescu/ui5-jsx-rm/blob/57beb245a6c70d7fad75a69242deb0a1ee7f3ee0/src/visitor.js#L16-L20 |
44,424 | dpw/node-buffer-more-ints | buffer-more-ints.js | check_value | function check_value(val, min, max) {
val = +val;
if (typeof(val) != 'number' || val < min || val > max || Math.floor(val) !== val) {
throw new TypeError("\"value\" argument is out of bounds");
}
return val;
} | javascript | function check_value(val, min, max) {
val = +val;
if (typeof(val) != 'number' || val < min || val > max || Math.floor(val) !== val) {
throw new TypeError("\"value\" argument is out of bounds");
}
return val;
} | [
"function",
"check_value",
"(",
"val",
",",
"min",
",",
"max",
")",
"{",
"val",
"=",
"+",
"val",
";",
"if",
"(",
"typeof",
"(",
"val",
")",
"!=",
"'number'",
"||",
"val",
"<",
"min",
"||",
"val",
">",
"max",
"||",
"Math",
".",
"floor",
"(",
"val",
")",
"!==",
"val",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"\\\"value\\\" argument is out of bounds\"",
")",
";",
"}",
"return",
"val",
";",
"}"
]
| Check that a value is an integer within the given range | [
"Check",
"that",
"a",
"value",
"is",
"an",
"integer",
"within",
"the",
"given",
"range"
]
| e0909f16d6d2c8801ae0119c36486019cfd8cf31 | https://github.com/dpw/node-buffer-more-ints/blob/e0909f16d6d2c8801ae0119c36486019cfd8cf31/buffer-more-ints.js#L49-L55 |
44,425 | dpw/node-buffer-more-ints | buffer-more-ints.js | check_bounds | function check_bounds(buf, offset, len) {
if (offset < 0 || offset + len > buf.length) {
throw new RangeError("Index out of range");
}
} | javascript | function check_bounds(buf, offset, len) {
if (offset < 0 || offset + len > buf.length) {
throw new RangeError("Index out of range");
}
} | [
"function",
"check_bounds",
"(",
"buf",
",",
"offset",
",",
"len",
")",
"{",
"if",
"(",
"offset",
"<",
"0",
"||",
"offset",
"+",
"len",
">",
"buf",
".",
"length",
")",
"{",
"throw",
"new",
"RangeError",
"(",
"\"Index out of range\"",
")",
";",
"}",
"}"
]
| Check that something is within the Buffer bounds | [
"Check",
"that",
"something",
"is",
"within",
"the",
"Buffer",
"bounds"
]
| e0909f16d6d2c8801ae0119c36486019cfd8cf31 | https://github.com/dpw/node-buffer-more-ints/blob/e0909f16d6d2c8801ae0119c36486019cfd8cf31/buffer-more-ints.js#L58-L62 |
44,426 | jugglinmike/compare-ast | lib/compare.js | compareAst | function compareAst(actualSrc, expectedSrc, options) {
var actualAst, expectedAst;
options = options || {};
if (!options.comparators) {
options.comparators = [];
}
/*
* A collection of comparator functions that recognize equivalent nodes
* that would otherwise be reported as unequal by simple object comparison.
* These may:
*
* - return `true` if the given nodes can be verified as equivalent with no
* further processing
* - return an instance of MatchError if the nodes are verified as
* uniquivalent
* - return any other value if equivalency cannot be determined
*/
Array.prototype.push.apply(options.comparators, [
require('./comparators/fuzzy-identifiers')(options),
require('./comparators/fuzzy-strings')(options)
]);
try {
actualAst = parse(actualSrc).body;
} catch(err) {
throw new Errors.ParseError();
}
try {
expectedAst = parse(expectedSrc).body;
} catch (err) {
throw new Errors.ParseError();
}
function _bind(actual, expected) {
var attr;
// Literal values
if (Object(actual) !== actual) {
if (actual !== expected) {
throw new Errors.MatchError(actualAst, expectedAst);
}
return;
}
// Arrays
if (Array.isArray(actual)) {
if (actual.length !== expected.length) {
throw new Errors.MatchError(actualAst, expectedAst);
}
actual.forEach(function(_, i) {
_bind(actual[i], expected[i]);
});
return;
}
// Nodes
normalizeMemberExpr(actual);
normalizeMemberExpr(expected);
if (checkEquivalency(options.comparators, actual, expected)) {
return;
}
// Either remove attributes or recurse on their values
for (attr in actual) {
if (expected && attr in expected) {
_bind(actual[attr], expected[attr]);
} else {
throw new Errors.MatchError(actualAst, expectedAst);
}
}
}
// Start recursing on the ASTs from the top level.
_bind(actualAst, expectedAst);
return null;
} | javascript | function compareAst(actualSrc, expectedSrc, options) {
var actualAst, expectedAst;
options = options || {};
if (!options.comparators) {
options.comparators = [];
}
/*
* A collection of comparator functions that recognize equivalent nodes
* that would otherwise be reported as unequal by simple object comparison.
* These may:
*
* - return `true` if the given nodes can be verified as equivalent with no
* further processing
* - return an instance of MatchError if the nodes are verified as
* uniquivalent
* - return any other value if equivalency cannot be determined
*/
Array.prototype.push.apply(options.comparators, [
require('./comparators/fuzzy-identifiers')(options),
require('./comparators/fuzzy-strings')(options)
]);
try {
actualAst = parse(actualSrc).body;
} catch(err) {
throw new Errors.ParseError();
}
try {
expectedAst = parse(expectedSrc).body;
} catch (err) {
throw new Errors.ParseError();
}
function _bind(actual, expected) {
var attr;
// Literal values
if (Object(actual) !== actual) {
if (actual !== expected) {
throw new Errors.MatchError(actualAst, expectedAst);
}
return;
}
// Arrays
if (Array.isArray(actual)) {
if (actual.length !== expected.length) {
throw new Errors.MatchError(actualAst, expectedAst);
}
actual.forEach(function(_, i) {
_bind(actual[i], expected[i]);
});
return;
}
// Nodes
normalizeMemberExpr(actual);
normalizeMemberExpr(expected);
if (checkEquivalency(options.comparators, actual, expected)) {
return;
}
// Either remove attributes or recurse on their values
for (attr in actual) {
if (expected && attr in expected) {
_bind(actual[attr], expected[attr]);
} else {
throw new Errors.MatchError(actualAst, expectedAst);
}
}
}
// Start recursing on the ASTs from the top level.
_bind(actualAst, expectedAst);
return null;
} | [
"function",
"compareAst",
"(",
"actualSrc",
",",
"expectedSrc",
",",
"options",
")",
"{",
"var",
"actualAst",
",",
"expectedAst",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"options",
".",
"comparators",
")",
"{",
"options",
".",
"comparators",
"=",
"[",
"]",
";",
"}",
"/*\n\t * A collection of comparator functions that recognize equivalent nodes\n\t * that would otherwise be reported as unequal by simple object comparison.\n\t * These may:\n\t *\n\t * - return `true` if the given nodes can be verified as equivalent with no\n\t * further processing\n\t * - return an instance of MatchError if the nodes are verified as\n\t * uniquivalent\n\t * - return any other value if equivalency cannot be determined\n\t */",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"options",
".",
"comparators",
",",
"[",
"require",
"(",
"'./comparators/fuzzy-identifiers'",
")",
"(",
"options",
")",
",",
"require",
"(",
"'./comparators/fuzzy-strings'",
")",
"(",
"options",
")",
"]",
")",
";",
"try",
"{",
"actualAst",
"=",
"parse",
"(",
"actualSrc",
")",
".",
"body",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Errors",
".",
"ParseError",
"(",
")",
";",
"}",
"try",
"{",
"expectedAst",
"=",
"parse",
"(",
"expectedSrc",
")",
".",
"body",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Errors",
".",
"ParseError",
"(",
")",
";",
"}",
"function",
"_bind",
"(",
"actual",
",",
"expected",
")",
"{",
"var",
"attr",
";",
"// Literal values",
"if",
"(",
"Object",
"(",
"actual",
")",
"!==",
"actual",
")",
"{",
"if",
"(",
"actual",
"!==",
"expected",
")",
"{",
"throw",
"new",
"Errors",
".",
"MatchError",
"(",
"actualAst",
",",
"expectedAst",
")",
";",
"}",
"return",
";",
"}",
"// Arrays",
"if",
"(",
"Array",
".",
"isArray",
"(",
"actual",
")",
")",
"{",
"if",
"(",
"actual",
".",
"length",
"!==",
"expected",
".",
"length",
")",
"{",
"throw",
"new",
"Errors",
".",
"MatchError",
"(",
"actualAst",
",",
"expectedAst",
")",
";",
"}",
"actual",
".",
"forEach",
"(",
"function",
"(",
"_",
",",
"i",
")",
"{",
"_bind",
"(",
"actual",
"[",
"i",
"]",
",",
"expected",
"[",
"i",
"]",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"// Nodes",
"normalizeMemberExpr",
"(",
"actual",
")",
";",
"normalizeMemberExpr",
"(",
"expected",
")",
";",
"if",
"(",
"checkEquivalency",
"(",
"options",
".",
"comparators",
",",
"actual",
",",
"expected",
")",
")",
"{",
"return",
";",
"}",
"// Either remove attributes or recurse on their values",
"for",
"(",
"attr",
"in",
"actual",
")",
"{",
"if",
"(",
"expected",
"&&",
"attr",
"in",
"expected",
")",
"{",
"_bind",
"(",
"actual",
"[",
"attr",
"]",
",",
"expected",
"[",
"attr",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Errors",
".",
"MatchError",
"(",
"actualAst",
",",
"expectedAst",
")",
";",
"}",
"}",
"}",
"// Start recursing on the ASTs from the top level.",
"_bind",
"(",
"actualAst",
",",
"expectedAst",
")",
";",
"return",
"null",
";",
"}"
]
| Given a "template" expected AST that defines abstract identifier names described by `options.varPattern`, "bind" those identifiers to their concrete names in the "actual" AST. | [
"Given",
"a",
"template",
"expected",
"AST",
"that",
"defines",
"abstract",
"identifier",
"names",
"described",
"by",
"options",
".",
"varPattern",
"bind",
"those",
"identifiers",
"to",
"their",
"concrete",
"names",
"in",
"the",
"actual",
"AST",
"."
]
| 4329c661186c976ffe556826f518167256ca7ab3 | https://github.com/jugglinmike/compare-ast/blob/4329c661186c976ffe556826f518167256ca7ab3/lib/compare.js#L8-L89 |
44,427 | radiovisual/metalsmith-rootpath | index.js | plugin | function plugin() {
return function (files, metalsmith, done) {
Object.keys(files).forEach(function (file) {
setImmediate(done);
var pathslash = process.platform === 'win32' ? '\\' : '/';
var rootPath = '';
var levels = needles(file, pathslash);
for (var i = 0; i < levels; i++) {
rootPath += '../';
}
files[file].rootPath = rootPath;
});
};
} | javascript | function plugin() {
return function (files, metalsmith, done) {
Object.keys(files).forEach(function (file) {
setImmediate(done);
var pathslash = process.platform === 'win32' ? '\\' : '/';
var rootPath = '';
var levels = needles(file, pathslash);
for (var i = 0; i < levels; i++) {
rootPath += '../';
}
files[file].rootPath = rootPath;
});
};
} | [
"function",
"plugin",
"(",
")",
"{",
"return",
"function",
"(",
"files",
",",
"metalsmith",
",",
"done",
")",
"{",
"Object",
".",
"keys",
"(",
"files",
")",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"setImmediate",
"(",
"done",
")",
";",
"var",
"pathslash",
"=",
"process",
".",
"platform",
"===",
"'win32'",
"?",
"'\\\\'",
":",
"'/'",
";",
"var",
"rootPath",
"=",
"''",
";",
"var",
"levels",
"=",
"needles",
"(",
"file",
",",
"pathslash",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"levels",
";",
"i",
"++",
")",
"{",
"rootPath",
"+=",
"'../'",
";",
"}",
"files",
"[",
"file",
"]",
".",
"rootPath",
"=",
"rootPath",
";",
"}",
")",
";",
"}",
";",
"}"
]
| Metalsmith plugin that sets a `rootPath` variable on each file's metadata.
This allows you to find relative paths in your templates easily.
@return {Function} | [
"Metalsmith",
"plugin",
"that",
"sets",
"a",
"rootPath",
"variable",
"on",
"each",
"file",
"s",
"metadata",
".",
"This",
"allows",
"you",
"to",
"find",
"relative",
"paths",
"in",
"your",
"templates",
"easily",
"."
]
| a649c672e25107ac190969a6db5c6a79ead0c698 | https://github.com/radiovisual/metalsmith-rootpath/blob/a649c672e25107ac190969a6db5c6a79ead0c698/index.js#L17-L32 |
44,428 | bowheart/zedux | src/utils/general.js | getDetailedObjectType | function getDetailedObjectType(thing) {
let prototype = Object.getPrototypeOf(thing)
if (!prototype) return NO_PROTOTYPE
return Object.getPrototypeOf(prototype)
? COMPLEX_OBJECT
: PLAIN_OBJECT
} | javascript | function getDetailedObjectType(thing) {
let prototype = Object.getPrototypeOf(thing)
if (!prototype) return NO_PROTOTYPE
return Object.getPrototypeOf(prototype)
? COMPLEX_OBJECT
: PLAIN_OBJECT
} | [
"function",
"getDetailedObjectType",
"(",
"thing",
")",
"{",
"let",
"prototype",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"thing",
")",
"if",
"(",
"!",
"prototype",
")",
"return",
"NO_PROTOTYPE",
"return",
"Object",
".",
"getPrototypeOf",
"(",
"prototype",
")",
"?",
"COMPLEX_OBJECT",
":",
"PLAIN_OBJECT",
"}"
]
| Determines which kind of object an "object" is.
Objects can be prototype-less, complex, or plain. | [
"Determines",
"which",
"kind",
"of",
"object",
"an",
"object",
"is",
"."
]
| f817a5e9520e0496628e94e8782134ac53ece858 | https://github.com/bowheart/zedux/blob/f817a5e9520e0496628e94e8782134ac53ece858/src/utils/general.js#L95-L103 |
44,429 | rsamec/business-rules | dist/invoice/node-business-rules.js | BusinessRules | function BusinessRules(Data) {
this.Data = Data;
this.InvoiceValidator = this.createInvoiceValidator().CreateRule("Data");
this.ValidationResult = this.InvoiceValidator.ValidationResult;
} | javascript | function BusinessRules(Data) {
this.Data = Data;
this.InvoiceValidator = this.createInvoiceValidator().CreateRule("Data");
this.ValidationResult = this.InvoiceValidator.ValidationResult;
} | [
"function",
"BusinessRules",
"(",
"Data",
")",
"{",
"this",
".",
"Data",
"=",
"Data",
";",
"this",
".",
"InvoiceValidator",
"=",
"this",
".",
"createInvoiceValidator",
"(",
")",
".",
"CreateRule",
"(",
"\"Data\"",
")",
";",
"this",
".",
"ValidationResult",
"=",
"this",
".",
"InvoiceValidator",
".",
"ValidationResult",
";",
"}"
]
| Default ctor.
@param Data Invoice data | [
"Default",
"ctor",
"."
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/invoice/node-business-rules.js#L25-L30 |
44,430 | rsamec/business-rules | dist/invoice/node-business-rules.js | function (args) {
args.HasError = false;
args.ErrorMessage = "";
if (this.Items !== undefined && this.Items.length === 0) {
args.HasError = true;
args.ErrorMessage = "At least one item must be on invoice.";
args.TranslateArgs = { TranslateId: "AnyItem", MessageArgs: undefined };
return;
}
} | javascript | function (args) {
args.HasError = false;
args.ErrorMessage = "";
if (this.Items !== undefined && this.Items.length === 0) {
args.HasError = true;
args.ErrorMessage = "At least one item must be on invoice.";
args.TranslateArgs = { TranslateId: "AnyItem", MessageArgs: undefined };
return;
}
} | [
"function",
"(",
"args",
")",
"{",
"args",
".",
"HasError",
"=",
"false",
";",
"args",
".",
"ErrorMessage",
"=",
"\"\"",
";",
"if",
"(",
"this",
".",
"Items",
"!==",
"undefined",
"&&",
"this",
".",
"Items",
".",
"length",
"===",
"0",
")",
"{",
"args",
".",
"HasError",
"=",
"true",
";",
"args",
".",
"ErrorMessage",
"=",
"\"At least one item must be on invoice.\"",
";",
"args",
".",
"TranslateArgs",
"=",
"{",
"TranslateId",
":",
"\"AnyItem\"",
",",
"MessageArgs",
":",
"undefined",
"}",
";",
"return",
";",
"}",
"}"
]
| at least one item must be filled | [
"at",
"least",
"one",
"item",
"must",
"be",
"filled"
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/invoice/node-business-rules.js#L63-L73 |
|
44,431 | seriousManual/node-piglow | index.js | createPiGlow | function createPiGlow(callback) {
var myPiGlow = new PiGlowBackend();
var myInterface = piGlowInterface(myPiGlow);
myPiGlow
.on('initialize', function() {
callback(null, myInterface);
})
.on('error', function(error) {
callback(error, null);
});
} | javascript | function createPiGlow(callback) {
var myPiGlow = new PiGlowBackend();
var myInterface = piGlowInterface(myPiGlow);
myPiGlow
.on('initialize', function() {
callback(null, myInterface);
})
.on('error', function(error) {
callback(error, null);
});
} | [
"function",
"createPiGlow",
"(",
"callback",
")",
"{",
"var",
"myPiGlow",
"=",
"new",
"PiGlowBackend",
"(",
")",
";",
"var",
"myInterface",
"=",
"piGlowInterface",
"(",
"myPiGlow",
")",
";",
"myPiGlow",
".",
"on",
"(",
"'initialize'",
",",
"function",
"(",
")",
"{",
"callback",
"(",
"null",
",",
"myInterface",
")",
";",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"error",
")",
"{",
"callback",
"(",
"error",
",",
"null",
")",
";",
"}",
")",
";",
"}"
]
| convenience constructor function | [
"convenience",
"constructor",
"function"
]
| 2175fda7d56a779adb4aaec29e86cbc7745809ef | https://github.com/seriousManual/node-piglow/blob/2175fda7d56a779adb4aaec29e86cbc7745809ef/index.js#L10-L21 |
44,432 | dominictarr/line-graph | ruler.js | calcSteps | function calcSteps (min, max, room, width) {
var range = max - min
var i = 0, e
while(true) {
var e = Math.pow(10, i++)
if(e > 10000000000)
throw new Error('oops')
var re = range/e
var space = width*1.25
if(room / (re) > space) return e
if(room*2 / (re) > space) return e*2
if(room*2.5 / (re) > space) return e*2.5
if(room*5 / (re) > space) return e*5
}
} | javascript | function calcSteps (min, max, room, width) {
var range = max - min
var i = 0, e
while(true) {
var e = Math.pow(10, i++)
if(e > 10000000000)
throw new Error('oops')
var re = range/e
var space = width*1.25
if(room / (re) > space) return e
if(room*2 / (re) > space) return e*2
if(room*2.5 / (re) > space) return e*2.5
if(room*5 / (re) > space) return e*5
}
} | [
"function",
"calcSteps",
"(",
"min",
",",
"max",
",",
"room",
",",
"width",
")",
"{",
"var",
"range",
"=",
"max",
"-",
"min",
"var",
"i",
"=",
"0",
",",
"e",
"while",
"(",
"true",
")",
"{",
"var",
"e",
"=",
"Math",
".",
"pow",
"(",
"10",
",",
"i",
"++",
")",
"if",
"(",
"e",
">",
"10000000000",
")",
"throw",
"new",
"Error",
"(",
"'oops'",
")",
"var",
"re",
"=",
"range",
"/",
"e",
"var",
"space",
"=",
"width",
"*",
"1.25",
"if",
"(",
"room",
"/",
"(",
"re",
")",
">",
"space",
")",
"return",
"e",
"if",
"(",
"room",
"*",
"2",
"/",
"(",
"re",
")",
">",
"space",
")",
"return",
"e",
"*",
"2",
"if",
"(",
"room",
"*",
"2.5",
"/",
"(",
"re",
")",
">",
"space",
")",
"return",
"e",
"*",
"2.5",
"if",
"(",
"room",
"*",
"5",
"/",
"(",
"re",
")",
">",
"space",
")",
"return",
"e",
"*",
"5",
"}",
"}"
]
| must have range, room, and width | [
"must",
"have",
"range",
"room",
"and",
"width"
]
| 81b3d0eed7b6b2809a4aff0fc990e00df325ab30 | https://github.com/dominictarr/line-graph/blob/81b3d0eed7b6b2809a4aff0fc990e00df325ab30/ruler.js#L6-L23 |
44,433 | kengz/neo4jKB | lib/query.js | postQuery | function postQuery(statArr) {
var options = {
method: 'POST',
baseUrl: this.NEO4J_BASEURL,
url: this.NEO4J_ENDPT,
headers: {
'Accept': 'application/json; charset=UTF-8',
'Content-type': 'application/json'
},
json: {
statements: statArr
// [{statement: query, parameters: params},
// {statement: query, parameters: params}]
}
}
// call to the db server, returns a Promise
return request(options).then(resolver).catch(function(e) {
throw new Error(JSON.stringify(e))
})
} | javascript | function postQuery(statArr) {
var options = {
method: 'POST',
baseUrl: this.NEO4J_BASEURL,
url: this.NEO4J_ENDPT,
headers: {
'Accept': 'application/json; charset=UTF-8',
'Content-type': 'application/json'
},
json: {
statements: statArr
// [{statement: query, parameters: params},
// {statement: query, parameters: params}]
}
}
// call to the db server, returns a Promise
return request(options).then(resolver).catch(function(e) {
throw new Error(JSON.stringify(e))
})
} | [
"function",
"postQuery",
"(",
"statArr",
")",
"{",
"var",
"options",
"=",
"{",
"method",
":",
"'POST'",
",",
"baseUrl",
":",
"this",
".",
"NEO4J_BASEURL",
",",
"url",
":",
"this",
".",
"NEO4J_ENDPT",
",",
"headers",
":",
"{",
"'Accept'",
":",
"'application/json; charset=UTF-8'",
",",
"'Content-type'",
":",
"'application/json'",
"}",
",",
"json",
":",
"{",
"statements",
":",
"statArr",
"// [{statement: query, parameters: params},",
"// {statement: query, parameters: params}]",
"}",
"}",
"// call to the db server, returns a Promise",
"return",
"request",
"(",
"options",
")",
".",
"then",
"(",
"resolver",
")",
".",
"catch",
"(",
"function",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"JSON",
".",
"stringify",
"(",
"e",
")",
")",
"}",
")",
"}"
]
| POST a comitting query to the db.
@private
@param {Array} statArr Array of statement objects.
@param {Function} callback Function with (err, res, body) args for the query result.
@return {Promise} A promise object resolved with the query results from the request module. | [
"POST",
"a",
"comitting",
"query",
"to",
"the",
"db",
"."
]
| 8762390ac81974afc6bb44a2dd3c44b44aaaa09a | https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/query.js#L89-L108 |
44,434 | kengz/neo4jKB | lib/query.js | resolver | function resolver(obj) {
return new Promise(function(resolve, reject) {
_.isEmpty(obj.results) ? reject(new Error(JSON.stringify(obj.errors))) : resolve(obj.results);
})
} | javascript | function resolver(obj) {
return new Promise(function(resolve, reject) {
_.isEmpty(obj.results) ? reject(new Error(JSON.stringify(obj.errors))) : resolve(obj.results);
})
} | [
"function",
"resolver",
"(",
"obj",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"_",
".",
"isEmpty",
"(",
"obj",
".",
"results",
")",
"?",
"reject",
"(",
"new",
"Error",
"(",
"JSON",
".",
"stringify",
"(",
"obj",
".",
"errors",
")",
")",
")",
":",
"resolve",
"(",
"obj",
".",
"results",
")",
";",
"}",
")",
"}"
]
| Resolver function to chain Promise to resolve results or reject errors. Used in postQuery.
@private
@param {JSON} obj Returned from the neo4j server.
@return {Promise} That resolves results or rejects errors. | [
"Resolver",
"function",
"to",
"chain",
"Promise",
"to",
"resolve",
"results",
"or",
"reject",
"errors",
".",
"Used",
"in",
"postQuery",
"."
]
| 8762390ac81974afc6bb44a2dd3c44b44aaaa09a | https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/query.js#L116-L120 |
44,435 | seriousManual/node-piglow | lib/util/valueProcessor.js | processValue | function processValue(value) {
if (isNaN(value)) return 0;
value = Math.max(MIN_VALUE, Math.min(value, MAX_VALUE));
//value is between 0 and 1, thus is interpreted as percentage
if (value < 1) value = value * MAX_VALUE;
value = parseInt(value, 10);
return value;
} | javascript | function processValue(value) {
if (isNaN(value)) return 0;
value = Math.max(MIN_VALUE, Math.min(value, MAX_VALUE));
//value is between 0 and 1, thus is interpreted as percentage
if (value < 1) value = value * MAX_VALUE;
value = parseInt(value, 10);
return value;
} | [
"function",
"processValue",
"(",
"value",
")",
"{",
"if",
"(",
"isNaN",
"(",
"value",
")",
")",
"return",
"0",
";",
"value",
"=",
"Math",
".",
"max",
"(",
"MIN_VALUE",
",",
"Math",
".",
"min",
"(",
"value",
",",
"MAX_VALUE",
")",
")",
";",
"//value is between 0 and 1, thus is interpreted as percentage",
"if",
"(",
"value",
"<",
"1",
")",
"value",
"=",
"value",
"*",
"MAX_VALUE",
";",
"value",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"return",
"value",
";",
"}"
]
| sanitizes brightness values and does a gamma correction mapping
@param value
@return {*} | [
"sanitizes",
"brightness",
"values",
"and",
"does",
"a",
"gamma",
"correction",
"mapping"
]
| 2175fda7d56a779adb4aaec29e86cbc7745809ef | https://github.com/seriousManual/node-piglow/blob/2175fda7d56a779adb4aaec29e86cbc7745809ef/lib/util/valueProcessor.js#L9-L20 |
44,436 | rsamec/business-rules | dist/vacationApproval/node-business-rules.js | function () {
if (this.Data.ExcludedDays == undefined || this.Data.ExcludedDays.length == 0)
return this.ExcludedWeekdays;
return _.union(this.ExcludedWeekdays, this.ExcludedDaysDatePart);
} | javascript | function () {
if (this.Data.ExcludedDays == undefined || this.Data.ExcludedDays.length == 0)
return this.ExcludedWeekdays;
return _.union(this.ExcludedWeekdays, this.ExcludedDaysDatePart);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"Data",
".",
"ExcludedDays",
"==",
"undefined",
"||",
"this",
".",
"Data",
".",
"ExcludedDays",
".",
"length",
"==",
"0",
")",
"return",
"this",
".",
"ExcludedWeekdays",
";",
"return",
"_",
".",
"union",
"(",
"this",
".",
"ExcludedWeekdays",
",",
"this",
".",
"ExcludedDaysDatePart",
")",
";",
"}"
]
| Return days excluded out of vacation. | [
"Return",
"days",
"excluded",
"out",
"of",
"vacation",
"."
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/vacationApproval/node-business-rules.js#L289-L293 |
|
44,437 | rsamec/business-rules | dist/vacationApproval/node-business-rules.js | function (config, args) {
var msg = config["Msg"];
var format = config["Format"];
if (format != undefined) {
_.extend(args, {
FormatedFrom: moment(args.From).format(format),
FormatedTo: moment(args.To).format(format),
FormatedAttemptedValue: moment(args.AttemptedValue).format(format)
});
}
msg = msg.replace('From', 'FormatedFrom');
msg = msg.replace('To', 'FormatedTo');
msg = msg.replace('AttemptedValue', 'FormatedAttemptedValue');
return Utils.StringFce.format(msg, args);
} | javascript | function (config, args) {
var msg = config["Msg"];
var format = config["Format"];
if (format != undefined) {
_.extend(args, {
FormatedFrom: moment(args.From).format(format),
FormatedTo: moment(args.To).format(format),
FormatedAttemptedValue: moment(args.AttemptedValue).format(format)
});
}
msg = msg.replace('From', 'FormatedFrom');
msg = msg.replace('To', 'FormatedTo');
msg = msg.replace('AttemptedValue', 'FormatedAttemptedValue');
return Utils.StringFce.format(msg, args);
} | [
"function",
"(",
"config",
",",
"args",
")",
"{",
"var",
"msg",
"=",
"config",
"[",
"\"Msg\"",
"]",
";",
"var",
"format",
"=",
"config",
"[",
"\"Format\"",
"]",
";",
"if",
"(",
"format",
"!=",
"undefined",
")",
"{",
"_",
".",
"extend",
"(",
"args",
",",
"{",
"FormatedFrom",
":",
"moment",
"(",
"args",
".",
"From",
")",
".",
"format",
"(",
"format",
")",
",",
"FormatedTo",
":",
"moment",
"(",
"args",
".",
"To",
")",
".",
"format",
"(",
"format",
")",
",",
"FormatedAttemptedValue",
":",
"moment",
"(",
"args",
".",
"AttemptedValue",
")",
".",
"format",
"(",
"format",
")",
"}",
")",
";",
"}",
"msg",
"=",
"msg",
".",
"replace",
"(",
"'From'",
",",
"'FormatedFrom'",
")",
";",
"msg",
"=",
"msg",
".",
"replace",
"(",
"'To'",
",",
"'FormatedTo'",
")",
";",
"msg",
"=",
"msg",
".",
"replace",
"(",
"'AttemptedValue'",
",",
"'FormatedAttemptedValue'",
")",
";",
"return",
"Utils",
".",
"StringFce",
".",
"format",
"(",
"msg",
",",
"args",
")",
";",
"}"
]
| create custom message for validation | [
"create",
"custom",
"message",
"for",
"validation"
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/vacationApproval/node-business-rules.js#L347-L363 |
|
44,438 | rsamec/business-rules | dist/vacationApproval/node-business-rules.js | function (args) {
args.HasError = false;
args.ErrorMessage = "";
//no dates - > nothing to validate
if (!_.isDate(this.From) || !_.isDate(this.To))
return;
if (self.FromDatePart.isAfter(self.ToDatePart)) {
args.HasError = true;
args.ErrorMessage = customErrorMessage({ Msg: "Date from '{From}' must be before date to '{To}'.", Format: 'MM/DD/YYYY' }, this);
args.TranslateArgs = { TranslateId: 'BeforeDate', MessageArgs: this, CustomMessage: customErrorMessage };
return;
}
var minDays = 1;
var maxDays = 25;
//maximal duration
if (self.IsOverLimitRange || (self.VacationDaysCount > maxDays || self.VacationDaysCount < minDays)) {
args.HasError = true;
var messageArgs = { MaxDays: maxDays, MinDays: minDays };
args.ErrorMessage = Utils.StringFce.format("Vacation duration value must be between {MinDays] and {MaxDays} days.", messageArgs);
args.TranslateArgs = { TranslateId: 'RangeDuration', MessageArgs: messageArgs };
return;
}
var diff = _.difference(self.ExcludedDaysDatePart, self.RangeDays);
if (diff.length != 0) {
args.HasError = true;
var messageArgs2 = { ExcludedDates: _.reduce(diff, function (memo, item) {
return memo + item.format("MM/DD/YYYY");
}) };
args.ErrorMessage = Utils.StringFce.format("Excluded days are not in range. '{ExcludedDates}'.", messageArgs2);
args.TranslateArgs = { TranslateId: 'ExcludedDaysMsg', MessageArgs: messageArgs2 };
return;
}
} | javascript | function (args) {
args.HasError = false;
args.ErrorMessage = "";
//no dates - > nothing to validate
if (!_.isDate(this.From) || !_.isDate(this.To))
return;
if (self.FromDatePart.isAfter(self.ToDatePart)) {
args.HasError = true;
args.ErrorMessage = customErrorMessage({ Msg: "Date from '{From}' must be before date to '{To}'.", Format: 'MM/DD/YYYY' }, this);
args.TranslateArgs = { TranslateId: 'BeforeDate', MessageArgs: this, CustomMessage: customErrorMessage };
return;
}
var minDays = 1;
var maxDays = 25;
//maximal duration
if (self.IsOverLimitRange || (self.VacationDaysCount > maxDays || self.VacationDaysCount < minDays)) {
args.HasError = true;
var messageArgs = { MaxDays: maxDays, MinDays: minDays };
args.ErrorMessage = Utils.StringFce.format("Vacation duration value must be between {MinDays] and {MaxDays} days.", messageArgs);
args.TranslateArgs = { TranslateId: 'RangeDuration', MessageArgs: messageArgs };
return;
}
var diff = _.difference(self.ExcludedDaysDatePart, self.RangeDays);
if (diff.length != 0) {
args.HasError = true;
var messageArgs2 = { ExcludedDates: _.reduce(diff, function (memo, item) {
return memo + item.format("MM/DD/YYYY");
}) };
args.ErrorMessage = Utils.StringFce.format("Excluded days are not in range. '{ExcludedDates}'.", messageArgs2);
args.TranslateArgs = { TranslateId: 'ExcludedDaysMsg', MessageArgs: messageArgs2 };
return;
}
} | [
"function",
"(",
"args",
")",
"{",
"args",
".",
"HasError",
"=",
"false",
";",
"args",
".",
"ErrorMessage",
"=",
"\"\"",
";",
"//no dates - > nothing to validate",
"if",
"(",
"!",
"_",
".",
"isDate",
"(",
"this",
".",
"From",
")",
"||",
"!",
"_",
".",
"isDate",
"(",
"this",
".",
"To",
")",
")",
"return",
";",
"if",
"(",
"self",
".",
"FromDatePart",
".",
"isAfter",
"(",
"self",
".",
"ToDatePart",
")",
")",
"{",
"args",
".",
"HasError",
"=",
"true",
";",
"args",
".",
"ErrorMessage",
"=",
"customErrorMessage",
"(",
"{",
"Msg",
":",
"\"Date from '{From}' must be before date to '{To}'.\"",
",",
"Format",
":",
"'MM/DD/YYYY'",
"}",
",",
"this",
")",
";",
"args",
".",
"TranslateArgs",
"=",
"{",
"TranslateId",
":",
"'BeforeDate'",
",",
"MessageArgs",
":",
"this",
",",
"CustomMessage",
":",
"customErrorMessage",
"}",
";",
"return",
";",
"}",
"var",
"minDays",
"=",
"1",
";",
"var",
"maxDays",
"=",
"25",
";",
"//maximal duration",
"if",
"(",
"self",
".",
"IsOverLimitRange",
"||",
"(",
"self",
".",
"VacationDaysCount",
">",
"maxDays",
"||",
"self",
".",
"VacationDaysCount",
"<",
"minDays",
")",
")",
"{",
"args",
".",
"HasError",
"=",
"true",
";",
"var",
"messageArgs",
"=",
"{",
"MaxDays",
":",
"maxDays",
",",
"MinDays",
":",
"minDays",
"}",
";",
"args",
".",
"ErrorMessage",
"=",
"Utils",
".",
"StringFce",
".",
"format",
"(",
"\"Vacation duration value must be between {MinDays] and {MaxDays} days.\"",
",",
"messageArgs",
")",
";",
"args",
".",
"TranslateArgs",
"=",
"{",
"TranslateId",
":",
"'RangeDuration'",
",",
"MessageArgs",
":",
"messageArgs",
"}",
";",
"return",
";",
"}",
"var",
"diff",
"=",
"_",
".",
"difference",
"(",
"self",
".",
"ExcludedDaysDatePart",
",",
"self",
".",
"RangeDays",
")",
";",
"if",
"(",
"diff",
".",
"length",
"!=",
"0",
")",
"{",
"args",
".",
"HasError",
"=",
"true",
";",
"var",
"messageArgs2",
"=",
"{",
"ExcludedDates",
":",
"_",
".",
"reduce",
"(",
"diff",
",",
"function",
"(",
"memo",
",",
"item",
")",
"{",
"return",
"memo",
"+",
"item",
".",
"format",
"(",
"\"MM/DD/YYYY\"",
")",
";",
"}",
")",
"}",
";",
"args",
".",
"ErrorMessage",
"=",
"Utils",
".",
"StringFce",
".",
"format",
"(",
"\"Excluded days are not in range. '{ExcludedDates}'.\"",
",",
"messageArgs2",
")",
";",
"args",
".",
"TranslateArgs",
"=",
"{",
"TranslateId",
":",
"'ExcludedDaysMsg'",
",",
"MessageArgs",
":",
"messageArgs2",
"}",
";",
"return",
";",
"}",
"}"
]
| create validator function | [
"create",
"validator",
"function"
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/vacationApproval/node-business-rules.js#L368-L405 |
|
44,439 | rsamec/business-rules | dist/vacationApproval/node-business-rules.js | function (args) {
args.HasError = false;
args.ErrorMessage = "";
var greaterThanToday = new VacationApproval.FromToDateValidator();
greaterThanToday.FromOperator = 4 /* GreaterThanEqual */;
greaterThanToday.From = new Date();
greaterThanToday.ToOperator = 1 /* LessThanEqual */;
greaterThanToday.To = this.Duration.From;
greaterThanToday.IgnoreTime = true;
if (!greaterThanToday.isAcceptable(this.Approval.ApprovedDate)) {
args.HasError = true;
args.ErrorMessage = greaterThanToday.customMessage({
"Format": "MM/DD/YYYY",
"Msg": "Date must be between ('{From}' - '{To}')."
}, greaterThanToday);
args.TranslateArgs = { TranslateId: greaterThanToday.tagName, MessageArgs: greaterThanToday, CustomMessage: greaterThanToday.customMessage };
return;
}
} | javascript | function (args) {
args.HasError = false;
args.ErrorMessage = "";
var greaterThanToday = new VacationApproval.FromToDateValidator();
greaterThanToday.FromOperator = 4 /* GreaterThanEqual */;
greaterThanToday.From = new Date();
greaterThanToday.ToOperator = 1 /* LessThanEqual */;
greaterThanToday.To = this.Duration.From;
greaterThanToday.IgnoreTime = true;
if (!greaterThanToday.isAcceptable(this.Approval.ApprovedDate)) {
args.HasError = true;
args.ErrorMessage = greaterThanToday.customMessage({
"Format": "MM/DD/YYYY",
"Msg": "Date must be between ('{From}' - '{To}')."
}, greaterThanToday);
args.TranslateArgs = { TranslateId: greaterThanToday.tagName, MessageArgs: greaterThanToday, CustomMessage: greaterThanToday.customMessage };
return;
}
} | [
"function",
"(",
"args",
")",
"{",
"args",
".",
"HasError",
"=",
"false",
";",
"args",
".",
"ErrorMessage",
"=",
"\"\"",
";",
"var",
"greaterThanToday",
"=",
"new",
"VacationApproval",
".",
"FromToDateValidator",
"(",
")",
";",
"greaterThanToday",
".",
"FromOperator",
"=",
"4",
"/* GreaterThanEqual */",
";",
"greaterThanToday",
".",
"From",
"=",
"new",
"Date",
"(",
")",
";",
"greaterThanToday",
".",
"ToOperator",
"=",
"1",
"/* LessThanEqual */",
";",
"greaterThanToday",
".",
"To",
"=",
"this",
".",
"Duration",
".",
"From",
";",
"greaterThanToday",
".",
"IgnoreTime",
"=",
"true",
";",
"if",
"(",
"!",
"greaterThanToday",
".",
"isAcceptable",
"(",
"this",
".",
"Approval",
".",
"ApprovedDate",
")",
")",
"{",
"args",
".",
"HasError",
"=",
"true",
";",
"args",
".",
"ErrorMessage",
"=",
"greaterThanToday",
".",
"customMessage",
"(",
"{",
"\"Format\"",
":",
"\"MM/DD/YYYY\"",
",",
"\"Msg\"",
":",
"\"Date must be between ('{From}' - '{To}').\"",
"}",
",",
"greaterThanToday",
")",
";",
"args",
".",
"TranslateArgs",
"=",
"{",
"TranslateId",
":",
"greaterThanToday",
".",
"tagName",
",",
"MessageArgs",
":",
"greaterThanToday",
",",
"CustomMessage",
":",
"greaterThanToday",
".",
"customMessage",
"}",
";",
"return",
";",
"}",
"}"
]
| add custom validation | [
"add",
"custom",
"validation"
]
| 09be8a3764874fa2b020f0e6eae1241d0a9e94cc | https://github.com/rsamec/business-rules/blob/09be8a3764874fa2b020f0e6eae1241d0a9e94cc/dist/vacationApproval/node-business-rules.js#L517-L537 |
|
44,440 | rbackhouse/mpdjs | cordova/mpdjs/plugins/cordova-plugin-file/src/browser/FileProxy.js | onError | function onError (e) {
switch (e.target.errorCode) {
case 12:
console.log('Error - Attempt to open db with a lower version than the ' +
'current one.');
break;
default:
console.log('errorCode: ' + e.target.errorCode);
}
console.log(e, e.code, e.message);
} | javascript | function onError (e) {
switch (e.target.errorCode) {
case 12:
console.log('Error - Attempt to open db with a lower version than the ' +
'current one.');
break;
default:
console.log('errorCode: ' + e.target.errorCode);
}
console.log(e, e.code, e.message);
} | [
"function",
"onError",
"(",
"e",
")",
"{",
"switch",
"(",
"e",
".",
"target",
".",
"errorCode",
")",
"{",
"case",
"12",
":",
"console",
".",
"log",
"(",
"'Error - Attempt to open db with a lower version than the '",
"+",
"'current one.'",
")",
";",
"break",
";",
"default",
":",
"console",
".",
"log",
"(",
"'errorCode: '",
"+",
"e",
".",
"target",
".",
"errorCode",
")",
";",
"}",
"console",
".",
"log",
"(",
"e",
",",
"e",
".",
"code",
",",
"e",
".",
"message",
")",
";",
"}"
]
| Global error handler. Errors bubble from request, to transaction, to db. | [
"Global",
"error",
"handler",
".",
"Errors",
"bubble",
"from",
"request",
"to",
"transaction",
"to",
"db",
"."
]
| 23fde33a7a24ba8d516c623643e359a25a46259c | https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/plugins/cordova-plugin-file/src/browser/FileProxy.js#L968-L979 |
44,441 | Deathspike/npm-build-tools | src/embed.js | embed | function embed(sourcePath, relativePaths, name, done) {
var items = '';
each(relativePaths, function(relativePath, next) {
var fullPath = path.join(sourcePath, relativePath);
fs.readFile(fullPath, 'utf8', function(err, text) {
if (err) return next(err);
items += ' $templateCache.put(\'' +
inline(relativePath) + '\', \'' +
inline(text.trim()) + '\');\n';
next();
});
}, function(err) {
if (err) return done(err);
console.log(
'angular.module(\'' + inline(name) + '\', []).run([\'$templateCache\', function($templateCache) {\n' +
items +
'}]);');
done();
});
} | javascript | function embed(sourcePath, relativePaths, name, done) {
var items = '';
each(relativePaths, function(relativePath, next) {
var fullPath = path.join(sourcePath, relativePath);
fs.readFile(fullPath, 'utf8', function(err, text) {
if (err) return next(err);
items += ' $templateCache.put(\'' +
inline(relativePath) + '\', \'' +
inline(text.trim()) + '\');\n';
next();
});
}, function(err) {
if (err) return done(err);
console.log(
'angular.module(\'' + inline(name) + '\', []).run([\'$templateCache\', function($templateCache) {\n' +
items +
'}]);');
done();
});
} | [
"function",
"embed",
"(",
"sourcePath",
",",
"relativePaths",
",",
"name",
",",
"done",
")",
"{",
"var",
"items",
"=",
"''",
";",
"each",
"(",
"relativePaths",
",",
"function",
"(",
"relativePath",
",",
"next",
")",
"{",
"var",
"fullPath",
"=",
"path",
".",
"join",
"(",
"sourcePath",
",",
"relativePath",
")",
";",
"fs",
".",
"readFile",
"(",
"fullPath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"text",
")",
"{",
"if",
"(",
"err",
")",
"return",
"next",
"(",
"err",
")",
";",
"items",
"+=",
"' $templateCache.put(\\''",
"+",
"inline",
"(",
"relativePath",
")",
"+",
"'\\', \\''",
"+",
"inline",
"(",
"text",
".",
"trim",
"(",
")",
")",
"+",
"'\\');\\n'",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"'angular.module(\\''",
"+",
"inline",
"(",
"name",
")",
"+",
"'\\', []).run([\\'$templateCache\\', function($templateCache) {\\n'",
"+",
"items",
"+",
"'}]);'",
")",
";",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Embed the relative paths in an angular-specific template wrapper.
@param {string} sourcePath
@param {Array.<string>} relativePaths
@param {string} name
@param {function(Error=)} done | [
"Embed",
"the",
"relative",
"paths",
"in",
"an",
"angular",
"-",
"specific",
"template",
"wrapper",
"."
]
| caf2a0933b5900e34dc093f34b070a5b947cce39 | https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/embed.js#L36-L55 |
44,442 | Deathspike/npm-build-tools | src/embed.js | inline | function inline(text) {
var result = '';
for (var i = 0; i < text.length; i += 1) {
var value = text.charAt(i);
if (value === '\'') result += '\\\'';
else if (value === '\\') result += '\\\\';
else if (value === '\b') result += '\\b';
else if (value === '\f') result += '\\f';
else if (value === '\n') result += '\\n';
else if (value === '\r') result += '\\r';
else if (value === '\t') result += '\\t';
else result += value;
}
return result;
} | javascript | function inline(text) {
var result = '';
for (var i = 0; i < text.length; i += 1) {
var value = text.charAt(i);
if (value === '\'') result += '\\\'';
else if (value === '\\') result += '\\\\';
else if (value === '\b') result += '\\b';
else if (value === '\f') result += '\\f';
else if (value === '\n') result += '\\n';
else if (value === '\r') result += '\\r';
else if (value === '\t') result += '\\t';
else result += value;
}
return result;
} | [
"function",
"inline",
"(",
"text",
")",
"{",
"var",
"result",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"text",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"var",
"value",
"=",
"text",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"value",
"===",
"'\\''",
")",
"result",
"+=",
"'\\\\\\''",
";",
"else",
"if",
"(",
"value",
"===",
"'\\\\'",
")",
"result",
"+=",
"'\\\\\\\\'",
";",
"else",
"if",
"(",
"value",
"===",
"'\\b'",
")",
"result",
"+=",
"'\\\\b'",
";",
"else",
"if",
"(",
"value",
"===",
"'\\f'",
")",
"result",
"+=",
"'\\\\f'",
";",
"else",
"if",
"(",
"value",
"===",
"'\\n'",
")",
"result",
"+=",
"'\\\\n'",
";",
"else",
"if",
"(",
"value",
"===",
"'\\r'",
")",
"result",
"+=",
"'\\\\r'",
";",
"else",
"if",
"(",
"value",
"===",
"'\\t'",
")",
"result",
"+=",
"'\\\\t'",
";",
"else",
"result",
"+=",
"value",
";",
"}",
"return",
"result",
";",
"}"
]
| Escapes for inline embedding.
@param {string} text
@returns {string} | [
"Escapes",
"for",
"inline",
"embedding",
"."
]
| caf2a0933b5900e34dc093f34b070a5b947cce39 | https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/embed.js#L62-L76 |
44,443 | raineorshine/generator-yoga | app/index.js | parseArray | function parseArray(str) {
return R.filter(R.identity, str.split(',').map(R.invoker(0, 'trim')))
} | javascript | function parseArray(str) {
return R.filter(R.identity, str.split(',').map(R.invoker(0, 'trim')))
} | [
"function",
"parseArray",
"(",
"str",
")",
"{",
"return",
"R",
".",
"filter",
"(",
"R",
".",
"identity",
",",
"str",
".",
"split",
"(",
"','",
")",
".",
"map",
"(",
"R",
".",
"invoker",
"(",
"0",
",",
"'trim'",
")",
")",
")",
"}"
]
| parse an array from a string | [
"parse",
"an",
"array",
"from",
"a",
"string"
]
| 26b133ee29a8a690e208efcabbeac28fde4e93a4 | https://github.com/raineorshine/generator-yoga/blob/26b133ee29a8a690e208efcabbeac28fde4e93a4/app/index.js#L16-L18 |
44,444 | raineorshine/generator-yoga | app/index.js | stringifyIndented | function stringifyIndented(value, chr, n) {
return indent(JSON.stringify(value, null, n), chr, n).slice(chr.length * n)
} | javascript | function stringifyIndented(value, chr, n) {
return indent(JSON.stringify(value, null, n), chr, n).slice(chr.length * n)
} | [
"function",
"stringifyIndented",
"(",
"value",
",",
"chr",
",",
"n",
")",
"{",
"return",
"indent",
"(",
"JSON",
".",
"stringify",
"(",
"value",
",",
"null",
",",
"n",
")",
",",
"chr",
",",
"n",
")",
".",
"slice",
"(",
"chr",
".",
"length",
"*",
"n",
")",
"}"
]
| stringify an object and indent everything after the opening line | [
"stringify",
"an",
"object",
"and",
"indent",
"everything",
"after",
"the",
"opening",
"line"
]
| 26b133ee29a8a690e208efcabbeac28fde4e93a4 | https://github.com/raineorshine/generator-yoga/blob/26b133ee29a8a690e208efcabbeac28fde4e93a4/app/index.js#L21-L23 |
44,445 | raineorshine/generator-yoga | app/index.js | function () {
var done = this.async();
if(this.createMode) {
// copy yoga-generator itself
this.fs.copy(path.join(__dirname, '../'), this.destinationPath(), {
globOptions: {
dot: true,
ignore: [
'**/.DS_Store',
'**/.git',
'**/.git/**/*',
'**/node_modules',
'**/node_modules/**/*',
'**/test/**/*',
'**/create/**/*'
]
}
})
// copy the package.json and README
this.fs.copyTpl(path.join(__dirname, '../create/{}package.json'), this.destinationPath('package.json'), this.viewData)
this.fs.copyTpl(path.join(__dirname, '../create/README.md'), this.destinationPath('README.md'), this.viewData)
done()
}
else {
this.registerTransformStream(striate(this.viewData))
prefixnote.parseFiles(this.templatePath(), this.viewData)
// copy each file that is traversed
.on('data', function (file) {
var filename = path.basename(file.original)
// always ignore files like .DS_Store
if(ignore.indexOf(filename) === -1) {
var from = file.original
var to = this.destinationPath(path.relative(this.templatePath(), file.parsed))
// copy the file with templating
this.fs.copyTpl(from, to, this.viewData)
}
}.bind(this))
.on('end', done)
.on('error', done)
}
} | javascript | function () {
var done = this.async();
if(this.createMode) {
// copy yoga-generator itself
this.fs.copy(path.join(__dirname, '../'), this.destinationPath(), {
globOptions: {
dot: true,
ignore: [
'**/.DS_Store',
'**/.git',
'**/.git/**/*',
'**/node_modules',
'**/node_modules/**/*',
'**/test/**/*',
'**/create/**/*'
]
}
})
// copy the package.json and README
this.fs.copyTpl(path.join(__dirname, '../create/{}package.json'), this.destinationPath('package.json'), this.viewData)
this.fs.copyTpl(path.join(__dirname, '../create/README.md'), this.destinationPath('README.md'), this.viewData)
done()
}
else {
this.registerTransformStream(striate(this.viewData))
prefixnote.parseFiles(this.templatePath(), this.viewData)
// copy each file that is traversed
.on('data', function (file) {
var filename = path.basename(file.original)
// always ignore files like .DS_Store
if(ignore.indexOf(filename) === -1) {
var from = file.original
var to = this.destinationPath(path.relative(this.templatePath(), file.parsed))
// copy the file with templating
this.fs.copyTpl(from, to, this.viewData)
}
}.bind(this))
.on('end', done)
.on('error', done)
}
} | [
"function",
"(",
")",
"{",
"var",
"done",
"=",
"this",
".",
"async",
"(",
")",
";",
"if",
"(",
"this",
".",
"createMode",
")",
"{",
"// copy yoga-generator itself",
"this",
".",
"fs",
".",
"copy",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"'../'",
")",
",",
"this",
".",
"destinationPath",
"(",
")",
",",
"{",
"globOptions",
":",
"{",
"dot",
":",
"true",
",",
"ignore",
":",
"[",
"'**/.DS_Store'",
",",
"'**/.git'",
",",
"'**/.git/**/*'",
",",
"'**/node_modules'",
",",
"'**/node_modules/**/*'",
",",
"'**/test/**/*'",
",",
"'**/create/**/*'",
"]",
"}",
"}",
")",
"// copy the package.json and README",
"this",
".",
"fs",
".",
"copyTpl",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"'../create/{}package.json'",
")",
",",
"this",
".",
"destinationPath",
"(",
"'package.json'",
")",
",",
"this",
".",
"viewData",
")",
"this",
".",
"fs",
".",
"copyTpl",
"(",
"path",
".",
"join",
"(",
"__dirname",
",",
"'../create/README.md'",
")",
",",
"this",
".",
"destinationPath",
"(",
"'README.md'",
")",
",",
"this",
".",
"viewData",
")",
"done",
"(",
")",
"}",
"else",
"{",
"this",
".",
"registerTransformStream",
"(",
"striate",
"(",
"this",
".",
"viewData",
")",
")",
"prefixnote",
".",
"parseFiles",
"(",
"this",
".",
"templatePath",
"(",
")",
",",
"this",
".",
"viewData",
")",
"// copy each file that is traversed",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"file",
")",
"{",
"var",
"filename",
"=",
"path",
".",
"basename",
"(",
"file",
".",
"original",
")",
"// always ignore files like .DS_Store",
"if",
"(",
"ignore",
".",
"indexOf",
"(",
"filename",
")",
"===",
"-",
"1",
")",
"{",
"var",
"from",
"=",
"file",
".",
"original",
"var",
"to",
"=",
"this",
".",
"destinationPath",
"(",
"path",
".",
"relative",
"(",
"this",
".",
"templatePath",
"(",
")",
",",
"file",
".",
"parsed",
")",
")",
"// copy the file with templating",
"this",
".",
"fs",
".",
"copyTpl",
"(",
"from",
",",
"to",
",",
"this",
".",
"viewData",
")",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"on",
"(",
"'end'",
",",
"done",
")",
".",
"on",
"(",
"'error'",
",",
"done",
")",
"}",
"}"
]
| Copies all files from the template directory to the destination path parsing filenames using prefixnote and running them through striate | [
"Copies",
"all",
"files",
"from",
"the",
"template",
"directory",
"to",
"the",
"destination",
"path",
"parsing",
"filenames",
"using",
"prefixnote",
"and",
"running",
"them",
"through",
"striate"
]
| 26b133ee29a8a690e208efcabbeac28fde4e93a4 | https://github.com/raineorshine/generator-yoga/blob/26b133ee29a8a690e208efcabbeac28fde4e93a4/app/index.js#L106-L157 |
|
44,446 | alexindigo/manifesto | manifesto.js | parseManifest | function parseManifest(manifest, docroot, callback)
{
var inCache = false
, lines = [];
// get manifest file data
fs.readFile(manifest, 'ascii', function(err, data)
{
var counter = 0;
if (err)
{
// to prevent sudden continuation
return callback(err);
}
cache[manifest] =
{
version: 0,
files: [],
manifest: data
};
lines = data.split('\n');
lines.forEach(function(line)
{
var match;
line = line.trim();
// empty lines
if (line.substr(0, 1) == '') return;
// skip comments
if (line.substr(0, 1) == '#') return;
// process control keywords
switch (line)
{
case 'CACHE MANIFEST':
case 'CACHE:':
inCache = true;
return;
break;
// TODO: Add proper support for fallbacks
case 'NETWORK:':
case 'FALLBACK:':
inCache = false;
return;
break;
}
// do nothing for network files
if (!inCache) return;
// check the file and setup monitoring
if (!line.match(/^http(s)?:\/\//))
{
addWatcher(docroot+line, watcher(manifest), function(added, mtime)
{
// undo counter
counter--;
if (!added)
{
// check if everything is done
if (counter == 0) callback();
return;
}
if (mtime > cache[manifest].version) cache[manifest].version = mtime;
cache[manifest].files.push(line);
// check if everything is done
if (counter == 0) callback();
});
// track inception
counter++;
}
});
});
} | javascript | function parseManifest(manifest, docroot, callback)
{
var inCache = false
, lines = [];
// get manifest file data
fs.readFile(manifest, 'ascii', function(err, data)
{
var counter = 0;
if (err)
{
// to prevent sudden continuation
return callback(err);
}
cache[manifest] =
{
version: 0,
files: [],
manifest: data
};
lines = data.split('\n');
lines.forEach(function(line)
{
var match;
line = line.trim();
// empty lines
if (line.substr(0, 1) == '') return;
// skip comments
if (line.substr(0, 1) == '#') return;
// process control keywords
switch (line)
{
case 'CACHE MANIFEST':
case 'CACHE:':
inCache = true;
return;
break;
// TODO: Add proper support for fallbacks
case 'NETWORK:':
case 'FALLBACK:':
inCache = false;
return;
break;
}
// do nothing for network files
if (!inCache) return;
// check the file and setup monitoring
if (!line.match(/^http(s)?:\/\//))
{
addWatcher(docroot+line, watcher(manifest), function(added, mtime)
{
// undo counter
counter--;
if (!added)
{
// check if everything is done
if (counter == 0) callback();
return;
}
if (mtime > cache[manifest].version) cache[manifest].version = mtime;
cache[manifest].files.push(line);
// check if everything is done
if (counter == 0) callback();
});
// track inception
counter++;
}
});
});
} | [
"function",
"parseManifest",
"(",
"manifest",
",",
"docroot",
",",
"callback",
")",
"{",
"var",
"inCache",
"=",
"false",
",",
"lines",
"=",
"[",
"]",
";",
"// get manifest file data",
"fs",
".",
"readFile",
"(",
"manifest",
",",
"'ascii'",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"var",
"counter",
"=",
"0",
";",
"if",
"(",
"err",
")",
"{",
"// to prevent sudden continuation",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"cache",
"[",
"manifest",
"]",
"=",
"{",
"version",
":",
"0",
",",
"files",
":",
"[",
"]",
",",
"manifest",
":",
"data",
"}",
";",
"lines",
"=",
"data",
".",
"split",
"(",
"'\\n'",
")",
";",
"lines",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"var",
"match",
";",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"// empty lines",
"if",
"(",
"line",
".",
"substr",
"(",
"0",
",",
"1",
")",
"==",
"''",
")",
"return",
";",
"// skip comments",
"if",
"(",
"line",
".",
"substr",
"(",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"return",
";",
"// process control keywords",
"switch",
"(",
"line",
")",
"{",
"case",
"'CACHE MANIFEST'",
":",
"case",
"'CACHE:'",
":",
"inCache",
"=",
"true",
";",
"return",
";",
"break",
";",
"// TODO: Add proper support for fallbacks",
"case",
"'NETWORK:'",
":",
"case",
"'FALLBACK:'",
":",
"inCache",
"=",
"false",
";",
"return",
";",
"break",
";",
"}",
"// do nothing for network files",
"if",
"(",
"!",
"inCache",
")",
"return",
";",
"// check the file and setup monitoring",
"if",
"(",
"!",
"line",
".",
"match",
"(",
"/",
"^http(s)?:\\/\\/",
"/",
")",
")",
"{",
"addWatcher",
"(",
"docroot",
"+",
"line",
",",
"watcher",
"(",
"manifest",
")",
",",
"function",
"(",
"added",
",",
"mtime",
")",
"{",
"// undo counter",
"counter",
"--",
";",
"if",
"(",
"!",
"added",
")",
"{",
"// check if everything is done",
"if",
"(",
"counter",
"==",
"0",
")",
"callback",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"mtime",
">",
"cache",
"[",
"manifest",
"]",
".",
"version",
")",
"cache",
"[",
"manifest",
"]",
".",
"version",
"=",
"mtime",
";",
"cache",
"[",
"manifest",
"]",
".",
"files",
".",
"push",
"(",
"line",
")",
";",
"// check if everything is done",
"if",
"(",
"counter",
"==",
"0",
")",
"callback",
"(",
")",
";",
"}",
")",
";",
"// track inception",
"counter",
"++",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
]
| strip cacheable items from the manifest file | [
"strip",
"cacheable",
"items",
"from",
"the",
"manifest",
"file"
]
| 5ec285d3ef6db35c7c5c017694665e4b0f4119c3 | https://github.com/alexindigo/manifesto/blob/5ec285d3ef6db35c7c5c017694665e4b0f4119c3/manifesto.js#L48-L134 |
44,447 | alexindigo/manifesto | manifesto.js | addWatcher | function addWatcher(file, handler, callback)
{
fs.stat(file, function(err, stat)
{
if (err) return callback(false);
fs.watch(file, handler(file));
callback(true, stat.mtime.getTime());
});
} | javascript | function addWatcher(file, handler, callback)
{
fs.stat(file, function(err, stat)
{
if (err) return callback(false);
fs.watch(file, handler(file));
callback(true, stat.mtime.getTime());
});
} | [
"function",
"addWatcher",
"(",
"file",
",",
"handler",
",",
"callback",
")",
"{",
"fs",
".",
"stat",
"(",
"file",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"false",
")",
";",
"fs",
".",
"watch",
"(",
"file",
",",
"handler",
"(",
"file",
")",
")",
";",
"callback",
"(",
"true",
",",
"stat",
".",
"mtime",
".",
"getTime",
"(",
")",
")",
";",
"}",
")",
";",
"}"
]
| gets file's mtime and sets the watcher | [
"gets",
"file",
"s",
"mtime",
"and",
"sets",
"the",
"watcher"
]
| 5ec285d3ef6db35c7c5c017694665e4b0f4119c3 | https://github.com/alexindigo/manifesto/blob/5ec285d3ef6db35c7c5c017694665e4b0f4119c3/manifesto.js#L137-L147 |
44,448 | alexindigo/manifesto | manifesto.js | watcher | function watcher(manifest)
{
return function(file)
{
return function(event)
{
if (event == 'change')
{
fs.stat(file, function(err, stat)
{
if (err) return; // do nothing at this point
var mtime = stat.mtime.getTime();
if (cache[manifest].version < mtime) cache[manifest].version = mtime;
});
}
// TODO: add support for rename, maybe
};
}
} | javascript | function watcher(manifest)
{
return function(file)
{
return function(event)
{
if (event == 'change')
{
fs.stat(file, function(err, stat)
{
if (err) return; // do nothing at this point
var mtime = stat.mtime.getTime();
if (cache[manifest].version < mtime) cache[manifest].version = mtime;
});
}
// TODO: add support for rename, maybe
};
}
} | [
"function",
"watcher",
"(",
"manifest",
")",
"{",
"return",
"function",
"(",
"file",
")",
"{",
"return",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"event",
"==",
"'change'",
")",
"{",
"fs",
".",
"stat",
"(",
"file",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
")",
"return",
";",
"// do nothing at this point",
"var",
"mtime",
"=",
"stat",
".",
"mtime",
".",
"getTime",
"(",
")",
";",
"if",
"(",
"cache",
"[",
"manifest",
"]",
".",
"version",
"<",
"mtime",
")",
"cache",
"[",
"manifest",
"]",
".",
"version",
"=",
"mtime",
";",
"}",
")",
";",
"}",
"// TODO: add support for rename, maybe",
"}",
";",
"}",
"}"
]
| generates version watcher callback going total inception | [
"generates",
"version",
"watcher",
"callback",
"going",
"total",
"inception"
]
| 5ec285d3ef6db35c7c5c017694665e4b0f4119c3 | https://github.com/alexindigo/manifesto/blob/5ec285d3ef6db35c7c5c017694665e4b0f4119c3/manifesto.js#L151-L172 |
44,449 | sematext/spm-agent | lib/agent.js | Agent | function Agent (plugin) {
var events = require('events')
var util = require('util')
var eventEmitter = new events.EventEmitter()
var cluster = require('cluster')
var workerId = 0 + '-' + process.pid // 0 == Master, default
if (!cluster.isMaster) {
workerId = cluster.worker.id + '-' + process.pid
}
var agentSuperClass = {
plugin: plugin,
defaultType: 'njs',
defaultFilters: function () {
return [workerId || 0, process.pid || 0]
},
metricBuffer: [],
/**
* Adds a metric value and emits event to listeners on 'metric' or metric.name
* @param metric
*/
addMetrics: function (metric) {
metric.workerId = workerId
metric.pid = process.pid
if (!metric.sct) {
if (metric.name && /collectd/.test(metric.name)) {
metric.sct = 'OS'
} else {
metric.sct = 'APP'
}
}
if (!metric.ts) {
metric.ts = new Date().getTime()
}
if (!metric.type) {
metric.type = this.defaultType
}
if (!metric.filters && metric.type === 'njs') {
metric.filters = this.defaultFilters()
}
metric.spmLine = this.formatLine(metric)
this.emit('metric', metric)
if (metric.name) {
this.emit(metric.name, metric)
}
},
collectdFormatLine: function (metric) {
var now = (new Date().getTime()).toFixed(0)
var metricsTs = (metric.ts).toFixed(0)
var metricsTs2 = (metric.ts / 1000).toFixed(0)
var dateString = moment(metric.ts).format('YYYY-MM-DD')
var line = ''
if ((/collectd.*\-/.test(metric.name))) {
if (/collectd\-cpu/.test(metric.name) || /collectd\-io\-octets/.test(metric.name)) {
line = (now + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value)
} else if (/disk/.test(metric.name)) {
line = (now + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value.toFixed(6))
} else {
line = now + '\t' + metric.name + '\t' + metricsTs2 + ',' + metric.value
}
} else {
line = now + '\t' + metric.name + '\t' + metricsTs + ',' + metric.value
}
return line
},
defaultFormatLine: function (metric) {
var now = (new Date().getTime()).toFixed(0)
var line = null
if (metric.sct === 'OS') {
line = this.collectdFormatLine(metric)
} else {
line = util.format('%d\t%s\t%d\t%s\t%s', now, (metric.type || this.defaultType) + '-' + metric.name, metric.ts, formatArray(metric.filters), formatArray(metric.value))
logger.log(line)
}
return line
},
/**
* formats a line for SPM sender, if the plugin does not support this method the default formatter for nodejs and OP metrics is used
* @maram metric to format
*/
formatLine: function (metric) {
if (!this.plugin.formatLine) {
return this.defaultFormatLine(metric)
} else {
return this.plugin.formatLine(metric)
}
},
/**
* Starts the agent - typically thy create listeners or interval checks for metrics, and use 'addMetrics' to inform listeners
*/
start: function () {
if (this.plugin && this.plugin.start) {
// this is the place to register for external events that return metrics
this.plugin.start(this)
} else {
console.log('NOT called start')
}
},
/**
* Stops the plugin - timers could be pushed to plugins 'timers' Array, if timers exists it tries to clearInterval(timerId)
* if no timers are defined it tries to call stop method of the plugin
*/
stop: function () {
if (this.plugin.timers) {
this.plugin.timers.forEach(function (tid) {
clearInterval(tid)
})
} else {
if (this.plugin.stop) {
this.plugin.stop()
} else {
logger.warn('could not stop agent')
}
}
}
}
return util._extend(eventEmitter, agentSuperClass)
} | javascript | function Agent (plugin) {
var events = require('events')
var util = require('util')
var eventEmitter = new events.EventEmitter()
var cluster = require('cluster')
var workerId = 0 + '-' + process.pid // 0 == Master, default
if (!cluster.isMaster) {
workerId = cluster.worker.id + '-' + process.pid
}
var agentSuperClass = {
plugin: plugin,
defaultType: 'njs',
defaultFilters: function () {
return [workerId || 0, process.pid || 0]
},
metricBuffer: [],
/**
* Adds a metric value and emits event to listeners on 'metric' or metric.name
* @param metric
*/
addMetrics: function (metric) {
metric.workerId = workerId
metric.pid = process.pid
if (!metric.sct) {
if (metric.name && /collectd/.test(metric.name)) {
metric.sct = 'OS'
} else {
metric.sct = 'APP'
}
}
if (!metric.ts) {
metric.ts = new Date().getTime()
}
if (!metric.type) {
metric.type = this.defaultType
}
if (!metric.filters && metric.type === 'njs') {
metric.filters = this.defaultFilters()
}
metric.spmLine = this.formatLine(metric)
this.emit('metric', metric)
if (metric.name) {
this.emit(metric.name, metric)
}
},
collectdFormatLine: function (metric) {
var now = (new Date().getTime()).toFixed(0)
var metricsTs = (metric.ts).toFixed(0)
var metricsTs2 = (metric.ts / 1000).toFixed(0)
var dateString = moment(metric.ts).format('YYYY-MM-DD')
var line = ''
if ((/collectd.*\-/.test(metric.name))) {
if (/collectd\-cpu/.test(metric.name) || /collectd\-io\-octets/.test(metric.name)) {
line = (now + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value)
} else if (/disk/.test(metric.name)) {
line = (now + '\t' + metric.name + '-' + dateString + ',' + metricsTs2 + ',' + metric.value.toFixed(6))
} else {
line = now + '\t' + metric.name + '\t' + metricsTs2 + ',' + metric.value
}
} else {
line = now + '\t' + metric.name + '\t' + metricsTs + ',' + metric.value
}
return line
},
defaultFormatLine: function (metric) {
var now = (new Date().getTime()).toFixed(0)
var line = null
if (metric.sct === 'OS') {
line = this.collectdFormatLine(metric)
} else {
line = util.format('%d\t%s\t%d\t%s\t%s', now, (metric.type || this.defaultType) + '-' + metric.name, metric.ts, formatArray(metric.filters), formatArray(metric.value))
logger.log(line)
}
return line
},
/**
* formats a line for SPM sender, if the plugin does not support this method the default formatter for nodejs and OP metrics is used
* @maram metric to format
*/
formatLine: function (metric) {
if (!this.plugin.formatLine) {
return this.defaultFormatLine(metric)
} else {
return this.plugin.formatLine(metric)
}
},
/**
* Starts the agent - typically thy create listeners or interval checks for metrics, and use 'addMetrics' to inform listeners
*/
start: function () {
if (this.plugin && this.plugin.start) {
// this is the place to register for external events that return metrics
this.plugin.start(this)
} else {
console.log('NOT called start')
}
},
/**
* Stops the plugin - timers could be pushed to plugins 'timers' Array, if timers exists it tries to clearInterval(timerId)
* if no timers are defined it tries to call stop method of the plugin
*/
stop: function () {
if (this.plugin.timers) {
this.plugin.timers.forEach(function (tid) {
clearInterval(tid)
})
} else {
if (this.plugin.stop) {
this.plugin.stop()
} else {
logger.warn('could not stop agent')
}
}
}
}
return util._extend(eventEmitter, agentSuperClass)
} | [
"function",
"Agent",
"(",
"plugin",
")",
"{",
"var",
"events",
"=",
"require",
"(",
"'events'",
")",
"var",
"util",
"=",
"require",
"(",
"'util'",
")",
"var",
"eventEmitter",
"=",
"new",
"events",
".",
"EventEmitter",
"(",
")",
"var",
"cluster",
"=",
"require",
"(",
"'cluster'",
")",
"var",
"workerId",
"=",
"0",
"+",
"'-'",
"+",
"process",
".",
"pid",
"// 0 == Master, default",
"if",
"(",
"!",
"cluster",
".",
"isMaster",
")",
"{",
"workerId",
"=",
"cluster",
".",
"worker",
".",
"id",
"+",
"'-'",
"+",
"process",
".",
"pid",
"}",
"var",
"agentSuperClass",
"=",
"{",
"plugin",
":",
"plugin",
",",
"defaultType",
":",
"'njs'",
",",
"defaultFilters",
":",
"function",
"(",
")",
"{",
"return",
"[",
"workerId",
"||",
"0",
",",
"process",
".",
"pid",
"||",
"0",
"]",
"}",
",",
"metricBuffer",
":",
"[",
"]",
",",
"/**\n * Adds a metric value and emits event to listeners on 'metric' or metric.name\n * @param metric\n */",
"addMetrics",
":",
"function",
"(",
"metric",
")",
"{",
"metric",
".",
"workerId",
"=",
"workerId",
"metric",
".",
"pid",
"=",
"process",
".",
"pid",
"if",
"(",
"!",
"metric",
".",
"sct",
")",
"{",
"if",
"(",
"metric",
".",
"name",
"&&",
"/",
"collectd",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
")",
"{",
"metric",
".",
"sct",
"=",
"'OS'",
"}",
"else",
"{",
"metric",
".",
"sct",
"=",
"'APP'",
"}",
"}",
"if",
"(",
"!",
"metric",
".",
"ts",
")",
"{",
"metric",
".",
"ts",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
"}",
"if",
"(",
"!",
"metric",
".",
"type",
")",
"{",
"metric",
".",
"type",
"=",
"this",
".",
"defaultType",
"}",
"if",
"(",
"!",
"metric",
".",
"filters",
"&&",
"metric",
".",
"type",
"===",
"'njs'",
")",
"{",
"metric",
".",
"filters",
"=",
"this",
".",
"defaultFilters",
"(",
")",
"}",
"metric",
".",
"spmLine",
"=",
"this",
".",
"formatLine",
"(",
"metric",
")",
"this",
".",
"emit",
"(",
"'metric'",
",",
"metric",
")",
"if",
"(",
"metric",
".",
"name",
")",
"{",
"this",
".",
"emit",
"(",
"metric",
".",
"name",
",",
"metric",
")",
"}",
"}",
",",
"collectdFormatLine",
":",
"function",
"(",
"metric",
")",
"{",
"var",
"now",
"=",
"(",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
")",
".",
"toFixed",
"(",
"0",
")",
"var",
"metricsTs",
"=",
"(",
"metric",
".",
"ts",
")",
".",
"toFixed",
"(",
"0",
")",
"var",
"metricsTs2",
"=",
"(",
"metric",
".",
"ts",
"/",
"1000",
")",
".",
"toFixed",
"(",
"0",
")",
"var",
"dateString",
"=",
"moment",
"(",
"metric",
".",
"ts",
")",
".",
"format",
"(",
"'YYYY-MM-DD'",
")",
"var",
"line",
"=",
"''",
"if",
"(",
"(",
"/",
"collectd.*\\-",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
")",
")",
"{",
"if",
"(",
"/",
"collectd\\-cpu",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
"||",
"/",
"collectd\\-io\\-octets",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
")",
"{",
"line",
"=",
"(",
"now",
"+",
"'\\t'",
"+",
"metric",
".",
"name",
"+",
"'-'",
"+",
"dateString",
"+",
"','",
"+",
"metricsTs2",
"+",
"','",
"+",
"metric",
".",
"value",
")",
"}",
"else",
"if",
"(",
"/",
"disk",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
")",
"{",
"line",
"=",
"(",
"now",
"+",
"'\\t'",
"+",
"metric",
".",
"name",
"+",
"'-'",
"+",
"dateString",
"+",
"','",
"+",
"metricsTs2",
"+",
"','",
"+",
"metric",
".",
"value",
".",
"toFixed",
"(",
"6",
")",
")",
"}",
"else",
"{",
"line",
"=",
"now",
"+",
"'\\t'",
"+",
"metric",
".",
"name",
"+",
"'\\t'",
"+",
"metricsTs2",
"+",
"','",
"+",
"metric",
".",
"value",
"}",
"}",
"else",
"{",
"line",
"=",
"now",
"+",
"'\\t'",
"+",
"metric",
".",
"name",
"+",
"'\\t'",
"+",
"metricsTs",
"+",
"','",
"+",
"metric",
".",
"value",
"}",
"return",
"line",
"}",
",",
"defaultFormatLine",
":",
"function",
"(",
"metric",
")",
"{",
"var",
"now",
"=",
"(",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
")",
".",
"toFixed",
"(",
"0",
")",
"var",
"line",
"=",
"null",
"if",
"(",
"metric",
".",
"sct",
"===",
"'OS'",
")",
"{",
"line",
"=",
"this",
".",
"collectdFormatLine",
"(",
"metric",
")",
"}",
"else",
"{",
"line",
"=",
"util",
".",
"format",
"(",
"'%d\\t%s\\t%d\\t%s\\t%s'",
",",
"now",
",",
"(",
"metric",
".",
"type",
"||",
"this",
".",
"defaultType",
")",
"+",
"'-'",
"+",
"metric",
".",
"name",
",",
"metric",
".",
"ts",
",",
"formatArray",
"(",
"metric",
".",
"filters",
")",
",",
"formatArray",
"(",
"metric",
".",
"value",
")",
")",
"logger",
".",
"log",
"(",
"line",
")",
"}",
"return",
"line",
"}",
",",
"/**\n * formats a line for SPM sender, if the plugin does not support this method the default formatter for nodejs and OP metrics is used\n * @maram metric to format\n */",
"formatLine",
":",
"function",
"(",
"metric",
")",
"{",
"if",
"(",
"!",
"this",
".",
"plugin",
".",
"formatLine",
")",
"{",
"return",
"this",
".",
"defaultFormatLine",
"(",
"metric",
")",
"}",
"else",
"{",
"return",
"this",
".",
"plugin",
".",
"formatLine",
"(",
"metric",
")",
"}",
"}",
",",
"/**\n * Starts the agent - typically thy create listeners or interval checks for metrics, and use 'addMetrics' to inform listeners\n */",
"start",
":",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"plugin",
"&&",
"this",
".",
"plugin",
".",
"start",
")",
"{",
"// this is the place to register for external events that return metrics",
"this",
".",
"plugin",
".",
"start",
"(",
"this",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'NOT called start'",
")",
"}",
"}",
",",
"/**\n * Stops the plugin - timers could be pushed to plugins 'timers' Array, if timers exists it tries to clearInterval(timerId)\n * if no timers are defined it tries to call stop method of the plugin\n */",
"stop",
":",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"plugin",
".",
"timers",
")",
"{",
"this",
".",
"plugin",
".",
"timers",
".",
"forEach",
"(",
"function",
"(",
"tid",
")",
"{",
"clearInterval",
"(",
"tid",
")",
"}",
")",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"plugin",
".",
"stop",
")",
"{",
"this",
".",
"plugin",
".",
"stop",
"(",
")",
"}",
"else",
"{",
"logger",
".",
"warn",
"(",
"'could not stop agent'",
")",
"}",
"}",
"}",
"}",
"return",
"util",
".",
"_extend",
"(",
"eventEmitter",
",",
"agentSuperClass",
")",
"}"
]
| Agent super class that provides an EventEmitter for 'metric' event.
In addition it fires for each added metric an event named by the property metric.name
@param {function} plugin - Function providing a plugin having start(agent) and stop method. The plugin can use agent.addMetric function.
@returns {function} an Agent having start,stop, addMetric function | [
"Agent",
"super",
"class",
"that",
"provides",
"an",
"EventEmitter",
"for",
"metric",
"event",
".",
"In",
"addition",
"it",
"fires",
"for",
"each",
"added",
"metric",
"an",
"event",
"named",
"by",
"the",
"property",
"metric",
".",
"name"
]
| 7b98be0cfc41fb7bf7f7c605e6602148570269a3 | https://github.com/sematext/spm-agent/blob/7b98be0cfc41fb7bf7f7c605e6602148570269a3/lib/agent.js#L29-L147 |
44,450 | sematext/spm-agent | lib/agent.js | function (metric) {
metric.workerId = workerId
metric.pid = process.pid
if (!metric.sct) {
if (metric.name && /collectd/.test(metric.name)) {
metric.sct = 'OS'
} else {
metric.sct = 'APP'
}
}
if (!metric.ts) {
metric.ts = new Date().getTime()
}
if (!metric.type) {
metric.type = this.defaultType
}
if (!metric.filters && metric.type === 'njs') {
metric.filters = this.defaultFilters()
}
metric.spmLine = this.formatLine(metric)
this.emit('metric', metric)
if (metric.name) {
this.emit(metric.name, metric)
}
} | javascript | function (metric) {
metric.workerId = workerId
metric.pid = process.pid
if (!metric.sct) {
if (metric.name && /collectd/.test(metric.name)) {
metric.sct = 'OS'
} else {
metric.sct = 'APP'
}
}
if (!metric.ts) {
metric.ts = new Date().getTime()
}
if (!metric.type) {
metric.type = this.defaultType
}
if (!metric.filters && metric.type === 'njs') {
metric.filters = this.defaultFilters()
}
metric.spmLine = this.formatLine(metric)
this.emit('metric', metric)
if (metric.name) {
this.emit(metric.name, metric)
}
} | [
"function",
"(",
"metric",
")",
"{",
"metric",
".",
"workerId",
"=",
"workerId",
"metric",
".",
"pid",
"=",
"process",
".",
"pid",
"if",
"(",
"!",
"metric",
".",
"sct",
")",
"{",
"if",
"(",
"metric",
".",
"name",
"&&",
"/",
"collectd",
"/",
".",
"test",
"(",
"metric",
".",
"name",
")",
")",
"{",
"metric",
".",
"sct",
"=",
"'OS'",
"}",
"else",
"{",
"metric",
".",
"sct",
"=",
"'APP'",
"}",
"}",
"if",
"(",
"!",
"metric",
".",
"ts",
")",
"{",
"metric",
".",
"ts",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
"}",
"if",
"(",
"!",
"metric",
".",
"type",
")",
"{",
"metric",
".",
"type",
"=",
"this",
".",
"defaultType",
"}",
"if",
"(",
"!",
"metric",
".",
"filters",
"&&",
"metric",
".",
"type",
"===",
"'njs'",
")",
"{",
"metric",
".",
"filters",
"=",
"this",
".",
"defaultFilters",
"(",
")",
"}",
"metric",
".",
"spmLine",
"=",
"this",
".",
"formatLine",
"(",
"metric",
")",
"this",
".",
"emit",
"(",
"'metric'",
",",
"metric",
")",
"if",
"(",
"metric",
".",
"name",
")",
"{",
"this",
".",
"emit",
"(",
"metric",
".",
"name",
",",
"metric",
")",
"}",
"}"
]
| Adds a metric value and emits event to listeners on 'metric' or metric.name
@param metric | [
"Adds",
"a",
"metric",
"value",
"and",
"emits",
"event",
"to",
"listeners",
"on",
"metric",
"or",
"metric",
".",
"name"
]
| 7b98be0cfc41fb7bf7f7c605e6602148570269a3 | https://github.com/sematext/spm-agent/blob/7b98be0cfc41fb7bf7f7c605e6602148570269a3/lib/agent.js#L49-L73 |
|
44,451 | reelyactive/barterer | lib/routes/whereis.js | redirect | function redirect(id, prefix, suffix, res) {
var validatedID = reelib.identifier.toIdentifierString(id);
if(validatedID && (validatedID !== id)) {
res.redirect(prefix + validatedID + suffix);
return true;
}
return false;
} | javascript | function redirect(id, prefix, suffix, res) {
var validatedID = reelib.identifier.toIdentifierString(id);
if(validatedID && (validatedID !== id)) {
res.redirect(prefix + validatedID + suffix);
return true;
}
return false;
} | [
"function",
"redirect",
"(",
"id",
",",
"prefix",
",",
"suffix",
",",
"res",
")",
"{",
"var",
"validatedID",
"=",
"reelib",
".",
"identifier",
".",
"toIdentifierString",
"(",
"id",
")",
";",
"if",
"(",
"validatedID",
"&&",
"(",
"validatedID",
"!==",
"id",
")",
")",
"{",
"res",
".",
"redirect",
"(",
"prefix",
"+",
"validatedID",
"+",
"suffix",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Redirect if required and return the status.
@param {String} id The given ID.
@param {String} prefix The prefix to the ID in the path.
@param {String} suffix The suffix to the ID in the path.
@param {Object} res The HTTP result.
@return {boolean} Redirection performed? | [
"Redirect",
"if",
"required",
"and",
"return",
"the",
"status",
"."
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/routes/whereis.js#L58-L67 |
44,452 | yamadapc/airbnb-scrapper | lib/index.js | main | function main(program) {
program || (program = { args: [] });
if(program.args.length === 0) {
program.outputHelp();
return process.exit(1);
}
return Promise
.map(program.args, _.partial(exports.downloadPosting, program))
.map(function(html) {
return cheerio.load(html);
})
.map(exports.extractInfo)
.then(_.partial(exports.outputInfo, program));
} | javascript | function main(program) {
program || (program = { args: [] });
if(program.args.length === 0) {
program.outputHelp();
return process.exit(1);
}
return Promise
.map(program.args, _.partial(exports.downloadPosting, program))
.map(function(html) {
return cheerio.load(html);
})
.map(exports.extractInfo)
.then(_.partial(exports.outputInfo, program));
} | [
"function",
"main",
"(",
"program",
")",
"{",
"program",
"||",
"(",
"program",
"=",
"{",
"args",
":",
"[",
"]",
"}",
")",
";",
"if",
"(",
"program",
".",
"args",
".",
"length",
"===",
"0",
")",
"{",
"program",
".",
"outputHelp",
"(",
")",
";",
"return",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"return",
"Promise",
".",
"map",
"(",
"program",
".",
"args",
",",
"_",
".",
"partial",
"(",
"exports",
".",
"downloadPosting",
",",
"program",
")",
")",
".",
"map",
"(",
"function",
"(",
"html",
")",
"{",
"return",
"cheerio",
".",
"load",
"(",
"html",
")",
";",
"}",
")",
".",
"map",
"(",
"exports",
".",
"extractInfo",
")",
".",
"then",
"(",
"_",
".",
"partial",
"(",
"exports",
".",
"outputInfo",
",",
"program",
")",
")",
";",
"}"
]
| Takes a `program` instance from the `commander` module and executes the `cli`
functionality.
@param {Object} program A `program` object from `commander`
@return {Promise} A promise to the execution's result | [
"Takes",
"a",
"program",
"instance",
"from",
"the",
"commander",
"module",
"and",
"executes",
"the",
"cli",
"functionality",
"."
]
| 7cf98ecb496e348f91568ceb5aca4cb57205ace5 | https://github.com/yamadapc/airbnb-scrapper/blob/7cf98ecb496e348f91568ceb5aca4cb57205ace5/lib/index.js#L26-L40 |
44,453 | alexindigo/mixly | append.js | mixAppend | function mixAppend(to)
{
var args = Array.prototype.slice.call(arguments)
, i = 0
;
// it will start with `1` – second argument
// leaving `to` out of the loop
while (++i < args.length)
{
copy(to, args[i]);
}
return to;
} | javascript | function mixAppend(to)
{
var args = Array.prototype.slice.call(arguments)
, i = 0
;
// it will start with `1` – second argument
// leaving `to` out of the loop
while (++i < args.length)
{
copy(to, args[i]);
}
return to;
} | [
"function",
"mixAppend",
"(",
"to",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
",",
"i",
"=",
"0",
";",
"// it will start with `1` – second argument",
"// leaving `to` out of the loop",
"while",
"(",
"++",
"i",
"<",
"args",
".",
"length",
")",
"{",
"copy",
"(",
"to",
",",
"args",
"[",
"i",
"]",
")",
";",
"}",
"return",
"to",
";",
"}"
]
| Merges objects into the first one
@param {object} to - object to merge into
@param {...object} from - object(s) to merge with
@returns {object} - mixed result object | [
"Merges",
"objects",
"into",
"the",
"first",
"one"
]
| 602081b28806dc46286da783fef4f3ba1ecbb199 | https://github.com/alexindigo/mixly/blob/602081b28806dc46286da783fef4f3ba1ecbb199/append.js#L13-L27 |
44,454 | weswigham/not.js | not.js | function(rec, key) {
return (function() {
if (typeof key === "symbol") {
return undefined;
}
if (key === scopeName) {
return scope;
}
if (key === indicator) {
return proxy;
}
if (key.slice(-1) === indicator) {
builder.pushSingleToken(key.slice(0,key.length-1));
var classproxy = makeProxy({
get: function(rec, key) {
if (typeof key === "symbol") {
return undefined;
}
builder.addClass(key);
return classproxy;
}
},
function(obj) {
builder.rewriteSingleTokenAttributes(obj);
return classproxy;
});
return classproxy;
} else if (key.slice(0,1) === indicator) {
builder.pushEndToken(key.slice(1));
return {
valueOf: function() {
if (shortcuts.hasOwnProperty(key)) {
var args = builder.dropLastToken();
shortcuts[key](builder, scope, args);
} else {
throw new Error('Attempted to call nonexistant shortcut');
}
return 0;
}
}
} else {
builder.pushStartToken(key);
var classproxy = makeProxy({
get: function(rec, nkey) {
if (typeof nkey === "symbol") {
return undefined;
}
if (nkey === 'valueOf') {
if (shortcuts.hasOwnProperty(key)) {
var args = builder.dropLastToken();
shortcuts[key](builder, scope, args);
} else {
throw new Error('Attempted to call nonexistant shortcut');
}
return function() {return 0};
}
builder.addClass(nkey);
return classproxy;
}
},
function(obj) {
builder.rewriteStartTokenAttributes(obj);
return classproxy;
});
return classproxy;
}
})();
} | javascript | function(rec, key) {
return (function() {
if (typeof key === "symbol") {
return undefined;
}
if (key === scopeName) {
return scope;
}
if (key === indicator) {
return proxy;
}
if (key.slice(-1) === indicator) {
builder.pushSingleToken(key.slice(0,key.length-1));
var classproxy = makeProxy({
get: function(rec, key) {
if (typeof key === "symbol") {
return undefined;
}
builder.addClass(key);
return classproxy;
}
},
function(obj) {
builder.rewriteSingleTokenAttributes(obj);
return classproxy;
});
return classproxy;
} else if (key.slice(0,1) === indicator) {
builder.pushEndToken(key.slice(1));
return {
valueOf: function() {
if (shortcuts.hasOwnProperty(key)) {
var args = builder.dropLastToken();
shortcuts[key](builder, scope, args);
} else {
throw new Error('Attempted to call nonexistant shortcut');
}
return 0;
}
}
} else {
builder.pushStartToken(key);
var classproxy = makeProxy({
get: function(rec, nkey) {
if (typeof nkey === "symbol") {
return undefined;
}
if (nkey === 'valueOf') {
if (shortcuts.hasOwnProperty(key)) {
var args = builder.dropLastToken();
shortcuts[key](builder, scope, args);
} else {
throw new Error('Attempted to call nonexistant shortcut');
}
return function() {return 0};
}
builder.addClass(nkey);
return classproxy;
}
},
function(obj) {
builder.rewriteStartTokenAttributes(obj);
return classproxy;
});
return classproxy;
}
})();
} | [
"function",
"(",
"rec",
",",
"key",
")",
"{",
"return",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"\"symbol\"",
")",
"{",
"return",
"undefined",
";",
"}",
"if",
"(",
"key",
"===",
"scopeName",
")",
"{",
"return",
"scope",
";",
"}",
"if",
"(",
"key",
"===",
"indicator",
")",
"{",
"return",
"proxy",
";",
"}",
"if",
"(",
"key",
".",
"slice",
"(",
"-",
"1",
")",
"===",
"indicator",
")",
"{",
"builder",
".",
"pushSingleToken",
"(",
"key",
".",
"slice",
"(",
"0",
",",
"key",
".",
"length",
"-",
"1",
")",
")",
";",
"var",
"classproxy",
"=",
"makeProxy",
"(",
"{",
"get",
":",
"function",
"(",
"rec",
",",
"key",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"\"symbol\"",
")",
"{",
"return",
"undefined",
";",
"}",
"builder",
".",
"addClass",
"(",
"key",
")",
";",
"return",
"classproxy",
";",
"}",
"}",
",",
"function",
"(",
"obj",
")",
"{",
"builder",
".",
"rewriteSingleTokenAttributes",
"(",
"obj",
")",
";",
"return",
"classproxy",
";",
"}",
")",
";",
"return",
"classproxy",
";",
"}",
"else",
"if",
"(",
"key",
".",
"slice",
"(",
"0",
",",
"1",
")",
"===",
"indicator",
")",
"{",
"builder",
".",
"pushEndToken",
"(",
"key",
".",
"slice",
"(",
"1",
")",
")",
";",
"return",
"{",
"valueOf",
":",
"function",
"(",
")",
"{",
"if",
"(",
"shortcuts",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"var",
"args",
"=",
"builder",
".",
"dropLastToken",
"(",
")",
";",
"shortcuts",
"[",
"key",
"]",
"(",
"builder",
",",
"scope",
",",
"args",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Attempted to call nonexistant shortcut'",
")",
";",
"}",
"return",
"0",
";",
"}",
"}",
"}",
"else",
"{",
"builder",
".",
"pushStartToken",
"(",
"key",
")",
";",
"var",
"classproxy",
"=",
"makeProxy",
"(",
"{",
"get",
":",
"function",
"(",
"rec",
",",
"nkey",
")",
"{",
"if",
"(",
"typeof",
"nkey",
"===",
"\"symbol\"",
")",
"{",
"return",
"undefined",
";",
"}",
"if",
"(",
"nkey",
"===",
"'valueOf'",
")",
"{",
"if",
"(",
"shortcuts",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"var",
"args",
"=",
"builder",
".",
"dropLastToken",
"(",
")",
";",
"shortcuts",
"[",
"key",
"]",
"(",
"builder",
",",
"scope",
",",
"args",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Attempted to call nonexistant shortcut'",
")",
";",
"}",
"return",
"function",
"(",
")",
"{",
"return",
"0",
"}",
";",
"}",
"builder",
".",
"addClass",
"(",
"nkey",
")",
";",
"return",
"classproxy",
";",
"}",
"}",
",",
"function",
"(",
"obj",
")",
"{",
"builder",
".",
"rewriteStartTokenAttributes",
"(",
"obj",
")",
";",
"return",
"classproxy",
";",
"}",
")",
";",
"return",
"classproxy",
";",
"}",
"}",
")",
"(",
")",
";",
"}"
]
| New version of the has-all-the-things trap | [
"New",
"version",
"of",
"the",
"has",
"-",
"all",
"-",
"the",
"-",
"things",
"trap"
]
| 58688349c9945e1d56ab2864e942c8f3e2e7cb55 | https://github.com/weswigham/not.js/blob/58688349c9945e1d56ab2864e942c8f3e2e7cb55/not.js#L264-L333 |
|
44,455 | weswigham/not.js | not.js | prepareFunc | function prepareFunc(func, builder, basepath) { //Prepare an implied function for repeated use
funcStringCache[func] = funcStringCache[func] || ('(function() { with (proxy(scope)) { return ('+func.toString()+')('+defaultScopeName+'); } })()');
return function(scope) {
var scope = scope || {};
var builder = builder || stringBuilder;
var proxy = jshtmlProxy(new builder(basepath));
var ret = eval(funcStringCache[func]);
if (ret && typeof(ret.then) === 'function') { //looks like a promise. Let's use it why don't we?
ret.proxy = proxy;
return ret;
}
return proxy.collect();
}
} | javascript | function prepareFunc(func, builder, basepath) { //Prepare an implied function for repeated use
funcStringCache[func] = funcStringCache[func] || ('(function() { with (proxy(scope)) { return ('+func.toString()+')('+defaultScopeName+'); } })()');
return function(scope) {
var scope = scope || {};
var builder = builder || stringBuilder;
var proxy = jshtmlProxy(new builder(basepath));
var ret = eval(funcStringCache[func]);
if (ret && typeof(ret.then) === 'function') { //looks like a promise. Let's use it why don't we?
ret.proxy = proxy;
return ret;
}
return proxy.collect();
}
} | [
"function",
"prepareFunc",
"(",
"func",
",",
"builder",
",",
"basepath",
")",
"{",
"//Prepare an implied function for repeated use",
"funcStringCache",
"[",
"func",
"]",
"=",
"funcStringCache",
"[",
"func",
"]",
"||",
"(",
"'(function() { with (proxy(scope)) { return ('",
"+",
"func",
".",
"toString",
"(",
")",
"+",
"')('",
"+",
"defaultScopeName",
"+",
"'); } })()'",
")",
";",
"return",
"function",
"(",
"scope",
")",
"{",
"var",
"scope",
"=",
"scope",
"||",
"{",
"}",
";",
"var",
"builder",
"=",
"builder",
"||",
"stringBuilder",
";",
"var",
"proxy",
"=",
"jshtmlProxy",
"(",
"new",
"builder",
"(",
"basepath",
")",
")",
";",
"var",
"ret",
"=",
"eval",
"(",
"funcStringCache",
"[",
"func",
"]",
")",
";",
"if",
"(",
"ret",
"&&",
"typeof",
"(",
"ret",
".",
"then",
")",
"===",
"'function'",
")",
"{",
"//looks like a promise. Let's use it why don't we?",
"ret",
".",
"proxy",
"=",
"proxy",
";",
"return",
"ret",
";",
"}",
"return",
"proxy",
".",
"collect",
"(",
")",
";",
"}",
"}"
]
| Cache stringified functions for implied usage | [
"Cache",
"stringified",
"functions",
"for",
"implied",
"usage"
]
| 58688349c9945e1d56ab2864e942c8f3e2e7cb55 | https://github.com/weswigham/not.js/blob/58688349c9945e1d56ab2864e942c8f3e2e7cb55/not.js#L358-L372 |
44,456 | alexindigo/mixly | chain.js | mixChain | function mixChain()
{
var args = Array.prototype.slice.call(arguments)
, i = args.length
;
while (--i > 0)
{
args[i-1].__proto__ = args[i];
}
return args[i];
} | javascript | function mixChain()
{
var args = Array.prototype.slice.call(arguments)
, i = args.length
;
while (--i > 0)
{
args[i-1].__proto__ = args[i];
}
return args[i];
} | [
"function",
"mixChain",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
",",
"i",
"=",
"args",
".",
"length",
";",
"while",
"(",
"--",
"i",
">",
"0",
")",
"{",
"args",
"[",
"i",
"-",
"1",
"]",
".",
"__proto__",
"=",
"args",
"[",
"i",
"]",
";",
"}",
"return",
"args",
"[",
"i",
"]",
";",
"}"
]
| Modifies prototype chain for the provided objects,
based on the order of the arguments
@param {...object} object - objects to be part of the prototype chain
@returns {object} - augmented object | [
"Modifies",
"prototype",
"chain",
"for",
"the",
"provided",
"objects",
"based",
"on",
"the",
"order",
"of",
"the",
"arguments"
]
| 602081b28806dc46286da783fef4f3ba1ecbb199 | https://github.com/alexindigo/mixly/blob/602081b28806dc46286da783fef4f3ba1ecbb199/chain.js#L11-L23 |
44,457 | Smile-SA/grunt-build-html | tasks/buildHtml.js | function (remoteUrl) {
if (remoteUrl.indexOf('http') !== 0) {
grunt.log.error('Something seems wrong with this remote url: ' + remoteUrl);
}
return remoteUrl.toLowerCase().replace('://', '@@').replace(/\?/g, '@');
} | javascript | function (remoteUrl) {
if (remoteUrl.indexOf('http') !== 0) {
grunt.log.error('Something seems wrong with this remote url: ' + remoteUrl);
}
return remoteUrl.toLowerCase().replace('://', '@@').replace(/\?/g, '@');
} | [
"function",
"(",
"remoteUrl",
")",
"{",
"if",
"(",
"remoteUrl",
".",
"indexOf",
"(",
"'http'",
")",
"!==",
"0",
")",
"{",
"grunt",
".",
"log",
".",
"error",
"(",
"'Something seems wrong with this remote url: '",
"+",
"remoteUrl",
")",
";",
"}",
"return",
"remoteUrl",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"'://'",
",",
"'@@'",
")",
".",
"replace",
"(",
"/",
"\\?",
"/",
"g",
",",
"'@'",
")",
";",
"}"
]
| Transform URL to cache key in order to dump its content
@param remoteUrl Remote content URL
@returns {string|*} URL as cache key | [
"Transform",
"URL",
"to",
"cache",
"key",
"in",
"order",
"to",
"dump",
"its",
"content"
]
| 6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e | https://github.com/Smile-SA/grunt-build-html/blob/6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e/tasks/buildHtml.js#L67-L72 |
|
44,458 | Smile-SA/grunt-build-html | tasks/buildHtml.js | function (tplUrl, data) {
if (urlPrefix) {
tplUrl = urlPrefix + tplUrl;
}
if (urlSuffix) {
tplUrl += urlSuffix;
}
var html = '';
debug(' retrieve remote content from ' + tplUrl);
var remoteFragmentKey = getTemplateCacheKeyFromRemoteUrl(tplUrl);
if (data && !data.cache) {
html = retrieveFromUrl(tplUrl, remoteFragmentKey, true);
} else {
if (!_.has(cache, remoteFragmentKey)) {
cache[remoteFragmentKey] = retrieveFromUrl(tplUrl, remoteFragmentKey, false);
debug(' stash content in memory');
} else {
debug(' get content from memory');
}
html = getTemplateFromCache(remoteFragmentKey);
}
return html;
} | javascript | function (tplUrl, data) {
if (urlPrefix) {
tplUrl = urlPrefix + tplUrl;
}
if (urlSuffix) {
tplUrl += urlSuffix;
}
var html = '';
debug(' retrieve remote content from ' + tplUrl);
var remoteFragmentKey = getTemplateCacheKeyFromRemoteUrl(tplUrl);
if (data && !data.cache) {
html = retrieveFromUrl(tplUrl, remoteFragmentKey, true);
} else {
if (!_.has(cache, remoteFragmentKey)) {
cache[remoteFragmentKey] = retrieveFromUrl(tplUrl, remoteFragmentKey, false);
debug(' stash content in memory');
} else {
debug(' get content from memory');
}
html = getTemplateFromCache(remoteFragmentKey);
}
return html;
} | [
"function",
"(",
"tplUrl",
",",
"data",
")",
"{",
"if",
"(",
"urlPrefix",
")",
"{",
"tplUrl",
"=",
"urlPrefix",
"+",
"tplUrl",
";",
"}",
"if",
"(",
"urlSuffix",
")",
"{",
"tplUrl",
"+=",
"urlSuffix",
";",
"}",
"var",
"html",
"=",
"''",
";",
"debug",
"(",
"' retrieve remote content from '",
"+",
"tplUrl",
")",
";",
"var",
"remoteFragmentKey",
"=",
"getTemplateCacheKeyFromRemoteUrl",
"(",
"tplUrl",
")",
";",
"if",
"(",
"data",
"&&",
"!",
"data",
".",
"cache",
")",
"{",
"html",
"=",
"retrieveFromUrl",
"(",
"tplUrl",
",",
"remoteFragmentKey",
",",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"_",
".",
"has",
"(",
"cache",
",",
"remoteFragmentKey",
")",
")",
"{",
"cache",
"[",
"remoteFragmentKey",
"]",
"=",
"retrieveFromUrl",
"(",
"tplUrl",
",",
"remoteFragmentKey",
",",
"false",
")",
";",
"debug",
"(",
"' stash content in memory'",
")",
";",
"}",
"else",
"{",
"debug",
"(",
"' get content from memory'",
")",
";",
"}",
"html",
"=",
"getTemplateFromCache",
"(",
"remoteFragmentKey",
")",
";",
"}",
"return",
"html",
";",
"}"
]
| Retrieve remote content method to be used in HTML files.
@param tplUrl
Remote content URL
@param data
Options
@returns {*} Remote content data | [
"Retrieve",
"remote",
"content",
"method",
"to",
"be",
"used",
"in",
"HTML",
"files",
"."
]
| 6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e | https://github.com/Smile-SA/grunt-build-html/blob/6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e/tasks/buildHtml.js#L90-L112 |
|
44,459 | Smile-SA/grunt-build-html | tasks/buildHtml.js | function (tplName, data, ignoreEvaluation) {
var files, templateData, html = '';
if (typeof data !== 'object') {
ignoreEvaluation = data;
data = {};
}
data = _.extend({}, options.data, data);
if (_.has(templates, tplName)) {
debug(' include ' + templates[tplName].filepath);
files = _.clone(this.files);
files.push(templates[tplName].filepath);
templateData = {
files: files
};
data.include = include.bind(templateData);
try {
if (ignoreEvaluation) {
html = templates[tplName].content;
} else {
html = _.template(templates[tplName].content, options.templateSettings)(data);
}
} catch (error) {
grunt.log.error(error.message);
backtrace(files);
}
} else {
grunt.log.writeln('Template "' + tplName + '" does not exists.');
backtrace(this.files);
}
return html;
} | javascript | function (tplName, data, ignoreEvaluation) {
var files, templateData, html = '';
if (typeof data !== 'object') {
ignoreEvaluation = data;
data = {};
}
data = _.extend({}, options.data, data);
if (_.has(templates, tplName)) {
debug(' include ' + templates[tplName].filepath);
files = _.clone(this.files);
files.push(templates[tplName].filepath);
templateData = {
files: files
};
data.include = include.bind(templateData);
try {
if (ignoreEvaluation) {
html = templates[tplName].content;
} else {
html = _.template(templates[tplName].content, options.templateSettings)(data);
}
} catch (error) {
grunt.log.error(error.message);
backtrace(files);
}
} else {
grunt.log.writeln('Template "' + tplName + '" does not exists.');
backtrace(this.files);
}
return html;
} | [
"function",
"(",
"tplName",
",",
"data",
",",
"ignoreEvaluation",
")",
"{",
"var",
"files",
",",
"templateData",
",",
"html",
"=",
"''",
";",
"if",
"(",
"typeof",
"data",
"!==",
"'object'",
")",
"{",
"ignoreEvaluation",
"=",
"data",
";",
"data",
"=",
"{",
"}",
";",
"}",
"data",
"=",
"_",
".",
"extend",
"(",
"{",
"}",
",",
"options",
".",
"data",
",",
"data",
")",
";",
"if",
"(",
"_",
".",
"has",
"(",
"templates",
",",
"tplName",
")",
")",
"{",
"debug",
"(",
"' include '",
"+",
"templates",
"[",
"tplName",
"]",
".",
"filepath",
")",
";",
"files",
"=",
"_",
".",
"clone",
"(",
"this",
".",
"files",
")",
";",
"files",
".",
"push",
"(",
"templates",
"[",
"tplName",
"]",
".",
"filepath",
")",
";",
"templateData",
"=",
"{",
"files",
":",
"files",
"}",
";",
"data",
".",
"include",
"=",
"include",
".",
"bind",
"(",
"templateData",
")",
";",
"try",
"{",
"if",
"(",
"ignoreEvaluation",
")",
"{",
"html",
"=",
"templates",
"[",
"tplName",
"]",
".",
"content",
";",
"}",
"else",
"{",
"html",
"=",
"_",
".",
"template",
"(",
"templates",
"[",
"tplName",
"]",
".",
"content",
",",
"options",
".",
"templateSettings",
")",
"(",
"data",
")",
";",
"}",
"}",
"catch",
"(",
"error",
")",
"{",
"grunt",
".",
"log",
".",
"error",
"(",
"error",
".",
"message",
")",
";",
"backtrace",
"(",
"files",
")",
";",
"}",
"}",
"else",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Template \"'",
"+",
"tplName",
"+",
"'\" does not exists.'",
")",
";",
"backtrace",
"(",
"this",
".",
"files",
")",
";",
"}",
"return",
"html",
";",
"}"
]
| Include method to be used in HTML files.
@param tplName Relative template path
@param data The data object used to populate the text.
@returns {string} Compiled template content | [
"Include",
"method",
"to",
"be",
"used",
"in",
"HTML",
"files",
"."
]
| 6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e | https://github.com/Smile-SA/grunt-build-html/blob/6fe1644ff6d08e0eada9482ae9dcdb0d4169ea2e/tasks/buildHtml.js#L120-L150 |
|
44,460 | Mogztter/opal-node-runtime | src/opal.js | const_lookup_nesting | function const_lookup_nesting(nesting, name) {
var i, ii, result, constant;
if (nesting.length === 0) return;
// If the nesting is not empty the constant is looked up in its elements
// and in order. The ancestors of those elements are ignored.
for (i = 0, ii = nesting.length; i < ii; i++) {
constant = nesting[i].$$const[name];
if (constant != null) return constant;
}
} | javascript | function const_lookup_nesting(nesting, name) {
var i, ii, result, constant;
if (nesting.length === 0) return;
// If the nesting is not empty the constant is looked up in its elements
// and in order. The ancestors of those elements are ignored.
for (i = 0, ii = nesting.length; i < ii; i++) {
constant = nesting[i].$$const[name];
if (constant != null) return constant;
}
} | [
"function",
"const_lookup_nesting",
"(",
"nesting",
",",
"name",
")",
"{",
"var",
"i",
",",
"ii",
",",
"result",
",",
"constant",
";",
"if",
"(",
"nesting",
".",
"length",
"===",
"0",
")",
"return",
";",
"// If the nesting is not empty the constant is looked up in its elements",
"// and in order. The ancestors of those elements are ignored.",
"for",
"(",
"i",
"=",
"0",
",",
"ii",
"=",
"nesting",
".",
"length",
";",
"i",
"<",
"ii",
";",
"i",
"++",
")",
"{",
"constant",
"=",
"nesting",
"[",
"i",
"]",
".",
"$$const",
"[",
"name",
"]",
";",
"if",
"(",
"constant",
"!=",
"null",
")",
"return",
"constant",
";",
"}",
"}"
]
| Walk up the nesting array looking for the constant | [
"Walk",
"up",
"the",
"nesting",
"array",
"looking",
"for",
"the",
"constant"
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L185-L196 |
44,461 | Mogztter/opal-node-runtime | src/opal.js | const_lookup_ancestors | function const_lookup_ancestors(cref, name) {
var i, ii, result, ancestors;
if (cref == null) return;
ancestors = Opal.ancestors(cref);
for (i = 0, ii = ancestors.length; i < ii; i++) {
if (ancestors[i].$$const && $hasOwn.call(ancestors[i].$$const, name)) {
return ancestors[i].$$const[name];
}
}
} | javascript | function const_lookup_ancestors(cref, name) {
var i, ii, result, ancestors;
if (cref == null) return;
ancestors = Opal.ancestors(cref);
for (i = 0, ii = ancestors.length; i < ii; i++) {
if (ancestors[i].$$const && $hasOwn.call(ancestors[i].$$const, name)) {
return ancestors[i].$$const[name];
}
}
} | [
"function",
"const_lookup_ancestors",
"(",
"cref",
",",
"name",
")",
"{",
"var",
"i",
",",
"ii",
",",
"result",
",",
"ancestors",
";",
"if",
"(",
"cref",
"==",
"null",
")",
"return",
";",
"ancestors",
"=",
"Opal",
".",
"ancestors",
"(",
"cref",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"ii",
"=",
"ancestors",
".",
"length",
";",
"i",
"<",
"ii",
";",
"i",
"++",
")",
"{",
"if",
"(",
"ancestors",
"[",
"i",
"]",
".",
"$$const",
"&&",
"$hasOwn",
".",
"call",
"(",
"ancestors",
"[",
"i",
"]",
".",
"$$const",
",",
"name",
")",
")",
"{",
"return",
"ancestors",
"[",
"i",
"]",
".",
"$$const",
"[",
"name",
"]",
";",
"}",
"}",
"}"
]
| Walk up the ancestors chain looking for the constant | [
"Walk",
"up",
"the",
"ancestors",
"chain",
"looking",
"for",
"the",
"constant"
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L199-L211 |
44,462 | Mogztter/opal-node-runtime | src/opal.js | create_dummy_iclass | function create_dummy_iclass(module) {
var iclass = {},
proto = module.$$prototype;
if (proto.hasOwnProperty('$$dummy')) {
proto = proto.$$define_methods_on;
}
var props = Object.getOwnPropertyNames(proto),
length = props.length, i;
for (i = 0; i < length; i++) {
var prop = props[i];
$defineProperty(iclass, prop, proto[prop]);
}
$defineProperty(iclass, '$$iclass', true);
$defineProperty(iclass, '$$module', module);
return iclass;
} | javascript | function create_dummy_iclass(module) {
var iclass = {},
proto = module.$$prototype;
if (proto.hasOwnProperty('$$dummy')) {
proto = proto.$$define_methods_on;
}
var props = Object.getOwnPropertyNames(proto),
length = props.length, i;
for (i = 0; i < length; i++) {
var prop = props[i];
$defineProperty(iclass, prop, proto[prop]);
}
$defineProperty(iclass, '$$iclass', true);
$defineProperty(iclass, '$$module', module);
return iclass;
} | [
"function",
"create_dummy_iclass",
"(",
"module",
")",
"{",
"var",
"iclass",
"=",
"{",
"}",
",",
"proto",
"=",
"module",
".",
"$$prototype",
";",
"if",
"(",
"proto",
".",
"hasOwnProperty",
"(",
"'$$dummy'",
")",
")",
"{",
"proto",
"=",
"proto",
".",
"$$define_methods_on",
";",
"}",
"var",
"props",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"proto",
")",
",",
"length",
"=",
"props",
".",
"length",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"var",
"prop",
"=",
"props",
"[",
"i",
"]",
";",
"$defineProperty",
"(",
"iclass",
",",
"prop",
",",
"proto",
"[",
"prop",
"]",
")",
";",
"}",
"$defineProperty",
"(",
"iclass",
",",
"'$$iclass'",
",",
"true",
")",
";",
"$defineProperty",
"(",
"iclass",
",",
"'$$module'",
",",
"module",
")",
";",
"return",
"iclass",
";",
"}"
]
| Dummy iclass doesn't receive updates when the module gets a new method. | [
"Dummy",
"iclass",
"doesn",
"t",
"receive",
"updates",
"when",
"the",
"module",
"gets",
"a",
"new",
"method",
"."
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L1092-L1112 |
44,463 | Mogztter/opal-node-runtime | src/opal.js | descending_factorial | function descending_factorial(from, how_many) {
var count = how_many >= 0 ? 1 : 0;
while (how_many) {
count *= from;
from--;
how_many--;
}
return count;
} | javascript | function descending_factorial(from, how_many) {
var count = how_many >= 0 ? 1 : 0;
while (how_many) {
count *= from;
from--;
how_many--;
}
return count;
} | [
"function",
"descending_factorial",
"(",
"from",
",",
"how_many",
")",
"{",
"var",
"count",
"=",
"how_many",
">=",
"0",
"?",
"1",
":",
"0",
";",
"while",
"(",
"how_many",
")",
"{",
"count",
"*=",
"from",
";",
"from",
"--",
";",
"how_many",
"--",
";",
"}",
"return",
"count",
";",
"}"
]
| Returns the product of from, from-1, ..., from - how_many + 1. | [
"Returns",
"the",
"product",
"of",
"from",
"from",
"-",
"1",
"...",
"from",
"-",
"how_many",
"+",
"1",
"."
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L13635-L13643 |
44,464 | Mogztter/opal-node-runtime | src/opal.js | cutNumber | function cutNumber() {
if (isFloat()) {
var numerator = parseFloat(cutFloat());
if (str[0] === '/') {
// rational real part
str = str.slice(1);
if (isFloat()) {
var denominator = parseFloat(cutFloat());
return self.$Rational(numerator, denominator);
} else {
// reverting '/'
str = '/' + str;
return numerator;
}
} else {
// float real part, no denominator
return numerator;
}
} else {
return null;
}
} | javascript | function cutNumber() {
if (isFloat()) {
var numerator = parseFloat(cutFloat());
if (str[0] === '/') {
// rational real part
str = str.slice(1);
if (isFloat()) {
var denominator = parseFloat(cutFloat());
return self.$Rational(numerator, denominator);
} else {
// reverting '/'
str = '/' + str;
return numerator;
}
} else {
// float real part, no denominator
return numerator;
}
} else {
return null;
}
} | [
"function",
"cutNumber",
"(",
")",
"{",
"if",
"(",
"isFloat",
"(",
")",
")",
"{",
"var",
"numerator",
"=",
"parseFloat",
"(",
"cutFloat",
"(",
")",
")",
";",
"if",
"(",
"str",
"[",
"0",
"]",
"===",
"'/'",
")",
"{",
"// rational real part",
"str",
"=",
"str",
".",
"slice",
"(",
"1",
")",
";",
"if",
"(",
"isFloat",
"(",
")",
")",
"{",
"var",
"denominator",
"=",
"parseFloat",
"(",
"cutFloat",
"(",
")",
")",
";",
"return",
"self",
".",
"$Rational",
"(",
"numerator",
",",
"denominator",
")",
";",
"}",
"else",
"{",
"// reverting '/'",
"str",
"=",
"'/'",
"+",
"str",
";",
"return",
"numerator",
";",
"}",
"}",
"else",
"{",
"// float real part, no denominator",
"return",
"numerator",
";",
"}",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
]
| handles both floats and rationals | [
"handles",
"both",
"floats",
"and",
"rationals"
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L19882-L19905 |
44,465 | Mogztter/opal-node-runtime | src/opal.js | genrand_real | function genrand_real(mt) {
/* mt must be initialized */
var a = genrand_int32(mt), b = genrand_int32(mt);
return int_pair_to_real_exclusive(a, b);
} | javascript | function genrand_real(mt) {
/* mt must be initialized */
var a = genrand_int32(mt), b = genrand_int32(mt);
return int_pair_to_real_exclusive(a, b);
} | [
"function",
"genrand_real",
"(",
"mt",
")",
"{",
"/* mt must be initialized */",
"var",
"a",
"=",
"genrand_int32",
"(",
"mt",
")",
",",
"b",
"=",
"genrand_int32",
"(",
"mt",
")",
";",
"return",
"int_pair_to_real_exclusive",
"(",
"a",
",",
"b",
")",
";",
"}"
]
| generates a random number on [0,1) with 53-bit resolution | [
"generates",
"a",
"random",
"number",
"on",
"[",
"0",
"1",
")",
"with",
"53",
"-",
"bit",
"resolution"
]
| cde4c78099358ef47cc30b41f699ee56ff40d5e3 | https://github.com/Mogztter/opal-node-runtime/blob/cde4c78099358ef47cc30b41f699ee56ff40d5e3/src/opal.js#L22784-L22788 |
44,466 | thlorenz/browserify-swap | index.js | browserifySwap | function browserifySwap(file) {
var env = process.env.BROWSERIFYSWAP_ENV
, data = ''
, swapFile;
// no stubbing desired or we already determined that we can't find a swap config => just pipe it through
if (!env || cachedConfig === -1) return through();
if (cachedConfig) {
swapFile = swap(cachedConfig, env, file);
// early exit if we have config cached already and know we won't replace anything anyways
return swapFile ? through(write, end) : through();
} else {
return through(write, end)
}
function write(d, enc, cb) { data += d; cb(); }
function end(cb) {
/*jshint validthis:true */
var self = this;
// if config was cached we already resolved the swapFile if we got here
if (swapFile) {
swapFile = swapFile.replace(/\\/g, '/');
debug.inspect({ file: file, swapFile: swapFile });
self.push(requireSwap(swapFile));
return cb();
}
// we should only get here the very first time that this transform is invoked
resolveSwaps(root, function (err, config) {
if (config && config.packages) viralifyDeps(config.packages);
var swaps = config && config.swaps;
// signal with -1 that we already tried to resolve a swap config but didn't find any
cachedConfig = swaps || -1;
if (err) return cb(err);
debug.inspect({ swaps: swaps, env: env });
swapFile = swap(swaps, env, file);
debug.inspect({ file: file, swapFile: swapFile });
var src = swapFile ? requireSwap(swapFile.replace(/\\/g, '/')) : data;
self.push(src);
cb();
});
}
} | javascript | function browserifySwap(file) {
var env = process.env.BROWSERIFYSWAP_ENV
, data = ''
, swapFile;
// no stubbing desired or we already determined that we can't find a swap config => just pipe it through
if (!env || cachedConfig === -1) return through();
if (cachedConfig) {
swapFile = swap(cachedConfig, env, file);
// early exit if we have config cached already and know we won't replace anything anyways
return swapFile ? through(write, end) : through();
} else {
return through(write, end)
}
function write(d, enc, cb) { data += d; cb(); }
function end(cb) {
/*jshint validthis:true */
var self = this;
// if config was cached we already resolved the swapFile if we got here
if (swapFile) {
swapFile = swapFile.replace(/\\/g, '/');
debug.inspect({ file: file, swapFile: swapFile });
self.push(requireSwap(swapFile));
return cb();
}
// we should only get here the very first time that this transform is invoked
resolveSwaps(root, function (err, config) {
if (config && config.packages) viralifyDeps(config.packages);
var swaps = config && config.swaps;
// signal with -1 that we already tried to resolve a swap config but didn't find any
cachedConfig = swaps || -1;
if (err) return cb(err);
debug.inspect({ swaps: swaps, env: env });
swapFile = swap(swaps, env, file);
debug.inspect({ file: file, swapFile: swapFile });
var src = swapFile ? requireSwap(swapFile.replace(/\\/g, '/')) : data;
self.push(src);
cb();
});
}
} | [
"function",
"browserifySwap",
"(",
"file",
")",
"{",
"var",
"env",
"=",
"process",
".",
"env",
".",
"BROWSERIFYSWAP_ENV",
",",
"data",
"=",
"''",
",",
"swapFile",
";",
"// no stubbing desired or we already determined that we can't find a swap config => just pipe it through",
"if",
"(",
"!",
"env",
"||",
"cachedConfig",
"===",
"-",
"1",
")",
"return",
"through",
"(",
")",
";",
"if",
"(",
"cachedConfig",
")",
"{",
"swapFile",
"=",
"swap",
"(",
"cachedConfig",
",",
"env",
",",
"file",
")",
";",
"// early exit if we have config cached already and know we won't replace anything anyways",
"return",
"swapFile",
"?",
"through",
"(",
"write",
",",
"end",
")",
":",
"through",
"(",
")",
";",
"}",
"else",
"{",
"return",
"through",
"(",
"write",
",",
"end",
")",
"}",
"function",
"write",
"(",
"d",
",",
"enc",
",",
"cb",
")",
"{",
"data",
"+=",
"d",
";",
"cb",
"(",
")",
";",
"}",
"function",
"end",
"(",
"cb",
")",
"{",
"/*jshint validthis:true */",
"var",
"self",
"=",
"this",
";",
"// if config was cached we already resolved the swapFile if we got here",
"if",
"(",
"swapFile",
")",
"{",
"swapFile",
"=",
"swapFile",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"debug",
".",
"inspect",
"(",
"{",
"file",
":",
"file",
",",
"swapFile",
":",
"swapFile",
"}",
")",
";",
"self",
".",
"push",
"(",
"requireSwap",
"(",
"swapFile",
")",
")",
";",
"return",
"cb",
"(",
")",
";",
"}",
"// we should only get here the very first time that this transform is invoked",
"resolveSwaps",
"(",
"root",
",",
"function",
"(",
"err",
",",
"config",
")",
"{",
"if",
"(",
"config",
"&&",
"config",
".",
"packages",
")",
"viralifyDeps",
"(",
"config",
".",
"packages",
")",
";",
"var",
"swaps",
"=",
"config",
"&&",
"config",
".",
"swaps",
";",
"// signal with -1 that we already tried to resolve a swap config but didn't find any",
"cachedConfig",
"=",
"swaps",
"||",
"-",
"1",
";",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"debug",
".",
"inspect",
"(",
"{",
"swaps",
":",
"swaps",
",",
"env",
":",
"env",
"}",
")",
";",
"swapFile",
"=",
"swap",
"(",
"swaps",
",",
"env",
",",
"file",
")",
";",
"debug",
".",
"inspect",
"(",
"{",
"file",
":",
"file",
",",
"swapFile",
":",
"swapFile",
"}",
")",
";",
"var",
"src",
"=",
"swapFile",
"?",
"requireSwap",
"(",
"swapFile",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
")",
":",
"data",
";",
"self",
".",
"push",
"(",
"src",
")",
";",
"cb",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Looks up browserify_swap configuratios specified for the given file in the environment specified via `BROWSERIFYSWAP_ENV`.
If found the file content is replaced with a require statement to the file to swap in for the original.
Otherwise the file's content is just piped through.
@name browserifySwap
@function
@param {String} file full path to file being transformed
@return {TransformStream} transform stream into which `browserify` will pipe the original content of the file | [
"Looks",
"up",
"browserify_swap",
"configuratios",
"specified",
"for",
"the",
"given",
"file",
"in",
"the",
"environment",
"specified",
"via",
"BROWSERIFYSWAP_ENV",
"."
]
| 2a697cdaec59d2cb83244863616d92dc8eb14137 | https://github.com/thlorenz/browserify-swap/blob/2a697cdaec59d2cb83244863616d92dc8eb14137/index.js#L59-L108 |
44,467 | reelyactive/barterer | lib/responsehandler.js | prepareResponse | function prepareResponse(status, rootUrl, queryPath, data) {
var response = {};
prepareMeta(response, status);
if(rootUrl && queryPath) {
prepareLinks(response, rootUrl, queryPath);
}
if(data) {
prepareData(response, rootUrl, data);
}
return response;
} | javascript | function prepareResponse(status, rootUrl, queryPath, data) {
var response = {};
prepareMeta(response, status);
if(rootUrl && queryPath) {
prepareLinks(response, rootUrl, queryPath);
}
if(data) {
prepareData(response, rootUrl, data);
}
return response;
} | [
"function",
"prepareResponse",
"(",
"status",
",",
"rootUrl",
",",
"queryPath",
",",
"data",
")",
"{",
"var",
"response",
"=",
"{",
"}",
";",
"prepareMeta",
"(",
"response",
",",
"status",
")",
";",
"if",
"(",
"rootUrl",
"&&",
"queryPath",
")",
"{",
"prepareLinks",
"(",
"response",
",",
"rootUrl",
",",
"queryPath",
")",
";",
"}",
"if",
"(",
"data",
")",
"{",
"prepareData",
"(",
"response",
",",
"rootUrl",
",",
"data",
")",
";",
"}",
"return",
"response",
";",
"}"
]
| Prepares the JSON for an API query response which is successful
@param {Number} status Integer status code
@param {String} rootUrl The root URL of the original query.
@param {String} queryPath The query path of the original query.
@param {Object} data The data to include in the response | [
"Prepares",
"the",
"JSON",
"for",
"an",
"API",
"query",
"response",
"which",
"is",
"successful"
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/responsehandler.js#L26-L36 |
44,468 | reelyactive/barterer | lib/responsehandler.js | prepareMeta | function prepareMeta(response, status) {
switch(status) {
case CODE_OK:
response._meta = { "message": MESSAGE_OK,
"statusCode": CODE_OK };
break;
case CODE_NOTFOUND:
response._meta = { "message": MESSAGE_NOTFOUND,
"statusCode": CODE_NOTFOUND };
break;
case CODE_NOTIMPLEMENTED:
response._meta = { "message": MESSAGE_NOTIMPLEMENTED,
"statusCode": CODE_NOTIMPLEMENTED };
break;
case CODE_SERVICEUNAVAILABLE:
response._meta = { "message": MESSAGE_SERVICEUNAVAILABLE,
"statusCode": CODE_SERVICEUNAVAILABLE };
break;
default:
response._meta = { "message": MESSAGE_BADREQUEST,
"statusCode": CODE_BADREQUEST };
}
} | javascript | function prepareMeta(response, status) {
switch(status) {
case CODE_OK:
response._meta = { "message": MESSAGE_OK,
"statusCode": CODE_OK };
break;
case CODE_NOTFOUND:
response._meta = { "message": MESSAGE_NOTFOUND,
"statusCode": CODE_NOTFOUND };
break;
case CODE_NOTIMPLEMENTED:
response._meta = { "message": MESSAGE_NOTIMPLEMENTED,
"statusCode": CODE_NOTIMPLEMENTED };
break;
case CODE_SERVICEUNAVAILABLE:
response._meta = { "message": MESSAGE_SERVICEUNAVAILABLE,
"statusCode": CODE_SERVICEUNAVAILABLE };
break;
default:
response._meta = { "message": MESSAGE_BADREQUEST,
"statusCode": CODE_BADREQUEST };
}
} | [
"function",
"prepareMeta",
"(",
"response",
",",
"status",
")",
"{",
"switch",
"(",
"status",
")",
"{",
"case",
"CODE_OK",
":",
"response",
".",
"_meta",
"=",
"{",
"\"message\"",
":",
"MESSAGE_OK",
",",
"\"statusCode\"",
":",
"CODE_OK",
"}",
";",
"break",
";",
"case",
"CODE_NOTFOUND",
":",
"response",
".",
"_meta",
"=",
"{",
"\"message\"",
":",
"MESSAGE_NOTFOUND",
",",
"\"statusCode\"",
":",
"CODE_NOTFOUND",
"}",
";",
"break",
";",
"case",
"CODE_NOTIMPLEMENTED",
":",
"response",
".",
"_meta",
"=",
"{",
"\"message\"",
":",
"MESSAGE_NOTIMPLEMENTED",
",",
"\"statusCode\"",
":",
"CODE_NOTIMPLEMENTED",
"}",
";",
"break",
";",
"case",
"CODE_SERVICEUNAVAILABLE",
":",
"response",
".",
"_meta",
"=",
"{",
"\"message\"",
":",
"MESSAGE_SERVICEUNAVAILABLE",
",",
"\"statusCode\"",
":",
"CODE_SERVICEUNAVAILABLE",
"}",
";",
"break",
";",
"default",
":",
"response",
".",
"_meta",
"=",
"{",
"\"message\"",
":",
"MESSAGE_BADREQUEST",
",",
"\"statusCode\"",
":",
"CODE_BADREQUEST",
"}",
";",
"}",
"}"
]
| Prepares and adds the _meta to the given API query response
@param {Object} response JSON representation of the response
@param {Number} status Integer status code | [
"Prepares",
"and",
"adds",
"the",
"_meta",
"to",
"the",
"given",
"API",
"query",
"response"
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/responsehandler.js#L44-L66 |
44,469 | reelyactive/barterer | lib/responsehandler.js | prepareLinks | function prepareLinks(response, rootUrl, queryPath) {
var selfLink = { "href": rootUrl + queryPath };
response._links = {};
response._links.self = selfLink;
} | javascript | function prepareLinks(response, rootUrl, queryPath) {
var selfLink = { "href": rootUrl + queryPath };
response._links = {};
response._links.self = selfLink;
} | [
"function",
"prepareLinks",
"(",
"response",
",",
"rootUrl",
",",
"queryPath",
")",
"{",
"var",
"selfLink",
"=",
"{",
"\"href\"",
":",
"rootUrl",
"+",
"queryPath",
"}",
";",
"response",
".",
"_links",
"=",
"{",
"}",
";",
"response",
".",
"_links",
".",
"self",
"=",
"selfLink",
";",
"}"
]
| Prepares and adds the _links to the given API query response
@param {Object} response JSON representation of the response
@param {String} rootUrl The root URL of the original query.
@param {String} queryPath The query path of the original query. | [
"Prepares",
"and",
"adds",
"the",
"_links",
"to",
"the",
"given",
"API",
"query",
"response"
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/responsehandler.js#L75-L79 |
44,470 | watson/mode-s-aircraft-store | lib/cpr.js | cprModFunction | function cprModFunction (a, b) {
let res = a % b
if (res < 0) res += b
return res
} | javascript | function cprModFunction (a, b) {
let res = a % b
if (res < 0) res += b
return res
} | [
"function",
"cprModFunction",
"(",
"a",
",",
"b",
")",
"{",
"let",
"res",
"=",
"a",
"%",
"b",
"if",
"(",
"res",
"<",
"0",
")",
"res",
"+=",
"b",
"return",
"res",
"}"
]
| Always positive MOD operation, used for CPR decoding | [
"Always",
"positive",
"MOD",
"operation",
"used",
"for",
"CPR",
"decoding"
]
| c8ba99927d5cba1c8fbbf2b90f35cf076360299b | https://github.com/watson/mode-s-aircraft-store/blob/c8ba99927d5cba1c8fbbf2b90f35cf076360299b/lib/cpr.js#L59-L63 |
44,471 | watson/mode-s-aircraft-store | lib/cpr.js | cprNLFunction | function cprNLFunction (lat) {
if (lat < 0) lat = -lat // Table is simmetric about the equator
if (lat < 10.47047130) return 59
if (lat < 14.82817437) return 58
if (lat < 18.18626357) return 57
if (lat < 21.02939493) return 56
if (lat < 23.54504487) return 55
if (lat < 25.82924707) return 54
if (lat < 27.93898710) return 53
if (lat < 29.91135686) return 52
if (lat < 31.77209708) return 51
if (lat < 33.53993436) return 50
if (lat < 35.22899598) return 49
if (lat < 36.85025108) return 48
if (lat < 38.41241892) return 47
if (lat < 39.92256684) return 46
if (lat < 41.38651832) return 45
if (lat < 42.80914012) return 44
if (lat < 44.19454951) return 43
if (lat < 45.54626723) return 42
if (lat < 46.86733252) return 41
if (lat < 48.16039128) return 40
if (lat < 49.42776439) return 39
if (lat < 50.67150166) return 38
if (lat < 51.89342469) return 37
if (lat < 53.09516153) return 36
if (lat < 54.27817472) return 35
if (lat < 55.44378444) return 34
if (lat < 56.59318756) return 33
if (lat < 57.72747354) return 32
if (lat < 58.84763776) return 31
if (lat < 59.95459277) return 30
if (lat < 61.04917774) return 29
if (lat < 62.13216659) return 28
if (lat < 63.20427479) return 27
if (lat < 64.26616523) return 26
if (lat < 65.31845310) return 25
if (lat < 66.36171008) return 24
if (lat < 67.39646774) return 23
if (lat < 68.42322022) return 22
if (lat < 69.44242631) return 21
if (lat < 70.45451075) return 20
if (lat < 71.45986473) return 19
if (lat < 72.45884545) return 18
if (lat < 73.45177442) return 17
if (lat < 74.43893416) return 16
if (lat < 75.42056257) return 15
if (lat < 76.39684391) return 14
if (lat < 77.36789461) return 13
if (lat < 78.33374083) return 12
if (lat < 79.29428225) return 11
if (lat < 80.24923213) return 10
if (lat < 81.19801349) return 9
if (lat < 82.13956981) return 8
if (lat < 83.07199445) return 7
if (lat < 83.99173563) return 6
if (lat < 84.89166191) return 5
if (lat < 85.75541621) return 4
if (lat < 86.53536998) return 3
if (lat < 87.00000000) return 2
else return 1
} | javascript | function cprNLFunction (lat) {
if (lat < 0) lat = -lat // Table is simmetric about the equator
if (lat < 10.47047130) return 59
if (lat < 14.82817437) return 58
if (lat < 18.18626357) return 57
if (lat < 21.02939493) return 56
if (lat < 23.54504487) return 55
if (lat < 25.82924707) return 54
if (lat < 27.93898710) return 53
if (lat < 29.91135686) return 52
if (lat < 31.77209708) return 51
if (lat < 33.53993436) return 50
if (lat < 35.22899598) return 49
if (lat < 36.85025108) return 48
if (lat < 38.41241892) return 47
if (lat < 39.92256684) return 46
if (lat < 41.38651832) return 45
if (lat < 42.80914012) return 44
if (lat < 44.19454951) return 43
if (lat < 45.54626723) return 42
if (lat < 46.86733252) return 41
if (lat < 48.16039128) return 40
if (lat < 49.42776439) return 39
if (lat < 50.67150166) return 38
if (lat < 51.89342469) return 37
if (lat < 53.09516153) return 36
if (lat < 54.27817472) return 35
if (lat < 55.44378444) return 34
if (lat < 56.59318756) return 33
if (lat < 57.72747354) return 32
if (lat < 58.84763776) return 31
if (lat < 59.95459277) return 30
if (lat < 61.04917774) return 29
if (lat < 62.13216659) return 28
if (lat < 63.20427479) return 27
if (lat < 64.26616523) return 26
if (lat < 65.31845310) return 25
if (lat < 66.36171008) return 24
if (lat < 67.39646774) return 23
if (lat < 68.42322022) return 22
if (lat < 69.44242631) return 21
if (lat < 70.45451075) return 20
if (lat < 71.45986473) return 19
if (lat < 72.45884545) return 18
if (lat < 73.45177442) return 17
if (lat < 74.43893416) return 16
if (lat < 75.42056257) return 15
if (lat < 76.39684391) return 14
if (lat < 77.36789461) return 13
if (lat < 78.33374083) return 12
if (lat < 79.29428225) return 11
if (lat < 80.24923213) return 10
if (lat < 81.19801349) return 9
if (lat < 82.13956981) return 8
if (lat < 83.07199445) return 7
if (lat < 83.99173563) return 6
if (lat < 84.89166191) return 5
if (lat < 85.75541621) return 4
if (lat < 86.53536998) return 3
if (lat < 87.00000000) return 2
else return 1
} | [
"function",
"cprNLFunction",
"(",
"lat",
")",
"{",
"if",
"(",
"lat",
"<",
"0",
")",
"lat",
"=",
"-",
"lat",
"// Table is simmetric about the equator",
"if",
"(",
"lat",
"<",
"10.47047130",
")",
"return",
"59",
"if",
"(",
"lat",
"<",
"14.82817437",
")",
"return",
"58",
"if",
"(",
"lat",
"<",
"18.18626357",
")",
"return",
"57",
"if",
"(",
"lat",
"<",
"21.02939493",
")",
"return",
"56",
"if",
"(",
"lat",
"<",
"23.54504487",
")",
"return",
"55",
"if",
"(",
"lat",
"<",
"25.82924707",
")",
"return",
"54",
"if",
"(",
"lat",
"<",
"27.93898710",
")",
"return",
"53",
"if",
"(",
"lat",
"<",
"29.91135686",
")",
"return",
"52",
"if",
"(",
"lat",
"<",
"31.77209708",
")",
"return",
"51",
"if",
"(",
"lat",
"<",
"33.53993436",
")",
"return",
"50",
"if",
"(",
"lat",
"<",
"35.22899598",
")",
"return",
"49",
"if",
"(",
"lat",
"<",
"36.85025108",
")",
"return",
"48",
"if",
"(",
"lat",
"<",
"38.41241892",
")",
"return",
"47",
"if",
"(",
"lat",
"<",
"39.92256684",
")",
"return",
"46",
"if",
"(",
"lat",
"<",
"41.38651832",
")",
"return",
"45",
"if",
"(",
"lat",
"<",
"42.80914012",
")",
"return",
"44",
"if",
"(",
"lat",
"<",
"44.19454951",
")",
"return",
"43",
"if",
"(",
"lat",
"<",
"45.54626723",
")",
"return",
"42",
"if",
"(",
"lat",
"<",
"46.86733252",
")",
"return",
"41",
"if",
"(",
"lat",
"<",
"48.16039128",
")",
"return",
"40",
"if",
"(",
"lat",
"<",
"49.42776439",
")",
"return",
"39",
"if",
"(",
"lat",
"<",
"50.67150166",
")",
"return",
"38",
"if",
"(",
"lat",
"<",
"51.89342469",
")",
"return",
"37",
"if",
"(",
"lat",
"<",
"53.09516153",
")",
"return",
"36",
"if",
"(",
"lat",
"<",
"54.27817472",
")",
"return",
"35",
"if",
"(",
"lat",
"<",
"55.44378444",
")",
"return",
"34",
"if",
"(",
"lat",
"<",
"56.59318756",
")",
"return",
"33",
"if",
"(",
"lat",
"<",
"57.72747354",
")",
"return",
"32",
"if",
"(",
"lat",
"<",
"58.84763776",
")",
"return",
"31",
"if",
"(",
"lat",
"<",
"59.95459277",
")",
"return",
"30",
"if",
"(",
"lat",
"<",
"61.04917774",
")",
"return",
"29",
"if",
"(",
"lat",
"<",
"62.13216659",
")",
"return",
"28",
"if",
"(",
"lat",
"<",
"63.20427479",
")",
"return",
"27",
"if",
"(",
"lat",
"<",
"64.26616523",
")",
"return",
"26",
"if",
"(",
"lat",
"<",
"65.31845310",
")",
"return",
"25",
"if",
"(",
"lat",
"<",
"66.36171008",
")",
"return",
"24",
"if",
"(",
"lat",
"<",
"67.39646774",
")",
"return",
"23",
"if",
"(",
"lat",
"<",
"68.42322022",
")",
"return",
"22",
"if",
"(",
"lat",
"<",
"69.44242631",
")",
"return",
"21",
"if",
"(",
"lat",
"<",
"70.45451075",
")",
"return",
"20",
"if",
"(",
"lat",
"<",
"71.45986473",
")",
"return",
"19",
"if",
"(",
"lat",
"<",
"72.45884545",
")",
"return",
"18",
"if",
"(",
"lat",
"<",
"73.45177442",
")",
"return",
"17",
"if",
"(",
"lat",
"<",
"74.43893416",
")",
"return",
"16",
"if",
"(",
"lat",
"<",
"75.42056257",
")",
"return",
"15",
"if",
"(",
"lat",
"<",
"76.39684391",
")",
"return",
"14",
"if",
"(",
"lat",
"<",
"77.36789461",
")",
"return",
"13",
"if",
"(",
"lat",
"<",
"78.33374083",
")",
"return",
"12",
"if",
"(",
"lat",
"<",
"79.29428225",
")",
"return",
"11",
"if",
"(",
"lat",
"<",
"80.24923213",
")",
"return",
"10",
"if",
"(",
"lat",
"<",
"81.19801349",
")",
"return",
"9",
"if",
"(",
"lat",
"<",
"82.13956981",
")",
"return",
"8",
"if",
"(",
"lat",
"<",
"83.07199445",
")",
"return",
"7",
"if",
"(",
"lat",
"<",
"83.99173563",
")",
"return",
"6",
"if",
"(",
"lat",
"<",
"84.89166191",
")",
"return",
"5",
"if",
"(",
"lat",
"<",
"85.75541621",
")",
"return",
"4",
"if",
"(",
"lat",
"<",
"86.53536998",
")",
"return",
"3",
"if",
"(",
"lat",
"<",
"87.00000000",
")",
"return",
"2",
"else",
"return",
"1",
"}"
]
| The NL function uses the precomputed table from 1090-WP-9-14 | [
"The",
"NL",
"function",
"uses",
"the",
"precomputed",
"table",
"from",
"1090",
"-",
"WP",
"-",
"9",
"-",
"14"
]
| c8ba99927d5cba1c8fbbf2b90f35cf076360299b | https://github.com/watson/mode-s-aircraft-store/blob/c8ba99927d5cba1c8fbbf2b90f35cf076360299b/lib/cpr.js#L76-L137 |
44,472 | micromatch/bash-glob | index.js | glob | function glob(pattern, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
if (Array.isArray(pattern)) {
return glob.each.apply(glob, arguments);
}
if (typeof cb !== 'function') {
if (typeof cb !== 'undefined') {
throw new TypeError('expected callback to be a function');
}
return glob.promise.apply(glob, arguments);
}
if (typeof pattern !== 'string') {
cb(new TypeError('expected glob to be a string or array'));
return;
}
var opts = createOptions(pattern, options);
bash(pattern, opts, function(err, files) {
if (err instanceof Error) {
cb(err);
return;
}
if (!files) {
files = err;
}
if (opts.nullglob === true && Array.isArray(files) && !files.length) {
files = [pattern];
}
glob.emit('files', files, opts.cwd);
if (!opts.each) {
glob.end(files);
}
cb(null, files);
});
return glob;
} | javascript | function glob(pattern, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
if (Array.isArray(pattern)) {
return glob.each.apply(glob, arguments);
}
if (typeof cb !== 'function') {
if (typeof cb !== 'undefined') {
throw new TypeError('expected callback to be a function');
}
return glob.promise.apply(glob, arguments);
}
if (typeof pattern !== 'string') {
cb(new TypeError('expected glob to be a string or array'));
return;
}
var opts = createOptions(pattern, options);
bash(pattern, opts, function(err, files) {
if (err instanceof Error) {
cb(err);
return;
}
if (!files) {
files = err;
}
if (opts.nullglob === true && Array.isArray(files) && !files.length) {
files = [pattern];
}
glob.emit('files', files, opts.cwd);
if (!opts.each) {
glob.end(files);
}
cb(null, files);
});
return glob;
} | [
"function",
"glob",
"(",
"pattern",
",",
"options",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"cb",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"pattern",
")",
")",
"{",
"return",
"glob",
".",
"each",
".",
"apply",
"(",
"glob",
",",
"arguments",
")",
";",
"}",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"if",
"(",
"typeof",
"cb",
"!==",
"'undefined'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected callback to be a function'",
")",
";",
"}",
"return",
"glob",
".",
"promise",
".",
"apply",
"(",
"glob",
",",
"arguments",
")",
";",
"}",
"if",
"(",
"typeof",
"pattern",
"!==",
"'string'",
")",
"{",
"cb",
"(",
"new",
"TypeError",
"(",
"'expected glob to be a string or array'",
")",
")",
";",
"return",
";",
"}",
"var",
"opts",
"=",
"createOptions",
"(",
"pattern",
",",
"options",
")",
";",
"bash",
"(",
"pattern",
",",
"opts",
",",
"function",
"(",
"err",
",",
"files",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"{",
"cb",
"(",
"err",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"files",
")",
"{",
"files",
"=",
"err",
";",
"}",
"if",
"(",
"opts",
".",
"nullglob",
"===",
"true",
"&&",
"Array",
".",
"isArray",
"(",
"files",
")",
"&&",
"!",
"files",
".",
"length",
")",
"{",
"files",
"=",
"[",
"pattern",
"]",
";",
"}",
"glob",
".",
"emit",
"(",
"'files'",
",",
"files",
",",
"opts",
".",
"cwd",
")",
";",
"if",
"(",
"!",
"opts",
".",
"each",
")",
"{",
"glob",
".",
"end",
"(",
"files",
")",
";",
"}",
"cb",
"(",
"null",
",",
"files",
")",
";",
"}",
")",
";",
"return",
"glob",
";",
"}"
]
| Asynchronously returns an array of files that match the given pattern
or patterns.
```js
var glob = require('bash-glob');
glob('*.js', function(err, files) {
if (err) return console.log(err);
console.log(files);
});
```
@param {String|Array} `patterns` One or more glob patterns to use for matching.
@param {Object} `options` Options to pass to bash. See available [options](#options).
@param {Function} `cb` Callback function, with `err` and `files` array.
@api public | [
"Asynchronously",
"returns",
"an",
"array",
"of",
"files",
"that",
"match",
"the",
"given",
"pattern",
"or",
"patterns",
"."
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L30-L77 |
44,473 | micromatch/bash-glob | index.js | bash | function bash(pattern, options, cb) {
if (!isGlob(pattern)) {
return nonGlob(pattern, options, cb);
}
if (typeof options === 'function') {
cb = options;
options = undefined;
}
var opts = extend({cwd: process.cwd()}, options);
fs.stat(opts.cwd, function(err, stat) {
if (err) {
cb(handleError(err, pattern, opts));
return;
}
if (!stat.isDirectory()) {
cb(new Error('cwd is not a directory: ' + opts.cwd));
return;
}
var cp = spawn(bashPath, cmd(pattern, options), options);
var buf = new Buffer(0);
cp.stdout.on('data', function(data) {
emitMatches(data.toString(), pattern, options);
buf = Buffer.concat([buf, data]);
});
cp.stderr.on('data', function(data) {
cb(handleError(data.toString(), pattern, options));
});
cp.on('close', function(code) {
cb(code, getFiles(buf.toString(), pattern, options));
});
});
} | javascript | function bash(pattern, options, cb) {
if (!isGlob(pattern)) {
return nonGlob(pattern, options, cb);
}
if (typeof options === 'function') {
cb = options;
options = undefined;
}
var opts = extend({cwd: process.cwd()}, options);
fs.stat(opts.cwd, function(err, stat) {
if (err) {
cb(handleError(err, pattern, opts));
return;
}
if (!stat.isDirectory()) {
cb(new Error('cwd is not a directory: ' + opts.cwd));
return;
}
var cp = spawn(bashPath, cmd(pattern, options), options);
var buf = new Buffer(0);
cp.stdout.on('data', function(data) {
emitMatches(data.toString(), pattern, options);
buf = Buffer.concat([buf, data]);
});
cp.stderr.on('data', function(data) {
cb(handleError(data.toString(), pattern, options));
});
cp.on('close', function(code) {
cb(code, getFiles(buf.toString(), pattern, options));
});
});
} | [
"function",
"bash",
"(",
"pattern",
",",
"options",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"isGlob",
"(",
"pattern",
")",
")",
"{",
"return",
"nonGlob",
"(",
"pattern",
",",
"options",
",",
"cb",
")",
";",
"}",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"cb",
"=",
"options",
";",
"options",
"=",
"undefined",
";",
"}",
"var",
"opts",
"=",
"extend",
"(",
"{",
"cwd",
":",
"process",
".",
"cwd",
"(",
")",
"}",
",",
"options",
")",
";",
"fs",
".",
"stat",
"(",
"opts",
".",
"cwd",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"handleError",
"(",
"err",
",",
"pattern",
",",
"opts",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"cb",
"(",
"new",
"Error",
"(",
"'cwd is not a directory: '",
"+",
"opts",
".",
"cwd",
")",
")",
";",
"return",
";",
"}",
"var",
"cp",
"=",
"spawn",
"(",
"bashPath",
",",
"cmd",
"(",
"pattern",
",",
"options",
")",
",",
"options",
")",
";",
"var",
"buf",
"=",
"new",
"Buffer",
"(",
"0",
")",
";",
"cp",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"emitMatches",
"(",
"data",
".",
"toString",
"(",
")",
",",
"pattern",
",",
"options",
")",
";",
"buf",
"=",
"Buffer",
".",
"concat",
"(",
"[",
"buf",
",",
"data",
"]",
")",
";",
"}",
")",
";",
"cp",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"cb",
"(",
"handleError",
"(",
"data",
".",
"toString",
"(",
")",
",",
"pattern",
",",
"options",
")",
")",
";",
"}",
")",
";",
"cp",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
")",
"{",
"cb",
"(",
"code",
",",
"getFiles",
"(",
"buf",
".",
"toString",
"(",
")",
",",
"pattern",
",",
"options",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Base bash function | [
"Base",
"bash",
"function"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L244-L283 |
44,474 | micromatch/bash-glob | index.js | normalize | function normalize(val) {
if (Array.isArray(val)) {
val = val.join(' ');
}
return val.split(' ').join('\\ ');
} | javascript | function normalize(val) {
if (Array.isArray(val)) {
val = val.join(' ');
}
return val.split(' ').join('\\ ');
} | [
"function",
"normalize",
"(",
"val",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"val",
"=",
"val",
".",
"join",
"(",
"' '",
")",
";",
"}",
"return",
"val",
".",
"split",
"(",
"' '",
")",
".",
"join",
"(",
"'\\\\ '",
")",
";",
"}"
]
| Escape spaces in glob patterns | [
"Escape",
"spaces",
"in",
"glob",
"patterns"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L289-L294 |
44,475 | micromatch/bash-glob | index.js | cmd | function cmd(patterns, options) {
var str = normalize(patterns);
var keys = Object.keys(options);
var args = [];
var valid = [
'dotglob',
'extglob',
'failglob',
'globstar',
'nocaseglob',
'nullglob'
];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (valid.indexOf(key) !== -1) {
args.push('-O', key);
}
}
args.push('-c', 'for i in ' + str + '; do echo $i; done');
return args;
} | javascript | function cmd(patterns, options) {
var str = normalize(patterns);
var keys = Object.keys(options);
var args = [];
var valid = [
'dotglob',
'extglob',
'failglob',
'globstar',
'nocaseglob',
'nullglob'
];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (valid.indexOf(key) !== -1) {
args.push('-O', key);
}
}
args.push('-c', 'for i in ' + str + '; do echo $i; done');
return args;
} | [
"function",
"cmd",
"(",
"patterns",
",",
"options",
")",
"{",
"var",
"str",
"=",
"normalize",
"(",
"patterns",
")",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"options",
")",
";",
"var",
"args",
"=",
"[",
"]",
";",
"var",
"valid",
"=",
"[",
"'dotglob'",
",",
"'extglob'",
",",
"'failglob'",
",",
"'globstar'",
",",
"'nocaseglob'",
",",
"'nullglob'",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"valid",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"{",
"args",
".",
"push",
"(",
"'-O'",
",",
"key",
")",
";",
"}",
"}",
"args",
".",
"push",
"(",
"'-c'",
",",
"'for i in '",
"+",
"str",
"+",
"'; do echo $i; done'",
")",
";",
"return",
"args",
";",
"}"
]
| Create the command to use | [
"Create",
"the",
"command",
"to",
"use"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L300-L322 |
44,476 | micromatch/bash-glob | index.js | handleError | function handleError(err, pattern, options) {
var message = err;
if (typeof err === 'string') {
err = new Error(message.trim());
err.pattern = pattern;
err.options = options;
if (/invalid shell option/.test(err)) {
err.code = 'INVALID_SHELL_OPTION';
}
if (/no match:/.test(err)) {
err.code = 'NOMATCH';
}
return err;
}
if (err && (err.code === 'ENOENT' || err.code === 'NOMATCH')) {
if (options.nullglob === true) {
return [pattern];
}
if (options.failglob === true) {
return err;
}
return [];
}
return err;
} | javascript | function handleError(err, pattern, options) {
var message = err;
if (typeof err === 'string') {
err = new Error(message.trim());
err.pattern = pattern;
err.options = options;
if (/invalid shell option/.test(err)) {
err.code = 'INVALID_SHELL_OPTION';
}
if (/no match:/.test(err)) {
err.code = 'NOMATCH';
}
return err;
}
if (err && (err.code === 'ENOENT' || err.code === 'NOMATCH')) {
if (options.nullglob === true) {
return [pattern];
}
if (options.failglob === true) {
return err;
}
return [];
}
return err;
} | [
"function",
"handleError",
"(",
"err",
",",
"pattern",
",",
"options",
")",
"{",
"var",
"message",
"=",
"err",
";",
"if",
"(",
"typeof",
"err",
"===",
"'string'",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"message",
".",
"trim",
"(",
")",
")",
";",
"err",
".",
"pattern",
"=",
"pattern",
";",
"err",
".",
"options",
"=",
"options",
";",
"if",
"(",
"/",
"invalid shell option",
"/",
".",
"test",
"(",
"err",
")",
")",
"{",
"err",
".",
"code",
"=",
"'INVALID_SHELL_OPTION'",
";",
"}",
"if",
"(",
"/",
"no match:",
"/",
".",
"test",
"(",
"err",
")",
")",
"{",
"err",
".",
"code",
"=",
"'NOMATCH'",
";",
"}",
"return",
"err",
";",
"}",
"if",
"(",
"err",
"&&",
"(",
"err",
".",
"code",
"===",
"'ENOENT'",
"||",
"err",
".",
"code",
"===",
"'NOMATCH'",
")",
")",
"{",
"if",
"(",
"options",
".",
"nullglob",
"===",
"true",
")",
"{",
"return",
"[",
"pattern",
"]",
";",
"}",
"if",
"(",
"options",
".",
"failglob",
"===",
"true",
")",
"{",
"return",
"err",
";",
"}",
"return",
"[",
"]",
";",
"}",
"return",
"err",
";",
"}"
]
| Handle errors to ensure the correct value is returned based on options | [
"Handle",
"errors",
"to",
"ensure",
"the",
"correct",
"value",
"is",
"returned",
"based",
"on",
"options"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L348-L373 |
44,477 | micromatch/bash-glob | index.js | getFiles | function getFiles(res, pattern, options) {
var files = res.split(/\r?\n/).filter(Boolean);
if (files.length === 1 && files[0] === pattern) {
files = [];
} else if (options.realpath === true || options.follow === true) {
files = toAbsolute(files, options);
}
if (files.length === 0) {
if (options.nullglob === true) {
return [pattern];
}
if (options.failglob === true) {
return new Error('no matches:' + pattern);
}
}
return files.filter(function(filepath) {
return filepath !== '.' && filepath !== '..';
});
} | javascript | function getFiles(res, pattern, options) {
var files = res.split(/\r?\n/).filter(Boolean);
if (files.length === 1 && files[0] === pattern) {
files = [];
} else if (options.realpath === true || options.follow === true) {
files = toAbsolute(files, options);
}
if (files.length === 0) {
if (options.nullglob === true) {
return [pattern];
}
if (options.failglob === true) {
return new Error('no matches:' + pattern);
}
}
return files.filter(function(filepath) {
return filepath !== '.' && filepath !== '..';
});
} | [
"function",
"getFiles",
"(",
"res",
",",
"pattern",
",",
"options",
")",
"{",
"var",
"files",
"=",
"res",
".",
"split",
"(",
"/",
"\\r?\\n",
"/",
")",
".",
"filter",
"(",
"Boolean",
")",
";",
"if",
"(",
"files",
".",
"length",
"===",
"1",
"&&",
"files",
"[",
"0",
"]",
"===",
"pattern",
")",
"{",
"files",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"options",
".",
"realpath",
"===",
"true",
"||",
"options",
".",
"follow",
"===",
"true",
")",
"{",
"files",
"=",
"toAbsolute",
"(",
"files",
",",
"options",
")",
";",
"}",
"if",
"(",
"files",
".",
"length",
"===",
"0",
")",
"{",
"if",
"(",
"options",
".",
"nullglob",
"===",
"true",
")",
"{",
"return",
"[",
"pattern",
"]",
";",
"}",
"if",
"(",
"options",
".",
"failglob",
"===",
"true",
")",
"{",
"return",
"new",
"Error",
"(",
"'no matches:'",
"+",
"pattern",
")",
";",
"}",
"}",
"return",
"files",
".",
"filter",
"(",
"function",
"(",
"filepath",
")",
"{",
"return",
"filepath",
"!==",
"'.'",
"&&",
"filepath",
"!==",
"'..'",
";",
"}",
")",
";",
"}"
]
| Handle files to ensure the correct value is returned based on options | [
"Handle",
"files",
"to",
"ensure",
"the",
"correct",
"value",
"is",
"returned",
"based",
"on",
"options"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L379-L398 |
44,478 | micromatch/bash-glob | index.js | toAbsolute | function toAbsolute(files, options) {
var len = files.length;
var idx = -1;
var arr = [];
while (++idx < len) {
var file = files[idx];
if (!file.trim()) continue;
if (file && options.cwd) {
file = path.resolve(options.cwd, file);
}
if (file && options.realpath === true) {
file = follow(file);
}
if (file) {
arr.push(file);
}
}
return arr;
} | javascript | function toAbsolute(files, options) {
var len = files.length;
var idx = -1;
var arr = [];
while (++idx < len) {
var file = files[idx];
if (!file.trim()) continue;
if (file && options.cwd) {
file = path.resolve(options.cwd, file);
}
if (file && options.realpath === true) {
file = follow(file);
}
if (file) {
arr.push(file);
}
}
return arr;
} | [
"function",
"toAbsolute",
"(",
"files",
",",
"options",
")",
"{",
"var",
"len",
"=",
"files",
".",
"length",
";",
"var",
"idx",
"=",
"-",
"1",
";",
"var",
"arr",
"=",
"[",
"]",
";",
"while",
"(",
"++",
"idx",
"<",
"len",
")",
"{",
"var",
"file",
"=",
"files",
"[",
"idx",
"]",
";",
"if",
"(",
"!",
"file",
".",
"trim",
"(",
")",
")",
"continue",
";",
"if",
"(",
"file",
"&&",
"options",
".",
"cwd",
")",
"{",
"file",
"=",
"path",
".",
"resolve",
"(",
"options",
".",
"cwd",
",",
"file",
")",
";",
"}",
"if",
"(",
"file",
"&&",
"options",
".",
"realpath",
"===",
"true",
")",
"{",
"file",
"=",
"follow",
"(",
"file",
")",
";",
"}",
"if",
"(",
"file",
")",
"{",
"arr",
".",
"push",
"(",
"file",
")",
";",
"}",
"}",
"return",
"arr",
";",
"}"
]
| Make symlinks absolute when `options.follow` is defined. | [
"Make",
"symlinks",
"absolute",
"when",
"options",
".",
"follow",
"is",
"defined",
"."
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L404-L423 |
44,479 | micromatch/bash-glob | index.js | nonGlob | function nonGlob(pattern, options, cb) {
if (options.nullglob) {
cb(null, [pattern]);
return;
}
fs.stat(pattern, callback(null, pattern, options, cb));
return;
} | javascript | function nonGlob(pattern, options, cb) {
if (options.nullglob) {
cb(null, [pattern]);
return;
}
fs.stat(pattern, callback(null, pattern, options, cb));
return;
} | [
"function",
"nonGlob",
"(",
"pattern",
",",
"options",
",",
"cb",
")",
"{",
"if",
"(",
"options",
".",
"nullglob",
")",
"{",
"cb",
"(",
"null",
",",
"[",
"pattern",
"]",
")",
";",
"return",
";",
"}",
"fs",
".",
"stat",
"(",
"pattern",
",",
"callback",
"(",
"null",
",",
"pattern",
",",
"options",
",",
"cb",
")",
")",
";",
"return",
";",
"}"
]
| Handle non-globs | [
"Handle",
"non",
"-",
"globs"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L461-L468 |
44,480 | micromatch/bash-glob | index.js | emitMatches | function emitMatches(str, pattern, options) {
glob.emit('match', getFiles(str, pattern, options), options.cwd);
} | javascript | function emitMatches(str, pattern, options) {
glob.emit('match', getFiles(str, pattern, options), options.cwd);
} | [
"function",
"emitMatches",
"(",
"str",
",",
"pattern",
",",
"options",
")",
"{",
"glob",
".",
"emit",
"(",
"'match'",
",",
"getFiles",
"(",
"str",
",",
"pattern",
",",
"options",
")",
",",
"options",
".",
"cwd",
")",
";",
"}"
]
| Emit matches for a pattern | [
"Emit",
"matches",
"for",
"a",
"pattern"
]
| eddb7de28a22d90c9a26389f7c884af5ddaadead | https://github.com/micromatch/bash-glob/blob/eddb7de28a22d90c9a26389f7c884af5ddaadead/index.js#L474-L476 |
44,481 | reelyactive/barterer | lib/barterer.js | Barterer | function Barterer(options) {
var self = this;
options = options || {};
self.routes = {
"/whereis": require('./routes/whereis'),
"/whatat": require('./routes/whatat'),
"/whatnear": require('./routes/whatnear'),
"/": express.static(path.resolve(__dirname + '/../web'))
};
console.log('reelyActive Barterer instance is exchanging data in an open IoT');
} | javascript | function Barterer(options) {
var self = this;
options = options || {};
self.routes = {
"/whereis": require('./routes/whereis'),
"/whatat": require('./routes/whatat'),
"/whatnear": require('./routes/whatnear'),
"/": express.static(path.resolve(__dirname + '/../web'))
};
console.log('reelyActive Barterer instance is exchanging data in an open IoT');
} | [
"function",
"Barterer",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"self",
".",
"routes",
"=",
"{",
"\"/whereis\"",
":",
"require",
"(",
"'./routes/whereis'",
")",
",",
"\"/whatat\"",
":",
"require",
"(",
"'./routes/whatat'",
")",
",",
"\"/whatnear\"",
":",
"require",
"(",
"'./routes/whatnear'",
")",
",",
"\"/\"",
":",
"express",
".",
"static",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
"+",
"'/../web'",
")",
")",
"}",
";",
"console",
".",
"log",
"(",
"'reelyActive Barterer instance is exchanging data in an open IoT'",
")",
";",
"}"
]
| Barterer Class
API for real-time location and hyperlocal context.
@param {Object} options The options as a JSON object.
@constructor | [
"Barterer",
"Class",
"API",
"for",
"real",
"-",
"time",
"location",
"and",
"hyperlocal",
"context",
"."
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/barterer.js#L19-L31 |
44,482 | reelyactive/barterer | lib/barterer.js | isValidOptions | function isValidOptions(options) {
if(!options) {
return false;
}
if(options.hasOwnProperty('ids') && Array.isArray(options.ids)) {
for(var cId = 0; cId < options.ids.length; cId++) {
if(!reelib.identifier.isValid(options.ids[cId])) {
return false;
}
}
return true;
}
else {
return false;
}
} | javascript | function isValidOptions(options) {
if(!options) {
return false;
}
if(options.hasOwnProperty('ids') && Array.isArray(options.ids)) {
for(var cId = 0; cId < options.ids.length; cId++) {
if(!reelib.identifier.isValid(options.ids[cId])) {
return false;
}
}
return true;
}
else {
return false;
}
} | [
"function",
"isValidOptions",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"options",
".",
"hasOwnProperty",
"(",
"'ids'",
")",
"&&",
"Array",
".",
"isArray",
"(",
"options",
".",
"ids",
")",
")",
"{",
"for",
"(",
"var",
"cId",
"=",
"0",
";",
"cId",
"<",
"options",
".",
"ids",
".",
"length",
";",
"cId",
"++",
")",
"{",
"if",
"(",
"!",
"reelib",
".",
"identifier",
".",
"isValid",
"(",
"options",
".",
"ids",
"[",
"cId",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Determine if the given options are valid.
@param {Object} options The given options.
@return {boolean} True if the options are valid, false otherwise. | [
"Determine",
"if",
"the",
"given",
"options",
"are",
"valid",
"."
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/barterer.js#L113-L130 |
44,483 | jossmac/react-deprecate | lib/index.js | getComponentName | function getComponentName(target) {
if (target.displayName && typeof target.displayName === 'string') {
return target.displayName;
}
return target.name || 'Component';
} | javascript | function getComponentName(target) {
if (target.displayName && typeof target.displayName === 'string') {
return target.displayName;
}
return target.name || 'Component';
} | [
"function",
"getComponentName",
"(",
"target",
")",
"{",
"if",
"(",
"target",
".",
"displayName",
"&&",
"typeof",
"target",
".",
"displayName",
"===",
"'string'",
")",
"{",
"return",
"target",
".",
"displayName",
";",
"}",
"return",
"target",
".",
"name",
"||",
"'Component'",
";",
"}"
]
| attempt to get the wrapped component's name | [
"attempt",
"to",
"get",
"the",
"wrapped",
"component",
"s",
"name"
]
| 4a96b1dff81ffd5eadba480d71b5b99fc91375b1 | https://github.com/jossmac/react-deprecate/blob/4a96b1dff81ffd5eadba480d71b5b99fc91375b1/lib/index.js#L28-L34 |
44,484 | jossmac/react-deprecate | lib/index.js | defaultWarningMessage | function defaultWarningMessage(_ref) {
var componentName = _ref.componentName,
prop = _ref.prop,
renamedProps = _ref.renamedProps;
return componentName + ' Warning: Prop "' + prop + '" is deprecated, use "' + renamedProps[prop] + '" instead.';
} | javascript | function defaultWarningMessage(_ref) {
var componentName = _ref.componentName,
prop = _ref.prop,
renamedProps = _ref.renamedProps;
return componentName + ' Warning: Prop "' + prop + '" is deprecated, use "' + renamedProps[prop] + '" instead.';
} | [
"function",
"defaultWarningMessage",
"(",
"_ref",
")",
"{",
"var",
"componentName",
"=",
"_ref",
".",
"componentName",
",",
"prop",
"=",
"_ref",
".",
"prop",
",",
"renamedProps",
"=",
"_ref",
".",
"renamedProps",
";",
"return",
"componentName",
"+",
"' Warning: Prop \"'",
"+",
"prop",
"+",
"'\" is deprecated, use \"'",
"+",
"renamedProps",
"[",
"prop",
"]",
"+",
"'\" instead.'",
";",
"}"
]
| deprecation warning for consumer | [
"deprecation",
"warning",
"for",
"consumer"
]
| 4a96b1dff81ffd5eadba480d71b5b99fc91375b1 | https://github.com/jossmac/react-deprecate/blob/4a96b1dff81ffd5eadba480d71b5b99fc91375b1/lib/index.js#L37-L43 |
44,485 | jossmac/react-deprecate | lib/index.js | componentDidMount | function componentDidMount() {
var _this2 = this;
Object.keys(renamedProps).forEach(function (prop) {
if (prop in _this2.props) {
console.warn(warningMessage({
componentName: getComponentName(WrappedComponent),
prop: prop,
renamedProps: renamedProps
}));
}
});
} | javascript | function componentDidMount() {
var _this2 = this;
Object.keys(renamedProps).forEach(function (prop) {
if (prop in _this2.props) {
console.warn(warningMessage({
componentName: getComponentName(WrappedComponent),
prop: prop,
renamedProps: renamedProps
}));
}
});
} | [
"function",
"componentDidMount",
"(",
")",
"{",
"var",
"_this2",
"=",
"this",
";",
"Object",
".",
"keys",
"(",
"renamedProps",
")",
".",
"forEach",
"(",
"function",
"(",
"prop",
")",
"{",
"if",
"(",
"prop",
"in",
"_this2",
".",
"props",
")",
"{",
"console",
".",
"warn",
"(",
"warningMessage",
"(",
"{",
"componentName",
":",
"getComponentName",
"(",
"WrappedComponent",
")",
",",
"prop",
":",
"prop",
",",
"renamedProps",
":",
"renamedProps",
"}",
")",
")",
";",
"}",
"}",
")",
";",
"}"
]
| warn on deprecated props | [
"warn",
"on",
"deprecated",
"props"
]
| 4a96b1dff81ffd5eadba480d71b5b99fc91375b1 | https://github.com/jossmac/react-deprecate/blob/4a96b1dff81ffd5eadba480d71b5b99fc91375b1/lib/index.js#L67-L79 |
44,486 | sematext/spm-agent | lib/harvester.js | harvester | function harvester (metricConsumer, agentList) {
var agentsToLoad = []
this.metricConsumer = metricConsumer
this.httpAgent = null
if (agentList) {
agentsToLoad = agentList
}
this.agents = []
for (var x in agentsToLoad) {
try {
var TmpAgentClass = require(agentsToLoad[x])
var tmpAgentInstance = new TmpAgentClass()
this.addAgent(tmpAgentInstance)
} catch (err) {
logger.error('Loading of agent failed:' + agentsToLoad[x])
logger.error(err)
}
}
process.on('exit', function () {
this.stop()
}.bind(this))
return this
} | javascript | function harvester (metricConsumer, agentList) {
var agentsToLoad = []
this.metricConsumer = metricConsumer
this.httpAgent = null
if (agentList) {
agentsToLoad = agentList
}
this.agents = []
for (var x in agentsToLoad) {
try {
var TmpAgentClass = require(agentsToLoad[x])
var tmpAgentInstance = new TmpAgentClass()
this.addAgent(tmpAgentInstance)
} catch (err) {
logger.error('Loading of agent failed:' + agentsToLoad[x])
logger.error(err)
}
}
process.on('exit', function () {
this.stop()
}.bind(this))
return this
} | [
"function",
"harvester",
"(",
"metricConsumer",
",",
"agentList",
")",
"{",
"var",
"agentsToLoad",
"=",
"[",
"]",
"this",
".",
"metricConsumer",
"=",
"metricConsumer",
"this",
".",
"httpAgent",
"=",
"null",
"if",
"(",
"agentList",
")",
"{",
"agentsToLoad",
"=",
"agentList",
"}",
"this",
".",
"agents",
"=",
"[",
"]",
"for",
"(",
"var",
"x",
"in",
"agentsToLoad",
")",
"{",
"try",
"{",
"var",
"TmpAgentClass",
"=",
"require",
"(",
"agentsToLoad",
"[",
"x",
"]",
")",
"var",
"tmpAgentInstance",
"=",
"new",
"TmpAgentClass",
"(",
")",
"this",
".",
"addAgent",
"(",
"tmpAgentInstance",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"'Loading of agent failed:'",
"+",
"agentsToLoad",
"[",
"x",
"]",
")",
"logger",
".",
"error",
"(",
"err",
")",
"}",
"}",
"process",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
")",
"{",
"this",
".",
"stop",
"(",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
"return",
"this",
"}"
]
| This module harvest metrics from agents, registers to all agents and fires own metric events
@metricConsumer - an object that listens on "metric" event. The metric event passes a metric object with (name, value, type, ts) properties
@agentList a list of agents to be created e.g. ['./agents/osAgent.js', './agents/eventLoopAgent.js'] | [
"This",
"module",
"harvest",
"metrics",
"from",
"agents",
"registers",
"to",
"all",
"agents",
"and",
"fires",
"own",
"metric",
"events"
]
| 7b98be0cfc41fb7bf7f7c605e6602148570269a3 | https://github.com/sematext/spm-agent/blob/7b98be0cfc41fb7bf7f7c605e6602148570269a3/lib/harvester.js#L19-L41 |
44,487 | warmsea/node-rfr | lib/rfr.js | coerceRoot | function coerceRoot(root) {
var coerced = root.substring().trim();
var len = coerced.length;
if (len > 0 && coerced[len - 1] !== '/') {
coerced = coerced + '/';
}
return coerced;
} | javascript | function coerceRoot(root) {
var coerced = root.substring().trim();
var len = coerced.length;
if (len > 0 && coerced[len - 1] !== '/') {
coerced = coerced + '/';
}
return coerced;
} | [
"function",
"coerceRoot",
"(",
"root",
")",
"{",
"var",
"coerced",
"=",
"root",
".",
"substring",
"(",
")",
".",
"trim",
"(",
")",
";",
"var",
"len",
"=",
"coerced",
".",
"length",
";",
"if",
"(",
"len",
">",
"0",
"&&",
"coerced",
"[",
"len",
"-",
"1",
"]",
"!==",
"'/'",
")",
"{",
"coerced",
"=",
"coerced",
"+",
"'/'",
";",
"}",
"return",
"coerced",
";",
"}"
]
| Trim a root and add tailing slash if not exists.
@param {String} root A root.
@returns {String} The coerced root.
@private | [
"Trim",
"a",
"root",
"and",
"add",
"tailing",
"slash",
"if",
"not",
"exists",
"."
]
| 4c6c62dd5c338824e7eeccb44321942a7c3a8662 | https://github.com/warmsea/node-rfr/blob/4c6c62dd5c338824e7eeccb44321942a7c3a8662/lib/rfr.js#L27-L34 |
44,488 | warmsea/node-rfr | lib/rfr.js | function(callable, root, isMaster) {
rfr = callable.bind(callable);
/**
* A read-only property tells whether this rfr instance is a master one.
* Call `require('rfr')` to get a master rfr instance.
* User created rfr instances, such as `require('rfr')({ root: '...' })` are
* not master ones.
* @type {Boolean}
*/
Object.defineProperty(rfr, 'isMaster', {
configurable: false,
enumerable: true,
value: !!isMaster,
writable: false
});
/**
* A read-only property tells whether this rfr instance is a global master.
* Call `require('rfr')` on a global rfr module to get a master rfr instance.
* Using the global master is error-prone.
* @type {Boolean}
*/
Object.defineProperty(rfr, 'isGlobalMaster', {
configurable: false,
enumerable: true,
value: constants.isGlobal && !!isMaster,
writable: false
});
/**
* The root of a rfr instance.
* @type {String}
*/
Object.defineProperty(rfr, 'root', {
configurable: false,
enumerable: true,
get: function() {
return callable.root;
},
set: function(root) {
callable.root = coerceRoot(root);
}
});
/**
* Set the root.
* @param {String} root The new root.
*/
rfr.setRoot = function(root) {
this.root = root;
};
/**
* Get the filename that will be loaded when this rfr is called.
* @returns {String} module filename.
*/
rfr.resolve = function(idFromRoot) {
return require.resolve(normalizeId(idFromRoot, this.root));
};
rfr.root = root;
return rfr;
} | javascript | function(callable, root, isMaster) {
rfr = callable.bind(callable);
/**
* A read-only property tells whether this rfr instance is a master one.
* Call `require('rfr')` to get a master rfr instance.
* User created rfr instances, such as `require('rfr')({ root: '...' })` are
* not master ones.
* @type {Boolean}
*/
Object.defineProperty(rfr, 'isMaster', {
configurable: false,
enumerable: true,
value: !!isMaster,
writable: false
});
/**
* A read-only property tells whether this rfr instance is a global master.
* Call `require('rfr')` on a global rfr module to get a master rfr instance.
* Using the global master is error-prone.
* @type {Boolean}
*/
Object.defineProperty(rfr, 'isGlobalMaster', {
configurable: false,
enumerable: true,
value: constants.isGlobal && !!isMaster,
writable: false
});
/**
* The root of a rfr instance.
* @type {String}
*/
Object.defineProperty(rfr, 'root', {
configurable: false,
enumerable: true,
get: function() {
return callable.root;
},
set: function(root) {
callable.root = coerceRoot(root);
}
});
/**
* Set the root.
* @param {String} root The new root.
*/
rfr.setRoot = function(root) {
this.root = root;
};
/**
* Get the filename that will be loaded when this rfr is called.
* @returns {String} module filename.
*/
rfr.resolve = function(idFromRoot) {
return require.resolve(normalizeId(idFromRoot, this.root));
};
rfr.root = root;
return rfr;
} | [
"function",
"(",
"callable",
",",
"root",
",",
"isMaster",
")",
"{",
"rfr",
"=",
"callable",
".",
"bind",
"(",
"callable",
")",
";",
"/**\n * A read-only property tells whether this rfr instance is a master one.\n * Call `require('rfr')` to get a master rfr instance.\n * User created rfr instances, such as `require('rfr')({ root: '...' })` are\n * not master ones.\n * @type {Boolean}\n */",
"Object",
".",
"defineProperty",
"(",
"rfr",
",",
"'isMaster'",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"!",
"!",
"isMaster",
",",
"writable",
":",
"false",
"}",
")",
";",
"/**\n * A read-only property tells whether this rfr instance is a global master.\n * Call `require('rfr')` on a global rfr module to get a master rfr instance.\n * Using the global master is error-prone.\n * @type {Boolean}\n */",
"Object",
".",
"defineProperty",
"(",
"rfr",
",",
"'isGlobalMaster'",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"constants",
".",
"isGlobal",
"&&",
"!",
"!",
"isMaster",
",",
"writable",
":",
"false",
"}",
")",
";",
"/**\n * The root of a rfr instance.\n * @type {String}\n */",
"Object",
".",
"defineProperty",
"(",
"rfr",
",",
"'root'",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"true",
",",
"get",
":",
"function",
"(",
")",
"{",
"return",
"callable",
".",
"root",
";",
"}",
",",
"set",
":",
"function",
"(",
"root",
")",
"{",
"callable",
".",
"root",
"=",
"coerceRoot",
"(",
"root",
")",
";",
"}",
"}",
")",
";",
"/**\n * Set the root.\n * @param {String} root The new root.\n */",
"rfr",
".",
"setRoot",
"=",
"function",
"(",
"root",
")",
"{",
"this",
".",
"root",
"=",
"root",
";",
"}",
";",
"/**\n * Get the filename that will be loaded when this rfr is called.\n * @returns {String} module filename.\n */",
"rfr",
".",
"resolve",
"=",
"function",
"(",
"idFromRoot",
")",
"{",
"return",
"require",
".",
"resolve",
"(",
"normalizeId",
"(",
"idFromRoot",
",",
"this",
".",
"root",
")",
")",
";",
"}",
";",
"rfr",
".",
"root",
"=",
"root",
";",
"return",
"rfr",
";",
"}"
]
| Create a new version of rfr with a function.
@param {Function} callable The rfr require function.
@param {String} root The root for rfr require.
@param {Boolean} isMaster Whether this is a master rfr.
@private | [
"Create",
"a",
"new",
"version",
"of",
"rfr",
"with",
"a",
"function",
"."
]
| 4c6c62dd5c338824e7eeccb44321942a7c3a8662 | https://github.com/warmsea/node-rfr/blob/4c6c62dd5c338824e7eeccb44321942a7c3a8662/lib/rfr.js#L59-L122 |
|
44,489 | warmsea/node-rfr | lib/rfr.js | createVersion | function createVersion(config) {
if (!(config && (typeof config.root === 'string'
|| config.root === null || config.root === undefined))) {
throw new Error('"config.root" is required and must be a string');
}
var root = config.root;
if (root === null || root === undefined) {
root = defaultRoot;
}
return createRfr(function(idFromRoot) {
if (typeof idFromRoot !== 'string') {
throw new Error('A string is required for the argument of ' +
'a user created RFR version.');
}
return require(normalizeId(idFromRoot, this.root));
}, root);
} | javascript | function createVersion(config) {
if (!(config && (typeof config.root === 'string'
|| config.root === null || config.root === undefined))) {
throw new Error('"config.root" is required and must be a string');
}
var root = config.root;
if (root === null || root === undefined) {
root = defaultRoot;
}
return createRfr(function(idFromRoot) {
if (typeof idFromRoot !== 'string') {
throw new Error('A string is required for the argument of ' +
'a user created RFR version.');
}
return require(normalizeId(idFromRoot, this.root));
}, root);
} | [
"function",
"createVersion",
"(",
"config",
")",
"{",
"if",
"(",
"!",
"(",
"config",
"&&",
"(",
"typeof",
"config",
".",
"root",
"===",
"'string'",
"||",
"config",
".",
"root",
"===",
"null",
"||",
"config",
".",
"root",
"===",
"undefined",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"config.root\" is required and must be a string'",
")",
";",
"}",
"var",
"root",
"=",
"config",
".",
"root",
";",
"if",
"(",
"root",
"===",
"null",
"||",
"root",
"===",
"undefined",
")",
"{",
"root",
"=",
"defaultRoot",
";",
"}",
"return",
"createRfr",
"(",
"function",
"(",
"idFromRoot",
")",
"{",
"if",
"(",
"typeof",
"idFromRoot",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A string is required for the argument of '",
"+",
"'a user created RFR version.'",
")",
";",
"}",
"return",
"require",
"(",
"normalizeId",
"(",
"idFromRoot",
",",
"this",
".",
"root",
")",
")",
";",
"}",
",",
"root",
")",
";",
"}"
]
| Create a new version of rfr.
@param {{root:String}} config config of this version.
@returns {rfr} a new rfr version.
@private | [
"Create",
"a",
"new",
"version",
"of",
"rfr",
"."
]
| 4c6c62dd5c338824e7eeccb44321942a7c3a8662 | https://github.com/warmsea/node-rfr/blob/4c6c62dd5c338824e7eeccb44321942a7c3a8662/lib/rfr.js#L130-L147 |
44,490 | hayspec/framework | common/scripts/install-run.js | parsePackageSpecifier | function parsePackageSpecifier(rawPackageSpecifier) {
rawPackageSpecifier = (rawPackageSpecifier || '').trim();
const separatorIndex = rawPackageSpecifier.lastIndexOf('@');
let name;
let version = undefined;
if (separatorIndex === 0) {
// The specifier starts with a scope and doesn't have a version specified
name = rawPackageSpecifier;
}
else if (separatorIndex === -1) {
// The specifier doesn't have a version
name = rawPackageSpecifier;
}
else {
name = rawPackageSpecifier.substring(0, separatorIndex);
version = rawPackageSpecifier.substring(separatorIndex + 1);
}
if (!name) {
throw new Error(`Invalid package specifier: ${rawPackageSpecifier}`);
}
return { name, version };
} | javascript | function parsePackageSpecifier(rawPackageSpecifier) {
rawPackageSpecifier = (rawPackageSpecifier || '').trim();
const separatorIndex = rawPackageSpecifier.lastIndexOf('@');
let name;
let version = undefined;
if (separatorIndex === 0) {
// The specifier starts with a scope and doesn't have a version specified
name = rawPackageSpecifier;
}
else if (separatorIndex === -1) {
// The specifier doesn't have a version
name = rawPackageSpecifier;
}
else {
name = rawPackageSpecifier.substring(0, separatorIndex);
version = rawPackageSpecifier.substring(separatorIndex + 1);
}
if (!name) {
throw new Error(`Invalid package specifier: ${rawPackageSpecifier}`);
}
return { name, version };
} | [
"function",
"parsePackageSpecifier",
"(",
"rawPackageSpecifier",
")",
"{",
"rawPackageSpecifier",
"=",
"(",
"rawPackageSpecifier",
"||",
"''",
")",
".",
"trim",
"(",
")",
";",
"const",
"separatorIndex",
"=",
"rawPackageSpecifier",
".",
"lastIndexOf",
"(",
"'@'",
")",
";",
"let",
"name",
";",
"let",
"version",
"=",
"undefined",
";",
"if",
"(",
"separatorIndex",
"===",
"0",
")",
"{",
"// The specifier starts with a scope and doesn't have a version specified\r",
"name",
"=",
"rawPackageSpecifier",
";",
"}",
"else",
"if",
"(",
"separatorIndex",
"===",
"-",
"1",
")",
"{",
"// The specifier doesn't have a version\r",
"name",
"=",
"rawPackageSpecifier",
";",
"}",
"else",
"{",
"name",
"=",
"rawPackageSpecifier",
".",
"substring",
"(",
"0",
",",
"separatorIndex",
")",
";",
"version",
"=",
"rawPackageSpecifier",
".",
"substring",
"(",
"separatorIndex",
"+",
"1",
")",
";",
"}",
"if",
"(",
"!",
"name",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"rawPackageSpecifier",
"}",
"`",
")",
";",
"}",
"return",
"{",
"name",
",",
"version",
"}",
";",
"}"
]
| Parse a package specifier (in the form of name\@version) into name and version parts. | [
"Parse",
"a",
"package",
"specifier",
"(",
"in",
"the",
"form",
"of",
"name",
"\\"
]
| 739e2fca2a99ee5cf9f10c658fe0fd0a81129803 | https://github.com/hayspec/framework/blob/739e2fca2a99ee5cf9f10c658fe0fd0a81129803/common/scripts/install-run.js#L26-L47 |
44,491 | hayspec/framework | common/scripts/install-run.js | resolvePackageVersion | function resolvePackageVersion(rushCommonFolder, { name, version }) {
if (!version) {
version = '*'; // If no version is specified, use the latest version
}
if (version.match(/^[a-zA-Z0-9\-\+\.]+$/)) {
// If the version contains only characters that we recognize to be used in static version specifiers,
// pass the version through
return version;
}
else {
// version resolves to
try {
const rushTempFolder = ensureAndJoinPath(rushCommonFolder, 'temp');
const sourceNpmrcFolder = path.join(rushCommonFolder, 'config', 'rush');
syncNpmrc(sourceNpmrcFolder, rushTempFolder);
const npmPath = getNpmPath();
// This returns something that looks like:
// @microsoft/[email protected] '3.0.0'
// @microsoft/[email protected] '3.0.1'
// ...
// @microsoft/[email protected] '3.0.20'
// <blank line>
const npmVersionSpawnResult = childProcess.spawnSync(npmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier'], {
cwd: rushTempFolder,
stdio: []
});
if (npmVersionSpawnResult.status !== 0) {
throw new Error(`"npm view" returned error code ${npmVersionSpawnResult.status}`);
}
const npmViewVersionOutput = npmVersionSpawnResult.stdout.toString();
const versionLines = npmViewVersionOutput.split('\n').filter((line) => !!line);
const latestVersion = versionLines[versionLines.length - 1];
if (!latestVersion) {
throw new Error('No versions found for the specified version range.');
}
const versionMatches = latestVersion.match(/^.+\s\'(.+)\'$/);
if (!versionMatches) {
throw new Error(`Invalid npm output ${latestVersion}`);
}
return versionMatches[1];
}
catch (e) {
throw new Error(`Unable to resolve version ${version} of package ${name}: ${e}`);
}
}
} | javascript | function resolvePackageVersion(rushCommonFolder, { name, version }) {
if (!version) {
version = '*'; // If no version is specified, use the latest version
}
if (version.match(/^[a-zA-Z0-9\-\+\.]+$/)) {
// If the version contains only characters that we recognize to be used in static version specifiers,
// pass the version through
return version;
}
else {
// version resolves to
try {
const rushTempFolder = ensureAndJoinPath(rushCommonFolder, 'temp');
const sourceNpmrcFolder = path.join(rushCommonFolder, 'config', 'rush');
syncNpmrc(sourceNpmrcFolder, rushTempFolder);
const npmPath = getNpmPath();
// This returns something that looks like:
// @microsoft/[email protected] '3.0.0'
// @microsoft/[email protected] '3.0.1'
// ...
// @microsoft/[email protected] '3.0.20'
// <blank line>
const npmVersionSpawnResult = childProcess.spawnSync(npmPath, ['view', `${name}@${version}`, 'version', '--no-update-notifier'], {
cwd: rushTempFolder,
stdio: []
});
if (npmVersionSpawnResult.status !== 0) {
throw new Error(`"npm view" returned error code ${npmVersionSpawnResult.status}`);
}
const npmViewVersionOutput = npmVersionSpawnResult.stdout.toString();
const versionLines = npmViewVersionOutput.split('\n').filter((line) => !!line);
const latestVersion = versionLines[versionLines.length - 1];
if (!latestVersion) {
throw new Error('No versions found for the specified version range.');
}
const versionMatches = latestVersion.match(/^.+\s\'(.+)\'$/);
if (!versionMatches) {
throw new Error(`Invalid npm output ${latestVersion}`);
}
return versionMatches[1];
}
catch (e) {
throw new Error(`Unable to resolve version ${version} of package ${name}: ${e}`);
}
}
} | [
"function",
"resolvePackageVersion",
"(",
"rushCommonFolder",
",",
"{",
"name",
",",
"version",
"}",
")",
"{",
"if",
"(",
"!",
"version",
")",
"{",
"version",
"=",
"'*'",
";",
"// If no version is specified, use the latest version\r",
"}",
"if",
"(",
"version",
".",
"match",
"(",
"/",
"^[a-zA-Z0-9\\-\\+\\.]+$",
"/",
")",
")",
"{",
"// If the version contains only characters that we recognize to be used in static version specifiers,\r",
"// pass the version through\r",
"return",
"version",
";",
"}",
"else",
"{",
"// version resolves to\r",
"try",
"{",
"const",
"rushTempFolder",
"=",
"ensureAndJoinPath",
"(",
"rushCommonFolder",
",",
"'temp'",
")",
";",
"const",
"sourceNpmrcFolder",
"=",
"path",
".",
"join",
"(",
"rushCommonFolder",
",",
"'config'",
",",
"'rush'",
")",
";",
"syncNpmrc",
"(",
"sourceNpmrcFolder",
",",
"rushTempFolder",
")",
";",
"const",
"npmPath",
"=",
"getNpmPath",
"(",
")",
";",
"// This returns something that looks like:\r",
"// @microsoft/[email protected] '3.0.0'\r",
"// @microsoft/[email protected] '3.0.1'\r",
"// ...\r",
"// @microsoft/[email protected] '3.0.20'\r",
"// <blank line>\r",
"const",
"npmVersionSpawnResult",
"=",
"childProcess",
".",
"spawnSync",
"(",
"npmPath",
",",
"[",
"'view'",
",",
"`",
"${",
"name",
"}",
"${",
"version",
"}",
"`",
",",
"'version'",
",",
"'--no-update-notifier'",
"]",
",",
"{",
"cwd",
":",
"rushTempFolder",
",",
"stdio",
":",
"[",
"]",
"}",
")",
";",
"if",
"(",
"npmVersionSpawnResult",
".",
"status",
"!==",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"npmVersionSpawnResult",
".",
"status",
"}",
"`",
")",
";",
"}",
"const",
"npmViewVersionOutput",
"=",
"npmVersionSpawnResult",
".",
"stdout",
".",
"toString",
"(",
")",
";",
"const",
"versionLines",
"=",
"npmViewVersionOutput",
".",
"split",
"(",
"'\\n'",
")",
".",
"filter",
"(",
"(",
"line",
")",
"=>",
"!",
"!",
"line",
")",
";",
"const",
"latestVersion",
"=",
"versionLines",
"[",
"versionLines",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"latestVersion",
")",
"{",
"throw",
"new",
"Error",
"(",
"'No versions found for the specified version range.'",
")",
";",
"}",
"const",
"versionMatches",
"=",
"latestVersion",
".",
"match",
"(",
"/",
"^.+\\s\\'(.+)\\'$",
"/",
")",
";",
"if",
"(",
"!",
"versionMatches",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"latestVersion",
"}",
"`",
")",
";",
"}",
"return",
"versionMatches",
"[",
"1",
"]",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"version",
"}",
"${",
"name",
"}",
"${",
"e",
"}",
"`",
")",
";",
"}",
"}",
"}"
]
| Resolve a package specifier to a static version | [
"Resolve",
"a",
"package",
"specifier",
"to",
"a",
"static",
"version"
]
| 739e2fca2a99ee5cf9f10c658fe0fd0a81129803 | https://github.com/hayspec/framework/blob/739e2fca2a99ee5cf9f10c658fe0fd0a81129803/common/scripts/install-run.js#L51-L96 |
44,492 | hayspec/framework | common/scripts/install-run.js | getNpmPath | function getNpmPath() {
if (!_npmPath) {
try {
if (os.platform() === 'win32') {
// We're on Windows
const whereOutput = childProcess.execSync('where npm', { stdio: [] }).toString();
const lines = whereOutput.split(os.EOL).filter((line) => !!line);
// take the last result, we are looking for a .cmd command
// see https://github.com/Microsoft/web-build-tools/issues/759
_npmPath = lines[lines.length - 1];
}
else {
// We aren't on Windows - assume we're on *NIX or Darwin
_npmPath = childProcess.execSync('which npm', { stdio: [] }).toString();
}
}
catch (e) {
throw new Error(`Unable to determine the path to the NPM tool: ${e}`);
}
_npmPath = _npmPath.trim();
if (!fs.existsSync(_npmPath)) {
throw new Error('The NPM executable does not exist');
}
}
return _npmPath;
} | javascript | function getNpmPath() {
if (!_npmPath) {
try {
if (os.platform() === 'win32') {
// We're on Windows
const whereOutput = childProcess.execSync('where npm', { stdio: [] }).toString();
const lines = whereOutput.split(os.EOL).filter((line) => !!line);
// take the last result, we are looking for a .cmd command
// see https://github.com/Microsoft/web-build-tools/issues/759
_npmPath = lines[lines.length - 1];
}
else {
// We aren't on Windows - assume we're on *NIX or Darwin
_npmPath = childProcess.execSync('which npm', { stdio: [] }).toString();
}
}
catch (e) {
throw new Error(`Unable to determine the path to the NPM tool: ${e}`);
}
_npmPath = _npmPath.trim();
if (!fs.existsSync(_npmPath)) {
throw new Error('The NPM executable does not exist');
}
}
return _npmPath;
} | [
"function",
"getNpmPath",
"(",
")",
"{",
"if",
"(",
"!",
"_npmPath",
")",
"{",
"try",
"{",
"if",
"(",
"os",
".",
"platform",
"(",
")",
"===",
"'win32'",
")",
"{",
"// We're on Windows\r",
"const",
"whereOutput",
"=",
"childProcess",
".",
"execSync",
"(",
"'where npm'",
",",
"{",
"stdio",
":",
"[",
"]",
"}",
")",
".",
"toString",
"(",
")",
";",
"const",
"lines",
"=",
"whereOutput",
".",
"split",
"(",
"os",
".",
"EOL",
")",
".",
"filter",
"(",
"(",
"line",
")",
"=>",
"!",
"!",
"line",
")",
";",
"// take the last result, we are looking for a .cmd command\r",
"// see https://github.com/Microsoft/web-build-tools/issues/759\r",
"_npmPath",
"=",
"lines",
"[",
"lines",
".",
"length",
"-",
"1",
"]",
";",
"}",
"else",
"{",
"// We aren't on Windows - assume we're on *NIX or Darwin\r",
"_npmPath",
"=",
"childProcess",
".",
"execSync",
"(",
"'which npm'",
",",
"{",
"stdio",
":",
"[",
"]",
"}",
")",
".",
"toString",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"e",
"}",
"`",
")",
";",
"}",
"_npmPath",
"=",
"_npmPath",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"_npmPath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The NPM executable does not exist'",
")",
";",
"}",
"}",
"return",
"_npmPath",
";",
"}"
]
| Get the absolute path to the npm executable | [
"Get",
"the",
"absolute",
"path",
"to",
"the",
"npm",
"executable"
]
| 739e2fca2a99ee5cf9f10c658fe0fd0a81129803 | https://github.com/hayspec/framework/blob/739e2fca2a99ee5cf9f10c658fe0fd0a81129803/common/scripts/install-run.js#L101-L126 |
44,493 | justinwilaby/svg-path-interpolator | src/math/utils.js | rotatePoint | function rotatePoint(originX, originY, x, y, radiansX, radiansY) {
const v = {x: x - originX, y: y - originY};
const vx = (v.x * Math.cos(radiansX)) - (v.y * Math.sin(radiansX));
const vy = (v.x * Math.sin(radiansY)) + (v.y * Math.cos(radiansY));
return {x: vx + originX, y: vy + originY};
} | javascript | function rotatePoint(originX, originY, x, y, radiansX, radiansY) {
const v = {x: x - originX, y: y - originY};
const vx = (v.x * Math.cos(radiansX)) - (v.y * Math.sin(radiansX));
const vy = (v.x * Math.sin(radiansY)) + (v.y * Math.cos(radiansY));
return {x: vx + originX, y: vy + originY};
} | [
"function",
"rotatePoint",
"(",
"originX",
",",
"originY",
",",
"x",
",",
"y",
",",
"radiansX",
",",
"radiansY",
")",
"{",
"const",
"v",
"=",
"{",
"x",
":",
"x",
"-",
"originX",
",",
"y",
":",
"y",
"-",
"originY",
"}",
";",
"const",
"vx",
"=",
"(",
"v",
".",
"x",
"*",
"Math",
".",
"cos",
"(",
"radiansX",
")",
")",
"-",
"(",
"v",
".",
"y",
"*",
"Math",
".",
"sin",
"(",
"radiansX",
")",
")",
";",
"const",
"vy",
"=",
"(",
"v",
".",
"x",
"*",
"Math",
".",
"sin",
"(",
"radiansY",
")",
")",
"+",
"(",
"v",
".",
"y",
"*",
"Math",
".",
"cos",
"(",
"radiansY",
")",
")",
";",
"return",
"{",
"x",
":",
"vx",
"+",
"originX",
",",
"y",
":",
"vy",
"+",
"originY",
"}",
";",
"}"
]
| Rotates a point around the given origin
by the specified radians and returns the
rotated point.
@param originX The x coordinate of the point to rotate around.
@param originY The y coordinate of the point to rotate around.
@param x The x coordinate of the point to be rotated.
@param y The y coordinate of the point to be rotated.
@param radiansX Radians to rotate along the x axis.
@param radiansY Radians to rotate along the y axis.
@returns {Object} The point with the rotated coordinates. | [
"Rotates",
"a",
"point",
"around",
"the",
"given",
"origin",
"by",
"the",
"specified",
"radians",
"and",
"returns",
"the",
"rotated",
"point",
"."
]
| d88933a89e3dd8eeadd6f5ebb64b341b65d2e42a | https://github.com/justinwilaby/svg-path-interpolator/blob/d88933a89e3dd8eeadd6f5ebb64b341b65d2e42a/src/math/utils.js#L27-L32 |
44,494 | 5orenso/geo-lib | lib/geo-lib.js | isPointOnLineSegment | function isPointOnLineSegment(line1p1, line1p2, point) {
if (line1p2.lat <= Math.max(line1p1.lat, point.lat) && line1p2.lat >= Math.min(line1p1.lat, point.lat) &&
line1p2.lon <= Math.max(line1p1.lon, point.lon) && line1p2.lon >= Math.min(line1p1.lon, point.lon)) {
return true;
}
return false;
} | javascript | function isPointOnLineSegment(line1p1, line1p2, point) {
if (line1p2.lat <= Math.max(line1p1.lat, point.lat) && line1p2.lat >= Math.min(line1p1.lat, point.lat) &&
line1p2.lon <= Math.max(line1p1.lon, point.lon) && line1p2.lon >= Math.min(line1p1.lon, point.lon)) {
return true;
}
return false;
} | [
"function",
"isPointOnLineSegment",
"(",
"line1p1",
",",
"line1p2",
",",
"point",
")",
"{",
"if",
"(",
"line1p2",
".",
"lat",
"<=",
"Math",
".",
"max",
"(",
"line1p1",
".",
"lat",
",",
"point",
".",
"lat",
")",
"&&",
"line1p2",
".",
"lat",
">=",
"Math",
".",
"min",
"(",
"line1p1",
".",
"lat",
",",
"point",
".",
"lat",
")",
"&&",
"line1p2",
".",
"lon",
"<=",
"Math",
".",
"max",
"(",
"line1p1",
".",
"lon",
",",
"point",
".",
"lon",
")",
"&&",
"line1p2",
".",
"lon",
">=",
"Math",
".",
"min",
"(",
"line1p1",
".",
"lon",
",",
"point",
".",
"lon",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Given three colinear points line1p1, line1p2, point, the function checks if point lies on line segment 'line' | [
"Given",
"three",
"colinear",
"points",
"line1p1",
"line1p2",
"point",
"the",
"function",
"checks",
"if",
"point",
"lies",
"on",
"line",
"segment",
"line"
]
| be186a133cea75f77e65d3071c66899cbe2a792e | https://github.com/5orenso/geo-lib/blob/be186a133cea75f77e65d3071c66899cbe2a792e/lib/geo-lib.js#L236-L242 |
44,495 | reelyactive/barterer | lib/routes/whatat.js | retrieveWhatAtTransmitter | function retrieveWhatAtTransmitter(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
switch(req.accepts(['json', 'html'])) {
case 'html':
res.sendFile(path.resolve(__dirname + '/../../web/response.html'));
break;
default:
var options = {
query: 'receivedBy',
req: req,
ids: [req.params.id]
};
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.barterer.getDevicesState(options, rootUrl, queryPath,
function(response, status) {
res.status(status).json(response);
});
break;
}
} | javascript | function retrieveWhatAtTransmitter(req, res) {
if(redirect(req.params.id, '', '', res)) {
return;
}
switch(req.accepts(['json', 'html'])) {
case 'html':
res.sendFile(path.resolve(__dirname + '/../../web/response.html'));
break;
default:
var options = {
query: 'receivedBy',
req: req,
ids: [req.params.id]
};
var rootUrl = req.protocol + '://' + req.get('host');
var queryPath = req.originalUrl;
req.barterer.getDevicesState(options, rootUrl, queryPath,
function(response, status) {
res.status(status).json(response);
});
break;
}
} | [
"function",
"retrieveWhatAtTransmitter",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"redirect",
"(",
"req",
".",
"params",
".",
"id",
",",
"''",
",",
"''",
",",
"res",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"req",
".",
"accepts",
"(",
"[",
"'json'",
",",
"'html'",
"]",
")",
")",
"{",
"case",
"'html'",
":",
"res",
".",
"sendFile",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
"+",
"'/../../web/response.html'",
")",
")",
";",
"break",
";",
"default",
":",
"var",
"options",
"=",
"{",
"query",
":",
"'receivedBy'",
",",
"req",
":",
"req",
",",
"ids",
":",
"[",
"req",
".",
"params",
".",
"id",
"]",
"}",
";",
"var",
"rootUrl",
"=",
"req",
".",
"protocol",
"+",
"'://'",
"+",
"req",
".",
"get",
"(",
"'host'",
")",
";",
"var",
"queryPath",
"=",
"req",
".",
"originalUrl",
";",
"req",
".",
"barterer",
".",
"getDevicesState",
"(",
"options",
",",
"rootUrl",
",",
"queryPath",
",",
"function",
"(",
"response",
",",
"status",
")",
"{",
"res",
".",
"status",
"(",
"status",
")",
".",
"json",
"(",
"response",
")",
";",
"}",
")",
";",
"break",
";",
"}",
"}"
]
| Retrieve what is decoded by a specific receiver device.
@param {Object} req The HTTP request.
@param {Object} res The HTTP result. | [
"Retrieve",
"what",
"is",
"decoded",
"by",
"a",
"specific",
"receiver",
"device",
"."
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/routes/whatat.js#L24-L47 |
44,496 | reelyactive/barterer | lib/server.js | BartererServer | function BartererServer(options) {
options = options || {};
var specifiedHttpPort = options.httpPort || HTTP_PORT;
var httpPort = process.env.PORT || specifiedHttpPort;
var app = express();
var instance = new Barterer(options);
options.app = app;
instance.configureRoutes(options);
app.listen(httpPort, function() {
console.log('barterer is listening on port', httpPort);
});
return instance;
} | javascript | function BartererServer(options) {
options = options || {};
var specifiedHttpPort = options.httpPort || HTTP_PORT;
var httpPort = process.env.PORT || specifiedHttpPort;
var app = express();
var instance = new Barterer(options);
options.app = app;
instance.configureRoutes(options);
app.listen(httpPort, function() {
console.log('barterer is listening on port', httpPort);
});
return instance;
} | [
"function",
"BartererServer",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"specifiedHttpPort",
"=",
"options",
".",
"httpPort",
"||",
"HTTP_PORT",
";",
"var",
"httpPort",
"=",
"process",
".",
"env",
".",
"PORT",
"||",
"specifiedHttpPort",
";",
"var",
"app",
"=",
"express",
"(",
")",
";",
"var",
"instance",
"=",
"new",
"Barterer",
"(",
"options",
")",
";",
"options",
".",
"app",
"=",
"app",
";",
"instance",
".",
"configureRoutes",
"(",
"options",
")",
";",
"app",
".",
"listen",
"(",
"httpPort",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'barterer is listening on port'",
",",
"httpPort",
")",
";",
"}",
")",
";",
"return",
"instance",
";",
"}"
]
| BartererServer Class
Server for barterer, returns an instance of barterer with its own Express
server listening on the given port.
@param {Object} options The options as a JSON object.
@constructor | [
"BartererServer",
"Class",
"Server",
"for",
"barterer",
"returns",
"an",
"instance",
"of",
"barterer",
"with",
"its",
"own",
"Express",
"server",
"listening",
"on",
"the",
"given",
"port",
"."
]
| ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c | https://github.com/reelyactive/barterer/blob/ab4caa541b13c78cca3f4df9dcfc8f17c1c14c2c/lib/server.js#L22-L38 |
44,497 | gritzko/stream-url | src/ZeroServer.js | ZeroServer | function ZeroServer (url, options, callback) {
EventEmitter.call(this);
this.id = null;
//this.streams = {};
if (url) {
this.listen(url, options, callback);
}
} | javascript | function ZeroServer (url, options, callback) {
EventEmitter.call(this);
this.id = null;
//this.streams = {};
if (url) {
this.listen(url, options, callback);
}
} | [
"function",
"ZeroServer",
"(",
"url",
",",
"options",
",",
"callback",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"id",
"=",
"null",
";",
"//this.streams = {};",
"if",
"(",
"url",
")",
"{",
"this",
".",
"listen",
"(",
"url",
",",
"options",
",",
"callback",
")",
";",
"}",
"}"
]
| Fake server for ZeroStreams. | [
"Fake",
"server",
"for",
"ZeroStreams",
"."
]
| 1291ed6a628fe4935a9f960e204f26771f13072b | https://github.com/gritzko/stream-url/blob/1291ed6a628fe4935a9f960e204f26771f13072b/src/ZeroServer.js#L6-L13 |
44,498 | ysugimoto/js-dependency-visualizer | visualize/d3Renderer.js | D3Renderer | function D3Renderer(view, graphData, options) {
/**
* View stack
*
* @property view
* @param Array
*/
this.view = view;
/**
* graph Data
*
* @property graph
* @param Object
*/
this.graph = graphData;
/**
* (Default merged) option
*
* @property option
* @type Object
*/
this.option = mixin(defaultOptions, options || {});
/**
* Canvas container
*
* @property container
* @type d3-element-array
*/
this.container = null;
/**
* SVG container
*
* @property svg
* @type d3-element-array
*/
this.svg = null;
/**
* force reloader
*
* @property force
* @type d3-element-array
*/
this.force = null;
/**
* link elements
*
* @property link
* @type d3-element-array
*/
this.link = null;
/**
* Node elements
*
* @property node
* @type d3-element-array
*/
this.node = null;
/**
* test elements
*
* @property text
* @type d3-element-array
*/
this.text = null;
/**
* d3 color object
*
* @property color
* @type Object
*/
this.color = d3.scale.category20();
/**
* selected index
*
* @property selectedIdx
* @type Number
* @default -1
*/
this.selectedIdx = -1;
/**
* selected type
*
* @property selectedType
* @type String
* @default "normal"
*/
this.selectedType = 'normal';
/**
* selected object
*
* @property selectedObject
* @type Object
*/
this.selectedObject = {};
// Scope trick
this.radius = this.radius();
this.linkLine = this.linkLine();
} | javascript | function D3Renderer(view, graphData, options) {
/**
* View stack
*
* @property view
* @param Array
*/
this.view = view;
/**
* graph Data
*
* @property graph
* @param Object
*/
this.graph = graphData;
/**
* (Default merged) option
*
* @property option
* @type Object
*/
this.option = mixin(defaultOptions, options || {});
/**
* Canvas container
*
* @property container
* @type d3-element-array
*/
this.container = null;
/**
* SVG container
*
* @property svg
* @type d3-element-array
*/
this.svg = null;
/**
* force reloader
*
* @property force
* @type d3-element-array
*/
this.force = null;
/**
* link elements
*
* @property link
* @type d3-element-array
*/
this.link = null;
/**
* Node elements
*
* @property node
* @type d3-element-array
*/
this.node = null;
/**
* test elements
*
* @property text
* @type d3-element-array
*/
this.text = null;
/**
* d3 color object
*
* @property color
* @type Object
*/
this.color = d3.scale.category20();
/**
* selected index
*
* @property selectedIdx
* @type Number
* @default -1
*/
this.selectedIdx = -1;
/**
* selected type
*
* @property selectedType
* @type String
* @default "normal"
*/
this.selectedType = 'normal';
/**
* selected object
*
* @property selectedObject
* @type Object
*/
this.selectedObject = {};
// Scope trick
this.radius = this.radius();
this.linkLine = this.linkLine();
} | [
"function",
"D3Renderer",
"(",
"view",
",",
"graphData",
",",
"options",
")",
"{",
"/**\n * View stack\n *\n * @property view\n * @param Array\n */",
"this",
".",
"view",
"=",
"view",
";",
"/**\n * graph Data\n *\n * @property graph\n * @param Object\n */",
"this",
".",
"graph",
"=",
"graphData",
";",
"/**\n * (Default merged) option\n *\n * @property option\n * @type Object\n */",
"this",
".",
"option",
"=",
"mixin",
"(",
"defaultOptions",
",",
"options",
"||",
"{",
"}",
")",
";",
"/**\n * Canvas container\n *\n * @property container\n * @type d3-element-array\n */",
"this",
".",
"container",
"=",
"null",
";",
"/**\n * SVG container\n *\n * @property svg\n * @type d3-element-array\n */",
"this",
".",
"svg",
"=",
"null",
";",
"/**\n * force reloader\n *\n * @property force\n * @type d3-element-array\n */",
"this",
".",
"force",
"=",
"null",
";",
"/**\n * link elements\n *\n * @property link\n * @type d3-element-array\n */",
"this",
".",
"link",
"=",
"null",
";",
"/**\n * Node elements\n *\n * @property node\n * @type d3-element-array\n */",
"this",
".",
"node",
"=",
"null",
";",
"/**\n * test elements\n *\n * @property text\n * @type d3-element-array\n */",
"this",
".",
"text",
"=",
"null",
";",
"/**\n * d3 color object\n *\n * @property color\n * @type Object\n */",
"this",
".",
"color",
"=",
"d3",
".",
"scale",
".",
"category20",
"(",
")",
";",
"/**\n * selected index\n *\n * @property selectedIdx\n * @type Number\n * @default -1\n */",
"this",
".",
"selectedIdx",
"=",
"-",
"1",
";",
"/**\n * selected type\n *\n * @property selectedType\n * @type String\n * @default \"normal\"\n */",
"this",
".",
"selectedType",
"=",
"'normal'",
";",
"/**\n * selected object\n *\n * @property selectedObject\n * @type Object\n */",
"this",
".",
"selectedObject",
"=",
"{",
"}",
";",
"// Scope trick",
"this",
".",
"radius",
"=",
"this",
".",
"radius",
"(",
")",
";",
"this",
".",
"linkLine",
"=",
"this",
".",
"linkLine",
"(",
")",
";",
"}"
]
| D3Render main class
@class D3Renderer
@constructor
@param {Array} view : d3.select() returns
@param {Object} graphData : DependencyParser::parse() returns
@param {Object} options | [
"D3Render",
"main",
"class"
]
| 0dadd6986f5b585cf70ad6925c5aac33cdc15a69 | https://github.com/ysugimoto/js-dependency-visualizer/blob/0dadd6986f5b585cf70ad6925c5aac33cdc15a69/visualize/d3Renderer.js#L48-L160 |
44,499 | lynx-json/lynx-docs | src/cli/stream-utils.js | function (vinyl) {
return path.extname(vinyl.path) === ".lnxs" ? options.spec.dir : options.output;
} | javascript | function (vinyl) {
return path.extname(vinyl.path) === ".lnxs" ? options.spec.dir : options.output;
} | [
"function",
"(",
"vinyl",
")",
"{",
"return",
"path",
".",
"extname",
"(",
"vinyl",
".",
"path",
")",
"===",
"\".lnxs\"",
"?",
"options",
".",
"spec",
".",
"dir",
":",
"options",
".",
"output",
";",
"}"
]
| convert from vinyl stream to regular stream | [
"convert",
"from",
"vinyl",
"stream",
"to",
"regular",
"stream"
]
| 7f450fc348fedb4ecd16adeaac0e54bedebadec0 | https://github.com/lynx-json/lynx-docs/blob/7f450fc348fedb4ecd16adeaac0e54bedebadec0/src/cli/stream-utils.js#L17-L19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.