id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
56,700 | AndreasMadsen/immortal | lib/executables/daemon.js | function (emit) {
ipc.send({
cmd : 'setup',
emit: emit,
daemon: process.pid,
message: errorBuffer === "" ? null : errorBuffer
});
} | javascript | function (emit) {
ipc.send({
cmd : 'setup',
emit: emit,
daemon: process.pid,
message: errorBuffer === "" ? null : errorBuffer
});
} | [
"function",
"(",
"emit",
")",
"{",
"ipc",
".",
"send",
"(",
"{",
"cmd",
":",
"'setup'",
",",
"emit",
":",
"emit",
",",
"daemon",
":",
"process",
".",
"pid",
",",
"message",
":",
"errorBuffer",
"===",
"\"\"",
"?",
"null",
":",
"errorBuffer",
"}",
")",
";",
"}"
] | this function will setup a new pump as a daemon | [
"this",
"function",
"will",
"setup",
"a",
"new",
"pump",
"as",
"a",
"daemon"
] | c1ab5a4287a543fdfd980604a9e9927d663a9ef2 | https://github.com/AndreasMadsen/immortal/blob/c1ab5a4287a543fdfd980604a9e9927d663a9ef2/lib/executables/daemon.js#L43-L50 |
|
56,701 | overlookmotel/ejs-extra | lib/index.js | resolveObjectName | function resolveObjectName(view){
return cache[view] || (cache[view] = view
.split('/')
.slice(-1)[0]
.split('.')[0]
.replace(/^_/, '')
.replace(/[^a-zA-Z0-9 ]+/g, ' ')
.split(/ +/).map(function(word, i){
return i ? word[0].toUpperCase() + word.substr(1) : word;
}).join(''));
} | javascript | function resolveObjectName(view){
return cache[view] || (cache[view] = view
.split('/')
.slice(-1)[0]
.split('.')[0]
.replace(/^_/, '')
.replace(/[^a-zA-Z0-9 ]+/g, ' ')
.split(/ +/).map(function(word, i){
return i ? word[0].toUpperCase() + word.substr(1) : word;
}).join(''));
} | [
"function",
"resolveObjectName",
"(",
"view",
")",
"{",
"return",
"cache",
"[",
"view",
"]",
"||",
"(",
"cache",
"[",
"view",
"]",
"=",
"view",
".",
"split",
"(",
"'/'",
")",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
".",
"replace",
"(",
"/",
"^_",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"[^a-zA-Z0-9 ]+",
"/",
"g",
",",
"' '",
")",
".",
"split",
"(",
"/",
" +",
"/",
")",
".",
"map",
"(",
"function",
"(",
"word",
",",
"i",
")",
"{",
"return",
"i",
"?",
"word",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"word",
".",
"substr",
"(",
"1",
")",
":",
"word",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
")",
";",
"}"
] | Resolve partial object name from the view path.
Examples:
"user.ejs" becomes "user"
"forum thread.ejs" becomes "forumThread"
"forum/thread/post.ejs" becomes "post"
"blog-post.ejs" becomes "blogPost"
@return {String}
@api private | [
"Resolve",
"partial",
"object",
"name",
"from",
"the",
"view",
"path",
"."
] | 0bda55152b174f1a990f4a04787a41676b1430d1 | https://github.com/overlookmotel/ejs-extra/blob/0bda55152b174f1a990f4a04787a41676b1430d1/lib/index.js#L160-L170 |
56,702 | overlookmotel/ejs-extra | lib/index.js | block | function block(name, html) {
// bound to the blocks object in renderFile
var blk = this[name];
if (!blk) {
// always create, so if we request a
// non-existent block we'll get a new one
blk = this[name] = new Block();
}
if (html) {
blk.append(html);
}
return blk;
} | javascript | function block(name, html) {
// bound to the blocks object in renderFile
var blk = this[name];
if (!blk) {
// always create, so if we request a
// non-existent block we'll get a new one
blk = this[name] = new Block();
}
if (html) {
blk.append(html);
}
return blk;
} | [
"function",
"block",
"(",
"name",
",",
"html",
")",
"{",
"// bound to the blocks object in renderFile",
"var",
"blk",
"=",
"this",
"[",
"name",
"]",
";",
"if",
"(",
"!",
"blk",
")",
"{",
"// always create, so if we request a",
"// non-existent block we'll get a new one",
"blk",
"=",
"this",
"[",
"name",
"]",
"=",
"new",
"Block",
"(",
")",
";",
"}",
"if",
"(",
"html",
")",
"{",
"blk",
".",
"append",
"(",
"html",
")",
";",
"}",
"return",
"blk",
";",
"}"
] | Return the block with the given name, create it if necessary.
Optionally append the given html to the block.
The returned Block can append, prepend or replace the block,
as well as render it when included in a parent template.
@param {String} name
@param {String} html
@return {Block}
@api private | [
"Return",
"the",
"block",
"with",
"the",
"given",
"name",
"create",
"it",
"if",
"necessary",
".",
"Optionally",
"append",
"the",
"given",
"html",
"to",
"the",
"block",
"."
] | 0bda55152b174f1a990f4a04787a41676b1430d1 | https://github.com/overlookmotel/ejs-extra/blob/0bda55152b174f1a990f4a04787a41676b1430d1/lib/index.js#L427-L439 |
56,703 | overlookmotel/ejs-extra | lib/index.js | script | function script(path, type) {
if (path) {
var html = '<script src="'+path+'"'+(type ? 'type="'+type+'"' : '')+'></script>';
if (this.html.indexOf(html) == -1) this.append(html);
}
return this;
} | javascript | function script(path, type) {
if (path) {
var html = '<script src="'+path+'"'+(type ? 'type="'+type+'"' : '')+'></script>';
if (this.html.indexOf(html) == -1) this.append(html);
}
return this;
} | [
"function",
"script",
"(",
"path",
",",
"type",
")",
"{",
"if",
"(",
"path",
")",
"{",
"var",
"html",
"=",
"'<script src=\"'",
"+",
"path",
"+",
"'\"'",
"+",
"(",
"type",
"?",
"'type=\"'",
"+",
"type",
"+",
"'\"'",
":",
"''",
")",
"+",
"'></script>'",
";",
"if",
"(",
"this",
".",
"html",
".",
"indexOf",
"(",
"html",
")",
"==",
"-",
"1",
")",
"this",
".",
"append",
"(",
"html",
")",
";",
"}",
"return",
"this",
";",
"}"
] | bound to scripts Block in renderFile | [
"bound",
"to",
"scripts",
"Block",
"in",
"renderFile"
] | 0bda55152b174f1a990f4a04787a41676b1430d1 | https://github.com/overlookmotel/ejs-extra/blob/0bda55152b174f1a990f4a04787a41676b1430d1/lib/index.js#L442-L448 |
56,704 | overlookmotel/ejs-extra | lib/index.js | stylesheet | function stylesheet(path, media) {
if (path) {
var html = '<link rel="stylesheet" href="'+path+'"'+(media ? 'media="'+media+'"' : '')+' />';
if (this.html.indexOf(html) == -1) this.append(html);
}
return this;
} | javascript | function stylesheet(path, media) {
if (path) {
var html = '<link rel="stylesheet" href="'+path+'"'+(media ? 'media="'+media+'"' : '')+' />';
if (this.html.indexOf(html) == -1) this.append(html);
}
return this;
} | [
"function",
"stylesheet",
"(",
"path",
",",
"media",
")",
"{",
"if",
"(",
"path",
")",
"{",
"var",
"html",
"=",
"'<link rel=\"stylesheet\" href=\"'",
"+",
"path",
"+",
"'\"'",
"+",
"(",
"media",
"?",
"'media=\"'",
"+",
"media",
"+",
"'\"'",
":",
"''",
")",
"+",
"' />'",
";",
"if",
"(",
"this",
".",
"html",
".",
"indexOf",
"(",
"html",
")",
"==",
"-",
"1",
")",
"this",
".",
"append",
"(",
"html",
")",
";",
"}",
"return",
"this",
";",
"}"
] | bound to stylesheets Block in renderFile | [
"bound",
"to",
"stylesheets",
"Block",
"in",
"renderFile"
] | 0bda55152b174f1a990f4a04787a41676b1430d1 | https://github.com/overlookmotel/ejs-extra/blob/0bda55152b174f1a990f4a04787a41676b1430d1/lib/index.js#L451-L457 |
56,705 | Pocketbrain/native-ads-web-ad-library | src/ads/insertAds.js | insertAds | function insertAds(adUnit, ads, adLoadedCallback) {
var adContainers = page.getAdContainers(adUnit);
if (!adContainers.length) {
logger.error("No ad containers could be found. stopping insertion for adUnit " + adUnit.name);
return []; //Ad can't be inserted
}
var adBuilder = new AdBuilder(ads);
var beforeElement;
var insertedAdElements = [];
for (var i = 0; i < adContainers.length; i++) {
var adContainer = adContainers[i];
while ((beforeElement = adContainer.getNextElement()) !== null) {
var adToInsert = adBuilder.createAdUnit(adUnit, adContainer.containerElement);
if (adToInsert === null) {
//we ran out of ads.
break;
}
insertedAdElements.push(adToInsert);
beforeElement.parentNode.insertBefore(adToInsert, beforeElement.nextSibling);
// var elementDisplay = adToInsert.style.display || "block";
//TODO: Why are we defaulting to block here?
// adToInsert.style.display = elementDisplay;
handleImageLoad(adToInsert, adLoadedCallback);
}
}
return insertedAdElements;
} | javascript | function insertAds(adUnit, ads, adLoadedCallback) {
var adContainers = page.getAdContainers(adUnit);
if (!adContainers.length) {
logger.error("No ad containers could be found. stopping insertion for adUnit " + adUnit.name);
return []; //Ad can't be inserted
}
var adBuilder = new AdBuilder(ads);
var beforeElement;
var insertedAdElements = [];
for (var i = 0; i < adContainers.length; i++) {
var adContainer = adContainers[i];
while ((beforeElement = adContainer.getNextElement()) !== null) {
var adToInsert = adBuilder.createAdUnit(adUnit, adContainer.containerElement);
if (adToInsert === null) {
//we ran out of ads.
break;
}
insertedAdElements.push(adToInsert);
beforeElement.parentNode.insertBefore(adToInsert, beforeElement.nextSibling);
// var elementDisplay = adToInsert.style.display || "block";
//TODO: Why are we defaulting to block here?
// adToInsert.style.display = elementDisplay;
handleImageLoad(adToInsert, adLoadedCallback);
}
}
return insertedAdElements;
} | [
"function",
"insertAds",
"(",
"adUnit",
",",
"ads",
",",
"adLoadedCallback",
")",
"{",
"var",
"adContainers",
"=",
"page",
".",
"getAdContainers",
"(",
"adUnit",
")",
";",
"if",
"(",
"!",
"adContainers",
".",
"length",
")",
"{",
"logger",
".",
"error",
"(",
"\"No ad containers could be found. stopping insertion for adUnit \"",
"+",
"adUnit",
".",
"name",
")",
";",
"return",
"[",
"]",
";",
"//Ad can't be inserted",
"}",
"var",
"adBuilder",
"=",
"new",
"AdBuilder",
"(",
"ads",
")",
";",
"var",
"beforeElement",
";",
"var",
"insertedAdElements",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"adContainers",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"adContainer",
"=",
"adContainers",
"[",
"i",
"]",
";",
"while",
"(",
"(",
"beforeElement",
"=",
"adContainer",
".",
"getNextElement",
"(",
")",
")",
"!==",
"null",
")",
"{",
"var",
"adToInsert",
"=",
"adBuilder",
".",
"createAdUnit",
"(",
"adUnit",
",",
"adContainer",
".",
"containerElement",
")",
";",
"if",
"(",
"adToInsert",
"===",
"null",
")",
"{",
"//we ran out of ads.",
"break",
";",
"}",
"insertedAdElements",
".",
"push",
"(",
"adToInsert",
")",
";",
"beforeElement",
".",
"parentNode",
".",
"insertBefore",
"(",
"adToInsert",
",",
"beforeElement",
".",
"nextSibling",
")",
";",
"// var elementDisplay = adToInsert.style.display || \"block\";",
"//TODO: Why are we defaulting to block here?",
"// adToInsert.style.display = elementDisplay;",
"handleImageLoad",
"(",
"adToInsert",
",",
"adLoadedCallback",
")",
";",
"}",
"}",
"return",
"insertedAdElements",
";",
"}"
] | Insert advertisements for the given ad unit on the page
@param adUnit - The ad unit to insert advertisements for
@param ads - Array of ads retrieved from OfferEngine
@param adLoadedCallback - Callback to execute when the ads are fully loaded
@returns {Array} | [
"Insert",
"advertisements",
"for",
"the",
"given",
"ad",
"unit",
"on",
"the",
"page"
] | aafee1c42e0569ee77f334fc2c4eb71eb146957e | https://github.com/Pocketbrain/native-ads-web-ad-library/blob/aafee1c42e0569ee77f334fc2c4eb71eb146957e/src/ads/insertAds.js#L17-L50 |
56,706 | Pocketbrain/native-ads-web-ad-library | src/ads/insertAds.js | handleImageLoad | function handleImageLoad(adElement, adLoadedCallback) {
var adImage = adElement.querySelector("img");
if (adImage) {
(function (adToInsert, adImage) {
adImage.onload = function () {
adLoadedCallback(adToInsert, true);
};
})(adElement, adImage);
} else {
adLoadedCallback(adElement, false);
}
} | javascript | function handleImageLoad(adElement, adLoadedCallback) {
var adImage = adElement.querySelector("img");
if (adImage) {
(function (adToInsert, adImage) {
adImage.onload = function () {
adLoadedCallback(adToInsert, true);
};
})(adElement, adImage);
} else {
adLoadedCallback(adElement, false);
}
} | [
"function",
"handleImageLoad",
"(",
"adElement",
",",
"adLoadedCallback",
")",
"{",
"var",
"adImage",
"=",
"adElement",
".",
"querySelector",
"(",
"\"img\"",
")",
";",
"if",
"(",
"adImage",
")",
"{",
"(",
"function",
"(",
"adToInsert",
",",
"adImage",
")",
"{",
"adImage",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"adLoadedCallback",
"(",
"adToInsert",
",",
"true",
")",
";",
"}",
";",
"}",
")",
"(",
"adElement",
",",
"adImage",
")",
";",
"}",
"else",
"{",
"adLoadedCallback",
"(",
"adElement",
",",
"false",
")",
";",
"}",
"}"
] | Add an event handler to the onload of ad images.
@param adElement - The HTML element of the advertisement
@param adLoadedCallback - Callback to execute when ads are loaded | [
"Add",
"an",
"event",
"handler",
"to",
"the",
"onload",
"of",
"ad",
"images",
"."
] | aafee1c42e0569ee77f334fc2c4eb71eb146957e | https://github.com/Pocketbrain/native-ads-web-ad-library/blob/aafee1c42e0569ee77f334fc2c4eb71eb146957e/src/ads/insertAds.js#L57-L68 |
56,707 | shkuznetsov/machinegun | index.js | function (powder) {
var callback = function (err) {
shooting--;
if (err) {
// Only emit error if a listener exists
// This is mainly to prevent silent errors in promises
if (machinegun.listenerCount('error')) machinegun.emit('error', err);
if (opt.giveUpOnError) machinegun.giveUp(err);
}
trigger();
};
var primer = function () {
var maybeThenable = powder(callback);
if (maybeThenable && (typeof maybeThenable.then == 'function')) {
maybeThenable.then(callback.bind(null, null), function (err) { callback(err || new Error()); });
}
};
this.shoot = function () {
shooting++;
process.nextTick(primer);
};
} | javascript | function (powder) {
var callback = function (err) {
shooting--;
if (err) {
// Only emit error if a listener exists
// This is mainly to prevent silent errors in promises
if (machinegun.listenerCount('error')) machinegun.emit('error', err);
if (opt.giveUpOnError) machinegun.giveUp(err);
}
trigger();
};
var primer = function () {
var maybeThenable = powder(callback);
if (maybeThenable && (typeof maybeThenable.then == 'function')) {
maybeThenable.then(callback.bind(null, null), function (err) { callback(err || new Error()); });
}
};
this.shoot = function () {
shooting++;
process.nextTick(primer);
};
} | [
"function",
"(",
"powder",
")",
"{",
"var",
"callback",
"=",
"function",
"(",
"err",
")",
"{",
"shooting",
"--",
";",
"if",
"(",
"err",
")",
"{",
"// Only emit error if a listener exists\r",
"// This is mainly to prevent silent errors in promises\r",
"if",
"(",
"machinegun",
".",
"listenerCount",
"(",
"'error'",
")",
")",
"machinegun",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"if",
"(",
"opt",
".",
"giveUpOnError",
")",
"machinegun",
".",
"giveUp",
"(",
"err",
")",
";",
"}",
"trigger",
"(",
")",
";",
"}",
";",
"var",
"primer",
"=",
"function",
"(",
")",
"{",
"var",
"maybeThenable",
"=",
"powder",
"(",
"callback",
")",
";",
"if",
"(",
"maybeThenable",
"&&",
"(",
"typeof",
"maybeThenable",
".",
"then",
"==",
"'function'",
")",
")",
"{",
"maybeThenable",
".",
"then",
"(",
"callback",
".",
"bind",
"(",
"null",
",",
"null",
")",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
"||",
"new",
"Error",
"(",
")",
")",
";",
"}",
")",
";",
"}",
"}",
";",
"this",
".",
"shoot",
"=",
"function",
"(",
")",
"{",
"shooting",
"++",
";",
"process",
".",
"nextTick",
"(",
"primer",
")",
";",
"}",
";",
"}"
] | Primer function wrapper class Used mainly to contextualise callback | [
"Primer",
"function",
"wrapper",
"class",
"Used",
"mainly",
"to",
"contextualise",
"callback"
] | a9d342300dca7a7701a7f3954fe63bf88e206634 | https://github.com/shkuznetsov/machinegun/blob/a9d342300dca7a7701a7f3954fe63bf88e206634/index.js#L21-L42 |
|
56,708 | hakovala/node-fse-promise | index.js | callPromise | function callPromise(fn, args) {
return new Promise((resolve, reject) => {
// promisified callback
function callback(err,other) {
// check if the 'err' is boolean, if so then this is a 'exists' callback special case
if (err && (typeof err !== 'boolean')) return reject(err);
// convert arguments to proper array, ignoring error argument
let args = Array.prototype.slice.call(arguments, 1);
// if arguments length is one or more resolve arguments as array,
// otherwise resolve the argument as is.
return resolve(args.length < 2 ? args[0] : args);
}
fn.apply(null, args.concat([callback]));
});
} | javascript | function callPromise(fn, args) {
return new Promise((resolve, reject) => {
// promisified callback
function callback(err,other) {
// check if the 'err' is boolean, if so then this is a 'exists' callback special case
if (err && (typeof err !== 'boolean')) return reject(err);
// convert arguments to proper array, ignoring error argument
let args = Array.prototype.slice.call(arguments, 1);
// if arguments length is one or more resolve arguments as array,
// otherwise resolve the argument as is.
return resolve(args.length < 2 ? args[0] : args);
}
fn.apply(null, args.concat([callback]));
});
} | [
"function",
"callPromise",
"(",
"fn",
",",
"args",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"// promisified callback",
"function",
"callback",
"(",
"err",
",",
"other",
")",
"{",
"// check if the 'err' is boolean, if so then this is a 'exists' callback special case",
"if",
"(",
"err",
"&&",
"(",
"typeof",
"err",
"!==",
"'boolean'",
")",
")",
"return",
"reject",
"(",
"err",
")",
";",
"// convert arguments to proper array, ignoring error argument",
"let",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"// if arguments length is one or more resolve arguments as array,",
"// otherwise resolve the argument as is.",
"return",
"resolve",
"(",
"args",
".",
"length",
"<",
"2",
"?",
"args",
"[",
"0",
"]",
":",
"args",
")",
";",
"}",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
".",
"concat",
"(",
"[",
"callback",
"]",
")",
")",
";",
"}",
")",
";",
"}"
] | Call method with promises | [
"Call",
"method",
"with",
"promises"
] | 0171cd2927f4daad8c33ed99e1e46b53a7e24b90 | https://github.com/hakovala/node-fse-promise/blob/0171cd2927f4daad8c33ed99e1e46b53a7e24b90/index.js#L82-L96 |
56,709 | hakovala/node-fse-promise | index.js | makePromise | function makePromise(fn) {
return function() {
var args = Array.prototype.slice.call(arguments);
if (hasCallback(args)) {
// argument list has callback, so call method with callback
return callCallback(fn, args);
} else {
// no callback, call method with promises
return callPromise(fn, args);
}
}
} | javascript | function makePromise(fn) {
return function() {
var args = Array.prototype.slice.call(arguments);
if (hasCallback(args)) {
// argument list has callback, so call method with callback
return callCallback(fn, args);
} else {
// no callback, call method with promises
return callPromise(fn, args);
}
}
} | [
"function",
"makePromise",
"(",
"fn",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"if",
"(",
"hasCallback",
"(",
"args",
")",
")",
"{",
"// argument list has callback, so call method with callback",
"return",
"callCallback",
"(",
"fn",
",",
"args",
")",
";",
"}",
"else",
"{",
"// no callback, call method with promises",
"return",
"callPromise",
"(",
"fn",
",",
"args",
")",
";",
"}",
"}",
"}"
] | Wrap method to handle both callbacks and promises | [
"Wrap",
"method",
"to",
"handle",
"both",
"callbacks",
"and",
"promises"
] | 0171cd2927f4daad8c33ed99e1e46b53a7e24b90 | https://github.com/hakovala/node-fse-promise/blob/0171cd2927f4daad8c33ed99e1e46b53a7e24b90/index.js#L101-L112 |
56,710 | mheadd/phl-property | index.js | standardizeAddress | function standardizeAddress(address, callback) {
var url = address_url + encodeURIComponent(address) + '?format=json';
request(url, function(err, resp, body) {
var error = resp.statusCode != 200 ? new Error('Unable to standardize address') : err;
callback(error, body);
});
} | javascript | function standardizeAddress(address, callback) {
var url = address_url + encodeURIComponent(address) + '?format=json';
request(url, function(err, resp, body) {
var error = resp.statusCode != 200 ? new Error('Unable to standardize address') : err;
callback(error, body);
});
} | [
"function",
"standardizeAddress",
"(",
"address",
",",
"callback",
")",
"{",
"var",
"url",
"=",
"address_url",
"+",
"encodeURIComponent",
"(",
"address",
")",
"+",
"'?format=json'",
";",
"request",
"(",
"url",
",",
"function",
"(",
"err",
",",
"resp",
",",
"body",
")",
"{",
"var",
"error",
"=",
"resp",
".",
"statusCode",
"!=",
"200",
"?",
"new",
"Error",
"(",
"'Unable to standardize address'",
")",
":",
"err",
";",
"callback",
"(",
"error",
",",
"body",
")",
";",
"}",
")",
";",
"}"
] | Standardize address and location information for a property. | [
"Standardize",
"address",
"and",
"location",
"information",
"for",
"a",
"property",
"."
] | d94abe26cd9ec11a94320ccee42a6abb2e08d49e | https://github.com/mheadd/phl-property/blob/d94abe26cd9ec11a94320ccee42a6abb2e08d49e/index.js#L30-L36 |
56,711 | mheadd/phl-property | index.js | getAddressDetails | function getAddressDetails(body, callback) {
var addresses = JSON.parse(body).addresses
if(addresses.length == 0) {
callback(new Error('No property information for that address'), null);
}
else {
var url = property_url + encodeURIComponent(addresses[0].standardizedAddress);
request(url, function(err, resp, body) {
callback(err, body);
});
}
} | javascript | function getAddressDetails(body, callback) {
var addresses = JSON.parse(body).addresses
if(addresses.length == 0) {
callback(new Error('No property information for that address'), null);
}
else {
var url = property_url + encodeURIComponent(addresses[0].standardizedAddress);
request(url, function(err, resp, body) {
callback(err, body);
});
}
} | [
"function",
"getAddressDetails",
"(",
"body",
",",
"callback",
")",
"{",
"var",
"addresses",
"=",
"JSON",
".",
"parse",
"(",
"body",
")",
".",
"addresses",
"if",
"(",
"addresses",
".",
"length",
"==",
"0",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"'No property information for that address'",
")",
",",
"null",
")",
";",
"}",
"else",
"{",
"var",
"url",
"=",
"property_url",
"+",
"encodeURIComponent",
"(",
"addresses",
"[",
"0",
"]",
".",
"standardizedAddress",
")",
";",
"request",
"(",
"url",
",",
"function",
"(",
"err",
",",
"resp",
",",
"body",
")",
"{",
"callback",
"(",
"err",
",",
"body",
")",
";",
"}",
")",
";",
"}",
"}"
] | Get property details for an address. | [
"Get",
"property",
"details",
"for",
"an",
"address",
"."
] | d94abe26cd9ec11a94320ccee42a6abb2e08d49e | https://github.com/mheadd/phl-property/blob/d94abe26cd9ec11a94320ccee42a6abb2e08d49e/index.js#L39-L50 |
56,712 | verbose/verb-reflinks | index.js | isValidPackageName | function isValidPackageName(name) {
const stats = validateName(name);
return stats.validForNewPackages === true
&& stats.validForOldPackages === true;
} | javascript | function isValidPackageName(name) {
const stats = validateName(name);
return stats.validForNewPackages === true
&& stats.validForOldPackages === true;
} | [
"function",
"isValidPackageName",
"(",
"name",
")",
"{",
"const",
"stats",
"=",
"validateName",
"(",
"name",
")",
";",
"return",
"stats",
".",
"validForNewPackages",
"===",
"true",
"&&",
"stats",
".",
"validForOldPackages",
"===",
"true",
";",
"}"
] | Returns true if the given name is a valid npm package name | [
"Returns",
"true",
"if",
"the",
"given",
"name",
"is",
"a",
"valid",
"npm",
"package",
"name"
] | 89ee1e55a1385d6de03af9af97c28042de4e3b37 | https://github.com/verbose/verb-reflinks/blob/89ee1e55a1385d6de03af9af97c28042de4e3b37/index.js#L124-L128 |
56,713 | Pocketbrain/native-ads-web-ad-library | src/device/deviceDetector.js | isValidPlatform | function isValidPlatform() {
if (appSettings.overrides && appSettings.overrides.platform) {
return true; //If a platform override is set, it's always valid
}
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
} | javascript | function isValidPlatform() {
if (appSettings.overrides && appSettings.overrides.platform) {
return true; //If a platform override is set, it's always valid
}
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
} | [
"function",
"isValidPlatform",
"(",
")",
"{",
"if",
"(",
"appSettings",
".",
"overrides",
"&&",
"appSettings",
".",
"overrides",
".",
"platform",
")",
"{",
"return",
"true",
";",
"//If a platform override is set, it's always valid",
"}",
"return",
"/",
"iPhone|iPad|iPod|Android",
"/",
"i",
".",
"test",
"(",
"navigator",
".",
"userAgent",
")",
";",
"}"
] | Check if the platform the user is currently visiting the page with is valid for
the ad library to run
@returns {boolean} | [
"Check",
"if",
"the",
"platform",
"the",
"user",
"is",
"currently",
"visiting",
"the",
"page",
"with",
"is",
"valid",
"for",
"the",
"ad",
"library",
"to",
"run"
] | aafee1c42e0569ee77f334fc2c4eb71eb146957e | https://github.com/Pocketbrain/native-ads-web-ad-library/blob/aafee1c42e0569ee77f334fc2c4eb71eb146957e/src/device/deviceDetector.js#L14-L19 |
56,714 | Pocketbrain/native-ads-web-ad-library | src/device/deviceDetector.js | detectFormFactor | function detectFormFactor() {
var viewPortWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var displaySettings = appSettings.displaySettings; //convenience variable
var formFactor;
if (viewPortWidth >= displaySettings.mobile.minWidth && viewPortWidth <= displaySettings.mobile.maxWidth) {
formFactor = DeviceEnumerations.formFactor.smartPhone;
} else if (viewPortWidth >= displaySettings.tablet.minWidth && viewPortWidth <= displaySettings.tablet.maxWidth) {
formFactor = DeviceEnumerations.formFactor.tablet;
} else {
formFactor = DeviceEnumerations.formFactor.desktop;
}
return formFactor;
} | javascript | function detectFormFactor() {
var viewPortWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var displaySettings = appSettings.displaySettings; //convenience variable
var formFactor;
if (viewPortWidth >= displaySettings.mobile.minWidth && viewPortWidth <= displaySettings.mobile.maxWidth) {
formFactor = DeviceEnumerations.formFactor.smartPhone;
} else if (viewPortWidth >= displaySettings.tablet.minWidth && viewPortWidth <= displaySettings.tablet.maxWidth) {
formFactor = DeviceEnumerations.formFactor.tablet;
} else {
formFactor = DeviceEnumerations.formFactor.desktop;
}
return formFactor;
} | [
"function",
"detectFormFactor",
"(",
")",
"{",
"var",
"viewPortWidth",
"=",
"Math",
".",
"max",
"(",
"document",
".",
"documentElement",
".",
"clientWidth",
",",
"window",
".",
"innerWidth",
"||",
"0",
")",
";",
"var",
"displaySettings",
"=",
"appSettings",
".",
"displaySettings",
";",
"//convenience variable",
"var",
"formFactor",
";",
"if",
"(",
"viewPortWidth",
">=",
"displaySettings",
".",
"mobile",
".",
"minWidth",
"&&",
"viewPortWidth",
"<=",
"displaySettings",
".",
"mobile",
".",
"maxWidth",
")",
"{",
"formFactor",
"=",
"DeviceEnumerations",
".",
"formFactor",
".",
"smartPhone",
";",
"}",
"else",
"if",
"(",
"viewPortWidth",
">=",
"displaySettings",
".",
"tablet",
".",
"minWidth",
"&&",
"viewPortWidth",
"<=",
"displaySettings",
".",
"tablet",
".",
"maxWidth",
")",
"{",
"formFactor",
"=",
"DeviceEnumerations",
".",
"formFactor",
".",
"tablet",
";",
"}",
"else",
"{",
"formFactor",
"=",
"DeviceEnumerations",
".",
"formFactor",
".",
"desktop",
";",
"}",
"return",
"formFactor",
";",
"}"
] | Detects the device form factor based on the ViewPort and the deviceWidths in AppSettings
The test_old is done based on the viewport, because it is already validated that a device is Android or iOS
@returns {*} the form factor of the device
@private | [
"Detects",
"the",
"device",
"form",
"factor",
"based",
"on",
"the",
"ViewPort",
"and",
"the",
"deviceWidths",
"in",
"AppSettings",
"The",
"test_old",
"is",
"done",
"based",
"on",
"the",
"viewport",
"because",
"it",
"is",
"already",
"validated",
"that",
"a",
"device",
"is",
"Android",
"or",
"iOS"
] | aafee1c42e0569ee77f334fc2c4eb71eb146957e | https://github.com/Pocketbrain/native-ads-web-ad-library/blob/aafee1c42e0569ee77f334fc2c4eb71eb146957e/src/device/deviceDetector.js#L27-L42 |
56,715 | smallhadroncollider/grunt-jspm | tasks/jspm.js | function () {
var pkgJson = grunt.file.readJSON("package.json");
if (pkgJson.jspm && pkgJson.jspm.directories && pkgJson.jspm.directories.baseURL) {
return pkgJson.jspm.directories.baseURL;
}
return "";
} | javascript | function () {
var pkgJson = grunt.file.readJSON("package.json");
if (pkgJson.jspm && pkgJson.jspm.directories && pkgJson.jspm.directories.baseURL) {
return pkgJson.jspm.directories.baseURL;
}
return "";
} | [
"function",
"(",
")",
"{",
"var",
"pkgJson",
"=",
"grunt",
".",
"file",
".",
"readJSON",
"(",
"\"package.json\"",
")",
";",
"if",
"(",
"pkgJson",
".",
"jspm",
"&&",
"pkgJson",
".",
"jspm",
".",
"directories",
"&&",
"pkgJson",
".",
"jspm",
".",
"directories",
".",
"baseURL",
")",
"{",
"return",
"pkgJson",
".",
"jspm",
".",
"directories",
".",
"baseURL",
";",
"}",
"return",
"\"\"",
";",
"}"
] | Geth the JSPM baseURL from package.json | [
"Geth",
"the",
"JSPM",
"baseURL",
"from",
"package",
".",
"json"
] | 45c02eedef0f1a578a379631891e0ef13406786e | https://github.com/smallhadroncollider/grunt-jspm/blob/45c02eedef0f1a578a379631891e0ef13406786e/tasks/jspm.js#L11-L19 |
|
56,716 | apflieger/grunt-csstree | lib/csstree.js | function(treeRoot) {
var stat = fs.statSync(treeRoot);
if (stat.isDirectory()) {
return buildTree(treeRoot);
} else {
throw new Error("path: " + treeRoot + " is not a directory");
}
} | javascript | function(treeRoot) {
var stat = fs.statSync(treeRoot);
if (stat.isDirectory()) {
return buildTree(treeRoot);
} else {
throw new Error("path: " + treeRoot + " is not a directory");
}
} | [
"function",
"(",
"treeRoot",
")",
"{",
"var",
"stat",
"=",
"fs",
".",
"statSync",
"(",
"treeRoot",
")",
";",
"if",
"(",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"return",
"buildTree",
"(",
"treeRoot",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"path: \"",
"+",
"treeRoot",
"+",
"\" is not a directory\"",
")",
";",
"}",
"}"
] | Crawl the given directory and build the tree object model for further use | [
"Crawl",
"the",
"given",
"directory",
"and",
"build",
"the",
"tree",
"object",
"model",
"for",
"further",
"use"
] | a1844eb22acc7359116ab1fa9bf1004a6512a2b2 | https://github.com/apflieger/grunt-csstree/blob/a1844eb22acc7359116ab1fa9bf1004a6512a2b2/lib/csstree.js#L76-L83 |
|
56,717 | apflieger/grunt-csstree | lib/csstree.js | function(tree, options) {
if (!options) {
options = {
ext: '.css',
importFormat: null, // to be initialized just bellow
encoding: 'utf-8'
};
}
if (!options.ext) {
options.ext = '.css';
}
if (!options.importFormat) {
if (options.ext === '.css') {
options.importFormat = function(path) {
return '@import "' + path + '";';
};
} else if (options.ext === '.less') {
options.importFormat = function(path) {
return '@import (less) "' + path + '";';
};
}
}
if (!options.encoding) {
options.encoding = 'utf-8';
}
generate(tree, null, options);
} | javascript | function(tree, options) {
if (!options) {
options = {
ext: '.css',
importFormat: null, // to be initialized just bellow
encoding: 'utf-8'
};
}
if (!options.ext) {
options.ext = '.css';
}
if (!options.importFormat) {
if (options.ext === '.css') {
options.importFormat = function(path) {
return '@import "' + path + '";';
};
} else if (options.ext === '.less') {
options.importFormat = function(path) {
return '@import (less) "' + path + '";';
};
}
}
if (!options.encoding) {
options.encoding = 'utf-8';
}
generate(tree, null, options);
} | [
"function",
"(",
"tree",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"ext",
":",
"'.css'",
",",
"importFormat",
":",
"null",
",",
"// to be initialized just bellow",
"encoding",
":",
"'utf-8'",
"}",
";",
"}",
"if",
"(",
"!",
"options",
".",
"ext",
")",
"{",
"options",
".",
"ext",
"=",
"'.css'",
";",
"}",
"if",
"(",
"!",
"options",
".",
"importFormat",
")",
"{",
"if",
"(",
"options",
".",
"ext",
"===",
"'.css'",
")",
"{",
"options",
".",
"importFormat",
"=",
"function",
"(",
"path",
")",
"{",
"return",
"'@import \"'",
"+",
"path",
"+",
"'\";'",
";",
"}",
";",
"}",
"else",
"if",
"(",
"options",
".",
"ext",
"===",
"'.less'",
")",
"{",
"options",
".",
"importFormat",
"=",
"function",
"(",
"path",
")",
"{",
"return",
"'@import (less) \"'",
"+",
"path",
"+",
"'\";'",
";",
"}",
";",
"}",
"}",
"if",
"(",
"!",
"options",
".",
"encoding",
")",
"{",
"options",
".",
"encoding",
"=",
"'utf-8'",
";",
"}",
"generate",
"(",
"tree",
",",
"null",
",",
"options",
")",
";",
"}"
] | Generate the files that contains @import rules on the given tree | [
"Generate",
"the",
"files",
"that",
"contains"
] | a1844eb22acc7359116ab1fa9bf1004a6512a2b2 | https://github.com/apflieger/grunt-csstree/blob/a1844eb22acc7359116ab1fa9bf1004a6512a2b2/lib/csstree.js#L85-L115 |
|
56,718 | intervolga/bemjson-loader | lib/validate-bemdecl.js | validateBemDecl | function validateBemDecl(bemDecl, fileName) {
let errors = [];
bemDecl.forEach((decl) => {
errors = errors.concat(validateBemDeclItem(decl, fileName));
});
return errors;
} | javascript | function validateBemDecl(bemDecl, fileName) {
let errors = [];
bemDecl.forEach((decl) => {
errors = errors.concat(validateBemDeclItem(decl, fileName));
});
return errors;
} | [
"function",
"validateBemDecl",
"(",
"bemDecl",
",",
"fileName",
")",
"{",
"let",
"errors",
"=",
"[",
"]",
";",
"bemDecl",
".",
"forEach",
"(",
"(",
"decl",
")",
"=>",
"{",
"errors",
"=",
"errors",
".",
"concat",
"(",
"validateBemDeclItem",
"(",
"decl",
",",
"fileName",
")",
")",
";",
"}",
")",
";",
"return",
"errors",
";",
"}"
] | Validate BEM declarations
@param {Array} bemDecl
@param {String} fileName
@return {Array} of validation errors | [
"Validate",
"BEM",
"declarations"
] | c4ff680ee07ab939d400f241859fe608411fd8de | https://github.com/intervolga/bemjson-loader/blob/c4ff680ee07ab939d400f241859fe608411fd8de/lib/validate-bemdecl.js#L8-L16 |
56,719 | intervolga/bemjson-loader | lib/validate-bemdecl.js | validateBemDeclItem | function validateBemDeclItem(decl, fileName) {
let errors = [];
Object.keys(decl).forEach((key) => {
const val = decl[key];
if (val === '[object Object]') {
errors.push(new Error('Error in BemJson ' + fileName +
' produced wrong BemDecl ' + JSON.stringify(decl, null, 2)));
}
});
return errors;
} | javascript | function validateBemDeclItem(decl, fileName) {
let errors = [];
Object.keys(decl).forEach((key) => {
const val = decl[key];
if (val === '[object Object]') {
errors.push(new Error('Error in BemJson ' + fileName +
' produced wrong BemDecl ' + JSON.stringify(decl, null, 2)));
}
});
return errors;
} | [
"function",
"validateBemDeclItem",
"(",
"decl",
",",
"fileName",
")",
"{",
"let",
"errors",
"=",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"decl",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"const",
"val",
"=",
"decl",
"[",
"key",
"]",
";",
"if",
"(",
"val",
"===",
"'[object Object]'",
")",
"{",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"'Error in BemJson '",
"+",
"fileName",
"+",
"' produced wrong BemDecl '",
"+",
"JSON",
".",
"stringify",
"(",
"decl",
",",
"null",
",",
"2",
")",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"errors",
";",
"}"
] | Validate single BEM declaration
@param {Object} decl
@param {String} fileName
@return {Array} of validation errors | [
"Validate",
"single",
"BEM",
"declaration"
] | c4ff680ee07ab939d400f241859fe608411fd8de | https://github.com/intervolga/bemjson-loader/blob/c4ff680ee07ab939d400f241859fe608411fd8de/lib/validate-bemdecl.js#L25-L37 |
56,720 | royriojas/simplessy | compile-less.js | _getToken | function _getToken( /*klass, klass1, klass2*/ ) {
if ( !tokens ) {
throw new Error( 'no tokens found' );
}
var _args = [ ].slice.call( arguments ).join( ' ' ).split( ' ' );
var _result = _args.map( function ( klass ) {
var token = tokens[ klass ];
if ( !token ) {
throw new Error( 'no token found for ' + klass );
}
return token;
} ).join( ' ' );
return _result;
} | javascript | function _getToken( /*klass, klass1, klass2*/ ) {
if ( !tokens ) {
throw new Error( 'no tokens found' );
}
var _args = [ ].slice.call( arguments ).join( ' ' ).split( ' ' );
var _result = _args.map( function ( klass ) {
var token = tokens[ klass ];
if ( !token ) {
throw new Error( 'no token found for ' + klass );
}
return token;
} ).join( ' ' );
return _result;
} | [
"function",
"_getToken",
"(",
"/*klass, klass1, klass2*/",
")",
"{",
"if",
"(",
"!",
"tokens",
")",
"{",
"throw",
"new",
"Error",
"(",
"'no tokens found'",
")",
";",
"}",
"var",
"_args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
".",
"join",
"(",
"' '",
")",
".",
"split",
"(",
"' '",
")",
";",
"var",
"_result",
"=",
"_args",
".",
"map",
"(",
"function",
"(",
"klass",
")",
"{",
"var",
"token",
"=",
"tokens",
"[",
"klass",
"]",
";",
"if",
"(",
"!",
"token",
")",
"{",
"throw",
"new",
"Error",
"(",
"'no token found for '",
"+",
"klass",
")",
";",
"}",
"return",
"token",
";",
"}",
")",
".",
"join",
"(",
"' '",
")",
";",
"return",
"_result",
";",
"}"
] | be careful here, this function is defined like this for ease of use, but this is going to actually be serialized inside the output of the transform so tokens inside this function, refer to the tokens variable declared in the transformed code | [
"be",
"careful",
"here",
"this",
"function",
"is",
"defined",
"like",
"this",
"for",
"ease",
"of",
"use",
"but",
"this",
"is",
"going",
"to",
"actually",
"be",
"serialized",
"inside",
"the",
"output",
"of",
"the",
"transform",
"so",
"tokens",
"inside",
"this",
"function",
"refer",
"to",
"the",
"tokens",
"variable",
"declared",
"in",
"the",
"transformed",
"code"
] | ac6c7af664c846bcfb23099ca5f6841335f833ae | https://github.com/royriojas/simplessy/blob/ac6c7af664c846bcfb23099ca5f6841335f833ae/compile-less.js#L58-L76 |
56,721 | Chapabu/gulp-holograph | src/index.js | handleBuffer | function handleBuffer (file, encoding, cb) {
const config = configParser(String(file.contents));
holograph.holograph(config);
return cb(null, file);
} | javascript | function handleBuffer (file, encoding, cb) {
const config = configParser(String(file.contents));
holograph.holograph(config);
return cb(null, file);
} | [
"function",
"handleBuffer",
"(",
"file",
",",
"encoding",
",",
"cb",
")",
"{",
"const",
"config",
"=",
"configParser",
"(",
"String",
"(",
"file",
".",
"contents",
")",
")",
";",
"holograph",
".",
"holograph",
"(",
"config",
")",
";",
"return",
"cb",
"(",
"null",
",",
"file",
")",
";",
"}"
] | Run Hologram when given a buffer.
@param {Object} file A Vinyl file.
@param {String} encoding The file encoding.
@param {Function} cb Called after hologram has run.
@returns {Function} Executed callback. | [
"Run",
"Hologram",
"when",
"given",
"a",
"buffer",
"."
] | 182dc177efd593956abf31d3a402f2d02daa95a5 | https://github.com/Chapabu/gulp-holograph/blob/182dc177efd593956abf31d3a402f2d02daa95a5/src/index.js#L20-L24 |
56,722 | Chapabu/gulp-holograph | src/index.js | handleStream | function handleStream (file, encoding, cb) {
let config = '';
file.contents.on('data', chunk => {
config += chunk;
});
file.contents.on('end', () => {
config = configParser(config);
holograph.holograph(config);
return cb(null, file);
});
} | javascript | function handleStream (file, encoding, cb) {
let config = '';
file.contents.on('data', chunk => {
config += chunk;
});
file.contents.on('end', () => {
config = configParser(config);
holograph.holograph(config);
return cb(null, file);
});
} | [
"function",
"handleStream",
"(",
"file",
",",
"encoding",
",",
"cb",
")",
"{",
"let",
"config",
"=",
"''",
";",
"file",
".",
"contents",
".",
"on",
"(",
"'data'",
",",
"chunk",
"=>",
"{",
"config",
"+=",
"chunk",
";",
"}",
")",
";",
"file",
".",
"contents",
".",
"on",
"(",
"'end'",
",",
"(",
")",
"=>",
"{",
"config",
"=",
"configParser",
"(",
"config",
")",
";",
"holograph",
".",
"holograph",
"(",
"config",
")",
";",
"return",
"cb",
"(",
"null",
",",
"file",
")",
";",
"}",
")",
";",
"}"
] | Run Hologram when given a stream.
@param {Object} file A Vinyl file.
@param {String} encoding The file encoding.
@param {Function} cb Called after hologram has run.
@returns {Function} Executed callback. | [
"Run",
"Hologram",
"when",
"given",
"a",
"stream",
"."
] | 182dc177efd593956abf31d3a402f2d02daa95a5 | https://github.com/Chapabu/gulp-holograph/blob/182dc177efd593956abf31d3a402f2d02daa95a5/src/index.js#L34-L48 |
56,723 | Chapabu/gulp-holograph | src/index.js | gulpHolograph | function gulpHolograph () {
return through.obj(function (file, encoding, cb) {
// Handle any non-supported types.
// This covers directories and symlinks as well, as they have to be null.
if (file.isNull()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'No file contents.'));
}
// Handle buffers.
if (file.isBuffer()) {
handleBuffer(file, encoding, cb);
}
// Handle streams.
if (file.isStream()) {
handleStream(file, encoding, cb);
}
});
} | javascript | function gulpHolograph () {
return through.obj(function (file, encoding, cb) {
// Handle any non-supported types.
// This covers directories and symlinks as well, as they have to be null.
if (file.isNull()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'No file contents.'));
}
// Handle buffers.
if (file.isBuffer()) {
handleBuffer(file, encoding, cb);
}
// Handle streams.
if (file.isStream()) {
handleStream(file, encoding, cb);
}
});
} | [
"function",
"gulpHolograph",
"(",
")",
"{",
"return",
"through",
".",
"obj",
"(",
"function",
"(",
"file",
",",
"encoding",
",",
"cb",
")",
"{",
"// Handle any non-supported types.",
"// This covers directories and symlinks as well, as they have to be null.",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"'No file contents.'",
")",
")",
";",
"}",
"// Handle buffers.",
"if",
"(",
"file",
".",
"isBuffer",
"(",
")",
")",
"{",
"handleBuffer",
"(",
"file",
",",
"encoding",
",",
"cb",
")",
";",
"}",
"// Handle streams.",
"if",
"(",
"file",
".",
"isStream",
"(",
")",
")",
"{",
"handleStream",
"(",
"file",
",",
"encoding",
",",
"cb",
")",
";",
"}",
"}",
")",
";",
"}"
] | The actual plugin. Runs Holograph with a provided config file.
@returns {Object} A through2 stream. | [
"The",
"actual",
"plugin",
".",
"Runs",
"Holograph",
"with",
"a",
"provided",
"config",
"file",
"."
] | 182dc177efd593956abf31d3a402f2d02daa95a5 | https://github.com/Chapabu/gulp-holograph/blob/182dc177efd593956abf31d3a402f2d02daa95a5/src/index.js#L55-L77 |
56,724 | ianmuninio/jmodel | lib/error.js | JModelError | function JModelError(obj) {
this.message = obj['message'];
this.propertyName = obj['propertyName'];
Error.call(this);
Error.captureStackTrace(this, this.constructor);
} | javascript | function JModelError(obj) {
this.message = obj['message'];
this.propertyName = obj['propertyName'];
Error.call(this);
Error.captureStackTrace(this, this.constructor);
} | [
"function",
"JModelError",
"(",
"obj",
")",
"{",
"this",
".",
"message",
"=",
"obj",
"[",
"'message'",
"]",
";",
"this",
".",
"propertyName",
"=",
"obj",
"[",
"'propertyName'",
"]",
";",
"Error",
".",
"call",
"(",
"this",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"}"
] | JModel Error Class
@param {Object} obj
@returns {JModelError} | [
"JModel",
"Error",
"Class"
] | c118bfc46596f59445604acc43b01ad2b04c31ef | https://github.com/ianmuninio/jmodel/blob/c118bfc46596f59445604acc43b01ad2b04c31ef/lib/error.js#L14-L20 |
56,725 | weisjohn/jsonload | index.js | normalize | function normalize(filepath) {
// resolve to an absolute ppath
if (!path.isAbsolute || !path.isAbsolute(filepath))
filepath = path.resolve(path.dirname(module.parent.filename), filepath);
// tack .json on the end if need be
if (!/\.json$/.test(filepath))
filepath = filepath + '.json';
return filepath;
} | javascript | function normalize(filepath) {
// resolve to an absolute ppath
if (!path.isAbsolute || !path.isAbsolute(filepath))
filepath = path.resolve(path.dirname(module.parent.filename), filepath);
// tack .json on the end if need be
if (!/\.json$/.test(filepath))
filepath = filepath + '.json';
return filepath;
} | [
"function",
"normalize",
"(",
"filepath",
")",
"{",
"// resolve to an absolute ppath",
"if",
"(",
"!",
"path",
".",
"isAbsolute",
"||",
"!",
"path",
".",
"isAbsolute",
"(",
"filepath",
")",
")",
"filepath",
"=",
"path",
".",
"resolve",
"(",
"path",
".",
"dirname",
"(",
"module",
".",
"parent",
".",
"filename",
")",
",",
"filepath",
")",
";",
"// tack .json on the end if need be",
"if",
"(",
"!",
"/",
"\\.json$",
"/",
".",
"test",
"(",
"filepath",
")",
")",
"filepath",
"=",
"filepath",
"+",
"'.json'",
";",
"return",
"filepath",
";",
"}"
] | clean up paths for convenient loading | [
"clean",
"up",
"paths",
"for",
"convenient",
"loading"
] | 53ad101bc32c766c75bf93616a805ab67edaa9ef | https://github.com/weisjohn/jsonload/blob/53ad101bc32c766c75bf93616a805ab67edaa9ef/index.js#L6-L17 |
56,726 | weisjohn/jsonload | index.js | parse | function parse(contents, retained, parser) {
var errors = [], data = [], lines = 0;
// optional parser
if (!parser) parser = JSON;
// process each line of the file
contents.toString().split('\n').forEach(function(line) {
if (!line) return;
lines++;
try {
data.push(parser.parse(line));
} catch (e) {
e.line = line;
errors.push(e);
}
});
// if no errors/data, don't return an empty array
var ret = {};
if (errors.length) ret.errors = errors;
if (data.length) ret.data = data;
// if every line failed, probably not line-delimited
if (errors.length == lines) ret.errors = retained;
return ret;
} | javascript | function parse(contents, retained, parser) {
var errors = [], data = [], lines = 0;
// optional parser
if (!parser) parser = JSON;
// process each line of the file
contents.toString().split('\n').forEach(function(line) {
if (!line) return;
lines++;
try {
data.push(parser.parse(line));
} catch (e) {
e.line = line;
errors.push(e);
}
});
// if no errors/data, don't return an empty array
var ret = {};
if (errors.length) ret.errors = errors;
if (data.length) ret.data = data;
// if every line failed, probably not line-delimited
if (errors.length == lines) ret.errors = retained;
return ret;
} | [
"function",
"parse",
"(",
"contents",
",",
"retained",
",",
"parser",
")",
"{",
"var",
"errors",
"=",
"[",
"]",
",",
"data",
"=",
"[",
"]",
",",
"lines",
"=",
"0",
";",
"// optional parser",
"if",
"(",
"!",
"parser",
")",
"parser",
"=",
"JSON",
";",
"// process each line of the file",
"contents",
".",
"toString",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
".",
"forEach",
"(",
"function",
"(",
"line",
")",
"{",
"if",
"(",
"!",
"line",
")",
"return",
";",
"lines",
"++",
";",
"try",
"{",
"data",
".",
"push",
"(",
"parser",
".",
"parse",
"(",
"line",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"e",
".",
"line",
"=",
"line",
";",
"errors",
".",
"push",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"// if no errors/data, don't return an empty array",
"var",
"ret",
"=",
"{",
"}",
";",
"if",
"(",
"errors",
".",
"length",
")",
"ret",
".",
"errors",
"=",
"errors",
";",
"if",
"(",
"data",
".",
"length",
")",
"ret",
".",
"data",
"=",
"data",
";",
"// if every line failed, probably not line-delimited",
"if",
"(",
"errors",
".",
"length",
"==",
"lines",
")",
"ret",
".",
"errors",
"=",
"retained",
";",
"return",
"ret",
";",
"}"
] | process line-delimited files | [
"process",
"line",
"-",
"delimited",
"files"
] | 53ad101bc32c766c75bf93616a805ab67edaa9ef | https://github.com/weisjohn/jsonload/blob/53ad101bc32c766c75bf93616a805ab67edaa9ef/index.js#L20-L47 |
56,727 | AgronKabashi/trastpiler | lib/trastpiler.js | createTranspiler | function createTranspiler ({ mappers = {}, initialScopeData } = {}) {
const config = {
scope: createScope(initialScopeData),
mappers
};
return (config.decoratedTranspile = transpile.bind(null, config));
} | javascript | function createTranspiler ({ mappers = {}, initialScopeData } = {}) {
const config = {
scope: createScope(initialScopeData),
mappers
};
return (config.decoratedTranspile = transpile.bind(null, config));
} | [
"function",
"createTranspiler",
"(",
"{",
"mappers",
"=",
"{",
"}",
",",
"initialScopeData",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"config",
"=",
"{",
"scope",
":",
"createScope",
"(",
"initialScopeData",
")",
",",
"mappers",
"}",
";",
"return",
"(",
"config",
".",
"decoratedTranspile",
"=",
"transpile",
".",
"bind",
"(",
"null",
",",
"config",
")",
")",
";",
"}"
] | eslint-disable-line no-use-before-define | [
"eslint",
"-",
"disable",
"-",
"line",
"no",
"-",
"use",
"-",
"before",
"-",
"define"
] | 6bbebda1290aa2aaf9dfe6c286777aa20bfe56c5 | https://github.com/AgronKabashi/trastpiler/blob/6bbebda1290aa2aaf9dfe6c286777aa20bfe56c5/lib/trastpiler.js#L53-L60 |
56,728 | ltoussaint/node-bootstrap-core | routers/matchPath.js | MatchPath | function MatchPath() {
var defaultAction = 'welcome',
defaultMethod = 'index';
/**
* Resolve uri
* @param request
* @returns {*}
*/
this.resolve = function (request) {
var action = defaultAction;
var method = defaultMethod;
if ('/' != request.url) {
var uriComponents = request.url.split('?')[0].substr(1).split('/');
if (uriComponents.length > 1) {
method = uriComponents.pop();
action = uriComponents.join('/');
} else if (uriComponents.length == 1) {
action = uriComponents[0];
}
}
return {
action: action,
method: method,
arguments: []
};
};
/**
* Set default action
* @param action
* @returns {MatchPath}
*/
this.setDefaultAction = function (action) {
defaultAction = action;
return this;
};
/**
* Set default method
* @param method
* @returns {MatchPath}
*/
this.setDefaultMethod = function (method) {
defaultMethod = method;
return this;
};
return this;
} | javascript | function MatchPath() {
var defaultAction = 'welcome',
defaultMethod = 'index';
/**
* Resolve uri
* @param request
* @returns {*}
*/
this.resolve = function (request) {
var action = defaultAction;
var method = defaultMethod;
if ('/' != request.url) {
var uriComponents = request.url.split('?')[0].substr(1).split('/');
if (uriComponents.length > 1) {
method = uriComponents.pop();
action = uriComponents.join('/');
} else if (uriComponents.length == 1) {
action = uriComponents[0];
}
}
return {
action: action,
method: method,
arguments: []
};
};
/**
* Set default action
* @param action
* @returns {MatchPath}
*/
this.setDefaultAction = function (action) {
defaultAction = action;
return this;
};
/**
* Set default method
* @param method
* @returns {MatchPath}
*/
this.setDefaultMethod = function (method) {
defaultMethod = method;
return this;
};
return this;
} | [
"function",
"MatchPath",
"(",
")",
"{",
"var",
"defaultAction",
"=",
"'welcome'",
",",
"defaultMethod",
"=",
"'index'",
";",
"/**\n * Resolve uri\n * @param request\n * @returns {*}\n */",
"this",
".",
"resolve",
"=",
"function",
"(",
"request",
")",
"{",
"var",
"action",
"=",
"defaultAction",
";",
"var",
"method",
"=",
"defaultMethod",
";",
"if",
"(",
"'/'",
"!=",
"request",
".",
"url",
")",
"{",
"var",
"uriComponents",
"=",
"request",
".",
"url",
".",
"split",
"(",
"'?'",
")",
"[",
"0",
"]",
".",
"substr",
"(",
"1",
")",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"uriComponents",
".",
"length",
">",
"1",
")",
"{",
"method",
"=",
"uriComponents",
".",
"pop",
"(",
")",
";",
"action",
"=",
"uriComponents",
".",
"join",
"(",
"'/'",
")",
";",
"}",
"else",
"if",
"(",
"uriComponents",
".",
"length",
"==",
"1",
")",
"{",
"action",
"=",
"uriComponents",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"{",
"action",
":",
"action",
",",
"method",
":",
"method",
",",
"arguments",
":",
"[",
"]",
"}",
";",
"}",
";",
"/**\n * Set default action\n * @param action\n * @returns {MatchPath}\n */",
"this",
".",
"setDefaultAction",
"=",
"function",
"(",
"action",
")",
"{",
"defaultAction",
"=",
"action",
";",
"return",
"this",
";",
"}",
";",
"/**\n * Set default method\n * @param method\n * @returns {MatchPath}\n */",
"this",
".",
"setDefaultMethod",
"=",
"function",
"(",
"method",
")",
"{",
"defaultMethod",
"=",
"method",
";",
"return",
"this",
";",
"}",
";",
"return",
"this",
";",
"}"
] | Simple router which will match url pathname with an action
@returns {MatchPath}
@constructor | [
"Simple",
"router",
"which",
"will",
"match",
"url",
"pathname",
"with",
"an",
"action"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/routers/matchPath.js#L8-L60 |
56,729 | twolfson/grunt-init-init | src/init/resolveTemplateFiles.js | resolveTemplateFiles | function resolveTemplateFiles(name) {
// Create paths for resolving
var customFile = customDir + '/' + name + '.js',
customTemplateDir = customDir + '/' + name + '/**/*',
stdFile = stdDir + '/' + name + '.js',
stdTemplateDir = stdDir + '/' + name + '/**/*';
// Grab any and all files
var customFiles = expandFiles(customFile).concat(expandFiles(customTemplateDir)),
stdFiles = expandFiles(stdFile).concat(expandFiles(stdTemplateDir));
// Generate a hash of files
var fileMap = {};
// Iterate over the customFiles
customFiles.forEach(function (file) {
// Extract the relative path of the file
var relPath = path.relative(customDir, file);
// Save the relative path
fileMap[relPath] = file;
});
// Iterate over the stdFiles
stdFiles.forEach(function (file) {
// Extract the relative path of the file
var relPath = path.relative(stdDir, file),
overrideExists = fileMap[relPath];
// If it does not exist, save it
if (!overrideExists) {
fileMap[relPath] = file;
}
});
// Return the fileMap
return fileMap;
} | javascript | function resolveTemplateFiles(name) {
// Create paths for resolving
var customFile = customDir + '/' + name + '.js',
customTemplateDir = customDir + '/' + name + '/**/*',
stdFile = stdDir + '/' + name + '.js',
stdTemplateDir = stdDir + '/' + name + '/**/*';
// Grab any and all files
var customFiles = expandFiles(customFile).concat(expandFiles(customTemplateDir)),
stdFiles = expandFiles(stdFile).concat(expandFiles(stdTemplateDir));
// Generate a hash of files
var fileMap = {};
// Iterate over the customFiles
customFiles.forEach(function (file) {
// Extract the relative path of the file
var relPath = path.relative(customDir, file);
// Save the relative path
fileMap[relPath] = file;
});
// Iterate over the stdFiles
stdFiles.forEach(function (file) {
// Extract the relative path of the file
var relPath = path.relative(stdDir, file),
overrideExists = fileMap[relPath];
// If it does not exist, save it
if (!overrideExists) {
fileMap[relPath] = file;
}
});
// Return the fileMap
return fileMap;
} | [
"function",
"resolveTemplateFiles",
"(",
"name",
")",
"{",
"// Create paths for resolving",
"var",
"customFile",
"=",
"customDir",
"+",
"'/'",
"+",
"name",
"+",
"'.js'",
",",
"customTemplateDir",
"=",
"customDir",
"+",
"'/'",
"+",
"name",
"+",
"'/**/*'",
",",
"stdFile",
"=",
"stdDir",
"+",
"'/'",
"+",
"name",
"+",
"'.js'",
",",
"stdTemplateDir",
"=",
"stdDir",
"+",
"'/'",
"+",
"name",
"+",
"'/**/*'",
";",
"// Grab any and all files",
"var",
"customFiles",
"=",
"expandFiles",
"(",
"customFile",
")",
".",
"concat",
"(",
"expandFiles",
"(",
"customTemplateDir",
")",
")",
",",
"stdFiles",
"=",
"expandFiles",
"(",
"stdFile",
")",
".",
"concat",
"(",
"expandFiles",
"(",
"stdTemplateDir",
")",
")",
";",
"// Generate a hash of files",
"var",
"fileMap",
"=",
"{",
"}",
";",
"// Iterate over the customFiles",
"customFiles",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"// Extract the relative path of the file",
"var",
"relPath",
"=",
"path",
".",
"relative",
"(",
"customDir",
",",
"file",
")",
";",
"// Save the relative path",
"fileMap",
"[",
"relPath",
"]",
"=",
"file",
";",
"}",
")",
";",
"// Iterate over the stdFiles",
"stdFiles",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"// Extract the relative path of the file",
"var",
"relPath",
"=",
"path",
".",
"relative",
"(",
"stdDir",
",",
"file",
")",
",",
"overrideExists",
"=",
"fileMap",
"[",
"relPath",
"]",
";",
"// If it does not exist, save it",
"if",
"(",
"!",
"overrideExists",
")",
"{",
"fileMap",
"[",
"relPath",
"]",
"=",
"file",
";",
"}",
"}",
")",
";",
"// Return the fileMap",
"return",
"fileMap",
";",
"}"
] | Define a helper to find custom and standard template files | [
"Define",
"a",
"helper",
"to",
"find",
"custom",
"and",
"standard",
"template",
"files"
] | 2dd3d063f06213c4ca086ec5b220759067ecd567 | https://github.com/twolfson/grunt-init-init/blob/2dd3d063f06213c4ca086ec5b220759067ecd567/src/init/resolveTemplateFiles.js#L9-L46 |
56,730 | pinyin/outline | vendor/transformation-matrix/rotate.js | rotate | function rotate(angle, cx, cy) {
var cosAngle = cos(angle);
var sinAngle = sin(angle);
var rotationMatrix = {
a: cosAngle, c: -sinAngle, e: 0,
b: sinAngle, d: cosAngle, f: 0
};
if ((0, _utils.isUndefined)(cx) || (0, _utils.isUndefined)(cy)) {
return rotationMatrix;
}
return (0, _transform.transform)([(0, _translate.translate)(cx, cy), rotationMatrix, (0, _translate.translate)(-cx, -cy)]);
} | javascript | function rotate(angle, cx, cy) {
var cosAngle = cos(angle);
var sinAngle = sin(angle);
var rotationMatrix = {
a: cosAngle, c: -sinAngle, e: 0,
b: sinAngle, d: cosAngle, f: 0
};
if ((0, _utils.isUndefined)(cx) || (0, _utils.isUndefined)(cy)) {
return rotationMatrix;
}
return (0, _transform.transform)([(0, _translate.translate)(cx, cy), rotationMatrix, (0, _translate.translate)(-cx, -cy)]);
} | [
"function",
"rotate",
"(",
"angle",
",",
"cx",
",",
"cy",
")",
"{",
"var",
"cosAngle",
"=",
"cos",
"(",
"angle",
")",
";",
"var",
"sinAngle",
"=",
"sin",
"(",
"angle",
")",
";",
"var",
"rotationMatrix",
"=",
"{",
"a",
":",
"cosAngle",
",",
"c",
":",
"-",
"sinAngle",
",",
"e",
":",
"0",
",",
"b",
":",
"sinAngle",
",",
"d",
":",
"cosAngle",
",",
"f",
":",
"0",
"}",
";",
"if",
"(",
"(",
"0",
",",
"_utils",
".",
"isUndefined",
")",
"(",
"cx",
")",
"||",
"(",
"0",
",",
"_utils",
".",
"isUndefined",
")",
"(",
"cy",
")",
")",
"{",
"return",
"rotationMatrix",
";",
"}",
"return",
"(",
"0",
",",
"_transform",
".",
"transform",
")",
"(",
"[",
"(",
"0",
",",
"_translate",
".",
"translate",
")",
"(",
"cx",
",",
"cy",
")",
",",
"rotationMatrix",
",",
"(",
"0",
",",
"_translate",
".",
"translate",
")",
"(",
"-",
"cx",
",",
"-",
"cy",
")",
"]",
")",
";",
"}"
] | Calculate a rotation matrix
@param angle Angle in radians
@param [cx] If (cx,cy) are supplied the rotate is about this point
@param [cy] If (cx,cy) are supplied the rotate is about this point
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix * | [
"Calculate",
"a",
"rotation",
"matrix"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/rotate.js#L27-L39 |
56,731 | pinyin/outline | vendor/transformation-matrix/rotate.js | rotateDEG | function rotateDEG(angle) {
var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
return rotate(angle * PI / 180, cx, cy);
} | javascript | function rotateDEG(angle) {
var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
return rotate(angle * PI / 180, cx, cy);
} | [
"function",
"rotateDEG",
"(",
"angle",
")",
"{",
"var",
"cx",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"undefined",
";",
"var",
"cy",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"undefined",
";",
"return",
"rotate",
"(",
"angle",
"*",
"PI",
"/",
"180",
",",
"cx",
",",
"cy",
")",
";",
"}"
] | Calculate a rotation matrix with a DEG angle
@param angle Angle in degree
@param [cx] If (cx,cy) are supplied the rotate is about this point
@param [cy] If (cx,cy) are supplied the rotate is about this point
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"rotation",
"matrix",
"with",
"a",
"DEG",
"angle"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/rotate.js#L48-L53 |
56,732 | vnykmshr/proc-utils | lib/proc.js | reload | function reload(args) {
if (args !== undefined) {
if (args.l !== undefined) {
fs.closeSync(1);
fs.openSync(args.l, 'a+');
}
if (args.e !== undefined) {
fs.closeSync(2);
fs.openSync(args.e, 'a+');
}
}
} | javascript | function reload(args) {
if (args !== undefined) {
if (args.l !== undefined) {
fs.closeSync(1);
fs.openSync(args.l, 'a+');
}
if (args.e !== undefined) {
fs.closeSync(2);
fs.openSync(args.e, 'a+');
}
}
} | [
"function",
"reload",
"(",
"args",
")",
"{",
"if",
"(",
"args",
"!==",
"undefined",
")",
"{",
"if",
"(",
"args",
".",
"l",
"!==",
"undefined",
")",
"{",
"fs",
".",
"closeSync",
"(",
"1",
")",
";",
"fs",
".",
"openSync",
"(",
"args",
".",
"l",
",",
"'a+'",
")",
";",
"}",
"if",
"(",
"args",
".",
"e",
"!==",
"undefined",
")",
"{",
"fs",
".",
"closeSync",
"(",
"2",
")",
";",
"fs",
".",
"openSync",
"(",
"args",
".",
"e",
",",
"'a+'",
")",
";",
"}",
"}",
"}"
] | Close the standard output and error descriptors
and redirect them to the specified files provided
in the argument | [
"Close",
"the",
"standard",
"output",
"and",
"error",
"descriptors",
"and",
"redirect",
"them",
"to",
"the",
"specified",
"files",
"provided",
"in",
"the",
"argument"
] | cae3b96a9cd6689a3e5cfedfefef3718c1e4839c | https://github.com/vnykmshr/proc-utils/blob/cae3b96a9cd6689a3e5cfedfefef3718c1e4839c/lib/proc.js#L17-L29 |
56,733 | vnykmshr/proc-utils | lib/proc.js | setupHandlers | function setupHandlers() {
function terminate(err) {
util.log('Uncaught Error: ' + err.message);
console.log(err.stack);
if (proc.shutdownHook) {
proc.shutdownHook(err, gracefulShutdown);
}
}
process.on('uncaughtException', terminate);
process.addListener('SIGINT', gracefulShutdown);
process.addListener('SIGHUP', function () {
util.log('RECIEVED SIGHUP signal, reloading log files...');
reload(argv);
});
} | javascript | function setupHandlers() {
function terminate(err) {
util.log('Uncaught Error: ' + err.message);
console.log(err.stack);
if (proc.shutdownHook) {
proc.shutdownHook(err, gracefulShutdown);
}
}
process.on('uncaughtException', terminate);
process.addListener('SIGINT', gracefulShutdown);
process.addListener('SIGHUP', function () {
util.log('RECIEVED SIGHUP signal, reloading log files...');
reload(argv);
});
} | [
"function",
"setupHandlers",
"(",
")",
"{",
"function",
"terminate",
"(",
"err",
")",
"{",
"util",
".",
"log",
"(",
"'Uncaught Error: '",
"+",
"err",
".",
"message",
")",
";",
"console",
".",
"log",
"(",
"err",
".",
"stack",
")",
";",
"if",
"(",
"proc",
".",
"shutdownHook",
")",
"{",
"proc",
".",
"shutdownHook",
"(",
"err",
",",
"gracefulShutdown",
")",
";",
"}",
"}",
"process",
".",
"on",
"(",
"'uncaughtException'",
",",
"terminate",
")",
";",
"process",
".",
"addListener",
"(",
"'SIGINT'",
",",
"gracefulShutdown",
")",
";",
"process",
".",
"addListener",
"(",
"'SIGHUP'",
",",
"function",
"(",
")",
"{",
"util",
".",
"log",
"(",
"'RECIEVED SIGHUP signal, reloading log files...'",
")",
";",
"reload",
"(",
"argv",
")",
";",
"}",
")",
";",
"}"
] | Reopen logfiles on SIGHUP
Exit on uncaught exceptions | [
"Reopen",
"logfiles",
"on",
"SIGHUP",
"Exit",
"on",
"uncaught",
"exceptions"
] | cae3b96a9cd6689a3e5cfedfefef3718c1e4839c | https://github.com/vnykmshr/proc-utils/blob/cae3b96a9cd6689a3e5cfedfefef3718c1e4839c/lib/proc.js#L56-L75 |
56,734 | JohnnieFucker/dreamix-admin | lib/consoleService.js | enableCommand | function enableCommand(consoleService, moduleId, msg, cb) {
if (!moduleId) {
logger.error(`fail to enable admin module for ${moduleId}`);
cb('empty moduleId');
return;
}
const modules = consoleService.modules;
if (!modules[moduleId]) {
cb(null, protocol.PRO_FAIL);
return;
}
if (consoleService.master) {
consoleService.enable(moduleId);
consoleService.agent.notifyCommand('enable', moduleId, msg);
cb(null, protocol.PRO_OK);
} else {
consoleService.enable(moduleId);
cb(null, protocol.PRO_OK);
}
} | javascript | function enableCommand(consoleService, moduleId, msg, cb) {
if (!moduleId) {
logger.error(`fail to enable admin module for ${moduleId}`);
cb('empty moduleId');
return;
}
const modules = consoleService.modules;
if (!modules[moduleId]) {
cb(null, protocol.PRO_FAIL);
return;
}
if (consoleService.master) {
consoleService.enable(moduleId);
consoleService.agent.notifyCommand('enable', moduleId, msg);
cb(null, protocol.PRO_OK);
} else {
consoleService.enable(moduleId);
cb(null, protocol.PRO_OK);
}
} | [
"function",
"enableCommand",
"(",
"consoleService",
",",
"moduleId",
",",
"msg",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"moduleId",
")",
"{",
"logger",
".",
"error",
"(",
"`",
"${",
"moduleId",
"}",
"`",
")",
";",
"cb",
"(",
"'empty moduleId'",
")",
";",
"return",
";",
"}",
"const",
"modules",
"=",
"consoleService",
".",
"modules",
";",
"if",
"(",
"!",
"modules",
"[",
"moduleId",
"]",
")",
"{",
"cb",
"(",
"null",
",",
"protocol",
".",
"PRO_FAIL",
")",
";",
"return",
";",
"}",
"if",
"(",
"consoleService",
".",
"master",
")",
"{",
"consoleService",
".",
"enable",
"(",
"moduleId",
")",
";",
"consoleService",
".",
"agent",
".",
"notifyCommand",
"(",
"'enable'",
",",
"moduleId",
",",
"msg",
")",
";",
"cb",
"(",
"null",
",",
"protocol",
".",
"PRO_OK",
")",
";",
"}",
"else",
"{",
"consoleService",
".",
"enable",
"(",
"moduleId",
")",
";",
"cb",
"(",
"null",
",",
"protocol",
".",
"PRO_OK",
")",
";",
"}",
"}"
] | enable module in current server | [
"enable",
"module",
"in",
"current",
"server"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/consoleService.js#L35-L56 |
56,735 | JohnnieFucker/dreamix-admin | lib/consoleService.js | registerRecord | function registerRecord(service, moduleId, module) {
const record = {
moduleId: moduleId,
module: module,
enable: false
};
if (module.type && module.interval) {
if (!service.master && record.module.type === 'push' || service.master && record.module.type !== 'push') {// eslint-disable-line
// push for monitor or pull for master(default)
record.delay = module.delay || 0;
record.interval = module.interval || 1;
// normalize the arguments
if (record.delay < 0) {
record.delay = 0;
}
if (record.interval < 0) {
record.interval = 1;
}
record.interval = Math.ceil(record.interval);
record.delay *= MS_OF_SECOND;
record.interval *= MS_OF_SECOND;
record.schedule = true;
}
}
return record;
} | javascript | function registerRecord(service, moduleId, module) {
const record = {
moduleId: moduleId,
module: module,
enable: false
};
if (module.type && module.interval) {
if (!service.master && record.module.type === 'push' || service.master && record.module.type !== 'push') {// eslint-disable-line
// push for monitor or pull for master(default)
record.delay = module.delay || 0;
record.interval = module.interval || 1;
// normalize the arguments
if (record.delay < 0) {
record.delay = 0;
}
if (record.interval < 0) {
record.interval = 1;
}
record.interval = Math.ceil(record.interval);
record.delay *= MS_OF_SECOND;
record.interval *= MS_OF_SECOND;
record.schedule = true;
}
}
return record;
} | [
"function",
"registerRecord",
"(",
"service",
",",
"moduleId",
",",
"module",
")",
"{",
"const",
"record",
"=",
"{",
"moduleId",
":",
"moduleId",
",",
"module",
":",
"module",
",",
"enable",
":",
"false",
"}",
";",
"if",
"(",
"module",
".",
"type",
"&&",
"module",
".",
"interval",
")",
"{",
"if",
"(",
"!",
"service",
".",
"master",
"&&",
"record",
".",
"module",
".",
"type",
"===",
"'push'",
"||",
"service",
".",
"master",
"&&",
"record",
".",
"module",
".",
"type",
"!==",
"'push'",
")",
"{",
"// eslint-disable-line",
"// push for monitor or pull for master(default)",
"record",
".",
"delay",
"=",
"module",
".",
"delay",
"||",
"0",
";",
"record",
".",
"interval",
"=",
"module",
".",
"interval",
"||",
"1",
";",
"// normalize the arguments",
"if",
"(",
"record",
".",
"delay",
"<",
"0",
")",
"{",
"record",
".",
"delay",
"=",
"0",
";",
"}",
"if",
"(",
"record",
".",
"interval",
"<",
"0",
")",
"{",
"record",
".",
"interval",
"=",
"1",
";",
"}",
"record",
".",
"interval",
"=",
"Math",
".",
"ceil",
"(",
"record",
".",
"interval",
")",
";",
"record",
".",
"delay",
"*=",
"MS_OF_SECOND",
";",
"record",
".",
"interval",
"*=",
"MS_OF_SECOND",
";",
"record",
".",
"schedule",
"=",
"true",
";",
"}",
"}",
"return",
"record",
";",
"}"
] | register a module service
@param {Object} service consoleService object
@param {String} moduleId adminConsole id/name
@param {Object} module module object
@api private | [
"register",
"a",
"module",
"service"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/consoleService.js#L93-L120 |
56,736 | JohnnieFucker/dreamix-admin | lib/consoleService.js | addToSchedule | function addToSchedule(service, record) {
if (record && record.schedule) {
record.jobId = schedule.scheduleJob({
start: Date.now() + record.delay,
period: record.interval
},
doScheduleJob, {
service: service,
record: record
});
}
} | javascript | function addToSchedule(service, record) {
if (record && record.schedule) {
record.jobId = schedule.scheduleJob({
start: Date.now() + record.delay,
period: record.interval
},
doScheduleJob, {
service: service,
record: record
});
}
} | [
"function",
"addToSchedule",
"(",
"service",
",",
"record",
")",
"{",
"if",
"(",
"record",
"&&",
"record",
".",
"schedule",
")",
"{",
"record",
".",
"jobId",
"=",
"schedule",
".",
"scheduleJob",
"(",
"{",
"start",
":",
"Date",
".",
"now",
"(",
")",
"+",
"record",
".",
"delay",
",",
"period",
":",
"record",
".",
"interval",
"}",
",",
"doScheduleJob",
",",
"{",
"service",
":",
"service",
",",
"record",
":",
"record",
"}",
")",
";",
"}",
"}"
] | schedule console module
@param {Object} service consoleService object
@param {Object} record module object
@api private | [
"schedule",
"console",
"module"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/consoleService.js#L153-L164 |
56,737 | JohnnieFucker/dreamix-admin | lib/consoleService.js | exportEvent | function exportEvent(outer, inner, event) {
inner.on(event, (...args) => {
args.unshift(event);
outer.emit(...args);
});
} | javascript | function exportEvent(outer, inner, event) {
inner.on(event, (...args) => {
args.unshift(event);
outer.emit(...args);
});
} | [
"function",
"exportEvent",
"(",
"outer",
",",
"inner",
",",
"event",
")",
"{",
"inner",
".",
"on",
"(",
"event",
",",
"(",
"...",
"args",
")",
"=>",
"{",
"args",
".",
"unshift",
"(",
"event",
")",
";",
"outer",
".",
"emit",
"(",
"...",
"args",
")",
";",
"}",
")",
";",
"}"
] | export closure function out
@param {Function} outer outer function
@param {Function} inner inner function
@param {object} event
@api private | [
"export",
"closure",
"function",
"out"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/consoleService.js#L174-L179 |
56,738 | fladi/sails-generate-avahi | templates/hook.template.js | add_group | function add_group() {
server.EntryGroupNew(function(err, path) {
if (err) {
sails.log.error('DBus: Could not call org.freedesktop.Avahi.Server.EntryGroupNew');
return;
}
service.getInterface(
path,
avahi.DBUS_INTERFACE_ENTRY_GROUP.value,
function (
err,
newGroup
) {
group = newGroup;
add_service();
}
)
});
} | javascript | function add_group() {
server.EntryGroupNew(function(err, path) {
if (err) {
sails.log.error('DBus: Could not call org.freedesktop.Avahi.Server.EntryGroupNew');
return;
}
service.getInterface(
path,
avahi.DBUS_INTERFACE_ENTRY_GROUP.value,
function (
err,
newGroup
) {
group = newGroup;
add_service();
}
)
});
} | [
"function",
"add_group",
"(",
")",
"{",
"server",
".",
"EntryGroupNew",
"(",
"function",
"(",
"err",
",",
"path",
")",
"{",
"if",
"(",
"err",
")",
"{",
"sails",
".",
"log",
".",
"error",
"(",
"'DBus: Could not call org.freedesktop.Avahi.Server.EntryGroupNew'",
")",
";",
"return",
";",
"}",
"service",
".",
"getInterface",
"(",
"path",
",",
"avahi",
".",
"DBUS_INTERFACE_ENTRY_GROUP",
".",
"value",
",",
"function",
"(",
"err",
",",
"newGroup",
")",
"{",
"group",
"=",
"newGroup",
";",
"add_service",
"(",
")",
";",
"}",
")",
"}",
")",
";",
"}"
] | Add a new EntryGroup for our service. | [
"Add",
"a",
"new",
"EntryGroup",
"for",
"our",
"service",
"."
] | 09f66f30d9301ad7078a3b4e95f3b3c7f3b6d337 | https://github.com/fladi/sails-generate-avahi/blob/09f66f30d9301ad7078a3b4e95f3b3c7f3b6d337/templates/hook.template.js#L41-L59 |
56,739 | fladi/sails-generate-avahi | templates/hook.template.js | add_service | function add_service() {
// Default configuration. Overrides can be defined in `config/avahi.js`.
sails.log.info('Publishing service ' + config.name + ' (' + config.type + ') on port '+ config.port);
group.AddService(
avahi.IF_UNSPEC.value,
avahi.PROTO_INET.value,
0,
config.name,
config.type,
config.domain,
config.host,
config.port,
'',
function(err) {
if (err) {
sails.log.error('DBus: Could not call org.freedesktop.Avahi.EntryGroup.AddService');
return;
}
group.Commit();
}
);
} | javascript | function add_service() {
// Default configuration. Overrides can be defined in `config/avahi.js`.
sails.log.info('Publishing service ' + config.name + ' (' + config.type + ') on port '+ config.port);
group.AddService(
avahi.IF_UNSPEC.value,
avahi.PROTO_INET.value,
0,
config.name,
config.type,
config.domain,
config.host,
config.port,
'',
function(err) {
if (err) {
sails.log.error('DBus: Could not call org.freedesktop.Avahi.EntryGroup.AddService');
return;
}
group.Commit();
}
);
} | [
"function",
"add_service",
"(",
")",
"{",
"// Default configuration. Overrides can be defined in `config/avahi.js`.",
"sails",
".",
"log",
".",
"info",
"(",
"'Publishing service '",
"+",
"config",
".",
"name",
"+",
"' ('",
"+",
"config",
".",
"type",
"+",
"') on port '",
"+",
"config",
".",
"port",
")",
";",
"group",
".",
"AddService",
"(",
"avahi",
".",
"IF_UNSPEC",
".",
"value",
",",
"avahi",
".",
"PROTO_INET",
".",
"value",
",",
"0",
",",
"config",
".",
"name",
",",
"config",
".",
"type",
",",
"config",
".",
"domain",
",",
"config",
".",
"host",
",",
"config",
".",
"port",
",",
"''",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"sails",
".",
"log",
".",
"error",
"(",
"'DBus: Could not call org.freedesktop.Avahi.EntryGroup.AddService'",
")",
";",
"return",
";",
"}",
"group",
".",
"Commit",
"(",
")",
";",
"}",
")",
";",
"}"
] | Add our service definition. | [
"Add",
"our",
"service",
"definition",
"."
] | 09f66f30d9301ad7078a3b4e95f3b3c7f3b6d337 | https://github.com/fladi/sails-generate-avahi/blob/09f66f30d9301ad7078a3b4e95f3b3c7f3b6d337/templates/hook.template.js#L62-L84 |
56,740 | vanjacosic/opbeat-js | src/opbeat.js | triggerEvent | function triggerEvent(eventType, options) {
var event, key;
options = options || {};
eventType = 'opbeat' + eventType.substr(0,1).toUpperCase() + eventType.substr(1);
if (document.createEvent) {
event = document.createEvent('HTMLEvents');
event.initEvent(eventType, true, true);
} else {
event = document.createEventObject();
event.eventType = eventType;
}
for (key in options) if (hasKey(options, key)) {
event[key] = options[key];
}
if (document.createEvent) {
// IE9 if standards
document.dispatchEvent(event);
} else {
// IE8 regardless of Quirks or Standards
// IE9 if quirks
try {
document.fireEvent('on' + event.eventType.toLowerCase(), event);
} catch(e) {}
}
} | javascript | function triggerEvent(eventType, options) {
var event, key;
options = options || {};
eventType = 'opbeat' + eventType.substr(0,1).toUpperCase() + eventType.substr(1);
if (document.createEvent) {
event = document.createEvent('HTMLEvents');
event.initEvent(eventType, true, true);
} else {
event = document.createEventObject();
event.eventType = eventType;
}
for (key in options) if (hasKey(options, key)) {
event[key] = options[key];
}
if (document.createEvent) {
// IE9 if standards
document.dispatchEvent(event);
} else {
// IE8 regardless of Quirks or Standards
// IE9 if quirks
try {
document.fireEvent('on' + event.eventType.toLowerCase(), event);
} catch(e) {}
}
} | [
"function",
"triggerEvent",
"(",
"eventType",
",",
"options",
")",
"{",
"var",
"event",
",",
"key",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"eventType",
"=",
"'opbeat'",
"+",
"eventType",
".",
"substr",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"eventType",
".",
"substr",
"(",
"1",
")",
";",
"if",
"(",
"document",
".",
"createEvent",
")",
"{",
"event",
"=",
"document",
".",
"createEvent",
"(",
"'HTMLEvents'",
")",
";",
"event",
".",
"initEvent",
"(",
"eventType",
",",
"true",
",",
"true",
")",
";",
"}",
"else",
"{",
"event",
"=",
"document",
".",
"createEventObject",
"(",
")",
";",
"event",
".",
"eventType",
"=",
"eventType",
";",
"}",
"for",
"(",
"key",
"in",
"options",
")",
"if",
"(",
"hasKey",
"(",
"options",
",",
"key",
")",
")",
"{",
"event",
"[",
"key",
"]",
"=",
"options",
"[",
"key",
"]",
";",
"}",
"if",
"(",
"document",
".",
"createEvent",
")",
"{",
"// IE9 if standards",
"document",
".",
"dispatchEvent",
"(",
"event",
")",
";",
"}",
"else",
"{",
"// IE8 regardless of Quirks or Standards",
"// IE9 if quirks",
"try",
"{",
"document",
".",
"fireEvent",
"(",
"'on'",
"+",
"event",
".",
"eventType",
".",
"toLowerCase",
"(",
")",
",",
"event",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"}",
"}"
] | To be deprecated | [
"To",
"be",
"deprecated"
] | 136065ff2f6cda0097c783e43ca3773da6dff3ed | https://github.com/vanjacosic/opbeat-js/blob/136065ff2f6cda0097c783e43ca3773da6dff3ed/src/opbeat.js#L308-L337 |
56,741 | PrinceNebulon/github-api-promise | src/request-helpers.js | function(url, method = 'get', body = undefined) {
var deferred = Q.defer();
this.extendedRequest(url, method, body)
.then((res) => { deferred.resolve(res.body); })
.catch((err) => { deferred.reject(err); });
return deferred.promise;
} | javascript | function(url, method = 'get', body = undefined) {
var deferred = Q.defer();
this.extendedRequest(url, method, body)
.then((res) => { deferred.resolve(res.body); })
.catch((err) => { deferred.reject(err); });
return deferred.promise;
} | [
"function",
"(",
"url",
",",
"method",
"=",
"'get'",
",",
"body",
"=",
"undefined",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"this",
".",
"extendedRequest",
"(",
"url",
",",
"method",
",",
"body",
")",
".",
"then",
"(",
"(",
"res",
")",
"=>",
"{",
"deferred",
".",
"resolve",
"(",
"res",
".",
"body",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"err",
")",
"=>",
"{",
"deferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Returns only the response body | [
"Returns",
"only",
"the",
"response",
"body"
] | 990cb2cce19b53f54d9243002fde47428f24e7cc | https://github.com/PrinceNebulon/github-api-promise/blob/990cb2cce19b53f54d9243002fde47428f24e7cc/src/request-helpers.js#L37-L45 |
|
56,742 | mjhasbach/bower-package-url | lib/bowerPackageURL.js | bowerPackageURL | function bowerPackageURL(packageName, cb) {
if (typeof cb !== 'function') {
throw new TypeError('cb must be a function');
}
if (typeof packageName !== 'string') {
cb(new TypeError('packageName must be a string'));
return;
}
http.get('https://bower.herokuapp.com/packages/' + packageName)
.end(function(err, res) {
if (err && err.status === 404) {
err = new Error('Package ' + packageName + ' not found on Bower');
}
cb(err, res.body.url);
});
} | javascript | function bowerPackageURL(packageName, cb) {
if (typeof cb !== 'function') {
throw new TypeError('cb must be a function');
}
if (typeof packageName !== 'string') {
cb(new TypeError('packageName must be a string'));
return;
}
http.get('https://bower.herokuapp.com/packages/' + packageName)
.end(function(err, res) {
if (err && err.status === 404) {
err = new Error('Package ' + packageName + ' not found on Bower');
}
cb(err, res.body.url);
});
} | [
"function",
"bowerPackageURL",
"(",
"packageName",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'cb must be a function'",
")",
";",
"}",
"if",
"(",
"typeof",
"packageName",
"!==",
"'string'",
")",
"{",
"cb",
"(",
"new",
"TypeError",
"(",
"'packageName must be a string'",
")",
")",
";",
"return",
";",
"}",
"http",
".",
"get",
"(",
"'https://bower.herokuapp.com/packages/'",
"+",
"packageName",
")",
".",
"end",
"(",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"status",
"===",
"404",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'Package '",
"+",
"packageName",
"+",
"' not found on Bower'",
")",
";",
"}",
"cb",
"(",
"err",
",",
"res",
".",
"body",
".",
"url",
")",
";",
"}",
")",
";",
"}"
] | The bowerPackageURL callback
@callback bowerPackageURLCallback
@param {Object} err - An error object if an error occurred
@param {string} url - The repository URL associated with the provided bower package name
Get the repository URL associated with a bower package name
@alias module:bowerPackageURL
@param {string} packageName - A bower package name
@param {bowerPackageURLCallback} cb - A callback to be executed after the repository URL is collected
@example
bowerPackageURL('lodash', function(err, url) {
if (err) { console.error(err); }
console.log(url);
}); | [
"The",
"bowerPackageURL",
"callback"
] | 5ed279cc7e685789ec73667ff6787ae85e368acc | https://github.com/mjhasbach/bower-package-url/blob/5ed279cc7e685789ec73667ff6787ae85e368acc/lib/bowerPackageURL.js#L26-L43 |
56,743 | crokita/functionite | examples/example3.js | addPoints | function addPoints (x1, y1, x2, y2, cb) {
var xFinal = x1 + x2;
var yFinal = y1 + y2;
cb(xFinal, yFinal);
} | javascript | function addPoints (x1, y1, x2, y2, cb) {
var xFinal = x1 + x2;
var yFinal = y1 + y2;
cb(xFinal, yFinal);
} | [
"function",
"addPoints",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"cb",
")",
"{",
"var",
"xFinal",
"=",
"x1",
"+",
"x2",
";",
"var",
"yFinal",
"=",
"y1",
"+",
"y2",
";",
"cb",
"(",
"xFinal",
",",
"yFinal",
")",
";",
"}"
] | this function takes the sum of two points, and returns the sum of x's and the sum of y's in a callback | [
"this",
"function",
"takes",
"the",
"sum",
"of",
"two",
"points",
"and",
"returns",
"the",
"sum",
"of",
"x",
"s",
"and",
"the",
"sum",
"of",
"y",
"s",
"in",
"a",
"callback"
] | e5d52b3bded8eac6b42413208e1dc61e0741ae34 | https://github.com/crokita/functionite/blob/e5d52b3bded8eac6b42413208e1dc61e0741ae34/examples/example3.js#L16-L20 |
56,744 | creationix/git-pack-codec | decode.js | emitObject | function emitObject() {
var item = {
type: types[type],
size: length,
body: bops.join(parts),
offset: start
};
if (ref) item.ref = ref;
parts.length = 0;
start = 0;
offset = 0;
type = 0;
length = 0;
ref = null;
emit(item);
} | javascript | function emitObject() {
var item = {
type: types[type],
size: length,
body: bops.join(parts),
offset: start
};
if (ref) item.ref = ref;
parts.length = 0;
start = 0;
offset = 0;
type = 0;
length = 0;
ref = null;
emit(item);
} | [
"function",
"emitObject",
"(",
")",
"{",
"var",
"item",
"=",
"{",
"type",
":",
"types",
"[",
"type",
"]",
",",
"size",
":",
"length",
",",
"body",
":",
"bops",
".",
"join",
"(",
"parts",
")",
",",
"offset",
":",
"start",
"}",
";",
"if",
"(",
"ref",
")",
"item",
".",
"ref",
"=",
"ref",
";",
"parts",
".",
"length",
"=",
"0",
";",
"start",
"=",
"0",
";",
"offset",
"=",
"0",
";",
"type",
"=",
"0",
";",
"length",
"=",
"0",
";",
"ref",
"=",
"null",
";",
"emit",
"(",
"item",
")",
";",
"}"
] | Common helper for emitting all three object shapes | [
"Common",
"helper",
"for",
"emitting",
"all",
"three",
"object",
"shapes"
] | bf14e63755795dc5d15f7f68b68bbc312a114ef2 | https://github.com/creationix/git-pack-codec/blob/bf14e63755795dc5d15f7f68b68bbc312a114ef2/decode.js#L149-L164 |
56,745 | creationix/git-pack-codec | decode.js | $body | function $body(byte, i, chunk) {
if (inf.write(byte)) return $body;
var buf = inf.flush();
inf.recycle();
if (buf.length) {
parts.push(buf);
}
emitObject();
// If this was all the objects, start calculating the sha1sum
if (--num) return $header;
sha1sum.update(bops.subarray(chunk, 0, i + 1));
return $checksum;
} | javascript | function $body(byte, i, chunk) {
if (inf.write(byte)) return $body;
var buf = inf.flush();
inf.recycle();
if (buf.length) {
parts.push(buf);
}
emitObject();
// If this was all the objects, start calculating the sha1sum
if (--num) return $header;
sha1sum.update(bops.subarray(chunk, 0, i + 1));
return $checksum;
} | [
"function",
"$body",
"(",
"byte",
",",
"i",
",",
"chunk",
")",
"{",
"if",
"(",
"inf",
".",
"write",
"(",
"byte",
")",
")",
"return",
"$body",
";",
"var",
"buf",
"=",
"inf",
".",
"flush",
"(",
")",
";",
"inf",
".",
"recycle",
"(",
")",
";",
"if",
"(",
"buf",
".",
"length",
")",
"{",
"parts",
".",
"push",
"(",
"buf",
")",
";",
"}",
"emitObject",
"(",
")",
";",
"// If this was all the objects, start calculating the sha1sum",
"if",
"(",
"--",
"num",
")",
"return",
"$header",
";",
"sha1sum",
".",
"update",
"(",
"bops",
".",
"subarray",
"(",
"chunk",
",",
"0",
",",
"i",
"+",
"1",
")",
")",
";",
"return",
"$checksum",
";",
"}"
] | Feed the deflated code to the inflate engine | [
"Feed",
"the",
"deflated",
"code",
"to",
"the",
"inflate",
"engine"
] | bf14e63755795dc5d15f7f68b68bbc312a114ef2 | https://github.com/creationix/git-pack-codec/blob/bf14e63755795dc5d15f7f68b68bbc312a114ef2/decode.js#L167-L179 |
56,746 | pierrec/node-atok | lib/subrule.js | typeOf | function typeOf (rule) {
var ruleType = typeof rule
return ruleType === 'function'
? ruleType
: ruleType !== 'object'
? (rule.length === 0
? 'noop'
: (rule === 0
? 'zero'
: ruleType
)
)
: Buffer.isBuffer(rule)
? 'buffer'
: !isArray(rule)
? ((has(rule, 'start') && has(rule, 'end')
? 'range'
: has(rule, 'start')
? 'rangestart'
: has(rule, 'end')
? 'rangeend'
: has(rule, 'firstOf')
? (( (isArray(rule.firstOf) && sameTypeArray(rule.firstOf) )
|| typeof rule.firstOf === 'string'
)
&& rule.firstOf.length > 1
)
? 'firstof'
: 'invalid firstof'
: 'invalid'
)
+ '_object'
)
: !sameTypeArray(rule)
? 'multi types array'
: ((Buffer.isBuffer( rule[0] )
? 'buffer'
: typeof rule[0]
)
+ '_array'
)
} | javascript | function typeOf (rule) {
var ruleType = typeof rule
return ruleType === 'function'
? ruleType
: ruleType !== 'object'
? (rule.length === 0
? 'noop'
: (rule === 0
? 'zero'
: ruleType
)
)
: Buffer.isBuffer(rule)
? 'buffer'
: !isArray(rule)
? ((has(rule, 'start') && has(rule, 'end')
? 'range'
: has(rule, 'start')
? 'rangestart'
: has(rule, 'end')
? 'rangeend'
: has(rule, 'firstOf')
? (( (isArray(rule.firstOf) && sameTypeArray(rule.firstOf) )
|| typeof rule.firstOf === 'string'
)
&& rule.firstOf.length > 1
)
? 'firstof'
: 'invalid firstof'
: 'invalid'
)
+ '_object'
)
: !sameTypeArray(rule)
? 'multi types array'
: ((Buffer.isBuffer( rule[0] )
? 'buffer'
: typeof rule[0]
)
+ '_array'
)
} | [
"function",
"typeOf",
"(",
"rule",
")",
"{",
"var",
"ruleType",
"=",
"typeof",
"rule",
"return",
"ruleType",
"===",
"'function'",
"?",
"ruleType",
":",
"ruleType",
"!==",
"'object'",
"?",
"(",
"rule",
".",
"length",
"===",
"0",
"?",
"'noop'",
":",
"(",
"rule",
"===",
"0",
"?",
"'zero'",
":",
"ruleType",
")",
")",
":",
"Buffer",
".",
"isBuffer",
"(",
"rule",
")",
"?",
"'buffer'",
":",
"!",
"isArray",
"(",
"rule",
")",
"?",
"(",
"(",
"has",
"(",
"rule",
",",
"'start'",
")",
"&&",
"has",
"(",
"rule",
",",
"'end'",
")",
"?",
"'range'",
":",
"has",
"(",
"rule",
",",
"'start'",
")",
"?",
"'rangestart'",
":",
"has",
"(",
"rule",
",",
"'end'",
")",
"?",
"'rangeend'",
":",
"has",
"(",
"rule",
",",
"'firstOf'",
")",
"?",
"(",
"(",
"(",
"isArray",
"(",
"rule",
".",
"firstOf",
")",
"&&",
"sameTypeArray",
"(",
"rule",
".",
"firstOf",
")",
")",
"||",
"typeof",
"rule",
".",
"firstOf",
"===",
"'string'",
")",
"&&",
"rule",
".",
"firstOf",
".",
"length",
">",
"1",
")",
"?",
"'firstof'",
":",
"'invalid firstof'",
":",
"'invalid'",
")",
"+",
"'_object'",
")",
":",
"!",
"sameTypeArray",
"(",
"rule",
")",
"?",
"'multi types array'",
":",
"(",
"(",
"Buffer",
".",
"isBuffer",
"(",
"rule",
"[",
"0",
"]",
")",
"?",
"'buffer'",
":",
"typeof",
"rule",
"[",
"0",
"]",
")",
"+",
"'_array'",
")",
"}"
] | Return the type of an item
@param {...} item to check
@return {String} type | [
"Return",
"the",
"type",
"of",
"an",
"item"
] | abe139e7fa8c092d87e528289b6abd9083df2323 | https://github.com/pierrec/node-atok/blob/abe139e7fa8c092d87e528289b6abd9083df2323/lib/subrule.js#L603-L645 |
56,747 | hillscottc/nostra | src/sentence_mgr.js | encounter | function encounter(mood) {
//Sentence 1: The meeting
const familiar_people = wordLib.getWords("familiar_people");
const strange_people = wordLib.getWords("strange_people");
const locations = wordLib.getWords("locations");
const person = nu.chooseFrom(familiar_people.concat(strange_people));
let location = nu.chooseFrom(wordLib.getWords("locations"));
const preposition = location[0];
location = location[1];
const s1 = `You may meet ${person} ${preposition} ${location}.`;
// Sentence 2: The discussion
let discussions = wordLib.getWords("neutral_discussions");
discussions.concat(wordLib.getWords(mood + "_discussions"));
const feeling_nouns = wordLib.getWords(mood + "_feeling_nouns");
const emotive_nouns = wordLib.getWords(mood + "_emotive_nouns");
const conversation_topics = wordLib.getWords("conversation_topics");
const discussion = nu.chooseFrom(discussions);
const rnum = Math.floor(Math.random() * 10);
let feeling;
if (rnum <- 5) {
feeling = nu.chooseFrom(feeling_nouns);
feeling = "feelings of " + feeling;
} else {
feeling = nu.chooseFrom(emotive_nouns);
}
const topic = nu.chooseFrom(conversation_topics);
let s2 = `${nu.an(discussion)} about ${topic} may lead to ${feeling}.`;
s2 = nu.sentenceCase(s2);
return `${s1} ${s2}`;
} | javascript | function encounter(mood) {
//Sentence 1: The meeting
const familiar_people = wordLib.getWords("familiar_people");
const strange_people = wordLib.getWords("strange_people");
const locations = wordLib.getWords("locations");
const person = nu.chooseFrom(familiar_people.concat(strange_people));
let location = nu.chooseFrom(wordLib.getWords("locations"));
const preposition = location[0];
location = location[1];
const s1 = `You may meet ${person} ${preposition} ${location}.`;
// Sentence 2: The discussion
let discussions = wordLib.getWords("neutral_discussions");
discussions.concat(wordLib.getWords(mood + "_discussions"));
const feeling_nouns = wordLib.getWords(mood + "_feeling_nouns");
const emotive_nouns = wordLib.getWords(mood + "_emotive_nouns");
const conversation_topics = wordLib.getWords("conversation_topics");
const discussion = nu.chooseFrom(discussions);
const rnum = Math.floor(Math.random() * 10);
let feeling;
if (rnum <- 5) {
feeling = nu.chooseFrom(feeling_nouns);
feeling = "feelings of " + feeling;
} else {
feeling = nu.chooseFrom(emotive_nouns);
}
const topic = nu.chooseFrom(conversation_topics);
let s2 = `${nu.an(discussion)} about ${topic} may lead to ${feeling}.`;
s2 = nu.sentenceCase(s2);
return `${s1} ${s2}`;
} | [
"function",
"encounter",
"(",
"mood",
")",
"{",
"//Sentence 1: The meeting",
"const",
"familiar_people",
"=",
"wordLib",
".",
"getWords",
"(",
"\"familiar_people\"",
")",
";",
"const",
"strange_people",
"=",
"wordLib",
".",
"getWords",
"(",
"\"strange_people\"",
")",
";",
"const",
"locations",
"=",
"wordLib",
".",
"getWords",
"(",
"\"locations\"",
")",
";",
"const",
"person",
"=",
"nu",
".",
"chooseFrom",
"(",
"familiar_people",
".",
"concat",
"(",
"strange_people",
")",
")",
";",
"let",
"location",
"=",
"nu",
".",
"chooseFrom",
"(",
"wordLib",
".",
"getWords",
"(",
"\"locations\"",
")",
")",
";",
"const",
"preposition",
"=",
"location",
"[",
"0",
"]",
";",
"location",
"=",
"location",
"[",
"1",
"]",
";",
"const",
"s1",
"=",
"`",
"${",
"person",
"}",
"${",
"preposition",
"}",
"${",
"location",
"}",
"`",
";",
"// Sentence 2: The discussion",
"let",
"discussions",
"=",
"wordLib",
".",
"getWords",
"(",
"\"neutral_discussions\"",
")",
";",
"discussions",
".",
"concat",
"(",
"wordLib",
".",
"getWords",
"(",
"mood",
"+",
"\"_discussions\"",
")",
")",
";",
"const",
"feeling_nouns",
"=",
"wordLib",
".",
"getWords",
"(",
"mood",
"+",
"\"_feeling_nouns\"",
")",
";",
"const",
"emotive_nouns",
"=",
"wordLib",
".",
"getWords",
"(",
"mood",
"+",
"\"_emotive_nouns\"",
")",
";",
"const",
"conversation_topics",
"=",
"wordLib",
".",
"getWords",
"(",
"\"conversation_topics\"",
")",
";",
"const",
"discussion",
"=",
"nu",
".",
"chooseFrom",
"(",
"discussions",
")",
";",
"const",
"rnum",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"10",
")",
";",
"let",
"feeling",
";",
"if",
"(",
"rnum",
"<",
"-",
"5",
")",
"{",
"feeling",
"=",
"nu",
".",
"chooseFrom",
"(",
"feeling_nouns",
")",
";",
"feeling",
"=",
"\"feelings of \"",
"+",
"feeling",
";",
"}",
"else",
"{",
"feeling",
"=",
"nu",
".",
"chooseFrom",
"(",
"emotive_nouns",
")",
";",
"}",
"const",
"topic",
"=",
"nu",
".",
"chooseFrom",
"(",
"conversation_topics",
")",
";",
"let",
"s2",
"=",
"`",
"${",
"nu",
".",
"an",
"(",
"discussion",
")",
"}",
"${",
"topic",
"}",
"${",
"feeling",
"}",
"`",
";",
"s2",
"=",
"nu",
".",
"sentenceCase",
"(",
"s2",
")",
";",
"return",
"`",
"${",
"s1",
"}",
"${",
"s2",
"}",
"`",
";",
"}"
] | Generate a few sentences about a meeting with another person.
@param mood | [
"Generate",
"a",
"few",
"sentences",
"about",
"a",
"meeting",
"with",
"another",
"person",
"."
] | 1801c8e19f7fab91dd29fea07195789d41624915 | https://github.com/hillscottc/nostra/blob/1801c8e19f7fab91dd29fea07195789d41624915/src/sentence_mgr.js#L38-L76 |
56,748 | hillscottc/nostra | src/sentence_mgr.js | feeling | function feeling(mood) {
const rnum = Math.floor(Math.random() * 10);
const adjectives = wordLib.getWords(mood + "_feeling_adjs");
//var degrees = getWords("neutral_degrees") + getWords(mood + "_degrees");
const degrees = wordLib.getWords("neutral_degrees").concat(wordLib.getWords(mood + "_degrees"));
const adj = nu.ingToEd(nu.chooseFrom(adjectives));
const degree = nu.chooseFrom(degrees);
let ending;
if (mood === "good") {
ending = wordLib.positiveIntensify();
} else {
ending = wordLib.consolation();
}
const exciting = (mood === "GOOD" && rnum <= 5);
const are = nu.chooseFrom([" are", "'re"]);
const sentence = `You${are} feeling ${degree} ${adj}${ending}`;
return nu.sentenceCase(sentence, exciting);
} | javascript | function feeling(mood) {
const rnum = Math.floor(Math.random() * 10);
const adjectives = wordLib.getWords(mood + "_feeling_adjs");
//var degrees = getWords("neutral_degrees") + getWords(mood + "_degrees");
const degrees = wordLib.getWords("neutral_degrees").concat(wordLib.getWords(mood + "_degrees"));
const adj = nu.ingToEd(nu.chooseFrom(adjectives));
const degree = nu.chooseFrom(degrees);
let ending;
if (mood === "good") {
ending = wordLib.positiveIntensify();
} else {
ending = wordLib.consolation();
}
const exciting = (mood === "GOOD" && rnum <= 5);
const are = nu.chooseFrom([" are", "'re"]);
const sentence = `You${are} feeling ${degree} ${adj}${ending}`;
return nu.sentenceCase(sentence, exciting);
} | [
"function",
"feeling",
"(",
"mood",
")",
"{",
"const",
"rnum",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"10",
")",
";",
"const",
"adjectives",
"=",
"wordLib",
".",
"getWords",
"(",
"mood",
"+",
"\"_feeling_adjs\"",
")",
";",
"//var degrees = getWords(\"neutral_degrees\") + getWords(mood + \"_degrees\");",
"const",
"degrees",
"=",
"wordLib",
".",
"getWords",
"(",
"\"neutral_degrees\"",
")",
".",
"concat",
"(",
"wordLib",
".",
"getWords",
"(",
"mood",
"+",
"\"_degrees\"",
")",
")",
";",
"const",
"adj",
"=",
"nu",
".",
"ingToEd",
"(",
"nu",
".",
"chooseFrom",
"(",
"adjectives",
")",
")",
";",
"const",
"degree",
"=",
"nu",
".",
"chooseFrom",
"(",
"degrees",
")",
";",
"let",
"ending",
";",
"if",
"(",
"mood",
"===",
"\"good\"",
")",
"{",
"ending",
"=",
"wordLib",
".",
"positiveIntensify",
"(",
")",
";",
"}",
"else",
"{",
"ending",
"=",
"wordLib",
".",
"consolation",
"(",
")",
";",
"}",
"const",
"exciting",
"=",
"(",
"mood",
"===",
"\"GOOD\"",
"&&",
"rnum",
"<=",
"5",
")",
";",
"const",
"are",
"=",
"nu",
".",
"chooseFrom",
"(",
"[",
"\" are\"",
",",
"\"'re\"",
"]",
")",
";",
"const",
"sentence",
"=",
"`",
"${",
"are",
"}",
"${",
"degree",
"}",
"${",
"adj",
"}",
"${",
"ending",
"}",
"`",
";",
"return",
"nu",
".",
"sentenceCase",
"(",
"sentence",
",",
"exciting",
")",
";",
"}"
] | A mood-based feeling
@param mood
@returns {*} | [
"A",
"mood",
"-",
"based",
"feeling"
] | 1801c8e19f7fab91dd29fea07195789d41624915 | https://github.com/hillscottc/nostra/blob/1801c8e19f7fab91dd29fea07195789d41624915/src/sentence_mgr.js#L83-L101 |
56,749 | angeloocana/joj-core | dist-esnext/Move.js | getGameAfterMove | function getGameAfterMove(game, move, backMove = false) {
if (!backMove && canNotMove(game, move))
return game;
const board = getBoardAfterMove(game.board, move);
return {
players: game.players,
board,
score: Score.getScore(game.board),
moves: backMove ? game.moves : game.moves.concat(getMoveXAndY(move))
};
} | javascript | function getGameAfterMove(game, move, backMove = false) {
if (!backMove && canNotMove(game, move))
return game;
const board = getBoardAfterMove(game.board, move);
return {
players: game.players,
board,
score: Score.getScore(game.board),
moves: backMove ? game.moves : game.moves.concat(getMoveXAndY(move))
};
} | [
"function",
"getGameAfterMove",
"(",
"game",
",",
"move",
",",
"backMove",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"backMove",
"&&",
"canNotMove",
"(",
"game",
",",
"move",
")",
")",
"return",
"game",
";",
"const",
"board",
"=",
"getBoardAfterMove",
"(",
"game",
".",
"board",
",",
"move",
")",
";",
"return",
"{",
"players",
":",
"game",
".",
"players",
",",
"board",
",",
"score",
":",
"Score",
".",
"getScore",
"(",
"game",
".",
"board",
")",
",",
"moves",
":",
"backMove",
"?",
"game",
".",
"moves",
":",
"game",
".",
"moves",
".",
"concat",
"(",
"getMoveXAndY",
"(",
"move",
")",
")",
"}",
";",
"}"
] | Takes game and move then returns new game after move.
Updates:
- .board (It cleans board, set new positions and move breadcrumb)
- .score
- .moves (add new move if valid and it is not backMove) | [
"Takes",
"game",
"and",
"move",
"then",
"returns",
"new",
"game",
"after",
"move",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist-esnext/Move.js#L69-L79 |
56,750 | angeloocana/joj-core | dist-esnext/Move.js | getGameBeforeLastMove | function getGameBeforeLastMove(game) {
// $Fix I do NOT know if it is the best way to make game immutable.
game = Object.assign({}, game);
let lastMove = game.moves.pop();
if (lastMove)
game = getGameAfterMove(game, getBackMove(lastMove), true);
if (Game.getPlayerTurn(game).isAi) {
lastMove = game.moves.pop();
if (lastMove) {
game = getGameAfterMove(game, getBackMove(lastMove), true);
}
}
return game;
} | javascript | function getGameBeforeLastMove(game) {
// $Fix I do NOT know if it is the best way to make game immutable.
game = Object.assign({}, game);
let lastMove = game.moves.pop();
if (lastMove)
game = getGameAfterMove(game, getBackMove(lastMove), true);
if (Game.getPlayerTurn(game).isAi) {
lastMove = game.moves.pop();
if (lastMove) {
game = getGameAfterMove(game, getBackMove(lastMove), true);
}
}
return game;
} | [
"function",
"getGameBeforeLastMove",
"(",
"game",
")",
"{",
"// $Fix I do NOT know if it is the best way to make game immutable.",
"game",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"game",
")",
";",
"let",
"lastMove",
"=",
"game",
".",
"moves",
".",
"pop",
"(",
")",
";",
"if",
"(",
"lastMove",
")",
"game",
"=",
"getGameAfterMove",
"(",
"game",
",",
"getBackMove",
"(",
"lastMove",
")",
",",
"true",
")",
";",
"if",
"(",
"Game",
".",
"getPlayerTurn",
"(",
"game",
")",
".",
"isAi",
")",
"{",
"lastMove",
"=",
"game",
".",
"moves",
".",
"pop",
"(",
")",
";",
"if",
"(",
"lastMove",
")",
"{",
"game",
"=",
"getGameAfterMove",
"(",
"game",
",",
"getBackMove",
"(",
"lastMove",
")",
",",
"true",
")",
";",
"}",
"}",
"return",
"game",
";",
"}"
] | Get game before last move,
if playing vs Ai rollback Ai move too. | [
"Get",
"game",
"before",
"last",
"move",
"if",
"playing",
"vs",
"Ai",
"rollback",
"Ai",
"move",
"too",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist-esnext/Move.js#L84-L97 |
56,751 | evaisse/wiresrc | lib/detect.js | function (config) {
/**
* The iterator function, which is called on each component.
*
* @param {string} version the version of the component
* @param {string} component the name of the component
* @return {undefined}
*/
return function (version, component) {
var dep = config.get('global-dependencies').get(component) || {
main: '',
type: '',
name: '',
dependencies: {}
};
console.log(version, component);
var componentConfigFile = findComponentConfigFile(config, component);
var warnings = config.get('warnings');
var overrides = config.get('overrides');
if (overrides && overrides[component]) {
if (overrides[component].dependencies) {
componentConfigFile.dependencies = overrides[component].dependencies;
}
if (overrides[component].main) {
componentConfigFile.main = overrides[component].main;
}
}
var mains = findMainFiles(config, component, componentConfigFile);
var fileTypes = _.chain(mains).map(path.extname).unique().value();
dep.main = mains;
dep.type = fileTypes;
dep.name = componentConfigFile.name;
var depIsExcluded = _.find(config.get('exclude'), function (pattern) {
return path.join(config.get('bower-directory'), component).match(pattern);
});
if (dep.main.length === 0 && !depIsExcluded) {
// can't find the main file. this config file is useless!
warnings.push(component + ' was not injected in your file.');
warnings.push(
'Please go take a look in "' + path.join(config.get('bower-directory'), component) + '" for the file you need, then manually include it in your file.');
config.set('warnings', warnings);
return;
}
if (componentConfigFile.dependencies) {
dep.dependencies = componentConfigFile.dependencies;
_.each(componentConfigFile.dependencies, gatherInfo(config));
}
config.get('global-dependencies').set(component, dep);
};
} | javascript | function (config) {
/**
* The iterator function, which is called on each component.
*
* @param {string} version the version of the component
* @param {string} component the name of the component
* @return {undefined}
*/
return function (version, component) {
var dep = config.get('global-dependencies').get(component) || {
main: '',
type: '',
name: '',
dependencies: {}
};
console.log(version, component);
var componentConfigFile = findComponentConfigFile(config, component);
var warnings = config.get('warnings');
var overrides = config.get('overrides');
if (overrides && overrides[component]) {
if (overrides[component].dependencies) {
componentConfigFile.dependencies = overrides[component].dependencies;
}
if (overrides[component].main) {
componentConfigFile.main = overrides[component].main;
}
}
var mains = findMainFiles(config, component, componentConfigFile);
var fileTypes = _.chain(mains).map(path.extname).unique().value();
dep.main = mains;
dep.type = fileTypes;
dep.name = componentConfigFile.name;
var depIsExcluded = _.find(config.get('exclude'), function (pattern) {
return path.join(config.get('bower-directory'), component).match(pattern);
});
if (dep.main.length === 0 && !depIsExcluded) {
// can't find the main file. this config file is useless!
warnings.push(component + ' was not injected in your file.');
warnings.push(
'Please go take a look in "' + path.join(config.get('bower-directory'), component) + '" for the file you need, then manually include it in your file.');
config.set('warnings', warnings);
return;
}
if (componentConfigFile.dependencies) {
dep.dependencies = componentConfigFile.dependencies;
_.each(componentConfigFile.dependencies, gatherInfo(config));
}
config.get('global-dependencies').set(component, dep);
};
} | [
"function",
"(",
"config",
")",
"{",
"/**\n * The iterator function, which is called on each component.\n *\n * @param {string} version the version of the component\n * @param {string} component the name of the component\n * @return {undefined}\n */",
"return",
"function",
"(",
"version",
",",
"component",
")",
"{",
"var",
"dep",
"=",
"config",
".",
"get",
"(",
"'global-dependencies'",
")",
".",
"get",
"(",
"component",
")",
"||",
"{",
"main",
":",
"''",
",",
"type",
":",
"''",
",",
"name",
":",
"''",
",",
"dependencies",
":",
"{",
"}",
"}",
";",
"console",
".",
"log",
"(",
"version",
",",
"component",
")",
";",
"var",
"componentConfigFile",
"=",
"findComponentConfigFile",
"(",
"config",
",",
"component",
")",
";",
"var",
"warnings",
"=",
"config",
".",
"get",
"(",
"'warnings'",
")",
";",
"var",
"overrides",
"=",
"config",
".",
"get",
"(",
"'overrides'",
")",
";",
"if",
"(",
"overrides",
"&&",
"overrides",
"[",
"component",
"]",
")",
"{",
"if",
"(",
"overrides",
"[",
"component",
"]",
".",
"dependencies",
")",
"{",
"componentConfigFile",
".",
"dependencies",
"=",
"overrides",
"[",
"component",
"]",
".",
"dependencies",
";",
"}",
"if",
"(",
"overrides",
"[",
"component",
"]",
".",
"main",
")",
"{",
"componentConfigFile",
".",
"main",
"=",
"overrides",
"[",
"component",
"]",
".",
"main",
";",
"}",
"}",
"var",
"mains",
"=",
"findMainFiles",
"(",
"config",
",",
"component",
",",
"componentConfigFile",
")",
";",
"var",
"fileTypes",
"=",
"_",
".",
"chain",
"(",
"mains",
")",
".",
"map",
"(",
"path",
".",
"extname",
")",
".",
"unique",
"(",
")",
".",
"value",
"(",
")",
";",
"dep",
".",
"main",
"=",
"mains",
";",
"dep",
".",
"type",
"=",
"fileTypes",
";",
"dep",
".",
"name",
"=",
"componentConfigFile",
".",
"name",
";",
"var",
"depIsExcluded",
"=",
"_",
".",
"find",
"(",
"config",
".",
"get",
"(",
"'exclude'",
")",
",",
"function",
"(",
"pattern",
")",
"{",
"return",
"path",
".",
"join",
"(",
"config",
".",
"get",
"(",
"'bower-directory'",
")",
",",
"component",
")",
".",
"match",
"(",
"pattern",
")",
";",
"}",
")",
";",
"if",
"(",
"dep",
".",
"main",
".",
"length",
"===",
"0",
"&&",
"!",
"depIsExcluded",
")",
"{",
"// can't find the main file. this config file is useless!",
"warnings",
".",
"push",
"(",
"component",
"+",
"' was not injected in your file.'",
")",
";",
"warnings",
".",
"push",
"(",
"'Please go take a look in \"'",
"+",
"path",
".",
"join",
"(",
"config",
".",
"get",
"(",
"'bower-directory'",
")",
",",
"component",
")",
"+",
"'\" for the file you need, then manually include it in your file.'",
")",
";",
"config",
".",
"set",
"(",
"'warnings'",
",",
"warnings",
")",
";",
"return",
";",
"}",
"if",
"(",
"componentConfigFile",
".",
"dependencies",
")",
"{",
"dep",
".",
"dependencies",
"=",
"componentConfigFile",
".",
"dependencies",
";",
"_",
".",
"each",
"(",
"componentConfigFile",
".",
"dependencies",
",",
"gatherInfo",
"(",
"config",
")",
")",
";",
"}",
"config",
".",
"get",
"(",
"'global-dependencies'",
")",
".",
"set",
"(",
"component",
",",
"dep",
")",
";",
"}",
";",
"}"
] | Store the information our prioritizer will need to determine rank.
@param {object} config the global configuration object
@return {function} the iterator function, called on every component | [
"Store",
"the",
"information",
"our",
"prioritizer",
"will",
"need",
"to",
"determine",
"rank",
"."
] | 73b6e8b25bca095d665bf85478429996613f88a3 | https://github.com/evaisse/wiresrc/blob/73b6e8b25bca095d665bf85478429996613f88a3/lib/detect.js#L78-L140 |
|
56,752 | evaisse/wiresrc | lib/detect.js | function (a, b) {
var aNeedsB = false;
var bNeedsA = false;
aNeedsB = Object.
keys(a.dependencies).
some(function (dependency) {
return dependency === b.name;
});
if (aNeedsB) {
return 1;
}
bNeedsA = Object.
keys(b.dependencies).
some(function (dependency) {
return dependency === a.name;
});
if (bNeedsA) {
return -1;
}
return 0;
} | javascript | function (a, b) {
var aNeedsB = false;
var bNeedsA = false;
aNeedsB = Object.
keys(a.dependencies).
some(function (dependency) {
return dependency === b.name;
});
if (aNeedsB) {
return 1;
}
bNeedsA = Object.
keys(b.dependencies).
some(function (dependency) {
return dependency === a.name;
});
if (bNeedsA) {
return -1;
}
return 0;
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"aNeedsB",
"=",
"false",
";",
"var",
"bNeedsA",
"=",
"false",
";",
"aNeedsB",
"=",
"Object",
".",
"keys",
"(",
"a",
".",
"dependencies",
")",
".",
"some",
"(",
"function",
"(",
"dependency",
")",
"{",
"return",
"dependency",
"===",
"b",
".",
"name",
";",
"}",
")",
";",
"if",
"(",
"aNeedsB",
")",
"{",
"return",
"1",
";",
"}",
"bNeedsA",
"=",
"Object",
".",
"keys",
"(",
"b",
".",
"dependencies",
")",
".",
"some",
"(",
"function",
"(",
"dependency",
")",
"{",
"return",
"dependency",
"===",
"a",
".",
"name",
";",
"}",
")",
";",
"if",
"(",
"bNeedsA",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Compare two dependencies to determine priority.
@param {object} a dependency a
@param {object} b dependency b
@return {number} the priority of dependency a in comparison to dependency b | [
"Compare",
"two",
"dependencies",
"to",
"determine",
"priority",
"."
] | 73b6e8b25bca095d665bf85478429996613f88a3 | https://github.com/evaisse/wiresrc/blob/73b6e8b25bca095d665bf85478429996613f88a3/lib/detect.js#L150-L175 |
|
56,753 | evaisse/wiresrc | lib/detect.js | function (left, right) {
var result = [];
var leftIndex = 0;
var rightIndex = 0;
while (leftIndex < left.length && rightIndex < right.length) {
if (dependencyComparator(left[leftIndex], right[rightIndex]) < 1) {
result.push(left[leftIndex++]);
} else {
result.push(right[rightIndex++]);
}
}
return result.
concat(left.slice(leftIndex)).
concat(right.slice(rightIndex));
} | javascript | function (left, right) {
var result = [];
var leftIndex = 0;
var rightIndex = 0;
while (leftIndex < left.length && rightIndex < right.length) {
if (dependencyComparator(left[leftIndex], right[rightIndex]) < 1) {
result.push(left[leftIndex++]);
} else {
result.push(right[rightIndex++]);
}
}
return result.
concat(left.slice(leftIndex)).
concat(right.slice(rightIndex));
} | [
"function",
"(",
"left",
",",
"right",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"leftIndex",
"=",
"0",
";",
"var",
"rightIndex",
"=",
"0",
";",
"while",
"(",
"leftIndex",
"<",
"left",
".",
"length",
"&&",
"rightIndex",
"<",
"right",
".",
"length",
")",
"{",
"if",
"(",
"dependencyComparator",
"(",
"left",
"[",
"leftIndex",
"]",
",",
"right",
"[",
"rightIndex",
"]",
")",
"<",
"1",
")",
"{",
"result",
".",
"push",
"(",
"left",
"[",
"leftIndex",
"++",
"]",
")",
";",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"right",
"[",
"rightIndex",
"++",
"]",
")",
";",
"}",
"}",
"return",
"result",
".",
"concat",
"(",
"left",
".",
"slice",
"(",
"leftIndex",
")",
")",
".",
"concat",
"(",
"right",
".",
"slice",
"(",
"rightIndex",
")",
")",
";",
"}"
] | Take two arrays, sort based on their dependency relationship, then merge them
together.
@param {array} left
@param {array} right
@return {array} the sorted, merged array | [
"Take",
"two",
"arrays",
"sort",
"based",
"on",
"their",
"dependency",
"relationship",
"then",
"merge",
"them",
"together",
"."
] | 73b6e8b25bca095d665bf85478429996613f88a3 | https://github.com/evaisse/wiresrc/blob/73b6e8b25bca095d665bf85478429996613f88a3/lib/detect.js#L186-L202 |
|
56,754 | evaisse/wiresrc | lib/detect.js | function (items) {
if (items.length < 2) {
return items;
}
var middle = Math.floor(items.length / 2);
return merge(
mergeSort(items.slice(0, middle)),
mergeSort(items.slice(middle))
);
} | javascript | function (items) {
if (items.length < 2) {
return items;
}
var middle = Math.floor(items.length / 2);
return merge(
mergeSort(items.slice(0, middle)),
mergeSort(items.slice(middle))
);
} | [
"function",
"(",
"items",
")",
"{",
"if",
"(",
"items",
".",
"length",
"<",
"2",
")",
"{",
"return",
"items",
";",
"}",
"var",
"middle",
"=",
"Math",
".",
"floor",
"(",
"items",
".",
"length",
"/",
"2",
")",
";",
"return",
"merge",
"(",
"mergeSort",
"(",
"items",
".",
"slice",
"(",
"0",
",",
"middle",
")",
")",
",",
"mergeSort",
"(",
"items",
".",
"slice",
"(",
"middle",
")",
")",
")",
";",
"}"
] | Take an array and slice it in halves, sorting each half along the way.
@param {array} items
@return {array} the sorted array | [
"Take",
"an",
"array",
"and",
"slice",
"it",
"in",
"halves",
"sorting",
"each",
"half",
"along",
"the",
"way",
"."
] | 73b6e8b25bca095d665bf85478429996613f88a3 | https://github.com/evaisse/wiresrc/blob/73b6e8b25bca095d665bf85478429996613f88a3/lib/detect.js#L211-L222 |
|
56,755 | evaisse/wiresrc | lib/detect.js | function (allDependencies, patterns) {
return _.transform(allDependencies, function (result, dependencies, fileType) {
result[fileType] = _.reject(dependencies, function (dependency) {
return _.find(patterns, function (pattern) {
return dependency.match(pattern);
});
});
});
} | javascript | function (allDependencies, patterns) {
return _.transform(allDependencies, function (result, dependencies, fileType) {
result[fileType] = _.reject(dependencies, function (dependency) {
return _.find(patterns, function (pattern) {
return dependency.match(pattern);
});
});
});
} | [
"function",
"(",
"allDependencies",
",",
"patterns",
")",
"{",
"return",
"_",
".",
"transform",
"(",
"allDependencies",
",",
"function",
"(",
"result",
",",
"dependencies",
",",
"fileType",
")",
"{",
"result",
"[",
"fileType",
"]",
"=",
"_",
".",
"reject",
"(",
"dependencies",
",",
"function",
"(",
"dependency",
")",
"{",
"return",
"_",
".",
"find",
"(",
"patterns",
",",
"function",
"(",
"pattern",
")",
"{",
"return",
"dependency",
".",
"match",
"(",
"pattern",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Excludes dependencies that match any of the patterns.
@param {array} allDependencies array of dependencies to filter
@param {array} patterns array of patterns to match against
@return {array} items that don't match any of the patterns | [
"Excludes",
"dependencies",
"that",
"match",
"any",
"of",
"the",
"patterns",
"."
] | 73b6e8b25bca095d665bf85478429996613f88a3 | https://github.com/evaisse/wiresrc/blob/73b6e8b25bca095d665bf85478429996613f88a3/lib/detect.js#L279-L287 |
|
56,756 | tether/methodd | index.js | proxy | function proxy (original, routes) {
return new Proxy(original, {
get(target, key, receiver) {
const method = target[key]
if (method) return method
else return function (path, ...args) {
const cb = args[0]
if (typeof cb === 'function') {
original.add(key, path, cb)
} else {
const fn = routes[key]
return fn && fn.exec(path, ...args)
}
}
}
})
} | javascript | function proxy (original, routes) {
return new Proxy(original, {
get(target, key, receiver) {
const method = target[key]
if (method) return method
else return function (path, ...args) {
const cb = args[0]
if (typeof cb === 'function') {
original.add(key, path, cb)
} else {
const fn = routes[key]
return fn && fn.exec(path, ...args)
}
}
}
})
} | [
"function",
"proxy",
"(",
"original",
",",
"routes",
")",
"{",
"return",
"new",
"Proxy",
"(",
"original",
",",
"{",
"get",
"(",
"target",
",",
"key",
",",
"receiver",
")",
"{",
"const",
"method",
"=",
"target",
"[",
"key",
"]",
"if",
"(",
"method",
")",
"return",
"method",
"else",
"return",
"function",
"(",
"path",
",",
"...",
"args",
")",
"{",
"const",
"cb",
"=",
"args",
"[",
"0",
"]",
"if",
"(",
"typeof",
"cb",
"===",
"'function'",
")",
"{",
"original",
".",
"add",
"(",
"key",
",",
"path",
",",
"cb",
")",
"}",
"else",
"{",
"const",
"fn",
"=",
"routes",
"[",
"key",
"]",
"return",
"fn",
"&&",
"fn",
".",
"exec",
"(",
"path",
",",
"...",
"args",
")",
"}",
"}",
"}",
"}",
")",
"}"
] | Proxy function with router.
@param {Function} original
@param {Object} routes
@api private | [
"Proxy",
"function",
"with",
"router",
"."
] | 1604ffb43e28742003ea74c080d936e5a4f203fd | https://github.com/tether/methodd/blob/1604ffb43e28742003ea74c080d936e5a4f203fd/index.js#L98-L114 |
56,757 | YusukeHirao/sceg | lib/fn/gen.js | gen | function gen(path) {
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = assignConfig_1.default(option, path);
return globElements_1.default(config).then(readElements_1.default(config)).then(optimize_1.default()).then(render_1.default(config));
} | javascript | function gen(path) {
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = assignConfig_1.default(option, path);
return globElements_1.default(config).then(readElements_1.default(config)).then(optimize_1.default()).then(render_1.default(config));
} | [
"function",
"gen",
"(",
"path",
")",
"{",
"var",
"option",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"var",
"config",
"=",
"assignConfig_1",
".",
"default",
"(",
"option",
",",
"path",
")",
";",
"return",
"globElements_1",
".",
"default",
"(",
"config",
")",
".",
"then",
"(",
"readElements_1",
".",
"default",
"(",
"config",
")",
")",
".",
"then",
"(",
"optimize_1",
".",
"default",
"(",
")",
")",
".",
"then",
"(",
"render_1",
".",
"default",
"(",
"config",
")",
")",
";",
"}"
] | Generate guide page from elements
@param path Paths of element files that glob pattern
@param option Optional configure
@return rendered HTML string | [
"Generate",
"guide",
"page",
"from",
"elements"
] | 4cde1e56d48dd3b604cc2ddff36b2e9de3348771 | https://github.com/YusukeHirao/sceg/blob/4cde1e56d48dd3b604cc2ddff36b2e9de3348771/lib/fn/gen.js#L16-L21 |
56,758 | oliversalzburg/strider-modern-extensions | lib/proxy.js | toStriderProxy | function toStriderProxy(instance) {
debug(`Proxying async plugin: ${instance.constructor.name}`);
const functionsInInstance = Object.getOwnPropertyNames(Object.getPrototypeOf(instance)).filter(propertyName => {
return typeof instance[propertyName] === 'function' && propertyName !== 'constructor';
});
functionsInInstance.forEach(functionInInstance => {
instance[`${functionInInstance}Async`] = instance[functionInInstance];
instance[functionInInstance] = function () {
const args = Array.from(arguments);
const done = args.pop();
return instance[`${functionInInstance}Async`].apply(instance, args)
.then(result => done(null, result))
.catch(errors.ExtensionConfigurationError, error => {
debug(`Extension configuration error:${error.message}` || error.info);
return done(error);
})
.catch(error => done(error));
};
Object.defineProperty(instance[functionInInstance], 'length', {
value: instance[`${functionInInstance}Async`].length
});
});
return instance;
} | javascript | function toStriderProxy(instance) {
debug(`Proxying async plugin: ${instance.constructor.name}`);
const functionsInInstance = Object.getOwnPropertyNames(Object.getPrototypeOf(instance)).filter(propertyName => {
return typeof instance[propertyName] === 'function' && propertyName !== 'constructor';
});
functionsInInstance.forEach(functionInInstance => {
instance[`${functionInInstance}Async`] = instance[functionInInstance];
instance[functionInInstance] = function () {
const args = Array.from(arguments);
const done = args.pop();
return instance[`${functionInInstance}Async`].apply(instance, args)
.then(result => done(null, result))
.catch(errors.ExtensionConfigurationError, error => {
debug(`Extension configuration error:${error.message}` || error.info);
return done(error);
})
.catch(error => done(error));
};
Object.defineProperty(instance[functionInInstance], 'length', {
value: instance[`${functionInInstance}Async`].length
});
});
return instance;
} | [
"function",
"toStriderProxy",
"(",
"instance",
")",
"{",
"debug",
"(",
"`",
"${",
"instance",
".",
"constructor",
".",
"name",
"}",
"`",
")",
";",
"const",
"functionsInInstance",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"Object",
".",
"getPrototypeOf",
"(",
"instance",
")",
")",
".",
"filter",
"(",
"propertyName",
"=>",
"{",
"return",
"typeof",
"instance",
"[",
"propertyName",
"]",
"===",
"'function'",
"&&",
"propertyName",
"!==",
"'constructor'",
";",
"}",
")",
";",
"functionsInInstance",
".",
"forEach",
"(",
"functionInInstance",
"=>",
"{",
"instance",
"[",
"`",
"${",
"functionInInstance",
"}",
"`",
"]",
"=",
"instance",
"[",
"functionInInstance",
"]",
";",
"instance",
"[",
"functionInInstance",
"]",
"=",
"function",
"(",
")",
"{",
"const",
"args",
"=",
"Array",
".",
"from",
"(",
"arguments",
")",
";",
"const",
"done",
"=",
"args",
".",
"pop",
"(",
")",
";",
"return",
"instance",
"[",
"`",
"${",
"functionInInstance",
"}",
"`",
"]",
".",
"apply",
"(",
"instance",
",",
"args",
")",
".",
"then",
"(",
"result",
"=>",
"done",
"(",
"null",
",",
"result",
")",
")",
".",
"catch",
"(",
"errors",
".",
"ExtensionConfigurationError",
",",
"error",
"=>",
"{",
"debug",
"(",
"`",
"${",
"error",
".",
"message",
"}",
"`",
"||",
"error",
".",
"info",
")",
";",
"return",
"done",
"(",
"error",
")",
";",
"}",
")",
".",
"catch",
"(",
"error",
"=>",
"done",
"(",
"error",
")",
")",
";",
"}",
";",
"Object",
".",
"defineProperty",
"(",
"instance",
"[",
"functionInInstance",
"]",
",",
"'length'",
",",
"{",
"value",
":",
"instance",
"[",
"`",
"${",
"functionInInstance",
"}",
"`",
"]",
".",
"length",
"}",
")",
";",
"}",
")",
";",
"return",
"instance",
";",
"}"
] | Given an input object, replaces all functions on that object with node-style callback equivalents.
The methods are expected to return promises. It's kind of like a reverse-promisifyAll.
The original methods are available by their old name with "Async" appended.
@param {Object} instance
@returns {Object} | [
"Given",
"an",
"input",
"object",
"replaces",
"all",
"functions",
"on",
"that",
"object",
"with",
"node",
"-",
"style",
"callback",
"equivalents",
".",
"The",
"methods",
"are",
"expected",
"to",
"return",
"promises",
".",
"It",
"s",
"kind",
"of",
"like",
"a",
"reverse",
"-",
"promisifyAll",
".",
"The",
"original",
"methods",
"are",
"available",
"by",
"their",
"old",
"name",
"with",
"Async",
"appended",
"."
] | f8c37e49af1f05e34c66afff71d977e4b316289b | https://github.com/oliversalzburg/strider-modern-extensions/blob/f8c37e49af1f05e34c66afff71d977e4b316289b/lib/proxy.js#L15-L41 |
56,759 | phated/grunt-enyo | tasks/init/enyo/root/enyo/source/touch/Thumb.js | function(inShowing) {
if (inShowing && inShowing != this.showing) {
if (this.scrollBounds[this.sizeDimension] >= this.scrollBounds[this.dimension]) {
return;
}
}
if (this.hasNode()) {
this.cancelDelayHide();
}
if (inShowing != this.showing) {
var last = this.showing;
this.showing = inShowing;
this.showingChanged(last);
}
} | javascript | function(inShowing) {
if (inShowing && inShowing != this.showing) {
if (this.scrollBounds[this.sizeDimension] >= this.scrollBounds[this.dimension]) {
return;
}
}
if (this.hasNode()) {
this.cancelDelayHide();
}
if (inShowing != this.showing) {
var last = this.showing;
this.showing = inShowing;
this.showingChanged(last);
}
} | [
"function",
"(",
"inShowing",
")",
"{",
"if",
"(",
"inShowing",
"&&",
"inShowing",
"!=",
"this",
".",
"showing",
")",
"{",
"if",
"(",
"this",
".",
"scrollBounds",
"[",
"this",
".",
"sizeDimension",
"]",
">=",
"this",
".",
"scrollBounds",
"[",
"this",
".",
"dimension",
"]",
")",
"{",
"return",
";",
"}",
"}",
"if",
"(",
"this",
".",
"hasNode",
"(",
")",
")",
"{",
"this",
".",
"cancelDelayHide",
"(",
")",
";",
"}",
"if",
"(",
"inShowing",
"!=",
"this",
".",
"showing",
")",
"{",
"var",
"last",
"=",
"this",
".",
"showing",
";",
"this",
".",
"showing",
"=",
"inShowing",
";",
"this",
".",
"showingChanged",
"(",
"last",
")",
";",
"}",
"}"
] | implement set because showing is not changed while we delayHide but we want to cancel the hide. | [
"implement",
"set",
"because",
"showing",
"is",
"not",
"changed",
"while",
"we",
"delayHide",
"but",
"we",
"want",
"to",
"cancel",
"the",
"hide",
"."
] | d2990ee4cd85eea8db4108c43086c6d8c3c90c30 | https://github.com/phated/grunt-enyo/blob/d2990ee4cd85eea8db4108c43086c6d8c3c90c30/tasks/init/enyo/root/enyo/source/touch/Thumb.js#L88-L102 |
|
56,760 | jharding/yapawapa | lib/utils.js | extend | function extend(obj) {
var slice = Array.prototype.slice;
slice.call(arguments, 1).forEach(function(source) {
var getter
, setter;
for (var key in source) {
getter = source.__lookupGetter__(key);
setter = source.__lookupSetter__(key);
if (getter || setter) {
getter && obj.__defineGetter__(key, getter);
setter && obj.__defineSetter__(key, setter);
}
else {
obj[key] = source[key];
}
}
});
return obj;
} | javascript | function extend(obj) {
var slice = Array.prototype.slice;
slice.call(arguments, 1).forEach(function(source) {
var getter
, setter;
for (var key in source) {
getter = source.__lookupGetter__(key);
setter = source.__lookupSetter__(key);
if (getter || setter) {
getter && obj.__defineGetter__(key, getter);
setter && obj.__defineSetter__(key, setter);
}
else {
obj[key] = source[key];
}
}
});
return obj;
} | [
"function",
"extend",
"(",
"obj",
")",
"{",
"var",
"slice",
"=",
"Array",
".",
"prototype",
".",
"slice",
";",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
".",
"forEach",
"(",
"function",
"(",
"source",
")",
"{",
"var",
"getter",
",",
"setter",
";",
"for",
"(",
"var",
"key",
"in",
"source",
")",
"{",
"getter",
"=",
"source",
".",
"__lookupGetter__",
"(",
"key",
")",
";",
"setter",
"=",
"source",
".",
"__lookupSetter__",
"(",
"key",
")",
";",
"if",
"(",
"getter",
"||",
"setter",
")",
"{",
"getter",
"&&",
"obj",
".",
"__defineGetter__",
"(",
"key",
",",
"getter",
")",
";",
"setter",
"&&",
"obj",
".",
"__defineSetter__",
"(",
"key",
",",
"setter",
")",
";",
"}",
"else",
"{",
"obj",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"}",
"}",
"}",
")",
";",
"return",
"obj",
";",
"}"
] | roll custom extend since underscore's doesn't play nice with getters and setters | [
"roll",
"custom",
"extend",
"since",
"underscore",
"s",
"doesn",
"t",
"play",
"nice",
"with",
"getters",
"and",
"setters"
] | 18816447a9fcfbe744cadf2d6f0fdceca443c05f | https://github.com/jharding/yapawapa/blob/18816447a9fcfbe744cadf2d6f0fdceca443c05f/lib/utils.js#L12-L35 |
56,761 | Industryswarm/isnode-mod-data | lib/mongodb/mongodb-core/lib/sdam/cursor.js | setCursorDeadAndNotified | function setCursorDeadAndNotified(cursor, callback) {
cursor.s.dead = true;
setCursorNotified(cursor, callback);
} | javascript | function setCursorDeadAndNotified(cursor, callback) {
cursor.s.dead = true;
setCursorNotified(cursor, callback);
} | [
"function",
"setCursorDeadAndNotified",
"(",
"cursor",
",",
"callback",
")",
"{",
"cursor",
".",
"s",
".",
"dead",
"=",
"true",
";",
"setCursorNotified",
"(",
"cursor",
",",
"callback",
")",
";",
"}"
] | Mark cursor as being dead and notified | [
"Mark",
"cursor",
"as",
"being",
"dead",
"and",
"notified"
] | 5adc639b88a0d72cbeef23a6b5df7f4540745089 | https://github.com/Industryswarm/isnode-mod-data/blob/5adc639b88a0d72cbeef23a6b5df7f4540745089/lib/mongodb/mongodb-core/lib/sdam/cursor.js#L523-L526 |
56,762 | TribeMedia/tribemedia-kurento-client-core | lib/complexTypes/RTCOutboundRTPStreamStats.js | RTCOutboundRTPStreamStats | function RTCOutboundRTPStreamStats(rTCOutboundRTPStreamStatsDict){
if(!(this instanceof RTCOutboundRTPStreamStats))
return new RTCOutboundRTPStreamStats(rTCOutboundRTPStreamStatsDict)
// Check rTCOutboundRTPStreamStatsDict has the required fields
checkType('int', 'rTCOutboundRTPStreamStatsDict.packetsSent', rTCOutboundRTPStreamStatsDict.packetsSent, {required: true});
checkType('int', 'rTCOutboundRTPStreamStatsDict.bytesSent', rTCOutboundRTPStreamStatsDict.bytesSent, {required: true});
checkType('float', 'rTCOutboundRTPStreamStatsDict.targetBitrate', rTCOutboundRTPStreamStatsDict.targetBitrate, {required: true});
checkType('float', 'rTCOutboundRTPStreamStatsDict.roundTripTime', rTCOutboundRTPStreamStatsDict.roundTripTime, {required: true});
// Init parent class
RTCOutboundRTPStreamStats.super_.call(this, rTCOutboundRTPStreamStatsDict)
// Set object properties
Object.defineProperties(this, {
packetsSent: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.packetsSent
},
bytesSent: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.bytesSent
},
targetBitrate: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.targetBitrate
},
roundTripTime: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.roundTripTime
}
})
} | javascript | function RTCOutboundRTPStreamStats(rTCOutboundRTPStreamStatsDict){
if(!(this instanceof RTCOutboundRTPStreamStats))
return new RTCOutboundRTPStreamStats(rTCOutboundRTPStreamStatsDict)
// Check rTCOutboundRTPStreamStatsDict has the required fields
checkType('int', 'rTCOutboundRTPStreamStatsDict.packetsSent', rTCOutboundRTPStreamStatsDict.packetsSent, {required: true});
checkType('int', 'rTCOutboundRTPStreamStatsDict.bytesSent', rTCOutboundRTPStreamStatsDict.bytesSent, {required: true});
checkType('float', 'rTCOutboundRTPStreamStatsDict.targetBitrate', rTCOutboundRTPStreamStatsDict.targetBitrate, {required: true});
checkType('float', 'rTCOutboundRTPStreamStatsDict.roundTripTime', rTCOutboundRTPStreamStatsDict.roundTripTime, {required: true});
// Init parent class
RTCOutboundRTPStreamStats.super_.call(this, rTCOutboundRTPStreamStatsDict)
// Set object properties
Object.defineProperties(this, {
packetsSent: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.packetsSent
},
bytesSent: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.bytesSent
},
targetBitrate: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.targetBitrate
},
roundTripTime: {
writable: true,
enumerable: true,
value: rTCOutboundRTPStreamStatsDict.roundTripTime
}
})
} | [
"function",
"RTCOutboundRTPStreamStats",
"(",
"rTCOutboundRTPStreamStatsDict",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"RTCOutboundRTPStreamStats",
")",
")",
"return",
"new",
"RTCOutboundRTPStreamStats",
"(",
"rTCOutboundRTPStreamStatsDict",
")",
"// Check rTCOutboundRTPStreamStatsDict has the required fields",
"checkType",
"(",
"'int'",
",",
"'rTCOutboundRTPStreamStatsDict.packetsSent'",
",",
"rTCOutboundRTPStreamStatsDict",
".",
"packetsSent",
",",
"{",
"required",
":",
"true",
"}",
")",
";",
"checkType",
"(",
"'int'",
",",
"'rTCOutboundRTPStreamStatsDict.bytesSent'",
",",
"rTCOutboundRTPStreamStatsDict",
".",
"bytesSent",
",",
"{",
"required",
":",
"true",
"}",
")",
";",
"checkType",
"(",
"'float'",
",",
"'rTCOutboundRTPStreamStatsDict.targetBitrate'",
",",
"rTCOutboundRTPStreamStatsDict",
".",
"targetBitrate",
",",
"{",
"required",
":",
"true",
"}",
")",
";",
"checkType",
"(",
"'float'",
",",
"'rTCOutboundRTPStreamStatsDict.roundTripTime'",
",",
"rTCOutboundRTPStreamStatsDict",
".",
"roundTripTime",
",",
"{",
"required",
":",
"true",
"}",
")",
";",
"// Init parent class",
"RTCOutboundRTPStreamStats",
".",
"super_",
".",
"call",
"(",
"this",
",",
"rTCOutboundRTPStreamStatsDict",
")",
"// Set object properties",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"packetsSent",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"rTCOutboundRTPStreamStatsDict",
".",
"packetsSent",
"}",
",",
"bytesSent",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"rTCOutboundRTPStreamStatsDict",
".",
"bytesSent",
"}",
",",
"targetBitrate",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"rTCOutboundRTPStreamStatsDict",
".",
"targetBitrate",
"}",
",",
"roundTripTime",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"rTCOutboundRTPStreamStatsDict",
".",
"roundTripTime",
"}",
"}",
")",
"}"
] | Statistics that represents the measurement metrics for the outgoing media
stream.
@constructor module:core/complexTypes.RTCOutboundRTPStreamStats
@property {external:Integer} packetsSent
Total number of RTP packets sent for this SSRC.
@property {external:Integer} bytesSent
Total number of bytes sent for this SSRC.
@property {external:Number} targetBitrate
Presently configured bitrate target of this SSRC, in bits per second.
@property {external:Number} roundTripTime
Estimated round trip time (seconds) for this SSRC based on the RTCP
timestamp.
@extends module:core.RTCRTPStreamStats | [
"Statistics",
"that",
"represents",
"the",
"measurement",
"metrics",
"for",
"the",
"outgoing",
"media",
"stream",
"."
] | de4c0094644aae91320e330f9cea418a3ac55468 | https://github.com/TribeMedia/tribemedia-kurento-client-core/blob/de4c0094644aae91320e330f9cea418a3ac55468/lib/complexTypes/RTCOutboundRTPStreamStats.js#L45-L81 |
56,763 | pinyin/outline | vendor/transformation-matrix/inverse.js | inverse | function inverse(matrix) {
//http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D
var a = matrix.a,
b = matrix.b,
c = matrix.c,
d = matrix.d,
e = matrix.e,
f = matrix.f;
var denom = a * d - b * c;
return {
a: d / denom,
b: b / -denom,
c: c / -denom,
d: a / denom,
e: (d * e - c * f) / -denom,
f: (b * e - a * f) / denom
};
} | javascript | function inverse(matrix) {
//http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D
var a = matrix.a,
b = matrix.b,
c = matrix.c,
d = matrix.d,
e = matrix.e,
f = matrix.f;
var denom = a * d - b * c;
return {
a: d / denom,
b: b / -denom,
c: c / -denom,
d: a / denom,
e: (d * e - c * f) / -denom,
f: (b * e - a * f) / denom
};
} | [
"function",
"inverse",
"(",
"matrix",
")",
"{",
"//http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D",
"var",
"a",
"=",
"matrix",
".",
"a",
",",
"b",
"=",
"matrix",
".",
"b",
",",
"c",
"=",
"matrix",
".",
"c",
",",
"d",
"=",
"matrix",
".",
"d",
",",
"e",
"=",
"matrix",
".",
"e",
",",
"f",
"=",
"matrix",
".",
"f",
";",
"var",
"denom",
"=",
"a",
"*",
"d",
"-",
"b",
"*",
"c",
";",
"return",
"{",
"a",
":",
"d",
"/",
"denom",
",",
"b",
":",
"b",
"/",
"-",
"denom",
",",
"c",
":",
"c",
"/",
"-",
"denom",
",",
"d",
":",
"a",
"/",
"denom",
",",
"e",
":",
"(",
"d",
"*",
"e",
"-",
"c",
"*",
"f",
")",
"/",
"-",
"denom",
",",
"f",
":",
"(",
"b",
"*",
"e",
"-",
"a",
"*",
"f",
")",
"/",
"denom",
"}",
";",
"}"
] | Calculate a matrix that is the inverse of the provided matrix
@param matrix Affine matrix
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"matrix",
"that",
"is",
"the",
"inverse",
"of",
"the",
"provided",
"matrix"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/inverse.js#L13-L34 |
56,764 | brianloveswords/gogo | lib/ext-underscore.js | curry | function curry(fn, obj) {
// create a local copy of the function. don't apply anything yet
// optionally bind an object to the `this` of the function.
var newFunction = _.bind(fn, (obj || null));
// curried functions always take one argument
return function () {
// create another copy of the function with the arguments applied
var me = _.partial(newFunction, arguments);
// take advantage of the fact that bind changes the method signature:
// if we have no arguments left, run the method
if (!me.length) return me();
// otherwise, curry again and return that.
return curry(me);
};
} | javascript | function curry(fn, obj) {
// create a local copy of the function. don't apply anything yet
// optionally bind an object to the `this` of the function.
var newFunction = _.bind(fn, (obj || null));
// curried functions always take one argument
return function () {
// create another copy of the function with the arguments applied
var me = _.partial(newFunction, arguments);
// take advantage of the fact that bind changes the method signature:
// if we have no arguments left, run the method
if (!me.length) return me();
// otherwise, curry again and return that.
return curry(me);
};
} | [
"function",
"curry",
"(",
"fn",
",",
"obj",
")",
"{",
"// create a local copy of the function. don't apply anything yet",
"// optionally bind an object to the `this` of the function.",
"var",
"newFunction",
"=",
"_",
".",
"bind",
"(",
"fn",
",",
"(",
"obj",
"||",
"null",
")",
")",
";",
"// curried functions always take one argument",
"return",
"function",
"(",
")",
"{",
"// create another copy of the function with the arguments applied",
"var",
"me",
"=",
"_",
".",
"partial",
"(",
"newFunction",
",",
"arguments",
")",
";",
"// take advantage of the fact that bind changes the method signature:",
"// if we have no arguments left, run the method",
"if",
"(",
"!",
"me",
".",
"length",
")",
"return",
"me",
"(",
")",
";",
"// otherwise, curry again and return that.",
"return",
"curry",
"(",
"me",
")",
";",
"}",
";",
"}"
] | this takes advantage of ES5 bind's awesome ability to do partial application | [
"this",
"takes",
"advantage",
"of",
"ES5",
"bind",
"s",
"awesome",
"ability",
"to",
"do",
"partial",
"application"
] | f17ee794e0439ed961907f52b91bcb74dcca351a | https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/ext-underscore.js#L21-L38 |
56,765 | brianloveswords/gogo | lib/ext-underscore.js | function (o, path) {
function iterator(m, p) { return _.getv(p)(m); }
return _.reduce(path, iterator, o);
} | javascript | function (o, path) {
function iterator(m, p) { return _.getv(p)(m); }
return _.reduce(path, iterator, o);
} | [
"function",
"(",
"o",
",",
"path",
")",
"{",
"function",
"iterator",
"(",
"m",
",",
"p",
")",
"{",
"return",
"_",
".",
"getv",
"(",
"p",
")",
"(",
"m",
")",
";",
"}",
"return",
"_",
".",
"reduce",
"(",
"path",
",",
"iterator",
",",
"o",
")",
";",
"}"
] | perform a root canal on an object. depends on getv | [
"perform",
"a",
"root",
"canal",
"on",
"an",
"object",
".",
"depends",
"on",
"getv"
] | f17ee794e0439ed961907f52b91bcb74dcca351a | https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/ext-underscore.js#L65-L68 |
|
56,766 | brianloveswords/gogo | lib/ext-underscore.js | function (a) {
var elements = _.reject(_.rest(arguments), _.isMissing);
return a.push.apply(a, elements);
} | javascript | function (a) {
var elements = _.reject(_.rest(arguments), _.isMissing);
return a.push.apply(a, elements);
} | [
"function",
"(",
"a",
")",
"{",
"var",
"elements",
"=",
"_",
".",
"reject",
"(",
"_",
".",
"rest",
"(",
"arguments",
")",
",",
"_",
".",
"isMissing",
")",
";",
"return",
"a",
".",
"push",
".",
"apply",
"(",
"a",
",",
"elements",
")",
";",
"}"
] | push only defined elements to the array | [
"push",
"only",
"defined",
"elements",
"to",
"the",
"array"
] | f17ee794e0439ed961907f52b91bcb74dcca351a | https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/ext-underscore.js#L119-L122 |
|
56,767 | inlight-media/gulp-asset | index.js | function(opts) {
var opts = opts || {};
var shouldHash = typeof opts.hash != 'undefined' ? opts.hash : defaults.hash;
var prefix = _.flatten([defaults.prefix]);
var shouldPrefix = typeof opts.shouldPrefix != 'undefined' ? opts.shouldPrefix : true;
return through.obj(function(file, enc, cb) {
var originalPath = file.path;
// Get hash of contents
var hash = md5(opts, file.contents.toString());
// Construct new filename
var ext = path.extname(file.path);
var basePath = path.basename(file.path, ext);
var filename = typeof hash !== 'undefined' ? basePath + '-' + hash + ext : basePath + ext;
file.path = path.join(path.dirname(file.path), filename);
// Add to manifest
var base = path.join(file.cwd, defaults.src);
var key = originalPath.replace(base, '');
// @TODO: Instead of this it could use "glob" module to regex delete files
// Check for existing value and whether cleanup is set
var existing = manifest[key];
if (existing && existing.src && defaults.cleanup) {
// Delete the file
fs.unlink(path.join(file.cwd, defaults.dest, existing.src));
} else if (defaults.cleanup && shouldHash) {
// Check if cleanup and hash enabled then we can remove any non hashed version from dest directory
var nonHashPath = path.join(path.dirname(originalPath), basePath + ext).replace(base, '');
var absPath = path.join(file.cwd, defaults.dest, nonHashPath);
fs.exists(absPath, function(exists) {
if (!exists) return;
fs.unlink(absPath);
});
}
var filePrefix = shouldPrefix ? prefix[index % prefix.length] : '';
// Finally add new value to manifest
var src = file.path.replace(base, '');
manifest[key] = {
index: index++,
src: src,
dest: filePrefix + src
};
// Write manifest file
writeManifest();
// Return and continue
this.push(file);
cb();
});
} | javascript | function(opts) {
var opts = opts || {};
var shouldHash = typeof opts.hash != 'undefined' ? opts.hash : defaults.hash;
var prefix = _.flatten([defaults.prefix]);
var shouldPrefix = typeof opts.shouldPrefix != 'undefined' ? opts.shouldPrefix : true;
return through.obj(function(file, enc, cb) {
var originalPath = file.path;
// Get hash of contents
var hash = md5(opts, file.contents.toString());
// Construct new filename
var ext = path.extname(file.path);
var basePath = path.basename(file.path, ext);
var filename = typeof hash !== 'undefined' ? basePath + '-' + hash + ext : basePath + ext;
file.path = path.join(path.dirname(file.path), filename);
// Add to manifest
var base = path.join(file.cwd, defaults.src);
var key = originalPath.replace(base, '');
// @TODO: Instead of this it could use "glob" module to regex delete files
// Check for existing value and whether cleanup is set
var existing = manifest[key];
if (existing && existing.src && defaults.cleanup) {
// Delete the file
fs.unlink(path.join(file.cwd, defaults.dest, existing.src));
} else if (defaults.cleanup && shouldHash) {
// Check if cleanup and hash enabled then we can remove any non hashed version from dest directory
var nonHashPath = path.join(path.dirname(originalPath), basePath + ext).replace(base, '');
var absPath = path.join(file.cwd, defaults.dest, nonHashPath);
fs.exists(absPath, function(exists) {
if (!exists) return;
fs.unlink(absPath);
});
}
var filePrefix = shouldPrefix ? prefix[index % prefix.length] : '';
// Finally add new value to manifest
var src = file.path.replace(base, '');
manifest[key] = {
index: index++,
src: src,
dest: filePrefix + src
};
// Write manifest file
writeManifest();
// Return and continue
this.push(file);
cb();
});
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"var",
"shouldHash",
"=",
"typeof",
"opts",
".",
"hash",
"!=",
"'undefined'",
"?",
"opts",
".",
"hash",
":",
"defaults",
".",
"hash",
";",
"var",
"prefix",
"=",
"_",
".",
"flatten",
"(",
"[",
"defaults",
".",
"prefix",
"]",
")",
";",
"var",
"shouldPrefix",
"=",
"typeof",
"opts",
".",
"shouldPrefix",
"!=",
"'undefined'",
"?",
"opts",
".",
"shouldPrefix",
":",
"true",
";",
"return",
"through",
".",
"obj",
"(",
"function",
"(",
"file",
",",
"enc",
",",
"cb",
")",
"{",
"var",
"originalPath",
"=",
"file",
".",
"path",
";",
"// Get hash of contents",
"var",
"hash",
"=",
"md5",
"(",
"opts",
",",
"file",
".",
"contents",
".",
"toString",
"(",
")",
")",
";",
"// Construct new filename",
"var",
"ext",
"=",
"path",
".",
"extname",
"(",
"file",
".",
"path",
")",
";",
"var",
"basePath",
"=",
"path",
".",
"basename",
"(",
"file",
".",
"path",
",",
"ext",
")",
";",
"var",
"filename",
"=",
"typeof",
"hash",
"!==",
"'undefined'",
"?",
"basePath",
"+",
"'-'",
"+",
"hash",
"+",
"ext",
":",
"basePath",
"+",
"ext",
";",
"file",
".",
"path",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"file",
".",
"path",
")",
",",
"filename",
")",
";",
"// Add to manifest",
"var",
"base",
"=",
"path",
".",
"join",
"(",
"file",
".",
"cwd",
",",
"defaults",
".",
"src",
")",
";",
"var",
"key",
"=",
"originalPath",
".",
"replace",
"(",
"base",
",",
"''",
")",
";",
"// @TODO: Instead of this it could use \"glob\" module to regex delete files",
"// Check for existing value and whether cleanup is set",
"var",
"existing",
"=",
"manifest",
"[",
"key",
"]",
";",
"if",
"(",
"existing",
"&&",
"existing",
".",
"src",
"&&",
"defaults",
".",
"cleanup",
")",
"{",
"// Delete the file",
"fs",
".",
"unlink",
"(",
"path",
".",
"join",
"(",
"file",
".",
"cwd",
",",
"defaults",
".",
"dest",
",",
"existing",
".",
"src",
")",
")",
";",
"}",
"else",
"if",
"(",
"defaults",
".",
"cleanup",
"&&",
"shouldHash",
")",
"{",
"// Check if cleanup and hash enabled then we can remove any non hashed version from dest directory",
"var",
"nonHashPath",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"originalPath",
")",
",",
"basePath",
"+",
"ext",
")",
".",
"replace",
"(",
"base",
",",
"''",
")",
";",
"var",
"absPath",
"=",
"path",
".",
"join",
"(",
"file",
".",
"cwd",
",",
"defaults",
".",
"dest",
",",
"nonHashPath",
")",
";",
"fs",
".",
"exists",
"(",
"absPath",
",",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"!",
"exists",
")",
"return",
";",
"fs",
".",
"unlink",
"(",
"absPath",
")",
";",
"}",
")",
";",
"}",
"var",
"filePrefix",
"=",
"shouldPrefix",
"?",
"prefix",
"[",
"index",
"%",
"prefix",
".",
"length",
"]",
":",
"''",
";",
"// Finally add new value to manifest",
"var",
"src",
"=",
"file",
".",
"path",
".",
"replace",
"(",
"base",
",",
"''",
")",
";",
"manifest",
"[",
"key",
"]",
"=",
"{",
"index",
":",
"index",
"++",
",",
"src",
":",
"src",
",",
"dest",
":",
"filePrefix",
"+",
"src",
"}",
";",
"// Write manifest file",
"writeManifest",
"(",
")",
";",
"// Return and continue",
"this",
".",
"push",
"(",
"file",
")",
";",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | Gets md5 from file contents and writes new filename with hash included to destinations | [
"Gets",
"md5",
"from",
"file",
"contents",
"and",
"writes",
"new",
"filename",
"with",
"hash",
"included",
"to",
"destinations"
] | 13cbd41def828c9af1de50d44b753e1bf05c3916 | https://github.com/inlight-media/gulp-asset/blob/13cbd41def828c9af1de50d44b753e1bf05c3916/index.js#L85-L139 |
|
56,768 | nil/options-config | src/index.js | validateValue | function validateValue(key, valObj, list) {
let type; let valid; let range; let regex;
const object = list[key];
const val = hasKey(valObj, key) ? valObj[key] : 'value_not_defined';
let defaultValue = object;
if (object) {
type = object.type;
valid = object.valid;
range = object.range;
regex = object.regex;
defaultValue = hasKey(object, 'default') ? object.default : object;
}
if (isDeclared(val)) {
return defaultValue;
}
if (isMatch(key, val, regex)) {
return val;
}
if (isValid(key, val, valid, type)) {
return val;
}
isType(key, val, type);
inRange(key, val, range);
return val;
} | javascript | function validateValue(key, valObj, list) {
let type; let valid; let range; let regex;
const object = list[key];
const val = hasKey(valObj, key) ? valObj[key] : 'value_not_defined';
let defaultValue = object;
if (object) {
type = object.type;
valid = object.valid;
range = object.range;
regex = object.regex;
defaultValue = hasKey(object, 'default') ? object.default : object;
}
if (isDeclared(val)) {
return defaultValue;
}
if (isMatch(key, val, regex)) {
return val;
}
if (isValid(key, val, valid, type)) {
return val;
}
isType(key, val, type);
inRange(key, val, range);
return val;
} | [
"function",
"validateValue",
"(",
"key",
",",
"valObj",
",",
"list",
")",
"{",
"let",
"type",
";",
"let",
"valid",
";",
"let",
"range",
";",
"let",
"regex",
";",
"const",
"object",
"=",
"list",
"[",
"key",
"]",
";",
"const",
"val",
"=",
"hasKey",
"(",
"valObj",
",",
"key",
")",
"?",
"valObj",
"[",
"key",
"]",
":",
"'value_not_defined'",
";",
"let",
"defaultValue",
"=",
"object",
";",
"if",
"(",
"object",
")",
"{",
"type",
"=",
"object",
".",
"type",
";",
"valid",
"=",
"object",
".",
"valid",
";",
"range",
"=",
"object",
".",
"range",
";",
"regex",
"=",
"object",
".",
"regex",
";",
"defaultValue",
"=",
"hasKey",
"(",
"object",
",",
"'default'",
")",
"?",
"object",
".",
"default",
":",
"object",
";",
"}",
"if",
"(",
"isDeclared",
"(",
"val",
")",
")",
"{",
"return",
"defaultValue",
";",
"}",
"if",
"(",
"isMatch",
"(",
"key",
",",
"val",
",",
"regex",
")",
")",
"{",
"return",
"val",
";",
"}",
"if",
"(",
"isValid",
"(",
"key",
",",
"val",
",",
"valid",
",",
"type",
")",
")",
"{",
"return",
"val",
";",
"}",
"isType",
"(",
"key",
",",
"val",
",",
"type",
")",
";",
"inRange",
"(",
"key",
",",
"val",
",",
"range",
")",
";",
"return",
"val",
";",
"}"
] | Checks if a value fits the restrictions.
@param {string} key - The name of the option
@param {object} valObj - The value to check.
@param {object} list - The replacement restrictions.
@returns A value, whether it is the default or the given by the user. | [
"Checks",
"if",
"a",
"value",
"fits",
"the",
"restrictions",
"."
] | 40fb5011d3d931913318d7e852c029ab816885b8 | https://github.com/nil/options-config/blob/40fb5011d3d931913318d7e852c029ab816885b8/src/index.js#L19-L52 |
56,769 | dekujs/assert-element | index.js | classes | function classes(input) {
if (!input) return [];
assert.strictEqual(typeof input, 'string', 'expected a string for the class name');
if (!input.trim()) return [];
return input.trim().split(/\s+/g);
} | javascript | function classes(input) {
if (!input) return [];
assert.strictEqual(typeof input, 'string', 'expected a string for the class name');
if (!input.trim()) return [];
return input.trim().split(/\s+/g);
} | [
"function",
"classes",
"(",
"input",
")",
"{",
"if",
"(",
"!",
"input",
")",
"return",
"[",
"]",
";",
"assert",
".",
"strictEqual",
"(",
"typeof",
"input",
",",
"'string'",
",",
"'expected a string for the class name'",
")",
";",
"if",
"(",
"!",
"input",
".",
"trim",
"(",
")",
")",
"return",
"[",
"]",
";",
"return",
"input",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
"g",
")",
";",
"}"
] | private helpers
Parse the given `input` into an `Array` of class names. Will always return
an `Array`, even if it's empty.
@param {String} [input] The class attribute string.
@return {Array} | [
"private",
"helpers",
"Parse",
"the",
"given",
"input",
"into",
"an",
"Array",
"of",
"class",
"names",
".",
"Will",
"always",
"return",
"an",
"Array",
"even",
"if",
"it",
"s",
"empty",
"."
] | a275c98825249101f0e790635a1d33b300b16bc1 | https://github.com/dekujs/assert-element/blob/a275c98825249101f0e790635a1d33b300b16bc1/index.js#L162-L167 |
56,770 | dekujs/assert-element | index.js | deepChild | function deepChild(root, path) {
return path.reduce(function (node, index, x) {
assert(index in node.children, 'child does not exist at the given deep index ' + path.join('.'));
return node.children[index];
}, root);
} | javascript | function deepChild(root, path) {
return path.reduce(function (node, index, x) {
assert(index in node.children, 'child does not exist at the given deep index ' + path.join('.'));
return node.children[index];
}, root);
} | [
"function",
"deepChild",
"(",
"root",
",",
"path",
")",
"{",
"return",
"path",
".",
"reduce",
"(",
"function",
"(",
"node",
",",
"index",
",",
"x",
")",
"{",
"assert",
"(",
"index",
"in",
"node",
".",
"children",
",",
"'child does not exist at the given deep index '",
"+",
"path",
".",
"join",
"(",
"'.'",
")",
")",
";",
"return",
"node",
".",
"children",
"[",
"index",
"]",
";",
"}",
",",
"root",
")",
";",
"}"
] | Retrieve a deep child via an input array `index` of indices to traverse.
@param {Object} node The virtual node to traverse.
@param {Array:Number} path The path to traverse.
@return {Object} | [
"Retrieve",
"a",
"deep",
"child",
"via",
"an",
"input",
"array",
"index",
"of",
"indices",
"to",
"traverse",
"."
] | a275c98825249101f0e790635a1d33b300b16bc1 | https://github.com/dekujs/assert-element/blob/a275c98825249101f0e790635a1d33b300b16bc1/index.js#L177-L182 |
56,771 | mhelgeson/b9 | src/post/index.js | handler | function handler ( err, data ){
if ( callback != null ){
callback.apply( b9, arguments );
}
// only emit events when there is no error
if ( err == null ){
b9.emit.call( b9, method, data );
}
} | javascript | function handler ( err, data ){
if ( callback != null ){
callback.apply( b9, arguments );
}
// only emit events when there is no error
if ( err == null ){
b9.emit.call( b9, method, data );
}
} | [
"function",
"handler",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"callback",
"!=",
"null",
")",
"{",
"callback",
".",
"apply",
"(",
"b9",
",",
"arguments",
")",
";",
"}",
"// only emit events when there is no error",
"if",
"(",
"err",
"==",
"null",
")",
"{",
"b9",
".",
"emit",
".",
"call",
"(",
"b9",
",",
"method",
",",
"data",
")",
";",
"}",
"}"
] | wrap callback with an event emitter | [
"wrap",
"callback",
"with",
"an",
"event",
"emitter"
] | 5f7ad9ac7c3fa586b06f6460b70a42c50b34e6f1 | https://github.com/mhelgeson/b9/blob/5f7ad9ac7c3fa586b06f6460b70a42c50b34e6f1/src/post/index.js#L54-L62 |
56,772 | mgesmundo/port-manager | lib/service.js | Service | function Service(manager, name, port, heartbeat) {
var _name = name;
/**
* @property {String} name The name of the service
*/
Object.defineProperty(this, 'name', {
get: function get() {
return _name;
},
enumerable: true
});
var _port = port;
/**
* @property {Number} port The port claimed by the service
*/
Object.defineProperty(this, 'port', {
get: function get() {
return _port;
},
enumerable: true
});
var _heartbeatInterval;
if (heartbeat !== 0) {
debug('set heartbeat %d', heartbeat);
_heartbeatInterval = setInterval(heartbeatTest.call(this, manager), heartbeat);
}
/**
* @property {Number} heartbeat The heartbeat counter for the periodic port checking
*/
Object.defineProperty(this, 'heartbeat', {
get: function get() {
return _heartbeatInterval;
}
});
} | javascript | function Service(manager, name, port, heartbeat) {
var _name = name;
/**
* @property {String} name The name of the service
*/
Object.defineProperty(this, 'name', {
get: function get() {
return _name;
},
enumerable: true
});
var _port = port;
/**
* @property {Number} port The port claimed by the service
*/
Object.defineProperty(this, 'port', {
get: function get() {
return _port;
},
enumerable: true
});
var _heartbeatInterval;
if (heartbeat !== 0) {
debug('set heartbeat %d', heartbeat);
_heartbeatInterval = setInterval(heartbeatTest.call(this, manager), heartbeat);
}
/**
* @property {Number} heartbeat The heartbeat counter for the periodic port checking
*/
Object.defineProperty(this, 'heartbeat', {
get: function get() {
return _heartbeatInterval;
}
});
} | [
"function",
"Service",
"(",
"manager",
",",
"name",
",",
"port",
",",
"heartbeat",
")",
"{",
"var",
"_name",
"=",
"name",
";",
"/**\n * @property {String} name The name of the service\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'name'",
",",
"{",
"get",
":",
"function",
"get",
"(",
")",
"{",
"return",
"_name",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"var",
"_port",
"=",
"port",
";",
"/**\n * @property {Number} port The port claimed by the service\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'port'",
",",
"{",
"get",
":",
"function",
"get",
"(",
")",
"{",
"return",
"_port",
";",
"}",
",",
"enumerable",
":",
"true",
"}",
")",
";",
"var",
"_heartbeatInterval",
";",
"if",
"(",
"heartbeat",
"!==",
"0",
")",
"{",
"debug",
"(",
"'set heartbeat %d'",
",",
"heartbeat",
")",
";",
"_heartbeatInterval",
"=",
"setInterval",
"(",
"heartbeatTest",
".",
"call",
"(",
"this",
",",
"manager",
")",
",",
"heartbeat",
")",
";",
"}",
"/**\n * @property {Number} heartbeat The heartbeat counter for the periodic port checking\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'heartbeat'",
",",
"{",
"get",
":",
"function",
"get",
"(",
")",
"{",
"return",
"_heartbeatInterval",
";",
"}",
"}",
")",
";",
"}"
] | The service to manage
@class node_modules.port_manager.Service
@param {Manager} manager The manager instance that store all services
@param {String} name The name of the service
@param {Number} port The port claimed by the service
@param {Number} [heartbeat] The heartbeat timer
@constructor | [
"The",
"service",
"to",
"manage"
] | a09356b9063c228616d0ffc56217b93c479f2604 | https://github.com/mgesmundo/port-manager/blob/a09356b9063c228616d0ffc56217b93c479f2604/lib/service.js#L29-L63 |
56,773 | rranauro/boxspringjs | workflows.js | function(docs, callback) {
remaining = docs;
console.log('[ remove ] info: ' + remaining +' to remove.');
async.eachLimit(_.range(0, docs, 10000), 1, handleOneBlock, callback);
} | javascript | function(docs, callback) {
remaining = docs;
console.log('[ remove ] info: ' + remaining +' to remove.');
async.eachLimit(_.range(0, docs, 10000), 1, handleOneBlock, callback);
} | [
"function",
"(",
"docs",
",",
"callback",
")",
"{",
"remaining",
"=",
"docs",
";",
"console",
".",
"log",
"(",
"'[ remove ] info: '",
"+",
"remaining",
"+",
"' to remove.'",
")",
";",
"async",
".",
"eachLimit",
"(",
"_",
".",
"range",
"(",
"0",
",",
"docs",
",",
"10000",
")",
",",
"1",
",",
"handleOneBlock",
",",
"callback",
")",
";",
"}"
] | fetch the 'removeView' list; returns array of objects marked "_deleted" | [
"fetch",
"the",
"removeView",
"list",
";",
"returns",
"array",
"of",
"objects",
"marked",
"_deleted"
] | 43fd13ae45ba5b16ba9144084b96748a1cd8c0ea | https://github.com/rranauro/boxspringjs/blob/43fd13ae45ba5b16ba9144084b96748a1cd8c0ea/workflows.js#L83-L87 |
|
56,774 | CCISEL/connect-controller | example/lib/controllers/favorites.js | function(teamId, req) {
const favoritesList = req.app.locals.favoritesList
const index = favoritesList.findIndex(t => t.id == teamId)
if(index < 0) {
const err = new Error('Team is not parte of Favorites!!!')
err.status = 409
throw err
}
favoritesList.splice(index, 1)
} | javascript | function(teamId, req) {
const favoritesList = req.app.locals.favoritesList
const index = favoritesList.findIndex(t => t.id == teamId)
if(index < 0) {
const err = new Error('Team is not parte of Favorites!!!')
err.status = 409
throw err
}
favoritesList.splice(index, 1)
} | [
"function",
"(",
"teamId",
",",
"req",
")",
"{",
"const",
"favoritesList",
"=",
"req",
".",
"app",
".",
"locals",
".",
"favoritesList",
"const",
"index",
"=",
"favoritesList",
".",
"findIndex",
"(",
"t",
"=>",
"t",
".",
"id",
"==",
"teamId",
")",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"const",
"err",
"=",
"new",
"Error",
"(",
"'Team is not parte of Favorites!!!'",
")",
"err",
".",
"status",
"=",
"409",
"throw",
"err",
"}",
"favoritesList",
".",
"splice",
"(",
"index",
",",
"1",
")",
"}"
] | This is a synchronous action that does not do any IO.
Simply returning with NO exceptions just means success and
connect-controller will send a 200 response status. | [
"This",
"is",
"a",
"synchronous",
"action",
"that",
"does",
"not",
"do",
"any",
"IO",
".",
"Simply",
"returning",
"with",
"NO",
"exceptions",
"just",
"means",
"success",
"and",
"connect",
"-",
"controller",
"will",
"send",
"a",
"200",
"response",
"status",
"."
] | c8e2587c5a31e3cb54e3668c4b98b7b7526d69b4 | https://github.com/CCISEL/connect-controller/blob/c8e2587c5a31e3cb54e3668c4b98b7b7526d69b4/example/lib/controllers/favorites.js#L34-L43 |
|
56,775 | richRemer/twixt-click | click.js | click | function click(target, handler) {
target.addEventListener("click", function(evt) {
evt.stopPropagation();
evt.preventDefault();
handler.call(this);
});
} | javascript | function click(target, handler) {
target.addEventListener("click", function(evt) {
evt.stopPropagation();
evt.preventDefault();
handler.call(this);
});
} | [
"function",
"click",
"(",
"target",
",",
"handler",
")",
"{",
"target",
".",
"addEventListener",
"(",
"\"click\"",
",",
"function",
"(",
"evt",
")",
"{",
"evt",
".",
"stopPropagation",
"(",
")",
";",
"evt",
".",
"preventDefault",
"(",
")",
";",
"handler",
".",
"call",
"(",
"this",
")",
";",
"}",
")",
";",
"}"
] | Attach click event handler.
@param {EventTarget} target
@param {function} handler | [
"Attach",
"click",
"event",
"handler",
"."
] | e3b0574f148c8060b19b1fe4517ede460474e821 | https://github.com/richRemer/twixt-click/blob/e3b0574f148c8060b19b1fe4517ede460474e821/click.js#L6-L12 |
56,776 | fshost/api-chain | api-chain.js | function(name, method) {
API.prototype[name] = function() {
var api = this;
var args = Array.prototype.slice.call(arguments);
this.chain(function(next) {
var cargs = [].slice.call(arguments);
cargs = args.concat(cargs);
// args.push(next);
method.apply(api, cargs);
});
return this;
};
return this;
} | javascript | function(name, method) {
API.prototype[name] = function() {
var api = this;
var args = Array.prototype.slice.call(arguments);
this.chain(function(next) {
var cargs = [].slice.call(arguments);
cargs = args.concat(cargs);
// args.push(next);
method.apply(api, cargs);
});
return this;
};
return this;
} | [
"function",
"(",
"name",
",",
"method",
")",
"{",
"API",
".",
"prototype",
"[",
"name",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"api",
"=",
"this",
";",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"this",
".",
"chain",
"(",
"function",
"(",
"next",
")",
"{",
"var",
"cargs",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"cargs",
"=",
"args",
".",
"concat",
"(",
"cargs",
")",
";",
"// args.push(next);",
"method",
".",
"apply",
"(",
"api",
",",
"cargs",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}",
";",
"return",
"this",
";",
"}"
] | add a method to the prototype | [
"add",
"a",
"method",
"to",
"the",
"prototype"
] | d98df82575b0a0afd20c10424c0c038389b32f80 | https://github.com/fshost/api-chain/blob/d98df82575b0a0afd20c10424c0c038389b32f80/api-chain.js#L67-L82 |
|
56,777 | fshost/api-chain | api-chain.js | function(err) {
if (err) this._onError(err);
if (this._continueErrors || !err) {
var args = [].slice.call(arguments);
if (this._callbacks.length > 0) {
this._isQueueRunning = true;
var cb = this._callbacks.shift();
cb = cb.bind(this);
args = args.slice(1);
args.push(this.next);
cb.apply(this, args);
} else {
this._isQueueRunning = false;
this.start = (function() {
this.start = null;
this.next.apply(this, args);
}).bind(this);
}
}
return this;
} | javascript | function(err) {
if (err) this._onError(err);
if (this._continueErrors || !err) {
var args = [].slice.call(arguments);
if (this._callbacks.length > 0) {
this._isQueueRunning = true;
var cb = this._callbacks.shift();
cb = cb.bind(this);
args = args.slice(1);
args.push(this.next);
cb.apply(this, args);
} else {
this._isQueueRunning = false;
this.start = (function() {
this.start = null;
this.next.apply(this, args);
}).bind(this);
}
}
return this;
} | [
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"this",
".",
"_onError",
"(",
"err",
")",
";",
"if",
"(",
"this",
".",
"_continueErrors",
"||",
"!",
"err",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"if",
"(",
"this",
".",
"_callbacks",
".",
"length",
">",
"0",
")",
"{",
"this",
".",
"_isQueueRunning",
"=",
"true",
";",
"var",
"cb",
"=",
"this",
".",
"_callbacks",
".",
"shift",
"(",
")",
";",
"cb",
"=",
"cb",
".",
"bind",
"(",
"this",
")",
";",
"args",
"=",
"args",
".",
"slice",
"(",
"1",
")",
";",
"args",
".",
"push",
"(",
"this",
".",
"next",
")",
";",
"cb",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
"else",
"{",
"this",
".",
"_isQueueRunning",
"=",
"false",
";",
"this",
".",
"start",
"=",
"(",
"function",
"(",
")",
"{",
"this",
".",
"start",
"=",
"null",
";",
"this",
".",
"next",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
")",
".",
"bind",
"(",
"this",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | advance to next cb | [
"advance",
"to",
"next",
"cb"
] | d98df82575b0a0afd20c10424c0c038389b32f80 | https://github.com/fshost/api-chain/blob/d98df82575b0a0afd20c10424c0c038389b32f80/api-chain.js#L96-L118 |
|
56,778 | fshost/api-chain | api-chain.js | function(name, value, immediate) {
if (immediate) {
this[name] = value;
} else this.chain(function() {
var args = Array.prototype.slice.call(arguments);
var next = args.pop();
this[name] = value;
args.unshift(null);
next.apply(this, args);
});
return this;
} | javascript | function(name, value, immediate) {
if (immediate) {
this[name] = value;
} else this.chain(function() {
var args = Array.prototype.slice.call(arguments);
var next = args.pop();
this[name] = value;
args.unshift(null);
next.apply(this, args);
});
return this;
} | [
"function",
"(",
"name",
",",
"value",
",",
"immediate",
")",
"{",
"if",
"(",
"immediate",
")",
"{",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"}",
"else",
"this",
".",
"chain",
"(",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"var",
"next",
"=",
"args",
".",
"pop",
"(",
")",
";",
"this",
"[",
"name",
"]",
"=",
"value",
";",
"args",
".",
"unshift",
"(",
"null",
")",
";",
"next",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] | set instance property | [
"set",
"instance",
"property"
] | d98df82575b0a0afd20c10424c0c038389b32f80 | https://github.com/fshost/api-chain/blob/d98df82575b0a0afd20c10424c0c038389b32f80/api-chain.js#L121-L132 |
|
56,779 | fshost/api-chain | api-chain.js | function(cb) {
cb = this.wrap(cb);
this._callbacks.push(cb);
if (!this._isQueueRunning) {
if (this.start) {
this.start();
} else this.next();
// this.start();
}
return this;
} | javascript | function(cb) {
cb = this.wrap(cb);
this._callbacks.push(cb);
if (!this._isQueueRunning) {
if (this.start) {
this.start();
} else this.next();
// this.start();
}
return this;
} | [
"function",
"(",
"cb",
")",
"{",
"cb",
"=",
"this",
".",
"wrap",
"(",
"cb",
")",
";",
"this",
".",
"_callbacks",
".",
"push",
"(",
"cb",
")",
";",
"if",
"(",
"!",
"this",
".",
"_isQueueRunning",
")",
"{",
"if",
"(",
"this",
".",
"start",
")",
"{",
"this",
".",
"start",
"(",
")",
";",
"}",
"else",
"this",
".",
"next",
"(",
")",
";",
"// this.start();",
"}",
"return",
"this",
";",
"}"
] | add a callback to the execution chain | [
"add",
"a",
"callback",
"to",
"the",
"execution",
"chain"
] | d98df82575b0a0afd20c10424c0c038389b32f80 | https://github.com/fshost/api-chain/blob/d98df82575b0a0afd20c10424c0c038389b32f80/api-chain.js#L151-L161 |
|
56,780 | iolo/node-toybox | async.js | parallel | function parallel(promises, limit) {
var d = Q.defer();
var total = promises.length;
var results = new Array(total);
var firstErr;
var running = 0;
var finished = 0;
var next = 0;
limit = limit || total;
function sched() {
while (next < total && running < limit) {
DEBUG && debug('*** sched #', next, '***', promises[next].inspect());
exec(next++);
}
}
function exec(id) {
running += 1;
var promise = promises[id];
DEBUG && debug('>>> running', running);
DEBUG && debug('*** run #', id, '***', promise.inspect());
promise.then(function (result) {
DEBUG && debug('#', id, 'then ***', result);
results[id] = result; // collect all result
d.notify(promise.inspect());
}).catch(function (err) {
DEBUG && debug('#', id, 'catch ***', err);
firstErr = firstErr || err; // keep the first error
}).finally(function () {
DEBUG && debug('#', id, 'finally ***', promise.inspect());
if (++finished === total) {
DEBUG && debug('>>> finished all ***', firstErr, results);
return firstErr ? d.reject(firstErr) : d.resolve(results);
}
DEBUG && debug('>>> finished', finished);
running -= 1;
sched();
});
}
sched();
return d.promise;
} | javascript | function parallel(promises, limit) {
var d = Q.defer();
var total = promises.length;
var results = new Array(total);
var firstErr;
var running = 0;
var finished = 0;
var next = 0;
limit = limit || total;
function sched() {
while (next < total && running < limit) {
DEBUG && debug('*** sched #', next, '***', promises[next].inspect());
exec(next++);
}
}
function exec(id) {
running += 1;
var promise = promises[id];
DEBUG && debug('>>> running', running);
DEBUG && debug('*** run #', id, '***', promise.inspect());
promise.then(function (result) {
DEBUG && debug('#', id, 'then ***', result);
results[id] = result; // collect all result
d.notify(promise.inspect());
}).catch(function (err) {
DEBUG && debug('#', id, 'catch ***', err);
firstErr = firstErr || err; // keep the first error
}).finally(function () {
DEBUG && debug('#', id, 'finally ***', promise.inspect());
if (++finished === total) {
DEBUG && debug('>>> finished all ***', firstErr, results);
return firstErr ? d.reject(firstErr) : d.resolve(results);
}
DEBUG && debug('>>> finished', finished);
running -= 1;
sched();
});
}
sched();
return d.promise;
} | [
"function",
"parallel",
"(",
"promises",
",",
"limit",
")",
"{",
"var",
"d",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"total",
"=",
"promises",
".",
"length",
";",
"var",
"results",
"=",
"new",
"Array",
"(",
"total",
")",
";",
"var",
"firstErr",
";",
"var",
"running",
"=",
"0",
";",
"var",
"finished",
"=",
"0",
";",
"var",
"next",
"=",
"0",
";",
"limit",
"=",
"limit",
"||",
"total",
";",
"function",
"sched",
"(",
")",
"{",
"while",
"(",
"next",
"<",
"total",
"&&",
"running",
"<",
"limit",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'*** sched #'",
",",
"next",
",",
"'***'",
",",
"promises",
"[",
"next",
"]",
".",
"inspect",
"(",
")",
")",
";",
"exec",
"(",
"next",
"++",
")",
";",
"}",
"}",
"function",
"exec",
"(",
"id",
")",
"{",
"running",
"+=",
"1",
";",
"var",
"promise",
"=",
"promises",
"[",
"id",
"]",
";",
"DEBUG",
"&&",
"debug",
"(",
"'>>> running'",
",",
"running",
")",
";",
"DEBUG",
"&&",
"debug",
"(",
"'*** run #'",
",",
"id",
",",
"'***'",
",",
"promise",
".",
"inspect",
"(",
")",
")",
";",
"promise",
".",
"then",
"(",
"function",
"(",
"result",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'#'",
",",
"id",
",",
"'then ***'",
",",
"result",
")",
";",
"results",
"[",
"id",
"]",
"=",
"result",
";",
"// collect all result",
"d",
".",
"notify",
"(",
"promise",
".",
"inspect",
"(",
")",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'#'",
",",
"id",
",",
"'catch ***'",
",",
"err",
")",
";",
"firstErr",
"=",
"firstErr",
"||",
"err",
";",
"// keep the first error",
"}",
")",
".",
"finally",
"(",
"function",
"(",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'#'",
",",
"id",
",",
"'finally ***'",
",",
"promise",
".",
"inspect",
"(",
")",
")",
";",
"if",
"(",
"++",
"finished",
"===",
"total",
")",
"{",
"DEBUG",
"&&",
"debug",
"(",
"'>>> finished all ***'",
",",
"firstErr",
",",
"results",
")",
";",
"return",
"firstErr",
"?",
"d",
".",
"reject",
"(",
"firstErr",
")",
":",
"d",
".",
"resolve",
"(",
"results",
")",
";",
"}",
"DEBUG",
"&&",
"debug",
"(",
"'>>> finished'",
",",
"finished",
")",
";",
"running",
"-=",
"1",
";",
"sched",
"(",
")",
";",
"}",
")",
";",
"}",
"sched",
"(",
")",
";",
"return",
"d",
".",
"promise",
";",
"}"
] | !!debug.enabled;
@param {Array.<promise>} promises
@param {number} [limit]
@returns {promise} | [
"!!debug",
".",
"enabled",
";"
] | d03e48b5e4b3deb022688fee59dd33a2b71819d0 | https://github.com/iolo/node-toybox/blob/d03e48b5e4b3deb022688fee59dd33a2b71819d0/async.js#L15-L59 |
56,781 | Techniv/node-command-io | libs/commandio.js | addCommand | function addCommand(descriptor){
// Check descriptor type.
var err = {};
if( !checkDescriptor(descriptor, err) ){
logger.error(
'The command descriptor is invalid.',
new Error('[command.io] Invalid command descriptor ("'+err.key+'": expected "'+err.expect+'", have "'+err.type+'").')
);
logger.error('Please check this doc: https://github.com/Techniv/node-command-io/wiki/Command-descriptor-refactoring');
return module.exports;
}
var name = descriptor.name;
descriptor.controller = new CommandController(descriptor);
// Index the command descriptor
commandDescriptors[name] = descriptor;
// Chain addCommand
return module.exports;
} | javascript | function addCommand(descriptor){
// Check descriptor type.
var err = {};
if( !checkDescriptor(descriptor, err) ){
logger.error(
'The command descriptor is invalid.',
new Error('[command.io] Invalid command descriptor ("'+err.key+'": expected "'+err.expect+'", have "'+err.type+'").')
);
logger.error('Please check this doc: https://github.com/Techniv/node-command-io/wiki/Command-descriptor-refactoring');
return module.exports;
}
var name = descriptor.name;
descriptor.controller = new CommandController(descriptor);
// Index the command descriptor
commandDescriptors[name] = descriptor;
// Chain addCommand
return module.exports;
} | [
"function",
"addCommand",
"(",
"descriptor",
")",
"{",
"// Check descriptor type.",
"var",
"err",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"checkDescriptor",
"(",
"descriptor",
",",
"err",
")",
")",
"{",
"logger",
".",
"error",
"(",
"'The command descriptor is invalid.'",
",",
"new",
"Error",
"(",
"'[command.io] Invalid command descriptor (\"'",
"+",
"err",
".",
"key",
"+",
"'\": expected \"'",
"+",
"err",
".",
"expect",
"+",
"'\", have \"'",
"+",
"err",
".",
"type",
"+",
"'\").'",
")",
")",
";",
"logger",
".",
"error",
"(",
"'Please check this doc: https://github.com/Techniv/node-command-io/wiki/Command-descriptor-refactoring'",
")",
";",
"return",
"module",
".",
"exports",
";",
"}",
"var",
"name",
"=",
"descriptor",
".",
"name",
";",
"descriptor",
".",
"controller",
"=",
"new",
"CommandController",
"(",
"descriptor",
")",
";",
"// Index the command descriptor",
"commandDescriptors",
"[",
"name",
"]",
"=",
"descriptor",
";",
"// Chain addCommand",
"return",
"module",
".",
"exports",
";",
"}"
] | Add a command
@param name string
@param description string
@param action Function
@returns Object return Command.IO API. | [
"Add",
"a",
"command"
] | 3d3cdfac83b2e14e801a9fc94ced9024c757674f | https://github.com/Techniv/node-command-io/blob/3d3cdfac83b2e14e801a9fc94ced9024c757674f/libs/commandio.js#L122-L142 |
56,782 | Techniv/node-command-io | libs/commandio.js | addCommands | function addCommands(commands){
for(var i in commands){
var commandObj = commands[i];
addCommand(commandObj);
}
return module.exports;
} | javascript | function addCommands(commands){
for(var i in commands){
var commandObj = commands[i];
addCommand(commandObj);
}
return module.exports;
} | [
"function",
"addCommands",
"(",
"commands",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"commands",
")",
"{",
"var",
"commandObj",
"=",
"commands",
"[",
"i",
"]",
";",
"addCommand",
"(",
"commandObj",
")",
";",
"}",
"return",
"module",
".",
"exports",
";",
"}"
] | Add commands recursively.
@param commands Object[] An array of command descriptor {name: string, description: string, :action: function}.
@return Object Return Command.IO API. | [
"Add",
"commands",
"recursively",
"."
] | 3d3cdfac83b2e14e801a9fc94ced9024c757674f | https://github.com/Techniv/node-command-io/blob/3d3cdfac83b2e14e801a9fc94ced9024c757674f/libs/commandio.js#L149-L156 |
56,783 | Techniv/node-command-io | libs/commandio.js | CommandController | function CommandController(descriptor){
Object.defineProperties(this, {
name: {
get: function(){
return descriptor.name;
}
},
description: {
get: function(){
return descriptor.description;
}
},
CommandError: {
get: function(){
return LocalCommandError;
}
},
RuntimeCommandError: {
get: function (){
return LocalRuntimeCommandError;
}
},
errorLvl: {
get: function(){
return Object.create(CONST.errorLvl);
}
}
});
function LocalCommandError(message, level){
CommandError.call(this, message, descriptor.name, level);
}
LocalCommandError.prototype = Object.create(CommandError.prototype);
function LocalRuntimeCommandError(message){
RuntimeCommandError.call(this, message, descriptor.name);
}
LocalRuntimeCommandError.prototype = Object.create(RuntimeCommandError.prototype);
} | javascript | function CommandController(descriptor){
Object.defineProperties(this, {
name: {
get: function(){
return descriptor.name;
}
},
description: {
get: function(){
return descriptor.description;
}
},
CommandError: {
get: function(){
return LocalCommandError;
}
},
RuntimeCommandError: {
get: function (){
return LocalRuntimeCommandError;
}
},
errorLvl: {
get: function(){
return Object.create(CONST.errorLvl);
}
}
});
function LocalCommandError(message, level){
CommandError.call(this, message, descriptor.name, level);
}
LocalCommandError.prototype = Object.create(CommandError.prototype);
function LocalRuntimeCommandError(message){
RuntimeCommandError.call(this, message, descriptor.name);
}
LocalRuntimeCommandError.prototype = Object.create(RuntimeCommandError.prototype);
} | [
"function",
"CommandController",
"(",
"descriptor",
")",
"{",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"name",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"descriptor",
".",
"name",
";",
"}",
"}",
",",
"description",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"descriptor",
".",
"description",
";",
"}",
"}",
",",
"CommandError",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"LocalCommandError",
";",
"}",
"}",
",",
"RuntimeCommandError",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"LocalRuntimeCommandError",
";",
"}",
"}",
",",
"errorLvl",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"Object",
".",
"create",
"(",
"CONST",
".",
"errorLvl",
")",
";",
"}",
"}",
"}",
")",
";",
"function",
"LocalCommandError",
"(",
"message",
",",
"level",
")",
"{",
"CommandError",
".",
"call",
"(",
"this",
",",
"message",
",",
"descriptor",
".",
"name",
",",
"level",
")",
";",
"}",
"LocalCommandError",
".",
"prototype",
"=",
"Object",
".",
"create",
"(",
"CommandError",
".",
"prototype",
")",
";",
"function",
"LocalRuntimeCommandError",
"(",
"message",
")",
"{",
"RuntimeCommandError",
".",
"call",
"(",
"this",
",",
"message",
",",
"descriptor",
".",
"name",
")",
";",
"}",
"LocalRuntimeCommandError",
".",
"prototype",
"=",
"Object",
".",
"create",
"(",
"RuntimeCommandError",
".",
"prototype",
")",
";",
"}"
] | CommandIO API to command action.
@param descriptor The command descriptor. | [
"CommandIO",
"API",
"to",
"command",
"action",
"."
] | 3d3cdfac83b2e14e801a9fc94ced9024c757674f | https://github.com/Techniv/node-command-io/blob/3d3cdfac83b2e14e801a9fc94ced9024c757674f/libs/commandio.js#L222-L261 |
56,784 | Techniv/node-command-io | libs/commandio.js | checkDescriptor | function checkDescriptor(descriptor, err){
if(typeof descriptor != 'object') return false;
for(var key in CONST.descriptorType){
if(!checkType(descriptor[key], CONST.descriptorType[key])){
err.key = key;
err.expect = CONST.descriptorType[key];
err.type = typeof descriptor[key];
return false;
}
}
for(var key in CONST.descriptorOptType){
if(typeof descriptor[key] != 'undefined' && checkType(descriptor[key], CONST.descriptorOptType[key].type)) continue;
if(typeof descriptor[key] == 'undefined'){
if(typeof CONST.descriptorOptType[key].value != 'undefined') descriptor[key] = CONST.descriptorOptType[key].value;
continue;
}
err.key = key;
err.expect = CONST.descriptorOptType[key].type;
err.type = typeof descriptor[key];
return false;
}
return true;
} | javascript | function checkDescriptor(descriptor, err){
if(typeof descriptor != 'object') return false;
for(var key in CONST.descriptorType){
if(!checkType(descriptor[key], CONST.descriptorType[key])){
err.key = key;
err.expect = CONST.descriptorType[key];
err.type = typeof descriptor[key];
return false;
}
}
for(var key in CONST.descriptorOptType){
if(typeof descriptor[key] != 'undefined' && checkType(descriptor[key], CONST.descriptorOptType[key].type)) continue;
if(typeof descriptor[key] == 'undefined'){
if(typeof CONST.descriptorOptType[key].value != 'undefined') descriptor[key] = CONST.descriptorOptType[key].value;
continue;
}
err.key = key;
err.expect = CONST.descriptorOptType[key].type;
err.type = typeof descriptor[key];
return false;
}
return true;
} | [
"function",
"checkDescriptor",
"(",
"descriptor",
",",
"err",
")",
"{",
"if",
"(",
"typeof",
"descriptor",
"!=",
"'object'",
")",
"return",
"false",
";",
"for",
"(",
"var",
"key",
"in",
"CONST",
".",
"descriptorType",
")",
"{",
"if",
"(",
"!",
"checkType",
"(",
"descriptor",
"[",
"key",
"]",
",",
"CONST",
".",
"descriptorType",
"[",
"key",
"]",
")",
")",
"{",
"err",
".",
"key",
"=",
"key",
";",
"err",
".",
"expect",
"=",
"CONST",
".",
"descriptorType",
"[",
"key",
"]",
";",
"err",
".",
"type",
"=",
"typeof",
"descriptor",
"[",
"key",
"]",
";",
"return",
"false",
";",
"}",
"}",
"for",
"(",
"var",
"key",
"in",
"CONST",
".",
"descriptorOptType",
")",
"{",
"if",
"(",
"typeof",
"descriptor",
"[",
"key",
"]",
"!=",
"'undefined'",
"&&",
"checkType",
"(",
"descriptor",
"[",
"key",
"]",
",",
"CONST",
".",
"descriptorOptType",
"[",
"key",
"]",
".",
"type",
")",
")",
"continue",
";",
"if",
"(",
"typeof",
"descriptor",
"[",
"key",
"]",
"==",
"'undefined'",
")",
"{",
"if",
"(",
"typeof",
"CONST",
".",
"descriptorOptType",
"[",
"key",
"]",
".",
"value",
"!=",
"'undefined'",
")",
"descriptor",
"[",
"key",
"]",
"=",
"CONST",
".",
"descriptorOptType",
"[",
"key",
"]",
".",
"value",
";",
"continue",
";",
"}",
"err",
".",
"key",
"=",
"key",
";",
"err",
".",
"expect",
"=",
"CONST",
".",
"descriptorOptType",
"[",
"key",
"]",
".",
"type",
";",
"err",
".",
"type",
"=",
"typeof",
"descriptor",
"[",
"key",
"]",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if the command descriptor is valid.
@return boolean | [
"Check",
"if",
"the",
"command",
"descriptor",
"is",
"valid",
"."
] | 3d3cdfac83b2e14e801a9fc94ced9024c757674f | https://github.com/Techniv/node-command-io/blob/3d3cdfac83b2e14e801a9fc94ced9024c757674f/libs/commandio.js#L306-L332 |
56,785 | Techniv/node-command-io | libs/commandio.js | CommandError | function CommandError(message, command, level){
var that = this, error;
// Set the default level.
if( isNaN(level) || level < 1 || level > 3) level = CONST.errorLvl.error;
// Format the message
if(typeof command == 'string') message = '{'+command+'} '+message;
message = '[command.io] '+message;
// Create the native Error object.
error = new Error(message);
// Create the getter for native error properties and custom properties.
Object.defineProperties(this, {
'stack': {
get: function(){
return error.stack;
}
},
message: {
get: function(){
return error.message;
}
},
command: {
get: function(){
return command;
}
},
level: {
get: function(){
return level;
}
}
});
} | javascript | function CommandError(message, command, level){
var that = this, error;
// Set the default level.
if( isNaN(level) || level < 1 || level > 3) level = CONST.errorLvl.error;
// Format the message
if(typeof command == 'string') message = '{'+command+'} '+message;
message = '[command.io] '+message;
// Create the native Error object.
error = new Error(message);
// Create the getter for native error properties and custom properties.
Object.defineProperties(this, {
'stack': {
get: function(){
return error.stack;
}
},
message: {
get: function(){
return error.message;
}
},
command: {
get: function(){
return command;
}
},
level: {
get: function(){
return level;
}
}
});
} | [
"function",
"CommandError",
"(",
"message",
",",
"command",
",",
"level",
")",
"{",
"var",
"that",
"=",
"this",
",",
"error",
";",
"// Set the default level.",
"if",
"(",
"isNaN",
"(",
"level",
")",
"||",
"level",
"<",
"1",
"||",
"level",
">",
"3",
")",
"level",
"=",
"CONST",
".",
"errorLvl",
".",
"error",
";",
"// Format the message",
"if",
"(",
"typeof",
"command",
"==",
"'string'",
")",
"message",
"=",
"'{'",
"+",
"command",
"+",
"'} '",
"+",
"message",
";",
"message",
"=",
"'[command.io] '",
"+",
"message",
";",
"// Create the native Error object.",
"error",
"=",
"new",
"Error",
"(",
"message",
")",
";",
"// Create the getter for native error properties and custom properties.",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"'stack'",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"error",
".",
"stack",
";",
"}",
"}",
",",
"message",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"error",
".",
"message",
";",
"}",
"}",
",",
"command",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"command",
";",
"}",
"}",
",",
"level",
":",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"level",
";",
"}",
"}",
"}",
")",
";",
"}"
] | ERRORS
Custom error object to manage exceptions on command's action.
@param string message The error message.
@param string command The command name what throw the error.
@param int level The severity level (1,2 or 3 to notice, error, critical).
@constructor | [
"ERRORS",
"Custom",
"error",
"object",
"to",
"manage",
"exceptions",
"on",
"command",
"s",
"action",
"."
] | 3d3cdfac83b2e14e801a9fc94ced9024c757674f | https://github.com/Techniv/node-command-io/blob/3d3cdfac83b2e14e801a9fc94ced9024c757674f/libs/commandio.js#L354-L390 |
56,786 | wigy/chronicles_of_grunt | lib/templates.js | substitute | function substitute(str, variables) {
// Based on Simple JavaScript Templating by
// John Resig - http://ejohn.org/blog/javascript-micro-templating/ - MIT Licensed
if (!cache[str]) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
try {
/*jshint -W054 */
cache[str] = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'") +
"');}return p.join('');");
/*jshint +W054 */
} catch(e) {
grunt.fail.fatal("Failed to compile template:\n" + str);
}
}
return cache[str](variables || {});
} | javascript | function substitute(str, variables) {
// Based on Simple JavaScript Templating by
// John Resig - http://ejohn.org/blog/javascript-micro-templating/ - MIT Licensed
if (!cache[str]) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
try {
/*jshint -W054 */
cache[str] = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'") +
"');}return p.join('');");
/*jshint +W054 */
} catch(e) {
grunt.fail.fatal("Failed to compile template:\n" + str);
}
}
return cache[str](variables || {});
} | [
"function",
"substitute",
"(",
"str",
",",
"variables",
")",
"{",
"// Based on Simple JavaScript Templating by",
"// John Resig - http://ejohn.org/blog/javascript-micro-templating/ - MIT Licensed",
"if",
"(",
"!",
"cache",
"[",
"str",
"]",
")",
"{",
"// Figure out if we're getting a template, or if we need to",
"// load the template - and be sure to cache the result.",
"try",
"{",
"/*jshint -W054 */",
"cache",
"[",
"str",
"]",
"=",
"new",
"Function",
"(",
"\"obj\"",
",",
"\"var p=[],print=function(){p.push.apply(p,arguments);};\"",
"+",
"// Introduce the data as local variables using with(){}",
"\"with(obj){p.push('\"",
"+",
"// Convert the template into pure JavaScript",
"str",
".",
"replace",
"(",
"/",
"[\\r\\t\\n]",
"/",
"g",
",",
"\" \"",
")",
".",
"split",
"(",
"\"<%\"",
")",
".",
"join",
"(",
"\"\\t\"",
")",
".",
"replace",
"(",
"/",
"((^|%>)[^\\t]*)'",
"/",
"g",
",",
"\"$1\\r\"",
")",
".",
"replace",
"(",
"/",
"\\t=(.*?)%>",
"/",
"g",
",",
"\"',$1,'\"",
")",
".",
"split",
"(",
"\"\\t\"",
")",
".",
"join",
"(",
"\"');\"",
")",
".",
"split",
"(",
"\"%>\"",
")",
".",
"join",
"(",
"\"p.push('\"",
")",
".",
"split",
"(",
"\"\\r\"",
")",
".",
"join",
"(",
"\"\\\\'\"",
")",
"+",
"\"');}return p.join('');\"",
")",
";",
"/*jshint +W054 */",
"}",
"catch",
"(",
"e",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"\"Failed to compile template:\\n\"",
"+",
"str",
")",
";",
"}",
"}",
"return",
"cache",
"[",
"str",
"]",
"(",
"variables",
"||",
"{",
"}",
")",
";",
"}"
] | Perform variable substitutions in the template.
@param str Content of the template as a string.
@param variables An object containing variable values.
Note that templating does not support single quotes. It also removes line feeds. | [
"Perform",
"variable",
"substitutions",
"in",
"the",
"template",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/templates.js#L39-L70 |
56,787 | wigy/chronicles_of_grunt | lib/templates.js | generate | function generate(tmpl, src, variables) {
variables = variables || {};
variables.FILES = {};
for (var i = 0; i < src.length; i++) {
var content = JSON.stringify(grunt.file.read(src[i]));
variables.FILES[src[i]] = content;
}
var template = grunt.file.read(tmpl);
return substitute(template, variables);
} | javascript | function generate(tmpl, src, variables) {
variables = variables || {};
variables.FILES = {};
for (var i = 0; i < src.length; i++) {
var content = JSON.stringify(grunt.file.read(src[i]));
variables.FILES[src[i]] = content;
}
var template = grunt.file.read(tmpl);
return substitute(template, variables);
} | [
"function",
"generate",
"(",
"tmpl",
",",
"src",
",",
"variables",
")",
"{",
"variables",
"=",
"variables",
"||",
"{",
"}",
";",
"variables",
".",
"FILES",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"src",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"content",
"=",
"JSON",
".",
"stringify",
"(",
"grunt",
".",
"file",
".",
"read",
"(",
"src",
"[",
"i",
"]",
")",
")",
";",
"variables",
".",
"FILES",
"[",
"src",
"[",
"i",
"]",
"]",
"=",
"content",
";",
"}",
"var",
"template",
"=",
"grunt",
".",
"file",
".",
"read",
"(",
"tmpl",
")",
";",
"return",
"substitute",
"(",
"template",
",",
"variables",
")",
";",
"}"
] | Generate a file based on the template and source files.
@param tmpl Path to the template file.
@param src An array of source files.
@param variables Initial variables as an object.
@return A string with template substitutions made. | [
"Generate",
"a",
"file",
"based",
"on",
"the",
"template",
"and",
"source",
"files",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/templates.js#L80-L89 |
56,788 | melvincarvalho/rdf-shell | lib/util.js | putStorage | function putStorage(host, path, data, cert, callback) {
var protocol = 'https://'
var ldp = {
hostname: host,
rejectUnauthorized: false,
port: 443,
method: 'PUT',
headers: {'Content-Type': 'text/turtle'}
}
if (cert) {
ldp.key = fs.readFileSync(cert)
ldp.cert = fs.readFileSync(cert)
}
// put file to ldp
ldp.path = path
debug('sending to : ' + protocol + host + path)
var put = https.request(ldp, function(res) {
chunks = ''
debug('STATUS: ' + res.statusCode)
debug('HEADERS: ' + JSON.stringify(res.headers))
res.on('data', function (chunk) {
chunks += chunk
})
res.on('end', function (chunk) {
callback(null, chunks, ldp)
})
})
put.on('error', function(e) {
callback(e)
})
put.write(data)
put.end()
} | javascript | function putStorage(host, path, data, cert, callback) {
var protocol = 'https://'
var ldp = {
hostname: host,
rejectUnauthorized: false,
port: 443,
method: 'PUT',
headers: {'Content-Type': 'text/turtle'}
}
if (cert) {
ldp.key = fs.readFileSync(cert)
ldp.cert = fs.readFileSync(cert)
}
// put file to ldp
ldp.path = path
debug('sending to : ' + protocol + host + path)
var put = https.request(ldp, function(res) {
chunks = ''
debug('STATUS: ' + res.statusCode)
debug('HEADERS: ' + JSON.stringify(res.headers))
res.on('data', function (chunk) {
chunks += chunk
})
res.on('end', function (chunk) {
callback(null, chunks, ldp)
})
})
put.on('error', function(e) {
callback(e)
})
put.write(data)
put.end()
} | [
"function",
"putStorage",
"(",
"host",
",",
"path",
",",
"data",
",",
"cert",
",",
"callback",
")",
"{",
"var",
"protocol",
"=",
"'https://'",
"var",
"ldp",
"=",
"{",
"hostname",
":",
"host",
",",
"rejectUnauthorized",
":",
"false",
",",
"port",
":",
"443",
",",
"method",
":",
"'PUT'",
",",
"headers",
":",
"{",
"'Content-Type'",
":",
"'text/turtle'",
"}",
"}",
"if",
"(",
"cert",
")",
"{",
"ldp",
".",
"key",
"=",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
"ldp",
".",
"cert",
"=",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
"}",
"// put file to ldp",
"ldp",
".",
"path",
"=",
"path",
"debug",
"(",
"'sending to : '",
"+",
"protocol",
"+",
"host",
"+",
"path",
")",
"var",
"put",
"=",
"https",
".",
"request",
"(",
"ldp",
",",
"function",
"(",
"res",
")",
"{",
"chunks",
"=",
"''",
"debug",
"(",
"'STATUS: '",
"+",
"res",
".",
"statusCode",
")",
"debug",
"(",
"'HEADERS: '",
"+",
"JSON",
".",
"stringify",
"(",
"res",
".",
"headers",
")",
")",
"res",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"chunks",
"+=",
"chunk",
"}",
")",
"res",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
"chunk",
")",
"{",
"callback",
"(",
"null",
",",
"chunks",
",",
"ldp",
")",
"}",
")",
"}",
")",
"put",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"callback",
"(",
"e",
")",
"}",
")",
"put",
".",
"write",
"(",
"data",
")",
"put",
".",
"end",
"(",
")",
"}"
] | putStorage Sends turtle data to remote storage via put request
@param {String} host The host to send to
@param {String} path The path relative to host
@param {String} data The turtle to send
@param {String} cert Certificate path used for auth
@param {Function} callback Callback with error or response | [
"putStorage",
"Sends",
"turtle",
"data",
"to",
"remote",
"storage",
"via",
"put",
"request"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/util.js#L72-L109 |
56,789 | melvincarvalho/rdf-shell | lib/util.js | is | function is(store, uri, type) {
var ret = false
var types = store.findTypeURIs($rdf.sym(uri))
if (types && types[type]) {
ret = true
}
return ret
} | javascript | function is(store, uri, type) {
var ret = false
var types = store.findTypeURIs($rdf.sym(uri))
if (types && types[type]) {
ret = true
}
return ret
} | [
"function",
"is",
"(",
"store",
",",
"uri",
",",
"type",
")",
"{",
"var",
"ret",
"=",
"false",
"var",
"types",
"=",
"store",
".",
"findTypeURIs",
"(",
"$rdf",
".",
"sym",
"(",
"uri",
")",
")",
"if",
"(",
"types",
"&&",
"types",
"[",
"type",
"]",
")",
"{",
"ret",
"=",
"true",
"}",
"return",
"ret",
"}"
] | See if a URI is a certain type
@param {object} store the rdflib store
@param {string} uri the uri to check
@param {string} type the type to test
@return {Boolean} true if uri is that type | [
"See",
"if",
"a",
"URI",
"is",
"a",
"certain",
"type"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/util.js#L362-L372 |
56,790 | kaelzhang/typo-rgb | lib/rgb.js | to_rgb | function to_rgb(obj){
return [obj.R, obj.G, obj.B].map(format_number).join('');
} | javascript | function to_rgb(obj){
return [obj.R, obj.G, obj.B].map(format_number).join('');
} | [
"function",
"to_rgb",
"(",
"obj",
")",
"{",
"return",
"[",
"obj",
".",
"R",
",",
"obj",
".",
"G",
",",
"obj",
".",
"B",
"]",
".",
"map",
"(",
"format_number",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
] | reversed method of `rgb_2_object` | [
"reversed",
"method",
"of",
"rgb_2_object"
] | 27a0498bb291fbda8c33e4c9568fc9ae5d539edb | https://github.com/kaelzhang/typo-rgb/blob/27a0498bb291fbda8c33e4c9568fc9ae5d539edb/lib/rgb.js#L313-L315 |
56,791 | benzhou1/iod | lib/iod.js | function(results) {
// Only do so if `callback` is specified
if (IODOpts.callback) {
var options = { url: IODOpts.callback.uri }
var res = JSON.stringify(results)
// Url-encode use `form` property
if (IODOpts.callback.method === 'encoded') {
options.form = { results: res }
}
var r = request.post(options, function(err, res) {
// Emits `CbError` if any error occurs while sending results to callback
if (err) IOD.eventEmitter.emit('CbError', err)
else if (res.statusCode !== 200) {
IOD.eventEmitter.emit('CbError', 'Status Code: ' + res.statusCode)
}
})
// Multipart use form object
if (IODOpts.callback.method === 'multipart') {
var form = r.form()
form.append('results', res)
form.on('error', function(err) {
IOD.evenEmitter.emit('CBError', err)
})
}
}
} | javascript | function(results) {
// Only do so if `callback` is specified
if (IODOpts.callback) {
var options = { url: IODOpts.callback.uri }
var res = JSON.stringify(results)
// Url-encode use `form` property
if (IODOpts.callback.method === 'encoded') {
options.form = { results: res }
}
var r = request.post(options, function(err, res) {
// Emits `CbError` if any error occurs while sending results to callback
if (err) IOD.eventEmitter.emit('CbError', err)
else if (res.statusCode !== 200) {
IOD.eventEmitter.emit('CbError', 'Status Code: ' + res.statusCode)
}
})
// Multipart use form object
if (IODOpts.callback.method === 'multipart') {
var form = r.form()
form.append('results', res)
form.on('error', function(err) {
IOD.evenEmitter.emit('CBError', err)
})
}
}
} | [
"function",
"(",
"results",
")",
"{",
"// Only do so if `callback` is specified",
"if",
"(",
"IODOpts",
".",
"callback",
")",
"{",
"var",
"options",
"=",
"{",
"url",
":",
"IODOpts",
".",
"callback",
".",
"uri",
"}",
"var",
"res",
"=",
"JSON",
".",
"stringify",
"(",
"results",
")",
"// Url-encode use `form` property",
"if",
"(",
"IODOpts",
".",
"callback",
".",
"method",
"===",
"'encoded'",
")",
"{",
"options",
".",
"form",
"=",
"{",
"results",
":",
"res",
"}",
"}",
"var",
"r",
"=",
"request",
".",
"post",
"(",
"options",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"// Emits `CbError` if any error occurs while sending results to callback",
"if",
"(",
"err",
")",
"IOD",
".",
"eventEmitter",
".",
"emit",
"(",
"'CbError'",
",",
"err",
")",
"else",
"if",
"(",
"res",
".",
"statusCode",
"!==",
"200",
")",
"{",
"IOD",
".",
"eventEmitter",
".",
"emit",
"(",
"'CbError'",
",",
"'Status Code: '",
"+",
"res",
".",
"statusCode",
")",
"}",
"}",
")",
"// Multipart use form object",
"if",
"(",
"IODOpts",
".",
"callback",
".",
"method",
"===",
"'multipart'",
")",
"{",
"var",
"form",
"=",
"r",
".",
"form",
"(",
")",
"form",
".",
"append",
"(",
"'results'",
",",
"res",
")",
"form",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"IOD",
".",
"evenEmitter",
".",
"emit",
"(",
"'CBError'",
",",
"err",
")",
"}",
")",
"}",
"}",
"}"
] | Sends results of request to specified callback.
@param {*} results - Results of request | [
"Sends",
"results",
"of",
"request",
"to",
"specified",
"callback",
"."
] | a346628f9bc5e4420e4d00e8f21c4cb268b6237c | https://github.com/benzhou1/iod/blob/a346628f9bc5e4420e4d00e8f21c4cb268b6237c/lib/iod.js#L236-L265 |
|
56,792 | benzhou1/iod | lib/iod.js | function(jobId) {
var isFinished = function(res) {
return res && res.status &&
(res.status === 'finished' || res.status === 'failed')
}
var poll = function() {
IOD.status({ jobId: jobId }, function(err, res) {
// Emits err as first argument
if (err) IOD.eventEmitter.emit(jobId, err)
else if (isFinished(res)) {
IOD.eventEmitter.emit(jobId, null, res)
sendCallback(res)
}
else setTimeout(poll, IODOpts.pollInterval)
})
}
setTimeout(poll, IODOpts.pollInterval)
} | javascript | function(jobId) {
var isFinished = function(res) {
return res && res.status &&
(res.status === 'finished' || res.status === 'failed')
}
var poll = function() {
IOD.status({ jobId: jobId }, function(err, res) {
// Emits err as first argument
if (err) IOD.eventEmitter.emit(jobId, err)
else if (isFinished(res)) {
IOD.eventEmitter.emit(jobId, null, res)
sendCallback(res)
}
else setTimeout(poll, IODOpts.pollInterval)
})
}
setTimeout(poll, IODOpts.pollInterval)
} | [
"function",
"(",
"jobId",
")",
"{",
"var",
"isFinished",
"=",
"function",
"(",
"res",
")",
"{",
"return",
"res",
"&&",
"res",
".",
"status",
"&&",
"(",
"res",
".",
"status",
"===",
"'finished'",
"||",
"res",
".",
"status",
"===",
"'failed'",
")",
"}",
"var",
"poll",
"=",
"function",
"(",
")",
"{",
"IOD",
".",
"status",
"(",
"{",
"jobId",
":",
"jobId",
"}",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"// Emits err as first argument",
"if",
"(",
"err",
")",
"IOD",
".",
"eventEmitter",
".",
"emit",
"(",
"jobId",
",",
"err",
")",
"else",
"if",
"(",
"isFinished",
"(",
"res",
")",
")",
"{",
"IOD",
".",
"eventEmitter",
".",
"emit",
"(",
"jobId",
",",
"null",
",",
"res",
")",
"sendCallback",
"(",
"res",
")",
"}",
"else",
"setTimeout",
"(",
"poll",
",",
"IODOpts",
".",
"pollInterval",
")",
"}",
")",
"}",
"setTimeout",
"(",
"poll",
",",
"IODOpts",
".",
"pollInterval",
")",
"}"
] | Periodically get status of a job with specified job id `jobId`.
Do so until job has finished or failed.
@param {String} jobId - Job id | [
"Periodically",
"get",
"status",
"of",
"a",
"job",
"with",
"specified",
"job",
"id",
"jobId",
".",
"Do",
"so",
"until",
"job",
"has",
"finished",
"or",
"failed",
"."
] | a346628f9bc5e4420e4d00e8f21c4cb268b6237c | https://github.com/benzhou1/iod/blob/a346628f9bc5e4420e4d00e8f21c4cb268b6237c/lib/iod.js#L273-L292 |
|
56,793 | benzhou1/iod | lib/iod.js | function(asyncRes, callback) {
var jobId = asyncRes.jobID
if (!jobId) return callback(null, asyncRes)
else if (IODOpts.getResults) {
IOD.result({
jobId: jobId,
majorVersion: IODOpts.majorVersion,
retries: 3
}, callback)
}
else {
callback(null, asyncRes)
pollUntilDone(jobId)
}
} | javascript | function(asyncRes, callback) {
var jobId = asyncRes.jobID
if (!jobId) return callback(null, asyncRes)
else if (IODOpts.getResults) {
IOD.result({
jobId: jobId,
majorVersion: IODOpts.majorVersion,
retries: 3
}, callback)
}
else {
callback(null, asyncRes)
pollUntilDone(jobId)
}
} | [
"function",
"(",
"asyncRes",
",",
"callback",
")",
"{",
"var",
"jobId",
"=",
"asyncRes",
".",
"jobID",
"if",
"(",
"!",
"jobId",
")",
"return",
"callback",
"(",
"null",
",",
"asyncRes",
")",
"else",
"if",
"(",
"IODOpts",
".",
"getResults",
")",
"{",
"IOD",
".",
"result",
"(",
"{",
"jobId",
":",
"jobId",
",",
"majorVersion",
":",
"IODOpts",
".",
"majorVersion",
",",
"retries",
":",
"3",
"}",
",",
"callback",
")",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"asyncRes",
")",
"pollUntilDone",
"(",
"jobId",
")",
"}",
"}"
] | If getResults is true and jobId is found, send IOD result request.
@param {Object} asyncRes - Async request response
@param {Function} callback - Callback(err, IOD response)) | [
"If",
"getResults",
"is",
"true",
"and",
"jobId",
"is",
"found",
"send",
"IOD",
"result",
"request",
"."
] | a346628f9bc5e4420e4d00e8f21c4cb268b6237c | https://github.com/benzhou1/iod/blob/a346628f9bc5e4420e4d00e8f21c4cb268b6237c/lib/iod.js#L300-L316 |
|
56,794 | JohnnieFucker/dreamix-admin | lib/modules/scripts.js | list | function list(scriptModule, agent, msg, cb) {
const servers = [];
const scripts = [];
const idMap = agent.idMap;
for (const sid in idMap) {
if (idMap.hasOwnProperty(sid)) {
servers.push(sid);
}
}
fs.readdir(scriptModule.root, (err, filenames) => {
if (err) {
filenames = [];
}
for (let i = 0, l = filenames.length; i < l; i++) {
scripts.push(filenames[i]);
}
cb(null, {
servers: servers,
scripts: scripts
});
});
} | javascript | function list(scriptModule, agent, msg, cb) {
const servers = [];
const scripts = [];
const idMap = agent.idMap;
for (const sid in idMap) {
if (idMap.hasOwnProperty(sid)) {
servers.push(sid);
}
}
fs.readdir(scriptModule.root, (err, filenames) => {
if (err) {
filenames = [];
}
for (let i = 0, l = filenames.length; i < l; i++) {
scripts.push(filenames[i]);
}
cb(null, {
servers: servers,
scripts: scripts
});
});
} | [
"function",
"list",
"(",
"scriptModule",
",",
"agent",
",",
"msg",
",",
"cb",
")",
"{",
"const",
"servers",
"=",
"[",
"]",
";",
"const",
"scripts",
"=",
"[",
"]",
";",
"const",
"idMap",
"=",
"agent",
".",
"idMap",
";",
"for",
"(",
"const",
"sid",
"in",
"idMap",
")",
"{",
"if",
"(",
"idMap",
".",
"hasOwnProperty",
"(",
"sid",
")",
")",
"{",
"servers",
".",
"push",
"(",
"sid",
")",
";",
"}",
"}",
"fs",
".",
"readdir",
"(",
"scriptModule",
".",
"root",
",",
"(",
"err",
",",
"filenames",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"filenames",
"=",
"[",
"]",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"filenames",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"scripts",
".",
"push",
"(",
"filenames",
"[",
"i",
"]",
")",
";",
"}",
"cb",
"(",
"null",
",",
"{",
"servers",
":",
"servers",
",",
"scripts",
":",
"scripts",
"}",
")",
";",
"}",
")",
";",
"}"
] | List server id and scripts file name | [
"List",
"server",
"id",
"and",
"scripts",
"file",
"name"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/modules/scripts.js#L13-L37 |
56,795 | JohnnieFucker/dreamix-admin | lib/modules/scripts.js | get | function get(scriptModule, agent, msg, cb) {
const filename = msg.filename;
if (!filename) {
cb('empty filename');
return;
}
fs.readFile(path.join(scriptModule.root, filename), 'utf-8', (err, data) => {
if (err) {
logger.error(`fail to read script file:${filename}, ${err.stack}`);
cb(`fail to read script with name:${filename}`);
}
cb(null, data);
});
} | javascript | function get(scriptModule, agent, msg, cb) {
const filename = msg.filename;
if (!filename) {
cb('empty filename');
return;
}
fs.readFile(path.join(scriptModule.root, filename), 'utf-8', (err, data) => {
if (err) {
logger.error(`fail to read script file:${filename}, ${err.stack}`);
cb(`fail to read script with name:${filename}`);
}
cb(null, data);
});
} | [
"function",
"get",
"(",
"scriptModule",
",",
"agent",
",",
"msg",
",",
"cb",
")",
"{",
"const",
"filename",
"=",
"msg",
".",
"filename",
";",
"if",
"(",
"!",
"filename",
")",
"{",
"cb",
"(",
"'empty filename'",
")",
";",
"return",
";",
"}",
"fs",
".",
"readFile",
"(",
"path",
".",
"join",
"(",
"scriptModule",
".",
"root",
",",
"filename",
")",
",",
"'utf-8'",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"`",
"${",
"filename",
"}",
"${",
"err",
".",
"stack",
"}",
"`",
")",
";",
"cb",
"(",
"`",
"${",
"filename",
"}",
"`",
")",
";",
"}",
"cb",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
";",
"}"
] | Get the content of the script file | [
"Get",
"the",
"content",
"of",
"the",
"script",
"file"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/modules/scripts.js#L42-L57 |
56,796 | JohnnieFucker/dreamix-admin | lib/modules/scripts.js | save | function save(scriptModule, agent, msg, cb) {
const filepath = path.join(scriptModule.root, msg.filename);
fs.writeFile(filepath, msg.body, (err) => {
if (err) {
logger.error(`fail to write script file:${msg.filename}, ${err.stack}`);
cb(`fail to write script file:${msg.filename}`);
return;
}
cb();
});
} | javascript | function save(scriptModule, agent, msg, cb) {
const filepath = path.join(scriptModule.root, msg.filename);
fs.writeFile(filepath, msg.body, (err) => {
if (err) {
logger.error(`fail to write script file:${msg.filename}, ${err.stack}`);
cb(`fail to write script file:${msg.filename}`);
return;
}
cb();
});
} | [
"function",
"save",
"(",
"scriptModule",
",",
"agent",
",",
"msg",
",",
"cb",
")",
"{",
"const",
"filepath",
"=",
"path",
".",
"join",
"(",
"scriptModule",
".",
"root",
",",
"msg",
".",
"filename",
")",
";",
"fs",
".",
"writeFile",
"(",
"filepath",
",",
"msg",
".",
"body",
",",
"(",
"err",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"`",
"${",
"msg",
".",
"filename",
"}",
"${",
"err",
".",
"stack",
"}",
"`",
")",
";",
"cb",
"(",
"`",
"${",
"msg",
".",
"filename",
"}",
"`",
")",
";",
"return",
";",
"}",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | Save a script file that posted from admin console | [
"Save",
"a",
"script",
"file",
"that",
"posted",
"from",
"admin",
"console"
] | fc169e2481d5a7456725fb33f7a7907e0776ef79 | https://github.com/JohnnieFucker/dreamix-admin/blob/fc169e2481d5a7456725fb33f7a7907e0776ef79/lib/modules/scripts.js#L62-L74 |
56,797 | melvincarvalho/rdf-shell | bin/cat.js | bin | function bin(argv) {
if (!argv[2]) {
console.error("url is required")
console.error("Usage : cat <url>")
process.exit(-1)
}
shell.cat(argv[2], function(err, res, uri) {
if (err) {
console.error(err)
} else {
console.log(res)
}
})
} | javascript | function bin(argv) {
if (!argv[2]) {
console.error("url is required")
console.error("Usage : cat <url>")
process.exit(-1)
}
shell.cat(argv[2], function(err, res, uri) {
if (err) {
console.error(err)
} else {
console.log(res)
}
})
} | [
"function",
"bin",
"(",
"argv",
")",
"{",
"if",
"(",
"!",
"argv",
"[",
"2",
"]",
")",
"{",
"console",
".",
"error",
"(",
"\"url is required\"",
")",
"console",
".",
"error",
"(",
"\"Usage : cat <url>\"",
")",
"process",
".",
"exit",
"(",
"-",
"1",
")",
"}",
"shell",
".",
"cat",
"(",
"argv",
"[",
"2",
"]",
",",
"function",
"(",
"err",
",",
"res",
",",
"uri",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"res",
")",
"}",
"}",
")",
"}"
] | cat as a command
@param {Array} argv Args, argv[2] is the uri | [
"cat",
"as",
"a",
"command"
] | bf2015f6f333855e69a18ce3ec9e917bbddfb425 | https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/bin/cat.js#L9-L22 |
56,798 | oleics/node-xcouch | registry.js | connectUser | function connectUser(name, pass, cb) {
loginUser(name, pass, function(err, user) {
if(err) return cb(err)
var nano = NANO(_ci.protocol+'//'+encodeURIComponent(name)+':'+encodeURIComponent(pass)+'@'+_ci.host+'/')
, db = nano.use(name)
;
function getObject(type, id, rev) {
var ctor = registry[type]
, obj = new ctor(id, rev)
obj.type(type)
if(ctor.dbname) {
obj.db = nano.use(ctor.dbname)
} else {
obj.db = db
}
obj.getObject = getObject
return obj
}
cb(null, user, getObject, db, nano)
})
} | javascript | function connectUser(name, pass, cb) {
loginUser(name, pass, function(err, user) {
if(err) return cb(err)
var nano = NANO(_ci.protocol+'//'+encodeURIComponent(name)+':'+encodeURIComponent(pass)+'@'+_ci.host+'/')
, db = nano.use(name)
;
function getObject(type, id, rev) {
var ctor = registry[type]
, obj = new ctor(id, rev)
obj.type(type)
if(ctor.dbname) {
obj.db = nano.use(ctor.dbname)
} else {
obj.db = db
}
obj.getObject = getObject
return obj
}
cb(null, user, getObject, db, nano)
})
} | [
"function",
"connectUser",
"(",
"name",
",",
"pass",
",",
"cb",
")",
"{",
"loginUser",
"(",
"name",
",",
"pass",
",",
"function",
"(",
"err",
",",
"user",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"var",
"nano",
"=",
"NANO",
"(",
"_ci",
".",
"protocol",
"+",
"'//'",
"+",
"encodeURIComponent",
"(",
"name",
")",
"+",
"':'",
"+",
"encodeURIComponent",
"(",
"pass",
")",
"+",
"'@'",
"+",
"_ci",
".",
"host",
"+",
"'/'",
")",
",",
"db",
"=",
"nano",
".",
"use",
"(",
"name",
")",
";",
"function",
"getObject",
"(",
"type",
",",
"id",
",",
"rev",
")",
"{",
"var",
"ctor",
"=",
"registry",
"[",
"type",
"]",
",",
"obj",
"=",
"new",
"ctor",
"(",
"id",
",",
"rev",
")",
"obj",
".",
"type",
"(",
"type",
")",
"if",
"(",
"ctor",
".",
"dbname",
")",
"{",
"obj",
".",
"db",
"=",
"nano",
".",
"use",
"(",
"ctor",
".",
"dbname",
")",
"}",
"else",
"{",
"obj",
".",
"db",
"=",
"db",
"}",
"obj",
".",
"getObject",
"=",
"getObject",
"return",
"obj",
"}",
"cb",
"(",
"null",
",",
"user",
",",
"getObject",
",",
"db",
",",
"nano",
")",
"}",
")",
"}"
] | Connects a user | [
"Connects",
"a",
"user"
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L141-L164 |
56,799 | oleics/node-xcouch | registry.js | createDatabase | function createDatabase(name, cb) {
nano().db.create(name, function(err) {
if(err && err.status_code !== 412) return cb(err)
cb(null, err ? false : true)
})
} | javascript | function createDatabase(name, cb) {
nano().db.create(name, function(err) {
if(err && err.status_code !== 412) return cb(err)
cb(null, err ? false : true)
})
} | [
"function",
"createDatabase",
"(",
"name",
",",
"cb",
")",
"{",
"nano",
"(",
")",
".",
"db",
".",
"create",
"(",
"name",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"&&",
"err",
".",
"status_code",
"!==",
"412",
")",
"return",
"cb",
"(",
"err",
")",
"cb",
"(",
"null",
",",
"err",
"?",
"false",
":",
"true",
")",
"}",
")",
"}"
] | Creates a database We assume that every database belongs to exactly one user. Both share the same name. | [
"Creates",
"a",
"database",
"We",
"assume",
"that",
"every",
"database",
"belongs",
"to",
"exactly",
"one",
"user",
".",
"Both",
"share",
"the",
"same",
"name",
"."
] | 47e492235b8e6c7235c7f8807725a3bb51fb44ba | https://github.com/oleics/node-xcouch/blob/47e492235b8e6c7235c7f8807725a3bb51fb44ba/registry.js#L209-L214 |
Subsets and Splits