id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
44,300
andrewdavey/vogue
src/client/vogue-client.js
loadScript
function loadScript(src, loadedCallback) { var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("src", src); // Call the callback when the script is loaded. script.onload = loadedCallback; script.onreadystatechange = function () { if (this.readyState === "complete" || this.readyState === "loaded") { loadedCallback(); } }; head.appendChild(script); }
javascript
function loadScript(src, loadedCallback) { var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute("src", src); // Call the callback when the script is loaded. script.onload = loadedCallback; script.onreadystatechange = function () { if (this.readyState === "complete" || this.readyState === "loaded") { loadedCallback(); } }; head.appendChild(script); }
[ "function", "loadScript", "(", "src", ",", "loadedCallback", ")", "{", "var", "script", "=", "document", ".", "createElement", "(", "\"script\"", ")", ";", "script", ".", "setAttribute", "(", "\"type\"", ",", "\"text/javascript\"", ")", ";", "script", ".", "setAttribute", "(", "\"src\"", ",", "src", ")", ";", "// Call the callback when the script is loaded.", "script", ".", "onload", "=", "loadedCallback", ";", "script", ".", "onreadystatechange", "=", "function", "(", ")", "{", "if", "(", "this", ".", "readyState", "===", "\"complete\"", "||", "this", ".", "readyState", "===", "\"loaded\"", ")", "{", "loadedCallback", "(", ")", ";", "}", "}", ";", "head", ".", "appendChild", "(", "script", ")", ";", "}" ]
Load a script into the page, and call a callback when it is loaded. @param {String} src The URL of the script to be loaded. @param {Function} loadedCallback The function to be called when the script is loaded.
[ "Load", "a", "script", "into", "the", "page", "and", "call", "a", "callback", "when", "it", "is", "loaded", "." ]
46e38b373c7a86bbbb15177822e1ea3ff1ecda6c
https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L175-L189
44,301
andrewdavey/vogue
src/client/vogue-client.js
loadScripts
function loadScripts(scripts, loadedCallback) { var srcs = [], property, count, i, src, countDown = function () { count -= 1; if (!count) { loadedCallback(); } }; for (property in scripts) { if (!(property in window)) { srcs.push(scripts[property]); } } count = srcs.length; if (!count) { loadedCallback(); } for (i = 0; i < srcs.length; i += 1) { src = srcs[i]; loadScript(src, countDown); } }
javascript
function loadScripts(scripts, loadedCallback) { var srcs = [], property, count, i, src, countDown = function () { count -= 1; if (!count) { loadedCallback(); } }; for (property in scripts) { if (!(property in window)) { srcs.push(scripts[property]); } } count = srcs.length; if (!count) { loadedCallback(); } for (i = 0; i < srcs.length; i += 1) { src = srcs[i]; loadScript(src, countDown); } }
[ "function", "loadScripts", "(", "scripts", ",", "loadedCallback", ")", "{", "var", "srcs", "=", "[", "]", ",", "property", ",", "count", ",", "i", ",", "src", ",", "countDown", "=", "function", "(", ")", "{", "count", "-=", "1", ";", "if", "(", "!", "count", ")", "{", "loadedCallback", "(", ")", ";", "}", "}", ";", "for", "(", "property", "in", "scripts", ")", "{", "if", "(", "!", "(", "property", "in", "window", ")", ")", "{", "srcs", ".", "push", "(", "scripts", "[", "property", "]", ")", ";", "}", "}", "count", "=", "srcs", ".", "length", ";", "if", "(", "!", "count", ")", "{", "loadedCallback", "(", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "srcs", ".", "length", ";", "i", "+=", "1", ")", "{", "src", "=", "srcs", "[", "i", "]", ";", "loadScript", "(", "src", ",", "countDown", ")", ";", "}", "}" ]
Load scripts into the page, and call a callback when they are loaded. @param {Array} scripts The scripts to be loaded. @param {Function} loadedCallback The function to be called when all the scripts have loaded.
[ "Load", "scripts", "into", "the", "page", "and", "call", "a", "callback", "when", "they", "are", "loaded", "." ]
46e38b373c7a86bbbb15177822e1ea3ff1ecda6c
https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L197-L221
44,302
andrewdavey/vogue
src/client/vogue-client.js
getScriptInfo
function getScriptInfo() { var bases = [ document.location.protocol + "//" + document.location.host ], scripts, src, rootUrl, baseMatch; if (typeof window.__vogue__ === "undefined") { scripts = document.getElementsByTagName("script"); for (var i=0; i < scripts.length; i++) { src = scripts[i].getAttribute("src"); if (src && src.slice(-15) === 'vogue-client.js') break; } rootUrl = src.match(/^https?\:\/\/(.*?)\//)[0]; // There is an optional base argument, that can be used. baseMatch = src.match(/\bbase=(.*)(&|$)/); if (baseMatch) { bases = bases.concat(baseMatch[1].split(",")); } return { rootUrl: rootUrl, bases: bases }; } else { window.__vogue__.bases = bases; return window.__vogue__; } }
javascript
function getScriptInfo() { var bases = [ document.location.protocol + "//" + document.location.host ], scripts, src, rootUrl, baseMatch; if (typeof window.__vogue__ === "undefined") { scripts = document.getElementsByTagName("script"); for (var i=0; i < scripts.length; i++) { src = scripts[i].getAttribute("src"); if (src && src.slice(-15) === 'vogue-client.js') break; } rootUrl = src.match(/^https?\:\/\/(.*?)\//)[0]; // There is an optional base argument, that can be used. baseMatch = src.match(/\bbase=(.*)(&|$)/); if (baseMatch) { bases = bases.concat(baseMatch[1].split(",")); } return { rootUrl: rootUrl, bases: bases }; } else { window.__vogue__.bases = bases; return window.__vogue__; } }
[ "function", "getScriptInfo", "(", ")", "{", "var", "bases", "=", "[", "document", ".", "location", ".", "protocol", "+", "\"//\"", "+", "document", ".", "location", ".", "host", "]", ",", "scripts", ",", "src", ",", "rootUrl", ",", "baseMatch", ";", "if", "(", "typeof", "window", ".", "__vogue__", "===", "\"undefined\"", ")", "{", "scripts", "=", "document", ".", "getElementsByTagName", "(", "\"script\"", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "scripts", ".", "length", ";", "i", "++", ")", "{", "src", "=", "scripts", "[", "i", "]", ".", "getAttribute", "(", "\"src\"", ")", ";", "if", "(", "src", "&&", "src", ".", "slice", "(", "-", "15", ")", "===", "'vogue-client.js'", ")", "break", ";", "}", "rootUrl", "=", "src", ".", "match", "(", "/", "^https?\\:\\/\\/(.*?)\\/", "/", ")", "[", "0", "]", ";", "// There is an optional base argument, that can be used.", "baseMatch", "=", "src", ".", "match", "(", "/", "\\bbase=(.*)(&|$)", "/", ")", ";", "if", "(", "baseMatch", ")", "{", "bases", "=", "bases", ".", "concat", "(", "baseMatch", "[", "1", "]", ".", "split", "(", "\",\"", ")", ")", ";", "}", "return", "{", "rootUrl", ":", "rootUrl", ",", "bases", ":", "bases", "}", ";", "}", "else", "{", "window", ".", "__vogue__", ".", "bases", "=", "bases", ";", "return", "window", ".", "__vogue__", ";", "}", "}" ]
Fetches the info for the vogue client.
[ "Fetches", "the", "info", "for", "the", "vogue", "client", "." ]
46e38b373c7a86bbbb15177822e1ea3ff1ecda6c
https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L226-L250
44,303
andrewdavey/vogue
src/client/vogue-client.js
getPort
function getPort(url) { // URL may contain the port number after the second colon. // http://domain:1234/ var index = url.indexOf(":", 6); // skipping 6 characters to ignore first colon return index < 0 ? 80 : parseInt(url.substr(index + 1), 10); }
javascript
function getPort(url) { // URL may contain the port number after the second colon. // http://domain:1234/ var index = url.indexOf(":", 6); // skipping 6 characters to ignore first colon return index < 0 ? 80 : parseInt(url.substr(index + 1), 10); }
[ "function", "getPort", "(", "url", ")", "{", "// URL may contain the port number after the second colon.", "// http://domain:1234/", "var", "index", "=", "url", ".", "indexOf", "(", "\":\"", ",", "6", ")", ";", "// skipping 6 characters to ignore first colon", "return", "index", "<", "0", "?", "80", ":", "parseInt", "(", "url", ".", "substr", "(", "index", "+", "1", ")", ",", "10", ")", ";", "}" ]
Fetches the port from the URL. @param {String} url URL to get the port from @returns {Number} The port number, or 80 if no port number found or is invalid.
[ "Fetches", "the", "port", "from", "the", "URL", "." ]
46e38b373c7a86bbbb15177822e1ea3ff1ecda6c
https://github.com/andrewdavey/vogue/blob/46e38b373c7a86bbbb15177822e1ea3ff1ecda6c/src/client/vogue-client.js#L258-L263
44,304
Tabcorp/injectmd
index.js
nodeInjectmd
function nodeInjectmd (opts) { const inBuf = bl() assert.equal(typeof opts, 'object', 'opts should be an object') assert.equal(typeof opts.in, 'string', 'opts.in should be a string') assert.equal(typeof opts.tag, 'string', 'opts.tag should be a string') const inFile = opts.in const tag = opts.tag const startTag = new RegExp('<!--\\s*START ' + tag + '\\s*-->') const endTag = new RegExp('<!--\\s*END ' + tag + '\\s*-->') assert.equal(typeof opts, 'object', 'opts must be an object') const rs = new stream.PassThrough() rs.pipe(inBuf) rs.on('end', function () { var tagMode = false const mdPath = path.join(process.cwd(), inFile) const irs = fs.createReadStream(mdPath) const its = split(parse) const tmpBuf = bl() irs.pipe(its).pipe(tmpBuf) tmpBuf.on('finish', function () { const ws = fs.createWriteStream(inFile, { flags: 'w' }) const rs = tmpBuf.duplicate() rs.pipe(ws) }) function parse (line) { if (startTag.test(line.trim())) { tagMode = true const res = line + EOL + String(inBuf) + EOL return res } else if (endTag.test(line.trim())) { tagMode = false return line + EOL } else if (!tagMode) { return line + EOL } } }) return rs }
javascript
function nodeInjectmd (opts) { const inBuf = bl() assert.equal(typeof opts, 'object', 'opts should be an object') assert.equal(typeof opts.in, 'string', 'opts.in should be a string') assert.equal(typeof opts.tag, 'string', 'opts.tag should be a string') const inFile = opts.in const tag = opts.tag const startTag = new RegExp('<!--\\s*START ' + tag + '\\s*-->') const endTag = new RegExp('<!--\\s*END ' + tag + '\\s*-->') assert.equal(typeof opts, 'object', 'opts must be an object') const rs = new stream.PassThrough() rs.pipe(inBuf) rs.on('end', function () { var tagMode = false const mdPath = path.join(process.cwd(), inFile) const irs = fs.createReadStream(mdPath) const its = split(parse) const tmpBuf = bl() irs.pipe(its).pipe(tmpBuf) tmpBuf.on('finish', function () { const ws = fs.createWriteStream(inFile, { flags: 'w' }) const rs = tmpBuf.duplicate() rs.pipe(ws) }) function parse (line) { if (startTag.test(line.trim())) { tagMode = true const res = line + EOL + String(inBuf) + EOL return res } else if (endTag.test(line.trim())) { tagMode = false return line + EOL } else if (!tagMode) { return line + EOL } } }) return rs }
[ "function", "nodeInjectmd", "(", "opts", ")", "{", "const", "inBuf", "=", "bl", "(", ")", "assert", ".", "equal", "(", "typeof", "opts", ",", "'object'", ",", "'opts should be an object'", ")", "assert", ".", "equal", "(", "typeof", "opts", ".", "in", ",", "'string'", ",", "'opts.in should be a string'", ")", "assert", ".", "equal", "(", "typeof", "opts", ".", "tag", ",", "'string'", ",", "'opts.tag should be a string'", ")", "const", "inFile", "=", "opts", ".", "in", "const", "tag", "=", "opts", ".", "tag", "const", "startTag", "=", "new", "RegExp", "(", "'<!--\\\\s*START '", "+", "tag", "+", "'\\\\s*-->'", ")", "const", "endTag", "=", "new", "RegExp", "(", "'<!--\\\\s*END '", "+", "tag", "+", "'\\\\s*-->'", ")", "assert", ".", "equal", "(", "typeof", "opts", ",", "'object'", ",", "'opts must be an object'", ")", "const", "rs", "=", "new", "stream", ".", "PassThrough", "(", ")", "rs", ".", "pipe", "(", "inBuf", ")", "rs", ".", "on", "(", "'end'", ",", "function", "(", ")", "{", "var", "tagMode", "=", "false", "const", "mdPath", "=", "path", ".", "join", "(", "process", ".", "cwd", "(", ")", ",", "inFile", ")", "const", "irs", "=", "fs", ".", "createReadStream", "(", "mdPath", ")", "const", "its", "=", "split", "(", "parse", ")", "const", "tmpBuf", "=", "bl", "(", ")", "irs", ".", "pipe", "(", "its", ")", ".", "pipe", "(", "tmpBuf", ")", "tmpBuf", ".", "on", "(", "'finish'", ",", "function", "(", ")", "{", "const", "ws", "=", "fs", ".", "createWriteStream", "(", "inFile", ",", "{", "flags", ":", "'w'", "}", ")", "const", "rs", "=", "tmpBuf", ".", "duplicate", "(", ")", "rs", ".", "pipe", "(", "ws", ")", "}", ")", "function", "parse", "(", "line", ")", "{", "if", "(", "startTag", ".", "test", "(", "line", ".", "trim", "(", ")", ")", ")", "{", "tagMode", "=", "true", "const", "res", "=", "line", "+", "EOL", "+", "String", "(", "inBuf", ")", "+", "EOL", "return", "res", "}", "else", "if", "(", "endTag", ".", "test", "(", "line", ".", "trim", "(", ")", ")", ")", "{", "tagMode", "=", "false", "return", "line", "+", "EOL", "}", "else", "if", "(", "!", "tagMode", ")", "{", "return", "line", "+", "EOL", "}", "}", "}", ")", "return", "rs", "}" ]
Inject markdown into markdown obj -> null
[ "Inject", "markdown", "into", "markdown", "obj", "-", ">", "null" ]
24bddd988777b5905abd76bbad0d70215e874af8
https://github.com/Tabcorp/injectmd/blob/24bddd988777b5905abd76bbad0d70215e874af8/index.js#L13-L61
44,305
simov/xsql
lib/escape.js
wrap
function wrap (str, quote) { if (this.typecheck) t.typecheck('wrap', [str, quote]); if (!quote||quote=="'") return "'"+str+"'"; if (quote == '"') return '"'+str+'"'; return quote+str+quote; }
javascript
function wrap (str, quote) { if (this.typecheck) t.typecheck('wrap', [str, quote]); if (!quote||quote=="'") return "'"+str+"'"; if (quote == '"') return '"'+str+'"'; return quote+str+quote; }
[ "function", "wrap", "(", "str", ",", "quote", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'wrap'", ",", "[", "str", ",", "quote", "]", ")", ";", "if", "(", "!", "quote", "||", "quote", "==", "\"'\"", ")", "return", "\"'\"", "+", "str", "+", "\"'\"", ";", "if", "(", "quote", "==", "'\"'", ")", "return", "'\"'", "+", "str", "+", "'\"'", ";", "return", "quote", "+", "str", "+", "quote", ";", "}" ]
wrap string with quotes
[ "wrap", "string", "with", "quotes" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/escape.js#L12-L17
44,306
simov/xsql
lib/escape.js
string
function string (str, quote) { if (this.typecheck) t.typecheck('string', [str, quote]); return this.wrap(this.escape(str), quote); }
javascript
function string (str, quote) { if (this.typecheck) t.typecheck('string', [str, quote]); return this.wrap(this.escape(str), quote); }
[ "function", "string", "(", "str", ",", "quote", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'string'", ",", "[", "str", ",", "quote", "]", ")", ";", "return", "this", ".", "wrap", "(", "this", ".", "escape", "(", "str", ")", ",", "quote", ")", ";", "}" ]
escape string quotes and wrap it with quotes
[ "escape", "string", "quotes", "and", "wrap", "it", "with", "quotes" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/escape.js#L26-L29
44,307
sergeche/grunt-frontend
tasks/lib/css.js
function(files, config, catalog, env) { var grunt = env.grunt; var that = this; files.forEach(function(f) { var file = utils.fileInfo(f.dest, config); grunt.log.write('Processing ' + file.catalogPath.cyan); var src = f.src.map(function(src) { return utils.fileInfo(src, {cwd: config.srcWebroot}); }); file.content = src.map(function(src) { return that.processFile(src, config, catalog, env).content; }).join(''); if ( !config.force && file.catalogPath in catalog && catalog[file.catalogPath].hash === file.hash && fs.existsSync(file.absPath)) { grunt.log.writeln(' [skip]'.grey); return; } // save result grunt.log.writeln(' [save]'.green); grunt.file.write(file.absPath, file.content); catalog[file.catalogPath] = { hash: file.hash, date: utils.timestamp(), versioned: file.versionedUrl(config), files: src.map(function(f) { return { file: f.catalogPath, hash: f.hash, versioned: f.versionedUrl(config) }; }) }; }); }
javascript
function(files, config, catalog, env) { var grunt = env.grunt; var that = this; files.forEach(function(f) { var file = utils.fileInfo(f.dest, config); grunt.log.write('Processing ' + file.catalogPath.cyan); var src = f.src.map(function(src) { return utils.fileInfo(src, {cwd: config.srcWebroot}); }); file.content = src.map(function(src) { return that.processFile(src, config, catalog, env).content; }).join(''); if ( !config.force && file.catalogPath in catalog && catalog[file.catalogPath].hash === file.hash && fs.existsSync(file.absPath)) { grunt.log.writeln(' [skip]'.grey); return; } // save result grunt.log.writeln(' [save]'.green); grunt.file.write(file.absPath, file.content); catalog[file.catalogPath] = { hash: file.hash, date: utils.timestamp(), versioned: file.versionedUrl(config), files: src.map(function(f) { return { file: f.catalogPath, hash: f.hash, versioned: f.versionedUrl(config) }; }) }; }); }
[ "function", "(", "files", ",", "config", ",", "catalog", ",", "env", ")", "{", "var", "grunt", "=", "env", ".", "grunt", ";", "var", "that", "=", "this", ";", "files", ".", "forEach", "(", "function", "(", "f", ")", "{", "var", "file", "=", "utils", ".", "fileInfo", "(", "f", ".", "dest", ",", "config", ")", ";", "grunt", ".", "log", ".", "write", "(", "'Processing '", "+", "file", ".", "catalogPath", ".", "cyan", ")", ";", "var", "src", "=", "f", ".", "src", ".", "map", "(", "function", "(", "src", ")", "{", "return", "utils", ".", "fileInfo", "(", "src", ",", "{", "cwd", ":", "config", ".", "srcWebroot", "}", ")", ";", "}", ")", ";", "file", ".", "content", "=", "src", ".", "map", "(", "function", "(", "src", ")", "{", "return", "that", ".", "processFile", "(", "src", ",", "config", ",", "catalog", ",", "env", ")", ".", "content", ";", "}", ")", ".", "join", "(", "''", ")", ";", "if", "(", "!", "config", ".", "force", "&&", "file", ".", "catalogPath", "in", "catalog", "&&", "catalog", "[", "file", ".", "catalogPath", "]", ".", "hash", "===", "file", ".", "hash", "&&", "fs", ".", "existsSync", "(", "file", ".", "absPath", ")", ")", "{", "grunt", ".", "log", ".", "writeln", "(", "' [skip]'", ".", "grey", ")", ";", "return", ";", "}", "// save result", "grunt", ".", "log", ".", "writeln", "(", "' [save]'", ".", "green", ")", ";", "grunt", ".", "file", ".", "write", "(", "file", ".", "absPath", ",", "file", ".", "content", ")", ";", "catalog", "[", "file", ".", "catalogPath", "]", "=", "{", "hash", ":", "file", ".", "hash", ",", "date", ":", "utils", ".", "timestamp", "(", ")", ",", "versioned", ":", "file", ".", "versionedUrl", "(", "config", ")", ",", "files", ":", "src", ".", "map", "(", "function", "(", "f", ")", "{", "return", "{", "file", ":", "f", ".", "catalogPath", ",", "hash", ":", "f", ".", "hash", ",", "versioned", ":", "f", ".", "versionedUrl", "(", "config", ")", "}", ";", "}", ")", "}", ";", "}", ")", ";", "}" ]
Processes given CSS files @param {Array} files Normalized Grunt task file list @param {Object} config Current task config @param {Object} catalog Output catalog @param {Object} env Task environment (`grunt` and `task` properties) @return {Object} Updated catalog
[ "Processes", "given", "CSS", "files" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/css.js#L61-L101
44,308
wieden-kennedy/voyager
lib/task.js
Task
function Task(phase, name, func) { if (typeof name === 'function') { func = name; name = 'anonymous'; } if (phases.indexOf(phase) < 0) { throw new Error('Phase ' + phase + ' is not valid.'); } if (typeof func !== 'function') { throw new TypeError('Expected function, got ' + typeof func); } /** * The unique identifier for this task * @member {string} * @public */ this.name = name; /** * The phase under which this task is to be run * @member {string} * @public */ this.phase = phase; /** * The wrapped task function (func) * @member {Function} * @public * @returns Promise */ this.func = function () { var wheel = new Pinwheel('TASK: '+this.name+' ('+this.phase+')') , task = this; return new Promise(function (done, fail) { if (process.env.ENV !== 'test') wheel.start(); func.call(task, function (err) { if (err) return fail(err); return done(); }); }) .then(function () { if (process.env.ENV !== 'test') wheel.stop(); }) .catch(function (err) { if (process.env.ENV !== 'test') wheel.stop(err); return console.error(err); }); }; }
javascript
function Task(phase, name, func) { if (typeof name === 'function') { func = name; name = 'anonymous'; } if (phases.indexOf(phase) < 0) { throw new Error('Phase ' + phase + ' is not valid.'); } if (typeof func !== 'function') { throw new TypeError('Expected function, got ' + typeof func); } /** * The unique identifier for this task * @member {string} * @public */ this.name = name; /** * The phase under which this task is to be run * @member {string} * @public */ this.phase = phase; /** * The wrapped task function (func) * @member {Function} * @public * @returns Promise */ this.func = function () { var wheel = new Pinwheel('TASK: '+this.name+' ('+this.phase+')') , task = this; return new Promise(function (done, fail) { if (process.env.ENV !== 'test') wheel.start(); func.call(task, function (err) { if (err) return fail(err); return done(); }); }) .then(function () { if (process.env.ENV !== 'test') wheel.stop(); }) .catch(function (err) { if (process.env.ENV !== 'test') wheel.stop(err); return console.error(err); }); }; }
[ "function", "Task", "(", "phase", ",", "name", ",", "func", ")", "{", "if", "(", "typeof", "name", "===", "'function'", ")", "{", "func", "=", "name", ";", "name", "=", "'anonymous'", ";", "}", "if", "(", "phases", ".", "indexOf", "(", "phase", ")", "<", "0", ")", "{", "throw", "new", "Error", "(", "'Phase '", "+", "phase", "+", "' is not valid.'", ")", ";", "}", "if", "(", "typeof", "func", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "'Expected function, got '", "+", "typeof", "func", ")", ";", "}", "/**\n * The unique identifier for this task\n * @member {string}\n * @public\n */", "this", ".", "name", "=", "name", ";", "/**\n * The phase under which this task is to be run\n * @member {string}\n * @public\n */", "this", ".", "phase", "=", "phase", ";", "/**\n * The wrapped task function (func)\n * @member {Function}\n * @public\n * @returns Promise\n */", "this", ".", "func", "=", "function", "(", ")", "{", "var", "wheel", "=", "new", "Pinwheel", "(", "'TASK: '", "+", "this", ".", "name", "+", "' ('", "+", "this", ".", "phase", "+", "')'", ")", ",", "task", "=", "this", ";", "return", "new", "Promise", "(", "function", "(", "done", ",", "fail", ")", "{", "if", "(", "process", ".", "env", ".", "ENV", "!==", "'test'", ")", "wheel", ".", "start", "(", ")", ";", "func", ".", "call", "(", "task", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "fail", "(", "err", ")", ";", "return", "done", "(", ")", ";", "}", ")", ";", "}", ")", ".", "then", "(", "function", "(", ")", "{", "if", "(", "process", ".", "env", ".", "ENV", "!==", "'test'", ")", "wheel", ".", "stop", "(", ")", ";", "}", ")", ".", "catch", "(", "function", "(", "err", ")", "{", "if", "(", "process", ".", "env", ".", "ENV", "!==", "'test'", ")", "wheel", ".", "stop", "(", "err", ")", ";", "return", "console", ".", "error", "(", "err", ")", ";", "}", ")", ";", "}", ";", "}" ]
Task constructor, wraps task function and stores information about the task @constructor @param {string} phase - The phase under which this task is to be run @param {string} [name='anonymous'] - The unique identifier for this task @param {Function} func - The task function to be called
[ "Task", "constructor", "wraps", "task", "function", "and", "stores", "information", "about", "the", "task" ]
13b767b3fd6d562cd696fa36f2285c5ca38741a2
https://github.com/wieden-kennedy/voyager/blob/13b767b3fd6d562cd696fa36f2285c5ca38741a2/lib/task.js#L22-L74
44,309
sergeche/grunt-frontend
tasks/lib/catalog.js
function(content) { if (typeof content != 'string') { content = JSON.stringify(content, null, '\t'); } fs.writeFileSync(catalogFile, content); }
javascript
function(content) { if (typeof content != 'string') { content = JSON.stringify(content, null, '\t'); } fs.writeFileSync(catalogFile, content); }
[ "function", "(", "content", ")", "{", "if", "(", "typeof", "content", "!=", "'string'", ")", "{", "content", "=", "JSON", ".", "stringify", "(", "content", ",", "null", ",", "'\\t'", ")", ";", "}", "fs", ".", "writeFileSync", "(", "catalogFile", ",", "content", ")", ";", "}" ]
Saves given content in catalog file @param {Object} content Catalog content
[ "Saves", "given", "content", "in", "catalog", "file" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/catalog.js#L23-L29
44,310
jhermsmeier/node-blockdevice
lib/blockdevice.js
function( callback ) { var self = this // Close a previously opened handle if( this.fd != null ) { return this.close( function( error ) { if( error != null ) return callback.call( self, error ) self.open( callback ) }) } // Open a new fd handle debug( 'fs:open', this.mode, this.path ) this.fs.open( this.path, this.mode, function( error, fd ) { if( error != null ) return callback.call( self, error, fd ) // Set file descriptor self.fd = fd // If no blockSize has been set, attempt to // detect it after opening the device if( self.blockSize == null || self.blockSize <= 0 ) { self.detectBlockSize( 0, 0, 0, function( error, blockSize ) { self.blockSize = blockSize || -1 callback.call( self, error, self.fd ) }) } else { callback.call( self, error, fd ) } }) return this }
javascript
function( callback ) { var self = this // Close a previously opened handle if( this.fd != null ) { return this.close( function( error ) { if( error != null ) return callback.call( self, error ) self.open( callback ) }) } // Open a new fd handle debug( 'fs:open', this.mode, this.path ) this.fs.open( this.path, this.mode, function( error, fd ) { if( error != null ) return callback.call( self, error, fd ) // Set file descriptor self.fd = fd // If no blockSize has been set, attempt to // detect it after opening the device if( self.blockSize == null || self.blockSize <= 0 ) { self.detectBlockSize( 0, 0, 0, function( error, blockSize ) { self.blockSize = blockSize || -1 callback.call( self, error, self.fd ) }) } else { callback.call( self, error, fd ) } }) return this }
[ "function", "(", "callback", ")", "{", "var", "self", "=", "this", "// Close a previously opened handle", "if", "(", "this", ".", "fd", "!=", "null", ")", "{", "return", "this", ".", "close", "(", "function", "(", "error", ")", "{", "if", "(", "error", "!=", "null", ")", "return", "callback", ".", "call", "(", "self", ",", "error", ")", "self", ".", "open", "(", "callback", ")", "}", ")", "}", "// Open a new fd handle", "debug", "(", "'fs:open'", ",", "this", ".", "mode", ",", "this", ".", "path", ")", "this", ".", "fs", ".", "open", "(", "this", ".", "path", ",", "this", ".", "mode", ",", "function", "(", "error", ",", "fd", ")", "{", "if", "(", "error", "!=", "null", ")", "return", "callback", ".", "call", "(", "self", ",", "error", ",", "fd", ")", "// Set file descriptor", "self", ".", "fd", "=", "fd", "// If no blockSize has been set, attempt to", "// detect it after opening the device", "if", "(", "self", ".", "blockSize", "==", "null", "||", "self", ".", "blockSize", "<=", "0", ")", "{", "self", ".", "detectBlockSize", "(", "0", ",", "0", ",", "0", ",", "function", "(", "error", ",", "blockSize", ")", "{", "self", ".", "blockSize", "=", "blockSize", "||", "-", "1", "callback", ".", "call", "(", "self", ",", "error", ",", "self", ".", "fd", ")", "}", ")", "}", "else", "{", "callback", ".", "call", "(", "self", ",", "error", ",", "fd", ")", "}", "}", ")", "return", "this", "}" ]
Opens a file descriptor for this device @param {Function} callback @return {BlockDevice}
[ "Opens", "a", "file", "descriptor", "for", "this", "device" ]
10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d
https://github.com/jhermsmeier/node-blockdevice/blob/10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d/lib/blockdevice.js#L69-L107
44,311
jhermsmeier/node-blockdevice
lib/blockdevice.js
function( size, step, limit, callback ) { var args = [].slice.call( arguments ) callback = args.pop() if( this.fd == null ) return callback.call( this, new Error( 'Invalid file descriptor' ) ) limit = args.pop() || 0x2000 step = args.pop() || 0x80 size = args.pop() || 0x200 var self = this var readBlock = function() { var block = Buffer.allocUnsafe( size ) self.fs.read( self.fd, block, 0, size, 0, function( error, bytesRead ) { if( error != null ) { // EINVAL tells us that the block size // ain't just right (yet); everything // else is probably user error if( error.code !== 'EINVAL' ) return callback.call( self, error ) // Increase the blocksize by `step` size += step // Attempt next size read return readBlock() } // Check if bytes read correspond // to current block size if( size !== bytesRead ) { error = new Error( 'Size and bytes read mismatch: ' + size + ', ' + bytesRead ) return callback.call( self, error ) } // Check if the limit has been reached, // and terminate with error, if so if( size > limit ) { error = new Error( 'Reached limit of ' + limit + ' bytes' ) return callback.call( self, error ) } // We've successfully found the // smallest readable block size; // stop looking... self.blockSize = size callback.call( self, null, size ) }) } // Start reading blocks readBlock() return this }
javascript
function( size, step, limit, callback ) { var args = [].slice.call( arguments ) callback = args.pop() if( this.fd == null ) return callback.call( this, new Error( 'Invalid file descriptor' ) ) limit = args.pop() || 0x2000 step = args.pop() || 0x80 size = args.pop() || 0x200 var self = this var readBlock = function() { var block = Buffer.allocUnsafe( size ) self.fs.read( self.fd, block, 0, size, 0, function( error, bytesRead ) { if( error != null ) { // EINVAL tells us that the block size // ain't just right (yet); everything // else is probably user error if( error.code !== 'EINVAL' ) return callback.call( self, error ) // Increase the blocksize by `step` size += step // Attempt next size read return readBlock() } // Check if bytes read correspond // to current block size if( size !== bytesRead ) { error = new Error( 'Size and bytes read mismatch: ' + size + ', ' + bytesRead ) return callback.call( self, error ) } // Check if the limit has been reached, // and terminate with error, if so if( size > limit ) { error = new Error( 'Reached limit of ' + limit + ' bytes' ) return callback.call( self, error ) } // We've successfully found the // smallest readable block size; // stop looking... self.blockSize = size callback.call( self, null, size ) }) } // Start reading blocks readBlock() return this }
[ "function", "(", "size", ",", "step", ",", "limit", ",", "callback", ")", "{", "var", "args", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ")", "callback", "=", "args", ".", "pop", "(", ")", "if", "(", "this", ".", "fd", "==", "null", ")", "return", "callback", ".", "call", "(", "this", ",", "new", "Error", "(", "'Invalid file descriptor'", ")", ")", "limit", "=", "args", ".", "pop", "(", ")", "||", "0x2000", "step", "=", "args", ".", "pop", "(", ")", "||", "0x80", "size", "=", "args", ".", "pop", "(", ")", "||", "0x200", "var", "self", "=", "this", "var", "readBlock", "=", "function", "(", ")", "{", "var", "block", "=", "Buffer", ".", "allocUnsafe", "(", "size", ")", "self", ".", "fs", ".", "read", "(", "self", ".", "fd", ",", "block", ",", "0", ",", "size", ",", "0", ",", "function", "(", "error", ",", "bytesRead", ")", "{", "if", "(", "error", "!=", "null", ")", "{", "// EINVAL tells us that the block size", "// ain't just right (yet); everything", "// else is probably user error", "if", "(", "error", ".", "code", "!==", "'EINVAL'", ")", "return", "callback", ".", "call", "(", "self", ",", "error", ")", "// Increase the blocksize by `step`", "size", "+=", "step", "// Attempt next size read", "return", "readBlock", "(", ")", "}", "// Check if bytes read correspond", "// to current block size", "if", "(", "size", "!==", "bytesRead", ")", "{", "error", "=", "new", "Error", "(", "'Size and bytes read mismatch: '", "+", "size", "+", "', '", "+", "bytesRead", ")", "return", "callback", ".", "call", "(", "self", ",", "error", ")", "}", "// Check if the limit has been reached,", "// and terminate with error, if so", "if", "(", "size", ">", "limit", ")", "{", "error", "=", "new", "Error", "(", "'Reached limit of '", "+", "limit", "+", "' bytes'", ")", "return", "callback", ".", "call", "(", "self", ",", "error", ")", "}", "// We've successfully found the", "// smallest readable block size;", "// stop looking...", "self", ".", "blockSize", "=", "size", "callback", ".", "call", "(", "self", ",", "null", ",", "size", ")", "}", ")", "}", "// Start reading blocks", "readBlock", "(", ")", "return", "this", "}" ]
Primitive logical block size detection @param {Number} [size=128] @param {Number} [step=128] @param {Number} [limit=8192] @param {Function} callback( err, blockSize ) @return {BlockDevice}
[ "Primitive", "logical", "block", "size", "detection" ]
10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d
https://github.com/jhermsmeier/node-blockdevice/blob/10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d/lib/blockdevice.js#L139-L200
44,312
jhermsmeier/node-blockdevice
lib/blockdevice.js
function( cylinder, head, sector ) { if( this.headsPerTrack < 0 || this.sectorsPerTrack < 0 ) throw new Error( 'Unspecified device geometry' ) return ( cylinder * this.headsPerTrack + head ) * this.sectorsPerTrack + ( sector - 1 ) }
javascript
function( cylinder, head, sector ) { if( this.headsPerTrack < 0 || this.sectorsPerTrack < 0 ) throw new Error( 'Unspecified device geometry' ) return ( cylinder * this.headsPerTrack + head ) * this.sectorsPerTrack + ( sector - 1 ) }
[ "function", "(", "cylinder", ",", "head", ",", "sector", ")", "{", "if", "(", "this", ".", "headsPerTrack", "<", "0", "||", "this", ".", "sectorsPerTrack", "<", "0", ")", "throw", "new", "Error", "(", "'Unspecified device geometry'", ")", "return", "(", "cylinder", "*", "this", ".", "headsPerTrack", "+", "head", ")", "*", "this", ".", "sectorsPerTrack", "+", "(", "sector", "-", "1", ")", "}" ]
Converts a CHS address to an LBA @param {Number} cylinder @param {Number} head @param {Number} sector @return {BlockDevice}
[ "Converts", "a", "CHS", "address", "to", "an", "LBA" ]
10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d
https://github.com/jhermsmeier/node-blockdevice/blob/10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d/lib/blockdevice.js#L289-L297
44,313
jhermsmeier/node-blockdevice
lib/blockdevice.js
function( fromLBA, toLBA, buffer, callback ) { fromLBA = fromLBA || 0 toLBA = toLBA || ( fromLBA + 1 ) if( fromLBA > toLBA ) { var swap = fromLBA fromLBA = toLBA toLBA = swap swap = void 0 } if( typeof buffer === 'function' ) { callback = buffer buffer = null } var self = this var from = this.blockSize * fromLBA var to = this.blockSize * toLBA debug( 'read_blocks', fromLBA, toLBA, buffer && buffer.length ) this._read( from, to - from, buffer, callback ) return this }
javascript
function( fromLBA, toLBA, buffer, callback ) { fromLBA = fromLBA || 0 toLBA = toLBA || ( fromLBA + 1 ) if( fromLBA > toLBA ) { var swap = fromLBA fromLBA = toLBA toLBA = swap swap = void 0 } if( typeof buffer === 'function' ) { callback = buffer buffer = null } var self = this var from = this.blockSize * fromLBA var to = this.blockSize * toLBA debug( 'read_blocks', fromLBA, toLBA, buffer && buffer.length ) this._read( from, to - from, buffer, callback ) return this }
[ "function", "(", "fromLBA", ",", "toLBA", ",", "buffer", ",", "callback", ")", "{", "fromLBA", "=", "fromLBA", "||", "0", "toLBA", "=", "toLBA", "||", "(", "fromLBA", "+", "1", ")", "if", "(", "fromLBA", ">", "toLBA", ")", "{", "var", "swap", "=", "fromLBA", "fromLBA", "=", "toLBA", "toLBA", "=", "swap", "swap", "=", "void", "0", "}", "if", "(", "typeof", "buffer", "===", "'function'", ")", "{", "callback", "=", "buffer", "buffer", "=", "null", "}", "var", "self", "=", "this", "var", "from", "=", "this", ".", "blockSize", "*", "fromLBA", "var", "to", "=", "this", ".", "blockSize", "*", "toLBA", "debug", "(", "'read_blocks'", ",", "fromLBA", ",", "toLBA", ",", "buffer", "&&", "buffer", ".", "length", ")", "this", ".", "_read", "(", "from", ",", "to", "-", "from", ",", "buffer", ",", "callback", ")", "return", "this", "}" ]
Reads from one LBA to another @param {Number} fromLBA @param {Number} toLBA @param {Buffer} buffer (optional) @param {Function} callback( error, buffer, bytesRead ) @return {BlockDevice}
[ "Reads", "from", "one", "LBA", "to", "another" ]
10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d
https://github.com/jhermsmeier/node-blockdevice/blob/10fcfa6cc1c053fd72d7046ae0372ff275b4bf7d/lib/blockdevice.js#L330-L357
44,314
alexindigo/configly
lib/env_vars.js
envVars
function envVars(config, backRef) { backRef = backRef || []; Object.keys(config).forEach(function(key) { var value; if (typeof config[key] == 'string') { // try simple match first, for non-empty value value = getVar.call(this, config[key], process.env); // if not, try parsing for variables if (!hasValue(value)) { value = parseTokens.call(this, config[key], process.env); } // keep the entry if something's been resolved // empty or unchanged value signal otherwise if (hasValue(value)) { config[key] = value; } else { delete config[key]; } } else if (isObject(config[key])) { envVars.call(this, config[key], backRef.concat(key)); } // Unsupported entry type else { throw new Error('Illegal key type for custom-environment-variables at ' + backRef.concat(key).join('.') + ': ' + Object.prototype.toString.call(config[key])); } }.bind(this)); return config; }
javascript
function envVars(config, backRef) { backRef = backRef || []; Object.keys(config).forEach(function(key) { var value; if (typeof config[key] == 'string') { // try simple match first, for non-empty value value = getVar.call(this, config[key], process.env); // if not, try parsing for variables if (!hasValue(value)) { value = parseTokens.call(this, config[key], process.env); } // keep the entry if something's been resolved // empty or unchanged value signal otherwise if (hasValue(value)) { config[key] = value; } else { delete config[key]; } } else if (isObject(config[key])) { envVars.call(this, config[key], backRef.concat(key)); } // Unsupported entry type else { throw new Error('Illegal key type for custom-environment-variables at ' + backRef.concat(key).join('.') + ': ' + Object.prototype.toString.call(config[key])); } }.bind(this)); return config; }
[ "function", "envVars", "(", "config", ",", "backRef", ")", "{", "backRef", "=", "backRef", "||", "[", "]", ";", "Object", ".", "keys", "(", "config", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "var", "value", ";", "if", "(", "typeof", "config", "[", "key", "]", "==", "'string'", ")", "{", "// try simple match first, for non-empty value", "value", "=", "getVar", ".", "call", "(", "this", ",", "config", "[", "key", "]", ",", "process", ".", "env", ")", ";", "// if not, try parsing for variables", "if", "(", "!", "hasValue", "(", "value", ")", ")", "{", "value", "=", "parseTokens", ".", "call", "(", "this", ",", "config", "[", "key", "]", ",", "process", ".", "env", ")", ";", "}", "// keep the entry if something's been resolved", "// empty or unchanged value signal otherwise", "if", "(", "hasValue", "(", "value", ")", ")", "{", "config", "[", "key", "]", "=", "value", ";", "}", "else", "{", "delete", "config", "[", "key", "]", ";", "}", "}", "else", "if", "(", "isObject", "(", "config", "[", "key", "]", ")", ")", "{", "envVars", ".", "call", "(", "this", ",", "config", "[", "key", "]", ",", "backRef", ".", "concat", "(", "key", ")", ")", ";", "}", "// Unsupported entry type", "else", "{", "throw", "new", "Error", "(", "'Illegal key type for custom-environment-variables at '", "+", "backRef", ".", "concat", "(", "key", ")", ".", "join", "(", "'.'", ")", "+", "': '", "+", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "config", "[", "key", "]", ")", ")", ";", "}", "}", ".", "bind", "(", "this", ")", ")", ";", "return", "config", ";", "}" ]
Replaces object's elements with corresponding environment variables, if defined @param {object} config - config object to process @param {array} [backRef] - back reference to the parent element @returns {object} - resolved object
[ "Replaces", "object", "s", "elements", "with", "corresponding", "environment", "variables", "if", "defined" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/env_vars.js#L17-L59
44,315
simov/xsql
lib/primitive.js
name
function name (column, table, schema) { if (this.typecheck) t.typecheck('name', [column, table, schema]); var result = []; schema && result.push(this.quotes(schema)); table && result.push(this.quotes(table)); column && result.push(this.quotes(column)); return result.join('.'); }
javascript
function name (column, table, schema) { if (this.typecheck) t.typecheck('name', [column, table, schema]); var result = []; schema && result.push(this.quotes(schema)); table && result.push(this.quotes(table)); column && result.push(this.quotes(column)); return result.join('.'); }
[ "function", "name", "(", "column", ",", "table", ",", "schema", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'name'", ",", "[", "column", ",", "table", ",", "schema", "]", ")", ";", "var", "result", "=", "[", "]", ";", "schema", "&&", "result", ".", "push", "(", "this", ".", "quotes", "(", "schema", ")", ")", ";", "table", "&&", "result", ".", "push", "(", "this", ".", "quotes", "(", "table", ")", ")", ";", "column", "&&", "result", ".", "push", "(", "this", ".", "quotes", "(", "column", ")", ")", ";", "return", "result", ".", "join", "(", "'.'", ")", ";", "}" ]
"name" | "table"."name" | "schema"."table"."name"
[ "name", "|", "table", ".", "name", "|", "schema", ".", "table", ".", "name" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L6-L14
44,316
simov/xsql
lib/primitive.js
names
function names (columns, table, schema) { if (this.typecheck) t.typecheck('names', [columns, table, schema]); var result = []; for (var i=0; i < columns.length; i++) { result.push(this.name(columns[i],table,schema)); } return result.join(','); }
javascript
function names (columns, table, schema) { if (this.typecheck) t.typecheck('names', [columns, table, schema]); var result = []; for (var i=0; i < columns.length; i++) { result.push(this.name(columns[i],table,schema)); } return result.join(','); }
[ "function", "names", "(", "columns", ",", "table", ",", "schema", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'names'", ",", "[", "columns", ",", "table", ",", "schema", "]", ")", ";", "var", "result", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "columns", ".", "length", ";", "i", "++", ")", "{", "result", ".", "push", "(", "this", ".", "name", "(", "columns", "[", "i", "]", ",", "table", ",", "schema", ")", ")", ";", "}", "return", "result", ".", "join", "(", "','", ")", ";", "}" ]
name,name,...
[ "name", "name", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L17-L26
44,317
simov/xsql
lib/primitive.js
as
function as (column, name) { if (this.typecheck) t.typecheck('as', [column, name]); return [column,'as',name].join(' '); }
javascript
function as (column, name) { if (this.typecheck) t.typecheck('as', [column, name]); return [column,'as',name].join(' '); }
[ "function", "as", "(", "column", ",", "name", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'as'", ",", "[", "column", ",", "name", "]", ")", ";", "return", "[", "column", ",", "'as'", ",", "name", "]", ".", "join", "(", "' '", ")", ";", "}" ]
column as name
[ "column", "as", "name" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L36-L39
44,318
simov/xsql
lib/primitive.js
select
function select (args) { if (this.typecheck) t.typecheck('select', [args]); if ('string'===typeof args) args = [args]; return 'select '+args.join(); }
javascript
function select (args) { if (this.typecheck) t.typecheck('select', [args]); if ('string'===typeof args) args = [args]; return 'select '+args.join(); }
[ "function", "select", "(", "args", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'select'", ",", "[", "args", "]", ")", ";", "if", "(", "'string'", "===", "typeof", "args", ")", "args", "=", "[", "args", "]", ";", "return", "'select '", "+", "args", ".", "join", "(", ")", ";", "}" ]
select col1,col2
[ "select", "col1", "col2" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L55-L59
44,319
simov/xsql
lib/primitive.js
join
function join (table, args, type) { this.typecheck && t.typecheck('join', [table, args, type]); if ('string'===typeof args) args = [args]; var result = ['join',table,'on',args.join(' and ')]; if (type) result.splice(0,0,type); return result.join(' '); }
javascript
function join (table, args, type) { this.typecheck && t.typecheck('join', [table, args, type]); if ('string'===typeof args) args = [args]; var result = ['join',table,'on',args.join(' and ')]; if (type) result.splice(0,0,type); return result.join(' '); }
[ "function", "join", "(", "table", ",", "args", ",", "type", ")", "{", "this", ".", "typecheck", "&&", "t", ".", "typecheck", "(", "'join'", ",", "[", "table", ",", "args", ",", "type", "]", ")", ";", "if", "(", "'string'", "===", "typeof", "args", ")", "args", "=", "[", "args", "]", ";", "var", "result", "=", "[", "'join'", ",", "table", ",", "'on'", ",", "args", ".", "join", "(", "' and '", ")", "]", ";", "if", "(", "type", ")", "result", ".", "splice", "(", "0", ",", "0", ",", "type", ")", ";", "return", "result", ".", "join", "(", "' '", ")", ";", "}" ]
left join table on pk1=fk1 and pk2=fk2 ...
[ "left", "join", "table", "on", "pk1", "=", "fk1", "and", "pk2", "=", "fk2", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L68-L74
44,320
simov/xsql
lib/primitive.js
eq
function eq (a, b) { if (this.typecheck) t.typecheck('eq', [a, b]); return a+'='+b; }
javascript
function eq (a, b) { if (this.typecheck) t.typecheck('eq', [a, b]); return a+'='+b; }
[ "function", "eq", "(", "a", ",", "b", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'eq'", ",", "[", "a", ",", "b", "]", ")", ";", "return", "a", "+", "'='", "+", "b", ";", "}" ]
a = b
[ "a", "=", "b" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L77-L80
44,321
simov/xsql
lib/primitive.js
eqv
function eqv (column, value) { if (this.typecheck) t.typecheck('eqv', [column, value]); if (value===undefined||value===null) value = null; if ('string'===typeof value) value = this.string(value); if ('boolean'===typeof value) value = (this.dialect == 'pg') ? ((value == false) ? this.wrap('f') : this.wrap('t')) : ((value == false) ? 0 : 1); return column+'='+value; }
javascript
function eqv (column, value) { if (this.typecheck) t.typecheck('eqv', [column, value]); if (value===undefined||value===null) value = null; if ('string'===typeof value) value = this.string(value); if ('boolean'===typeof value) value = (this.dialect == 'pg') ? ((value == false) ? this.wrap('f') : this.wrap('t')) : ((value == false) ? 0 : 1); return column+'='+value; }
[ "function", "eqv", "(", "column", ",", "value", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'eqv'", ",", "[", "column", ",", "value", "]", ")", ";", "if", "(", "value", "===", "undefined", "||", "value", "===", "null", ")", "value", "=", "null", ";", "if", "(", "'string'", "===", "typeof", "value", ")", "value", "=", "this", ".", "string", "(", "value", ")", ";", "if", "(", "'boolean'", "===", "typeof", "value", ")", "value", "=", "(", "this", ".", "dialect", "==", "'pg'", ")", "?", "(", "(", "value", "==", "false", ")", "?", "this", ".", "wrap", "(", "'f'", ")", ":", "this", ".", "wrap", "(", "'t'", ")", ")", ":", "(", "(", "value", "==", "false", ")", "?", "0", ":", "1", ")", ";", "return", "column", "+", "'='", "+", "value", ";", "}" ]
col = val
[ "col", "=", "val" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L83-L93
44,322
simov/xsql
lib/primitive.js
groupby
function groupby (args) { if (this.typecheck) t.typecheck('groupby', [args]); if ('string'===typeof args) args = [args]; return 'group by '+args.join(); }
javascript
function groupby (args) { if (this.typecheck) t.typecheck('groupby', [args]); if ('string'===typeof args) args = [args]; return 'group by '+args.join(); }
[ "function", "groupby", "(", "args", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'groupby'", ",", "[", "args", "]", ")", ";", "if", "(", "'string'", "===", "typeof", "args", ")", "args", "=", "[", "args", "]", ";", "return", "'group by '", "+", "args", ".", "join", "(", ")", ";", "}" ]
group by arg1,arg2 ...
[ "group", "by", "arg1", "arg2", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L96-L100
44,323
simov/xsql
lib/primitive.js
orderby
function orderby (args, order) { if (this.typecheck) t.typecheck('orderby', [args, order]); var o = (order&&'string'===typeof order) ? order : ''; var result = []; if ('string'===typeof args) { result = o ? [args+' '+o] : [args]; } else if (args instanceof Array) { for (var i=0; i < args.length; i++) { if ('string'===typeof args[i]) { o ? result.push(args[i]+' '+o) : result.push(args[i]); } else if ('object'===typeof args[i]) { var key = Object.keys(args[i])[0]; result.push(key+' '+args[i][key]); } } } else if (args instanceof Object) { var key = Object.keys(args)[0]; result = [key+' '+args[key]]; } return 'order by '+result.join(); }
javascript
function orderby (args, order) { if (this.typecheck) t.typecheck('orderby', [args, order]); var o = (order&&'string'===typeof order) ? order : ''; var result = []; if ('string'===typeof args) { result = o ? [args+' '+o] : [args]; } else if (args instanceof Array) { for (var i=0; i < args.length; i++) { if ('string'===typeof args[i]) { o ? result.push(args[i]+' '+o) : result.push(args[i]); } else if ('object'===typeof args[i]) { var key = Object.keys(args[i])[0]; result.push(key+' '+args[i][key]); } } } else if (args instanceof Object) { var key = Object.keys(args)[0]; result = [key+' '+args[key]]; } return 'order by '+result.join(); }
[ "function", "orderby", "(", "args", ",", "order", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'orderby'", ",", "[", "args", ",", "order", "]", ")", ";", "var", "o", "=", "(", "order", "&&", "'string'", "===", "typeof", "order", ")", "?", "order", ":", "''", ";", "var", "result", "=", "[", "]", ";", "if", "(", "'string'", "===", "typeof", "args", ")", "{", "result", "=", "o", "?", "[", "args", "+", "' '", "+", "o", "]", ":", "[", "args", "]", ";", "}", "else", "if", "(", "args", "instanceof", "Array", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "if", "(", "'string'", "===", "typeof", "args", "[", "i", "]", ")", "{", "o", "?", "result", ".", "push", "(", "args", "[", "i", "]", "+", "' '", "+", "o", ")", ":", "result", ".", "push", "(", "args", "[", "i", "]", ")", ";", "}", "else", "if", "(", "'object'", "===", "typeof", "args", "[", "i", "]", ")", "{", "var", "key", "=", "Object", ".", "keys", "(", "args", "[", "i", "]", ")", "[", "0", "]", ";", "result", ".", "push", "(", "key", "+", "' '", "+", "args", "[", "i", "]", "[", "key", "]", ")", ";", "}", "}", "}", "else", "if", "(", "args", "instanceof", "Object", ")", "{", "var", "key", "=", "Object", ".", "keys", "(", "args", ")", "[", "0", "]", ";", "result", "=", "[", "key", "+", "' '", "+", "args", "[", "key", "]", "]", ";", "}", "return", "'order by '", "+", "result", ".", "join", "(", ")", ";", "}" ]
order by col1 asc, col2 desc ...
[ "order", "by", "col1", "asc", "col2", "desc", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L103-L129
44,324
simov/xsql
lib/primitive.js
limit
function limit (a, b) { if (this.typecheck) t.typecheck('limit', [a, b]); return (this.dialect == 'pg') ? ['limit',b,'offset',a].join(' ') : 'limit '+[a,b].join(); }
javascript
function limit (a, b) { if (this.typecheck) t.typecheck('limit', [a, b]); return (this.dialect == 'pg') ? ['limit',b,'offset',a].join(' ') : 'limit '+[a,b].join(); }
[ "function", "limit", "(", "a", ",", "b", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'limit'", ",", "[", "a", ",", "b", "]", ")", ";", "return", "(", "this", ".", "dialect", "==", "'pg'", ")", "?", "[", "'limit'", ",", "b", ",", "'offset'", ",", "a", "]", ".", "join", "(", "' '", ")", ":", "'limit '", "+", "[", "a", ",", "b", "]", ".", "join", "(", ")", ";", "}" ]
limit 1,2
[ "limit", "1", "2" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L132-L137
44,325
simov/xsql
lib/primitive.js
between
function between (a, b) { if (this.typecheck) t.typecheck('between', [a, b]); return ['between',a,'and',b].join(' '); }
javascript
function between (a, b) { if (this.typecheck) t.typecheck('between', [a, b]); return ['between',a,'and',b].join(' '); }
[ "function", "between", "(", "a", ",", "b", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'between'", ",", "[", "a", ",", "b", "]", ")", ";", "return", "[", "'between'", ",", "a", ",", "'and'", ",", "b", "]", ".", "join", "(", "' '", ")", ";", "}" ]
between a and b
[ "between", "a", "and", "b" ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L154-L157
44,326
simov/xsql
lib/primitive.js
where
function where (expr, operator) { if (this.typecheck) t.typecheck('where', [expr, operator]); if ('string'===typeof expr) return 'where '+expr; return 'where ' + expr.join(' '+(operator||'and')+' '); }
javascript
function where (expr, operator) { if (this.typecheck) t.typecheck('where', [expr, operator]); if ('string'===typeof expr) return 'where '+expr; return 'where ' + expr.join(' '+(operator||'and')+' '); }
[ "function", "where", "(", "expr", ",", "operator", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'where'", ",", "[", "expr", ",", "operator", "]", ")", ";", "if", "(", "'string'", "===", "typeof", "expr", ")", "return", "'where '", "+", "expr", ";", "return", "'where '", "+", "expr", ".", "join", "(", "' '", "+", "(", "operator", "||", "'and'", ")", "+", "' '", ")", ";", "}" ]
where expr1 and expr2 ...
[ "where", "expr1", "and", "expr2", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L166-L170
44,327
simov/xsql
lib/primitive.js
update
function update (table, columns, values) { if (this.typecheck) t.typecheck('update', [table, columns, values]); if ('string'===typeof columns) { columns = [columns]; values = [values]; } var result = []; for (var i=0; i < columns.length; i++) { var value = ('string'===typeof values[i] // X\'blob\' \'\\xblob\' && values[i].indexOf("X\'") != 0 && values[i].indexOf("\'\\x") != 0) ? this.string(values[i]) : values[i]; result.push(columns[i]+'='+value); } return ['update',table,'set',result.join()].join(' '); }
javascript
function update (table, columns, values) { if (this.typecheck) t.typecheck('update', [table, columns, values]); if ('string'===typeof columns) { columns = [columns]; values = [values]; } var result = []; for (var i=0; i < columns.length; i++) { var value = ('string'===typeof values[i] // X\'blob\' \'\\xblob\' && values[i].indexOf("X\'") != 0 && values[i].indexOf("\'\\x") != 0) ? this.string(values[i]) : values[i]; result.push(columns[i]+'='+value); } return ['update',table,'set',result.join()].join(' '); }
[ "function", "update", "(", "table", ",", "columns", ",", "values", ")", "{", "if", "(", "this", ".", "typecheck", ")", "t", ".", "typecheck", "(", "'update'", ",", "[", "table", ",", "columns", ",", "values", "]", ")", ";", "if", "(", "'string'", "===", "typeof", "columns", ")", "{", "columns", "=", "[", "columns", "]", ";", "values", "=", "[", "values", "]", ";", "}", "var", "result", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "columns", ".", "length", ";", "i", "++", ")", "{", "var", "value", "=", "(", "'string'", "===", "typeof", "values", "[", "i", "]", "// X\\'blob\\' \\'\\\\xblob\\'", "&&", "values", "[", "i", "]", ".", "indexOf", "(", "\"X\\'\"", ")", "!=", "0", "&&", "values", "[", "i", "]", ".", "indexOf", "(", "\"\\'\\\\x\"", ")", "!=", "0", ")", "?", "this", ".", "string", "(", "values", "[", "i", "]", ")", ":", "values", "[", "i", "]", ";", "result", ".", "push", "(", "columns", "[", "i", "]", "+", "'='", "+", "value", ")", ";", "}", "return", "[", "'update'", ",", "table", ",", "'set'", ",", "result", ".", "join", "(", ")", "]", ".", "join", "(", "' '", ")", ";", "}" ]
update tbl set col1=val1,col2=val2 ...
[ "update", "tbl", "set", "col1", "=", "val1", "col2", "=", "val2", "..." ]
32ea619470aa0a42e10aacc4b30df19105038976
https://github.com/simov/xsql/blob/32ea619470aa0a42e10aacc4b30df19105038976/lib/primitive.js#L208-L223
44,328
alexindigo/configly
lib/load_files.js
loadFiles
function loadFiles(directories, files) { // sort extensions to provide deterministic order of loading var _instance = this , extensions = resolveExts.call(this) , layers = [] ; // treat all inputs as list of directories directories = (typeOf(directories) == 'array') ? directories : [directories]; files.forEach(function(filename) { var layer = {file: filename, exts: []}; extensions.forEach(function(ext) { var layerExt = {ext: ext, dirs: []}; directories.forEach(function(dir) { var cfg, file = path.resolve(dir, filename + '.' + ext); if (fs.existsSync(file)) { cfg = loadContent.call(_instance, file, _instance.parsers[ext]); // check if any hooks needed to be applied cfg = applyHooks.call(_instance, cfg, filename); } if (cfg) { layerExt.dirs.push({ dir : dir, config: cfg }); } }); // populate with non-empty layers only if (layerExt.dirs.length) { layer.exts.push(layerExt); } }); // populate with non-empty layers only if (layer.exts.length) { layers.push(layer); } }); return layers; }
javascript
function loadFiles(directories, files) { // sort extensions to provide deterministic order of loading var _instance = this , extensions = resolveExts.call(this) , layers = [] ; // treat all inputs as list of directories directories = (typeOf(directories) == 'array') ? directories : [directories]; files.forEach(function(filename) { var layer = {file: filename, exts: []}; extensions.forEach(function(ext) { var layerExt = {ext: ext, dirs: []}; directories.forEach(function(dir) { var cfg, file = path.resolve(dir, filename + '.' + ext); if (fs.existsSync(file)) { cfg = loadContent.call(_instance, file, _instance.parsers[ext]); // check if any hooks needed to be applied cfg = applyHooks.call(_instance, cfg, filename); } if (cfg) { layerExt.dirs.push({ dir : dir, config: cfg }); } }); // populate with non-empty layers only if (layerExt.dirs.length) { layer.exts.push(layerExt); } }); // populate with non-empty layers only if (layer.exts.length) { layers.push(layer); } }); return layers; }
[ "function", "loadFiles", "(", "directories", ",", "files", ")", "{", "// sort extensions to provide deterministic order of loading", "var", "_instance", "=", "this", ",", "extensions", "=", "resolveExts", ".", "call", "(", "this", ")", ",", "layers", "=", "[", "]", ";", "// treat all inputs as list of directories", "directories", "=", "(", "typeOf", "(", "directories", ")", "==", "'array'", ")", "?", "directories", ":", "[", "directories", "]", ";", "files", ".", "forEach", "(", "function", "(", "filename", ")", "{", "var", "layer", "=", "{", "file", ":", "filename", ",", "exts", ":", "[", "]", "}", ";", "extensions", ".", "forEach", "(", "function", "(", "ext", ")", "{", "var", "layerExt", "=", "{", "ext", ":", "ext", ",", "dirs", ":", "[", "]", "}", ";", "directories", ".", "forEach", "(", "function", "(", "dir", ")", "{", "var", "cfg", ",", "file", "=", "path", ".", "resolve", "(", "dir", ",", "filename", "+", "'.'", "+", "ext", ")", ";", "if", "(", "fs", ".", "existsSync", "(", "file", ")", ")", "{", "cfg", "=", "loadContent", ".", "call", "(", "_instance", ",", "file", ",", "_instance", ".", "parsers", "[", "ext", "]", ")", ";", "// check if any hooks needed to be applied", "cfg", "=", "applyHooks", ".", "call", "(", "_instance", ",", "cfg", ",", "filename", ")", ";", "}", "if", "(", "cfg", ")", "{", "layerExt", ".", "dirs", ".", "push", "(", "{", "dir", ":", "dir", ",", "config", ":", "cfg", "}", ")", ";", "}", "}", ")", ";", "// populate with non-empty layers only", "if", "(", "layerExt", ".", "dirs", ".", "length", ")", "{", "layer", ".", "exts", ".", "push", "(", "layerExt", ")", ";", "}", "}", ")", ";", "// populate with non-empty layers only", "if", "(", "layer", ".", "exts", ".", "length", ")", "{", "layers", ".", "push", "(", "layer", ")", ";", "}", "}", ")", ";", "return", "layers", ";", "}" ]
Loads and parses config from available files @param {array|string} directories - directories to search in @param {array} files - list of files to search for @returns {array} - list of loaded configs in order of provided files
[ "Loads", "and", "parses", "config", "from", "available", "files" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/load_files.js#L19-L75
44,329
wieden-kennedy/voyager
lib/watch.js
Watch
function Watch(patterns, ids) { if (typeof patterns === 'undefined') { throw new Error('Watch constructor requires a patterns argument'); } if (typeof ids === 'undefined') { throw new Error('Watch constructor requires an ids argument'); } patterns = Array.isArray(patterns) ? patterns : [patterns]; ids = Array.isArray(ids) ? ids : [ids]; /** * The patterns/globs to be watched * @member {Array} * @public */ this.patterns = patterns; /** * Registered tasks namespace * @member {Object} * @public */ this.tasks = { /** * All 'read' phase tasks associated with this watch * @property {Array} * @public */ read: [] /** * A single 'write' task associated with this watch * @property {Task} */ , write: null }; // add the initial set of tasks this.add(ids); }
javascript
function Watch(patterns, ids) { if (typeof patterns === 'undefined') { throw new Error('Watch constructor requires a patterns argument'); } if (typeof ids === 'undefined') { throw new Error('Watch constructor requires an ids argument'); } patterns = Array.isArray(patterns) ? patterns : [patterns]; ids = Array.isArray(ids) ? ids : [ids]; /** * The patterns/globs to be watched * @member {Array} * @public */ this.patterns = patterns; /** * Registered tasks namespace * @member {Object} * @public */ this.tasks = { /** * All 'read' phase tasks associated with this watch * @property {Array} * @public */ read: [] /** * A single 'write' task associated with this watch * @property {Task} */ , write: null }; // add the initial set of tasks this.add(ids); }
[ "function", "Watch", "(", "patterns", ",", "ids", ")", "{", "if", "(", "typeof", "patterns", "===", "'undefined'", ")", "{", "throw", "new", "Error", "(", "'Watch constructor requires a patterns argument'", ")", ";", "}", "if", "(", "typeof", "ids", "===", "'undefined'", ")", "{", "throw", "new", "Error", "(", "'Watch constructor requires an ids argument'", ")", ";", "}", "patterns", "=", "Array", ".", "isArray", "(", "patterns", ")", "?", "patterns", ":", "[", "patterns", "]", ";", "ids", "=", "Array", ".", "isArray", "(", "ids", ")", "?", "ids", ":", "[", "ids", "]", ";", "/**\n * The patterns/globs to be watched\n * @member {Array}\n * @public\n */", "this", ".", "patterns", "=", "patterns", ";", "/**\n * Registered tasks namespace\n * @member {Object}\n * @public\n */", "this", ".", "tasks", "=", "{", "/**\n * All 'read' phase tasks associated with this watch\n * @property {Array}\n * @public\n */", "read", ":", "[", "]", "/**\n * A single 'write' task associated with this watch\n * @property {Task}\n */", ",", "write", ":", "null", "}", ";", "// add the initial set of tasks", "this", ".", "add", "(", "ids", ")", ";", "}" ]
Watch constructor, stores tasks to be run on given patterns @constructor @param {Array} patterns - The patterns/globs of this instance @param {Array} ids - Array of tasks identifiers to be run on these patterns
[ "Watch", "constructor", "stores", "tasks", "to", "be", "run", "on", "given", "patterns" ]
13b767b3fd6d562cd696fa36f2285c5ca38741a2
https://github.com/wieden-kennedy/voyager/blob/13b767b3fd6d562cd696fa36f2285c5ca38741a2/lib/watch.js#L20-L61
44,330
samthor/gulp-limiter
index.js
queue
function queue(runner) { if (running < tasks) { ++running; runner(release); } else { pending.push(runner); } }
javascript
function queue(runner) { if (running < tasks) { ++running; runner(release); } else { pending.push(runner); } }
[ "function", "queue", "(", "runner", ")", "{", "if", "(", "running", "<", "tasks", ")", "{", "++", "running", ";", "runner", "(", "release", ")", ";", "}", "else", "{", "pending", ".", "push", "(", "runner", ")", ";", "}", "}" ]
Queue an upcoming task, or run it immediately.
[ "Queue", "an", "upcoming", "task", "or", "run", "it", "immediately", "." ]
e7209ac6695a2cc2ba6b045202fded16716589e2
https://github.com/samthor/gulp-limiter/blob/e7209ac6695a2cc2ba6b045202fded16716589e2/index.js#L48-L55
44,331
inadarei/tap-nirvana
tap-nirvana.js
removeUselessStackLines
function removeUselessStackLines(stack) { let pretty = stack.split('\n'); pretty = pretty.filter((line) => { return !line.includes('node_modules') && !line.includes('Error'); }); pretty = pretty.join('\n'); return pretty; }
javascript
function removeUselessStackLines(stack) { let pretty = stack.split('\n'); pretty = pretty.filter((line) => { return !line.includes('node_modules') && !line.includes('Error'); }); pretty = pretty.join('\n'); return pretty; }
[ "function", "removeUselessStackLines", "(", "stack", ")", "{", "let", "pretty", "=", "stack", ".", "split", "(", "'\\n'", ")", ";", "pretty", "=", "pretty", ".", "filter", "(", "(", "line", ")", "=>", "{", "return", "!", "line", ".", "includes", "(", "'node_modules'", ")", "&&", "!", "line", ".", "includes", "(", "'Error'", ")", ";", "}", ")", ";", "pretty", "=", "pretty", ".", "join", "(", "'\\n'", ")", ";", "return", "pretty", ";", "}" ]
Remove lines from error stack that belong to test runner. Nobody cares @param {*String} stack
[ "Remove", "lines", "from", "error", "stack", "that", "belong", "to", "test", "runner", ".", "Nobody", "cares" ]
61e1785814f46c1f091c911a6c12912f0e79f729
https://github.com/inadarei/tap-nirvana/blob/61e1785814f46c1f091c911a6c12912f0e79f729/tap-nirvana.js#L52-L59
44,332
inadarei/tap-nirvana
tap-nirvana.js
formatErrors
function formatErrors (results) { return ''; var failCount = results.fail.length; var past = (failCount === 1) ? 'was' : 'were'; var plural = (failCount === 1) ? 'failure' : 'failures'; var out = '\n' + pad(format.red.bold('Failed Tests:') + ' There ' + past + ' ' + format.red.bold(failCount) + ' ' + plural + '\n'); out += formatFailedAssertions(results); return out; }
javascript
function formatErrors (results) { return ''; var failCount = results.fail.length; var past = (failCount === 1) ? 'was' : 'were'; var plural = (failCount === 1) ? 'failure' : 'failures'; var out = '\n' + pad(format.red.bold('Failed Tests:') + ' There ' + past + ' ' + format.red.bold(failCount) + ' ' + plural + '\n'); out += formatFailedAssertions(results); return out; }
[ "function", "formatErrors", "(", "results", ")", "{", "return", "''", ";", "var", "failCount", "=", "results", ".", "fail", ".", "length", ";", "var", "past", "=", "(", "failCount", "===", "1", ")", "?", "'was'", ":", "'were'", ";", "var", "plural", "=", "(", "failCount", "===", "1", ")", "?", "'failure'", ":", "'failures'", ";", "var", "out", "=", "'\\n'", "+", "pad", "(", "format", ".", "red", ".", "bold", "(", "'Failed Tests:'", ")", "+", "' There '", "+", "past", "+", "' '", "+", "format", ".", "red", ".", "bold", "(", "failCount", ")", "+", "' '", "+", "plural", "+", "'\\n'", ")", ";", "out", "+=", "formatFailedAssertions", "(", "results", ")", ";", "return", "out", ";", "}" ]
this duplicates errors that we already showd. @TODO : remove
[ "this", "duplicates", "errors", "that", "we", "already", "showd", "." ]
61e1785814f46c1f091c911a6c12912f0e79f729
https://github.com/inadarei/tap-nirvana/blob/61e1785814f46c1f091c911a6c12912f0e79f729/tap-nirvana.js#L191-L202
44,333
Stamplay/stamplay-cli
lib/stamplay.js
_checkUpdate
function _checkUpdate(){ var notifier = updateNotifier({ pkg: pkg, updateCheckInterval: 1000 * 60 * 60 * 24 * 7 }) if (notifier.update) notifier.notify() }
javascript
function _checkUpdate(){ var notifier = updateNotifier({ pkg: pkg, updateCheckInterval: 1000 * 60 * 60 * 24 * 7 }) if (notifier.update) notifier.notify() }
[ "function", "_checkUpdate", "(", ")", "{", "var", "notifier", "=", "updateNotifier", "(", "{", "pkg", ":", "pkg", ",", "updateCheckInterval", ":", "1000", "*", "60", "*", "60", "*", "24", "*", "7", "}", ")", "if", "(", "notifier", ".", "update", ")", "notifier", ".", "notify", "(", ")", "}" ]
Check if there is new package version
[ "Check", "if", "there", "is", "new", "package", "version" ]
5986d0163307102ce539e0a9f66c4b35f533d4a2
https://github.com/Stamplay/stamplay-cli/blob/5986d0163307102ce539e0a9f66c4b35f533d4a2/lib/stamplay.js#L91-L98
44,334
Stamplay/stamplay-cli
lib/stamplay.js
_detectComment
function _detectComment(argv){ var comment = '' if(argv._.length == 1){ if(argv.m && typeof argv.m == 'string') comment = argv.m else if (argv.message && typeof argv.message == 'string') comment = argv.message return comment } else { console.log(chalk.red.bold('Invalid command: use stamplay deploy -m "YOUR MESSAGE"')) process.exit(1) } }
javascript
function _detectComment(argv){ var comment = '' if(argv._.length == 1){ if(argv.m && typeof argv.m == 'string') comment = argv.m else if (argv.message && typeof argv.message == 'string') comment = argv.message return comment } else { console.log(chalk.red.bold('Invalid command: use stamplay deploy -m "YOUR MESSAGE"')) process.exit(1) } }
[ "function", "_detectComment", "(", "argv", ")", "{", "var", "comment", "=", "''", "if", "(", "argv", ".", "_", ".", "length", "==", "1", ")", "{", "if", "(", "argv", ".", "m", "&&", "typeof", "argv", ".", "m", "==", "'string'", ")", "comment", "=", "argv", ".", "m", "else", "if", "(", "argv", ".", "message", "&&", "typeof", "argv", ".", "message", "==", "'string'", ")", "comment", "=", "argv", ".", "message", "return", "comment", "}", "else", "{", "console", ".", "log", "(", "chalk", ".", "red", ".", "bold", "(", "'Invalid command: use stamplay deploy -m \"YOUR MESSAGE\"'", ")", ")", "process", ".", "exit", "(", "1", ")", "}", "}" ]
Detect if the option -m is present in the command
[ "Detect", "if", "the", "option", "-", "m", "is", "present", "in", "the", "command" ]
5986d0163307102ce539e0a9f66c4b35f533d4a2
https://github.com/Stamplay/stamplay-cli/blob/5986d0163307102ce539e0a9f66c4b35f533d4a2/lib/stamplay.js#L104-L114
44,335
ConnorWiseman/koa-hbs-renderer
lib/index.js
renderView
function renderView(view, layout, partials, context) { let options = { partials: partials }; // Handle dynamically-defined content tag let renderedView = {}; renderedView[opts.contentTag] = view(context, options); return layout(Object.assign({}, context, renderedView), options); }
javascript
function renderView(view, layout, partials, context) { let options = { partials: partials }; // Handle dynamically-defined content tag let renderedView = {}; renderedView[opts.contentTag] = view(context, options); return layout(Object.assign({}, context, renderedView), options); }
[ "function", "renderView", "(", "view", ",", "layout", ",", "partials", ",", "context", ")", "{", "let", "options", "=", "{", "partials", ":", "partials", "}", ";", "// Handle dynamically-defined content tag", "let", "renderedView", "=", "{", "}", ";", "renderedView", "[", "opts", ".", "contentTag", "]", "=", "view", "(", "context", ",", "options", ")", ";", "return", "layout", "(", "Object", ".", "assign", "(", "{", "}", ",", "context", ",", "renderedView", ")", ",", "options", ")", ";", "}" ]
Renders the specified view using the specified layout, partials, and context into a string. Although another Handlebars environment may be provided to the underlying renderer middleware, and partials manually registered with that environment will be used when rendering templates, all partials loaded by this module are handled manually by this module. There is no significant performance or usability advantage to using the #registerPartial method included in the Handlebars API to register partials instead; please see the Handlebars.js source code for further details. @param {Function} view The view to render @param {Function} layout The layout to render the view onto @param {Object.<Function>} partials An object map of partials @param {Object} context Data to be rendered into the view @return {String} @private @see {@link https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/base.js#L49}
[ "Renders", "the", "specified", "view", "using", "the", "specified", "layout", "partials", "and", "context", "into", "a", "string", "." ]
94cd84585543e157bda40bdbf27c2b4cc3e1ee58
https://github.com/ConnorWiseman/koa-hbs-renderer/blob/94cd84585543e157bda40bdbf27c2b4cc3e1ee58/lib/index.js#L97-L107
44,336
tlrobinson/xkcdplot
xkcd.js
function (nm) { el = d3.select(nm).append("svg") .attr("width", config.width + 2 * config.margin) .attr("height", config.height + 2 * config.margin) .append("g") .attr("transform", "translate(" + config.margin + ", " + config.margin + ")"); return xkcd; }
javascript
function (nm) { el = d3.select(nm).append("svg") .attr("width", config.width + 2 * config.margin) .attr("height", config.height + 2 * config.margin) .append("g") .attr("transform", "translate(" + config.margin + ", " + config.margin + ")"); return xkcd; }
[ "function", "(", "nm", ")", "{", "el", "=", "d3", ".", "select", "(", "nm", ")", ".", "append", "(", "\"svg\"", ")", ".", "attr", "(", "\"width\"", ",", "config", ".", "width", "+", "2", "*", "config", ".", "margin", ")", ".", "attr", "(", "\"height\"", ",", "config", ".", "height", "+", "2", "*", "config", ".", "margin", ")", ".", "append", "(", "\"g\"", ")", ".", "attr", "(", "\"transform\"", ",", "\"translate(\"", "+", "config", ".", "margin", "+", "\", \"", "+", "config", ".", "margin", "+", "\")\"", ")", ";", "return", "xkcd", ";", "}" ]
The XKCD object itself.
[ "The", "XKCD", "object", "itself", "." ]
4ed4426b1fd7370d162c6989d2cc103489e3d73a
https://github.com/tlrobinson/xkcdplot/blob/4ed4426b1fd7370d162c6989d2cc103489e3d73a/xkcd.js#L30-L38
44,337
tlrobinson/xkcdplot
xkcd.js
makeGetterSetter
function makeGetterSetter(name) { xkcd[name] = function (value) { if (arguments.length === 0) { return config[name]; } config[name] = value; return xkcd; }; }
javascript
function makeGetterSetter(name) { xkcd[name] = function (value) { if (arguments.length === 0) { return config[name]; } config[name] = value; return xkcd; }; }
[ "function", "makeGetterSetter", "(", "name", ")", "{", "xkcd", "[", "name", "]", "=", "function", "(", "value", ")", "{", "if", "(", "arguments", ".", "length", "===", "0", ")", "{", "return", "config", "[", "name", "]", ";", "}", "config", "[", "name", "]", "=", "value", ";", "return", "xkcd", ";", "}", ";", "}" ]
Getters and setters.
[ "Getters", "and", "setters", "." ]
4ed4426b1fd7370d162c6989d2cc103489e3d73a
https://github.com/tlrobinson/xkcdplot/blob/4ed4426b1fd7370d162c6989d2cc103489e3d73a/xkcd.js#L41-L49
44,338
tlrobinson/xkcdplot
xkcd.js
lineplot
function lineplot(data, x, y, opts) { var line = d3.svg.line().x(x).y(y).interpolate(xinterp), bgline = d3.svg.line().x(x).y(y), strokeWidth = _get(opts, "stroke-width", 3), color = _get(opts, "stroke", "steelblue"); el.append("svg:path").attr("d", bgline(data)) .style("stroke", "white") .style("stroke-width", 2 * strokeWidth + "px") .style("fill", "none") .attr("class", "bgline"); el.append("svg:path").attr("d", line(data)) .style("stroke", color) .style("stroke-width", strokeWidth + "px") .style("fill", "none"); }
javascript
function lineplot(data, x, y, opts) { var line = d3.svg.line().x(x).y(y).interpolate(xinterp), bgline = d3.svg.line().x(x).y(y), strokeWidth = _get(opts, "stroke-width", 3), color = _get(opts, "stroke", "steelblue"); el.append("svg:path").attr("d", bgline(data)) .style("stroke", "white") .style("stroke-width", 2 * strokeWidth + "px") .style("fill", "none") .attr("class", "bgline"); el.append("svg:path").attr("d", line(data)) .style("stroke", color) .style("stroke-width", strokeWidth + "px") .style("fill", "none"); }
[ "function", "lineplot", "(", "data", ",", "x", ",", "y", ",", "opts", ")", "{", "var", "line", "=", "d3", ".", "svg", ".", "line", "(", ")", ".", "x", "(", "x", ")", ".", "y", "(", "y", ")", ".", "interpolate", "(", "xinterp", ")", ",", "bgline", "=", "d3", ".", "svg", ".", "line", "(", ")", ".", "x", "(", "x", ")", ".", "y", "(", "y", ")", ",", "strokeWidth", "=", "_get", "(", "opts", ",", "\"stroke-width\"", ",", "3", ")", ",", "color", "=", "_get", "(", "opts", ",", "\"stroke\"", ",", "\"steelblue\"", ")", ";", "el", ".", "append", "(", "\"svg:path\"", ")", ".", "attr", "(", "\"d\"", ",", "bgline", "(", "data", ")", ")", ".", "style", "(", "\"stroke\"", ",", "\"white\"", ")", ".", "style", "(", "\"stroke-width\"", ",", "2", "*", "strokeWidth", "+", "\"px\"", ")", ".", "style", "(", "\"fill\"", ",", "\"none\"", ")", ".", "attr", "(", "\"class\"", ",", "\"bgline\"", ")", ";", "el", ".", "append", "(", "\"svg:path\"", ")", ".", "attr", "(", "\"d\"", ",", "line", "(", "data", ")", ")", ".", "style", "(", "\"stroke\"", ",", "color", ")", ".", "style", "(", "\"stroke-width\"", ",", "strokeWidth", "+", "\"px\"", ")", ".", "style", "(", "\"fill\"", ",", "\"none\"", ")", ";", "}" ]
Plot styles.
[ "Plot", "styles", "." ]
4ed4426b1fd7370d162c6989d2cc103489e3d73a
https://github.com/tlrobinson/xkcdplot/blob/4ed4426b1fd7370d162c6989d2cc103489e3d73a/xkcd.js#L151-L165
44,339
tlrobinson/xkcdplot
xkcd.js
_get
function _get(d, k, def) { if (typeof d === "undefined") return def; if (typeof d[k] === "undefined") return def; return d[k]; }
javascript
function _get(d, k, def) { if (typeof d === "undefined") return def; if (typeof d[k] === "undefined") return def; return d[k]; }
[ "function", "_get", "(", "d", ",", "k", ",", "def", ")", "{", "if", "(", "typeof", "d", "===", "\"undefined\"", ")", "return", "def", ";", "if", "(", "typeof", "d", "[", "k", "]", "===", "\"undefined\"", ")", "return", "def", ";", "return", "d", "[", "k", "]", ";", "}" ]
Get a value from an object or return a default if that doesn't work.
[ "Get", "a", "value", "from", "an", "object", "or", "return", "a", "default", "if", "that", "doesn", "t", "work", "." ]
4ed4426b1fd7370d162c6989d2cc103489e3d73a
https://github.com/tlrobinson/xkcdplot/blob/4ed4426b1fd7370d162c6989d2cc103489e3d73a/xkcd.js#L250-L254
44,340
thlorenz/stack-mapper
index.js
StackMapper
function StackMapper(sourcemap) { if (!(this instanceof StackMapper)) return new StackMapper(sourcemap); if (typeof sourcemap !== 'object') throw new Error('sourcemap needs to be an object, please use convert-source-map module to convert it from any other format\n' + 'See: https://github.com/thlorenz/stack-mapper#obtaining-the-source-map'); this._sourcemap = sourcemap; this._prepared = false; }
javascript
function StackMapper(sourcemap) { if (!(this instanceof StackMapper)) return new StackMapper(sourcemap); if (typeof sourcemap !== 'object') throw new Error('sourcemap needs to be an object, please use convert-source-map module to convert it from any other format\n' + 'See: https://github.com/thlorenz/stack-mapper#obtaining-the-source-map'); this._sourcemap = sourcemap; this._prepared = false; }
[ "function", "StackMapper", "(", "sourcemap", ")", "{", "if", "(", "!", "(", "this", "instanceof", "StackMapper", ")", ")", "return", "new", "StackMapper", "(", "sourcemap", ")", ";", "if", "(", "typeof", "sourcemap", "!==", "'object'", ")", "throw", "new", "Error", "(", "'sourcemap needs to be an object, please use convert-source-map module to convert it from any other format\\n'", "+", "'See: https://github.com/thlorenz/stack-mapper#obtaining-the-source-map'", ")", ";", "this", ".", "_sourcemap", "=", "sourcemap", ";", "this", ".", "_prepared", "=", "false", ";", "}" ]
Creates a Stackmapper that will use the given source map to map error trace locations @name StackMapper @private @constructor @param {Object} sourcemap
[ "Creates", "a", "Stackmapper", "that", "will", "use", "the", "given", "source", "map", "to", "map", "error", "trace", "locations" ]
a95b4a6899cca4ac8715863fd580827efe30fd0f
https://github.com/thlorenz/stack-mapper/blob/a95b4a6899cca4ac8715863fd580827efe30fd0f/index.js#L35-L43
44,341
ConnorWiseman/koa-hbs-renderer
lib/template-manager.js
compileTemplate
function compileTemplate(baseDir, filePath, type) { return new options.Promise((resolve, reject) => { let now = timestamp(); let name = filePath.substring(baseDir.length + 1).replace(/\\/g, '/'); name = name.substring(0, name.indexOf('.')); // A cached template is only invalidated if the environment is something // other than `development` and the time-to-live has been exceeded. if (cache[type][name] && (env !== 'development' || cache[type][name]._cached + expires > now)) { return resolve(cache[type][name]); } fs.readFile(filePath, 'utf-8', (error, contents) => { if (error) { return reject(error); } cache[type][name] = hbs.compile(contents.trim()); // Decorate the cached function with private members. The underscore // is necessary to avoid conflict with function's name to prevent all // compiled templates from being named `ret` in the cache. cache[type][name]._name = name; cache[type][name]._cached = timestamp(); return resolve(cache[type][name]); }); }); }
javascript
function compileTemplate(baseDir, filePath, type) { return new options.Promise((resolve, reject) => { let now = timestamp(); let name = filePath.substring(baseDir.length + 1).replace(/\\/g, '/'); name = name.substring(0, name.indexOf('.')); // A cached template is only invalidated if the environment is something // other than `development` and the time-to-live has been exceeded. if (cache[type][name] && (env !== 'development' || cache[type][name]._cached + expires > now)) { return resolve(cache[type][name]); } fs.readFile(filePath, 'utf-8', (error, contents) => { if (error) { return reject(error); } cache[type][name] = hbs.compile(contents.trim()); // Decorate the cached function with private members. The underscore // is necessary to avoid conflict with function's name to prevent all // compiled templates from being named `ret` in the cache. cache[type][name]._name = name; cache[type][name]._cached = timestamp(); return resolve(cache[type][name]); }); }); }
[ "function", "compileTemplate", "(", "baseDir", ",", "filePath", ",", "type", ")", "{", "return", "new", "options", ".", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "let", "now", "=", "timestamp", "(", ")", ";", "let", "name", "=", "filePath", ".", "substring", "(", "baseDir", ".", "length", "+", "1", ")", ".", "replace", "(", "/", "\\\\", "/", "g", ",", "'/'", ")", ";", "name", "=", "name", ".", "substring", "(", "0", ",", "name", ".", "indexOf", "(", "'.'", ")", ")", ";", "// A cached template is only invalidated if the environment is something", "// other than `development` and the time-to-live has been exceeded.", "if", "(", "cache", "[", "type", "]", "[", "name", "]", "&&", "(", "env", "!==", "'development'", "||", "cache", "[", "type", "]", "[", "name", "]", ".", "_cached", "+", "expires", ">", "now", ")", ")", "{", "return", "resolve", "(", "cache", "[", "type", "]", "[", "name", "]", ")", ";", "}", "fs", ".", "readFile", "(", "filePath", ",", "'utf-8'", ",", "(", "error", ",", "contents", ")", "=>", "{", "if", "(", "error", ")", "{", "return", "reject", "(", "error", ")", ";", "}", "cache", "[", "type", "]", "[", "name", "]", "=", "hbs", ".", "compile", "(", "contents", ".", "trim", "(", ")", ")", ";", "// Decorate the cached function with private members. The underscore", "// is necessary to avoid conflict with function's name to prevent all", "// compiled templates from being named `ret` in the cache.", "cache", "[", "type", "]", "[", "name", "]", ".", "_name", "=", "name", ";", "cache", "[", "type", "]", "[", "name", "]", ".", "_cached", "=", "timestamp", "(", ")", ";", "return", "resolve", "(", "cache", "[", "type", "]", "[", "name", "]", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Compiles and caches the template stored at the specified file path, if it exists. Cached templates will be stored in the in-memory cache belonging to the specified template type. @param {String} baseDir The base directory of the templates @param {String} filePath The path of the template to compile @param {String} type The type of template this is @return {Promise.<Function>} @public
[ "Compiles", "and", "caches", "the", "template", "stored", "at", "the", "specified", "file", "path", "if", "it", "exists", ".", "Cached", "templates", "will", "be", "stored", "in", "the", "in", "-", "memory", "cache", "belonging", "to", "the", "specified", "template", "type", "." ]
94cd84585543e157bda40bdbf27c2b4cc3e1ee58
https://github.com/ConnorWiseman/koa-hbs-renderer/blob/94cd84585543e157bda40bdbf27c2b4cc3e1ee58/lib/template-manager.js#L61-L91
44,342
ConnorWiseman/koa-hbs-renderer
lib/template-manager.js
compileTemplates
function compileTemplates(dir, type) { return getPaths(dir, ext, options).then(paths => { return options.Promise.all(paths.map(filePath => { return compileTemplate(dir, filePath, type); })).then(templates => { return templates.reduce((all, current) => { all[current._name] = current; return all; }, {}); }); }); }
javascript
function compileTemplates(dir, type) { return getPaths(dir, ext, options).then(paths => { return options.Promise.all(paths.map(filePath => { return compileTemplate(dir, filePath, type); })).then(templates => { return templates.reduce((all, current) => { all[current._name] = current; return all; }, {}); }); }); }
[ "function", "compileTemplates", "(", "dir", ",", "type", ")", "{", "return", "getPaths", "(", "dir", ",", "ext", ",", "options", ")", ".", "then", "(", "paths", "=>", "{", "return", "options", ".", "Promise", ".", "all", "(", "paths", ".", "map", "(", "filePath", "=>", "{", "return", "compileTemplate", "(", "dir", ",", "filePath", ",", "type", ")", ";", "}", ")", ")", ".", "then", "(", "templates", "=>", "{", "return", "templates", ".", "reduce", "(", "(", "all", ",", "current", ")", "=>", "{", "all", "[", "current", ".", "_name", "]", "=", "current", ";", "return", "all", ";", "}", ",", "{", "}", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Compiles and caches all the templates in the specified directory, if it exists. Returns a Promise for an object map of compiled Handlebars template functions, mapped from the results of compileTemplate above. @param {String} dir The directory to search in @param {String} type The type of templates these are @return {Promise.<Object>} @public
[ "Compiles", "and", "caches", "all", "the", "templates", "in", "the", "specified", "directory", "if", "it", "exists", ".", "Returns", "a", "Promise", "for", "an", "object", "map", "of", "compiled", "Handlebars", "template", "functions", "mapped", "from", "the", "results", "of", "compileTemplate", "above", "." ]
94cd84585543e157bda40bdbf27c2b4cc3e1ee58
https://github.com/ConnorWiseman/koa-hbs-renderer/blob/94cd84585543e157bda40bdbf27c2b4cc3e1ee58/lib/template-manager.js#L103-L114
44,343
alexindigo/configly
parsers.js
jsCompile
function jsCompile(content, file) { // make it as a child of this module // Would be nice to actually make it transparent // and pretend it to be child of the caller module // but there is no obvious way, yet var jsMod = new Module(file, module); // override parents to exclude configly from the chain // it's like this js file is included directly // from the file that included `configly` while (jsMod.parent && typeof jsMod.parent.id === 'string' && jsMod.parent.id.match(/\/node_modules\/configly\//) && jsMod.parent.parent) { /* istanbul ignore next */ jsMod.parent = jsMod.parent.parent; } // generate node_modules paths for the file jsMod.paths = Module._nodeModulePaths(path.dirname(file)); // execute the module jsMod._compile(content, file); // return just exported object return jsMod.exports; }
javascript
function jsCompile(content, file) { // make it as a child of this module // Would be nice to actually make it transparent // and pretend it to be child of the caller module // but there is no obvious way, yet var jsMod = new Module(file, module); // override parents to exclude configly from the chain // it's like this js file is included directly // from the file that included `configly` while (jsMod.parent && typeof jsMod.parent.id === 'string' && jsMod.parent.id.match(/\/node_modules\/configly\//) && jsMod.parent.parent) { /* istanbul ignore next */ jsMod.parent = jsMod.parent.parent; } // generate node_modules paths for the file jsMod.paths = Module._nodeModulePaths(path.dirname(file)); // execute the module jsMod._compile(content, file); // return just exported object return jsMod.exports; }
[ "function", "jsCompile", "(", "content", ",", "file", ")", "{", "// make it as a child of this module", "// Would be nice to actually make it transparent", "// and pretend it to be child of the caller module", "// but there is no obvious way, yet", "var", "jsMod", "=", "new", "Module", "(", "file", ",", "module", ")", ";", "// override parents to exclude configly from the chain", "// it's like this js file is included directly", "// from the file that included `configly`", "while", "(", "jsMod", ".", "parent", "&&", "typeof", "jsMod", ".", "parent", ".", "id", "===", "'string'", "&&", "jsMod", ".", "parent", ".", "id", ".", "match", "(", "/", "\\/node_modules\\/configly\\/", "/", ")", "&&", "jsMod", ".", "parent", ".", "parent", ")", "{", "/* istanbul ignore next */", "jsMod", ".", "parent", "=", "jsMod", ".", "parent", ".", "parent", ";", "}", "// generate node_modules paths for the file", "jsMod", ".", "paths", "=", "Module", ".", "_nodeModulePaths", "(", "path", ".", "dirname", "(", "file", ")", ")", ";", "// execute the module", "jsMod", ".", "_compile", "(", "content", ",", "file", ")", ";", "// return just exported object", "return", "jsMod", ".", "exports", ";", "}" ]
Compiles js content in the manner it's done in the node itself @param {string} content - file's content @param {string} file - full path of the file @returns {mixed} - result javascript object
[ "Compiles", "js", "content", "in", "the", "manner", "it", "s", "done", "in", "the", "node", "itself" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/parsers.js#L19-L45
44,344
sergeche/grunt-frontend
tasks/lib/utils.js
function(dt) { dt = dt || new Date(); return [dt.getFullYear(), padNumber(dt.getMonth() + 1), padNumber(dt.getDate()), padNumber(dt.getHours()), padNumber(dt.getMinutes()), padNumber(dt.getSeconds()) ].join(''); }
javascript
function(dt) { dt = dt || new Date(); return [dt.getFullYear(), padNumber(dt.getMonth() + 1), padNumber(dt.getDate()), padNumber(dt.getHours()), padNumber(dt.getMinutes()), padNumber(dt.getSeconds()) ].join(''); }
[ "function", "(", "dt", ")", "{", "dt", "=", "dt", "||", "new", "Date", "(", ")", ";", "return", "[", "dt", ".", "getFullYear", "(", ")", ",", "padNumber", "(", "dt", ".", "getMonth", "(", ")", "+", "1", ")", ",", "padNumber", "(", "dt", ".", "getDate", "(", ")", ")", ",", "padNumber", "(", "dt", ".", "getHours", "(", ")", ")", ",", "padNumber", "(", "dt", ".", "getMinutes", "(", ")", ")", ",", "padNumber", "(", "dt", ".", "getSeconds", "(", ")", ")", "]", ".", "join", "(", "''", ")", ";", "}" ]
Returns string timestamp of given date in "yyyymmddhhss" format @param {Date} dt Source date. If not specified, current date is used @return {String}
[ "Returns", "string", "timestamp", "of", "given", "date", "in", "yyyymmddhhss", "format" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/utils.js#L60-L69
44,345
sergeche/grunt-frontend
tasks/lib/utils.js
function(file, options) { file = this.absPath(file); var cwd = (options && options.cwd) || ''; if (file.substring(0, cwd.length) == cwd) { file = file.substring(cwd.length); if (file.charAt(0) != '/') { file = '/' + file; } } return file; }
javascript
function(file, options) { file = this.absPath(file); var cwd = (options && options.cwd) || ''; if (file.substring(0, cwd.length) == cwd) { file = file.substring(cwd.length); if (file.charAt(0) != '/') { file = '/' + file; } } return file; }
[ "function", "(", "file", ",", "options", ")", "{", "file", "=", "this", ".", "absPath", "(", "file", ")", ";", "var", "cwd", "=", "(", "options", "&&", "options", ".", "cwd", ")", "||", "''", ";", "if", "(", "file", ".", "substring", "(", "0", ",", "cwd", ".", "length", ")", "==", "cwd", ")", "{", "file", "=", "file", ".", "substring", "(", "cwd", ".", "length", ")", ";", "if", "(", "file", ".", "charAt", "(", "0", ")", "!=", "'/'", ")", "{", "file", "=", "'/'", "+", "file", ";", "}", "}", "return", "file", ";", "}" ]
Returns file path suitable for storing in catalog @param {String} file File path @param {Object} options Options for transforming path @return {String}
[ "Returns", "file", "path", "suitable", "for", "storing", "in", "catalog" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/utils.js#L104-L115
44,346
sergeche/grunt-frontend
tasks/lib/utils.js
function(grunt, task) { var config = task.options(grunt.config.getRaw('frontend') || {}); if (!config.webroot) { return grunt.fail.fatal('You should specify "webroot" property in frontend config', 100); } var cwd = this.absPath(config.cwd || config.webroot); var force = false; if ('force' in config) { force = !!config.force; } return grunt.util._.extend(config, { force: force, cwd: this.absPath(config.cwd || config.webroot), webroot: this.absPath(config.webroot), srcWebroot: this.absPath(config.srcWebroot || config.webroot) }); }
javascript
function(grunt, task) { var config = task.options(grunt.config.getRaw('frontend') || {}); if (!config.webroot) { return grunt.fail.fatal('You should specify "webroot" property in frontend config', 100); } var cwd = this.absPath(config.cwd || config.webroot); var force = false; if ('force' in config) { force = !!config.force; } return grunt.util._.extend(config, { force: force, cwd: this.absPath(config.cwd || config.webroot), webroot: this.absPath(config.webroot), srcWebroot: this.absPath(config.srcWebroot || config.webroot) }); }
[ "function", "(", "grunt", ",", "task", ")", "{", "var", "config", "=", "task", ".", "options", "(", "grunt", ".", "config", ".", "getRaw", "(", "'frontend'", ")", "||", "{", "}", ")", ";", "if", "(", "!", "config", ".", "webroot", ")", "{", "return", "grunt", ".", "fail", ".", "fatal", "(", "'You should specify \"webroot\" property in frontend config'", ",", "100", ")", ";", "}", "var", "cwd", "=", "this", ".", "absPath", "(", "config", ".", "cwd", "||", "config", ".", "webroot", ")", ";", "var", "force", "=", "false", ";", "if", "(", "'force'", "in", "config", ")", "{", "force", "=", "!", "!", "config", ".", "force", ";", "}", "return", "grunt", ".", "util", ".", "_", ".", "extend", "(", "config", ",", "{", "force", ":", "force", ",", "cwd", ":", "this", ".", "absPath", "(", "config", ".", "cwd", "||", "config", ".", "webroot", ")", ",", "webroot", ":", "this", ".", "absPath", "(", "config", ".", "webroot", ")", ",", "srcWebroot", ":", "this", ".", "absPath", "(", "config", ".", "srcWebroot", "||", "config", ".", "webroot", ")", "}", ")", ";", "}" ]
Returns config for currently running grunt task @param {Object} grunt @param {Object} task @return {Object}
[ "Returns", "config", "for", "currently", "running", "grunt", "task" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/utils.js#L133-L151
44,347
sergeche/grunt-frontend
tasks/lib/utils.js
function(url, version, config) { if (!config.rewriteScheme) { return url; } var basename = path.basename(url); var ext = path.extname(url).substr(1); var filename = basename.replace(new RegExp('\\.' + ext + '$'), ''); var data = { url: url, dirname: path.dirname(url), basename: basename, ext: ext, filename: filename, version: version }; if (typeof config.rewriteScheme == 'string') { return _.template(config.rewriteScheme, data); } return config.rewriteScheme(data); }
javascript
function(url, version, config) { if (!config.rewriteScheme) { return url; } var basename = path.basename(url); var ext = path.extname(url).substr(1); var filename = basename.replace(new RegExp('\\.' + ext + '$'), ''); var data = { url: url, dirname: path.dirname(url), basename: basename, ext: ext, filename: filename, version: version }; if (typeof config.rewriteScheme == 'string') { return _.template(config.rewriteScheme, data); } return config.rewriteScheme(data); }
[ "function", "(", "url", ",", "version", ",", "config", ")", "{", "if", "(", "!", "config", ".", "rewriteScheme", ")", "{", "return", "url", ";", "}", "var", "basename", "=", "path", ".", "basename", "(", "url", ")", ";", "var", "ext", "=", "path", ".", "extname", "(", "url", ")", ".", "substr", "(", "1", ")", ";", "var", "filename", "=", "basename", ".", "replace", "(", "new", "RegExp", "(", "'\\\\.'", "+", "ext", "+", "'$'", ")", ",", "''", ")", ";", "var", "data", "=", "{", "url", ":", "url", ",", "dirname", ":", "path", ".", "dirname", "(", "url", ")", ",", "basename", ":", "basename", ",", "ext", ":", "ext", ",", "filename", ":", "filename", ",", "version", ":", "version", "}", ";", "if", "(", "typeof", "config", ".", "rewriteScheme", "==", "'string'", ")", "{", "return", "_", ".", "template", "(", "config", ".", "rewriteScheme", ",", "data", ")", ";", "}", "return", "config", ".", "rewriteScheme", "(", "data", ")", ";", "}" ]
Creates versioned URL from original one @param {String} url Original URL @param {String} version Cache-busting token @param {Object} config @return {String}
[ "Creates", "versioned", "URL", "from", "original", "one" ]
e6552c178651b40f20d4ff2e297bc3efa9446f33
https://github.com/sergeche/grunt-frontend/blob/e6552c178651b40f20d4ff2e297bc3efa9446f33/tasks/lib/utils.js#L160-L183
44,348
p1100i/quadtree2.js
index/vec2.js
function(x, y, silent) { if('number' != typeof x) { silent = y; y = x.y; x = x.x; } if(this.x === x && this.y === y) return this; this.x = Vec2.clean(x); this.y = Vec2.clean(y); if(silent !== false) return this.change(); }
javascript
function(x, y, silent) { if('number' != typeof x) { silent = y; y = x.y; x = x.x; } if(this.x === x && this.y === y) return this; this.x = Vec2.clean(x); this.y = Vec2.clean(y); if(silent !== false) return this.change(); }
[ "function", "(", "x", ",", "y", ",", "silent", ")", "{", "if", "(", "'number'", "!=", "typeof", "x", ")", "{", "silent", "=", "y", ";", "y", "=", "x", ".", "y", ";", "x", "=", "x", ".", "x", ";", "}", "if", "(", "this", ".", "x", "===", "x", "&&", "this", ".", "y", "===", "y", ")", "return", "this", ";", "this", ".", "x", "=", "Vec2", ".", "clean", "(", "x", ")", ";", "this", ".", "y", "=", "Vec2", ".", "clean", "(", "y", ")", ";", "if", "(", "silent", "!==", "false", ")", "return", "this", ".", "change", "(", ")", ";", "}" ]
set x and y
[ "set", "x", "and", "y" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L46-L60
44,349
p1100i/quadtree2.js
index/vec2.js
function(vec2, returnNew) { if (!returnNew) { this.x += vec2.x; this.y += vec2.y; return this.change(); } else { // Return a new vector if `returnNew` is truthy return new Vec2( this.x + vec2.x, this.y + vec2.y ); } }
javascript
function(vec2, returnNew) { if (!returnNew) { this.x += vec2.x; this.y += vec2.y; return this.change(); } else { // Return a new vector if `returnNew` is truthy return new Vec2( this.x + vec2.x, this.y + vec2.y ); } }
[ "function", "(", "vec2", ",", "returnNew", ")", "{", "if", "(", "!", "returnNew", ")", "{", "this", ".", "x", "+=", "vec2", ".", "x", ";", "this", ".", "y", "+=", "vec2", ".", "y", ";", "return", "this", ".", "change", "(", ")", ";", "}", "else", "{", "// Return a new vector if `returnNew` is truthy", "return", "new", "Vec2", "(", "this", ".", "x", "+", "vec2", ".", "x", ",", "this", ".", "y", "+", "vec2", ".", "y", ")", ";", "}", "}" ]
Add the incoming `vec2` vector to this vector
[ "Add", "the", "incoming", "vec2", "vector", "to", "this", "vector" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L83-L94
44,350
p1100i/quadtree2.js
index/vec2.js
function(vec2, returnNew) { var x,y; if ('number' !== typeof vec2) { //.x !== undef) { x = vec2.x; y = vec2.y; // Handle incoming scalars } else { x = y = vec2; } if (!returnNew) { return this.set(this.x * x, this.y * y); } else { return new Vec2( this.x * x, this.y * y ); } }
javascript
function(vec2, returnNew) { var x,y; if ('number' !== typeof vec2) { //.x !== undef) { x = vec2.x; y = vec2.y; // Handle incoming scalars } else { x = y = vec2; } if (!returnNew) { return this.set(this.x * x, this.y * y); } else { return new Vec2( this.x * x, this.y * y ); } }
[ "function", "(", "vec2", ",", "returnNew", ")", "{", "var", "x", ",", "y", ";", "if", "(", "'number'", "!==", "typeof", "vec2", ")", "{", "//.x !== undef) {", "x", "=", "vec2", ".", "x", ";", "y", "=", "vec2", ".", "y", ";", "// Handle incoming scalars", "}", "else", "{", "x", "=", "y", "=", "vec2", ";", "}", "if", "(", "!", "returnNew", ")", "{", "return", "this", ".", "set", "(", "this", ".", "x", "*", "x", ",", "this", ".", "y", "*", "y", ")", ";", "}", "else", "{", "return", "new", "Vec2", "(", "this", ".", "x", "*", "x", ",", "this", ".", "y", "*", "y", ")", ";", "}", "}" ]
Multiply this vector by the incoming `vec2`
[ "Multiply", "this", "vector", "by", "the", "incoming", "vec2" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L111-L130
44,351
p1100i/quadtree2.js
index/vec2.js
function(r, inverse, returnNew) { var x = this.x, y = this.y, cos = Math.cos(r), sin = Math.sin(r), rx, ry; inverse = (inverse) ? -1 : 1; rx = cos * x - (inverse * sin) * y; ry = (inverse * sin) * x + cos * y; if (returnNew) { return new Vec2(rx, ry); } else { return this.set(rx, ry); } }
javascript
function(r, inverse, returnNew) { var x = this.x, y = this.y, cos = Math.cos(r), sin = Math.sin(r), rx, ry; inverse = (inverse) ? -1 : 1; rx = cos * x - (inverse * sin) * y; ry = (inverse * sin) * x + cos * y; if (returnNew) { return new Vec2(rx, ry); } else { return this.set(rx, ry); } }
[ "function", "(", "r", ",", "inverse", ",", "returnNew", ")", "{", "var", "x", "=", "this", ".", "x", ",", "y", "=", "this", ".", "y", ",", "cos", "=", "Math", ".", "cos", "(", "r", ")", ",", "sin", "=", "Math", ".", "sin", "(", "r", ")", ",", "rx", ",", "ry", ";", "inverse", "=", "(", "inverse", ")", "?", "-", "1", ":", "1", ";", "rx", "=", "cos", "*", "x", "-", "(", "inverse", "*", "sin", ")", "*", "y", ";", "ry", "=", "(", "inverse", "*", "sin", ")", "*", "x", "+", "cos", "*", "y", ";", "if", "(", "returnNew", ")", "{", "return", "new", "Vec2", "(", "rx", ",", "ry", ")", ";", "}", "else", "{", "return", "this", ".", "set", "(", "rx", ",", "ry", ")", ";", "}", "}" ]
Rotate this vector. Accepts a `Rotation` or angle in radians. Passing a truthy `inverse` will cause the rotation to be reversed. If `returnNew` is truthy, a new `Vec2` will be created with the values resulting from the rotation. Otherwise the rotation will be applied to this vector directly, and this vector will be returned.
[ "Rotate", "this", "vector", ".", "Accepts", "a", "Rotation", "or", "angle", "in", "radians", ".", "Passing", "a", "truthy", "inverse", "will", "cause", "the", "rotation", "to", "be", "reversed", ".", "If", "returnNew", "is", "truthy", "a", "new", "Vec2", "will", "be", "created", "with", "the", "values", "resulting", "from", "the", "rotation", ".", "Otherwise", "the", "rotation", "will", "be", "applied", "to", "this", "vector", "directly", "and", "this", "vector", "will", "be", "returned", "." ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L141-L159
44,352
p1100i/quadtree2.js
index/vec2.js
function(vec2) { var x = this.x - vec2.x; var y = this.y - vec2.y; return Math.sqrt(x*x + y*y); }
javascript
function(vec2) { var x = this.x - vec2.x; var y = this.y - vec2.y; return Math.sqrt(x*x + y*y); }
[ "function", "(", "vec2", ")", "{", "var", "x", "=", "this", ".", "x", "-", "vec2", ".", "x", ";", "var", "y", "=", "this", ".", "y", "-", "vec2", ".", "y", ";", "return", "Math", ".", "sqrt", "(", "x", "*", "x", "+", "y", "*", "y", ")", ";", "}" ]
Return the distance betwen this `Vec2` and the incoming vec2 vector and return a scalar
[ "Return", "the", "distance", "betwen", "this", "Vec2", "and", "the", "incoming", "vec2", "vector", "and", "return", "a", "scalar" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L175-L179
44,353
p1100i/quadtree2.js
index/vec2.js
function(returnNew) { var length = this.length(); // Collect a ratio to shrink the x and y coords var invertedLength = (length < Number.MIN_VALUE) ? 0 : 1/length; if (!returnNew) { // Convert the coords to be greater than zero // but smaller than or equal to 1.0 return this.set(this.x * invertedLength, this.y * invertedLength); } else { return new Vec2(this.x * invertedLength, this.y * invertedLength); } }
javascript
function(returnNew) { var length = this.length(); // Collect a ratio to shrink the x and y coords var invertedLength = (length < Number.MIN_VALUE) ? 0 : 1/length; if (!returnNew) { // Convert the coords to be greater than zero // but smaller than or equal to 1.0 return this.set(this.x * invertedLength, this.y * invertedLength); } else { return new Vec2(this.x * invertedLength, this.y * invertedLength); } }
[ "function", "(", "returnNew", ")", "{", "var", "length", "=", "this", ".", "length", "(", ")", ";", "// Collect a ratio to shrink the x and y coords", "var", "invertedLength", "=", "(", "length", "<", "Number", ".", "MIN_VALUE", ")", "?", "0", ":", "1", "/", "length", ";", "if", "(", "!", "returnNew", ")", "{", "// Convert the coords to be greater than zero", "// but smaller than or equal to 1.0", "return", "this", ".", "set", "(", "this", ".", "x", "*", "invertedLength", ",", "this", ".", "y", "*", "invertedLength", ")", ";", "}", "else", "{", "return", "new", "Vec2", "(", "this", ".", "x", "*", "invertedLength", ",", "this", ".", "y", "*", "invertedLength", ")", ";", "}", "}" ]
Convert this vector into a unit vector. Returns the length.
[ "Convert", "this", "vector", "into", "a", "unit", "vector", ".", "Returns", "the", "length", "." ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L183-L196
44,354
p1100i/quadtree2.js
index/vec2.js
function(v, w) { if (w === undef) { w = v.y; v = v.x; } return (Vec2.clean(v) === this.x && Vec2.clean(w) === this.y); }
javascript
function(v, w) { if (w === undef) { w = v.y; v = v.x; } return (Vec2.clean(v) === this.x && Vec2.clean(w) === this.y); }
[ "function", "(", "v", ",", "w", ")", "{", "if", "(", "w", "===", "undef", ")", "{", "w", "=", "v", ".", "y", ";", "v", "=", "v", ".", "x", ";", "}", "return", "(", "Vec2", ".", "clean", "(", "v", ")", "===", "this", ".", "x", "&&", "Vec2", ".", "clean", "(", "w", ")", "===", "this", ".", "y", ")", ";", "}" ]
Determine if another `Vec2`'s components match this one's also accepts 2 scalars
[ "Determine", "if", "another", "Vec2", "s", "components", "match", "this", "one", "s", "also", "accepts", "2", "scalars" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L200-L207
44,355
p1100i/quadtree2.js
index/vec2.js
function(returnNew) { var x = Math.abs(this.x), y = Math.abs(this.y); if (returnNew) { return new Vec2(x, y); } else { return this.set(x, y); } }
javascript
function(returnNew) { var x = Math.abs(this.x), y = Math.abs(this.y); if (returnNew) { return new Vec2(x, y); } else { return this.set(x, y); } }
[ "function", "(", "returnNew", ")", "{", "var", "x", "=", "Math", ".", "abs", "(", "this", ".", "x", ")", ",", "y", "=", "Math", ".", "abs", "(", "this", ".", "y", ")", ";", "if", "(", "returnNew", ")", "{", "return", "new", "Vec2", "(", "x", ",", "y", ")", ";", "}", "else", "{", "return", "this", ".", "set", "(", "x", ",", "y", ")", ";", "}", "}" ]
Return a new `Vec2` that contains the absolute value of each of this vector's parts
[ "Return", "a", "new", "Vec2", "that", "contains", "the", "absolute", "value", "of", "each", "of", "this", "vector", "s", "parts" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L211-L219
44,356
p1100i/quadtree2.js
index/vec2.js
function(v, returnNew) { var tx = this.x, ty = this.y, vx = v.x, vy = v.y, x = tx < vx ? tx : vx, y = ty < vy ? ty : vy; if (returnNew) { return new Vec2(x, y); } else { return this.set(x, y); } }
javascript
function(v, returnNew) { var tx = this.x, ty = this.y, vx = v.x, vy = v.y, x = tx < vx ? tx : vx, y = ty < vy ? ty : vy; if (returnNew) { return new Vec2(x, y); } else { return this.set(x, y); } }
[ "function", "(", "v", ",", "returnNew", ")", "{", "var", "tx", "=", "this", ".", "x", ",", "ty", "=", "this", ".", "y", ",", "vx", "=", "v", ".", "x", ",", "vy", "=", "v", ".", "y", ",", "x", "=", "tx", "<", "vx", "?", "tx", ":", "vx", ",", "y", "=", "ty", "<", "vy", "?", "ty", ":", "vy", ";", "if", "(", "returnNew", ")", "{", "return", "new", "Vec2", "(", "x", ",", "y", ")", ";", "}", "else", "{", "return", "this", ".", "set", "(", "x", ",", "y", ")", ";", "}", "}" ]
Return a new `Vec2` consisting of the smallest values from this vector and the incoming When returnNew is truthy, a new `Vec2` will be returned otherwise the minimum values in either this or `v` will be applied to this vector.
[ "Return", "a", "new", "Vec2", "consisting", "of", "the", "smallest", "values", "from", "this", "vector", "and", "the", "incoming", "When", "returnNew", "is", "truthy", "a", "new", "Vec2", "will", "be", "returned", "otherwise", "the", "minimum", "values", "in", "either", "this", "or", "v", "will", "be", "applied", "to", "this", "vector", "." ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L227-L241
44,357
p1100i/quadtree2.js
index/vec2.js
function(low, high, returnNew) { var ret = this.min(high, true).max(low); if (returnNew) { return ret; } else { return this.set(ret.x, ret.y); } }
javascript
function(low, high, returnNew) { var ret = this.min(high, true).max(low); if (returnNew) { return ret; } else { return this.set(ret.x, ret.y); } }
[ "function", "(", "low", ",", "high", ",", "returnNew", ")", "{", "var", "ret", "=", "this", ".", "min", "(", "high", ",", "true", ")", ".", "max", "(", "low", ")", ";", "if", "(", "returnNew", ")", "{", "return", "ret", ";", "}", "else", "{", "return", "this", ".", "set", "(", "ret", ".", "x", ",", "ret", ".", "y", ")", ";", "}", "}" ]
Clamp values into a range. If this vector's values are lower than the `low`'s values, then raise them. If they are higher than `high`'s then lower them. Passing returnNew as true will cause a new Vec2 to be returned. Otherwise, this vector's values will be clamped
[ "Clamp", "values", "into", "a", "range", ".", "If", "this", "vector", "s", "values", "are", "lower", "than", "the", "low", "s", "values", "then", "raise", "them", ".", "If", "they", "are", "higher", "than", "high", "s", "then", "lower", "them", ".", "Passing", "returnNew", "as", "true", "will", "cause", "a", "new", "Vec2", "to", "be", "returned", ".", "Otherwise", "this", "vector", "s", "values", "will", "be", "clamped" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L272-L279
44,358
p1100i/quadtree2.js
index/vec2.js
function(vec2, returnNew) { var x,y; if ('number' !== typeof vec2) { x = vec2.x; y = vec2.y; // Handle incoming scalars } else { x = y = vec2; } if (x === 0 || y === 0) { throw new Error('division by zero') } if (isNaN(x) || isNaN(y)) { throw new Error('NaN detected'); } if (returnNew) { return new Vec2(this.x / x, this.y / y); } return this.set(this.x / x, this.y / y); }
javascript
function(vec2, returnNew) { var x,y; if ('number' !== typeof vec2) { x = vec2.x; y = vec2.y; // Handle incoming scalars } else { x = y = vec2; } if (x === 0 || y === 0) { throw new Error('division by zero') } if (isNaN(x) || isNaN(y)) { throw new Error('NaN detected'); } if (returnNew) { return new Vec2(this.x / x, this.y / y); } return this.set(this.x / x, this.y / y); }
[ "function", "(", "vec2", ",", "returnNew", ")", "{", "var", "x", ",", "y", ";", "if", "(", "'number'", "!==", "typeof", "vec2", ")", "{", "x", "=", "vec2", ".", "x", ";", "y", "=", "vec2", ".", "y", ";", "// Handle incoming scalars", "}", "else", "{", "x", "=", "y", "=", "vec2", ";", "}", "if", "(", "x", "===", "0", "||", "y", "===", "0", ")", "{", "throw", "new", "Error", "(", "'division by zero'", ")", "}", "if", "(", "isNaN", "(", "x", ")", "||", "isNaN", "(", "y", ")", ")", "{", "throw", "new", "Error", "(", "'NaN detected'", ")", ";", "}", "if", "(", "returnNew", ")", "{", "return", "new", "Vec2", "(", "this", ".", "x", "/", "x", ",", "this", ".", "y", "/", "y", ")", ";", "}", "return", "this", ".", "set", "(", "this", ".", "x", "/", "x", ",", "this", ".", "y", "/", "y", ")", ";", "}" ]
Divide this vector's components by a scalar
[ "Divide", "this", "vector", "s", "components", "by", "a", "scalar" ]
c44dc648a7cb5a0dd98d5e8240ef423f10135445
https://github.com/p1100i/quadtree2.js/blob/c44dc648a7cb5a0dd98d5e8240ef423f10135445/index/vec2.js#L311-L335
44,359
alexindigo/configly
modifiers.js
json
function json(value) { var parsedPojo; try { parsedPojo = JSON.parse(value); } catch(e) { return throwModifierError('json', value, e); } return parsedPojo; }
javascript
function json(value) { var parsedPojo; try { parsedPojo = JSON.parse(value); } catch(e) { return throwModifierError('json', value, e); } return parsedPojo; }
[ "function", "json", "(", "value", ")", "{", "var", "parsedPojo", ";", "try", "{", "parsedPojo", "=", "JSON", ".", "parse", "(", "value", ")", ";", "}", "catch", "(", "e", ")", "{", "return", "throwModifierError", "(", "'json'", ",", "value", ",", "e", ")", ";", "}", "return", "parsedPojo", ";", "}" ]
Parses provided string as JSON string @param {string} value - Date string to parse @returns {object} - Parsed JSON POJO
[ "Parses", "provided", "string", "as", "JSON", "string" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/modifiers.js#L44-L54
44,360
alexindigo/configly
modifiers.js
date
function date(value) { var parsedDate = Date.parse(value); // couldn't parse it if (typeOf(parsedDate) != 'number') { return throwModifierError('date', value, {message: 'Invalid Date'}); } return new Date(parsedDate); }
javascript
function date(value) { var parsedDate = Date.parse(value); // couldn't parse it if (typeOf(parsedDate) != 'number') { return throwModifierError('date', value, {message: 'Invalid Date'}); } return new Date(parsedDate); }
[ "function", "date", "(", "value", ")", "{", "var", "parsedDate", "=", "Date", ".", "parse", "(", "value", ")", ";", "// couldn't parse it", "if", "(", "typeOf", "(", "parsedDate", ")", "!=", "'number'", ")", "{", "return", "throwModifierError", "(", "'date'", ",", "value", ",", "{", "message", ":", "'Invalid Date'", "}", ")", ";", "}", "return", "new", "Date", "(", "parsedDate", ")", ";", "}" ]
Parses provided string as a Date string @param {string} value - Date string to parse @returns {Date} - Date object representaion of the provided string
[ "Parses", "provided", "string", "as", "a", "Date", "string" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/modifiers.js#L62-L71
44,361
alexindigo/configly
modifiers.js
float
function float(value) { var parsedFloat = Number.parseFloat(value); // couldn't parse it if (typeOf(parsedFloat) != 'number') { return throwModifierError('float', value, {message: 'Invalid Float'}); } return parsedFloat; }
javascript
function float(value) { var parsedFloat = Number.parseFloat(value); // couldn't parse it if (typeOf(parsedFloat) != 'number') { return throwModifierError('float', value, {message: 'Invalid Float'}); } return parsedFloat; }
[ "function", "float", "(", "value", ")", "{", "var", "parsedFloat", "=", "Number", ".", "parseFloat", "(", "value", ")", ";", "// couldn't parse it", "if", "(", "typeOf", "(", "parsedFloat", ")", "!=", "'number'", ")", "{", "return", "throwModifierError", "(", "'float'", ",", "value", ",", "{", "message", ":", "'Invalid Float'", "}", ")", ";", "}", "return", "parsedFloat", ";", "}" ]
Parses provided string as Float @param {string} value - string to parse @returns {float} - Parsed float number
[ "Parses", "provided", "string", "as", "Float" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/modifiers.js#L96-L105
44,362
joshwcomeau/redux-favicon
src/favicon-middleware.js
favicoIntegration
function favicoIntegration(options = defaultFavicoOptions) { // Create a new Favico integration. // Initially this was going to be a singleton object, but I realized there // may be cases where you want several different types of notifications. // The middleware does not yet support multiple instances, but it should // be easy to add if there's demand :) // // Not using the constructor pattern, because it obfuscates JS' prototypal // nature, and there's no need for inheritance here, so this is equivalent. const favico = new Favico(options); return { currentVal: 0, update(value, callback) { if ( typeof value === 'number' ) { // Don't allow non-integer values if ( value % 1 !== 0 ) { return callback(` Warning: Favico not affected. You provided a floating-point value: ${value}. You need to provide an integer, or a keyword value. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } this.currentVal = value; } else if ( typeof value === 'string' ) { switch ( value.toLowerCase() ) { case 'increment': this.currentVal++; break; case 'decrement': this.currentVal--; break; case 'reset': this.currentVal=0; break; default: return callback(` Warning: Favico not affected. You provided a string value: ${value}. The only strings we accept are: ${favicoEnumValues.join(', ')}. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } } else { // Annoyingly, istanbul won't give me 100% coverage unless all possible // typeof values are checked. It is not possible for all types to make // it to this check; `undefined` aborts earlier. /* istanbul ignore next */ const provided_type = typeof value; return callback(` Warning: Favico provided an illegal type. You provided a a value of type: ${provided_type}. We only accept integers or strings. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } // Don't allow negative numbers this.currentVal = ( this.currentVal < 0 ) ? 0 : this.currentVal; // Set the 'badge' to be our derived value. // The favico.js library will show it if it's truthy, hide it if falsy. favico.badge(this.currentVal); return callback(); } }; }
javascript
function favicoIntegration(options = defaultFavicoOptions) { // Create a new Favico integration. // Initially this was going to be a singleton object, but I realized there // may be cases where you want several different types of notifications. // The middleware does not yet support multiple instances, but it should // be easy to add if there's demand :) // // Not using the constructor pattern, because it obfuscates JS' prototypal // nature, and there's no need for inheritance here, so this is equivalent. const favico = new Favico(options); return { currentVal: 0, update(value, callback) { if ( typeof value === 'number' ) { // Don't allow non-integer values if ( value % 1 !== 0 ) { return callback(` Warning: Favico not affected. You provided a floating-point value: ${value}. You need to provide an integer, or a keyword value. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } this.currentVal = value; } else if ( typeof value === 'string' ) { switch ( value.toLowerCase() ) { case 'increment': this.currentVal++; break; case 'decrement': this.currentVal--; break; case 'reset': this.currentVal=0; break; default: return callback(` Warning: Favico not affected. You provided a string value: ${value}. The only strings we accept are: ${favicoEnumValues.join(', ')}. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } } else { // Annoyingly, istanbul won't give me 100% coverage unless all possible // typeof values are checked. It is not possible for all types to make // it to this check; `undefined` aborts earlier. /* istanbul ignore next */ const provided_type = typeof value; return callback(` Warning: Favico provided an illegal type. You provided a a value of type: ${provided_type}. We only accept integers or strings. See https://github.com/joshwcomeau/redux-favicon#troubleshooting for more information. `); } // Don't allow negative numbers this.currentVal = ( this.currentVal < 0 ) ? 0 : this.currentVal; // Set the 'badge' to be our derived value. // The favico.js library will show it if it's truthy, hide it if falsy. favico.badge(this.currentVal); return callback(); } }; }
[ "function", "favicoIntegration", "(", "options", "=", "defaultFavicoOptions", ")", "{", "// Create a new Favico integration.", "// Initially this was going to be a singleton object, but I realized there", "// may be cases where you want several different types of notifications.", "// The middleware does not yet support multiple instances, but it should", "// be easy to add if there's demand :)", "//", "// Not using the constructor pattern, because it obfuscates JS' prototypal", "// nature, and there's no need for inheritance here, so this is equivalent.", "const", "favico", "=", "new", "Favico", "(", "options", ")", ";", "return", "{", "currentVal", ":", "0", ",", "update", "(", "value", ",", "callback", ")", "{", "if", "(", "typeof", "value", "===", "'number'", ")", "{", "// Don't allow non-integer values", "if", "(", "value", "%", "1", "!==", "0", ")", "{", "return", "callback", "(", "`", "${", "value", "}", "`", ")", ";", "}", "this", ".", "currentVal", "=", "value", ";", "}", "else", "if", "(", "typeof", "value", "===", "'string'", ")", "{", "switch", "(", "value", ".", "toLowerCase", "(", ")", ")", "{", "case", "'increment'", ":", "this", ".", "currentVal", "++", ";", "break", ";", "case", "'decrement'", ":", "this", ".", "currentVal", "--", ";", "break", ";", "case", "'reset'", ":", "this", ".", "currentVal", "=", "0", ";", "break", ";", "default", ":", "return", "callback", "(", "`", "${", "value", "}", "${", "favicoEnumValues", ".", "join", "(", "', '", ")", "}", "`", ")", ";", "}", "}", "else", "{", "// Annoyingly, istanbul won't give me 100% coverage unless all possible", "// typeof values are checked. It is not possible for all types to make", "// it to this check; `undefined` aborts earlier.", "/* istanbul ignore next */", "const", "provided_type", "=", "typeof", "value", ";", "return", "callback", "(", "`", "${", "provided_type", "}", "`", ")", ";", "}", "// Don't allow negative numbers", "this", ".", "currentVal", "=", "(", "this", ".", "currentVal", "<", "0", ")", "?", "0", ":", "this", ".", "currentVal", ";", "// Set the 'badge' to be our derived value.", "// The favico.js library will show it if it's truthy, hide it if falsy.", "favico", ".", "badge", "(", "this", ".", "currentVal", ")", ";", "return", "callback", "(", ")", ";", "}", "}", ";", "}" ]
This integration communicates directly with Favico.js to set the badge.
[ "This", "integration", "communicates", "directly", "with", "Favico", ".", "js", "to", "set", "the", "badge", "." ]
655f9810f9745bc9e44c1b827e4653e24660a7b6
https://github.com/joshwcomeau/redux-favicon/blob/655f9810f9745bc9e44c1b827e4653e24660a7b6/src/favicon-middleware.js#L38-L108
44,363
alexindigo/configly
lib/parse_tokens.js
parseTokens
function parseTokens(entry, env) { var found = 0; if (entry.indexOf('${') > -1) { entry = entry.replace(/\$\{([^}]+)\}/g, function(match, token) { var value = getVar.call(this, token, env); // need to have `found` counter // to see if any of the variables // in the string were resolved if (hasValue(value)) { found++; } return value; }.bind(this)); } // reset entry if no variables were resolved if (!found) entry = ''; return entry; }
javascript
function parseTokens(entry, env) { var found = 0; if (entry.indexOf('${') > -1) { entry = entry.replace(/\$\{([^}]+)\}/g, function(match, token) { var value = getVar.call(this, token, env); // need to have `found` counter // to see if any of the variables // in the string were resolved if (hasValue(value)) { found++; } return value; }.bind(this)); } // reset entry if no variables were resolved if (!found) entry = ''; return entry; }
[ "function", "parseTokens", "(", "entry", ",", "env", ")", "{", "var", "found", "=", "0", ";", "if", "(", "entry", ".", "indexOf", "(", "'${'", ")", ">", "-", "1", ")", "{", "entry", "=", "entry", ".", "replace", "(", "/", "\\$\\{([^}]+)\\}", "/", "g", ",", "function", "(", "match", ",", "token", ")", "{", "var", "value", "=", "getVar", ".", "call", "(", "this", ",", "token", ",", "env", ")", ";", "// need to have `found` counter", "// to see if any of the variables", "// in the string were resolved", "if", "(", "hasValue", "(", "value", ")", ")", "{", "found", "++", ";", "}", "return", "value", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}", "// reset entry if no variables were resolved", "if", "(", "!", "found", ")", "entry", "=", "''", ";", "return", "entry", ";", "}" ]
Parses provided config entry to find variable placeholders and replace them with values @param {string} entry - string to parse @param {object} env - object to search within @returns {string|boolean} - replaced string or empty string if no matching variables found
[ "Parses", "provided", "config", "entry", "to", "find", "variable", "placeholders", "and", "replace", "them", "with", "values" ]
026423ba0e036cf8ca33cd2fd160df519715272d
https://github.com/alexindigo/configly/blob/026423ba0e036cf8ca33cd2fd160df519715272d/lib/parse_tokens.js#L18-L44
44,364
Deathspike/npm-build-tools
src/utilities/cmd.js
globs
function globs(sourcePath, ignore, commands, done) { var expression = /\$g\[(.+?)\]/g; var result = []; each(commands, function(command, next) { var map = {}; var match; var matches = []; while ((match = expression.exec(command))) matches.push(match); each(matches, function(patternMatch, next) { find(patternMatch[1], sourcePath, ignore, function(err, relativePaths) { if (err) return next(err); map[patternMatch[1]] = relativePaths; next(); }); }, function(err) { if (err) return next(err); result.push(command.replace(expression, function(match, matchKey) { return map[matchKey].join(' '); })); next(); }); }, function(err) { if (err) return done(err); done(undefined, result); }); }
javascript
function globs(sourcePath, ignore, commands, done) { var expression = /\$g\[(.+?)\]/g; var result = []; each(commands, function(command, next) { var map = {}; var match; var matches = []; while ((match = expression.exec(command))) matches.push(match); each(matches, function(patternMatch, next) { find(patternMatch[1], sourcePath, ignore, function(err, relativePaths) { if (err) return next(err); map[patternMatch[1]] = relativePaths; next(); }); }, function(err) { if (err) return next(err); result.push(command.replace(expression, function(match, matchKey) { return map[matchKey].join(' '); })); next(); }); }, function(err) { if (err) return done(err); done(undefined, result); }); }
[ "function", "globs", "(", "sourcePath", ",", "ignore", ",", "commands", ",", "done", ")", "{", "var", "expression", "=", "/", "\\$g\\[(.+?)\\]", "/", "g", ";", "var", "result", "=", "[", "]", ";", "each", "(", "commands", ",", "function", "(", "command", ",", "next", ")", "{", "var", "map", "=", "{", "}", ";", "var", "match", ";", "var", "matches", "=", "[", "]", ";", "while", "(", "(", "match", "=", "expression", ".", "exec", "(", "command", ")", ")", ")", "matches", ".", "push", "(", "match", ")", ";", "each", "(", "matches", ",", "function", "(", "patternMatch", ",", "next", ")", "{", "find", "(", "patternMatch", "[", "1", "]", ",", "sourcePath", ",", "ignore", ",", "function", "(", "err", ",", "relativePaths", ")", "{", "if", "(", "err", ")", "return", "next", "(", "err", ")", ";", "map", "[", "patternMatch", "[", "1", "]", "]", "=", "relativePaths", ";", "next", "(", ")", ";", "}", ")", ";", "}", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "next", "(", "err", ")", ";", "result", ".", "push", "(", "command", ".", "replace", "(", "expression", ",", "function", "(", "match", ",", "matchKey", ")", "{", "return", "map", "[", "matchKey", "]", ".", "join", "(", "' '", ")", ";", "}", ")", ")", ";", "next", "(", ")", ";", "}", ")", ";", "}", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "done", "(", "err", ")", ";", "done", "(", "undefined", ",", "result", ")", ";", "}", ")", ";", "}" ]
Iterates through each command and expands each glob pattern. @param {string} sourcePath @param {Array.<string>} commands @param {function(Error, Array.<string>=)} done
[ "Iterates", "through", "each", "command", "and", "expands", "each", "glob", "pattern", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/utilities/cmd.js#L35-L60
44,365
Deathspike/npm-build-tools
src/utilities/cmd.js
loadConfig
function loadConfig(done) { fs.stat('package.json', function(err) { if (err) return done(undefined, {}); fs.readFile('package.json', function(err, contents) { if (err) return done(err); try { done(undefined, JSON.parse(contents).config || {}); } catch(err) { done(err); } }); }); }
javascript
function loadConfig(done) { fs.stat('package.json', function(err) { if (err) return done(undefined, {}); fs.readFile('package.json', function(err, contents) { if (err) return done(err); try { done(undefined, JSON.parse(contents).config || {}); } catch(err) { done(err); } }); }); }
[ "function", "loadConfig", "(", "done", ")", "{", "fs", ".", "stat", "(", "'package.json'", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "done", "(", "undefined", ",", "{", "}", ")", ";", "fs", ".", "readFile", "(", "'package.json'", ",", "function", "(", "err", ",", "contents", ")", "{", "if", "(", "err", ")", "return", "done", "(", "err", ")", ";", "try", "{", "done", "(", "undefined", ",", "JSON", ".", "parse", "(", "contents", ")", ".", "config", "||", "{", "}", ")", ";", "}", "catch", "(", "err", ")", "{", "done", "(", "err", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Loads the configuration. @param {function(Error, Object=)}
[ "Loads", "the", "configuration", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/utilities/cmd.js#L66-L78
44,366
Deathspike/npm-build-tools
src/utilities/cmd.js
loadOptions
function loadOptions(entries) { var options = new Command().version(require('../../package').version); entries.forEach(function(entry) { options.option(entry.option, entry.text, entry.parse); }); return options.parse(process.argv); }
javascript
function loadOptions(entries) { var options = new Command().version(require('../../package').version); entries.forEach(function(entry) { options.option(entry.option, entry.text, entry.parse); }); return options.parse(process.argv); }
[ "function", "loadOptions", "(", "entries", ")", "{", "var", "options", "=", "new", "Command", "(", ")", ".", "version", "(", "require", "(", "'../../package'", ")", ".", "version", ")", ";", "entries", ".", "forEach", "(", "function", "(", "entry", ")", "{", "options", ".", "option", "(", "entry", ".", "option", ",", "entry", ".", "text", ",", "entry", ".", "parse", ")", ";", "}", ")", ";", "return", "options", ".", "parse", "(", "process", ".", "argv", ")", ";", "}" ]
Loads the options. @param {Array.<{option: string, text: string}>} entries @returns {Object.<string, *>}
[ "Loads", "the", "options", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/utilities/cmd.js#L85-L91
44,367
Deathspike/npm-build-tools
src/utilities/cmd.js
variables
function variables(root, config, done) { var expression = /\$v\[(.+?)\]/g; each(Object.keys(root), function(key, next) { var value = root[key]; if (typeof value === 'object') return variables(value, config, next); if (typeof value !== 'string') return next(); root[key] = value.replace(expression, function(match, matchKey) { return config[matchKey] || match; }); next(); }, done); }
javascript
function variables(root, config, done) { var expression = /\$v\[(.+?)\]/g; each(Object.keys(root), function(key, next) { var value = root[key]; if (typeof value === 'object') return variables(value, config, next); if (typeof value !== 'string') return next(); root[key] = value.replace(expression, function(match, matchKey) { return config[matchKey] || match; }); next(); }, done); }
[ "function", "variables", "(", "root", ",", "config", ",", "done", ")", "{", "var", "expression", "=", "/", "\\$v\\[(.+?)\\]", "/", "g", ";", "each", "(", "Object", ".", "keys", "(", "root", ")", ",", "function", "(", "key", ",", "next", ")", "{", "var", "value", "=", "root", "[", "key", "]", ";", "if", "(", "typeof", "value", "===", "'object'", ")", "return", "variables", "(", "value", ",", "config", ",", "next", ")", ";", "if", "(", "typeof", "value", "!==", "'string'", ")", "return", "next", "(", ")", ";", "root", "[", "key", "]", "=", "value", ".", "replace", "(", "expression", ",", "function", "(", "match", ",", "matchKey", ")", "{", "return", "config", "[", "matchKey", "]", "||", "match", ";", "}", ")", ";", "next", "(", ")", ";", "}", ",", "done", ")", ";", "}" ]
Expands each variable. @param {Object} root @param {Object.<string, string>} config @param {function()} done
[ "Expands", "each", "variable", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/utilities/cmd.js#L99-L110
44,368
aheckmann/observed
lib/observed.js
Observable
function Observable (subject, parent, prefix) { if ('object' != typeof subject) throw new TypeError('object expected. got: ' + typeof subject); if (!(this instanceof Observable)) return new Observable(subject, parent, prefix); debug('new', subject, !!parent, prefix); Emitter.call(this); this._bind(subject, parent, prefix); }
javascript
function Observable (subject, parent, prefix) { if ('object' != typeof subject) throw new TypeError('object expected. got: ' + typeof subject); if (!(this instanceof Observable)) return new Observable(subject, parent, prefix); debug('new', subject, !!parent, prefix); Emitter.call(this); this._bind(subject, parent, prefix); }
[ "function", "Observable", "(", "subject", ",", "parent", ",", "prefix", ")", "{", "if", "(", "'object'", "!=", "typeof", "subject", ")", "throw", "new", "TypeError", "(", "'object expected. got: '", "+", "typeof", "subject", ")", ";", "if", "(", "!", "(", "this", "instanceof", "Observable", ")", ")", "return", "new", "Observable", "(", "subject", ",", "parent", ",", "prefix", ")", ";", "debug", "(", "'new'", ",", "subject", ",", "!", "!", "parent", ",", "prefix", ")", ";", "Emitter", ".", "call", "(", "this", ")", ";", "this", ".", "_bind", "(", "subject", ",", "parent", ",", "prefix", ")", ";", "}" ]
Observable constructor. The passed `subject` will be observed for changes to all properties, included nested objects and arrays. An `EventEmitter` will be returned. This emitter will emit the following events: - add - update - delete - reconfigure // - setPrototype? @param {Object} subject @param {Observable} [parent] (internal use) @param {String} [prefix] (internal use) @return {EventEmitter}
[ "Observable", "constructor", "." ]
834ddd5be149aeb2b1ee9ce231cf3e836b9ea4bf
https://github.com/aheckmann/observed/blob/834ddd5be149aeb2b1ee9ce231cf3e836b9ea4bf/lib/observed.js#L31-L42
44,369
http-auth/apache-md5
src/index.js
to64
function to64(index, count) { let result = ''; while (--count >= 0) { // Result char count. result += itoa64[index & 63]; // Get corresponding char. index = index >> 6; // Move to next one. } return result; }
javascript
function to64(index, count) { let result = ''; while (--count >= 0) { // Result char count. result += itoa64[index & 63]; // Get corresponding char. index = index >> 6; // Move to next one. } return result; }
[ "function", "to64", "(", "index", ",", "count", ")", "{", "let", "result", "=", "''", ";", "while", "(", "--", "count", ">=", "0", ")", "{", "// Result char count.", "result", "+=", "itoa64", "[", "index", "&", "63", "]", ";", "// Get corresponding char.", "index", "=", "index", ">>", "6", ";", "// Move to next one.", "}", "return", "result", ";", "}" ]
To 64 bit version.
[ "To", "64", "bit", "version", "." ]
27aa6364d50eeb93dfaf0b2a090c0cf035b32b49
https://github.com/http-auth/apache-md5/blob/27aa6364d50eeb93dfaf0b2a090c0cf035b32b49/src/index.js#L10-L19
44,370
http-auth/apache-md5
src/index.js
getSalt
function getSalt(inputSalt) { let salt = ''; if (inputSalt) { // Remove $apr1$ token and extract salt. salt = inputSalt.split('$')[2]; } else { while(salt.length < 8) { // Random 8 chars. let rchIndex = Math.floor((Math.random() * 64)); salt += itoa64[rchIndex]; } } return salt; }
javascript
function getSalt(inputSalt) { let salt = ''; if (inputSalt) { // Remove $apr1$ token and extract salt. salt = inputSalt.split('$')[2]; } else { while(salt.length < 8) { // Random 8 chars. let rchIndex = Math.floor((Math.random() * 64)); salt += itoa64[rchIndex]; } } return salt; }
[ "function", "getSalt", "(", "inputSalt", ")", "{", "let", "salt", "=", "''", ";", "if", "(", "inputSalt", ")", "{", "// Remove $apr1$ token and extract salt.", "salt", "=", "inputSalt", ".", "split", "(", "'$'", ")", "[", "2", "]", ";", "}", "else", "{", "while", "(", "salt", ".", "length", "<", "8", ")", "{", "// Random 8 chars.", "let", "rchIndex", "=", "Math", ".", "floor", "(", "(", "Math", ".", "random", "(", ")", "*", "64", ")", ")", ";", "salt", "+=", "itoa64", "[", "rchIndex", "]", ";", "}", "}", "return", "salt", ";", "}" ]
Returns salt.
[ "Returns", "salt", "." ]
27aa6364d50eeb93dfaf0b2a090c0cf035b32b49
https://github.com/http-auth/apache-md5/blob/27aa6364d50eeb93dfaf0b2a090c0cf035b32b49/src/index.js#L22-L36
44,371
http-auth/apache-md5
src/index.js
getPassword
function getPassword(final) { // Encrypted pass. let epass = ''; epass += to64((final.charCodeAt(0) << 16) | (final.charCodeAt(6) << 8) | final.charCodeAt(12), 4); epass += to64((final.charCodeAt(1) << 16) | (final.charCodeAt(7) << 8) | final.charCodeAt(13), 4); epass += to64((final.charCodeAt(2) << 16) | (final.charCodeAt(8) << 8) | final.charCodeAt(14), 4); epass += to64((final.charCodeAt(3) << 16) | (final.charCodeAt(9) << 8) | final.charCodeAt(15), 4); epass += to64((final.charCodeAt(4) << 16) | (final.charCodeAt(10) << 8) | final.charCodeAt(5), 4); epass += to64(final.charCodeAt(11), 2); return epass; }
javascript
function getPassword(final) { // Encrypted pass. let epass = ''; epass += to64((final.charCodeAt(0) << 16) | (final.charCodeAt(6) << 8) | final.charCodeAt(12), 4); epass += to64((final.charCodeAt(1) << 16) | (final.charCodeAt(7) << 8) | final.charCodeAt(13), 4); epass += to64((final.charCodeAt(2) << 16) | (final.charCodeAt(8) << 8) | final.charCodeAt(14), 4); epass += to64((final.charCodeAt(3) << 16) | (final.charCodeAt(9) << 8) | final.charCodeAt(15), 4); epass += to64((final.charCodeAt(4) << 16) | (final.charCodeAt(10) << 8) | final.charCodeAt(5), 4); epass += to64(final.charCodeAt(11), 2); return epass; }
[ "function", "getPassword", "(", "final", ")", "{", "// Encrypted pass.", "let", "epass", "=", "''", ";", "epass", "+=", "to64", "(", "(", "final", ".", "charCodeAt", "(", "0", ")", "<<", "16", ")", "|", "(", "final", ".", "charCodeAt", "(", "6", ")", "<<", "8", ")", "|", "final", ".", "charCodeAt", "(", "12", ")", ",", "4", ")", ";", "epass", "+=", "to64", "(", "(", "final", ".", "charCodeAt", "(", "1", ")", "<<", "16", ")", "|", "(", "final", ".", "charCodeAt", "(", "7", ")", "<<", "8", ")", "|", "final", ".", "charCodeAt", "(", "13", ")", ",", "4", ")", ";", "epass", "+=", "to64", "(", "(", "final", ".", "charCodeAt", "(", "2", ")", "<<", "16", ")", "|", "(", "final", ".", "charCodeAt", "(", "8", ")", "<<", "8", ")", "|", "final", ".", "charCodeAt", "(", "14", ")", ",", "4", ")", ";", "epass", "+=", "to64", "(", "(", "final", ".", "charCodeAt", "(", "3", ")", "<<", "16", ")", "|", "(", "final", ".", "charCodeAt", "(", "9", ")", "<<", "8", ")", "|", "final", ".", "charCodeAt", "(", "15", ")", ",", "4", ")", ";", "epass", "+=", "to64", "(", "(", "final", ".", "charCodeAt", "(", "4", ")", "<<", "16", ")", "|", "(", "final", ".", "charCodeAt", "(", "10", ")", "<<", "8", ")", "|", "final", ".", "charCodeAt", "(", "5", ")", ",", "4", ")", ";", "epass", "+=", "to64", "(", "final", ".", "charCodeAt", "(", "11", ")", ",", "2", ")", ";", "return", "epass", ";", "}" ]
Returns password.
[ "Returns", "password", "." ]
27aa6364d50eeb93dfaf0b2a090c0cf035b32b49
https://github.com/http-auth/apache-md5/blob/27aa6364d50eeb93dfaf0b2a090c0cf035b32b49/src/index.js#L39-L51
44,372
serban-petrescu/ui5-jsx-rm
src/transformer.js
getElementTag
function getElementTag(node) { if (node.openingElement && t.isJSXIdentifier(node.openingElement.name)) { return node.openingElement.name.name; } else { error(node.openingElement, "Unable to parse opening tag."); } }
javascript
function getElementTag(node) { if (node.openingElement && t.isJSXIdentifier(node.openingElement.name)) { return node.openingElement.name.name; } else { error(node.openingElement, "Unable to parse opening tag."); } }
[ "function", "getElementTag", "(", "node", ")", "{", "if", "(", "node", ".", "openingElement", "&&", "t", ".", "isJSXIdentifier", "(", "node", ".", "openingElement", ".", "name", ")", ")", "{", "return", "node", ".", "openingElement", ".", "name", ".", "name", ";", "}", "else", "{", "error", "(", "node", ".", "openingElement", ",", "\"Unable to parse opening tag.\"", ")", ";", "}", "}" ]
Retrieve the tag string for an element node.
[ "Retrieve", "the", "tag", "string", "for", "an", "element", "node", "." ]
57beb245a6c70d7fad75a69242deb0a1ee7f3ee0
https://github.com/serban-petrescu/ui5-jsx-rm/blob/57beb245a6c70d7fad75a69242deb0a1ee7f3ee0/src/transformer.js#L8-L14
44,373
serban-petrescu/ui5-jsx-rm
src/transformer.js
transformSpecialAttribute
function transformSpecialAttribute(name, attribute) { if (t.isJSXExpressionContainer(attribute.value)) { let value = attribute.value.expression; switch (name) { case "ui5ControlData": renderer.renderControlData(value); break; case "ui5ElementData": renderer.renderElementData(value); break; case "ui5AccessibilityData": renderer.handleAccessibilityData(value); break; default: error(attribute, "Unknown special attribute: '" + name + "'."); } } else { error(attribute, "Only expressions supported in special attributes."); } }
javascript
function transformSpecialAttribute(name, attribute) { if (t.isJSXExpressionContainer(attribute.value)) { let value = attribute.value.expression; switch (name) { case "ui5ControlData": renderer.renderControlData(value); break; case "ui5ElementData": renderer.renderElementData(value); break; case "ui5AccessibilityData": renderer.handleAccessibilityData(value); break; default: error(attribute, "Unknown special attribute: '" + name + "'."); } } else { error(attribute, "Only expressions supported in special attributes."); } }
[ "function", "transformSpecialAttribute", "(", "name", ",", "attribute", ")", "{", "if", "(", "t", ".", "isJSXExpressionContainer", "(", "attribute", ".", "value", ")", ")", "{", "let", "value", "=", "attribute", ".", "value", ".", "expression", ";", "switch", "(", "name", ")", "{", "case", "\"ui5ControlData\"", ":", "renderer", ".", "renderControlData", "(", "value", ")", ";", "break", ";", "case", "\"ui5ElementData\"", ":", "renderer", ".", "renderElementData", "(", "value", ")", ";", "break", ";", "case", "\"ui5AccessibilityData\"", ":", "renderer", ".", "handleAccessibilityData", "(", "value", ")", ";", "break", ";", "default", ":", "error", "(", "attribute", ",", "\"Unknown special attribute: '\"", "+", "name", "+", "\"'.\"", ")", ";", "}", "}", "else", "{", "error", "(", "attribute", ",", "\"Only expressions supported in special attributes.\"", ")", ";", "}", "}" ]
Transforms the special attribute with the given name.
[ "Transforms", "the", "special", "attribute", "with", "the", "given", "name", "." ]
57beb245a6c70d7fad75a69242deb0a1ee7f3ee0
https://github.com/serban-petrescu/ui5-jsx-rm/blob/57beb245a6c70d7fad75a69242deb0a1ee7f3ee0/src/transformer.js#L19-L38
44,374
serban-petrescu/ui5-jsx-rm
src/transformer.js
transformStyles
function transformStyles(value) { if (t.isStringLiteral(value)) { renderer.renderAttributeExpression("style", value); } else if (t.isJSXExpressionContainer(value)){ renderer.handleStyles(value.expression); } else { error(value, "Unknown style specification type."); } }
javascript
function transformStyles(value) { if (t.isStringLiteral(value)) { renderer.renderAttributeExpression("style", value); } else if (t.isJSXExpressionContainer(value)){ renderer.handleStyles(value.expression); } else { error(value, "Unknown style specification type."); } }
[ "function", "transformStyles", "(", "value", ")", "{", "if", "(", "t", ".", "isStringLiteral", "(", "value", ")", ")", "{", "renderer", ".", "renderAttributeExpression", "(", "\"style\"", ",", "value", ")", ";", "}", "else", "if", "(", "t", ".", "isJSXExpressionContainer", "(", "value", ")", ")", "{", "renderer", ".", "handleStyles", "(", "value", ".", "expression", ")", ";", "}", "else", "{", "error", "(", "value", ",", "\"Unknown style specification type.\"", ")", ";", "}", "}" ]
Transforms the style specification in either a plain attribute rendering or a handler function call.
[ "Transforms", "the", "style", "specification", "in", "either", "a", "plain", "attribute", "rendering", "or", "a", "handler", "function", "call", "." ]
57beb245a6c70d7fad75a69242deb0a1ee7f3ee0
https://github.com/serban-petrescu/ui5-jsx-rm/blob/57beb245a6c70d7fad75a69242deb0a1ee7f3ee0/src/transformer.js#L44-L52
44,375
serban-petrescu/ui5-jsx-rm
src/transformer.js
transformClasses
function transformClasses(value) { if (t.isStringLiteral(value)) { value.value.split(" ").forEach(function(cls) { renderer.addClass(cls); }); } else if (t.isJSXExpressionContainer(value)){ renderer.handleClasses(value.expression); } else { error(value, "Unknown class specification type."); } }
javascript
function transformClasses(value) { if (t.isStringLiteral(value)) { value.value.split(" ").forEach(function(cls) { renderer.addClass(cls); }); } else if (t.isJSXExpressionContainer(value)){ renderer.handleClasses(value.expression); } else { error(value, "Unknown class specification type."); } }
[ "function", "transformClasses", "(", "value", ")", "{", "if", "(", "t", ".", "isStringLiteral", "(", "value", ")", ")", "{", "value", ".", "value", ".", "split", "(", "\" \"", ")", ".", "forEach", "(", "function", "(", "cls", ")", "{", "renderer", ".", "addClass", "(", "cls", ")", ";", "}", ")", ";", "}", "else", "if", "(", "t", ".", "isJSXExpressionContainer", "(", "value", ")", ")", "{", "renderer", ".", "handleClasses", "(", "value", ".", "expression", ")", ";", "}", "else", "{", "error", "(", "value", ",", "\"Unknown class specification type.\"", ")", ";", "}", "}" ]
Transforms the class specification into either a sequence of add-class renderer calls or a handler function call.
[ "Transforms", "the", "class", "specification", "into", "either", "a", "sequence", "of", "add", "-", "class", "renderer", "calls", "or", "a", "handler", "function", "call", "." ]
57beb245a6c70d7fad75a69242deb0a1ee7f3ee0
https://github.com/serban-petrescu/ui5-jsx-rm/blob/57beb245a6c70d7fad75a69242deb0a1ee7f3ee0/src/transformer.js#L58-L68
44,376
davidfig/pixel
convert.js
draw
function draw(c, frame) { const pixels = frame.data for (let y = 0; y < frame.height; y++) { for (let x = 0; x < frame.width; x++) { const color = pixels[x + y * frame.width] if (typeof color !== 'undefined') { let hex = color.toString(16) while (hex.length < 6) { hex = '0' + hex } c.fillStyle = '#' + hex c.beginPath() c.fillRect(x, y, 1, 1) } } } }
javascript
function draw(c, frame) { const pixels = frame.data for (let y = 0; y < frame.height; y++) { for (let x = 0; x < frame.width; x++) { const color = pixels[x + y * frame.width] if (typeof color !== 'undefined') { let hex = color.toString(16) while (hex.length < 6) { hex = '0' + hex } c.fillStyle = '#' + hex c.beginPath() c.fillRect(x, y, 1, 1) } } } }
[ "function", "draw", "(", "c", ",", "frame", ")", "{", "const", "pixels", "=", "frame", ".", "data", "for", "(", "let", "y", "=", "0", ";", "y", "<", "frame", ".", "height", ";", "y", "++", ")", "{", "for", "(", "let", "x", "=", "0", ";", "x", "<", "frame", ".", "width", ";", "x", "++", ")", "{", "const", "color", "=", "pixels", "[", "x", "+", "y", "*", "frame", ".", "width", "]", "if", "(", "typeof", "color", "!==", "'undefined'", ")", "{", "let", "hex", "=", "color", ".", "toString", "(", "16", ")", "while", "(", "hex", ".", "length", "<", "6", ")", "{", "hex", "=", "'0'", "+", "hex", "}", "c", ".", "fillStyle", "=", "'#'", "+", "hex", "c", ".", "beginPath", "(", ")", "c", ".", "fillRect", "(", "x", ",", "y", ",", "1", ",", "1", ")", "}", "}", "}", "}" ]
used by RenderSheet to render the frame @private @param {CanvasRenderingContext2D} c @param {object} frame
[ "used", "by", "RenderSheet", "to", "render", "the", "frame" ]
2713a7922f9e7f4c008c0fc4ec398e9b1b64aace
https://github.com/davidfig/pixel/blob/2713a7922f9e7f4c008c0fc4ec398e9b1b64aace/convert.js#L34-L55
44,377
SungardAS/condensation
lib/condensation/util.js
taskNameFunc
function taskNameFunc() { var validParts = _.dropWhile(_.flatten([this.prefix,arguments]),function(item) { return !item; }); return validParts.join(this.separator); }
javascript
function taskNameFunc() { var validParts = _.dropWhile(_.flatten([this.prefix,arguments]),function(item) { return !item; }); return validParts.join(this.separator); }
[ "function", "taskNameFunc", "(", ")", "{", "var", "validParts", "=", "_", ".", "dropWhile", "(", "_", ".", "flatten", "(", "[", "this", ".", "prefix", ",", "arguments", "]", ")", ",", "function", "(", "item", ")", "{", "return", "!", "item", ";", "}", ")", ";", "return", "validParts", ".", "join", "(", "this", ".", "separator", ")", ";", "}" ]
Make a task name @param {...string} str - Parts of the task name that will be joined together @returns {string} - The full task name
[ "Make", "a", "task", "name" ]
4595b3d7ac7f7adbc7a8c049aa5fac18e59bf016
https://github.com/SungardAS/condensation/blob/4595b3d7ac7f7adbc7a8c049aa5fac18e59bf016/lib/condensation/util.js#L25-L30
44,378
MoOx/postcss-message-helpers
index.js
sourceString
function sourceString(source) { var message = "<css input>" if (source) { if (source.input && source.input.file) { message = source.input.file } if (source.start) { message += ":" + source.start.line + ":" + source.start.column } } return message }
javascript
function sourceString(source) { var message = "<css input>" if (source) { if (source.input && source.input.file) { message = source.input.file } if (source.start) { message += ":" + source.start.line + ":" + source.start.column } } return message }
[ "function", "sourceString", "(", "source", ")", "{", "var", "message", "=", "\"<css input>\"", "if", "(", "source", ")", "{", "if", "(", "source", ".", "input", "&&", "source", ".", "input", ".", "file", ")", "{", "message", "=", "source", ".", "input", ".", "file", "}", "if", "(", "source", ".", "start", ")", "{", "message", "+=", "\":\"", "+", "source", ".", "start", ".", "line", "+", "\":\"", "+", "source", ".", "start", ".", "column", "}", "}", "return", "message", "}" ]
Returns GNU style source @param {Object} source
[ "Returns", "GNU", "style", "source" ]
5f9d44c18e0aba563ac13550617378b69a4f9744
https://github.com/MoOx/postcss-message-helpers/blob/5f9d44c18e0aba563ac13550617378b69a4f9744/index.js#L20-L32
44,379
Z-Team-Pro/ZTeam-Chat
public/js/main.js
scrollToBottom
function scrollToBottom(){ var it= jQuery('#testit'); var message= jQuery('#messages'); var newMessage= message.children('li:last-child') var clientH= it.prop('clientHeight'); var scrollTop=it.prop('scrollTop'); var scrollH=it.prop('scrollHeight'); var newMessageH= newMessage.innerHeight(); var prevmessageH=newMessage.prev().innerHeight(); var t=clientH+scrollTop+newMessageH+prevmessageH; if(clientH+scrollTop+newMessageH+prevmessageH>=scrollH){ it.scrollTop(scrollH); } }
javascript
function scrollToBottom(){ var it= jQuery('#testit'); var message= jQuery('#messages'); var newMessage= message.children('li:last-child') var clientH= it.prop('clientHeight'); var scrollTop=it.prop('scrollTop'); var scrollH=it.prop('scrollHeight'); var newMessageH= newMessage.innerHeight(); var prevmessageH=newMessage.prev().innerHeight(); var t=clientH+scrollTop+newMessageH+prevmessageH; if(clientH+scrollTop+newMessageH+prevmessageH>=scrollH){ it.scrollTop(scrollH); } }
[ "function", "scrollToBottom", "(", ")", "{", "var", "it", "=", "jQuery", "(", "'#testit'", ")", ";", "var", "message", "=", "jQuery", "(", "'#messages'", ")", ";", "var", "newMessage", "=", "message", ".", "children", "(", "'li:last-child'", ")", "var", "clientH", "=", "it", ".", "prop", "(", "'clientHeight'", ")", ";", "var", "scrollTop", "=", "it", ".", "prop", "(", "'scrollTop'", ")", ";", "var", "scrollH", "=", "it", ".", "prop", "(", "'scrollHeight'", ")", ";", "var", "newMessageH", "=", "newMessage", ".", "innerHeight", "(", ")", ";", "var", "prevmessageH", "=", "newMessage", ".", "prev", "(", ")", ".", "innerHeight", "(", ")", ";", "var", "t", "=", "clientH", "+", "scrollTop", "+", "newMessageH", "+", "prevmessageH", ";", "if", "(", "clientH", "+", "scrollTop", "+", "newMessageH", "+", "prevmessageH", ">=", "scrollH", ")", "{", "it", ".", "scrollTop", "(", "scrollH", ")", ";", "}", "}" ]
scroll to bottom
[ "scroll", "to", "bottom" ]
e6557a36cb20ecf040688c1e30bb6aac5fab438a
https://github.com/Z-Team-Pro/ZTeam-Chat/blob/e6557a36cb20ecf040688c1e30bb6aac5fab438a/public/js/main.js#L46-L62
44,380
kengz/neo4jKB
lib/constrain.js
function(res) { var author = _.get(res, 'envelope.user.id') || 'bot' return _.zipObject(cons.mandatoryFields, ['hash', 'test', author, cons.now()]) }
javascript
function(res) { var author = _.get(res, 'envelope.user.id') || 'bot' return _.zipObject(cons.mandatoryFields, ['hash', 'test', author, cons.now()]) }
[ "function", "(", "res", ")", "{", "var", "author", "=", "_", ".", "get", "(", "res", ",", "'envelope.user.id'", ")", "||", "'bot'", "return", "_", ".", "zipObject", "(", "cons", ".", "mandatoryFields", ",", "[", "'hash'", ",", "'test'", ",", "author", ",", "cons", ".", "now", "(", ")", "]", ")", "}" ]
Generate an object of mandatoryFields with default values for extension. @private @param {JSON} [res] For the robot to extract user id. @return {JSON} mandatoryFieldsObject with default values.
[ "Generate", "an", "object", "of", "mandatoryFields", "with", "default", "values", "for", "extension", "." ]
8762390ac81974afc6bb44a2dd3c44b44aaaa09a
https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/constrain.js#L101-L104
44,381
kengz/neo4jKB
lib/constrain.js
function(str) { var startsWith = !_.isNull(str.match(wOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
javascript
function(str) { var startsWith = !_.isNull(str.match(wOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
[ "function", "(", "str", ")", "{", "var", "startsWith", "=", "!", "_", ".", "isNull", "(", "str", ".", "match", "(", "wOpsHeadRe", ")", ")", "return", "startsWith", "&", "cons", ".", "isLegalSentence", "(", "str", ")", "}" ]
Check if the string is a WHERE operation string and is legal. @private @param {string} str WHERE sentence. @return {Boolean}
[ "Check", "if", "the", "string", "is", "a", "WHERE", "operation", "string", "and", "is", "legal", "." ]
8762390ac81974afc6bb44a2dd3c44b44aaaa09a
https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/constrain.js#L349-L352
44,382
kengz/neo4jKB
lib/constrain.js
function(str) { var startsWith = !_.isNull(str.match(sOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
javascript
function(str) { var startsWith = !_.isNull(str.match(sOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
[ "function", "(", "str", ")", "{", "var", "startsWith", "=", "!", "_", ".", "isNull", "(", "str", ".", "match", "(", "sOpsHeadRe", ")", ")", "return", "startsWith", "&", "cons", ".", "isLegalSentence", "(", "str", ")", "}" ]
Check if the string is a SET|REMOVE operation string and is legal. @private @param {string} str WHERE sentence. @return {Boolean}
[ "Check", "if", "the", "string", "is", "a", "SET|REMOVE", "operation", "string", "and", "is", "legal", "." ]
8762390ac81974afc6bb44a2dd3c44b44aaaa09a
https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/constrain.js#L360-L363
44,383
kengz/neo4jKB
lib/constrain.js
function(str) { var startsWith = !_.isNull(str.match(rOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
javascript
function(str) { var startsWith = !_.isNull(str.match(rOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
[ "function", "(", "str", ")", "{", "var", "startsWith", "=", "!", "_", ".", "isNull", "(", "str", ".", "match", "(", "rOpsHeadRe", ")", ")", "return", "startsWith", "&", "cons", ".", "isLegalSentence", "(", "str", ")", "}" ]
Check if the string is a RETURN|DELETE|DETACH DELETE operation string and is legal. @private @param {string} str RETURN sentence. @return {Boolean}
[ "Check", "if", "the", "string", "is", "a", "RETURN|DELETE|DETACH", "DELETE", "operation", "string", "and", "is", "legal", "." ]
8762390ac81974afc6bb44a2dd3c44b44aaaa09a
https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/constrain.js#L371-L374
44,384
kengz/neo4jKB
lib/constrain.js
function(str) { var startsWith = !_.isNull(str.match(pOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
javascript
function(str) { var startsWith = !_.isNull(str.match(pOpsHeadRe)) return startsWith & cons.isLegalSentence(str) }
[ "function", "(", "str", ")", "{", "var", "startsWith", "=", "!", "_", ".", "isNull", "(", "str", ".", "match", "(", "pOpsHeadRe", ")", ")", "return", "startsWith", "&", "cons", ".", "isLegalSentence", "(", "str", ")", "}" ]
Check if the string is a SHORTESTPATH|ALLSHORTESTPATHS operation string and is legal. @private @param {string} str PATH sentence. @return {Boolean}
[ "Check", "if", "the", "string", "is", "a", "SHORTESTPATH|ALLSHORTESTPATHS", "operation", "string", "and", "is", "legal", "." ]
8762390ac81974afc6bb44a2dd3c44b44aaaa09a
https://github.com/kengz/neo4jKB/blob/8762390ac81974afc6bb44a2dd3c44b44aaaa09a/lib/constrain.js#L382-L385
44,385
Deathspike/npm-build-tools
src/run.js
run
function run(commands, done) { var children = []; var pending = commands.length || 1; var err; each(commands, function(command, next) { children.push(childProcess.spawn(shell[0], [shell[1], command], { stdio: ['pipe', process.stdout, process.stderr] }).on('exit', function(code) { if (!err && code > 0) { err = new Error('`' + command + '` failed with exit code ' + code); children.forEach(function(child) { if (child.connected) child.kill(); }); } pending -= 1; if (pending === 0) done(err); })); next(); }); }
javascript
function run(commands, done) { var children = []; var pending = commands.length || 1; var err; each(commands, function(command, next) { children.push(childProcess.spawn(shell[0], [shell[1], command], { stdio: ['pipe', process.stdout, process.stderr] }).on('exit', function(code) { if (!err && code > 0) { err = new Error('`' + command + '` failed with exit code ' + code); children.forEach(function(child) { if (child.connected) child.kill(); }); } pending -= 1; if (pending === 0) done(err); })); next(); }); }
[ "function", "run", "(", "commands", ",", "done", ")", "{", "var", "children", "=", "[", "]", ";", "var", "pending", "=", "commands", ".", "length", "||", "1", ";", "var", "err", ";", "each", "(", "commands", ",", "function", "(", "command", ",", "next", ")", "{", "children", ".", "push", "(", "childProcess", ".", "spawn", "(", "shell", "[", "0", "]", ",", "[", "shell", "[", "1", "]", ",", "command", "]", ",", "{", "stdio", ":", "[", "'pipe'", ",", "process", ".", "stdout", ",", "process", ".", "stderr", "]", "}", ")", ".", "on", "(", "'exit'", ",", "function", "(", "code", ")", "{", "if", "(", "!", "err", "&&", "code", ">", "0", ")", "{", "err", "=", "new", "Error", "(", "'`'", "+", "command", "+", "'` failed with exit code '", "+", "code", ")", ";", "children", ".", "forEach", "(", "function", "(", "child", ")", "{", "if", "(", "child", ".", "connected", ")", "child", ".", "kill", "(", ")", ";", "}", ")", ";", "}", "pending", "-=", "1", ";", "if", "(", "pending", "===", "0", ")", "done", "(", "err", ")", ";", "}", ")", ")", ";", "next", "(", ")", ";", "}", ")", ";", "}" ]
Runs each command in parallel. @param {Array.<string>} commands @param {function(Error=)} done
[ "Runs", "each", "command", "in", "parallel", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/run.js#L31-L50
44,386
Deathspike/npm-build-tools
src/run.js
watch
function watch(sourcePath, patterns, commands) { var isBusy = false; var isPending = false; var runnable = function() { if (isBusy) return (isPending = true); isBusy = true; run(commands, function(err) { if (err) console.error(err.stack || err); isBusy = false; if (isPending) runnable(isPending = false); }); }; chokidar.watch(patterns, { cwd: sourcePath, ignoreInitial: true }).on('add', runnable).on('change', runnable).on('unlink', runnable); }
javascript
function watch(sourcePath, patterns, commands) { var isBusy = false; var isPending = false; var runnable = function() { if (isBusy) return (isPending = true); isBusy = true; run(commands, function(err) { if (err) console.error(err.stack || err); isBusy = false; if (isPending) runnable(isPending = false); }); }; chokidar.watch(patterns, { cwd: sourcePath, ignoreInitial: true }).on('add', runnable).on('change', runnable).on('unlink', runnable); }
[ "function", "watch", "(", "sourcePath", ",", "patterns", ",", "commands", ")", "{", "var", "isBusy", "=", "false", ";", "var", "isPending", "=", "false", ";", "var", "runnable", "=", "function", "(", ")", "{", "if", "(", "isBusy", ")", "return", "(", "isPending", "=", "true", ")", ";", "isBusy", "=", "true", ";", "run", "(", "commands", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "console", ".", "error", "(", "err", ".", "stack", "||", "err", ")", ";", "isBusy", "=", "false", ";", "if", "(", "isPending", ")", "runnable", "(", "isPending", "=", "false", ")", ";", "}", ")", ";", "}", ";", "chokidar", ".", "watch", "(", "patterns", ",", "{", "cwd", ":", "sourcePath", ",", "ignoreInitial", ":", "true", "}", ")", ".", "on", "(", "'add'", ",", "runnable", ")", ".", "on", "(", "'change'", ",", "runnable", ")", ".", "on", "(", "'unlink'", ",", "runnable", ")", ";", "}" ]
Watches the patterns in the source path and runs commands on changes. @param {string} sourcePath @param {(Array.<string>|string)} patterns @param {Array.<string>} commands
[ "Watches", "the", "patterns", "in", "the", "source", "path", "and", "runs", "commands", "on", "changes", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/run.js#L74-L90
44,387
draggett/arena-webhub
webhub.js
fail
function fail(status, description, response) { let body = status + ' ' + description; console.log(body); response.writeHead(status, { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': '*', 'Content-Length': body.length }); response.write(body); response.end(); }
javascript
function fail(status, description, response) { let body = status + ' ' + description; console.log(body); response.writeHead(status, { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': '*', 'Content-Length': body.length }); response.write(body); response.end(); }
[ "function", "fail", "(", "status", ",", "description", ",", "response", ")", "{", "let", "body", "=", "status", "+", "' '", "+", "description", ";", "console", ".", "log", "(", "body", ")", ";", "response", ".", "writeHead", "(", "status", ",", "{", "'Content-Type'", ":", "'text/plain'", ",", "'Access-Control-Allow-Origin'", ":", "'*'", ",", "'Content-Length'", ":", "body", ".", "length", "}", ")", ";", "response", ".", "write", "(", "body", ")", ";", "response", ".", "end", "(", ")", ";", "}" ]
helper for http server
[ "helper", "for", "http", "server" ]
85335f197147e608d3899e3c1665188dddd178ec
https://github.com/draggett/arena-webhub/blob/85335f197147e608d3899e3c1665188dddd178ec/webhub.js#L701-L712
44,388
draggett/arena-webhub
webhub.js
authorised
function authorised(request) { // JWT is usually passed via an HTTP header let token = request.headers.authorization; // For EventSource and WebSocket, JWT is passed as a URL parameter if (token === undefined) { let url = URL.parse(request.url, true); if (url.query) token = url.query.jwt; } // ask app to validate JWT authorisation token return (!token || config.validateJWT(token, request.url)); }
javascript
function authorised(request) { // JWT is usually passed via an HTTP header let token = request.headers.authorization; // For EventSource and WebSocket, JWT is passed as a URL parameter if (token === undefined) { let url = URL.parse(request.url, true); if (url.query) token = url.query.jwt; } // ask app to validate JWT authorisation token return (!token || config.validateJWT(token, request.url)); }
[ "function", "authorised", "(", "request", ")", "{", "// JWT is usually passed via an HTTP header", "let", "token", "=", "request", ".", "headers", ".", "authorization", ";", "// For EventSource and WebSocket, JWT is passed as a URL parameter", "if", "(", "token", "===", "undefined", ")", "{", "let", "url", "=", "URL", ".", "parse", "(", "request", ".", "url", ",", "true", ")", ";", "if", "(", "url", ".", "query", ")", "token", "=", "url", ".", "query", ".", "jwt", ";", "}", "// ask app to validate JWT authorisation token", "return", "(", "!", "token", "||", "config", ".", "validateJWT", "(", "token", ",", "request", ".", "url", ")", ")", ";", "}" ]
helper for HTTP request authorisation
[ "helper", "for", "HTTP", "request", "authorisation" ]
85335f197147e608d3899e3c1665188dddd178ec
https://github.com/draggett/arena-webhub/blob/85335f197147e608d3899e3c1665188dddd178ec/webhub.js#L730-L744
44,389
draggett/arena-webhub
webhub.js
ws_send
function ws_send(socket, data) { //console.log("send: " + data); let header; let payload = new Buffer.from(data); const len = payload.length; if (len <= 125) { header = new Buffer.alloc(2); header[1] = len; } else if (len <= 0xffff) { header = new Buffer.alloc(4); header[1] = 126; header[2] = (len >> 8) & 0xff; header[3] = len & 0xff; } else { /* 0xffff < len <= 2^63 */ header = new Buffer(10); header[1] = 127; header[2] = (len >> 56) & 0xff; header[3] = (len >> 48) & 0xff; header[4] = (len >> 40) & 0xff; header[5] = (len >> 32) & 0xff; header[6] = (len >> 24) & 0xff; header[7] = (len >> 16) & 0xff; header[8] = (len >> 8) & 0xff; header[9] = len & 0xff; } header[0] = 0x81; socket.write(Buffer.concat([header, payload], header.length + payload.length), 'binary'); //console.log('sent ' + data.length + ' bytes'); }
javascript
function ws_send(socket, data) { //console.log("send: " + data); let header; let payload = new Buffer.from(data); const len = payload.length; if (len <= 125) { header = new Buffer.alloc(2); header[1] = len; } else if (len <= 0xffff) { header = new Buffer.alloc(4); header[1] = 126; header[2] = (len >> 8) & 0xff; header[3] = len & 0xff; } else { /* 0xffff < len <= 2^63 */ header = new Buffer(10); header[1] = 127; header[2] = (len >> 56) & 0xff; header[3] = (len >> 48) & 0xff; header[4] = (len >> 40) & 0xff; header[5] = (len >> 32) & 0xff; header[6] = (len >> 24) & 0xff; header[7] = (len >> 16) & 0xff; header[8] = (len >> 8) & 0xff; header[9] = len & 0xff; } header[0] = 0x81; socket.write(Buffer.concat([header, payload], header.length + payload.length), 'binary'); //console.log('sent ' + data.length + ' bytes'); }
[ "function", "ws_send", "(", "socket", ",", "data", ")", "{", "//console.log(\"send: \" + data);", "let", "header", ";", "let", "payload", "=", "new", "Buffer", ".", "from", "(", "data", ")", ";", "const", "len", "=", "payload", ".", "length", ";", "if", "(", "len", "<=", "125", ")", "{", "header", "=", "new", "Buffer", ".", "alloc", "(", "2", ")", ";", "header", "[", "1", "]", "=", "len", ";", "}", "else", "if", "(", "len", "<=", "0xffff", ")", "{", "header", "=", "new", "Buffer", ".", "alloc", "(", "4", ")", ";", "header", "[", "1", "]", "=", "126", ";", "header", "[", "2", "]", "=", "(", "len", ">>", "8", ")", "&", "0xff", ";", "header", "[", "3", "]", "=", "len", "&", "0xff", ";", "}", "else", "{", "/* 0xffff < len <= 2^63 */", "header", "=", "new", "Buffer", "(", "10", ")", ";", "header", "[", "1", "]", "=", "127", ";", "header", "[", "2", "]", "=", "(", "len", ">>", "56", ")", "&", "0xff", ";", "header", "[", "3", "]", "=", "(", "len", ">>", "48", ")", "&", "0xff", ";", "header", "[", "4", "]", "=", "(", "len", ">>", "40", ")", "&", "0xff", ";", "header", "[", "5", "]", "=", "(", "len", ">>", "32", ")", "&", "0xff", ";", "header", "[", "6", "]", "=", "(", "len", ">>", "24", ")", "&", "0xff", ";", "header", "[", "7", "]", "=", "(", "len", ">>", "16", ")", "&", "0xff", ";", "header", "[", "8", "]", "=", "(", "len", ">>", "8", ")", "&", "0xff", ";", "header", "[", "9", "]", "=", "len", "&", "0xff", ";", "}", "header", "[", "0", "]", "=", "0x81", ";", "socket", ".", "write", "(", "Buffer", ".", "concat", "(", "[", "header", ",", "payload", "]", ",", "header", ".", "length", "+", "payload", ".", "length", ")", ",", "'binary'", ")", ";", "//console.log('sent ' + data.length + ' bytes');", "}" ]
send string data to web socket
[ "send", "string", "data", "to", "web", "socket" ]
85335f197147e608d3899e3c1665188dddd178ec
https://github.com/draggett/arena-webhub/blob/85335f197147e608d3899e3c1665188dddd178ec/webhub.js#L1186-L1217
44,390
draggett/arena-webhub
webhub.js
ws_receive
function ws_receive(raw) { let data = unpack(raw); // string to byte array let fin = (data[0] & 128) == 128; let opcode = data[0] & 15; let isMasked = (data[1] & 128) == 128; let dataLength = data[1] & 127; let start = 2; let length = data.length; let output = ""; if (dataLength == 126) start = 4; else if (dataLength == 127) start = 10; if (isMasked) { let i = start + 4; let masks = data.slice(start, i); let index = 0; while (i < length) { output += String.fromCharCode(data[i++] ^ masks[index++ % 4]); } } else { let i = start; while (i < length) { output += String.fromCharCode(data[i++]); } } //console.log("decode message: " + output); return output; }
javascript
function ws_receive(raw) { let data = unpack(raw); // string to byte array let fin = (data[0] & 128) == 128; let opcode = data[0] & 15; let isMasked = (data[1] & 128) == 128; let dataLength = data[1] & 127; let start = 2; let length = data.length; let output = ""; if (dataLength == 126) start = 4; else if (dataLength == 127) start = 10; if (isMasked) { let i = start + 4; let masks = data.slice(start, i); let index = 0; while (i < length) { output += String.fromCharCode(data[i++] ^ masks[index++ % 4]); } } else { let i = start; while (i < length) { output += String.fromCharCode(data[i++]); } } //console.log("decode message: " + output); return output; }
[ "function", "ws_receive", "(", "raw", ")", "{", "let", "data", "=", "unpack", "(", "raw", ")", ";", "// string to byte array", "let", "fin", "=", "(", "data", "[", "0", "]", "&", "128", ")", "==", "128", ";", "let", "opcode", "=", "data", "[", "0", "]", "&", "15", ";", "let", "isMasked", "=", "(", "data", "[", "1", "]", "&", "128", ")", "==", "128", ";", "let", "dataLength", "=", "data", "[", "1", "]", "&", "127", ";", "let", "start", "=", "2", ";", "let", "length", "=", "data", ".", "length", ";", "let", "output", "=", "\"\"", ";", "if", "(", "dataLength", "==", "126", ")", "start", "=", "4", ";", "else", "if", "(", "dataLength", "==", "127", ")", "start", "=", "10", ";", "if", "(", "isMasked", ")", "{", "let", "i", "=", "start", "+", "4", ";", "let", "masks", "=", "data", ".", "slice", "(", "start", ",", "i", ")", ";", "let", "index", "=", "0", ";", "while", "(", "i", "<", "length", ")", "{", "output", "+=", "String", ".", "fromCharCode", "(", "data", "[", "i", "++", "]", "^", "masks", "[", "index", "++", "%", "4", "]", ")", ";", "}", "}", "else", "{", "let", "i", "=", "start", ";", "while", "(", "i", "<", "length", ")", "{", "output", "+=", "String", ".", "fromCharCode", "(", "data", "[", "i", "++", "]", ")", ";", "}", "}", "//console.log(\"decode message: \" + output);", "return", "output", ";", "}" ]
return message as string
[ "return", "message", "as", "string" ]
85335f197147e608d3899e3c1665188dddd178ec
https://github.com/draggett/arena-webhub/blob/85335f197147e608d3899e3c1665188dddd178ec/webhub.js#L1220-L1253
44,391
Deathspike/npm-build-tools
src/concat.js
concat
function concat(divider, sourcePath, relativePaths, done) { var writeDivider = false; each(relativePaths, function(relativePath, next) { var absoluteSourcePath = path.resolve(sourcePath, relativePath); var readStream = fs.createReadStream(absoluteSourcePath); if (writeDivider) process.stdout.write(divider); writeDivider = true; readStream.on('close', next).on('error', next).pipe(process.stdout); }, done); }
javascript
function concat(divider, sourcePath, relativePaths, done) { var writeDivider = false; each(relativePaths, function(relativePath, next) { var absoluteSourcePath = path.resolve(sourcePath, relativePath); var readStream = fs.createReadStream(absoluteSourcePath); if (writeDivider) process.stdout.write(divider); writeDivider = true; readStream.on('close', next).on('error', next).pipe(process.stdout); }, done); }
[ "function", "concat", "(", "divider", ",", "sourcePath", ",", "relativePaths", ",", "done", ")", "{", "var", "writeDivider", "=", "false", ";", "each", "(", "relativePaths", ",", "function", "(", "relativePath", ",", "next", ")", "{", "var", "absoluteSourcePath", "=", "path", ".", "resolve", "(", "sourcePath", ",", "relativePath", ")", ";", "var", "readStream", "=", "fs", ".", "createReadStream", "(", "absoluteSourcePath", ")", ";", "if", "(", "writeDivider", ")", "process", ".", "stdout", ".", "write", "(", "divider", ")", ";", "writeDivider", "=", "true", ";", "readStream", ".", "on", "(", "'close'", ",", "next", ")", ".", "on", "(", "'error'", ",", "next", ")", ".", "pipe", "(", "process", ".", "stdout", ")", ";", "}", ",", "done", ")", ";", "}" ]
Concatenate files from the source path into the standard output. @param {string} divider @param {string} sourcePath @param {Array.<string>} relativePaths @param {function(Error)=} done
[ "Concatenate", "files", "from", "the", "source", "path", "into", "the", "standard", "output", "." ]
caf2a0933b5900e34dc093f34b070a5b947cce39
https://github.com/Deathspike/npm-build-tools/blob/caf2a0933b5900e34dc093f34b070a5b947cce39/src/concat.js#L37-L46
44,392
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
function (path) { //There has to be an easier way to do this. var i, part, ary, firstChar = path.charAt(0); if (firstChar !== '/' && firstChar !== '\\' && path.indexOf(':') === -1) { //A relative path. Use the current working directory. path = xpcUtil.cwd() + '/' + path; } ary = path.replace(/\\/g, '/').split('/'); for (i = 0; i < ary.length; i += 1) { part = ary[i]; if (part === '.') { ary.splice(i, 1); i -= 1; } else if (part === '..') { ary.splice(i - 1, 2); i -= 2; } } return ary.join('/'); }
javascript
function (path) { //There has to be an easier way to do this. var i, part, ary, firstChar = path.charAt(0); if (firstChar !== '/' && firstChar !== '\\' && path.indexOf(':') === -1) { //A relative path. Use the current working directory. path = xpcUtil.cwd() + '/' + path; } ary = path.replace(/\\/g, '/').split('/'); for (i = 0; i < ary.length; i += 1) { part = ary[i]; if (part === '.') { ary.splice(i, 1); i -= 1; } else if (part === '..') { ary.splice(i - 1, 2); i -= 2; } } return ary.join('/'); }
[ "function", "(", "path", ")", "{", "//There has to be an easier way to do this.", "var", "i", ",", "part", ",", "ary", ",", "firstChar", "=", "path", ".", "charAt", "(", "0", ")", ";", "if", "(", "firstChar", "!==", "'/'", "&&", "firstChar", "!==", "'\\\\'", "&&", "path", ".", "indexOf", "(", "':'", ")", "===", "-", "1", ")", "{", "//A relative path. Use the current working directory.", "path", "=", "xpcUtil", ".", "cwd", "(", ")", "+", "'/'", "+", "path", ";", "}", "ary", "=", "path", ".", "replace", "(", "/", "\\\\", "/", "g", ",", "'/'", ")", ".", "split", "(", "'/'", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "ary", ".", "length", ";", "i", "+=", "1", ")", "{", "part", "=", "ary", "[", "i", "]", ";", "if", "(", "part", "===", "'.'", ")", "{", "ary", ".", "splice", "(", "i", ",", "1", ")", ";", "i", "-=", "1", ";", "}", "else", "if", "(", "part", "===", "'..'", ")", "{", "ary", ".", "splice", "(", "i", "-", "1", ",", "2", ")", ";", "i", "-=", "2", ";", "}", "}", "return", "ary", ".", "join", "(", "'/'", ")", ";", "}" ]
Remove . and .. from paths, normalize on front slashes
[ "Remove", ".", "and", "..", "from", "paths", "normalize", "on", "front", "slashes" ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L155-L180
44,393
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
function(dest, source) { lang.eachProp(source, function (value, prop) { if (typeof value === 'object' && value && !lang.isArray(value) && !lang.isFunction(value) && !(value instanceof RegExp)) { if (!dest[prop]) { dest[prop] = {}; } lang.deepMix(dest[prop], value); } else { dest[prop] = value; } }); return dest; }
javascript
function(dest, source) { lang.eachProp(source, function (value, prop) { if (typeof value === 'object' && value && !lang.isArray(value) && !lang.isFunction(value) && !(value instanceof RegExp)) { if (!dest[prop]) { dest[prop] = {}; } lang.deepMix(dest[prop], value); } else { dest[prop] = value; } }); return dest; }
[ "function", "(", "dest", ",", "source", ")", "{", "lang", ".", "eachProp", "(", "source", ",", "function", "(", "value", ",", "prop", ")", "{", "if", "(", "typeof", "value", "===", "'object'", "&&", "value", "&&", "!", "lang", ".", "isArray", "(", "value", ")", "&&", "!", "lang", ".", "isFunction", "(", "value", ")", "&&", "!", "(", "value", "instanceof", "RegExp", ")", ")", "{", "if", "(", "!", "dest", "[", "prop", "]", ")", "{", "dest", "[", "prop", "]", "=", "{", "}", ";", "}", "lang", ".", "deepMix", "(", "dest", "[", "prop", "]", ",", "value", ")", ";", "}", "else", "{", "dest", "[", "prop", "]", "=", "value", ";", "}", "}", ")", ";", "return", "dest", ";", "}" ]
Does a deep mix of source into dest, where source values override dest values if a winner is needed. @param {Object} dest destination object that receives the mixed values. @param {Object} source source object contributing properties to mix in. @return {[Object]} returns dest object with the modification.
[ "Does", "a", "deep", "mix", "of", "source", "into", "dest", "where", "source", "values", "override", "dest", "values", "if", "a", "winner", "is", "needed", "." ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L2796-L2811
44,394
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
SourceMap
function SourceMap(options) { options = defaults(options, { file : null, root : null, orig : null, orig_line_diff : 0, dest_line_diff : 0, }); var generator = new MOZ_SourceMap.SourceMapGenerator({ file : options.file, sourceRoot : options.root }); var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig); if (orig_map && Array.isArray(options.orig.sources)) { orig_map._sources.toArray().forEach(function(source) { var sourceContent = orig_map.sourceContentFor(source, true); if (sourceContent) { generator.setSourceContent(source, sourceContent); } }); } function add(source, gen_line, gen_col, orig_line, orig_col, name) { if (orig_map) { var info = orig_map.originalPositionFor({ line: orig_line, column: orig_col }); if (info.source === null) { return; } source = info.source; orig_line = info.line; orig_col = info.column; name = info.name || name; } generator.addMapping({ generated : { line: gen_line + options.dest_line_diff, column: gen_col }, original : { line: orig_line + options.orig_line_diff, column: orig_col }, source : source, name : name }); }; return { add : add, get : function() { return generator }, toString : function() { return JSON.stringify(generator.toJSON()); } }; }
javascript
function SourceMap(options) { options = defaults(options, { file : null, root : null, orig : null, orig_line_diff : 0, dest_line_diff : 0, }); var generator = new MOZ_SourceMap.SourceMapGenerator({ file : options.file, sourceRoot : options.root }); var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig); if (orig_map && Array.isArray(options.orig.sources)) { orig_map._sources.toArray().forEach(function(source) { var sourceContent = orig_map.sourceContentFor(source, true); if (sourceContent) { generator.setSourceContent(source, sourceContent); } }); } function add(source, gen_line, gen_col, orig_line, orig_col, name) { if (orig_map) { var info = orig_map.originalPositionFor({ line: orig_line, column: orig_col }); if (info.source === null) { return; } source = info.source; orig_line = info.line; orig_col = info.column; name = info.name || name; } generator.addMapping({ generated : { line: gen_line + options.dest_line_diff, column: gen_col }, original : { line: orig_line + options.orig_line_diff, column: orig_col }, source : source, name : name }); }; return { add : add, get : function() { return generator }, toString : function() { return JSON.stringify(generator.toJSON()); } }; }
[ "function", "SourceMap", "(", "options", ")", "{", "options", "=", "defaults", "(", "options", ",", "{", "file", ":", "null", ",", "root", ":", "null", ",", "orig", ":", "null", ",", "orig_line_diff", ":", "0", ",", "dest_line_diff", ":", "0", ",", "}", ")", ";", "var", "generator", "=", "new", "MOZ_SourceMap", ".", "SourceMapGenerator", "(", "{", "file", ":", "options", ".", "file", ",", "sourceRoot", ":", "options", ".", "root", "}", ")", ";", "var", "orig_map", "=", "options", ".", "orig", "&&", "new", "MOZ_SourceMap", ".", "SourceMapConsumer", "(", "options", ".", "orig", ")", ";", "if", "(", "orig_map", "&&", "Array", ".", "isArray", "(", "options", ".", "orig", ".", "sources", ")", ")", "{", "orig_map", ".", "_sources", ".", "toArray", "(", ")", ".", "forEach", "(", "function", "(", "source", ")", "{", "var", "sourceContent", "=", "orig_map", ".", "sourceContentFor", "(", "source", ",", "true", ")", ";", "if", "(", "sourceContent", ")", "{", "generator", ".", "setSourceContent", "(", "source", ",", "sourceContent", ")", ";", "}", "}", ")", ";", "}", "function", "add", "(", "source", ",", "gen_line", ",", "gen_col", ",", "orig_line", ",", "orig_col", ",", "name", ")", "{", "if", "(", "orig_map", ")", "{", "var", "info", "=", "orig_map", ".", "originalPositionFor", "(", "{", "line", ":", "orig_line", ",", "column", ":", "orig_col", "}", ")", ";", "if", "(", "info", ".", "source", "===", "null", ")", "{", "return", ";", "}", "source", "=", "info", ".", "source", ";", "orig_line", "=", "info", ".", "line", ";", "orig_col", "=", "info", ".", "column", ";", "name", "=", "info", ".", "name", "||", "name", ";", "}", "generator", ".", "addMapping", "(", "{", "generated", ":", "{", "line", ":", "gen_line", "+", "options", ".", "dest_line_diff", ",", "column", ":", "gen_col", "}", ",", "original", ":", "{", "line", ":", "orig_line", "+", "options", ".", "orig_line_diff", ",", "column", ":", "orig_col", "}", ",", "source", ":", "source", ",", "name", ":", "name", "}", ")", ";", "}", ";", "return", "{", "add", ":", "add", ",", "get", ":", "function", "(", ")", "{", "return", "generator", "}", ",", "toString", ":", "function", "(", ")", "{", "return", "JSON", ".", "stringify", "(", "generator", ".", "toJSON", "(", ")", ")", ";", "}", "}", ";", "}" ]
a small wrapper around fitzgen's source-map library
[ "a", "small", "wrapper", "around", "fitzgen", "s", "source", "-", "map", "library" ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L23709-L23759
44,395
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
can_mangle
function can_mangle(name) { if (unmangleable.indexOf(name) >= 0) return false; if (reserved.indexOf(name) >= 0) return false; if (options.only_cache) { return cache.props.has(name); } if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false; return true; }
javascript
function can_mangle(name) { if (unmangleable.indexOf(name) >= 0) return false; if (reserved.indexOf(name) >= 0) return false; if (options.only_cache) { return cache.props.has(name); } if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false; return true; }
[ "function", "can_mangle", "(", "name", ")", "{", "if", "(", "unmangleable", ".", "indexOf", "(", "name", ")", ">=", "0", ")", "return", "false", ";", "if", "(", "reserved", ".", "indexOf", "(", "name", ")", ">=", "0", ")", "return", "false", ";", "if", "(", "options", ".", "only_cache", ")", "{", "return", "cache", ".", "props", ".", "has", "(", "name", ")", ";", "}", "if", "(", "/", "^-?[0-9]+(\\.[0-9]+)?(e[+-][0-9]+)?$", "/", ".", "test", "(", "name", ")", ")", "return", "false", ";", "return", "true", ";", "}" ]
only function declarations after this line
[ "only", "function", "declarations", "after", "this", "line" ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L24531-L24539
44,396
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
traverse
function traverse(object, visitor) { var child; if (!object) { return; } if (visitor.call(null, object) === false) { return false; } for (var i = 0, keys = Object.keys(object); i < keys.length; i++) { child = object[keys[i]]; if (typeof child === 'object' && child !== null) { if (traverse(child, visitor) === false) { return false; } } } }
javascript
function traverse(object, visitor) { var child; if (!object) { return; } if (visitor.call(null, object) === false) { return false; } for (var i = 0, keys = Object.keys(object); i < keys.length; i++) { child = object[keys[i]]; if (typeof child === 'object' && child !== null) { if (traverse(child, visitor) === false) { return false; } } } }
[ "function", "traverse", "(", "object", ",", "visitor", ")", "{", "var", "child", ";", "if", "(", "!", "object", ")", "{", "return", ";", "}", "if", "(", "visitor", ".", "call", "(", "null", ",", "object", ")", "===", "false", ")", "{", "return", "false", ";", "}", "for", "(", "var", "i", "=", "0", ",", "keys", "=", "Object", ".", "keys", "(", "object", ")", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "child", "=", "object", "[", "keys", "[", "i", "]", "]", ";", "if", "(", "typeof", "child", "===", "'object'", "&&", "child", "!==", "null", ")", "{", "if", "(", "traverse", "(", "child", ",", "visitor", ")", "===", "false", ")", "{", "return", "false", ";", "}", "}", "}", "}" ]
From an esprima example for traversing its ast.
[ "From", "an", "esprima", "example", "for", "traversing", "its", "ast", "." ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L24982-L25000
44,397
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
getValidDeps
function getValidDeps(node) { if (!node || node.type !== 'ArrayExpression' || !node.elements) { return; } var deps = []; node.elements.some(function (elem) { if (elem.type === 'Literal') { deps.push(elem.value); } }); return deps.length ? deps : undefined; }
javascript
function getValidDeps(node) { if (!node || node.type !== 'ArrayExpression' || !node.elements) { return; } var deps = []; node.elements.some(function (elem) { if (elem.type === 'Literal') { deps.push(elem.value); } }); return deps.length ? deps : undefined; }
[ "function", "getValidDeps", "(", "node", ")", "{", "if", "(", "!", "node", "||", "node", ".", "type", "!==", "'ArrayExpression'", "||", "!", "node", ".", "elements", ")", "{", "return", ";", "}", "var", "deps", "=", "[", "]", ";", "node", ".", "elements", ".", "some", "(", "function", "(", "elem", ")", "{", "if", "(", "elem", ".", "type", "===", "'Literal'", ")", "{", "deps", ".", "push", "(", "elem", ".", "value", ")", ";", "}", "}", ")", ";", "return", "deps", ".", "length", "?", "deps", ":", "undefined", ";", "}" ]
Pulls out dependencies from an array literal with just string members. If string literals, will just return those string values in an array, skipping other items in the array. @param {Node} node an AST node. @returns {Array} an array of strings. If null is returned, then it means the input node was not a valid dependency.
[ "Pulls", "out", "dependencies", "from", "an", "array", "literal", "with", "just", "string", "members", ".", "If", "string", "literals", "will", "just", "return", "those", "string", "values", "in", "an", "array", "skipping", "other", "items", "in", "the", "array", "." ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L25034-L25048
44,398
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
function (obj, options, totalIndent) { var startBrace, endBrace, nextIndent, first = true, value = '', lineReturn = options.lineReturn, indent = options.indent, outDentRegExp = options.outDentRegExp, quote = options.quote || '"'; totalIndent = totalIndent || ''; nextIndent = totalIndent + indent; if (obj === null) { value = 'null'; } else if (obj === undefined) { value = 'undefined'; } else if (typeof obj === 'number' || typeof obj === 'boolean') { value = obj; } else if (typeof obj === 'string') { //Use double quotes in case the config may also work as JSON. value = quote + lang.jsEscape(obj) + quote; } else if (lang.isArray(obj)) { lang.each(obj, function (item, i) { value += (i !== 0 ? ',' + lineReturn : '' ) + nextIndent + transform.objectToString(item, options, nextIndent); }); startBrace = '['; endBrace = ']'; } else if (lang.isFunction(obj) || lang.isRegExp(obj)) { //The outdent regexp just helps pretty up the conversion //just in node. Rhino strips comments and does a different //indent scheme for Function toString, so not really helpful //there. value = obj.toString().replace(outDentRegExp, '$1'); } else { //An object lang.eachProp(obj, function (v, prop) { value += (first ? '': ',' + lineReturn) + nextIndent + (keyRegExp.test(prop) ? prop : quote + lang.jsEscape(prop) + quote )+ ': ' + transform.objectToString(v, options, nextIndent); first = false; }); startBrace = '{'; endBrace = '}'; } if (startBrace) { value = startBrace + lineReturn + value + lineReturn + totalIndent + endBrace; } return value; }
javascript
function (obj, options, totalIndent) { var startBrace, endBrace, nextIndent, first = true, value = '', lineReturn = options.lineReturn, indent = options.indent, outDentRegExp = options.outDentRegExp, quote = options.quote || '"'; totalIndent = totalIndent || ''; nextIndent = totalIndent + indent; if (obj === null) { value = 'null'; } else if (obj === undefined) { value = 'undefined'; } else if (typeof obj === 'number' || typeof obj === 'boolean') { value = obj; } else if (typeof obj === 'string') { //Use double quotes in case the config may also work as JSON. value = quote + lang.jsEscape(obj) + quote; } else if (lang.isArray(obj)) { lang.each(obj, function (item, i) { value += (i !== 0 ? ',' + lineReturn : '' ) + nextIndent + transform.objectToString(item, options, nextIndent); }); startBrace = '['; endBrace = ']'; } else if (lang.isFunction(obj) || lang.isRegExp(obj)) { //The outdent regexp just helps pretty up the conversion //just in node. Rhino strips comments and does a different //indent scheme for Function toString, so not really helpful //there. value = obj.toString().replace(outDentRegExp, '$1'); } else { //An object lang.eachProp(obj, function (v, prop) { value += (first ? '': ',' + lineReturn) + nextIndent + (keyRegExp.test(prop) ? prop : quote + lang.jsEscape(prop) + quote )+ ': ' + transform.objectToString(v, options, nextIndent); first = false; }); startBrace = '{'; endBrace = '}'; } if (startBrace) { value = startBrace + lineReturn + value + lineReturn + totalIndent + endBrace; } return value; }
[ "function", "(", "obj", ",", "options", ",", "totalIndent", ")", "{", "var", "startBrace", ",", "endBrace", ",", "nextIndent", ",", "first", "=", "true", ",", "value", "=", "''", ",", "lineReturn", "=", "options", ".", "lineReturn", ",", "indent", "=", "options", ".", "indent", ",", "outDentRegExp", "=", "options", ".", "outDentRegExp", ",", "quote", "=", "options", ".", "quote", "||", "'\"'", ";", "totalIndent", "=", "totalIndent", "||", "''", ";", "nextIndent", "=", "totalIndent", "+", "indent", ";", "if", "(", "obj", "===", "null", ")", "{", "value", "=", "'null'", ";", "}", "else", "if", "(", "obj", "===", "undefined", ")", "{", "value", "=", "'undefined'", ";", "}", "else", "if", "(", "typeof", "obj", "===", "'number'", "||", "typeof", "obj", "===", "'boolean'", ")", "{", "value", "=", "obj", ";", "}", "else", "if", "(", "typeof", "obj", "===", "'string'", ")", "{", "//Use double quotes in case the config may also work as JSON.", "value", "=", "quote", "+", "lang", ".", "jsEscape", "(", "obj", ")", "+", "quote", ";", "}", "else", "if", "(", "lang", ".", "isArray", "(", "obj", ")", ")", "{", "lang", ".", "each", "(", "obj", ",", "function", "(", "item", ",", "i", ")", "{", "value", "+=", "(", "i", "!==", "0", "?", "','", "+", "lineReturn", ":", "''", ")", "+", "nextIndent", "+", "transform", ".", "objectToString", "(", "item", ",", "options", ",", "nextIndent", ")", ";", "}", ")", ";", "startBrace", "=", "'['", ";", "endBrace", "=", "']'", ";", "}", "else", "if", "(", "lang", ".", "isFunction", "(", "obj", ")", "||", "lang", ".", "isRegExp", "(", "obj", ")", ")", "{", "//The outdent regexp just helps pretty up the conversion", "//just in node. Rhino strips comments and does a different", "//indent scheme for Function toString, so not really helpful", "//there.", "value", "=", "obj", ".", "toString", "(", ")", ".", "replace", "(", "outDentRegExp", ",", "'$1'", ")", ";", "}", "else", "{", "//An object", "lang", ".", "eachProp", "(", "obj", ",", "function", "(", "v", ",", "prop", ")", "{", "value", "+=", "(", "first", "?", "''", ":", "','", "+", "lineReturn", ")", "+", "nextIndent", "+", "(", "keyRegExp", ".", "test", "(", "prop", ")", "?", "prop", ":", "quote", "+", "lang", ".", "jsEscape", "(", "prop", ")", "+", "quote", ")", "+", "': '", "+", "transform", ".", "objectToString", "(", "v", ",", "options", ",", "nextIndent", ")", ";", "first", "=", "false", ";", "}", ")", ";", "startBrace", "=", "'{'", ";", "endBrace", "=", "'}'", ";", "}", "if", "(", "startBrace", ")", "{", "value", "=", "startBrace", "+", "lineReturn", "+", "value", "+", "lineReturn", "+", "totalIndent", "+", "endBrace", ";", "}", "return", "value", ";", "}" ]
Tries converting a JS object to a string. This will likely suck, and is tailored to the type of config expected in a loader config call. So, hasOwnProperty fields, strings, numbers, arrays and functions, no weird recursively referenced stuff. @param {Object} obj the object to convert @param {Object} options options object with the following values: {String} indent the indentation to use for each level {String} lineReturn the type of line return to use {outDentRegExp} outDentRegExp the regexp to use to outdent functions {String} quote the quote type to use, ' or ". Optional. Default is " @param {String} totalIndent the total indent to print for this level @return {String} a string representation of the object.
[ "Tries", "converting", "a", "JS", "object", "to", "a", "string", ".", "This", "will", "likely", "suck", "and", "is", "tailored", "to", "the", "type", "of", "config", "expected", "in", "a", "loader", "config", "call", ".", "So", "hasOwnProperty", "fields", "strings", "numbers", "arrays", "and", "functions", "no", "weird", "recursively", "referenced", "stuff", "." ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L26399-L26462
44,399
rbackhouse/mpdjs
cordova/mpdjs/jsbuild/r.js
addSemiColon
function addSemiColon(text, config) { if (config.skipSemiColonInsertion || endsWithSemiColonRegExp.test(text)) { return text; } else { return text + ";"; } }
javascript
function addSemiColon(text, config) { if (config.skipSemiColonInsertion || endsWithSemiColonRegExp.test(text)) { return text; } else { return text + ";"; } }
[ "function", "addSemiColon", "(", "text", ",", "config", ")", "{", "if", "(", "config", ".", "skipSemiColonInsertion", "||", "endsWithSemiColonRegExp", ".", "test", "(", "text", ")", ")", "{", "return", "text", ";", "}", "else", "{", "return", "text", "+", "\";\"", ";", "}", "}" ]
Some JS may not be valid if concatenated with other JS, in particular the style of omitting semicolons and rely on ASI. Add a semicolon in those cases.
[ "Some", "JS", "may", "not", "be", "valid", "if", "concatenated", "with", "other", "JS", "in", "particular", "the", "style", "of", "omitting", "semicolons", "and", "rely", "on", "ASI", ".", "Add", "a", "semicolon", "in", "those", "cases", "." ]
23fde33a7a24ba8d516c623643e359a25a46259c
https://github.com/rbackhouse/mpdjs/blob/23fde33a7a24ba8d516c623643e359a25a46259c/cordova/mpdjs/jsbuild/r.js#L28129-L28135