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
|
---|---|---|---|---|---|---|---|---|---|---|---|
49,100 | westtrade/waterlock-vkontakte-auth | lib/vkoauth2.js | VKOAuth2 | function VKOAuth2(appId, appSecret, redirectURL, fullSettings) {
this._appId = appId;
this._appSecret = appSecret;
this._redirectURL = redirectURL;
fullSettings = fullSettings || {};
this._vkOpts = fullSettings.settings || {};
this._apiVersion = this._vkOpts.version || '5.41';
this._dialogOptions = this._vkOpts.dialog || {};
this._fields = fullSettings.fieldMap ? _.values(fullSettings.fieldMap) : [];
this._fields = _.unique(this._fields.concat(['uid', 'first_name', 'last_name', 'screen_name']));
this._authURL = 'https://oauth.vk.com/authorize';
this._accessTokenURI = 'https://oauth.vk.com/access_token';
this._profileURI = 'https://api.vk.com/method/users.get';
} | javascript | function VKOAuth2(appId, appSecret, redirectURL, fullSettings) {
this._appId = appId;
this._appSecret = appSecret;
this._redirectURL = redirectURL;
fullSettings = fullSettings || {};
this._vkOpts = fullSettings.settings || {};
this._apiVersion = this._vkOpts.version || '5.41';
this._dialogOptions = this._vkOpts.dialog || {};
this._fields = fullSettings.fieldMap ? _.values(fullSettings.fieldMap) : [];
this._fields = _.unique(this._fields.concat(['uid', 'first_name', 'last_name', 'screen_name']));
this._authURL = 'https://oauth.vk.com/authorize';
this._accessTokenURI = 'https://oauth.vk.com/access_token';
this._profileURI = 'https://api.vk.com/method/users.get';
} | [
"function",
"VKOAuth2",
"(",
"appId",
",",
"appSecret",
",",
"redirectURL",
",",
"fullSettings",
")",
"{",
"this",
".",
"_appId",
"=",
"appId",
";",
"this",
".",
"_appSecret",
"=",
"appSecret",
";",
"this",
".",
"_redirectURL",
"=",
"redirectURL",
";",
"fullSettings",
"=",
"fullSettings",
"||",
"{",
"}",
";",
"this",
".",
"_vkOpts",
"=",
"fullSettings",
".",
"settings",
"||",
"{",
"}",
";",
"this",
".",
"_apiVersion",
"=",
"this",
".",
"_vkOpts",
".",
"version",
"||",
"'5.41'",
";",
"this",
".",
"_dialogOptions",
"=",
"this",
".",
"_vkOpts",
".",
"dialog",
"||",
"{",
"}",
";",
"this",
".",
"_fields",
"=",
"fullSettings",
".",
"fieldMap",
"?",
"_",
".",
"values",
"(",
"fullSettings",
".",
"fieldMap",
")",
":",
"[",
"]",
";",
"this",
".",
"_fields",
"=",
"_",
".",
"unique",
"(",
"this",
".",
"_fields",
".",
"concat",
"(",
"[",
"'uid'",
",",
"'first_name'",
",",
"'last_name'",
",",
"'screen_name'",
"]",
")",
")",
";",
"this",
".",
"_authURL",
"=",
"'https://oauth.vk.com/authorize'",
";",
"this",
".",
"_accessTokenURI",
"=",
"'https://oauth.vk.com/access_token'",
";",
"this",
".",
"_profileURI",
"=",
"'https://api.vk.com/method/users.get'",
";",
"}"
] | vkontakte OAuth2 object, make various requests
the graphAPI
@param {string} appId the vkontakte app id
@param {string} appSecret the vkontakte app secret
@param {string} redirectURL the url vkontakte should use as a callback | [
"vkontakte",
"OAuth2",
"object",
"make",
"various",
"requests",
"the",
"graphAPI"
] | 7723740bf9d6df369918d9a9a17953b10e17fd01 | https://github.com/westtrade/waterlock-vkontakte-auth/blob/7723740bf9d6df369918d9a9a17953b10e17fd01/lib/vkoauth2.js#L17-L37 |
49,101 | amida-tech/blue-button-pim | lib/scorer.js | score | function score(data, candidate) {
var result = 0;
/*
Scoring calculations here
*/
//Last Name
if (!data.name.last || !candidate.name.last) {
result = result + 0;
} else if (data.name.last.toUpperCase() === candidate.name.last.toUpperCase()) {
result = result + 9.58;
} else if (data.name.last.toUpperCase().substring(0, 3) === candidate.name.last.toUpperCase().substring(0, 3)) {
result = result + 5.18;
} else if (data.name.last.toUpperCase().substring(0, 3) !== candidate.name.last.toUpperCase().substring(0, 3)) {
result = result - 3.62;
}
//First Name
if (!data.name.first || !candidate.name.first) {
result = result + 0;
} else if (data.name.first.toUpperCase() === candidate.name.first.toUpperCase()) {
result = result + 6.69;
} else if (data.name.first.toUpperCase().substring(0, 3) === candidate.name.first.toUpperCase().substring(0, 3)) {
result = result + 3.37;
} else if (data.name.first.toUpperCase().substring(0, 3) !== candidate.name.first.toUpperCase().substring(0, 3)) {
result = result - 3.27;
}
//Middle Initial
if (!data.name.middle || !candidate.name.middle) {
result = result + 0;
} else if (data.name.middle.toUpperCase().substring(0, 1) === candidate.name.middle.toUpperCase().substring(0, 1)) {
result = result + 3.65;
}
//DOB
if (!data.dob || !candidate.dob) {
result = result + 0;
} else if (data.dob.substring(0, 10) === candidate.dob.substring(0, 10)) {
result = result + 6.22;
}
//Initials
result = result + 0;
return result;
} | javascript | function score(data, candidate) {
var result = 0;
/*
Scoring calculations here
*/
//Last Name
if (!data.name.last || !candidate.name.last) {
result = result + 0;
} else if (data.name.last.toUpperCase() === candidate.name.last.toUpperCase()) {
result = result + 9.58;
} else if (data.name.last.toUpperCase().substring(0, 3) === candidate.name.last.toUpperCase().substring(0, 3)) {
result = result + 5.18;
} else if (data.name.last.toUpperCase().substring(0, 3) !== candidate.name.last.toUpperCase().substring(0, 3)) {
result = result - 3.62;
}
//First Name
if (!data.name.first || !candidate.name.first) {
result = result + 0;
} else if (data.name.first.toUpperCase() === candidate.name.first.toUpperCase()) {
result = result + 6.69;
} else if (data.name.first.toUpperCase().substring(0, 3) === candidate.name.first.toUpperCase().substring(0, 3)) {
result = result + 3.37;
} else if (data.name.first.toUpperCase().substring(0, 3) !== candidate.name.first.toUpperCase().substring(0, 3)) {
result = result - 3.27;
}
//Middle Initial
if (!data.name.middle || !candidate.name.middle) {
result = result + 0;
} else if (data.name.middle.toUpperCase().substring(0, 1) === candidate.name.middle.toUpperCase().substring(0, 1)) {
result = result + 3.65;
}
//DOB
if (!data.dob || !candidate.dob) {
result = result + 0;
} else if (data.dob.substring(0, 10) === candidate.dob.substring(0, 10)) {
result = result + 6.22;
}
//Initials
result = result + 0;
return result;
} | [
"function",
"score",
"(",
"data",
",",
"candidate",
")",
"{",
"var",
"result",
"=",
"0",
";",
"/*\n Scoring calculations here\n */",
"//Last Name",
"if",
"(",
"!",
"data",
".",
"name",
".",
"last",
"||",
"!",
"candidate",
".",
"name",
".",
"last",
")",
"{",
"result",
"=",
"result",
"+",
"0",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
"===",
"candidate",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
")",
"{",
"result",
"=",
"result",
"+",
"9.58",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
"===",
"candidate",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
")",
"{",
"result",
"=",
"result",
"+",
"5.18",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
"!==",
"candidate",
".",
"name",
".",
"last",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
")",
"{",
"result",
"=",
"result",
"-",
"3.62",
";",
"}",
"//First Name",
"if",
"(",
"!",
"data",
".",
"name",
".",
"first",
"||",
"!",
"candidate",
".",
"name",
".",
"first",
")",
"{",
"result",
"=",
"result",
"+",
"0",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
"===",
"candidate",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
")",
"{",
"result",
"=",
"result",
"+",
"6.69",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
"===",
"candidate",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
")",
"{",
"result",
"=",
"result",
"+",
"3.37",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
"!==",
"candidate",
".",
"name",
".",
"first",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"3",
")",
")",
"{",
"result",
"=",
"result",
"-",
"3.27",
";",
"}",
"//Middle Initial",
"if",
"(",
"!",
"data",
".",
"name",
".",
"middle",
"||",
"!",
"candidate",
".",
"name",
".",
"middle",
")",
"{",
"result",
"=",
"result",
"+",
"0",
";",
"}",
"else",
"if",
"(",
"data",
".",
"name",
".",
"middle",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"1",
")",
"===",
"candidate",
".",
"name",
".",
"middle",
".",
"toUpperCase",
"(",
")",
".",
"substring",
"(",
"0",
",",
"1",
")",
")",
"{",
"result",
"=",
"result",
"+",
"3.65",
";",
"}",
"//DOB",
"if",
"(",
"!",
"data",
".",
"dob",
"||",
"!",
"candidate",
".",
"dob",
")",
"{",
"result",
"=",
"result",
"+",
"0",
";",
"}",
"else",
"if",
"(",
"data",
".",
"dob",
".",
"substring",
"(",
"0",
",",
"10",
")",
"===",
"candidate",
".",
"dob",
".",
"substring",
"(",
"0",
",",
"10",
")",
")",
"{",
"result",
"=",
"result",
"+",
"6.22",
";",
"}",
"//Initials",
"result",
"=",
"result",
"+",
"0",
";",
"return",
"result",
";",
"}"
] | scores match between candidate vs patient data | [
"scores",
"match",
"between",
"candidate",
"vs",
"patient",
"data"
] | 329dcc5fa5f3d877c2b675e8e0d689a8ef25a895 | https://github.com/amida-tech/blue-button-pim/blob/329dcc5fa5f3d877c2b675e8e0d689a8ef25a895/lib/scorer.js#L4-L50 |
49,102 | davidtucker/node-shutdown-manager | examples/example.js | function() {
var deferred = q.defer();
setTimeout(function() {
console.log("Async Action 1 Completed");
deferred.resolve();
}, 1000);
return deferred.promise;
} | javascript | function() {
var deferred = q.defer();
setTimeout(function() {
console.log("Async Action 1 Completed");
deferred.resolve();
}, 1000);
return deferred.promise;
} | [
"function",
"(",
")",
"{",
"var",
"deferred",
"=",
"q",
".",
"defer",
"(",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"\"Async Action 1 Completed\"",
")",
";",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
",",
"1000",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Adding Async Named Function | [
"Adding",
"Async",
"Named",
"Function"
] | 5106ba004f7351c4281d9f736de176126077e75a | https://github.com/davidtucker/node-shutdown-manager/blob/5106ba004f7351c4281d9f736de176126077e75a/examples/example.js#L22-L29 |
|
49,103 | Fullstop000/redux-sirius | src/index.js | createRootReducer | function createRootReducer (model, name) {
const handlers = {}
const initialState = model.state
// auto-generated reducers
if (isNotNullObject(initialState)) {
for (const key of Object.keys(initialState)) {
handlers[addSetPrefix(name)(key)] = (state, action) => includeKey(action, 'payload') ? { ...state, [key]: action.payload } : state
}
}
// reducer for updating multiple field of the state in one action
// or replace the state directly
handlers[addPrefix(name)('merge')] = (state, action) => {
if (!includeKey(action, 'payload')) {
return state
}
const payload = action.payload
if (isNotArrayObject(state)) {
// if (includeNewKeys(state, payload)) {
// return pureMerge(state, payload)
// } else {
// return { ...state, ...payload }
// }
return pureMerge(state, payload)
} else {
return payload
}
}
// user defined reducers
for (const r of Object.keys(model.reducers || {})) {
const reducer = model.reducers[r]
let finalReducer
if (typeof reducer === 'function') {
finalReducer = (state, action) => reducer(state, action)
} else {
finalReducer = (state) => state
}
// notice the reducer override occurs here
handlers[addPrefix(name)(r)] = finalReducer
}
return (state = initialState, action) => (handlers[action.type] ? handlers[action.type](state, action) : state)
} | javascript | function createRootReducer (model, name) {
const handlers = {}
const initialState = model.state
// auto-generated reducers
if (isNotNullObject(initialState)) {
for (const key of Object.keys(initialState)) {
handlers[addSetPrefix(name)(key)] = (state, action) => includeKey(action, 'payload') ? { ...state, [key]: action.payload } : state
}
}
// reducer for updating multiple field of the state in one action
// or replace the state directly
handlers[addPrefix(name)('merge')] = (state, action) => {
if (!includeKey(action, 'payload')) {
return state
}
const payload = action.payload
if (isNotArrayObject(state)) {
// if (includeNewKeys(state, payload)) {
// return pureMerge(state, payload)
// } else {
// return { ...state, ...payload }
// }
return pureMerge(state, payload)
} else {
return payload
}
}
// user defined reducers
for (const r of Object.keys(model.reducers || {})) {
const reducer = model.reducers[r]
let finalReducer
if (typeof reducer === 'function') {
finalReducer = (state, action) => reducer(state, action)
} else {
finalReducer = (state) => state
}
// notice the reducer override occurs here
handlers[addPrefix(name)(r)] = finalReducer
}
return (state = initialState, action) => (handlers[action.type] ? handlers[action.type](state, action) : state)
} | [
"function",
"createRootReducer",
"(",
"model",
",",
"name",
")",
"{",
"const",
"handlers",
"=",
"{",
"}",
"const",
"initialState",
"=",
"model",
".",
"state",
"// auto-generated reducers",
"if",
"(",
"isNotNullObject",
"(",
"initialState",
")",
")",
"{",
"for",
"(",
"const",
"key",
"of",
"Object",
".",
"keys",
"(",
"initialState",
")",
")",
"{",
"handlers",
"[",
"addSetPrefix",
"(",
"name",
")",
"(",
"key",
")",
"]",
"=",
"(",
"state",
",",
"action",
")",
"=>",
"includeKey",
"(",
"action",
",",
"'payload'",
")",
"?",
"{",
"...",
"state",
",",
"[",
"key",
"]",
":",
"action",
".",
"payload",
"}",
":",
"state",
"}",
"}",
"// reducer for updating multiple field of the state in one action",
"// or replace the state directly",
"handlers",
"[",
"addPrefix",
"(",
"name",
")",
"(",
"'merge'",
")",
"]",
"=",
"(",
"state",
",",
"action",
")",
"=>",
"{",
"if",
"(",
"!",
"includeKey",
"(",
"action",
",",
"'payload'",
")",
")",
"{",
"return",
"state",
"}",
"const",
"payload",
"=",
"action",
".",
"payload",
"if",
"(",
"isNotArrayObject",
"(",
"state",
")",
")",
"{",
"// if (includeNewKeys(state, payload)) {",
"// return pureMerge(state, payload)",
"// } else {",
"// return { ...state, ...payload }",
"// }",
"return",
"pureMerge",
"(",
"state",
",",
"payload",
")",
"}",
"else",
"{",
"return",
"payload",
"}",
"}",
"// user defined reducers",
"for",
"(",
"const",
"r",
"of",
"Object",
".",
"keys",
"(",
"model",
".",
"reducers",
"||",
"{",
"}",
")",
")",
"{",
"const",
"reducer",
"=",
"model",
".",
"reducers",
"[",
"r",
"]",
"let",
"finalReducer",
"if",
"(",
"typeof",
"reducer",
"===",
"'function'",
")",
"{",
"finalReducer",
"=",
"(",
"state",
",",
"action",
")",
"=>",
"reducer",
"(",
"state",
",",
"action",
")",
"}",
"else",
"{",
"finalReducer",
"=",
"(",
"state",
")",
"=>",
"state",
"}",
"// notice the reducer override occurs here",
"handlers",
"[",
"addPrefix",
"(",
"name",
")",
"(",
"r",
")",
"]",
"=",
"finalReducer",
"}",
"return",
"(",
"state",
"=",
"initialState",
",",
"action",
")",
"=>",
"(",
"handlers",
"[",
"action",
".",
"type",
"]",
"?",
"handlers",
"[",
"action",
".",
"type",
"]",
"(",
"state",
",",
"action",
")",
":",
"state",
")",
"}"
] | Create a root reducer based on model state and model reducers
If you have a model like the below
{
namespace: 'form',
state: {
loading: false,
password: ''
}
}
then sirius will generate a reducer for each state field following a preset rule:
for state loading : form/setLoading
for state password : form/setPassword
And a reducer receiving action whose type is '<namespace>/merge' (in the scenario above is 'form/merge')
will be generated.
If state is an Object (not Array, not null), action payload must be a 'sub-object' of the state
which means all the fields of payload can be also found in the state. the 'merge' reducer will
do a 'merge-like' action to the state just like Object Spreading.
If the state is not an Object, reducer replace the state with payload directly.
@param {Object} model model
@param {String} name model namespace
@returns {Function} combined reducer for the model | [
"Create",
"a",
"root",
"reducer",
"based",
"on",
"model",
"state",
"and",
"model",
"reducers"
] | 1337e7d3414879d5d5364db89d0e08f18f9ef984 | https://github.com/Fullstop000/redux-sirius/blob/1337e7d3414879d5d5364db89d0e08f18f9ef984/src/index.js#L241-L281 |
49,104 | Fullstop000/redux-sirius | src/index.js | getNamespace | function getNamespace (path, relative) {
// ignore parent path
let final = ''
if (relative) {
const s = path.split('/')
final = s[s.length - 1]
} else {
final = path.startsWith('./') ? path.slice(2) : path
}
// remove '.js'
return final.slice(0, final.length - 3)
} | javascript | function getNamespace (path, relative) {
// ignore parent path
let final = ''
if (relative) {
const s = path.split('/')
final = s[s.length - 1]
} else {
final = path.startsWith('./') ? path.slice(2) : path
}
// remove '.js'
return final.slice(0, final.length - 3)
} | [
"function",
"getNamespace",
"(",
"path",
",",
"relative",
")",
"{",
"// ignore parent path",
"let",
"final",
"=",
"''",
"if",
"(",
"relative",
")",
"{",
"const",
"s",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"final",
"=",
"s",
"[",
"s",
".",
"length",
"-",
"1",
"]",
"}",
"else",
"{",
"final",
"=",
"path",
".",
"startsWith",
"(",
"'./'",
")",
"?",
"path",
".",
"slice",
"(",
"2",
")",
":",
"path",
"}",
"// remove '.js'",
"return",
"final",
".",
"slice",
"(",
"0",
",",
"final",
".",
"length",
"-",
"3",
")",
"}"
] | Get namespace from file path
@param {String} path model file path such as 'test/sub/model.js'
@param {Boolean} relative use relative namespace or not | [
"Get",
"namespace",
"from",
"file",
"path"
] | 1337e7d3414879d5d5364db89d0e08f18f9ef984 | https://github.com/Fullstop000/redux-sirius/blob/1337e7d3414879d5d5364db89d0e08f18f9ef984/src/index.js#L293-L304 |
49,105 | Fullstop000/redux-sirius | src/index.js | readModels | function readModels (dir, relative) {
const fs = require('fs')
const path = require('path')
// eslint-disable-next-line no-eval
const evalRequire = eval('require')
const list = []
function readRecursively (dir, root, list) {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file)
if (fs.statSync(filePath).isDirectory()) {
// walk through
readRecursively(filePath, root, list)
} else {
// only '*.js' file will be added as model
if (file.match(/^(\.\/)?([\w]+\/)*([\w]+\.js)$/)) {
// bundler like webpack will complain about using dynamic require
// See https://github.com/webpack/webpack/issues/196
// use `eval` trick to avoid this
let model = evalRequire(filePath)
// handling es6 module
if (model.__esModule) {
model = model.default
}
// get relative path of the root path
const pathNS = path.join(path.relative(root, dir), file)
list.push(checkNS(model) ? model : {namespace: getNamespace(pathNS, relative), ...model})
}
}
})
}
const p = path.resolve(__dirname, dir)
readRecursively(p, p, list)
return list
} | javascript | function readModels (dir, relative) {
const fs = require('fs')
const path = require('path')
// eslint-disable-next-line no-eval
const evalRequire = eval('require')
const list = []
function readRecursively (dir, root, list) {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file)
if (fs.statSync(filePath).isDirectory()) {
// walk through
readRecursively(filePath, root, list)
} else {
// only '*.js' file will be added as model
if (file.match(/^(\.\/)?([\w]+\/)*([\w]+\.js)$/)) {
// bundler like webpack will complain about using dynamic require
// See https://github.com/webpack/webpack/issues/196
// use `eval` trick to avoid this
let model = evalRequire(filePath)
// handling es6 module
if (model.__esModule) {
model = model.default
}
// get relative path of the root path
const pathNS = path.join(path.relative(root, dir), file)
list.push(checkNS(model) ? model : {namespace: getNamespace(pathNS, relative), ...model})
}
}
})
}
const p = path.resolve(__dirname, dir)
readRecursively(p, p, list)
return list
} | [
"function",
"readModels",
"(",
"dir",
",",
"relative",
")",
"{",
"const",
"fs",
"=",
"require",
"(",
"'fs'",
")",
"const",
"path",
"=",
"require",
"(",
"'path'",
")",
"// eslint-disable-next-line no-eval",
"const",
"evalRequire",
"=",
"eval",
"(",
"'require'",
")",
"const",
"list",
"=",
"[",
"]",
"function",
"readRecursively",
"(",
"dir",
",",
"root",
",",
"list",
")",
"{",
"fs",
".",
"readdirSync",
"(",
"dir",
")",
".",
"forEach",
"(",
"file",
"=>",
"{",
"const",
"filePath",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"file",
")",
"if",
"(",
"fs",
".",
"statSync",
"(",
"filePath",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"// walk through",
"readRecursively",
"(",
"filePath",
",",
"root",
",",
"list",
")",
"}",
"else",
"{",
"// only '*.js' file will be added as model",
"if",
"(",
"file",
".",
"match",
"(",
"/",
"^(\\.\\/)?([\\w]+\\/)*([\\w]+\\.js)$",
"/",
")",
")",
"{",
"// bundler like webpack will complain about using dynamic require",
"// See https://github.com/webpack/webpack/issues/196",
"// use `eval` trick to avoid this",
"let",
"model",
"=",
"evalRequire",
"(",
"filePath",
")",
"// handling es6 module",
"if",
"(",
"model",
".",
"__esModule",
")",
"{",
"model",
"=",
"model",
".",
"default",
"}",
"// get relative path of the root path",
"const",
"pathNS",
"=",
"path",
".",
"join",
"(",
"path",
".",
"relative",
"(",
"root",
",",
"dir",
")",
",",
"file",
")",
"list",
".",
"push",
"(",
"checkNS",
"(",
"model",
")",
"?",
"model",
":",
"{",
"namespace",
":",
"getNamespace",
"(",
"pathNS",
",",
"relative",
")",
",",
"...",
"model",
"}",
")",
"}",
"}",
"}",
")",
"}",
"const",
"p",
"=",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"dir",
")",
"readRecursively",
"(",
"p",
",",
"p",
",",
"list",
")",
"return",
"list",
"}"
] | Read all models recursively in a path. This just works in Node project
@param {String} dir
@param {String} root
@param {Array} list | [
"Read",
"all",
"models",
"recursively",
"in",
"a",
"path",
".",
"This",
"just",
"works",
"in",
"Node",
"project"
] | 1337e7d3414879d5d5364db89d0e08f18f9ef984 | https://github.com/Fullstop000/redux-sirius/blob/1337e7d3414879d5d5364db89d0e08f18f9ef984/src/index.js#L313-L346 |
49,106 | francois2metz/node-intervals | intervals.js | transformHtmlEntities | function transformHtmlEntities() {
return function(method, request, next) {
next(function(response, next) {
response.body = utils.deHtmlEntities(response.body);
next();
})
};
} | javascript | function transformHtmlEntities() {
return function(method, request, next) {
next(function(response, next) {
response.body = utils.deHtmlEntities(response.body);
next();
})
};
} | [
"function",
"transformHtmlEntities",
"(",
")",
"{",
"return",
"function",
"(",
"method",
",",
"request",
",",
"next",
")",
"{",
"next",
"(",
"function",
"(",
"response",
",",
"next",
")",
"{",
"response",
".",
"body",
"=",
"utils",
".",
"deHtmlEntities",
"(",
"response",
".",
"body",
")",
";",
"next",
"(",
")",
";",
"}",
")",
"}",
";",
"}"
] | Replace all html entities from api response to real utf8 characters | [
"Replace",
"all",
"html",
"entities",
"from",
"api",
"response",
"to",
"real",
"utf8",
"characters"
] | 0633747156f02938ce4d8063e1fed8a33beab365 | https://github.com/francois2metz/node-intervals/blob/0633747156f02938ce4d8063e1fed8a33beab365/intervals.js#L56-L63 |
49,107 | olaurendeau/grunt-contrib-mongo-migrate | tasks/mongo-migrate.js | run | function run(cmd){
var proc = require('child_process'),
done = grunt.task.current.async(); // Tells Grunt that an async task is complete
proc.exec(cmd,
function(error, stdout, stderr){
if(stderr){
grunt.log.writeln('ERROR: ' + stderr).error();
}
grunt.log.writeln(stdout);
done(error);
}
);
} | javascript | function run(cmd){
var proc = require('child_process'),
done = grunt.task.current.async(); // Tells Grunt that an async task is complete
proc.exec(cmd,
function(error, stdout, stderr){
if(stderr){
grunt.log.writeln('ERROR: ' + stderr).error();
}
grunt.log.writeln(stdout);
done(error);
}
);
} | [
"function",
"run",
"(",
"cmd",
")",
"{",
"var",
"proc",
"=",
"require",
"(",
"'child_process'",
")",
",",
"done",
"=",
"grunt",
".",
"task",
".",
"current",
".",
"async",
"(",
")",
";",
"// Tells Grunt that an async task is complete",
"proc",
".",
"exec",
"(",
"cmd",
",",
"function",
"(",
"error",
",",
"stdout",
",",
"stderr",
")",
"{",
"if",
"(",
"stderr",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'ERROR: '",
"+",
"stderr",
")",
".",
"error",
"(",
")",
";",
"}",
"grunt",
".",
"log",
".",
"writeln",
"(",
"stdout",
")",
";",
"done",
"(",
"error",
")",
";",
"}",
")",
";",
"}"
] | Helper method to interface with the migrate bin file.
@param cmd Command that is going to be executed. | [
"Helper",
"method",
"to",
"interface",
"with",
"the",
"migrate",
"bin",
"file",
"."
] | 2b9f20d60df877c6e850887f6f69a5e9769b0854 | https://github.com/olaurendeau/grunt-contrib-mongo-migrate/blob/2b9f20d60df877c6e850887f6f69a5e9769b0854/tasks/mongo-migrate.js#L22-L36 |
49,108 | olaurendeau/grunt-contrib-mongo-migrate | tasks/mongo-migrate.js | up | function up(){
console.log(grunt.target);
var key = (grunt.option('name') || ""),
label = ( key || "EMPTY"),
cmd = (migrateBinPath + " up " + key).trim();
grunt.log.write('Running migration "UP" [' + label + ']...').ok();
run(cmd);
} | javascript | function up(){
console.log(grunt.target);
var key = (grunt.option('name') || ""),
label = ( key || "EMPTY"),
cmd = (migrateBinPath + " up " + key).trim();
grunt.log.write('Running migration "UP" [' + label + ']...').ok();
run(cmd);
} | [
"function",
"up",
"(",
")",
"{",
"console",
".",
"log",
"(",
"grunt",
".",
"target",
")",
";",
"var",
"key",
"=",
"(",
"grunt",
".",
"option",
"(",
"'name'",
")",
"||",
"\"\"",
")",
",",
"label",
"=",
"(",
"key",
"||",
"\"EMPTY\"",
")",
",",
"cmd",
"=",
"(",
"migrateBinPath",
"+",
"\" up \"",
"+",
"key",
")",
".",
"trim",
"(",
")",
";",
"grunt",
".",
"log",
".",
"write",
"(",
"'Running migration \"UP\" ['",
"+",
"label",
"+",
"']...'",
")",
".",
"ok",
"(",
")",
";",
"run",
"(",
"cmd",
")",
";",
"}"
] | Migrate UP to either the latest migration file or to a migration name passed in as an argument. | [
"Migrate",
"UP",
"to",
"either",
"the",
"latest",
"migration",
"file",
"or",
"to",
"a",
"migration",
"name",
"passed",
"in",
"as",
"an",
"argument",
"."
] | 2b9f20d60df877c6e850887f6f69a5e9769b0854 | https://github.com/olaurendeau/grunt-contrib-mongo-migrate/blob/2b9f20d60df877c6e850887f6f69a5e9769b0854/tasks/mongo-migrate.js#L41-L49 |
49,109 | olaurendeau/grunt-contrib-mongo-migrate | tasks/mongo-migrate.js | down | function down(){
var key = (grunt.option('name') || ""),
label = ( key || "EMPTY"),
cmd = (migrateBinPath + " down " + key).trim();
grunt.log.write('Running migration "DOWN" [' + label + ']...').ok();
run(cmd);
} | javascript | function down(){
var key = (grunt.option('name') || ""),
label = ( key || "EMPTY"),
cmd = (migrateBinPath + " down " + key).trim();
grunt.log.write('Running migration "DOWN" [' + label + ']...').ok();
run(cmd);
} | [
"function",
"down",
"(",
")",
"{",
"var",
"key",
"=",
"(",
"grunt",
".",
"option",
"(",
"'name'",
")",
"||",
"\"\"",
")",
",",
"label",
"=",
"(",
"key",
"||",
"\"EMPTY\"",
")",
",",
"cmd",
"=",
"(",
"migrateBinPath",
"+",
"\" down \"",
"+",
"key",
")",
".",
"trim",
"(",
")",
";",
"grunt",
".",
"log",
".",
"write",
"(",
"'Running migration \"DOWN\" ['",
"+",
"label",
"+",
"']...'",
")",
".",
"ok",
"(",
")",
";",
"run",
"(",
"cmd",
")",
";",
"}"
] | Migrate DOWN to either the latest migration file or to a migration name passed in as an argument. | [
"Migrate",
"DOWN",
"to",
"either",
"the",
"latest",
"migration",
"file",
"or",
"to",
"a",
"migration",
"name",
"passed",
"in",
"as",
"an",
"argument",
"."
] | 2b9f20d60df877c6e850887f6f69a5e9769b0854 | https://github.com/olaurendeau/grunt-contrib-mongo-migrate/blob/2b9f20d60df877c6e850887f6f69a5e9769b0854/tasks/mongo-migrate.js#L54-L61 |
49,110 | olaurendeau/grunt-contrib-mongo-migrate | tasks/mongo-migrate.js | create | function create(){
var cmd = (migrateBinPath + " create " + grunt.option('name')).trim();
grunt.log.write('Creating a new migration named "' + grunt.option('name') + '"...').ok();
run(cmd);
} | javascript | function create(){
var cmd = (migrateBinPath + " create " + grunt.option('name')).trim();
grunt.log.write('Creating a new migration named "' + grunt.option('name') + '"...').ok();
run(cmd);
} | [
"function",
"create",
"(",
")",
"{",
"var",
"cmd",
"=",
"(",
"migrateBinPath",
"+",
"\" create \"",
"+",
"grunt",
".",
"option",
"(",
"'name'",
")",
")",
".",
"trim",
"(",
")",
";",
"grunt",
".",
"log",
".",
"write",
"(",
"'Creating a new migration named \"'",
"+",
"grunt",
".",
"option",
"(",
"'name'",
")",
"+",
"'\"...'",
")",
".",
"ok",
"(",
")",
";",
"run",
"(",
"cmd",
")",
";",
"}"
] | Migrate CREATE will create a new migration file. | [
"Migrate",
"CREATE",
"will",
"create",
"a",
"new",
"migration",
"file",
"."
] | 2b9f20d60df877c6e850887f6f69a5e9769b0854 | https://github.com/olaurendeau/grunt-contrib-mongo-migrate/blob/2b9f20d60df877c6e850887f6f69a5e9769b0854/tasks/mongo-migrate.js#L66-L71 |
49,111 | lokijs/loki-core | lib/game.js | function(entity) {
// Bind to start event right away.
var boundStart = entity.start.bind(entity);
this.on('start', boundStart);
// Bind to preloadComplete, but only once.
var boundPreloadComplete = entity.preloadComplete.bind(entity);
this.once('preloadComplete', boundPreloadComplete);
// Only bind to update after preloadComplete event.
var boundUpdate = entity.update.bind(entity);
this.once('preloadComplete', function() {
this.on('update', boundUpdate);
}.bind(this));
entity.on('destroy', function() {
this.removeListener('start', boundStart);
this.removeListener('preloadComplete', boundPreloadComplete);
this.removeListener('update', boundUpdate);
}.bind(this));
this.emit('entityAdded', entity);
} | javascript | function(entity) {
// Bind to start event right away.
var boundStart = entity.start.bind(entity);
this.on('start', boundStart);
// Bind to preloadComplete, but only once.
var boundPreloadComplete = entity.preloadComplete.bind(entity);
this.once('preloadComplete', boundPreloadComplete);
// Only bind to update after preloadComplete event.
var boundUpdate = entity.update.bind(entity);
this.once('preloadComplete', function() {
this.on('update', boundUpdate);
}.bind(this));
entity.on('destroy', function() {
this.removeListener('start', boundStart);
this.removeListener('preloadComplete', boundPreloadComplete);
this.removeListener('update', boundUpdate);
}.bind(this));
this.emit('entityAdded', entity);
} | [
"function",
"(",
"entity",
")",
"{",
"// Bind to start event right away.",
"var",
"boundStart",
"=",
"entity",
".",
"start",
".",
"bind",
"(",
"entity",
")",
";",
"this",
".",
"on",
"(",
"'start'",
",",
"boundStart",
")",
";",
"// Bind to preloadComplete, but only once.",
"var",
"boundPreloadComplete",
"=",
"entity",
".",
"preloadComplete",
".",
"bind",
"(",
"entity",
")",
";",
"this",
".",
"once",
"(",
"'preloadComplete'",
",",
"boundPreloadComplete",
")",
";",
"// Only bind to update after preloadComplete event.",
"var",
"boundUpdate",
"=",
"entity",
".",
"update",
".",
"bind",
"(",
"entity",
")",
";",
"this",
".",
"once",
"(",
"'preloadComplete'",
",",
"function",
"(",
")",
"{",
"this",
".",
"on",
"(",
"'update'",
",",
"boundUpdate",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"entity",
".",
"on",
"(",
"'destroy'",
",",
"function",
"(",
")",
"{",
"this",
".",
"removeListener",
"(",
"'start'",
",",
"boundStart",
")",
";",
"this",
".",
"removeListener",
"(",
"'preloadComplete'",
",",
"boundPreloadComplete",
")",
";",
"this",
".",
"removeListener",
"(",
"'update'",
",",
"boundUpdate",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"emit",
"(",
"'entityAdded'",
",",
"entity",
")",
";",
"}"
] | Bound to a game instance, will add a single entity. | [
"Bound",
"to",
"a",
"game",
"instance",
"will",
"add",
"a",
"single",
"entity",
"."
] | ee17222ca8ce52faefd8d0874feda80364b8dd13 | https://github.com/lokijs/loki-core/blob/ee17222ca8ce52faefd8d0874feda80364b8dd13/lib/game.js#L73-L91 |
|
49,112 | gethuman/pancakes-angular | lib/ngapp/ajax.js | saveOpts | function saveOpts(apiOpts) {
if (apiOpts.url && apiOpts.url.toLowerCase().indexOf('password') >= 0) {
var idx = apiOpts.url.indexOf('?');
apiOpts.url = apiOpts.url.substring(0, idx);
}
storage.set('lastApiCall', (JSON.stringify(apiOpts) || '').substring(0, 250));
} | javascript | function saveOpts(apiOpts) {
if (apiOpts.url && apiOpts.url.toLowerCase().indexOf('password') >= 0) {
var idx = apiOpts.url.indexOf('?');
apiOpts.url = apiOpts.url.substring(0, idx);
}
storage.set('lastApiCall', (JSON.stringify(apiOpts) || '').substring(0, 250));
} | [
"function",
"saveOpts",
"(",
"apiOpts",
")",
"{",
"if",
"(",
"apiOpts",
".",
"url",
"&&",
"apiOpts",
".",
"url",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"'password'",
")",
">=",
"0",
")",
"{",
"var",
"idx",
"=",
"apiOpts",
".",
"url",
".",
"indexOf",
"(",
"'?'",
")",
";",
"apiOpts",
".",
"url",
"=",
"apiOpts",
".",
"url",
".",
"substring",
"(",
"0",
",",
"idx",
")",
";",
"}",
"storage",
".",
"set",
"(",
"'lastApiCall'",
",",
"(",
"JSON",
".",
"stringify",
"(",
"apiOpts",
")",
"||",
"''",
")",
".",
"substring",
"(",
"0",
",",
"250",
")",
")",
";",
"}"
] | Save the options to storage for later debugging | [
"Save",
"the",
"options",
"to",
"storage",
"for",
"later",
"debugging"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/ajax.js#L68-L75 |
49,113 | gethuman/pancakes-angular | lib/ngapp/ajax.js | send | function send(url, method, options, resourceName) {
var deferred = $q.defer();
var key, val, paramArray = [];
url = config.apiBase + url;
options = options || {};
// separate out data if it exists
var data = options.data;
delete options.data;
// attempt to add id to the url if it exists
if (url.indexOf('{_id}') >= 0) {
if (options._id) {
url = url.replace('{_id}', options._id);
delete options._id;
}
else if (data && data._id) {
url = url.replace('{_id}', data._id);
}
}
else if (method === 'GET' && options._id) {
url += '/' + options._id;
delete options._id;
}
var showErr = options.showErr !== false;
delete options.showErr;
// add params to the URL
options.lang = options.lang || config.lang;
for (key in options) {
if (options.hasOwnProperty(key) && options[key]) {
val = options[key];
val = angular.isObject(val) ? JSON.stringify(val) : val;
paramArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
}
}
// add params to URL
if (paramArray.length) {
url += '?' + paramArray.join('&');
}
// set up the api options
var apiOpts = {
method: method,
url: url
};
// if the jwt exists, add it to the request
var jwt = storage.get('jwt');
if (jwt && jwt !== 'null') { // hack fix; someone setting localStorage to 'null'
apiOpts.headers = {
Authorization: jwt
};
}
// add data to api options if available
if (data) {
apiOpts.data = data;
}
// emit events for start and end so realtime services can stop syncing for post
eventBus.emit(resourceName + '.' + method.toLowerCase() + '.start');
// finally make the http call
$http(apiOpts)
.then(function (respData) {
respData = respData || {};
saveOpts(apiOpts);
deferred.resolve(respData.data); //deferred.resolve(respData.data || respData);
})
.catch(function (err) {
// if (status > 450 && status < 499) {
// eventBus.emit('error.' + status, err);
// return;
// }
saveOpts(apiOpts);
// var isTimeout = !status || status === -1;
// if (!err && isTimeout) {
// err = new Error('Cannot access back end');
// }
if (!err) {
err = new Error('error httpCode ' + status + ' headers ' +
JSON.stringify(headers) + ' conf ' +
JSON.stringify(conf));
}
if (showErr) {
eventBus.emit('error.api', err);
}
log.error(err, {
apiOpts: apiOpts,
status: status,
headers: headers
});
deferred.reject(err);
})
.finally(function () {
eventBus.emit(resourceName + '.' + method.toLowerCase() + '.end');
});
return deferred.promise;
} | javascript | function send(url, method, options, resourceName) {
var deferred = $q.defer();
var key, val, paramArray = [];
url = config.apiBase + url;
options = options || {};
// separate out data if it exists
var data = options.data;
delete options.data;
// attempt to add id to the url if it exists
if (url.indexOf('{_id}') >= 0) {
if (options._id) {
url = url.replace('{_id}', options._id);
delete options._id;
}
else if (data && data._id) {
url = url.replace('{_id}', data._id);
}
}
else if (method === 'GET' && options._id) {
url += '/' + options._id;
delete options._id;
}
var showErr = options.showErr !== false;
delete options.showErr;
// add params to the URL
options.lang = options.lang || config.lang;
for (key in options) {
if (options.hasOwnProperty(key) && options[key]) {
val = options[key];
val = angular.isObject(val) ? JSON.stringify(val) : val;
paramArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
}
}
// add params to URL
if (paramArray.length) {
url += '?' + paramArray.join('&');
}
// set up the api options
var apiOpts = {
method: method,
url: url
};
// if the jwt exists, add it to the request
var jwt = storage.get('jwt');
if (jwt && jwt !== 'null') { // hack fix; someone setting localStorage to 'null'
apiOpts.headers = {
Authorization: jwt
};
}
// add data to api options if available
if (data) {
apiOpts.data = data;
}
// emit events for start and end so realtime services can stop syncing for post
eventBus.emit(resourceName + '.' + method.toLowerCase() + '.start');
// finally make the http call
$http(apiOpts)
.then(function (respData) {
respData = respData || {};
saveOpts(apiOpts);
deferred.resolve(respData.data); //deferred.resolve(respData.data || respData);
})
.catch(function (err) {
// if (status > 450 && status < 499) {
// eventBus.emit('error.' + status, err);
// return;
// }
saveOpts(apiOpts);
// var isTimeout = !status || status === -1;
// if (!err && isTimeout) {
// err = new Error('Cannot access back end');
// }
if (!err) {
err = new Error('error httpCode ' + status + ' headers ' +
JSON.stringify(headers) + ' conf ' +
JSON.stringify(conf));
}
if (showErr) {
eventBus.emit('error.api', err);
}
log.error(err, {
apiOpts: apiOpts,
status: status,
headers: headers
});
deferred.reject(err);
})
.finally(function () {
eventBus.emit(resourceName + '.' + method.toLowerCase() + '.end');
});
return deferred.promise;
} | [
"function",
"send",
"(",
"url",
",",
"method",
",",
"options",
",",
"resourceName",
")",
"{",
"var",
"deferred",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"var",
"key",
",",
"val",
",",
"paramArray",
"=",
"[",
"]",
";",
"url",
"=",
"config",
".",
"apiBase",
"+",
"url",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// separate out data if it exists",
"var",
"data",
"=",
"options",
".",
"data",
";",
"delete",
"options",
".",
"data",
";",
"// attempt to add id to the url if it exists",
"if",
"(",
"url",
".",
"indexOf",
"(",
"'{_id}'",
")",
">=",
"0",
")",
"{",
"if",
"(",
"options",
".",
"_id",
")",
"{",
"url",
"=",
"url",
".",
"replace",
"(",
"'{_id}'",
",",
"options",
".",
"_id",
")",
";",
"delete",
"options",
".",
"_id",
";",
"}",
"else",
"if",
"(",
"data",
"&&",
"data",
".",
"_id",
")",
"{",
"url",
"=",
"url",
".",
"replace",
"(",
"'{_id}'",
",",
"data",
".",
"_id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"method",
"===",
"'GET'",
"&&",
"options",
".",
"_id",
")",
"{",
"url",
"+=",
"'/'",
"+",
"options",
".",
"_id",
";",
"delete",
"options",
".",
"_id",
";",
"}",
"var",
"showErr",
"=",
"options",
".",
"showErr",
"!==",
"false",
";",
"delete",
"options",
".",
"showErr",
";",
"// add params to the URL",
"options",
".",
"lang",
"=",
"options",
".",
"lang",
"||",
"config",
".",
"lang",
";",
"for",
"(",
"key",
"in",
"options",
")",
"{",
"if",
"(",
"options",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"options",
"[",
"key",
"]",
")",
"{",
"val",
"=",
"options",
"[",
"key",
"]",
";",
"val",
"=",
"angular",
".",
"isObject",
"(",
"val",
")",
"?",
"JSON",
".",
"stringify",
"(",
"val",
")",
":",
"val",
";",
"paramArray",
".",
"push",
"(",
"encodeURIComponent",
"(",
"key",
")",
"+",
"'='",
"+",
"encodeURIComponent",
"(",
"val",
")",
")",
";",
"}",
"}",
"// add params to URL",
"if",
"(",
"paramArray",
".",
"length",
")",
"{",
"url",
"+=",
"'?'",
"+",
"paramArray",
".",
"join",
"(",
"'&'",
")",
";",
"}",
"// set up the api options",
"var",
"apiOpts",
"=",
"{",
"method",
":",
"method",
",",
"url",
":",
"url",
"}",
";",
"// if the jwt exists, add it to the request",
"var",
"jwt",
"=",
"storage",
".",
"get",
"(",
"'jwt'",
")",
";",
"if",
"(",
"jwt",
"&&",
"jwt",
"!==",
"'null'",
")",
"{",
"// hack fix; someone setting localStorage to 'null'",
"apiOpts",
".",
"headers",
"=",
"{",
"Authorization",
":",
"jwt",
"}",
";",
"}",
"// add data to api options if available",
"if",
"(",
"data",
")",
"{",
"apiOpts",
".",
"data",
"=",
"data",
";",
"}",
"// emit events for start and end so realtime services can stop syncing for post",
"eventBus",
".",
"emit",
"(",
"resourceName",
"+",
"'.'",
"+",
"method",
".",
"toLowerCase",
"(",
")",
"+",
"'.start'",
")",
";",
"// finally make the http call",
"$http",
"(",
"apiOpts",
")",
".",
"then",
"(",
"function",
"(",
"respData",
")",
"{",
"respData",
"=",
"respData",
"||",
"{",
"}",
";",
"saveOpts",
"(",
"apiOpts",
")",
";",
"deferred",
".",
"resolve",
"(",
"respData",
".",
"data",
")",
";",
"//deferred.resolve(respData.data || respData);",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"// if (status > 450 && status < 499) {",
"// eventBus.emit('error.' + status, err);",
"// return;",
"// }",
"saveOpts",
"(",
"apiOpts",
")",
";",
"// var isTimeout = !status || status === -1;",
"// if (!err && isTimeout) {",
"// err = new Error('Cannot access back end');",
"// }",
"if",
"(",
"!",
"err",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"'error httpCode '",
"+",
"status",
"+",
"' headers '",
"+",
"JSON",
".",
"stringify",
"(",
"headers",
")",
"+",
"' conf '",
"+",
"JSON",
".",
"stringify",
"(",
"conf",
")",
")",
";",
"}",
"if",
"(",
"showErr",
")",
"{",
"eventBus",
".",
"emit",
"(",
"'error.api'",
",",
"err",
")",
";",
"}",
"log",
".",
"error",
"(",
"err",
",",
"{",
"apiOpts",
":",
"apiOpts",
",",
"status",
":",
"status",
",",
"headers",
":",
"headers",
"}",
")",
";",
"deferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
".",
"finally",
"(",
"function",
"(",
")",
"{",
"eventBus",
".",
"emit",
"(",
"resourceName",
"+",
"'.'",
"+",
"method",
".",
"toLowerCase",
"(",
")",
"+",
"'.end'",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Send call to the server and get a response
@param url
@param method
@param options
@param resourceName | [
"Send",
"call",
"to",
"the",
"server",
"and",
"get",
"a",
"response"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/ajax.js#L85-L195 |
49,114 | nyteshade/ne-types | dist/types.js | extendsFrom | function extendsFrom(TestedClass, RootClass, enforceClasses = false) {
if (!TestedClass || !RootClass) {
return false;
}
if (TestedClass === RootClass) {
return true;
}
TestedClass = TestedClass.constructor && typeof TestedClass !== 'function' ? TestedClass.constructor : TestedClass;
RootClass = RootClass.constructor && typeof RootClass !== 'function' ? RootClass.constructor : RootClass;
let ParentClass = TestedClass;
if (parseInt(process.version.substring(1)) < 6) {
throw new Error(`
Reflect must be implemented in the JavaScript engine. This cannot be
polyfilled and as such, if process.version is less than 6 an error will
be thrown. Please try an alternate means of doing what you desire.
`);
}
if (enforceClasses) {
if (!isClass(TestedClass) && !isClass(RootClass)) {
throw new Error(`
When using extendsFrom() with enforceClasses true, each Function
argument supplied must pass the isClass() method testing. See the
function isClass to learn more about these requirements.
`);
}
}
if (!TestedClass || !RootClass) {
return false;
}
if (TestedClass === RootClass) {
return true;
}
do {
ParentClass = (0, _getPrototypeOf2.default)(ParentClass);
if (ParentClass === RootClass) {
return true;
}
} while (ParentClass);
return false;
} | javascript | function extendsFrom(TestedClass, RootClass, enforceClasses = false) {
if (!TestedClass || !RootClass) {
return false;
}
if (TestedClass === RootClass) {
return true;
}
TestedClass = TestedClass.constructor && typeof TestedClass !== 'function' ? TestedClass.constructor : TestedClass;
RootClass = RootClass.constructor && typeof RootClass !== 'function' ? RootClass.constructor : RootClass;
let ParentClass = TestedClass;
if (parseInt(process.version.substring(1)) < 6) {
throw new Error(`
Reflect must be implemented in the JavaScript engine. This cannot be
polyfilled and as such, if process.version is less than 6 an error will
be thrown. Please try an alternate means of doing what you desire.
`);
}
if (enforceClasses) {
if (!isClass(TestedClass) && !isClass(RootClass)) {
throw new Error(`
When using extendsFrom() with enforceClasses true, each Function
argument supplied must pass the isClass() method testing. See the
function isClass to learn more about these requirements.
`);
}
}
if (!TestedClass || !RootClass) {
return false;
}
if (TestedClass === RootClass) {
return true;
}
do {
ParentClass = (0, _getPrototypeOf2.default)(ParentClass);
if (ParentClass === RootClass) {
return true;
}
} while (ParentClass);
return false;
} | [
"function",
"extendsFrom",
"(",
"TestedClass",
",",
"RootClass",
",",
"enforceClasses",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"TestedClass",
"||",
"!",
"RootClass",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"TestedClass",
"===",
"RootClass",
")",
"{",
"return",
"true",
";",
"}",
"TestedClass",
"=",
"TestedClass",
".",
"constructor",
"&&",
"typeof",
"TestedClass",
"!==",
"'function'",
"?",
"TestedClass",
".",
"constructor",
":",
"TestedClass",
";",
"RootClass",
"=",
"RootClass",
".",
"constructor",
"&&",
"typeof",
"RootClass",
"!==",
"'function'",
"?",
"RootClass",
".",
"constructor",
":",
"RootClass",
";",
"let",
"ParentClass",
"=",
"TestedClass",
";",
"if",
"(",
"parseInt",
"(",
"process",
".",
"version",
".",
"substring",
"(",
"1",
")",
")",
"<",
"6",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"`",
")",
";",
"}",
"if",
"(",
"enforceClasses",
")",
"{",
"if",
"(",
"!",
"isClass",
"(",
"TestedClass",
")",
"&&",
"!",
"isClass",
"(",
"RootClass",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"`",
")",
";",
"}",
"}",
"if",
"(",
"!",
"TestedClass",
"||",
"!",
"RootClass",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"TestedClass",
"===",
"RootClass",
")",
"{",
"return",
"true",
";",
"}",
"do",
"{",
"ParentClass",
"=",
"(",
"0",
",",
"_getPrototypeOf2",
".",
"default",
")",
"(",
"ParentClass",
")",
";",
"if",
"(",
"ParentClass",
"===",
"RootClass",
")",
"{",
"return",
"true",
";",
"}",
"}",
"while",
"(",
"ParentClass",
")",
";",
"return",
"false",
";",
"}"
] | NOTE This function will not work on nodejs versions less than 6 as Reflect
is needed natively.
The instanceof keyword only works on instances of an object and not on
the class objects the instances are created from.
```js
class A {}
class B extends A {}
let a = new A();
let b = new B();
b instanceof A; // true
a instanceof A; // true
B instanceof A; // false
```
Therefore the extendsFrom function checks this relationship at the class
level and not at the instance level.
```js
import { extendsFrom } from '...'
class A {}
class B extends A {}
class C extends B {}
extendsFrom(A, A); // true
extendsFrom(B, A); // true
extendsFrom(C, A); // true
extendsFrom(C, 1); // false
extendsFrom(B, null); // false
```
@method ⌾⠀extendsFrom
@memberof types
@inner
@param {Function} TestedClass the class of which to test heredity
@param {Function} RootClass the ancestor to test for
@param {Boolean} enforceClasses if true, false by default, an additional
runtime check for the type of the supplied Class objects will be made. If
either is not a Function, an error is thrown.
@return {Boolean} true if the lineage exists; false otherwise
@see types#isClass | [
"NOTE",
"This",
"function",
"will",
"not",
"work",
"on",
"nodejs",
"versions",
"less",
"than",
"6",
"as",
"Reflect",
"is",
"needed",
"natively",
"."
] | 46656c6b53e9b773e85dd7c24e6814d4717305ec | https://github.com/nyteshade/ne-types/blob/46656c6b53e9b773e85dd7c24e6814d4717305ec/dist/types.js#L324-L373 |
49,115 | PanthR/panthrMath | panthrMath/distributions/geom.js | rgeom | function rgeom(prob) {
var scale;
if (prob <= 0 || prob > 1) { return function() { return NaN; }; }
scale = prob / (1 - prob);
return function() {
return rpois(rexp(scale)())();
};
} | javascript | function rgeom(prob) {
var scale;
if (prob <= 0 || prob > 1) { return function() { return NaN; }; }
scale = prob / (1 - prob);
return function() {
return rpois(rexp(scale)())();
};
} | [
"function",
"rgeom",
"(",
"prob",
")",
"{",
"var",
"scale",
";",
"if",
"(",
"prob",
"<=",
"0",
"||",
"prob",
">",
"1",
")",
"{",
"return",
"function",
"(",
")",
"{",
"return",
"NaN",
";",
"}",
";",
"}",
"scale",
"=",
"prob",
"/",
"(",
"1",
"-",
"prob",
")",
";",
"return",
"function",
"(",
")",
"{",
"return",
"rpois",
"(",
"rexp",
"(",
"scale",
")",
"(",
")",
")",
"(",
")",
";",
"}",
";",
"}"
] | Returns a random variate from the geometric distribution.
Expects the probability parameter $0 < p \leq 1$.
Following R's code (rgeom.c)
@fullName rgeom(prob)()
@memberof geometric | [
"Returns",
"a",
"random",
"variate",
"from",
"the",
"geometric",
"distribution",
"."
] | 54d249ca9903a9535f963da711bd3a87fb229c0b | https://github.com/PanthR/panthrMath/blob/54d249ca9903a9535f963da711bd3a87fb229c0b/panthrMath/distributions/geom.js#L173-L183 |
49,116 | Nazariglez/perenquen | lib/pixi/src/core/graphics/webgl/GraphicsRenderer.js | GraphicsRenderer | function GraphicsRenderer(renderer)
{
ObjectRenderer.call(this, renderer);
this.graphicsDataPool = [];
this.primitiveShader = null;
this.complexPrimitiveShader = null;
} | javascript | function GraphicsRenderer(renderer)
{
ObjectRenderer.call(this, renderer);
this.graphicsDataPool = [];
this.primitiveShader = null;
this.complexPrimitiveShader = null;
} | [
"function",
"GraphicsRenderer",
"(",
"renderer",
")",
"{",
"ObjectRenderer",
".",
"call",
"(",
"this",
",",
"renderer",
")",
";",
"this",
".",
"graphicsDataPool",
"=",
"[",
"]",
";",
"this",
".",
"primitiveShader",
"=",
"null",
";",
"this",
".",
"complexPrimitiveShader",
"=",
"null",
";",
"}"
] | Renders the graphics object.
@class
@private
@memberof PIXI
@extends ObjectRenderer
@param renderer {WebGLRenderer} The renderer this object renderer works for. | [
"Renders",
"the",
"graphics",
"object",
"."
] | e023964d05afeefebdcac4e2044819fdfa3899ae | https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/core/graphics/webgl/GraphicsRenderer.js#L17-L25 |
49,117 | tolokoban/ToloFrameWork | ker/mod/tfw.view.js | ensureCodeBehind | function ensureCodeBehind(code_behind) {
if (typeof code_behind === 'undefined')
throw "Missing mandatory global variable CODE_BEHIND!";
var i, funcName;
for (i = 1; i < arguments.length; i++) {
funcName = arguments[i];
if (typeof code_behind[funcName] !== 'function')
throw "Expected CODE_BEHIND." + funcName + " to be a function!";
}
} | javascript | function ensureCodeBehind(code_behind) {
if (typeof code_behind === 'undefined')
throw "Missing mandatory global variable CODE_BEHIND!";
var i, funcName;
for (i = 1; i < arguments.length; i++) {
funcName = arguments[i];
if (typeof code_behind[funcName] !== 'function')
throw "Expected CODE_BEHIND." + funcName + " to be a function!";
}
} | [
"function",
"ensureCodeBehind",
"(",
"code_behind",
")",
"{",
"if",
"(",
"typeof",
"code_behind",
"===",
"'undefined'",
")",
"throw",
"\"Missing mandatory global variable CODE_BEHIND!\"",
";",
"var",
"i",
",",
"funcName",
";",
"for",
"(",
"i",
"=",
"1",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"{",
"funcName",
"=",
"arguments",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"code_behind",
"[",
"funcName",
"]",
"!==",
"'function'",
")",
"throw",
"\"Expected CODE_BEHIND.\"",
"+",
"funcName",
"+",
"\" to be a function!\"",
";",
"}",
"}"
] | Check if all needed function from code behind are defined. | [
"Check",
"if",
"all",
"needed",
"function",
"from",
"code",
"behind",
"are",
"defined",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.view.js#L191-L201 |
49,118 | tolokoban/ToloFrameWork | ker/mod/tfw.view.js | defVal | function defVal(target, args, defaultValues) {
var key, val;
for (key in defaultValues) {
val = defaultValues[key];
if (typeof args[key] === 'undefined') {
target[key] = val;
} else {
target[key] = args[key];
}
}
} | javascript | function defVal(target, args, defaultValues) {
var key, val;
for (key in defaultValues) {
val = defaultValues[key];
if (typeof args[key] === 'undefined') {
target[key] = val;
} else {
target[key] = args[key];
}
}
} | [
"function",
"defVal",
"(",
"target",
",",
"args",
",",
"defaultValues",
")",
"{",
"var",
"key",
",",
"val",
";",
"for",
"(",
"key",
"in",
"defaultValues",
")",
"{",
"val",
"=",
"defaultValues",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"args",
"[",
"key",
"]",
"===",
"'undefined'",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"val",
";",
"}",
"else",
"{",
"target",
"[",
"key",
"]",
"=",
"args",
"[",
"key",
"]",
";",
"}",
"}",
"}"
] | Assign default values. | [
"Assign",
"default",
"values",
"."
] | 730845a833a9660ebfdb60ad027ebaab5ac871b6 | https://github.com/tolokoban/ToloFrameWork/blob/730845a833a9660ebfdb60ad027ebaab5ac871b6/ker/mod/tfw.view.js#L259-L269 |
49,119 | FinalDevStudio/fi-auth | lib/index.js | generate | function generate(allows) {
return function (req, res, next) {
req.route.allows = allows;
next();
};
} | javascript | function generate(allows) {
return function (req, res, next) {
req.route.allows = allows;
next();
};
} | [
"function",
"generate",
"(",
"allows",
")",
"{",
"return",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"req",
".",
"route",
".",
"allows",
"=",
"allows",
";",
"next",
"(",
")",
";",
"}",
";",
"}"
] | Generates the Express middleware to associate the allowed values to the route. | [
"Generates",
"the",
"Express",
"middleware",
"to",
"associate",
"the",
"allowed",
"values",
"to",
"the",
"route",
"."
] | 0067e31af94b6f4c5cf0d6a630f37d710034faff | https://github.com/FinalDevStudio/fi-auth/blob/0067e31af94b6f4c5cf0d6a630f37d710034faff/lib/index.js#L81-L86 |
49,120 | reptilbud/hapi-swagger | lib/index.js | function (plugin, settings) {
plugin.ext('onPostHandler', (request, reply) => {
let response = request.response;
// if the reply is a view add settings data into template system
if (response.variety === 'view') {
// Added to fix bug that cannot yet be reproduced in test - REVIEW
/* $lab:coverage:off$ */
if (!response.source.context) {
response.source.context = {};
}
/* $lab:coverage:on$ */
// append tags from document request to JSON request
if (request.query.tags) {
settings.jsonPath = appendQueryString(settings.jsonPath, 'tags', request.query.tags);
} else {
settings.jsonPath = appendQueryString(settings.jsonPath, null, null);
}
const prefixedSettings = Hoek.clone(settings);
if (plugin.realm.modifiers.route.prefix) {
['jsonPath', 'swaggerUIPath'].forEach((setting) => {
prefixedSettings[setting] = plugin.realm.modifiers.route.prefix + prefixedSettings[setting];
});
}
const prefix = findAPIKeyPrefix(settings);
if (prefix) {
prefixedSettings.keyPrefix = prefix;
}
prefixedSettings.stringified = JSON.stringify(prefixedSettings);
response.source.context.hapiSwagger = prefixedSettings;
}
return reply.continue();
});
} | javascript | function (plugin, settings) {
plugin.ext('onPostHandler', (request, reply) => {
let response = request.response;
// if the reply is a view add settings data into template system
if (response.variety === 'view') {
// Added to fix bug that cannot yet be reproduced in test - REVIEW
/* $lab:coverage:off$ */
if (!response.source.context) {
response.source.context = {};
}
/* $lab:coverage:on$ */
// append tags from document request to JSON request
if (request.query.tags) {
settings.jsonPath = appendQueryString(settings.jsonPath, 'tags', request.query.tags);
} else {
settings.jsonPath = appendQueryString(settings.jsonPath, null, null);
}
const prefixedSettings = Hoek.clone(settings);
if (plugin.realm.modifiers.route.prefix) {
['jsonPath', 'swaggerUIPath'].forEach((setting) => {
prefixedSettings[setting] = plugin.realm.modifiers.route.prefix + prefixedSettings[setting];
});
}
const prefix = findAPIKeyPrefix(settings);
if (prefix) {
prefixedSettings.keyPrefix = prefix;
}
prefixedSettings.stringified = JSON.stringify(prefixedSettings);
response.source.context.hapiSwagger = prefixedSettings;
}
return reply.continue();
});
} | [
"function",
"(",
"plugin",
",",
"settings",
")",
"{",
"plugin",
".",
"ext",
"(",
"'onPostHandler'",
",",
"(",
"request",
",",
"reply",
")",
"=>",
"{",
"let",
"response",
"=",
"request",
".",
"response",
";",
"// if the reply is a view add settings data into template system",
"if",
"(",
"response",
".",
"variety",
"===",
"'view'",
")",
"{",
"// Added to fix bug that cannot yet be reproduced in test - REVIEW",
"/* $lab:coverage:off$ */",
"if",
"(",
"!",
"response",
".",
"source",
".",
"context",
")",
"{",
"response",
".",
"source",
".",
"context",
"=",
"{",
"}",
";",
"}",
"/* $lab:coverage:on$ */",
"// append tags from document request to JSON request",
"if",
"(",
"request",
".",
"query",
".",
"tags",
")",
"{",
"settings",
".",
"jsonPath",
"=",
"appendQueryString",
"(",
"settings",
".",
"jsonPath",
",",
"'tags'",
",",
"request",
".",
"query",
".",
"tags",
")",
";",
"}",
"else",
"{",
"settings",
".",
"jsonPath",
"=",
"appendQueryString",
"(",
"settings",
".",
"jsonPath",
",",
"null",
",",
"null",
")",
";",
"}",
"const",
"prefixedSettings",
"=",
"Hoek",
".",
"clone",
"(",
"settings",
")",
";",
"if",
"(",
"plugin",
".",
"realm",
".",
"modifiers",
".",
"route",
".",
"prefix",
")",
"{",
"[",
"'jsonPath'",
",",
"'swaggerUIPath'",
"]",
".",
"forEach",
"(",
"(",
"setting",
")",
"=>",
"{",
"prefixedSettings",
"[",
"setting",
"]",
"=",
"plugin",
".",
"realm",
".",
"modifiers",
".",
"route",
".",
"prefix",
"+",
"prefixedSettings",
"[",
"setting",
"]",
";",
"}",
")",
";",
"}",
"const",
"prefix",
"=",
"findAPIKeyPrefix",
"(",
"settings",
")",
";",
"if",
"(",
"prefix",
")",
"{",
"prefixedSettings",
".",
"keyPrefix",
"=",
"prefix",
";",
"}",
"prefixedSettings",
".",
"stringified",
"=",
"JSON",
".",
"stringify",
"(",
"prefixedSettings",
")",
";",
"response",
".",
"source",
".",
"context",
".",
"hapiSwagger",
"=",
"prefixedSettings",
";",
"}",
"return",
"reply",
".",
"continue",
"(",
")",
";",
"}",
")",
";",
"}"
] | appends settings data in template context
@param {Object} plugin
@param {Object} settings
@return {Object} | [
"appends",
"settings",
"data",
"in",
"template",
"context"
] | 8a4a1059f060a7100270e837d2759c6a2b9c7e74 | https://github.com/reptilbud/hapi-swagger/blob/8a4a1059f060a7100270e837d2759c6a2b9c7e74/lib/index.js#L253-L291 |
|
49,121 | reptilbud/hapi-swagger | lib/index.js | function (url, qsName, qsValue) {
let urlObj = Url.parse(url);
if (qsName && qsValue) {
urlObj.query = Querystring.parse(qsName + '=' + qsValue);
urlObj.search = '?' + encodeURIComponent(qsName) + '=' + encodeURIComponent(qsValue);
} else {
urlObj.search = '';
}
return urlObj.format(urlObj);
} | javascript | function (url, qsName, qsValue) {
let urlObj = Url.parse(url);
if (qsName && qsValue) {
urlObj.query = Querystring.parse(qsName + '=' + qsValue);
urlObj.search = '?' + encodeURIComponent(qsName) + '=' + encodeURIComponent(qsValue);
} else {
urlObj.search = '';
}
return urlObj.format(urlObj);
} | [
"function",
"(",
"url",
",",
"qsName",
",",
"qsValue",
")",
"{",
"let",
"urlObj",
"=",
"Url",
".",
"parse",
"(",
"url",
")",
";",
"if",
"(",
"qsName",
"&&",
"qsValue",
")",
"{",
"urlObj",
".",
"query",
"=",
"Querystring",
".",
"parse",
"(",
"qsName",
"+",
"'='",
"+",
"qsValue",
")",
";",
"urlObj",
".",
"search",
"=",
"'?'",
"+",
"encodeURIComponent",
"(",
"qsName",
")",
"+",
"'='",
"+",
"encodeURIComponent",
"(",
"qsValue",
")",
";",
"}",
"else",
"{",
"urlObj",
".",
"search",
"=",
"''",
";",
"}",
"return",
"urlObj",
".",
"format",
"(",
"urlObj",
")",
";",
"}"
] | appends a querystring to a url path - will overwrite existings values
@param {String} url
@param {String} qsName
@param {String} qsValue
@return {String} | [
"appends",
"a",
"querystring",
"to",
"a",
"url",
"path",
"-",
"will",
"overwrite",
"existings",
"values"
] | 8a4a1059f060a7100270e837d2759c6a2b9c7e74 | https://github.com/reptilbud/hapi-swagger/blob/8a4a1059f060a7100270e837d2759c6a2b9c7e74/lib/index.js#L302-L312 |
|
49,122 | reptilbud/hapi-swagger | lib/index.js | function (settings) {
let out = '';
if (settings.securityDefinitions) {
Object.keys(settings.securityDefinitions).forEach((key) => {
if (settings.securityDefinitions[key]['x-keyPrefix']) {
out = settings.securityDefinitions[key]['x-keyPrefix'];
}
});
}
return out;
} | javascript | function (settings) {
let out = '';
if (settings.securityDefinitions) {
Object.keys(settings.securityDefinitions).forEach((key) => {
if (settings.securityDefinitions[key]['x-keyPrefix']) {
out = settings.securityDefinitions[key]['x-keyPrefix'];
}
});
}
return out;
} | [
"function",
"(",
"settings",
")",
"{",
"let",
"out",
"=",
"''",
";",
"if",
"(",
"settings",
".",
"securityDefinitions",
")",
"{",
"Object",
".",
"keys",
"(",
"settings",
".",
"securityDefinitions",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"if",
"(",
"settings",
".",
"securityDefinitions",
"[",
"key",
"]",
"[",
"'x-keyPrefix'",
"]",
")",
"{",
"out",
"=",
"settings",
".",
"securityDefinitions",
"[",
"key",
"]",
"[",
"'x-keyPrefix'",
"]",
";",
"}",
"}",
")",
";",
"}",
"return",
"out",
";",
"}"
] | finds any keyPrefix in securityDefinitions - also add x- to name
@param {Object} settings
@return {String} | [
"finds",
"any",
"keyPrefix",
"in",
"securityDefinitions",
"-",
"also",
"add",
"x",
"-",
"to",
"name"
] | 8a4a1059f060a7100270e837d2759c6a2b9c7e74 | https://github.com/reptilbud/hapi-swagger/blob/8a4a1059f060a7100270e837d2759c6a2b9c7e74/lib/index.js#L321-L333 |
|
49,123 | sendanor/nor-nopg | src/ResourceView.js | render_path | function render_path(path, params) {
params = params || {};
return ARRAY( is.array(path) ? path : [path] ).map(function(p) {
return p.replace(/:([a-z0-9A-Z\_]+)/g, function(match, key) {
if(params[key] === undefined) {
return ':'+key;
}
return ''+fix_object_ids(params[key]);
});
}).valueOf();
} | javascript | function render_path(path, params) {
params = params || {};
return ARRAY( is.array(path) ? path : [path] ).map(function(p) {
return p.replace(/:([a-z0-9A-Z\_]+)/g, function(match, key) {
if(params[key] === undefined) {
return ':'+key;
}
return ''+fix_object_ids(params[key]);
});
}).valueOf();
} | [
"function",
"render_path",
"(",
"path",
",",
"params",
")",
"{",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"return",
"ARRAY",
"(",
"is",
".",
"array",
"(",
"path",
")",
"?",
"path",
":",
"[",
"path",
"]",
")",
".",
"map",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
".",
"replace",
"(",
"/",
":([a-z0-9A-Z\\_]+)",
"/",
"g",
",",
"function",
"(",
"match",
",",
"key",
")",
"{",
"if",
"(",
"params",
"[",
"key",
"]",
"===",
"undefined",
")",
"{",
"return",
"':'",
"+",
"key",
";",
"}",
"return",
"''",
"+",
"fix_object_ids",
"(",
"params",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
")",
".",
"valueOf",
"(",
")",
";",
"}"
] | Render `path` with optional `params` | [
"Render",
"path",
"with",
"optional",
"params"
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/ResourceView.js#L42-L52 |
49,124 | sendanor/nor-nopg | src/ResourceView.js | ResourceView | function ResourceView(opts) {
var view = this;
var compute_keys;
if(opts && opts.compute_keys) {
compute_keys = opts.compute_keys;
}
var element_keys;
if(opts && opts.element_keys) {
element_keys = opts.element_keys;
}
var collection_keys;
if(opts && opts.collection_keys) {
collection_keys = opts.collection_keys;
}
var element_post;
if(opts && opts.element_post) {
element_post = opts.element_post;
}
var collection_post;
if(opts && opts.collection_post) {
collection_post = opts.collection_post;
}
opts = copy(opts || {});
debug.assert(opts).is('object');
debug.assert(opts.path).is('string');
view.opts = {};
view.opts.keys = opts.keys || ['$id', '$type', '$ref'];
view.opts.path = opts.path;
view.opts.elementPath = opts.elementPath;
view.Type = opts.Type;
if(is.obj(compute_keys)) {
view.compute_keys = compute_keys;
}
if(is.obj(element_keys)) {
view.element_keys = element_keys;
}
if(is.obj(collection_keys)) {
view.collection_keys = collection_keys;
}
if(is.func(element_post)) {
view.element_post = element_post;
}
if(is.func(collection_post)) {
view.collection_post = collection_post;
}
//debug.log("view.opts = ", view.opts);
} | javascript | function ResourceView(opts) {
var view = this;
var compute_keys;
if(opts && opts.compute_keys) {
compute_keys = opts.compute_keys;
}
var element_keys;
if(opts && opts.element_keys) {
element_keys = opts.element_keys;
}
var collection_keys;
if(opts && opts.collection_keys) {
collection_keys = opts.collection_keys;
}
var element_post;
if(opts && opts.element_post) {
element_post = opts.element_post;
}
var collection_post;
if(opts && opts.collection_post) {
collection_post = opts.collection_post;
}
opts = copy(opts || {});
debug.assert(opts).is('object');
debug.assert(opts.path).is('string');
view.opts = {};
view.opts.keys = opts.keys || ['$id', '$type', '$ref'];
view.opts.path = opts.path;
view.opts.elementPath = opts.elementPath;
view.Type = opts.Type;
if(is.obj(compute_keys)) {
view.compute_keys = compute_keys;
}
if(is.obj(element_keys)) {
view.element_keys = element_keys;
}
if(is.obj(collection_keys)) {
view.collection_keys = collection_keys;
}
if(is.func(element_post)) {
view.element_post = element_post;
}
if(is.func(collection_post)) {
view.collection_post = collection_post;
}
//debug.log("view.opts = ", view.opts);
} | [
"function",
"ResourceView",
"(",
"opts",
")",
"{",
"var",
"view",
"=",
"this",
";",
"var",
"compute_keys",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"compute_keys",
")",
"{",
"compute_keys",
"=",
"opts",
".",
"compute_keys",
";",
"}",
"var",
"element_keys",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"element_keys",
")",
"{",
"element_keys",
"=",
"opts",
".",
"element_keys",
";",
"}",
"var",
"collection_keys",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"collection_keys",
")",
"{",
"collection_keys",
"=",
"opts",
".",
"collection_keys",
";",
"}",
"var",
"element_post",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"element_post",
")",
"{",
"element_post",
"=",
"opts",
".",
"element_post",
";",
"}",
"var",
"collection_post",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"collection_post",
")",
"{",
"collection_post",
"=",
"opts",
".",
"collection_post",
";",
"}",
"opts",
"=",
"copy",
"(",
"opts",
"||",
"{",
"}",
")",
";",
"debug",
".",
"assert",
"(",
"opts",
")",
".",
"is",
"(",
"'object'",
")",
";",
"debug",
".",
"assert",
"(",
"opts",
".",
"path",
")",
".",
"is",
"(",
"'string'",
")",
";",
"view",
".",
"opts",
"=",
"{",
"}",
";",
"view",
".",
"opts",
".",
"keys",
"=",
"opts",
".",
"keys",
"||",
"[",
"'$id'",
",",
"'$type'",
",",
"'$ref'",
"]",
";",
"view",
".",
"opts",
".",
"path",
"=",
"opts",
".",
"path",
";",
"view",
".",
"opts",
".",
"elementPath",
"=",
"opts",
".",
"elementPath",
";",
"view",
".",
"Type",
"=",
"opts",
".",
"Type",
";",
"if",
"(",
"is",
".",
"obj",
"(",
"compute_keys",
")",
")",
"{",
"view",
".",
"compute_keys",
"=",
"compute_keys",
";",
"}",
"if",
"(",
"is",
".",
"obj",
"(",
"element_keys",
")",
")",
"{",
"view",
".",
"element_keys",
"=",
"element_keys",
";",
"}",
"if",
"(",
"is",
".",
"obj",
"(",
"collection_keys",
")",
")",
"{",
"view",
".",
"collection_keys",
"=",
"collection_keys",
";",
"}",
"if",
"(",
"is",
".",
"func",
"(",
"element_post",
")",
")",
"{",
"view",
".",
"element_post",
"=",
"element_post",
";",
"}",
"if",
"(",
"is",
".",
"func",
"(",
"collection_post",
")",
")",
"{",
"view",
".",
"collection_post",
"=",
"collection_post",
";",
"}",
"//debug.log(\"view.opts = \", view.opts);",
"}"
] | Builds a builder for REST data views | [
"Builds",
"a",
"builder",
"for",
"REST",
"data",
"views"
] | 0d99b86c1a1996b5828b56de8de23700df8bbc0c | https://github.com/sendanor/nor-nopg/blob/0d99b86c1a1996b5828b56de8de23700df8bbc0c/src/ResourceView.js#L55-L116 |
49,125 | thelonious/kld-array-iterators | examples/flatten.js | flatten | function flatten(list) {
return list.reduce(function (acc, item) {
if (Array.isArray(item)) {
return acc.concat(flatten(item));
}
else {
return acc.concat(item);
}
}, []);
} | javascript | function flatten(list) {
return list.reduce(function (acc, item) {
if (Array.isArray(item)) {
return acc.concat(flatten(item));
}
else {
return acc.concat(item);
}
}, []);
} | [
"function",
"flatten",
"(",
"list",
")",
"{",
"return",
"list",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"item",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"item",
")",
")",
"{",
"return",
"acc",
".",
"concat",
"(",
"flatten",
"(",
"item",
")",
")",
";",
"}",
"else",
"{",
"return",
"acc",
".",
"concat",
"(",
"item",
")",
";",
"}",
"}",
",",
"[",
"]",
")",
";",
"}"
] | export utility to flatten nested arrays | [
"export",
"utility",
"to",
"flatten",
"nested",
"arrays"
] | 20fa2ae9ce5f72d9e0b09945365cf44052057dc2 | https://github.com/thelonious/kld-array-iterators/blob/20fa2ae9ce5f72d9e0b09945365cf44052057dc2/examples/flatten.js#L3-L12 |
49,126 | aleclarson/testpass | src/context.js | getFile | function getFile(group) {
while (group) {
if (group.file) return group.file
group = group.parent
}
} | javascript | function getFile(group) {
while (group) {
if (group.file) return group.file
group = group.parent
}
} | [
"function",
"getFile",
"(",
"group",
")",
"{",
"while",
"(",
"group",
")",
"{",
"if",
"(",
"group",
".",
"file",
")",
"return",
"group",
".",
"file",
"group",
"=",
"group",
".",
"parent",
"}",
"}"
] | Find which file the given group is in. | [
"Find",
"which",
"file",
"the",
"given",
"group",
"is",
"in",
"."
] | 023f4d1a9ea525fd3abd3b456e9b604037282326 | https://github.com/aleclarson/testpass/blob/023f4d1a9ea525fd3abd3b456e9b604037282326/src/context.js#L43-L48 |
49,127 | aleclarson/testpass | src/context.js | getContext | function getContext(i) {
if (context) {
return context
} else {
const path = getCallsite(i || 2).getFileName()
const file = files[path]
if (file) return file.group
throw Error(`Test module was not loaded properly: "${path}"`)
}
} | javascript | function getContext(i) {
if (context) {
return context
} else {
const path = getCallsite(i || 2).getFileName()
const file = files[path]
if (file) return file.group
throw Error(`Test module was not loaded properly: "${path}"`)
}
} | [
"function",
"getContext",
"(",
"i",
")",
"{",
"if",
"(",
"context",
")",
"{",
"return",
"context",
"}",
"else",
"{",
"const",
"path",
"=",
"getCallsite",
"(",
"i",
"||",
"2",
")",
".",
"getFileName",
"(",
")",
"const",
"file",
"=",
"files",
"[",
"path",
"]",
"if",
"(",
"file",
")",
"return",
"file",
".",
"group",
"throw",
"Error",
"(",
"`",
"${",
"path",
"}",
"`",
")",
"}",
"}"
] | Create a file if no context exists. | [
"Create",
"a",
"file",
"if",
"no",
"context",
"exists",
"."
] | 023f4d1a9ea525fd3abd3b456e9b604037282326 | https://github.com/aleclarson/testpass/blob/023f4d1a9ea525fd3abd3b456e9b604037282326/src/context.js#L56-L65 |
49,128 | humanise-ai/botmaster-humanise-ware | lib/makeHumaniseWare.js | makeHumaniseWare | function makeHumaniseWare ({
apiKey,
incomingWebhookUrl,
logger,
getHandoffFromUpdate
}) {
if (!apiKey || !incomingWebhookUrl) {
throw new Error('botmaster-humanise-ware requires at least both of apiKey and incomingWebhookUrl parameters to be defined')
}
const HUMANISE_URL = incomingWebhookUrl
if (!logger) {
logger = {
log: debug,
debug: debug,
info: debug,
verbose: debug,
warn: debug,
error: debug
}
}
logger.info(`sending updates to humanise on: ${HUMANISE_URL}`)
const incoming = {
type: 'incoming',
name: 'humanise-wrapped-incoming-ware',
controller: async (bot, update) => {
bot.sendIsTypingMessageTo(update.sender.id, {ignoreMiddleware: true}).catch(err => logger.error(err))
// a few refinements for messenger specific messages before sending to humanise
// will be deprecated in the future
if (bot.type === 'messenger') {
convertPostbacks(bot, update)
convertRefs(bot, update)
convertMessengerThumbsup(bot, update)
}
// updates with no messages are currently not supported. Also,
// not sending back messages that come from a potential humanise bot
// as would just be re-sending to platform that just sent it
if (!update.message || bot.type === 'humanise') {
const debugMessage = !update.message
? 'Got an update with no message, not sending it to humanise'
: 'Got a user update from humanise, not sending it back to them'
logger.verbose(debugMessage)
return
}
// humanise takes in only objects that would be accepted on the various platforms
const userInfo = await bot.getUserInfo(update.sender.id)
if (getHandoffFromUpdate) {
const handoffReason = await getHandoffFromUpdate(update)
if (handoffReason) {
const handoffTag = `<handoff>${handoffReason}</handoff>`
update.message.text
? update.message.text += handoffTag
: update.message.text = handoffTag
}
}
const objectToSend = {
apiKey,
update,
senderType: 'user',
userInfo
}
const requestOptions = {
method: 'POST',
uri: HUMANISE_URL,
json: objectToSend
}
const debugMessage = 'About to send update to humanise'
logger.debug(debugMessage)
await request(requestOptions)
update.senderUserInfo = userInfo
}
}
const outgoing = {
type: 'outgoing',
name: 'humanise-wrapped-outgoing-ware',
controller: async (bot, update, message) => {
// skip if there is no message
if (!message.message) {
return
}
let userInfo
if (update.sender.id === message.recipient.id) {
userInfo = update.senderUserInfo
} else {
// this should never be the case if it is something like an
// an automated answer from an AI
userInfo = bot.getUserInfo(message.recipient.id)
}
const objectToSend = {
apiKey,
update: message,
senderType: 'bot',
userInfo
}
const requestOptions = {
method: 'POST',
uri: HUMANISE_URL,
json: objectToSend
}
await request(requestOptions)
// don't send anything. Your webhook should now be doing that
return 'cancel'
}
}
const humaniseWare = {
incoming,
outgoing
}
return humaniseWare
} | javascript | function makeHumaniseWare ({
apiKey,
incomingWebhookUrl,
logger,
getHandoffFromUpdate
}) {
if (!apiKey || !incomingWebhookUrl) {
throw new Error('botmaster-humanise-ware requires at least both of apiKey and incomingWebhookUrl parameters to be defined')
}
const HUMANISE_URL = incomingWebhookUrl
if (!logger) {
logger = {
log: debug,
debug: debug,
info: debug,
verbose: debug,
warn: debug,
error: debug
}
}
logger.info(`sending updates to humanise on: ${HUMANISE_URL}`)
const incoming = {
type: 'incoming',
name: 'humanise-wrapped-incoming-ware',
controller: async (bot, update) => {
bot.sendIsTypingMessageTo(update.sender.id, {ignoreMiddleware: true}).catch(err => logger.error(err))
// a few refinements for messenger specific messages before sending to humanise
// will be deprecated in the future
if (bot.type === 'messenger') {
convertPostbacks(bot, update)
convertRefs(bot, update)
convertMessengerThumbsup(bot, update)
}
// updates with no messages are currently not supported. Also,
// not sending back messages that come from a potential humanise bot
// as would just be re-sending to platform that just sent it
if (!update.message || bot.type === 'humanise') {
const debugMessage = !update.message
? 'Got an update with no message, not sending it to humanise'
: 'Got a user update from humanise, not sending it back to them'
logger.verbose(debugMessage)
return
}
// humanise takes in only objects that would be accepted on the various platforms
const userInfo = await bot.getUserInfo(update.sender.id)
if (getHandoffFromUpdate) {
const handoffReason = await getHandoffFromUpdate(update)
if (handoffReason) {
const handoffTag = `<handoff>${handoffReason}</handoff>`
update.message.text
? update.message.text += handoffTag
: update.message.text = handoffTag
}
}
const objectToSend = {
apiKey,
update,
senderType: 'user',
userInfo
}
const requestOptions = {
method: 'POST',
uri: HUMANISE_URL,
json: objectToSend
}
const debugMessage = 'About to send update to humanise'
logger.debug(debugMessage)
await request(requestOptions)
update.senderUserInfo = userInfo
}
}
const outgoing = {
type: 'outgoing',
name: 'humanise-wrapped-outgoing-ware',
controller: async (bot, update, message) => {
// skip if there is no message
if (!message.message) {
return
}
let userInfo
if (update.sender.id === message.recipient.id) {
userInfo = update.senderUserInfo
} else {
// this should never be the case if it is something like an
// an automated answer from an AI
userInfo = bot.getUserInfo(message.recipient.id)
}
const objectToSend = {
apiKey,
update: message,
senderType: 'bot',
userInfo
}
const requestOptions = {
method: 'POST',
uri: HUMANISE_URL,
json: objectToSend
}
await request(requestOptions)
// don't send anything. Your webhook should now be doing that
return 'cancel'
}
}
const humaniseWare = {
incoming,
outgoing
}
return humaniseWare
} | [
"function",
"makeHumaniseWare",
"(",
"{",
"apiKey",
",",
"incomingWebhookUrl",
",",
"logger",
",",
"getHandoffFromUpdate",
"}",
")",
"{",
"if",
"(",
"!",
"apiKey",
"||",
"!",
"incomingWebhookUrl",
")",
"{",
"throw",
"new",
"Error",
"(",
"'botmaster-humanise-ware requires at least both of apiKey and incomingWebhookUrl parameters to be defined'",
")",
"}",
"const",
"HUMANISE_URL",
"=",
"incomingWebhookUrl",
"if",
"(",
"!",
"logger",
")",
"{",
"logger",
"=",
"{",
"log",
":",
"debug",
",",
"debug",
":",
"debug",
",",
"info",
":",
"debug",
",",
"verbose",
":",
"debug",
",",
"warn",
":",
"debug",
",",
"error",
":",
"debug",
"}",
"}",
"logger",
".",
"info",
"(",
"`",
"${",
"HUMANISE_URL",
"}",
"`",
")",
"const",
"incoming",
"=",
"{",
"type",
":",
"'incoming'",
",",
"name",
":",
"'humanise-wrapped-incoming-ware'",
",",
"controller",
":",
"async",
"(",
"bot",
",",
"update",
")",
"=>",
"{",
"bot",
".",
"sendIsTypingMessageTo",
"(",
"update",
".",
"sender",
".",
"id",
",",
"{",
"ignoreMiddleware",
":",
"true",
"}",
")",
".",
"catch",
"(",
"err",
"=>",
"logger",
".",
"error",
"(",
"err",
")",
")",
"// a few refinements for messenger specific messages before sending to humanise",
"// will be deprecated in the future",
"if",
"(",
"bot",
".",
"type",
"===",
"'messenger'",
")",
"{",
"convertPostbacks",
"(",
"bot",
",",
"update",
")",
"convertRefs",
"(",
"bot",
",",
"update",
")",
"convertMessengerThumbsup",
"(",
"bot",
",",
"update",
")",
"}",
"// updates with no messages are currently not supported. Also,",
"// not sending back messages that come from a potential humanise bot",
"// as would just be re-sending to platform that just sent it",
"if",
"(",
"!",
"update",
".",
"message",
"||",
"bot",
".",
"type",
"===",
"'humanise'",
")",
"{",
"const",
"debugMessage",
"=",
"!",
"update",
".",
"message",
"?",
"'Got an update with no message, not sending it to humanise'",
":",
"'Got a user update from humanise, not sending it back to them'",
"logger",
".",
"verbose",
"(",
"debugMessage",
")",
"return",
"}",
"// humanise takes in only objects that would be accepted on the various platforms",
"const",
"userInfo",
"=",
"await",
"bot",
".",
"getUserInfo",
"(",
"update",
".",
"sender",
".",
"id",
")",
"if",
"(",
"getHandoffFromUpdate",
")",
"{",
"const",
"handoffReason",
"=",
"await",
"getHandoffFromUpdate",
"(",
"update",
")",
"if",
"(",
"handoffReason",
")",
"{",
"const",
"handoffTag",
"=",
"`",
"${",
"handoffReason",
"}",
"`",
"update",
".",
"message",
".",
"text",
"?",
"update",
".",
"message",
".",
"text",
"+=",
"handoffTag",
":",
"update",
".",
"message",
".",
"text",
"=",
"handoffTag",
"}",
"}",
"const",
"objectToSend",
"=",
"{",
"apiKey",
",",
"update",
",",
"senderType",
":",
"'user'",
",",
"userInfo",
"}",
"const",
"requestOptions",
"=",
"{",
"method",
":",
"'POST'",
",",
"uri",
":",
"HUMANISE_URL",
",",
"json",
":",
"objectToSend",
"}",
"const",
"debugMessage",
"=",
"'About to send update to humanise'",
"logger",
".",
"debug",
"(",
"debugMessage",
")",
"await",
"request",
"(",
"requestOptions",
")",
"update",
".",
"senderUserInfo",
"=",
"userInfo",
"}",
"}",
"const",
"outgoing",
"=",
"{",
"type",
":",
"'outgoing'",
",",
"name",
":",
"'humanise-wrapped-outgoing-ware'",
",",
"controller",
":",
"async",
"(",
"bot",
",",
"update",
",",
"message",
")",
"=>",
"{",
"// skip if there is no message",
"if",
"(",
"!",
"message",
".",
"message",
")",
"{",
"return",
"}",
"let",
"userInfo",
"if",
"(",
"update",
".",
"sender",
".",
"id",
"===",
"message",
".",
"recipient",
".",
"id",
")",
"{",
"userInfo",
"=",
"update",
".",
"senderUserInfo",
"}",
"else",
"{",
"// this should never be the case if it is something like an",
"// an automated answer from an AI",
"userInfo",
"=",
"bot",
".",
"getUserInfo",
"(",
"message",
".",
"recipient",
".",
"id",
")",
"}",
"const",
"objectToSend",
"=",
"{",
"apiKey",
",",
"update",
":",
"message",
",",
"senderType",
":",
"'bot'",
",",
"userInfo",
"}",
"const",
"requestOptions",
"=",
"{",
"method",
":",
"'POST'",
",",
"uri",
":",
"HUMANISE_URL",
",",
"json",
":",
"objectToSend",
"}",
"await",
"request",
"(",
"requestOptions",
")",
"// don't send anything. Your webhook should now be doing that",
"return",
"'cancel'",
"}",
"}",
"const",
"humaniseWare",
"=",
"{",
"incoming",
",",
"outgoing",
"}",
"return",
"humaniseWare",
"}"
] | Make botmaster middleware
@param {$0.apiKey} ApiKey Humanise.AI API Key
@param {$0.incomingWebhookUrl} incomingWebhookUrl Humanise.AI full webhook url that identifies your channel. It ends with your Webhook Id
to humanise should go to. This package will then make calls to: https://alpha.humanise.ai/webhooks/{WebhookId}
@param {$0.logger} [Logger] optional logger with .verbose, .debug, .error, .info, .warning methods
@param {$0.getHandoffFromUpdate} [getHandoffFromUpdate] optional async function that takes a botmaster update and returns 'lowSentiment', 'handoff', 'lowConfidence' or null.
Use this param to dynamically set whether you want to handoff a conversation based on a certain user input message. Sentiment of the
user's message is a good example of how to use this.
@exports | [
"Make",
"botmaster",
"middleware"
] | a94af55ace6a4c90f7f795d84d08ac7f2a920f82 | https://github.com/humanise-ai/botmaster-humanise-ware/blob/a94af55ace6a4c90f7f795d84d08ac7f2a920f82/lib/makeHumaniseWare.js#L15-L136 |
49,129 | ryanlabouve/ember-cli-randoport | lib/randoport.js | checkPort | function checkPort(basePort, callback){
return deasync(function(basePort, callback) {
portfinder.basePort = basePort;
portfinder.getPort(function (err, port) {
callback(null, port);
});
})(basePort);
} | javascript | function checkPort(basePort, callback){
return deasync(function(basePort, callback) {
portfinder.basePort = basePort;
portfinder.getPort(function (err, port) {
callback(null, port);
});
})(basePort);
} | [
"function",
"checkPort",
"(",
"basePort",
",",
"callback",
")",
"{",
"return",
"deasync",
"(",
"function",
"(",
"basePort",
",",
"callback",
")",
"{",
"portfinder",
".",
"basePort",
"=",
"basePort",
";",
"portfinder",
".",
"getPort",
"(",
"function",
"(",
"err",
",",
"port",
")",
"{",
"callback",
"(",
"null",
",",
"port",
")",
";",
"}",
")",
";",
"}",
")",
"(",
"basePort",
")",
";",
"}"
] | Returns the next open port
@method checkPort
@param {Number} port to start checking from
@return {Number} closest open port to one provided | [
"Returns",
"the",
"next",
"open",
"port"
] | 628b3a5fefab6e9228b517648aa1bae2989bd54c | https://github.com/ryanlabouve/ember-cli-randoport/blob/628b3a5fefab6e9228b517648aa1bae2989bd54c/lib/randoport.js#L13-L20 |
49,130 | ryanlabouve/ember-cli-randoport | lib/randoport.js | inBlackList | function inBlackList(port, additionalPorts) {
const blacklist = [4200].concat(additionalPorts || []);
return blacklist.indexOf(port) === -1 ? false : true;
} | javascript | function inBlackList(port, additionalPorts) {
const blacklist = [4200].concat(additionalPorts || []);
return blacklist.indexOf(port) === -1 ? false : true;
} | [
"function",
"inBlackList",
"(",
"port",
",",
"additionalPorts",
")",
"{",
"const",
"blacklist",
"=",
"[",
"4200",
"]",
".",
"concat",
"(",
"additionalPorts",
"||",
"[",
"]",
")",
";",
"return",
"blacklist",
".",
"indexOf",
"(",
"port",
")",
"===",
"-",
"1",
"?",
"false",
":",
"true",
";",
"}"
] | Checks if port is in blacklist
@method inBlackList
@param {Number} port we are checking
@return {Number} additional array of blocked ports | [
"Checks",
"if",
"port",
"is",
"in",
"blacklist"
] | 628b3a5fefab6e9228b517648aa1bae2989bd54c | https://github.com/ryanlabouve/ember-cli-randoport/blob/628b3a5fefab6e9228b517648aa1bae2989bd54c/lib/randoport.js#L28-L31 |
49,131 | blixt/js-starbound-files | lib/btreedb.js | Index | function Index(keySize, block) {
var reader = new SbonReader(block.buffer);
this.level = reader.readUint8();
// Number of keys in this index.
this.keyCount = reader.readInt32();
// The blocks that the keys point to. There will be one extra block in the
// beginning of this list that points to the block to go to if the key being
// searched for is left of the first key in this index.
this.blockIds = new Int32Array(this.keyCount + 1);
this.blockIds[0] = reader.readInt32();
this.keys = [];
// Load all key/block reference pairs.
for (var i = 1; i <= this.keyCount; i++) {
this.keys.push(reader.readByteString(keySize));
this.blockIds[i] = reader.readInt32();
}
} | javascript | function Index(keySize, block) {
var reader = new SbonReader(block.buffer);
this.level = reader.readUint8();
// Number of keys in this index.
this.keyCount = reader.readInt32();
// The blocks that the keys point to. There will be one extra block in the
// beginning of this list that points to the block to go to if the key being
// searched for is left of the first key in this index.
this.blockIds = new Int32Array(this.keyCount + 1);
this.blockIds[0] = reader.readInt32();
this.keys = [];
// Load all key/block reference pairs.
for (var i = 1; i <= this.keyCount; i++) {
this.keys.push(reader.readByteString(keySize));
this.blockIds[i] = reader.readInt32();
}
} | [
"function",
"Index",
"(",
"keySize",
",",
"block",
")",
"{",
"var",
"reader",
"=",
"new",
"SbonReader",
"(",
"block",
".",
"buffer",
")",
";",
"this",
".",
"level",
"=",
"reader",
".",
"readUint8",
"(",
")",
";",
"// Number of keys in this index.",
"this",
".",
"keyCount",
"=",
"reader",
".",
"readInt32",
"(",
")",
";",
"// The blocks that the keys point to. There will be one extra block in the",
"// beginning of this list that points to the block to go to if the key being",
"// searched for is left of the first key in this index.",
"this",
".",
"blockIds",
"=",
"new",
"Int32Array",
"(",
"this",
".",
"keyCount",
"+",
"1",
")",
";",
"this",
".",
"blockIds",
"[",
"0",
"]",
"=",
"reader",
".",
"readInt32",
"(",
")",
";",
"this",
".",
"keys",
"=",
"[",
"]",
";",
"// Load all key/block reference pairs.",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<=",
"this",
".",
"keyCount",
";",
"i",
"++",
")",
"{",
"this",
".",
"keys",
".",
"push",
"(",
"reader",
".",
"readByteString",
"(",
"keySize",
")",
")",
";",
"this",
".",
"blockIds",
"[",
"i",
"]",
"=",
"reader",
".",
"readInt32",
"(",
")",
";",
"}",
"}"
] | Wraps a block object to provide functionality for parsing and scanning an
index. | [
"Wraps",
"a",
"block",
"object",
"to",
"provide",
"functionality",
"for",
"parsing",
"and",
"scanning",
"an",
"index",
"."
] | f20f18e4caee87f940b3d9cbe92cacccee3f8d17 | https://github.com/blixt/js-starbound-files/blob/f20f18e4caee87f940b3d9cbe92cacccee3f8d17/lib/btreedb.js#L107-L128 |
49,132 | BartoszPiwek/FrontBox-Grunt | tasks/autoclass.js | function(className, array) {
var len = array.length;
for (var i = 0; i < len; i++) {
if (array[i].indexOf(className) > -1) {
return i;
}
}
return -1;
} | javascript | function(className, array) {
var len = array.length;
for (var i = 0; i < len; i++) {
if (array[i].indexOf(className) > -1) {
return i;
}
}
return -1;
} | [
"function",
"(",
"className",
",",
"array",
")",
"{",
"var",
"len",
"=",
"array",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"if",
"(",
"array",
"[",
"i",
"]",
".",
"indexOf",
"(",
"className",
")",
">",
"-",
"1",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Return number of usage array | [
"Return",
"number",
"of",
"usage",
"array"
] | 2943638c3ac55b0c6b372bf8238c037858be6d4b | https://github.com/BartoszPiwek/FrontBox-Grunt/blob/2943638c3ac55b0c6b372bf8238c037858be6d4b/tasks/autoclass.js#L49-L57 |
|
49,133 | BartoszPiwek/FrontBox-Grunt | tasks/autoclass.js | function(className) {
for (var i = 0; i < databaseLen; i++) {
if (database["field" + i].regExp.test(className)) {
return i;
}
}
return -1;
} | javascript | function(className) {
for (var i = 0; i < databaseLen; i++) {
if (database["field" + i].regExp.test(className)) {
return i;
}
}
return -1;
} | [
"function",
"(",
"className",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"databaseLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"database",
"[",
"\"field\"",
"+",
"i",
"]",
".",
"regExp",
".",
"test",
"(",
"className",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Return database type number | [
"Return",
"database",
"type",
"number"
] | 2943638c3ac55b0c6b372bf8238c037858be6d4b | https://github.com/BartoszPiwek/FrontBox-Grunt/blob/2943638c3ac55b0c6b372bf8238c037858be6d4b/tasks/autoclass.js#L79-L86 |
|
49,134 | BartoszPiwek/FrontBox-Grunt | tasks/autoclass.js | function(array) {
// Run Functions
regLoop();
// Functions
var addOutputValue = function(objectField, value, property, addon) {
var index = objectField.unit.indexOf(property),
indexInDatabase,
unit;
if (addon === "responsive") {
indexInDatabase = checkClassExist(property, responsiveArray);
if (indexInDatabase === -1) {
unit = objectField.unit[index + 1];
responsiveArray.push([property, unit, value]);
// If array exist
} else if (responsiveArray[indexInDatabase].indexOf(value) === -1) {
responsiveArray[indexInDatabase].push(value);
}
var typedata = checkType(value);
if (typedata !== -1) {
var field = "field" + typedata;
if (!database[field].output) {
database[field].output = [];
}
// grunt.log.writeln(typedata + " " + field + " " + value);
}
return value;
// if (indexInDatabase === -1) {
// console.log("Create new responsive: " + property, unit, value);
// unit = objectField.unit[index + 1];
// responsiveArray.push([property, unit, value]);
// // If array exist
// } else if (responsiveArray[indexInDatabase].indexOf(value) === -1) {
// console.log("Add value to database " + value);
// responsiveArray[indexInDatabase].push(value);
// }
// console.log("Create new responsive: " + property, unit, value);
// return value;
} else {
indexInDatabase = checkClassExist(property, objectField.output);
if (indexInDatabase === -1) {
unit = objectField.unit[index + 1];
objectField.output.push([property, unit, value]);
// If array exist
} else if (objectField.output[indexInDatabase].indexOf(value) === -1) {
objectField.output[indexInDatabase].push(value);
}
}
};
var classProcess = function(name) {
var typedata = checkType(name);
if (typedata !== -1) {
var field = "field" + typedata;
if (!database[field].output) {
database[field].output = [];
}
var checkInField = database[field],
indexDash = name.indexOf(checkInField.gap),
property = name.slice(0, indexDash),
value = name.slice(indexDash + 1, name.length),
addon = false;
if (!database[field].output) {
database[field].output = [];
}
// Check if have addon property - "responsive"
if (database[field].addon === "responsive") {
addon = addOutputValue(database[field], value, property, "responsive");
}
// If don't have addon property
else {
addon = addOutputValue(database[field], value, property);
}
if (addon) {
classProcess(addon);
}
} else {
return false;
}
};
// Variables
var output = [],
len = array.length;
// Loop
for (var i = 0; i < len; i++) {
classProcess(array[i]);
}
return output;
} | javascript | function(array) {
// Run Functions
regLoop();
// Functions
var addOutputValue = function(objectField, value, property, addon) {
var index = objectField.unit.indexOf(property),
indexInDatabase,
unit;
if (addon === "responsive") {
indexInDatabase = checkClassExist(property, responsiveArray);
if (indexInDatabase === -1) {
unit = objectField.unit[index + 1];
responsiveArray.push([property, unit, value]);
// If array exist
} else if (responsiveArray[indexInDatabase].indexOf(value) === -1) {
responsiveArray[indexInDatabase].push(value);
}
var typedata = checkType(value);
if (typedata !== -1) {
var field = "field" + typedata;
if (!database[field].output) {
database[field].output = [];
}
// grunt.log.writeln(typedata + " " + field + " " + value);
}
return value;
// if (indexInDatabase === -1) {
// console.log("Create new responsive: " + property, unit, value);
// unit = objectField.unit[index + 1];
// responsiveArray.push([property, unit, value]);
// // If array exist
// } else if (responsiveArray[indexInDatabase].indexOf(value) === -1) {
// console.log("Add value to database " + value);
// responsiveArray[indexInDatabase].push(value);
// }
// console.log("Create new responsive: " + property, unit, value);
// return value;
} else {
indexInDatabase = checkClassExist(property, objectField.output);
if (indexInDatabase === -1) {
unit = objectField.unit[index + 1];
objectField.output.push([property, unit, value]);
// If array exist
} else if (objectField.output[indexInDatabase].indexOf(value) === -1) {
objectField.output[indexInDatabase].push(value);
}
}
};
var classProcess = function(name) {
var typedata = checkType(name);
if (typedata !== -1) {
var field = "field" + typedata;
if (!database[field].output) {
database[field].output = [];
}
var checkInField = database[field],
indexDash = name.indexOf(checkInField.gap),
property = name.slice(0, indexDash),
value = name.slice(indexDash + 1, name.length),
addon = false;
if (!database[field].output) {
database[field].output = [];
}
// Check if have addon property - "responsive"
if (database[field].addon === "responsive") {
addon = addOutputValue(database[field], value, property, "responsive");
}
// If don't have addon property
else {
addon = addOutputValue(database[field], value, property);
}
if (addon) {
classProcess(addon);
}
} else {
return false;
}
};
// Variables
var output = [],
len = array.length;
// Loop
for (var i = 0; i < len; i++) {
classProcess(array[i]);
}
return output;
} | [
"function",
"(",
"array",
")",
"{",
"// Run Functions",
"regLoop",
"(",
")",
";",
"// Functions",
"var",
"addOutputValue",
"=",
"function",
"(",
"objectField",
",",
"value",
",",
"property",
",",
"addon",
")",
"{",
"var",
"index",
"=",
"objectField",
".",
"unit",
".",
"indexOf",
"(",
"property",
")",
",",
"indexInDatabase",
",",
"unit",
";",
"if",
"(",
"addon",
"===",
"\"responsive\"",
")",
"{",
"indexInDatabase",
"=",
"checkClassExist",
"(",
"property",
",",
"responsiveArray",
")",
";",
"if",
"(",
"indexInDatabase",
"===",
"-",
"1",
")",
"{",
"unit",
"=",
"objectField",
".",
"unit",
"[",
"index",
"+",
"1",
"]",
";",
"responsiveArray",
".",
"push",
"(",
"[",
"property",
",",
"unit",
",",
"value",
"]",
")",
";",
"// If array exist",
"}",
"else",
"if",
"(",
"responsiveArray",
"[",
"indexInDatabase",
"]",
".",
"indexOf",
"(",
"value",
")",
"===",
"-",
"1",
")",
"{",
"responsiveArray",
"[",
"indexInDatabase",
"]",
".",
"push",
"(",
"value",
")",
";",
"}",
"var",
"typedata",
"=",
"checkType",
"(",
"value",
")",
";",
"if",
"(",
"typedata",
"!==",
"-",
"1",
")",
"{",
"var",
"field",
"=",
"\"field\"",
"+",
"typedata",
";",
"if",
"(",
"!",
"database",
"[",
"field",
"]",
".",
"output",
")",
"{",
"database",
"[",
"field",
"]",
".",
"output",
"=",
"[",
"]",
";",
"}",
"// grunt.log.writeln(typedata + \" \" + field + \" \" + value);",
"}",
"return",
"value",
";",
"// if (indexInDatabase === -1) {",
"// console.log(\"Create new responsive: \" + property, unit, value);",
"// unit = objectField.unit[index + 1];",
"// responsiveArray.push([property, unit, value]);",
"// // If array exist",
"// } else if (responsiveArray[indexInDatabase].indexOf(value) === -1) {",
"// console.log(\"Add value to database \" + value);",
"// responsiveArray[indexInDatabase].push(value);",
"// }",
"// console.log(\"Create new responsive: \" + property, unit, value);",
"// return value;",
"}",
"else",
"{",
"indexInDatabase",
"=",
"checkClassExist",
"(",
"property",
",",
"objectField",
".",
"output",
")",
";",
"if",
"(",
"indexInDatabase",
"===",
"-",
"1",
")",
"{",
"unit",
"=",
"objectField",
".",
"unit",
"[",
"index",
"+",
"1",
"]",
";",
"objectField",
".",
"output",
".",
"push",
"(",
"[",
"property",
",",
"unit",
",",
"value",
"]",
")",
";",
"// If array exist",
"}",
"else",
"if",
"(",
"objectField",
".",
"output",
"[",
"indexInDatabase",
"]",
".",
"indexOf",
"(",
"value",
")",
"===",
"-",
"1",
")",
"{",
"objectField",
".",
"output",
"[",
"indexInDatabase",
"]",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"}",
";",
"var",
"classProcess",
"=",
"function",
"(",
"name",
")",
"{",
"var",
"typedata",
"=",
"checkType",
"(",
"name",
")",
";",
"if",
"(",
"typedata",
"!==",
"-",
"1",
")",
"{",
"var",
"field",
"=",
"\"field\"",
"+",
"typedata",
";",
"if",
"(",
"!",
"database",
"[",
"field",
"]",
".",
"output",
")",
"{",
"database",
"[",
"field",
"]",
".",
"output",
"=",
"[",
"]",
";",
"}",
"var",
"checkInField",
"=",
"database",
"[",
"field",
"]",
",",
"indexDash",
"=",
"name",
".",
"indexOf",
"(",
"checkInField",
".",
"gap",
")",
",",
"property",
"=",
"name",
".",
"slice",
"(",
"0",
",",
"indexDash",
")",
",",
"value",
"=",
"name",
".",
"slice",
"(",
"indexDash",
"+",
"1",
",",
"name",
".",
"length",
")",
",",
"addon",
"=",
"false",
";",
"if",
"(",
"!",
"database",
"[",
"field",
"]",
".",
"output",
")",
"{",
"database",
"[",
"field",
"]",
".",
"output",
"=",
"[",
"]",
";",
"}",
"// Check if have addon property - \"responsive\"",
"if",
"(",
"database",
"[",
"field",
"]",
".",
"addon",
"===",
"\"responsive\"",
")",
"{",
"addon",
"=",
"addOutputValue",
"(",
"database",
"[",
"field",
"]",
",",
"value",
",",
"property",
",",
"\"responsive\"",
")",
";",
"}",
"// If don't have addon property",
"else",
"{",
"addon",
"=",
"addOutputValue",
"(",
"database",
"[",
"field",
"]",
",",
"value",
",",
"property",
")",
";",
"}",
"if",
"(",
"addon",
")",
"{",
"classProcess",
"(",
"addon",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
";",
"// Variables",
"var",
"output",
"=",
"[",
"]",
",",
"len",
"=",
"array",
".",
"length",
";",
"// Loop",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"classProcess",
"(",
"array",
"[",
"i",
"]",
")",
";",
"}",
"return",
"output",
";",
"}"
] | Return full array with class | [
"Return",
"full",
"array",
"with",
"class"
] | 2943638c3ac55b0c6b372bf8238c037858be6d4b | https://github.com/BartoszPiwek/FrontBox-Grunt/blob/2943638c3ac55b0c6b372bf8238c037858be6d4b/tasks/autoclass.js#L89-L191 |
|
49,135 | pzlr/build-core | lib/resolve.js | entry | function entry(name = '') {
return path.normalize(path.join(sourceDir, config.entriesDir, name ? `${name}.js` : ''));
} | javascript | function entry(name = '') {
return path.normalize(path.join(sourceDir, config.entriesDir, name ? `${name}.js` : ''));
} | [
"function",
"entry",
"(",
"name",
"=",
"''",
")",
"{",
"return",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"sourceDir",
",",
"config",
".",
"entriesDir",
",",
"name",
"?",
"`",
"${",
"name",
"}",
"`",
":",
"''",
")",
")",
";",
"}"
] | Returns an absolute path to an entry by the specified name
@param {string=} [name] - entry name (if empty, returns path to the entries folder) | [
"Returns",
"an",
"absolute",
"path",
"to",
"an",
"entry",
"by",
"the",
"specified",
"name"
] | 11e20eda500682b9fa62c7804c66be1714df0df4 | https://github.com/pzlr/build-core/blob/11e20eda500682b9fa62c7804c66be1714df0df4/lib/resolve.js#L254-L256 |
49,136 | alexpods/InjectorJS | dist/InjectorJS.js | function(name, factory, object) {
var that = this;
var objects = this._resolveObjects(name, factory, object);
_.each(objects, function(factoryObjects, factory) {
_.each(factoryObjects, function(object, name) {
that._setObjectCreator([name], that._createObjectCreator(factory, object));
});
});
return this;
} | javascript | function(name, factory, object) {
var that = this;
var objects = this._resolveObjects(name, factory, object);
_.each(objects, function(factoryObjects, factory) {
_.each(factoryObjects, function(object, name) {
that._setObjectCreator([name], that._createObjectCreator(factory, object));
});
});
return this;
} | [
"function",
"(",
"name",
",",
"factory",
",",
"object",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"objects",
"=",
"this",
".",
"_resolveObjects",
"(",
"name",
",",
"factory",
",",
"object",
")",
";",
"_",
".",
"each",
"(",
"objects",
",",
"function",
"(",
"factoryObjects",
",",
"factory",
")",
"{",
"_",
".",
"each",
"(",
"factoryObjects",
",",
"function",
"(",
"object",
",",
"name",
")",
"{",
"that",
".",
"_setObjectCreator",
"(",
"[",
"name",
"]",
",",
"that",
".",
"_createObjectCreator",
"(",
"factory",
",",
"object",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Sets new object to the container
@param {string|object} name Object name or hash of the objects
@param {string} factory Factory name
@param {*} object Object or its factory method
@returns {Injector} this
@this {Injector} | [
"Sets",
"new",
"object",
"to",
"the",
"container"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L124-L136 |
|
49,137 | alexpods/InjectorJS | dist/InjectorJS.js | function(name) {
this._checkObject(name);
if (!this._hasObject([name])) {
this._setObject([name], this._getObjectCreator([name]).call())._removeObjectCreator([name]);
}
return this._getObject([name]);
} | javascript | function(name) {
this._checkObject(name);
if (!this._hasObject([name])) {
this._setObject([name], this._getObjectCreator([name]).call())._removeObjectCreator([name]);
}
return this._getObject([name]);
} | [
"function",
"(",
"name",
")",
"{",
"this",
".",
"_checkObject",
"(",
"name",
")",
";",
"if",
"(",
"!",
"this",
".",
"_hasObject",
"(",
"[",
"name",
"]",
")",
")",
"{",
"this",
".",
"_setObject",
"(",
"[",
"name",
"]",
",",
"this",
".",
"_getObjectCreator",
"(",
"[",
"name",
"]",
")",
".",
"call",
"(",
")",
")",
".",
"_removeObjectCreator",
"(",
"[",
"name",
"]",
")",
";",
"}",
"return",
"this",
".",
"_getObject",
"(",
"[",
"name",
"]",
")",
";",
"}"
] | Gets specified object
@param {string} name Object name
@returns {*} Specified object
@throws {Error} if specified object does not exist
@this {Injector} | [
"Gets",
"specified",
"object"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L160-L167 |
|
49,138 | alexpods/InjectorJS | dist/InjectorJS.js | function(name) {
this._checkObject(name);
return (this._hasObject([name]) && this._removeObject([name])) || (this._hasObjectCreator([name]) && this._removeObjectCreator([name]));
} | javascript | function(name) {
this._checkObject(name);
return (this._hasObject([name]) && this._removeObject([name])) || (this._hasObjectCreator([name]) && this._removeObjectCreator([name]));
} | [
"function",
"(",
"name",
")",
"{",
"this",
".",
"_checkObject",
"(",
"name",
")",
";",
"return",
"(",
"this",
".",
"_hasObject",
"(",
"[",
"name",
"]",
")",
"&&",
"this",
".",
"_removeObject",
"(",
"[",
"name",
"]",
")",
")",
"||",
"(",
"this",
".",
"_hasObjectCreator",
"(",
"[",
"name",
"]",
")",
"&&",
"this",
".",
"_removeObjectCreator",
"(",
"[",
"name",
"]",
")",
")",
";",
"}"
] | Removes specified object
@param {string} name Object name
@returns {Injector} this
@throws {Error} if specified object does not exist
@this {Injector} | [
"Removes",
"specified",
"object"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L179-L183 |
|
49,139 | alexpods/InjectorJS | dist/InjectorJS.js | function(name, factory) {
if (_.isUndefined(factory)) {
factory = name;
name = undefined;
}
if (factory && factory.__clazz && factory.__clazz.__isSubclazzOf('/InjectorJS/Factories/Abstract')) {
return this.__setPropertyValue(['factory', factory.getName()], factory);
}
var fields = _.isString(name) ? name.split('.') : name || [];
return this.__setPropertyValue(['factory'].concat(fields), factory);
} | javascript | function(name, factory) {
if (_.isUndefined(factory)) {
factory = name;
name = undefined;
}
if (factory && factory.__clazz && factory.__clazz.__isSubclazzOf('/InjectorJS/Factories/Abstract')) {
return this.__setPropertyValue(['factory', factory.getName()], factory);
}
var fields = _.isString(name) ? name.split('.') : name || [];
return this.__setPropertyValue(['factory'].concat(fields), factory);
} | [
"function",
"(",
"name",
",",
"factory",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"factory",
")",
")",
"{",
"factory",
"=",
"name",
";",
"name",
"=",
"undefined",
";",
"}",
"if",
"(",
"factory",
"&&",
"factory",
".",
"__clazz",
"&&",
"factory",
".",
"__clazz",
".",
"__isSubclazzOf",
"(",
"'/InjectorJS/Factories/Abstract'",
")",
")",
"{",
"return",
"this",
".",
"__setPropertyValue",
"(",
"[",
"'factory'",
",",
"factory",
".",
"getName",
"(",
")",
"]",
",",
"factory",
")",
";",
"}",
"var",
"fields",
"=",
"_",
".",
"isString",
"(",
"name",
")",
"?",
"name",
".",
"split",
"(",
"'.'",
")",
":",
"name",
"||",
"[",
"]",
";",
"return",
"this",
".",
"__setPropertyValue",
"(",
"[",
"'factory'",
"]",
".",
"concat",
"(",
"fields",
")",
",",
"factory",
")",
";",
"}"
] | Sets object factory
@param {string,Factory} name Factory name of factory instance
@param {function|Factory} factory Object factory
@returns {Injector} this
@this {Injector} | [
"Sets",
"object",
"factory"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L194-L207 |
|
49,140 | alexpods/InjectorJS | dist/InjectorJS.js | function(factory) {
var factoryName = _.isString(factory) ? factory : factory.getName();
return this.__hasPropertyValue(['factory', factoryName]);
} | javascript | function(factory) {
var factoryName = _.isString(factory) ? factory : factory.getName();
return this.__hasPropertyValue(['factory', factoryName]);
} | [
"function",
"(",
"factory",
")",
"{",
"var",
"factoryName",
"=",
"_",
".",
"isString",
"(",
"factory",
")",
"?",
"factory",
":",
"factory",
".",
"getName",
"(",
")",
";",
"return",
"this",
".",
"__hasPropertyValue",
"(",
"[",
"'factory'",
",",
"factoryName",
"]",
")",
";",
"}"
] | Checks whether specified factory exist
@param {string|Factory} factory Object factory or its name
@returns {boolean} true if object factory exist
@this {Injector} | [
"Checks",
"whether",
"specified",
"factory",
"exist"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L217-L220 |
|
49,141 | alexpods/InjectorJS | dist/InjectorJS.js | function(name, factory, object) {
var that = this;
var objects = {};
var defaultFactory = this.getDefaultFactory().getName();
if (_.isObject(name)) {
objects = name;
} else {
if (_.isUndefined(object)) {
object = factory;
factory = undefined;
}
if (_.isUndefined(factory)) {
factory = defaultFactory;
}
objects[factory] = {};
objects[factory][name] = object;
}
_.each(objects, function(factoryObjects, factory) {
if (!that.hasFactory(factory)) {
if (!(defaultFactory in objects)) {
objects[defaultFactory] = {};
}
objects[defaultFactory][factory] = factoryObjects;
delete objects[factory];
}
});
return objects;
} | javascript | function(name, factory, object) {
var that = this;
var objects = {};
var defaultFactory = this.getDefaultFactory().getName();
if (_.isObject(name)) {
objects = name;
} else {
if (_.isUndefined(object)) {
object = factory;
factory = undefined;
}
if (_.isUndefined(factory)) {
factory = defaultFactory;
}
objects[factory] = {};
objects[factory][name] = object;
}
_.each(objects, function(factoryObjects, factory) {
if (!that.hasFactory(factory)) {
if (!(defaultFactory in objects)) {
objects[defaultFactory] = {};
}
objects[defaultFactory][factory] = factoryObjects;
delete objects[factory];
}
});
return objects;
} | [
"function",
"(",
"name",
",",
"factory",
",",
"object",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"objects",
"=",
"{",
"}",
";",
"var",
"defaultFactory",
"=",
"this",
".",
"getDefaultFactory",
"(",
")",
".",
"getName",
"(",
")",
";",
"if",
"(",
"_",
".",
"isObject",
"(",
"name",
")",
")",
"{",
"objects",
"=",
"name",
";",
"}",
"else",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"object",
")",
")",
"{",
"object",
"=",
"factory",
";",
"factory",
"=",
"undefined",
";",
"}",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"factory",
")",
")",
"{",
"factory",
"=",
"defaultFactory",
";",
"}",
"objects",
"[",
"factory",
"]",
"=",
"{",
"}",
";",
"objects",
"[",
"factory",
"]",
"[",
"name",
"]",
"=",
"object",
";",
"}",
"_",
".",
"each",
"(",
"objects",
",",
"function",
"(",
"factoryObjects",
",",
"factory",
")",
"{",
"if",
"(",
"!",
"that",
".",
"hasFactory",
"(",
"factory",
")",
")",
"{",
"if",
"(",
"!",
"(",
"defaultFactory",
"in",
"objects",
")",
")",
"{",
"objects",
"[",
"defaultFactory",
"]",
"=",
"{",
"}",
";",
"}",
"objects",
"[",
"defaultFactory",
"]",
"[",
"factory",
"]",
"=",
"factoryObjects",
";",
"delete",
"objects",
"[",
"factory",
"]",
";",
"}",
"}",
")",
";",
"return",
"objects",
";",
"}"
] | Resolves specified objects
@see set() method
@param {string|object} name Object name or hash of the objects
@param {string} factory Factory name
@param {*} object Object or its factory method
@returns {object} Resolved objects
@this {Injector}
@private | [
"Resolves",
"specified",
"objects"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L265-L299 |
|
49,142 | alexpods/InjectorJS | dist/InjectorJS.js | function(factoryName, object) {
if (_.isUndefined(object)) {
object = factoryName;
factoryName = undefined;
}
var that = this;
return function() {
var factory = !_.isUndefined(factoryName) ? that.getFactory(factoryName) : that.getDefaultFactory();
var params = _.isFunction(object) ? object.call(that) : object;
return _.isFunction(factory) ? factory(params) : factory.create(params);
}
} | javascript | function(factoryName, object) {
if (_.isUndefined(object)) {
object = factoryName;
factoryName = undefined;
}
var that = this;
return function() {
var factory = !_.isUndefined(factoryName) ? that.getFactory(factoryName) : that.getDefaultFactory();
var params = _.isFunction(object) ? object.call(that) : object;
return _.isFunction(factory) ? factory(params) : factory.create(params);
}
} | [
"function",
"(",
"factoryName",
",",
"object",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"object",
")",
")",
"{",
"object",
"=",
"factoryName",
";",
"factoryName",
"=",
"undefined",
";",
"}",
"var",
"that",
"=",
"this",
";",
"return",
"function",
"(",
")",
"{",
"var",
"factory",
"=",
"!",
"_",
".",
"isUndefined",
"(",
"factoryName",
")",
"?",
"that",
".",
"getFactory",
"(",
"factoryName",
")",
":",
"that",
".",
"getDefaultFactory",
"(",
")",
";",
"var",
"params",
"=",
"_",
".",
"isFunction",
"(",
"object",
")",
"?",
"object",
".",
"call",
"(",
"that",
")",
":",
"object",
";",
"return",
"_",
".",
"isFunction",
"(",
"factory",
")",
"?",
"factory",
"(",
"params",
")",
":",
"factory",
".",
"create",
"(",
"params",
")",
";",
"}",
"}"
] | Creates object creator
@param {string} factoryName Factory name
@param {*|factory} object Object or its factory function
@returns {Function} Object creator
@this {Injector}
@private | [
"Creates",
"object",
"creator"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L311-L327 |
|
49,143 | alexpods/InjectorJS | dist/InjectorJS.js | function(value, metaData, name, object) {
name = name || 'unknown';
object = object || this;
var that = this;
var processors = this.getProcessor();
_.each(metaData, function(data, option) {
if (!(option in processors)) {
return;
}
value = processors[option].call(that, value, data, name, object);
});
return value;
} | javascript | function(value, metaData, name, object) {
name = name || 'unknown';
object = object || this;
var that = this;
var processors = this.getProcessor();
_.each(metaData, function(data, option) {
if (!(option in processors)) {
return;
}
value = processors[option].call(that, value, data, name, object);
});
return value;
} | [
"function",
"(",
"value",
",",
"metaData",
",",
"name",
",",
"object",
")",
"{",
"name",
"=",
"name",
"||",
"'unknown'",
";",
"object",
"=",
"object",
"||",
"this",
";",
"var",
"that",
"=",
"this",
";",
"var",
"processors",
"=",
"this",
".",
"getProcessor",
"(",
")",
";",
"_",
".",
"each",
"(",
"metaData",
",",
"function",
"(",
"data",
",",
"option",
")",
"{",
"if",
"(",
"!",
"(",
"option",
"in",
"processors",
")",
")",
"{",
"return",
";",
"}",
"value",
"=",
"processors",
"[",
"option",
"]",
".",
"call",
"(",
"that",
",",
"value",
",",
"data",
",",
"name",
",",
"object",
")",
";",
"}",
")",
";",
"return",
"value",
";",
"}"
] | Process parameter value
@param {*} value Parameter value
@param {object} metaData Meta data for parameter
@param {string} name Parameter name
@param {object} object Object of specified parameter
@returns {*} Processed parameter value
@this {ParameterProcessor} | [
"Process",
"parameter",
"value"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L385-L402 |
|
49,144 | alexpods/InjectorJS | dist/InjectorJS.js | function(params) {
var that = this;
var paramsDefinition = this.getParamsDefinition();
var parameterProcessor = this.getParameterProcessor();
_.each(params, function(value, param) {
if (!(param in paramsDefinition)) {
throw new Error('Parameter "' + param + '" does not defined!');
}
params[param] = parameterProcessor.process(value, paramsDefinition[param], param, that);
});
return params;
} | javascript | function(params) {
var that = this;
var paramsDefinition = this.getParamsDefinition();
var parameterProcessor = this.getParameterProcessor();
_.each(params, function(value, param) {
if (!(param in paramsDefinition)) {
throw new Error('Parameter "' + param + '" does not defined!');
}
params[param] = parameterProcessor.process(value, paramsDefinition[param], param, that);
});
return params;
} | [
"function",
"(",
"params",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"paramsDefinition",
"=",
"this",
".",
"getParamsDefinition",
"(",
")",
";",
"var",
"parameterProcessor",
"=",
"this",
".",
"getParameterProcessor",
"(",
")",
";",
"_",
".",
"each",
"(",
"params",
",",
"function",
"(",
"value",
",",
"param",
")",
"{",
"if",
"(",
"!",
"(",
"param",
"in",
"paramsDefinition",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Parameter \"'",
"+",
"param",
"+",
"'\" does not defined!'",
")",
";",
"}",
"params",
"[",
"param",
"]",
"=",
"parameterProcessor",
".",
"process",
"(",
"value",
",",
"paramsDefinition",
"[",
"param",
"]",
",",
"param",
",",
"that",
")",
";",
"}",
")",
";",
"return",
"params",
";",
"}"
] | Process parameters for object creation
@param {object} params Raw object parameters for object creation
@returns {object} Processed object parameters
@this {AbstractFactory} | [
"Process",
"parameters",
"for",
"object",
"creation"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L495-L509 |
|
49,145 | alexpods/InjectorJS | dist/InjectorJS.js | function(params) {
var clazz = this.getClazz();
return clazz(params.name, params.parent, params.deps)
} | javascript | function(params) {
var clazz = this.getClazz();
return clazz(params.name, params.parent, params.deps)
} | [
"function",
"(",
"params",
")",
"{",
"var",
"clazz",
"=",
"this",
".",
"getClazz",
"(",
")",
";",
"return",
"clazz",
"(",
"params",
".",
"name",
",",
"params",
".",
"parent",
",",
"params",
".",
"deps",
")",
"}"
] | Creates clazz using specified processed parameters
@param {object} params Parameters for clazz creation
@returns {*} Created clazz
@this {ClazzFactory} | [
"Creates",
"clazz",
"using",
"specified",
"processed",
"parameters"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L578-L581 |
|
49,146 | alexpods/InjectorJS | dist/InjectorJS.js | function(params) {
// Create '_createService' function for this purpose for parameters applying to clazz constructor.
var service = this._createService(params.class, params.init);
_.each(params.call, function(params, method) {
service[method].apply(service, params);
});
return service;
} | javascript | function(params) {
// Create '_createService' function for this purpose for parameters applying to clazz constructor.
var service = this._createService(params.class, params.init);
_.each(params.call, function(params, method) {
service[method].apply(service, params);
});
return service;
} | [
"function",
"(",
"params",
")",
"{",
"// Create '_createService' function for this purpose for parameters applying to clazz constructor.",
"var",
"service",
"=",
"this",
".",
"_createService",
"(",
"params",
".",
"class",
",",
"params",
".",
"init",
")",
";",
"_",
".",
"each",
"(",
"params",
".",
"call",
",",
"function",
"(",
"params",
",",
"method",
")",
"{",
"service",
"[",
"method",
"]",
".",
"apply",
"(",
"service",
",",
"params",
")",
";",
"}",
")",
";",
"return",
"service",
";",
"}"
] | Creates object using specified processed parameters
@param {object} params Parameters for object creation
@returns {*} Created object
@this {ServiceFactory} | [
"Creates",
"object",
"using",
"specified",
"processed",
"parameters"
] | e808ed504768a7b65b5a3710bd028502ebdedaf0 | https://github.com/alexpods/InjectorJS/blob/e808ed504768a7b65b5a3710bd028502ebdedaf0/dist/InjectorJS.js#L677-L687 |
|
49,147 | Everyplay/backbone-db-indexing-adapter | lib/indexing_db_local.js | function(collection, options, cb) {
this.store().setItem(
options.indexKey,
JSON.stringify([]),
function(err, res) {
cb(err, [], res);
}
);
} | javascript | function(collection, options, cb) {
this.store().setItem(
options.indexKey,
JSON.stringify([]),
function(err, res) {
cb(err, [], res);
}
);
} | [
"function",
"(",
"collection",
",",
"options",
",",
"cb",
")",
"{",
"this",
".",
"store",
"(",
")",
".",
"setItem",
"(",
"options",
".",
"indexKey",
",",
"JSON",
".",
"stringify",
"(",
"[",
"]",
")",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"cb",
"(",
"err",
",",
"[",
"]",
",",
"res",
")",
";",
"}",
")",
";",
"}"
] | removes everything from index | [
"removes",
"everything",
"from",
"index"
] | 9e6e51dd918f4c2e71ef1d478fa9bc7e4eae3112 | https://github.com/Everyplay/backbone-db-indexing-adapter/blob/9e6e51dd918f4c2e71ef1d478fa9bc7e4eae3112/lib/indexing_db_local.js#L131-L139 |
|
49,148 | Everyplay/backbone-db-indexing-adapter | lib/indexing_db_local.js | function(collection, options, cb) {
var ids = [];
var keys = _.isFunction(collection.url) ? collection.url() : collection.url;
keys += options.keys;
debug('findKeys', keys);
this.store().getItem(keys, function(err, data) {
if (data) ids.push(keys);
cb(null, ids);
});
} | javascript | function(collection, options, cb) {
var ids = [];
var keys = _.isFunction(collection.url) ? collection.url() : collection.url;
keys += options.keys;
debug('findKeys', keys);
this.store().getItem(keys, function(err, data) {
if (data) ids.push(keys);
cb(null, ids);
});
} | [
"function",
"(",
"collection",
",",
"options",
",",
"cb",
")",
"{",
"var",
"ids",
"=",
"[",
"]",
";",
"var",
"keys",
"=",
"_",
".",
"isFunction",
"(",
"collection",
".",
"url",
")",
"?",
"collection",
".",
"url",
"(",
")",
":",
"collection",
".",
"url",
";",
"keys",
"+=",
"options",
".",
"keys",
";",
"debug",
"(",
"'findKeys'",
",",
"keys",
")",
";",
"this",
".",
"store",
"(",
")",
".",
"getItem",
"(",
"keys",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"data",
")",
"ids",
".",
"push",
"(",
"keys",
")",
";",
"cb",
"(",
"null",
",",
"ids",
")",
";",
"}",
")",
";",
"}"
] | mock adapter only supports exact match | [
"mock",
"adapter",
"only",
"supports",
"exact",
"match"
] | 9e6e51dd918f4c2e71ef1d478fa9bc7e4eae3112 | https://github.com/Everyplay/backbone-db-indexing-adapter/blob/9e6e51dd918f4c2e71ef1d478fa9bc7e4eae3112/lib/indexing_db_local.js#L156-L165 |
|
49,149 | sbj42/maze-generator-core | src/Maze.js | Cell | function Cell(north, east, south, west) {
this._north = north;
this._east = east;
this._south = south;
this._west = west;
} | javascript | function Cell(north, east, south, west) {
this._north = north;
this._east = east;
this._south = south;
this._west = west;
} | [
"function",
"Cell",
"(",
"north",
",",
"east",
",",
"south",
",",
"west",
")",
"{",
"this",
".",
"_north",
"=",
"north",
";",
"this",
".",
"_east",
"=",
"east",
";",
"this",
".",
"_south",
"=",
"south",
";",
"this",
".",
"_west",
"=",
"west",
";",
"}"
] | A Cell is a wrapper object that makes it easier to
ask for passage information by name.
@constructor
@private
@param {integer} width
@param {integer} height | [
"A",
"Cell",
"is",
"a",
"wrapper",
"object",
"that",
"makes",
"it",
"easier",
"to",
"ask",
"for",
"passage",
"information",
"by",
"name",
"."
] | 0ea4825344ca0e0292edaa77d7ea493ba1eaa1e9 | https://github.com/sbj42/maze-generator-core/blob/0ea4825344ca0e0292edaa77d7ea493ba1eaa1e9/src/Maze.js#L12-L17 |
49,150 | sbj42/maze-generator-core | src/Maze.js | Maze | function Maze(width, height) {
if (width < 0 || height < 0)
throw new Error('invalid size: ' + width + 'x' + height);
this._width = width;
this._height = height;
this._blockWidth = ((width+1)+15) >> 4;
this._grid = new Array(this._blockWidth * (height + 1));
for (var i = 0; i < this._blockWidth * (height + 1); i ++)
this._grid[i] = 0;
} | javascript | function Maze(width, height) {
if (width < 0 || height < 0)
throw new Error('invalid size: ' + width + 'x' + height);
this._width = width;
this._height = height;
this._blockWidth = ((width+1)+15) >> 4;
this._grid = new Array(this._blockWidth * (height + 1));
for (var i = 0; i < this._blockWidth * (height + 1); i ++)
this._grid[i] = 0;
} | [
"function",
"Maze",
"(",
"width",
",",
"height",
")",
"{",
"if",
"(",
"width",
"<",
"0",
"||",
"height",
"<",
"0",
")",
"throw",
"new",
"Error",
"(",
"'invalid size: '",
"+",
"width",
"+",
"'x'",
"+",
"height",
")",
";",
"this",
".",
"_width",
"=",
"width",
";",
"this",
".",
"_height",
"=",
"height",
";",
"this",
".",
"_blockWidth",
"=",
"(",
"(",
"width",
"+",
"1",
")",
"+",
"15",
")",
">>",
"4",
";",
"this",
".",
"_grid",
"=",
"new",
"Array",
"(",
"this",
".",
"_blockWidth",
"*",
"(",
"height",
"+",
"1",
")",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_blockWidth",
"*",
"(",
"height",
"+",
"1",
")",
";",
"i",
"++",
")",
"this",
".",
"_grid",
"[",
"i",
"]",
"=",
"0",
";",
"}"
] | A Maze is a rectangular grid of cells, where each cell
may have passages in each of the cardinal directions.
The maze is initialized with each cell having no passages.
@constructor
@param {integer} width
@param {integer} height | [
"A",
"Maze",
"is",
"a",
"rectangular",
"grid",
"of",
"cells",
"where",
"each",
"cell",
"may",
"have",
"passages",
"in",
"each",
"of",
"the",
"cardinal",
"directions",
".",
"The",
"maze",
"is",
"initialized",
"with",
"each",
"cell",
"having",
"no",
"passages",
"."
] | 0ea4825344ca0e0292edaa77d7ea493ba1eaa1e9 | https://github.com/sbj42/maze-generator-core/blob/0ea4825344ca0e0292edaa77d7ea493ba1eaa1e9/src/Maze.js#L44-L53 |
49,151 | feedhenry/fh-mbaas-middleware | lib/middleware/envMongoDb.js | dropEnvironmentDatabase | function dropEnvironmentDatabase(domain, env, next) {
_getEnvironmentDatabase({
domain: domain,
environment: env
}, function (err, found) {
if (err) {
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get environment',
httpCode: 500
}));
}
if (!found) {
log.logger.info("no environment db for " + env + " moving on");
return next();
}
found.dropDb(config.getConfig(), function dropped(err) {
if (err) {
log.logger.error('Failed to delete model');
return next(common.buildErrorObject({
err: err,
msg: 'Failed to drop environment db',
httpCode: 500
}));
}
found.remove(next);
});
});
} | javascript | function dropEnvironmentDatabase(domain, env, next) {
_getEnvironmentDatabase({
domain: domain,
environment: env
}, function (err, found) {
if (err) {
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get environment',
httpCode: 500
}));
}
if (!found) {
log.logger.info("no environment db for " + env + " moving on");
return next();
}
found.dropDb(config.getConfig(), function dropped(err) {
if (err) {
log.logger.error('Failed to delete model');
return next(common.buildErrorObject({
err: err,
msg: 'Failed to drop environment db',
httpCode: 500
}));
}
found.remove(next);
});
});
} | [
"function",
"dropEnvironmentDatabase",
"(",
"domain",
",",
"env",
",",
"next",
")",
"{",
"_getEnvironmentDatabase",
"(",
"{",
"domain",
":",
"domain",
",",
"environment",
":",
"env",
"}",
",",
"function",
"(",
"err",
",",
"found",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to get environment'",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
"if",
"(",
"!",
"found",
")",
"{",
"log",
".",
"logger",
".",
"info",
"(",
"\"no environment db for \"",
"+",
"env",
"+",
"\" moving on\"",
")",
";",
"return",
"next",
"(",
")",
";",
"}",
"found",
".",
"dropDb",
"(",
"config",
".",
"getConfig",
"(",
")",
",",
"function",
"dropped",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"'Failed to delete model'",
")",
";",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to drop environment db'",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
"found",
".",
"remove",
"(",
"next",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | DropEnvironmentDatabase removes the database for specific environment completely | [
"DropEnvironmentDatabase",
"removes",
"the",
"database",
"for",
"specific",
"environment",
"completely"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/middleware/envMongoDb.js#L14-L42 |
49,152 | feedhenry/fh-mbaas-middleware | lib/middleware/envMongoDb.js | getOrCreateEnvironmentDatabase | function getOrCreateEnvironmentDatabase(req, res, next){
var models = mbaas.getModels();
log.logger.debug('process getOrCreateEnvironmentDatabase request', req.originalUrl , req.body, req.method, req.params);
var domain = req.params.domain;
var env = req.params.environment;
log.logger.debug('process db create request', {domain: domain, env: env} );
_getEnvironmentDatabase({
domain: domain,
environment: env
}, function(err, found){
if(err){
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get mbaas instance',
httpCode: 500
}));
}
log.logger.debug('process db create request AFTER', {domain: domain, env: env} );
if(found){
req.mongoUrl = common.formatDbUri(found.dbConf);
return next();
} else {
// because of the composite unique index on the collection, only the first creation call will succeed.
// NB the req.params should have the mongo.host and mongo.port set !!
var cfg = config.getConfig();
models.Mbaas.createModel(domain, env, cfg, function(err, created){
if(err){
return next(common.buildErrorObject({
err: err,
msg: 'Failed to create mbaas instance',
httpCode: 500
}));
}
created.createDb(cfg, function(err, dbConf){
if(err){
log.logger.error('Failed to create db, delete model');
created.remove(function(removeErr){
if(removeErr){
log.logger.error(removeErr, 'Failed to remove model');
}
return next(common.buildErrorObject({
err: err,
msg: 'Failed to create db for domain ' + domain + ' and env ' + env,
httpCode: 500
}));
});
} else {
req.mongoUrl = common.formatDbUri(dbConf);
next();
}
});
});
}
});
} | javascript | function getOrCreateEnvironmentDatabase(req, res, next){
var models = mbaas.getModels();
log.logger.debug('process getOrCreateEnvironmentDatabase request', req.originalUrl , req.body, req.method, req.params);
var domain = req.params.domain;
var env = req.params.environment;
log.logger.debug('process db create request', {domain: domain, env: env} );
_getEnvironmentDatabase({
domain: domain,
environment: env
}, function(err, found){
if(err){
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get mbaas instance',
httpCode: 500
}));
}
log.logger.debug('process db create request AFTER', {domain: domain, env: env} );
if(found){
req.mongoUrl = common.formatDbUri(found.dbConf);
return next();
} else {
// because of the composite unique index on the collection, only the first creation call will succeed.
// NB the req.params should have the mongo.host and mongo.port set !!
var cfg = config.getConfig();
models.Mbaas.createModel(domain, env, cfg, function(err, created){
if(err){
return next(common.buildErrorObject({
err: err,
msg: 'Failed to create mbaas instance',
httpCode: 500
}));
}
created.createDb(cfg, function(err, dbConf){
if(err){
log.logger.error('Failed to create db, delete model');
created.remove(function(removeErr){
if(removeErr){
log.logger.error(removeErr, 'Failed to remove model');
}
return next(common.buildErrorObject({
err: err,
msg: 'Failed to create db for domain ' + domain + ' and env ' + env,
httpCode: 500
}));
});
} else {
req.mongoUrl = common.formatDbUri(dbConf);
next();
}
});
});
}
});
} | [
"function",
"getOrCreateEnvironmentDatabase",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"models",
"=",
"mbaas",
".",
"getModels",
"(",
")",
";",
"log",
".",
"logger",
".",
"debug",
"(",
"'process getOrCreateEnvironmentDatabase request'",
",",
"req",
".",
"originalUrl",
",",
"req",
".",
"body",
",",
"req",
".",
"method",
",",
"req",
".",
"params",
")",
";",
"var",
"domain",
"=",
"req",
".",
"params",
".",
"domain",
";",
"var",
"env",
"=",
"req",
".",
"params",
".",
"environment",
";",
"log",
".",
"logger",
".",
"debug",
"(",
"'process db create request'",
",",
"{",
"domain",
":",
"domain",
",",
"env",
":",
"env",
"}",
")",
";",
"_getEnvironmentDatabase",
"(",
"{",
"domain",
":",
"domain",
",",
"environment",
":",
"env",
"}",
",",
"function",
"(",
"err",
",",
"found",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to get mbaas instance'",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
"log",
".",
"logger",
".",
"debug",
"(",
"'process db create request AFTER'",
",",
"{",
"domain",
":",
"domain",
",",
"env",
":",
"env",
"}",
")",
";",
"if",
"(",
"found",
")",
"{",
"req",
".",
"mongoUrl",
"=",
"common",
".",
"formatDbUri",
"(",
"found",
".",
"dbConf",
")",
";",
"return",
"next",
"(",
")",
";",
"}",
"else",
"{",
"// because of the composite unique index on the collection, only the first creation call will succeed.",
"// NB the req.params should have the mongo.host and mongo.port set !!",
"var",
"cfg",
"=",
"config",
".",
"getConfig",
"(",
")",
";",
"models",
".",
"Mbaas",
".",
"createModel",
"(",
"domain",
",",
"env",
",",
"cfg",
",",
"function",
"(",
"err",
",",
"created",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to create mbaas instance'",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
"created",
".",
"createDb",
"(",
"cfg",
",",
"function",
"(",
"err",
",",
"dbConf",
")",
"{",
"if",
"(",
"err",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"'Failed to create db, delete model'",
")",
";",
"created",
".",
"remove",
"(",
"function",
"(",
"removeErr",
")",
"{",
"if",
"(",
"removeErr",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"removeErr",
",",
"'Failed to remove model'",
")",
";",
"}",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to create db for domain '",
"+",
"domain",
"+",
"' and env '",
"+",
"env",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"req",
".",
"mongoUrl",
"=",
"common",
".",
"formatDbUri",
"(",
"dbConf",
")",
";",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Function that will return a mongo
@param req
@param res
@param next | [
"Function",
"that",
"will",
"return",
"a",
"mongo"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/middleware/envMongoDb.js#L50-L111 |
49,153 | feedhenry/fh-mbaas-middleware | lib/middleware/envMongoDb.js | getEnvironmentDatabase | function getEnvironmentDatabase(req, res, next){
log.logger.debug('process getEnvironmentDatabase request', req.originalUrl );
_getEnvironmentDatabase({
domain: req.params.domain,
environment: req.params.environment
}, function(err, envDb){
if(err){
log.logger.error('Failed to get mbaas instance', err);
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get mbaas instance',
httpCode: 500
}));
}
if(!envDb){
log.logger.error("No Environment Database Found", err);
return next(common.buildErrorObject({
err: new Error("No Environment Database Found"),
httpCode: 400
}));
}
req.mongoUrl = common.formatDbUri(envDb.dbConf);
log.logger.debug("Found Environment Database", req.mongoUrl);
return next();
});
} | javascript | function getEnvironmentDatabase(req, res, next){
log.logger.debug('process getEnvironmentDatabase request', req.originalUrl );
_getEnvironmentDatabase({
domain: req.params.domain,
environment: req.params.environment
}, function(err, envDb){
if(err){
log.logger.error('Failed to get mbaas instance', err);
return next(common.buildErrorObject({
err: err,
msg: 'Failed to get mbaas instance',
httpCode: 500
}));
}
if(!envDb){
log.logger.error("No Environment Database Found", err);
return next(common.buildErrorObject({
err: new Error("No Environment Database Found"),
httpCode: 400
}));
}
req.mongoUrl = common.formatDbUri(envDb.dbConf);
log.logger.debug("Found Environment Database", req.mongoUrl);
return next();
});
} | [
"function",
"getEnvironmentDatabase",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"log",
".",
"logger",
".",
"debug",
"(",
"'process getEnvironmentDatabase request'",
",",
"req",
".",
"originalUrl",
")",
";",
"_getEnvironmentDatabase",
"(",
"{",
"domain",
":",
"req",
".",
"params",
".",
"domain",
",",
"environment",
":",
"req",
".",
"params",
".",
"environment",
"}",
",",
"function",
"(",
"err",
",",
"envDb",
")",
"{",
"if",
"(",
"err",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"'Failed to get mbaas instance'",
",",
"err",
")",
";",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"err",
",",
"msg",
":",
"'Failed to get mbaas instance'",
",",
"httpCode",
":",
"500",
"}",
")",
")",
";",
"}",
"if",
"(",
"!",
"envDb",
")",
"{",
"log",
".",
"logger",
".",
"error",
"(",
"\"No Environment Database Found\"",
",",
"err",
")",
";",
"return",
"next",
"(",
"common",
".",
"buildErrorObject",
"(",
"{",
"err",
":",
"new",
"Error",
"(",
"\"No Environment Database Found\"",
")",
",",
"httpCode",
":",
"400",
"}",
")",
")",
";",
"}",
"req",
".",
"mongoUrl",
"=",
"common",
".",
"formatDbUri",
"(",
"envDb",
".",
"dbConf",
")",
";",
"log",
".",
"logger",
".",
"debug",
"(",
"\"Found Environment Database\"",
",",
"req",
".",
"mongoUrl",
")",
";",
"return",
"next",
"(",
")",
";",
"}",
")",
";",
"}"
] | Middleware To Get An Environment Database | [
"Middleware",
"To",
"Get",
"An",
"Environment",
"Database"
] | f906e98efbb4b0963bf5137b34b5e0589ba24e69 | https://github.com/feedhenry/fh-mbaas-middleware/blob/f906e98efbb4b0963bf5137b34b5e0589ba24e69/lib/middleware/envMongoDb.js#L120-L150 |
49,154 | crishernandezmaps/liqen-scrapper | src/downloadArticle.js | getMedia | function getMedia (hostname) {
const patterns = {
abc: /abc\.es/,
ara: /ara\.cat/,
elconfidencial: /elconfidencial\.com/,
eldiario: /eldiario\.es/,
elespanol: /elespanol\.com/,
elmundo: /elmundo\.es/,
elpais: /elpais\.com/,
elperiodico: /elperiodico\.com/,
esdiario: /esdiario\.com/,
europapress: /europapress\.es/,
huffingtonpost: /huffingtonpost\.es/,
lainformacion: /lainformacion\.com/,
larazon: /larazon\.es/,
lavanguardia: /lavanguardia\.com/,
lavozdegalicia: /lavozdegalicia\.es/,
libertaddigital: /libertaddigital\.com/,
okdiario: /okdiario\.com/,
publico: /publico\.es/
}
for (const id in patterns) {
if (patterns[id].test(hostname)) {
return id
}
}
return null
} | javascript | function getMedia (hostname) {
const patterns = {
abc: /abc\.es/,
ara: /ara\.cat/,
elconfidencial: /elconfidencial\.com/,
eldiario: /eldiario\.es/,
elespanol: /elespanol\.com/,
elmundo: /elmundo\.es/,
elpais: /elpais\.com/,
elperiodico: /elperiodico\.com/,
esdiario: /esdiario\.com/,
europapress: /europapress\.es/,
huffingtonpost: /huffingtonpost\.es/,
lainformacion: /lainformacion\.com/,
larazon: /larazon\.es/,
lavanguardia: /lavanguardia\.com/,
lavozdegalicia: /lavozdegalicia\.es/,
libertaddigital: /libertaddigital\.com/,
okdiario: /okdiario\.com/,
publico: /publico\.es/
}
for (const id in patterns) {
if (patterns[id].test(hostname)) {
return id
}
}
return null
} | [
"function",
"getMedia",
"(",
"hostname",
")",
"{",
"const",
"patterns",
"=",
"{",
"abc",
":",
"/",
"abc\\.es",
"/",
",",
"ara",
":",
"/",
"ara\\.cat",
"/",
",",
"elconfidencial",
":",
"/",
"elconfidencial\\.com",
"/",
",",
"eldiario",
":",
"/",
"eldiario\\.es",
"/",
",",
"elespanol",
":",
"/",
"elespanol\\.com",
"/",
",",
"elmundo",
":",
"/",
"elmundo\\.es",
"/",
",",
"elpais",
":",
"/",
"elpais\\.com",
"/",
",",
"elperiodico",
":",
"/",
"elperiodico\\.com",
"/",
",",
"esdiario",
":",
"/",
"esdiario\\.com",
"/",
",",
"europapress",
":",
"/",
"europapress\\.es",
"/",
",",
"huffingtonpost",
":",
"/",
"huffingtonpost\\.es",
"/",
",",
"lainformacion",
":",
"/",
"lainformacion\\.com",
"/",
",",
"larazon",
":",
"/",
"larazon\\.es",
"/",
",",
"lavanguardia",
":",
"/",
"lavanguardia\\.com",
"/",
",",
"lavozdegalicia",
":",
"/",
"lavozdegalicia\\.es",
"/",
",",
"libertaddigital",
":",
"/",
"libertaddigital\\.com",
"/",
",",
"okdiario",
":",
"/",
"okdiario\\.com",
"/",
",",
"publico",
":",
"/",
"publico\\.es",
"/",
"}",
"for",
"(",
"const",
"id",
"in",
"patterns",
")",
"{",
"if",
"(",
"patterns",
"[",
"id",
"]",
".",
"test",
"(",
"hostname",
")",
")",
"{",
"return",
"id",
"}",
"}",
"return",
"null",
"}"
] | A full article object
@typedef {Object} Article
@property {string} title - The title of the article
@property {string} html - The content of the article in HTML
@property {string} image - The heading image URI of the article
@property {Date} publishedDate - The publishing date of the article
@property {object} json - Raw JSON object obtained from the article
@private | [
"A",
"full",
"article",
"object"
] | 0462d25359ed13fc8321e85cb6a0d87abece7218 | https://github.com/crishernandezmaps/liqen-scrapper/blob/0462d25359ed13fc8321e85cb6a0d87abece7218/src/downloadArticle.js#L20-L48 |
49,155 | PanthR/panthrMath | panthrMath/basicFunc/gratio.js | delta | function delta(a) {
return lgamma(a) - (a - 0.5) * Math.log(a) + a - 0.5 * Math.log(2 * Math.PI);
} | javascript | function delta(a) {
return lgamma(a) - (a - 0.5) * Math.log(a) + a - 0.5 * Math.log(2 * Math.PI);
} | [
"function",
"delta",
"(",
"a",
")",
"{",
"return",
"lgamma",
"(",
"a",
")",
"-",
"(",
"a",
"-",
"0.5",
")",
"*",
"Math",
".",
"log",
"(",
"a",
")",
"+",
"a",
"-",
"0.5",
"*",
"Math",
".",
"log",
"(",
"2",
"*",
"Math",
".",
"PI",
")",
";",
"}"
] | From equation 3 | [
"From",
"equation",
"3"
] | 54d249ca9903a9535f963da711bd3a87fb229c0b | https://github.com/PanthR/panthrMath/blob/54d249ca9903a9535f963da711bd3a87fb229c0b/panthrMath/basicFunc/gratio.js#L156-L158 |
49,156 | PanthR/panthrMath | panthrMath/basicFunc/gratio.js | findx0SmallA | function findx0SmallA(a, p, q) {
var B, u, temp;
B = q * gamma(a);
if (B > 0.6 || B >= 0.45 && a >= 0.3) {
// use 21
u = B * q > 1e-8 ? Math.pow(p * gamma(a + 1), 1 / a)
: Math.exp(-q / a - eulerGamma);
return u / (1 - u / (a + 1));
}
if (a < 0.3 && B >= 0.35 && B <= 0.6) {
// use 22
temp = Math.exp(-eulerGamma - B);
u = temp * Math.exp(temp);
return temp * Math.exp(u);
}
temp = -Math.log(B);
u = temp - (1 - a) * Math.log(temp);
if (B >= 0.15) {
// use 23, with temp for y and u for v
return temp - (1 - a) * Math.log(u) -
Math.log(1 + (1 - a) / (1 + u));
}
if (B > 0.01) {
// use 24, with temp for y and u for v
return temp - (1 - a) * Math.log(u) - Math.log(
(u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) /
(u * u + (5 - a) * u + 2));
}
// use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1
// using u for c1, temp for y
return findx0TinyB(a, temp);
} | javascript | function findx0SmallA(a, p, q) {
var B, u, temp;
B = q * gamma(a);
if (B > 0.6 || B >= 0.45 && a >= 0.3) {
// use 21
u = B * q > 1e-8 ? Math.pow(p * gamma(a + 1), 1 / a)
: Math.exp(-q / a - eulerGamma);
return u / (1 - u / (a + 1));
}
if (a < 0.3 && B >= 0.35 && B <= 0.6) {
// use 22
temp = Math.exp(-eulerGamma - B);
u = temp * Math.exp(temp);
return temp * Math.exp(u);
}
temp = -Math.log(B);
u = temp - (1 - a) * Math.log(temp);
if (B >= 0.15) {
// use 23, with temp for y and u for v
return temp - (1 - a) * Math.log(u) -
Math.log(1 + (1 - a) / (1 + u));
}
if (B > 0.01) {
// use 24, with temp for y and u for v
return temp - (1 - a) * Math.log(u) - Math.log(
(u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) /
(u * u + (5 - a) * u + 2));
}
// use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1
// using u for c1, temp for y
return findx0TinyB(a, temp);
} | [
"function",
"findx0SmallA",
"(",
"a",
",",
"p",
",",
"q",
")",
"{",
"var",
"B",
",",
"u",
",",
"temp",
";",
"B",
"=",
"q",
"*",
"gamma",
"(",
"a",
")",
";",
"if",
"(",
"B",
">",
"0.6",
"||",
"B",
">=",
"0.45",
"&&",
"a",
">=",
"0.3",
")",
"{",
"// use 21",
"u",
"=",
"B",
"*",
"q",
">",
"1e-8",
"?",
"Math",
".",
"pow",
"(",
"p",
"*",
"gamma",
"(",
"a",
"+",
"1",
")",
",",
"1",
"/",
"a",
")",
":",
"Math",
".",
"exp",
"(",
"-",
"q",
"/",
"a",
"-",
"eulerGamma",
")",
";",
"return",
"u",
"/",
"(",
"1",
"-",
"u",
"/",
"(",
"a",
"+",
"1",
")",
")",
";",
"}",
"if",
"(",
"a",
"<",
"0.3",
"&&",
"B",
">=",
"0.35",
"&&",
"B",
"<=",
"0.6",
")",
"{",
"// use 22",
"temp",
"=",
"Math",
".",
"exp",
"(",
"-",
"eulerGamma",
"-",
"B",
")",
";",
"u",
"=",
"temp",
"*",
"Math",
".",
"exp",
"(",
"temp",
")",
";",
"return",
"temp",
"*",
"Math",
".",
"exp",
"(",
"u",
")",
";",
"}",
"temp",
"=",
"-",
"Math",
".",
"log",
"(",
"B",
")",
";",
"u",
"=",
"temp",
"-",
"(",
"1",
"-",
"a",
")",
"*",
"Math",
".",
"log",
"(",
"temp",
")",
";",
"if",
"(",
"B",
">=",
"0.15",
")",
"{",
"// use 23, with temp for y and u for v",
"return",
"temp",
"-",
"(",
"1",
"-",
"a",
")",
"*",
"Math",
".",
"log",
"(",
"u",
")",
"-",
"Math",
".",
"log",
"(",
"1",
"+",
"(",
"1",
"-",
"a",
")",
"/",
"(",
"1",
"+",
"u",
")",
")",
";",
"}",
"if",
"(",
"B",
">",
"0.01",
")",
"{",
"// use 24, with temp for y and u for v",
"return",
"temp",
"-",
"(",
"1",
"-",
"a",
")",
"*",
"Math",
".",
"log",
"(",
"u",
")",
"-",
"Math",
".",
"log",
"(",
"(",
"u",
"*",
"u",
"+",
"2",
"*",
"(",
"3",
"-",
"a",
")",
"*",
"u",
"+",
"(",
"2",
"-",
"a",
")",
"*",
"(",
"3",
"-",
"a",
")",
")",
"/",
"(",
"u",
"*",
"u",
"+",
"(",
"5",
"-",
"a",
")",
"*",
"u",
"+",
"2",
")",
")",
";",
"}",
"// use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1",
"// using u for c1, temp for y",
"return",
"findx0TinyB",
"(",
"a",
",",
"temp",
")",
";",
"}"
] | Use formulas 21 through 25 from DiDonato to get initial estimate for x when a < 1. | [
"Use",
"formulas",
"21",
"through",
"25",
"from",
"DiDonato",
"to",
"get",
"initial",
"estimate",
"for",
"x",
"when",
"a",
"<",
"1",
"."
] | 54d249ca9903a9535f963da711bd3a87fb229c0b | https://github.com/PanthR/panthrMath/blob/54d249ca9903a9535f963da711bd3a87fb229c0b/panthrMath/basicFunc/gratio.js#L395-L427 |
49,157 | PanthR/panthrMath | panthrMath/basicFunc/gratio.js | f | function f(x, n) {
return Math.exp((logpg + x - Math.log(series(snTerm(x), n + 1))) / a);
} | javascript | function f(x, n) {
return Math.exp((logpg + x - Math.log(series(snTerm(x), n + 1))) / a);
} | [
"function",
"f",
"(",
"x",
",",
"n",
")",
"{",
"return",
"Math",
".",
"exp",
"(",
"(",
"logpg",
"+",
"x",
"-",
"Math",
".",
"log",
"(",
"series",
"(",
"snTerm",
"(",
"x",
")",
",",
"n",
"+",
"1",
")",
")",
")",
"/",
"a",
")",
";",
"}"
] | See formula 34, where `n` is off by 1 | [
"See",
"formula",
"34",
"where",
"n",
"is",
"off",
"by",
"1"
] | 54d249ca9903a9535f963da711bd3a87fb229c0b | https://github.com/PanthR/panthrMath/blob/54d249ca9903a9535f963da711bd3a87fb229c0b/panthrMath/basicFunc/gratio.js#L469-L471 |
49,158 | PanthR/panthrMath | panthrMath/basicFunc/gratio.js | step | function step(x, a, p, q) {
var temp, w;
temp = p <= 0.5 ? gratio(a)(x) - p : q - gratioc(a)(x);
temp /= r(a, x);
w = (a - 1 - x) / 2;
if (Math.max(Math.abs(temp), Math.abs(w * temp)) <= 0.1) {
return x * (1 - (temp + w * temp * temp));
}
return x * (1 - temp);
} | javascript | function step(x, a, p, q) {
var temp, w;
temp = p <= 0.5 ? gratio(a)(x) - p : q - gratioc(a)(x);
temp /= r(a, x);
w = (a - 1 - x) / 2;
if (Math.max(Math.abs(temp), Math.abs(w * temp)) <= 0.1) {
return x * (1 - (temp + w * temp * temp));
}
return x * (1 - temp);
} | [
"function",
"step",
"(",
"x",
",",
"a",
",",
"p",
",",
"q",
")",
"{",
"var",
"temp",
",",
"w",
";",
"temp",
"=",
"p",
"<=",
"0.5",
"?",
"gratio",
"(",
"a",
")",
"(",
"x",
")",
"-",
"p",
":",
"q",
"-",
"gratioc",
"(",
"a",
")",
"(",
"x",
")",
";",
"temp",
"/=",
"r",
"(",
"a",
",",
"x",
")",
";",
"w",
"=",
"(",
"a",
"-",
"1",
"-",
"x",
")",
"/",
"2",
";",
"if",
"(",
"Math",
".",
"max",
"(",
"Math",
".",
"abs",
"(",
"temp",
")",
",",
"Math",
".",
"abs",
"(",
"w",
"*",
"temp",
")",
")",
"<=",
"0.1",
")",
"{",
"return",
"x",
"*",
"(",
"1",
"-",
"(",
"temp",
"+",
"w",
"*",
"temp",
"*",
"temp",
")",
")",
";",
"}",
"return",
"x",
"*",
"(",
"1",
"-",
"temp",
")",
";",
"}"
] | Use Schroeder or Newton-Raphson to do one step of the iteration, formulas 37 and 38. | [
"Use",
"Schroeder",
"or",
"Newton",
"-",
"Raphson",
"to",
"do",
"one",
"step",
"of",
"the",
"iteration",
"formulas",
"37",
"and",
"38",
"."
] | 54d249ca9903a9535f963da711bd3a87fb229c0b | https://github.com/PanthR/panthrMath/blob/54d249ca9903a9535f963da711bd3a87fb229c0b/panthrMath/basicFunc/gratio.js#L514-L524 |
49,159 | novadiscovery/nway | lib/decojs.js | decojs | function decojs(str) {
var i
, curChar, nextChar, lastNoSpaceChar
, inString = false
, inComment = false
, inRegex = false
, onlyComment = false
, newStr = ''
, curLine = ''
, keepLineFeed = false // Keep a line feed after comment
, stringOpenWith
;
for (i = 0; i < str.length; ++i) {
curChar = str.charAt(i);
nextChar = str.charAt(i + 1);
curLine = curLine + '' + curChar;
// In string switcher
if (
!inRegex
&& !inComment
&& (curChar === '"' || curChar === "'")
&& (
(str.charAt(i - 1) !== '\\')
|| (str.charAt(i - 2) + str.charAt(i - 1) == '\\\\')
)
) {
if(inString && (curChar === stringOpenWith)) {
inString = false;
stringOpenWith = null;
} else if(!inString) {
inString = true;
stringOpenWith = curChar;
}
}
// In regex switcher
if((!inComment && !inString) && (curChar === '/')) {
if(inRegex
// Not escaped ... /myregexp\/...../
&& (str.charAt(i - 1) !== '\\')
// Or escape char, previously escaped /myregexp\\/
|| ((str.charAt(i - 1) === '\\') && (str.charAt(i - 2) === '\\'))) {
inRegex = false;
} else {
if(~['=',',','('].indexOf(lastNoSpaceChar)) {
inRegex = true;
}
}
}
if(!~['', ' '].indexOf(curChar)) {
lastNoSpaceChar = curChar;
}
// we are not inside of a string or a regex
if (!inString && !inRegex) {
// Reset current line:
if(curChar == '\n') {
curLine = '';
if(inComment === 2) {
keepLineFeed = true;
}
}
// singleline comment start
if (!inComment && curChar + nextChar === '/'+'/') {
++i;
inComment = 1;
keepLineFeed = (curLine.slice(0,-1).trim() != '');
// singleline comment end
} else if (inComment === 1 && curChar === '\n') {
inComment = false;
curChar = keepLineFeed ? '\n' : '';
// multiline comment start
} else if (!inComment && curChar + nextChar === '/'+'*') {
++i;
inComment = 2;
curChar = '';
// multiline comment end
} else if (inComment === 2 && curChar + nextChar === '*'+'/') {
++i;
inComment = false;
curChar = keepLineFeed ? '\n' : '';
}
if (inComment === 2 && curChar === '\n') {
curChar = '';
} else if (inComment) {
curChar = '';
}
}
newStr += curChar;
}
return newStr;
} | javascript | function decojs(str) {
var i
, curChar, nextChar, lastNoSpaceChar
, inString = false
, inComment = false
, inRegex = false
, onlyComment = false
, newStr = ''
, curLine = ''
, keepLineFeed = false // Keep a line feed after comment
, stringOpenWith
;
for (i = 0; i < str.length; ++i) {
curChar = str.charAt(i);
nextChar = str.charAt(i + 1);
curLine = curLine + '' + curChar;
// In string switcher
if (
!inRegex
&& !inComment
&& (curChar === '"' || curChar === "'")
&& (
(str.charAt(i - 1) !== '\\')
|| (str.charAt(i - 2) + str.charAt(i - 1) == '\\\\')
)
) {
if(inString && (curChar === stringOpenWith)) {
inString = false;
stringOpenWith = null;
} else if(!inString) {
inString = true;
stringOpenWith = curChar;
}
}
// In regex switcher
if((!inComment && !inString) && (curChar === '/')) {
if(inRegex
// Not escaped ... /myregexp\/...../
&& (str.charAt(i - 1) !== '\\')
// Or escape char, previously escaped /myregexp\\/
|| ((str.charAt(i - 1) === '\\') && (str.charAt(i - 2) === '\\'))) {
inRegex = false;
} else {
if(~['=',',','('].indexOf(lastNoSpaceChar)) {
inRegex = true;
}
}
}
if(!~['', ' '].indexOf(curChar)) {
lastNoSpaceChar = curChar;
}
// we are not inside of a string or a regex
if (!inString && !inRegex) {
// Reset current line:
if(curChar == '\n') {
curLine = '';
if(inComment === 2) {
keepLineFeed = true;
}
}
// singleline comment start
if (!inComment && curChar + nextChar === '/'+'/') {
++i;
inComment = 1;
keepLineFeed = (curLine.slice(0,-1).trim() != '');
// singleline comment end
} else if (inComment === 1 && curChar === '\n') {
inComment = false;
curChar = keepLineFeed ? '\n' : '';
// multiline comment start
} else if (!inComment && curChar + nextChar === '/'+'*') {
++i;
inComment = 2;
curChar = '';
// multiline comment end
} else if (inComment === 2 && curChar + nextChar === '*'+'/') {
++i;
inComment = false;
curChar = keepLineFeed ? '\n' : '';
}
if (inComment === 2 && curChar === '\n') {
curChar = '';
} else if (inComment) {
curChar = '';
}
}
newStr += curChar;
}
return newStr;
} | [
"function",
"decojs",
"(",
"str",
")",
"{",
"var",
"i",
",",
"curChar",
",",
"nextChar",
",",
"lastNoSpaceChar",
",",
"inString",
"=",
"false",
",",
"inComment",
"=",
"false",
",",
"inRegex",
"=",
"false",
",",
"onlyComment",
"=",
"false",
",",
"newStr",
"=",
"''",
",",
"curLine",
"=",
"''",
",",
"keepLineFeed",
"=",
"false",
"// Keep a line feed after comment",
",",
"stringOpenWith",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"str",
".",
"length",
";",
"++",
"i",
")",
"{",
"curChar",
"=",
"str",
".",
"charAt",
"(",
"i",
")",
";",
"nextChar",
"=",
"str",
".",
"charAt",
"(",
"i",
"+",
"1",
")",
";",
"curLine",
"=",
"curLine",
"+",
"''",
"+",
"curChar",
";",
"// In string switcher",
"if",
"(",
"!",
"inRegex",
"&&",
"!",
"inComment",
"&&",
"(",
"curChar",
"===",
"'\"'",
"||",
"curChar",
"===",
"\"'\"",
")",
"&&",
"(",
"(",
"str",
".",
"charAt",
"(",
"i",
"-",
"1",
")",
"!==",
"'\\\\'",
")",
"||",
"(",
"str",
".",
"charAt",
"(",
"i",
"-",
"2",
")",
"+",
"str",
".",
"charAt",
"(",
"i",
"-",
"1",
")",
"==",
"'\\\\\\\\'",
")",
")",
")",
"{",
"if",
"(",
"inString",
"&&",
"(",
"curChar",
"===",
"stringOpenWith",
")",
")",
"{",
"inString",
"=",
"false",
";",
"stringOpenWith",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"!",
"inString",
")",
"{",
"inString",
"=",
"true",
";",
"stringOpenWith",
"=",
"curChar",
";",
"}",
"}",
"// In regex switcher",
"if",
"(",
"(",
"!",
"inComment",
"&&",
"!",
"inString",
")",
"&&",
"(",
"curChar",
"===",
"'/'",
")",
")",
"{",
"if",
"(",
"inRegex",
"// Not escaped ... /myregexp\\/...../",
"&&",
"(",
"str",
".",
"charAt",
"(",
"i",
"-",
"1",
")",
"!==",
"'\\\\'",
")",
"// Or escape char, previously escaped /myregexp\\\\/",
"||",
"(",
"(",
"str",
".",
"charAt",
"(",
"i",
"-",
"1",
")",
"===",
"'\\\\'",
")",
"&&",
"(",
"str",
".",
"charAt",
"(",
"i",
"-",
"2",
")",
"===",
"'\\\\'",
")",
")",
")",
"{",
"inRegex",
"=",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"~",
"[",
"'='",
",",
"','",
",",
"'('",
"]",
".",
"indexOf",
"(",
"lastNoSpaceChar",
")",
")",
"{",
"inRegex",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"~",
"[",
"''",
",",
"' '",
"]",
".",
"indexOf",
"(",
"curChar",
")",
")",
"{",
"lastNoSpaceChar",
"=",
"curChar",
";",
"}",
"// we are not inside of a string or a regex",
"if",
"(",
"!",
"inString",
"&&",
"!",
"inRegex",
")",
"{",
"// Reset current line:",
"if",
"(",
"curChar",
"==",
"'\\n'",
")",
"{",
"curLine",
"=",
"''",
";",
"if",
"(",
"inComment",
"===",
"2",
")",
"{",
"keepLineFeed",
"=",
"true",
";",
"}",
"}",
"// singleline comment start",
"if",
"(",
"!",
"inComment",
"&&",
"curChar",
"+",
"nextChar",
"===",
"'/'",
"+",
"'/'",
")",
"{",
"++",
"i",
";",
"inComment",
"=",
"1",
";",
"keepLineFeed",
"=",
"(",
"curLine",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
".",
"trim",
"(",
")",
"!=",
"''",
")",
";",
"// singleline comment end",
"}",
"else",
"if",
"(",
"inComment",
"===",
"1",
"&&",
"curChar",
"===",
"'\\n'",
")",
"{",
"inComment",
"=",
"false",
";",
"curChar",
"=",
"keepLineFeed",
"?",
"'\\n'",
":",
"''",
";",
"// multiline comment start",
"}",
"else",
"if",
"(",
"!",
"inComment",
"&&",
"curChar",
"+",
"nextChar",
"===",
"'/'",
"+",
"'*'",
")",
"{",
"++",
"i",
";",
"inComment",
"=",
"2",
";",
"curChar",
"=",
"''",
";",
"// multiline comment end",
"}",
"else",
"if",
"(",
"inComment",
"===",
"2",
"&&",
"curChar",
"+",
"nextChar",
"===",
"'*'",
"+",
"'/'",
")",
"{",
"++",
"i",
";",
"inComment",
"=",
"false",
";",
"curChar",
"=",
"keepLineFeed",
"?",
"'\\n'",
":",
"''",
";",
"}",
"if",
"(",
"inComment",
"===",
"2",
"&&",
"curChar",
"===",
"'\\n'",
")",
"{",
"curChar",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"inComment",
")",
"{",
"curChar",
"=",
"''",
";",
"}",
"}",
"newStr",
"+=",
"curChar",
";",
"}",
"return",
"newStr",
";",
"}"
] | Remove comment in a source code
decojs() is remove javascript style single line
and multiline comments (// and /*)
@param {string} str The source to de-comment
@return {string} Result string without comment | [
"Remove",
"comment",
"in",
"a",
"source",
"code"
] | fa31c6fe56f2305721e581ac25e8ac9a87e15dda | https://github.com/novadiscovery/nway/blob/fa31c6fe56f2305721e581ac25e8ac9a87e15dda/lib/decojs.js#L38-L136 |
49,160 | tjmehta/validate-reql | lib/validate-reql.js | validateReQL | function validateReQL (reql, reqlOpts, whitelist) {
var args = assertArgs(arguments, {
'reql': '*',
'[reqlOpts]': 'object',
'whitelist': 'array'
})
reql = args.reql
reqlOpts = args.reqlOpts
whitelist = args.whitelist
var firstErr
var errCount = 0
var promises = whitelist.map(function (reqlValidator) {
return validate(reql, reqlOpts, reqlValidator)
.catch(function (err) {
firstErr = firstErr || err
errCount++
})
})
return Promise.all(promises).then(function () {
if (errCount === whitelist.length) {
throw firstErr
} else {
return true
}
})
} | javascript | function validateReQL (reql, reqlOpts, whitelist) {
var args = assertArgs(arguments, {
'reql': '*',
'[reqlOpts]': 'object',
'whitelist': 'array'
})
reql = args.reql
reqlOpts = args.reqlOpts
whitelist = args.whitelist
var firstErr
var errCount = 0
var promises = whitelist.map(function (reqlValidator) {
return validate(reql, reqlOpts, reqlValidator)
.catch(function (err) {
firstErr = firstErr || err
errCount++
})
})
return Promise.all(promises).then(function () {
if (errCount === whitelist.length) {
throw firstErr
} else {
return true
}
})
} | [
"function",
"validateReQL",
"(",
"reql",
",",
"reqlOpts",
",",
"whitelist",
")",
"{",
"var",
"args",
"=",
"assertArgs",
"(",
"arguments",
",",
"{",
"'reql'",
":",
"'*'",
",",
"'[reqlOpts]'",
":",
"'object'",
",",
"'whitelist'",
":",
"'array'",
"}",
")",
"reql",
"=",
"args",
".",
"reql",
"reqlOpts",
"=",
"args",
".",
"reqlOpts",
"whitelist",
"=",
"args",
".",
"whitelist",
"var",
"firstErr",
"var",
"errCount",
"=",
"0",
"var",
"promises",
"=",
"whitelist",
".",
"map",
"(",
"function",
"(",
"reqlValidator",
")",
"{",
"return",
"validate",
"(",
"reql",
",",
"reqlOpts",
",",
"reqlValidator",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"firstErr",
"=",
"firstErr",
"||",
"err",
"errCount",
"++",
"}",
")",
"}",
")",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"errCount",
"===",
"whitelist",
".",
"length",
")",
"{",
"throw",
"firstErr",
"}",
"else",
"{",
"return",
"true",
"}",
"}",
")",
"}"
] | validate reql and reql opts
@param {Object} reql rethinkdb query reql
@param {Object} [reqlOpts] rethinkdb reql opts
@param {Array} whitelist reql validators/queries
@return {Promise.<Boolean>} isValid promise | [
"validate",
"reql",
"and",
"reql",
"opts"
] | e510f5202e3ef0188a0632fff617c69940083785 | https://github.com/tjmehta/validate-reql/blob/e510f5202e3ef0188a0632fff617c69940083785/lib/validate-reql.js#L22-L47 |
49,161 | sendanor/nor-rest | src/request.js | do_plain | function do_plain(url, opts) {
opts = do_args(url, opts);
if(opts.redirect_loop_counter === undefined) {
opts.redirect_loop_counter = 10;
}
var buffer;
var d = Q.defer();
var req = require(opts.protocol).request(opts.url, function(res) {
var buffer = "";
res.setEncoding('utf8');
function collect_chunks(chunk) {
buffer += chunk;
}
res.on('data', collect_chunks);
res.once('end', function() {
res.removeListener('data', collect_chunks);
var content_type = res.headers['content-type'] || undefined;
//debug.log('content_type = ' , content_type);
d.resolve( Q.fcall(function() {
//debug.log('buffer = ', buffer);
//debug.log('res.headers = ', res.headers);
if(res.headers && res.headers['set-cookie']) {
_cookies.set(opts.url, res.headers['set-cookie']);
}
if( (res.statusCode >= 301) && (res.statusCode <= 303) ) {
if(opts.redirect_loop_counter < 0) {
throw new Error('Redirect loop detected');
}
opts.redirect_loop_counter -= 1;
//debug.log('res.statusCode = ', res.statusCode);
//debug.log('res.headers.location = ', res.headers.location);
return do_plain(res.headers.location, {
'method': 'GET',
'headers': {
'accept': opts.url.headers && opts.url.headers.accept
}
});
}
if(!((res.statusCode >= 200) && (res.statusCode < 400))) {
throw new HTTPError(res.statusCode, ((content_type === 'application/json') ? JSON.parse(buffer) : buffer) );
}
return buffer;
}) );
});
}).once('error', function(e) {
d.reject(new TypeError(''+e));
});
if(opts.body && (url.method !== 'GET')) {
buffer = is.string(opts.body) ? opts.body : JSON.stringify(opts.body);
//debug.log('Writing buffer = ', buffer);
req.end( buffer, 'utf8' );
} else {
req.end();
}
return d.promise;
} | javascript | function do_plain(url, opts) {
opts = do_args(url, opts);
if(opts.redirect_loop_counter === undefined) {
opts.redirect_loop_counter = 10;
}
var buffer;
var d = Q.defer();
var req = require(opts.protocol).request(opts.url, function(res) {
var buffer = "";
res.setEncoding('utf8');
function collect_chunks(chunk) {
buffer += chunk;
}
res.on('data', collect_chunks);
res.once('end', function() {
res.removeListener('data', collect_chunks);
var content_type = res.headers['content-type'] || undefined;
//debug.log('content_type = ' , content_type);
d.resolve( Q.fcall(function() {
//debug.log('buffer = ', buffer);
//debug.log('res.headers = ', res.headers);
if(res.headers && res.headers['set-cookie']) {
_cookies.set(opts.url, res.headers['set-cookie']);
}
if( (res.statusCode >= 301) && (res.statusCode <= 303) ) {
if(opts.redirect_loop_counter < 0) {
throw new Error('Redirect loop detected');
}
opts.redirect_loop_counter -= 1;
//debug.log('res.statusCode = ', res.statusCode);
//debug.log('res.headers.location = ', res.headers.location);
return do_plain(res.headers.location, {
'method': 'GET',
'headers': {
'accept': opts.url.headers && opts.url.headers.accept
}
});
}
if(!((res.statusCode >= 200) && (res.statusCode < 400))) {
throw new HTTPError(res.statusCode, ((content_type === 'application/json') ? JSON.parse(buffer) : buffer) );
}
return buffer;
}) );
});
}).once('error', function(e) {
d.reject(new TypeError(''+e));
});
if(opts.body && (url.method !== 'GET')) {
buffer = is.string(opts.body) ? opts.body : JSON.stringify(opts.body);
//debug.log('Writing buffer = ', buffer);
req.end( buffer, 'utf8' );
} else {
req.end();
}
return d.promise;
} | [
"function",
"do_plain",
"(",
"url",
",",
"opts",
")",
"{",
"opts",
"=",
"do_args",
"(",
"url",
",",
"opts",
")",
";",
"if",
"(",
"opts",
".",
"redirect_loop_counter",
"===",
"undefined",
")",
"{",
"opts",
".",
"redirect_loop_counter",
"=",
"10",
";",
"}",
"var",
"buffer",
";",
"var",
"d",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"req",
"=",
"require",
"(",
"opts",
".",
"protocol",
")",
".",
"request",
"(",
"opts",
".",
"url",
",",
"function",
"(",
"res",
")",
"{",
"var",
"buffer",
"=",
"\"\"",
";",
"res",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"function",
"collect_chunks",
"(",
"chunk",
")",
"{",
"buffer",
"+=",
"chunk",
";",
"}",
"res",
".",
"on",
"(",
"'data'",
",",
"collect_chunks",
")",
";",
"res",
".",
"once",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"res",
".",
"removeListener",
"(",
"'data'",
",",
"collect_chunks",
")",
";",
"var",
"content_type",
"=",
"res",
".",
"headers",
"[",
"'content-type'",
"]",
"||",
"undefined",
";",
"//debug.log('content_type = ' , content_type);",
"d",
".",
"resolve",
"(",
"Q",
".",
"fcall",
"(",
"function",
"(",
")",
"{",
"//debug.log('buffer = ', buffer);",
"//debug.log('res.headers = ', res.headers);",
"if",
"(",
"res",
".",
"headers",
"&&",
"res",
".",
"headers",
"[",
"'set-cookie'",
"]",
")",
"{",
"_cookies",
".",
"set",
"(",
"opts",
".",
"url",
",",
"res",
".",
"headers",
"[",
"'set-cookie'",
"]",
")",
";",
"}",
"if",
"(",
"(",
"res",
".",
"statusCode",
">=",
"301",
")",
"&&",
"(",
"res",
".",
"statusCode",
"<=",
"303",
")",
")",
"{",
"if",
"(",
"opts",
".",
"redirect_loop_counter",
"<",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Redirect loop detected'",
")",
";",
"}",
"opts",
".",
"redirect_loop_counter",
"-=",
"1",
";",
"//debug.log('res.statusCode = ', res.statusCode);",
"//debug.log('res.headers.location = ', res.headers.location);",
"return",
"do_plain",
"(",
"res",
".",
"headers",
".",
"location",
",",
"{",
"'method'",
":",
"'GET'",
",",
"'headers'",
":",
"{",
"'accept'",
":",
"opts",
".",
"url",
".",
"headers",
"&&",
"opts",
".",
"url",
".",
"headers",
".",
"accept",
"}",
"}",
")",
";",
"}",
"if",
"(",
"!",
"(",
"(",
"res",
".",
"statusCode",
">=",
"200",
")",
"&&",
"(",
"res",
".",
"statusCode",
"<",
"400",
")",
")",
")",
"{",
"throw",
"new",
"HTTPError",
"(",
"res",
".",
"statusCode",
",",
"(",
"(",
"content_type",
"===",
"'application/json'",
")",
"?",
"JSON",
".",
"parse",
"(",
"buffer",
")",
":",
"buffer",
")",
")",
";",
"}",
"return",
"buffer",
";",
"}",
")",
")",
";",
"}",
")",
";",
"}",
")",
".",
"once",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"d",
".",
"reject",
"(",
"new",
"TypeError",
"(",
"''",
"+",
"e",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"opts",
".",
"body",
"&&",
"(",
"url",
".",
"method",
"!==",
"'GET'",
")",
")",
"{",
"buffer",
"=",
"is",
".",
"string",
"(",
"opts",
".",
"body",
")",
"?",
"opts",
".",
"body",
":",
"JSON",
".",
"stringify",
"(",
"opts",
".",
"body",
")",
";",
"//debug.log('Writing buffer = ', buffer);",
"req",
".",
"end",
"(",
"buffer",
",",
"'utf8'",
")",
";",
"}",
"else",
"{",
"req",
".",
"end",
"(",
")",
";",
"}",
"return",
"d",
".",
"promise",
";",
"}"
] | Performs generic request | [
"Performs",
"generic",
"request"
] | b2571e689c7a7e5129e361a7c66c7e5e946d4ca1 | https://github.com/sendanor/nor-rest/blob/b2571e689c7a7e5129e361a7c66c7e5e946d4ca1/src/request.js#L55-L118 |
49,162 | sendanor/nor-rest | src/request.js | do_js | function do_js(url, opts) {
opts = opts || {};
if(is.object(opts) && is['function'](opts.body)) {
opts.body = FUNCTION(opts.body).stringify();
} else if(is.object(opts) && is.string(opts.body)) {
} else {
throw new TypeError('opts.body is not function nor string');
}
opts.headers = opts.headers || {};
if(opts.body) {
opts.headers['Content-Type'] = 'application/javascript;charset=utf8';
}
// Default method should be POST since JavaScript code usually might change something.
if(!opts.method) {
opts.method = 'post';
}
opts.headers.Accept = 'application/json';
return do_plain(url, opts).then(function(buffer) {
return JSON.parse(buffer);
});
} | javascript | function do_js(url, opts) {
opts = opts || {};
if(is.object(opts) && is['function'](opts.body)) {
opts.body = FUNCTION(opts.body).stringify();
} else if(is.object(opts) && is.string(opts.body)) {
} else {
throw new TypeError('opts.body is not function nor string');
}
opts.headers = opts.headers || {};
if(opts.body) {
opts.headers['Content-Type'] = 'application/javascript;charset=utf8';
}
// Default method should be POST since JavaScript code usually might change something.
if(!opts.method) {
opts.method = 'post';
}
opts.headers.Accept = 'application/json';
return do_plain(url, opts).then(function(buffer) {
return JSON.parse(buffer);
});
} | [
"function",
"do_js",
"(",
"url",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"is",
".",
"object",
"(",
"opts",
")",
"&&",
"is",
"[",
"'function'",
"]",
"(",
"opts",
".",
"body",
")",
")",
"{",
"opts",
".",
"body",
"=",
"FUNCTION",
"(",
"opts",
".",
"body",
")",
".",
"stringify",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is",
".",
"object",
"(",
"opts",
")",
"&&",
"is",
".",
"string",
"(",
"opts",
".",
"body",
")",
")",
"{",
"}",
"else",
"{",
"throw",
"new",
"TypeError",
"(",
"'opts.body is not function nor string'",
")",
";",
"}",
"opts",
".",
"headers",
"=",
"opts",
".",
"headers",
"||",
"{",
"}",
";",
"if",
"(",
"opts",
".",
"body",
")",
"{",
"opts",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/javascript;charset=utf8'",
";",
"}",
"// Default method should be POST since JavaScript code usually might change something.",
"if",
"(",
"!",
"opts",
".",
"method",
")",
"{",
"opts",
".",
"method",
"=",
"'post'",
";",
"}",
"opts",
".",
"headers",
".",
"Accept",
"=",
"'application/json'",
";",
"return",
"do_plain",
"(",
"url",
",",
"opts",
")",
".",
"then",
"(",
"function",
"(",
"buffer",
")",
"{",
"return",
"JSON",
".",
"parse",
"(",
"buffer",
")",
";",
"}",
")",
";",
"}"
] | JavaScript function request | [
"JavaScript",
"function",
"request"
] | b2571e689c7a7e5129e361a7c66c7e5e946d4ca1 | https://github.com/sendanor/nor-rest/blob/b2571e689c7a7e5129e361a7c66c7e5e946d4ca1/src/request.js#L137-L159 |
49,163 | rmariuzzo/entrify | index.js | entrify | function entrify(dir, options = {}) {
if (!dir) {
throw new Error('the path is required')
}
if (typeof dir !== 'string') {
throw new Error('the path must be a string')
}
options = Object.assign({}, defaults, options)
return entrifyFromPkg(dir, options)
} | javascript | function entrify(dir, options = {}) {
if (!dir) {
throw new Error('the path is required')
}
if (typeof dir !== 'string') {
throw new Error('the path must be a string')
}
options = Object.assign({}, defaults, options)
return entrifyFromPkg(dir, options)
} | [
"function",
"entrify",
"(",
"dir",
",",
"options",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"!",
"dir",
")",
"{",
"throw",
"new",
"Error",
"(",
"'the path is required'",
")",
"}",
"if",
"(",
"typeof",
"dir",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'the path must be a string'",
")",
"}",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"defaults",
",",
"options",
")",
"return",
"entrifyFromPkg",
"(",
"dir",
",",
"options",
")",
"}"
] | Entrify a path.
@param {String} dir The path.
@param {Object} options Hash of options. | [
"Entrify",
"a",
"path",
"."
] | cd3f67fea55a78f95ae168cd66c9173d36a446a8 | https://github.com/rmariuzzo/entrify/blob/cd3f67fea55a78f95ae168cd66c9173d36a446a8/index.js#L33-L47 |
49,164 | rmariuzzo/entrify | index.js | entrifyFromPkg | function entrifyFromPkg(dir, options) {
// Find package.json files.
const pkgPaths = glob.sync('**/package.json', { cwd: dir, nodir: true, absolute: true })
pkgPaths.forEach((pkgPath) => {
console.log('[entrify]', 'Found:', pkgPath)
const pkg = require(pkgPath)
// A package.json file should have a main entry.
if (!pkg.main) {
console.warn('[entrify]', pkgPath, 'does not have a main entry.')
return
}
// The main entry should not point to an index.js file.
if (pkg.main === 'index.js' || pkg.main === './index.js') {
console.warn('[entrify]', pkgPath, 'main entry is index.js.')
return
}
// Ensure the index.js file to create doesn't already exist.
const pkgDir = path.dirname(pkgPath)
const indexPath = `${pkgDir}/index.js`
if (fs.existsSync(indexPath)) {
console.warn('[entrify]', indexPath, 'already exists.')
return
}
// Create an index.js file alongside the package.json.
const name = camelize(path.basename(pkgDir))
const main = pkg.main.startsWith('./') ? pkg.main : `./${pkg.main}`
fs.writeFileSync(indexPath, indexTemplate(options.format, { name, main }))
console.log('[entrify]', indexPath, 'created!')
// Delete the package.json file.
fs.unlinkSync(pkgPath)
console.log('[entrify]', pkgPath, 'deleted!')
})
} | javascript | function entrifyFromPkg(dir, options) {
// Find package.json files.
const pkgPaths = glob.sync('**/package.json', { cwd: dir, nodir: true, absolute: true })
pkgPaths.forEach((pkgPath) => {
console.log('[entrify]', 'Found:', pkgPath)
const pkg = require(pkgPath)
// A package.json file should have a main entry.
if (!pkg.main) {
console.warn('[entrify]', pkgPath, 'does not have a main entry.')
return
}
// The main entry should not point to an index.js file.
if (pkg.main === 'index.js' || pkg.main === './index.js') {
console.warn('[entrify]', pkgPath, 'main entry is index.js.')
return
}
// Ensure the index.js file to create doesn't already exist.
const pkgDir = path.dirname(pkgPath)
const indexPath = `${pkgDir}/index.js`
if (fs.existsSync(indexPath)) {
console.warn('[entrify]', indexPath, 'already exists.')
return
}
// Create an index.js file alongside the package.json.
const name = camelize(path.basename(pkgDir))
const main = pkg.main.startsWith('./') ? pkg.main : `./${pkg.main}`
fs.writeFileSync(indexPath, indexTemplate(options.format, { name, main }))
console.log('[entrify]', indexPath, 'created!')
// Delete the package.json file.
fs.unlinkSync(pkgPath)
console.log('[entrify]', pkgPath, 'deleted!')
})
} | [
"function",
"entrifyFromPkg",
"(",
"dir",
",",
"options",
")",
"{",
"// Find package.json files.",
"const",
"pkgPaths",
"=",
"glob",
".",
"sync",
"(",
"'**/package.json'",
",",
"{",
"cwd",
":",
"dir",
",",
"nodir",
":",
"true",
",",
"absolute",
":",
"true",
"}",
")",
"pkgPaths",
".",
"forEach",
"(",
"(",
"pkgPath",
")",
"=>",
"{",
"console",
".",
"log",
"(",
"'[entrify]'",
",",
"'Found:'",
",",
"pkgPath",
")",
"const",
"pkg",
"=",
"require",
"(",
"pkgPath",
")",
"// A package.json file should have a main entry.",
"if",
"(",
"!",
"pkg",
".",
"main",
")",
"{",
"console",
".",
"warn",
"(",
"'[entrify]'",
",",
"pkgPath",
",",
"'does not have a main entry.'",
")",
"return",
"}",
"// The main entry should not point to an index.js file.",
"if",
"(",
"pkg",
".",
"main",
"===",
"'index.js'",
"||",
"pkg",
".",
"main",
"===",
"'./index.js'",
")",
"{",
"console",
".",
"warn",
"(",
"'[entrify]'",
",",
"pkgPath",
",",
"'main entry is index.js.'",
")",
"return",
"}",
"// Ensure the index.js file to create doesn't already exist.",
"const",
"pkgDir",
"=",
"path",
".",
"dirname",
"(",
"pkgPath",
")",
"const",
"indexPath",
"=",
"`",
"${",
"pkgDir",
"}",
"`",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"indexPath",
")",
")",
"{",
"console",
".",
"warn",
"(",
"'[entrify]'",
",",
"indexPath",
",",
"'already exists.'",
")",
"return",
"}",
"// Create an index.js file alongside the package.json.",
"const",
"name",
"=",
"camelize",
"(",
"path",
".",
"basename",
"(",
"pkgDir",
")",
")",
"const",
"main",
"=",
"pkg",
".",
"main",
".",
"startsWith",
"(",
"'./'",
")",
"?",
"pkg",
".",
"main",
":",
"`",
"${",
"pkg",
".",
"main",
"}",
"`",
"fs",
".",
"writeFileSync",
"(",
"indexPath",
",",
"indexTemplate",
"(",
"options",
".",
"format",
",",
"{",
"name",
",",
"main",
"}",
")",
")",
"console",
".",
"log",
"(",
"'[entrify]'",
",",
"indexPath",
",",
"'created!'",
")",
"// Delete the package.json file.",
"fs",
".",
"unlinkSync",
"(",
"pkgPath",
")",
"console",
".",
"log",
"(",
"'[entrify]'",
",",
"pkgPath",
",",
"'deleted!'",
")",
"}",
")",
"}"
] | Entrify a directory by creating an index.js file when a valid package.json is found.
@param {String} dir The directory to entrify.
@param {Object} options Hash of options. | [
"Entrify",
"a",
"directory",
"by",
"creating",
"an",
"index",
".",
"js",
"file",
"when",
"a",
"valid",
"package",
".",
"json",
"is",
"found",
"."
] | cd3f67fea55a78f95ae168cd66c9173d36a446a8 | https://github.com/rmariuzzo/entrify/blob/cd3f67fea55a78f95ae168cd66c9173d36a446a8/index.js#L55-L96 |
49,165 | rmariuzzo/entrify | index.js | indexTemplate | function indexTemplate(format, data) {
if (format === 'cjs') {
return `module.exports = require('${data.main}')`
}
if (format === 'esm') {
return `import ${data.name} from '${data.main}'
export default ${data.name}`
}
} | javascript | function indexTemplate(format, data) {
if (format === 'cjs') {
return `module.exports = require('${data.main}')`
}
if (format === 'esm') {
return `import ${data.name} from '${data.main}'
export default ${data.name}`
}
} | [
"function",
"indexTemplate",
"(",
"format",
",",
"data",
")",
"{",
"if",
"(",
"format",
"===",
"'cjs'",
")",
"{",
"return",
"`",
"${",
"data",
".",
"main",
"}",
"`",
"}",
"if",
"(",
"format",
"===",
"'esm'",
")",
"{",
"return",
"`",
"${",
"data",
".",
"name",
"}",
"${",
"data",
".",
"main",
"}",
"${",
"data",
".",
"name",
"}",
"`",
"}",
"}"
] | Utility functions.
@private
Create contents for an index.js file.
@param {String} format The format to use. 'cjs' or 'esm'.
@param {Object} data The data to use as part of the template. | [
"Utility",
"functions",
"."
] | cd3f67fea55a78f95ae168cd66c9173d36a446a8 | https://github.com/rmariuzzo/entrify/blob/cd3f67fea55a78f95ae168cd66c9173d36a446a8/index.js#L109-L118 |
49,166 | rmariuzzo/entrify | index.js | camelize | function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index === 0 ? letter.toLowerCase() : letter.toUpperCase()
}).replace(/[\s\-_]+/g, '')
} | javascript | function camelize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index === 0 ? letter.toLowerCase() : letter.toUpperCase()
}).replace(/[\s\-_]+/g, '')
} | [
"function",
"camelize",
"(",
"str",
")",
"{",
"return",
"str",
".",
"replace",
"(",
"/",
"(?:^\\w|[A-Z]|\\b\\w)",
"/",
"g",
",",
"(",
"letter",
",",
"index",
")",
"=>",
"{",
"return",
"index",
"===",
"0",
"?",
"letter",
".",
"toLowerCase",
"(",
")",
":",
"letter",
".",
"toUpperCase",
"(",
")",
"}",
")",
".",
"replace",
"(",
"/",
"[\\s\\-_]+",
"/",
"g",
",",
"''",
")",
"}"
] | Convert a string to camelCase.
@param {String} str The string to camelize.
@return {String} The camelized version of the provided string. | [
"Convert",
"a",
"string",
"to",
"camelCase",
"."
] | cd3f67fea55a78f95ae168cd66c9173d36a446a8 | https://github.com/rmariuzzo/entrify/blob/cd3f67fea55a78f95ae168cd66c9173d36a446a8/index.js#L126-L130 |
49,167 | me-ventures/microservice-toolkit | src/swagger/corsMiddleware.js | getOperationResponseHeaders | function getOperationResponseHeaders(operation) {
var headers = [];
if (operation) {
_.each(operation.responses, function(response, responseCode) {
// Convert responseCode to a numeric value for sorting ("default" comes last)
responseCode = parseInt(responseCode) || 999;
_.each(response.headers, function(header, name) {
// We only care about headers that have a default value defined
if (header.default !== undefined) {
headers.push({
order: responseCode,
name: name.toLowerCase(),
value: header.default
});
}
});
});
}
return _.sortBy(headers, 'order');
} | javascript | function getOperationResponseHeaders(operation) {
var headers = [];
if (operation) {
_.each(operation.responses, function(response, responseCode) {
// Convert responseCode to a numeric value for sorting ("default" comes last)
responseCode = parseInt(responseCode) || 999;
_.each(response.headers, function(header, name) {
// We only care about headers that have a default value defined
if (header.default !== undefined) {
headers.push({
order: responseCode,
name: name.toLowerCase(),
value: header.default
});
}
});
});
}
return _.sortBy(headers, 'order');
} | [
"function",
"getOperationResponseHeaders",
"(",
"operation",
")",
"{",
"var",
"headers",
"=",
"[",
"]",
";",
"if",
"(",
"operation",
")",
"{",
"_",
".",
"each",
"(",
"operation",
".",
"responses",
",",
"function",
"(",
"response",
",",
"responseCode",
")",
"{",
"// Convert responseCode to a numeric value for sorting (\"default\" comes last)",
"responseCode",
"=",
"parseInt",
"(",
"responseCode",
")",
"||",
"999",
";",
"_",
".",
"each",
"(",
"response",
".",
"headers",
",",
"function",
"(",
"header",
",",
"name",
")",
"{",
"// We only care about headers that have a default value defined",
"if",
"(",
"header",
".",
"default",
"!==",
"undefined",
")",
"{",
"headers",
".",
"push",
"(",
"{",
"order",
":",
"responseCode",
",",
"name",
":",
"name",
".",
"toLowerCase",
"(",
")",
",",
"value",
":",
"header",
".",
"default",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"_",
".",
"sortBy",
"(",
"headers",
",",
"'order'",
")",
";",
"}"
] | Returns all response headers for the given Swagger operation, sorted by HTTP response code.
@param {object} operation - The Operation object from the Swagger API
@returns {{responseCode: integer, name: string, value: string}[]} | [
"Returns",
"all",
"response",
"headers",
"for",
"the",
"given",
"Swagger",
"operation",
"sorted",
"by",
"HTTP",
"response",
"code",
"."
] | 9aedc9542dffdc274a5142515bd22e92833220d2 | https://github.com/me-ventures/microservice-toolkit/blob/9aedc9542dffdc274a5142515bd22e92833220d2/src/swagger/corsMiddleware.js#L141-L163 |
49,168 | wunderbyte/grunt-spiritual-edbml | src/header.js | cast | function cast(string) {
var result = String(string);
switch (result) {
case 'null':
result = null;
break;
case 'true':
case 'false':
result = result === 'true';
break;
default:
if (String(parseInt(result, 10)) === result) {
result = parseInt(result, 10);
} else if (String(parseFloat(result)) === result) {
result = parseFloat(result);
}
break;
}
return result === '' ? true : result;
} | javascript | function cast(string) {
var result = String(string);
switch (result) {
case 'null':
result = null;
break;
case 'true':
case 'false':
result = result === 'true';
break;
default:
if (String(parseInt(result, 10)) === result) {
result = parseInt(result, 10);
} else if (String(parseFloat(result)) === result) {
result = parseFloat(result);
}
break;
}
return result === '' ? true : result;
} | [
"function",
"cast",
"(",
"string",
")",
"{",
"var",
"result",
"=",
"String",
"(",
"string",
")",
";",
"switch",
"(",
"result",
")",
"{",
"case",
"'null'",
":",
"result",
"=",
"null",
";",
"break",
";",
"case",
"'true'",
":",
"case",
"'false'",
":",
"result",
"=",
"result",
"===",
"'true'",
";",
"break",
";",
"default",
":",
"if",
"(",
"String",
"(",
"parseInt",
"(",
"result",
",",
"10",
")",
")",
"===",
"result",
")",
"{",
"result",
"=",
"parseInt",
"(",
"result",
",",
"10",
")",
";",
"}",
"else",
"if",
"(",
"String",
"(",
"parseFloat",
"(",
"result",
")",
")",
"===",
"result",
")",
"{",
"result",
"=",
"parseFloat",
"(",
"result",
")",
";",
"}",
"break",
";",
"}",
"return",
"result",
"===",
"''",
"?",
"true",
":",
"result",
";",
"}"
] | Autocast string to an inferred type. "123" returns a number
while "true" and false" return a boolean. Empty string evals
to `true` in order to support HTML attribute minimization.
@param {string} string
@returns {object} | [
"Autocast",
"string",
"to",
"an",
"inferred",
"type",
".",
"123",
"returns",
"a",
"number",
"while",
"true",
"and",
"false",
"return",
"a",
"boolean",
".",
"Empty",
"string",
"evals",
"to",
"true",
"in",
"order",
"to",
"support",
"HTML",
"attribute",
"minimization",
"."
] | 2ba0aa8042eceee917f1ee48c7881345df3bce46 | https://github.com/wunderbyte/grunt-spiritual-edbml/blob/2ba0aa8042eceee917f1ee48c7881345df3bce46/src/header.js#L23-L42 |
49,169 | moov2/grunt-orchard-development | tasks/remove-modules.js | function (srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
} | javascript | function (srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
} | [
"function",
"(",
"srcpath",
")",
"{",
"return",
"fs",
".",
"readdirSync",
"(",
"srcpath",
")",
".",
"filter",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"srcpath",
",",
"file",
")",
")",
".",
"isDirectory",
"(",
")",
";",
"}",
")",
";",
"}"
] | Returns directories inside the directory associated to the provided path. | [
"Returns",
"directories",
"inside",
"the",
"directory",
"associated",
"to",
"the",
"provided",
"path",
"."
] | 658c5bae73f894469d099a7c2d735f9cda08d0cc | https://github.com/moov2/grunt-orchard-development/blob/658c5bae73f894469d099a7c2d735f9cda08d0cc/tasks/remove-modules.js#L26-L30 |
|
49,170 | moov2/grunt-orchard-development | tasks/remove-modules.js | function (csprojFilePath, success, error) {
var parser = new xml2js.Parser(),
projectGuid;
fs.readFile(csprojFilePath, function(err, data) {
if (typeof(data) !== 'undefined') {
parser.parseString(data, function (err, result) {
if (typeof(result) !== 'undefined') {
projectGuid = JSON.stringify(result.Project.PropertyGroup[0].ProjectGuid[0].toString());
projectGuid = projectGuid.replace(/"/g, '');
success(projectGuid);
} else {
error(err);
}
});
} else {
error(err);
}
});
} | javascript | function (csprojFilePath, success, error) {
var parser = new xml2js.Parser(),
projectGuid;
fs.readFile(csprojFilePath, function(err, data) {
if (typeof(data) !== 'undefined') {
parser.parseString(data, function (err, result) {
if (typeof(result) !== 'undefined') {
projectGuid = JSON.stringify(result.Project.PropertyGroup[0].ProjectGuid[0].toString());
projectGuid = projectGuid.replace(/"/g, '');
success(projectGuid);
} else {
error(err);
}
});
} else {
error(err);
}
});
} | [
"function",
"(",
"csprojFilePath",
",",
"success",
",",
"error",
")",
"{",
"var",
"parser",
"=",
"new",
"xml2js",
".",
"Parser",
"(",
")",
",",
"projectGuid",
";",
"fs",
".",
"readFile",
"(",
"csprojFilePath",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"typeof",
"(",
"data",
")",
"!==",
"'undefined'",
")",
"{",
"parser",
".",
"parseString",
"(",
"data",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"typeof",
"(",
"result",
")",
"!==",
"'undefined'",
")",
"{",
"projectGuid",
"=",
"JSON",
".",
"stringify",
"(",
"result",
".",
"Project",
".",
"PropertyGroup",
"[",
"0",
"]",
".",
"ProjectGuid",
"[",
"0",
"]",
".",
"toString",
"(",
")",
")",
";",
"projectGuid",
"=",
"projectGuid",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"''",
")",
";",
"success",
"(",
"projectGuid",
")",
";",
"}",
"else",
"{",
"error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"error",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] | Extracts the project GUID from the provided .csproj file. | [
"Extracts",
"the",
"project",
"GUID",
"from",
"the",
"provided",
".",
"csproj",
"file",
"."
] | 658c5bae73f894469d099a7c2d735f9cda08d0cc | https://github.com/moov2/grunt-orchard-development/blob/658c5bae73f894469d099a7c2d735f9cda08d0cc/tasks/remove-modules.js#L35-L54 |
|
49,171 | moov2/grunt-orchard-development | tasks/remove-modules.js | function () {
fs.writeFile(solutionFile, solutionFileContents, function(err) {
if (err) {
grunt.fail.warning('Failed to update solution file.');
}
done();
});
} | javascript | function () {
fs.writeFile(solutionFile, solutionFileContents, function(err) {
if (err) {
grunt.fail.warning('Failed to update solution file.');
}
done();
});
} | [
"function",
"(",
")",
"{",
"fs",
".",
"writeFile",
"(",
"solutionFile",
",",
"solutionFileContents",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"grunt",
".",
"fail",
".",
"warning",
"(",
"'Failed to update solution file.'",
")",
";",
"}",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
] | Writes the update contents of the solution to file. | [
"Writes",
"the",
"update",
"contents",
"of",
"the",
"solution",
"to",
"file",
"."
] | 658c5bae73f894469d099a7c2d735f9cda08d0cc | https://github.com/moov2/grunt-orchard-development/blob/658c5bae73f894469d099a7c2d735f9cda08d0cc/tasks/remove-modules.js#L84-L92 |
|
49,172 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | storeActors | function storeActors() {
test.actorsStored = 0;
for (var i = 0; i < test.actorsInfo.length; i++) {
test.actor.set('ID', null);
test.actor.set('name', test.actorsInfo[i][0]);
test.actor.set('born', test.actorsInfo[i][1]);
test.actor.set('isMale', test.actorsInfo[i][2]);
storeBeingTested.putModel(test.actor, actorStored);
}
} | javascript | function storeActors() {
test.actorsStored = 0;
for (var i = 0; i < test.actorsInfo.length; i++) {
test.actor.set('ID', null);
test.actor.set('name', test.actorsInfo[i][0]);
test.actor.set('born', test.actorsInfo[i][1]);
test.actor.set('isMale', test.actorsInfo[i][2]);
storeBeingTested.putModel(test.actor, actorStored);
}
} | [
"function",
"storeActors",
"(",
")",
"{",
"test",
".",
"actorsStored",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"test",
".",
"actorsInfo",
".",
"length",
";",
"i",
"++",
")",
"{",
"test",
".",
"actor",
".",
"set",
"(",
"'ID'",
",",
"null",
")",
";",
"test",
".",
"actor",
".",
"set",
"(",
"'name'",
",",
"test",
".",
"actorsInfo",
"[",
"i",
"]",
"[",
"0",
"]",
")",
";",
"test",
".",
"actor",
".",
"set",
"(",
"'born'",
",",
"test",
".",
"actorsInfo",
"[",
"i",
"]",
"[",
"1",
"]",
")",
";",
"test",
".",
"actor",
".",
"set",
"(",
"'isMale'",
",",
"test",
".",
"actorsInfo",
"[",
"i",
"]",
"[",
"2",
"]",
")",
";",
"storeBeingTested",
".",
"putModel",
"(",
"test",
".",
"actor",
",",
"actorStored",
")",
";",
"}",
"}"
] | callback after model cleaned now, build List and add to store | [
"callback",
"after",
"model",
"cleaned",
"now",
"build",
"List",
"and",
"add",
"to",
"store"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L1617-L1626 |
49,173 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | actorStored | function actorStored(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
if (++test.actorsStored >= test.actorsInfo.length) {
getAllActors();
}
} | javascript | function actorStored(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
if (++test.actorsStored >= test.actorsInfo.length) {
getAllActors();
}
} | [
"function",
"actorStored",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"if",
"(",
"++",
"test",
".",
"actorsStored",
">=",
"test",
".",
"actorsInfo",
".",
"length",
")",
"{",
"getAllActors",
"(",
")",
";",
"}",
"}"
] | callback after actor stored | [
"callback",
"after",
"actor",
"stored"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L1629-L1637 |
49,174 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | getAllActors | function getAllActors() {
try {
storeBeingTested.getList(test.list, {}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
test.shouldBeTrue(list._items.length == 20, '20');
getTomHanks();
});
}
catch (err) {
callback(err);
}
} | javascript | function getAllActors() {
try {
storeBeingTested.getList(test.list, {}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
test.shouldBeTrue(list._items.length == 20, '20');
getTomHanks();
});
}
catch (err) {
callback(err);
}
} | [
"function",
"getAllActors",
"(",
")",
"{",
"try",
"{",
"storeBeingTested",
".",
"getList",
"(",
"test",
".",
"list",
",",
"{",
"}",
",",
"function",
"(",
"list",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"_items",
".",
"length",
"==",
"20",
",",
"'20'",
")",
";",
"getTomHanks",
"(",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}"
] | test getting all 20 | [
"test",
"getting",
"all",
"20"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L1640-L1654 |
49,175 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | getTomHanks | function getTomHanks() {
try {
storeBeingTested.getList(test.list, {name: "Tom Hanks"}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
test.shouldBeTrue(list._items.length == 1, ('1 not ' + list._items.length));
getD();
});
}
catch (err) {
callback(err);
}
} | javascript | function getTomHanks() {
try {
storeBeingTested.getList(test.list, {name: "Tom Hanks"}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
test.shouldBeTrue(list._items.length == 1, ('1 not ' + list._items.length));
getD();
});
}
catch (err) {
callback(err);
}
} | [
"function",
"getTomHanks",
"(",
")",
"{",
"try",
"{",
"storeBeingTested",
".",
"getList",
"(",
"test",
".",
"list",
",",
"{",
"name",
":",
"\"Tom Hanks\"",
"}",
",",
"function",
"(",
"list",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"_items",
".",
"length",
"==",
"1",
",",
"(",
"'1 not '",
"+",
"list",
".",
"_items",
".",
"length",
")",
")",
";",
"getD",
"(",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}"
] | only one Tom Hanks | [
"only",
"one",
"Tom",
"Hanks"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L1657-L1671 |
49,176 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | getAlphabetical | function getAlphabetical() {
try {
storeBeingTested.getList(test.list, {}, {name: 1}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
// Verify each move returns true when move succeeds
test.shouldBeTrue(list.moveFirst(), 'moveFirst');
test.shouldBeTrue(!list.movePrevious(), 'movePrevious');
test.shouldBeTrue(list.get('name') == 'Al Pacino', 'AP');
test.shouldBeTrue(list.moveLast(), 'moveLast');
test.shouldBeTrue(!list.moveNext(), 'moveNext');
test.shouldBeTrue(list.get('name') == 'Tom Hanks', 'TH');
callback(true);
});
}
catch (err) {
callback(err);
}
} | javascript | function getAlphabetical() {
try {
storeBeingTested.getList(test.list, {}, {name: 1}, function (list, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
// Verify each move returns true when move succeeds
test.shouldBeTrue(list.moveFirst(), 'moveFirst');
test.shouldBeTrue(!list.movePrevious(), 'movePrevious');
test.shouldBeTrue(list.get('name') == 'Al Pacino', 'AP');
test.shouldBeTrue(list.moveLast(), 'moveLast');
test.shouldBeTrue(!list.moveNext(), 'moveNext');
test.shouldBeTrue(list.get('name') == 'Tom Hanks', 'TH');
callback(true);
});
}
catch (err) {
callback(err);
}
} | [
"function",
"getAlphabetical",
"(",
")",
"{",
"try",
"{",
"storeBeingTested",
".",
"getList",
"(",
"test",
".",
"list",
",",
"{",
"}",
",",
"{",
"name",
":",
"1",
"}",
",",
"function",
"(",
"list",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"// Verify each move returns true when move succeeds",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"moveFirst",
"(",
")",
",",
"'moveFirst'",
")",
";",
"test",
".",
"shouldBeTrue",
"(",
"!",
"list",
".",
"movePrevious",
"(",
")",
",",
"'movePrevious'",
")",
";",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"get",
"(",
"'name'",
")",
"==",
"'Al Pacino'",
",",
"'AP'",
")",
";",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"moveLast",
"(",
")",
",",
"'moveLast'",
")",
";",
"test",
".",
"shouldBeTrue",
"(",
"!",
"list",
".",
"moveNext",
"(",
")",
",",
"'moveNext'",
")",
";",
"test",
".",
"shouldBeTrue",
"(",
"list",
".",
"get",
"(",
"'name'",
")",
"==",
"'Tom Hanks'",
",",
"'TH'",
")",
";",
"callback",
"(",
"true",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}"
] | Retrieve list alphabetically by name test order parameter | [
"Retrieve",
"list",
"alphabetically",
"by",
"name",
"test",
"order",
"parameter"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L1713-L1733 |
49,177 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | storeStooges | function storeStooges() {
self.log(self.oldStoogesFound);
self.log(self.oldStoogesKilled);
spec.integrationStore.putModel(self.moe, stoogeStored);
spec.integrationStore.putModel(self.larry, stoogeStored);
spec.integrationStore.putModel(self.shemp, stoogeStored);
} | javascript | function storeStooges() {
self.log(self.oldStoogesFound);
self.log(self.oldStoogesKilled);
spec.integrationStore.putModel(self.moe, stoogeStored);
spec.integrationStore.putModel(self.larry, stoogeStored);
spec.integrationStore.putModel(self.shemp, stoogeStored);
} | [
"function",
"storeStooges",
"(",
")",
"{",
"self",
".",
"log",
"(",
"self",
".",
"oldStoogesFound",
")",
";",
"self",
".",
"log",
"(",
"self",
".",
"oldStoogesKilled",
")",
";",
"spec",
".",
"integrationStore",
".",
"putModel",
"(",
"self",
".",
"moe",
",",
"stoogeStored",
")",
";",
"spec",
".",
"integrationStore",
".",
"putModel",
"(",
"self",
".",
"larry",
",",
"stoogeStored",
")",
";",
"spec",
".",
"integrationStore",
".",
"putModel",
"(",
"self",
".",
"shemp",
",",
"stoogeStored",
")",
";",
"}"
] | callback to store new stooges | [
"callback",
"to",
"store",
"new",
"stooges"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2618-L2624 |
49,178 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | stoogeRetrieved | function stoogeRetrieved(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.stoogesRetrieved.push(model);
if (self.stoogesRetrieved.length == 3) {
self.shouldBeTrue(true,'here');
// Now we have stored and retrieved (via IDs into new objects). So verify the stooges made it
self.shouldBeTrue(self.stoogesRetrieved[0] !== self.moe && // Make sure not a reference but a copy
self.stoogesRetrieved[0] !== self.larry && self.stoogesRetrieved[0] !== self.shemp,'copy');
var s = []; // get list of names to see if all stooges made it
for (var i = 0; i < 3; i++) s.push(self.stoogesRetrieved[i].get('name'));
self.log(s);
self.shouldBeTrue(contains(s, 'Moe') && contains(s, 'Larry') && contains(s, 'Shemp'));
// Replace Shemp with Curly
var didPutCurly = false;
for (i = 0; i < 3; i++) {
if (self.stoogesRetrieved[i].get('name') == 'Shemp') {
didPutCurly = true;
self.stoogesRetrieved[i].set('name', 'Curly');
try {
spec.integrationStore.putModel(self.stoogesRetrieved[i], stoogeChanged);
}
catch (err) {
callback(err);
}
}
}
if (!didPutCurly) {
callback(Error("Can't find Shemp!"));
}
}
} | javascript | function stoogeRetrieved(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.stoogesRetrieved.push(model);
if (self.stoogesRetrieved.length == 3) {
self.shouldBeTrue(true,'here');
// Now we have stored and retrieved (via IDs into new objects). So verify the stooges made it
self.shouldBeTrue(self.stoogesRetrieved[0] !== self.moe && // Make sure not a reference but a copy
self.stoogesRetrieved[0] !== self.larry && self.stoogesRetrieved[0] !== self.shemp,'copy');
var s = []; // get list of names to see if all stooges made it
for (var i = 0; i < 3; i++) s.push(self.stoogesRetrieved[i].get('name'));
self.log(s);
self.shouldBeTrue(contains(s, 'Moe') && contains(s, 'Larry') && contains(s, 'Shemp'));
// Replace Shemp with Curly
var didPutCurly = false;
for (i = 0; i < 3; i++) {
if (self.stoogesRetrieved[i].get('name') == 'Shemp') {
didPutCurly = true;
self.stoogesRetrieved[i].set('name', 'Curly');
try {
spec.integrationStore.putModel(self.stoogesRetrieved[i], stoogeChanged);
}
catch (err) {
callback(err);
}
}
}
if (!didPutCurly) {
callback(Error("Can't find Shemp!"));
}
}
} | [
"function",
"stoogeRetrieved",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"self",
".",
"stoogesRetrieved",
".",
"push",
"(",
"model",
")",
";",
"if",
"(",
"self",
".",
"stoogesRetrieved",
".",
"length",
"==",
"3",
")",
"{",
"self",
".",
"shouldBeTrue",
"(",
"true",
",",
"'here'",
")",
";",
"// Now we have stored and retrieved (via IDs into new objects). So verify the stooges made it",
"self",
".",
"shouldBeTrue",
"(",
"self",
".",
"stoogesRetrieved",
"[",
"0",
"]",
"!==",
"self",
".",
"moe",
"&&",
"// Make sure not a reference but a copy",
"self",
".",
"stoogesRetrieved",
"[",
"0",
"]",
"!==",
"self",
".",
"larry",
"&&",
"self",
".",
"stoogesRetrieved",
"[",
"0",
"]",
"!==",
"self",
".",
"shemp",
",",
"'copy'",
")",
";",
"var",
"s",
"=",
"[",
"]",
";",
"// get list of names to see if all stooges made it",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"s",
".",
"push",
"(",
"self",
".",
"stoogesRetrieved",
"[",
"i",
"]",
".",
"get",
"(",
"'name'",
")",
")",
";",
"self",
".",
"log",
"(",
"s",
")",
";",
"self",
".",
"shouldBeTrue",
"(",
"contains",
"(",
"s",
",",
"'Moe'",
")",
"&&",
"contains",
"(",
"s",
",",
"'Larry'",
")",
"&&",
"contains",
"(",
"s",
",",
"'Shemp'",
")",
")",
";",
"// Replace Shemp with Curly",
"var",
"didPutCurly",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"3",
";",
"i",
"++",
")",
"{",
"if",
"(",
"self",
".",
"stoogesRetrieved",
"[",
"i",
"]",
".",
"get",
"(",
"'name'",
")",
"==",
"'Shemp'",
")",
"{",
"didPutCurly",
"=",
"true",
";",
"self",
".",
"stoogesRetrieved",
"[",
"i",
"]",
".",
"set",
"(",
"'name'",
",",
"'Curly'",
")",
";",
"try",
"{",
"spec",
".",
"integrationStore",
".",
"putModel",
"(",
"self",
".",
"stoogesRetrieved",
"[",
"i",
"]",
",",
"stoogeChanged",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"didPutCurly",
")",
"{",
"callback",
"(",
"Error",
"(",
"\"Can't find Shemp!\"",
")",
")",
";",
"}",
"}",
"}"
] | callback after retrieving stored stooges | [
"callback",
"after",
"retrieving",
"stored",
"stooges"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2651-L2684 |
49,179 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | stoogeChanged | function stoogeChanged(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.shouldBeTrue(model.get('name') == 'Curly','Curly');
var curly = new self.Stooge();
curly.set('id', model.get('id'));
try {
spec.integrationStore.getModel(curly, storeChangedShempToCurly);
}
catch (err) {
callback(err);
}
} | javascript | function stoogeChanged(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.shouldBeTrue(model.get('name') == 'Curly','Curly');
var curly = new self.Stooge();
curly.set('id', model.get('id'));
try {
spec.integrationStore.getModel(curly, storeChangedShempToCurly);
}
catch (err) {
callback(err);
}
} | [
"function",
"stoogeChanged",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"self",
".",
"shouldBeTrue",
"(",
"model",
".",
"get",
"(",
"'name'",
")",
"==",
"'Curly'",
",",
"'Curly'",
")",
";",
"var",
"curly",
"=",
"new",
"self",
".",
"Stooge",
"(",
")",
";",
"curly",
".",
"set",
"(",
"'id'",
",",
"model",
".",
"get",
"(",
"'id'",
")",
")",
";",
"try",
"{",
"spec",
".",
"integrationStore",
".",
"getModel",
"(",
"curly",
",",
"storeChangedShempToCurly",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}"
] | callback after storing changed stooge | [
"callback",
"after",
"storing",
"changed",
"stooge"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2687-L2701 |
49,180 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | storeChangedShempToCurly | function storeChangedShempToCurly(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.shouldBeTrue(model.get('name') == 'Curly','Curly');
// Now test delete
self.deletedModelId = model.get('id'); // Remember this
spec.integrationStore.deleteModel(model, stoogeDeleted);
} | javascript | function storeChangedShempToCurly(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
self.shouldBeTrue(model.get('name') == 'Curly','Curly');
// Now test delete
self.deletedModelId = model.get('id'); // Remember this
spec.integrationStore.deleteModel(model, stoogeDeleted);
} | [
"function",
"storeChangedShempToCurly",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"self",
".",
"shouldBeTrue",
"(",
"model",
".",
"get",
"(",
"'name'",
")",
"==",
"'Curly'",
",",
"'Curly'",
")",
";",
"// Now test delete",
"self",
".",
"deletedModelId",
"=",
"model",
".",
"get",
"(",
"'id'",
")",
";",
"// Remember this",
"spec",
".",
"integrationStore",
".",
"deleteModel",
"(",
"model",
",",
"stoogeDeleted",
")",
";",
"}"
] | callback after retrieving changed stooge | [
"callback",
"after",
"retrieving",
"changed",
"stooge"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2704-L2713 |
49,181 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | stoogeDeleted | function stoogeDeleted(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
// model parameter is what was deleted
self.shouldBeTrue(undefined === model.get('id')); // ID removed
self.shouldBeTrue(model.get('name') == 'Curly'); // the rest remains
// Is it really dead?
var curly = new self.Stooge();
curly.set('id', self.deletedModelId);
spec.integrationStore.getModel(curly, hesDeadJim);
} | javascript | function stoogeDeleted(model, error) {
if (typeof error != 'undefined') {
callback(error);
return;
}
// model parameter is what was deleted
self.shouldBeTrue(undefined === model.get('id')); // ID removed
self.shouldBeTrue(model.get('name') == 'Curly'); // the rest remains
// Is it really dead?
var curly = new self.Stooge();
curly.set('id', self.deletedModelId);
spec.integrationStore.getModel(curly, hesDeadJim);
} | [
"function",
"stoogeDeleted",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"// model parameter is what was deleted",
"self",
".",
"shouldBeTrue",
"(",
"undefined",
"===",
"model",
".",
"get",
"(",
"'id'",
")",
")",
";",
"// ID removed",
"self",
".",
"shouldBeTrue",
"(",
"model",
".",
"get",
"(",
"'name'",
")",
"==",
"'Curly'",
")",
";",
"// the rest remains",
"// Is it really dead?",
"var",
"curly",
"=",
"new",
"self",
".",
"Stooge",
"(",
")",
";",
"curly",
".",
"set",
"(",
"'id'",
",",
"self",
".",
"deletedModelId",
")",
";",
"spec",
".",
"integrationStore",
".",
"getModel",
"(",
"curly",
",",
"hesDeadJim",
")",
";",
"}"
] | callback when Curly is deleted | [
"callback",
"when",
"Curly",
"is",
"deleted"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2716-L2728 |
49,182 | tgi-io/tgi-store-json-file | dist/tgi-store-json-file.spec.js | hesDeadJim | function hesDeadJim(model, error) {
if (typeof error != 'undefined') {
if ((error != 'Error: id not found in store') && (error != 'Error: model not found in store')) {
callback(error);
return;
}
} else {
callback(Error('no error deleting stooge when expected'));
return;
}
// Skip List test if subclass can't do
if (!spec.integrationStore.getServices().canGetList) {
callback(true);
} else {
// Now create a list from the stooge store
var list = new List(new self.Stooge());
try {
spec.integrationStore.getList(list, {}, {name:1}, listReady);
}
catch (err) {
callback(err);
}
}
} | javascript | function hesDeadJim(model, error) {
if (typeof error != 'undefined') {
if ((error != 'Error: id not found in store') && (error != 'Error: model not found in store')) {
callback(error);
return;
}
} else {
callback(Error('no error deleting stooge when expected'));
return;
}
// Skip List test if subclass can't do
if (!spec.integrationStore.getServices().canGetList) {
callback(true);
} else {
// Now create a list from the stooge store
var list = new List(new self.Stooge());
try {
spec.integrationStore.getList(list, {}, {name:1}, listReady);
}
catch (err) {
callback(err);
}
}
} | [
"function",
"hesDeadJim",
"(",
"model",
",",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
"!=",
"'undefined'",
")",
"{",
"if",
"(",
"(",
"error",
"!=",
"'Error: id not found in store'",
")",
"&&",
"(",
"error",
"!=",
"'Error: model not found in store'",
")",
")",
"{",
"callback",
"(",
"error",
")",
";",
"return",
";",
"}",
"}",
"else",
"{",
"callback",
"(",
"Error",
"(",
"'no error deleting stooge when expected'",
")",
")",
";",
"return",
";",
"}",
"// Skip List test if subclass can't do",
"if",
"(",
"!",
"spec",
".",
"integrationStore",
".",
"getServices",
"(",
")",
".",
"canGetList",
")",
"{",
"callback",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// Now create a list from the stooge store",
"var",
"list",
"=",
"new",
"List",
"(",
"new",
"self",
".",
"Stooge",
"(",
")",
")",
";",
"try",
"{",
"spec",
".",
"integrationStore",
".",
"getList",
"(",
"list",
",",
"{",
"}",
",",
"{",
"name",
":",
"1",
"}",
",",
"listReady",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"}",
"}"
] | callback after lookup of dead stooge | [
"callback",
"after",
"lookup",
"of",
"dead",
"stooge"
] | 21f5c4164326c5e80989f19413d26ba591f362ac | https://github.com/tgi-io/tgi-store-json-file/blob/21f5c4164326c5e80989f19413d26ba591f362ac/dist/tgi-store-json-file.spec.js#L2731-L2754 |
49,183 | MakerCollider/upm_mc | doxy/node/generators/yuidoc/generator.js | generateDocs | function generateDocs(specjs) {
var docs = GENERATE_MODULE(specjs.MODULE, '');
GENERATE_TYPE = (function(enums) {
return function(type) {
return (_.contains(enums, type) ? ('Enum ' + type) : type);
}
})(_.keys(specjs.ENUMS_BY_GROUP));
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
return memo += GENERATE_METHOD(methodName, methodSpec);
}, docs);
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
return memo += GENERATE_ENUM(enumName, enumSpec);
}, docs);
if (_.isEmpty(specjs.CLASSGROUPS)) {
docs += GENERATE_CLASSES(specjs.CLASSES);
} else {
docs += GENERATE_MODULE('common', '');
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped), 'common');
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName);
});
// TODO: figure out why yuidoc won't associate the class with the right module if module definitions are interspersed
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
docs += GENERATE_MODULE(groupName, groupSpec.description);
});
}
return docs;
} | javascript | function generateDocs(specjs) {
var docs = GENERATE_MODULE(specjs.MODULE, '');
GENERATE_TYPE = (function(enums) {
return function(type) {
return (_.contains(enums, type) ? ('Enum ' + type) : type);
}
})(_.keys(specjs.ENUMS_BY_GROUP));
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
return memo += GENERATE_METHOD(methodName, methodSpec);
}, docs);
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
return memo += GENERATE_ENUM(enumName, enumSpec);
}, docs);
if (_.isEmpty(specjs.CLASSGROUPS)) {
docs += GENERATE_CLASSES(specjs.CLASSES);
} else {
docs += GENERATE_MODULE('common', '');
var grouped = _.flatten(_.pluck(_.values(specjs.CLASSGROUPS), 'classes'));
var ungrouped = _.difference(_.keys(specjs.CLASSES), grouped);
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, ungrouped), 'common');
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
docs += GENERATE_CLASSES(_.pick(specjs.CLASSES, groupSpec.classes), groupName);
});
// TODO: figure out why yuidoc won't associate the class with the right module if module definitions are interspersed
_.each(specjs.CLASSGROUPS, function(groupSpec, groupName) {
docs += GENERATE_MODULE(groupName, groupSpec.description);
});
}
return docs;
} | [
"function",
"generateDocs",
"(",
"specjs",
")",
"{",
"var",
"docs",
"=",
"GENERATE_MODULE",
"(",
"specjs",
".",
"MODULE",
",",
"''",
")",
";",
"GENERATE_TYPE",
"=",
"(",
"function",
"(",
"enums",
")",
"{",
"return",
"function",
"(",
"type",
")",
"{",
"return",
"(",
"_",
".",
"contains",
"(",
"enums",
",",
"type",
")",
"?",
"(",
"'Enum '",
"+",
"type",
")",
":",
"type",
")",
";",
"}",
"}",
")",
"(",
"_",
".",
"keys",
"(",
"specjs",
".",
"ENUMS_BY_GROUP",
")",
")",
";",
"docs",
"=",
"_",
".",
"reduce",
"(",
"specjs",
".",
"METHODS",
",",
"function",
"(",
"memo",
",",
"methodSpec",
",",
"methodName",
")",
"{",
"return",
"memo",
"+=",
"GENERATE_METHOD",
"(",
"methodName",
",",
"methodSpec",
")",
";",
"}",
",",
"docs",
")",
";",
"docs",
"=",
"_",
".",
"reduce",
"(",
"specjs",
".",
"ENUMS",
",",
"function",
"(",
"memo",
",",
"enumSpec",
",",
"enumName",
")",
"{",
"return",
"memo",
"+=",
"GENERATE_ENUM",
"(",
"enumName",
",",
"enumSpec",
")",
";",
"}",
",",
"docs",
")",
";",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"specjs",
".",
"CLASSGROUPS",
")",
")",
"{",
"docs",
"+=",
"GENERATE_CLASSES",
"(",
"specjs",
".",
"CLASSES",
")",
";",
"}",
"else",
"{",
"docs",
"+=",
"GENERATE_MODULE",
"(",
"'common'",
",",
"''",
")",
";",
"var",
"grouped",
"=",
"_",
".",
"flatten",
"(",
"_",
".",
"pluck",
"(",
"_",
".",
"values",
"(",
"specjs",
".",
"CLASSGROUPS",
")",
",",
"'classes'",
")",
")",
";",
"var",
"ungrouped",
"=",
"_",
".",
"difference",
"(",
"_",
".",
"keys",
"(",
"specjs",
".",
"CLASSES",
")",
",",
"grouped",
")",
";",
"docs",
"+=",
"GENERATE_CLASSES",
"(",
"_",
".",
"pick",
"(",
"specjs",
".",
"CLASSES",
",",
"ungrouped",
")",
",",
"'common'",
")",
";",
"_",
".",
"each",
"(",
"specjs",
".",
"CLASSGROUPS",
",",
"function",
"(",
"groupSpec",
",",
"groupName",
")",
"{",
"docs",
"+=",
"GENERATE_CLASSES",
"(",
"_",
".",
"pick",
"(",
"specjs",
".",
"CLASSES",
",",
"groupSpec",
".",
"classes",
")",
",",
"groupName",
")",
";",
"}",
")",
";",
"// TODO: figure out why yuidoc won't associate the class with the right module if module definitions are interspersed",
"_",
".",
"each",
"(",
"specjs",
".",
"CLASSGROUPS",
",",
"function",
"(",
"groupSpec",
",",
"groupName",
")",
"{",
"docs",
"+=",
"GENERATE_MODULE",
"(",
"groupName",
",",
"groupSpec",
".",
"description",
")",
";",
"}",
")",
";",
"}",
"return",
"docs",
";",
"}"
] | generate YuiDocs-style documentation | [
"generate",
"YuiDocs",
"-",
"style",
"documentation"
] | 525e775a17b85c30716c00435a2acb26bb198c12 | https://github.com/MakerCollider/upm_mc/blob/525e775a17b85c30716c00435a2acb26bb198c12/doxy/node/generators/yuidoc/generator.js#L30-L59 |
49,184 | MakerCollider/upm_mc | doxy/node/generators/yuidoc/generator.js | GENERATE_CLASSES | function GENERATE_CLASSES(classes, parent) {
return _.reduce(classes, function(memo, classSpec, className) {
return memo
+ GENERATE_CLASS(className, classSpec.description, parent, classSpec.parent)
+ _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
return memo += GENERATE_METHOD(methodName, methodSpec, className);
}, '')
+ _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
return memo += GENERATE_VAR(variableName, variableSpec, className);
}, '')
+ _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
return memo += GENERATE_ENUM(enumName, enumSpec, className);
}, '');
}, '');
} | javascript | function GENERATE_CLASSES(classes, parent) {
return _.reduce(classes, function(memo, classSpec, className) {
return memo
+ GENERATE_CLASS(className, classSpec.description, parent, classSpec.parent)
+ _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
return memo += GENERATE_METHOD(methodName, methodSpec, className);
}, '')
+ _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
return memo += GENERATE_VAR(variableName, variableSpec, className);
}, '')
+ _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
return memo += GENERATE_ENUM(enumName, enumSpec, className);
}, '');
}, '');
} | [
"function",
"GENERATE_CLASSES",
"(",
"classes",
",",
"parent",
")",
"{",
"return",
"_",
".",
"reduce",
"(",
"classes",
",",
"function",
"(",
"memo",
",",
"classSpec",
",",
"className",
")",
"{",
"return",
"memo",
"+",
"GENERATE_CLASS",
"(",
"className",
",",
"classSpec",
".",
"description",
",",
"parent",
",",
"classSpec",
".",
"parent",
")",
"+",
"_",
".",
"reduce",
"(",
"classSpec",
".",
"methods",
",",
"function",
"(",
"memo",
",",
"methodSpec",
",",
"methodName",
")",
"{",
"return",
"memo",
"+=",
"GENERATE_METHOD",
"(",
"methodName",
",",
"methodSpec",
",",
"className",
")",
";",
"}",
",",
"''",
")",
"+",
"_",
".",
"reduce",
"(",
"classSpec",
".",
"variables",
",",
"function",
"(",
"memo",
",",
"variableSpec",
",",
"variableName",
")",
"{",
"return",
"memo",
"+=",
"GENERATE_VAR",
"(",
"variableName",
",",
"variableSpec",
",",
"className",
")",
";",
"}",
",",
"''",
")",
"+",
"_",
".",
"reduce",
"(",
"classSpec",
".",
"enums",
",",
"function",
"(",
"memo",
",",
"enumSpec",
",",
"enumName",
")",
"{",
"return",
"memo",
"+=",
"GENERATE_ENUM",
"(",
"enumName",
",",
"enumSpec",
",",
"className",
")",
";",
"}",
",",
"''",
")",
";",
"}",
",",
"''",
")",
";",
"}"
] | generate spec for the given list of classes | [
"generate",
"spec",
"for",
"the",
"given",
"list",
"of",
"classes"
] | 525e775a17b85c30716c00435a2acb26bb198c12 | https://github.com/MakerCollider/upm_mc/blob/525e775a17b85c30716c00435a2acb26bb198c12/doxy/node/generators/yuidoc/generator.js#L76-L90 |
49,185 | MakerCollider/upm_mc | doxy/node/generators/yuidoc/generator.js | GENERATE_CLASS | function GENERATE_CLASS(name, description, namespace, parent) {
return GENERATE_DOC(description + '\n'
+ '@class ' + name + '\n'
+ (namespace ? ('@module ' + namespace + '\n') : '')
/*
TODO: leave out until figure out what swig does with inheritance
+ (parent ? ('@extends ' + parent + '\n') : '')
*/
);
} | javascript | function GENERATE_CLASS(name, description, namespace, parent) {
return GENERATE_DOC(description + '\n'
+ '@class ' + name + '\n'
+ (namespace ? ('@module ' + namespace + '\n') : '')
/*
TODO: leave out until figure out what swig does with inheritance
+ (parent ? ('@extends ' + parent + '\n') : '')
*/
);
} | [
"function",
"GENERATE_CLASS",
"(",
"name",
",",
"description",
",",
"namespace",
",",
"parent",
")",
"{",
"return",
"GENERATE_DOC",
"(",
"description",
"+",
"'\\n'",
"+",
"'@class '",
"+",
"name",
"+",
"'\\n'",
"+",
"(",
"namespace",
"?",
"(",
"'@module '",
"+",
"namespace",
"+",
"'\\n'",
")",
":",
"''",
")",
"/*\n TODO: leave out until figure out what swig does with inheritance\n + (parent ? ('@extends ' + parent + '\\n') : '')\n */",
")",
";",
"}"
] | generate class spec | [
"generate",
"class",
"spec"
] | 525e775a17b85c30716c00435a2acb26bb198c12 | https://github.com/MakerCollider/upm_mc/blob/525e775a17b85c30716c00435a2acb26bb198c12/doxy/node/generators/yuidoc/generator.js#L94-L103 |
49,186 | MakerCollider/upm_mc | doxy/node/generators/yuidoc/generator.js | GENERATE_ENUM | function GENERATE_ENUM(name, spec, parent) {
return GENERATE_DOC(spec.description + '\n'
+ '@property ' + name + '\n'
+ '@type Enum ' + spec.type + '\n'
+ '@for ' + (parent ? parent : 'common') + '\n');
} | javascript | function GENERATE_ENUM(name, spec, parent) {
return GENERATE_DOC(spec.description + '\n'
+ '@property ' + name + '\n'
+ '@type Enum ' + spec.type + '\n'
+ '@for ' + (parent ? parent : 'common') + '\n');
} | [
"function",
"GENERATE_ENUM",
"(",
"name",
",",
"spec",
",",
"parent",
")",
"{",
"return",
"GENERATE_DOC",
"(",
"spec",
".",
"description",
"+",
"'\\n'",
"+",
"'@property '",
"+",
"name",
"+",
"'\\n'",
"+",
"'@type Enum '",
"+",
"spec",
".",
"type",
"+",
"'\\n'",
"+",
"'@for '",
"+",
"(",
"parent",
"?",
"parent",
":",
"'common'",
")",
"+",
"'\\n'",
")",
";",
"}"
] | generate enum spec | [
"generate",
"enum",
"spec"
] | 525e775a17b85c30716c00435a2acb26bb198c12 | https://github.com/MakerCollider/upm_mc/blob/525e775a17b85c30716c00435a2acb26bb198c12/doxy/node/generators/yuidoc/generator.js#L120-L125 |
49,187 | MakerCollider/upm_mc | doxy/node/generators/yuidoc/generator.js | GENERATE_VAR | function GENERATE_VAR(name, spec, parent) {
return GENERATE_DOC(spec.description + '\n'
+ '@property ' + name + '\n'
+ '@type ' + spec.type + '\n'
+ '@for ' + parent + '\n');
} | javascript | function GENERATE_VAR(name, spec, parent) {
return GENERATE_DOC(spec.description + '\n'
+ '@property ' + name + '\n'
+ '@type ' + spec.type + '\n'
+ '@for ' + parent + '\n');
} | [
"function",
"GENERATE_VAR",
"(",
"name",
",",
"spec",
",",
"parent",
")",
"{",
"return",
"GENERATE_DOC",
"(",
"spec",
".",
"description",
"+",
"'\\n'",
"+",
"'@property '",
"+",
"name",
"+",
"'\\n'",
"+",
"'@type '",
"+",
"spec",
".",
"type",
"+",
"'\\n'",
"+",
"'@for '",
"+",
"parent",
"+",
"'\\n'",
")",
";",
"}"
] | generate variable specs | [
"generate",
"variable",
"specs"
] | 525e775a17b85c30716c00435a2acb26bb198c12 | https://github.com/MakerCollider/upm_mc/blob/525e775a17b85c30716c00435a2acb26bb198c12/doxy/node/generators/yuidoc/generator.js#L129-L134 |
49,188 | marcin-chwedczuk/format.js | lib/bigint.js | function(lDigits, rDigits) {
var difference = [];
// assert: lDigits.length >= rDigits.length
var carry = 0, i;
for (i = 0; i < rDigits.length; i += 1) {
difference[i] = lDigits[i] - rDigits[i] + carry;
if (difference[i] < 0) {
difference[i] += 2;
carry = -1;
}
else {
carry = 0;
}
}
for (; i < lDigits.length; i += 1) {
difference[i] = lDigits[i] + carry;
if (difference[i] < 0) {
difference[i] += 2;
carry = -1;
}
else {
carry = 0;
}
}
if (carry !== 0) {
throw new Error('never goes here');
}
return difference;
} | javascript | function(lDigits, rDigits) {
var difference = [];
// assert: lDigits.length >= rDigits.length
var carry = 0, i;
for (i = 0; i < rDigits.length; i += 1) {
difference[i] = lDigits[i] - rDigits[i] + carry;
if (difference[i] < 0) {
difference[i] += 2;
carry = -1;
}
else {
carry = 0;
}
}
for (; i < lDigits.length; i += 1) {
difference[i] = lDigits[i] + carry;
if (difference[i] < 0) {
difference[i] += 2;
carry = -1;
}
else {
carry = 0;
}
}
if (carry !== 0) {
throw new Error('never goes here');
}
return difference;
} | [
"function",
"(",
"lDigits",
",",
"rDigits",
")",
"{",
"var",
"difference",
"=",
"[",
"]",
";",
"// assert: lDigits.length >= rDigits.length",
"var",
"carry",
"=",
"0",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"rDigits",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"difference",
"[",
"i",
"]",
"=",
"lDigits",
"[",
"i",
"]",
"-",
"rDigits",
"[",
"i",
"]",
"+",
"carry",
";",
"if",
"(",
"difference",
"[",
"i",
"]",
"<",
"0",
")",
"{",
"difference",
"[",
"i",
"]",
"+=",
"2",
";",
"carry",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"carry",
"=",
"0",
";",
"}",
"}",
"for",
"(",
";",
"i",
"<",
"lDigits",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"difference",
"[",
"i",
"]",
"=",
"lDigits",
"[",
"i",
"]",
"+",
"carry",
";",
"if",
"(",
"difference",
"[",
"i",
"]",
"<",
"0",
")",
"{",
"difference",
"[",
"i",
"]",
"+=",
"2",
";",
"carry",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"carry",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"carry",
"!==",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"'never goes here'",
")",
";",
"}",
"return",
"difference",
";",
"}"
] | lDigits must represent number that is greater than number representated by rDigits. | [
"lDigits",
"must",
"represent",
"number",
"that",
"is",
"greater",
"than",
"number",
"representated",
"by",
"rDigits",
"."
] | 01b146bc160cba9a70f6bdf6094bf353b4c56b5d | https://github.com/marcin-chwedczuk/format.js/blob/01b146bc160cba9a70f6bdf6094bf353b4c56b5d/lib/bigint.js#L170-L206 |
|
49,189 | marcin-chwedczuk/format.js | lib/bigint.js | function(normalizedLeft, normalizedRight) {
if (normalizedLeft.length !== normalizedRight.length) {
return normalizedLeft.length - normalizedRight.length;
}
for (var i = normalizedLeft.length - 1; i >= 0; i -= 1) {
if (normalizedLeft[i] !== normalizedRight[i]) {
return normalizedLeft[i] - normalizedRight[i];
}
}
return 0;
} | javascript | function(normalizedLeft, normalizedRight) {
if (normalizedLeft.length !== normalizedRight.length) {
return normalizedLeft.length - normalizedRight.length;
}
for (var i = normalizedLeft.length - 1; i >= 0; i -= 1) {
if (normalizedLeft[i] !== normalizedRight[i]) {
return normalizedLeft[i] - normalizedRight[i];
}
}
return 0;
} | [
"function",
"(",
"normalizedLeft",
",",
"normalizedRight",
")",
"{",
"if",
"(",
"normalizedLeft",
".",
"length",
"!==",
"normalizedRight",
".",
"length",
")",
"{",
"return",
"normalizedLeft",
".",
"length",
"-",
"normalizedRight",
".",
"length",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"normalizedLeft",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"-=",
"1",
")",
"{",
"if",
"(",
"normalizedLeft",
"[",
"i",
"]",
"!==",
"normalizedRight",
"[",
"i",
"]",
")",
"{",
"return",
"normalizedLeft",
"[",
"i",
"]",
"-",
"normalizedRight",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | compares numbers represented by two NORMALIZED digits arrays | [
"compares",
"numbers",
"represented",
"by",
"two",
"NORMALIZED",
"digits",
"arrays"
] | 01b146bc160cba9a70f6bdf6094bf353b4c56b5d | https://github.com/marcin-chwedczuk/format.js/blob/01b146bc160cba9a70f6bdf6094bf353b4c56b5d/lib/bigint.js#L459-L471 |
|
49,190 | redisjs/jsr-server | lib/socket.js | SocketProxy | function SocketProxy() {
// the socket we are paired with
this.pair = null;
// internal sockets have fd -1
this._handle = {fd: -1};
// mimic a remote address / remote port
this.remoteAddress = '0.0.0.0';
this.remotePort = '0';
// give the client some time to listen
// for the connect event
function onNextTick() {
this.emit('connect');
}
process.nextTick(onNextTick.bind(this));
} | javascript | function SocketProxy() {
// the socket we are paired with
this.pair = null;
// internal sockets have fd -1
this._handle = {fd: -1};
// mimic a remote address / remote port
this.remoteAddress = '0.0.0.0';
this.remotePort = '0';
// give the client some time to listen
// for the connect event
function onNextTick() {
this.emit('connect');
}
process.nextTick(onNextTick.bind(this));
} | [
"function",
"SocketProxy",
"(",
")",
"{",
"// the socket we are paired with",
"this",
".",
"pair",
"=",
"null",
";",
"// internal sockets have fd -1",
"this",
".",
"_handle",
"=",
"{",
"fd",
":",
"-",
"1",
"}",
";",
"// mimic a remote address / remote port",
"this",
".",
"remoteAddress",
"=",
"'0.0.0.0'",
";",
"this",
".",
"remotePort",
"=",
"'0'",
";",
"// give the client some time to listen",
"// for the connect event",
"function",
"onNextTick",
"(",
")",
"{",
"this",
".",
"emit",
"(",
"'connect'",
")",
";",
"}",
"process",
".",
"nextTick",
"(",
"onNextTick",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Abstract socket class used to create a bi-directional link between
a server and a client connecting in the same process.
Simulates the `net.Socket` class so that the code flows in exactly
the same way but bypasses encoding, decoding and TCP transmission
overhead. | [
"Abstract",
"socket",
"class",
"used",
"to",
"create",
"a",
"bi",
"-",
"directional",
"link",
"between",
"a",
"server",
"and",
"a",
"client",
"connecting",
"in",
"the",
"same",
"process",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/socket.js#L12-L29 |
49,191 | loggur-legacy/baucis-decorator-deep-select | index.js | gatherPopulateParams | function gatherPopulateParams (populate, pointers, model, deepPath) {
var modelName = model.modelName;
var paths = model.schema.paths;
var path = '';
var options;
var params;
var ref;
var deep = false;
while (deepPath.length) {
path += (path ? '.' : '')+deepPath.shift();
options = paths[path] && (
paths[path].caster && paths[path].caster.options
|| paths[path].options
);
if (!options) {
continue;
}
params = pointers[path] || (pointers[path] = {});
ref = options.ref || options.type[0] && options.type[0].ref;
if (!ref) {
if (selectPointers(params)) {
deep = true;
}
continue;
}
if (!params.path) {
params.path = path;
params.model = ref;
params.populate = [];
params.pointers = {};
populate.push(params);
}
if (gatherPopulateParams(
params.populate,
params.pointers,
model.model(ref),
deepPath
)) {
deep = true;
}
if (selectPointers(params)) {
deep = true;
}
}
return deep;
} | javascript | function gatherPopulateParams (populate, pointers, model, deepPath) {
var modelName = model.modelName;
var paths = model.schema.paths;
var path = '';
var options;
var params;
var ref;
var deep = false;
while (deepPath.length) {
path += (path ? '.' : '')+deepPath.shift();
options = paths[path] && (
paths[path].caster && paths[path].caster.options
|| paths[path].options
);
if (!options) {
continue;
}
params = pointers[path] || (pointers[path] = {});
ref = options.ref || options.type[0] && options.type[0].ref;
if (!ref) {
if (selectPointers(params)) {
deep = true;
}
continue;
}
if (!params.path) {
params.path = path;
params.model = ref;
params.populate = [];
params.pointers = {};
populate.push(params);
}
if (gatherPopulateParams(
params.populate,
params.pointers,
model.model(ref),
deepPath
)) {
deep = true;
}
if (selectPointers(params)) {
deep = true;
}
}
return deep;
} | [
"function",
"gatherPopulateParams",
"(",
"populate",
",",
"pointers",
",",
"model",
",",
"deepPath",
")",
"{",
"var",
"modelName",
"=",
"model",
".",
"modelName",
";",
"var",
"paths",
"=",
"model",
".",
"schema",
".",
"paths",
";",
"var",
"path",
"=",
"''",
";",
"var",
"options",
";",
"var",
"params",
";",
"var",
"ref",
";",
"var",
"deep",
"=",
"false",
";",
"while",
"(",
"deepPath",
".",
"length",
")",
"{",
"path",
"+=",
"(",
"path",
"?",
"'.'",
":",
"''",
")",
"+",
"deepPath",
".",
"shift",
"(",
")",
";",
"options",
"=",
"paths",
"[",
"path",
"]",
"&&",
"(",
"paths",
"[",
"path",
"]",
".",
"caster",
"&&",
"paths",
"[",
"path",
"]",
".",
"caster",
".",
"options",
"||",
"paths",
"[",
"path",
"]",
".",
"options",
")",
";",
"if",
"(",
"!",
"options",
")",
"{",
"continue",
";",
"}",
"params",
"=",
"pointers",
"[",
"path",
"]",
"||",
"(",
"pointers",
"[",
"path",
"]",
"=",
"{",
"}",
")",
";",
"ref",
"=",
"options",
".",
"ref",
"||",
"options",
".",
"type",
"[",
"0",
"]",
"&&",
"options",
".",
"type",
"[",
"0",
"]",
".",
"ref",
";",
"if",
"(",
"!",
"ref",
")",
"{",
"if",
"(",
"selectPointers",
"(",
"params",
")",
")",
"{",
"deep",
"=",
"true",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"params",
".",
"path",
")",
"{",
"params",
".",
"path",
"=",
"path",
";",
"params",
".",
"model",
"=",
"ref",
";",
"params",
".",
"populate",
"=",
"[",
"]",
";",
"params",
".",
"pointers",
"=",
"{",
"}",
";",
"populate",
".",
"push",
"(",
"params",
")",
";",
"}",
"if",
"(",
"gatherPopulateParams",
"(",
"params",
".",
"populate",
",",
"params",
".",
"pointers",
",",
"model",
".",
"model",
"(",
"ref",
")",
",",
"deepPath",
")",
")",
"{",
"deep",
"=",
"true",
";",
"}",
"if",
"(",
"selectPointers",
"(",
"params",
")",
")",
"{",
"deep",
"=",
"true",
";",
"}",
"}",
"return",
"deep",
";",
"}"
] | Gathers the params required for population of some deep path, if any.
@param {Array} populate
@param {Object} pointers
@param {Model} model
@param {Array} deepPath
@return {Boolean} true if deep population
@api private | [
"Gathers",
"the",
"params",
"required",
"for",
"population",
"of",
"some",
"deep",
"path",
"if",
"any",
"."
] | 8f14bb6aca76d43fd163d2142ff49c3058ddc657 | https://github.com/loggur-legacy/baucis-decorator-deep-select/blob/8f14bb6aca76d43fd163d2142ff49c3058ddc657/index.js#L117-L166 |
49,192 | loggur-legacy/baucis-decorator-deep-select | index.js | selectPointers | function selectPointers (params) {
if (params.pointers) {
delete params.pointers['-_id'];
params.select = Object.keys(params.pointers).join(' ');
} else {
delete params.select;
}
return params.select;
} | javascript | function selectPointers (params) {
if (params.pointers) {
delete params.pointers['-_id'];
params.select = Object.keys(params.pointers).join(' ');
} else {
delete params.select;
}
return params.select;
} | [
"function",
"selectPointers",
"(",
"params",
")",
"{",
"if",
"(",
"params",
".",
"pointers",
")",
"{",
"delete",
"params",
".",
"pointers",
"[",
"'-_id'",
"]",
";",
"params",
".",
"select",
"=",
"Object",
".",
"keys",
"(",
"params",
".",
"pointers",
")",
".",
"join",
"(",
"' '",
")",
";",
"}",
"else",
"{",
"delete",
"params",
".",
"select",
";",
"}",
"return",
"params",
".",
"select",
";",
"}"
] | Sets the `select` parameter to the keys of the `pointers` and ensures `_id`
can't be hidden.
@param {Object} params
@return {String} select
@api private | [
"Sets",
"the",
"select",
"parameter",
"to",
"the",
"keys",
"of",
"the",
"pointers",
"and",
"ensures",
"_id",
"can",
"t",
"be",
"hidden",
"."
] | 8f14bb6aca76d43fd163d2142ff49c3058ddc657 | https://github.com/loggur-legacy/baucis-decorator-deep-select/blob/8f14bb6aca76d43fd163d2142ff49c3058ddc657/index.js#L176-L184 |
49,193 | gethuman/taste | lib/taste.js | firstBite | function firstBite(dir) {
targetDir = dir || path.join(__dirname, '../../..');
if (targetDir.substring(targetDir.length - 1) === '/') {
targetDir = targetDir.substring(0, targetDir.length - 1);
}
} | javascript | function firstBite(dir) {
targetDir = dir || path.join(__dirname, '../../..');
if (targetDir.substring(targetDir.length - 1) === '/') {
targetDir = targetDir.substring(0, targetDir.length - 1);
}
} | [
"function",
"firstBite",
"(",
"dir",
")",
"{",
"targetDir",
"=",
"dir",
"||",
"path",
".",
"join",
"(",
"__dirname",
",",
"'../../..'",
")",
";",
"if",
"(",
"targetDir",
".",
"substring",
"(",
"targetDir",
".",
"length",
"-",
"1",
")",
"===",
"'/'",
")",
"{",
"targetDir",
"=",
"targetDir",
".",
"substring",
"(",
"0",
",",
"targetDir",
".",
"length",
"-",
"1",
")",
";",
"}",
"}"
] | chai.config.truncateThreshold = 0;
Initialize taste with the input params
@param dir | [
"chai",
".",
"config",
".",
"truncateThreshold",
"=",
"0",
";",
"Initialize",
"taste",
"with",
"the",
"input",
"params"
] | f06938fe0c182235e88403e3341a94b6f47c2e2d | https://github.com/gethuman/taste/blob/f06938fe0c182235e88403e3341a94b6f47c2e2d/lib/taste.js#L27-L33 |
49,194 | gethuman/taste | lib/taste.js | eventuallyEqual | function eventuallyEqual(promise, expected, done) {
all([
promise.should.be.fulfilled,
promise.should.eventually.deep.equal(expected)
], done);
} | javascript | function eventuallyEqual(promise, expected, done) {
all([
promise.should.be.fulfilled,
promise.should.eventually.deep.equal(expected)
], done);
} | [
"function",
"eventuallyEqual",
"(",
"promise",
",",
"expected",
",",
"done",
")",
"{",
"all",
"(",
"[",
"promise",
".",
"should",
".",
"be",
".",
"fulfilled",
",",
"promise",
".",
"should",
".",
"eventually",
".",
"deep",
".",
"equal",
"(",
"expected",
")",
"]",
",",
"done",
")",
";",
"}"
] | Shorthand for just making sure a promise eventually equals a value
@param promise
@param expected
@param done | [
"Shorthand",
"for",
"just",
"making",
"sure",
"a",
"promise",
"eventually",
"equals",
"a",
"value"
] | f06938fe0c182235e88403e3341a94b6f47c2e2d | https://github.com/gethuman/taste/blob/f06938fe0c182235e88403e3341a94b6f47c2e2d/lib/taste.js#L51-L56 |
49,195 | gethuman/taste | lib/taste.js | eventuallyRejectedWith | function eventuallyRejectedWith(promise, expected, done) {
all([
promise.should.be.rejectedWith(expected)
], done);
} | javascript | function eventuallyRejectedWith(promise, expected, done) {
all([
promise.should.be.rejectedWith(expected)
], done);
} | [
"function",
"eventuallyRejectedWith",
"(",
"promise",
",",
"expected",
",",
"done",
")",
"{",
"all",
"(",
"[",
"promise",
".",
"should",
".",
"be",
".",
"rejectedWith",
"(",
"expected",
")",
"]",
",",
"done",
")",
";",
"}"
] | Shorthand for making sure the promise will eventually be rejected
@param promise
@param expected
@param done | [
"Shorthand",
"for",
"making",
"sure",
"the",
"promise",
"will",
"eventually",
"be",
"rejected"
] | f06938fe0c182235e88403e3341a94b6f47c2e2d | https://github.com/gethuman/taste/blob/f06938fe0c182235e88403e3341a94b6f47c2e2d/lib/taste.js#L86-L90 |
49,196 | web-mech/can-stream-x | interface-factory.js | function (updated) {
// When the stream passes a new values, save a reference to it and call
// the compute's internal `updated` method (which ultimately calls `get`)
streamHandler = function (val) {
lastValue = val;
updated();
};
unsubscribe = valueStream[on](streamHandler);
} | javascript | function (updated) {
// When the stream passes a new values, save a reference to it and call
// the compute's internal `updated` method (which ultimately calls `get`)
streamHandler = function (val) {
lastValue = val;
updated();
};
unsubscribe = valueStream[on](streamHandler);
} | [
"function",
"(",
"updated",
")",
"{",
"// When the stream passes a new values, save a reference to it and call",
"// the compute's internal `updated` method (which ultimately calls `get`)",
"streamHandler",
"=",
"function",
"(",
"val",
")",
"{",
"lastValue",
"=",
"val",
";",
"updated",
"(",
")",
";",
"}",
";",
"unsubscribe",
"=",
"valueStream",
"[",
"on",
"]",
"(",
"streamHandler",
")",
";",
"}"
] | When the compute is bound, bind to the resolved stream | [
"When",
"the",
"compute",
"is",
"bound",
"bind",
"to",
"the",
"resolved",
"stream"
] | bb025a313c2432861ba7293c6d8f6128f187ced8 | https://github.com/web-mech/can-stream-x/blob/bb025a313c2432861ba7293c6d8f6128f187ced8/interface-factory.js#L89-L98 |
|
49,197 | chanoch/simple-react-router | src/route/SetRoute.js | setRoot | function setRoot(mountpath) {
// mount to root if not mountpath
let root=mountpath?mountpath:"";
// add leading slash if needed
root=root.match(/^\/.*/)?root:`/${root}`;
// chop off trailing slash
root=root.match(/^.*\/$/)?root.substring(0,root.length-1):root;
// if root is just slash then mountpath is empty (load on root of site)
root=root.length>1?root:"";
return root;
} | javascript | function setRoot(mountpath) {
// mount to root if not mountpath
let root=mountpath?mountpath:"";
// add leading slash if needed
root=root.match(/^\/.*/)?root:`/${root}`;
// chop off trailing slash
root=root.match(/^.*\/$/)?root.substring(0,root.length-1):root;
// if root is just slash then mountpath is empty (load on root of site)
root=root.length>1?root:"";
return root;
} | [
"function",
"setRoot",
"(",
"mountpath",
")",
"{",
"// mount to root if not mountpath",
"let",
"root",
"=",
"mountpath",
"?",
"mountpath",
":",
"\"\"",
";",
"// add leading slash if needed",
"root",
"=",
"root",
".",
"match",
"(",
"/",
"^\\/.*",
"/",
")",
"?",
"root",
":",
"`",
"${",
"root",
"}",
"`",
";",
"// chop off trailing slash",
"root",
"=",
"root",
".",
"match",
"(",
"/",
"^.*\\/$",
"/",
")",
"?",
"root",
".",
"substring",
"(",
"0",
",",
"root",
".",
"length",
"-",
"1",
")",
":",
"root",
";",
"// if root is just slash then mountpath is empty (load on root of site)",
"root",
"=",
"root",
".",
"length",
">",
"1",
"?",
"root",
":",
"\"\"",
";",
"return",
"root",
";",
"}"
] | make sure that mountpath has a leading slash and no training slash | [
"make",
"sure",
"that",
"mountpath",
"has",
"a",
"leading",
"slash",
"and",
"no",
"training",
"slash"
] | 3c71feeeb039111f33c934257732e2ea6ddde9ff | https://github.com/chanoch/simple-react-router/blob/3c71feeeb039111f33c934257732e2ea6ddde9ff/src/route/SetRoute.js#L19-L30 |
49,198 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | popupClick | function popupClick(e) {
var editor = this,
popup = e.data.popup,
target = e.target;
// Check for message and prompt popups
if (popup === popups.msg || $(popup).hasClass(PROMPT_CLASS))
return;
// Get the button info
var buttonDiv = $.data(popup, BUTTON),
buttonName = $.data(buttonDiv, BUTTON_NAME),
button = buttons[buttonName],
command = button.command,
value,
useCSS = editor.options.useCSS;
// Get the command value
if (buttonName == "font")
// Opera returns the fontfamily wrapped in quotes
value = target.style.fontFamily.replace(/"/g, "");
else if (buttonName == "size") {
if (target.tagName == "DIV")
target = target.children[0];
value = target.innerHTML;
}
else if (buttonName == "style")
value = "<" + target.tagName + ">";
else if (buttonName == "color")
value = hex(target.style.backgroundColor);
else if (buttonName == "highlight") {
value = hex(target.style.backgroundColor);
if (ie) command = 'backcolor';
else useCSS = true;
}
// Fire the popupClick event
var data = {
editor: editor,
button: buttonDiv,
buttonName: buttonName,
popup: popup,
popupName: button.popupName,
command: command,
value: value,
useCSS: useCSS
};
if (button.popupClick && button.popupClick(e, data) === false)
return;
// Execute the command
if (data.command && !execCommand(editor, data.command, data.value, data.useCSS, buttonDiv))
return false;
// Hide the popup and focus the editor
hidePopups();
focus(editor);
} | javascript | function popupClick(e) {
var editor = this,
popup = e.data.popup,
target = e.target;
// Check for message and prompt popups
if (popup === popups.msg || $(popup).hasClass(PROMPT_CLASS))
return;
// Get the button info
var buttonDiv = $.data(popup, BUTTON),
buttonName = $.data(buttonDiv, BUTTON_NAME),
button = buttons[buttonName],
command = button.command,
value,
useCSS = editor.options.useCSS;
// Get the command value
if (buttonName == "font")
// Opera returns the fontfamily wrapped in quotes
value = target.style.fontFamily.replace(/"/g, "");
else if (buttonName == "size") {
if (target.tagName == "DIV")
target = target.children[0];
value = target.innerHTML;
}
else if (buttonName == "style")
value = "<" + target.tagName + ">";
else if (buttonName == "color")
value = hex(target.style.backgroundColor);
else if (buttonName == "highlight") {
value = hex(target.style.backgroundColor);
if (ie) command = 'backcolor';
else useCSS = true;
}
// Fire the popupClick event
var data = {
editor: editor,
button: buttonDiv,
buttonName: buttonName,
popup: popup,
popupName: button.popupName,
command: command,
value: value,
useCSS: useCSS
};
if (button.popupClick && button.popupClick(e, data) === false)
return;
// Execute the command
if (data.command && !execCommand(editor, data.command, data.value, data.useCSS, buttonDiv))
return false;
// Hide the popup and focus the editor
hidePopups();
focus(editor);
} | [
"function",
"popupClick",
"(",
"e",
")",
"{",
"var",
"editor",
"=",
"this",
",",
"popup",
"=",
"e",
".",
"data",
".",
"popup",
",",
"target",
"=",
"e",
".",
"target",
";",
"// Check for message and prompt popups\r",
"if",
"(",
"popup",
"===",
"popups",
".",
"msg",
"||",
"$",
"(",
"popup",
")",
".",
"hasClass",
"(",
"PROMPT_CLASS",
")",
")",
"return",
";",
"// Get the button info\r",
"var",
"buttonDiv",
"=",
"$",
".",
"data",
"(",
"popup",
",",
"BUTTON",
")",
",",
"buttonName",
"=",
"$",
".",
"data",
"(",
"buttonDiv",
",",
"BUTTON_NAME",
")",
",",
"button",
"=",
"buttons",
"[",
"buttonName",
"]",
",",
"command",
"=",
"button",
".",
"command",
",",
"value",
",",
"useCSS",
"=",
"editor",
".",
"options",
".",
"useCSS",
";",
"// Get the command value\r",
"if",
"(",
"buttonName",
"==",
"\"font\"",
")",
"// Opera returns the fontfamily wrapped in quotes\r",
"value",
"=",
"target",
".",
"style",
".",
"fontFamily",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"\"\"",
")",
";",
"else",
"if",
"(",
"buttonName",
"==",
"\"size\"",
")",
"{",
"if",
"(",
"target",
".",
"tagName",
"==",
"\"DIV\"",
")",
"target",
"=",
"target",
".",
"children",
"[",
"0",
"]",
";",
"value",
"=",
"target",
".",
"innerHTML",
";",
"}",
"else",
"if",
"(",
"buttonName",
"==",
"\"style\"",
")",
"value",
"=",
"\"<\"",
"+",
"target",
".",
"tagName",
"+",
"\">\"",
";",
"else",
"if",
"(",
"buttonName",
"==",
"\"color\"",
")",
"value",
"=",
"hex",
"(",
"target",
".",
"style",
".",
"backgroundColor",
")",
";",
"else",
"if",
"(",
"buttonName",
"==",
"\"highlight\"",
")",
"{",
"value",
"=",
"hex",
"(",
"target",
".",
"style",
".",
"backgroundColor",
")",
";",
"if",
"(",
"ie",
")",
"command",
"=",
"'backcolor'",
";",
"else",
"useCSS",
"=",
"true",
";",
"}",
"// Fire the popupClick event\r",
"var",
"data",
"=",
"{",
"editor",
":",
"editor",
",",
"button",
":",
"buttonDiv",
",",
"buttonName",
":",
"buttonName",
",",
"popup",
":",
"popup",
",",
"popupName",
":",
"button",
".",
"popupName",
",",
"command",
":",
"command",
",",
"value",
":",
"value",
",",
"useCSS",
":",
"useCSS",
"}",
";",
"if",
"(",
"button",
".",
"popupClick",
"&&",
"button",
".",
"popupClick",
"(",
"e",
",",
"data",
")",
"===",
"false",
")",
"return",
";",
"// Execute the command\r",
"if",
"(",
"data",
".",
"command",
"&&",
"!",
"execCommand",
"(",
"editor",
",",
"data",
".",
"command",
",",
"data",
".",
"value",
",",
"data",
".",
"useCSS",
",",
"buttonDiv",
")",
")",
"return",
"false",
";",
"// Hide the popup and focus the editor\r",
"hidePopups",
"(",
")",
";",
"focus",
"(",
"editor",
")",
";",
"}"
] | popupClick - click event handler for popup items | [
"popupClick",
"-",
"click",
"event",
"handler",
"for",
"popup",
"items"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L500-L560 |
49,199 | tnantoka/LooseLeaf | skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js | createPopup | function createPopup(popupName, options, popupTypeClass, popupContent, popupHover) {
// Check if popup already exists
if (popups[popupName])
return popups[popupName];
// Create the popup
var $popup = $(DIV_TAG)
.hide()
.addClass(POPUP_CLASS)
.appendTo("body");
// Add the content
// Custom popup
if (popupContent)
$popup.html(popupContent);
// Color
else if (popupName == "color") {
var colors = options.colors.split(" ");
if (colors.length < 10)
$popup.width("auto");
$.each(colors, function(idx, color) {
$(DIV_TAG).appendTo($popup)
.css(BACKGROUND_COLOR, "#" + color);
});
popupTypeClass = COLOR_CLASS;
}
// Font
else if (popupName == "font")
$.each(options.fonts.split(","), function(idx, font) {
$(DIV_TAG).appendTo($popup)
.css("fontFamily", font)
.html(font);
});
// Size
else if (popupName == "size")
$.each(options.sizes.split(","), function(idx, size) {
$(DIV_TAG).appendTo($popup)
.html("<font size=" + size + ">" + size + "</font>");
});
// Style
else if (popupName == "style")
$.each(options.styles, function(idx, style) {
$(DIV_TAG).appendTo($popup)
.html(style[1] + style[0] + style[1].replace("<", "</"));
});
// URL
else if (popupName == "url") {
$popup.html('Enter URL:<br><input type=text value="http://" size=35><br><input type=button value="Submit">');
popupTypeClass = PROMPT_CLASS;
}
// Paste as Text
else if (popupName == "pastetext") {
$popup.html('Paste your content here and click submit.<br /><textarea cols=40 rows=3></textarea><br /><input type=button value=Submit>');
popupTypeClass = PROMPT_CLASS;
}
// Add the popup type class name
if (!popupTypeClass && !popupContent)
popupTypeClass = LIST_CLASS;
$popup.addClass(popupTypeClass);
// Add the unselectable attribute to all items
if (ie) {
$popup.attr(UNSELECTABLE, "on")
.find("div,font,p,h1,h2,h3,h4,h5,h6")
.attr(UNSELECTABLE, "on");
}
// Add the hover effect to all items
if ($popup.hasClass(LIST_CLASS) || popupHover === true)
$popup.children().hover(hoverEnter, hoverLeave);
// Add the popup to the array and return it
popups[popupName] = $popup[0];
return $popup[0];
} | javascript | function createPopup(popupName, options, popupTypeClass, popupContent, popupHover) {
// Check if popup already exists
if (popups[popupName])
return popups[popupName];
// Create the popup
var $popup = $(DIV_TAG)
.hide()
.addClass(POPUP_CLASS)
.appendTo("body");
// Add the content
// Custom popup
if (popupContent)
$popup.html(popupContent);
// Color
else if (popupName == "color") {
var colors = options.colors.split(" ");
if (colors.length < 10)
$popup.width("auto");
$.each(colors, function(idx, color) {
$(DIV_TAG).appendTo($popup)
.css(BACKGROUND_COLOR, "#" + color);
});
popupTypeClass = COLOR_CLASS;
}
// Font
else if (popupName == "font")
$.each(options.fonts.split(","), function(idx, font) {
$(DIV_TAG).appendTo($popup)
.css("fontFamily", font)
.html(font);
});
// Size
else if (popupName == "size")
$.each(options.sizes.split(","), function(idx, size) {
$(DIV_TAG).appendTo($popup)
.html("<font size=" + size + ">" + size + "</font>");
});
// Style
else if (popupName == "style")
$.each(options.styles, function(idx, style) {
$(DIV_TAG).appendTo($popup)
.html(style[1] + style[0] + style[1].replace("<", "</"));
});
// URL
else if (popupName == "url") {
$popup.html('Enter URL:<br><input type=text value="http://" size=35><br><input type=button value="Submit">');
popupTypeClass = PROMPT_CLASS;
}
// Paste as Text
else if (popupName == "pastetext") {
$popup.html('Paste your content here and click submit.<br /><textarea cols=40 rows=3></textarea><br /><input type=button value=Submit>');
popupTypeClass = PROMPT_CLASS;
}
// Add the popup type class name
if (!popupTypeClass && !popupContent)
popupTypeClass = LIST_CLASS;
$popup.addClass(popupTypeClass);
// Add the unselectable attribute to all items
if (ie) {
$popup.attr(UNSELECTABLE, "on")
.find("div,font,p,h1,h2,h3,h4,h5,h6")
.attr(UNSELECTABLE, "on");
}
// Add the hover effect to all items
if ($popup.hasClass(LIST_CLASS) || popupHover === true)
$popup.children().hover(hoverEnter, hoverLeave);
// Add the popup to the array and return it
popups[popupName] = $popup[0];
return $popup[0];
} | [
"function",
"createPopup",
"(",
"popupName",
",",
"options",
",",
"popupTypeClass",
",",
"popupContent",
",",
"popupHover",
")",
"{",
"// Check if popup already exists\r",
"if",
"(",
"popups",
"[",
"popupName",
"]",
")",
"return",
"popups",
"[",
"popupName",
"]",
";",
"// Create the popup\r",
"var",
"$popup",
"=",
"$",
"(",
"DIV_TAG",
")",
".",
"hide",
"(",
")",
".",
"addClass",
"(",
"POPUP_CLASS",
")",
".",
"appendTo",
"(",
"\"body\"",
")",
";",
"// Add the content\r",
"// Custom popup\r",
"if",
"(",
"popupContent",
")",
"$popup",
".",
"html",
"(",
"popupContent",
")",
";",
"// Color\r",
"else",
"if",
"(",
"popupName",
"==",
"\"color\"",
")",
"{",
"var",
"colors",
"=",
"options",
".",
"colors",
".",
"split",
"(",
"\" \"",
")",
";",
"if",
"(",
"colors",
".",
"length",
"<",
"10",
")",
"$popup",
".",
"width",
"(",
"\"auto\"",
")",
";",
"$",
".",
"each",
"(",
"colors",
",",
"function",
"(",
"idx",
",",
"color",
")",
"{",
"$",
"(",
"DIV_TAG",
")",
".",
"appendTo",
"(",
"$popup",
")",
".",
"css",
"(",
"BACKGROUND_COLOR",
",",
"\"#\"",
"+",
"color",
")",
";",
"}",
")",
";",
"popupTypeClass",
"=",
"COLOR_CLASS",
";",
"}",
"// Font\r",
"else",
"if",
"(",
"popupName",
"==",
"\"font\"",
")",
"$",
".",
"each",
"(",
"options",
".",
"fonts",
".",
"split",
"(",
"\",\"",
")",
",",
"function",
"(",
"idx",
",",
"font",
")",
"{",
"$",
"(",
"DIV_TAG",
")",
".",
"appendTo",
"(",
"$popup",
")",
".",
"css",
"(",
"\"fontFamily\"",
",",
"font",
")",
".",
"html",
"(",
"font",
")",
";",
"}",
")",
";",
"// Size\r",
"else",
"if",
"(",
"popupName",
"==",
"\"size\"",
")",
"$",
".",
"each",
"(",
"options",
".",
"sizes",
".",
"split",
"(",
"\",\"",
")",
",",
"function",
"(",
"idx",
",",
"size",
")",
"{",
"$",
"(",
"DIV_TAG",
")",
".",
"appendTo",
"(",
"$popup",
")",
".",
"html",
"(",
"\"<font size=\"",
"+",
"size",
"+",
"\">\"",
"+",
"size",
"+",
"\"</font>\"",
")",
";",
"}",
")",
";",
"// Style\r",
"else",
"if",
"(",
"popupName",
"==",
"\"style\"",
")",
"$",
".",
"each",
"(",
"options",
".",
"styles",
",",
"function",
"(",
"idx",
",",
"style",
")",
"{",
"$",
"(",
"DIV_TAG",
")",
".",
"appendTo",
"(",
"$popup",
")",
".",
"html",
"(",
"style",
"[",
"1",
"]",
"+",
"style",
"[",
"0",
"]",
"+",
"style",
"[",
"1",
"]",
".",
"replace",
"(",
"\"<\"",
",",
"\"</\"",
")",
")",
";",
"}",
")",
";",
"// URL\r",
"else",
"if",
"(",
"popupName",
"==",
"\"url\"",
")",
"{",
"$popup",
".",
"html",
"(",
"'Enter URL:<br><input type=text value=\"http://\" size=35><br><input type=button value=\"Submit\">'",
")",
";",
"popupTypeClass",
"=",
"PROMPT_CLASS",
";",
"}",
"// Paste as Text\r",
"else",
"if",
"(",
"popupName",
"==",
"\"pastetext\"",
")",
"{",
"$popup",
".",
"html",
"(",
"'Paste your content here and click submit.<br /><textarea cols=40 rows=3></textarea><br /><input type=button value=Submit>'",
")",
";",
"popupTypeClass",
"=",
"PROMPT_CLASS",
";",
"}",
"// Add the popup type class name\r",
"if",
"(",
"!",
"popupTypeClass",
"&&",
"!",
"popupContent",
")",
"popupTypeClass",
"=",
"LIST_CLASS",
";",
"$popup",
".",
"addClass",
"(",
"popupTypeClass",
")",
";",
"// Add the unselectable attribute to all items\r",
"if",
"(",
"ie",
")",
"{",
"$popup",
".",
"attr",
"(",
"UNSELECTABLE",
",",
"\"on\"",
")",
".",
"find",
"(",
"\"div,font,p,h1,h2,h3,h4,h5,h6\"",
")",
".",
"attr",
"(",
"UNSELECTABLE",
",",
"\"on\"",
")",
";",
"}",
"// Add the hover effect to all items\r",
"if",
"(",
"$popup",
".",
"hasClass",
"(",
"LIST_CLASS",
")",
"||",
"popupHover",
"===",
"true",
")",
"$popup",
".",
"children",
"(",
")",
".",
"hover",
"(",
"hoverEnter",
",",
"hoverLeave",
")",
";",
"// Add the popup to the array and return it\r",
"popups",
"[",
"popupName",
"]",
"=",
"$popup",
"[",
"0",
"]",
";",
"return",
"$popup",
"[",
"0",
"]",
";",
"}"
] | createPopup - creates a popup and adds it to the body | [
"createPopup",
"-",
"creates",
"a",
"popup",
"and",
"adds",
"it",
"to",
"the",
"body"
] | 0c6333977224d8f4ef7ad40415aa69e0ff76f7b5 | https://github.com/tnantoka/LooseLeaf/blob/0c6333977224d8f4ef7ad40415aa69e0ff76f7b5/skeleton/public/javascripts/lib/cleditor/jquery.cleditor.js#L584-L668 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.