id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
53,600
aledbf/deis-api
lib/domains.js
add
function add(appName, domain, callback) { commons.post(format('/%s/apps/%s/domains/', deis.version, appName), { domain: domain.toString() }, callback); }
javascript
function add(appName, domain, callback) { commons.post(format('/%s/apps/%s/domains/', deis.version, appName), { domain: domain.toString() }, callback); }
[ "function", "add", "(", "appName", ",", "domain", ",", "callback", ")", "{", "commons", ".", "post", "(", "format", "(", "'/%s/apps/%s/domains/'", ",", "deis", ".", "version", ",", "appName", ")", ",", "{", "domain", ":", "domain", ".", "toString", "(", ")", "}", ",", "callback", ")", ";", "}" ]
Add a domain to an app registered with the Deis controller.
[ "Add", "a", "domain", "to", "an", "app", "registered", "with", "the", "Deis", "controller", "." ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/domains.js#L10-L14
53,601
aledbf/deis-api
lib/domains.js
remove
function remove(appName, domain, callback) { var url = format('/%s/apps/%s/domains/%s', deis.version, appName, domain); commons.del(url, callback); }
javascript
function remove(appName, domain, callback) { var url = format('/%s/apps/%s/domains/%s', deis.version, appName, domain); commons.del(url, callback); }
[ "function", "remove", "(", "appName", ",", "domain", ",", "callback", ")", "{", "var", "url", "=", "format", "(", "'/%s/apps/%s/domains/%s'", ",", "deis", ".", "version", ",", "appName", ",", "domain", ")", ";", "commons", ".", "del", "(", "url", ",", "callback", ")", ";", "}" ]
Remove a domain registered on an application.
[ "Remove", "a", "domain", "registered", "on", "an", "application", "." ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/domains.js#L19-L22
53,602
aledbf/deis-api
lib/domains.js
getAll
function getAll(appName, callback) { var url = format('/%s/apps/%s/domains/', deis.version, appName); commons.get(endpoint, callback); }
javascript
function getAll(appName, callback) { var url = format('/%s/apps/%s/domains/', deis.version, appName); commons.get(endpoint, callback); }
[ "function", "getAll", "(", "appName", ",", "callback", ")", "{", "var", "url", "=", "format", "(", "'/%s/apps/%s/domains/'", ",", "deis", ".", "version", ",", "appName", ")", ";", "commons", ".", "get", "(", "endpoint", ",", "callback", ")", ";", "}" ]
Get all the domains for an application.
[ "Get", "all", "the", "domains", "for", "an", "application", "." ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/domains.js#L27-L30
53,603
aledbf/deis-api
lib/domains.js
getDomain
function getDomain(domain, callback) { getAll(function onGetAll(err, domains) { if (err) { return callback(err); } callback(null, domains.results.filter(function onGetDomain(domain_obj) { return domain_obj.domain == domain; })[0]); }); }
javascript
function getDomain(domain, callback) { getAll(function onGetAll(err, domains) { if (err) { return callback(err); } callback(null, domains.results.filter(function onGetDomain(domain_obj) { return domain_obj.domain == domain; })[0]); }); }
[ "function", "getDomain", "(", "domain", ",", "callback", ")", "{", "getAll", "(", "function", "onGetAll", "(", "err", ",", "domains", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", ";", "}", "callback", "(", "null", ",", "domains", ".", "results", ".", "filter", "(", "function", "onGetDomain", "(", "domain_obj", ")", "{", "return", "domain_obj", ".", "domain", "==", "domain", ";", "}", ")", "[", "0", "]", ")", ";", "}", ")", ";", "}" ]
Get a domain by it's name.
[ "Get", "a", "domain", "by", "it", "s", "name", "." ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/domains.js#L35-L45
53,604
robgietema/twist
public/libs/jquery.selectbox.js
function (target) { var inst = this._getInst(target); if (!inst) { return FALSE; } $("#sbHolder_" + inst.uid).remove(); $.data(target, PROP_NAME, null); $(target).show(); }
javascript
function (target) { var inst = this._getInst(target); if (!inst) { return FALSE; } $("#sbHolder_" + inst.uid).remove(); $.data(target, PROP_NAME, null); $(target).show(); }
[ "function", "(", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "if", "(", "!", "inst", ")", "{", "return", "FALSE", ";", "}", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ".", "remove", "(", ")", ";", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "null", ")", ";", "$", "(", "target", ")", ".", "show", "(", ")", ";", "}" ]
Remove the selectbox functionality completely. This will return the element back to its pre-init state. @param {HTMLElement} target
[ "Remove", "the", "selectbox", "functionality", "completely", ".", "This", "will", "return", "the", "element", "back", "to", "its", "pre", "-", "init", "state", "." ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L231-L239
53,605
robgietema/twist
public/libs/jquery.selectbox.js
function (target, value, text) { var inst = this._getInst(target), onChange = this._get(inst, 'onChange'); $("#sbSelector_" + inst.uid).text(text); $(target).find("option[value='" + value + "']").attr("selected", TRUE); if (onChange) { onChange.apply((inst.input ? inst.input[0] : null), [value, inst]); } else if (inst.input) { inst.input.trigger('change'); } }
javascript
function (target, value, text) { var inst = this._getInst(target), onChange = this._get(inst, 'onChange'); $("#sbSelector_" + inst.uid).text(text); $(target).find("option[value='" + value + "']").attr("selected", TRUE); if (onChange) { onChange.apply((inst.input ? inst.input[0] : null), [value, inst]); } else if (inst.input) { inst.input.trigger('change'); } }
[ "function", "(", "target", ",", "value", ",", "text", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ",", "onChange", "=", "this", ".", "_get", "(", "inst", ",", "'onChange'", ")", ";", "$", "(", "\"#sbSelector_\"", "+", "inst", ".", "uid", ")", ".", "text", "(", "text", ")", ";", "$", "(", "target", ")", ".", "find", "(", "\"option[value='\"", "+", "value", "+", "\"']\"", ")", ".", "attr", "(", "\"selected\"", ",", "TRUE", ")", ";", "if", "(", "onChange", ")", "{", "onChange", ".", "apply", "(", "(", "inst", ".", "input", "?", "inst", ".", "input", "[", "0", "]", ":", "null", ")", ",", "[", "value", ",", "inst", "]", ")", ";", "}", "else", "if", "(", "inst", ".", "input", ")", "{", "inst", ".", "input", ".", "trigger", "(", "'change'", ")", ";", "}", "}" ]
Change selected attribute of the selectbox. @param {HTMLElement} target @param {String} value @param {String} text
[ "Change", "selected", "attribute", "of", "the", "selectbox", "." ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L247-L257
53,606
robgietema/twist
public/libs/jquery.selectbox.js
function (target) { var inst = this._getInst(target); if (!inst || !inst.isDisabled) { return FALSE; } $("#sbHolder_" + inst.uid).removeClass(inst.settings.classHolderDisabled); inst.isDisabled = FALSE; $.data(target, PROP_NAME, inst); }
javascript
function (target) { var inst = this._getInst(target); if (!inst || !inst.isDisabled) { return FALSE; } $("#sbHolder_" + inst.uid).removeClass(inst.settings.classHolderDisabled); inst.isDisabled = FALSE; $.data(target, PROP_NAME, inst); }
[ "function", "(", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "if", "(", "!", "inst", "||", "!", "inst", ".", "isDisabled", ")", "{", "return", "FALSE", ";", "}", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ".", "removeClass", "(", "inst", ".", "settings", ".", "classHolderDisabled", ")", ";", "inst", ".", "isDisabled", "=", "FALSE", ";", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "inst", ")", ";", "}" ]
Enable the selectbox. @param {HTMLElement} target
[ "Enable", "the", "selectbox", "." ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L263-L271
53,607
robgietema/twist
public/libs/jquery.selectbox.js
function (target) { var inst = this._getInst(target); if (!inst || inst.isDisabled) { return FALSE; } $("#sbHolder_" + inst.uid).addClass(inst.settings.classHolderDisabled); inst.isDisabled = TRUE; $.data(target, PROP_NAME, inst); }
javascript
function (target) { var inst = this._getInst(target); if (!inst || inst.isDisabled) { return FALSE; } $("#sbHolder_" + inst.uid).addClass(inst.settings.classHolderDisabled); inst.isDisabled = TRUE; $.data(target, PROP_NAME, inst); }
[ "function", "(", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "if", "(", "!", "inst", "||", "inst", ".", "isDisabled", ")", "{", "return", "FALSE", ";", "}", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ".", "addClass", "(", "inst", ".", "settings", ".", "classHolderDisabled", ")", ";", "inst", ".", "isDisabled", "=", "TRUE", ";", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "inst", ")", ";", "}" ]
Disable the selectbox. @param {HTMLElement} target
[ "Disable", "the", "selectbox", "." ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L277-L285
53,608
robgietema/twist
public/libs/jquery.selectbox.js
function (target, name, value) { var inst = this._getInst(target); if (!inst) { return FALSE; } //TODO check name inst[name] = value; $.data(target, PROP_NAME, inst); }
javascript
function (target, name, value) { var inst = this._getInst(target); if (!inst) { return FALSE; } //TODO check name inst[name] = value; $.data(target, PROP_NAME, inst); }
[ "function", "(", "target", ",", "name", ",", "value", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "if", "(", "!", "inst", ")", "{", "return", "FALSE", ";", "}", "//TODO check name\r", "inst", "[", "name", "]", "=", "value", ";", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "inst", ")", ";", "}" ]
Get or set any selectbox option. If no value is specified, will act as a getter. @param {HTMLElement} target @param {String} name @param {Object} value
[ "Get", "or", "set", "any", "selectbox", "option", ".", "If", "no", "value", "is", "specified", "will", "act", "as", "a", "getter", "." ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L293-L301
53,609
robgietema/twist
public/libs/jquery.selectbox.js
function (target) { var inst = this._getInst(target); //if (!inst || this._state[inst.uid] || inst.isDisabled) { if (!inst || inst.isOpen || inst.isDisabled) { return; } var el = $("#sbHolder_" + inst.uid), viewportHeight = parseInt($(window).height(), 10), offset = $("#sbHolder_" + inst.uid).offset(), scrollTop = $(window).scrollTop(), height = el.height(), diff = viewportHeight - (offset.top - scrollTop) - height / 2, onOpen = this._get(inst, 'onOpen'); // Commented this out, let html/css handle this // el.css({ // "maxHeight": (diff - height) + "px" // }); el.find(".sbContent").attr('style', 'display: block'); inst.settings.effect === "fade" ? el.fadeIn(inst.settings.speed) : el.slideDown(inst.settings.speed); el.removeClass('closed'); el.addClass('open'); $("#sbToggle_" + inst.uid).addClass(inst.settings.classToggleOpen); this._state[inst.uid] = TRUE; inst.isOpen = TRUE; if (onOpen) { onOpen.apply((inst.input ? inst.input[0] : null), [inst]); } $.data(target, PROP_NAME, inst); }
javascript
function (target) { var inst = this._getInst(target); //if (!inst || this._state[inst.uid] || inst.isDisabled) { if (!inst || inst.isOpen || inst.isDisabled) { return; } var el = $("#sbHolder_" + inst.uid), viewportHeight = parseInt($(window).height(), 10), offset = $("#sbHolder_" + inst.uid).offset(), scrollTop = $(window).scrollTop(), height = el.height(), diff = viewportHeight - (offset.top - scrollTop) - height / 2, onOpen = this._get(inst, 'onOpen'); // Commented this out, let html/css handle this // el.css({ // "maxHeight": (diff - height) + "px" // }); el.find(".sbContent").attr('style', 'display: block'); inst.settings.effect === "fade" ? el.fadeIn(inst.settings.speed) : el.slideDown(inst.settings.speed); el.removeClass('closed'); el.addClass('open'); $("#sbToggle_" + inst.uid).addClass(inst.settings.classToggleOpen); this._state[inst.uid] = TRUE; inst.isOpen = TRUE; if (onOpen) { onOpen.apply((inst.input ? inst.input[0] : null), [inst]); } $.data(target, PROP_NAME, inst); }
[ "function", "(", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "//if (!inst || this._state[inst.uid] || inst.isDisabled) {\r", "if", "(", "!", "inst", "||", "inst", ".", "isOpen", "||", "inst", ".", "isDisabled", ")", "{", "return", ";", "}", "var", "el", "=", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ",", "viewportHeight", "=", "parseInt", "(", "$", "(", "window", ")", ".", "height", "(", ")", ",", "10", ")", ",", "offset", "=", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ".", "offset", "(", ")", ",", "scrollTop", "=", "$", "(", "window", ")", ".", "scrollTop", "(", ")", ",", "height", "=", "el", ".", "height", "(", ")", ",", "diff", "=", "viewportHeight", "-", "(", "offset", ".", "top", "-", "scrollTop", ")", "-", "height", "/", "2", ",", "onOpen", "=", "this", ".", "_get", "(", "inst", ",", "'onOpen'", ")", ";", "// Commented this out, let html/css handle this\r", "//\t\t\tel.css({\r", "//\t\t\t\t\"maxHeight\": (diff - height) + \"px\"\r", "//\t\t\t});\r", "el", ".", "find", "(", "\".sbContent\"", ")", ".", "attr", "(", "'style'", ",", "'display: block'", ")", ";", "inst", ".", "settings", ".", "effect", "===", "\"fade\"", "?", "el", ".", "fadeIn", "(", "inst", ".", "settings", ".", "speed", ")", ":", "el", ".", "slideDown", "(", "inst", ".", "settings", ".", "speed", ")", ";", "el", ".", "removeClass", "(", "'closed'", ")", ";", "el", ".", "addClass", "(", "'open'", ")", ";", "$", "(", "\"#sbToggle_\"", "+", "inst", ".", "uid", ")", ".", "addClass", "(", "inst", ".", "settings", ".", "classToggleOpen", ")", ";", "this", ".", "_state", "[", "inst", ".", "uid", "]", "=", "TRUE", ";", "inst", ".", "isOpen", "=", "TRUE", ";", "if", "(", "onOpen", ")", "{", "onOpen", ".", "apply", "(", "(", "inst", ".", "input", "?", "inst", ".", "input", "[", "0", "]", ":", "null", ")", ",", "[", "inst", "]", ")", ";", "}", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "inst", ")", ";", "}" ]
Call up attached selectbox @param {HTMLElement} target
[ "Call", "up", "attached", "selectbox" ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L307-L335
53,610
robgietema/twist
public/libs/jquery.selectbox.js
function (target) { var inst = this._getInst(target); //if (!inst || !this._state[inst.uid]) { if (!inst || !inst.isOpen) { return; } var onClose = this._get(inst, 'onClose'); inst.settings.effect === "fade" ? $("#sbOptions_" + inst.uid).fadeOut(inst.settings.speed) : $("#sbOptions_" + inst.uid).slideUp(inst.settings.speed); $("#sbToggle_" + inst.uid).removeClass(inst.settings.classToggleOpen); var holder = $("#sbHolder_" + inst.uid); holder.removeClass('open'); holder.addClass('closed'); this._state[inst.uid] = FALSE; inst.isOpen = FALSE; if (onClose) { onClose.apply((inst.input ? inst.input[0] : null), [inst]); } $.data(target, PROP_NAME, inst); }
javascript
function (target) { var inst = this._getInst(target); //if (!inst || !this._state[inst.uid]) { if (!inst || !inst.isOpen) { return; } var onClose = this._get(inst, 'onClose'); inst.settings.effect === "fade" ? $("#sbOptions_" + inst.uid).fadeOut(inst.settings.speed) : $("#sbOptions_" + inst.uid).slideUp(inst.settings.speed); $("#sbToggle_" + inst.uid).removeClass(inst.settings.classToggleOpen); var holder = $("#sbHolder_" + inst.uid); holder.removeClass('open'); holder.addClass('closed'); this._state[inst.uid] = FALSE; inst.isOpen = FALSE; if (onClose) { onClose.apply((inst.input ? inst.input[0] : null), [inst]); } $.data(target, PROP_NAME, inst); }
[ "function", "(", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "target", ")", ";", "//if (!inst || !this._state[inst.uid]) {\r", "if", "(", "!", "inst", "||", "!", "inst", ".", "isOpen", ")", "{", "return", ";", "}", "var", "onClose", "=", "this", ".", "_get", "(", "inst", ",", "'onClose'", ")", ";", "inst", ".", "settings", ".", "effect", "===", "\"fade\"", "?", "$", "(", "\"#sbOptions_\"", "+", "inst", ".", "uid", ")", ".", "fadeOut", "(", "inst", ".", "settings", ".", "speed", ")", ":", "$", "(", "\"#sbOptions_\"", "+", "inst", ".", "uid", ")", ".", "slideUp", "(", "inst", ".", "settings", ".", "speed", ")", ";", "$", "(", "\"#sbToggle_\"", "+", "inst", ".", "uid", ")", ".", "removeClass", "(", "inst", ".", "settings", ".", "classToggleOpen", ")", ";", "var", "holder", "=", "$", "(", "\"#sbHolder_\"", "+", "inst", ".", "uid", ")", ";", "holder", ".", "removeClass", "(", "'open'", ")", ";", "holder", ".", "addClass", "(", "'closed'", ")", ";", "this", ".", "_state", "[", "inst", ".", "uid", "]", "=", "FALSE", ";", "inst", ".", "isOpen", "=", "FALSE", ";", "if", "(", "onClose", ")", "{", "onClose", ".", "apply", "(", "(", "inst", ".", "input", "?", "inst", ".", "input", "[", "0", "]", ":", "null", ")", ",", "[", "inst", "]", ")", ";", "}", "$", ".", "data", "(", "target", ",", "PROP_NAME", ",", "inst", ")", ";", "}" ]
Close opened selectbox @param {HTMLElement} target
[ "Close", "opened", "selectbox" ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L341-L359
53,611
robgietema/twist
public/libs/jquery.selectbox.js
function(target) { var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); return { id: id, input: target, uid: Math.floor(Math.random() * 99999999), isOpen: FALSE, isDisabled: FALSE, settings: {} }; }
javascript
function(target) { var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); return { id: id, input: target, uid: Math.floor(Math.random() * 99999999), isOpen: FALSE, isDisabled: FALSE, settings: {} }; }
[ "function", "(", "target", ")", "{", "var", "id", "=", "target", "[", "0", "]", ".", "id", ".", "replace", "(", "/", "([^A-Za-z0-9_-])", "/", "g", ",", "'\\\\\\\\$1'", ")", ";", "return", "{", "id", ":", "id", ",", "input", ":", "target", ",", "uid", ":", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "99999999", ")", ",", "isOpen", ":", "FALSE", ",", "isDisabled", ":", "FALSE", ",", "settings", ":", "{", "}", "}", ";", "}" ]
Create a new instance object @param {HTMLElement} target @return {Object}
[ "Create", "a", "new", "instance", "object" ]
7dc81080c6c28f34ad8e2334118ff416d2a004a0
https://github.com/robgietema/twist/blob/7dc81080c6c28f34ad8e2334118ff416d2a004a0/public/libs/jquery.selectbox.js#L366-L376
53,612
aledbf/deis-api
lib/commons.js
checkHttpCode
function checkHttpCode(expected, res, body, callback) { if (res.statusCode !== expected) { if (!body) { return callback(new Error(format('Unexpected deis response (expected %s but %s was returned)', expected, res.statusCode))); } var error = body.hasOwnProperty('detail') ? body.detail : JSON.stringify(body); return callback(new Error(error)); } return callback(null, body); }
javascript
function checkHttpCode(expected, res, body, callback) { if (res.statusCode !== expected) { if (!body) { return callback(new Error(format('Unexpected deis response (expected %s but %s was returned)', expected, res.statusCode))); } var error = body.hasOwnProperty('detail') ? body.detail : JSON.stringify(body); return callback(new Error(error)); } return callback(null, body); }
[ "function", "checkHttpCode", "(", "expected", ",", "res", ",", "body", ",", "callback", ")", "{", "if", "(", "res", ".", "statusCode", "!==", "expected", ")", "{", "if", "(", "!", "body", ")", "{", "return", "callback", "(", "new", "Error", "(", "format", "(", "'Unexpected deis response (expected %s but %s was returned)'", ",", "expected", ",", "res", ".", "statusCode", ")", ")", ")", ";", "}", "var", "error", "=", "body", ".", "hasOwnProperty", "(", "'detail'", ")", "?", "body", ".", "detail", ":", "JSON", ".", "stringify", "(", "body", ")", ";", "return", "callback", "(", "new", "Error", "(", "error", ")", ")", ";", "}", "return", "callback", "(", "null", ",", "body", ")", ";", "}" ]
Check if the http response returns the expected http code and return an error with the detail if the check fails @param {Number} expected http @param {Response} res @param {Object} body @param {Function} callback
[ "Check", "if", "the", "http", "response", "returns", "the", "expected", "http", "code", "and", "return", "an", "error", "with", "the", "detail", "if", "the", "check", "fails" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/commons.js#L14-L27
53,613
m59peacemaker/browser-disable-chrome-ptr
docs/docs.js
compareVersions
function compareVersions(versions) { // 1) get common precision for both versions, for example for "10.0" and "9" it should be 2 var precision = Math.max(getVersionPrecision(versions[0]), getVersionPrecision(versions[1])); var chunks = map(versions, function (version) { var delta = precision - getVersionPrecision(version); // 2) "9" -> "9.0" (for precision = 2) version = version + new Array(delta + 1).join(".0"); // 3) "9.0" -> ["000000000"", "000000009"] return map(version.split("."), function (chunk) { return new Array(20 - chunk.length).join("0") + chunk; }).reverse(); }); // iterate in reverse order by reversed chunks array while (--precision >= 0) { // 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true) if (chunks[0][precision] > chunks[1][precision]) { return 1; } else if (chunks[0][precision] === chunks[1][precision]) { if (precision === 0) { // all version chunks are same return 0; } } else { return -1; } } }
javascript
function compareVersions(versions) { // 1) get common precision for both versions, for example for "10.0" and "9" it should be 2 var precision = Math.max(getVersionPrecision(versions[0]), getVersionPrecision(versions[1])); var chunks = map(versions, function (version) { var delta = precision - getVersionPrecision(version); // 2) "9" -> "9.0" (for precision = 2) version = version + new Array(delta + 1).join(".0"); // 3) "9.0" -> ["000000000"", "000000009"] return map(version.split("."), function (chunk) { return new Array(20 - chunk.length).join("0") + chunk; }).reverse(); }); // iterate in reverse order by reversed chunks array while (--precision >= 0) { // 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true) if (chunks[0][precision] > chunks[1][precision]) { return 1; } else if (chunks[0][precision] === chunks[1][precision]) { if (precision === 0) { // all version chunks are same return 0; } } else { return -1; } } }
[ "function", "compareVersions", "(", "versions", ")", "{", "// 1) get common precision for both versions, for example for \"10.0\" and \"9\" it should be 2", "var", "precision", "=", "Math", ".", "max", "(", "getVersionPrecision", "(", "versions", "[", "0", "]", ")", ",", "getVersionPrecision", "(", "versions", "[", "1", "]", ")", ")", ";", "var", "chunks", "=", "map", "(", "versions", ",", "function", "(", "version", ")", "{", "var", "delta", "=", "precision", "-", "getVersionPrecision", "(", "version", ")", ";", "// 2) \"9\" -> \"9.0\" (for precision = 2)", "version", "=", "version", "+", "new", "Array", "(", "delta", "+", "1", ")", ".", "join", "(", "\".0\"", ")", ";", "// 3) \"9.0\" -> [\"000000000\"\", \"000000009\"]", "return", "map", "(", "version", ".", "split", "(", "\".\"", ")", ",", "function", "(", "chunk", ")", "{", "return", "new", "Array", "(", "20", "-", "chunk", ".", "length", ")", ".", "join", "(", "\"0\"", ")", "+", "chunk", ";", "}", ")", ".", "reverse", "(", ")", ";", "}", ")", ";", "// iterate in reverse order by reversed chunks array", "while", "(", "--", "precision", ">=", "0", ")", "{", "// 4) compare: \"000000009\" > \"000000010\" = false (but \"9\" > \"10\" = true)", "if", "(", "chunks", "[", "0", "]", "[", "precision", "]", ">", "chunks", "[", "1", "]", "[", "precision", "]", ")", "{", "return", "1", ";", "}", "else", "if", "(", "chunks", "[", "0", "]", "[", "precision", "]", "===", "chunks", "[", "1", "]", "[", "precision", "]", ")", "{", "if", "(", "precision", "===", "0", ")", "{", "// all version chunks are same", "return", "0", ";", "}", "}", "else", "{", "return", "-", "1", ";", "}", "}", "}" ]
Calculate browser version weight @example compareVersions(['1.10.2.1', '1.8.2.1.90']) // 1 compareVersions(['1.010.2.1', '1.09.2.1.90']); // 1 compareVersions(['1.10.2.1', '1.10.2.1']); // 0 compareVersions(['1.10.2.1', '1.0800.2']); // -1 @param {Array<String>} versions versions to compare @return {Number} comparison result
[ "Calculate", "browser", "version", "weight" ]
8170384999f0f4da5817c07b4d44347455b6de15
https://github.com/m59peacemaker/browser-disable-chrome-ptr/blob/8170384999f0f4da5817c07b4d44347455b6de15/docs/docs.js#L507-L538
53,614
m59peacemaker/browser-disable-chrome-ptr
docs/docs.js
isUnsupportedBrowser
function isUnsupportedBrowser(minVersions, strictMode, ua) { var _bowser = bowser; // make strictMode param optional with ua param usage if (typeof strictMode === 'string') { ua = strictMode; strictMode = void(0); } if (strictMode === void(0)) { strictMode = false; } if (ua) { _bowser = detect(ua); } var version = "" + _bowser.version; for (var browser in minVersions) { if (minVersions.hasOwnProperty(browser)) { if (_bowser[browser]) { if (typeof minVersions[browser] !== 'string') { throw new Error('Browser version in the minVersion map should be a string: ' + browser + ': ' + String(minVersions)); } // browser version and min supported version. return compareVersions([version, minVersions[browser]]) < 0; } } } return strictMode; // not found }
javascript
function isUnsupportedBrowser(minVersions, strictMode, ua) { var _bowser = bowser; // make strictMode param optional with ua param usage if (typeof strictMode === 'string') { ua = strictMode; strictMode = void(0); } if (strictMode === void(0)) { strictMode = false; } if (ua) { _bowser = detect(ua); } var version = "" + _bowser.version; for (var browser in minVersions) { if (minVersions.hasOwnProperty(browser)) { if (_bowser[browser]) { if (typeof minVersions[browser] !== 'string') { throw new Error('Browser version in the minVersion map should be a string: ' + browser + ': ' + String(minVersions)); } // browser version and min supported version. return compareVersions([version, minVersions[browser]]) < 0; } } } return strictMode; // not found }
[ "function", "isUnsupportedBrowser", "(", "minVersions", ",", "strictMode", ",", "ua", ")", "{", "var", "_bowser", "=", "bowser", ";", "// make strictMode param optional with ua param usage", "if", "(", "typeof", "strictMode", "===", "'string'", ")", "{", "ua", "=", "strictMode", ";", "strictMode", "=", "void", "(", "0", ")", ";", "}", "if", "(", "strictMode", "===", "void", "(", "0", ")", ")", "{", "strictMode", "=", "false", ";", "}", "if", "(", "ua", ")", "{", "_bowser", "=", "detect", "(", "ua", ")", ";", "}", "var", "version", "=", "\"\"", "+", "_bowser", ".", "version", ";", "for", "(", "var", "browser", "in", "minVersions", ")", "{", "if", "(", "minVersions", ".", "hasOwnProperty", "(", "browser", ")", ")", "{", "if", "(", "_bowser", "[", "browser", "]", ")", "{", "if", "(", "typeof", "minVersions", "[", "browser", "]", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Browser version in the minVersion map should be a string: '", "+", "browser", "+", "': '", "+", "String", "(", "minVersions", ")", ")", ";", "}", "// browser version and min supported version.", "return", "compareVersions", "(", "[", "version", ",", "minVersions", "[", "browser", "]", "]", ")", "<", "0", ";", "}", "}", "}", "return", "strictMode", ";", "// not found", "}" ]
Check if browser is unsupported @example bowser.isUnsupportedBrowser({ msie: "10", firefox: "23", chrome: "29", safari: "5.1", opera: "16", phantom: "534" }); @param {Object} minVersions map of minimal version to browser @param {Boolean} [strictMode = false] flag to return false if browser wasn't found in map @param {String} [ua] user agent string @return {Boolean}
[ "Check", "if", "browser", "is", "unsupported" ]
8170384999f0f4da5817c07b4d44347455b6de15
https://github.com/m59peacemaker/browser-disable-chrome-ptr/blob/8170384999f0f4da5817c07b4d44347455b6de15/docs/docs.js#L558-L589
53,615
spacemaus/postvox
vox-common/connection-manager.js
sendCommand
function sendCommand(method, url, payload, skipQueue) { if (!self.connected) { debug('Queueing %s %s', method, url); return new P(function(resolve, reject) { var p = P.method(function() { debug('Dequeueing %s %s', method, url); return _sendCommand(method, url, payload) .then(resolve) .catch(reject); }); if (skipQueue) { pendingCommands.splice(0, 0, p); } else { pendingCommands.push(p); } }); } return _sendCommand(method, url, payload); }
javascript
function sendCommand(method, url, payload, skipQueue) { if (!self.connected) { debug('Queueing %s %s', method, url); return new P(function(resolve, reject) { var p = P.method(function() { debug('Dequeueing %s %s', method, url); return _sendCommand(method, url, payload) .then(resolve) .catch(reject); }); if (skipQueue) { pendingCommands.splice(0, 0, p); } else { pendingCommands.push(p); } }); } return _sendCommand(method, url, payload); }
[ "function", "sendCommand", "(", "method", ",", "url", ",", "payload", ",", "skipQueue", ")", "{", "if", "(", "!", "self", ".", "connected", ")", "{", "debug", "(", "'Queueing %s %s'", ",", "method", ",", "url", ")", ";", "return", "new", "P", "(", "function", "(", "resolve", ",", "reject", ")", "{", "var", "p", "=", "P", ".", "method", "(", "function", "(", ")", "{", "debug", "(", "'Dequeueing %s %s'", ",", "method", ",", "url", ")", ";", "return", "_sendCommand", "(", "method", ",", "url", ",", "payload", ")", ".", "then", "(", "resolve", ")", ".", "catch", "(", "reject", ")", ";", "}", ")", ";", "if", "(", "skipQueue", ")", "{", "pendingCommands", ".", "splice", "(", "0", ",", "0", ",", "p", ")", ";", "}", "else", "{", "pendingCommands", ".", "push", "(", "p", ")", ";", "}", "}", ")", ";", "}", "return", "_sendCommand", "(", "method", ",", "url", ",", "payload", ")", ";", "}" ]
Helper function to send a command to the server. Returns a Promise for the server's response. Rejects the Promise if the reply's status is not 200. If this connection is not ready to receive commands, the command is queued for later execution.
[ "Helper", "function", "to", "send", "a", "command", "to", "the", "server", "." ]
de98e5ed37edaee1b1edadf93e15eb8f8d21f457
https://github.com/spacemaus/postvox/blob/de98e5ed37edaee1b1edadf93e15eb8f8d21f457/vox-common/connection-manager.js#L288-L306
53,616
danigb/step-seq
index.js
sequencer
function sequencer (ctx, callback) { var timer, iterable, iterator, nextTick, tempo, tickInterval, lookahead function emit (event, data, time, duration) { setTimeout(function () { callback(event, data, time, duration) }, 0) } function sequence (data) { if (!data) iterator = rangeIterator(0, Infinity) else if (typeof data === 'function') iterator = data else if (Math.floor(data) === data) iterator = rangeIterator(0, data) else if (typeof data === 'string') iterator = arrayIterator(data.split(' ')) else if (Array.isArray(data)) iterator = arrayIterator(data) else iterator = arrayIterator([ data ]) return sequence } sequence.tempo = function (newTempo) { if (arguments.length === 0) return tempo tempo = newTempo tickInterval = 60 / tempo lookahead = tickInterval * 0.1 return sequence } sequence.start = function () { if (!timer) { iterable = iterator() nextTick = ctx.currentTime + lookahead emit('start', null, nextTick) timer = setInterval(schedule, lookahead) } return sequence } sequence.stop = function () { if (timer) { clearInterval(timer) timer = null emit('stop') } return sequence } function schedule () { var current = ctx.currentTime var ahead = current + lookahead if (nextTick >= current && nextTick < ahead) { var n = iterable.next() if (n.done) { sequence.stop() } else { callback('data', n.value, nextTick, tickInterval) } nextTick += tickInterval } } return sequence().tempo(120) }
javascript
function sequencer (ctx, callback) { var timer, iterable, iterator, nextTick, tempo, tickInterval, lookahead function emit (event, data, time, duration) { setTimeout(function () { callback(event, data, time, duration) }, 0) } function sequence (data) { if (!data) iterator = rangeIterator(0, Infinity) else if (typeof data === 'function') iterator = data else if (Math.floor(data) === data) iterator = rangeIterator(0, data) else if (typeof data === 'string') iterator = arrayIterator(data.split(' ')) else if (Array.isArray(data)) iterator = arrayIterator(data) else iterator = arrayIterator([ data ]) return sequence } sequence.tempo = function (newTempo) { if (arguments.length === 0) return tempo tempo = newTempo tickInterval = 60 / tempo lookahead = tickInterval * 0.1 return sequence } sequence.start = function () { if (!timer) { iterable = iterator() nextTick = ctx.currentTime + lookahead emit('start', null, nextTick) timer = setInterval(schedule, lookahead) } return sequence } sequence.stop = function () { if (timer) { clearInterval(timer) timer = null emit('stop') } return sequence } function schedule () { var current = ctx.currentTime var ahead = current + lookahead if (nextTick >= current && nextTick < ahead) { var n = iterable.next() if (n.done) { sequence.stop() } else { callback('data', n.value, nextTick, tickInterval) } nextTick += tickInterval } } return sequence().tempo(120) }
[ "function", "sequencer", "(", "ctx", ",", "callback", ")", "{", "var", "timer", ",", "iterable", ",", "iterator", ",", "nextTick", ",", "tempo", ",", "tickInterval", ",", "lookahead", "function", "emit", "(", "event", ",", "data", ",", "time", ",", "duration", ")", "{", "setTimeout", "(", "function", "(", ")", "{", "callback", "(", "event", ",", "data", ",", "time", ",", "duration", ")", "}", ",", "0", ")", "}", "function", "sequence", "(", "data", ")", "{", "if", "(", "!", "data", ")", "iterator", "=", "rangeIterator", "(", "0", ",", "Infinity", ")", "else", "if", "(", "typeof", "data", "===", "'function'", ")", "iterator", "=", "data", "else", "if", "(", "Math", ".", "floor", "(", "data", ")", "===", "data", ")", "iterator", "=", "rangeIterator", "(", "0", ",", "data", ")", "else", "if", "(", "typeof", "data", "===", "'string'", ")", "iterator", "=", "arrayIterator", "(", "data", ".", "split", "(", "' '", ")", ")", "else", "if", "(", "Array", ".", "isArray", "(", "data", ")", ")", "iterator", "=", "arrayIterator", "(", "data", ")", "else", "iterator", "=", "arrayIterator", "(", "[", "data", "]", ")", "return", "sequence", "}", "sequence", ".", "tempo", "=", "function", "(", "newTempo", ")", "{", "if", "(", "arguments", ".", "length", "===", "0", ")", "return", "tempo", "tempo", "=", "newTempo", "tickInterval", "=", "60", "/", "tempo", "lookahead", "=", "tickInterval", "*", "0.1", "return", "sequence", "}", "sequence", ".", "start", "=", "function", "(", ")", "{", "if", "(", "!", "timer", ")", "{", "iterable", "=", "iterator", "(", ")", "nextTick", "=", "ctx", ".", "currentTime", "+", "lookahead", "emit", "(", "'start'", ",", "null", ",", "nextTick", ")", "timer", "=", "setInterval", "(", "schedule", ",", "lookahead", ")", "}", "return", "sequence", "}", "sequence", ".", "stop", "=", "function", "(", ")", "{", "if", "(", "timer", ")", "{", "clearInterval", "(", "timer", ")", "timer", "=", "null", "emit", "(", "'stop'", ")", "}", "return", "sequence", "}", "function", "schedule", "(", ")", "{", "var", "current", "=", "ctx", ".", "currentTime", "var", "ahead", "=", "current", "+", "lookahead", "if", "(", "nextTick", ">=", "current", "&&", "nextTick", "<", "ahead", ")", "{", "var", "n", "=", "iterable", ".", "next", "(", ")", "if", "(", "n", ".", "done", ")", "{", "sequence", ".", "stop", "(", ")", "}", "else", "{", "callback", "(", "'data'", ",", "n", ".", "value", ",", "nextTick", ",", "tickInterval", ")", "}", "nextTick", "+=", "tickInterval", "}", "}", "return", "sequence", "(", ")", ".", "tempo", "(", "120", ")", "}" ]
Create a sequence A sequence is an object with two methods: start and stop @param {AudioContext} ctx - the audio context @param {Function} player - the function that plays the song @param {Integer} tempo - the tempo @param {Array|Integer} data - the data source
[ "Create", "a", "sequence" ]
4014eecff5728fe07adc36071276d94e277bf437
https://github.com/danigb/step-seq/blob/4014eecff5728fe07adc36071276d94e277bf437/index.js#L13-L72
53,617
cliffano/cmdt
lib/checker.js
_checkExitCode
function _checkExitCode(result, test) { var actual = result.exitcode; var expect = test.exitcode; var error; if (typeof expect === 'string') { expect = parseInt(expect, 10); } if (expect !== undefined && expect !== actual) { error = util.format('Exit code %d does not match expected %d', actual, expect); } return error; }
javascript
function _checkExitCode(result, test) { var actual = result.exitcode; var expect = test.exitcode; var error; if (typeof expect === 'string') { expect = parseInt(expect, 10); } if (expect !== undefined && expect !== actual) { error = util.format('Exit code %d does not match expected %d', actual, expect); } return error; }
[ "function", "_checkExitCode", "(", "result", ",", "test", ")", "{", "var", "actual", "=", "result", ".", "exitcode", ";", "var", "expect", "=", "test", ".", "exitcode", ";", "var", "error", ";", "if", "(", "typeof", "expect", "===", "'string'", ")", "{", "expect", "=", "parseInt", "(", "expect", ",", "10", ")", ";", "}", "if", "(", "expect", "!==", "undefined", "&&", "expect", "!==", "actual", ")", "{", "error", "=", "util", ".", "format", "(", "'Exit code %d does not match expected %d'", ",", "actual", ",", "expect", ")", ";", "}", "return", "error", ";", "}" ]
Check result exit code against expectated exit code. @param {Object} result: command execution result @param {Object} test: test expectation @return {Object} error if actual exit code doesn't equal expected exit code
[ "Check", "result", "exit", "code", "against", "expectated", "exit", "code", "." ]
8b8de56a23994a02117069c9c6da5fa1a3176fe5
https://github.com/cliffano/cmdt/blob/8b8de56a23994a02117069c9c6da5fa1a3176fe5/lib/checker.js#L10-L25
53,618
cliffano/cmdt
lib/checker.js
check
function check(result, test) { const CHECKERS = [ _checkExitCode, _checkOutput, _checkStdout, _checkStderr ]; var errors = []; CHECKERS.forEach(function (checker) { var error = checker(result, test); if (error) { errors.push(error); } }); return errors; }
javascript
function check(result, test) { const CHECKERS = [ _checkExitCode, _checkOutput, _checkStdout, _checkStderr ]; var errors = []; CHECKERS.forEach(function (checker) { var error = checker(result, test); if (error) { errors.push(error); } }); return errors; }
[ "function", "check", "(", "result", ",", "test", ")", "{", "const", "CHECKERS", "=", "[", "_checkExitCode", ",", "_checkOutput", ",", "_checkStdout", ",", "_checkStderr", "]", ";", "var", "errors", "=", "[", "]", ";", "CHECKERS", ".", "forEach", "(", "function", "(", "checker", ")", "{", "var", "error", "=", "checker", "(", "result", ",", "test", ")", ";", "if", "(", "error", ")", "{", "errors", ".", "push", "(", "error", ")", ";", "}", "}", ")", ";", "return", "errors", ";", "}" ]
Check command execution result with test expectation against a set of check functions. @param {Object} result: command execution result @param {Object} test: test expectation @return {Array} check errors
[ "Check", "command", "execution", "result", "with", "test", "expectation", "against", "a", "set", "of", "check", "functions", "." ]
8b8de56a23994a02117069c9c6da5fa1a3176fe5
https://github.com/cliffano/cmdt/blob/8b8de56a23994a02117069c9c6da5fa1a3176fe5/lib/checker.js#L80-L93
53,619
yeptlabs/wns
src/core/base/wnComponent.js
function (obj) { if (typeof obj === 'undefined') { obj = this.getConfig(); delete obj.class; } if (typeof obj == 'object') { delete obj.autoInit; delete obj.id; delete obj.serverID; delete obj.modulePath; for (o in obj) { this.exportConfig(obj[o]); } } return JSON.stringify(obj, null, '\t'); }
javascript
function (obj) { if (typeof obj === 'undefined') { obj = this.getConfig(); delete obj.class; } if (typeof obj == 'object') { delete obj.autoInit; delete obj.id; delete obj.serverID; delete obj.modulePath; for (o in obj) { this.exportConfig(obj[o]); } } return JSON.stringify(obj, null, '\t'); }
[ "function", "(", "obj", ")", "{", "if", "(", "typeof", "obj", "===", "'undefined'", ")", "{", "obj", "=", "this", ".", "getConfig", "(", ")", ";", "delete", "obj", ".", "class", ";", "}", "if", "(", "typeof", "obj", "==", "'object'", ")", "{", "delete", "obj", ".", "autoInit", ";", "delete", "obj", ".", "id", ";", "delete", "obj", ".", "serverID", ";", "delete", "obj", ".", "modulePath", ";", "for", "(", "o", "in", "obj", ")", "{", "this", ".", "exportConfig", "(", "obj", "[", "o", "]", ")", ";", "}", "}", "return", "JSON", ".", "stringify", "(", "obj", ",", "null", ",", "'\\t'", ")", ";", "}" ]
Export to JSON the components's config. @param object $obj @return object
[ "Export", "to", "JSON", "the", "components", "s", "config", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L195-L218
53,620
yeptlabs/wns
src/core/base/wnComponent.js
function (filePath) { if (typeof arguments[1]=='function') var cb = arguments[1]; if (typeof arguments[2]=='function') var cb = arguments[2]; var binary = typeof arguments[1]=='boolean' ? arguments[1] : false, realPath = this.instanceOf('wnModule')?this.modulePath+filePath:filePath, cmd = !cb ? 'readFileSync' : 'readFile'; try { var _cb = cb ? function (err,file) { cb&&cb(!err ? ((binary===true) ? file : file.toString()) : false); } : null, file = fs[cmd](realPath,_cb); } catch (e) { if (_cb) cb&&cb(false); else return false; } return (file ? (binary===true) ? file : file.toString() : false); }
javascript
function (filePath) { if (typeof arguments[1]=='function') var cb = arguments[1]; if (typeof arguments[2]=='function') var cb = arguments[2]; var binary = typeof arguments[1]=='boolean' ? arguments[1] : false, realPath = this.instanceOf('wnModule')?this.modulePath+filePath:filePath, cmd = !cb ? 'readFileSync' : 'readFile'; try { var _cb = cb ? function (err,file) { cb&&cb(!err ? ((binary===true) ? file : file.toString()) : false); } : null, file = fs[cmd](realPath,_cb); } catch (e) { if (_cb) cb&&cb(false); else return false; } return (file ? (binary===true) ? file : file.toString() : false); }
[ "function", "(", "filePath", ")", "{", "if", "(", "typeof", "arguments", "[", "1", "]", "==", "'function'", ")", "var", "cb", "=", "arguments", "[", "1", "]", ";", "if", "(", "typeof", "arguments", "[", "2", "]", "==", "'function'", ")", "var", "cb", "=", "arguments", "[", "2", "]", ";", "var", "binary", "=", "typeof", "arguments", "[", "1", "]", "==", "'boolean'", "?", "arguments", "[", "1", "]", ":", "false", ",", "realPath", "=", "this", ".", "instanceOf", "(", "'wnModule'", ")", "?", "this", ".", "modulePath", "+", "filePath", ":", "filePath", ",", "cmd", "=", "!", "cb", "?", "'readFileSync'", ":", "'readFile'", ";", "try", "{", "var", "_cb", "=", "cb", "?", "function", "(", "err", ",", "file", ")", "{", "cb", "&&", "cb", "(", "!", "err", "?", "(", "(", "binary", "===", "true", ")", "?", "file", ":", "file", ".", "toString", "(", ")", ")", ":", "false", ")", ";", "}", ":", "null", ",", "file", "=", "fs", "[", "cmd", "]", "(", "realPath", ",", "_cb", ")", ";", "}", "catch", "(", "e", ")", "{", "if", "(", "_cb", ")", "cb", "&&", "cb", "(", "false", ")", ";", "else", "return", "false", ";", "}", "return", "(", "file", "?", "(", "binary", "===", "true", ")", "?", "file", ":", "file", ".", "toString", "(", ")", ":", "false", ")", ";", "}" ]
Get a file. The file's path is relative to the module's path. @param string $filePath file's path @param boolean $binary is it binary? @param function $cb async callback function @return boolean|string
[ "Get", "a", "file", ".", "The", "file", "s", "path", "is", "relative", "to", "the", "module", "s", "path", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L228-L253
53,621
yeptlabs/wns
src/core/base/wnComponent.js
function (filePath,cb) { var realPath = this.instanceOf('wnModule')?this.modulePath+filePath:filePath, cmd = !cb ? 'statSync' : 'stat'; if (!fs.existsSync(realPath)) return (cb&&cb(false) == true); var _cb = cb ? function (err,stat) { cb&&cb(!err ? stat : false); } : null, stat = fs[cmd](realPath,_cb); return stat; }
javascript
function (filePath,cb) { var realPath = this.instanceOf('wnModule')?this.modulePath+filePath:filePath, cmd = !cb ? 'statSync' : 'stat'; if (!fs.existsSync(realPath)) return (cb&&cb(false) == true); var _cb = cb ? function (err,stat) { cb&&cb(!err ? stat : false); } : null, stat = fs[cmd](realPath,_cb); return stat; }
[ "function", "(", "filePath", ",", "cb", ")", "{", "var", "realPath", "=", "this", ".", "instanceOf", "(", "'wnModule'", ")", "?", "this", ".", "modulePath", "+", "filePath", ":", "filePath", ",", "cmd", "=", "!", "cb", "?", "'statSync'", ":", "'stat'", ";", "if", "(", "!", "fs", ".", "existsSync", "(", "realPath", ")", ")", "return", "(", "cb", "&&", "cb", "(", "false", ")", "==", "true", ")", ";", "var", "_cb", "=", "cb", "?", "function", "(", "err", ",", "stat", ")", "{", "cb", "&&", "cb", "(", "!", "err", "?", "stat", ":", "false", ")", ";", "}", ":", "null", ",", "stat", "=", "fs", "[", "cmd", "]", "(", "realPath", ",", "_cb", ")", ";", "return", "stat", ";", "}" ]
Get a file statistic. The file's path is relative to the module's path. @param string $filePath file's path @param function $cb callback
[ "Get", "a", "file", "statistic", ".", "The", "file", "s", "path", "is", "relative", "to", "the", "module", "s", "path", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L291-L302
53,622
yeptlabs/wns
src/core/base/wnComponent.js
function () { this.e.log&&this.e.log('Preloading events...','system'); var preload = {}; _.merge(preload,this.defaultEvents); _.merge(preload,this.getConfig().events); if (preload != undefined) this.setEvents(preload); for (e in preload) { this.getEvent(e); } this.attachEventsHandlers(); return this; }
javascript
function () { this.e.log&&this.e.log('Preloading events...','system'); var preload = {}; _.merge(preload,this.defaultEvents); _.merge(preload,this.getConfig().events); if (preload != undefined) this.setEvents(preload); for (e in preload) { this.getEvent(e); } this.attachEventsHandlers(); return this; }
[ "function", "(", ")", "{", "this", ".", "e", ".", "log", "&&", "this", ".", "e", ".", "log", "(", "'Preloading events...'", ",", "'system'", ")", ";", "var", "preload", "=", "{", "}", ";", "_", ".", "merge", "(", "preload", ",", "this", ".", "defaultEvents", ")", ";", "_", ".", "merge", "(", "preload", ",", "this", ".", "getConfig", "(", ")", ".", "events", ")", ";", "if", "(", "preload", "!=", "undefined", ")", "this", ".", "setEvents", "(", "preload", ")", ";", "for", "(", "e", "in", "preload", ")", "{", "this", ".", "getEvent", "(", "e", ")", ";", "}", "this", ".", "attachEventsHandlers", "(", ")", ";", "return", "this", ";", "}" ]
Preload all required events @return this
[ "Preload", "all", "required", "events" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L308-L322
53,623
yeptlabs/wns
src/core/base/wnComponent.js
function (className,config,path,npmPath) { var source = this.c || process.wns; var instance; var builder = this.getComponent&&this.getComponent('classBuilder'); if (!source || !source[className]) { return false; } if (config.id) source[className].build.id = config.id; if (source[className].build.extend.indexOf('wnModule')!==-1) { instance = new source[className](self,config,path,npmPath,builder.classesPath); } else instance = new source[className](config,source); if (WNS_TEST && builder) { console.log('- Testing '+className) var tests = builder.classes[className].test; for (t in tests) { //console.log('Testing: '+t); tests[t](instance); } } return instance; }
javascript
function (className,config,path,npmPath) { var source = this.c || process.wns; var instance; var builder = this.getComponent&&this.getComponent('classBuilder'); if (!source || !source[className]) { return false; } if (config.id) source[className].build.id = config.id; if (source[className].build.extend.indexOf('wnModule')!==-1) { instance = new source[className](self,config,path,npmPath,builder.classesPath); } else instance = new source[className](config,source); if (WNS_TEST && builder) { console.log('- Testing '+className) var tests = builder.classes[className].test; for (t in tests) { //console.log('Testing: '+t); tests[t](instance); } } return instance; }
[ "function", "(", "className", ",", "config", ",", "path", ",", "npmPath", ")", "{", "var", "source", "=", "this", ".", "c", "||", "process", ".", "wns", ";", "var", "instance", ";", "var", "builder", "=", "this", ".", "getComponent", "&&", "this", ".", "getComponent", "(", "'classBuilder'", ")", ";", "if", "(", "!", "source", "||", "!", "source", "[", "className", "]", ")", "{", "return", "false", ";", "}", "if", "(", "config", ".", "id", ")", "source", "[", "className", "]", ".", "build", ".", "id", "=", "config", ".", "id", ";", "if", "(", "source", "[", "className", "]", ".", "build", ".", "extend", ".", "indexOf", "(", "'wnModule'", ")", "!==", "-", "1", ")", "{", "instance", "=", "new", "source", "[", "className", "]", "(", "self", ",", "config", ",", "path", ",", "npmPath", ",", "builder", ".", "classesPath", ")", ";", "}", "else", "instance", "=", "new", "source", "[", "className", "]", "(", "config", ",", "source", ")", ";", "if", "(", "WNS_TEST", "&&", "builder", ")", "{", "console", ".", "log", "(", "'- Testing '", "+", "className", ")", "var", "tests", "=", "builder", ".", "classes", "[", "className", "]", ".", "test", ";", "for", "(", "t", "in", "tests", ")", "{", "//console.log('Testing: '+t);", "tests", "[", "t", "]", "(", "instance", ")", ";", "}", "}", "return", "instance", ";", "}" ]
Create an class from the classSources. @param string $className name of the class @param object $config class configuration @param component $boolean is it component format? @return boolean|object
[ "Create", "an", "class", "from", "the", "classSources", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L331-L361
53,624
yeptlabs/wns
src/core/base/wnComponent.js
function () { this.e.log&&this.e.log("Attaching default event's handlers...",'system'); var events = this.getEvents(); for (e in events) { var eventName = e.split('-').pop(), event = this.getEvent(eventName), evtConfig = event.getConfig(); if (evtConfig.handler != null && this[evtConfig.handler] && typeof this[evtConfig.handler] == 'function') { event.addListener(this[evtConfig.handler]); event.setConfig({ handler: null }); } if (evtConfig.listenEvent != null && e.indexOf('event-module') == -1 && this.hasEvent(evtConfig.listenEvent)) { var listenTo = this.getEvent(evtConfig.listenEvent), listenName = evtConfig.listenEvent+''; listenTo.addListener(function (e) { if (typeof e == 'object' && e.stopPropagation == true) return false; this.event.emit.apply(this.event,arguments); }.bind({ event: event })); event.setConfig({ listenEvent: null }); } } }
javascript
function () { this.e.log&&this.e.log("Attaching default event's handlers...",'system'); var events = this.getEvents(); for (e in events) { var eventName = e.split('-').pop(), event = this.getEvent(eventName), evtConfig = event.getConfig(); if (evtConfig.handler != null && this[evtConfig.handler] && typeof this[evtConfig.handler] == 'function') { event.addListener(this[evtConfig.handler]); event.setConfig({ handler: null }); } if (evtConfig.listenEvent != null && e.indexOf('event-module') == -1 && this.hasEvent(evtConfig.listenEvent)) { var listenTo = this.getEvent(evtConfig.listenEvent), listenName = evtConfig.listenEvent+''; listenTo.addListener(function (e) { if (typeof e == 'object' && e.stopPropagation == true) return false; this.event.emit.apply(this.event,arguments); }.bind({ event: event })); event.setConfig({ listenEvent: null }); } } }
[ "function", "(", ")", "{", "this", ".", "e", ".", "log", "&&", "this", ".", "e", ".", "log", "(", "\"Attaching default event's handlers...\"", ",", "'system'", ")", ";", "var", "events", "=", "this", ".", "getEvents", "(", ")", ";", "for", "(", "e", "in", "events", ")", "{", "var", "eventName", "=", "e", ".", "split", "(", "'-'", ")", ".", "pop", "(", ")", ",", "event", "=", "this", ".", "getEvent", "(", "eventName", ")", ",", "evtConfig", "=", "event", ".", "getConfig", "(", ")", ";", "if", "(", "evtConfig", ".", "handler", "!=", "null", "&&", "this", "[", "evtConfig", ".", "handler", "]", "&&", "typeof", "this", "[", "evtConfig", ".", "handler", "]", "==", "'function'", ")", "{", "event", ".", "addListener", "(", "this", "[", "evtConfig", ".", "handler", "]", ")", ";", "event", ".", "setConfig", "(", "{", "handler", ":", "null", "}", ")", ";", "}", "if", "(", "evtConfig", ".", "listenEvent", "!=", "null", "&&", "e", ".", "indexOf", "(", "'event-module'", ")", "==", "-", "1", "&&", "this", ".", "hasEvent", "(", "evtConfig", ".", "listenEvent", ")", ")", "{", "var", "listenTo", "=", "this", ".", "getEvent", "(", "evtConfig", ".", "listenEvent", ")", ",", "listenName", "=", "evtConfig", ".", "listenEvent", "+", "''", ";", "listenTo", ".", "addListener", "(", "function", "(", "e", ")", "{", "if", "(", "typeof", "e", "==", "'object'", "&&", "e", ".", "stopPropagation", "==", "true", ")", "return", "false", ";", "this", ".", "event", ".", "emit", ".", "apply", "(", "this", ".", "event", ",", "arguments", ")", ";", "}", ".", "bind", "(", "{", "event", ":", "event", "}", ")", ")", ";", "event", ".", "setConfig", "(", "{", "listenEvent", ":", "null", "}", ")", ";", "}", "}", "}" ]
Search for handlers and eventlisteners of all events of this component.
[ "Search", "for", "handlers", "and", "eventlisteners", "of", "all", "events", "of", "this", "component", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L367-L395
53,625
yeptlabs/wns
src/core/base/wnComponent.js
function (events) { var event = {}; for (e in events) { var ref=events[e], e = 'event-'+e.replace('-','.'); event[e]=ref; event[e].class=ref.class || 'wnEvent'; event[e].eventName = e.split('-').pop(); if (this.hasEvent(e)) { _.merge(event[e],this.getEvent(e)); } _eventsConfig[e]=_eventsConfig[e] || {}; _.merge(_eventsConfig[e], event[e]); } return this; }
javascript
function (events) { var event = {}; for (e in events) { var ref=events[e], e = 'event-'+e.replace('-','.'); event[e]=ref; event[e].class=ref.class || 'wnEvent'; event[e].eventName = e.split('-').pop(); if (this.hasEvent(e)) { _.merge(event[e],this.getEvent(e)); } _eventsConfig[e]=_eventsConfig[e] || {}; _.merge(_eventsConfig[e], event[e]); } return this; }
[ "function", "(", "events", ")", "{", "var", "event", "=", "{", "}", ";", "for", "(", "e", "in", "events", ")", "{", "var", "ref", "=", "events", "[", "e", "]", ",", "e", "=", "'event-'", "+", "e", ".", "replace", "(", "'-'", ",", "'.'", ")", ";", "event", "[", "e", "]", "=", "ref", ";", "event", "[", "e", "]", ".", "class", "=", "ref", ".", "class", "||", "'wnEvent'", ";", "event", "[", "e", "]", ".", "eventName", "=", "e", ".", "split", "(", "'-'", ")", ".", "pop", "(", ")", ";", "if", "(", "this", ".", "hasEvent", "(", "e", ")", ")", "{", "_", ".", "merge", "(", "event", "[", "e", "]", ",", "this", ".", "getEvent", "(", "e", ")", ")", ";", "}", "_eventsConfig", "[", "e", "]", "=", "_eventsConfig", "[", "e", "]", "||", "{", "}", ";", "_", ".", "merge", "(", "_eventsConfig", "[", "e", "]", ",", "event", "[", "e", "]", ")", ";", "}", "return", "this", ";", "}" ]
Set new properties to the respective events @param object $events events configurations @return this
[ "Set", "new", "properties", "to", "the", "respective", "events" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L402-L420
53,626
yeptlabs/wns
src/core/base/wnComponent.js
function (name,hidden) { var eventName = 'event-'+name; if (_events[eventName] != undefined) return _events[eventName]; else { if (!_eventsConfig[eventName] || !this.c) return false; var config = _eventsConfig[eventName] || {}, _class = config.class; config.id = eventName; config.autoInit = false; var evt = this.createClass(_class,config); if (evt) { evt.setParent(this); evt.init(); if (hidden != false) { _events[eventName] = evt; this.e[name]=evt.emit; } else { Object.defineProperty(_events[eventName],{ value: evt, enumerable: false }); } return evt; } return false; } }
javascript
function (name,hidden) { var eventName = 'event-'+name; if (_events[eventName] != undefined) return _events[eventName]; else { if (!_eventsConfig[eventName] || !this.c) return false; var config = _eventsConfig[eventName] || {}, _class = config.class; config.id = eventName; config.autoInit = false; var evt = this.createClass(_class,config); if (evt) { evt.setParent(this); evt.init(); if (hidden != false) { _events[eventName] = evt; this.e[name]=evt.emit; } else { Object.defineProperty(_events[eventName],{ value: evt, enumerable: false }); } return evt; } return false; } }
[ "function", "(", "name", ",", "hidden", ")", "{", "var", "eventName", "=", "'event-'", "+", "name", ";", "if", "(", "_events", "[", "eventName", "]", "!=", "undefined", ")", "return", "_events", "[", "eventName", "]", ";", "else", "{", "if", "(", "!", "_eventsConfig", "[", "eventName", "]", "||", "!", "this", ".", "c", ")", "return", "false", ";", "var", "config", "=", "_eventsConfig", "[", "eventName", "]", "||", "{", "}", ",", "_class", "=", "config", ".", "class", ";", "config", ".", "id", "=", "eventName", ";", "config", ".", "autoInit", "=", "false", ";", "var", "evt", "=", "this", ".", "createClass", "(", "_class", ",", "config", ")", ";", "if", "(", "evt", ")", "{", "evt", ".", "setParent", "(", "this", ")", ";", "evt", ".", "init", "(", ")", ";", "if", "(", "hidden", "!=", "false", ")", "{", "_events", "[", "eventName", "]", "=", "evt", ";", "this", ".", "e", "[", "name", "]", "=", "evt", ".", "emit", ";", "}", "else", "{", "Object", ".", "defineProperty", "(", "_events", "[", "eventName", "]", ",", "{", "value", ":", "evt", ",", "enumerable", ":", "false", "}", ")", ";", "}", "return", "evt", ";", "}", "return", "false", ";", "}", "}" ]
Get an event and create an alias to the push function. @param string $name eventName @param boolean $hidden ? @return wnEvent
[ "Get", "an", "event", "and", "create", "an", "alias", "to", "the", "push", "function", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L428-L458
53,627
yeptlabs/wns
src/core/base/wnComponent.js
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.addListener(handler)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
javascript
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.addListener(handler)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
[ "function", "(", "eventName", ",", "handler", ")", "{", "var", "event", ";", "if", "(", "event", "=", "this", ".", "getEvent", "(", "eventName", ")", ")", "{", "if", "(", "!", "event", ".", "addListener", "(", "handler", ")", ")", "this", ".", "e", ".", "log", "(", "'Invalid handler sent to event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "}", "else", "this", ".", "e", ".", "log", "(", "'Not existent event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "return", "this", ";", "}" ]
Add a new listener to the event, if it exists @param string $eventName event name @param function $handler event handler @return this
[ "Add", "a", "new", "listener", "to", "the", "event", "if", "it", "exists" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L510-L519
53,628
yeptlabs/wns
src/core/base/wnComponent.js
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.prependListener(handler)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
javascript
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.prependListener(handler)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
[ "function", "(", "eventName", ",", "handler", ")", "{", "var", "event", ";", "if", "(", "event", "=", "this", ".", "getEvent", "(", "eventName", ")", ")", "{", "if", "(", "!", "event", ".", "prependListener", "(", "handler", ")", ")", "this", ".", "e", ".", "log", "(", "'Invalid handler sent to event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "}", "else", "this", ".", "e", ".", "log", "(", "'Not existent event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "return", "this", ";", "}" ]
Prepend a new listener to the event, if it exists @param string $eventName event name @param function $handler event handler @return this
[ "Prepend", "a", "new", "listener", "to", "the", "event", "if", "it", "exists" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L527-L536
53,629
yeptlabs/wns
src/core/base/wnComponent.js
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.once(handler,true)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
javascript
function (eventName,handler) { var event; if (event = this.getEvent(eventName)) { if (!event.once(handler,true)) this.e.log('Invalid handler sent to event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); } else this.e.log('Not existent event `'+eventName+'` on `'+this.getConfig('id')+'`','warning'); return this; }
[ "function", "(", "eventName", ",", "handler", ")", "{", "var", "event", ";", "if", "(", "event", "=", "this", ".", "getEvent", "(", "eventName", ")", ")", "{", "if", "(", "!", "event", ".", "once", "(", "handler", ",", "true", ")", ")", "this", ".", "e", ".", "log", "(", "'Invalid handler sent to event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "}", "else", "this", ".", "e", ".", "log", "(", "'Not existent event `'", "+", "eventName", "+", "'` on `'", "+", "this", ".", "getConfig", "(", "'id'", ")", "+", "'`'", ",", "'warning'", ")", ";", "return", "this", ";", "}" ]
Prepend a new one-time-listener to the event, if it exists @param string $eventName event name @param function $handler event handler @return this
[ "Prepend", "a", "new", "one", "-", "time", "-", "listener", "to", "the", "event", "if", "it", "exists" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L544-L553
53,630
yeptlabs/wns
src/core/base/wnComponent.js
function () { var _export = {}, merge = {}; _.merge(merge,this.getConfig()); _.merge(merge,this); var proto = this._proto.public; for (p in proto) if (!((typeof proto[p] == 'object' || typeof proto[p] == 'function') && proto[p] != null && proto[p].instanceOf!=undefined)) _export[p] = proto[p]; for (p in merge) if (!((typeof merge[p] == 'object' || typeof merge[p] == 'function') && merge[p] != null && merge[p].instanceOf!=undefined)) _export[p] = merge[p]; return _export; }
javascript
function () { var _export = {}, merge = {}; _.merge(merge,this.getConfig()); _.merge(merge,this); var proto = this._proto.public; for (p in proto) if (!((typeof proto[p] == 'object' || typeof proto[p] == 'function') && proto[p] != null && proto[p].instanceOf!=undefined)) _export[p] = proto[p]; for (p in merge) if (!((typeof merge[p] == 'object' || typeof merge[p] == 'function') && merge[p] != null && merge[p].instanceOf!=undefined)) _export[p] = merge[p]; return _export; }
[ "function", "(", ")", "{", "var", "_export", "=", "{", "}", ",", "merge", "=", "{", "}", ";", "_", ".", "merge", "(", "merge", ",", "this", ".", "getConfig", "(", ")", ")", ";", "_", ".", "merge", "(", "merge", ",", "this", ")", ";", "var", "proto", "=", "this", ".", "_proto", ".", "public", ";", "for", "(", "p", "in", "proto", ")", "if", "(", "!", "(", "(", "typeof", "proto", "[", "p", "]", "==", "'object'", "||", "typeof", "proto", "[", "p", "]", "==", "'function'", ")", "&&", "proto", "[", "p", "]", "!=", "null", "&&", "proto", "[", "p", "]", ".", "instanceOf", "!=", "undefined", ")", ")", "_export", "[", "p", "]", "=", "proto", "[", "p", "]", ";", "for", "(", "p", "in", "merge", ")", "if", "(", "!", "(", "(", "typeof", "merge", "[", "p", "]", "==", "'object'", "||", "typeof", "merge", "[", "p", "]", "==", "'function'", ")", "&&", "merge", "[", "p", "]", "!=", "null", "&&", "merge", "[", "p", "]", ".", "instanceOf", "!=", "undefined", ")", ")", "_export", "[", "p", "]", "=", "merge", "[", "p", "]", ";", "return", "_export", ";", "}" ]
Return an object with all attributes and configuration of this component @return object
[ "Return", "an", "object", "with", "all", "attributes", "and", "configuration", "of", "this", "component" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L559-L575
53,631
yeptlabs/wns
src/core/base/wnComponent.js
function (msg,verbosity) { if (!_debug || verbosity>_verbosity) return false; this.e.log.apply(this,[msg||'','debug',verbosity||0]); return self; }
javascript
function (msg,verbosity) { if (!_debug || verbosity>_verbosity) return false; this.e.log.apply(this,[msg||'','debug',verbosity||0]); return self; }
[ "function", "(", "msg", ",", "verbosity", ")", "{", "if", "(", "!", "_debug", "||", "verbosity", ">", "_verbosity", ")", "return", "false", ";", "this", ".", "e", ".", "log", ".", "apply", "(", "this", ",", "[", "msg", "||", "''", ",", "'debug'", ",", "verbosity", "||", "0", "]", ")", ";", "return", "self", ";", "}" ]
Component's debug log function @return self
[ "Component", "s", "debug", "log", "function" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L590-L596
53,632
yeptlabs/wns
src/core/base/wnComponent.js
function () { arguments[arguments.length+'']='info'; arguments.length++; this.e.log.apply(this,arguments); return self; }
javascript
function () { arguments[arguments.length+'']='info'; arguments.length++; this.e.log.apply(this,arguments); return self; }
[ "function", "(", ")", "{", "arguments", "[", "arguments", ".", "length", "+", "''", "]", "=", "'info'", ";", "arguments", ".", "length", "++", ";", "this", ".", "e", ".", "log", ".", "apply", "(", "this", ",", "arguments", ")", ";", "return", "self", ";", "}" ]
Component's info log function @return self
[ "Component", "s", "info", "log", "function" ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L602-L608
53,633
yeptlabs/wns
src/core/base/wnComponent.js
function (cmd,context,silent) { var ctx = (context!=undefined?context:this); try { return (function () { var result = eval(cmd); if (!silent) self.e.log&&self.e.log(util.inspect(result),'result'); return result; }.bind(ctx))(); } catch (e) { this.e.exception&&this.e.exception(e); } return; }
javascript
function (cmd,context,silent) { var ctx = (context!=undefined?context:this); try { return (function () { var result = eval(cmd); if (!silent) self.e.log&&self.e.log(util.inspect(result),'result'); return result; }.bind(ctx))(); } catch (e) { this.e.exception&&this.e.exception(e); } return; }
[ "function", "(", "cmd", ",", "context", ",", "silent", ")", "{", "var", "ctx", "=", "(", "context", "!=", "undefined", "?", "context", ":", "this", ")", ";", "try", "{", "return", "(", "function", "(", ")", "{", "var", "result", "=", "eval", "(", "cmd", ")", ";", "if", "(", "!", "silent", ")", "self", ".", "e", ".", "log", "&&", "self", ".", "e", ".", "log", "(", "util", ".", "inspect", "(", "result", ")", ",", "'result'", ")", ";", "return", "result", ";", "}", ".", "bind", "(", "ctx", ")", ")", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "this", ".", "e", ".", "exception", "&&", "this", ".", "e", ".", "exception", "(", "e", ")", ";", "}", "return", ";", "}" ]
Execute an expression in this component's context. @param string $cmd expression @param object $context forced context @param boolean $silent do not print result? @return this
[ "Execute", "an", "expression", "in", "this", "component", "s", "context", "." ]
c42602b062dcf6bbffc22e4365bba2cbf363fe2f
https://github.com/yeptlabs/wns/blob/c42602b062dcf6bbffc22e4365bba2cbf363fe2f/src/core/base/wnComponent.js#L673-L689
53,634
rkaw92/esdf
utils/loadAggregate.js
rehydrateAggregate
function rehydrateAggregate(ARObject){ return when.try(eventSink.rehydrate.bind(eventSink), ARObject, ARID, ARObject.getNextSequenceNumber()); }
javascript
function rehydrateAggregate(ARObject){ return when.try(eventSink.rehydrate.bind(eventSink), ARObject, ARID, ARObject.getNextSequenceNumber()); }
[ "function", "rehydrateAggregate", "(", "ARObject", ")", "{", "return", "when", ".", "try", "(", "eventSink", ".", "rehydrate", ".", "bind", "(", "eventSink", ")", ",", "ARObject", ",", "ARID", ",", "ARObject", ".", "getNextSequenceNumber", "(", ")", ")", ";", "}" ]
Rehydration. It will resolve the top-level promise for us, so that there is no need to call anything else to finish the loading.
[ "Rehydration", ".", "It", "will", "resolve", "the", "top", "-", "level", "promise", "for", "us", "so", "that", "there", "is", "no", "need", "to", "call", "anything", "else", "to", "finish", "the", "loading", "." ]
9c6bd2c278428096cb8c1ceeca62a5493d19613e
https://github.com/rkaw92/esdf/blob/9c6bd2c278428096cb8c1ceeca62a5493d19613e/utils/loadAggregate.js#L76-L78
53,635
karfcz/kff
src/CollectionBinder.js
function() { this.anchor = this.view.env.document.createTextNode(''); var el = this.view.element; if(el.parentNode) { el.parentNode.insertBefore(this.anchor, el.nextSibling); el.parentNode.removeChild(el); } this.boundViews = []; // Boundview options: this.boundViewName = this.view.element.getAttribute(settings.DATA_VIEW_ATTR); var opt = this.view.element.getAttribute(settings.DATA_OPTIONS_ATTR); this.boundViewOptions = opt ? JSON.parse(opt) : {}; this.boundViewOptions.parentView = this.view; this.boundViewOptions.env = this.view.env; this.boundViewOptions.isBoundView = true; this.refreshBoundViews(); }
javascript
function() { this.anchor = this.view.env.document.createTextNode(''); var el = this.view.element; if(el.parentNode) { el.parentNode.insertBefore(this.anchor, el.nextSibling); el.parentNode.removeChild(el); } this.boundViews = []; // Boundview options: this.boundViewName = this.view.element.getAttribute(settings.DATA_VIEW_ATTR); var opt = this.view.element.getAttribute(settings.DATA_OPTIONS_ATTR); this.boundViewOptions = opt ? JSON.parse(opt) : {}; this.boundViewOptions.parentView = this.view; this.boundViewOptions.env = this.view.env; this.boundViewOptions.isBoundView = true; this.refreshBoundViews(); }
[ "function", "(", ")", "{", "this", ".", "anchor", "=", "this", ".", "view", ".", "env", ".", "document", ".", "createTextNode", "(", "''", ")", ";", "var", "el", "=", "this", ".", "view", ".", "element", ";", "if", "(", "el", ".", "parentNode", ")", "{", "el", ".", "parentNode", ".", "insertBefore", "(", "this", ".", "anchor", ",", "el", ".", "nextSibling", ")", ";", "el", ".", "parentNode", ".", "removeChild", "(", "el", ")", ";", "}", "this", ".", "boundViews", "=", "[", "]", ";", "// Boundview options:", "this", ".", "boundViewName", "=", "this", ".", "view", ".", "element", ".", "getAttribute", "(", "settings", ".", "DATA_VIEW_ATTR", ")", ";", "var", "opt", "=", "this", ".", "view", ".", "element", ".", "getAttribute", "(", "settings", ".", "DATA_OPTIONS_ATTR", ")", ";", "this", ".", "boundViewOptions", "=", "opt", "?", "JSON", ".", "parse", "(", "opt", ")", ":", "{", "}", ";", "this", ".", "boundViewOptions", ".", "parentView", "=", "this", ".", "view", ";", "this", ".", "boundViewOptions", ".", "env", "=", "this", ".", "view", ".", "env", ";", "this", ".", "boundViewOptions", ".", "isBoundView", "=", "true", ";", "this", ".", "refreshBoundViews", "(", ")", ";", "}" ]
Renders "bound" views. This method generates DOM elements corresponding to each item in the bound collection and creates the bindingView for each element. If the collection changes, it reflects those changes automatically in real time. @private
[ "Renders", "bound", "views", ".", "This", "method", "generates", "DOM", "elements", "corresponding", "to", "each", "item", "in", "the", "bound", "collection", "and", "creates", "the", "bindingView", "for", "each", "element", ".", "If", "the", "collection", "changes", "it", "reflects", "those", "changes", "automatically", "in", "real", "time", "." ]
533b69e8bc9e9b7f60b403d776678bf1c06ac502
https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/CollectionBinder.js#L37-L60
53,636
karfcz/kff
src/CollectionBinder.js
function() { var boundView, i, l; // Destroy boundviews if(this.boundViews !== null) { for(i = 0, l = this.boundViews.length; i < l; i++) { boundView = this.boundViews[i]; boundView.destroyAll(); if(boundView.element && boundView.element.parentNode) boundView.element.parentNode.removeChild(boundView.element); } this.boundViews = null; } if(this.anchor) { if(this.anchor.parentNode) { this.anchor.parentNode.insertBefore(this.view.element, this.anchor.nextSibling); this.anchor.parentNode.removeChild(this.anchor); } this.anchor = null; } if(this.elementTemplate) { if(this.elementTemplate.parentNode) { this.elementTemplate.parentNode.removeChild(this.elementTemplate); } this.elementTemplate = null; } this.viewTemplate = null; if(this.collection) this.collection = null; }
javascript
function() { var boundView, i, l; // Destroy boundviews if(this.boundViews !== null) { for(i = 0, l = this.boundViews.length; i < l; i++) { boundView = this.boundViews[i]; boundView.destroyAll(); if(boundView.element && boundView.element.parentNode) boundView.element.parentNode.removeChild(boundView.element); } this.boundViews = null; } if(this.anchor) { if(this.anchor.parentNode) { this.anchor.parentNode.insertBefore(this.view.element, this.anchor.nextSibling); this.anchor.parentNode.removeChild(this.anchor); } this.anchor = null; } if(this.elementTemplate) { if(this.elementTemplate.parentNode) { this.elementTemplate.parentNode.removeChild(this.elementTemplate); } this.elementTemplate = null; } this.viewTemplate = null; if(this.collection) this.collection = null; }
[ "function", "(", ")", "{", "var", "boundView", ",", "i", ",", "l", ";", "// Destroy boundviews", "if", "(", "this", ".", "boundViews", "!==", "null", ")", "{", "for", "(", "i", "=", "0", ",", "l", "=", "this", ".", "boundViews", ".", "length", ";", "i", "<", "l", ";", "i", "++", ")", "{", "boundView", "=", "this", ".", "boundViews", "[", "i", "]", ";", "boundView", ".", "destroyAll", "(", ")", ";", "if", "(", "boundView", ".", "element", "&&", "boundView", ".", "element", ".", "parentNode", ")", "boundView", ".", "element", ".", "parentNode", ".", "removeChild", "(", "boundView", ".", "element", ")", ";", "}", "this", ".", "boundViews", "=", "null", ";", "}", "if", "(", "this", ".", "anchor", ")", "{", "if", "(", "this", ".", "anchor", ".", "parentNode", ")", "{", "this", ".", "anchor", ".", "parentNode", ".", "insertBefore", "(", "this", ".", "view", ".", "element", ",", "this", ".", "anchor", ".", "nextSibling", ")", ";", "this", ".", "anchor", ".", "parentNode", ".", "removeChild", "(", "this", ".", "anchor", ")", ";", "}", "this", ".", "anchor", "=", "null", ";", "}", "if", "(", "this", ".", "elementTemplate", ")", "{", "if", "(", "this", ".", "elementTemplate", ".", "parentNode", ")", "{", "this", ".", "elementTemplate", ".", "parentNode", ".", "removeChild", "(", "this", ".", "elementTemplate", ")", ";", "}", "this", ".", "elementTemplate", "=", "null", ";", "}", "this", ".", "viewTemplate", "=", "null", ";", "if", "(", "this", ".", "collection", ")", "this", ".", "collection", "=", "null", ";", "}" ]
Destroys previously bound views. @private
[ "Destroys", "previously", "bound", "views", "." ]
533b69e8bc9e9b7f60b403d776678bf1c06ac502
https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/CollectionBinder.js#L67-L102
53,637
karfcz/kff
src/CollectionBinder.js
function(from, to) { if(!from) from = 0; if(!to || to > this.boundViews.length) to = this.boundViews.length; // Reindex subsequent boundviews: for(var i = from; i < to; i++) { this.boundViews[i].setBindingIndex(i); this.boundViews[i].refreshBinders(true); } }
javascript
function(from, to) { if(!from) from = 0; if(!to || to > this.boundViews.length) to = this.boundViews.length; // Reindex subsequent boundviews: for(var i = from; i < to; i++) { this.boundViews[i].setBindingIndex(i); this.boundViews[i].refreshBinders(true); } }
[ "function", "(", "from", ",", "to", ")", "{", "if", "(", "!", "from", ")", "from", "=", "0", ";", "if", "(", "!", "to", "||", "to", ">", "this", ".", "boundViews", ".", "length", ")", "to", "=", "this", ".", "boundViews", ".", "length", ";", "// Reindex subsequent boundviews:", "for", "(", "var", "i", "=", "from", ";", "i", "<", "to", ";", "i", "++", ")", "{", "this", ".", "boundViews", "[", "i", "]", ".", "setBindingIndex", "(", "i", ")", ";", "this", ".", "boundViews", "[", "i", "]", ".", "refreshBinders", "(", "true", ")", ";", "}", "}" ]
Refreshes view indices when the collection changes @private @param {nubmer} from Render index at which reindexing starts @param {number} to Render index at which reindexing ends
[ "Refreshes", "view", "indices", "when", "the", "collection", "changes" ]
533b69e8bc9e9b7f60b403d776678bf1c06ac502
https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/CollectionBinder.js#L330-L341
53,638
karfcz/kff
src/CollectionBinder.js
function(item) { var boundView, element, i; if(!this.viewTemplate) { element = this.view.element.cloneNode(true); this.boundViewOptions.element = element; boundView = new this.view.constructor(this.boundViewOptions); boundView._collectionBinder = null; boundView._modelBindersMap = this.view._modelBindersMap.clone(); this.boundViews.push(boundView); i = this.boundViews.length - 1; boundView.scope['*'] = this.cursor.refine([i]); if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*']; boundView.setBindingIndex(i); boundView.renderAll(); this.viewTemplate = boundView._clone(); this.elementTemplate = element.cloneNode(true); } else { element = this.elementTemplate.cloneNode(true); boundView = this.viewTemplate._clone(); boundView._setParentView(this.view); this.boundViews.push(boundView); i = this.boundViews.length - 1; boundView.scope['*'] = this.cursor.refine([i]); if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*']; boundView.setBindingIndex(i); boundView._rebindElement(element); } element.setAttribute(settings.DATA_RENDERED_ATTR, true); boundView._itemAlias = this.view._itemAlias; boundView._modelBindersMap.setView(boundView); return boundView; }
javascript
function(item) { var boundView, element, i; if(!this.viewTemplate) { element = this.view.element.cloneNode(true); this.boundViewOptions.element = element; boundView = new this.view.constructor(this.boundViewOptions); boundView._collectionBinder = null; boundView._modelBindersMap = this.view._modelBindersMap.clone(); this.boundViews.push(boundView); i = this.boundViews.length - 1; boundView.scope['*'] = this.cursor.refine([i]); if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*']; boundView.setBindingIndex(i); boundView.renderAll(); this.viewTemplate = boundView._clone(); this.elementTemplate = element.cloneNode(true); } else { element = this.elementTemplate.cloneNode(true); boundView = this.viewTemplate._clone(); boundView._setParentView(this.view); this.boundViews.push(boundView); i = this.boundViews.length - 1; boundView.scope['*'] = this.cursor.refine([i]); if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*']; boundView.setBindingIndex(i); boundView._rebindElement(element); } element.setAttribute(settings.DATA_RENDERED_ATTR, true); boundView._itemAlias = this.view._itemAlias; boundView._modelBindersMap.setView(boundView); return boundView; }
[ "function", "(", "item", ")", "{", "var", "boundView", ",", "element", ",", "i", ";", "if", "(", "!", "this", ".", "viewTemplate", ")", "{", "element", "=", "this", ".", "view", ".", "element", ".", "cloneNode", "(", "true", ")", ";", "this", ".", "boundViewOptions", ".", "element", "=", "element", ";", "boundView", "=", "new", "this", ".", "view", ".", "constructor", "(", "this", ".", "boundViewOptions", ")", ";", "boundView", ".", "_collectionBinder", "=", "null", ";", "boundView", ".", "_modelBindersMap", "=", "this", ".", "view", ".", "_modelBindersMap", ".", "clone", "(", ")", ";", "this", ".", "boundViews", ".", "push", "(", "boundView", ")", ";", "i", "=", "this", ".", "boundViews", ".", "length", "-", "1", ";", "boundView", ".", "scope", "[", "'*'", "]", "=", "this", ".", "cursor", ".", "refine", "(", "[", "i", "]", ")", ";", "if", "(", "this", ".", "view", ".", "_itemAlias", ")", "boundView", ".", "scope", "[", "this", ".", "view", ".", "_itemAlias", "]", "=", "boundView", ".", "scope", "[", "'*'", "]", ";", "boundView", ".", "setBindingIndex", "(", "i", ")", ";", "boundView", ".", "renderAll", "(", ")", ";", "this", ".", "viewTemplate", "=", "boundView", ".", "_clone", "(", ")", ";", "this", ".", "elementTemplate", "=", "element", ".", "cloneNode", "(", "true", ")", ";", "}", "else", "{", "element", "=", "this", ".", "elementTemplate", ".", "cloneNode", "(", "true", ")", ";", "boundView", "=", "this", ".", "viewTemplate", ".", "_clone", "(", ")", ";", "boundView", ".", "_setParentView", "(", "this", ".", "view", ")", ";", "this", ".", "boundViews", ".", "push", "(", "boundView", ")", ";", "i", "=", "this", ".", "boundViews", ".", "length", "-", "1", ";", "boundView", ".", "scope", "[", "'*'", "]", "=", "this", ".", "cursor", ".", "refine", "(", "[", "i", "]", ")", ";", "if", "(", "this", ".", "view", ".", "_itemAlias", ")", "boundView", ".", "scope", "[", "this", ".", "view", ".", "_itemAlias", "]", "=", "boundView", ".", "scope", "[", "'*'", "]", ";", "boundView", ".", "setBindingIndex", "(", "i", ")", ";", "boundView", ".", "_rebindElement", "(", "element", ")", ";", "}", "element", ".", "setAttribute", "(", "settings", ".", "DATA_RENDERED_ATTR", ",", "true", ")", ";", "boundView", ".", "_itemAlias", "=", "this", ".", "view", ".", "_itemAlias", ";", "boundView", ".", "_modelBindersMap", ".", "setView", "(", "boundView", ")", ";", "return", "boundView", ";", "}" ]
Creates a new bound view for item in collection @private @param {Object} item Item for data-binding @param {number} i Binding index @return {View} created view
[ "Creates", "a", "new", "bound", "view", "for", "item", "in", "collection" ]
533b69e8bc9e9b7f60b403d776678bf1c06ac502
https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/CollectionBinder.js#L351-L401
53,639
zerkalica/hyper-config
lib/hyper-config.js
normalize
function normalize(acc, val) { if (typeof val === 'string') { var value = val.trim().replace(acc.refIgnoreRegExp, REF_MAGIC); if (value.indexOf(acc.refLabel) === 0 && value.indexOf(acc.refLabel + acc.macroBegin) === -1) { value = value.substring(acc.refLabel.length); this.update(acc.get(value)); } else if (value.indexOf(acc.refLabel + 'disable') === 0) { this.remove(); } else { value = value.replace(acc.refRegExp, function replaceMacro(val, path) { return acc.get(path); }); this.update(value.replace(REF_MAGIC_REGEXP, acc.refLabel)); } } var key = this.key; if (key && key.indexOf(acc.annotationLabel) === 0) { normalizer = acc.normalizers[key.substring(acc.annotationLabel.length)]; if (normalizer) { normalizer(acc, val, this); } } return acc; }
javascript
function normalize(acc, val) { if (typeof val === 'string') { var value = val.trim().replace(acc.refIgnoreRegExp, REF_MAGIC); if (value.indexOf(acc.refLabel) === 0 && value.indexOf(acc.refLabel + acc.macroBegin) === -1) { value = value.substring(acc.refLabel.length); this.update(acc.get(value)); } else if (value.indexOf(acc.refLabel + 'disable') === 0) { this.remove(); } else { value = value.replace(acc.refRegExp, function replaceMacro(val, path) { return acc.get(path); }); this.update(value.replace(REF_MAGIC_REGEXP, acc.refLabel)); } } var key = this.key; if (key && key.indexOf(acc.annotationLabel) === 0) { normalizer = acc.normalizers[key.substring(acc.annotationLabel.length)]; if (normalizer) { normalizer(acc, val, this); } } return acc; }
[ "function", "normalize", "(", "acc", ",", "val", ")", "{", "if", "(", "typeof", "val", "===", "'string'", ")", "{", "var", "value", "=", "val", ".", "trim", "(", ")", ".", "replace", "(", "acc", ".", "refIgnoreRegExp", ",", "REF_MAGIC", ")", ";", "if", "(", "value", ".", "indexOf", "(", "acc", ".", "refLabel", ")", "===", "0", "&&", "value", ".", "indexOf", "(", "acc", ".", "refLabel", "+", "acc", ".", "macroBegin", ")", "===", "-", "1", ")", "{", "value", "=", "value", ".", "substring", "(", "acc", ".", "refLabel", ".", "length", ")", ";", "this", ".", "update", "(", "acc", ".", "get", "(", "value", ")", ")", ";", "}", "else", "if", "(", "value", ".", "indexOf", "(", "acc", ".", "refLabel", "+", "'disable'", ")", "===", "0", ")", "{", "this", ".", "remove", "(", ")", ";", "}", "else", "{", "value", "=", "value", ".", "replace", "(", "acc", ".", "refRegExp", ",", "function", "replaceMacro", "(", "val", ",", "path", ")", "{", "return", "acc", ".", "get", "(", "path", ")", ";", "}", ")", ";", "this", ".", "update", "(", "value", ".", "replace", "(", "REF_MAGIC_REGEXP", ",", "acc", ".", "refLabel", ")", ")", ";", "}", "}", "var", "key", "=", "this", ".", "key", ";", "if", "(", "key", "&&", "key", ".", "indexOf", "(", "acc", ".", "annotationLabel", ")", "===", "0", ")", "{", "normalizer", "=", "acc", ".", "normalizers", "[", "key", ".", "substring", "(", "acc", ".", "annotationLabel", ".", "length", ")", "]", ";", "if", "(", "normalizer", ")", "{", "normalizer", "(", "acc", ",", "val", ",", "this", ")", ";", "}", "}", "return", "acc", ";", "}" ]
Normalize config value @param {object} acc reduce acc @param {any} val config value @return {object} reduce acc
[ "Normalize", "config", "value" ]
ae21220ece60b644b720c3469c63ab144576f1f6
https://github.com/zerkalica/hyper-config/blob/ae21220ece60b644b720c3469c63ab144576f1f6/lib/hyper-config.js#L47-L71
53,640
zerkalica/hyper-config
lib/hyper-config.js
HyperConfig
function HyperConfig(options) { this.name = 'HyperConfig'; if (!(this instanceof HyperConfig)) { return new HyperConfig(options); } options = options || {}; this._refLabel = options.refLabel || '~'; this._annotationLabel = options.annotationLabel || '@'; this._macroBegin = options.macroBegin || '{'; this._macroEnd = options.macroEnd || '}'; this._config = traverse({}); this._isBuilded = false; this._normalizers = {}; this.addNormalizer('tags', extractTags); }
javascript
function HyperConfig(options) { this.name = 'HyperConfig'; if (!(this instanceof HyperConfig)) { return new HyperConfig(options); } options = options || {}; this._refLabel = options.refLabel || '~'; this._annotationLabel = options.annotationLabel || '@'; this._macroBegin = options.macroBegin || '{'; this._macroEnd = options.macroEnd || '}'; this._config = traverse({}); this._isBuilded = false; this._normalizers = {}; this.addNormalizer('tags', extractTags); }
[ "function", "HyperConfig", "(", "options", ")", "{", "this", ".", "name", "=", "'HyperConfig'", ";", "if", "(", "!", "(", "this", "instanceof", "HyperConfig", ")", ")", "{", "return", "new", "HyperConfig", "(", "options", ")", ";", "}", "options", "=", "options", "||", "{", "}", ";", "this", ".", "_refLabel", "=", "options", ".", "refLabel", "||", "'~'", ";", "this", ".", "_annotationLabel", "=", "options", ".", "annotationLabel", "||", "'@'", ";", "this", ".", "_macroBegin", "=", "options", ".", "macroBegin", "||", "'{'", ";", "this", ".", "_macroEnd", "=", "options", ".", "macroEnd", "||", "'}'", ";", "this", ".", "_config", "=", "traverse", "(", "{", "}", ")", ";", "this", ".", "_isBuilded", "=", "false", ";", "this", ".", "_normalizers", "=", "{", "}", ";", "this", ".", "addNormalizer", "(", "'tags'", ",", "extractTags", ")", ";", "}" ]
Hyper config builder @param {object} options Options @param {string} options.refLabel '~' @param {string} options.annotationLabel & @param {string} options.macroBegin { @param {string} options.macroEnd }
[ "Hyper", "config", "builder" ]
ae21220ece60b644b720c3469c63ab144576f1f6
https://github.com/zerkalica/hyper-config/blob/ae21220ece60b644b720c3469c63ab144576f1f6/lib/hyper-config.js#L106-L121
53,641
boylesoftware/x2node-validators
lib/standard.js
isEmpty
function isEmpty(ptr, propDesc, value) { if ((value === undefined) || (value === null)) return true; if (propDesc.isArray() && !ptr.collectionElement && Array.isArray(value)) { if (value.length === 0) return true; } else if (propDesc.isMap() && !ptr.collectionElement && ((typeof value) === 'object')) { if (Object.keys(value).length === 0) return true; } else if ((propDesc.isScalar() || ptr.collectionElement) && (propDesc.scalarValueType === 'string') && ((typeof value) === 'string')) { if (value.length === 0) return true; } return false; }
javascript
function isEmpty(ptr, propDesc, value) { if ((value === undefined) || (value === null)) return true; if (propDesc.isArray() && !ptr.collectionElement && Array.isArray(value)) { if (value.length === 0) return true; } else if (propDesc.isMap() && !ptr.collectionElement && ((typeof value) === 'object')) { if (Object.keys(value).length === 0) return true; } else if ((propDesc.isScalar() || ptr.collectionElement) && (propDesc.scalarValueType === 'string') && ((typeof value) === 'string')) { if (value.length === 0) return true; } return false; }
[ "function", "isEmpty", "(", "ptr", ",", "propDesc", ",", "value", ")", "{", "if", "(", "(", "value", "===", "undefined", ")", "||", "(", "value", "===", "null", ")", ")", "return", "true", ";", "if", "(", "propDesc", ".", "isArray", "(", ")", "&&", "!", "ptr", ".", "collectionElement", "&&", "Array", ".", "isArray", "(", "value", ")", ")", "{", "if", "(", "value", ".", "length", "===", "0", ")", "return", "true", ";", "}", "else", "if", "(", "propDesc", ".", "isMap", "(", ")", "&&", "!", "ptr", ".", "collectionElement", "&&", "(", "(", "typeof", "value", ")", "===", "'object'", ")", ")", "{", "if", "(", "Object", ".", "keys", "(", "value", ")", ".", "length", "===", "0", ")", "return", "true", ";", "}", "else", "if", "(", "(", "propDesc", ".", "isScalar", "(", ")", "||", "ptr", ".", "collectionElement", ")", "&&", "(", "propDesc", ".", "scalarValueType", "===", "'string'", ")", "&&", "(", "(", "typeof", "value", ")", "===", "'string'", ")", ")", "{", "if", "(", "value", ".", "length", "===", "0", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Tell if the specified property value can be considered empty. @private @param {module:x2node-pointers~RecordElementPointer} ptr Property pointer. @param {module:x2node-records~PropertyDescriptor} propDesc Property descriptor. @param {*} value Property value to test. @returns {boolean} <code>true</code> if empty.
[ "Tell", "if", "the", "specified", "property", "value", "can", "be", "considered", "empty", "." ]
e98a65c13a4092f80e96517c8e8c9523f8e84c63
https://github.com/boylesoftware/x2node-validators/blob/e98a65c13a4092f80e96517c8e8c9523f8e84c63/lib/standard.js#L156-L176
53,642
boylesoftware/x2node-validators
lib/standard.js
hasMatchingSibling
function hasMatchingSibling(ctx, propName, testValue, whenErrors) { const containerDesc = ctx.currentPropDesc.container; const propDesc = containerDesc.getPropertyDesc(propName); let propPtr; if (containerDesc.parentContainer && containerDesc.parentContainer.isPolymorphObject()) { const pathParts = containerDesc.nestedPath.split('.'); propPtr = ctx.currentPointer.parent.createChildPointer( `${pathParts[pathParts.length - 2]}:${propName}`); } else { propPtr = ctx.currentPointer.parent.createChildPointer(propName); } if (ctx.hasErrorsFor(propPtr)) return whenErrors; const container = ctx.containersChain[ctx.containersChain.length - 1]; const propValue = container[propName]; if (testValue !== undefined) { if (((testValue instanceof RegExp) && testValue.test(propValue)) || (propValue === testValue)) return true; } else { if (!isEmpty(propPtr, propDesc, propValue)) return true; } return false; }
javascript
function hasMatchingSibling(ctx, propName, testValue, whenErrors) { const containerDesc = ctx.currentPropDesc.container; const propDesc = containerDesc.getPropertyDesc(propName); let propPtr; if (containerDesc.parentContainer && containerDesc.parentContainer.isPolymorphObject()) { const pathParts = containerDesc.nestedPath.split('.'); propPtr = ctx.currentPointer.parent.createChildPointer( `${pathParts[pathParts.length - 2]}:${propName}`); } else { propPtr = ctx.currentPointer.parent.createChildPointer(propName); } if (ctx.hasErrorsFor(propPtr)) return whenErrors; const container = ctx.containersChain[ctx.containersChain.length - 1]; const propValue = container[propName]; if (testValue !== undefined) { if (((testValue instanceof RegExp) && testValue.test(propValue)) || (propValue === testValue)) return true; } else { if (!isEmpty(propPtr, propDesc, propValue)) return true; } return false; }
[ "function", "hasMatchingSibling", "(", "ctx", ",", "propName", ",", "testValue", ",", "whenErrors", ")", "{", "const", "containerDesc", "=", "ctx", ".", "currentPropDesc", ".", "container", ";", "const", "propDesc", "=", "containerDesc", ".", "getPropertyDesc", "(", "propName", ")", ";", "let", "propPtr", ";", "if", "(", "containerDesc", ".", "parentContainer", "&&", "containerDesc", ".", "parentContainer", ".", "isPolymorphObject", "(", ")", ")", "{", "const", "pathParts", "=", "containerDesc", ".", "nestedPath", ".", "split", "(", "'.'", ")", ";", "propPtr", "=", "ctx", ".", "currentPointer", ".", "parent", ".", "createChildPointer", "(", "`", "${", "pathParts", "[", "pathParts", ".", "length", "-", "2", "]", "}", "${", "propName", "}", "`", ")", ";", "}", "else", "{", "propPtr", "=", "ctx", ".", "currentPointer", ".", "parent", ".", "createChildPointer", "(", "propName", ")", ";", "}", "if", "(", "ctx", ".", "hasErrorsFor", "(", "propPtr", ")", ")", "return", "whenErrors", ";", "const", "container", "=", "ctx", ".", "containersChain", "[", "ctx", ".", "containersChain", ".", "length", "-", "1", "]", ";", "const", "propValue", "=", "container", "[", "propName", "]", ";", "if", "(", "testValue", "!==", "undefined", ")", "{", "if", "(", "(", "(", "testValue", "instanceof", "RegExp", ")", "&&", "testValue", ".", "test", "(", "propValue", ")", ")", "||", "(", "propValue", "===", "testValue", ")", ")", "return", "true", ";", "}", "else", "{", "if", "(", "!", "isEmpty", "(", "propPtr", ",", "propDesc", ",", "propValue", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Tell if the specified context container has specified property and it optionally matches the specified test value. @private @param {module:x2node-validators~ValidationContext} ctx Current validation context. @param {string} propName Sibling property name. @param {(*|RegExp)} [testValue] Test value. @param {boolean} whenErrors What to return when <code>propName</code> has validation errors. @returns {boolean} <code>true</code> if has matching sibling.
[ "Tell", "if", "the", "specified", "context", "container", "has", "specified", "property", "and", "it", "optionally", "matches", "the", "specified", "test", "value", "." ]
e98a65c13a4092f80e96517c8e8c9523f8e84c63
https://github.com/boylesoftware/x2node-validators/blob/e98a65c13a4092f80e96517c8e8c9523f8e84c63/lib/standard.js#L191-L221
53,643
boylesoftware/x2node-validators
lib/standard.js
addDepsError
function addDepsError(ctx, type, propName, testValue) { let depsErrors = ctx[DEPS_ERRORS]; if (!depsErrors) depsErrors = ctx[DEPS_ERRORS] = {}; const curPtrStr = ctx.currentPointer.toString(); if (depsErrors[curPtrStr]) return; depsErrors[curPtrStr] = true; const hasTestValue = (testValue !== undefined); const testValueIsPattern = (testValue instanceof RegExp); ctx.addError( ( hasTestValue ? ( testValueIsPattern ? `{${type}Pattern}` : `{${type}Value}` ) : `{${type}}` ), { prop: propName, [testValueIsPattern ? 'pattern' : 'value']: testValue } ); }
javascript
function addDepsError(ctx, type, propName, testValue) { let depsErrors = ctx[DEPS_ERRORS]; if (!depsErrors) depsErrors = ctx[DEPS_ERRORS] = {}; const curPtrStr = ctx.currentPointer.toString(); if (depsErrors[curPtrStr]) return; depsErrors[curPtrStr] = true; const hasTestValue = (testValue !== undefined); const testValueIsPattern = (testValue instanceof RegExp); ctx.addError( ( hasTestValue ? ( testValueIsPattern ? `{${type}Pattern}` : `{${type}Value}` ) : `{${type}}` ), { prop: propName, [testValueIsPattern ? 'pattern' : 'value']: testValue } ); }
[ "function", "addDepsError", "(", "ctx", ",", "type", ",", "propName", ",", "testValue", ")", "{", "let", "depsErrors", "=", "ctx", "[", "DEPS_ERRORS", "]", ";", "if", "(", "!", "depsErrors", ")", "depsErrors", "=", "ctx", "[", "DEPS_ERRORS", "]", "=", "{", "}", ";", "const", "curPtrStr", "=", "ctx", ".", "currentPointer", ".", "toString", "(", ")", ";", "if", "(", "depsErrors", "[", "curPtrStr", "]", ")", "return", ";", "depsErrors", "[", "curPtrStr", "]", "=", "true", ";", "const", "hasTestValue", "=", "(", "testValue", "!==", "undefined", ")", ";", "const", "testValueIsPattern", "=", "(", "testValue", "instanceof", "RegExp", ")", ";", "ctx", ".", "addError", "(", "(", "hasTestValue", "?", "(", "testValueIsPattern", "?", "`", "${", "type", "}", "`", ":", "`", "${", "type", "}", "`", ")", ":", "`", "${", "type", "}", "`", ")", ",", "{", "prop", ":", "propName", ",", "[", "testValueIsPattern", "?", "'pattern'", ":", "'value'", "]", ":", "testValue", "}", ")", ";", "}" ]
Add dependecy validator error to the context if no dependency validator errors already added for the current property. @private @param {module:x2node-validators~ValidationContext} ctx Current validation context. @param {string} type Validator type. @param {string} propName Dependency property name. @param {(*|RegExp)} testValue Dependecy property test value.
[ "Add", "dependecy", "validator", "error", "to", "the", "context", "if", "no", "dependency", "validator", "errors", "already", "added", "for", "the", "current", "property", "." ]
e98a65c13a4092f80e96517c8e8c9523f8e84c63
https://github.com/boylesoftware/x2node-validators/blob/e98a65c13a4092f80e96517c8e8c9523f8e84c63/lib/standard.js#L242-L267
53,644
glennschler/spotspec
lib/credentials.js
Credentials
function Credentials (options) { EventEmitter.call(this) options.keys.apiVersion = 'latest' options.keys.sslEnabled = true if (options.hasOwnProperty('upgrade')) { // Update with the MFA token passed in with the credentials this.upgrade(options) return } let awsConfig = Object.assign({}, options.keys) // Else not using a MFA token this._awsConfig = new AWS.Config(awsConfig) // Upgrade creditials not necessary. Tell the caller ready. internals.emitAsync.call(this, internals.EVENT_INITIALIZED, null, { state: 'ok' }) }
javascript
function Credentials (options) { EventEmitter.call(this) options.keys.apiVersion = 'latest' options.keys.sslEnabled = true if (options.hasOwnProperty('upgrade')) { // Update with the MFA token passed in with the credentials this.upgrade(options) return } let awsConfig = Object.assign({}, options.keys) // Else not using a MFA token this._awsConfig = new AWS.Config(awsConfig) // Upgrade creditials not necessary. Tell the caller ready. internals.emitAsync.call(this, internals.EVENT_INITIALIZED, null, { state: 'ok' }) }
[ "function", "Credentials", "(", "options", ")", "{", "EventEmitter", ".", "call", "(", "this", ")", "options", ".", "keys", ".", "apiVersion", "=", "'latest'", "options", ".", "keys", ".", "sslEnabled", "=", "true", "if", "(", "options", ".", "hasOwnProperty", "(", "'upgrade'", ")", ")", "{", "// Update with the MFA token passed in with the credentials", "this", ".", "upgrade", "(", "options", ")", "return", "}", "let", "awsConfig", "=", "Object", ".", "assign", "(", "{", "}", ",", "options", ".", "keys", ")", "// Else not using a MFA token", "this", ".", "_awsConfig", "=", "new", "AWS", ".", "Config", "(", "awsConfig", ")", "// Upgrade creditials not necessary. Tell the caller ready.", "internals", ".", "emitAsync", ".", "call", "(", "this", ",", "internals", ".", "EVENT_INITIALIZED", ",", "null", ",", "{", "state", ":", "'ok'", "}", ")", "}" ]
Credentials - Create MFA short term credentials @constructor @arg {object} options - The AWS service IAM credentials @arg {object} options.keys - Credentials for the service API authentication. See [aws docs]{@link http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html} @arg {string} options.keys.accessKeyId - AWS access key ID @arg {string} options.keys.secretAccessKey - AWS secret access key @arg {string} options.keys.region - The EC2 region to send service requests @arg {object} options.upgrade - Temporary Session Token credentials. See [aws docs]{@link http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/STS.html#getSessionToken-property} @arg {string} options.upgrade.serialNumber - Identifies the user's hardware or virtual MFA device @arg {number} options.upgrade.tokenCode - Time-based one-time password (TOTP) that the MFA devices produces @arg {number} [options.upgrade.durationSeconds=900] - The duration, in seconds, that the credentials should remain valid @arg {boolean} [options.isLogging=false] - Use internal logging @throws {error} @emits {initialized}
[ "Credentials", "-", "Create", "MFA", "short", "term", "credentials" ]
ca6f5b17b84b3536b6b2ce9a472d5ae91c8cd727
https://github.com/glennschler/spotspec/blob/ca6f5b17b84b3536b6b2ce9a472d5ae91c8cd727/lib/credentials.js#L53-L72
53,645
dpjanes/iotdb-upnp
upnp/upnp-device.js
function (controlPoint, uuid, location, desc, localAddress) { EventEmitter.call(this); if (TRACE) { logger.info({ method: "UpnpDevice", uuid: uuid, }, "new device object"); } this.controlPoint = controlPoint; this.uuid = uuid; this.udn = desc.UDN[0]; this.forgotten = false this.last_seen = (new Date()).getTime(); this.location = location; this.deviceType = desc.deviceType ? desc.deviceType[0] : null; this.friendlyName = desc.friendlyName ? desc.friendlyName[0] : null; this.manufacturer = desc.manufacturer ? desc.manufacturer[0] : null; this.manufacturerUrl = desc.manufacturerURL ? desc.manufacturerURL[0] : null; this.modelNumber = desc.modelNumber ? desc.modelNumber[0] : null; this.modelDescription = desc.modelDescription ? desc.modelDescription[0] : null; this.modelName = desc.modelName ? desc.modelName[0] : null; this.modelUrl = desc.modelURL ? desc.modelURL[0] : null; this.softwareVersion = desc.softwareVersion ? desc.softwareVersion[0] : null; this.hardwareVersion = desc.hardwareVersion ? desc.hardwareVersion[0] : null; this.serialNum = desc.serialNum ? desc.serialNum[0] : null; var u = url.parse(this.location); this.host = u.hostname; this.port = u.port; this.localAddress = localAddress; this.devices = {}; // sub-devices this.services = {}; this._handleDeviceInfo(desc); if (seend[this.uuid] === undefined) { seend[this.uuid] = true; logger.info({ method: "UpnpDevice", device: { loction: this.location, uuid: this.uuid, deviceType: this.deviceType, friendlyName: this.friendlyName, manufacturer: this.manufacturer, manufacturerUrl: this.manufacturerURL, modelNumber: this.modelNumber, modelDescription: this.modelDescription, modelName: this.modelName, modelUrl: this.modelURL, } }, "previously unseen UPnP device"); } // var self = this; // this._getDeviceDetails(function(desc) { // self._handleDeviceInfo(desc); // }); }
javascript
function (controlPoint, uuid, location, desc, localAddress) { EventEmitter.call(this); if (TRACE) { logger.info({ method: "UpnpDevice", uuid: uuid, }, "new device object"); } this.controlPoint = controlPoint; this.uuid = uuid; this.udn = desc.UDN[0]; this.forgotten = false this.last_seen = (new Date()).getTime(); this.location = location; this.deviceType = desc.deviceType ? desc.deviceType[0] : null; this.friendlyName = desc.friendlyName ? desc.friendlyName[0] : null; this.manufacturer = desc.manufacturer ? desc.manufacturer[0] : null; this.manufacturerUrl = desc.manufacturerURL ? desc.manufacturerURL[0] : null; this.modelNumber = desc.modelNumber ? desc.modelNumber[0] : null; this.modelDescription = desc.modelDescription ? desc.modelDescription[0] : null; this.modelName = desc.modelName ? desc.modelName[0] : null; this.modelUrl = desc.modelURL ? desc.modelURL[0] : null; this.softwareVersion = desc.softwareVersion ? desc.softwareVersion[0] : null; this.hardwareVersion = desc.hardwareVersion ? desc.hardwareVersion[0] : null; this.serialNum = desc.serialNum ? desc.serialNum[0] : null; var u = url.parse(this.location); this.host = u.hostname; this.port = u.port; this.localAddress = localAddress; this.devices = {}; // sub-devices this.services = {}; this._handleDeviceInfo(desc); if (seend[this.uuid] === undefined) { seend[this.uuid] = true; logger.info({ method: "UpnpDevice", device: { loction: this.location, uuid: this.uuid, deviceType: this.deviceType, friendlyName: this.friendlyName, manufacturer: this.manufacturer, manufacturerUrl: this.manufacturerURL, modelNumber: this.modelNumber, modelDescription: this.modelDescription, modelName: this.modelName, modelUrl: this.modelURL, } }, "previously unseen UPnP device"); } // var self = this; // this._getDeviceDetails(function(desc) { // self._handleDeviceInfo(desc); // }); }
[ "function", "(", "controlPoint", ",", "uuid", ",", "location", ",", "desc", ",", "localAddress", ")", "{", "EventEmitter", ".", "call", "(", "this", ")", ";", "if", "(", "TRACE", ")", "{", "logger", ".", "info", "(", "{", "method", ":", "\"UpnpDevice\"", ",", "uuid", ":", "uuid", ",", "}", ",", "\"new device object\"", ")", ";", "}", "this", ".", "controlPoint", "=", "controlPoint", ";", "this", ".", "uuid", "=", "uuid", ";", "this", ".", "udn", "=", "desc", ".", "UDN", "[", "0", "]", ";", "this", ".", "forgotten", "=", "false", "this", ".", "last_seen", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "this", ".", "location", "=", "location", ";", "this", ".", "deviceType", "=", "desc", ".", "deviceType", "?", "desc", ".", "deviceType", "[", "0", "]", ":", "null", ";", "this", ".", "friendlyName", "=", "desc", ".", "friendlyName", "?", "desc", ".", "friendlyName", "[", "0", "]", ":", "null", ";", "this", ".", "manufacturer", "=", "desc", ".", "manufacturer", "?", "desc", ".", "manufacturer", "[", "0", "]", ":", "null", ";", "this", ".", "manufacturerUrl", "=", "desc", ".", "manufacturerURL", "?", "desc", ".", "manufacturerURL", "[", "0", "]", ":", "null", ";", "this", ".", "modelNumber", "=", "desc", ".", "modelNumber", "?", "desc", ".", "modelNumber", "[", "0", "]", ":", "null", ";", "this", ".", "modelDescription", "=", "desc", ".", "modelDescription", "?", "desc", ".", "modelDescription", "[", "0", "]", ":", "null", ";", "this", ".", "modelName", "=", "desc", ".", "modelName", "?", "desc", ".", "modelName", "[", "0", "]", ":", "null", ";", "this", ".", "modelUrl", "=", "desc", ".", "modelURL", "?", "desc", ".", "modelURL", "[", "0", "]", ":", "null", ";", "this", ".", "softwareVersion", "=", "desc", ".", "softwareVersion", "?", "desc", ".", "softwareVersion", "[", "0", "]", ":", "null", ";", "this", ".", "hardwareVersion", "=", "desc", ".", "hardwareVersion", "?", "desc", ".", "hardwareVersion", "[", "0", "]", ":", "null", ";", "this", ".", "serialNum", "=", "desc", ".", "serialNum", "?", "desc", ".", "serialNum", "[", "0", "]", ":", "null", ";", "var", "u", "=", "url", ".", "parse", "(", "this", ".", "location", ")", ";", "this", ".", "host", "=", "u", ".", "hostname", ";", "this", ".", "port", "=", "u", ".", "port", ";", "this", ".", "localAddress", "=", "localAddress", ";", "this", ".", "devices", "=", "{", "}", ";", "// sub-devices", "this", ".", "services", "=", "{", "}", ";", "this", ".", "_handleDeviceInfo", "(", "desc", ")", ";", "if", "(", "seend", "[", "this", ".", "uuid", "]", "===", "undefined", ")", "{", "seend", "[", "this", ".", "uuid", "]", "=", "true", ";", "logger", ".", "info", "(", "{", "method", ":", "\"UpnpDevice\"", ",", "device", ":", "{", "loction", ":", "this", ".", "location", ",", "uuid", ":", "this", ".", "uuid", ",", "deviceType", ":", "this", ".", "deviceType", ",", "friendlyName", ":", "this", ".", "friendlyName", ",", "manufacturer", ":", "this", ".", "manufacturer", ",", "manufacturerUrl", ":", "this", ".", "manufacturerURL", ",", "modelNumber", ":", "this", ".", "modelNumber", ",", "modelDescription", ":", "this", ".", "modelDescription", ",", "modelName", ":", "this", ".", "modelName", ",", "modelUrl", ":", "this", ".", "modelURL", ",", "}", "}", ",", "\"previously unseen UPnP device\"", ")", ";", "}", "// var self = this;", "// this._getDeviceDetails(function(desc) {", "// self._handleDeviceInfo(desc);", "// });", "}" ]
A UPnP WeMo Controllee. Includes socket switch.
[ "A", "UPnP", "WeMo", "Controllee", ".", "Includes", "socket", "switch", "." ]
514d6253eca4c6440105e48aa940a07778187e43
https://github.com/dpjanes/iotdb-upnp/blob/514d6253eca4c6440105e48aa940a07778187e43/upnp/upnp-device.js#L25-L91
53,646
iolo/express-toybox
utils.js
extendHttpRequest
function extendHttpRequest(req) { req = req || express.request; /** * get param value from path-variable or query or body or headers. * @param {string} paramName * @param {*} [fallback] * @returns {*} */ req.anyParam = function (paramName, fallback) { return (this.params && this.params[paramName]) || // path-variable (this.query && this.query[paramName]) || (this.body && this.body[paramName]) || (this.get && this.get(paramName)) || // header fallback; }; /** * get string param from http request. * * @param {String} paramName * @param {String} [fallback] * @returns {String} param value * @throws {errors.BadRequest} no string param acquired and no fallback provided * @memberOf {express.request} */ req.strParam = function (paramName, fallback) { var paramValue = this.anyParam(paramName); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('param_required:' + paramName); }; /** * get integer param from http request. * * @param {String} paramName * @param {Number} [fallback] * @returns {Number} param value * @throws {errors.BadRequest} no integer param acquired and no fallback provided * @memberOf {express.request} */ req.intParam = function (paramName, fallback) { var paramValue = utils.toInt(this.anyParam(paramName), fallback); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('int_param_required:' + paramName); }; /** * get number(float) param from http request. * * @param {String} paramName * @param {Number} [fallback] * @returns {Number} param value * @throws {errors.BadRequest} no number param acquired and no fallback provided * @memberOf {express.request} */ req.numberParam = function (paramName, fallback) { var paramValue = utils.toNumber(this.anyParam(paramName)); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('number_param_required:' + paramName); }; /** * get boolean param from http request. * * @param {String} paramName * @returns {Boolean} [fallback] * @returns {Boolean} param value * @throws {errors.BadRequest} no boolean param acquired and no fallback provided * @memberOf {express.request} */ req.boolParam = function (paramName, fallback) { var paramValue = utils.toBoolean(this.anyParam(paramName)); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('bool_param_required:' + paramName); }; /** * get date param from http request. * * @param {String} paramName * @param {Date} [fallback] * @returns {Date} param value * @throws {errors.BadRequest} no date param acquired and no fallback provided * @memberOf {express.request} */ req.dateParam = function (paramName, fallback) { var paramValue = Date.parse(this.anyParam(paramName)); if (!isNaN(paramValue)) { return new Date(paramValue); } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('date_param_required:' + paramName); }; /** * collect params from http request. * * @param {Array.<String>} paramNames * @returns {Object.<String,String>} */ req.collectParams = function (paramNames) { var self = this; return paramNames.reduce(function (params, paramName) { var paramValue = self.strParam(paramName); if (paramValue) { params[paramName] = paramValue.trim(); } return params; }, {}); }; }
javascript
function extendHttpRequest(req) { req = req || express.request; /** * get param value from path-variable or query or body or headers. * @param {string} paramName * @param {*} [fallback] * @returns {*} */ req.anyParam = function (paramName, fallback) { return (this.params && this.params[paramName]) || // path-variable (this.query && this.query[paramName]) || (this.body && this.body[paramName]) || (this.get && this.get(paramName)) || // header fallback; }; /** * get string param from http request. * * @param {String} paramName * @param {String} [fallback] * @returns {String} param value * @throws {errors.BadRequest} no string param acquired and no fallback provided * @memberOf {express.request} */ req.strParam = function (paramName, fallback) { var paramValue = this.anyParam(paramName); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('param_required:' + paramName); }; /** * get integer param from http request. * * @param {String} paramName * @param {Number} [fallback] * @returns {Number} param value * @throws {errors.BadRequest} no integer param acquired and no fallback provided * @memberOf {express.request} */ req.intParam = function (paramName, fallback) { var paramValue = utils.toInt(this.anyParam(paramName), fallback); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('int_param_required:' + paramName); }; /** * get number(float) param from http request. * * @param {String} paramName * @param {Number} [fallback] * @returns {Number} param value * @throws {errors.BadRequest} no number param acquired and no fallback provided * @memberOf {express.request} */ req.numberParam = function (paramName, fallback) { var paramValue = utils.toNumber(this.anyParam(paramName)); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('number_param_required:' + paramName); }; /** * get boolean param from http request. * * @param {String} paramName * @returns {Boolean} [fallback] * @returns {Boolean} param value * @throws {errors.BadRequest} no boolean param acquired and no fallback provided * @memberOf {express.request} */ req.boolParam = function (paramName, fallback) { var paramValue = utils.toBoolean(this.anyParam(paramName)); if (paramValue !== undefined) { return paramValue; } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('bool_param_required:' + paramName); }; /** * get date param from http request. * * @param {String} paramName * @param {Date} [fallback] * @returns {Date} param value * @throws {errors.BadRequest} no date param acquired and no fallback provided * @memberOf {express.request} */ req.dateParam = function (paramName, fallback) { var paramValue = Date.parse(this.anyParam(paramName)); if (!isNaN(paramValue)) { return new Date(paramValue); } if (fallback !== undefined) { return fallback; } throw new errors.BadRequest('date_param_required:' + paramName); }; /** * collect params from http request. * * @param {Array.<String>} paramNames * @returns {Object.<String,String>} */ req.collectParams = function (paramNames) { var self = this; return paramNames.reduce(function (params, paramName) { var paramValue = self.strParam(paramName); if (paramValue) { params[paramName] = paramValue.trim(); } return params; }, {}); }; }
[ "function", "extendHttpRequest", "(", "req", ")", "{", "req", "=", "req", "||", "express", ".", "request", ";", "/**\n * get param value from path-variable or query or body or headers.\n * @param {string} paramName\n * @param {*} [fallback]\n * @returns {*}\n */", "req", ".", "anyParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "return", "(", "this", ".", "params", "&&", "this", ".", "params", "[", "paramName", "]", ")", "||", "// path-variable", "(", "this", ".", "query", "&&", "this", ".", "query", "[", "paramName", "]", ")", "||", "(", "this", ".", "body", "&&", "this", ".", "body", "[", "paramName", "]", ")", "||", "(", "this", ".", "get", "&&", "this", ".", "get", "(", "paramName", ")", ")", "||", "// header", "fallback", ";", "}", ";", "/**\n * get string param from http request.\n *\n * @param {String} paramName\n * @param {String} [fallback]\n * @returns {String} param value\n * @throws {errors.BadRequest} no string param acquired and no fallback provided\n * @memberOf {express.request}\n */", "req", ".", "strParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "var", "paramValue", "=", "this", ".", "anyParam", "(", "paramName", ")", ";", "if", "(", "paramValue", "!==", "undefined", ")", "{", "return", "paramValue", ";", "}", "if", "(", "fallback", "!==", "undefined", ")", "{", "return", "fallback", ";", "}", "throw", "new", "errors", ".", "BadRequest", "(", "'param_required:'", "+", "paramName", ")", ";", "}", ";", "/**\n * get integer param from http request.\n *\n * @param {String} paramName\n * @param {Number} [fallback]\n * @returns {Number} param value\n * @throws {errors.BadRequest} no integer param acquired and no fallback provided\n * @memberOf {express.request}\n */", "req", ".", "intParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "var", "paramValue", "=", "utils", ".", "toInt", "(", "this", ".", "anyParam", "(", "paramName", ")", ",", "fallback", ")", ";", "if", "(", "paramValue", "!==", "undefined", ")", "{", "return", "paramValue", ";", "}", "if", "(", "fallback", "!==", "undefined", ")", "{", "return", "fallback", ";", "}", "throw", "new", "errors", ".", "BadRequest", "(", "'int_param_required:'", "+", "paramName", ")", ";", "}", ";", "/**\n * get number(float) param from http request.\n *\n * @param {String} paramName\n * @param {Number} [fallback]\n * @returns {Number} param value\n * @throws {errors.BadRequest} no number param acquired and no fallback provided\n * @memberOf {express.request}\n */", "req", ".", "numberParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "var", "paramValue", "=", "utils", ".", "toNumber", "(", "this", ".", "anyParam", "(", "paramName", ")", ")", ";", "if", "(", "paramValue", "!==", "undefined", ")", "{", "return", "paramValue", ";", "}", "if", "(", "fallback", "!==", "undefined", ")", "{", "return", "fallback", ";", "}", "throw", "new", "errors", ".", "BadRequest", "(", "'number_param_required:'", "+", "paramName", ")", ";", "}", ";", "/**\n * get boolean param from http request.\n *\n * @param {String} paramName\n * @returns {Boolean} [fallback]\n * @returns {Boolean} param value\n * @throws {errors.BadRequest} no boolean param acquired and no fallback provided\n * @memberOf {express.request}\n */", "req", ".", "boolParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "var", "paramValue", "=", "utils", ".", "toBoolean", "(", "this", ".", "anyParam", "(", "paramName", ")", ")", ";", "if", "(", "paramValue", "!==", "undefined", ")", "{", "return", "paramValue", ";", "}", "if", "(", "fallback", "!==", "undefined", ")", "{", "return", "fallback", ";", "}", "throw", "new", "errors", ".", "BadRequest", "(", "'bool_param_required:'", "+", "paramName", ")", ";", "}", ";", "/**\n * get date param from http request.\n *\n * @param {String} paramName\n * @param {Date} [fallback]\n * @returns {Date} param value\n * @throws {errors.BadRequest} no date param acquired and no fallback provided\n * @memberOf {express.request}\n */", "req", ".", "dateParam", "=", "function", "(", "paramName", ",", "fallback", ")", "{", "var", "paramValue", "=", "Date", ".", "parse", "(", "this", ".", "anyParam", "(", "paramName", ")", ")", ";", "if", "(", "!", "isNaN", "(", "paramValue", ")", ")", "{", "return", "new", "Date", "(", "paramValue", ")", ";", "}", "if", "(", "fallback", "!==", "undefined", ")", "{", "return", "fallback", ";", "}", "throw", "new", "errors", ".", "BadRequest", "(", "'date_param_required:'", "+", "paramName", ")", ";", "}", ";", "/**\n * collect params from http request.\n *\n * @param {Array.<String>} paramNames\n * @returns {Object.<String,String>}\n */", "req", ".", "collectParams", "=", "function", "(", "paramNames", ")", "{", "var", "self", "=", "this", ";", "return", "paramNames", ".", "reduce", "(", "function", "(", "params", ",", "paramName", ")", "{", "var", "paramValue", "=", "self", ".", "strParam", "(", "paramName", ")", ";", "if", "(", "paramValue", ")", "{", "params", "[", "paramName", "]", "=", "paramValue", ".", "trim", "(", ")", ";", "}", "return", "params", ";", "}", ",", "{", "}", ")", ";", "}", ";", "}" ]
add some utility methods to http request. @param {*} [req]
[ "add", "some", "utility", "methods", "to", "http", "request", "." ]
c375a1388cfc167017e8dcd2325e71ca86ccb994
https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/utils.js#L151-L284
53,647
iolo/express-toybox
utils.js
extendHttpResponse
function extendHttpResponse(res) { res = res || express.response; function callbackFnFn(verbFunc) { return function (next, status) { var res = this; return function (err, result) { if (err) { return next(err); } if (status) { return res.status(status); } return verbFunc.call(res, result); }; }; } function laterFnFn(verbFunc) { return function (promise, next, status) { var res = this; return Q.when(promise).then(function (result) { if (status) { res.status(status); } return verbFunc.call(res, result); }).fail(next).done(); }; } // // callback helpers // /** * create generic node.js callback function to invoke 'express.response.send()'. * * ex. * ``` * var fs = require('fs'); * app.get('/foo', function(req, res, next) { * fs.readFile('foo.txt', res.sendCallbackFn(next)); * }); * ``` * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send response. * @method * @memberOf {express.request} */ res.sendCallbackFn = callbackFnFn(res.send); /** * create generic node.js callback function to invoke 'express.response.json()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'json' response. * @method * @memberOf {express.request} */ res.jsonCallbackFn = callbackFnFn(res.json); /** * create generic node.js callback function to invoke 'express.response.jsonp()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'jsonp' response. * @method * @memberOf {express.request} */ res.jsonpCallbackFn = callbackFnFn(res.jsonp); /** * create generic node.js callback function to invoke 'express.response.sendFile()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'sendFile' response. * @method * @memberOf {express.request} */ res.sendFileCallbackFn = callbackFnFn(res.sendFile); /** * create generic node.js callback function to invoke 'express.response.redirect()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'redirect' response. * @method * @memberOf {express.request} */ res.redirectCallbackFn = callbackFnFn(res.redirect); /** * ex. * ``` * fs.stat('foo.txt', res.renderCallbackFn('stat_view', next)); * ``` * * @param {string} view * @param {function} next * @param {number} [status] * @returns {function(err, result)} * @memberOf {express.response} */ res.renderCallbackFn = function (view, next, status) { var res = this; return function (err, result) { if (err) { return next(err); } if (status) { res.status(status); } return res.render(view, result); }; }; // // promise helpers // /** * promise version to invoke `express.response.send()`. * * ex. * ``` * var FS = require('q-io/fs'); * app.get('/foo', function (req, res, next) { * res.sendLater(FS.readFile('foo.txt'), next); * }) * ``` * * @param {promise|*} promise of response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.sendLater = laterFnFn(res.send); /** * promise version of `express.response.json()`. * * @param {promise|*} promise of 'json' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.jsonLater = laterFnFn(res.json); /** * promise version of `express.response.jsonp()`. * * @param {promise|*} promise of 'jsonp' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.jsonpLater = laterFnFn(res.jsonp); /** * promise version of `express.response.sendFile()`. * * @param {promise|*} promise of 'sendFile' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.sendFileLater = laterFnFn(res.sendFile); /** * promise version of `express.response.redirect()`. * * @param {promise|*} promise of 'redirect' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.redirectLater = laterFnFn(res.redirect); /** * * ex. * ``` * var FS = require('q-io/fs'); * res.renderLater('stat_view', FS.stat('foo.txt'), next); * ``` * * @param {string} view * @param {promise|*} promise of 'render' model. * @param {function} next * @param {number} [status] * @memberOf {express.response} */ res.renderLater = function (view, promise, next, status) { var res = this; return Q.when(promise).then(function (result) { if (status) { res.status(status); } return res.render(view, result); }).fail(next).done(); }; }
javascript
function extendHttpResponse(res) { res = res || express.response; function callbackFnFn(verbFunc) { return function (next, status) { var res = this; return function (err, result) { if (err) { return next(err); } if (status) { return res.status(status); } return verbFunc.call(res, result); }; }; } function laterFnFn(verbFunc) { return function (promise, next, status) { var res = this; return Q.when(promise).then(function (result) { if (status) { res.status(status); } return verbFunc.call(res, result); }).fail(next).done(); }; } // // callback helpers // /** * create generic node.js callback function to invoke 'express.response.send()'. * * ex. * ``` * var fs = require('fs'); * app.get('/foo', function(req, res, next) { * fs.readFile('foo.txt', res.sendCallbackFn(next)); * }); * ``` * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send response. * @method * @memberOf {express.request} */ res.sendCallbackFn = callbackFnFn(res.send); /** * create generic node.js callback function to invoke 'express.response.json()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'json' response. * @method * @memberOf {express.request} */ res.jsonCallbackFn = callbackFnFn(res.json); /** * create generic node.js callback function to invoke 'express.response.jsonp()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'jsonp' response. * @method * @memberOf {express.request} */ res.jsonpCallbackFn = callbackFnFn(res.jsonp); /** * create generic node.js callback function to invoke 'express.response.sendFile()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'sendFile' response. * @method * @memberOf {express.request} */ res.sendFileCallbackFn = callbackFnFn(res.sendFile); /** * create generic node.js callback function to invoke 'express.response.redirect()'. * * @param {function} next * @param {number} [status] * @returns {function(err, result)} generic node.js callback which send 'redirect' response. * @method * @memberOf {express.request} */ res.redirectCallbackFn = callbackFnFn(res.redirect); /** * ex. * ``` * fs.stat('foo.txt', res.renderCallbackFn('stat_view', next)); * ``` * * @param {string} view * @param {function} next * @param {number} [status] * @returns {function(err, result)} * @memberOf {express.response} */ res.renderCallbackFn = function (view, next, status) { var res = this; return function (err, result) { if (err) { return next(err); } if (status) { res.status(status); } return res.render(view, result); }; }; // // promise helpers // /** * promise version to invoke `express.response.send()`. * * ex. * ``` * var FS = require('q-io/fs'); * app.get('/foo', function (req, res, next) { * res.sendLater(FS.readFile('foo.txt'), next); * }) * ``` * * @param {promise|*} promise of response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.sendLater = laterFnFn(res.send); /** * promise version of `express.response.json()`. * * @param {promise|*} promise of 'json' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.jsonLater = laterFnFn(res.json); /** * promise version of `express.response.jsonp()`. * * @param {promise|*} promise of 'jsonp' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.jsonpLater = laterFnFn(res.jsonp); /** * promise version of `express.response.sendFile()`. * * @param {promise|*} promise of 'sendFile' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.sendFileLater = laterFnFn(res.sendFile); /** * promise version of `express.response.redirect()`. * * @param {promise|*} promise of 'redirect' response. * @param {function} next * @param {number} [status] * @method * @memberOf {express.request} */ res.redirectLater = laterFnFn(res.redirect); /** * * ex. * ``` * var FS = require('q-io/fs'); * res.renderLater('stat_view', FS.stat('foo.txt'), next); * ``` * * @param {string} view * @param {promise|*} promise of 'render' model. * @param {function} next * @param {number} [status] * @memberOf {express.response} */ res.renderLater = function (view, promise, next, status) { var res = this; return Q.when(promise).then(function (result) { if (status) { res.status(status); } return res.render(view, result); }).fail(next).done(); }; }
[ "function", "extendHttpResponse", "(", "res", ")", "{", "res", "=", "res", "||", "express", ".", "response", ";", "function", "callbackFnFn", "(", "verbFunc", ")", "{", "return", "function", "(", "next", ",", "status", ")", "{", "var", "res", "=", "this", ";", "return", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "return", "next", "(", "err", ")", ";", "}", "if", "(", "status", ")", "{", "return", "res", ".", "status", "(", "status", ")", ";", "}", "return", "verbFunc", ".", "call", "(", "res", ",", "result", ")", ";", "}", ";", "}", ";", "}", "function", "laterFnFn", "(", "verbFunc", ")", "{", "return", "function", "(", "promise", ",", "next", ",", "status", ")", "{", "var", "res", "=", "this", ";", "return", "Q", ".", "when", "(", "promise", ")", ".", "then", "(", "function", "(", "result", ")", "{", "if", "(", "status", ")", "{", "res", ".", "status", "(", "status", ")", ";", "}", "return", "verbFunc", ".", "call", "(", "res", ",", "result", ")", ";", "}", ")", ".", "fail", "(", "next", ")", ".", "done", "(", ")", ";", "}", ";", "}", "//", "// callback helpers", "//", "/**\n * create generic node.js callback function to invoke 'express.response.send()'.\n *\n * ex.\n * ```\n * var fs = require('fs');\n * app.get('/foo', function(req, res, next) {\n * fs.readFile('foo.txt', res.sendCallbackFn(next));\n * });\n * ```\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)} generic node.js callback which send response.\n * @method\n * @memberOf {express.request}\n */", "res", ".", "sendCallbackFn", "=", "callbackFnFn", "(", "res", ".", "send", ")", ";", "/**\n * create generic node.js callback function to invoke 'express.response.json()'.\n *\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)} generic node.js callback which send 'json' response.\n * @method\n * @memberOf {express.request}\n */", "res", ".", "jsonCallbackFn", "=", "callbackFnFn", "(", "res", ".", "json", ")", ";", "/**\n * create generic node.js callback function to invoke 'express.response.jsonp()'.\n *\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)} generic node.js callback which send 'jsonp' response.\n * @method\n * @memberOf {express.request}\n */", "res", ".", "jsonpCallbackFn", "=", "callbackFnFn", "(", "res", ".", "jsonp", ")", ";", "/**\n * create generic node.js callback function to invoke 'express.response.sendFile()'.\n *\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)} generic node.js callback which send 'sendFile' response.\n * @method\n * @memberOf {express.request}\n */", "res", ".", "sendFileCallbackFn", "=", "callbackFnFn", "(", "res", ".", "sendFile", ")", ";", "/**\n * create generic node.js callback function to invoke 'express.response.redirect()'.\n *\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)} generic node.js callback which send 'redirect' response.\n * @method\n * @memberOf {express.request}\n */", "res", ".", "redirectCallbackFn", "=", "callbackFnFn", "(", "res", ".", "redirect", ")", ";", "/**\n * ex.\n * ```\n * fs.stat('foo.txt', res.renderCallbackFn('stat_view', next));\n * ```\n *\n * @param {string} view\n * @param {function} next\n * @param {number} [status]\n * @returns {function(err, result)}\n * @memberOf {express.response}\n */", "res", ".", "renderCallbackFn", "=", "function", "(", "view", ",", "next", ",", "status", ")", "{", "var", "res", "=", "this", ";", "return", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "return", "next", "(", "err", ")", ";", "}", "if", "(", "status", ")", "{", "res", ".", "status", "(", "status", ")", ";", "}", "return", "res", ".", "render", "(", "view", ",", "result", ")", ";", "}", ";", "}", ";", "//", "// promise helpers", "//", "/**\n * promise version to invoke `express.response.send()`.\n *\n * ex.\n * ```\n * var FS = require('q-io/fs');\n * app.get('/foo', function (req, res, next) {\n * res.sendLater(FS.readFile('foo.txt'), next);\n * })\n * ```\n *\n * @param {promise|*} promise of response.\n * @param {function} next\n * @param {number} [status]\n * @method\n * @memberOf {express.request}\n */", "res", ".", "sendLater", "=", "laterFnFn", "(", "res", ".", "send", ")", ";", "/**\n * promise version of `express.response.json()`.\n *\n * @param {promise|*} promise of 'json' response.\n * @param {function} next\n * @param {number} [status]\n * @method\n * @memberOf {express.request}\n */", "res", ".", "jsonLater", "=", "laterFnFn", "(", "res", ".", "json", ")", ";", "/**\n * promise version of `express.response.jsonp()`.\n *\n * @param {promise|*} promise of 'jsonp' response.\n * @param {function} next\n * @param {number} [status]\n * @method\n * @memberOf {express.request}\n */", "res", ".", "jsonpLater", "=", "laterFnFn", "(", "res", ".", "jsonp", ")", ";", "/**\n * promise version of `express.response.sendFile()`.\n *\n * @param {promise|*} promise of 'sendFile' response.\n * @param {function} next\n * @param {number} [status]\n * @method\n * @memberOf {express.request}\n */", "res", ".", "sendFileLater", "=", "laterFnFn", "(", "res", ".", "sendFile", ")", ";", "/**\n * promise version of `express.response.redirect()`.\n *\n * @param {promise|*} promise of 'redirect' response.\n * @param {function} next\n * @param {number} [status]\n * @method\n * @memberOf {express.request}\n */", "res", ".", "redirectLater", "=", "laterFnFn", "(", "res", ".", "redirect", ")", ";", "/**\n *\n * ex.\n * ```\n * var FS = require('q-io/fs');\n * res.renderLater('stat_view', FS.stat('foo.txt'), next);\n * ```\n *\n * @param {string} view\n * @param {promise|*} promise of 'render' model.\n * @param {function} next\n * @param {number} [status]\n * @memberOf {express.response}\n */", "res", ".", "renderLater", "=", "function", "(", "view", ",", "promise", ",", "next", ",", "status", ")", "{", "var", "res", "=", "this", ";", "return", "Q", ".", "when", "(", "promise", ")", ".", "then", "(", "function", "(", "result", ")", "{", "if", "(", "status", ")", "{", "res", ".", "status", "(", "status", ")", ";", "}", "return", "res", ".", "render", "(", "view", ",", "result", ")", ";", "}", ")", ".", "fail", "(", "next", ")", ".", "done", "(", ")", ";", "}", ";", "}" ]
add some utility methods to http response. @param {*} [res]
[ "add", "some", "utility", "methods", "to", "http", "response", "." ]
c375a1388cfc167017e8dcd2325e71ca86ccb994
https://github.com/iolo/express-toybox/blob/c375a1388cfc167017e8dcd2325e71ca86ccb994/utils.js#L291-L502
53,648
karfcz/kff
src/functions/delegatedEventHandler.js
matches
function matches(el, target, selector) { var elements = el.querySelectorAll(selector); return arrayIndexOf(elements, target) !== -1; }
javascript
function matches(el, target, selector) { var elements = el.querySelectorAll(selector); return arrayIndexOf(elements, target) !== -1; }
[ "function", "matches", "(", "el", ",", "target", ",", "selector", ")", "{", "var", "elements", "=", "el", ".", "querySelectorAll", "(", "selector", ")", ";", "return", "arrayIndexOf", "(", "elements", ",", "target", ")", "!==", "-", "1", ";", "}" ]
Matches target element against CSS selector starting from element el @param {DOMElement} el Root DOM element @param {DOMElement} target Target DOM element @param {string} selector CSS selector @return {boolean} True if target element matches CSS selector, false otherwise
[ "Matches", "target", "element", "against", "CSS", "selector", "starting", "from", "element", "el" ]
533b69e8bc9e9b7f60b403d776678bf1c06ac502
https://github.com/karfcz/kff/blob/533b69e8bc9e9b7f60b403d776678bf1c06ac502/src/functions/delegatedEventHandler.js#L21-L25
53,649
mvrilo/tumblrrr
lib/tumblrrr.js
tumblr
function tumblr(hostname, key, secret, access_key, access_secret) { if (!(this instanceof tumblr)) return new tumblr(hostname, key, secret, access_key, access_secret); var obj = (typeof hostname !== 'object') ? { hostname : hostname, secret : secret, key : key, access_secret : access_secret, access_key : access_key } : hostname; // reference if (obj && obj.hostname) this.hostname = !/\./.test(obj.hostname) ? obj.hostname + '.tumblr.com' : obj.hostname; this.key = obj.key; this.secret = obj.secret; this.access_key = obj.access_key; this.access_secret = obj.access_secret; // output the log to console this.debug = false; // keeping the logs even if debug is false this.log = []; // caching requests this.caches = false; this._cache = {}; // oauth access this._oauth_access = this.access_key && this.access_secret; // if response should omit "meta" this.onlyResponse = true; if (this.key && this.secret && this._oauth_access) { this._oa = oa = new OAuth('http://www.tumblr.com/oauth/request_token', 'http://www.tumblr.com/oauth/access_token', this.key, this.secret, '1.0A', null, 'HMAC-SHA1'); var self = this; oa.getOAuthRequestToken(function(err, req_key, req_secret, res) { if (!err) { var url = ['http://www.tumblr.com/oauth/authorize/?oauth_token=', req_key].join(''); self.OAuthAuthorizationURL = url; self._oa.session = self._oa.session || {}; self._oa.session.key = req_key; self._oa.session.secret = req_secret; } else { debug(err); } }); } return this; }
javascript
function tumblr(hostname, key, secret, access_key, access_secret) { if (!(this instanceof tumblr)) return new tumblr(hostname, key, secret, access_key, access_secret); var obj = (typeof hostname !== 'object') ? { hostname : hostname, secret : secret, key : key, access_secret : access_secret, access_key : access_key } : hostname; // reference if (obj && obj.hostname) this.hostname = !/\./.test(obj.hostname) ? obj.hostname + '.tumblr.com' : obj.hostname; this.key = obj.key; this.secret = obj.secret; this.access_key = obj.access_key; this.access_secret = obj.access_secret; // output the log to console this.debug = false; // keeping the logs even if debug is false this.log = []; // caching requests this.caches = false; this._cache = {}; // oauth access this._oauth_access = this.access_key && this.access_secret; // if response should omit "meta" this.onlyResponse = true; if (this.key && this.secret && this._oauth_access) { this._oa = oa = new OAuth('http://www.tumblr.com/oauth/request_token', 'http://www.tumblr.com/oauth/access_token', this.key, this.secret, '1.0A', null, 'HMAC-SHA1'); var self = this; oa.getOAuthRequestToken(function(err, req_key, req_secret, res) { if (!err) { var url = ['http://www.tumblr.com/oauth/authorize/?oauth_token=', req_key].join(''); self.OAuthAuthorizationURL = url; self._oa.session = self._oa.session || {}; self._oa.session.key = req_key; self._oa.session.secret = req_secret; } else { debug(err); } }); } return this; }
[ "function", "tumblr", "(", "hostname", ",", "key", ",", "secret", ",", "access_key", ",", "access_secret", ")", "{", "if", "(", "!", "(", "this", "instanceof", "tumblr", ")", ")", "return", "new", "tumblr", "(", "hostname", ",", "key", ",", "secret", ",", "access_key", ",", "access_secret", ")", ";", "var", "obj", "=", "(", "typeof", "hostname", "!==", "'object'", ")", "?", "{", "hostname", ":", "hostname", ",", "secret", ":", "secret", ",", "key", ":", "key", ",", "access_secret", ":", "access_secret", ",", "access_key", ":", "access_key", "}", ":", "hostname", ";", "// reference", "if", "(", "obj", "&&", "obj", ".", "hostname", ")", "this", ".", "hostname", "=", "!", "/", "\\.", "/", ".", "test", "(", "obj", ".", "hostname", ")", "?", "obj", ".", "hostname", "+", "'.tumblr.com'", ":", "obj", ".", "hostname", ";", "this", ".", "key", "=", "obj", ".", "key", ";", "this", ".", "secret", "=", "obj", ".", "secret", ";", "this", ".", "access_key", "=", "obj", ".", "access_key", ";", "this", ".", "access_secret", "=", "obj", ".", "access_secret", ";", "// output the log to console", "this", ".", "debug", "=", "false", ";", "// keeping the logs even if debug is false", "this", ".", "log", "=", "[", "]", ";", "// caching requests", "this", ".", "caches", "=", "false", ";", "this", ".", "_cache", "=", "{", "}", ";", "// oauth access", "this", ".", "_oauth_access", "=", "this", ".", "access_key", "&&", "this", ".", "access_secret", ";", "// if response should omit \"meta\"", "this", ".", "onlyResponse", "=", "true", ";", "if", "(", "this", ".", "key", "&&", "this", ".", "secret", "&&", "this", ".", "_oauth_access", ")", "{", "this", ".", "_oa", "=", "oa", "=", "new", "OAuth", "(", "'http://www.tumblr.com/oauth/request_token'", ",", "'http://www.tumblr.com/oauth/access_token'", ",", "this", ".", "key", ",", "this", ".", "secret", ",", "'1.0A'", ",", "null", ",", "'HMAC-SHA1'", ")", ";", "var", "self", "=", "this", ";", "oa", ".", "getOAuthRequestToken", "(", "function", "(", "err", ",", "req_key", ",", "req_secret", ",", "res", ")", "{", "if", "(", "!", "err", ")", "{", "var", "url", "=", "[", "'http://www.tumblr.com/oauth/authorize/?oauth_token='", ",", "req_key", "]", ".", "join", "(", "''", ")", ";", "self", ".", "OAuthAuthorizationURL", "=", "url", ";", "self", ".", "_oa", ".", "session", "=", "self", ".", "_oa", ".", "session", "||", "{", "}", ";", "self", ".", "_oa", ".", "session", ".", "key", "=", "req_key", ";", "self", ".", "_oa", ".", "session", ".", "secret", "=", "req_secret", ";", "}", "else", "{", "debug", "(", "err", ")", ";", "}", "}", ")", ";", "}", "return", "this", ";", "}" ]
first argument can be string or object
[ "first", "argument", "can", "be", "string", "or", "object" ]
509690be73555cd232861e82506cd8bf6f9e9a91
https://github.com/mvrilo/tumblrrr/blob/509690be73555cd232861e82506cd8bf6f9e9a91/lib/tumblrrr.js#L25-L80
53,650
azendal/argon
argon/storage/local.js
create
function create(requestObj, callback) { var storage = this; callback = callback || function defaultPostCallback() { //setup Error Notification here }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(); return this; } requestObj.data.id = this._generateUid(); for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } this.storage[requestObj.data.id] = requestObj.data; var data = this.storage[requestObj.data.id]; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data); } callback(data); return this; }
javascript
function create(requestObj, callback) { var storage = this; callback = callback || function defaultPostCallback() { //setup Error Notification here }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(); return this; } requestObj.data.id = this._generateUid(); for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } this.storage[requestObj.data.id] = requestObj.data; var data = this.storage[requestObj.data.id]; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data); } callback(data); return this; }
[ "function", "create", "(", "requestObj", ",", "callback", ")", "{", "var", "storage", "=", "this", ";", "callback", "=", "callback", "||", "function", "defaultPostCallback", "(", ")", "{", "//setup Error Notification here", "}", ";", "if", "(", "(", "typeof", "requestObj", ")", "===", "'undefined'", "||", "requestObj", "===", "null", ")", "{", "callback", "(", ")", ";", "return", "this", ";", "}", "requestObj", ".", "data", ".", "id", "=", "this", ".", "_generateUid", "(", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "preprocessors", ".", "length", ";", "i", "++", ")", "{", "requestObj", ".", "data", "=", "storage", ".", "preprocessors", "[", "i", "]", "(", "requestObj", ".", "data", ",", "requestObj", ")", ";", "}", "this", ".", "storage", "[", "requestObj", ".", "data", ".", "id", "]", "=", "requestObj", ".", "data", ";", "var", "data", "=", "this", ".", "storage", "[", "requestObj", ".", "data", ".", "id", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "processors", ".", "length", ";", "i", "++", ")", "{", "data", "=", "storage", ".", "processors", "[", "i", "]", "(", "data", ")", ";", "}", "callback", "(", "data", ")", ";", "return", "this", ";", "}" ]
Creates new data on the storage instance @method post <public> @argument data <required> [Object] the data to create on the storage instance @argument callback [Function] The function that will be executed when the process ends @return [Array]
[ "Creates", "new", "data", "on", "the", "storage", "instance" ]
0cfd3a3b3731b69abca55c956c757476779ec1bd
https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/storage/local.js#L127-L155
53,651
azendal/argon
argon/storage/local.js
find
function find(requestObj, callback) { var found, storedData, property; var storage = this; callback = callback || function defaultGetCallback() { //nothing here maybe put error notification }; for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } found = []; storedData = this.storage; Object.keys(storedData).forEach(function (property) { found.push(storedData[property]); }); var data = found; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data, requestObj); } callback(data); return this; }
javascript
function find(requestObj, callback) { var found, storedData, property; var storage = this; callback = callback || function defaultGetCallback() { //nothing here maybe put error notification }; for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } found = []; storedData = this.storage; Object.keys(storedData).forEach(function (property) { found.push(storedData[property]); }); var data = found; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data, requestObj); } callback(data); return this; }
[ "function", "find", "(", "requestObj", ",", "callback", ")", "{", "var", "found", ",", "storedData", ",", "property", ";", "var", "storage", "=", "this", ";", "callback", "=", "callback", "||", "function", "defaultGetCallback", "(", ")", "{", "//nothing here maybe put error notification", "}", ";", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "preprocessors", ".", "length", ";", "i", "++", ")", "{", "requestObj", ".", "data", "=", "storage", ".", "preprocessors", "[", "i", "]", "(", "requestObj", ".", "data", ",", "requestObj", ")", ";", "}", "if", "(", "(", "typeof", "requestObj", ")", "===", "'undefined'", "||", "requestObj", "===", "null", ")", "{", "callback", "(", "null", ")", ";", "return", "this", ";", "}", "found", "=", "[", "]", ";", "storedData", "=", "this", ".", "storage", ";", "Object", ".", "keys", "(", "storedData", ")", ".", "forEach", "(", "function", "(", "property", ")", "{", "found", ".", "push", "(", "storedData", "[", "property", "]", ")", ";", "}", ")", ";", "var", "data", "=", "found", ";", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "processors", ".", "length", ";", "i", "++", ")", "{", "data", "=", "storage", ".", "processors", "[", "i", "]", "(", "data", ",", "requestObj", ")", ";", "}", "callback", "(", "data", ")", ";", "return", "this", ";", "}" ]
Retrieves a set of data on the storage instance @method get <public> @argument query <required> [Object] the query to the elements that must be updated @argument callback [Function] The function that will be executed when the process ends @return [Array]
[ "Retrieves", "a", "set", "of", "data", "on", "the", "storage", "instance" ]
0cfd3a3b3731b69abca55c956c757476779ec1bd
https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/storage/local.js#L164-L197
53,652
azendal/argon
argon/storage/local.js
update
function update(requestObj, callback) { var storage = this; callback = callback || function defaultPutCallBack() { //setup Error notification }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } if (requestObj.data) { for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } } this.storage[requestObj.data.id] = requestObj.data; var data = this.storage[requestObj.data.id]; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data, requestObj); } callback(data); }
javascript
function update(requestObj, callback) { var storage = this; callback = callback || function defaultPutCallBack() { //setup Error notification }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } if (requestObj.data) { for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } } this.storage[requestObj.data.id] = requestObj.data; var data = this.storage[requestObj.data.id]; for (i = 0; i < storage.processors.length; i++) { data = storage.processors[i](data, requestObj); } callback(data); }
[ "function", "update", "(", "requestObj", ",", "callback", ")", "{", "var", "storage", "=", "this", ";", "callback", "=", "callback", "||", "function", "defaultPutCallBack", "(", ")", "{", "//setup Error notification", "}", ";", "if", "(", "(", "typeof", "requestObj", ")", "===", "'undefined'", "||", "requestObj", "===", "null", ")", "{", "callback", "(", "null", ")", ";", "return", "this", ";", "}", "if", "(", "requestObj", ".", "data", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "preprocessors", ".", "length", ";", "i", "++", ")", "{", "requestObj", ".", "data", "=", "storage", ".", "preprocessors", "[", "i", "]", "(", "requestObj", ".", "data", ",", "requestObj", ")", ";", "}", "}", "this", ".", "storage", "[", "requestObj", ".", "data", ".", "id", "]", "=", "requestObj", ".", "data", ";", "var", "data", "=", "this", ".", "storage", "[", "requestObj", ".", "data", ".", "id", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "processors", ".", "length", ";", "i", "++", ")", "{", "data", "=", "storage", ".", "processors", "[", "i", "]", "(", "data", ",", "requestObj", ")", ";", "}", "callback", "(", "data", ")", ";", "}" ]
Updates a set of data on the storage instance @method put <public> @argument query <required> [Object] the query to the elements that must be updated @argument callback [Function] The function that will be executed when the process ends @return [Object] this
[ "Updates", "a", "set", "of", "data", "on", "the", "storage", "instance" ]
0cfd3a3b3731b69abca55c956c757476779ec1bd
https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/storage/local.js#L234-L259
53,653
azendal/argon
argon/storage/local.js
remove
function remove(requestObj, callback) { var storageInstance = this; var storage = this; callback = callback || function defaultRemoveCallBack() { //setup Error Notification }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } if (requestObj.data) { for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } } if (requestObj.data && requestObj.data.id) { delete storageInstance.storage[requestObj.data.id]; } callback(null); return this; }
javascript
function remove(requestObj, callback) { var storageInstance = this; var storage = this; callback = callback || function defaultRemoveCallBack() { //setup Error Notification }; if ((typeof requestObj) === 'undefined' || requestObj === null) { callback(null); return this; } if (requestObj.data) { for (i = 0; i < storage.preprocessors.length; i++) { requestObj.data = storage.preprocessors[i](requestObj.data, requestObj); } } if (requestObj.data && requestObj.data.id) { delete storageInstance.storage[requestObj.data.id]; } callback(null); return this; }
[ "function", "remove", "(", "requestObj", ",", "callback", ")", "{", "var", "storageInstance", "=", "this", ";", "var", "storage", "=", "this", ";", "callback", "=", "callback", "||", "function", "defaultRemoveCallBack", "(", ")", "{", "//setup Error Notification", "}", ";", "if", "(", "(", "typeof", "requestObj", ")", "===", "'undefined'", "||", "requestObj", "===", "null", ")", "{", "callback", "(", "null", ")", ";", "return", "this", ";", "}", "if", "(", "requestObj", ".", "data", ")", "{", "for", "(", "i", "=", "0", ";", "i", "<", "storage", ".", "preprocessors", ".", "length", ";", "i", "++", ")", "{", "requestObj", ".", "data", "=", "storage", ".", "preprocessors", "[", "i", "]", "(", "requestObj", ".", "data", ",", "requestObj", ")", ";", "}", "}", "if", "(", "requestObj", ".", "data", "&&", "requestObj", ".", "data", ".", "id", ")", "{", "delete", "storageInstance", ".", "storage", "[", "requestObj", ".", "data", ".", "id", "]", ";", "}", "callback", "(", "null", ")", ";", "return", "this", ";", "}" ]
Removes a set of elements from the storage @method remove <public> @argument query <required> [Object] the query to the elements that must be removed @argument callback [Function] The function that will be executed when the process ends @return [Object] this
[ "Removes", "a", "set", "of", "elements", "from", "the", "storage" ]
0cfd3a3b3731b69abca55c956c757476779ec1bd
https://github.com/azendal/argon/blob/0cfd3a3b3731b69abca55c956c757476779ec1bd/argon/storage/local.js#L268-L294
53,654
jetiny/rollup-standalone
lib/rollup-cli.js
log
function log ( object, symbol ) { var message = (object.plugin ? ("(" + (object.plugin) + " plugin) " + (object.message)) : object.message) || object; stderr( ("" + symbol + (index$3.bold( message ))) ); if ( object.url ) { stderr( index$3.cyan( object.url ) ); } if ( object.loc ) { stderr( ((relativeId( object.loc.file )) + " (" + (object.loc.line) + ":" + (object.loc.column) + ")") ); } else if ( object.id ) { stderr( relativeId( object.id ) ); } if ( object.frame ) { stderr( index$3.dim( object.frame ) ); } stderr( '' ); }
javascript
function log ( object, symbol ) { var message = (object.plugin ? ("(" + (object.plugin) + " plugin) " + (object.message)) : object.message) || object; stderr( ("" + symbol + (index$3.bold( message ))) ); if ( object.url ) { stderr( index$3.cyan( object.url ) ); } if ( object.loc ) { stderr( ((relativeId( object.loc.file )) + " (" + (object.loc.line) + ":" + (object.loc.column) + ")") ); } else if ( object.id ) { stderr( relativeId( object.id ) ); } if ( object.frame ) { stderr( index$3.dim( object.frame ) ); } stderr( '' ); }
[ "function", "log", "(", "object", ",", "symbol", ")", "{", "var", "message", "=", "(", "object", ".", "plugin", "?", "(", "\"(\"", "+", "(", "object", ".", "plugin", ")", "+", "\" plugin) \"", "+", "(", "object", ".", "message", ")", ")", ":", "object", ".", "message", ")", "||", "object", ";", "stderr", "(", "(", "\"\"", "+", "symbol", "+", "(", "index$3", ".", "bold", "(", "message", ")", ")", ")", ")", ";", "if", "(", "object", ".", "url", ")", "{", "stderr", "(", "index$3", ".", "cyan", "(", "object", ".", "url", ")", ")", ";", "}", "if", "(", "object", ".", "loc", ")", "{", "stderr", "(", "(", "(", "relativeId", "(", "object", ".", "loc", ".", "file", ")", ")", "+", "\" (\"", "+", "(", "object", ".", "loc", ".", "line", ")", "+", "\":\"", "+", "(", "object", ".", "loc", ".", "column", ")", "+", "\")\"", ")", ")", ";", "}", "else", "if", "(", "object", ".", "id", ")", "{", "stderr", "(", "relativeId", "(", "object", ".", "id", ")", ")", ";", "}", "if", "(", "object", ".", "frame", ")", "{", "stderr", "(", "index$3", ".", "dim", "(", "object", ".", "frame", ")", ")", ";", "}", "stderr", "(", "''", ")", ";", "}" ]
eslint-disable-line no-console
[ "eslint", "-", "disable", "-", "line", "no", "-", "console" ]
949d30c702b666a1a6b92e353b3a70c2e8290a66
https://github.com/jetiny/rollup-standalone/blob/949d30c702b666a1a6b92e353b3a70c2e8290a66/lib/rollup-cli.js#L568-L588
53,655
carrascoMDD/protractor-relaunchable
lib/configParser.js
function(into, from) { for (var key in from) { if (into[key] instanceof Object && !(into[key] instanceof Array) && !(into[key] instanceof Function)) { merge_(into[key], from[key]); } else { into[key] = from[key]; } } return into; }
javascript
function(into, from) { for (var key in from) { if (into[key] instanceof Object && !(into[key] instanceof Array) && !(into[key] instanceof Function)) { merge_(into[key], from[key]); } else { into[key] = from[key]; } } return into; }
[ "function", "(", "into", ",", "from", ")", "{", "for", "(", "var", "key", "in", "from", ")", "{", "if", "(", "into", "[", "key", "]", "instanceof", "Object", "&&", "!", "(", "into", "[", "key", "]", "instanceof", "Array", ")", "&&", "!", "(", "into", "[", "key", "]", "instanceof", "Function", ")", ")", "{", "merge_", "(", "into", "[", "key", "]", ",", "from", "[", "key", "]", ")", ";", "}", "else", "{", "into", "[", "key", "]", "=", "from", "[", "key", "]", ";", "}", "}", "return", "into", ";", "}" ]
Merge config objects together. @private @param {Object} into @param {Object} from @return {Object} The 'into' config.
[ "Merge", "config", "objects", "together", "." ]
c18e17ecd8b5b036217f87680800c6e14b47361f
https://github.com/carrascoMDD/protractor-relaunchable/blob/c18e17ecd8b5b036217f87680800c6e14b47361f/lib/configParser.js#L58-L69
53,656
thiagodp/split-cmd
index.js
split
function split( command ) { if ( typeof command !== 'string' ) { throw new Error( 'Command must be a string' ); } var r = command.match( /[^"\s]+|"(?:\\"|[^"])*"/g ); if ( ! r ) { return []; } return r.map( function ( expr ) { var isQuoted = expr.charAt( 0 ) === '"' && expr.charAt( expr.length - 1 ) === '"'; return isQuoted ? expr.slice( 1, -1 ) : expr; } ); }
javascript
function split( command ) { if ( typeof command !== 'string' ) { throw new Error( 'Command must be a string' ); } var r = command.match( /[^"\s]+|"(?:\\"|[^"])*"/g ); if ( ! r ) { return []; } return r.map( function ( expr ) { var isQuoted = expr.charAt( 0 ) === '"' && expr.charAt( expr.length - 1 ) === '"'; return isQuoted ? expr.slice( 1, -1 ) : expr; } ); }
[ "function", "split", "(", "command", ")", "{", "if", "(", "typeof", "command", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Command must be a string'", ")", ";", "}", "var", "r", "=", "command", ".", "match", "(", "/", "[^\"\\s]+|\"(?:\\\\\"|[^\"])*\"", "/", "g", ")", ";", "if", "(", "!", "r", ")", "{", "return", "[", "]", ";", "}", "return", "r", ".", "map", "(", "function", "(", "expr", ")", "{", "var", "isQuoted", "=", "expr", ".", "charAt", "(", "0", ")", "===", "'\"'", "&&", "expr", ".", "charAt", "(", "expr", ".", "length", "-", "1", ")", "===", "'\"'", ";", "return", "isQuoted", "?", "expr", ".", "slice", "(", "1", ",", "-", "1", ")", ":", "expr", ";", "}", ")", ";", "}" ]
Split a command into an array. @example ```js var arr = split( 'git commit -m "some message with spaces"' ); console.log( arr ); // [ "git", "commit", "-m", "some message with spaces" ] ``` @param {string} command Command to split. @returns {Array}
[ "Split", "a", "command", "into", "an", "array", "." ]
6574da1c7d0f4d216d9d5897794fc14397ae41be
https://github.com/thiagodp/split-cmd/blob/6574da1c7d0f4d216d9d5897794fc14397ae41be/index.js#L13-L27
53,657
thiagodp/split-cmd
index.js
splitToObject
function splitToObject( command ) { var cmds = split( command ); switch( cmds.length ) { case 0: return {}; case 1: return { command: cmds[ 0 ] }; default: { var first = cmds[ 0 ]; cmds.shift(); return { command: first, args: cmds }; } } }
javascript
function splitToObject( command ) { var cmds = split( command ); switch( cmds.length ) { case 0: return {}; case 1: return { command: cmds[ 0 ] }; default: { var first = cmds[ 0 ]; cmds.shift(); return { command: first, args: cmds }; } } }
[ "function", "splitToObject", "(", "command", ")", "{", "var", "cmds", "=", "split", "(", "command", ")", ";", "switch", "(", "cmds", ".", "length", ")", "{", "case", "0", ":", "return", "{", "}", ";", "case", "1", ":", "return", "{", "command", ":", "cmds", "[", "0", "]", "}", ";", "default", ":", "{", "var", "first", "=", "cmds", "[", "0", "]", ";", "cmds", ".", "shift", "(", ")", ";", "return", "{", "command", ":", "first", ",", "args", ":", "cmds", "}", ";", "}", "}", "}" ]
Split a command into an object with the attributes `command` and `args`. @example ```js var obj = splitToObject( 'git commit -m "some message with spaces"' ); console.log( obj.command ); // git console.log( obj.args ); // [ "commit", "-m", "some message with spaces" ] ``` @param {string} command Command to split. @returns {object}
[ "Split", "a", "command", "into", "an", "object", "with", "the", "attributes", "command", "and", "args", "." ]
6574da1c7d0f4d216d9d5897794fc14397ae41be
https://github.com/thiagodp/split-cmd/blob/6574da1c7d0f4d216d9d5897794fc14397ae41be/index.js#L42-L53
53,658
layerhq/node-layer-webhooks
lib/webhooks.js
function(params, callback) { if (!params.url) return (callback || function() {})(new Error(utils.i18n.webhooks.url)); if (!params.events || !params.events.length) return (callback || function() {})(new Error(utils.i18n.webhooks.events)); if (!params.secret) return (callback || function() {})(new Error(utils.i18n.webhooks.secret)); utils.debug('Webhooks register: ' + params.url); request.post({ path: '/webhooks', body: { target_url: params.url, events: params.events, secret: params.secret, config: params.config || {}, version: version, } }, function(err, res) { if (!err) res.body.secret = params.secret; if (callback) callback(err, res); }); }
javascript
function(params, callback) { if (!params.url) return (callback || function() {})(new Error(utils.i18n.webhooks.url)); if (!params.events || !params.events.length) return (callback || function() {})(new Error(utils.i18n.webhooks.events)); if (!params.secret) return (callback || function() {})(new Error(utils.i18n.webhooks.secret)); utils.debug('Webhooks register: ' + params.url); request.post({ path: '/webhooks', body: { target_url: params.url, events: params.events, secret: params.secret, config: params.config || {}, version: version, } }, function(err, res) { if (!err) res.body.secret = params.secret; if (callback) callback(err, res); }); }
[ "function", "(", "params", ",", "callback", ")", "{", "if", "(", "!", "params", ".", "url", ")", "return", "(", "callback", "||", "function", "(", ")", "{", "}", ")", "(", "new", "Error", "(", "utils", ".", "i18n", ".", "webhooks", ".", "url", ")", ")", ";", "if", "(", "!", "params", ".", "events", "||", "!", "params", ".", "events", ".", "length", ")", "return", "(", "callback", "||", "function", "(", ")", "{", "}", ")", "(", "new", "Error", "(", "utils", ".", "i18n", ".", "webhooks", ".", "events", ")", ")", ";", "if", "(", "!", "params", ".", "secret", ")", "return", "(", "callback", "||", "function", "(", ")", "{", "}", ")", "(", "new", "Error", "(", "utils", ".", "i18n", ".", "webhooks", ".", "secret", ")", ")", ";", "utils", ".", "debug", "(", "'Webhooks register: '", "+", "params", ".", "url", ")", ";", "request", ".", "post", "(", "{", "path", ":", "'/webhooks'", ",", "body", ":", "{", "target_url", ":", "params", ".", "url", ",", "events", ":", "params", ".", "events", ",", "secret", ":", "params", ".", "secret", ",", "config", ":", "params", ".", "config", "||", "{", "}", ",", "version", ":", "version", ",", "}", "}", ",", "function", "(", "err", ",", "res", ")", "{", "if", "(", "!", "err", ")", "res", ".", "body", ".", "secret", "=", "params", ".", "secret", ";", "if", "(", "callback", ")", "callback", "(", "err", ",", "res", ")", ";", "}", ")", ";", "}" ]
Register a Webhook @param {Object} params @param {String[]} params.events Array of event names to subscribe to @param {String} params.url URL for webhook events to go to @param {String} params.secret Unique string known only to your server for validating webhook events @param {Object} params.config JSON object to send with all webhook events @param {Function} callback Callback function
[ "Register", "a", "Webhook" ]
9bfbee048c03d3ba4474a3490085626cd8a7a0df
https://github.com/layerhq/node-layer-webhooks/blob/9bfbee048c03d3ba4474a3490085626cd8a7a0df/lib/webhooks.js#L22-L41
53,659
layerhq/node-layer-webhooks
lib/webhooks.js
function(webhookId, callback) { utils.debug('Webhooks disable: ' + webhookId); request.post({ path: '/webhooks/' + utils.toUUID(webhookId) + '/deactivate', }, callback || utils.nop); }
javascript
function(webhookId, callback) { utils.debug('Webhooks disable: ' + webhookId); request.post({ path: '/webhooks/' + utils.toUUID(webhookId) + '/deactivate', }, callback || utils.nop); }
[ "function", "(", "webhookId", ",", "callback", ")", "{", "utils", ".", "debug", "(", "'Webhooks disable: '", "+", "webhookId", ")", ";", "request", ".", "post", "(", "{", "path", ":", "'/webhooks/'", "+", "utils", ".", "toUUID", "(", "webhookId", ")", "+", "'/deactivate'", ",", "}", ",", "callback", "||", "utils", ".", "nop", ")", ";", "}" ]
Disable a webhook @param {String} webhookId @param {Function} callback Callback function
[ "Disable", "a", "webhook" ]
9bfbee048c03d3ba4474a3490085626cd8a7a0df
https://github.com/layerhq/node-layer-webhooks/blob/9bfbee048c03d3ba4474a3490085626cd8a7a0df/lib/webhooks.js#L49-L54
53,660
layerhq/node-layer-webhooks
lib/webhooks.js
function(webhookId, callback) { utils.debug('Webhooks get: ' + webhookId); request.get({ path: '/webhooks/' + utils.toUUID(webhookId), }, callback); }
javascript
function(webhookId, callback) { utils.debug('Webhooks get: ' + webhookId); request.get({ path: '/webhooks/' + utils.toUUID(webhookId), }, callback); }
[ "function", "(", "webhookId", ",", "callback", ")", "{", "utils", ".", "debug", "(", "'Webhooks get: '", "+", "webhookId", ")", ";", "request", ".", "get", "(", "{", "path", ":", "'/webhooks/'", "+", "utils", ".", "toUUID", "(", "webhookId", ")", ",", "}", ",", "callback", ")", ";", "}" ]
Get a webhook @param {String} webhookId @param {Function} callback Callback function
[ "Get", "a", "webhook" ]
9bfbee048c03d3ba4474a3490085626cd8a7a0df
https://github.com/layerhq/node-layer-webhooks/blob/9bfbee048c03d3ba4474a3490085626cd8a7a0df/lib/webhooks.js#L101-L106
53,661
SolarNetwork/solarnetwork-d3
src/chart/baseGroupedStackTimeBarChart.js
xBarPadding
function xBarPadding() { var domain = xBar.domain(); var barSpacing = (domain.length > 1 ? (xBar(domain[1]) - xBar(domain[0])) : xBar.rangeBand()); var barPadding = (barSpacing - xBar.rangeBand()); return barPadding; }
javascript
function xBarPadding() { var domain = xBar.domain(); var barSpacing = (domain.length > 1 ? (xBar(domain[1]) - xBar(domain[0])) : xBar.rangeBand()); var barPadding = (barSpacing - xBar.rangeBand()); return barPadding; }
[ "function", "xBarPadding", "(", ")", "{", "var", "domain", "=", "xBar", ".", "domain", "(", ")", ";", "var", "barSpacing", "=", "(", "domain", ".", "length", ">", "1", "?", "(", "xBar", "(", "domain", "[", "1", "]", ")", "-", "xBar", "(", "domain", "[", "0", "]", ")", ")", ":", "xBar", ".", "rangeBand", "(", ")", ")", ";", "var", "barPadding", "=", "(", "barSpacing", "-", "xBar", ".", "rangeBand", "(", ")", ")", ";", "return", "barPadding", ";", "}" ]
Get the number of pixels used for padding between bars. @returns {Number} the number of pixels padding between each bar
[ "Get", "the", "number", "of", "pixels", "used", "for", "padding", "between", "bars", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/chart/baseGroupedStackTimeBarChart.js#L146-L153
53,662
SolarNetwork/solarnetwork-d3
src/chart/baseGroupedStackTimeBarChart.js
trimToXDomain
function trimToXDomain(array) { var start = 0, len = array.length, xDomainStart = parent.x.domain()[0]; // remove any data earlier than first full range while ( start < len ) { if ( array[start].date.getTime() >= xDomainStart.getTime() ) { break; } start += 1; } return (start === 0 ? array : array.slice(start)); }
javascript
function trimToXDomain(array) { var start = 0, len = array.length, xDomainStart = parent.x.domain()[0]; // remove any data earlier than first full range while ( start < len ) { if ( array[start].date.getTime() >= xDomainStart.getTime() ) { break; } start += 1; } return (start === 0 ? array : array.slice(start)); }
[ "function", "trimToXDomain", "(", "array", ")", "{", "var", "start", "=", "0", ",", "len", "=", "array", ".", "length", ",", "xDomainStart", "=", "parent", ".", "x", ".", "domain", "(", ")", "[", "0", "]", ";", "// remove any data earlier than first full range", "while", "(", "start", "<", "len", ")", "{", "if", "(", "array", "[", "start", "]", ".", "date", ".", "getTime", "(", ")", ">=", "xDomainStart", ".", "getTime", "(", ")", ")", "{", "break", ";", "}", "start", "+=", "1", ";", "}", "return", "(", "start", "===", "0", "?", "array", ":", "array", ".", "slice", "(", "start", ")", ")", ";", "}" ]
Remove data self falls outside the X domain. @param {Array} array The array to inspect. @returns {Array} Either a copy of the array with some elements removed, or the original array if nothing needed to be removed.
[ "Remove", "data", "self", "falls", "outside", "the", "X", "domain", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/chart/baseGroupedStackTimeBarChart.js#L162-L175
53,663
SolarNetwork/solarnetwork-d3
src/chart/baseGroupedStackTimeBarChart.js
drawHoverHighlightBars
function drawHoverHighlightBars(dataArray) { var hoverBar = parent.svgHoverRoot.selectAll('rect.highlightbar').data(dataArray); hoverBar.attr('x', valueX) .attr('width', xBar.rangeBand()); hoverBar.enter().append('rect') .attr('x', valueX) .attr('y', 0) .attr('height', parent.height) .attr('width', xBar.rangeBand()) .classed('highlightbar clickable', true); hoverBar.exit().remove(); }
javascript
function drawHoverHighlightBars(dataArray) { var hoverBar = parent.svgHoverRoot.selectAll('rect.highlightbar').data(dataArray); hoverBar.attr('x', valueX) .attr('width', xBar.rangeBand()); hoverBar.enter().append('rect') .attr('x', valueX) .attr('y', 0) .attr('height', parent.height) .attr('width', xBar.rangeBand()) .classed('highlightbar clickable', true); hoverBar.exit().remove(); }
[ "function", "drawHoverHighlightBars", "(", "dataArray", ")", "{", "var", "hoverBar", "=", "parent", ".", "svgHoverRoot", ".", "selectAll", "(", "'rect.highlightbar'", ")", ".", "data", "(", "dataArray", ")", ";", "hoverBar", ".", "attr", "(", "'x'", ",", "valueX", ")", ".", "attr", "(", "'width'", ",", "xBar", ".", "rangeBand", "(", ")", ")", ";", "hoverBar", ".", "enter", "(", ")", ".", "append", "(", "'rect'", ")", ".", "attr", "(", "'x'", ",", "valueX", ")", ".", "attr", "(", "'y'", ",", "0", ")", ".", "attr", "(", "'height'", ",", "parent", ".", "height", ")", ".", "attr", "(", "'width'", ",", "xBar", ".", "rangeBand", "(", ")", ")", ".", "classed", "(", "'highlightbar clickable'", ",", "true", ")", ";", "hoverBar", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Render a "highlight bar" over a set of bars. @param {array} dataArray An array of data elements for which to render highlight bars over. Pass an empty array to remove all bars.
[ "Render", "a", "highlight", "bar", "over", "a", "set", "of", "bars", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/chart/baseGroupedStackTimeBarChart.js#L291-L302
53,664
SolarNetwork/solarnetwork-d3
src/chart/baseGroupedStackTimeBarChart.js
drawSelection
function drawSelection(dataArray) { var firstItem = (dataArray && dataArray.length > 0 ? dataArray.slice(0, 1) : []), firstItemX = (dataArray && dataArray.length > 0 ? valueX(dataArray[0]) : 0), lastItemX = (dataArray && dataArray.length > 0 ? valueX(dataArray[dataArray.length - 1]) : 0), width = (lastItemX - firstItemX) + xBar.rangeBand(); var selectBar = parent.svgHoverRoot.selectAll('rect.selectionbar').data(firstItem); selectBar.attr('x', firstItemX) .attr('width', width); selectBar.enter().append('rect') .attr('x', firstItemX) .attr('y', 0) .attr('height', parent.height) .attr('width', width) .classed('selectionbar clickable', true); selectBar.exit().remove(); }
javascript
function drawSelection(dataArray) { var firstItem = (dataArray && dataArray.length > 0 ? dataArray.slice(0, 1) : []), firstItemX = (dataArray && dataArray.length > 0 ? valueX(dataArray[0]) : 0), lastItemX = (dataArray && dataArray.length > 0 ? valueX(dataArray[dataArray.length - 1]) : 0), width = (lastItemX - firstItemX) + xBar.rangeBand(); var selectBar = parent.svgHoverRoot.selectAll('rect.selectionbar').data(firstItem); selectBar.attr('x', firstItemX) .attr('width', width); selectBar.enter().append('rect') .attr('x', firstItemX) .attr('y', 0) .attr('height', parent.height) .attr('width', width) .classed('selectionbar clickable', true); selectBar.exit().remove(); }
[ "function", "drawSelection", "(", "dataArray", ")", "{", "var", "firstItem", "=", "(", "dataArray", "&&", "dataArray", ".", "length", ">", "0", "?", "dataArray", ".", "slice", "(", "0", ",", "1", ")", ":", "[", "]", ")", ",", "firstItemX", "=", "(", "dataArray", "&&", "dataArray", ".", "length", ">", "0", "?", "valueX", "(", "dataArray", "[", "0", "]", ")", ":", "0", ")", ",", "lastItemX", "=", "(", "dataArray", "&&", "dataArray", ".", "length", ">", "0", "?", "valueX", "(", "dataArray", "[", "dataArray", ".", "length", "-", "1", "]", ")", ":", "0", ")", ",", "width", "=", "(", "lastItemX", "-", "firstItemX", ")", "+", "xBar", ".", "rangeBand", "(", ")", ";", "var", "selectBar", "=", "parent", ".", "svgHoverRoot", ".", "selectAll", "(", "'rect.selectionbar'", ")", ".", "data", "(", "firstItem", ")", ";", "selectBar", ".", "attr", "(", "'x'", ",", "firstItemX", ")", ".", "attr", "(", "'width'", ",", "width", ")", ";", "selectBar", ".", "enter", "(", ")", ".", "append", "(", "'rect'", ")", ".", "attr", "(", "'x'", ",", "firstItemX", ")", ".", "attr", "(", "'y'", ",", "0", ")", ".", "attr", "(", "'height'", ",", "parent", ".", "height", ")", ".", "attr", "(", "'width'", ",", "width", ")", ".", "classed", "(", "'selectionbar clickable'", ",", "true", ")", ";", "selectBar", ".", "exit", "(", ")", ".", "remove", "(", ")", ";", "}" ]
Render a "selection" rect over a set of bars. @param {array} dataArray An array of data elements for which to render a selection over. Pass an empty array to remove the selection.
[ "Render", "a", "selection", "rect", "over", "a", "set", "of", "bars", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/chart/baseGroupedStackTimeBarChart.js#L310-L325
53,665
pagespace/pagespace
spec/unit/helpers/spies.js
mongooseify
function mongooseify(obj, returnValues) { applyMethods(obj); traverse(obj, (key, value) => { applyMethods(value); }); function applyMethods(value) { if(value && value.hasOwnProperty('_id')) { value.toObject = jasmine.createSpy('toObject'); value.toObject.and.returnValue(JSON.parse(JSON.stringify(value))); value.save = jasmine.createSpy('save'); value.save.and.returnValue(returnValues && returnValues.save ? returnValues.save : Promise.resolve({name : 'fooy'})); } } }
javascript
function mongooseify(obj, returnValues) { applyMethods(obj); traverse(obj, (key, value) => { applyMethods(value); }); function applyMethods(value) { if(value && value.hasOwnProperty('_id')) { value.toObject = jasmine.createSpy('toObject'); value.toObject.and.returnValue(JSON.parse(JSON.stringify(value))); value.save = jasmine.createSpy('save'); value.save.and.returnValue(returnValues && returnValues.save ? returnValues.save : Promise.resolve({name : 'fooy'})); } } }
[ "function", "mongooseify", "(", "obj", ",", "returnValues", ")", "{", "applyMethods", "(", "obj", ")", ";", "traverse", "(", "obj", ",", "(", "key", ",", "value", ")", "=>", "{", "applyMethods", "(", "value", ")", ";", "}", ")", ";", "function", "applyMethods", "(", "value", ")", "{", "if", "(", "value", "&&", "value", ".", "hasOwnProperty", "(", "'_id'", ")", ")", "{", "value", ".", "toObject", "=", "jasmine", ".", "createSpy", "(", "'toObject'", ")", ";", "value", ".", "toObject", ".", "and", ".", "returnValue", "(", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "value", ")", ")", ")", ";", "value", ".", "save", "=", "jasmine", ".", "createSpy", "(", "'save'", ")", ";", "value", ".", "save", ".", "and", ".", "returnValue", "(", "returnValues", "&&", "returnValues", ".", "save", "?", "returnValues", ".", "save", ":", "Promise", ".", "resolve", "(", "{", "name", ":", "'fooy'", "}", ")", ")", ";", "}", "}", "}" ]
called with every property and it's value
[ "called", "with", "every", "property", "and", "it", "s", "value" ]
943c45ddd9aaa4f3136e1ba4c2593aa0289daf43
https://github.com/pagespace/pagespace/blob/943c45ddd9aaa4f3136e1ba4c2593aa0289daf43/spec/unit/helpers/spies.js#L48-L64
53,666
BoogeeDoo/jockeyjs-bower
jockey.js
function(type, envelope, complete) { // We send the message by navigating the browser to a special URL. // The iOS library will catch the navigation, prevent the UIWebView // from continuing, and use the data in the URL to execute code // within the iOS app. var dispatcher = this; this.callbacks[envelope.id] = function() { complete(); delete dispatcher.callbacks[envelope.id]; }; var src = "jockey://" + type + "/" + envelope.id + "?" + encodeURIComponent(JSON.stringify(envelope)); var iframe = document.createElement("iframe"); iframe.setAttribute("src", src); document.documentElement.appendChild(iframe); iframe.parentNode.removeChild(iframe); iframe = null; }
javascript
function(type, envelope, complete) { // We send the message by navigating the browser to a special URL. // The iOS library will catch the navigation, prevent the UIWebView // from continuing, and use the data in the URL to execute code // within the iOS app. var dispatcher = this; this.callbacks[envelope.id] = function() { complete(); delete dispatcher.callbacks[envelope.id]; }; var src = "jockey://" + type + "/" + envelope.id + "?" + encodeURIComponent(JSON.stringify(envelope)); var iframe = document.createElement("iframe"); iframe.setAttribute("src", src); document.documentElement.appendChild(iframe); iframe.parentNode.removeChild(iframe); iframe = null; }
[ "function", "(", "type", ",", "envelope", ",", "complete", ")", "{", "// We send the message by navigating the browser to a special URL.", "// The iOS library will catch the navigation, prevent the UIWebView", "// from continuing, and use the data in the URL to execute code", "// within the iOS app.", "var", "dispatcher", "=", "this", ";", "this", ".", "callbacks", "[", "envelope", ".", "id", "]", "=", "function", "(", ")", "{", "complete", "(", ")", ";", "delete", "dispatcher", ".", "callbacks", "[", "envelope", ".", "id", "]", ";", "}", ";", "var", "src", "=", "\"jockey://\"", "+", "type", "+", "\"/\"", "+", "envelope", ".", "id", "+", "\"?\"", "+", "encodeURIComponent", "(", "JSON", ".", "stringify", "(", "envelope", ")", ")", ";", "var", "iframe", "=", "document", ".", "createElement", "(", "\"iframe\"", ")", ";", "iframe", ".", "setAttribute", "(", "\"src\"", ",", "src", ")", ";", "document", ".", "documentElement", ".", "appendChild", "(", "iframe", ")", ";", "iframe", ".", "parentNode", ".", "removeChild", "(", "iframe", ")", ";", "iframe", "=", "null", ";", "}" ]
`type` can either be "event" or "callback"
[ "type", "can", "either", "be", "event", "or", "callback" ]
614788cb2eb843d56009fe0c8e5940b02170d74c
https://github.com/BoogeeDoo/jockeyjs-bower/blob/614788cb2eb843d56009fe0c8e5940b02170d74c/jockey.js#L55-L75
53,667
BoogeeDoo/jockeyjs-bower
jockey.js
function(type, messageId, json) { var self = this; var listenerList = this.listeners[type] || []; var executedCount = 0; var complete = function() { executedCount += 1; if (executedCount >= listenerList.length) { self.dispatcher.sendCallback(messageId); } }; for (var index = 0; index < listenerList.length; index++) { var listener = listenerList[index]; // If it's a "sync" listener, we'll call the complete() function // after it has finished. If it's async, we expect it to call complete(). if (listener.length <= 1) { listener(json); complete(); } else { listener(json, complete); } } }
javascript
function(type, messageId, json) { var self = this; var listenerList = this.listeners[type] || []; var executedCount = 0; var complete = function() { executedCount += 1; if (executedCount >= listenerList.length) { self.dispatcher.sendCallback(messageId); } }; for (var index = 0; index < listenerList.length; index++) { var listener = listenerList[index]; // If it's a "sync" listener, we'll call the complete() function // after it has finished. If it's async, we expect it to call complete(). if (listener.length <= 1) { listener(json); complete(); } else { listener(json, complete); } } }
[ "function", "(", "type", ",", "messageId", ",", "json", ")", "{", "var", "self", "=", "this", ";", "var", "listenerList", "=", "this", ".", "listeners", "[", "type", "]", "||", "[", "]", ";", "var", "executedCount", "=", "0", ";", "var", "complete", "=", "function", "(", ")", "{", "executedCount", "+=", "1", ";", "if", "(", "executedCount", ">=", "listenerList", ".", "length", ")", "{", "self", ".", "dispatcher", ".", "sendCallback", "(", "messageId", ")", ";", "}", "}", ";", "for", "(", "var", "index", "=", "0", ";", "index", "<", "listenerList", ".", "length", ";", "index", "++", ")", "{", "var", "listener", "=", "listenerList", "[", "index", "]", ";", "// If it's a \"sync\" listener, we'll call the complete() function", "// after it has finished. If it's async, we expect it to call complete().", "if", "(", "listener", ".", "length", "<=", "1", ")", "{", "listener", "(", "json", ")", ";", "complete", "(", ")", ";", "}", "else", "{", "listener", "(", "json", ",", "complete", ")", ";", "}", "}", "}" ]
Called by the native application when events are sent to JS from the app. Will execute every function, FIFO order, that was attached to this event type.
[ "Called", "by", "the", "native", "application", "when", "events", "are", "sent", "to", "JS", "from", "the", "app", ".", "Will", "execute", "every", "function", "FIFO", "order", "that", "was", "attached", "to", "this", "event", "type", "." ]
614788cb2eb843d56009fe0c8e5940b02170d74c
https://github.com/BoogeeDoo/jockeyjs-bower/blob/614788cb2eb843d56009fe0c8e5940b02170d74c/jockey.js#L119-L147
53,668
flegall/haste-map-webpack-resolver
packages/haste-map-provider/index.js
buildHasteMap
function buildHasteMap(rootPath, prefix) { var prefix = prefix || 'haste-map-provider'; return new HasteMapBuilder({ "extensions": [ "snap", "js", "json", "jsx", "node" ], "ignorePattern": /SOME_COMPLEX_IGNORE_PATTERN_UNLIKELY_TO_HAPPEN/, "maxWorkers": 7, "name": prefix + "-" + rootPath.replace(/[\/\\]/g, '_'), "platforms": [ "ios", "android" ], "providesModuleNodeModules": [], "resetCache": false, "retainAllFiles": false, "roots": [ rootPath, ], "useWatchman": true, }).build(); }
javascript
function buildHasteMap(rootPath, prefix) { var prefix = prefix || 'haste-map-provider'; return new HasteMapBuilder({ "extensions": [ "snap", "js", "json", "jsx", "node" ], "ignorePattern": /SOME_COMPLEX_IGNORE_PATTERN_UNLIKELY_TO_HAPPEN/, "maxWorkers": 7, "name": prefix + "-" + rootPath.replace(/[\/\\]/g, '_'), "platforms": [ "ios", "android" ], "providesModuleNodeModules": [], "resetCache": false, "retainAllFiles": false, "roots": [ rootPath, ], "useWatchman": true, }).build(); }
[ "function", "buildHasteMap", "(", "rootPath", ",", "prefix", ")", "{", "var", "prefix", "=", "prefix", "||", "'haste-map-provider'", ";", "return", "new", "HasteMapBuilder", "(", "{", "\"extensions\"", ":", "[", "\"snap\"", ",", "\"js\"", ",", "\"json\"", ",", "\"jsx\"", ",", "\"node\"", "]", ",", "\"ignorePattern\"", ":", "/", "SOME_COMPLEX_IGNORE_PATTERN_UNLIKELY_TO_HAPPEN", "/", ",", "\"maxWorkers\"", ":", "7", ",", "\"name\"", ":", "prefix", "+", "\"-\"", "+", "rootPath", ".", "replace", "(", "/", "[\\/\\\\]", "/", "g", ",", "'_'", ")", ",", "\"platforms\"", ":", "[", "\"ios\"", ",", "\"android\"", "]", ",", "\"providesModuleNodeModules\"", ":", "[", "]", ",", "\"resetCache\"", ":", "false", ",", "\"retainAllFiles\"", ":", "false", ",", "\"roots\"", ":", "[", "rootPath", ",", "]", ",", "\"useWatchman\"", ":", "true", ",", "}", ")", ".", "build", "(", ")", ";", "}" ]
Builds a Haste Map @param {string} rootPath - The rootPath to search sources for @param {string} prefix - The prefix for the haste map file (optional) @returns {Promise} A promise of the Haste Map
[ "Builds", "a", "Haste", "Map" ]
4ba928291c518b24596c3384b61b75fb14f433b7
https://github.com/flegall/haste-map-webpack-resolver/blob/4ba928291c518b24596c3384b61b75fb14f433b7/packages/haste-map-provider/index.js#L10-L35
53,669
pulsecat/cexio
cexio.js
function(to_clean) { _.map(to_clean, function(value, key, to_clean) { if (value === undefined) { delete to_clean[key]; } }); return to_clean; }
javascript
function(to_clean) { _.map(to_clean, function(value, key, to_clean) { if (value === undefined) { delete to_clean[key]; } }); return to_clean; }
[ "function", "(", "to_clean", ")", "{", "_", ".", "map", "(", "to_clean", ",", "function", "(", "value", ",", "key", ",", "to_clean", ")", "{", "if", "(", "value", "===", "undefined", ")", "{", "delete", "to_clean", "[", "key", "]", ";", "}", "}", ")", ";", "return", "to_clean", ";", "}" ]
compact for objects
[ "compact", "for", "objects" ]
24207a71779775574405dfd332b9a09f2d9d2bc8
https://github.com/pulsecat/cexio/blob/24207a71779775574405dfd332b9a09f2d9d2bc8/cexio.js#L8-L15
53,670
aledbf/deis-api
lib/apps.js
create
function create(appName, callback) { commons.post(format('/%s/apps/', deis.version), { id: appName }, callback); }
javascript
function create(appName, callback) { commons.post(format('/%s/apps/', deis.version), { id: appName }, callback); }
[ "function", "create", "(", "appName", ",", "callback", ")", "{", "commons", ".", "post", "(", "format", "(", "'/%s/apps/'", ",", "deis", ".", "version", ")", ",", "{", "id", ":", "appName", "}", ",", "callback", ")", ";", "}" ]
Create a new application
[ "Create", "a", "new", "application" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L11-L15
53,671
aledbf/deis-api
lib/apps.js
list
function list(pageSize, callback) { var limit = 100; if (!isFunction(pageSize)) { limit = pageSize; }else { callback = pageSize; } commons.get(format('/%s/apps?limit=%s', deis.version, limit), callback); }
javascript
function list(pageSize, callback) { var limit = 100; if (!isFunction(pageSize)) { limit = pageSize; }else { callback = pageSize; } commons.get(format('/%s/apps?limit=%s', deis.version, limit), callback); }
[ "function", "list", "(", "pageSize", ",", "callback", ")", "{", "var", "limit", "=", "100", ";", "if", "(", "!", "isFunction", "(", "pageSize", ")", ")", "{", "limit", "=", "pageSize", ";", "}", "else", "{", "callback", "=", "pageSize", ";", "}", "commons", ".", "get", "(", "format", "(", "'/%s/apps?limit=%s'", ",", "deis", ".", "version", ",", "limit", ")", ",", "callback", ")", ";", "}" ]
List accessible applications
[ "List", "accessible", "applications" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L20-L28
53,672
aledbf/deis-api
lib/apps.js
info
function info(appName, callback) { commons.get(format('/%s/apps/%s/', deis.version, appName), callback); }
javascript
function info(appName, callback) { commons.get(format('/%s/apps/%s/', deis.version, appName), callback); }
[ "function", "info", "(", "appName", ",", "callback", ")", "{", "commons", ".", "get", "(", "format", "(", "'/%s/apps/%s/'", ",", "deis", ".", "version", ",", "appName", ")", ",", "callback", ")", ";", "}" ]
View info about an application
[ "View", "info", "about", "an", "application" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L33-L35
53,673
aledbf/deis-api
lib/apps.js
logs
function logs(appName, callback) { commons.get(format('/%s/apps/%s/logs/', deis.version, appName), callback); }
javascript
function logs(appName, callback) { commons.get(format('/%s/apps/%s/logs/', deis.version, appName), callback); }
[ "function", "logs", "(", "appName", ",", "callback", ")", "{", "commons", ".", "get", "(", "format", "(", "'/%s/apps/%s/logs/'", ",", "deis", ".", "version", ",", "appName", ")", ",", "callback", ")", ";", "}" ]
View aggregated application logs
[ "View", "aggregated", "application", "logs" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L40-L42
53,674
aledbf/deis-api
lib/apps.js
run
function run(appName, command, callback) { commons.get(format('/%s/apps/%s/run/', deis.version, appName), callback); }
javascript
function run(appName, command, callback) { commons.get(format('/%s/apps/%s/run/', deis.version, appName), callback); }
[ "function", "run", "(", "appName", ",", "command", ",", "callback", ")", "{", "commons", ".", "get", "(", "format", "(", "'/%s/apps/%s/run/'", ",", "deis", ".", "version", ",", "appName", ")", ",", "callback", ")", ";", "}" ]
Run a command in an ephemeral app container
[ "Run", "a", "command", "in", "an", "ephemeral", "app", "container" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L47-L49
53,675
aledbf/deis-api
lib/apps.js
destroy
function destroy(appName, callback) { commons.del(format('/%s/apps/%s/', deis.version, appName), callback); }
javascript
function destroy(appName, callback) { commons.del(format('/%s/apps/%s/', deis.version, appName), callback); }
[ "function", "destroy", "(", "appName", ",", "callback", ")", "{", "commons", ".", "del", "(", "format", "(", "'/%s/apps/%s/'", ",", "deis", ".", "version", ",", "appName", ")", ",", "callback", ")", ";", "}" ]
Destroy an application
[ "Destroy", "an", "application" ]
f0833789998032b11221a3a617bb566ade1fcc13
https://github.com/aledbf/deis-api/blob/f0833789998032b11221a3a617bb566ade1fcc13/lib/apps.js#L54-L56
53,676
chrishayesmu/DubBotBase
main.js
start
function start(basedir, connectionCompleteCallback) { var defaultConfig = require("./config/defaults.json"); var config = Config.create(basedir, defaultConfig); var globalObject = { config: config }; var loginCompleteCallback = function(bot) { globalObject.bot = bot; bot.connect(config.DubBotBase.roomName); LOG.info("Connect request sent. Waiting 5 seconds for the connection to be established."); var innerConnectionCompleteCallback = function() { StateTracker.init(globalObject, function() { // Connect before registering anything, because StateTracker depends on being connected var commands = _registerCommands(basedir, globalObject); var eventListeners = _registerEventListeners(basedir, globalObject); // Hook our own event listener in to chat, for the command framework bot.on(Event.CHAT, _createCommandHandler(commands)); if (connectionCompleteCallback) { connectionCompleteCallback(globalObject); } }); }; setTimeout(innerConnectionCompleteCallback, 5000); }; new Dubtrack.Bot({ username: config.DubBotBase.botEmail, password: config.DubBotBase.botPassword }, globalObject, loginCompleteCallback); return globalObject; }
javascript
function start(basedir, connectionCompleteCallback) { var defaultConfig = require("./config/defaults.json"); var config = Config.create(basedir, defaultConfig); var globalObject = { config: config }; var loginCompleteCallback = function(bot) { globalObject.bot = bot; bot.connect(config.DubBotBase.roomName); LOG.info("Connect request sent. Waiting 5 seconds for the connection to be established."); var innerConnectionCompleteCallback = function() { StateTracker.init(globalObject, function() { // Connect before registering anything, because StateTracker depends on being connected var commands = _registerCommands(basedir, globalObject); var eventListeners = _registerEventListeners(basedir, globalObject); // Hook our own event listener in to chat, for the command framework bot.on(Event.CHAT, _createCommandHandler(commands)); if (connectionCompleteCallback) { connectionCompleteCallback(globalObject); } }); }; setTimeout(innerConnectionCompleteCallback, 5000); }; new Dubtrack.Bot({ username: config.DubBotBase.botEmail, password: config.DubBotBase.botPassword }, globalObject, loginCompleteCallback); return globalObject; }
[ "function", "start", "(", "basedir", ",", "connectionCompleteCallback", ")", "{", "var", "defaultConfig", "=", "require", "(", "\"./config/defaults.json\"", ")", ";", "var", "config", "=", "Config", ".", "create", "(", "basedir", ",", "defaultConfig", ")", ";", "var", "globalObject", "=", "{", "config", ":", "config", "}", ";", "var", "loginCompleteCallback", "=", "function", "(", "bot", ")", "{", "globalObject", ".", "bot", "=", "bot", ";", "bot", ".", "connect", "(", "config", ".", "DubBotBase", ".", "roomName", ")", ";", "LOG", ".", "info", "(", "\"Connect request sent. Waiting 5 seconds for the connection to be established.\"", ")", ";", "var", "innerConnectionCompleteCallback", "=", "function", "(", ")", "{", "StateTracker", ".", "init", "(", "globalObject", ",", "function", "(", ")", "{", "// Connect before registering anything, because StateTracker depends on being connected", "var", "commands", "=", "_registerCommands", "(", "basedir", ",", "globalObject", ")", ";", "var", "eventListeners", "=", "_registerEventListeners", "(", "basedir", ",", "globalObject", ")", ";", "// Hook our own event listener in to chat, for the command framework", "bot", ".", "on", "(", "Event", ".", "CHAT", ",", "_createCommandHandler", "(", "commands", ")", ")", ";", "if", "(", "connectionCompleteCallback", ")", "{", "connectionCompleteCallback", "(", "globalObject", ")", ";", "}", "}", ")", ";", "}", ";", "setTimeout", "(", "innerConnectionCompleteCallback", ",", "5000", ")", ";", "}", ";", "new", "Dubtrack", ".", "Bot", "(", "{", "username", ":", "config", ".", "DubBotBase", ".", "botEmail", ",", "password", ":", "config", ".", "DubBotBase", ".", "botPassword", "}", ",", "globalObject", ",", "loginCompleteCallback", ")", ";", "return", "globalObject", ";", "}" ]
Starts up the bot, registering all commands and event listeners. @param {string} basedir - The base directory containing the commands/ and event_listeners/ subdirectories @param {function} connectionCompleteCallback - A function to be called once the bot has connected to the room and is ready to use @returns {object} The global object which contains a reference to the bot
[ "Starts", "up", "the", "bot", "registering", "all", "commands", "and", "event", "listeners", "." ]
0e4b5e65531c23293d22ac766850c802b1266e48
https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/main.js#L24-L59
53,677
chrishayesmu/DubBotBase
main.js
_createCommandHandler
function _createCommandHandler(commands) { return function(chatEvent, globalObject) { if (!chatEvent.command) { return; } var commandName = chatEvent.command; if (!globalObject.config.DubBotBase.areCommandsCaseSensitive) { commandName = commandName.toLowerCase(); } for (var i = 0; i < commands.length; i++) { var command = commands[i]; if (command.triggers.indexOf(commandName) >= 0) { if (command.minimumRole && chatEvent.userRole.level < command.minimumRole.level) { // user doesn't have sufficient permissions; notify the command module if possible if (command.insufficientPermissionsHandler) { command.insufficientPermissionsHandler.call(command.context, chatEvent, globalObject); } continue; } command.handler.call(command.context, chatEvent, globalObject); } } }; }
javascript
function _createCommandHandler(commands) { return function(chatEvent, globalObject) { if (!chatEvent.command) { return; } var commandName = chatEvent.command; if (!globalObject.config.DubBotBase.areCommandsCaseSensitive) { commandName = commandName.toLowerCase(); } for (var i = 0; i < commands.length; i++) { var command = commands[i]; if (command.triggers.indexOf(commandName) >= 0) { if (command.minimumRole && chatEvent.userRole.level < command.minimumRole.level) { // user doesn't have sufficient permissions; notify the command module if possible if (command.insufficientPermissionsHandler) { command.insufficientPermissionsHandler.call(command.context, chatEvent, globalObject); } continue; } command.handler.call(command.context, chatEvent, globalObject); } } }; }
[ "function", "_createCommandHandler", "(", "commands", ")", "{", "return", "function", "(", "chatEvent", ",", "globalObject", ")", "{", "if", "(", "!", "chatEvent", ".", "command", ")", "{", "return", ";", "}", "var", "commandName", "=", "chatEvent", ".", "command", ";", "if", "(", "!", "globalObject", ".", "config", ".", "DubBotBase", ".", "areCommandsCaseSensitive", ")", "{", "commandName", "=", "commandName", ".", "toLowerCase", "(", ")", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "commands", ".", "length", ";", "i", "++", ")", "{", "var", "command", "=", "commands", "[", "i", "]", ";", "if", "(", "command", ".", "triggers", ".", "indexOf", "(", "commandName", ")", ">=", "0", ")", "{", "if", "(", "command", ".", "minimumRole", "&&", "chatEvent", ".", "userRole", ".", "level", "<", "command", ".", "minimumRole", ".", "level", ")", "{", "// user doesn't have sufficient permissions; notify the command module if possible", "if", "(", "command", ".", "insufficientPermissionsHandler", ")", "{", "command", ".", "insufficientPermissionsHandler", ".", "call", "(", "command", ".", "context", ",", "chatEvent", ",", "globalObject", ")", ";", "}", "continue", ";", "}", "command", ".", "handler", ".", "call", "(", "command", ".", "context", ",", "chatEvent", ",", "globalObject", ")", ";", "}", "}", "}", ";", "}" ]
Creates a handler for the CHAT_COMMAND event which will distribute chat commands to the appropriate registered handlers. @param {array} commands - All of the registered command handlers @returns {function} An event handler
[ "Creates", "a", "handler", "for", "the", "CHAT_COMMAND", "event", "which", "will", "distribute", "chat", "commands", "to", "the", "appropriate", "registered", "handlers", "." ]
0e4b5e65531c23293d22ac766850c802b1266e48
https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/main.js#L68-L98
53,678
chrishayesmu/DubBotBase
main.js
_registerCommands
function _registerCommands(basedir, globalObject) { var commandsDir = path.resolve(basedir, "commands"); var files; try { files = Utils.getAllFilePathsUnderDirectory(commandsDir); LOG.info("Found the following potential command files: {}", files); } catch (e) { LOG.error("Unable to register commands from the base directory '{}'. Error: {}", commandsDir, e); return; } var commands = []; for (var i = 0; i < files.length; i++) { var filePath = files[i]; if (filePath.lastIndexOf(".js") !== filePath.length - 3) { LOG.info("File {} doesn't appear to be a JS module. Ignoring.", filePath); continue; } var module = require(filePath); if (!module.triggers || !module.handler) { LOG.warn("Found a module at {} but it doesn't appear to be a command handler. Ignoring.", filePath); continue; } if (typeof module.init === "function") { module.init(globalObject); } commands.push(module); LOG.info("Registered command from file {}", filePath); } return commands; }
javascript
function _registerCommands(basedir, globalObject) { var commandsDir = path.resolve(basedir, "commands"); var files; try { files = Utils.getAllFilePathsUnderDirectory(commandsDir); LOG.info("Found the following potential command files: {}", files); } catch (e) { LOG.error("Unable to register commands from the base directory '{}'. Error: {}", commandsDir, e); return; } var commands = []; for (var i = 0; i < files.length; i++) { var filePath = files[i]; if (filePath.lastIndexOf(".js") !== filePath.length - 3) { LOG.info("File {} doesn't appear to be a JS module. Ignoring.", filePath); continue; } var module = require(filePath); if (!module.triggers || !module.handler) { LOG.warn("Found a module at {} but it doesn't appear to be a command handler. Ignoring.", filePath); continue; } if (typeof module.init === "function") { module.init(globalObject); } commands.push(module); LOG.info("Registered command from file {}", filePath); } return commands; }
[ "function", "_registerCommands", "(", "basedir", ",", "globalObject", ")", "{", "var", "commandsDir", "=", "path", ".", "resolve", "(", "basedir", ",", "\"commands\"", ")", ";", "var", "files", ";", "try", "{", "files", "=", "Utils", ".", "getAllFilePathsUnderDirectory", "(", "commandsDir", ")", ";", "LOG", ".", "info", "(", "\"Found the following potential command files: {}\"", ",", "files", ")", ";", "}", "catch", "(", "e", ")", "{", "LOG", ".", "error", "(", "\"Unable to register commands from the base directory '{}'. Error: {}\"", ",", "commandsDir", ",", "e", ")", ";", "return", ";", "}", "var", "commands", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "files", ".", "length", ";", "i", "++", ")", "{", "var", "filePath", "=", "files", "[", "i", "]", ";", "if", "(", "filePath", ".", "lastIndexOf", "(", "\".js\"", ")", "!==", "filePath", ".", "length", "-", "3", ")", "{", "LOG", ".", "info", "(", "\"File {} doesn't appear to be a JS module. Ignoring.\"", ",", "filePath", ")", ";", "continue", ";", "}", "var", "module", "=", "require", "(", "filePath", ")", ";", "if", "(", "!", "module", ".", "triggers", "||", "!", "module", ".", "handler", ")", "{", "LOG", ".", "warn", "(", "\"Found a module at {} but it doesn't appear to be a command handler. Ignoring.\"", ",", "filePath", ")", ";", "continue", ";", "}", "if", "(", "typeof", "module", ".", "init", "===", "\"function\"", ")", "{", "module", ".", "init", "(", "globalObject", ")", ";", "}", "commands", ".", "push", "(", "module", ")", ";", "LOG", ".", "info", "(", "\"Registered command from file {}\"", ",", "filePath", ")", ";", "}", "return", "commands", ";", "}" ]
Registers all of the eligible files from the commands directory as commands with the bot. @param {string} basedir - The base directory which holds the commands directory @param {object} bot - An instance of DubBotBase.Bot
[ "Registers", "all", "of", "the", "eligible", "files", "from", "the", "commands", "directory", "as", "commands", "with", "the", "bot", "." ]
0e4b5e65531c23293d22ac766850c802b1266e48
https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/main.js#L107-L144
53,679
chrishayesmu/DubBotBase
main.js
_registerEventListeners
function _registerEventListeners(basedir, globalObject) { var bot = globalObject.bot; var eventListenerDir = path.resolve(basedir, "event_listeners"); var files; try { files = Utils.getAllFilePathsUnderDirectory(eventListenerDir); LOG.info("Found the following potential event listener files: {}", files); } catch (e) { LOG.error("Unable to register event listeners from the base directory '{}'. Error: {}", eventListenerDir, e); return; } var listeners = []; for (var i = 0; i < files.length; i++) { var filePath = files[i]; if (filePath.lastIndexOf(".js") !== filePath.length - 3) { LOG.info("File {} doesn't appear to be a JS module. Ignoring.", filePath); continue; } var module = require(filePath); /* Check each event key and look for an export in one of two forms: * * 1) EVENT_KEY : some_function * 2) EVENT_KEY : { handler: some_function, context: some_object } * * Context is optional even in the second form, but a function is always required. */ var eventHandlerFound = false; for (var eventKey in Event) { var eventValue = Event[eventKey]; var eventHandler = null; var handlerContext = null; var error = null; if (!module[eventValue]) { continue; } if (typeof module[eventValue] === "function") { eventHandler = module[eventValue]; } else if (typeof module[eventValue] === "object") { if (typeof module[eventValue].handler !== "function") { LOG.error("An error occurred while reading event listener from file {}", filePath); LOG.error("Event listener for event '{}' has an object type, but the 'handler' property does not refer to a function", eventKey); throw new Error("An error occurred while initializing event listeners. Check your logfile (or just stdout) for more details."); } eventHandler = module[eventValue].handler; handlerContext = module[eventValue].context; } else { LOG.warn("Found what looks like an event listener, but it's not an object or a function. Event: {}, from file: {}", eventKey, filePath); continue; } eventHandlerFound = true; bot.on(eventValue, eventHandler, handlerContext); } if (!eventHandlerFound) { LOG.warn("Found a module at {} but it doesn't appear to be an event handler. Ignoring.", filePath); continue; } if (typeof module.init === "function") { LOG.info("Calling init for module at {}", filePath); module.init(globalObject); } listeners.push(module); LOG.info("Registered event listener from file {}", filePath); } return listeners; }
javascript
function _registerEventListeners(basedir, globalObject) { var bot = globalObject.bot; var eventListenerDir = path.resolve(basedir, "event_listeners"); var files; try { files = Utils.getAllFilePathsUnderDirectory(eventListenerDir); LOG.info("Found the following potential event listener files: {}", files); } catch (e) { LOG.error("Unable to register event listeners from the base directory '{}'. Error: {}", eventListenerDir, e); return; } var listeners = []; for (var i = 0; i < files.length; i++) { var filePath = files[i]; if (filePath.lastIndexOf(".js") !== filePath.length - 3) { LOG.info("File {} doesn't appear to be a JS module. Ignoring.", filePath); continue; } var module = require(filePath); /* Check each event key and look for an export in one of two forms: * * 1) EVENT_KEY : some_function * 2) EVENT_KEY : { handler: some_function, context: some_object } * * Context is optional even in the second form, but a function is always required. */ var eventHandlerFound = false; for (var eventKey in Event) { var eventValue = Event[eventKey]; var eventHandler = null; var handlerContext = null; var error = null; if (!module[eventValue]) { continue; } if (typeof module[eventValue] === "function") { eventHandler = module[eventValue]; } else if (typeof module[eventValue] === "object") { if (typeof module[eventValue].handler !== "function") { LOG.error("An error occurred while reading event listener from file {}", filePath); LOG.error("Event listener for event '{}' has an object type, but the 'handler' property does not refer to a function", eventKey); throw new Error("An error occurred while initializing event listeners. Check your logfile (or just stdout) for more details."); } eventHandler = module[eventValue].handler; handlerContext = module[eventValue].context; } else { LOG.warn("Found what looks like an event listener, but it's not an object or a function. Event: {}, from file: {}", eventKey, filePath); continue; } eventHandlerFound = true; bot.on(eventValue, eventHandler, handlerContext); } if (!eventHandlerFound) { LOG.warn("Found a module at {} but it doesn't appear to be an event handler. Ignoring.", filePath); continue; } if (typeof module.init === "function") { LOG.info("Calling init for module at {}", filePath); module.init(globalObject); } listeners.push(module); LOG.info("Registered event listener from file {}", filePath); } return listeners; }
[ "function", "_registerEventListeners", "(", "basedir", ",", "globalObject", ")", "{", "var", "bot", "=", "globalObject", ".", "bot", ";", "var", "eventListenerDir", "=", "path", ".", "resolve", "(", "basedir", ",", "\"event_listeners\"", ")", ";", "var", "files", ";", "try", "{", "files", "=", "Utils", ".", "getAllFilePathsUnderDirectory", "(", "eventListenerDir", ")", ";", "LOG", ".", "info", "(", "\"Found the following potential event listener files: {}\"", ",", "files", ")", ";", "}", "catch", "(", "e", ")", "{", "LOG", ".", "error", "(", "\"Unable to register event listeners from the base directory '{}'. Error: {}\"", ",", "eventListenerDir", ",", "e", ")", ";", "return", ";", "}", "var", "listeners", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "files", ".", "length", ";", "i", "++", ")", "{", "var", "filePath", "=", "files", "[", "i", "]", ";", "if", "(", "filePath", ".", "lastIndexOf", "(", "\".js\"", ")", "!==", "filePath", ".", "length", "-", "3", ")", "{", "LOG", ".", "info", "(", "\"File {} doesn't appear to be a JS module. Ignoring.\"", ",", "filePath", ")", ";", "continue", ";", "}", "var", "module", "=", "require", "(", "filePath", ")", ";", "/* Check each event key and look for an export in one of two forms:\n *\n * 1) EVENT_KEY : some_function\n * 2) EVENT_KEY : { handler: some_function, context: some_object }\n *\n * Context is optional even in the second form, but a function is always required.\n */", "var", "eventHandlerFound", "=", "false", ";", "for", "(", "var", "eventKey", "in", "Event", ")", "{", "var", "eventValue", "=", "Event", "[", "eventKey", "]", ";", "var", "eventHandler", "=", "null", ";", "var", "handlerContext", "=", "null", ";", "var", "error", "=", "null", ";", "if", "(", "!", "module", "[", "eventValue", "]", ")", "{", "continue", ";", "}", "if", "(", "typeof", "module", "[", "eventValue", "]", "===", "\"function\"", ")", "{", "eventHandler", "=", "module", "[", "eventValue", "]", ";", "}", "else", "if", "(", "typeof", "module", "[", "eventValue", "]", "===", "\"object\"", ")", "{", "if", "(", "typeof", "module", "[", "eventValue", "]", ".", "handler", "!==", "\"function\"", ")", "{", "LOG", ".", "error", "(", "\"An error occurred while reading event listener from file {}\"", ",", "filePath", ")", ";", "LOG", ".", "error", "(", "\"Event listener for event '{}' has an object type, but the 'handler' property does not refer to a function\"", ",", "eventKey", ")", ";", "throw", "new", "Error", "(", "\"An error occurred while initializing event listeners. Check your logfile (or just stdout) for more details.\"", ")", ";", "}", "eventHandler", "=", "module", "[", "eventValue", "]", ".", "handler", ";", "handlerContext", "=", "module", "[", "eventValue", "]", ".", "context", ";", "}", "else", "{", "LOG", ".", "warn", "(", "\"Found what looks like an event listener, but it's not an object or a function. Event: {}, from file: {}\"", ",", "eventKey", ",", "filePath", ")", ";", "continue", ";", "}", "eventHandlerFound", "=", "true", ";", "bot", ".", "on", "(", "eventValue", ",", "eventHandler", ",", "handlerContext", ")", ";", "}", "if", "(", "!", "eventHandlerFound", ")", "{", "LOG", ".", "warn", "(", "\"Found a module at {} but it doesn't appear to be an event handler. Ignoring.\"", ",", "filePath", ")", ";", "continue", ";", "}", "if", "(", "typeof", "module", ".", "init", "===", "\"function\"", ")", "{", "LOG", ".", "info", "(", "\"Calling init for module at {}\"", ",", "filePath", ")", ";", "module", ".", "init", "(", "globalObject", ")", ";", "}", "listeners", ".", "push", "(", "module", ")", ";", "LOG", ".", "info", "(", "\"Registered event listener from file {}\"", ",", "filePath", ")", ";", "}", "return", "listeners", ";", "}" ]
Registers all of the eligible files from the event_listeners directory as event listeners with the bot. @param {string} basedir - The base directory which holds the event_listeners directory @param {object} bot - An instance of DubBotBase.Bot
[ "Registers", "all", "of", "the", "eligible", "files", "from", "the", "event_listeners", "directory", "as", "event", "listeners", "with", "the", "bot", "." ]
0e4b5e65531c23293d22ac766850c802b1266e48
https://github.com/chrishayesmu/DubBotBase/blob/0e4b5e65531c23293d22ac766850c802b1266e48/main.js#L153-L232
53,680
jfseb/mgnlq_model
js/model/model.js
getMongoHandle
function getMongoHandle(mongoose) { var res = { mongoose: mongoose, modelDocs: {}, modelESchemas: {}, mongoMaps: {} }; var modelES = Schemaload.getExtendedSchemaModel(mongoose); return modelES.distinct('modelname').then((modelnames) => { debuglog(() => 'here distinct modelnames ' + JSON.stringify(modelnames)); return Promise.all(modelnames.map(function (modelname) { debuglog(() => 'creating tripel for ' + modelname); return Promise.all([Schemaload.getExtendSchemaDocFromDB(mongoose, modelname), Schemaload.makeModelFromDB(mongoose, modelname), Schemaload.getModelDocFromDB(mongoose, modelname)]).then((value) => { debuglog(() => 'attempting to load ' + modelname + 'to create mongomap'); var [extendedSchema, model, modelDoc] = value; res.modelESchemas[modelname] = extendedSchema; res.modelDocs[modelname] = modelDoc; res.mongoMaps[modelname] = MongoMap.makeMongoMap(modelDoc, extendedSchema); debuglog(() => 'created mongomap for ' + modelname); }); })); }).then(() => { return res; }); //var modelDoc = Schemaload.getExtendedDocModel(mongoose); //res.modelDocs[ISchema.MongoNLQ.MODELNAME_METAMODELS] = modelDoc; //return Promise.resolve(res); }
javascript
function getMongoHandle(mongoose) { var res = { mongoose: mongoose, modelDocs: {}, modelESchemas: {}, mongoMaps: {} }; var modelES = Schemaload.getExtendedSchemaModel(mongoose); return modelES.distinct('modelname').then((modelnames) => { debuglog(() => 'here distinct modelnames ' + JSON.stringify(modelnames)); return Promise.all(modelnames.map(function (modelname) { debuglog(() => 'creating tripel for ' + modelname); return Promise.all([Schemaload.getExtendSchemaDocFromDB(mongoose, modelname), Schemaload.makeModelFromDB(mongoose, modelname), Schemaload.getModelDocFromDB(mongoose, modelname)]).then((value) => { debuglog(() => 'attempting to load ' + modelname + 'to create mongomap'); var [extendedSchema, model, modelDoc] = value; res.modelESchemas[modelname] = extendedSchema; res.modelDocs[modelname] = modelDoc; res.mongoMaps[modelname] = MongoMap.makeMongoMap(modelDoc, extendedSchema); debuglog(() => 'created mongomap for ' + modelname); }); })); }).then(() => { return res; }); //var modelDoc = Schemaload.getExtendedDocModel(mongoose); //res.modelDocs[ISchema.MongoNLQ.MODELNAME_METAMODELS] = modelDoc; //return Promise.resolve(res); }
[ "function", "getMongoHandle", "(", "mongoose", ")", "{", "var", "res", "=", "{", "mongoose", ":", "mongoose", ",", "modelDocs", ":", "{", "}", ",", "modelESchemas", ":", "{", "}", ",", "mongoMaps", ":", "{", "}", "}", ";", "var", "modelES", "=", "Schemaload", ".", "getExtendedSchemaModel", "(", "mongoose", ")", ";", "return", "modelES", ".", "distinct", "(", "'modelname'", ")", ".", "then", "(", "(", "modelnames", ")", "=>", "{", "debuglog", "(", "(", ")", "=>", "'here distinct modelnames '", "+", "JSON", ".", "stringify", "(", "modelnames", ")", ")", ";", "return", "Promise", ".", "all", "(", "modelnames", ".", "map", "(", "function", "(", "modelname", ")", "{", "debuglog", "(", "(", ")", "=>", "'creating tripel for '", "+", "modelname", ")", ";", "return", "Promise", ".", "all", "(", "[", "Schemaload", ".", "getExtendSchemaDocFromDB", "(", "mongoose", ",", "modelname", ")", ",", "Schemaload", ".", "makeModelFromDB", "(", "mongoose", ",", "modelname", ")", ",", "Schemaload", ".", "getModelDocFromDB", "(", "mongoose", ",", "modelname", ")", "]", ")", ".", "then", "(", "(", "value", ")", "=>", "{", "debuglog", "(", "(", ")", "=>", "'attempting to load '", "+", "modelname", "+", "'to create mongomap'", ")", ";", "var", "[", "extendedSchema", ",", "model", ",", "modelDoc", "]", "=", "value", ";", "res", ".", "modelESchemas", "[", "modelname", "]", "=", "extendedSchema", ";", "res", ".", "modelDocs", "[", "modelname", "]", "=", "modelDoc", ";", "res", ".", "mongoMaps", "[", "modelname", "]", "=", "MongoMap", ".", "makeMongoMap", "(", "modelDoc", ",", "extendedSchema", ")", ";", "debuglog", "(", "(", ")", "=>", "'created mongomap for '", "+", "modelname", ")", ";", "}", ")", ";", "}", ")", ")", ";", "}", ")", ".", "then", "(", "(", ")", "=>", "{", "return", "res", ";", "}", ")", ";", "//var modelDoc = Schemaload.getExtendedDocModel(mongoose);", "//res.modelDocs[ISchema.MongoNLQ.MODELNAME_METAMODELS] = modelDoc;", "//return Promise.resolve(res);", "}" ]
returns when all models are loaded and all modeldocs are made @param mongoose
[ "returns", "when", "all", "models", "are", "loaded", "and", "all", "modeldocs", "are", "made" ]
be1be4406b05718d666d6d0f712c9cadb5169f2c
https://github.com/jfseb/mgnlq_model/blob/be1be4406b05718d666d6d0f712c9cadb5169f2c/js/model/model.js#L40-L69
53,681
jfseb/mgnlq_model
js/model/model.js
getDomainsForBitField
function getDomainsForBitField(oModel, bitfield) { return oModel.domains.filter(domain => (getDomainBitIndex(domain, oModel) & bitfield)); }
javascript
function getDomainsForBitField(oModel, bitfield) { return oModel.domains.filter(domain => (getDomainBitIndex(domain, oModel) & bitfield)); }
[ "function", "getDomainsForBitField", "(", "oModel", ",", "bitfield", ")", "{", "return", "oModel", ".", "domains", ".", "filter", "(", "domain", "=>", "(", "getDomainBitIndex", "(", "domain", ",", "oModel", ")", "&", "bitfield", ")", ")", ";", "}" ]
Given a bitfield, return an unsorted set of domains matching present bits @param oModel @param bitfield
[ "Given", "a", "bitfield", "return", "an", "unsorted", "set", "of", "domains", "matching", "present", "bits" ]
be1be4406b05718d666d6d0f712c9cadb5169f2c
https://github.com/jfseb/mgnlq_model/blob/be1be4406b05718d666d6d0f712c9cadb5169f2c/js/model/model.js#L525-L527
53,682
jfseb/mgnlq_model
js/model/model.js
loadModels
function loadModels(mongoose, modelPath) { if (mongoose === undefined) { throw new Error('expect a mongoose handle to be passed'); } return getMongoHandle(mongoose).then((modelHandle) => { debuglog(`got a mongo handle for ${modelPath}`); return _loadModelsFull(modelHandle, modelPath); }); }
javascript
function loadModels(mongoose, modelPath) { if (mongoose === undefined) { throw new Error('expect a mongoose handle to be passed'); } return getMongoHandle(mongoose).then((modelHandle) => { debuglog(`got a mongo handle for ${modelPath}`); return _loadModelsFull(modelHandle, modelPath); }); }
[ "function", "loadModels", "(", "mongoose", ",", "modelPath", ")", "{", "if", "(", "mongoose", "===", "undefined", ")", "{", "throw", "new", "Error", "(", "'expect a mongoose handle to be passed'", ")", ";", "}", "return", "getMongoHandle", "(", "mongoose", ")", ".", "then", "(", "(", "modelHandle", ")", "=>", "{", "debuglog", "(", "`", "${", "modelPath", "}", "`", ")", ";", "return", "_loadModelsFull", "(", "modelHandle", ",", "modelPath", ")", ";", "}", ")", ";", "}" ]
expects an open connection! @param mongoose @param modelPath
[ "expects", "an", "open", "connection!" ]
be1be4406b05718d666d6d0f712c9cadb5169f2c
https://github.com/jfseb/mgnlq_model/blob/be1be4406b05718d666d6d0f712c9cadb5169f2c/js/model/model.js#L1202-L1210
53,683
jmorrell/backbone-paginated-collection
index.js
difference
function difference(arrayA, arrayB) { var maxLength = _.max([ arrayA.length, arrayB.length ]); for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) { if (arrayA[i] !== arrayB[j]) { if (arrayB[i-1] === arrayA[i]) { j -= 1; } else if (arrayB[i+1] === arrayA[i]) { j += 1; } else { return arrayA[i]; } } } }
javascript
function difference(arrayA, arrayB) { var maxLength = _.max([ arrayA.length, arrayB.length ]); for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) { if (arrayA[i] !== arrayB[j]) { if (arrayB[i-1] === arrayA[i]) { j -= 1; } else if (arrayB[i+1] === arrayA[i]) { j += 1; } else { return arrayA[i]; } } } }
[ "function", "difference", "(", "arrayA", ",", "arrayB", ")", "{", "var", "maxLength", "=", "_", ".", "max", "(", "[", "arrayA", ".", "length", ",", "arrayB", ".", "length", "]", ")", ";", "for", "(", "var", "i", "=", "0", ",", "j", "=", "0", ";", "i", "<", "maxLength", ";", "i", "+=", "1", ",", "j", "+=", "1", ")", "{", "if", "(", "arrayA", "[", "i", "]", "!==", "arrayB", "[", "j", "]", ")", "{", "if", "(", "arrayB", "[", "i", "-", "1", "]", "===", "arrayA", "[", "i", "]", ")", "{", "j", "-=", "1", ";", "}", "else", "if", "(", "arrayB", "[", "i", "+", "1", "]", "===", "arrayA", "[", "i", "]", ")", "{", "j", "+=", "1", ";", "}", "else", "{", "return", "arrayA", "[", "i", "]", ";", "}", "}", "}", "}" ]
Given two arrays of backbone models, with at most one model added and one model removed from each, return the model in arrayA that is not in arrayB or undefined.
[ "Given", "two", "arrays", "of", "backbone", "models", "with", "at", "most", "one", "model", "added", "and", "one", "model", "removed", "from", "each", "return", "the", "model", "in", "arrayA", "that", "is", "not", "in", "arrayB", "or", "undefined", "." ]
46b8de1c8b24d741852294048f21d43225838364
https://github.com/jmorrell/backbone-paginated-collection/blob/46b8de1c8b24d741852294048f21d43225838364/index.js#L52-L66
53,684
MauroJr/amp
src/decode.js
decode
function decode(buf) { let off = 0; var i; // unpack meta const meta = buf[(off += 1)]; // const VERSION = meta >> 4; const argv = meta & 0xf; const args = new Array(argv); // unpack args for (i = 0; i < argv; i += 1) { const len = buf.readUInt32BE(off); off += 4; args[i] = buf.slice(off, (off += len)); } return args; }
javascript
function decode(buf) { let off = 0; var i; // unpack meta const meta = buf[(off += 1)]; // const VERSION = meta >> 4; const argv = meta & 0xf; const args = new Array(argv); // unpack args for (i = 0; i < argv; i += 1) { const len = buf.readUInt32BE(off); off += 4; args[i] = buf.slice(off, (off += len)); } return args; }
[ "function", "decode", "(", "buf", ")", "{", "let", "off", "=", "0", ";", "var", "i", ";", "// unpack meta", "const", "meta", "=", "buf", "[", "(", "off", "+=", "1", ")", "]", ";", "// const VERSION = meta >> 4;", "const", "argv", "=", "meta", "&", "0xf", ";", "const", "args", "=", "new", "Array", "(", "argv", ")", ";", "// unpack args", "for", "(", "i", "=", "0", ";", "i", "<", "argv", ";", "i", "+=", "1", ")", "{", "const", "len", "=", "buf", ".", "readUInt32BE", "(", "off", ")", ";", "off", "+=", "4", ";", "args", "[", "i", "]", "=", "buf", ".", "slice", "(", "off", ",", "(", "off", "+=", "len", ")", ")", ";", "}", "return", "args", ";", "}" ]
Decode the given `buf`. @param {Buffer} buf @return {Object} @api public
[ "Decode", "the", "given", "buf", "." ]
2b7df0bcf91228d02bdd6d6f1e1238743dbbb086
https://github.com/MauroJr/amp/blob/2b7df0bcf91228d02bdd6d6f1e1238743dbbb086/src/decode.js#L12-L31
53,685
kevinconway/Event.js
event/event.js
appendListener
function appendListener(event, listener, once) { this.events[event] = this.events[event] || []; this.events[event].push({ "listener": listener, "once": !!once }); this.emit('newListener', event, listener); if (this.events[event].length > this.maxListeners) { console.warn('warning: possible EventEmitter memory leak detected. ', this.events[event].length, ' listeners added. ', 'Use emitter.setMaxListeners() to increase limit. ', this); } }
javascript
function appendListener(event, listener, once) { this.events[event] = this.events[event] || []; this.events[event].push({ "listener": listener, "once": !!once }); this.emit('newListener', event, listener); if (this.events[event].length > this.maxListeners) { console.warn('warning: possible EventEmitter memory leak detected. ', this.events[event].length, ' listeners added. ', 'Use emitter.setMaxListeners() to increase limit. ', this); } }
[ "function", "appendListener", "(", "event", ",", "listener", ",", "once", ")", "{", "this", ".", "events", "[", "event", "]", "=", "this", ".", "events", "[", "event", "]", "||", "[", "]", ";", "this", ".", "events", "[", "event", "]", ".", "push", "(", "{", "\"listener\"", ":", "listener", ",", "\"once\"", ":", "!", "!", "once", "}", ")", ";", "this", ".", "emit", "(", "'newListener'", ",", "event", ",", "listener", ")", ";", "if", "(", "this", ".", "events", "[", "event", "]", ".", "length", ">", "this", ".", "maxListeners", ")", "{", "console", ".", "warn", "(", "'warning: possible EventEmitter memory leak detected. '", ",", "this", ".", "events", "[", "event", "]", ".", "length", ",", "' listeners added. '", ",", "'Use emitter.setMaxListeners() to increase limit. '", ",", "this", ")", ";", "}", "}" ]
Adds a listener to the list. Private method hidden from api.
[ "Adds", "a", "listener", "to", "the", "list", ".", "Private", "method", "hidden", "from", "api", "." ]
65b4a0b4e19defaa9a863c107633b1835929a660
https://github.com/kevinconway/Event.js/blob/65b4a0b4e19defaa9a863c107633b1835929a660/event/event.js#L35-L54
53,686
joemccann/photopipe
utils/validation.js
function(u){ var urlObj = url.parse(u) return u.replace( urlObj.search, '').replace('#', '') }
javascript
function(u){ var urlObj = url.parse(u) return u.replace( urlObj.search, '').replace('#', '') }
[ "function", "(", "u", ")", "{", "var", "urlObj", "=", "url", ".", "parse", "(", "u", ")", "return", "u", ".", "replace", "(", "urlObj", ".", "search", ",", "''", ")", ".", "replace", "(", "'#'", ",", "''", ")", "}" ]
Brute force way of removing querystring and hash
[ "Brute", "force", "way", "of", "removing", "querystring", "and", "hash" ]
20318fde11163a8b732b077a141a8d8530372333
https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/utils/validation.js#L10-L13
53,687
joemccann/photopipe
utils/validation.js
function(u){ var urlObj = url.parse(u) return urlObj.protocol + "//" + urlObj.hostname + urlObj.pathname }
javascript
function(u){ var urlObj = url.parse(u) return urlObj.protocol + "//" + urlObj.hostname + urlObj.pathname }
[ "function", "(", "u", ")", "{", "var", "urlObj", "=", "url", ".", "parse", "(", "u", ")", "return", "urlObj", ".", "protocol", "+", "\"//\"", "+", "urlObj", ".", "hostname", "+", "urlObj", ".", "pathname", "}" ]
Build path from urlObj after parsing
[ "Build", "path", "from", "urlObj", "after", "parsing" ]
20318fde11163a8b732b077a141a8d8530372333
https://github.com/joemccann/photopipe/blob/20318fde11163a8b732b077a141a8d8530372333/utils/validation.js#L15-L18
53,688
bredele/post
post.js
PostEmitter
function PostEmitter() { var _this = this; //might be global this._listener = function(ev) { //check origin //then var data = ev.data; _this.emit.apply(_this, data instanceof Array ? data : [data]); }; window[attach](prefix + 'message', this._listener); }
javascript
function PostEmitter() { var _this = this; //might be global this._listener = function(ev) { //check origin //then var data = ev.data; _this.emit.apply(_this, data instanceof Array ? data : [data]); }; window[attach](prefix + 'message', this._listener); }
[ "function", "PostEmitter", "(", ")", "{", "var", "_this", "=", "this", ";", "//might be global", "this", ".", "_listener", "=", "function", "(", "ev", ")", "{", "//check origin", "//then", "var", "data", "=", "ev", ".", "data", ";", "_this", ".", "emit", ".", "apply", "(", "_this", ",", "data", "instanceof", "Array", "?", "data", ":", "[", "data", "]", ")", ";", "}", ";", "window", "[", "attach", "]", "(", "prefix", "+", "'message'", ",", "this", ".", "_listener", ")", ";", "}" ]
PostEmitter constructor. Listen local and remote messages. @api public
[ "PostEmitter", "constructor", ".", "Listen", "local", "and", "remote", "messages", "." ]
a0a7365e432c4d10e660e872825c094c08f32ba8
https://github.com/bredele/post/blob/a0a7365e432c4d10e660e872825c094c08f32ba8/post.js#L397-L407
53,689
SolarNetwork/solarnetwork-d3
src/color/util.js
sn_color_map
function sn_color_map(fillColors, keys) { var colorRange = d3.scale.ordinal().range(fillColors); var colorData = keys.map(function(el, i) { return {source:el, color:colorRange(i)}; }); // also provide a mapping of sources to corresponding colors var i, len, sourceName; for ( i = 0, len = colorData.length; i < len; i += 1 ) { // a source value might actually be a number string, which JavaScript will treat // as an array index so only set non-numbers here sourceName = colorData[i].source; if ( sourceName === '' ) { // default to Main if source not provided sourceName = 'Main'; } if ( isNaN(Number(sourceName)) ) { colorData[sourceName] = colorData[i].color; } } return colorData; }
javascript
function sn_color_map(fillColors, keys) { var colorRange = d3.scale.ordinal().range(fillColors); var colorData = keys.map(function(el, i) { return {source:el, color:colorRange(i)}; }); // also provide a mapping of sources to corresponding colors var i, len, sourceName; for ( i = 0, len = colorData.length; i < len; i += 1 ) { // a source value might actually be a number string, which JavaScript will treat // as an array index so only set non-numbers here sourceName = colorData[i].source; if ( sourceName === '' ) { // default to Main if source not provided sourceName = 'Main'; } if ( isNaN(Number(sourceName)) ) { colorData[sourceName] = colorData[i].color; } } return colorData; }
[ "function", "sn_color_map", "(", "fillColors", ",", "keys", ")", "{", "var", "colorRange", "=", "d3", ".", "scale", ".", "ordinal", "(", ")", ".", "range", "(", "fillColors", ")", ";", "var", "colorData", "=", "keys", ".", "map", "(", "function", "(", "el", ",", "i", ")", "{", "return", "{", "source", ":", "el", ",", "color", ":", "colorRange", "(", "i", ")", "}", ";", "}", ")", ";", "// also provide a mapping of sources to corresponding colors", "var", "i", ",", "len", ",", "sourceName", ";", "for", "(", "i", "=", "0", ",", "len", "=", "colorData", ".", "length", ";", "i", "<", "len", ";", "i", "+=", "1", ")", "{", "// a source value might actually be a number string, which JavaScript will treat ", "// as an array index so only set non-numbers here", "sourceName", "=", "colorData", "[", "i", "]", ".", "source", ";", "if", "(", "sourceName", "===", "''", ")", "{", "// default to Main if source not provided", "sourceName", "=", "'Main'", ";", "}", "if", "(", "isNaN", "(", "Number", "(", "sourceName", ")", ")", ")", "{", "colorData", "[", "sourceName", "]", "=", "colorData", "[", "i", "]", ".", "color", ";", "}", "}", "return", "colorData", ";", "}" ]
Return an array of colors for a set of unique keys, where the returned array also contains associative properties for all key values to thier corresponding color value. <p>This is designed so the set of keys always map to the same color, even across charts where not all sources may be present.</p> @preserve
[ "Return", "an", "array", "of", "colors", "for", "a", "set", "of", "unique", "keys", "where", "the", "returned", "array", "also", "contains", "associative", "properties", "for", "all", "key", "values", "to", "thier", "corresponding", "color", "value", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/color/util.js#L17-L37
53,690
SolarNetwork/solarnetwork-d3
src/color/util.js
sn_color_color
function sn_color_color(d) { var s = Number(d.source); if ( isNaN(s) ) { return sn.runtime.colorData[d.source]; } return sn.runtime.colorData.reduce(function(c, obj) { return (obj.source === d.source ? obj.color : c); }, sn.runtime.colorData[0].color); }
javascript
function sn_color_color(d) { var s = Number(d.source); if ( isNaN(s) ) { return sn.runtime.colorData[d.source]; } return sn.runtime.colorData.reduce(function(c, obj) { return (obj.source === d.source ? obj.color : c); }, sn.runtime.colorData[0].color); }
[ "function", "sn_color_color", "(", "d", ")", "{", "var", "s", "=", "Number", "(", "d", ".", "source", ")", ";", "if", "(", "isNaN", "(", "s", ")", ")", "{", "return", "sn", ".", "runtime", ".", "colorData", "[", "d", ".", "source", "]", ";", "}", "return", "sn", ".", "runtime", ".", "colorData", ".", "reduce", "(", "function", "(", "c", ",", "obj", ")", "{", "return", "(", "obj", ".", "source", "===", "d", ".", "source", "?", "obj", ".", "color", ":", "c", ")", ";", "}", ",", "sn", ".", "runtime", ".", "colorData", "[", "0", "]", ".", "color", ")", ";", "}" ]
Use the configured runtime color map to turn a source into a color. The {@code sn.runtime.colorData} property must be set to a color map object as returned by {@link sn.colorMap}. @param {object} d the data element, expected to contain a {@code source} property @returns {string} color value @preserve
[ "Use", "the", "configured", "runtime", "color", "map", "to", "turn", "a", "source", "into", "a", "color", "." ]
26848b1c303b98b7c0ddeefb8c68c5f5bf78927e
https://github.com/SolarNetwork/solarnetwork-d3/blob/26848b1c303b98b7c0ddeefb8c68c5f5bf78927e/src/color/util.js#L49-L57
53,691
frankandrobot/js-go-channels
packages/js-go-channels/src/index.js
_createConsumerMessage
function _createConsumerMessage(consumer, message, {chanId}) { const { iterator: consumerIterator, type: requestType, payload } = consumer if (requestType === cSelectRequest) { const {selectedChanIds} = payload const i = selectedChanIds.indexOf(chanId) const response = new Array(selectedChanIds.length) response[i] = message return [consumerIterator, response] } else if (requestType === cTakeRequest) { return [consumerIterator, message] } throw new Error(`Unknown request type ${requestType}`) }
javascript
function _createConsumerMessage(consumer, message, {chanId}) { const { iterator: consumerIterator, type: requestType, payload } = consumer if (requestType === cSelectRequest) { const {selectedChanIds} = payload const i = selectedChanIds.indexOf(chanId) const response = new Array(selectedChanIds.length) response[i] = message return [consumerIterator, response] } else if (requestType === cTakeRequest) { return [consumerIterator, message] } throw new Error(`Unknown request type ${requestType}`) }
[ "function", "_createConsumerMessage", "(", "consumer", ",", "message", ",", "{", "chanId", "}", ")", "{", "const", "{", "iterator", ":", "consumerIterator", ",", "type", ":", "requestType", ",", "payload", "}", "=", "consumer", "if", "(", "requestType", "===", "cSelectRequest", ")", "{", "const", "{", "selectedChanIds", "}", "=", "payload", "const", "i", "=", "selectedChanIds", ".", "indexOf", "(", "chanId", ")", "const", "response", "=", "new", "Array", "(", "selectedChanIds", ".", "length", ")", "response", "[", "i", "]", "=", "message", "return", "[", "consumerIterator", ",", "response", "]", "}", "else", "if", "(", "requestType", "===", "cTakeRequest", ")", "{", "return", "[", "consumerIterator", ",", "message", "]", "}", "throw", "new", "Error", "(", "`", "${", "requestType", "}", "`", ")", "}" ]
Does what it says. Need to take into account the case when the consumer is a pending select, pending take. `select`s have a different signature. @param {Object} consumer - the consumer and message that was queued @param {Iterator} consumer.iterator @param {string} consumer.type - the consumer's message type @param {Object} consumer.payload - the consumer's message payload @param {Object} message - the message to give to the consumer @param {Object} extraArgs @param {string} extraArgs.chanId @returns {[Iterator, Message]}
[ "Does", "what", "it", "says", ".", "Need", "to", "take", "into", "account", "the", "case", "when", "the", "consumer", "is", "a", "pending", "select", "pending", "take", ".", "select", "s", "have", "a", "different", "signature", "." ]
cf1f7329e5e424a9e4123816f2b27adf73022eff
https://github.com/frankandrobot/js-go-channels/blob/cf1f7329e5e424a9e4123816f2b27adf73022eff/packages/js-go-channels/src/index.js#L65-L81
53,692
leipert/gulp-stack
tasks/app.js
function () { var stream = new $.streamqueue({ objectMode: true }); //Optionally injected additional javascript sourcecode injectIntoStream(stream, options.injectInto.js.pre); // App files without vendor files stream.queue(gulp.src(options.files.jsNoVendor)); //Angular template files stream.queue( gulp.src(options.files.partials) .pipe($.htmlMinify()) .pipe($.angularTemplatecache(options.templateCacheOptions)) ); //Optionally injected additional javascript sourcecode injectIntoStream(stream, options.injectInto.js.post); return stream .done() .pipe($.angularFilesort()) .pipe($.concat(options.output.js.app)) .pipe($.generateOutPipe(options.paths.build, options.output.js.path, 'app.js', options.rev, $.jsMinify)()); }
javascript
function () { var stream = new $.streamqueue({ objectMode: true }); //Optionally injected additional javascript sourcecode injectIntoStream(stream, options.injectInto.js.pre); // App files without vendor files stream.queue(gulp.src(options.files.jsNoVendor)); //Angular template files stream.queue( gulp.src(options.files.partials) .pipe($.htmlMinify()) .pipe($.angularTemplatecache(options.templateCacheOptions)) ); //Optionally injected additional javascript sourcecode injectIntoStream(stream, options.injectInto.js.post); return stream .done() .pipe($.angularFilesort()) .pipe($.concat(options.output.js.app)) .pipe($.generateOutPipe(options.paths.build, options.output.js.path, 'app.js', options.rev, $.jsMinify)()); }
[ "function", "(", ")", "{", "var", "stream", "=", "new", "$", ".", "streamqueue", "(", "{", "objectMode", ":", "true", "}", ")", ";", "//Optionally injected additional javascript sourcecode", "injectIntoStream", "(", "stream", ",", "options", ".", "injectInto", ".", "js", ".", "pre", ")", ";", "// App files without vendor files", "stream", ".", "queue", "(", "gulp", ".", "src", "(", "options", ".", "files", ".", "jsNoVendor", ")", ")", ";", "//Angular template files", "stream", ".", "queue", "(", "gulp", ".", "src", "(", "options", ".", "files", ".", "partials", ")", ".", "pipe", "(", "$", ".", "htmlMinify", "(", ")", ")", ".", "pipe", "(", "$", ".", "angularTemplatecache", "(", "options", ".", "templateCacheOptions", ")", ")", ")", ";", "//Optionally injected additional javascript sourcecode", "injectIntoStream", "(", "stream", ",", "options", ".", "injectInto", ".", "js", ".", "post", ")", ";", "return", "stream", ".", "done", "(", ")", ".", "pipe", "(", "$", ".", "angularFilesort", "(", ")", ")", ".", "pipe", "(", "$", ".", "concat", "(", "options", ".", "output", ".", "js", ".", "app", ")", ")", ".", "pipe", "(", "$", ".", "generateOutPipe", "(", "options", ".", "paths", ".", "build", ",", "options", ".", "output", ".", "js", ".", "path", ",", "'app.js'", ",", "options", ".", "rev", ",", "$", ".", "jsMinify", ")", "(", ")", ")", ";", "}" ]
Takes all app javascript files, angular templates and concats and minifies them
[ "Takes", "all", "app", "javascript", "files", "angular", "templates", "and", "concats", "and", "minifies", "them" ]
717bd0524f835393d2d3870c3e8f4d9af39c52c7
https://github.com/leipert/gulp-stack/blob/717bd0524f835393d2d3870c3e8f4d9af39c52c7/tasks/app.js#L28-L54
53,693
leipert/gulp-stack
tasks/app.js
function () { var stream = new $.streamqueue({ objectMode: true }); //Optionally injected additional css sourcecode injectIntoStream(stream, options.injectInto.css.pre); // App files without vendor files stream.queue(gulp.src(options.files.cssNoVendor)); //Optionally injected additional css sourcecode injectIntoStream(stream, options.injectInto.css.post); return stream .done() .pipe($.concat(options.output.css.app)) .pipe($.generateOutPipe(options.paths.build, options.output.css.path, 'app.css', options.rev, $.cssMinify)()); }
javascript
function () { var stream = new $.streamqueue({ objectMode: true }); //Optionally injected additional css sourcecode injectIntoStream(stream, options.injectInto.css.pre); // App files without vendor files stream.queue(gulp.src(options.files.cssNoVendor)); //Optionally injected additional css sourcecode injectIntoStream(stream, options.injectInto.css.post); return stream .done() .pipe($.concat(options.output.css.app)) .pipe($.generateOutPipe(options.paths.build, options.output.css.path, 'app.css', options.rev, $.cssMinify)()); }
[ "function", "(", ")", "{", "var", "stream", "=", "new", "$", ".", "streamqueue", "(", "{", "objectMode", ":", "true", "}", ")", ";", "//Optionally injected additional css sourcecode", "injectIntoStream", "(", "stream", ",", "options", ".", "injectInto", ".", "css", ".", "pre", ")", ";", "// App files without vendor files", "stream", ".", "queue", "(", "gulp", ".", "src", "(", "options", ".", "files", ".", "cssNoVendor", ")", ")", ";", "//Optionally injected additional css sourcecode", "injectIntoStream", "(", "stream", ",", "options", ".", "injectInto", ".", "css", ".", "post", ")", ";", "return", "stream", ".", "done", "(", ")", ".", "pipe", "(", "$", ".", "concat", "(", "options", ".", "output", ".", "css", ".", "app", ")", ")", ".", "pipe", "(", "$", ".", "generateOutPipe", "(", "options", ".", "paths", ".", "build", ",", "options", ".", "output", ".", "css", ".", "path", ",", "'app.css'", ",", "options", ".", "rev", ",", "$", ".", "cssMinify", ")", "(", ")", ")", ";", "}" ]
Takes all app css files and concats and minfies them
[ "Takes", "all", "app", "css", "files", "and", "concats", "and", "minfies", "them" ]
717bd0524f835393d2d3870c3e8f4d9af39c52c7
https://github.com/leipert/gulp-stack/blob/717bd0524f835393d2d3870c3e8f4d9af39c52c7/tasks/app.js#L60-L79
53,694
hammy2899/circle-assign
src/merge.js
merge
function merge(target, ...sources) { let targetObject = target; if (!isObj(target)) { targetObject = {}; } // for all the sources provided merge them with // the target object sources.forEach((s) => { // before merging check the source is an object if (isObj(s)) { targetObject = mergeObject(targetObject, s); } }); return targetObject; }
javascript
function merge(target, ...sources) { let targetObject = target; if (!isObj(target)) { targetObject = {}; } // for all the sources provided merge them with // the target object sources.forEach((s) => { // before merging check the source is an object if (isObj(s)) { targetObject = mergeObject(targetObject, s); } }); return targetObject; }
[ "function", "merge", "(", "target", ",", "...", "sources", ")", "{", "let", "targetObject", "=", "target", ";", "if", "(", "!", "isObj", "(", "target", ")", ")", "{", "targetObject", "=", "{", "}", ";", "}", "// for all the sources provided merge them with", "// the target object", "sources", ".", "forEach", "(", "(", "s", ")", "=>", "{", "// before merging check the source is an object", "if", "(", "isObj", "(", "s", ")", ")", "{", "targetObject", "=", "mergeObject", "(", "targetObject", ",", "s", ")", ";", "}", "}", ")", ";", "return", "targetObject", ";", "}" ]
Merge specified objects into one object with the most right object having the most priority @param {Object} target The base object @param {...Object} sources The object(s) to merge @returns {Object} The merged object(s) result
[ "Merge", "specified", "objects", "into", "one", "object", "with", "the", "most", "right", "object", "having", "the", "most", "priority" ]
4eb202021279b789ce758b3feae2417eb7f2ded5
https://github.com/hammy2899/circle-assign/blob/4eb202021279b789ce758b3feae2417eb7f2ded5/src/merge.js#L13-L30
53,695
benquarmby/gulp-byo-jslint
index.js
lintStream
function lintStream(spec) { if (!spec || !spec.jslint) { throw new gulpUtil.PluginError(pluginName, 'The file path to jslint is required.'); } var errors = 0; function lint(source, callback) { var contents = source.contents.toString('utf8'); var result = context.jslint(contents, spec.options, spec.globals); if (result.ok) { gulpUtil.log(colors.green(source.path)); } else { gulpUtil.log(colors.red(source.path)); errors += result.warnings.length; result.warnings.forEach(logWarning); } callback(null, source); } function map(source, callback) { if (context.jslint) { lint(source, callback); return; } fs.readFile(spec.jslint, 'utf8', function (err, jslint) { if (err) { throw new gulpUtil.PluginError(pluginName, err); } vm.runInNewContext(jslint, context); lint(source, callback); }); } function onEnd() { if (errors && !spec.noFail) { var message = errors === 1 ? 'JSLint found one error.' : 'JSLint found ' + errors + ' errors.'; throw new gulpUtil.PluginError(pluginName, message); } } return eventStream .map(map) .on('end', onEnd); }
javascript
function lintStream(spec) { if (!spec || !spec.jslint) { throw new gulpUtil.PluginError(pluginName, 'The file path to jslint is required.'); } var errors = 0; function lint(source, callback) { var contents = source.contents.toString('utf8'); var result = context.jslint(contents, spec.options, spec.globals); if (result.ok) { gulpUtil.log(colors.green(source.path)); } else { gulpUtil.log(colors.red(source.path)); errors += result.warnings.length; result.warnings.forEach(logWarning); } callback(null, source); } function map(source, callback) { if (context.jslint) { lint(source, callback); return; } fs.readFile(spec.jslint, 'utf8', function (err, jslint) { if (err) { throw new gulpUtil.PluginError(pluginName, err); } vm.runInNewContext(jslint, context); lint(source, callback); }); } function onEnd() { if (errors && !spec.noFail) { var message = errors === 1 ? 'JSLint found one error.' : 'JSLint found ' + errors + ' errors.'; throw new gulpUtil.PluginError(pluginName, message); } } return eventStream .map(map) .on('end', onEnd); }
[ "function", "lintStream", "(", "spec", ")", "{", "if", "(", "!", "spec", "||", "!", "spec", ".", "jslint", ")", "{", "throw", "new", "gulpUtil", ".", "PluginError", "(", "pluginName", ",", "'The file path to jslint is required.'", ")", ";", "}", "var", "errors", "=", "0", ";", "function", "lint", "(", "source", ",", "callback", ")", "{", "var", "contents", "=", "source", ".", "contents", ".", "toString", "(", "'utf8'", ")", ";", "var", "result", "=", "context", ".", "jslint", "(", "contents", ",", "spec", ".", "options", ",", "spec", ".", "globals", ")", ";", "if", "(", "result", ".", "ok", ")", "{", "gulpUtil", ".", "log", "(", "colors", ".", "green", "(", "source", ".", "path", ")", ")", ";", "}", "else", "{", "gulpUtil", ".", "log", "(", "colors", ".", "red", "(", "source", ".", "path", ")", ")", ";", "errors", "+=", "result", ".", "warnings", ".", "length", ";", "result", ".", "warnings", ".", "forEach", "(", "logWarning", ")", ";", "}", "callback", "(", "null", ",", "source", ")", ";", "}", "function", "map", "(", "source", ",", "callback", ")", "{", "if", "(", "context", ".", "jslint", ")", "{", "lint", "(", "source", ",", "callback", ")", ";", "return", ";", "}", "fs", ".", "readFile", "(", "spec", ".", "jslint", ",", "'utf8'", ",", "function", "(", "err", ",", "jslint", ")", "{", "if", "(", "err", ")", "{", "throw", "new", "gulpUtil", ".", "PluginError", "(", "pluginName", ",", "err", ")", ";", "}", "vm", ".", "runInNewContext", "(", "jslint", ",", "context", ")", ";", "lint", "(", "source", ",", "callback", ")", ";", "}", ")", ";", "}", "function", "onEnd", "(", ")", "{", "if", "(", "errors", "&&", "!", "spec", ".", "noFail", ")", "{", "var", "message", "=", "errors", "===", "1", "?", "'JSLint found one error.'", ":", "'JSLint found '", "+", "errors", "+", "' errors.'", ";", "throw", "new", "gulpUtil", ".", "PluginError", "(", "pluginName", ",", "message", ")", ";", "}", "}", "return", "eventStream", ".", "map", "(", "map", ")", ".", "on", "(", "'end'", ",", "onEnd", ")", ";", "}" ]
Runs JSLint over each item in the stream. @param {Object} spec The specification. @param {String} spec.jslint The file path to jslint.js. @param {Object} [spec.options] The options to pass to JSLint. @param {Array} [spec.globals] The list of known global variables to pass to JSLint. @param {Boolean} [spec.noFail] True to log all warnings without failing.
[ "Runs", "JSLint", "over", "each", "item", "in", "the", "stream", "." ]
aeae37424e325ae390a25bc4cf93d333da1de559
https://github.com/benquarmby/gulp-byo-jslint/blob/aeae37424e325ae390a25bc4cf93d333da1de559/index.js#L50-L105
53,696
veo-labs/openveo-rest-nodejs-client
lib/RestClient.js
rejectAll
function rejectAll(requests, error) { for (const request of requests) { request.abort(); request.reject(error); } }
javascript
function rejectAll(requests, error) { for (const request of requests) { request.abort(); request.reject(error); } }
[ "function", "rejectAll", "(", "requests", ",", "error", ")", "{", "for", "(", "const", "request", "of", "requests", ")", "{", "request", ".", "abort", "(", ")", ";", "request", ".", "reject", "(", "error", ")", ";", "}", "}" ]
Rejects all requests with the given error. If the request is running, it will be aborted. @private @param {Set} requests The list of requests to reject @param {Error} error The reject's error
[ "Rejects", "all", "requests", "with", "the", "given", "error", "." ]
c88f8daca56ca38d649bd76633a55440e5dc47c2
https://github.com/veo-labs/openveo-rest-nodejs-client/blob/c88f8daca56ca38d649bd76633a55440e5dc47c2/lib/RestClient.js#L27-L32
53,697
deanlandolt/endo
util/index.js
UnauthorizedError
function UnauthorizedError(message) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.status = 401; this.message = 'Unauthorized: ' + message; this.name = this.constructor.name; }
javascript
function UnauthorizedError(message) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.status = 401; this.message = 'Unauthorized: ' + message; this.name = this.constructor.name; }
[ "function", "UnauthorizedError", "(", "message", ")", "{", "Error", ".", "call", "(", "this", ")", ";", "Error", ".", "captureStackTrace", "(", "this", ",", "this", ".", "constructor", ")", ";", "this", ".", "status", "=", "401", ";", "this", ".", "message", "=", "'Unauthorized: '", "+", "message", ";", "this", ".", "name", "=", "this", ".", "constructor", ".", "name", ";", "}" ]
thrown when endpoint authorization fails
[ "thrown", "when", "endpoint", "authorization", "fails" ]
e96234226e3a56e5c71b7f68690b5cc98123ed03
https://github.com/deanlandolt/endo/blob/e96234226e3a56e5c71b7f68690b5cc98123ed03/util/index.js#L181-L188
53,698
deanlandolt/endo
util/index.js
NotFoundError
function NotFoundError(message) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.status = 404; this.message = 'Not Found: ' + message; this.name = this.constructor.name; }
javascript
function NotFoundError(message) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.status = 404; this.message = 'Not Found: ' + message; this.name = this.constructor.name; }
[ "function", "NotFoundError", "(", "message", ")", "{", "Error", ".", "call", "(", "this", ")", ";", "Error", ".", "captureStackTrace", "(", "this", ",", "this", ".", "constructor", ")", ";", "this", ".", "status", "=", "404", ";", "this", ".", "message", "=", "'Not Found: '", "+", "message", ";", "this", ".", "name", "=", "this", ".", "constructor", ".", "name", ";", "}" ]
thrown when endpoint resolution fails
[ "thrown", "when", "endpoint", "resolution", "fails" ]
e96234226e3a56e5c71b7f68690b5cc98123ed03
https://github.com/deanlandolt/endo/blob/e96234226e3a56e5c71b7f68690b5cc98123ed03/util/index.js#L196-L203
53,699
SwirlNetworks/discus
src/view.js
function(el) { var self = this, $el = $(el); if ($el.length > 1) { $el.each(function() { self.addElement(this); }); } else if ($el.length === 0) { throw new Error("Invalid element!"); } if (this.$el.closest($el).length) { throw new Error("Element is a child of this view. This is only for unrelated elements"); } if ($el.closest(this.$el).length) { throw new Error("Element is an ancestor of this view! Reconsider how you're using this view."); } // normalize el = $el.get(0); if (!this._trackedElements) { this._trackedElements = []; } _(this._trackedElements).each(function(otherEl) { var $otherEl = $(otherEl); if ($otherEl.closest($el).length) { throw new Error("Element is a child of another tracked element. This will cause problems."); } if ($el.closest($otherEl).length) { throw new Error("Element is an ancestor of another tracked element. This will cause problems."); } }); this._trackedElements.push(el); }
javascript
function(el) { var self = this, $el = $(el); if ($el.length > 1) { $el.each(function() { self.addElement(this); }); } else if ($el.length === 0) { throw new Error("Invalid element!"); } if (this.$el.closest($el).length) { throw new Error("Element is a child of this view. This is only for unrelated elements"); } if ($el.closest(this.$el).length) { throw new Error("Element is an ancestor of this view! Reconsider how you're using this view."); } // normalize el = $el.get(0); if (!this._trackedElements) { this._trackedElements = []; } _(this._trackedElements).each(function(otherEl) { var $otherEl = $(otherEl); if ($otherEl.closest($el).length) { throw new Error("Element is a child of another tracked element. This will cause problems."); } if ($el.closest($otherEl).length) { throw new Error("Element is an ancestor of another tracked element. This will cause problems."); } }); this._trackedElements.push(el); }
[ "function", "(", "el", ")", "{", "var", "self", "=", "this", ",", "$el", "=", "$", "(", "el", ")", ";", "if", "(", "$el", ".", "length", ">", "1", ")", "{", "$el", ".", "each", "(", "function", "(", ")", "{", "self", ".", "addElement", "(", "this", ")", ";", "}", ")", ";", "}", "else", "if", "(", "$el", ".", "length", "===", "0", ")", "{", "throw", "new", "Error", "(", "\"Invalid element!\"", ")", ";", "}", "if", "(", "this", ".", "$el", ".", "closest", "(", "$el", ")", ".", "length", ")", "{", "throw", "new", "Error", "(", "\"Element is a child of this view. This is only for unrelated elements\"", ")", ";", "}", "if", "(", "$el", ".", "closest", "(", "this", ".", "$el", ")", ".", "length", ")", "{", "throw", "new", "Error", "(", "\"Element is an ancestor of this view! Reconsider how you're using this view.\"", ")", ";", "}", "// normalize", "el", "=", "$el", ".", "get", "(", "0", ")", ";", "if", "(", "!", "this", ".", "_trackedElements", ")", "{", "this", ".", "_trackedElements", "=", "[", "]", ";", "}", "_", "(", "this", ".", "_trackedElements", ")", ".", "each", "(", "function", "(", "otherEl", ")", "{", "var", "$otherEl", "=", "$", "(", "otherEl", ")", ";", "if", "(", "$otherEl", ".", "closest", "(", "$el", ")", ".", "length", ")", "{", "throw", "new", "Error", "(", "\"Element is a child of another tracked element. This will cause problems.\"", ")", ";", "}", "if", "(", "$el", ".", "closest", "(", "$otherEl", ")", ".", "length", ")", "{", "throw", "new", "Error", "(", "\"Element is an ancestor of another tracked element. This will cause problems.\"", ")", ";", "}", "}", ")", ";", "this", ".", "_trackedElements", ".", "push", "(", "el", ")", ";", "}" ]
track el as part of this view even though it's not a child..
[ "track", "el", "as", "part", "of", "this", "view", "even", "though", "it", "s", "not", "a", "child", ".." ]
79df8de5ec268879e50ec1e12e78b62a13b4a427
https://github.com/SwirlNetworks/discus/blob/79df8de5ec268879e50ec1e12e78b62a13b4a427/src/view.js#L186-L222