id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
47,300 | BlackWaspTech/wasp-graphql | _internal/configureFetch.js | configureFetch | function configureFetch(init) {
// If the user only provided a query string
if (typeof init === 'string') {
var request = {
method: init.method || 'POST',
headers: init.headers || {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
query: init
})
};
// If the user provided an actual configuration object
} else {
var request = {
method: init.method || 'POST',
headers: init.headers || {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body:
init.body ||
JSON.stringify({
query: init.fields,
variables: init.variables
}),
mode: init.mode,
credentials: init.credentials,
cache: init.cache,
redirect: init.redirect,
referrer: init.referrer,
referrerPolicy: init.referrerPolicy,
integrity: init.integrity,
keepalive: init.keepalive,
signal: init.signal
};
}
return request;
} | javascript | function configureFetch(init) {
// If the user only provided a query string
if (typeof init === 'string') {
var request = {
method: init.method || 'POST',
headers: init.headers || {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
query: init
})
};
// If the user provided an actual configuration object
} else {
var request = {
method: init.method || 'POST',
headers: init.headers || {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body:
init.body ||
JSON.stringify({
query: init.fields,
variables: init.variables
}),
mode: init.mode,
credentials: init.credentials,
cache: init.cache,
redirect: init.redirect,
referrer: init.referrer,
referrerPolicy: init.referrerPolicy,
integrity: init.integrity,
keepalive: init.keepalive,
signal: init.signal
};
}
return request;
} | [
"function",
"configureFetch",
"(",
"init",
")",
"{",
"// If the user only provided a query string\r",
"if",
"(",
"typeof",
"init",
"===",
"'string'",
")",
"{",
"var",
"request",
"=",
"{",
"method",
":",
"init",
".",
"method",
"||",
"'POST'",
",",
"headers",
":",
"init",
".",
"headers",
"||",
"{",
"'Content-Type'",
":",
"'application/json'",
",",
"Accept",
":",
"'application/json'",
"}",
",",
"body",
":",
"JSON",
".",
"stringify",
"(",
"{",
"query",
":",
"init",
"}",
")",
"}",
";",
"// If the user provided an actual configuration object\r",
"}",
"else",
"{",
"var",
"request",
"=",
"{",
"method",
":",
"init",
".",
"method",
"||",
"'POST'",
",",
"headers",
":",
"init",
".",
"headers",
"||",
"{",
"'Content-Type'",
":",
"'application/json'",
",",
"Accept",
":",
"'application/json'",
"}",
",",
"body",
":",
"init",
".",
"body",
"||",
"JSON",
".",
"stringify",
"(",
"{",
"query",
":",
"init",
".",
"fields",
",",
"variables",
":",
"init",
".",
"variables",
"}",
")",
",",
"mode",
":",
"init",
".",
"mode",
",",
"credentials",
":",
"init",
".",
"credentials",
",",
"cache",
":",
"init",
".",
"cache",
",",
"redirect",
":",
"init",
".",
"redirect",
",",
"referrer",
":",
"init",
".",
"referrer",
",",
"referrerPolicy",
":",
"init",
".",
"referrerPolicy",
",",
"integrity",
":",
"init",
".",
"integrity",
",",
"keepalive",
":",
"init",
".",
"keepalive",
",",
"signal",
":",
"init",
".",
"signal",
"}",
";",
"}",
"return",
"request",
";",
"}"
]
| Generates the settings necessary for a successful GraphQL request.
@param {(string|Object)} init - Option(s) provided by the user
@returns {string} - A parsable JSON string | [
"Generates",
"the",
"settings",
"necessary",
"for",
"a",
"successful",
"GraphQL",
"request",
"."
]
| 5857b82b6eda9bb5dea5f0a881cd910b1bb3944a | https://github.com/BlackWaspTech/wasp-graphql/blob/5857b82b6eda9bb5dea5f0a881cd910b1bb3944a/_internal/configureFetch.js#L11-L52 |
47,301 | feedhenry-raincatcher/raincatcher-angularjs | demo/mobile/src/app/sync/syncGlobalManager.js | createGlobalManagerService | function createGlobalManagerService($http, authService) {
//Init the sync service
syncNetworkInit.initSync($http).catch(function(error) {
logger.getLogger().error("Failed to initialize sync", error);
});
var syncManager = new SyncManager();
authService.setLoginListener(function(profileData) {
syncManager.syncManagerMap(profileData);
});
authService.setLogoutListener(function() {
syncManager.removeManagers();
});
return syncManager;
} | javascript | function createGlobalManagerService($http, authService) {
//Init the sync service
syncNetworkInit.initSync($http).catch(function(error) {
logger.getLogger().error("Failed to initialize sync", error);
});
var syncManager = new SyncManager();
authService.setLoginListener(function(profileData) {
syncManager.syncManagerMap(profileData);
});
authService.setLogoutListener(function() {
syncManager.removeManagers();
});
return syncManager;
} | [
"function",
"createGlobalManagerService",
"(",
"$http",
",",
"authService",
")",
"{",
"//Init the sync service",
"syncNetworkInit",
".",
"initSync",
"(",
"$http",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"logger",
".",
"getLogger",
"(",
")",
".",
"error",
"(",
"\"Failed to initialize sync\"",
",",
"error",
")",
";",
"}",
")",
";",
"var",
"syncManager",
"=",
"new",
"SyncManager",
"(",
")",
";",
"authService",
".",
"setLoginListener",
"(",
"function",
"(",
"profileData",
")",
"{",
"syncManager",
".",
"syncManagerMap",
"(",
"profileData",
")",
";",
"}",
")",
";",
"authService",
".",
"setLogoutListener",
"(",
"function",
"(",
")",
"{",
"syncManager",
".",
"removeManagers",
"(",
")",
";",
"}",
")",
";",
"return",
"syncManager",
";",
"}"
]
| Service to manage init all of the sync data sets.
@param $q
@returns {{}}
@constructor | [
"Service",
"to",
"manage",
"init",
"all",
"of",
"the",
"sync",
"data",
"sets",
"."
]
| b394689227901e18871ad9edd0ec226c5e6839e1 | https://github.com/feedhenry-raincatcher/raincatcher-angularjs/blob/b394689227901e18871ad9edd0ec226c5e6839e1/demo/mobile/src/app/sync/syncGlobalManager.js#L117-L131 |
47,302 | chjj/rondo | lib/io.js | function(path) {
var loc = window.location;
if (path[path.length-1] === '/') {
path = path.slice(0, -1);
}
if (~path.indexOf('//')) {
return path;
}
var auth = /^[^:\/]+:\/\/[^\/]+/.exec(loc.href)[0];
if (path[0] === '/') {
path = auth + path;
} else {
path = path.replace(/^\.?\//, '');
loc = loc.pathname.replace(/^\/|\/$/g, '');
path = [auth, loc, path].join('/');
}
return path;
} | javascript | function(path) {
var loc = window.location;
if (path[path.length-1] === '/') {
path = path.slice(0, -1);
}
if (~path.indexOf('//')) {
return path;
}
var auth = /^[^:\/]+:\/\/[^\/]+/.exec(loc.href)[0];
if (path[0] === '/') {
path = auth + path;
} else {
path = path.replace(/^\.?\//, '');
loc = loc.pathname.replace(/^\/|\/$/g, '');
path = [auth, loc, path].join('/');
}
return path;
} | [
"function",
"(",
"path",
")",
"{",
"var",
"loc",
"=",
"window",
".",
"location",
";",
"if",
"(",
"path",
"[",
"path",
".",
"length",
"-",
"1",
"]",
"===",
"'/'",
")",
"{",
"path",
"=",
"path",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
";",
"}",
"if",
"(",
"~",
"path",
".",
"indexOf",
"(",
"'//'",
")",
")",
"{",
"return",
"path",
";",
"}",
"var",
"auth",
"=",
"/",
"^[^:\\/]+:\\/\\/[^\\/]+",
"/",
".",
"exec",
"(",
"loc",
".",
"href",
")",
"[",
"0",
"]",
";",
"if",
"(",
"path",
"[",
"0",
"]",
"===",
"'/'",
")",
"{",
"path",
"=",
"auth",
"+",
"path",
";",
"}",
"else",
"{",
"path",
"=",
"path",
".",
"replace",
"(",
"/",
"^\\.?\\/",
"/",
",",
"''",
")",
";",
"loc",
"=",
"loc",
".",
"pathname",
".",
"replace",
"(",
"/",
"^\\/|\\/$",
"/",
"g",
",",
"''",
")",
";",
"path",
"=",
"[",
"auth",
",",
"loc",
",",
"path",
"]",
".",
"join",
"(",
"'/'",
")",
";",
"}",
"return",
"path",
";",
"}"
]
| XXX this needs cleaning, add a parsePath method | [
"XXX",
"this",
"needs",
"cleaning",
"add",
"a",
"parsePath",
"method"
]
| 5a0643a2e4ce74e25240517e1cf423df5a188008 | https://github.com/chjj/rondo/blob/5a0643a2e4ce74e25240517e1cf423df5a188008/lib/io.js#L51-L73 |
|
47,303 | alexyoung/pop | lib/file_map.js | FileMap | function FileMap(config) {
this.config = config || {};
this.config.exclude = config && config.exclude ? config.exclude : [];
this.config.exclude.push('/_site');
this.ignoreDotFiles = true;
this.root = config.root;
this.files = [];
this.events = new EventEmitter();
this.filesLeft = 0;
this.dirsLeft = 1;
} | javascript | function FileMap(config) {
this.config = config || {};
this.config.exclude = config && config.exclude ? config.exclude : [];
this.config.exclude.push('/_site');
this.ignoreDotFiles = true;
this.root = config.root;
this.files = [];
this.events = new EventEmitter();
this.filesLeft = 0;
this.dirsLeft = 1;
} | [
"function",
"FileMap",
"(",
"config",
")",
"{",
"this",
".",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"this",
".",
"config",
".",
"exclude",
"=",
"config",
"&&",
"config",
".",
"exclude",
"?",
"config",
".",
"exclude",
":",
"[",
"]",
";",
"this",
".",
"config",
".",
"exclude",
".",
"push",
"(",
"'/_site'",
")",
";",
"this",
".",
"ignoreDotFiles",
"=",
"true",
";",
"this",
".",
"root",
"=",
"config",
".",
"root",
";",
"this",
".",
"files",
"=",
"[",
"]",
";",
"this",
".",
"events",
"=",
"new",
"EventEmitter",
"(",
")",
";",
"this",
".",
"filesLeft",
"=",
"0",
";",
"this",
".",
"dirsLeft",
"=",
"1",
";",
"}"
]
| Initialize `FileMap` with a config object.
@param {Object} options
@api public | [
"Initialize",
"FileMap",
"with",
"a",
"config",
"object",
"."
]
| 8a0b3f2605cb58e8ae6b34f1373dde00610e9858 | https://github.com/alexyoung/pop/blob/8a0b3f2605cb58e8ae6b34f1373dde00610e9858/lib/file_map.js#L21-L31 |
47,304 | diosney/json2pot | utils.js | dotFlatten | function dotFlatten(object, optSep) {
let flattenedMap = {};
if (!object) {
throw new Error('`object` should be a proper Object non null nor undefined.');
}
let sep = optSep || '.';
dotFlattenFn(object, sep, flattenedMap);
return flattenedMap;
} | javascript | function dotFlatten(object, optSep) {
let flattenedMap = {};
if (!object) {
throw new Error('`object` should be a proper Object non null nor undefined.');
}
let sep = optSep || '.';
dotFlattenFn(object, sep, flattenedMap);
return flattenedMap;
} | [
"function",
"dotFlatten",
"(",
"object",
",",
"optSep",
")",
"{",
"let",
"flattenedMap",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"object",
")",
"{",
"throw",
"new",
"Error",
"(",
"'`object` should be a proper Object non null nor undefined.'",
")",
";",
"}",
"let",
"sep",
"=",
"optSep",
"||",
"'.'",
";",
"dotFlattenFn",
"(",
"object",
",",
"sep",
",",
"flattenedMap",
")",
";",
"return",
"flattenedMap",
";",
"}"
]
| Flattens an object tree down to an object of only one level with property
names with the dotted full path to the leave data.
Ex: { 'a.b.c.d': 23, 'a.b.c.e': 54 }
Usage: `dotFlatten(object)`
Usage: `dotFlatten(object, ',')`
@param {Object} object - The object to process.
@param {String} [optSep] - The separator between nested properties. Default '.'.
@return {Object} | [
"Flattens",
"an",
"object",
"tree",
"down",
"to",
"an",
"object",
"of",
"only",
"one",
"level",
"with",
"property",
"names",
"with",
"the",
"dotted",
"full",
"path",
"to",
"the",
"leave",
"data",
"."
]
| a46c8dc0f479141824d05330d7b31cf72a5e8aa1 | https://github.com/diosney/json2pot/blob/a46c8dc0f479141824d05330d7b31cf72a5e8aa1/utils.js#L19-L29 |
47,305 | diosney/json2pot | utils.js | dotFlattenFn | function dotFlattenFn(object, sep, flattenedMap, optPathSoFar) {
let levelKeys = Object.keys(object);
for (let i = 0, j = levelKeys.length; i < j; i++) {
let key = levelKeys[i];
let value = object[key];
let pathSoFar = cloneDeep(optPathSoFar) || [];
pathSoFar.push(key);
if (isPlainObject(value)) {
dotFlattenFn(value, sep, flattenedMap, pathSoFar);
}
else {
flattenedMap[pathSoFar.join(sep)] = value;
}
}
} | javascript | function dotFlattenFn(object, sep, flattenedMap, optPathSoFar) {
let levelKeys = Object.keys(object);
for (let i = 0, j = levelKeys.length; i < j; i++) {
let key = levelKeys[i];
let value = object[key];
let pathSoFar = cloneDeep(optPathSoFar) || [];
pathSoFar.push(key);
if (isPlainObject(value)) {
dotFlattenFn(value, sep, flattenedMap, pathSoFar);
}
else {
flattenedMap[pathSoFar.join(sep)] = value;
}
}
} | [
"function",
"dotFlattenFn",
"(",
"object",
",",
"sep",
",",
"flattenedMap",
",",
"optPathSoFar",
")",
"{",
"let",
"levelKeys",
"=",
"Object",
".",
"keys",
"(",
"object",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"j",
"=",
"levelKeys",
".",
"length",
";",
"i",
"<",
"j",
";",
"i",
"++",
")",
"{",
"let",
"key",
"=",
"levelKeys",
"[",
"i",
"]",
";",
"let",
"value",
"=",
"object",
"[",
"key",
"]",
";",
"let",
"pathSoFar",
"=",
"cloneDeep",
"(",
"optPathSoFar",
")",
"||",
"[",
"]",
";",
"pathSoFar",
".",
"push",
"(",
"key",
")",
";",
"if",
"(",
"isPlainObject",
"(",
"value",
")",
")",
"{",
"dotFlattenFn",
"(",
"value",
",",
"sep",
",",
"flattenedMap",
",",
"pathSoFar",
")",
";",
"}",
"else",
"{",
"flattenedMap",
"[",
"pathSoFar",
".",
"join",
"(",
"sep",
")",
"]",
"=",
"value",
";",
"}",
"}",
"}"
]
| The real workhorse of the `dotFlatten` function.
A recursive function that fills a map when found the object leaves.
@param {Object} object
@param {String} sep - The separator between nested properties.
@param {Object} flattenedMap - The resulting object map of the flattening process.
@param {Array} [optPathSoFar] - The path that we have processed so far.
@return {Object} | [
"The",
"real",
"workhorse",
"of",
"the",
"dotFlatten",
"function",
".",
"A",
"recursive",
"function",
"that",
"fills",
"a",
"map",
"when",
"found",
"the",
"object",
"leaves",
"."
]
| a46c8dc0f479141824d05330d7b31cf72a5e8aa1 | https://github.com/diosney/json2pot/blob/a46c8dc0f479141824d05330d7b31cf72a5e8aa1/utils.js#L41-L58 |
47,306 | chovy/shapeshift | index.js | get | function get(url, opts){
opts = opts || {};
return requestp(_.extend(defaults, opts, {
url: url
}));
} | javascript | function get(url, opts){
opts = opts || {};
return requestp(_.extend(defaults, opts, {
url: url
}));
} | [
"function",
"get",
"(",
"url",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"return",
"requestp",
"(",
"_",
".",
"extend",
"(",
"defaults",
",",
"opts",
",",
"{",
"url",
":",
"url",
"}",
")",
")",
";",
"}"
]
| todo add support for callbacks instead of promises with options arg | [
"todo",
"add",
"support",
"for",
"callbacks",
"instead",
"of",
"promises",
"with",
"options",
"arg"
]
| f6699fc7df74e10bf8fe79ee81bce5d72a47df54 | https://github.com/chovy/shapeshift/blob/f6699fc7df74e10bf8fe79ee81bce5d72a47df54/index.js#L13-L19 |
47,307 | smfoote/tornado | src/compiler/visitors/visitor.js | normalizeFns | function normalizeFns(fns) {
Object.keys(fns).forEach(function(key) {
var handler = fns[key];
if (typeof handler === 'function') {
fns[key] = {
enter: handler,
leave: noop
};
}
});
} | javascript | function normalizeFns(fns) {
Object.keys(fns).forEach(function(key) {
var handler = fns[key];
if (typeof handler === 'function') {
fns[key] = {
enter: handler,
leave: noop
};
}
});
} | [
"function",
"normalizeFns",
"(",
"fns",
")",
"{",
"Object",
".",
"keys",
"(",
"fns",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"handler",
"=",
"fns",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"handler",
"===",
"'function'",
")",
"{",
"fns",
"[",
"key",
"]",
"=",
"{",
"enter",
":",
"handler",
",",
"leave",
":",
"noop",
"}",
";",
"}",
"}",
")",
";",
"}"
]
| visit can be an object with enter leave or a function if it is a function, run this on enter | [
"visit",
"can",
"be",
"an",
"object",
"with",
"enter",
"leave",
"or",
"a",
"function",
"if",
"it",
"is",
"a",
"function",
"run",
"this",
"on",
"enter"
]
| e70f35c56ee9887390843cce96ee8bf5fa491501 | https://github.com/smfoote/tornado/blob/e70f35c56ee9887390843cce96ee8bf5fa491501/src/compiler/visitors/visitor.js#L15-L25 |
47,308 | kengz/poly-socketio | src/global-client.js | init | function init(options) {
options = options || {}
var port = options.port || 6466
global.client = global.client || socketIOClient(`http://localhost:${port}`)
client = global.client
log.debug(`Started global js socketIO client for ${process.env.ADAPTER} at ${port}`)
client.emit('join', ioid) // first join for serialization
client.on('disconnect', client.disconnect)
client.on('take', hasher.handle) // add listener
// add methods
client.pass = pass
client.clientPass = clientPass
return client
} | javascript | function init(options) {
options = options || {}
var port = options.port || 6466
global.client = global.client || socketIOClient(`http://localhost:${port}`)
client = global.client
log.debug(`Started global js socketIO client for ${process.env.ADAPTER} at ${port}`)
client.emit('join', ioid) // first join for serialization
client.on('disconnect', client.disconnect)
client.on('take', hasher.handle) // add listener
// add methods
client.pass = pass
client.clientPass = clientPass
return client
} | [
"function",
"init",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
"var",
"port",
"=",
"options",
".",
"port",
"||",
"6466",
"global",
".",
"client",
"=",
"global",
".",
"client",
"||",
"socketIOClient",
"(",
"`",
"${",
"port",
"}",
"`",
")",
"client",
"=",
"global",
".",
"client",
"log",
".",
"debug",
"(",
"`",
"${",
"process",
".",
"env",
".",
"ADAPTER",
"}",
"${",
"port",
"}",
"`",
")",
"client",
".",
"emit",
"(",
"'join'",
",",
"ioid",
")",
"// first join for serialization",
"client",
".",
"on",
"(",
"'disconnect'",
",",
"client",
".",
"disconnect",
")",
"client",
".",
"on",
"(",
"'take'",
",",
"hasher",
".",
"handle",
")",
"// add listener",
"// add methods",
"client",
".",
"pass",
"=",
"pass",
"client",
".",
"clientPass",
"=",
"clientPass",
"return",
"client",
"}"
]
| init a global client at port | [
"init",
"a",
"global",
"client",
"at",
"port"
]
| 261f84d3b4267a6d1a36eadd6526ddb45369973e | https://github.com/kengz/poly-socketio/blob/261f84d3b4267a6d1a36eadd6526ddb45369973e/src/global-client.js#L12-L26 |
47,309 | kengz/poly-socketio | src/global-client.js | pass | function pass(to, input) {
var defer = cdefer()
clientPass(defer.resolve, to, input)
return defer.promise.catch((err) => {
console.log(`global-client-js promise exception with input: ${input}, to: ${JSON.stringify(to)}`)
})
} | javascript | function pass(to, input) {
var defer = cdefer()
clientPass(defer.resolve, to, input)
return defer.promise.catch((err) => {
console.log(`global-client-js promise exception with input: ${input}, to: ${JSON.stringify(to)}`)
})
} | [
"function",
"pass",
"(",
"to",
",",
"input",
")",
"{",
"var",
"defer",
"=",
"cdefer",
"(",
")",
"clientPass",
"(",
"defer",
".",
"resolve",
",",
"to",
",",
"input",
")",
"return",
"defer",
".",
"promise",
".",
"catch",
"(",
"(",
"err",
")",
"=>",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"input",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"to",
")",
"}",
"`",
")",
"}",
")",
"}"
]
| Pass that returns a promise for getting client replies conveniently.
Has promise timeout of 60s; is properly binded.
@param {string|JSON} to Name of the to script, or a JSON msg containing at least to, input
@param {*} input Input for the client to pass
@return {Promise} The promise object that will be resolved when target script replies. | [
"Pass",
"that",
"returns",
"a",
"promise",
"for",
"getting",
"client",
"replies",
"conveniently",
".",
"Has",
"promise",
"timeout",
"of",
"60s",
";",
"is",
"properly",
"binded",
"."
]
| 261f84d3b4267a6d1a36eadd6526ddb45369973e | https://github.com/kengz/poly-socketio/blob/261f84d3b4267a6d1a36eadd6526ddb45369973e/src/global-client.js#L35-L41 |
47,310 | kengz/poly-socketio | src/global-client.js | cdefer | function cdefer() {
const maxWait = 20000
var resolve, reject
var promise = new Promise((...args) => {
resolve = args[0]
reject = args[1]
})
.timeout(maxWait)
return {
resolve: resolve,
reject: reject,
promise: promise
}
} | javascript | function cdefer() {
const maxWait = 20000
var resolve, reject
var promise = new Promise((...args) => {
resolve = args[0]
reject = args[1]
})
.timeout(maxWait)
return {
resolve: resolve,
reject: reject,
promise: promise
}
} | [
"function",
"cdefer",
"(",
")",
"{",
"const",
"maxWait",
"=",
"20000",
"var",
"resolve",
",",
"reject",
"var",
"promise",
"=",
"new",
"Promise",
"(",
"(",
"...",
"args",
")",
"=>",
"{",
"resolve",
"=",
"args",
"[",
"0",
"]",
"reject",
"=",
"args",
"[",
"1",
"]",
"}",
")",
".",
"timeout",
"(",
"maxWait",
")",
"return",
"{",
"resolve",
":",
"resolve",
",",
"reject",
":",
"reject",
",",
"promise",
":",
"promise",
"}",
"}"
]
| Promise constructor using defer pattern to expose its promise, resolve, reject. Has a timeout of 60s.
@return {defer} The Promise.defer legacy msg.
/* istanbul ignore next | [
"Promise",
"constructor",
"using",
"defer",
"pattern",
"to",
"expose",
"its",
"promise",
"resolve",
"reject",
".",
"Has",
"a",
"timeout",
"of",
"60s",
"."
]
| 261f84d3b4267a6d1a36eadd6526ddb45369973e | https://github.com/kengz/poly-socketio/blob/261f84d3b4267a6d1a36eadd6526ddb45369973e/src/global-client.js#L88-L101 |
47,311 | simbo/metalsmith-better-excerpts | lib/index.js | getExcerptByMoreTag | function getExcerptByMoreTag(file, regExp) {
var excerpt = false,
contents = file.contents.toString();
contents = cheerio.load('<root>' + contents + '</root>', {decodeEntities: false})('root').html();
var match = contents.search(regExp);
if (match > -1) {
excerpt = contents.slice(0, match);
excerpt = v.unescapeHtml(excerpt);
}
return excerpt;
} | javascript | function getExcerptByMoreTag(file, regExp) {
var excerpt = false,
contents = file.contents.toString();
contents = cheerio.load('<root>' + contents + '</root>', {decodeEntities: false})('root').html();
var match = contents.search(regExp);
if (match > -1) {
excerpt = contents.slice(0, match);
excerpt = v.unescapeHtml(excerpt);
}
return excerpt;
} | [
"function",
"getExcerptByMoreTag",
"(",
"file",
",",
"regExp",
")",
"{",
"var",
"excerpt",
"=",
"false",
",",
"contents",
"=",
"file",
".",
"contents",
".",
"toString",
"(",
")",
";",
"contents",
"=",
"cheerio",
".",
"load",
"(",
"'<root>'",
"+",
"contents",
"+",
"'</root>'",
",",
"{",
"decodeEntities",
":",
"false",
"}",
")",
"(",
"'root'",
")",
".",
"html",
"(",
")",
";",
"var",
"match",
"=",
"contents",
".",
"search",
"(",
"regExp",
")",
";",
"if",
"(",
"match",
">",
"-",
"1",
")",
"{",
"excerpt",
"=",
"contents",
".",
"slice",
"(",
"0",
",",
"match",
")",
";",
"excerpt",
"=",
"v",
".",
"unescapeHtml",
"(",
"excerpt",
")",
";",
"}",
"return",
"excerpt",
";",
"}"
]
| retrieve excerpt from file object by extracting contents until a 'more' tag
@param {Object} file file object
@param {RegExp} regExp 'more' tag regexp
@return {mixed} excerpt string or false | [
"retrieve",
"excerpt",
"from",
"file",
"object",
"by",
"extracting",
"contents",
"until",
"a",
"more",
"tag"
]
| ccc9535ec8e8491eda50fabc2d433c8053435924 | https://github.com/simbo/metalsmith-better-excerpts/blob/ccc9535ec8e8491eda50fabc2d433c8053435924/lib/index.js#L57-L67 |
47,312 | simbo/metalsmith-better-excerpts | lib/index.js | getExcerptByFirstParagraph | function getExcerptByFirstParagraph(file) {
var $ = cheerio.load(file.contents.toString(), {decodeEntities: false}),
p = $('p').first(),
excerpt = p.length ? p.html().trim() : false;
if (excerpt) {
excerpt = v.unescapeHtml(excerpt);
}
return excerpt;
} | javascript | function getExcerptByFirstParagraph(file) {
var $ = cheerio.load(file.contents.toString(), {decodeEntities: false}),
p = $('p').first(),
excerpt = p.length ? p.html().trim() : false;
if (excerpt) {
excerpt = v.unescapeHtml(excerpt);
}
return excerpt;
} | [
"function",
"getExcerptByFirstParagraph",
"(",
"file",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"file",
".",
"contents",
".",
"toString",
"(",
")",
",",
"{",
"decodeEntities",
":",
"false",
"}",
")",
",",
"p",
"=",
"$",
"(",
"'p'",
")",
".",
"first",
"(",
")",
",",
"excerpt",
"=",
"p",
".",
"length",
"?",
"p",
".",
"html",
"(",
")",
".",
"trim",
"(",
")",
":",
"false",
";",
"if",
"(",
"excerpt",
")",
"{",
"excerpt",
"=",
"v",
".",
"unescapeHtml",
"(",
"excerpt",
")",
";",
"}",
"return",
"excerpt",
";",
"}"
]
| retrieve excerpt from file object by extracting the first p's contents
@param {Object} file file object
@return {mixed} excerpt string or false | [
"retrieve",
"excerpt",
"from",
"file",
"object",
"by",
"extracting",
"the",
"first",
"p",
"s",
"contents"
]
| ccc9535ec8e8491eda50fabc2d433c8053435924 | https://github.com/simbo/metalsmith-better-excerpts/blob/ccc9535ec8e8491eda50fabc2d433c8053435924/lib/index.js#L76-L84 |
47,313 | quorrajs/Positron | lib/support/str.js | is | function is(pattern, value) {
if (pattern == value) return true;
pattern = regexQuote(pattern);
// Asterisks are translated into zero-or-more regular expression wildcards
// to make it convenient to check if the strings starts with the given
// pattern such as "library/*", making any string check convenient.
pattern = pattern.replace(/\\\*/g, '.*');
pattern = new RegExp('^' + pattern + '$');
return pattern.test(value);
} | javascript | function is(pattern, value) {
if (pattern == value) return true;
pattern = regexQuote(pattern);
// Asterisks are translated into zero-or-more regular expression wildcards
// to make it convenient to check if the strings starts with the given
// pattern such as "library/*", making any string check convenient.
pattern = pattern.replace(/\\\*/g, '.*');
pattern = new RegExp('^' + pattern + '$');
return pattern.test(value);
} | [
"function",
"is",
"(",
"pattern",
",",
"value",
")",
"{",
"if",
"(",
"pattern",
"==",
"value",
")",
"return",
"true",
";",
"pattern",
"=",
"regexQuote",
"(",
"pattern",
")",
";",
"// Asterisks are translated into zero-or-more regular expression wildcards",
"// to make it convenient to check if the strings starts with the given",
"// pattern such as \"library/*\", making any string check convenient.",
"pattern",
"=",
"pattern",
".",
"replace",
"(",
"/",
"\\\\\\*",
"/",
"g",
",",
"'.*'",
")",
";",
"pattern",
"=",
"new",
"RegExp",
"(",
"'^'",
"+",
"pattern",
"+",
"'$'",
")",
";",
"return",
"pattern",
".",
"test",
"(",
"value",
")",
";",
"}"
]
| Determine if a given string matches a given pattern.
@param {string} pattern
@param {string} value
@return bool | [
"Determine",
"if",
"a",
"given",
"string",
"matches",
"a",
"given",
"pattern",
"."
]
| a4bad5a5f581743d1885405c11ae26600fb957af | https://github.com/quorrajs/Positron/blob/a4bad5a5f581743d1885405c11ae26600fb957af/lib/support/str.js#L25-L37 |
47,314 | quorrajs/Positron | lib/support/str.js | quickRandom | function quickRandom(length) {
length = length || 16;
var pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return str_shuffle(pool.repeat(5)).substr(0, length);
} | javascript | function quickRandom(length) {
length = length || 16;
var pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return str_shuffle(pool.repeat(5)).substr(0, length);
} | [
"function",
"quickRandom",
"(",
"length",
")",
"{",
"length",
"=",
"length",
"||",
"16",
";",
"var",
"pool",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'",
";",
"return",
"str_shuffle",
"(",
"pool",
".",
"repeat",
"(",
"5",
")",
")",
".",
"substr",
"(",
"0",
",",
"length",
")",
";",
"}"
]
| Generate a "random" alpha-numeric string.
Should not be considered sufficient for cryptography, etc.
@param {number} [length]
@return {string} | [
"Generate",
"a",
"random",
"alpha",
"-",
"numeric",
"string",
"."
]
| a4bad5a5f581743d1885405c11ae26600fb957af | https://github.com/quorrajs/Positron/blob/a4bad5a5f581743d1885405c11ae26600fb957af/lib/support/str.js#L77-L82 |
47,315 | Kurento/kurento-module-chroma-js | lib/complexTypes/WindowParam.js | WindowParam | function WindowParam(windowParamDict){
if(!(this instanceof WindowParam))
return new WindowParam(windowParamDict)
windowParamDict = windowParamDict || {}
// Check windowParamDict has the required fields
//
// checkType('int', 'windowParamDict.topRightCornerX', windowParamDict.topRightCornerX, {required: true});
//
// checkType('int', 'windowParamDict.topRightCornerY', windowParamDict.topRightCornerY, {required: true});
//
// checkType('int', 'windowParamDict.width', windowParamDict.width, {required: true});
//
// checkType('int', 'windowParamDict.height', windowParamDict.height, {required: true});
//
// Init parent class
WindowParam.super_.call(this, windowParamDict)
// Set object properties
Object.defineProperties(this, {
topRightCornerX: {
writable: true,
enumerable: true,
value: windowParamDict.topRightCornerX
},
topRightCornerY: {
writable: true,
enumerable: true,
value: windowParamDict.topRightCornerY
},
width: {
writable: true,
enumerable: true,
value: windowParamDict.width
},
height: {
writable: true,
enumerable: true,
value: windowParamDict.height
}
})
} | javascript | function WindowParam(windowParamDict){
if(!(this instanceof WindowParam))
return new WindowParam(windowParamDict)
windowParamDict = windowParamDict || {}
// Check windowParamDict has the required fields
//
// checkType('int', 'windowParamDict.topRightCornerX', windowParamDict.topRightCornerX, {required: true});
//
// checkType('int', 'windowParamDict.topRightCornerY', windowParamDict.topRightCornerY, {required: true});
//
// checkType('int', 'windowParamDict.width', windowParamDict.width, {required: true});
//
// checkType('int', 'windowParamDict.height', windowParamDict.height, {required: true});
//
// Init parent class
WindowParam.super_.call(this, windowParamDict)
// Set object properties
Object.defineProperties(this, {
topRightCornerX: {
writable: true,
enumerable: true,
value: windowParamDict.topRightCornerX
},
topRightCornerY: {
writable: true,
enumerable: true,
value: windowParamDict.topRightCornerY
},
width: {
writable: true,
enumerable: true,
value: windowParamDict.width
},
height: {
writable: true,
enumerable: true,
value: windowParamDict.height
}
})
} | [
"function",
"WindowParam",
"(",
"windowParamDict",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"WindowParam",
")",
")",
"return",
"new",
"WindowParam",
"(",
"windowParamDict",
")",
"windowParamDict",
"=",
"windowParamDict",
"||",
"{",
"}",
"// Check windowParamDict has the required fields",
"// ",
"// checkType('int', 'windowParamDict.topRightCornerX', windowParamDict.topRightCornerX, {required: true});",
"// ",
"// checkType('int', 'windowParamDict.topRightCornerY', windowParamDict.topRightCornerY, {required: true});",
"// ",
"// checkType('int', 'windowParamDict.width', windowParamDict.width, {required: true});",
"// ",
"// checkType('int', 'windowParamDict.height', windowParamDict.height, {required: true});",
"// ",
"// Init parent class",
"WindowParam",
".",
"super_",
".",
"call",
"(",
"this",
",",
"windowParamDict",
")",
"// Set object properties",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"topRightCornerX",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"windowParamDict",
".",
"topRightCornerX",
"}",
",",
"topRightCornerY",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"windowParamDict",
".",
"topRightCornerY",
"}",
",",
"width",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"windowParamDict",
".",
"width",
"}",
",",
"height",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"windowParamDict",
".",
"height",
"}",
"}",
")",
"}"
]
| Parameter representing a window in a video stream.
It is used in command and constructor for media elements.
All units are in pixels, X runs from left to right, Y from top to bottom.
@constructor module:chroma/complexTypes.WindowParam
@property {external:Integer} topRightCornerX
X coordinate of the left upper point of the window
@property {external:Integer} topRightCornerY
Y coordinate of the left upper point of the window
@property {external:Integer} width
width in pixels of the window
@property {external:Integer} height
height in pixels of the window | [
"Parameter",
"representing",
"a",
"window",
"in",
"a",
"video",
"stream",
".",
"It",
"is",
"used",
"in",
"command",
"and",
"constructor",
"for",
"media",
"elements",
".",
"All",
"units",
"are",
"in",
"pixels",
"X",
"runs",
"from",
"left",
"to",
"right",
"Y",
"from",
"top",
"to",
"bottom",
"."
]
| 4cd3a7504016bfb4cfd469be751a016a644fc0ba | https://github.com/Kurento/kurento-module-chroma-js/blob/4cd3a7504016bfb4cfd469be751a016a644fc0ba/lib/complexTypes/WindowParam.js#L45-L88 |
47,316 | brewster/imagine | lib/imagine/source_downloader.js | function () {
// Create request options from parsed source URL
var options = url.parse(this.source, false);
// Add on some defaults
extend(options, {
method: 'get',
headers: {
host: options.host,
accept: 'image/*'
}
});
// Determine https/http from source URL
var library = options.protocol === 'https:' ? https : http;
// Setup the request and its event binds
this.request = library.request(options);
this.request.on('response', this.onResponse.bind(this));
this.request.on('error', this.onError.bind(this));
this.request.setTimeout(5000, this.onTimeout.bind(this));
// Start the download
this.startTime = new Date().getTime();
this.request.end();
} | javascript | function () {
// Create request options from parsed source URL
var options = url.parse(this.source, false);
// Add on some defaults
extend(options, {
method: 'get',
headers: {
host: options.host,
accept: 'image/*'
}
});
// Determine https/http from source URL
var library = options.protocol === 'https:' ? https : http;
// Setup the request and its event binds
this.request = library.request(options);
this.request.on('response', this.onResponse.bind(this));
this.request.on('error', this.onError.bind(this));
this.request.setTimeout(5000, this.onTimeout.bind(this));
// Start the download
this.startTime = new Date().getTime();
this.request.end();
} | [
"function",
"(",
")",
"{",
"// Create request options from parsed source URL",
"var",
"options",
"=",
"url",
".",
"parse",
"(",
"this",
".",
"source",
",",
"false",
")",
";",
"// Add on some defaults",
"extend",
"(",
"options",
",",
"{",
"method",
":",
"'get'",
",",
"headers",
":",
"{",
"host",
":",
"options",
".",
"host",
",",
"accept",
":",
"'image/*'",
"}",
"}",
")",
";",
"// Determine https/http from source URL",
"var",
"library",
"=",
"options",
".",
"protocol",
"===",
"'https:'",
"?",
"https",
":",
"http",
";",
"// Setup the request and its event binds",
"this",
".",
"request",
"=",
"library",
".",
"request",
"(",
"options",
")",
";",
"this",
".",
"request",
".",
"on",
"(",
"'response'",
",",
"this",
".",
"onResponse",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"request",
".",
"on",
"(",
"'error'",
",",
"this",
".",
"onError",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"request",
".",
"setTimeout",
"(",
"5000",
",",
"this",
".",
"onTimeout",
".",
"bind",
"(",
"this",
")",
")",
";",
"// Start the download",
"this",
".",
"startTime",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"this",
".",
"request",
".",
"end",
"(",
")",
";",
"}"
]
| Simply start the request when we're ready to go | [
"Simply",
"start",
"the",
"request",
"when",
"we",
"re",
"ready",
"to",
"go"
]
| 42782ff6365f225f1fb9d90d3a654791286ef023 | https://github.com/brewster/imagine/blob/42782ff6365f225f1fb9d90d3a654791286ef023/lib/imagine/source_downloader.js#L18-L43 |
|
47,317 | excellalabs/ngComponentRouter | angular_1_router.js | normalizeRouteConfig | function normalizeRouteConfig(config, registry) {
if (config instanceof route_config_decorator_1.AsyncRoute) {
var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: wrappedLoader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
if (config instanceof route_config_decorator_1.Route || config instanceof route_config_decorator_1.Redirect || config instanceof route_config_decorator_1.AuxRoute) {
return config;
}
if ((+!!config.component) + (+!!config.redirectTo) + (+!!config.loader) != 1) {
throw new BaseException("Route config should contain exactly one \"component\", \"loader\", or \"redirectTo\" property.");
}
if (config.as && config.name) {
throw new BaseException("Route config should contain exactly one \"as\" or \"name\" property.");
}
if (config.as) {
config.name = config.as;
}
if (config.loader) {
var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: wrappedLoader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
if (config.aux) {
return new route_config_decorator_1.AuxRoute({ path: config.aux, component: config.component, name: config.name });
}
if (config.component) {
if (typeof config.component == 'object') {
var componentDefinitionObject = config.component;
if (componentDefinitionObject.type == 'constructor') {
return new route_config_decorator_1.Route({
path: config.path,
component: componentDefinitionObject.constructor,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
else if (componentDefinitionObject.type == 'loader') {
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: componentDefinitionObject.loader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
else {
throw new BaseException("Invalid component type \"" + componentDefinitionObject.type + "\". Valid types are \"constructor\" and \"loader\".");
}
}
return new route_config_decorator_1.Route(config);
}
if (config.redirectTo) {
return new route_config_decorator_1.Redirect({ path: config.path, redirectTo: config.redirectTo });
}
return config;
} | javascript | function normalizeRouteConfig(config, registry) {
if (config instanceof route_config_decorator_1.AsyncRoute) {
var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: wrappedLoader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
if (config instanceof route_config_decorator_1.Route || config instanceof route_config_decorator_1.Redirect || config instanceof route_config_decorator_1.AuxRoute) {
return config;
}
if ((+!!config.component) + (+!!config.redirectTo) + (+!!config.loader) != 1) {
throw new BaseException("Route config should contain exactly one \"component\", \"loader\", or \"redirectTo\" property.");
}
if (config.as && config.name) {
throw new BaseException("Route config should contain exactly one \"as\" or \"name\" property.");
}
if (config.as) {
config.name = config.as;
}
if (config.loader) {
var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: wrappedLoader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
if (config.aux) {
return new route_config_decorator_1.AuxRoute({ path: config.aux, component: config.component, name: config.name });
}
if (config.component) {
if (typeof config.component == 'object') {
var componentDefinitionObject = config.component;
if (componentDefinitionObject.type == 'constructor') {
return new route_config_decorator_1.Route({
path: config.path,
component: componentDefinitionObject.constructor,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
else if (componentDefinitionObject.type == 'loader') {
return new route_config_decorator_1.AsyncRoute({
path: config.path,
loader: componentDefinitionObject.loader,
name: config.name,
data: config.data,
useAsDefault: config.useAsDefault
});
}
else {
throw new BaseException("Invalid component type \"" + componentDefinitionObject.type + "\". Valid types are \"constructor\" and \"loader\".");
}
}
return new route_config_decorator_1.Route(config);
}
if (config.redirectTo) {
return new route_config_decorator_1.Redirect({ path: config.path, redirectTo: config.redirectTo });
}
return config;
} | [
"function",
"normalizeRouteConfig",
"(",
"config",
",",
"registry",
")",
"{",
"if",
"(",
"config",
"instanceof",
"route_config_decorator_1",
".",
"AsyncRoute",
")",
"{",
"var",
"wrappedLoader",
"=",
"wrapLoaderToReconfigureRegistry",
"(",
"config",
".",
"loader",
",",
"registry",
")",
";",
"return",
"new",
"route_config_decorator_1",
".",
"AsyncRoute",
"(",
"{",
"path",
":",
"config",
".",
"path",
",",
"loader",
":",
"wrappedLoader",
",",
"name",
":",
"config",
".",
"name",
",",
"data",
":",
"config",
".",
"data",
",",
"useAsDefault",
":",
"config",
".",
"useAsDefault",
"}",
")",
";",
"}",
"if",
"(",
"config",
"instanceof",
"route_config_decorator_1",
".",
"Route",
"||",
"config",
"instanceof",
"route_config_decorator_1",
".",
"Redirect",
"||",
"config",
"instanceof",
"route_config_decorator_1",
".",
"AuxRoute",
")",
"{",
"return",
"config",
";",
"}",
"if",
"(",
"(",
"+",
"!",
"!",
"config",
".",
"component",
")",
"+",
"(",
"+",
"!",
"!",
"config",
".",
"redirectTo",
")",
"+",
"(",
"+",
"!",
"!",
"config",
".",
"loader",
")",
"!=",
"1",
")",
"{",
"throw",
"new",
"BaseException",
"(",
"\"Route config should contain exactly one \\\"component\\\", \\\"loader\\\", or \\\"redirectTo\\\" property.\"",
")",
";",
"}",
"if",
"(",
"config",
".",
"as",
"&&",
"config",
".",
"name",
")",
"{",
"throw",
"new",
"BaseException",
"(",
"\"Route config should contain exactly one \\\"as\\\" or \\\"name\\\" property.\"",
")",
";",
"}",
"if",
"(",
"config",
".",
"as",
")",
"{",
"config",
".",
"name",
"=",
"config",
".",
"as",
";",
"}",
"if",
"(",
"config",
".",
"loader",
")",
"{",
"var",
"wrappedLoader",
"=",
"wrapLoaderToReconfigureRegistry",
"(",
"config",
".",
"loader",
",",
"registry",
")",
";",
"return",
"new",
"route_config_decorator_1",
".",
"AsyncRoute",
"(",
"{",
"path",
":",
"config",
".",
"path",
",",
"loader",
":",
"wrappedLoader",
",",
"name",
":",
"config",
".",
"name",
",",
"data",
":",
"config",
".",
"data",
",",
"useAsDefault",
":",
"config",
".",
"useAsDefault",
"}",
")",
";",
"}",
"if",
"(",
"config",
".",
"aux",
")",
"{",
"return",
"new",
"route_config_decorator_1",
".",
"AuxRoute",
"(",
"{",
"path",
":",
"config",
".",
"aux",
",",
"component",
":",
"config",
".",
"component",
",",
"name",
":",
"config",
".",
"name",
"}",
")",
";",
"}",
"if",
"(",
"config",
".",
"component",
")",
"{",
"if",
"(",
"typeof",
"config",
".",
"component",
"==",
"'object'",
")",
"{",
"var",
"componentDefinitionObject",
"=",
"config",
".",
"component",
";",
"if",
"(",
"componentDefinitionObject",
".",
"type",
"==",
"'constructor'",
")",
"{",
"return",
"new",
"route_config_decorator_1",
".",
"Route",
"(",
"{",
"path",
":",
"config",
".",
"path",
",",
"component",
":",
"componentDefinitionObject",
".",
"constructor",
",",
"name",
":",
"config",
".",
"name",
",",
"data",
":",
"config",
".",
"data",
",",
"useAsDefault",
":",
"config",
".",
"useAsDefault",
"}",
")",
";",
"}",
"else",
"if",
"(",
"componentDefinitionObject",
".",
"type",
"==",
"'loader'",
")",
"{",
"return",
"new",
"route_config_decorator_1",
".",
"AsyncRoute",
"(",
"{",
"path",
":",
"config",
".",
"path",
",",
"loader",
":",
"componentDefinitionObject",
".",
"loader",
",",
"name",
":",
"config",
".",
"name",
",",
"data",
":",
"config",
".",
"data",
",",
"useAsDefault",
":",
"config",
".",
"useAsDefault",
"}",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"BaseException",
"(",
"\"Invalid component type \\\"\"",
"+",
"componentDefinitionObject",
".",
"type",
"+",
"\"\\\". Valid types are \\\"constructor\\\" and \\\"loader\\\".\"",
")",
";",
"}",
"}",
"return",
"new",
"route_config_decorator_1",
".",
"Route",
"(",
"config",
")",
";",
"}",
"if",
"(",
"config",
".",
"redirectTo",
")",
"{",
"return",
"new",
"route_config_decorator_1",
".",
"Redirect",
"(",
"{",
"path",
":",
"config",
".",
"path",
",",
"redirectTo",
":",
"config",
".",
"redirectTo",
"}",
")",
";",
"}",
"return",
"config",
";",
"}"
]
| Given a JS Object that represents a route config, returns a corresponding Route, AsyncRoute,
AuxRoute or Redirect object.
Also wraps an AsyncRoute's loader function to add the loaded component's route config to the
`RouteRegistry`. | [
"Given",
"a",
"JS",
"Object",
"that",
"represents",
"a",
"route",
"config",
"returns",
"a",
"corresponding",
"Route",
"AsyncRoute",
"AuxRoute",
"or",
"Redirect",
"object",
"."
]
| b2240385bf542987916e07aa0d8712c962963f2d | https://github.com/excellalabs/ngComponentRouter/blob/b2240385bf542987916e07aa0d8712c962963f2d/angular_1_router.js#L1134-L1201 |
47,318 | excellalabs/ngComponentRouter | angular_1_router.js | ParamRoutePath | function ParamRoutePath(routePath) {
this.routePath = routePath;
this.terminal = true;
this._assertValidPath(routePath);
this._parsePathString(routePath);
this.specificity = this._calculateSpecificity();
this.hash = this._calculateHash();
var lastSegment = this._segments[this._segments.length - 1];
this.terminal = !(lastSegment instanceof ContinuationPathSegment);
} | javascript | function ParamRoutePath(routePath) {
this.routePath = routePath;
this.terminal = true;
this._assertValidPath(routePath);
this._parsePathString(routePath);
this.specificity = this._calculateSpecificity();
this.hash = this._calculateHash();
var lastSegment = this._segments[this._segments.length - 1];
this.terminal = !(lastSegment instanceof ContinuationPathSegment);
} | [
"function",
"ParamRoutePath",
"(",
"routePath",
")",
"{",
"this",
".",
"routePath",
"=",
"routePath",
";",
"this",
".",
"terminal",
"=",
"true",
";",
"this",
".",
"_assertValidPath",
"(",
"routePath",
")",
";",
"this",
".",
"_parsePathString",
"(",
"routePath",
")",
";",
"this",
".",
"specificity",
"=",
"this",
".",
"_calculateSpecificity",
"(",
")",
";",
"this",
".",
"hash",
"=",
"this",
".",
"_calculateHash",
"(",
")",
";",
"var",
"lastSegment",
"=",
"this",
".",
"_segments",
"[",
"this",
".",
"_segments",
".",
"length",
"-",
"1",
"]",
";",
"this",
".",
"terminal",
"=",
"!",
"(",
"lastSegment",
"instanceof",
"ContinuationPathSegment",
")",
";",
"}"
]
| Takes a string representing the matcher DSL | [
"Takes",
"a",
"string",
"representing",
"the",
"matcher",
"DSL"
]
| b2240385bf542987916e07aa0d8712c962963f2d | https://github.com/excellalabs/ngComponentRouter/blob/b2240385bf542987916e07aa0d8712c962963f2d/angular_1_router.js#L1610-L1619 |
47,319 | gurmukhp/gulp-svg-json-spritesheet | index.js | convertToJson | function convertToJson(callback) {
var output = new File(file);
output.contents = new Buffer(JSON.stringify(spritesheet, null, '\t'));
output.path = file;
this.push(output);
callback();
} | javascript | function convertToJson(callback) {
var output = new File(file);
output.contents = new Buffer(JSON.stringify(spritesheet, null, '\t'));
output.path = file;
this.push(output);
callback();
} | [
"function",
"convertToJson",
"(",
"callback",
")",
"{",
"var",
"output",
"=",
"new",
"File",
"(",
"file",
")",
";",
"output",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"JSON",
".",
"stringify",
"(",
"spritesheet",
",",
"null",
",",
"'\\t'",
")",
")",
";",
"output",
".",
"path",
"=",
"file",
";",
"this",
".",
"push",
"(",
"output",
")",
";",
"callback",
"(",
")",
";",
"}"
]
| Once all files have been compressed, return compressed JSON file.
@param {Function} callback | [
"Once",
"all",
"files",
"have",
"been",
"compressed",
"return",
"compressed",
"JSON",
"file",
"."
]
| 393f629cad491365c0fc65b290b81f036432d50a | https://github.com/gurmukhp/gulp-svg-json-spritesheet/blob/393f629cad491365c0fc65b290b81f036432d50a/index.js#L64-L70 |
47,320 | freshout-dev/thulium | lib/Thulium/Parser.js | function( callback ){
var tm = this;
setTimeout(function () {
var returnValue;
//check for template existance.
if (tm.template) {
tm._tokenize();
returnValue = tm._tokens;
// execute callback.
if (callback) {
callback( returnValue );
}
} else {
throw "ParseError: No template to parse.";
}
}, 0);
} | javascript | function( callback ){
var tm = this;
setTimeout(function () {
var returnValue;
//check for template existance.
if (tm.template) {
tm._tokenize();
returnValue = tm._tokens;
// execute callback.
if (callback) {
callback( returnValue );
}
} else {
throw "ParseError: No template to parse.";
}
}, 0);
} | [
"function",
"(",
"callback",
")",
"{",
"var",
"tm",
"=",
"this",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"var",
"returnValue",
";",
"//check for template existance.",
"if",
"(",
"tm",
".",
"template",
")",
"{",
"tm",
".",
"_tokenize",
"(",
")",
";",
"returnValue",
"=",
"tm",
".",
"_tokens",
";",
"// execute callback.",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"returnValue",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"\"ParseError: No template to parse.\"",
";",
"}",
"}",
",",
"0",
")",
";",
"}"
]
| Creates the token array and sends them to a callback | [
"Creates",
"the",
"token",
"array",
"and",
"sends",
"them",
"to",
"a",
"callback"
]
| ba3173e700fbe810ce13063e7ad46e9b05bb49e7 | https://github.com/freshout-dev/thulium/blob/ba3173e700fbe810ce13063e7ad46e9b05bb49e7/lib/Thulium/Parser.js#L75-L94 |
|
47,321 | freshout-dev/thulium | lib/Thulium/Parser.js | function () {
var i;
i = this._openPrints.indexOf(this._openBrackets);
// if print indicators where found
if (i >= 0) {
// close it
this._tokens.push({
type : "closePrintIndicator"
});
// remove the print from the stack
this._openPrints.splice(i, 1);
}
} | javascript | function () {
var i;
i = this._openPrints.indexOf(this._openBrackets);
// if print indicators where found
if (i >= 0) {
// close it
this._tokens.push({
type : "closePrintIndicator"
});
// remove the print from the stack
this._openPrints.splice(i, 1);
}
} | [
"function",
"(",
")",
"{",
"var",
"i",
";",
"i",
"=",
"this",
".",
"_openPrints",
".",
"indexOf",
"(",
"this",
".",
"_openBrackets",
")",
";",
"// if print indicators where found",
"if",
"(",
"i",
">=",
"0",
")",
"{",
"// close it",
"this",
".",
"_tokens",
".",
"push",
"(",
"{",
"type",
":",
"\"closePrintIndicator\"",
"}",
")",
";",
"// remove the print from the stack",
"this",
".",
"_openPrints",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"}"
]
| Remove the printIndicator buffer if no open brackets were found. | [
"Remove",
"the",
"printIndicator",
"buffer",
"if",
"no",
"open",
"brackets",
"were",
"found",
"."
]
| ba3173e700fbe810ce13063e7ad46e9b05bb49e7 | https://github.com/freshout-dev/thulium/blob/ba3173e700fbe810ce13063e7ad46e9b05bb49e7/lib/Thulium/Parser.js#L249-L262 |
|
47,322 | mgcrea/gulp-nginclude | src/index.js | readSource | function readSource(src) {
var cwd = path.dirname(file.path);
if (options.assetsDirs && options.assetsDirs.length) {
var basename = path.basename(cwd);
if (options.assetsDirs.indexOf(basename) === -1) {
options.assetsDirs.unshift(path.basename(cwd));
}
src = path.join(options.assetsDirs.length > 1 ? '{' + options.assetsDirs.join(',') + '}' : options.assetsDirs[0], src);
cwd = path.dirname(cwd);
}
var match = glob.sync(src, {cwd: cwd});
if (!match.length) return next(new PluginError('gulp-nginclude', 'File "' + src + '" not found'));
return fs.readFileSync(path.join(cwd, match[0])).toString();
} | javascript | function readSource(src) {
var cwd = path.dirname(file.path);
if (options.assetsDirs && options.assetsDirs.length) {
var basename = path.basename(cwd);
if (options.assetsDirs.indexOf(basename) === -1) {
options.assetsDirs.unshift(path.basename(cwd));
}
src = path.join(options.assetsDirs.length > 1 ? '{' + options.assetsDirs.join(',') + '}' : options.assetsDirs[0], src);
cwd = path.dirname(cwd);
}
var match = glob.sync(src, {cwd: cwd});
if (!match.length) return next(new PluginError('gulp-nginclude', 'File "' + src + '" not found'));
return fs.readFileSync(path.join(cwd, match[0])).toString();
} | [
"function",
"readSource",
"(",
"src",
")",
"{",
"var",
"cwd",
"=",
"path",
".",
"dirname",
"(",
"file",
".",
"path",
")",
";",
"if",
"(",
"options",
".",
"assetsDirs",
"&&",
"options",
".",
"assetsDirs",
".",
"length",
")",
"{",
"var",
"basename",
"=",
"path",
".",
"basename",
"(",
"cwd",
")",
";",
"if",
"(",
"options",
".",
"assetsDirs",
".",
"indexOf",
"(",
"basename",
")",
"===",
"-",
"1",
")",
"{",
"options",
".",
"assetsDirs",
".",
"unshift",
"(",
"path",
".",
"basename",
"(",
"cwd",
")",
")",
";",
"}",
"src",
"=",
"path",
".",
"join",
"(",
"options",
".",
"assetsDirs",
".",
"length",
">",
"1",
"?",
"'{'",
"+",
"options",
".",
"assetsDirs",
".",
"join",
"(",
"','",
")",
"+",
"'}'",
":",
"options",
".",
"assetsDirs",
"[",
"0",
"]",
",",
"src",
")",
";",
"cwd",
"=",
"path",
".",
"dirname",
"(",
"cwd",
")",
";",
"}",
"var",
"match",
"=",
"glob",
".",
"sync",
"(",
"src",
",",
"{",
"cwd",
":",
"cwd",
"}",
")",
";",
"if",
"(",
"!",
"match",
".",
"length",
")",
"return",
"next",
"(",
"new",
"PluginError",
"(",
"'gulp-nginclude'",
",",
"'File \"'",
"+",
"src",
"+",
"'\" not found'",
")",
")",
";",
"return",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"join",
"(",
"cwd",
",",
"match",
"[",
"0",
"]",
")",
")",
".",
"toString",
"(",
")",
";",
"}"
]
| This function receives an ng-include src and tries to read it from the filesystem | [
"This",
"function",
"receives",
"an",
"ng",
"-",
"include",
"src",
"and",
"tries",
"to",
"read",
"it",
"from",
"the",
"filesystem"
]
| d9bfbf6c5d0f120f67827aa42fdb98ddc9177862 | https://github.com/mgcrea/gulp-nginclude/blob/d9bfbf6c5d0f120f67827aa42fdb98ddc9177862/src/index.js#L25-L38 |
47,323 | edus44/express-deliver | lib/response/success.js | normalizeResult | function normalizeResult(result){
if (!result || result._isResponseData !== true)
return ResponseData(result,{default:true})
return result
} | javascript | function normalizeResult(result){
if (!result || result._isResponseData !== true)
return ResponseData(result,{default:true})
return result
} | [
"function",
"normalizeResult",
"(",
"result",
")",
"{",
"if",
"(",
"!",
"result",
"||",
"result",
".",
"_isResponseData",
"!==",
"true",
")",
"return",
"ResponseData",
"(",
"result",
",",
"{",
"default",
":",
"true",
"}",
")",
"return",
"result",
"}"
]
| Tries to return a ResponseData object
@param {any} result
@return {ResponseData} | [
"Tries",
"to",
"return",
"a",
"ResponseData",
"object"
]
| 895abfaf2e5e48a00b4fef943dccaffcbf244780 | https://github.com/edus44/express-deliver/blob/895abfaf2e5e48a00b4fef943dccaffcbf244780/lib/response/success.js#L25-L29 |
47,324 | edus44/express-deliver | lib/response/success.js | defaultTransformSuccess | function defaultTransformSuccess(value,options){
if (options.default === true){
return {
status:true,
data:value
}
}
if (options.appendStatus !== false){
let obj = typeof value == 'object' ? value : {}
return Object.assign(obj,{status:true})
}
return value
} | javascript | function defaultTransformSuccess(value,options){
if (options.default === true){
return {
status:true,
data:value
}
}
if (options.appendStatus !== false){
let obj = typeof value == 'object' ? value : {}
return Object.assign(obj,{status:true})
}
return value
} | [
"function",
"defaultTransformSuccess",
"(",
"value",
",",
"options",
")",
"{",
"if",
"(",
"options",
".",
"default",
"===",
"true",
")",
"{",
"return",
"{",
"status",
":",
"true",
",",
"data",
":",
"value",
"}",
"}",
"if",
"(",
"options",
".",
"appendStatus",
"!==",
"false",
")",
"{",
"let",
"obj",
"=",
"typeof",
"value",
"==",
"'object'",
"?",
"value",
":",
"{",
"}",
"return",
"Object",
".",
"assign",
"(",
"obj",
",",
"{",
"status",
":",
"true",
"}",
")",
"}",
"return",
"value",
"}"
]
| Transform the responseData
@param {any} value
@param {Object} options
@param {Request} req
@returns {Object} | [
"Transform",
"the",
"responseData"
]
| 895abfaf2e5e48a00b4fef943dccaffcbf244780 | https://github.com/edus44/express-deliver/blob/895abfaf2e5e48a00b4fef943dccaffcbf244780/lib/response/success.js#L40-L54 |
47,325 | fibo/strict-mode | index.js | strictMode | function strictMode (callback) {
'use strict'
// The module api is in *Locked* state, so it will not change
// see http://nodejs.org/api/modules.html
// that is why I just copyed and pasted the orig module wrapper.
//
// By the way, in test.js there is a test that checks if the content of
// *origWrapper* needs an update.
const origWrapper = '(function (exports, require, module, __filename, __dirname) { '
const strictWrapper = origWrapper + '"use strict";'
if (typeof callback !== 'function') {
throw new TypeError('Argument *callback* must be a function')
}
const module = require('module')
if (typeof module.wrapper === 'undefined') {
// If you enter here, you are in a context other than server side Node.js.
// Since module.wrapper is not defined, do not switch strict mode on.
callback()
} else {
if (module.wrapper[0] === origWrapper) {
module.wrapper[0] = strictWrapper
// Every require in this callback will load modules in strict mode.
try {
callback()
} catch (err) {
console.error(err.stack)
}
// Restore orig module wrapper, play well with others.
module.wrapper[0] = origWrapper
} else {
// If module.wrapper[0] changed, do not switch strict mode on.
callback()
}
}
} | javascript | function strictMode (callback) {
'use strict'
// The module api is in *Locked* state, so it will not change
// see http://nodejs.org/api/modules.html
// that is why I just copyed and pasted the orig module wrapper.
//
// By the way, in test.js there is a test that checks if the content of
// *origWrapper* needs an update.
const origWrapper = '(function (exports, require, module, __filename, __dirname) { '
const strictWrapper = origWrapper + '"use strict";'
if (typeof callback !== 'function') {
throw new TypeError('Argument *callback* must be a function')
}
const module = require('module')
if (typeof module.wrapper === 'undefined') {
// If you enter here, you are in a context other than server side Node.js.
// Since module.wrapper is not defined, do not switch strict mode on.
callback()
} else {
if (module.wrapper[0] === origWrapper) {
module.wrapper[0] = strictWrapper
// Every require in this callback will load modules in strict mode.
try {
callback()
} catch (err) {
console.error(err.stack)
}
// Restore orig module wrapper, play well with others.
module.wrapper[0] = origWrapper
} else {
// If module.wrapper[0] changed, do not switch strict mode on.
callback()
}
}
} | [
"function",
"strictMode",
"(",
"callback",
")",
"{",
"'use strict'",
"// The module api is in *Locked* state, so it will not change",
"// see http://nodejs.org/api/modules.html",
"// that is why I just copyed and pasted the orig module wrapper.",
"//",
"// By the way, in test.js there is a test that checks if the content of",
"// *origWrapper* needs an update.",
"const",
"origWrapper",
"=",
"'(function (exports, require, module, __filename, __dirname) { '",
"const",
"strictWrapper",
"=",
"origWrapper",
"+",
"'\"use strict\";'",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'Argument *callback* must be a function'",
")",
"}",
"const",
"module",
"=",
"require",
"(",
"'module'",
")",
"if",
"(",
"typeof",
"module",
".",
"wrapper",
"===",
"'undefined'",
")",
"{",
"// If you enter here, you are in a context other than server side Node.js.",
"// Since module.wrapper is not defined, do not switch strict mode on.",
"callback",
"(",
")",
"}",
"else",
"{",
"if",
"(",
"module",
".",
"wrapper",
"[",
"0",
"]",
"===",
"origWrapper",
")",
"{",
"module",
".",
"wrapper",
"[",
"0",
"]",
"=",
"strictWrapper",
"// Every require in this callback will load modules in strict mode.",
"try",
"{",
"callback",
"(",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
".",
"stack",
")",
"}",
"// Restore orig module wrapper, play well with others.",
"module",
".",
"wrapper",
"[",
"0",
"]",
"=",
"origWrapper",
"}",
"else",
"{",
"// If module.wrapper[0] changed, do not switch strict mode on.",
"callback",
"(",
")",
"}",
"}",
"}"
]
| Wraps module `exports`
See [Usage](http://g14n.info/strict-mode#usage)
@param {Function} callback containing caller package's exports statements | [
"Wraps",
"module",
"exports"
]
| f0039a08bdd7835af64610cafdd2caab554cd700 | https://github.com/fibo/strict-mode/blob/f0039a08bdd7835af64610cafdd2caab554cd700/index.js#L9-L50 |
47,326 | sapegin/textlint-rule-diacritics | index.js | getWords | function getWords(words) {
const defaults = loadJson('./words.json');
const extras = typeof words === 'string' ? loadJson(words) : words;
return defaults.concat(extras);
} | javascript | function getWords(words) {
const defaults = loadJson('./words.json');
const extras = typeof words === 'string' ? loadJson(words) : words;
return defaults.concat(extras);
} | [
"function",
"getWords",
"(",
"words",
")",
"{",
"const",
"defaults",
"=",
"loadJson",
"(",
"'./words.json'",
")",
";",
"const",
"extras",
"=",
"typeof",
"words",
"===",
"'string'",
"?",
"loadJson",
"(",
"words",
")",
":",
"words",
";",
"return",
"defaults",
".",
"concat",
"(",
"extras",
")",
";",
"}"
]
| Load all default words joined with additional worsd from a config file
@param {string|string[]} words
@return {string[]} | [
"Load",
"all",
"default",
"words",
"joined",
"with",
"additional",
"worsd",
"from",
"a",
"config",
"file"
]
| 5dcb40c9ec128bc147325783ed4859fa66baaecf | https://github.com/sapegin/textlint-rule-diacritics/blob/5dcb40c9ec128bc147325783ed4859fa66baaecf/index.js#L54-L58 |
47,327 | sapegin/textlint-rule-diacritics | index.js | loadJson | function loadJson(filepath) {
const json = fs.readFileSync(require.resolve(filepath), 'utf8');
return JSON.parse(stripJsonComments(json));
} | javascript | function loadJson(filepath) {
const json = fs.readFileSync(require.resolve(filepath), 'utf8');
return JSON.parse(stripJsonComments(json));
} | [
"function",
"loadJson",
"(",
"filepath",
")",
"{",
"const",
"json",
"=",
"fs",
".",
"readFileSync",
"(",
"require",
".",
"resolve",
"(",
"filepath",
")",
",",
"'utf8'",
")",
";",
"return",
"JSON",
".",
"parse",
"(",
"stripJsonComments",
"(",
"json",
")",
")",
";",
"}"
]
| Load JSON file, strip comments.
@param {string} filepath
@return {object} | [
"Load",
"JSON",
"file",
"strip",
"comments",
"."
]
| 5dcb40c9ec128bc147325783ed4859fa66baaecf | https://github.com/sapegin/textlint-rule-diacritics/blob/5dcb40c9ec128bc147325783ed4859fa66baaecf/index.js#L66-L69 |
47,328 | sapegin/textlint-rule-diacritics | index.js | getCorrection | function getCorrection(words, match) {
for (const word of words) {
const pattern = getPattern(word);
if (!getRegExp([pattern]).test(match)) {
continue;
}
const corrected = match.replace(new RegExp(`\\b${pattern}`, 'i'), word);
return matchCasing(corrected, match);
}
return false;
} | javascript | function getCorrection(words, match) {
for (const word of words) {
const pattern = getPattern(word);
if (!getRegExp([pattern]).test(match)) {
continue;
}
const corrected = match.replace(new RegExp(`\\b${pattern}`, 'i'), word);
return matchCasing(corrected, match);
}
return false;
} | [
"function",
"getCorrection",
"(",
"words",
",",
"match",
")",
"{",
"for",
"(",
"const",
"word",
"of",
"words",
")",
"{",
"const",
"pattern",
"=",
"getPattern",
"(",
"word",
")",
";",
"if",
"(",
"!",
"getRegExp",
"(",
"[",
"pattern",
"]",
")",
".",
"test",
"(",
"match",
")",
")",
"{",
"continue",
";",
"}",
"const",
"corrected",
"=",
"match",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"`",
"\\\\",
"${",
"pattern",
"}",
"`",
",",
"'i'",
")",
",",
"word",
")",
";",
"return",
"matchCasing",
"(",
"corrected",
",",
"match",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Return a correct word based on found incorrect word.
Keeps case and suffix of an original word.
@param {string[]} words
@param {string} match
@return {string|boolean} | [
"Return",
"a",
"correct",
"word",
"based",
"on",
"found",
"incorrect",
"word",
".",
"Keeps",
"case",
"and",
"suffix",
"of",
"an",
"original",
"word",
"."
]
| 5dcb40c9ec128bc147325783ed4859fa66baaecf | https://github.com/sapegin/textlint-rule-diacritics/blob/5dcb40c9ec128bc147325783ed4859fa66baaecf/index.js#L127-L139 |
47,329 | brewster/imagine | lib/imagine/server.js | function () {
// Determine https vs. http
this.server = this.ssl ?
https.createServer(this.ssl) :
http.createServer();
// Bind to the request
this.server.on('request', this.handle.bind(this));
} | javascript | function () {
// Determine https vs. http
this.server = this.ssl ?
https.createServer(this.ssl) :
http.createServer();
// Bind to the request
this.server.on('request', this.handle.bind(this));
} | [
"function",
"(",
")",
"{",
"// Determine https vs. http",
"this",
".",
"server",
"=",
"this",
".",
"ssl",
"?",
"https",
".",
"createServer",
"(",
"this",
".",
"ssl",
")",
":",
"http",
".",
"createServer",
"(",
")",
";",
"// Bind to the request",
"this",
".",
"server",
".",
"on",
"(",
"'request'",
",",
"this",
".",
"handle",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Create a new server | [
"Create",
"a",
"new",
"server"
]
| 42782ff6365f225f1fb9d90d3a654791286ef023 | https://github.com/brewster/imagine/blob/42782ff6365f225f1fb9d90d3a654791286ef023/lib/imagine/server.js#L43-L51 |
|
47,330 | partageit/vegetables | lib/generate.js | function(folder, dest) {
try {
fs.mkdirSync(dest, '0755');
} catch (e) {}
var files = fs.readdirSync(folder);
var indexFile = templatesManager.getFolderIndex(files);
logger.debug('Index file for "%s": "%s"', folder, indexFile);
files.forEach(function(file) {
if (config.exclude.indexOf(file) === -1) {
var curPath = path.join(folder, file);
if (fs.statSync(curPath).isDirectory()) {
walk(curPath, path.join(dest, file));
} else {
if (['.md', '.markdown'].indexOf(path.extname(file).toLowerCase()) !== -1) {
var isIndex = (file === indexFile);
filesToRender[curPath] = {
filename: file,
path: curPath,
versions: templatesManager.getVersions(curPath, 'template', isIndex),
isIndex: isIndex
};
} else if (config.media.indexOf(path.extname(file).toLowerCase().substr(1)) !== -1) {
logger.log('Copy "%s" to "%s"', curPath, path.join(dest, path.basename(curPath)));
fs.copy(curPath, path.join(dest, path.basename(curPath)), {replace: true}, function(err) {
if (err) {
logger.error('Problem while copying media file "%s" to "%s": "%s"', curPath, path.join(dest, path.basename(curPath)), err);
}
});
}
}
} else {
logger.debug('Excluded:', file);
}
});
} | javascript | function(folder, dest) {
try {
fs.mkdirSync(dest, '0755');
} catch (e) {}
var files = fs.readdirSync(folder);
var indexFile = templatesManager.getFolderIndex(files);
logger.debug('Index file for "%s": "%s"', folder, indexFile);
files.forEach(function(file) {
if (config.exclude.indexOf(file) === -1) {
var curPath = path.join(folder, file);
if (fs.statSync(curPath).isDirectory()) {
walk(curPath, path.join(dest, file));
} else {
if (['.md', '.markdown'].indexOf(path.extname(file).toLowerCase()) !== -1) {
var isIndex = (file === indexFile);
filesToRender[curPath] = {
filename: file,
path: curPath,
versions: templatesManager.getVersions(curPath, 'template', isIndex),
isIndex: isIndex
};
} else if (config.media.indexOf(path.extname(file).toLowerCase().substr(1)) !== -1) {
logger.log('Copy "%s" to "%s"', curPath, path.join(dest, path.basename(curPath)));
fs.copy(curPath, path.join(dest, path.basename(curPath)), {replace: true}, function(err) {
if (err) {
logger.error('Problem while copying media file "%s" to "%s": "%s"', curPath, path.join(dest, path.basename(curPath)), err);
}
});
}
}
} else {
logger.debug('Excluded:', file);
}
});
} | [
"function",
"(",
"folder",
",",
"dest",
")",
"{",
"try",
"{",
"fs",
".",
"mkdirSync",
"(",
"dest",
",",
"'0755'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"var",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"folder",
")",
";",
"var",
"indexFile",
"=",
"templatesManager",
".",
"getFolderIndex",
"(",
"files",
")",
";",
"logger",
".",
"debug",
"(",
"'Index file for \"%s\": \"%s\"'",
",",
"folder",
",",
"indexFile",
")",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"config",
".",
"exclude",
".",
"indexOf",
"(",
"file",
")",
"===",
"-",
"1",
")",
"{",
"var",
"curPath",
"=",
"path",
".",
"join",
"(",
"folder",
",",
"file",
")",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"curPath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"walk",
"(",
"curPath",
",",
"path",
".",
"join",
"(",
"dest",
",",
"file",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"[",
"'.md'",
",",
"'.markdown'",
"]",
".",
"indexOf",
"(",
"path",
".",
"extname",
"(",
"file",
")",
".",
"toLowerCase",
"(",
")",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"isIndex",
"=",
"(",
"file",
"===",
"indexFile",
")",
";",
"filesToRender",
"[",
"curPath",
"]",
"=",
"{",
"filename",
":",
"file",
",",
"path",
":",
"curPath",
",",
"versions",
":",
"templatesManager",
".",
"getVersions",
"(",
"curPath",
",",
"'template'",
",",
"isIndex",
")",
",",
"isIndex",
":",
"isIndex",
"}",
";",
"}",
"else",
"if",
"(",
"config",
".",
"media",
".",
"indexOf",
"(",
"path",
".",
"extname",
"(",
"file",
")",
".",
"toLowerCase",
"(",
")",
".",
"substr",
"(",
"1",
")",
")",
"!==",
"-",
"1",
")",
"{",
"logger",
".",
"log",
"(",
"'Copy \"%s\" to \"%s\"'",
",",
"curPath",
",",
"path",
".",
"join",
"(",
"dest",
",",
"path",
".",
"basename",
"(",
"curPath",
")",
")",
")",
";",
"fs",
".",
"copy",
"(",
"curPath",
",",
"path",
".",
"join",
"(",
"dest",
",",
"path",
".",
"basename",
"(",
"curPath",
")",
")",
",",
"{",
"replace",
":",
"true",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"logger",
".",
"error",
"(",
"'Problem while copying media file \"%s\" to \"%s\": \"%s\"'",
",",
"curPath",
",",
"path",
".",
"join",
"(",
"dest",
",",
"path",
".",
"basename",
"(",
"curPath",
")",
")",
",",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
"else",
"{",
"logger",
".",
"debug",
"(",
"'Excluded:'",
",",
"file",
")",
";",
"}",
"}",
")",
";",
"}"
]
| filename => filename, path, versions Function to discover Markdown files and copy media files | [
"filename",
"=",
">",
"filename",
"path",
"versions",
"Function",
"to",
"discover",
"Markdown",
"files",
"and",
"copy",
"media",
"files"
]
| 1aca3ee726885427974e3f0f88e6c2f5fe884e74 | https://github.com/partageit/vegetables/blob/1aca3ee726885427974e3f0f88e6c2f5fe884e74/lib/generate.js#L28-L62 |
|
47,331 | partageit/vegetables | lib/generate.js | function(commands) {
if (!commands || (commands.length === 0)) {
return true;
}
if (typeof commands === 'string') {
commands = [commands];
}
return commands.every(function(command) {
logger.info('Starting command "%s"...', command);
var result = exec(
command,
{cwd: path.resolve('.')}
);
if (result.status !== 0) { // error
logger.error('Error: "%s" - "%s"', result.stdout, result.stderr.trim());
return false;
}
logger.success('Command successfully finished');
logger.log('Command result: "%s"', result.stdout);
return true;
});
} | javascript | function(commands) {
if (!commands || (commands.length === 0)) {
return true;
}
if (typeof commands === 'string') {
commands = [commands];
}
return commands.every(function(command) {
logger.info('Starting command "%s"...', command);
var result = exec(
command,
{cwd: path.resolve('.')}
);
if (result.status !== 0) { // error
logger.error('Error: "%s" - "%s"', result.stdout, result.stderr.trim());
return false;
}
logger.success('Command successfully finished');
logger.log('Command result: "%s"', result.stdout);
return true;
});
} | [
"function",
"(",
"commands",
")",
"{",
"if",
"(",
"!",
"commands",
"||",
"(",
"commands",
".",
"length",
"===",
"0",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"typeof",
"commands",
"===",
"'string'",
")",
"{",
"commands",
"=",
"[",
"commands",
"]",
";",
"}",
"return",
"commands",
".",
"every",
"(",
"function",
"(",
"command",
")",
"{",
"logger",
".",
"info",
"(",
"'Starting command \"%s\"...'",
",",
"command",
")",
";",
"var",
"result",
"=",
"exec",
"(",
"command",
",",
"{",
"cwd",
":",
"path",
".",
"resolve",
"(",
"'.'",
")",
"}",
")",
";",
"if",
"(",
"result",
".",
"status",
"!==",
"0",
")",
"{",
"// error",
"logger",
".",
"error",
"(",
"'Error: \"%s\" - \"%s\"'",
",",
"result",
".",
"stdout",
",",
"result",
".",
"stderr",
".",
"trim",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"logger",
".",
"success",
"(",
"'Command successfully finished'",
")",
";",
"logger",
".",
"log",
"(",
"'Command result: \"%s\"'",
",",
"result",
".",
"stdout",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"}"
]
| Function to start before and after commands | [
"Function",
"to",
"start",
"before",
"and",
"after",
"commands"
]
| 1aca3ee726885427974e3f0f88e6c2f5fe884e74 | https://github.com/partageit/vegetables/blob/1aca3ee726885427974e3f0f88e6c2f5fe884e74/lib/generate.js#L65-L86 |
|
47,332 | edloidas/roll-parser | src/roller.js | rollClassic | function rollClassic( roll ) {
const data = roll instanceof Roll ? roll : convertToRoll( roll );
const { dice, count, modifier } = data;
const rolls = [ ...new Array( count ) ].map(() => randomRoll( dice ));
const summ = rolls.reduce(( prev, curr ) => prev + curr, 0 );
const result = normalizeRollResult( summ + modifier );
return new Result( data.toString(), result, rolls );
} | javascript | function rollClassic( roll ) {
const data = roll instanceof Roll ? roll : convertToRoll( roll );
const { dice, count, modifier } = data;
const rolls = [ ...new Array( count ) ].map(() => randomRoll( dice ));
const summ = rolls.reduce(( prev, curr ) => prev + curr, 0 );
const result = normalizeRollResult( summ + modifier );
return new Result( data.toString(), result, rolls );
} | [
"function",
"rollClassic",
"(",
"roll",
")",
"{",
"const",
"data",
"=",
"roll",
"instanceof",
"Roll",
"?",
"roll",
":",
"convertToRoll",
"(",
"roll",
")",
";",
"const",
"{",
"dice",
",",
"count",
",",
"modifier",
"}",
"=",
"data",
";",
"const",
"rolls",
"=",
"[",
"...",
"new",
"Array",
"(",
"count",
")",
"]",
".",
"map",
"(",
"(",
")",
"=>",
"randomRoll",
"(",
"dice",
")",
")",
";",
"const",
"summ",
"=",
"rolls",
".",
"reduce",
"(",
"(",
"prev",
",",
"curr",
")",
"=>",
"prev",
"+",
"curr",
",",
"0",
")",
";",
"const",
"result",
"=",
"normalizeRollResult",
"(",
"summ",
"+",
"modifier",
")",
";",
"return",
"new",
"Result",
"(",
"data",
".",
"toString",
"(",
")",
",",
"result",
",",
"rolls",
")",
";",
"}"
]
| Rolls the dice from `Roll` object.
@func
@since v2.0.0
@param {Roll} roll - `Roll` object or similar
@return {Result}
@see roll
@see rollWod
@example
rollClassic(new Roll(10, 2, -1)); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
rollClassic({ dice: 6 }); //=> { notation: 'd6', value: 4, rolls: [ 4 ] } | [
"Rolls",
"the",
"dice",
"from",
"Roll",
"object",
"."
]
| 38912b298edb0a4d67ba1c796d7ac159ebaf7901 | https://github.com/edloidas/roll-parser/blob/38912b298edb0a4d67ba1c796d7ac159ebaf7901/src/roller.js#L22-L31 |
47,333 | edloidas/roll-parser | src/roller.js | rollWod | function rollWod( roll ) {
const data = roll instanceof WodRoll ? roll : convertToWodRoll( roll );
const { dice, count, again, success, fail } = data;
const rolls = [];
let i = count;
while ( i > 0 ) {
const value = randomRoll( dice );
rolls.push( value );
// Check for "10 Again" flag
// `repeatLimit` will prevent infinite loop, for cases like `d1!>1`
const repeatLimit = 100;
if ( value !== dice || !again || rolls.length > repeatLimit ) {
i -= 1;
}
}
const result = rolls.reduce(( suc, val ) => {
if ( val >= success ) {
return suc + 1;
} else if ( val <= fail ) {
return suc - 1;
}
return suc;
}, 0 );
return new Result( data.toString(), Math.max( result, 0 ), rolls );
} | javascript | function rollWod( roll ) {
const data = roll instanceof WodRoll ? roll : convertToWodRoll( roll );
const { dice, count, again, success, fail } = data;
const rolls = [];
let i = count;
while ( i > 0 ) {
const value = randomRoll( dice );
rolls.push( value );
// Check for "10 Again" flag
// `repeatLimit` will prevent infinite loop, for cases like `d1!>1`
const repeatLimit = 100;
if ( value !== dice || !again || rolls.length > repeatLimit ) {
i -= 1;
}
}
const result = rolls.reduce(( suc, val ) => {
if ( val >= success ) {
return suc + 1;
} else if ( val <= fail ) {
return suc - 1;
}
return suc;
}, 0 );
return new Result( data.toString(), Math.max( result, 0 ), rolls );
} | [
"function",
"rollWod",
"(",
"roll",
")",
"{",
"const",
"data",
"=",
"roll",
"instanceof",
"WodRoll",
"?",
"roll",
":",
"convertToWodRoll",
"(",
"roll",
")",
";",
"const",
"{",
"dice",
",",
"count",
",",
"again",
",",
"success",
",",
"fail",
"}",
"=",
"data",
";",
"const",
"rolls",
"=",
"[",
"]",
";",
"let",
"i",
"=",
"count",
";",
"while",
"(",
"i",
">",
"0",
")",
"{",
"const",
"value",
"=",
"randomRoll",
"(",
"dice",
")",
";",
"rolls",
".",
"push",
"(",
"value",
")",
";",
"// Check for \"10 Again\" flag",
"// `repeatLimit` will prevent infinite loop, for cases like `d1!>1`",
"const",
"repeatLimit",
"=",
"100",
";",
"if",
"(",
"value",
"!==",
"dice",
"||",
"!",
"again",
"||",
"rolls",
".",
"length",
">",
"repeatLimit",
")",
"{",
"i",
"-=",
"1",
";",
"}",
"}",
"const",
"result",
"=",
"rolls",
".",
"reduce",
"(",
"(",
"suc",
",",
"val",
")",
"=>",
"{",
"if",
"(",
"val",
">=",
"success",
")",
"{",
"return",
"suc",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"val",
"<=",
"fail",
")",
"{",
"return",
"suc",
"-",
"1",
";",
"}",
"return",
"suc",
";",
"}",
",",
"0",
")",
";",
"return",
"new",
"Result",
"(",
"data",
".",
"toString",
"(",
")",
",",
"Math",
".",
"max",
"(",
"result",
",",
"0",
")",
",",
"rolls",
")",
";",
"}"
]
| Rolls the dice from `WodRoll` object.
@func
@since v2.0.0
@param {WodRoll} roll - `WodRoll` object or similar
@return {Result}
@see roll
@see rollClassic
@example
rollWod(new WodRoll(10, 4, true, 8)); //=> { notation: '4d10!>8', value: 2, rolls: [3,10,7,9,5] }
rollWod({ dice: 8, count: 3 }); //=> { notation: '3d8>6', value: 2, rolls: [ 7, 3, 9 ] } | [
"Rolls",
"the",
"dice",
"from",
"WodRoll",
"object",
"."
]
| 38912b298edb0a4d67ba1c796d7ac159ebaf7901 | https://github.com/edloidas/roll-parser/blob/38912b298edb0a4d67ba1c796d7ac159ebaf7901/src/roller.js#L46-L74 |
47,334 | edloidas/roll-parser | src/roller.js | rollAny | function rollAny( roll ) {
if ( roll instanceof Roll ) {
return rollClassic( roll );
} else if ( roll instanceof WodRoll ) {
return rollWod( roll );
}
return isDefined( roll ) ? rollAny( convertToAnyRoll( roll )) : null;
} | javascript | function rollAny( roll ) {
if ( roll instanceof Roll ) {
return rollClassic( roll );
} else if ( roll instanceof WodRoll ) {
return rollWod( roll );
}
return isDefined( roll ) ? rollAny( convertToAnyRoll( roll )) : null;
} | [
"function",
"rollAny",
"(",
"roll",
")",
"{",
"if",
"(",
"roll",
"instanceof",
"Roll",
")",
"{",
"return",
"rollClassic",
"(",
"roll",
")",
";",
"}",
"else",
"if",
"(",
"roll",
"instanceof",
"WodRoll",
")",
"{",
"return",
"rollWod",
"(",
"roll",
")",
";",
"}",
"return",
"isDefined",
"(",
"roll",
")",
"?",
"rollAny",
"(",
"convertToAnyRoll",
"(",
"roll",
")",
")",
":",
"null",
";",
"}"
]
| Rolls the dice from `Roll` or `WodRoll` objects.
@func
@alias roll
@since v2.0.0
@param {Roll|WodRoll|Object} roll - `Roll`, `WodRoll` or similar object.
@return {Result} Returns `Result` for defined parameters, otherwise returns `null`.
@see rollClassic
@see rollWod
@example
roll(new Roll(10, 2, -1)); //=> { notation: '2d10-1', value: 14, rolls: [ 7, 8 ] }
roll({ dice: 6 }); //=> { notation: 'd6', value: 4, rolls: [ 4 ] }
roll(new WodRoll(10, 4, true, 8)); //=> { notation: '4d10!>8', value: 2, rolls: [3,10,7,9,5] }
roll({ dice: 8, count: 3, again: true }); //=> { notation: '3d8!>6', value: 2, rolls: [7,3,9 ] }
roll( null ); //=> null | [
"Rolls",
"the",
"dice",
"from",
"Roll",
"or",
"WodRoll",
"objects",
"."
]
| 38912b298edb0a4d67ba1c796d7ac159ebaf7901 | https://github.com/edloidas/roll-parser/blob/38912b298edb0a4d67ba1c796d7ac159ebaf7901/src/roller.js#L93-L100 |
47,335 | luoyjx/koa-rest-mongoose | lib/index.js | KoaRestMongoose | function KoaRestMongoose(options) {
if (!(this instanceof KoaRestMongoose)) {
return new KoaRestMongoose(options);
}
options = options || {};
debug('options: ', options);
// api url prefix
this.prefix = null;
if (options.prefix !== null && typeof options.prefix !== 'undefined') {
// add `/` if not exists
if (options.prefix.indexOf('/') === -1) {
this.prefix = '/';
}
this.prefix = (this.prefix || '') + options.prefix;
debug('prefix: ', this.prefix);
}
// get all mongoose models
this.models = mongoose.models;
const modelNames = Object.keys(this.models);
// generate controller by mongoose model
modelNames.map(modelName => {
const model = this.models[modelName];
debug('model: ', model);
const actions = generateActions(model);
// generate route and bind to router
generateRoutes(router, model.modelName, actions, this.prefix);
});
// router instance
this.router = router;
// get all routes
this.routes = () => {
return this.router.routes();
};
} | javascript | function KoaRestMongoose(options) {
if (!(this instanceof KoaRestMongoose)) {
return new KoaRestMongoose(options);
}
options = options || {};
debug('options: ', options);
// api url prefix
this.prefix = null;
if (options.prefix !== null && typeof options.prefix !== 'undefined') {
// add `/` if not exists
if (options.prefix.indexOf('/') === -1) {
this.prefix = '/';
}
this.prefix = (this.prefix || '') + options.prefix;
debug('prefix: ', this.prefix);
}
// get all mongoose models
this.models = mongoose.models;
const modelNames = Object.keys(this.models);
// generate controller by mongoose model
modelNames.map(modelName => {
const model = this.models[modelName];
debug('model: ', model);
const actions = generateActions(model);
// generate route and bind to router
generateRoutes(router, model.modelName, actions, this.prefix);
});
// router instance
this.router = router;
// get all routes
this.routes = () => {
return this.router.routes();
};
} | [
"function",
"KoaRestMongoose",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"KoaRestMongoose",
")",
")",
"{",
"return",
"new",
"KoaRestMongoose",
"(",
"options",
")",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"debug",
"(",
"'options: '",
",",
"options",
")",
";",
"// api url prefix",
"this",
".",
"prefix",
"=",
"null",
";",
"if",
"(",
"options",
".",
"prefix",
"!==",
"null",
"&&",
"typeof",
"options",
".",
"prefix",
"!==",
"'undefined'",
")",
"{",
"// add `/` if not exists",
"if",
"(",
"options",
".",
"prefix",
".",
"indexOf",
"(",
"'/'",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"prefix",
"=",
"'/'",
";",
"}",
"this",
".",
"prefix",
"=",
"(",
"this",
".",
"prefix",
"||",
"''",
")",
"+",
"options",
".",
"prefix",
";",
"debug",
"(",
"'prefix: '",
",",
"this",
".",
"prefix",
")",
";",
"}",
"// get all mongoose models",
"this",
".",
"models",
"=",
"mongoose",
".",
"models",
";",
"const",
"modelNames",
"=",
"Object",
".",
"keys",
"(",
"this",
".",
"models",
")",
";",
"// generate controller by mongoose model",
"modelNames",
".",
"map",
"(",
"modelName",
"=>",
"{",
"const",
"model",
"=",
"this",
".",
"models",
"[",
"modelName",
"]",
";",
"debug",
"(",
"'model: '",
",",
"model",
")",
";",
"const",
"actions",
"=",
"generateActions",
"(",
"model",
")",
";",
"// generate route and bind to router",
"generateRoutes",
"(",
"router",
",",
"model",
".",
"modelName",
",",
"actions",
",",
"this",
".",
"prefix",
")",
";",
"}",
")",
";",
"// router instance",
"this",
".",
"router",
"=",
"router",
";",
"// get all routes",
"this",
".",
"routes",
"=",
"(",
")",
"=>",
"{",
"return",
"this",
".",
"router",
".",
"routes",
"(",
")",
";",
"}",
";",
"}"
]
| Create a KoaRestMongoose instance.
@param {Object} options | [
"Create",
"a",
"KoaRestMongoose",
"instance",
"."
]
| 322e4b6623ff0f708df383c7dd76bee76e90be81 | https://github.com/luoyjx/koa-rest-mongoose/blob/322e4b6623ff0f708df383c7dd76bee76e90be81/lib/index.js#L21-L64 |
47,336 | fex-team/yog-bigpipe | scripts/bigpipe.js | function () {
var i, len;
// eval scripts.
if (data.scripts && data.scripts.length) {
for (i = 0, len = data.scripts.length; i < len; i++) {
Util.globalEval(data.scripts[i]);
}
}
callback && callback(data);
} | javascript | function () {
var i, len;
// eval scripts.
if (data.scripts && data.scripts.length) {
for (i = 0, len = data.scripts.length; i < len; i++) {
Util.globalEval(data.scripts[i]);
}
}
callback && callback(data);
} | [
"function",
"(",
")",
"{",
"var",
"i",
",",
"len",
";",
"// eval scripts.",
"if",
"(",
"data",
".",
"scripts",
"&&",
"data",
".",
"scripts",
".",
"length",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"len",
"=",
"data",
".",
"scripts",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"Util",
".",
"globalEval",
"(",
"data",
".",
"scripts",
"[",
"i",
"]",
")",
";",
"}",
"}",
"callback",
"&&",
"callback",
"(",
"data",
")",
";",
"}"
]
| exec data.scripts | [
"exec",
"data",
".",
"scripts"
]
| 5c9c761d1940f1ea5b4d46b9f1ed3da8a20db21d | https://github.com/fex-team/yog-bigpipe/blob/5c9c761d1940f1ea5b4d46b9f1ed3da8a20db21d/scripts/bigpipe.js#L419-L430 |
|
47,337 | fex-team/yog-bigpipe | scripts/bigpipe.js | function (obj) {
if (!resourceChecked) {
Util.saveLoadedRes();
resourceChecked = true;
}
currReqID = obj.reqID;
// console.log('arrive', obj.id);
this.trigger('pageletarrive', obj);
var pagelet = new PageLet(obj, function () {
// console.log('dom ready', obj.id);
var item;
count--;
// enforce js executed after dom inserted.
if (count === 0) {
while ((item = pagelets.shift())) {
BigPipe.trigger('pageletinsert', pagelet, item.pageletData);
// console.log('pagelet exec js', item.pageletData.id);
item.loadJs((function (item) {
// console.log('pagelet exec done', item.pageletData.id);
BigPipe.trigger('pageletdone', pagelet, item.pageletData);
})(item));
}
}
});
pagelet.pageletData = obj;
pagelets.push(pagelet);
count++;
pagelet.loadCss();
} | javascript | function (obj) {
if (!resourceChecked) {
Util.saveLoadedRes();
resourceChecked = true;
}
currReqID = obj.reqID;
// console.log('arrive', obj.id);
this.trigger('pageletarrive', obj);
var pagelet = new PageLet(obj, function () {
// console.log('dom ready', obj.id);
var item;
count--;
// enforce js executed after dom inserted.
if (count === 0) {
while ((item = pagelets.shift())) {
BigPipe.trigger('pageletinsert', pagelet, item.pageletData);
// console.log('pagelet exec js', item.pageletData.id);
item.loadJs((function (item) {
// console.log('pagelet exec done', item.pageletData.id);
BigPipe.trigger('pageletdone', pagelet, item.pageletData);
})(item));
}
}
});
pagelet.pageletData = obj;
pagelets.push(pagelet);
count++;
pagelet.loadCss();
} | [
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"resourceChecked",
")",
"{",
"Util",
".",
"saveLoadedRes",
"(",
")",
";",
"resourceChecked",
"=",
"true",
";",
"}",
"currReqID",
"=",
"obj",
".",
"reqID",
";",
"// console.log('arrive', obj.id);",
"this",
".",
"trigger",
"(",
"'pageletarrive'",
",",
"obj",
")",
";",
"var",
"pagelet",
"=",
"new",
"PageLet",
"(",
"obj",
",",
"function",
"(",
")",
"{",
"// console.log('dom ready', obj.id);",
"var",
"item",
";",
"count",
"--",
";",
"// enforce js executed after dom inserted.",
"if",
"(",
"count",
"===",
"0",
")",
"{",
"while",
"(",
"(",
"item",
"=",
"pagelets",
".",
"shift",
"(",
")",
")",
")",
"{",
"BigPipe",
".",
"trigger",
"(",
"'pageletinsert'",
",",
"pagelet",
",",
"item",
".",
"pageletData",
")",
";",
"// console.log('pagelet exec js', item.pageletData.id);",
"item",
".",
"loadJs",
"(",
"(",
"function",
"(",
"item",
")",
"{",
"// console.log('pagelet exec done', item.pageletData.id);",
"BigPipe",
".",
"trigger",
"(",
"'pageletdone'",
",",
"pagelet",
",",
"item",
".",
"pageletData",
")",
";",
"}",
")",
"(",
"item",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"pagelet",
".",
"pageletData",
"=",
"obj",
";",
"pagelets",
".",
"push",
"(",
"pagelet",
")",
";",
"count",
"++",
";",
"pagelet",
".",
"loadCss",
"(",
")",
";",
"}"
]
| This is method will be executed automaticlly. - after chunk output pagelet. - after async load quickling pagelet. | [
"This",
"is",
"method",
"will",
"be",
"executed",
"automaticlly",
".",
"-",
"after",
"chunk",
"output",
"pagelet",
".",
"-",
"after",
"async",
"load",
"quickling",
"pagelet",
"."
]
| 5c9c761d1940f1ea5b4d46b9f1ed3da8a20db21d | https://github.com/fex-team/yog-bigpipe/blob/5c9c761d1940f1ea5b4d46b9f1ed3da8a20db21d/scripts/bigpipe.js#L465-L493 |
|
47,338 | willmark/file-compare | index.js | checkCommonArgs | function checkCommonArgs(args) {
if (args.length < 2) throw new Error("File1, File2, and callback required");
if (typeof args.at(1) != "string") throw new Error("File2 required");
if (typeof args.at(0) != "string") throw new Error("File1 required");
if (!args.callbackGiven()) throw new Error("Callback required");
} | javascript | function checkCommonArgs(args) {
if (args.length < 2) throw new Error("File1, File2, and callback required");
if (typeof args.at(1) != "string") throw new Error("File2 required");
if (typeof args.at(0) != "string") throw new Error("File1 required");
if (!args.callbackGiven()) throw new Error("Callback required");
} | [
"function",
"checkCommonArgs",
"(",
"args",
")",
"{",
"if",
"(",
"args",
".",
"length",
"<",
"2",
")",
"throw",
"new",
"Error",
"(",
"\"File1, File2, and callback required\"",
")",
";",
"if",
"(",
"typeof",
"args",
".",
"at",
"(",
"1",
")",
"!=",
"\"string\"",
")",
"throw",
"new",
"Error",
"(",
"\"File2 required\"",
")",
";",
"if",
"(",
"typeof",
"args",
".",
"at",
"(",
"0",
")",
"!=",
"\"string\"",
")",
"throw",
"new",
"Error",
"(",
"\"File1 required\"",
")",
";",
"if",
"(",
"!",
"args",
".",
"callbackGiven",
"(",
")",
")",
"throw",
"new",
"Error",
"(",
"\"Callback required\"",
")",
";",
"}"
]
| Common argument checking for crop and resize | [
"Common",
"argument",
"checking",
"for",
"crop",
"and",
"resize"
]
| 1878fef8d54c527a5106e1995c4557251d9bd550 | https://github.com/willmark/file-compare/blob/1878fef8d54c527a5106e1995c4557251d9bd550/index.js#L19-L24 |
47,339 | willmark/file-compare | index.js | computeHash | function computeHash(filename, algo, callback) {
var crypto = require('crypto');
var fs = require('fs');
var chksum = crypto.createHash(algo);
var s = fs.ReadStream(filename);
s.on('error', function (err) {
//no file, hash will be zero
callback(0, err);
});
s.on('data', function (d) {
chksum.update(d);
});
s.on('end', function () {
var d = chksum.digest('hex');
//util.debug(d + ' ' + filename);
callback(d);
});
} | javascript | function computeHash(filename, algo, callback) {
var crypto = require('crypto');
var fs = require('fs');
var chksum = crypto.createHash(algo);
var s = fs.ReadStream(filename);
s.on('error', function (err) {
//no file, hash will be zero
callback(0, err);
});
s.on('data', function (d) {
chksum.update(d);
});
s.on('end', function () {
var d = chksum.digest('hex');
//util.debug(d + ' ' + filename);
callback(d);
});
} | [
"function",
"computeHash",
"(",
"filename",
",",
"algo",
",",
"callback",
")",
"{",
"var",
"crypto",
"=",
"require",
"(",
"'crypto'",
")",
";",
"var",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"var",
"chksum",
"=",
"crypto",
".",
"createHash",
"(",
"algo",
")",
";",
"var",
"s",
"=",
"fs",
".",
"ReadStream",
"(",
"filename",
")",
";",
"s",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"//no file, hash will be zero",
"callback",
"(",
"0",
",",
"err",
")",
";",
"}",
")",
";",
"s",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"d",
")",
"{",
"chksum",
".",
"update",
"(",
"d",
")",
";",
"}",
")",
";",
"s",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"var",
"d",
"=",
"chksum",
".",
"digest",
"(",
"'hex'",
")",
";",
"//util.debug(d + ' ' + filename);",
"callback",
"(",
"d",
")",
";",
"}",
")",
";",
"}"
]
| Create a new hash of given file name | [
"Create",
"a",
"new",
"hash",
"of",
"given",
"file",
"name"
]
| 1878fef8d54c527a5106e1995c4557251d9bd550 | https://github.com/willmark/file-compare/blob/1878fef8d54c527a5106e1995c4557251d9bd550/index.js#L54-L74 |
47,340 | edloidas/roll-parser | src/object/WodRoll.js | WodRoll | function WodRoll( dice = 10, count = 1, again = false, success = 6, fail ) {
this.dice = positiveInteger( dice );
this.count = positiveInteger( count );
this.again = !!again;
[ this.fail, this.success ] = normalizeWodBorders( fail, success, this.dice );
} | javascript | function WodRoll( dice = 10, count = 1, again = false, success = 6, fail ) {
this.dice = positiveInteger( dice );
this.count = positiveInteger( count );
this.again = !!again;
[ this.fail, this.success ] = normalizeWodBorders( fail, success, this.dice );
} | [
"function",
"WodRoll",
"(",
"dice",
"=",
"10",
",",
"count",
"=",
"1",
",",
"again",
"=",
"false",
",",
"success",
"=",
"6",
",",
"fail",
")",
"{",
"this",
".",
"dice",
"=",
"positiveInteger",
"(",
"dice",
")",
";",
"this",
".",
"count",
"=",
"positiveInteger",
"(",
"count",
")",
";",
"this",
".",
"again",
"=",
"!",
"!",
"again",
";",
"[",
"this",
".",
"fail",
",",
"this",
".",
"success",
"]",
"=",
"normalizeWodBorders",
"(",
"fail",
",",
"success",
",",
"this",
".",
"dice",
")",
";",
"}"
]
| A class that represents a dice roll from World of Darkness setting
@class
@classdesc A class that represents a dice roll from World of Darkness setting
@since v2.0.0
@param {Number} dice - A number of dice faces
@param {Number} count - A number of dices
@param {Boolean} again - A flag for "10 Again" rolls policy
@param {Number} success - A minimum value, that counts as success
@param {Number} fail - A maximum value, that counts as failure
@see Roll | [
"A",
"class",
"that",
"represents",
"a",
"dice",
"roll",
"from",
"World",
"of",
"Darkness",
"setting"
]
| 38912b298edb0a4d67ba1c796d7ac159ebaf7901 | https://github.com/edloidas/roll-parser/blob/38912b298edb0a4d67ba1c796d7ac159ebaf7901/src/object/WodRoll.js#L18-L23 |
47,341 | bestander/pong-box2d | physics/box2dPhysics.js | Physics | function Physics(width, height, ballRadius) {
this._height = height;
this._width = width;
this._ballRadius = ballRadius || 0.2;
this._world = null;
this._ballScored = function () {
};
this._paddleFixtures = {};
this._init();
} | javascript | function Physics(width, height, ballRadius) {
this._height = height;
this._width = width;
this._ballRadius = ballRadius || 0.2;
this._world = null;
this._ballScored = function () {
};
this._paddleFixtures = {};
this._init();
} | [
"function",
"Physics",
"(",
"width",
",",
"height",
",",
"ballRadius",
")",
"{",
"this",
".",
"_height",
"=",
"height",
";",
"this",
".",
"_width",
"=",
"width",
";",
"this",
".",
"_ballRadius",
"=",
"ballRadius",
"||",
"0.2",
";",
"this",
".",
"_world",
"=",
"null",
";",
"this",
".",
"_ballScored",
"=",
"function",
"(",
")",
"{",
"}",
";",
"this",
".",
"_paddleFixtures",
"=",
"{",
"}",
";",
"this",
".",
"_init",
"(",
")",
";",
"}"
]
| Initialize physics environment
@param width field width
@param height field height
@param ballRadius ball game radius
@constructor | [
"Initialize",
"physics",
"environment"
]
| 18e6d14a38d4bb552a22a19b0c00b05e02d2cc5b | https://github.com/bestander/pong-box2d/blob/18e6d14a38d4bb552a22a19b0c00b05e02d2cc5b/physics/box2dPhysics.js#L37-L46 |
47,342 | amobiz/json-normalizer | lib/deref.js | deref | function deref(theSchema, optionalOptions, callbackFn) {
var root, loaders, error, options, callback;
options = optionalOptions || {};
if (typeof options === 'function') {
callback = options;
} else {
callback = callbackFn;
}
root = _.cloneDeep(theSchema);
loaders = _loaders(require('./loader/local'), options);
process.nextTick(function () {
traverse(root, _visit, _done);
});
function _visit(node, key, owner, next) {
if (node === root) {
next();
}
if (typeof node.$ref === 'string') {
_load(node.$ref, function (err, schema) {
if (err) {
error = err;
return false;
}
owner[key] = schema;
next();
});
} else {
next();
}
function _load($ref, resolve) {
if (!_evaluate(loaders, _try)) {
resolve({
message: 'no appropriate loader',
$ref: $ref
});
}
function _try(loader) {
return loader(root, $ref, resolve);
}
}
}
function _done() {
process.nextTick(function () {
if (error) {
callback(error);
} else {
callback(null, root);
}
});
}
} | javascript | function deref(theSchema, optionalOptions, callbackFn) {
var root, loaders, error, options, callback;
options = optionalOptions || {};
if (typeof options === 'function') {
callback = options;
} else {
callback = callbackFn;
}
root = _.cloneDeep(theSchema);
loaders = _loaders(require('./loader/local'), options);
process.nextTick(function () {
traverse(root, _visit, _done);
});
function _visit(node, key, owner, next) {
if (node === root) {
next();
}
if (typeof node.$ref === 'string') {
_load(node.$ref, function (err, schema) {
if (err) {
error = err;
return false;
}
owner[key] = schema;
next();
});
} else {
next();
}
function _load($ref, resolve) {
if (!_evaluate(loaders, _try)) {
resolve({
message: 'no appropriate loader',
$ref: $ref
});
}
function _try(loader) {
return loader(root, $ref, resolve);
}
}
}
function _done() {
process.nextTick(function () {
if (error) {
callback(error);
} else {
callback(null, root);
}
});
}
} | [
"function",
"deref",
"(",
"theSchema",
",",
"optionalOptions",
",",
"callbackFn",
")",
"{",
"var",
"root",
",",
"loaders",
",",
"error",
",",
"options",
",",
"callback",
";",
"options",
"=",
"optionalOptions",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
";",
"}",
"else",
"{",
"callback",
"=",
"callbackFn",
";",
"}",
"root",
"=",
"_",
".",
"cloneDeep",
"(",
"theSchema",
")",
";",
"loaders",
"=",
"_loaders",
"(",
"require",
"(",
"'./loader/local'",
")",
",",
"options",
")",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"traverse",
"(",
"root",
",",
"_visit",
",",
"_done",
")",
";",
"}",
")",
";",
"function",
"_visit",
"(",
"node",
",",
"key",
",",
"owner",
",",
"next",
")",
"{",
"if",
"(",
"node",
"===",
"root",
")",
"{",
"next",
"(",
")",
";",
"}",
"if",
"(",
"typeof",
"node",
".",
"$ref",
"===",
"'string'",
")",
"{",
"_load",
"(",
"node",
".",
"$ref",
",",
"function",
"(",
"err",
",",
"schema",
")",
"{",
"if",
"(",
"err",
")",
"{",
"error",
"=",
"err",
";",
"return",
"false",
";",
"}",
"owner",
"[",
"key",
"]",
"=",
"schema",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"function",
"_load",
"(",
"$ref",
",",
"resolve",
")",
"{",
"if",
"(",
"!",
"_evaluate",
"(",
"loaders",
",",
"_try",
")",
")",
"{",
"resolve",
"(",
"{",
"message",
":",
"'no appropriate loader'",
",",
"$ref",
":",
"$ref",
"}",
")",
";",
"}",
"function",
"_try",
"(",
"loader",
")",
"{",
"return",
"loader",
"(",
"root",
",",
"$ref",
",",
"resolve",
")",
";",
"}",
"}",
"}",
"function",
"_done",
"(",
")",
"{",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"error",
")",
"{",
"callback",
"(",
"error",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"root",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
]
| Dereference a schema that using JSON references.
Default implementation supports only local references,
i.e. references that starts with “#“.
Custom loaders can be provided via the options object.
@context don't care.
@param theSchema: string
@param optionalOptions.loader | optionalOptions.loaders: function | [function]
A loader function or an array of loader functions.
Loader must be a function that returns truthy if it can handle the given reference, falsy otherwise.
Loader takes root schema, $ref and callback(err, schema) as parameters in that order.
A local loader that is always tested first, and other loaders provided in options are then tested by the order they being listed.
@param callbackFn: function
@return no return value. | [
"Dereference",
"a",
"schema",
"that",
"using",
"JSON",
"references",
"."
]
| 76a8ab1db2da4600dbd28c5c6c7fd11e43c0dd55 | https://github.com/amobiz/json-normalizer/blob/76a8ab1db2da4600dbd28c5c6c7fd11e43c0dd55/lib/deref.js#L26-L83 |
47,343 | mrfishie/detect-log | index.js | logAll | function logAll(files, cb) {
_walkAll(files, function(err, node) {
if (err) {
exports.log(err.name + ': ' + err.message + ' in ' + err.file + ':' + err.line + ':' + err.column);
if (cb) cb(err);
}
exports.log('Found console.' + node.type + ' at ' + node.file + ':' + node.line + ':' + node.column + ' with '
+ node.arguments.length + ' arg(s)');
}).then(function(allNodes) {
if (cb) cb(null, allNodes);
});
} | javascript | function logAll(files, cb) {
_walkAll(files, function(err, node) {
if (err) {
exports.log(err.name + ': ' + err.message + ' in ' + err.file + ':' + err.line + ':' + err.column);
if (cb) cb(err);
}
exports.log('Found console.' + node.type + ' at ' + node.file + ':' + node.line + ':' + node.column + ' with '
+ node.arguments.length + ' arg(s)');
}).then(function(allNodes) {
if (cb) cb(null, allNodes);
});
} | [
"function",
"logAll",
"(",
"files",
",",
"cb",
")",
"{",
"_walkAll",
"(",
"files",
",",
"function",
"(",
"err",
",",
"node",
")",
"{",
"if",
"(",
"err",
")",
"{",
"exports",
".",
"log",
"(",
"err",
".",
"name",
"+",
"': '",
"+",
"err",
".",
"message",
"+",
"' in '",
"+",
"err",
".",
"file",
"+",
"':'",
"+",
"err",
".",
"line",
"+",
"':'",
"+",
"err",
".",
"column",
")",
";",
"if",
"(",
"cb",
")",
"cb",
"(",
"err",
")",
";",
"}",
"exports",
".",
"log",
"(",
"'Found console.'",
"+",
"node",
".",
"type",
"+",
"' at '",
"+",
"node",
".",
"file",
"+",
"':'",
"+",
"node",
".",
"line",
"+",
"':'",
"+",
"node",
".",
"column",
"+",
"' with '",
"+",
"node",
".",
"arguments",
".",
"length",
"+",
"' arg(s)'",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"allNodes",
")",
"{",
"if",
"(",
"cb",
")",
"cb",
"(",
"null",
",",
"allNodes",
")",
";",
"}",
")",
";",
"}"
]
| Logs all found instances of console.log and calls the callback specifying if there were any instances, or an error
if one occurred
@param {String} files A file glob
@param {Function?} cb Called with arguments <Error, Array>. If there was an error it will not be called again,
otherwise it will be called at the end with null as the error value and the array of nodes
found. | [
"Logs",
"all",
"found",
"instances",
"of",
"console",
".",
"log",
"and",
"calls",
"the",
"callback",
"specifying",
"if",
"there",
"were",
"any",
"instances",
"or",
"an",
"error",
"if",
"one",
"occurred"
]
| 7a42e0a727fd57edf908423bf17e74c639788b9d | https://github.com/mrfishie/detect-log/blob/7a42e0a727fd57edf908423bf17e74c639788b9d/index.js#L38-L50 |
47,344 | mrfishie/detect-log | index.js | getAll | function getAll(files, cb) {
walkAll(files)
.then(function(allNodes) {
if (cb) cb(null, allNodes);
})
.catch(function(err) {
if (cb) cb(err, []);
});
} | javascript | function getAll(files, cb) {
walkAll(files)
.then(function(allNodes) {
if (cb) cb(null, allNodes);
})
.catch(function(err) {
if (cb) cb(err, []);
});
} | [
"function",
"getAll",
"(",
"files",
",",
"cb",
")",
"{",
"walkAll",
"(",
"files",
")",
".",
"then",
"(",
"function",
"(",
"allNodes",
")",
"{",
"if",
"(",
"cb",
")",
"cb",
"(",
"null",
",",
"allNodes",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"cb",
")",
"cb",
"(",
"err",
",",
"[",
"]",
")",
";",
"}",
")",
";",
"}"
]
| Gets a list of all found console.logs
@param {String} files A file glob
@param {Function?} cb Called with arguments <Error, Array>. If an error occurred the error will be passed with an
empty array, otherwise error will be null and an array will be passed. | [
"Gets",
"a",
"list",
"of",
"all",
"found",
"console",
".",
"logs"
]
| 7a42e0a727fd57edf908423bf17e74c639788b9d | https://github.com/mrfishie/detect-log/blob/7a42e0a727fd57edf908423bf17e74c639788b9d/index.js#L61-L69 |
47,345 | quorrajs/Positron | lib/foundation/Application.js | App | function App() {
require('colors');
/**
* All of the developer defined middlewares.
*
* @var {Array}
* @protected
*/
this.__middlewares = [];
/**
* The filter instance
* @var {Object}
*/
this.filter;
/**
* The list of loaded service providers.
*
* @var {Object}
* @protected
*/
this.__loadedProviders = {};
/**
* Indicates if the application has "booted".
*
* @var {Boolean}
* @protected
*/
this.__booted = false;
/**
* The array of booting callbacks.
*
* @var {Array}
* @protected
*/
this.__bootingCallbacks = [];
/**
* The array of booted callbacks.
*
* @var {Array}
* @protected
*/
this.__bootedCallbacks = [];
/**
* Node HTTP server reference.
*
* @var {Object}
* @protected
*/
this.__server;
/**
* The application locals object.
*
* @var {Object}
*/
this.locals = {};
/**
* Aliases for internal Positron module
*
* @type {Object}
* @protected
*/
this.__aliases = {};
var self = this;
/**
* Run the application and send the response.
*
* @param request
* @param response
* @return {void}
*/
this.run = function (request, response) {
var reqDomain = domain.create();
reqDomain
.on('error', self.handleError.bind(self, request, response))
.run(function () {
self.__getStackedClient().handle(request, response);
});
};
} | javascript | function App() {
require('colors');
/**
* All of the developer defined middlewares.
*
* @var {Array}
* @protected
*/
this.__middlewares = [];
/**
* The filter instance
* @var {Object}
*/
this.filter;
/**
* The list of loaded service providers.
*
* @var {Object}
* @protected
*/
this.__loadedProviders = {};
/**
* Indicates if the application has "booted".
*
* @var {Boolean}
* @protected
*/
this.__booted = false;
/**
* The array of booting callbacks.
*
* @var {Array}
* @protected
*/
this.__bootingCallbacks = [];
/**
* The array of booted callbacks.
*
* @var {Array}
* @protected
*/
this.__bootedCallbacks = [];
/**
* Node HTTP server reference.
*
* @var {Object}
* @protected
*/
this.__server;
/**
* The application locals object.
*
* @var {Object}
*/
this.locals = {};
/**
* Aliases for internal Positron module
*
* @type {Object}
* @protected
*/
this.__aliases = {};
var self = this;
/**
* Run the application and send the response.
*
* @param request
* @param response
* @return {void}
*/
this.run = function (request, response) {
var reqDomain = domain.create();
reqDomain
.on('error', self.handleError.bind(self, request, response))
.run(function () {
self.__getStackedClient().handle(request, response);
});
};
} | [
"function",
"App",
"(",
")",
"{",
"require",
"(",
"'colors'",
")",
";",
"/**\n * All of the developer defined middlewares.\n *\n * @var {Array}\n * @protected\n */",
"this",
".",
"__middlewares",
"=",
"[",
"]",
";",
"/**\n * The filter instance\n * @var {Object}\n */",
"this",
".",
"filter",
";",
"/**\n * The list of loaded service providers.\n *\n * @var {Object}\n * @protected\n */",
"this",
".",
"__loadedProviders",
"=",
"{",
"}",
";",
"/**\n * Indicates if the application has \"booted\".\n *\n * @var {Boolean}\n * @protected\n */",
"this",
".",
"__booted",
"=",
"false",
";",
"/**\n * The array of booting callbacks.\n *\n * @var {Array}\n * @protected\n */",
"this",
".",
"__bootingCallbacks",
"=",
"[",
"]",
";",
"/**\n * The array of booted callbacks.\n *\n * @var {Array}\n * @protected\n */",
"this",
".",
"__bootedCallbacks",
"=",
"[",
"]",
";",
"/**\n * Node HTTP server reference.\n *\n * @var {Object}\n * @protected\n */",
"this",
".",
"__server",
";",
"/**\n * The application locals object.\n *\n * @var {Object}\n */",
"this",
".",
"locals",
"=",
"{",
"}",
";",
"/**\n * Aliases for internal Positron module\n *\n * @type {Object}\n * @protected\n */",
"this",
".",
"__aliases",
"=",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"/**\n * Run the application and send the response.\n *\n * @param request\n * @param response\n * @return {void}\n */",
"this",
".",
"run",
"=",
"function",
"(",
"request",
",",
"response",
")",
"{",
"var",
"reqDomain",
"=",
"domain",
".",
"create",
"(",
")",
";",
"reqDomain",
".",
"on",
"(",
"'error'",
",",
"self",
".",
"handleError",
".",
"bind",
"(",
"self",
",",
"request",
",",
"response",
")",
")",
".",
"run",
"(",
"function",
"(",
")",
"{",
"self",
".",
"__getStackedClient",
"(",
")",
".",
"handle",
"(",
"request",
",",
"response",
")",
";",
"}",
")",
";",
"}",
";",
"}"
]
| Create a Quorra application.
@extend Container
@return {Function}
@api public | [
"Create",
"a",
"Quorra",
"application",
"."
]
| a4bad5a5f581743d1885405c11ae26600fb957af | https://github.com/quorrajs/Positron/blob/a4bad5a5f581743d1885405c11ae26600fb957af/lib/foundation/Application.js#L47-L138 |
47,346 | gribnoysup/nfield-api | api.js | checkRequiredParameter | function checkRequiredParameter (param) {
return (
typeof param === 'function' || typeof param === 'undefined' || param === '' || param === null || (typeof param === 'number' && isNaN(param))
);
} | javascript | function checkRequiredParameter (param) {
return (
typeof param === 'function' || typeof param === 'undefined' || param === '' || param === null || (typeof param === 'number' && isNaN(param))
);
} | [
"function",
"checkRequiredParameter",
"(",
"param",
")",
"{",
"return",
"(",
"typeof",
"param",
"===",
"'function'",
"||",
"typeof",
"param",
"===",
"'undefined'",
"||",
"param",
"===",
"''",
"||",
"param",
"===",
"null",
"||",
"(",
"typeof",
"param",
"===",
"'number'",
"&&",
"isNaN",
"(",
"param",
")",
")",
")",
";",
"}"
]
| Check if specific required request parameter is valid | [
"Check",
"if",
"specific",
"required",
"request",
"parameter",
"is",
"valid"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L26-L30 |
47,347 | gribnoysup/nfield-api | api.js | checkIfOnlyOneRequired | function checkIfOnlyOneRequired (defaultParams) {
var keys = Object.keys(defaultParams);
var i, key;
var onlyOne = '';
for (i = 0; i < keys.length; i++){
key = keys[i];
if (defaultParams[key] === '') {
if (onlyOne !== '') return false;
onlyOne = key;
}
}
return onlyOne;
} | javascript | function checkIfOnlyOneRequired (defaultParams) {
var keys = Object.keys(defaultParams);
var i, key;
var onlyOne = '';
for (i = 0; i < keys.length; i++){
key = keys[i];
if (defaultParams[key] === '') {
if (onlyOne !== '') return false;
onlyOne = key;
}
}
return onlyOne;
} | [
"function",
"checkIfOnlyOneRequired",
"(",
"defaultParams",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"defaultParams",
")",
";",
"var",
"i",
",",
"key",
";",
"var",
"onlyOne",
"=",
"''",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"defaultParams",
"[",
"key",
"]",
"===",
"''",
")",
"{",
"if",
"(",
"onlyOne",
"!==",
"''",
")",
"return",
"false",
";",
"onlyOne",
"=",
"key",
";",
"}",
"}",
"return",
"onlyOne",
";",
"}"
]
| Check if default parameters has only one required param
Returns false if there are more than one, or a param name if there is only one | [
"Check",
"if",
"default",
"parameters",
"has",
"only",
"one",
"required",
"param"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L37-L51 |
47,348 | gribnoysup/nfield-api | api.js | normalizeRequestParameters | function normalizeRequestParameters (defaultsObject, paramsName, requestParams) {
var promise = new Promise(function (resolve, reject) {
var defaultParams;
var onlyOne;
// First check if we have a default parameters object with this name
if (typeof defaultsObject[paramsName] !== 'object') reject(new RequiredError(`No default parameters for '${paramsName}'`, paramsName, defaultsObject[paramsName]));
// Create an empty object with default parameters
defaultParams = extend(Object.create(null), defaultsObject[paramsName]);
// Check if there is only one required parameter in defaults
onlyOne = checkIfOnlyOneRequired(defaultParams);
// If checked parameters are not an object
if (typeof requestParams !== 'object') {
// If they are a string or a valid number and there is only one required parameter in default parameters
if ((typeof requestParams === 'string' || (typeof requestParams === 'number' && isNaN(requestParams))) && onlyOne !== false) {
// Provide this value as a value in the default params
defaultParams[onlyOne] = requestParams;
} else {
// Reject with error in other case
reject(new RequiredError('No request parameters provided', 'requestParams', requestParams));
}
}
for (var key in defaultParams) {
if (checkRequiredParameter(requestParams[key]) && defaultParams[key] === '') {
reject(new RequiredError(`Missing required parameter '${key}'`, key, requestParams[key]));
} else if (!checkRequiredParameter(requestParams[key])) {
defaultParams[key] = requestParams[key];
}
if (defaultParams[key] === '__optional') defaultParams[key] = '';
}
resolve(defaultParams);
});
return promise;
} | javascript | function normalizeRequestParameters (defaultsObject, paramsName, requestParams) {
var promise = new Promise(function (resolve, reject) {
var defaultParams;
var onlyOne;
// First check if we have a default parameters object with this name
if (typeof defaultsObject[paramsName] !== 'object') reject(new RequiredError(`No default parameters for '${paramsName}'`, paramsName, defaultsObject[paramsName]));
// Create an empty object with default parameters
defaultParams = extend(Object.create(null), defaultsObject[paramsName]);
// Check if there is only one required parameter in defaults
onlyOne = checkIfOnlyOneRequired(defaultParams);
// If checked parameters are not an object
if (typeof requestParams !== 'object') {
// If they are a string or a valid number and there is only one required parameter in default parameters
if ((typeof requestParams === 'string' || (typeof requestParams === 'number' && isNaN(requestParams))) && onlyOne !== false) {
// Provide this value as a value in the default params
defaultParams[onlyOne] = requestParams;
} else {
// Reject with error in other case
reject(new RequiredError('No request parameters provided', 'requestParams', requestParams));
}
}
for (var key in defaultParams) {
if (checkRequiredParameter(requestParams[key]) && defaultParams[key] === '') {
reject(new RequiredError(`Missing required parameter '${key}'`, key, requestParams[key]));
} else if (!checkRequiredParameter(requestParams[key])) {
defaultParams[key] = requestParams[key];
}
if (defaultParams[key] === '__optional') defaultParams[key] = '';
}
resolve(defaultParams);
});
return promise;
} | [
"function",
"normalizeRequestParameters",
"(",
"defaultsObject",
",",
"paramsName",
",",
"requestParams",
")",
"{",
"var",
"promise",
"=",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"defaultParams",
";",
"var",
"onlyOne",
";",
"// First check if we have a default parameters object with this name",
"if",
"(",
"typeof",
"defaultsObject",
"[",
"paramsName",
"]",
"!==",
"'object'",
")",
"reject",
"(",
"new",
"RequiredError",
"(",
"`",
"${",
"paramsName",
"}",
"`",
",",
"paramsName",
",",
"defaultsObject",
"[",
"paramsName",
"]",
")",
")",
";",
"// Create an empty object with default parameters",
"defaultParams",
"=",
"extend",
"(",
"Object",
".",
"create",
"(",
"null",
")",
",",
"defaultsObject",
"[",
"paramsName",
"]",
")",
";",
"// Check if there is only one required parameter in defaults",
"onlyOne",
"=",
"checkIfOnlyOneRequired",
"(",
"defaultParams",
")",
";",
"// If checked parameters are not an object",
"if",
"(",
"typeof",
"requestParams",
"!==",
"'object'",
")",
"{",
"// If they are a string or a valid number and there is only one required parameter in default parameters",
"if",
"(",
"(",
"typeof",
"requestParams",
"===",
"'string'",
"||",
"(",
"typeof",
"requestParams",
"===",
"'number'",
"&&",
"isNaN",
"(",
"requestParams",
")",
")",
")",
"&&",
"onlyOne",
"!==",
"false",
")",
"{",
"// Provide this value as a value in the default params",
"defaultParams",
"[",
"onlyOne",
"]",
"=",
"requestParams",
";",
"}",
"else",
"{",
"// Reject with error in other case",
"reject",
"(",
"new",
"RequiredError",
"(",
"'No request parameters provided'",
",",
"'requestParams'",
",",
"requestParams",
")",
")",
";",
"}",
"}",
"for",
"(",
"var",
"key",
"in",
"defaultParams",
")",
"{",
"if",
"(",
"checkRequiredParameter",
"(",
"requestParams",
"[",
"key",
"]",
")",
"&&",
"defaultParams",
"[",
"key",
"]",
"===",
"''",
")",
"{",
"reject",
"(",
"new",
"RequiredError",
"(",
"`",
"${",
"key",
"}",
"`",
",",
"key",
",",
"requestParams",
"[",
"key",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"checkRequiredParameter",
"(",
"requestParams",
"[",
"key",
"]",
")",
")",
"{",
"defaultParams",
"[",
"key",
"]",
"=",
"requestParams",
"[",
"key",
"]",
";",
"}",
"if",
"(",
"defaultParams",
"[",
"key",
"]",
"===",
"'__optional'",
")",
"defaultParams",
"[",
"key",
"]",
"=",
"''",
";",
"}",
"resolve",
"(",
"defaultParams",
")",
";",
"}",
")",
";",
"return",
"promise",
";",
"}"
]
| Return a promise with normalized request parameters or an error | [
"Return",
"a",
"promise",
"with",
"normalized",
"request",
"parameters",
"or",
"an",
"error"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L56-L96 |
47,349 | gribnoysup/nfield-api | api.js | signIn | function signIn (defOptions, credentials, callback) {
var promise = normalizeRequestParameters(defaults, 'SignIn', credentials).then(function (credentials) {
var options = {
method : 'POST',
uri : 'v1/SignIn',
json : credentials
};
extend(true, options, defOptions);
return options;
}).then(request).nodeify(callback);
return promise;
} | javascript | function signIn (defOptions, credentials, callback) {
var promise = normalizeRequestParameters(defaults, 'SignIn', credentials).then(function (credentials) {
var options = {
method : 'POST',
uri : 'v1/SignIn',
json : credentials
};
extend(true, options, defOptions);
return options;
}).then(request).nodeify(callback);
return promise;
} | [
"function",
"signIn",
"(",
"defOptions",
",",
"credentials",
",",
"callback",
")",
"{",
"var",
"promise",
"=",
"normalizeRequestParameters",
"(",
"defaults",
",",
"'SignIn'",
",",
"credentials",
")",
".",
"then",
"(",
"function",
"(",
"credentials",
")",
"{",
"var",
"options",
"=",
"{",
"method",
":",
"'POST'",
",",
"uri",
":",
"'v1/SignIn'",
",",
"json",
":",
"credentials",
"}",
";",
"extend",
"(",
"true",
",",
"options",
",",
"defOptions",
")",
";",
"return",
"options",
";",
"}",
")",
".",
"then",
"(",
"request",
")",
".",
"nodeify",
"(",
"callback",
")",
";",
"return",
"promise",
";",
"}"
]
| Sign in to Nfield API
{@link https://api.nfieldmr.com/help/api/post-v1-signin} | [
"Sign",
"in",
"to",
"Nfield",
"API"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L103-L119 |
47,350 | gribnoysup/nfield-api | api.js | requestWithTokenCheck | function requestWithTokenCheck (defOptions, credentials, token, options, callback) {
var returnedPromise;
options.headers = options.headers || {};
extend(true, options, defOptions);
if (Date.now() - token.Timestamp > tokenUpdateTime) {
returnedPromise = signIn(defOptions, credentials).then(function (data) {
if (data[0].statusCode !== 200) {
throw new Error(`${data[0].statusCode}: ${data[0].body.Message}`);
} else {
token.AuthenticationToken = data[0].body.AuthenticationToken;
token.Timestamp = Date.now();
options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
return request(options);
}
});
} else {
options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
returnedPromise = request(options);
}
returnedPromise.nodeify(callback);
return returnedPromise;
} | javascript | function requestWithTokenCheck (defOptions, credentials, token, options, callback) {
var returnedPromise;
options.headers = options.headers || {};
extend(true, options, defOptions);
if (Date.now() - token.Timestamp > tokenUpdateTime) {
returnedPromise = signIn(defOptions, credentials).then(function (data) {
if (data[0].statusCode !== 200) {
throw new Error(`${data[0].statusCode}: ${data[0].body.Message}`);
} else {
token.AuthenticationToken = data[0].body.AuthenticationToken;
token.Timestamp = Date.now();
options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
return request(options);
}
});
} else {
options.headers.Authorization = `Basic ${token.AuthenticationToken}`;
returnedPromise = request(options);
}
returnedPromise.nodeify(callback);
return returnedPromise;
} | [
"function",
"requestWithTokenCheck",
"(",
"defOptions",
",",
"credentials",
",",
"token",
",",
"options",
",",
"callback",
")",
"{",
"var",
"returnedPromise",
";",
"options",
".",
"headers",
"=",
"options",
".",
"headers",
"||",
"{",
"}",
";",
"extend",
"(",
"true",
",",
"options",
",",
"defOptions",
")",
";",
"if",
"(",
"Date",
".",
"now",
"(",
")",
"-",
"token",
".",
"Timestamp",
">",
"tokenUpdateTime",
")",
"{",
"returnedPromise",
"=",
"signIn",
"(",
"defOptions",
",",
"credentials",
")",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"if",
"(",
"data",
"[",
"0",
"]",
".",
"statusCode",
"!==",
"200",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"data",
"[",
"0",
"]",
".",
"statusCode",
"}",
"${",
"data",
"[",
"0",
"]",
".",
"body",
".",
"Message",
"}",
"`",
")",
";",
"}",
"else",
"{",
"token",
".",
"AuthenticationToken",
"=",
"data",
"[",
"0",
"]",
".",
"body",
".",
"AuthenticationToken",
";",
"token",
".",
"Timestamp",
"=",
"Date",
".",
"now",
"(",
")",
";",
"options",
".",
"headers",
".",
"Authorization",
"=",
"`",
"${",
"token",
".",
"AuthenticationToken",
"}",
"`",
";",
"return",
"request",
"(",
"options",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"options",
".",
"headers",
".",
"Authorization",
"=",
"`",
"${",
"token",
".",
"AuthenticationToken",
"}",
"`",
";",
"returnedPromise",
"=",
"request",
"(",
"options",
")",
";",
"}",
"returnedPromise",
".",
"nodeify",
"(",
"callback",
")",
";",
"return",
"returnedPromise",
";",
"}"
]
| Wrapper function for all Nfield API requests that checks if API token is not outdated, and refreshes it otherwise | [
"Wrapper",
"function",
"for",
"all",
"Nfield",
"API",
"requests",
"that",
"checks",
"if",
"API",
"token",
"is",
"not",
"outdated",
"and",
"refreshes",
"it",
"otherwise"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L124-L148 |
47,351 | gribnoysup/nfield-api | api.js | removeSurveyLanguages | function removeSurveyLanguages (defOptions, credentials, token, requestParams, callback) {
var promise = normalizeRequestParameters(defaults, 'RemoveSurveyLanguages', requestParams).then(function (params) {
var options = {
method : 'DELETE',
uri : `v1/Surveys/${params.SurveyId}/Languages/${params.LanguageId}`,
};
return options;
}).then(options => requestWithTokenCheck(defOptions, credentials, token, options)).nodeify(callback);
return promise;
} | javascript | function removeSurveyLanguages (defOptions, credentials, token, requestParams, callback) {
var promise = normalizeRequestParameters(defaults, 'RemoveSurveyLanguages', requestParams).then(function (params) {
var options = {
method : 'DELETE',
uri : `v1/Surveys/${params.SurveyId}/Languages/${params.LanguageId}`,
};
return options;
}).then(options => requestWithTokenCheck(defOptions, credentials, token, options)).nodeify(callback);
return promise;
} | [
"function",
"removeSurveyLanguages",
"(",
"defOptions",
",",
"credentials",
",",
"token",
",",
"requestParams",
",",
"callback",
")",
"{",
"var",
"promise",
"=",
"normalizeRequestParameters",
"(",
"defaults",
",",
"'RemoveSurveyLanguages'",
",",
"requestParams",
")",
".",
"then",
"(",
"function",
"(",
"params",
")",
"{",
"var",
"options",
"=",
"{",
"method",
":",
"'DELETE'",
",",
"uri",
":",
"`",
"${",
"params",
".",
"SurveyId",
"}",
"${",
"params",
".",
"LanguageId",
"}",
"`",
",",
"}",
";",
"return",
"options",
";",
"}",
")",
".",
"then",
"(",
"options",
"=>",
"requestWithTokenCheck",
"(",
"defOptions",
",",
"credentials",
",",
"token",
",",
"options",
")",
")",
".",
"nodeify",
"(",
"callback",
")",
";",
"return",
"promise",
";",
"}"
]
| Remove existing language
{@link https://api.nfieldmr.com/help/api/delete-v1-surveys-surveyid-languages-languageid} | [
"Remove",
"existing",
"language"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L393-L407 |
47,352 | gribnoysup/nfield-api | api.js | getSurveySettings | function getSurveySettings (defOptions, credentials, token, surveyId, callback) {
if (typeof surveyId === 'function') callback = surveyId;
if (checkRequiredParameter(surveyId)) return Promise.reject(Error(`Missing required parameter 'SurveyId'`)).nodeify(callback);
var options = {
method : 'GET',
uri : `v1/Surveys/${surveyId}/Settings`
};
return requestWithTokenCheck(defOptions, credentials, token, options, callback);
} | javascript | function getSurveySettings (defOptions, credentials, token, surveyId, callback) {
if (typeof surveyId === 'function') callback = surveyId;
if (checkRequiredParameter(surveyId)) return Promise.reject(Error(`Missing required parameter 'SurveyId'`)).nodeify(callback);
var options = {
method : 'GET',
uri : `v1/Surveys/${surveyId}/Settings`
};
return requestWithTokenCheck(defOptions, credentials, token, options, callback);
} | [
"function",
"getSurveySettings",
"(",
"defOptions",
",",
"credentials",
",",
"token",
",",
"surveyId",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"surveyId",
"===",
"'function'",
")",
"callback",
"=",
"surveyId",
";",
"if",
"(",
"checkRequiredParameter",
"(",
"surveyId",
")",
")",
"return",
"Promise",
".",
"reject",
"(",
"Error",
"(",
"`",
"`",
")",
")",
".",
"nodeify",
"(",
"callback",
")",
";",
"var",
"options",
"=",
"{",
"method",
":",
"'GET'",
",",
"uri",
":",
"`",
"${",
"surveyId",
"}",
"`",
"}",
";",
"return",
"requestWithTokenCheck",
"(",
"defOptions",
",",
"credentials",
",",
"token",
",",
"options",
",",
"callback",
")",
";",
"}"
]
| Retrieve survey settings
{@link https://api.nfieldmr.com/help/api/get-v1-surveys-surveyid-settings} | [
"Retrieve",
"survey",
"settings"
]
| fcd635255fad2fc483d0e9045ecf7faba04378d9 | https://github.com/gribnoysup/nfield-api/blob/fcd635255fad2fc483d0e9045ecf7faba04378d9/api.js#L414-L425 |
47,353 | andreypopp/react-app-middleware | index.js | evaluatePromise | function evaluatePromise() {
var promise = kew.defer();
var args = utils.toArray(arguments);
args.push(promise.makeNodeResolver());
/*jshint validthis:true */
evaluate.apply(this, args);
return promise;
} | javascript | function evaluatePromise() {
var promise = kew.defer();
var args = utils.toArray(arguments);
args.push(promise.makeNodeResolver());
/*jshint validthis:true */
evaluate.apply(this, args);
return promise;
} | [
"function",
"evaluatePromise",
"(",
")",
"{",
"var",
"promise",
"=",
"kew",
".",
"defer",
"(",
")",
";",
"var",
"args",
"=",
"utils",
".",
"toArray",
"(",
"arguments",
")",
";",
"args",
".",
"push",
"(",
"promise",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"/*jshint validthis:true */",
"evaluate",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"return",
"promise",
";",
"}"
]
| Like evaluate from react-app-server-runtime but exposes Promise API | [
"Like",
"evaluate",
"from",
"react",
"-",
"app",
"-",
"server",
"-",
"runtime",
"but",
"exposes",
"Promise",
"API"
]
| 20288fde7916894b84f01ef5640b3dadd98a0bfb | https://github.com/andreypopp/react-app-middleware/blob/20288fde7916894b84f01ef5640b3dadd98a0bfb/index.js#L46-L53 |
47,354 | andreypopp/react-app-middleware | index.js | makeLocation | function makeLocation(req, origin) {
var protocol = !!req.connection.verifyPeer ? 'https://' : 'http://',
reqOrigin = origin || (protocol + req.headers.host);
return url.parse(reqOrigin + req.originalUrl);
} | javascript | function makeLocation(req, origin) {
var protocol = !!req.connection.verifyPeer ? 'https://' : 'http://',
reqOrigin = origin || (protocol + req.headers.host);
return url.parse(reqOrigin + req.originalUrl);
} | [
"function",
"makeLocation",
"(",
"req",
",",
"origin",
")",
"{",
"var",
"protocol",
"=",
"!",
"!",
"req",
".",
"connection",
".",
"verifyPeer",
"?",
"'https://'",
":",
"'http://'",
",",
"reqOrigin",
"=",
"origin",
"||",
"(",
"protocol",
"+",
"req",
".",
"headers",
".",
"host",
")",
";",
"return",
"url",
".",
"parse",
"(",
"reqOrigin",
"+",
"req",
".",
"originalUrl",
")",
";",
"}"
]
| Create window.location-like object from express request
@param {ExpressRequest} req
@param {String} origin | [
"Create",
"window",
".",
"location",
"-",
"like",
"object",
"from",
"express",
"request"
]
| 20288fde7916894b84f01ef5640b3dadd98a0bfb | https://github.com/andreypopp/react-app-middleware/blob/20288fde7916894b84f01ef5640b3dadd98a0bfb/index.js#L61-L65 |
47,355 | andreypopp/react-app-middleware | index.js | servePage | function servePage(bundle, opts) {
opts = opts || {};
if (typeof bundle !== 'function') {
bundle = bundler.create(bundle, opts);
}
return function(req, res, next) {
var location = makeLocation(req, opts.origin);
var clientReq = request.createRequestFromLocation(location);
bundle()
.then(function(bundle) {
return evaluatePromise({
bundle: bundle,
code: renderComponentToString(clientReq),
debug: opts.debug,
location: location
});
})
.then(function(rendered) {
var init = renderComponent(rendered.request.data);
var markup = rendered.markup.replace(
'</head>',
'<script>' + init + '</script>'
);
res.setHeader('Content-type', 'text/html');
res.statusCode = rendered.isNotFoundErrorHandled ? 404 : 200;
res.write(markup);
res.end();
}, function(err) {
err.isNotFoundError ? res.send(404) : next(err);
});
}
} | javascript | function servePage(bundle, opts) {
opts = opts || {};
if (typeof bundle !== 'function') {
bundle = bundler.create(bundle, opts);
}
return function(req, res, next) {
var location = makeLocation(req, opts.origin);
var clientReq = request.createRequestFromLocation(location);
bundle()
.then(function(bundle) {
return evaluatePromise({
bundle: bundle,
code: renderComponentToString(clientReq),
debug: opts.debug,
location: location
});
})
.then(function(rendered) {
var init = renderComponent(rendered.request.data);
var markup = rendered.markup.replace(
'</head>',
'<script>' + init + '</script>'
);
res.setHeader('Content-type', 'text/html');
res.statusCode = rendered.isNotFoundErrorHandled ? 404 : 200;
res.write(markup);
res.end();
}, function(err) {
err.isNotFoundError ? res.send(404) : next(err);
});
}
} | [
"function",
"servePage",
"(",
"bundle",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"bundle",
"!==",
"'function'",
")",
"{",
"bundle",
"=",
"bundler",
".",
"create",
"(",
"bundle",
",",
"opts",
")",
";",
"}",
"return",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"location",
"=",
"makeLocation",
"(",
"req",
",",
"opts",
".",
"origin",
")",
";",
"var",
"clientReq",
"=",
"request",
".",
"createRequestFromLocation",
"(",
"location",
")",
";",
"bundle",
"(",
")",
".",
"then",
"(",
"function",
"(",
"bundle",
")",
"{",
"return",
"evaluatePromise",
"(",
"{",
"bundle",
":",
"bundle",
",",
"code",
":",
"renderComponentToString",
"(",
"clientReq",
")",
",",
"debug",
":",
"opts",
".",
"debug",
",",
"location",
":",
"location",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"rendered",
")",
"{",
"var",
"init",
"=",
"renderComponent",
"(",
"rendered",
".",
"request",
".",
"data",
")",
";",
"var",
"markup",
"=",
"rendered",
".",
"markup",
".",
"replace",
"(",
"'</head>'",
",",
"'<script>'",
"+",
"init",
"+",
"'</script>'",
")",
";",
"res",
".",
"setHeader",
"(",
"'Content-type'",
",",
"'text/html'",
")",
";",
"res",
".",
"statusCode",
"=",
"rendered",
".",
"isNotFoundErrorHandled",
"?",
"404",
":",
"200",
";",
"res",
".",
"write",
"(",
"markup",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"err",
".",
"isNotFoundError",
"?",
"res",
".",
"send",
"(",
"404",
")",
":",
"next",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Middleware for serving pre-rendered React UI
@param {Bundler|Browserify|ModuleId} bundle
@param {Options} opts | [
"Middleware",
"for",
"serving",
"pre",
"-",
"rendered",
"React",
"UI"
]
| 20288fde7916894b84f01ef5640b3dadd98a0bfb | https://github.com/andreypopp/react-app-middleware/blob/20288fde7916894b84f01ef5640b3dadd98a0bfb/index.js#L73-L106 |
47,356 | 75lb/argv-tools | index.js | expandCombinedShortArg | function expandCombinedShortArg (arg) {
/* remove initial hypen */
arg = arg.slice(1)
return arg.split('').map(letter => '-' + letter)
} | javascript | function expandCombinedShortArg (arg) {
/* remove initial hypen */
arg = arg.slice(1)
return arg.split('').map(letter => '-' + letter)
} | [
"function",
"expandCombinedShortArg",
"(",
"arg",
")",
"{",
"/* remove initial hypen */",
"arg",
"=",
"arg",
".",
"slice",
"(",
"1",
")",
"return",
"arg",
".",
"split",
"(",
"''",
")",
".",
"map",
"(",
"letter",
"=>",
"'-'",
"+",
"letter",
")",
"}"
]
| Expand a combined short option.
@param {string} - the string to expand, e.g. `-ab`
@returns {string[]}
@static | [
"Expand",
"a",
"combined",
"short",
"option",
"."
]
| 624e9249623003a1cadb4cbecd2c428366039e80 | https://github.com/75lb/argv-tools/blob/624e9249623003a1cadb4cbecd2c428366039e80/index.js#L102-L106 |
47,357 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/panel/plugin.js | function( index )
{
if ( index == -1 )
return;
var links = this.element.getElementsByTag( 'a' );
var item = links.getItem( this._.focusIndex = index );
// Safari need focus on the iframe window first(#3389), but we need
// lock the blur to avoid hiding the panel.
if ( CKEDITOR.env.webkit || CKEDITOR.env.opera )
item.getDocument().getWindow().focus();
item.focus();
this.onMark && this.onMark( item );
} | javascript | function( index )
{
if ( index == -1 )
return;
var links = this.element.getElementsByTag( 'a' );
var item = links.getItem( this._.focusIndex = index );
// Safari need focus on the iframe window first(#3389), but we need
// lock the blur to avoid hiding the panel.
if ( CKEDITOR.env.webkit || CKEDITOR.env.opera )
item.getDocument().getWindow().focus();
item.focus();
this.onMark && this.onMark( item );
} | [
"function",
"(",
"index",
")",
"{",
"if",
"(",
"index",
"==",
"-",
"1",
")",
"return",
";",
"var",
"links",
"=",
"this",
".",
"element",
".",
"getElementsByTag",
"(",
"'a'",
")",
";",
"var",
"item",
"=",
"links",
".",
"getItem",
"(",
"this",
".",
"_",
".",
"focusIndex",
"=",
"index",
")",
";",
"// Safari need focus on the iframe window first(#3389), but we need\r",
"// lock the blur to avoid hiding the panel.\r",
"if",
"(",
"CKEDITOR",
".",
"env",
".",
"webkit",
"||",
"CKEDITOR",
".",
"env",
".",
"opera",
")",
"item",
".",
"getDocument",
"(",
")",
".",
"getWindow",
"(",
")",
".",
"focus",
"(",
")",
";",
"item",
".",
"focus",
"(",
")",
";",
"this",
".",
"onMark",
"&&",
"this",
".",
"onMark",
"(",
"item",
")",
";",
"}"
]
| Mark the item specified by the index as current activated. | [
"Mark",
"the",
"item",
"specified",
"by",
"the",
"index",
"as",
"current",
"activated",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/panel/plugin.js#L305-L319 |
|
47,358 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | subscribe | function subscribe (state, topic, subscription, options, context) {
assert(typeof topic, 'string', 'Arbiter.subscribe', 'strings', 'topics');
options = merge(state.options, options);
var
ancestor = addTopicLine(
topic, ancestorTopicSearch(topic, state._topics)
),
node = insert(
getPriority,
createSubscription(state, subscription, options, context),
ancestor.subscriptions
),
subscriptionToken = {
topic: topic,
id: node.id,
priority: node.priority
};
// Notify late subscribers of persisted messages
if (!options.ignorePersisted) {
var
persistedDescendents = map(getPersisted, descendents(ancestor)),
persistedMessages = mergeBy(getFingerArrayOrder, persistedDescendents),
persisted, i, n;
for (i = 0, n = persistedMessages.length; i < n; i++) {
persisted = persistedMessages[i];
!subscription.suspended // eslint-disable-line no-unused-expressions
&& subscription.call(
subscription.context, persisted.data, persisted.topic
);
}
}
return subscriptionToken;
} | javascript | function subscribe (state, topic, subscription, options, context) {
assert(typeof topic, 'string', 'Arbiter.subscribe', 'strings', 'topics');
options = merge(state.options, options);
var
ancestor = addTopicLine(
topic, ancestorTopicSearch(topic, state._topics)
),
node = insert(
getPriority,
createSubscription(state, subscription, options, context),
ancestor.subscriptions
),
subscriptionToken = {
topic: topic,
id: node.id,
priority: node.priority
};
// Notify late subscribers of persisted messages
if (!options.ignorePersisted) {
var
persistedDescendents = map(getPersisted, descendents(ancestor)),
persistedMessages = mergeBy(getFingerArrayOrder, persistedDescendents),
persisted, i, n;
for (i = 0, n = persistedMessages.length; i < n; i++) {
persisted = persistedMessages[i];
!subscription.suspended // eslint-disable-line no-unused-expressions
&& subscription.call(
subscription.context, persisted.data, persisted.topic
);
}
}
return subscriptionToken;
} | [
"function",
"subscribe",
"(",
"state",
",",
"topic",
",",
"subscription",
",",
"options",
",",
"context",
")",
"{",
"assert",
"(",
"typeof",
"topic",
",",
"'string'",
",",
"'Arbiter.subscribe'",
",",
"'strings'",
",",
"'topics'",
")",
";",
"options",
"=",
"merge",
"(",
"state",
".",
"options",
",",
"options",
")",
";",
"var",
"ancestor",
"=",
"addTopicLine",
"(",
"topic",
",",
"ancestorTopicSearch",
"(",
"topic",
",",
"state",
".",
"_topics",
")",
")",
",",
"node",
"=",
"insert",
"(",
"getPriority",
",",
"createSubscription",
"(",
"state",
",",
"subscription",
",",
"options",
",",
"context",
")",
",",
"ancestor",
".",
"subscriptions",
")",
",",
"subscriptionToken",
"=",
"{",
"topic",
":",
"topic",
",",
"id",
":",
"node",
".",
"id",
",",
"priority",
":",
"node",
".",
"priority",
"}",
";",
"// Notify late subscribers of persisted messages",
"if",
"(",
"!",
"options",
".",
"ignorePersisted",
")",
"{",
"var",
"persistedDescendents",
"=",
"map",
"(",
"getPersisted",
",",
"descendents",
"(",
"ancestor",
")",
")",
",",
"persistedMessages",
"=",
"mergeBy",
"(",
"getFingerArrayOrder",
",",
"persistedDescendents",
")",
",",
"persisted",
",",
"i",
",",
"n",
";",
"for",
"(",
"i",
"=",
"0",
",",
"n",
"=",
"persistedMessages",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"persisted",
"=",
"persistedMessages",
"[",
"i",
"]",
";",
"!",
"subscription",
".",
"suspended",
"// eslint-disable-line no-unused-expressions",
"&&",
"subscription",
".",
"call",
"(",
"subscription",
".",
"context",
",",
"persisted",
".",
"data",
",",
"persisted",
".",
"topic",
")",
";",
"}",
"}",
"return",
"subscriptionToken",
";",
"}"
]
| `Arbiter.subscribe` registers a subscription to a topic and its
descendants. When a publication occurs it will be notified. The behavior
can be modified by using the options parameter. `options.priority`
establishes the order to notify subscribers when multiple subscribers
exist. The other option is `ignorePersisted`. This allows a subscriber
to skip being notified of saved messages.
@function subscribe
@memberof Arbiter
@param {Topic|Topic[]} topic The title of the topic to listen for
publications. Topics are hierarchical can be separated by `","`.
@param {Subscription} subscription The function to invoke every
time a publication occurs. If `subscription` is not a function, a
no-operation is put in its place.
@param {Object} [options]. An object that can have two properties.
`ignorePersited` and `priority`.
@param {Object} [context=null] The value of `this` for the subscription.
@return {Token} A unique token to remove this subscription from
the distribution list.
@example
Arbiter.publish('my.topic', null, {persist: true});
Arbiter.subscribe('my.topic', log, {ignorePersisted: true}); // => Nothing
A Subscription is a function provided to the `subscribe` method. It is used
as a callback when a publication occurs. The subscriber is considered
"done working" if it returns a value (even `undefined`). If an error is
thrown, then it is assumed that the subscriber failed. If it returns a
`Promise`, then it is "done" when the `Promise` is fulfilled. If rejected,
it is assumed to fail. If the subscriber function has a length of 3
or more, then it is provided with callback function as the third argument
to be treated as a node-style callback. The first argument to the callback
is the error and the second is the "return value".
@callback Subscription
@memberof Arbiter
@param {Object} data The data associated with the publication.
@param {Topic} topic The topic to which the publication belongs.
@param {Function} [callback] A node style callback.
@return {Object} This is either a `Promise` or a value used to
communicate when the subscriber is done.
@example
// All of the following look the same from a publishers perspective.
Arbiter.subscribe('my.topic', function() {
return new Promise(function(fulfill, reject) {
Math.random() > 0.5 ? fulfill('hi') : reject('bye');
});
});
Arbiter.subscribe('my.topic', function(data, topic, done) {
Math.random() > 0.5 ? done(null, 'hi') : done('bye');
});
Arbiter.subscribe('my.topic', function() {
if (Math.random() > 0.5) {
return 'hi';
} else {
throw 'bye';
}
}); | [
"Arbiter",
".",
"subscribe",
"registers",
"a",
"subscription",
"to",
"a",
"topic",
"and",
"its",
"descendants",
".",
"When",
"a",
"publication",
"occurs",
"it",
"will",
"be",
"notified",
".",
"The",
"behavior",
"can",
"be",
"modified",
"by",
"using",
"the",
"options",
"parameter",
".",
"options",
".",
"priority",
"establishes",
"the",
"order",
"to",
"notify",
"subscribers",
"when",
"multiple",
"subscribers",
"exist",
".",
"The",
"other",
"option",
"is",
"ignorePersisted",
".",
"This",
"allows",
"a",
"subscriber",
"to",
"skip",
"being",
"notified",
"of",
"saved",
"messages",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L127-L164 |
47,359 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | publish | function publish (state, topic, data, options) {
assert(typeof topic, 'string', 'Arbiter.publish', 'strings', 'topics');
options = merge(state.options, options);
var args = [state, topic, data, options];
if (options.sync) {
return hierarchicalTopicDispatcher(state, topic, data, options);
}
return async(hierarchicalTopicDispatcher, args);
} | javascript | function publish (state, topic, data, options) {
assert(typeof topic, 'string', 'Arbiter.publish', 'strings', 'topics');
options = merge(state.options, options);
var args = [state, topic, data, options];
if (options.sync) {
return hierarchicalTopicDispatcher(state, topic, data, options);
}
return async(hierarchicalTopicDispatcher, args);
} | [
"function",
"publish",
"(",
"state",
",",
"topic",
",",
"data",
",",
"options",
")",
"{",
"assert",
"(",
"typeof",
"topic",
",",
"'string'",
",",
"'Arbiter.publish'",
",",
"'strings'",
",",
"'topics'",
")",
";",
"options",
"=",
"merge",
"(",
"state",
".",
"options",
",",
"options",
")",
";",
"var",
"args",
"=",
"[",
"state",
",",
"topic",
",",
"data",
",",
"options",
"]",
";",
"if",
"(",
"options",
".",
"sync",
")",
"{",
"return",
"hierarchicalTopicDispatcher",
"(",
"state",
",",
"topic",
",",
"data",
",",
"options",
")",
";",
"}",
"return",
"async",
"(",
"hierarchicalTopicDispatcher",
",",
"args",
")",
";",
"}"
]
| `Arbiter.publish` notifies all subscribers of a publication by invoking
their subscription function with the data and topic associated with the
publication.
@function publish
@memberof Arbiter
@param {Topic} topic All subscribers to this topic, will be notified of
the publication
@param {Object} [data] This data is the publication that all subscribers
will receive.
@param {Object} [options] These options override the options in
Arbiter.options for this publication only. See [`Options`](#options) for
a complete list
@return {PublicationPromise} This resolves according to
[`Options`](#options)
@example
var options = {persist: true, preventBubble: true};
Arbiter.publish('app.init', 'initialization', options);
Arbiter.subscribe('app', log); // => Nothing because of `preventBubble`
Arbiter.subscribe('app.init', log); // => logs app.init initialization
`publish` returns a `PublicationPromise`. This is a regular old
promise with some additional properties described below. Each property is
updated in real time as updates occur; it stops updating when the promise
fulfills. This can be changed with
`Arbiter.options.updateAfterSettlement`.
@typedef PublicationPromise PublicationPromise
@memberof Arbiter
@property {number} fulfilled The number of promises fulfilled when this
promise settles.
@property {number} rejected The number of promises rejected when this
promise settles.
@property {number} pending The number of promises pending when this
promise settles.
@property {Token} token If the `options.persist` is true, then a token is
added to the promise so it can be removed later.
@example
Arbiter.subscribe('get', getFromCache);
Arbiter.subscribe('get', getFromAjax);
Arbiter.publish('get', {latch: 1})
.then(function(data) {
// This is fulfilled when one of the subscribers fulfills because
// of `latch: 1`. In this case we could also use `latch: 0.5`.
}, function(errs) {
// This occurs when it is impossible to satisify the latch. In this
// case, both have to fail.
}); | [
"Arbiter",
".",
"publish",
"notifies",
"all",
"subscribers",
"of",
"a",
"publication",
"by",
"invoking",
"their",
"subscription",
"function",
"with",
"the",
"data",
"and",
"topic",
"associated",
"with",
"the",
"publication",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L224-L234 |
47,360 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | unsubscribe | function unsubscribe (state, tokens, suspend) {
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(
{topics: state._topics, suspend: suspend}, removeSubscriber, tokens
);
return result.length === 1 ? result[0] : result;
} | javascript | function unsubscribe (state, tokens, suspend) {
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(
{topics: state._topics, suspend: suspend}, removeSubscriber, tokens
);
return result.length === 1 ? result[0] : result;
} | [
"function",
"unsubscribe",
"(",
"state",
",",
"tokens",
",",
"suspend",
")",
"{",
"tokens",
"=",
"typeof",
"tokens",
"===",
"'string'",
"?",
"tokens",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
":",
"tokens",
";",
"tokens",
"=",
"!",
"tokens",
".",
"length",
"?",
"[",
"tokens",
"]",
":",
"tokens",
";",
"var",
"result",
"=",
"curryMap",
"(",
"{",
"topics",
":",
"state",
".",
"_topics",
",",
"suspend",
":",
"suspend",
"}",
",",
"removeSubscriber",
",",
"tokens",
")",
";",
"return",
"result",
".",
"length",
"===",
"1",
"?",
"result",
"[",
"0",
"]",
":",
"result",
";",
"}"
]
| `Arbiter.unsubscribe` removes the subscribers associated with a token or
a topic. This prevents them from being notified when a publication
occurs. By default these cannot be recovered, however this also allows
us to temporarily suspend them instead.
@function unsubscribe
@memberof Arbiter
@param {Token|Topic} token Removes the subscription associated with the
provided token. If a topic is provided, then this removes all
subscribers and their descendants are removed.
@param {Boolean} [suspend=false] If this true, then the subscriptions
are only suspended. This means that they will not be notified of any
publications, but they can be re-enabled with [Arbiter.resubscribe].
@return {Boolean} Returns false if the token's subscription cannot be
located and true otherwise. This returns an array if multiple tokens
or topics used.
@example
Arbiter.subscribe('a', function a () {});
Arbiter.subscribe('a.b', function ab () {});
var bToken = Arbiter.subscribe('b', function b () {});
Arbiter.subscribe('c', function c () {});
Arbiter.unsubscribe(bToken); // 'a', 'a.b', 'c' remain
Arbiter.unsubscribe('a'); // Only 'c' remains
Arbiter.unsubscribe(''); // Removes all subscriptions | [
"Arbiter",
".",
"unsubscribe",
"removes",
"the",
"subscribers",
"associated",
"with",
"a",
"token",
"or",
"a",
"topic",
".",
"This",
"prevents",
"them",
"from",
"being",
"notified",
"when",
"a",
"publication",
"occurs",
".",
"By",
"default",
"these",
"cannot",
"be",
"recovered",
"however",
"this",
"also",
"allows",
"us",
"to",
"temporarily",
"suspend",
"them",
"instead",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L265-L274 |
47,361 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | resubscribe | function resubscribe (state, tokens) {
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(state._topics, unsuspendSubscriber, tokens);
return result.length === 1 ? result[0] : result;
} | javascript | function resubscribe (state, tokens) {
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(state._topics, unsuspendSubscriber, tokens);
return result.length === 1 ? result[0] : result;
} | [
"function",
"resubscribe",
"(",
"state",
",",
"tokens",
")",
"{",
"tokens",
"=",
"typeof",
"tokens",
"===",
"'string'",
"?",
"tokens",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
":",
"tokens",
";",
"tokens",
"=",
"!",
"tokens",
".",
"length",
"?",
"[",
"tokens",
"]",
":",
"tokens",
";",
"var",
"result",
"=",
"curryMap",
"(",
"state",
".",
"_topics",
",",
"unsuspendSubscriber",
",",
"tokens",
")",
";",
"return",
"result",
".",
"length",
"===",
"1",
"?",
"result",
"[",
"0",
"]",
":",
"result",
";",
"}"
]
| Reactivates all subscriptions associated with a token or all
subscriptions that are descendants of a topic.
@function resubscribe
@memberof Arbiter
@param {Token|Topic} token The token or topic to reactivates
@return {Boolean} Returns false if the token's subscription cannot be
located and true otherwise. This returns an array if multiple tokens
or topics used.
@example
Arbiter.subscribe('a, b, c', function() {}); // Create 3 listeners
Arbiter.unsubscribe('', true); // Suspends all listeners
Arbiter.resubscribe(''); // Resumes all listeners | [
"Reactivates",
"all",
"subscriptions",
"associated",
"with",
"a",
"token",
"or",
"all",
"subscriptions",
"that",
"are",
"descendants",
"of",
"a",
"topic",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L294-L301 |
47,362 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | create | function create () {
/**
* Arbiter has a few options to affect the way that subscribers are
* notified and PublicationPromises are resolved.
*
* @typedef Options
* @memberof Arbiter
*
* @property {boolean} persist=false When true, subscribers are notified
* of past messages.
* @property {boolean} sync=false When true, invokes the subscription
* functions synchronously.
* @property {boolean} preventBubble=false When true, only the topics
* that match the published topics exactly are invoked.
* @property {number} latch=0.9999999999999999 When this number is less
* than one, it is the ratio of subscribers that must fulfilled before
* resolving the `PublicationPromise`. If greater or equal to one,
* then it is a count of the subscribers that must fulfill.
* @property {boolean} settlementLatch=false Changes the resolving logic
* of `PublicationPromise` to be based off resolved rather than
* fulfilled promises. This means that failed subscribers will count
* toward the tally of latch.
* @property {number} semaphor=Infinity The maximum number of subscribers
* to allowed to be pending at any given point in time.
* @property {boolean} updateAfterSettlement=false If true, updates the
* `PublicationPromise` after it resolves.
*
* @example
*
* Arbiter.subscribe('a', log);
* Arbiter.subscribe('a.b', log);
* Arbiter.subscribe('a.b.c', log);
* var promise = Arbiter.publish('a.b.c', {latch: 1});
*
* // Remeber publish is async by default?
* // promise.pending === 3;
* // promise.fulfilled === 0;
* // promise.rejected === 0;
*/
var
topics = createNode(''),
options = {
persist: false,
sync: false,
preventBubble: false,
latch: 0.9999999999999999,
settlementLatch: false,
semaphor: Infinity,
updateAfterSettlement: false
},
arbiter = {
_topics: topics,
options: options,
version: 'v1.0.0',
id: mkGenerator(),
create: create
};
arbiter.subscribe = partial1(subscribeDispatcher, arbiter);
arbiter.publish = partial1(publish, arbiter);
arbiter.unsubscribe = partial1(unsubscribe, arbiter);
arbiter.resubscribe = partial1(resubscribe, arbiter);
arbiter.removePersisted = partial1(removePersistedDispatcher, arbiter);
return arbiter;
} | javascript | function create () {
/**
* Arbiter has a few options to affect the way that subscribers are
* notified and PublicationPromises are resolved.
*
* @typedef Options
* @memberof Arbiter
*
* @property {boolean} persist=false When true, subscribers are notified
* of past messages.
* @property {boolean} sync=false When true, invokes the subscription
* functions synchronously.
* @property {boolean} preventBubble=false When true, only the topics
* that match the published topics exactly are invoked.
* @property {number} latch=0.9999999999999999 When this number is less
* than one, it is the ratio of subscribers that must fulfilled before
* resolving the `PublicationPromise`. If greater or equal to one,
* then it is a count of the subscribers that must fulfill.
* @property {boolean} settlementLatch=false Changes the resolving logic
* of `PublicationPromise` to be based off resolved rather than
* fulfilled promises. This means that failed subscribers will count
* toward the tally of latch.
* @property {number} semaphor=Infinity The maximum number of subscribers
* to allowed to be pending at any given point in time.
* @property {boolean} updateAfterSettlement=false If true, updates the
* `PublicationPromise` after it resolves.
*
* @example
*
* Arbiter.subscribe('a', log);
* Arbiter.subscribe('a.b', log);
* Arbiter.subscribe('a.b.c', log);
* var promise = Arbiter.publish('a.b.c', {latch: 1});
*
* // Remeber publish is async by default?
* // promise.pending === 3;
* // promise.fulfilled === 0;
* // promise.rejected === 0;
*/
var
topics = createNode(''),
options = {
persist: false,
sync: false,
preventBubble: false,
latch: 0.9999999999999999,
settlementLatch: false,
semaphor: Infinity,
updateAfterSettlement: false
},
arbiter = {
_topics: topics,
options: options,
version: 'v1.0.0',
id: mkGenerator(),
create: create
};
arbiter.subscribe = partial1(subscribeDispatcher, arbiter);
arbiter.publish = partial1(publish, arbiter);
arbiter.unsubscribe = partial1(unsubscribe, arbiter);
arbiter.resubscribe = partial1(resubscribe, arbiter);
arbiter.removePersisted = partial1(removePersistedDispatcher, arbiter);
return arbiter;
} | [
"function",
"create",
"(",
")",
"{",
"/**\n * Arbiter has a few options to affect the way that subscribers are\n * notified and PublicationPromises are resolved.\n *\n * @typedef Options\n * @memberof Arbiter\n *\n * @property {boolean} persist=false When true, subscribers are notified\n * of past messages.\n * @property {boolean} sync=false When true, invokes the subscription\n * functions synchronously.\n * @property {boolean} preventBubble=false When true, only the topics\n * that match the published topics exactly are invoked.\n * @property {number} latch=0.9999999999999999 When this number is less\n * than one, it is the ratio of subscribers that must fulfilled before\n * resolving the `PublicationPromise`. If greater or equal to one,\n * then it is a count of the subscribers that must fulfill.\n * @property {boolean} settlementLatch=false Changes the resolving logic\n * of `PublicationPromise` to be based off resolved rather than\n * fulfilled promises. This means that failed subscribers will count\n * toward the tally of latch.\n * @property {number} semaphor=Infinity The maximum number of subscribers\n * to allowed to be pending at any given point in time.\n * @property {boolean} updateAfterSettlement=false If true, updates the\n * `PublicationPromise` after it resolves.\n *\n * @example\n *\n * Arbiter.subscribe('a', log);\n * Arbiter.subscribe('a.b', log);\n * Arbiter.subscribe('a.b.c', log);\n * var promise = Arbiter.publish('a.b.c', {latch: 1});\n *\n * // Remeber publish is async by default?\n * // promise.pending === 3;\n * // promise.fulfilled === 0;\n * // promise.rejected === 0;\n */",
"var",
"topics",
"=",
"createNode",
"(",
"''",
")",
",",
"options",
"=",
"{",
"persist",
":",
"false",
",",
"sync",
":",
"false",
",",
"preventBubble",
":",
"false",
",",
"latch",
":",
"0.9999999999999999",
",",
"settlementLatch",
":",
"false",
",",
"semaphor",
":",
"Infinity",
",",
"updateAfterSettlement",
":",
"false",
"}",
",",
"arbiter",
"=",
"{",
"_topics",
":",
"topics",
",",
"options",
":",
"options",
",",
"version",
":",
"'v1.0.0'",
",",
"id",
":",
"mkGenerator",
"(",
")",
",",
"create",
":",
"create",
"}",
";",
"arbiter",
".",
"subscribe",
"=",
"partial1",
"(",
"subscribeDispatcher",
",",
"arbiter",
")",
";",
"arbiter",
".",
"publish",
"=",
"partial1",
"(",
"publish",
",",
"arbiter",
")",
";",
"arbiter",
".",
"unsubscribe",
"=",
"partial1",
"(",
"unsubscribe",
",",
"arbiter",
")",
";",
"arbiter",
".",
"resubscribe",
"=",
"partial1",
"(",
"resubscribe",
",",
"arbiter",
")",
";",
"arbiter",
".",
"removePersisted",
"=",
"partial1",
"(",
"removePersistedDispatcher",
",",
"arbiter",
")",
";",
"return",
"arbiter",
";",
"}"
]
| Creates a new instance of Arbiter that is completely separate from the
original. It has its own set of topics, subscribers, and options.
@function create
@memberof Arbiter
@return {Arbiter} The new instance.
@example
var arbiter = Arbiter.create();
Arbiter.subscribe('a', function a () {});
arbiter.publish('a'); // Does not execute a | [
"Creates",
"a",
"new",
"instance",
"of",
"Arbiter",
"that",
"is",
"completely",
"separate",
"from",
"the",
"original",
".",
"It",
"has",
"its",
"own",
"set",
"of",
"topics",
"subscribers",
"and",
"options",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L363-L428 |
47,363 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | hierarchicalTopicDispatcher | function hierarchicalTopicDispatcher (state, topic, data, options) {
var
lineage = findLineage(getTopic, isAncestorTopic, topic, state._topics),
topicNode = lineage[lineage.length - 1],
subscriptions = options.preventBubble
? topicNode.topic === topic ? topicNode.subscriptions : []
: mergeBy(getFingerArrayPriority, map(getSubscriptions, lineage)),
fulfilledPromise = subscriptionDispatcher(
topic, data, options, subscriptions
);
if (options.persist) {
var id = state.id();
topicNode = addTopicLine(topic, topicNode);
topicNode.persisted.push(
{topic: topic, data: data, order: id}
);
fulfilledPromise.token = {
topic: topic,
id: id
};
}
return fulfilledPromise;
} | javascript | function hierarchicalTopicDispatcher (state, topic, data, options) {
var
lineage = findLineage(getTopic, isAncestorTopic, topic, state._topics),
topicNode = lineage[lineage.length - 1],
subscriptions = options.preventBubble
? topicNode.topic === topic ? topicNode.subscriptions : []
: mergeBy(getFingerArrayPriority, map(getSubscriptions, lineage)),
fulfilledPromise = subscriptionDispatcher(
topic, data, options, subscriptions
);
if (options.persist) {
var id = state.id();
topicNode = addTopicLine(topic, topicNode);
topicNode.persisted.push(
{topic: topic, data: data, order: id}
);
fulfilledPromise.token = {
topic: topic,
id: id
};
}
return fulfilledPromise;
} | [
"function",
"hierarchicalTopicDispatcher",
"(",
"state",
",",
"topic",
",",
"data",
",",
"options",
")",
"{",
"var",
"lineage",
"=",
"findLineage",
"(",
"getTopic",
",",
"isAncestorTopic",
",",
"topic",
",",
"state",
".",
"_topics",
")",
",",
"topicNode",
"=",
"lineage",
"[",
"lineage",
".",
"length",
"-",
"1",
"]",
",",
"subscriptions",
"=",
"options",
".",
"preventBubble",
"?",
"topicNode",
".",
"topic",
"===",
"topic",
"?",
"topicNode",
".",
"subscriptions",
":",
"[",
"]",
":",
"mergeBy",
"(",
"getFingerArrayPriority",
",",
"map",
"(",
"getSubscriptions",
",",
"lineage",
")",
")",
",",
"fulfilledPromise",
"=",
"subscriptionDispatcher",
"(",
"topic",
",",
"data",
",",
"options",
",",
"subscriptions",
")",
";",
"if",
"(",
"options",
".",
"persist",
")",
"{",
"var",
"id",
"=",
"state",
".",
"id",
"(",
")",
";",
"topicNode",
"=",
"addTopicLine",
"(",
"topic",
",",
"topicNode",
")",
";",
"topicNode",
".",
"persisted",
".",
"push",
"(",
"{",
"topic",
":",
"topic",
",",
"data",
":",
"data",
",",
"order",
":",
"id",
"}",
")",
";",
"fulfilledPromise",
".",
"token",
"=",
"{",
"topic",
":",
"topic",
",",
"id",
":",
"id",
"}",
";",
"}",
"return",
"fulfilledPromise",
";",
"}"
]
| Takes care of all the heavy lifting of publishing a message. This includes locating all topics, their subscribers, publishing the data and, if necessary, storing the message for late subscribers. | [
"Takes",
"care",
"of",
"all",
"the",
"heavy",
"lifting",
"of",
"publishing",
"a",
"message",
".",
"This",
"includes",
"locating",
"all",
"topics",
"their",
"subscribers",
"publishing",
"the",
"data",
"and",
"if",
"necessary",
"storing",
"the",
"message",
"for",
"late",
"subscribers",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L437-L462 |
47,364 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | resumeSubscriptionDispatcher | function resumeSubscriptionDispatcher (
topic, data, options, subscriptions, resolver, fulfill, reject
) {
var
promise = resolver.promise,
subscription;
for (
;
resolver.i >= 0 && promise.pending < options.semaphor;
resolver.i -= 1
) {
subscription = subscriptions[resolver.i];
if (!subscription.suspended) {
promise.pending += 1;
subscriptionInvoker(subscription, data, topic).then(fulfill, reject);
}
}
} | javascript | function resumeSubscriptionDispatcher (
topic, data, options, subscriptions, resolver, fulfill, reject
) {
var
promise = resolver.promise,
subscription;
for (
;
resolver.i >= 0 && promise.pending < options.semaphor;
resolver.i -= 1
) {
subscription = subscriptions[resolver.i];
if (!subscription.suspended) {
promise.pending += 1;
subscriptionInvoker(subscription, data, topic).then(fulfill, reject);
}
}
} | [
"function",
"resumeSubscriptionDispatcher",
"(",
"topic",
",",
"data",
",",
"options",
",",
"subscriptions",
",",
"resolver",
",",
"fulfill",
",",
"reject",
")",
"{",
"var",
"promise",
"=",
"resolver",
".",
"promise",
",",
"subscription",
";",
"for",
"(",
";",
"resolver",
".",
"i",
">=",
"0",
"&&",
"promise",
".",
"pending",
"<",
"options",
".",
"semaphor",
";",
"resolver",
".",
"i",
"-=",
"1",
")",
"{",
"subscription",
"=",
"subscriptions",
"[",
"resolver",
".",
"i",
"]",
";",
"if",
"(",
"!",
"subscription",
".",
"suspended",
")",
"{",
"promise",
".",
"pending",
"+=",
"1",
";",
"subscriptionInvoker",
"(",
"subscription",
",",
"data",
",",
"topic",
")",
".",
"then",
"(",
"fulfill",
",",
"reject",
")",
";",
"}",
"}",
"}"
]
| Invokes the next set of subscriptions | [
"Invokes",
"the",
"next",
"set",
"of",
"subscriptions"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L465-L484 |
47,365 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | removePersistedDispatcher | function removePersistedDispatcher (state, tokens) {
tokens = tokens && tokens.token || tokens || '';
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(state._topics, removePersisted, tokens);
return result.length === 1 ? result[0] : result;
} | javascript | function removePersistedDispatcher (state, tokens) {
tokens = tokens && tokens.token || tokens || '';
tokens = typeof tokens === 'string' ? tokens.split(/,\s*/) : tokens;
tokens = !tokens.length ? [tokens] : tokens;
var result = curryMap(state._topics, removePersisted, tokens);
return result.length === 1 ? result[0] : result;
} | [
"function",
"removePersistedDispatcher",
"(",
"state",
",",
"tokens",
")",
"{",
"tokens",
"=",
"tokens",
"&&",
"tokens",
".",
"token",
"||",
"tokens",
"||",
"''",
";",
"tokens",
"=",
"typeof",
"tokens",
"===",
"'string'",
"?",
"tokens",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
":",
"tokens",
";",
"tokens",
"=",
"!",
"tokens",
".",
"length",
"?",
"[",
"tokens",
"]",
":",
"tokens",
";",
"var",
"result",
"=",
"curryMap",
"(",
"state",
".",
"_topics",
",",
"removePersisted",
",",
"tokens",
")",
";",
"return",
"result",
".",
"length",
"===",
"1",
"?",
"result",
"[",
"0",
"]",
":",
"result",
";",
"}"
]
| Takes care of sending all the requests on their way | [
"Takes",
"care",
"of",
"sending",
"all",
"the",
"requests",
"on",
"their",
"way"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L487-L495 |
47,366 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | subscriptionDispatcher | function subscriptionDispatcher (topic, data, options, subscriptions) {
var
resolver = createResolver(),
fulfill = resolveUse('fulfilledValues', 'fulfilled', options, resolver),
reject = resolveUse('rejectedValues', 'rejected', options, resolver);
resolver.i = subscriptions.length - 1;
resolver.resume = {
topic: topic,
data: data,
subscriptions: subscriptions,
fulfill: fulfill,
reject: reject
};
resumeSubscriptionDispatcher(
topic, data, options, subscriptions, resolver, fulfill, reject
);
evaluateLatch(resolver, options);
return resolver.promise;
} | javascript | function subscriptionDispatcher (topic, data, options, subscriptions) {
var
resolver = createResolver(),
fulfill = resolveUse('fulfilledValues', 'fulfilled', options, resolver),
reject = resolveUse('rejectedValues', 'rejected', options, resolver);
resolver.i = subscriptions.length - 1;
resolver.resume = {
topic: topic,
data: data,
subscriptions: subscriptions,
fulfill: fulfill,
reject: reject
};
resumeSubscriptionDispatcher(
topic, data, options, subscriptions, resolver, fulfill, reject
);
evaluateLatch(resolver, options);
return resolver.promise;
} | [
"function",
"subscriptionDispatcher",
"(",
"topic",
",",
"data",
",",
"options",
",",
"subscriptions",
")",
"{",
"var",
"resolver",
"=",
"createResolver",
"(",
")",
",",
"fulfill",
"=",
"resolveUse",
"(",
"'fulfilledValues'",
",",
"'fulfilled'",
",",
"options",
",",
"resolver",
")",
",",
"reject",
"=",
"resolveUse",
"(",
"'rejectedValues'",
",",
"'rejected'",
",",
"options",
",",
"resolver",
")",
";",
"resolver",
".",
"i",
"=",
"subscriptions",
".",
"length",
"-",
"1",
";",
"resolver",
".",
"resume",
"=",
"{",
"topic",
":",
"topic",
",",
"data",
":",
"data",
",",
"subscriptions",
":",
"subscriptions",
",",
"fulfill",
":",
"fulfill",
",",
"reject",
":",
"reject",
"}",
";",
"resumeSubscriptionDispatcher",
"(",
"topic",
",",
"data",
",",
"options",
",",
"subscriptions",
",",
"resolver",
",",
"fulfill",
",",
"reject",
")",
";",
"evaluateLatch",
"(",
"resolver",
",",
"options",
")",
";",
"return",
"resolver",
".",
"promise",
";",
"}"
]
| Invokes all the subscriptions according to `options` and returns a promise that resolves according to `options`. | [
"Invokes",
"all",
"the",
"subscriptions",
"according",
"to",
"options",
"and",
"returns",
"a",
"promise",
"that",
"resolves",
"according",
"to",
"options",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L499-L520 |
47,367 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | resolveUse | function resolveUse (appendList, increment, options, resolver) {
return function resolveUseClosure (value) {
// TODO This should state.options('update..
// TODO look at all of options.xxxx
if (resolver.settled && !options.updateAfterSettlement) {
return;
}
var promise = resolver.promise;
resolver[appendList].push(value);
promise[increment] += 1;
promise.pending -= 1;
if (resolver.i >= 0) {
var resume = resolver.resume;
resumeSubscriptionDispatcher(
resume.topic, resume.data, options, resume.subscriptions,
resolver, resume.fulfill, resume.reject
);
return;
}
evaluateLatch(resolver, options);
};
} | javascript | function resolveUse (appendList, increment, options, resolver) {
return function resolveUseClosure (value) {
// TODO This should state.options('update..
// TODO look at all of options.xxxx
if (resolver.settled && !options.updateAfterSettlement) {
return;
}
var promise = resolver.promise;
resolver[appendList].push(value);
promise[increment] += 1;
promise.pending -= 1;
if (resolver.i >= 0) {
var resume = resolver.resume;
resumeSubscriptionDispatcher(
resume.topic, resume.data, options, resume.subscriptions,
resolver, resume.fulfill, resume.reject
);
return;
}
evaluateLatch(resolver, options);
};
} | [
"function",
"resolveUse",
"(",
"appendList",
",",
"increment",
",",
"options",
",",
"resolver",
")",
"{",
"return",
"function",
"resolveUseClosure",
"(",
"value",
")",
"{",
"// TODO This should state.options('update..",
"// TODO look at all of options.xxxx",
"if",
"(",
"resolver",
".",
"settled",
"&&",
"!",
"options",
".",
"updateAfterSettlement",
")",
"{",
"return",
";",
"}",
"var",
"promise",
"=",
"resolver",
".",
"promise",
";",
"resolver",
"[",
"appendList",
"]",
".",
"push",
"(",
"value",
")",
";",
"promise",
"[",
"increment",
"]",
"+=",
"1",
";",
"promise",
".",
"pending",
"-=",
"1",
";",
"if",
"(",
"resolver",
".",
"i",
">=",
"0",
")",
"{",
"var",
"resume",
"=",
"resolver",
".",
"resume",
";",
"resumeSubscriptionDispatcher",
"(",
"resume",
".",
"topic",
",",
"resume",
".",
"data",
",",
"options",
",",
"resume",
".",
"subscriptions",
",",
"resolver",
",",
"resume",
".",
"fulfill",
",",
"resume",
".",
"reject",
")",
";",
"return",
";",
"}",
"evaluateLatch",
"(",
"resolver",
",",
"options",
")",
";",
"}",
";",
"}"
]
| Takes care all the bookkeeping work surrounding a subscriber resolving resolving. | [
"Takes",
"care",
"all",
"the",
"bookkeeping",
"work",
"surrounding",
"a",
"subscriber",
"resolving",
"resolving",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L524-L549 |
47,368 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | evaluateLatch | function evaluateLatch (resolver, options) {
var
settlementLatch = options.settlementLatch,
latch = options.latch,
promise = resolver.promise,
fulfilled = promise.fulfilled,
pending = promise.pending,
rejected = promise.rejected,
settled = fulfilled + rejected,
maxFulfilled = fulfilled + pending,
total = fulfilled + pending + rejected;
if (resolver.settled) {
return resolver.settled;
}
if (!settlementLatch && latch >= 1 && maxFulfilled < latch
|| !settlementLatch && latch < 1 && maxFulfilled / total < latch
|| settlementLatch && latch >= 1 && total < latch
|| settlementLatch && latch < 1 && total === 0
) {
resolver.settled = true;
return resolver.reject(resolver.rejectedValues);
}
if (!settlementLatch && latch >= 1 && fulfilled >= latch
|| !settlementLatch && latch < 1 && fulfilled / total >= latch
|| settlementLatch && latch >= 1 && settled >= latch
|| settlementLatch && latch < 1 && settled / total >= latch
) {
resolver.settled = true;
return settlementLatch
? resolver.fulfill(
resolver.fulfilledValues.concat(resolver.rejectedValues)
) : resolver.fulfill(resolver.fulfilledValues);
}
return resolver.settled;
} | javascript | function evaluateLatch (resolver, options) {
var
settlementLatch = options.settlementLatch,
latch = options.latch,
promise = resolver.promise,
fulfilled = promise.fulfilled,
pending = promise.pending,
rejected = promise.rejected,
settled = fulfilled + rejected,
maxFulfilled = fulfilled + pending,
total = fulfilled + pending + rejected;
if (resolver.settled) {
return resolver.settled;
}
if (!settlementLatch && latch >= 1 && maxFulfilled < latch
|| !settlementLatch && latch < 1 && maxFulfilled / total < latch
|| settlementLatch && latch >= 1 && total < latch
|| settlementLatch && latch < 1 && total === 0
) {
resolver.settled = true;
return resolver.reject(resolver.rejectedValues);
}
if (!settlementLatch && latch >= 1 && fulfilled >= latch
|| !settlementLatch && latch < 1 && fulfilled / total >= latch
|| settlementLatch && latch >= 1 && settled >= latch
|| settlementLatch && latch < 1 && settled / total >= latch
) {
resolver.settled = true;
return settlementLatch
? resolver.fulfill(
resolver.fulfilledValues.concat(resolver.rejectedValues)
) : resolver.fulfill(resolver.fulfilledValues);
}
return resolver.settled;
} | [
"function",
"evaluateLatch",
"(",
"resolver",
",",
"options",
")",
"{",
"var",
"settlementLatch",
"=",
"options",
".",
"settlementLatch",
",",
"latch",
"=",
"options",
".",
"latch",
",",
"promise",
"=",
"resolver",
".",
"promise",
",",
"fulfilled",
"=",
"promise",
".",
"fulfilled",
",",
"pending",
"=",
"promise",
".",
"pending",
",",
"rejected",
"=",
"promise",
".",
"rejected",
",",
"settled",
"=",
"fulfilled",
"+",
"rejected",
",",
"maxFulfilled",
"=",
"fulfilled",
"+",
"pending",
",",
"total",
"=",
"fulfilled",
"+",
"pending",
"+",
"rejected",
";",
"if",
"(",
"resolver",
".",
"settled",
")",
"{",
"return",
"resolver",
".",
"settled",
";",
"}",
"if",
"(",
"!",
"settlementLatch",
"&&",
"latch",
">=",
"1",
"&&",
"maxFulfilled",
"<",
"latch",
"||",
"!",
"settlementLatch",
"&&",
"latch",
"<",
"1",
"&&",
"maxFulfilled",
"/",
"total",
"<",
"latch",
"||",
"settlementLatch",
"&&",
"latch",
">=",
"1",
"&&",
"total",
"<",
"latch",
"||",
"settlementLatch",
"&&",
"latch",
"<",
"1",
"&&",
"total",
"===",
"0",
")",
"{",
"resolver",
".",
"settled",
"=",
"true",
";",
"return",
"resolver",
".",
"reject",
"(",
"resolver",
".",
"rejectedValues",
")",
";",
"}",
"if",
"(",
"!",
"settlementLatch",
"&&",
"latch",
">=",
"1",
"&&",
"fulfilled",
">=",
"latch",
"||",
"!",
"settlementLatch",
"&&",
"latch",
"<",
"1",
"&&",
"fulfilled",
"/",
"total",
">=",
"latch",
"||",
"settlementLatch",
"&&",
"latch",
">=",
"1",
"&&",
"settled",
">=",
"latch",
"||",
"settlementLatch",
"&&",
"latch",
"<",
"1",
"&&",
"settled",
"/",
"total",
">=",
"latch",
")",
"{",
"resolver",
".",
"settled",
"=",
"true",
";",
"return",
"settlementLatch",
"?",
"resolver",
".",
"fulfill",
"(",
"resolver",
".",
"fulfilledValues",
".",
"concat",
"(",
"resolver",
".",
"rejectedValues",
")",
")",
":",
"resolver",
".",
"fulfill",
"(",
"resolver",
".",
"fulfilledValues",
")",
";",
"}",
"return",
"resolver",
".",
"settled",
";",
"}"
]
| Resolves the latch according to `options`. Computes the hypothetical max and resolves if is not met. | [
"Resolves",
"the",
"latch",
"according",
"to",
"options",
".",
"Computes",
"the",
"hypothetical",
"max",
"and",
"resolves",
"if",
"is",
"not",
"met",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L553-L591 |
47,369 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | subscriptionInvoker | function subscriptionInvoker (subscription, data, topic) {
var result;
if (subscription.fn.length === 3) {
return new Promise(function promiseResolver (fulfill, reject) {
subscription.fn.call(
subscription.context, data, topic, function callback (err, succ) {
return err ? reject(err) : fulfill(succ);
}
);
});
}
try {
result = subscription.fn.call(subscription.context, data, topic);
} catch (e) {
return Promise.reject(e);
}
if (result && typeof result.then === 'function') {
return result;
}
return Promise.resolve(result);
} | javascript | function subscriptionInvoker (subscription, data, topic) {
var result;
if (subscription.fn.length === 3) {
return new Promise(function promiseResolver (fulfill, reject) {
subscription.fn.call(
subscription.context, data, topic, function callback (err, succ) {
return err ? reject(err) : fulfill(succ);
}
);
});
}
try {
result = subscription.fn.call(subscription.context, data, topic);
} catch (e) {
return Promise.reject(e);
}
if (result && typeof result.then === 'function') {
return result;
}
return Promise.resolve(result);
} | [
"function",
"subscriptionInvoker",
"(",
"subscription",
",",
"data",
",",
"topic",
")",
"{",
"var",
"result",
";",
"if",
"(",
"subscription",
".",
"fn",
".",
"length",
"===",
"3",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"promiseResolver",
"(",
"fulfill",
",",
"reject",
")",
"{",
"subscription",
".",
"fn",
".",
"call",
"(",
"subscription",
".",
"context",
",",
"data",
",",
"topic",
",",
"function",
"callback",
"(",
"err",
",",
"succ",
")",
"{",
"return",
"err",
"?",
"reject",
"(",
"err",
")",
":",
"fulfill",
"(",
"succ",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"try",
"{",
"result",
"=",
"subscription",
".",
"fn",
".",
"call",
"(",
"subscription",
".",
"context",
",",
"data",
",",
"topic",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"e",
")",
";",
"}",
"if",
"(",
"result",
"&&",
"typeof",
"result",
".",
"then",
"===",
"'function'",
")",
"{",
"return",
"result",
";",
"}",
"return",
"Promise",
".",
"resolve",
"(",
"result",
")",
";",
"}"
]
| Invokes a subscription with the required parameters and acts as an adapter for the different asynchronous mechanisms behavior. i.e. node-style callbacks and promises. | [
"Invokes",
"a",
"subscription",
"with",
"the",
"required",
"parameters",
"and",
"acts",
"as",
"an",
"adapter",
"for",
"the",
"different",
"asynchronous",
"mechanisms",
"behavior",
".",
"i",
".",
"e",
".",
"node",
"-",
"style",
"callbacks",
"and",
"promises",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L596-L620 |
47,370 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | subscribeDispatcher | function subscribeDispatcher (state, topic, subscriptions, options, context) {
topic = typeof topic === 'string' ? topic.split(/,\s*/) : topic;
topic = topic && topic.length ? topic : [topic];
var result = curryMap(
[state, null, subscriptions, options, context],
subscribeTopicApplier,
topic
);
return result.length === 1 ? result[0] : result;
} | javascript | function subscribeDispatcher (state, topic, subscriptions, options, context) {
topic = typeof topic === 'string' ? topic.split(/,\s*/) : topic;
topic = topic && topic.length ? topic : [topic];
var result = curryMap(
[state, null, subscriptions, options, context],
subscribeTopicApplier,
topic
);
return result.length === 1 ? result[0] : result;
} | [
"function",
"subscribeDispatcher",
"(",
"state",
",",
"topic",
",",
"subscriptions",
",",
"options",
",",
"context",
")",
"{",
"topic",
"=",
"typeof",
"topic",
"===",
"'string'",
"?",
"topic",
".",
"split",
"(",
"/",
",\\s*",
"/",
")",
":",
"topic",
";",
"topic",
"=",
"topic",
"&&",
"topic",
".",
"length",
"?",
"topic",
":",
"[",
"topic",
"]",
";",
"var",
"result",
"=",
"curryMap",
"(",
"[",
"state",
",",
"null",
",",
"subscriptions",
",",
"options",
",",
"context",
"]",
",",
"subscribeTopicApplier",
",",
"topic",
")",
";",
"return",
"result",
".",
"length",
"===",
"1",
"?",
"result",
"[",
"0",
"]",
":",
"result",
";",
"}"
]
| This coverts `topic`, which can represent multiple subscriptions and serializes them into individual topics for use with the `subscription` | [
"This",
"coverts",
"topic",
"which",
"can",
"represent",
"multiple",
"subscriptions",
"and",
"serializes",
"them",
"into",
"individual",
"topics",
"for",
"use",
"with",
"the",
"subscription"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L624-L635 |
47,371 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | applyTopicDescendents | function applyTopicDescendents (f, property, topic, topics) {
var node = ancestorTopicSearch(topic, topics);
if (node.topic === topic) {
return curryMap(property, f, descendents(node));
}
return null;
} | javascript | function applyTopicDescendents (f, property, topic, topics) {
var node = ancestorTopicSearch(topic, topics);
if (node.topic === topic) {
return curryMap(property, f, descendents(node));
}
return null;
} | [
"function",
"applyTopicDescendents",
"(",
"f",
",",
"property",
",",
"topic",
",",
"topics",
")",
"{",
"var",
"node",
"=",
"ancestorTopicSearch",
"(",
"topic",
",",
"topics",
")",
";",
"if",
"(",
"node",
".",
"topic",
"===",
"topic",
")",
"{",
"return",
"curryMap",
"(",
"property",
",",
"f",
",",
"descendents",
"(",
"node",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| For all descendants of `topic` remove all elements of `node[property`. | [
"For",
"all",
"descendants",
"of",
"topic",
"remove",
"all",
"elements",
"of",
"node",
"[",
"property",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L645-L652 |
47,372 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | unsuspendSubscriber | function unsuspendSubscriber (topic, token) {
if (typeof token === 'string') {
return !!applyTopicDescendents(
unsuspendTopic, 'subscriptions', token, topic
);
}
var node = ancestorTopicSearch(token.topic, topic);
if (node.topic !== token.topic) {
return false;
}
var i = searchAround(
getId, getPriority,
token.id, token.priority,
binaryIndexBy(getPriority, token.priority, node.subscriptions),
node.subscriptions
);
if (i === -1) {
return false;
}
return !!unsuspendNode(node.subscriptions[i]);
} | javascript | function unsuspendSubscriber (topic, token) {
if (typeof token === 'string') {
return !!applyTopicDescendents(
unsuspendTopic, 'subscriptions', token, topic
);
}
var node = ancestorTopicSearch(token.topic, topic);
if (node.topic !== token.topic) {
return false;
}
var i = searchAround(
getId, getPriority,
token.id, token.priority,
binaryIndexBy(getPriority, token.priority, node.subscriptions),
node.subscriptions
);
if (i === -1) {
return false;
}
return !!unsuspendNode(node.subscriptions[i]);
} | [
"function",
"unsuspendSubscriber",
"(",
"topic",
",",
"token",
")",
"{",
"if",
"(",
"typeof",
"token",
"===",
"'string'",
")",
"{",
"return",
"!",
"!",
"applyTopicDescendents",
"(",
"unsuspendTopic",
",",
"'subscriptions'",
",",
"token",
",",
"topic",
")",
";",
"}",
"var",
"node",
"=",
"ancestorTopicSearch",
"(",
"token",
".",
"topic",
",",
"topic",
")",
";",
"if",
"(",
"node",
".",
"topic",
"!==",
"token",
".",
"topic",
")",
"{",
"return",
"false",
";",
"}",
"var",
"i",
"=",
"searchAround",
"(",
"getId",
",",
"getPriority",
",",
"token",
".",
"id",
",",
"token",
".",
"priority",
",",
"binaryIndexBy",
"(",
"getPriority",
",",
"token",
".",
"priority",
",",
"node",
".",
"subscriptions",
")",
",",
"node",
".",
"subscriptions",
")",
";",
"if",
"(",
"i",
"===",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"!",
"unsuspendNode",
"(",
"node",
".",
"subscriptions",
"[",
"i",
"]",
")",
";",
"}"
]
| Finds the subscription associated with a token and unsuspendes it. Returns false if it was removed and true it was unsuspended. | [
"Finds",
"the",
"subscription",
"associated",
"with",
"a",
"token",
"and",
"unsuspendes",
"it",
".",
"Returns",
"false",
"if",
"it",
"was",
"removed",
"and",
"true",
"it",
"was",
"unsuspended",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L656-L680 |
47,373 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | removeSubscriber | function removeSubscriber (args, token) {
var
topics = args.topics,
suspendSubs = args.suspend;
if (typeof token === 'string') {
return !!applyTopicDescendents(
suspendSubs ? suspendTopic : empty, 'subscriptions', token, topics
);
}
var node = ancestorTopicSearch(token.topic, topics);
if (node.topic !== token.topic) {
return false;
}
var i = searchAround(
getId, getPriority,
token.id, token.priority,
binaryIndexBy(getPriority, token.priority, node.subscriptions),
node.subscriptions
);
if (i === -1) {
return false;
}
if (suspendSubs) {
return !!suspendNode(node.subscriptions[i]);
}
return !!node.subscriptions.splice(i, 1);
} | javascript | function removeSubscriber (args, token) {
var
topics = args.topics,
suspendSubs = args.suspend;
if (typeof token === 'string') {
return !!applyTopicDescendents(
suspendSubs ? suspendTopic : empty, 'subscriptions', token, topics
);
}
var node = ancestorTopicSearch(token.topic, topics);
if (node.topic !== token.topic) {
return false;
}
var i = searchAround(
getId, getPriority,
token.id, token.priority,
binaryIndexBy(getPriority, token.priority, node.subscriptions),
node.subscriptions
);
if (i === -1) {
return false;
}
if (suspendSubs) {
return !!suspendNode(node.subscriptions[i]);
}
return !!node.subscriptions.splice(i, 1);
} | [
"function",
"removeSubscriber",
"(",
"args",
",",
"token",
")",
"{",
"var",
"topics",
"=",
"args",
".",
"topics",
",",
"suspendSubs",
"=",
"args",
".",
"suspend",
";",
"if",
"(",
"typeof",
"token",
"===",
"'string'",
")",
"{",
"return",
"!",
"!",
"applyTopicDescendents",
"(",
"suspendSubs",
"?",
"suspendTopic",
":",
"empty",
",",
"'subscriptions'",
",",
"token",
",",
"topics",
")",
";",
"}",
"var",
"node",
"=",
"ancestorTopicSearch",
"(",
"token",
".",
"topic",
",",
"topics",
")",
";",
"if",
"(",
"node",
".",
"topic",
"!==",
"token",
".",
"topic",
")",
"{",
"return",
"false",
";",
"}",
"var",
"i",
"=",
"searchAround",
"(",
"getId",
",",
"getPriority",
",",
"token",
".",
"id",
",",
"token",
".",
"priority",
",",
"binaryIndexBy",
"(",
"getPriority",
",",
"token",
".",
"priority",
",",
"node",
".",
"subscriptions",
")",
",",
"node",
".",
"subscriptions",
")",
";",
"if",
"(",
"i",
"===",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"suspendSubs",
")",
"{",
"return",
"!",
"!",
"suspendNode",
"(",
"node",
".",
"subscriptions",
"[",
"i",
"]",
")",
";",
"}",
"return",
"!",
"!",
"node",
".",
"subscriptions",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}"
]
| Finds the subscription associated with a token and removes or suspends is. If the subscription associated with a token cannot be found then this returns false. This usually means that the token was already removed. | [
"Finds",
"the",
"subscription",
"associated",
"with",
"a",
"token",
"and",
"removes",
"or",
"suspends",
"is",
".",
"If",
"the",
"subscription",
"associated",
"with",
"a",
"token",
"cannot",
"be",
"found",
"then",
"this",
"returns",
"false",
".",
"This",
"usually",
"means",
"that",
"the",
"token",
"was",
"already",
"removed",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L685-L717 |
47,374 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | addTopicLine | function addTopicLine (topic, ancestor) {
var
ancestorTopic = ancestor.topic,
additionalTopics = [];
if (ancestorTopic !== topic) {
// All of the generations to add seeded by the youngest existing ancestor
additionalTopics = reduce(
appendPrefixedTopic, [ancestorTopic],
topic.substr(ancestorTopic.length).replace(/^\./, '').split('.')
);
}
// Add a node to the tree for each new topic
return addFamilyLine(
addChildTopic, map(createNode, additionalTopics.slice(1)), ancestor
);
} | javascript | function addTopicLine (topic, ancestor) {
var
ancestorTopic = ancestor.topic,
additionalTopics = [];
if (ancestorTopic !== topic) {
// All of the generations to add seeded by the youngest existing ancestor
additionalTopics = reduce(
appendPrefixedTopic, [ancestorTopic],
topic.substr(ancestorTopic.length).replace(/^\./, '').split('.')
);
}
// Add a node to the tree for each new topic
return addFamilyLine(
addChildTopic, map(createNode, additionalTopics.slice(1)), ancestor
);
} | [
"function",
"addTopicLine",
"(",
"topic",
",",
"ancestor",
")",
"{",
"var",
"ancestorTopic",
"=",
"ancestor",
".",
"topic",
",",
"additionalTopics",
"=",
"[",
"]",
";",
"if",
"(",
"ancestorTopic",
"!==",
"topic",
")",
"{",
"// All of the generations to add seeded by the youngest existing ancestor",
"additionalTopics",
"=",
"reduce",
"(",
"appendPrefixedTopic",
",",
"[",
"ancestorTopic",
"]",
",",
"topic",
".",
"substr",
"(",
"ancestorTopic",
".",
"length",
")",
".",
"replace",
"(",
"/",
"^\\.",
"/",
",",
"''",
")",
".",
"split",
"(",
"'.'",
")",
")",
";",
"}",
"// Add a node to the tree for each new topic",
"return",
"addFamilyLine",
"(",
"addChildTopic",
",",
"map",
"(",
"createNode",
",",
"additionalTopics",
".",
"slice",
"(",
"1",
")",
")",
",",
"ancestor",
")",
";",
"}"
]
| Takes a topic and an ancestor and adds all of the generations from the ancestor to the topic returning the topic that represents the node. | [
"Takes",
"a",
"topic",
"and",
"an",
"ancestor",
"and",
"adds",
"all",
"of",
"the",
"generations",
"from",
"the",
"ancestor",
"to",
"the",
"topic",
"returning",
"the",
"topic",
"that",
"represents",
"the",
"node",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L726-L743 |
47,375 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | isAncestorTopic | function isAncestorTopic (topic, node) {
var nodeTopic = getTopic(node);
return topic === nodeTopic
|| startsWith(topic, nodeTopic + '.')
|| nodeTopic === '';
} | javascript | function isAncestorTopic (topic, node) {
var nodeTopic = getTopic(node);
return topic === nodeTopic
|| startsWith(topic, nodeTopic + '.')
|| nodeTopic === '';
} | [
"function",
"isAncestorTopic",
"(",
"topic",
",",
"node",
")",
"{",
"var",
"nodeTopic",
"=",
"getTopic",
"(",
"node",
")",
";",
"return",
"topic",
"===",
"nodeTopic",
"||",
"startsWith",
"(",
"topic",
",",
"nodeTopic",
"+",
"'.'",
")",
"||",
"nodeTopic",
"===",
"''",
";",
"}"
]
| Finds the Ancestor of the specified topic or undefined | [
"Finds",
"the",
"Ancestor",
"of",
"the",
"specified",
"topic",
"or",
"undefined"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L764-L770 |
47,376 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | getFingerArrayOrder | function getFingerArrayOrder (fingerArray) {
var item = getPointedFinger(fingerArray);
return item !== SYMBOL_NOTHING ? getOrder(item) : Infinity;
} | javascript | function getFingerArrayOrder (fingerArray) {
var item = getPointedFinger(fingerArray);
return item !== SYMBOL_NOTHING ? getOrder(item) : Infinity;
} | [
"function",
"getFingerArrayOrder",
"(",
"fingerArray",
")",
"{",
"var",
"item",
"=",
"getPointedFinger",
"(",
"fingerArray",
")",
";",
"return",
"item",
"!==",
"SYMBOL_NOTHING",
"?",
"getOrder",
"(",
"item",
")",
":",
"Infinity",
";",
"}"
]
| Given a fingerArray, return the order of current item | [
"Given",
"a",
"fingerArray",
"return",
"the",
"order",
"of",
"current",
"item"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L773-L776 |
47,377 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | getFingerArrayPriority | function getFingerArrayPriority (fingerArray) {
var item = getPointedFinger(fingerArray);
return item !== SYMBOL_NOTHING ? getPriority(item) : Infinity;
} | javascript | function getFingerArrayPriority (fingerArray) {
var item = getPointedFinger(fingerArray);
return item !== SYMBOL_NOTHING ? getPriority(item) : Infinity;
} | [
"function",
"getFingerArrayPriority",
"(",
"fingerArray",
")",
"{",
"var",
"item",
"=",
"getPointedFinger",
"(",
"fingerArray",
")",
";",
"return",
"item",
"!==",
"SYMBOL_NOTHING",
"?",
"getPriority",
"(",
"item",
")",
":",
"Infinity",
";",
"}"
]
| Given a fingerArray, return the priority of current item | [
"Given",
"a",
"fingerArray",
"return",
"the",
"priority",
"of",
"current",
"item"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L779-L782 |
47,378 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | createResolver | function createResolver () {
var
resolver = {
settled: false,
fulfilledValues: [],
rejectedValues: []
},
promise = new Promise(function promiseResolver (fulfill, reject) {
resolver.fulfill = fulfill;
resolver.reject = reject;
});
promise.fulfilled = 0;
promise.rejected = 0;
promise.pending = 0;
resolver.promise = promise;
return resolver;
} | javascript | function createResolver () {
var
resolver = {
settled: false,
fulfilledValues: [],
rejectedValues: []
},
promise = new Promise(function promiseResolver (fulfill, reject) {
resolver.fulfill = fulfill;
resolver.reject = reject;
});
promise.fulfilled = 0;
promise.rejected = 0;
promise.pending = 0;
resolver.promise = promise;
return resolver;
} | [
"function",
"createResolver",
"(",
")",
"{",
"var",
"resolver",
"=",
"{",
"settled",
":",
"false",
",",
"fulfilledValues",
":",
"[",
"]",
",",
"rejectedValues",
":",
"[",
"]",
"}",
",",
"promise",
"=",
"new",
"Promise",
"(",
"function",
"promiseResolver",
"(",
"fulfill",
",",
"reject",
")",
"{",
"resolver",
".",
"fulfill",
"=",
"fulfill",
";",
"resolver",
".",
"reject",
"=",
"reject",
";",
"}",
")",
";",
"promise",
".",
"fulfilled",
"=",
"0",
";",
"promise",
".",
"rejected",
"=",
"0",
";",
"promise",
".",
"pending",
"=",
"0",
";",
"resolver",
".",
"promise",
"=",
"promise",
";",
"return",
"resolver",
";",
"}"
]
| Creates a resolver object that keeps track of promise related values | [
"Creates",
"a",
"resolver",
"object",
"that",
"keeps",
"track",
"of",
"promise",
"related",
"values"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L837-L855 |
47,379 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | createSubscription | function createSubscription (state, fn, options, context) {
return {
id: state.id(),
fn: typeof fn === 'function' ? fn : noop,
suspended: false,
priority: +options.priority || 0,
context: context || null
};
} | javascript | function createSubscription (state, fn, options, context) {
return {
id: state.id(),
fn: typeof fn === 'function' ? fn : noop,
suspended: false,
priority: +options.priority || 0,
context: context || null
};
} | [
"function",
"createSubscription",
"(",
"state",
",",
"fn",
",",
"options",
",",
"context",
")",
"{",
"return",
"{",
"id",
":",
"state",
".",
"id",
"(",
")",
",",
"fn",
":",
"typeof",
"fn",
"===",
"'function'",
"?",
"fn",
":",
"noop",
",",
"suspended",
":",
"false",
",",
"priority",
":",
"+",
"options",
".",
"priority",
"||",
"0",
",",
"context",
":",
"context",
"||",
"null",
"}",
";",
"}"
]
| Creates a subscription object | [
"Creates",
"a",
"subscription",
"object"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L858-L866 |
47,380 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | addChild | function addChild (getValue, newChild, tree) {
tree.children.splice(
binaryIndexBy(getValue, getValue(newChild), tree.children),
0, newChild
);
return newChild;
} | javascript | function addChild (getValue, newChild, tree) {
tree.children.splice(
binaryIndexBy(getValue, getValue(newChild), tree.children),
0, newChild
);
return newChild;
} | [
"function",
"addChild",
"(",
"getValue",
",",
"newChild",
",",
"tree",
")",
"{",
"tree",
".",
"children",
".",
"splice",
"(",
"binaryIndexBy",
"(",
"getValue",
",",
"getValue",
"(",
"newChild",
")",
",",
"tree",
".",
"children",
")",
",",
"0",
",",
"newChild",
")",
";",
"return",
"newChild",
";",
"}"
]
| Adds a node child into the tree in order according to `getValue` | [
"Adds",
"a",
"node",
"child",
"into",
"the",
"tree",
"in",
"order",
"according",
"to",
"getValue"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L937-L944 |
47,381 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | insert | function insert (getValue, item, list) {
var index = binaryIndexBy(getValue, getValue(item), list);
list.splice(index, 0, item);
return item;
} | javascript | function insert (getValue, item, list) {
var index = binaryIndexBy(getValue, getValue(item), list);
list.splice(index, 0, item);
return item;
} | [
"function",
"insert",
"(",
"getValue",
",",
"item",
",",
"list",
")",
"{",
"var",
"index",
"=",
"binaryIndexBy",
"(",
"getValue",
",",
"getValue",
"(",
"item",
")",
",",
"list",
")",
";",
"list",
".",
"splice",
"(",
"index",
",",
"0",
",",
"item",
")",
";",
"return",
"item",
";",
"}"
]
| Inserts an item in ascending order according to `getValue`. | [
"Inserts",
"an",
"item",
"in",
"ascending",
"order",
"according",
"to",
"getValue",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L968-L973 |
47,382 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | minBy | function minBy (valueComputer, list) {
var
idx = 0,
winner = list[idx],
computedWinner = valueComputer(winner),
computedCurrent;
while (++idx < list.length) {
computedCurrent = valueComputer(list[idx]);
if (computedCurrent < computedWinner) {
computedWinner = computedCurrent;
winner = list[idx];
}
}
return winner;
} | javascript | function minBy (valueComputer, list) {
var
idx = 0,
winner = list[idx],
computedWinner = valueComputer(winner),
computedCurrent;
while (++idx < list.length) {
computedCurrent = valueComputer(list[idx]);
if (computedCurrent < computedWinner) {
computedWinner = computedCurrent;
winner = list[idx];
}
}
return winner;
} | [
"function",
"minBy",
"(",
"valueComputer",
",",
"list",
")",
"{",
"var",
"idx",
"=",
"0",
",",
"winner",
"=",
"list",
"[",
"idx",
"]",
",",
"computedWinner",
"=",
"valueComputer",
"(",
"winner",
")",
",",
"computedCurrent",
";",
"while",
"(",
"++",
"idx",
"<",
"list",
".",
"length",
")",
"{",
"computedCurrent",
"=",
"valueComputer",
"(",
"list",
"[",
"idx",
"]",
")",
";",
"if",
"(",
"computedCurrent",
"<",
"computedWinner",
")",
"{",
"computedWinner",
"=",
"computedCurrent",
";",
"winner",
"=",
"list",
"[",
"idx",
"]",
";",
"}",
"}",
"return",
"winner",
";",
"}"
]
| Finds the `minimum` element of an array according to the `valueComputer` function. | [
"Finds",
"the",
"minimum",
"element",
"of",
"an",
"array",
"according",
"to",
"the",
"valueComputer",
"function",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1035-L1053 |
47,383 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | getPointedFinger | function getPointedFinger (fArray) {
var
pointer = fArray.pointer,
array = fArray.array;
return array.length > pointer ? array[pointer] : SYMBOL_NOTHING;
} | javascript | function getPointedFinger (fArray) {
var
pointer = fArray.pointer,
array = fArray.array;
return array.length > pointer ? array[pointer] : SYMBOL_NOTHING;
} | [
"function",
"getPointedFinger",
"(",
"fArray",
")",
"{",
"var",
"pointer",
"=",
"fArray",
".",
"pointer",
",",
"array",
"=",
"fArray",
".",
"array",
";",
"return",
"array",
".",
"length",
">",
"pointer",
"?",
"array",
"[",
"pointer",
"]",
":",
"SYMBOL_NOTHING",
";",
"}"
]
| Retrieves the element that is the current focus and apply a | [
"Retrieves",
"the",
"element",
"that",
"is",
"the",
"current",
"focus",
"and",
"apply",
"a"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1056-L1062 |
47,384 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | partial1 | function partial1 (f, x) {
return function partiallyApplied1 () {
// Using slice or splice on `arguments` causes the function to be
// unoptimizable. Who doesn't like optimization?
var args = map(identity, arguments);
args.unshift(x);
return f.apply(null, args);
};
} | javascript | function partial1 (f, x) {
return function partiallyApplied1 () {
// Using slice or splice on `arguments` causes the function to be
// unoptimizable. Who doesn't like optimization?
var args = map(identity, arguments);
args.unshift(x);
return f.apply(null, args);
};
} | [
"function",
"partial1",
"(",
"f",
",",
"x",
")",
"{",
"return",
"function",
"partiallyApplied1",
"(",
")",
"{",
"// Using slice or splice on `arguments` causes the function to be",
"// unoptimizable. Who doesn't like optimization?",
"var",
"args",
"=",
"map",
"(",
"identity",
",",
"arguments",
")",
";",
"args",
".",
"unshift",
"(",
"x",
")",
";",
"return",
"f",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}",
";",
"}"
]
| Partially applies 1 argument to a function. | [
"Partially",
"applies",
"1",
"argument",
"to",
"a",
"function",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1102-L1111 |
47,385 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | merge | function merge (a, b) {
var result = {};
var x;
for (x in a) {
if (a.hasOwnProperty(x)) {
result[x] = a[x];
}
}
for (x in b) {
if (b.hasOwnProperty(x)) {
result[x] = b[x];
}
}
return result;
} | javascript | function merge (a, b) {
var result = {};
var x;
for (x in a) {
if (a.hasOwnProperty(x)) {
result[x] = a[x];
}
}
for (x in b) {
if (b.hasOwnProperty(x)) {
result[x] = b[x];
}
}
return result;
} | [
"function",
"merge",
"(",
"a",
",",
"b",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"var",
"x",
";",
"for",
"(",
"x",
"in",
"a",
")",
"{",
"if",
"(",
"a",
".",
"hasOwnProperty",
"(",
"x",
")",
")",
"{",
"result",
"[",
"x",
"]",
"=",
"a",
"[",
"x",
"]",
";",
"}",
"}",
"for",
"(",
"x",
"in",
"b",
")",
"{",
"if",
"(",
"b",
".",
"hasOwnProperty",
"(",
"x",
")",
")",
"{",
"result",
"[",
"x",
"]",
"=",
"b",
"[",
"x",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Returns a new object will all the properties of `a` and `b` giving b the priority. | [
"Returns",
"a",
"new",
"object",
"will",
"all",
"the",
"properties",
"of",
"a",
"and",
"b",
"giving",
"b",
"the",
"priority",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1115-L1132 |
47,386 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | reduce | function reduce (f, seed, arr) {
var result = seed, i, n;
for (i = 0, n = arr.length; i < n; i++) {
result = f(result, arr[i]);
}
return result;
} | javascript | function reduce (f, seed, arr) {
var result = seed, i, n;
for (i = 0, n = arr.length; i < n; i++) {
result = f(result, arr[i]);
}
return result;
} | [
"function",
"reduce",
"(",
"f",
",",
"seed",
",",
"arr",
")",
"{",
"var",
"result",
"=",
"seed",
",",
"i",
",",
"n",
";",
"for",
"(",
"i",
"=",
"0",
",",
"n",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"result",
"=",
"f",
"(",
"result",
",",
"arr",
"[",
"i",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Array.prototype.reduce has similar performance to Array.prototype.map, so we define a custom reduce function to increase performance | [
"Array",
".",
"prototype",
".",
"reduce",
"has",
"similar",
"performance",
"to",
"Array",
".",
"prototype",
".",
"map",
"so",
"we",
"define",
"a",
"custom",
"reduce",
"function",
"to",
"increase",
"performance"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1136-L1142 |
47,387 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | curryMap | function curryMap (args, f, arr) {
var result = [], i, n;
for (i = 0, n = arr.length; i < n; i++) {
result.push(f(args, arr[i]));
}
return result;
} | javascript | function curryMap (args, f, arr) {
var result = [], i, n;
for (i = 0, n = arr.length; i < n; i++) {
result.push(f(args, arr[i]));
}
return result;
} | [
"function",
"curryMap",
"(",
"args",
",",
"f",
",",
"arr",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"i",
",",
"n",
";",
"for",
"(",
"i",
"=",
"0",
",",
"n",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"result",
".",
"push",
"(",
"f",
"(",
"args",
",",
"arr",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| A special version of map to get around the performance hit for creating closures as a form of currying | [
"A",
"special",
"version",
"of",
"map",
"to",
"get",
"around",
"the",
"performance",
"hit",
"for",
"creating",
"closures",
"as",
"a",
"form",
"of",
"currying"
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1146-L1152 |
47,388 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | map | function map (f, arr) {
var result = [], i, n;
for (i = 0, n = arr.length; i < n; i++) {
result.push(f(arr[i]));
}
return result;
} | javascript | function map (f, arr) {
var result = [], i, n;
for (i = 0, n = arr.length; i < n; i++) {
result.push(f(arr[i]));
}
return result;
} | [
"function",
"map",
"(",
"f",
",",
"arr",
")",
"{",
"var",
"result",
"=",
"[",
"]",
",",
"i",
",",
"n",
";",
"for",
"(",
"i",
"=",
"0",
",",
"n",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"result",
".",
"push",
"(",
"f",
"(",
"arr",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Array.prototype.map is supeeeeer slow. In fact, it is slower than a custom map function, which is usually slower than an inline for loop, but is more maintainable. | [
"Array",
".",
"prototype",
".",
"map",
"is",
"supeeeeer",
"slow",
".",
"In",
"fact",
"it",
"is",
"slower",
"than",
"a",
"custom",
"map",
"function",
"which",
"is",
"usually",
"slower",
"than",
"an",
"inline",
"for",
"loop",
"but",
"is",
"more",
"maintainable",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1157-L1163 |
47,389 | taylor1791/promissory-arbiter | src/promissory-arbiter.js | startsWith | function startsWith (haystack, needle, startPosition) {
startPosition = startPosition || 0;
return haystack.lastIndexOf(needle, startPosition) === startPosition;
} | javascript | function startsWith (haystack, needle, startPosition) {
startPosition = startPosition || 0;
return haystack.lastIndexOf(needle, startPosition) === startPosition;
} | [
"function",
"startsWith",
"(",
"haystack",
",",
"needle",
",",
"startPosition",
")",
"{",
"startPosition",
"=",
"startPosition",
"||",
"0",
";",
"return",
"haystack",
".",
"lastIndexOf",
"(",
"needle",
",",
"startPosition",
")",
"===",
"startPosition",
";",
"}"
]
| Determines whether a string begins with the characters of another string, returning true or false as appropriate. | [
"Determines",
"whether",
"a",
"string",
"begins",
"with",
"the",
"characters",
"of",
"another",
"string",
"returning",
"true",
"or",
"false",
"as",
"appropriate",
"."
]
| 6327b87efd9ee997cbfaa009164dac266d9e16c2 | https://github.com/taylor1791/promissory-arbiter/blob/6327b87efd9ee997cbfaa009164dac266d9e16c2/src/promissory-arbiter.js#L1167-L1170 |
47,390 | DavideDaniel/npm-link-extra | lib/index.js | checkNpmVersion | function checkNpmVersion() {
return execa.shell('npm -v')
.then(({ stdout }) => stdout)
.then((v) => {
if (v && !(v.indexOf('3') === 0)) {
log('Use npm v3.10.10 for unobtrusive symlinks: npm i -g [email protected]');
}
});
} | javascript | function checkNpmVersion() {
return execa.shell('npm -v')
.then(({ stdout }) => stdout)
.then((v) => {
if (v && !(v.indexOf('3') === 0)) {
log('Use npm v3.10.10 for unobtrusive symlinks: npm i -g [email protected]');
}
});
} | [
"function",
"checkNpmVersion",
"(",
")",
"{",
"return",
"execa",
".",
"shell",
"(",
"'npm -v'",
")",
".",
"then",
"(",
"(",
"{",
"stdout",
"}",
")",
"=>",
"stdout",
")",
".",
"then",
"(",
"(",
"v",
")",
"=>",
"{",
"if",
"(",
"v",
"&&",
"!",
"(",
"v",
".",
"indexOf",
"(",
"'3'",
")",
"===",
"0",
")",
")",
"{",
"log",
"(",
"'Use npm v3.10.10 for unobtrusive symlinks: npm i -g [email protected]'",
")",
";",
"}",
"}",
")",
";",
"}"
]
| check npm version and show warning if needed | [
"check",
"npm",
"version",
"and",
"show",
"warning",
"if",
"needed"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L18-L26 |
47,391 | DavideDaniel/npm-link-extra | lib/index.js | linkPackages | function linkPackages(pathToPkgs) {
const pkgs = pathToPkgs.join(' ');
return execa
.shell(`npm link ${pkgs}`)
.then(() => log('Succesfully linked'));
} | javascript | function linkPackages(pathToPkgs) {
const pkgs = pathToPkgs.join(' ');
return execa
.shell(`npm link ${pkgs}`)
.then(() => log('Succesfully linked'));
} | [
"function",
"linkPackages",
"(",
"pathToPkgs",
")",
"{",
"const",
"pkgs",
"=",
"pathToPkgs",
".",
"join",
"(",
"' '",
")",
";",
"return",
"execa",
".",
"shell",
"(",
"`",
"${",
"pkgs",
"}",
"`",
")",
".",
"then",
"(",
"(",
")",
"=>",
"log",
"(",
"'Succesfully linked'",
")",
")",
";",
"}"
]
| Execa functions link packages | [
"Execa",
"functions",
"link",
"packages"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L84-L89 |
47,392 | DavideDaniel/npm-link-extra | lib/index.js | getSharedDepDirs | function getSharedDepDirs(pkgs, hash) {
return pkgs.map(({ name, dir }) => {
if (hash[name]) {
return dir;
}
return false;
}).filter(Boolean);
} | javascript | function getSharedDepDirs(pkgs, hash) {
return pkgs.map(({ name, dir }) => {
if (hash[name]) {
return dir;
}
return false;
}).filter(Boolean);
} | [
"function",
"getSharedDepDirs",
"(",
"pkgs",
",",
"hash",
")",
"{",
"return",
"pkgs",
".",
"map",
"(",
"(",
"{",
"name",
",",
"dir",
"}",
")",
"=>",
"{",
"if",
"(",
"hash",
"[",
"name",
"]",
")",
"{",
"return",
"dir",
";",
"}",
"return",
"false",
";",
"}",
")",
".",
"filter",
"(",
"Boolean",
")",
";",
"}"
]
| getSharedDepDirs selects an array of shared and linked packages
@param {Array} pkgs An array of dependencies
@param {Object} hash A hash map of our deps
@return {Array} A filtered list of shared pkg dirs | [
"getSharedDepDirs",
"selects",
"an",
"array",
"of",
"shared",
"and",
"linked",
"packages"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L117-L124 |
47,393 | DavideDaniel/npm-link-extra | lib/index.js | getSharedLinked | function getSharedLinked(pkgs, hash) {
return pkgs.map((name) => {
const module = hash[name];
if (module && module.isLinked) {
return name;
}
return false;
}).filter(Boolean);
} | javascript | function getSharedLinked(pkgs, hash) {
return pkgs.map((name) => {
const module = hash[name];
if (module && module.isLinked) {
return name;
}
return false;
}).filter(Boolean);
} | [
"function",
"getSharedLinked",
"(",
"pkgs",
",",
"hash",
")",
"{",
"return",
"pkgs",
".",
"map",
"(",
"(",
"name",
")",
"=>",
"{",
"const",
"module",
"=",
"hash",
"[",
"name",
"]",
";",
"if",
"(",
"module",
"&&",
"module",
".",
"isLinked",
")",
"{",
"return",
"name",
";",
"}",
"return",
"false",
";",
"}",
")",
".",
"filter",
"(",
"Boolean",
")",
";",
"}"
]
| getSharedLinked selects an array of shared and linked packages
@param {Array} pkgs An array of dependencies
@param {Object} hash A hash map of our deps
@return {Array} A filtered list of packages | [
"getSharedLinked",
"selects",
"an",
"array",
"of",
"shared",
"and",
"linked",
"packages"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L133-L141 |
47,394 | DavideDaniel/npm-link-extra | lib/index.js | getSharedDeps | function getSharedDeps(pkgs, hash) {
return pkgs.map(({ name }) => {
if (hash[name]) {
return name;
}
return false;
}).filter(Boolean);
} | javascript | function getSharedDeps(pkgs, hash) {
return pkgs.map(({ name }) => {
if (hash[name]) {
return name;
}
return false;
}).filter(Boolean);
} | [
"function",
"getSharedDeps",
"(",
"pkgs",
",",
"hash",
")",
"{",
"return",
"pkgs",
".",
"map",
"(",
"(",
"{",
"name",
"}",
")",
"=>",
"{",
"if",
"(",
"hash",
"[",
"name",
"]",
")",
"{",
"return",
"name",
";",
"}",
"return",
"false",
";",
"}",
")",
".",
"filter",
"(",
"Boolean",
")",
";",
"}"
]
| getSharedDeps will show any shared dependencies between project & target dir
@param {Array} pkgs An array of dependencies
@param {Object} hash A hash map of our deps
@return {Array} Array of shared dep names | [
"getSharedDeps",
"will",
"show",
"any",
"shared",
"dependencies",
"between",
"project",
"&",
"target",
"dir"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L149-L156 |
47,395 | DavideDaniel/npm-link-extra | lib/index.js | getLinkedDeps | function getLinkedDeps(pkgs) {
return pkgs.map((name) => {
const isLinked = checkForLink(name);
return isLinked ? name : false;
}).filter(Boolean);
} | javascript | function getLinkedDeps(pkgs) {
return pkgs.map((name) => {
const isLinked = checkForLink(name);
return isLinked ? name : false;
}).filter(Boolean);
} | [
"function",
"getLinkedDeps",
"(",
"pkgs",
")",
"{",
"return",
"pkgs",
".",
"map",
"(",
"(",
"name",
")",
"=>",
"{",
"const",
"isLinked",
"=",
"checkForLink",
"(",
"name",
")",
";",
"return",
"isLinked",
"?",
"name",
":",
"false",
";",
"}",
")",
".",
"filter",
"(",
"Boolean",
")",
";",
"}"
]
| getLinkedDeps returns a list of linked dependencies
@param {Array} pkgs An array of dependencies
@return {Array} Array of linked dep names | [
"getLinkedDeps",
"returns",
"a",
"list",
"of",
"linked",
"dependencies"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L163-L168 |
47,396 | DavideDaniel/npm-link-extra | lib/index.js | showLinkedDeps | function showLinkedDeps() {
const linkedDeps = getLinkedDeps(packageKeys, packageHash);
if (linkedDeps.length) {
logPkgsMsg('Linked', linkedDeps);
} else {
log('No linked dependencies found');
}
} | javascript | function showLinkedDeps() {
const linkedDeps = getLinkedDeps(packageKeys, packageHash);
if (linkedDeps.length) {
logPkgsMsg('Linked', linkedDeps);
} else {
log('No linked dependencies found');
}
} | [
"function",
"showLinkedDeps",
"(",
")",
"{",
"const",
"linkedDeps",
"=",
"getLinkedDeps",
"(",
"packageKeys",
",",
"packageHash",
")",
";",
"if",
"(",
"linkedDeps",
".",
"length",
")",
"{",
"logPkgsMsg",
"(",
"'Linked'",
",",
"linkedDeps",
")",
";",
"}",
"else",
"{",
"log",
"(",
"'No linked dependencies found'",
")",
";",
"}",
"}"
]
| show all linked dependencies in your node_modules | [
"show",
"all",
"linked",
"dependencies",
"in",
"your",
"node_modules"
]
| 049112dc145b4325052f4ddf0ceadfa1e206c154 | https://github.com/DavideDaniel/npm-link-extra/blob/049112dc145b4325052f4ddf0ceadfa1e206c154/lib/index.js#L203-L210 |
47,397 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/scayt/dialogs/options.js | function( option, list )
{
var label = doc.createElement( 'label' );
label.setAttribute( 'for', 'cke_option' + option );
label.setHtml( list[ option ] );
if ( dialog.sLang == option ) // Current.
dialog.chosed_lang = option;
var div = doc.createElement( 'div' );
var radio = CKEDITOR.dom.element.createFromHtml( '<input id="cke_option' +
option + '" type="radio" ' +
( dialog.sLang == option ? 'checked="checked"' : '' ) +
' value="' + option + '" name="scayt_lang" />' );
radio.on( 'click', function()
{
this.$.checked = true;
dialog.chosed_lang = option;
});
div.append( radio );
div.append( label );
return {
lang : list[ option ],
code : option,
radio : div
};
} | javascript | function( option, list )
{
var label = doc.createElement( 'label' );
label.setAttribute( 'for', 'cke_option' + option );
label.setHtml( list[ option ] );
if ( dialog.sLang == option ) // Current.
dialog.chosed_lang = option;
var div = doc.createElement( 'div' );
var radio = CKEDITOR.dom.element.createFromHtml( '<input id="cke_option' +
option + '" type="radio" ' +
( dialog.sLang == option ? 'checked="checked"' : '' ) +
' value="' + option + '" name="scayt_lang" />' );
radio.on( 'click', function()
{
this.$.checked = true;
dialog.chosed_lang = option;
});
div.append( radio );
div.append( label );
return {
lang : list[ option ],
code : option,
radio : div
};
} | [
"function",
"(",
"option",
",",
"list",
")",
"{",
"var",
"label",
"=",
"doc",
".",
"createElement",
"(",
"'label'",
")",
";",
"label",
".",
"setAttribute",
"(",
"'for'",
",",
"'cke_option'",
"+",
"option",
")",
";",
"label",
".",
"setHtml",
"(",
"list",
"[",
"option",
"]",
")",
";",
"if",
"(",
"dialog",
".",
"sLang",
"==",
"option",
")",
"// Current.\r",
"dialog",
".",
"chosed_lang",
"=",
"option",
";",
"var",
"div",
"=",
"doc",
".",
"createElement",
"(",
"'div'",
")",
";",
"var",
"radio",
"=",
"CKEDITOR",
".",
"dom",
".",
"element",
".",
"createFromHtml",
"(",
"'<input id=\"cke_option'",
"+",
"option",
"+",
"'\" type=\"radio\" '",
"+",
"(",
"dialog",
".",
"sLang",
"==",
"option",
"?",
"'checked=\"checked\"'",
":",
"''",
")",
"+",
"' value=\"'",
"+",
"option",
"+",
"'\" name=\"scayt_lang\" />'",
")",
";",
"radio",
".",
"on",
"(",
"'click'",
",",
"function",
"(",
")",
"{",
"this",
".",
"$",
".",
"checked",
"=",
"true",
";",
"dialog",
".",
"chosed_lang",
"=",
"option",
";",
"}",
")",
";",
"div",
".",
"append",
"(",
"radio",
")",
";",
"div",
".",
"append",
"(",
"label",
")",
";",
"return",
"{",
"lang",
":",
"list",
"[",
"option",
"]",
",",
"code",
":",
"option",
",",
"radio",
":",
"div",
"}",
";",
"}"
]
| Create languages tab. | [
"Create",
"languages",
"tab",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/scayt/dialogs/options.js#L262-L291 |
|
47,398 | Kurento/kurento-module-pointerdetector-js | lib/complexTypes/PointerDetectorWindowMediaParam.js | PointerDetectorWindowMediaParam | function PointerDetectorWindowMediaParam(pointerDetectorWindowMediaParamDict){
if(!(this instanceof PointerDetectorWindowMediaParam))
return new PointerDetectorWindowMediaParam(pointerDetectorWindowMediaParamDict)
pointerDetectorWindowMediaParamDict = pointerDetectorWindowMediaParamDict || {}
// Check pointerDetectorWindowMediaParamDict has the required fields
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.id', pointerDetectorWindowMediaParamDict.id, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.height', pointerDetectorWindowMediaParamDict.height, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.width', pointerDetectorWindowMediaParamDict.width, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightX', pointerDetectorWindowMediaParamDict.upperRightX, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightY', pointerDetectorWindowMediaParamDict.upperRightY, {required: true});
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.activeImage', pointerDetectorWindowMediaParamDict.activeImage);
//
// checkType('float', 'pointerDetectorWindowMediaParamDict.imageTransparency', pointerDetectorWindowMediaParamDict.imageTransparency);
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.image', pointerDetectorWindowMediaParamDict.image);
//
// Init parent class
PointerDetectorWindowMediaParam.super_.call(this, pointerDetectorWindowMediaParamDict)
// Set object properties
Object.defineProperties(this, {
id: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.id
},
height: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.height
},
width: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.width
},
upperRightX: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.upperRightX
},
upperRightY: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.upperRightY
},
activeImage: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.activeImage
},
imageTransparency: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.imageTransparency
},
image: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.image
}
})
} | javascript | function PointerDetectorWindowMediaParam(pointerDetectorWindowMediaParamDict){
if(!(this instanceof PointerDetectorWindowMediaParam))
return new PointerDetectorWindowMediaParam(pointerDetectorWindowMediaParamDict)
pointerDetectorWindowMediaParamDict = pointerDetectorWindowMediaParamDict || {}
// Check pointerDetectorWindowMediaParamDict has the required fields
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.id', pointerDetectorWindowMediaParamDict.id, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.height', pointerDetectorWindowMediaParamDict.height, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.width', pointerDetectorWindowMediaParamDict.width, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightX', pointerDetectorWindowMediaParamDict.upperRightX, {required: true});
//
// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightY', pointerDetectorWindowMediaParamDict.upperRightY, {required: true});
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.activeImage', pointerDetectorWindowMediaParamDict.activeImage);
//
// checkType('float', 'pointerDetectorWindowMediaParamDict.imageTransparency', pointerDetectorWindowMediaParamDict.imageTransparency);
//
// checkType('String', 'pointerDetectorWindowMediaParamDict.image', pointerDetectorWindowMediaParamDict.image);
//
// Init parent class
PointerDetectorWindowMediaParam.super_.call(this, pointerDetectorWindowMediaParamDict)
// Set object properties
Object.defineProperties(this, {
id: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.id
},
height: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.height
},
width: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.width
},
upperRightX: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.upperRightX
},
upperRightY: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.upperRightY
},
activeImage: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.activeImage
},
imageTransparency: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.imageTransparency
},
image: {
writable: true,
enumerable: true,
value: pointerDetectorWindowMediaParamDict.image
}
})
} | [
"function",
"PointerDetectorWindowMediaParam",
"(",
"pointerDetectorWindowMediaParamDict",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"PointerDetectorWindowMediaParam",
")",
")",
"return",
"new",
"PointerDetectorWindowMediaParam",
"(",
"pointerDetectorWindowMediaParamDict",
")",
"pointerDetectorWindowMediaParamDict",
"=",
"pointerDetectorWindowMediaParamDict",
"||",
"{",
"}",
"// Check pointerDetectorWindowMediaParamDict has the required fields",
"// ",
"// checkType('String', 'pointerDetectorWindowMediaParamDict.id', pointerDetectorWindowMediaParamDict.id, {required: true});",
"// ",
"// checkType('int', 'pointerDetectorWindowMediaParamDict.height', pointerDetectorWindowMediaParamDict.height, {required: true});",
"// ",
"// checkType('int', 'pointerDetectorWindowMediaParamDict.width', pointerDetectorWindowMediaParamDict.width, {required: true});",
"// ",
"// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightX', pointerDetectorWindowMediaParamDict.upperRightX, {required: true});",
"// ",
"// checkType('int', 'pointerDetectorWindowMediaParamDict.upperRightY', pointerDetectorWindowMediaParamDict.upperRightY, {required: true});",
"// ",
"// checkType('String', 'pointerDetectorWindowMediaParamDict.activeImage', pointerDetectorWindowMediaParamDict.activeImage);",
"// ",
"// checkType('float', 'pointerDetectorWindowMediaParamDict.imageTransparency', pointerDetectorWindowMediaParamDict.imageTransparency);",
"// ",
"// checkType('String', 'pointerDetectorWindowMediaParamDict.image', pointerDetectorWindowMediaParamDict.image);",
"// ",
"// Init parent class",
"PointerDetectorWindowMediaParam",
".",
"super_",
".",
"call",
"(",
"this",
",",
"pointerDetectorWindowMediaParamDict",
")",
"// Set object properties",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"id",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"id",
"}",
",",
"height",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"height",
"}",
",",
"width",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"width",
"}",
",",
"upperRightX",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"upperRightX",
"}",
",",
"upperRightY",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"upperRightY",
"}",
",",
"activeImage",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"activeImage",
"}",
",",
"imageTransparency",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"imageTransparency",
"}",
",",
"image",
":",
"{",
"writable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"value",
":",
"pointerDetectorWindowMediaParamDict",
".",
"image",
"}",
"}",
")",
"}"
]
| Data structure for UI Pointer detection in video streams.
All the coordinates are in pixels. X is horizontal, Y is vertical, running
from the top of the window. Thus, 0,0 corresponds to the topleft corner.
@constructor module:pointerdetector/complexTypes.PointerDetectorWindowMediaParam
@property {external:String} id
id of the window for pointer detection
@property {external:Integer} height
height in pixels
@property {external:Integer} width
width in pixels
@property {external:Integer} upperRightX
X coordinate in pixels of the upper left corner
@property {external:Integer} upperRightY
Y coordinate in pixels of the upper left corner
@property {external:String} activeImage
uri of the image to be used when the pointer is inside the window
@property {external:Number} imageTransparency
transparency ratio of the image
@property {external:String} image
uri of the image to be used for the window.
If {@link
module:pointerdetector/complexTypes.PointerDetectorWindowMediaParam#activeImage} | [
"Data",
"structure",
"for",
"UI",
"Pointer",
"detection",
"in",
"video",
"streams",
".",
"All",
"the",
"coordinates",
"are",
"in",
"pixels",
".",
"X",
"is",
"horizontal",
"Y",
"is",
"vertical",
"running",
"from",
"the",
"top",
"of",
"the",
"window",
".",
"Thus",
"0",
"0",
"corresponds",
"to",
"the",
"topleft",
"corner",
"."
]
| b5bce99fcd7087f12d14c39584edd6093099437e | https://github.com/Kurento/kurento-module-pointerdetector-js/blob/b5bce99fcd7087f12d14c39584edd6093099437e/lib/complexTypes/PointerDetectorWindowMediaParam.js#L55-L126 |
47,399 | ohager/stappo | gulpfile.js | renderTemplate | function renderTemplate(impl, targetFile){
var stappoImpl = fs.readFileSync(impl, "utf8");
return gulp.src([targetFile])
.pipe(replace('/*__stappo_impl__*/', stappoImpl));
} | javascript | function renderTemplate(impl, targetFile){
var stappoImpl = fs.readFileSync(impl, "utf8");
return gulp.src([targetFile])
.pipe(replace('/*__stappo_impl__*/', stappoImpl));
} | [
"function",
"renderTemplate",
"(",
"impl",
",",
"targetFile",
")",
"{",
"var",
"stappoImpl",
"=",
"fs",
".",
"readFileSync",
"(",
"impl",
",",
"\"utf8\"",
")",
";",
"return",
"gulp",
".",
"src",
"(",
"[",
"targetFile",
"]",
")",
".",
"pipe",
"(",
"replace",
"(",
"'/*__stappo_impl__*/'",
",",
"stappoImpl",
")",
")",
";",
"}"
]
| web-only implementation | [
"web",
"-",
"only",
"implementation"
]
| 1e89154e003d99975eeb1ee6ab0d456aea58b7d1 | https://github.com/ohager/stappo/blob/1e89154e003d99975eeb1ee6ab0d456aea58b7d1/gulpfile.js#L17-L21 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.