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
55,500
infonl/delegator
index.js
Delegator
function Delegator(id, events, capture, bubble, contextDocument) { this.bubble = bubble; this.capture = capture; this.document = contextDocument; this.documentElement = contextDocument.documentElement; this.events = events; this.id = id; this.registry = {}; }
javascript
function Delegator(id, events, capture, bubble, contextDocument) { this.bubble = bubble; this.capture = capture; this.document = contextDocument; this.documentElement = contextDocument.documentElement; this.events = events; this.id = id; this.registry = {}; }
[ "function", "Delegator", "(", "id", ",", "events", ",", "capture", ",", "bubble", ",", "contextDocument", ")", "{", "this", ".", "bubble", "=", "bubble", ";", "this", ".", "capture", "=", "capture", ";", "this", ".", "document", "=", "contextDocument", ";", "this", ".", "documentElement", "=", "contextDocument", ".", "documentElement", ";", "this", ".", "events", "=", "events", ";", "this", ".", "id", "=", "id", ";", "this", ".", "registry", "=", "{", "}", ";", "}" ]
Generic delegator for user interaction events, intended to be consumed by an encapsulation module that exposes an API that addresses concerns like proper usage, privacy, sensible defaults and such. @param {String} id @param {Array} events @param {Array} capture @param {Array} bubble @param {Document} contextDocument @constructor
[ "Generic", "delegator", "for", "user", "interaction", "events", "intended", "to", "be", "consumed", "by", "an", "encapsulation", "module", "that", "exposes", "an", "API", "that", "addresses", "concerns", "like", "proper", "usage", "privacy", "sensible", "defaults", "and", "such", "." ]
3ed07c189109ec7f6e1475cca3313ded9a72a75a
https://github.com/infonl/delegator/blob/3ed07c189109ec7f6e1475cca3313ded9a72a75a/index.js#L16-L24
55,501
infonl/delegator
index.js
function (event) { var trigger = event.target; var probe = function (type) { if ((type !== event.type) || (1 !== trigger.nodeType)) { return false; } var attribute = ['data', this.id, type].join('-'); var key = trigger.getAttribute(attribute); if (key && this.registry.hasOwnProperty(key)) { this.registry[key](event, trigger); return true; } if (-1 !== this.bubble.indexOf(type)) { while (this.documentElement !== trigger) { trigger = trigger.parentNode; if (probe(type)) { break; } } } return false; }.bind(this); this.events.forEach(probe); }
javascript
function (event) { var trigger = event.target; var probe = function (type) { if ((type !== event.type) || (1 !== trigger.nodeType)) { return false; } var attribute = ['data', this.id, type].join('-'); var key = trigger.getAttribute(attribute); if (key && this.registry.hasOwnProperty(key)) { this.registry[key](event, trigger); return true; } if (-1 !== this.bubble.indexOf(type)) { while (this.documentElement !== trigger) { trigger = trigger.parentNode; if (probe(type)) { break; } } } return false; }.bind(this); this.events.forEach(probe); }
[ "function", "(", "event", ")", "{", "var", "trigger", "=", "event", ".", "target", ";", "var", "probe", "=", "function", "(", "type", ")", "{", "if", "(", "(", "type", "!==", "event", ".", "type", ")", "||", "(", "1", "!==", "trigger", ".", "nodeType", ")", ")", "{", "return", "false", ";", "}", "var", "attribute", "=", "[", "'data'", ",", "this", ".", "id", ",", "type", "]", ".", "join", "(", "'-'", ")", ";", "var", "key", "=", "trigger", ".", "getAttribute", "(", "attribute", ")", ";", "if", "(", "key", "&&", "this", ".", "registry", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "this", ".", "registry", "[", "key", "]", "(", "event", ",", "trigger", ")", ";", "return", "true", ";", "}", "if", "(", "-", "1", "!==", "this", ".", "bubble", ".", "indexOf", "(", "type", ")", ")", "{", "while", "(", "this", ".", "documentElement", "!==", "trigger", ")", "{", "trigger", "=", "trigger", ".", "parentNode", ";", "if", "(", "probe", "(", "type", ")", ")", "{", "break", ";", "}", "}", "}", "return", "false", ";", "}", ".", "bind", "(", "this", ")", ";", "this", ".", "events", ".", "forEach", "(", "probe", ")", ";", "}" ]
Delegate the event. @param {Event} event
[ "Delegate", "the", "event", "." ]
3ed07c189109ec7f6e1475cca3313ded9a72a75a
https://github.com/infonl/delegator/blob/3ed07c189109ec7f6e1475cca3313ded9a72a75a/index.js#L33-L62
55,502
infonl/delegator
index.js
function (map) { Object.keys(map).forEach(function (key) { if (!this.registry.hasOwnProperty(key)) { this.registry[key] = map[key]; } }, this); return this; }
javascript
function (map) { Object.keys(map).forEach(function (key) { if (!this.registry.hasOwnProperty(key)) { this.registry[key] = map[key]; } }, this); return this; }
[ "function", "(", "map", ")", "{", "Object", ".", "keys", "(", "map", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "if", "(", "!", "this", ".", "registry", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "this", ".", "registry", "[", "key", "]", "=", "map", "[", "key", "]", ";", "}", "}", ",", "this", ")", ";", "return", "this", ";", "}" ]
Add handlers to the registry. @param {Object} map @returns {Delegator}
[ "Add", "handlers", "to", "the", "registry", "." ]
3ed07c189109ec7f6e1475cca3313ded9a72a75a
https://github.com/infonl/delegator/blob/3ed07c189109ec7f6e1475cca3313ded9a72a75a/index.js#L83-L90
55,503
LOKE/loke-config
lib/loke-config.js
LokeConfig
function LokeConfig(appName, options) { options = options || {}; // check args if (typeof appName !== 'string' || appName === '') { throw new Error('LokeConfig requires appName to be provided'); } if (Array.isArray(options)) { // Support original argument format: if (options.length === 0) { throw new Error('"paths" contains no items'); } options = {paths: options.slice(1), defaultPath: options[0]}; } var settings, self = this; var argv = minimist(process.argv.slice(2)); var appPath = options.appPath || dirname(require.main.filename); var paths = options.paths; var defaultsPath = options.defaultPath || resolve(appPath, './config/defaults.yml'); var configPath = argv.config; if (!configPath && !paths) { paths = self._getDefaultPaths(appName, appPath); } // first load defaults... // the defaults file locks the object model, so all settings must be defined here. // // anything not defined here won't be able to be set. // this forces everyone to keep the defaults file up to date, and in essence becomes // the documentation for our settings if (!fs.existsSync(defaultsPath)) { throw new Error('Default file missing. Expected path is: ' + defaultsPath); } settings = self._loadYamlFile(defaultsPath) || {}; (paths || []).forEach(function(path, i) { if (fs.existsSync(path)) { settings = mergeInto(settings, self._loadYamlFile(path)); } }); if (configPath) { settings = mergeInto(settings, self._loadYamlFile(configPath)); } Object.defineProperty(self, '_settings', {value: settings}); }
javascript
function LokeConfig(appName, options) { options = options || {}; // check args if (typeof appName !== 'string' || appName === '') { throw new Error('LokeConfig requires appName to be provided'); } if (Array.isArray(options)) { // Support original argument format: if (options.length === 0) { throw new Error('"paths" contains no items'); } options = {paths: options.slice(1), defaultPath: options[0]}; } var settings, self = this; var argv = minimist(process.argv.slice(2)); var appPath = options.appPath || dirname(require.main.filename); var paths = options.paths; var defaultsPath = options.defaultPath || resolve(appPath, './config/defaults.yml'); var configPath = argv.config; if (!configPath && !paths) { paths = self._getDefaultPaths(appName, appPath); } // first load defaults... // the defaults file locks the object model, so all settings must be defined here. // // anything not defined here won't be able to be set. // this forces everyone to keep the defaults file up to date, and in essence becomes // the documentation for our settings if (!fs.existsSync(defaultsPath)) { throw new Error('Default file missing. Expected path is: ' + defaultsPath); } settings = self._loadYamlFile(defaultsPath) || {}; (paths || []).forEach(function(path, i) { if (fs.existsSync(path)) { settings = mergeInto(settings, self._loadYamlFile(path)); } }); if (configPath) { settings = mergeInto(settings, self._loadYamlFile(configPath)); } Object.defineProperty(self, '_settings', {value: settings}); }
[ "function", "LokeConfig", "(", "appName", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "// check args", "if", "(", "typeof", "appName", "!==", "'string'", "||", "appName", "===", "''", ")", "{", "throw", "new", "Error", "(", "'LokeConfig requires appName to be provided'", ")", ";", "}", "if", "(", "Array", ".", "isArray", "(", "options", ")", ")", "{", "// Support original argument format:", "if", "(", "options", ".", "length", "===", "0", ")", "{", "throw", "new", "Error", "(", "'\"paths\" contains no items'", ")", ";", "}", "options", "=", "{", "paths", ":", "options", ".", "slice", "(", "1", ")", ",", "defaultPath", ":", "options", "[", "0", "]", "}", ";", "}", "var", "settings", ",", "self", "=", "this", ";", "var", "argv", "=", "minimist", "(", "process", ".", "argv", ".", "slice", "(", "2", ")", ")", ";", "var", "appPath", "=", "options", ".", "appPath", "||", "dirname", "(", "require", ".", "main", ".", "filename", ")", ";", "var", "paths", "=", "options", ".", "paths", ";", "var", "defaultsPath", "=", "options", ".", "defaultPath", "||", "resolve", "(", "appPath", ",", "'./config/defaults.yml'", ")", ";", "var", "configPath", "=", "argv", ".", "config", ";", "if", "(", "!", "configPath", "&&", "!", "paths", ")", "{", "paths", "=", "self", ".", "_getDefaultPaths", "(", "appName", ",", "appPath", ")", ";", "}", "// first load defaults...", "// the defaults file locks the object model, so all settings must be defined here.", "//", "// anything not defined here won't be able to be set.", "// this forces everyone to keep the defaults file up to date, and in essence becomes", "// the documentation for our settings", "if", "(", "!", "fs", ".", "existsSync", "(", "defaultsPath", ")", ")", "{", "throw", "new", "Error", "(", "'Default file missing. Expected path is: '", "+", "defaultsPath", ")", ";", "}", "settings", "=", "self", ".", "_loadYamlFile", "(", "defaultsPath", ")", "||", "{", "}", ";", "(", "paths", "||", "[", "]", ")", ".", "forEach", "(", "function", "(", "path", ",", "i", ")", "{", "if", "(", "fs", ".", "existsSync", "(", "path", ")", ")", "{", "settings", "=", "mergeInto", "(", "settings", ",", "self", ".", "_loadYamlFile", "(", "path", ")", ")", ";", "}", "}", ")", ";", "if", "(", "configPath", ")", "{", "settings", "=", "mergeInto", "(", "settings", ",", "self", ".", "_loadYamlFile", "(", "configPath", ")", ")", ";", "}", "Object", ".", "defineProperty", "(", "self", ",", "'_settings'", ",", "{", "value", ":", "settings", "}", ")", ";", "}" ]
Creates a new LOKE config instance @param {String} appName The application name or ID. Should match where the config files are placed/ @param {String} [options.appPath] @param {[String]} [options.paths] An array of full paths to search for files. The first file on the list should be the defaults and specify all values.
[ "Creates", "a", "new", "LOKE", "config", "instance" ]
84c207b2724c919bc6dde5efd7e7328591908cce
https://github.com/LOKE/loke-config/blob/84c207b2724c919bc6dde5efd7e7328591908cce/lib/loke-config.js#L18-L66
55,504
adiwidjaja/frontend-pagebuilder
js/tinymce/plugins/bbcode/plugin.js
function (s) { s = Tools.trim(s); function rep(re, str) { s = s.replace(re, str); } // example: <strong> to [b] rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi, "[url=$1]$2[/url]"); rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]"); rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]"); rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]"); rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]"); rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi, "[color=$1]$2[/color]"); rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[color=$1]$2[/color]"); rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi, "[size=$1]$2[/size]"); rep(/<font>(.*?)<\/font>/gi, "$1"); rep(/<img.*?src=\"(.*?)\".*?\/>/gi, "[img]$1[/img]"); rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi, "[code]$1[/code]"); rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi, "[quote]$1[/quote]"); rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi, "[code][b]$1[/b][/code]"); rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi, "[quote][b]$1[/b][/quote]"); rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi, "[code][i]$1[/i][/code]"); rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi, "[quote][i]$1[/i][/quote]"); rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi, "[code][u]$1[/u][/code]"); rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi, "[quote][u]$1[/u][/quote]"); rep(/<\/(strong|b)>/gi, "[/b]"); rep(/<(strong|b)>/gi, "[b]"); rep(/<\/(em|i)>/gi, "[/i]"); rep(/<(em|i)>/gi, "[i]"); rep(/<\/u>/gi, "[/u]"); rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi, "[u]$1[/u]"); rep(/<u>/gi, "[u]"); rep(/<blockquote[^>]*>/gi, "[quote]"); rep(/<\/blockquote>/gi, "[/quote]"); rep(/<br \/>/gi, "\n"); rep(/<br\/>/gi, "\n"); rep(/<br>/gi, "\n"); rep(/<p>/gi, ""); rep(/<\/p>/gi, "\n"); rep(/&nbsp;|\u00a0/gi, " "); rep(/&quot;/gi, "\""); rep(/&lt;/gi, "<"); rep(/&gt;/gi, ">"); rep(/&amp;/gi, "&"); return s; }
javascript
function (s) { s = Tools.trim(s); function rep(re, str) { s = s.replace(re, str); } // example: <strong> to [b] rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi, "[url=$1]$2[/url]"); rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]"); rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]"); rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[code][color=$1]$2[/color][/code]"); rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[quote][color=$1]$2[/color][/quote]"); rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi, "[color=$1]$2[/color]"); rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi, "[color=$1]$2[/color]"); rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi, "[size=$1]$2[/size]"); rep(/<font>(.*?)<\/font>/gi, "$1"); rep(/<img.*?src=\"(.*?)\".*?\/>/gi, "[img]$1[/img]"); rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi, "[code]$1[/code]"); rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi, "[quote]$1[/quote]"); rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi, "[code][b]$1[/b][/code]"); rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi, "[quote][b]$1[/b][/quote]"); rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi, "[code][i]$1[/i][/code]"); rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi, "[quote][i]$1[/i][/quote]"); rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi, "[code][u]$1[/u][/code]"); rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi, "[quote][u]$1[/u][/quote]"); rep(/<\/(strong|b)>/gi, "[/b]"); rep(/<(strong|b)>/gi, "[b]"); rep(/<\/(em|i)>/gi, "[/i]"); rep(/<(em|i)>/gi, "[i]"); rep(/<\/u>/gi, "[/u]"); rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi, "[u]$1[/u]"); rep(/<u>/gi, "[u]"); rep(/<blockquote[^>]*>/gi, "[quote]"); rep(/<\/blockquote>/gi, "[/quote]"); rep(/<br \/>/gi, "\n"); rep(/<br\/>/gi, "\n"); rep(/<br>/gi, "\n"); rep(/<p>/gi, ""); rep(/<\/p>/gi, "\n"); rep(/&nbsp;|\u00a0/gi, " "); rep(/&quot;/gi, "\""); rep(/&lt;/gi, "<"); rep(/&gt;/gi, ">"); rep(/&amp;/gi, "&"); return s; }
[ "function", "(", "s", ")", "{", "s", "=", "Tools", ".", "trim", "(", "s", ")", ";", "function", "rep", "(", "re", ",", "str", ")", "{", "s", "=", "s", ".", "replace", "(", "re", ",", "str", ")", ";", "}", "// example: <strong> to [b]", "rep", "(", "/", "<a.*?href=\\\"(.*?)\\\".*?>(.*?)<\\/a>", "/", "gi", ",", "\"[url=$1]$2[/url]\"", ")", ";", "rep", "(", "/", "<font.*?color=\\\"(.*?)\\\".*?class=\\\"codeStyle\\\".*?>(.*?)<\\/font>", "/", "gi", ",", "\"[code][color=$1]$2[/color][/code]\"", ")", ";", "rep", "(", "/", "<font.*?color=\\\"(.*?)\\\".*?class=\\\"quoteStyle\\\".*?>(.*?)<\\/font>", "/", "gi", ",", "\"[quote][color=$1]$2[/color][/quote]\"", ")", ";", "rep", "(", "/", "<font.*?class=\\\"codeStyle\\\".*?color=\\\"(.*?)\\\".*?>(.*?)<\\/font>", "/", "gi", ",", "\"[code][color=$1]$2[/color][/code]\"", ")", ";", "rep", "(", "/", "<font.*?class=\\\"quoteStyle\\\".*?color=\\\"(.*?)\\\".*?>(.*?)<\\/font>", "/", "gi", ",", "\"[quote][color=$1]$2[/color][/quote]\"", ")", ";", "rep", "(", "/", "<span style=\\\"color: ?(.*?);\\\">(.*?)<\\/span>", "/", "gi", ",", "\"[color=$1]$2[/color]\"", ")", ";", "rep", "(", "/", "<font.*?color=\\\"(.*?)\\\".*?>(.*?)<\\/font>", "/", "gi", ",", "\"[color=$1]$2[/color]\"", ")", ";", "rep", "(", "/", "<span style=\\\"font-size:(.*?);\\\">(.*?)<\\/span>", "/", "gi", ",", "\"[size=$1]$2[/size]\"", ")", ";", "rep", "(", "/", "<font>(.*?)<\\/font>", "/", "gi", ",", "\"$1\"", ")", ";", "rep", "(", "/", "<img.*?src=\\\"(.*?)\\\".*?\\/>", "/", "gi", ",", "\"[img]$1[/img]\"", ")", ";", "rep", "(", "/", "<span class=\\\"codeStyle\\\">(.*?)<\\/span>", "/", "gi", ",", "\"[code]$1[/code]\"", ")", ";", "rep", "(", "/", "<span class=\\\"quoteStyle\\\">(.*?)<\\/span>", "/", "gi", ",", "\"[quote]$1[/quote]\"", ")", ";", "rep", "(", "/", "<strong class=\\\"codeStyle\\\">(.*?)<\\/strong>", "/", "gi", ",", "\"[code][b]$1[/b][/code]\"", ")", ";", "rep", "(", "/", "<strong class=\\\"quoteStyle\\\">(.*?)<\\/strong>", "/", "gi", ",", "\"[quote][b]$1[/b][/quote]\"", ")", ";", "rep", "(", "/", "<em class=\\\"codeStyle\\\">(.*?)<\\/em>", "/", "gi", ",", "\"[code][i]$1[/i][/code]\"", ")", ";", "rep", "(", "/", "<em class=\\\"quoteStyle\\\">(.*?)<\\/em>", "/", "gi", ",", "\"[quote][i]$1[/i][/quote]\"", ")", ";", "rep", "(", "/", "<u class=\\\"codeStyle\\\">(.*?)<\\/u>", "/", "gi", ",", "\"[code][u]$1[/u][/code]\"", ")", ";", "rep", "(", "/", "<u class=\\\"quoteStyle\\\">(.*?)<\\/u>", "/", "gi", ",", "\"[quote][u]$1[/u][/quote]\"", ")", ";", "rep", "(", "/", "<\\/(strong|b)>", "/", "gi", ",", "\"[/b]\"", ")", ";", "rep", "(", "/", "<(strong|b)>", "/", "gi", ",", "\"[b]\"", ")", ";", "rep", "(", "/", "<\\/(em|i)>", "/", "gi", ",", "\"[/i]\"", ")", ";", "rep", "(", "/", "<(em|i)>", "/", "gi", ",", "\"[i]\"", ")", ";", "rep", "(", "/", "<\\/u>", "/", "gi", ",", "\"[/u]\"", ")", ";", "rep", "(", "/", "<span style=\\\"text-decoration: ?underline;\\\">(.*?)<\\/span>", "/", "gi", ",", "\"[u]$1[/u]\"", ")", ";", "rep", "(", "/", "<u>", "/", "gi", ",", "\"[u]\"", ")", ";", "rep", "(", "/", "<blockquote[^>]*>", "/", "gi", ",", "\"[quote]\"", ")", ";", "rep", "(", "/", "<\\/blockquote>", "/", "gi", ",", "\"[/quote]\"", ")", ";", "rep", "(", "/", "<br \\/>", "/", "gi", ",", "\"\\n\"", ")", ";", "rep", "(", "/", "<br\\/>", "/", "gi", ",", "\"\\n\"", ")", ";", "rep", "(", "/", "<br>", "/", "gi", ",", "\"\\n\"", ")", ";", "rep", "(", "/", "<p>", "/", "gi", ",", "\"\"", ")", ";", "rep", "(", "/", "<\\/p>", "/", "gi", ",", "\"\\n\"", ")", ";", "rep", "(", "/", "&nbsp;|\\u00a0", "/", "gi", ",", "\" \"", ")", ";", "rep", "(", "/", "&quot;", "/", "gi", ",", "\"\\\"\"", ")", ";", "rep", "(", "/", "&lt;", "/", "gi", ",", "\"<\"", ")", ";", "rep", "(", "/", "&gt;", "/", "gi", ",", "\">\"", ")", ";", "rep", "(", "/", "&amp;", "/", "gi", ",", "\"&\"", ")", ";", "return", "s", ";", "}" ]
Private methods HTML -> BBCode in PunBB dialect
[ "Private", "methods", "HTML", "-", ">", "BBCode", "in", "PunBB", "dialect" ]
a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f
https://github.com/adiwidjaja/frontend-pagebuilder/blob/a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f/js/tinymce/plugins/bbcode/plugin.js#L182-L229
55,505
adiwidjaja/frontend-pagebuilder
js/tinymce/plugins/bbcode/plugin.js
function (s) { s = Tools.trim(s); function rep(re, str) { s = s.replace(re, str); } // example: [b] to <strong> rep(/\n/gi, "<br />"); rep(/\[b\]/gi, "<strong>"); rep(/\[\/b\]/gi, "</strong>"); rep(/\[i\]/gi, "<em>"); rep(/\[\/i\]/gi, "</em>"); rep(/\[u\]/gi, "<u>"); rep(/\[\/u\]/gi, "</u>"); rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi, "<a href=\"$1\">$2</a>"); rep(/\[url\](.*?)\[\/url\]/gi, "<a href=\"$1\">$1</a>"); rep(/\[img\](.*?)\[\/img\]/gi, "<img src=\"$1\" />"); rep(/\[color=(.*?)\](.*?)\[\/color\]/gi, "<font color=\"$1\">$2</font>"); rep(/\[code\](.*?)\[\/code\]/gi, "<span class=\"codeStyle\">$1</span>&nbsp;"); rep(/\[quote.*?\](.*?)\[\/quote\]/gi, "<span class=\"quoteStyle\">$1</span>&nbsp;"); return s; }
javascript
function (s) { s = Tools.trim(s); function rep(re, str) { s = s.replace(re, str); } // example: [b] to <strong> rep(/\n/gi, "<br />"); rep(/\[b\]/gi, "<strong>"); rep(/\[\/b\]/gi, "</strong>"); rep(/\[i\]/gi, "<em>"); rep(/\[\/i\]/gi, "</em>"); rep(/\[u\]/gi, "<u>"); rep(/\[\/u\]/gi, "</u>"); rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi, "<a href=\"$1\">$2</a>"); rep(/\[url\](.*?)\[\/url\]/gi, "<a href=\"$1\">$1</a>"); rep(/\[img\](.*?)\[\/img\]/gi, "<img src=\"$1\" />"); rep(/\[color=(.*?)\](.*?)\[\/color\]/gi, "<font color=\"$1\">$2</font>"); rep(/\[code\](.*?)\[\/code\]/gi, "<span class=\"codeStyle\">$1</span>&nbsp;"); rep(/\[quote.*?\](.*?)\[\/quote\]/gi, "<span class=\"quoteStyle\">$1</span>&nbsp;"); return s; }
[ "function", "(", "s", ")", "{", "s", "=", "Tools", ".", "trim", "(", "s", ")", ";", "function", "rep", "(", "re", ",", "str", ")", "{", "s", "=", "s", ".", "replace", "(", "re", ",", "str", ")", ";", "}", "// example: [b] to <strong>", "rep", "(", "/", "\\n", "/", "gi", ",", "\"<br />\"", ")", ";", "rep", "(", "/", "\\[b\\]", "/", "gi", ",", "\"<strong>\"", ")", ";", "rep", "(", "/", "\\[\\/b\\]", "/", "gi", ",", "\"</strong>\"", ")", ";", "rep", "(", "/", "\\[i\\]", "/", "gi", ",", "\"<em>\"", ")", ";", "rep", "(", "/", "\\[\\/i\\]", "/", "gi", ",", "\"</em>\"", ")", ";", "rep", "(", "/", "\\[u\\]", "/", "gi", ",", "\"<u>\"", ")", ";", "rep", "(", "/", "\\[\\/u\\]", "/", "gi", ",", "\"</u>\"", ")", ";", "rep", "(", "/", "\\[url=([^\\]]+)\\](.*?)\\[\\/url\\]", "/", "gi", ",", "\"<a href=\\\"$1\\\">$2</a>\"", ")", ";", "rep", "(", "/", "\\[url\\](.*?)\\[\\/url\\]", "/", "gi", ",", "\"<a href=\\\"$1\\\">$1</a>\"", ")", ";", "rep", "(", "/", "\\[img\\](.*?)\\[\\/img\\]", "/", "gi", ",", "\"<img src=\\\"$1\\\" />\"", ")", ";", "rep", "(", "/", "\\[color=(.*?)\\](.*?)\\[\\/color\\]", "/", "gi", ",", "\"<font color=\\\"$1\\\">$2</font>\"", ")", ";", "rep", "(", "/", "\\[code\\](.*?)\\[\\/code\\]", "/", "gi", ",", "\"<span class=\\\"codeStyle\\\">$1</span>&nbsp;\"", ")", ";", "rep", "(", "/", "\\[quote.*?\\](.*?)\\[\\/quote\\]", "/", "gi", ",", "\"<span class=\\\"quoteStyle\\\">$1</span>&nbsp;\"", ")", ";", "return", "s", ";", "}" ]
BBCode -> HTML from PunBB dialect
[ "BBCode", "-", ">", "HTML", "from", "PunBB", "dialect" ]
a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f
https://github.com/adiwidjaja/frontend-pagebuilder/blob/a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f/js/tinymce/plugins/bbcode/plugin.js#L232-L255
55,506
Ma3Route/node-sdk
lib/auth.js
addSignature
function addSignature(key, secret, uri, body, options) { if (!_.isString(key) || !_.isString(secret)) { throw new errors.AuthenticationRequiredError("key and secret must be provided for signing requests"); } options = options || {}; // remove signature if it exists in URI object uri.removeSearch("signature"); // add api key uri.removeSearch("apikey"); uri.addQuery("apikey", key); // create a valid baseurl // consider that some users might be sitting behind a proxy var signatureBase; var baseurl = options.apiVersion === 3 ? utils.setup().baseurlv3 : utils.setup().baseurl; baseurl = trim(baseurl, "/"); var url = uri.toString(); url = trim(url.substring(0, url.indexOf("?")), "/"); if (url.search(baseurl) !== -1) { baseurl = url; } else { baseurl += "/" + uri.segment().join("/"); } signatureBase = encodeURIComponent(trim(baseurl, "/")); // append a "?" - preparing for parameter string signatureBase += "?"; // create the parameter string var params = uri.search(true); var paramsKeys = utils.sortKeys(params); var parameterString = ""; paramsKeys.forEach(function(paramKey) { if (parameterString !== "") { parameterString += "&"; } parameterString += encodeURIComponent(paramKey) + "=" + encodeURIComponent(params[paramKey]); }); // concatenating the parameter string signatureBase += parameterString; // concatenating the request body, if available if (body) { if (typeof body !== "string") { body = JSON.stringify(body); } signatureBase += encodeURIComponent(body); } // creating a hash var hmac = crypto.createHmac("sha256", secret); hmac.update(signatureBase); var hash = hmac.digest("hex"); // add hash to original uri object uri.addQuery("signature", hash); return uri; }
javascript
function addSignature(key, secret, uri, body, options) { if (!_.isString(key) || !_.isString(secret)) { throw new errors.AuthenticationRequiredError("key and secret must be provided for signing requests"); } options = options || {}; // remove signature if it exists in URI object uri.removeSearch("signature"); // add api key uri.removeSearch("apikey"); uri.addQuery("apikey", key); // create a valid baseurl // consider that some users might be sitting behind a proxy var signatureBase; var baseurl = options.apiVersion === 3 ? utils.setup().baseurlv3 : utils.setup().baseurl; baseurl = trim(baseurl, "/"); var url = uri.toString(); url = trim(url.substring(0, url.indexOf("?")), "/"); if (url.search(baseurl) !== -1) { baseurl = url; } else { baseurl += "/" + uri.segment().join("/"); } signatureBase = encodeURIComponent(trim(baseurl, "/")); // append a "?" - preparing for parameter string signatureBase += "?"; // create the parameter string var params = uri.search(true); var paramsKeys = utils.sortKeys(params); var parameterString = ""; paramsKeys.forEach(function(paramKey) { if (parameterString !== "") { parameterString += "&"; } parameterString += encodeURIComponent(paramKey) + "=" + encodeURIComponent(params[paramKey]); }); // concatenating the parameter string signatureBase += parameterString; // concatenating the request body, if available if (body) { if (typeof body !== "string") { body = JSON.stringify(body); } signatureBase += encodeURIComponent(body); } // creating a hash var hmac = crypto.createHmac("sha256", secret); hmac.update(signatureBase); var hash = hmac.digest("hex"); // add hash to original uri object uri.addQuery("signature", hash); return uri; }
[ "function", "addSignature", "(", "key", ",", "secret", ",", "uri", ",", "body", ",", "options", ")", "{", "if", "(", "!", "_", ".", "isString", "(", "key", ")", "||", "!", "_", ".", "isString", "(", "secret", ")", ")", "{", "throw", "new", "errors", ".", "AuthenticationRequiredError", "(", "\"key and secret must be provided for signing requests\"", ")", ";", "}", "options", "=", "options", "||", "{", "}", ";", "// remove signature if it exists in URI object", "uri", ".", "removeSearch", "(", "\"signature\"", ")", ";", "// add api key", "uri", ".", "removeSearch", "(", "\"apikey\"", ")", ";", "uri", ".", "addQuery", "(", "\"apikey\"", ",", "key", ")", ";", "// create a valid baseurl", "// consider that some users might be sitting behind a proxy", "var", "signatureBase", ";", "var", "baseurl", "=", "options", ".", "apiVersion", "===", "3", "?", "utils", ".", "setup", "(", ")", ".", "baseurlv3", ":", "utils", ".", "setup", "(", ")", ".", "baseurl", ";", "baseurl", "=", "trim", "(", "baseurl", ",", "\"/\"", ")", ";", "var", "url", "=", "uri", ".", "toString", "(", ")", ";", "url", "=", "trim", "(", "url", ".", "substring", "(", "0", ",", "url", ".", "indexOf", "(", "\"?\"", ")", ")", ",", "\"/\"", ")", ";", "if", "(", "url", ".", "search", "(", "baseurl", ")", "!==", "-", "1", ")", "{", "baseurl", "=", "url", ";", "}", "else", "{", "baseurl", "+=", "\"/\"", "+", "uri", ".", "segment", "(", ")", ".", "join", "(", "\"/\"", ")", ";", "}", "signatureBase", "=", "encodeURIComponent", "(", "trim", "(", "baseurl", ",", "\"/\"", ")", ")", ";", "// append a \"?\" - preparing for parameter string", "signatureBase", "+=", "\"?\"", ";", "// create the parameter string", "var", "params", "=", "uri", ".", "search", "(", "true", ")", ";", "var", "paramsKeys", "=", "utils", ".", "sortKeys", "(", "params", ")", ";", "var", "parameterString", "=", "\"\"", ";", "paramsKeys", ".", "forEach", "(", "function", "(", "paramKey", ")", "{", "if", "(", "parameterString", "!==", "\"\"", ")", "{", "parameterString", "+=", "\"&\"", ";", "}", "parameterString", "+=", "encodeURIComponent", "(", "paramKey", ")", "+", "\"=\"", "+", "encodeURIComponent", "(", "params", "[", "paramKey", "]", ")", ";", "}", ")", ";", "// concatenating the parameter string", "signatureBase", "+=", "parameterString", ";", "// concatenating the request body, if available", "if", "(", "body", ")", "{", "if", "(", "typeof", "body", "!==", "\"string\"", ")", "{", "body", "=", "JSON", ".", "stringify", "(", "body", ")", ";", "}", "signatureBase", "+=", "encodeURIComponent", "(", "body", ")", ";", "}", "// creating a hash", "var", "hmac", "=", "crypto", ".", "createHmac", "(", "\"sha256\"", ",", "secret", ")", ";", "hmac", ".", "update", "(", "signatureBase", ")", ";", "var", "hash", "=", "hmac", ".", "digest", "(", "\"hex\"", ")", ";", "// add hash to original uri object", "uri", ".", "addQuery", "(", "\"signature\"", ",", "hash", ")", ";", "return", "uri", ";", "}" ]
Add signature to URI instance for use in authenticating against the API. The request body will be stringified using JSON.stringify if its not a string. @private @memberof auth @param {String} key - used to identify the client @param {String} secret - used to sign the request @param {URIjs} uri - an instance of URIjs @param {*} body - request body @param {Object} [options] - options @param {Number} [options.apiVersion] - API version @return {URIjs} the same instance of URIjs @throws {errors.AuthenticationRequiredError}
[ "Add", "signature", "to", "URI", "instance", "for", "use", "in", "authenticating", "against", "the", "API", ".", "The", "request", "body", "will", "be", "stringified", "using", "JSON", ".", "stringify", "if", "its", "not", "a", "string", "." ]
a2769d97d77d6f762d23e743bf4c749e2bad0d8a
https://github.com/Ma3Route/node-sdk/blob/a2769d97d77d6f762d23e743bf4c749e2bad0d8a/lib/auth.js#L49-L112
55,507
Ma3Route/node-sdk
lib/auth.js
sign
function sign(key, secret, uri, body, options) { // add timestamp uri.addQuery("timestamp", utils.createTimestamp()); // add signature addSignature(key, secret, uri, body, options); return uri; }
javascript
function sign(key, secret, uri, body, options) { // add timestamp uri.addQuery("timestamp", utils.createTimestamp()); // add signature addSignature(key, secret, uri, body, options); return uri; }
[ "function", "sign", "(", "key", ",", "secret", ",", "uri", ",", "body", ",", "options", ")", "{", "// add timestamp", "uri", ".", "addQuery", "(", "\"timestamp\"", ",", "utils", ".", "createTimestamp", "(", ")", ")", ";", "// add signature", "addSignature", "(", "key", ",", "secret", ",", "uri", ",", "body", ",", "options", ")", ";", "return", "uri", ";", "}" ]
Sign a URI instance. Automatically adds a timestamp to the URI instance. @public @param {String} key - key used to sign @param {String} secret - used to sign the request @param {URIjs} uri - an instance of URIjs @param {*} body - body to used in request @param {Object} [options] - options @param {Number} [options.apiVersion] - API version @return {URIjs} same instance of URIjs, i.e. 'uri' @throws {errors.AuthenticationRequiredError} if 'key' or 'secret' are invalid.
[ "Sign", "a", "URI", "instance", ".", "Automatically", "adds", "a", "timestamp", "to", "the", "URI", "instance", "." ]
a2769d97d77d6f762d23e743bf4c749e2bad0d8a
https://github.com/Ma3Route/node-sdk/blob/a2769d97d77d6f762d23e743bf4c749e2bad0d8a/lib/auth.js#L130-L138
55,508
ozinc/node-restify-links
lib/links.js
makeLink
function makeLink(rel, ldo) { var i, key, keys, result; if (typeof ldo === 'string') { return '<' + ldo + '>; rel="' + rel + '"'; } result = '<' + ldo.href + '>; rel="' + rel + '"'; keys = Object.keys(ldo); for (i = 0; i < keys.length; i += 1) { key = keys[i]; if (key !== 'href' && key !== 'rel') { result += '; ' + key + '="' + ldo[key] + '"'; } } return result; }
javascript
function makeLink(rel, ldo) { var i, key, keys, result; if (typeof ldo === 'string') { return '<' + ldo + '>; rel="' + rel + '"'; } result = '<' + ldo.href + '>; rel="' + rel + '"'; keys = Object.keys(ldo); for (i = 0; i < keys.length; i += 1) { key = keys[i]; if (key !== 'href' && key !== 'rel') { result += '; ' + key + '="' + ldo[key] + '"'; } } return result; }
[ "function", "makeLink", "(", "rel", ",", "ldo", ")", "{", "var", "i", ",", "key", ",", "keys", ",", "result", ";", "if", "(", "typeof", "ldo", "===", "'string'", ")", "{", "return", "'<'", "+", "ldo", "+", "'>; rel=\"'", "+", "rel", "+", "'\"'", ";", "}", "result", "=", "'<'", "+", "ldo", ".", "href", "+", "'>; rel=\"'", "+", "rel", "+", "'\"'", ";", "keys", "=", "Object", ".", "keys", "(", "ldo", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "keys", ".", "length", ";", "i", "+=", "1", ")", "{", "key", "=", "keys", "[", "i", "]", ";", "if", "(", "key", "!==", "'href'", "&&", "key", "!==", "'rel'", ")", "{", "result", "+=", "'; '", "+", "key", "+", "'=\"'", "+", "ldo", "[", "key", "]", "+", "'\"'", ";", "}", "}", "return", "result", ";", "}" ]
Set Link header field with the given `links`. Examples: res.links({ next: 'http://api.example.com/users?page=2', last: 'http://api.example.com/users?page=5' }); @param {Object} links @return {ServerResponse} @api public
[ "Set", "Link", "header", "field", "with", "the", "given", "links", "." ]
68213903fa4ff8d9e55697bff1e8cd2fa348089f
https://github.com/ozinc/node-restify-links/blob/68213903fa4ff8d9e55697bff1e8cd2fa348089f/lib/links.js#L18-L37
55,509
hpcloud/hpcloud-js
lib/objectstorage/index.js
newFromIdentity
function newFromIdentity(identity, region) { var service = identity.serviceByName('object-store', region); var endpoint = service.publicURL; var os = new ObjectStorage(identity.token(), endpoint); return os; }
javascript
function newFromIdentity(identity, region) { var service = identity.serviceByName('object-store', region); var endpoint = service.publicURL; var os = new ObjectStorage(identity.token(), endpoint); return os; }
[ "function", "newFromIdentity", "(", "identity", ",", "region", ")", "{", "var", "service", "=", "identity", ".", "serviceByName", "(", "'object-store'", ",", "region", ")", ";", "var", "endpoint", "=", "service", ".", "publicURL", ";", "var", "os", "=", "new", "ObjectStorage", "(", "identity", ".", "token", "(", ")", ",", "endpoint", ")", ";", "return", "os", ";", "}" ]
Create a new ObjectStorage instance from an IdentityServices Identity. @param {Identity} identity An identity with a service catalog. @param {string} region The availability zone. e.g. 'az-1.region-a.geo-1'. If this is omitted, the first available object storage will be used. @param {Function} fn A callback, which will receive an Error (if applicable) and an ObjectStorage instance.
[ "Create", "a", "new", "ObjectStorage", "instance", "from", "an", "IdentityServices", "Identity", "." ]
c457ea3ee6a21e361d1af0af70d64622b6910208
https://github.com/hpcloud/hpcloud-js/blob/c457ea3ee6a21e361d1af0af70d64622b6910208/lib/objectstorage/index.js#L57-L63
55,510
d08ble/livecomment
public/js/main.js
modifyState
function modifyState($n) { var state = self.state; function selectByStateRecursive(name) { if (state.recursive) { return $n.find(name); } else { return $n.children(name) } } var a; var b; if (state.mode == 'code') { a = selectByStateRecursive('pre:visible'); if (a.length > 0) // a.hide(); hideShowCode(a, 'hide'); else { a = selectByStateRecursive('pre'); // a.show(); hideShowCode(a, 'show'); } } if (state.mode == 'childs') { a = selectByStateRecursive('.node:visible'); if (a.length > 0) hideShowNodes(a, 'hide'); // a.hide(); else { a = selectByStateRecursive('.node'); // a.show(); hideShowNodes(a, 'show'); } } if (state.mode == 'code childs') { a = selectByStateRecursive('.node:hidden'); b = selectByStateRecursive('pre:hidden'); if (a.length > 0 || b.length > 0) { hideShowNodes(a, 'show'); hideShowCode(b, 'show'); // a.show(); // b.show(); } else { a = selectByStateRecursive('.node'); b = selectByStateRecursive('pre'); hideShowNodes(a, 'hide'); hideShowCode(b, 'hide'); // a.hide(); // b.hide(); } } }
javascript
function modifyState($n) { var state = self.state; function selectByStateRecursive(name) { if (state.recursive) { return $n.find(name); } else { return $n.children(name) } } var a; var b; if (state.mode == 'code') { a = selectByStateRecursive('pre:visible'); if (a.length > 0) // a.hide(); hideShowCode(a, 'hide'); else { a = selectByStateRecursive('pre'); // a.show(); hideShowCode(a, 'show'); } } if (state.mode == 'childs') { a = selectByStateRecursive('.node:visible'); if (a.length > 0) hideShowNodes(a, 'hide'); // a.hide(); else { a = selectByStateRecursive('.node'); // a.show(); hideShowNodes(a, 'show'); } } if (state.mode == 'code childs') { a = selectByStateRecursive('.node:hidden'); b = selectByStateRecursive('pre:hidden'); if (a.length > 0 || b.length > 0) { hideShowNodes(a, 'show'); hideShowCode(b, 'show'); // a.show(); // b.show(); } else { a = selectByStateRecursive('.node'); b = selectByStateRecursive('pre'); hideShowNodes(a, 'hide'); hideShowCode(b, 'hide'); // a.hide(); // b.hide(); } } }
[ "function", "modifyState", "(", "$n", ")", "{", "var", "state", "=", "self", ".", "state", ";", "function", "selectByStateRecursive", "(", "name", ")", "{", "if", "(", "state", ".", "recursive", ")", "{", "return", "$n", ".", "find", "(", "name", ")", ";", "}", "else", "{", "return", "$n", ".", "children", "(", "name", ")", "}", "}", "var", "a", ";", "var", "b", ";", "if", "(", "state", ".", "mode", "==", "'code'", ")", "{", "a", "=", "selectByStateRecursive", "(", "'pre:visible'", ")", ";", "if", "(", "a", ".", "length", ">", "0", ")", "// a.hide();", "hideShowCode", "(", "a", ",", "'hide'", ")", ";", "else", "{", "a", "=", "selectByStateRecursive", "(", "'pre'", ")", ";", "// a.show();", "hideShowCode", "(", "a", ",", "'show'", ")", ";", "}", "}", "if", "(", "state", ".", "mode", "==", "'childs'", ")", "{", "a", "=", "selectByStateRecursive", "(", "'.node:visible'", ")", ";", "if", "(", "a", ".", "length", ">", "0", ")", "hideShowNodes", "(", "a", ",", "'hide'", ")", ";", "// a.hide();", "else", "{", "a", "=", "selectByStateRecursive", "(", "'.node'", ")", ";", "// a.show();", "hideShowNodes", "(", "a", ",", "'show'", ")", ";", "}", "}", "if", "(", "state", ".", "mode", "==", "'code childs'", ")", "{", "a", "=", "selectByStateRecursive", "(", "'.node:hidden'", ")", ";", "b", "=", "selectByStateRecursive", "(", "'pre:hidden'", ")", ";", "if", "(", "a", ".", "length", ">", "0", "||", "b", ".", "length", ">", "0", ")", "{", "hideShowNodes", "(", "a", ",", "'show'", ")", ";", "hideShowCode", "(", "b", ",", "'show'", ")", ";", "// a.show();", "// b.show();", "}", "else", "{", "a", "=", "selectByStateRecursive", "(", "'.node'", ")", ";", "b", "=", "selectByStateRecursive", "(", "'pre'", ")", ";", "hideShowNodes", "(", "a", ",", "'hide'", ")", ";", "hideShowCode", "(", "b", ",", "'hide'", ")", ";", "// a.hide();", "// b.hide();", "}", "}", "}" ]
DOM UPDATE STATE [
[ "DOM", "UPDATE", "STATE", "[" ]
9c4a00878101501411668070b4f6e7719e10d1fd
https://github.com/d08ble/livecomment/blob/9c4a00878101501411668070b4f6e7719e10d1fd/public/js/main.js#L204-L257
55,511
UXFoundry/hashdo
lib/packs.js
function (baseUrl, cardsDirectory) { var packs = _.filter(FS.readdirSync(cardsDirectory), function (dir) { return _.startsWith(dir, 'hashdo-'); }); console.log('PACKS: Cards will be loaded from %s.', cardsDirectory); var packCounter = 0, cardCounter = 0, hiddenCounter = 0; for (var i = 0; i < packs.length; i++) { var isPackage = false, packDir = Path.join(cardsDirectory, packs[i]); // Check if the directory has a package.json file, otherwise ignore it, it's not a pack. try { FS.statSync(Path.join(packDir, 'package.json')); isPackage = true; } catch (err) {} if (isPackage) { var packageJson = FS.readFileSync(Path.join(packDir, 'package.json')), packageInfo = JSON.parse(packageJson.toString()), packInfo = packageInfo.pack, packCardsDir = Path.join(cardsDirectory, packs[i]), packCards = getPackCardFiles(packCardsDir), packName = packageInfo.name.replace('hashdo-', ''); if (packInfo) { packCounter++; if (!packInfo.hidden) { cardPacks[packName] = { name: packInfo.friendlyName, cards: {} }; for (var j = 0; j < packCards.length; j++) { var card = require(Path.join(packCardsDir, packCards[j])), cardName = packCards[j]; cardCounter++; cardPacks[packName].cards[cardName] = { pack: packName, card: cardName, name: card.name, description: card.description || '', icon: card.icon || _.trimEnd(baseUrl, '/') + '/' + packName + '/' + cardName + '/icon.png', baseUrl: _.trimEnd(baseUrl, '/') + '/' + packName + '/' + cardName, inputs: card.inputs }; } } else { hiddenCounter++; } } } } console.log('PACKS: %d packs and %d card(s) have been loaded (%d hidden).', packCounter, cardCounter, hiddenCounter); }
javascript
function (baseUrl, cardsDirectory) { var packs = _.filter(FS.readdirSync(cardsDirectory), function (dir) { return _.startsWith(dir, 'hashdo-'); }); console.log('PACKS: Cards will be loaded from %s.', cardsDirectory); var packCounter = 0, cardCounter = 0, hiddenCounter = 0; for (var i = 0; i < packs.length; i++) { var isPackage = false, packDir = Path.join(cardsDirectory, packs[i]); // Check if the directory has a package.json file, otherwise ignore it, it's not a pack. try { FS.statSync(Path.join(packDir, 'package.json')); isPackage = true; } catch (err) {} if (isPackage) { var packageJson = FS.readFileSync(Path.join(packDir, 'package.json')), packageInfo = JSON.parse(packageJson.toString()), packInfo = packageInfo.pack, packCardsDir = Path.join(cardsDirectory, packs[i]), packCards = getPackCardFiles(packCardsDir), packName = packageInfo.name.replace('hashdo-', ''); if (packInfo) { packCounter++; if (!packInfo.hidden) { cardPacks[packName] = { name: packInfo.friendlyName, cards: {} }; for (var j = 0; j < packCards.length; j++) { var card = require(Path.join(packCardsDir, packCards[j])), cardName = packCards[j]; cardCounter++; cardPacks[packName].cards[cardName] = { pack: packName, card: cardName, name: card.name, description: card.description || '', icon: card.icon || _.trimEnd(baseUrl, '/') + '/' + packName + '/' + cardName + '/icon.png', baseUrl: _.trimEnd(baseUrl, '/') + '/' + packName + '/' + cardName, inputs: card.inputs }; } } else { hiddenCounter++; } } } } console.log('PACKS: %d packs and %d card(s) have been loaded (%d hidden).', packCounter, cardCounter, hiddenCounter); }
[ "function", "(", "baseUrl", ",", "cardsDirectory", ")", "{", "var", "packs", "=", "_", ".", "filter", "(", "FS", ".", "readdirSync", "(", "cardsDirectory", ")", ",", "function", "(", "dir", ")", "{", "return", "_", ".", "startsWith", "(", "dir", ",", "'hashdo-'", ")", ";", "}", ")", ";", "console", ".", "log", "(", "'PACKS: Cards will be loaded from %s.'", ",", "cardsDirectory", ")", ";", "var", "packCounter", "=", "0", ",", "cardCounter", "=", "0", ",", "hiddenCounter", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "packs", ".", "length", ";", "i", "++", ")", "{", "var", "isPackage", "=", "false", ",", "packDir", "=", "Path", ".", "join", "(", "cardsDirectory", ",", "packs", "[", "i", "]", ")", ";", "// Check if the directory has a package.json file, otherwise ignore it, it's not a pack.", "try", "{", "FS", ".", "statSync", "(", "Path", ".", "join", "(", "packDir", ",", "'package.json'", ")", ")", ";", "isPackage", "=", "true", ";", "}", "catch", "(", "err", ")", "{", "}", "if", "(", "isPackage", ")", "{", "var", "packageJson", "=", "FS", ".", "readFileSync", "(", "Path", ".", "join", "(", "packDir", ",", "'package.json'", ")", ")", ",", "packageInfo", "=", "JSON", ".", "parse", "(", "packageJson", ".", "toString", "(", ")", ")", ",", "packInfo", "=", "packageInfo", ".", "pack", ",", "packCardsDir", "=", "Path", ".", "join", "(", "cardsDirectory", ",", "packs", "[", "i", "]", ")", ",", "packCards", "=", "getPackCardFiles", "(", "packCardsDir", ")", ",", "packName", "=", "packageInfo", ".", "name", ".", "replace", "(", "'hashdo-'", ",", "''", ")", ";", "if", "(", "packInfo", ")", "{", "packCounter", "++", ";", "if", "(", "!", "packInfo", ".", "hidden", ")", "{", "cardPacks", "[", "packName", "]", "=", "{", "name", ":", "packInfo", ".", "friendlyName", ",", "cards", ":", "{", "}", "}", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "packCards", ".", "length", ";", "j", "++", ")", "{", "var", "card", "=", "require", "(", "Path", ".", "join", "(", "packCardsDir", ",", "packCards", "[", "j", "]", ")", ")", ",", "cardName", "=", "packCards", "[", "j", "]", ";", "cardCounter", "++", ";", "cardPacks", "[", "packName", "]", ".", "cards", "[", "cardName", "]", "=", "{", "pack", ":", "packName", ",", "card", ":", "cardName", ",", "name", ":", "card", ".", "name", ",", "description", ":", "card", ".", "description", "||", "''", ",", "icon", ":", "card", ".", "icon", "||", "_", ".", "trimEnd", "(", "baseUrl", ",", "'/'", ")", "+", "'/'", "+", "packName", "+", "'/'", "+", "cardName", "+", "'/icon.png'", ",", "baseUrl", ":", "_", ".", "trimEnd", "(", "baseUrl", ",", "'/'", ")", "+", "'/'", "+", "packName", "+", "'/'", "+", "cardName", ",", "inputs", ":", "card", ".", "inputs", "}", ";", "}", "}", "else", "{", "hiddenCounter", "++", ";", "}", "}", "}", "}", "console", ".", "log", "(", "'PACKS: %d packs and %d card(s) have been loaded (%d hidden).'", ",", "packCounter", ",", "cardCounter", ",", "hiddenCounter", ")", ";", "}" ]
Initializes and caches the packs and card data. This function should be called before any other functions in the packs API. @method init @param {String} baseUrl The protocol and host name where your cards are being hosted. Eg: https://hashdo.com @param {String} cardsDirectory The directory where you packs and cards can be found and loaded from.
[ "Initializes", "and", "caches", "the", "packs", "and", "card", "data", ".", "This", "function", "should", "be", "called", "before", "any", "other", "functions", "in", "the", "packs", "API", "." ]
c2a0adcba0cca26d6ebe56bba17017b177609057
https://github.com/UXFoundry/hashdo/blob/c2a0adcba0cca26d6ebe56bba17017b177609057/lib/packs.js#L48-L109
55,512
UXFoundry/hashdo
lib/packs.js
function (filter) { if (cardCount > 0) { return cardCount; } else { cardCount = 0; if (filter) { filter = filter.toLowerCase(); _.each(_.keys(cardPacks), function (packKey) { _.each(_.keys(cardPacks[packKey].cards), function (cardKey) { var card = cardPacks[packKey].cards[cardKey]; if (Fuzzy(filter, card.name.toLowerCase())) { cardCount = cardCount + 1; } }); }); } else { _.each(_.keys(cardPacks), function (packKey) { cardCount = cardCount + _.keys(cardPacks[packKey].cards).length; }); } return cardCount; } }
javascript
function (filter) { if (cardCount > 0) { return cardCount; } else { cardCount = 0; if (filter) { filter = filter.toLowerCase(); _.each(_.keys(cardPacks), function (packKey) { _.each(_.keys(cardPacks[packKey].cards), function (cardKey) { var card = cardPacks[packKey].cards[cardKey]; if (Fuzzy(filter, card.name.toLowerCase())) { cardCount = cardCount + 1; } }); }); } else { _.each(_.keys(cardPacks), function (packKey) { cardCount = cardCount + _.keys(cardPacks[packKey].cards).length; }); } return cardCount; } }
[ "function", "(", "filter", ")", "{", "if", "(", "cardCount", ">", "0", ")", "{", "return", "cardCount", ";", "}", "else", "{", "cardCount", "=", "0", ";", "if", "(", "filter", ")", "{", "filter", "=", "filter", ".", "toLowerCase", "(", ")", ";", "_", ".", "each", "(", "_", ".", "keys", "(", "cardPacks", ")", ",", "function", "(", "packKey", ")", "{", "_", ".", "each", "(", "_", ".", "keys", "(", "cardPacks", "[", "packKey", "]", ".", "cards", ")", ",", "function", "(", "cardKey", ")", "{", "var", "card", "=", "cardPacks", "[", "packKey", "]", ".", "cards", "[", "cardKey", "]", ";", "if", "(", "Fuzzy", "(", "filter", ",", "card", ".", "name", ".", "toLowerCase", "(", ")", ")", ")", "{", "cardCount", "=", "cardCount", "+", "1", ";", "}", "}", ")", ";", "}", ")", ";", "}", "else", "{", "_", ".", "each", "(", "_", ".", "keys", "(", "cardPacks", ")", ",", "function", "(", "packKey", ")", "{", "cardCount", "=", "cardCount", "+", "_", ".", "keys", "(", "cardPacks", "[", "packKey", "]", ".", "cards", ")", ".", "length", ";", "}", ")", ";", "}", "return", "cardCount", ";", "}", "}" ]
Get the number of cards matching an optional filter. @method count @param {String} [filter] Optional filter for card names. The filter will use fuzzy matching. @returns {Number} The number of cards found matching the filter.
[ "Get", "the", "number", "of", "cards", "matching", "an", "optional", "filter", "." ]
c2a0adcba0cca26d6ebe56bba17017b177609057
https://github.com/UXFoundry/hashdo/blob/c2a0adcba0cca26d6ebe56bba17017b177609057/lib/packs.js#L119-L147
55,513
UXFoundry/hashdo
lib/packs.js
function (pack, card) { if (cardPacks[pack] && cardPacks[pack].cards[card]) { return cardPacks[pack].cards[card]; } }
javascript
function (pack, card) { if (cardPacks[pack] && cardPacks[pack].cards[card]) { return cardPacks[pack].cards[card]; } }
[ "function", "(", "pack", ",", "card", ")", "{", "if", "(", "cardPacks", "[", "pack", "]", "&&", "cardPacks", "[", "pack", "]", ".", "cards", "[", "card", "]", ")", "{", "return", "cardPacks", "[", "pack", "]", ".", "cards", "[", "card", "]", ";", "}", "}" ]
Get a specific card object. @method card @param {String} pack The pack name. @param {String} card The card name. @returns {Object} The card object macthing the pack and name provided, undefined if not found.
[ "Get", "a", "specific", "card", "object", "." ]
c2a0adcba0cca26d6ebe56bba17017b177609057
https://github.com/UXFoundry/hashdo/blob/c2a0adcba0cca26d6ebe56bba17017b177609057/lib/packs.js#L199-L203
55,514
jias/eoraptor.js
build/eoraptor.js
compile
function compile (str, options) { var id; var render; str = str || EMPTY; options = options || {}; id = options.id || str; render = eoraptor[id]; if (render) { return render; } var oTag = options.oTag || OTAG; var cTag = options.cTag || CTAG; var code = build(parse(str, oTag, cTag)); render = function (data) { var result; try { result = new Function('data', codePrefix + code)(data); } catch(err) { console.error('"' +err.message + '" from data and tpl below:'); console.log(data); console.log(str); } return result; }; render.render = render; render.source = 'function (data) {\n' + code + '\n}'; return eoraptor[id] = render; }
javascript
function compile (str, options) { var id; var render; str = str || EMPTY; options = options || {}; id = options.id || str; render = eoraptor[id]; if (render) { return render; } var oTag = options.oTag || OTAG; var cTag = options.cTag || CTAG; var code = build(parse(str, oTag, cTag)); render = function (data) { var result; try { result = new Function('data', codePrefix + code)(data); } catch(err) { console.error('"' +err.message + '" from data and tpl below:'); console.log(data); console.log(str); } return result; }; render.render = render; render.source = 'function (data) {\n' + code + '\n}'; return eoraptor[id] = render; }
[ "function", "compile", "(", "str", ",", "options", ")", "{", "var", "id", ";", "var", "render", ";", "str", "=", "str", "||", "EMPTY", ";", "options", "=", "options", "||", "{", "}", ";", "id", "=", "options", ".", "id", "||", "str", ";", "render", "=", "eoraptor", "[", "id", "]", ";", "if", "(", "render", ")", "{", "return", "render", ";", "}", "var", "oTag", "=", "options", ".", "oTag", "||", "OTAG", ";", "var", "cTag", "=", "options", ".", "cTag", "||", "CTAG", ";", "var", "code", "=", "build", "(", "parse", "(", "str", ",", "oTag", ",", "cTag", ")", ")", ";", "render", "=", "function", "(", "data", ")", "{", "var", "result", ";", "try", "{", "result", "=", "new", "Function", "(", "'data'", ",", "codePrefix", "+", "code", ")", "(", "data", ")", ";", "}", "catch", "(", "err", ")", "{", "console", ".", "error", "(", "'\"'", "+", "err", ".", "message", "+", "'\" from data and tpl below:'", ")", ";", "console", ".", "log", "(", "data", ")", ";", "console", ".", "log", "(", "str", ")", ";", "}", "return", "result", ";", "}", ";", "render", ".", "render", "=", "render", ";", "render", ".", "source", "=", "'function (data) {\\n'", "+", "code", "+", "'\\n}'", ";", "return", "eoraptor", "[", "id", "]", "=", "render", ";", "}" ]
to compile a template string to callable render @param {string} str a template string @param {object} options optional @param {string} options.id the unique name for the template @param {string} options.oTag set a one-off opening tag TODO oTag cTag
[ "to", "compile", "a", "template", "string", "to", "callable", "render" ]
65483f3c6c001d75de3f5c240d999351f73d1fc1
https://github.com/jias/eoraptor.js/blob/65483f3c6c001d75de3f5c240d999351f73d1fc1/build/eoraptor.js#L100-L135
55,515
jias/eoraptor.js
build/eoraptor.js
isOTag
function isOTag (str, oTag, index) { var l = oTag.length, s = str.substr(index, l), sign = str.charAt(index+l); // NOTE 要保证sign有值 如果当前的index已经是字符串尾部 如'foo{{' sign为空 if (oTag === s && sign && SIGN.indexOf(sign) > -1) { return { str: s + sign, index: index, // sign: signType[str.charAt(index+l)], // TODO: delete sign: str.charAt(index+l), // ignore the last oTag charts and the sign char, // l(oTag.length) - 1(oTag's first char) + 1(sign's char) jump: l }; } }
javascript
function isOTag (str, oTag, index) { var l = oTag.length, s = str.substr(index, l), sign = str.charAt(index+l); // NOTE 要保证sign有值 如果当前的index已经是字符串尾部 如'foo{{' sign为空 if (oTag === s && sign && SIGN.indexOf(sign) > -1) { return { str: s + sign, index: index, // sign: signType[str.charAt(index+l)], // TODO: delete sign: str.charAt(index+l), // ignore the last oTag charts and the sign char, // l(oTag.length) - 1(oTag's first char) + 1(sign's char) jump: l }; } }
[ "function", "isOTag", "(", "str", ",", "oTag", ",", "index", ")", "{", "var", "l", "=", "oTag", ".", "length", ",", "s", "=", "str", ".", "substr", "(", "index", ",", "l", ")", ",", "sign", "=", "str", ".", "charAt", "(", "index", "+", "l", ")", ";", "// NOTE 要保证sign有值 如果当前的index已经是字符串尾部 如'foo{{' sign为空", "if", "(", "oTag", "===", "s", "&&", "sign", "&&", "SIGN", ".", "indexOf", "(", "sign", ")", ">", "-", "1", ")", "{", "return", "{", "str", ":", "s", "+", "sign", ",", "index", ":", "index", ",", "// sign: signType[str.charAt(index+l)], // TODO: delete", "sign", ":", "str", ".", "charAt", "(", "index", "+", "l", ")", ",", "// ignore the last oTag charts and the sign char,", "// l(oTag.length) - 1(oTag's first char) + 1(sign's char)", "jump", ":", "l", "}", ";", "}", "}" ]
Is it the first char of an opening tag?
[ "Is", "it", "the", "first", "char", "of", "an", "opening", "tag?" ]
65483f3c6c001d75de3f5c240d999351f73d1fc1
https://github.com/jias/eoraptor.js/blob/65483f3c6c001d75de3f5c240d999351f73d1fc1/build/eoraptor.js#L238-L252
55,516
jias/eoraptor.js
build/eoraptor.js
isCTag
function isCTag (str, cTag, index) { var l = cTag.length, s = str.substr(index, l); if (cTag === s) { return { str: s, index: index, type: 1, jump: l - 1 }; } }
javascript
function isCTag (str, cTag, index) { var l = cTag.length, s = str.substr(index, l); if (cTag === s) { return { str: s, index: index, type: 1, jump: l - 1 }; } }
[ "function", "isCTag", "(", "str", ",", "cTag", ",", "index", ")", "{", "var", "l", "=", "cTag", ".", "length", ",", "s", "=", "str", ".", "substr", "(", "index", ",", "l", ")", ";", "if", "(", "cTag", "===", "s", ")", "{", "return", "{", "str", ":", "s", ",", "index", ":", "index", ",", "type", ":", "1", ",", "jump", ":", "l", "-", "1", "}", ";", "}", "}" ]
Is it the first char of a closing tag?
[ "Is", "it", "the", "first", "char", "of", "a", "closing", "tag?" ]
65483f3c6c001d75de3f5c240d999351f73d1fc1
https://github.com/jias/eoraptor.js/blob/65483f3c6c001d75de3f5c240d999351f73d1fc1/build/eoraptor.js#L255-L265
55,517
jias/eoraptor.js
build/eoraptor.js
isOSB
function isOSB (str, index) { var quote = str.charAt(index+1); if (quote === DQ || quote === SQ) { return { str: LSB + quote, index: index, quote: quote, jump: 1 }; } }
javascript
function isOSB (str, index) { var quote = str.charAt(index+1); if (quote === DQ || quote === SQ) { return { str: LSB + quote, index: index, quote: quote, jump: 1 }; } }
[ "function", "isOSB", "(", "str", ",", "index", ")", "{", "var", "quote", "=", "str", ".", "charAt", "(", "index", "+", "1", ")", ";", "if", "(", "quote", "===", "DQ", "||", "quote", "===", "SQ", ")", "{", "return", "{", "str", ":", "LSB", "+", "quote", ",", "index", ":", "index", ",", "quote", ":", "quote", ",", "jump", ":", "1", "}", ";", "}", "}" ]
Is it the first char of an opening square bracket expression?
[ "Is", "it", "the", "first", "char", "of", "an", "opening", "square", "bracket", "expression?" ]
65483f3c6c001d75de3f5c240d999351f73d1fc1
https://github.com/jias/eoraptor.js/blob/65483f3c6c001d75de3f5c240d999351f73d1fc1/build/eoraptor.js#L272-L282
55,518
jias/eoraptor.js
build/eoraptor.js
isCSB
function isCSB (str, index, quote) { if (str.charAt(index+1) === RSB) { return { str: quote + RSB, index: index, quote: quote, jump: 1 }; } }
javascript
function isCSB (str, index, quote) { if (str.charAt(index+1) === RSB) { return { str: quote + RSB, index: index, quote: quote, jump: 1 }; } }
[ "function", "isCSB", "(", "str", ",", "index", ",", "quote", ")", "{", "if", "(", "str", ".", "charAt", "(", "index", "+", "1", ")", "===", "RSB", ")", "{", "return", "{", "str", ":", "quote", "+", "RSB", ",", "index", ":", "index", ",", "quote", ":", "quote", ",", "jump", ":", "1", "}", ";", "}", "}" ]
Is it the first char of a closing square bracket expression?
[ "Is", "it", "the", "first", "char", "of", "a", "closing", "square", "bracket", "expression?" ]
65483f3c6c001d75de3f5c240d999351f73d1fc1
https://github.com/jias/eoraptor.js/blob/65483f3c6c001d75de3f5c240d999351f73d1fc1/build/eoraptor.js#L285-L294
55,519
melvincarvalho/rdf-shell
lib/ws.js
ws
function ws(argv, callback) { if (!argv[2]) { console.error("url is required"); console.error("Usage : ws <url>"); process.exit(-1); } var uri = argv[2]; var updatesVia = 'wss://' + uri.split('/')[2] + '/'; var s; var connect = function(){ s = new wss(updatesVia, { origin: 'http://websocket.org' }); s.on('error', function() { callback('socket error'); setTimeout(connect, RECONNECT); }); s.on('open', function open() { var sub = 'sub ' + uri; callback(null, sub); s.send(sub); // periodically ping server setInterval(function() { var message = 'ping'; debug(null, message); s.send(message); }, INTERVAL); }); }; connect(); s.on('message', function message(data, flags) { callback(null, data); }); }
javascript
function ws(argv, callback) { if (!argv[2]) { console.error("url is required"); console.error("Usage : ws <url>"); process.exit(-1); } var uri = argv[2]; var updatesVia = 'wss://' + uri.split('/')[2] + '/'; var s; var connect = function(){ s = new wss(updatesVia, { origin: 'http://websocket.org' }); s.on('error', function() { callback('socket error'); setTimeout(connect, RECONNECT); }); s.on('open', function open() { var sub = 'sub ' + uri; callback(null, sub); s.send(sub); // periodically ping server setInterval(function() { var message = 'ping'; debug(null, message); s.send(message); }, INTERVAL); }); }; connect(); s.on('message', function message(data, flags) { callback(null, data); }); }
[ "function", "ws", "(", "argv", ",", "callback", ")", "{", "if", "(", "!", "argv", "[", "2", "]", ")", "{", "console", ".", "error", "(", "\"url is required\"", ")", ";", "console", ".", "error", "(", "\"Usage : ws <url>\"", ")", ";", "process", ".", "exit", "(", "-", "1", ")", ";", "}", "var", "uri", "=", "argv", "[", "2", "]", ";", "var", "updatesVia", "=", "'wss://'", "+", "uri", ".", "split", "(", "'/'", ")", "[", "2", "]", "+", "'/'", ";", "var", "s", ";", "var", "connect", "=", "function", "(", ")", "{", "s", "=", "new", "wss", "(", "updatesVia", ",", "{", "origin", ":", "'http://websocket.org'", "}", ")", ";", "s", ".", "on", "(", "'error'", ",", "function", "(", ")", "{", "callback", "(", "'socket error'", ")", ";", "setTimeout", "(", "connect", ",", "RECONNECT", ")", ";", "}", ")", ";", "s", ".", "on", "(", "'open'", ",", "function", "open", "(", ")", "{", "var", "sub", "=", "'sub '", "+", "uri", ";", "callback", "(", "null", ",", "sub", ")", ";", "s", ".", "send", "(", "sub", ")", ";", "// periodically ping server", "setInterval", "(", "function", "(", ")", "{", "var", "message", "=", "'ping'", ";", "debug", "(", "null", ",", "message", ")", ";", "s", ".", "send", "(", "message", ")", ";", "}", ",", "INTERVAL", ")", ";", "}", ")", ";", "}", ";", "connect", "(", ")", ";", "s", ".", "on", "(", "'message'", ",", "function", "message", "(", "data", ",", "flags", ")", "{", "callback", "(", "null", ",", "data", ")", ";", "}", ")", ";", "}" ]
ws runs a websocket against a URI @param {String} argv[2] url @callback {bin~cb} callback
[ "ws", "runs", "a", "websocket", "against", "a", "URI" ]
bf2015f6f333855e69a18ce3ec9e917bbddfb425
https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/ws.js#L18-L59
55,520
melvincarvalho/rdf-shell
lib/ws.js
bin
function bin(argv) { ws(argv, function(err, res) { if (err) { console.err(err); } else { console.log(res); } }); }
javascript
function bin(argv) { ws(argv, function(err, res) { if (err) { console.err(err); } else { console.log(res); } }); }
[ "function", "bin", "(", "argv", ")", "{", "ws", "(", "argv", ",", "function", "(", "err", ",", "res", ")", "{", "if", "(", "err", ")", "{", "console", ".", "err", "(", "err", ")", ";", "}", "else", "{", "console", ".", "log", "(", "res", ")", ";", "}", "}", ")", ";", "}" ]
ws as a command @param {String} argv[2] login @callback {bin~cb} callback
[ "ws", "as", "a", "command" ]
bf2015f6f333855e69a18ce3ec9e917bbddfb425
https://github.com/melvincarvalho/rdf-shell/blob/bf2015f6f333855e69a18ce3ec9e917bbddfb425/lib/ws.js#L68-L76
55,521
Ma3Route/node-sdk
example/init.js
init
function init() { /** * Get API key and secret. */ var auth = utils.getAuth(); /** * Set up the SDK. */ sdk.utils.setup({ key: auth.key, secret: auth.secret, }); return { out: out, sdk: sdk, }; }
javascript
function init() { /** * Get API key and secret. */ var auth = utils.getAuth(); /** * Set up the SDK. */ sdk.utils.setup({ key: auth.key, secret: auth.secret, }); return { out: out, sdk: sdk, }; }
[ "function", "init", "(", ")", "{", "/**\n * Get API key and secret.\n */", "var", "auth", "=", "utils", ".", "getAuth", "(", ")", ";", "/**\n * Set up the SDK.\n */", "sdk", ".", "utils", ".", "setup", "(", "{", "key", ":", "auth", ".", "key", ",", "secret", ":", "auth", ".", "secret", ",", "}", ")", ";", "return", "{", "out", ":", "out", ",", "sdk", ":", "sdk", ",", "}", ";", "}" ]
Initialize. This has placed in this separate file so as to avoid duplicate code all over. It simply does the following: 1. `require()` the modules we will be using frequently (already done above) 2. get API key and secret 3. setup the SDK so we can use it immediately 4. return an object containing modules from (1) above and the SDK module
[ "Initialize", ".", "This", "has", "placed", "in", "this", "separate", "file", "so", "as", "to", "avoid", "duplicate", "code", "all", "over", "." ]
a2769d97d77d6f762d23e743bf4c749e2bad0d8a
https://github.com/Ma3Route/node-sdk/blob/a2769d97d77d6f762d23e743bf4c749e2bad0d8a/example/init.js#L23-L41
55,522
bionikspoon/unipath
src/index.js
unipath
function unipath(...bases) { return partial; /** * Resolve base with paths. * * @param {...string} paths - Paths to join to base * @returns {string} Resolved path */ function partial(...paths) { const baseList = bases.length ? bases : [ '.' ]; const pathList = paths.length ? paths : [ '.' ]; return path.resolve(path.join(...baseList, ...pathList)); } }
javascript
function unipath(...bases) { return partial; /** * Resolve base with paths. * * @param {...string} paths - Paths to join to base * @returns {string} Resolved path */ function partial(...paths) { const baseList = bases.length ? bases : [ '.' ]; const pathList = paths.length ? paths : [ '.' ]; return path.resolve(path.join(...baseList, ...pathList)); } }
[ "function", "unipath", "(", "...", "bases", ")", "{", "return", "partial", ";", "/**\n * Resolve base with paths.\n *\n * @param {...string} paths - Paths to join to base\n * @returns {string} Resolved path\n */", "function", "partial", "(", "...", "paths", ")", "{", "const", "baseList", "=", "bases", ".", "length", "?", "bases", ":", "[", "'.'", "]", ";", "const", "pathList", "=", "paths", ".", "length", "?", "paths", ":", "[", "'.'", "]", ";", "return", "path", ".", "resolve", "(", "path", ".", "join", "(", "...", "baseList", ",", "...", "pathList", ")", ")", ";", "}", "}" ]
Create a path.join partial. @param {...string} bases - Base paths @returns {partial} Path join partial
[ "Create", "a", "path", ".", "join", "partial", "." ]
91d196b902f66f85ffb8b9a37ae9bb51b86507e7
https://github.com/bionikspoon/unipath/blob/91d196b902f66f85ffb8b9a37ae9bb51b86507e7/src/index.js#L11-L26
55,523
gtriggiano/dnsmq-messagebus
src/MasterBroker.js
startHeartbeats
function startHeartbeats () { _isMaster = true if (_hearbeatInterval) return debug('starting heartbeats') _sendHeartbeat() _hearbeatInterval = setInterval(_sendHeartbeat, HEARTBEAT_INTERVAL) }
javascript
function startHeartbeats () { _isMaster = true if (_hearbeatInterval) return debug('starting heartbeats') _sendHeartbeat() _hearbeatInterval = setInterval(_sendHeartbeat, HEARTBEAT_INTERVAL) }
[ "function", "startHeartbeats", "(", ")", "{", "_isMaster", "=", "true", "if", "(", "_hearbeatInterval", ")", "return", "debug", "(", "'starting heartbeats'", ")", "_sendHeartbeat", "(", ")", "_hearbeatInterval", "=", "setInterval", "(", "_sendHeartbeat", ",", "HEARTBEAT_INTERVAL", ")", "}" ]
starts the emission of heartbeats at regular intervals
[ "starts", "the", "emission", "of", "heartbeats", "at", "regular", "intervals" ]
ab935cae537f8a7e61a6ed6fba247661281c9374
https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterBroker.js#L114-L120
55,524
digiaonline/generator-nord-backbone
app/templates/_Gruntfile.js
findBowerMainFiles
function findBowerMainFiles(componentsPath) { var files = []; fs.readdirSync(componentsPath).filter(function (file) { return fs.statSync(componentsPath + '/' + file).isDirectory(); }).forEach(function (packageName) { var bowerJsonPath = componentsPath + '/' + packageName + '/bower.json'; if (fs.existsSync(bowerJsonPath)) { var json = grunt.file.readJSON(bowerJsonPath); files.push(packageName + '/' + json.main); } }); return files; }
javascript
function findBowerMainFiles(componentsPath) { var files = []; fs.readdirSync(componentsPath).filter(function (file) { return fs.statSync(componentsPath + '/' + file).isDirectory(); }).forEach(function (packageName) { var bowerJsonPath = componentsPath + '/' + packageName + '/bower.json'; if (fs.existsSync(bowerJsonPath)) { var json = grunt.file.readJSON(bowerJsonPath); files.push(packageName + '/' + json.main); } }); return files; }
[ "function", "findBowerMainFiles", "(", "componentsPath", ")", "{", "var", "files", "=", "[", "]", ";", "fs", ".", "readdirSync", "(", "componentsPath", ")", ".", "filter", "(", "function", "(", "file", ")", "{", "return", "fs", ".", "statSync", "(", "componentsPath", "+", "'/'", "+", "file", ")", ".", "isDirectory", "(", ")", ";", "}", ")", ".", "forEach", "(", "function", "(", "packageName", ")", "{", "var", "bowerJsonPath", "=", "componentsPath", "+", "'/'", "+", "packageName", "+", "'/bower.json'", ";", "if", "(", "fs", ".", "existsSync", "(", "bowerJsonPath", ")", ")", "{", "var", "json", "=", "grunt", ".", "file", ".", "readJSON", "(", "bowerJsonPath", ")", ";", "files", ".", "push", "(", "packageName", "+", "'/'", "+", "json", ".", "main", ")", ";", "}", "}", ")", ";", "return", "files", ";", "}" ]
Parses the given components path and returns a list with the main file for each bower dependency. @param {string} componentsPath path to Bower components @returns {Array} list of files
[ "Parses", "the", "given", "components", "path", "and", "returns", "a", "list", "with", "the", "main", "file", "for", "each", "bower", "dependency", "." ]
bc962e16b6354c7a4034ce09cf4030b9d300202e
https://github.com/digiaonline/generator-nord-backbone/blob/bc962e16b6354c7a4034ce09cf4030b9d300202e/app/templates/_Gruntfile.js#L10-L24
55,525
brianloveswords/gogo
lib/base.js
extraction
function extraction(o) { return _.map(o, function (spec, field) { var fn = _.extract(spec, ['mutators', direction]) || _.identity; return [field, fn]; }); }
javascript
function extraction(o) { return _.map(o, function (spec, field) { var fn = _.extract(spec, ['mutators', direction]) || _.identity; return [field, fn]; }); }
[ "function", "extraction", "(", "o", ")", "{", "return", "_", ".", "map", "(", "o", ",", "function", "(", "spec", ",", "field", ")", "{", "var", "fn", "=", "_", ".", "extract", "(", "spec", ",", "[", "'mutators'", ",", "direction", "]", ")", "||", "_", ".", "identity", ";", "return", "[", "field", ",", "fn", "]", ";", "}", ")", ";", "}" ]
make a zipped array of field, mutator
[ "make", "a", "zipped", "array", "of", "field", "mutator" ]
f17ee794e0439ed961907f52b91bcb74dcca351a
https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/base.js#L97-L102
55,526
brianloveswords/gogo
lib/base.js
cleanup
function cleanup(a) { return _.filter(a, function (a) { var field = a[0]; return attr[field]; }); }
javascript
function cleanup(a) { return _.filter(a, function (a) { var field = a[0]; return attr[field]; }); }
[ "function", "cleanup", "(", "a", ")", "{", "return", "_", ".", "filter", "(", "a", ",", "function", "(", "a", ")", "{", "var", "field", "=", "a", "[", "0", "]", ";", "return", "attr", "[", "field", "]", ";", "}", ")", ";", "}" ]
drop all fields that aren't found in the attributes array
[ "drop", "all", "fields", "that", "aren", "t", "found", "in", "the", "attributes", "array" ]
f17ee794e0439ed961907f52b91bcb74dcca351a
https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/base.js#L105-L110
55,527
brianloveswords/gogo
lib/base.js
getMutations
function getMutations(spec, attr) { var fns = compose(extraction, cleanup, stitch)(spec); return _.callmap(fns, attr); }
javascript
function getMutations(spec, attr) { var fns = compose(extraction, cleanup, stitch)(spec); return _.callmap(fns, attr); }
[ "function", "getMutations", "(", "spec", ",", "attr", ")", "{", "var", "fns", "=", "compose", "(", "extraction", ",", "cleanup", ",", "stitch", ")", "(", "spec", ")", ";", "return", "_", ".", "callmap", "(", "fns", ",", "attr", ")", ";", "}" ]
call of the functions in the mutators fn object with the values of the attributes object
[ "call", "of", "the", "functions", "in", "the", "mutators", "fn", "object", "with", "the", "values", "of", "the", "attributes", "object" ]
f17ee794e0439ed961907f52b91bcb74dcca351a
https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/base.js#L117-L120
55,528
muttr/libmuttr
lib/connection.js
Connection
function Connection(options) { if (!(this instanceof Connection)) { return new Connection(options); } events.EventEmitter.call(this); this.options = merge(Object.create(Connection.DEFAULTS), options); this._log = new kademlia.Logger(this.options.logLevel); this._natClient = nat.createClient(); }
javascript
function Connection(options) { if (!(this instanceof Connection)) { return new Connection(options); } events.EventEmitter.call(this); this.options = merge(Object.create(Connection.DEFAULTS), options); this._log = new kademlia.Logger(this.options.logLevel); this._natClient = nat.createClient(); }
[ "function", "Connection", "(", "options", ")", "{", "if", "(", "!", "(", "this", "instanceof", "Connection", ")", ")", "{", "return", "new", "Connection", "(", "options", ")", ";", "}", "events", ".", "EventEmitter", ".", "call", "(", "this", ")", ";", "this", ".", "options", "=", "merge", "(", "Object", ".", "create", "(", "Connection", ".", "DEFAULTS", ")", ",", "options", ")", ";", "this", ".", "_log", "=", "new", "kademlia", ".", "Logger", "(", "this", ".", "options", ".", "logLevel", ")", ";", "this", ".", "_natClient", "=", "nat", ".", "createClient", "(", ")", ";", "}" ]
Creates a connection the the Muttr DHT @constructor @param {object} options @param {string} options.address @param {number} options.port @param {array} options.seeds @param {object} options.seeds[] @param {string} options.seeds[].address @param {number} options.seeds[].port @param {object} options.storage @param {function} options.storage.get @param {function} options.storage.put @param {function} options.storage.del @param {function} options.storage.createReadStream @param {boolean} options.forwardPort @param {boolean} options.logLevel
[ "Creates", "a", "connection", "the", "the", "Muttr", "DHT" ]
2e4fda9cb2b47b8febe30585f54196d39d79e2e5
https://github.com/muttr/libmuttr/blob/2e4fda9cb2b47b8febe30585f54196d39d79e2e5/lib/connection.js#L60-L71
55,529
redisjs/jsr-validate
lib/validators/auth.js
auth
function auth(cmd, args, info) { var pass = args[0]; if(pass instanceof Buffer) { pass = pass.toString(); } if(!info.conf.requirepass) { throw AuthNotSet; }else if(pass !== info.conf.requirepass) { throw InvalidPassword; } return true; }
javascript
function auth(cmd, args, info) { var pass = args[0]; if(pass instanceof Buffer) { pass = pass.toString(); } if(!info.conf.requirepass) { throw AuthNotSet; }else if(pass !== info.conf.requirepass) { throw InvalidPassword; } return true; }
[ "function", "auth", "(", "cmd", ",", "args", ",", "info", ")", "{", "var", "pass", "=", "args", "[", "0", "]", ";", "if", "(", "pass", "instanceof", "Buffer", ")", "{", "pass", "=", "pass", ".", "toString", "(", ")", ";", "}", "if", "(", "!", "info", ".", "conf", ".", "requirepass", ")", "{", "throw", "AuthNotSet", ";", "}", "else", "if", "(", "pass", "!==", "info", ".", "conf", ".", "requirepass", ")", "{", "throw", "InvalidPassword", ";", "}", "return", "true", ";", "}" ]
Authentication validation. @param cmd The command name - always AUTH. @param args The command arguments. @param info The server information.
[ "Authentication", "validation", "." ]
2e0dddafb32c019ef9293a35b96cdd78dd8e4ae5
https://github.com/redisjs/jsr-validate/blob/2e0dddafb32c019ef9293a35b96cdd78dd8e4ae5/lib/validators/auth.js#L13-L24
55,530
jurca/idb-entity
es2015/equals.js
equals
function equals(value1, value2, traversedValues) { if (!(value1 instanceof Object)) { return value1 === value2 } for (let wrappedType of WRAPPED_TYPES) { if (value1 instanceof wrappedType) { return (value2 instanceof wrappedType) && (value1.valueOf() === value2.valueOf()) } } if (value1 instanceof RegExp) { return (value2 instanceof RegExp) && (value1.source === value2.source) && (value2.flags === value2.flags) } for (let uninspectableType of UNINSPECTABLE_TYPES) { if (value1 instanceof uninspectableType) { return (value2 instanceof uninspectableType) && (value1 === value2) } } if ((typeof ArrayBuffer === "function") && (value1 instanceof ArrayBuffer)) { return (value2 instanceof ArrayBuffer) && equals(new Int8Array(value1), new Int8Array(value2), traversedValues) } if ((typeof DataView === "function") && (value1 instanceof DataView)) { return (value2 instanceof DataView) && equals( new Int8Array(value1.buffer, value1.byteOffset, value1.byteLength), new Int8Array(value2.buffer, value2.byteOffset, value2.byteLength), traversedValues ) } for (let arrayType of TYPED_ARRAY_TYPES) { if (value1 instanceof arrayType) { return (value2 instanceof arrayType) && arrayEquals(value1, value2, traversedValues) } } if ((typeof ImageData === "function") && (value1 instanceof ImageData)) { return (value2 instanceof ImageData) && (value1.width === value2.width) && (value1.height === value2.height) && equals(value1.data, value2.data, traversedValues) } if (value1 instanceof Array) { return (value2 instanceof Array) && arrayEquals(value1, value2, traversedValues) } if (value1 instanceof Map) { return mapEquals(value1, value2, traversedValues) } if (value1 instanceof Set) { return setEquals(value1, value2, traversedValues) } if (isPlainObjectOrEntity(value1) && isPlainObjectOrEntity(value2)) { return objectEquals(value1, value2, traversedValues) } throw new Error(`Unsupported argument types: ${value1}, ${value2}`) }
javascript
function equals(value1, value2, traversedValues) { if (!(value1 instanceof Object)) { return value1 === value2 } for (let wrappedType of WRAPPED_TYPES) { if (value1 instanceof wrappedType) { return (value2 instanceof wrappedType) && (value1.valueOf() === value2.valueOf()) } } if (value1 instanceof RegExp) { return (value2 instanceof RegExp) && (value1.source === value2.source) && (value2.flags === value2.flags) } for (let uninspectableType of UNINSPECTABLE_TYPES) { if (value1 instanceof uninspectableType) { return (value2 instanceof uninspectableType) && (value1 === value2) } } if ((typeof ArrayBuffer === "function") && (value1 instanceof ArrayBuffer)) { return (value2 instanceof ArrayBuffer) && equals(new Int8Array(value1), new Int8Array(value2), traversedValues) } if ((typeof DataView === "function") && (value1 instanceof DataView)) { return (value2 instanceof DataView) && equals( new Int8Array(value1.buffer, value1.byteOffset, value1.byteLength), new Int8Array(value2.buffer, value2.byteOffset, value2.byteLength), traversedValues ) } for (let arrayType of TYPED_ARRAY_TYPES) { if (value1 instanceof arrayType) { return (value2 instanceof arrayType) && arrayEquals(value1, value2, traversedValues) } } if ((typeof ImageData === "function") && (value1 instanceof ImageData)) { return (value2 instanceof ImageData) && (value1.width === value2.width) && (value1.height === value2.height) && equals(value1.data, value2.data, traversedValues) } if (value1 instanceof Array) { return (value2 instanceof Array) && arrayEquals(value1, value2, traversedValues) } if (value1 instanceof Map) { return mapEquals(value1, value2, traversedValues) } if (value1 instanceof Set) { return setEquals(value1, value2, traversedValues) } if (isPlainObjectOrEntity(value1) && isPlainObjectOrEntity(value2)) { return objectEquals(value1, value2, traversedValues) } throw new Error(`Unsupported argument types: ${value1}, ${value2}`) }
[ "function", "equals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "{", "if", "(", "!", "(", "value1", "instanceof", "Object", ")", ")", "{", "return", "value1", "===", "value2", "}", "for", "(", "let", "wrappedType", "of", "WRAPPED_TYPES", ")", "{", "if", "(", "value1", "instanceof", "wrappedType", ")", "{", "return", "(", "value2", "instanceof", "wrappedType", ")", "&&", "(", "value1", ".", "valueOf", "(", ")", "===", "value2", ".", "valueOf", "(", ")", ")", "}", "}", "if", "(", "value1", "instanceof", "RegExp", ")", "{", "return", "(", "value2", "instanceof", "RegExp", ")", "&&", "(", "value1", ".", "source", "===", "value2", ".", "source", ")", "&&", "(", "value2", ".", "flags", "===", "value2", ".", "flags", ")", "}", "for", "(", "let", "uninspectableType", "of", "UNINSPECTABLE_TYPES", ")", "{", "if", "(", "value1", "instanceof", "uninspectableType", ")", "{", "return", "(", "value2", "instanceof", "uninspectableType", ")", "&&", "(", "value1", "===", "value2", ")", "}", "}", "if", "(", "(", "typeof", "ArrayBuffer", "===", "\"function\"", ")", "&&", "(", "value1", "instanceof", "ArrayBuffer", ")", ")", "{", "return", "(", "value2", "instanceof", "ArrayBuffer", ")", "&&", "equals", "(", "new", "Int8Array", "(", "value1", ")", ",", "new", "Int8Array", "(", "value2", ")", ",", "traversedValues", ")", "}", "if", "(", "(", "typeof", "DataView", "===", "\"function\"", ")", "&&", "(", "value1", "instanceof", "DataView", ")", ")", "{", "return", "(", "value2", "instanceof", "DataView", ")", "&&", "equals", "(", "new", "Int8Array", "(", "value1", ".", "buffer", ",", "value1", ".", "byteOffset", ",", "value1", ".", "byteLength", ")", ",", "new", "Int8Array", "(", "value2", ".", "buffer", ",", "value2", ".", "byteOffset", ",", "value2", ".", "byteLength", ")", ",", "traversedValues", ")", "}", "for", "(", "let", "arrayType", "of", "TYPED_ARRAY_TYPES", ")", "{", "if", "(", "value1", "instanceof", "arrayType", ")", "{", "return", "(", "value2", "instanceof", "arrayType", ")", "&&", "arrayEquals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "}", "}", "if", "(", "(", "typeof", "ImageData", "===", "\"function\"", ")", "&&", "(", "value1", "instanceof", "ImageData", ")", ")", "{", "return", "(", "value2", "instanceof", "ImageData", ")", "&&", "(", "value1", ".", "width", "===", "value2", ".", "width", ")", "&&", "(", "value1", ".", "height", "===", "value2", ".", "height", ")", "&&", "equals", "(", "value1", ".", "data", ",", "value2", ".", "data", ",", "traversedValues", ")", "}", "if", "(", "value1", "instanceof", "Array", ")", "{", "return", "(", "value2", "instanceof", "Array", ")", "&&", "arrayEquals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "}", "if", "(", "value1", "instanceof", "Map", ")", "{", "return", "mapEquals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "}", "if", "(", "value1", "instanceof", "Set", ")", "{", "return", "setEquals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "}", "if", "(", "isPlainObjectOrEntity", "(", "value1", ")", "&&", "isPlainObjectOrEntity", "(", "value2", ")", ")", "{", "return", "objectEquals", "(", "value1", ",", "value2", ",", "traversedValues", ")", "}", "throw", "new", "Error", "(", "`", "${", "value1", "}", "${", "value2", "}", "`", ")", "}" ]
Compares the provided values to determine whether they are equal. @param {*} value1 The 1st value to compare. @param {*} value2 The 2nd value to compare. @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the values are equal.
[ "Compares", "the", "provided", "values", "to", "determine", "whether", "they", "are", "equal", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L47-L118
55,531
jurca/idb-entity
es2015/equals.js
objectEquals
function objectEquals(object1, object2, traversedValues) { let keys1 = Object.keys(object1) let keys2 = Object.keys(object2) return structureEquals( object1, object2, keys1, keys2, (object, key) => object[key], traversedValues ) }
javascript
function objectEquals(object1, object2, traversedValues) { let keys1 = Object.keys(object1) let keys2 = Object.keys(object2) return structureEquals( object1, object2, keys1, keys2, (object, key) => object[key], traversedValues ) }
[ "function", "objectEquals", "(", "object1", ",", "object2", ",", "traversedValues", ")", "{", "let", "keys1", "=", "Object", ".", "keys", "(", "object1", ")", "let", "keys2", "=", "Object", ".", "keys", "(", "object2", ")", "return", "structureEquals", "(", "object1", ",", "object2", ",", "keys1", ",", "keys2", ",", "(", "object", ",", "key", ")", "=>", "object", "[", "key", "]", ",", "traversedValues", ")", "}" ]
Compares the two provided plain objects. @param {Object<string, *>} object1 The 1st object to compare. @param {Object<string, *>} object2 The 2nd object to compare. @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the objects are equal.
[ "Compares", "the", "two", "provided", "plain", "objects", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L130-L142
55,532
jurca/idb-entity
es2015/equals.js
setEquals
function setEquals(set1, set2, traversedValues) { if (set1.size !== set2.size) { return false } return structureEquals( set1, set2, iteratorToArray(set1.values()), iteratorToArray(set2.values()), () => undefined, traversedValues ) }
javascript
function setEquals(set1, set2, traversedValues) { if (set1.size !== set2.size) { return false } return structureEquals( set1, set2, iteratorToArray(set1.values()), iteratorToArray(set2.values()), () => undefined, traversedValues ) }
[ "function", "setEquals", "(", "set1", ",", "set2", ",", "traversedValues", ")", "{", "if", "(", "set1", ".", "size", "!==", "set2", ".", "size", ")", "{", "return", "false", "}", "return", "structureEquals", "(", "set1", ",", "set2", ",", "iteratorToArray", "(", "set1", ".", "values", "(", ")", ")", ",", "iteratorToArray", "(", "set2", ".", "values", "(", ")", ")", ",", "(", ")", "=>", "undefined", ",", "traversedValues", ")", "}" ]
Compares the two provided sets. @param {Set<*>} set1 The 1st set to compare. @param {Set<*>} set2 The 2nd set to compare. @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the sets are equal.
[ "Compares", "the", "two", "provided", "sets", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L154-L167
55,533
jurca/idb-entity
es2015/equals.js
mapEquals
function mapEquals(map1, map2, traversedValues) { if (map1.size !== map2.size) { return false } return structureEquals( map1, map2, iteratorToArray(map1.keys()), iteratorToArray(map2.keys()), (map, key) => map.get(key), traversedValues ) }
javascript
function mapEquals(map1, map2, traversedValues) { if (map1.size !== map2.size) { return false } return structureEquals( map1, map2, iteratorToArray(map1.keys()), iteratorToArray(map2.keys()), (map, key) => map.get(key), traversedValues ) }
[ "function", "mapEquals", "(", "map1", ",", "map2", ",", "traversedValues", ")", "{", "if", "(", "map1", ".", "size", "!==", "map2", ".", "size", ")", "{", "return", "false", "}", "return", "structureEquals", "(", "map1", ",", "map2", ",", "iteratorToArray", "(", "map1", ".", "keys", "(", ")", ")", ",", "iteratorToArray", "(", "map2", ".", "keys", "(", ")", ")", ",", "(", "map", ",", "key", ")", "=>", "map", ".", "get", "(", "key", ")", ",", "traversedValues", ")", "}" ]
Compares the two provided maps. @param {Map<*, *>} map1 The 1st map to compare. @param {Map<*, *>} map2 The 2nd map to compare. @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the maps are equal.
[ "Compares", "the", "two", "provided", "maps", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L179-L192
55,534
jurca/idb-entity
es2015/equals.js
arrayEquals
function arrayEquals(array1, array2, traversedValues) { if (array1.length !== array2.length) { return false } return structureEquals( array1, array2, iteratorToArray(array1.keys()), iteratorToArray(array2.keys()), (array, key) => array[key], traversedValues ) }
javascript
function arrayEquals(array1, array2, traversedValues) { if (array1.length !== array2.length) { return false } return structureEquals( array1, array2, iteratorToArray(array1.keys()), iteratorToArray(array2.keys()), (array, key) => array[key], traversedValues ) }
[ "function", "arrayEquals", "(", "array1", ",", "array2", ",", "traversedValues", ")", "{", "if", "(", "array1", ".", "length", "!==", "array2", ".", "length", ")", "{", "return", "false", "}", "return", "structureEquals", "(", "array1", ",", "array2", ",", "iteratorToArray", "(", "array1", ".", "keys", "(", ")", ")", ",", "iteratorToArray", "(", "array2", ".", "keys", "(", ")", ")", ",", "(", "array", ",", "key", ")", "=>", "array", "[", "key", "]", ",", "traversedValues", ")", "}" ]
Compares the two provided arrays. @param {*[]} array1 The 1st array to compare. @param {*[]} array2 The 2nd array to compare. @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the arrays are equal.
[ "Compares", "the", "two", "provided", "arrays", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L204-L217
55,535
jurca/idb-entity
es2015/equals.js
structureEquals
function structureEquals(structure1, structure2, keys1, keys2, getter, traversedValues) { if (keys1.length !== keys2.length) { return false } traversedValues.set(structure1, structure2) for (let i = keys1.length; i--;) { let key1 = keys1[i] let key2 = keys2[i] if ((key1 instanceof Object) && traversedValues.has(key1)) { if (traversedValues.get(key1) !== key2) { return false } else { continue } } if (!equals(key1, key2, traversedValues)) { return false } if (key1 instanceof Object) { traversedValues.set(key1, key2) } let value1 = getter(structure1, key1) let value2 = getter(structure2, key2) if ((value1 instanceof Object) && traversedValues.has(value1)) { if (traversedValues.get(value1) !== value2) { return false } else { continue } } if (!equals(value1, value2, traversedValues)) { return false } if (value1 instanceof Object) { traversedValues.set(value1, value2) } } return true }
javascript
function structureEquals(structure1, structure2, keys1, keys2, getter, traversedValues) { if (keys1.length !== keys2.length) { return false } traversedValues.set(structure1, structure2) for (let i = keys1.length; i--;) { let key1 = keys1[i] let key2 = keys2[i] if ((key1 instanceof Object) && traversedValues.has(key1)) { if (traversedValues.get(key1) !== key2) { return false } else { continue } } if (!equals(key1, key2, traversedValues)) { return false } if (key1 instanceof Object) { traversedValues.set(key1, key2) } let value1 = getter(structure1, key1) let value2 = getter(structure2, key2) if ((value1 instanceof Object) && traversedValues.has(value1)) { if (traversedValues.get(value1) !== value2) { return false } else { continue } } if (!equals(value1, value2, traversedValues)) { return false } if (value1 instanceof Object) { traversedValues.set(value1, value2) } } return true }
[ "function", "structureEquals", "(", "structure1", ",", "structure2", ",", "keys1", ",", "keys2", ",", "getter", ",", "traversedValues", ")", "{", "if", "(", "keys1", ".", "length", "!==", "keys2", ".", "length", ")", "{", "return", "false", "}", "traversedValues", ".", "set", "(", "structure1", ",", "structure2", ")", "for", "(", "let", "i", "=", "keys1", ".", "length", ";", "i", "--", ";", ")", "{", "let", "key1", "=", "keys1", "[", "i", "]", "let", "key2", "=", "keys2", "[", "i", "]", "if", "(", "(", "key1", "instanceof", "Object", ")", "&&", "traversedValues", ".", "has", "(", "key1", ")", ")", "{", "if", "(", "traversedValues", ".", "get", "(", "key1", ")", "!==", "key2", ")", "{", "return", "false", "}", "else", "{", "continue", "}", "}", "if", "(", "!", "equals", "(", "key1", ",", "key2", ",", "traversedValues", ")", ")", "{", "return", "false", "}", "if", "(", "key1", "instanceof", "Object", ")", "{", "traversedValues", ".", "set", "(", "key1", ",", "key2", ")", "}", "let", "value1", "=", "getter", "(", "structure1", ",", "key1", ")", "let", "value2", "=", "getter", "(", "structure2", ",", "key2", ")", "if", "(", "(", "value1", "instanceof", "Object", ")", "&&", "traversedValues", ".", "has", "(", "value1", ")", ")", "{", "if", "(", "traversedValues", ".", "get", "(", "value1", ")", "!==", "value2", ")", "{", "return", "false", "}", "else", "{", "continue", "}", "}", "if", "(", "!", "equals", "(", "value1", ",", "value2", ",", "traversedValues", ")", ")", "{", "return", "false", "}", "if", "(", "value1", "instanceof", "Object", ")", "{", "traversedValues", ".", "set", "(", "value1", ",", "value2", ")", "}", "}", "return", "true", "}" ]
Performs a structured comparison of two structures, determining their equality. @param {Object} structure1 The first structure to compare. @param {Object} structure2 The second structure to compare. @param {*[]} keys1 The keys of the properties to compare in the first structure. @param {*[]} keys2 The keys of the properties to compare in the second structure. @param {function(Object, *): *} getter A callback for retrieving the value of the property identified by the provided key (2nd argument) from the structure (1st argument). @param {Map<Object, Object>} traversedValues A map of non-primitive values traversed in the first structure to their equal counterparts in the second structure. @return {boolean} {@code true} if the keys, the order of the keys and the values retrieved by the keys from the structures are equal.
[ "Performs", "a", "structured", "comparison", "of", "two", "structures", "determining", "their", "equality", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L238-L287
55,536
jurca/idb-entity
es2015/equals.js
iteratorToArray
function iteratorToArray(iterator) { let elements = [] for (let element of iterator) { elements.push(element) } return elements }
javascript
function iteratorToArray(iterator) { let elements = [] for (let element of iterator) { elements.push(element) } return elements }
[ "function", "iteratorToArray", "(", "iterator", ")", "{", "let", "elements", "=", "[", "]", "for", "(", "let", "element", "of", "iterator", ")", "{", "elements", ".", "push", "(", "element", ")", "}", "return", "elements", "}" ]
Traverses the provided finite iterator or iterable object and returns an array of generated values. @param {({[Symbol.iterator]: function(): {next: function(): {value: *, done: boolean}}}|{next: function(): {value: *, done: boolean}})} iterator The iterator or iterable object. @return {*[]} The elements generated by the iterator.
[ "Traverses", "the", "provided", "finite", "iterator", "or", "iterable", "object", "and", "returns", "an", "array", "of", "generated", "values", "." ]
361ef8482872d9fc9a0d83b86970d49d391dc276
https://github.com/jurca/idb-entity/blob/361ef8482872d9fc9a0d83b86970d49d391dc276/es2015/equals.js#L297-L305
55,537
fosrias/apiql-express
lib/api.js
jsonDescription
function jsonDescription(format, description) { switch (format) { case 'application/openapi+json': if (typeof description == object) { return description; } else { throw new Error(`application/openapi+json description ${description} is not an object`); } case 'application/openapi+yaml': return yaml.safeLoad(description); default: throw new Error(`Unknown format: ${format} for ${description}`); } }
javascript
function jsonDescription(format, description) { switch (format) { case 'application/openapi+json': if (typeof description == object) { return description; } else { throw new Error(`application/openapi+json description ${description} is not an object`); } case 'application/openapi+yaml': return yaml.safeLoad(description); default: throw new Error(`Unknown format: ${format} for ${description}`); } }
[ "function", "jsonDescription", "(", "format", ",", "description", ")", "{", "switch", "(", "format", ")", "{", "case", "'application/openapi+json'", ":", "if", "(", "typeof", "description", "==", "object", ")", "{", "return", "description", ";", "}", "else", "{", "throw", "new", "Error", "(", "`", "${", "description", "}", "`", ")", ";", "}", "case", "'application/openapi+yaml'", ":", "return", "yaml", ".", "safeLoad", "(", "description", ")", ";", "default", ":", "throw", "new", "Error", "(", "`", "${", "format", "}", "${", "description", "}", "`", ")", ";", "}", "}" ]
private helper methods
[ "private", "helper", "methods" ]
1bbfc5049f036d6311ade6c7486c63404f59af43
https://github.com/fosrias/apiql-express/blob/1bbfc5049f036d6311ade6c7486c63404f59af43/lib/api.js#L119-L132
55,538
torworx/well
well.js
well
function well(promiseOrValue, onFulfilled, onRejected, onProgress) { // Get a trusted promise for the input promiseOrValue, and then // register promise handlers return resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress); }
javascript
function well(promiseOrValue, onFulfilled, onRejected, onProgress) { // Get a trusted promise for the input promiseOrValue, and then // register promise handlers return resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress); }
[ "function", "well", "(", "promiseOrValue", ",", "onFulfilled", ",", "onRejected", ",", "onProgress", ")", "{", "// Get a trusted promise for the input promiseOrValue, and then", "// register promise handlers", "return", "resolve", "(", "promiseOrValue", ")", ".", "then", "(", "onFulfilled", ",", "onRejected", ",", "onProgress", ")", ";", "}" ]
Determine if a thing is a promise Register an observer for a promise or immediate value. @param {*} promiseOrValue @param {function?} [onFulfilled] callback to be called when promiseOrValue is successfully fulfilled. If promiseOrValue is an immediate value, callback will be invoked immediately. @param {function?} [onRejected] callback to be called when promiseOrValue is rejected. @param {function?} [onProgress] callback to be called when progress updates are issued for promiseOrValue. @returns {Promise} a new {@link Promise} that will complete with the return value of callback or errback or the completion value of promiseOrValue if callback and/or errback is not supplied.
[ "Determine", "if", "a", "thing", "is", "a", "promise", "Register", "an", "observer", "for", "a", "promise", "or", "immediate", "value", "." ]
45a1724a0a4192628c80b3c4ae541d6de28ac7da
https://github.com/torworx/well/blob/45a1724a0a4192628c80b3c4ae541d6de28ac7da/well.js#L51-L55
55,539
torworx/well
well.js
chain
function chain(promiseOrValue, resolver, resolveValue) { var useResolveValue = arguments.length > 2; return well(promiseOrValue, function (val) { val = useResolveValue ? resolveValue : val; resolver.resolve(val); return val; }, function (reason) { resolver.reject(reason); return rejected(reason); }, function (update) { typeof resolver.notify === 'function' && resolver.notify(update); return update; } ); }
javascript
function chain(promiseOrValue, resolver, resolveValue) { var useResolveValue = arguments.length > 2; return well(promiseOrValue, function (val) { val = useResolveValue ? resolveValue : val; resolver.resolve(val); return val; }, function (reason) { resolver.reject(reason); return rejected(reason); }, function (update) { typeof resolver.notify === 'function' && resolver.notify(update); return update; } ); }
[ "function", "chain", "(", "promiseOrValue", ",", "resolver", ",", "resolveValue", ")", "{", "var", "useResolveValue", "=", "arguments", ".", "length", ">", "2", ";", "return", "well", "(", "promiseOrValue", ",", "function", "(", "val", ")", "{", "val", "=", "useResolveValue", "?", "resolveValue", ":", "val", ";", "resolver", ".", "resolve", "(", "val", ")", ";", "return", "val", ";", "}", ",", "function", "(", "reason", ")", "{", "resolver", ".", "reject", "(", "reason", ")", ";", "return", "rejected", "(", "reason", ")", ";", "}", ",", "function", "(", "update", ")", "{", "typeof", "resolver", ".", "notify", "===", "'function'", "&&", "resolver", ".", "notify", "(", "update", ")", ";", "return", "update", ";", "}", ")", ";", "}" ]
Ensure that resolution of promiseOrValue will trigger resolver with the value or reason of promiseOrValue, or instead with resolveValue if it is provided. @param promiseOrValue @param {Object} resolver @param {function} resolver.resolve @param {function} resolver.reject @param {*} [resolveValue] @returns {Promise}
[ "Ensure", "that", "resolution", "of", "promiseOrValue", "will", "trigger", "resolver", "with", "the", "value", "or", "reason", "of", "promiseOrValue", "or", "instead", "with", "resolveValue", "if", "it", "is", "provided", "." ]
45a1724a0a4192628c80b3c4ae541d6de28ac7da
https://github.com/torworx/well/blob/45a1724a0a4192628c80b3c4ae541d6de28ac7da/well.js#L771-L789
55,540
torworx/well
well.js
processQueue
function processQueue(queue, value) { if (!queue || queue.length === 0) return; var handler, i = 0; while (handler = queue[i++]) { handler(value); } }
javascript
function processQueue(queue, value) { if (!queue || queue.length === 0) return; var handler, i = 0; while (handler = queue[i++]) { handler(value); } }
[ "function", "processQueue", "(", "queue", ",", "value", ")", "{", "if", "(", "!", "queue", "||", "queue", ".", "length", "===", "0", ")", "return", ";", "var", "handler", ",", "i", "=", "0", ";", "while", "(", "handler", "=", "queue", "[", "i", "++", "]", ")", "{", "handler", "(", "value", ")", ";", "}", "}" ]
Utility functions Apply all functions in queue to value @param {Array} queue array of functions to execute @param {*} value argument passed to each function
[ "Utility", "functions", "Apply", "all", "functions", "in", "queue", "to", "value" ]
45a1724a0a4192628c80b3c4ae541d6de28ac7da
https://github.com/torworx/well/blob/45a1724a0a4192628c80b3c4ae541d6de28ac7da/well.js#L800-L807
55,541
torworx/well
well.js
checkCallbacks
function checkCallbacks(start, arrayOfCallbacks) { // TODO: Promises/A+ update type checking and docs var arg, i = arrayOfCallbacks.length; while (i > start) { arg = arrayOfCallbacks[--i]; if (arg != null && typeof arg != 'function') { throw new Error('arg ' + i + ' must be a function'); } } }
javascript
function checkCallbacks(start, arrayOfCallbacks) { // TODO: Promises/A+ update type checking and docs var arg, i = arrayOfCallbacks.length; while (i > start) { arg = arrayOfCallbacks[--i]; if (arg != null && typeof arg != 'function') { throw new Error('arg ' + i + ' must be a function'); } } }
[ "function", "checkCallbacks", "(", "start", ",", "arrayOfCallbacks", ")", "{", "// TODO: Promises/A+ update type checking and docs", "var", "arg", ",", "i", "=", "arrayOfCallbacks", ".", "length", ";", "while", "(", "i", ">", "start", ")", "{", "arg", "=", "arrayOfCallbacks", "[", "--", "i", "]", ";", "if", "(", "arg", "!=", "null", "&&", "typeof", "arg", "!=", "'function'", ")", "{", "throw", "new", "Error", "(", "'arg '", "+", "i", "+", "' must be a function'", ")", ";", "}", "}", "}" ]
Helper that checks arrayOfCallbacks to ensure that each element is either a function, or null or undefined. @private @param {number} start index at which to start checking items in arrayOfCallbacks @param {Array} arrayOfCallbacks array to check @throws {Error} if any element of arrayOfCallbacks is something other than a functions, null, or undefined.
[ "Helper", "that", "checks", "arrayOfCallbacks", "to", "ensure", "that", "each", "element", "is", "either", "a", "function", "or", "null", "or", "undefined", "." ]
45a1724a0a4192628c80b3c4ae541d6de28ac7da
https://github.com/torworx/well/blob/45a1724a0a4192628c80b3c4ae541d6de28ac7da/well.js#L818-L829
55,542
TJkrusinski/git-sha
index.js
git
function git(cb) { which('git', function(err, data){ if (err) return cb(err, data); child.exec('git rev-parse HEAD', cb); }); }
javascript
function git(cb) { which('git', function(err, data){ if (err) return cb(err, data); child.exec('git rev-parse HEAD', cb); }); }
[ "function", "git", "(", "cb", ")", "{", "which", "(", "'git'", ",", "function", "(", "err", ",", "data", ")", "{", "if", "(", "err", ")", "return", "cb", "(", "err", ",", "data", ")", ";", "child", ".", "exec", "(", "'git rev-parse HEAD'", ",", "cb", ")", ";", "}", ")", ";", "}" ]
Get the git sha of the current commit @param {Function} cb
[ "Get", "the", "git", "sha", "of", "the", "current", "commit" ]
12e7c077989beb40931144f0c8abba2165292ad5
https://github.com/TJkrusinski/git-sha/blob/12e7c077989beb40931144f0c8abba2165292ad5/index.js#L18-L24
55,543
CyclicMaterials/util-combine-class-names
src/index.js
combineClassNames
function combineClassNames(...classNames) { return classNames.map((value) => { if (!value) { return value; } return Array.isArray(value) ? combineClassNames.apply(void 0, value) : value; }).join(` `).replace(/ +/g, ` `).trim(); }
javascript
function combineClassNames(...classNames) { return classNames.map((value) => { if (!value) { return value; } return Array.isArray(value) ? combineClassNames.apply(void 0, value) : value; }).join(` `).replace(/ +/g, ` `).trim(); }
[ "function", "combineClassNames", "(", "...", "classNames", ")", "{", "return", "classNames", ".", "map", "(", "(", "value", ")", "=>", "{", "if", "(", "!", "value", ")", "{", "return", "value", ";", "}", "return", "Array", ".", "isArray", "(", "value", ")", "?", "combineClassNames", ".", "apply", "(", "void", "0", ",", "value", ")", ":", "value", ";", "}", ")", ".", "join", "(", "`", "`", ")", ".", "replace", "(", "/", " +", "/", "g", ",", "`", "`", ")", ".", "trim", "(", ")", ";", "}" ]
Returns a trimmed string of the combined class names. Class names can be either strings or arrays of strings. Example: combineClassNames(`my-class`, `my-other-class`, [`first`, `second`]) // `myclass my-other-class first second` Arrays can be nested. @param {Array|String} classNames Any number of arguments of class names. @returns {String} The combined class names.
[ "Returns", "a", "trimmed", "string", "of", "the", "combined", "class", "names", ".", "Class", "names", "can", "be", "either", "strings", "or", "arrays", "of", "strings", "." ]
9fc0473b9640830861cd8f4cefb78109c2bd6b81
https://github.com/CyclicMaterials/util-combine-class-names/blob/9fc0473b9640830861cd8f4cefb78109c2bd6b81/src/index.js#L14-L24
55,544
campsi/campsi-service-auth
lib/handlers.js
initAuth
function initAuth (req, res, next) { const params = { session: false, state: state.serialize(req), scope: req.authProvider.scope }; // noinspection JSUnresolvedFunction passport.authenticate( req.params.provider, params )(req, res, next); }
javascript
function initAuth (req, res, next) { const params = { session: false, state: state.serialize(req), scope: req.authProvider.scope }; // noinspection JSUnresolvedFunction passport.authenticate( req.params.provider, params )(req, res, next); }
[ "function", "initAuth", "(", "req", ",", "res", ",", "next", ")", "{", "const", "params", "=", "{", "session", ":", "false", ",", "state", ":", "state", ".", "serialize", "(", "req", ")", ",", "scope", ":", "req", ".", "authProvider", ".", "scope", "}", ";", "// noinspection JSUnresolvedFunction", "passport", ".", "authenticate", "(", "req", ".", "params", ".", "provider", ",", "params", ")", "(", "req", ",", "res", ",", "next", ")", ";", "}" ]
Entry point of the authentification workflow. There's no req.user yet. @param req @param res @param next
[ "Entry", "point", "of", "the", "authentification", "workflow", ".", "There", "s", "no", "req", ".", "user", "yet", "." ]
f877626496de2288f9cfb50024accca2a88e179d
https://github.com/campsi/campsi-service-auth/blob/f877626496de2288f9cfb50024accca2a88e179d/lib/handlers.js#L124-L136
55,545
chunksnbits/grunt-template-render
tasks/template.js
function(filename) { var filepath = options.cwd + filename; var template = readTemplateFile({ src: [ filepath ] }); return grunt.template.process(template, options); }
javascript
function(filename) { var filepath = options.cwd + filename; var template = readTemplateFile({ src: [ filepath ] }); return grunt.template.process(template, options); }
[ "function", "(", "filename", ")", "{", "var", "filepath", "=", "options", ".", "cwd", "+", "filename", ";", "var", "template", "=", "readTemplateFile", "(", "{", "src", ":", "[", "filepath", "]", "}", ")", ";", "return", "grunt", ".", "template", ".", "process", "(", "template", ",", "options", ")", ";", "}" ]
Render helper method. Allows to render partials within template files.
[ "Render", "helper", "method", ".", "Allows", "to", "render", "partials", "within", "template", "files", "." ]
0e3c0b3e646a2d37e13f30eaee7baa433435f2a7
https://github.com/chunksnbits/grunt-template-render/blob/0e3c0b3e646a2d37e13f30eaee7baa433435f2a7/tasks/template.js#L42-L46
55,546
chunksnbits/grunt-template-render
tasks/template.js
function(key) { var translation = options.translations[key]; if (!translation) { grunt.fail.warn('No translation found for key:', key); } return translation; }
javascript
function(key) { var translation = options.translations[key]; if (!translation) { grunt.fail.warn('No translation found for key:', key); } return translation; }
[ "function", "(", "key", ")", "{", "var", "translation", "=", "options", ".", "translations", "[", "key", "]", ";", "if", "(", "!", "translation", ")", "{", "grunt", ".", "fail", ".", "warn", "(", "'No translation found for key:'", ",", "key", ")", ";", "}", "return", "translation", ";", "}" ]
Translation helper method. Allows resolving keys within a translation file.
[ "Translation", "helper", "method", ".", "Allows", "resolving", "keys", "within", "a", "translation", "file", "." ]
0e3c0b3e646a2d37e13f30eaee7baa433435f2a7
https://github.com/chunksnbits/grunt-template-render/blob/0e3c0b3e646a2d37e13f30eaee7baa433435f2a7/tasks/template.js#L50-L57
55,547
chunksnbits/grunt-template-render
tasks/template.js
function(options) { var recurse = function(options) { _.each(options, function(value, key) { if (_.isFunction(value)) { options[key] = value(); } else if (_.isObject(value)) { options[key] = recurse(value); } }); return options; }; return recurse(options); }
javascript
function(options) { var recurse = function(options) { _.each(options, function(value, key) { if (_.isFunction(value)) { options[key] = value(); } else if (_.isObject(value)) { options[key] = recurse(value); } }); return options; }; return recurse(options); }
[ "function", "(", "options", ")", "{", "var", "recurse", "=", "function", "(", "options", ")", "{", "_", ".", "each", "(", "options", ",", "function", "(", "value", ",", "key", ")", "{", "if", "(", "_", ".", "isFunction", "(", "value", ")", ")", "{", "options", "[", "key", "]", "=", "value", "(", ")", ";", "}", "else", "if", "(", "_", ".", "isObject", "(", "value", ")", ")", "{", "options", "[", "key", "]", "=", "recurse", "(", "value", ")", ";", "}", "}", ")", ";", "return", "options", ";", "}", ";", "return", "recurse", "(", "options", ")", ";", "}" ]
Iterates recursively over all provided options executes them in case the option was provided as a function.
[ "Iterates", "recursively", "over", "all", "provided", "options", "executes", "them", "in", "case", "the", "option", "was", "provided", "as", "a", "function", "." ]
0e3c0b3e646a2d37e13f30eaee7baa433435f2a7
https://github.com/chunksnbits/grunt-template-render/blob/0e3c0b3e646a2d37e13f30eaee7baa433435f2a7/tasks/template.js#L64-L78
55,548
zzolo/github-collect
index.js
qG
function qG(options) { var defer = q.defer(); var compiledData = []; // Recursive call to paginate function qGCall(pageLink) { var methodCall; // Callback function callback(error, data) { if (error) { defer.reject(new Error(error)); } else { compiledData = compiledData.concat(data); if (github.hasNextPage(data)) { qGCall(data); } else { defer.resolve(compiledData); } } } // If the call is a link to another page, use that. if (pageLink) { method = github.getNextPage(pageLink, callback); } else { githubAuth()[options.obj][options.method](options, callback); } } qGCall(); return defer.promise; }
javascript
function qG(options) { var defer = q.defer(); var compiledData = []; // Recursive call to paginate function qGCall(pageLink) { var methodCall; // Callback function callback(error, data) { if (error) { defer.reject(new Error(error)); } else { compiledData = compiledData.concat(data); if (github.hasNextPage(data)) { qGCall(data); } else { defer.resolve(compiledData); } } } // If the call is a link to another page, use that. if (pageLink) { method = github.getNextPage(pageLink, callback); } else { githubAuth()[options.obj][options.method](options, callback); } } qGCall(); return defer.promise; }
[ "function", "qG", "(", "options", ")", "{", "var", "defer", "=", "q", ".", "defer", "(", ")", ";", "var", "compiledData", "=", "[", "]", ";", "// Recursive call to paginate", "function", "qGCall", "(", "pageLink", ")", "{", "var", "methodCall", ";", "// Callback", "function", "callback", "(", "error", ",", "data", ")", "{", "if", "(", "error", ")", "{", "defer", ".", "reject", "(", "new", "Error", "(", "error", ")", ")", ";", "}", "else", "{", "compiledData", "=", "compiledData", ".", "concat", "(", "data", ")", ";", "if", "(", "github", ".", "hasNextPage", "(", "data", ")", ")", "{", "qGCall", "(", "data", ")", ";", "}", "else", "{", "defer", ".", "resolve", "(", "compiledData", ")", ";", "}", "}", "}", "// If the call is a link to another page, use that.", "if", "(", "pageLink", ")", "{", "method", "=", "github", ".", "getNextPage", "(", "pageLink", ",", "callback", ")", ";", "}", "else", "{", "githubAuth", "(", ")", "[", "options", ".", "obj", "]", "[", "options", ".", "method", "]", "(", "options", ",", "callback", ")", ";", "}", "}", "qGCall", "(", ")", ";", "return", "defer", ".", "promise", ";", "}" ]
Wrap github calls in to promises
[ "Wrap", "github", "calls", "in", "to", "promises" ]
8b28add17a3fbd6e18d7532bf5dc42d898cd625e
https://github.com/zzolo/github-collect/blob/8b28add17a3fbd6e18d7532bf5dc42d898cd625e/index.js#L28-L63
55,549
zzolo/github-collect
index.js
getObjects
function getObjects(user) { var username = (_.isObject(user)) ? user.login : user; var isOrg = (_.isObject(user) && user.type === 'Organization'); var defers = []; // Get repos defers.push(qG({ obj: 'repos', method: 'getFromUser', user: username, sort: 'created', per_page: 100 })); // Get gists defers.push(qG({ obj: 'gists', method: 'getFromUser', user: username, sort: 'created', per_page: 100 })); // Get members (for orgs) if (isOrg) { defers.push(qG({ obj: 'orgs', method: 'getMembers', org: username, per_page: 100 })); } return q.all(defers); }
javascript
function getObjects(user) { var username = (_.isObject(user)) ? user.login : user; var isOrg = (_.isObject(user) && user.type === 'Organization'); var defers = []; // Get repos defers.push(qG({ obj: 'repos', method: 'getFromUser', user: username, sort: 'created', per_page: 100 })); // Get gists defers.push(qG({ obj: 'gists', method: 'getFromUser', user: username, sort: 'created', per_page: 100 })); // Get members (for orgs) if (isOrg) { defers.push(qG({ obj: 'orgs', method: 'getMembers', org: username, per_page: 100 })); } return q.all(defers); }
[ "function", "getObjects", "(", "user", ")", "{", "var", "username", "=", "(", "_", ".", "isObject", "(", "user", ")", ")", "?", "user", ".", "login", ":", "user", ";", "var", "isOrg", "=", "(", "_", ".", "isObject", "(", "user", ")", "&&", "user", ".", "type", "===", "'Organization'", ")", ";", "var", "defers", "=", "[", "]", ";", "// Get repos", "defers", ".", "push", "(", "qG", "(", "{", "obj", ":", "'repos'", ",", "method", ":", "'getFromUser'", ",", "user", ":", "username", ",", "sort", ":", "'created'", ",", "per_page", ":", "100", "}", ")", ")", ";", "// Get gists", "defers", ".", "push", "(", "qG", "(", "{", "obj", ":", "'gists'", ",", "method", ":", "'getFromUser'", ",", "user", ":", "username", ",", "sort", ":", "'created'", ",", "per_page", ":", "100", "}", ")", ")", ";", "// Get members (for orgs)", "if", "(", "isOrg", ")", "{", "defers", ".", "push", "(", "qG", "(", "{", "obj", ":", "'orgs'", ",", "method", ":", "'getMembers'", ",", "org", ":", "username", ",", "per_page", ":", "100", "}", ")", ")", ";", "}", "return", "q", ".", "all", "(", "defers", ")", ";", "}" ]
Get objects for a specific username
[ "Get", "objects", "for", "a", "specific", "username" ]
8b28add17a3fbd6e18d7532bf5dc42d898cd625e
https://github.com/zzolo/github-collect/blob/8b28add17a3fbd6e18d7532bf5dc42d898cd625e/index.js#L66-L92
55,550
zzolo/github-collect
index.js
get
function get(usernames, options) { usernames = usernames || ''; usernames = (_.isArray(usernames)) ? usernames : usernames.split(','); options = options || {}; var defers = []; var collection = {}; _.each(usernames, function(u) { var defer = q.defer(); u = u.toLowerCase(); if (u.length === 0) { return; } qG({ obj: 'user', method: 'getFrom', user: u }) .done(function(data) { collection[u] = data[0]; // Get objects for the specific user getObjects(data[0]).done(function(objData) { collection[u].objects = collection[u].objects || {}; collection[u].objects.repos = objData[0]; collection[u].objects.gists = objData[1]; collection[u].objects.members = objData[2]; defer.resolve(collection[u]); }); }); defers.push(defer.promise); }); return q.all(defers).then(function() { return collection; }); }
javascript
function get(usernames, options) { usernames = usernames || ''; usernames = (_.isArray(usernames)) ? usernames : usernames.split(','); options = options || {}; var defers = []; var collection = {}; _.each(usernames, function(u) { var defer = q.defer(); u = u.toLowerCase(); if (u.length === 0) { return; } qG({ obj: 'user', method: 'getFrom', user: u }) .done(function(data) { collection[u] = data[0]; // Get objects for the specific user getObjects(data[0]).done(function(objData) { collection[u].objects = collection[u].objects || {}; collection[u].objects.repos = objData[0]; collection[u].objects.gists = objData[1]; collection[u].objects.members = objData[2]; defer.resolve(collection[u]); }); }); defers.push(defer.promise); }); return q.all(defers).then(function() { return collection; }); }
[ "function", "get", "(", "usernames", ",", "options", ")", "{", "usernames", "=", "usernames", "||", "''", ";", "usernames", "=", "(", "_", ".", "isArray", "(", "usernames", ")", ")", "?", "usernames", ":", "usernames", ".", "split", "(", "','", ")", ";", "options", "=", "options", "||", "{", "}", ";", "var", "defers", "=", "[", "]", ";", "var", "collection", "=", "{", "}", ";", "_", ".", "each", "(", "usernames", ",", "function", "(", "u", ")", "{", "var", "defer", "=", "q", ".", "defer", "(", ")", ";", "u", "=", "u", ".", "toLowerCase", "(", ")", ";", "if", "(", "u", ".", "length", "===", "0", ")", "{", "return", ";", "}", "qG", "(", "{", "obj", ":", "'user'", ",", "method", ":", "'getFrom'", ",", "user", ":", "u", "}", ")", ".", "done", "(", "function", "(", "data", ")", "{", "collection", "[", "u", "]", "=", "data", "[", "0", "]", ";", "// Get objects for the specific user", "getObjects", "(", "data", "[", "0", "]", ")", ".", "done", "(", "function", "(", "objData", ")", "{", "collection", "[", "u", "]", ".", "objects", "=", "collection", "[", "u", "]", ".", "objects", "||", "{", "}", ";", "collection", "[", "u", "]", ".", "objects", ".", "repos", "=", "objData", "[", "0", "]", ";", "collection", "[", "u", "]", ".", "objects", ".", "gists", "=", "objData", "[", "1", "]", ";", "collection", "[", "u", "]", ".", "objects", ".", "members", "=", "objData", "[", "2", "]", ";", "defer", ".", "resolve", "(", "collection", "[", "u", "]", ")", ";", "}", ")", ";", "}", ")", ";", "defers", ".", "push", "(", "defer", ".", "promise", ")", ";", "}", ")", ";", "return", "q", ".", "all", "(", "defers", ")", ".", "then", "(", "function", "(", ")", "{", "return", "collection", ";", "}", ")", ";", "}" ]
Get data from usernames, which can be an array of usernames or a string of usernames separated by commas.
[ "Get", "data", "from", "usernames", "which", "can", "be", "an", "array", "of", "usernames", "or", "a", "string", "of", "usernames", "separated", "by", "commas", "." ]
8b28add17a3fbd6e18d7532bf5dc42d898cd625e
https://github.com/zzolo/github-collect/blob/8b28add17a3fbd6e18d7532bf5dc42d898cd625e/index.js#L96-L134
55,551
Ma3Route/node-sdk
lib/poller.js
Poller
function Poller(getRequest, options) { options = options || { }; events.EventEmitter.call(this); this._pollerOptions = utils.getPollerOptions([utils.setup().poller, options]); this._get = getRequest; this._params = options.params || { }; this._lastreadId = this._params.lastreadId || null; this._timer = null; this._requestPending = false; this._paused = false; return this; }
javascript
function Poller(getRequest, options) { options = options || { }; events.EventEmitter.call(this); this._pollerOptions = utils.getPollerOptions([utils.setup().poller, options]); this._get = getRequest; this._params = options.params || { }; this._lastreadId = this._params.lastreadId || null; this._timer = null; this._requestPending = false; this._paused = false; return this; }
[ "function", "Poller", "(", "getRequest", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "events", ".", "EventEmitter", ".", "call", "(", "this", ")", ";", "this", ".", "_pollerOptions", "=", "utils", ".", "getPollerOptions", "(", "[", "utils", ".", "setup", "(", ")", ".", "poller", ",", "options", "]", ")", ";", "this", ".", "_get", "=", "getRequest", ";", "this", ".", "_params", "=", "options", ".", "params", "||", "{", "}", ";", "this", ".", "_lastreadId", "=", "this", ".", "_params", ".", "lastreadId", "||", "null", ";", "this", ".", "_timer", "=", "null", ";", "this", ".", "_requestPending", "=", "false", ";", "this", ".", "_paused", "=", "false", ";", "return", "this", ";", "}" ]
Poller Class. Inherits from events.EventEmitter. This poller is designed in that it polls for new items automatically without having you implement `lastreadId` logic. @example // create a new poller that keeps retrieiving traffic updates var poller = new sdk.Poller(sdk.trafficUpdates.get, { interval: 5000, // 5 seconds }); // listen for new updates poller.on("message", function(updates, meta, responseObject) { console.log("received these updates: %j", updates); }); // listen for errors e.g. network failures etc. // if an error occurs an you not listening on the "error" // event, the error will bubble up to the domain/process. poller.on("error", function(err) { console.log("error: %s", err); }); // you have to explicitly start it poller.start(); // lets say we close it after a minute or so setTimeout(function() { poller.stop(); }, 1000 * 60); @constructor @param {itemsGetRequest} getRequest - request function fired in each poll @param {Object} [options] @param {Object|Function} [options.params] - parameters passed to get request. If `options.params` is a function, it is invoked and its return value is assumed an object as the request params. If `options.params` requires to do an asynchronous action, it is passed a `done` function as its only argument to call with the value when done. @param {Integer} [options.interval=5000] - configures the poller's timer
[ "Poller", "Class", ".", "Inherits", "from", "events", ".", "EventEmitter", ".", "This", "poller", "is", "designed", "in", "that", "it", "polls", "for", "new", "items", "automatically", "without", "having", "you", "implement", "lastreadId", "logic", "." ]
a2769d97d77d6f762d23e743bf4c749e2bad0d8a
https://github.com/Ma3Route/node-sdk/blob/a2769d97d77d6f762d23e743bf4c749e2bad0d8a/lib/poller.js#L65-L76
55,552
altshift/altshift
lib/altshift/promise.js
function (array) { var self = this, deferred = new Deferred(), fulfilled = 0, length, results = [], hasError = false; if (!isArray(array)) { array = slice.call(arguments); } length = array.length; if (length === 0) { deferred.emitSuccess(results); } else { array.forEach(function (promise, index) { self.when(promise, //Success function (value) { results[index] = value; fulfilled += 1; if (fulfilled === length) { if (hasError) { deferred.emitError(results); } else { deferred.emitSuccess(results); } } }, //Error function (error) { results[index] = error; hasError = true; fulfilled += 1; if (fulfilled === length) { deferred.emitError(results); } } ); }); } return deferred.getPromise(); }
javascript
function (array) { var self = this, deferred = new Deferred(), fulfilled = 0, length, results = [], hasError = false; if (!isArray(array)) { array = slice.call(arguments); } length = array.length; if (length === 0) { deferred.emitSuccess(results); } else { array.forEach(function (promise, index) { self.when(promise, //Success function (value) { results[index] = value; fulfilled += 1; if (fulfilled === length) { if (hasError) { deferred.emitError(results); } else { deferred.emitSuccess(results); } } }, //Error function (error) { results[index] = error; hasError = true; fulfilled += 1; if (fulfilled === length) { deferred.emitError(results); } } ); }); } return deferred.getPromise(); }
[ "function", "(", "array", ")", "{", "var", "self", "=", "this", ",", "deferred", "=", "new", "Deferred", "(", ")", ",", "fulfilled", "=", "0", ",", "length", ",", "results", "=", "[", "]", ",", "hasError", "=", "false", ";", "if", "(", "!", "isArray", "(", "array", ")", ")", "{", "array", "=", "slice", ".", "call", "(", "arguments", ")", ";", "}", "length", "=", "array", ".", "length", ";", "if", "(", "length", "===", "0", ")", "{", "deferred", ".", "emitSuccess", "(", "results", ")", ";", "}", "else", "{", "array", ".", "forEach", "(", "function", "(", "promise", ",", "index", ")", "{", "self", ".", "when", "(", "promise", ",", "//Success", "function", "(", "value", ")", "{", "results", "[", "index", "]", "=", "value", ";", "fulfilled", "+=", "1", ";", "if", "(", "fulfilled", "===", "length", ")", "{", "if", "(", "hasError", ")", "{", "deferred", ".", "emitError", "(", "results", ")", ";", "}", "else", "{", "deferred", ".", "emitSuccess", "(", "results", ")", ";", "}", "}", "}", ",", "//Error", "function", "(", "error", ")", "{", "results", "[", "index", "]", "=", "error", ";", "hasError", "=", "true", ";", "fulfilled", "+=", "1", ";", "if", "(", "fulfilled", "===", "length", ")", "{", "deferred", ".", "emitError", "(", "results", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}", "return", "deferred", ".", "getPromise", "(", ")", ";", "}" ]
Takes an array of promises and returns a promise that is fulfilled once all the promises in the array are fulfilled @param {Array} array The array of promises @return {Promise} the promise that is fulfilled when all the array is fulfilled, resolved to the array of results
[ "Takes", "an", "array", "of", "promises", "and", "returns", "a", "promise", "that", "is", "fulfilled", "once", "all", "the", "promises", "in", "the", "array", "are", "fulfilled" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L120-L165
55,553
altshift/altshift
lib/altshift/promise.js
function (array) { var self = this, deferred = new Deferred(), fulfilled = false, index, length, onSuccess = function (value) { if (!fulfilled) { fulfilled = true; deferred.emitSuccess(value); } }, onError = function (error) { if (!fulfilled) { fulfilled = true; deferred.emitSuccess(error); } }; if (!isArray(array)) { array = slice.call(arguments); } for (index = 0, length = array.length; index < length; index += 1) { this.when(array[index], onSuccess, onError); } return deferred.getPromise(); }
javascript
function (array) { var self = this, deferred = new Deferred(), fulfilled = false, index, length, onSuccess = function (value) { if (!fulfilled) { fulfilled = true; deferred.emitSuccess(value); } }, onError = function (error) { if (!fulfilled) { fulfilled = true; deferred.emitSuccess(error); } }; if (!isArray(array)) { array = slice.call(arguments); } for (index = 0, length = array.length; index < length; index += 1) { this.when(array[index], onSuccess, onError); } return deferred.getPromise(); }
[ "function", "(", "array", ")", "{", "var", "self", "=", "this", ",", "deferred", "=", "new", "Deferred", "(", ")", ",", "fulfilled", "=", "false", ",", "index", ",", "length", ",", "onSuccess", "=", "function", "(", "value", ")", "{", "if", "(", "!", "fulfilled", ")", "{", "fulfilled", "=", "true", ";", "deferred", ".", "emitSuccess", "(", "value", ")", ";", "}", "}", ",", "onError", "=", "function", "(", "error", ")", "{", "if", "(", "!", "fulfilled", ")", "{", "fulfilled", "=", "true", ";", "deferred", ".", "emitSuccess", "(", "error", ")", ";", "}", "}", ";", "if", "(", "!", "isArray", "(", "array", ")", ")", "{", "array", "=", "slice", ".", "call", "(", "arguments", ")", ";", "}", "for", "(", "index", "=", "0", ",", "length", "=", "array", ".", "length", ";", "index", "<", "length", ";", "index", "+=", "1", ")", "{", "this", ".", "when", "(", "array", "[", "index", "]", ",", "onSuccess", ",", "onError", ")", ";", "}", "return", "deferred", ".", "getPromise", "(", ")", ";", "}" ]
Takes an array of promises and returns a promise that is fulfilled when the first promise in the array of promises is fulfilled @param {Array} array The array of promises @return {Promise} a promise that is fulfilled with the value of the value of first promise to be fulfilled
[ "Takes", "an", "array", "of", "promises", "and", "returns", "a", "promise", "that", "is", "fulfilled", "when", "the", "first", "promise", "in", "the", "array", "of", "promises", "is", "fulfilled" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L175-L200
55,554
altshift/altshift
lib/altshift/promise.js
function (value) { var nextAction = array.shift(); if (nextAction) { self.when(nextAction(value), next, deferred.reject); } else { deferred.emitSuccess(value); } }
javascript
function (value) { var nextAction = array.shift(); if (nextAction) { self.when(nextAction(value), next, deferred.reject); } else { deferred.emitSuccess(value); } }
[ "function", "(", "value", ")", "{", "var", "nextAction", "=", "array", ".", "shift", "(", ")", ";", "if", "(", "nextAction", ")", "{", "self", ".", "when", "(", "nextAction", "(", "value", ")", ",", "next", ",", "deferred", ".", "reject", ")", ";", "}", "else", "{", "deferred", ".", "emitSuccess", "(", "value", ")", ";", "}", "}" ]
make a copy
[ "make", "a", "copy" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L215-L222
55,555
altshift/altshift
lib/altshift/promise.js
function (milliseconds) { var deferred, timer = setTimeout(function () { deferred.emitSuccess(); }, milliseconds), canceller = function () { clearTimeout(timer); }; deferred = new Deferred(canceller); return deferred.getPromise(); }
javascript
function (milliseconds) { var deferred, timer = setTimeout(function () { deferred.emitSuccess(); }, milliseconds), canceller = function () { clearTimeout(timer); }; deferred = new Deferred(canceller); return deferred.getPromise(); }
[ "function", "(", "milliseconds", ")", "{", "var", "deferred", ",", "timer", "=", "setTimeout", "(", "function", "(", ")", "{", "deferred", ".", "emitSuccess", "(", ")", ";", "}", ",", "milliseconds", ")", ",", "canceller", "=", "function", "(", ")", "{", "clearTimeout", "(", "timer", ")", ";", "}", ";", "deferred", "=", "new", "Deferred", "(", "canceller", ")", ";", "return", "deferred", ".", "getPromise", "(", ")", ";", "}" ]
Delays for a given amount of time and then fulfills the returned promise. @param {int} milliseconds The number of milliseconds to delay @return {Promise} A promise that will be fulfilled after the delay
[ "Delays", "for", "a", "given", "amount", "of", "time", "and", "then", "fulfills", "the", "returned", "promise", "." ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L233-L243
55,556
altshift/altshift
lib/altshift/promise.js
function (resolvedCallback, errorCallback, progressCallback) { var returnDeferred = new Deferred(this._canceller), //new Deferred(this.getPromise().cancel) listener = { resolved : resolvedCallback, error : errorCallback, progress : progressCallback, deferred : returnDeferred }; if (this.finished) { this._notify(listener); } else { this.waiting.push(listener); } return returnDeferred.getPromise(); }
javascript
function (resolvedCallback, errorCallback, progressCallback) { var returnDeferred = new Deferred(this._canceller), //new Deferred(this.getPromise().cancel) listener = { resolved : resolvedCallback, error : errorCallback, progress : progressCallback, deferred : returnDeferred }; if (this.finished) { this._notify(listener); } else { this.waiting.push(listener); } return returnDeferred.getPromise(); }
[ "function", "(", "resolvedCallback", ",", "errorCallback", ",", "progressCallback", ")", "{", "var", "returnDeferred", "=", "new", "Deferred", "(", "this", ".", "_canceller", ")", ",", "//new Deferred(this.getPromise().cancel)", "listener", "=", "{", "resolved", ":", "resolvedCallback", ",", "error", ":", "errorCallback", ",", "progress", ":", "progressCallback", ",", "deferred", ":", "returnDeferred", "}", ";", "if", "(", "this", ".", "finished", ")", "{", "this", ".", "_notify", "(", "listener", ")", ";", "}", "else", "{", "this", ".", "waiting", ".", "push", "(", "listener", ")", ";", "}", "return", "returnDeferred", ".", "getPromise", "(", ")", ";", "}" ]
Return a new promise @param {Function} resolvedCallback @param {Function} errorCallback @param {Function} progressCallback @return {Promise}
[ "Return", "a", "new", "promise" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L488-L503
55,557
altshift/altshift
lib/altshift/promise.js
function (error, dontThrow) { var self = this; self.isError = true; self._notifyAll(error); if (!dontThrow) { enqueue(function () { if (!self.handled) { throw error; } }); } return self.handled; }
javascript
function (error, dontThrow) { var self = this; self.isError = true; self._notifyAll(error); if (!dontThrow) { enqueue(function () { if (!self.handled) { throw error; } }); } return self.handled; }
[ "function", "(", "error", ",", "dontThrow", ")", "{", "var", "self", "=", "this", ";", "self", ".", "isError", "=", "true", ";", "self", ".", "_notifyAll", "(", "error", ")", ";", "if", "(", "!", "dontThrow", ")", "{", "enqueue", "(", "function", "(", ")", "{", "if", "(", "!", "self", ".", "handled", ")", "{", "throw", "error", ";", "}", "}", ")", ";", "}", "return", "self", ".", "handled", ";", "}" ]
Calling emitError will indicate that the promise failed @param {*} value send to all resolved callbacks @return this
[ "Calling", "emitError", "will", "indicate", "that", "the", "promise", "failed" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L531-L544
55,558
altshift/altshift
lib/altshift/promise.js
function (update) { var waiting = this.waiting, length = waiting.length, index, progress; for (index = 0; index < length; index += 1) { progress = waiting[index].progress; if (progress) { progress(update); } } return this; }
javascript
function (update) { var waiting = this.waiting, length = waiting.length, index, progress; for (index = 0; index < length; index += 1) { progress = waiting[index].progress; if (progress) { progress(update); } } return this; }
[ "function", "(", "update", ")", "{", "var", "waiting", "=", "this", ".", "waiting", ",", "length", "=", "waiting", ".", "length", ",", "index", ",", "progress", ";", "for", "(", "index", "=", "0", ";", "index", "<", "length", ";", "index", "+=", "1", ")", "{", "progress", "=", "waiting", "[", "index", "]", ".", "progress", ";", "if", "(", "progress", ")", "{", "progress", "(", "update", ")", ";", "}", "}", "return", "this", ";", "}" ]
Call progress on every waiting function to notify that the promise was updated @param {*} update @return this
[ "Call", "progress", "on", "every", "waiting", "function", "to", "notify", "that", "the", "promise", "was", "updated" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L558-L571
55,559
altshift/altshift
lib/altshift/promise.js
function () { if (!this.finished && this._canceller) { var error = this._canceller(); if (!(error instanceof Error)) { error = new Error(error); } return this.emitError(error); } return false; }
javascript
function () { if (!this.finished && this._canceller) { var error = this._canceller(); if (!(error instanceof Error)) { error = new Error(error); } return this.emitError(error); } return false; }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "finished", "&&", "this", ".", "_canceller", ")", "{", "var", "error", "=", "this", ".", "_canceller", "(", ")", ";", "if", "(", "!", "(", "error", "instanceof", "Error", ")", ")", "{", "error", "=", "new", "Error", "(", "error", ")", ";", "}", "return", "this", ".", "emitError", "(", "error", ")", ";", "}", "return", "false", ";", "}" ]
Cancel the promise @return {boolean} true if error was handled
[ "Cancel", "the", "promise" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L578-L587
55,560
altshift/altshift
lib/altshift/promise.js
function (milliseconds) { if (milliseconds === undefined) { milliseconds = this._timeout; } var self = this; if (self._timeout !== milliseconds) { self._timeout = milliseconds; if (self._timer) { clearTimeout(this._timer); self._timer = null; } if (milliseconds) { this._timer = setTimeout(function () { self._timer = null; if (!self.finished) { var error = new core.Error({ code: 'timeout', message: 'Promise has timeout' }); /*if (self.getPromise().cancel) { self.getPromise().cancel(error); } else { self.emitError(error); }*/ if (this._canceller) { self.cancel(error); } else { self.emitError(error); } } }, milliseconds); } } return this; }
javascript
function (milliseconds) { if (milliseconds === undefined) { milliseconds = this._timeout; } var self = this; if (self._timeout !== milliseconds) { self._timeout = milliseconds; if (self._timer) { clearTimeout(this._timer); self._timer = null; } if (milliseconds) { this._timer = setTimeout(function () { self._timer = null; if (!self.finished) { var error = new core.Error({ code: 'timeout', message: 'Promise has timeout' }); /*if (self.getPromise().cancel) { self.getPromise().cancel(error); } else { self.emitError(error); }*/ if (this._canceller) { self.cancel(error); } else { self.emitError(error); } } }, milliseconds); } } return this; }
[ "function", "(", "milliseconds", ")", "{", "if", "(", "milliseconds", "===", "undefined", ")", "{", "milliseconds", "=", "this", ".", "_timeout", ";", "}", "var", "self", "=", "this", ";", "if", "(", "self", ".", "_timeout", "!==", "milliseconds", ")", "{", "self", ".", "_timeout", "=", "milliseconds", ";", "if", "(", "self", ".", "_timer", ")", "{", "clearTimeout", "(", "this", ".", "_timer", ")", ";", "self", ".", "_timer", "=", "null", ";", "}", "if", "(", "milliseconds", ")", "{", "this", ".", "_timer", "=", "setTimeout", "(", "function", "(", ")", "{", "self", ".", "_timer", "=", "null", ";", "if", "(", "!", "self", ".", "finished", ")", "{", "var", "error", "=", "new", "core", ".", "Error", "(", "{", "code", ":", "'timeout'", ",", "message", ":", "'Promise has timeout'", "}", ")", ";", "/*if (self.getPromise().cancel) {\n self.getPromise().cancel(error);\n } else {\n self.emitError(error);\n }*/", "if", "(", "this", ".", "_canceller", ")", "{", "self", ".", "cancel", "(", "error", ")", ";", "}", "else", "{", "self", ".", "emitError", "(", "error", ")", ";", "}", "}", "}", ",", "milliseconds", ")", ";", "}", "}", "return", "this", ";", "}" ]
Set the timeout in milliseconds to auto cancel the promise @param {int} milliseconds @return this
[ "Set", "the", "timeout", "in", "milliseconds", "to", "auto", "cancel", "the", "promise" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L595-L634
55,561
altshift/altshift
lib/altshift/promise.js
function (target, property) { return perform(target, function (target) { return target.get(property); }, function (target) { return target[property]; }); }
javascript
function (target, property) { return perform(target, function (target) { return target.get(property); }, function (target) { return target[property]; }); }
[ "function", "(", "target", ",", "property", ")", "{", "return", "perform", "(", "target", ",", "function", "(", "target", ")", "{", "return", "target", ".", "get", "(", "property", ")", ";", "}", ",", "function", "(", "target", ")", "{", "return", "target", "[", "property", "]", ";", "}", ")", ";", "}" ]
Gets the value of a property in a future turn. @param {Promise} target promise or value for target object @param {string} property name of property to get @return {Promise} promise for the property value
[ "Gets", "the", "value", "of", "a", "property", "in", "a", "future", "turn", "." ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L768-L774
55,562
altshift/altshift
lib/altshift/promise.js
function (target, methodName, args) { return perform(target, function (target) { return target.apply(methodName, args); }, function (target) { return target[methodName].apply(target, args); }); }
javascript
function (target, methodName, args) { return perform(target, function (target) { return target.apply(methodName, args); }, function (target) { return target[methodName].apply(target, args); }); }
[ "function", "(", "target", ",", "methodName", ",", "args", ")", "{", "return", "perform", "(", "target", ",", "function", "(", "target", ")", "{", "return", "target", ".", "apply", "(", "methodName", ",", "args", ")", ";", "}", ",", "function", "(", "target", ")", "{", "return", "target", "[", "methodName", "]", ".", "apply", "(", "target", ",", "args", ")", ";", "}", ")", ";", "}" ]
Invokes a method in a future turn. @param {Promise} target promise or value for target object @param {string} methodName name of method to invoke @param {Array} args array of invocation arguments @return {Promise} promise for the return value
[ "Invokes", "a", "method", "in", "a", "future", "turn", "." ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L784-L790
55,563
altshift/altshift
lib/altshift/promise.js
function (target, property, value) { return perform(target, function (target) { return target.set(property, value); }, function (target) { target[property] = value; return value; }); }
javascript
function (target, property, value) { return perform(target, function (target) { return target.set(property, value); }, function (target) { target[property] = value; return value; }); }
[ "function", "(", "target", ",", "property", ",", "value", ")", "{", "return", "perform", "(", "target", ",", "function", "(", "target", ")", "{", "return", "target", ".", "set", "(", "property", ",", "value", ")", ";", "}", ",", "function", "(", "target", ")", "{", "target", "[", "property", "]", "=", "value", ";", "return", "value", ";", "}", ")", ";", "}" ]
Sets the value of a property in a future turn. @param {Promise} target promise or value for target object @param {string} property name of property to set @param {*} value new value of property @return promise for the return value
[ "Sets", "the", "value", "of", "a", "property", "in", "a", "future", "turn", "." ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L800-L807
55,564
altshift/altshift
lib/altshift/promise.js
function (asyncFunction, callbackNotDeclared) { var arity = asyncFunction.length; return function () { var deferred = new Deferred(), args = slice.call(arguments), callback; if (callbackNotDeclared && !args[args.length + 1] instanceof Function) { arity = args.length + 1; } callback = args[arity - 1]; args.splice(arity); args[arity - 1] = function (error, result) { if (error) { deferred.emitError(error); } else { if (args.length > 2) { // if there are multiple success values, we return an array args.shift(1); deferred.emitSuccess(args); } else { deferred.emitSuccess(result); } } }; asyncFunction.apply(this, args); //Node old school if (callback) { deferred.then( function (result) { callback(Promise.NO_ERROR, result); }, function (error) { callback(error, Promise.NO_RESULT); } ); } return deferred.getPromise(); }; }
javascript
function (asyncFunction, callbackNotDeclared) { var arity = asyncFunction.length; return function () { var deferred = new Deferred(), args = slice.call(arguments), callback; if (callbackNotDeclared && !args[args.length + 1] instanceof Function) { arity = args.length + 1; } callback = args[arity - 1]; args.splice(arity); args[arity - 1] = function (error, result) { if (error) { deferred.emitError(error); } else { if (args.length > 2) { // if there are multiple success values, we return an array args.shift(1); deferred.emitSuccess(args); } else { deferred.emitSuccess(result); } } }; asyncFunction.apply(this, args); //Node old school if (callback) { deferred.then( function (result) { callback(Promise.NO_ERROR, result); }, function (error) { callback(error, Promise.NO_RESULT); } ); } return deferred.getPromise(); }; }
[ "function", "(", "asyncFunction", ",", "callbackNotDeclared", ")", "{", "var", "arity", "=", "asyncFunction", ".", "length", ";", "return", "function", "(", ")", "{", "var", "deferred", "=", "new", "Deferred", "(", ")", ",", "args", "=", "slice", ".", "call", "(", "arguments", ")", ",", "callback", ";", "if", "(", "callbackNotDeclared", "&&", "!", "args", "[", "args", ".", "length", "+", "1", "]", "instanceof", "Function", ")", "{", "arity", "=", "args", ".", "length", "+", "1", ";", "}", "callback", "=", "args", "[", "arity", "-", "1", "]", ";", "args", ".", "splice", "(", "arity", ")", ";", "args", "[", "arity", "-", "1", "]", "=", "function", "(", "error", ",", "result", ")", "{", "if", "(", "error", ")", "{", "deferred", ".", "emitError", "(", "error", ")", ";", "}", "else", "{", "if", "(", "args", ".", "length", ">", "2", ")", "{", "// if there are multiple success values, we return an array", "args", ".", "shift", "(", "1", ")", ";", "deferred", ".", "emitSuccess", "(", "args", ")", ";", "}", "else", "{", "deferred", ".", "emitSuccess", "(", "result", ")", ";", "}", "}", "}", ";", "asyncFunction", ".", "apply", "(", "this", ",", "args", ")", ";", "//Node old school", "if", "(", "callback", ")", "{", "deferred", ".", "then", "(", "function", "(", "result", ")", "{", "callback", "(", "Promise", ".", "NO_ERROR", ",", "result", ")", ";", "}", ",", "function", "(", "error", ")", "{", "callback", "(", "error", ",", "Promise", ".", "NO_RESULT", ")", ";", "}", ")", ";", "}", "return", "deferred", ".", "getPromise", "(", ")", ";", "}", ";", "}" ]
Converts a Node async function to a promise returning function @param {Function} asyncFunction node async function which takes a callback as its last argument @param {boolean} callbackNotDeclared true if callback is optional in the definition @return {Function} A function that returns a promise
[ "Converts", "a", "Node", "async", "function", "to", "a", "promise", "returning", "function" ]
5c051157e6f558636c8e12081b6707caa66249de
https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/promise.js#L907-L949
55,565
iopa-io/iopa-devices
demo.js
DemoDevice
function DemoDevice(){ var _device = {}; _device[DEVICE.ModelManufacturer] = "Internet of Protocols Alliance"; _device[DEVICE.ModelManufacturerUrl] = "http://iopa.io"; _device[DEVICE.ModelName] = "npm install iopa-devices"; _device[DEVICE.ModelNumber] = "iopa-devices"; _device[DEVICE.ModelUrl] = "http://github.com/iopa-io/iopa-devices"; _device[DEVICE.PlatformId] = "LOCALHOST"; _device[DEVICE.PlatformName] = "Iopa Device Stick"; _device[DEVICE.PlatformFirmware] = packageVersion; _device[DEVICE.PlatformOS] = require('os').type() + "/" + require('os').release(); _device[DEVICE.Id] = "12345-67890"; _device[DEVICE.Type] = "urn:io.iopa:demo:devices"; _device[DEVICE.Version] = packageVersion; _device[DEVICE.Location] = [37.7833, 122.4167]; _device[DEVICE.LocationName] = "San Francisco, USA"; _device[DEVICE.Currency] = "USD"; _device[DEVICE.Region] = "Home"; _device[DEVICE.Policy] = null; _device[DEVICE.Url] = "coap://localhost"; _device[DEVICE.Resources] = []; var _res = {}; _res[RESOURCE.TypeName] = "IOPA Demo Projector"; _res[RESOURCE.Type] = "urn:io.iopa:resource:projector"; _res[RESOURCE.Interface] = "if.switch.binary"; _res[RESOURCE.Path] = "/media/projector"; _res[RESOURCE.Name] = "Projector 1"; _res[RESOURCE.Value] = false; _device[DEVICE.Resources].push(_res); this._device = _device; }
javascript
function DemoDevice(){ var _device = {}; _device[DEVICE.ModelManufacturer] = "Internet of Protocols Alliance"; _device[DEVICE.ModelManufacturerUrl] = "http://iopa.io"; _device[DEVICE.ModelName] = "npm install iopa-devices"; _device[DEVICE.ModelNumber] = "iopa-devices"; _device[DEVICE.ModelUrl] = "http://github.com/iopa-io/iopa-devices"; _device[DEVICE.PlatformId] = "LOCALHOST"; _device[DEVICE.PlatformName] = "Iopa Device Stick"; _device[DEVICE.PlatformFirmware] = packageVersion; _device[DEVICE.PlatformOS] = require('os').type() + "/" + require('os').release(); _device[DEVICE.Id] = "12345-67890"; _device[DEVICE.Type] = "urn:io.iopa:demo:devices"; _device[DEVICE.Version] = packageVersion; _device[DEVICE.Location] = [37.7833, 122.4167]; _device[DEVICE.LocationName] = "San Francisco, USA"; _device[DEVICE.Currency] = "USD"; _device[DEVICE.Region] = "Home"; _device[DEVICE.Policy] = null; _device[DEVICE.Url] = "coap://localhost"; _device[DEVICE.Resources] = []; var _res = {}; _res[RESOURCE.TypeName] = "IOPA Demo Projector"; _res[RESOURCE.Type] = "urn:io.iopa:resource:projector"; _res[RESOURCE.Interface] = "if.switch.binary"; _res[RESOURCE.Path] = "/media/projector"; _res[RESOURCE.Name] = "Projector 1"; _res[RESOURCE.Value] = false; _device[DEVICE.Resources].push(_res); this._device = _device; }
[ "function", "DemoDevice", "(", ")", "{", "var", "_device", "=", "{", "}", ";", "_device", "[", "DEVICE", ".", "ModelManufacturer", "]", "=", "\"Internet of Protocols Alliance\"", ";", "_device", "[", "DEVICE", ".", "ModelManufacturerUrl", "]", "=", "\"http://iopa.io\"", ";", "_device", "[", "DEVICE", ".", "ModelName", "]", "=", "\"npm install iopa-devices\"", ";", "_device", "[", "DEVICE", ".", "ModelNumber", "]", "=", "\"iopa-devices\"", ";", "_device", "[", "DEVICE", ".", "ModelUrl", "]", "=", "\"http://github.com/iopa-io/iopa-devices\"", ";", "_device", "[", "DEVICE", ".", "PlatformId", "]", "=", "\"LOCALHOST\"", ";", "_device", "[", "DEVICE", ".", "PlatformName", "]", "=", "\"Iopa Device Stick\"", ";", "_device", "[", "DEVICE", ".", "PlatformFirmware", "]", "=", "packageVersion", ";", "_device", "[", "DEVICE", ".", "PlatformOS", "]", "=", "require", "(", "'os'", ")", ".", "type", "(", ")", "+", "\"/\"", "+", "require", "(", "'os'", ")", ".", "release", "(", ")", ";", "_device", "[", "DEVICE", ".", "Id", "]", "=", "\"12345-67890\"", ";", "_device", "[", "DEVICE", ".", "Type", "]", "=", "\"urn:io.iopa:demo:devices\"", ";", "_device", "[", "DEVICE", ".", "Version", "]", "=", "packageVersion", ";", "_device", "[", "DEVICE", ".", "Location", "]", "=", "[", "37.7833", ",", "122.4167", "]", ";", "_device", "[", "DEVICE", ".", "LocationName", "]", "=", "\"San Francisco, USA\"", ";", "_device", "[", "DEVICE", ".", "Currency", "]", "=", "\"USD\"", ";", "_device", "[", "DEVICE", ".", "Region", "]", "=", "\"Home\"", ";", "_device", "[", "DEVICE", ".", "Policy", "]", "=", "null", ";", "_device", "[", "DEVICE", ".", "Url", "]", "=", "\"coap://localhost\"", ";", "_device", "[", "DEVICE", ".", "Resources", "]", "=", "[", "]", ";", "var", "_res", "=", "{", "}", ";", "_res", "[", "RESOURCE", ".", "TypeName", "]", "=", "\"IOPA Demo Projector\"", ";", "_res", "[", "RESOURCE", ".", "Type", "]", "=", "\"urn:io.iopa:resource:projector\"", ";", "_res", "[", "RESOURCE", ".", "Interface", "]", "=", "\"if.switch.binary\"", ";", "_res", "[", "RESOURCE", ".", "Path", "]", "=", "\"/media/projector\"", ";", "_res", "[", "RESOURCE", ".", "Name", "]", "=", "\"Projector 1\"", ";", "_res", "[", "RESOURCE", ".", "Value", "]", "=", "false", ";", "_device", "[", "DEVICE", ".", "Resources", "]", ".", "push", "(", "_res", ")", ";", "this", ".", "_device", "=", "_device", ";", "}" ]
Demo Device Class
[ "Demo", "Device", "Class" ]
1610a73f391fefa3f67f21b113f2206f13ba268d
https://github.com/iopa-io/iopa-devices/blob/1610a73f391fefa3f67f21b113f2206f13ba268d/demo.js#L46-L80
55,566
mannyvergel/oils-js
core/utils/oilsUtils.js
function(arrPathFromRoot) { if (arrPathFromRoot) { let routes = {}; for (let pathFromRoot of arrPathFromRoot) { routes['/' + pathFromRoot] = { get: function(req, res) { web.utils.serveStaticFile(path.join(web.conf.publicDir, pathFromRoot), res); } } } return routes; } return null; }
javascript
function(arrPathFromRoot) { if (arrPathFromRoot) { let routes = {}; for (let pathFromRoot of arrPathFromRoot) { routes['/' + pathFromRoot] = { get: function(req, res) { web.utils.serveStaticFile(path.join(web.conf.publicDir, pathFromRoot), res); } } } return routes; } return null; }
[ "function", "(", "arrPathFromRoot", ")", "{", "if", "(", "arrPathFromRoot", ")", "{", "let", "routes", "=", "{", "}", ";", "for", "(", "let", "pathFromRoot", "of", "arrPathFromRoot", ")", "{", "routes", "[", "'/'", "+", "pathFromRoot", "]", "=", "{", "get", ":", "function", "(", "req", ",", "res", ")", "{", "web", ".", "utils", ".", "serveStaticFile", "(", "path", ".", "join", "(", "web", ".", "conf", ".", "publicDir", ",", "pathFromRoot", ")", ",", "res", ")", ";", "}", "}", "}", "return", "routes", ";", "}", "return", "null", ";", "}" ]
because of the ability to change the context of the public folder some icons like favico, sitemap, robots.txt are still best served in root
[ "because", "of", "the", "ability", "to", "change", "the", "context", "of", "the", "public", "folder", "some", "icons", "like", "favico", "sitemap", "robots", ".", "txt", "are", "still", "best", "served", "in", "root" ]
8d23714cab202f6dbb79d5d4ec536a684d77ca00
https://github.com/mannyvergel/oils-js/blob/8d23714cab202f6dbb79d5d4ec536a684d77ca00/core/utils/oilsUtils.js#L25-L40
55,567
GoIncremental/gi-util
dist/gi-util.js
transformData
function transformData(data, headers, status, fns) { if (isFunction(fns)) return fns(data, headers, status); forEach(fns, function(fn) { data = fn(data, headers, status); }); return data; }
javascript
function transformData(data, headers, status, fns) { if (isFunction(fns)) return fns(data, headers, status); forEach(fns, function(fn) { data = fn(data, headers, status); }); return data; }
[ "function", "transformData", "(", "data", ",", "headers", ",", "status", ",", "fns", ")", "{", "if", "(", "isFunction", "(", "fns", ")", ")", "return", "fns", "(", "data", ",", "headers", ",", "status", ")", ";", "forEach", "(", "fns", ",", "function", "(", "fn", ")", "{", "data", "=", "fn", "(", "data", ",", "headers", ",", "status", ")", ";", "}", ")", ";", "return", "data", ";", "}" ]
Chain all given functions This function is used for both request and response transforming @param {*} data Data to transform. @param {function(string=)} headers HTTP headers getter fn. @param {number} status HTTP status code of the response. @param {(Function|Array.<Function>)} fns Function or an array of functions. @returns {*} Transformed data.
[ "Chain", "all", "given", "functions" ]
ea9eb87f1c94efbc2a5f935e8159b536d7af3c40
https://github.com/GoIncremental/gi-util/blob/ea9eb87f1c94efbc2a5f935e8159b536d7af3c40/dist/gi-util.js#L13310-L13319
55,568
nfroidure/gulp-vartree
src/index.js
treeSorter
function treeSorter(node) { if(node[options.childsProp]) { node[options.childsProp].forEach(function(node) { treeSorter(node); }); node[options.childsProp].sort(function childSorter(a, b) { var result; if('undefined' === typeof a[options.sortProp]) { result = (options.sortDesc ? 1 : -1); } else if('undefined' === typeof b[options.sortProp]) { result = (options.sortDesc ? -1 : 1); } else { result = a[options.sortProp] > b[options.sortProp] ? (options.sortDesc ? -1 : 1) : (options.sortDesc ? 1 : -1); } return result; }); } }
javascript
function treeSorter(node) { if(node[options.childsProp]) { node[options.childsProp].forEach(function(node) { treeSorter(node); }); node[options.childsProp].sort(function childSorter(a, b) { var result; if('undefined' === typeof a[options.sortProp]) { result = (options.sortDesc ? 1 : -1); } else if('undefined' === typeof b[options.sortProp]) { result = (options.sortDesc ? -1 : 1); } else { result = a[options.sortProp] > b[options.sortProp] ? (options.sortDesc ? -1 : 1) : (options.sortDesc ? 1 : -1); } return result; }); } }
[ "function", "treeSorter", "(", "node", ")", "{", "if", "(", "node", "[", "options", ".", "childsProp", "]", ")", "{", "node", "[", "options", ".", "childsProp", "]", ".", "forEach", "(", "function", "(", "node", ")", "{", "treeSorter", "(", "node", ")", ";", "}", ")", ";", "node", "[", "options", ".", "childsProp", "]", ".", "sort", "(", "function", "childSorter", "(", "a", ",", "b", ")", "{", "var", "result", ";", "if", "(", "'undefined'", "===", "typeof", "a", "[", "options", ".", "sortProp", "]", ")", "{", "result", "=", "(", "options", ".", "sortDesc", "?", "1", ":", "-", "1", ")", ";", "}", "else", "if", "(", "'undefined'", "===", "typeof", "b", "[", "options", ".", "sortProp", "]", ")", "{", "result", "=", "(", "options", ".", "sortDesc", "?", "-", "1", ":", "1", ")", ";", "}", "else", "{", "result", "=", "a", "[", "options", ".", "sortProp", "]", ">", "b", "[", "options", ".", "sortProp", "]", "?", "(", "options", ".", "sortDesc", "?", "-", "1", ":", "1", ")", ":", "(", "options", ".", "sortDesc", "?", "1", ":", "-", "1", ")", ";", "}", "return", "result", ";", "}", ")", ";", "}", "}" ]
Tree sorting function
[ "Tree", "sorting", "function" ]
44ea5059845b2e330f7514a666d89eb8e889422e
https://github.com/nfroidure/gulp-vartree/blob/44ea5059845b2e330f7514a666d89eb8e889422e/src/index.js#L41-L59
55,569
Jam3/innkeeper
index.js
function( userId ) { return this.memory.createRoom( userId ) .then( function( id ) { rooms[ id ] = room( this.memory, id ); return promise.resolve( rooms[ id ] ); }.bind( this ), function() { return promise.reject( 'could not get a roomID to create a room' ); }); }
javascript
function( userId ) { return this.memory.createRoom( userId ) .then( function( id ) { rooms[ id ] = room( this.memory, id ); return promise.resolve( rooms[ id ] ); }.bind( this ), function() { return promise.reject( 'could not get a roomID to create a room' ); }); }
[ "function", "(", "userId", ")", "{", "return", "this", ".", "memory", ".", "createRoom", "(", "userId", ")", ".", "then", "(", "function", "(", "id", ")", "{", "rooms", "[", "id", "]", "=", "room", "(", "this", ".", "memory", ",", "id", ")", ";", "return", "promise", ".", "resolve", "(", "rooms", "[", "id", "]", ")", ";", "}", ".", "bind", "(", "this", ")", ",", "function", "(", ")", "{", "return", "promise", ".", "reject", "(", "'could not get a roomID to create a room'", ")", ";", "}", ")", ";", "}" ]
Create a new room object @param {String} userId id of the user whose reserving a room @param {Boolean} isPublic whether the room your are creating is publicly available @return {Promise} This promise will resolve by sending a room instance
[ "Create", "a", "new", "room", "object" ]
95182271c62cf4416442c825189f025234b6ef1e
https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/index.js#L28-L40
55,570
Jam3/innkeeper
index.js
function( userId, id ) { return this.memory.joinRoom( userId, id ) .then( function( id ) { if( rooms[ id ] === undefined ) { rooms[ id ] = room( this.memory, id ); } return promise.resolve( rooms[ id ] ); }.bind( this )); }
javascript
function( userId, id ) { return this.memory.joinRoom( userId, id ) .then( function( id ) { if( rooms[ id ] === undefined ) { rooms[ id ] = room( this.memory, id ); } return promise.resolve( rooms[ id ] ); }.bind( this )); }
[ "function", "(", "userId", ",", "id", ")", "{", "return", "this", ".", "memory", ".", "joinRoom", "(", "userId", ",", "id", ")", ".", "then", "(", "function", "(", "id", ")", "{", "if", "(", "rooms", "[", "id", "]", "===", "undefined", ")", "{", "rooms", "[", "id", "]", "=", "room", "(", "this", ".", "memory", ",", "id", ")", ";", "}", "return", "promise", ".", "resolve", "(", "rooms", "[", "id", "]", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}" ]
Join a room @param {String} userId id of the user whose entering a room @param {String} id id for the room you'd like to enter @return {Promise} This promise will resolve by sending a room instance if the room does not exist it will fail
[ "Join", "a", "room" ]
95182271c62cf4416442c825189f025234b6ef1e
https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/index.js#L49-L61
55,571
Jam3/innkeeper
index.js
function( userId ) { return this.memory.getPublicRoom() .then(function( roomId ) { if ( roomId ) { return this.enter( userId, roomId); } else { return promise.reject( 'Could not find a public room' ); } }.bind(this)); }
javascript
function( userId ) { return this.memory.getPublicRoom() .then(function( roomId ) { if ( roomId ) { return this.enter( userId, roomId); } else { return promise.reject( 'Could not find a public room' ); } }.bind(this)); }
[ "function", "(", "userId", ")", "{", "return", "this", ".", "memory", ".", "getPublicRoom", "(", ")", ".", "then", "(", "function", "(", "roomId", ")", "{", "if", "(", "roomId", ")", "{", "return", "this", ".", "enter", "(", "userId", ",", "roomId", ")", ";", "}", "else", "{", "return", "promise", ".", "reject", "(", "'Could not find a public room'", ")", ";", "}", "}", ".", "bind", "(", "this", ")", ")", ";", "}" ]
Join an available public room or create one @param {String} userId id of the user whose entering a room @return {Promise} This promise will resolve by sending a room instance, or reject if no public rooms available
[ "Join", "an", "available", "public", "room", "or", "create", "one" ]
95182271c62cf4416442c825189f025234b6ef1e
https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/index.js#L82-L91
55,572
Jam3/innkeeper
index.js
function( userId, id ) { return this.memory.leaveRoom( userId, id ) .then( function( numUsers ) { if( numUsers == 0 ) { // remove all listeners from room since there should be one rooms[ id ].removeAllListeners(); rooms[ id ].setPrivate(); delete rooms[ id ]; return promise.resolve( null ); } else { return promise.resolve( rooms[ id ] ); } }); }
javascript
function( userId, id ) { return this.memory.leaveRoom( userId, id ) .then( function( numUsers ) { if( numUsers == 0 ) { // remove all listeners from room since there should be one rooms[ id ].removeAllListeners(); rooms[ id ].setPrivate(); delete rooms[ id ]; return promise.resolve( null ); } else { return promise.resolve( rooms[ id ] ); } }); }
[ "function", "(", "userId", ",", "id", ")", "{", "return", "this", ".", "memory", ".", "leaveRoom", "(", "userId", ",", "id", ")", ".", "then", "(", "function", "(", "numUsers", ")", "{", "if", "(", "numUsers", "==", "0", ")", "{", "// remove all listeners from room since there should be one", "rooms", "[", "id", "]", ".", "removeAllListeners", "(", ")", ";", "rooms", "[", "id", "]", ".", "setPrivate", "(", ")", ";", "delete", "rooms", "[", "id", "]", ";", "return", "promise", ".", "resolve", "(", "null", ")", ";", "}", "else", "{", "return", "promise", ".", "resolve", "(", "rooms", "[", "id", "]", ")", ";", "}", "}", ")", ";", "}" ]
Leave a room. @param {String} userId id of the user whose leaving a room @param {String} id id for the room you'd like to leave @return {Promise} When this promise resolves it will return a room object if the room still exists and null if not
[ "Leave", "a", "room", "." ]
95182271c62cf4416442c825189f025234b6ef1e
https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/index.js#L100-L118
55,573
juttle/juttle-googleanalytics-adapter
lib/google.js
getProperties
function getProperties() { return analytics.management.webproperties.listAsync({ auth: auth, accountId: accountId }) .then((properties) => { logger.debug('got properties', JSON.stringify(properties, null, 4)); return _.map(properties.items, (property) => { return _.pick(property, 'id', 'name'); }); }); }
javascript
function getProperties() { return analytics.management.webproperties.listAsync({ auth: auth, accountId: accountId }) .then((properties) => { logger.debug('got properties', JSON.stringify(properties, null, 4)); return _.map(properties.items, (property) => { return _.pick(property, 'id', 'name'); }); }); }
[ "function", "getProperties", "(", ")", "{", "return", "analytics", ".", "management", ".", "webproperties", ".", "listAsync", "(", "{", "auth", ":", "auth", ",", "accountId", ":", "accountId", "}", ")", ".", "then", "(", "(", "properties", ")", "=>", "{", "logger", ".", "debug", "(", "'got properties'", ",", "JSON", ".", "stringify", "(", "properties", ",", "null", ",", "4", ")", ")", ";", "return", "_", ".", "map", "(", "properties", ".", "items", ",", "(", "property", ")", "=>", "{", "return", "_", ".", "pick", "(", "property", ",", "'id'", ",", "'name'", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Get all accessible properties for the account
[ "Get", "all", "accessible", "properties", "for", "the", "account" ]
2843c9667f21a3ff5dad62eca34e9935e835da22
https://github.com/juttle/juttle-googleanalytics-adapter/blob/2843c9667f21a3ff5dad62eca34e9935e835da22/lib/google.js#L116-L127
55,574
juttle/juttle-googleanalytics-adapter
lib/google.js
getViews
function getViews(property, options) { logger.debug('getting views for', property); return analytics.management.profiles.listAsync({ auth: auth, accountId: accountId, webPropertyId: property.id }) .then((profiles) => { // If we're not grouping by view, then only include the default view // named "All Web Site Data". Otherwise the counts can potentially be // duplicated. if (options.metagroup !== 'view') { profiles.items = _.where(profiles.items, {name: 'All Web Site Data'}); } return _.map(profiles.items, (profile) => { return { webPropertyId: property.id, webProperty: property.name, viewId: profile.id, view: profile.name }; }); }); }
javascript
function getViews(property, options) { logger.debug('getting views for', property); return analytics.management.profiles.listAsync({ auth: auth, accountId: accountId, webPropertyId: property.id }) .then((profiles) => { // If we're not grouping by view, then only include the default view // named "All Web Site Data". Otherwise the counts can potentially be // duplicated. if (options.metagroup !== 'view') { profiles.items = _.where(profiles.items, {name: 'All Web Site Data'}); } return _.map(profiles.items, (profile) => { return { webPropertyId: property.id, webProperty: property.name, viewId: profile.id, view: profile.name }; }); }); }
[ "function", "getViews", "(", "property", ",", "options", ")", "{", "logger", ".", "debug", "(", "'getting views for'", ",", "property", ")", ";", "return", "analytics", ".", "management", ".", "profiles", ".", "listAsync", "(", "{", "auth", ":", "auth", ",", "accountId", ":", "accountId", ",", "webPropertyId", ":", "property", ".", "id", "}", ")", ".", "then", "(", "(", "profiles", ")", "=>", "{", "// If we're not grouping by view, then only include the default view", "// named \"All Web Site Data\". Otherwise the counts can potentially be", "// duplicated.", "if", "(", "options", ".", "metagroup", "!==", "'view'", ")", "{", "profiles", ".", "items", "=", "_", ".", "where", "(", "profiles", ".", "items", ",", "{", "name", ":", "'All Web Site Data'", "}", ")", ";", "}", "return", "_", ".", "map", "(", "profiles", ".", "items", ",", "(", "profile", ")", "=>", "{", "return", "{", "webPropertyId", ":", "property", ".", "id", ",", "webProperty", ":", "property", ".", "name", ",", "viewId", ":", "profile", ".", "id", ",", "view", ":", "profile", ".", "name", "}", ";", "}", ")", ";", "}", ")", ";", "}" ]
Get all views for the given property
[ "Get", "all", "views", "for", "the", "given", "property" ]
2843c9667f21a3ff5dad62eca34e9935e835da22
https://github.com/juttle/juttle-googleanalytics-adapter/blob/2843c9667f21a3ff5dad62eca34e9935e835da22/lib/google.js#L130-L153
55,575
hl198181/neptune
misc/demo/public/vendor/plupload-2.1.2/js/plupload.dev.js
get
function get(ids) { var els = [], el; if (o.typeOf(ids) !== 'array') { ids = [ids]; } var i = ids.length; while (i--) { el = o.get(ids[i]); if (el) { els.push(el); } } return els.length ? els : null; }
javascript
function get(ids) { var els = [], el; if (o.typeOf(ids) !== 'array') { ids = [ids]; } var i = ids.length; while (i--) { el = o.get(ids[i]); if (el) { els.push(el); } } return els.length ? els : null; }
[ "function", "get", "(", "ids", ")", "{", "var", "els", "=", "[", "]", ",", "el", ";", "if", "(", "o", ".", "typeOf", "(", "ids", ")", "!==", "'array'", ")", "{", "ids", "=", "[", "ids", "]", ";", "}", "var", "i", "=", "ids", ".", "length", ";", "while", "(", "i", "--", ")", "{", "el", "=", "o", ".", "get", "(", "ids", "[", "i", "]", ")", ";", "if", "(", "el", ")", "{", "els", ".", "push", "(", "el", ")", ";", "}", "}", "return", "els", ".", "length", "?", "els", ":", "null", ";", "}" ]
Get array of DOM Elements by their ids. @method get @for Utils @param {String} id Identifier of the DOM Element @return {Array}
[ "Get", "array", "of", "DOM", "Elements", "by", "their", "ids", "." ]
88030bb4222945900e6a225469380cc43a016c13
https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/plupload.dev.js#L310-L326
55,576
hl198181/neptune
misc/demo/public/vendor/plupload-2.1.2/js/plupload.dev.js
function(config, runtimes) { var up, runtime; up = new plupload.Uploader(config); runtime = o.Runtime.thatCan(up.getOption().required_features, runtimes || config.runtimes); up.destroy(); return runtime; }
javascript
function(config, runtimes) { var up, runtime; up = new plupload.Uploader(config); runtime = o.Runtime.thatCan(up.getOption().required_features, runtimes || config.runtimes); up.destroy(); return runtime; }
[ "function", "(", "config", ",", "runtimes", ")", "{", "var", "up", ",", "runtime", ";", "up", "=", "new", "plupload", ".", "Uploader", "(", "config", ")", ";", "runtime", "=", "o", ".", "Runtime", ".", "thatCan", "(", "up", ".", "getOption", "(", ")", ".", "required_features", ",", "runtimes", "||", "config", ".", "runtimes", ")", ";", "up", ".", "destroy", "(", ")", ";", "return", "runtime", ";", "}" ]
A way to predict what runtime will be choosen in the current environment with the specified settings. @method predictRuntime @static @param {Object|String} config Plupload settings to check @param {String} [runtimes] Comma-separated list of runtimes to check against @return {String} Type of compatible runtime
[ "A", "way", "to", "predict", "what", "runtime", "will", "be", "choosen", "in", "the", "current", "environment", "with", "the", "specified", "settings", "." ]
88030bb4222945900e6a225469380cc43a016c13
https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/plupload.dev.js#L625-L632
55,577
robertblackwell/yake
src/yake/tasks.js
normalizeArguments
function normalizeArguments() { const a = arguments; if (debug) debugLog(`normalizeArguments: arguments:${util.inspect(arguments)}`); if (debug) debugLog(`normalizeArguments: a0: ${a[0]} a1:${a[1]} a2:${a[2]} a3:${a[3]}`); if (debug) debugLog(`normalizeArguments: a0: ${typeof a[0]} a1:${typeof a[1]} a2:${typeof a[2]} a3:${typeof a[3]}`); if (debug) { debugLog(`normalizeArguments:` + ` a0: ${typeof a[0]} a1:${typeof a[1]} a2:${Array.isArray(a[2])} a3:${typeof a[3]}`); } let args = { name : '', description : '', prereqs : [], /* eslint-disable no-empty-function */ action : function action() {}, /* eslint-enable no-empty-function */ }; if ((a.length === 4) && (typeof a[3] === 'function') && (Array.isArray(a[2])) && (typeof a[1] === 'string') && (typeof a[0] === 'string')) { // all 4 arguments provided and of the correct type args.name = a[0]; args.description = a[1]; args.prereqs = a[2]; args.action = a[3]; } else if ((a.length === 3) && (typeof a[2] === 'function') && (Array.isArray(a[1])) && (typeof a[0] === 'string')) { // only 3 arguments types string, array, function args.name = a[0]; args.prereqs = a[1]; args.action = a[2]; } else if ((a.length === 3) && (typeof a[2] === 'function') && (typeof a[1] === 'string') && (typeof a[0] === 'string')) { // only 3 arguments types string string, function args.name = a[0]; args.description = a[1]; args.action = a[2]; } else if ((a.length === 2) && (typeof a[1] === 'function') && (typeof a[0] === 'string')) { // only 2 arguments - they must be - types string, function args.name = a[0]; args.action = a[1]; } else { args = undefined; } return args; }
javascript
function normalizeArguments() { const a = arguments; if (debug) debugLog(`normalizeArguments: arguments:${util.inspect(arguments)}`); if (debug) debugLog(`normalizeArguments: a0: ${a[0]} a1:${a[1]} a2:${a[2]} a3:${a[3]}`); if (debug) debugLog(`normalizeArguments: a0: ${typeof a[0]} a1:${typeof a[1]} a2:${typeof a[2]} a3:${typeof a[3]}`); if (debug) { debugLog(`normalizeArguments:` + ` a0: ${typeof a[0]} a1:${typeof a[1]} a2:${Array.isArray(a[2])} a3:${typeof a[3]}`); } let args = { name : '', description : '', prereqs : [], /* eslint-disable no-empty-function */ action : function action() {}, /* eslint-enable no-empty-function */ }; if ((a.length === 4) && (typeof a[3] === 'function') && (Array.isArray(a[2])) && (typeof a[1] === 'string') && (typeof a[0] === 'string')) { // all 4 arguments provided and of the correct type args.name = a[0]; args.description = a[1]; args.prereqs = a[2]; args.action = a[3]; } else if ((a.length === 3) && (typeof a[2] === 'function') && (Array.isArray(a[1])) && (typeof a[0] === 'string')) { // only 3 arguments types string, array, function args.name = a[0]; args.prereqs = a[1]; args.action = a[2]; } else if ((a.length === 3) && (typeof a[2] === 'function') && (typeof a[1] === 'string') && (typeof a[0] === 'string')) { // only 3 arguments types string string, function args.name = a[0]; args.description = a[1]; args.action = a[2]; } else if ((a.length === 2) && (typeof a[1] === 'function') && (typeof a[0] === 'string')) { // only 2 arguments - they must be - types string, function args.name = a[0]; args.action = a[1]; } else { args = undefined; } return args; }
[ "function", "normalizeArguments", "(", ")", "{", "const", "a", "=", "arguments", ";", "if", "(", "debug", ")", "debugLog", "(", "`", "${", "util", ".", "inspect", "(", "arguments", ")", "}", "`", ")", ";", "if", "(", "debug", ")", "debugLog", "(", "`", "${", "a", "[", "0", "]", "}", "${", "a", "[", "1", "]", "}", "${", "a", "[", "2", "]", "}", "${", "a", "[", "3", "]", "}", "`", ")", ";", "if", "(", "debug", ")", "debugLog", "(", "`", "${", "typeof", "a", "[", "0", "]", "}", "${", "typeof", "a", "[", "1", "]", "}", "${", "typeof", "a", "[", "2", "]", "}", "${", "typeof", "a", "[", "3", "]", "}", "`", ")", ";", "if", "(", "debug", ")", "{", "debugLog", "(", "`", "`", "+", "`", "${", "typeof", "a", "[", "0", "]", "}", "${", "typeof", "a", "[", "1", "]", "}", "${", "Array", ".", "isArray", "(", "a", "[", "2", "]", ")", "}", "${", "typeof", "a", "[", "3", "]", "}", "`", ")", ";", "}", "let", "args", "=", "{", "name", ":", "''", ",", "description", ":", "''", ",", "prereqs", ":", "[", "]", ",", "/* eslint-disable no-empty-function */", "action", ":", "function", "action", "(", ")", "{", "}", ",", "/* eslint-enable no-empty-function */", "}", ";", "if", "(", "(", "a", ".", "length", "===", "4", ")", "&&", "(", "typeof", "a", "[", "3", "]", "===", "'function'", ")", "&&", "(", "Array", ".", "isArray", "(", "a", "[", "2", "]", ")", ")", "&&", "(", "typeof", "a", "[", "1", "]", "===", "'string'", ")", "&&", "(", "typeof", "a", "[", "0", "]", "===", "'string'", ")", ")", "{", "// all 4 arguments provided and of the correct type", "args", ".", "name", "=", "a", "[", "0", "]", ";", "args", ".", "description", "=", "a", "[", "1", "]", ";", "args", ".", "prereqs", "=", "a", "[", "2", "]", ";", "args", ".", "action", "=", "a", "[", "3", "]", ";", "}", "else", "if", "(", "(", "a", ".", "length", "===", "3", ")", "&&", "(", "typeof", "a", "[", "2", "]", "===", "'function'", ")", "&&", "(", "Array", ".", "isArray", "(", "a", "[", "1", "]", ")", ")", "&&", "(", "typeof", "a", "[", "0", "]", "===", "'string'", ")", ")", "{", "// only 3 arguments types string, array, function", "args", ".", "name", "=", "a", "[", "0", "]", ";", "args", ".", "prereqs", "=", "a", "[", "1", "]", ";", "args", ".", "action", "=", "a", "[", "2", "]", ";", "}", "else", "if", "(", "(", "a", ".", "length", "===", "3", ")", "&&", "(", "typeof", "a", "[", "2", "]", "===", "'function'", ")", "&&", "(", "typeof", "a", "[", "1", "]", "===", "'string'", ")", "&&", "(", "typeof", "a", "[", "0", "]", "===", "'string'", ")", ")", "{", "// only 3 arguments types string string, function", "args", ".", "name", "=", "a", "[", "0", "]", ";", "args", ".", "description", "=", "a", "[", "1", "]", ";", "args", ".", "action", "=", "a", "[", "2", "]", ";", "}", "else", "if", "(", "(", "a", ".", "length", "===", "2", ")", "&&", "(", "typeof", "a", "[", "1", "]", "===", "'function'", ")", "&&", "(", "typeof", "a", "[", "0", "]", "===", "'string'", ")", ")", "{", "// only 2 arguments - they must be - types string, function", "args", ".", "name", "=", "a", "[", "0", "]", ";", "args", ".", "action", "=", "a", "[", "1", "]", ";", "}", "else", "{", "args", "=", "undefined", ";", "}", "return", "args", ";", "}" ]
Normalize the arguments passed into the task definition function. Inside a yakefile tasks are defined with a call like ... jake.task('name', 'description', ['prerequisite1', ...], function action(){}) The name and action are manditory while the other two - description and [prerequisistes] are optional. This function goes through the process of determining which form was given and returns an object literal with all 4 values provided. @param {string} name Manditory @param {string} description Optional @param {array of strings} prerequisistes Optional @param {function} action Manditory @return {object} with keys name, description, prerequisites, action
[ "Normalize", "the", "arguments", "passed", "into", "the", "task", "definition", "function", ".", "Inside", "a", "yakefile", "tasks", "are", "defined", "with", "a", "call", "like", "..." ]
172b02e29303fb718bac88bbda9b85749c57169c
https://github.com/robertblackwell/yake/blob/172b02e29303fb718bac88bbda9b85749c57169c/src/yake/tasks.js#L233-L302
55,578
robertblackwell/yake
src/yake/tasks.js
loadPreloadedTasks
function loadPreloadedTasks(taskCollection) { const preTasks = [ { name : 'help', description : 'list all tasks', prerequisites : [], action : function actionHelp() { /* eslint-disable no-console */ console.log('this is the help task running '); /* eslint-enable no-console */ }, }, ]; const collection = loadTasksFromArray(preTasks, taskCollection); return collection; }
javascript
function loadPreloadedTasks(taskCollection) { const preTasks = [ { name : 'help', description : 'list all tasks', prerequisites : [], action : function actionHelp() { /* eslint-disable no-console */ console.log('this is the help task running '); /* eslint-enable no-console */ }, }, ]; const collection = loadTasksFromArray(preTasks, taskCollection); return collection; }
[ "function", "loadPreloadedTasks", "(", "taskCollection", ")", "{", "const", "preTasks", "=", "[", "{", "name", ":", "'help'", ",", "description", ":", "'list all tasks'", ",", "prerequisites", ":", "[", "]", ",", "action", ":", "function", "actionHelp", "(", ")", "{", "/* eslint-disable no-console */", "console", ".", "log", "(", "'this is the help task running '", ")", ";", "/* eslint-enable no-console */", "}", ",", "}", ",", "]", ";", "const", "collection", "=", "loadTasksFromArray", "(", "preTasks", ",", "taskCollection", ")", ";", "return", "collection", ";", "}" ]
Yake provides for a set of standard tasks to be preloaded. This function performs that process. @param {TaskCollection} taskCollection into which the tasks are to be loaded @return {TaskCollection} the same one that was passed in but updated
[ "Yake", "provides", "for", "a", "set", "of", "standard", "tasks", "to", "be", "preloaded", ".", "This", "function", "performs", "that", "process", "." ]
172b02e29303fb718bac88bbda9b85749c57169c
https://github.com/robertblackwell/yake/blob/172b02e29303fb718bac88bbda9b85749c57169c/src/yake/tasks.js#L332-L350
55,579
robertblackwell/yake
src/yake/tasks.js
requireTasks
function requireTasks(yakefile, taskCollection) { const debug = false; globals.globalTaskCollection = taskCollection; if (debug) debugLog(`loadTasks: called ${yakefile}`); /* eslint-disable global-require */ require(yakefile); /* eslint-disable global-require */ const newTaskCollection = globals.globalTaskCollection; return newTaskCollection; // no copy - untidy functional programming }
javascript
function requireTasks(yakefile, taskCollection) { const debug = false; globals.globalTaskCollection = taskCollection; if (debug) debugLog(`loadTasks: called ${yakefile}`); /* eslint-disable global-require */ require(yakefile); /* eslint-disable global-require */ const newTaskCollection = globals.globalTaskCollection; return newTaskCollection; // no copy - untidy functional programming }
[ "function", "requireTasks", "(", "yakefile", ",", "taskCollection", ")", "{", "const", "debug", "=", "false", ";", "globals", ".", "globalTaskCollection", "=", "taskCollection", ";", "if", "(", "debug", ")", "debugLog", "(", "`", "${", "yakefile", "}", "`", ")", ";", "/* eslint-disable global-require */", "require", "(", "yakefile", ")", ";", "/* eslint-disable global-require */", "const", "newTaskCollection", "=", "globals", ".", "globalTaskCollection", ";", "return", "newTaskCollection", ";", "// no copy - untidy functional programming", "}" ]
Loads tasks from a yakefile into taskCollection and returns the updated taskCollection. It does this by a dynamic 'require' @param {string} yakefile - full path to yakefile - assume it exists @parame {TaskCollection} taskCollection - collection into which tasks will be placed @return {TaskCollection} update taskCollection
[ "Loads", "tasks", "from", "a", "yakefile", "into", "taskCollection", "and", "returns", "the", "updated", "taskCollection", ".", "It", "does", "this", "by", "a", "dynamic", "require" ]
172b02e29303fb718bac88bbda9b85749c57169c
https://github.com/robertblackwell/yake/blob/172b02e29303fb718bac88bbda9b85749c57169c/src/yake/tasks.js#L361-L375
55,580
BarzinJS/string-extensions
lib/parsers/bool.js
function (item, arr, options) { debug('Match'); debug('Item: %s', item); debug('Array: %s', arr); debug('Options: %o', options); // normal item match (case-sensitive) let found = arr.indexOf(item) > -1; // case insensitive test if only item not found in case-sensitive mode if (options.caseInsensitive || (options.caseInsensitive && !found)) { debug('Checking case-insensitive too...'); arr.map(target => { if (target.toLowerCase() === item.toLowerCase()) { found = true; } }); } debug('Found: %s', found); return found; }
javascript
function (item, arr, options) { debug('Match'); debug('Item: %s', item); debug('Array: %s', arr); debug('Options: %o', options); // normal item match (case-sensitive) let found = arr.indexOf(item) > -1; // case insensitive test if only item not found in case-sensitive mode if (options.caseInsensitive || (options.caseInsensitive && !found)) { debug('Checking case-insensitive too...'); arr.map(target => { if (target.toLowerCase() === item.toLowerCase()) { found = true; } }); } debug('Found: %s', found); return found; }
[ "function", "(", "item", ",", "arr", ",", "options", ")", "{", "debug", "(", "'Match'", ")", ";", "debug", "(", "'Item: %s'", ",", "item", ")", ";", "debug", "(", "'Array: %s'", ",", "arr", ")", ";", "debug", "(", "'Options: %o'", ",", "options", ")", ";", "// normal item match (case-sensitive)", "let", "found", "=", "arr", ".", "indexOf", "(", "item", ")", ">", "-", "1", ";", "// case insensitive test if only item not found in case-sensitive mode", "if", "(", "options", ".", "caseInsensitive", "||", "(", "options", ".", "caseInsensitive", "&&", "!", "found", ")", ")", "{", "debug", "(", "'Checking case-insensitive too...'", ")", ";", "arr", ".", "map", "(", "target", "=>", "{", "if", "(", "target", ".", "toLowerCase", "(", ")", "===", "item", ".", "toLowerCase", "(", ")", ")", "{", "found", "=", "true", ";", "}", "}", ")", ";", "}", "debug", "(", "'Found: %s'", ",", "found", ")", ";", "return", "found", ";", "}" ]
Match item in an array @param {string} item Item to search for @param {array<string>} arr Array of string items @param {any} options Search/Match options @returns {bool} Match result
[ "Match", "item", "in", "an", "array" ]
448db8fa460cb10859e927fadde3bde0eb8fb054
https://github.com/BarzinJS/string-extensions/blob/448db8fa460cb10859e927fadde3bde0eb8fb054/lib/parsers/bool.js#L21-L48
55,581
lorenwest/monitor-min
lib/Sync.js
function(changedModel, options) { // Don't update unless the model is different var newModel = model.syncMonitor.get('model'); if (_.isEqual(JSON.parse(JSON.stringify(model)), JSON.parse(JSON.stringify(newModel)))) { log.info('monitorListener.noChanges', t.className, newModel); return; } // Disconnect if the model was deleted or the ID isn't the same var isDeleted = (_.size(newModel) === 0); if (isDeleted || newModel.id !== modelId) { log.info('modelListener.deleted', t.className, newModel); disconnectListeners(); } // Forward changes to the model (including server-side delete) var newOpts = {isSyncChanging:true}; if (isDeleted) { log.info('modelListener.deleting', t.className, newModel); model.clear(newOpts); } else { // Make sure the model is set to exactly the new contents (vs. override) log.info('modelListener.setting', t.className, newModel); model.clear({silent:true}); model.set(newModel, newOpts); } }
javascript
function(changedModel, options) { // Don't update unless the model is different var newModel = model.syncMonitor.get('model'); if (_.isEqual(JSON.parse(JSON.stringify(model)), JSON.parse(JSON.stringify(newModel)))) { log.info('monitorListener.noChanges', t.className, newModel); return; } // Disconnect if the model was deleted or the ID isn't the same var isDeleted = (_.size(newModel) === 0); if (isDeleted || newModel.id !== modelId) { log.info('modelListener.deleted', t.className, newModel); disconnectListeners(); } // Forward changes to the model (including server-side delete) var newOpts = {isSyncChanging:true}; if (isDeleted) { log.info('modelListener.deleting', t.className, newModel); model.clear(newOpts); } else { // Make sure the model is set to exactly the new contents (vs. override) log.info('modelListener.setting', t.className, newModel); model.clear({silent:true}); model.set(newModel, newOpts); } }
[ "function", "(", "changedModel", ",", "options", ")", "{", "// Don't update unless the model is different", "var", "newModel", "=", "model", ".", "syncMonitor", ".", "get", "(", "'model'", ")", ";", "if", "(", "_", ".", "isEqual", "(", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "model", ")", ")", ",", "JSON", ".", "parse", "(", "JSON", ".", "stringify", "(", "newModel", ")", ")", ")", ")", "{", "log", ".", "info", "(", "'monitorListener.noChanges'", ",", "t", ".", "className", ",", "newModel", ")", ";", "return", ";", "}", "// Disconnect if the model was deleted or the ID isn't the same", "var", "isDeleted", "=", "(", "_", ".", "size", "(", "newModel", ")", "===", "0", ")", ";", "if", "(", "isDeleted", "||", "newModel", ".", "id", "!==", "modelId", ")", "{", "log", ".", "info", "(", "'modelListener.deleted'", ",", "t", ".", "className", ",", "newModel", ")", ";", "disconnectListeners", "(", ")", ";", "}", "// Forward changes to the model (including server-side delete)", "var", "newOpts", "=", "{", "isSyncChanging", ":", "true", "}", ";", "if", "(", "isDeleted", ")", "{", "log", ".", "info", "(", "'modelListener.deleting'", ",", "t", ".", "className", ",", "newModel", ")", ";", "model", ".", "clear", "(", "newOpts", ")", ";", "}", "else", "{", "// Make sure the model is set to exactly the new contents (vs. override)", "log", ".", "info", "(", "'modelListener.setting'", ",", "t", ".", "className", ",", "newModel", ")", ";", "model", ".", "clear", "(", "{", "silent", ":", "true", "}", ")", ";", "model", ".", "set", "(", "newModel", ",", "newOpts", ")", ";", "}", "}" ]
Server-side listener - for updating server changes into the model
[ "Server", "-", "side", "listener", "-", "for", "updating", "server", "changes", "into", "the", "model" ]
859ba34a121498dc1cb98577ae24abd825407fca
https://github.com/lorenwest/monitor-min/blob/859ba34a121498dc1cb98577ae24abd825407fca/lib/Sync.js#L299-L326
55,582
imlucas/node-stor
stores/indexeddb.js
db
function db(op, fn){ if(!indexedDB){ return fn(new Error('store `indexeddb` not supported by this browser')); } if(typeof op === 'function'){ fn = op; op = 'readwrite'; } if(source !== null){ return fn(null, source.transaction(module.exports.prefix, op).objectStore(module.exports.prefix)); } var req = indexedDB.open(module.exports.prefix, 1); req.onerror = function(e){ fn(e); }; req.onupgradeneeded = function(){ // First time setup: create an empty object store req.result.createObjectStore(module.exports.prefix); }; req.onsuccess = function() { source = req.result; db(op, fn); }; }
javascript
function db(op, fn){ if(!indexedDB){ return fn(new Error('store `indexeddb` not supported by this browser')); } if(typeof op === 'function'){ fn = op; op = 'readwrite'; } if(source !== null){ return fn(null, source.transaction(module.exports.prefix, op).objectStore(module.exports.prefix)); } var req = indexedDB.open(module.exports.prefix, 1); req.onerror = function(e){ fn(e); }; req.onupgradeneeded = function(){ // First time setup: create an empty object store req.result.createObjectStore(module.exports.prefix); }; req.onsuccess = function() { source = req.result; db(op, fn); }; }
[ "function", "db", "(", "op", ",", "fn", ")", "{", "if", "(", "!", "indexedDB", ")", "{", "return", "fn", "(", "new", "Error", "(", "'store `indexeddb` not supported by this browser'", ")", ")", ";", "}", "if", "(", "typeof", "op", "===", "'function'", ")", "{", "fn", "=", "op", ";", "op", "=", "'readwrite'", ";", "}", "if", "(", "source", "!==", "null", ")", "{", "return", "fn", "(", "null", ",", "source", ".", "transaction", "(", "module", ".", "exports", ".", "prefix", ",", "op", ")", ".", "objectStore", "(", "module", ".", "exports", ".", "prefix", ")", ")", ";", "}", "var", "req", "=", "indexedDB", ".", "open", "(", "module", ".", "exports", ".", "prefix", ",", "1", ")", ";", "req", ".", "onerror", "=", "function", "(", "e", ")", "{", "fn", "(", "e", ")", ";", "}", ";", "req", ".", "onupgradeneeded", "=", "function", "(", ")", "{", "// First time setup: create an empty object store", "req", ".", "result", ".", "createObjectStore", "(", "module", ".", "exports", ".", "prefix", ")", ";", "}", ";", "req", ".", "onsuccess", "=", "function", "(", ")", "{", "source", "=", "req", ".", "result", ";", "db", "(", "op", ",", "fn", ")", ";", "}", ";", "}" ]
Wrapper function that handles creating or acquiring the object store if it hasn't been already.
[ "Wrapper", "function", "that", "handles", "creating", "or", "acquiring", "the", "object", "store", "if", "it", "hasn", "t", "been", "already", "." ]
6b74af52bf160873658bc3570db716d44c33f335
https://github.com/imlucas/node-stor/blob/6b74af52bf160873658bc3570db716d44c33f335/stores/indexeddb.js#L8-L32
55,583
YahooArchive/mojito-cli-jslint
lib/reporter.js
main
function main(env, print, cb) { var dir = env.opts.directory || path.resolve(env.cwd, 'artifacts/jslint'), lines = [], count = 0, total = 0; function perOffense(o) { var evidence = o.evidence.trim(); count += 1; total += 1; lines.push(fmt(' #%d %d,%d: %s', count, o.line, o.col, o.msg)); if (evidence) { lines.push(' ' + evidence); } } /** * invoked by lintifier.doneYet() * @param {object|string|null} offenses * @param {string} msg "Done. no lint found..." */ function reporter(offenses, msg) { var files, summary, writeErr; if (('string' === typeof offenses) || offenses instanceof Error) { cb(offenses); return; } function perFile(pathname) { count = 0; lines.push(pathname); offenses[pathname].forEach(perOffense); lines.push(''); // blank line } if (offenses) { // accumulate report in lines array files = Object.keys(offenses); files.forEach(perFile); summary = getSummary(total, files.length); if (env.opts.print) { lines.unshift('JSLint Report', ''); print(lines.join(EOL)); } else { writeErr = writeHtmlFile(dir, getHtml(lines, summary)); } // has errors cb(writeErr || summary); } else { // is lint free cb(null, msg); } } return reporter; }
javascript
function main(env, print, cb) { var dir = env.opts.directory || path.resolve(env.cwd, 'artifacts/jslint'), lines = [], count = 0, total = 0; function perOffense(o) { var evidence = o.evidence.trim(); count += 1; total += 1; lines.push(fmt(' #%d %d,%d: %s', count, o.line, o.col, o.msg)); if (evidence) { lines.push(' ' + evidence); } } /** * invoked by lintifier.doneYet() * @param {object|string|null} offenses * @param {string} msg "Done. no lint found..." */ function reporter(offenses, msg) { var files, summary, writeErr; if (('string' === typeof offenses) || offenses instanceof Error) { cb(offenses); return; } function perFile(pathname) { count = 0; lines.push(pathname); offenses[pathname].forEach(perOffense); lines.push(''); // blank line } if (offenses) { // accumulate report in lines array files = Object.keys(offenses); files.forEach(perFile); summary = getSummary(total, files.length); if (env.opts.print) { lines.unshift('JSLint Report', ''); print(lines.join(EOL)); } else { writeErr = writeHtmlFile(dir, getHtml(lines, summary)); } // has errors cb(writeErr || summary); } else { // is lint free cb(null, msg); } } return reporter; }
[ "function", "main", "(", "env", ",", "print", ",", "cb", ")", "{", "var", "dir", "=", "env", ".", "opts", ".", "directory", "||", "path", ".", "resolve", "(", "env", ".", "cwd", ",", "'artifacts/jslint'", ")", ",", "lines", "=", "[", "]", ",", "count", "=", "0", ",", "total", "=", "0", ";", "function", "perOffense", "(", "o", ")", "{", "var", "evidence", "=", "o", ".", "evidence", ".", "trim", "(", ")", ";", "count", "+=", "1", ";", "total", "+=", "1", ";", "lines", ".", "push", "(", "fmt", "(", "' #%d %d,%d: %s'", ",", "count", ",", "o", ".", "line", ",", "o", ".", "col", ",", "o", ".", "msg", ")", ")", ";", "if", "(", "evidence", ")", "{", "lines", ".", "push", "(", "' '", "+", "evidence", ")", ";", "}", "}", "/**\n * invoked by lintifier.doneYet()\n * @param {object|string|null} offenses\n * @param {string} msg \"Done. no lint found...\"\n */", "function", "reporter", "(", "offenses", ",", "msg", ")", "{", "var", "files", ",", "summary", ",", "writeErr", ";", "if", "(", "(", "'string'", "===", "typeof", "offenses", ")", "||", "offenses", "instanceof", "Error", ")", "{", "cb", "(", "offenses", ")", ";", "return", ";", "}", "function", "perFile", "(", "pathname", ")", "{", "count", "=", "0", ";", "lines", ".", "push", "(", "pathname", ")", ";", "offenses", "[", "pathname", "]", ".", "forEach", "(", "perOffense", ")", ";", "lines", ".", "push", "(", "''", ")", ";", "// blank line", "}", "if", "(", "offenses", ")", "{", "// accumulate report in lines array", "files", "=", "Object", ".", "keys", "(", "offenses", ")", ";", "files", ".", "forEach", "(", "perFile", ")", ";", "summary", "=", "getSummary", "(", "total", ",", "files", ".", "length", ")", ";", "if", "(", "env", ".", "opts", ".", "print", ")", "{", "lines", ".", "unshift", "(", "'JSLint Report'", ",", "''", ")", ";", "print", "(", "lines", ".", "join", "(", "EOL", ")", ")", ";", "}", "else", "{", "writeErr", "=", "writeHtmlFile", "(", "dir", ",", "getHtml", "(", "lines", ",", "summary", ")", ")", ";", "}", "// has errors", "cb", "(", "writeErr", "||", "summary", ")", ";", "}", "else", "{", "// is lint free", "cb", "(", "null", ",", "msg", ")", ";", "}", "}", "return", "reporter", ";", "}" ]
return a function that is responsible for outputing the lint results, to a file or stdout, and then invoking the final callback.
[ "return", "a", "function", "that", "is", "responsible", "for", "outputing", "the", "lint", "results", "to", "a", "file", "or", "stdout", "and", "then", "invoking", "the", "final", "callback", "." ]
cc6f90352534689a9e8c524c4cce825215bb5186
https://github.com/YahooArchive/mojito-cli-jslint/blob/cc6f90352534689a9e8c524c4cce825215bb5186/lib/reporter.js#L57-L121
55,584
commenthol/streamss-readonly
index.js
readonly
function readonly (stream) { var rs = stream._readableState || {} var opts = {} if (typeof stream.read !== 'function') { throw new Error('not a readable stream') } ['highWaterMark', 'encoding', 'objectMode'].forEach(function (p) { opts[p] = rs[p] }) var readOnly = new Readable(opts) var waiting = false stream.on('readable', function () { if (waiting) { waiting = false readOnly._read() } }) readOnly._read = function (size) { var buf while ((buf = stream.read(size)) !== null) { if (!readOnly.push(buf)) { return } } waiting = true } stream.once('end', function () { readOnly.push(null) }) stream.on('close', function () { readOnly.emit('close') }) stream.on('error', function (err) { readOnly.emit('error', err) }) return readOnly }
javascript
function readonly (stream) { var rs = stream._readableState || {} var opts = {} if (typeof stream.read !== 'function') { throw new Error('not a readable stream') } ['highWaterMark', 'encoding', 'objectMode'].forEach(function (p) { opts[p] = rs[p] }) var readOnly = new Readable(opts) var waiting = false stream.on('readable', function () { if (waiting) { waiting = false readOnly._read() } }) readOnly._read = function (size) { var buf while ((buf = stream.read(size)) !== null) { if (!readOnly.push(buf)) { return } } waiting = true } stream.once('end', function () { readOnly.push(null) }) stream.on('close', function () { readOnly.emit('close') }) stream.on('error', function (err) { readOnly.emit('error', err) }) return readOnly }
[ "function", "readonly", "(", "stream", ")", "{", "var", "rs", "=", "stream", ".", "_readableState", "||", "{", "}", "var", "opts", "=", "{", "}", "if", "(", "typeof", "stream", ".", "read", "!==", "'function'", ")", "{", "throw", "new", "Error", "(", "'not a readable stream'", ")", "}", "[", "'highWaterMark'", ",", "'encoding'", ",", "'objectMode'", "]", ".", "forEach", "(", "function", "(", "p", ")", "{", "opts", "[", "p", "]", "=", "rs", "[", "p", "]", "}", ")", "var", "readOnly", "=", "new", "Readable", "(", "opts", ")", "var", "waiting", "=", "false", "stream", ".", "on", "(", "'readable'", ",", "function", "(", ")", "{", "if", "(", "waiting", ")", "{", "waiting", "=", "false", "readOnly", ".", "_read", "(", ")", "}", "}", ")", "readOnly", ".", "_read", "=", "function", "(", "size", ")", "{", "var", "buf", "while", "(", "(", "buf", "=", "stream", ".", "read", "(", "size", ")", ")", "!==", "null", ")", "{", "if", "(", "!", "readOnly", ".", "push", "(", "buf", ")", ")", "{", "return", "}", "}", "waiting", "=", "true", "}", "stream", ".", "once", "(", "'end'", ",", "function", "(", ")", "{", "readOnly", ".", "push", "(", "null", ")", "}", ")", "stream", ".", "on", "(", "'close'", ",", "function", "(", ")", "{", "readOnly", ".", "emit", "(", "'close'", ")", "}", ")", "stream", ".", "on", "(", "'error'", ",", "function", "(", "err", ")", "{", "readOnly", ".", "emit", "(", "'error'", ",", "err", ")", "}", ")", "return", "readOnly", "}" ]
Converts any stream into a read-only stream @param {Readable|Transform|Duplex} stream - A stream which shall behave as a Readable only stream. @throws {Error} "not a readable stream" - if stream does not implement a Readable component this error is thrown @return {Readable} - A read-only readable stream
[ "Converts", "any", "stream", "into", "a", "read", "-", "only", "stream" ]
cdeb9a41821a4837d94bc8bda8667d86dc74d273
https://github.com/commenthol/streamss-readonly/blob/cdeb9a41821a4837d94bc8bda8667d86dc74d273/index.js#L19-L62
55,585
fczbkk/event-simulator
lib/index.js
setupEvent
function setupEvent(event_type) { var event = void 0; if (exists(document.createEvent)) { // modern browsers event = document.createEvent('HTMLEvents'); event.initEvent(event_type, true, true); } else if (exists(document.createEventObject)) { // IE9- event = document.createEventObject(); event.eventType = event_type; event.eventName = event_type; } return event; }
javascript
function setupEvent(event_type) { var event = void 0; if (exists(document.createEvent)) { // modern browsers event = document.createEvent('HTMLEvents'); event.initEvent(event_type, true, true); } else if (exists(document.createEventObject)) { // IE9- event = document.createEventObject(); event.eventType = event_type; event.eventName = event_type; } return event; }
[ "function", "setupEvent", "(", "event_type", ")", "{", "var", "event", "=", "void", "0", ";", "if", "(", "exists", "(", "document", ".", "createEvent", ")", ")", "{", "// modern browsers", "event", "=", "document", ".", "createEvent", "(", "'HTMLEvents'", ")", ";", "event", ".", "initEvent", "(", "event_type", ",", "true", ",", "true", ")", ";", "}", "else", "if", "(", "exists", "(", "document", ".", "createEventObject", ")", ")", "{", "// IE9-", "event", "=", "document", ".", "createEventObject", "(", ")", ";", "event", ".", "eventType", "=", "event_type", ";", "event", ".", "eventName", "=", "event_type", ";", "}", "return", "event", ";", "}" ]
Cross-browser bridge that creates event object @param {string} event_type Event identifier @returns {Event} Event object @private
[ "Cross", "-", "browser", "bridge", "that", "creates", "event", "object" ]
ad7f7caff8145226c5b19faeac680772e5040001
https://github.com/fczbkk/event-simulator/blob/ad7f7caff8145226c5b19faeac680772e5040001/lib/index.js#L27-L41
55,586
fczbkk/event-simulator
lib/index.js
fireEvent
function fireEvent(target_object, event, event_type) { var on_event_type = 'on' + event_type; if (exists(target_object.dispatchEvent)) { // modern browsers target_object.dispatchEvent(event); } else if (exists(target_object.fireEvent)) { // IE9- target_object.fireEvent(on_event_type, event); } else if (exists(target_object[event_type])) { target_object[event_type](); } else if (exists(target_object[on_event_type])) { target_object[on_event_type](); } }
javascript
function fireEvent(target_object, event, event_type) { var on_event_type = 'on' + event_type; if (exists(target_object.dispatchEvent)) { // modern browsers target_object.dispatchEvent(event); } else if (exists(target_object.fireEvent)) { // IE9- target_object.fireEvent(on_event_type, event); } else if (exists(target_object[event_type])) { target_object[event_type](); } else if (exists(target_object[on_event_type])) { target_object[on_event_type](); } }
[ "function", "fireEvent", "(", "target_object", ",", "event", ",", "event_type", ")", "{", "var", "on_event_type", "=", "'on'", "+", "event_type", ";", "if", "(", "exists", "(", "target_object", ".", "dispatchEvent", ")", ")", "{", "// modern browsers", "target_object", ".", "dispatchEvent", "(", "event", ")", ";", "}", "else", "if", "(", "exists", "(", "target_object", ".", "fireEvent", ")", ")", "{", "// IE9-", "target_object", ".", "fireEvent", "(", "on_event_type", ",", "event", ")", ";", "}", "else", "if", "(", "exists", "(", "target_object", "[", "event_type", "]", ")", ")", "{", "target_object", "[", "event_type", "]", "(", ")", ";", "}", "else", "if", "(", "exists", "(", "target_object", "[", "on_event_type", "]", ")", ")", "{", "target_object", "[", "on_event_type", "]", "(", ")", ";", "}", "}" ]
Cross-browser bridge that fires an event object on target object @param {Object} target_object Any object that can fire an event @param {Event} event Event object @param {string} event_type Event identifier @private
[ "Cross", "-", "browser", "bridge", "that", "fires", "an", "event", "object", "on", "target", "object" ]
ad7f7caff8145226c5b19faeac680772e5040001
https://github.com/fczbkk/event-simulator/blob/ad7f7caff8145226c5b19faeac680772e5040001/lib/index.js#L50-L64
55,587
fczbkk/event-simulator
lib/index.js
simulateEvent
function simulateEvent(target_object, event_type) { if (!exists(target_object)) { throw new TypeError('simulateEvent: target object must be defined'); } if (typeof event_type !== 'string') { throw new TypeError('simulateEvent: event type must be a string'); } var event = setupEvent(event_type); fireEvent(target_object, event, event_type); }
javascript
function simulateEvent(target_object, event_type) { if (!exists(target_object)) { throw new TypeError('simulateEvent: target object must be defined'); } if (typeof event_type !== 'string') { throw new TypeError('simulateEvent: event type must be a string'); } var event = setupEvent(event_type); fireEvent(target_object, event, event_type); }
[ "function", "simulateEvent", "(", "target_object", ",", "event_type", ")", "{", "if", "(", "!", "exists", "(", "target_object", ")", ")", "{", "throw", "new", "TypeError", "(", "'simulateEvent: target object must be defined'", ")", ";", "}", "if", "(", "typeof", "event_type", "!==", "'string'", ")", "{", "throw", "new", "TypeError", "(", "'simulateEvent: event type must be a string'", ")", ";", "}", "var", "event", "=", "setupEvent", "(", "event_type", ")", ";", "fireEvent", "(", "target_object", ",", "event", ",", "event_type", ")", ";", "}" ]
Fires an event of provided type on provided object @param {Object} target_object Any object that can fire an event @param {string} event_type Event identifier @example simulateEvent(window, 'scroll');
[ "Fires", "an", "event", "of", "provided", "type", "on", "provided", "object" ]
ad7f7caff8145226c5b19faeac680772e5040001
https://github.com/fczbkk/event-simulator/blob/ad7f7caff8145226c5b19faeac680772e5040001/lib/index.js#L73-L84
55,588
fczbkk/event-simulator
lib/index.js
setupMouseEvent
function setupMouseEvent(properties) { var event = document.createEvent('MouseEvents'); event.initMouseEvent(properties.type, properties.canBubble, properties.cancelable, properties.view, properties.detail, properties.screenX, properties.screenY, properties.clientX, properties.clientY, properties.ctrlKey, properties.altKey, properties.shiftKey, properties.metaKey, properties.button, properties.relatedTarget); return event; }
javascript
function setupMouseEvent(properties) { var event = document.createEvent('MouseEvents'); event.initMouseEvent(properties.type, properties.canBubble, properties.cancelable, properties.view, properties.detail, properties.screenX, properties.screenY, properties.clientX, properties.clientY, properties.ctrlKey, properties.altKey, properties.shiftKey, properties.metaKey, properties.button, properties.relatedTarget); return event; }
[ "function", "setupMouseEvent", "(", "properties", ")", "{", "var", "event", "=", "document", ".", "createEvent", "(", "'MouseEvents'", ")", ";", "event", ".", "initMouseEvent", "(", "properties", ".", "type", ",", "properties", ".", "canBubble", ",", "properties", ".", "cancelable", ",", "properties", ".", "view", ",", "properties", ".", "detail", ",", "properties", ".", "screenX", ",", "properties", ".", "screenY", ",", "properties", ".", "clientX", ",", "properties", ".", "clientY", ",", "properties", ".", "ctrlKey", ",", "properties", ".", "altKey", ",", "properties", ".", "shiftKey", ",", "properties", ".", "metaKey", ",", "properties", ".", "button", ",", "properties", ".", "relatedTarget", ")", ";", "return", "event", ";", "}" ]
Constructs mouse event object @param {Object} properties @returns {Event} @private
[ "Constructs", "mouse", "event", "object" ]
ad7f7caff8145226c5b19faeac680772e5040001
https://github.com/fczbkk/event-simulator/blob/ad7f7caff8145226c5b19faeac680772e5040001/lib/index.js#L136-L140
55,589
fczbkk/event-simulator
lib/index.js
simulateMouseEvent
function simulateMouseEvent(target_object) { var custom_properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var properties = sanitizeProperties(custom_properties); var event = setupMouseEvent(properties); target_object.dispatchEvent(event); }
javascript
function simulateMouseEvent(target_object) { var custom_properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var properties = sanitizeProperties(custom_properties); var event = setupMouseEvent(properties); target_object.dispatchEvent(event); }
[ "function", "simulateMouseEvent", "(", "target_object", ")", "{", "var", "custom_properties", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "{", "}", ";", "var", "properties", "=", "sanitizeProperties", "(", "custom_properties", ")", ";", "var", "event", "=", "setupMouseEvent", "(", "properties", ")", ";", "target_object", ".", "dispatchEvent", "(", "event", ")", ";", "}" ]
Fires a mouse event on provided object @param {Object} target_object @param {Object} custom_properties @example simulateMouseEvent(window, {type: 'mousedown', button: 'right'});
[ "Fires", "a", "mouse", "event", "on", "provided", "object" ]
ad7f7caff8145226c5b19faeac680772e5040001
https://github.com/fczbkk/event-simulator/blob/ad7f7caff8145226c5b19faeac680772e5040001/lib/index.js#L149-L155
55,590
TJkrusinski/feedtitles
index.js
onText
function onText (text) { if (!current || !text) return; titles.push(text); self.emit('title', text); }
javascript
function onText (text) { if (!current || !text) return; titles.push(text); self.emit('title', text); }
[ "function", "onText", "(", "text", ")", "{", "if", "(", "!", "current", "||", "!", "text", ")", "return", ";", "titles", ".", "push", "(", "text", ")", ";", "self", ".", "emit", "(", "'title'", ",", "text", ")", ";", "}" ]
If we are in a title node then push on the text @param {String} text
[ "If", "we", "are", "in", "a", "title", "node", "then", "push", "on", "the", "text" ]
f398f4515607f03af05e4e3e340f9fdfd1aec195
https://github.com/TJkrusinski/feedtitles/blob/f398f4515607f03af05e4e3e340f9fdfd1aec195/index.js#L50-L54
55,591
pmh/espresso
lib/ometa/ometa/base.js
extend
function extend(obj) { for(var i=1,len=arguments.length;i<len;i++) { var props = arguments[i]; for(var p in props) { if(props.hasOwnProperty(p)) { obj[p] = props[p]; } } } return obj; }
javascript
function extend(obj) { for(var i=1,len=arguments.length;i<len;i++) { var props = arguments[i]; for(var p in props) { if(props.hasOwnProperty(p)) { obj[p] = props[p]; } } } return obj; }
[ "function", "extend", "(", "obj", ")", "{", "for", "(", "var", "i", "=", "1", ",", "len", "=", "arguments", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "var", "props", "=", "arguments", "[", "i", "]", ";", "for", "(", "var", "p", "in", "props", ")", "{", "if", "(", "props", ".", "hasOwnProperty", "(", "p", ")", ")", "{", "obj", "[", "p", "]", "=", "props", "[", "p", "]", ";", "}", "}", "}", "return", "obj", ";", "}" ]
Local helper methods
[ "Local", "helper", "methods" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L47-L58
55,592
pmh/espresso
lib/ometa/ometa/base.js
inherit
function inherit(x, props) { var r = Object.create(x); return extend(r, props); }
javascript
function inherit(x, props) { var r = Object.create(x); return extend(r, props); }
[ "function", "inherit", "(", "x", ",", "props", ")", "{", "var", "r", "=", "Object", ".", "create", "(", "x", ")", ";", "return", "extend", "(", "r", ",", "props", ")", ";", "}" ]
A simplified Version of Object.create
[ "A", "simplified", "Version", "of", "Object", ".", "create" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L61-L64
55,593
pmh/espresso
lib/ometa/ometa/base.js
function(grammar, ruleName) { grammar = this._apply("anything"); ruleName = this._apply("anything"); var foreign = inherit(grammar, { bt: this.bt.borrow() }); var ans = foreign._apply(ruleName); this.bt.take_back(); // return the borrowed input stream return ans; }
javascript
function(grammar, ruleName) { grammar = this._apply("anything"); ruleName = this._apply("anything"); var foreign = inherit(grammar, { bt: this.bt.borrow() }); var ans = foreign._apply(ruleName); this.bt.take_back(); // return the borrowed input stream return ans; }
[ "function", "(", "grammar", ",", "ruleName", ")", "{", "grammar", "=", "this", ".", "_apply", "(", "\"anything\"", ")", ";", "ruleName", "=", "this", ".", "_apply", "(", "\"anything\"", ")", ";", "var", "foreign", "=", "inherit", "(", "grammar", ",", "{", "bt", ":", "this", ".", "bt", ".", "borrow", "(", ")", "}", ")", ";", "var", "ans", "=", "foreign", ".", "_apply", "(", "ruleName", ")", ";", "this", ".", "bt", ".", "take_back", "(", ")", ";", "// return the borrowed input stream", "return", "ans", ";", "}" ]
otherGrammar.rule
[ "otherGrammar", ".", "rule" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L684-L695
55,594
pmh/espresso
lib/ometa/ometa/base.js
_not
function _not(expr) { var state = this.bt.current_state(); try { var r = expr.call(this) } catch (f) { this.bt.catch_mismatch(f); this.bt.restore(state); return true } this.bt.mismatch("Negative lookahead didn't match got " + r); }
javascript
function _not(expr) { var state = this.bt.current_state(); try { var r = expr.call(this) } catch (f) { this.bt.catch_mismatch(f); this.bt.restore(state); return true } this.bt.mismatch("Negative lookahead didn't match got " + r); }
[ "function", "_not", "(", "expr", ")", "{", "var", "state", "=", "this", ".", "bt", ".", "current_state", "(", ")", ";", "try", "{", "var", "r", "=", "expr", ".", "call", "(", "this", ")", "}", "catch", "(", "f", ")", "{", "this", ".", "bt", ".", "catch_mismatch", "(", "f", ")", ";", "this", ".", "bt", ".", "restore", "(", "state", ")", ";", "return", "true", "}", "this", ".", "bt", ".", "mismatch", "(", "\"Negative lookahead didn't match got \"", "+", "r", ")", ";", "}" ]
negative lookahead ~rule
[ "negative", "lookahead", "~rule" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L714-L723
55,595
pmh/espresso
lib/ometa/ometa/base.js
_lookahead
function _lookahead(expr) { var state = this.bt.current_state(), ans = expr.call(this); this.bt.restore(state); return ans }
javascript
function _lookahead(expr) { var state = this.bt.current_state(), ans = expr.call(this); this.bt.restore(state); return ans }
[ "function", "_lookahead", "(", "expr", ")", "{", "var", "state", "=", "this", ".", "bt", ".", "current_state", "(", ")", ",", "ans", "=", "expr", ".", "call", "(", "this", ")", ";", "this", ".", "bt", ".", "restore", "(", "state", ")", ";", "return", "ans", "}" ]
positive lookahead &rule
[ "positive", "lookahead", "&rule" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L727-L732
55,596
pmh/espresso
lib/ometa/ometa/base.js
function() { var state = this.bt.current_state(); for(var i=0,len=arguments.length; i<len; i++) { try { return arguments[i].call(this) } catch (f) { this.bt.catch_mismatch(f); this.bt.restore(state); } } this.bt.mismatch("All alternatives failed"); }
javascript
function() { var state = this.bt.current_state(); for(var i=0,len=arguments.length; i<len; i++) { try { return arguments[i].call(this) } catch (f) { this.bt.catch_mismatch(f); this.bt.restore(state); } } this.bt.mismatch("All alternatives failed"); }
[ "function", "(", ")", "{", "var", "state", "=", "this", ".", "bt", ".", "current_state", "(", ")", ";", "for", "(", "var", "i", "=", "0", ",", "len", "=", "arguments", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "try", "{", "return", "arguments", "[", "i", "]", ".", "call", "(", "this", ")", "}", "catch", "(", "f", ")", "{", "this", ".", "bt", ".", "catch_mismatch", "(", "f", ")", ";", "this", ".", "bt", ".", "restore", "(", "state", ")", ";", "}", "}", "this", ".", "bt", ".", "mismatch", "(", "\"All alternatives failed\"", ")", ";", "}" ]
ordered alternatives rule_a | rule_b tries all alternatives until the first match
[ "ordered", "alternatives", "rule_a", "|", "rule_b", "tries", "all", "alternatives", "until", "the", "first", "match" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L737-L749
55,597
pmh/espresso
lib/ometa/ometa/base.js
function(rule) { var state = this.bt.current_state(); try { return rule.call(this); } catch(f) { this.bt.catch_mismatch(f); this.bt.restore(state); } }
javascript
function(rule) { var state = this.bt.current_state(); try { return rule.call(this); } catch(f) { this.bt.catch_mismatch(f); this.bt.restore(state); } }
[ "function", "(", "rule", ")", "{", "var", "state", "=", "this", ".", "bt", ".", "current_state", "(", ")", ";", "try", "{", "return", "rule", ".", "call", "(", "this", ")", ";", "}", "catch", "(", "f", ")", "{", "this", ".", "bt", ".", "catch_mismatch", "(", "f", ")", ";", "this", ".", "bt", ".", "restore", "(", "state", ")", ";", "}", "}" ]
Optional occurance of rule rule?
[ "Optional", "occurance", "of", "rule", "rule?" ]
26d7b2089a2098344aaaf32ec7eb942e91a7edf5
https://github.com/pmh/espresso/blob/26d7b2089a2098344aaaf32ec7eb942e91a7edf5/lib/ometa/ometa/base.js#L788-L795
55,598
nail/node-gelf-manager
lib/gelf-manager.js
GELFManager
function GELFManager(options) { if (typeof options === 'undefined') options = {}; for (k in GELFManager.options) if (typeof options[k] === 'undefined') options[k] = GELFManager.options[k]; this.debug = options.debug; this.chunkTimeout = options.chunkTimeout; this.gcTimeout = options.gcTimeout; EventEmitter.call(this); this.chunksPool = {}; process.nextTick(this._gc.bind(this)); }
javascript
function GELFManager(options) { if (typeof options === 'undefined') options = {}; for (k in GELFManager.options) if (typeof options[k] === 'undefined') options[k] = GELFManager.options[k]; this.debug = options.debug; this.chunkTimeout = options.chunkTimeout; this.gcTimeout = options.gcTimeout; EventEmitter.call(this); this.chunksPool = {}; process.nextTick(this._gc.bind(this)); }
[ "function", "GELFManager", "(", "options", ")", "{", "if", "(", "typeof", "options", "===", "'undefined'", ")", "options", "=", "{", "}", ";", "for", "(", "k", "in", "GELFManager", ".", "options", ")", "if", "(", "typeof", "options", "[", "k", "]", "===", "'undefined'", ")", "options", "[", "k", "]", "=", "GELFManager", ".", "options", "[", "k", "]", ";", "this", ".", "debug", "=", "options", ".", "debug", ";", "this", ".", "chunkTimeout", "=", "options", ".", "chunkTimeout", ";", "this", ".", "gcTimeout", "=", "options", ".", "gcTimeout", ";", "EventEmitter", ".", "call", "(", "this", ")", ";", "this", ".", "chunksPool", "=", "{", "}", ";", "process", ".", "nextTick", "(", "this", ".", "_gc", ".", "bind", "(", "this", ")", ")", ";", "}" ]
GELFManager - Handles GELF messages Example: var manager = new GELFManager(); manager.on('message', function(msg) { console.log(msg); }); manager.feed(rawUDPMessage);
[ "GELFManager", "-", "Handles", "GELF", "messages" ]
4c090050c8706e5e20158263fea451e5e814285e
https://github.com/nail/node-gelf-manager/blob/4c090050c8706e5e20158263fea451e5e814285e/lib/gelf-manager.js#L23-L39
55,599
danawoodman/parent-folder
lib/index.js
parentFolder
function parentFolder(fullPath) { var isFile = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; // If no path passed in, use the file path of the // caller. if (!fullPath) { fullPath = module.parent.filename; isFile = true; } var pathObj = _path2['default'].parse(fullPath); if (isFile) { return pathObj.dir.split(_path2['default'].sep).slice(-1)[0]; } return pathObj.name; }
javascript
function parentFolder(fullPath) { var isFile = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; // If no path passed in, use the file path of the // caller. if (!fullPath) { fullPath = module.parent.filename; isFile = true; } var pathObj = _path2['default'].parse(fullPath); if (isFile) { return pathObj.dir.split(_path2['default'].sep).slice(-1)[0]; } return pathObj.name; }
[ "function", "parentFolder", "(", "fullPath", ")", "{", "var", "isFile", "=", "arguments", ".", "length", "<=", "1", "||", "arguments", "[", "1", "]", "===", "undefined", "?", "false", ":", "arguments", "[", "1", "]", ";", "// If no path passed in, use the file path of the", "// caller.", "if", "(", "!", "fullPath", ")", "{", "fullPath", "=", "module", ".", "parent", ".", "filename", ";", "isFile", "=", "true", ";", "}", "var", "pathObj", "=", "_path2", "[", "'default'", "]", ".", "parse", "(", "fullPath", ")", ";", "if", "(", "isFile", ")", "{", "return", "pathObj", ".", "dir", ".", "split", "(", "_path2", "[", "'default'", "]", ".", "sep", ")", ".", "slice", "(", "-", "1", ")", "[", "0", "]", ";", "}", "return", "pathObj", ".", "name", ";", "}" ]
Get the name of the parent folder. If given a directory as a path, return the last directory. If given a path with a file, return the parent of that file. Default to the parent folder of the call path. @module parentFolder @param {String} [fullPath=module.parent.filename] The full path to find the parent folder from @param {Boolean} [isFile=false] Flag to indicate passed in path is to a file not a folder @returns {String} The parent folder's name
[ "Get", "the", "name", "of", "the", "parent", "folder", ".", "If", "given", "a", "directory", "as", "a", "path", "return", "the", "last", "directory", ".", "If", "given", "a", "path", "with", "a", "file", "return", "the", "parent", "of", "that", "file", ".", "Default", "to", "the", "parent", "folder", "of", "the", "call", "path", "." ]
36ec3bf041d1402ce9f6946e1d05d7f9aff01e5a
https://github.com/danawoodman/parent-folder/blob/36ec3bf041d1402ce9f6946e1d05d7f9aff01e5a/lib/index.js#L26-L43