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
|
---|---|---|---|---|---|---|---|---|---|---|---|
37,800 |
lammas/tree-traversal
|
tree-traversal.js
|
traverseDepthFirst
|
function traverseDepthFirst(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
userdataAccessor: function(node, userdata) { return userdata; },
onNode: function(node, callback, userdata) { callback(); },
onComplete: function(rootNode) {},
userdata: null
}, options);
var stack = [];
stack.push([rootNode, options.userdata]);
(function next() {
if (stack.length == 0) {
options.onComplete(rootNode);
return;
}
var top = stack.pop();
var node = top[0];
var data = top[1];
options.onNode(node, function() {
var subnodeData = options.userdataAccessor(node, data);
var subnodes = options.subnodesAccessor(node);
async.eachSeries(subnodes,
function(subnode, nextNode) {
stack.push([subnode, subnodeData]);
async.setImmediate(nextNode);
},
function() {
async.setImmediate(next);
}
);
}, data);
})();
}
|
javascript
|
function traverseDepthFirst(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
userdataAccessor: function(node, userdata) { return userdata; },
onNode: function(node, callback, userdata) { callback(); },
onComplete: function(rootNode) {},
userdata: null
}, options);
var stack = [];
stack.push([rootNode, options.userdata]);
(function next() {
if (stack.length == 0) {
options.onComplete(rootNode);
return;
}
var top = stack.pop();
var node = top[0];
var data = top[1];
options.onNode(node, function() {
var subnodeData = options.userdataAccessor(node, data);
var subnodes = options.subnodesAccessor(node);
async.eachSeries(subnodes,
function(subnode, nextNode) {
stack.push([subnode, subnodeData]);
async.setImmediate(nextNode);
},
function() {
async.setImmediate(next);
}
);
}, data);
})();
}
|
[
"function",
"traverseDepthFirst",
"(",
"rootNode",
",",
"options",
")",
"{",
"options",
"=",
"extend",
"(",
"{",
"subnodesAccessor",
":",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"subnodes",
";",
"}",
",",
"userdataAccessor",
":",
"function",
"(",
"node",
",",
"userdata",
")",
"{",
"return",
"userdata",
";",
"}",
",",
"onNode",
":",
"function",
"(",
"node",
",",
"callback",
",",
"userdata",
")",
"{",
"callback",
"(",
")",
";",
"}",
",",
"onComplete",
":",
"function",
"(",
"rootNode",
")",
"{",
"}",
",",
"userdata",
":",
"null",
"}",
",",
"options",
")",
";",
"var",
"stack",
"=",
"[",
"]",
";",
"stack",
".",
"push",
"(",
"[",
"rootNode",
",",
"options",
".",
"userdata",
"]",
")",
";",
"(",
"function",
"next",
"(",
")",
"{",
"if",
"(",
"stack",
".",
"length",
"==",
"0",
")",
"{",
"options",
".",
"onComplete",
"(",
"rootNode",
")",
";",
"return",
";",
"}",
"var",
"top",
"=",
"stack",
".",
"pop",
"(",
")",
";",
"var",
"node",
"=",
"top",
"[",
"0",
"]",
";",
"var",
"data",
"=",
"top",
"[",
"1",
"]",
";",
"options",
".",
"onNode",
"(",
"node",
",",
"function",
"(",
")",
"{",
"var",
"subnodeData",
"=",
"options",
".",
"userdataAccessor",
"(",
"node",
",",
"data",
")",
";",
"var",
"subnodes",
"=",
"options",
".",
"subnodesAccessor",
"(",
"node",
")",
";",
"async",
".",
"eachSeries",
"(",
"subnodes",
",",
"function",
"(",
"subnode",
",",
"nextNode",
")",
"{",
"stack",
".",
"push",
"(",
"[",
"subnode",
",",
"subnodeData",
"]",
")",
";",
"async",
".",
"setImmediate",
"(",
"nextNode",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"async",
".",
"setImmediate",
"(",
"next",
")",
";",
"}",
")",
";",
"}",
",",
"data",
")",
";",
"}",
")",
"(",
")",
";",
"}"
] |
Asynchronously traverses the tree depth first.
|
[
"Asynchronously",
"traverses",
"the",
"tree",
"depth",
"first",
"."
] |
ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47
|
https://github.com/lammas/tree-traversal/blob/ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47/tree-traversal.js#L90-L126
|
37,801 |
lammas/tree-traversal
|
tree-traversal.js
|
traverseDepthFirstSync
|
function traverseDepthFirstSync(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
userdataAccessor: function(node, userdata) { return userdata; },
onNode: function(node, userdata) {},
userdata: null
}, options);
var stack = [];
stack.push([rootNode, options.userdata]);
while (stack.length>0) {
var top = stack.pop();
var node = top[0];
var data = top[1];
options.onNode(node, data);
var subnodeData = options.userdataAccessor(node, data);
var subnodes = options.subnodesAccessor(node);
for (var i=0; i<subnodes.length; i++)
stack.push([subnodes[i], subnodeData]);
}
return rootNode;
}
|
javascript
|
function traverseDepthFirstSync(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
userdataAccessor: function(node, userdata) { return userdata; },
onNode: function(node, userdata) {},
userdata: null
}, options);
var stack = [];
stack.push([rootNode, options.userdata]);
while (stack.length>0) {
var top = stack.pop();
var node = top[0];
var data = top[1];
options.onNode(node, data);
var subnodeData = options.userdataAccessor(node, data);
var subnodes = options.subnodesAccessor(node);
for (var i=0; i<subnodes.length; i++)
stack.push([subnodes[i], subnodeData]);
}
return rootNode;
}
|
[
"function",
"traverseDepthFirstSync",
"(",
"rootNode",
",",
"options",
")",
"{",
"options",
"=",
"extend",
"(",
"{",
"subnodesAccessor",
":",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"subnodes",
";",
"}",
",",
"userdataAccessor",
":",
"function",
"(",
"node",
",",
"userdata",
")",
"{",
"return",
"userdata",
";",
"}",
",",
"onNode",
":",
"function",
"(",
"node",
",",
"userdata",
")",
"{",
"}",
",",
"userdata",
":",
"null",
"}",
",",
"options",
")",
";",
"var",
"stack",
"=",
"[",
"]",
";",
"stack",
".",
"push",
"(",
"[",
"rootNode",
",",
"options",
".",
"userdata",
"]",
")",
";",
"while",
"(",
"stack",
".",
"length",
">",
"0",
")",
"{",
"var",
"top",
"=",
"stack",
".",
"pop",
"(",
")",
";",
"var",
"node",
"=",
"top",
"[",
"0",
"]",
";",
"var",
"data",
"=",
"top",
"[",
"1",
"]",
";",
"options",
".",
"onNode",
"(",
"node",
",",
"data",
")",
";",
"var",
"subnodeData",
"=",
"options",
".",
"userdataAccessor",
"(",
"node",
",",
"data",
")",
";",
"var",
"subnodes",
"=",
"options",
".",
"subnodesAccessor",
"(",
"node",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"subnodes",
".",
"length",
";",
"i",
"++",
")",
"stack",
".",
"push",
"(",
"[",
"subnodes",
"[",
"i",
"]",
",",
"subnodeData",
"]",
")",
";",
"}",
"return",
"rootNode",
";",
"}"
] |
Synchronously traverses the tree depth first.
|
[
"Synchronously",
"traverses",
"the",
"tree",
"depth",
"first",
"."
] |
ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47
|
https://github.com/lammas/tree-traversal/blob/ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47/tree-traversal.js#L131-L154
|
37,802 |
lammas/tree-traversal
|
tree-traversal.js
|
traverseRecursive
|
function traverseRecursive(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
onNode: function(node, callback, userdata) {},
onComplete: function(rootNode) {},
userdata: null
}, options);
(function visitNode(node, callback) {
var subnodes = options.subnodesAccessor(node);
async.eachSeries(subnodes, function(subnode, next) {
visitNode(subnode, function() {
async.setImmediate(next);
});
},
function() {
options.onNode(node, function() {
async.setImmediate(callback);
}, options.userdata);
});
})(rootNode, function() {
options.onComplete(rootNode);
});
}
|
javascript
|
function traverseRecursive(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
onNode: function(node, callback, userdata) {},
onComplete: function(rootNode) {},
userdata: null
}, options);
(function visitNode(node, callback) {
var subnodes = options.subnodesAccessor(node);
async.eachSeries(subnodes, function(subnode, next) {
visitNode(subnode, function() {
async.setImmediate(next);
});
},
function() {
options.onNode(node, function() {
async.setImmediate(callback);
}, options.userdata);
});
})(rootNode, function() {
options.onComplete(rootNode);
});
}
|
[
"function",
"traverseRecursive",
"(",
"rootNode",
",",
"options",
")",
"{",
"options",
"=",
"extend",
"(",
"{",
"subnodesAccessor",
":",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"subnodes",
";",
"}",
",",
"onNode",
":",
"function",
"(",
"node",
",",
"callback",
",",
"userdata",
")",
"{",
"}",
",",
"onComplete",
":",
"function",
"(",
"rootNode",
")",
"{",
"}",
",",
"userdata",
":",
"null",
"}",
",",
"options",
")",
";",
"(",
"function",
"visitNode",
"(",
"node",
",",
"callback",
")",
"{",
"var",
"subnodes",
"=",
"options",
".",
"subnodesAccessor",
"(",
"node",
")",
";",
"async",
".",
"eachSeries",
"(",
"subnodes",
",",
"function",
"(",
"subnode",
",",
"next",
")",
"{",
"visitNode",
"(",
"subnode",
",",
"function",
"(",
")",
"{",
"async",
".",
"setImmediate",
"(",
"next",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"options",
".",
"onNode",
"(",
"node",
",",
"function",
"(",
")",
"{",
"async",
".",
"setImmediate",
"(",
"callback",
")",
";",
"}",
",",
"options",
".",
"userdata",
")",
";",
"}",
")",
";",
"}",
")",
"(",
"rootNode",
",",
"function",
"(",
")",
"{",
"options",
".",
"onComplete",
"(",
"rootNode",
")",
";",
"}",
")",
";",
"}"
] |
Asynchronously traverses the tree recursively.
|
[
"Asynchronously",
"traverses",
"the",
"tree",
"recursively",
"."
] |
ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47
|
https://github.com/lammas/tree-traversal/blob/ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47/tree-traversal.js#L160-L183
|
37,803 |
lammas/tree-traversal
|
tree-traversal.js
|
traverseRecursiveSync
|
function traverseRecursiveSync(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
onNode: function(node, userdata) {},
userdata: null
}, options);
(function visitNode(node) {
var subnodes = options.subnodesAccessor(node);
for (var i=0; i<subnodes.length; i++) {
visitNode(subnodes[i]);
}
options.onNode(node, options.userdata);
})(rootNode);
return rootNode;
}
|
javascript
|
function traverseRecursiveSync(rootNode, options) {
options = extend({
subnodesAccessor: function(node) { return node.subnodes; },
onNode: function(node, userdata) {},
userdata: null
}, options);
(function visitNode(node) {
var subnodes = options.subnodesAccessor(node);
for (var i=0; i<subnodes.length; i++) {
visitNode(subnodes[i]);
}
options.onNode(node, options.userdata);
})(rootNode);
return rootNode;
}
|
[
"function",
"traverseRecursiveSync",
"(",
"rootNode",
",",
"options",
")",
"{",
"options",
"=",
"extend",
"(",
"{",
"subnodesAccessor",
":",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"subnodes",
";",
"}",
",",
"onNode",
":",
"function",
"(",
"node",
",",
"userdata",
")",
"{",
"}",
",",
"userdata",
":",
"null",
"}",
",",
"options",
")",
";",
"(",
"function",
"visitNode",
"(",
"node",
")",
"{",
"var",
"subnodes",
"=",
"options",
".",
"subnodesAccessor",
"(",
"node",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"subnodes",
".",
"length",
";",
"i",
"++",
")",
"{",
"visitNode",
"(",
"subnodes",
"[",
"i",
"]",
")",
";",
"}",
"options",
".",
"onNode",
"(",
"node",
",",
"options",
".",
"userdata",
")",
";",
"}",
")",
"(",
"rootNode",
")",
";",
"return",
"rootNode",
";",
"}"
] |
Synchronously traverses the tree recursively.
|
[
"Synchronously",
"traverses",
"the",
"tree",
"recursively",
"."
] |
ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47
|
https://github.com/lammas/tree-traversal/blob/ca02a2a4308eb6cff27b0dd030fd8ccfb36b6e47/tree-traversal.js#L188-L204
|
37,804 |
dalekjs/dalek-reporter-junit
|
index.js
|
Reporter
|
function Reporter (opts) {
this.events = opts.events;
this.config = opts.config;
this.testCount = 0;
this.testIdx = -1;
this.variationCount = -1;
this.data = {};
this.data.tests = [];
this.browser = null;
var defaultReportFolder = 'report';
this.dest = this.config.get('junit-reporter') && this.config.get('junit-reporter').dest ? this.config.get('junit-reporter').dest : defaultReportFolder;
// prepare base xml
this.xml = [
{
name: 'resource',
attrs: {
name:'DalekJSTest'
},
children: []
}
];
this.startListening();
}
|
javascript
|
function Reporter (opts) {
this.events = opts.events;
this.config = opts.config;
this.testCount = 0;
this.testIdx = -1;
this.variationCount = -1;
this.data = {};
this.data.tests = [];
this.browser = null;
var defaultReportFolder = 'report';
this.dest = this.config.get('junit-reporter') && this.config.get('junit-reporter').dest ? this.config.get('junit-reporter').dest : defaultReportFolder;
// prepare base xml
this.xml = [
{
name: 'resource',
attrs: {
name:'DalekJSTest'
},
children: []
}
];
this.startListening();
}
|
[
"function",
"Reporter",
"(",
"opts",
")",
"{",
"this",
".",
"events",
"=",
"opts",
".",
"events",
";",
"this",
".",
"config",
"=",
"opts",
".",
"config",
";",
"this",
".",
"testCount",
"=",
"0",
";",
"this",
".",
"testIdx",
"=",
"-",
"1",
";",
"this",
".",
"variationCount",
"=",
"-",
"1",
";",
"this",
".",
"data",
"=",
"{",
"}",
";",
"this",
".",
"data",
".",
"tests",
"=",
"[",
"]",
";",
"this",
".",
"browser",
"=",
"null",
";",
"var",
"defaultReportFolder",
"=",
"'report'",
";",
"this",
".",
"dest",
"=",
"this",
".",
"config",
".",
"get",
"(",
"'junit-reporter'",
")",
"&&",
"this",
".",
"config",
".",
"get",
"(",
"'junit-reporter'",
")",
".",
"dest",
"?",
"this",
".",
"config",
".",
"get",
"(",
"'junit-reporter'",
")",
".",
"dest",
":",
"defaultReportFolder",
";",
"// prepare base xml",
"this",
".",
"xml",
"=",
"[",
"{",
"name",
":",
"'resource'",
",",
"attrs",
":",
"{",
"name",
":",
"'DalekJSTest'",
"}",
",",
"children",
":",
"[",
"]",
"}",
"]",
";",
"this",
".",
"startListening",
"(",
")",
";",
"}"
] |
The jUnit reporter can produce a jUnit compatible file with the results of your testrun,
this reporter enables you to use daleks testresults within a CI environment like Jenkins.
The reporter can be installed with the following command:
```bash
$ npm install dalek-reporter-junit --save-dev
```
The file will follow the jUnit XML format:
```html
<?xml version="1.0" encoding="utf-8"?>
<resource name="DalekJSTest">
<testsuite start="1375125067" name="Click - DalekJS guinea pig [Phantomjs]" end="1375125067" totalTests="1">
<testcase start="1375125067" name="Can click a select option (OK, jQuery style, no message)" end="1375125067" result="pass">
<variation start="1375125067" name="val" end="1375125067">
<severity>pass</severity>
<description><![CDATA[David is the favourite]]></description>
<resource>DalekJSTest</resource>
</variation>
<variation start="1375125067" name="val" end="1375125067">
<severity>pass</severity>
<description><![CDATA[Matt is now my favourite, bow ties are cool]]></description>
<resource>DalekJSTest</resource>
</variation>
</testcase>
</testsuite>
</resource>
```
By default the file will be written to `report/dalek.xml`,
you can change this by adding a config option to the your Dalekfile
```javascript
"junit-reporter": {
"dest": "your/folder/your_file.xml"
}
```
If you would like to use the reporter (in addition to the std. console reporter),
you can start dalek with a special command line argument
```bash
$ dalek your_test.js -r console,junit
```
or you can add it to your Dalekfile
```javascript
"reporter": ["console", "junit"]
```
@class Reporter
@constructor
@part JUnit
@api
|
[
"The",
"jUnit",
"reporter",
"can",
"produce",
"a",
"jUnit",
"compatible",
"file",
"with",
"the",
"results",
"of",
"your",
"testrun",
"this",
"reporter",
"enables",
"you",
"to",
"use",
"daleks",
"testresults",
"within",
"a",
"CI",
"environment",
"like",
"Jenkins",
"."
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L95-L120
|
37,805 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (name) {
this.testCount = 0;
this.testIdx++;
this.xml[0].children.push({
name: 'testsuite',
children: [],
attrs: {
name: name + ' [' + this.browser + ']',
}
});
return this;
}
|
javascript
|
function (name) {
this.testCount = 0;
this.testIdx++;
this.xml[0].children.push({
name: 'testsuite',
children: [],
attrs: {
name: name + ' [' + this.browser + ']',
}
});
return this;
}
|
[
"function",
"(",
"name",
")",
"{",
"this",
".",
"testCount",
"=",
"0",
";",
"this",
".",
"testIdx",
"++",
";",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
".",
"push",
"(",
"{",
"name",
":",
"'testsuite'",
",",
"children",
":",
"[",
"]",
",",
"attrs",
":",
"{",
"name",
":",
"name",
"+",
"' ['",
"+",
"this",
".",
"browser",
"+",
"']'",
",",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Generates XML skeleton for testsuites
@method testsuiteStarted
@param {string} name Testsuite name
@chainable
|
[
"Generates",
"XML",
"skeleton",
"for",
"testsuites"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L175-L186
|
|
37,806 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (data) {
if (! data.success) {
//var timestamp = Math.round(new Date().getTime() / 1000);
this.xml[0].children[this.testIdx].children[this.testCount].children.push({
name: 'failure',
attrs: {
name: data.type,
message: (data.message ? data.message : 'Expected: ' + data.expected + 'Actual: ' + data.value)
}
});
//if (this.variationCount > -1 && this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount]) {
//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;
//}
this.variationCount++;
}
return this;
}
|
javascript
|
function (data) {
if (! data.success) {
//var timestamp = Math.round(new Date().getTime() / 1000);
this.xml[0].children[this.testIdx].children[this.testCount].children.push({
name: 'failure',
attrs: {
name: data.type,
message: (data.message ? data.message : 'Expected: ' + data.expected + 'Actual: ' + data.value)
}
});
//if (this.variationCount > -1 && this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount]) {
//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;
//}
this.variationCount++;
}
return this;
}
|
[
"function",
"(",
"data",
")",
"{",
"if",
"(",
"!",
"data",
".",
"success",
")",
"{",
"//var timestamp = Math.round(new Date().getTime() / 1000);",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"this",
".",
"testIdx",
"]",
".",
"children",
"[",
"this",
".",
"testCount",
"]",
".",
"children",
".",
"push",
"(",
"{",
"name",
":",
"'failure'",
",",
"attrs",
":",
"{",
"name",
":",
"data",
".",
"type",
",",
"message",
":",
"(",
"data",
".",
"message",
"?",
"data",
".",
"message",
":",
"'Expected: '",
"+",
"data",
".",
"expected",
"+",
"'Actual: '",
"+",
"data",
".",
"value",
")",
"}",
"}",
")",
";",
"//if (this.variationCount > -1 && this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount]) {",
"//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;",
"//}",
"this",
".",
"variationCount",
"++",
";",
"}",
"return",
"this",
";",
"}"
] |
Generates XML skeleton for an assertion
@method assertion
@param {object} data Event data
@chainable
|
[
"Generates",
"XML",
"skeleton",
"for",
"an",
"assertion"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L208-L227
|
|
37,807 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (data) {
this.variationCount = -1;
this.xml[0].children[this.testIdx].children.push({
name: 'testcase',
children: [],
attrs: {
classname: this.xml[0].children[this.testIdx].attrs.name,
name: data.name
}
});
return this;
}
|
javascript
|
function (data) {
this.variationCount = -1;
this.xml[0].children[this.testIdx].children.push({
name: 'testcase',
children: [],
attrs: {
classname: this.xml[0].children[this.testIdx].attrs.name,
name: data.name
}
});
return this;
}
|
[
"function",
"(",
"data",
")",
"{",
"this",
".",
"variationCount",
"=",
"-",
"1",
";",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"this",
".",
"testIdx",
"]",
".",
"children",
".",
"push",
"(",
"{",
"name",
":",
"'testcase'",
",",
"children",
":",
"[",
"]",
",",
"attrs",
":",
"{",
"classname",
":",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"this",
".",
"testIdx",
"]",
".",
"attrs",
".",
"name",
",",
"name",
":",
"data",
".",
"name",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Generates XML skeleton for a testcase
@method testStarted
@param {object} data Event data
@chainable
|
[
"Generates",
"XML",
"skeleton",
"for",
"a",
"testcase"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L237-L249
|
|
37,808 |
dalekjs/dalek-reporter-junit
|
index.js
|
function () {
//var timestamp = Math.round(new Date().getTime() / 1000);
if (this._checkNodeAttributes(this.testIdx, this.testCount)) {
this.xml[0].children[this.testIdx].children[this.testCount].attrs = {};
}
//this.xml[0].children[this.testIdx].children[this.testCount].attrs.end = timestamp;
//this.xml[0].children[this.testIdx].children[this.testCount].attrs.result = data.status ? 'Passed' : 'Failed';
if (this.variationCount > -1) {
if (this._checkNodeAttributes(this.testIdx, this.testCount, this.variationCount)) {
this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs = {};
}
//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;
}
this.testCount++;
this.variationCount = -1;
return this;
}
|
javascript
|
function () {
//var timestamp = Math.round(new Date().getTime() / 1000);
if (this._checkNodeAttributes(this.testIdx, this.testCount)) {
this.xml[0].children[this.testIdx].children[this.testCount].attrs = {};
}
//this.xml[0].children[this.testIdx].children[this.testCount].attrs.end = timestamp;
//this.xml[0].children[this.testIdx].children[this.testCount].attrs.result = data.status ? 'Passed' : 'Failed';
if (this.variationCount > -1) {
if (this._checkNodeAttributes(this.testIdx, this.testCount, this.variationCount)) {
this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs = {};
}
//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;
}
this.testCount++;
this.variationCount = -1;
return this;
}
|
[
"function",
"(",
")",
"{",
"//var timestamp = Math.round(new Date().getTime() / 1000);",
"if",
"(",
"this",
".",
"_checkNodeAttributes",
"(",
"this",
".",
"testIdx",
",",
"this",
".",
"testCount",
")",
")",
"{",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"this",
".",
"testIdx",
"]",
".",
"children",
"[",
"this",
".",
"testCount",
"]",
".",
"attrs",
"=",
"{",
"}",
";",
"}",
"//this.xml[0].children[this.testIdx].children[this.testCount].attrs.end = timestamp;",
"//this.xml[0].children[this.testIdx].children[this.testCount].attrs.result = data.status ? 'Passed' : 'Failed';",
"if",
"(",
"this",
".",
"variationCount",
">",
"-",
"1",
")",
"{",
"if",
"(",
"this",
".",
"_checkNodeAttributes",
"(",
"this",
".",
"testIdx",
",",
"this",
".",
"testCount",
",",
"this",
".",
"variationCount",
")",
")",
"{",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"this",
".",
"testIdx",
"]",
".",
"children",
"[",
"this",
".",
"testCount",
"]",
".",
"children",
"[",
"this",
".",
"variationCount",
"]",
".",
"attrs",
"=",
"{",
"}",
";",
"}",
"//this.xml[0].children[this.testIdx].children[this.testCount].children[this.variationCount].attrs.end = timestamp;",
"}",
"this",
".",
"testCount",
"++",
";",
"this",
".",
"variationCount",
"=",
"-",
"1",
";",
"return",
"this",
";",
"}"
] |
Finishes XML skeleton for a testcase
@method testFinished
@param {object} data Event data
@chainable
|
[
"Finishes",
"XML",
"skeleton",
"for",
"a",
"testcase"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L259-L278
|
|
37,809 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (data) {
this.data.elapsedTime = data.elapsedTime;
this.data.status = data.status;
this.data.assertions = data.assertions;
this.data.assertionsFailed = data.assertionsFailed;
this.data.assertionsPassed = data.assertionsPassed;
var contents = jsonxml(this.xml, {escape: true, removeIllegalNameCharacters: true, prettyPrint: true, xmlHeader: 'version="1.0" encoding="UTF-8"'});
if (path.extname(this.dest) !== '.xml') {
this.dest = this.dest + '/dalek.xml';
}
this.events.emit('report:written', {type: 'junit', dest: this.dest});
this._recursiveMakeDirSync(path.dirname(this.dest.replace(path.basename(this.dest, ''))));
fs.writeFileSync(this.dest, contents, 'utf8');
}
|
javascript
|
function (data) {
this.data.elapsedTime = data.elapsedTime;
this.data.status = data.status;
this.data.assertions = data.assertions;
this.data.assertionsFailed = data.assertionsFailed;
this.data.assertionsPassed = data.assertionsPassed;
var contents = jsonxml(this.xml, {escape: true, removeIllegalNameCharacters: true, prettyPrint: true, xmlHeader: 'version="1.0" encoding="UTF-8"'});
if (path.extname(this.dest) !== '.xml') {
this.dest = this.dest + '/dalek.xml';
}
this.events.emit('report:written', {type: 'junit', dest: this.dest});
this._recursiveMakeDirSync(path.dirname(this.dest.replace(path.basename(this.dest, ''))));
fs.writeFileSync(this.dest, contents, 'utf8');
}
|
[
"function",
"(",
"data",
")",
"{",
"this",
".",
"data",
".",
"elapsedTime",
"=",
"data",
".",
"elapsedTime",
";",
"this",
".",
"data",
".",
"status",
"=",
"data",
".",
"status",
";",
"this",
".",
"data",
".",
"assertions",
"=",
"data",
".",
"assertions",
";",
"this",
".",
"data",
".",
"assertionsFailed",
"=",
"data",
".",
"assertionsFailed",
";",
"this",
".",
"data",
".",
"assertionsPassed",
"=",
"data",
".",
"assertionsPassed",
";",
"var",
"contents",
"=",
"jsonxml",
"(",
"this",
".",
"xml",
",",
"{",
"escape",
":",
"true",
",",
"removeIllegalNameCharacters",
":",
"true",
",",
"prettyPrint",
":",
"true",
",",
"xmlHeader",
":",
"'version=\"1.0\" encoding=\"UTF-8\"'",
"}",
")",
";",
"if",
"(",
"path",
".",
"extname",
"(",
"this",
".",
"dest",
")",
"!==",
"'.xml'",
")",
"{",
"this",
".",
"dest",
"=",
"this",
".",
"dest",
"+",
"'/dalek.xml'",
";",
"}",
"this",
".",
"events",
".",
"emit",
"(",
"'report:written'",
",",
"{",
"type",
":",
"'junit'",
",",
"dest",
":",
"this",
".",
"dest",
"}",
")",
";",
"this",
".",
"_recursiveMakeDirSync",
"(",
"path",
".",
"dirname",
"(",
"this",
".",
"dest",
".",
"replace",
"(",
"path",
".",
"basename",
"(",
"this",
".",
"dest",
",",
"''",
")",
")",
")",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"this",
".",
"dest",
",",
"contents",
",",
"'utf8'",
")",
";",
"}"
] |
Finishes XML and writes file to the file system
@method runnerFinished
@param {object} data Event data
@chainable
|
[
"Finishes",
"XML",
"and",
"writes",
"file",
"to",
"the",
"file",
"system"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L288-L304
|
|
37,810 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (path) {
var pathSep = require('path').sep;
var dirs = path.split(pathSep);
var root = '';
while (dirs.length > 0) {
var dir = dirs.shift();
if (dir === '') {
root = pathSep;
}
if (!fs.existsSync(root + dir)) {
fs.mkdirSync(root + dir);
}
root += dir + pathSep;
}
}
|
javascript
|
function (path) {
var pathSep = require('path').sep;
var dirs = path.split(pathSep);
var root = '';
while (dirs.length > 0) {
var dir = dirs.shift();
if (dir === '') {
root = pathSep;
}
if (!fs.existsSync(root + dir)) {
fs.mkdirSync(root + dir);
}
root += dir + pathSep;
}
}
|
[
"function",
"(",
"path",
")",
"{",
"var",
"pathSep",
"=",
"require",
"(",
"'path'",
")",
".",
"sep",
";",
"var",
"dirs",
"=",
"path",
".",
"split",
"(",
"pathSep",
")",
";",
"var",
"root",
"=",
"''",
";",
"while",
"(",
"dirs",
".",
"length",
">",
"0",
")",
"{",
"var",
"dir",
"=",
"dirs",
".",
"shift",
"(",
")",
";",
"if",
"(",
"dir",
"===",
"''",
")",
"{",
"root",
"=",
"pathSep",
";",
"}",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"root",
"+",
"dir",
")",
")",
"{",
"fs",
".",
"mkdirSync",
"(",
"root",
"+",
"dir",
")",
";",
"}",
"root",
"+=",
"dir",
"+",
"pathSep",
";",
"}",
"}"
] |
Helper method to generate deeper nested directory structures
@method _recursiveMakeDirSync
@param {string} path PAth to create
|
[
"Helper",
"method",
"to",
"generate",
"deeper",
"nested",
"directory",
"structures"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L313-L328
|
|
37,811 |
dalekjs/dalek-reporter-junit
|
index.js
|
function (testIdx, testCount, variationCount) {
if (variationCount === undefined) {
return typeof this.xml[0].children[testIdx].children[testCount].attrs === 'undefined';
}
return typeof this.xml[0].children[testIdx].children[testCount].children[variationCount].attrs === 'undefined';
}
|
javascript
|
function (testIdx, testCount, variationCount) {
if (variationCount === undefined) {
return typeof this.xml[0].children[testIdx].children[testCount].attrs === 'undefined';
}
return typeof this.xml[0].children[testIdx].children[testCount].children[variationCount].attrs === 'undefined';
}
|
[
"function",
"(",
"testIdx",
",",
"testCount",
",",
"variationCount",
")",
"{",
"if",
"(",
"variationCount",
"===",
"undefined",
")",
"{",
"return",
"typeof",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"testIdx",
"]",
".",
"children",
"[",
"testCount",
"]",
".",
"attrs",
"===",
"'undefined'",
";",
"}",
"return",
"typeof",
"this",
".",
"xml",
"[",
"0",
"]",
".",
"children",
"[",
"testIdx",
"]",
".",
"children",
"[",
"testCount",
"]",
".",
"children",
"[",
"variationCount",
"]",
".",
"attrs",
"===",
"'undefined'",
";",
"}"
] |
Helper method to check if attributes should be set to an empty object literal
@method _checkNodeAttributes
@param {string} testIdx Id of the test node
@param {string} testCount Id of the child node
@param {string} variationCount Id of the testCount child node
|
[
"Helper",
"method",
"to",
"check",
"if",
"attributes",
"should",
"be",
"set",
"to",
"an",
"empty",
"object",
"literal"
] |
af67e4716ad02b911f450d0a0333e0e7d92752df
|
https://github.com/dalekjs/dalek-reporter-junit/blob/af67e4716ad02b911f450d0a0333e0e7d92752df/index.js#L339-L345
|
|
37,812 |
folktale/control.async
|
lib/core.js
|
resolveFuture
|
function resolveFuture(reject, resolve) {
state = STARTED
return future.fork( function(error) { state = REJECTED
value = error
invokePending('rejected', error)
return reject(error) }
, function(data) { state = RESOLVED
value = data
invokePending('resolved', data)
return resolve(data) })}
|
javascript
|
function resolveFuture(reject, resolve) {
state = STARTED
return future.fork( function(error) { state = REJECTED
value = error
invokePending('rejected', error)
return reject(error) }
, function(data) { state = RESOLVED
value = data
invokePending('resolved', data)
return resolve(data) })}
|
[
"function",
"resolveFuture",
"(",
"reject",
",",
"resolve",
")",
"{",
"state",
"=",
"STARTED",
"return",
"future",
".",
"fork",
"(",
"function",
"(",
"error",
")",
"{",
"state",
"=",
"REJECTED",
"value",
"=",
"error",
"invokePending",
"(",
"'rejected'",
",",
"error",
")",
"return",
"reject",
"(",
"error",
")",
"}",
",",
"function",
"(",
"data",
")",
"{",
"state",
"=",
"RESOLVED",
"value",
"=",
"data",
"invokePending",
"(",
"'resolved'",
",",
"data",
")",
"return",
"resolve",
"(",
"data",
")",
"}",
")",
"}"
] |
Resolves the future, places the machine in a resolved state, and invokes all pending operations.
|
[
"Resolves",
"the",
"future",
"places",
"the",
"machine",
"in",
"a",
"resolved",
"state",
"and",
"invokes",
"all",
"pending",
"operations",
"."
] |
83f4d2a16cb3d2739ee58ae69372deb53fc38835
|
https://github.com/folktale/control.async/blob/83f4d2a16cb3d2739ee58ae69372deb53fc38835/lib/core.js#L92-L102
|
37,813 |
folktale/control.async
|
lib/core.js
|
invokePending
|
function invokePending(kind, data) {
var xs = pending
pending.length = 0
for (var i = 0; i < xs.length; ++i) xs[i][kind](value) }
|
javascript
|
function invokePending(kind, data) {
var xs = pending
pending.length = 0
for (var i = 0; i < xs.length; ++i) xs[i][kind](value) }
|
[
"function",
"invokePending",
"(",
"kind",
",",
"data",
")",
"{",
"var",
"xs",
"=",
"pending",
"pending",
".",
"length",
"=",
"0",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"xs",
".",
"length",
";",
"++",
"i",
")",
"xs",
"[",
"i",
"]",
"[",
"kind",
"]",
"(",
"value",
")",
"}"
] |
Invokes all pending operations.
|
[
"Invokes",
"all",
"pending",
"operations",
"."
] |
83f4d2a16cb3d2739ee58ae69372deb53fc38835
|
https://github.com/folktale/control.async/blob/83f4d2a16cb3d2739ee58ae69372deb53fc38835/lib/core.js#L105-L108
|
37,814 |
dsfields/elv
|
lib/index.js
|
function (val) {
return (!behavior.enableUndefined || typeof val !== 'undefined')
&& (!behavior.enableNull || val !== null)
&& (!behavior.enableFalse || val !== false)
&& (!behavior.enableNaN || !Number.isNaN(val));
}
|
javascript
|
function (val) {
return (!behavior.enableUndefined || typeof val !== 'undefined')
&& (!behavior.enableNull || val !== null)
&& (!behavior.enableFalse || val !== false)
&& (!behavior.enableNaN || !Number.isNaN(val));
}
|
[
"function",
"(",
"val",
")",
"{",
"return",
"(",
"!",
"behavior",
".",
"enableUndefined",
"||",
"typeof",
"val",
"!==",
"'undefined'",
")",
"&&",
"(",
"!",
"behavior",
".",
"enableNull",
"||",
"val",
"!==",
"null",
")",
"&&",
"(",
"!",
"behavior",
".",
"enableFalse",
"||",
"val",
"!==",
"false",
")",
"&&",
"(",
"!",
"behavior",
".",
"enableNaN",
"||",
"!",
"Number",
".",
"isNaN",
"(",
"val",
")",
")",
";",
"}"
] |
Checks if the provided value is defined.
@method
@param {*} val - The value on which to perform an existential check.
@returns {boolean}
|
[
"Checks",
"if",
"the",
"provided",
"value",
"is",
"defined",
"."
] |
c603170c645b6ad0c2df6d7f8ba572bf77821ede
|
https://github.com/dsfields/elv/blob/c603170c645b6ad0c2df6d7f8ba572bf77821ede/lib/index.js#L21-L26
|
|
37,815 |
cgiffard/SteamShovel
|
lib/instrumentor.js
|
function (node) {
// Does this node have a body? If so we can replace its contents.
if (node.body && node.body.length) {
node.body =
[].slice.call(node.body, 0)
.reduce(function(body, node) {
if (!~allowedPrepend.indexOf(node.type))
return body.concat(node);
id++;
sourceMapAdd(id, node, true);
return body.concat(
expressionStatement(
callExpression(filetag, id)
),
node
);
}, []);
}
if (node.noReplace)
return;
// If we're allowed to replace the node,
// replace it with a Call Expression.
if (~allowedReplacements.indexOf(node.type))
return (
id ++,
sourceMapAdd(id, node, false),
callExpression(filetag, id, node)
);
}
|
javascript
|
function (node) {
// Does this node have a body? If so we can replace its contents.
if (node.body && node.body.length) {
node.body =
[].slice.call(node.body, 0)
.reduce(function(body, node) {
if (!~allowedPrepend.indexOf(node.type))
return body.concat(node);
id++;
sourceMapAdd(id, node, true);
return body.concat(
expressionStatement(
callExpression(filetag, id)
),
node
);
}, []);
}
if (node.noReplace)
return;
// If we're allowed to replace the node,
// replace it with a Call Expression.
if (~allowedReplacements.indexOf(node.type))
return (
id ++,
sourceMapAdd(id, node, false),
callExpression(filetag, id, node)
);
}
|
[
"function",
"(",
"node",
")",
"{",
"// Does this node have a body? If so we can replace its contents.",
"if",
"(",
"node",
".",
"body",
"&&",
"node",
".",
"body",
".",
"length",
")",
"{",
"node",
".",
"body",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"node",
".",
"body",
",",
"0",
")",
".",
"reduce",
"(",
"function",
"(",
"body",
",",
"node",
")",
"{",
"if",
"(",
"!",
"~",
"allowedPrepend",
".",
"indexOf",
"(",
"node",
".",
"type",
")",
")",
"return",
"body",
".",
"concat",
"(",
"node",
")",
";",
"id",
"++",
";",
"sourceMapAdd",
"(",
"id",
",",
"node",
",",
"true",
")",
";",
"return",
"body",
".",
"concat",
"(",
"expressionStatement",
"(",
"callExpression",
"(",
"filetag",
",",
"id",
")",
")",
",",
"node",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}",
"if",
"(",
"node",
".",
"noReplace",
")",
"return",
";",
"// If we're allowed to replace the node,",
"// replace it with a Call Expression.",
"if",
"(",
"~",
"allowedReplacements",
".",
"indexOf",
"(",
"node",
".",
"type",
")",
")",
"return",
"(",
"id",
"++",
",",
"sourceMapAdd",
"(",
"id",
",",
"node",
",",
"false",
")",
",",
"callExpression",
"(",
"filetag",
",",
"id",
",",
"node",
")",
")",
";",
"}"
] |
Leave is where we replace the actual nodes.
|
[
"Leave",
"is",
"where",
"we",
"replace",
"the",
"actual",
"nodes",
"."
] |
7c9a4baf4e1f9390b352742ab26a6900c78b6e25
|
https://github.com/cgiffard/SteamShovel/blob/7c9a4baf4e1f9390b352742ab26a6900c78b6e25/lib/instrumentor.js#L102-L138
|
|
37,816 |
OriR/interpolate-loader-options-webpack-plugin
|
index.js
|
interpolatedOptions
|
function interpolatedOptions(options, context, source, hierarchy = '') {
Object.keys(options).forEach((key) => {
if (typeof options[key] === 'object') {
interpolatedOptions(options[key], context, source, `${hierarchy}.${key}`);
}
else if (typeof options[key] === 'string' && shouldPatchProperty(`${hierarchy}.${key}`)) {
options[key] = utils.interpolateName(context, options[key], { content: source });
}
});
return options;
}
|
javascript
|
function interpolatedOptions(options, context, source, hierarchy = '') {
Object.keys(options).forEach((key) => {
if (typeof options[key] === 'object') {
interpolatedOptions(options[key], context, source, `${hierarchy}.${key}`);
}
else if (typeof options[key] === 'string' && shouldPatchProperty(`${hierarchy}.${key}`)) {
options[key] = utils.interpolateName(context, options[key], { content: source });
}
});
return options;
}
|
[
"function",
"interpolatedOptions",
"(",
"options",
",",
"context",
",",
"source",
",",
"hierarchy",
"=",
"''",
")",
"{",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"if",
"(",
"typeof",
"options",
"[",
"key",
"]",
"===",
"'object'",
")",
"{",
"interpolatedOptions",
"(",
"options",
"[",
"key",
"]",
",",
"context",
",",
"source",
",",
"`",
"${",
"hierarchy",
"}",
"${",
"key",
"}",
"`",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
"[",
"key",
"]",
"===",
"'string'",
"&&",
"shouldPatchProperty",
"(",
"`",
"${",
"hierarchy",
"}",
"${",
"key",
"}",
"`",
")",
")",
"{",
"options",
"[",
"key",
"]",
"=",
"utils",
".",
"interpolateName",
"(",
"context",
",",
"options",
"[",
"key",
"]",
",",
"{",
"content",
":",
"source",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"options",
";",
"}"
] |
Interpolating all the string values in the options object.
|
[
"Interpolating",
"all",
"the",
"string",
"values",
"in",
"the",
"options",
"object",
"."
] |
8b8f6e315f7d606a4fbcf4f473e75c4e26d287df
|
https://github.com/OriR/interpolate-loader-options-webpack-plugin/blob/8b8f6e315f7d606a4fbcf4f473e75c4e26d287df/index.js#L38-L48
|
37,817 |
impromptu/impromptu
|
lib/exec.js
|
Executable
|
function Executable(log, command) {
/** @type {string} */
this.command = command
/** @type {Array.<function(Error, Buffer, Buffer)>} */
this.callbacks = []
/** @type {Arguments} */
this.results = null
var startTime = Date.now()
child_process.exec(this.command, function() {
var timeDiff = `${Date.now() - startTime}`
if (timeDiff.length < 3) timeDiff = ` ${timeDiff}`.slice(-3)
log.debug(`Exec | ${timeDiff}ms | ${this.command}`)
this.results = arguments
for (var i = 0; i < this.callbacks.length; i++) {
var callback = this.callbacks[i]
callback.apply(null, arguments)
}
}.bind(this))
}
|
javascript
|
function Executable(log, command) {
/** @type {string} */
this.command = command
/** @type {Array.<function(Error, Buffer, Buffer)>} */
this.callbacks = []
/** @type {Arguments} */
this.results = null
var startTime = Date.now()
child_process.exec(this.command, function() {
var timeDiff = `${Date.now() - startTime}`
if (timeDiff.length < 3) timeDiff = ` ${timeDiff}`.slice(-3)
log.debug(`Exec | ${timeDiff}ms | ${this.command}`)
this.results = arguments
for (var i = 0; i < this.callbacks.length; i++) {
var callback = this.callbacks[i]
callback.apply(null, arguments)
}
}.bind(this))
}
|
[
"function",
"Executable",
"(",
"log",
",",
"command",
")",
"{",
"/** @type {string} */",
"this",
".",
"command",
"=",
"command",
"/** @type {Array.<function(Error, Buffer, Buffer)>} */",
"this",
".",
"callbacks",
"=",
"[",
"]",
"/** @type {Arguments} */",
"this",
".",
"results",
"=",
"null",
"var",
"startTime",
"=",
"Date",
".",
"now",
"(",
")",
"child_process",
".",
"exec",
"(",
"this",
".",
"command",
",",
"function",
"(",
")",
"{",
"var",
"timeDiff",
"=",
"`",
"${",
"Date",
".",
"now",
"(",
")",
"-",
"startTime",
"}",
"`",
"if",
"(",
"timeDiff",
".",
"length",
"<",
"3",
")",
"timeDiff",
"=",
"`",
"${",
"timeDiff",
"}",
"`",
".",
"slice",
"(",
"-",
"3",
")",
"log",
".",
"debug",
"(",
"`",
"${",
"timeDiff",
"}",
"${",
"this",
".",
"command",
"}",
"`",
")",
"this",
".",
"results",
"=",
"arguments",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"callbacks",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"callback",
"=",
"this",
".",
"callbacks",
"[",
"i",
"]",
"callback",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
"}"
] |
A memoized executable command. The first time the command is run, the results are stored.
Callbacks are tracked while the command is running to avoid race conditions.
@constructor
@param {Log} log A logging instance.
@param {string} command The command to execute.
|
[
"A",
"memoized",
"executable",
"command",
".",
"The",
"first",
"time",
"the",
"command",
"is",
"run",
"the",
"results",
"are",
"stored",
".",
"Callbacks",
"are",
"tracked",
"while",
"the",
"command",
"is",
"running",
"to",
"avoid",
"race",
"conditions",
"."
] |
829798eda62771d6a6ed971d87eef7a461932704
|
https://github.com/impromptu/impromptu/blob/829798eda62771d6a6ed971d87eef7a461932704/lib/exec.js#L23-L45
|
37,818 |
impromptu/impromptu
|
lib/exec.js
|
execute
|
function execute(log, command, opt_callback) {
if (!registry[command]) {
registry[command] = new Executable(log, command)
}
var executable = registry[command]
if (opt_callback) executable.addCallback(opt_callback)
}
|
javascript
|
function execute(log, command, opt_callback) {
if (!registry[command]) {
registry[command] = new Executable(log, command)
}
var executable = registry[command]
if (opt_callback) executable.addCallback(opt_callback)
}
|
[
"function",
"execute",
"(",
"log",
",",
"command",
",",
"opt_callback",
")",
"{",
"if",
"(",
"!",
"registry",
"[",
"command",
"]",
")",
"{",
"registry",
"[",
"command",
"]",
"=",
"new",
"Executable",
"(",
"log",
",",
"command",
")",
"}",
"var",
"executable",
"=",
"registry",
"[",
"command",
"]",
"if",
"(",
"opt_callback",
")",
"executable",
".",
"addCallback",
"(",
"opt_callback",
")",
"}"
] |
Executes a memoized command and triggers the callback on a result.
@param {Log} log
@param {string} command
@param {function(Error, Buffer, Buffer)=} opt_callback
|
[
"Executes",
"a",
"memoized",
"command",
"and",
"triggers",
"the",
"callback",
"on",
"a",
"result",
"."
] |
829798eda62771d6a6ed971d87eef7a461932704
|
https://github.com/impromptu/impromptu/blob/829798eda62771d6a6ed971d87eef7a461932704/lib/exec.js#L65-L72
|
37,819 |
typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation
|
template/copy/script/navigation/enhancednav.js
|
deserializeNavState
|
function deserializeNavState()
{
var navID = $('.navigation .nav-accordion-menu').data('nav-id');
if (sessionStorage)
{
var checkboxMap = sessionStorage.getItem(navID + '-accordion-state');
// If there is no data in session storage then create an empty map.
if (checkboxMap == null) { checkboxMap = '{}'; }
checkboxMap = JSON.parse(checkboxMap);
$('.navigation .nav-accordion-menu').find('input[type="checkbox"]').each(function()
{
var checkboxValue = checkboxMap[$(this).attr('name')];
if (typeof checkboxValue === 'boolean') { $(this).prop('checked', checkboxValue); }
});
}
// Set navigation menu visible
$('.navigation .nav-accordion-menu').removeClass('hidden');
// Set navigation menu scroll bar from session state.
if (sessionStorage)
{
var navScrollTop = sessionStorage.getItem(navID + '-scrolltop');
if (typeof navScrollTop === 'string') { $('.navigation').prop('scrollTop', navScrollTop); }
}
}
|
javascript
|
function deserializeNavState()
{
var navID = $('.navigation .nav-accordion-menu').data('nav-id');
if (sessionStorage)
{
var checkboxMap = sessionStorage.getItem(navID + '-accordion-state');
// If there is no data in session storage then create an empty map.
if (checkboxMap == null) { checkboxMap = '{}'; }
checkboxMap = JSON.parse(checkboxMap);
$('.navigation .nav-accordion-menu').find('input[type="checkbox"]').each(function()
{
var checkboxValue = checkboxMap[$(this).attr('name')];
if (typeof checkboxValue === 'boolean') { $(this).prop('checked', checkboxValue); }
});
}
// Set navigation menu visible
$('.navigation .nav-accordion-menu').removeClass('hidden');
// Set navigation menu scroll bar from session state.
if (sessionStorage)
{
var navScrollTop = sessionStorage.getItem(navID + '-scrolltop');
if (typeof navScrollTop === 'string') { $('.navigation').prop('scrollTop', navScrollTop); }
}
}
|
[
"function",
"deserializeNavState",
"(",
")",
"{",
"var",
"navID",
"=",
"$",
"(",
"'.navigation .nav-accordion-menu'",
")",
".",
"data",
"(",
"'nav-id'",
")",
";",
"if",
"(",
"sessionStorage",
")",
"{",
"var",
"checkboxMap",
"=",
"sessionStorage",
".",
"getItem",
"(",
"navID",
"+",
"'-accordion-state'",
")",
";",
"// If there is no data in session storage then create an empty map.",
"if",
"(",
"checkboxMap",
"==",
"null",
")",
"{",
"checkboxMap",
"=",
"'{}'",
";",
"}",
"checkboxMap",
"=",
"JSON",
".",
"parse",
"(",
"checkboxMap",
")",
";",
"$",
"(",
"'.navigation .nav-accordion-menu'",
")",
".",
"find",
"(",
"'input[type=\"checkbox\"]'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"checkboxValue",
"=",
"checkboxMap",
"[",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'name'",
")",
"]",
";",
"if",
"(",
"typeof",
"checkboxValue",
"===",
"'boolean'",
")",
"{",
"$",
"(",
"this",
")",
".",
"prop",
"(",
"'checked'",
",",
"checkboxValue",
")",
";",
"}",
"}",
")",
";",
"}",
"// Set navigation menu visible",
"$",
"(",
"'.navigation .nav-accordion-menu'",
")",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"// Set navigation menu scroll bar from session state.",
"if",
"(",
"sessionStorage",
")",
"{",
"var",
"navScrollTop",
"=",
"sessionStorage",
".",
"getItem",
"(",
"navID",
"+",
"'-scrolltop'",
")",
";",
"if",
"(",
"typeof",
"navScrollTop",
"===",
"'string'",
")",
"{",
"$",
"(",
"'.navigation'",
")",
".",
"prop",
"(",
"'scrollTop'",
",",
"navScrollTop",
")",
";",
"}",
"}",
"}"
] |
Deserializes navigation accordion state from session storage.
|
[
"Deserializes",
"navigation",
"accordion",
"state",
"from",
"session",
"storage",
"."
] |
db25fb3e570fbae97bedf06fe4daf4d51e4c788b
|
https://github.com/typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation/blob/db25fb3e570fbae97bedf06fe4daf4d51e4c788b/template/copy/script/navigation/enhancednav.js#L27-L56
|
37,820 |
typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation
|
template/copy/script/navigation/enhancednav.js
|
hideNavContextMenu
|
function hideNavContextMenu(event)
{
var contextMenuButton = $('#context-menu');
var popupmenu = $('#contextpopup .mdl-menu__container');
// If an event is defined then make sure it isn't targeting the context menu.
if (event)
{
// Picked element is not the menu
if (!$(event.target).parents('#contextpopup').length > 0)
{
// Hide menu if currently visible
if (popupmenu.hasClass('is-visible')) { contextMenuButton.click(); }
}
}
else // No event defined so always close context menu and remove node highlighting.
{
// Hide menu if currently visible
if (popupmenu.hasClass('is-visible')) { contextMenuButton.click(); }
}
}
|
javascript
|
function hideNavContextMenu(event)
{
var contextMenuButton = $('#context-menu');
var popupmenu = $('#contextpopup .mdl-menu__container');
// If an event is defined then make sure it isn't targeting the context menu.
if (event)
{
// Picked element is not the menu
if (!$(event.target).parents('#contextpopup').length > 0)
{
// Hide menu if currently visible
if (popupmenu.hasClass('is-visible')) { contextMenuButton.click(); }
}
}
else // No event defined so always close context menu and remove node highlighting.
{
// Hide menu if currently visible
if (popupmenu.hasClass('is-visible')) { contextMenuButton.click(); }
}
}
|
[
"function",
"hideNavContextMenu",
"(",
"event",
")",
"{",
"var",
"contextMenuButton",
"=",
"$",
"(",
"'#context-menu'",
")",
";",
"var",
"popupmenu",
"=",
"$",
"(",
"'#contextpopup .mdl-menu__container'",
")",
";",
"// If an event is defined then make sure it isn't targeting the context menu.",
"if",
"(",
"event",
")",
"{",
"// Picked element is not the menu",
"if",
"(",
"!",
"$",
"(",
"event",
".",
"target",
")",
".",
"parents",
"(",
"'#contextpopup'",
")",
".",
"length",
">",
"0",
")",
"{",
"// Hide menu if currently visible",
"if",
"(",
"popupmenu",
".",
"hasClass",
"(",
"'is-visible'",
")",
")",
"{",
"contextMenuButton",
".",
"click",
"(",
")",
";",
"}",
"}",
"}",
"else",
"// No event defined so always close context menu and remove node highlighting.",
"{",
"// Hide menu if currently visible",
"if",
"(",
"popupmenu",
".",
"hasClass",
"(",
"'is-visible'",
")",
")",
"{",
"contextMenuButton",
".",
"click",
"(",
")",
";",
"}",
"}",
"}"
] |
Hides the nav context menu if visible. If an event is supplied it is checked against any existing context menu
and is ignored if the context menu is within the parent hierarchy.
@param {object|undefined} event - Optional event
|
[
"Hides",
"the",
"nav",
"context",
"menu",
"if",
"visible",
".",
"If",
"an",
"event",
"is",
"supplied",
"it",
"is",
"checked",
"against",
"any",
"existing",
"context",
"menu",
"and",
"is",
"ignored",
"if",
"the",
"context",
"menu",
"is",
"within",
"the",
"parent",
"hierarchy",
"."
] |
db25fb3e570fbae97bedf06fe4daf4d51e4c788b
|
https://github.com/typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation/blob/db25fb3e570fbae97bedf06fe4daf4d51e4c788b/template/copy/script/navigation/enhancednav.js#L64-L84
|
37,821 |
typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation
|
template/copy/script/navigation/enhancednav.js
|
onNavContextClick
|
function onNavContextClick(event)
{
// Hides any existing nav context menu.
hideNavContextMenu(event);
var target = $(this);
var packageLink = target.data('package-link');
var packageType = target.data('package-type') || '...';
// Create proper name for package type.
switch (packageType)
{
case 'npm':
packageType = 'NPM';
break;
}
var packageVersion = target.data('package-version');
var scmLink = target.data('scm-link');
var scmType = target.data('scm-type') || '...';
// Create proper name for SCM type.
switch (scmType)
{
case 'github':
scmType = 'Github';
break;
}
var popupmenu = $('#contextpopup .mdl-menu__container');
// Populate data for the context menu.
popupmenu.find('li').each(function(index)
{
var liTarget = $(this);
switch (index)
{
case 0:
if (scmLink)
{
liTarget.text('Open on ' + scmType);
liTarget.data('link', scmLink);
liTarget.removeClass('hidden');
// Add divider if there are additional non-hidden items
if (packageLink || packageVersion) { liTarget.addClass('mdl-menu__item--full-bleed-divider'); }
else { liTarget.removeClass('mdl-menu__item--full-bleed-divider'); }
}
else
{
liTarget.addClass('hidden');
}
break;
case 1:
if (packageLink)
{
liTarget.text('Open on ' + packageType);
liTarget.data('link', packageLink);
liTarget.removeClass('hidden');
// Add divider if there are additional non-hidden items
if (packageVersion) { liTarget.addClass('mdl-menu__item--full-bleed-divider'); }
else { liTarget.removeClass('mdl-menu__item--full-bleed-divider'); }
}
else
{
liTarget.addClass('hidden');
}
break;
case 2:
if (packageVersion)
{
liTarget.text('Version: ' + packageVersion);
liTarget.removeClass('hidden');
}
else
{
liTarget.addClass('hidden');
}
break;
}
});
// Wrapping in a 100ms timeout allows MDL to draw animation when showing a context menu after one has been hidden.
setTimeout(function()
{
// For MDL a programmatic click of the hidden context menu.
var contextMenuButton = $("#context-menu");
contextMenuButton.click();
// Necessary to defer reposition of the context menu.
setTimeout(function()
{
popupmenu.parent().css({ position: 'relative' });
popupmenu.css({ left: event.pageX, top: event.pageY - $('header').outerHeight(), position:'absolute' });
}, 0);
}, 100);
}
|
javascript
|
function onNavContextClick(event)
{
// Hides any existing nav context menu.
hideNavContextMenu(event);
var target = $(this);
var packageLink = target.data('package-link');
var packageType = target.data('package-type') || '...';
// Create proper name for package type.
switch (packageType)
{
case 'npm':
packageType = 'NPM';
break;
}
var packageVersion = target.data('package-version');
var scmLink = target.data('scm-link');
var scmType = target.data('scm-type') || '...';
// Create proper name for SCM type.
switch (scmType)
{
case 'github':
scmType = 'Github';
break;
}
var popupmenu = $('#contextpopup .mdl-menu__container');
// Populate data for the context menu.
popupmenu.find('li').each(function(index)
{
var liTarget = $(this);
switch (index)
{
case 0:
if (scmLink)
{
liTarget.text('Open on ' + scmType);
liTarget.data('link', scmLink);
liTarget.removeClass('hidden');
// Add divider if there are additional non-hidden items
if (packageLink || packageVersion) { liTarget.addClass('mdl-menu__item--full-bleed-divider'); }
else { liTarget.removeClass('mdl-menu__item--full-bleed-divider'); }
}
else
{
liTarget.addClass('hidden');
}
break;
case 1:
if (packageLink)
{
liTarget.text('Open on ' + packageType);
liTarget.data('link', packageLink);
liTarget.removeClass('hidden');
// Add divider if there are additional non-hidden items
if (packageVersion) { liTarget.addClass('mdl-menu__item--full-bleed-divider'); }
else { liTarget.removeClass('mdl-menu__item--full-bleed-divider'); }
}
else
{
liTarget.addClass('hidden');
}
break;
case 2:
if (packageVersion)
{
liTarget.text('Version: ' + packageVersion);
liTarget.removeClass('hidden');
}
else
{
liTarget.addClass('hidden');
}
break;
}
});
// Wrapping in a 100ms timeout allows MDL to draw animation when showing a context menu after one has been hidden.
setTimeout(function()
{
// For MDL a programmatic click of the hidden context menu.
var contextMenuButton = $("#context-menu");
contextMenuButton.click();
// Necessary to defer reposition of the context menu.
setTimeout(function()
{
popupmenu.parent().css({ position: 'relative' });
popupmenu.css({ left: event.pageX, top: event.pageY - $('header').outerHeight(), position:'absolute' });
}, 0);
}, 100);
}
|
[
"function",
"onNavContextClick",
"(",
"event",
")",
"{",
"// Hides any existing nav context menu.",
"hideNavContextMenu",
"(",
"event",
")",
";",
"var",
"target",
"=",
"$",
"(",
"this",
")",
";",
"var",
"packageLink",
"=",
"target",
".",
"data",
"(",
"'package-link'",
")",
";",
"var",
"packageType",
"=",
"target",
".",
"data",
"(",
"'package-type'",
")",
"||",
"'...'",
";",
"// Create proper name for package type.",
"switch",
"(",
"packageType",
")",
"{",
"case",
"'npm'",
":",
"packageType",
"=",
"'NPM'",
";",
"break",
";",
"}",
"var",
"packageVersion",
"=",
"target",
".",
"data",
"(",
"'package-version'",
")",
";",
"var",
"scmLink",
"=",
"target",
".",
"data",
"(",
"'scm-link'",
")",
";",
"var",
"scmType",
"=",
"target",
".",
"data",
"(",
"'scm-type'",
")",
"||",
"'...'",
";",
"// Create proper name for SCM type.",
"switch",
"(",
"scmType",
")",
"{",
"case",
"'github'",
":",
"scmType",
"=",
"'Github'",
";",
"break",
";",
"}",
"var",
"popupmenu",
"=",
"$",
"(",
"'#contextpopup .mdl-menu__container'",
")",
";",
"// Populate data for the context menu.",
"popupmenu",
".",
"find",
"(",
"'li'",
")",
".",
"each",
"(",
"function",
"(",
"index",
")",
"{",
"var",
"liTarget",
"=",
"$",
"(",
"this",
")",
";",
"switch",
"(",
"index",
")",
"{",
"case",
"0",
":",
"if",
"(",
"scmLink",
")",
"{",
"liTarget",
".",
"text",
"(",
"'Open on '",
"+",
"scmType",
")",
";",
"liTarget",
".",
"data",
"(",
"'link'",
",",
"scmLink",
")",
";",
"liTarget",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"// Add divider if there are additional non-hidden items",
"if",
"(",
"packageLink",
"||",
"packageVersion",
")",
"{",
"liTarget",
".",
"addClass",
"(",
"'mdl-menu__item--full-bleed-divider'",
")",
";",
"}",
"else",
"{",
"liTarget",
".",
"removeClass",
"(",
"'mdl-menu__item--full-bleed-divider'",
")",
";",
"}",
"}",
"else",
"{",
"liTarget",
".",
"addClass",
"(",
"'hidden'",
")",
";",
"}",
"break",
";",
"case",
"1",
":",
"if",
"(",
"packageLink",
")",
"{",
"liTarget",
".",
"text",
"(",
"'Open on '",
"+",
"packageType",
")",
";",
"liTarget",
".",
"data",
"(",
"'link'",
",",
"packageLink",
")",
";",
"liTarget",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"// Add divider if there are additional non-hidden items",
"if",
"(",
"packageVersion",
")",
"{",
"liTarget",
".",
"addClass",
"(",
"'mdl-menu__item--full-bleed-divider'",
")",
";",
"}",
"else",
"{",
"liTarget",
".",
"removeClass",
"(",
"'mdl-menu__item--full-bleed-divider'",
")",
";",
"}",
"}",
"else",
"{",
"liTarget",
".",
"addClass",
"(",
"'hidden'",
")",
";",
"}",
"break",
";",
"case",
"2",
":",
"if",
"(",
"packageVersion",
")",
"{",
"liTarget",
".",
"text",
"(",
"'Version: '",
"+",
"packageVersion",
")",
";",
"liTarget",
".",
"removeClass",
"(",
"'hidden'",
")",
";",
"}",
"else",
"{",
"liTarget",
".",
"addClass",
"(",
"'hidden'",
")",
";",
"}",
"break",
";",
"}",
"}",
")",
";",
"// Wrapping in a 100ms timeout allows MDL to draw animation when showing a context menu after one has been hidden.",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"// For MDL a programmatic click of the hidden context menu.",
"var",
"contextMenuButton",
"=",
"$",
"(",
"\"#context-menu\"",
")",
";",
"contextMenuButton",
".",
"click",
"(",
")",
";",
"// Necessary to defer reposition of the context menu.",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"popupmenu",
".",
"parent",
"(",
")",
".",
"css",
"(",
"{",
"position",
":",
"'relative'",
"}",
")",
";",
"popupmenu",
".",
"css",
"(",
"{",
"left",
":",
"event",
".",
"pageX",
",",
"top",
":",
"event",
".",
"pageY",
"-",
"$",
"(",
"'header'",
")",
".",
"outerHeight",
"(",
")",
",",
"position",
":",
"'absolute'",
"}",
")",
";",
"}",
",",
"0",
")",
";",
"}",
",",
"100",
")",
";",
"}"
] |
Shows the nav context menu
@param {object} event - jQuery mouse event
|
[
"Shows",
"the",
"nav",
"context",
"menu"
] |
db25fb3e570fbae97bedf06fe4daf4d51e4c788b
|
https://github.com/typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation/blob/db25fb3e570fbae97bedf06fe4daf4d51e4c788b/template/copy/script/navigation/enhancednav.js#L91-L193
|
37,822 |
typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation
|
template/copy/script/navigation/enhancednav.js
|
serializeNavState
|
function serializeNavState()
{
var checkboxMap = {};
$('.navigation .nav-accordion-menu').find('input[type="checkbox"]').each(function()
{
checkboxMap[$(this).attr('name')] = $(this).is(':checked');
});
var navID = $('.navigation .nav-accordion-menu').data('nav-id');
if (sessionStorage) { sessionStorage.setItem(navID + '-accordion-state', JSON.stringify(checkboxMap))}
}
|
javascript
|
function serializeNavState()
{
var checkboxMap = {};
$('.navigation .nav-accordion-menu').find('input[type="checkbox"]').each(function()
{
checkboxMap[$(this).attr('name')] = $(this).is(':checked');
});
var navID = $('.navigation .nav-accordion-menu').data('nav-id');
if (sessionStorage) { sessionStorage.setItem(navID + '-accordion-state', JSON.stringify(checkboxMap))}
}
|
[
"function",
"serializeNavState",
"(",
")",
"{",
"var",
"checkboxMap",
"=",
"{",
"}",
";",
"$",
"(",
"'.navigation .nav-accordion-menu'",
")",
".",
"find",
"(",
"'input[type=\"checkbox\"]'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"checkboxMap",
"[",
"$",
"(",
"this",
")",
".",
"attr",
"(",
"'name'",
")",
"]",
"=",
"$",
"(",
"this",
")",
".",
"is",
"(",
"':checked'",
")",
";",
"}",
")",
";",
"var",
"navID",
"=",
"$",
"(",
"'.navigation .nav-accordion-menu'",
")",
".",
"data",
"(",
"'nav-id'",
")",
";",
"if",
"(",
"sessionStorage",
")",
"{",
"sessionStorage",
".",
"setItem",
"(",
"navID",
"+",
"'-accordion-state'",
",",
"JSON",
".",
"stringify",
"(",
"checkboxMap",
")",
")",
"}",
"}"
] |
Serializes to session storage the navigation menu accordion state.
|
[
"Serializes",
"to",
"session",
"storage",
"the",
"navigation",
"menu",
"accordion",
"state",
"."
] |
db25fb3e570fbae97bedf06fe4daf4d51e4c788b
|
https://github.com/typhonjs-node-esdoc/esdoc-plugin-enhanced-navigation/blob/db25fb3e570fbae97bedf06fe4daf4d51e4c788b/template/copy/script/navigation/enhancednav.js#L219-L231
|
37,823 |
mattdesl/webgl-compile-shader
|
index.js
|
compile
|
function compile(gl, vertSource, fragSource, attribs, verbose) {
var log = "";
var vert = loadShader(gl, gl.VERTEX_SHADER, vertSource, verbose);
var frag = loadShader(gl, gl.FRAGMENT_SHADER, fragSource, verbose);
var vertShader = vert.shader;
var fragShader = frag.shader;
log += vert.log + "\n" + frag.log;
var program = gl.createProgram();
gl.attachShader(program, vertShader);
gl.attachShader(program, fragShader);
//TODO: Chrome seems a bit buggy with attribute bindings...
if (attribs) {
for (var key in attribs) {
if (attribs.hasOwnProperty(key)) {
gl.bindAttribLocation(program, Math.floor(attribs[key]), key);
}
}
}
gl.linkProgram(program);
log += gl.getProgramInfoLog(program) || "";
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
if (verbose) {
console.error("Shader error:\n"+log);
console.error("Problematic shaders:\nVERTEX_SHADER:\n"+addLineNumbers(vertSource)
+"\n\nFRAGMENT_SHADER:\n"+addLineNumbers(fragSource));
}
//delete before throwing error
gl.detachShader(program, vertShader);
gl.detachShader(program, fragShader);
gl.deleteShader(vertShader);
gl.deleteShader(fragShader);
throw new Error("Error linking the shader program:\n" + log);
}
return {
program: program,
vertex: vertShader,
fragment: fragShader,
log: log.trim()
};
}
|
javascript
|
function compile(gl, vertSource, fragSource, attribs, verbose) {
var log = "";
var vert = loadShader(gl, gl.VERTEX_SHADER, vertSource, verbose);
var frag = loadShader(gl, gl.FRAGMENT_SHADER, fragSource, verbose);
var vertShader = vert.shader;
var fragShader = frag.shader;
log += vert.log + "\n" + frag.log;
var program = gl.createProgram();
gl.attachShader(program, vertShader);
gl.attachShader(program, fragShader);
//TODO: Chrome seems a bit buggy with attribute bindings...
if (attribs) {
for (var key in attribs) {
if (attribs.hasOwnProperty(key)) {
gl.bindAttribLocation(program, Math.floor(attribs[key]), key);
}
}
}
gl.linkProgram(program);
log += gl.getProgramInfoLog(program) || "";
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
if (verbose) {
console.error("Shader error:\n"+log);
console.error("Problematic shaders:\nVERTEX_SHADER:\n"+addLineNumbers(vertSource)
+"\n\nFRAGMENT_SHADER:\n"+addLineNumbers(fragSource));
}
//delete before throwing error
gl.detachShader(program, vertShader);
gl.detachShader(program, fragShader);
gl.deleteShader(vertShader);
gl.deleteShader(fragShader);
throw new Error("Error linking the shader program:\n" + log);
}
return {
program: program,
vertex: vertShader,
fragment: fragShader,
log: log.trim()
};
}
|
[
"function",
"compile",
"(",
"gl",
",",
"vertSource",
",",
"fragSource",
",",
"attribs",
",",
"verbose",
")",
"{",
"var",
"log",
"=",
"\"\"",
";",
"var",
"vert",
"=",
"loadShader",
"(",
"gl",
",",
"gl",
".",
"VERTEX_SHADER",
",",
"vertSource",
",",
"verbose",
")",
";",
"var",
"frag",
"=",
"loadShader",
"(",
"gl",
",",
"gl",
".",
"FRAGMENT_SHADER",
",",
"fragSource",
",",
"verbose",
")",
";",
"var",
"vertShader",
"=",
"vert",
".",
"shader",
";",
"var",
"fragShader",
"=",
"frag",
".",
"shader",
";",
"log",
"+=",
"vert",
".",
"log",
"+",
"\"\\n\"",
"+",
"frag",
".",
"log",
";",
"var",
"program",
"=",
"gl",
".",
"createProgram",
"(",
")",
";",
"gl",
".",
"attachShader",
"(",
"program",
",",
"vertShader",
")",
";",
"gl",
".",
"attachShader",
"(",
"program",
",",
"fragShader",
")",
";",
"//TODO: Chrome seems a bit buggy with attribute bindings...",
"if",
"(",
"attribs",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"attribs",
")",
"{",
"if",
"(",
"attribs",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"gl",
".",
"bindAttribLocation",
"(",
"program",
",",
"Math",
".",
"floor",
"(",
"attribs",
"[",
"key",
"]",
")",
",",
"key",
")",
";",
"}",
"}",
"}",
"gl",
".",
"linkProgram",
"(",
"program",
")",
";",
"log",
"+=",
"gl",
".",
"getProgramInfoLog",
"(",
"program",
")",
"||",
"\"\"",
";",
"if",
"(",
"!",
"gl",
".",
"getProgramParameter",
"(",
"program",
",",
"gl",
".",
"LINK_STATUS",
")",
")",
"{",
"if",
"(",
"verbose",
")",
"{",
"console",
".",
"error",
"(",
"\"Shader error:\\n\"",
"+",
"log",
")",
";",
"console",
".",
"error",
"(",
"\"Problematic shaders:\\nVERTEX_SHADER:\\n\"",
"+",
"addLineNumbers",
"(",
"vertSource",
")",
"+",
"\"\\n\\nFRAGMENT_SHADER:\\n\"",
"+",
"addLineNumbers",
"(",
"fragSource",
")",
")",
";",
"}",
"//delete before throwing error ",
"gl",
".",
"detachShader",
"(",
"program",
",",
"vertShader",
")",
";",
"gl",
".",
"detachShader",
"(",
"program",
",",
"fragShader",
")",
";",
"gl",
".",
"deleteShader",
"(",
"vertShader",
")",
";",
"gl",
".",
"deleteShader",
"(",
"fragShader",
")",
";",
"throw",
"new",
"Error",
"(",
"\"Error linking the shader program:\\n\"",
"+",
"log",
")",
";",
"}",
"return",
"{",
"program",
":",
"program",
",",
"vertex",
":",
"vertShader",
",",
"fragment",
":",
"fragShader",
",",
"log",
":",
"log",
".",
"trim",
"(",
")",
"}",
";",
"}"
] |
Compiles the shaders, throwing an error if the program was invalid.
|
[
"Compiles",
"the",
"shaders",
"throwing",
"an",
"error",
"if",
"the",
"program",
"was",
"invalid",
"."
] |
0d8f658c19f4e4414504b4304314ca3b8286433e
|
https://github.com/mattdesl/webgl-compile-shader/blob/0d8f658c19f4e4414504b4304314ca3b8286433e/index.js#L20-L70
|
37,824 |
byron-dupreez/aws-core-utils
|
kms-utils.js
|
encrypt
|
function encrypt(kms, params, logger) {
logger = logger || console;
const startMs = Date.now();
return kms.encrypt(params).promise().then(
result => {
if (logger.traceEnabled) logger.trace(`KMS encrypt success took ${Date.now() - startMs} ms`);
return result;
},
err => {
logger.error(`KMS encrypt failure took ${Date.now() - startMs} ms`, err);
throw err;
}
);
}
|
javascript
|
function encrypt(kms, params, logger) {
logger = logger || console;
const startMs = Date.now();
return kms.encrypt(params).promise().then(
result => {
if (logger.traceEnabled) logger.trace(`KMS encrypt success took ${Date.now() - startMs} ms`);
return result;
},
err => {
logger.error(`KMS encrypt failure took ${Date.now() - startMs} ms`, err);
throw err;
}
);
}
|
[
"function",
"encrypt",
"(",
"kms",
",",
"params",
",",
"logger",
")",
"{",
"logger",
"=",
"logger",
"||",
"console",
";",
"const",
"startMs",
"=",
"Date",
".",
"now",
"(",
")",
";",
"return",
"kms",
".",
"encrypt",
"(",
"params",
")",
".",
"promise",
"(",
")",
".",
"then",
"(",
"result",
"=>",
"{",
"if",
"(",
"logger",
".",
"traceEnabled",
")",
"logger",
".",
"trace",
"(",
"`",
"${",
"Date",
".",
"now",
"(",
")",
"-",
"startMs",
"}",
"`",
")",
";",
"return",
"result",
";",
"}",
",",
"err",
"=>",
"{",
"logger",
".",
"error",
"(",
"`",
"${",
"Date",
".",
"now",
"(",
")",
"-",
"startMs",
"}",
"`",
",",
"err",
")",
";",
"throw",
"err",
";",
"}",
")",
";",
"}"
] |
Encrypts the plaintext within the given KMS parameters using the given AWS.KMS instance & returns the KMS result.
@param {AWS.KMS} kms - an AWS.KMS instance to use
@param {KMSEncryptParams} params - the KMS encrypt parameters to use
@param {Logger|console|undefined} [logger] - an optional logger to use (defaults to console if omitted)
@returns {Promise.<KMSEncryptResult>} a promise of the KMS encrypt result
|
[
"Encrypts",
"the",
"plaintext",
"within",
"the",
"given",
"KMS",
"parameters",
"using",
"the",
"given",
"AWS",
".",
"KMS",
"instance",
"&",
"returns",
"the",
"KMS",
"result",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/kms-utils.js#L22-L35
|
37,825 |
byron-dupreez/aws-core-utils
|
kms-utils.js
|
encryptKey
|
function encryptKey(kms, keyId, plaintext, logger) {
const params = {KeyId: keyId, Plaintext: plaintext};
return encrypt(kms, params, logger).then(result => result.CiphertextBlob && result.CiphertextBlob.toString('base64'));
}
|
javascript
|
function encryptKey(kms, keyId, plaintext, logger) {
const params = {KeyId: keyId, Plaintext: plaintext};
return encrypt(kms, params, logger).then(result => result.CiphertextBlob && result.CiphertextBlob.toString('base64'));
}
|
[
"function",
"encryptKey",
"(",
"kms",
",",
"keyId",
",",
"plaintext",
",",
"logger",
")",
"{",
"const",
"params",
"=",
"{",
"KeyId",
":",
"keyId",
",",
"Plaintext",
":",
"plaintext",
"}",
";",
"return",
"encrypt",
"(",
"kms",
",",
"params",
",",
"logger",
")",
".",
"then",
"(",
"result",
"=>",
"result",
".",
"CiphertextBlob",
"&&",
"result",
".",
"CiphertextBlob",
".",
"toString",
"(",
"'base64'",
")",
")",
";",
"}"
] |
Encrypts the given plaintext using the given AWS.KMS instance & returns the encrypted ciphertext.
@param {AWS.KMS} kms - an AWS.KMS instance to use
@param {string} keyId - the identifier of the CMK to use for encryption. You can use the key ID or Amazon Resource Name (ARN) of the CMK, or the name or ARN of an alias that refers to the CMK.
@param {string} plaintext - the plaintext to encrypt
@param {Logger|console|undefined} [logger] - an optional logger to use (defaults to console if omitted)
@returns {Promise.<string>} a promise of the encrypted ciphertext
|
[
"Encrypts",
"the",
"given",
"plaintext",
"using",
"the",
"given",
"AWS",
".",
"KMS",
"instance",
"&",
"returns",
"the",
"encrypted",
"ciphertext",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/kms-utils.js#L67-L70
|
37,826 |
byron-dupreez/aws-core-utils
|
kms-utils.js
|
decryptKey
|
function decryptKey(kms, ciphertextBase64, logger) {
const params = {CiphertextBlob: new Buffer(ciphertextBase64, 'base64')};
return decrypt(kms, params, logger).then(result => result.Plaintext && result.Plaintext.toString('utf8'));
}
|
javascript
|
function decryptKey(kms, ciphertextBase64, logger) {
const params = {CiphertextBlob: new Buffer(ciphertextBase64, 'base64')};
return decrypt(kms, params, logger).then(result => result.Plaintext && result.Plaintext.toString('utf8'));
}
|
[
"function",
"decryptKey",
"(",
"kms",
",",
"ciphertextBase64",
",",
"logger",
")",
"{",
"const",
"params",
"=",
"{",
"CiphertextBlob",
":",
"new",
"Buffer",
"(",
"ciphertextBase64",
",",
"'base64'",
")",
"}",
";",
"return",
"decrypt",
"(",
"kms",
",",
"params",
",",
"logger",
")",
".",
"then",
"(",
"result",
"=>",
"result",
".",
"Plaintext",
"&&",
"result",
".",
"Plaintext",
".",
"toString",
"(",
"'utf8'",
")",
")",
";",
"}"
] |
Decrypts the given ciphertext in base 64 using the given AWS.KMS instance & returns the decrypted plaintext.
@param {AWS.KMS} kms - an AWS.KMS instance to use
@param {string} ciphertextBase64 - the encrypted ciphertext in base 64 encoding
@param {Logger|console|undefined} [logger] - an optional logger to use (defaults to console if omitted)
@returns {Promise.<string>} a promise of the decrypted plaintext
|
[
"Decrypts",
"the",
"given",
"ciphertext",
"in",
"base",
"64",
"using",
"the",
"given",
"AWS",
".",
"KMS",
"instance",
"&",
"returns",
"the",
"decrypted",
"plaintext",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/kms-utils.js#L79-L82
|
37,827 |
zerobias/humint
|
index.js
|
genericLog
|
function genericLog(logger, moduletag, logLevel='info'){
const isDebug = logLevel==='debug'
const level = isDebug
? 'info'
: logLevel
const levelLogger = logger[level]
const active = isDebug
? enabled(moduletag)
: true
/**
* tagged Logger
* @function taggedLog
* @param {...string} tags Optional message tags
*/
function taggedLog(...tags) {
const tag = normalizeDefaults(tags)
/**
* message Logger
* @function messageLog
* @template T
* @param {...T} messages message
* @returns {T}
*/
function messageLog(...messages) {
if (active) {
const protectedMessage = messageArrayProtect(messages)
levelLogger(tag, ...protectedMessage)
}
return messages[0]
}
return messageLog
}
/**
* Array logge Prinst every value on separated line
* @function mapLog
* @param {...string} tags Optional message tags
*/
function mapLog(...tags) {
/**
* Array logge Prinst every value on separated line
* @function printArray
* @param {Array} message Printed list
* @returns {Array}
*/
function printArray(message) {
if (active) {
arrayCheck(message)
const tag = normalizeDefaults(tags)
//count length + 2. Also handles edge case with objects without 'length' field
const spaceLn = P(
length,
defaultTo(0),
add(2) )
const ln = sum( map( spaceLn, tags ) )
const spaces = new Array(ln)
.fill(' ')
.join('')
const getFormatted = num => chalk.green(`<${num}>`)
levelLogger( tag, getFormatted(0), head( message ) )
const printTail = (e, i) => levelLogger(spaces, getFormatted(i+1), e)
P(
tail,
indexedMap(printTail)
)(message)
}
return message
}
return printArray
}
taggedLog.map = mapLog
return taggedLog
}
|
javascript
|
function genericLog(logger, moduletag, logLevel='info'){
const isDebug = logLevel==='debug'
const level = isDebug
? 'info'
: logLevel
const levelLogger = logger[level]
const active = isDebug
? enabled(moduletag)
: true
/**
* tagged Logger
* @function taggedLog
* @param {...string} tags Optional message tags
*/
function taggedLog(...tags) {
const tag = normalizeDefaults(tags)
/**
* message Logger
* @function messageLog
* @template T
* @param {...T} messages message
* @returns {T}
*/
function messageLog(...messages) {
if (active) {
const protectedMessage = messageArrayProtect(messages)
levelLogger(tag, ...protectedMessage)
}
return messages[0]
}
return messageLog
}
/**
* Array logge Prinst every value on separated line
* @function mapLog
* @param {...string} tags Optional message tags
*/
function mapLog(...tags) {
/**
* Array logge Prinst every value on separated line
* @function printArray
* @param {Array} message Printed list
* @returns {Array}
*/
function printArray(message) {
if (active) {
arrayCheck(message)
const tag = normalizeDefaults(tags)
//count length + 2. Also handles edge case with objects without 'length' field
const spaceLn = P(
length,
defaultTo(0),
add(2) )
const ln = sum( map( spaceLn, tags ) )
const spaces = new Array(ln)
.fill(' ')
.join('')
const getFormatted = num => chalk.green(`<${num}>`)
levelLogger( tag, getFormatted(0), head( message ) )
const printTail = (e, i) => levelLogger(spaces, getFormatted(i+1), e)
P(
tail,
indexedMap(printTail)
)(message)
}
return message
}
return printArray
}
taggedLog.map = mapLog
return taggedLog
}
|
[
"function",
"genericLog",
"(",
"logger",
",",
"moduletag",
",",
"logLevel",
"=",
"'info'",
")",
"{",
"const",
"isDebug",
"=",
"logLevel",
"===",
"'debug'",
"const",
"level",
"=",
"isDebug",
"?",
"'info'",
":",
"logLevel",
"const",
"levelLogger",
"=",
"logger",
"[",
"level",
"]",
"const",
"active",
"=",
"isDebug",
"?",
"enabled",
"(",
"moduletag",
")",
":",
"true",
"/**\n * tagged Logger\n * @function taggedLog\n * @param {...string} tags Optional message tags\n */",
"function",
"taggedLog",
"(",
"...",
"tags",
")",
"{",
"const",
"tag",
"=",
"normalizeDefaults",
"(",
"tags",
")",
"/**\n * message Logger\n * @function messageLog\n * @template T\n * @param {...T} messages message\n * @returns {T}\n */",
"function",
"messageLog",
"(",
"...",
"messages",
")",
"{",
"if",
"(",
"active",
")",
"{",
"const",
"protectedMessage",
"=",
"messageArrayProtect",
"(",
"messages",
")",
"levelLogger",
"(",
"tag",
",",
"...",
"protectedMessage",
")",
"}",
"return",
"messages",
"[",
"0",
"]",
"}",
"return",
"messageLog",
"}",
"/**\n * Array logge Prinst every value on separated line\n * @function mapLog\n * @param {...string} tags Optional message tags\n */",
"function",
"mapLog",
"(",
"...",
"tags",
")",
"{",
"/**\n * Array logge Prinst every value on separated line\n * @function printArray\n * @param {Array} message Printed list\n * @returns {Array}\n */",
"function",
"printArray",
"(",
"message",
")",
"{",
"if",
"(",
"active",
")",
"{",
"arrayCheck",
"(",
"message",
")",
"const",
"tag",
"=",
"normalizeDefaults",
"(",
"tags",
")",
"//count length + 2. Also handles edge case with objects without 'length' field",
"const",
"spaceLn",
"=",
"P",
"(",
"length",
",",
"defaultTo",
"(",
"0",
")",
",",
"add",
"(",
"2",
")",
")",
"const",
"ln",
"=",
"sum",
"(",
"map",
"(",
"spaceLn",
",",
"tags",
")",
")",
"const",
"spaces",
"=",
"new",
"Array",
"(",
"ln",
")",
".",
"fill",
"(",
"' '",
")",
".",
"join",
"(",
"''",
")",
"const",
"getFormatted",
"=",
"num",
"=>",
"chalk",
".",
"green",
"(",
"`",
"${",
"num",
"}",
"`",
")",
"levelLogger",
"(",
"tag",
",",
"getFormatted",
"(",
"0",
")",
",",
"head",
"(",
"message",
")",
")",
"const",
"printTail",
"=",
"(",
"e",
",",
"i",
")",
"=>",
"levelLogger",
"(",
"spaces",
",",
"getFormatted",
"(",
"i",
"+",
"1",
")",
",",
"e",
")",
"P",
"(",
"tail",
",",
"indexedMap",
"(",
"printTail",
")",
")",
"(",
"message",
")",
"}",
"return",
"message",
"}",
"return",
"printArray",
"}",
"taggedLog",
".",
"map",
"=",
"mapLog",
"return",
"taggedLog",
"}"
] |
Allow to select log level
@function genericLog
@param {LoggerInstance} logger Winston logger instance
@param {string} moduletag Module tag name
@param {string} logLevel Log level
|
[
"Allow",
"to",
"select",
"log",
"level"
] |
e4074de0a6e972b651a3d38c722cb5d28a24a548
|
https://github.com/zerobias/humint/blob/e4074de0a6e972b651a3d38c722cb5d28a24a548/index.js#L77-L151
|
37,828 |
zerobias/humint
|
index.js
|
mapLog
|
function mapLog(...tags) {
/**
* Array logge Prinst every value on separated line
* @function printArray
* @param {Array} message Printed list
* @returns {Array}
*/
function printArray(message) {
if (active) {
arrayCheck(message)
const tag = normalizeDefaults(tags)
//count length + 2. Also handles edge case with objects without 'length' field
const spaceLn = P(
length,
defaultTo(0),
add(2) )
const ln = sum( map( spaceLn, tags ) )
const spaces = new Array(ln)
.fill(' ')
.join('')
const getFormatted = num => chalk.green(`<${num}>`)
levelLogger( tag, getFormatted(0), head( message ) )
const printTail = (e, i) => levelLogger(spaces, getFormatted(i+1), e)
P(
tail,
indexedMap(printTail)
)(message)
}
return message
}
return printArray
}
|
javascript
|
function mapLog(...tags) {
/**
* Array logge Prinst every value on separated line
* @function printArray
* @param {Array} message Printed list
* @returns {Array}
*/
function printArray(message) {
if (active) {
arrayCheck(message)
const tag = normalizeDefaults(tags)
//count length + 2. Also handles edge case with objects without 'length' field
const spaceLn = P(
length,
defaultTo(0),
add(2) )
const ln = sum( map( spaceLn, tags ) )
const spaces = new Array(ln)
.fill(' ')
.join('')
const getFormatted = num => chalk.green(`<${num}>`)
levelLogger( tag, getFormatted(0), head( message ) )
const printTail = (e, i) => levelLogger(spaces, getFormatted(i+1), e)
P(
tail,
indexedMap(printTail)
)(message)
}
return message
}
return printArray
}
|
[
"function",
"mapLog",
"(",
"...",
"tags",
")",
"{",
"/**\n * Array logge Prinst every value on separated line\n * @function printArray\n * @param {Array} message Printed list\n * @returns {Array}\n */",
"function",
"printArray",
"(",
"message",
")",
"{",
"if",
"(",
"active",
")",
"{",
"arrayCheck",
"(",
"message",
")",
"const",
"tag",
"=",
"normalizeDefaults",
"(",
"tags",
")",
"//count length + 2. Also handles edge case with objects without 'length' field",
"const",
"spaceLn",
"=",
"P",
"(",
"length",
",",
"defaultTo",
"(",
"0",
")",
",",
"add",
"(",
"2",
")",
")",
"const",
"ln",
"=",
"sum",
"(",
"map",
"(",
"spaceLn",
",",
"tags",
")",
")",
"const",
"spaces",
"=",
"new",
"Array",
"(",
"ln",
")",
".",
"fill",
"(",
"' '",
")",
".",
"join",
"(",
"''",
")",
"const",
"getFormatted",
"=",
"num",
"=>",
"chalk",
".",
"green",
"(",
"`",
"${",
"num",
"}",
"`",
")",
"levelLogger",
"(",
"tag",
",",
"getFormatted",
"(",
"0",
")",
",",
"head",
"(",
"message",
")",
")",
"const",
"printTail",
"=",
"(",
"e",
",",
"i",
")",
"=>",
"levelLogger",
"(",
"spaces",
",",
"getFormatted",
"(",
"i",
"+",
"1",
")",
",",
"e",
")",
"P",
"(",
"tail",
",",
"indexedMap",
"(",
"printTail",
")",
")",
"(",
"message",
")",
"}",
"return",
"message",
"}",
"return",
"printArray",
"}"
] |
Array logge Prinst every value on separated line
@function mapLog
@param {...string} tags Optional message tags
|
[
"Array",
"logge",
"Prinst",
"every",
"value",
"on",
"separated",
"line"
] |
e4074de0a6e972b651a3d38c722cb5d28a24a548
|
https://github.com/zerobias/humint/blob/e4074de0a6e972b651a3d38c722cb5d28a24a548/index.js#L115-L148
|
37,829 |
zerobias/humint
|
index.js
|
Logger
|
function Logger(moduletag) {
const trimmedModule = trim(moduletag)
winston.loggers.add(trimmedModule, {
console: {
colorize: true,
label : trimmedModule
}
})
const logger = winston.loggers.get(trimmedModule)
const defs = genericLog(logger, trimmedModule)
defs.warn = genericLog(logger, trimmedModule, 'warn')
defs.error = genericLog(logger, trimmedModule, 'error')
defs.debug = genericLog(logger, trimmedModule, 'debug')
defs.info = genericLog(logger, trimmedModule, 'info')
return defs
}
|
javascript
|
function Logger(moduletag) {
const trimmedModule = trim(moduletag)
winston.loggers.add(trimmedModule, {
console: {
colorize: true,
label : trimmedModule
}
})
const logger = winston.loggers.get(trimmedModule)
const defs = genericLog(logger, trimmedModule)
defs.warn = genericLog(logger, trimmedModule, 'warn')
defs.error = genericLog(logger, trimmedModule, 'error')
defs.debug = genericLog(logger, trimmedModule, 'debug')
defs.info = genericLog(logger, trimmedModule, 'info')
return defs
}
|
[
"function",
"Logger",
"(",
"moduletag",
")",
"{",
"const",
"trimmedModule",
"=",
"trim",
"(",
"moduletag",
")",
"winston",
".",
"loggers",
".",
"add",
"(",
"trimmedModule",
",",
"{",
"console",
":",
"{",
"colorize",
":",
"true",
",",
"label",
":",
"trimmedModule",
"}",
"}",
")",
"const",
"logger",
"=",
"winston",
".",
"loggers",
".",
"get",
"(",
"trimmedModule",
")",
"const",
"defs",
"=",
"genericLog",
"(",
"logger",
",",
"trimmedModule",
")",
"defs",
".",
"warn",
"=",
"genericLog",
"(",
"logger",
",",
"trimmedModule",
",",
"'warn'",
")",
"defs",
".",
"error",
"=",
"genericLog",
"(",
"logger",
",",
"trimmedModule",
",",
"'error'",
")",
"defs",
".",
"debug",
"=",
"genericLog",
"(",
"logger",
",",
"trimmedModule",
",",
"'debug'",
")",
"defs",
".",
"info",
"=",
"genericLog",
"(",
"logger",
",",
"trimmedModule",
",",
"'info'",
")",
"return",
"defs",
"}"
] |
Logging function based on winston library
@function Logger
@param {string} moduletag Name of apps module
|
[
"Logging",
"function",
"based",
"on",
"winston",
"library"
] |
e4074de0a6e972b651a3d38c722cb5d28a24a548
|
https://github.com/zerobias/humint/blob/e4074de0a6e972b651a3d38c722cb5d28a24a548/index.js#L157-L172
|
37,830 |
byron-dupreez/aws-core-utils
|
lambdas.js
|
getInvokedFunctionArnFunctionName
|
function getInvokedFunctionArnFunctionName(awsContext) {
const invokedFunctionArn = awsContext && awsContext.invokedFunctionArn;
const resources = getArnResources(invokedFunctionArn);
return resources.resource;
}
|
javascript
|
function getInvokedFunctionArnFunctionName(awsContext) {
const invokedFunctionArn = awsContext && awsContext.invokedFunctionArn;
const resources = getArnResources(invokedFunctionArn);
return resources.resource;
}
|
[
"function",
"getInvokedFunctionArnFunctionName",
"(",
"awsContext",
")",
"{",
"const",
"invokedFunctionArn",
"=",
"awsContext",
"&&",
"awsContext",
".",
"invokedFunctionArn",
";",
"const",
"resources",
"=",
"getArnResources",
"(",
"invokedFunctionArn",
")",
";",
"return",
"resources",
".",
"resource",
";",
"}"
] |
Extracts and returns the function name from the given AWS context's invokedFunctionArn.
@param {AWSContext} awsContext - the AWS context
@returns {string} the extracted function name
|
[
"Extracts",
"and",
"returns",
"the",
"function",
"name",
"from",
"the",
"given",
"AWS",
"context",
"s",
"invokedFunctionArn",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/lambdas.js#L59-L63
|
37,831 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(search, type, limit, fields) {
if (!search) return Promise.reject(new Error('wotblitz.account.list: search is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/account/list/'
}, {
fields: fields ? fields.toString() : '',
limit: limit,
search: search,
type: type
});
}
|
javascript
|
function(search, type, limit, fields) {
if (!search) return Promise.reject(new Error('wotblitz.account.list: search is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/account/list/'
}, {
fields: fields ? fields.toString() : '',
limit: limit,
search: search,
type: type
});
}
|
[
"function",
"(",
"search",
",",
"type",
",",
"limit",
",",
"fields",
")",
"{",
"if",
"(",
"!",
"search",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.account.list: search is required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/account/list/'",
"}",
",",
"{",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
",",
"limit",
":",
"limit",
",",
"search",
":",
"search",
",",
"type",
":",
"type",
"}",
")",
";",
"}"
] |
Search for a player.
@param {string} search value to match usernames
@param {string} [type] how to match, "startswith" or "exact"
@param {number} [limit] maximum number of entries to match
@param {string|string[]} [fields] response selection
@returns {Promise<Object[]> resolves to an array of matching accounts
|
[
"Search",
"for",
"a",
"player",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L158-L170
|
|
37,832 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, expires_at) {
if (!access_token) return Promise.reject(new Error('wotblitz.auth.prolongate: access_token is required'));
return request({
hostname: hosts.wot,
path: '/wot/auth/prolongate/'
}, {
access_token: access_token,
expires_at: expires_at || 14 * 24 * 60 * 60 // 14 days in seconds
});
}
|
javascript
|
function(access_token, expires_at) {
if (!access_token) return Promise.reject(new Error('wotblitz.auth.prolongate: access_token is required'));
return request({
hostname: hosts.wot,
path: '/wot/auth/prolongate/'
}, {
access_token: access_token,
expires_at: expires_at || 14 * 24 * 60 * 60 // 14 days in seconds
});
}
|
[
"function",
"(",
"access_token",
",",
"expires_at",
")",
"{",
"if",
"(",
"!",
"access_token",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.auth.prolongate: access_token is required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wot",
",",
"path",
":",
"'/wot/auth/prolongate/'",
"}",
",",
"{",
"access_token",
":",
"access_token",
",",
"expires_at",
":",
"expires_at",
"||",
"14",
"*",
"24",
"*",
"60",
"*",
"60",
"// 14 days in seconds",
"}",
")",
";",
"}"
] |
Access token extension
@param {string} access_token user's authentication string
@param {number} [expires_at] date or time span of expiration (default: 14 days)
@returns {Promise<Object>} resolves to the new token and related information
|
[
"Access",
"token",
"extension"
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L264-L274
|
|
37,833 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, message_id, filters, fields) {
if (!access_token) return Promise.reject(new Error('wotblitz.clanmessages.messages: access_token is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/messages/'
}, Object.assign({
access_token: access_token,
message_id: message_id,
fields: fields ? fields.toString() : ''
}, filters, {
order_by: filters && filters.order_by ? filters.order_by.toString() : ''
}));
}
|
javascript
|
function(access_token, message_id, filters, fields) {
if (!access_token) return Promise.reject(new Error('wotblitz.clanmessages.messages: access_token is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/messages/'
}, Object.assign({
access_token: access_token,
message_id: message_id,
fields: fields ? fields.toString() : ''
}, filters, {
order_by: filters && filters.order_by ? filters.order_by.toString() : ''
}));
}
|
[
"function",
"(",
"access_token",
",",
"message_id",
",",
"filters",
",",
"fields",
")",
"{",
"if",
"(",
"!",
"access_token",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.messages: access_token is required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clanmessages/messages/'",
"}",
",",
"Object",
".",
"assign",
"(",
"{",
"access_token",
":",
"access_token",
",",
"message_id",
":",
"message_id",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
",",
"filters",
",",
"{",
"order_by",
":",
"filters",
"&&",
"filters",
".",
"order_by",
"?",
"filters",
".",
"order_by",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
")",
";",
"}"
] |
The text and meta data of all conversation.
@param {string} access_token user's authentication string
@param {number} [message_id] a specific message
@param {Object} [filters] options
@param {number} [filters.page_no] which page
@param {number} [filters.limit] how many per page
@param {string|string[]} [filters.order_by] which field(s) to order the response (too many values to list)
@param {number|date} [filters.expires_before] only messages before this date (unix or ISO)
@param {number|date} [filters.expires_after] only messages on or after this date (unix or ISO)
@param {string} [filters.importance] only messages with this level, values "important" or "standard"
@param {string} [filters.status] only messages with this status, values "active" or "deleted"
@param {string} [filters.type] only messages of this type, values "general", "training", "meeting", or "battle"
@param {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to a message board object
|
[
"The",
"text",
"and",
"meta",
"data",
"of",
"all",
"conversation",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L311-L324
|
|
37,834 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, title, text, type, importance, expires_at) {
if (!expires_at) return Promise.reject(new Error('wotblitz.clanmessages.create: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/create/'
}, {
access_token: access_token,
expires_at: expires_at,
importance: importance,
text: text,
title: title,
type: type
});
}
|
javascript
|
function(access_token, title, text, type, importance, expires_at) {
if (!expires_at) return Promise.reject(new Error('wotblitz.clanmessages.create: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/create/'
}, {
access_token: access_token,
expires_at: expires_at,
importance: importance,
text: text,
title: title,
type: type
});
}
|
[
"function",
"(",
"access_token",
",",
"title",
",",
"text",
",",
"type",
",",
"importance",
",",
"expires_at",
")",
"{",
"if",
"(",
"!",
"expires_at",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.create: all arguments are required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clanmessages/create/'",
"}",
",",
"{",
"access_token",
":",
"access_token",
",",
"expires_at",
":",
"expires_at",
",",
"importance",
":",
"importance",
",",
"text",
":",
"text",
",",
"title",
":",
"title",
",",
"type",
":",
"type",
"}",
")",
";",
"}"
] |
Post a new message.
@param {string} access_token user's authentication string
@param {string} title message topic
@param {string} text message body
@param {string} type message category, values "general", "training", "meeting", or "battle"
@param {string} importance values "important" or "standard"
@param {string} expires_at invalidation date
@returns {Promise<Object>} resolves to the `message_id`
|
[
"Post",
"a",
"new",
"message",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L336-L350
|
|
37,835 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, message_id) {
if (!message_id) return Promise.reject(new Error('wotblitz.clanmessages.delete: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/delete/'
}, {
access_token: access_token,
message_id: message_id
});
}
|
javascript
|
function(access_token, message_id) {
if (!message_id) return Promise.reject(new Error('wotblitz.clanmessages.delete: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/delete/'
}, {
access_token: access_token,
message_id: message_id
});
}
|
[
"function",
"(",
"access_token",
",",
"message_id",
")",
"{",
"if",
"(",
"!",
"message_id",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.delete: all arguments are required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clanmessages/delete/'",
"}",
",",
"{",
"access_token",
":",
"access_token",
",",
"message_id",
":",
"message_id",
"}",
")",
";",
"}"
] |
Remove a message.
@param {string} access_token user's authentication string
@param {number} message_id exactly this message
@returns {Promise<Object>} resolves to an empty object
|
[
"Remove",
"a",
"message",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L358-L368
|
|
37,836 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, message_id, action) {
if (!action) return Promise.reject(new Error('wotblitz.clanmessages.like: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/like/'
}, {
access_token,
action: action,
message_id: message_id
});
}
|
javascript
|
function(access_token, message_id, action) {
if (!action) return Promise.reject(new Error('wotblitz.clanmessages.like: all arguments are required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/like/'
}, {
access_token,
action: action,
message_id: message_id
});
}
|
[
"function",
"(",
"access_token",
",",
"message_id",
",",
"action",
")",
"{",
"if",
"(",
"!",
"action",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.like: all arguments are required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clanmessages/like/'",
"}",
",",
"{",
"access_token",
",",
"action",
":",
"action",
",",
"message_id",
":",
"message_id",
"}",
")",
";",
"}"
] |
Set like value on a message.
@param {string} access_token user's authentication string
@param {number} message_id exactly this message
@param {string} action literally "add" or "remove"
@returns {Promise<Object>} resolves to an empty object
|
[
"Set",
"like",
"value",
"on",
"a",
"message",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L377-L388
|
|
37,837 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(access_token, message_id, fields) {
if (!access_token) return Promise.reject(new Error('wotblitz.clanmessages.likes: access_token is required'));
if (!message_id) return Promise.reject(new Error('wotblitz.clanmessages.likes: message_id is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/likes/'
}, {
access_token: access_token,
message_id: message_id,
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(access_token, message_id, fields) {
if (!access_token) return Promise.reject(new Error('wotblitz.clanmessages.likes: access_token is required'));
if (!message_id) return Promise.reject(new Error('wotblitz.clanmessages.likes: message_id is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/clanmessages/likes/'
}, {
access_token: access_token,
message_id: message_id,
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"access_token",
",",
"message_id",
",",
"fields",
")",
"{",
"if",
"(",
"!",
"access_token",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.likes: access_token is required'",
")",
")",
";",
"if",
"(",
"!",
"message_id",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.clanmessages.likes: message_id is required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clanmessages/likes/'",
"}",
",",
"{",
"access_token",
":",
"access_token",
",",
"message_id",
":",
"message_id",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
All likes on a message.
@params {string} access_token user's authentication string
@params {number} message_id exactly this message
@params {string|string[]} [fields] response selection
@returns {Promise<Object[]>} resolves to list of by whom and when a like was added
|
[
"All",
"likes",
"on",
"a",
"message",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L397-L409
|
|
37,838 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(search, page_no, limit, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/clans/list/'
}, {
search: search,
page_no: page_no,
limit: limit,
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(search, page_no, limit, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/clans/list/'
}, {
search: search,
page_no: page_no,
limit: limit,
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"search",
",",
"page_no",
",",
"limit",
",",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clans/list/'",
"}",
",",
"{",
"search",
":",
"search",
",",
"page_no",
":",
"page_no",
",",
"limit",
":",
"limit",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
List of clans with minimal details.
@param {string} [search] filter by clan name or tag
@param {number} [page_no] which page to return, starting at 1
@param {number} [limit] max count of entries
@param {string|string[]} [fields] response selection
@returns {Promise<Object[]>} resolves to a list of short clan descriptions
|
[
"List",
"of",
"clans",
"with",
"minimal",
"details",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L451-L461
|
|
37,839 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/clans/glossary/'
}, {
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/clans/glossary/'
}, {
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/clans/glossary/'",
"}",
",",
"{",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
Meta information about clans.
@param {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to clan terminology definitions
|
[
"Meta",
"information",
"about",
"clans",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L508-L515
|
|
37,840 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(tank_id, nation, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/vehicles/'
}, {
tank_id: tank_id ? tank_id.toString() : '',
nation: nation ? nation.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(tank_id, nation, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/vehicles/'
}, {
tank_id: tank_id ? tank_id.toString() : '',
nation: nation ? nation.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"tank_id",
",",
"nation",
",",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/encyclopedia/vehicles/'",
"}",
",",
"{",
"tank_id",
":",
"tank_id",
"?",
"tank_id",
".",
"toString",
"(",
")",
":",
"''",
",",
"nation",
":",
"nation",
"?",
"nation",
".",
"toString",
"(",
")",
":",
"''",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
List of vehicle information
@param {number|number[]} [tank_id] limit to this vehicle id(s) only
@param {string|string[]} [nation] limit to vehicle in this tech tree(s)
@param {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to description of requested vehicles
|
[
"List",
"of",
"vehicle",
"information"
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L527-L536
|
|
37,841 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(tank_id, profile_id, modules, fields) {
if (!tank_id) return Promise.reject(new Error('wotblitz.encyclopedia.vehicleprofile: tank_id is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/vehicleprofile/'
}, Object.assign({
tank_id: tank_id,
fields: fields ? fields.toString() : ''
}, modules || {
profile_id: profile_id
}));
}
|
javascript
|
function(tank_id, profile_id, modules, fields) {
if (!tank_id) return Promise.reject(new Error('wotblitz.encyclopedia.vehicleprofile: tank_id is required'));
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/vehicleprofile/'
}, Object.assign({
tank_id: tank_id,
fields: fields ? fields.toString() : ''
}, modules || {
profile_id: profile_id
}));
}
|
[
"function",
"(",
"tank_id",
",",
"profile_id",
",",
"modules",
",",
"fields",
")",
"{",
"if",
"(",
"!",
"tank_id",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'wotblitz.encyclopedia.vehicleprofile: tank_id is required'",
")",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/encyclopedia/vehicleprofile/'",
"}",
",",
"Object",
".",
"assign",
"(",
"{",
"tank_id",
":",
"tank_id",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
",",
"modules",
"||",
"{",
"profile_id",
":",
"profile_id",
"}",
")",
")",
";",
"}"
] |
Characteristics with different vehicle modules installed.
@param {string} tank_id vehicle to select
@param {string} [profile_id] shorthand returned by the "vehicleprofiles" route
@param {Object} [modules] specify modules individually (overrides profile_id)
@param {number} [modules.engine_id] which engine module to select
@param {number} [modules.gun_id] which gun module to select
@param {number} [modules.suspension_id] which suspension module to select
@param {number} [modules.turret_id] which turret module to select
@param {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to exact vehicle information
|
[
"Characteristics",
"with",
"different",
"vehicle",
"modules",
"installed",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L550-L562
|
|
37,842 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(module_id, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/modules/'
}, {
module_id: module_id ? module_id.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(module_id, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/modules/'
}, {
module_id: module_id ? module_id.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"module_id",
",",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/encyclopedia/modules/'",
"}",
",",
"{",
"module_id",
":",
"module_id",
"?",
"module_id",
".",
"toString",
"(",
")",
":",
"''",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
Information on any engine, suspension, gun, or turret.
@params {number|number[]} [module_id] id of any vehicle's module
@params {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to description of each module
|
[
"Information",
"on",
"any",
"engine",
"suspension",
"gun",
"or",
"turret",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L570-L578
|
|
37,843 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(tank_id, provision_id, type, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/provisions/'
}, {
tank_id: tank_id ? tank_id.toString() : '',
provision_id: provision_id ? provision_id.toString() : '',
type: type,
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(tank_id, provision_id, type, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/provisions/'
}, {
tank_id: tank_id ? tank_id.toString() : '',
provision_id: provision_id ? provision_id.toString() : '',
type: type,
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"tank_id",
",",
"provision_id",
",",
"type",
",",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/encyclopedia/provisions/'",
"}",
",",
"{",
"tank_id",
":",
"tank_id",
"?",
"tank_id",
".",
"toString",
"(",
")",
":",
"''",
",",
"provision_id",
":",
"provision_id",
"?",
"provision_id",
".",
"toString",
"(",
")",
":",
"''",
",",
"type",
":",
"type",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
Available equipment and provisions.
@param {number|number[]} [tank_id] select provisions for the given tank(s)
@param {number|number[]} [provision_id] item id
@param {string} [type] provision type, value "optionalDevice" or "equipment"
@param {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to description of each provision
|
[
"Available",
"equipment",
"and",
"provisions",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L588-L598
|
|
37,844 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(skill_id, vehicle_type, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/crewskills/'
}, {
skill_id: skill_id ? skill_id.toString() : '',
vehicle_type: vehicle_type ? vehicle_type.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
javascript
|
function(skill_id, vehicle_type, fields) {
return request({
hostname: hosts.wotb,
path: '/wotb/encyclopedia/crewskills/'
}, {
skill_id: skill_id ? skill_id.toString() : '',
vehicle_type: vehicle_type ? vehicle_type.toString() : '',
fields: fields ? fields.toString() : ''
});
}
|
[
"function",
"(",
"skill_id",
",",
"vehicle_type",
",",
"fields",
")",
"{",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/encyclopedia/crewskills/'",
"}",
",",
"{",
"skill_id",
":",
"skill_id",
"?",
"skill_id",
".",
"toString",
"(",
")",
":",
"''",
",",
"vehicle_type",
":",
"vehicle_type",
"?",
"vehicle_type",
".",
"toString",
"(",
")",
":",
"''",
",",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"}"
] |
Description of crew skills.
@params {string|string[]} [skill_id] name of skill(s) to request
@params {string|string[]} [vehicle_type] select skill category
@params {string|string[]} [fields] response selection
@returns {Promise<Object>} resolves to the description
|
[
"Description",
"of",
"crew",
"skills",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L635-L644
|
|
37,845 |
CodeMan99/wotblitz.js
|
wotblitz.js
|
function(options, fields) {
options = Object.assign({
search: null,
status: null,
page_no: null,
limit: null
}, options, {
fields: fields ? fields.toString() : ''
});
if (Array.isArray(options.status)) options.status = options.status.toString();
return request({
hostname: hosts.wotb,
path: '/wotb/tournaments/list/'
}, options);
}
|
javascript
|
function(options, fields) {
options = Object.assign({
search: null,
status: null,
page_no: null,
limit: null
}, options, {
fields: fields ? fields.toString() : ''
});
if (Array.isArray(options.status)) options.status = options.status.toString();
return request({
hostname: hosts.wotb,
path: '/wotb/tournaments/list/'
}, options);
}
|
[
"function",
"(",
"options",
",",
"fields",
")",
"{",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"search",
":",
"null",
",",
"status",
":",
"null",
",",
"page_no",
":",
"null",
",",
"limit",
":",
"null",
"}",
",",
"options",
",",
"{",
"fields",
":",
"fields",
"?",
"fields",
".",
"toString",
"(",
")",
":",
"''",
"}",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"options",
".",
"status",
")",
")",
"options",
".",
"status",
"=",
"options",
".",
"status",
".",
"toString",
"(",
")",
";",
"return",
"request",
"(",
"{",
"hostname",
":",
"hosts",
".",
"wotb",
",",
"path",
":",
"'/wotb/tournaments/list/'",
"}",
",",
"options",
")",
";",
"}"
] |
List of all tournaments.
@param {Object} [options]
@param {string} [options.search]
@param {string|string[]} [options.status]
@param {number} [options.page_no]
@param {number} [options.limit]
@param {string|string[]} [fields] response selection
@returns {Promise<Object>}
|
[
"List",
"of",
"all",
"tournaments",
"."
] |
d4a56e4523704418029e2b9846410b31a8d69478
|
https://github.com/CodeMan99/wotblitz.js/blob/d4a56e4523704418029e2b9846410b31a8d69478/wotblitz.js#L749-L765
|
|
37,846 |
d5/deep-defaults
|
lib/index.js
|
_deepDefaults
|
function _deepDefaults(dest, src) {
if(_.isUndefined(dest) || _.isNull(dest) || !_.isPlainObject(dest)) { return dest; }
_.each(src, function(v, k) {
if(_.isUndefined(dest[k])) {
dest[k] = v;
} else if(_.isPlainObject(v)) {
_deepDefaults(dest[k], v);
}
});
return dest;
}
|
javascript
|
function _deepDefaults(dest, src) {
if(_.isUndefined(dest) || _.isNull(dest) || !_.isPlainObject(dest)) { return dest; }
_.each(src, function(v, k) {
if(_.isUndefined(dest[k])) {
dest[k] = v;
} else if(_.isPlainObject(v)) {
_deepDefaults(dest[k], v);
}
});
return dest;
}
|
[
"function",
"_deepDefaults",
"(",
"dest",
",",
"src",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"dest",
")",
"||",
"_",
".",
"isNull",
"(",
"dest",
")",
"||",
"!",
"_",
".",
"isPlainObject",
"(",
"dest",
")",
")",
"{",
"return",
"dest",
";",
"}",
"_",
".",
"each",
"(",
"src",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"dest",
"[",
"k",
"]",
")",
")",
"{",
"dest",
"[",
"k",
"]",
"=",
"v",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isPlainObject",
"(",
"v",
")",
")",
"{",
"_deepDefaults",
"(",
"dest",
"[",
"k",
"]",
",",
"v",
")",
";",
"}",
"}",
")",
";",
"return",
"dest",
";",
"}"
] |
Recursively assigns own enumerable properties of the source object to the destination object for all destination properties that resolve to undefined.
@param {Object} dest destination object; this object is modified.
@param {Object} src source object that has the defaults
@returns {Object} destination object
|
[
"Recursively",
"assigns",
"own",
"enumerable",
"properties",
"of",
"the",
"source",
"object",
"to",
"the",
"destination",
"object",
"for",
"all",
"destination",
"properties",
"that",
"resolve",
"to",
"undefined",
"."
] |
321d0e2231aa807d54e7f95d75c22048a806923f
|
https://github.com/d5/deep-defaults/blob/321d0e2231aa807d54e7f95d75c22048a806923f/lib/index.js#L11-L23
|
37,847 |
evanshortiss/browser-local-storage
|
lib/LocalStorage.js
|
genStorageKey
|
function genStorageKey (ns, key) {
return (ns === '') ? ns.concat(key) : ns.concat('.').concat(key);
}
|
javascript
|
function genStorageKey (ns, key) {
return (ns === '') ? ns.concat(key) : ns.concat('.').concat(key);
}
|
[
"function",
"genStorageKey",
"(",
"ns",
",",
"key",
")",
"{",
"return",
"(",
"ns",
"===",
"''",
")",
"?",
"ns",
".",
"concat",
"(",
"key",
")",
":",
"ns",
".",
"concat",
"(",
"'.'",
")",
".",
"concat",
"(",
"key",
")",
";",
"}"
] |
Generate a period separated storage key
@param {String} ns Namespace being used
@param {String} key Actual key of the data
@return {String} The generated namespaced key
@api private
|
[
"Generate",
"a",
"period",
"separated",
"storage",
"key"
] |
c1266354837ab71a04bad2ba40554474aa6381f9
|
https://github.com/evanshortiss/browser-local-storage/blob/c1266354837ab71a04bad2ba40554474aa6381f9/lib/LocalStorage.js#L45-L47
|
37,848 |
evanshortiss/browser-local-storage
|
lib/LocalStorage.js
|
LocalStorage
|
function LocalStorage (params) {
events.EventEmitter.call(this);
if (!params || typeof params === 'string') {
params = {
ns: params || ''
};
}
this.ns = params.ns || '';
if (typeof this.ns !== 'string') {
throw new Error('Namespace must be a string.');
}
this.preSave = params.preSave || defProcessor;
this.postLoad = params.postLoad || defProcessor;
if (this.preSave && typeof this.preSave !== 'function') {
throw new Error('preSave option must be a function');
}
if (this.postLoad && typeof this.postLoad !== 'function') {
throw new Error('postLoad option must be a function');
}
this.EVENTS = EVENTS;
}
|
javascript
|
function LocalStorage (params) {
events.EventEmitter.call(this);
if (!params || typeof params === 'string') {
params = {
ns: params || ''
};
}
this.ns = params.ns || '';
if (typeof this.ns !== 'string') {
throw new Error('Namespace must be a string.');
}
this.preSave = params.preSave || defProcessor;
this.postLoad = params.postLoad || defProcessor;
if (this.preSave && typeof this.preSave !== 'function') {
throw new Error('preSave option must be a function');
}
if (this.postLoad && typeof this.postLoad !== 'function') {
throw new Error('postLoad option must be a function');
}
this.EVENTS = EVENTS;
}
|
[
"function",
"LocalStorage",
"(",
"params",
")",
"{",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"!",
"params",
"||",
"typeof",
"params",
"===",
"'string'",
")",
"{",
"params",
"=",
"{",
"ns",
":",
"params",
"||",
"''",
"}",
";",
"}",
"this",
".",
"ns",
"=",
"params",
".",
"ns",
"||",
"''",
";",
"if",
"(",
"typeof",
"this",
".",
"ns",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Namespace must be a string.'",
")",
";",
"}",
"this",
".",
"preSave",
"=",
"params",
".",
"preSave",
"||",
"defProcessor",
";",
"this",
".",
"postLoad",
"=",
"params",
".",
"postLoad",
"||",
"defProcessor",
";",
"if",
"(",
"this",
".",
"preSave",
"&&",
"typeof",
"this",
".",
"preSave",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'preSave option must be a function'",
")",
";",
"}",
"if",
"(",
"this",
".",
"postLoad",
"&&",
"typeof",
"this",
".",
"postLoad",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'postLoad option must be a function'",
")",
";",
"}",
"this",
".",
"EVENTS",
"=",
"EVENTS",
";",
"}"
] |
Class used to provide a wrapper over localStorage
@param {String} [ns] Optional namespace for the adpater.
|
[
"Class",
"used",
"to",
"provide",
"a",
"wrapper",
"over",
"localStorage"
] |
c1266354837ab71a04bad2ba40554474aa6381f9
|
https://github.com/evanshortiss/browser-local-storage/blob/c1266354837ab71a04bad2ba40554474aa6381f9/lib/LocalStorage.js#L63-L90
|
37,849 |
scott-wyatt/sails-stripe
|
templates/Invoiceitem.template.js
|
function (invoiceitem, cb) {
Invoiceitem.findOrCreate(invoiceitem.id, invoiceitem)
.exec(function (err, foundInvoiceitem){
if (err) return cb(err);
if (foundInvoiceitem.lastStripeEvent > invoiceitem.lastStripeEvent) return cb(null, foundInvoiceitem);
if (foundInvoiceitem.lastStripeEvent == invoiceitem.lastStripeEvent) return Invoiceitem.afterStripeInvoiceitemUpdated(foundInvoiceitem, function(err, invoiceitem){ return cb(err, invoiceitem)});
Invoiceitem.update(foundInvoiceitem.id, invoiceitem)
.exec(function(err, updatedInvoiceitem){
if (err) return cb(err);
if (!updatedInvoiceitem) return cb(null,null);
Invoiceitem.afterStripeInvoiceitemUpdated(updatedInvoiceitem[0], function(err, invoiceitem){
cb(err, invoiceitem);
});
});
});
}
|
javascript
|
function (invoiceitem, cb) {
Invoiceitem.findOrCreate(invoiceitem.id, invoiceitem)
.exec(function (err, foundInvoiceitem){
if (err) return cb(err);
if (foundInvoiceitem.lastStripeEvent > invoiceitem.lastStripeEvent) return cb(null, foundInvoiceitem);
if (foundInvoiceitem.lastStripeEvent == invoiceitem.lastStripeEvent) return Invoiceitem.afterStripeInvoiceitemUpdated(foundInvoiceitem, function(err, invoiceitem){ return cb(err, invoiceitem)});
Invoiceitem.update(foundInvoiceitem.id, invoiceitem)
.exec(function(err, updatedInvoiceitem){
if (err) return cb(err);
if (!updatedInvoiceitem) return cb(null,null);
Invoiceitem.afterStripeInvoiceitemUpdated(updatedInvoiceitem[0], function(err, invoiceitem){
cb(err, invoiceitem);
});
});
});
}
|
[
"function",
"(",
"invoiceitem",
",",
"cb",
")",
"{",
"Invoiceitem",
".",
"findOrCreate",
"(",
"invoiceitem",
".",
"id",
",",
"invoiceitem",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundInvoiceitem",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"foundInvoiceitem",
".",
"lastStripeEvent",
">",
"invoiceitem",
".",
"lastStripeEvent",
")",
"return",
"cb",
"(",
"null",
",",
"foundInvoiceitem",
")",
";",
"if",
"(",
"foundInvoiceitem",
".",
"lastStripeEvent",
"==",
"invoiceitem",
".",
"lastStripeEvent",
")",
"return",
"Invoiceitem",
".",
"afterStripeInvoiceitemUpdated",
"(",
"foundInvoiceitem",
",",
"function",
"(",
"err",
",",
"invoiceitem",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"invoiceitem",
")",
"}",
")",
";",
"Invoiceitem",
".",
"update",
"(",
"foundInvoiceitem",
".",
"id",
",",
"invoiceitem",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedInvoiceitem",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"updatedInvoiceitem",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Invoiceitem",
".",
"afterStripeInvoiceitemUpdated",
"(",
"updatedInvoiceitem",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"invoiceitem",
")",
"{",
"cb",
"(",
"err",
",",
"invoiceitem",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook invoiceitem.updated
|
[
"Stripe",
"Webhook",
"invoiceitem",
".",
"updated"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Invoiceitem.template.js#L90-L106
|
|
37,850 |
scott-wyatt/sails-stripe
|
templates/Invoiceitem.template.js
|
function (invoiceitem, cb) {
Invoiceitem.destroy(invoiceitem.id)
.exec(function (err, destroyedInvoiceitems){
if (err) return cb(err);
if (!destroyedInvoiceitems) return cb(null, null);
Invoiceitem.afterStripeInvoiceitemDeleted(destroyedInvoiceitems[0], function(err, invoiceitem){
cb(err, invoiceitem);
});
});
}
|
javascript
|
function (invoiceitem, cb) {
Invoiceitem.destroy(invoiceitem.id)
.exec(function (err, destroyedInvoiceitems){
if (err) return cb(err);
if (!destroyedInvoiceitems) return cb(null, null);
Invoiceitem.afterStripeInvoiceitemDeleted(destroyedInvoiceitems[0], function(err, invoiceitem){
cb(err, invoiceitem);
});
});
}
|
[
"function",
"(",
"invoiceitem",
",",
"cb",
")",
"{",
"Invoiceitem",
".",
"destroy",
"(",
"invoiceitem",
".",
"id",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"destroyedInvoiceitems",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"destroyedInvoiceitems",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Invoiceitem",
".",
"afterStripeInvoiceitemDeleted",
"(",
"destroyedInvoiceitems",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"invoiceitem",
")",
"{",
"cb",
"(",
"err",
",",
"invoiceitem",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook invoiceitem.deleted
|
[
"Stripe",
"Webhook",
"invoiceitem",
".",
"deleted"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Invoiceitem.template.js#L114-L124
|
|
37,851 |
om-mani-padme-hum/ezobjects-mysql
|
index.js
|
validateTableConfig
|
function validateTableConfig(obj) {
/** If configuration has missing or invalid 'tableName' configuration, throw error */
if ( typeof obj.tableName !== `string` || !obj.tableName.match(/^[a-z_]+$/) )
throw new Error(`ezobjects.validateTableConfig(): Configuration has missing or invalid 'tableName', must be string containing characters 'a-z_'.`);
validateClassConfig(obj);
}
|
javascript
|
function validateTableConfig(obj) {
/** If configuration has missing or invalid 'tableName' configuration, throw error */
if ( typeof obj.tableName !== `string` || !obj.tableName.match(/^[a-z_]+$/) )
throw new Error(`ezobjects.validateTableConfig(): Configuration has missing or invalid 'tableName', must be string containing characters 'a-z_'.`);
validateClassConfig(obj);
}
|
[
"function",
"validateTableConfig",
"(",
"obj",
")",
"{",
"/** If configuration has missing or invalid 'tableName' configuration, throw error */",
"if",
"(",
"typeof",
"obj",
".",
"tableName",
"!==",
"`",
"`",
"||",
"!",
"obj",
".",
"tableName",
".",
"match",
"(",
"/",
"^[a-z_]+$",
"/",
")",
")",
"throw",
"new",
"Error",
"(",
"`",
"`",
")",
";",
"validateClassConfig",
"(",
"obj",
")",
";",
"}"
] |
Validate configuration for a creating MySQL table based on class configuration
|
[
"Validate",
"configuration",
"for",
"a",
"creating",
"MySQL",
"table",
"based",
"on",
"class",
"configuration"
] |
6c73476af9d2855e7c4d7b56176da3f57f1ae37b
|
https://github.com/om-mani-padme-hum/ezobjects-mysql/blob/6c73476af9d2855e7c4d7b56176da3f57f1ae37b/index.js#L415-L421
|
37,852 |
elb-min-uhh/markdown-elearnjs
|
assets/elearnjs/extensions/quiz/assets/js/quiz.js
|
ev_canvas
|
function ev_canvas(ev) {
if(!root.is('.blocked')) {
if(ev.layerX || ev.layerX == 0) { // Firefox
ev._x = ev.layerX;
ev._y = ev.layerY;
} else if(ev.offsetX || ev.offsetX == 0) { // Opera
ev._x = ev.offsetX;
ev._y = ev.offsetY;
}
// Call the event handler of the tool.
var func = tool[ev.type];
if(func) {
func(ev);
}
}
}
|
javascript
|
function ev_canvas(ev) {
if(!root.is('.blocked')) {
if(ev.layerX || ev.layerX == 0) { // Firefox
ev._x = ev.layerX;
ev._y = ev.layerY;
} else if(ev.offsetX || ev.offsetX == 0) { // Opera
ev._x = ev.offsetX;
ev._y = ev.offsetY;
}
// Call the event handler of the tool.
var func = tool[ev.type];
if(func) {
func(ev);
}
}
}
|
[
"function",
"ev_canvas",
"(",
"ev",
")",
"{",
"if",
"(",
"!",
"root",
".",
"is",
"(",
"'.blocked'",
")",
")",
"{",
"if",
"(",
"ev",
".",
"layerX",
"||",
"ev",
".",
"layerX",
"==",
"0",
")",
"{",
"// Firefox",
"ev",
".",
"_x",
"=",
"ev",
".",
"layerX",
";",
"ev",
".",
"_y",
"=",
"ev",
".",
"layerY",
";",
"}",
"else",
"if",
"(",
"ev",
".",
"offsetX",
"||",
"ev",
".",
"offsetX",
"==",
"0",
")",
"{",
"// Opera",
"ev",
".",
"_x",
"=",
"ev",
".",
"offsetX",
";",
"ev",
".",
"_y",
"=",
"ev",
".",
"offsetY",
";",
"}",
"// Call the event handler of the tool.",
"var",
"func",
"=",
"tool",
"[",
"ev",
".",
"type",
"]",
";",
"if",
"(",
"func",
")",
"{",
"func",
"(",
"ev",
")",
";",
"}",
"}",
"}"
] |
The general-purpose event handler. This function just determines the mouse position relative to the canvas element.
|
[
"The",
"general",
"-",
"purpose",
"event",
"handler",
".",
"This",
"function",
"just",
"determines",
"the",
"mouse",
"position",
"relative",
"to",
"the",
"canvas",
"element",
"."
] |
a09bcc497c3c50dd565b7f440fa1f7b62074d679
|
https://github.com/elb-min-uhh/markdown-elearnjs/blob/a09bcc497c3c50dd565b7f440fa1f7b62074d679/assets/elearnjs/extensions/quiz/assets/js/quiz.js#L2207-L2223
|
37,853 |
scott-wyatt/sails-stripe
|
templates/Coupon.template.js
|
function (coupon, cb) {
Coupon.findOrCreate(coupon.id, coupon)
.exec(function (err, foundCoupon){
if (err) return cb(err);
if (foundCoupon.lastStripeEvent > coupon.lastStripeEvent) return cb(null, foundCoupon);
if (foundCoupon.lastStripeEvent == coupon.lastStripeEvent) return Coupon.afterStripeCouponCreated(foundCoupon, function(err, coupon){ return cb(err, coupon)});
Coupon.update(foundCoupon.id, coupon)
.exec(function(err, updatedCoupons){
if (err) return cb(err);
Coupon.afterStripeCouponCreated(updatedCoupons[0], function(err, coupon){
cb(err, coupon);
});
});
});
}
|
javascript
|
function (coupon, cb) {
Coupon.findOrCreate(coupon.id, coupon)
.exec(function (err, foundCoupon){
if (err) return cb(err);
if (foundCoupon.lastStripeEvent > coupon.lastStripeEvent) return cb(null, foundCoupon);
if (foundCoupon.lastStripeEvent == coupon.lastStripeEvent) return Coupon.afterStripeCouponCreated(foundCoupon, function(err, coupon){ return cb(err, coupon)});
Coupon.update(foundCoupon.id, coupon)
.exec(function(err, updatedCoupons){
if (err) return cb(err);
Coupon.afterStripeCouponCreated(updatedCoupons[0], function(err, coupon){
cb(err, coupon);
});
});
});
}
|
[
"function",
"(",
"coupon",
",",
"cb",
")",
"{",
"Coupon",
".",
"findOrCreate",
"(",
"coupon",
".",
"id",
",",
"coupon",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundCoupon",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"foundCoupon",
".",
"lastStripeEvent",
">",
"coupon",
".",
"lastStripeEvent",
")",
"return",
"cb",
"(",
"null",
",",
"foundCoupon",
")",
";",
"if",
"(",
"foundCoupon",
".",
"lastStripeEvent",
"==",
"coupon",
".",
"lastStripeEvent",
")",
"return",
"Coupon",
".",
"afterStripeCouponCreated",
"(",
"foundCoupon",
",",
"function",
"(",
"err",
",",
"coupon",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"coupon",
")",
"}",
")",
";",
"Coupon",
".",
"update",
"(",
"foundCoupon",
".",
"id",
",",
"coupon",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedCoupons",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"Coupon",
".",
"afterStripeCouponCreated",
"(",
"updatedCoupons",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"coupon",
")",
"{",
"cb",
"(",
"err",
",",
"coupon",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook coupon.created
|
[
"Stripe",
"Webhook",
"coupon",
".",
"created"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Coupon.template.js#L75-L90
|
|
37,854 |
scott-wyatt/sails-stripe
|
templates/Coupon.template.js
|
function (coupon, cb) {
Coupon.destroy(coupon.id)
.exec(function (err, destroyedCoupons){
if (err) return cb(err);
if(!destroyedCoupons) return cb(null, null);
Coupon.afterStripeCouponDeleted(destroyedCoupons[0], function(err, coupon){
cb(null, coupon);
});
});
}
|
javascript
|
function (coupon, cb) {
Coupon.destroy(coupon.id)
.exec(function (err, destroyedCoupons){
if (err) return cb(err);
if(!destroyedCoupons) return cb(null, null);
Coupon.afterStripeCouponDeleted(destroyedCoupons[0], function(err, coupon){
cb(null, coupon);
});
});
}
|
[
"function",
"(",
"coupon",
",",
"cb",
")",
"{",
"Coupon",
".",
"destroy",
"(",
"coupon",
".",
"id",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"destroyedCoupons",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"destroyedCoupons",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Coupon",
".",
"afterStripeCouponDeleted",
"(",
"destroyedCoupons",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"coupon",
")",
"{",
"cb",
"(",
"null",
",",
"coupon",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook coupon.deleted
|
[
"Stripe",
"Webhook",
"coupon",
".",
"deleted"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Coupon.template.js#L98-L108
|
|
37,855 |
scott-wyatt/sails-stripe
|
templates/Stripeaccount.template.js
|
function (account, cb) {
Stripeaccount.findOrCreate(account.id, account)
.exec(function (err, foundAccount){
if (err) return cb(err);
Stripeaccount.update(foundAccount.id, account)
.exec(function(err, updatedAccounts){
if (err) return cb(err);
cb(null, updatedAccounts[0]);
});
});
}
|
javascript
|
function (account, cb) {
Stripeaccount.findOrCreate(account.id, account)
.exec(function (err, foundAccount){
if (err) return cb(err);
Stripeaccount.update(foundAccount.id, account)
.exec(function(err, updatedAccounts){
if (err) return cb(err);
cb(null, updatedAccounts[0]);
});
});
}
|
[
"function",
"(",
"account",
",",
"cb",
")",
"{",
"Stripeaccount",
".",
"findOrCreate",
"(",
"account",
".",
"id",
",",
"account",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundAccount",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"Stripeaccount",
".",
"update",
"(",
"foundAccount",
".",
"id",
",",
"account",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedAccounts",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"cb",
"(",
"null",
",",
"updatedAccounts",
"[",
"0",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook account.updated
|
[
"Stripe",
"Webhook",
"account",
".",
"updated"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Stripeaccount.template.js#L98-L109
|
|
37,856 |
mojaie/kiwiii
|
src/component/tree.js
|
checkboxValues
|
function checkboxValues(selection) {
return selection.select('.body')
.selectAll('input:checked').data().map(d => d.id);
}
|
javascript
|
function checkboxValues(selection) {
return selection.select('.body')
.selectAll('input:checked').data().map(d => d.id);
}
|
[
"function",
"checkboxValues",
"(",
"selection",
")",
"{",
"return",
"selection",
".",
"select",
"(",
"'.body'",
")",
".",
"selectAll",
"(",
"'input:checked'",
")",
".",
"data",
"(",
")",
".",
"map",
"(",
"d",
"=>",
"d",
".",
"id",
")",
";",
"}"
] |
Return an array of ids that are checked
@param {d3.selection} selection - selection of node content
|
[
"Return",
"an",
"array",
"of",
"ids",
"that",
"are",
"checked"
] |
30d75685b1ab388b5f1467c753cacd090971ceba
|
https://github.com/mojaie/kiwiii/blob/30d75685b1ab388b5f1467c753cacd090971ceba/src/component/tree.js#L132-L135
|
37,857 |
xbtsw/makejs
|
lib/make.js
|
addDepsToRequiredTargets
|
function addDepsToRequiredTargets(target, parents){
if (parents.have(target)){
callback(new Error("Circular dependencies detected"));
return;
}
requiredTargets.add(target);
parents.add(target);
for(var deps in makeInst.targets[target].dependsOn.hash){
addDepsToRequiredTargets(deps, parents.clone());
}
}
|
javascript
|
function addDepsToRequiredTargets(target, parents){
if (parents.have(target)){
callback(new Error("Circular dependencies detected"));
return;
}
requiredTargets.add(target);
parents.add(target);
for(var deps in makeInst.targets[target].dependsOn.hash){
addDepsToRequiredTargets(deps, parents.clone());
}
}
|
[
"function",
"addDepsToRequiredTargets",
"(",
"target",
",",
"parents",
")",
"{",
"if",
"(",
"parents",
".",
"have",
"(",
"target",
")",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"\"Circular dependencies detected\"",
")",
")",
";",
"return",
";",
"}",
"requiredTargets",
".",
"add",
"(",
"target",
")",
";",
"parents",
".",
"add",
"(",
"target",
")",
";",
"for",
"(",
"var",
"deps",
"in",
"makeInst",
".",
"targets",
"[",
"target",
"]",
".",
"dependsOn",
".",
"hash",
")",
"{",
"addDepsToRequiredTargets",
"(",
"deps",
",",
"parents",
".",
"clone",
"(",
")",
")",
";",
"}",
"}"
] |
find all the required targets
|
[
"find",
"all",
"the",
"required",
"targets"
] |
f43a52310bb1df625a5bf3ed9ea0b1654d638eb6
|
https://github.com/xbtsw/makejs/blob/f43a52310bb1df625a5bf3ed9ea0b1654d638eb6/lib/make.js#L126-L136
|
37,858 |
jsantell/mock-s3
|
lib/mpu.js
|
MPU
|
function MPU (ops) {
File.call(this, ops);
this._parts = {};
this._bufferParts = [];
this._data.UploadId = makeUploadId();
}
|
javascript
|
function MPU (ops) {
File.call(this, ops);
this._parts = {};
this._bufferParts = [];
this._data.UploadId = makeUploadId();
}
|
[
"function",
"MPU",
"(",
"ops",
")",
"{",
"File",
".",
"call",
"(",
"this",
",",
"ops",
")",
";",
"this",
".",
"_parts",
"=",
"{",
"}",
";",
"this",
".",
"_bufferParts",
"=",
"[",
"]",
";",
"this",
".",
"_data",
".",
"UploadId",
"=",
"makeUploadId",
"(",
")",
";",
"}"
] |
Creates a new file for mock-s3.
@class
|
[
"Creates",
"a",
"new",
"file",
"for",
"mock",
"-",
"s3",
"."
] |
d02e3b0558cc60c7887232b69df41e2b0fe09147
|
https://github.com/jsantell/mock-s3/blob/d02e3b0558cc60c7887232b69df41e2b0fe09147/lib/mpu.js#L10-L15
|
37,859 |
jamiebuilds/backbone.storage
|
dist/backbone.storage.js
|
find
|
function find(model) {
var _this = this;
var forceFetch = arguments[1] === undefined ? false : arguments[1];
var record = this.records.get(model);
if (record && !forceFetch) {
return Promise.resolve(record);
} else {
model = this._ensureModel(model);
return Promise.resolve(model.fetch()).then(function () {
return _this.insert(model);
});
}
}
|
javascript
|
function find(model) {
var _this = this;
var forceFetch = arguments[1] === undefined ? false : arguments[1];
var record = this.records.get(model);
if (record && !forceFetch) {
return Promise.resolve(record);
} else {
model = this._ensureModel(model);
return Promise.resolve(model.fetch()).then(function () {
return _this.insert(model);
});
}
}
|
[
"function",
"find",
"(",
"model",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"forceFetch",
"=",
"arguments",
"[",
"1",
"]",
"===",
"undefined",
"?",
"false",
":",
"arguments",
"[",
"1",
"]",
";",
"var",
"record",
"=",
"this",
".",
"records",
".",
"get",
"(",
"model",
")",
";",
"if",
"(",
"record",
"&&",
"!",
"forceFetch",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"record",
")",
";",
"}",
"else",
"{",
"model",
"=",
"this",
".",
"_ensureModel",
"(",
"model",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
"model",
".",
"fetch",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"_this",
".",
"insert",
"(",
"model",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Find a specific model from the store or fetch it from the server and insert
it into the store.
@public
@instance
@method find
@memberOf Storage
@param {Number|String|Object|Backbone.Model} model - The model to find.
@param {Boolean} forceFetch - Force fetch model from server.
@returns {Promise} - A promise that will resolve to the model.
|
[
"Find",
"a",
"specific",
"model",
"from",
"the",
"store",
"or",
"fetch",
"it",
"from",
"the",
"server",
"and",
"insert",
"it",
"into",
"the",
"store",
"."
] |
db8169a07b54f30baa4a8c3963c8cbefe2dd47c9
|
https://github.com/jamiebuilds/backbone.storage/blob/db8169a07b54f30baa4a8c3963c8cbefe2dd47c9/dist/backbone.storage.js#L45-L58
|
37,860 |
jamiebuilds/backbone.storage
|
dist/backbone.storage.js
|
findAll
|
function findAll() {
var _this = this;
var options = arguments[0] === undefined ? {} : arguments[0];
var forceFetch = arguments[1] === undefined ? false : arguments[1];
if (this._hasSynced && !forceFetch) {
return Promise.resolve(this.records);
} else {
return Promise.resolve(this.records.fetch(options)).then(function () {
return _this.records;
});
}
}
|
javascript
|
function findAll() {
var _this = this;
var options = arguments[0] === undefined ? {} : arguments[0];
var forceFetch = arguments[1] === undefined ? false : arguments[1];
if (this._hasSynced && !forceFetch) {
return Promise.resolve(this.records);
} else {
return Promise.resolve(this.records.fetch(options)).then(function () {
return _this.records;
});
}
}
|
[
"function",
"findAll",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"options",
"=",
"arguments",
"[",
"0",
"]",
"===",
"undefined",
"?",
"{",
"}",
":",
"arguments",
"[",
"0",
"]",
";",
"var",
"forceFetch",
"=",
"arguments",
"[",
"1",
"]",
"===",
"undefined",
"?",
"false",
":",
"arguments",
"[",
"1",
"]",
";",
"if",
"(",
"this",
".",
"_hasSynced",
"&&",
"!",
"forceFetch",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"this",
".",
"records",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"this",
".",
"records",
".",
"fetch",
"(",
"options",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"_this",
".",
"records",
";",
"}",
")",
";",
"}",
"}"
] |
Find all the models in the store or fetch them from the server if they
haven't been fetched before.
@public
@instance
@method findAll
@memberOf Storage
@param {Object} options - Options to pass to collection fetch. Also allows
setting parameters on collection.
@param {Boolean} forceFetch - Force fetch model from server.
@returns {Promise} - A promise that will resolve to the entire collection.
|
[
"Find",
"all",
"the",
"models",
"in",
"the",
"store",
"or",
"fetch",
"them",
"from",
"the",
"server",
"if",
"they",
"haven",
"t",
"been",
"fetched",
"before",
"."
] |
db8169a07b54f30baa4a8c3963c8cbefe2dd47c9
|
https://github.com/jamiebuilds/backbone.storage/blob/db8169a07b54f30baa4a8c3963c8cbefe2dd47c9/dist/backbone.storage.js#L73-L84
|
37,861 |
jamiebuilds/backbone.storage
|
dist/backbone.storage.js
|
save
|
function save(model) {
var _this = this;
var record = this.records.get(model);
model = record || this._ensureModel(model);
return Promise.resolve(model.save()).then(function () {
if (!record) {
_this.insert(model);
}
return model;
});
}
|
javascript
|
function save(model) {
var _this = this;
var record = this.records.get(model);
model = record || this._ensureModel(model);
return Promise.resolve(model.save()).then(function () {
if (!record) {
_this.insert(model);
}
return model;
});
}
|
[
"function",
"save",
"(",
"model",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"var",
"record",
"=",
"this",
".",
"records",
".",
"get",
"(",
"model",
")",
";",
"model",
"=",
"record",
"||",
"this",
".",
"_ensureModel",
"(",
"model",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
"model",
".",
"save",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"record",
")",
"{",
"_this",
".",
"insert",
"(",
"model",
")",
";",
"}",
"return",
"model",
";",
"}",
")",
";",
"}"
] |
Save a model to the server.
@public
@instance
@method save
@memberOf Storage
@param {Number|String|Object|Backbone.Model} model - The model to save
@returns {Promise} - A promise that will resolve to the saved model.
|
[
"Save",
"a",
"model",
"to",
"the",
"server",
"."
] |
db8169a07b54f30baa4a8c3963c8cbefe2dd47c9
|
https://github.com/jamiebuilds/backbone.storage/blob/db8169a07b54f30baa4a8c3963c8cbefe2dd47c9/dist/backbone.storage.js#L96-L106
|
37,862 |
jamiebuilds/backbone.storage
|
dist/backbone.storage.js
|
insert
|
function insert(model) {
model = this.records.add(model, { merge: true });
return Promise.resolve(model);
}
|
javascript
|
function insert(model) {
model = this.records.add(model, { merge: true });
return Promise.resolve(model);
}
|
[
"function",
"insert",
"(",
"model",
")",
"{",
"model",
"=",
"this",
".",
"records",
".",
"add",
"(",
"model",
",",
"{",
"merge",
":",
"true",
"}",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
"model",
")",
";",
"}"
] |
Insert a model into the store.
@public
@instance
@method insert
@memberOf Storage
@params {Object|Backbone.Model} - The model to add.
@returns {Promise} - A promise that will resolve to the added model.
|
[
"Insert",
"a",
"model",
"into",
"the",
"store",
"."
] |
db8169a07b54f30baa4a8c3963c8cbefe2dd47c9
|
https://github.com/jamiebuilds/backbone.storage/blob/db8169a07b54f30baa4a8c3963c8cbefe2dd47c9/dist/backbone.storage.js#L118-L121
|
37,863 |
jamiebuilds/backbone.storage
|
dist/backbone.storage.js
|
_ensureModel
|
function _ensureModel(model) {
if (model instanceof this.model) {
return model;
} else if (typeof model === "object") {
return new this.model(model);
} else {
return new this.model({ id: model });
}
}
|
javascript
|
function _ensureModel(model) {
if (model instanceof this.model) {
return model;
} else if (typeof model === "object") {
return new this.model(model);
} else {
return new this.model({ id: model });
}
}
|
[
"function",
"_ensureModel",
"(",
"model",
")",
"{",
"if",
"(",
"model",
"instanceof",
"this",
".",
"model",
")",
"{",
"return",
"model",
";",
"}",
"else",
"if",
"(",
"typeof",
"model",
"===",
"\"object\"",
")",
"{",
"return",
"new",
"this",
".",
"model",
"(",
"model",
")",
";",
"}",
"else",
"{",
"return",
"new",
"this",
".",
"model",
"(",
"{",
"id",
":",
"model",
"}",
")",
";",
"}",
"}"
] |
Ensure that we have a real model from an id, object, or model.
@private
@instance
@method _ensureModel
@memberOf Storage
@params {Number|String|Object|Backbone.Model} - An id, object, or model.
@returns {Backbone.Model} - The model.
|
[
"Ensure",
"that",
"we",
"have",
"a",
"real",
"model",
"from",
"an",
"id",
"object",
"or",
"model",
"."
] |
db8169a07b54f30baa4a8c3963c8cbefe2dd47c9
|
https://github.com/jamiebuilds/backbone.storage/blob/db8169a07b54f30baa4a8c3963c8cbefe2dd47c9/dist/backbone.storage.js#L133-L141
|
37,864 |
impromptu/impromptu
|
lib/Prompt.js
|
function(input, callback) {
// Handle non-function `input`.
if (!_.isFunction(input)) {
callback(null, input)
return
}
// Handle asynchronous `input` function.
if (input.length) {
input(callback)
return
}
// Handle synchronous `input` function.
var results = null
var err = null
try {
results = input()
} catch (e) {
err = e
}
callback(err, results)
}
|
javascript
|
function(input, callback) {
// Handle non-function `input`.
if (!_.isFunction(input)) {
callback(null, input)
return
}
// Handle asynchronous `input` function.
if (input.length) {
input(callback)
return
}
// Handle synchronous `input` function.
var results = null
var err = null
try {
results = input()
} catch (e) {
err = e
}
callback(err, results)
}
|
[
"function",
"(",
"input",
",",
"callback",
")",
"{",
"// Handle non-function `input`.",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"input",
")",
")",
"{",
"callback",
"(",
"null",
",",
"input",
")",
"return",
"}",
"// Handle asynchronous `input` function.",
"if",
"(",
"input",
".",
"length",
")",
"{",
"input",
"(",
"callback",
")",
"return",
"}",
"// Handle synchronous `input` function.",
"var",
"results",
"=",
"null",
"var",
"err",
"=",
"null",
"try",
"{",
"results",
"=",
"input",
"(",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"err",
"=",
"e",
"}",
"callback",
"(",
"err",
",",
"results",
")",
"}"
] |
Allows any input to be treated asynchronously.
|
[
"Allows",
"any",
"input",
"to",
"be",
"treated",
"asynchronously",
"."
] |
829798eda62771d6a6ed971d87eef7a461932704
|
https://github.com/impromptu/impromptu/blob/829798eda62771d6a6ed971d87eef7a461932704/lib/Prompt.js#L21-L44
|
|
37,865 |
XOP/sass-vars-to-js
|
src/index.js
|
sassVars
|
function sassVars (filePath) {
const declarations = collectDeclarations(filePath);
let variables = {};
if (!declarations.length) {
message('Warning: Zero declarations found');
return;
}
declarations.forEach(function (declaration) {
const parsedDeclaration = parseDeclaration(declaration);
const varName = parsedDeclaration.key;
let varValue = parsedDeclaration.value;
const valueType = getValueType(varValue);
/*
* $key: $value;
*/
if (valueType === 'var') {
const localVarName = varValue;
varValue = getVarValue(localVarName, variables);
if (!varValue) {
message(`Warning: Null value for variable ${localVarName}`);
}
}
/*
* $key: ($value-1 + $value-2) * $value-3 ... ;
*/
if (valueType === 'expression') {
// todo
}
/*
* $key: value;
*/
variables[varName] = varValue;
});
return variables;
}
|
javascript
|
function sassVars (filePath) {
const declarations = collectDeclarations(filePath);
let variables = {};
if (!declarations.length) {
message('Warning: Zero declarations found');
return;
}
declarations.forEach(function (declaration) {
const parsedDeclaration = parseDeclaration(declaration);
const varName = parsedDeclaration.key;
let varValue = parsedDeclaration.value;
const valueType = getValueType(varValue);
/*
* $key: $value;
*/
if (valueType === 'var') {
const localVarName = varValue;
varValue = getVarValue(localVarName, variables);
if (!varValue) {
message(`Warning: Null value for variable ${localVarName}`);
}
}
/*
* $key: ($value-1 + $value-2) * $value-3 ... ;
*/
if (valueType === 'expression') {
// todo
}
/*
* $key: value;
*/
variables[varName] = varValue;
});
return variables;
}
|
[
"function",
"sassVars",
"(",
"filePath",
")",
"{",
"const",
"declarations",
"=",
"collectDeclarations",
"(",
"filePath",
")",
";",
"let",
"variables",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"declarations",
".",
"length",
")",
"{",
"message",
"(",
"'Warning: Zero declarations found'",
")",
";",
"return",
";",
"}",
"declarations",
".",
"forEach",
"(",
"function",
"(",
"declaration",
")",
"{",
"const",
"parsedDeclaration",
"=",
"parseDeclaration",
"(",
"declaration",
")",
";",
"const",
"varName",
"=",
"parsedDeclaration",
".",
"key",
";",
"let",
"varValue",
"=",
"parsedDeclaration",
".",
"value",
";",
"const",
"valueType",
"=",
"getValueType",
"(",
"varValue",
")",
";",
"/*\n * $key: $value;\n */",
"if",
"(",
"valueType",
"===",
"'var'",
")",
"{",
"const",
"localVarName",
"=",
"varValue",
";",
"varValue",
"=",
"getVarValue",
"(",
"localVarName",
",",
"variables",
")",
";",
"if",
"(",
"!",
"varValue",
")",
"{",
"message",
"(",
"`",
"${",
"localVarName",
"}",
"`",
")",
";",
"}",
"}",
"/*\n * $key: ($value-1 + $value-2) * $value-3 ... ;\n */",
"if",
"(",
"valueType",
"===",
"'expression'",
")",
"{",
"// todo",
"}",
"/*\n * $key: value;\n */",
"variables",
"[",
"varName",
"]",
"=",
"varValue",
";",
"}",
")",
";",
"return",
"variables",
";",
"}"
] |
Takes file.scss as an argument
Returns parsed variables hash-map
@param filePath
@returns {{}}
|
[
"Takes",
"file",
".",
"scss",
"as",
"an",
"argument",
"Returns",
"parsed",
"variables",
"hash",
"-",
"map"
] |
87ad8588701a9c2e69ace75931947d11698f25f0
|
https://github.com/XOP/sass-vars-to-js/blob/87ad8588701a9c2e69ace75931947d11698f25f0/src/index.js#L13-L54
|
37,866 |
fnogatz/node-swtparser
|
lib/from-data-view.js
|
getOrderedPlayers
|
function getOrderedPlayers (tnmt) {
var res = []
for (var i = 0; i < tnmt.players.length; i++) {
res[tnmt.players[i].positionInSWT] = tnmt.players[i]['2020']
}
return res
}
|
javascript
|
function getOrderedPlayers (tnmt) {
var res = []
for (var i = 0; i < tnmt.players.length; i++) {
res[tnmt.players[i].positionInSWT] = tnmt.players[i]['2020']
}
return res
}
|
[
"function",
"getOrderedPlayers",
"(",
"tnmt",
")",
"{",
"var",
"res",
"=",
"[",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tnmt",
".",
"players",
".",
"length",
";",
"i",
"++",
")",
"{",
"res",
"[",
"tnmt",
".",
"players",
"[",
"i",
"]",
".",
"positionInSWT",
"]",
"=",
"tnmt",
".",
"players",
"[",
"i",
"]",
"[",
"'2020'",
"]",
"}",
"return",
"res",
"}"
] |
Takes a tournament and returns the players in order of
their occurences within the SWT.
@param {Object} tournament object after parsing process
@return {Array} of players
|
[
"Takes",
"a",
"tournament",
"and",
"returns",
"the",
"players",
"in",
"order",
"of",
"their",
"occurences",
"within",
"the",
"SWT",
"."
] |
4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3
|
https://github.com/fnogatz/node-swtparser/blob/4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3/lib/from-data-view.js#L261-L267
|
37,867 |
fnogatz/node-swtparser
|
lib/from-data-view.js
|
getOrderedTeams
|
function getOrderedTeams (tnmt) {
var res = []
for (var i = 0; i < tnmt.teams.length; i++) {
res[tnmt.teams[i].positionInSWT] = tnmt.teams[i]['1018']
}
return res
}
|
javascript
|
function getOrderedTeams (tnmt) {
var res = []
for (var i = 0; i < tnmt.teams.length; i++) {
res[tnmt.teams[i].positionInSWT] = tnmt.teams[i]['1018']
}
return res
}
|
[
"function",
"getOrderedTeams",
"(",
"tnmt",
")",
"{",
"var",
"res",
"=",
"[",
"]",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tnmt",
".",
"teams",
".",
"length",
";",
"i",
"++",
")",
"{",
"res",
"[",
"tnmt",
".",
"teams",
"[",
"i",
"]",
".",
"positionInSWT",
"]",
"=",
"tnmt",
".",
"teams",
"[",
"i",
"]",
"[",
"'1018'",
"]",
"}",
"return",
"res",
"}"
] |
Takes a tournament and returns the teams in order of
their occurences within the SWT.
@param {Object} tournament object after parsing process
@return {Array} of teams
|
[
"Takes",
"a",
"tournament",
"and",
"returns",
"the",
"teams",
"in",
"order",
"of",
"their",
"occurences",
"within",
"the",
"SWT",
"."
] |
4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3
|
https://github.com/fnogatz/node-swtparser/blob/4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3/lib/from-data-view.js#L276-L282
|
37,868 |
fnogatz/node-swtparser
|
lib/from-data-view.js
|
playerPairingFilter
|
function playerPairingFilter (tnmt) {
return function (pairing) {
// board number too high?
if (tnmt.general[35] && pairing[4006] > tnmt.general[34]) { return false }
// no color set?
if (pairing[4000] === '4000-0') { return false }
return true
}
}
|
javascript
|
function playerPairingFilter (tnmt) {
return function (pairing) {
// board number too high?
if (tnmt.general[35] && pairing[4006] > tnmt.general[34]) { return false }
// no color set?
if (pairing[4000] === '4000-0') { return false }
return true
}
}
|
[
"function",
"playerPairingFilter",
"(",
"tnmt",
")",
"{",
"return",
"function",
"(",
"pairing",
")",
"{",
"// board number too high?",
"if",
"(",
"tnmt",
".",
"general",
"[",
"35",
"]",
"&&",
"pairing",
"[",
"4006",
"]",
">",
"tnmt",
".",
"general",
"[",
"34",
"]",
")",
"{",
"return",
"false",
"}",
"// no color set?",
"if",
"(",
"pairing",
"[",
"4000",
"]",
"===",
"'4000-0'",
")",
"{",
"return",
"false",
"}",
"return",
"true",
"}",
"}"
] |
Filter function to remove dummy player pairings.
@param {Object} pairing
@return {Boolean} true -> valid pairing
|
[
"Filter",
"function",
"to",
"remove",
"dummy",
"player",
"pairings",
"."
] |
4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3
|
https://github.com/fnogatz/node-swtparser/blob/4a109dcfef19ca5ca01fa7b4256ee57a2a3c1dd3/lib/from-data-view.js#L289-L299
|
37,869 |
nwtjs/nwt
|
src/io/js/io.js
|
NWTIO
|
function NWTIO(args) {
this.req = new XMLHttpRequest();
this.config = {};
this.url = args[0];
// Data to send as
this.ioData = '';
var chainableSetters = ['success', 'failure', 'serialize'],
i,
setter,
mythis = this,
// Returns the setter function
getSetter = function (setter) {
return function (value) {
mythis.config[setter] = value;
return this;
}
};
for (i = 0, setter; setter = chainableSetters[i]; i++) {
this[setter] = getSetter(setter);
}
}
|
javascript
|
function NWTIO(args) {
this.req = new XMLHttpRequest();
this.config = {};
this.url = args[0];
// Data to send as
this.ioData = '';
var chainableSetters = ['success', 'failure', 'serialize'],
i,
setter,
mythis = this,
// Returns the setter function
getSetter = function (setter) {
return function (value) {
mythis.config[setter] = value;
return this;
}
};
for (i = 0, setter; setter = chainableSetters[i]; i++) {
this[setter] = getSetter(setter);
}
}
|
[
"function",
"NWTIO",
"(",
"args",
")",
"{",
"this",
".",
"req",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"this",
".",
"config",
"=",
"{",
"}",
";",
"this",
".",
"url",
"=",
"args",
"[",
"0",
"]",
";",
"// Data to send as",
"this",
".",
"ioData",
"=",
"''",
";",
"var",
"chainableSetters",
"=",
"[",
"'success'",
",",
"'failure'",
",",
"'serialize'",
"]",
",",
"i",
",",
"setter",
",",
"mythis",
"=",
"this",
",",
"// Returns the setter function",
"getSetter",
"=",
"function",
"(",
"setter",
")",
"{",
"return",
"function",
"(",
"value",
")",
"{",
"mythis",
".",
"config",
"[",
"setter",
"]",
"=",
"value",
";",
"return",
"this",
";",
"}",
"}",
";",
"for",
"(",
"i",
"=",
"0",
",",
"setter",
";",
"setter",
"=",
"chainableSetters",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"this",
"[",
"setter",
"]",
"=",
"getSetter",
"(",
"setter",
")",
";",
"}",
"}"
] |
Provides ajax communication methods
The folllowing methods are chainable
success - success handler
failure - failure handler
serialize - serialize a form, selector, array, or object to send
@constructor
|
[
"Provides",
"ajax",
"communication",
"methods",
"The",
"folllowing",
"methods",
"are",
"chainable",
"success",
"-",
"success",
"handler",
"failure",
"-",
"failure",
"handler",
"serialize",
"-",
"serialize",
"a",
"form",
"selector",
"array",
"or",
"object",
"to",
"send"
] |
49991293e621846e435992b764265abb13a7346b
|
https://github.com/nwtjs/nwt/blob/49991293e621846e435992b764265abb13a7346b/src/io/js/io.js#L32-L56
|
37,870 |
nwtjs/nwt
|
src/io/js/io.js
|
function() {
var mythis = this;
this.req.onload = function() {
if (mythis.config.success) {
var response = new NWTIOResponse(mythis.req);
mythis.config.success(response);
}
};
this.req.onerror = function() {
if (mythis.config.failure) {
var response = new NWTIOResponse(mythis.req);
mythis.config.failure(response);
}
};
this.req.send(this.ioData ? this.ioData : null);
return this;
}
|
javascript
|
function() {
var mythis = this;
this.req.onload = function() {
if (mythis.config.success) {
var response = new NWTIOResponse(mythis.req);
mythis.config.success(response);
}
};
this.req.onerror = function() {
if (mythis.config.failure) {
var response = new NWTIOResponse(mythis.req);
mythis.config.failure(response);
}
};
this.req.send(this.ioData ? this.ioData : null);
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"mythis",
"=",
"this",
";",
"this",
".",
"req",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"mythis",
".",
"config",
".",
"success",
")",
"{",
"var",
"response",
"=",
"new",
"NWTIOResponse",
"(",
"mythis",
".",
"req",
")",
";",
"mythis",
".",
"config",
".",
"success",
"(",
"response",
")",
";",
"}",
"}",
";",
"this",
".",
"req",
".",
"onerror",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"mythis",
".",
"config",
".",
"failure",
")",
"{",
"var",
"response",
"=",
"new",
"NWTIOResponse",
"(",
"mythis",
".",
"req",
")",
";",
"mythis",
".",
"config",
".",
"failure",
"(",
"response",
")",
";",
"}",
"}",
";",
"this",
".",
"req",
".",
"send",
"(",
"this",
".",
"ioData",
"?",
"this",
".",
"ioData",
":",
"null",
")",
";",
"return",
"this",
";",
"}"
] |
Runs the IO call
@param string Type of call
|
[
"Runs",
"the",
"IO",
"call"
] |
49991293e621846e435992b764265abb13a7346b
|
https://github.com/nwtjs/nwt/blob/49991293e621846e435992b764265abb13a7346b/src/io/js/io.js#L63-L81
|
|
37,871 |
nwtjs/nwt
|
src/io/js/io.js
|
function(data, method) {
var urlencodedForm = true;
if (typeof data == 'string') {
this.ioData = data;
} else if (typeof data == 'object' && data._node) {
if (data.getAttribute('enctype')) {
urlencodedForm = false;
}
this.ioData = new FormData(data._node);
}
var req = this.req,
method = method || 'POST';
req.open(method, this.url);
//Send the proper header information along with the request
// Send as form encoded if we do not have a file field
if (urlencodedForm) {
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
return this._run();
}
|
javascript
|
function(data, method) {
var urlencodedForm = true;
if (typeof data == 'string') {
this.ioData = data;
} else if (typeof data == 'object' && data._node) {
if (data.getAttribute('enctype')) {
urlencodedForm = false;
}
this.ioData = new FormData(data._node);
}
var req = this.req,
method = method || 'POST';
req.open(method, this.url);
//Send the proper header information along with the request
// Send as form encoded if we do not have a file field
if (urlencodedForm) {
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
return this._run();
}
|
[
"function",
"(",
"data",
",",
"method",
")",
"{",
"var",
"urlencodedForm",
"=",
"true",
";",
"if",
"(",
"typeof",
"data",
"==",
"'string'",
")",
"{",
"this",
".",
"ioData",
"=",
"data",
";",
"}",
"else",
"if",
"(",
"typeof",
"data",
"==",
"'object'",
"&&",
"data",
".",
"_node",
")",
"{",
"if",
"(",
"data",
".",
"getAttribute",
"(",
"'enctype'",
")",
")",
"{",
"urlencodedForm",
"=",
"false",
";",
"}",
"this",
".",
"ioData",
"=",
"new",
"FormData",
"(",
"data",
".",
"_node",
")",
";",
"}",
"var",
"req",
"=",
"this",
".",
"req",
",",
"method",
"=",
"method",
"||",
"'POST'",
";",
"req",
".",
"open",
"(",
"method",
",",
"this",
".",
"url",
")",
";",
"//Send the proper header information along with the request",
"// Send as form encoded if we do not have a file field",
"if",
"(",
"urlencodedForm",
")",
"{",
"req",
".",
"setRequestHeader",
"(",
"\"Content-type\"",
",",
"\"application/x-www-form-urlencoded\"",
")",
";",
"}",
"return",
"this",
".",
"_run",
"(",
")",
";",
"}"
] |
Runs IO POST
We also use post for PUT or DELETE requests
|
[
"Runs",
"IO",
"POST",
"We",
"also",
"use",
"post",
"for",
"PUT",
"or",
"DELETE",
"requests"
] |
49991293e621846e435992b764265abb13a7346b
|
https://github.com/nwtjs/nwt/blob/49991293e621846e435992b764265abb13a7346b/src/io/js/io.js#L88-L115
|
|
37,872 |
nwtjs/nwt
|
src/io/js/io.js
|
function(data) {
// Strip out the old query string and append the new one
if (data) {
this.url = this.url.split('?', 1)[0] + '?' + data;
}
this.req.open('GET', this.url);
return this._run();
}
|
javascript
|
function(data) {
// Strip out the old query string and append the new one
if (data) {
this.url = this.url.split('?', 1)[0] + '?' + data;
}
this.req.open('GET', this.url);
return this._run();
}
|
[
"function",
"(",
"data",
")",
"{",
"// Strip out the old query string and append the new one",
"if",
"(",
"data",
")",
"{",
"this",
".",
"url",
"=",
"this",
".",
"url",
".",
"split",
"(",
"'?'",
",",
"1",
")",
"[",
"0",
"]",
"+",
"'?'",
"+",
"data",
";",
"}",
"this",
".",
"req",
".",
"open",
"(",
"'GET'",
",",
"this",
".",
"url",
")",
";",
"return",
"this",
".",
"_run",
"(",
")",
";",
"}"
] |
Runs IO GET
@param string We update the URL if we receive data to GET here
|
[
"Runs",
"IO",
"GET"
] |
49991293e621846e435992b764265abb13a7346b
|
https://github.com/nwtjs/nwt/blob/49991293e621846e435992b764265abb13a7346b/src/io/js/io.js#L122-L131
|
|
37,873 |
cludden/mycro
|
hooks/models.js
|
function(fn) {
asyncjs.each(modelNames, function(name, _fn) {
// get model definition
var modelDefinition = modelDefinitions[name];
modelDefinition.__name = name;
// get connection info
var connectionInfo = lib.findConnection(mycro, name);
if (!connectionInfo) {
mycro.log('silly', '[models] Unable to find explicit adapter for model (' + name + ')');
if (!defaultConnection ) {
return _fn('Unable to find adapter for model (' + name + ')');
} else {
connectionInfo = defaultConnection;
}
}
// validate handler exists
var adapter = connectionInfo.adapter;
if (!adapter.registerModel || !_.isFunction(adapter.registerModel) || adapter.registerModel.length < 3) {
return _fn('Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback');
}
// hand off to adapter
var registerModelCallback = function(err, model) {
if (err) {
return _fn(err);
}
if (!model) {
return _fn('No model (' + name + ') returned from `adapter.registerModel`');
}
mycro.models[name] = model;
_fn();
};
if (adapter.registerModel.length === 3) {
return adapter.registerModel(connectionInfo.connection, modelDefinition, registerModelCallback);
} else if (adapter.registerModel.length === 4) {
return adapter.registerModel(connectionInfo.connection, modelDefinition, name, registerModelCallback);
} else {
return adapter.registerModel(connectionInfo.connection, modelDefinition, name, mycro, registerModelCallback);
}
}, fn);
}
|
javascript
|
function(fn) {
asyncjs.each(modelNames, function(name, _fn) {
// get model definition
var modelDefinition = modelDefinitions[name];
modelDefinition.__name = name;
// get connection info
var connectionInfo = lib.findConnection(mycro, name);
if (!connectionInfo) {
mycro.log('silly', '[models] Unable to find explicit adapter for model (' + name + ')');
if (!defaultConnection ) {
return _fn('Unable to find adapter for model (' + name + ')');
} else {
connectionInfo = defaultConnection;
}
}
// validate handler exists
var adapter = connectionInfo.adapter;
if (!adapter.registerModel || !_.isFunction(adapter.registerModel) || adapter.registerModel.length < 3) {
return _fn('Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback');
}
// hand off to adapter
var registerModelCallback = function(err, model) {
if (err) {
return _fn(err);
}
if (!model) {
return _fn('No model (' + name + ') returned from `adapter.registerModel`');
}
mycro.models[name] = model;
_fn();
};
if (adapter.registerModel.length === 3) {
return adapter.registerModel(connectionInfo.connection, modelDefinition, registerModelCallback);
} else if (adapter.registerModel.length === 4) {
return adapter.registerModel(connectionInfo.connection, modelDefinition, name, registerModelCallback);
} else {
return adapter.registerModel(connectionInfo.connection, modelDefinition, name, mycro, registerModelCallback);
}
}, fn);
}
|
[
"function",
"(",
"fn",
")",
"{",
"asyncjs",
".",
"each",
"(",
"modelNames",
",",
"function",
"(",
"name",
",",
"_fn",
")",
"{",
"// get model definition",
"var",
"modelDefinition",
"=",
"modelDefinitions",
"[",
"name",
"]",
";",
"modelDefinition",
".",
"__name",
"=",
"name",
";",
"// get connection info",
"var",
"connectionInfo",
"=",
"lib",
".",
"findConnection",
"(",
"mycro",
",",
"name",
")",
";",
"if",
"(",
"!",
"connectionInfo",
")",
"{",
"mycro",
".",
"log",
"(",
"'silly'",
",",
"'[models] Unable to find explicit adapter for model ('",
"+",
"name",
"+",
"')'",
")",
";",
"if",
"(",
"!",
"defaultConnection",
")",
"{",
"return",
"_fn",
"(",
"'Unable to find adapter for model ('",
"+",
"name",
"+",
"')'",
")",
";",
"}",
"else",
"{",
"connectionInfo",
"=",
"defaultConnection",
";",
"}",
"}",
"// validate handler exists",
"var",
"adapter",
"=",
"connectionInfo",
".",
"adapter",
";",
"if",
"(",
"!",
"adapter",
".",
"registerModel",
"||",
"!",
"_",
".",
"isFunction",
"(",
"adapter",
".",
"registerModel",
")",
"||",
"adapter",
".",
"registerModel",
".",
"length",
"<",
"3",
")",
"{",
"return",
"_fn",
"(",
"'Invalid adapter api: adapters should define a `registerModel` method that accepts a connection object, model definition object, and a callback'",
")",
";",
"}",
"// hand off to adapter",
"var",
"registerModelCallback",
"=",
"function",
"(",
"err",
",",
"model",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"_fn",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"model",
")",
"{",
"return",
"_fn",
"(",
"'No model ('",
"+",
"name",
"+",
"') returned from `adapter.registerModel`'",
")",
";",
"}",
"mycro",
".",
"models",
"[",
"name",
"]",
"=",
"model",
";",
"_fn",
"(",
")",
";",
"}",
";",
"if",
"(",
"adapter",
".",
"registerModel",
".",
"length",
"===",
"3",
")",
"{",
"return",
"adapter",
".",
"registerModel",
"(",
"connectionInfo",
".",
"connection",
",",
"modelDefinition",
",",
"registerModelCallback",
")",
";",
"}",
"else",
"if",
"(",
"adapter",
".",
"registerModel",
".",
"length",
"===",
"4",
")",
"{",
"return",
"adapter",
".",
"registerModel",
"(",
"connectionInfo",
".",
"connection",
",",
"modelDefinition",
",",
"name",
",",
"registerModelCallback",
")",
";",
"}",
"else",
"{",
"return",
"adapter",
".",
"registerModel",
"(",
"connectionInfo",
".",
"connection",
",",
"modelDefinition",
",",
"name",
",",
"mycro",
",",
"registerModelCallback",
")",
";",
"}",
"}",
",",
"fn",
")",
";",
"}"
] |
hand model definitions to the appropriate adapter for construction
|
[
"hand",
"model",
"definitions",
"to",
"the",
"appropriate",
"adapter",
"for",
"construction"
] |
762e6ba0f38f37497eefb933252edc2c16bfb40b
|
https://github.com/cludden/mycro/blob/762e6ba0f38f37497eefb933252edc2c16bfb40b/hooks/models.js#L33-L75
|
|
37,874 |
cludden/mycro
|
hooks/models.js
|
function(err, model) {
if (err) {
return _fn(err);
}
if (!model) {
return _fn('No model (' + name + ') returned from `adapter.registerModel`');
}
mycro.models[name] = model;
_fn();
}
|
javascript
|
function(err, model) {
if (err) {
return _fn(err);
}
if (!model) {
return _fn('No model (' + name + ') returned from `adapter.registerModel`');
}
mycro.models[name] = model;
_fn();
}
|
[
"function",
"(",
"err",
",",
"model",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"_fn",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"model",
")",
"{",
"return",
"_fn",
"(",
"'No model ('",
"+",
"name",
"+",
"') returned from `adapter.registerModel`'",
")",
";",
"}",
"mycro",
".",
"models",
"[",
"name",
"]",
"=",
"model",
";",
"_fn",
"(",
")",
";",
"}"
] |
hand off to adapter
|
[
"hand",
"off",
"to",
"adapter"
] |
762e6ba0f38f37497eefb933252edc2c16bfb40b
|
https://github.com/cludden/mycro/blob/762e6ba0f38f37497eefb933252edc2c16bfb40b/hooks/models.js#L57-L66
|
|
37,875 |
scienceai/graph-rdfa-processor
|
src/rdfa-processor.js
|
function(baseURI) {
var hash = baseURI.indexOf("#");
if (hash>=0) {
baseURI = baseURI.substring(0,hash);
}
if (options && options.baseURIMap) {
baseURI = options.baseURIMap(baseURI);
}
return baseURI;
}
|
javascript
|
function(baseURI) {
var hash = baseURI.indexOf("#");
if (hash>=0) {
baseURI = baseURI.substring(0,hash);
}
if (options && options.baseURIMap) {
baseURI = options.baseURIMap(baseURI);
}
return baseURI;
}
|
[
"function",
"(",
"baseURI",
")",
"{",
"var",
"hash",
"=",
"baseURI",
".",
"indexOf",
"(",
"\"#\"",
")",
";",
"if",
"(",
"hash",
">=",
"0",
")",
"{",
"baseURI",
"=",
"baseURI",
".",
"substring",
"(",
"0",
",",
"hash",
")",
";",
"}",
"if",
"(",
"options",
"&&",
"options",
".",
"baseURIMap",
")",
"{",
"baseURI",
"=",
"options",
".",
"baseURIMap",
"(",
"baseURI",
")",
";",
"}",
"return",
"baseURI",
";",
"}"
] |
Fix for Firefox that includes the hash in the base URI
|
[
"Fix",
"for",
"Firefox",
"that",
"includes",
"the",
"hash",
"in",
"the",
"base",
"URI"
] |
39e00b3d498b2081524843717b287dfaa946c261
|
https://github.com/scienceai/graph-rdfa-processor/blob/39e00b3d498b2081524843717b287dfaa946c261/src/rdfa-processor.js#L289-L298
|
|
37,876 |
scott-wyatt/sails-stripe
|
templates/Subscription.template.js
|
function (subscription, cb) {
Subscription.findOrCreate(subscription.id, subscription)
.exec(function (err, foundSubscription){
if (err) return cb(err);
if (foundSubscription.lastStripeEvent > subscription.lastStripeEvent) return cb(null, foundSubscription);
if (foundSubscription.lastStripeEvent == subscription.lastStripeEvent) return Subscription.afterStripeCustomerSubscriptionUpdated(foundSubscription, function(err, subscription){ return cb(err, subscription)});
Subscription.update(foundSubscription.id, subscription)
.exec(function(err, updatedSubscriptions){
if (err) return cb(err);
if(!updatedSubscriptions) return cb(null, null);
Subscription.afterStripeCustomerSubscriptionUpdated(updatedSubscriptions[0], function(err, subscription){
cb(err, subscription);
});
});
});
}
|
javascript
|
function (subscription, cb) {
Subscription.findOrCreate(subscription.id, subscription)
.exec(function (err, foundSubscription){
if (err) return cb(err);
if (foundSubscription.lastStripeEvent > subscription.lastStripeEvent) return cb(null, foundSubscription);
if (foundSubscription.lastStripeEvent == subscription.lastStripeEvent) return Subscription.afterStripeCustomerSubscriptionUpdated(foundSubscription, function(err, subscription){ return cb(err, subscription)});
Subscription.update(foundSubscription.id, subscription)
.exec(function(err, updatedSubscriptions){
if (err) return cb(err);
if(!updatedSubscriptions) return cb(null, null);
Subscription.afterStripeCustomerSubscriptionUpdated(updatedSubscriptions[0], function(err, subscription){
cb(err, subscription);
});
});
});
}
|
[
"function",
"(",
"subscription",
",",
"cb",
")",
"{",
"Subscription",
".",
"findOrCreate",
"(",
"subscription",
".",
"id",
",",
"subscription",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundSubscription",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"foundSubscription",
".",
"lastStripeEvent",
">",
"subscription",
".",
"lastStripeEvent",
")",
"return",
"cb",
"(",
"null",
",",
"foundSubscription",
")",
";",
"if",
"(",
"foundSubscription",
".",
"lastStripeEvent",
"==",
"subscription",
".",
"lastStripeEvent",
")",
"return",
"Subscription",
".",
"afterStripeCustomerSubscriptionUpdated",
"(",
"foundSubscription",
",",
"function",
"(",
"err",
",",
"subscription",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"subscription",
")",
"}",
")",
";",
"Subscription",
".",
"update",
"(",
"foundSubscription",
".",
"id",
",",
"subscription",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedSubscriptions",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"updatedSubscriptions",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Subscription",
".",
"afterStripeCustomerSubscriptionUpdated",
"(",
"updatedSubscriptions",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"subscription",
")",
"{",
"cb",
"(",
"err",
",",
"subscription",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook customer.subscription.updated
|
[
"Stripe",
"Webhook",
"customer",
".",
"subscription",
".",
"updated"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Subscription.template.js#L126-L142
|
|
37,877 |
scott-wyatt/sails-stripe
|
templates/Subscription.template.js
|
function (subscription, cb) {
Subscription.destroy(subscription.id)
.exec(function (err, destroyedSubscriptions){
if (err) return cb(err);
if (!destroyedSubscriptions) return cb(null, subscription);
Subscription.afterStripeCustomerSubscriptionDeleted(destroyedSubscriptions[0], function(err, subscription){
cb(err, subscription);
});
});
}
|
javascript
|
function (subscription, cb) {
Subscription.destroy(subscription.id)
.exec(function (err, destroyedSubscriptions){
if (err) return cb(err);
if (!destroyedSubscriptions) return cb(null, subscription);
Subscription.afterStripeCustomerSubscriptionDeleted(destroyedSubscriptions[0], function(err, subscription){
cb(err, subscription);
});
});
}
|
[
"function",
"(",
"subscription",
",",
"cb",
")",
"{",
"Subscription",
".",
"destroy",
"(",
"subscription",
".",
"id",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"destroyedSubscriptions",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"destroyedSubscriptions",
")",
"return",
"cb",
"(",
"null",
",",
"subscription",
")",
";",
"Subscription",
".",
"afterStripeCustomerSubscriptionDeleted",
"(",
"destroyedSubscriptions",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"subscription",
")",
"{",
"cb",
"(",
"err",
",",
"subscription",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook customer.subscription.deleted
|
[
"Stripe",
"Webhook",
"customer",
".",
"subscription",
".",
"deleted"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Subscription.template.js#L150-L160
|
|
37,878 |
ChrisWren/mdlint
|
index.js
|
fetchRepoREADME
|
function fetchRepoREADME (repo) {
request({
uri: 'https://api.github.com/repos/' + repo + '/readme',
headers: _.extend(headers, {
// Get raw README content
'Accept': 'application/vnd.github.VERSION.raw'
})
},
function (error, response, body) {
if (!error && response.statusCode === 200) {
lintMarkdown(body, repo);
} else {
if (response.headers['x-ratelimit-remaining'] === '0') {
getAuthToken();
} else {
console.log('README for https://github.com/' + repo.blue + ' not found.'.red);
return;
}
}
});
}
|
javascript
|
function fetchRepoREADME (repo) {
request({
uri: 'https://api.github.com/repos/' + repo + '/readme',
headers: _.extend(headers, {
// Get raw README content
'Accept': 'application/vnd.github.VERSION.raw'
})
},
function (error, response, body) {
if (!error && response.statusCode === 200) {
lintMarkdown(body, repo);
} else {
if (response.headers['x-ratelimit-remaining'] === '0') {
getAuthToken();
} else {
console.log('README for https://github.com/' + repo.blue + ' not found.'.red);
return;
}
}
});
}
|
[
"function",
"fetchRepoREADME",
"(",
"repo",
")",
"{",
"request",
"(",
"{",
"uri",
":",
"'https://api.github.com/repos/'",
"+",
"repo",
"+",
"'/readme'",
",",
"headers",
":",
"_",
".",
"extend",
"(",
"headers",
",",
"{",
"// Get raw README content",
"'Accept'",
":",
"'application/vnd.github.VERSION.raw'",
"}",
")",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"!",
"error",
"&&",
"response",
".",
"statusCode",
"===",
"200",
")",
"{",
"lintMarkdown",
"(",
"body",
",",
"repo",
")",
";",
"}",
"else",
"{",
"if",
"(",
"response",
".",
"headers",
"[",
"'x-ratelimit-remaining'",
"]",
"===",
"'0'",
")",
"{",
"getAuthToken",
"(",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'README for https://github.com/'",
"+",
"repo",
".",
"blue",
"+",
"' not found.'",
".",
"red",
")",
";",
"return",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Fetches a README from GitHub
@param {String} repo URL of repo to fetch
|
[
"Fetches",
"a",
"README",
"from",
"GitHub"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L162-L183
|
37,879 |
ChrisWren/mdlint
|
index.js
|
lintMarkdown
|
function lintMarkdown (body, file) {
var codeBlocks = parseMarkdown(body);
didLogFileBreak = false;
var failedCodeBlocks = _.reject(_.compact(codeBlocks), function (codeBlock) {
return validateCodeBlock(codeBlock, file);
});
numFilesToParse--;
if (failedCodeBlocks.length === 0) {
if (program.verbose) {
console.log('Markdown passed linting for '.green + file.blue.bold + '\n');
} else if (numFilesToParse === 0) {
console.log('All markdown files passed linting'.green);
}
} else {
if (numFailedFiles % 2 === 0) {
console.log('Markdown failed linting for '.red + file.yellow);
} else {
console.log('Markdown failed linting for '.red + file.blue);
}
numFailedFiles++;
console.log('');
}
}
|
javascript
|
function lintMarkdown (body, file) {
var codeBlocks = parseMarkdown(body);
didLogFileBreak = false;
var failedCodeBlocks = _.reject(_.compact(codeBlocks), function (codeBlock) {
return validateCodeBlock(codeBlock, file);
});
numFilesToParse--;
if (failedCodeBlocks.length === 0) {
if (program.verbose) {
console.log('Markdown passed linting for '.green + file.blue.bold + '\n');
} else if (numFilesToParse === 0) {
console.log('All markdown files passed linting'.green);
}
} else {
if (numFailedFiles % 2 === 0) {
console.log('Markdown failed linting for '.red + file.yellow);
} else {
console.log('Markdown failed linting for '.red + file.blue);
}
numFailedFiles++;
console.log('');
}
}
|
[
"function",
"lintMarkdown",
"(",
"body",
",",
"file",
")",
"{",
"var",
"codeBlocks",
"=",
"parseMarkdown",
"(",
"body",
")",
";",
"didLogFileBreak",
"=",
"false",
";",
"var",
"failedCodeBlocks",
"=",
"_",
".",
"reject",
"(",
"_",
".",
"compact",
"(",
"codeBlocks",
")",
",",
"function",
"(",
"codeBlock",
")",
"{",
"return",
"validateCodeBlock",
"(",
"codeBlock",
",",
"file",
")",
";",
"}",
")",
";",
"numFilesToParse",
"--",
";",
"if",
"(",
"failedCodeBlocks",
".",
"length",
"===",
"0",
")",
"{",
"if",
"(",
"program",
".",
"verbose",
")",
"{",
"console",
".",
"log",
"(",
"'Markdown passed linting for '",
".",
"green",
"+",
"file",
".",
"blue",
".",
"bold",
"+",
"'\\n'",
")",
";",
"}",
"else",
"if",
"(",
"numFilesToParse",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'All markdown files passed linting'",
".",
"green",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"numFailedFiles",
"%",
"2",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'Markdown failed linting for '",
".",
"red",
"+",
"file",
".",
"yellow",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'Markdown failed linting for '",
".",
"red",
"+",
"file",
".",
"blue",
")",
";",
"}",
"numFailedFiles",
"++",
";",
"console",
".",
"log",
"(",
"''",
")",
";",
"}",
"}"
] |
Parses the JavaScript code blocks from the markdown file
@param {String} body Body of markdown file
@param {String} file Filename
|
[
"Parses",
"the",
"JavaScript",
"code",
"blocks",
"from",
"the",
"markdown",
"file"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L226-L252
|
37,880 |
ChrisWren/mdlint
|
index.js
|
logFileBreak
|
function logFileBreak (text) {
if (numFailedFiles % 2 === 0) {
console.log(text.yellow.inverse);
} else {
console.log(text.blue.inverse);
}
}
|
javascript
|
function logFileBreak (text) {
if (numFailedFiles % 2 === 0) {
console.log(text.yellow.inverse);
} else {
console.log(text.blue.inverse);
}
}
|
[
"function",
"logFileBreak",
"(",
"text",
")",
"{",
"if",
"(",
"numFailedFiles",
"%",
"2",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"yellow",
".",
"inverse",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"text",
".",
"blue",
".",
"inverse",
")",
";",
"}",
"}"
] |
Logs a break between files for readability
@param {String} text Text to log
|
[
"Logs",
"a",
"break",
"between",
"files",
"for",
"readability"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L258-L264
|
37,881 |
ChrisWren/mdlint
|
index.js
|
validateCodeBlock
|
function validateCodeBlock (codeBlock, file) {
var lang = codeBlock.lang;
var code = codeBlock.code;
if (lang === 'json') {
try {
JSON.parse(code);
} catch (e) {
console.log(e);
console.log(code);
return false;
}
return true;
} else if (lang === 'js' || lang === 'javascript') {
code = preprocessCode(code);
try {
esprima.parse(code, { tolerant: true });
} catch (e) {
// Get indeces from lineNumber and column
var line = e.lineNumber - 1;
var column = e.column - 1;
// Highlight error in code
code = code.split('\n');
code[line] = code[line].slice(0, column).magenta +
code[line][column].red +
code[line].slice(column + 1).magenta;
code = code.join('\n');
if (!didLogFileBreak) {
logFileBreak(file);
didLogFileBreak = true;
}
console.log(e);
console.log(code);
return false;
}
return true;
}
}
|
javascript
|
function validateCodeBlock (codeBlock, file) {
var lang = codeBlock.lang;
var code = codeBlock.code;
if (lang === 'json') {
try {
JSON.parse(code);
} catch (e) {
console.log(e);
console.log(code);
return false;
}
return true;
} else if (lang === 'js' || lang === 'javascript') {
code = preprocessCode(code);
try {
esprima.parse(code, { tolerant: true });
} catch (e) {
// Get indeces from lineNumber and column
var line = e.lineNumber - 1;
var column = e.column - 1;
// Highlight error in code
code = code.split('\n');
code[line] = code[line].slice(0, column).magenta +
code[line][column].red +
code[line].slice(column + 1).magenta;
code = code.join('\n');
if (!didLogFileBreak) {
logFileBreak(file);
didLogFileBreak = true;
}
console.log(e);
console.log(code);
return false;
}
return true;
}
}
|
[
"function",
"validateCodeBlock",
"(",
"codeBlock",
",",
"file",
")",
"{",
"var",
"lang",
"=",
"codeBlock",
".",
"lang",
";",
"var",
"code",
"=",
"codeBlock",
".",
"code",
";",
"if",
"(",
"lang",
"===",
"'json'",
")",
"{",
"try",
"{",
"JSON",
".",
"parse",
"(",
"code",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"e",
")",
";",
"console",
".",
"log",
"(",
"code",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"lang",
"===",
"'js'",
"||",
"lang",
"===",
"'javascript'",
")",
"{",
"code",
"=",
"preprocessCode",
"(",
"code",
")",
";",
"try",
"{",
"esprima",
".",
"parse",
"(",
"code",
",",
"{",
"tolerant",
":",
"true",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Get indeces from lineNumber and column",
"var",
"line",
"=",
"e",
".",
"lineNumber",
"-",
"1",
";",
"var",
"column",
"=",
"e",
".",
"column",
"-",
"1",
";",
"// Highlight error in code",
"code",
"=",
"code",
".",
"split",
"(",
"'\\n'",
")",
";",
"code",
"[",
"line",
"]",
"=",
"code",
"[",
"line",
"]",
".",
"slice",
"(",
"0",
",",
"column",
")",
".",
"magenta",
"+",
"code",
"[",
"line",
"]",
"[",
"column",
"]",
".",
"red",
"+",
"code",
"[",
"line",
"]",
".",
"slice",
"(",
"column",
"+",
"1",
")",
".",
"magenta",
";",
"code",
"=",
"code",
".",
"join",
"(",
"'\\n'",
")",
";",
"if",
"(",
"!",
"didLogFileBreak",
")",
"{",
"logFileBreak",
"(",
"file",
")",
";",
"didLogFileBreak",
"=",
"true",
";",
"}",
"console",
".",
"log",
"(",
"e",
")",
";",
"console",
".",
"log",
"(",
"code",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"}"
] |
Validates that code blocks are valid JavaScript
@param {Object} code A block of code from the markdown file containg the lang and code
@param {String} file Name of file currently being validated
|
[
"Validates",
"that",
"code",
"blocks",
"are",
"valid",
"JavaScript"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L271-L315
|
37,882 |
ChrisWren/mdlint
|
index.js
|
getAuthToken
|
function getAuthToken () {
console.log('You have hit the rate limit for unauthenticated requests, please log in to raise your rate limit:\n'.red);
program.prompt('GitHub Username: ', function (user) {
console.log('\nAfter entering your password, hit return' + ' twice.\n'.green);
var authProcess = spawn('curl', [
'-u',
user,
'-d',
'{"scopes":["repo"],"note":"mdlint"}',
'-s',
'https://api.github.com/authorizations'
], {
stdio: [process.stdin, 'pipe', process.stderr]
});
authProcess.stdout.setEncoding('utf8');
authProcess.stdout.on('data', function (data) {
var response = JSON.parse(data);
if (response.message) {
console.log(response.message.red + '\n');
process.exit();
} else {
fs.writeFileSync(tokenFile, response.token);
console.log('Authenticated :). Now try your lint again. \n'.green);
process.exit();
}
});
});
}
|
javascript
|
function getAuthToken () {
console.log('You have hit the rate limit for unauthenticated requests, please log in to raise your rate limit:\n'.red);
program.prompt('GitHub Username: ', function (user) {
console.log('\nAfter entering your password, hit return' + ' twice.\n'.green);
var authProcess = spawn('curl', [
'-u',
user,
'-d',
'{"scopes":["repo"],"note":"mdlint"}',
'-s',
'https://api.github.com/authorizations'
], {
stdio: [process.stdin, 'pipe', process.stderr]
});
authProcess.stdout.setEncoding('utf8');
authProcess.stdout.on('data', function (data) {
var response = JSON.parse(data);
if (response.message) {
console.log(response.message.red + '\n');
process.exit();
} else {
fs.writeFileSync(tokenFile, response.token);
console.log('Authenticated :). Now try your lint again. \n'.green);
process.exit();
}
});
});
}
|
[
"function",
"getAuthToken",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'You have hit the rate limit for unauthenticated requests, please log in to raise your rate limit:\\n'",
".",
"red",
")",
";",
"program",
".",
"prompt",
"(",
"'GitHub Username: '",
",",
"function",
"(",
"user",
")",
"{",
"console",
".",
"log",
"(",
"'\\nAfter entering your password, hit return'",
"+",
"' twice.\\n'",
".",
"green",
")",
";",
"var",
"authProcess",
"=",
"spawn",
"(",
"'curl'",
",",
"[",
"'-u'",
",",
"user",
",",
"'-d'",
",",
"'{\"scopes\":[\"repo\"],\"note\":\"mdlint\"}'",
",",
"'-s'",
",",
"'https://api.github.com/authorizations'",
"]",
",",
"{",
"stdio",
":",
"[",
"process",
".",
"stdin",
",",
"'pipe'",
",",
"process",
".",
"stderr",
"]",
"}",
")",
";",
"authProcess",
".",
"stdout",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"authProcess",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"var",
"response",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"if",
"(",
"response",
".",
"message",
")",
"{",
"console",
".",
"log",
"(",
"response",
".",
"message",
".",
"red",
"+",
"'\\n'",
")",
";",
"process",
".",
"exit",
"(",
")",
";",
"}",
"else",
"{",
"fs",
".",
"writeFileSync",
"(",
"tokenFile",
",",
"response",
".",
"token",
")",
";",
"console",
".",
"log",
"(",
"'Authenticated :). Now try your lint again. \\n'",
".",
"green",
")",
";",
"process",
".",
"exit",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Retrieves an auth token so that the user can exceed the uauthenticated rate limit
|
[
"Retrieves",
"an",
"auth",
"token",
"so",
"that",
"the",
"user",
"can",
"exceed",
"the",
"uauthenticated",
"rate",
"limit"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L320-L350
|
37,883 |
ChrisWren/mdlint
|
index.js
|
preprocessCode
|
function preprocessCode (code) {
// Remove starting comments
while (code.indexOf('//') === 0) {
code = code.slice(code.indexOf('\n'));
}
// Starts with an object literal
if (code.indexOf('{') === 0) {
code = 'var json = ' + code;
// Starts with an object property
} else if (code.indexOf(':') !== -1 &&
code.indexOf(':') < code.indexOf(' ')) {
code = 'var json = {' + code + '}';
}
// Starts with an anonymous function
if (code.indexOf('function') === 0) {
code = 'var func = ' + code;
}
// Contains ...
return code.replace('...', '');
}
|
javascript
|
function preprocessCode (code) {
// Remove starting comments
while (code.indexOf('//') === 0) {
code = code.slice(code.indexOf('\n'));
}
// Starts with an object literal
if (code.indexOf('{') === 0) {
code = 'var json = ' + code;
// Starts with an object property
} else if (code.indexOf(':') !== -1 &&
code.indexOf(':') < code.indexOf(' ')) {
code = 'var json = {' + code + '}';
}
// Starts with an anonymous function
if (code.indexOf('function') === 0) {
code = 'var func = ' + code;
}
// Contains ...
return code.replace('...', '');
}
|
[
"function",
"preprocessCode",
"(",
"code",
")",
"{",
"// Remove starting comments",
"while",
"(",
"code",
".",
"indexOf",
"(",
"'//'",
")",
"===",
"0",
")",
"{",
"code",
"=",
"code",
".",
"slice",
"(",
"code",
".",
"indexOf",
"(",
"'\\n'",
")",
")",
";",
"}",
"// Starts with an object literal",
"if",
"(",
"code",
".",
"indexOf",
"(",
"'{'",
")",
"===",
"0",
")",
"{",
"code",
"=",
"'var json = '",
"+",
"code",
";",
"// Starts with an object property",
"}",
"else",
"if",
"(",
"code",
".",
"indexOf",
"(",
"':'",
")",
"!==",
"-",
"1",
"&&",
"code",
".",
"indexOf",
"(",
"':'",
")",
"<",
"code",
".",
"indexOf",
"(",
"' '",
")",
")",
"{",
"code",
"=",
"'var json = {'",
"+",
"code",
"+",
"'}'",
";",
"}",
"// Starts with an anonymous function",
"if",
"(",
"code",
".",
"indexOf",
"(",
"'function'",
")",
"===",
"0",
")",
"{",
"code",
"=",
"'var func = '",
"+",
"code",
";",
"}",
"// Contains ...",
"return",
"code",
".",
"replace",
"(",
"'...'",
",",
"''",
")",
";",
"}"
] |
Preprocesses the code block and re-formats it to allow for partial code
@param {String} code A block of code from the markdown file
@return {String} Processed code transformed from partial code
|
[
"Preprocesses",
"the",
"code",
"block",
"and",
"re",
"-",
"formats",
"it",
"to",
"allow",
"for",
"partial",
"code"
] |
15acc4b044f102644cba907699e793aecd053ab7
|
https://github.com/ChrisWren/mdlint/blob/15acc4b044f102644cba907699e793aecd053ab7/index.js#L357-L381
|
37,884 |
tprobinson/node-simple-dockerode
|
lib/processExec.js
|
processExec
|
function processExec(opts, createOpts, execOpts, callback) {
this.execRaw(createOpts, (createErr, exec) => {
if( createErr ) { callback(createErr); return }
exec.start(execOpts, (execErr, stream) => {
if( execErr ) { callback(execErr); return }
if( 'live' in opts && opts.live ) {
// If the user wants live streams, give them a function to attach to the builtin demuxStream
callback(null, (stdout, stderr) => {
if( stdout || stderr ) {
this.modem.demuxStream(stream, stdout, stderr)
}
// Allow an .on('end').
return stream
})
} else {
const results = {}
let callbackCalled = false
const callbackOnce = err => {
if( !callbackCalled ) {
callbackCalled = true
if( err ) {
Object.assign(results, {error: err})
}
// Inspect the exec and put that information into the results as well
// Allow this to be turned off via option later
// Workaround: if the user only has stdin and no stdout,
// the process will sometimes not immediately end.
let times = 10
const inspectLoop = () => {
exec.inspect((inspError, inspect) => {
if( inspect.ExitCode !== null ) {
if( times !== 10 ) {
inspect.tries = 10 - times
}
Object.assign(results, {inspect})
callback(inspError, results)
} else {
times--
setTimeout(inspectLoop, 50)
}
})
}
inspectLoop()
}
}
if( execOpts.Detach ) {
// Bitbucket the stream's data, so that it can close.
stream.on('data', () => {})
}
if( opts.stdin ) {
// Send the process whatever the user's going for.
if( isStream(opts.stdin) ) {
opts.stdin.pipe(stream)
} else {
const sender = new Stream.Readable()
sender.push(opts.stdin)
sender.push(null)
sender.pipe(stream)
}
}
if( opts.stdout || opts.stderr ) {
// Set up the battery to merge in its results when it's done. If it had an error, trigger the whole thing returning.
const battery = new StreamBattery(['stdout', 'stderr'], (battError, battResults) => {
Object.assign(results, battResults)
if( battError ) {
callbackOnce(battError)
}
})
// Start the stream demuxing
this.modem.demuxStream(stream, ...battery.streams)
stream.on('end', () => battery.end())
}
// Wait for the exec to end.
stream.on('end', callbackOnce)
stream.on('close', callbackOnce)
stream.on('error', callbackOnce)
}
})
})
}
|
javascript
|
function processExec(opts, createOpts, execOpts, callback) {
this.execRaw(createOpts, (createErr, exec) => {
if( createErr ) { callback(createErr); return }
exec.start(execOpts, (execErr, stream) => {
if( execErr ) { callback(execErr); return }
if( 'live' in opts && opts.live ) {
// If the user wants live streams, give them a function to attach to the builtin demuxStream
callback(null, (stdout, stderr) => {
if( stdout || stderr ) {
this.modem.demuxStream(stream, stdout, stderr)
}
// Allow an .on('end').
return stream
})
} else {
const results = {}
let callbackCalled = false
const callbackOnce = err => {
if( !callbackCalled ) {
callbackCalled = true
if( err ) {
Object.assign(results, {error: err})
}
// Inspect the exec and put that information into the results as well
// Allow this to be turned off via option later
// Workaround: if the user only has stdin and no stdout,
// the process will sometimes not immediately end.
let times = 10
const inspectLoop = () => {
exec.inspect((inspError, inspect) => {
if( inspect.ExitCode !== null ) {
if( times !== 10 ) {
inspect.tries = 10 - times
}
Object.assign(results, {inspect})
callback(inspError, results)
} else {
times--
setTimeout(inspectLoop, 50)
}
})
}
inspectLoop()
}
}
if( execOpts.Detach ) {
// Bitbucket the stream's data, so that it can close.
stream.on('data', () => {})
}
if( opts.stdin ) {
// Send the process whatever the user's going for.
if( isStream(opts.stdin) ) {
opts.stdin.pipe(stream)
} else {
const sender = new Stream.Readable()
sender.push(opts.stdin)
sender.push(null)
sender.pipe(stream)
}
}
if( opts.stdout || opts.stderr ) {
// Set up the battery to merge in its results when it's done. If it had an error, trigger the whole thing returning.
const battery = new StreamBattery(['stdout', 'stderr'], (battError, battResults) => {
Object.assign(results, battResults)
if( battError ) {
callbackOnce(battError)
}
})
// Start the stream demuxing
this.modem.demuxStream(stream, ...battery.streams)
stream.on('end', () => battery.end())
}
// Wait for the exec to end.
stream.on('end', callbackOnce)
stream.on('close', callbackOnce)
stream.on('error', callbackOnce)
}
})
})
}
|
[
"function",
"processExec",
"(",
"opts",
",",
"createOpts",
",",
"execOpts",
",",
"callback",
")",
"{",
"this",
".",
"execRaw",
"(",
"createOpts",
",",
"(",
"createErr",
",",
"exec",
")",
"=>",
"{",
"if",
"(",
"createErr",
")",
"{",
"callback",
"(",
"createErr",
")",
";",
"return",
"}",
"exec",
".",
"start",
"(",
"execOpts",
",",
"(",
"execErr",
",",
"stream",
")",
"=>",
"{",
"if",
"(",
"execErr",
")",
"{",
"callback",
"(",
"execErr",
")",
";",
"return",
"}",
"if",
"(",
"'live'",
"in",
"opts",
"&&",
"opts",
".",
"live",
")",
"{",
"// If the user wants live streams, give them a function to attach to the builtin demuxStream",
"callback",
"(",
"null",
",",
"(",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"if",
"(",
"stdout",
"||",
"stderr",
")",
"{",
"this",
".",
"modem",
".",
"demuxStream",
"(",
"stream",
",",
"stdout",
",",
"stderr",
")",
"}",
"// Allow an .on('end').",
"return",
"stream",
"}",
")",
"}",
"else",
"{",
"const",
"results",
"=",
"{",
"}",
"let",
"callbackCalled",
"=",
"false",
"const",
"callbackOnce",
"=",
"err",
"=>",
"{",
"if",
"(",
"!",
"callbackCalled",
")",
"{",
"callbackCalled",
"=",
"true",
"if",
"(",
"err",
")",
"{",
"Object",
".",
"assign",
"(",
"results",
",",
"{",
"error",
":",
"err",
"}",
")",
"}",
"// Inspect the exec and put that information into the results as well",
"// Allow this to be turned off via option later",
"// Workaround: if the user only has stdin and no stdout,",
"// the process will sometimes not immediately end.",
"let",
"times",
"=",
"10",
"const",
"inspectLoop",
"=",
"(",
")",
"=>",
"{",
"exec",
".",
"inspect",
"(",
"(",
"inspError",
",",
"inspect",
")",
"=>",
"{",
"if",
"(",
"inspect",
".",
"ExitCode",
"!==",
"null",
")",
"{",
"if",
"(",
"times",
"!==",
"10",
")",
"{",
"inspect",
".",
"tries",
"=",
"10",
"-",
"times",
"}",
"Object",
".",
"assign",
"(",
"results",
",",
"{",
"inspect",
"}",
")",
"callback",
"(",
"inspError",
",",
"results",
")",
"}",
"else",
"{",
"times",
"--",
"setTimeout",
"(",
"inspectLoop",
",",
"50",
")",
"}",
"}",
")",
"}",
"inspectLoop",
"(",
")",
"}",
"}",
"if",
"(",
"execOpts",
".",
"Detach",
")",
"{",
"// Bitbucket the stream's data, so that it can close.",
"stream",
".",
"on",
"(",
"'data'",
",",
"(",
")",
"=>",
"{",
"}",
")",
"}",
"if",
"(",
"opts",
".",
"stdin",
")",
"{",
"// Send the process whatever the user's going for.",
"if",
"(",
"isStream",
"(",
"opts",
".",
"stdin",
")",
")",
"{",
"opts",
".",
"stdin",
".",
"pipe",
"(",
"stream",
")",
"}",
"else",
"{",
"const",
"sender",
"=",
"new",
"Stream",
".",
"Readable",
"(",
")",
"sender",
".",
"push",
"(",
"opts",
".",
"stdin",
")",
"sender",
".",
"push",
"(",
"null",
")",
"sender",
".",
"pipe",
"(",
"stream",
")",
"}",
"}",
"if",
"(",
"opts",
".",
"stdout",
"||",
"opts",
".",
"stderr",
")",
"{",
"// Set up the battery to merge in its results when it's done. If it had an error, trigger the whole thing returning.",
"const",
"battery",
"=",
"new",
"StreamBattery",
"(",
"[",
"'stdout'",
",",
"'stderr'",
"]",
",",
"(",
"battError",
",",
"battResults",
")",
"=>",
"{",
"Object",
".",
"assign",
"(",
"results",
",",
"battResults",
")",
"if",
"(",
"battError",
")",
"{",
"callbackOnce",
"(",
"battError",
")",
"}",
"}",
")",
"// Start the stream demuxing",
"this",
".",
"modem",
".",
"demuxStream",
"(",
"stream",
",",
"...",
"battery",
".",
"streams",
")",
"stream",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"battery",
".",
"end",
"(",
")",
")",
"}",
"// Wait for the exec to end.",
"stream",
".",
"on",
"(",
"'end'",
",",
"callbackOnce",
")",
"stream",
".",
"on",
"(",
"'close'",
",",
"callbackOnce",
")",
"stream",
".",
"on",
"(",
"'error'",
",",
"callbackOnce",
")",
"}",
"}",
")",
"}",
")",
"}"
] |
A version of exec that wraps Dockerode's, reducing the stream handling for most use cases.
@param {Array<string>} Cmd The command to execute, in exec array form.
@param {Object} opts Object of options.
@param {boolean} opts.stdout True/false, if true, user will receive a stdout key with the output
@param {boolean} opts.stderr True/false, if true, user will receive a stderr key with the output
@param {string|Stream} opts.stdin If this key exists, whatever the user puts in here will be sent to the container.
@param {boolean} opts.live If true, the user will receive a function to plug into the demuxer, instead of finished values.
@param {Object} createOpts Args for the normal exec.create, processed via {@link processArgs}
@param {Object} execOpts Args for the normal exec.start, processed via {@link processArgs}
@param {function} callback Will be called with either a function to plug into demuxer, or an object with whatever output keys the user requested.
|
[
"A",
"version",
"of",
"exec",
"that",
"wraps",
"Dockerode",
"s",
"reducing",
"the",
"stream",
"handling",
"for",
"most",
"use",
"cases",
"."
] |
b201490ac82859d560e5a687fee7a8410700a87a
|
https://github.com/tprobinson/node-simple-dockerode/blob/b201490ac82859d560e5a687fee7a8410700a87a/lib/processExec.js#L17-L103
|
37,885 |
brandonheyer/mazejs
|
js/foundation/foundation.forms.js
|
function() {
// Internal reference.
var _self = this;
// Loop through our hidden element collection.
_self.hidden.each( function( i ) {
// Cache this element.
var $elem = $( this ),
_tmp = _self.tmp[ i ]; // Get the stored 'style' value for this element.
// If the stored value is undefined.
if( _tmp === undefined )
// Remove the style attribute.
$elem.removeAttr( 'style' );
else
// Otherwise, reset the element style attribute.
$elem.attr( 'style', _tmp );
});
// Reset the tmp array.
_self.tmp = [];
// Reset the hidden elements variable.
_self.hidden = null;
}
|
javascript
|
function() {
// Internal reference.
var _self = this;
// Loop through our hidden element collection.
_self.hidden.each( function( i ) {
// Cache this element.
var $elem = $( this ),
_tmp = _self.tmp[ i ]; // Get the stored 'style' value for this element.
// If the stored value is undefined.
if( _tmp === undefined )
// Remove the style attribute.
$elem.removeAttr( 'style' );
else
// Otherwise, reset the element style attribute.
$elem.attr( 'style', _tmp );
});
// Reset the tmp array.
_self.tmp = [];
// Reset the hidden elements variable.
_self.hidden = null;
}
|
[
"function",
"(",
")",
"{",
"// Internal reference.",
"var",
"_self",
"=",
"this",
";",
"// Loop through our hidden element collection.",
"_self",
".",
"hidden",
".",
"each",
"(",
"function",
"(",
"i",
")",
"{",
"// Cache this element.",
"var",
"$elem",
"=",
"$",
"(",
"this",
")",
",",
"_tmp",
"=",
"_self",
".",
"tmp",
"[",
"i",
"]",
";",
"// Get the stored 'style' value for this element.",
"// If the stored value is undefined.",
"if",
"(",
"_tmp",
"===",
"undefined",
")",
"// Remove the style attribute.",
"$elem",
".",
"removeAttr",
"(",
"'style'",
")",
";",
"else",
"// Otherwise, reset the element style attribute.",
"$elem",
".",
"attr",
"(",
"'style'",
",",
"_tmp",
")",
";",
"}",
")",
";",
"// Reset the tmp array.",
"_self",
".",
"tmp",
"=",
"[",
"]",
";",
"// Reset the hidden elements variable.",
"_self",
".",
"hidden",
"=",
"null",
";",
"}"
] |
end adjust
Resets the elements previous state.
@method reset
|
[
"end",
"adjust",
"Resets",
"the",
"elements",
"previous",
"state",
"."
] |
5efffc0279eeb061a71ba243313d165c16300fe6
|
https://github.com/brandonheyer/mazejs/blob/5efffc0279eeb061a71ba243313d165c16300fe6/js/foundation/foundation.forms.js#L396-L419
|
|
37,886 |
scott-wyatt/sails-stripe
|
templates/Transfer.template.js
|
function (transfer, cb) {
Transfer.findOrCreate(transfer.id, transfer)
.exec(function (err, foundTransfer){
if (err) return cb(err);
if (foundTransfer.lastStripeEvent > transfer.lastStripeEvent) return cb(null, foundTransfer);
if (foundTransfer.lastStripeEvent == transfer.lastStripeEvent) return Transfer.afterStripeTransferCreated(foundTransfer, function(err, transfer){ return cb(err, transfer)});
Transfer.update(foundTransfer.id, transfer)
.exec(function(err, updatedTransfers){
if (err) return cb(err);
if(!updatedTransfers) return cb(null, null);
Transfer.afterStripeTransferCreated(updatedTransfers[0], function(err, transfer){
cb(err, transfer);
});
});
});
}
|
javascript
|
function (transfer, cb) {
Transfer.findOrCreate(transfer.id, transfer)
.exec(function (err, foundTransfer){
if (err) return cb(err);
if (foundTransfer.lastStripeEvent > transfer.lastStripeEvent) return cb(null, foundTransfer);
if (foundTransfer.lastStripeEvent == transfer.lastStripeEvent) return Transfer.afterStripeTransferCreated(foundTransfer, function(err, transfer){ return cb(err, transfer)});
Transfer.update(foundTransfer.id, transfer)
.exec(function(err, updatedTransfers){
if (err) return cb(err);
if(!updatedTransfers) return cb(null, null);
Transfer.afterStripeTransferCreated(updatedTransfers[0], function(err, transfer){
cb(err, transfer);
});
});
});
}
|
[
"function",
"(",
"transfer",
",",
"cb",
")",
"{",
"Transfer",
".",
"findOrCreate",
"(",
"transfer",
".",
"id",
",",
"transfer",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundTransfer",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"foundTransfer",
".",
"lastStripeEvent",
">",
"transfer",
".",
"lastStripeEvent",
")",
"return",
"cb",
"(",
"null",
",",
"foundTransfer",
")",
";",
"if",
"(",
"foundTransfer",
".",
"lastStripeEvent",
"==",
"transfer",
".",
"lastStripeEvent",
")",
"return",
"Transfer",
".",
"afterStripeTransferCreated",
"(",
"foundTransfer",
",",
"function",
"(",
"err",
",",
"transfer",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"transfer",
")",
"}",
")",
";",
"Transfer",
".",
"update",
"(",
"foundTransfer",
".",
"id",
",",
"transfer",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedTransfers",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"updatedTransfers",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Transfer",
".",
"afterStripeTransferCreated",
"(",
"updatedTransfers",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"transfer",
")",
"{",
"cb",
"(",
"err",
",",
"transfer",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook transfer.created
|
[
"Stripe",
"Webhook",
"transfer",
".",
"created"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Transfer.template.js#L102-L118
|
|
37,887 |
nfroidure/jsarch
|
src/jsarch.js
|
initJSArch
|
async function initJSArch({ CONFIG, EOL, glob, fs, parser, log = noop }) {
return jsArch;
/**
* Compile an run a template
* @param {Object} options
* Options (destructured)
* @param {Object} options.cwd
* Current working directory
* @param {Object} options.patterns
* Patterns to look files for (see node-glob)
* @param {Object} options.eol
* End of line character (default to the OS one)
* @param {Object} options.titleLevel
* The base title level of the output makdown document
* @param {Object} options.base
* The base directory for the ARCHITECTURE.md references
* @return {Promise<String>}
* Computed architecture notes as a markdown file
*/
async function jsArch({
cwd,
patterns,
eol,
titleLevel = TITLE_LEVEL,
base = BASE,
}) {
eol = eol || EOL;
const files = await _computePatterns({ glob, log }, cwd, patterns);
const architectureNotes = _linearize(
await Promise.all(
files.map(_extractArchitectureNotes.bind(null, { parser, fs, log })),
),
);
const content = architectureNotes
.sort(compareNotes)
.reduce((content, architectureNote) => {
let linesLink =
'#L' +
architectureNote.loc.start.line +
'-L' +
architectureNote.loc.end.line;
if (CONFIG.gitProvider.toLowerCase() === 'bitbucket') {
linesLink =
'#' +
path.basename(architectureNote.filePath) +
'-' +
architectureNote.loc.start.line +
':' +
architectureNote.loc.end.line;
}
return (
content +
eol +
eol +
titleLevel +
architectureNote.num
.split('.')
.map(() => '#')
.join('') +
' ' +
architectureNote.title +
eol +
eol +
architectureNote.content.replace(
new RegExp(
'([\r\n]+)[ \t]{' + architectureNote.loc.start.column + '}',
'g',
),
'$1',
) +
eol +
eol +
'[See in context](' +
base +
'/' +
path.relative(cwd, architectureNote.filePath) +
linesLink +
')' +
eol +
eol
);
}, '');
if (content) {
return (
JSARCH_PREFIX.replace(EOL_REGEXP, eol) +
titleLevel +
' Architecture Notes' +
eol +
eol +
content
);
}
return content;
}
}
|
javascript
|
async function initJSArch({ CONFIG, EOL, glob, fs, parser, log = noop }) {
return jsArch;
/**
* Compile an run a template
* @param {Object} options
* Options (destructured)
* @param {Object} options.cwd
* Current working directory
* @param {Object} options.patterns
* Patterns to look files for (see node-glob)
* @param {Object} options.eol
* End of line character (default to the OS one)
* @param {Object} options.titleLevel
* The base title level of the output makdown document
* @param {Object} options.base
* The base directory for the ARCHITECTURE.md references
* @return {Promise<String>}
* Computed architecture notes as a markdown file
*/
async function jsArch({
cwd,
patterns,
eol,
titleLevel = TITLE_LEVEL,
base = BASE,
}) {
eol = eol || EOL;
const files = await _computePatterns({ glob, log }, cwd, patterns);
const architectureNotes = _linearize(
await Promise.all(
files.map(_extractArchitectureNotes.bind(null, { parser, fs, log })),
),
);
const content = architectureNotes
.sort(compareNotes)
.reduce((content, architectureNote) => {
let linesLink =
'#L' +
architectureNote.loc.start.line +
'-L' +
architectureNote.loc.end.line;
if (CONFIG.gitProvider.toLowerCase() === 'bitbucket') {
linesLink =
'#' +
path.basename(architectureNote.filePath) +
'-' +
architectureNote.loc.start.line +
':' +
architectureNote.loc.end.line;
}
return (
content +
eol +
eol +
titleLevel +
architectureNote.num
.split('.')
.map(() => '#')
.join('') +
' ' +
architectureNote.title +
eol +
eol +
architectureNote.content.replace(
new RegExp(
'([\r\n]+)[ \t]{' + architectureNote.loc.start.column + '}',
'g',
),
'$1',
) +
eol +
eol +
'[See in context](' +
base +
'/' +
path.relative(cwd, architectureNote.filePath) +
linesLink +
')' +
eol +
eol
);
}, '');
if (content) {
return (
JSARCH_PREFIX.replace(EOL_REGEXP, eol) +
titleLevel +
' Architecture Notes' +
eol +
eol +
content
);
}
return content;
}
}
|
[
"async",
"function",
"initJSArch",
"(",
"{",
"CONFIG",
",",
"EOL",
",",
"glob",
",",
"fs",
",",
"parser",
",",
"log",
"=",
"noop",
"}",
")",
"{",
"return",
"jsArch",
";",
"/**\n * Compile an run a template\n * @param {Object} options\n * Options (destructured)\n * @param {Object} options.cwd\n * Current working directory\n * @param {Object} options.patterns\n * Patterns to look files for (see node-glob)\n * @param {Object} options.eol\n * End of line character (default to the OS one)\n * @param {Object} options.titleLevel\n * The base title level of the output makdown document\n * @param {Object} options.base\n * The base directory for the ARCHITECTURE.md references\n * @return {Promise<String>}\n * Computed architecture notes as a markdown file\n */",
"async",
"function",
"jsArch",
"(",
"{",
"cwd",
",",
"patterns",
",",
"eol",
",",
"titleLevel",
"=",
"TITLE_LEVEL",
",",
"base",
"=",
"BASE",
",",
"}",
")",
"{",
"eol",
"=",
"eol",
"||",
"EOL",
";",
"const",
"files",
"=",
"await",
"_computePatterns",
"(",
"{",
"glob",
",",
"log",
"}",
",",
"cwd",
",",
"patterns",
")",
";",
"const",
"architectureNotes",
"=",
"_linearize",
"(",
"await",
"Promise",
".",
"all",
"(",
"files",
".",
"map",
"(",
"_extractArchitectureNotes",
".",
"bind",
"(",
"null",
",",
"{",
"parser",
",",
"fs",
",",
"log",
"}",
")",
")",
",",
")",
",",
")",
";",
"const",
"content",
"=",
"architectureNotes",
".",
"sort",
"(",
"compareNotes",
")",
".",
"reduce",
"(",
"(",
"content",
",",
"architectureNote",
")",
"=>",
"{",
"let",
"linesLink",
"=",
"'#L'",
"+",
"architectureNote",
".",
"loc",
".",
"start",
".",
"line",
"+",
"'-L'",
"+",
"architectureNote",
".",
"loc",
".",
"end",
".",
"line",
";",
"if",
"(",
"CONFIG",
".",
"gitProvider",
".",
"toLowerCase",
"(",
")",
"===",
"'bitbucket'",
")",
"{",
"linesLink",
"=",
"'#'",
"+",
"path",
".",
"basename",
"(",
"architectureNote",
".",
"filePath",
")",
"+",
"'-'",
"+",
"architectureNote",
".",
"loc",
".",
"start",
".",
"line",
"+",
"':'",
"+",
"architectureNote",
".",
"loc",
".",
"end",
".",
"line",
";",
"}",
"return",
"(",
"content",
"+",
"eol",
"+",
"eol",
"+",
"titleLevel",
"+",
"architectureNote",
".",
"num",
".",
"split",
"(",
"'.'",
")",
".",
"map",
"(",
"(",
")",
"=>",
"'#'",
")",
".",
"join",
"(",
"''",
")",
"+",
"' '",
"+",
"architectureNote",
".",
"title",
"+",
"eol",
"+",
"eol",
"+",
"architectureNote",
".",
"content",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'([\\r\\n]+)[ \\t]{'",
"+",
"architectureNote",
".",
"loc",
".",
"start",
".",
"column",
"+",
"'}'",
",",
"'g'",
",",
")",
",",
"'$1'",
",",
")",
"+",
"eol",
"+",
"eol",
"+",
"'[See in context]('",
"+",
"base",
"+",
"'/'",
"+",
"path",
".",
"relative",
"(",
"cwd",
",",
"architectureNote",
".",
"filePath",
")",
"+",
"linesLink",
"+",
"')'",
"+",
"eol",
"+",
"eol",
")",
";",
"}",
",",
"''",
")",
";",
"if",
"(",
"content",
")",
"{",
"return",
"(",
"JSARCH_PREFIX",
".",
"replace",
"(",
"EOL_REGEXP",
",",
"eol",
")",
"+",
"titleLevel",
"+",
"' Architecture Notes'",
"+",
"eol",
"+",
"eol",
"+",
"content",
")",
";",
"}",
"return",
"content",
";",
"}",
"}"
] |
Declare jsArch in the dependency injection system
@param {Object} services
Services (provided by the dependency injector)
@param {Object} services.CONFIG
The JSArch config
@param {Object} services.EOL
The OS EOL chars
@param {Object} services.glob
Globbing service
@param {Object} services.fs
File system service
@param {Object} services.parser
Parser service
@param {Object} [services.log = noop]
Logging service
@returns {Promise<Function>}
|
[
"Declare",
"jsArch",
"in",
"the",
"dependency",
"injection",
"system"
] |
df23251b90d64794d733d4fdebfbb31a03b9fe1c
|
https://github.com/nfroidure/jsarch/blob/df23251b90d64794d733d4fdebfbb31a03b9fe1c/src/jsarch.js#L102-L198
|
37,888 |
byron-dupreez/aws-core-utils
|
dynamodb-doc-client-utils.js
|
getItem
|
function getItem(tableName, key, opts, desc, context) {
try {
const params = {
TableName: tableName,
Key: key
};
if (opts) merge(opts, params, mergeOpts);
if (context.traceEnabled) context.trace(`Loading ${desc} from ${tableName} using params (${JSON.stringify(params)})`);
return context.dynamoDBDocClient.get(params).promise()
.then(result => {
if (context.traceEnabled) context.trace(`Loaded ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
if (result && typeof result === 'object') {
return result;
}
throw new TypeError(`Unexpected result from get ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
})
.catch(err => {
context.error(`Failed to load ${desc} from ${tableName}`, err);
throw err;
});
} catch (err) {
context.error(`Failed to load ${desc} from ${tableName}`, err);
return Promise.reject(err);
}
}
|
javascript
|
function getItem(tableName, key, opts, desc, context) {
try {
const params = {
TableName: tableName,
Key: key
};
if (opts) merge(opts, params, mergeOpts);
if (context.traceEnabled) context.trace(`Loading ${desc} from ${tableName} using params (${JSON.stringify(params)})`);
return context.dynamoDBDocClient.get(params).promise()
.then(result => {
if (context.traceEnabled) context.trace(`Loaded ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
if (result && typeof result === 'object') {
return result;
}
throw new TypeError(`Unexpected result from get ${desc} from ${tableName} - result (${JSON.stringify(result)})`);
})
.catch(err => {
context.error(`Failed to load ${desc} from ${tableName}`, err);
throw err;
});
} catch (err) {
context.error(`Failed to load ${desc} from ${tableName}`, err);
return Promise.reject(err);
}
}
|
[
"function",
"getItem",
"(",
"tableName",
",",
"key",
",",
"opts",
",",
"desc",
",",
"context",
")",
"{",
"try",
"{",
"const",
"params",
"=",
"{",
"TableName",
":",
"tableName",
",",
"Key",
":",
"key",
"}",
";",
"if",
"(",
"opts",
")",
"merge",
"(",
"opts",
",",
"params",
",",
"mergeOpts",
")",
";",
"if",
"(",
"context",
".",
"traceEnabled",
")",
"context",
".",
"trace",
"(",
"`",
"${",
"desc",
"}",
"${",
"tableName",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"params",
")",
"}",
"`",
")",
";",
"return",
"context",
".",
"dynamoDBDocClient",
".",
"get",
"(",
"params",
")",
".",
"promise",
"(",
")",
".",
"then",
"(",
"result",
"=>",
"{",
"if",
"(",
"context",
".",
"traceEnabled",
")",
"context",
".",
"trace",
"(",
"`",
"${",
"desc",
"}",
"${",
"tableName",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"result",
")",
"}",
"`",
")",
";",
"if",
"(",
"result",
"&&",
"typeof",
"result",
"===",
"'object'",
")",
"{",
"return",
"result",
";",
"}",
"throw",
"new",
"TypeError",
"(",
"`",
"${",
"desc",
"}",
"${",
"tableName",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"result",
")",
"}",
"`",
")",
";",
"}",
")",
".",
"catch",
"(",
"err",
"=>",
"{",
"context",
".",
"error",
"(",
"`",
"${",
"desc",
"}",
"${",
"tableName",
"}",
"`",
",",
"err",
")",
";",
"throw",
"err",
";",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"context",
".",
"error",
"(",
"`",
"${",
"desc",
"}",
"${",
"tableName",
"}",
"`",
",",
"err",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}"
] |
Gets the item with the given key from the named DynamoDB table.
@param {string} tableName - the name of the DynamoDB table from which to load
@param {K} key - the key of the item to get
@param {DynamoGetOpts|undefined} [opts] - optional DynamoDB `get` parameter options to use
@param {string} desc - a description of the item being requested for logging purposes
@param {StandardContext} context - the context to use
@return {Promise.<DynamoGetResult.<I>>} a promise that will resolve with the result or reject with an error
@template I,K
|
[
"Gets",
"the",
"item",
"with",
"the",
"given",
"key",
"from",
"the",
"named",
"DynamoDB",
"table",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/dynamodb-doc-client-utils.js#L33-L60
|
37,889 |
byron-dupreez/aws-core-utils
|
dynamodb-doc-client-utils.js
|
updateProjectionExpression
|
function updateProjectionExpression(opts, expressions) {
if (!expressions || !Array.isArray(expressions) || expressions.length <= 0) return opts;
if (!opts) opts = {};
const projectionExpressions = opts.ProjectionExpression ?
opts.ProjectionExpression.split(',').filter(isNotBlank).map(trim) : [];
expressions.forEach(expression => {
if (isNotBlank(expression) && projectionExpressions.indexOf(expression) === -1) {
projectionExpressions.push(trim(expression));
}
});
const projectionExpression = projectionExpressions.length > 0 ? projectionExpressions.join(',') : undefined;
opts.ProjectionExpression = isNotBlank(projectionExpression) ? projectionExpression : undefined;
return opts;
}
|
javascript
|
function updateProjectionExpression(opts, expressions) {
if (!expressions || !Array.isArray(expressions) || expressions.length <= 0) return opts;
if (!opts) opts = {};
const projectionExpressions = opts.ProjectionExpression ?
opts.ProjectionExpression.split(',').filter(isNotBlank).map(trim) : [];
expressions.forEach(expression => {
if (isNotBlank(expression) && projectionExpressions.indexOf(expression) === -1) {
projectionExpressions.push(trim(expression));
}
});
const projectionExpression = projectionExpressions.length > 0 ? projectionExpressions.join(',') : undefined;
opts.ProjectionExpression = isNotBlank(projectionExpression) ? projectionExpression : undefined;
return opts;
}
|
[
"function",
"updateProjectionExpression",
"(",
"opts",
",",
"expressions",
")",
"{",
"if",
"(",
"!",
"expressions",
"||",
"!",
"Array",
".",
"isArray",
"(",
"expressions",
")",
"||",
"expressions",
".",
"length",
"<=",
"0",
")",
"return",
"opts",
";",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
";",
"const",
"projectionExpressions",
"=",
"opts",
".",
"ProjectionExpression",
"?",
"opts",
".",
"ProjectionExpression",
".",
"split",
"(",
"','",
")",
".",
"filter",
"(",
"isNotBlank",
")",
".",
"map",
"(",
"trim",
")",
":",
"[",
"]",
";",
"expressions",
".",
"forEach",
"(",
"expression",
"=>",
"{",
"if",
"(",
"isNotBlank",
"(",
"expression",
")",
"&&",
"projectionExpressions",
".",
"indexOf",
"(",
"expression",
")",
"===",
"-",
"1",
")",
"{",
"projectionExpressions",
".",
"push",
"(",
"trim",
"(",
"expression",
")",
")",
";",
"}",
"}",
")",
";",
"const",
"projectionExpression",
"=",
"projectionExpressions",
".",
"length",
">",
"0",
"?",
"projectionExpressions",
".",
"join",
"(",
"','",
")",
":",
"undefined",
";",
"opts",
".",
"ProjectionExpression",
"=",
"isNotBlank",
"(",
"projectionExpression",
")",
"?",
"projectionExpression",
":",
"undefined",
";",
"return",
"opts",
";",
"}"
] |
Updates the ProjectionExpression property of the given opts with the given extra expressions.
@param {DynamoGetOpts|DynamoQueryOpts|Object|undefined} opts - the options to update
@param {string[]} expressions - the expressions to add
@return {DynamoGetOpts|DynamoQueryOpts|Object} the updated options
|
[
"Updates",
"the",
"ProjectionExpression",
"property",
"of",
"the",
"given",
"opts",
"with",
"the",
"given",
"extra",
"expressions",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/dynamodb-doc-client-utils.js#L68-L84
|
37,890 |
byron-dupreez/aws-core-utils
|
dynamodb-doc-client-utils.js
|
updateExpressionAttributeNames
|
function updateExpressionAttributeNames(opts, expressionAttributeNames) {
if (!expressionAttributeNames || typeof expressionAttributeNames !== 'object') return opts;
if (!opts) opts = {};
if (!opts.ExpressionAttributeNames) opts.ExpressionAttributeNames = {};
const keys = Object.getOwnPropertyNames(expressionAttributeNames);
keys.forEach(key => {
opts.ExpressionAttributeNames[key] = expressionAttributeNames[key];
});
return opts;
}
|
javascript
|
function updateExpressionAttributeNames(opts, expressionAttributeNames) {
if (!expressionAttributeNames || typeof expressionAttributeNames !== 'object') return opts;
if (!opts) opts = {};
if (!opts.ExpressionAttributeNames) opts.ExpressionAttributeNames = {};
const keys = Object.getOwnPropertyNames(expressionAttributeNames);
keys.forEach(key => {
opts.ExpressionAttributeNames[key] = expressionAttributeNames[key];
});
return opts;
}
|
[
"function",
"updateExpressionAttributeNames",
"(",
"opts",
",",
"expressionAttributeNames",
")",
"{",
"if",
"(",
"!",
"expressionAttributeNames",
"||",
"typeof",
"expressionAttributeNames",
"!==",
"'object'",
")",
"return",
"opts",
";",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"ExpressionAttributeNames",
")",
"opts",
".",
"ExpressionAttributeNames",
"=",
"{",
"}",
";",
"const",
"keys",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"expressionAttributeNames",
")",
";",
"keys",
".",
"forEach",
"(",
"key",
"=>",
"{",
"opts",
".",
"ExpressionAttributeNames",
"[",
"key",
"]",
"=",
"expressionAttributeNames",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"opts",
";",
"}"
] |
Updates the ExpressionAttributeNames map of the given opts with the given map of extra expression attribute names.
@param {DynamoGetOpts|DynamoQueryOpts|Object|undefined} opts - the options to update
@param {Object.<string, string>} expressionAttributeNames - the map of extra expression attribute names to add
@return {DynamoGetOpts|DynamoQueryOpts|Object} the updated options
|
[
"Updates",
"the",
"ExpressionAttributeNames",
"map",
"of",
"the",
"given",
"opts",
"with",
"the",
"given",
"map",
"of",
"extra",
"expression",
"attribute",
"names",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/dynamodb-doc-client-utils.js#L92-L103
|
37,891 |
byron-dupreez/aws-core-utils
|
dynamodb-doc-client-utils.js
|
updateExpressionAttributeValues
|
function updateExpressionAttributeValues(opts, expressionAttributeValues) {
if (!expressionAttributeValues || typeof expressionAttributeValues !== 'object') return opts;
if (!opts) opts = {};
if (!opts.ExpressionAttributeValues) opts.ExpressionAttributeValues = {};
const keys = Object.getOwnPropertyNames(expressionAttributeValues);
keys.forEach(key => {
opts.ExpressionAttributeValues[key] = expressionAttributeValues[key];
});
return opts;
}
|
javascript
|
function updateExpressionAttributeValues(opts, expressionAttributeValues) {
if (!expressionAttributeValues || typeof expressionAttributeValues !== 'object') return opts;
if (!opts) opts = {};
if (!opts.ExpressionAttributeValues) opts.ExpressionAttributeValues = {};
const keys = Object.getOwnPropertyNames(expressionAttributeValues);
keys.forEach(key => {
opts.ExpressionAttributeValues[key] = expressionAttributeValues[key];
});
return opts;
}
|
[
"function",
"updateExpressionAttributeValues",
"(",
"opts",
",",
"expressionAttributeValues",
")",
"{",
"if",
"(",
"!",
"expressionAttributeValues",
"||",
"typeof",
"expressionAttributeValues",
"!==",
"'object'",
")",
"return",
"opts",
";",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"ExpressionAttributeValues",
")",
"opts",
".",
"ExpressionAttributeValues",
"=",
"{",
"}",
";",
"const",
"keys",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"expressionAttributeValues",
")",
";",
"keys",
".",
"forEach",
"(",
"key",
"=>",
"{",
"opts",
".",
"ExpressionAttributeValues",
"[",
"key",
"]",
"=",
"expressionAttributeValues",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"opts",
";",
"}"
] |
Updates the ExpressionAttributeValues map of the given opts with the given map of extra expression attribute names.
@param {DynamoQueryOpts|Object|undefined} opts - the options to update
@param {Object.<string, string>} expressionAttributeValues - the map of extra expression attribute names to add
@return {DynamoQueryOpts|Object} the updated options
|
[
"Updates",
"the",
"ExpressionAttributeValues",
"map",
"of",
"the",
"given",
"opts",
"with",
"the",
"given",
"map",
"of",
"extra",
"expression",
"attribute",
"names",
"."
] |
2530155b5afc102f61658b28183a16027ecae86a
|
https://github.com/byron-dupreez/aws-core-utils/blob/2530155b5afc102f61658b28183a16027ecae86a/dynamodb-doc-client-utils.js#L111-L122
|
37,892 |
scott-wyatt/sails-stripe
|
templates/Card.template.js
|
function (card, cb) {
Card.findOrCreate(card.id, card)
.exec(function (err, foundCard){
if (err) return cb(err);
if (foundCard.lastStripeEvent > card.lastStripeEvent) return cb(null, foundCard);
if (foundCard.lastStripeEvent == card.lastStripeEvent) return Card.afterStripeCustomerCardUpdated(foundCard, function(err, card){ return cb(err, card)});
Card.update(foundCard.id, card)
.exec(function(err, updatedCards){
if (err) return cb(err);
if (!updatedCards) return cb(null, null);
Card.afterStripeCustomerCardUpdated(updatedCards[0], function(err, card){
cb(err, card);
});
});
});
}
|
javascript
|
function (card, cb) {
Card.findOrCreate(card.id, card)
.exec(function (err, foundCard){
if (err) return cb(err);
if (foundCard.lastStripeEvent > card.lastStripeEvent) return cb(null, foundCard);
if (foundCard.lastStripeEvent == card.lastStripeEvent) return Card.afterStripeCustomerCardUpdated(foundCard, function(err, card){ return cb(err, card)});
Card.update(foundCard.id, card)
.exec(function(err, updatedCards){
if (err) return cb(err);
if (!updatedCards) return cb(null, null);
Card.afterStripeCustomerCardUpdated(updatedCards[0], function(err, card){
cb(err, card);
});
});
});
}
|
[
"function",
"(",
"card",
",",
"cb",
")",
"{",
"Card",
".",
"findOrCreate",
"(",
"card",
".",
"id",
",",
"card",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"foundCard",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"foundCard",
".",
"lastStripeEvent",
">",
"card",
".",
"lastStripeEvent",
")",
"return",
"cb",
"(",
"null",
",",
"foundCard",
")",
";",
"if",
"(",
"foundCard",
".",
"lastStripeEvent",
"==",
"card",
".",
"lastStripeEvent",
")",
"return",
"Card",
".",
"afterStripeCustomerCardUpdated",
"(",
"foundCard",
",",
"function",
"(",
"err",
",",
"card",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"card",
")",
"}",
")",
";",
"Card",
".",
"update",
"(",
"foundCard",
".",
"id",
",",
"card",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"updatedCards",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"updatedCards",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Card",
".",
"afterStripeCustomerCardUpdated",
"(",
"updatedCards",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"card",
")",
"{",
"cb",
"(",
"err",
",",
"card",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook customer.card.updated
|
[
"Stripe",
"Webhook",
"customer",
".",
"card",
".",
"updated"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Card.template.js#L111-L127
|
|
37,893 |
scott-wyatt/sails-stripe
|
templates/Card.template.js
|
function (card, cb) {
Card.destroy(card.id)
.exec(function (err, destroyedCards){
if (err) return cb(err);
if (!destroyedCards) return cb(null, null);
Card.afterStripeCustomerCardDeleted(destroyedCards[0], function(err, card){
cb(null, card);
});
});
}
|
javascript
|
function (card, cb) {
Card.destroy(card.id)
.exec(function (err, destroyedCards){
if (err) return cb(err);
if (!destroyedCards) return cb(null, null);
Card.afterStripeCustomerCardDeleted(destroyedCards[0], function(err, card){
cb(null, card);
});
});
}
|
[
"function",
"(",
"card",
",",
"cb",
")",
"{",
"Card",
".",
"destroy",
"(",
"card",
".",
"id",
")",
".",
"exec",
"(",
"function",
"(",
"err",
",",
"destroyedCards",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"!",
"destroyedCards",
")",
"return",
"cb",
"(",
"null",
",",
"null",
")",
";",
"Card",
".",
"afterStripeCustomerCardDeleted",
"(",
"destroyedCards",
"[",
"0",
"]",
",",
"function",
"(",
"err",
",",
"card",
")",
"{",
"cb",
"(",
"null",
",",
"card",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Stripe Webhook customer.card.deleted
|
[
"Stripe",
"Webhook",
"customer",
".",
"card",
".",
"deleted"
] |
0766bc04a6893a07c842170f37b37200d6771425
|
https://github.com/scott-wyatt/sails-stripe/blob/0766bc04a6893a07c842170f37b37200d6771425/templates/Card.template.js#L135-L145
|
|
37,894 |
contactlab/ikonograph
|
demo/svgxuse.js
|
getOrigin
|
function getOrigin(loc) {
var a;
if (loc.protocol !== undefined) {
a = loc;
} else {
a = document.createElement("a");
a.href = loc;
}
return a.protocol.replace(/:/g, "") + a.host;
}
|
javascript
|
function getOrigin(loc) {
var a;
if (loc.protocol !== undefined) {
a = loc;
} else {
a = document.createElement("a");
a.href = loc;
}
return a.protocol.replace(/:/g, "") + a.host;
}
|
[
"function",
"getOrigin",
"(",
"loc",
")",
"{",
"var",
"a",
";",
"if",
"(",
"loc",
".",
"protocol",
"!==",
"undefined",
")",
"{",
"a",
"=",
"loc",
";",
"}",
"else",
"{",
"a",
"=",
"document",
".",
"createElement",
"(",
"\"a\"",
")",
";",
"a",
".",
"href",
"=",
"loc",
";",
"}",
"return",
"a",
".",
"protocol",
".",
"replace",
"(",
"/",
":",
"/",
"g",
",",
"\"\"",
")",
"+",
"a",
".",
"host",
";",
"}"
] |
In IE 9, cross origin requests can only be sent using XDomainRequest. XDomainRequest would fail if CORS headers are not set. Therefore, XDomainRequest should only be used with cross origin requests.
|
[
"In",
"IE",
"9",
"cross",
"origin",
"requests",
"can",
"only",
"be",
"sent",
"using",
"XDomainRequest",
".",
"XDomainRequest",
"would",
"fail",
"if",
"CORS",
"headers",
"are",
"not",
"set",
".",
"Therefore",
"XDomainRequest",
"should",
"only",
"be",
"used",
"with",
"cross",
"origin",
"requests",
"."
] |
f95a8fa571d3143aa6ad3542b21681a04f5d235e
|
https://github.com/contactlab/ikonograph/blob/f95a8fa571d3143aa6ad3542b21681a04f5d235e/demo/svgxuse.js#L53-L62
|
37,895 |
Fizzadar/selected.js
|
selected/selected.js
|
function(ev) {
var regex = new RegExp(searchBox.value, 'i'),
targets = optionsList.querySelectorAll('li');
for (var i=0; i<targets.length; i++) {
var target = targets[i];
// With multiple active options are never shown in the options list, with single
// we show both the active/inactive options with the active highlighted
if(multiple && target.classList.contains('active'))
continue;
if(!target.textContent.match(regex)) {
target.style.display = 'none';
} else {
target.style.display = 'block';
}
};
searchBox.style.width = ((searchBox.value.length * selected.textWidth) + 25) + 'px';
moveOptionList();
}
|
javascript
|
function(ev) {
var regex = new RegExp(searchBox.value, 'i'),
targets = optionsList.querySelectorAll('li');
for (var i=0; i<targets.length; i++) {
var target = targets[i];
// With multiple active options are never shown in the options list, with single
// we show both the active/inactive options with the active highlighted
if(multiple && target.classList.contains('active'))
continue;
if(!target.textContent.match(regex)) {
target.style.display = 'none';
} else {
target.style.display = 'block';
}
};
searchBox.style.width = ((searchBox.value.length * selected.textWidth) + 25) + 'px';
moveOptionList();
}
|
[
"function",
"(",
"ev",
")",
"{",
"var",
"regex",
"=",
"new",
"RegExp",
"(",
"searchBox",
".",
"value",
",",
"'i'",
")",
",",
"targets",
"=",
"optionsList",
".",
"querySelectorAll",
"(",
"'li'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"targets",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"target",
"=",
"targets",
"[",
"i",
"]",
";",
"// With multiple active options are never shown in the options list, with single",
"// we show both the active/inactive options with the active highlighted",
"if",
"(",
"multiple",
"&&",
"target",
".",
"classList",
".",
"contains",
"(",
"'active'",
")",
")",
"continue",
";",
"if",
"(",
"!",
"target",
".",
"textContent",
".",
"match",
"(",
"regex",
")",
")",
"{",
"target",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"}",
"else",
"{",
"target",
".",
"style",
".",
"display",
"=",
"'block'",
";",
"}",
"}",
";",
"searchBox",
".",
"style",
".",
"width",
"=",
"(",
"(",
"searchBox",
".",
"value",
".",
"length",
"*",
"selected",
".",
"textWidth",
")",
"+",
"25",
")",
"+",
"'px'",
";",
"moveOptionList",
"(",
")",
";",
"}"
] |
Filter options list by searchbox results
|
[
"Filter",
"options",
"list",
"by",
"searchbox",
"results"
] |
0fd1c02ddf0b9e7f1796a88744b3fc8be811bfb3
|
https://github.com/Fizzadar/selected.js/blob/0fd1c02ddf0b9e7f1796a88744b3fc8be811bfb3/selected/selected.js#L70-L91
|
|
37,896 |
Fizzadar/selected.js
|
selected/selected.js
|
function(option, selected) {
var item = document.createElement('li');
item.textContent = option.textContent;
var activate = function() {
// If multiple we just remove this option from the list
if (multiple) {
item.style.display = 'none';
// If single ensure no other options are selected, but keep in the list
} else {
for (var i=0; i<options.length; i++) {
if (options[i]._deselected)
options[i]._deselected.classList.remove('active');
}
}
item.classList.add('active');
}
item.addEventListener('click', function(ev) {
activate();
selectOption(option); // create "selected" option
});
if (selected) {
activate();
}
optionsList.appendChild(item);
option._deselected = item;
}
|
javascript
|
function(option, selected) {
var item = document.createElement('li');
item.textContent = option.textContent;
var activate = function() {
// If multiple we just remove this option from the list
if (multiple) {
item.style.display = 'none';
// If single ensure no other options are selected, but keep in the list
} else {
for (var i=0; i<options.length; i++) {
if (options[i]._deselected)
options[i]._deselected.classList.remove('active');
}
}
item.classList.add('active');
}
item.addEventListener('click', function(ev) {
activate();
selectOption(option); // create "selected" option
});
if (selected) {
activate();
}
optionsList.appendChild(item);
option._deselected = item;
}
|
[
"function",
"(",
"option",
",",
"selected",
")",
"{",
"var",
"item",
"=",
"document",
".",
"createElement",
"(",
"'li'",
")",
";",
"item",
".",
"textContent",
"=",
"option",
".",
"textContent",
";",
"var",
"activate",
"=",
"function",
"(",
")",
"{",
"// If multiple we just remove this option from the list",
"if",
"(",
"multiple",
")",
"{",
"item",
".",
"style",
".",
"display",
"=",
"'none'",
";",
"// If single ensure no other options are selected, but keep in the list",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"options",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"options",
"[",
"i",
"]",
".",
"_deselected",
")",
"options",
"[",
"i",
"]",
".",
"_deselected",
".",
"classList",
".",
"remove",
"(",
"'active'",
")",
";",
"}",
"}",
"item",
".",
"classList",
".",
"add",
"(",
"'active'",
")",
";",
"}",
"item",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"(",
"ev",
")",
"{",
"activate",
"(",
")",
";",
"selectOption",
"(",
"option",
")",
";",
"// create \"selected\" option",
"}",
")",
";",
"if",
"(",
"selected",
")",
"{",
"activate",
"(",
")",
";",
"}",
"optionsList",
".",
"appendChild",
"(",
"item",
")",
";",
"option",
".",
"_deselected",
"=",
"item",
";",
"}"
] |
Create "deselected" option this is here because we _always_ have a full list of items in the optionList basically this means when we deselect something, it will always return to the original list position, rather than appending to the end
|
[
"Create",
"deselected",
"option",
"this",
"is",
"here",
"because",
"we",
"_always_",
"have",
"a",
"full",
"list",
"of",
"items",
"in",
"the",
"optionList",
"basically",
"this",
"means",
"when",
"we",
"deselect",
"something",
"it",
"will",
"always",
"return",
"to",
"the",
"original",
"list",
"position",
"rather",
"than",
"appending",
"to",
"the",
"end"
] |
0fd1c02ddf0b9e7f1796a88744b3fc8be811bfb3
|
https://github.com/Fizzadar/selected.js/blob/0fd1c02ddf0b9e7f1796a88744b3fc8be811bfb3/selected/selected.js#L98-L130
|
|
37,897 |
daffl/connect-injector
|
lib/connect-injector.js
|
function () {
var self = this;
if (typeof this._isIntercepted === 'undefined') {
// Got through all injector objects
each(res.injectors, function (obj) {
if (obj.when(req, res)) {
self._isIntercepted = true;
obj.active = true;
}
});
if (!this._isIntercepted) {
this._isIntercepted = false;
}
debug('first time _interceptCheck ran', this._isIntercepted);
}
return this._isIntercepted;
}
|
javascript
|
function () {
var self = this;
if (typeof this._isIntercepted === 'undefined') {
// Got through all injector objects
each(res.injectors, function (obj) {
if (obj.when(req, res)) {
self._isIntercepted = true;
obj.active = true;
}
});
if (!this._isIntercepted) {
this._isIntercepted = false;
}
debug('first time _interceptCheck ran', this._isIntercepted);
}
return this._isIntercepted;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"typeof",
"this",
".",
"_isIntercepted",
"===",
"'undefined'",
")",
"{",
"// Got through all injector objects",
"each",
"(",
"res",
".",
"injectors",
",",
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"when",
"(",
"req",
",",
"res",
")",
")",
"{",
"self",
".",
"_isIntercepted",
"=",
"true",
";",
"obj",
".",
"active",
"=",
"true",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"this",
".",
"_isIntercepted",
")",
"{",
"this",
".",
"_isIntercepted",
"=",
"false",
";",
"}",
"debug",
"(",
"'first time _interceptCheck ran'",
",",
"this",
".",
"_isIntercepted",
")",
";",
"}",
"return",
"this",
".",
"_isIntercepted",
";",
"}"
] |
Checks if this response should be intercepted
|
[
"Checks",
"if",
"this",
"response",
"should",
"be",
"intercepted"
] |
a23b7c93b60464ca43273c58cba2c07b890124f0
|
https://github.com/daffl/connect-injector/blob/a23b7c93b60464ca43273c58cba2c07b890124f0/lib/connect-injector.js#L42-L59
|
|
37,898 |
daffl/connect-injector
|
lib/connect-injector.js
|
function(status, reasonPhrase, headers) {
var self = this;
each(headers || reasonPhrase, function(value, name) {
self.setHeader(name, value);
});
return this._super(status, typeof reasonPhrase === 'string' ? reasonPhrase : undefined);
}
|
javascript
|
function(status, reasonPhrase, headers) {
var self = this;
each(headers || reasonPhrase, function(value, name) {
self.setHeader(name, value);
});
return this._super(status, typeof reasonPhrase === 'string' ? reasonPhrase : undefined);
}
|
[
"function",
"(",
"status",
",",
"reasonPhrase",
",",
"headers",
")",
"{",
"var",
"self",
"=",
"this",
";",
"each",
"(",
"headers",
"||",
"reasonPhrase",
",",
"function",
"(",
"value",
",",
"name",
")",
"{",
"self",
".",
"setHeader",
"(",
"name",
",",
"value",
")",
";",
"}",
")",
";",
"return",
"this",
".",
"_super",
"(",
"status",
",",
"typeof",
"reasonPhrase",
"===",
"'string'",
"?",
"reasonPhrase",
":",
"undefined",
")",
";",
"}"
] |
Overwrite writeHead since it can also set the headers and we need to override the transfer-encoding
|
[
"Overwrite",
"writeHead",
"since",
"it",
"can",
"also",
"set",
"the",
"headers",
"and",
"we",
"need",
"to",
"override",
"the",
"transfer",
"-",
"encoding"
] |
a23b7c93b60464ca43273c58cba2c07b890124f0
|
https://github.com/daffl/connect-injector/blob/a23b7c93b60464ca43273c58cba2c07b890124f0/lib/connect-injector.js#L74-L82
|
|
37,899 |
daffl/connect-injector
|
lib/connect-injector.js
|
function (chunk, encoding) {
if (this._interceptCheck()) {
if(!this._interceptBuffer) {
debug('initializing _interceptBuffer');
this._interceptBuffer = new WritableStream();
}
return this._interceptBuffer.write(chunk, encoding);
}
return this._super.apply(this, arguments);
}
|
javascript
|
function (chunk, encoding) {
if (this._interceptCheck()) {
if(!this._interceptBuffer) {
debug('initializing _interceptBuffer');
this._interceptBuffer = new WritableStream();
}
return this._interceptBuffer.write(chunk, encoding);
}
return this._super.apply(this, arguments);
}
|
[
"function",
"(",
"chunk",
",",
"encoding",
")",
"{",
"if",
"(",
"this",
".",
"_interceptCheck",
"(",
")",
")",
"{",
"if",
"(",
"!",
"this",
".",
"_interceptBuffer",
")",
"{",
"debug",
"(",
"'initializing _interceptBuffer'",
")",
";",
"this",
".",
"_interceptBuffer",
"=",
"new",
"WritableStream",
"(",
")",
";",
"}",
"return",
"this",
".",
"_interceptBuffer",
".",
"write",
"(",
"chunk",
",",
"encoding",
")",
";",
"}",
"return",
"this",
".",
"_super",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] |
Write into the buffer if this request is intercepted
|
[
"Write",
"into",
"the",
"buffer",
"if",
"this",
"request",
"is",
"intercepted"
] |
a23b7c93b60464ca43273c58cba2c07b890124f0
|
https://github.com/daffl/connect-injector/blob/a23b7c93b60464ca43273c58cba2c07b890124f0/lib/connect-injector.js#L85-L96
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.